Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 line
559B

  1. : (rdlnc) ( -- c )
  2. ( buffer overflow? same as if we typed a newline )
  3. IN> @ IN) = IF 0x0a ELSE KEY THEN ( c )
  4. DUP 0x0a = IF DROP 0xd THEN ( lf? same as cr )
  5. ( backspace? handle and exit )
  6. DUP BS? IF _bs EXIT THEN
  7. ( echo back )
  8. DUP EMIT ( c )
  9. ( write and advance )
  10. DUP ( keep as result ) ( c c )
  11. ( We take advantage of the fact that c's MSB is always zero and
  12. thus ! automatically null-terminates our string )
  13. IN> @ ! 1 IN> +! ( c )
  14. ( if newline, replace with zero to indicate EOL )
  15. DUP 0xd = IF DROP 0 THEN ;