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): replace str_concat with str_concat2 an...



details:   https://anonhg.NetBSD.org/src/rev/a9ee3300e56e
branches:  trunk
changeset: 974780:a9ee3300e56e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 10 19:53:19 2020 +0000

description:
make(1): replace str_concat with str_concat2 and str_concat3

The new functions have a simpler interface, and str_concat3 is even more
general-purpose, since the middle string is no longer required to be
exactly of length 1.

diffstat:

 usr.bin/make/dir.c     |  19 +++++++++----------
 usr.bin/make/job.c     |   8 ++++----
 usr.bin/make/main.c    |   8 ++++----
 usr.bin/make/nonints.h |  12 +++---------
 usr.bin/make/parse.c   |   8 ++++----
 usr.bin/make/str.c     |  46 ++++++++++++++++++++--------------------------
 usr.bin/make/suff.c    |  10 +++++-----
 7 files changed, 49 insertions(+), 62 deletions(-)

diffs (truncated from 328 to 300 lines):

diff -r a27753bb9136 -r a9ee3300e56e usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Mon Aug 10 19:30:30 2020 +0000
+++ b/usr.bin/make/dir.c        Mon Aug 10 19:53:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.86 2020/08/10 19:30:30 rillig Exp $  */
+/*     $NetBSD: dir.c,v 1.87 2020/08/10 19:53:19 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.86 2020/08/10 19:30:30 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.87 2020/08/10 19:53:19 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c      8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.86 2020/08/10 19:30:30 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.87 2020/08/10 19:53:19 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -640,8 +640,7 @@
        {
            (void)Lst_AtEnd(expansions,
                            (isDot ? bmake_strdup(entry->name) :
-                            str_concat(p->name, entry->name,
-                                       STR_ADDSLASH)));
+                            str_concat3(p->name, "/", entry->name)));
        }
     }
     return 0;
@@ -981,7 +980,7 @@
     if (Hash_FindEntry(&p->files, cp) == NULL)
        return NULL;
 
-    file = str_concat(p->name, cp, STR_ADDSLASH);
+    file = str_concat3(p->name, "/", cp);
     if (DEBUG(DIR)) {
        fprintf(debug_file, "   returning %s\n", file);
     }
@@ -1012,7 +1011,7 @@
     char *file;                        /* the current filename to check */
 
     if (p != dot) {
-       file = str_concat(p->name, name, STR_ADDSLASH);
+       file = str_concat3(p->name, "/", name);
     } else {
        /*
         * Checking in dot -- DON'T put a leading ./ on the thing.
@@ -1117,7 +1116,7 @@
        }
        hits += 1;
        cur->hits += 1;
-       return str_concat(cur->name, cp, STR_ADDSLASH);
+       return str_concat3(cur->name, "/", cp);
     }
 
     return NULL;
@@ -1735,8 +1734,8 @@
     if (Lst_Open(path) == SUCCESS) {
        while ((ln = Lst_Next(path)) != NULL) {
            p = (Path *)Lst_Datum(ln);
-           s2 = str_concat(flag, p->name, STR_ADDNONE);
-           str = str_concat(s1 = str, s2, STR_ADDSPACE);
+           s2 = str_concat2(flag, p->name);
+           str = str_concat3(s1 = str, " ", s2);
            free(s1);
            free(s2);
        }
diff -r a27753bb9136 -r a9ee3300e56e usr.bin/make/job.c
--- a/usr.bin/make/job.c        Mon Aug 10 19:30:30 2020 +0000
+++ b/usr.bin/make/job.c        Mon Aug 10 19:53:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.205 2020/08/01 14:47:49 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.206 2020/08/10 19:53:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: job.c,v 1.205 2020/08/01 14:47:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.206 2020/08/10 19:53:19 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)job.c      8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.205 2020/08/01 14:47:49 rillig Exp $");
+__RCSID("$NetBSD: job.c,v 1.206 2020/08/10 19:53:19 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2199,7 +2199,7 @@
            shellName++;
        } else
 #endif
-       shellPath = str_concat(_PATH_DEFSHELLDIR, shellName, STR_ADDSLASH);
+       shellPath = str_concat3(_PATH_DEFSHELLDIR, "/", shellName);
     }
     if (commandShell->exit == NULL) {
        commandShell->exit = "";
diff -r a27753bb9136 -r a9ee3300e56e usr.bin/make/main.c
--- a/usr.bin/make/main.c       Mon Aug 10 19:30:30 2020 +0000
+++ b/usr.bin/make/main.c       Mon Aug 10 19:53:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.302 2020/08/09 09:44:14 rillig Exp $        */
+/*     $NetBSD: main.c,v 1.303 2020/08/10 19:53:19 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.302 2020/08/09 09:44:14 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.303 2020/08/10 19:53:19 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.302 2020/08/09 09:44:14 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.303 2020/08/10 19:53:19 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -705,7 +705,7 @@
        if (!*line)
                return;
 
-       buf = str_concat(argv0, line, STR_ADDSPACE);
+       buf = str_concat3(argv0, " ", line);
        free(p1);
 
        argv = brk_string(buf, &argc, TRUE, &args);
diff -r a27753bb9136 -r a9ee3300e56e usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Mon Aug 10 19:30:30 2020 +0000
+++ b/usr.bin/make/nonints.h    Mon Aug 10 19:53:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.92 2020/08/10 19:30:30 rillig Exp $      */
+/*     $NetBSD: nonints.h,v 1.93 2020/08/10 19:53:19 rillig Exp $      */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -134,14 +134,8 @@
 Lst Parse_MainName(void);
 
 /* str.c */
-
-typedef enum {
-    STR_ADDNONE,               /* just concat the two strings */
-    STR_ADDSPACE,              /* add a space between the two strings */
-    STR_ADDSLASH               /* add a slash between the two strings */
-} StrConcatMode;
-
-char *str_concat(const char *, const char *, StrConcatMode);
+char *str_concat2(const char *, const char *);
+char *str_concat3(const char *, const char *, const char *);
 char **brk_string(const char *, int *, Boolean, char **);
 char *Str_FindSubstring(const char *, const char *);
 Boolean Str_Match(const char *, const char *);
diff -r a27753bb9136 -r a9ee3300e56e usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Mon Aug 10 19:30:30 2020 +0000
+++ b/usr.bin/make/parse.c      Mon Aug 10 19:53:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.250 2020/08/09 13:05:04 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.251 2020/08/10 19:53:19 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.250 2020/08/09 13:05:04 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.251 2020/08/10 19:53:19 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c    8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.250 2020/08/09 13:05:04 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.251 2020/08/10 19:53:19 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2219,7 +2219,7 @@
                    break;
                *prefEnd = '\0';
            }
-           newName = str_concat(incdir, file + i, STR_ADDSLASH);
+           newName = str_concat3(incdir, "/", file + i);
            fullname = Dir_FindFile(newName, parseIncPath);
            if (fullname == NULL)
                fullname = Dir_FindFile(newName, dirSearchPath);
diff -r a27753bb9136 -r a9ee3300e56e usr.bin/make/str.c
--- a/usr.bin/make/str.c        Mon Aug 10 19:30:30 2020 +0000
+++ b/usr.bin/make/str.c        Mon Aug 10 19:53:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: str.c,v 1.58 2020/08/10 19:30:30 rillig Exp $  */
+/*     $NetBSD: str.c,v 1.59 2020/08/10 19:53:19 rillig Exp $  */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,49 +69,43 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: str.c,v 1.58 2020/08/10 19:30:30 rillig Exp $";
+static char rcsid[] = "$NetBSD: str.c,v 1.59 2020/08/10 19:53:19 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.58 2020/08/10 19:30:30 rillig Exp $");
+__RCSID("$NetBSD: str.c,v 1.59 2020/08/10 19:53:19 rillig Exp $");
 #endif
 #endif                         /* not lint */
 #endif
 
 #include "make.h"
 
-/*-
- * str_concat --
- *     concatenate the two strings, inserting a space or slash between them.
- *
- * returns --
- *     the resulting string in allocated space.
- */
+/* Return the concatenation of s1 and s2, freshly allocated. */
 char *
-str_concat(const char *s1, const char *s2, StrConcatMode mode)
+str_concat2(const char *s1, const char *s2)
 {
        size_t len1 = strlen(s1);
        size_t len2 = strlen(s2);
-       char *result = bmake_malloc(len1 + 1 + len2 + 1);
-
-       /* copy first string into place */
+       char *result = bmake_malloc(len1 + len2 + 1);
        memcpy(result, s1, len1);
+       memcpy(result + len1, s2, len2 + 1);
+       return result;
+}
 
-       /* add separator character */
-       if (mode == STR_ADDSPACE) {
-               result[len1] = ' ';
-               ++len1;
-       } else if (mode == STR_ADDSLASH) {
-               result[len1] = '/';
-               ++len1;
-       }
-
-       /* copy second string plus EOS into place */
-       memcpy(result + len1, s2, len2 + 1);
-
+/* Return the concatenation of s1, s2 and s3, freshly allocated. */
+char *
+str_concat3(const char *s1, const char *s2, const char *s3)
+{
+       size_t len1 = strlen(s1);
+       size_t len2 = strlen(s2);
+       size_t len3 = strlen(s3);
+       char *result = bmake_malloc(len1 + len2 + len3 + 1);
+       memcpy(result, s1, len1);
+       memcpy(result + len1, s2, len2);
+       memcpy(result + len1 + len2, s3, len3 + 1);
        return result;
 }
 
diff -r a27753bb9136 -r a9ee3300e56e usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Mon Aug 10 19:30:30 2020 +0000
+++ b/usr.bin/make/suff.c       Mon Aug 10 19:53:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.94 2020/08/10 19:30:30 rillig Exp $ */
+/*     $NetBSD: suff.c,v 1.95 2020/08/10 19:53:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: suff.c,v 1.94 2020/08/10 19:30:30 rillig Exp $";
+static char rcsid[] = "$NetBSD: suff.c,v 1.95 2020/08/10 19:53:19 rillig Exp $";
 #else



Home | Main Index | Thread Index | Old Index