1999-01-21 16:10:08 +03:00
|
|
|
/* $NetBSD: mkheaders.c,v 1.22 1999/01/21 13:10:09 pk Exp $ */
|
1996-03-03 20:21:25 +03:00
|
|
|
|
1996-03-17 09:29:19 +03:00
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratories.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1995-04-28 10:54:58 +04:00
|
|
|
*
|
|
|
|
* from: @(#)mkheaders.c 8.1 (Berkeley) 6/6/93
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
#include <sys/param.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <ctype.h>
|
1995-04-28 10:54:58 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
static int emitcnt __P((struct nvlist *));
|
1997-03-14 03:14:09 +03:00
|
|
|
static int emitlocs __P((void));
|
1998-01-12 10:37:40 +03:00
|
|
|
static int emitopts __P((void));
|
|
|
|
static int emitioconfh __P((void));
|
1998-10-16 18:27:17 +04:00
|
|
|
static int herr __P((const char *, const char *, FILE *));
|
1997-03-14 03:14:09 +03:00
|
|
|
static int locators_print __P((const char *, void *, void *));
|
1998-01-12 10:37:40 +03:00
|
|
|
static int defopts_print __P((const char *, void *, void *));
|
1995-04-28 10:54:58 +04:00
|
|
|
static char *cntname __P((const char *));
|
1998-01-12 10:37:40 +03:00
|
|
|
static int cmphdr __P((const char *, const char *));
|
1998-06-24 15:20:54 +04:00
|
|
|
static int fprintcnt(FILE *fp, struct nvlist *nv);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-03-14 03:14:09 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1998-01-12 10:37:40 +03:00
|
|
|
* Make the various config-generated header files.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1995-04-28 10:54:58 +04:00
|
|
|
int
|
|
|
|
mkheaders()
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct files *fi;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
1998-01-12 10:37:40 +03:00
|
|
|
/*
|
|
|
|
* Make headers containing counts, as needed.
|
|
|
|
*/
|
1995-04-28 10:54:58 +04:00
|
|
|
for (fi = allfiles; fi != NULL; fi = fi->fi_next) {
|
|
|
|
if (fi->fi_flags & FI_HIDDEN)
|
|
|
|
continue;
|
|
|
|
if (fi->fi_flags & (FI_NEEDSCOUNT | FI_NEEDSFLAG) &&
|
1996-03-17 16:18:15 +03:00
|
|
|
emitcnt(fi->fi_optf))
|
1995-04-28 10:54:58 +04:00
|
|
|
return (1);
|
|
|
|
}
|
1997-02-03 00:12:30 +03:00
|
|
|
|
1998-01-12 10:37:40 +03:00
|
|
|
if (emitopts() || emitlocs() || emitioconfh())
|
1997-03-14 03:14:09 +03:00
|
|
|
return (1);
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1998-06-24 15:20:54 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
fprintcnt(fp, nv)
|
|
|
|
FILE *fp;
|
|
|
|
struct nvlist *nv;
|
|
|
|
{
|
|
|
|
return (fprintf(fp, "#define\t%s\t%d\n",
|
|
|
|
cntname(nv->nv_name), nv->nv_int));
|
|
|
|
}
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
static int
|
|
|
|
emitcnt(head)
|
1997-10-18 11:58:56 +04:00
|
|
|
struct nvlist *head;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-01-12 10:37:40 +03:00
|
|
|
char nfname[BUFSIZ], tfname[BUFSIZ];
|
1997-10-18 11:58:56 +04:00
|
|
|
struct nvlist *nv;
|
|
|
|
FILE *fp;
|
1998-01-12 10:37:40 +03:00
|
|
|
|
|
|
|
(void)sprintf(nfname, "%s.h", head->nv_name);
|
|
|
|
(void)sprintf(tfname, "tmp_%s", nfname);
|
|
|
|
|
1998-10-16 18:27:17 +04:00
|
|
|
if ((fp = fopen(tfname, "w")) == NULL)
|
|
|
|
return (herr("open", tfname, NULL));
|
1998-01-12 10:37:40 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
for (nv = head; nv != NULL; nv = nv->nv_next)
|
1998-06-24 15:20:54 +04:00
|
|
|
if (fprintcnt(fp, nv) < 0)
|
1998-10-16 18:27:17 +04:00
|
|
|
return (herr("writ", tfname, fp));
|
1998-01-12 10:37:40 +03:00
|
|
|
|
|
|
|
if (fclose(fp) == EOF)
|
1998-10-16 18:27:17 +04:00
|
|
|
return (herr("clos", tfname, NULL));
|
1998-01-12 10:37:40 +03:00
|
|
|
|
|
|
|
return (cmphdr(tfname, nfname));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1998-01-12 10:37:40 +03:00
|
|
|
/*
|
|
|
|
* Callback function for walking the option file hash table. We write out
|
|
|
|
* the options defined for this file.
|
|
|
|
*/
|
1997-02-03 00:12:30 +03:00
|
|
|
static int
|
1998-01-12 10:37:40 +03:00
|
|
|
defopts_print(name, value, arg)
|
|
|
|
const char *name;
|
|
|
|
void *value, *arg;
|
1997-02-03 00:12:30 +03:00
|
|
|
{
|
1998-01-12 10:37:40 +03:00
|
|
|
char tfname[BUFSIZ];
|
|
|
|
struct nvlist *nv, *option;
|
1998-02-19 09:13:51 +03:00
|
|
|
int isfsoption;
|
1998-06-24 15:20:54 +04:00
|
|
|
int isparam;
|
|
|
|
int isflag;
|
1997-02-03 00:12:30 +03:00
|
|
|
FILE *fp;
|
|
|
|
|
1998-01-12 10:37:40 +03:00
|
|
|
(void)sprintf(tfname, "tmp_%s", name);
|
1998-10-16 18:27:17 +04:00
|
|
|
if ((fp = fopen(tfname, "w")) == NULL)
|
|
|
|
return (herr("open", tfname, NULL));
|
1998-01-12 10:37:40 +03:00
|
|
|
|
|
|
|
for (nv = value; nv != NULL; nv = nv->nv_next) {
|
1998-06-30 07:30:56 +04:00
|
|
|
isfsoption = OPT_FSOPT(nv->nv_name);
|
|
|
|
isparam = OPT_DEFPARAM(nv->nv_name);
|
|
|
|
isflag = OPT_DEFFLAG(nv->nv_name);
|
1998-02-19 09:13:51 +03:00
|
|
|
|
|
|
|
if ((option = ht_lookup(opttab, nv->nv_name)) == NULL &&
|
|
|
|
(option = ht_lookup(fsopttab, nv->nv_name)) == NULL) {
|
|
|
|
if (fprintf(fp, "/* %s `%s' not defined */\n",
|
|
|
|
isfsoption ? "file system" : "option",
|
1998-01-12 10:37:40 +03:00
|
|
|
nv->nv_name) < 0)
|
|
|
|
goto bad;
|
|
|
|
} else {
|
|
|
|
if (fprintf(fp, "#define\t%s", option->nv_name) < 0)
|
|
|
|
goto bad;
|
1998-02-19 09:13:51 +03:00
|
|
|
if (option->nv_str != NULL && isfsoption == 0 &&
|
1998-01-12 10:37:40 +03:00
|
|
|
fprintf(fp, "\t%s", option->nv_str) < 0)
|
|
|
|
goto bad;
|
|
|
|
if (fputc('\n', fp) < 0)
|
|
|
|
goto bad;
|
|
|
|
}
|
1998-06-24 15:20:54 +04:00
|
|
|
if (isflag)
|
|
|
|
fprintcnt(fp, nv);
|
|
|
|
|
1998-01-12 10:37:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fclose(fp) == EOF)
|
1998-10-16 18:27:17 +04:00
|
|
|
return (herr("clos", tfname, NULL));
|
1998-01-12 10:37:40 +03:00
|
|
|
|
|
|
|
return (cmphdr(tfname, name));
|
|
|
|
|
|
|
|
bad:
|
1998-10-16 18:27:17 +04:00
|
|
|
return (herr("writ", tfname, fp));
|
1998-01-12 10:37:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit the option header files.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
emitopts()
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ht_enumerate(optfiletab, defopts_print, NULL));
|
1997-02-03 00:12:30 +03:00
|
|
|
}
|
|
|
|
|
1997-03-14 03:14:09 +03:00
|
|
|
/*
|
|
|
|
* A callback function for walking the attribute hash table.
|
|
|
|
* Emit CPP definitions of manifest constants for the locators on the
|
|
|
|
* "name" attribute node (passed as the "value" parameter).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
locators_print(name, value, arg)
|
|
|
|
const char *name;
|
|
|
|
void *value;
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct attr *a;
|
1997-10-18 11:58:56 +04:00
|
|
|
struct nvlist *nv;
|
|
|
|
int i;
|
1997-03-14 03:14:09 +03:00
|
|
|
char *locdup, *namedup;
|
1997-10-18 11:58:56 +04:00
|
|
|
char *cp;
|
1997-03-14 03:14:09 +03:00
|
|
|
FILE *fp = arg;
|
|
|
|
|
|
|
|
a = value;
|
|
|
|
if (a->a_locs) {
|
1997-07-18 15:27:37 +04:00
|
|
|
if (strchr(name, ' ') != NULL || strchr(name, '\t') != NULL)
|
|
|
|
/*
|
|
|
|
* name contains a space; we can't generate
|
|
|
|
* usable defines, so ignore it.
|
|
|
|
*/
|
|
|
|
return 0;
|
1997-03-14 03:14:09 +03:00
|
|
|
locdup = strdup(name);
|
|
|
|
for (cp = locdup; *cp; cp++)
|
|
|
|
if (islower(*cp))
|
|
|
|
*cp = toupper(*cp);
|
|
|
|
if (fprintf(fp, "extern const char *%scf_locnames[];\n",
|
1998-10-16 18:27:17 +04:00
|
|
|
name) < 0)
|
1997-03-14 03:14:09 +03:00
|
|
|
return 1;
|
|
|
|
for (i = 0, nv = a->a_locs; nv; nv = nv->nv_next, i++) {
|
1997-07-18 15:27:37 +04:00
|
|
|
if (strchr(nv->nv_name, ' ') != NULL ||
|
|
|
|
strchr(nv->nv_name, '\t') != NULL)
|
|
|
|
/*
|
|
|
|
* name contains a space; we can't generate
|
|
|
|
* usable defines, so ignore it.
|
|
|
|
*/
|
|
|
|
continue;
|
1997-03-14 03:14:09 +03:00
|
|
|
namedup = strdup(nv->nv_name);
|
|
|
|
for (cp = namedup; *cp; cp++)
|
|
|
|
if (islower(*cp))
|
|
|
|
*cp = toupper(*cp);
|
1999-01-21 16:10:08 +03:00
|
|
|
else if (*cp == ARRCHR)
|
|
|
|
*cp = '_';
|
1997-03-14 03:14:09 +03:00
|
|
|
if (fprintf(fp, "#define %sCF_%s %d\n",
|
1998-10-16 18:27:17 +04:00
|
|
|
locdup, namedup, i) < 0)
|
1997-03-14 03:14:09 +03:00
|
|
|
return 1;
|
|
|
|
if (nv->nv_str &&
|
1998-10-16 18:27:17 +04:00
|
|
|
fprintf(fp, "#define %sCF_%s_DEFAULT %s\n",
|
|
|
|
locdup, namedup, nv->nv_str) < 0)
|
1997-03-14 03:14:09 +03:00
|
|
|
return 1;
|
|
|
|
free(namedup);
|
|
|
|
}
|
|
|
|
free(locdup);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build the "locators.h" file with manifest constants for all potential
|
|
|
|
* locators in the configuration. Do this by enumerating the attribute
|
|
|
|
* hash table and emitting all the locators for each attribute.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
emitlocs()
|
|
|
|
{
|
1998-01-12 10:37:40 +03:00
|
|
|
char *tfname;
|
1997-10-18 11:58:56 +04:00
|
|
|
int rval;
|
1998-01-12 10:37:40 +03:00
|
|
|
FILE *tfp;
|
1997-03-14 03:14:09 +03:00
|
|
|
|
|
|
|
tfname = "tmp_locators.h";
|
1998-10-16 18:27:17 +04:00
|
|
|
if ((tfp = fopen(tfname, "w")) == NULL)
|
|
|
|
return (herr("open", tfname, NULL));
|
1997-03-14 03:14:09 +03:00
|
|
|
|
|
|
|
rval = ht_enumerate(attrtab, locators_print, tfp);
|
|
|
|
if (fclose(tfp) == EOF)
|
1998-10-16 18:27:17 +04:00
|
|
|
return (herr("clos", tfname, NULL));
|
1998-01-12 10:37:40 +03:00
|
|
|
if (rval)
|
|
|
|
return (rval);
|
|
|
|
return (cmphdr(tfname, "locators.h"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build the "ioconf.h" file with extern declarations for all configured
|
|
|
|
* cfdrivers.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
emitioconfh()
|
|
|
|
{
|
|
|
|
const char *tfname;
|
|
|
|
FILE *tfp;
|
|
|
|
struct devbase *d;
|
|
|
|
|
|
|
|
tfname = "tmp_ioconf.h";
|
1998-10-16 18:27:17 +04:00
|
|
|
if ((tfp = fopen(tfname, "w")) == NULL)
|
|
|
|
return (herr("open", tfname, NULL));
|
1998-01-12 10:37:40 +03:00
|
|
|
|
|
|
|
for (d = allbases; d != NULL; d = d->d_next) {
|
|
|
|
if (!devbase_has_instances(d, WILD))
|
|
|
|
continue;
|
|
|
|
if (fprintf(tfp, "extern struct cfdriver %s_cd;\n",
|
1998-10-16 18:27:17 +04:00
|
|
|
d->d_name) < 0)
|
1998-01-12 10:37:40 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fclose(tfp) == EOF)
|
1998-10-16 18:27:17 +04:00
|
|
|
return (herr("clos", tfname, NULL));
|
1998-01-12 10:37:40 +03:00
|
|
|
|
|
|
|
return (cmphdr(tfname, "ioconf.h"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare two header files. If nfname doesn't exist, or is different from
|
|
|
|
* tfname, move tfname to nfname. Otherwise, delete tfname.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
cmphdr(tfname, nfname)
|
|
|
|
const char *tfname, *nfname;
|
|
|
|
{
|
|
|
|
char tbuf[BUFSIZ], nbuf[BUFSIZ];
|
|
|
|
FILE *tfp, *nfp;
|
1997-03-14 03:14:09 +03:00
|
|
|
|
|
|
|
if ((tfp = fopen(tfname, "r")) == NULL)
|
1998-10-16 18:27:17 +04:00
|
|
|
return (herr("open", tfname, NULL));
|
1997-03-14 03:14:09 +03:00
|
|
|
|
|
|
|
if ((nfp = fopen(nfname, "r")) == NULL)
|
|
|
|
goto moveit;
|
|
|
|
|
1998-01-12 10:37:40 +03:00
|
|
|
while (fgets(tbuf, sizeof(tbuf), tfp) != NULL) {
|
|
|
|
if (fgets(nbuf, sizeof(nbuf), nfp) == NULL) {
|
|
|
|
/*
|
|
|
|
* Old file has fewer lines.
|
|
|
|
*/
|
1997-03-14 03:14:09 +03:00
|
|
|
goto moveit;
|
1998-01-12 10:37:40 +03:00
|
|
|
}
|
|
|
|
if (strcmp(tbuf, nbuf) != 0)
|
1997-03-14 03:14:09 +03:00
|
|
|
goto moveit;
|
|
|
|
}
|
1998-01-12 10:37:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We've reached the end of the new file. Check to see if new file
|
|
|
|
* has fewer lines than old.
|
|
|
|
*/
|
|
|
|
if (fgets(nbuf, sizeof(nbuf), nfp) != NULL) {
|
|
|
|
/*
|
|
|
|
* New file has fewer lines.
|
|
|
|
*/
|
|
|
|
goto moveit;
|
|
|
|
}
|
|
|
|
|
1997-03-14 03:14:09 +03:00
|
|
|
(void) fclose(nfp);
|
|
|
|
(void) fclose(tfp);
|
|
|
|
if (remove(tfname) == -1)
|
1998-10-16 18:27:17 +04:00
|
|
|
return(herr("remov", tfname, NULL));
|
1997-03-14 03:14:09 +03:00
|
|
|
return (0);
|
|
|
|
|
1998-01-12 10:37:40 +03:00
|
|
|
moveit:
|
1997-03-14 03:14:09 +03:00
|
|
|
/*
|
|
|
|
* They're different, or the file doesn't exist.
|
|
|
|
*/
|
|
|
|
if (nfp)
|
|
|
|
(void) fclose(nfp);
|
|
|
|
if (tfp)
|
|
|
|
(void) fclose(tfp);
|
|
|
|
if (rename(tfname, nfname) == -1)
|
1998-10-16 18:27:17 +04:00
|
|
|
return (herr("renam", tfname, NULL));
|
1997-03-14 03:14:09 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
static int
|
1998-10-16 18:27:17 +04:00
|
|
|
herr(what, fname, fp)
|
1998-01-12 10:37:40 +03:00
|
|
|
const char *what, *fname;
|
1995-04-28 10:54:58 +04:00
|
|
|
FILE *fp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-10-16 18:27:17 +04:00
|
|
|
extern char *__progname;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-10-16 18:27:17 +04:00
|
|
|
(void)fprintf(stderr, "%s: error %sing %s: %s\n",
|
|
|
|
__progname, what, fname, strerror(errno));
|
1995-04-28 10:54:58 +04:00
|
|
|
if (fp)
|
|
|
|
(void)fclose(fp);
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
static char *
|
|
|
|
cntname(src)
|
1997-10-18 11:58:56 +04:00
|
|
|
const char *src;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
char *dst, c;
|
1995-04-28 10:54:58 +04:00
|
|
|
static char buf[100];
|
|
|
|
|
|
|
|
dst = buf;
|
|
|
|
*dst++ = 'N';
|
|
|
|
while ((c = *src++) != 0)
|
|
|
|
*dst++ = islower(c) ? toupper(c) : c;
|
|
|
|
*dst = 0;
|
|
|
|
return (buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|