6
* Here's something you've all been waiting for: the AT&T public domain
7
* source for getopt(3). It is the code which was given out at the 1985
8
* UNIFORUM conference in Dallas. I obtained it by electronic mail
9
* directly from AT&T. The people there assure me that it is indeed
10
* in the public domain.
12
* There is no manual page. That is because the one they gave out at
13
* UNIFORUM was slightly different from the current System V Release 2
14
* manual page. The difference apparently involved a note about the
15
* famous rules 5 and 6, recommending using white space between an option
16
* and its first argument, and not grouping options that have arguments.
17
* Getopt itself is currently lenient about both of these things White
18
* space is allowed, but not mandatory, and the last option in a group can
19
* have an argument. That particular version of the man page evidently
20
* has no official existence, and my source at AT&T did not send a copy.
21
* The current SVR2 man page reflects the actual behavor of this getopt.
22
* However, I am not about to post a copy of anything licensed by AT&T.
41
void ERR(char *s, char c, char **argv)
48
/* (void) write(2, argv[0], (unsigned)strlen(argv[0]));
49
(void) write(2, s, (unsigned)strlen(s));
50
(void) write(2, errbuf, 2); */
51
(void) fwrite(argv[0], (unsigned)strlen(argv[0]),1,stderr);
52
(void) fwrite(s, (unsigned)strlen(s),1,stderr);
53
(void) fwrite(errbuf, 2, 1,stderr);
57
char *index2(char *str, char c)
65
int getoptions(int argc, char **argv, char *opts)
73
argv[optind][0] != '-' || argv[optind][1] == '\0')
75
else if(strcmp(argv[optind], "--") == 0) {
79
optopt = c = argv[optind][sp];
80
if(c == ':' || (cp=index2(opts, c)) == NULL) {
81
ERR(": illegal option -- ", c,argv);
82
if(argv[optind][++sp] == '\0') {
89
if(argv[optind][sp+1] != '\0')
90
optarg = &argv[optind++][sp+1];
91
else if(++optind >= argc) {
92
ERR(": option requires an argument -- ", c,argv);
96
optarg = argv[optind++];
99
if(argv[optind][++sp] == '\0') {