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): use consistent and descriptive names f...



details:   https://anonhg.NetBSD.org/src/rev/ab058702617b
branches:  trunk
changeset: 1012092:ab058702617b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Jul 21 20:56:56 2020 +0000

description:
make(1): use consistent and descriptive names for callback functions

diffstat:

 usr.bin/make/var.c |  310 +++++++++++++++++++++++++---------------------------
 1 files changed, 147 insertions(+), 163 deletions(-)

diffs (truncated from 618 to 300 lines):

diff -r 66a6433d55e9 -r ab058702617b usr.bin/make/var.c
--- a/usr.bin/make/var.c        Tue Jul 21 20:08:44 2020 +0000
+++ b/usr.bin/make/var.c        Tue Jul 21 20:56:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.290 2020/07/21 20:08:44 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.291 2020/07/21 20:56:56 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.290 2020/07/21 20:08:44 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.291 2020/07/21 20:56:56 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.290 2020/07/21 20:08:44 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.291 2020/07/21 20:56:56 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -262,33 +262,6 @@
                                 * several space-separated words). */
 } Var_Parse_State;
 
-/* struct passed as 'void *' to VarSubstitute() for ":S/lhs/rhs/" */
-typedef struct {
-    const char *lhs;
-    size_t     lhsLen;
-    const char *rhs;
-    size_t     rhsLen;
-    VarPatternFlags pflags;
-} VarSubstituteArgs;
-
-/* struct passed as 'void *' to VarLoopExpand() for ":@tvar@str@" */
-typedef struct {
-    char       *tvar;          /* name of temporary variable */
-    char       *str;           /* string to expand */
-    VarEvalFlags eflags;
-} VarLoop;
-
-#ifndef NO_REGEX
-/* struct passed as 'void *' to VarRESubstitute() for ":C///" */
-typedef struct {
-    regex_t       re;
-    int                   nsub;
-    regmatch_t           *matches;
-    char         *replace;
-    VarPatternFlags pflags;
-} VarREPattern;
-#endif
-
 #define BROPEN '{'
 #define BRCLOSE        '}'
 #define PROPEN '('
@@ -1135,18 +1108,18 @@
 }
 
 
-/* This callback for VarModify gets a single word from an expression and
+/* This callback for ModifyWords gets a single word from an expression and
  * typically adds a modification of this word to the buffer. It may also do
  * nothing or add several words. */
-typedef void (*VarModifyCallback)(GNode *ctxt, const char *word, SepBuf *buf,
-                                 void *data);
-
-
-/* Callback function for VarModify to implement the :H modifier.
+typedef void (*ModifyWordsCallback)(GNode *ctxt, const char *word,
+                                   SepBuf *buf, void *data);
+
+
+/* Callback for ModifyWords to implement the :H modifier.
  * Add the dirname of the given word to the buffer. */
 static void
-VarHead(GNode *ctx MAKE_ATTR_UNUSED, const char *word, SepBuf *buf,
-       void *dummy MAKE_ATTR_UNUSED)
+ModifyWord_Head(GNode *ctx MAKE_ATTR_UNUSED, const char *word,
+               SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
 {
     const char *slash = strrchr(word, '/');
     if (slash != NULL)
@@ -1155,44 +1128,44 @@
        SepBuf_AddBytes(buf, ".", 1);
 }
 
-/* Callback function for VarModify to implement the :T modifier.
+/* Callback for ModifyWords to implement the :T modifier.
  * Add the basename of the given word to the buffer. */
 static void
-VarTail(GNode *ctx MAKE_ATTR_UNUSED, const char *word, SepBuf *buf,
-       void *dummy MAKE_ATTR_UNUSED)
+ModifyWord_Tail(GNode *ctx MAKE_ATTR_UNUSED, const char *word,
+               SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
 {
     const char *slash = strrchr(word, '/');
     const char *base = slash != NULL ? slash + 1 : word;
     SepBuf_AddBytes(buf, base, strlen(base));
 }
 
-/* Callback function for VarModify to implement the :E modifier.
+/* Callback for ModifyWords to implement the :E modifier.
  * Add the filename suffix of the given word to the buffer, if it exists. */
 static void
-VarSuffix(GNode *ctx MAKE_ATTR_UNUSED, const char *word, SepBuf *buf,
-         void *dummy MAKE_ATTR_UNUSED)
+ModifyWord_Suffix(GNode *ctx MAKE_ATTR_UNUSED, const char *word,
+                 SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
 {
     const char *dot = strrchr(word, '.');
     if (dot != NULL)
        SepBuf_AddBytes(buf, dot + 1, strlen(dot + 1));
 }
 
-/* Callback function for VarModify to implement the :R modifier.
- * Add the filename basename of the given word to the buffer. */
+/* Callback for ModifyWords to implement the :R modifier.
+ * Add the basename of the given word to the buffer. */
 static void
-VarRoot(GNode *ctx MAKE_ATTR_UNUSED, const char *word, SepBuf *buf,
-       void *dummy MAKE_ATTR_UNUSED)
+ModifyWord_Root(GNode *ctx MAKE_ATTR_UNUSED, const char *word,
+               SepBuf *buf, void *dummy MAKE_ATTR_UNUSED)
 {
     char *dot = strrchr(word, '.');
     size_t len = dot != NULL ? (size_t)(dot - word) : strlen(word);
     SepBuf_AddBytes(buf, word, len);
 }
 
-/* Callback function for VarModify to implement the :M modifier.
+/* Callback for ModifyWords to implement the :M modifier.
  * Place the word in the buffer if it matches the given pattern. */
 static void
-VarMatch(GNode *ctx MAKE_ATTR_UNUSED, const char *word, SepBuf *buf,
-        void *data)
+ModifyWord_Match(GNode *ctx MAKE_ATTR_UNUSED, const char *word,
+                SepBuf *buf, void *data)
 {
     const char *pattern = data;
     if (DEBUG(VAR))
@@ -1201,6 +1174,17 @@
        SepBuf_AddBytes(buf, word, strlen(word));
 }
 
+/* Callback for ModifyWords to implement the :N modifier.
+ * Place the word in the buffer if it doesn't match the given pattern. */
+static void
+ModifyWord_NoMatch(GNode *ctx MAKE_ATTR_UNUSED, const char *word,
+                  SepBuf *buf, void *data)
+{
+    const char *pattern = data;
+    if (!Str_Match(word, pattern))
+       SepBuf_AddBytes(buf, word, strlen(word));
+}
+
 #ifdef SYSVVARSUB
 /*-
  *-----------------------------------------------------------------------
@@ -1302,13 +1286,13 @@
 typedef struct {
     const char *lhs;
     const char *rhs;
-} VarSYSVSubstArgs;
-
-/* Callback function for VarModify to implement the :%.from=%.to modifier. */
+} ModifyWord_SYSVSubstArgs;
+
+/* Callback for ModifyWords to implement the :%.from=%.to modifier. */
 static void
-VarSYSVSubst(GNode *ctx, const char *word, SepBuf *buf, void *data)
+ModifyWord_SYSVSubst(GNode *ctx, const char *word, SepBuf *buf, void *data)
 {
-    const VarSYSVSubstArgs *args = data;
+    const ModifyWord_SYSVSubstArgs *args = data;
 
     size_t len;
     Boolean hasPercent;
@@ -1323,25 +1307,23 @@
 }
 #endif
 
-/* Callback function for VarModify to implement the :N modifier.
- * Place the word in the buffer if it doesn't match the given pattern. */
-static void
-VarNoMatch(GNode *ctx MAKE_ATTR_UNUSED, const char *word, SepBuf *buf,
-          void *data)
-{
-    const char *pattern = data;
-    if (!Str_Match(word, pattern))
-       SepBuf_AddBytes(buf, word, strlen(word));
-}
-
-/* Callback function for VarModify to implement the :S,from,to, modifier.
+
+typedef struct {
+    const char *lhs;
+    size_t     lhsLen;
+    const char *rhs;
+    size_t     rhsLen;
+    VarPatternFlags pflags;
+} ModifyWord_SubstArgs;
+
+/* Callback for ModifyWords to implement the :S,from,to, modifier.
  * Perform a string substitution on the given word. */
 static void
-VarSubstitute(GNode *ctx MAKE_ATTR_UNUSED, const char *word, SepBuf *buf,
-             void *data)
+ModifyWord_Subst(GNode *ctx MAKE_ATTR_UNUSED, const char *word,
+                 SepBuf *buf, void *data)
 {
     size_t wordLen = strlen(word);
-    VarSubstituteArgs *args = data;
+    ModifyWord_SubstArgs *args = data;
     const VarPatternFlags pflags = args->pflags;
 
     if ((pflags & (VARP_SUB_ONE | VARP_SUB_MATCHED)) ==
@@ -1419,13 +1401,21 @@
     free(errbuf);
 }
 
-/* Callback function for VarModify to implement the :C/from/to/ modifier.
+typedef struct {
+    regex_t       re;
+    int                   nsub;
+    regmatch_t           *matches;
+    char         *replace;
+    VarPatternFlags pflags;
+} ModifyWord_SubstRegexArgs;
+
+/* Callback for ModifyWords to implement the :C/from/to/ modifier.
  * Perform a regex substitution on the given word. */
 static void
-VarRESubstitute(GNode *ctx MAKE_ATTR_UNUSED, const char *word, SepBuf *buf,
-               void *data)
+ModifyWord_SubstRegex(GNode *ctx MAKE_ATTR_UNUSED, const char *word,
+                     SepBuf *buf, void *data)
 {
-    VarREPattern *pat = data;
+    ModifyWord_SubstRegexArgs *pat = data;
     int xrv;
     const char *wp = word;
     char *rp;
@@ -1511,19 +1501,25 @@
 #endif
 
 
-/* Callback for VarModify to implement the :@var@...@ modifier of ODE make. */
+typedef struct {
+    char       *tvar;          /* name of temporary variable */
+    char       *str;           /* string to expand */
+    VarEvalFlags eflags;
+} ModifyWord_LoopArgs;
+
+/* Callback for ModifyWords to implement the :@var@...@ modifier of ODE make. */
 static void
-VarLoopExpand(GNode *ctx, const char *word, SepBuf *buf, void *data)
+ModifyWord_Loop(GNode *ctx, const char *word, SepBuf *buf, void *data)
 {
     if (word[0] == '\0')
        return;
 
-    const VarLoop *loop = data;
+    const ModifyWord_LoopArgs *loop = data;
     Var_Set_with_flags(loop->tvar, word, ctx, VAR_NO_EXPORT);
     char *s = Var_Subst(NULL, loop->str, ctx, loop->eflags);
     if (DEBUG(VAR)) {
        fprintf(debug_file,
-               "VarLoopExpand: in \"%s\", replace \"%s\" with \"%s\" "
+               "ModifyWord_Loop: in \"%s\", replace \"%s\" with \"%s\" "
                "to \"%s\"\n",
                word, loop->tvar, loop->str, s ? s : "(null)");
     }
@@ -1539,23 +1535,9 @@
 
 
 /*-
- *-----------------------------------------------------------------------
- * VarSelectWords --
- *     Implements the :[start..end] modifier.
- *     This is a special case of VarModify since we want to be able
- *     to scan the list backwards if start > end.
- *
- * Input:
- *     str             String whose words should be trimmed
- *     seldata         words to select
- *
- * Results:
- *     A string of all the words selected.
- *
- * Side Effects:
- *     None.
- *
- *-----------------------------------------------------------------------
+ * Implements the :[first..last] modifier.
+ * This is a special case of VarModify since we want to be able



Home | Main Index | Thread Index | Old Index