Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 53 lines (46 sloc) 1.341 kB
cbe7047 @bruceg Replaced many library with public-domain sources.
authored
1 /* Public domain, from ezmlm-0.53. */
a283642 @bruceg First check-in of development sources.
authored
2 /* sgetopt.c, sgetopt.h: (yet another) improved getopt clone, outer layer
3 D. J. Bernstein, djb@pobox.com.
4 Depends on subgetopt.h, substdio.h, subfd.h.
5 No system requirements.
6 19970208: Cleanups.
7 931201: Baseline.
8 No known patent problems.
9
10 Documentation in sgetopt.3.
11 */
12
13 #include "substdio.h"
14 #include "subfd.h"
15 #define SGETOPTNOSHORT
16 #include "sgetopt.h"
17 #define SUBGETOPTNOSHORT
18 #include "subgetopt.h"
19
20 #define getopt sgetoptmine
21 #define optind subgetoptind
22 #define opterr sgetopterr
23 #define optproblem subgetoptproblem
24 #define optprogname sgetoptprogname
25
26 int opterr = 1;
f6fc11d @bruceg Imported the const prototype definitions from the public domain sgeto…
authored
27 const char *optprogname = 0;
a283642 @bruceg First check-in of development sources.
authored
28
5602dcc @bruceg Relaxed the "const"s on the sgetoptmine prototype to eliminate several
authored
29 int getopt(int argc,char *const *argv,const char *opts)
a283642 @bruceg First check-in of development sources.
authored
30 {
31 int c;
f6fc11d @bruceg Imported the const prototype definitions from the public domain sgeto…
authored
32 const char *s;
a283642 @bruceg First check-in of development sources.
authored
33
34 if (!optprogname) {
35 optprogname = *argv;
36 if (!optprogname) optprogname = "";
37 for (s = optprogname;*s;++s) if (*s == '/') optprogname = s + 1;
38 }
5602dcc @bruceg Relaxed the "const"s on the sgetoptmine prototype to eliminate several
authored
39 c = subgetopt(argc,(const char *const*)argv,opts);
a283642 @bruceg First check-in of development sources.
authored
40 if (opterr)
41 if (c == '?') {
42 char chp[2]; chp[0] = optproblem; chp[1] = '\n';
43 substdio_puts(subfderr,optprogname);
44 if (argv[optind] && (optind < argc))
45 substdio_puts(subfderr,": illegal option -- ");
46 else
47 substdio_puts(subfderr,": option requires an argument -- ");
48 substdio_put(subfderr,chp,2);
49 substdio_flush(subfderr);
50 }
51 return c;
52 }
Something went wrong with that request. Please try again.