diff options
author | Georg Brandl <georg@python.org> | 2006-07-12 15:31:17 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-07-12 15:31:17 (GMT) |
commit | 9dceedbb97396e2c4959b6bb9f78eee0d9049283 (patch) | |
tree | 61f791f407fc1b0f9540e761eac0ce51bd3a6e94 /Python/getopt.c | |
parent | 76c5af62166cc8cf225dc5b4868fde93f46a43b1 (diff) | |
download | cpython-9dceedbb97396e2c4959b6bb9f78eee0d9049283.zip cpython-9dceedbb97396e2c4959b6bb9f78eee0d9049283.tar.gz cpython-9dceedbb97396e2c4959b6bb9f78eee0d9049283.tar.bz2 |
Accept long options "--help" and "--version".
Diffstat (limited to 'Python/getopt.c')
-rw-r--r-- | Python/getopt.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/Python/getopt.c b/Python/getopt.c index 5429fac5..659efcf 100644 --- a/Python/getopt.c +++ b/Python/getopt.c @@ -24,6 +24,9 @@ * davegottner@delphi.com. *---------------------------------------------------------------------------*/ +/* Modified to support --help and --version, as well as /? on Windows + * by Georg Brandl. */ + #include <stdio.h> #include <string.h> @@ -43,8 +46,17 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring) if (*opt_ptr == '\0') { - if (_PyOS_optind >= argc || argv[_PyOS_optind][0] != '-' || - argv[_PyOS_optind][1] == '\0' /* lone dash */ ) + if (_PyOS_optind >= argc) + return -1; +#ifdef MS_WINDOWS + else if (strcmp(argv[_PyOS_optind], "/?") == 0) { + ++_PyOS_optind; + return 'h'; + } +#endif + + else if (argv[_PyOS_optind][0] != '-' || + argv[_PyOS_optind][1] == '\0' /* lone dash */ ) return -1; else if (strcmp(argv[_PyOS_optind], "--") == 0) { @@ -52,6 +64,17 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring) return -1; } + else if (strcmp(argv[_PyOS_optind], "--help") == 0) { + ++_PyOS_optind; + return 'h'; + } + + else if (strcmp(argv[_PyOS_optind], "--version") == 0) { + ++_PyOS_optind; + return 'V'; + } + + opt_ptr = &argv[_PyOS_optind++][1]; } @@ -62,7 +85,7 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring) if (_PyOS_opterr) fprintf(stderr, "Unknown option: -%c\n", option); - return '?'; + return '_'; } if (*(ptr + 1) == ':') { @@ -76,7 +99,7 @@ int _PyOS_GetOpt(int argc, char **argv, char *optstring) if (_PyOS_opterr) fprintf(stderr, "Argument expected for the -%c option\n", option); - return '?'; + return '_'; } _PyOS_optarg = argv[_PyOS_optind++]; |