From 6fedaccfe790e33bb7a71d8a5f776e4cfa7e6c62 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 26 Nov 2013 22:45:42 -0800 Subject: Stream-seeking functionality. Bugfix in stdio_flush: check FILE * handle for null. Minor cleanups. * eval.c (eval_init): Register seek_stream as intrinsic. * stream.c (from_start_k, from_current_k, from_end_k): New symbol variables. (strm_whence): New enum. (strm_ops): New member, seek. (stdio_maybe_write_error): Renamed to stdio_maybe_error; takes new string argument to describe action. (stdio_put_string, stdio_put_char, stdio_put_byte): Updated call to stdio_maybe_error. (stdio_flush): Updated call to stdio_maybe_error. Check handle for null. (stdio_seek): New static function. (stdio_ops): Added stdio_seek. (pipe_ops, string_in_ops, byte_in_ops, string_out_ops, strlist_out_ops, dir_ops): Added explicit zero entries and comments for unimplemented functions. (seek_stream): New function. (stream_init): New keyword symbols interned. * stream.h (from_start_k, from_current_k, from_end_k): New variables declared. (dev_k, ino_k, mode_k, nlink_k, uid_k, gid_k, rdev_k, size_k, blksize_k, blocks_k, atime_k, mtime_k, ctime_k, s_ifmt, s_iflnk, s_ifreg, s_ifblk, s_ifdir, s_ifchr, s_ififo, s_isuid, s_isgid, s_isvtx, s_irwxu, s_irusr, s_iwusr, s_ixusr, s_irwxg, s_irgrp, s_iwgrp): Existing extern variables declared. (seek_stream): New function declared. * txr.1: Documented seek-stream. --- txr.1 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index 571e2271..6d98aab7 100644 --- a/txr.1 +++ b/txr.1 @@ -10241,6 +10241,40 @@ Calling this function causes all accumulated data inside to be passed to the operating system. If called on streams for which this function is not meaningful, it does nothing. +.SS Function seek-stream + +.TP +Syntax: + + (seek-stream ) + +.TP +Description: + +The seek-stream function is meaningful for file streams. It changes the +current read/write position within . It can also be used +to determine the current position: see the notes about the +return value below. + +The argument is a positive or negative integer which gives a +displacement that is measured from the point identified by the +argument. + +Note that for text files, there isn't necessarily a 1:1 correspondence between +characters and positions due to line-ending conversions and conversions +to and from UTF-8. + +The argument is one of three keywords: :from-start, :from-current +and :from-end. These denote the start of the file, the current position +and the end of the file. + +If is zero, and is :from-current, then +seek-stream returns the current absolute position within the +stream, if it can successfully obtain it. Otherwise, it +returns t if it is successful. + +On failure, it throws an exception of type stream-error. + .SH FILESYSTEM ACCESS .SS Function stat -- cgit v1.2.3