[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 03/10: put-char in Scheme
From: |
Andy Wingo |
Subject: |
[Guile-commits] 03/10: put-char in Scheme |
Date: |
Fri, 3 Jun 2016 21:03:47 +0000 (UTC) |
wingo pushed a commit to branch wip-ethreads
in repository guile.
commit 05b3a5031ae0db1ab1e1a76c11dc3a0c50850956
Author: Andy Wingo <address@hidden>
Date: Wed Jun 1 23:48:08 2016 +0200
put-char in Scheme
* libguile/ports.c (scm_port_encode_char): New function.
* module/ice-9/ports.scm (port-encode-char): Export port-encode-char to
the internals module.
* module/ice-9/sports.scm (put-char): New function.
(port-bindings): Add put-char and put-string.
---
libguile/ports.c | 19 +++++++++++++++++++
module/ice-9/ports.scm | 2 ++
module/ice-9/sports.scm | 15 ++++++++++++++-
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/libguile/ports.c b/libguile/ports.c
index a14aac2..2ca20c0 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -3238,6 +3238,25 @@ SCM_DEFINE (scm_port_encode_chars, "port-encode-chars",
5, 0, 0,
}
#undef FUNC_NAME
+SCM scm_port_encode_char (SCM, SCM, SCM);
+SCM_DEFINE (scm_port_encode_char, "port-encode-char", 3, 0, 0,
+ (SCM port, SCM buf, SCM ch),
+ "")
+#define FUNC_NAME s_scm_port_encode_char
+{
+ scm_t_uint32 codepoint;
+
+ SCM_VALIDATE_OPOUTPORT (1, port);
+ SCM_VALIDATE_VECTOR (2, buf);
+ SCM_VALIDATE_CHAR (3, ch);
+
+ codepoint = SCM_CHAR (ch);
+ encode_utf32_chars (port, buf, &codepoint, 1);
+
+ return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+
void
scm_c_put_latin1_chars (SCM port, const scm_t_uint8 *chars, size_t len)
{
diff --git a/module/ice-9/ports.scm b/module/ice-9/ports.scm
index 57ecbd4..e4315bc 100644
--- a/module/ice-9/ports.scm
+++ b/module/ice-9/ports.scm
@@ -189,6 +189,7 @@ interpret its input and output."
specialize-port-encoding!
port-random-access?
port-decode-char
+ port-encode-char
port-encode-chars
port-read-buffering
port-poll
@@ -235,6 +236,7 @@ interpret its input and output."
%port-encoding
specialize-port-encoding!
port-decode-char
+ port-encode-char
port-encode-chars
port-random-access?
port-read-buffering
diff --git a/module/ice-9/sports.scm b/module/ice-9/sports.scm
index d145d07..9341d0a 100644
--- a/module/ice-9/sports.scm
+++ b/module/ice-9/sports.scm
@@ -675,9 +675,22 @@
(port-line-buffered? port))
(flush-output port))))
+(define* (put-char port char)
+ (let ((aux (port-auxiliary-write-buffer port)))
+ (set-port-buffer-cur! aux 0)
+ (port-clear-stream-start-for-bom-write port aux)
+ (port-encode-char port aux char)
+ (let ((end (port-buffer-end aux)))
+ (set-port-buffer-end! aux 0)
+ (put-bytevector port (port-buffer-bytevector aux) 0 end))
+ (when (and (eqv? char #\newline) (port-line-buffered? port))
+ (flush-output port))))
+
(define saved-port-bindings #f)
(define port-bindings
- '(((guile) read-char peek-char force-output close-port)
+ '(((guile)
+ read-char peek-char force-output close-port
+ put-char put-string)
((ice-9 binary-ports)
get-u8 lookahead-u8 get-bytevector-n
put-u8 put-bytevector)
- [Guile-commits] branch wip-ethreads created (now ddb971b), Andy Wingo, 2016/06/03
- [Guile-commits] 01/10: socket: TCP_CORK, TCP_NODELAY, Andy Wingo, 2016/06/03
- [Guile-commits] 04/10: `accept' on nonblocking socket can return #f, Andy Wingo, 2016/06/03
- [Guile-commits] 06/10: Non-blocking accept/connect Scheme support, Andy Wingo, 2016/06/03
- [Guile-commits] 05/10: Support `connect' on nonblocking sockets, Andy Wingo, 2016/06/03
- [Guile-commits] 03/10: put-char in Scheme,
Andy Wingo <=
- [Guile-commits] 07/10: add (ice-9 epoll), Andy Wingo, 2016/06/03
- [Guile-commits] 09/10: add examples/ethreads/memcached-{client, server}, Andy Wingo, 2016/06/03
- [Guile-commits] 08/10: add (ice-9 ethreads), Andy Wingo, 2016/06/03
- [Guile-commits] 10/10: add (web server ethreads), Andy Wingo, 2016/06/03
- [Guile-commits] 02/10: put-char, put-string in default namespace, Andy Wingo, 2016/06/03