Module Name:    src
Committed By:   rillig
Date:           Mon Sep 14 20:43:44 UTC 2020

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

Log Message:
make(1): inline character constants in var.c

This removes a level of indirection, and the macro names were quite
similar in appearance as well.  The macros may have been used by people
whose editors don't recognize C string and character literals when
navigating to the corresponding brace or parenthesis.  These editors had
already been confused before this commit since there are also string
literals with unbalanced parentheses, and there are far fewer
compensating comments such as /*{*/ or /*)*/ in the code.  In fact, the
only such comment that is left over was in for.c.

This way, there is now a single consistent way of writing these
character literals, which is without macros or comments, since that is
the simplest form.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/make/for.c
cvs rdiff -u -r1.520 -r1.521 src/usr.bin/make/var.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.83 src/usr.bin/make/for.c:1.84
--- src/usr.bin/make/for.c:1.83	Sun Sep 13 15:15:51 2020
+++ src/usr.bin/make/for.c	Mon Sep 14 20:43:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.83 2020/09/13 15:15:51 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.84 2020/09/14 20:43:44 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -60,7 +60,7 @@
 #include    "strlist.h"
 
 /*	"@(#)for.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: for.c,v 1.83 2020/09/13 15:15:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.84 2020/09/14 20:43:44 rillig Exp $");
 
 typedef enum {
     FOR_SUB_ESCAPE_CHAR = 0x0001,
@@ -424,7 +424,7 @@ ForIterate(void *v_arg, size_t *ret_len)
 	    Buf_AddBytesBetween(&cmds, cmd_cp, cp);
 	    Buf_AddStr(&cmds, "{:U");
 	    cmd_cp = ++cp;
-	    for_substitute(&cmds, &arg->items, arg->sub_next + i, /*{*/ '}');
+	    for_substitute(&cmds, &arg->items, arg->sub_next + i, '}');
 	    Buf_AddByte(&cmds, '}');
 	    break;
 	}

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.520 src/usr.bin/make/var.c:1.521
--- src/usr.bin/make/var.c:1.520	Mon Sep 14 07:04:56 2020
+++ src/usr.bin/make/var.c	Mon Sep 14 20:43:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.520 2020/09/14 07:04:56 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.521 2020/09/14 20:43:44 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
 #include    "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.520 2020/09/14 07:04:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.521 2020/09/14 20:43:44 rillig Exp $");
 
 #define VAR_DEBUG_IF(cond, fmt, ...)	\
     if (!(DEBUG(VAR) && (cond)))	\
@@ -262,11 +262,6 @@ typedef enum {
     VARP_ANCHOR_END	= 0x08	/* Match at end of word */
 } VarPatternFlags;
 
-#define BROPEN	'{'
-#define BRCLOSE	'}'
-#define PROPEN	'('
-#define PRCLOSE	')'
-
 /*-
  *-----------------------------------------------------------------------
  * VarFind --
@@ -1692,14 +1687,14 @@ ParseModifierPart(
 	 * No code should ever depend on these details, but who knows. */
 
 	varstart = p;		/* Nested variable, only parsed */
-	if (p[1] == PROPEN || p[1] == BROPEN) {
+	if (p[1] == '(' || p[1] == '{') {
 	    /*
 	     * Find the end of this variable reference
 	     * and suck it in without further ado.
 	     * It will be interpreted later.
 	     */
 	    int have = p[1];
-	    int want = have == PROPEN ? PRCLOSE : BRCLOSE;
+	    int want = have == '(' ? ')' : '}';
 	    int depth = 1;
 
 	    for (p += 2; *p != '\0' && depth > 0; p++) {
@@ -2828,7 +2823,7 @@ ApplyModifier_Assign(const char **pp, Ap
 	break;
     }
 
-    delim = st->startc == PROPEN ? PRCLOSE : BRCLOSE;
+    delim = st->startc == '(' ? ')' : '}';
     val = ParseModifierPart(pp, delim, st->eflags, st->ctxt, NULL, NULL, NULL);
     if (st->v->flags & VAR_JUNK) {
 	/* restore original name */
@@ -3468,7 +3463,7 @@ Var_Parse(const char **pp, GNode *ctxt, 
     endc = '\0';
 
     startc = start[1];
-    if (startc != PROPEN && startc != BROPEN) {
+    if (startc != '(' && startc != '{') {
 	char name[2];
 
 	/*
@@ -3503,7 +3498,7 @@ Var_Parse(const char **pp, GNode *ctxt, 
 	size_t namelen;
 	char *varname;
 
-	endc = startc == PROPEN ? PRCLOSE : BRCLOSE;
+	endc = startc == '(' ? ')' : '}';
 
 	p = start + 2;
 	varname = ParseVarname(&p, startc, endc, ctxt, eflags, &namelen);

Reply via email to