diff options
| author | reinoud <reinoud@NetBSD.org> | 2002-02-21 22:21:34 +0000 |
|---|---|---|
| committer | reinoud <reinoud@NetBSD.org> | 2002-02-21 22:21:34 +0000 |
| commit | 502866c1feb2a3f635fbb09d26cf7570dca92084 (patch) | |
| tree | 999d0fe3c2717d3e8db0afd1f2593772d8770fb5 /usr.bin/make | |
| parent | a9c374ed2667ed9ecd971189c561023391c2c369 (diff) | |
Pull every file parsing context into one structure instead of using a few
file global variables... adding an extra context variable is thus allmost
trivial now.
Diffstat (limited to 'usr.bin/make')
| -rw-r--r-- | usr.bin/make/parse.c | 146 |
1 files changed, 70 insertions, 76 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index b4be7d8ebca..73273e29999 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.81 2002/02/17 23:53:46 pk Exp $ */ +/* $NetBSD: parse.c,v 1.82 2002/02/21 22:21:34 reinoud Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -39,14 +39,14 @@ */ #ifdef MAKE_BOOTSTRAP -static char rcsid[] = "$NetBSD: parse.c,v 1.81 2002/02/17 23:53:46 pk Exp $"; +static char rcsid[] = "$NetBSD: parse.c,v 1.82 2002/02/21 22:21:34 reinoud Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: parse.c,v 1.81 2002/02/17 23:53:46 pk Exp $"); +__RCSID("$NetBSD: parse.c,v 1.82 2002/02/21 22:21:34 reinoud Exp $"); #endif #endif /* not lint */ #endif @@ -126,27 +126,25 @@ typedef struct { char *ptr; } PTR; -static char *fname; /* name of current file (for errors) */ -static int lineno; /* line number in current file */ -static FILE *curFILE = NULL; /* current makefile */ - -static PTR *curPTR = NULL; /* current makefile */ - static int fatals = 0; static GNode *mainNode; /* The main target to create. This is the * first target on the first dependency * line in the first makefile */ -/* - * Definitions for handling #include specifications - */ typedef struct IFile { char *fname; /* name of previous file */ int lineno; /* saved line number */ FILE * F; /* the open stream */ - PTR * p; /* the char pointer */ + PTR * P; /* the char pointer */ } IFile; +static IFile curFile; + + +/* + * Definitions for handling #include specifications + */ + static Lst includes; /* stack of IFiles generated by * #includes */ Lst parseIncPath; /* list of directories for "..." includes */ @@ -480,7 +478,7 @@ Parse_Error(va_alist) type = va_arg(ap, int); fmt = va_arg(ap, char *); #endif - ParseVErrorInternal(fname, lineno, type, fmt, ap); + ParseVErrorInternal(curFile.fname, curFile.lineno, type, fmt, ap); va_end(ap); } @@ -1816,7 +1814,7 @@ ParseDoInclude (line) char *prefEnd, *Fname; /* Make a temporary copy of this, to be safe. */ - Fname = estrdup(fname); + Fname = estrdup(curFile.fname); prefEnd = strrchr (Fname, '/'); if (prefEnd != (char *)NULL) { @@ -1876,11 +1874,8 @@ ParseDoInclude (line) * a very nice stack to track how we got here... */ oldFile = (IFile *) emalloc (sizeof (IFile)); - oldFile->fname = fname; - oldFile->F = curFILE; - oldFile->p = curPTR; - oldFile->lineno = lineno; + memcpy(oldFile, &curFile, sizeof (IFile)); (void) Lst_AtFront (includes, (ClientData)oldFile); @@ -1890,14 +1885,15 @@ ParseDoInclude (line) * name of the include file so error messages refer to the right * place. Naturally enough, we start reading at line number 0. */ - fname = fullname; - lineno = 0; + curFile.fname = fullname; + curFile.lineno = 0; + + ParseSetParseFile(curFile.fname); - ParseSetParseFile(fname); + curFile.F = fopen (fullname, "r"); + curFile.P = NULL; - curFILE = fopen (fullname, "r"); - curPTR = NULL; - if (curFILE == (FILE * ) NULL) { + if (curFile.F == (FILE * ) NULL) { if (!silent) Parse_Error (PARSE_FATAL, "Cannot open %s", fullname); /* @@ -1964,18 +1960,15 @@ Parse_FromString(str) (void) fprintf(stderr, "%s\n----\n", str); oldFile = (IFile *) emalloc (sizeof (IFile)); - oldFile->lineno = lineno; - oldFile->fname = fname; - oldFile->F = curFILE; - oldFile->p = curPTR; + memcpy(oldFile, &curFile, sizeof (IFile)); (void) Lst_AtFront (includes, (ClientData)oldFile); - curFILE = NULL; - curPTR = (PTR *) emalloc (sizeof (PTR)); - curPTR->str = curPTR->ptr = str; - lineno = 0; - fname = estrdup(fname); + curFile.F = NULL; + curFile.P = (PTR *) emalloc (sizeof (PTR)); + curFile.P->str = curFile.P->ptr = str; + curFile.lineno = 0; + curFile.fname = estrdup(curFile.fname); } @@ -2007,9 +2000,11 @@ ParseTraditionalInclude (line) int done = 0; int silent = (line[0] != 'i') ? 1 : 0; char *file = &line[silent + 7]; - char *cfname = fname; - size_t clineno = lineno; + char *cfname; + size_t clineno; + cfname = curFile.fname; + clineno = curFile.lineno; /* * Skip over whitespace @@ -2108,11 +2103,7 @@ ParseTraditionalInclude (line) * a very nice stack to track how we got here... */ oldFile = (IFile *) emalloc(sizeof(IFile)); - oldFile->fname = fname; - - oldFile->F = curFILE; - oldFile->p = curPTR; - oldFile->lineno = lineno; + memcpy(oldFile, &curFile, sizeof (IFile)); (void) Lst_AtFront(includes, (ClientData)oldFile); @@ -2122,12 +2113,13 @@ ParseTraditionalInclude (line) * absolute name of the include file so error messages refer to the * right place. Naturally enough, we start reading at line number 0. */ - fname = fullname; - lineno = 0; + curFile.fname = fullname; + curFile.lineno = 0; + + curFile.F = fopen(fullname, "r"); + curFile.P = NULL; - curFILE = fopen(fullname, "r"); - curPTR = NULL; - if (curFILE == NULL) { + if (curFile.F == NULL) { if (!silent) ParseErrorInternal(cfname, clineno, PARSE_FATAL, "Cannot open %s", fullname); @@ -2168,21 +2160,22 @@ ParseEOF (opened) } ifile = (IFile *) Lst_DeQueue (includes); - free ((Address) fname); - fname = ifile->fname; - lineno = ifile->lineno; - if (opened && curFILE) - (void) fclose (curFILE); - if (curPTR) { - free((Address) curPTR->str); - free((Address) curPTR); + + /* XXX dispose of curFile info */ + free ((Address) curFile.fname); + if (opened && curFile.F) + (void) fclose (curFile.F); + if (curFile.P) { + free((Address) curFile.P->str); + free((Address) curFile.P); } - curFILE = ifile->F; - curPTR = ifile->p; + + memcpy(&curFile, ifile, sizeof (IFile)); + free ((Address)ifile); /* pop the PARSEDIR/PARSEFILE variables */ - ParseSetParseFile(fname); + ParseSetParseFile(curFile.fname); return (CONTINUE); } @@ -2200,11 +2193,11 @@ ParseEOF (opened) static __inline int ParseReadc() { - if (curFILE) - return fgetc(curFILE); + if (curFile.F) + return fgetc(curFile.F); - if (curPTR && *curPTR->ptr) - return *curPTR->ptr++; + if (curFile.P && *curFile.P->ptr) + return *curFile.P->ptr++; return EOF; } @@ -2224,12 +2217,12 @@ static void ParseUnreadc(c) int c; { - if (curFILE) { - ungetc(c, curFILE); + if (curFile.F) { + ungetc(c, curFile.F); return; } - if (curPTR) { - *--(curPTR->ptr) = c; + if (curFile.P) { + *--(curFile.P->ptr) = c; return; } } @@ -2256,7 +2249,7 @@ ParseSkipLine(skip) && c != EOF) { if (c == '\n') { Buf_ReplaceLastByte(buf, (Byte)' '); - lineno++; + curFile.lineno++; while ((c = ParseReadc()) == ' ' || c == '\t'); @@ -2274,7 +2267,7 @@ ParseSkipLine(skip) return((char *)NULL); } - lineno++; + curFile.lineno++; Buf_AddByte(buf, (Byte)'\0'); line = (char *)Buf_GetAll(buf, &lineLength); } while (skip == 1 && line[0] != '.'); @@ -2334,7 +2327,7 @@ ParseReadLine () ignComment = ignDepOp = TRUE; break; } else if (c == '\n') { - lineno++; + curFile.lineno++; } else if (c == '#') { ParseUnreadc(c); break; @@ -2364,7 +2357,7 @@ test_char: * semi-colon and semiNL is TRUE, it will be recognized as a * newline in the code below this... */ - lineno++; + curFile.lineno++; lastc = ' '; while ((c = ParseReadc ()) == ' ' || c == '\t') { continue; @@ -2467,7 +2460,7 @@ test_char: } line_read: - lineno++; + curFile.lineno++; if (lastc != '\0') { Buf_AddByte (buf, (Byte)lastc); @@ -2596,12 +2589,13 @@ Parse_File(name, stream) *line; /* the line we're working on */ inLine = FALSE; - fname = name; - curFILE = stream; - lineno = 0; fatals = 0; - ParseSetParseFile(fname); + curFile.fname = name; + curFile.F = stream; + curFile.lineno = 0; + + ParseSetParseFile(curFile.fname); do { while ((line = ParseReadLine ()) != NULL) { @@ -2861,6 +2855,6 @@ static void ParseMark(gn) GNode *gn; { - gn->fname = strdup(fname); - gn->lineno = lineno; + gn->fname = strdup(curFile.fname); + gn->lineno = curFile.lineno; } |
