|
Ruby 1.9.2p290(2011-07-09revision32553)
|
00001 /* -*- C -*- 00002 * $Id: curses.c 25286 2009-10-10 10:49:47Z akr $ 00003 * 00004 * ext/curses/curses.c 00005 * 00006 * by MAEDA Shugo (ender@pic-internet.or.jp) 00007 * modified by Yukihiro Matsumoto (matz@netlab.co.jp), 00008 * Toki Yoshinori, 00009 * Hitoshi Takahashi, 00010 * and Takaaki Tateishi (ttate@kt.jaist.ac.jp) 00011 * 00012 * maintainers: 00013 * - Takaaki Tateishi (ttate@kt.jaist.ac.jp) 00014 */ 00015 00016 #include "ruby.h" 00017 #include "ruby/io.h" 00018 00019 #if defined(HAVE_NCURSES_H) 00020 # include <ncurses.h> 00021 #elif defined(HAVE_NCURSES_CURSES_H) 00022 # include <ncurses/curses.h> 00023 #elif defined(HAVE_CURSES_COLR_CURSES_H) 00024 # ifdef HAVE_STDARG_PROTOTYPES 00025 # include <stdarg.h> 00026 # else 00027 # include <varargs.h> 00028 # endif 00029 # include <curses_colr/curses.h> 00030 #else 00031 # include <curses.h> 00032 # if defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__) 00033 # if !defined(_maxx) 00034 # define _maxx maxx 00035 # endif 00036 # if !defined(_maxy) 00037 # define _maxy maxy 00038 # endif 00039 # if !defined(_begx) 00040 # define _begx begx 00041 # endif 00042 # if !defined(_begy) 00043 # define _begy begy 00044 # endif 00045 # endif 00046 #endif 00047 00048 #ifdef HAVE_INIT_COLOR 00049 # define USE_COLOR 1 00050 #endif 00051 00052 /* supports only ncurses mouse routines */ 00053 #ifdef NCURSES_MOUSE_VERSION 00054 # define USE_MOUSE 1 00055 #endif 00056 00057 #define NUM2CH NUM2CHR 00058 #define CH2FIX CHR2FIX 00059 00060 static VALUE mCurses; 00061 static VALUE mKey; 00062 static VALUE cWindow; 00063 #ifdef USE_MOUSE 00064 static VALUE cMouseEvent; 00065 #endif 00066 00067 static VALUE rb_stdscr; 00068 00069 struct windata { 00070 WINDOW *window; 00071 }; 00072 00073 #define CHECK(c) c 00074 00075 static VALUE window_attroff(VALUE obj, VALUE attrs); 00076 static VALUE window_attron(VALUE obj, VALUE attrs); 00077 static VALUE window_attrset(VALUE obj, VALUE attrs); 00078 00079 static void 00080 no_window(void) 00081 { 00082 rb_raise(rb_eRuntimeError, "already closed window"); 00083 } 00084 00085 #define GetWINDOW(obj, winp) do {\ 00086 if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)\ 00087 rb_raise(rb_eSecurityError, "Insecure: operation on untainted window");\ 00088 Data_Get_Struct(obj, struct windata, winp);\ 00089 if (winp->window == 0) no_window();\ 00090 } while (0) 00091 00092 static void 00093 free_window(struct windata *winp) 00094 { 00095 if (winp->window && winp->window != stdscr) delwin(winp->window); 00096 winp->window = 0; 00097 xfree(winp); 00098 } 00099 00100 static VALUE 00101 prep_window(VALUE class, WINDOW *window) 00102 { 00103 VALUE obj; 00104 struct windata *winp; 00105 00106 if (window == NULL) { 00107 rb_raise(rb_eRuntimeError, "failed to create window"); 00108 } 00109 00110 obj = rb_obj_alloc(class); 00111 Data_Get_Struct(obj, struct windata, winp); 00112 winp->window = window; 00113 00114 return obj; 00115 } 00116 00117 /*-------------------------- module Curses --------------------------*/ 00118 00119 /* def init_screen */ 00120 static VALUE 00121 curses_init_screen(void) 00122 { 00123 rb_secure(4); 00124 if (rb_stdscr) return rb_stdscr; 00125 initscr(); 00126 if (stdscr == 0) { 00127 rb_raise(rb_eRuntimeError, "can't initialize curses"); 00128 } 00129 clear(); 00130 rb_stdscr = prep_window(cWindow, stdscr); 00131 return rb_stdscr; 00132 } 00133 00134 /* def stdscr */ 00135 #define curses_stdscr curses_init_screen 00136 00137 /* def close_screen */ 00138 static VALUE 00139 curses_close_screen(void) 00140 { 00141 curses_stdscr(); 00142 #ifdef HAVE_ISENDWIN 00143 if (!isendwin()) 00144 #endif 00145 endwin(); 00146 rb_stdscr = 0; 00147 return Qnil; 00148 } 00149 00150 static void 00151 curses_finalize(VALUE dummy) 00152 { 00153 if (stdscr 00154 #ifdef HAVE_ISENDWIN 00155 && !isendwin() 00156 #endif 00157 ) 00158 endwin(); 00159 rb_stdscr = 0; 00160 rb_gc_unregister_address(&rb_stdscr); 00161 } 00162 00163 #ifdef HAVE_ISENDWIN 00164 /* def closed? */ 00165 static VALUE 00166 curses_closed(void) 00167 { 00168 curses_stdscr(); 00169 if (isendwin()) { 00170 return Qtrue; 00171 } 00172 return Qfalse; 00173 } 00174 #else 00175 #define curses_closed rb_f_notimplement 00176 #endif 00177 00178 /* def clear */ 00179 static VALUE 00180 curses_clear(VALUE obj) 00181 { 00182 curses_stdscr(); 00183 wclear(stdscr); 00184 return Qnil; 00185 } 00186 00187 /* def clrtoeol */ 00188 static VALUE 00189 curses_clrtoeol(void) 00190 { 00191 curses_stdscr(); 00192 clrtoeol(); 00193 return Qnil; 00194 } 00195 00196 /* def refresh */ 00197 static VALUE 00198 curses_refresh(VALUE obj) 00199 { 00200 curses_stdscr(); 00201 refresh(); 00202 return Qnil; 00203 } 00204 00205 /* def doupdate */ 00206 static VALUE 00207 curses_doupdate(VALUE obj) 00208 { 00209 curses_stdscr(); 00210 #ifdef HAVE_DOUPDATE 00211 doupdate(); 00212 #else 00213 refresh(); 00214 #endif 00215 return Qnil; 00216 } 00217 00218 /* def echo */ 00219 static VALUE 00220 curses_echo(VALUE obj) 00221 { 00222 curses_stdscr(); 00223 echo(); 00224 return Qnil; 00225 } 00226 00227 /* def noecho */ 00228 static VALUE 00229 curses_noecho(VALUE obj) 00230 { 00231 curses_stdscr(); 00232 noecho(); 00233 return Qnil; 00234 } 00235 00236 /* def raw */ 00237 static VALUE 00238 curses_raw(VALUE obj) 00239 { 00240 curses_stdscr(); 00241 raw(); 00242 return Qnil; 00243 } 00244 00245 /* def noraw */ 00246 static VALUE 00247 curses_noraw(VALUE obj) 00248 { 00249 curses_stdscr(); 00250 noraw(); 00251 return Qnil; 00252 } 00253 00254 /* def cbreak */ 00255 static VALUE 00256 curses_cbreak(VALUE obj) 00257 { 00258 curses_stdscr(); 00259 cbreak(); 00260 return Qnil; 00261 } 00262 00263 /* def nocbreak */ 00264 static VALUE 00265 curses_nocbreak(VALUE obj) 00266 { 00267 curses_stdscr(); 00268 nocbreak(); 00269 return Qnil; 00270 } 00271 00272 /* def nl */ 00273 static VALUE 00274 curses_nl(VALUE obj) 00275 { 00276 curses_stdscr(); 00277 nl(); 00278 return Qnil; 00279 } 00280 00281 /* def nonl */ 00282 static VALUE 00283 curses_nonl(VALUE obj) 00284 { 00285 curses_stdscr(); 00286 nonl(); 00287 return Qnil; 00288 } 00289 00290 /* def beep */ 00291 static VALUE 00292 curses_beep(VALUE obj) 00293 { 00294 #ifdef HAVE_BEEP 00295 curses_stdscr(); 00296 beep(); 00297 #endif 00298 return Qnil; 00299 } 00300 00301 /* def flash */ 00302 static VALUE 00303 curses_flash(VALUE obj) 00304 { 00305 #ifdef HAVE_FLASH 00306 curses_stdscr(); 00307 flash(); 00308 #endif 00309 return Qnil; 00310 } 00311 00312 static int 00313 curses_char(VALUE c) 00314 { 00315 if (FIXNUM_P(c)) { 00316 return NUM2INT(c); 00317 } 00318 else { 00319 int cc; 00320 00321 StringValue(c); 00322 if (RSTRING_LEN(c) == 0 || RSTRING_LEN(c) > 1) { 00323 rb_raise(rb_eArgError, "string not corresponding a character"); 00324 } 00325 cc = RSTRING_PTR(c)[0]; 00326 if (cc > 0x7f) { 00327 rb_raise(rb_eArgError, "no multibyte string supported (yet)"); 00328 } 00329 return cc; 00330 } 00331 } 00332 00333 #ifdef HAVE_UNGETCH 00334 /* def ungetch */ 00335 static VALUE 00336 curses_ungetch(VALUE obj, VALUE ch) 00337 { 00338 int c = curses_char(ch); 00339 curses_stdscr(); 00340 ungetch(c); 00341 return Qnil; 00342 } 00343 #else 00344 #define curses_ungetch rb_f_notimplement 00345 #endif 00346 00347 /* def setpos(y, x) */ 00348 static VALUE 00349 curses_setpos(VALUE obj, VALUE y, VALUE x) 00350 { 00351 curses_stdscr(); 00352 move(NUM2INT(y), NUM2INT(x)); 00353 return Qnil; 00354 } 00355 00356 /* def standout */ 00357 static VALUE 00358 curses_standout(VALUE obj) 00359 { 00360 curses_stdscr(); 00361 standout(); 00362 return Qnil; 00363 } 00364 00365 /* def standend */ 00366 static VALUE 00367 curses_standend(VALUE obj) 00368 { 00369 curses_stdscr(); 00370 standend(); 00371 return Qnil; 00372 } 00373 00374 /* def inch */ 00375 static VALUE 00376 curses_inch(VALUE obj) 00377 { 00378 curses_stdscr(); 00379 return CH2FIX(inch()); 00380 } 00381 00382 /* def addch(ch) */ 00383 static VALUE 00384 curses_addch(VALUE obj, VALUE ch) 00385 { 00386 curses_stdscr(); 00387 addch(NUM2CH(ch)); 00388 return Qnil; 00389 } 00390 00391 /* def insch(ch) */ 00392 static VALUE 00393 curses_insch(VALUE obj, VALUE ch) 00394 { 00395 curses_stdscr(); 00396 insch(NUM2CH(ch)); 00397 return Qnil; 00398 } 00399 00400 /* def addstr(str) */ 00401 static VALUE 00402 curses_addstr(VALUE obj, VALUE str) 00403 { 00404 StringValue(str); 00405 str = rb_str_export_locale(str); 00406 curses_stdscr(); 00407 if (!NIL_P(str)) { 00408 addstr(StringValueCStr(str)); 00409 } 00410 return Qnil; 00411 } 00412 00413 static VALUE 00414 getch_func(void *arg) 00415 { 00416 int *ip = (int *)arg; 00417 *ip = getch(); 00418 return Qnil; 00419 } 00420 00421 /* def getch */ 00422 static VALUE 00423 curses_getch(VALUE obj) 00424 { 00425 int c; 00426 00427 curses_stdscr(); 00428 rb_thread_blocking_region(getch_func, (void *)&c, RUBY_UBF_IO, 0); 00429 if (c == EOF) return Qnil; 00430 if (rb_isprint(c)) { 00431 char ch = (char)c; 00432 00433 return rb_locale_str_new(&ch, 1); 00434 } 00435 return UINT2NUM(c); 00436 } 00437 00438 /* This should be big enough.. I hope */ 00439 #define GETSTR_BUF_SIZE 1024 00440 00441 static VALUE 00442 getstr_func(void *arg) 00443 { 00444 char *rtn = (char *)arg; 00445 #if defined(HAVE_GETNSTR) 00446 getnstr(rtn,GETSTR_BUF_SIZE-1); 00447 #else 00448 getstr(rtn); 00449 #endif 00450 return Qnil; 00451 } 00452 00453 /* def getstr */ 00454 static VALUE 00455 curses_getstr(VALUE obj) 00456 { 00457 char rtn[GETSTR_BUF_SIZE]; 00458 00459 curses_stdscr(); 00460 rb_thread_blocking_region(getstr_func, (void *)rtn, RUBY_UBF_IO, 0); 00461 return rb_locale_str_new_cstr(rtn); 00462 } 00463 00464 /* def delch */ 00465 static VALUE 00466 curses_delch(VALUE obj) 00467 { 00468 curses_stdscr(); 00469 delch(); 00470 return Qnil; 00471 } 00472 00473 /* def delelteln */ 00474 static VALUE 00475 curses_deleteln(VALUE obj) 00476 { 00477 curses_stdscr(); 00478 #if defined(HAVE_DELETELN) || defined(deleteln) 00479 deleteln(); 00480 #endif 00481 return Qnil; 00482 } 00483 00484 /* def insertln */ 00485 static VALUE 00486 curses_insertln(VALUE obj) 00487 { 00488 curses_stdscr(); 00489 #if defined(HAVE_INSERTLN) || defined(insertln) 00490 insertln(); 00491 #endif 00492 return Qnil; 00493 } 00494 00495 /* def keyname */ 00496 static VALUE 00497 curses_keyname(VALUE obj, VALUE c) 00498 { 00499 #ifdef HAVE_KEYNAME 00500 int cc = curses_char(c); 00501 const char *name; 00502 00503 curses_stdscr(); 00504 name = keyname(cc); 00505 if (name) { 00506 return rb_str_new_cstr(name); 00507 } 00508 else { 00509 return Qnil; 00510 } 00511 #else 00512 return Qnil; 00513 #endif 00514 } 00515 00516 static VALUE 00517 curses_lines(void) 00518 { 00519 return INT2FIX(LINES); 00520 } 00521 00522 static VALUE 00523 curses_cols(void) 00524 { 00525 return INT2FIX(COLS); 00526 } 00527 00534 static VALUE 00535 curses_curs_set(VALUE obj, VALUE visibility) 00536 { 00537 #ifdef HAVE_CURS_SET 00538 int n; 00539 curses_stdscr(); 00540 return (n = curs_set(NUM2INT(visibility)) != ERR) ? INT2FIX(n) : Qnil; 00541 #else 00542 return Qnil; 00543 #endif 00544 } 00545 00546 static VALUE 00547 curses_scrl(VALUE obj, VALUE n) 00548 { 00549 /* may have to raise exception on ERR */ 00550 #ifdef HAVE_SCRL 00551 curses_stdscr(); 00552 return (scrl(NUM2INT(n)) == OK) ? Qtrue : Qfalse; 00553 #else 00554 return Qfalse; 00555 #endif 00556 } 00557 00558 static VALUE 00559 curses_setscrreg(VALUE obj, VALUE top, VALUE bottom) 00560 { 00561 /* may have to raise exception on ERR */ 00562 #ifdef HAVE_SETSCRREG 00563 curses_stdscr(); 00564 return (setscrreg(NUM2INT(top), NUM2INT(bottom)) == OK) ? Qtrue : Qfalse; 00565 #else 00566 return Qfalse; 00567 #endif 00568 } 00569 00570 static VALUE 00571 curses_attroff(VALUE obj, VALUE attrs) 00572 { 00573 curses_stdscr(); 00574 return window_attroff(rb_stdscr,attrs); 00575 /* return INT2FIX(attroff(NUM2INT(attrs))); */ 00576 } 00577 00578 static VALUE 00579 curses_attron(VALUE obj, VALUE attrs) 00580 { 00581 curses_stdscr(); 00582 return window_attron(rb_stdscr,attrs); 00583 /* return INT2FIX(attroff(NUM2INT(attrs))); */ 00584 } 00585 00586 static VALUE 00587 curses_attrset(VALUE obj, VALUE attrs) 00588 { 00589 curses_stdscr(); 00590 return window_attrset(rb_stdscr,attrs); 00591 /* return INT2FIX(attroff(NUM2INT(attrs))); */ 00592 } 00593 00594 static VALUE 00595 curses_bkgdset(VALUE obj, VALUE ch) 00596 { 00597 #ifdef HAVE_BKGDSET 00598 curses_stdscr(); 00599 bkgdset(NUM2CH(ch)); 00600 #endif 00601 return Qnil; 00602 } 00603 00604 static VALUE 00605 curses_bkgd(VALUE obj, VALUE ch) 00606 { 00607 #ifdef HAVE_BKGD 00608 curses_stdscr(); 00609 return (bkgd(NUM2CH(ch)) == OK) ? Qtrue : Qfalse; 00610 #else 00611 return Qfalse; 00612 #endif 00613 } 00614 00615 #if defined(HAVE_USE_DEFAULT_COLORS) 00616 static VALUE 00617 curses_use_default_colors(VALUE obj) 00618 { 00619 curses_stdscr(); 00620 use_default_colors(); 00621 return Qnil; 00622 } 00623 #else 00624 #define curses_use_default_colors rb_f_notimplement 00625 #endif 00626 00627 #if defined(HAVE_TABSIZE) 00628 static VALUE 00629 curses_tabsize_set(VALUE obj, VALUE val) 00630 { 00631 TABSIZE = NUM2INT(val); 00632 return INT2NUM(TABSIZE); 00633 } 00634 #else 00635 #define curses_tabsize_set rb_f_notimplement 00636 #endif 00637 00638 #if defined(HAVE_TABSIZE) 00639 static VALUE 00640 curses_tabsize_get(VALUE ojb) 00641 { 00642 return INT2NUM(TABSIZE); 00643 } 00644 #else 00645 #define curses_tabsize_get rb_f_notimplement 00646 #endif 00647 00648 #if defined(HAVE_ESCDELAY) 00649 static VALUE 00650 curses_escdelay_set(VALUE obj, VALUE val) 00651 { 00652 ESCDELAY = NUM2INT(val); 00653 return INT2NUM(ESCDELAY); 00654 } 00655 #else 00656 #define curses_escdelay_set rb_f_notimplement 00657 #endif 00658 00659 #if defined(HAVE_ESCDELAY) 00660 static VALUE 00661 curses_escdelay_get(VALUE obj) 00662 { 00663 return INT2NUM(ESCDELAY); 00664 } 00665 #else 00666 #define curses_escdelay_get rb_f_notimplement 00667 #endif 00668 00669 static VALUE 00670 curses_resizeterm(VALUE obj, VALUE lin, VALUE col) 00671 { 00672 #if defined(HAVE_RESIZETERM) 00673 curses_stdscr(); 00674 return (resizeterm(NUM2INT(lin),NUM2INT(col)) == OK) ? Qtrue : Qfalse; 00675 #else 00676 return Qnil; 00677 #endif 00678 } 00679 00680 #ifdef USE_COLOR 00681 static VALUE 00682 curses_start_color(VALUE obj) 00683 { 00684 /* may have to raise exception on ERR */ 00685 curses_stdscr(); 00686 return (start_color() == OK) ? Qtrue : Qfalse; 00687 } 00688 00689 static VALUE 00690 curses_init_pair(VALUE obj, VALUE pair, VALUE f, VALUE b) 00691 { 00692 /* may have to raise exception on ERR */ 00693 curses_stdscr(); 00694 return (init_pair(NUM2INT(pair),NUM2INT(f),NUM2INT(b)) == OK) ? Qtrue : Qfalse; 00695 } 00696 00697 static VALUE 00698 curses_init_color(VALUE obj, VALUE color, VALUE r, VALUE g, VALUE b) 00699 { 00700 /* may have to raise exception on ERR */ 00701 curses_stdscr(); 00702 return (init_color(NUM2INT(color),NUM2INT(r), 00703 NUM2INT(g),NUM2INT(b)) == OK) ? Qtrue : Qfalse; 00704 } 00705 00706 static VALUE 00707 curses_has_colors(VALUE obj) 00708 { 00709 curses_stdscr(); 00710 return has_colors() ? Qtrue : Qfalse; 00711 } 00712 00713 static VALUE 00714 curses_can_change_color(VALUE obj) 00715 { 00716 curses_stdscr(); 00717 return can_change_color() ? Qtrue : Qfalse; 00718 } 00719 00720 #if defined(HAVE_COLORS) 00721 static VALUE 00722 curses_colors(VALUE obj) 00723 { 00724 return INT2FIX(COLORS); 00725 } 00726 #else 00727 #define curses_colors rb_f_notimplement 00728 #endif 00729 00730 static VALUE 00731 curses_color_content(VALUE obj, VALUE color) 00732 { 00733 short r,g,b; 00734 00735 curses_stdscr(); 00736 color_content(NUM2INT(color),&r,&g,&b); 00737 return rb_ary_new3(3,INT2FIX(r),INT2FIX(g),INT2FIX(b)); 00738 } 00739 00740 00741 #if defined(HAVE_COLOR_PAIRS) 00742 static VALUE 00743 curses_color_pairs(VALUE obj) 00744 { 00745 return INT2FIX(COLOR_PAIRS); 00746 } 00747 #else 00748 #define curses_color_pairs rb_f_notimplement 00749 #endif 00750 00751 static VALUE 00752 curses_pair_content(VALUE obj, VALUE pair) 00753 { 00754 short f,b; 00755 00756 curses_stdscr(); 00757 pair_content(NUM2INT(pair),&f,&b); 00758 return rb_ary_new3(2,INT2FIX(f),INT2FIX(b)); 00759 } 00760 00761 static VALUE 00762 curses_color_pair(VALUE obj, VALUE attrs) 00763 { 00764 return INT2FIX(COLOR_PAIR(NUM2INT(attrs))); 00765 } 00766 00767 static VALUE 00768 curses_pair_number(VALUE obj, VALUE attrs) 00769 { 00770 curses_stdscr(); 00771 return INT2FIX(PAIR_NUMBER(NUM2INT(attrs))); 00772 } 00773 #endif /* USE_COLOR */ 00774 00775 #ifdef USE_MOUSE 00776 struct mousedata { 00777 MEVENT *mevent; 00778 }; 00779 00780 static void 00781 no_mevent(void) 00782 { 00783 rb_raise(rb_eRuntimeError, "no such mouse event"); 00784 } 00785 00786 #define GetMOUSE(obj, data) do {\ 00787 if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)\ 00788 rb_raise(rb_eSecurityError, "Insecure: operation on untainted mouse");\ 00789 Data_Get_Struct(obj, struct mousedata, data);\ 00790 if (data->mevent == 0) no_mevent();\ 00791 } while (0) 00792 00793 static void 00794 curses_mousedata_free(struct mousedata *mdata) 00795 { 00796 if (mdata->mevent) 00797 xfree(mdata->mevent); 00798 } 00799 00800 static VALUE 00801 curses_getmouse(VALUE obj) 00802 { 00803 struct mousedata *mdata; 00804 VALUE val; 00805 00806 curses_stdscr(); 00807 val = Data_Make_Struct(cMouseEvent,struct mousedata, 00808 0,curses_mousedata_free,mdata); 00809 mdata->mevent = (MEVENT*)xmalloc(sizeof(MEVENT)); 00810 return (getmouse(mdata->mevent) == OK) ? val : Qnil; 00811 } 00812 00813 static VALUE 00814 curses_ungetmouse(VALUE obj, VALUE mevent) 00815 { 00816 struct mousedata *mdata; 00817 00818 curses_stdscr(); 00819 GetMOUSE(mevent,mdata); 00820 return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse; 00821 } 00822 00823 static VALUE 00824 curses_mouseinterval(VALUE obj, VALUE interval) 00825 { 00826 curses_stdscr(); 00827 return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse; 00828 } 00829 00830 static VALUE 00831 curses_mousemask(VALUE obj, VALUE mask) 00832 { 00833 curses_stdscr(); 00834 return INT2NUM(mousemask(NUM2UINT(mask),NULL)); 00835 } 00836 00837 #define DEFINE_MOUSE_GET_MEMBER(func_name,mem) \ 00838 static VALUE func_name (VALUE mouse) \ 00839 { \ 00840 struct mousedata *mdata; \ 00841 GetMOUSE(mouse, mdata); \ 00842 return (UINT2NUM(mdata->mevent -> mem)); \ 00843 } 00844 00845 DEFINE_MOUSE_GET_MEMBER(curs_mouse_id, id) 00846 DEFINE_MOUSE_GET_MEMBER(curs_mouse_x, x) 00847 DEFINE_MOUSE_GET_MEMBER(curs_mouse_y, y) 00848 DEFINE_MOUSE_GET_MEMBER(curs_mouse_z, z) 00849 DEFINE_MOUSE_GET_MEMBER(curs_mouse_bstate, bstate) 00850 #undef define_curs_mouse_member 00851 #endif /* USE_MOUSE */ 00852 00853 #ifdef HAVE_TIMEOUT 00854 static VALUE 00855 curses_timeout(VALUE obj, VALUE delay) 00856 { 00857 curses_stdscr(); 00858 timeout(NUM2INT(delay)); 00859 return Qnil; 00860 } 00861 #else 00862 #define curses_timeout rb_f_notimplement 00863 #endif 00864 00865 #ifdef HAVE_DEF_PROG_MODE 00866 static VALUE 00867 curses_def_prog_mode(VALUE obj) 00868 { 00869 curses_stdscr(); 00870 return def_prog_mode() == OK ? Qtrue : Qfalse; 00871 } 00872 #else 00873 #define curses_def_prog_mode rb_f_notimplement 00874 #endif 00875 00876 #ifdef HAVE_RESET_PROG_MODE 00877 static VALUE 00878 curses_reset_prog_mode(VALUE obj) 00879 { 00880 curses_stdscr(); 00881 return reset_prog_mode() == OK ? Qtrue : Qfalse; 00882 } 00883 #else 00884 #define curses_reset_prog_mode rb_f_notimplement 00885 #endif 00886 00887 /*-------------------------- class Window --------------------------*/ 00888 00889 /* def self.allocate */ 00890 static VALUE 00891 window_s_allocate(VALUE class) 00892 { 00893 struct windata *winp; 00894 00895 return Data_Make_Struct(class, struct windata, 0, free_window, winp); 00896 } 00897 00898 /* def initialize(h, w, top, left) */ 00899 static VALUE 00900 window_initialize(VALUE obj, VALUE h, VALUE w, VALUE top, VALUE left) 00901 { 00902 struct windata *winp; 00903 WINDOW *window; 00904 00905 rb_secure(4); 00906 curses_init_screen(); 00907 Data_Get_Struct(obj, struct windata, winp); 00908 if (winp->window) delwin(winp->window); 00909 window = newwin(NUM2INT(h), NUM2INT(w), NUM2INT(top), NUM2INT(left)); 00910 wclear(window); 00911 winp->window = window; 00912 00913 return obj; 00914 } 00915 00916 /* def subwin(height, width, top, left) */ 00917 static VALUE 00918 window_subwin(VALUE obj, VALUE height, VALUE width, VALUE top, VALUE left) 00919 { 00920 struct windata *winp; 00921 WINDOW *window; 00922 VALUE win; 00923 int h, w, t, l; 00924 00925 h = NUM2INT(height); 00926 w = NUM2INT(width); 00927 t = NUM2INT(top); 00928 l = NUM2INT(left); 00929 GetWINDOW(obj, winp); 00930 window = subwin(winp->window, h, w, t, l); 00931 win = prep_window(rb_obj_class(obj), window); 00932 00933 return win; 00934 } 00935 00936 /* def close */ 00937 static VALUE 00938 window_close(VALUE obj) 00939 { 00940 struct windata *winp; 00941 00942 GetWINDOW(obj, winp); 00943 delwin(winp->window); 00944 winp->window = 0; 00945 00946 return Qnil; 00947 } 00948 00949 /* def clear */ 00950 static VALUE 00951 window_clear(VALUE obj) 00952 { 00953 struct windata *winp; 00954 00955 GetWINDOW(obj, winp); 00956 wclear(winp->window); 00957 00958 return Qnil; 00959 } 00960 00961 /* def clrtoeol */ 00962 static VALUE 00963 window_clrtoeol(VALUE obj) 00964 { 00965 struct windata *winp; 00966 00967 GetWINDOW(obj, winp); 00968 wclrtoeol(winp->window); 00969 00970 return Qnil; 00971 } 00972 00973 /* def refresh */ 00974 static VALUE 00975 window_refresh(VALUE obj) 00976 { 00977 struct windata *winp; 00978 00979 GetWINDOW(obj, winp); 00980 wrefresh(winp->window); 00981 00982 return Qnil; 00983 } 00984 00985 /* def noutrefresh */ 00986 static VALUE 00987 window_noutrefresh(VALUE obj) 00988 { 00989 struct windata *winp; 00990 00991 GetWINDOW(obj, winp); 00992 #ifdef HAVE_DOUPDATE 00993 wnoutrefresh(winp->window); 00994 #else 00995 wrefresh(winp->window); 00996 #endif 00997 00998 return Qnil; 00999 } 01000 01001 /* def move(y, x) */ 01002 static VALUE 01003 window_move(VALUE obj, VALUE y, VALUE x) 01004 { 01005 struct windata *winp; 01006 01007 GetWINDOW(obj, winp); 01008 mvwin(winp->window, NUM2INT(y), NUM2INT(x)); 01009 01010 return Qnil; 01011 } 01012 01013 /* def setpos(y, x) */ 01014 static VALUE 01015 window_setpos(VALUE obj, VALUE y, VALUE x) 01016 { 01017 struct windata *winp; 01018 01019 GetWINDOW(obj, winp); 01020 wmove(winp->window, NUM2INT(y), NUM2INT(x)); 01021 return Qnil; 01022 } 01023 01024 /* def cury */ 01025 static VALUE 01026 window_cury(VALUE obj) 01027 { 01028 struct windata *winp; 01029 int x, y; 01030 01031 GetWINDOW(obj, winp); 01032 getyx(winp->window, y, x); 01033 return INT2FIX(y); 01034 } 01035 01036 /* def curx */ 01037 static VALUE 01038 window_curx(VALUE obj) 01039 { 01040 struct windata *winp; 01041 int x, y; 01042 01043 GetWINDOW(obj, winp); 01044 getyx(winp->window, y, x); 01045 return INT2FIX(x); 01046 } 01047 01048 /* def maxy */ 01049 static VALUE 01050 window_maxy(VALUE obj) 01051 { 01052 struct windata *winp; 01053 01054 GetWINDOW(obj, winp); 01055 #if defined(getmaxy) 01056 return INT2FIX(getmaxy(winp->window)); 01057 #elif defined(getmaxyx) 01058 { 01059 int x, y; 01060 getmaxyx(winp->window, y, x); 01061 return INT2FIX(y); 01062 } 01063 #else 01064 return INT2FIX(winp->window->_maxy+1); 01065 #endif 01066 } 01067 01068 /* def maxx */ 01069 static VALUE 01070 window_maxx(VALUE obj) 01071 { 01072 struct windata *winp; 01073 01074 GetWINDOW(obj, winp); 01075 #if defined(getmaxx) 01076 return INT2FIX(getmaxx(winp->window)); 01077 #elif defined(getmaxyx) 01078 { 01079 int x, y; 01080 getmaxyx(winp->window, y, x); 01081 return INT2FIX(x); 01082 } 01083 #else 01084 return INT2FIX(winp->window->_maxx+1); 01085 #endif 01086 } 01087 01088 /* def begy */ 01089 static VALUE 01090 window_begy(VALUE obj) 01091 { 01092 struct windata *winp; 01093 int x, y; 01094 01095 GetWINDOW(obj, winp); 01096 #ifdef getbegyx 01097 getbegyx(winp->window, y, x); 01098 return INT2FIX(y); 01099 #else 01100 return INT2FIX(winp->window->_begy); 01101 #endif 01102 } 01103 01104 /* def begx */ 01105 static VALUE 01106 window_begx(VALUE obj) 01107 { 01108 struct windata *winp; 01109 int x, y; 01110 01111 GetWINDOW(obj, winp); 01112 #ifdef getbegyx 01113 getbegyx(winp->window, y, x); 01114 return INT2FIX(x); 01115 #else 01116 return INT2FIX(winp->window->_begx); 01117 #endif 01118 } 01119 01120 /* def box(vert, hor) */ 01121 static VALUE 01122 window_box(int argc, VALUE *argv, VALUE self) 01123 { 01124 struct windata *winp; 01125 VALUE vert, hor, corn; 01126 01127 rb_scan_args(argc, argv, "21", &vert, &hor, &corn); 01128 01129 GetWINDOW(self, winp); 01130 box(winp->window, NUM2CH(vert), NUM2CH(hor)); 01131 01132 if (!NIL_P(corn)) { 01133 int cur_x, cur_y, x, y; 01134 chtype c; 01135 01136 c = NUM2CH(corn); 01137 getyx(winp->window, cur_y, cur_x); 01138 x = NUM2INT(window_maxx(self)) - 1; 01139 y = NUM2INT(window_maxy(self)) - 1; 01140 wmove(winp->window, 0, 0); 01141 waddch(winp->window, c); 01142 wmove(winp->window, y, 0); 01143 waddch(winp->window, c); 01144 wmove(winp->window, y, x); 01145 waddch(winp->window, c); 01146 wmove(winp->window, 0, x); 01147 waddch(winp->window, c); 01148 wmove(winp->window, cur_y, cur_x); 01149 } 01150 01151 return Qnil; 01152 } 01153 01154 /* def standout */ 01155 static VALUE 01156 window_standout(VALUE obj) 01157 { 01158 struct windata *winp; 01159 01160 GetWINDOW(obj, winp); 01161 wstandout(winp->window); 01162 return Qnil; 01163 } 01164 01165 /* def standend */ 01166 static VALUE 01167 window_standend(VALUE obj) 01168 { 01169 struct windata *winp; 01170 01171 GetWINDOW(obj, winp); 01172 wstandend(winp->window); 01173 return Qnil; 01174 } 01175 01176 /* def inch */ 01177 static VALUE 01178 window_inch(VALUE obj) 01179 { 01180 struct windata *winp; 01181 01182 GetWINDOW(obj, winp); 01183 return CH2FIX(winch(winp->window)); 01184 } 01185 01186 /* def addch(ch) */ 01187 static VALUE 01188 window_addch(VALUE obj, VALUE ch) 01189 { 01190 struct windata *winp; 01191 01192 GetWINDOW(obj, winp); 01193 waddch(winp->window, NUM2CH(ch)); 01194 01195 return Qnil; 01196 } 01197 01198 /* def insch(ch) */ 01199 static VALUE 01200 window_insch(VALUE obj, VALUE ch) 01201 { 01202 struct windata *winp; 01203 01204 GetWINDOW(obj, winp); 01205 winsch(winp->window, NUM2CH(ch)); 01206 01207 return Qnil; 01208 } 01209 01210 /* def addstr(str) */ 01211 static VALUE 01212 window_addstr(VALUE obj, VALUE str) 01213 { 01214 if (!NIL_P(str)) { 01215 struct windata *winp; 01216 01217 StringValue(str); 01218 str = rb_str_export_locale(str); 01219 GetWINDOW(obj, winp); 01220 waddstr(winp->window, StringValueCStr(str)); 01221 } 01222 return Qnil; 01223 } 01224 01225 /* def <<(str) */ 01226 static VALUE 01227 window_addstr2(VALUE obj, VALUE str) 01228 { 01229 window_addstr(obj, str); 01230 return obj; 01231 } 01232 01233 struct wgetch_arg { 01234 WINDOW *win; 01235 int c; 01236 }; 01237 01238 static VALUE 01239 wgetch_func(void *_arg) 01240 { 01241 struct wgetch_arg *arg = (struct wgetch_arg *)_arg; 01242 arg->c = wgetch(arg->win); 01243 return Qnil; 01244 } 01245 01246 /* def getch */ 01247 static VALUE 01248 window_getch(VALUE obj) 01249 { 01250 struct windata *winp; 01251 struct wgetch_arg arg; 01252 int c; 01253 01254 GetWINDOW(obj, winp); 01255 arg.win = winp->window; 01256 rb_thread_blocking_region(wgetch_func, (void *)&arg, RUBY_UBF_IO, 0); 01257 c = arg.c; 01258 if (c == EOF) return Qnil; 01259 if (rb_isprint(c)) { 01260 char ch = (char)c; 01261 01262 return rb_locale_str_new(&ch, 1); 01263 } 01264 return UINT2NUM(c); 01265 } 01266 01267 struct wgetstr_arg { 01268 WINDOW *win; 01269 char rtn[GETSTR_BUF_SIZE]; 01270 }; 01271 01272 static VALUE 01273 wgetstr_func(void *_arg) 01274 { 01275 struct wgetstr_arg *arg = (struct wgetstr_arg *)_arg; 01276 #if defined(HAVE_WGETNSTR) 01277 wgetnstr(arg->win, arg->rtn, GETSTR_BUF_SIZE-1); 01278 #else 01279 wgetstr(arg->win, arg->rtn); 01280 #endif 01281 return Qnil; 01282 } 01283 01284 /* def getstr */ 01285 static VALUE 01286 window_getstr(VALUE obj) 01287 { 01288 struct windata *winp; 01289 struct wgetstr_arg arg; 01290 01291 GetWINDOW(obj, winp); 01292 arg.win = winp->window; 01293 rb_thread_blocking_region(wgetstr_func, (void *)&arg, RUBY_UBF_IO, 0); 01294 return rb_locale_str_new_cstr(arg.rtn); 01295 } 01296 01297 /* def delch */ 01298 static VALUE 01299 window_delch(VALUE obj) 01300 { 01301 struct windata *winp; 01302 01303 GetWINDOW(obj, winp); 01304 wdelch(winp->window); 01305 return Qnil; 01306 } 01307 01308 /* def delelteln */ 01309 static VALUE 01310 window_deleteln(VALUE obj) 01311 { 01312 #if defined(HAVE_WDELETELN) || defined(wdeleteln) 01313 struct windata *winp; 01314 01315 GetWINDOW(obj, winp); 01316 wdeleteln(winp->window); 01317 #endif 01318 return Qnil; 01319 } 01320 01321 /* def insertln */ 01322 static VALUE 01323 window_insertln(VALUE obj) 01324 { 01325 #if defined(HAVE_WINSERTLN) || defined(winsertln) 01326 struct windata *winp; 01327 01328 GetWINDOW(obj, winp); 01329 winsertln(winp->window); 01330 #endif 01331 return Qnil; 01332 } 01333 01334 static VALUE 01335 window_scrollok(VALUE obj, VALUE bf) 01336 { 01337 struct windata *winp; 01338 01339 GetWINDOW(obj, winp); 01340 scrollok(winp->window, RTEST(bf) ? TRUE : FALSE); 01341 return Qnil; 01342 } 01343 01344 static VALUE 01345 window_idlok(VALUE obj, VALUE bf) 01346 { 01347 struct windata *winp; 01348 01349 GetWINDOW(obj, winp); 01350 idlok(winp->window, RTEST(bf) ? TRUE : FALSE); 01351 return Qnil; 01352 } 01353 01354 static VALUE 01355 window_setscrreg(VALUE obj, VALUE top, VALUE bottom) 01356 { 01357 #ifdef HAVE_WSETSCRREG 01358 struct windata *winp; 01359 int res; 01360 01361 GetWINDOW(obj, winp); 01362 res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom)); 01363 /* may have to raise exception on ERR */ 01364 return (res == OK) ? Qtrue : Qfalse; 01365 #else 01366 return Qfalse; 01367 #endif 01368 } 01369 01370 #if defined(USE_COLOR) && defined(HAVE_WCOLOR_SET) 01371 static VALUE 01372 window_color_set(VALUE obj, VALUE col) 01373 { 01374 struct windata *winp; 01375 int res; 01376 01377 GetWINDOW(obj, winp); 01378 res = wcolor_set(winp->window, NUM2INT(col), NULL); 01379 return (res == OK) ? Qtrue : Qfalse; 01380 } 01381 #endif /* defined(USE_COLOR) && defined(HAVE_WCOLOR_SET) */ 01382 01383 static VALUE 01384 window_scroll(VALUE obj) 01385 { 01386 struct windata *winp; 01387 01388 GetWINDOW(obj, winp); 01389 /* may have to raise exception on ERR */ 01390 return (scroll(winp->window) == OK) ? Qtrue : Qfalse; 01391 } 01392 01393 static VALUE 01394 window_scrl(VALUE obj, VALUE n) 01395 { 01396 #ifdef HAVE_WSCRL 01397 struct windata *winp; 01398 01399 GetWINDOW(obj, winp); 01400 /* may have to raise exception on ERR */ 01401 return (wscrl(winp->window,NUM2INT(n)) == OK) ? Qtrue : Qfalse; 01402 #else 01403 return Qfalse; 01404 #endif 01405 } 01406 01407 static VALUE 01408 window_attroff(VALUE obj, VALUE attrs) 01409 { 01410 #ifdef HAVE_WATTROFF 01411 struct windata *winp; 01412 01413 GetWINDOW(obj,winp); 01414 return INT2FIX(wattroff(winp->window,NUM2INT(attrs))); 01415 #else 01416 return Qtrue; 01417 #endif 01418 } 01419 01420 static VALUE 01421 window_attron(VALUE obj, VALUE attrs) 01422 { 01423 #ifdef HAVE_WATTRON 01424 struct windata *winp; 01425 VALUE val; 01426 01427 GetWINDOW(obj,winp); 01428 val = INT2FIX(wattron(winp->window,NUM2INT(attrs))); 01429 if (rb_block_given_p()) { 01430 rb_yield(val); 01431 wattroff(winp->window,NUM2INT(attrs)); 01432 return val; 01433 } 01434 else{ 01435 return val; 01436 } 01437 #else 01438 return Qtrue; 01439 #endif 01440 } 01441 01442 static VALUE 01443 window_attrset(VALUE obj, VALUE attrs) 01444 { 01445 #ifdef HAVE_WATTRSET 01446 struct windata *winp; 01447 01448 GetWINDOW(obj,winp); 01449 return INT2FIX(wattrset(winp->window,NUM2INT(attrs))); 01450 #else 01451 return Qtrue; 01452 #endif 01453 } 01454 01455 static VALUE 01456 window_bkgdset(VALUE obj, VALUE ch) 01457 { 01458 #ifdef HAVE_WBKGDSET 01459 struct windata *winp; 01460 01461 GetWINDOW(obj,winp); 01462 wbkgdset(winp->window, NUM2CH(ch)); 01463 #endif 01464 return Qnil; 01465 } 01466 01467 static VALUE 01468 window_bkgd(VALUE obj, VALUE ch) 01469 { 01470 #ifdef HAVE_WBKGD 01471 struct windata *winp; 01472 01473 GetWINDOW(obj,winp); 01474 return (wbkgd(winp->window, NUM2CH(ch)) == OK) ? Qtrue : Qfalse; 01475 #else 01476 return Qfalse; 01477 #endif 01478 } 01479 01480 static VALUE 01481 window_getbkgd(VALUE obj) 01482 { 01483 #ifdef HAVE_WGETBKGD 01484 chtype c; 01485 struct windata *winp; 01486 01487 GetWINDOW(obj,winp); 01488 return (c = getbkgd(winp->window) != ERR) ? CH2FIX(c) : Qnil; 01489 #else 01490 return Qnil; 01491 #endif 01492 } 01493 01494 static VALUE 01495 window_resize(VALUE obj, VALUE lin, VALUE col) 01496 { 01497 #if defined(HAVE_WRESIZE) 01498 struct windata *winp; 01499 01500 GetWINDOW(obj,winp); 01501 return wresize(winp->window, NUM2INT(lin), NUM2INT(col)) == OK ? Qtrue : Qfalse; 01502 #else 01503 return Qnil; 01504 #endif 01505 } 01506 01507 01508 #ifdef HAVE_KEYPAD 01509 static VALUE 01510 window_keypad(VALUE obj, VALUE val) 01511 { 01512 struct windata *winp; 01513 01514 GetWINDOW(obj,winp); 01515 /* keypad() of NetBSD's libcurses returns no value */ 01516 #if defined(__NetBSD__) && !defined(NCURSES_VERSION) 01517 keypad(winp->window,(RTEST(val) ? TRUE : FALSE)); 01518 return Qnil; 01519 #else 01520 /* may have to raise exception on ERR */ 01521 return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ? 01522 Qtrue : Qfalse; 01523 #endif 01524 } 01525 #else 01526 #define window_keypad rb_f_notimplement 01527 #endif 01528 01529 #ifdef HAVE_NODELAY 01530 static VALUE 01531 window_nodelay(VALUE obj, VALUE val) 01532 { 01533 struct windata *winp; 01534 GetWINDOW(obj,winp); 01535 01536 /* nodelay() of NetBSD's libcurses returns no value */ 01537 #if defined(__NetBSD__) && !defined(NCURSES_VERSION) 01538 nodelay(winp->window, RTEST(val) ? TRUE : FALSE); 01539 return Qnil; 01540 #else 01541 return nodelay(winp->window,RTEST(val) ? TRUE : FALSE) == OK ? Qtrue : Qfalse; 01542 #endif 01543 } 01544 #else 01545 #define window_nodelay rb_f_notimplement 01546 #endif 01547 01548 #ifdef HAVE_WTIMEOUT 01549 static VALUE 01550 window_timeout(VALUE obj, VALUE delay) 01551 { 01552 struct windata *winp; 01553 GetWINDOW(obj,winp); 01554 01555 wtimeout(winp->window,NUM2INT(delay)); 01556 return Qnil; 01557 } 01558 #else 01559 #define window_timeout rb_f_notimplement 01560 #endif 01561 01562 /*------------------------- Initialization -------------------------*/ 01563 void 01564 Init_curses(void) 01565 { 01566 mCurses = rb_define_module("Curses"); 01567 mKey = rb_define_module_under(mCurses, "Key"); 01568 01569 rb_gc_register_address(&rb_stdscr); 01570 01571 #ifdef USE_MOUSE 01572 cMouseEvent = rb_define_class_under(mCurses,"MouseEvent",rb_cObject); 01573 rb_undef_method(CLASS_OF(cMouseEvent),"new"); 01574 rb_define_method(cMouseEvent, "eid", curs_mouse_id, 0); 01575 rb_define_method(cMouseEvent, "x", curs_mouse_x, 0); 01576 rb_define_method(cMouseEvent, "y", curs_mouse_y, 0); 01577 rb_define_method(cMouseEvent, "z", curs_mouse_z, 0); 01578 rb_define_method(cMouseEvent, "bstate", curs_mouse_bstate, 0); 01579 #endif /* USE_MOUSE */ 01580 01581 rb_define_module_function(mCurses, "ESCDELAY=", curses_escdelay_set, 1); 01582 rb_define_module_function(mCurses, "ESCDELAY", curses_escdelay_get, 0); 01583 rb_define_module_function(mCurses, "TABSIZE", curses_tabsize_get, 0); 01584 rb_define_module_function(mCurses, "TABSIZE=", curses_tabsize_set, 1); 01585 01586 rb_define_module_function(mCurses, "use_default_colors", curses_use_default_colors, 0); 01587 rb_define_module_function(mCurses, "init_screen", curses_init_screen, 0); 01588 rb_define_module_function(mCurses, "close_screen", curses_close_screen, 0); 01589 rb_define_module_function(mCurses, "closed?", curses_closed, 0); 01590 rb_define_module_function(mCurses, "stdscr", curses_stdscr, 0); 01591 rb_define_module_function(mCurses, "refresh", curses_refresh, 0); 01592 rb_define_module_function(mCurses, "doupdate", curses_doupdate, 0); 01593 rb_define_module_function(mCurses, "clear", curses_clear, 0); 01594 rb_define_module_function(mCurses, "clrtoeol", curses_clrtoeol, 0); 01595 rb_define_module_function(mCurses, "echo", curses_echo, 0); 01596 rb_define_module_function(mCurses, "noecho", curses_noecho, 0); 01597 rb_define_module_function(mCurses, "raw", curses_raw, 0); 01598 rb_define_module_function(mCurses, "noraw", curses_noraw, 0); 01599 rb_define_module_function(mCurses, "cbreak", curses_cbreak, 0); 01600 rb_define_module_function(mCurses, "nocbreak", curses_nocbreak, 0); 01601 rb_define_module_function(mCurses, "crmode", curses_nocbreak, 0); 01602 rb_define_module_function(mCurses, "nocrmode", curses_nocbreak, 0); 01603 rb_define_module_function(mCurses, "nl", curses_nl, 0); 01604 rb_define_module_function(mCurses, "nonl", curses_nonl, 0); 01605 rb_define_module_function(mCurses, "beep", curses_beep, 0); 01606 rb_define_module_function(mCurses, "flash", curses_flash, 0); 01607 rb_define_module_function(mCurses, "ungetch", curses_ungetch, 1); 01608 rb_define_module_function(mCurses, "setpos", curses_setpos, 2); 01609 rb_define_module_function(mCurses, "standout", curses_standout, 0); 01610 rb_define_module_function(mCurses, "standend", curses_standend, 0); 01611 rb_define_module_function(mCurses, "inch", curses_inch, 0); 01612 rb_define_module_function(mCurses, "addch", curses_addch, 1); 01613 rb_define_module_function(mCurses, "insch", curses_insch, 1); 01614 rb_define_module_function(mCurses, "addstr", curses_addstr, 1); 01615 rb_define_module_function(mCurses, "getch", curses_getch, 0); 01616 rb_define_module_function(mCurses, "getstr", curses_getstr, 0); 01617 rb_define_module_function(mCurses, "delch", curses_delch, 0); 01618 rb_define_module_function(mCurses, "deleteln", curses_deleteln, 0); 01619 rb_define_module_function(mCurses, "insertln", curses_insertln, 0); 01620 rb_define_module_function(mCurses, "keyname", curses_keyname, 1); 01621 rb_define_module_function(mCurses, "lines", curses_lines, 0); 01622 rb_define_module_function(mCurses, "cols", curses_cols, 0); 01623 rb_define_module_function(mCurses, "curs_set", curses_curs_set, 1); 01624 rb_define_module_function(mCurses, "scrl", curses_scrl, 1); 01625 rb_define_module_function(mCurses, "setscrreg", curses_setscrreg, 2); 01626 rb_define_module_function(mCurses, "attroff", curses_attroff, 1); 01627 rb_define_module_function(mCurses, "attron", curses_attron, 1); 01628 rb_define_module_function(mCurses, "attrset", curses_attrset, 1); 01629 rb_define_module_function(mCurses, "bkgdset", curses_bkgdset, 1); 01630 rb_define_module_function(mCurses, "bkgd", curses_bkgd, 1); 01631 rb_define_module_function(mCurses, "resizeterm", curses_resizeterm, 2); 01632 rb_define_module_function(mCurses, "resize", curses_resizeterm, 2); 01633 #ifdef USE_COLOR 01634 rb_define_module_function(mCurses, "start_color", curses_start_color, 0); 01635 rb_define_module_function(mCurses, "init_pair", curses_init_pair, 3); 01636 rb_define_module_function(mCurses, "init_color", curses_init_color, 4); 01637 rb_define_module_function(mCurses, "has_colors?", curses_has_colors, 0); 01638 rb_define_module_function(mCurses, "can_change_color?", 01639 curses_can_change_color, 0); 01640 rb_define_module_function(mCurses, "colors", curses_colors, 0); 01641 rb_define_module_function(mCurses, "color_content", curses_color_content, 1); 01642 rb_define_module_function(mCurses, "color_pairs", curses_color_pairs, 0); 01643 rb_define_module_function(mCurses, "pair_content", curses_pair_content, 1); 01644 rb_define_module_function(mCurses, "color_pair", curses_color_pair, 1); 01645 rb_define_module_function(mCurses, "pair_number", curses_pair_number, 1); 01646 #endif /* USE_COLOR */ 01647 #ifdef USE_MOUSE 01648 rb_define_module_function(mCurses, "getmouse", curses_getmouse, 0); 01649 rb_define_module_function(mCurses, "ungetmouse", curses_ungetmouse, 1); 01650 rb_define_module_function(mCurses, "mouseinterval", curses_mouseinterval, 1); 01651 rb_define_module_function(mCurses, "mousemask", curses_mousemask, 1); 01652 #endif /* USE_MOUSE */ 01653 01654 rb_define_module_function(mCurses, "timeout=", curses_timeout, 1); 01655 rb_define_module_function(mCurses, "def_prog_mode", curses_def_prog_mode, 0); 01656 rb_define_module_function(mCurses, "reset_prog_mode", curses_reset_prog_mode, 0); 01657 01658 cWindow = rb_define_class_under(mCurses, "Window", rb_cData); 01659 rb_define_alloc_func(cWindow, window_s_allocate); 01660 rb_define_method(cWindow, "initialize", window_initialize, 4); 01661 rb_define_method(cWindow, "subwin", window_subwin, 4); 01662 rb_define_method(cWindow, "close", window_close, 0); 01663 rb_define_method(cWindow, "clear", window_clear, 0); 01664 rb_define_method(cWindow, "clrtoeol", window_clrtoeol, 0); 01665 rb_define_method(cWindow, "refresh", window_refresh, 0); 01666 rb_define_method(cWindow, "noutrefresh", window_noutrefresh, 0); 01667 rb_define_method(cWindow, "box", window_box, -1); 01668 rb_define_method(cWindow, "move", window_move, 2); 01669 rb_define_method(cWindow, "setpos", window_setpos, 2); 01670 #if defined(USE_COLOR) && defined(HAVE_WCOLOR_SET) 01671 rb_define_method(cWindow, "color_set", window_color_set, 1); 01672 #endif /* USE_COLOR && HAVE_WCOLOR_SET */ 01673 rb_define_method(cWindow, "cury", window_cury, 0); 01674 rb_define_method(cWindow, "curx", window_curx, 0); 01675 rb_define_method(cWindow, "maxy", window_maxy, 0); 01676 rb_define_method(cWindow, "maxx", window_maxx, 0); 01677 rb_define_method(cWindow, "begy", window_begy, 0); 01678 rb_define_method(cWindow, "begx", window_begx, 0); 01679 rb_define_method(cWindow, "standout", window_standout, 0); 01680 rb_define_method(cWindow, "standend", window_standend, 0); 01681 rb_define_method(cWindow, "inch", window_inch, 0); 01682 rb_define_method(cWindow, "addch", window_addch, 1); 01683 rb_define_method(cWindow, "insch", window_insch, 1); 01684 rb_define_method(cWindow, "addstr", window_addstr, 1); 01685 rb_define_method(cWindow, "<<", window_addstr2, 1); 01686 rb_define_method(cWindow, "getch", window_getch, 0); 01687 rb_define_method(cWindow, "getstr", window_getstr, 0); 01688 rb_define_method(cWindow, "delch", window_delch, 0); 01689 rb_define_method(cWindow, "deleteln", window_deleteln, 0); 01690 rb_define_method(cWindow, "insertln", window_insertln, 0); 01691 rb_define_method(cWindow, "scroll", window_scroll, 0); 01692 rb_define_method(cWindow, "scrollok", window_scrollok, 1); 01693 rb_define_method(cWindow, "idlok", window_idlok, 1); 01694 rb_define_method(cWindow, "setscrreg", window_setscrreg, 2); 01695 rb_define_method(cWindow, "scrl", window_scrl, 1); 01696 rb_define_method(cWindow, "resize", window_resize, 2); 01697 rb_define_method(cWindow, "keypad", window_keypad, 1); 01698 rb_define_method(cWindow, "keypad=", window_keypad, 1); 01699 01700 rb_define_method(cWindow, "attroff", window_attroff, 1); 01701 rb_define_method(cWindow, "attron", window_attron, 1); 01702 rb_define_method(cWindow, "attrset", window_attrset, 1); 01703 rb_define_method(cWindow, "bkgdset", window_bkgdset, 1); 01704 rb_define_method(cWindow, "bkgd", window_bkgd, 1); 01705 rb_define_method(cWindow, "getbkgd", window_getbkgd, 0); 01706 01707 rb_define_method(cWindow, "nodelay=", window_nodelay, 1); 01708 rb_define_method(cWindow, "timeout=", window_timeout, 1); 01709 01710 #define rb_curses_define_const(c) rb_define_const(mCurses,#c,UINT2NUM(c)) 01711 01712 #ifdef USE_COLOR 01713 rb_curses_define_const(A_ATTRIBUTES); 01714 #ifdef A_NORMAL 01715 rb_curses_define_const(A_NORMAL); 01716 #endif 01717 rb_curses_define_const(A_STANDOUT); 01718 rb_curses_define_const(A_UNDERLINE); 01719 rb_curses_define_const(A_REVERSE); 01720 rb_curses_define_const(A_BLINK); 01721 rb_curses_define_const(A_DIM); 01722 rb_curses_define_const(A_BOLD); 01723 rb_curses_define_const(A_PROTECT); 01724 #ifdef A_INVIS /* for NetBSD */ 01725 rb_curses_define_const(A_INVIS); 01726 #endif 01727 rb_curses_define_const(A_ALTCHARSET); 01728 rb_curses_define_const(A_CHARTEXT); 01729 #ifdef A_HORIZONTAL 01730 rb_curses_define_const(A_HORIZONTAL); 01731 #endif 01732 #ifdef A_LEFT 01733 rb_curses_define_const(A_LEFT); 01734 #endif 01735 #ifdef A_LOW 01736 rb_curses_define_const(A_LOW); 01737 #endif 01738 #ifdef A_RIGHT 01739 rb_curses_define_const(A_RIGHT); 01740 #endif 01741 #ifdef A_TOP 01742 rb_curses_define_const(A_TOP); 01743 #endif 01744 #ifdef A_VERTICAL 01745 rb_curses_define_const(A_VERTICAL); 01746 #endif 01747 rb_curses_define_const(A_COLOR); 01748 01749 #ifdef COLORS 01750 rb_curses_define_const(COLORS); 01751 #endif 01752 rb_curses_define_const(COLOR_BLACK); 01753 rb_curses_define_const(COLOR_RED); 01754 rb_curses_define_const(COLOR_GREEN); 01755 rb_curses_define_const(COLOR_YELLOW); 01756 rb_curses_define_const(COLOR_BLUE); 01757 rb_curses_define_const(COLOR_MAGENTA); 01758 rb_curses_define_const(COLOR_CYAN); 01759 rb_curses_define_const(COLOR_WHITE); 01760 #endif /* USE_COLOR */ 01761 #ifdef USE_MOUSE 01762 #ifdef BUTTON1_PRESSED 01763 rb_curses_define_const(BUTTON1_PRESSED); 01764 #endif 01765 #ifdef BUTTON1_RELEASED 01766 rb_curses_define_const(BUTTON1_RELEASED); 01767 #endif 01768 #ifdef BUTTON1_CLICKED 01769 rb_curses_define_const(BUTTON1_CLICKED); 01770 #endif 01771 #ifdef BUTTON1_DOUBLE_CLICKED 01772 rb_curses_define_const(BUTTON1_DOUBLE_CLICKED); 01773 #endif 01774 #ifdef BUTTON1_TRIPLE_CLICKED 01775 rb_curses_define_const(BUTTON1_TRIPLE_CLICKED); 01776 #endif 01777 #ifdef BUTTON2_PRESSED 01778 rb_curses_define_const(BUTTON2_PRESSED); 01779 #endif 01780 #ifdef BUTTON2_RELEASED 01781 rb_curses_define_const(BUTTON2_RELEASED); 01782 #endif 01783 #ifdef BUTTON2_CLICKED 01784 rb_curses_define_const(BUTTON2_CLICKED); 01785 #endif 01786 #ifdef BUTTON2_DOUBLE_CLICKED 01787 rb_curses_define_const(BUTTON2_DOUBLE_CLICKED); 01788 #endif 01789 #ifdef BUTTON2_TRIPLE_CLICKED 01790 rb_curses_define_const(BUTTON2_TRIPLE_CLICKED); 01791 #endif 01792 #ifdef BUTTON3_PRESSED 01793 rb_curses_define_const(BUTTON3_PRESSED); 01794 #endif 01795 #ifdef BUTTON3_RELEASED 01796 rb_curses_define_const(BUTTON3_RELEASED); 01797 #endif 01798 #ifdef BUTTON3_CLICKED 01799 rb_curses_define_const(BUTTON3_CLICKED); 01800 #endif 01801 #ifdef BUTTON3_DOUBLE_CLICKED 01802 rb_curses_define_const(BUTTON3_DOUBLE_CLICKED); 01803 #endif 01804 #ifdef BUTTON3_TRIPLE_CLICKED 01805 rb_curses_define_const(BUTTON3_TRIPLE_CLICKED); 01806 #endif 01807 #ifdef BUTTON4_PRESSED 01808 rb_curses_define_const(BUTTON4_PRESSED); 01809 #endif 01810 #ifdef BUTTON4_RELEASED 01811 rb_curses_define_const(BUTTON4_RELEASED); 01812 #endif 01813 #ifdef BUTTON4_CLICKED 01814 rb_curses_define_const(BUTTON4_CLICKED); 01815 #endif 01816 #ifdef BUTTON4_DOUBLE_CLICKED 01817 rb_curses_define_const(BUTTON4_DOUBLE_CLICKED); 01818 #endif 01819 #ifdef BUTTON4_TRIPLE_CLICKED 01820 rb_curses_define_const(BUTTON4_TRIPLE_CLICKED); 01821 #endif 01822 #ifdef BUTTON_SHIFT 01823 rb_curses_define_const(BUTTON_SHIFT); 01824 #endif 01825 #ifdef BUTTON_CTRL 01826 rb_curses_define_const(BUTTON_CTRL); 01827 #endif 01828 #ifdef BUTTON_ALT 01829 rb_curses_define_const(BUTTON_ALT); 01830 #endif 01831 #ifdef ALL_MOUSE_EVENTS 01832 rb_curses_define_const(ALL_MOUSE_EVENTS); 01833 #endif 01834 #ifdef REPORT_MOUSE_POSITION 01835 rb_curses_define_const(REPORT_MOUSE_POSITION); 01836 #endif 01837 #endif /* USE_MOUSE */ 01838 01839 #if defined(KEY_MOUSE) && defined(USE_MOUSE) 01840 rb_curses_define_const(KEY_MOUSE); 01841 rb_define_const(mKey, "MOUSE", INT2NUM(KEY_MOUSE)); 01842 #endif 01843 #ifdef KEY_MIN 01844 rb_curses_define_const(KEY_MIN); 01845 rb_define_const(mKey, "MIN", INT2NUM(KEY_MIN)); 01846 #endif 01847 #ifdef KEY_BREAK 01848 rb_curses_define_const(KEY_BREAK); 01849 rb_define_const(mKey, "BREAK", INT2NUM(KEY_BREAK)); 01850 #endif 01851 #ifdef KEY_DOWN 01852 rb_curses_define_const(KEY_DOWN); 01853 rb_define_const(mKey, "DOWN", INT2NUM(KEY_DOWN)); 01854 #endif 01855 #ifdef KEY_UP 01856 rb_curses_define_const(KEY_UP); 01857 rb_define_const(mKey, "UP", INT2NUM(KEY_UP)); 01858 #endif 01859 #ifdef KEY_LEFT 01860 rb_curses_define_const(KEY_LEFT); 01861 rb_define_const(mKey, "LEFT", INT2NUM(KEY_LEFT)); 01862 #endif 01863 #ifdef KEY_RIGHT 01864 rb_curses_define_const(KEY_RIGHT); 01865 rb_define_const(mKey, "RIGHT", INT2NUM(KEY_RIGHT)); 01866 #endif 01867 #ifdef KEY_HOME 01868 rb_curses_define_const(KEY_HOME); 01869 rb_define_const(mKey, "HOME", INT2NUM(KEY_HOME)); 01870 #endif 01871 #ifdef KEY_BACKSPACE 01872 rb_curses_define_const(KEY_BACKSPACE); 01873 rb_define_const(mKey, "BACKSPACE", INT2NUM(KEY_BACKSPACE)); 01874 #endif 01875 #ifdef KEY_F 01876 /* KEY_F(n) : 0 <= n <= 63 */ 01877 { 01878 int i; 01879 char c[8]; 01880 for (i=0; i<64; i++) { 01881 sprintf(c, "KEY_F%d", i); 01882 rb_define_const(mCurses, c, INT2NUM(KEY_F(i))); 01883 sprintf(c, "F%d", i); 01884 rb_define_const(mKey, c, INT2NUM(KEY_F(i))); 01885 } 01886 } 01887 #endif 01888 #ifdef KEY_DL 01889 rb_curses_define_const(KEY_DL); 01890 rb_define_const(mKey, "DL", INT2NUM(KEY_DL)); 01891 #endif 01892 #ifdef KEY_IL 01893 rb_curses_define_const(KEY_IL); 01894 rb_define_const(mKey, "IL", INT2NUM(KEY_IL)); 01895 #endif 01896 #ifdef KEY_DC 01897 rb_curses_define_const(KEY_DC); 01898 rb_define_const(mKey, "DC", INT2NUM(KEY_DC)); 01899 #endif 01900 #ifdef KEY_IC 01901 rb_curses_define_const(KEY_IC); 01902 rb_define_const(mKey, "IC", INT2NUM(KEY_IC)); 01903 #endif 01904 #ifdef KEY_EIC 01905 rb_curses_define_const(KEY_EIC); 01906 rb_define_const(mKey, "EIC", INT2NUM(KEY_EIC)); 01907 #endif 01908 #ifdef KEY_CLEAR 01909 rb_curses_define_const(KEY_CLEAR); 01910 rb_define_const(mKey, "CLEAR", INT2NUM(KEY_CLEAR)); 01911 #endif 01912 #ifdef KEY_EOS 01913 rb_curses_define_const(KEY_EOS); 01914 rb_define_const(mKey, "EOS", INT2NUM(KEY_EOS)); 01915 #endif 01916 #ifdef KEY_EOL 01917 rb_curses_define_const(KEY_EOL); 01918 rb_define_const(mKey, "EOL", INT2NUM(KEY_EOL)); 01919 #endif 01920 #ifdef KEY_SF 01921 rb_curses_define_const(KEY_SF); 01922 rb_define_const(mKey, "SF", INT2NUM(KEY_SF)); 01923 #endif 01924 #ifdef KEY_SR 01925 rb_curses_define_const(KEY_SR); 01926 rb_define_const(mKey, "SR", INT2NUM(KEY_SR)); 01927 #endif 01928 #ifdef KEY_NPAGE 01929 rb_curses_define_const(KEY_NPAGE); 01930 rb_define_const(mKey, "NPAGE", INT2NUM(KEY_NPAGE)); 01931 #endif 01932 #ifdef KEY_PPAGE 01933 rb_curses_define_const(KEY_PPAGE); 01934 rb_define_const(mKey, "PPAGE", INT2NUM(KEY_PPAGE)); 01935 #endif 01936 #ifdef KEY_STAB 01937 rb_curses_define_const(KEY_STAB); 01938 rb_define_const(mKey, "STAB", INT2NUM(KEY_STAB)); 01939 #endif 01940 #ifdef KEY_CTAB 01941 rb_curses_define_const(KEY_CTAB); 01942 rb_define_const(mKey, "CTAB", INT2NUM(KEY_CTAB)); 01943 #endif 01944 #ifdef KEY_CATAB 01945 rb_curses_define_const(KEY_CATAB); 01946 rb_define_const(mKey, "CATAB", INT2NUM(KEY_CATAB)); 01947 #endif 01948 #ifdef KEY_ENTER 01949 rb_curses_define_const(KEY_ENTER); 01950 rb_define_const(mKey, "ENTER", INT2NUM(KEY_ENTER)); 01951 #endif 01952 #ifdef KEY_SRESET 01953 rb_curses_define_const(KEY_SRESET); 01954 rb_define_const(mKey, "SRESET", INT2NUM(KEY_SRESET)); 01955 #endif 01956 #ifdef KEY_RESET 01957 rb_curses_define_const(KEY_RESET); 01958 rb_define_const(mKey, "RESET", INT2NUM(KEY_RESET)); 01959 #endif 01960 #ifdef KEY_PRINT 01961 rb_curses_define_const(KEY_PRINT); 01962 rb_define_const(mKey, "PRINT", INT2NUM(KEY_PRINT)); 01963 #endif 01964 #ifdef KEY_LL 01965 rb_curses_define_const(KEY_LL); 01966 rb_define_const(mKey, "LL", INT2NUM(KEY_LL)); 01967 #endif 01968 #ifdef KEY_A1 01969 rb_curses_define_const(KEY_A1); 01970 rb_define_const(mKey, "A1", INT2NUM(KEY_A1)); 01971 #endif 01972 #ifdef KEY_A3 01973 rb_curses_define_const(KEY_A3); 01974 rb_define_const(mKey, "A3", INT2NUM(KEY_A3)); 01975 #endif 01976 #ifdef KEY_B2 01977 rb_curses_define_const(KEY_B2); 01978 rb_define_const(mKey, "B2", INT2NUM(KEY_B2)); 01979 #endif 01980 #ifdef KEY_C1 01981 rb_curses_define_const(KEY_C1); 01982 rb_define_const(mKey, "C1", INT2NUM(KEY_C1)); 01983 #endif 01984 #ifdef KEY_C3 01985 rb_curses_define_const(KEY_C3); 01986 rb_define_const(mKey, "C3", INT2NUM(KEY_C3)); 01987 #endif 01988 #ifdef KEY_BTAB 01989 rb_curses_define_const(KEY_BTAB); 01990 rb_define_const(mKey, "BTAB", INT2NUM(KEY_BTAB)); 01991 #endif 01992 #ifdef KEY_BEG 01993 rb_curses_define_const(KEY_BEG); 01994 rb_define_const(mKey, "BEG", INT2NUM(KEY_BEG)); 01995 #endif 01996 #ifdef KEY_CANCEL 01997 rb_curses_define_const(KEY_CANCEL); 01998 rb_define_const(mKey, "CANCEL", INT2NUM(KEY_CANCEL)); 01999 #endif 02000 #ifdef KEY_CLOSE 02001 rb_curses_define_const(KEY_CLOSE); 02002 rb_define_const(mKey, "CLOSE", INT2NUM(KEY_CLOSE)); 02003 #endif 02004 #ifdef KEY_COMMAND 02005 rb_curses_define_const(KEY_COMMAND); 02006 rb_define_const(mKey, "COMMAND", INT2NUM(KEY_COMMAND)); 02007 #endif 02008 #ifdef KEY_COPY 02009 rb_curses_define_const(KEY_COPY); 02010 rb_define_const(mKey, "COPY", INT2NUM(KEY_COPY)); 02011 #endif 02012 #ifdef KEY_CREATE 02013 rb_curses_define_const(KEY_CREATE); 02014 rb_define_const(mKey, "CREATE", INT2NUM(KEY_CREATE)); 02015 #endif 02016 #ifdef KEY_END 02017 rb_curses_define_const(KEY_END); 02018 rb_define_const(mKey, "END", INT2NUM(KEY_END)); 02019 #endif 02020 #ifdef KEY_EXIT 02021 rb_curses_define_const(KEY_EXIT); 02022 rb_define_const(mKey, "EXIT", INT2NUM(KEY_EXIT)); 02023 #endif 02024 #ifdef KEY_FIND 02025 rb_curses_define_const(KEY_FIND); 02026 rb_define_const(mKey, "FIND", INT2NUM(KEY_FIND)); 02027 #endif 02028 #ifdef KEY_HELP 02029 rb_curses_define_const(KEY_HELP); 02030 rb_define_const(mKey, "HELP", INT2NUM(KEY_HELP)); 02031 #endif 02032 #ifdef KEY_MARK 02033 rb_curses_define_const(KEY_MARK); 02034 rb_define_const(mKey, "MARK", INT2NUM(KEY_MARK)); 02035 #endif 02036 #ifdef KEY_MESSAGE 02037 rb_curses_define_const(KEY_MESSAGE); 02038 rb_define_const(mKey, "MESSAGE", INT2NUM(KEY_MESSAGE)); 02039 #endif 02040 #ifdef KEY_MOVE 02041 rb_curses_define_const(KEY_MOVE); 02042 rb_define_const(mKey, "MOVE", INT2NUM(KEY_MOVE)); 02043 #endif 02044 #ifdef KEY_NEXT 02045 rb_curses_define_const(KEY_NEXT); 02046 rb_define_const(mKey, "NEXT", INT2NUM(KEY_NEXT)); 02047 #endif 02048 #ifdef KEY_OPEN 02049 rb_curses_define_const(KEY_OPEN); 02050 rb_define_const(mKey, "OPEN", INT2NUM(KEY_OPEN)); 02051 #endif 02052 #ifdef KEY_OPTIONS 02053 rb_curses_define_const(KEY_OPTIONS); 02054 rb_define_const(mKey, "OPTIONS", INT2NUM(KEY_OPTIONS)); 02055 #endif 02056 #ifdef KEY_PREVIOUS 02057 rb_curses_define_const(KEY_PREVIOUS); 02058 rb_define_const(mKey, "PREVIOUS", INT2NUM(KEY_PREVIOUS)); 02059 #endif 02060 #ifdef KEY_REDO 02061 rb_curses_define_const(KEY_REDO); 02062 rb_define_const(mKey, "REDO", INT2NUM(KEY_REDO)); 02063 #endif 02064 #ifdef KEY_REFERENCE 02065 rb_curses_define_const(KEY_REFERENCE); 02066 rb_define_const(mKey, "REFERENCE", INT2NUM(KEY_REFERENCE)); 02067 #endif 02068 #ifdef KEY_REFRESH 02069 rb_curses_define_const(KEY_REFRESH); 02070 rb_define_const(mKey, "REFRESH", INT2NUM(KEY_REFRESH)); 02071 #endif 02072 #ifdef KEY_REPLACE 02073 rb_curses_define_const(KEY_REPLACE); 02074 rb_define_const(mKey, "REPLACE", INT2NUM(KEY_REPLACE)); 02075 #endif 02076 #ifdef KEY_RESTART 02077 rb_curses_define_const(KEY_RESTART); 02078 rb_define_const(mKey, "RESTART", INT2NUM(KEY_RESTART)); 02079 #endif 02080 #ifdef KEY_RESUME 02081 rb_curses_define_const(KEY_RESUME); 02082 rb_define_const(mKey, "RESUME", INT2NUM(KEY_RESUME)); 02083 #endif 02084 #ifdef KEY_SAVE 02085 rb_curses_define_const(KEY_SAVE); 02086 rb_define_const(mKey, "SAVE", INT2NUM(KEY_SAVE)); 02087 #endif 02088 #ifdef KEY_SBEG 02089 rb_curses_define_const(KEY_SBEG); 02090 rb_define_const(mKey, "SBEG", INT2NUM(KEY_SBEG)); 02091 #endif 02092 #ifdef KEY_SCANCEL 02093 rb_curses_define_const(KEY_SCANCEL); 02094 rb_define_const(mKey, "SCANCEL", INT2NUM(KEY_SCANCEL)); 02095 #endif 02096 #ifdef KEY_SCOMMAND 02097 rb_curses_define_const(KEY_SCOMMAND); 02098 rb_define_const(mKey, "SCOMMAND", INT2NUM(KEY_SCOMMAND)); 02099 #endif 02100 #ifdef KEY_SCOPY 02101 rb_curses_define_const(KEY_SCOPY); 02102 rb_define_const(mKey, "SCOPY", INT2NUM(KEY_SCOPY)); 02103 #endif 02104 #ifdef KEY_SCREATE 02105 rb_curses_define_const(KEY_SCREATE); 02106 rb_define_const(mKey, "SCREATE", INT2NUM(KEY_SCREATE)); 02107 #endif 02108 #ifdef KEY_SDC 02109 rb_curses_define_const(KEY_SDC); 02110 rb_define_const(mKey, "SDC", INT2NUM(KEY_SDC)); 02111 #endif 02112 #ifdef KEY_SDL 02113 rb_curses_define_const(KEY_SDL); 02114 rb_define_const(mKey, "SDL", INT2NUM(KEY_SDL)); 02115 #endif 02116 #ifdef KEY_SELECT 02117 rb_curses_define_const(KEY_SELECT); 02118 rb_define_const(mKey, "SELECT", INT2NUM(KEY_SELECT)); 02119 #endif 02120 #ifdef KEY_SEND 02121 rb_curses_define_const(KEY_SEND); 02122 rb_define_const(mKey, "SEND", INT2NUM(KEY_SEND)); 02123 #endif 02124 #ifdef KEY_SEOL 02125 rb_curses_define_const(KEY_SEOL); 02126 rb_define_const(mKey, "SEOL", INT2NUM(KEY_SEOL)); 02127 #endif 02128 #ifdef KEY_SEXIT 02129 rb_curses_define_const(KEY_SEXIT); 02130 rb_define_const(mKey, "SEXIT", INT2NUM(KEY_SEXIT)); 02131 #endif 02132 #ifdef KEY_SFIND 02133 rb_curses_define_const(KEY_SFIND); 02134 rb_define_const(mKey, "SFIND", INT2NUM(KEY_SFIND)); 02135 #endif 02136 #ifdef KEY_SHELP 02137 rb_curses_define_const(KEY_SHELP); 02138 rb_define_const(mKey, "SHELP", INT2NUM(KEY_SHELP)); 02139 #endif 02140 #ifdef KEY_SHOME 02141 rb_curses_define_const(KEY_SHOME); 02142 rb_define_const(mKey, "SHOME", INT2NUM(KEY_SHOME)); 02143 #endif 02144 #ifdef KEY_SIC 02145 rb_curses_define_const(KEY_SIC); 02146 rb_define_const(mKey, "SIC", INT2NUM(KEY_SIC)); 02147 #endif 02148 #ifdef KEY_SLEFT 02149 rb_curses_define_const(KEY_SLEFT); 02150 rb_define_const(mKey, "SLEFT", INT2NUM(KEY_SLEFT)); 02151 #endif 02152 #ifdef KEY_SMESSAGE 02153 rb_curses_define_const(KEY_SMESSAGE); 02154 rb_define_const(mKey, "SMESSAGE", INT2NUM(KEY_SMESSAGE)); 02155 #endif 02156 #ifdef KEY_SMOVE 02157 rb_curses_define_const(KEY_SMOVE); 02158 rb_define_const(mKey, "SMOVE", INT2NUM(KEY_SMOVE)); 02159 #endif 02160 #ifdef KEY_SNEXT 02161 rb_curses_define_const(KEY_SNEXT); 02162 rb_define_const(mKey, "SNEXT", INT2NUM(KEY_SNEXT)); 02163 #endif 02164 #ifdef KEY_SOPTIONS 02165 rb_curses_define_const(KEY_SOPTIONS); 02166 rb_define_const(mKey, "SOPTIONS", INT2NUM(KEY_SOPTIONS)); 02167 #endif 02168 #ifdef KEY_SPREVIOUS 02169 rb_curses_define_const(KEY_SPREVIOUS); 02170 rb_define_const(mKey, "SPREVIOUS", INT2NUM(KEY_SPREVIOUS)); 02171 #endif 02172 #ifdef KEY_SPRINT 02173 rb_curses_define_const(KEY_SPRINT); 02174 rb_define_const(mKey, "SPRINT", INT2NUM(KEY_SPRINT)); 02175 #endif 02176 #ifdef KEY_SREDO 02177 rb_curses_define_const(KEY_SREDO); 02178 rb_define_const(mKey, "SREDO", INT2NUM(KEY_SREDO)); 02179 #endif 02180 #ifdef KEY_SREPLACE 02181 rb_curses_define_const(KEY_SREPLACE); 02182 rb_define_const(mKey, "SREPLACE", INT2NUM(KEY_SREPLACE)); 02183 #endif 02184 #ifdef KEY_SRIGHT 02185 rb_curses_define_const(KEY_SRIGHT); 02186 rb_define_const(mKey, "SRIGHT", INT2NUM(KEY_SRIGHT)); 02187 #endif 02188 #ifdef KEY_SRSUME 02189 rb_curses_define_const(KEY_SRSUME); 02190 rb_define_const(mKey, "SRSUME", INT2NUM(KEY_SRSUME)); 02191 #endif 02192 #ifdef KEY_SSAVE 02193 rb_curses_define_const(KEY_SSAVE); 02194 rb_define_const(mKey, "SSAVE", INT2NUM(KEY_SSAVE)); 02195 #endif 02196 #ifdef KEY_SSUSPEND 02197 rb_curses_define_const(KEY_SSUSPEND); 02198 rb_define_const(mKey, "SSUSPEND", INT2NUM(KEY_SSUSPEND)); 02199 #endif 02200 #ifdef KEY_SUNDO 02201 rb_curses_define_const(KEY_SUNDO); 02202 rb_define_const(mKey, "SUNDO", INT2NUM(KEY_SUNDO)); 02203 #endif 02204 #ifdef KEY_SUSPEND 02205 rb_curses_define_const(KEY_SUSPEND); 02206 rb_define_const(mKey, "SUSPEND", INT2NUM(KEY_SUSPEND)); 02207 #endif 02208 #ifdef KEY_UNDO 02209 rb_curses_define_const(KEY_UNDO); 02210 rb_define_const(mKey, "UNDO", INT2NUM(KEY_UNDO)); 02211 #endif 02212 #ifdef KEY_RESIZE 02213 rb_curses_define_const(KEY_RESIZE); 02214 rb_define_const(mKey, "RESIZE", INT2NUM(KEY_RESIZE)); 02215 #endif 02216 #ifdef KEY_MAX 02217 rb_curses_define_const(KEY_MAX); 02218 rb_define_const(mKey, "MAX", INT2NUM(KEY_MAX)); 02219 #endif 02220 { 02221 int c; 02222 char name[] = "KEY_CTRL_x"; 02223 for (c = 'A'; c <= 'Z'; c++) { 02224 name[sizeof(name) - 2] = c; 02225 rb_define_const(mCurses, name, INT2FIX(c - 'A' + 1)); 02226 } 02227 } 02228 #undef rb_curses_define_const 02229 02230 rb_set_end_proc(curses_finalize, 0); 02231 } 02232
1.7.3