summaryrefslogtreecommitdiffstats
path: root/usr.sbin/config/mkoptions.c
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2010-04-27 05:38:26 +0000
committerimp <imp@FreeBSD.org>2010-04-27 05:38:26 +0000
commit687e047ca195631a69ddbd770d9b88470f6f69d1 (patch)
treee44d1918af98cac50de4ae928cb2ef18f2ac0f95 /usr.sbin/config/mkoptions.c
parent0ee54d44efd2c656c466198d0afa88cd0357a0eb (diff)
downloadFreeBSD-src-687e047ca195631a69ddbd770d9b88470f6f69d1.zip
FreeBSD-src-687e047ca195631a69ddbd770d9b88470f6f69d1.tar.gz
Redo how we add compat options so as to be compatible with old
versions of config. Remove support for the syntax OLD = NEW form the options file, and instead have a new file $S/conf/options-compat. This file will be parsed as OLD NEW on each line. Bump version of config. Since nothing in -current ever used this, there's no hazards for current users, so I'm not bumping the version in the Makefiles.$MACHINE. No need, really, for this version bump in -current, but this was introduced into -stable before I realized the version check was ineffective there, so the verison bump doesn't hurt here and keeps the two branches in sync, versionwise, after the MFC. MFC after: 3 days
Diffstat (limited to 'usr.sbin/config/mkoptions.c')
-rw-r--r--usr.sbin/config/mkoptions.c157
1 files changed, 80 insertions, 77 deletions
diff --git a/usr.sbin/config/mkoptions.c b/usr.sbin/config/mkoptions.c
index 1a6ccc8..846e028 100644
--- a/usr.sbin/config/mkoptions.c
+++ b/usr.sbin/config/mkoptions.c
@@ -166,7 +166,7 @@ do_option(char *name)
fprintf(outf, "#define %s %s\n", name, value);
} /* else empty file */
- (void) fclose(outf);
+ (void)fclose(outf);
return;
}
basefile = "";
@@ -225,7 +225,7 @@ do_option(char *name)
if (cp == (char *)EOF)
break;
}
- (void) fclose(inf);
+ (void)fclose(inf);
if (!tidy && ((value == NULL && oldvalue == NULL) ||
(value && oldvalue && eq(value, oldvalue)))) {
while (!SLIST_EMPTY(&op_head)) {
@@ -263,7 +263,7 @@ do_option(char *name)
free(op->op_value);
free(op);
}
- (void) fclose(outf);
+ (void)fclose(outf);
}
/*
@@ -277,7 +277,7 @@ tooption(char *name)
struct opt_list *po;
/* "cannot happen"? the otab list should be complete.. */
- (void) strlcpy(nbuf, "options.h", sizeof(nbuf));
+ (void)strlcpy(nbuf, "options.h", sizeof(nbuf));
SLIST_FOREACH(po, &otab, o_next) {
if (eq(po->o_name, name)) {
@@ -286,96 +286,99 @@ tooption(char *name)
}
}
- (void) strlcpy(hbuf, path(nbuf), sizeof(hbuf));
+ (void)strlcpy(hbuf, path(nbuf), sizeof(hbuf));
return (hbuf);
}
-/*
- * read the options and options.<machine> files
- */
+
static void
-read_options(void)
+insert_option(char *this, char *val, int flags)
+{
+ struct opt_list *po;
+
+ po = (struct opt_list *) calloc(1, sizeof *po);
+ if (po == NULL)
+ err(EXIT_FAILURE, "calloc");
+ po->o_name = this;
+ po->o_file = val;
+ po->o_flags = flags;
+ SLIST_INSERT_HEAD(&otab, po, o_next);
+}
+
+
+static void
+check_duplicate(const char *fname, const char *this)
+{
+ struct opt_list *po;
+
+ SLIST_FOREACH(po, &otab, o_next) {
+ if (eq(po->o_name, this)) {
+ printf("%s: Duplicate option %s.\n",
+ fname, this);
+ exit(1);
+ }
+ }
+}
+
+static int
+read_option_file(const char *fname, int flags)
{
FILE *fp;
- char fname[MAXPATHLEN];
char *wd, *this, *val;
- struct opt_list *po;
- int first = 1;
char genopt[MAXPATHLEN];
- int flags = 0;
- SLIST_INIT(&otab);
- (void) snprintf(fname, sizeof(fname), "../../conf/options");
-openit:
fp = fopen(fname, "r");
- if (fp == 0) {
- return;
- }
-next:
- flags = 0;
- wd = get_word(fp);
- if (wd == (char *)EOF) {
- (void) fclose(fp);
- if (first == 1) {
- first++;
- (void) snprintf(fname, sizeof fname, "../../conf/options.%s", machinename);
- fp = fopen(fname, "r");
- if (fp != 0)
- goto next;
- (void) snprintf(fname, sizeof fname, "options.%s", machinename);
- goto openit;
+ if (fp == 0)
+ return (0);
+ while ((wd = get_word(fp)) != (char *)EOF) {
+ if (wd == 0)
+ continue;
+ if (wd[0] == '#') {
+ while (((wd = get_word(fp)) != (char *)EOF) && wd)
+ continue;
+ continue;
}
- return;
- }
- if (wd == 0)
- goto next;
- if (wd[0] == '#')
- {
- while (((wd = get_word(fp)) != (char *)EOF) && wd)
- ;
- goto next;
- }
- this = ns(wd);
- val = get_word(fp);
- if (val == (char *)EOF)
- return;
- if (val == 0) {
- char *s = ns(this);
- (void) snprintf(genopt, sizeof(genopt), "opt_%s.h", lower(s));
- val = genopt;
- free(s);
- } else if (eq(val, "=")) {
+ this = ns(wd);
val = get_word(fp);
- if (val == (char *)EOF) {
- printf("%s: unexpected end of file\n", fname);
- exit(1);
- }
+ if (val == (char *)EOF)
+ return (1);
if (val == 0) {
- printf("%s: Expected a right hand side at %s\n", fname,
- this);
- exit(1);
+ if (flags) {
+ printf("%s: compat file requires two words "
+ "per line at %s\n", fname, this);
+ exit(1);
+ }
+ char *s = ns(this);
+ (void)snprintf(genopt, sizeof(genopt), "opt_%s.h",
+ lower(s));
+ val = genopt;
+ free(s);
}
- flags |= OL_ALIAS;
+ val = ns(val);
+ check_duplicate(fname, this);
+ insert_option(this, val, flags);
}
- val = ns(val);
+ (void)fclose(fp);
+ return (1);
+}
- SLIST_FOREACH(po, &otab, o_next) {
- if (eq(po->o_name, this)) {
- printf("%s: Duplicate option %s.\n",
- fname, this);
- exit(1);
- }
- }
-
- po = (struct opt_list *) calloc(1, sizeof *po);
- if (po == NULL)
- err(EXIT_FAILURE, "calloc");
- po->o_name = this;
- po->o_file = val;
- po->o_flags = flags;
- SLIST_INSERT_HEAD(&otab, po, o_next);
+/*
+ * read the options and options.<machine> files
+ */
+static void
+read_options(void)
+{
+ char fname[MAXPATHLEN];
- goto next;
+ SLIST_INIT(&otab);
+ read_option_file("../../conf/options", 0);
+ (void)snprintf(fname, sizeof fname, "../../conf/options.%s",
+ machinename);
+ if (!read_option_file(fname, 0)) {
+ (void)snprintf(fname, sizeof fname, "options.%s", machinename);
+ read_option_file(fname, 0);
+ }
+ read_option_file("../../conf/options-compat", OL_ALIAS);
}
static char *
OpenPOWER on IntegriCloud