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: clean up code and comments around ModifyWord



details:   https://anonhg.NetBSD.org/src/rev/31613855daff
branches:  trunk
changeset: 980688:31613855daff
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Feb 15 06:46:01 2021 +0000

description:
make: clean up code and comments around ModifyWord

In ModifyWords, there is no "passed string" anymore since that function
now directly operates on the expression value.

While here, improve the documentation of ModifyWordsCallback and rename
it to ModifyWordProc, focusing on its purpose instead of where it is
used.

diffstat:

 usr.bin/make/var.c |  28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)

diffs (81 lines):

diff -r a8086134d4c7 -r 31613855daff usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Feb 15 03:41:01 2021 +0000
+++ b/usr.bin/make/var.c        Mon Feb 15 06:46:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.821 2021/02/14 22:48:17 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.822 2021/02/15 06:46:01 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.821 2021/02/14 22:48:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.822 2021/02/15 06:46:01 rillig Exp $");
 
 typedef enum VarFlags {
        VAR_NONE        = 0,
@@ -1298,10 +1298,10 @@
  * and typically adds a modification of this word to the buffer. It may also
  * do nothing or add several words.
  *
- * For example, in ${:Ua b c:M*2}, the callback is called 3 times, once for
- * each word of "a b c".
+ * For example, when evaluating the modifier ':M*b' in ${:Ua b c:M*b}, the
+ * callback is called 3 times, once for "a", "b" and "c".
  */
-typedef void (*ModifyWordsCallback)(const char *word, SepBuf *buf, void *data);
+typedef void (*ModifyWordProc)(const char *word, SepBuf *buf, void *data);
 
 
 /*
@@ -2324,16 +2324,12 @@
 }
 
 /*
- * Modify each of the words of the passed string using the given function.
- *
- * Input:
- *     str             String whose words should be modified
- *     modifyWord      Function that modifies a single word
- *     modifyWord_args Custom arguments for modifyWord
+ * Modify each word of the expression using the given function and place the
+ * result back in the expression.
  */
 static void
 ModifyWords(ApplyModifiersState *st,
-           ModifyWordsCallback modifyWord, void *modifyWord_args,
+           ModifyWordProc modifyWord, void *modifyWord_args,
            Boolean oneBigWord)
 {
        SepBuf result;
@@ -2667,7 +2663,7 @@
        Boolean needSubst = FALSE;
        const char *endpat;
        char *pattern;
-       ModifyWordsCallback callback;
+       ModifyWordProc modifyWord;
 
        /*
         * In the loop below, ignore ':' unless we are at (or back to) the
@@ -2730,8 +2726,8 @@
        DEBUG3(VAR, "Pattern[%s] for [%s] is [%s]\n",
            st->var->name.str, st->value.str, pattern);
 
-       callback = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch;
-       ModifyWords(st, callback, pattern, st->oneBigWord);
+       modifyWord = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch;
+       ModifyWords(st, modifyWord, pattern, st->oneBigWord);
        free(pattern);
        return AMR_OK;
 }
@@ -3359,7 +3355,7 @@
  */
 static ApplyModifierResult
 ApplyModifier_WordFunc(const char **pp, ApplyModifiersState *st,
-                      ModifyWordsCallback modifyWord)
+                      ModifyWordProc modifyWord)
 {
        char delim = (*pp)[1];
        if (delim != st->endc && delim != ':')



Home | Main Index | Thread Index | Old Index