Make CRLF handling in accept more robust.
This commit is contained in:
@ -103,8 +103,15 @@ e: test-accept
|
|||||||
in: 1234567890xxxxxx
|
in: 1234567890xxxxxx
|
||||||
pad 10 accept
|
pad 10 accept
|
||||||
pad swap type cr
|
pad swap type cr
|
||||||
out: --> 1234567890
|
out:\ --> 1234567890
|
||||||
|
out:crlf
|
||||||
out: 1234567890
|
out: 1234567890
|
||||||
|
in: foo
|
||||||
|
pad 10 accept
|
||||||
|
pad swap type cr
|
||||||
|
out:\ --> foo
|
||||||
|
out:crlf
|
||||||
|
out: foo
|
||||||
;e
|
;e
|
||||||
|
|
||||||
e: test-key
|
e: test-key
|
||||||
|
|||||||
@ -158,12 +158,16 @@ variable hld
|
|||||||
|
|
||||||
( Input )
|
( Input )
|
||||||
: raw.s depth 0 max for aft sp@ r@ cells - @ . then next ;
|
: raw.s depth 0 max for aft sp@ r@ cells - @ . then next ;
|
||||||
variable echo -1 echo ! variable arrow -1 arrow !
|
variable echo -1 echo ! variable arrow -1 arrow ! variable wascr
|
||||||
: ?echo ( n -- ) echo @ if emit else drop then ;
|
: *emit ( n -- ) dup emit 13 = if cr then ;
|
||||||
|
: ?echo ( n -- ) echo @ if *emit else drop then ;
|
||||||
: ?arrow. arrow @ if >r >r raw.s r> r> ." --> " then ;
|
: ?arrow. arrow @ if >r >r raw.s r> r> ." --> " then ;
|
||||||
|
: *key ( -- n )
|
||||||
|
begin key dup nl = wascr @ 0= and if drop 13 exit then dup until
|
||||||
|
dup 13 = wascr ! ;
|
||||||
: accept ( a n -- n ) ?arrow. 0 swap begin 2dup < while
|
: accept ( a n -- n ) ?arrow. 0 swap begin 2dup < while
|
||||||
key
|
*key
|
||||||
dup nl = over 13 = or if ?echo drop nip exit then
|
dup 13 = if ?echo drop nip exit then
|
||||||
dup 8 = over 127 = or if
|
dup 8 = over 127 = or if
|
||||||
drop over if rot 1- rot 1- rot 8 ?echo bl ?echo 8 ?echo then
|
drop over if rot 1- rot 1- rot 8 ?echo bl ?echo 8 ?echo then
|
||||||
else
|
else
|
||||||
@ -172,7 +176,7 @@ variable echo -1 echo ! variable arrow -1 arrow !
|
|||||||
then
|
then
|
||||||
repeat drop nip
|
repeat drop nip
|
||||||
( Eat rest of the line if buffer too small )
|
( Eat rest of the line if buffer too small )
|
||||||
begin key dup nl = over 13 = or if ?echo exit else drop then again
|
begin *key dup 13 = if ?echo exit else drop then again
|
||||||
;
|
;
|
||||||
200 constant input-limit
|
200 constant input-limit
|
||||||
: tib ( -- a ) 'tib @ ;
|
: tib ( -- a ) 'tib @ ;
|
||||||
|
|||||||
@ -46,6 +46,7 @@ variable expect-used variable result-used
|
|||||||
: expected ( -- a n ) expect-buffer expect-used @ ;
|
: expected ( -- a n ) expect-buffer expect-used @ ;
|
||||||
: resulted ( -- a n ) result-buffer result-used @ ;
|
: resulted ( -- a n ) result-buffer result-used @ ;
|
||||||
: out:cr nl expect-emit ;
|
: out:cr nl expect-emit ;
|
||||||
|
: out:crlf 13 expect-emit nl expect-emit ;
|
||||||
: out:\ ( "line" -- ) nl parse expect-type ;
|
: out:\ ( "line" -- ) nl parse expect-type ;
|
||||||
: out: ( "line" -- ) out:\ out:cr ;
|
: out: ( "line" -- ) out:\ out:cr ;
|
||||||
variable confirm-old-type
|
variable confirm-old-type
|
||||||
|
|||||||
@ -53,6 +53,7 @@ variable scope scope context cell - !
|
|||||||
transfer{
|
transfer{
|
||||||
xt-find& xt-hide xt-transfer
|
xt-find& xt-hide xt-transfer
|
||||||
voc-stack-end last-vocabulary notfound
|
voc-stack-end last-vocabulary notfound
|
||||||
|
*key *emit wascr
|
||||||
immediate? input-buffer ?echo ?arrow. arrow
|
immediate? input-buffer ?echo ?arrow. arrow
|
||||||
evaluate-buffer aliteral value-bind
|
evaluate-buffer aliteral value-bind
|
||||||
leaving( )leaving leaving leaving,
|
leaving( )leaving leaving leaving,
|
||||||
|
|||||||
Reference in New Issue
Block a user