From 3b4a4d98b6b69fb0b6ea5176449d83f207ff4b0d Mon Sep 17 00:00:00 2001 From: jgarcia Date: Wed, 6 Sep 2006 14:24:52 +0000 Subject: [PATCH] DIRECTORY now works like in CLISP. --- src/CHANGELOG | 9 +++++++ src/c/unixfsys.d | 68 ++++++++++++++++-------------------------------- 2 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/CHANGELOG b/src/CHANGELOG index c9799672d..f928421a5 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -35,6 +35,15 @@ ECL 1.0: - [Win32] DIRECTORY now lists root directory correctly (M. Goffioul) + - DIRECTORY behaves more according to people's expectations + (DIRECTORY "*/") => List all directories in current path + (DIRECTORY "*.*") => List all files in current path + This means you need to make two calls to DIRECTORY to get all the content of + it, but it allows you to select whether you want to list files or + not. Furthermore, the paths returned by DIRECTORY are more or less + guaranteed to match the mask -- the exception are links, for whose the + truename is returned. + ;;; Local Variables: *** ;;; mode:text *** ;;; fill-column:79 *** diff --git a/src/c/unixfsys.d b/src/c/unixfsys.d index ebb9a6552..72be3a127 100644 --- a/src/c/unixfsys.d +++ b/src/c/unixfsys.d @@ -72,9 +72,6 @@ static cl_object current_dir(void) { cl_object output; const char *ok; -#ifdef _MSC_VER - char *c; -#endif cl_index size = 128; do { @@ -89,15 +86,8 @@ current_dir(void) { strcpy(other->base_string.self, output->base_string.self); output = other; } -#ifdef _MSC_VER - for (c=output->base_string.self; *c; c++) - if (*c == '\\') - *c = '/'; -#endif - if (output->base_string.self[size-1] != '/') { - output->base_string.self[size++] = '/'; - output->base_string.self[size] = 0; - } + output->base_string.self[size++] = '/'; + output->base_string.self[size] = 0; output->base_string.fillp = size; return output; } @@ -581,45 +571,33 @@ static cl_object dir_files(cl_object basedir, cl_object pathname) { cl_object all_files, output = Cnil; - cl_object mask, name, type; - - name = pathname->pathname.name; - type = pathname->pathname.type; - if (name != Cnil || type != Cnil) { - mask = make_pathname(Cnil, Cnil, Cnil, name, type, - pathname->pathname.version); - } else { - mask = Cnil; + cl_object mask; + cl_object name = pathname->pathname.name; + cl_object type = pathname->pathname.type; + if (name == Cnil && type == Cnil) { + return cl_list(1, basedir); } + mask = make_pathname(Cnil, Cnil, Cnil, name, type, pathname->pathname.version); all_files = list_current_directory(NULL, FALSE); loop_for_in(all_files) { - char *text = CAR(all_files)->base_string.self; - if (file_kind(text, TRUE) == @':directory') { - if (mask == Cnil) { - cl_object new = nconc(cl_copy_list(basedir->pathname.directory), - CONS(CAR(all_files), Cnil)); - new = make_pathname(basedir->pathname.host, - basedir->pathname.device, - new, Cnil, Cnil, Cnil); - output = CONS(new, output); - } - } else { - cl_object new = cl_pathname(CAR(all_files)); - if (mask != Cnil && Null(cl_pathname_match_p(new, mask))) - continue; + cl_object new = CAR(all_files); + char *text = new->base_string.self; + if (file_kind(text, TRUE) == @':directory') + continue; + new = cl_pathname(new); + if (Null(cl_pathname_match_p(new, mask))) + continue; #ifdef HAVE_LSTAT - if (file_kind(text, FALSE) == @':link') -#else - if (0) + if (file_kind(text, FALSE) == @':link') { + new = cl_truename(new); + } else #endif - new = cl_truename(CAR(all_files)); - else { - new->pathname.host = basedir->pathname.host; - new->pathname.device = basedir->pathname.device; - new->pathname.directory = basedir->pathname.directory; - } - output = CONS(new, output); + { + new->pathname.host = basedir->pathname.host; + new->pathname.device = basedir->pathname.device; + new->pathname.directory = basedir->pathname.directory; } + output = CONS(new, output); } end_loop_for_in; return output; }