Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make Pull every file parsing context into one struct...



details:   https://anonhg.NetBSD.org/src/rev/dc4f6377999e
branches:  trunk
changeset: 522577:dc4f6377999e
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Thu Feb 21 22:21:34 2002 +0000

description:
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:

 usr.bin/make/parse.c |  146 ++++++++++++++++++++++++--------------------------
 1 files changed, 70 insertions(+), 76 deletions(-)

diffs (truncated from 325 to 300 lines):

diff -r 146d250617a2 -r dc4f6377999e usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Thu Feb 21 22:15:28 2002 +0000
+++ b/usr.bin/make/parse.c      Thu Feb 21 22:21:34 2002 +0000
@@ -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 @@
     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 @@
        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 @@
        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 @@
      * 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 @@
      * 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 @@
        (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 @@
     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 @@
         * 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 @@
         * 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 = fopen(fullname, "r");
-       curPTR = NULL;
-       if (curFILE == NULL) {
+       curFile.F = fopen(fullname, "r");
+       curFile.P = NULL;
+
+       if (curFile.F == NULL) {
            if (!silent)
                ParseErrorInternal(cfname, clineno, PARSE_FATAL,
                    "Cannot open %s", fullname);
@@ -2168,21 +2160,22 @@
     }
 
     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 @@
 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 @@
 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 @@
                && c != EOF) {
             if (c == '\n') {
                 Buf_ReplaceLastByte(buf, (Byte)' ');
-                lineno++;
+                curFile.lineno++;
 
                 while ((c = ParseReadc()) == ' ' || c == '\t');
 
@@ -2274,7 +2267,7 @@
             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 @@
            ignComment = ignDepOp = TRUE;
            break;
        } else if (c == '\n') {
-           lineno++;
+           curFile.lineno++;
        } else if (c == '#') {
            ParseUnreadc(c);
            break;
@@ -2364,7 +2357,7 @@
                 * 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 @@
 
        }
     line_read:
-       lineno++;
+       curFile.lineno++;
 
        if (lastc != '\0') {
            Buf_AddByte (buf, (Byte)lastc);
@@ -2596,12 +2589,13 @@
                   *line;       /* the line we're working on */



Home | Main Index | Thread Index | Old Index