Module Name:    src
Committed By:   rillig
Date:           Mon Sep 14 16:23:33 UTC 2020

Modified Files:
        src/usr.bin/make: parse.c

Log Message:
make(1): extract some code out of ParseDoDependency

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


To generate a diff of this commit:
cvs rdiff -u -r1.310 -r1.311 src/usr.bin/make/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.310 src/usr.bin/make/parse.c:1.311
--- src/usr.bin/make/parse.c:1.310	Mon Sep 14 16:16:52 2020
+++ src/usr.bin/make/parse.c	Mon Sep 14 16:23:32 2020
@@ -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 @@ ParseClearPath(void *path, void *dummy M
     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 @@ ParseDoDependency(char *line)
 	}
 
 	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;
 	}
 

Reply via email to