Commit 3b200f89 authored by Rusty Russell's avatar Rusty Russell

tools: fix ctype.h and string usage.

Enable CCAN_STR_DEBUG in the default flags, so our tools get checked,
and fix up the resulting errors.
parent 02bdd9ac
......@@ -3,7 +3,7 @@
# SRCFILES += $(wildcard ccan/*/*.c)
#CCAN_CFLAGS=-g -O3 -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations
CCAN_CFLAGS=-g -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations
CCAN_CFLAGS=-g -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -DCCAN_STR_DEBUG=1
CFLAGS = $(CCAN_CFLAGS) -I. $(DEPGEN) -Werror
......
......@@ -3,7 +3,7 @@
#define CCAN_CONFIG_H
#define _GNU_SOURCE /* Always use GNU extensions. */
#define CCAN_COMPILER "cc"
#define CCAN_CFLAGS "-g -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations"
#define CCAN_CFLAGS "-g -Wall -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -DCCAN_STR_DEBUG=1"
#define HAVE_ALIGNOF 1
#define HAVE_ASPRINTF 1
......
ALL_TOOLS = tools/configurator/configurator tools/ccan_depends tools/doc_extract tools/namespacize tools/ccanlint/ccanlint
DEP_OBJS = tools/depends.o tools/compile.o tools/tools.o ccan/str_talloc/str_talloc.o ccan/str/str.o ccan/grab_file/grab_file.o ccan/talloc/talloc.o ccan/noerr/noerr.o ccan/read_write_all/read_write_all.o
DEP_OBJS = tools/depends.o tools/compile.o tools/tools.o ccan/str_talloc/str_talloc.o ccan/str/str.o ccan/str/debug.o ccan/grab_file/grab_file.o ccan/talloc/talloc.o ccan/noerr/noerr.o ccan/read_write_all/read_write_all.o
.PHONY: tools
tools: $(ALL_TOOLS)
......
......@@ -9,7 +9,7 @@ CORE_OBJS := tools/ccanlint/ccanlint.o \
tools/tools.o \
tools/compile.o \
ccan/str_talloc/str_talloc.o ccan/grab_file/grab_file.o \
ccan/str/str.o \
ccan/str/str.o ccan/str/debug.o \
ccan/asort/asort.o \
ccan/btree/btree.o \
ccan/talloc/talloc.o ccan/noerr/noerr.o \
......
......@@ -499,7 +499,7 @@ static char *demangle_string(char *string)
if (string[i] == '\\') {
char repl;
unsigned len = 0;
char *p = strchr(mapfrom, string[i+1]);
const char *p = strchr(mapfrom, string[i+1]);
if (p) {
repl = mapto[p - mapfrom];
len = 1;
......@@ -508,7 +508,7 @@ static char *demangle_string(char *string)
repl = (string[i+2]-'0')*16
+ string[i+3]-'0';
len = 3;
} else if (isdigit(string[i+1])) {
} else if (cisdigit(string[i+1])) {
repl = (string[i+2]-'0')*8*8
+ (string[i+3]-'0')*8
+ (string[i+4]-'0');
......
......@@ -253,16 +253,17 @@ struct manifest *get_manifest(const void *ctx, const char *dir)
/* We expect the ccan dir to be two levels above module dir. */
if (!ccan_dir) {
char *p;
ccan_dir = talloc_strdup(NULL, m->dir);
p = strrchr(ccan_dir, '/');
char *p, *dir;
dir = talloc_strdup(NULL, m->dir);
p = strrchr(dir, '/');
if (!p)
errx(1, "I expect the ccan root directory in ../..");
*p = '\0';
p = strrchr(ccan_dir, '/');
p = strrchr(dir, '/');
if (!p)
errx(1, "I expect the ccan root directory in ../..");
*p = '\0';
ccan_dir = dir;
}
add_files(m, "");
......@@ -361,7 +362,7 @@ bool get_token(const char **line, const char *token)
unsigned int toklen;
*line += strspn(*line, " \t");
if (isalnum(token[0]) || token[0] == '_')
if (cisalnum(token[0]) || token[0] == '_')
toklen = strspn(*line, IDENT_CHARS);
else {
/* FIXME: real tokenizer handles ++ and other multi-chars. */
......
......@@ -145,13 +145,13 @@ static char *start_main(char *ret, const char *why)
static char *add_func(char *others, const char *line)
{
const char *p, *end = strchr(line, '(') - 1;
while (isspace(*end)) {
while (cisspace(*end)) {
end--;
if (end == line)
return others;
}
for (p = end; isalnum(*p) || *p == '_'; p--) {
for (p = end; cisalnum(*p) || *p == '_'; p--) {
if (p == line)
return others;
}
......@@ -188,7 +188,7 @@ static bool looks_internal(char **lines, char **why)
const char *line = lines[i] + strspn(lines[i], " \t");
unsigned len = strspn(line, IDENT_CHARS);
if (!line[0] || isspace(line[0]) || strstarts(line, "//"))
if (!line[0] || cisspace(line[0]) || strstarts(line, "//"))
continue;
/* The winners. */
......@@ -228,7 +228,7 @@ static bool looks_internal(char **lines, char **why)
/* Single identifier then operator == inside function. */
if (last_ended && len
&& ispunct(line[len+strspn(line+len, " ")])) {
&& cispunct(line[len+strspn(line+len, " ")])) {
*why = "starts with identifier then punctuation";
return true;
}
......@@ -361,7 +361,7 @@ static char *mangle(struct manifest *m, char **lines)
} else {
/* Character at start of line, with ( and no ;
* == function start. Ignore comments. */
if (!isspace(line[0])
if (!cisspace(line[0])
&& strchr(line, '(')
&& !strchr(line, ';')
&& !strstr(line, "//")) {
......
......@@ -36,10 +36,10 @@ static bool scan_forv(const void *ctx,
va_copy(ap, *args);
if (isspace(fmt[0])) {
if (cisspace(fmt[0])) {
/* One format space can swallow many input spaces */
ret = false;
while (isspace(input[0])) {
while (cisspace(input[0])) {
if (scan_forv(ctx, ++input, fmt+1, &ap)) {
ret = true;
break;
......
......@@ -27,7 +27,7 @@ static void fix_name(char *name)
unsigned int i;
for (i = 0; name[i]; i++) {
if (isalnum(name[i]))
if (cisalnum(name[i]))
name[i] = toupper(name[i]);
else
name[i] = '_';
......
......@@ -112,7 +112,7 @@ static void look_for_macros(char *contents, struct replace **repl)
for (p = contents; *p; p++) {
if (*p == '\n')
state = LINESTART;
else if (!isspace(*p)) {
else if (!cisspace(*p)) {
if (state == LINESTART && *p == '#')
state = HASH;
else if (state==HASH && !strncmp(p, "define", 6)) {
......@@ -178,9 +178,9 @@ static char *get_statement(const void *ctx, char **p)
return answer;
}
/* Compress whitespace into a single ' ' */
if (isspace(c)) {
if (cisspace(c)) {
c = ' ';
while (isspace((*p)[1]))
while (cisspace((*p)[1]))
(*p)++;
} else if (c == '{' || c == '(' || c == '[') {
if (c == '(')
......@@ -317,11 +317,11 @@ static char *find_word(char *f, const char *str)
while ((p = strstr(p, str)) != NULL) {
/* Check it's not in the middle of a word. */
if (p > f && (isalnum(p[-1]) || p[-1] == '_')) {
if (p > f && (cisalnum(p[-1]) || p[-1] == '_')) {
p++;
continue;
}
if (isalnum(p[strlen(str)]) || p[strlen(str)] == '_') {
if (cisalnum(p[strlen(str)]) || p[strlen(str)] == '_') {
p++;
continue;
}
......@@ -351,7 +351,7 @@ static const char *rewrite_file(const char *filename,
off = p - file;
memcpy(new, file, off);
if (isupper(repl->string[0]))
if (cisupper(repl->string[0]))
memcpy(new + off, "CCAN_", 5);
else
memcpy(new + off, "ccan_", 5);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment