config: make changes to allow some parts to build as C++
Highlights: - Avoid keywords (this, not) as variable names - Move yyparse into config.h with other declarations - All declarations in config.h are assumed guilty until proven innocent - Some const-correctness - Casting malloc/calloc returns Note that we're not building any C++ here yet, this will be introduced in other commits to replace some of the lib dependencies. Reducing the number of FreeBSD-specific dependencies we have reduces some friction for building our bootstrap tools independently in other environments. Reviewed by: imp Sponsored by: Klara, Inc. Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D38274
This commit is contained in:
@@ -35,12 +35,15 @@
|
|||||||
/*
|
/*
|
||||||
* Config.
|
* Config.
|
||||||
*/
|
*/
|
||||||
|
#include <sys/cdefs.h> /* __BEGIN_DECLS/__END_DECLS */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
struct cfgfile {
|
struct cfgfile {
|
||||||
STAILQ_ENTRY(cfgfile) cfg_next;
|
STAILQ_ENTRY(cfgfile) cfg_next;
|
||||||
char *cfg_path;
|
char *cfg_path;
|
||||||
@@ -190,6 +193,7 @@ char *raisestr(char *);
|
|||||||
void remember(const char *);
|
void remember(const char *);
|
||||||
void moveifchanged(const char *, const char *);
|
void moveifchanged(const char *, const char *);
|
||||||
int yylex(void);
|
int yylex(void);
|
||||||
|
int yyparse(void);
|
||||||
void options(void);
|
void options(void);
|
||||||
void makefile(void);
|
void makefile(void);
|
||||||
void makeenv(void);
|
void makeenv(void);
|
||||||
@@ -218,5 +222,7 @@ extern int versreq;
|
|||||||
extern char *PREFIX; /* Config file name - for error messages */
|
extern char *PREFIX; /* Config file name - for error messages */
|
||||||
extern char srcdir[]; /* root of the kernel source tree */
|
extern char srcdir[]; /* root of the kernel source tree */
|
||||||
|
|
||||||
|
__END_DECLS;
|
||||||
|
|
||||||
#define eq(a,b) (!strcmp(a,b))
|
#define eq(a,b) (!strcmp(a,b))
|
||||||
#define ns(s) strdup(s)
|
#define ns(s) strdup(s)
|
||||||
|
|||||||
+10
-9
@@ -105,10 +105,9 @@ static void cleanheaders(char *);
|
|||||||
static void kernconfdump(const char *);
|
static void kernconfdump(const char *);
|
||||||
static void badversion(void);
|
static void badversion(void);
|
||||||
static void checkversion(void);
|
static void checkversion(void);
|
||||||
extern int yyparse(void);
|
|
||||||
|
|
||||||
struct hdr_list {
|
struct hdr_list {
|
||||||
char *h_name;
|
const char *h_name;
|
||||||
struct hdr_list *h_next;
|
struct hdr_list *h_next;
|
||||||
} *htab;
|
} *htab;
|
||||||
|
|
||||||
@@ -620,10 +619,12 @@ moveifchanged(const char *from_name, const char *to_name)
|
|||||||
tsize = (size_t)from_sb.st_size;
|
tsize = (size_t)from_sb.st_size;
|
||||||
|
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
p = mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0);
|
p = (char *)mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd,
|
||||||
|
(off_t)0);
|
||||||
if (p == MAP_FAILED)
|
if (p == MAP_FAILED)
|
||||||
err(EX_OSERR, "mmap %s", from_name);
|
err(EX_OSERR, "mmap %s", from_name);
|
||||||
q = mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, (off_t)0);
|
q = (char *)mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd,
|
||||||
|
(off_t)0);
|
||||||
if (q == MAP_FAILED)
|
if (q == MAP_FAILED)
|
||||||
err(EX_OSERR, "mmap %s", to_name);
|
err(EX_OSERR, "mmap %s", to_name);
|
||||||
|
|
||||||
@@ -688,7 +689,7 @@ cleanheaders(char *p)
|
|||||||
void
|
void
|
||||||
remember(const char *file)
|
remember(const char *file)
|
||||||
{
|
{
|
||||||
char *s;
|
const char *s;
|
||||||
struct hdr_list *hl;
|
struct hdr_list *hl;
|
||||||
|
|
||||||
if ((s = strrchr(file, '/')) != NULL)
|
if ((s = strrchr(file, '/')) != NULL)
|
||||||
@@ -697,16 +698,16 @@ remember(const char *file)
|
|||||||
s = ns(file);
|
s = ns(file);
|
||||||
|
|
||||||
if (strchr(s, '_') && strncmp(s, "opt_", 4) != 0) {
|
if (strchr(s, '_') && strncmp(s, "opt_", 4) != 0) {
|
||||||
free(s);
|
free(__DECONST(char *, s));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (hl = htab; hl != NULL; hl = hl->h_next) {
|
for (hl = htab; hl != NULL; hl = hl->h_next) {
|
||||||
if (eq(s, hl->h_name)) {
|
if (eq(s, hl->h_name)) {
|
||||||
free(s);
|
free(__DECONST(char *, s));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hl = calloc(1, sizeof(*hl));
|
hl = (struct hdr_list *)calloc(1, sizeof(*hl));
|
||||||
if (hl == NULL)
|
if (hl == NULL)
|
||||||
err(EXIT_FAILURE, "calloc");
|
err(EXIT_FAILURE, "calloc");
|
||||||
hl->h_name = s;
|
hl->h_name = s;
|
||||||
@@ -740,7 +741,7 @@ kernconfdump(const char *file)
|
|||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
err(EXIT_FAILURE, "fdopen() failed");
|
err(EXIT_FAILURE, "fdopen() failed");
|
||||||
osz = 1024;
|
osz = 1024;
|
||||||
o = calloc(1, osz);
|
o = (char *)calloc(1, osz);
|
||||||
if (o == NULL)
|
if (o == NULL)
|
||||||
err(EXIT_FAILURE, "Couldn't allocate memory");
|
err(EXIT_FAILURE, "Couldn't allocate memory");
|
||||||
/* ELF note section header. */
|
/* ELF note section header. */
|
||||||
|
|||||||
@@ -392,9 +392,9 @@ read_file(char *fname)
|
|||||||
struct file_list *tp;
|
struct file_list *tp;
|
||||||
struct device *dp;
|
struct device *dp;
|
||||||
struct opt *op;
|
struct opt *op;
|
||||||
char *wd, *this, *compilewith, *depends, *clean, *warning;
|
char *wd, *rfile, *compilewith, *depends, *clean, *warning;
|
||||||
const char *objprefix;
|
const char *objprefix;
|
||||||
int compile, match, nreqs, std, filetype, not,
|
int compile, match, nreqs, std, filetype, negate,
|
||||||
imp_rule, no_ctfconvert, no_obj, before_depend, nowerror;
|
imp_rule, no_ctfconvert, no_obj, before_depend, nowerror;
|
||||||
|
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
@@ -434,13 +434,13 @@ read_file(char *fname)
|
|||||||
;
|
;
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
this = ns(wd);
|
rfile = ns(wd);
|
||||||
wd = get_word(fp);
|
wd = get_word(fp);
|
||||||
if (wd == (char *)EOF)
|
if (wd == (char *)EOF)
|
||||||
return;
|
return;
|
||||||
if (wd == NULL)
|
if (wd == NULL)
|
||||||
errout("%s: No type for %s.\n", fname, this);
|
errout("%s: No type for %s.\n", fname, rfile);
|
||||||
tp = fl_lookup(this);
|
tp = fl_lookup(rfile);
|
||||||
compile = 0;
|
compile = 0;
|
||||||
match = 1;
|
match = 1;
|
||||||
nreqs = 0;
|
nreqs = 0;
|
||||||
@@ -454,25 +454,25 @@ read_file(char *fname)
|
|||||||
no_obj = 0;
|
no_obj = 0;
|
||||||
before_depend = 0;
|
before_depend = 0;
|
||||||
nowerror = 0;
|
nowerror = 0;
|
||||||
not = 0;
|
negate = 0;
|
||||||
filetype = NORMAL;
|
filetype = NORMAL;
|
||||||
objprefix = "";
|
objprefix = "";
|
||||||
if (eq(wd, "standard"))
|
if (eq(wd, "standard"))
|
||||||
std = 1;
|
std = 1;
|
||||||
else if (!eq(wd, "optional"))
|
else if (!eq(wd, "optional"))
|
||||||
errout("%s: \"%s\" %s must be optional or standard\n",
|
errout("%s: \"%s\" %s must be optional or standard\n",
|
||||||
fname, wd, this);
|
fname, wd, rfile);
|
||||||
for (wd = get_word(fp); wd; wd = get_word(fp)) {
|
for (wd = get_word(fp); wd; wd = get_word(fp)) {
|
||||||
if (wd == (char *)EOF)
|
if (wd == (char *)EOF)
|
||||||
return;
|
return;
|
||||||
if (eq(wd, "!")) {
|
if (eq(wd, "!")) {
|
||||||
not = 1;
|
negate = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (eq(wd, "|")) {
|
if (eq(wd, "|")) {
|
||||||
if (nreqs == 0)
|
if (nreqs == 0)
|
||||||
errout("%s: syntax error describing %s\n",
|
errout("%s: syntax error describing %s\n",
|
||||||
fname, this);
|
fname, rfile);
|
||||||
compile += match;
|
compile += match;
|
||||||
match = 1;
|
match = 1;
|
||||||
nreqs = 0;
|
nreqs = 0;
|
||||||
@@ -491,7 +491,7 @@ read_file(char *fname)
|
|||||||
errout("%s: alternate rule required when "
|
errout("%s: alternate rule required when "
|
||||||
"\"no-implicit-rule\" is specified for"
|
"\"no-implicit-rule\" is specified for"
|
||||||
" %s.\n",
|
" %s.\n",
|
||||||
fname, this);
|
fname, rfile);
|
||||||
imp_rule++;
|
imp_rule++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -503,7 +503,7 @@ read_file(char *fname)
|
|||||||
wd = get_quoted_word(fp);
|
wd = get_quoted_word(fp);
|
||||||
if (wd == (char *)EOF || wd == NULL)
|
if (wd == (char *)EOF || wd == NULL)
|
||||||
errout("%s: %s missing dependency string.\n",
|
errout("%s: %s missing dependency string.\n",
|
||||||
fname, this);
|
fname, rfile);
|
||||||
depends = ns(wd);
|
depends = ns(wd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -511,7 +511,7 @@ read_file(char *fname)
|
|||||||
wd = get_quoted_word(fp);
|
wd = get_quoted_word(fp);
|
||||||
if (wd == (char *)EOF || wd == NULL)
|
if (wd == (char *)EOF || wd == NULL)
|
||||||
errout("%s: %s missing clean file list.\n",
|
errout("%s: %s missing clean file list.\n",
|
||||||
fname, this);
|
fname, rfile);
|
||||||
clean = ns(wd);
|
clean = ns(wd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -519,7 +519,7 @@ read_file(char *fname)
|
|||||||
wd = get_quoted_word(fp);
|
wd = get_quoted_word(fp);
|
||||||
if (wd == (char *)EOF || wd == NULL)
|
if (wd == (char *)EOF || wd == NULL)
|
||||||
errout("%s: %s missing compile command string.\n",
|
errout("%s: %s missing compile command string.\n",
|
||||||
fname, this);
|
fname, rfile);
|
||||||
compilewith = ns(wd);
|
compilewith = ns(wd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -527,7 +527,7 @@ read_file(char *fname)
|
|||||||
wd = get_quoted_word(fp);
|
wd = get_quoted_word(fp);
|
||||||
if (wd == (char *)EOF || wd == NULL)
|
if (wd == (char *)EOF || wd == NULL)
|
||||||
errout("%s: %s missing warning text string.\n",
|
errout("%s: %s missing warning text string.\n",
|
||||||
fname, this);
|
fname, rfile);
|
||||||
warning = ns(wd);
|
warning = ns(wd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -535,7 +535,7 @@ read_file(char *fname)
|
|||||||
wd = get_quoted_word(fp);
|
wd = get_quoted_word(fp);
|
||||||
if (wd == (char *)EOF || wd == NULL)
|
if (wd == (char *)EOF || wd == NULL)
|
||||||
errout("%s: %s missing object prefix string.\n",
|
errout("%s: %s missing object prefix string.\n",
|
||||||
fname, this);
|
fname, rfile);
|
||||||
objprefix = ns(wd);
|
objprefix = ns(wd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -554,10 +554,10 @@ read_file(char *fname)
|
|||||||
nreqs++;
|
nreqs++;
|
||||||
if (std)
|
if (std)
|
||||||
errout("standard entry %s has optional inclusion specifier %s!\n",
|
errout("standard entry %s has optional inclusion specifier %s!\n",
|
||||||
this, wd);
|
rfile, wd);
|
||||||
STAILQ_FOREACH(dp, &dtab, d_next)
|
STAILQ_FOREACH(dp, &dtab, d_next)
|
||||||
if (eq(dp->d_name, wd)) {
|
if (eq(dp->d_name, wd)) {
|
||||||
if (not)
|
if (negate)
|
||||||
match = 0;
|
match = 0;
|
||||||
else
|
else
|
||||||
dp->d_done |= DEVDONE;
|
dp->d_done |= DEVDONE;
|
||||||
@@ -566,21 +566,21 @@ read_file(char *fname)
|
|||||||
SLIST_FOREACH(op, &opt, op_next)
|
SLIST_FOREACH(op, &opt, op_next)
|
||||||
if (op->op_value == 0 &&
|
if (op->op_value == 0 &&
|
||||||
strcasecmp(op->op_name, wd) == 0) {
|
strcasecmp(op->op_name, wd) == 0) {
|
||||||
if (not)
|
if (negate)
|
||||||
match = 0;
|
match = 0;
|
||||||
goto nextparam;
|
goto nextparam;
|
||||||
}
|
}
|
||||||
match &= not;
|
match &= negate;
|
||||||
nextparam:;
|
nextparam:;
|
||||||
not = 0;
|
negate = 0;
|
||||||
}
|
}
|
||||||
compile += match;
|
compile += match;
|
||||||
if (compile && tp == NULL) {
|
if (compile && tp == NULL) {
|
||||||
if (std == 0 && nreqs == 0)
|
if (std == 0 && nreqs == 0)
|
||||||
errout("%s: what is %s optional on?\n",
|
errout("%s: what is %s optional on?\n",
|
||||||
fname, this);
|
fname, rfile);
|
||||||
tp = new_fent();
|
tp = new_fent();
|
||||||
tp->f_fn = this;
|
tp->f_fn = rfile;
|
||||||
tp->f_type = filetype;
|
tp->f_type = filetype;
|
||||||
if (filetype == LOCAL)
|
if (filetype == LOCAL)
|
||||||
tp->f_srcprefix = "";
|
tp->f_srcprefix = "";
|
||||||
|
|||||||
+14
-14
@@ -312,41 +312,41 @@ tooption(char *name)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_duplicate(const char *fname, const char *this)
|
check_duplicate(const char *fname, const char *chkopt)
|
||||||
{
|
{
|
||||||
struct opt_list *po;
|
struct opt_list *po;
|
||||||
|
|
||||||
SLIST_FOREACH(po, &otab, o_next) {
|
SLIST_FOREACH(po, &otab, o_next) {
|
||||||
if (eq(po->o_name, this)) {
|
if (eq(po->o_name, chkopt)) {
|
||||||
fprintf(stderr, "%s: Duplicate option %s.\n",
|
fprintf(stderr, "%s: Duplicate option %s.\n",
|
||||||
fname, this);
|
fname, chkopt);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
insert_option(const char *fname, char *this, char *val)
|
insert_option(const char *fname, char *optname, char *val)
|
||||||
{
|
{
|
||||||
struct opt_list *po;
|
struct opt_list *po;
|
||||||
|
|
||||||
check_duplicate(fname, this);
|
check_duplicate(fname, optname);
|
||||||
po = (struct opt_list *) calloc(1, sizeof *po);
|
po = (struct opt_list *) calloc(1, sizeof *po);
|
||||||
if (po == NULL)
|
if (po == NULL)
|
||||||
err(EXIT_FAILURE, "calloc");
|
err(EXIT_FAILURE, "calloc");
|
||||||
po->o_name = this;
|
po->o_name = optname;
|
||||||
po->o_file = val;
|
po->o_file = val;
|
||||||
po->o_flags = 0;
|
po->o_flags = 0;
|
||||||
SLIST_INSERT_HEAD(&otab, po, o_next);
|
SLIST_INSERT_HEAD(&otab, po, o_next);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_option(const char *this, char *val, int flags)
|
update_option(const char *optname, char *val, int flags)
|
||||||
{
|
{
|
||||||
struct opt_list *po;
|
struct opt_list *po;
|
||||||
|
|
||||||
SLIST_FOREACH(po, &otab, o_next) {
|
SLIST_FOREACH(po, &otab, o_next) {
|
||||||
if (eq(po->o_name, this)) {
|
if (eq(po->o_name, optname)) {
|
||||||
free(po->o_file);
|
free(po->o_file);
|
||||||
po->o_file = val;
|
po->o_file = val;
|
||||||
po->o_flags = flags;
|
po->o_flags = flags;
|
||||||
@@ -364,7 +364,7 @@ static int
|
|||||||
read_option_file(const char *fname, int flags)
|
read_option_file(const char *fname, int flags)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *wd, *this, *val;
|
char *wd, *optname, *val;
|
||||||
char genopt[MAXPATHLEN];
|
char genopt[MAXPATHLEN];
|
||||||
|
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
@@ -378,17 +378,17 @@ read_option_file(const char *fname, int flags)
|
|||||||
continue;
|
continue;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this = ns(wd);
|
optname = ns(wd);
|
||||||
val = get_word(fp);
|
val = get_word(fp);
|
||||||
if (val == (char *)EOF)
|
if (val == (char *)EOF)
|
||||||
return (1);
|
return (1);
|
||||||
if (val == NULL) {
|
if (val == NULL) {
|
||||||
if (flags) {
|
if (flags) {
|
||||||
fprintf(stderr, "%s: compat file requires two"
|
fprintf(stderr, "%s: compat file requires two"
|
||||||
" words per line at %s\n", fname, this);
|
" words per line at %s\n", fname, optname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
char *s = ns(this);
|
char *s = ns(optname);
|
||||||
(void)snprintf(genopt, sizeof(genopt), "opt_%s.h",
|
(void)snprintf(genopt, sizeof(genopt), "opt_%s.h",
|
||||||
lower(s));
|
lower(s));
|
||||||
val = genopt;
|
val = genopt;
|
||||||
@@ -396,9 +396,9 @@ read_option_file(const char *fname, int flags)
|
|||||||
}
|
}
|
||||||
val = ns(val);
|
val = ns(val);
|
||||||
if (flags == 0)
|
if (flags == 0)
|
||||||
insert_option(fname, this, val);
|
insert_option(fname, optname, val);
|
||||||
else
|
else
|
||||||
update_option(this, val, flags);
|
update_option(optname, val, flags);
|
||||||
}
|
}
|
||||||
(void)fclose(fp);
|
(void)fclose(fp);
|
||||||
return (1);
|
return (1);
|
||||||
|
|||||||
Reference in New Issue
Block a user