Mercurial > cpython-lru_cache-weakref
diff Python/getopt.c @ 39073:c48b3a68f696 legacy-trunk
Accept long options "--help" and "--version".
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Wed, 12 Jul 2006 15:31:17 +0000 |
| parents | 2f3f2e32dfd9 |
| children | c1fa2e758e05 22a74eaf6b22 |
line wrap: on
line diff
--- a/Python/getopt.c Wed Jul 12 14:25:18 2006 +0000 +++ b/Python/getopt.c Wed Jul 12 15:31:17 2006 +0000 @@ -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 @@ 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 @@ 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 @@ if (_PyOS_opterr) fprintf(stderr, "Unknown option: -%c\n", option); - return '?'; + return '_'; } if (*(ptr + 1) == ':') { @@ -76,7 +99,7 @@ if (_PyOS_opterr) fprintf(stderr, "Argument expected for the -%c option\n", option); - return '?'; + return '_'; } _PyOS_optarg = argv[_PyOS_optind++];
