summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authoruebayasi <uebayasi@NetBSD.org>2014-11-17 00:53:15 +0000
committeruebayasi <uebayasi@NetBSD.org>2014-11-17 00:53:15 +0000
commit806e02b60d6d332ce680291ec6d0cf46de442fbf (patch)
treef7737a98f09b91c316883f82c5e82462522634bd /usr.bin
parentcd530ca711f0a3a352f3d6777255939b4be3f357 (diff)
Pre-calc file path len/suffix. Misc. clean up.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/config/defs.h6
-rw-r--r--usr.bin/config/files.c6
-rw-r--r--usr.bin/config/mkmakefile.c45
3 files changed, 28 insertions, 29 deletions
diff --git a/usr.bin/config/defs.h b/usr.bin/config/defs.h
index 054afd06166..afaabbf78fe 100644
--- a/usr.bin/config/defs.h
+++ b/usr.bin/config/defs.h
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.63 2014/11/15 08:21:38 uebayasi Exp $ */
+/* $NetBSD: defs.h,v 1.64 2014/11/17 00:53:15 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -340,6 +340,8 @@ struct filetype
char fit_lastc; /* last char from path */
const char *fit_path; /* full file path */
const char *fit_prefix; /* any file prefix */
+ size_t fit_len; /* path string length */
+ int fit_suffix; /* single char suffix */
struct attr *fit_attr; /* owner attr */
TAILQ_ENTRY(files) fit_anext; /* next file in attr */
};
@@ -371,6 +373,8 @@ struct files {
#define fi_lastc fi_fit.fit_lastc
#define fi_path fi_fit.fit_path
#define fi_prefix fi_fit.fit_prefix
+#define fi_suffix fi_fit.fit_suffix
+#define fi_len fi_fit.fit_len
#define fi_attr fi_fit.fit_attr
#define fi_anext fi_fit.fit_anext
diff --git a/usr.bin/config/files.c b/usr.bin/config/files.c
index b6a8f192b63..3b9ddd776fd 100644
--- a/usr.bin/config/files.c
+++ b/usr.bin/config/files.c
@@ -1,4 +1,4 @@
-/* $NetBSD: files.c,v 1.17 2014/10/29 17:14:50 christos Exp $ */
+/* $NetBSD: files.c,v 1.18 2014/11/17 00:53:15 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: files.c,v 1.17 2014/10/29 17:14:50 christos Exp $");
+__RCSID("$NetBSD: files.c,v 1.18 2014/11/17 00:53:15 uebayasi Exp $");
#include <sys/param.h>
#include <errno.h>
@@ -158,6 +158,8 @@ addfile(const char *path, struct condexpr *optx, u_char flags, const char *rule)
fi->fi_base = intern(base);
fi->fi_prefix = SLIST_EMPTY(&prefixes) ? NULL :
SLIST_FIRST(&prefixes)->pf_prefix;
+ fi->fi_len = strlen(path);
+ fi->fi_suffix = path[fi->fi_len - 1];
fi->fi_optx = optx;
fi->fi_optf = NULL;
fi->fi_mkrule = rule;
diff --git a/usr.bin/config/mkmakefile.c b/usr.bin/config/mkmakefile.c
index 157e2536c39..fd180e9621a 100644
--- a/usr.bin/config/mkmakefile.c
+++ b/usr.bin/config/mkmakefile.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mkmakefile.c,v 1.32 2014/11/16 15:10:54 uebayasi Exp $ */
+/* $NetBSD: mkmakefile.c,v 1.33 2014/11/17 00:53:15 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: mkmakefile.c,v 1.32 2014/11/16 15:10:54 uebayasi Exp $");
+__RCSID("$NetBSD: mkmakefile.c,v 1.33 2014/11/17 00:53:15 uebayasi Exp $");
#include <sys/param.h>
#include <ctype.h>
@@ -273,19 +273,15 @@ srcpath(struct files *fi)
static const char *
filetype_prologue(struct filetype *fit)
{
- if (*fit->fit_path == '/')
- return ("");
- else
- return ("$S/");
+
+ return (*fit->fit_path == '/') ? "" : "$S/";
}
static const char *
prefix_prologue(const char *path)
{
- if (*path == '/')
- return ("");
- else
- return ("$S/");
+
+ return (*path == '/') ? "" : "$S/";
}
static void
@@ -300,23 +296,25 @@ emitdefs(FILE *fp)
/* Skip any options output to a header file */
if (DEFINED_OPTION(nv->nv_name))
continue;
+ const char *s = nv->nv_str;
fprintf(fp, "\t-D%s%s%s%s \\\n", nv->nv_name,
- (nv->nv_str != NULL) ? "=\"" : "",
- (nv->nv_str != NULL) ? nv->nv_str : "",
- (nv->nv_str != NULL) ? "\"" : "");
+ s ? "=\"" : "",
+ s ? s : "",
+ s ? "\"" : "");
}
putc('\n', fp);
fprintf(fp, "PARAM=-DMAXUSERS=%d\n", maxusers);
fprintf(fp, "MACHINE=%s\n", machine);
- if (*srcdir == '/' || *srcdir == '.') {
- fprintf(fp, "S=\t%s\n", srcdir);
- } else {
+
+ const char *subdir = "";
+ if (*srcdir != '/' && *srcdir != '.') {
/*
* libkern and libcompat "Makefile.inc"s want relative S
* specification to begin with '.'.
*/
- fprintf(fp, "S=\t./%s\n", srcdir);
+ subdir = "./";
}
+ fprintf(fp, "S=\t%s%s\n", subdir, srcdir);
for (nv = mkoptions; nv != NULL; nv = nv->nv_next)
fprintf(fp, "%s=%s\n", nv->nv_name, nv->nv_str);
}
@@ -482,7 +480,6 @@ static void
emitfiles(FILE *fp, int suffix, int upper_suffix)
{
struct files *fi;
- size_t len;
const char *fpath;
struct config *cf;
char swapname[100];
@@ -494,8 +491,7 @@ emitfiles(FILE *fp, int suffix, int upper_suffix)
if ((fi->fi_flags & FI_SEL) == 0)
continue;
fpath = srcpath(fi);
- len = strlen(fpath);
- if (fpath[len - 1] != suffix && fpath[len - 1] != upper_suffix)
+ if (fi->fi_suffix != suffix && fi->fi_suffix != upper_suffix)
continue;
prologue = prefix = sep = "";
if (*fi->fi_path != '/') {
@@ -532,9 +528,7 @@ static void
emitrules(FILE *fp)
{
struct files *fi;
- size_t len;
const char *fpath;
- int suffix;
TAILQ_FOREACH(fi, &allfiles, fi_next) {
const char *prologue, *prefix, *sep;
@@ -542,8 +536,6 @@ emitrules(FILE *fp)
if ((fi->fi_flags & FI_SEL) == 0)
continue;
fpath = srcpath(fi);
- len = strlen(fpath);
- suffix = fpath[len - 1];
prologue = prefix = sep = "";
if (*fpath != '/') {
if (fi->fi_prefix != NULL) {
@@ -559,7 +551,7 @@ emitrules(FILE *fp)
if (fi->fi_mkrule != NULL) {
fprintf(fp, "\t%s\n\n", fi->fi_mkrule);
} else {
- fprintf(fp, "\t${NORMAL_%c}\n\n", toupper(suffix));
+ fprintf(fp, "\t${NORMAL_%c}\n\n", toupper(fi->fi_suffix));
}
}
}
@@ -574,7 +566,8 @@ emitload(FILE *fp)
{
struct config *cf;
- fputs(".MAIN: all\nall:", fp);
+ fputs(".MAIN: all\n", fp);
+ fputs("all:", fp);
TAILQ_FOREACH(cf, &allcf, cf_next) {
fprintf(fp, " %s", cf->cf_name);
/*