Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/util-linux/getopt.c

    r3232 r3621  
    3636//usage:#define getopt_full_usage "\n\n"
    3737//usage:    IF_LONG_OPTS(
    38 //usage:       "    -a,--alternative        Allow long options starting with single -"
    39 //usage:     "\n    -l,--longoptions=LOPT[,...] Long options to be recognized"
    40 //usage:     "\n    -n,--name=PROGNAME      The name under which errors are reported"
    41 //usage:     "\n    -o,--options=OPTSTRING      Short options to be recognized"
    42 //usage:     "\n    -q,--quiet          Disable error reporting by getopt(3)"
     38//usage:    IF_FEATURE_GETOPT_LONG(
     39//usage:       "    -a,--alternative        Allow long options starting with single -\n"
     40//usage:       "    -l,--longoptions=LOPT[,...] Long options to recognize\n"
     41//usage:    )
     42//usage:       "    -n,--name=PROGNAME      The name under which errors are reported"
     43//usage:     "\n    -o,--options=OPTSTRING      Short options to recognize"
     44//usage:     "\n    -q,--quiet          No error messages on unrecognized options"
    4345//usage:     "\n    -Q,--quiet-output       No normal output"
    4446//usage:     "\n    -s,--shell=SHELL        Set shell quoting conventions"
    45 //usage:     "\n    -T,--test           Test for getopt(1) version"
    46 //usage:     "\n    -u,--unquoted           Don't quote the output"
     47//usage:     "\n    -T,--test           Version test (exits with 4)"
     48//usage:     "\n    -u,--unquoted           Don't quote output"
    4749//usage:    )
    4850//usage:    IF_NOT_LONG_OPTS(
    49 //usage:       "    -a      Allow long options starting with single -"
    50 //usage:     "\n    -l LOPT[,...]   Long options to be recognized"
    51 //usage:     "\n    -n PROGNAME The name under which errors are reported"
    52 //usage:     "\n    -o OPTSTRING    Short options to be recognized"
    53 //usage:     "\n    -q      Disable error reporting by getopt(3)"
     51//usage:    IF_FEATURE_GETOPT_LONG(
     52//usage:       "    -a      Allow long options starting with single -\n"
     53//usage:       "    -l LOPT[,...]   Long options to recognize\n"
     54//usage:    )
     55//usage:       "    -n PROGNAME The name under which errors are reported"
     56//usage:     "\n    -o OPTSTRING    Short options to recognize"
     57//usage:     "\n    -q      No error messages on unrecognized options"
    5458//usage:     "\n    -Q      No normal output"
    5559//usage:     "\n    -s SHELL    Set shell quoting conventions"
    56 //usage:     "\n    -T      Test for getopt(1) version"
    57 //usage:     "\n    -u      Don't quote the output"
     60//usage:     "\n    -T      Version test (exits with 4)"
     61//usage:     "\n    -u      Don't quote output"
    5862//usage:    )
     63//usage:    IF_FEATURE_GETOPT_LONG( /* example uses -l, needs FEATURE_GETOPT_LONG */
    5964//usage:     "\n"
    6065//usage:     "\nExample:"
     
    7479//usage:     "\n    esac"
    7580//usage:     "\ndone"
     81//usage:    )
    7682//usage:
    7783//usage:#define getopt_example_usage
     
    215221{
    216222    int exit_code = 0; /* We assume everything will be OK */
    217     int opt;
    218 #if ENABLE_FEATURE_GETOPT_LONG
    219     int longindex;
    220 #endif
    221     const char *charptr;
    222223
    223224    if (quiet_errors) /* No error reporting from getopt(3) */
     
    234235
    235236    while (1) {
    236         opt =
    237 #if ENABLE_FEATURE_GETOPT_LONG
    238             alternative ?
    239             getopt_long_only(argc, argv, optstr, longopts, &longindex) :
    240             getopt_long(argc, argv, optstr, longopts, &longindex);
     237#if ENABLE_FEATURE_GETOPT_LONG
     238        int longindex;
     239        int opt = alternative
     240            ? getopt_long_only(argc, argv, optstr, longopts, &longindex)
     241            : getopt_long(argc, argv, optstr, longopts, &longindex)
     242        ;
    241243#else
    242             getopt(argc, argv, optstr);
     244        int opt = getopt(argc, argv, optstr);
    243245#endif
    244246        if (opt == -1)
     
    258260                printf(" %s", normalize(optarg));
    259261            else {
     262                const char *charptr;
    260263                printf(" -%c", opt);
    261264                charptr = strchr(optstr, opt);
    262                 if (charptr != NULL && *++charptr == ':')
     265                if (charptr && *++charptr == ':')
    263266                    printf(" %s",
    264267                        normalize(optarg ? optarg : ""));
     
    268271
    269272    if (!quiet_output) {
     273        unsigned idx;
    270274        printf(" --");
    271         while (optind < argc)
    272             printf(" %s", normalize(argv[optind++]));
     275        idx = optind;
     276        while (argv[idx])
     277            printf(" %s", normalize(argv[idx++]));
    273278        bb_putchar('\n');
    274279    }
     
    374379            /* For some reason, the original getopt gave no error
    375380             * when there were no arguments. */
    376             printf(" --\n");
     381            puts(" --");
    377382            return 0;
    378383        }
Note: See TracChangeset for help on using the changeset viewer.