Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Python/getopt.c

    r2 r391  
    88 *                    All Rights Reserved
    99 *
    10  * Permission to use, copy, modify, and distribute this software and its 
    11  * documentation for any purpose and without fee is hereby granted, 
     10 * Permission to use, copy, modify, and distribute this software and its
     11 * documentation for any purpose and without fee is hereby granted,
    1212 * provided that the above copyright notice, this permission notice and
    1313 * the following disclaimer notice appear unmodified in all copies.
     
    3838int _PyOS_optind = 1;          /* index into argv array   */
    3939char *_PyOS_optarg = NULL;     /* optional argument       */
     40static char *opt_ptr = "";
     41
     42void _PyOS_ResetGetOpt(void)
     43{
     44    _PyOS_opterr = 1;
     45    _PyOS_optind = 1;
     46    _PyOS_optarg = NULL;
     47    opt_ptr = "";
     48}
    4049
    4150int _PyOS_GetOpt(int argc, char **argv, char *optstring)
    4251{
    43         static char *opt_ptr = "";
    44         char *ptr;
    45         int option;
     52    char *ptr;
     53    int option;
    4654
    47         if (*opt_ptr == '\0') {
     55    if (*opt_ptr == '\0') {
    4856
    49                 if (_PyOS_optind >= argc)
    50                         return -1;
     57        if (_PyOS_optind >= argc)
     58            return -1;
    5159#ifdef MS_WINDOWS
    52                 else if (strcmp(argv[_PyOS_optind], "/?") == 0) {
    53                         ++_PyOS_optind;
    54                         return 'h';
    55                 }
     60        else if (strcmp(argv[_PyOS_optind], "/?") == 0) {
     61            ++_PyOS_optind;
     62            return 'h';
     63        }
    5664#endif
    5765
    58                 else if (argv[_PyOS_optind][0] != '-' ||
    59                          argv[_PyOS_optind][1] == '\0' /* lone dash */ )
    60                         return -1;
     66        else if (argv[_PyOS_optind][0] != '-' ||
     67                 argv[_PyOS_optind][1] == '\0' /* lone dash */ )
     68            return -1;
    6169
    62                 else if (strcmp(argv[_PyOS_optind], "--") == 0) {
    63                         ++_PyOS_optind;
    64                         return -1;
    65                 }
     70        else if (strcmp(argv[_PyOS_optind], "--") == 0) {
     71            ++_PyOS_optind;
     72            return -1;
     73        }
    6674
    67                 else if (strcmp(argv[_PyOS_optind], "--help") == 0) {
    68                         ++_PyOS_optind;
    69                         return 'h';
    70                 }
     75        else if (strcmp(argv[_PyOS_optind], "--help") == 0) {
     76            ++_PyOS_optind;
     77            return 'h';
     78        }
    7179
    72                 else if (strcmp(argv[_PyOS_optind], "--version") == 0) {
    73                         ++_PyOS_optind;
    74                         return 'V';
    75                 }
     80        else if (strcmp(argv[_PyOS_optind], "--version") == 0) {
     81            ++_PyOS_optind;
     82            return 'V';
     83        }
    7684
    7785
    78                 opt_ptr = &argv[_PyOS_optind++][1];
    79         }
     86        opt_ptr = &argv[_PyOS_optind++][1];
     87    }
    8088
    81         if ( (option = *opt_ptr++) == '\0')
    82                 return -1;
     89    if ((option = *opt_ptr++) == '\0')
     90        return -1;
    8391
    84         if (option == 'J') {
    85                 fprintf(stderr, "-J is reserved for Jython\n");
    86                 return '_';
    87         }
     92    if (option == 'J') {
     93        if (_PyOS_opterr)
     94            fprintf(stderr, "-J is reserved for Jython\n");
     95        return '_';
     96    }
    8897
    89         if (option == 'X') {
    90                 fprintf(stderr,
    91                   "-X is reserved for implementation-specific arguments\n");
    92                 return '_';
    93         }
     98    if (option == 'X') {
     99        if (_PyOS_opterr)
     100            fprintf(stderr,
     101                "-X is reserved for implementation-specific arguments\n");
     102        return '_';
     103    }
    94104
    95         if ((ptr = strchr(optstring, option)) == NULL) {
    96                 if (_PyOS_opterr)
    97                         fprintf(stderr, "Unknown option: -%c\n", option);
     105    if ((ptr = strchr(optstring, option)) == NULL) {
     106        if (_PyOS_opterr)
     107            fprintf(stderr, "Unknown option: -%c\n", option);
    98108
    99                 return '_';
    100         }
     109        return '_';
     110    }
    101111
    102         if (*(ptr + 1) == ':') {
    103                 if (*opt_ptr != '\0') {
    104                         _PyOS_optarg  = opt_ptr;
    105                         opt_ptr = "";
    106                 }
     112    if (*(ptr + 1) == ':') {
     113        if (*opt_ptr != '\0') {
     114            _PyOS_optarg  = opt_ptr;
     115            opt_ptr = "";
     116        }
    107117
    108                 else {
    109                         if (_PyOS_optind >= argc) {
    110                                 if (_PyOS_opterr)
    111                                         fprintf(stderr,
    112                             "Argument expected for the -%c option\n", option);
    113                                 return '_';
    114                         }
     118        else {
     119            if (_PyOS_optind >= argc) {
     120                if (_PyOS_opterr)
     121                    fprintf(stderr,
     122                        "Argument expected for the -%c option\n", option);
     123                return '_';
     124            }
    115125
    116                         _PyOS_optarg = argv[_PyOS_optind++];
    117                 }
    118         }
     126            _PyOS_optarg = argv[_PyOS_optind++];
     127        }
     128    }
    119129
    120         return option;
     130    return option;
    121131}
    122132
Note: See TracChangeset for help on using the changeset viewer.