summaryrefslogtreecommitdiffstats
path: root/stream.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2013-12-01 23:46:41 -0800
committerKaz Kylheku <kaz@kylheku.com>2013-12-01 23:46:41 -0800
commit980a1c1d78d838bbc13e90053ba90e02671878ae (patch)
treed059f1a9189b91205ebfb5118b4a9916383a7d76 /stream.h
parent360dc82e12c0031401b81f18e6b9108801277d69 (diff)
downloadtxr-980a1c1d78d838bbc13e90053ba90e02671878ae.tar.gz
txr-980a1c1d78d838bbc13e90053ba90e02671878ae.tar.bz2
txr-980a1c1d78d838bbc13e90053ba90e02671878ae.zip
Steps toward fixing an issue: lazy list readahead.
The problem is that accurate lazy lists are not suitable for real time use, where we want the TXR program to respond immediately to matching some datum. I'm implementing a simple, naive variant of lazy stream lists which simply populates the lazy cons by reading from the stream when the car or cdr fields are accessed. This type of stream can never be nil (empty list) even if the file is empty; in that case it will be (nil) and in general, it will have a spurious nil item at the end instead of ending in a string. (An adjustment was made in match.c to detect this; more will be needed.) I'm adding attributes to streams so streams can now have a "real-time" attribute. When a lazy string list is constructed over a real-time stream, the simple implementation is used. File streams are automatically real-time if (on Unix) they are tied to tty streams. Tail streams are also real-time. More work is needed to achieve the goal of this change, but this is a big step in the right direction. * configure: Detect isatty function. * lib.c (simple_lazy_stream_func): New static function. (lazy_stream_cons): Use simple implementation for real-time streams. * match.c (match_files): Do not call match_line_completely with a data line that is nil (as a result of simple lazy list over a real-time stream). A nil item in a lazy list of strings is treated as eof. * stream.c (real_time_k): New symbol variable. (struct strm_ops): New members: get_prop, set_prop. (struct stdio_handle): New member: is_real_time. (stdio_get_prop, stdio_set_prop): New static function. (stdio_ops, tail_ops, pipe_ops): stdio_get_prop and stdio_set_prop funtions wired in. (make_stdio_stream_common): Attribute streams as real-time if they are tty devices. (make_tail_stream): Tail streams are real-time attributed. (stream_set_prop, real_time_stream_p): New functions. (stream_init): Initialize real_time_k. * stream.h (real_time_k): Declared. (real_time_stream_p, stream_set_prop): Likewise.
Diffstat (limited to 'stream.h')
-rw-r--r--stream.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/stream.h b/stream.h
index efd3e912..6bf7c5e6 100644
--- a/stream.h
+++ b/stream.h
@@ -31,6 +31,7 @@ extern val dev_k, ino_k, mode_k, nlink_k, uid_k;
extern val gid_k, rdev_k, size_k, blksize_k, blocks_k;
extern val atime_k, mtime_k, ctime_k;
extern val from_start_k, from_current_k, from_end_k;
+extern val real_time_k;
extern val s_ifmt, s_iflnk, s_ifreg, s_ifblk, s_ifdir;
extern val s_ifchr, s_ififo, s_isuid, s_isgid, s_isvtx, s_irwxu;
@@ -48,6 +49,8 @@ val make_strlist_output_stream(void);
val get_list_from_stream(val);
val make_dir_stream(DIR *);
val streamp(val obj);
+val real_time_stream_p(val obj);
+val stream_set_prop(val stream, val ind, val prop);
val close_stream(val stream, val throw_on_error);
val get_line(val);
val get_char(val);