diff options
author | kevans <kevans@FreeBSD.org> | 2018-01-18 21:29:46 +0000 |
---|---|---|
committer | kevans <kevans@FreeBSD.org> | 2018-01-18 21:29:46 +0000 |
commit | b3e92c201285ccffefab78500eae3e9c4c4054df (patch) | |
tree | c88481ac103fce2c00c1030e881d309d4eae8d74 /usr.bin | |
parent | b299fcd9ac0152c5f0b8648847979f5fb92a54a9 (diff) | |
download | FreeBSD-src-b3e92c201285ccffefab78500eae3e9c4c4054df.zip FreeBSD-src-b3e92c201285ccffefab78500eae3e9c4c4054df.tar.gz |
MFC r322177: Respect SIMPLE_BACKUP_SUFFIX environment variable in indent(1)
Instead of using a non-configurable ".BAK" suffix, respect the
SIMPLE_BACKUP_SUFFIX environment variable also used by patch(1). This
simplifies cleanup operations in some patch/indent workflows.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/indent/indent.1 | 7 | ||||
-rw-r--r-- | usr.bin/indent/indent.c | 10 |
2 files changed, 13 insertions, 4 deletions
diff --git a/usr.bin/indent/indent.1 b/usr.bin/indent/indent.1 index 60ae0bc..9e83538 100644 --- a/usr.bin/indent/indent.1 +++ b/usr.bin/indent/indent.1 @@ -30,7 +30,7 @@ .\" @(#)indent.1 8.1 (Berkeley) 7/1/93 .\" $FreeBSD$ .\" -.Dd March 3, 2012 +.Dd August 7, 2017 .Dt INDENT 1 .Os .Sh NAME @@ -113,7 +113,10 @@ If is named .Sq Pa /blah/blah/file , the backup file is named -.Sq Pa file.BAK . +.Sq Pa file.BAK +by default. The extension used for the backup file may be overridden using the +.Ev SIMPLE_BACKUP_SUFFIX +environment variable. .Pp If .Ar output-file diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c index 7c2cbea..bc28079 100644 --- a/usr.bin/indent/indent.c +++ b/usr.bin/indent/indent.c @@ -68,6 +68,8 @@ const char *in_name = "Standard Input"; /* will always point to name of input * file */ const char *out_name = "Standard Output"; /* will always point to name * of output file */ +const char *simple_backup_suffix = ".BAK"; /* Suffix to use for backup + * files */ char bakfile[MAXPATHLEN] = ""; int @@ -94,7 +96,7 @@ main(int argc, char **argv) int type_code; /* the type of token, returned by lexi */ int last_else = 0; /* true iff last keyword was an else */ - + const char *envval = NULL; /*-----------------------------------------------*\ | INITIALIZATION | @@ -154,6 +156,10 @@ main(int argc, char **argv) output = 0; tabs_to_var = 0; + envval = getenv("SIMPLE_BACKUP_SUFFIX"); + if (envval) + simple_backup_suffix = envval; + /*--------------------------------------------------*\ | COMMAND LINE SCAN | \*--------------------------------------------------*/ @@ -1207,7 +1213,7 @@ bakcopy(void) p--; if (*p == '/') p++; - sprintf(bakfile, "%s.BAK", p); + sprintf(bakfile, "%s%s", p, simple_backup_suffix); /* copy in_name to backup file */ bakchn = creat(bakfile, 0600); |