tools: fix ctype.h and string usage.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 17 Mar 2011 11:45:13 +0000 (22:15 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 17 Mar 2011 11:45:13 +0000 (22:15 +1030)
Enable CCAN_STR_DEBUG in the default flags, so our tools get checked,
and fix up the resulting errors.

Makefile-ccan
config.h
tools/Makefile
tools/ccanlint/Makefile
tools/ccanlint/ccanlint.c
tools/ccanlint/file_analysis.c
tools/ccanlint/tests/examples_compile.c
tools/ccanlint/tests/examples_run.c
tools/ccanlint/tests/headers_idempotent.c
tools/namespacize.c

index f1d76e6c8927ef111ac4f9c24b45eac669e08dd3..22f1bbe5d7016637f844e5aab69a3eb196e91d30 100644 (file)
@@ -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
 
 
index 4cd3f2edb16f8cb5db007378abe60b40161813e2..22e6c2f97565aafde65f9a6e12c2cb9c10394913 100644 (file)
--- 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
index a981e4049def9bfcd06027aaf7f8afee46feb17c..63d474fbcc00255343b12e198014f0d3549a8cf7 100644 (file)
@@ -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)
index 043c3fd2c7d17b82063350fa7c0fb52a67ee789e..3772267ed418b4d845fc10d777a4c64c41792899 100644 (file)
@@ -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 \
index e59912cccfe289b56689ffb654469594d9ed069d..5180368b3dda56c080f4eb97ed83fb5875168b13 100644 (file)
@@ -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');
index 92c23798292c9844058374f22115b324345ae720..530416e368cb1fd17a48f93fa7c9bc220b0f1a20 100644 (file)
@@ -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.  */
index a0a3dd64c57bf61bbde8d92ae24e140038c5f6e5..7d28aad6ca63ec965f796e3d9f3f2e33ad393082 100644 (file)
@@ -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, "//")) {
index 4cf9242297988ad64b75835f098799aea52c2915..23a3844a5bb7d0d153bb2f55cb638107e77b3a79 100644 (file)
@@ -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;
index 7e0dc300c81307b6b7786c0306e964c94c8fbc86..59d240e339f1a60477dd12814a47eb833e5db08d 100644 (file)
@@ -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] = '_';
index cf6bc26d7c4983a8d3483c976ecb9428ad8ebaac..100d79428a1a1de6877c298d48c11e3bab5a0245 100644 (file)
@@ -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);