-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
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
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);
if (!buffer)
err(1, "Getting file %s", name);
- return split(buffer, buffer, "\n", num_lines);
+ return strsplit(buffer, buffer, "\n", num_lines);
}
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)
#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)
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;
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], "/**")) {
#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" \
#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;
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;
}
+++ /dev/null
-#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;
-}
-
#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);