diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2013-12-13 22:35:31 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2013-12-13 22:35:31 -0800 |
commit | f8ffbad0cec3ff0be1376a6352fe63a3c5e5f361 (patch) | |
tree | f872eed68a69c5dd2cb921315da224f2c0bbe29f | |
parent | 097cf5fd7b8ea700b6012cd22cc56268695a5248 (diff) | |
download | txr-f8ffbad0cec3ff0be1376a6352fe63a3c5e5f361.tar.gz txr-f8ffbad0cec3ff0be1376a6352fe63a3c5e5f361.tar.bz2 txr-f8ffbad0cec3ff0be1376a6352fe63a3c5e5f361.zip |
New stream property: name. Some streams can report
their name: some kind of string.
* stream.c (name_k): New variable.
(null_get_prop): New static function.
(null_ops): Wire null_get_prop into ops structure.
(stdio_get_prop): Report h->descr as name.
(string_in_get_prop): New function.
(string_in_ops): Wire string_in_get_prop into ops structure.
(stream_init): Initialize name_k.
* stream.h (name_k): Declared.
* syslog.c (syslog_get_prop): Report "syslog" as
stream name.
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | stream.c | 28 | ||||
-rw-r--r-- | stream.h | 2 | ||||
-rw-r--r-- | syslog.c | 2 |
4 files changed, 45 insertions, 5 deletions
@@ -1,5 +1,23 @@ 2013-12-13 Kaz Kylheku <kaz@kylheku.com> + New stream property: name. Some streams can report + their name: some kind of string. + + * stream.c (name_k): New variable. + (null_get_prop): New static function. + (null_ops): Wire null_get_prop into ops structure. + (stdio_get_prop): Report h->descr as name. + (string_in_get_prop): New function. + (string_in_ops): Wire string_in_get_prop into ops structure. + (stream_init): Initialize name_k. + + * stream.h (name_k): Declared. + + * syslog.c (syslog_get_prop): Report "syslog" as + stream name. + +2013-12-13 Kaz Kylheku <kaz@kylheku.com> + * signal.c (sig_handler): Pass two arguments to signal handler rather than 1. The new argument is the value t, telling the handler that it's asynchronously invoked in @@ -59,7 +59,7 @@ val dev_k, ino_k, mode_k, nlink_k, uid_k; val gid_k, rdev_k, size_k, blksize_k, blocks_k; val atime_k, mtime_k, ctime_k; val from_start_k, from_current_k, from_end_k; -val real_time_k; +val real_time_k, name_k; val s_ifmt, s_ifsock, s_iflnk, s_ifreg, s_ifblk, s_ifdir; val s_ifchr, s_ififo, s_isuid, s_isgid, s_isvtx, s_irwxu; @@ -76,6 +76,13 @@ static void null_stream_print(val stream, val out) format(out, lit("#<~s null>"), stream->co.cls, nao); } +static val null_get_prop(val stream, val ind) +{ + if (ind == name_k) + return lit("null-stream"); + return nil; +} + static struct strm_ops null_ops = { { cobj_equal_op, null_stream_print, @@ -91,7 +98,7 @@ static struct strm_ops null_ops = { 0, /* close, */ 0, /* flush, */ 0, /* seek, */ - 0, /* get_prop, */ + null_get_prop, 0, /* set_prop */ }; @@ -267,9 +274,12 @@ static val stdio_seek(val stream, cnum offset, enum strm_whence whence) static val stdio_get_prop(val stream, val ind) { + struct stdio_handle *h = (struct stdio_handle *) stream->co.handle; + if (ind == real_time_k) { - struct stdio_handle *h = (struct stdio_handle *) stream->co.handle; return h->is_real_time ? t : nil; + } else if (ind == name_k) { + return h->descr; } return nil; } @@ -630,6 +640,15 @@ static val string_in_get_char(val stream) return nil; } +static val string_in_get_prop(val stream, val ind) +{ + if (ind == name_k) { + val pair = (val) stream->co.handle; + return format(nil, lit("string-stream (~s)"), car(pair), nao); + } + return nil; +} + static struct strm_ops string_in_ops = { { cobj_equal_op, cobj_print_op, @@ -645,7 +664,7 @@ static struct strm_ops string_in_ops = { 0, /* close */ 0, /* flush */ 0, /* TODO: seek */ - 0, /* get_prop */ + string_in_get_prop, 0 /* set_prop */ }; @@ -2038,6 +2057,7 @@ void stream_init(void) from_current_k = intern(lit("from-current"), keyword_package); from_end_k = intern(lit("from-end"), keyword_package); real_time_k = intern(lit("real-time"), keyword_package); + name_k = intern(lit("name"), keyword_package); s_ifmt = num(S_IFMT); s_iflnk = num(S_IFLNK); s_ifreg = num(S_IFREG); s_ifblk = num(S_IFBLK); s_ifdir = num(S_IFDIR); @@ -52,7 +52,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 real_time_k, name_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; @@ -191,6 +191,8 @@ static val syslog_get_prop(val stream, val ind) if (ind == prio_k) { val cell = (val) stream->co.handle; return car(cell); + } else if (ind == name_k) { + return lit("syslog"); } return nil; } |