/** * * This module defines the standard C main function _main. * * This version processes the command-line specifiers which modify * the stack size or specify assignments for "stdin" and "stdout". * **/ #include "stdio.h" #include "ctype.h" #define MAXNAM 16 /* maximum filename size */ #define MAXARG 32 /* maximum command line arguments */ /** * * The following location defines the default stack size (bytes). It is * used by "sbrk" to call XCMEM to initialize the memory pool. * **/ extern int _stack; /** * * 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 [=stack] [outfile] parms * * and processes the three optional leading fields, builds * a list of pointers to the other parameters, and calls * the main function "main". The first optional field * specifies an override of the default stack size; "stack" * should be a decimal number of bytes. The second specifies * a file name for assignment to "stdin"; "infile" is the * file name. The third specifies, similarly, a file name * "outfile" for assignment to "stdout". Note that the * optional fields need not be specified in the order listed * above. * **/ _main(line) char *line; { int i; FILE *fp0, *fp1, *fp2; static int argc = 1; static char *outmode = "w"; static char inam[MAXNAM+1], onam[MAXNAM+1], tnam[1]; static char *argv[MAXARG]; while (isspace(*line)) line++; /* find program name */ for(argc = 0; argc < MAXARG; ) { switch(*line) { case '=': /* stack size specifier */ line++; _stack = 0; while (isdigit(*line)) _stack = 10*_stack + (*line++ & 15); break; case '<': /* input file specifier */ line++; for(i = 0; (*line != '\0') && (isspace(*line) == 0); line++) if (i': /* output file specifier */ line++; if (*line == '>') { /* output file to be appended to */ outmode = "a"; line++; } for (i = 0; (*line != '\0') && (isspace(*line) == 0); line++) if (i_flag |= _IONBF; if (onam[0] == '\0') fp1->_flag |= _IONBF; fp2->_flag |= _IONBF; main(argc, argv); /* call main function */ exit(0); } 0') fp1->_flag |= _IONBF; fp2->_flag |= _IONBF;