From 2e8a8367082218c5a245992b34bc3f341307b0b3 Mon Sep 17 00:00:00 2001 From: ketmar Date: Wed, 2 Oct 2013 11:40:32 +0300 Subject: [PATCH] jam using new normalize_path(); NormPath built-in replaced with NormalizePath --- doc/ChangeLog | 6 ++++++ src/builtins.c | 9 +++++---- src/hcache.c | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index d390e9e..3928793 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -445,3 +445,9 @@ [+] :W=width: pad string to the given width; if width<0: left padding [+] :W -- return string length [+] :C=width: cut string to the given width + + [-] NormPath + [+] NormalizePath path [: pwd ] + prepend 'pwd' if path is not absolute (use current working dir if no 'pwd' given). + resolve '.' and '..' (it will not use filesystem for this, just string processing). + if path ends with '/', result will end with '/' too diff --git a/src/builtins.c b/src/builtins.c index 5e27933..d53a559 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -646,20 +646,21 @@ static LIST *builtin_dependslist (PARSE *parse, LOL *args, int *jmp) { /* - * NormPath path + * NormalizePath path [: pwd] * * it will add 'pwd' if path is not absolute and will try to resolve some '.' and '..' (only leading '..' though). * it can be used in SubDir replacement to automate dir building + * if there is no $(2), use current directory as 'pwd' */ static LIST *builtin_normpath (PARSE *parse, LOL *args, int *jmp) { - LIST *el = lol_get(args, 0); + LIST *el = lol_get(args, 0), *pl = lol_get(args, 1); char *buf; int bsz; if (!el || !el->string) return L0; bsz = strlen(el->string)*2+1024; buf = malloc(bsz); if (buf == NULL) return L0; - if (!normalize_path(el->string, buf, bsz)) { free(buf); return L0; } + if (!normalize_path(el->string, buf, bsz, (pl != NULL ? pl->string : NULL))) { free(buf); return L0; } el = list_new(NULL, buf, 0); free(buf); return el; @@ -955,7 +956,7 @@ void load_builtins (void) { "Split"); bind_builtin(parse_make(builtin_normpath, P0, P0, P0, C0, C0, 0), - "NormPath"); + "NormalizePath"); bind_builtin(parse_make(builtin_listlength, P0, P0, P0, C0, C0, 0), "ListLength"); diff --git a/src/hcache.c b/src/hcache.c index b74c580..cffc548 100644 --- a/src/hcache.c +++ b/src/hcache.c @@ -254,7 +254,7 @@ LIST *hcache (TARGET *t, LIST *hdrscan) { hcachedata_t cachedata, *c = &cachedata; LIST *l = 0; static char _normalizedPath[PATH_MAX]; /* hcache() can't be called recursive, so don't put this on stack */ - char *normalizedPath = normalize_path(t->boundname, _normalizedPath, sizeof(_normalizedPath)); + char *normalizedPath = normalize_path(t->boundname, _normalizedPath, sizeof(_normalizedPath), NULL); ++queries; c->boundname = (normalizedPath != NULL ? normalizedPath : t->boundname); if (hashcheck(hcachehash, (HASHDATA **)&c)) { -- 2.11.4.GIT