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>
This commit is contained in:
parent
79eebb23db
commit
17625371ee
12 changed files with 39 additions and 37 deletions
16
checks.c
16
checks.c
|
@ -53,7 +53,7 @@ struct check {
|
|||
void *data;
|
||||
bool warn, error;
|
||||
enum checkstatus status;
|
||||
int inprogress;
|
||||
bool inprogress;
|
||||
int num_prereqs;
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
assert(!c->inprogress);
|
||||
|
@ -151,11 +151,11 @@ static int run_check(struct check *c, struct node *dt)
|
|||
if (c->status != UNCHECKED)
|
||||
goto out;
|
||||
|
||||
c->inprogress = 1;
|
||||
c->inprogress = true;
|
||||
|
||||
for (i = 0; i < c->num_prereqs; i++) {
|
||||
struct check *prq = c->prereq[i];
|
||||
error |= run_check(prq, dt);
|
||||
error = error || run_check(prq, dt);
|
||||
if (prq->status != PASSED) {
|
||||
c->status = PREREQ;
|
||||
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);
|
||||
|
||||
out:
|
||||
c->inprogress = 0;
|
||||
c->inprogress = false;
|
||||
if ((c->status != PASSED) && (c->error))
|
||||
error = 1;
|
||||
error = true;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -733,7 +733,7 @@ void parse_checks_option(bool warn, bool error, const char *optarg)
|
|||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
int data_is_one_string(struct data d)
|
||||
bool data_is_one_string(struct data d)
|
||||
{
|
||||
int i;
|
||||
int len = d.len;
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
for (i = 0; i < len-1; i++)
|
||||
if (d.val[i] == '\0')
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
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); \
|
||||
|
||||
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)
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
yypop_buffer_state();
|
||||
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 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 char eval_char_literal(const char *s);
|
||||
|
@ -478,7 +478,7 @@ void print_error(char const *fmt, ...)
|
|||
srcpos_verror(&yylloc, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
treesource_error = 1;
|
||||
treesource_error = true;
|
||||
}
|
||||
|
||||
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 *outname = "-";
|
||||
const char *depname = NULL;
|
||||
int force = 0, sort = 0;
|
||||
bool force = false, sort = false;
|
||||
const char *arg;
|
||||
int opt;
|
||||
FILE *outf = NULL;
|
||||
|
@ -148,7 +148,7 @@ int main(int argc, char *argv[])
|
|||
padsize = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 'f':
|
||||
force = 1;
|
||||
force = true;
|
||||
break;
|
||||
case 'q':
|
||||
quiet++;
|
||||
|
@ -174,7 +174,7 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 's':
|
||||
sort = 1;
|
||||
sort = true;
|
||||
break;
|
||||
|
||||
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);
|
||||
|
||||
int data_is_one_string(struct data d);
|
||||
bool data_is_one_string(struct data d);
|
||||
|
||||
/* DT constraints */
|
||||
|
||||
|
@ -127,13 +127,13 @@ int data_is_one_string(struct data d);
|
|||
|
||||
/* Live trees */
|
||||
struct label {
|
||||
int deleted;
|
||||
bool deleted;
|
||||
char *label;
|
||||
struct label *next;
|
||||
};
|
||||
|
||||
struct property {
|
||||
int deleted;
|
||||
bool deleted;
|
||||
char *name;
|
||||
struct data val;
|
||||
|
||||
|
@ -143,7 +143,7 @@ struct property {
|
|||
};
|
||||
|
||||
struct node {
|
||||
int deleted;
|
||||
bool deleted;
|
||||
char *name;
|
||||
struct property *proplist;
|
||||
struct node *children;
|
||||
|
@ -248,7 +248,7 @@ void sort_tree(struct boot_info *bi);
|
|||
/* Checks */
|
||||
|
||||
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 */
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
|
|||
{
|
||||
struct property *prop;
|
||||
struct node *child;
|
||||
int seen_name_prop = 0;
|
||||
bool seen_name_prop = false;
|
||||
|
||||
if (tree->deleted)
|
||||
return;
|
||||
|
@ -279,7 +279,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
|
|||
int nameoff;
|
||||
|
||||
if (streq(prop->name, "name"))
|
||||
seen_name_prop = 1;
|
||||
seen_name_prop = true;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int srcfile_pop(void)
|
||||
bool srcfile_pop(void)
|
||||
{
|
||||
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
|
||||
* table, or use a pool allocator. */
|
||||
|
||||
return current_srcfile ? 1 : 0;
|
||||
return current_srcfile ? true : false;
|
||||
}
|
||||
|
||||
void srcfile_add_search_path(const char *dirname)
|
||||
|
|
3
srcpos.h
3
srcpos.h
|
@ -21,6 +21,7 @@
|
|||
#define _SRCPOS_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct srcfile_state {
|
||||
FILE *f;
|
||||
|
@ -55,7 +56,7 @@ extern struct srcfile_state *current_srcfile; /* = NULL */
|
|||
FILE *srcfile_relative_open(const char *fname, char **fullnamep);
|
||||
|
||||
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
|
||||
|
|
|
@ -26,12 +26,12 @@ extern int yyparse(void);
|
|||
extern YYLTYPE yylloc;
|
||||
|
||||
struct boot_info *the_boot_info;
|
||||
int treesource_error;
|
||||
bool treesource_error;
|
||||
|
||||
struct boot_info *dt_from_source(const char *fname)
|
||||
{
|
||||
the_boot_info = NULL;
|
||||
treesource_error = 0;
|
||||
treesource_error = false;
|
||||
|
||||
srcfile_push(fname);
|
||||
yyin = current_srcfile->f;
|
||||
|
@ -54,7 +54,7 @@ static void write_prefix(FILE *f, int level)
|
|||
fputc('\t', f);
|
||||
}
|
||||
|
||||
static int isstring(char c)
|
||||
static bool isstring(char c)
|
||||
{
|
||||
return (isprint(c)
|
||||
|| (c == '\0')
|
||||
|
|
2
util.c
2
util.c
|
@ -70,7 +70,7 @@ char *join_path(const char *path, const char *name)
|
|||
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 *ss, *se;
|
||||
|
|
3
util.h
3
util.h
|
@ -2,6 +2,7 @@
|
|||
#define _UTIL_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.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
|
||||
* @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
|
||||
|
|
Loading…
Reference in a new issue