186
189
{ "lint", optional_argument, NULL, 'L' },
187
190
{ "lint-old", no_argument, NULL, 't' },
188
191
{ "load", required_argument, NULL, 'l' },
192
#if defined(LOCALEDEBUG)
193
{ "locale", required_argument, NULL, 'Z' },
189
195
{ "non-decimal-data", no_argument, NULL, 'n' },
190
196
{ "nostalgia", no_argument, & do_nostalgia, 1 },
191
197
{ "optimize", no_argument, NULL, 'O' },
233
231
#endif /* HAVE_MTRACE */
234
232
#endif /* HAVE_MCHECK_H */
236
#if defined(LC_CTYPE)
237
setlocale(LC_CTYPE, "");
239
#if defined(LC_COLLATE)
240
setlocale(LC_COLLATE, "");
242
#if defined(LC_MESSAGES)
243
setlocale(LC_MESSAGES, "");
245
#if defined(LC_NUMERIC) && defined(HAVE_LOCALE_H)
247
* Force the issue here. According to POSIX 2001, decimal
248
* point is used for parsing source code and for command-line
249
* assignments and the locale value for processing input,
250
* number to string conversion, and printing output.
252
* 10/2005 --- see below also; we now only use the locale's
253
* decimal point if do_posix in effect.
256
* This is a mess. We need to get the locale's numeric info for
257
* the thousands separator for the %'d flag.
259
setlocale(LC_NUMERIC, "");
261
setlocale(LC_NUMERIC, "C");
264
setlocale(LC_TIME, "");
269
* In glibc, MB_CUR_MAX is actually a function. This value is
270
* tested *a lot* in many speed-critical places in gawk. Caching
271
* this value once makes a speed difference.
273
gawk_mb_cur_max = MB_CUR_MAX;
274
/* Without MBS_SUPPORT, gawk_mb_cur_max is 1. */
276
/* init the cache for checking bytes if they're characters */
234
myname = gawk_name(argv[0]);
235
os_arg_fixup(&argc, &argv); /* emulate redirection, expand wildcards */
238
usage(EXIT_FAILURE, stderr);
280
240
(void) bindtextdomain(PACKAGE, LOCALEDIR);
281
241
(void) textdomain(PACKAGE);
328
282
output_fp = stdout;
330
/* we do error messages ourselves on invalid options */
333
/* copy argv before getopt gets to it; used to restart the debugger */
334
save_argv(argc, argv);
336
284
/* initialize global (main) execution context */
337
285
push_context(new_context());
339
/* option processing. ready, set, go! */
340
for (optopt = 0, old_optind = 1;
341
(c = getopt_long(argc, argv, optlist, optab, NULL)) != EOF;
342
optopt = 0, old_optind = optind) {
348
add_preassign(PRE_ASSIGN_FS, optarg);
352
disallow_var_assigns = true;
356
* Allow multiple -f options.
357
* This makes function libraries real easy.
358
* Most of the magic is in the scanner.
360
* The following is to allow for whitespace at the end
361
* of a #! /bin/gawk line in an executable file
364
if (argv[optind-1] != optarg)
365
while (isspace((unsigned char) *scan))
367
src = (*scan == '\0' ? argv[optind++] : optarg);
368
(void) add_srcfile((src && src[0] == '-' && src[1] == '\0') ?
369
SRC_STDIN : SRC_FILE,
370
src, srcfiles, NULL, NULL);
375
add_preassign(PRE_ASSIGN, optarg);
383
do_flags |= DO_TRADITIONAL;
391
do_flags |= DO_DUMP_VARS;
392
if (optarg != NULL && optarg[0] != '\0')
397
do_flags |= DO_DEBUG;
398
if (optarg != NULL && optarg[0] != '\0')
399
command_file = optarg;
403
if (optarg[0] == '\0')
404
warning(_("empty argument to `-e/--source' ignored"));
406
(void) add_srcfile(SRC_CMDLINE, optarg, srcfiles, NULL, NULL);
414
/* write usage to stdout, per GNU coding stds */
415
usage(EXIT_SUCCESS, stdout);
419
(void) add_srcfile(SRC_INC, optarg, srcfiles, NULL, NULL);
423
(void) add_srcfile(SRC_EXTLIB, optarg, srcfiles, NULL, NULL);
428
do_flags |= DO_LINT_ALL;
429
if (optarg != NULL) {
430
if (strcmp(optarg, "fatal") == 0)
432
else if (strcmp(optarg, "invalid") == 0) {
433
do_flags &= ~DO_LINT_ALL;
434
do_flags |= DO_LINT_INVALID;
440
do_flags |= DO_LINT_OLD;
449
do_flags |= DO_NON_DEC_DATA;
453
use_lc_numeric = true;
461
do_flags |= DO_PROFILE;
464
do_flags |= DO_PRETTY_PRINT;
466
set_prof_file(optarg);
468
set_prof_file(DEFAULT_PROFILE);
475
warning(_("-M ignored: MPFR/GMP support not compiled in"));
480
do_flags |= DO_POSIX;
484
do_flags |= DO_INTERVALS;
488
do_flags |= DO_SANDBOX;
495
case 'W': /* gawk specific options - now in getopt_long */
496
fprintf(stderr, _("%s: option `-W %s' unrecognized, ignored\n"),
502
* getopt_long found an option that sets a variable
503
* instead of returning a letter. Do nothing, just
504
* cycle around for the next one.
509
#if defined(YYDEBUG) || defined(GAWKDEBUG)
515
/* if not debugging, fall through */
519
* If not posix, an unrecognized option stops argument
520
* processing so that it can go into ARGV for the awk
521
* program to see. This makes use of ``#! /bin/gawk -f''
524
* However, it's never simple. If optopt is set,
525
* an option that requires an argument didn't get the
526
* argument. We care because if opterr is 0, then
527
* getopt_long won't print the error message for us.
530
&& (optopt == '\0' || strchr(optlist, optopt) == NULL)) {
532
* can't just do optind--. In case of an
533
* option with >= 2 letters, getopt_long
534
* won't have incremented optind.
537
stopped_early = true;
539
} else if (optopt != '\0') {
540
/* Use POSIX required message format */
542
_("%s: option requires an argument -- %c\n"),
544
usage(EXIT_FAILURE, stderr);
547
let getopt print error message for us */
550
if (c == 'E') /* --exec ends option processing */
287
parse_args(argc, argv);
292
* In glibc, MB_CUR_MAX is actually a function. This value is
293
* tested *a lot* in many speed-critical places in gawk. Caching
294
* this value once makes a speed difference.
296
gawk_mb_cur_max = MB_CUR_MAX;
298
/* init the cache for checking bytes if they're characters */
555
301
if (do_nostalgia)
1391
/* parse_args --- do the getopt_long thing */
1394
parse_args(int argc, char **argv)
1397
* The + on the front tells GNU getopt not to rearrange argv.
1399
const char *optlist = "+F:f:v:W;bcCd::D::e:E:ghi:l:L:nNo::Op::MPrStVYZ:";
1405
/* we do error messages ourselves on invalid options */
1408
/* copy argv before getopt gets to it; used to restart the debugger */
1409
save_argv(argc, argv);
1411
/* option processing. ready, set, go! */
1412
for (optopt = 0, old_optind = 1;
1413
(c = getopt_long(argc, argv, optlist, optab, NULL)) != EOF;
1414
optopt = 0, old_optind = optind) {
1420
add_preassign(PRE_ASSIGN_FS, optarg);
1424
disallow_var_assigns = true;
1428
* Allow multiple -f options.
1429
* This makes function libraries real easy.
1430
* Most of the magic is in the scanner.
1432
* The following is to allow for whitespace at the end
1433
* of a #! /bin/gawk line in an executable file
1436
if (argv[optind-1] != optarg)
1437
while (isspace((unsigned char) *scan))
1439
src = (*scan == '\0' ? argv[optind++] : optarg);
1440
(void) add_srcfile((src && src[0] == '-' && src[1] == '\0') ?
1441
SRC_STDIN : SRC_FILE,
1442
src, srcfiles, NULL, NULL);
1447
add_preassign(PRE_ASSIGN, optarg);
1455
do_flags |= DO_TRADITIONAL;
1463
do_flags |= DO_DUMP_VARS;
1464
if (optarg != NULL && optarg[0] != '\0')
1469
do_flags |= DO_DEBUG;
1470
if (optarg != NULL && optarg[0] != '\0')
1471
command_file = optarg;
1475
if (optarg[0] == '\0')
1476
warning(_("empty argument to `-e/--source' ignored"));
1478
(void) add_srcfile(SRC_CMDLINE, optarg, srcfiles, NULL, NULL);
1482
do_flags |= DO_INTL;
1486
/* write usage to stdout, per GNU coding stds */
1487
usage(EXIT_SUCCESS, stdout);
1491
(void) add_srcfile(SRC_INC, optarg, srcfiles, NULL, NULL);
1495
(void) add_srcfile(SRC_EXTLIB, optarg, srcfiles, NULL, NULL);
1500
do_flags |= DO_LINT_ALL;
1501
if (optarg != NULL) {
1502
if (strcmp(optarg, "fatal") == 0)
1504
else if (strcmp(optarg, "invalid") == 0) {
1505
do_flags &= ~DO_LINT_ALL;
1506
do_flags |= DO_LINT_INVALID;
1512
do_flags |= DO_LINT_OLD;
1521
do_flags |= DO_NON_DEC_DATA;
1525
use_lc_numeric = true;
1533
do_flags |= DO_PROFILE;
1536
do_flags |= DO_PRETTY_PRINT;
1538
set_prof_file(optarg);
1540
set_prof_file(DEFAULT_PROFILE);
1545
do_flags |= DO_MPFR;
1547
warning(_("-M ignored: MPFR/GMP support not compiled in"));
1552
do_flags |= DO_POSIX;
1556
do_flags |= DO_INTERVALS;
1560
do_flags |= DO_SANDBOX;
1567
case 'W': /* gawk specific options - now in getopt_long */
1568
fprintf(stderr, _("%s: option `-W %s' unrecognized, ignored\n"),
1574
* getopt_long found an option that sets a variable
1575
* instead of returning a letter. Do nothing, just
1576
* cycle around for the next one.
1582
#if defined(YYDEBUG) || defined(GAWKDEBUG)
1588
#if defined(LOCALEDEBUG)
1594
/* if not debugging, fall through */
1598
* If not posix, an unrecognized option stops argument
1599
* processing so that it can go into ARGV for the awk
1600
* program to see. This makes use of ``#! /bin/gawk -f''
1603
* However, it's never simple. If optopt is set,
1604
* an option that requires an argument didn't get the
1605
* argument. We care because if opterr is 0, then
1606
* getopt_long won't print the error message for us.
1609
&& (optopt == '\0' || strchr(optlist, optopt) == NULL)) {
1611
* can't just do optind--. In case of an
1612
* option with >= 2 letters, getopt_long
1613
* won't have incremented optind.
1615
optind = old_optind;
1616
stopped_early = true;
1618
} else if (optopt != '\0') {
1619
/* Use POSIX required message format */
1621
_("%s: option requires an argument -- %c\n"),
1623
usage(EXIT_FAILURE, stderr);
1626
let getopt print error message for us */
1629
if (c == 'E') /* --exec ends option processing */
1636
/* set_locale_stuff --- setup the locale stuff */
1639
set_locale_stuff(void)
1641
#if defined(LC_CTYPE)
1642
setlocale(LC_CTYPE, locale);
1644
#if defined(LC_COLLATE)
1645
setlocale(LC_COLLATE, locale);
1647
#if defined(LC_MESSAGES)
1648
setlocale(LC_MESSAGES, locale);
1650
#if defined(LC_NUMERIC) && defined(HAVE_LOCALE_H)
1652
* Force the issue here. According to POSIX 2001, decimal
1653
* point is used for parsing source code and for command-line
1654
* assignments and the locale value for processing input,
1655
* number to string conversion, and printing output.
1657
* 10/2005 --- see below also; we now only use the locale's
1658
* decimal point if do_posix in effect.
1661
* This is a mess. We need to get the locale's numeric info for
1662
* the thousands separator for the %'d flag.
1664
setlocale(LC_NUMERIC, locale);
1666
setlocale(LC_NUMERIC, "C");
1668
#if defined(LC_TIME)
1669
setlocale(LC_TIME, locale);