]> git.ozlabs.org Git - ccan/commitdiff
tools: use tal/path instead of opencoding most paths.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 3 Dec 2012 11:36:40 +0000 (22:06 +1030)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tools/ccanlint/ccanlint.c
tools/ccanlint/tests/depends_exist.c
tools/ccanlint/tests/license_exists.c
tools/ccanlint/tests/objects_build.c
tools/ccanlint/tests/tests_exist.c
tools/depends.c
tools/manifest.c
tools/namespacize.c
tools/read_config_header.c

index 83549cc968ffb71feb36da499453e3a3e996deec..196f75f4352f1750f033fbfe4c63b91f3b06fcdb 100644 (file)
@@ -647,7 +647,7 @@ int main(int argc, char *argv[])
                strmap_iterate(&tests, add_to_all, &all);
 
        /* This links back to the module's test dir. */
                strmap_iterate(&tests, add_to_all, &all);
 
        /* This links back to the module's test dir. */
-       testlink = tal_fmt(NULL, "%s/test", temp_dir());
+       testlink = path_join(NULL, temp_dir(), "test");
 
        /* Defaults to pwd. */
        if (argc == 1) {
 
        /* Defaults to pwd. */
        if (argc == 1) {
@@ -656,12 +656,8 @@ int main(int argc, char *argv[])
        }
 
        for (i = 1; i < argc; i++) {
        }
 
        for (i = 1; i < argc; i++) {
-               dir = argv[i];
-
-               if (dir[0] != '/')
-                       dir = tal_fmt(NULL, "%s/%s", base_dir, dir);
-               while (strends(dir, "/"))
-                       dir[strlen(dir)-1] = '\0';
+               dir = path_simplify(NULL,
+                                   take(path_join(NULL, base_dir, argv[i])));
 
        got_dir:
                /* We assume there's a ccan/ in there somewhere... */
 
        got_dir:
                /* We assume there's a ccan/ in there somewhere... */
@@ -685,7 +681,7 @@ int main(int argc, char *argv[])
                /* Create a symlink from temp dir back to src dir's
                 * test directory. */
                unlink(testlink);
                /* Create a symlink from temp dir back to src dir's
                 * test directory. */
                unlink(testlink);
-               if (symlink(tal_fmt(m, "%s/test", dir), testlink) != 0)
+               if (symlink(path_join(m, dir, "test"), testlink) != 0)
                        err(1, "Creating test symlink in %s", temp_dir());
 
                if (!run_tests(&all, summary, m, prefix))
                        err(1, "Creating test symlink in %s", temp_dir());
 
                if (!run_tests(&all, summary, m, prefix))
index c63d2d2c84d6d85baafdd953a2279bd671199b29..39015fd58730d9184edc0a295ab127a34005530c 100644 (file)
@@ -1,6 +1,7 @@
 #include <tools/ccanlint/ccanlint.h>
 #include <tools/tools.h>
 #include <ccan/str/str.h>
 #include <tools/ccanlint/ccanlint.h>
 #include <tools/tools.h>
 #include <ccan/str/str.h>
+#include <ccan/tal/path/path.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -30,7 +31,7 @@ static bool add_dep(struct manifest *m,
 {
        struct stat st;
        struct manifest *subm;
 {
        struct stat st;
        struct manifest *subm;
-       char *dir = tal_fmt(m, "%s/%s", ccan_dir, dep);
+       char *dir = path_join(m, ccan_dir, dep);
 
        /* FIXME: get_manifest has a tendency to exit. */
        if (stat(dir, &st) != 0) {
 
        /* FIXME: get_manifest has a tendency to exit. */
        if (stat(dir, &st) != 0) {
index af1bc52a07c85e875829f54824c56bdad9540256..85ff79854082a096756f037ec1b415de4ee50cdd 100644 (file)
@@ -1,6 +1,7 @@
 #include <tools/ccanlint/ccanlint.h>
 #include <ccan/tal/tal.h>
 #include <ccan/tal/str/str.h>
 #include <tools/ccanlint/ccanlint.h>
 #include <ccan/tal/tal.h>
 #include <ccan/tal/str/str.h>
+#include <ccan/tal/path/path.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -73,7 +74,7 @@ static void handle_license_link(struct manifest *m, struct score *score)
 {
        struct doc_section *d = find_license_tag(m);
        const char *prefix = link_prefix(m);
 {
        struct doc_section *d = find_license_tag(m);
        const char *prefix = link_prefix(m);
-       const char *link = tal_fmt(m, "%s/LICENSE", m->dir);
+       const char *link = path_join(m, m->dir, "LICENSE");
        const char *ldest = expected_link(score, prefix, m->license);
        char *q;
 
        const char *ldest = expected_link(score, prefix, m->license);
        char *q;
 
@@ -97,7 +98,7 @@ static void check_has_license(struct manifest *m,
 {
        char buf[PATH_MAX];
        ssize_t len;
 {
        char buf[PATH_MAX];
        ssize_t len;
-       char *license = tal_fmt(m, "%s/LICENSE", m->dir);
+       char *license = path_join(m, m->dir, "LICENSE");
        const char *expected;
        struct doc_section *d;
        const char *prefix = link_prefix(m);
        const char *expected;
        struct doc_section *d;
        const char *prefix = link_prefix(m);
index b86c53beeff096a2c27f1b7be76e10ff2ea8f890..21a02773aeb95dc18cbb11e7acbedeacba271372 100644 (file)
@@ -1,6 +1,7 @@
 #include <tools/ccanlint/ccanlint.h>
 #include <tools/tools.h>
 #include <ccan/str/str.h>
 #include <tools/ccanlint/ccanlint.h>
 #include <tools/tools.h>
 #include <ccan/str/str.h>
+#include <ccan/tal/path/path.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -35,7 +36,7 @@ void build_objects(struct manifest *m,
 
        list_for_each(&m->c_files, i, list) {
                char *output;
 
        list_for_each(&m->c_files, i, list) {
                char *output;
-               char *fullfile = tal_fmt(m, "%s/%s", m->dir, i->name);
+               char *fullfile = path_join(m, m->dir, i->name);
 
                i->compiled[ctype] = temp_file(m, "", fullfile);
                if (!compile_object(score, fullfile, ccan_dir, compiler, flags,
 
                i->compiled[ctype] = temp_file(m, "", fullfile);
                if (!compile_object(score, fullfile, ccan_dir, compiler, flags,
index f339b6b9df319b08c48f5c6109eeb6d7f8a17e40..69e01df6e909ee64c0501384dcc25291efe7afa3 100644 (file)
@@ -1,5 +1,6 @@
 #include <tools/ccanlint/ccanlint.h>
 #include <ccan/tal/str/str.h>
 #include <tools/ccanlint/ccanlint.h>
 #include <ccan/tal/str/str.h>
+#include <ccan/tal/path/path.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -106,7 +107,7 @@ static void check_tests_exist(struct manifest *m,
                            unsigned int *timeleft, struct score *score)
 {
        struct stat st;
                            unsigned int *timeleft, struct score *score)
 {
        struct stat st;
-       char *test_dir = tal_fmt(m, "%s/test", m->dir);
+       char *test_dir = path_join(m, m->dir, "test");
 
        if (lstat(test_dir, &st) != 0) {
                score->error = tal_strdup(score, "No test directory");
 
        if (lstat(test_dir, &st) != 0) {
                score->error = tal_strdup(score, "No test directory");
index 664b3972968263febd5ff762331ff3fd31f5d97b..4f56d14e1eeb97edf71f5b07b2e7050ec3c940a1 100644 (file)
@@ -1,6 +1,7 @@
 #include <ccan/str/str.h>
 #include <ccan/read_write_all/read_write_all.h>
 #include <ccan/rbuf/rbuf.h>
 #include <ccan/str/str.h>
 #include <ccan/read_write_all/read_write_all.h>
 #include <ccan/rbuf/rbuf.h>
+#include <ccan/tal/path/path.h>
 #include <ccan/compiler/compiler.h>
 #include <ccan/err/err.h>
 #include "tools.h"
 #include <ccan/compiler/compiler.h>
 #include <ccan/err/err.h>
 #include "tools.h"
@@ -125,7 +126,7 @@ static char **get_one_safe_deps(const void *ctx,
        unsigned int i, n;
        bool correct_style = false;
 
        unsigned int i, n;
        bool correct_style = false;
 
-       fname = tal_fmt(ctx, "%s/_info", dir);
+       fname = path_join(ctx, dir, "_info");
        raw = tal_grab_file(fname, fname, NULL);
        if (!raw)
                errx(1, "Could not open %s", fname);
        raw = tal_grab_file(fname, fname, NULL);
        if (!raw)
                errx(1, "Could not open %s", fname);
@@ -206,7 +207,7 @@ get_all_deps(const void *ctx, const char *dir, const char *style,
                if (!strstarts(deps[i], "ccan/"))
                        continue;
 
                if (!strstarts(deps[i], "ccan/"))
                        continue;
 
-               subdir = tal_fmt(ctx, "%s/%s", find_ccan_dir(dir), deps[i]);
+               subdir = path_join(ctx, find_ccan_dir(dir), deps[i]);
                newdeps = get_one(ctx, subdir, "depends", get_info);
 
                /* Should be short, so brute-force out dups. */
                newdeps = get_one(ctx, subdir, "depends", get_info);
 
                /* Should be short, so brute-force out dups. */
@@ -279,8 +280,7 @@ char **get_libs(const void *ctx, const char *dir, const char *style,
                        if (!strstarts(deps[i], "ccan/"))
                                continue;
 
                        if (!strstarts(deps[i], "ccan/"))
                                continue;
 
-                       subdir = tal_fmt(ctx, "%s/%s",
-                                        find_ccan_dir(dir), deps[i]);
+                       subdir = path_join(ctx, find_ccan_dir(dir), deps[i]);
 
                        newlibs = get_one_libs(ctx, subdir, get_info);
                        newlen = tal_count(newlibs);
 
                        newlibs = get_one_libs(ctx, subdir, get_info);
                        newlen = tal_count(newlibs);
index 612a8a6d53ecfb1fe277483640b4fc080fcded06..b94016e1a62a419249e8a4f9bcb2d272b132be3c 100644 (file)
@@ -76,7 +76,7 @@ struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name)
        for (i = 0; i < ARRAY_SIZE(f->compiled); i++)
                f->compiled[i] = NULL;
        f->name = tal_steal(f, name);
        for (i = 0; i < ARRAY_SIZE(f->compiled); i++)
                f->compiled[i] = NULL;
        f->name = tal_steal(f, name);
-       f->fullname = tal_fmt(f, "%s/%s", dir, f->name);
+       f->fullname = path_join(f, dir, f->name);
        f->contents = NULL;
        f->simplified = NULL;
        return f;
        f->contents = NULL;
        f->simplified = NULL;
        return f;
index f1a9374e8fee1e363a549db84d324a81ecf132bc..ac4135459d88b1868d8967013daa14c824ae23de 100644 (file)
@@ -256,7 +256,8 @@ static void analyze_headers(const char *dir, struct replace **repl)
        char *hdr, *contents;
 
        /* Get hold of header, assume that's it. */
        char *hdr, *contents;
 
        /* Get hold of header, assume that's it. */
-       hdr = tal_fmt(dir, "%s/%s.h", dir, path_basename(dir, dir));
+       hdr = tal_fmt(dir, "%s.h",
+                     path_join(NULL, dir, take(path_basename(NULL, dir))));
 
        contents = tal_grab_file(dir, hdr, NULL);
        if (!contents)
 
        contents = tal_grab_file(dir, hdr, NULL);
        if (!contents)
@@ -275,7 +276,7 @@ static void analyze_headers(const char *dir, struct replace **repl)
 
 static void write_replacement_file(const char *dir, struct replace **repl)
 {
 
 static void write_replacement_file(const char *dir, struct replace **repl)
 {
-       char *replname = tal_fmt(dir, "%s/.namespacize", dir);
+       char *replname = path_join(dir, dir, ".namespacize");
        int fd;
        struct replace *r;
 
        int fd;
        struct replace *r;
 
@@ -415,10 +416,7 @@ static void convert_dir(const char *dir)
        struct adjusted *adj = NULL;
 
        /* Remove any ugly trailing slashes. */
        struct adjusted *adj = NULL;
 
        /* Remove any ugly trailing slashes. */
-       name = tal_strdup(NULL, dir);
-       while (strends(name, "/"))
-               name[strlen(name)-1] = '\0';
-
+       name = path_canon(NULL, dir);
        analyze_headers(name, &replace);
        write_replacement_file(name, &replace);
        setup_adjust_files(name, replace, &adj);
        analyze_headers(name, &replace);
        write_replacement_file(name, &replace);
        setup_adjust_files(name, replace, &adj);
@@ -430,7 +428,7 @@ static void convert_dir(const char *dir)
 static struct replace *read_replacement_file(const char *depdir)
 {
        struct replace *repl = NULL;
 static struct replace *read_replacement_file(const char *depdir)
 {
        struct replace *repl = NULL;
-       char *replname = tal_fmt(depdir, "%s/.namespacize", depdir);
+       char *replname = path_join(depdir, depdir, ".namespacize");
        char *file, **line;
 
        file = tal_grab_file(replname, replname, NULL);
        char *file, **line;
 
        file = tal_grab_file(replname, replname, NULL);
@@ -459,7 +457,7 @@ static void adjust_dir(const char *dir)
                struct adjusted *adj = NULL;
                struct replace *repl;
 
                struct adjusted *adj = NULL;
                struct replace *repl;
 
-               depdir = tal_fmt(parent, "%s/%s", parent, *deps);
+               depdir = path_join(parent, parent, *deps);
                repl = read_replacement_file(depdir);
                if (repl) {
                        verbose("%s has been namespacized\n", depdir);
                repl = read_replacement_file(depdir);
                if (repl) {
                        verbose("%s has been namespacized\n", depdir);
@@ -488,7 +486,7 @@ static void adjust_dependents(const char *dir)
                if (path_basename(*file, *file)[0] == '.')
                        continue;
 
                if (path_basename(*file, *file)[0] == '.')
                        continue;
 
-               info = tal_fmt(*file, "%s/_info", *file);
+               info = path_join(*file, *file, "_info");
                if (access(info, R_OK) != 0)
                        continue;
 
                if (access(info, R_OK) != 0)
                        continue;
 
index bd268722bb2f9d7cb63c04a87c6f0e40dc08a28b..732ab4abb2970d7fd54bb08a720abdc3b98b7ed6 100644 (file)
@@ -1,5 +1,6 @@
 #include <ccan/err/err.h>
 #include <ccan/str/str.h>
 #include <ccan/err/err.h>
 #include <ccan/str/str.h>
+#include <ccan/tal/path/path.h>
 #include "read_config_header.h"
 #include "tools.h"
 #include <string.h>
 #include "read_config_header.h"
 #include "tools.h"
 #include <string.h>
@@ -90,7 +91,7 @@ char *read_config_header(const char *ccan_dir,
                         const char **compiler, const char **cflags,
                         bool verbose)
 {
                         const char **compiler, const char **cflags,
                         bool verbose)
 {
-       char *fname = tal_fmt(NULL, "%s/config.h", ccan_dir);
+       char *fname = path_join(NULL, ccan_dir, "config.h");
        char **lines;
        unsigned int i;
        char *config_header;
        char **lines;
        unsigned int i;
        char *config_header;