Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): clean up parse.c



details:   https://anonhg.NetBSD.org/src/rev/28469ada2dd7
branches:  trunk
changeset: 942410:28469ada2dd7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Nov 07 22:25:19 2020 +0000

description:
make(1): clean up parse.c

The generated code stays exactly the same.  The only changes will be the
line numbers of assertions.  To preserve them, the removed lines have
been filled up with comments and will be removed in the follow-up commit.

diffstat:

 usr.bin/make/parse.c |  312 +++++++++++++++++++++++++-------------------------
 1 files changed, 156 insertions(+), 156 deletions(-)

diffs (truncated from 603 to 300 lines):

diff -r 099696d64678 -r 28469ada2dd7 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Nov 07 21:42:32 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Nov 07 22:25:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.429 2020/11/07 10:44:53 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.430 2020/11/07 22:25:19 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.429 2020/11/07 10:44:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.430 2020/11/07 22:25:19 rillig Exp $");
 
 /* types and constants */
 
@@ -373,14 +373,14 @@
 loadedfile_destroy(struct loadedfile *lf)
 {
        if (lf->buf != NULL) {
-               if (lf->maplen > 0) {
+               if (lf->maplen > 0)
                        munmap(lf->buf, lf->maplen);
-               } else {
+               else
                        free(lf->buf);
-               }
        }
        free(lf);
 }
+/* deleteme */
 
 /*
  * nextbuf() operation for loadedfile, as needed by the weird and twisted
@@ -391,9 +391,9 @@
 {
        struct loadedfile *lf = x;
 
-       if (lf->used) {
+       if (lf->used)
                return NULL;
-       }
+
        lf->used = TRUE;
        *len = lf->len;
        return lf->buf;
@@ -407,13 +407,11 @@
 {
        struct stat st;
 
-       if (fstat(fd, &st) < 0) {
+       if (fstat(fd, &st) < 0)
                return FALSE;
-       }
-
-       if (!S_ISREG(st.st_mode)) {
+
+       if (!S_ISREG(st.st_mode))
                return FALSE;
-       }
 
        /*
         * st_size is an off_t, which is 64 bits signed; *ret is
@@ -424,60 +422,63 @@
         *
         * While we're at it reject negative sizes too, just in case.
         */
-       if (st.st_size < 0 || st.st_size > 0x7fffffff) {
+       if (st.st_size < 0 || st.st_size > 0x7fffffff)
                return FALSE;
-       }
 
        *ret = (size_t)st.st_size;
        return TRUE;
 }
+/* deleteme */
+/* deleteme */
+/* deleteme */
 
 static Boolean
 loadedfile_mmap(struct loadedfile *lf, int fd)
 {
        static unsigned long pagesize = 0;
 
-       if (load_getsize(fd, &lf->len)) {
-
-               /* found a size, try mmap */
-               if (pagesize == 0)
-                       pagesize = (unsigned long)sysconf(_SC_PAGESIZE);
-               if (pagesize == 0 || pagesize == (unsigned long)-1) {
-                       pagesize = 0x1000;
-               }
-               /* round size up to a page */
-               lf->maplen = pagesize * ((lf->len + pagesize - 1) / pagesize);
-
-               /*
-                * XXX hack for dealing with empty files; remove when
-                * we're no longer limited by interfacing to the old
-                * logic elsewhere in this file.
-                */
-               if (lf->maplen == 0) {
-                       lf->maplen = pagesize;
-               }
-
-               /*
-                * FUTURE: remove PROT_WRITE when the parser no longer
-                * needs to scribble on the input.
-                */
-               lf->buf = mmap(NULL, lf->maplen, PROT_READ|PROT_WRITE,
-                              MAP_FILE|MAP_COPY, fd, 0);
-               if (lf->buf != MAP_FAILED) {
-                       /* succeeded */
-                       if (lf->len == lf->maplen && lf->buf[lf->len - 1] != '\n') {
-                               char *b = bmake_malloc(lf->len + 1);
-                               b[lf->len] = '\n';
-                               memcpy(b, lf->buf, lf->len++);
-                               munmap(lf->buf, lf->maplen);
-                               lf->maplen = 0;
-                               lf->buf = b;
-                       }
-                       return TRUE;
-               }
+       if (!load_getsize(fd, &lf->len))
+               return FALSE;
+
+       /* found a size, try mmap */
+       if (pagesize == 0)
+               pagesize = (unsigned long)sysconf(_SC_PAGESIZE);
+       if (pagesize == 0 || pagesize == (unsigned long)-1)
+               pagesize = 0x1000;
+
+       /* round size up to a page */
+       lf->maplen = pagesize * ((lf->len + pagesize - 1) / pagesize);
+
+       /*
+        * XXX hack for dealing with empty files; remove when
+        * we're no longer limited by interfacing to the old
+        * logic elsewhere in this file.
+        */
+       if (lf->maplen == 0)
+               lf->maplen = pagesize;
+
+       /*
+        * FUTURE: remove PROT_WRITE when the parser no longer
+        * needs to scribble on the input.
+        */
+       lf->buf = mmap(NULL, lf->maplen, PROT_READ|PROT_WRITE,
+                      MAP_FILE|MAP_COPY, fd, 0);
+       if (lf->buf == MAP_FAILED)
+               return FALSE;
+
+       if (lf->len == lf->maplen && lf->buf[lf->len - 1] != '\n') {
+               char *b = bmake_malloc(lf->len + 1);
+               b[lf->len] = '\n';
+               memcpy(b, lf->buf, lf->len++);
+               munmap(lf->buf, lf->maplen);
+               lf->maplen = 0;
+               lf->buf = b;
        }
-       return FALSE;
+
+       return TRUE;
 }
+/* deleteme */
+/* deleteme */
 
 /*
  * Read in a file.
@@ -486,8 +487,7 @@
  * being in the caller in another source file, we need to have the fd
  * passed in already open. Bleh.
  *
- * If the path is NULL use stdin and (to insure against fd leaks)
- * assert that the caller passed in -1.
+ * If the path is NULL, use stdin.
  */
 static struct loadedfile *
 loadfile(const char *path, int fd)
@@ -539,9 +539,9 @@
                        Error("%s: read error: %s", path, strerror(errno));
                        exit(1);
                }
-               if (result == 0) {
+               if (result == 0)
                        break;
-               }
+
                bufpos += (size_t)result;
        }
        assert(bufpos <= lf->len);
@@ -557,9 +557,9 @@
        }
 
 done:
-       if (path != NULL) {
+       if (path != NULL)
                close(fd);
-       }
+
        return lf;
 }
 
@@ -594,26 +594,26 @@
 static int
 ParseFindKeyword(const char *str)
 {
-    int start, end, cur;
-    int diff;
-
-    start = 0;
-    end = sizeof parseKeywords / sizeof parseKeywords[0] - 1;
+    int start = 0;
+    int end = sizeof parseKeywords / sizeof parseKeywords[0] - 1;
 
     do {
-       cur = start + (end - start) / 2;
-       diff = strcmp(str, parseKeywords[cur].name);
-
-       if (diff == 0) {
+       int cur = start + (end - start) / 2;
+       int diff = strcmp(str, parseKeywords[cur].name);
+
+       if (diff == 0)
            return cur;
-       } else if (diff < 0) {
+       if (diff < 0)
            end = cur - 1;
-       } else {
+       else
            start = cur + 1;
-       }
     } while (start <= end);
+
     return -1;
 }
+/* deleteme */
+/* deleteme */
+/* deleteme */
 
 static void
 PrintLocation(FILE *f, const char *filename, size_t lineno)
@@ -971,12 +971,12 @@
     gn = Targ_GetNode(src);
     if (doing_depend)
        ParseMark(gn);
-    if (tOp) {
+    if (tOp)
        gn->type |= tOp;
-    } else {
+    else
        LinkToTargets(gn, specType != SP_NOT);
-    }
 }
+/* deleteme */
 
 /* Given the name of a source in a dependency line, figure out if it is an
  * attribute (such as .SILENT) and apply it to the targets if it is. Else
@@ -1124,16 +1124,16 @@
 {
     switch (*inout_specType) {
     case SP_PATH:
-       if (*inout_paths == NULL) {
+       if (*inout_paths == NULL)
            *inout_paths = Lst_New();
-       }
        Lst_Append(*inout_paths, dirSearchPath);
        break;
+/* deleteme */
     case SP_MAIN:
-       if (!Lst_IsEmpty(opts.create)) {
+       if (!Lst_IsEmpty(opts.create))
            *inout_specType = SP_NOT;
-       }
        break;
+/* deleteme */
     case SP_BEGIN:
     case SP_END:
     case SP_STALE:
@@ -1185,12 +1185,12 @@
                    "Suffix '%s' not defined (yet)",
                    &line[5]);
        return FALSE;
-    } else {
-       if (*inout_paths == NULL) {
-           *inout_paths = Lst_New();
-       }
-       Lst_Append(*inout_paths, path);
     }
+
+    if (*inout_paths == NULL)
+       *inout_paths = Lst_New();
+    Lst_Append(*inout_paths, path);
+
     return TRUE;
 }
 
@@ -1273,19 +1273,19 @@
     Boolean warning = FALSE;



Home | Main Index | Thread Index | Old Index