Module Name: src Committed By: uebayasi Date: Tue Sep 1 12:46:20 UTC 2015
Modified Files: src/usr.bin/config: defs.h files.c Log Message: Keep track of directory of files internally. To generate a diff of this commit: cvs rdiff -u -r1.79 -r1.80 src/usr.bin/config/defs.h cvs rdiff -u -r1.23 -r1.24 src/usr.bin/config/files.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/config/defs.h diff -u src/usr.bin/config/defs.h:1.79 src/usr.bin/config/defs.h:1.80 --- src/usr.bin/config/defs.h:1.79 Tue Sep 1 12:32:26 2015 +++ src/usr.bin/config/defs.h Tue Sep 1 12:46:20 2015 @@ -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 @@ struct files { 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 */ Index: src/usr.bin/config/files.c diff -u src/usr.bin/config/files.c:1.23 src/usr.bin/config/files.c:1.24 --- src/usr.bin/config/files.c:1.23 Tue Sep 1 12:10:56 2015 +++ src/usr.bin/config/files.c Tue Sep 1 12:46:20 2015 @@ -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 @@ addfile(const char *path, struct condexp 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 @@ addfile(const char *path, struct condexp /* 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 @@ addfile(const char *path, struct condexp 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);