1 /*  This file can be automatically generated; changes may be lost.
2 **
3 **
4 **  CursesVar.c -- the variables
5 **
6 **  This is an inclusion for Curses.c
7 **
8 **  Copyright (c) 1994-2000  William Setzer
9 **
10 **  You may distribute under the terms of either the Artistic License
11 **  or the GNU General Public License, as specified in the README file.
12 */
13 
XS(XS_Curses_LINES)14 XS(XS_Curses_LINES)
15 {
16     dXSARGS;
17 #ifdef C_LINES
18     c_exactargs("LINES", items, 0);
19     {
20 	ST(0) = sv_newmortal();
21 	sv_setiv(ST(0), (IV)LINES);
22     }
23     XSRETURN(1);
24 #else
25     c_var_not_there("LINES");
26     XSRETURN(0);
27 #endif
28 }
29 
XS(XS_Curses_COLS)30 XS(XS_Curses_COLS)
31 {
32     dXSARGS;
33 #ifdef C_COLS
34     c_exactargs("COLS", items, 0);
35     {
36 	ST(0) = sv_newmortal();
37 	sv_setiv(ST(0), (IV)COLS);
38     }
39     XSRETURN(1);
40 #else
41     c_var_not_there("COLS");
42     XSRETURN(0);
43 #endif
44 }
45 
XS(XS_Curses_stdscr)46 XS(XS_Curses_stdscr)
47 {
48     dXSARGS;
49 #ifdef C_STDSCR
50     c_exactargs("stdscr", items, 0);
51     {
52 	ST(0) = sv_newmortal();
53 	c_window2sv(ST(0), stdscr);
54     }
55     XSRETURN(1);
56 #else
57     c_var_not_there("stdscr");
58     XSRETURN(0);
59 #endif
60 }
61 
XS(XS_Curses_curscr)62 XS(XS_Curses_curscr)
63 {
64     dXSARGS;
65 #ifdef C_CURSCR
66     c_exactargs("curscr", items, 0);
67     {
68 	ST(0) = sv_newmortal();
69 	c_window2sv(ST(0), curscr);
70     }
71     XSRETURN(1);
72 #else
73     c_var_not_there("curscr");
74     XSRETURN(0);
75 #endif
76 }
77 
XS(XS_Curses_COLORS)78 XS(XS_Curses_COLORS)
79 {
80     dXSARGS;
81 #ifdef C_COLORS
82     c_exactargs("COLORS", items, 0);
83     {
84 	ST(0) = sv_newmortal();
85 	sv_setiv(ST(0), (IV)COLORS);
86     }
87     XSRETURN(1);
88 #else
89     c_var_not_there("COLORS");
90     XSRETURN(0);
91 #endif
92 }
93 
XS(XS_Curses_COLOR_PAIRS)94 XS(XS_Curses_COLOR_PAIRS)
95 {
96     dXSARGS;
97 #ifdef C_COLOR_PAIRS
98     c_exactargs("COLOR_PAIRS", items, 0);
99     {
100 	ST(0) = sv_newmortal();
101 	sv_setiv(ST(0), (IV)COLOR_PAIRS);
102     }
103     XSRETURN(1);
104 #else
105     c_var_not_there("COLOR_PAIRS");
106     XSRETURN(0);
107 #endif
108 }
109 
110 
XS(XS_Curses_Vars_TIESCALAR)111 XS(XS_Curses_Vars_TIESCALAR)
112 {
113     dXSARGS;
114     c_exactargs("TIESCALAR", items, 2);
115     {
116 	char *	pack = (char *)SvPV_nolen(ST(0));
117 	int	n    = (int)SvIV(ST(1));
118 
119 	ST(0) = sv_newmortal();
120 	sv_setref_iv(ST(0), pack, n);
121     }
122     XSRETURN(1);
123 }
124 
XS(XS_Curses_Vars_FETCH)125 XS(XS_Curses_Vars_FETCH)
126 {
127     dXSARGS;
128     {
129 	int	num = (int)SvIV(SvRV((SV*)ST(0)));
130 
131 	ST(0) = sv_newmortal();
132 	switch (num) {
133 	case 1:
134 #ifdef C_LINES
135 	    sv_setiv(ST(0), (IV)LINES);
136 #else
137 	    c_var_not_there("LINES");
138 #endif
139 	    break;
140 	case 2:
141 #ifdef C_COLS
142 	    sv_setiv(ST(0), (IV)COLS);
143 #else
144 	    c_var_not_there("COLS");
145 #endif
146 	    break;
147 	case 3:
148 #ifdef C_STDSCR
149 	    c_window2sv(ST(0), stdscr);
150 #else
151 	    c_var_not_there("stdscr");
152 #endif
153 	    break;
154 	case 4:
155 #ifdef C_CURSCR
156 	    c_window2sv(ST(0), curscr);
157 #else
158 	    c_var_not_there("curscr");
159 #endif
160 	    break;
161 	case 5:
162 #ifdef C_COLORS
163 	    sv_setiv(ST(0), (IV)COLORS);
164 #else
165 	    c_var_not_there("COLORS");
166 #endif
167 	    break;
168 	case 6:
169 #ifdef C_COLOR_PAIRS
170 	    sv_setiv(ST(0), (IV)COLOR_PAIRS);
171 #else
172 	    c_var_not_there("COLOR_PAIRS");
173 #endif
174 	    break;
175 	default:
176 	    croak("Curses::Vars::FETCH called with bad index");
177 	    /* NOTREACHED */
178 	}
179     }
180     XSRETURN(1);
181 }
182 
XS(XS_Curses_Vars_STORE)183 XS(XS_Curses_Vars_STORE)
184 {
185     dXSARGS;
186     {
187 #ifdef ALLOW_VARS_STORE
188 	int	num = (int)SvIV((SV*)SvRV(ST(0)));
189 
190 	switch (num) {
191 	case 1:
192 #ifdef C_LINES
193 	    LINES = (int)SvIV(ST(1));
194 #else
195 	    c_var_not_there("LINES");
196 #endif
197 	    break;
198 	case 2:
199 #ifdef C_COLS
200 	    COLS = (int)SvIV(ST(1));
201 #else
202 	    c_var_not_there("COLS");
203 #endif
204 	    break;
205 	case 3:
206 #ifdef C_STDSCR
207 	    stdscr = c_sv2window(ST(1), -1);
208 #else
209 	    c_var_not_there("stdscr");
210 #endif
211 	    break;
212 	case 4:
213 #ifdef C_CURSCR
214 	    curscr = c_sv2window(ST(1), -1);
215 #else
216 	    c_var_not_there("curscr");
217 #endif
218 	    break;
219 	case 5:
220 #ifdef C_COLORS
221 	    COLORS = (int)SvIV(ST(1));
222 #else
223 	    c_var_not_there("COLORS");
224 #endif
225 	    break;
226 	case 6:
227 #ifdef C_COLOR_PAIRS
228 	    COLOR_PAIRS = (int)SvIV(ST(1));
229 #else
230 	    c_var_not_there("COLOR_PAIRS");
231 #endif
232 	    break;
233 	default:
234 	    croak("Curses::Vars::STORE called with bad index");
235 	    /* NOTREACHED */
236 	}
237 	ST(0) = &PL_sv_yes;
238 #else
239     croak("Curses::Vars::STORE is not available in this version of "
240           "Curses.pm.  Setting of variables is not allowed in recent "
241           "Curses (C) libraries.");
242 
243     /* In January 2010, we first saw a version of Ncurses that does not
244        allow setting of variables.  This has to do with making the library
245        re-entrant.  The variables do not exist, but code that refers to them
246        still works because the variable names are defined as macros that call
247        functions that retrieve the value.  For some of the variables, it
248        doesn't even make sense to set the variables, and we assume few programs
249        ever exploited this ability, so simply removed it by default for
250        everyone starting with the January 2010 release.
251 
252        If you have an old Ncurses library that allows setting of variables
253        and really want this function in Curses.pm, #define ALLOW_VARS_STORE
254        in your c-config.h.
255     */
256 #endif
257     }
258     XSRETURN(1);
259 }
260 
XS(XS_Curses_Vars_DESTROY)261 XS(XS_Curses_Vars_DESTROY)
262 {
263     dXSARGS;
264     {
265 	SV *	rv = ST(0);
266 
267 	ST(0) = &PL_sv_yes;
268     }
269     XSRETURN(1);
270 }
271