diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-02-01 18:42:05 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-02-01 18:46:24 +0200 |
commit | a9ffc779d3c56b43f216197a65675402ad95e3a1 (patch) | |
tree | 19531574009643d43b3798a69fde71ea9e2b425d | |
parent | 81b653e7adc6c69e78ed0c73dca2a16a28ba3208 (diff) | |
download | xenv-a9ffc779d3c56b43f216197a65675402ad95e3a1.tar.gz xenv-a9ffc779d3c56b43f216197a65675402ad95e3a1.tar.bz2 |
Minor improvements
* xenv.1: Document the -r option.
* xenv.l: New option -r (retain unexpanded references).
(open_input): Emit syncline for the first line of each input file.
(main): Initialize yyout.
Don't call yylex in a loop.
-rw-r--r-- | xenv.1 | 19 | ||||
-rw-r--r-- | xenv.l | 18 |
2 files changed, 30 insertions, 7 deletions
@@ -13,12 +13,12 @@ .\" .\" You should have received a copy of the GNU General Public License along .\" with xenv. If not, see <http://www.gnu.org/licenses/>. -.TH XENV 1 "January 31, 2021" "XENV" "General Commands Manual" +.TH XENV 1 "February 1, 2021" "XENV" "General Commands Manual" .SH NAME xenv \- expand shell variables in input files .SH SYNOPSIS \fBxenv\fR\ - [\fB\-hnsu\fR]\ + [\fB\-hnrsu\fR]\ [\fB\-D \fINAME\fR[\fB=\fIVALUE\fR]]\ [\fB\-U \fINAME\fR]\ [\fIFILE\fR...] @@ -159,10 +159,25 @@ Dry-run mode. Process the input files without producing any output. Report any errors. Useful together with the \fB\-u\fR option to discover undefined variables. .TP +.B \-r +Retain references to undefined variables in output. By default, an +undefined variable expands to an empty string. This option instructs +\fBxenv\fR to reproduce the variable reference verbatim in the output. +Naturally, this affects only \fB$\fIX\fR and \fB${\fIX\fB}\fR +references. +.TP .B \-s Generate synchronization directives, i.e. lines of the form \fB#line \fINUM\fR "\fIFILE\fR"\fR, which mean that the following line originated at line \fINUM\fR in file \fIFILE\fR. +.br +Synchronization directives are emitted when variable or preprocessor +directive expansion causes removal or insertion of one or more lines +to the output. Each synchronization directive occupies a single line +by itself. If a synchronization discrepancy occurs in the middle of +an output line, emission of the synchronization directive is delayed +until the next newline that does not occur in the middle of a quoted +string (both single and double quotes are understood). .TP .B \-u Treat unset variables as an error. @@ -27,7 +27,7 @@ char const *filename; /* Name of the input file. */ unsigned lineno; /* Line number in the input file. */ int undef_error_option; /* Treat undefined variables as error. */ int synclines_option; /* Generate `#line NUM "FILE"' lines. */ - +int retain_unexpanded_option;/* Retain unexpanded constructs in the output. */ int status = 0; /* Exit status */ static int save_state; /* Saved scanner state. */ @@ -332,8 +332,9 @@ expandenv(char const *ident, int len) fprintf(stderr, "%s:%u: variable %.*s not defined\n", filename, lineno, len, ident); status = EX_DATAERR; - ECHO; } + if (retain_unexpanded_option) + ECHO; } } @@ -569,6 +570,8 @@ open_input(char const *name) yyin = fp; filename = name; lineno = 1; + if (synclines_option) + fprintf(yyout, "#line %u \"%s\"\n", lineno, filename); } int @@ -592,6 +595,7 @@ usage(FILE *fp) fprintf(fp, " -D NAME[=VALUE] set environment variable NAME\n"); fprintf(fp, " -U NAME unset environment variable NAME\n"); fprintf(fp, " -n don't produce output, only report errors\n"); + fprintf(fp, " -r Retain unexpanded constructs in the output\n"); fprintf(fp, " -s generate `#line NUM \"FILE\"' lines\n"); fprintf(fp, " -u treat unset variables as errors\n"); fprintf(fp, " -h print this help text\n"); @@ -606,7 +610,7 @@ main(int argc, char **argv) int dry_run = 0; progname = argv[0]; - while ((c = getopt(argc, argv, "D:hnsU:u")) != EOF) { + while ((c = getopt(argc, argv, "D:hnrsU:u")) != EOF) { switch (c) { case 'D':{ char *p = strchr(optarg, '='); @@ -630,6 +634,10 @@ main(int argc, char **argv) dry_run = 1; break; + case 'r': + retain_unexpanded_option = 1; + break; + case 's': synclines_option = 1; break; @@ -662,9 +670,9 @@ main(int argc, char **argv) static char *stdin_file[] = { "-", NULL }; input_files = stdin_file; } + yyout = stdout; open_input(input_files[input_index++]); - while (yylex()) - ; + yylex(); return status; } |