Terminal modes in Ultrix's System V emulation

Jonathan Ballard asmodeus at tree.UUCP
Thu Oct 6 09:15:05 AEST 1988


In article <829 at philmds.UUCP>, leo at philmds.UUCP (Leo de Wit) writes:
> 
> When porting a database application to Ultrix (Oracle dbms), I found
> out we had to use System V libraries (grrr 8-), since the Oracle
> libraries depended upon them. I don't want to discuss whether Oracle's
...  [stuff deleted]
> The problem:
> I want to read characters from a terminal, without echo and not having
> to wait for a newline. After each character I might do some processing,
> based on the character read. The old solution did something along the
...[more stuff deleted]

This code here is what I used also...

> 
> #include <sys/termio.h>
> 
>     struct termio newbuf, oldbuf; /* oldbuf needed for restoring afterwards */
> 
>     ioctl(0,TCGETA,&oldbuf);
>     newbuf = oldbuf;
>     newbuf.c_lflag &= ~(ECHO|ICANON);
>     ioctl(0,TCSETA,&newbuf);
> 


Have you triing using a switch() to post process what you need?  This  is
what i use.   If your just looking for a return you could do something
like...
 
	c=getchar();
	switch(c) {
		case RETURN : 	printf("\n");
				break;
		default : 	printf(c);
				break;
	}


RETURN could be the real value or '\n' if you want to go by how the
compiler would implement it.
This is how I get the terminal set...

#include <termio.h>   /* include needed */

struct termio  save, term; /* global varibles used */


	/* check and see if terminal */
	if ( ioctl (0, TCGETA, &term) == -1 ) {
		fprintf (stderr, "standard input not a tty\n");
		exit (1);
	}
	/* set terminal for one-char input */
	save = term;
	term.c_lflag &= ~ICANON;  /* single key input ready */
	term.c_lflag &= ~ECHO;	  /* turn off echo */
	term.c_cc[VMIN] = 1;	/* minimal of one key for input being ready */
	term.c_cc[VTIME] = 0;   /*  turn off time-out */
	ioctl (0, TCSETA, &term);


	/* to reset old tty state */
	ioctl (0, TCSETA, &save);

That seems to be the usual way other programmers use too... 
Well.. hope it helps...
-- 
         _
   |    | \	 	UUCP e-mail:  ..!{csusac,pacbell}!sactoh0!jhballar
   |    |-< 	    		      ..!{csusac,pacbell}!sactoh0!tree!asmodeus
|__|on  |_/allard  		      ..!csusac!tree!asmodeus 



More information about the Comp.unix.questions mailing list