]> git.ozlabs.org Git - ccan/commitdiff
Use new string.h strsplit() everywhere.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 28 Jul 2008 04:21:23 +0000 (14:21 +1000)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 28 Jul 2008 04:21:23 +0000 (14:21 +1000)
tools/Makefile
tools/ccanlint/Makefile
tools/ccanlint/get_file_lines.c
tools/depends.c
tools/doc_extract.c
tools/namespacize.c
tools/split.c [deleted file]
tools/tools.h

index 4f6f699abbef92d1443d89d8c7c2676f96ee07e1..3c7fb7fa60dc57d0afaf28d8b92fef2045185a68 100644 (file)
@@ -1,15 +1,15 @@
-tools/ccan_depends: tools/ccan_depends.o tools/depends.o tools/split.o tools/grab_file.o ccan/talloc/talloc.o
+tools/ccan_depends: tools/ccan_depends.o tools/depends.o tools/grab_file.o ccan/string/string.o ccan/talloc/talloc.o
 
-tools/run_tests: tools/run_tests.o tools/depends.o tools/split.o tools/grab_file.o ccan/tap/tap.o ccan/talloc/talloc.o
+tools/run_tests: tools/run_tests.o tools/depends.o tools/grab_file.o ccan/tap/tap.o ccan/string/string.o ccan/talloc/talloc.o
 
-tools/doc_extract: tools/doc_extract.c ccan/talloc/talloc.o
+tools/doc_extract: tools/doc_extract.o ccan/string/string.o ccan/talloc/talloc.o
 
-tools/namespacize: tools/namespacize.c tools/split.o tools/grab_file.o tools/depends.o ccan/talloc/talloc.o
+tools/namespacize: tools/namespacize.o tools/grab_file.o tools/depends.o ccan/string/string.o ccan/talloc/talloc.o
 
-tools/run_tests.o tools/namespacize.o tools/split.o tools/grab_file.o tools/depends.o: tools/tools.h
+tools/run_tests.o tools/namespacize.o tools/grab_file.o tools/depends.o: tools/tools.h
 
 tools-clean: ccanlint-clean
-       rm -f run_tests doc_extract namespacize
+       rm -f tools/ccan_depends tools/run_tests tools/doc_extract tools/namespacize
 
 include tools/ccanlint/Makefile
 include tools/_infotojson/Makefile
index 60a35c121050a9e08785f4543775e67c5e487506..40c26a83978c5049e57258ac373e480b535e294d 100644 (file)
@@ -24,7 +24,7 @@ tools/ccanlint/ccanlint: \
        tools/ccanlint/ccanlint.o \
        tools/ccanlint/get_file_lines.o \
        tools/ccanlint/file_analysis.o \
-       ccan/talloc/talloc.o ccan/noerr/noerr.o
+       ccan/string/string.o ccan/talloc/talloc.o ccan/noerr/noerr.o
 
 ccanlint-clean:
        $(RM) tools/ccanlint/generated-init-tests
index e9ef302b32f0c739be09d289b5feccaaab5b078f..2f27a012dca5431a44c240a90c16307127ce9cbf 100644 (file)
@@ -49,31 +49,6 @@ static void *grab_file(const void *ctx, const char *filename)
        return buffer;
 }
 
-/* This is a dumb one which copies.  We could mangle instead. */
-static char **split(const void *ctx, const char *text, const char *delims,
-                   unsigned int *nump)
-{
-       char **lines = NULL;
-       unsigned int max = 64, num = 0;
-
-       lines = talloc_array(ctx, char *, max+1);
-
-       while (*text != '\0') {
-               unsigned int len = strcspn(text, delims);
-               lines[num] = talloc_array(lines, char, len + 1);
-               memcpy(lines[num], text, len);
-               lines[num][len] = '\0';
-               text += len;
-               text += strspn(text, delims);
-               if (++num == max)
-                       lines = talloc_realloc(ctx, lines, char *, max*=2 + 1);
-       }
-       lines[num] = NULL;
-       if (nump)
-               *nump = num;
-       return lines;
-}
-
 char **get_file_lines(void *ctx, const char *name, unsigned int *num_lines)
 {
        char *buffer = grab_file(ctx, name);
@@ -81,5 +56,5 @@ char **get_file_lines(void *ctx, const char *name, unsigned int *num_lines)
        if (!buffer)
                err(1, "Getting file %s", name);
 
-       return split(buffer, buffer, "\n", num_lines);
+       return strsplit(buffer, buffer, "\n", num_lines);
 }
index f416257a67775a5ecfd6700ee28d1afcc666c1b4..1422c8585f51d8b220fc04ca9144dc91d9eaacae 100644 (file)
@@ -24,7 +24,7 @@ lines_from_cmd(const void *ctx, unsigned int *num, char *format, ...)
                err(1, "Reading from '%s'", cmd);
        pclose(p);
 
-       return split(ctx, buffer, "\n", num);
+       return strsplit(ctx, buffer, "\n", num);
 }
 
 static char **get_one_deps(const void *ctx, const char *dir, unsigned int *num)
index b4ac0d3e6e144e6daa33d188d895baf12b874063..aa3f2206cc3bace91b18b657690d2d282084a9a1 100644 (file)
@@ -9,12 +9,7 @@
 #include <fcntl.h>
 #include <stdbool.h>
 #include "talloc/talloc.h"
-
-/* Is A == B ? */
-#define streq(a,b) (strcmp((a),(b)) == 0)
-
-/* Does A start with B ? */
-#define strstarts(a,b) (strncmp((a),(b),strlen(b)) == 0)
+#include "string/string.h"
 
 /* This version adds one byte (for nul term) */
 static void *grab_file(void *ctx, const char *filename)
@@ -46,27 +41,6 @@ static void *grab_file(void *ctx, const char *filename)
        return buffer;
 }
 
-/* This is a dumb one which copies.  We could mangle instead. */
-static char **split(const char *text)
-{
-       char **lines = NULL;
-       unsigned int max = 64, num = 0;
-
-       lines = talloc_array(text, char *, max+1);
-
-       while (*text != '\0') {
-               unsigned int len = strcspn(text, "\n");
-               lines[num] = talloc_array(lines, char, len + 1);
-               memcpy(lines[num], text, len);
-               lines[num][len] = '\0';
-               text += len + 1;
-               if (++num == max)
-                       lines = talloc_realloc(text, lines, char *, max*=2 + 1);
-       }
-       lines[num] = NULL;
-       return lines;
-}
-
 int main(int argc, char *argv[])
 {
        unsigned int i, j;
@@ -79,7 +53,7 @@ int main(int argc, char *argv[])
                file = grab_file(NULL, argv[i]);
                if (!file)
                        err(1, "Reading file %s", argv[i]);
-               lines = split(file);
+               lines = strsplit(file, file, "\n", NULL);
 
                for (j = 0; lines[j]; j++) {
                        if (streq(lines[j], "/**")) {
index 8c6c6632f51fad49ef735cd4023140e790a6554e..759ef938482f98a3b3aabd267f7e79c2fe56962d 100644 (file)
@@ -10,8 +10,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include "string/string.h"
-#include "talloc/talloc.h"
+#include "ccan/string/string.h"
+#include "ccan/talloc/talloc.h"
 #include "tools.h"
 
 #define IDENT_CHARS    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
@@ -30,16 +30,6 @@ static int indent = 0;
 #define verbose_indent() (indent += 2)
 #define verbose_unindent() (indent -= 2)
 
-#define strstarts(str,prefix) (strncmp((str),(prefix),strlen(prefix)) == 0)
-
-static inline bool strends(const char *str, const char *postfix)
-{
-       if (strlen(str) < strlen(postfix))
-               return false;
-
-       return streq(str + strlen(str) - strlen(postfix), postfix);
-}
-
 static int unlink_no_errno(const char *filename)
 {
        int ret = 0, serrno = errno;
@@ -466,7 +456,7 @@ static struct replace *read_replacement_file(const char *depdir)
                return NULL;
        }
 
-       for (line = split(file, file, "\n", NULL); *line; line++)
+       for (line = strsplit(file, file, "\n", NULL); *line; line++)
                add_replace(&repl, *line);
        return repl;
 }
diff --git a/tools/split.c b/tools/split.c
deleted file mode 100644 (file)
index f5d016a..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "tools.h"
-#include "talloc/talloc.h"
-#include <string.h>
-
-/* This is a dumb one which copies.  We could mangle instead. */
-char **split(const void *ctx, const char *text, const char *delims,
-            unsigned int *nump)
-{
-       char **lines = NULL;
-       unsigned int max = 64, num = 0;
-
-       lines = talloc_array(ctx, char *, max+1);
-
-       while (*text != '\0') {
-               unsigned int len = strcspn(text, delims);
-               lines[num] = talloc_array(lines, char, len + 1);
-               memcpy(lines[num], text, len);
-               lines[num][len] = '\0';
-               text += len;
-               text += strspn(text, delims);
-               if (++num == max)
-                       lines = talloc_realloc(ctx, lines, char *, max*=2 + 1);
-       }
-       lines[num] = NULL;
-       if (nump)
-               *nump = num;
-       return lines;
-}
-
index 4e8a48e6ab3b664ee4277fadae0725c3601fc7cb..fff962c7eb033cf08f7fe1939e2f231bef8caf74 100644 (file)
@@ -3,9 +3,6 @@
 
 #define CFLAGS "-O3 -Wall -Wundef -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Werror -Iccan/ -I."
 
-char **split(const void *ctx, const char *text, const char *delims,
-            unsigned int *nump);
-
 char **get_deps(const void *ctx, const char *dir);
 
 void *grab_fd(const void *ctx, int fd);