/* cpp.c */ /* Copyright (c) 1991 Xerox Corporation. All rights reserved */ /* front end processor for /lib/cpp */ /* ccc -Bstatic -g -o cpp cpp.c */ /* it's job is to teach cpp about tioga files: */ /* parses the cpp command line */ /* figures out the name of the file being compiled */ /* creates a stripped version of the file being compiled */ /* prepends the appropriate #file directive to that file */ /* invokes /lib/cpp on this temp file */ /* this "cpp" is normally invoked from ccc */ /* Notes: Eduardo wrote a cpp program which simply stopped scanning */ /* when the first null was encountered. The downside to this approach is */ /* it requires us to patch cpp's on each release. The other downside is that */ /* we've lost the sources of his patches. This is a replacement, but it isn't */ /* as functional as his original. In particular there isn't a way to support */ /* tioga formatting in .h files without reimplementing cpp. */ #include #include #include #include #include #include "/usr/5include/malloc.h" extern void exit(); static void error(s) char *s; { if (s != NULL) (void)fprintf(stderr, "cedar cpp: %s\n", s); exit(-1); } main(argc, argv) int argc; char **argv; { unsigned i, len, sourceFileIndex = 0; size_t totlen = 0; char c; char *realcpp = "/lib/cpp"; char *arg = NULL, *tempinfilename = NULL; FILE *tmpinfp, *cfile; /* parse the command line */ for (i = 1; i < argc; i++) { arg = argv[i]; len = strlen(arg); totlen = len + totlen; if (len > 2) { if (arg[len-2] == '.' && (arg[len-1] == 'c' || arg[len-1] == 'S')) { /* two source file files? ignore second one */ if (sourceFileIndex == 0) sourceFileIndex = i; } } } if (sourceFileIndex == 0) error("didn't find a source file to process"); /* open the source file */ if ((cfile = fopen(argv[sourceFileIndex], "r")) == NULL) error("couldn't open the source file"); /* open the temp file */ tempinfilename = tempnam(P_tmpdir, "ccppi"); tmpinfp = fopen(tempinfilename, "w"); if (tmpinfp == NULL) { (void)fclose(cfile); error("couldn't open the in temp file"); }; /* stream the source file into the temp in file with mods */ if (fprintf(tmpinfp, "\#\ 1 \"%s\"\n", argv[sourceFileIndex]) == EOF) error("fprintf failed"); while ((c = getc(cfile)) != EOF && c != '\0' ) { if (c == '\015') c = '\012'; if (putc(c, tmpinfp) == EOF) error("fputc failed"); } (void)fclose(cfile); (void)fclose(tmpinfp); /* prepend the correct # line directive */ if (printf("\#\ 1 \"%s\"\n", argv[sourceFileIndex]) == EOF) error("printf failed"); if (fflush(stdout) == EOF) error("fflush failed"); /* build the new command line */ argv[sourceFileIndex] = tempinfilename; argv[0] = realcpp; if (fork() == 0) {/* child */ /* invoke the real cpp */ (void)execvp(realcpp, argv); return(-1); } else { /* parent */ int statusp = 0; /* wait for the real cpp to finish */ (void)wait(&statusp); if (unlink(tempinfilename) == -1) error("unlink failed"); free((void *)tempinfilename); return(WEXITSTATUS(statusp)); } }  Κ‰•NewlineDelimiter – "cedar" style™J˜ JšœΟnœ ˜&J˜"J˜1JšœΟzœ˜!J˜5J˜;J˜;J˜(J˜-J˜JšœF˜FJ˜KJ˜PJ˜QJ˜PJ˜>J˜Jšœžœ ˜Jšœžœ ˜Jšœžœ˜Jšœžœ˜Jšœžœ ˜Jšœžœ˜!J˜Jšœœžœ˜J˜Jšœœžœ˜Jšœ˜˜Jš œΠkzœœžœžœ˜;Jšžœ˜ —J˜J˜Jšžœ ˜Jšœ˜ Jšœ˜ ˜Jšœ˜%J˜Jšœ˜Jšœ˜JšœŸœŸœ˜*JšŸœ˜J˜Jšœžœ˜šœ˜J˜J˜J˜šœ ˜šœB˜DJ˜.Jšœ,˜.J˜—J˜—J˜—šœžœ)˜HJ˜—J˜šœ žœ!Ÿœ˜9Jšžœ"˜'J˜—J˜J˜,Jšœ žœ˜%šœ Ÿœ˜Jšœœžœ˜Jšžœ#˜(J˜—J˜J˜<šœžœ6Οkœ˜EJšžœ˜—šœžœ  œ˜0Jšœ˜Jšœžœ œžœ˜3J˜—Jšœœžœ˜Jšœœžœ ˜J˜Jšœžœ ˜*šœžœ- œ˜