1 /* this is a public domain version of getopt */
2 /* FTP Site: ftp.uu.net/pub/OS/unix/bsd-sources/lib/librpc/etc/getopt.c */
8 #define ERR(s, c) if(opterr){\
9 extern size_t strlen();\
12 errbuf[0] = c; errbuf[1] = '\n';\
13 (void) write(2, argv[0], strlen(argv[0]));\
14 (void) write(2, s, strlen(s));\
15 (void) write(2, errbuf, 2);}
23 getopt(argc
, argv
, opts
)
33 argv
[optind
][0] != '-' || argv
[optind
][1] == '\0')
35 else if(strcmp(argv
[optind
], "--") == MYNULL
) {
39 optopt
= c
= argv
[optind
][sp
];
40 if(c
== ':' || (cp
=strchr(opts
, c
)) == 0) {
41 ERR(": unknown option, -", c
);
42 if(argv
[optind
][++sp
] == '\0') {
49 if(argv
[optind
][sp
+1] != '\0')
50 optarg
= &argv
[optind
++][sp
+1];
51 else if(++optind
>= argc
) {
52 ERR(": argument missing for -", c
);
56 optarg
= argv
[optind
++];
59 if(argv
[optind
][++sp
] == '\0') {