137
137
extern int optind;
138
138
extern int opterr;
139
139
extern char *optarg;
140
char *optlist = "+F:f:v:W:";
143
_response(&argc, &argv);
144
_wildcard(&argc, &argv);
145
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
142
148
(void) signal(SIGFPE, (SIGTYPE (*) P((int))) catchsig);
143
149
(void) signal(SIGSEGV, (SIGTYPE (*) P((int))) catchsig);
185
191
/* the + on the front tells GNU getopt not to rearrange argv */
186
while ((c = getopt_long(argc, argv, "+F:f:v:W:", optab, NULL)) != EOF) {
193
(c = getopt_long(argc, argv, optlist, optab, NULL)) != EOF;
254
262
* option stops argument processing so that it can
255
263
* go into ARGV for the awk program to see. This
256
264
* makes use of ``#! /bin/gawk -f'' easier.
266
* However, it's never simple. If optopt is set,
267
* an option that requires an argument didn't get the
268
* argument. We care because if opterr is 0, then
269
* getopt_long won't print the error message for us.
272
&& (optopt == 0 || strchr(optlist, optopt) == NULL)) {
276
/* Use 1003.2 required message format */
278
"%s: option requires an argument -- %c\n",
261
281
let getopt print error message for us */
321
341
char *opt1 = " -f progfile [--]";
342
#if defined(MSDOS) || defined(OS2)
343
char *opt2 = " [--] \"program\"";
322
345
char *opt2 = " [--] 'program'";
323
347
char *regops = " [POSIX or GNU style options]";
326
fprintf(stderr, "usage: %s%s%s file ...\n %s%s%s file ...\n",
350
fprintf(stderr, "Usage: %s%s%s file ...\n\t%s%s%s file ...\n",
327
351
myname, regops, opt1, myname, regops, opt2);
329
353
/* GNU long options info. Gack. */
330
fputs("\nPOSIX options:\t\tGNU long options:\n", stderr);
354
fputs("POSIX options:\t\tGNU long options:\n", stderr);
331
355
fputs("\t-f progfile\t\t--file=progfile\n", stderr);
332
356
fputs("\t-F fs\t\t\t--field-separator=fs\n", stderr);
333
357
fputs("\t-v var=val\t\t--assign=var=val\n", stderr);
446
470
{&FS_node, "FS", Node_FS, " ", 0, 0 },
447
471
{&RS_node, "RS", Node_RS, "\n", 0, set_RS },
448
472
{&IGNORECASE_node, "IGNORECASE", Node_IGNORECASE, 0, 0, set_IGNORECASE },
449
{&FILENAME_node, "FILENAME", Node_var, "-", 0, 0 },
473
{&FILENAME_node, "FILENAME", Node_var, "", 0, 0 },
450
474
{&OFS_node, "OFS", Node_OFS, " ", 0, set_OFS },
451
475
{&ORS_node, "ORS", Node_ORS, "\n", 0, set_ORS },
452
476
{&OFMT_node, "OFMT", Node_OFMT, "%.6g", 0, set_OFMT },
519
544
cp = strchr(arg, '=');
520
545
if (cp != NULL) {
547
/* first check that the variable name has valid syntax */
549
if (! isalpha(arg[0]) && arg[0] != '_')
552
for (cp2 = arg+1; *cp2; cp2++)
553
if (! isalnum(*cp2) && *cp2 != '_') {
558
fatal("illegal name `%s' in variable assignment", arg);
523
561
* Recent versions of nawk expand escapes inside assignments.
524
562
* This makes sense, so we do it too.
691
729
fprintf(stderr, "%s, patchlevel %d\n", version_string, PATCHLEVEL);
732
/* this mess will improve in 2.16 */
696
734
gawk_name(filespec)
701
739
#ifdef VMS /* "device:[root.][directory.subdir]GAWK.EXE;n" -> "GAWK" */
704
p = strrchr(filespec, ']'); /* directory punctuation */
705
q = strrchr(filespec, '>'); /* alternate <international> punct */
707
if (p == NULL || q > p) p = q;
742
p = strrchr(filespec, ']'); /* directory punctuation */
743
q = strrchr(filespec, '>'); /* alternate <international> punct */
745
if (p == NULL || q > p) p = q;
708
746
p = strdup(p == NULL ? filespec : (p + 1));
709
747
if ((q = strrchr(p, '.')) != NULL) *q = '\0'; /* strip .typ;vers */
714
#if defined(MSDOS) || defined(atarist)
719
if (q = strrchr(p, '\\'))
721
if (q = strchr(p, '.'))
725
return (p == NULL ? filespec : p);
752
#if defined(MSDOS) || defined(OS2) || defined(atarist)
755
for (p = filespec; (p = strchr(p, '\\')); *p = '/')
758
if ((q = strrchr(p, '/')))
760
if ((q = strchr(p, '.')))
764
return (p == NULL ? filespec : p);
726
765
#endif /* MSDOS || atarist */
728
767
/* "path/name" -> "name" */