File: iott_setterm.c

package info (click to toggle)
fis-gtm 7.1-006-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 32,908 kB
  • sloc: ansic: 344,906; asm: 5,184; csh: 4,859; sh: 2,000; awk: 294; makefile: 73; sed: 13
file content (121 lines) | stat: -rwxr-xr-x 2,969 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/****************************************************************
 *								*
 * Copyright (c) 2001-2023 Fidelity National Information	*
 * Services, Inc. and/or its subsidiaries. All rights reserved.	*
 *								*
 *	This source code contains the intellectual property	*
 *	of its copyright holder(s), and is made available	*
 *	under a license.  If you do not know the terms of	*
 *	the license, please stop and do not read further.	*
 *								*
 ****************************************************************/

#include "mdef.h"

#include <errno.h>

#include "gtm_termios.h"
#include "gtm_signal.h"	/* for SIGPROCMASK used inside Tcsetattr */

#include "io.h"
#include "iosp.h"
#include "iottdef.h"
#include "gtmio.h"
#include "iott_setterm.h"
#include "eintr_wrappers.h"
#include "gtm_isanlp.h"

error_def(ERR_TCSETATTR);

void iott_setterm(io_desc *ioptr)
{
	int		status;
	int		save_errno;
	struct termios	t;
	d_tt_struct	*tt_ptr;

	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, save_errno);
	if (0 != status)
	{
		if (gtm_isanlp(tt_ptr->fildes) == 0)
			RTS_ERROR_CSA_ABT(NULL, VARLSTCNT(4) ERR_TCSETATTR, 1, tt_ptr->fildes, save_errno);
	}
	return;
}


/* These routines are here because it is frightfully important to keep them
   in synch with setterm.  When they get out of line, a r x:0 causes your
   terminal to be unreachable thereafter.
*/

/* iott_mterm sets the inter-character timer (t.c_cc[VTIME]) to 0.0 seconds
   so that a read with a zero timeout (ie.  Read x:0) will not wait.
*/

void iott_mterm(io_desc *ioptr)
{
	int		status;
	int		save_errno;
	struct termios	t;
	d_tt_struct	*tt_ptr;

	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);
#ifdef __MVS__
		t.c_cc[VTIME] = 1;
#else
		t.c_cc[VTIME] = 0;
#endif
		t.c_cc[VMIN] = 0;
	}
	t.c_iflag &= ~(ICRNL);
	Tcsetattr(tt_ptr->fildes, TCSANOW, &t, status, save_errno);
	if (0 != status)
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_TCSETATTR, 1, tt_ptr->fildes, save_errno);
	return;
}


/* iott_rterm restores the inter-character timer (t.c_cc[VTIME]) to 0.8 seconds
*/

void iott_rterm(io_desc *ioptr)
{
	int		status;
	int		save_errno;
	struct termios	t;
	d_tt_struct  	*tt_ptr;

	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, save_errno);
	if (0 != status)
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_TCSETATTR, 1, tt_ptr->fildes, save_errno);
	return;
}