comparison Python/getopt.c @ 61465:e38335d4df91 2.6

Recorded merge of revisions 81029 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines Untabify C files. Will watch buildbots. ........
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 09 May 2010 15:15:40 +0000
parents 7c21cc14b94f
children 0abffbe7cf22
comparison
equal deleted inserted replaced
61461:b6e03ca8a206 61465:e38335d4df91
5 * 5 *
6 * Copyright 1992-1994, David Gottner 6 * Copyright 1992-1994, David Gottner
7 * 7 *
8 * All Rights Reserved 8 * All Rights Reserved
9 * 9 *
10 * Permission to use, copy, modify, and distribute this software and its 10 * Permission to use, copy, modify, and distribute this software and its
11 * documentation for any purpose and without fee is hereby granted, 11 * documentation for any purpose and without fee is hereby granted,
12 * provided that the above copyright notice, this permission notice and 12 * provided that the above copyright notice, this permission notice and
13 * the following disclaimer notice appear unmodified in all copies. 13 * the following disclaimer notice appear unmodified in all copies.
14 * 14 *
15 * I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 15 * I DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL I 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL I
38 int _PyOS_optind = 1; /* index into argv array */ 38 int _PyOS_optind = 1; /* index into argv array */
39 char *_PyOS_optarg = NULL; /* optional argument */ 39 char *_PyOS_optarg = NULL; /* optional argument */
40 40
41 int _PyOS_GetOpt(int argc, char **argv, char *optstring) 41 int _PyOS_GetOpt(int argc, char **argv, char *optstring)
42 { 42 {
43 static char *opt_ptr = ""; 43 static char *opt_ptr = "";
44 char *ptr; 44 char *ptr;
45 int option; 45 int option;
46 46
47 if (*opt_ptr == '\0') { 47 if (*opt_ptr == '\0') {
48 48
49 if (_PyOS_optind >= argc) 49 if (_PyOS_optind >= argc)
50 return -1; 50 return -1;
51 #ifdef MS_WINDOWS 51 #ifdef MS_WINDOWS
52 else if (strcmp(argv[_PyOS_optind], "/?") == 0) { 52 else if (strcmp(argv[_PyOS_optind], "/?") == 0) {
53 ++_PyOS_optind; 53 ++_PyOS_optind;
54 return 'h'; 54 return 'h';
55 } 55 }
56 #endif 56 #endif
57 57
58 else if (argv[_PyOS_optind][0] != '-' || 58 else if (argv[_PyOS_optind][0] != '-' ||
59 argv[_PyOS_optind][1] == '\0' /* lone dash */ ) 59 argv[_PyOS_optind][1] == '\0' /* lone dash */ )
60 return -1; 60 return -1;
61 61
62 else if (strcmp(argv[_PyOS_optind], "--") == 0) { 62 else if (strcmp(argv[_PyOS_optind], "--") == 0) {
63 ++_PyOS_optind; 63 ++_PyOS_optind;
64 return -1; 64 return -1;
65 } 65 }
66 66
67 else if (strcmp(argv[_PyOS_optind], "--help") == 0) { 67 else if (strcmp(argv[_PyOS_optind], "--help") == 0) {
68 ++_PyOS_optind; 68 ++_PyOS_optind;
69 return 'h'; 69 return 'h';
70 } 70 }
71 71
72 else if (strcmp(argv[_PyOS_optind], "--version") == 0) { 72 else if (strcmp(argv[_PyOS_optind], "--version") == 0) {
73 ++_PyOS_optind; 73 ++_PyOS_optind;
74 return 'V'; 74 return 'V';
75 } 75 }
76 76
77 77
78 opt_ptr = &argv[_PyOS_optind++][1]; 78 opt_ptr = &argv[_PyOS_optind++][1];
79 } 79 }
80 80
81 if ( (option = *opt_ptr++) == '\0') 81 if ( (option = *opt_ptr++) == '\0')
82 return -1; 82 return -1;
83 83
84 if (option == 'J') { 84 if (option == 'J') {
85 fprintf(stderr, "-J is reserved for Jython\n"); 85 fprintf(stderr, "-J is reserved for Jython\n");
86 return '_'; 86 return '_';
87 } 87 }
88 88
89 if (option == 'X') { 89 if (option == 'X') {
90 fprintf(stderr, 90 fprintf(stderr,
91 "-X is reserved for implementation-specific arguments\n"); 91 "-X is reserved for implementation-specific arguments\n");
92 return '_'; 92 return '_';
93 } 93 }
94 94
95 if ((ptr = strchr(optstring, option)) == NULL) { 95 if ((ptr = strchr(optstring, option)) == NULL) {
96 if (_PyOS_opterr) 96 if (_PyOS_opterr)
97 fprintf(stderr, "Unknown option: -%c\n", option); 97 fprintf(stderr, "Unknown option: -%c\n", option);
98 98
99 return '_'; 99 return '_';
100 } 100 }
101 101
102 if (*(ptr + 1) == ':') { 102 if (*(ptr + 1) == ':') {
103 if (*opt_ptr != '\0') { 103 if (*opt_ptr != '\0') {
104 _PyOS_optarg = opt_ptr; 104 _PyOS_optarg = opt_ptr;
105 opt_ptr = ""; 105 opt_ptr = "";
106 } 106 }
107 107
108 else { 108 else {
109 if (_PyOS_optind >= argc) { 109 if (_PyOS_optind >= argc) {
110 if (_PyOS_opterr) 110 if (_PyOS_opterr)
111 fprintf(stderr, 111 fprintf(stderr,
112 "Argument expected for the -%c option\n", option); 112 "Argument expected for the -%c option\n", option);
113 return '_'; 113 return '_';
114 } 114 }
115 115
116 _PyOS_optarg = argv[_PyOS_optind++]; 116 _PyOS_optarg = argv[_PyOS_optind++];
117 } 117 }
118 } 118 }
119 119
120 return option; 120 return option;
121 } 121 }
122 122
123 #ifdef __cplusplus 123 #ifdef __cplusplus
124 } 124 }
125 #endif 125 #endif