[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 09/09: put-string in Scheme
From: |
Andy Wingo |
Subject: |
[Guile-commits] 09/09: put-string in Scheme |
Date: |
Wed, 1 Jun 2016 10:11:30 +0000 (UTC) |
wingo pushed a commit to branch master
in repository guile.
commit 9454068a54a4e9e84db61dc42d9a5d7a544a7ece
Author: Andy Wingo <address@hidden>
Date: Wed Jun 1 12:01:16 2016 +0200
put-string in Scheme
* module/ice-9/ports.scm: Export port-encode-chars and
port-clear-stream-start-for-bom-write via the internals module.
* module/ice-9/sports.scm (put-string): New function.
---
module/ice-9/ports.scm | 4 ++++
module/ice-9/sports.scm | 22 ++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/module/ice-9/ports.scm b/module/ice-9/ports.scm
index 3fc2f64..68afed1 100644
--- a/module/ice-9/ports.scm
+++ b/module/ice-9/ports.scm
@@ -182,10 +182,12 @@ interpret its input and output."
port-read
port-write
port-clear-stream-start-for-bom-read
+ port-clear-stream-start-for-bom-write
%port-encoding
specialize-port-encoding!
port-random-access?
port-decode-char
+ port-encode-chars
port-read-buffering
port-poll
port-read-wait-fd
@@ -227,9 +229,11 @@ interpret its input and output."
port-read
port-write
port-clear-stream-start-for-bom-read
+ port-clear-stream-start-for-bom-write
%port-encoding
specialize-port-encoding!
port-decode-char
+ port-encode-chars
port-random-access?
port-read-buffering
port-poll
diff --git a/module/ice-9/sports.scm b/module/ice-9/sports.scm
index 86d9a5b..d145d07 100644
--- a/module/ice-9/sports.scm
+++ b/module/ice-9/sports.scm
@@ -64,6 +64,7 @@
get-bytevector-n
put-u8
put-bytevector
+ put-string
%read-line
read-line
@@ -653,6 +654,27 @@
(define* (%read-line port)
(read-line port 'split))
+(define* (put-string port str #:optional (start 0)
+ (count (- (string-length str) start)))
+ (let* ((aux (port-auxiliary-write-buffer port))
+ (pos (port-buffer-position aux))
+ (line (port-position-line pos)))
+ (set-port-buffer-cur! aux 0)
+ (port-clear-stream-start-for-bom-write port aux)
+ (let lp ((encoded 0))
+ (when (< encoded count)
+ (let ((encoded (+ encoded
+ (port-encode-chars port aux str
+ (+ start encoded)
+ (- count encoded)))))
+ (let ((end (port-buffer-end aux)))
+ (set-port-buffer-end! aux 0)
+ (put-bytevector port (port-buffer-bytevector aux) 0 end)
+ (lp encoded)))))
+ (when (and (not (eqv? line (port-position-line pos)))
+ (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-commits] branch master updated (47918f3 -> 9454068), Andy Wingo, 2016/06/01
- [Guile-commits] 06/09: Add scm_c_put_escaped_char, scm_c_can_put_char, Andy Wingo, 2016/06/01
- [Guile-commits] 05/09: iprin1 uses scm_c_put_string, Andy Wingo, 2016/06/01
- [Guile-commits] 01/09: port_clear_stream_start_for_bom_write refactor, Andy Wingo, 2016/06/01
- [Guile-commits] 09/09: put-string in Scheme,
Andy Wingo <=
- [Guile-commits] 02/09: Add port-line-buffered?, Andy Wingo, 2016/06/01
- [Guile-commits] 04/09: print_normal_symbol uses new port functions, Andy Wingo, 2016/06/01
- [Guile-commits] 08/09: Rework text encoding to be more Scheme-friendly, Andy Wingo, 2016/06/01
- [Guile-commits] 07/09: Simplify string, symbol, char display/write impls, Andy Wingo, 2016/06/01
- [Guile-commits] 03/09: Beginnings of supporting encoding text in ports.c, Andy Wingo, 2016/06/01