staload "libc/SATS/stdio.sats"
extern fun getword {lim:int | lim >= 2} {l:addr}
(pf: !b0ytes lim @ l >> strbuf lim @ l | word: ptr l, lim: int lim): void
implement getword {lim} {l} (pf | word, lim) = let
var c: int val () = loop (c) where {
fun loop (c: &int? >> int): void = let
val () = c := getchar1 ()
in
if (c >= 0) then begin
if char_isspace (char_of_int1 c) then loop (c) else ()
end end } prval () = pf := bytes_v_of_b0ytes_v (pf)
var i: natLt lim = 0
val () = if c >= 0 then begin
if char_isalpha (char_of_int c) then let
prval (pf1, pf2) = array_v_uncons {byte} (pf)
val () = (!word := byte_of_int c)
val nLeft = loop
(pf2 | word + sizeof<byte>, lim - 2) where {
fun loop {n:nat} {l:addr} .<n>.
(pf: !bytes (n+1) @ l | p: ptr l, n: int n): natLte n =
if n = 0 then 0 else let
val c = getchar1 ()
in
if c < 0 then n else begin
if char_isalnum (char_of_int c) then let
prval (pf1, pf2) = array_v_uncons {byte} (pf)
val () = (!p := byte_of_int c)
val nLeft = loop (pf2 | p + sizeof<byte>, n-1)
val () = pf := array_v_cons {byte} (pf1, pf2)
in
nLeft
end else begin
n end end end } prval () = pf := array_v_cons {byte} (pf1, pf2)
in
i := 1 + nLeft
end end in
bytes_strbuf_trans (pf | word, size1_of_int1 i)
end
#define BUFSZ 16
implement main (argc, argv) = let
var !p_buf with pf_buf = @[byte][BUFSZ]()
val () = getword (pf_buf | p_buf, BUFSZ)
val () = print_string (__cast p_buf) where {
extern castfn __cast (p: ptr): string
} val () = print_newline ()
prval () = pf_buf := bytes_v_of_strbuf_v (pf_buf)
in
end