Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Aug 2014 18:42:20 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r269825 - stable/10/usr.sbin/config
Message-ID:  <53e90e8d.2878.29cbb502@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Mon Aug 11 18:42:20 2014
New Revision: 269825
URL: http://svnweb.freebsd.org/changeset/base/269825

Log:
  MFC: Merge in the changes in -current:
  
  Support ! operator in "files" files.
  Improve error detection and reporting
  Cleanup code to make it easier to maintain.
  Remove mandatory keyword: it has been used for 17 years.
  Bump version number (we should have bumped for -I too, but didn't)
  
  	r261501 | imp | 2014-02-04 17:26:11 -0700 (Tue, 04 Feb 2014) | 5 lines
  	Fix ! by not clearing not at the bottom of the loop.
  	Add a blank line
  	Submitted by:   bde (blank line)
  
  	r261493 | imp | 2014-02-04 11:28:58 -0700 (Tue, 04 Feb 2014) | 5 lines
  	Implement the '!' operator for files* files. It means 'include this
  	only if the specified option is NOT specified.' Bump version because
  	old config won't be able to cope with files* files that have this
  	construct in them.
  
  	r261446 | imp | 2014-02-03 12:14:36 -0700 (Mon, 03 Feb 2014) | 5 lines
  	Convert the loop by gotos into a for loop to improve readability. I
  	did this only with the inner loop for the token parsing, and not the
  	outer loop which was understandable enough when the extra layers of
  	looping went away...
  
  	r261445 | imp | 2014-02-03 12:10:33 -0700 (Mon, 03 Feb 2014) | 4 lines
  	Fix a bug introduced in r261437 that failed to honor "optional
  	profiling-routine" to work, since profiling-routine is not really an
  	option or a device, but a special case elsewhere in the code.
  
  	r261444 | imp | 2014-02-03 11:56:41 -0700 (Mon, 03 Feb 2014) | 2 lines
  	Slight cleanup to the error messaging to compress code vertically...
  
  	r261442 | imp | 2014-02-03 11:31:51 -0700 (Mon, 03 Feb 2014) | 2 lines
  	Better error messages when EOF is hit in the middle of a phrase.
  
  	r261438 | imp | 2014-02-03 09:54:53 -0700 (Mon, 03 Feb 2014) | 5 lines
  	Move the check for standard keyword + optional inclusion specifier to
  	its proper location. Otherwise you could have 'file.c standard pci'
  	without an error. This construct isn't in our tree, and has no well
  	defined meaning.
  
  	r261437 | imp | 2014-02-03 09:47:10 -0700 (Mon, 03 Feb 2014) | 4 lines
  	Don't believe we have a requirement until after we've checked all the
  	known key words. This will make error messages slightly better in
  	weird corner cases, but should otherwise be a nop.
  
  	r261436 | imp | 2014-02-03 09:46:01 -0700 (Mon, 03 Feb 2014) | 3 lines
  	In the 17 years since r30796, the mandatory keyword has never been used
  	in any files as far as I can tell, and is currently unused. Retire it.
  
  	r261435 | imp | 2014-02-03 08:10:44 -0700 (Mon, 03 Feb 2014) | 6 lines
  	Slightly deobfuscate read_file() and likely pessimize the runtime
  	performance by epsilon.
  	(Translation: elminate bogus macros that hid 'returns' making it hard
  	 to read and moved a block of code inline rather than at the end of the
  	 fuction where it was effectively a 'gosub' kind of goto).

Modified:
  stable/10/usr.sbin/config/configvers.h
  stable/10/usr.sbin/config/mkmakefile.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/config/configvers.h
==============================================================================
--- stable/10/usr.sbin/config/configvers.h	Mon Aug 11 18:26:57 2014	(r269824)
+++ stable/10/usr.sbin/config/configvers.h	Mon Aug 11 18:42:20 2014	(r269825)
@@ -49,5 +49,5 @@
  *
  * $FreeBSD$
  */
-#define	CONFIGVERS	600012
+#define	CONFIGVERS	600013
 #define	MAJOR_VERS(x)	((x) / 100000)

Modified: stable/10/usr.sbin/config/mkmakefile.c
==============================================================================
--- stable/10/usr.sbin/config/mkmakefile.c	Mon Aug 11 18:26:57 2014	(r269824)
+++ stable/10/usr.sbin/config/mkmakefile.c	Mon Aug 11 18:42:20 2014	(r269825)
@@ -43,6 +43,7 @@ static const char rcsid[] =
 
 #include <ctype.h>
 #include <err.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/param.h>
@@ -50,21 +51,6 @@ static const char rcsid[] =
 #include "config.h"
 #include "configvers.h"
 
-#define next_word(fp, wd) \
-	{ char *word = get_word(fp); \
-	  if (word == (char *)EOF) \
-		return; \
-	  else \
-		wd = word; \
-	}
-#define next_quoted_word(fp, wd) \
-	{ char *word = get_quoted_word(fp); \
-	  if (word == (char *)EOF) \
-		return; \
-	  else \
-		wd = word; \
-	}
-
 static char *tail(char *);
 static void do_clean(FILE *);
 static void do_rules(FILE *);
@@ -74,6 +60,16 @@ static void do_before_depend(FILE *);
 static int opteq(const char *, const char *);
 static void read_files(void);
 
+static void errout(const char *fmt, ...)
+{
+	va_list ap;
+
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+	exit(1);
+}
+
 /*
  * Lookup a file, by name.
  */
@@ -313,8 +309,8 @@ read_file(char *fname)
 	struct opt *op;
 	char *wd, *this, *compilewith, *depends, *clean, *warning;
 	const char *objprefix;
-	int compile, match, nreqs, std, filetype,
-	    imp_rule, no_obj, before_depend, mandatory, nowerror;
+	int compile, match, nreqs, std, filetype, not,
+	    imp_rule, no_obj, before_depend, nowerror;
 
 	fp = fopen(fname, "r");
 	if (fp == 0)
@@ -322,7 +318,7 @@ read_file(char *fname)
 next:
 	/*
 	 * include "filename"
-	 * filename    [ standard | mandatory | optional ]
+	 * filename    [ standard | optional ]
 	 *	[ dev* [ | dev* ... ] | profiling-routine ] [ no-obj ]
 	 *	[ compile-with "compile rule" [no-implicit-rule] ]
 	 *      [ dependency "dependency-list"] [ before-depend ]
@@ -343,12 +339,9 @@ next:
 		goto next;
 	}
 	if (eq(wd, "include")) {
-		next_quoted_word(fp, wd);
-		if (wd == 0) {
-			fprintf(stderr, "%s: missing include filename.\n",
-			    fname);
-			exit(1);
-		}
+		wd = get_quoted_word(fp);
+		if (wd == (char *)EOF || wd == 0)
+			errout("%s: missing include filename.\n", fname);
 		(void) snprintf(ifname, sizeof(ifname), "../../%s", wd);
 		read_file(ifname);
 		while (((wd = get_word(fp)) != (char *)EOF) && wd)
@@ -356,11 +349,11 @@ next:
 		goto next;
 	}
 	this = ns(wd);
-	next_word(fp, wd);
-	if (wd == 0) {
-		fprintf(stderr, "%s: No type for %s.\n", fname, this);
-		exit(1);
-	}
+	wd = get_word(fp);
+	if (wd == (char *)EOF)
+		return;
+	if (wd == 0)
+		errout("%s: No type for %s.\n", fname, this);
 	tp = fl_lookup(this);
 	compile = 0;
 	match = 1;
@@ -369,186 +362,154 @@ next:
 	depends = 0;
 	clean = 0;
 	warning = 0;
-	std = mandatory = 0;
+	std = 0;
 	imp_rule = 0;
 	no_obj = 0;
 	before_depend = 0;
 	nowerror = 0;
+	not = 0;
 	filetype = NORMAL;
 	objprefix = "";
-	if (eq(wd, "standard")) {
+	if (eq(wd, "standard"))
 		std = 1;
-	/*
-	 * If an entry is marked "mandatory", config will abort if it's
-	 * not called by a configuration line in the config file.  Apart
-	 * from this, the device is handled like one marked "optional".
-	 */
-	} else if (eq(wd, "mandatory")) {
-		mandatory = 1;
-	} else if (!eq(wd, "optional")) {
-		fprintf(stderr,
-		    "%s: \"%s\" %s must be optional, mandatory or standard\n",
+	else if (!eq(wd, "optional"))
+		errout("%s: \"%s\" %s must be optional or standard\n",
 		    fname, wd, this);
-		exit(1);
-	}
-nextparam:
-	next_word(fp, wd);
-	if (wd == 0) {
-		compile += match;
-		if (compile && tp == NULL)
-			goto doneparam;
-		goto next;
-	}
-	if (eq(wd, "|")) {
-		if (nreqs == 0) {
-			fprintf(stderr, "%s: syntax error describing %s\n",
-			    fname, this);
-			exit(1);
+	for (wd = get_word(fp); wd; wd = get_word(fp)) {
+		if (wd == (char *)EOF)
+			return;
+		if (eq(wd, "!")) {
+			not = 1;
+			continue;
+		}
+		if (eq(wd, "|")) {
+			if (nreqs == 0)
+				errout("%s: syntax error describing %s\n",
+				       fname, this);
+			if (not)
+				compile += !match;
+			else
+				compile += match;
+			match = 1;
+			nreqs = 0;
+			not = 0;
+			continue;
+		}
+		if (eq(wd, "no-obj")) {
+			no_obj++;
+			continue;
+		}
+		if (eq(wd, "no-implicit-rule")) {
+			if (compilewith == 0)
+				errout("%s: alternate rule required when "
+				       "\"no-implicit-rule\" is specified for"
+				       " %s.\n",
+				       fname, this);
+			imp_rule++;
+			continue;
+		}
+		if (eq(wd, "before-depend")) {
+			before_depend++;
+			continue;
+		}
+		if (eq(wd, "dependency")) {
+			wd = get_quoted_word(fp);
+			if (wd == (char *)EOF || wd == 0)
+				errout("%s: %s missing dependency string.\n",
+				       fname, this);
+			depends = ns(wd);
+			continue;
+		}
+		if (eq(wd, "clean")) {
+			wd = get_quoted_word(fp);
+			if (wd == (char *)EOF || wd == 0)
+				errout("%s: %s missing clean file list.\n",
+				       fname, this);
+			clean = ns(wd);
+			continue;
+		}
+		if (eq(wd, "compile-with")) {
+			wd = get_quoted_word(fp);
+			if (wd == (char *)EOF || wd == 0)
+				errout("%s: %s missing compile command string.\n",
+				       fname, this);
+			compilewith = ns(wd);
+			continue;
+		}
+		if (eq(wd, "warning")) {
+			wd = get_quoted_word(fp);
+			if (wd == (char *)EOF || wd == 0)
+				errout("%s: %s missing warning text string.\n",
+				       fname, this);
+			warning = ns(wd);
+			continue;
+		}
+		if (eq(wd, "obj-prefix")) {
+			wd = get_quoted_word(fp);
+			if (wd == (char *)EOF || wd == 0)
+				errout("%s: %s missing object prefix string.\n",
+				       fname, this);
+			objprefix = ns(wd);
+			continue;
+		}
+		if (eq(wd, "nowerror")) {
+			nowerror = 1;
+			continue;
 		}
+		if (eq(wd, "local")) {
+			filetype = LOCAL;
+			continue;
+		}
+		if (eq(wd, "no-depend")) {
+			filetype = NODEPEND;
+			continue;
+		}
+		nreqs++;
+		if (eq(wd, "profiling-routine")) {
+			filetype = PROFILING;
+			continue;
+		}
+		if (std)
+			errout("standard entry %s has optional inclusion specifier %s!\n",
+			       this, wd);
+		STAILQ_FOREACH(dp, &dtab, d_next)
+			if (eq(dp->d_name, wd)) {
+				dp->d_done |= DEVDONE;
+				goto nextparam;
+			}
+		SLIST_FOREACH(op, &opt, op_next)
+			if (op->op_value == 0 && opteq(op->op_name, wd))
+				goto nextparam;
+		match = 0;
+nextparam:;
+	}
+	if (not)
+		compile += !match;
+	else
 		compile += match;
-		match = 1;
-		nreqs = 0;
-		goto nextparam;
-	}
-	if (eq(wd, "no-obj")) {
-		no_obj++;
-		goto nextparam;
+	if (compile && tp == NULL) {
+		if (std == 0 && nreqs == 0)
+			errout("%s: what is %s optional on?\n",
+			       fname, this);
+		if (filetype == PROFILING && profiling == 0)
+			goto next;
+		tp = new_fent();
+		tp->f_fn = this;
+		tp->f_type = filetype;
+		if (imp_rule)
+			tp->f_flags |= NO_IMPLCT_RULE;
+		if (no_obj)
+			tp->f_flags |= NO_OBJ;
+		if (before_depend)
+			tp->f_flags |= BEFORE_DEPEND;
+		if (nowerror)
+			tp->f_flags |= NOWERROR;
+		tp->f_compilewith = compilewith;
+		tp->f_depends = depends;
+		tp->f_clean = clean;
+		tp->f_warn = warning;
+		tp->f_objprefix = objprefix;
 	}
-	if (eq(wd, "no-implicit-rule")) {
-		if (compilewith == 0) {
-			fprintf(stderr, "%s: alternate rule required when "
-			    "\"no-implicit-rule\" is specified.\n",
-			    fname);
-		}
-		imp_rule++;
-		goto nextparam;
-	}
-	if (eq(wd, "before-depend")) {
-		before_depend++;
-		goto nextparam;
-	}
-	if (eq(wd, "dependency")) {
-		next_quoted_word(fp, wd);
-		if (wd == 0) {
-			fprintf(stderr,
-			    "%s: %s missing dependency string.\n",
-			    fname, this);
-			exit(1);
-		}
-		depends = ns(wd);
-		goto nextparam;
-	}
-	if (eq(wd, "clean")) {
-		next_quoted_word(fp, wd);
-		if (wd == 0) {
-			fprintf(stderr, "%s: %s missing clean file list.\n",
-			    fname, this);
-			exit(1);
-		}
-		clean = ns(wd);
-		goto nextparam;
-	}
-	if (eq(wd, "compile-with")) {
-		next_quoted_word(fp, wd);
-		if (wd == 0) {
-			fprintf(stderr,
-			    "%s: %s missing compile command string.\n",
-			    fname, this);
-			exit(1);
-		}
-		compilewith = ns(wd);
-		goto nextparam;
-	}
-	if (eq(wd, "warning")) {
-		next_quoted_word(fp, wd);
-		if (wd == 0) {
-			fprintf(stderr,
-			    "%s: %s missing warning text string.\n",
-			    fname, this);
-			exit(1);
-		}
-		warning = ns(wd);
-		goto nextparam;
-	}
-	if (eq(wd, "obj-prefix")) {
-		next_quoted_word(fp, wd);
-		if (wd == 0) {
-			printf("%s: %s missing object prefix string.\n",
-				fname, this);
-			exit(1);
-		}
-		objprefix = ns(wd);
-		goto nextparam;
-	}
-	nreqs++;
-	if (eq(wd, "local")) {
-		filetype = LOCAL;
-		goto nextparam;
-	}
-	if (eq(wd, "no-depend")) {
-		filetype = NODEPEND;
-		goto nextparam;
-	}
-	if (eq(wd, "profiling-routine")) {
-		filetype = PROFILING;
-		goto nextparam;
-	}
-	if (eq(wd, "nowerror")) {
-		nowerror = 1;
-		goto nextparam;
-	}
-	STAILQ_FOREACH(dp, &dtab, d_next)
-		if (eq(dp->d_name, wd)) {
-			dp->d_done |= DEVDONE;
-			goto nextparam;
-		}
-	if (mandatory) {
-		fprintf(stderr, "%s: mandatory device \"%s\" not found\n",
-		       fname, wd);
-		exit(1);
-	}
-	if (std) {
-		fprintf(stderr,
-		    "standard entry %s has a device keyword - %s!\n",
-		    this, wd);
-		exit(1);
-	}
-	SLIST_FOREACH(op, &opt, op_next)
-		if (op->op_value == 0 && opteq(op->op_name, wd))
-			goto nextparam;
-	match = 0;
-	goto nextparam;
-
-doneparam:
-	if (std == 0 && nreqs == 0) {
-		fprintf(stderr, "%s: what is %s optional on?\n",
-		    fname, this);
-		exit(1);
-	}
-
-	if (wd) {
-		fprintf(stderr, "%s: syntax error describing %s\n",
-		    fname, this);
-		exit(1);
-	}
-	if (filetype == PROFILING && profiling == 0)
-		goto next;
-	tp = new_fent();
-	tp->f_fn = this;
-	tp->f_type = filetype;
-	if (imp_rule)
-		tp->f_flags |= NO_IMPLCT_RULE;
-	if (no_obj)
-		tp->f_flags |= NO_OBJ;
-	if (before_depend)
-		tp->f_flags |= BEFORE_DEPEND;
-	if (nowerror)
-		tp->f_flags |= NOWERROR;
-	tp->f_compilewith = compilewith;
-	tp->f_depends = depends;
-	tp->f_clean = clean;
-	tp->f_warn = warning;
-	tp->f_objprefix = objprefix;
 	goto next;
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?53e90e8d.2878.29cbb502>