summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--stream.c26
-rw-r--r--txr.136
2 files changed, 51 insertions, 11 deletions
diff --git a/stream.c b/stream.c
index 469416be..d8babd36 100644
--- a/stream.c
+++ b/stream.c
@@ -71,7 +71,7 @@ val print_flo_precision_s, print_flo_digits_s, print_flo_format_s;
val print_base_s;
val from_start_k, from_current_k, from_end_k;
-val real_time_k, name_k, addr_k, fd_k;
+val real_time_k, name_k, addr_k, fd_k, byte_oriented_k;
val format_s;
val stdio_stream_s;
@@ -364,6 +364,7 @@ struct stdio_handle {
val mode; /* used by tail */
unsigned is_rotated; /* used by tail */
unsigned is_real_time;
+ unsigned is_byte_oriented;
#if HAVE_SOCKETS
val family;
val type;
@@ -579,16 +580,22 @@ static val stdio_get_prop(val stream, val ind)
return h->descr;
} else if (ind == fd_k) {
return h->f ? num(fileno(h->f)) : nil;
+ } else if (ind == byte_oriented_k) {
+ return h->is_byte_oriented ? t : nil;
}
return nil;
}
static val stdio_set_prop(val stream, val ind, val prop)
{
+ struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle);
+
if (ind == real_time_k) {
- struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle);
h->is_real_time = prop ? 1 : 0;
return t;
+ } else if (ind == byte_oriented_k) {
+ h->is_byte_oriented = prop ? 1 : 0;
+ return t;
}
return nil;
}
@@ -688,8 +695,17 @@ static val stdio_get_char(val stream)
return rcyc_pop(&h->unget_c);
if (h->f) {
- wint_t ch = utf8_decode(&h->ud, stdio_get_char_callback,
- coerce(mem_t *, h->f));
+ wint_t ch;
+
+ if (h->is_byte_oriented) {
+ ch = se_getc(h->f);
+ if (ch == 0)
+ ch = 0xDC00;
+ } else {
+ ch = utf8_decode(&h->ud, stdio_get_char_callback,
+ coerce(mem_t *, h->f));
+ }
+
return (ch != WEOF) ? chr(ch) : stdio_maybe_read_error(stream);
}
return stdio_maybe_read_error(stream);
@@ -1307,6 +1323,7 @@ static val make_stdio_stream_common(FILE *f, val descr, struct cobj_ops *ops)
#else
h->is_real_time = 0;
#endif
+ h->is_byte_oriented = 0;
#if HAVE_SOCKETS
h->family = nil;
h->type = nil;
@@ -3898,6 +3915,7 @@ void stream_init(void)
name_k = intern(lit("name"), keyword_package);
addr_k = intern(lit("addr"), keyword_package);
fd_k = intern(lit("fd"), keyword_package);
+ byte_oriented_k = intern(lit("byte-oriented"), keyword_package);
format_s = intern(lit("format"), user_package);
stdio_stream_s = intern(lit("stdio-stream"), user_package);
#if HAVE_SOCKETS
diff --git a/txr.1 b/txr.1
index 51d6c1df..cc7390e4 100644
--- a/txr.1
+++ b/txr.1
@@ -34627,15 +34627,37 @@ value. If the stream does not understand a property, nil is returned, which is
also returned if the property exists, but its value happens to be
.codn nil .
-Properties are currently used for marking certain streams as "real-time" (see
-the
+The
+.code :name
+property is widely supported by streams of various types. It associates
+the stream with a name. This property is not always modifiable.
+
+File, process and stream socket I/O streams have a
+.code :fd
+property which can be accessed, but not modified. It retrieves
+the same value as the
+.code stream-fd
+function.
+
+The "real time"
+property supported by these streams, connected with the
.code real-time-stream-p
-function above), and also for setting the priority at
-which messages are reported to syslog by the
-.code *stdlog*
-stream (see
+function, also appears as the
+.code :real-time
+property.
+
+I/O streams also have a property called
+.code :byte-oriented
+which, if set, suppresses the decoding of UTF-8 on character input. Rather,
+each byte of the file corresponds directly to one character. Bytes
+in the range 1 to 255 correspond to the character code points U+0001
+to U+00FF. Byte value 0 is mapped to the code point U+DC00.
+
+The logging priority of the
.code *stdlog*
-in the Unix Syslog section).
+syslog stream is controlled by the
+.code :prio
+property.
If
.meta stream