diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | dep.mk | 2 | ||||
-rw-r--r-- | match.c | 2 | ||||
-rw-r--r-- | stream.c | 21 | ||||
-rw-r--r-- | stream.h | 1 | ||||
-rw-r--r-- | txr.1 | 36 |
6 files changed, 74 insertions, 2 deletions
@@ -1,3 +1,17 @@ +2014-06-12 Kaz Kylheku <kaz@kylheku.com> + + * 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. + 2014-06-11 Kaz Kylheku <kaz@kylheku.com> Version 90 @@ -6,7 +6,7 @@ ./regex.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./parser.h $(top_srcdir)/./signal.h $(top_srcdir)/./unwind.h $(top_srcdir)/./regex.h $(top_srcdir)/./txr.h ./gc.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./stream.h $(top_srcdir)/./hash.h $(top_srcdir)/./txr.h $(top_srcdir)/./gc.h $(top_srcdir)/./signal.h ./unwind.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./gc.h $(top_srcdir)/./stream.h $(top_srcdir)/./txr.h $(top_srcdir)/./signal.h $(top_srcdir)/./eval.h $(top_srcdir)/./parser.h $(top_srcdir)/./unwind.h -./stream.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./gc.h $(top_srcdir)/./signal.h $(top_srcdir)/./unwind.h $(top_srcdir)/./stream.h $(top_srcdir)/./utf8.h $(top_srcdir)/./eval.h +./stream.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./gc.h $(top_srcdir)/./signal.h $(top_srcdir)/./unwind.h $(top_srcdir)/./stream.h $(top_srcdir)/./utf8.h $(top_srcdir)/./eval.h $(top_srcdir)/./regex.h ./arith.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./signal.h $(top_srcdir)/./unwind.h $(top_srcdir)/./gc.h $(top_srcdir)/./arith.h ./hash.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./gc.h $(top_srcdir)/./signal.h $(top_srcdir)/./unwind.h $(top_srcdir)/./stream.h $(top_srcdir)/./hash.h ./utf8.o: config.h $(top_srcdir)/./lib.h $(top_srcdir)/./signal.h $(top_srcdir)/./unwind.h $(top_srcdir)/./utf8.h @@ -3647,7 +3647,7 @@ static val v_load(match_files_ctx *c) sem_error(specline, lit("load: null string path given"), nao); { - val path = if3(chr_str(target, zero) == chr('/'), + val path = if3(abs_path_p(target), target, cat_str(nappend2(sub_list(split_str(parent, lit("/")), zero, negone), @@ -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)); } @@ -113,5 +113,6 @@ val mknod_wrap(val path, val mode, val dev); val symlink_wrap(val target, val to); val link_wrap(val target, val to); val readlink_wrap(val path); +val abs_path_p(val path); void stream_init(void); @@ -12452,6 +12452,42 @@ there are no files, then read from standard input: @line @(end) +.SS Function abs-path-p + +.TP +Syntax: + + (abs-path-p <path>) + +.TP +Description: + +The abs-path-function whether the argument <path> is an absolute path. +If this is true, it returns t, otherwise nil. + +An absolute path is a string which either begins with a slash or backslash +character, or which begins with an alphanumeric word, followed by a colon, +followed by a slash or backslash. + +Examples of absolute paths: + + /etc + + c:/tmp + + ftp://user@server + + disk0:/home + + Z:\eUsers + +Examples of strings which are not absolute paths. + + (the empty string) + . + abc + foo:bar/x + $:\eabc .SS Function read |