svn commit: r337335 - stable/11/usr.sbin/config
Kyle Evans
kevans at FreeBSD.org
Sat Aug 4 22:12:13 UTC 2018
Author: kevans
Date: Sat Aug 4 22:12:12 2018
New Revision: 337335
URL: https://svnweb.freebsd.org/changeset/base/337335
Log:
MFC r336973-r336975
r336973:
config(8): Strip comments from env lines
Consolidates the small bits of logic required for preprocessing a line
before inclusion into a file or nvlist.
r336974:
Re-insert variable disappeared during mis-application of r336973
r336975:
Remove variable re-inserted during mis-application of r336973
Modified:
stable/11/usr.sbin/config/mkmakefile.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/usr.sbin/config/mkmakefile.c
==============================================================================
--- stable/11/usr.sbin/config/mkmakefile.c Sat Aug 4 22:08:24 2018 (r337334)
+++ stable/11/usr.sbin/config/mkmakefile.c Sat Aug 4 22:12:12 2018 (r337335)
@@ -63,6 +63,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);
@@ -241,16 +242,29 @@ 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 *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
@@ -258,15 +272,13 @@ process_into_nvlist(char *line, nvlist_t *nvl)
{
char result[BUFSIZ], *s;
- 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
More information about the svn-src-stable
mailing list