From 36d533d5436d4b351fc1f691415956afc77d5b12 Mon Sep 17 00:00:00 2001 From: jhb Date: Thu, 27 Oct 2005 17:13:23 +0000 Subject: Optionally include a DEFAULTS config file if it is present in the current directory before the specified config file. This is implemented by opening DEFAULTS as stdin if it exists, and if so resetting stdin to the actual config file when DEFAULTS is fully parsed via yywrap(). In short, this lets us create DEFAULTS kernel configs in /sys//conf that can enable certain options or devices by default and allow users to disable them via 'nooptions' or 'nodevice' rather than having to create kludge NO_FOO options. Requested by: scottl Reviewed by: scottl --- usr.sbin/config/config.y | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'usr.sbin/config/config.y') diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y index 018ec61..58d6b0c 100644 --- a/usr.sbin/config/config.y +++ b/usr.sbin/config/config.y @@ -92,6 +92,7 @@ int maxusers; #define ns(s) strdup(s) int include(const char *, int); void yyerror(const char *s); +int yywrap(void); static char * devopt(char *dev) @@ -300,6 +301,21 @@ yyerror(const char *s) errx(1, "%s:%d: %s", yyfile, yyline + 1, s); } +int +yywrap(void) +{ + + if (found_defaults) { + if (freopen(PREFIX, "r", stdin) == NULL) + err(2, "%s", PREFIX); + yyfile = PREFIX; + yyline = 0; + found_defaults = 0; + return 0; + } + return 1; +} + /* * Add a new file to the list of files. */ -- cgit v1.1