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): migrate remaining Lst_Find to Lst_FindB



details:   https://anonhg.NetBSD.org/src/rev/7e4d01ac1dcf
branches:  trunk
changeset: 937949:7e4d01ac1dcf
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 29 10:06:23 2020 +0000

description:
make(1): migrate remaining Lst_Find to Lst_FindB

While here, rename SuffSuffIsSuffix to SuffSuffGetSuffix since a
function named "is" should return a boolean, not a string pointer.

diffstat:

 usr.bin/make/lst.c  |   36 +---------
 usr.bin/make/lst.h  |    4 +-
 usr.bin/make/meta.c |   47 ++++---------
 usr.bin/make/suff.c |  174 ++++++++++++++-------------------------------------
 4 files changed, 68 insertions(+), 193 deletions(-)

diffs (truncated from 566 to 300 lines):

diff -r c8b8cad6f290 -r 7e4d01ac1dcf usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Sat Aug 29 09:30:10 2020 +0000
+++ b/usr.bin/make/lst.c        Sat Aug 29 10:06:23 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.53 2020/08/29 09:30:10 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.54 2020/08/29 10:06:23 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -37,11 +37,11 @@
 #include "make.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.53 2020/08/29 09:30:10 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.54 2020/08/29 10:06:23 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.53 2020/08/29 09:30:10 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.54 2020/08/29 10:06:23 rillig Exp $");
 #endif /* not lint */
 #endif
 
@@ -375,16 +375,6 @@
     return LstIsEmpty(list);
 }
 
-/* Return the first node from the given list for which the given comparison
- * function returns 0, or NULL if none of the nodes matches. */
-LstNode
-Lst_Find(Lst list, LstFindProc cmp, const void *cmpData)
-{
-    if (LstIsEmpty(list))
-       return NULL;
-    return Lst_FindFrom(list, Lst_First(list), cmp, cmpData);
-}
-
 /* Return the first node from the list for which the match function returns
  * TRUE, or NULL if none of the nodes matched. */
 LstNode
@@ -393,26 +383,6 @@
     return Lst_FindFromB(list, Lst_First(list), match, matchArgs);
 }
 
-/* Return the first node from the given list, starting at the given node, for
- * which the given comparison function returns 0, or NULL if none of the nodes
- * matches. */
-LstNode
-Lst_FindFrom(Lst list, LstNode node, LstFindProc cmp, const void *cmpData)
-{
-    LstNode tln;
-
-    assert(list != NULL);
-    assert(node != NULL);
-    assert(cmp != NULL);
-
-    for (tln = node; tln != NULL; tln = tln->next) {
-       if (cmp(tln->datum, cmpData) == 0)
-           return tln;
-    }
-
-    return NULL;
-}
-
 /* Return the first node from the list, starting at the given node, for which
  * the match function returns TRUE, or NULL if none of the nodes matches.
  *
diff -r c8b8cad6f290 -r 7e4d01ac1dcf usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Sat Aug 29 09:30:10 2020 +0000
+++ b/usr.bin/make/lst.h        Sat Aug 29 10:06:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lst.h,v 1.54 2020/08/29 09:30:10 rillig Exp $  */
+/*     $NetBSD: lst.h,v 1.55 2020/08/29 10:06:23 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -146,10 +146,8 @@
  * Functions for entire lists
  */
 /* Find an element in a list */
-LstNode                Lst_Find(Lst, LstFindProc, const void *);
 LstNode                Lst_FindB(Lst, LstFindBProc, const void *);
 /* Find an element starting from somewhere */
-LstNode                Lst_FindFrom(Lst, LstNode, LstFindProc, const void *);
 LstNode                Lst_FindFromB(Lst, LstNode, LstFindBProc, const void *);
 /*
  * See if the given datum is on the list. Returns the LstNode containing
diff -r c8b8cad6f290 -r 7e4d01ac1dcf usr.bin/make/meta.c
--- a/usr.bin/make/meta.c       Sat Aug 29 09:30:10 2020 +0000
+++ b/usr.bin/make/meta.c       Sat Aug 29 10:06:23 2020 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: meta.c,v 1.107 2020/08/28 06:47:14 rillig Exp $ */
+/*      $NetBSD: meta.c,v 1.108 2020/08/29 10:06:23 rillig Exp $ */
 
 /*
  * Implement 'meta' mode.
@@ -955,39 +955,23 @@
     return strncmp(path, prefix, n) == 0;
 }
 
-/*
- * looking for exact or prefix/ match to
- * Lst_Find wants 0 to stop search
- */
-static int
+/* See if the path equals prefix or starts with "prefix/". */
+static Boolean
 path_match(const void *p, const void *q)
 {
+    const char *path = p;
     const char *prefix = q;
-    const char *path = p;
     size_t n = strlen(prefix);
-    int rc;
 
-    if ((rc = strncmp(path, prefix, n)) == 0) {
-       switch (path[n]) {
-       case '\0':
-       case '/':
-           break;
-       default:
-           rc = 1;
-           break;
-       }
-    }
-    return rc;
+    if (strncmp(path, prefix, n) != 0)
+        return FALSE;
+    return path[n] == '\0' || path[n] == '/';
 }
 
-/* Lst_Find wants 0 to stop search */
-static int
+static Boolean
 string_match(const void *p, const void *q)
 {
-    const char *p1 = p;
-    const char *p2 = q;
-
-    return strcmp(p1, p2);
+    return strcmp(p, q) == 0;
 }
 
 
@@ -1334,17 +1318,14 @@
                case 'D':               /* unlink */
                    if (*p == '/' && !Lst_IsEmpty(missingFiles)) {
                        /* remove any missingFiles entries that match p */
-                       ln = Lst_Find(missingFiles, path_match, p);
+                       ln = Lst_FindB(missingFiles, path_match, p);
                        if (ln != NULL) {
                            LstNode nln;
                            char *tp;
 
                            do {
-                               LstNode succ = Lst_Succ(ln);
-                               nln = succ != NULL
-                                     ? Lst_FindFrom(missingFiles, succ,
-                                                    path_match, p)
-                                     : NULL;
+                               nln = Lst_FindFromB(missingFiles, Lst_Succ(ln),
+                                                   path_match, p);
                                tp = Lst_Datum(ln);
                                Lst_Remove(missingFiles, ln);
                                free(tp);
@@ -1414,7 +1395,7 @@
                    if ((link_src != NULL && cached_lstat(p, &fs) < 0) ||
                        (link_src == NULL && cached_stat(p, &fs) < 0)) {
                        if (!meta_ignore(gn, p)) {
-                           if (Lst_Find(missingFiles, string_match, p) == NULL)
+                           if (Lst_FindB(missingFiles, string_match, p) == NULL)
                                Lst_Append(missingFiles, bmake_strdup(p));
                        }
                    }
@@ -1500,7 +1481,7 @@
                             * A referenced file outside of CWD is missing.
                             * We cannot catch every eventuality here...
                             */
-                           if (Lst_Find(missingFiles, string_match, p) == NULL)
+                           if (Lst_FindB(missingFiles, string_match, p) == NULL)
                                Lst_Append(missingFiles, bmake_strdup(p));
                        }
                    }
diff -r c8b8cad6f290 -r 7e4d01ac1dcf usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Sat Aug 29 09:30:10 2020 +0000
+++ b/usr.bin/make/suff.c       Sat Aug 29 10:06:23 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.128 2020/08/28 19:21:00 rillig Exp $        */
+/*     $NetBSD: suff.c,v 1.129 2020/08/29 10:06:23 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.128 2020/08/28 19:21:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.129 2020/08/29 10:06:23 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)suff.c     8.4 (Berkeley) 3/21/94";
 #else
-__RCSID("$NetBSD: suff.c,v 1.128 2020/08/28 19:21:00 rillig Exp $");
+__RCSID("$NetBSD: suff.c,v 1.129 2020/08/29 10:06:23 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -209,11 +209,6 @@
                                 * single-suffix transformation rules */
 
 
-static const char *SuffStrIsPrefix(const char *, const char *);
-static int SuffSuffIsSuffixP(const void *, const void *);
-static int SuffSuffHasNameP(const void *, const void *);
-static int SuffSuffIsPrefix(const void *, const void *);
-static int SuffGNHasNameP(const void *, const void *);
 static void SuffUnRef(void *, void *);
 static void SuffFree(void *);
 static void SuffInsert(Lst, Suff *);
@@ -266,37 +261,30 @@
 typedef struct {
     char       *ename;         /* The end of the name */
     int                 len;           /* Length of the name */
-} SuffSuffIsSuffixArgs;
+} SuffSuffGetSuffixArgs;
 
-/*-
- *-----------------------------------------------------------------------
- * SuffSuffIsSuffix  --
- *     See if suff is a suffix of str. sd->ename should point to THE END
- *     of the string to check. (THE END == the null byte)
+/* See if suff is a suffix of str. str->ename should point to THE END
+ * of the string to check. (THE END == the null byte)
  *
  * Input:
  *     s               possible suffix
- *     sd              string to examine
+ *     str             string to examine
  *
  * Results:
  *     NULL if it ain't, pointer to character in str before suffix if
  *     it is.
- *
- * Side Effects:
- *     None
- *-----------------------------------------------------------------------
  */
 static char *
-SuffSuffIsSuffix(const Suff *s, const SuffSuffIsSuffixArgs *sd)
+SuffSuffGetSuffix(const Suff *s, const SuffSuffGetSuffixArgs *str)
 {
     char  *p1;         /* Pointer into suffix name */
     char  *p2;         /* Pointer into string being examined */
 
-    if (sd->len < s->nameLen)
+    if (str->len < s->nameLen)
        return NULL;            /* this string is shorter than the suffix */
 
     p1 = s->name + s->nameLen;
-    p2 = sd->ename;
+    p2 = str->ename;
 
     while (p1 >= s->name && *p1 == *p2) {
        p1--;
@@ -306,94 +294,34 @@
     return p1 == s->name - 1 ? p2 : NULL;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * SuffSuffIsSuffixP --
- *     Predicate form of SuffSuffIsSuffix. Passed as the callback function
- *     to Lst_Find.
- *
- * Results:
- *     0 if the suffix is the one desired, non-zero if not.
- *
- * Side Effects:
- *     None.
- *
- *-----------------------------------------------------------------------
- */
-static int
-SuffSuffIsSuffixP(const void *s, const void *sd)
+/* Predicate form of SuffSuffGetSuffix, for Lst_FindB. */
+static Boolean
+SuffSuffIsSuffix(const void *s, const void *sd)
 {
-    return !SuffSuffIsSuffix(s, sd);
+    return SuffSuffGetSuffix(s, sd) != NULL;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * SuffSuffHasNameP --
- *     Callback procedure for finding a suffix based on its name. Used by
- *     Suff_GetPath.
- *



Home | Main Index | Thread Index | Old Index