s/qmail  3.3.23
Next generation secure email transport
sgetopt.c
Go to the documentation of this file.
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.
5 19970208: Cleanups.
6 931201: Baseline.
7 No known patent problems.
8 
9 Documentation in sgetopt.3.
10 */
11 
12 #include "substdio.h"
13 #include "subfd.h"
14 #define SGETOPTNOSHORT
15 #include "sgetopt.h"
16 #define SUBGETOPTNOSHORT
17 #include "subgetopt.h"
18 
19 #define getopt sgetoptmine
20 #define optind subgetoptind
21 #define opterr sgetopterr
22 #define optproblem subgetoptproblem
23 #define optprogname sgetoptprogname
24 
25 int opterr = 1;
26 char *optprogname = 0;
27 
28 int getopt(argc,argv,opts)
29 int argc;
30 char **argv;
31 char *opts;
32 {
33  int c;
34  char *s;
35 
36  if (!optprogname) {
37  optprogname = *argv;
38  if (!optprogname) optprogname = "";
39  for (s = optprogname;*s;++s) if (*s == '/') optprogname = s + 1;
40  }
41  c = subgetopt(argc,argv,opts);
42  if (opterr)
43  if (c == '?') {
44  char chp[2]; chp[0] = optproblem; chp[1] = '\n';
46  if (argv[optind] && (optind < argc))
47  substdio_puts(subfderr,": illegal option -- ");
48  else
49  substdio_puts(subfderr,": option requires an argument -- ");
50  substdio_put(subfderr,chp,2);
52  }
53  return c;
54 }
void c(char *home, char *subdir, char *file, int uid, int gid, int mode)
Definition: install.c:57
#define optind
Definition: sgetopt.c:20
int subgetopt()
int substdio_puts()
#define opterr
Definition: sgetopt.c:21
substdio * subfderr
Definition: subfderr.c:7
int substdio_put()
#define optproblem
Definition: sgetopt.c:22
int substdio_flush()
#define getopt
Definition: sgetopt.c:19
#define optprogname
Definition: sgetopt.c:23