home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CMDPARSE.ZIP / CPDEMO.C < prev    next >
Text File  |  1989-12-02  |  2KB  |  68 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "cmdparse.h"
  4.  
  5. main()
  6. {
  7.     int status,i;
  8.     char *cptr;
  9.  
  10.     printf("Demonstration of CMDPARSE.C - parse command line\n");
  11.  
  12.     status = cmd_init();                      /* setup */
  13.  
  14.     if (status == 0)
  15.     {
  16.         printf("\nError on call to cmd_init() - Abort\n\n");
  17.         exit(0);
  18.     }
  19.  
  20.     printf("\n============== List of Parameters ==================\n\n");
  21.  
  22.     for (i=0; (cptr = get_param(i)) != NULL; i++)
  23.         printf("Parameter # %d: %s\n",i,cptr);
  24.  
  25.     printf("\n============== List of All Options ==================\n\n");
  26.  
  27.     for (i=0; cmd_arg[i] != NULL; i++)
  28.         if (arg_type[i] == 1)
  29.             printf("%s\n",cmd_arg[i]);
  30.  
  31.     printf("\nPress RETURN to continue");
  32.  
  33.     getchar();
  34.  
  35.     printf("\n========= Case-insensitive Option Search ============\n\n");
  36.  
  37.     printf("Looking for N option     :  ");
  38.  
  39.     if (if_optioni("n") == 0) printf("NOT ");
  40.  
  41.     printf("Found\n");
  42.  
  43.     printf("Looking for INDEX option :  ");
  44.  
  45.     if (if_optioni("index") == 0) printf("NOT ");
  46.  
  47.     printf("Found      ");
  48.  
  49.     if ((cptr = opt_valuei("index")) != NULL)
  50.         printf("Value of INDEX is %s\n",cptr);
  51.     else
  52.         printf("INDEX has no Rvalue (/index=value)\n");
  53.  
  54.     printf("\n========= GET_PARAM for parameters 1 & 3 ============\n\n");
  55.  
  56.     cptr = get_param(1);
  57.  
  58.     if (cptr != NULL)
  59.        printf("First parameter is     %s\n",cptr);
  60.  
  61.     cptr = get_param(3);
  62.  
  63.     if (cptr != NULL)
  64.        printf("Third parameter is     %s\n\n",cptr);
  65.  
  66.     exit(0);
  67. }
  68.