From aff5b89ac9a0a973710ba273f3ff5fbb4fcbc431 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 6 Jun 1990 16:10:19 +0000 Subject: [PATCH] change flag -xs to -i, -xm to -m, dependencies --- lang/cem/cpp.ansi/Makefile | 2 ++ lang/cem/cpp.ansi/domacro.c | 7 ++-- lang/cem/cpp.ansi/idf.h | 8 +++-- lang/cem/cpp.ansi/macro.str | 1 + lang/cem/cpp.ansi/main.c | 67 +++++++++++++++++++++++++++++++++++++ lang/cem/cpp.ansi/ncpp.6 | 22 ++++++++++++ lang/cem/cpp.ansi/options.c | 26 +++++++++++--- 7 files changed, 125 insertions(+), 8 deletions(-) diff --git a/lang/cem/cpp.ansi/Makefile b/lang/cem/cpp.ansi/Makefile index 6abafe2c2..3c16e0f26 100644 --- a/lang/cem/cpp.ansi/Makefile +++ b/lang/cem/cpp.ansi/Makefile @@ -208,7 +208,9 @@ input.o: input.h input.o: inputtype.h main.o: arith.h main.o: file_info.h +main.o: idf.h main.o: idfsize.h +main.o: macro.h options.o: class.h options.o: idf.h options.o: idfsize.h diff --git a/lang/cem/cpp.ansi/domacro.c b/lang/cem/cpp.ansi/domacro.c index 9e6aef839..1690f89fa 100644 --- a/lang/cem/cpp.ansi/domacro.c +++ b/lang/cem/cpp.ansi/domacro.c @@ -35,6 +35,7 @@ char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */ int nestlevel = -1; int svnestlevel[30] = {-1}; int nestcount; +extern int do_preprocess; char * GetIdentifier(skiponerr) @@ -301,10 +302,12 @@ do_include() inctable[0] = WorkingDir; if (filenm) { if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){ - error("cannot open include file \"%s\"", filenm); + if (do_preprocess) error("cannot open include file \"%s\"", filenm); + else warning("cannot open include file \"%s\"", filenm); + add_dependency(filenm); } else { - if (filenm != result) free(filenm); + add_dependency(result); WorkingDir = getwdir(result); svnestlevel[++nestcount] = nestlevel; FileName = result; diff --git a/lang/cem/cpp.ansi/idf.h b/lang/cem/cpp.ansi/idf.h index c2bce70b2..d74051834 100644 --- a/lang/cem/cpp.ansi/idf.h +++ b/lang/cem/cpp.ansi/idf.h @@ -4,13 +4,17 @@ */ /* $Header$ */ struct id_usr { - struct macro *idu_macro; + union { + struct macro *idu_macro; + struct idf *idu_file; + } idu_x; int idu_resmac; }; #define IDF_TYPE struct id_usr #define IDF_HSIZE 6 -#define id_macro id_user.idu_macro +#define id_macro id_user.idu_x.idu_macro +#define id_file id_user.idu_x.idu_file #define id_resmac id_user.idu_resmac #include diff --git a/lang/cem/cpp.ansi/macro.str b/lang/cem/cpp.ansi/macro.str index 32b867c5e..16bc9f463 100644 --- a/lang/cem/cpp.ansi/macro.str +++ b/lang/cem/cpp.ansi/macro.str @@ -44,3 +44,4 @@ struct macro { #define K_LINE 10 #define K_PRAGMA 11 #define K_UNDEF 12 +#define K_FILE 100 /* for dependency generator */ diff --git a/lang/cem/cpp.ansi/main.c b/lang/cem/cpp.ansi/main.c index 1008665eb..9f7c1519c 100644 --- a/lang/cem/cpp.ansi/main.c +++ b/lang/cem/cpp.ansi/main.c @@ -6,15 +6,22 @@ /* MAIN PROGRAM */ #include +#include #include #include "arith.h" #include "file_info.h" #include "idfsize.h" +#include "idf.h" +#include "macro.h" extern char *symbol2str(); extern char *getwdir(); extern int err_occurred; +extern int do_dependencies; +extern char *dep_file; int idfsize = IDFSIZE; +extern char options[]; +static File *dep_fd = STDOUT; arith ifval; @@ -81,6 +88,66 @@ compile(argc, argv) source ? source : "stdin"); if (source) WorkingDir = getwdir(dummy); preprocess(source); + if (do_dependencies) list_dependencies(source); +} + +struct idf *file_head; +extern char *strrindex(); + +list_dependencies(source) + char *source; +{ + register struct idf *p = file_head; + + if (source) { + register char *s = strrindex(source, '.'); + + if (s && *(s+1)) { + s++; + *s++ = 'o'; + *s = '\0'; + /* the source may be in another directory than the + * object generated, so don't include the pathname + * leading to it. + */ + if (s = strrindex(source, '/')) { + source = s + 1; + } + } + else source = 0; + } + if (dep_file && !sys_open(dep_file, OP_WRITE, &dep_fd)) { + fatal("could not open %s", dep_file); + } + while (p) { + assert(p->id_resmac == K_FILE); + dependency(p->id_text, source); + p = p->id_file; + } +} + +add_dependency(s) + char *s; +{ + register struct idf *p = str2idf(s, 0); + + if (! p->id_resmac) { + p->id_resmac = K_FILE; + p->id_file = file_head; + file_head = p; + } +} + +dependency(s, source) + char *s, *source; +{ + if (options['i'] && !strncmp(s, "/usr/include/", 13)) { + return; + } + if (options['m'] && source) { + fprint(dep_fd, "%s: %s\n", source, s); + } + else fprint(dep_fd, "%s\n", s); } No_Mem() /* called by alloc package */ diff --git a/lang/cem/cpp.ansi/ncpp.6 b/lang/cem/cpp.ansi/ncpp.6 index 797ccabec..2a757428b 100644 --- a/lang/cem/cpp.ansi/ncpp.6 +++ b/lang/cem/cpp.ansi/ncpp.6 @@ -42,6 +42,28 @@ do not generate line directives .IP -\fBM\fIn\fR set maximum identifier length to .IR n . +.IP -\fBd\fR[\fIfile\fR] +.br +if \fIfile\fR is not given, do not preprocess, but instead generate a list +of makefile dependencies and write them to the standard output. +If \fIfile\fP is given, generate preprocessor output on standard output, +and generate the list of makefile dependencies on file \fIfile\fP. +.IP -\fBA\fR[\fIfile\fR] +identical to the -d option. +.IP -\fBi\fR +when generating makefile dependencies, do not include files from +/usr/include. +.IP -\fBm\fR +when generating makefile dependencies, generate them in the following format: +.RS +.IP "file.o: file1.h" +.RE +.IP "" +where "file.o" is derived from the source file name. Normally, only a list +of files included is generated. +.IP -\fBundef\fR +.br +this flag is silently ignored, for compatibility with other preprocessors. .PP The following names are always available. They cannot be the subject of a -U command line option or a #undef directive. diff --git a/lang/cem/cpp.ansi/options.c b/lang/cem/cpp.ansi/options.c index d3533d659..fe497411f 100644 --- a/lang/cem/cpp.ansi/options.c +++ b/lang/cem/cpp.ansi/options.c @@ -15,8 +15,10 @@ char options[128]; /* one for every char */ int inc_pos = 1; /* place where next -I goes */ int inc_max; int inc_total; -int debug; +int do_preprocess = 1; +int do_dependencies = 0; char **inctable; +char *dep_file = 0; extern int idfsize; int txt2int(); @@ -28,14 +30,30 @@ do_option(text) case '-': options[*text] = 1; break; + case 'u': + if (! strcmp(text, "ndef")) { + /* ignore -undef */ + break; + } + /* fall through */ default: error("illegal option: %c", text[-1]); break; - case 'o': /* ignore garbage after #else or #endif */ - options['o'] = 1; + case 'A' : /* for Amake */ + case 'd' : /* dependency generation */ + do_dependencies = 1; + if (*text) { + dep_file = text; + } + else { + do_preprocess = 0; + } break; + case 'i': + case 'm': + case 'o': /* ignore garbage after #else or #endif */ case 'C' : /* comment output */ - options['C'] = 1; + options[*(text-1)] = 1; break; case 'D' : /* -Dname : predefine name */ { -- 2.34.1