Skip to content

Commit

Permalink
Use stdbool more widely
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dgibson committed Oct 28, 2013
1 parent 79eebb2 commit 1762537
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 37 deletions.
16 changes: 8 additions & 8 deletions checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct check {
void *data;
bool warn, error;
enum checkstatus status;
int inprogress;
bool inprogress;
int num_prereqs;
struct check **prereq;
};
Expand Down Expand Up @@ -141,21 +141,21 @@ 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);

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'",
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 4 additions & 4 deletions dtc-lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -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);
%}

%%
Expand Down Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions dtc-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions dtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand All @@ -174,7 +174,7 @@ int main(int argc, char *argv[])
break;

case 's':
sort = 1;
sort = true;
break;

case 'W':
Expand Down
10 changes: 5 additions & 5 deletions dtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -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;

Expand All @@ -143,7 +143,7 @@ struct property {
};

struct node {
int deleted;
bool deleted;
char *name;
struct property *proplist;
struct node *children;
Expand Down Expand Up @@ -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 */

Expand Down
4 changes: 2 additions & 2 deletions flattree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions srcpos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion srcpos.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define _SRCPOS_H_

#include <stdio.h>
#include <stdbool.h>

struct srcfile_state {
FILE *f;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions treesource.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _UTIL_H

#include <stdarg.h>
#include <stdbool.h>
#include <getopt.h>

/*
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1762537

Please sign in to comment.