Don't reference removed files in Makefile
[python/dscho.git] / Python / getopt.c
blobc08f07fa03bae0528f2b2710452bdbb0df758afe
1 /*---------------------------------------------------------------------------*
2 * <RCS keywords>
4 * C++ Library
6 * Copyright 1992-1994, David Gottner
8 * All Rights Reserved
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 #include <stdio.h>
28 #include <string.h>
30 #define bool int
31 #define TRUE 1
32 #define FALSE 0
35 bool opterr = TRUE; /* generate error messages */
36 int optind = 1; /* index into argv array */
37 char * optarg = NULL; /* optional argument */
40 int getopt(argc,argv,optstring)
41 int argc;
42 char *argv[];
43 char optstring[];
45 static char *opt_ptr = "";
46 register char *ptr;
47 int option;
49 if (*opt_ptr == '\0') {
51 if (optind >= argc || argv[optind][0] != '-')
52 return -1;
54 else if (strcmp(argv[optind], "--") == 0) {
55 ++optind;
56 return -1;
59 opt_ptr = &argv[optind++][1];
62 if ((ptr = strchr(optstring, option = *opt_ptr++)) == NULL) {
63 if (opterr)
64 fprintf(stderr, "Unknown option: -%c\n", option);
66 return '?';
69 if (*(ptr + 1) == ':') {
70 if (*opt_ptr != '\0') {
71 optarg = opt_ptr;
72 opt_ptr = "";
75 else {
76 if (optind >= argc) {
77 if (opterr)
78 fprintf(stderr,
79 "Argument expected for the -%c option\n", option);
80 return '?';
83 optarg = argv[optind++];
87 return option;