home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / DCFVBA.ZIP / DCFCMDL.C < prev    next >
Text File  |  1990-05-04  |  3KB  |  110 lines

  1. /**
  2. ***  This is a part of the PCL2VBA project.   This set of functions handle
  3. ***  The command line and the help information.
  4. **/
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "dcfvba.h"
  10.  
  11. /* -------------------------------------------------------------------------- */
  12.  
  13. void show_usage()
  14.    {
  15.    printf("Usage:  DCFVBA [options] PCL_file [VBA_file]\n");
  16.    printf("\twhere options are:\n");
  17.    printf("\t\t/L   output line length\n");
  18.    printf("\t\t/?   Show this usage screen.\n\n");
  19.    }
  20.  
  21. /* -------------------------------------------------------------------------- */
  22.  
  23. void parse_command_line(int argc, char *argv[])
  24.    {
  25.    int files = 0; /* number of files found on the command line */
  26.    int count;     /* index through the parameters */
  27.    if (argc == 1)
  28.       {
  29.       show_usage();
  30.       exit(0);
  31.       }
  32.    else
  33.       {
  34.  
  35.       /* Check for options */
  36.  
  37.       for (count = 1; count < argc; count++)
  38.          {
  39.          if ((*argv[count] == '/') || (*argv[count] == '-'))
  40.             {
  41.             switch (argv[count][1])
  42.                {
  43.                case '?':
  44.                   {
  45.                   show_usage();
  46.                   exit(0);
  47.                   }
  48.                case 'L':
  49.                case 'l':
  50.                   {
  51.                   char   number[10];
  52.                   char   *scanptr;
  53.                   int    i = 0;
  54.  
  55.                   scanptr = argv[count];
  56.                   scanptr += 2; /* Skip over the "/L" */
  57.                   while (number[i++] != '\0')
  58.                      number[i++] = *scanptr++;
  59.                   if ((line_length = atoi(number)) == 0)
  60.                      error(strcat("Invalid numeric in parameter string: ",number),16);
  61.                   break;
  62.                   }
  63.                default:
  64.                   {
  65.                   printf("Warning: Invalid flag argument \"%s\".\n",&argv[count][1]);
  66.                   break;
  67.                   }
  68.                } /* switch */
  69.             } /* if */
  70.          } /* for */
  71.  
  72.       /* Check for file names */
  73.  
  74.       for (count = 1; count < argc; count++)
  75.          {
  76.          if ((*argv[count] != '/') && (*argv[count] != '-'))
  77.             {
  78.             files++;
  79.             switch(files)
  80.                {
  81.                case 1: /* Input file */
  82.                   {
  83.                   if ((pcl_file = fopen(argv[count],"rt")) == NULL)
  84.                      error(strcat("Cannot open input file: ",argv[count]),16);
  85.                   break;
  86.                   }
  87.                case 2: /* Output file */
  88.                   {
  89.                   if ((vba_file = fopen(argv[count],"wt")) == NULL)
  90.                      error(strcat("Cannot open output file: ",argv[count]),16);
  91.                   break;
  92.                   }
  93.                default:
  94.                   {
  95.                   show_usage();
  96.                   error("Invalid number of parameters.",16);
  97.                   } /* default */
  98.                } /* switch */
  99.             } /* if */
  100.          } /* for */
  101.  
  102.       /* Make sure both files have been opened */
  103.  
  104.       if (files != 2)
  105.          error("Output file missing",16);
  106.  
  107.       } /* else */
  108.    return;
  109.    } /* parse_command_line */
  110.