Re: How to read characters from stdin?
jlyonm <jlyonm-g/[email protected]> Tue, 05 May 2026 16:40:25 +0000
| Newsgroups | gmane.comp.lang.forth.gforth |
|---|---|
| Message-ID | <26JKj8wGsV7HWyDeq0Q7Pf9TKUmhP-So_zinnLYZBUfnN71aB4FRMJ08XAhzw66ejaJil-fCVSjthyBzf4SiAoHdykvcjUbG5PcJjBtm6bE=@protonmail.com> |
This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------eaaa3b9e1c8b8526c76145ed6af861c9e6914f2229e9504d90e7283f2881729b Content-Type: multipart/mixed;boundary=---------------------f8ecfb19643243e2b2e8492370e10a9f -----------------------f8ecfb19643243e2b2e8492370e10a9f Content-Transfer-Encoding: quoted-printable Content-Type: text/plain;charset=utf-8 On Tuesday, May 5th, 2026 at 3:54 PM, Bernd Paysan <[email protected]> wrote= : > Am Dienstag, 5. Mai 2026, 17:31:53 Mitteleurop=C3=A4ische Sommerzeit sch= rieb jlyonm = > via Gforth discussion and announcements: > > On Tuesday, May 5th, 2026 at 1:55 AM, Mark J. Reed <[email protected]= m> = > wrote: > > > On Mon, May 4, 2026 at 11:53=E2=80=AFAM jlyonm <jlyonm-g/[email protected]= m> wrote: > > > > I wanted to write a simple program that reads input from stdin, an= d > > > > writes it out to stdout doing a little translation.> = > > > Ok, so does your program need to respond to each individual key pres= s, or > > > can it read a whole line and then process that all at once? > > I'm reading one character at a time. > > = > > > > At first I thought I could make use of key and key?, but I see the > > > > documentation indicates this can't be used on stdin.> = > > > I'm confused - don't those words work exclusively on stdin? > > = > > In the Gforth info document, section 2.6 it says, "If you pipe into Gf= orth, > > your program should read with `read-file' or `read-line' from `stdin'. > > `Key' does not recognize the end of input." This is exactly what I am > > seeing with my little program. It never exits. > = > KEY does recognize end of file, but it throws an exception instead of pa= ssing a = > flag. > = > For that purpose, there is now (in the development snapshot) KEY-IOR, wh= ich = > returns a negative value for end of file or other exceptions. > = > $ echo "check this" | gforth -e ": test begin key-ior dup 0>=3D while h.= repeat = > drop ; test cr bye" > $63 $68 $65 $63 $6B $20 $74 $68 $69 $73 $A > = > End of file is error code -512 (which translates into =E2=80=9Csuccess=E2= =80=9D if thrown, as = > there is no errno assigned to EOF). > Thanks for the extra details. I did not know about any of this. > > > Just use stdin file-eof? ? > > = > > Thanks a lot, this is exactly what I needed, and makes it work. How do= es one > > find that word? It is not in the info docs, nor can I find it online. = I > > wonder what else I am unaware of. > = > FILE-EOF? is documented in the current development manual. > = > https://net2o.de/gforth/ > = > Go to the index, search for EOF, and second hit is it. > = I am definitely bookmarking this page. I only knew about these pages on Gf= orth: https://www.gnu.org/software/gforth/ https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/ > > > > In case it matters, I'm actually running this on a phone running L= ineage > > > > OS (ostensibly Android) under termux. I don't think it effects the > > > > behavior. > = > The termux version is likely 0.7.3, and the development documentation ca= n be = > significantly ahead of the functions available there. > You are correct, termux has Gforth 0.7.3. I should have checked and provid= ed the version. > -- = > Bernd Paysan > "If you want it done right, you have to do it yourself" > net2o id: kQusJzA;7*?t=3Duy@X}1GWr!+0qqp_Cn176t4(dQ* > https://net2o.de/ > = -----------------------f8ecfb19643243e2b2e8492370e10a9f Content-Type: application/pgp-keys; filename="publickey - jlyonm-g/[email protected] - 0x2EE30A91.asc"; name="publickey - jlyonm-g/[email protected] - 0x2EE30A91.asc" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="publickey - jlyonm-g/[email protected] - 0x2EE30A91.asc"; name="publickey - jlyonm-g/[email protected] - 0x2EE30A91.asc" LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tCgp4ak1FWmVTaEFCWUpLd1lCQkFI YVJ3OEJBUWRBd0ltdkFvNnkwYm1pN2lmVk94ZFhac3NDL0ZPRTVxeXEKbzl2RHhXVWxDUEhOTFdw c2VXOXViVUJ3Y205MGIyNXRZV2xzTG1OdmJTQThhbXg1YjI1dFFIQnliM1J2CmJtMWhhV3d1WTI5 dFBzS01CQkFXQ2dBK0JZSmw1S0VBQkFzSkJ3Z0prT240NDY2V0hPbUJBeFVJQ2dRVwpBQUlCQWhr QkFwc0RBaDRCRmlFRUx1TUtrZGhYYmVHYkNoU2Q2ZmpqcnBZYzZZRUFBS2lqQVFETWl0dnkKc0xw UUlFMkNsWjV2VGhxSFRrMVdLdTFCc01BNGxpZmV1R0xFR1FEK1B1YVN5UUxmVTRHS1ZBcU1JcWp0 CnJHODd0MDkxTlllRHlLNXU2eThiZXc3T09BUmw1S0VBRWdvckJnRUVBWmRWQVFVQkFRZEFZUmdM WDFQagova0s0cC9mdFBuUnJUZkd2VG51eitGOXUyTExDUlBpS0tIRURBUWdId25nRUdCWUtBQ29G Z21Ya29RQUoKa09uNDQ2NldIT21CQXBzTUZpRUVMdU1La2RoWGJlR2JDaFNkNmZqanJwWWM2WUVB QUczdEFQNHdaUC9BCmVHQW5GbUdqTFRZeDN1TlBWdDlPUXM2RmtEV1hvU3IwUXZQMFJ3RC9jbWNO eWZhUmorcnlpeTlMaXBtLwoyb0hvd09PL2NudUZUVmpMc0w3TVVnVT0KPWxjU3IKLS0tLS1FTkQg UEdQIFBVQkxJQyBLRVkgQkxPQ0stLS0tLQo= -----------------------f8ecfb19643243e2b2e8492370e10a9f-- --------eaaa3b9e1c8b8526c76145ed6af861c9e6914f2229e9504d90e7283f2881729b Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: ProtonMail wrsEARYKAG0Fgmn6HWkJEOn4466WHOmBRRQAAAAAABwAIHNhbHRAbm90YXRp b25zLm9wZW5wZ3Bqcy5vcmcX96cGTIqP66B+3XAt1OCaN1ebgmku6EpUPseK tOOI2BYhBC7jCpHYV23hmwoUnen4466WHOmBAADp3wEAwQvur42J+8TfmvFb VzDninOLkCX/5xWk9UlI67W8VlsBAIvtjRwl4GP5pXC0cWarGkOTbOcF9dt3 yTOmi58reoIP =fzBB -----END PGP SIGNATURE----- --------eaaa3b9e1c8b8526c76145ed6af861c9e6914f2229e9504d90e7283f2881729b--