home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / POPCLIIV.LHA / popcliIV / sources / umain.c < prev   
Encoding:
C/C++ Source or Header  |  1993-01-12  |  2.7 KB  |  111 lines

  1. /*      _main.c         Copyright (C) 1985  Lattice, Inc.       */
  2.  
  3. #define MAXARG 32
  4. #define QUOTE  '"'
  5. #define ESCAPE '*'
  6. #define ESC '\027'
  7. #define NL '\n'
  8.  
  9. #define isspace(c)      ((c == ' ')||(c == '\t') || (c == '\n'))
  10.  
  11.  
  12. extern void main(int, char**);
  13. static int argc;                       /* arg count */
  14. static char **targv, *argv[MAXARG];   /* arg pointers */
  15.  
  16. extern struct WBStartup *WBenchMsg;
  17.  
  18. /**
  19. *
  20. * name         _main - process command line, open files, and call "main"
  21. *
  22. * synopsis     _main(line);
  23. *              char *line;     ptr to command line that caused execution
  24. *
  25. * description   This function performs the standard pre-processing for
  26. *               the main module of a C program.  It accepts a command
  27. *               line of the form
  28. *
  29. *                       pgmname arg1 arg2 ...
  30. *
  31. *               and builds a list of pointers to each argument.  The first
  32. *               pointer is to the program name.  For some environments, the
  33. *               standard I/O files are also opened, using file names that
  34. *               were set up by the OS interface module XCMAIN.
  35. *
  36. **/
  37.  
  38. void _main(line)
  39. register char *line;
  40. {
  41.    register char **pargv;
  42.    char *argbuf;
  43.  
  44. /*
  45. *
  46. * Build argument pointer list
  47. *
  48. */
  49.    
  50.    while (argc < MAXARG)
  51.    {
  52.         while (isspace(*line))  line++;
  53.         if (*line == '\0')      break;
  54.         pargv = &argv[argc++];
  55.         if (*line == QUOTE)
  56.         {
  57.             argbuf = *pargv = ++line;  /* ptr inside quoted string */
  58.             while (*line != QUOTE && *line != 0)
  59.             {
  60.                if (*line == ESCAPE)
  61.                {
  62.                   line++;
  63.                   switch (*line)
  64.                   {
  65.                      case '0':
  66.                         *argbuf = 0;
  67.                         goto linedone;
  68.                      case 'E':
  69.                         *argbuf++ = ESC;
  70.                         break;
  71.                      case 'N':
  72.                         *argbuf++ = NL;
  73.                         break;
  74.                      default:
  75.                         *argbuf++ = *line;
  76.                   }
  77.                   line++;
  78.                }
  79.                else
  80.                {
  81.                  *argbuf++ = *line++;
  82.                }
  83.             }
  84.             line++;
  85.             *argbuf++ = '\0'; /* terminate arg */
  86.         }
  87.         else            /* non-quoted arg */
  88.         {       
  89.             *pargv = line;
  90.             while ((*line != '\0') && (!isspace(*line))) line++;
  91.             if (*line == '\0')  break;
  92.             else                *line++ = '\0';  /* terminate arg */
  93.         }
  94.    }  /* while */
  95.  
  96. linedone:
  97.  
  98.    targv = (argc == 0) ? (char **)WBenchMsg : (char **)&argv[0];
  99.  
  100.  
  101.  
  102. /*
  103. *
  104. * Call user's main program
  105. *
  106. */
  107.  
  108.    main(argc,targv);              /* call main function */
  109.    exit(0);
  110. }
  111.