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): inline character constants in var.c
details: https://anonhg.NetBSD.org/src/rev/c206b8d0f38c
branches: trunk
changeset: 976228:c206b8d0f38c
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Sep 14 20:43:44 2020 +0000
description:
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.
diffstat:
usr.bin/make/for.c | 6 +++---
usr.bin/make/var.c | 19 +++++++------------
2 files changed, 10 insertions(+), 15 deletions(-)
diffs (101 lines):
diff -r a59dec86e441 -r c206b8d0f38c usr.bin/make/for.c
--- a/usr.bin/make/for.c Mon Sep 14 19:59:47 2020 +0000
+++ b/usr.bin/make/for.c Mon Sep 14 20:43:44 2020 +0000
@@ -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 @@
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;
}
diff -r a59dec86e441 -r c206b8d0f38c usr.bin/make/var.c
--- a/usr.bin/make/var.c Mon Sep 14 19:59:47 2020 +0000
+++ b/usr.bin/make/var.c Mon Sep 14 20:43:44 2020 +0000
@@ -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 @@
VARP_ANCHOR_END = 0x08 /* Match at end of word */
} VarPatternFlags;
-#define BROPEN '{'
-#define BRCLOSE '}'
-#define PROPEN '('
-#define PRCLOSE ')'
-
/*-
*-----------------------------------------------------------------------
* VarFind --
@@ -1692,14 +1687,14 @@
* 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 @@
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 @@
endc = '\0';
startc = start[1];
- if (startc != PROPEN && startc != BROPEN) {
+ if (startc != '(' && startc != '{') {
char name[2];
/*
@@ -3503,7 +3498,7 @@
size_t namelen;
char *varname;
- endc = startc == PROPEN ? PRCLOSE : BRCLOSE;
+ endc = startc == '(' ? ')' : '}';
p = start + 2;
varname = ParseVarname(&p, startc, endc, ctxt, eflags, &namelen);
Home |
Main Index |
Thread Index |
Old Index