From f37055af489b8f0b2bc3d62644679da0b5036bf4 Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Sun, 18 Mar 2012 16:53:44 +0100 Subject: [PATCH] New function to detect wild pathname components. --- src/c/pathname.d | 20 +++++++++++++++++--- src/h/internal.h | 4 ++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/c/pathname.d b/src/c/pathname.d index bc8e587d4..2e9299ba8 100644 --- a/src/c/pathname.d +++ b/src/c/pathname.d @@ -824,14 +824,14 @@ cl_logical_pathname(cl_object x) if (component == Cnil || component == @':name') { cl_object name = pathname->pathname.name; if (name != Cnil && - (name == @':wild' || (!SYMBOLP(name) && ecl_member_char('*', name)))) + (name == @':wild' || ecl_wild_string_p(name))) @(return Ct); checked = 1; } if (component == Cnil || component == @':type') { cl_object name = pathname->pathname.type; if (name != Cnil && - (name == @':wild' || (!SYMBOLP(name) && ecl_member_char('*', name)))) + (name == @':wild' || ecl_wild_string_p(name))) @(return Ct); checked = 1; } @@ -842,7 +842,7 @@ cl_logical_pathname(cl_object x) cl_object name = ECL_CONS_CAR(list); if (name != Cnil && (name == @':wild' || name == @':wild-inferiors' || - (!SYMBOLP(name) && ecl_member_char('*', name)))) + ecl_wild_string_p(name))) { @(return Ct) } @@ -1379,6 +1379,20 @@ cl_host_namestring(cl_object pname) /* --------------- PATHNAME MATCHING ------------------ */ +bool +ecl_wild_string_p(cl_object item) +{ + if (ECL_STRINGP(item)) { + cl_index i, l = ecl_length(item); + for (i = 0; i < l; i++) { + ecl_character c = ecl_char(item, i); + if (c == '\\' || c == '*' || c == '?') + return 1; + } + } + return 0; +} + /* * Take two C strings and check if the first (s) one matches against * the pattern given by the second one (p). The pattern is that of a diff --git a/src/h/internal.h b/src/h/internal.h index 165a0e661..e7782f1fd 100644 --- a/src/h/internal.h +++ b/src/h/internal.h @@ -418,6 +418,10 @@ extern void cl_write_object(cl_object x, cl_object stream); extern cl_object _ecl_package_to_be_created(const cl_env_ptr env, cl_object name); +/* pathname.d */ + +extern ecl_wild_string_p(cl_object item); + /* sequence.d */ typedef struct { cl_index start, end, length; } cl_index_pair; extern ECL_API cl_index_pair ecl_sequence_start_end(cl_object fun, cl_object s, cl_object start, cl_object end);