summaryrefslogtreecommitdiff
path: root/usr.sbin/config
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-07-31 16:03:30 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-07-31 16:03:30 +0000
commit9e7178f5c7edeaed0972fff6e7089ab5a8c87c17 (patch)
treedf9b53363af3d9904efc31d5921b6804f328960a /usr.sbin/config
parentfd12f2aaebd2d15445528155c562340ef299b193 (diff)
downloadsrc-test2-9e7178f5c7edeaed0972fff6e7089ab5a8c87c17.tar.gz
src-test2-9e7178f5c7edeaed0972fff6e7089ab5a8c87c17.zip
Notes
Diffstat (limited to 'usr.sbin/config')
-rw-r--r--usr.sbin/config/mkmakefile.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c
index 11ed92ed1f36..7cfefa2981b1 100644
--- a/usr.sbin/config/mkmakefile.c
+++ b/usr.sbin/config/mkmakefile.c
@@ -65,6 +65,7 @@ static void do_before_depend(FILE *);
static int opteq(const char *, const char *);
static void read_files(void);
static void sanitize_envline(char *result, const char *src);
+static bool preprocess(char *line, char *result);
static void process_into_file(char *line, FILE *ofp);
static void process_into_nvlist(char *line, nvlist_t *nvl);
static void dump_nvlist(nvlist_t *nvl, FILE *ofp);
@@ -243,32 +244,44 @@ sanitize_envline(char *result, const char *src)
*dst = 0;
}
+/*
+ * Returns true if the caller may use the string.
+ */
+static bool
+preprocess(char *line, char *result)
+{
+
+ char result[BUFSIZ], *s;
+
+ /* Strip any comments */
+ if ((s = strchr(line, '#')) != NULL)
+ *s = '\0';
+ sanitize_envline(result, line);
+ /* Return true if it's non-empty */
+ return (*result != '\0');
+}
+
static void
process_into_file(char *line, FILE *ofp)
{
char result[BUFSIZ];
- sanitize_envline(result, line);
- /* anything left? */
- if (*result == '\0')
- return;
- fprintf(ofp, "\"%s\\0\"\n", result);
+ if (preprocess(line, result))
+ fprintf(ofp, "\"%s\\0\"\n", result);
}
static void
process_into_nvlist(char *line, nvlist_t *nvl)
{
- char result[BUFSIZ], *s;
+ char result[BUFSIZ];
- sanitize_envline(result, line);
- /* anything left? */
- if (*result == '\0')
- return;
- s = strchr(result, '=');
- *s = 0;
- if (nvlist_exists(nvl, result))
- nvlist_free(nvl, result);
- nvlist_add_string(nvl, result, s + 1);
+ if (preprocess(line, result)) {
+ s = strchr(result, '=');
+ *s = '\0';
+ if (nvlist_exists(nvl, result))
+ nvlist_free(nvl, result);
+ nvlist_add_string(nvl, result, s + 1);
+ }
}
static void