summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--stream.c9
-rw-r--r--stream.h2
-rw-r--r--txr.114
4 files changed, 33 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 04aac25f..d80da9c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2015-01-21 Kaz Kylheku <kaz@kylheku.com>
+ * stream.c (get_string): New argument, close_after_p.
+ Close the stream unless close_after_p is specified and is nil,
+ or when it is missing, an there is no compatibility or it's
+ newer than version 102.
+
+ * stream.h (get_string): Updated declartion.
+
+ * txr.1: Documented default closing behavior of get-string
+ and the new optional argument for overriding it.
+
+2015-01-21 Kaz Kylheku <kaz@kylheku.com>
+
* txr.1: Minor fix in split-str-set documentation.
2015-01-21 Kaz Kylheku <kaz@kylheku.com>
diff --git a/stream.c b/stream.c
index 7945e43c..60a97f8e 100644
--- a/stream.c
+++ b/stream.c
@@ -56,6 +56,7 @@
#include "utf8.h"
#include "eval.h"
#include "regex.h"
+#include "txr.h"
val stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s;
@@ -2041,7 +2042,7 @@ val seek_stream(val stream, val offset, val whence)
}
}
-val get_string(val stream, val nchars)
+val get_string(val stream, val nchars, val close_after_p)
{
val strstream = make_string_output_stream();
nchars = default_bool_arg(nchars);
@@ -2056,6 +2057,10 @@ val get_string(val stream, val nchars)
put_char(ch, strstream);
}
+ if ((missingp(close_after_p) && (!opt_compat || opt_compat > 102)) ||
+ default_arg(close_after_p, t))
+ close_stream(stream, t);
+
return get_string_from_stream(strstream);
}
@@ -2611,7 +2616,7 @@ void stream_init(void)
reg_fun(intern(lit("get-line"), user_package), func_n1o(get_line, 0));
reg_fun(intern(lit("get-char"), user_package), func_n1o(get_char, 0));
reg_fun(intern(lit("get-byte"), user_package), func_n1o(get_byte, 0));
- reg_fun(intern(lit("get-string"), user_package), func_n2o(get_string, 0));
+ reg_fun(intern(lit("get-string"), user_package), func_n3o(get_string, 0));
reg_fun(intern(lit("put-string"), user_package), func_n2o(put_string, 1));
reg_fun(intern(lit("put-line"), user_package), func_n2o(put_line, 0));
reg_fun(intern(lit("put-char"), user_package), func_n2o(put_char, 1));
diff --git a/stream.h b/stream.h
index 0f28c57c..3b01dee2 100644
--- a/stream.h
+++ b/stream.h
@@ -96,7 +96,7 @@ val put_strings(val strings, val stream);
val put_lines(val lines, val stream);
val flush_stream(val stream);
val seek_stream(val stream, val offset, val whence);
-val get_string(val stream, val nchars);
+val get_string(val stream, val nchars, val close_after_p);
val statf(val path);
val open_directory(val path);
val open_file(val path, val mode_str);
diff --git a/txr.1 b/txr.1
index 505ded7c..328b4066 100644
--- a/txr.1
+++ b/txr.1
@@ -22055,7 +22055,7 @@ See also:
.coNP Function @ get-string
.synb
-.mets (get-string >> [ stream <> [ count ]])
+.mets (get-string >> [ stream >> [ count <> [ close-after-p ]]])
.syne
.desc
The
@@ -22067,6 +22067,13 @@ argument is omitted, then the
.code *stdin*
stream is used.
+The stream is closed after extracting the data, unless
+.meta close-after-p
+is specified as
+.codn nil .
+The default value of this argument is
+.codn t .
+
If the
.meta count
argument is missing, then all of the characters from the
@@ -26614,6 +26621,11 @@ can be emulated is \*(TX 97.
Here are values which have a special meaning as arguments to the
.code -C
option, along with a description of what behaviors are affected:
+.IP 102
+Up to \*(TX 102, the
+.code get-string
+function did not close the stream. This old behavior is emulated.
+
.IP 101
Up to \*(TX 101, the
.code make-like