Deutsch   English   Français   Italiano  
<vs0258$ncqh$1@news.xmission.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: getchar implementation without GNUishms
Date: Wed, 26 Mar 2025 05:08:56 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vs0258$ncqh$1@news.xmission.com>
References: <slrnvu4v4s.1su2.anthk@openbsd.home> <vrua0r$3d1du$1@dont-email.me> <vrvv30$spj$1@nnrp.usenet.blueworldhosting.com>
Injection-Date: Wed, 26 Mar 2025 05:08:56 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
	logging-data="766801"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
Bytes: 2422
Lines: 43

In article <vrvv30$spj$1@nnrp.usenet.blueworldhosting.com>,
Arti F. Idiot <addr@is.invalid> wrote:
>On 3/25/25 7:10 AM, Janis Papanagnou wrote:
>> On 25.03.2025 10:51, anthk wrote:
>>> Hello the guy from https://luxferre.top and gopher://hoi.st
>>> has pretty interesting stuff, such as
>>>
>>> [ shell specific or other tries to emulate some getchar function ]
>>>
>>> Could it be possible to implement a true portable getchar?
>> 
>> Those who think that getchar is a useful function may implement that
>> natively in Awk. (It avoids external dependencies and all the issues
>> that the posted/quoted code has made obvious.)
>
>
>I know you can iterate over input strings a character at a time in AWK
>but I don't think you can read a single character from stdin without
>also providing a newline via ENTER, which is perhaps what the OP was
>actually wanting to do?

This works for me:

--- Cut Here ---
@load "call_any"
BEGIN {
    system("stty raw -echo");
    s = " "
    n = call_any("iisi","read",0,s,1)
    system("stty sane");
    print "s =","|"s"|","n =",n
    }
--- Cut Here ---

Note: I could probably change the system() calls to use call_any() as well.

It looks like tcgetattr(3) and tcsetattr(3) are the currently accepted ways
of doing this.  I've used those calls in my C programs, so would have to
adapt that to work with call_any().

-- 
Liberals live in a fantasy world where (street) criminals are good people.

Conservatives live in a fantasy world where businessmen are good people.