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): merge parameter of ParseRawLine into r...



details:   https://anonhg.NetBSD.org/src/rev/cea1446b9b7c
branches:  trunk
changeset: 947596:cea1446b9b7c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Dec 19 10:57:17 2020 +0000

description:
make(1): merge parameter of ParseRawLine into return value

diffstat:

 usr.bin/make/parse.c |  50 +++++++++++++++++++++++++++-----------------------
 1 files changed, 27 insertions(+), 23 deletions(-)

diffs (124 lines):

diff -r 458f30a4ef16 -r cea1446b9b7c usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Dec 19 10:49:36 2020 +0000
+++ b/usr.bin/make/parse.c      Sat Dec 19 10:57:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.492 2020/12/19 10:49:36 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.493 2020/12/19 10:57:17 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.492 2020/12/19 10:49:36 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.493 2020/12/19 10:57:17 rillig Exp $");
 
 /* types and constants */
 
@@ -2656,37 +2656,42 @@
        return TRUE;
 }
 
+typedef enum ParseRawLineResult {
+       PRLR_LINE,
+       PRLR_EOF,
+       PRLR_ERROR
+} ParseRawLineResult;
+
 /*
  * Parse until the end of a line, taking into account lines that end with
  * backslash-newline.
  */
-static Boolean
-ParseRawLine(char **out_line, char **out_line_end,
-            char **out_firstBackslash, char **out_firstComment,
-            Boolean *out_eof, IFile *const cf)
+static ParseRawLineResult
+ParseRawLine(IFile *curFile, char **out_line, char **out_line_end,
+            char **out_firstBackslash, char **out_firstComment)
 {
-       char *line = cf->buf_ptr;
+       char *line = curFile->buf_ptr;
        char *p = line;
        char *line_end = line;
        char *firstBackslash = NULL;
        char *firstComment = NULL;
-       Boolean eof = FALSE;
-
-       cf->lineno++;
+       ParseRawLineResult res = PRLR_LINE;
+
+       curFile->lineno++;
 
        for (;;) {
                char ch;
 
-               if (p == cf->buf_end) {
-                       eof = TRUE;
+               if (p == curFile->buf_end) {
+                       res = PRLR_EOF;
                        break;
                }
 
                ch = *p;
                if (ch == '\0' ||
-                   (ch == '\\' && p + 1 < cf->buf_end && p[1] == '\0')) {
+                   (ch == '\\' && p + 1 < curFile->buf_end && p[1] == '\0')) {
                        Parse_Error(PARSE_FATAL, "Zero byte read from file");
-                       return FALSE;
+                       return PRLR_ERROR;
                }
 
                /* Treat next character after '\' as literal. */
@@ -2694,7 +2699,7 @@
                        if (firstBackslash == NULL)
                                firstBackslash = p;
                        if (p[1] == '\n')
-                               cf->lineno++;
+                               curFile->lineno++;
                        p += 2;
                        line_end = p;
                        continue;
@@ -2718,12 +2723,11 @@
        }
 
        *out_line = line;
-       cf->buf_ptr = p;
+       curFile->buf_ptr = p;
        *out_line_end = line_end;
        *out_firstBackslash = firstBackslash;
        *out_firstComment = firstComment;
-       *out_eof = eof;
-       return TRUE;
+       return res;
 }
 
 /*
@@ -2794,8 +2798,7 @@
 static char *
 ParseGetLine(GetLineMode mode)
 {
-       IFile *cf = CurFile();
-       Boolean eof;
+       IFile *curFile = CurFile();
        char *line;
        char *line_end;
        char *firstBackslash;
@@ -2803,12 +2806,13 @@
 
        /* Loop through blank lines and comment lines */
        for (;;) {
-               if (!ParseRawLine(&line, &line_end,
-                   &firstBackslash, &firstComment, &eof, cf))
+               ParseRawLineResult res = ParseRawLine(curFile,
+                   &line, &line_end, &firstBackslash, &firstComment);
+               if (res == PRLR_ERROR)
                        return NULL;
 
                if (line_end == line || firstComment == line) {
-                       if (eof)
+                       if (res == PRLR_EOF)
                                return NULL;
                        /* Parse another line */
                        continue;



Home | Main Index | Thread Index | Old Index