home *** CD-ROM | disk | FTP | other *** search
- /* _main.c Copyright (C) 1985 Lattice, Inc. */
-
- #define MAXARG 32
- #define QUOTE '"'
- #define ESCAPE '*'
- #define ESC '\027'
- #define NL '\n'
-
- #define isspace(c) ((c == ' ')||(c == '\t') || (c == '\n'))
-
-
- extern void main(int, char**);
- static int argc; /* arg count */
- static char **targv, *argv[MAXARG]; /* arg pointers */
-
- extern struct WBStartup *WBenchMsg;
-
- /**
- *
- * name _main - process command line, open files, and call "main"
- *
- * synopsis _main(line);
- * char *line; ptr to command line that caused execution
- *
- * description This function performs the standard pre-processing for
- * the main module of a C program. It accepts a command
- * line of the form
- *
- * pgmname arg1 arg2 ...
- *
- * and builds a list of pointers to each argument. The first
- * pointer is to the program name. For some environments, the
- * standard I/O files are also opened, using file names that
- * were set up by the OS interface module XCMAIN.
- *
- **/
-
- void _main(line)
- register char *line;
- {
- register char **pargv;
- char *argbuf;
-
- /*
- *
- * Build argument pointer list
- *
- */
-
- while (argc < MAXARG)
- {
- while (isspace(*line)) line++;
- if (*line == '\0') break;
- pargv = &argv[argc++];
- if (*line == QUOTE)
- {
- argbuf = *pargv = ++line; /* ptr inside quoted string */
- while (*line != QUOTE && *line != 0)
- {
- if (*line == ESCAPE)
- {
- line++;
- switch (*line)
- {
- case '0':
- *argbuf = 0;
- goto linedone;
- case 'E':
- *argbuf++ = ESC;
- break;
- case 'N':
- *argbuf++ = NL;
- break;
- default:
- *argbuf++ = *line;
- }
- line++;
- }
- else
- {
- *argbuf++ = *line++;
- }
- }
- line++;
- *argbuf++ = '\0'; /* terminate arg */
- }
- else /* non-quoted arg */
- {
- *pargv = line;
- while ((*line != '\0') && (!isspace(*line))) line++;
- if (*line == '\0') break;
- else *line++ = '\0'; /* terminate arg */
- }
- } /* while */
-
- linedone:
-
- targv = (argc == 0) ? (char **)WBenchMsg : (char **)&argv[0];
-
-
-
- /*
- *
- * Call user's main program
- *
- */
-
- main(argc,targv); /* call main function */
- exit(0);
- }
-