diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-01-21 20:38:52 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-01-21 20:38:52 -0800 |
commit | aa355befc89d94f3f43d3ae4124f7d048fb4e588 (patch) | |
tree | ecee6b6cde1f503ee165d0457d94a46256ee0ce5 /stream.c | |
parent | 11bd34ef3af16aae9bfb78a3bb46d8098cb3a15b (diff) | |
download | txr-aa355befc89d94f3f43d3ae4124f7d048fb4e588.tar.gz txr-aa355befc89d94f3f43d3ae4124f7d048fb4e588.tar.bz2 txr-aa355befc89d94f3f43d3ae4124f7d048fb4e588.zip |
* 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.
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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)); |