1 /* sgetopt.c, sgetopt.h: (yet another) improved getopt clone, outer layer
2 D. J. Bernstein, djb@pobox.com.
3 Depends on subgetopt.h, buffer.h.
4 No system requirements.
5 19991219: Switched to buffer.h.
8 No known patent problems.
10 Documentation in sgetopt.3.
14 #define SGETOPTNOSHORT
16 #define SUBGETOPTNOSHORT
17 #include "subgetopt.h"
19 #define getopt sgetoptmine
20 #define optind subgetoptind
21 #define opterr sgetopterr
22 #define optproblem subgetoptproblem
23 #define optprogname sgetoptprogname
26 const char *optprogname
= 0;
28 int getopt(int argc
,char **argv
,const char *opts
)
35 if (!optprogname
) optprogname
= "";
36 for (s
= optprogname
;*s
;++s
) if (*s
== '/') optprogname
= s
+ 1;
38 c
= subgetopt(argc
,argv
,opts
);
41 char chp
[2]; chp
[0] = optproblem
; chp
[1] = '\n';
42 buffer_puts(buffer_2
,optprogname
);
43 if (argv
[optind
] && (optind
< argc
))
44 buffer_puts(buffer_2
,": illegal option -- ");
46 buffer_puts(buffer_2
,": option requires an argument -- ");
47 buffer_put(buffer_2
,chp
,2);
48 buffer_flush(buffer_2
);