home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / cujv8a.arj / 8N03026A < prev    next >
Encoding:
Text File  |  1990-03-20  |  968 b   |  43 lines

  1. *****Listing 2*****
  2.  
  3. /* tcmdopts.c, c\lib\test
  4. *  Test cmd_options routine
  5. */
  6. #include <stdio.h>
  7. #include "cmd_opts.h"
  8.  
  9. main(argc, argv)
  10. int    argc;
  11. char    *argv[];
  12. {
  13.     int    cmd_errs, i;
  14.     static char    **barg, **darg;
  15.     static struct    options sw[] =
  16.         {'a',0,NULL,
  17.          'b',0,&barg,
  18.          'c',1,NULL,    /* generally useless */
  19.          'd',1,&darg,
  20.           0, 0,NULL};
  21.  
  22.     cmd_errs= cmd_options( & argc, argv, sw);
  23.     if (sw[0].arg_flg > 0)
  24.         printf("%d -a\n",sw[0].arg_flg);
  25.     for (i= 0; i < sw[1].arg_flg; i++)
  26.         printf("-b %s\n", barg[i]);
  27.     if (sw[2].arg_flg > 0)
  28.         printf("%d -c\n",sw[2].arg_flg);
  29.     for (i= 0; i < sw[3].arg_flg; i++)
  30.         printf("-d %s\n", darg[i]);
  31.     puts("Unclaimed:");
  32.     for (i= 1; i < argc; i++)    /* argv[0] is still
  33.                        the command */
  34.         printf(" %s",argv[i]);
  35.     puts("\n");
  36.     if (cmd_errs != 0)
  37.     {
  38.         printf("\7\ntcmdopts [-a] [-b<value>] -c -d<value> ...\n");
  39.         printf("\n%d Command line options invalid\n", -cmd_errs);
  40.         exit(1);
  41.     }
  42. }
  43.