home *** CD-ROM | disk | FTP | other *** search
- /* include - replace include file by contents of file */
- /* Version 1.2 1982/12/01 22:05 */
- /* 1982/10/09 22:57
- Original version from "Software Tools" by
- Kernighan & Plauger.
-
- This C version:
-
- Copyright 1982 William G. Hutchison, Jr.
- P.O. Box 278
- Exton, PA 19341-0278
- U.S.A.
-
- CompuServe 70665,1307
-
-
- This program may be used freely for any non-commercial
- purpose, provided that the user does not remove or alter
- this notice or the copyright statement.
- Those who wish to sell or lease this program, or to
- incorporate this into a product for sale or lease, should
- apply to the author (above) for licensing information.
- This program is not covered by a warranty, either
- express or implied. The author shall not be responsible for
- any damages (including consequential) caused by reliance on
- the materials presented, including but not limited to
- typographical errors or arithmetic errors.
-
- */
-
- /* max depth of include files: */
- #define MAINLY
- #define NFILES 5
- #include "a:c80def.h"
- #include "gets.c"
- #include "puts.c"
-
- #ifdef CP_M
- extern FILE *STDIN, *STDOUT;
- static FILE *STDERR;
- #endif
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- char line[MAXLINE], str[MAXLINE];
- int infile[NFILES];
- int len, level, loc;
- #define incl "#include"
-
- #ifdef CP_M
- STDERR= open("CON:", WRITE) /* delete for UNIX */;
- #endif
- infile[0]= STDIN;
- for (level= 0; level >= 0; level--) {
- while (fgets(line, MAXLINE, infile[level]) != NULL) {
- loc= 0;
- len= getwrd(line, &loc, str);
- if (equal(str, incl) == NO)
- call fputs(line, STDOUT);
- else {
- if (++level >= NFILES)
- call error("Includes nested too deeply.");
- len= getwrd(line, &loc, str);
- if ((infile[level]= open(str, READ)) == ERR)
- call cant(str);
- }
- }
- if (level > 0)
- call close(infile[level]);
- }
- } /* end of main */
-
- cant(s) /* can't open file message */
- char *s;
- {
- call fputs(s, STDERR);
- call error(": can't open.");
- } /* end of cant */
-
- equal(x, y) /* test two strings for equality */
- register char *x, *y;
- {
- for (; *x == *y; x++, y++)
- if (*x == EOS)
- return(YES);
- return (NO);
- } /* end of equal */
-
- error(s) /* print error message, then stop */
- char *s;
- {
- remark(s);
- exit();
- } /* end of error */
-
- /* getwrd gets the next word from the input line, advances the line
- index, and returns the word and the length of the word found */
- getwrd(in, i, out)
- char in[], out[];
- register int *i;
- {
- register int j;
-
- while (in[*i] == BLANK || in[*i] == TAB)
- (*i)++;
- j= 0;
- while (in[*i] != EOS &&
- in[*i] != BLANK &&
- in[*i] != TAB &&
- in[*i] != NEWLINE)
- out[j++]= in[(*i)++];
- out[j]= EOS;
- return(j);
- } /* end of getwrd */
-
- remark(s) /* print error message, then continue */
- char *s;
- {
- call fputs(s, STDERR);
- putc(NEWLINE, STDERR);
- } /* end of remark */