1 /* sgetopt.c, sgetopt.h: (yet another) improved getopt clone, outer layer
2 D. J. Bernstein, djb@pobox.com.
3 Depends on subgetopt.h, substdio.h, subfd.h.
4 No system requirements.
7 No known patent problems.
9 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 char *optprogname = 0;
28 int getopt(argc,argv,opts)
38 if (!optprogname) optprogname = "";
39 for (s = optprogname;*s;++s) if (*s == '/') optprogname = s + 1;
41 c = subgetopt(argc,argv,opts);
44 char chp[2]; chp[0] = optproblem; chp[1] = '\n';
45 substdio_puts(subfderr,optprogname);
46 if (argv[optind] && (optind < argc))
47 substdio_puts(subfderr,": illegal option -- ");
49 substdio_puts(subfderr,": option requires an argument -- ");
50 substdio_put(subfderr,chp,2);
51 substdio_flush(subfderr);