jh05629@phlux.UUCP (Jonas Heyman) (06/23/91)
Howdy
I have a piece of code here that I can't get to work properly.
The program sends a escape sequence to the attached terminal in
order to identify type, vt220 or vt100 and so on.
Then it sends back a unique escape sequence for that particular terminal.
I use this in order to set up the right environment.
I put it in my .profile and look at the exit codes produced.
The problem I can't work around is that the unique reply also echo's
on stdout on my terminal, I want to swallow the characters echoed back.
Could anyone help me on this, either to point out where my program
is wrong or give me a new piece of code.
Any help is most welcome !
Thanks in advance, Jonas.
Here is what i put in my .profile:
tty|hz
if [ $? = 0 ]
then
TERM=
.
.
.
And here is the code itself:
/*
calling syntax tty|hz
exit value 0 the connected terminal doesn't respond
1 - " - is a vt 100 - 102
2 - " - vt 220 - 240
3 - " - vt 300 - 340
*/
#include <stdio.h>
#include <fcntl.h>
main()
{
char tty[ 20 ], line[ 100 ] ;
unsigned fd, xit ;
FILE *fp ;
scanf( "%s", tty ) ; /* read unix cmd tty by redirection */
fclose( stdin ) ; /* close to avoid conflicts */
fclose( stdout ) ;
fd = open( tty, O_NDELAY | O_RDWR ) ;
write( fd, "\033[c", 3 ) ; /* ESC Z does not affective on vt300*/
sleep( 1 ) ;
if ( read( fd, line, 25 ))
if ( ! strncmp( line, "\033\133?63", 5 ))
xit = 3 ; /* fraction of vt320 response */
else if ( ! strncmp( line, "\033\133?62", 5 ))
xit = 2 ; /* fraction of vt220 response */
else if ( ! strncmp( line, "\033\133?", 3 ))
xit = 1 ; /* vt100, 101, 102 response */
else
xit = 0 ; /* dumb - could be hazeltine */
else
xit = 0 ;
close( fd ) ;
exit( xit ) ;
}
--
/jonas@lkbpyr.lkb.se/