Speaking of testargs.c ... the "d::" part means that the argument for -d is *optional*. Currently, getopt() requires an argument (read: it doesn't understand double-colons).
Q: should it understand a double-colon? [ the man page for getopt() describes the double-colon ] Cheers, -g On Sat, Nov 25, 2000 at 10:34:04PM -0000, [EMAIL PROTECTED] wrote: > gstein 00/11/25 14:34:04 > > Modified: test testargs.c > Log: > add a "default:" case, just to be sure. > print out any additional arguments. > factor out the maybe_arg() functionality. > > Revision Changes Path > 1.16 +20 -7 apr/test/testargs.c > > Index: testargs.c > =================================================================== > RCS file: /home/cvs/apr/test/testargs.c,v > retrieving revision 1.15 > retrieving revision 1.16 > diff -u -u -r1.15 -r1.16 > --- testargs.c 2000/08/09 14:55:44 1.15 > +++ testargs.c 2000/11/25 22:34:04 1.16 > @@ -63,6 +63,16 @@ > #include <unistd.h> > #endif > > +static void maybe_arg(const char *arg) > +{ > + if (arg) { > + printf(" with %s\n", arg); > + } > + else { > + printf("\n"); > + } > +} > + > int main(int argc, char * const argv[]) > { > apr_pool_t *context; > @@ -80,7 +90,7 @@ > exit(1); > } > while (apr_getopt(opt, "abc:d::", &data, &optarg) == APR_SUCCESS) { > - switch(data) { > + switch (data) { > case 'a': > case 'b': > printf("option %c\n", data); > @@ -90,14 +100,17 @@ > break; > case 'd': > printf("option %c", data); > - if (optarg) { > - printf(" with %s\n", optarg); > - } > - else { > - printf("\n"); > - } > + maybe_arg(optarg); > break; > + default: > + printf("unknown option: %c", data); > + maybe_arg(optarg); > + break; > } > } > + > + while (opt->ind < opt->argc) > + printf("extra arg: %s\n", opt->argv[opt->ind++]); > + > return 1; > } > > > -- Greg Stein, http://www.lyra.org/