4 modified public-domain AT&T getopt(3)
5 modified by Kurt Zeilenga for inclusion into OpenLDAP
14 #include <ac/string.h>
15 #include <ac/unistd.h>
22 static void ERR (char ** argv, char * s, char c)
27 printf("DF_TRACE_DEBUG: static void ERR () in getopt.c\n");
33 (void) write(STDERR_FILENO,argv[0],strlen(argv[0]));
34 (void) write(STDERR_FILENO,s,strlen(s));
35 (void) write(STDERR_FILENO,errbuf,sizeof errbuf);
39 int getopt (int argc, char ** argv, char * opts)
41 static int sp = 1, error = (int) '?';
42 static char sw = '-', eos = '\0', arg = ':';
43 register char c, * cp;
46 printf("DF_TRACE_DEBUG: int getopt () in getopt.c\n");
49 if (optind >= argc || argv[optind][0] != sw
50 || argv[optind][1] == eos)
52 else if (strcmp(argv[optind],"--") == 0)
59 if (c == arg || (cp = strchr(opts,c)) == NULL)
61 ERR(argv,": illegal option--",c);
62 if (argv[optind][++sp] == eos)
69 else if (*++cp == arg)
71 if (argv[optind][sp + 1] != eos)
72 optarg = &argv[optind++][sp + 1];
73 else if (++optind >= argc)
75 ERR(argv,": option requires an argument--",c);
80 optarg = argv[optind++];
85 if (argv[optind][++sp] == eos)
94 #endif /* HAVE_GETOPT */