From 5db06b07c5bb2f66677b4e924c1427707a398247 Mon Sep 17 00:00:00 2001 From: ketmar Date: Fri, 19 Aug 2011 18:44:35 +0300 Subject: [PATCH] added NormPath built-in --- doc/ChangeLog | 5 +++++ src/builtins.c | 22 +++++++++++++++++++++- src/builtins.h | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 45611e6..8e136a2 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -150,3 +150,8 @@ [+] lexer now needs less spaces (and sometimes more quoting) [+] added header caching (when using set-default-locations rule) + + [+] new build-in: [ NormPath pathstr ] + 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 diff --git a/src/builtins.c b/src/builtins.c index 73148f1..c0d9a26 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -157,6 +157,10 @@ void load_builtins (void) { bindrule("DependsList")->procedure = bindrule("DEPENDSLIST")->procedure = parse_make(builtin_dependslist, P0, P0, P0, C0, C0, 0); + + bindrule("NormPath")->procedure = + bindrule("NORMPATH")->procedure = + parse_make(builtin_normpath, P0, P0, P0, C0, C0, 0); } @@ -382,7 +386,7 @@ LIST *builtin_sort (PARSE *parse, LOL *args, int *jmp) { /* backported from boost-jam; greatly improved */ /* Command shcmd [[ : options ]] */ LIST *builtin_command (PARSE *parse, LOL *args, int *jmp) { - LIST *res = 0; + LIST *res = NULL; LIST *l; int ret; char buffer[1024], buf1[32], *spos, *epos; @@ -590,3 +594,19 @@ LIST *builtin_dependslist (PARSE *parse, LOL *args, int *jmp) { } return res; } + + +LIST *builtin_normpath (PARSE *parse, LOL *args, int *jmp) { + LIST *el = lol_get(args, 0); + 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; } + el = list_new(NULL, buf, 0); + free(buf); + return el; +} diff --git a/src/builtins.h b/src/builtins.h index 114173e..7d41667 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -35,5 +35,7 @@ extern LIST *builtin_expri1 (PARSE *parse, LOL *args, int *jmp); extern LIST *builtin_split (PARSE *parse, LOL *args, int *jmp); extern LIST *builtin_dependslist (PARSE *parse, LOL *args, int *jmp); +extern LIST *builtin_normpath (PARSE *parse, LOL *args, int *jmp); + #endif -- 2.11.4.GIT