Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/mkdep Handle the empty suffix properly. Convert suff...



details:   https://anonhg.NetBSD.org/src/rev/17cca96447e9
branches:  trunk
changeset: 765576:17cca96447e9
user:      christos <christos%NetBSD.org@localhost>
date:      Mon May 30 22:52:12 2011 +0000

description:
Handle the empty suffix properly. Convert suffix list to a list from an
array and don't have limits in the suffix length. Also don't require that
suffixes have a single dot.

diffstat:

 usr.bin/mkdep/mkdep.c |  68 ++++++++++++++++++++++++++++++---------------------
 1 files changed, 40 insertions(+), 28 deletions(-)

diffs (132 lines):

diff -r ec09e401e53e -r 17cca96447e9 usr.bin/mkdep/mkdep.c
--- a/usr.bin/mkdep/mkdep.c     Mon May 30 21:37:37 2011 +0000
+++ b/usr.bin/mkdep/mkdep.c     Mon May 30 22:52:12 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mkdep.c,v 1.36 2011/04/17 22:35:22 christos Exp $ */
+/* $NetBSD: mkdep.c,v 1.37 2011/05/30 22:52:12 christos Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 #if !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\
  All rights reserved.");
-__RCSID("$NetBSD: mkdep.c,v 1.36 2011/04/17 22:35:22 christos Exp $");
+__RCSID("$NetBSD: mkdep.c,v 1.37 2011/05/30 22:52:12 christos Exp $");
 #endif /* not lint */
 
 #include <sys/mman.h>
@@ -65,9 +65,10 @@
        char    name[4];
 };
 
-typedef struct {
+typedef struct suff_list {
        size_t  len;
-       char    suff[12];
+       char    *suff;
+       struct suff_list *next;
 } suff_list_t;
 
 /* tree of includes for -o processing */
@@ -125,10 +126,9 @@
                tmpdir = _PATH_TMP;
        (void)snprintf(tmpfilename, sizeof (tmpfilename), "%s/%s", tmpdir,
            "mkdepXXXXXX");
-       if ((tmpfd = mkstemp(tmpfilename)) < 0) {
-               warn("unable to create temporary file %s", tmpfilename);
-               exit(EXIT_FAILURE);
-       }
+       if ((tmpfd = mkstemp(tmpfilename)) < 0)
+               err(EXIT_FAILURE,  "Unable to create temporary file %s",
+                   tmpfilename);
        (void)unlink(tmpfilename);
        *fname = tmpfilename;
 
@@ -189,6 +189,22 @@
        { NULL, 0, NULL, '\0' },
 };
 
+static void
+addsuff(suff_list_t **l, const char *s, size_t len)
+{
+       suff_list_t *p = calloc(1, sizeof(*p));
+       if (p == NULL)
+               err(1, "calloc");
+       p->suff = malloc(len + 1);
+       if (p->suff == NULL)
+               err(1, "malloc");
+       memcpy(p->suff, s, len);
+       p->suff[len] = '\0';
+       p->len = len;
+       p->next = *l;
+       *l = p;
+}
+
 int
 main(int argc, char **argv)
 {
@@ -269,22 +285,15 @@
                usage();
 
        if (suffixes != NULL) {
-               /* parse list once and save names and lengths */
-               /* allocate an extra entry to mark end of list */
-               for (sz = 1, s = suffixes; *s != 0; s++)
-                       if (*s == '.')
-                           sz++;
-               suff_list = calloc(sz, sizeof *suff_list);
-               if (suff_list == NULL)
-                       err(2, "malloc");
-               sl = suff_list;
-               for (s = suffixes; (s = strchr(s, '.')); s += sz, sl++) {
-                       sz = strcspn(s, ", ");
-                       if (sz > sizeof sl->suff)
-                               errx(2, "suffix too long");
-                       sl->len = sz;
-                       memcpy(sl->suff, s, sz);
-               }
+               if (*suffixes) {
+                       for (s = suffixes; (sz = strcspn(s, ", ")) != 0;) {
+                               addsuff(&suff_list, s, sz);
+                               s += sz;
+                               while (*s && strchr(", ", *s))
+                                       s++;
+                       }
+               } else
+                       addsuff(&suff_list, "", 0);
        }
 
        dependfile = open(filename, aflag, 0666);
@@ -368,8 +377,10 @@
                                        errx(EXIT_FAILURE,
                                            "Corrupted file `%s'", fname);
                                /* Then look for any valid suffix */
-                               for (sl = suff_list; sl->len != 0; sl++) {
-                                       if (!memcmp(suf - sl->len, sl->suff,
+                               for (sl = suff_list; sl != NULL;
+                                   sl = sl->next) {
+                                       if (sl->len &&
+                                           !memcmp(suf - sl->len, sl->suff,
                                                    sl->len))
                                                break;
                                }
@@ -377,7 +388,7 @@
                                 * Not found, check for .o, since the
                                 * original file will have it.
                                 */
-                               if (sl->len == 0 && suff_list->len != 0) {
+                               if (sl == NULL) {
                                        if (memcmp(suf - 2, ".o", 2) == 0)
                                                slen = 2;
                                        else
@@ -387,7 +398,8 @@
                        }
                        if (suff_list != NULL && slen != 0) {
                                suf -= slen;
-                               for (sl = suff_list; sl->len != 0; sl++) {
+                               for (sl = suff_list; sl != NULL; sl = sl->next)
+                               {
                                        if (sl != suff_list)
                                                write(dependfile, " ", 1);
                                        write(dependfile, line, suf - line);



Home | Main Index | Thread Index | Old Index