[comp.unix.questions] no echo?

wswietse@eutrc3.UUCP (Wietse Venema) (01/22/88)

In article <128@dcrbg1.UUCP>, bcf2303@dcrbg1.UUCP (Wing Chow) writes:
> 
>       can you tell me how to avoid 'echoing' back to the user what he/she
> is typing in?
> 
>     thanks again for any help as i am new to unix and c.

Questions of this nature often show up in the news group comp.unix.questions.

Try system("stty -echo"); it should work on all unixes, tho it not
very efficiently. Try `man tty' for a more efficient implementation.

ok@quintus.UUCP (Richard A. O'Keefe) (01/25/88)

In article <173@eutrc3.UUCP>, wswietse@eutrc3.UUCP (Wietse Venema) writes:
> In article <128@dcrbg1.UUCP>, bcf2303@dcrbg1.UUCP (Wing Chow) writes:
> > can you tell me how to avoid 'echoing' back to the user what he/she
> > is typing in?
> Questions of this nature often show up in the news group comp.unix.questions.
> Try system("stty -echo"); it should work on all unixes, tho it not
> very efficiently. Try `man tty' for a more efficient implementation.

(1) If you want a method which works under other operating systems,
    find out about Curses.  The functions
	initscr();	/* Start Curses up */
	noecho();	/* Turn echoing off */

	echo();		/* Turn echoing on */
	endwin();	/* Shut Curses down */
    are the ones you want.  Curses is available under VMS, and there
    are several emulations of it around for IBM PCs (there was source
    code for one in Dr Dobbs last year).

(2) Whatever you do, DON'T forget to turn echoing back on again!
    system("stty echo") is the complement to system("stty -echo").
    The easiest way to manage this is to write yourself a function

	void my_exit(n)
	    int n;
	    {
		echo();		/* or whatever */
		endwin();	/* other shutting down */
		/* delete any scratch files you have open */
		exit(n);
	    }

	my_handler()
	    {
		my_exit(1);
	    }
		
	main()
	    {
		...				/* catch all the signals */
		signal(SIGQUIT, my_handler);	/* that terminate programs */
		...				/* and make them call your */
		signal(SIGTERM, my_handler);	/* graceful-exit routine */
		...
		initscr();
		...
	    }

    In any program which creates scratch files you should be doing
    something like this anyway.  It's a bit of a pain, but believe
    me, it's more of a pain to have someone explain your faults
    when a program of yours leaves their terminal in a strange
    state and they don't know how to get it back.