cchars.h

filter: Statementstmt 0.0% 0 / 98 Branchbran 0.0% 0 / 58 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 156 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Term/ReadKey.pm ↑ Summary ReadKey.xs »
1  
2  
3 /* Written by genchars.pl version 1.97 */
4  
5 #define HAVE_POLL_H
6 #define HAVE_SYS_POLL_H
7  
8  
9 #ifdef CC_TERMIOS
10 # define TermStructure struct termios
11 # ifdef NCCS
12 # define LEGALMAXCC NCCS
13 # else
14 # ifdef NCC
15 # define LEGALMAXCC NCC
16 # endif
17 # endif
18 #else
19 # ifdef CC_TERMIO
20 # define TermStructure struct termio
21 # ifdef NCC
22 # define LEGALMAXCC NCC
23 # else
24 # ifdef NCCS
25 # define LEGALMAXCC NCCS
26 # endif
27 # endif
28 # endif
29 #endif
30  
31 #if !defined(LEGALMAXCC)
32 # define LEGALMAXCC 126
33 #endif
34  
35 #if defined(CC_TERMIO) || defined(CC_TERMIOS)
36  
37 char * cc_names[] = {
38 #if defined(VDISCARD) && (VDISCARD < LEGALMAXCC)
39 "DISCARD",
40 #else
41 "",
42 #endif
43 #if defined(VFLUSH) && (VFLUSH < LEGALMAXCC)
44 "DISCARD",
45 #else
46 "",
47 #endif
48 #if defined(VDSUSP) && (VDSUSP < LEGALMAXCC)
49 "DSUSPEND",
50 #else
51 "",
52 #endif
53 #if defined(VEOF) && (VEOF < LEGALMAXCC)
54 "EOF",
55 #else
56 "",
57 #endif
58 #if defined(VEOL) && (VEOL < LEGALMAXCC)
59 "EOL",
60 #else
61 "",
62 #endif
63 #if defined(VEOL2) && (VEOL2 < LEGALMAXCC)
64 "EOL2",
65 #else
66 "",
67 #endif
68 #if defined(VERASE) && (VERASE < LEGALMAXCC)
69 "ERASE",
70 #else
71 "",
72 #endif
73 #if defined(VWERASE) && (VWERASE < LEGALMAXCC)
74 "ERASEWORD",
75 #else
76 "",
77 #endif
78 #if defined(VINTR) && (VINTR < LEGALMAXCC)
79 "INTERRUPT",
80 #else
81 "",
82 #endif
83 #if defined(VKILL) && (VKILL < LEGALMAXCC)
84 "KILL",
85 #else
86 "",
87 #endif
88 #if defined(VMIN) && (VMIN < LEGALMAXCC)
89 "MIN",
90 #else
91 "",
92 #endif
93 #if defined(VQUIT) && (VQUIT < LEGALMAXCC)
94 "QUIT",
95 #else
96 "",
97 #endif
98 #if defined(VLNEXT) && (VLNEXT < LEGALMAXCC)
99 "QUOTENEXT",
100 #else
101 "",
102 #endif
103 #if defined(VQUOTE) && (VQUOTE < LEGALMAXCC)
104 "QUOTENEXT",
105 #else
106 "",
107 #endif
108 #if defined(VREPRINT) && (VREPRINT < LEGALMAXCC)
109 "REPRINT",
110 #else
111 "",
112 #endif
113 #if defined(VSTART) && (VSTART < LEGALMAXCC)
114 "START",
115 #else
116 "",
117 #endif
118 #if defined(VSTATUS) && (VSTATUS < LEGALMAXCC)
119 "STATUS",
120 #else
121 "",
122 #endif
123 #if defined(VSTOP) && (VSTOP < LEGALMAXCC)
124 "STOP",
125 #else
126 "",
127 #endif
128 #if defined(VSUSP) && (VSUSP < LEGALMAXCC)
129 "SUSPEND",
130 #else
131 "",
132 #endif
133 #if defined(VSWTC) && (VSWTC < LEGALMAXCC)
134 "SWITCH",
135 #else
136 "",
137 #endif
138 #if defined(VSWTCH) && (VSWTCH < LEGALMAXCC)
139 "SWITCH",
140 #else
141 "",
142 #endif
143 #if defined(VTIME) && (VTIME < LEGALMAXCC)
144 "TIME",
145 #else
146 "",
147 #endif
148 };
149  
150 const int MAXCC = 0
151 #if defined(VDISCARD) && (VDISCARD < LEGALMAXCC)
152 +1 /* DISCARD */
153 #endif
154 #if defined(VFLUSH) && (VFLUSH < LEGALMAXCC)
155 +1 /* DISCARD */
156 #endif
157 #if defined(VDSUSP) && (VDSUSP < LEGALMAXCC)
158 +1 /* DSUSPEND */
159 #endif
160 #if defined(VEOF) && (VEOF < LEGALMAXCC)
161 +1 /* EOF */
162 #endif
163 #if defined(VEOL) && (VEOL < LEGALMAXCC)
164 +1 /* EOL */
165 #endif
166 #if defined(VEOL2) && (VEOL2 < LEGALMAXCC)
167 +1 /* EOL2 */
168 #endif
169 #if defined(VERASE) && (VERASE < LEGALMAXCC)
170 +1 /* ERASE */
171 #endif
172 #if defined(VWERASE) && (VWERASE < LEGALMAXCC)
173 +1 /* ERASEWORD */
174 #endif
175 #if defined(VINTR) && (VINTR < LEGALMAXCC)
176 +1 /* INTERRUPT */
177 #endif
178 #if defined(VKILL) && (VKILL < LEGALMAXCC)
179 +1 /* KILL */
180 #endif
181 #if defined(VMIN) && (VMIN < LEGALMAXCC)
182 +1 /* MIN */
183 #endif
184 #if defined(VQUIT) && (VQUIT < LEGALMAXCC)
185 +1 /* QUIT */
186 #endif
187 #if defined(VLNEXT) && (VLNEXT < LEGALMAXCC)
188 +1 /* QUOTENEXT */
189 #endif
190 #if defined(VQUOTE) && (VQUOTE < LEGALMAXCC)
191 +1 /* QUOTENEXT */
192 #endif
193 #if defined(VREPRINT) && (VREPRINT < LEGALMAXCC)
194 +1 /* REPRINT */
195 #endif
196 #if defined(VSTART) && (VSTART < LEGALMAXCC)
197 +1 /* START */
198 #endif
199 #if defined(VSTATUS) && (VSTATUS < LEGALMAXCC)
200 +1 /* STATUS */
201 #endif
202 #if defined(VSTOP) && (VSTOP < LEGALMAXCC)
203 +1 /* STOP */
204 #endif
205 #if defined(VSUSP) && (VSUSP < LEGALMAXCC)
206 +1 /* SUSPEND */
207 #endif
208 #if defined(VSWTC) && (VSWTC < LEGALMAXCC)
209 +1 /* SWITCH */
210 #endif
211 #if defined(VSWTCH) && (VSWTCH < LEGALMAXCC)
212 +1 /* SWITCH */
213 #endif
214 #if defined(VTIME) && (VTIME < LEGALMAXCC)
215 +1 /* TIME */
216 #endif
217 ;
218  
219 0 XS(XS_Term__ReadKey_GetControlChars)
220 {
221 0 dXSARGS;
222 0 ▶ if (items < 0 || items > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (items < 0 || items > 1) { 0 0 0
if (items < 0 || items > 1) { 0 0 0
223 0 croak("Usage: Term::ReadKey::GetControlChars()");
224 }
225 0 SP -= items;
226 {
227 PerlIO * file;
228 TermStructure s;
229 0 ▶ if (items < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items < 1) 0 0 0
230 0 file = STDIN;
231 else {
232 0 file = IoIFP(sv_2io(ST(0)));
233 }
234  
235 #ifdef CC_TERMIOS
236 0 ▶ if(tcgetattr(PerlIO_fileno(file),&s))
Branch: 1 branch
BranchTrueFalseTotal
if(tcgetattr(PerlIO_fileno(file),&s)) 0 0 0
237 #else
238 # ifdef CC_TERMIO
239 if(ioctl(PerlIO_fileno(file),TCGETA,&s))
240 # endif
241 #endif
242 0 croak("Unable to read terminal settings in GetControlChars");
243 else {
244 0 ▶ EXTEND(sp,MAXCC*2);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(sp,MAXCC*2); 0 0 0
EXTEND(sp,MAXCC*2); 0 0 0
245 #if defined(VDISCARD) && (VDISCARD < LEGALMAXCC)
246 0 PUSHs(sv_2mortal(newSVpv(cc_names[0],strlen(cc_names[0])))); /* DISCARD */
247 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VDISCARD],1)));
248 #endif
249 #if defined(VFLUSH) && (VFLUSH < LEGALMAXCC)
250 PUSHs(sv_2mortal(newSVpv(cc_names[1],strlen(cc_names[1])))); /* DISCARD */
251 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VFLUSH],1)));
252 #endif
253 #if defined(VDSUSP) && (VDSUSP < LEGALMAXCC)
254 PUSHs(sv_2mortal(newSVpv(cc_names[2],strlen(cc_names[2])))); /* DSUSPEND */
255 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VDSUSP],1)));
256 #endif
257 #if defined(VEOF) && (VEOF < LEGALMAXCC)
258 0 PUSHs(sv_2mortal(newSVpv(cc_names[3],strlen(cc_names[3])))); /* EOF */
259 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VEOF],1)));
260 #endif
261 #if defined(VEOL) && (VEOL < LEGALMAXCC)
262 0 PUSHs(sv_2mortal(newSVpv(cc_names[4],strlen(cc_names[4])))); /* EOL */
263 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VEOL],1)));
264 #endif
265 #if defined(VEOL2) && (VEOL2 < LEGALMAXCC)
266 0 PUSHs(sv_2mortal(newSVpv(cc_names[5],strlen(cc_names[5])))); /* EOL2 */
267 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VEOL2],1)));
268 #endif
269 #if defined(VERASE) && (VERASE < LEGALMAXCC)
270 0 PUSHs(sv_2mortal(newSVpv(cc_names[6],strlen(cc_names[6])))); /* ERASE */
271 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VERASE],1)));
272 #endif
273 #if defined(VWERASE) && (VWERASE < LEGALMAXCC)
274 0 PUSHs(sv_2mortal(newSVpv(cc_names[7],strlen(cc_names[7])))); /* ERASEWORD */
275 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VWERASE],1)));
276 #endif
277 #if defined(VINTR) && (VINTR < LEGALMAXCC)
278 0 PUSHs(sv_2mortal(newSVpv(cc_names[8],strlen(cc_names[8])))); /* INTERRUPT */
279 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VINTR],1)));
280 #endif
281 #if defined(VKILL) && (VKILL < LEGALMAXCC)
282 0 PUSHs(sv_2mortal(newSVpv(cc_names[9],strlen(cc_names[9])))); /* KILL */
283 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VKILL],1)));
284 #endif
285 #if defined(VMIN) && (VMIN < LEGALMAXCC)
286 0 PUSHs(sv_2mortal(newSVpv(cc_names[10],strlen(cc_names[10])))); /* MIN */
287 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VMIN],1)));
288 #endif
289 #if defined(VQUIT) && (VQUIT < LEGALMAXCC)
290 0 PUSHs(sv_2mortal(newSVpv(cc_names[11],strlen(cc_names[11])))); /* QUIT */
291 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VQUIT],1)));
292 #endif
293 #if defined(VLNEXT) && (VLNEXT < LEGALMAXCC)
294 0 PUSHs(sv_2mortal(newSVpv(cc_names[12],strlen(cc_names[12])))); /* QUOTENEXT */
295 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VLNEXT],1)));
296 #endif
297 #if defined(VQUOTE) && (VQUOTE < LEGALMAXCC)
298 PUSHs(sv_2mortal(newSVpv(cc_names[13],strlen(cc_names[13])))); /* QUOTENEXT */
299 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VQUOTE],1)));
300 #endif
301 #if defined(VREPRINT) && (VREPRINT < LEGALMAXCC)
302 0 PUSHs(sv_2mortal(newSVpv(cc_names[14],strlen(cc_names[14])))); /* REPRINT */
303 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VREPRINT],1)));
304 #endif
305 #if defined(VSTART) && (VSTART < LEGALMAXCC)
306 0 PUSHs(sv_2mortal(newSVpv(cc_names[15],strlen(cc_names[15])))); /* START */
307 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VSTART],1)));
308 #endif
309 #if defined(VSTATUS) && (VSTATUS < LEGALMAXCC)
310 PUSHs(sv_2mortal(newSVpv(cc_names[16],strlen(cc_names[16])))); /* STATUS */
311 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VSTATUS],1)));
312 #endif
313 #if defined(VSTOP) && (VSTOP < LEGALMAXCC)
314 0 PUSHs(sv_2mortal(newSVpv(cc_names[17],strlen(cc_names[17])))); /* STOP */
315 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VSTOP],1)));
316 #endif
317 #if defined(VSUSP) && (VSUSP < LEGALMAXCC)
318 0 PUSHs(sv_2mortal(newSVpv(cc_names[18],strlen(cc_names[18])))); /* SUSPEND */
319 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VSUSP],1)));
320 #endif
321 #if defined(VSWTC) && (VSWTC < LEGALMAXCC)
322 0 PUSHs(sv_2mortal(newSVpv(cc_names[19],strlen(cc_names[19])))); /* SWITCH */
323 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VSWTC],1)));
324 #endif
325 #if defined(VSWTCH) && (VSWTCH < LEGALMAXCC)
326 PUSHs(sv_2mortal(newSVpv(cc_names[20],strlen(cc_names[20])))); /* SWITCH */
327 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VSWTCH],1)));
328 #endif
329 #if defined(VTIME) && (VTIME < LEGALMAXCC)
330 0 PUSHs(sv_2mortal(newSVpv(cc_names[21],strlen(cc_names[21])))); /* TIME */
331 0 PUSHs(sv_2mortal(newSVpv((char*)&s.c_cc[VTIME],1)));
332 #endif
333
334 }
335 0 PUTBACK;
336 0 return;
337 }
338 }
339  
340 0 XS(XS_Term__ReadKey_SetControlChars)
341 {
342 0 dXSARGS;
343 /*if ((items % 2) != 0) {
344 croak("Usage: Term::ReadKey::SetControlChars(%charpairs,file=STDIN)");
345 }*/
346 0 SP -= items;
347 {
348 TermStructure s;
349 PerlIO * file;
350 0 ▶ if ((items % 2) == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ((items % 2) == 1) 0 0 0
351 0 file = IoIFP(sv_2io(ST(items-1)));
352 else {
353 0 file = STDIN;
354 }
355  
356 #ifdef CC_TERMIOS
357 0 ▶ if(tcgetattr(PerlIO_fileno(file),&s))
Branch: 1 branch
BranchTrueFalseTotal
if(tcgetattr(PerlIO_fileno(file),&s)) 0 0 0
358 #else
359 # ifdef CC_TERMIO
360 if(ioctl(PerlIO_fileno(file),TCGETA,&s))
361 # endif
362 #endif
363 0 croak("Unable to read terminal settings in SetControlChars");
364 else {
365 int i;
366 char * name, value;
367 0 ▶ for(i=0;i+1<items;i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0;i+1<items;i+=2) { 0 0 0
368 0 name = SvPV(ST(i),PL_na);
369 0 ▶ if( SvIOKp(ST(i+1)) || SvNOKp(ST(i+1)) )/* If Int or Float */
Branch: 2 branches
BranchTrueFalseTotal
if( SvIOKp(ST(i+1)) || SvNOKp(ST(i+1)) )/* If Int or Float */ 0 0 0
if( SvIOKp(ST(i+1)) || SvNOKp(ST(i+1)) )/* If Int or Float */ 0 0 0
370 0 value = (char)SvIV(ST(i+1)); /* Store int value */
371 else /* Otherwise */
372 0 value = SvPV(ST(i+1),PL_na)[0]; /* Use first char of PV */
373  
374 if (0) ;
375 #if defined(VDISCARD) && (VDISCARD < LEGALMAXCC)
376 0 ▶ else if(strcmp(name,cc_names[0])==0) /* DISCARD */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[0])==0) /* DISCARD */ 0 0 0
377 0 s.c_cc[VDISCARD] = value;
378 #endif
379 #if defined(VFLUSH) && (VFLUSH < LEGALMAXCC)
380 else if(strcmp(name,cc_names[1])==0) /* DISCARD */
381 s.c_cc[VFLUSH] = value;
382 #endif
383 #if defined(VDSUSP) && (VDSUSP < LEGALMAXCC)
384 else if(strcmp(name,cc_names[2])==0) /* DSUSPEND */
385 s.c_cc[VDSUSP] = value;
386 #endif
387 #if defined(VEOF) && (VEOF < LEGALMAXCC)
388 0 ▶ else if(strcmp(name,cc_names[3])==0) /* EOF */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[3])==0) /* EOF */ 0 0 0
389 0 s.c_cc[VEOF] = value;
390 #endif
391 #if defined(VEOL) && (VEOL < LEGALMAXCC)
392 0 ▶ else if(strcmp(name,cc_names[4])==0) /* EOL */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[4])==0) /* EOL */ 0 0 0
393 0 s.c_cc[VEOL] = value;
394 #endif
395 #if defined(VEOL2) && (VEOL2 < LEGALMAXCC)
396 0 ▶ else if(strcmp(name,cc_names[5])==0) /* EOL2 */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[5])==0) /* EOL2 */ 0 0 0
397 0 s.c_cc[VEOL2] = value;
398 #endif
399 #if defined(VERASE) && (VERASE < LEGALMAXCC)
400 0 ▶ else if(strcmp(name,cc_names[6])==0) /* ERASE */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[6])==0) /* ERASE */ 0 0 0
401 0 s.c_cc[VERASE] = value;
402 #endif
403 #if defined(VWERASE) && (VWERASE < LEGALMAXCC)
404 0 ▶ else if(strcmp(name,cc_names[7])==0) /* ERASEWORD */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[7])==0) /* ERASEWORD */ 0 0 0
405 0 s.c_cc[VWERASE] = value;
406 #endif
407 #if defined(VINTR) && (VINTR < LEGALMAXCC)
408 0 ▶ else if(strcmp(name,cc_names[8])==0) /* INTERRUPT */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[8])==0) /* INTERRUPT */ 0 0 0
409 0 s.c_cc[VINTR] = value;
410 #endif
411 #if defined(VKILL) && (VKILL < LEGALMAXCC)
412 0 ▶ else if(strcmp(name,cc_names[9])==0) /* KILL */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[9])==0) /* KILL */ 0 0 0
413 0 s.c_cc[VKILL] = value;
414 #endif
415 #if defined(VMIN) && (VMIN < LEGALMAXCC)
416 0 ▶ else if(strcmp(name,cc_names[10])==0) /* MIN */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[10])==0) /* MIN */ 0 0 0
417 0 s.c_cc[VMIN] = value;
418 #endif
419 #if defined(VQUIT) && (VQUIT < LEGALMAXCC)
420 0 ▶ else if(strcmp(name,cc_names[11])==0) /* QUIT */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[11])==0) /* QUIT */ 0 0 0
421 0 s.c_cc[VQUIT] = value;
422 #endif
423 #if defined(VLNEXT) && (VLNEXT < LEGALMAXCC)
424 0 ▶ else if(strcmp(name,cc_names[12])==0) /* QUOTENEXT */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[12])==0) /* QUOTENEXT */ 0 0 0
425 0 s.c_cc[VLNEXT] = value;
426 #endif
427 #if defined(VQUOTE) && (VQUOTE < LEGALMAXCC)
428 else if(strcmp(name,cc_names[13])==0) /* QUOTENEXT */
429 s.c_cc[VQUOTE] = value;
430 #endif
431 #if defined(VREPRINT) && (VREPRINT < LEGALMAXCC)
432 0 ▶ else if(strcmp(name,cc_names[14])==0) /* REPRINT */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[14])==0) /* REPRINT */ 0 0 0
433 0 s.c_cc[VREPRINT] = value;
434 #endif
435 #if defined(VSTART) && (VSTART < LEGALMAXCC)
436 0 ▶ else if(strcmp(name,cc_names[15])==0) /* START */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[15])==0) /* START */ 0 0 0
437 0 s.c_cc[VSTART] = value;
438 #endif
439 #if defined(VSTATUS) && (VSTATUS < LEGALMAXCC)
440 else if(strcmp(name,cc_names[16])==0) /* STATUS */
441 s.c_cc[VSTATUS] = value;
442 #endif
443 #if defined(VSTOP) && (VSTOP < LEGALMAXCC)
444 0 ▶ else if(strcmp(name,cc_names[17])==0) /* STOP */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[17])==0) /* STOP */ 0 0 0
445 0 s.c_cc[VSTOP] = value;
446 #endif
447 #if defined(VSUSP) && (VSUSP < LEGALMAXCC)
448 0 ▶ else if(strcmp(name,cc_names[18])==0) /* SUSPEND */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[18])==0) /* SUSPEND */ 0 0 0
449 0 s.c_cc[VSUSP] = value;
450 #endif
451 #if defined(VSWTC) && (VSWTC < LEGALMAXCC)
452 0 ▶ else if(strcmp(name,cc_names[19])==0) /* SWITCH */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[19])==0) /* SWITCH */ 0 0 0
453 0 s.c_cc[VSWTC] = value;
454 #endif
455 #if defined(VSWTCH) && (VSWTCH < LEGALMAXCC)
456 else if(strcmp(name,cc_names[20])==0) /* SWITCH */
457 s.c_cc[VSWTCH] = value;
458 #endif
459 #if defined(VTIME) && (VTIME < LEGALMAXCC)
460 0 ▶ else if(strcmp(name,cc_names[21])==0) /* TIME */
Branch: 1 branch
BranchTrueFalseTotal
else if(strcmp(name,cc_names[21])==0) /* TIME */ 0 0 0
461 0 s.c_cc[VTIME] = value;
462 #endif
463 else
464 0 croak("Invalid control character passed to SetControlChars");
465
466 }
467 #ifdef CC_TERMIOS
468 0 ▶ if(tcsetattr(PerlIO_fileno(file),TCSANOW,&s))
Branch: 1 branch
BranchTrueFalseTotal
if(tcsetattr(PerlIO_fileno(file),TCSANOW,&s)) 0 0 0
469 #else
470 # ifdef CC_TERMIO
471 if(ioctl(PerlIO_fileno(file),TCSETA,&s))
472 # endif
473 #endif
474 0 croak("Unable to write terminal settings in SetControlChars");
475 }
476 }
477 0 XSRETURN(1);
478 }
479  
480  
481 #endif
482  
483  
484  
485 #ifdef CC_SGTTY
486  
487 struct termstruct {
488 struct sgttyb s1;
489  
490 };
491 #define TermStructure struct termstruct
492  
493 char * cc_names[] = {
494 "ERASE",
495 "KILL",
496 };
497  
498 #define MAXCC 2
499  
500 XS(XS_Term__ReadKey_GetControlChars)
501 {
502 dXSARGS;
503 if (items < 0 || items > 1) {
504 croak("Usage: Term::ReadKey::GetControlChars()");
505 }
506 SP -= items;
507 {
508 PerlIO * file;
509 TermStructure s;
510 if (items < 1)
511 file = STDIN;
512 else {
513 file = IoIFP(sv_2io(ST(0)));
514 }
515 if(ioctl(fileno(PerlIO_file),TIOCGETP,&s.s1)
516 )
517 croak("Unable to read terminal settings in GetControlChars");
518 else {
519 int i;
520 EXTEND(sp,MAXCC*2);
521 PUSHs(sv_2mortal(newSVpv(cc_names[0],strlen(cc_names[0])))); /* ERASE */
522 PUSHs(sv_2mortal(newSVpv(&s.s1.sg_erase,1)));
523 PUSHs(sv_2mortal(newSVpv(cc_names[1],strlen(cc_names[1])))); /* KILL */
524 PUSHs(sv_2mortal(newSVpv(&s.s1.sg_kill,1)));
525
526 }
527 PUTBACK;
528 return;
529 }
530 }
531  
532 XS(XS_Term__ReadKey_SetControlChars)
533 {
534 dXSARGS;
535 /*if ((items % 2) != 0) {
536 croak("Usage: Term::ReadKey::SetControlChars(%charpairs,file=STDIN)");
537 }*/
538 SP -= items;
539 {
540 PerlIO * file;
541 TermStructure s;
542 if ((items%2)==0)
543 file = STDIN;
544 else {
545 file = IoIFP(sv_2io(ST(items-1)));
546 }
547  
548 if(ioctl(PerlIO_fileno(file),TIOCGETP,&s.s1)
549 )
550 croak("Unable to read terminal settings in SetControlChars");
551 else {
552 int i;
553 char * name, value;
554 for(i=0;i+1<items;i+=2) {
555 name = SvPV(ST(i),PL_na);
556 if( SvIOKp(ST(i+1)) || SvNOKp(ST(i+1)) )/* If Int or Float */
557 value = (char)SvIV(ST(i+1)); /* Store int value */
558 else /* Otherwise */
559 value = SvPV(ST(i+1),PL_na)[0]; /* Use first char of PV */
560  
561 if (0) ;
562 else if(strcmp(name,cc_names[0])==0) /* ERASE */
563 s.s1.sg_erase = value;
564 else if(strcmp(name,cc_names[1])==0) /* KILL */
565 s.s1.sg_kill = value;
566 else
567 croak("Invalid control character passed to SetControlChars");
568
569 }
570 if(ioctl(fileno(PerlIO_file),TIOCSETN,&s.s1)
571 ) croak("Unable to write terminal settings in SetControlChars");
572 }
573 }
574 XSRETURN(1);
575 }
576  
577 #endif
578  
579 #if !defined(CC_TERMIO) && !defined(CC_TERMIOS) && !defined(CC_SGTTY)
580 #define TermStructure int
581 XS(XS_Term__ReadKey_GetControlChars)
582 {
583 dXSARGS;
584 if (items <0 || items>1) {
585 croak("Usage: Term::ReadKey::GetControlChars([FileHandle])");
586 }
587 SP -= items;
588 {
589 ST(0) = sv_newmortal();
590 PUTBACK;
591 return;
592 }
593 }
594  
595 XS(XS_Term__ReadKey_SetControlChars)
596 {
597 dXSARGS;
598 if (items < 0 || items > 1) {
599 croak("Invalid control character passed to SetControlChars");
600 }
601 SP -= items;
602 XSRETURN(1);
603 }
604  
605 #endif
606  
« blib/lib/Term/ReadKey.pm ↑ Summary ReadKey.xs »