OUTPUT-PORT/BYTES-WRITTEN.
#| -*-Scheme-*-
-$Id: genio.scm,v 1.44 2006/10/25 02:50:01 cph Exp $
+$Id: genio.scm,v 1.45 2006/10/25 03:15:09 cph Exp $
Copyright 1991,1993,1995,1996,1999,2002 Massachusetts Institute of Technology
Copyright 2003,2004,2005,2006 Massachusetts Institute of Technology
(SET-INPUT-TERMINAL-MODE ,generic-io/set-input-terminal-mode)))
(ops:out1
`((BUFFERED-OUTPUT-BYTES ,generic-io/buffered-output-bytes)
+ (BYTES-WRITTEN ,generic-io/bytes-written)
(CLOSE-OUTPUT ,generic-io/close-output)
(FLUSH-OUTPUT ,generic-io/flush-output)
(OUTPUT-COLUMN ,generic-io/output-column)
(define (generic-io/buffered-output-bytes port)
(output-buffer-start (port-output-buffer port)))
+
+(define (generic-io/bytes-written port)
+ (output-buffer-total (port-output-buffer port)))
\f
;;;; Non-specific operations
(sink #f read-only #t)
(bytes #f read-only #t)
start
+ total
encode
denormalize
column)
(%make-output-buffer sink
(make-string byte-buffer-length)
0
+ 0
(name->encoder coder-name)
(name->denormalizer
(line-ending ((sink/get-channel sink))
(eq? (output-buffer-denormalize ob) binary-denormalizer))
(define (encode-char ob char)
- (set-output-buffer-start!
- ob
- (fix:+ (output-buffer-start ob)
- ((output-buffer-encode ob) ob (char->integer char)))))
+ (let ((n-bytes ((output-buffer-encode ob) ob (char->integer char))))
+ (set-output-buffer-start! ob (fix:+ (output-buffer-start ob) n-bytes))
+ (set-output-buffer-total! ob (fix:+ (output-buffer-total ob) n-bytes))))
(define (set-output-buffer-coding! ob coding)
(set-output-buffer-encode! ob (name->encoder coding))
(define (write-substring:string ob string start end)
(if (output-buffer-in-8-bit-mode? ob)
(let ((bv (output-buffer-bytes ob))
- (be (output-buffer-end ob)))
+ (be (output-buffer-end ob))
+ (ok
+ (lambda (n)
+ (set-output-buffer-total! ob (fix:+ (output-buffer-total ob) n))
+ n)))
(let loop ((i start) (bi (output-buffer-start ob)))
(if (fix:< i end)
(if (fix:< bi be)
(begin
(set-output-buffer-start! ob be)
(let ((n (drain-output-buffer ob)))
- (cond ((not n) (and (fix:> i start) (fix:- i start)))
- ((fix:> n 0) (loop i (output-buffer-start ob)))
- (else (fix:- i start))))))
+ (cond ((not n)
+ (and (fix:> i start)
+ (ok (fix:- i start))))
+ ((fix:> n 0)
+ (loop i (output-buffer-start ob)))
+ (else
+ (ok (fix:- i start)))))))
(begin
(set-output-buffer-start! ob bi)
- (fix:- end start)))))
+ (ok (fix:- end start))))))
(let loop ((i start))
(if (fix:< i end)
(if (write-next-char ob (string-ref string i))
#| -*-Scheme-*-
-$Id: output.scm,v 14.36 2005/03/30 03:50:18 cph Exp $
+$Id: output.scm,v 14.37 2006/10/25 03:15:15 cph Exp $
Copyright 1986,1987,1988,1989,1990,1991 Massachusetts Institute of Technology
Copyright 1992,1993,1999,2001,2002,2003 Massachusetts Institute of Technology
-Copyright 2004,2005 Massachusetts Institute of Technology
+Copyright 2004,2005,2006 Massachusetts Institute of Technology
This file is part of MIT/GNU Scheme.
(define (output-port/fresh-line port)
((port/operation/fresh-line port) port))
+(define (output-port/line-start? port)
+ ((port/operation/line-start? port) port))
+
(define (output-port/flush-output port)
((port/operation/flush-output port) port))
(let ((operation (port/operation port 'OUTPUT-COLUMN)))
(and operation
(operation port))))
+
+(define (output-port/bytes-written port)
+ (let ((operation (port/operation port 'BYTES-WRITTEN)))
+ (and operation
+ (operation port))))
\f
;;;; High level
#| -*-Scheme-*-
-$Id: port.scm,v 1.43 2006/10/04 05:51:55 savannah-arthur Exp $
+$Id: port.scm,v 1.44 2006/10/25 03:15:22 cph Exp $
Copyright 1991,1992,1993,1994,1997,1999 Massachusetts Institute of Technology
Copyright 2001,2002,2003,2004,2005,2006 Massachusetts Institute of Technology
(write-wide-substring #f read-only #t)
(write-external-substring #f read-only #t)
(fresh-line #f read-only #t)
+ (line-start? #f read-only #t)
(flush-output #f read-only #t)
(discretionary-flush-output #f read-only #t))
(op 'WRITE-WIDE-SUBSTRING)
(op 'WRITE-EXTERNAL-SUBSTRING)
(op 'FRESH-LINE)
+ (op 'LINE-START?)
(op 'FLUSH-OUTPUT)
(op 'DISCRETIONARY-FLUSH-OUTPUT)))))
\f
(not (char=? (port/previous port) #\newline)))
(write-char port #\newline)
0)))
+ ((LINE-START)
+ (lambda (port)
+ (if (port/previous port)
+ (char=? (port/previous port) #\newline)
+ 'UNKNOWN)))
((FLUSH-OUTPUT) flush-output)
((DISCRETIONARY-FLUSH-OUTPUT) discretionary-flush-output)
(else (op name))))))
(define-port-operation write-wide-substring)
(define-port-operation write-external-substring)
(define-port-operation fresh-line)
+ (define-port-operation line-start?)
(define-port-operation flush-output)
(define-port-operation discretionary-flush-output))
#| -*-Scheme-*-
-$Id: runtime.pkg,v 14.599 2006/10/24 04:08:58 cph Exp $
+$Id: runtime.pkg,v 14.600 2006/10/25 03:15:29 cph Exp $
Copyright 1988,1989,1990,1991,1992,1993 Massachusetts Institute of Technology
Copyright 1994,1995,1996,1997,1998,1999 Massachusetts Institute of Technology
port-type/discretionary-flush-output
port-type/flush-output
port-type/fresh-line
+ port-type/line-start?
port-type/operation
port-type/operation-names
port-type/operations
port/operation/discretionary-flush-output
port/operation/flush-output
port/operation/fresh-line
+ port/operation/line-start?
port/operation/write-char
port/operation/write-external-substring
port/operation/write-substring
flush-output
fresh-line
newline
+ output-port/bytes-written
output-port/column
output-port/discretionary-flush
output-port/flush-output
output-port/fresh-line
+ output-port/line-start?
output-port/write-char
output-port/write-object
output-port/write-external-string