Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/config Keep track of directory of files internally.



details:   https://anonhg.NetBSD.org/src/rev/9915f853d5a5
branches:  trunk
changeset: 340356:9915f853d5a5
user:      uebayasi <uebayasi%NetBSD.org@localhost>
date:      Tue Sep 01 12:46:20 2015 +0000

description:
Keep track of directory of files internally.

diffstat:

 usr.bin/config/defs.h  |   3 ++-
 usr.bin/config/files.c |  19 ++++++++++++++-----
 2 files changed, 16 insertions(+), 6 deletions(-)

diffs (81 lines):

diff -r a5205eae15bc -r 9915f853d5a5 usr.bin/config/defs.h
--- a/usr.bin/config/defs.h     Tue Sep 01 12:32:26 2015 +0000
+++ b/usr.bin/config/defs.h     Tue Sep 01 12:46:20 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.79 2015/09/01 12:32:26 uebayasi Exp $       */
+/*     $NetBSD: defs.h,v 1.80 2015/09/01 12:46:20 uebayasi Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -343,6 +343,7 @@
        u_char fi_flags;        /* as below */
        const char *fi_tail;    /* name, i.e., strrchr(fi_path, '/') + 1 */
        const char *fi_base;    /* tail minus ".c" (or whatever) */
+       const char *fi_dir;     /* path to file */
        const char *fi_path;    /* full file path */
        const char *fi_prefix;  /* any file prefix */
        int fi_suffix;          /* single char suffix */
diff -r a5205eae15bc -r 9915f853d5a5 usr.bin/config/files.c
--- a/usr.bin/config/files.c    Tue Sep 01 12:32:26 2015 +0000
+++ b/usr.bin/config/files.c    Tue Sep 01 12:46:20 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: files.c,v 1.23 2015/09/01 12:10:56 uebayasi Exp $      */
+/*     $NetBSD: files.c,v 1.24 2015/09/01 12:46:20 uebayasi Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: files.c,v 1.23 2015/09/01 12:10:56 uebayasi Exp $");
+__RCSID("$NetBSD: files.c,v 1.24 2015/09/01 12:46:20 uebayasi Exp $");
 
 #include <sys/param.h>
 #include <errno.h>
@@ -93,8 +93,10 @@
        struct files *fi;
        const char *dotp, *tail;
        size_t baselen;
+       size_t dirlen;
        int needc, needf;
        char base[200];
+       char dir[MAXPATHLEN];
 
        /* check various errors */
        needc = flags & FI_NEEDSCOUNT;
@@ -115,10 +117,16 @@
 
        /* find last part of pathname, and same without trailing suffix */
        tail = strrchr(path, '/');
-       if (tail == NULL)
+       if (tail == NULL) {
+               dirlen = 0;
                tail = path;
-       else
+       } else {
+               dirlen = (size_t)(tail - path);
                tail++;
+       }
+       memcpy(dir, path, dirlen);
+       dir[dirlen] = '\0';
+
        dotp = strrchr(tail, '.');
        if (dotp == NULL || dotp[1] == 0 ||
            (baselen = (size_t)(dotp - tail)) >= sizeof(base)) {
@@ -155,13 +163,14 @@
                goto bad;
        }
        memcpy(base, tail, baselen);
-       base[baselen] = 0;
+       base[baselen] = '\0';
        fi->fi_srcfile = yyfile;
        fi->fi_srcline = currentline();
        fi->fi_flags = flags;
        fi->fi_path = path;
        fi->fi_tail = tail;
        fi->fi_base = intern(base);
+       fi->fi_dir = intern(dir);
        fi->fi_prefix = SLIST_EMPTY(&prefixes) ? NULL :
                        SLIST_FIRST(&prefixes)->pf_prefix;
        fi->fi_len = strlen(path);



Home | Main Index | Thread Index | Old Index