summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kyheku <kaz@kylheku.com>2020-01-31 06:06:39 -0800
committerKaz Kylheku <kaz@kylheku.com>2020-01-31 06:06:39 -0800
commitb0ebc5943d7de0e76e3e908fb2d543f34396b69f (patch)
tree0392694052e11387e864ec2421ddd4e3a2f2c9d2
parenteeb8ac7f7bcb3ba950a927a4123e277d1130b862 (diff)
downloadtxr-b0ebc5943d7de0e76e3e908fb2d543f34396b69f.tar.gz
txr-b0ebc5943d7de0e76e3e908fb2d543f34396b69f.tar.bz2
txr-b0ebc5943d7de0e76e3e908fb2d543f34396b69f.zip
open-files: add mode string argument.
The open-files and open-files* functions are missing a mode string argument, which makes it impossible to, say, open all of the files in "rb" mode on a platform where that matters. * stream.c (open_files, open_files_star): Take mode as a third optional parameter. If it is present, then pass it to open_file. * txr.1: Document mode string parameter for the two functions.
-rw-r--r--stream.c16
-rw-r--r--txr.117
2 files changed, 26 insertions, 7 deletions
diff --git a/stream.c b/stream.c
index 3dd3ed30..3dd76a4d 100644
--- a/stream.c
+++ b/stream.c
@@ -4503,23 +4503,31 @@ val rename_path(val from, val to)
return t;
}
-static val open_files(val file_list, val substitute_stream)
+static val open_files(val file_list, val substitute_stream, val mode)
{
substitute_stream = default_null_arg(substitute_stream);
+ mode = default_null_arg(mode);
if (nilp(file_list) && substitute_stream) {
return substitute_stream;
+ } else if (mode) {
+ return make_catenated_stream(mapcar(curry_12_1(func_n2o(open_file, 1),
+ mode), file_list));
} else {
return make_catenated_stream(mapcar(func_n2o(open_file, 1), file_list));
}
}
-static val open_files_star(val file_list, val substitute_stream)
+static val open_files_star(val file_list, val substitute_stream, val mode)
{
substitute_stream = default_null_arg(substitute_stream);
+ mode = default_null_arg(mode);
if (nilp(file_list) && substitute_stream) {
return substitute_stream;
+ } else if (mode) {
+ return make_catenated_stream(lazy_mapcar(curry_12_1(func_n2o(open_file, 1),
+ mode), file_list));
} else {
return make_catenated_stream(lazy_mapcar(func_n2o(open_file, 1), file_list));
}
@@ -4875,8 +4883,8 @@ void stream_init(void)
reg_fun(intern(lit("run"), user_package), func_n2o(run, 1));
reg_fun(intern(lit("remove-path"), user_package), func_n2o(remove_path, 1));
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("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("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));
diff --git a/txr.1 b/txr.1
index dc0fad41..d58ff298 100644
--- a/txr.1
+++ b/txr.1
@@ -50010,8 +50010,8 @@ of
.coNP Functions @ open-files and @ open-files*
.synb
-.mets (open-files < path-list <> [ alternative-stream ])
-.mets (open-files* < path-list <> [ alternative-stream ])
+.mets (open-files < path-list >> [ alternative-stream <> [ mode-string ]])
+.mets (open-files* < path-list >> [ alternative-stream <> [ mode-string ]])
.syne
.desc
The
@@ -50019,8 +50019,19 @@ The
and
.code open-files*
functions create a list of streams by invoking
-the open-file function on each element of
+the
+.code open-file
+function on each element of
.metn path-list .
+By default, the mode string
+.str r
+is passed to
+.codn open-file ;
+if the
+.meta mode-string
+argument specified, it overrides this default. In that situation,
+the specified mode should permit reading.
+
These streams are turned
into a catenated stream as if applied as arguments to
.codn make-catenated-stream .