mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
fixing read-line on network ports
This commit is contained in:
parent
26ceb64434
commit
104811942f
4 changed files with 9 additions and 5 deletions
4
eval.c
4
eval.c
|
@ -1309,6 +1309,10 @@ sexp sexp_get_port_fileno (sexp ctx, sexp self, sexp_sint_t n, sexp port) {
|
|||
return sexp_make_fixnum(fd);
|
||||
return SEXP_FALSE;
|
||||
}
|
||||
sexp sexp_stream_portp_op (sexp ctx, sexp self, sexp_sint_t n, sexp port) {
|
||||
sexp_assert_type(ctx, sexp_portp, SEXP_IPORT, port);
|
||||
return sexp_make_boolean(sexp_stream_portp(port));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SEXP_USE_STATIC_LIBS
|
||||
|
|
|
@ -239,6 +239,7 @@ SEXP_API sexp sexp_9p_respond (sexp ctx, sexp self, sexp_sint_t n, sexp req, sex
|
|||
SEXP_API sexp sexp_9p_responderror (sexp ctx, sexp self, sexp_sint_t n, sexp req);
|
||||
#else
|
||||
SEXP_API sexp sexp_get_port_fileno (sexp ctx, sexp self, sexp_sint_t n, sexp port);
|
||||
SEXP_API sexp sexp_stream_portp_op (sexp ctx, sexp self, sexp_sint_t n, sexp port);
|
||||
#endif
|
||||
|
||||
#if SEXP_USE_SIMPLIFY
|
||||
|
|
|
@ -77,7 +77,8 @@
|
|||
|
||||
(define (%read-line n in)
|
||||
(cond
|
||||
((port-fileno in)
|
||||
((stream-port? in) ;;(port-fileno in)
|
||||
(port-line-set! in (+ 1 (port-line in)))
|
||||
(%%read-line n in))
|
||||
(else
|
||||
(let ((out (open-output-string)))
|
||||
|
@ -105,13 +106,10 @@
|
|||
(let ((in (if (pair? o) (car o) (current-input-port)))
|
||||
(n (if (and (pair? o) (pair? (cdr o))) (car (cdr o)) 8192)))
|
||||
(let ((res (%read-line n in)))
|
||||
(cond-expand
|
||||
(string-streams
|
||||
(port-line-set! in (+ 1 (port-line in)))))
|
||||
(if (not res)
|
||||
eof
|
||||
(let ((len (string-length res)))
|
||||
(cond
|
||||
(cond ;; strip crlf
|
||||
((and (> len 0) (eqv? #\newline (string-ref res (- len 1))))
|
||||
(if (and (> len 1) (eqv? #\return (string-ref res (- len 2))))
|
||||
(substring res 0 (- len 2))
|
||||
|
|
|
@ -258,6 +258,7 @@ _OP(SEXP_OPC_SETTER, SEXP_OP_SLOTN_SET, 4, 0, SEXP_VOID, _I(SEXP_OBJECT), _I(SEX
|
|||
#include "opt/plan9-opcodes.c"
|
||||
#else
|
||||
_FN1(_I(SEXP_OBJECT), _I(SEXP_IPORT), "port-fileno", 0, sexp_get_port_fileno),
|
||||
_FN1(_I(SEXP_BOOLEAN), _I(SEXP_IPORT), "stream-port?", 0, sexp_stream_portp_op),
|
||||
#endif
|
||||
_FN0(_I(SEXP_ENV), "current-environment", 0, sexp_current_environment),
|
||||
#if SEXP_USE_MODULES
|
||||
|
|
Loading…
Add table
Reference in a new issue