Module Name:    src
Committed By:   rillig
Date:           Sun Oct 25 14:29:13 UTC 2020

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

Log Message:
make(1): extract GetEscapes from For_Eval


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/usr.bin/make/for.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/for.c
diff -u src/usr.bin/make/for.c:1.98 src/usr.bin/make/for.c:1.99
--- src/usr.bin/make/for.c:1.98	Sun Oct 25 13:51:56 2020
+++ src/usr.bin/make/for.c	Sun Oct 25 14:29:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.98 2020/10/25 13:51:56 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.99 2020/10/25 14:29:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -60,7 +60,7 @@
 #include    "make.h"
 
 /*	"@(#)for.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: for.c,v 1.98 2020/10/25 13:51:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.99 2020/10/25 14:29:13 rillig Exp $");
 
 typedef enum ForEscapes {
     FOR_SUB_ESCAPE_CHAR = 0x0001,
@@ -145,6 +145,30 @@ For_Free(For *arg)
     free(arg);
 }
 
+static ForEscapes
+GetEscapes(const char *word)
+{
+    const char *p;
+    ForEscapes escapes = 0;
+
+    for (p = word; *p != '\0'; p++) {
+	switch (*p) {
+	case ':':
+	case '$':
+	case '\\':
+	    escapes |= FOR_SUB_ESCAPE_CHAR;
+	    break;
+	case ')':
+	    escapes |= FOR_SUB_ESCAPE_PAREN;
+	    break;
+	case '}':
+	    escapes |= FOR_SUB_ESCAPE_BRACE;
+	    break;
+	}
+    }
+    return escapes;
+}
+
 /* Evaluate the for loop in the passed line. The line looks like this:
  *	.for <varname...> in <value...>
  *
@@ -242,32 +266,17 @@ For_Eval(const char *line)
     }
 
     {
-	size_t n;
+	size_t i;
 
-	for (n = 0; n < words.len; n++) {
+	for (i = 0; i < words.len; i++) {
+	    const char *word = words.words[i];
 	    ForEscapes escapes;
-	    char ch;
 
-	    ptr = words.words[n];
-	    if (ptr[0] == '\0')
-		continue;
-	    escapes = 0;
-	    while ((ch = *ptr++)) {
-		switch (ch) {
-		case ':':
-		case '$':
-		case '\\':
-		    escapes |= FOR_SUB_ESCAPE_CHAR;
-		    break;
-		case ')':
-		    escapes |= FOR_SUB_ESCAPE_PAREN;
-		    break;
-		case '}':
-		    escapes |= FOR_SUB_ESCAPE_BRACE;
-		    break;
-		}
-	    }
-	    ForAddItem(new_for, words.words[n], escapes);
+	    if (word[0] == '\0')
+		continue;	/* .for var in ${:U} */
+
+	    escapes = GetEscapes(word);
+	    ForAddItem(new_for, word, escapes);
 	}
     }
 

Reply via email to