]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.10/Python/getopt.c
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
37 int _PyOS_opterr
= 1; /* generate error messages */
38 int _PyOS_optind
= 1; /* index into argv array */
39 char *_PyOS_optarg
= NULL
; /* optional argument */
40 static char *opt_ptr
= "";
42 void _PyOS_ResetGetOpt(void)
50 int _PyOS_GetOpt(int argc
, char **argv
, char *optstring
)
55 if (*opt_ptr
== '\0') {
57 if (_PyOS_optind
>= argc
)
60 else if (strcmp(argv
[_PyOS_optind
], "/?") == 0) {
66 else if (argv
[_PyOS_optind
][0] != '-' ||
67 argv
[_PyOS_optind
][1] == '\0' /* lone dash */ )
70 else if (strcmp(argv
[_PyOS_optind
], "--") == 0) {
75 else if (strcmp(argv
[_PyOS_optind
], "--help") == 0) {
80 else if (strcmp(argv
[_PyOS_optind
], "--version") == 0) {
86 opt_ptr
= &argv
[_PyOS_optind
++][1];
89 if ((option
= *opt_ptr
++) == '\0')
94 fprintf(stderr
, "-J is reserved for Jython\n");
101 "-X is reserved for implementation-specific arguments\n");
105 if ((ptr
= strchr(optstring
, option
)) == NULL
) {
107 fprintf(stderr
, "Unknown option: -%c\n", option
);
112 if (*(ptr
+ 1) == ':') {
113 if (*opt_ptr
!= '\0') {
114 _PyOS_optarg
= opt_ptr
;
119 if (_PyOS_optind
>= argc
) {
122 "Argument expected for the -%c option\n", option
);
126 _PyOS_optarg
= argv
[_PyOS_optind
++];