1 /* subgetopt.c, subgetopt.h: (yet another) improved getopt clone, inner layer
2 D. J. Bernstein, djb@pobox.com.
4 No system requirements.
6 931129: Adapted from getopt.c.
7 No known patent problems.
9 Documentation in subgetopt.3.
12 #define SUBGETOPTNOSHORT
13 #include "subgetopt.h"
15 #define sgopt subgetopt
16 #define optind subgetoptind
17 #define optpos subgetoptpos
18 #define optarg subgetoptarg
19 #define optproblem subgetoptproblem
20 #define optdone subgetoptdone
26 int optdone
= SUBGETOPTDONE
;
28 int sgopt(argc
,argv
,opts
)
37 if (!argv
|| (optind
>= argc
) || !argv
[optind
]) return optdone
;
38 if (optpos
&& !argv
[optind
][optpos
]) {
41 if ((optind
>= argc
) || !argv
[optind
]) return optdone
;
44 if (argv
[optind
][0] != '-') return optdone
;
47 if ((c
== '-') || (c
== 0)) {
52 /* otherwise c is reassigned below */
54 c
= argv
[optind
][optpos
];
60 optarg
= argv
[optind
] + optpos
;
64 optarg
= argv
[optind
];
65 if ((optind
>= argc
) || !optarg
) { /* argument past end */