File: CursesVar.c

package info (click to toggle)
libcurses-perl 1.37-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 932 kB
  • sloc: ansic: 9,143; perl: 1,432; makefile: 12
file content (270 lines) | stat: -rw-r--r-- 5,009 bytes parent folder | download | duplicates (5)
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*  This file can be automatically generated; changes may be lost.
**
**
**  CursesVar.c -- the variables
**
**  This is an inclusion for Curses.c
**
**  Copyright (c) 1994-2000  William Setzer
**
**  You may distribute under the terms of either the Artistic License
**  or the GNU General Public License, as specified in the README file.
*/

XS(XS_Curses_LINES)
{
    dXSARGS;
#ifdef C_LINES
    c_exactargs("LINES", items, 0);
    {
	ST(0) = sv_newmortal();
	sv_setiv(ST(0), (IV)LINES);
    }
    XSRETURN(1);
#else
    c_var_not_there("LINES");
    XSRETURN(0);
#endif
}

XS(XS_Curses_COLS)
{
    dXSARGS;
#ifdef C_COLS
    c_exactargs("COLS", items, 0);
    {
	ST(0) = sv_newmortal();
	sv_setiv(ST(0), (IV)COLS);
    }
    XSRETURN(1);
#else
    c_var_not_there("COLS");
    XSRETURN(0);
#endif
}

XS(XS_Curses_stdscr)
{
    dXSARGS;
#ifdef C_STDSCR
    c_exactargs("stdscr", items, 0);
    {
	ST(0) = sv_newmortal();
	c_window2sv(ST(0), stdscr);
    }
    XSRETURN(1);
#else
    c_var_not_there("stdscr");
    XSRETURN(0);
#endif
}

XS(XS_Curses_curscr)
{
    dXSARGS;
#ifdef C_CURSCR
    c_exactargs("curscr", items, 0);
    {
	ST(0) = sv_newmortal();
	c_window2sv(ST(0), curscr);
    }
    XSRETURN(1);
#else
    c_var_not_there("curscr");
    XSRETURN(0);
#endif
}

XS(XS_Curses_COLORS)
{
    dXSARGS;
#ifdef C_COLORS
    c_exactargs("COLORS", items, 0);
    {
	ST(0) = sv_newmortal();
	sv_setiv(ST(0), (IV)COLORS);
    }
    XSRETURN(1);
#else
    c_var_not_there("COLORS");
    XSRETURN(0);
#endif
}

XS(XS_Curses_COLOR_PAIRS)
{
    dXSARGS;
#ifdef C_COLOR_PAIRS
    c_exactargs("COLOR_PAIRS", items, 0);
    {
	ST(0) = sv_newmortal();
	sv_setiv(ST(0), (IV)COLOR_PAIRS);
    }
    XSRETURN(1);
#else
    c_var_not_there("COLOR_PAIRS");
    XSRETURN(0);
#endif
}


XS(XS_Curses_Vars_TIESCALAR)
{
    dXSARGS;
    c_exactargs("TIESCALAR", items, 2);
    {
	char *	pack = (char *)SvPV_nolen(ST(0));
	int	n    = (int)SvIV(ST(1));

	ST(0) = sv_newmortal();
	sv_setref_iv(ST(0), pack, n);
    }
    XSRETURN(1);
}

XS(XS_Curses_Vars_FETCH)
{
    dXSARGS;
    {
	int	num = (int)SvIV(SvRV((SV*)ST(0)));

	ST(0) = sv_newmortal();
	switch (num) {
	case 1:
#ifdef C_LINES
	    sv_setiv(ST(0), (IV)LINES);
#else
	    c_var_not_there("LINES");
#endif
	    break;
	case 2:
#ifdef C_COLS
	    sv_setiv(ST(0), (IV)COLS);
#else
	    c_var_not_there("COLS");
#endif
	    break;
	case 3:
#ifdef C_STDSCR
	    c_window2sv(ST(0), stdscr);
#else
	    c_var_not_there("stdscr");
#endif
	    break;
	case 4:
#ifdef C_CURSCR
	    c_window2sv(ST(0), curscr);
#else
	    c_var_not_there("curscr");
#endif
	    break;
	case 5:
#ifdef C_COLORS
	    sv_setiv(ST(0), (IV)COLORS);
#else
	    c_var_not_there("COLORS");
#endif
	    break;
	case 6:
#ifdef C_COLOR_PAIRS
	    sv_setiv(ST(0), (IV)COLOR_PAIRS);
#else
	    c_var_not_there("COLOR_PAIRS");
#endif
	    break;
	default:
	    croak("Curses::Vars::FETCH called with bad index");
	    /* NOTREACHED */
	}
    }
    XSRETURN(1);
}

XS(XS_Curses_Vars_STORE)
{
    dXSARGS;
    {
#ifdef ALLOW_VARS_STORE
	int	num = (int)SvIV((SV*)SvRV(ST(0)));

	switch (num) {
	case 1:
#ifdef C_LINES
	    LINES = (int)SvIV(ST(1));
#else
	    c_var_not_there("LINES");
#endif
	    break;
	case 2:
#ifdef C_COLS
	    COLS = (int)SvIV(ST(1));
#else
	    c_var_not_there("COLS");
#endif
	    break;
	case 3:
#ifdef C_STDSCR
	    stdscr = c_sv2window(ST(1), -1);
#else
	    c_var_not_there("stdscr");
#endif
	    break;
	case 4:
#ifdef C_CURSCR
	    curscr = c_sv2window(ST(1), -1);
#else
	    c_var_not_there("curscr");
#endif
	    break;
	case 5:
#ifdef C_COLORS
	    COLORS = (int)SvIV(ST(1));
#else
	    c_var_not_there("COLORS");
#endif
	    break;
	case 6:
#ifdef C_COLOR_PAIRS
	    COLOR_PAIRS = (int)SvIV(ST(1));
#else
	    c_var_not_there("COLOR_PAIRS");
#endif
	    break;
	default:
	    croak("Curses::Vars::STORE called with bad index");
	    /* NOTREACHED */
	}
	ST(0) = &PL_sv_yes;
#else
    croak("Curses::Vars::STORE is not available in this version of "
          "Curses.pm.  Setting of variables is not allowed in recent "
          "Curses (C) libraries.");

    /* In January 2010, we first saw a version of Ncurses that does not
       allow setting of variables.  This has to do with making the library
       re-entrant.  The variables do not exist, but code that refers to them
       still works because the variable names are defined as macros that call
       functions that retrieve the value.  For some of the variables, it
       doesn't even make sense to set the variables, and we assume few programs
       ever exploited this ability, so simply removed it by default for
       everyone starting with the January 2010 release.
    
       If you have an old Ncurses library that allows setting of variables
       and really want this function in Curses.pm, #define ALLOW_VARS_STORE
       in your c-config.h.
    */
#endif
    }
    XSRETURN(1);
}

XS(XS_Curses_Vars_DESTROY)
{
    dXSARGS;
    {
	SV *	rv = ST(0);

	ST(0) = &PL_sv_yes;
    }
    XSRETURN(1);
}