From 4564590c534364665c54ac4449dd9dce215421ea Mon Sep 17 00:00:00 2001 From: ketmar Date: Wed, 2 Jul 2008 13:26:38 +0300 Subject: [PATCH] glob omits "." and ".."; removed built-in that will never be ported --- Jamnew.sample | 10 +++++-- builtins.c | 93 +++++++---------------------------------------------------- builtins.h | 3 -- 3 files changed, 17 insertions(+), 89 deletions(-) diff --git a/Jamnew.sample b/Jamnew.sample index 5300344..05a265a 100644 --- a/Jamnew.sample +++ b/Jamnew.sample @@ -1,12 +1,16 @@ -pwd = [ PWD ] ; +pwd = [ Pwd ] ; Echo "currend dir" $(PWD) ; list = c b a d ; Echo "unsorted:" $(list) "|" ; -sorted = [ SORT $(list) ] ; +sorted = [ Sort $(list) ] ; Echo "sorted:" $(sorted) "|" ; -cmd = [ COMMAND "which sdl-config" exit-code ] ; +cmd = [ Command "which sdl-config" exit-code ] ; Echo "cmd:" $(cmd) "|" ; + + +fl = [ Glob . : * ] ; +Echo "flist:" $(fl) "|" ; diff --git a/builtins.c b/builtins.c index b77bc52..3e829d2 100644 --- a/builtins.c +++ b/builtins.c @@ -218,6 +218,16 @@ static void builtin_glob_back (void *closure, const char *file, int status, tim /* We wish we had file_dirscan() pass up a PATHNAME. */ path_parse(file, &f); f.f_dir.len = 0; + + /* For globbing, we unconditionally ignore current and parent + directory items. Since those items always exist, there's no + reason why caller of GLOB would want to see them. + We could also change file_dirscan, but then paths with embedded + "." and ".." won't work anywhere. + */ + /* k8: will this break anything? it shouldn't... */ + if (!strcmp(f.f_base.ptr, ".") || !strcmp(f.f_base.ptr, "..")) return; + path_build(&f, buf, 0); for (l = globbing->patterns; l; l = l->next) { @@ -319,89 +329,6 @@ LIST *builtin_sort (PARSE *parse, LOL *args, int *jmp) { } -#if 0 -/* backported from boost-jam */ -LIST *builtin_normalize_path (PARSE *parse, LOL *args, int *jmp) { - LIST *arg = lol_get(args, 0); - /* First, we iterate over all '/'-separated elements, starting from - the end of string. If we see '..', we remove previous path elements. - If we see '.', we remove it. - The removal is done by putting '\1' in the string. After all the string - is processed, we do a second pass, removing '\1' characters. - */ - string in[1], out[1], tmp[1]; - char *end; /* Last character of the part of string still to be processed. */ - char *current; /* Working pointer. */ - int dotdots = 0; /* Number of '..' elements seen and not processed yet. */ - int rooted = arg->string[0] == '/'; - char *result; - - /* Make a copy of input: we should not change it. */ - KStringNew(in); - if (!rooted) KStringPushBack(in, '/'); - while (arg) { - KStringAppend(in, arg->string); - arg = list_next(arg); - if (arg) KStringAppend(in, "/"); - } - - end = in->value+in->size-1; - current = end; - - for (; end >= in->value;) { - /* Set 'current' to the next occurence of '/', which always exists. */ - for (current = end; *current != '/'; --current) ; - if (current == end && current != in->value) { - /* Found a trailing slash. Remove it. */ - *current = '\1'; - } else if (current == end && *(current+1) == '/') { - /* Found duplicated slash. Remove it. */ - *current = '\1'; - } else if (end - current == 1 && strncmp(current, "/.", 2) == 0) { - /* Found '/.'. Drop them all. */ - *current = '\1'; - *(current+1) = '\1'; - } else if (end - current == 2 && strncmp(current, "/..", 3) == 0) { - /* Found '/..' */ - *current = '\1'; - *(current+1) = '\1'; - *(current+2) = '\1'; - ++dotdots; - } else if (dotdots) { - char* p = current; - memset(current, '\1', end-current+1); - --dotdots; - } - end = current-1; - } - - KStringNew(tmp); - while (dotdots--) KStringAppend(tmp, "/.."); - KStringAppend(tmp, in->value); - KStringCopy(in, tmp->value); - KStringFree(tmp); - - KStringNew(out); - /* The resulting path is either empty or has '/' as the first significant - element. If the original path was not rooted, we need to drop first '/'. - If the original path was rooted, and we've got empty path, need to add '/' - */ - if (!rooted) { - current = strchr(in->value, '/'); - if (current) *current = '\1'; - } - - for (current = in->value; *current; ++current) if (*current != '\1') KStringPushBack(out, *current); - - result = newstr(out->size ? out->value : (rooted ? "/" : ".")); - KStringFree(in); - KStringFree(out); - - return list_new(0, result); -} -#endif - - /* backported from boost-jam */ LIST *builtin_command (PARSE *parse, LOL *args, int *jmp) { LIST *l; diff --git a/builtins.h b/builtins.h index 61b11cd..2b7cd4b 100644 --- a/builtins.h +++ b/builtins.h @@ -23,7 +23,4 @@ LIST *builtin_hdrmacro (PARSE *parse, LOL *args, int *jmp); LIST *builtin_pwd (PARSE *parse, LOL *args, int *jmp); LIST *builtin_sort (PARSE *parse, LOL *args, int *jmp); -#if 0 -LIST *builtin_normalize_path (PARSE *parse, LOL *args, int *jmp); -#endif LIST *builtin_command (PARSE *parse, LOL *args, int *jmp); -- 2.11.4.GIT