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): move SysV string matching to var.c



details:   https://anonhg.NetBSD.org/src/rev/4dd4e3bbeed9
branches:  trunk
changeset: 973951:4dd4e3bbeed9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 19 09:26:18 2020 +0000

description:
make(1): move SysV string matching to var.c

This kind of string matching is only used in variable modifiers, and only
if this feature is enabled by SYSVVARSUB.

diffstat:

 usr.bin/make/nonints.h |    4 +-
 usr.bin/make/str.c     |  110 +-----------------------------------------------
 usr.bin/make/var.c     |  110 +++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 110 insertions(+), 114 deletions(-)

diffs (296 lines):

diff -r 748ecb87feff -r 4dd4e3bbeed9 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Jul 19 09:13:22 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Jul 19 09:26:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.78 2020/07/03 07:40:13 rillig Exp $      */
+/*     $NetBSD: nonints.h,v 1.79 2020/07/19 09:26:18 rillig Exp $      */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -138,8 +138,6 @@
 char **brk_string(const char *, int *, Boolean, char **);
 char *Str_FindSubstring(const char *, const char *);
 Boolean Str_Match(const char *, const char *);
-char *Str_SYSVMatch(const char *, const char *, size_t *, Boolean *);
-void Str_SYSVSubst(Buffer *, char *, char *, size_t, Boolean);
 
 /* suff.c */
 void Suff_ClearSuffixes(void);
diff -r 748ecb87feff -r 4dd4e3bbeed9 usr.bin/make/str.c
--- a/usr.bin/make/str.c        Sun Jul 19 09:13:22 2020 +0000
+++ b/usr.bin/make/str.c        Sun Jul 19 09:26:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: str.c,v 1.51 2020/07/03 07:40:13 rillig Exp $  */
+/*     $NetBSD: str.c,v 1.52 2020/07/19 09:26:18 rillig Exp $  */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: str.c,v 1.51 2020/07/03 07:40:13 rillig Exp $";
+static char rcsid[] = "$NetBSD: str.c,v 1.52 2020/07/19 09:26:18 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char     sccsid[] = "@(#)str.c  5.8 (Berkeley) 6/1/90";
 #else
-__RCSID("$NetBSD: str.c,v 1.51 2020/07/03 07:40:13 rillig Exp $");
+__RCSID("$NetBSD: str.c,v 1.52 2020/07/19 09:26:18 rillig Exp $");
 #endif
 #endif                         /* not lint */
 #endif
@@ -423,107 +423,3 @@
                str++;
        }
 }
-
-/*-
- *-----------------------------------------------------------------------
- * Str_SYSVMatch --
- *     Check word against pattern for a match (% is wild),
- *
- * Input:
- *     word            Word to examine
- *     pattern         Pattern to examine against
- *     len             Number of characters to substitute
- *
- * Results:
- *     Returns the beginning position of a match or null. The number
- *     of characters matched is returned in len.
- *
- * Side Effects:
- *     None
- *
- *-----------------------------------------------------------------------
- */
-char *
-Str_SYSVMatch(const char *word, const char *pattern, size_t *len,
-    Boolean *hasPercent)
-{
-    const char *p = pattern;
-    const char *w = word;
-    const char *m;
-
-    *hasPercent = FALSE;
-    if (*p == '\0') {
-       /* Null pattern is the whole string */
-       *len = strlen(w);
-       return UNCONST(w);
-    }
-
-    if ((m = strchr(p, '%')) != NULL) {
-       *hasPercent = TRUE;
-       if (*w == '\0') {
-               /* empty word does not match pattern */
-               return NULL;
-       }
-       /* check that the prefix matches */
-       for (; p != m && *w && *w == *p; w++, p++)
-            continue;
-
-       if (p != m)
-           return NULL;        /* No match */
-
-       if (*++p == '\0') {
-           /* No more pattern, return the rest of the string */
-           *len = strlen(w);
-           return UNCONST(w);
-       }
-    }
-
-    m = w;
-
-    /* Find a matching tail */
-    do
-       if (strcmp(p, w) == 0) {
-           *len = w - m;
-           return UNCONST(m);
-       }
-    while (*w++ != '\0');
-
-    return NULL;
-}
-
-
-/*-
- *-----------------------------------------------------------------------
- * Str_SYSVSubst --
- *     Substitute '%' on the pattern with len characters from src.
- *     If the pattern does not contain a '%' prepend len characters
- *     from src.
- *
- * Results:
- *     None
- *
- * Side Effects:
- *     Places result on buf
- *
- *-----------------------------------------------------------------------
- */
-void
-Str_SYSVSubst(Buffer *buf, char *pat, char *src, size_t len,
-    Boolean lhsHasPercent)
-{
-    char *m;
-
-    if ((m = strchr(pat, '%')) != NULL && lhsHasPercent) {
-       /* Copy the prefix */
-       Buf_AddBytes(buf, m - pat, pat);
-       /* skip the % */
-       pat = m + 1;
-    }
-    if (m != NULL || !lhsHasPercent) {
-       /* Copy the pattern */
-       Buf_AddBytes(buf, len, src);
-    }
-
-    /* append the rest */
-    Buf_AddBytes(buf, strlen(pat), pat);
-}
diff -r 748ecb87feff -r 4dd4e3bbeed9 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Jul 19 09:13:22 2020 +0000
+++ b/usr.bin/make/var.c        Sun Jul 19 09:26:18 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.255 2020/07/04 17:41:04 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.256 2020/07/19 09:26:18 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.255 2020/07/04 17:41:04 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.256 2020/07/19 09:26:18 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.255 2020/07/04 17:41:04 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.256 2020/07/19 09:26:18 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1215,6 +1215,108 @@
 }
 
 #ifdef SYSVVARSUB
+/*-
+ *-----------------------------------------------------------------------
+ * Str_SYSVMatch --
+ *     Check word against pattern for a match (% is wild),
+ *
+ * Input:
+ *     word            Word to examine
+ *     pattern         Pattern to examine against
+ *     len             Number of characters to substitute
+ *
+ * Results:
+ *     Returns the beginning position of a match or null. The number
+ *     of characters matched is returned in len.
+ *
+ * Side Effects:
+ *     None
+ *
+ *-----------------------------------------------------------------------
+ */
+static char *
+Str_SYSVMatch(const char *word, const char *pattern, size_t *len,
+    Boolean *hasPercent)
+{
+    const char *p = pattern;
+    const char *w = word;
+    const char *m;
+
+    *hasPercent = FALSE;
+    if (*p == '\0') {
+       /* Null pattern is the whole string */
+       *len = strlen(w);
+       return UNCONST(w);
+    }
+
+    if ((m = strchr(p, '%')) != NULL) {
+       *hasPercent = TRUE;
+       if (*w == '\0') {
+               /* empty word does not match pattern */
+               return NULL;
+       }
+       /* check that the prefix matches */
+       for (; p != m && *w && *w == *p; w++, p++)
+            continue;
+
+       if (p != m)
+           return NULL;        /* No match */
+
+       if (*++p == '\0') {
+           /* No more pattern, return the rest of the string */
+           *len = strlen(w);
+           return UNCONST(w);
+       }
+    }
+
+    m = w;
+
+    /* Find a matching tail */
+    do
+       if (strcmp(p, w) == 0) {
+           *len = w - m;
+           return UNCONST(m);
+       }
+    while (*w++ != '\0');
+
+    return NULL;
+}
+
+
+/*-
+ *-----------------------------------------------------------------------
+ * Str_SYSVSubst --
+ *     Substitute '%' on the pattern with len characters from src.
+ *     If the pattern does not contain a '%' prepend len characters
+ *     from src.
+ *
+ * Side Effects:
+ *     Places result on buf
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+Str_SYSVSubst(Buffer *buf, const char *pat, const char *src, size_t len,
+    Boolean lhsHasPercent)
+{
+    const char *m;
+
+    if ((m = strchr(pat, '%')) != NULL && lhsHasPercent) {
+       /* Copy the prefix */
+       Buf_AddBytes(buf, m - pat, pat);
+       /* skip the % */
+       pat = m + 1;
+    }
+    if (m != NULL || !lhsHasPercent) {
+       /* Copy the pattern */
+       Buf_AddBytes(buf, len, src);
+    }
+
+    /* append the rest */
+    Buf_AddBytes(buf, strlen(pat), pat);
+}
+
+
 /* Callback function for VarModify to implement the :%.from=%.to modifier. */
 static Boolean
 VarSYSVMatch(GNode *ctx, Var_Parse_State *vpstate,
@@ -1222,7 +1324,7 @@
             void *data)
 {
     size_t len;
-    char *ptr;
+    const char *ptr;
     Boolean hasPercent;
     VarPattern *pat = data;
 



Home | Main Index | Thread Index | Old Index