From 3b200f895cb7884c72d9e2409f047284027abc68 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 17 Mar 2011 22:15:13 +1030 Subject: [PATCH] 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. --- Makefile-ccan | 2 +- config.h | 2 +- tools/Makefile | 2 +- tools/ccanlint/Makefile | 2 +- tools/ccanlint/ccanlint.c | 4 ++-- tools/ccanlint/file_analysis.c | 11 ++++++----- tools/ccanlint/tests/examples_compile.c | 10 +++++----- tools/ccanlint/tests/examples_run.c | 4 ++-- tools/ccanlint/tests/headers_idempotent.c | 2 +- tools/namespacize.c | 12 ++++++------ 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Makefile-ccan b/Makefile-ccan index f1d76e6c..22f1bbe5 100644 --- a/Makefile-ccan +++ b/Makefile-ccan @@ -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 diff --git a/config.h b/config.h index 4cd3f2ed..22e6c2f9 100644 --- a/config.h +++ b/config.h @@ -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 diff --git a/tools/Makefile b/tools/Makefile index a981e404..63d474fb 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,6 +1,6 @@ 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) diff --git a/tools/ccanlint/Makefile b/tools/ccanlint/Makefile index 043c3fd2..3772267e 100644 --- a/tools/ccanlint/Makefile +++ b/tools/ccanlint/Makefile @@ -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 \ diff --git a/tools/ccanlint/ccanlint.c b/tools/ccanlint/ccanlint.c index e59912cc..5180368b 100644 --- a/tools/ccanlint/ccanlint.c +++ b/tools/ccanlint/ccanlint.c @@ -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'); diff --git a/tools/ccanlint/file_analysis.c b/tools/ccanlint/file_analysis.c index 92c23798..530416e3 100644 --- a/tools/ccanlint/file_analysis.c +++ b/tools/ccanlint/file_analysis.c @@ -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. */ diff --git a/tools/ccanlint/tests/examples_compile.c b/tools/ccanlint/tests/examples_compile.c index a0a3dd64..7d28aad6 100644 --- a/tools/ccanlint/tests/examples_compile.c +++ b/tools/ccanlint/tests/examples_compile.c @@ -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, "//")) { diff --git a/tools/ccanlint/tests/examples_run.c b/tools/ccanlint/tests/examples_run.c index 4cf92422..23a3844a 100644 --- a/tools/ccanlint/tests/examples_run.c +++ b/tools/ccanlint/tests/examples_run.c @@ -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; diff --git a/tools/ccanlint/tests/headers_idempotent.c b/tools/ccanlint/tests/headers_idempotent.c index 7e0dc300..59d240e3 100644 --- a/tools/ccanlint/tests/headers_idempotent.c +++ b/tools/ccanlint/tests/headers_idempotent.c @@ -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] = '_'; diff --git a/tools/namespacize.c b/tools/namespacize.c index cf6bc26d..100d7942 100644 --- a/tools/namespacize.c +++ b/tools/namespacize.c @@ -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); -- 2.39.2