apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@locus.apache.org
Subject cvs commit: apr/test testargs.c
Date Sat, 25 Nov 2000 22:34:04 GMT
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;
   }
  
  
  

Mime
View raw message