]> git.ozlabs.org Git - ccan/commitdiff
strsplit: remove nump argument
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 18 Jan 2011 00:44:46 +0000 (11:14 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 18 Jan 2011 00:44:46 +0000 (11:14 +1030)
You can use talloc_array_length() to get the length of a tallocated array.

16 files changed:
ccan/grab_file/grab_file.h
ccan/grab_file/test/run-grab.c
ccan/str_talloc/_info
ccan/str_talloc/str_talloc.c
ccan/str_talloc/str_talloc.h
ccan/str_talloc/test/run.c
ccan/tdb/tools/replay_trace.c
tools/ccanlint/ccanlint.c
tools/ccanlint/file_analysis.c
tools/ccanlint/tests/tests_coverage.c
tools/ccanlint/tests/tests_pass_valgrind.c
tools/depends.c
tools/doc_extract-core.c
tools/doc_extract.c
tools/doc_extract.h
tools/namespacize.c

index b2bd31ada26108d0c5a179b07c744bcdc26f692e..5d6d018c34e363ea530475ac8d0d3b65aed8fd2c 100644 (file)
@@ -25,7 +25,7 @@
  *             all = grab_fd(NULL, 0, NULL);
  *             if (!all)
  *                     return NULL;
  *             all = grab_fd(NULL, 0, NULL);
  *             if (!all)
  *                     return NULL;
- *             lines = strsplit(NULL, all, "\n", NULL);
+ *             lines = strsplit(NULL, all, "\n");
  *             talloc_free(all);
  *             return lines;
  *     }
  *             talloc_free(all);
  *             return lines;
  *     }
@@ -52,7 +52,7 @@ void *grab_fd(const void *ctx, int fd, size_t *size);
  *             all = grab_file(NULL, filename, NULL);
  *             if (!all)
  *                     return NULL;
  *             all = grab_file(NULL, filename, NULL);
  *             if (!all)
  *                     return NULL;
- *             lines = strsplit(NULL, all, "\n", NULL);
+ *             lines = strsplit(NULL, all, "\n");
  *             talloc_free(all);
  *             return lines;
  *     }
  *             talloc_free(all);
  *             return lines;
  *     }
index 67be97c1b7b512778df691fdecd70af4cf7fbaed..deb466e91d374e120ea9dc812fd96c5cc92cb7b6 100644 (file)
@@ -18,7 +18,7 @@ main(int argc, char *argv[])
        struct          stat st;
 
        str = grab_file(NULL, "test/run-grab.c", NULL);
        struct          stat st;
 
        str = grab_file(NULL, "test/run-grab.c", NULL);
-       split = strsplit(NULL, str, "\n", NULL);
+       split = strsplit(NULL, str, "\n");
        length = strlen(split[0]);
        ok1(!strcmp(split[0], "/* This is test for grab_file() function"));
        for (i = 1; split[i]; i++)      
        length = strlen(split[0]);
        ok1(!strcmp(split[0], "/* This is test for grab_file() function"));
        for (i = 1; split[i]; i++)      
index f6214ce79fe09f566dc52296834c865f6953d277..4edee27b2a5d7027d5d33a6fd65794efd98c6210 100644 (file)
@@ -25,7 +25,7 @@
  *             textfile = grab_file(NULL, argv[1], NULL);
  *             if (!textfile)
  *                     err(1, "Failed reading %s", argv[1]);
  *             textfile = grab_file(NULL, argv[1], NULL);
  *             if (!textfile)
  *                     err(1, "Failed reading %s", argv[1]);
- *             lines = strsplit(textfile, textfile, "\n", NULL);
+ *             lines = strsplit(textfile, textfile, "\n");
  *     
  *             // Join them back together with two linefeeds.
  *             printf("%s", strjoin(textfile, lines, "\n\n"));
  *     
  *             // Join them back together with two linefeeds.
  *             printf("%s", strjoin(textfile, lines, "\n\n"));
index e2d12df8791942744f3dec63f2e9a18284198a4d..3bcb1f2a9cf3f7836603bfa9cbed7524f98c87ff 100644 (file)
@@ -11,8 +11,7 @@
 #include <ccan/talloc/talloc.h>
 #include <ccan/str/str.h>
 
 #include <ccan/talloc/talloc.h>
 #include <ccan/str/str.h>
 
-char **strsplit(const void *ctx, const char *string, const char *delims,
-                unsigned int *nump)
+char **strsplit(const void *ctx, const char *string, const char *delims)
 {
        char **lines = NULL;
        unsigned int max = 64, num = 0;
 {
        char **lines = NULL;
        unsigned int max = 64, num = 0;
@@ -30,9 +29,9 @@ char **strsplit(const void *ctx, const char *string, const char *delims,
                        lines = talloc_realloc(ctx, lines, char *, max*=2 + 1);
        }
        lines[num] = NULL;
                        lines = talloc_realloc(ctx, lines, char *, max*=2 + 1);
        }
        lines[num] = NULL;
-       if (nump)
-               *nump = num;
-       return lines;
+
+       /* Shrink, so talloc_get_size works */
+       return talloc_realloc(ctx, lines, char *, num+1);
 }
 
 char *strjoin(const void *ctx, char *strings[], const char *delim)
 }
 
 char *strjoin(const void *ctx, char *strings[], const char *delim)
index 3c65f9f84691ef68e0f1d9e695e59b3edba0ddae..337422dee3e9af037051890e6db3f5ef02306b6f 100644 (file)
@@ -8,7 +8,6 @@
  * @ctx: the context to tallocate from (often NULL)
  * @string: the string to split
  * @delims: delimiters where lines should be split.
  * @ctx: the context to tallocate from (often NULL)
  * @string: the string to split
  * @delims: delimiters where lines should be split.
- * @nump: optional pointer to place resulting number of lines
  *
  * This function splits a single string into multiple strings.  The
  * original string is untouched: an array is allocated (using talloc)
  *
  * This function splits a single string into multiple strings.  The
  * original string is untouched: an array is allocated (using talloc)
@@ -16,8 +15,9 @@
  * in empty substrings.  By definition, no delimiters will appear in
  * the substrings.
  *
  * in empty substrings.  By definition, no delimiters will appear in
  * the substrings.
  *
- * The final char * in the array will be NULL, so you can use this or
- * @nump to find the array length.
+ * The final char * in the array will be NULL, talloc_array_length() of the
+ * returned value is 1 greater than the number of valid elements in
+ * the array.
  *
  * Example:
  *     #include <ccan/talloc/talloc.h>
  *
  * Example:
  *     #include <ccan/talloc/talloc.h>
@@ -29,7 +29,7 @@
  *             unsigned int i, long_lines = 0;
  *
  *             // Can only fail on out-of-memory.
  *             unsigned int i, long_lines = 0;
  *
  *             // Can only fail on out-of-memory.
- *             lines = strsplit(NULL, string, "\n", NULL);
+ *             lines = strsplit(NULL, string, "\n");
  *             for (i = 0; lines[i] != NULL; i++)
  *                     if (strlen(lines[i]) > 80)
  *                             long_lines++;
  *             for (i = 0; lines[i] != NULL; i++)
  *                     if (strlen(lines[i]) > 80)
  *                             long_lines++;
@@ -37,8 +37,7 @@
  *             return long_lines;
  *     }
  */
  *             return long_lines;
  *     }
  */
-char **strsplit(const void *ctx, const char *string, const char *delims,
-                unsigned int *nump);
+char **strsplit(const void *ctx, const char *string, const char *delims);
 
 /**
  * strjoin - Join an array of substrings into one long string
 
 /**
  * strjoin - Join an array of substrings into one long string
@@ -56,7 +55,7 @@ char **strsplit(const void *ctx, const char *string, const char *delims,
  *     {
  *             char **lines, *ret;
  *
  *     {
  *             char **lines, *ret;
  *
- *             lines = strsplit(NULL, string, "\n", NULL);
+ *             lines = strsplit(NULL, string, "\n");
  *             ret = strjoin(NULL, lines, "-- EOL\n");
  *             talloc_free(lines);
  *             return ret;
  *             ret = strjoin(NULL, lines, "-- EOL\n");
  *             talloc_free(lines);
  *             return ret;
index c8cc6217bd6e5832d2d0cee2a703a80964567d2c..6b7fe14ed1d71fd7fabe8e41cae8cc488a1b90aa 100644 (file)
@@ -4,34 +4,26 @@
 #include <ccan/str_talloc/str_talloc.c>
 #include <ccan/tap/tap.h>
 
 #include <ccan/str_talloc/str_talloc.c>
 #include <ccan/tap/tap.h>
 
-/* FIXME: ccanize */
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
 
 static char *substrings[] = { "far", "bar", "baz", "b", "ba", "z", "ar", NULL };
 
 int main(int argc, char *argv[])
 {
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
 
 static char *substrings[] = { "far", "bar", "baz", "b", "ba", "z", "ar", NULL };
 
 int main(int argc, char *argv[])
 {
-       unsigned int n;
        char **split, *str;
        void *ctx;
 
        char **split, *str;
        void *ctx;
 
-       plan_tests(19);
-       split = strsplit(NULL, "hello  world", " ", &n);
-       ok1(n == 3);
+       plan_tests(16);
+       split = strsplit(NULL, "hello  world", " ");
+       ok1(talloc_array_length(split) == 4);
        ok1(!strcmp(split[0], "hello"));
        ok1(!strcmp(split[1], ""));
        ok1(!strcmp(split[2], "world"));
        ok1(split[3] == NULL);
        talloc_free(split);
 
        ok1(!strcmp(split[0], "hello"));
        ok1(!strcmp(split[1], ""));
        ok1(!strcmp(split[2], "world"));
        ok1(split[3] == NULL);
        talloc_free(split);
 
-       split = strsplit(NULL, "hello  world", " ", NULL);
-       ok1(!strcmp(split[0], "hello"));
-       ok1(!strcmp(split[1], ""));
-       ok1(!strcmp(split[2], "world"));
-       ok1(split[3] == NULL);
-       talloc_free(split);
-
-       split = strsplit(NULL, "hello  world", "o ", NULL);
+       split = strsplit(NULL, "hello  world", "o ");
+       ok1(talloc_array_length(split) == 6);
        ok1(!strcmp(split[0], "hell"));
        ok1(!strcmp(split[1], ""));
        ok1(!strcmp(split[2], ""));
        ok1(!strcmp(split[0], "hell"));
        ok1(!strcmp(split[1], ""));
        ok1(!strcmp(split[2], ""));
@@ -40,7 +32,7 @@ int main(int argc, char *argv[])
        ok1(split[5] == NULL);
 
        ctx = split;
        ok1(split[5] == NULL);
 
        ctx = split;
-       split = strsplit(ctx, "hello  world", "o ", NULL);
+       split = strsplit(ctx, "hello  world", "o ");
        ok1(talloc_parent(split) == ctx);
        talloc_free(ctx);
 
        ok1(talloc_parent(split) == ctx);
        talloc_free(ctx);
 
index b42fb7b1b5e61e43858679a0b21e64f2ac66122f..0e799a686158fef4bc8c6a8229285d1387cec95a 100644 (file)
@@ -872,11 +872,11 @@ static struct op *load_tracefile(char *filename[],
        if (!contents)
                err(1, "Reading %s", filename[file]);
 
        if (!contents)
                err(1, "Reading %s", filename[file]);
 
-       lines = strsplit(contents, contents, "\n", NULL);
+       lines = strsplit(contents, contents, "\n");
        if (!lines[0])
                errx(1, "%s is empty", filename[file]);
 
        if (!lines[0])
                errx(1, "%s is empty", filename[file]);
 
-       words = strsplit(lines, lines[0], " ", NULL);
+       words = strsplit(lines, lines[0], " ");
        if (!streq(words[1], "tdb_open"))
                fail(filename[file], 1, "does not start with tdb_open");
 
        if (!streq(words[1], "tdb_open"))
                fail(filename[file], 1, "does not start with tdb_open");
 
@@ -887,7 +887,7 @@ static struct op *load_tracefile(char *filename[],
        for (i = 1; lines[i]; i++) {
                const struct op_table *opt;
 
        for (i = 1; lines[i]; i++) {
                const struct op_table *opt;
 
-               words = strsplit(lines, lines[i], " ", NULL);
+               words = strsplit(lines, lines[i], " ");
                if (!words[0] || !words[1])
                        fail(filename[file], i+1,
                             "Expected seqnum number and op");
                if (!words[0] || !words[1])
                        fail(filename[file], i+1,
                             "Expected seqnum number and op");
index 3ffe38b2cf5f3ff54629515e76dc4b2acf1850e0..15d131e20073c2106ec2963d07a2ed76c5492730 100644 (file)
@@ -238,7 +238,7 @@ static void init_tests(void)
        /* Resolve dependencies. */
        foreach_ptr(list, &compulsory_tests, &normal_tests) {
                list_for_each(list, c, list) {
        /* Resolve dependencies. */
        foreach_ptr(list, &compulsory_tests, &normal_tests) {
                list_for_each(list, c, list) {
-                       char **deps = strsplit(NULL, c->needs, " ", NULL);
+                       char **deps = strsplit(NULL, c->needs, " ");
                        unsigned int i;
 
                        for (i = 0; deps[i]; i++) {
                        unsigned int i;
 
                        for (i = 0; deps[i]; i++) {
@@ -410,8 +410,8 @@ static void add_info_options(struct ccan_file *info, bool mark_fails)
                        continue;
 
                for (i = 0; i < d->num_lines; i++) {
                        continue;
 
                for (i = 0; i < d->num_lines; i++) {
-                       char **words = collapse(strsplit(d, d->lines[i], " \t",
-                                                        NULL), NULL);
+                       char **words = collapse(strsplit(d, d->lines[i], " \t"),
+                                               NULL);
                        if (!words[0])
                                continue;
 
                        if (!words[0])
                                continue;
 
index b941f94e1c31e84c765b522f36da38338b7bca0b..985f259b24c3ac87821a614f01ce0ec63e9d1a89 100644 (file)
@@ -54,9 +54,10 @@ const char *get_ccan_file_contents(struct ccan_file *f)
 char **get_ccan_file_lines(struct ccan_file *f)
 {
        if (!f->lines)
 char **get_ccan_file_lines(struct ccan_file *f)
 {
        if (!f->lines)
-               f->lines = strsplit(f, get_ccan_file_contents(f),
-                                   "\n", &f->num_lines);
+               f->lines = strsplit(f, get_ccan_file_contents(f), "\n");
 
 
+       /* FIXME: is f->num_lines necessary? */
+       f->num_lines = talloc_array_length(f->lines) - 1;
        return f->lines;
 }
 
        return f->lines;
 }
 
@@ -64,7 +65,7 @@ struct list_head *get_ccan_file_docs(struct ccan_file *f)
 {
        if (!f->doc_sections) {
                get_ccan_file_lines(f);
 {
        if (!f->doc_sections) {
                get_ccan_file_lines(f);
-               f->doc_sections = extract_doc_sections(f->lines, f->num_lines);
+               f->doc_sections = extract_doc_sections(f->lines);
        }
        return f->doc_sections;
 }
        }
        return f->doc_sections;
 }
index ec9774dae53650778aaef9c02688e0b01e02c26e..a2b9ee32cf6d0ec421db8aa050a63332b82f829a 100644 (file)
@@ -54,7 +54,7 @@ static unsigned int score_coverage(float covered, unsigned total)
 static void analyze_coverage(struct manifest *m, bool full_gcov,
                             const char *output, struct score *score)
 {
 static void analyze_coverage(struct manifest *m, bool full_gcov,
                             const char *output, struct score *score)
 {
-       char **lines = strsplit(score, output, "\n", NULL);
+       char **lines = strsplit(score, output, "\n");
        float covered_lines = 0.0;
        unsigned int i, total_lines = 0;
        bool lines_matter = false;
        float covered_lines = 0.0;
        unsigned int i, total_lines = 0;
        bool lines_matter = false;
index 4365f2a60227bc1a259ad4671d23efa72f87f0e9..4c4338b6c1c6d3ab20ad9e93a61cdf3da8361c78 100644 (file)
@@ -52,11 +52,11 @@ static bool blank_line(const char *line)
 static char *get_leaks(const char *output, char **errs)
 {
        char *leaks = talloc_strdup(output, "");
 static char *get_leaks(const char *output, char **errs)
 {
        char *leaks = talloc_strdup(output, "");
-       unsigned int i, num;
-       char **lines = strsplit(output, output, "\n", &num);
+       unsigned int i;
+       char **lines = strsplit(output, output, "\n");
 
        *errs = talloc_strdup(output, "");
 
        *errs = talloc_strdup(output, "");
-       for (i = 0; i < num; i++) {
+       for (i = 0; i < talloc_array_length(lines) - 1; i++) {
                if (strstr(lines[i], " lost ")) {
                        /* A leak... */
                        if (strstr(lines[i], " definitely lost ")) {
                if (strstr(lines[i], " lost ")) {
                        /* A leak... */
                        if (strstr(lines[i], " definitely lost ")) {
index 4bac1b063fbcb1cdc5aea75ed3b543d8ebe9fb53..ee39a12f134e4405c98f45f10cefe9fff829752a 100644 (file)
@@ -12,8 +12,8 @@
 #include <unistd.h>
 #include <errno.h>
 
 #include <unistd.h>
 #include <errno.h>
 
-static char ** __attribute__((format(printf, 3, 4)))
-lines_from_cmd(const void *ctx, unsigned int *num, char *format, ...)
+static char ** __attribute__((format(printf, 2, 3)))
+lines_from_cmd(const void *ctx, char *format, ...)
 {
        va_list ap;
        char *cmd, *buffer;
 {
        va_list ap;
        char *cmd, *buffer;
@@ -32,7 +32,7 @@ lines_from_cmd(const void *ctx, unsigned int *num, char *format, ...)
                err(1, "Reading from '%s'", cmd);
        pclose(p);
 
                err(1, "Reading from '%s'", cmd);
        pclose(p);
 
-       return strsplit(ctx, buffer, "\n", num);
+       return strsplit(ctx, buffer, "\n");
 }
 
 /* Be careful about trying to compile over running programs (parallel make).
 }
 
 /* Be careful about trying to compile over running programs (parallel make).
@@ -80,9 +80,11 @@ static char **get_one_deps(const void *ctx, const char *dir,
        }
 
        cmd = talloc_asprintf(ctx, "%s depends", *infofile);
        }
 
        cmd = talloc_asprintf(ctx, "%s depends", *infofile);
-       deps = lines_from_cmd(cmd, num, "%s", cmd);
+       deps = lines_from_cmd(cmd, "%s", cmd);
        if (!deps)
                err(1, "Could not run '%s'", cmd);
        if (!deps)
                err(1, "Could not run '%s'", cmd);
+       /* FIXME: Do we need num arg? */
+       *num = talloc_array_length(deps) - 1;
        return deps;
 }
 
        return deps;
 }
 
@@ -120,7 +122,7 @@ static char **get_one_safe_deps(const void *ctx,
                                char **infofile)
 {
        char **deps, **lines, *raw, *fname;
                                char **infofile)
 {
        char **deps, **lines, *raw, *fname;
-       unsigned int i, n = 0;
+       unsigned int i, n;
 
        fname = talloc_asprintf(ctx, "%s/_info", dir);
        raw = grab_file(fname, fname, NULL);
 
        fname = talloc_asprintf(ctx, "%s/_info", dir);
        raw = grab_file(fname, fname, NULL);
@@ -128,9 +130,9 @@ static char **get_one_safe_deps(const void *ctx,
                errx(1, "Could not open %s", fname);
 
        /* Replace \n by actual line breaks, and split it. */
                errx(1, "Could not open %s", fname);
 
        /* Replace \n by actual line breaks, and split it. */
-       lines = strsplit(raw, replace(raw, raw, "\\n", "\n"), "\n", &n);
+       lines = strsplit(raw, replace(raw, raw, "\\n", "\n"), "\n");
 
 
-       deps = talloc_array(ctx, char *, n+1);
+       deps = talloc_array(ctx, char *, talloc_array_length(lines));
 
        for (n = i = 0; lines[i]; i++) {
                char *str;
 
        for (n = i = 0; lines[i]; i++) {
                char *str;
@@ -222,9 +224,11 @@ char **get_libs(const void *ctx, const char *dir,
        }
 
        cmd = talloc_asprintf(ctx, "%s libs", *infofile);
        }
 
        cmd = talloc_asprintf(ctx, "%s libs", *infofile);
-       libs = lines_from_cmd(cmd, num, "%s", cmd);
+       libs = lines_from_cmd(cmd, "%s", cmd);
        if (!libs)
                err(1, "Could not run '%s'", cmd);
        if (!libs)
                err(1, "Could not run '%s'", cmd);
+       /* FIXME: Do we need num arg? */
+       *num = talloc_array_length(libs) - 1;
        return libs;
 }
 
        return libs;
 }
 
index d7490598719f113ed0aa72738efb6c87c9734c91..781ce2bdbcc8d5a08baac318f5e419d14fe46781 100644 (file)
 #include "doc_extract.h"
 #include "tools.h"
 
 #include "doc_extract.h"
 #include "tools.h"
 
-static char **grab_doc(char **lines, unsigned int num, unsigned int **linemap)
+static char **grab_doc(char **lines, unsigned int **linemap)
 {
        char **ret;
 {
        char **ret;
-       unsigned int i;
+       unsigned int i, num;
        bool printing = false;
 
        bool printing = false;
 
-       ret = talloc_array(NULL, char *, num+1);
-       *linemap = talloc_array(ret, unsigned int, num);
+       ret = talloc_array(NULL, char *, talloc_array_length(lines));
+       *linemap = talloc_array(ret, unsigned int, talloc_array_length(lines));
 
        num = 0;
        for (i = 0; lines[i]; i++) {
 
        num = 0;
        for (i = 0; lines[i]; i++) {
@@ -129,10 +129,10 @@ static void add_line(struct doc_section *curr, const char *line)
        curr->lines[curr->num_lines++] = talloc_strdup(curr->lines, line);
 }
 
        curr->lines[curr->num_lines++] = talloc_strdup(curr->lines, line);
 }
 
-struct list_head *extract_doc_sections(char **rawlines, unsigned int num)
+struct list_head *extract_doc_sections(char **rawlines)
 {
        unsigned int *linemap;
 {
        unsigned int *linemap;
-       char **lines = grab_doc(rawlines, num, &linemap);
+       char **lines = grab_doc(rawlines, &linemap);
        const char *function = NULL;
        struct doc_section *curr = NULL;
        unsigned int i;
        const char *function = NULL;
        struct doc_section *curr = NULL;
        unsigned int i;
index d7617a076a752e23c858d1ab75b74a504960c9c7..5a48b79f50d048c706a5145392450fecfc936c99 100644 (file)
@@ -27,16 +27,15 @@ int main(int argc, char *argv[])
        type = argv[1];
        for (i = 2; i < argc; i++) {
                char *file, **lines;
        type = argv[1];
        for (i = 2; i < argc; i++) {
                char *file, **lines;
-               unsigned int num;
                struct list_head *list;
                struct doc_section *d;
 
                file = grab_file(NULL, argv[i], NULL);
                if (!file)
                        err(1, "Reading file %s", argv[i]);
                struct list_head *list;
                struct doc_section *d;
 
                file = grab_file(NULL, argv[i], NULL);
                if (!file)
                        err(1, "Reading file %s", argv[i]);
-               lines = strsplit(file, file, "\n", &num);
+               lines = strsplit(file, file, "\n");
 
 
-               list = extract_doc_sections(lines, num);
+               list = extract_doc_sections(lines);
                if (list_empty(list))
                        errx(1, "No documentation in file %s", argv[i]);
                talloc_free(file);
                if (list_empty(list))
                        errx(1, "No documentation in file %s", argv[i]);
                talloc_free(file);
index 24d076c929ea967d80fef193c12c00639c6b9fbf..1f4650a12bfcbc14a5efda0c7ecbf01d2a0df8a9 100644 (file)
@@ -13,5 +13,5 @@ struct doc_section {
        char **lines;
 };
 
        char **lines;
 };
 
-struct list_head *extract_doc_sections(char **rawlines, unsigned int num);
+struct list_head *extract_doc_sections(char **rawlines);
 #endif /* _DOC_EXTRACT_CORE_H */
 #endif /* _DOC_EXTRACT_CORE_H */
index 545b28bb1a4f7d2dcd138b9a4fe9325907b81502..5ac85f502f2abb0f5cc9cea1d583c68fdf5546d0 100644 (file)
@@ -445,7 +445,7 @@ static struct replace *read_replacement_file(const char *depdir)
                return NULL;
        }
 
                return NULL;
        }
 
-       for (line = strsplit(file, file, "\n", NULL); *line; line++)
+       for (line = strsplit(file, file, "\n"); *line; line++)
                add_replace(&repl, *line);
        return repl;
 }
                add_replace(&repl, *line);
        return repl;
 }