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/<arch>/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
This commit is contained in:
parent
518bf2dcc7
commit
dfdbf9be00
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=151744
@ -161,6 +161,7 @@ extern STAILQ_HEAD(files_name_head, files_name) fntab;
|
||||
|
||||
extern int profiling;
|
||||
extern int debugging;
|
||||
extern int found_defaults;
|
||||
|
||||
extern int maxusers;
|
||||
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -72,6 +72,7 @@ char srcdir[MAXPATHLEN];
|
||||
|
||||
int debugging;
|
||||
int profiling;
|
||||
int found_defaults;
|
||||
|
||||
static void configfile(void);
|
||||
static void get_srcdir(void);
|
||||
@ -123,8 +124,15 @@ main(int argc, char **argv)
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
if (freopen(PREFIX = *argv, "r", stdin) == NULL)
|
||||
err(2, "%s", PREFIX);
|
||||
PREFIX = *argv;
|
||||
if (freopen("DEFAULTS", "r", stdin) != NULL) {
|
||||
found_defaults = 1;
|
||||
yyfile = "DEFAULTS";
|
||||
} else {
|
||||
if (freopen(PREFIX, "r", stdin) == NULL)
|
||||
err(2, "%s", PREFIX);
|
||||
yyfile = PREFIX;
|
||||
}
|
||||
|
||||
if (*destdir != '\0') {
|
||||
len = strlen(destdir);
|
||||
@ -148,7 +156,6 @@ main(int argc, char **argv)
|
||||
STAILQ_INIT(&fntab);
|
||||
SLIST_INIT(&cputype);
|
||||
STAILQ_INIT(&ftab);
|
||||
yyfile = *argv;
|
||||
if (yyparse())
|
||||
exit(3);
|
||||
if (machinename == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user