4 modified public-domain AT&T getopt(3)
13 # define STDERR_FILENO 2
15 extern int write (int fildes, char * buf, unsigned nbyte);
27 static void ERR (char ** argv, char * s, char c)
29 static void ERR (argv, s, c)
36 printf("DF_TRACE_DEBUG: static void ERR () in getopt.c\n");
42 (void) write(STDERR_FILENO,argv[0],strlen(argv[0]));
43 (void) write(STDERR_FILENO,s,strlen(s));
44 (void) write(STDERR_FILENO,errbuf,sizeof errbuf);
49 int getopt (int argc, char ** argv, char * opts)
51 int getopt (argc, argv, opts)
56 static int sp = 1, error = (int) '?';
57 static char sw = '-', eos = '\0', arg = ':';
58 register char c, * cp;
61 printf("DF_TRACE_DEBUG: int getopt () in getopt.c\n");
64 if (optind >= argc || argv[optind][0] != sw
65 || argv[optind][1] == eos)
67 else if (strcmp(argv[optind],"--") == 0)
74 if (c == arg || (cp = strchr(opts,c)) == NULL)
76 ERR(argv,": illegal option--",c);
77 if (argv[optind][++sp] == eos)
84 else if (*++cp == arg)
86 if (argv[optind][sp + 1] != eos)
87 optarg = &argv[optind++][sp + 1];
88 else if (++optind >= argc)
90 ERR(argv,": option requires an argument--",c);
95 optarg = argv[optind++];
100 if (argv[optind][++sp] == eos)