Module Name:    src
Committed By:   rillig
Date:           Mon Oct  5 16:45:03 UTC 2020

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

Log Message:
make(1): extract the target parsing from ParseDoDependency


To generate a diff of this commit:
cvs rdiff -u -r1.364 -r1.365 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.364 src/usr.bin/make/parse.c:1.365
--- src/usr.bin/make/parse.c:1.364	Mon Oct  5 16:33:20 2020
+++ src/usr.bin/make/parse.c	Mon Oct  5 16:45:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.364 2020/10/05 16:33:20 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.365 2020/10/05 16:45:03 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.364 2020/10/05 16:33:20 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.365 2020/10/05 16:45:03 rillig Exp $");
 
 /* types and constants */
 
@@ -1463,62 +1463,18 @@ ParseDoDependencySourceSpecial(ParseSpec
     }
 }
 
-/* Parse a dependency line consisting of targets, followed by a dependency
- * operator, optionally followed by sources.
- *
- * The nodes of the sources are linked as children to the nodes of the
- * targets. Nodes are created as necessary.
- *
- * The operator is applied to each node in the global 'targets' list,
- * which is where the nodes found for the targets are kept, by means of
- * the ParseDoOp function.
- *
- * The sources are parsed in much the same way as the targets, except
- * that they are expanded using the wildcarding scheme of the C-Shell,
- * and all instances of the resulting words in the list of all targets
- * are found. Each of the resulting nodes is then linked to each of the
- * targets as one of its children.
- *
- * Certain targets and sources such as .PHONY or .PRECIOUS are handled
- * specially. These are the ones detailed by the specType variable.
- *
- * The storing of transformation rules such as '.c.o' is also taken care of
- * here. A target is recognized as a transformation rule by calling
- * Suff_IsTransform. If it is a transformation rule, its node is gotten
- * from the suffix module via Suff_AddTransform rather than the standard
- * Targ_FindNode in the target module.
- */
-static void
-ParseDoDependency(char *line)
-{
-    char *cp;			/* our current position */
-    GNodeType op;		/* the operator on the line */
-    char            savec;	/* a place to save a character */
-    SearchPathList *paths;	/* search paths to alter when parsing
-				 * a list of .PATH targets */
-    int tOp;			/* operator from special target */
-    GNodeList *sources;		/* archive sources after expansion */
-    StringList *curTargs;	/* target names to be found and added
-				 * to the targets list */
-    char	   *lstart = line;
-
-    /*
-     * specType contains the SPECial TYPE of the current target. It is Not
-     * if the target is unspecial. If it *is* special, however, the children
-     * are linked as children of the parent but not vice versa.
-     */
-    ParseSpecial specType = Not;
-
-    DEBUG1(PARSE, "ParseDoDependency(%s)\n", line);
-    tOp = 0;
-
-    paths = NULL;
-
-    curTargs = Lst_Init();
-
-    /*
-     * First, grind through the targets.
-     */
+static Boolean
+ParseDoDependencyTargets(char **const inout_cp,
+			 char **const inout_line,
+			 const char *const lstart,
+			 ParseSpecial *const inout_specType,
+			 GNodeType *const inout_tOp,
+			 SearchPathList **const inout_paths,
+			 StringList *const curTargs)
+{
+    char *cp = *inout_cp;
+    char *line = *inout_line;
+    char savec;
 
     for (;;) {
 	/*
@@ -1547,8 +1503,8 @@ ParseDoDependency(char *line)
 	     */
 	    if (!Arch_ParseArchive(&line, targets, VAR_CMD)) {
 		Parse_Error(PARSE_FATAL,
-			     "Error in archive specification: \"%s\"", line);
-		goto out;
+			    "Error in archive specification: \"%s\"", line);
+		return FALSE;
 	    } else {
 		/* Done with this word; on to the next. */
 		cp = line;
@@ -1558,23 +1514,24 @@ ParseDoDependency(char *line)
 
 	if (!*cp) {
 	    ParseErrorNoDependency(lstart, line);
-	    goto out;
+	    return FALSE;
 	}
 
 	/* Insert a null terminator. */
 	savec = *cp;
 	*cp = '\0';
 
-	if (!ParseDoDependencyTarget(line, &specType, &tOp, &paths))
-	    goto out;
+	if (!ParseDoDependencyTarget(line, inout_specType, inout_tOp,
+				     inout_paths))
+	    return FALSE;
 
 	/*
 	 * Have word in line. Get or create its node and stick it at
 	 * the end of the targets list
 	 */
-	if (specType == Not && *line != '\0') {
+	if (*inout_specType == Not && *line != '\0') {
 	    ParseDoDependencyTargetMundane(line, curTargs);
-	} else if (specType == ExPath && *line != '.' && *line != '\0') {
+	} else if (*inout_specType == ExPath && *line != '.' && *line != '\0') {
 	    Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line);
 	}
 
@@ -1585,7 +1542,7 @@ ParseDoDependency(char *line)
 	 * If it is a special type and not .PATH, it's the only target we
 	 * allow on this line...
 	 */
-	if (specType != Not && specType != ExPath) {
+	if (*inout_specType != Not && *inout_specType != ExPath) {
 	    ParseDoDependencyTargetExtraWarn(&cp, lstart);
 	} else {
 	    pp_skip_whitespace(&cp);
@@ -1597,6 +1554,71 @@ ParseDoDependency(char *line)
 	    break;
     }
 
+    *inout_cp = cp;
+    *inout_line = line;
+    return TRUE;
+}
+
+/* Parse a dependency line consisting of targets, followed by a dependency
+ * operator, optionally followed by sources.
+ *
+ * The nodes of the sources are linked as children to the nodes of the
+ * targets. Nodes are created as necessary.
+ *
+ * The operator is applied to each node in the global 'targets' list,
+ * which is where the nodes found for the targets are kept, by means of
+ * the ParseDoOp function.
+ *
+ * The sources are parsed in much the same way as the targets, except
+ * that they are expanded using the wildcarding scheme of the C-Shell,
+ * and all instances of the resulting words in the list of all targets
+ * are found. Each of the resulting nodes is then linked to each of the
+ * targets as one of its children.
+ *
+ * Certain targets and sources such as .PHONY or .PRECIOUS are handled
+ * specially. These are the ones detailed by the specType variable.
+ *
+ * The storing of transformation rules such as '.c.o' is also taken care of
+ * here. A target is recognized as a transformation rule by calling
+ * Suff_IsTransform. If it is a transformation rule, its node is gotten
+ * from the suffix module via Suff_AddTransform rather than the standard
+ * Targ_FindNode in the target module.
+ */
+static void
+ParseDoDependency(char *line)
+{
+    char *cp;			/* our current position */
+    GNodeType op;		/* the operator on the line */
+    char            savec;	/* a place to save a character */
+    SearchPathList *paths;	/* search paths to alter when parsing
+				 * a list of .PATH targets */
+    int tOp;			/* operator from special target */
+    GNodeList *sources;		/* archive sources after expansion */
+    StringList *curTargs;	/* target names to be found and added
+				 * to the targets list */
+    char	   *lstart = line;
+
+    /*
+     * specType contains the SPECial TYPE of the current target. It is Not
+     * if the target is unspecial. If it *is* special, however, the children
+     * are linked as children of the parent but not vice versa.
+     */
+    ParseSpecial specType = Not;
+
+    DEBUG1(PARSE, "ParseDoDependency(%s)\n", line);
+    tOp = 0;
+
+    paths = NULL;
+
+    curTargs = Lst_Init();
+
+    /*
+     * First, grind through the targets.
+     */
+    if (!ParseDoDependencyTargets(&cp, &line, lstart, &specType, &tOp, &paths,
+				  curTargs))
+	goto out;
+
     /*
      * Don't need the list of target names anymore...
      */

Reply via email to