diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | eval.c | 6 | ||||
-rw-r--r-- | stream.c | 11 | ||||
-rw-r--r-- | txr.1 | 33 |
4 files changed, 40 insertions, 22 deletions
@@ -1,5 +1,17 @@ 2014-02-18 Kaz Kylheku <kaz@kylheku.com> + The mode argument in some stream-opening functions becomes optional. + + * eval.c (eval_init): Change registration for open_file, open_tail + and open_command. + + * stream.c (open_file, open_tail, open_command): mode_str argument + defaulted. + + * txr.1: Updated. + +2014-02-18 Kaz Kylheku <kaz@kylheku.com> + * stream.c (open_tail): Fix 2013-12-02 regression: seek_to_end_p argument being ignored, with the behavior being no initial seek to the end. @@ -2952,9 +2952,9 @@ void eval_init(void) reg_var(intern(lit("s-ixoth"), user_package), &s_ixoth); reg_fun(intern(lit("open-directory"), user_package), func_n1(open_directory)); - reg_fun(intern(lit("open-file"), user_package), func_n2(open_file)); - reg_fun(intern(lit("open-tail"), user_package), func_n3(open_tail)); - reg_fun(intern(lit("open-command"), user_package), func_n2(open_command)); + reg_fun(intern(lit("open-file"), user_package), func_n2o(open_file, 1)); + reg_fun(intern(lit("open-tail"), user_package), func_n3o(open_tail, 1)); + reg_fun(intern(lit("open-command"), user_package), func_n2o(open_command, 1)); reg_fun(intern(lit("open-pipe"), user_package), func_n2(open_command)); reg_fun(intern(lit("open-process"), user_package), func_n3o(open_process, 2)); reg_fun(intern(lit("remove-path"), user_package), func_n1(remove_path)); @@ -2071,7 +2071,7 @@ val open_directory(val path) val open_file(val path, val mode_str) { - FILE *f = w_fopen(c_str(path), c_str(mode_str)); + FILE *f = w_fopen(c_str(path), c_str(default_arg(mode_str, lit("r")))); if (!f) uw_throwf(file_error_s, lit("error opening ~a: ~a/~s"), @@ -2082,19 +2082,20 @@ val open_file(val path, val mode_str) val open_tail(val path, val mode_str, val seek_end_p) { - FILE *f = w_fopen(c_str(path), c_str(mode_str)); + val mode = default_arg(mode_str, lit("r")); + FILE *f = w_fopen(c_str(path), c_str(mode)); struct stdio_handle *h; val stream; unsigned long state = 0; - if (f && seek_end_p) + if (f && default_bool_arg(seek_end_p)) if (fseek(f, 0, SEEK_END) < 0) uw_throwf(file_error_s, lit("error seeking to end of ~a: ~a/~s"), path, num(errno), string_utf8(strerror(errno)), nao); stream = make_tail_stream(f, path); h = (struct stdio_handle *) stream->co.handle; - h->mode = mode_str; + h->mode = mode; if (!f) tail_strategy(stream, &state); return stream; @@ -2102,7 +2103,7 @@ val open_tail(val path, val mode_str, val seek_end_p) val open_command(val path, val mode_str) { - FILE *f = w_popen(c_str(path), c_str(mode_str)); + FILE *f = w_popen(c_str(path), c_str(default_arg(mode_str, lit("r")))); if (!f) uw_throwf(file_error_s, lit("error opening pipe ~a: ~a/~s"), @@ -11598,13 +11598,14 @@ The . and .. entries in Unix filesystems are not skipped. .TP Syntax: - (open-file <path> <mode-string>) + (open-file <path> [<mode-string>]) .TP Description: The open-file function creates a stream connected to the file which is located at the given <path>, which is a string. + The <mode-string> argument is a string which uses the same conventions as the mode argument of the C language fopen function. The mode string determines whether the stream is an input stream @@ -11612,12 +11613,14 @@ or output stream. Note that the "b" mode is not supported. Whether a stream is text or binary depends on which operations are invoked on it. +If the <mode-string> argument is omitted, the mode "r" is used. + .SS Function open-tail .TP Syntax: - (open-tail <path> <mode-string> <seek-to-end-p>) + (open-tail <path> [ [<mode-string>] <seek-to-end-p> ]) .TP Description: @@ -11625,19 +11628,18 @@ Description: The open-tail function creates a tail stream connected to the file which is located at the given <path>. The <mode-string> argument is a string which uses the same conventions as the mode argument of the C language fopen function. -The mode string determines whether the stream is an input stream -or output stream. Note that the "b" mode is not supported. -Whether a stream is text or binary depends on which operations -are invoked on it. +If it is missing, it defaults to "r". Note that the "b" mode is not supported. +Whether a stream is text or binary depends on which operations are invoked on +it. The <seek-to-end-p> argument is a boolean which determines whether the initial -read/write position is at the start of the file, or just past the end. This -argument only makes a difference if the file exists at the time open-tail is -called. If the file does not exist, and is later created, then the tail stream -will follow that file from the beginning. In other words, <seek-to-end-p> -controls whether the tail stream reads all the existing data in the file, if -any, or whether it reads only newly added data from approximately the time the -stream is created. +read/write position is at the start of the file, or just past the end. +It defaults to nil. This argument only makes a difference if the file exists +at the time open-tail is called. If the file does not exist, and is later +created, then the tail stream will follow that file from the beginning. In +other words, <seek-to-end-p> controls whether the tail stream reads all the +existing data in the file, if any, or whether it reads only newly added data +from approximately the time the stream is created. A tail stream has special semantics with regard to reading at the end of file. A tail stream never reports an end-of-file condition; instead @@ -11658,7 +11660,7 @@ changes the current working directory, and the path name is relative. .TP Syntax: - (open-command <system-command> <mode-string>) + (open-command <system-command> [<mode-string>]) (open-process <command> <mode-string> [<argument-strings>]) .TP @@ -11669,6 +11671,9 @@ with the TXR program. Both functions return a unidirectional stream for communicating with these programs: either an output stream, or an input stream, depending on the contents of <mode-string>. +In open-command, the <mode-string> argument is optional, defaulting to +the value "r" if it is missing. + The open-command function accepts, via the <system-command> string parameter, a system command, which is in a system-dependent syntax. On a POSIX system, this would be in the POSIX Shell Command Language. |