diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | stream.c | 9 | ||||
-rw-r--r-- | stream.h | 2 | ||||
-rw-r--r-- | txr.1 | 14 |
4 files changed, 33 insertions, 4 deletions
@@ -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> @@ -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)); @@ -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); @@ -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 |