int MAIN(int argc, char** argv) { int i; char** useargv; char** pfargv; if( nRunde == 0 ) { pCppIn = stdin; pCppOut = stdout; } nRunde++; InitCpp1(); InitCpp2(); InitCpp3(); InitCpp4(); InitCpp5(); InitCpp6(); #if HOST == SYS_VMS argc = getredirection(argc, argv); /* vms >file and <file */ #endif initdefines(); /* O.S. specific def's */ if ( argv[argc-1][0] == '@' ) { i = readoptions( argv[1], &pfargv ); /* Command file */ useargv=pfargv; } else { i = dooptions(argc, argv); /* Command line -flags */ useargv=argv; } switch (i) { #if OSL_DEBUG_LEVEL > 1 case 4: if ( bDumpDefs ) { /* * Get defBase file, "-" means use stdout. */ if (!streq(useargv[3], "-")) { #if HOST == SYS_VMS /* * On vms, reopen stdout with "vanilla rms" attributes. */ if ((i = creat(useargv[3], 0, "rat=cr", "rfm=var")) == -1 || dup2(i, fileno(stdout)) == -1) #else pDefOut = fopen( useargv[3], "w" ); if( pDefOut == NULL ) #endif { perror(useargv[3]); cerror("Can't open output file \"%s\"", useargv[3]); exit(IO_ERROR); } } /* Continue by opening output */ } #endif case 3: /* * Get output file, "-" means use stdout. */ if (!streq(useargv[2], "-")) { #if HOST == SYS_VMS /* * On vms, reopen stdout with "vanilla rms" attributes. */ if ((i = creat(useargv[2], 0, "rat=cr", "rfm=var")) == -1 || dup2(i, fileno(stdout)) == -1) #else pCppOut = fopen( useargv[2], "w" ); if( pCppOut == NULL ) #endif { perror(useargv[2]); cerror("Can't open output file \"%s\"", useargv[2]); exit(IO_ERROR); } } /* Continue by opening input */ case 2: /* One file -> stdin */ /* * Open input file, "-" means use stdin. */ if (!streq(useargv[1], "-")) { pCppIn = fopen( useargv[1], "r" ); if( pCppIn == NULL) { perror(useargv[1]); cerror("Can't open input file \"%s\"", useargv[1]); exit(IO_ERROR); } strncpy(work, useargv[1], NWORK); /* Remember input filename */ break; } /* Else, just get stdin */ case 0: /* No args? */ case 1: /* No files, stdin -> stdout */ #if (HOST == SYS_UNIX) || (HOST == SYS_UNKNOWN) work[0] = EOS; /* Unix can't find stdin name */ #else fgetname(stdin, work); /* Vax-11C, Decus C know name */ #endif break; default: exit(IO_ERROR); /* Can't happen */ } setincdirs(); /* Setup -I include directories */ addfile( pCppIn, work); /* "open" main input file */ #if OSL_DEBUG_LEVEL > 1 if (debug > 0 || bDumpDefs) dumpdef("preset #define symbols"); #endif if( pCppIn != stdin ) rewind( pCppIn ); cppmain(); /* Process main file */ if ((i = (ifptr - &ifstack[0])) != 0) { #if OLD_PREPROCESSOR ciwarn("Inside #ifdef block at end of input, depth = %d", i); #else cierror("Inside #ifdef block at end of input, depth = %d", i); #endif } #if OSL_DEBUG_LEVEL > 1 if( pDefOut != stdout && pDefOut != stderr ) fclose( pDefOut ); #endif if( pCppOut != stdout && pCppOut != stderr ) fclose( pCppOut ); if (errors > 0) { fprintf(stderr, (errors == 1) ? "%d error in preprocessor\n" : "%d errors in preprocessor\n", errors); if (!eflag) exit(IO_ERROR); } #ifdef NOMAIN /* BP */ /* kein exit im der LIB-Version */ return( IO_NORMAL ); #else exit(IO_NORMAL); /* No errors or -E option set */ #endif }
int fppPreProcess(struct fppTag *tags) { int i=0; ReturnCode ret; /* cpp return code */ struct Global *global; global=(struct Global *)malloc(sizeof(struct Global)); if(!global) return(FPP_OUT_OF_MEMORY); memset(global, 0, sizeof(struct Global)); global->infile=NULL; global->line=0; global->wrongline=0; global->errors=0; global->recursion=0; global->rec_recover=TRUE; global->instring=FALSE; global->inmacro=FALSE; global->workp=NULL; global->keepcomments = FALSE; /* Write out comments flag */ global->cflag = FALSE; /* -C option (keep comments) */ global->eflag = FALSE; /* -E option (never fail) */ global->nflag = 0; /* -N option (no predefines) */ global->wflag = FALSE; /* -W option (write #defines) */ global->ifstack[0]=TRUE; /* #if information */ global->ifptr = global->ifstack; global->incend = global->incdir; /* names defined at cpp start */ global->preset[0]="frexxcpp"; /* This is the Frexx cpp program */ #if defined( unix ) global->preset[1]="unix"; global->preset[2]= NULL; #endif /* Note: order is important */ global->magic[0] = "__LINE__"; global->magic[1] = "__FILE__"; global->magic[2] = "__FUNCTION__"; global->magic[3] = "__FUNC_LINE__"; global->magic[4] = NULL; /* Must be last */ global->funcline = 0; global->cplusplus=1; global->sharpfilename=NULL; global->parmp=NULL; global->nargs=0; global->macro=NULL; global->evalue=0; global->error=NULL; global->first_file=NULL; global->linelines=TRUE; global->warnillegalcpp = FALSE; global->outputLINE = TRUE; global->warnnoinclude = TRUE; global->showversion = TRUE; global->showincluded = FALSE; global->showspace = FALSE; global->nestcomments = FALSE; global->warnnestcomments = FALSE; global->outputfile = TRUE; global->included = 0; global->comment = FALSE; global->rightconcat = FALSE; global->work[0] = '\0'; global->initialfunc = NULL; memset(global->symtab, 0, SBSIZE * sizeof(DEFBUF *)); ret=initdefines(global); /* O.S. specific def's */ if(ret) return(ret); dooptions(global, tags); /* Command line -flags */ ret=addfile(global, global->inputio, global->work); /* "open" main input file */ global->out = global->outputfile; if(!ret) ret=cppmain(global); /* Process main file */ if ((i = (int)(global->ifptr - global->ifstack)) != 0) { #if OLD_PREPROCESSOR cwarn(global, ERROR_IFDEF_DEPTH, i); #else cerror(global, ERROR_IFDEF_DEPTH, i); #endif } if (global->errors > 0 && !global->eflag) return(IO_ERROR); return(IO_NORMAL); /* No errors or -E option set */ }