… | |
… | |
79 | /* Some global variables that tells us how to parse. */ |
79 | /* Some global variables that tells us how to parse. */ |
80 | shell_t shell=BASH; /* The shell we generate output for. */ |
80 | shell_t shell=BASH; /* The shell we generate output for. */ |
81 | int quiet_errors=0; /* 0 is not quiet. */ |
81 | int quiet_errors=0; /* 0 is not quiet. */ |
82 | int quiet_output=0; /* 0 is not quiet. */ |
82 | int quiet_output=0; /* 0 is not quiet. */ |
83 | int quote=1; /* 1 is do quote. */ |
83 | int quote=1; /* 1 is do quote. */ |
84 | int alternative=0; /* 0 is getopt_long, 1 is getopt_long_only */ |
84 | |
|
|
85 | int (*getopt_long_fp) (int argc, char *const *argv, const char *optstr, |
|
|
86 | const struct option * longopts, int *longindex); |
85 | |
87 | |
86 | /* Function prototypes */ |
88 | /* Function prototypes */ |
87 | void *our_malloc(size_t size); |
89 | void *our_malloc(size_t size); |
88 | void *our_realloc(void *ptr, size_t size); |
90 | void *our_realloc(void *ptr, size_t size); |
89 | const char *normalize(const char *arg); |
91 | const char *normalize(const char *arg); |
… | |
… | |
206 | /* No error reporting from getopt(3) */ |
208 | /* No error reporting from getopt(3) */ |
207 | opterr=0; |
209 | opterr=0; |
208 | /* Reset getopt(3) */ |
210 | /* Reset getopt(3) */ |
209 | optind=0; |
211 | optind=0; |
210 | |
212 | |
211 | while ((opt = (alternative? |
213 | while ((opt = |
212 | getopt_long_only(argc,argv,optstr,longopts,&longindex): |
|
|
213 | getopt_long(argc,argv,optstr,longopts,&longindex))) |
214 | (getopt_long_fp(argc, argv, optstr, longopts, &longindex))) |
214 | != EOF) |
215 | != EOF) |
215 | if (opt == '?' || opt == ':' ) |
216 | if (opt == '?' || opt == ':' ) |
216 | exit_code = GETOPT_EXIT_CODE; |
217 | exit_code = GETOPT_EXIT_CODE; |
217 | else if (!quiet_output) |
218 | else if (!quiet_output) |
218 | { |
219 | { |
… | |
… | |
389 | bindtextdomain(PACKAGE, LOCALEDIR); |
390 | bindtextdomain(PACKAGE, LOCALEDIR); |
390 | textdomain(PACKAGE); |
391 | textdomain(PACKAGE); |
391 | #endif |
392 | #endif |
392 | |
393 | |
393 | init_longopt(); |
394 | init_longopt(); |
|
|
395 | getopt_long_fp = getopt_long; |
394 | |
396 | |
395 | if (getenv("GETOPT_COMPATIBLE")) |
397 | if (getenv("GETOPT_COMPATIBLE")) |
396 | compatible=1; |
398 | compatible=1; |
397 | |
399 | |
398 | if (argc == 1) |
400 | if (argc == 1) |
… | |
… | |
405 | printf(" --\n"); |
407 | printf(" --\n"); |
406 | return EXIT_SUCCESS; |
408 | return EXIT_SUCCESS; |
407 | } |
409 | } |
408 | else |
410 | else |
409 | parse_error(_("missing optstring argument")); |
411 | parse_error(_("missing optstring argument")); |
|
|
412 | } |
410 | |
413 | |
411 | |
414 | |
412 | if (argv[1][0] != '-' || compatible) { |
415 | if (argv[1][0] != '-' || compatible) { |
413 | quote=0; |
416 | quote=0; |
414 | optstr=our_malloc(strlen(argv[1])+1); |
417 | optstr=our_malloc(strlen(argv[1])+1); |
… | |
… | |
418 | } |
421 | } |
419 | |
422 | |
420 | while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF) |
423 | while ((opt=getopt_long(argc,argv,shortopts,longopts,NULL)) != EOF) |
421 | switch (opt) { |
424 | switch (opt) { |
422 | case 'a': |
425 | case 'a': |
423 | alternative=1; |
426 | getopt_long_fp = getopt_long_only; |
424 | break; |
427 | break; |
425 | case 'h': |
428 | case 'h': |
426 | print_help(); |
429 | print_help(); |
427 | case 'o': |
430 | case 'o': |
428 | if (optstr) |
431 | if (optstr) |