1 /* ISC license. */ 2 3 #ifndef SGETOPT_H 4 #define SGETOPT_H 5 6 7 /* reentrant */ 8 9 typedef struct subgetopt_s subgetopt_t, *subgetopt_t_ref ; 10 struct subgetopt_s 11 { 12 int ind ; 13 int err ; 14 int problem ; 15 char const *arg ; 16 unsigned int pos ; 17 char const *prog ; 18 } ; 19 20 #define SUBGETOPT_ZERO { .ind = 1, .err = 1, .problem = 0, .arg = 0, .pos = 0, .prog = 0 } 21 22 extern int subgetopt_r (int, char const *const *, char const *, subgetopt_t *) ; 23 24 25 /* non-reentrant */ 26 27 extern int sgetopt_r (int, char const *const *, char const *, subgetopt_t *) ; 28 29 extern subgetopt_t subgetopt_here ; 30 31 #define subgetopt(argc, argv, opts) subgetopt_r((argc), (argv), (opts), &subgetopt_here) 32 #define sgetopt(argc, argv, opts) sgetopt_r((argc), (argv), (opts), &subgetopt_here) 33 #define sgetopt_prog() (subgetopt_here.prog = PROG) 34 35 /* define SUBGETOPT_SHORT if you don't mind potential name conflicts */ 36 37 #ifdef SUBGETOPT_SHORT 38 # define getopt sgetopt 39 # define optarg subgetopt_here.arg 40 # define optind subgetopt_here.ind 41 # define opterr subgetopt_here.err 42 # define optopt subgetopt_here.problem 43 # define opteof (-1) 44 #endif 45 46 #endif 47