Module Name: src
Committed By: rillig
Date: Sat Aug 8 19:13:40 UTC 2020
Modified Files:
src/usr.bin/make: var.c
Log Message:
make(1): merge duplicate code for the :H :T :R :E modifiers
By setting modifyWord first, the rest of the code becomes exactly the
same and is merged by the compiler.
To generate a diff of this commit:
cvs rdiff -u -r1.433 -r1.434 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/var.c
diff -u src/usr.bin/make/var.c:1.433 src/usr.bin/make/var.c:1.434
--- src/usr.bin/make/var.c:1.433 Sat Aug 8 18:54:04 2020
+++ src/usr.bin/make/var.c Sat Aug 8 19:13:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.433 2020/08/08 18:54:04 rillig Exp $ */
+/* $NetBSD: var.c,v 1.434 2020/08/08 19:13:39 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.433 2020/08/08 18:54:04 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.434 2020/08/08 19:13:39 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.433 2020/08/08 18:54:04 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.434 2020/08/08 19:13:39 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -2898,6 +2898,21 @@ ApplyModifier_Remember(const char **pp,
return AMR_OK;
}
+/* Apply the given function to each word of the variable value. */
+static ApplyModifierResult
+ApplyModifier_WordFunc(const char **pp, ApplyModifiersState *st,
+ ModifyWordsCallback modifyWord)
+{
+ char delim = (*pp)[1];
+ if (delim != st->endc && delim != ':')
+ return AMR_UNKNOWN;
+
+ st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord,
+ st->val, modifyWord, NULL);
+ (*pp)++;
+ return AMR_OK;
+}
+
#ifdef SYSVVARSUB
/* :from=to */
static ApplyModifierResult
@@ -3122,40 +3137,16 @@ ApplyModifiers(
res = AMR_UNKNOWN;
break;
case 'T':
- if (p[1] == st.endc || p[1] == ':') {
- st.newVal = ModifyWords(st.ctxt, st.sep, st.oneBigWord,
- st.val, ModifyWord_Tail, NULL);
- p++;
- res = AMR_OK;
- } else
- res = AMR_UNKNOWN;
+ res = ApplyModifier_WordFunc(&p, &st, ModifyWord_Tail);
break;
case 'H':
- if (p[1] == st.endc || p[1] == ':') {
- st.newVal = ModifyWords(st.ctxt, st.sep, st.oneBigWord,
- st.val, ModifyWord_Head, NULL);
- p++;
- res = AMR_OK;
- } else
- res = AMR_UNKNOWN;
+ res = ApplyModifier_WordFunc(&p, &st, ModifyWord_Head);
break;
case 'E':
- if (p[1] == st.endc || p[1] == ':') {
- st.newVal = ModifyWords(st.ctxt, st.sep, st.oneBigWord,
- st.val, ModifyWord_Suffix, NULL);
- p++;
- res = AMR_OK;
- } else
- res = AMR_UNKNOWN;
+ res = ApplyModifier_WordFunc(&p, &st, ModifyWord_Suffix);
break;
case 'R':
- if (p[1] == st.endc || p[1] == ':') {
- st.newVal = ModifyWords(st.ctxt, st.sep, st.oneBigWord,
- st.val, ModifyWord_Root, NULL);
- p++;
- res = AMR_OK;
- } else
- res = AMR_UNKNOWN;
+ res = ApplyModifier_WordFunc(&p, &st, ModifyWord_Root);
break;
case 'r':
res = ApplyModifier_Range(&p, &st);