#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/types.h>
#include <sys/param.h>
#include <sys/queue.h>
#if !defined(MAKE_BOOTSTRAP) && defined(BSD)
#include <sys/cdefs.h>
#include <paths.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifndef __dead
#define __dead
#endif
#ifndef __printflike
#define __printflike(a, b)
#endif
#ifndef _PATH_DEVNULL
#define _PATH_DEVNULL "/dev/null"
#endif
#ifdef MAKE_BOOTSTRAP
#undef dev_t
#undef devmajor_t
#undef devminor_t
#undef NODEV
#undef NODEVMAJOR
#undef major
#undef minor
#undef makedev
#define dev_t unsigned int
#define NODEV ((dev_t)-1)
#define devmajor_t int
#define devminor_t int
#define NODEVMAJOR (-1)
#define major(x) ((devmajor_t)((((x) & 0x000fff00) >> 8)))
#define minor(x) ((devminor_t)((((x) & 0xfff00000) >> 12) | \
(((x) & 0x000000ff) >> 0)))
#define makedev(x,y) ((dev_t)((((dev_t)(x) << 8) & 0x000fff00U) | \
(((dev_t)(y) << 12) & 0xfff00000U) | \
(((dev_t)(y) << 0) & 0x000000ffU)))
#define __attribute__(x)
#endif
#undef setprogname
#undef getprogname
extern const char *progname;
#define setprogname(s) ((void)(progname = (s)))
#define getprogname() (progname)
#define ARRCHR '#'
#define CONFIG_VERSION 20240118
#define CONFIG_MINVERSION 0
struct where {
const char *w_srcfile;
u_short w_srcline;
};
struct nvlist {
struct nvlist *nv_next;
const char *nv_name;
const char *nv_str;
void *nv_ptr;
long long nv_num;
int nv_ifunit;
int nv_flags;
#define NV_DEPENDED 1
struct where nv_where;
};
struct config {
TAILQ_ENTRY(config) cf_next;
const char *cf_name;
const char *cf_fstype;
struct nvlist *cf_root;
struct nvlist *cf_dump;
struct where cf_where;
};
struct defoptlist {
struct defoptlist *dl_next;
const char *dl_name;
const char *dl_value;
const char *dl_lintvalue;
int dl_obsolete;
int dl_mkvar;
struct nvlist *dl_depends;
struct where dl_where;
};
struct files;
TAILQ_HEAD(filelist, files);
struct module {
const char *m_name;
#if 1
struct attrlist *m_deps;
#else
struct attrlist *m_attrs;
struct modulelist *m_deps;
#endif
int m_expanding;
struct filelist m_files;
int m_weight;
};
struct attr {
struct module a_m;
#define a_name a_m.m_name
#define a_deps a_m.m_deps
#define a_expanding a_m.m_expanding
#define a_files a_m.m_files
#define a_weight a_m.m_weight
uint8_t a_iattr;
uint8_t a_deselected;
struct loclist *a_locs;
int a_loclen;
struct nvlist *a_devs;
struct nvlist *a_refs;
const char *a_devclass;
struct where a_where;
size_t a_idx;
};
struct attrlist {
struct attrlist *al_next;
struct attr *al_this;
};
struct loclist {
const char *ll_name;
const char *ll_string;
long long ll_num;
struct loclist *ll_next;
};
struct pspec {
TAILQ_ENTRY(pspec) p_list;
struct attr *p_iattr;
struct devbase *p_atdev;
int p_atunit;
struct nvlist *p_devs;
int p_inst;
int p_active;
int p_ref;
};
struct devbase {
const char *d_name;
TAILQ_ENTRY(devbase) d_next;
int d_level;
struct devbase *d_levelparent;
int d_isdef;
int d_ispseudo;
devmajor_t d_major;
struct attrlist *d_attrs;
int d_umax;
struct devi *d_ihead;
struct devi **d_ipp;
struct deva *d_ahead;
struct deva **d_app;
struct attr *d_classattr;
struct where d_where;
};
struct deva {
const char *d_name;
TAILQ_ENTRY(deva) d_next;
struct deva *d_bsame;
int d_isdef;
int d_has_iattrs;
struct devbase *d_devbase;
struct nvlist *d_atlist;
struct attrlist *d_attrs;
struct devi *d_ihead;
struct devi **d_ipp;
struct where d_where;
};
struct devi {
const char *i_name;
int i_unit;
struct devbase *i_base;
TAILQ_ENTRY(devi) i_next;
struct devi *i_bsame;
struct devi *i_asame;
struct devi *i_alias;
const char *i_at;
struct pspec *i_pspec;
struct deva *i_atdeva;
const char **i_locs;
int i_cfflags;
int i_level;
int i_active;
#define DEVI_ORPHAN 0
#define DEVI_ACTIVE 1
#define DEVI_IGNORED 2
#define DEVI_BROKEN 3
int i_pseudoroot;
short i_collapsed;
u_short i_cfindex;
int i_locoff;
struct where i_where;
};
#define STAR (-1)
#define WILD (-2)
struct files {
TAILQ_ENTRY(files) fi_next;
TAILQ_ENTRY(files) fi_snext;
struct where fi_where;
u_char fi_flags;
const char *fi_tail;
const char *fi_base;
const char *fi_dir;
const char *fi_path;
const char *fi_prefix;
const char *fi_buildprefix;
int fi_suffix;
size_t fi_len;
struct condexpr *fi_optx;
struct nvlist *fi_optf;
const char *fi_mkrule;
struct attr *fi_attr;
int fi_order;
TAILQ_ENTRY(files) fi_anext;
};
#define FI_SEL 0x01
#define FI_NEEDSCOUNT 0x02
#define FI_NEEDSFLAG 0x04
#define FI_HIDDEN 0x08
extern size_t nselfiles;
extern struct files **selfiles;
enum condexpr_types {
CX_ATOM,
CX_NOT,
CX_AND,
CX_OR,
};
struct condexpr {
enum condexpr_types cx_type;
union {
const char *atom;
struct condexpr *not;
struct {
struct condexpr *left;
struct condexpr *right;
} and, or;
} cx_u;
};
#define cx_atom cx_u.atom
#define cx_not cx_u.not
#define cx_and cx_u.and
#define cx_or cx_u.or
struct prefix;
SLIST_HEAD(prefixlist, prefix);
struct prefix {
SLIST_ENTRY(prefix) pf_next;
const char *pf_prefix;
};
struct devm {
TAILQ_ENTRY(devm) dm_next;
const char *dm_name;
devmajor_t dm_cmajor;
devmajor_t dm_bmajor;
struct condexpr *dm_opts;
struct nvlist *dm_devnodes;
struct where dm_where;
};
struct hashtab;
extern int lkmmode;
extern const char *conffile;
extern const char *machine;
extern const char *machinearch;
extern struct nvlist *machinesubarches;
extern const char *ioconfname;
extern const char *srcdir;
extern const char *builddir;
extern const char *defbuilddir;
extern const char *ident;
extern int errors;
extern int minmaxusers;
extern int defmaxusers;
extern int maxmaxusers;
extern int maxusers;
extern int maxpartitions;
extern int version;
extern struct nvlist *options;
extern struct nvlist *fsoptions;
extern struct nvlist *mkoptions;
extern struct nvlist *appmkoptions;
extern struct nvlist *condmkoptions;
extern struct hashtab *devbasetab;
extern struct hashtab *devroottab;
extern struct hashtab *devatab;
extern struct hashtab *devitab;
extern struct hashtab *deaddevitab;
extern struct hashtab *selecttab;
extern struct hashtab *needcnttab;
extern struct hashtab *opttab;
extern struct hashtab *fsopttab;
extern struct dlhash *defopttab;
extern struct dlhash *defflagtab;
extern struct dlhash *defparamtab;
extern struct dlhash *defoptlint;
extern struct nvhash *deffstab;
extern struct dlhash *optfiletab;
extern struct hashtab *attrtab;
extern struct hashtab *attrdeptab;
extern struct hashtab *bdevmtab;
extern struct hashtab *cdevmtab;
TAILQ_HEAD(devbasetq, devbase);
TAILQ_HEAD(devatq, deva);
TAILQ_HEAD(conftq, config);
TAILQ_HEAD(devitq, devi);
TAILQ_HEAD(devmtq, devm);
TAILQ_HEAD(pspectq, pspec);
extern struct devbasetq allbases;
extern struct devatq alldevas;
extern struct conftq allcf;
extern struct devitq alldevi,
allpseudo;
extern struct devmtq alldevms;
extern struct pspectq allpspecs;
extern int ndevi;
extern int npspecs;
extern devmajor_t maxbdevm;
extern devmajor_t maxcdevm;
extern int do_devsw;
extern int oktopackage;
extern int devilevel;
extern struct filelist allfiles;
extern struct filelist allcfiles;
extern struct filelist allsfiles;
extern struct filelist allofiles;
extern struct prefixlist prefixes,
allprefixes;
extern struct prefixlist buildprefixes,
allbuildprefixes;
extern struct attr allattr;
extern struct devi **packed;
extern size_t npacked;
extern struct locators {
const char **vec;
int used;
} locators;
struct numconst {
int64_t val;
int fmt;
};
void initfiles(void);
void checkfiles(void);
int fixfiles(void);
int fixdevsw(void);
void addfile(const char *, struct condexpr *, u_char, const char *);
int expr_eval(struct condexpr *, int (*)(const char *, void *), void *);
struct hashtab *ht_new(void);
void ht_free(struct hashtab *);
int ht_insrep2(struct hashtab *, const char *, const char *, void *, int);
int ht_insrep(struct hashtab *, const char *, void *, int);
#define ht_insert2(ht, nam1, nam2, val) ht_insrep2(ht, nam1, nam2, val, 0)
#define ht_insert(ht, nam, val) ht_insrep(ht, nam, val, 0)
#define ht_replace(ht, nam, val) ht_insrep(ht, nam, val, 1)
int ht_remove2(struct hashtab *, const char *, const char *);
int ht_remove(struct hashtab *, const char *);
void *ht_lookup2(struct hashtab *, const char *, const char *);
void *ht_lookup(struct hashtab *, const char *);
void initintern(void);
const char *intern(const char *);
typedef int (*ht_callback2)(const char *, const char *, void *, void *);
typedef int (*ht_callback)(const char *, void *, void *);
int ht_enumerate2(struct hashtab *, ht_callback2, void *);
int ht_enumerate(struct hashtab *, ht_callback, void *);
#define DECLHASH(HT, VT) \
struct HT; \
struct HT *HT##_create(void); \
int HT##_insert(struct HT *, const char *, struct VT *); \
int HT##_replace(struct HT *, const char *, struct VT *); \
int HT##_remove(struct HT *, const char *); \
struct VT *HT##_lookup(struct HT *, const char *); \
int HT##_enumerate(struct HT *, \
int (*)(const char *, struct VT *, void *), \
void *)
DECLHASH(nvhash, nvlist);
DECLHASH(dlhash, defoptlist);
void emit_instances(void);
void emit_options(void);
void emit_params(void);
extern int Mflag;
extern int Sflag;
void addoption(const char *, const char *);
void addfsoption(const char *);
void addmkoption(const char *, const char *);
void appendmkoption(const char *, const char *);
void appendcondmkoption(struct condexpr *, const char *, const char *);
void deffilesystem(struct nvlist *, struct nvlist *);
void defoption(const char *, struct defoptlist *, struct nvlist *);
void defflag(const char *, struct defoptlist *, struct nvlist *, int);
void defparam(const char *, struct defoptlist *, struct nvlist *, int);
void deloption(const char *, int);
void delfsoption(const char *, int);
void delmkoption(const char *, int);
int devbase_has_instances(struct devbase *, int);
struct where *find_declared_option(const char *);
struct defoptlist *find_declared_option_option(const char *name);
int deva_has_instances(struct deva *, int);
void setupdirs(void);
void fixmaxusers(void);
void fixmkoption(void);
void mkflagvar(struct defoptlist *);
const char *strtolower(const char *);
#define OPT_FSOPT(n) (nvhash_lookup(deffstab, (n)) != NULL)
#define OPT_DEFOPT(n) (dlhash_lookup(defopttab, (n)) != NULL)
#define OPT_DEFFLAG(n) (dlhash_lookup(defflagtab, (n)) != NULL)
#define OPT_DEFPARAM(n) (dlhash_lookup(defparamtab, (n)) != NULL)
#define OPT_OBSOLETE(n) (dlhash_lookup(obsopttab, (n)) != NULL)
#define DEFINED_OPTION(n) (find_declared_option((n)))
void logconfig_include(FILE *, const char *);
int mkdevsw(void);
int mkheaders(void);
int moveifchanged(const char *, const char *);
int emitlocs(void);
int emitioconfh(void);
int mkioconf(void);
int mkmakefile(void);
int mkswap(void);
void pack(void);
u_short currentline(void);
int firstfile(const char *);
void package(const char *);
int include(const char *, int, int, int);
extern int includedepth;
void initsem(void);
int onlist(struct nvlist *, void *);
void prefix_push(const char *);
void prefix_pop(void);
void buildprefix_push(const char *);
void buildprefix_pop(void);
char *sourcepath(const char *);
extern int dflag;
#define CFGDBG(n, ...) \
do { if ((dflag) >= (n)) cfgdbg(__VA_ARGS__); } while (0)
void cfgdbg(const char *, ...)
__printflike(1, 2);
void cfgwarn(const char *, ...)
__printflike(1, 2);
void cfgxwarn(const char *, int, const char *, ...)
__printflike(3, 4);
void cfgerror(const char *, ...)
__printflike(1, 2);
void cfgxerror(const char *, int, const char *, ...)
__printflike(3, 4);
__dead void panic(const char *, ...)
__printflike(1, 2);
struct nvlist *newnv(const char *, const char *, void *, long long, struct nvlist *);
void nvfree(struct nvlist *);
void nvfreel(struct nvlist *);
struct nvlist *nvcat(struct nvlist *, struct nvlist *);
void autogen_comment(FILE *, const char *);
struct defoptlist *defoptlist_create(const char *, const char *, const char *);
void defoptlist_destroy(struct defoptlist *);
struct defoptlist *defoptlist_append(struct defoptlist *, struct defoptlist *);
struct attrlist *attrlist_create(void);
struct attrlist *attrlist_cons(struct attrlist *, struct attr *);
void attrlist_destroy(struct attrlist *);
void attrlist_destroyall(struct attrlist *);
struct loclist *loclist_create(const char *, const char *, long long);
void loclist_destroy(struct loclist *);
struct condexpr *condexpr_create(enum condexpr_types);
void condexpr_destroy(struct condexpr *);
void yyerror(const char *);
int yylex(void);