Esempio n. 1
0
File: n5.c Progetto: aksr/heirloom
void
save_tty(void)			/*save any tty settings that may be changed*/
{

#ifdef	USG
	if (tcgetattr(0, &ttys) >= 0)
		ttysave[0] = ttys.c_lflag;
#else
	if (gtty(0, &ttys[0]) >= 0)
		ttysave[0] = ttys[0].sg_flags;
	if (gtty(1, &ttys[1]) >= 0)
		ttysave[1] = ttys[1].sg_flags;
#endif	/* USG */

}
Esempio n. 2
0
void
gettmode(void)
{

#ifndef USG3TTY
	if (gtty(1, &tty) < 0)
		return;
	if (ex_ospeed != tty.sg_ospeed)
		value(SLOWOPEN) = tty.sg_ospeed < B1200;
	ex_ospeed = tty.sg_ospeed;
	normf = tty.sg_flags;
	UPPERCASE = (tty.sg_flags & LCASE) != 0;
	GT = (tty.sg_flags & XTABS) != XTABS && !XT;
	NONL = (tty.sg_flags & CRMOD) == 0;
#else
	if (tcgetattr(1, &tty) < 0)
		return;
	ex_ospeed = cfgetospeed(&tty);
	value(SLOWOPEN) = ex_ospeed < B1200;
	normf = tty;
#ifdef IUCLC
	UPPERCASE = (tty.c_iflag & IUCLC) != 0;
#endif
#ifdef TAB3
	GT = (tty.c_oflag & TABDLY) != TAB3 && !XT;
#endif
	NONL = (tty.c_oflag & ONLCR) == 0;
#endif
}
Esempio n. 3
0
File: main.c Progetto: yrchen/Athena
static void init_tty()
{
  if (gtty(1, &tty_state) < 0)
  {
    fprintf(stderr, "gtty failed\n");
    exit(-1);
  }
  memcpy(&tty_new, &tty_state, sizeof(tty_new));

//#ifdef  LINUX

  tty_new.c_lflag &= ~(ICANON | ECHO | ISIG);
  tcsetattr(1, TCSANOW, &tty_new);
  restore_tty();

//#else

//  tty_new.sg_flags |= RAW;

//#ifdef  HP_UX
//  tty_new.sg_flags &= ~(O_HUPCL | O_XTABS | LCASE | ECHO | CRMOD);
//#else
//  tty_new.sg_flags &= ~(TANDEM | CBREAK | LCASE | ECHO | CRMOD);
//#endif

  stty(1, &tty_new);
//#endif
}
Esempio n. 4
0
main()
{
	char *cp = getenv("TERM");
	char clbuf[20];
	char pcbuf[20];
	char *clbp = clbuf;
	char *pcbp = pcbuf;
	char *clear;
	char buf[1024];
	char *pc;
	struct sgttyb tty;

	gtty(1, &tty);
	ospeed = tty.sg_ospeed;
	if (cp == (char *) 0)
		exit(1);
	if (tgetent(buf, cp) != 1)
		exit(1);
	pc = tgetstr("pc", &pcbp);
	if (pc)
		PC = *pc;
	clear = tgetstr("cl", &clbp);
	if (clear)
		tputs(clear, tgetnum("li"), putchar);
	exit (clear == (char *) 0);
}
Esempio n. 5
0
void
openpl(void)
{
	if ( isatty(fileno( stdout )) ) {
		shakehands = TRUE;
		fildes = open(TERMINAL, 0);
		gtty(fildes, &sarg);
		sarg.sg_flags = sarg.sg_flags | RAW;
		stty(fildes, &sarg);
		sarg.sg_flags = sarg.sg_flags & ~RAW;
	}
	else {
		shakehands = FALSE;
	}
	buffcount = 0;
	currentx = 0;
	currenty = 0;
	buffready(8);
	putchar(ESC);
	putchar(GRAPHIC);
	putchar(DISPLAY);
	putchar('c');
	putchar(ESC);
	putchar(GRAPHIC);
	putchar(PLOT);
	putchar(BINARY);
	space(0,0,720,360);
}
Esempio n. 6
0
File: term.c Progetto: glamrock/eBBS
get_tty()
{   
    if(gtty(1,&tty_state) < 0) {
        return(-1) ;
    }
    return 1 ;
}
Esempio n. 7
0
char *get_tty_password(const char *opt_message)
{
#ifdef HAVE_GETPASS
  char *passbuff;
#else /* ! HAVE_GETPASS */
  TERMIO org,tmp;
#endif /* HAVE_GETPASS */
  char buff[80];

  DBUG_ENTER("get_tty_password");

#ifdef HAVE_GETPASS
  passbuff = getpass(opt_message ? opt_message : "Enter password: "******"Enter password: ",stdout);
    fflush(stdout);
  }
#if defined(HAVE_TERMIOS_H)
  tcgetattr(fileno(stdin), &org);
  tmp = org;
  tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
  tmp.c_cc[VMIN] = 1;
  tmp.c_cc[VTIME] = 0;
  tcsetattr(fileno(stdin), TCSADRAIN, &tmp);
  get_password(buff, sizeof(buff)-1, fileno(stdin), isatty(fileno(stdout)));
  tcsetattr(fileno(stdin), TCSADRAIN, &org);
#elif defined(HAVE_TERMIO_H)
  ioctl(fileno(stdin), (int) TCGETA, &org);
  tmp=org;
  tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
  tmp.c_cc[VMIN] = 1;
  tmp.c_cc[VTIME]= 0;
  ioctl(fileno(stdin),(int) TCSETA, &tmp);
  get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout)));
  ioctl(fileno(stdin),(int) TCSETA, &org);
#else
  gtty(fileno(stdin), &org);
  tmp=org;
  tmp.sg_flags &= ~ECHO;
  tmp.sg_flags |= RAW;
  stty(fileno(stdin), &tmp);
  get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout)));
  stty(fileno(stdin), &org);
#endif
  if (isatty(fileno(stdout)))
    fputc('\n',stdout);
#endif /* HAVE_GETPASS */

  DBUG_RETURN(my_strdup(buff,MYF(MY_FAE)));
}
Esempio n. 8
0
static void set_raw_tty(int mode)
{
	Terminal in_raw;

	if(mode != tty_mode && mode != -1) {
		if(!handlerIsSet) {
			/* Determine existing TTY settings */
			gtty (STDIN, &in_orig);
			need_tty_reset = 1;

			/* Restore original TTY settings on exit */
			atexit(cleanup_tty);
			handlerIsSet = 1;
		}


		setup_signal();
		signal (SIGALRM, (SIG_CAST) tty_time_out);
	
		/* Change STDIN settings to raw */

		gtty (STDIN, &in_raw);
		if(mode) {
#ifdef USE_SGTTY
			in_raw.sg_flags |= CBREAK;
#else
			in_raw.c_lflag &= ~ICANON;
			in_raw.c_cc[VMIN]=1;
			in_raw.c_cc[VTIME]=0;			
#endif
			stty (STDIN, &in_raw);
		} else {
#ifdef USE_SGTTY
			in_raw.sg_flags &= ~CBREAK;
#else
			in_raw.c_lflag |= ICANON;
#endif
			stty (STDIN, &in_raw);
		}
		tty_mode = mode;
		discard_input(STDIN);
	}
}
Esempio n. 9
0
/*
 * This function is called once to set up the terminal device streams.
 * On VMS, it translates TT until it finds the terminal, then assigns
 * a channel to it and sets it raw. On CPM it is a no-op.
 */
ttopen()

{
#if	USG | HPUX | XENIX
	ioctl(0, TCGETA, &otermio);	/* save old settings */
	ntermio.c_iflag = 0;		/* setup new settings */
	ntermio.c_oflag = 0;
	ntermio.c_cflag = otermio.c_cflag;
	ntermio.c_lflag = 0;
	ntermio.c_line = otermio.c_line;
	ntermio.c_cc[VMIN] = 1;
	ntermio.c_cc[VTIME] = 0;
	ioctl(0, TCSETAW, &ntermio);	/* and activate them */
	kbdflgs = fcntl( 0, F_GETFL, 0 );
	kbdpoll = FALSE;
#endif

#if     V7 | BSD | SUN
        gtty(0, &ostate);                       /* save old state */
        gtty(0, &nstate);                       /* get base of new state */
        nstate.sg_flags |= RAW;
        nstate.sg_flags &= ~(ECHO|CRMOD);       /* no echo for now... */
        stty(0, &nstate);                       /* set mode */
	ioctl(0, TIOCGETC, &otchars);		/* Save old characters */
	ioctl(0, TIOCSETC, &ntchars);		/* Place new character into K */
#if	BSD
	/* provide a smaller terminal output buffer so that
	   the type ahead detection works better (more often) */
	setbuffer(stdout, &tobuf[0], TBUFSIZ); 
	signal(SIGTSTP,SIG_DFL);	/* set signals so that we can */
	signal(SIGCONT,rtfrmshell);	/* suspend & restart emacs */
#endif
#endif
	/* on all screens we are not sure of the initial position
	   of the cursor					*/
	ttrow = 999;
	ttcol = 999;
}
Esempio n. 10
0
/*
 * put terminal into screen mode.
 */
ttyinit()
{
    gtty(2, &ttybuf);
    UPPERCASE = (ttybuf.sg_flags & LCASE) != 0;
    HASTABS = (ttybuf.sg_flags & XTABS) != 0;
    NONL = (ttybuf.sg_flags & CRMOD) == 0;
    ottybuf = ttybuf;
    ttybuf.sg_flags &= ~(ECHO|CRMOD);
    ttybuf.sg_flags |= CBREAK;
    ioctl(2, TIOCSETN, &ttybuf);	/* or stty */

    putpad(TI);
    putpad(KS);	/* only needed if you use keypad */
}
Esempio n. 11
0
void init_ttymodes(int pn)
{
  int speed_code, n;

  dump_ttymodes("init_ttymodes", pn);
#ifdef UNIX
  if (pn==0) {
    fflush(stdout);
# if USE_POSIX_TERMIOS || USE_TERMIO
    tcgetattr(0, &old_modes);
    speed_code = cfgetospeed(&old_modes);
# else
#   if USE_SGTTY
      gtty(0, &old_modes);
      ioctl(0, TIOCGETC, &old_tchars);
      ioctl(0, TIOCGLTC, &old_ltchars);
      speed_code = old_modes.sg_ospeed;
#   endif
# endif
    new_modes = old_modes;
    for (n = 0; n < TABLESIZE(speeds); n++) {
      if (speeds[n].name == speed_code) {
        tty_speed = speeds[n].code;
        break;
      }
    }
  } else {
    putchar(BEL);
    fflush(stdout);
    inflush();
    new_modes = old_modes;
    sleep(2);
  }
# if USE_POSIX_TERMIOS || USE_TERMIO
  new_modes.c_iflag = BRKINT | old_modes.c_iflag;
  new_modes.c_oflag &= ~tabs;
# else /* USE_SGTTY */
  new_modes.sg_flags = old_modes.sg_flags | CBREAK;
# endif
  set_ttymodes(&new_modes);
# ifdef HAVE_FCNTL_H
#  ifndef O_NDELAY
#  define O_NDELAY O_NONBLOCK   /* O_NONBLOCK is POSIX */
#  endif
  close(2);
  open("/dev/tty", O_RDWR|O_NDELAY);
# endif
#endif /* UNIX */
  dump_ttymodes("...init_ttymodes", pn);
}
Esempio n. 12
0
static void save_tty_state (void)
{
#if defined(HAVE_TCSETATTR)
    tcgetattr(ttyfd, &termb);
    flags = termb.c_lflag;
#else
#if defined(HAVE_TERMIO_H)
    ioctl(ttyfd, TCGETA, (char *) &termb);
    flags = termb.c_lflag;
#else  /* we HAVE_STTY */
    gtty(ttyfd, &ttyb);
    flags = ttyb.sg_flags;
#endif
#endif
}
Esempio n. 13
0
openpl ()
{
	int reset();
		xnow = ynow = 0;
		OUTF = 1;
		printf("\r");
		gtty(OUTF, &ITTY);
		signal (2, reset);
		PTTY = ITTY;
		PTTY.sg_flags &= ~CRMOD;	/* don't map lf */
		/* initialize constants */
		xscale  = 4096./(HORZRESP * WIDTH);
		yscale = 4096 /(VERTRESP * HEIGHT);
		xoffset = OFFSET * HORZRESP;
		return;
}
Esempio n. 14
0
File: tty.c Progetto: sng7ca/ygg
/* [...]
 * control terminal:
 * -- checks for STTY | GTTY error;
 * -- checks for !(STTY | GTTY) error;
 * -- clears STTY/GTTY before calling stty/gtty;
 */
static int ctltty(short mn, unsigned rq, unsigned arg)
{
	if (rq & STTY) {
		/* error -- cann't set & get */
		if (rq & GTTY)	/* avoid 2-check STTY && GTTY */
			return -1;
		/* set param */
		rq &= ~STTY;
		return stty(mn, rq, arg);
	}
	if (rq & GTTY) {
		/* get param */
		rq &= ~GTTY;
		return gtty(mn, rq, arg);
	}
	/* set/get not specified */
	return -1;
}
Esempio n. 15
0
File: reset.c Progetto: dank101/3BSD
main()
{
	struct sgttyb buf;
	struct tchars tbuf;

	gtty(2, &buf);
	ioctl(2, TIOCGETC, &tbuf);
	buf.sg_flags &= ~(RAW|CBREAK|VTDELAY|ALLDELAY);
	buf.sg_flags |= XTABS|ECHO|CRMOD|ANYP;
	buf.sg_erase = chk(buf.sg_erase, '\08');	/* ^H */
	buf.sg_kill = chk(buf.sg_kill, '\30');		/* ^X */
	tbuf.t_intrc = chk(tbuf.t_intrc, '\177');	/* ^? */
	tbuf.t_quitc = chk(tbuf.t_quitc, '\34');	/* ^\ */
	tbuf.t_startc = chk(tbuf.t_startc, '\22');	/* ^Q */
	tbuf.t_stopc = chk(tbuf.t_stopc, '\24');	/* ^S */
	tbuf.t_eofc = chk(tbuf.t_eofc, '\4');		/* ^D */
	/* brkc is left alone */
	ioctl(2, TIOCSETN, &buf);
	ioctl(2, TIOCSETC, &tbuf);
}
Esempio n. 16
0
gettmode() {

	if (gtty(_tty_ch, &_tty) < 0)
		return;
	savetty();
	if (stty(_tty_ch, &_tty) < 0)
		_tty.sg_flags = _res_flg;
	ospeed = _tty.sg_ospeed;
	_res_flg = _tty.sg_flags;
	UPPERCASE = (_tty.sg_flags & LCASE) != 0;
	GT = ((_tty.sg_flags & XTABS) == 0);
	NONL = ((_tty.sg_flags & CRMOD) == 0);
	_tty.sg_flags &= ~XTABS;
	stty(_tty_ch, &_tty);
# ifdef DEBUG
	fprintf(outf, "GETTMODE: UPPERCASE = %s\n", UPPERCASE ? "TRUE":"FALSE");
	fprintf(outf, "GETTMODE: GT = %s\n", GT ? "TRUE" : "FALSE");
	fprintf(outf, "GETTMODE: NONL = %s\n", NONL ? "TRUE" : "FALSE");
	fprintf(outf, "GETTMODE: ospeed = %d\n", ospeed);
# endif
}
Esempio n. 17
0
void dump_ttymodes(char *tag, int flag)
{
#ifdef UNIX
  TTY tmp_modes;
  if (LOG_ENABLED) {
    fprintf(log_fp, "%s (%d):\n", tag, flag);
# if USE_POSIX_TERMIOS || USE_TERMIO
    tcgetattr(0, &tmp_modes);
    fprintf(log_fp, " iflag %08o\n", tmp_modes.c_iflag);
    fprintf(log_fp, " oflag %08o\n", tmp_modes.c_oflag);
    fprintf(log_fp, " lflag %08o\n", tmp_modes.c_lflag);
    if (!tmp_modes.c_lflag & ICANON) {
      fprintf(log_fp, " %d:min  =%d\n", VMIN,  tmp_modes.c_cc[VMIN]);
      fprintf(log_fp, " %d:time =%d\n", VTIME, tmp_modes.c_cc[VTIME]);
    }
# else
    gtty(0, &tmp_modes);
    fprintf(log_fp, " flags %08o\n", tmp_modes.sg_flags);
# endif
  }
#endif
}
Esempio n. 18
0
File: term.c Progetto: wtj/formosa
void
init_tty()
{
#if defined(TERMIOS)
#define stty(fd, data) tcsetattr( fd, TCSANOW, data )
#define gtty(fd, data) tcgetattr( fd, data )
#endif

	if(gtty(1,&tty_state) < 0) 
	{
		fprintf(stderr,"gtty failed\n") ;
		exit(-1) ;
	}
#if defined(TERMIOS)
    tty_state.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ISIG);
    tty_state.c_cc[ VMIN ] = 1;
    tty_state.c_cc[ VTIME ] = 0;
#else
	tty_state.sg_flags &= ~(TANDEM|CBREAK|LCASE|ECHO|CRMOD);
#endif	            
	stty(1, &tty_state);                    
}    
Esempio n. 19
0
/*
 * This function is called once to set up the terminal device streams.
 * On VMS, it translates SYS$INPUT until it finds the terminal, then assigns
 * a channel to it and sets it raw. On CPM it is a no-op.
 */
ttopen()
{
#if     AMIGA
        terminal = Open("RAW:1/1/639/199/MicroEmacs", NEW);
#endif
#if     VMS
        struct  dsc$descriptor  idsc;
        struct  dsc$descriptor  odsc;
        char    oname[40];
        int     iosb[2];
        int     status;

        odsc.dsc$a_pointer = "SYS$INPUT";
        odsc.dsc$w_length  = strlen(odsc.dsc$a_pointer);
        odsc.dsc$b_dtype   = DSC$K_DTYPE_T;
        odsc.dsc$b_class   = DSC$K_CLASS_S;
        idsc.dsc$b_dtype   = DSC$K_DTYPE_T;
        idsc.dsc$b_class   = DSC$K_CLASS_S;
        do {
                idsc.dsc$a_pointer = odsc.dsc$a_pointer;
                idsc.dsc$w_length  = odsc.dsc$w_length;
                odsc.dsc$a_pointer = &oname[0];
                odsc.dsc$w_length  = sizeof(oname);
                status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc);
                if (status!=SS$_NORMAL && status!=SS$_NOTRAN)
                        exit(status);
                if (oname[0] == 0x1B) {
                        odsc.dsc$a_pointer += 4;
                        odsc.dsc$w_length  -= 4;
                }
        } while (status == SS$_NORMAL);
        status = SYS$ASSIGN(&odsc, &iochan, 0, 0);
        if (status != SS$_NORMAL)
                exit(status);
        status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0,
                          oldmode, sizeof(oldmode), 0, 0, 0, 0);
        if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
                exit(status);
        newmode[0] = oldmode[0];
        newmode[1] = oldmode[1] | TT$M_PASSALL | TT$M_NOECHO;
        status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
                          newmode, sizeof(newmode), 0, 0, 0, 0);
        if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
                exit(status);
#endif
#if     CPM
#endif
#if     MSDOS && !__OS2__
        /* Set control-break handler    */
        int_intercept(0x23,kbd_inthandler,128);
#endif
#if     BSDUNIX
        /* Adjust output channel        */
        gtty(1, &ostate);                       /* save old state */
        gtty(1, &nstate);                       /* get base of new state */
        nstate.sg_flags |= RAW;
        nstate.sg_flags &= ~(ECHO|CRMOD);       /* no echo for now... */
        stty(1, &nstate);                       /* set mode */

#if NONBLOCK
        /* Set input to non-blocking    */
        oldstatus = fcntl(0,F_GETFL);
        fcntl(0,F_SETFL,oldstatus | FNDELAY);   /* don't block on input */
#endif
#endif

#if     linux || __OpenBSD__ || __APPLE__
        /* Adjust output channel        */
        tcgetattr(1, &ostate);                       /* save old state */
        tcgetattr(1, &nstate);                       /* get base of new state */
	cfmakeraw(&nstate);
        tcsetattr(1, TCSADRAIN, &nstate);      /* set mode */
#endif

#if NCURSES
	initscr();
	cbreak();
	noecho();

	nonl();
	intrflush(stdscr, FALSE);
	keypad(stdscr, TRUE);
#endif
}
Esempio n. 20
0
int main(int argc, char **argv)
{
	register char *namep;
	int t, f, c;
	char *ttyn;

	alarm(60);
	signal(SIGQUIT, SIG_IGN);
	signal(SIGINT, SIG_IGN);
	nice(-100);
	nice(20);
	nice(0);
	gtty(0, &ttyb);
	ttyb.sg_erase = '#';
	ttyb.sg_kill = '@';
	stty(0, &ttyb);
	for (t=3; t<20; t++)
		close(t);
	ttyn = ttyname(0);
	if (ttyn==0)
		ttyn = "/dev/tty??";

    loop:
	SCPYN(utmp.ut_name, "");
	if (argc>1) {
		SCPYN(utmp.ut_name, argv[1]);
		argc = 0;
	}
	while (utmp.ut_name[0] == '\0') {
		namep = utmp.ut_name;
		printf("login: "******"Password:"******"Login incorrect\n");
			goto loop;
		}
	}
	if(chdir(pwd->pw_dir) < 0) {
		printf("No directory\n");
		goto loop;
	}
	time(&utmp.ut_time);
	t = ttyslot();
	if (t>0 && (f = open("/etc/utmp", 1)) >= 0) {
		lseek(f, (long)(t*sizeof(utmp)), 0);
		SCPYN(utmp.ut_line, strchr(ttyn+1, '/')+1);
		write(f, (char *)&utmp, sizeof(utmp));
		close(f);
	}
	if (t>0 && (f = open("/usr/adm/wtmp", 1)) >= 0) {
		lseek(f, 0L, 2);
		write(f, (char *)&utmp, sizeof(utmp));
		close(f);
	}
	chown(ttyn, pwd->pw_uid, pwd->pw_gid);
	setgid(pwd->pw_gid);
	setuid(pwd->pw_uid);
	if (*pwd->pw_shell == '\0')
		pwd->pw_shell = "/bin/sh";
	environ = envinit;
	strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
	if ((namep = strrchr(pwd->pw_shell, '/')) == NULL)
		namep = pwd->pw_shell;
	else
		namep++;
	strcat(minusnam, namep);
	alarm(0);
	umask(02);
	showmotd();
	strcat(maildir, pwd->pw_name);
	if(access(maildir,4)==0) {
		struct stat statb;
		stat(maildir, &statb);
		if (statb.st_size)
			printf("You have mail.\n");
	}
	signal(SIGQUIT, SIG_DFL);
	signal(SIGINT, SIG_DFL);
	execlp(pwd->pw_shell, minusnam, 0);
	printf("No shell\n");
	exit(0);
	return 0;
}
Esempio n. 21
0
int setupterm(char *termname, int filedes, int *errret)
{
    static int	_been_here = FALSE;
    char		filename1[1024];
    char		filename2[1024];
    char		*directory = SRCDIR;
    char		*terminfo;
    struct term	*term_ptr;
    char 		*rows, *cols;

    if (_been_here == FALSE) {
        _been_here = TRUE;
#ifdef TRACE
        _init_trace();
        if (_tracing)
            _tracef("setupterm(%s,%d,%x) called", termname, filedes, errret);
#endif

        if (termname == NULL)
        {
            termname = getenv("TERM");
            if (termname == NULL)
                ret_error0(-1, "TERM environment variable not set.\n");
        }

        term_ptr = (struct term *) malloc(sizeof(struct term));

        if (term_ptr == NULL)
            ret_error0(-1, "Not enough memory to create terminal structure.\n") ;

        if ((terminfo = getenv("TERMINFO")) != NULL)
            directory = terminfo;

        sprintf(filename1, "%s/%c/%s", directory, termname[0], termname);
        sprintf(filename2, "%s/%c/%s", SRCDIR, termname[0], termname);

        if (read_entry(filename1, term_ptr) < 0 &&  read_entry(filename2, term_ptr) < 0)
            ret_error(0, "'%s': Unknown terminal type.\n", termname);

        if (command_character  &&  getenv("CC"))
            do_prototype();

        cur_term = term_ptr;
        strncpy(ttytype, cur_term->term_names, NAMESIZE - 1);
        ttytype[NAMESIZE - 1] = '\0';
        cur_term->Filedes = filedes;

        /* figure out the size of the screen */

        rows = getenv("LINES");
        if (rows != (char *)NULL)
            LINES = atoi(rows);

        cols = getenv("COLUMNS");
        if (cols != (char *)NULL)
            COLS = atoi(cols);

        if (_use_env == FALSE)
            if (lines > 0 && columns > 0) {
                LINES = lines;
                COLS  = columns;
            }
        /* use envirronment; if not set then use window size */
#ifdef TRACE
        _tracef("using environment to find screen size");
#endif
        if (LINES <= 0 || COLS <= 0) {
            if (resize(filedes) == 1) {
                fprintf(stderr, "can't find the screen size");
                exit(1);
            }
        }
        lines = LINES;
        columns = COLS;

#ifdef TRACE
        _tracef("screen size is %dx%d and %dx%d", COLS, LINES, columns, lines);
#endif

#ifdef TERMIOS
        tcgetattr(filedes, &cur_term->Ottyb);
        if (cur_term->Ottyb.c_oflag & XTABS)
            tab = back_tab = NULL;

        cur_term->Nttyb = cur_term->Ottyb;
        cur_term->Nttyb.c_oflag &= ~XTABS;
#else
        gtty(filedes, &cur_term->Ottyb);
        if (cur_term->Ottyb.sg_flags & XTABS)
            tab = back_tab = NULL;

        cur_term->Nttyb = cur_term->Ottyb;
        cur_term->Nttyb.sg_flags &= ~XTABS;
#endif

        def_prog_mode();

        if (errret)
            *errret = 1;
    }
    return(1);
}