Changeset 388 for python/vendor/current/Python/getopt.c
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Python/getopt.c
r2 r388 8 8 * All Rights Reserved 9 9 * 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, 12 12 * provided that the above copyright notice, this permission notice and 13 13 * the following disclaimer notice appear unmodified in all copies. … … 38 38 int _PyOS_optind = 1; /* index into argv array */ 39 39 char *_PyOS_optarg = NULL; /* optional argument */ 40 static char *opt_ptr = ""; 41 42 void _PyOS_ResetGetOpt(void) 43 { 44 _PyOS_opterr = 1; 45 _PyOS_optind = 1; 46 _PyOS_optarg = NULL; 47 opt_ptr = ""; 48 } 40 49 41 50 int _PyOS_GetOpt(int argc, char **argv, char *optstring) 42 51 { 43 static char *opt_ptr = ""; 44 char *ptr; 45 int option; 52 char *ptr; 53 int option; 46 54 47 55 if (*opt_ptr == '\0') { 48 56 49 50 57 if (_PyOS_optind >= argc) 58 return -1; 51 59 #ifdef MS_WINDOWS 52 53 54 55 60 else if (strcmp(argv[_PyOS_optind], "/?") == 0) { 61 ++_PyOS_optind; 62 return 'h'; 63 } 56 64 #endif 57 65 58 59 60 66 else if (argv[_PyOS_optind][0] != '-' || 67 argv[_PyOS_optind][1] == '\0' /* lone dash */ ) 68 return -1; 61 69 62 63 64 65 70 else if (strcmp(argv[_PyOS_optind], "--") == 0) { 71 ++_PyOS_optind; 72 return -1; 73 } 66 74 67 68 69 70 75 else if (strcmp(argv[_PyOS_optind], "--help") == 0) { 76 ++_PyOS_optind; 77 return 'h'; 78 } 71 79 72 73 74 75 80 else if (strcmp(argv[_PyOS_optind], "--version") == 0) { 81 ++_PyOS_optind; 82 return 'V'; 83 } 76 84 77 85 78 opt_ptr = &argv[_PyOS_optind++][1]; 79 86 opt_ptr = &argv[_PyOS_optind++][1]; 87 } 80 88 81 if ((option = *opt_ptr++) == '\0')82 89 if ((option = *opt_ptr++) == '\0') 90 return -1; 83 91 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 } 88 97 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 } 94 104 95 96 97 105 if ((ptr = strchr(optstring, option)) == NULL) { 106 if (_PyOS_opterr) 107 fprintf(stderr, "Unknown option: -%c\n", option); 98 108 99 100 109 return '_'; 110 } 101 111 102 103 104 105 106 112 if (*(ptr + 1) == ':') { 113 if (*opt_ptr != '\0') { 114 _PyOS_optarg = opt_ptr; 115 opt_ptr = ""; 116 } 107 117 108 109 110 111 112 113 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 } 115 125 116 117 118 126 _PyOS_optarg = argv[_PyOS_optind++]; 127 } 128 } 119 129 120 130 return option; 121 131 } 122 132
Note:
See TracChangeset
for help on using the changeset viewer.