1 /*---------------------------------------------------------------------------*
6 * Copyright 1992-1994, David Gottner
10 * Permission to use, copy, modify, and distribute this software and its
11 * documentation for any purpose and without fee is hereby granted,
12 * provided that the above copyright notice, this permission notice and
13 * the following disclaimer notice appear unmodified in all copies.
15 * I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL I
17 * BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER
19 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
20 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 * Nevertheless, I would like to know about bugs in this library or
23 * suggestions for improvment. Send bug reports and feedback to
24 * davegottner@delphi.com.
25 *---------------------------------------------------------------------------*/
27 /* Modified to support --help and --version, as well as /? on Windows
40 int _PyOS_opterr
= 1; /* generate error messages */
41 int _PyOS_optind
= 1; /* index into argv array */
42 wchar_t *_PyOS_optarg
= NULL
; /* optional argument */
44 int _PyOS_GetOpt(int argc
, wchar_t **argv
, wchar_t *optstring
)
46 static wchar_t *opt_ptr
= L
"";
50 if (*opt_ptr
== '\0') {
52 if (_PyOS_optind
>= argc
)
55 else if (wcscmp(argv
[_PyOS_optind
], L
"/?") == 0) {
61 else if (argv
[_PyOS_optind
][0] != L
'-' ||
62 argv
[_PyOS_optind
][1] == L
'\0' /* lone dash */ )
65 else if (wcscmp(argv
[_PyOS_optind
], L
"--") == 0) {
70 else if (wcscmp(argv
[_PyOS_optind
], L
"--help") == 0) {
75 else if (wcscmp(argv
[_PyOS_optind
], L
"--version") == 0) {
81 opt_ptr
= &argv
[_PyOS_optind
++][1];
84 if ( (option
= *opt_ptr
++) == L
'\0')
88 fprintf(stderr
, "-J is reserved for Jython\n");
94 "-X is reserved for implementation-specific arguments\n");
98 if ((ptr
= wcschr(optstring
, option
)) == NULL
) {
100 fprintf(stderr
, "Unknown option: -%c\n", (char)option
);
105 if (*(ptr
+ 1) == L
':') {
106 if (*opt_ptr
!= L
'\0') {
107 _PyOS_optarg
= opt_ptr
;
112 if (_PyOS_optind
>= argc
) {
115 "Argument expected for the -%c option\n", (char)option
);
119 _PyOS_optarg
= argv
[_PyOS_optind
++];