Use stdbool more widely
We already use the C99 bool type from stdbool.h in a few places. However there are many other places we represent boolean values as plain ints. This patch changes that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>main
parent
79eebb23db
commit
17625371ee
16
checks.c
16
checks.c
|
@ -53,7 +53,7 @@ struct check {
|
||||||
void *data;
|
void *data;
|
||||||
bool warn, error;
|
bool warn, error;
|
||||||
enum checkstatus status;
|
enum checkstatus status;
|
||||||
int inprogress;
|
bool inprogress;
|
||||||
int num_prereqs;
|
int num_prereqs;
|
||||||
struct check **prereq;
|
struct check **prereq;
|
||||||
};
|
};
|
||||||
|
@ -141,9 +141,9 @@ static void check_nodes_props(struct check *c, struct node *dt, struct node *nod
|
||||||
check_nodes_props(c, dt, child);
|
check_nodes_props(c, dt, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int run_check(struct check *c, struct node *dt)
|
static bool run_check(struct check *c, struct node *dt)
|
||||||
{
|
{
|
||||||
int error = 0;
|
bool error = false;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
assert(!c->inprogress);
|
assert(!c->inprogress);
|
||||||
|
@ -151,11 +151,11 @@ static int run_check(struct check *c, struct node *dt)
|
||||||
if (c->status != UNCHECKED)
|
if (c->status != UNCHECKED)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
c->inprogress = 1;
|
c->inprogress = true;
|
||||||
|
|
||||||
for (i = 0; i < c->num_prereqs; i++) {
|
for (i = 0; i < c->num_prereqs; i++) {
|
||||||
struct check *prq = c->prereq[i];
|
struct check *prq = c->prereq[i];
|
||||||
error |= run_check(prq, dt);
|
error = error || run_check(prq, dt);
|
||||||
if (prq->status != PASSED) {
|
if (prq->status != PASSED) {
|
||||||
c->status = PREREQ;
|
c->status = PREREQ;
|
||||||
check_msg(c, "Failed prerequisite '%s'",
|
check_msg(c, "Failed prerequisite '%s'",
|
||||||
|
@ -177,9 +177,9 @@ static int run_check(struct check *c, struct node *dt)
|
||||||
TRACE(c, "\tCompleted, status %d", c->status);
|
TRACE(c, "\tCompleted, status %d", c->status);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
c->inprogress = 0;
|
c->inprogress = false;
|
||||||
if ((c->status != PASSED) && (c->error))
|
if ((c->status != PASSED) && (c->error))
|
||||||
error = 1;
|
error = true;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,7 +733,7 @@ void parse_checks_option(bool warn, bool error, const char *optarg)
|
||||||
die("Unrecognized check name \"%s\"\n", name);
|
die("Unrecognized check name \"%s\"\n", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_checks(int force, struct boot_info *bi)
|
void process_checks(bool force, struct boot_info *bi)
|
||||||
{
|
{
|
||||||
struct node *dt = bi->dt;
|
struct node *dt = bi->dt;
|
||||||
int i;
|
int i;
|
||||||
|
|
10
data.c
10
data.c
|
@ -250,20 +250,20 @@ struct data data_add_marker(struct data d, enum markertype type, char *ref)
|
||||||
return data_append_markers(d, m);
|
return data_append_markers(d, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
int data_is_one_string(struct data d)
|
bool data_is_one_string(struct data d)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int len = d.len;
|
int len = d.len;
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
for (i = 0; i < len-1; i++)
|
for (i = 0; i < len-1; i++)
|
||||||
if (d.val[i] == '\0')
|
if (d.val[i] == '\0')
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
if (d.val[len-1] != '\0')
|
if (d.val[len-1] != '\0')
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ static int dts_version = 1;
|
||||||
BEGIN(V1); \
|
BEGIN(V1); \
|
||||||
|
|
||||||
static void push_input_file(const char *filename);
|
static void push_input_file(const char *filename);
|
||||||
static int pop_input_file(void);
|
static bool pop_input_file(void);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
@ -238,13 +238,13 @@ static void push_input_file(const char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int pop_input_file(void)
|
static bool pop_input_file(void)
|
||||||
{
|
{
|
||||||
if (srcfile_pop() == 0)
|
if (srcfile_pop() == 0)
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
yypop_buffer_state();
|
yypop_buffer_state();
|
||||||
yyin = current_srcfile->f;
|
yyin = current_srcfile->f;
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ extern void print_error(char const *fmt, ...);
|
||||||
extern void yyerror(char const *s);
|
extern void yyerror(char const *s);
|
||||||
|
|
||||||
extern struct boot_info *the_boot_info;
|
extern struct boot_info *the_boot_info;
|
||||||
extern int treesource_error;
|
extern bool treesource_error;
|
||||||
|
|
||||||
static unsigned long long eval_literal(const char *s, int base, int bits);
|
static unsigned long long eval_literal(const char *s, int base, int bits);
|
||||||
static unsigned char eval_char_literal(const char *s);
|
static unsigned char eval_char_literal(const char *s);
|
||||||
|
@ -478,7 +478,7 @@ void print_error(char const *fmt, ...)
|
||||||
srcpos_verror(&yylloc, fmt, va);
|
srcpos_verror(&yylloc, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
treesource_error = 1;
|
treesource_error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void yyerror(char const *s) {
|
void yyerror(char const *s) {
|
||||||
|
|
6
dtc.c
6
dtc.c
|
@ -109,7 +109,7 @@ int main(int argc, char *argv[])
|
||||||
const char *outform = "dts";
|
const char *outform = "dts";
|
||||||
const char *outname = "-";
|
const char *outname = "-";
|
||||||
const char *depname = NULL;
|
const char *depname = NULL;
|
||||||
int force = 0, sort = 0;
|
bool force = false, sort = false;
|
||||||
const char *arg;
|
const char *arg;
|
||||||
int opt;
|
int opt;
|
||||||
FILE *outf = NULL;
|
FILE *outf = NULL;
|
||||||
|
@ -148,7 +148,7 @@ int main(int argc, char *argv[])
|
||||||
padsize = strtol(optarg, NULL, 0);
|
padsize = strtol(optarg, NULL, 0);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
force = 1;
|
force = true;
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
quiet++;
|
quiet++;
|
||||||
|
@ -174,7 +174,7 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
sort = 1;
|
sort = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'W':
|
case 'W':
|
||||||
|
|
10
dtc.h
10
dtc.h
|
@ -118,7 +118,7 @@ struct data data_append_align(struct data d, int align);
|
||||||
|
|
||||||
struct data data_add_marker(struct data d, enum markertype type, char *ref);
|
struct data data_add_marker(struct data d, enum markertype type, char *ref);
|
||||||
|
|
||||||
int data_is_one_string(struct data d);
|
bool data_is_one_string(struct data d);
|
||||||
|
|
||||||
/* DT constraints */
|
/* DT constraints */
|
||||||
|
|
||||||
|
@ -127,13 +127,13 @@ int data_is_one_string(struct data d);
|
||||||
|
|
||||||
/* Live trees */
|
/* Live trees */
|
||||||
struct label {
|
struct label {
|
||||||
int deleted;
|
bool deleted;
|
||||||
char *label;
|
char *label;
|
||||||
struct label *next;
|
struct label *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct property {
|
struct property {
|
||||||
int deleted;
|
bool deleted;
|
||||||
char *name;
|
char *name;
|
||||||
struct data val;
|
struct data val;
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ struct property {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct node {
|
struct node {
|
||||||
int deleted;
|
bool deleted;
|
||||||
char *name;
|
char *name;
|
||||||
struct property *proplist;
|
struct property *proplist;
|
||||||
struct node *children;
|
struct node *children;
|
||||||
|
@ -248,7 +248,7 @@ void sort_tree(struct boot_info *bi);
|
||||||
/* Checks */
|
/* Checks */
|
||||||
|
|
||||||
void parse_checks_option(bool warn, bool error, const char *optarg);
|
void parse_checks_option(bool warn, bool error, const char *optarg);
|
||||||
void process_checks(int force, struct boot_info *bi);
|
void process_checks(bool force, struct boot_info *bi);
|
||||||
|
|
||||||
/* Flattened trees */
|
/* Flattened trees */
|
||||||
|
|
||||||
|
|
|
@ -261,7 +261,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
|
||||||
{
|
{
|
||||||
struct property *prop;
|
struct property *prop;
|
||||||
struct node *child;
|
struct node *child;
|
||||||
int seen_name_prop = 0;
|
bool seen_name_prop = false;
|
||||||
|
|
||||||
if (tree->deleted)
|
if (tree->deleted)
|
||||||
return;
|
return;
|
||||||
|
@ -279,7 +279,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
|
||||||
int nameoff;
|
int nameoff;
|
||||||
|
|
||||||
if (streq(prop->name, "name"))
|
if (streq(prop->name, "name"))
|
||||||
seen_name_prop = 1;
|
seen_name_prop = true;
|
||||||
|
|
||||||
nameoff = stringtable_insert(strbuf, prop->name);
|
nameoff = stringtable_insert(strbuf, prop->name);
|
||||||
|
|
||||||
|
|
4
srcpos.c
4
srcpos.c
|
@ -159,7 +159,7 @@ void srcfile_push(const char *fname)
|
||||||
current_srcfile = srcfile;
|
current_srcfile = srcfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
int srcfile_pop(void)
|
bool srcfile_pop(void)
|
||||||
{
|
{
|
||||||
struct srcfile_state *srcfile = current_srcfile;
|
struct srcfile_state *srcfile = current_srcfile;
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ int srcfile_pop(void)
|
||||||
* fix this we could either allocate all the files from a
|
* fix this we could either allocate all the files from a
|
||||||
* table, or use a pool allocator. */
|
* table, or use a pool allocator. */
|
||||||
|
|
||||||
return current_srcfile ? 1 : 0;
|
return current_srcfile ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void srcfile_add_search_path(const char *dirname)
|
void srcfile_add_search_path(const char *dirname)
|
||||||
|
|
3
srcpos.h
3
srcpos.h
|
@ -21,6 +21,7 @@
|
||||||
#define _SRCPOS_H_
|
#define _SRCPOS_H_
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
struct srcfile_state {
|
struct srcfile_state {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
@ -55,7 +56,7 @@ extern struct srcfile_state *current_srcfile; /* = NULL */
|
||||||
FILE *srcfile_relative_open(const char *fname, char **fullnamep);
|
FILE *srcfile_relative_open(const char *fname, char **fullnamep);
|
||||||
|
|
||||||
void srcfile_push(const char *fname);
|
void srcfile_push(const char *fname);
|
||||||
int srcfile_pop(void);
|
bool srcfile_pop(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new directory to the search path for input files
|
* Add a new directory to the search path for input files
|
||||||
|
|
|
@ -26,12 +26,12 @@ extern int yyparse(void);
|
||||||
extern YYLTYPE yylloc;
|
extern YYLTYPE yylloc;
|
||||||
|
|
||||||
struct boot_info *the_boot_info;
|
struct boot_info *the_boot_info;
|
||||||
int treesource_error;
|
bool treesource_error;
|
||||||
|
|
||||||
struct boot_info *dt_from_source(const char *fname)
|
struct boot_info *dt_from_source(const char *fname)
|
||||||
{
|
{
|
||||||
the_boot_info = NULL;
|
the_boot_info = NULL;
|
||||||
treesource_error = 0;
|
treesource_error = false;
|
||||||
|
|
||||||
srcfile_push(fname);
|
srcfile_push(fname);
|
||||||
yyin = current_srcfile->f;
|
yyin = current_srcfile->f;
|
||||||
|
@ -54,7 +54,7 @@ static void write_prefix(FILE *f, int level)
|
||||||
fputc('\t', f);
|
fputc('\t', f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int isstring(char c)
|
static bool isstring(char c)
|
||||||
{
|
{
|
||||||
return (isprint(c)
|
return (isprint(c)
|
||||||
|| (c == '\0')
|
|| (c == '\0')
|
||||||
|
|
2
util.c
2
util.c
|
@ -70,7 +70,7 @@ char *join_path(const char *path, const char *name)
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
int util_is_printable_string(const void *data, int len)
|
bool util_is_printable_string(const void *data, int len)
|
||||||
{
|
{
|
||||||
const char *s = data;
|
const char *s = data;
|
||||||
const char *ss, *se;
|
const char *ss, *se;
|
||||||
|
|
3
util.h
3
util.h
|
@ -2,6 +2,7 @@
|
||||||
#define _UTIL_H
|
#define _UTIL_H
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -68,7 +69,7 @@ extern char *join_path(const char *path, const char *name);
|
||||||
* @param len The string length including terminator
|
* @param len The string length including terminator
|
||||||
* @return 1 if a valid printable string, 0 if not
|
* @return 1 if a valid printable string, 0 if not
|
||||||
*/
|
*/
|
||||||
int util_is_printable_string(const void *data, int len);
|
bool util_is_printable_string(const void *data, int len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse an escaped character starting at index i in string s. The resulting
|
* Parse an escaped character starting at index i in string s. The resulting
|
||||||
|
|
Loading…
Reference in New Issue