diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2010-07-16 12:33:03 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2010-07-16 12:33:03 +0300 |
commit | 2f83a4e72166e811a9f0b4726c19a3d5a0b17dcb (patch) | |
tree | 469bebda4e807139efb497edfca1ec0678b5ab8b /main.c | |
parent | 66b0bdd602e952f20fa98f6ce5430cea68d4f598 (diff) | |
download | egawk-2f83a4e72166e811a9f0b4726c19a3d5a0b17dcb.tar.gz egawk-2f83a4e72166e811a9f0b4726c19a3d5a0b17dcb.tar.bz2 egawk-2f83a4e72166e811a9f0b4726c19a3d5a0b17dcb.zip |
Move to gawk-2.15.5.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 41 |
1 files changed, 30 insertions, 11 deletions
@@ -55,9 +55,9 @@ NODE *ENVIRON_node, *IGNORECASE_node; NODE *ARGC_node, *ARGV_node, *ARGIND_node; NODE *FIELDWIDTHS_node; -int NF; -int NR; -int FNR; +long NF; +long NR; +long FNR; int IGNORECASE; char *RS; char *OFS; @@ -134,11 +134,13 @@ char **argv; { int c; char *scan; + /* the + on the front tells GNU getopt not to rearrange argv */ + const char *optlist = "+F:f:v:W:m:"; + int stopped_early = 0; + int old_optind; extern int optind; extern int opterr; extern char *optarg; - const char *optlist = "+F:f:v:W:m:"; - int stopped_early = 0; #ifdef __EMX__ _response(&argc, &argv); @@ -188,10 +190,10 @@ char **argv; /* we do error messages ourselves on invalid options */ opterr = 0; - /* the + on the front tells GNU getopt not to rearrange argv */ - for (optopt = 0; + /* option processing. ready, set, go! */ + for (optopt = 0, old_optind = 1; (c = getopt_long(argc, argv, optlist, optab, NULL)) != EOF; - optopt = 0) { + optopt = 0, old_optind = optind) { if (do_posix) opterr = 1; switch (c) { @@ -254,7 +256,7 @@ char **argv; break; case 's': - if (strlen(optarg) == 0) + if (optarg[0] == '\0') warning("empty argument to --source ignored"); else { srcfiles[++numfiles].stype = CMDLINE; @@ -291,7 +293,12 @@ char **argv; */ if (! do_posix && (optopt == 0 || strchr(optlist, optopt) == NULL)) { - optind--; + /* + * can't just do optind--. In case of an + * option with >=2 letters, getopt_long + * won't have incremented optind. + */ + optind = old_optind; stopped_early = 1; goto out; } else if (optopt) @@ -309,6 +316,14 @@ out: if (do_nostalgia) nostalgia(); + /* check for POSIXLY_CORRECT environment variable */ + if (! do_posix && getenv("POSIXLY_CORRECT") != NULL) { + do_posix = 1; + if (do_lint) + warning( + "environment variable `POSIXLY_CORRECT' set: turning on --posix"); + } + /* POSIX compliance also implies no Unix extensions either */ if (do_posix) do_unix = 1; @@ -336,6 +351,10 @@ out: /* Set up the field variables */ init_fields(); + if (do_lint && begin_block == NULL && expression_value == NULL + && end_block == NULL) + warning("no program"); + if (begin_block) { in_begin_rule = 1; (void) interpret(begin_block); @@ -718,7 +737,7 @@ char *optstr; if (strncasecmp(cp, "source=", 7) != 0) goto unknown; cp += 7; - if (strlen(cp) == 0) + if (cp[0] == '\0') warning("empty argument to -Wsource ignored"); else { srcfiles[++numfiles].stype = CMDLINE; |