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): extract some code out of ParseDoDepend...



details:   https://anonhg.NetBSD.org/src/rev/5d828bda0989
branches:  trunk
changeset: 976212:5d828bda0989
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Sep 14 16:23:32 2020 +0000

description:
make(1): extract some code out of ParseDoDependency

With its almost 600 lines, that function is way too long.

diffstat:

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

diffs (87 lines):

diff -r a49500afeaf5 -r 5d828bda0989 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Mon Sep 14 16:16:52 2020 +0000
+++ b/usr.bin/make/parse.c      Mon Sep 14 16:23:32 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.310 2020/09/14 16:16:52 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.311 2020/09/14 16:23:32 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.310 2020/09/14 16:16:52 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.311 2020/09/14 16:23:32 rillig Exp $");
 
 /* types and constants */
 
@@ -1072,6 +1072,35 @@
     return 0;
 }
 
+/*
+ * We got to the end of the line while we were still looking at targets.
+ *
+ * Ending a dependency line without an operator is a Bozo no-no.  As a
+ * heuristic, this is also often triggered by undetected conflicts from
+ * cvs/rcs merges.
+ */
+static void
+ParseErrorNoDependency(const char *lstart, const char *line)
+{
+    if ((strncmp(line, "<<<<<<", 6) == 0) ||
+       (strncmp(line, "======", 6) == 0) ||
+       (strncmp(line, ">>>>>>", 6) == 0))
+       Parse_Error(PARSE_FATAL,
+                   "Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
+    else if (lstart[0] == '.') {
+       const char *dirstart = lstart + 1;
+       const char *dirend;
+       while (ch_isspace(*dirstart))
+           dirstart++;
+       dirend = dirstart;
+       while (ch_isalnum(*dirend) || *dirend == '-')
+           dirend++;
+       Parse_Error(PARSE_FATAL, "Unknown directive \"%.*s\"",
+                   (int)(dirend - dirstart), dirstart);
+    } else
+       Parse_Error(PARSE_FATAL, "Need an operator");
+}
+
 /* Parse a dependency line consisting of targets, followed by a dependency
  * operator, optionally followed by sources.
  *
@@ -1186,31 +1215,7 @@
        }
 
        if (!*cp) {
-           /*
-            * We got to the end of the line while we were still
-            * looking at targets.
-            *
-            * Ending a dependency line without an operator is a Bozo
-            * no-no.  As a heuristic, this is also often triggered by
-            * undetected conflicts from cvs/rcs merges.
-            */
-           if ((strncmp(line, "<<<<<<", 6) == 0) ||
-               (strncmp(line, "======", 6) == 0) ||
-               (strncmp(line, ">>>>>>", 6) == 0))
-               Parse_Error(PARSE_FATAL,
-                   "Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
-           else if (lstart[0] == '.') {
-               const char *dirstart = lstart + 1;
-               const char *dirend;
-               while (ch_isspace(*dirstart))
-                   dirstart++;
-               dirend = dirstart;
-               while (ch_isalnum(*dirend) || *dirend == '-')
-                   dirend++;
-               Parse_Error(PARSE_FATAL, "Unknown directive \"%.*s\"",
-                           (int)(dirend - dirstart), dirstart);
-           } else
-               Parse_Error(PARSE_FATAL, "Need an operator");
+           ParseErrorNoDependency(lstart, line);
            goto out;
        }
 



Home | Main Index | Thread Index | Old Index