How to read characters from stdin?
jlyonm <jlyonm-g/[email protected]> Mon, 04 May 2026 15:46:58 +0000
| Newsgroups | gmane.comp.lang.forth.gforth |
|---|---|
| Message-ID | <cbNgpmtZUHOtN-ZCKrj9uPIjdwcmIHFAr5cVOd3diKGej7LxKVhFfwmCWVJUFbcsLMduLDvwHWmv6KZZhMIqsS9f-erG_pF297PHt6eIDrk=@protonmail.com> |
This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------5c00c8332036a4f336716a24950db9865595b1be8e4ebad387a84036e281f4a4 Content-Type: multipart/mixed;boundary=---------------------5e36110244f01639c9d8c81b8f86f698 -----------------------5e36110244f01639c9d8c81b8f86f698 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain;charset=utf-8 Hello, I am just starting to learn Forth. I appreciate the efforts put to produce= and maintain this nice package. I wanted to write a simple program that reads input from stdin, and writes= it out to stdout doing a little translation. At first I thought I could make use of key and key?, but I see the documen= tation indicates this can't be used on stdin. So, I tried read-line. This works mostly. I can read characters one at a t= ime, and the main program's begin ... while loop will terminate at EOF. Bu= t, as one would expect by something called read-line, it consumes returns = on its own. I'd like to receive those. Then I tried a combination of read-file and read-line with: chr 0 stdin read-line hoping to get the flag to know whether the end of the input has been reach= ed (which read-file doesn't provide), but this doesn't work either, and th= e program hangs indefinitely. In case it matters, I'm actually running this on a phone running Lineage O= S (ostensibly Android) under termux. I don't think it effects the behavior= . I did find something on rosettacode: https://rosettacode.org/wiki/Copy_stdin_to_stdout#Forth So I am currently using slurp-fid to dump all of stdin into memory, and th= en reading a character out and updating the address pointer as I go. But I was wondering if it is possible to do this from just reading charact= ers directly from the file descriptor. Is there some other check for EOF I= missed in the documentation? Thanks for reading. -----------------------5e36110244f01639c9d8c81b8f86f698-- --------5c00c8332036a4f336716a24950db9865595b1be8e4ebad387a84036e281f4a4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: ProtonMail wrsEARYKAG0Fgmn4v2QJEOn4466WHOmBRRQAAAAAABwAIHNhbHRAbm90YXRp b25zLm9wZW5wZ3Bqcy5vcmd19ESEA/wSy8lJD6jVmpLG/dPwIbKurvbTi/9t 1xof+hYhBC7jCpHYV23hmwoUnen4466WHOmBAADdTgD7B6Thz/+8m3HXJGmK MWZUpHsG8Cc1jDYYM/rX++tKayQBALOtfiijbyl8ES6E3D8rGVYPa3wkDN/y YHj6ykaQX84M =lM4C -----END PGP SIGNATURE----- --------5c00c8332036a4f336716a24950db9865595b1be8e4ebad387a84036e281f4a4--