summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-06-12 07:08:41 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-06-12 07:08:41 -0700
commitff7c7432e48776dbfc970d19bb81c6fe6075c117 (patch)
tree470c512cff9fa840d1dd17bdd071a64032143c2f /stream.c
parent7f28776c14136be6deebf0c72c3b0b532d70f5a9 (diff)
downloadtxr-ff7c7432e48776dbfc970d19bb81c6fe6075c117.tar.gz
txr-ff7c7432e48776dbfc970d19bb81c6fe6075c117.tar.bz2
txr-ff7c7432e48776dbfc970d19bb81c6fe6075c117.zip
* match.c (v_load): use the abs_path_p function instead of
checking for leading slash. * stream.c (abs_path_p): New function. (stream_init): Register abs_path_p as abs-path-p. * stream.h (abs_path_p): Declared. * txr.1: Documented abs-path-p. * dep.mk: Updated.
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/stream.c b/stream.c
index b12d06e0..0236b181 100644
--- a/stream.c
+++ b/stream.c
@@ -61,6 +61,7 @@
#include "stream.h"
#include "utf8.h"
#include "eval.h"
+#include "regex.h"
val stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s;
@@ -2690,6 +2691,25 @@ static val open_files_star(val file_list, val substitute_stream)
#endif
+val abs_path_p(val path)
+{
+ static val reg;
+ val ch;
+
+ if (length(path) == zero)
+ return nil;
+ if ((ch = chr_str(path, zero)) == chr('/') || ch == chr('\\'))
+ return t;
+
+ if (!reg)
+ reg = regex_compile(lit("[A-Za-z0-9]+:[/\\\\]"), nil);
+
+ if (match_regex(path, reg, zero))
+ return t;
+
+ return nil;
+}
+
void stream_init(void)
{
protect(&std_input, &std_output, &std_debug, &std_error, &std_null, (val *) 0);
@@ -2842,4 +2862,5 @@ 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_n2o(open_files, 1));
reg_fun(intern(lit("open-files*"), user_package), func_n2o(open_files_star, 1));
+ reg_fun(intern(lit("abs-path-p"), user_package), func_n1(abs_path_p));
}