Example #1
0
void setterm(io_desc *ioptr)
{
	int		status;
	int		save_errno;
	struct termios	t;
	d_tt_struct	*tt_ptr;
	error_def(ERR_TCSETATTR);

	tt_ptr = (d_tt_struct *) ioptr->dev_sp;
	t = *tt_ptr->ttio_struct;
	if (tt_ptr->canonical)
	{	t.c_lflag &= ~(ECHO);
		t.c_lflag |= ICANON;
	}else
	{	t.c_lflag &= ~(ICANON | ECHO);
		t.c_cc[VTIME] = 8;
		t.c_cc[VMIN] = 1;
	}
	t.c_iflag &= ~(ICRNL);
	Tcsetattr(tt_ptr->fildes, TCSANOW, &t, status);
	if (0 != status)
	{
		save_errno = errno;
		if (gtm_isanlp(tt_ptr->fildes) == 0)
			rts_error(VARLSTCNT(4) ERR_TCSETATTR, 1, tt_ptr->fildes, save_errno);
	}
	return;
}
Example #2
0
void  resetterm(io_desc *iod)
{
	int		status;
	int		save_errno;
	struct termios 	t;
	d_tt_struct	*ttptr;

	ttptr =(d_tt_struct *) iod->dev_sp;
	if (ttptr->ttio_struct)
	{
	        t = *ttptr->ttio_struct;
		Tcsetattr(ttptr->fildes, TCSANOW, &t, status, save_errno);
		if (status != 0)
		{
			if (gtm_isanlp(ttptr->fildes) == 0)
				rts_error(VARLSTCNT(4) ERR_TCSETATTR, 1, ttptr->fildes, save_errno);
		}
	}
	return;
}
Example #3
0
short iott_open(io_log_name *dev_name, mval *pp, int fd, mval *mspace, int4 timeout)
{
	unsigned char	ch;
	d_tt_struct	*tt_ptr;
	io_desc		*ioptr;
	int		status;
	int		save_errno;
	int		p_offset;

	error_def(ERR_NOTERMENV);
	error_def(ERR_NOTERMENTRY);
	error_def(ERR_NOTERMINFODB);
	error_def(ERR_TCGETATTR);

	ioptr = dev_name->iod;
	if (ioptr->state == dev_never_opened)
	{
		dev_name->iod->dev_sp = (void *)malloc(sizeof(d_tt_struct) + sizeof(struct termios));
		memset(dev_name->iod->dev_sp, 0, sizeof(d_tt_struct) + sizeof(struct termios));
		tt_ptr = (d_tt_struct *)dev_name->iod->dev_sp;
		tt_ptr->ttio_struct = (struct termios *)((char *)tt_ptr + sizeof(d_tt_struct));
		tt_ptr->in_buf_sz = TTDEF_BUF_SZ;
		tt_ptr->enbld_outofbands.x = 0;
		tt_ptr->term_ctrl &= (~TRM_NOECHO);
		tt_ptr->mask_term.mask[0] = TERM_MSK;
		tt_ptr->ttybuff = (char *)malloc(IOTT_BUFF_LEN);
	}
	tt_ptr = (d_tt_struct *)dev_name->iod->dev_sp;
	p_offset = 0;
	while (*(pp->str.addr + p_offset) != iop_eol)
	{
		if ((ch = *(pp->str.addr + p_offset++)) == iop_exception)
		{
			ioptr->error_handler.len = *(pp->str.addr + p_offset);
			ioptr->error_handler.addr = (char *)(pp->str.addr + p_offset + 1);
			s2pool(&ioptr->error_handler);
			break;
		} else  if (ch == iop_canonical)
			tt_ptr->canonical = TRUE;
		else  if (ch == iop_nocanonical)
			tt_ptr->canonical = FALSE;
		p_offset += ((IOP_VAR_SIZE == io_params_size[ch]) ?
			(unsigned char)*(pp->str.addr + p_offset) + 1 : io_params_size[ch]);
	}
	if (ioptr->state != dev_open)
	{
		int	status;
		char	*env_term;

		assert(fd >= 0);
		tt_ptr->fildes = fd;
		status = tcgetattr(tt_ptr->fildes, tt_ptr->ttio_struct);
		if (0 != status)
		{
			save_errno = errno;
			if (gtm_isanlp(tt_ptr->fildes) == 0)
				rts_error(VARLSTCNT(4) ERR_TCGETATTR, 1, tt_ptr->fildes, save_errno);
		}
		if (run_time)
			setterm(ioptr);
		status = getcaps(tt_ptr->fildes);
		if (1 != status)
		{
			if (status == 0)
			{
				env_term = GETENV("TERM");
				if (!env_term)
				{
					rts_error(VARLSTCNT(1) ERR_NOTERMENV);
					env_term = "unknown";
				}
				rts_error(VARLSTCNT(4) ERR_NOTERMENTRY, 2, LEN_AND_STR(env_term));
			} else
				rts_error(VARLSTCNT(1) ERR_NOTERMINFODB);
		}
		ioptr->width = COLUMNS;
		ioptr->length = GTM_LINES;
		ioptr->wrap = (0 == AUTO_RIGHT_MARGIN) ? FALSE : TRUE; /* defensive programming; till we are absolutely, positively
									* certain that there are no uses of wrap == TRUE */
		ioptr->state = dev_open;
		tt_ptr->tbuffp = tt_ptr->ttybuff;	/* Buffer is now empty */
	}
	return TRUE;
}