summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog18
-rw-r--r--stream.c28
-rw-r--r--stream.h2
-rw-r--r--syslog.c2
4 files changed, 45 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 07f901d8..6b0dcb93 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/stream.c b/stream.c
index 5a5d3f74..67765e8a 100644
--- a/stream.c
+++ b/stream.c
@@ -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);
diff --git a/stream.h b/stream.h
index 0748a00c..36236622 100644
--- a/stream.h
+++ b/stream.h
@@ -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;
diff --git a/syslog.c b/syslog.c
index 36edb2d7..39581d34 100644
--- a/syslog.c
+++ b/syslog.c
@@ -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;
}