ncurses_wrap.c (104377B) - raw
1 /*
2 * ncurses-ruby is a ruby module for accessing the FSF's ncurses library
3 * (C) 2002, 2003, 2004 Tobias Peters <t-peters@berlios.de>
4 * (C) 2004 Simon Kaczor <skaczor@cox.net>
5 * (C) 2005 2006 2009 2011 Tobias Herzke
6 * (C) 2013 Gaute Hope <eg@gaute.vetsj.com>
7 *
8 * This module is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This module is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this module; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * $Id: ncurses_wrap.c,v 1.19 2011-05-30 23:05:50 t-peters Exp $
23 *
24 * This file was adapted from the original ncurses header file which
25 * has the following copyright statements:
26 */
27
28 /****************************************************************************
29 * Copyright (c) 1998 Free Software Foundation, Inc. *
30 * *
31 * Permission is hereby granted, free of charge, to any person obtaining a *
32 * copy of this software and associated documentation files (the *
33 * "Software"), to deal in the Software without restriction, including *
34 * without limitation the rights to use, copy, modify, merge, publish, *
35 * distribute, distribute with modifications, sublicense, and/or sell *
36 * copies of the Software, and to permit persons to whom the Software is *
37 * furnished to do so, subject to the following conditions: *
38 * *
39 * The above copyright notice and this permission notice shall be included *
40 * in all copies or substantial portions of the Software. *
41 * *
42 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
43 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
44 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
45 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
46 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
47 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
48 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
49 * *
50 * Except as contained in this notice, the name(s) of the above copyright *
51 * holders shall not be used in advertising or otherwise to promote the *
52 * sale, use or other dealings in this Software without prior written *
53 * authorization. *
54 ****************************************************************************/
55
56 /****************************************************************************
57 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
58 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
59 ****************************************************************************/
60
61 /*
62 NOT IMPLEMENTED:
63 - terminfo, termcap-functions
64 - rippoffline
65 - v*printw functions (but normal printw functions are supported!)
66 */
67
68 #include "ncurses_wrap.h"
69 #include "compat.h"
70 #ifdef HAVE_LOCALE_H
71 #include <locale.h>
72 #endif
73
74 #ifdef HAVE_CLOCK_GETTIME
75 #include <time.h>
76 #endif
77
78 #ifdef HAVE_SYS_TIME_H
79 #include <sys/time.h>
80 #endif
81
82 VALUE mNcurses; /* module Ncurses */
83 VALUE cWINDOW; /* class Ncurses::WINDOW */
84 VALUE cSCREEN; /* class Ncurses::SCREEN */
85 VALUE eNcurses; /* Ncurses::Exception thrown by this extension */
86
87 static void Init_ncurses_full(void);
88
89 static
90 void
91 init_constants_1(void)
92 {
93 #ifdef CURSES
94 rb_define_const(mNcurses, "CURSES", INT2NUM((int)(CURSES)));
95 #endif
96 #ifdef CURSES_H
97 rb_define_const(mNcurses, "CURSES_H", INT2NUM((int)(CURSES_H)));
98 #endif
99 #ifdef NCURSES_VERSION_MAJOR
100 rb_define_const(mNcurses, "NCURSES_VERSION_MAJOR",
101 INT2NUM((int)(NCURSES_VERSION_MAJOR)));
102 #endif
103 #ifdef NCURSES_VERSION_MINOR
104 rb_define_const(mNcurses, "NCURSES_VERSION_MINOR",
105 INT2NUM((int)(NCURSES_VERSION_MINOR)));
106 #endif
107 #ifdef NCURSES_VERSION_PATCH
108 rb_define_const(mNcurses, "NCURSES_VERSION_PATCH",
109 INT2NUM((int)(NCURSES_VERSION_PATCH)));
110 #endif
111 #ifdef NCURSES_VERSION
112 rb_define_const(mNcurses, "NCURSES_VERSION",
113 rb_str_new2(NCURSES_VERSION));
114 #endif
115
116 /* attributes */
117 #ifdef WA_ATTRIBUTES
118 rb_define_const(mNcurses, "WA_ATTRIBUTES", INT2NUM(WA_ATTRIBUTES));
119 rb_define_const(mNcurses, "WA_NORMAL", INT2NUM(WA_NORMAL));
120 rb_define_const(mNcurses, "WA_STANDOUT", INT2NUM(WA_STANDOUT));
121 rb_define_const(mNcurses, "WA_UNDERLINE", INT2NUM(WA_UNDERLINE));
122 rb_define_const(mNcurses, "WA_REVERSE", INT2NUM(WA_REVERSE));
123 rb_define_const(mNcurses, "WA_BLINK", INT2NUM(WA_BLINK));
124 rb_define_const(mNcurses, "WA_DIM", INT2NUM(WA_DIM));
125 rb_define_const(mNcurses, "WA_BOLD", INT2NUM(WA_BOLD));
126 rb_define_const(mNcurses, "WA_ALTCHARSET", INT2NUM(WA_ALTCHARSET));
127 rb_define_const(mNcurses, "WA_INVIS", INT2NUM(WA_INVIS));
128 rb_define_const(mNcurses, "WA_PROTECT", INT2NUM(WA_PROTECT));
129 rb_define_const(mNcurses, "WA_HORIZONTAL", INT2NUM(WA_HORIZONTAL));
130 rb_define_const(mNcurses, "WA_LEFT", INT2NUM(WA_LEFT));
131 rb_define_const(mNcurses, "WA_LOW", INT2NUM(WA_LOW));
132 rb_define_const(mNcurses, "WA_RIGHT", INT2NUM(WA_RIGHT));
133 rb_define_const(mNcurses, "WA_TOP", INT2NUM(WA_TOP));
134 rb_define_const(mNcurses, "WA_VERTICAL", INT2NUM(WA_VERTICAL));
135 #endif
136
137 /* locale flags */
138 #ifdef HAVE_LOCALE_H
139 rb_define_const(mNcurses, "LC_ALL", INT2NUM(LC_ALL));
140 rb_define_const(mNcurses, "LC_COLLATE", INT2NUM(LC_COLLATE));
141 rb_define_const(mNcurses, "LC_CTYPE", INT2NUM(LC_CTYPE));
142 rb_define_const(mNcurses, "LC_MESSAGES", INT2NUM(LC_MESSAGES));
143 rb_define_const(mNcurses, "LC_MONETARY", INT2NUM(LC_MONETARY));
144 rb_define_const(mNcurses, "LC_NUMERIC", INT2NUM(LC_NUMERIC));
145 rb_define_const(mNcurses, "LC_TIME", INT2NUM(LC_TIME));
146 #endif
147 }
148
149 static VALUE rbncurs_COLORS(VALUE dummy)
150 {return INT2NUM(COLORS);}
151 static VALUE rbncurs_COLOR_PAIRS(VALUE dummy)
152 {return INT2NUM(COLOR_PAIRS);}
153
154 static
155 void
156 init_globals_1(void)
157 {
158 /* colors */
159 NCFUNC(COLORS, 0);
160 NCFUNC(COLOR_PAIRS, 0);
161 }
162 static
163 void
164 init_constants_2(void)
165 {
166 rb_define_const(mNcurses, "COLOR_BLACK", INT2NUM(COLOR_BLACK));
167 rb_define_const(mNcurses, "COLOR_RED", INT2NUM(COLOR_RED));
168 rb_define_const(mNcurses, "COLOR_GREEN", INT2NUM(COLOR_GREEN));
169 rb_define_const(mNcurses, "COLOR_YELLOW", INT2NUM(COLOR_YELLOW));
170 rb_define_const(mNcurses, "COLOR_BLUE", INT2NUM(COLOR_BLUE));
171 rb_define_const(mNcurses, "COLOR_MAGENTA", INT2NUM(COLOR_MAGENTA));
172 rb_define_const(mNcurses, "COLOR_CYAN", INT2NUM(COLOR_CYAN));
173 rb_define_const(mNcurses, "COLOR_WHITE", INT2NUM(COLOR_WHITE));
174
175 rb_define_const(mNcurses, "ERR", INT2NUM(ERR));
176 rb_define_const(mNcurses, "OK", INT2NUM(OK));
177
178 /* values for the _flags member */
179 #ifdef _SUBWIN
180 rb_define_const(mNcurses, "SUBWIN", INT2NUM(_SUBWIN));
181 #endif
182 #ifdef _ENDLINE
183 rb_define_const(mNcurses, "ENDLINE", INT2NUM(_ENDLINE));
184 #endif
185 #ifdef _FULLWIN
186 rb_define_const(mNcurses, "FULLWIN", INT2NUM(_FULLWIN));
187 #endif
188 #ifdef _SCROLLWIN
189 rb_define_const(mNcurses, "SCROLLWIN", INT2NUM(_SCROLLWIN));
190 #endif
191 #ifdef _ISPAD
192 rb_define_const(mNcurses, "ISPAD", INT2NUM(_ISPAD));
193 #endif
194 #ifdef _HASMOVED
195 rb_define_const(mNcurses, "HASMOVED", INT2NUM(_HASMOVED));
196 #endif
197 #ifdef _WRAPPED
198 rb_define_const(mNcurses, "WRAPPED", INT2NUM(_WRAPPED));
199 #endif
200
201 #ifdef _NOCHANGE
202 /*
203 * this value is used in the firstchar and lastchar fields to mark
204 * unchanged lines
205 */
206 rb_define_const(mNcurses, "NOCHANGE", INT2NUM(_NOCHANGE));
207 #endif
208 #ifdef _NEWINDEX
209 /*
210 * this value is used in the oldindex field to mark lines created by
211 * insertions and scrolls.
212 */
213 rb_define_const(mNcurses, "NEWINDEX", INT2NUM(_NEWINDEX));
214 #endif
215 #ifdef CCHARW_MAX
216 rb_define_const(mNcurses, "CCHARW_MAX", INT2NUM(CCHARW_MAX));
217 #endif
218 }
219
220 /// Portable (1.8,1.9) determination of array length (calling #length)
221 long rbncurs_array_length(VALUE array)
222 {
223 return NUM2LONG(rb_funcall(array, rb_intern("length"), 0));
224 }
225
226 static const struct rb_data_type_struct window_rbtype = {
227 .wrap_struct_name = "Ncurses::WINDOW",
228 };
229 VALUE wrap_window(WINDOW* window)
230 {
231 if (window == 0) return Qnil;
232 {
233 VALUE windows_hash = rb_iv_get(mNcurses, "@windows_hash");
234 VALUE window_adress = INT2NUM((long)(window));
235 VALUE rb_window = rb_hash_aref(windows_hash, window_adress);
236 if (rb_window == Qnil) {
237 rb_window = TypedData_Wrap_Struct(cWINDOW, &window_rbtype, window);
238 rb_iv_set(rb_window, "@destroyed", Qfalse);
239 rb_iv_set(rb_window, "@timeout", INT2FIX(-1));
240 rb_hash_aset(windows_hash, window_adress, rb_window);
241 }
242 return rb_window;
243 }
244 }
245 WINDOW* get_window(VALUE rb_window)
246 {
247 WINDOW* window;
248 if (rb_window == Qnil) return 0;
249 if (rb_iv_get(rb_window, "@destroyed") == Qtrue) {
250 rb_raise(eNcurses, "Attempt to access a destroyed window");
251 return 0;
252 }
253 TypedData_Get_Struct(rb_window, WINDOW, &window_rbtype, window);
254 return window;
255 }
256 static VALUE rbncurs_delwin(VALUE dummy, VALUE arg1) {
257 VALUE windows_hash = rb_iv_get(mNcurses, "@windows_hash");
258 WINDOW* window = get_window(arg1);
259 VALUE window_adress = INT2NUM((long)(window));
260 rb_funcall(windows_hash, rb_intern("delete"), 1, window_adress);
261 rb_iv_set(arg1, "@destroyed", Qtrue);
262 return INT2NUM(delwin(window));
263 }
264
265 static const struct rb_data_type_struct screen_rbtype = {
266 .wrap_struct_name = "Ncurses::SCREEN",
267 };
268 static VALUE wrap_screen(SCREEN* screen)
269 {
270 if (screen == 0) return Qnil;
271 {
272 VALUE screens_hash = rb_iv_get(mNcurses, "@screens_hash");
273 VALUE screen_adress = INT2NUM((long)(screen));
274 VALUE rb_screen = rb_hash_aref(screens_hash, screen_adress);
275 if (rb_screen == Qnil) {
276 rb_screen = TypedData_Wrap_Struct(cSCREEN, &screen_rbtype, screen);
277 rb_iv_set(rb_screen, "@destroyed", Qfalse);
278 rb_hash_aset(screens_hash, screen_adress, rb_screen);
279 }
280 return rb_screen;
281 }
282 }
283 static SCREEN* get_screen(VALUE rb_screen)
284 {
285 SCREEN* screen;
286 if (rb_screen == Qnil) return 0;
287 if (rb_iv_get(rb_screen, "@destroyed") == Qtrue) {
288 rb_raise(eNcurses, "Attempt to access a destroyed screen");
289 return 0;
290 }
291 TypedData_Get_Struct(rb_screen, SCREEN, &screen_rbtype, screen);
292 return screen;
293 }
294 #ifdef HAVE_DELSCREEN
295 static VALUE rbncurs_delscreen(VALUE dummy, VALUE arg1) {
296 VALUE screens_hash = rb_iv_get(mNcurses, "@screens_hash");
297 SCREEN* screen = get_screen(arg1);
298 VALUE screen_adress = INT2NUM((long)(screen));
299 rb_funcall(screens_hash, rb_intern("delete"), 1, screen_adress);
300 rb_iv_set(arg1, "@destroyed", Qtrue);
301 delscreen(screen);
302 return Qnil;
303 }
304 #endif
305 static VALUE rbncurs_winchnstr(VALUE dummy, VALUE rb_win, VALUE rb_str, VALUE rb_n)
306 {
307 if (rb_obj_is_instance_of(rb_str, rb_cArray) != Qtrue) {
308 rb_raise(rb_eArgError, "2nd argument must be an empty Array");
309 return Qnil;
310 }
311
312 {
313 WINDOW * window = get_window(rb_win);
314 int n = NUM2INT(rb_n);
315 chtype * str = ALLOC_N(chtype, n + 1);
316 int return_value;
317 return_value = winchnstr(window, str, n);
318 if (return_value != ERR) {
319 int i;
320 for (i = 0; i < return_value; ++i) {
321 rb_ary_push(rb_str, INT2NUM(str[i]));
322 }
323 }
324 xfree(str);
325 return INT2NUM(return_value);
326 }
327 }
328 static VALUE rbncurs_wgetnstr(VALUE dummy, VALUE rb_win, VALUE rb_chstr, VALUE rb_n)
329 {
330 WINDOW * window = get_window(rb_win);
331 int n = NUM2INT(rb_n);
332 char * str = ALLOC_N(char, n + 1);
333 int return_value;
334 return_value = wgetnstr(window, str, n);
335 if (return_value != ERR) {
336 rb_str_cat2(rb_chstr, str);
337 }
338 xfree(str);
339 return INT2NUM(return_value);
340 }
341 static VALUE rbncurs_winnstr(VALUE dummy, VALUE rb_win, VALUE rb_chstr, VALUE rb_n)
342 {
343 WINDOW * window = get_window(rb_win);
344 int n = NUM2INT(rb_n);
345 char* str = ALLOC_N(char, n + 1);
346 int return_value;
347 return_value = winnstr(window, str, n);
348 if (return_value != ERR) {
349 rb_str_cat(rb_chstr, str, return_value);
350 }
351 xfree(str);
352 return INT2NUM(return_value);
353 }
354
355 #if defined(HAVE_PANEL_H) || defined(HAVE_NCURSESW_PANEL_H)
356 #include "panel_wrap.h" /* needs access to mNcurses, wrap_window, get_window */
357 #endif
358
359 #if defined(HAVE_FORM_H) || defined(HAVE_NCURSESW_FORM_H)
360 #include "form_wrap.h" /* needs init_form */
361 #endif
362
363 #if defined(HAVE_MENU_H) || defined(HAVE_NCURSESW_MENU_H)
364 #include "menu_wrap.h" /* needs init_menu */
365 #endif
366
367 static
368 void
369 init_functions_0(void)
370 {
371 #ifdef HAVE_DELSCREEN
372 NCFUNC(delscreen, 1);
373 #endif
374 NCFUNC(delwin, 1);
375 NCFUNC(winchnstr, 3);
376 NCFUNC(winnstr, 3);
377 NCFUNC(wgetnstr, 3);
378 }
379
380 static VALUE get_stdscr(VALUE dummy)
381 {
382 VALUE rb_stdscr = rb_iv_get(mNcurses, "@stdscr");
383 if (rb_stdscr == Qnil) {
384 rb_stdscr = wrap_window(stdscr);
385 rb_iv_set(mNcurses, "@stdscr", rb_stdscr);
386 }
387 return rb_stdscr;
388 }
389 static VALUE get_curscr(VALUE dummy)
390 {
391 VALUE rb_curscr = rb_iv_get(mNcurses, "@curscr");
392 if (rb_curscr == Qnil) {
393 rb_curscr = wrap_window(curscr);
394 rb_iv_set(mNcurses, "@curscr", rb_curscr);
395 }
396 return rb_curscr;
397 }
398 #ifdef HAVE_NEWSCR
399 static VALUE get_newscr(VALUE dummy)
400 {
401 VALUE rb_newscr = rb_iv_get(mNcurses, "@newscr");
402 if (rb_newscr == Qnil) {
403 rb_newscr = wrap_window(newscr);
404 rb_iv_set(mNcurses, "@newscr", rb_newscr);
405 }
406 return rb_newscr;
407 }
408 #endif
409 static VALUE get_LINES(VALUE dummy) {return INT2NUM(LINES);}
410 static VALUE get_COLS(VALUE dummy) {return INT2NUM(COLS);}
411 #ifdef HAVE_TABSIZE
412 static VALUE get_TABSIZE(VALUE dummy) {return INT2NUM(TABSIZE);}
413 #endif
414 #ifdef HAVE_ESCDELAY
415 /* This global was an undocumented feature under AIX curses. */
416 /* ESC expire time in milliseconds */
417 static VALUE get_ESCDELAY(VALUE dummy){return INT2NUM(ESCDELAY);}
418 static VALUE set_ESCDELAY(VALUE dummy, VALUE new_delay)
419 {
420 ESCDELAY=NUM2INT(new_delay);
421 return INT2NUM(ESCDELAY);
422 }
423 #endif
424
425 /* This global is wrapper-specific. It denotes the interval after which the
426 terminal is periodically checked for having resized or not. */
427 /* time in milliseconds */
428 static VALUE get_RESIZEDELAY(VALUE dummy){return rb_iv_get(mNcurses, "@resize_delay");}
429 static VALUE set_RESIZEDELAY(VALUE dummy, VALUE rb_new_delay)
430 {
431 int c_new_delay = NUM2INT(rb_new_delay);
432 if (c_new_delay <= 0)
433 rb_raise(rb_eArgError, "delay must be > 0");
434 rb_new_delay = INT2NUM(c_new_delay);
435 rb_iv_set(mNcurses, "@resize_delay", rb_new_delay);
436 return rb_new_delay ;
437 }
438
439 static
440 void
441 init_globals_2(void)
442 {
443 rb_iv_set(mNcurses, "@stdscr", Qnil);
444 rb_iv_set(mNcurses, "@curscr", Qnil);
445 rb_iv_set(mNcurses, "@newscr", Qnil);
446
447 rb_define_module_function(mNcurses, "stdscr",
448 (&get_stdscr), 0);
449 rb_define_module_function(mNcurses, "curscr",
450 (&get_curscr), 0);
451 #ifdef HAVE_NEWSCR
452 rb_define_module_function(mNcurses, "newscr",
453 (&get_newscr), 0);
454 #endif
455 rb_define_module_function(mNcurses, "LINES",
456 (&get_LINES), 0);
457 rb_define_module_function(mNcurses, "COLS",
458 (&get_COLS), 0);
459 #ifdef HAVE_TABSIZE
460 rb_define_module_function(mNcurses, "TABSIZE",
461 (&get_TABSIZE),0);
462 #endif
463 #ifdef HAVE_ESCDELAY
464 rb_define_module_function(mNcurses, "ESCDELAY",
465 (&get_ESCDELAY),0);
466 rb_define_module_function(mNcurses, "ESCDELAY=",
467 (&set_ESCDELAY),1);
468 #endif
469 /* The maximum delay before screen resize is detected, in milliseconds */
470 rb_iv_set(mNcurses, "@resize_delay", INT2FIX(333));
471 rb_define_module_function(mNcurses, "RESIZEDELAY",
472 (&get_RESIZEDELAY),0);
473 rb_define_module_function(mNcurses, "RESIZEDELAY=",
474 (&set_RESIZEDELAY),1);
475 }
476 #ifdef HAVE_KEYBOUND
477 static VALUE rbncurs_keybound(VALUE dummy, VALUE keycode, VALUE count)
478 {
479 char * str = keybound(NUM2INT(keycode), NUM2INT(count));
480 VALUE rb_str = Qnil;
481 if (str) {
482 rb_str = rb_str_new2(str);
483 free(str);
484 }
485 return rb_str;
486 }
487 #endif
488 #ifdef HAVE_CURSES_VERSION
489 static VALUE rbncurs_curses_version(VALUE dummy){return rb_str_new2(curses_version());}
490 #endif
491 #ifdef HAVE_DEFINE_KEY
492 static VALUE rbncurs_define_key(VALUE dummy, VALUE definition, VALUE keycode)
493 {
494 return INT2NUM(define_key((definition != Qnil)
495 ? STR2CSTR(definition)
496 : (char*)(NULL),
497 NUM2INT(keycode)));
498 }
499 #endif
500 #ifdef HAVE_KEYOK
501 static VALUE rbncurs_keyok(VALUE dummy, VALUE keycode, VALUE enable)
502 {
503 return INT2NUM(keyok(NUM2INT(keycode), RTEST(enable)));
504 }
505 #endif
506 #ifdef HAVE_RESIZETERM
507 static VALUE rbncurs_resizeterm(VALUE dummy, VALUE lines, VALUE columns)
508 {
509 return INT2NUM(resizeterm(NUM2INT(lines), NUM2INT(columns)));
510 }
511 #endif
512 #ifdef HAVE_USE_DEFAULT_COLORS
513 static VALUE rbncurs_use_default_colors(VALUE dummy)
514 {
515 return INT2NUM(use_default_colors());
516 }
517 #endif
518 #ifdef HAVE_USE_EXTENDED_NAMES
519 static VALUE rbncurs_use_extended_names(VALUE dummy, VALUE boolean)
520 {return INT2NUM(use_extended_names(RTEST(boolean)));}
521 #endif
522 #ifdef HAVE_WRESIZE
523 static VALUE rbncurs_wresize(VALUE dummy, VALUE win, VALUE lines, VALUE columns)
524 {
525 return INT2NUM(wresize(get_window(win), NUM2INT(lines), NUM2INT(columns)));
526 }
527 #endif
528 static
529 void
530 init_functions_1(void)
531 {
532 #ifdef HAVE_KEYBOUND
533 NCFUNC(keybound, 2);
534 #endif
535 #ifdef HAVE_CURSES_VERSION
536 NCFUNC(curses_version, 0);
537 #endif
538 #ifdef HAVE_DEFINE_KEY
539 NCFUNC(define_key, 2);
540 #endif
541 #ifdef HAVE_KEYOK
542 NCFUNC(keyok, 2);
543 #endif
544 #ifdef HAVE_RESIZETERM
545 NCFUNC(resizeterm, 2);
546 #endif
547 #ifdef HAVE_USE_DEFAULT_COLORS
548 NCFUNC(use_default_colors, 0);
549 #endif
550 #ifdef HAVE_USE_EXTENDED_NAMES
551 NCFUNC(use_extended_names, 1);
552 #endif
553 #ifdef HAVE_WRESIZE
554 NCFUNC(wresize, 3);
555 #endif
556 }
557 /* FIXME: what's this? */
558 /* extern char ttytype[]; */ /* needed for backward compatibility */
559
560
561 /* copy a chstr from ruby to c */
562 static chtype * RB2CHSTR(VALUE array)
563 {
564 if (rb_obj_is_instance_of(array, rb_cArray) != Qtrue) {
565 rb_raise(rb_eArgError,
566 "chtype string argument must be an empty Array");
567 return NULL;
568 }
569 {
570 size_t string_length =
571 NUM2ULONG(rb_funcall(array, rb_intern("size"), 0));
572 size_t vector_length =
573 string_length + 1; /* for terminating 0 */
574 chtype * chstr = ALLOC_N(chtype, vector_length);
575 unsigned long i;
576 for (i = 0; i < string_length; ++i) {
577 chstr[i] = (int) NUM2ULONG(rb_ary_entry(array, i));
578 }
579 chstr[string_length] = 0;
580 return chstr;
581 }
582 }
583
584 static VALUE rbncurs_addch(VALUE dummy, VALUE arg1) {
585 return INT2NUM(addch((int) NUM2ULONG(arg1)));
586 }
587 #ifdef HAVE_ADD_WCH
588 static VALUE rbncurs_add_wch(VALUE dummy, VALUE arg1) {
589 cchar_t c = { 0, { NUM2ULONG(arg1), 0 } };
590 return INT2NUM(add_wch(&c));
591 }
592 #endif
593 static VALUE rbncurs_addchnstr(VALUE dummy, VALUE arg1, VALUE arg2) {
594 chtype * chstr = RB2CHSTR(arg1);
595 VALUE return_value = INT2NUM(addchnstr(chstr, NUM2INT(arg2)));
596 xfree(chstr);
597 return return_value;
598 }
599 static VALUE rbncurs_addchstr(VALUE dummy, VALUE arg1) {
600 chtype * chstr = RB2CHSTR(arg1);
601 VALUE return_value = INT2NUM(addchstr(chstr));
602 xfree(chstr);
603 return return_value;
604 }
605 static VALUE rbncurs_addnstr(VALUE dummy, VALUE arg1, VALUE arg2) {
606 return INT2NUM(addnstr(STR2CSTR(arg1), NUM2INT(arg2)));
607 }
608 static VALUE rbncurs_addstr(VALUE dummy, VALUE arg1) {
609 return INT2NUM(addstr(STR2CSTR(arg1)));
610 }
611 static VALUE rbncurs_attroff(VALUE dummy, VALUE arg1) {
612 return INT2NUM(attroff(NUM2ULONG(arg1)));
613 }
614 static VALUE rbncurs_attron(VALUE dummy, VALUE arg1) {
615 return INT2NUM(attron(NUM2ULONG(arg1)));
616 }
617 static VALUE rbncurs_attrset(VALUE dummy, VALUE arg1) {
618 return INT2NUM(attrset((int) NUM2ULONG(arg1)));
619 }
620 #if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR > 4
621 #ifdef HAVE_ATTR_OFF
622 static VALUE rbncurs_attr_off(VALUE dummy, VALUE arg1, VALUE arg2) {
623 return INT2NUM(attr_off((int) NUM2ULONG(arg1), ((void)(arg2),NULL)));
624 }
625 #endif
626 #ifdef HAVE_ATTR_ON
627 static VALUE rbncurs_attr_on(VALUE dummy, VALUE arg1, VALUE arg2) {
628 return INT2NUM(attr_on((int) NUM2ULONG(arg1), ((void)(arg2),NULL)));
629 }
630 #endif
631 #ifdef HAVE_ATTR_SET
632 static VALUE rbncurs_attr_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
633 return INT2NUM(attr_set((int) NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL)));
634 }
635 #endif
636 #if defined(HAVE_SLK_ATTR_OFF) || defined(slk_attr_off)
637 static VALUE rbncurs_slk_attr_off(VALUE dummy, VALUE arg1, VALUE arg2) {
638 return INT2NUM(slk_attr_off((int) NUM2ULONG(arg1), ((void)(arg2),NULL)));
639 }
640 #endif
641 #if defined(HAVE_SLK_ATTR_ON) || defined(slk_attr_on)
642 static VALUE rbncurs_slk_attr_on(VALUE dummy, VALUE arg1, VALUE arg2) {
643 return INT2NUM(slk_attr_on((int) NUM2ULONG(arg1), ((void)(arg2),NULL)));
644 }
645 #endif
646 #ifdef HAVE_SLK_ATTR_SET
647 static VALUE rbncurs_slk_attr_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
648 return INT2NUM(slk_attr_set((int) NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL)));
649 }
650 #endif
651 #ifdef HAVE_WATTR_ON
652 static VALUE rbncurs_wattr_on(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
653 return INT2NUM(wattr_on(get_window(arg1), (int) NUM2ULONG(arg2), ((void)(arg3),NULL)));
654 }
655 #endif
656 #ifdef HAVE_WATTR_OFF
657 static VALUE rbncurs_wattr_off(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
658 return INT2NUM(wattr_off(get_window(arg1), (int) NUM2ULONG(arg2), ((void)(arg3),NULL)));
659 }
660 #endif
661 #ifdef HAVE_WATTR_SET
662 static VALUE rbncurs_wattr_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
663 return INT2NUM(wattr_set(get_window(arg1), (int) NUM2ULONG(arg2), NUM2INT(arg3), ((void)(arg4),NULL)));
664 }
665 #endif
666 #if defined(HAVE_VID_ATTR) || defined(vid_attr)
667 static VALUE rbncurs_vid_attr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
668 return INT2NUM(vid_attr((int) NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL)));
669 }
670 #endif
671 #ifdef HAVE_ATTR_GET
672 static VALUE rbncurs_attr_get(VALUE dummy, VALUE rb_attrs, VALUE rb_pair,
673 VALUE dummy2)
674 {
675 if ((rb_obj_is_instance_of(rb_attrs, rb_cArray) != Qtrue)
676 || (rb_obj_is_instance_of(rb_pair, rb_cArray) != Qtrue)) {
677 rb_raise(rb_eArgError,
678 "attrs and pair arguments must be empty Arrays");
679 return Qnil;
680 }
681 {
682 attr_t attrs = 0;
683 short pair = 0;
684 int return_value = attr_get(&attrs, &pair, 0);
685 rb_ary_push(rb_attrs, INT2NUM(attrs));
686 rb_ary_push(rb_pair, INT2NUM(pair));
687 return INT2NUM(return_value);
688 }
689 }
690 static VALUE rbncurs_wattr_get(VALUE dummy,VALUE win, VALUE rb_attrs, VALUE rb_pair,
691 VALUE dummy2)
692 {
693 if ((rb_obj_is_instance_of(rb_attrs, rb_cArray) != Qtrue)
694 || (rb_obj_is_instance_of(rb_pair, rb_cArray) != Qtrue)) {
695 rb_raise(rb_eArgError,
696 "attrs and pair arguments must be empty Arrays");
697 return Qnil;
698 }
699 {
700 attr_t attrs = 0;
701 short pair = 0;
702 int return_value = wattr_get(get_window(win), &attrs, &pair, 0);
703 rb_ary_push(rb_attrs, INT2NUM(attrs));
704 rb_ary_push(rb_pair, INT2NUM(pair));
705 return INT2NUM(return_value);
706 }
707 }
708 #endif /* HAVE_ATTR_GET */
709 #endif
710
711 static VALUE rbncurs_baudrate(VALUE dummy) {
712 return INT2NUM(baudrate());
713 }
714 static VALUE rbncurs_beep(VALUE dummy) {
715 return INT2NUM(beep());
716 }
717 static VALUE rbncurs_bkgd(VALUE dummy, VALUE arg1) {
718 return INT2NUM(bkgd((int) NUM2ULONG(arg1)));
719 }
720 static VALUE rbncurs_bkgdset(VALUE dummy, VALUE arg1) {
721 return ((bkgdset((int) NUM2ULONG(arg1))),Qnil);
722 }
723 static VALUE rbncurs_border(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7, VALUE arg8) {
724 return INT2NUM(border((int) NUM2ULONG(arg1), (int) NUM2ULONG(arg2), (int) NUM2ULONG(arg3), (int) NUM2ULONG(arg4), (int) NUM2ULONG(arg5), (int) NUM2ULONG(arg6), (int) NUM2ULONG(arg7), (int) NUM2ULONG(arg8)));
725 }
726 static VALUE rbncurs_box(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
727 return INT2NUM(box(get_window(arg1), (int) NUM2ULONG(arg2), (int) NUM2ULONG(arg3)));
728 }
729 static VALUE rbncurs_can_change_color(VALUE dummy) {
730 return (can_change_color()) ? Qtrue : Qfalse;
731 }
732
733 static int rbncurshelper_halfdelay_cbreak(int tenths, int break_chars)
734 {
735 int status = break_chars ? cbreak() : nocbreak();
736 if (status != ERR) {
737 rb_iv_set(mNcurses, "@halfdelay", INT2NUM(tenths));
738 rb_iv_set(mNcurses, "@cbreak", break_chars ? Qtrue : Qfalse);
739 }
740 return status;
741 }
742 static void rbncurshelper_halfdelay_cbreak_restore()
743 {
744 if (RTEST(rb_iv_get(mNcurses, "@cbreak")))
745 cbreak();
746 else
747 nocbreak();
748 }
749 static VALUE rbncurs_cbreak(VALUE dummy) {
750 return INT2NUM(rbncurshelper_halfdelay_cbreak(0, 1));
751 }
752 #ifdef HAVE_CHGAT
753 static VALUE rbncurs_chgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
754 return INT2NUM(chgat(NUM2INT(arg1), (int) NUM2ULONG(arg2), NUM2INT(arg3),
755 ((void)(arg4),NULL)));
756 }
757 #endif
758 static VALUE rbncurs_clear(VALUE dummy) {
759 return INT2NUM(clear());
760 }
761 static VALUE rbncurs_clearok(VALUE dummy, VALUE arg1, VALUE arg2) {
762 return INT2NUM(clearok(get_window(arg1), RTEST(arg2)));
763 }
764 static VALUE rbncurs_clrtobot(VALUE dummy) {
765 return INT2NUM(clrtobot());
766 }
767 static VALUE rbncurs_clrtoeol(VALUE dummy) {
768 return INT2NUM(clrtoeol());
769 }
770 #ifdef HAVE_COLOR_SET
771 static VALUE rbncurs_color_set(VALUE dummy, VALUE arg1, VALUE arg2) {
772 return INT2NUM(color_set(NUM2INT(arg1), ((void)(arg2),NULL)));
773 }
774 #endif
775
776
777
778 static VALUE rbncurs_COLOR_PAIR(VALUE dummy, VALUE arg1) {
779 return INT2NUM(COLOR_PAIR(NUM2INT(arg1)));
780 }
781
782 // alias for COLOR_PAIR for compatibilty with ruby Curses gem.
783 static VALUE rbncurs_color_pair(VALUE dummy, VALUE arg1) {
784 return rbncurs_COLOR_PAIR (dummy, arg1);
785 }
786
787 static VALUE rbncurs_copywin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7, VALUE arg8, VALUE arg9) {
788 return INT2NUM(copywin(get_window(arg1), get_window(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5), NUM2INT(arg6), NUM2INT(arg7), NUM2INT(arg8), NUM2INT(arg9)));
789 }
790 static VALUE rbncurs_curs_set(VALUE dummy, VALUE arg1) {
791 return INT2NUM(curs_set(NUM2INT(arg1)));
792 }
793 static VALUE rbncurs_def_prog_mode(VALUE dummy) {
794 return INT2NUM(def_prog_mode());
795 }
796 static VALUE rbncurs_def_shell_mode(VALUE dummy) {
797 return INT2NUM(def_shell_mode());
798 }
799 static VALUE rbncurs_delay_output(VALUE dummy, VALUE arg1) {
800 return INT2NUM(delay_output(NUM2INT(arg1)));
801 }
802 static VALUE rbncurs_delch(VALUE dummy) {
803 return INT2NUM(delch());
804 }
805 static VALUE rbncurs_deleteln(VALUE dummy) {
806 return INT2NUM(deleteln());
807 }
808 static VALUE rbncurs_derwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
809 return wrap_window(derwin(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5)));
810 }
811 static VALUE rbncurs_doupdate(VALUE dummy) {
812 return INT2NUM(doupdate());
813 }
814 static VALUE rbncurs_dupwin(VALUE dummy, VALUE arg1) {
815 return wrap_window(dupwin(get_window(arg1)));
816 }
817 static VALUE rbncurs_echo(VALUE dummy) {
818 return INT2NUM(echo());
819 }
820 static VALUE rbncurs_echochar(VALUE dummy, VALUE arg1) {
821 return INT2NUM(echochar((int) NUM2ULONG(arg1)));
822 }
823 static VALUE rbncurs_endwin(VALUE dummy) {
824 return INT2NUM(endwin());
825 }
826 static VALUE rbncurs_erasechar(VALUE dummy) {
827 return INT2NUM(erasechar());
828 }
829 #ifdef HAVE_FILTER
830 static VALUE rbncurs_filter(VALUE dummy) {
831 return ((filter()),Qnil);
832 }
833 #endif
834 static VALUE rbncurs_flash(VALUE dummy) {
835 return INT2NUM(flash());
836 }
837 static VALUE rbncurs_flushinp(VALUE dummy) {
838 return INT2NUM(flushinp());
839 }
840 static VALUE rbncurs_getbkgd(VALUE dummy, VALUE arg1) {
841 return INT2NUM(getbkgd(get_window(arg1)));
842 }
843
844 /* typedef of a pointer to a wgetch function */
845 typedef int (*wgetch_func) (WINDOW *);
846
847 /* functor for getting a char nonblocking, pass getchar function */
848 static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_func, int windelay) {
849 /* nonblocking wgetch only implemented for Ncurses */
850 int halfdelay = NUM2INT(rb_iv_get(mNcurses, "@halfdelay"));
851 int infd = NUM2INT(rb_iv_get(mNcurses, "@infd"));
852 double screen_delay = halfdelay * 0.1;
853 double window_delay = (windelay >= 0) ? 0.001 * windelay : (1e200*1e200);
854 /* FIXME: ^ Infinity ^*/
855 double delay = (screen_delay > 0) ? screen_delay : window_delay;
856 int result;
857 double starttime, nowtime, finishtime;
858 double resize_delay = NUM2INT(get_RESIZEDELAY(mNcurses)) / 1000.0;
859 fd_set in_fds;
860 #ifdef HAVE_CLOCK_GETTIME
861 struct timespec tv;
862 struct timeval ts;
863 clock_gettime (CLOCK_MONOTONIC, &tv);
864 starttime = tv.tv_sec + tv.tv_nsec * 1e-9;
865 #else
866 struct timeval tv;
867 struct timezone tz = {0,0};
868 gettimeofday(&tv, &tz);
869 starttime = tv.tv_sec + tv.tv_usec * 1e-6;
870 #endif
871 finishtime = starttime + delay;
872 wtimeout(c_win, 0);
873 while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR) {
874 #ifdef HAVE_RB_THREAD_FD_SELECT
875 rb_fdset_t fdsets[3];
876 rb_fdset_t *rfds = NULL;
877 #endif
878 #ifdef HAVE_CLOCK_GETTIME
879 clock_gettime (CLOCK_MONOTONIC, &tv);
880 nowtime = tv.tv_sec + tv.tv_nsec * 1e-9;
881 #else
882 gettimeofday(&tv, &tz);
883 nowtime = tv.tv_sec + tv.tv_usec * 1e-6;
884 #endif
885 delay = finishtime - nowtime;
886 if (delay <= 0) break;
887
888 /* Check for terminal size change every resize_delay seconds */
889 if (resize_delay > delay) resize_delay = delay;
890 tv.tv_sec = (time_t)resize_delay;
891 #ifdef HAVE_CLOCK_GETTIME
892 tv.tv_nsec = (unsigned)( (resize_delay - tv.tv_sec) * 1e9 );
893 #else
894 tv.tv_usec = (unsigned)( (resize_delay - tv.tv_sec) * 1e6 );
895 #endif
896
897 #if HAVE_CLOCK_GETTIME
898 ts.tv_sec = tv.tv_sec;
899 ts.tv_usec = tv.tv_nsec * 1e-3;
900 #endif
901
902 /* sleep on infd until input is available or tv reaches timeout */
903 FD_ZERO(&in_fds);
904 FD_SET(infd, &in_fds);
905
906 #ifdef HAVE_RB_THREAD_FD_SELECT
907 rfds = &fdsets[0];
908 rb_fd_init(rfds);
909 rb_fd_copy(rfds, &in_fds, infd +1);
910
911 #if HAVE_CLOCK_GETTIME
912 rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &ts);
913 #else
914 rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &tv);
915 #endif
916
917 #else
918 #if HAVE_CLOCK_GETTIME
919 rb_thread_select(infd + 1, &in_fds, NULL, NULL, &ts);
920 #else
921 rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv);
922 #endif
923 #endif
924 }
925 wtimeout(c_win, windelay);
926 return result;
927 }
928
929 /* non-wide char getch */
930 static int rbncurshelper_nonblocking_wgetch(WINDOW *c_win, int windelay) {
931 return rbncurshelper_do_wgetch_functor (c_win, &wgetch, windelay);
932 }
933
934 #ifdef HAVE_GET_WCH
935 /* not thread safe: wide char getch */
936 static wint_t wget_wch_back;
937 static int my_wget_wch (WINDOW *c_win) {
938 return wget_wch (c_win, &wget_wch_back);
939 }
940
941 /* return array with first element being return key code status,
942 * and second element the key code */
943 static VALUE rbncurshelper_nonblocking_wget_wch(WINDOW *c_win, int windelay) {
944 int retcode = rbncurshelper_do_wgetch_functor (c_win, &my_wget_wch, windelay);
945 VALUE r = rb_assoc_new (INT2NUM(retcode), LONG2NUM(wget_wch_back));
946 return r;
947 }
948 #endif
949
950 static VALUE rbncurs_getch(VALUE dummy) {
951 int windelay = NUM2INT(rb_iv_get(get_stdscr(dummy), "@timeout"));
952 return INT2NUM(rbncurshelper_nonblocking_wgetch(stdscr, windelay));
953 }
954
955 #ifdef HAVE_GET_WCH
956 static VALUE rbncurs_get_wch(VALUE dummy) {
957 int windelay = NUM2INT(rb_iv_get(get_stdscr(dummy), "@timeout"));
958 return rbncurshelper_nonblocking_wget_wch(stdscr, windelay);
959 }
960 #endif
961
962 static VALUE rbncurs_halfdelay(VALUE dummy, VALUE arg1) {
963 return INT2NUM(rbncurshelper_halfdelay_cbreak(NUM2INT(arg1), 1));
964 }
965 static VALUE rbncurs_has_colors(VALUE dummy) {
966 return (has_colors()) ? Qtrue : Qfalse;
967 }
968 static VALUE rbncurs_has_ic(VALUE dummy) {
969 return (has_ic()) ? Qtrue : Qfalse;
970 }
971 static VALUE rbncurs_has_il(VALUE dummy) {
972 return (has_il()) ? Qtrue : Qfalse;
973 }
974 static VALUE rbncurs_hline(VALUE dummy, VALUE arg1, VALUE arg2) {
975 return INT2NUM(hline((int) NUM2ULONG(arg1), NUM2INT(arg2)));
976 }
977 static VALUE rbncurs_idcok(VALUE dummy, VALUE arg1, VALUE arg2) {
978 return ((idcok(get_window(arg1), RTEST(arg2))),Qnil);
979 }
980 static VALUE rbncurs_idlok(VALUE dummy, VALUE arg1, VALUE arg2) {
981 return INT2NUM(idlok(get_window(arg1), RTEST(arg2)));
982 }
983 static VALUE rbncurs_immedok(VALUE dummy, VALUE arg1, VALUE arg2) {
984 return ((immedok(get_window(arg1), RTEST(arg2))),Qnil);
985 }
986 static VALUE rbncurs_inch(VALUE dummy) {
987 return INT2NUM(inch());
988 }
989 static VALUE rbncurs_initscr(VALUE dummy) {
990 VALUE v = wrap_window(initscr());
991 if (!RTEST(v))
992 return v;
993
994 Init_ncurses_full();
995
996 /* Some constants defined by the initscr call. */
997
998 /* line graphics */
999
1000 /* VT100 symbols begin here */
1001
1002 rb_define_const(mNcurses, "ACS_ULCORNER", INT2NUM(ACS_ULCORNER));
1003 rb_define_const(mNcurses, "ACS_LLCORNER", INT2NUM(ACS_LLCORNER));
1004 rb_define_const(mNcurses, "ACS_URCORNER", INT2NUM(ACS_URCORNER));
1005 rb_define_const(mNcurses, "ACS_LRCORNER", INT2NUM(ACS_LRCORNER));
1006 rb_define_const(mNcurses, "ACS_LTEE", INT2NUM(ACS_LTEE));
1007 rb_define_const(mNcurses, "ACS_RTEE", INT2NUM(ACS_RTEE));
1008 rb_define_const(mNcurses, "ACS_BTEE", INT2NUM(ACS_BTEE));
1009 rb_define_const(mNcurses, "ACS_TTEE", INT2NUM(ACS_TTEE));
1010 rb_define_const(mNcurses, "ACS_HLINE", INT2NUM(ACS_HLINE));
1011 rb_define_const(mNcurses, "ACS_VLINE", INT2NUM(ACS_VLINE));
1012 rb_define_const(mNcurses, "ACS_PLUS", INT2NUM(ACS_PLUS));
1013 rb_define_const(mNcurses, "ACS_S1", INT2NUM(ACS_S1));
1014 rb_define_const(mNcurses, "ACS_S9", INT2NUM(ACS_S9));
1015 rb_define_const(mNcurses, "ACS_DIAMOND", INT2NUM(ACS_DIAMOND));
1016 rb_define_const(mNcurses, "ACS_CKBOARD", INT2NUM(ACS_CKBOARD));
1017 rb_define_const(mNcurses, "ACS_DEGREE", INT2NUM(ACS_DEGREE));
1018 rb_define_const(mNcurses, "ACS_PLMINUS", INT2NUM(ACS_PLMINUS));
1019 rb_define_const(mNcurses, "ACS_BULLET", INT2NUM(ACS_BULLET));
1020 /* Teletype 5410v1 symbols begin here */
1021 rb_define_const(mNcurses, "ACS_LARROW", INT2NUM(ACS_LARROW));
1022 rb_define_const(mNcurses, "ACS_RARROW", INT2NUM(ACS_RARROW));
1023 rb_define_const(mNcurses, "ACS_DARROW", INT2NUM(ACS_DARROW));
1024 rb_define_const(mNcurses, "ACS_UARROW", INT2NUM(ACS_UARROW));
1025 rb_define_const(mNcurses, "ACS_BOARD", INT2NUM(ACS_BOARD));
1026 rb_define_const(mNcurses, "ACS_LANTERN", INT2NUM(ACS_LANTERN));
1027 rb_define_const(mNcurses, "ACS_BLOCK", INT2NUM(ACS_BLOCK));
1028 /*
1029 * These aren't documented, but a lot of System Vs have them anyway
1030 * (you can spot pprryyzz{{||}} in a lot of AT&T terminfo strings).
1031 * The ACS_names may not match AT&T's, our source didn't know them.
1032 */
1033 #ifdef ACS_S3
1034 rb_define_const(mNcurses, "ACS_S3", INT2NUM(ACS_S3));
1035 #endif
1036 #ifdef ACS_S7
1037 rb_define_const(mNcurses, "ACS_S7", INT2NUM(ACS_S7));
1038 #endif
1039 #ifdef ACS_LEQUAL
1040 rb_define_const(mNcurses, "ACS_LEQUAL", INT2NUM(ACS_LEQUAL));
1041 #endif
1042 #ifdef ACS_LEQUAL
1043 rb_define_const(mNcurses, "ACS_GEQUAL", INT2NUM(ACS_GEQUAL));
1044 #endif
1045 #ifdef ACS_PI
1046 rb_define_const(mNcurses, "ACS_PI", INT2NUM(ACS_PI));
1047 #endif
1048 #ifdef ACS_NEQUAL
1049 rb_define_const(mNcurses, "ACS_NEQUAL", INT2NUM(ACS_NEQUAL));
1050 #endif
1051 #ifdef ACS_STERLING
1052 rb_define_const(mNcurses, "ACS_STERLING", INT2NUM(ACS_STERLING));
1053 #endif
1054 /*
1055 * Line drawing ACS names are of the form ACS_trbl, where t is the top, r
1056 * is the right, b is the bottom, and l is the left. t, r, b, and l might
1057 * be B (blank), S (single), D (double), or T (thick). The subset defined
1058 * here only uses B and S.
1059 */
1060 #ifdef ACS_BSSB
1061 rb_define_const(mNcurses, "ACS_BSSB", INT2NUM(ACS_BSSB));
1062 #endif
1063 #ifdef ACS_SSBB
1064 rb_define_const(mNcurses, "ACS_SSBB", INT2NUM(ACS_SSBB));
1065 #endif
1066 #ifdef ACS_BBSS
1067 rb_define_const(mNcurses, "ACS_BBSS", INT2NUM(ACS_BBSS));
1068 #endif
1069 #ifdef ACS_SBBS
1070 rb_define_const(mNcurses, "ACS_SBBS", INT2NUM(ACS_SBBS));
1071 #endif
1072 #ifdef ACS_SBSS
1073 rb_define_const(mNcurses, "ACS_SBSS", INT2NUM(ACS_SBSS));
1074 #endif
1075 #ifdef ACS_SSSB
1076 rb_define_const(mNcurses, "ACS_SSSB", INT2NUM(ACS_SSSB));
1077 #endif
1078 #ifdef ACS_SSBS
1079 rb_define_const(mNcurses, "ACS_SSBS", INT2NUM(ACS_SSBS));
1080 #endif
1081 #ifdef ACS_BSSS
1082 rb_define_const(mNcurses, "ACS_BSSS", INT2NUM(ACS_BSSS));
1083 #endif
1084 #ifdef ACS_BSBS
1085 rb_define_const(mNcurses, "ACS_BSBS", INT2NUM(ACS_BSBS));
1086 #endif
1087 #ifdef ACS_SBSB
1088 rb_define_const(mNcurses, "ACS_SBSB", INT2NUM(ACS_SBSB));
1089 #endif
1090 #ifdef ACS_SSSS
1091 rb_define_const(mNcurses, "ACS_SSSS", INT2NUM(ACS_SSSS));
1092 #endif
1093 rbncurshelper_halfdelay_cbreak_restore();
1094 rb_iv_set(mNcurses, "@infd", INT2FIX(0));
1095 rb_iv_set(mNcurses, "@halfdelay", INT2FIX(0));
1096 rb_iv_set(mNcurses, "@cbreak", Qfalse);
1097 return v;
1098 }
1099 static VALUE rbncurs_init_color(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1100 return INT2NUM(init_color(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4)));
1101 }
1102 static VALUE rbncurs_init_pair(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1103 return INT2NUM(init_pair(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3)));
1104 }
1105 static VALUE rbncurs_insch(VALUE dummy, VALUE arg1) {
1106 return INT2NUM(insch((int) NUM2ULONG(arg1)));
1107 }
1108 static VALUE rbncurs_insdelln(VALUE dummy, VALUE arg1) {
1109 return INT2NUM(insdelln(NUM2INT(arg1)));
1110 }
1111 static VALUE rbncurs_insertln(VALUE dummy) {
1112 return INT2NUM(insertln());
1113 }
1114 static VALUE rbncurs_insnstr(VALUE dummy, VALUE arg1, VALUE arg2) {
1115 return INT2NUM(insnstr(STR2CSTR(arg1), NUM2INT(arg2)));
1116 }
1117 static VALUE rbncurs_insstr(VALUE dummy, VALUE arg1) {
1118 return INT2NUM(insstr(STR2CSTR(arg1)));
1119 }
1120 #ifdef HAVE_INTRFLUSH
1121 static VALUE rbncurs_intrflush(VALUE dummy, VALUE arg1, VALUE arg2) {
1122 return INT2NUM(intrflush(get_window(arg1), RTEST(arg2)));
1123 }
1124 #endif
1125 static VALUE rbncurs_isendwin(VALUE dummy) {
1126 return (isendwin()) ? Qtrue : Qfalse;
1127 }
1128 static VALUE rbncurs_is_linetouched(VALUE dummy, VALUE arg1, VALUE arg2) {
1129 return (is_linetouched(get_window(arg1), NUM2INT(arg2))) ? Qtrue : Qfalse;
1130 }
1131 static VALUE rbncurs_is_wintouched(VALUE dummy, VALUE arg1) {
1132 return (is_wintouched(get_window(arg1))) ? Qtrue : Qfalse;
1133 }
1134 static VALUE rbncurs_keyname(VALUE dummy, VALUE arg1) {
1135 const char * str = keyname(NUM2INT(arg1));
1136 if (str == NULL) return Qnil;
1137 return rb_str_new2(str);
1138 }
1139 static VALUE rbncurs_keypad(VALUE dummy, VALUE arg1, VALUE arg2) {
1140 return INT2NUM(keypad(get_window(arg1), RTEST(arg2)));
1141 }
1142 static VALUE rbncurs_killchar(VALUE dummy) {
1143 return INT2NUM(killchar());
1144 }
1145 static VALUE rbncurs_leaveok(VALUE dummy, VALUE arg1, VALUE arg2) {
1146 return INT2NUM(leaveok(get_window(arg1), RTEST(arg2)));
1147 }
1148 static VALUE rbncurs_longname(VALUE dummy) {
1149 return rb_str_new2(longname());
1150 }
1151 static VALUE rbncurs_meta(VALUE dummy, VALUE arg1, VALUE arg2) {
1152 return INT2NUM(meta(get_window(arg1), RTEST(arg2)));
1153 }
1154 static VALUE rbncurs_move(VALUE dummy, VALUE arg1, VALUE arg2) {
1155 return INT2NUM(move(NUM2INT(arg1), NUM2INT(arg2)));
1156 }
1157 static VALUE rbncurs_mvaddch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1158 return INT2NUM(mvaddch(NUM2INT(arg1), NUM2INT(arg2), (int) NUM2ULONG(arg3)));
1159 }
1160 static VALUE rbncurs_mvaddchnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3,
1161 VALUE arg4) {
1162 chtype * chstr = RB2CHSTR(arg3);
1163 VALUE return_value = INT2NUM(mvaddchnstr(NUM2INT(arg1), NUM2INT(arg2),
1164 chstr, NUM2INT(arg4)));
1165 xfree(chstr);
1166 return return_value;
1167 }
1168 static VALUE rbncurs_mvaddchstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1169 chtype * chstr = RB2CHSTR(arg3);
1170 VALUE return_value = INT2NUM(mvaddchstr(NUM2INT(arg1), NUM2INT(arg2),
1171 chstr));
1172 xfree(chstr);
1173 return return_value;
1174 }
1175 static VALUE rbncurs_mvaddnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1176 return INT2NUM(mvaddnstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3), NUM2INT(arg4)));
1177 }
1178 static VALUE rbncurs_mvaddstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1179 return INT2NUM(mvaddstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3)));
1180 }
1181 #ifdef HAVE_MVCHGAT
1182 static VALUE rbncurs_mvchgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6) {
1183 return INT2NUM(mvchgat(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), (int) NUM2ULONG(arg4), NUM2INT(arg5), ((void)(arg6),NULL)));
1184 }
1185 #endif
1186 static VALUE rbncurs_mvcur(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1187 return INT2NUM(mvcur(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4)));
1188 }
1189 static VALUE rbncurs_mvdelch(VALUE dummy, VALUE arg1, VALUE arg2) {
1190 return INT2NUM(mvdelch(NUM2INT(arg1), NUM2INT(arg2)));
1191 }
1192 static VALUE rbncurs_mvderwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1193 return INT2NUM(mvderwin(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
1194 }
1195 static VALUE rbncurs_mvgetch(VALUE dummy, VALUE arg1, VALUE arg2) {
1196 int windelay = NUM2INT(rb_iv_get(get_stdscr(dummy), "@timeout"));
1197 if (wmove(stdscr, NUM2INT(arg1), NUM2INT(arg2)) == ERR)
1198 return INT2NUM(ERR);
1199 return INT2NUM(rbncurshelper_nonblocking_wgetch(stdscr, windelay));
1200 }
1201 #ifdef HAVE_MVHLINE
1202 static VALUE rbncurs_mvhline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1203 return INT2NUM(mvhline(NUM2INT(arg1), NUM2INT(arg2), (int) NUM2ULONG(arg3), NUM2INT(arg4)));
1204 }
1205 #endif
1206 static VALUE rbncurs_mvinch(VALUE dummy, VALUE arg1, VALUE arg2) {
1207 return INT2NUM(mvinch(NUM2INT(arg1), NUM2INT(arg2)));
1208 }
1209 static VALUE rbncurs_mvinsch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1210 return INT2NUM(mvinsch(NUM2INT(arg1), NUM2INT(arg2), (int) NUM2ULONG(arg3)));
1211 }
1212 static VALUE rbncurs_mvinsnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1213 return INT2NUM(mvinsnstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3), NUM2INT(arg4)));
1214 }
1215 static VALUE rbncurs_mvinsstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1216 return INT2NUM(mvinsstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3)));
1217 }
1218 #ifdef HAVE_MVVLINE
1219 static VALUE rbncurs_mvvline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1220 return INT2NUM(mvvline(NUM2INT(arg1), NUM2INT(arg2), (int) NUM2ULONG(arg3), NUM2INT(arg4)));
1221 }
1222 #endif
1223 static VALUE rbncurs_mvwaddch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1224 return INT2NUM(mvwaddch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), (int) NUM2ULONG(arg4)));
1225 }
1226 static VALUE rbncurs_mvwaddchnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3,
1227 VALUE arg4, VALUE arg5) {
1228 chtype * chstr = RB2CHSTR(arg4);
1229 VALUE return_value = INT2NUM(mvwaddchnstr(get_window(arg1), NUM2INT(arg2),
1230 NUM2INT(arg3), chstr,
1231 NUM2INT(arg5)));
1232 xfree(chstr);
1233 return return_value;
1234 }
1235 static VALUE rbncurs_mvwaddchstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3,
1236 VALUE arg4) {
1237 chtype * chstr = RB2CHSTR(arg4);
1238 VALUE return_value = INT2NUM(mvwaddchstr(get_window(arg1), NUM2INT(arg2),
1239 NUM2INT(arg3), chstr));
1240 xfree(chstr);
1241 return return_value;
1242 }
1243 static VALUE rbncurs_mvwaddnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
1244 return INT2NUM(mvwaddnstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4), NUM2INT(arg5)));
1245 }
1246 static VALUE rbncurs_mvwaddstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1247 return INT2NUM(mvwaddstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4)));
1248 }
1249 #ifdef HAVE_MVWCHGAT
1250 static VALUE rbncurs_mvwchgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7) {
1251 return INT2NUM(mvwchgat(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), (int) NUM2ULONG(arg5), NUM2INT(arg6), ((void)(arg7),NULL)));
1252 }
1253 #endif
1254 static VALUE rbncurs_mvwdelch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1255 return INT2NUM(mvwdelch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
1256 }
1257 static VALUE rbncurs_mvwgetch(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x) {
1258 WINDOW * c_win = get_window(rb_win);
1259 int windelay = NUM2INT(rb_iv_get(rb_win, "@timeout"));
1260 if (wmove(c_win, NUM2INT(rb_y), NUM2INT(rb_x)) == ERR)
1261 return INT2NUM(ERR);
1262 return INT2NUM(rbncurshelper_nonblocking_wgetch(c_win, windelay));
1263 }
1264 #ifdef HAVE_MVWHLINE
1265 static VALUE rbncurs_mvwhline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
1266 return INT2NUM(mvwhline(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), (int) NUM2ULONG(arg4), NUM2INT(arg5)));
1267 }
1268 #endif
1269 static VALUE rbncurs_mvwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1270 return INT2NUM(mvwin(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
1271 }
1272 static VALUE rbncurs_mvwinch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1273 return INT2NUM(mvwinch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
1274 }
1275 static VALUE rbncurs_mvwinsch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1276 return INT2NUM(mvwinsch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), (int) NUM2ULONG(arg4)));
1277 }
1278 static VALUE rbncurs_mvwinsnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
1279 return INT2NUM(mvwinsnstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4), NUM2INT(arg5)));
1280 }
1281 static VALUE rbncurs_mvwinsstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1282 return INT2NUM(mvwinsstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4)));
1283 }
1284 #ifdef HAVE_MVWVLINE
1285 static VALUE rbncurs_mvwvline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
1286 return INT2NUM(mvwvline(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), (int) NUM2ULONG(arg4), NUM2INT(arg5)));
1287 }
1288 #endif
1289 static VALUE rbncurs_napms(VALUE dummy, VALUE arg1) {
1290 return INT2NUM(napms(NUM2INT(arg1)));
1291 }
1292 static VALUE rbncurs_newpad(VALUE dummy, VALUE arg1, VALUE arg2) {
1293 return wrap_window(newpad(NUM2INT(arg1), NUM2INT(arg2)));
1294 }
1295 static VALUE rbncurs_newwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1296 return wrap_window(newwin(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4)));
1297 }
1298 static VALUE rbncurs_nl(VALUE dummy) {
1299 return INT2NUM(nl());
1300 }
1301 static VALUE rbncurs_nocbreak(VALUE dummy) {
1302 return INT2NUM(rbncurshelper_halfdelay_cbreak(0, 0));
1303 }
1304 static VALUE rbncurs_nodelay(VALUE dummy, VALUE arg1, VALUE arg2) {
1305 bool flag = RTEST(arg2);
1306 int return_value = nodelay(get_window(arg1), flag);
1307 if (return_value != ERR) {
1308 rb_iv_set(arg1, "@timeout", INT2FIX(flag ? 0 : -1));
1309 }
1310 return INT2NUM(return_value);
1311 }
1312 static VALUE rbncurs_noecho(VALUE dummy) {
1313 return INT2NUM(noecho());
1314 }
1315 static VALUE rbncurs_nonl(VALUE dummy) {
1316 return INT2NUM(nonl());
1317 }
1318 #ifdef HAVE_NOQIFLUSH
1319 static VALUE rbncurs_noqiflush(VALUE dummy) {
1320 return ((noqiflush()),Qnil);
1321 }
1322 #endif
1323 static VALUE rbncurs_noraw(VALUE dummy) {
1324 return INT2NUM(noraw());
1325 }
1326 static VALUE rbncurs_notimeout(VALUE dummy, VALUE arg1, VALUE arg2) {
1327 return INT2NUM(notimeout(get_window(arg1), RTEST(arg2)));
1328 }
1329 static VALUE rbncurs_overlay(VALUE dummy, VALUE arg1, VALUE arg2) {
1330 return INT2NUM(overlay(get_window(arg1), get_window(arg2)));
1331 }
1332 static VALUE rbncurs_overwrite(VALUE dummy, VALUE arg1, VALUE arg2) {
1333 return INT2NUM(overwrite(get_window(arg1), get_window(arg2)));
1334 }
1335 static VALUE rbncurs_PAIR_NUMBER(VALUE dummy, VALUE arg1) {
1336 return INT2NUM(PAIR_NUMBER(NUM2INT(arg1)));
1337 }
1338 #ifndef __PDCURSES__ /* pdcurses "pechochar" macro won't compile*/
1339 static VALUE rbncurs_pechochar(VALUE dummy, VALUE arg1, VALUE arg2) {
1340 return INT2NUM(pechochar(get_window(arg1), (int) NUM2ULONG(arg2)));
1341 }
1342 #endif
1343 static VALUE rbncurs_pnoutrefresh(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7) {
1344 return INT2NUM(pnoutrefresh(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5), NUM2INT(arg6), NUM2INT(arg7)));
1345 }
1346 static VALUE rbncurs_prefresh(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7) {
1347 return INT2NUM(prefresh(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5), NUM2INT(arg6), NUM2INT(arg7)));
1348 }
1349 #ifdef HAVE_PUTP
1350 static VALUE rbncurs_putp(VALUE dummy, VALUE arg1) {
1351 return INT2NUM(putp(STR2CSTR(arg1)));
1352 }
1353 #endif
1354 #ifdef HAVE_QIFLUSH
1355 static VALUE rbncurs_qiflush(VALUE dummy) {
1356 return ((qiflush()),Qnil);
1357 }
1358 #endif
1359 static VALUE rbncurs_raw(VALUE dummy) {
1360 return INT2NUM(raw());
1361 }
1362 #ifndef __PDCURSES__ /* __PDCURSES__ redrawwin macro is buggy */
1363 static VALUE rbncurs_redrawwin(VALUE dummy, VALUE arg1) {
1364 return INT2NUM(redrawwin(get_window(arg1)));
1365 }
1366 #endif
1367 static VALUE rbncurs_refresh(VALUE dummy) {
1368 return INT2NUM(refresh());
1369 }
1370 static VALUE rbncurs_resetty(VALUE dummy) {
1371 return INT2NUM(resetty());
1372 }
1373 static VALUE rbncurs_reset_prog_mode(VALUE dummy) {
1374 return INT2NUM(reset_prog_mode());
1375 }
1376 static VALUE rbncurs_reset_shell_mode(VALUE dummy) {
1377 return INT2NUM(reset_shell_mode());
1378 }
1379 static VALUE rbncurs_savetty(VALUE dummy) {
1380 return INT2NUM(savetty());
1381 }
1382 #ifdef HAVE_SCR_DUMP
1383 static VALUE rbncurs_scr_dump(VALUE dummy, VALUE arg1) {
1384 return INT2NUM(scr_dump(STR2CSTR(arg1)));
1385 }
1386 #endif
1387 #ifdef HAVE_SCR_INIT
1388 static VALUE rbncurs_scr_init(VALUE dummy, VALUE arg1) {
1389 return INT2NUM(scr_init(STR2CSTR(arg1)));
1390 }
1391 #endif
1392 static VALUE rbncurs_scrl(VALUE dummy, VALUE arg1) {
1393 return INT2NUM(scrl(NUM2INT(arg1)));
1394 }
1395 static VALUE rbncurs_scroll(VALUE dummy, VALUE arg1) {
1396 return INT2NUM(scroll(get_window(arg1)));
1397 }
1398 static VALUE rbncurs_scrollok(VALUE dummy, VALUE arg1, VALUE arg2) {
1399 return INT2NUM(scrollok(get_window(arg1), RTEST(arg2)));
1400 }
1401 #ifdef HAVE_SCR_RESTORE
1402 static VALUE rbncurs_scr_restore(VALUE dummy, VALUE arg1) {
1403 return INT2NUM(scr_restore(STR2CSTR(arg1)));
1404 }
1405 #endif
1406 #ifdef HAVE_SCR_SET
1407 static VALUE rbncurs_scr_set(VALUE dummy, VALUE arg1) {
1408 return INT2NUM(scr_set(STR2CSTR(arg1)));
1409 }
1410 #endif
1411 static VALUE rbncurs_setscrreg(VALUE dummy, VALUE arg1, VALUE arg2) {
1412 return INT2NUM(setscrreg(NUM2INT(arg1), NUM2INT(arg2)));
1413 }
1414 static VALUE rbncurs_set_term(VALUE dummy, VALUE rb_new_screen) {
1415 VALUE rb_old_screen = wrap_screen(set_term(get_screen(rb_new_screen)));
1416 rb_iv_set(rb_old_screen, "@infd", rb_iv_get(mNcurses, "@infd"));
1417 rb_iv_set(rb_old_screen, "@halfdelay", rb_iv_get(mNcurses, "@halfdelay"));
1418 rb_iv_set(rb_old_screen, "@cbreak", rb_iv_get(mNcurses, "@cbreak"));
1419 rb_iv_set(mNcurses, "@infd", rb_iv_get(rb_new_screen, "@infd"));
1420 rb_iv_set(mNcurses, "@halfdelay", rb_iv_get(rb_new_screen, "@halfdelay"));
1421 rb_iv_set(mNcurses, "@cbreak", rb_iv_get(rb_new_screen, "@cbreak"));
1422
1423 rbncurshelper_halfdelay_cbreak_restore();
1424 return rb_old_screen;
1425 }
1426 static VALUE rbncurs_slk_attroff(VALUE dummy, VALUE arg1) {
1427 return INT2NUM(slk_attroff((int) NUM2ULONG(arg1)));
1428 }
1429 static VALUE rbncurs_slk_attron(VALUE dummy, VALUE arg1) {
1430 return INT2NUM(slk_attron((int) NUM2ULONG(arg1)));
1431 }
1432 static VALUE rbncurs_slk_attrset(VALUE dummy, VALUE arg1) {
1433 return INT2NUM(slk_attrset((int) NUM2ULONG(arg1)));
1434 }
1435 #ifdef HAVE_SLK_ATTR
1436 static VALUE rbncurs_slk_attr(VALUE dummy) {
1437 return INT2NUM(slk_attr());
1438 }
1439 #endif
1440
1441 static VALUE rbncurs_slk_clear(VALUE dummy) {
1442 return INT2NUM(slk_clear());
1443 }
1444 #ifdef HAVE_SLK_COLOR
1445 static VALUE rbncurs_slk_color(VALUE dummy, VALUE arg1) {
1446 return INT2NUM(slk_color(NUM2INT(arg1)));
1447 }
1448 #endif
1449 static VALUE rbncurs_slk_init(VALUE dummy, VALUE arg1) {
1450 return INT2NUM(slk_init(NUM2INT(arg1)));
1451 }
1452 static VALUE rbncurs_slk_label(VALUE dummy, VALUE arg1) {
1453 char * str = slk_label(NUM2INT(arg1));
1454 if (str == NULL) return Qnil;
1455 return rb_str_new2(str);
1456 }
1457 static VALUE rbncurs_slk_noutrefresh(VALUE dummy) {
1458 return INT2NUM(slk_noutrefresh());
1459 }
1460 static VALUE rbncurs_slk_refresh(VALUE dummy) {
1461 return INT2NUM(slk_refresh());
1462 }
1463 static VALUE rbncurs_slk_restore(VALUE dummy) {
1464 return INT2NUM(slk_restore());
1465 }
1466 static VALUE rbncurs_slk_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1467 return INT2NUM(slk_set(NUM2INT(arg1), STR2CSTR(arg2), NUM2INT(arg3)));
1468 }
1469 static VALUE rbncurs_slk_touch(VALUE dummy) {
1470 return INT2NUM(slk_touch());
1471 }
1472 static VALUE rbncurs_standout(VALUE dummy) {
1473 return INT2NUM(standout());
1474 }
1475 static VALUE rbncurs_standend(VALUE dummy) {
1476 return INT2NUM(standend());
1477 }
1478 static VALUE rbncurs_start_color(VALUE dummy) {
1479 return INT2NUM(start_color());
1480 }
1481 static VALUE rbncurs_subpad(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
1482 return wrap_window(subpad(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5)));
1483 }
1484 static VALUE rbncurs_subwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
1485 return wrap_window(subwin(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5)));
1486 }
1487 static VALUE rbncurs_syncok(VALUE dummy, VALUE arg1, VALUE arg2) {
1488 return INT2NUM(syncok(get_window(arg1), RTEST(arg2)));
1489 }
1490 static VALUE rbncurs_termattrs(VALUE dummy) {
1491 return INT2NUM(termattrs());
1492 }
1493 static VALUE rbncurs_termname(VALUE dummy) {
1494 return rb_str_new2(termname());
1495 }
1496 #ifdef HAVE_TIGETFLAG
1497 static VALUE rbncurs_tigetflag(VALUE dummy, VALUE arg1) {
1498 return INT2NUM(tigetflag(STR2CSTR(arg1)));
1499 }
1500 #endif
1501 #ifdef HAVE_TIGETNUM
1502 static VALUE rbncurs_tigetnum(VALUE dummy, VALUE arg1) {
1503 return INT2NUM(tigetnum(STR2CSTR(arg1)));
1504 }
1505 #endif
1506 #ifdef HAVE_TIGETSTR
1507 static VALUE rbncurs_tigetstr(VALUE dummy, VALUE arg1) {
1508 char * str = tigetstr(STR2CSTR(arg1));
1509 if (str == NULL || str == (char *)-1) return Qnil;
1510 return rb_str_new2(str);
1511 }
1512 #endif
1513 static VALUE rbncurs_timeout(VALUE dummy, VALUE arg1) {
1514 rb_iv_set(get_stdscr(dummy), "@timeout", arg1);
1515 return ((timeout(NUM2INT(arg1))),Qnil);
1516 }
1517 static VALUE rbncurs_typeahead(VALUE dummy, VALUE arg1) {
1518 return INT2NUM(typeahead(NUM2INT(arg1)));
1519 }
1520 static VALUE rbncurs_ungetch(VALUE dummy, VALUE arg1) {
1521 return INT2NUM(ungetch(NUM2INT(arg1)));
1522 }
1523 static VALUE rbncurs_untouchwin(VALUE dummy, VALUE arg1) {
1524 return INT2NUM(untouchwin(get_window(arg1)));
1525 }
1526 #ifdef HAVE_USE_ENV
1527 static VALUE rbncurs_use_env(VALUE dummy, VALUE arg1) {
1528 return ((use_env(RTEST(arg1))),Qnil);
1529 }
1530 #endif
1531 #ifdef HAVE_VIDATTR
1532 static VALUE rbncurs_vidattr(VALUE dummy, VALUE arg1) {
1533 return INT2NUM(vidattr((int) NUM2ULONG(arg1)));
1534 }
1535 #endif
1536 static VALUE rbncurs_vline(VALUE dummy, VALUE arg1, VALUE arg2) {
1537 return INT2NUM(vline((int) NUM2ULONG(arg1), NUM2INT(arg2)));
1538 }
1539 static VALUE rbncurs_waddch(VALUE dummy, VALUE arg1, VALUE arg2) {
1540 return INT2NUM(waddch(get_window(arg1), (int) NUM2ULONG(arg2)));
1541 }
1542 #ifdef HAVE_ADD_WCH
1543 static VALUE rbncurs_wadd_wch(VALUE dummy, VALUE arg1, VALUE arg2) {
1544 cchar_t t = { 0, { NUM2ULONG(arg2), 0 } };
1545 return INT2NUM(wadd_wch(get_window(arg1), &t));
1546 }
1547 #endif
1548 static VALUE rbncurs_waddchnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1549 chtype * chstr = RB2CHSTR(arg2);
1550 VALUE return_value = INT2NUM(waddchnstr(get_window(arg1), chstr,
1551 NUM2INT(arg3)));
1552 xfree(chstr);
1553 return return_value;
1554 }
1555 static VALUE rbncurs_waddchstr(VALUE dummy, VALUE arg1, VALUE arg2) {
1556 chtype * chstr = RB2CHSTR(arg2);
1557 VALUE return_value = INT2NUM(waddchstr(get_window(arg1), chstr));
1558 xfree(chstr);
1559 return return_value;
1560 }
1561 static VALUE rbncurs_waddnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1562 return INT2NUM(waddnstr(get_window(arg1), STR2CSTR(arg2), NUM2INT(arg3)));
1563 }
1564 static VALUE rbncurs_waddstr(VALUE dummy, VALUE arg1, VALUE arg2) {
1565 return INT2NUM(waddstr(get_window(arg1), STR2CSTR(arg2)));
1566 }
1567 static VALUE rbncurs_wattron(VALUE dummy, VALUE arg1, VALUE arg2) {
1568 return INT2NUM(wattron(get_window(arg1), NUM2INT(arg2)));
1569 }
1570 static VALUE rbncurs_wattroff(VALUE dummy, VALUE arg1, VALUE arg2) {
1571 return INT2NUM(wattroff(get_window(arg1), NUM2INT(arg2)));
1572 }
1573 static VALUE rbncurs_wattrset(VALUE dummy, VALUE arg1, VALUE arg2) {
1574 return INT2NUM(wattrset(get_window(arg1), NUM2INT(arg2)));
1575 }
1576 static VALUE rbncurs_wbkgd(VALUE dummy, VALUE arg1, VALUE arg2) {
1577 return INT2NUM(wbkgd(get_window(arg1), (int) NUM2ULONG(arg2)));
1578 }
1579 static VALUE rbncurs_wbkgdset(VALUE dummy, VALUE arg1, VALUE arg2) {
1580 return ((wbkgdset(get_window(arg1), (int) NUM2ULONG(arg2))),Qnil);
1581 }
1582 static VALUE rbncurs_wborder(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7, VALUE arg8, VALUE arg9) {
1583 return INT2NUM(wborder(get_window(arg1), (int) NUM2ULONG(arg2), (int) NUM2ULONG(arg3), (int) NUM2ULONG(arg4), (int) NUM2ULONG(arg5), (int) NUM2ULONG(arg6), (int) NUM2ULONG(arg7), (int) NUM2ULONG(arg8), (int) NUM2ULONG(arg9)));
1584 }
1585 #ifdef HAVE_WCHGAT
1586 static VALUE rbncurs_wchgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) {
1587 return INT2NUM(wchgat(get_window(arg1), NUM2INT(arg2), (int) NUM2ULONG(arg3), NUM2INT(arg4), ((void)(arg5),NULL)));
1588 }
1589 #endif
1590 static VALUE rbncurs_wclear(VALUE dummy, VALUE arg1) {
1591 return INT2NUM(wclear(get_window(arg1)));
1592 }
1593 static VALUE rbncurs_wclrtobot(VALUE dummy, VALUE arg1) {
1594 return INT2NUM(wclrtobot(get_window(arg1)));
1595 }
1596 static VALUE rbncurs_wclrtoeol(VALUE dummy, VALUE arg1) {
1597 return INT2NUM(wclrtoeol(get_window(arg1)));
1598 }
1599 #ifdef HAVE_WCOLOR_SET
1600 static VALUE rbncurs_wcolor_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1601 return INT2NUM(wcolor_set(get_window(arg1), NUM2INT(arg2), ((void)(arg3),NULL)));
1602 }
1603 #endif
1604 static VALUE rbncurs_wcursyncup(VALUE dummy, VALUE arg1) {
1605 return ((wcursyncup(get_window(arg1))),Qnil);
1606 }
1607 static VALUE rbncurs_wdelch(VALUE dummy, VALUE arg1) {
1608 return INT2NUM(wdelch(get_window(arg1)));
1609 }
1610 static VALUE rbncurs_wdeleteln(VALUE dummy, VALUE arg1) {
1611 return INT2NUM(wdeleteln(get_window(arg1)));
1612 }
1613 static VALUE rbncurs_wechochar(VALUE dummy, VALUE arg1, VALUE arg2) {
1614 return INT2NUM(wechochar(get_window(arg1), (int) NUM2ULONG(arg2)));
1615 }
1616 static VALUE rbncurs_werase(VALUE dummy, VALUE arg1) {
1617 return INT2NUM(werase(get_window(arg1)));
1618 }
1619 static VALUE rbncurs_wgetch(VALUE dummy, VALUE arg1) {
1620 int windelay = NUM2INT(rb_iv_get(arg1, "@timeout"));
1621 return INT2NUM(rbncurshelper_nonblocking_wgetch(get_window(arg1), windelay));
1622 }
1623
1624 #ifdef HAVE_GET_WCH
1625 static VALUE rbncurs_wget_wch(VALUE dummy, VALUE arg1) {
1626 int windelay = NUM2INT(rb_iv_get(arg1, "@timeout"));
1627 return rbncurshelper_nonblocking_wget_wch(get_window(arg1), windelay);
1628 }
1629 #endif
1630
1631 static VALUE rbncurs_whline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1632 return INT2NUM(whline(get_window(arg1), (int) NUM2ULONG(arg2), NUM2INT(arg3)));
1633 }
1634 static VALUE rbncurs_winch(VALUE dummy, VALUE arg1) {
1635 return INT2NUM(winch(get_window(arg1)));
1636 }
1637 static VALUE rbncurs_winsch(VALUE dummy, VALUE arg1, VALUE arg2) {
1638 return INT2NUM(winsch(get_window(arg1), (int) NUM2ULONG(arg2)));
1639 }
1640 static VALUE rbncurs_winsdelln(VALUE dummy, VALUE arg1, VALUE arg2) {
1641 return INT2NUM(winsdelln(get_window(arg1), NUM2INT(arg2)));
1642 }
1643 static VALUE rbncurs_winsertln(VALUE dummy, VALUE arg1) {
1644 return INT2NUM(winsertln(get_window(arg1)));
1645 }
1646 static VALUE rbncurs_winsnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1647 return INT2NUM(winsnstr(get_window(arg1), STR2CSTR(arg2), NUM2INT(arg3)));
1648 }
1649 static VALUE rbncurs_winsstr(VALUE dummy, VALUE arg1, VALUE arg2) {
1650 return INT2NUM(winsstr(get_window(arg1), STR2CSTR(arg2)));
1651 }
1652 static VALUE rbncurs_wmove(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1653 return INT2NUM(wmove(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
1654 }
1655 static VALUE rbncurs_wnoutrefresh(VALUE dummy, VALUE arg1) {
1656 return INT2NUM(wnoutrefresh(get_window(arg1)));
1657 }
1658 static VALUE rbncurs_wredrawln(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1659 return INT2NUM(wredrawln(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
1660 }
1661 static VALUE rbncurs_wrefresh(VALUE dummy, VALUE arg1) {
1662 return INT2NUM(wrefresh(get_window(arg1)));
1663 }
1664 static VALUE rbncurs_wscrl(VALUE dummy, VALUE arg1, VALUE arg2) {
1665 return INT2NUM(wscrl(get_window(arg1), NUM2INT(arg2)));
1666 }
1667 static VALUE rbncurs_wsetscrreg(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1668 return INT2NUM(wsetscrreg(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3)));
1669 }
1670 static VALUE rbncurs_wstandout(VALUE dummy, VALUE arg1) {
1671 return INT2NUM(wstandout(get_window(arg1)));
1672 }
1673 static VALUE rbncurs_wstandend(VALUE dummy, VALUE arg1) {
1674 return INT2NUM(wstandend(get_window(arg1)));
1675 }
1676 static VALUE rbncurs_wsyncdown(VALUE dummy, VALUE arg1) {
1677 return ((wsyncdown(get_window(arg1))),Qnil);
1678 }
1679 static VALUE rbncurs_wsyncup(VALUE dummy, VALUE arg1) {
1680 return ((wsyncup(get_window(arg1))),Qnil);
1681 }
1682 static VALUE rbncurs_wtimeout(VALUE dummy, VALUE arg1, VALUE arg2) {
1683 rb_iv_set(arg1, "@timeout", arg2);
1684 return ((wtimeout(get_window(arg1), NUM2INT(arg2))),Qnil);
1685 }
1686 static VALUE rbncurs_wtouchln(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) {
1687 return INT2NUM(wtouchln(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4)));
1688 }
1689 static VALUE rbncurs_wvline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
1690 return INT2NUM(wvline(get_window(arg1), (int)NUM2ULONG(arg2), NUM2INT(arg3)));
1691 }
1692 static VALUE rbncurs_color_content(VALUE dummy, VALUE color, VALUE r, VALUE g, VALUE b) {
1693 if (rb_obj_is_instance_of(r, rb_cArray) != Qtrue
1694 || rb_obj_is_instance_of(g, rb_cArray) != Qtrue
1695 || rb_obj_is_instance_of(b, rb_cArray) != Qtrue) {
1696 rb_raise(rb_eArgError,
1697 "r,g and b (2nd to 4th argument) must be an empty Arrays");
1698 return Qnil;
1699 }
1700 {
1701 short cv[3] = {0,0,0};
1702 int return_value = color_content(NUM2INT(color), &cv[0], &cv[1],
1703 &cv[2]);
1704 rb_ary_push(r, INT2NUM(cv[0])); rb_ary_push(g, INT2NUM(cv[1]));
1705 rb_ary_push(b, INT2NUM(cv[2])); return INT2NUM(return_value);
1706 }
1707 }
1708 static VALUE rbncurs_pair_content(VALUE dummy, VALUE pair, VALUE fg, VALUE bg) {
1709 if (rb_obj_is_instance_of(fg, rb_cArray) != Qtrue
1710 || rb_obj_is_instance_of(bg, rb_cArray) != Qtrue) {
1711 rb_raise(rb_eArgError,
1712 "fg and bg (2nd and 3rd argument) must be an empty Arrays");
1713 return Qnil;
1714 }
1715 {
1716 short cn[2] = {0,0};
1717 int return_value = pair_content(NUM2INT(pair), &cn[0], &cn[1]);
1718 rb_ary_push(fg, INT2NUM(cn[0])); rb_ary_push(bg, INT2NUM(cn[1]));
1719 return INT2NUM(return_value);
1720 }
1721 }
1722 #ifdef HAVE_GETWIN
1723 static VALUE rbncurs_getwin(VALUE dummy, VALUE io)
1724 {
1725 int fd = dup(NUM2INT(rb_funcall(io, rb_intern("to_i"), 0)));
1726 FILE * f = fdopen(fd, "r");
1727 WINDOW * win = getwin(f);
1728 fclose(f);
1729 close(fd);
1730 {
1731 VALUE return_value = Qnil;
1732 if (win) return_value = wrap_window(win);
1733 return return_value;
1734 }
1735 }
1736 #endif
1737 #ifdef HAVE_PUTWIN
1738 static VALUE rbncurs_putwin(VALUE dummy, VALUE rb_win, VALUE io)
1739 {
1740 int fd = dup(NUM2INT(rb_funcall(io, rb_intern("to_i"), 0)));
1741 FILE * f = fdopen(fd, "w");
1742 WINDOW * win = get_window(rb_win);
1743 int return_value = putwin(win, f);
1744 fclose(f);
1745 close(fd);
1746 return INT2NUM(return_value);
1747 }
1748 #endif
1749 static VALUE rbncurs_unctrl(VALUE dummy, VALUE ch)
1750 { return rb_str_new2(unctrl((int)NUM2ULONG(ch))); }
1751 static VALUE rbncurs_newterm(VALUE dummy, VALUE rb_type, VALUE rb_outfd, VALUE rb_infd)
1752 {
1753 char * type = (rb_type == Qnil) ? (char*)0 : STR2CSTR(rb_type);
1754 int outfd = NUM2INT(rb_funcall(rb_outfd, rb_intern("to_i"), 0));
1755 int infd = NUM2INT(rb_funcall(rb_infd, rb_intern("to_i"), 0));
1756 VALUE rb_screen =
1757 wrap_screen(newterm(type, fdopen(outfd, "w"), fdopen(infd, "r")));
1758 if (RTEST(rb_screen)) {
1759 Init_ncurses_full();
1760 rbncurshelper_halfdelay_cbreak_restore();
1761 }
1762 rb_iv_set(mNcurses, "@infd", INT2NUM(infd));
1763 rb_iv_set(rb_screen, "@infd", INT2NUM(infd));
1764 rb_iv_set(mNcurses, "@halfdelay", INT2FIX(0));
1765 rb_iv_set(rb_screen, "@halfdelay", INT2FIX(0));
1766 rb_iv_set(mNcurses, "@cbreak", Qfalse);
1767 rb_iv_set(rb_screen, "@cbreak", Qfalse);
1768 return rb_screen;
1769 }
1770
1771
1772 static void init_functions_2(void) {
1773 NCFUNC(addch, 1);
1774 #ifdef HAVE_ADD_WCH
1775 NCFUNC(add_wch, 1);
1776 #endif
1777 NCFUNC(addchnstr, 2);
1778 NCFUNC(addchstr, 1);
1779 NCFUNC(addnstr, 2);
1780 NCFUNC(addstr, 1);
1781 NCFUNC(attroff, 1);
1782 NCFUNC(attron, 1);
1783 NCFUNC(attrset, 1);
1784 #if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR > 4
1785 #ifdef HAVE_ATTR_OFF
1786 NCFUNC(attr_off, 2);
1787 #endif
1788 #ifdef HAVE_ATTR_ON
1789 NCFUNC(attr_on, 2);
1790 #endif
1791 #ifdef HAVE_ATTR_SET
1792 NCFUNC(attr_set, 3);
1793 #endif
1794 #if defined(HAVE_SLK_ATTR_OFF) || defined(slk_attr_off)
1795 NCFUNC(slk_attr_off, 2);
1796 #endif
1797 #if defined(HAVE_SLK_ATTR_ON) || defined(slk_attr_on)
1798 NCFUNC(slk_attr_on, 2);
1799 #endif
1800 #ifdef HAVE_SLK_ATTR_SET
1801 NCFUNC(slk_attr_set, 3);
1802 #endif
1803 #ifdef HAVE_WATTR_ON
1804 NCFUNC(wattr_on, 3);
1805 #endif
1806 #ifdef HAVE_WATTR_OFF
1807 NCFUNC(wattr_off, 3);
1808 #endif
1809 #ifdef HAVE_WATTR_SET
1810 NCFUNC(wattr_set, 4);
1811 #endif
1812 #if defined (HAVE_VID_ATTR) || defined(vid_attr)
1813 NCFUNC(vid_attr, 3);
1814 #endif
1815 #ifdef HAVE_ATTR_GET
1816 NCFUNC(attr_get, 3);
1817 NCFUNC(wattr_get, 4);
1818 #endif /* HAVE_ATTR_GET */
1819 #endif
1820 NCFUNC(baudrate, 0);
1821 NCFUNC(beep, 0);
1822 NCFUNC(bkgd, 1);
1823 NCFUNC(bkgdset, 1);
1824 NCFUNC(border, 8);
1825 NCFUNC(box, 3);
1826 rb_define_module_function(mNcurses, "can_change_color?",
1827 (&rbncurs_can_change_color),
1828 0);
1829 NCFUNC(cbreak, 0);
1830 #ifdef HAVE_CHGAT
1831 NCFUNC(chgat, 4);
1832 #endif
1833 NCFUNC(clear, 0);
1834 NCFUNC(clearok, 2);
1835 NCFUNC(clrtobot, 0);
1836 NCFUNC(clrtoeol, 0);
1837 #ifdef HAVE_COLOR_SET
1838 NCFUNC(color_set, 2);
1839 #endif
1840 NCFUNC(COLOR_PAIR, 1);
1841 NCFUNC(color_pair, 1);
1842 NCFUNC(copywin, 9);
1843 NCFUNC(curs_set, 1);
1844 NCFUNC(def_prog_mode, 0);
1845 NCFUNC(def_shell_mode, 0);
1846 NCFUNC(delay_output, 1);
1847 NCFUNC(delch, 0);
1848 NCFUNC(deleteln, 0);
1849 NCFUNC(derwin, 5);
1850 NCFUNC(doupdate, 0);
1851 NCFUNC(dupwin, 1);
1852 NCFUNC(echo, 0);
1853 NCFUNC(echochar, 1);
1854 NCFUNC(endwin, 0);
1855 NCFUNC(erasechar, 0);
1856 NCFUNC(flash, 0);
1857 NCFUNC(flushinp, 0);
1858 NCFUNC(getbkgd, 1);
1859 NCFUNC(getch, 0);
1860 #ifdef HAVE_GET_WCH
1861 NCFUNC(get_wch, 0);
1862 NCFUNC(wget_wch, 1);
1863 #endif
1864 NCFUNC(halfdelay, 1);
1865 rb_define_module_function(mNcurses, "has_colors?",
1866 (&rbncurs_has_colors),
1867 0);
1868 rb_define_module_function(mNcurses, "has_ic?",
1869 (&rbncurs_has_ic),
1870 0);
1871 rb_define_module_function(mNcurses, "has_il?",
1872 (&rbncurs_has_il),
1873 0);
1874 NCFUNC(hline, 2);
1875 NCFUNC(idcok, 2);
1876 NCFUNC(idlok, 2);
1877 NCFUNC(immedok, 2);
1878 NCFUNC(inch, 0);
1879 NCFUNC(init_color, 4);
1880 NCFUNC(init_pair, 3);
1881 NCFUNC(insch, 1);
1882 NCFUNC(insdelln, 1);
1883 NCFUNC(insertln, 0);
1884 NCFUNC(insnstr, 2);
1885 NCFUNC(insstr, 1);
1886 #ifdef HAVE_INTRFLUSH
1887 NCFUNC(intrflush, 2);
1888 #endif
1889 rb_define_module_function(mNcurses, "isendwin?",
1890 (&rbncurs_isendwin),
1891 0);
1892 rb_define_module_function(mNcurses, "is_linetouched?",
1893 (&rbncurs_is_linetouched),
1894 2);
1895 rb_define_module_function(mNcurses, "is_wintouched?",
1896 (&rbncurs_is_wintouched),
1897 1);
1898 NCFUNC(keyname, 1);
1899 NCFUNC(keypad, 2);
1900 NCFUNC(killchar, 0);
1901 NCFUNC(leaveok, 2);
1902 NCFUNC(longname, 0);
1903 NCFUNC(meta, 2);
1904 NCFUNC(move, 2);
1905 NCFUNC(mvaddch, 3);
1906 NCFUNC(mvaddchnstr, 4);
1907 NCFUNC(mvaddchstr, 3);
1908 NCFUNC(mvaddnstr, 4);
1909 NCFUNC(mvaddstr, 3);
1910 #ifdef HAVE_MVCHGAT
1911 NCFUNC(mvchgat, 6);
1912 #endif
1913 NCFUNC(mvcur, 4);
1914 NCFUNC(mvdelch, 2);
1915 NCFUNC(mvderwin, 3);
1916 NCFUNC(mvgetch, 2);
1917 #ifdef HAVE_MVHLINE
1918 NCFUNC(mvhline, 4);
1919 #endif
1920 NCFUNC(mvinch, 2);
1921 NCFUNC(mvinsch, 3);
1922 NCFUNC(mvinsnstr, 4);
1923 NCFUNC(mvinsstr, 3);
1924 #ifdef HAVE_MVVLINE
1925 NCFUNC(mvvline, 4);
1926 #endif
1927 NCFUNC(mvwaddch, 4);
1928 NCFUNC(mvwaddchnstr, 5);
1929 NCFUNC(mvwaddchstr, 4);
1930 NCFUNC(mvwaddnstr, 5);
1931 NCFUNC(mvwaddstr, 4);
1932 #ifdef HAVE_MVWCHGAT
1933 NCFUNC(mvwchgat, 7);
1934 #endif
1935 NCFUNC(mvwdelch, 3);
1936 NCFUNC(mvwgetch, 3);
1937 #ifdef HAVE_MVWHLINE
1938 NCFUNC(mvwhline, 5);
1939 #endif
1940 NCFUNC(mvwin, 3);
1941 NCFUNC(mvwinch, 3);
1942 NCFUNC(mvwinsch, 4);
1943 NCFUNC(mvwinsnstr, 5);
1944 NCFUNC(mvwinsstr, 4);
1945 #ifdef HAVE_MVWVLINE
1946 NCFUNC(mvwvline, 5);
1947 #endif
1948 NCFUNC(napms, 1);
1949 NCFUNC(newpad, 2);
1950 NCFUNC(newwin, 4);
1951 NCFUNC(nl, 0);
1952 NCFUNC(nocbreak, 0);
1953 NCFUNC(nodelay, 2);
1954 NCFUNC(noecho, 0);
1955 NCFUNC(nonl, 0);
1956 #ifdef HAVE_NOQIFLUSH
1957 NCFUNC(noqiflush, 0);
1958 #endif
1959 NCFUNC(noraw, 0);
1960 NCFUNC(notimeout, 2);
1961 NCFUNC(overlay, 2);
1962 NCFUNC(overwrite, 2);
1963 NCFUNC(PAIR_NUMBER, 1);
1964 #ifndef __PDCURSES__ /* pdcurses' pechochar macro does not work */
1965 NCFUNC(pechochar, 2);
1966 #endif
1967 NCFUNC(pnoutrefresh, 7);
1968 NCFUNC(prefresh, 7);
1969 #ifdef HAVE_PUTP
1970 NCFUNC(putp, 1);
1971 #endif
1972 #ifdef HAVE_QIFLUSH
1973 NCFUNC(qiflush, 0);
1974 #endif
1975 NCFUNC(raw, 0);
1976 #ifndef __PDCURSES__ /* pdcurses redrawwin macro has a bug */
1977 NCFUNC(redrawwin, 1);
1978 #endif
1979 NCFUNC(refresh, 0);
1980 NCFUNC(resetty, 0);
1981 NCFUNC(reset_prog_mode, 0);
1982 NCFUNC(reset_shell_mode, 0);
1983 NCFUNC(savetty, 0);
1984 #ifdef HAVE_SCR_DUMP
1985 NCFUNC(scr_dump, 1);
1986 #endif
1987 #ifdef HAVE_SCR_INIT
1988 NCFUNC(scr_init, 1);
1989 #endif
1990 NCFUNC(scrl, 1);
1991 NCFUNC(scroll, 1);
1992 NCFUNC(scrollok, 2);
1993 #ifdef HAVE_SCR_RESTORE
1994 NCFUNC(scr_restore, 1);
1995 #endif
1996 #ifdef HAVE_SCR_SET
1997 NCFUNC(scr_set, 1);
1998 #endif
1999 NCFUNC(setscrreg, 2);
2000 NCFUNC(set_term, 1);
2001 NCFUNC(slk_attroff, 1);
2002 NCFUNC(slk_attron, 1);
2003 NCFUNC(slk_attrset, 1);
2004 #ifdef HAVE_SLK_ATTR
2005 NCFUNC(slk_attr, 0);
2006 #endif
2007 NCFUNC(slk_clear, 0);
2008 #ifdef HAVE_SLK_COLOR
2009 NCFUNC(slk_color, 1);
2010 #endif
2011 NCFUNC(slk_label, 1);
2012 NCFUNC(slk_noutrefresh, 0);
2013 NCFUNC(slk_refresh, 0);
2014 NCFUNC(slk_restore, 0);
2015 NCFUNC(slk_set, 3);
2016 NCFUNC(slk_touch, 0);
2017 NCFUNC(standout, 0);
2018 NCFUNC(standend, 0);
2019 NCFUNC(start_color, 0);
2020 NCFUNC(subpad, 5);
2021 NCFUNC(subwin, 5);
2022 NCFUNC(syncok, 2);
2023 NCFUNC(termattrs, 0);
2024 NCFUNC(termname, 0);
2025 #ifdef HAVE_TIGETFLAG
2026 NCFUNC(tigetflag, 1);
2027 #endif
2028 #ifdef HAVE_TIGETNUM
2029 NCFUNC(tigetnum, 1);
2030 #endif
2031 #ifdef HAVE_TIGETSTR
2032 NCFUNC(tigetstr, 1);
2033 #endif
2034 NCFUNC(timeout, 1);
2035 NCFUNC(typeahead, 1);
2036 NCFUNC(ungetch, 1);
2037 NCFUNC(untouchwin, 1);
2038 #ifdef HAVE_VIDATTR
2039 NCFUNC(vidattr, 1);
2040 #endif
2041 NCFUNC(vline, 2);
2042 NCFUNC(waddch, 2);
2043 #ifdef HAVE_ADD_WCH
2044 NCFUNC(wadd_wch, 2);
2045 #endif
2046 NCFUNC(waddchnstr, 3);
2047 NCFUNC(waddchstr, 2);
2048 NCFUNC(waddnstr, 3);
2049 NCFUNC(waddstr, 2);
2050 NCFUNC(wattron, 2);
2051 NCFUNC(wattroff, 2);
2052 NCFUNC(wattrset, 2);
2053 NCFUNC(wbkgd, 2);
2054 NCFUNC(wbkgdset, 2);
2055 NCFUNC(wborder, 9);
2056 #ifdef HAVE_WCHGAT
2057 NCFUNC(wchgat, 5);
2058 #endif
2059 NCFUNC(wclear, 1);
2060 NCFUNC(wclrtobot, 1);
2061 NCFUNC(wclrtoeol, 1);
2062 #ifdef HAVE_WCOLOR_SET
2063 NCFUNC(wcolor_set, 3);
2064 #endif
2065 NCFUNC(wcursyncup, 1);
2066 NCFUNC(wdelch, 1);
2067 NCFUNC(wdeleteln, 1);
2068 NCFUNC(wechochar, 2);
2069 NCFUNC(werase, 1);
2070 NCFUNC(wgetch, 1);
2071 NCFUNC(whline, 3);
2072 NCFUNC(winch, 1);
2073 NCFUNC(winsch, 2);
2074 NCFUNC(winsdelln, 2);
2075 NCFUNC(winsertln, 1);
2076 NCFUNC(winsnstr, 3);
2077 NCFUNC(winsstr, 2);
2078 NCFUNC(wmove, 3);
2079 NCFUNC(wnoutrefresh, 1);
2080 NCFUNC(wredrawln, 3);
2081 NCFUNC(wrefresh, 1);
2082 NCFUNC(wscrl, 2);
2083 NCFUNC(wsetscrreg, 3);
2084 NCFUNC(wstandout, 1);
2085 NCFUNC(wstandend, 1);
2086 NCFUNC(wsyncdown, 1);
2087 NCFUNC(wsyncup, 1);
2088 NCFUNC(wtimeout, 2);
2089 NCFUNC(wtouchln, 4);
2090 NCFUNC(wvline, 3);
2091 NCFUNC(color_content, 4);
2092 NCFUNC(pair_content, 3);
2093 #ifdef HAVE_GETWIN
2094 NCFUNC(getwin, 1);
2095 #endif
2096 #ifdef HAVE_PUTWIN
2097 NCFUNC(putwin, 2);
2098 #endif
2099 NCFUNC(unctrl, 1);
2100 }
2101
2102
2103 static void init_constants_3(void) {
2104 /* #define NCURSES_BITS(mask,shift) ((mask) << ((shift) + 8)) */
2105
2106 /* attributes */
2107
2108 rb_define_const(mNcurses, "A_NORMAL", INT2NUM(A_NORMAL));
2109 rb_define_const(mNcurses, "A_ATTRIBUTES", INT2NUM(A_ATTRIBUTES));
2110 rb_define_const(mNcurses, "A_CHARTEXT", INT2NUM(A_CHARTEXT));
2111 rb_define_const(mNcurses, "A_COLOR", INT2NUM(A_COLOR));
2112 rb_define_const(mNcurses, "A_STANDOUT", INT2NUM(A_STANDOUT));
2113 rb_define_const(mNcurses, "A_UNDERLINE", INT2NUM(A_UNDERLINE));
2114 rb_define_const(mNcurses, "A_REVERSE", INT2NUM(A_REVERSE));
2115 rb_define_const(mNcurses, "A_BLINK", INT2NUM(A_BLINK));
2116 rb_define_const(mNcurses, "A_DIM", INT2NUM(A_DIM));
2117 rb_define_const(mNcurses, "A_BOLD", INT2NUM(A_BOLD));
2118 rb_define_const(mNcurses, "A_ALTCHARSET", INT2NUM(A_ALTCHARSET));
2119 rb_define_const(mNcurses, "A_INVIS", INT2NUM(A_INVIS));
2120
2121 /* Tradeoff on 32-bit machines ('protect' vs widec). The others (e.g., left
2122 * highlight are not implemented in any terminal descriptions, anyway.
2123 */
2124 rb_define_const(mNcurses, "A_PROTECT", INT2NUM(A_PROTECT));
2125 #ifdef A_HORIZONTAL
2126 rb_define_const(mNcurses, "A_HORIZONTAL", INT2NUM(A_HORIZONTAL));
2127 #endif
2128 #ifdef A_LEFT
2129 rb_define_const(mNcurses, "A_LEFT", INT2NUM(A_LEFT));
2130 #endif
2131 #ifdef A_LOW
2132 rb_define_const(mNcurses, "A_LOW", INT2NUM(A_LOW));
2133 #endif
2134 #ifdef A_RIGHT
2135 rb_define_const(mNcurses, "A_RIGHT", INT2NUM(A_RIGHT));
2136 #endif
2137 #ifdef A_TOP
2138 rb_define_const(mNcurses, "A_TOP", INT2NUM(A_TOP));
2139 #endif
2140 #ifdef A_VERTICAL
2141 rb_define_const(mNcurses, "A_VERTICAL", INT2NUM(A_VERTICAL));
2142 #endif
2143
2144 /* Pseudo-character tokens outside ASCII range. The curses wgetch()
2145 * function will return any given one of these only if the corresponding
2146 * k- capability is defined in your terminal's terminfo entry. */
2147 #ifdef KEY_CODE_YES
2148 rb_define_const(mNcurses, "KEY_CODE_YES", INT2NUM(KEY_CODE_YES));
2149 #endif
2150 rb_define_const(mNcurses, "KEY_MIN", INT2NUM(KEY_MIN));
2151 rb_define_const(mNcurses, "KEY_BREAK", INT2NUM(KEY_BREAK));
2152 rb_define_const(mNcurses, "KEY_DOWN", INT2NUM(KEY_DOWN));
2153 rb_define_const(mNcurses, "KEY_UP", INT2NUM(KEY_UP));
2154 rb_define_const(mNcurses, "KEY_LEFT", INT2NUM(KEY_LEFT));
2155 rb_define_const(mNcurses, "KEY_RIGHT", INT2NUM(KEY_RIGHT));
2156 rb_define_const(mNcurses, "KEY_HOME", INT2NUM(KEY_HOME));
2157 rb_define_const(mNcurses, "KEY_BACKSPACE", INT2NUM(KEY_BACKSPACE));
2158 rb_define_const(mNcurses, "KEY_F0", INT2NUM(KEY_F(0)));
2159 rb_define_const(mNcurses, "KEY_F1", INT2NUM(KEY_F(1)));
2160 rb_define_const(mNcurses, "KEY_F2", INT2NUM(KEY_F(2)));
2161 rb_define_const(mNcurses, "KEY_F3", INT2NUM(KEY_F(3)));
2162 rb_define_const(mNcurses, "KEY_F4", INT2NUM(KEY_F(4)));
2163 rb_define_const(mNcurses, "KEY_F5", INT2NUM(KEY_F(5)));
2164 rb_define_const(mNcurses, "KEY_F6", INT2NUM(KEY_F(6)));
2165 rb_define_const(mNcurses, "KEY_F7", INT2NUM(KEY_F(7)));
2166 rb_define_const(mNcurses, "KEY_F8", INT2NUM(KEY_F(8)));
2167 rb_define_const(mNcurses, "KEY_F9", INT2NUM(KEY_F(9)));
2168 rb_define_const(mNcurses, "KEY_F10", INT2NUM(KEY_F(10)));
2169 rb_define_const(mNcurses, "KEY_F11", INT2NUM(KEY_F(11)));
2170 rb_define_const(mNcurses, "KEY_F12", INT2NUM(KEY_F(12)));
2171 rb_define_const(mNcurses, "KEY_F13", INT2NUM(KEY_F(13)));
2172 rb_define_const(mNcurses, "KEY_F14", INT2NUM(KEY_F(14)));
2173 rb_define_const(mNcurses, "KEY_F15", INT2NUM(KEY_F(15)));
2174 rb_define_const(mNcurses, "KEY_F16", INT2NUM(KEY_F(16)));
2175 rb_define_const(mNcurses, "KEY_F17", INT2NUM(KEY_F(17)));
2176 rb_define_const(mNcurses, "KEY_F18", INT2NUM(KEY_F(18)));
2177 rb_define_const(mNcurses, "KEY_F19", INT2NUM(KEY_F(19)));
2178 rb_define_const(mNcurses, "KEY_F20", INT2NUM(KEY_F(20)));
2179 rb_define_const(mNcurses, "KEY_F21", INT2NUM(KEY_F(21)));
2180 rb_define_const(mNcurses, "KEY_F22", INT2NUM(KEY_F(22)));
2181 rb_define_const(mNcurses, "KEY_F23", INT2NUM(KEY_F(23)));
2182 rb_define_const(mNcurses, "KEY_F24", INT2NUM(KEY_F(24)));
2183 rb_define_const(mNcurses, "KEY_F25", INT2NUM(KEY_F(25)));
2184 rb_define_const(mNcurses, "KEY_F26", INT2NUM(KEY_F(26)));
2185 rb_define_const(mNcurses, "KEY_F27", INT2NUM(KEY_F(27)));
2186 rb_define_const(mNcurses, "KEY_F28", INT2NUM(KEY_F(28)));
2187 rb_define_const(mNcurses, "KEY_F29", INT2NUM(KEY_F(29)));
2188 rb_define_const(mNcurses, "KEY_F30", INT2NUM(KEY_F(30)));
2189 rb_define_const(mNcurses, "KEY_DL", INT2NUM(KEY_DL));
2190 rb_define_const(mNcurses, "KEY_IL", INT2NUM(KEY_IL));
2191 rb_define_const(mNcurses, "KEY_DC", INT2NUM(KEY_DC));
2192 rb_define_const(mNcurses, "KEY_IC", INT2NUM(KEY_IC));
2193 rb_define_const(mNcurses, "KEY_EIC", INT2NUM(KEY_EIC));
2194 rb_define_const(mNcurses, "KEY_CLEAR", INT2NUM(KEY_CLEAR));
2195 rb_define_const(mNcurses, "KEY_EOS", INT2NUM(KEY_EOS));
2196 rb_define_const(mNcurses, "KEY_EOL", INT2NUM(KEY_EOL));
2197 rb_define_const(mNcurses, "KEY_SF", INT2NUM(KEY_SF));
2198 rb_define_const(mNcurses, "KEY_SR", INT2NUM(KEY_SR));
2199 rb_define_const(mNcurses, "KEY_NPAGE", INT2NUM(KEY_NPAGE));
2200 rb_define_const(mNcurses, "KEY_PPAGE", INT2NUM(KEY_PPAGE));
2201 rb_define_const(mNcurses, "KEY_STAB", INT2NUM(KEY_STAB));
2202 rb_define_const(mNcurses, "KEY_CTAB", INT2NUM(KEY_CTAB));
2203 rb_define_const(mNcurses, "KEY_CATAB", INT2NUM(KEY_CATAB));
2204 rb_define_const(mNcurses, "KEY_ENTER", INT2NUM(KEY_ENTER));
2205 rb_define_const(mNcurses, "KEY_SRESET", INT2NUM(KEY_SRESET));
2206 rb_define_const(mNcurses, "KEY_RESET", INT2NUM(KEY_RESET));
2207 rb_define_const(mNcurses, "KEY_PRINT", INT2NUM(KEY_PRINT));
2208 rb_define_const(mNcurses, "KEY_LL", INT2NUM(KEY_LL));
2209
2210 /* The keypad is arranged like this: */
2211 /* a1 up a3 */
2212 /* left b2 right */
2213 /* c1 down c3 */
2214
2215 rb_define_const(mNcurses, "KEY_A1", INT2NUM(KEY_A1));
2216 rb_define_const(mNcurses, "KEY_A3", INT2NUM(KEY_A3));
2217 rb_define_const(mNcurses, "KEY_B2", INT2NUM(KEY_B2));
2218 rb_define_const(mNcurses, "KEY_C1", INT2NUM(KEY_C1));
2219 rb_define_const(mNcurses, "KEY_C3", INT2NUM(KEY_C3));
2220 rb_define_const(mNcurses, "KEY_BTAB", INT2NUM(KEY_BTAB));
2221 rb_define_const(mNcurses, "KEY_BEG", INT2NUM(KEY_BEG));
2222 rb_define_const(mNcurses, "KEY_CANCEL", INT2NUM(KEY_CANCEL));
2223 rb_define_const(mNcurses, "KEY_CLOSE", INT2NUM(KEY_CLOSE));
2224 rb_define_const(mNcurses, "KEY_COMMAND", INT2NUM(KEY_COMMAND));
2225 rb_define_const(mNcurses, "KEY_COPY", INT2NUM(KEY_COPY));
2226 rb_define_const(mNcurses, "KEY_CREATE", INT2NUM(KEY_CREATE));
2227 rb_define_const(mNcurses, "KEY_END", INT2NUM(KEY_END));
2228 rb_define_const(mNcurses, "KEY_EXIT", INT2NUM(KEY_EXIT));
2229 rb_define_const(mNcurses, "KEY_FIND", INT2NUM(KEY_FIND));
2230 rb_define_const(mNcurses, "KEY_HELP", INT2NUM(KEY_HELP));
2231 rb_define_const(mNcurses, "KEY_MARK", INT2NUM(KEY_MARK));
2232 rb_define_const(mNcurses, "KEY_MESSAGE", INT2NUM(KEY_MESSAGE));
2233 rb_define_const(mNcurses, "KEY_MOVE", INT2NUM(KEY_MOVE));
2234 rb_define_const(mNcurses, "KEY_NEXT", INT2NUM(KEY_NEXT));
2235 rb_define_const(mNcurses, "KEY_OPEN", INT2NUM(KEY_OPEN));
2236 rb_define_const(mNcurses, "KEY_OPTIONS", INT2NUM(KEY_OPTIONS));
2237 rb_define_const(mNcurses, "KEY_PREVIOUS", INT2NUM(KEY_PREVIOUS));
2238 rb_define_const(mNcurses, "KEY_REDO", INT2NUM(KEY_REDO));
2239 rb_define_const(mNcurses, "KEY_REFERENCE", INT2NUM(KEY_REFERENCE));
2240 rb_define_const(mNcurses, "KEY_REFRESH", INT2NUM(KEY_REFRESH));
2241 rb_define_const(mNcurses, "KEY_REPLACE", INT2NUM(KEY_REPLACE));
2242 rb_define_const(mNcurses, "KEY_RESTART", INT2NUM(KEY_RESTART));
2243 rb_define_const(mNcurses, "KEY_RESUME", INT2NUM(KEY_RESUME));
2244 rb_define_const(mNcurses, "KEY_SAVE", INT2NUM(KEY_SAVE));
2245 rb_define_const(mNcurses, "KEY_SBEG", INT2NUM(KEY_SBEG));
2246 rb_define_const(mNcurses, "KEY_SCANCEL", INT2NUM(KEY_SCANCEL));
2247 rb_define_const(mNcurses, "KEY_SCOMMAND", INT2NUM(KEY_SCOMMAND));
2248 rb_define_const(mNcurses, "KEY_SCOPY", INT2NUM(KEY_SCOPY));
2249 rb_define_const(mNcurses, "KEY_SCREATE", INT2NUM(KEY_SCREATE));
2250 rb_define_const(mNcurses, "KEY_SDC", INT2NUM(KEY_SDC));
2251 rb_define_const(mNcurses, "KEY_SDL", INT2NUM(KEY_SDL));
2252 rb_define_const(mNcurses, "KEY_SELECT", INT2NUM(KEY_SELECT));
2253 rb_define_const(mNcurses, "KEY_SEND", INT2NUM(KEY_SEND));
2254 rb_define_const(mNcurses, "KEY_SEOL", INT2NUM(KEY_SEOL));
2255 rb_define_const(mNcurses, "KEY_SEXIT", INT2NUM(KEY_SEXIT));
2256 rb_define_const(mNcurses, "KEY_SFIND", INT2NUM(KEY_SFIND));
2257 rb_define_const(mNcurses, "KEY_SHELP", INT2NUM(KEY_SHELP));
2258 rb_define_const(mNcurses, "KEY_SHOME", INT2NUM(KEY_SHOME));
2259 rb_define_const(mNcurses, "KEY_SIC", INT2NUM(KEY_SIC));
2260 rb_define_const(mNcurses, "KEY_SLEFT", INT2NUM(KEY_SLEFT));
2261 rb_define_const(mNcurses, "KEY_SMESSAGE", INT2NUM(KEY_SMESSAGE));
2262 rb_define_const(mNcurses, "KEY_SMOVE", INT2NUM(KEY_SMOVE));
2263 rb_define_const(mNcurses, "KEY_SNEXT", INT2NUM(KEY_SNEXT));
2264 rb_define_const(mNcurses, "KEY_SOPTIONS", INT2NUM(KEY_SOPTIONS));
2265 rb_define_const(mNcurses, "KEY_SPREVIOUS", INT2NUM(KEY_SPREVIOUS));
2266 rb_define_const(mNcurses, "KEY_SPRINT", INT2NUM(KEY_SPRINT));
2267 rb_define_const(mNcurses, "KEY_SREDO", INT2NUM(KEY_SREDO));
2268 rb_define_const(mNcurses, "KEY_SREPLACE", INT2NUM(KEY_SREPLACE));
2269 rb_define_const(mNcurses, "KEY_SRIGHT", INT2NUM(KEY_SRIGHT));
2270 rb_define_const(mNcurses, "KEY_SRSUME", INT2NUM(KEY_SRSUME));
2271 rb_define_const(mNcurses, "KEY_SSAVE", INT2NUM(KEY_SSAVE));
2272 rb_define_const(mNcurses, "KEY_SSUSPEND", INT2NUM(KEY_SSUSPEND));
2273 rb_define_const(mNcurses, "KEY_SUNDO", INT2NUM(KEY_SUNDO));
2274 rb_define_const(mNcurses, "KEY_SUSPEND", INT2NUM(KEY_SUSPEND));
2275 rb_define_const(mNcurses, "KEY_UNDO", INT2NUM(KEY_UNDO));
2276 rb_define_const(mNcurses, "KEY_MOUSE", INT2NUM(KEY_MOUSE));
2277 rb_define_const(mNcurses, "KEY_RESIZE", INT2NUM(KEY_RESIZE));
2278 rb_define_const(mNcurses, "KEY_MAX", INT2NUM(KEY_MAX));
2279
2280 /* mouse interface */
2281 /* #define NCURSES_MOUSE_VERSION 1 */
2282
2283 /* event masks */
2284 rb_define_const(mNcurses, "BUTTON1_RELEASED", INT2NUM(BUTTON1_RELEASED));
2285 rb_define_const(mNcurses, "BUTTON1_PRESSED", INT2NUM(BUTTON1_PRESSED));
2286 rb_define_const(mNcurses, "BUTTON1_CLICKED", INT2NUM(BUTTON1_CLICKED));
2287 rb_define_const(mNcurses, "BUTTON1_DOUBLE_CLICKED", INT2NUM(BUTTON1_DOUBLE_CLICKED));
2288 rb_define_const(mNcurses, "BUTTON1_TRIPLE_CLICKED", INT2NUM(BUTTON1_TRIPLE_CLICKED));
2289 #ifdef BUTTON1_RESERVED_EVENT
2290 rb_define_const(mNcurses, "BUTTON1_RESERVED_EVENT", INT2NUM(BUTTON1_RESERVED_EVENT));
2291 #endif
2292 rb_define_const(mNcurses, "BUTTON2_RELEASED", INT2NUM(BUTTON2_RELEASED));
2293 rb_define_const(mNcurses, "BUTTON2_PRESSED", INT2NUM(BUTTON2_PRESSED));
2294 rb_define_const(mNcurses, "BUTTON2_CLICKED", INT2NUM(BUTTON2_CLICKED));
2295 rb_define_const(mNcurses, "BUTTON2_DOUBLE_CLICKED", INT2NUM(BUTTON2_DOUBLE_CLICKED));
2296 rb_define_const(mNcurses, "BUTTON2_TRIPLE_CLICKED", INT2NUM(BUTTON2_TRIPLE_CLICKED));
2297 #ifdef BUTTON2_RESERVED_EVENT
2298 rb_define_const(mNcurses, "BUTTON2_RESERVED_EVENT", INT2NUM(BUTTON2_RESERVED_EVENT));
2299 #endif
2300 rb_define_const(mNcurses, "BUTTON3_RELEASED", INT2NUM(BUTTON3_RELEASED));
2301 rb_define_const(mNcurses, "BUTTON3_PRESSED", INT2NUM(BUTTON3_PRESSED));
2302 rb_define_const(mNcurses, "BUTTON3_CLICKED", INT2NUM(BUTTON3_CLICKED));
2303 rb_define_const(mNcurses, "BUTTON3_DOUBLE_CLICKED", INT2NUM(BUTTON3_DOUBLE_CLICKED));
2304 rb_define_const(mNcurses, "BUTTON3_TRIPLE_CLICKED", INT2NUM(BUTTON3_TRIPLE_CLICKED));
2305 #ifdef BUTTON3_RESERVED_EVENT
2306 rb_define_const(mNcurses, "BUTTON3_RESERVED_EVENT", INT2NUM(BUTTON3_RESERVED_EVENT));
2307 #endif
2308 #ifdef BUTTON4_RELEASED
2309 rb_define_const(mNcurses, "BUTTON4_RELEASED", INT2NUM(BUTTON4_RELEASED));
2310 #endif
2311 #ifdef BUTTON4_PRESSED
2312 rb_define_const(mNcurses, "BUTTON4_PRESSED", INT2NUM(BUTTON4_PRESSED));
2313 #endif
2314 #ifdef BUTTON4_CLICKED
2315 rb_define_const(mNcurses, "BUTTON4_CLICKED", INT2NUM(BUTTON4_CLICKED));
2316 #endif
2317 #ifdef BUTTON4_DOUBLE_CLICKED
2318 rb_define_const(mNcurses, "BUTTON4_DOUBLE_CLICKED", INT2NUM(BUTTON4_DOUBLE_CLICKED));
2319 #endif
2320 #ifdef BUTTON4_TRIPLE_CLICKED
2321 rb_define_const(mNcurses, "BUTTON4_TRIPLE_CLICKED", INT2NUM(BUTTON4_TRIPLE_CLICKED));
2322 #endif
2323 #ifdef BUTTON4_RESERVED_EVENT
2324 rb_define_const(mNcurses, "BUTTON4_RESERVED_EVENT", INT2NUM(BUTTON4_RESERVED_EVENT));
2325 #endif
2326 #ifdef BUTTON_CTRL
2327 rb_define_const(mNcurses, "BUTTON_CTRL", INT2NUM(BUTTON_CTRL));
2328 #endif
2329 #ifdef BUTTON_CONTROL
2330 rb_define_const(mNcurses, "BUTTON_CTRL", INT2NUM(BUTTON_CONTROL));
2331 #endif
2332 rb_define_const(mNcurses, "BUTTON_SHIFT", INT2NUM(BUTTON_SHIFT));
2333 rb_define_const(mNcurses, "BUTTON_ALT", INT2NUM(BUTTON_ALT));
2334 rb_define_const(mNcurses, "ALL_MOUSE_EVENTS", INT2NUM(ALL_MOUSE_EVENTS));
2335 rb_define_const(mNcurses, "REPORT_MOUSE_POSITION", INT2NUM(REPORT_MOUSE_POSITION));
2336 }
2337
2338 /* typedef struct */
2339 /* { */
2340 /* short id; */ /* ID to distinguish multiple devices */
2341 /* int x, y, z; */ /* event coordinates (character-cell) */
2342 /* mmask_t bstate; *//* button state bits */
2343 /* } */
2344 /* MEVENT; */
2345 #ifdef HAVE_UNGETMOUSE
2346 static VALUE rbncurs_getmouse(VALUE dummy, VALUE rb_m)
2347 {
2348 MEVENT m;
2349 int return_value = getmouse(&m);
2350 if (return_value != ERR) {
2351 rb_iv_set(rb_m, "@id", INT2NUM(m.id));
2352 rb_iv_set(rb_m, "@x", INT2NUM(m.x));
2353 rb_iv_set(rb_m, "@y", INT2NUM(m.y));
2354 rb_iv_set(rb_m, "@z", INT2NUM(m.z));
2355 rb_iv_set(rb_m, "@bstate", INT2NUM(m.bstate));
2356 }
2357 return INT2NUM(return_value);
2358 }
2359 static VALUE rbncurs_ungetmouse(VALUE dummy, VALUE rb_m)
2360 {
2361 MEVENT m;
2362 m.id = NUM2INT(rb_iv_get(rb_m, "@id"));
2363 m.x = NUM2INT(rb_iv_get(rb_m, "@x"));
2364 m.y = NUM2INT(rb_iv_get(rb_m, "@y"));
2365 m.z = NUM2INT(rb_iv_get(rb_m, "@z"));
2366 m.bstate = NUM2ULONG(rb_iv_get(rb_m, "@bstate"));
2367 return INT2NUM(ungetmouse(&m));
2368 }
2369 #endif
2370 #ifdef HAVE_MOUSEMASK
2371 static VALUE rbncurs_mousemask(VALUE dummy, VALUE rb_newmask, VALUE rb_oldmask)
2372 {
2373 if (rb_obj_is_instance_of(rb_oldmask, rb_cArray) != Qtrue) {
2374 rb_raise(rb_eArgError,
2375 "oldmask (2nd argument) must be an empty Array");
2376 return Qnil;
2377 }
2378 {
2379 mmask_t oldmask, return_value;
2380 return_value = mousemask(NUM2ULONG(rb_newmask), &oldmask);
2381 rb_ary_push(rb_oldmask, INT2NUM(oldmask));
2382 return INT2NUM(return_value);
2383 }
2384 }
2385 #endif
2386 #ifdef HAVE_WENCLOSE
2387 static VALUE rbncurs_wenclose(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
2388 {
2389 return wenclose(get_window(rb_win), NUM2INT(rb_y), NUM2INT(rb_x))
2390 ? Qtrue : Qfalse;
2391 }
2392 #endif
2393 #ifdef HAVE_MOUSEINTERVAL
2394 static VALUE rbncurs_mouseinterval(VALUE dummy, VALUE rb_interval)
2395 { return INT2NUM(mouseinterval(NUM2INT(rb_interval))); }
2396 #endif
2397 #ifdef HAVE_WMOUSE_TRAFO
2398 static VALUE rbncurs_wmouse_trafo(VALUE dummy, VALUE rb_win, VALUE rb_pY, VALUE rb_pX,
2399 VALUE rb_to_screen)
2400 {
2401 if ((rb_obj_is_instance_of(rb_pY, rb_cArray) != Qtrue)
2402 || (rb_obj_is_instance_of(rb_pY, rb_cArray) != Qtrue)) {
2403 rb_raise(rb_eArgError,
2404 "pY and pX arguments must be Arrays, containing exactly one "
2405 "Integer");
2406 return Qnil;
2407 }
2408 {
2409 int X = NUM2INT(rb_ary_pop(rb_pX));
2410 int Y = NUM2INT(rb_ary_pop(rb_pY));
2411 bool return_value =
2412 wmouse_trafo(get_window(rb_win), &Y, &X, RTEST(rb_to_screen));
2413 rb_ary_push(rb_pY, INT2NUM(Y)); rb_ary_push(rb_pX, INT2NUM(X));
2414 return return_value ? Qtrue : Qfalse;
2415 }
2416 }
2417 #endif
2418 #ifdef HAVE_MCPRINT
2419 static VALUE rbncurs_mcprint(VALUE dummy, VALUE data, VALUE len)
2420 {
2421 return INT2NUM(mcprint(STR2CSTR(data), NUM2INT(len)));
2422 }
2423 #endif
2424 #ifdef HAVE_HAS_KEY
2425 static VALUE rbncurs_has_key(VALUE dummy, VALUE ch)
2426 {return INT2NUM(has_key(NUM2INT(ch)));}
2427 #endif
2428 static VALUE rbncurs_getyx(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
2429 {
2430 if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue)
2431 || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) {
2432 rb_raise(rb_eArgError,
2433 "y and x arguments must be empty Arrays");
2434 return Qnil;
2435 }
2436 {
2437 int y,x;
2438 getyx(get_window(rb_win), y,x);
2439 rb_ary_push(rb_y, INT2NUM(y));
2440 rb_ary_push(rb_x, INT2NUM(x));
2441 return Qnil;
2442 }
2443 }
2444 #if defined(HAVE_GETATTRS) || defined(getattrs)
2445 static VALUE rbncurs_getattrs(VALUE dummy, VALUE rb_win)
2446 {return INT2NUM(getattrs(get_window(rb_win)));}
2447 #endif
2448 static VALUE rbncurs_getbegyx(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
2449 {
2450 int y,x;
2451 if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue)
2452 || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) {
2453 rb_raise(rb_eArgError,
2454 "y and x arguments must be empty Arrays");
2455 return Qnil;
2456 }
2457 getbegyx(get_window(rb_win), y,x);
2458 rb_ary_push(rb_y, INT2NUM(y));
2459 rb_ary_push(rb_x, INT2NUM(x));
2460 return Qnil;
2461 }
2462 static VALUE rbncurs_getmaxyx(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
2463 {
2464 int y,x;
2465 if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue)
2466 || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) {
2467 rb_raise(rb_eArgError,
2468 "y and x arguments must be empty Arrays");
2469 return Qnil;
2470 }
2471 getmaxyx(get_window(rb_win), y,x);
2472 rb_ary_push(rb_y, INT2NUM(y));
2473 rb_ary_push(rb_x, INT2NUM(x));
2474 return Qnil;
2475 }
2476 static VALUE rbncurs_getparyx(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
2477 {
2478 int y,x;
2479 if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue)
2480 || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) {
2481 rb_raise(rb_eArgError,
2482 "y and x arguments must be empty Arrays");
2483 return Qnil;
2484 }
2485 getparyx(get_window(rb_win), y,x);
2486 rb_ary_push(rb_y, INT2NUM(y));
2487 rb_ary_push(rb_x, INT2NUM(x));
2488 return Qnil;
2489 }
2490 static VALUE rbncurs_getsyx(VALUE dummy, VALUE rb_y, VALUE rb_x)
2491 {
2492 int y = 0;
2493 int x = 0;
2494 if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue)
2495 || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) {
2496 rb_raise(rb_eArgError,
2497 "y and x arguments must be empty Arrays");
2498 return Qnil;
2499 }
2500 #ifdef getsyx
2501 getsyx(y,x);
2502 #else
2503 getsyx(&y,&x);
2504 #endif
2505 rb_ary_push(rb_y, INT2NUM(y));
2506 rb_ary_push(rb_x, INT2NUM(x));
2507 return Qnil;
2508 }
2509 static VALUE rbncurs_setsyx(VALUE dummy, VALUE rb_y, VALUE rb_x)
2510 {
2511 int y = NUM2INT(rb_y), x = NUM2INT(rb_x);
2512 setsyx(y,x);
2513 return Qnil;
2514 }
2515
2516 static VALUE rbncurs_wprintw(int argc, VALUE * argv, VALUE dummy)
2517 {
2518 if (argc < 2) {
2519 rb_raise(rb_eArgError, "function needs at least 2 arguments: a WINDOW"
2520 " and a String");
2521 return Qnil;
2522 }
2523 wprintw(get_window(argv[0]), "%s",
2524 STR2CSTR(rb_funcall3(rb_mKernel, rb_intern("sprintf"), argc-1,
2525 argv + 1)));
2526 return Qnil;
2527 }
2528
2529 /* Debugging : use with libncurses_g.a */
2530 #ifdef HAVE__TRACEF
2531 static VALUE rbncurs_tracef(int argc, VALUE * argv, VALUE dummy)
2532 {
2533 (void) dummy;
2534 if (argc < 1) {
2535 rb_raise(rb_eArgError, "function needs at least 1 argument");
2536 return Qnil;
2537 }
2538 _tracef("%s",
2539 STR2CSTR(funcall3(rb_mKernel, rb_intern("sprintf"), argc, argv)));
2540 return Qnil;
2541 }
2542 #endif /* HAVE__TRACEF */
2543 #ifdef HAVE__TRACEDUMP
2544 static VALUE rbncurs_tracedump(VALUE dummy, VALUE rb_label, VALUE rb_win)
2545 {
2546 _tracedump(STR2CSTR(rb_label), get_window(rb_win));
2547 }
2548 #endif /* HAVE__TRACEDUMP */
2549 #ifdef HAVE__TRACEATTR
2550 static VALUE rbncurs_traceattr(VALUE dummy, VALUE attr)
2551 { return rb_str_new2(_traceattr(NUM2ULONG(attr))); }
2552 #endif /* HAVE__TRACEATTR */
2553 #ifdef HAVE__TRACEATTR2
2554 static VALUE rbncurs_traceattr2(VALUE dummy, VALUE buffer, VALUE ch)
2555 { return rb_str_new2(_traceattr2(NUM2INT(buffer),NUM2ULONG(ch))); }
2556 #endif /* HAVE__TRACEATTR2 */
2557 #ifdef HAVE__TRACEBITS
2558 static VALUE rbncurs_tracebits(VALUE dummy)
2559 { return rb_str_new2(_tracebits()); }
2560 #endif /* HAVE__TRACEBITS */
2561 #ifdef HAVE__TRACECHAR
2562 static VALUE rbncurs_tracechar(VALUE dummy, VALUE ch)
2563 { return rb_str_new2(_tracechar(NUM2ULONG(ch))); }
2564 #endif /* HAVE__TRACECHAR */
2565 #ifdef HAVE__TRACECHTYPE
2566 static VALUE rbncurs_tracechtype(VALUE dummy, VALUE ch)
2567 { return rb_str_new2(_tracechtype(NUM2ULONG(ch))); }
2568 #endif /* HAVE__TRACECHTYPE */
2569 #ifdef HAVE__TRACECHTYPE2
2570 static VALUE rbncurs_tracechtype2(VALUE dummy, VALUE buffer, VALUE ch)
2571 { return rb_str_new2(_tracechtype2(NUM2INT(buffer),NUM2ULONG(ch))); }
2572 #endif /* HAVE__TRACECHTYPE2 */
2573 #ifdef HAVE__TRACEMOUSE
2574 static VALUE rbncurs_tracemouse(VALUE dummy, VALUE rb_m)
2575 {
2576 MEVENT m;
2577 m.id = NUM2INT(rb_iv_get(rb_m, "@id"));
2578 m.x = NUM2INT(rb_iv_get(rb_m, "@x"));
2579 m.y = NUM2INT(rb_iv_get(rb_m, "@y"));
2580 m.z = NUM2INT(rb_iv_get(rb_m, "@z"));
2581 m.bstate = NUM2ULONG(rb_iv_get(rb_m, "@bstate"));
2582 return rb_str_new2(_tracemouse(&m));
2583 }
2584 #endif /* HAVE__TRACEMOUSE */
2585 #ifdef HAVE_TRACE
2586 static VALUE rbncurs_trace(VALUE dummy, VALUE param)
2587 { trace(NUM2ULONG(param)); return Qnil; }
2588 #endif /* HAVE_TRACE */
2589 #ifdef HAVE__NC_TRACEBITS
2590 static VALUE rbncurs_nc_tracebits()
2591 { return rb_str_new2((char*)_nc_tracebits()); }
2592 #endif /* HAVE__NC_TRACEBITS */
2593
2594 #ifdef HAVE_ASSUME_DEFAULT_COLORS
2595 static VALUE rbncurs_assume_default_colors(VALUE dummy, VALUE fg, VALUE bg)
2596 { return INT2NUM(assume_default_colors(NUM2INT(fg),NUM2INT(bg))); }
2597 #endif /* HAVE_ASSUME_DEFAULT_COLORS */
2598
2599 static void init_functions_3(void)
2600 {
2601 #ifdef HAVE_UNGETMOUSE
2602 NCFUNC(getmouse, 1);
2603 NCFUNC(ungetmouse, 1);
2604 #endif
2605 #ifdef HAVE_MOUSEMASK
2606 NCFUNC(mousemask, 2);
2607 #endif
2608 #ifdef HAVE_WENCLOSE
2609 rb_define_module_function(mNcurses, "wenclose?",
2610 (&rbncurs_wenclose),
2611 3);
2612 #endif
2613 #ifdef HAVE_MOUSEINTERVAL
2614 NCFUNC(mouseinterval, 1);
2615 #endif
2616 #ifdef HAVE_WMOUSE_TRAFO
2617 NCFUNC(wmouse_trafo, 4);
2618 #endif
2619 #ifdef HAVE_MCPRINT
2620 NCFUNC(mcprint, 2);
2621 #endif
2622 #ifdef HAVE_HAS_KEY
2623 rb_define_module_function(mNcurses, "has_key?",
2624 (&rbncurs_has_key),
2625 1);
2626 #endif
2627 NCFUNC(getyx, 3);
2628 NCFUNC(getbegyx, 3);
2629 NCFUNC(getmaxyx, 3);
2630 NCFUNC(getparyx, 3);
2631 NCFUNC(getsyx, 2);
2632 NCFUNC(setsyx, 2);
2633 #if defined(HAVE_GETATTRS) || defined(getattrs)
2634 NCFUNC(getattrs, 1);
2635 #endif
2636 #ifdef HAVE__TRACEF
2637 rb_define_module_function(mNcurses, "_tracef",
2638 (&rbncurs_tracef), -1);
2639 #endif /* HAVE__TRACEF */
2640 #ifdef HAVE__TRACEDUMP
2641 rb_define_module_function(mNcurses, "_tracedump",
2642 (&rbncurs_tracedump),
2643 2);
2644 #endif /* HAVE__TRACEDUMP */
2645 #ifdef HAVE__TRACEATTR
2646 rb_define_module_function(mNcurses, "_traceattr",
2647 (&rbncurs_traceattr),
2648 1);
2649 #endif /* HAVE__TRACEATTR */
2650 #ifdef HAVE__TRACEATTR2
2651 rb_define_module_function(mNcurses, "_traceattr2",
2652 (&rbncurs_traceattr2),
2653 2);
2654 #endif /* HAVE__TRACEATTR2 */
2655 #ifdef HAVE__TRACEBITS
2656 rb_define_module_function(mNcurses, "_tracebits",
2657 (&rbncurs_tracebits),
2658 0);
2659 #endif /* HAVE__TRACEBITS */
2660 #ifdef HAVE__TRACECHAR
2661 rb_define_module_function(mNcurses, "_tracechar",
2662 (&rbncurs_tracechar),
2663 1);
2664 #endif /* HAVE__TRACECHAR */
2665 #ifdef HAVE__TRACECHTYPE
2666 rb_define_module_function(mNcurses, "_tracechtype",
2667 (&rbncurs_tracechtype),
2668 1);
2669 #endif /* HAVE__TRACECHTYPE */
2670 #ifdef HAVE__TRACECHTYPE2
2671 rb_define_module_function(mNcurses, "_tracechtype2",
2672 (&rbncurs_tracechtype2), 2);
2673 #endif /* HAVE__TRACECHTYPE2 */
2674 #ifdef HAVE__TRACEMOUSE
2675 rb_define_module_function(mNcurses, "_tracechmouse",
2676 (&rbncurs_tracemouse),
2677 1);
2678 #endif /* HAVE__TRACEMOUSE */
2679 #ifdef HAVE_TRACE
2680 NCFUNC(trace, 1);
2681 #endif /* HAVE_TRACE */
2682 #ifdef HAVE__NC_TRACEBITS
2683 rb_define_module_function(mNcurses, "_nc_tracebits", &rbncurs_nc_tracebits, 0);
2684 #endif /* HAVE__NC_TRACEBITS */
2685 #ifdef HAVE_ASSUME_DEFAULT_COLORS
2686 NCFUNC(assume_default_colors, 2);
2687 #endif /* HAVE_ASSUME_DEFAULT_COLORS */
2688 NCFUNC(wprintw, -1);
2689 }
2690
2691 static void init_constants_4(void)
2692 {
2693 /* trace masks */
2694 #ifdef TRACE_DISABLE
2695 rb_define_const(mNcurses, "TRACE_DISABLE", INT2NUM(TRACE_DISABLE));
2696 #endif
2697 #ifdef TRACE_TIMES
2698 rb_define_const(mNcurses, "TRACE_TIMES", INT2NUM(TRACE_TIMES));
2699 #endif
2700 #ifdef TRACE_TPUTS
2701 rb_define_const(mNcurses, "TRACE_TPUTS", INT2NUM(TRACE_TPUTS));
2702 #endif
2703 #ifdef TRACE_UPDATE
2704 rb_define_const(mNcurses, "TRACE_UPDATE", INT2NUM(TRACE_UPDATE));
2705 #endif
2706 #ifdef TRACE_MOVE
2707 rb_define_const(mNcurses, "TRACE_MOVE", INT2NUM(TRACE_MOVE));
2708 #endif
2709 #ifdef TRACE_CHARPUT
2710 rb_define_const(mNcurses, "TRACE_CHARPUT", INT2NUM(TRACE_CHARPUT));
2711 #endif
2712 #ifdef TRACE_ORDINARY
2713 rb_define_const(mNcurses, "TRACE_ORDINARY", INT2NUM(TRACE_ORDINARY));
2714 #endif
2715 #ifdef TRACE_CALLS
2716 rb_define_const(mNcurses, "TRACE_CALLS", INT2NUM(TRACE_CALLS));
2717 #endif
2718 #ifdef TRACE_VIRTPUT
2719 rb_define_const(mNcurses, "TRACE_VIRTPUT", INT2NUM(TRACE_VIRTPUT));
2720 #endif
2721 #ifdef TRACE_IEVENT
2722 rb_define_const(mNcurses, "TRACE_IEVENT", INT2NUM(TRACE_IEVENT));
2723 #endif
2724 #ifdef TRACE_BITS
2725 rb_define_const(mNcurses, "TRACE_BITS", INT2NUM(TRACE_BITS));
2726 #endif
2727 #ifdef TRACE_ICALLS
2728 rb_define_const(mNcurses, "TRACE_ICALLS", INT2NUM(TRACE_ICALLS));
2729 #endif
2730 #ifdef TRACE_CCALLS
2731 rb_define_const(mNcurses, "TRACE_CCALLS", INT2NUM(TRACE_CCALLS));
2732 #endif
2733 #ifdef TRACE_MAXIMUM
2734 rb_define_const(mNcurses, "TRACE_MAXIMUM", INT2NUM(TRACE_MAXIMUM));
2735 #endif
2736 }
2737
2738 /* Wrap ACS_* constants (additionally) as methods of SCREEN: */
2739 #define rb_ACS(ACS) \
2740 VALUE rb_## ACS (VALUE rb_screen) \
2741 { \
2742 VALUE current_screen = \
2743 rbncurs_set_term(mNcurses, rb_screen); \
2744 VALUE rb_ACS_CONST = INT2NUM(ACS); \
2745 rbncurs_set_term(mNcurses, current_screen); \
2746 return rb_ACS_CONST; \
2747 }
2748 #define wrap_ACS(ACS) \
2749 rb_define_method(cSCREEN, #ACS, \
2750 (&rb_ ## ACS), \
2751 0)
2752 rb_ACS(ACS_ULCORNER)
2753 rb_ACS(ACS_LLCORNER)
2754 rb_ACS(ACS_URCORNER)
2755 rb_ACS(ACS_LRCORNER)
2756 rb_ACS(ACS_LTEE)
2757 rb_ACS(ACS_RTEE)
2758 rb_ACS(ACS_BTEE)
2759 rb_ACS(ACS_TTEE)
2760 rb_ACS(ACS_HLINE)
2761 rb_ACS(ACS_VLINE)
2762 rb_ACS(ACS_PLUS)
2763 rb_ACS(ACS_S1)
2764 rb_ACS(ACS_S9)
2765 rb_ACS(ACS_DIAMOND)
2766 rb_ACS(ACS_CKBOARD)
2767 rb_ACS(ACS_DEGREE)
2768 rb_ACS(ACS_PLMINUS)
2769 rb_ACS(ACS_BULLET)
2770 rb_ACS(ACS_LARROW)
2771 rb_ACS(ACS_RARROW)
2772 rb_ACS(ACS_DARROW)
2773 rb_ACS(ACS_UARROW)
2774 rb_ACS(ACS_BOARD)
2775 rb_ACS(ACS_LANTERN)
2776 rb_ACS(ACS_BLOCK)
2777 #ifdef ACS_S3
2778 rb_ACS(ACS_S3)
2779 #endif
2780 #ifdef ACS_S7
2781 rb_ACS(ACS_S7)
2782 #endif
2783 #ifdef ACS_LEQUAL
2784 rb_ACS(ACS_LEQUAL)
2785 #endif
2786 #ifdef ACS_GEQUAL
2787 rb_ACS(ACS_GEQUAL)
2788 #endif
2789 #ifdef ACS_PI
2790 rb_ACS(ACS_PI)
2791 #endif
2792 #ifdef ACS_NEQUAL
2793 rb_ACS(ACS_NEQUAL)
2794 #endif
2795 #ifdef ACS_STERLING
2796 rb_ACS(ACS_STERLING)
2797 #endif
2798
2799 void init_SCREEN_methods(void)
2800 {
2801 wrap_ACS(ACS_ULCORNER);
2802 wrap_ACS(ACS_LLCORNER);
2803 wrap_ACS(ACS_URCORNER);
2804 wrap_ACS(ACS_LRCORNER);
2805 wrap_ACS(ACS_LTEE);
2806 wrap_ACS(ACS_RTEE);
2807 wrap_ACS(ACS_BTEE);
2808 wrap_ACS(ACS_TTEE);
2809 wrap_ACS(ACS_HLINE);
2810 wrap_ACS(ACS_VLINE);
2811 wrap_ACS(ACS_PLUS);
2812 wrap_ACS(ACS_S1);
2813 wrap_ACS(ACS_S9);
2814 wrap_ACS(ACS_DIAMOND);
2815 wrap_ACS(ACS_CKBOARD);
2816 wrap_ACS(ACS_DEGREE);
2817 wrap_ACS(ACS_PLMINUS);
2818 wrap_ACS(ACS_BULLET);
2819 wrap_ACS(ACS_LARROW);
2820 wrap_ACS(ACS_RARROW);
2821 wrap_ACS(ACS_DARROW);
2822 wrap_ACS(ACS_UARROW);
2823 wrap_ACS(ACS_BOARD);
2824 wrap_ACS(ACS_LANTERN);
2825 wrap_ACS(ACS_BLOCK);
2826 #ifdef ACS_S3
2827 wrap_ACS(ACS_S3);
2828 #endif
2829 #ifdef ACS_S7
2830 wrap_ACS(ACS_S7);
2831 #endif
2832 #ifdef ACS_LEQUAL
2833 wrap_ACS(ACS_LEQUAL);
2834 #endif
2835 #ifdef ACS_GEQUAL
2836 wrap_ACS(ACS_GEQUAL);
2837 #endif
2838 #ifdef ACS_PI
2839 wrap_ACS(ACS_PI);
2840 #endif
2841 #ifdef ACS_NEQUAL
2842 wrap_ACS(ACS_NEQUAL);
2843 #endif
2844 #ifdef ACS_STERLING
2845 wrap_ACS(ACS_STERLING);
2846 #endif
2847 }
2848
2849 #ifdef HAVE_LOCALE_H
2850 static VALUE rbncurs_setlocale(VALUE dummy, VALUE category, VALUE locale)
2851 {
2852 char * str = setlocale(NUM2INT(category), STR2CSTR(locale));
2853 if (str == NULL) return Qnil;
2854 return rb_str_new2(str);
2855 }
2856 #endif
2857
2858 static void init_safe_functions(void)
2859 {
2860 NCFUNC(initscr, 0);
2861 NCFUNC(newterm, 3);
2862 NCFUNC(slk_init, 1);
2863 #ifdef HAVE_FILTER
2864 NCFUNC(filter, 0);
2865 #endif
2866 #ifdef HAVE_USE_ENV
2867 NCFUNC(use_env, 1);
2868 #endif
2869 #ifdef HAVE_LOCALE_H
2870 NCFUNC(setlocale, 2);
2871 #endif
2872 }
2873 void Init_ncursesw_bin(void)
2874 {
2875 mNcurses = rb_define_module("Ncurses");
2876 eNcurses = rb_define_class_under(mNcurses, "Exception", rb_eRuntimeError);
2877 rb_iv_set(mNcurses, "@windows_hash", rb_hash_new());
2878 rb_iv_set(mNcurses, "@screens_hash", rb_hash_new());
2879
2880 /* keep track of "halfdelay" settings in the wrapper */
2881 rb_iv_set(mNcurses, "@halfdelay", INT2FIX(0));
2882 rb_iv_set(mNcurses, "@cbreak", Qfalse);
2883
2884 /* filedescriptor that transports input from terminal to application */
2885 rb_iv_set(mNcurses, "@infd", Qnil);
2886
2887 cWINDOW = rb_define_class_under(mNcurses, "WINDOW", rb_cObject);
2888 rb_undef_alloc_func(cWINDOW);
2889 cSCREEN = rb_define_class_under(mNcurses, "SCREEN", rb_cObject);
2890 rb_undef_alloc_func(cSCREEN);
2891 init_constants_1();
2892 init_constants_2();
2893 init_constants_3();
2894 init_constants_4();
2895 init_safe_functions();
2896 }
2897 static void Init_ncurses_full(void)
2898 {
2899 static bool already_done = false;
2900 if (already_done) return;
2901
2902 init_globals_1();
2903 init_globals_2();
2904 init_functions_0();
2905 init_functions_1();
2906 init_functions_2();
2907 init_functions_3();
2908
2909 init_SCREEN_methods();
2910 #if defined(HAVE_PANEL_H) || defined(HAVE_NCURSESW_PANEL_H)
2911 init_panel();
2912 #endif
2913 #if defined(HAVE_FORM_H) || defined(HAVE_NCURSESW_FORM_H)
2914 init_form();
2915 #endif
2916 #if defined(HAVE_MENU_H) || defined(HAVE_NCURSESW_MENU_H)
2917 init_menu();
2918 #endif
2919
2920 already_done = true;
2921 }