Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Apr 2010 05:38:26 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r207263 - head/usr.sbin/config
Message-ID:  <201004270538.o3R5cQUa014413@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Tue Apr 27 05:38:26 2010
New Revision: 207263
URL: http://svn.freebsd.org/changeset/base/207263

Log:
  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

Modified:
  head/usr.sbin/config/configvers.h
  head/usr.sbin/config/mkoptions.c

Modified: head/usr.sbin/config/configvers.h
==============================================================================
--- head/usr.sbin/config/configvers.h	Tue Apr 27 05:35:35 2010	(r207262)
+++ head/usr.sbin/config/configvers.h	Tue Apr 27 05:38:26 2010	(r207263)
@@ -49,5 +49,5 @@
  *
  * $FreeBSD$
  */
-#define	CONFIGVERS	600008
+#define	CONFIGVERS	600009
 #define	MAJOR_VERS(x)	((x) / 100000)

Modified: head/usr.sbin/config/mkoptions.c
==============================================================================
--- head/usr.sbin/config/mkoptions.c	Tue Apr 27 05:35:35 2010	(r207262)
+++ head/usr.sbin/config/mkoptions.c	Tue Apr 27 05:38:26 2010	(r207263)
@@ -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,78 +286,30 @@ 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)
 {
-	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;
-		}
-		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, "=")) {
-		val = get_word(fp);
-		if (val == (char *)EOF) {
-			printf("%s: unexpected end of file\n", fname);
-			exit(1);
-		}
-		if (val == 0) {
-			printf("%s: Expected a right hand side at %s\n", fname,
-			    this);
-			exit(1);
-		}
-		flags |= OL_ALIAS;
-	}
-	val = ns(val);
+	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)) {
@@ -366,16 +318,67 @@ next:
 			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);
+}
+
+static int
+read_option_file(const char *fname, int flags)
+{
+	FILE *fp;
+	char *wd, *this, *val;
+	char genopt[MAXPATHLEN];
 
-	goto next;
+	fp = fopen(fname, "r");
+	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;
+		}
+		this = ns(wd);
+		val = get_word(fp);
+		if (val == (char *)EOF)
+			return (1);
+		if (val == 0) {
+			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);
+		}
+		val = ns(val);
+		check_duplicate(fname, this);
+		insert_option(this, val, flags);
+	}
+	(void)fclose(fp);
+	return (1);
+}
+
+/*
+ * read the options and options.<machine> files
+ */
+static void
+read_options(void)
+{
+	char fname[MAXPATHLEN];
+
+	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 *



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004270538.o3R5cQUa014413>