[comp.lang.icon] non-echoed input

R.J.Hare@edinburgh.ac.uk (01/18/91)

I am trying to enter a parameter to an Icon program which I don't want echoing
(it's a password). I'm sure I should be able to do this either with getch() or
reads(,1) and then writes(\b*) or something similar, but I can't get it to go.
Has anyone got a solution to this oroblem?
 
Thanks.
 
Roger Hare.
 
PS: I am running on a Unix machine.

goer%sophist@GARGOYLE.UCHICAGO.EDU (Richard Goerwitz) (01/19/91)

> I am trying to enter a parameter to an Icon program which I don't want echoing
> (it's a password). I'm sure I should be able to do this either with getch() or
> reads(,1) and then writes(\b*) or something similar, but I can't get it to go.
> Has anyone got a solution to this problem?
	 
If you are using Unix, you won't be able to access getch().  It can't be done
portably.  You'll have to do a system() of some kind.  E.g.:

	system("stty -echo")
	read(&input)
	system("stty echo")

Difficulty:  What if, for some reason the system() fails?  Oh no!  Your
password gets echoed!  There's no way to test whether system() forked
a shell, and that shell couldn't execute the command.  You can't tell
whether the command worked or not using pipes, for the same reason.  All
you get is a diagnostic written to stderr by the shell, I believe.  Hmmm.
Maybe you can do this:

        instty := open("stty -echo 2>&1","pr")
        if ("" ~== !instty) then
	    stop("Can't seem to reset your tty to no echo mode.")
        close(instty)
        read(&input)

Then do the same sort of thing to reset to echo mode.

I have an implementation of getch() for UNIX around, but it's not per-
fect.  And it suffers from the same problem as above.

Anyone have any bright ideas, short of hacking a stub that will do an
extcall to stty, and then recompiling an idiosyncratic interpreter?

-Richard