summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-02 15:28:46 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-02 15:28:46 -0700
commitde3082638e204aae1fa63a390967cbef082304bb (patch)
tree8a5042ec0e1ce6d4cc1a353f471ebe5d55d7432b
parentffe87454b93115be056a5ec99dd8300dafa9eb18 (diff)
downloadtxr-de3082638e204aae1fa63a390967cbef082304bb.tar.gz
txr-de3082638e204aae1fa63a390967cbef082304bb.tar.bz2
txr-de3082638e204aae1fa63a390967cbef082304bb.zip
New function: portable-abs-path-p.
* share/txr/stdlib/doc-syms.tl: Updated. * stream.c (portable_abs_path_p): New function, exact copy of old abs_path_p. (abs_path_p): Rewritten to be specific to host platform. No Windows-drive-like prefixes are checked on POSIX. (stream_init): Register new function. Register abs-path-p conditionally based on 258 compatibility. * stream.h (portable_abs_path_p): Declared. * txr.1: Documented, with compat notes.
-rw-r--r--share/txr/stdlib/doc-syms.tl3
-rw-r--r--stream.c29
-rw-r--r--stream.h1
-rw-r--r--txr.136
4 files changed, 61 insertions, 8 deletions
diff --git a/share/txr/stdlib/doc-syms.tl b/share/txr/stdlib/doc-syms.tl
index 243493a7..cf061a69 100644
--- a/share/txr/stdlib/doc-syms.tl
+++ b/share/txr/stdlib/doc-syms.tl
@@ -1485,7 +1485,7 @@
("make-zstruct" "N-03855D2D")
("fnm-leading-dir" "N-0330E15A")
("enametoolong" "N-036B1BDB")
- ("abs-path-p" "N-0255B4F1")
+ ("abs-path-p" "N-00477B23")
("rng" "N-00BEA6DF")
("collect-each*" "N-0105F01D")
("dump-compiled-objects" "N-02FE7607")
@@ -1719,6 +1719,7 @@
("ignerr" "N-007287AC")
(":match" "N-03B92C0D")
("set-max-length" "N-031FA9E5")
+ ("portable-abs-path-p" "N-00477B23")
("whena" "N-005C93DF")
("find" "N-005431FF")
("base64-decode" "N-01B05083")
diff --git a/stream.c b/stream.c
index 2aa3e833..52389245 100644
--- a/stream.c
+++ b/stream.c
@@ -4712,7 +4712,7 @@ static val open_files_star(val file_list, val substitute_stream, val mode)
static val ap_regex;
-val abs_path_p(val path)
+val portable_abs_path_p(val path)
{
val ch;
@@ -4730,6 +4730,28 @@ val abs_path_p(val path)
return nil;
}
+val abs_path_p(val path)
+{
+ const wchar_t *psc = coerce(const wchar_t *, path_sep_chars);
+
+ if (length(path) == zero)
+ return nil;
+
+ if (wcschr(psc, c_chr(chr_str(path, zero))))
+ return t;
+
+ if (psc[0] != '\\')
+ return nil;
+
+ if (!ap_regex)
+ ap_regex = regex_compile(lit("[A-Za-z0-9]+:[/\\\\]"), nil);
+
+ if (match_regex(path, ap_regex, zero))
+ return t;
+
+ return nil;
+}
+
static val plp_regex;
val pure_rel_path_p(val path)
@@ -5065,7 +5087,10 @@ void stream_init(void)
reg_fun(intern(lit("rename-path"), user_package), func_n2(rename_path));
reg_fun(intern(lit("open-files"), user_package), func_n3o(open_files, 1));
reg_fun(intern(lit("open-files*"), user_package), func_n3o(open_files_star, 1));
- reg_fun(intern(lit("abs-path-p"), user_package), func_n1(abs_path_p));
+ reg_fun(intern(lit("portable-abs-path-p"), user_package), func_n1(portable_abs_path_p));
+ reg_fun(intern(lit("abs-path-p"), user_package),
+ func_n1(if3(opt_compat && opt_compat <= 258,
+ portable_abs_path_p, abs_path_p)));
reg_fun(intern(lit("pure-rel-path-p"), user_package), func_n1(pure_rel_path_p));
reg_fun(intern(lit("base-name"), user_package), func_n2o(base_name, 1));
reg_fun(intern(lit("dir-name"), user_package), func_n1(dir_name));
diff --git a/stream.h b/stream.h
index 9a1e9d4e..6d84f7a0 100644
--- a/stream.h
+++ b/stream.h
@@ -241,6 +241,7 @@ val catenated_stream_p(val obj);
val catenated_stream_push(val new_stream, val cat_stream);
val remove_path(val path, val throw_on_error);
val rename_path(val from, val to);
+val portable_abs_path_p(val path);
val abs_path_p(val path);
val pure_rel_path_p(val path);
val base_name(val path, val suff);
diff --git a/txr.1 b/txr.1
index ecf47c37..8bd9e791 100644
--- a/txr.1
+++ b/txr.1
@@ -55205,14 +55205,17 @@ there are no files, then read from standard input:
@(end)
.brev
-.coNP Function @ abs-path-p
+.coNP Functions @ abs-path-p and @ portable-abs-path-p
.synb
.mets (abs-path-p << path )
+.mets (portable-abs-path-p << path )
.syne
.desc
The
-.code abs-path-function
-tests whether the argument
+.code abs-path-p
+and
+.code portable-abs-path-p
+functions test whether the argument
.meta path
is an absolute path, returning a
.code t
@@ -55220,7 +55223,9 @@ or
.code nil
indication.
-The function behaves in the same manner on all platforms, implementing
+The
+.code portable-abs-path-p
+function behaves in the same manner on all platforms, implementing
a platform-agnostic definition of
.IR "absolute path" ,
as follows.
@@ -55231,7 +55236,8 @@ followed by a slash or backslash.
The empty string isn't an absolute path.
-Examples of absolute paths:
+Examples of absolute paths under
+.codn portable-abs-path-p :
.verb
/etc
@@ -55251,6 +55257,21 @@ Examples of strings which are not absolute paths:
$:\eabc
.onom
+The
+.code abs-path-p
+is similar to
+.code portable-abs-path-p
+except that it reports false for paths which are not absolute paths
+according to the host platform. The following paths are not absolute
+on POSIX platforms:
+
+.verb
+ c:/tmp
+ ftp://user@server
+ disk0:/home
+ Z:\eUsers
+.brev
+
.coNP Function @ pure-rel-path-p
.synb
.mets (pure-rel-path-p << path )
@@ -79415,6 +79436,11 @@ A compatibility value of 248 or lower restores the above old behaviors of
.code @
and
.codn hash-revget .
+.IP 258
+Selecting 258 or lower compatibility causes
+.code abs-path-p
+to behave like
+.codn portable-abs-path-p .
.IP 257
Until \*(TX 257, the function
.code lexical-var-p