From fcfeecc22b791bcba6b8d1411b88ab36125a99ea Mon Sep 17 00:00:00 2001 From: briggs Date: Sat, 18 Jan 1997 02:24:11 +0000 Subject: [PATCH] Sync. with current NetBSD--keeping local changes. --- usr.sbin/config/Makefile | 11 +- usr.sbin/config/Makefile.boot | 50 ++++++ usr.sbin/config/config.h | 40 ++++- usr.sbin/config/gram.y | 292 ++++++++++++++-------------------- usr.sbin/config/hash.c | 15 +- usr.sbin/config/main.c | 52 +++++- usr.sbin/config/mkioconf.c | 15 +- usr.sbin/config/scan.l | 148 +++++++++-------- usr.sbin/config/sem.c | 12 +- usr.sbin/config/sem.h | 6 +- usr.sbin/config/strerror.c | 19 +++ 11 files changed, 394 insertions(+), 266 deletions(-) create mode 100644 usr.sbin/config/Makefile.boot create mode 100644 usr.sbin/config/strerror.c diff --git a/usr.sbin/config/Makefile b/usr.sbin/config/Makefile index bb77cdf432e..1e5b7b00733 100644 --- a/usr.sbin/config/Makefile +++ b/usr.sbin/config/Makefile @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile,v 1.2 1996/03/25 15:55:00 niklas Exp $ -# $NetBSD: Makefile,v 1.11 1996/03/03 17:28:02 thorpej Exp $ +# $OpenBSD: Makefile,v 1.3 1997/01/18 02:24:11 briggs Exp $ +# $NetBSD: Makefile,v 1.12 1996/11/11 23:36:40 gwr Exp $ # from: @(#)Makefile 8.2 (Berkeley) 4/19/94 PROG= config @@ -7,8 +7,11 @@ BINDIR= /usr/sbin SRCS= files.c gram.y hash.c main.c mkheaders.c mkioconf.c mkmakefile.c \ mkswap.c pack.c scan.l sem.c util.c CFLAGS+=-I${.CURDIR} -I. -LDADD+= -ll -DPADD+= ${LIBL} + +# This program actually requires "flex" (not just any old lex). +# Also note that it does not use -ll +LEX=flex + CLEANFILES=gram.c scan.c y.tab.h MAN= config.8 diff --git a/usr.sbin/config/Makefile.boot b/usr.sbin/config/Makefile.boot new file mode 100644 index 00000000000..3f7830db8db --- /dev/null +++ b/usr.sbin/config/Makefile.boot @@ -0,0 +1,50 @@ +# $NetBSD: Makefile.boot,v 1.1 1996/11/07 22:59:39 gwr Exp $ +# from: @(#)Makefile 8.2 (Berkeley) 4/19/94 +# +# a very simple makefile... +# +# You only want to use this if you aren't running NetBSD. +# +CC=gcc -O +CFLAGS= -I. -DMAKE_BOOTSTRAP + +# Uncomment this if your system does not have strtoul (i.e. SunOS) +STRTOUL= -Dstrtoul=strtol + +# Note: The scanner here uses features specific to "flex" so +# do not bother even trying to make lex build the scanner. +# If you do not have flex, the source can be found in: +# src/usr.bin/lex (See Makefile.boot) +LEX=flex -l + +YACC=yacc + +OBJS= files.o hash.o main.o mkheaders.o mkioconf.o mkmakefile.o \ + mkswap.o pack.o sem.o util.o y.tab.o lex.yy.o strerror.o + +config: ${OBJS} + ${CC} -o $@ ${OBJS} + +y.tab.o : y.tab.c + ${CC} ${CFLAGS} -c y.tab.c + +y.tab.c y.tab.h : gram.y + ${YACC} -d gram.y + +lex.yy.o : lex.yy.c + ${CC} ${CFLAGS} ${STRTOUL} -c lex.yy.c + +lex.yy.c : scan.l + ${LEX} scan.l + +${OBJS} : config.h + +y.tab.o mkmakefile.o mkswap.o sem.o : sem.h +lex.yy.o : y.tab.h + +.c.o: + ${CC} ${CFLAGS} -c $< + +clean: + rm -f *.o config lex.yy.c y.tab.[ch] + diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h index e6ae2f8dff7..e97dc9c6d45 100644 --- a/usr.sbin/config/config.h +++ b/usr.sbin/config/config.h @@ -1,5 +1,5 @@ -/* $OpenBSD: config.h,v 1.6 1996/10/23 22:37:51 niklas Exp $ */ -/* $NetBSD: config.h,v 1.26 1996/08/31 21:15:05 mycroft Exp $ */ +/* $OpenBSD: config.h,v 1.7 1997/01/18 02:24:13 briggs Exp $ */ +/* $NetBSD: config.h,v 1.28 1996/11/11 23:40:09 gwr Exp $ */ /* * Copyright (c) 1992, 1993 @@ -45,6 +45,38 @@ * from: @(#)config.h 8.1 (Berkeley) 6/6/93 */ +/* + * config.h: Global definitions for "config" + */ + +#include +#include + +#if !defined(MAKE_BOOTSTRAP) && defined(BSD) +#include +#include +#else /* ...BSD */ +#if defined(__STDC__) || defined(__cplusplus) +#define __P(protos) protos /* full-blown ANSI C */ +#else /* ...STDC */ +#define __P(protos) () /* traditional C preprocessor */ +#endif /* ...STDC */ +#endif /* ...BSD */ + +#if __STDC__ +#include +#include +#endif + +/* These are really for MAKE_BOOTSTRAP but harmless. */ +#ifndef __dead +#define __dead +#endif +#ifndef _PATH_DEVNULL +#define _PATH_DEVNULL "/dev/null" +#endif + + /* * Name/value lists. Values can be strings or pointers and/or can carry * integers. The names can be NULL, resulting in simple value lists. @@ -206,7 +238,7 @@ struct files { u_char fi_flags; /* as below */ char fi_lastc; /* last char from path */ const char *fi_path; /* full file path */ - const char *fi_tail; /* name, i.e., rindex(fi_path, '/') + 1 */ + const char *fi_tail; /* name, i.e., strrchr(fi_path, '/') + 1 */ const char *fi_base; /* tail minus ".c" (or whatever) */ struct nvlist *fi_optx;/* options expression */ struct nvlist *fi_optf;/* flattened version of above, if needed */ @@ -293,6 +325,7 @@ void addoption __P((const char *name, const char *value)); void addmkoption __P((const char *name, const char *value)); int devbase_has_instances __P((struct devbase *, int)); int deva_has_instances __P((struct deva *, int)); +void setupdirs __P((void)); /* mkheaders.c */ int mkheaders __P((void)); @@ -311,6 +344,7 @@ void pack __P((void)); /* scan.l */ int currentline __P((void)); +int include __P((const char *, int)); /* sem.c, other than for yacc actions */ void initsem __P((void)); diff --git a/usr.sbin/config/gram.y b/usr.sbin/config/gram.y index c78de928e56..1f98ff9a992 100644 --- a/usr.sbin/config/gram.y +++ b/usr.sbin/config/gram.y @@ -1,6 +1,6 @@ %{ -/* $OpenBSD: gram.y,v 1.6 1996/10/23 22:37:52 niklas Exp $ */ -/* $NetBSD: gram.y,v 1.9 1996/08/31 21:15:07 mycroft Exp $ */ +/* $OpenBSD: gram.y,v 1.7 1997/01/18 02:24:14 briggs Exp $ */ +/* $NetBSD: gram.y,v 1.12 1996/11/11 23:54:17 gwr Exp $ */ /* * Copyright (c) 1992, 1993 @@ -46,11 +46,9 @@ * from: @(#)gram.y 8.1 (Berkeley) 6/6/93 */ -#include #include -#include +#include #include -#include #include #include #include @@ -65,7 +63,6 @@ int include __P((const char *, int)); void yyerror __P((const char *)); int yylex __P((void)); -extern const char *lastfile; static struct config conf; /* at most one active at a time */ @@ -88,10 +85,9 @@ static int adepth; #define fx_and(e1, e2) new0(NULL, NULL, e1, FX_AND, e2) #define fx_or(e1, e2) new0(NULL, NULL, e1, FX_OR, e2) -static void setupdirs __P((void)); static void cleanup __P((void)); static void setmachine __P((const char *, const char *)); -static void setmaxpartitions __P((int)); +static void check_maxpart __P((void)); %} @@ -107,11 +103,15 @@ static void setmaxpartitions __P((int)); %token AND AT ATTACH BUILD COMPILE_WITH CONFIG DEFINE DEVICE DISABLE DUMPS %token ENDFILE XFILE FLAGS INCLUDE XMACHINE MAJOR MAKEOPTIONS MAXUSERS %token MAXPARTITIONS MINOR ON OPTIONS PSEUDO_DEVICE ROOT SOURCE SWAP WITH -%token FFLAG NUMBER +%token NEEDS_COUNT NEEDS_FLAG +%token NUMBER %token PATHNAME WORD +%left '|' +%left '&' + %type fopts fexpr fatom -%type fflgs +%type fflgs fflag %type rule %type attr %type devbase @@ -130,9 +130,6 @@ static void setmaxpartitions __P((int)); %type major_minor signed_number npseudo %type flags_opt -%left '|' -%left '&' - %% /* @@ -140,81 +137,73 @@ static void setmaxpartitions __P((int)); * definition files (via the include() mechanism), followed by the * configuration specification(s) proper. In effect, this is two * separate grammars, with some shared terminals and nonterminals. + * Note that we do not have sufficient keywords to enforce any order + * between elements of "topthings" without introducing shift/reduce + * conflicts. Instead, check order requirements in the C code. */ Configuration: - dirs hdrs machine_spec /* "machine foo" from machine descr. */ - dev_defs dev_eof /* ../../conf/devices */ - dev_defs dev_eof /* devices.foo */ - maxpart_spec dev_defs dev_eof /* ../../conf/devices */ + topthings /* dirspecs, include "std.arch" */ + machine_spec /* "machine foo" from machine descr. */ + dev_defs dev_eof /* sys/conf/files */ + dev_defs dev_eof /* sys/arch/${MACHINE_ARCH}/... */ + dev_defs dev_eof /* sys/arch/${MACHINE}/... */ + { check_maxpart(); } specs; /* rest of machine description */ -dirs: - dirspecs = { setupdirs(); }; - -dirspecs: - dirspecs dir | +topthings: + topthings topthing | /* empty */; -dir: - SOURCE PATHNAME = { if (!srcdir) srcdir = $2; } | - BUILD PATHNAME = { if (!builddir) builddir = $2; } | - '\n'; - -hdrs: - hdrs hdr | - /* empty */; - -hdr: - include | +topthing: + SOURCE PATHNAME '\n' { if (!srcdir) srcdir = $2; } | + BUILD PATHNAME '\n' { if (!builddir) builddir = $2; } | + include '\n' | '\n'; machine_spec: - XMACHINE WORD = { setmachine($2,NULL); } | - XMACHINE WORD WORD = { setmachine($2,$3); } | - error = { stop("cannot proceed without machine specifier"); }; + XMACHINE WORD '\n' { setmachine($2,NULL); } | + XMACHINE WORD WORD '\n' { setmachine($2,$3); } | + error { stop("cannot proceed without machine specifier"); }; dev_eof: - ENDFILE = { enddefs(lastfile); checkfiles(); }; - -maxpart_blanks: - maxpart_blanks '\n' | - /* empty */; - -maxpart_spec: - maxpart_blanks MAXPARTITIONS NUMBER = { setmaxpartitions($3); } | - error = { stop("cannot proceed without maxpartitions specifier"); }; + ENDFILE { enddefs(); checkfiles(); }; /* * Various nonterminals shared between the grammars. */ file: - XFILE PATHNAME fopts fflgs rule = { addfile($2, $3, $4, $5); }; + XFILE PATHNAME fopts fflgs rule { addfile($2, $3, $4, $5); }; /* order of options is important, must use right recursion */ fopts: - fexpr = { $$ = $1; } | - /* empty */ = { $$ = NULL; }; + fexpr { $$ = $1; } | + /* empty */ { $$ = NULL; }; fexpr: - fatom = { $$ = $1; } | - '!' fatom = { $$ = fx_not($2); } | - fexpr '&' fexpr = { $$ = fx_and($1, $3); } | - fexpr '|' fexpr = { $$ = fx_or($1, $3); } | - '(' fexpr ')' = { $$ = $2; }; + fatom { $$ = $1; } | + '!' fatom { $$ = fx_not($2); } | + fexpr '&' fexpr { $$ = fx_and($1, $3); } | + fexpr '|' fexpr { $$ = fx_or($1, $3); } | + '(' fexpr ')' { $$ = $2; }; fatom: - WORD = { $$ = fx_atom($1); }; + WORD { $$ = fx_atom($1); }; fflgs: - fflgs FFLAG = { $$ = $1 | $2; } | - /* empty */ = { $$ = 0; }; + fflgs fflag { $$ = $1 | $2; } | + /* empty */ { $$ = 0; }; + +fflag: + NEEDS_COUNT { $$ = FI_NEEDSCOUNT; } | + NEEDS_FLAG { $$ = FI_NEEDSFLAG; }; rule: - COMPILE_WITH WORD = { $$ = $2; } | - /* empty */ = { $$ = NULL; }; + COMPILE_WITH WORD { $$ = $2; } | + /* empty */ { $$ = NULL; }; include: - INCLUDE WORD = { include($2, '\n'); }; + INCLUDE WORD { include($2, 0); }; + /* * The machine definitions grammar. @@ -224,90 +213,91 @@ dev_defs: /* empty */; dev_def: - one_def '\n' = { adepth = 0; } | + one_def '\n' { adepth = 0; } | '\n' | - error '\n' = { cleanup(); }; + error '\n' { cleanup(); }; one_def: file | include | - DEFINE WORD interface_opt = { (void)defattr($2, $3); } | + DEFINE WORD interface_opt { (void)defattr($2, $3); } | DEVICE devbase interface_opt attrs_opt - = { defdev($2, 0, $3, $4); } | + { defdev($2, 0, $3, $4); } | ATTACH devbase AT atlist devattach_opt attrs_opt - = { defdevattach($5, $2, $4, $6); } | - MAXUSERS NUMBER NUMBER NUMBER = { setdefmaxusers($2, $3, $4); } | - PSEUDO_DEVICE devbase attrs_opt = { defdev($2,1,NULL,$3); } | + { defdevattach($5, $2, $4, $6); } | + MAXUSERS NUMBER NUMBER NUMBER { setdefmaxusers($2, $3, $4); } | + MAXPARTITIONS NUMBER { maxpartitions = $2; } | + PSEUDO_DEVICE devbase attrs_opt { defdev($2,1,NULL,$3); } | MAJOR '{' majorlist '}'; disable: - DISABLE = { $$ = 1; } | - /* empty */ = { $$ = 0; }; + DISABLE { $$ = 1; } | + /* empty */ { $$ = 0; }; atlist: - atlist ',' atname = { $$ = new_nx($3, $1); } | - atname = { $$ = new_n($1); }; + atlist ',' atname { $$ = new_nx($3, $1); } | + atname { $$ = new_n($1); }; atname: - WORD = { $$ = $1; } | - ROOT = { $$ = NULL; }; + WORD { $$ = $1; } | + ROOT { $$ = NULL; }; devbase: - WORD = { $$ = getdevbase($1); }; + WORD { $$ = getdevbase($1); }; devattach_opt: - WITH WORD = { $$ = getdevattach($2); } | - /* empty */ = { $$ = NULL; }; + WITH WORD { $$ = getdevattach($2); } | + /* empty */ { $$ = NULL; }; interface_opt: - '{' loclist_opt '}' = { $$ = new_nx("", $2); } | - /* empty */ = { $$ = NULL; }; + '{' loclist_opt '}' { $$ = new_nx("", $2); } | + /* empty */ { $$ = NULL; }; loclist_opt: - loclist = { $$ = $1; } | - /* empty */ = { $$ = NULL; }; + loclist { $$ = $1; } | + /* empty */ { $$ = NULL; }; /* loclist order matters, must use right recursion */ loclist: - locdef ',' loclist = { ($$ = $1)->nv_next = $3; } | - locdef = { $$ = $1; }; + locdef ',' loclist { ($$ = $1)->nv_next = $3; } | + locdef { $$ = $1; }; /* "[ WORD locdefault ]" syntax may be unnecessary... */ locdef: - WORD locdefault = { $$ = new_nsi($1, $2, 0); } | - WORD = { $$ = new_nsi($1, NULL, 0); } | - '[' WORD locdefault ']' = { $$ = new_nsi($2, $3, 1); }; + WORD locdefault { $$ = new_nsi($1, $2, 0); } | + WORD { $$ = new_nsi($1, NULL, 0); } | + '[' WORD locdefault ']' { $$ = new_nsi($2, $3, 1); }; locdefault: - '=' value = { $$ = $2; }; + '=' value { $$ = $2; }; value: - WORD = { $$ = $1; } | - signed_number = { char bf[40]; + WORD { $$ = $1; } | + signed_number { char bf[40]; (void)sprintf(bf, FORMAT($1), $1); $$ = intern(bf); }; signed_number: - NUMBER = { $$ = $1; } | - '-' NUMBER = { $$ = -$2; }; + NUMBER { $$ = $1; } | + '-' NUMBER { $$ = -$2; }; attrs_opt: - ':' attrs = { $$ = $2; } | - /* empty */ = { $$ = NULL; }; + ':' attrs { $$ = $2; } | + /* empty */ { $$ = NULL; }; attrs: - attrs ',' attr = { $$ = new_px($3, $1); } | - attr = { $$ = new_p($1); }; + attrs ',' attr { $$ = new_px($3, $1); } | + attr { $$ = new_p($1); }; attr: - WORD = { $$ = getattr($1); }; + WORD { $$ = getattr($1); }; majorlist: majorlist ',' majordef | majordef; majordef: - devbase '=' NUMBER = { setmajor($1, $3); }; + devbase '=' NUMBER { setmajor($1, $3); }; @@ -319,38 +309,38 @@ specs: /* empty */; spec: - config_spec '\n' = { adepth = 0; } | + config_spec '\n' { adepth = 0; } | '\n' | - error '\n' = { cleanup(); }; + error '\n' { cleanup(); }; config_spec: file | include | OPTIONS opt_list | MAKEOPTIONS mkopt_list | - MAXUSERS NUMBER = { setmaxusers($2); } | - CONFIG conf sysparam_list = { addconf(&conf); } | - PSEUDO_DEVICE WORD npseudo = { addpseudo($2, $3); } | + MAXUSERS NUMBER { setmaxusers($2); } | + CONFIG conf sysparam_list { addconf(&conf); } | + PSEUDO_DEVICE WORD npseudo { addpseudo($2, $3); } | device_instance AT attachment disable locators flags_opt - = { adddev($1, $3, $5, $6, $4); }; + { adddev($1, $3, $5, $6, $4); }; mkopt_list: mkopt_list ',' mkoption | mkoption; mkoption: - WORD '=' value = { addmkoption($1, $3); } + WORD '=' value { addmkoption($1, $3); } opt_list: opt_list ',' option | option; option: - WORD = { addoption($1, NULL); } | - WORD '=' value = { addoption($1, $3); }; + WORD { addoption($1, NULL); } | + WORD '=' value { addoption($1, $3); }; conf: - WORD = { conf.cf_name = $1; + WORD { conf.cf_name = $1; conf.cf_lineno = currentline(); conf.cf_root = NULL; conf.cf_swap = NULL; @@ -361,48 +351,48 @@ sysparam_list: sysparam; sysparam: - ROOT on_opt dev_spec = { setconf(&conf.cf_root, "root", $3); } | - SWAP on_opt swapdev_list = { setconf(&conf.cf_swap, "swap", $3); } | - DUMPS on_opt dev_spec = { setconf(&conf.cf_dump, "dumps", $3); }; + ROOT on_opt dev_spec { setconf(&conf.cf_root, "root", $3); } | + SWAP on_opt swapdev_list { setconf(&conf.cf_swap, "swap", $3); } | + DUMPS on_opt dev_spec { setconf(&conf.cf_dump, "dumps", $3); }; swapdev_list: - dev_spec AND swapdev_list = { ($$ = $1)->nv_next = $3; } | - dev_spec = { $$ = $1; }; + dev_spec AND swapdev_list { ($$ = $1)->nv_next = $3; } | + dev_spec { $$ = $1; }; dev_spec: - WORD = { $$ = new_si($1, NODEV); } | - major_minor = { $$ = new_si(NULL, $1); }; + WORD { $$ = new_si($1, NODEV); } | + major_minor { $$ = new_si(NULL, $1); }; major_minor: - MAJOR NUMBER MINOR NUMBER = { $$ = makedev($2, $4); }; + MAJOR NUMBER MINOR NUMBER { $$ = makedev($2, $4); }; on_opt: ON | /* empty */; npseudo: - NUMBER = { $$ = $1; } | - /* empty */ = { $$ = 1; }; + NUMBER { $$ = $1; } | + /* empty */ { $$ = 1; }; device_instance: - WORD '*' = { $$ = starref($1); } | - WORD = { $$ = $1; }; + WORD '*' { $$ = starref($1); } | + WORD { $$ = $1; }; attachment: - ROOT = { $$ = NULL; } | - WORD '?' = { $$ = wildref($1); } | - WORD = { $$ = $1; }; + ROOT { $$ = NULL; } | + WORD '?' { $$ = wildref($1); } | + WORD { $$ = $1; }; locators: - locators locator = { ($$ = $2)->nv_next = $1; } | - /* empty */ = { $$ = NULL; }; + locators locator { ($$ = $2)->nv_next = $1; } | + /* empty */ { $$ = NULL; }; locator: - WORD value = { $$ = new_ns($1, $2); } | - WORD '?' = { $$ = new_ns($1, NULL); }; + WORD value { $$ = new_ns($1, $2); } | + WORD '?' { $$ = new_ns($1, NULL); }; flags_opt: - FLAGS NUMBER = { $$ = $2; } | - /* empty */ = { $$ = 0; }; + FLAGS NUMBER { $$ = $2; } | + /* empty */ { $$ = 0; }; %% @@ -414,48 +404,6 @@ yyerror(s) error("%s", s); } -/* - * Verify/create builddir if necessary, change to it, and verify srcdir. - */ -static void -setupdirs() -{ - struct stat st; - char *prof; - - /* srcdir must be specified if builddir is not specified or if - * no configuration filename was specified. */ - if ((builddir || strcmp(defbuilddir, ".") == 0) && !srcdir) - stop("source directory must be specified"); - - if (srcdir == NULL) - srcdir = "../../../.."; - if (builddir == NULL) - builddir = defbuilddir; - - if (stat(builddir, &st) != 0) { - if (mkdir(builddir, 0777)) { - (void)fprintf(stderr, "config: cannot create %s: %s\n", - builddir, strerror(errno)); - exit(2); - } - } else if (!S_ISDIR(st.st_mode)) { - (void)fprintf(stderr, "config: %s is not a directory\n", - builddir); - exit(2); - } - if (chdir(builddir) != 0) { - (void)fprintf(stderr, "config: cannot change to %s\n", - builddir); - exit(2); - } - if (stat(srcdir, &st) != 0 || !S_ISDIR(st.st_mode)) { - (void)fprintf(stderr, "config: %s is not a directory\n", - srcdir); - exit(2); - } -} - /* * Cleanup procedure after syntax error: release any nvlists * allocated during parsing the current line. @@ -498,9 +446,9 @@ setmachine(mch, mcharch) } static void -setmaxpartitions(n) - int n; +check_maxpart() { - - maxpartitions = n; + if (maxpartitions <= 0) { + stop("cannot proceed without maxpartitions specifier"); + } } diff --git a/usr.sbin/config/hash.c b/usr.sbin/config/hash.c index 538b7a703ff..bdff477855a 100644 --- a/usr.sbin/config/hash.c +++ b/usr.sbin/config/hash.c @@ -1,5 +1,5 @@ -/* $OpenBSD: hash.c,v 1.3 1996/04/21 23:40:12 deraadt Exp $ */ -/* $NetBSD: hash.c,v 1.3 1996/03/17 13:18:20 cgd Exp $ */ +/* $OpenBSD: hash.c,v 1.4 1997/01/18 02:24:15 briggs Exp $ */ +/* $NetBSD: hash.c,v 1.4 1996/11/07 22:59:43 gwr Exp $ */ /* * Copyright (c) 1992, 1993 @@ -50,6 +50,17 @@ #include #include "config.h" +/* + * These are really for MAKE_BOOTSTRAP but harmless. + * XXX - Why not just use malloc in here, anyway? + */ +#ifndef ALIGNBYTES +#define ALIGNBYTES 3 +#endif +#ifndef ALIGN +#define ALIGN(p) (((long)(p) + ALIGNBYTES) &~ ALIGNBYTES) +#endif + /* * Interned strings are kept in a hash table. By making each string * unique, the program can compare strings by comparing pointers. diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index 5d7aa13a19d..cd668e0e029 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.9 1997/01/15 23:43:53 millert Exp $ */ +/* $OpenBSD: main.c,v 1.10 1997/01/18 02:24:16 briggs Exp $ */ /* $NetBSD: main.c,v 1.18 1996/08/31 20:58:20 mycroft Exp $ */ /* @@ -111,7 +111,7 @@ main(argc, argv) /* * Essentially the same as makeoptions PROF="-pg", * but also changes the path from ../../compile/FOO - * to ../../compile/FOO.prof; i.e., compile a + * to ../../compile/FOO.PROF; i.e., compile a * profiling kernel based on a typical "regular" * kernel. * @@ -419,6 +419,9 @@ cfcrosscheck(cf, what, nv) register struct devi *pd; int errs, devminor; + if (maxpartitions <= 0) + panic("cfcrosscheck"); + for (errs = 0; nv != NULL; nv = nv->nv_next) { if (nv->nv_name == NULL) continue; @@ -519,3 +522,48 @@ badstar() } return (errs); } + +/* + * Verify/create builddir if necessary, change to it, and verify srcdir. + * This will be called when we see the first include. + */ +void +setupdirs() +{ + struct stat st; + char *prof; + + /* srcdir must be specified if builddir is not specified or if + * no configuration filename was specified. */ + if ((builddir || strcmp(defbuilddir, ".") == 0) && !srcdir) { + error("source directory must be specified"); + exit(1); + } + + if (srcdir == NULL) + srcdir = "../../../.."; + if (builddir == NULL) + builddir = defbuilddir; + + if (stat(builddir, &st) != 0) { + if (mkdir(builddir, 0777)) { + (void)fprintf(stderr, "config: cannot create %s: %s\n", + builddir, strerror(errno)); + exit(2); + } + } else if (!S_ISDIR(st.st_mode)) { + (void)fprintf(stderr, "config: %s is not a directory\n", + builddir); + exit(2); + } + if (chdir(builddir) != 0) { + (void)fprintf(stderr, "config: cannot change to %s\n", + builddir); + exit(2); + } + if (stat(srcdir, &st) != 0 || !S_ISDIR(st.st_mode)) { + (void)fprintf(stderr, "config: %s is not a directory\n", + srcdir); + exit(2); + } +} diff --git a/usr.sbin/config/mkioconf.c b/usr.sbin/config/mkioconf.c index 54f5206c8bd..7e1ae8ad673 100644 --- a/usr.sbin/config/mkioconf.c +++ b/usr.sbin/config/mkioconf.c @@ -1,5 +1,5 @@ -/* $OpenBSD: mkioconf.c,v 1.7 1996/10/23 22:37:55 niklas Exp $ */ -/* $NetBSD: mkioconf.c,v 1.40 1996/08/31 21:15:10 mycroft Exp $ */ +/* $OpenBSD: mkioconf.c,v 1.8 1997/01/18 02:24:17 briggs Exp $ */ +/* $NetBSD: mkioconf.c,v 1.41 1996/11/11 14:18:49 mycroft Exp $ */ /* * Copyright (c) 1992, 1993 @@ -343,7 +343,7 @@ emitcfdata(fp) { register struct devi **p, *i, **par; register int unit, v; - register const char *vs, *state, *basename, *attachment; + register const char *state, *basename, *attachment; register struct nvlist *nv; register struct attr *a; char *loc; @@ -356,7 +356,7 @@ emitcfdata(fp) #define DSTR FSTATE_DSTAR\n\ \n\ struct cfdata cfdata[] = {\n\ - /* attachment driver unit state loc flags parents nm ivstubs */\n") < 0) + /* attachment driver unit state loc flags parents */\n") < 0) return (1); for (p = packed; (i = *p) != NULL; p++) { /* the description */ @@ -396,19 +396,16 @@ struct cfdata cfdata[] = {\n\ state = "NORM"; } } - vs = ""; - v = 0; if (i->i_locoff >= 0) { (void)sprintf(locbuf, "loc+%3d", i->i_locoff); loc = locbuf; } else loc = "loc"; if (fprintf(fp, "\ - {&%s_ca,%s&%s_cd,%s%2d, %s, %7s, %#4x, pv+%2d, %d, %s%d},\n", + {&%s_ca,%s&%s_cd,%s%2d, %s, %7s, %#6x, pv+%2d},\n", attachment, strlen(attachment) < 6 ? "\t\t" : "\t", basename, strlen(basename) < 3 ? "\t\t" : "\t", unit, - state, loc, i->i_cfflags, i->i_pvoff, i->i_locnami, - vs, v) < 0) + state, loc, i->i_cfflags, i->i_pvoff) < 0) return (1); } if (fprintf(fp, " {0},\n {0},\n {0},\n {0},\n") < 0) diff --git a/usr.sbin/config/scan.l b/usr.sbin/config/scan.l index 542c5e31eff..b5779841ea7 100644 --- a/usr.sbin/config/scan.l +++ b/usr.sbin/config/scan.l @@ -1,6 +1,6 @@ %{ -/* $OpenBSD: scan.l,v 1.6 1996/10/23 22:37:59 niklas Exp $ */ -/* $NetBSD: scan.l,v 1.7 1996/08/31 21:15:13 mycroft Exp $ */ +/* $OpenBSD: scan.l,v 1.7 1997/01/18 02:24:18 briggs Exp $ */ +/* $NetBSD: scan.l,v 1.11 1996/11/13 18:42:18 gwr Exp $ */ /* * Copyright (c) 1992, 1993 @@ -59,8 +59,6 @@ int yyline; const char *yyfile; const char *lastfile; -int include __P((const char *, int)); - /* * Data for returning to previous files from include files. */ @@ -69,61 +67,68 @@ struct incl { YY_BUFFER_STATE in_buf; /* previous lex state */ const char *in_fname; /* previous file name */ int in_lineno; /* previous line number */ - int in_preveof; /* previous eoftoken */ + int in_ateof; /* token to insert at EOF */ }; static struct incl *incl; -static int eoftoken; /* current EOF token */ -static void endinclude __P((void)); +static int endinclude __P((void)); #define yywrap() 1 %} -PATH [-/A-Za-z0-9_.]*[./][-/A-Za-z0-9_.]* +PATH [A-Za-z_0-9]*[./][-A-Za-z_0-9./]* WORD [A-Za-z_][-A-Za-z_0-9]* %% + /* Local variables for yylex() */ + int tok; + +and return AND; +at return AT; +attach return ATTACH; +build return BUILD; +compile-with return COMPILE_WITH; +config return CONFIG; +define return DEFINE; +device return DEVICE; +disable return DISABLE; +dumps return DUMPS; +file return XFILE; +flags return FLAGS; +include return INCLUDE; +machine return XMACHINE; +major return MAJOR; +makeoptions return MAKEOPTIONS; +maxpartitions return MAXPARTITIONS; +maxusers return MAXUSERS; +minor return MINOR; +needs-count return NEEDS_COUNT; +needs-flag return NEEDS_FLAG; +on return ON; +options return OPTIONS; +option return OPTIONS; +pseudo-device return PSEUDO_DEVICE; +root return ROOT; +source return SOURCE; +swap return SWAP; +with return WITH; + +{PATH} { + yylval.str = intern(yytext); + return PATHNAME; + } +{WORD} { + yylval.str = intern(yytext); + return WORD; + } - /* plain keywords */ -and { return AND; } -at { return AT; } -attach { return ATTACH; } -build { return BUILD; } -compile-with { return COMPILE_WITH; } -config { return CONFIG; } -define { return DEFINE; } -device { return DEVICE; } -disable { return DISABLE; } -dumps { return DUMPS; } -flags { return FLAGS; } -file { return XFILE; } -include { return INCLUDE; } -machine { return XMACHINE; } -major { return MAJOR; } -makeoptions { return MAKEOPTIONS; } -maxusers { return MAXUSERS; } -maxpartitions { return MAXPARTITIONS; } -minor { return MINOR; } -on { return ON; } -options { return OPTIONS; } -option { return OPTIONS; } -"pseudo-device" { return PSEUDO_DEVICE; } -root { return ROOT; } -source { return SOURCE; } -swap { return SWAP; } -with { return WITH; } - - /* keywords with values */ -needs-count { yylval.val = FI_NEEDSCOUNT; return FFLAG; } -needs-flag { yylval.val = FI_NEEDSFLAG; return FFLAG; } - - /* all the rest */ -{PATH} { yylval.str = intern(yytext); return PATHNAME; } -{WORD} { yylval.str = intern(yytext); return WORD; } - -\"([^"]|\\\")*/\" { +\"([^"\n]|\\\")+ { + tok = input(); /* eat closing quote */ + if (tok != '"') { + error("closing quote missing\n"); + unput(tok); + } yylval.str = intern(yytext + 1); - (void)input(); /* eat closing quote */ return WORD; } 0[0-7]* { @@ -138,7 +143,12 @@ needs-flag { yylval.val = FI_NEEDSFLAG; return FFLAG; } yylval.val = strtol(yytext, NULL, 10); return NUMBER; } -\n/[ \t] { +\n[ \t] { + /* + * Note: newline followed by whitespace is always a + * continuation of the previous line, so do NOT + * return a token in this case. + */ yyline++; } \n { @@ -146,16 +156,15 @@ needs-flag { yylval.val = FI_NEEDSFLAG; return FFLAG; } return '\n'; } #.* { /* ignored (comment) */; } -[ \t]* { /* ignored (white space) */; } +[ \t]+ { /* ignored (white space) */; } . { return yytext[0]; } <> { - int tok; - - tok = eoftoken; - eoftoken = YY_NULL; - if (incl != NULL) - endinclude(); - return (tok); + if (incl == NULL) + return YY_NULL; + tok = endinclude(); + if (tok) + return tok; + /* otherwise continue scanning */ } %% @@ -172,7 +181,6 @@ firstfile(fname) return (-1); yyfile = conffile = fname; yyline = 1; - eoftoken = YY_NULL; return (0); } @@ -180,17 +188,23 @@ firstfile(fname) * Open the named file for inclusion at the current point. Returns 0 on * success (file opened and previous state pushed), nonzero on failure * (fopen failed, complaint made). The `ateof' parameter controls the - * token to be returned at the end of the include file (typically '\n' - * or ENDFILE). + * token to be inserted at the end of the include file (i.e. ENDFILE). + * If ateof == 0 then nothing is inserted. */ int include(fname, ateof) const char *fname; int ateof; { - register FILE *fp; - register struct incl *in; + FILE *fp; + struct incl *in; char *s; + static int havedirs; + + if (havedirs == 0) { + havedirs = 1; + setupdirs(); + } /* Kludge until files.* files are fixed. */ if (strncmp(fname, "../../../", 9) == 0) @@ -207,12 +221,11 @@ include(fname, ateof) in->in_buf = YY_CURRENT_BUFFER; in->in_fname = yyfile; in->in_lineno = yyline; - in->in_preveof = eoftoken; + in->in_ateof = ateof; incl = in; yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); yyfile = intern(s); yyline = 1; - eoftoken = ateof; free(s); return (0); } @@ -220,10 +233,11 @@ include(fname, ateof) /* * Terminate the most recent inclusion. */ -static void +static int endinclude() { - register struct incl *in; + struct incl *in; + int ateof; if ((in = incl) == NULL) panic("endinclude"); @@ -234,8 +248,10 @@ endinclude() yy_switch_to_buffer(in->in_buf); yyfile = in->in_fname; yyline = in->in_lineno; - eoftoken = in->in_preveof; + ateof = in->in_ateof; free(in); + + return (ateof); } /* diff --git a/usr.sbin/config/sem.c b/usr.sbin/config/sem.c index d796b84c152..94e667140d2 100644 --- a/usr.sbin/config/sem.c +++ b/usr.sbin/config/sem.c @@ -1,5 +1,5 @@ -/* $OpenBSD: sem.c,v 1.8 1996/12/12 00:24:44 niklas Exp $ */ -/* $NetBSD: sem.c,v 1.9 1996/08/31 21:15:15 mycroft Exp $ */ +/* $OpenBSD: sem.c,v 1.9 1997/01/18 02:24:19 briggs Exp $ */ +/* $NetBSD: sem.c,v 1.10 1996/11/11 23:40:11 gwr Exp $ */ /* * Copyright (c) 1992, 1993 @@ -121,9 +121,11 @@ initsem() s_qmark = intern("?"); } +/* Name of include file just ended (set in scan.l) */ +extern const char *lastfile; + void -enddefs(fname) - const char *fname; +enddefs() { register struct devbase *dev; @@ -131,7 +133,7 @@ enddefs(fname) if (!dev->d_isdef) { (void)fprintf(stderr, "%s: device `%s' used but not defined\n", - fname, dev->d_name); + lastfile, dev->d_name); errors++; continue; } diff --git a/usr.sbin/config/sem.h b/usr.sbin/config/sem.h index 9e439f211d7..3dd75d4e745 100644 --- a/usr.sbin/config/sem.h +++ b/usr.sbin/config/sem.h @@ -1,5 +1,5 @@ -/* $OpenBSD: sem.h,v 1.5 1996/10/23 22:38:01 niklas Exp $ */ -/* $NetBSD: sem.h,v 1.5 1996/08/31 21:15:16 mycroft Exp $ */ +/* $OpenBSD: sem.h,v 1.6 1997/01/18 02:24:20 briggs Exp $ */ +/* $NetBSD: sem.h,v 1.6 1996/11/11 23:40:10 gwr Exp $ */ /* * Copyright (c) 1992, 1993 @@ -45,7 +45,7 @@ * from: @(#)sem.h 8.1 (Berkeley) 6/6/93 */ -void enddefs __P((const char *)); +void enddefs __P((void)); void setdefmaxusers __P((int, int, int)); void setmaxusers __P((int)); diff --git a/usr.sbin/config/strerror.c b/usr.sbin/config/strerror.c new file mode 100644 index 00000000000..2d3eb60068b --- /dev/null +++ b/usr.sbin/config/strerror.c @@ -0,0 +1,19 @@ +/* + * strerror() - for those systems that don't have it yet. + */ + +/* These are part of the C library. (See perror.3) */ +extern char *sys_errlist[]; +extern int sys_nerr; + +static char errmsg[80]; + +char *strerror(en) + int en; +{ + if ((0 <= en) && (en < sys_nerr)) + return sys_errlist[en]; + + sprintf(errmsg, "Error %d", en); + return errmsg; +} -- 2.20.1