summaryrefslogtreecommitdiffstats
path: root/lib/libncurses/lib_options.c
blob: 7aefe960d6c6babdb8d19919d3701966889d8d81 (plain)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

/* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for   *
*  details. If they are missing then this copy is in violation of    *
*  the copyright conditions.                                        */

/*
**	lib_options.c
**
**	The routines to handle option setting.
**
*/

#include <stdlib.h>
#include "terminfo.h"
#include "curses.priv.h"

int idlok(WINDOW *win, int flag)
{
	T(("idlok(%x,%d) called", win, flag));

	if (flag == FALSE) {
		win->_idlok = FALSE;
		return OK;
	}

	if ((insert_line || parm_insert_line) && (delete_line || parm_delete_line)) {
		win->_idlok = TRUE;
	}
	return OK;
}


int clearok(WINDOW *win, int flag)
{
	T(("clearok(%x,%d) called", win, flag));

   	if (win == curscr)
	    newscr->_clear = flag;
	else
	    win->_clear = flag;
	return OK;
}


int leaveok(WINDOW *win, int flag)
{
	T(("leaveok(%x,%d) called", win, flag));

   	win->_leave = flag;
   	if (flag == TRUE)
   		curs_set(0);
   	else
   		curs_set(1);
	return OK;
}


int scrollok(WINDOW *win, int flag)
{
	T(("scrollok(%x,%d) called", win, flag));

   	win->_scroll = flag;
	return OK;
}

int halfdelay(int t)
{
	T(("halfdelay(%d) called", t));

	if (t < 1 || t > 255)
		return ERR;

	cbreak();
	SP->_cbreak = t+1;
	return OK;
}

int nodelay(WINDOW *win, int flag)
{
	T(("nodelay(%x,%d) called", win, flag));

   	if (flag == TRUE)
		win->_delay = 0;
	else win->_delay = -1;
	return OK;
}

int notimeout(WINDOW *win, bool f)
{
	T(("notimout(%x,%d) called", win, f));

	win->_notimeout = f;
	return OK;
}

int wtimeout(WINDOW *win, int delay)
{
	T(("wtimeout(%x,%d) called", win, delay));

	win->_delay = delay;
	return OK;
}

static void init_keytry();
static void add_to_try(char *, short);

int keypad(WINDOW *win, int flag)
{
	T(("keypad(%x,%d) called", win, flag));

   	win->_use_keypad = flag;

	if (flag  &&  keypad_xmit)
	    putp(keypad_xmit);
	else if (! flag  &&  keypad_local)
	    putp(keypad_local);

	if (SP->_keytry == UNINITIALISED)
	    init_keytry();
	return OK;
}



int meta(WINDOW *win, int flag)
{
	T(("meta(%x,%d) called", win, flag));

	win->_use_meta = flag;

	if (flag  &&  meta_on)
	    putp(meta_on);
	else if (! flag  &&  meta_off)
	    putp(meta_off);
	return OK;
}

/*
**      init_keytry()
**
**      Construct the try for the current terminal's keypad keys.
**
*/


static struct  try *newtry;

static void init_keytry()
{
    newtry = NULL;

#include "keys.tries"

	SP->_keytry = newtry;
}


static void add_to_try(char *str, short code)
{
static bool     out_of_memory = FALSE;
struct try      *ptr, *savedptr;

	if (! str  ||  out_of_memory)
	    	return;

	if (newtry != NULL)    {
    	ptr = savedptr = newtry;

       	for (;;) {
	       	while (ptr->ch != (unsigned char) *str
		       &&  ptr->sibling != NULL)
	       		ptr = ptr->sibling;

	       	if (ptr->ch == (unsigned char) *str) {
	    		if (*(++str)) {
	           		if (ptr->child != NULL)
	           			ptr = ptr->child;
               		else
	           			break;
	    		} else {
	        		ptr->value = code;
					return;
	   			}
			} else {
	    		if ((ptr->sibling = (struct try *) malloc(sizeof *ptr)) == NULL) {
	        		out_of_memory = TRUE;
					return;
	    		}

	    		savedptr = ptr = ptr->sibling;
	    		ptr->child = ptr->sibling = NULL;
	    		ptr->ch = *str++;
	    		ptr->value = (short) NULL;

           		break;
	       	}
	   	} /* end for (;;) */
	} else {   /* newtry == NULL :: First sequence to be added */
	    	savedptr = ptr = newtry = (struct try *) malloc(sizeof *ptr);

	    	if (ptr == NULL) {
	        	out_of_memory = TRUE;
				return;
	    	}

	    	ptr->child = ptr->sibling = NULL;
	    	ptr->ch = *(str++);
	    	ptr->value = (short) NULL;
	}

	    /* at this point, we are adding to the try.  ptr->child == NULL */

	while (*str) {
	   	ptr->child = (struct try *) malloc(sizeof *ptr);

	   	ptr = ptr->child;

	   	if (ptr == NULL) {
	       	out_of_memory = TRUE;

			ptr = savedptr;
			while (ptr != NULL) {
		    	savedptr = ptr->child;
		    	free(ptr);
		    	ptr = savedptr;
			}

			return;
		}

	   	ptr->child = ptr->sibling = NULL;
	   	ptr->ch = *(str++);
	   	ptr->value = (short) NULL;
	}

	ptr->value = code;
	return;
}

int typeahead(int fd)
{

	T(("typeahead(%d) called", fd));
	SP->_checkfd = fd;
	return OK;
}

int intrflush(WINDOW *win, bool flag)
{
	T(("intrflush(%x, %d) called", win, flag));
	return OK;
}
OpenPOWER on IntegriCloud