ncurses_wrap.c in ncursesw-1.2.4.3 vs ncurses_wrap.c in ncursesw-1.4.0.0

- old
+ new

@@ -1,10 +1,11 @@ /* * ncurses-ruby is a ruby module for accessing the FSF's ncurses library * (C) 2002, 2003, 2004 Tobias Peters <t-peters@berlios.de> * (C) 2004 Simon Kaczor <skaczor@cox.net> - * (C) 2005 2006 2009 Tobias Herzke + * (C) 2005 2006 2009 2011 Tobias Herzke + * (C) 2013 Gaute Hope <eg@gaute.vetsj.com> * * This module is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. @@ -16,11 +17,11 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this module; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: ncurses_wrap.c,v 1.18 2009/07/31 10:49:24 t-peters Exp $ + * $Id: ncurses_wrap.c,v 1.19 2011-05-30 23:05:50 t-peters Exp $ * * This file was adapted from the original ncurses header file which * has the following copyright statements: */ @@ -68,10 +69,14 @@ #include "compat.h" #ifdef HAVE_LOCALE_H #include <locale.h> #endif +#ifdef HAVE_CLOCK_GETTIME +#include <time.h> +#endif + VALUE mNcurses; /* module Ncurses */ VALUE cWINDOW; /* class Ncurses::WINDOW */ VALUE cSCREEN; /* class Ncurses::SCREEN */ VALUE eNcurses; /* Ncurses::Exception thrown by this extension */ @@ -334,19 +339,19 @@ } xfree(str); return INT2NUM(return_value); } -#ifdef HAVE_PANEL_H +#if defined(HAVE_PANEL_H) || defined(HAVE_NCURSESW_PANEL_H) #include "panel_wrap.h" /* needs access to mNcurses, wrap_window, get_window */ #endif -#ifdef HAVE_FORM_H +#if defined(HAVE_FORM_H) || defined(HAVE_NCURSESW_FORM_H) #include "form_wrap.h" /* needs init_form */ #endif -#ifdef HAVE_MENU_H +#if defined(HAVE_MENU_H) || defined(HAVE_NCURSESW_MENU_H) #include "menu_wrap.h" /* needs init_menu */ #endif static void @@ -426,21 +431,21 @@ { rb_iv_set(mNcurses, "@stdscr", Qnil); rb_iv_set(mNcurses, "@curscr", Qnil); rb_iv_set(mNcurses, "@newscr", Qnil); - rb_define_module_function(mNcurses, "stdscr", + rb_define_module_function(mNcurses, "stdscr", (&get_stdscr), 0); - rb_define_module_function(mNcurses, "curscr", + rb_define_module_function(mNcurses, "curscr", (&get_curscr), 0); #ifdef HAVE_NEWSCR - rb_define_module_function(mNcurses, "newscr", + rb_define_module_function(mNcurses, "newscr", (&get_newscr), 0); #endif - rb_define_module_function(mNcurses, "LINES", + rb_define_module_function(mNcurses, "LINES", (&get_LINES), 0); - rb_define_module_function(mNcurses, "COLS", + rb_define_module_function(mNcurses, "COLS", (&get_COLS), 0); #ifdef HAVE_TABSIZE rb_define_module_function(mNcurses, "TABSIZE", (&get_TABSIZE),0); #endif @@ -556,20 +561,24 @@ size_t vector_length = string_length + 1; /* for terminating 0 */ chtype * chstr = ALLOC_N(chtype, vector_length); unsigned long i; for (i = 0; i < string_length; ++i) { - chstr[i] = NUM2ULONG(rb_ary_entry(array, i)); + chstr[i] = (int) NUM2ULONG(rb_ary_entry(array, i)); } chstr[string_length] = 0; return chstr; } } static VALUE rbncurs_addch(VALUE dummy, VALUE arg1) { - return INT2NUM(addch(NUM2ULONG(arg1))); + return INT2NUM(addch((int) NUM2ULONG(arg1))); } +static VALUE rbncurs_add_wch(VALUE dummy, VALUE arg1) { + wchar_t c = NUM2ULONG(arg1); + return INT2NUM(add_wch((cchar_t *)&c)); +} static VALUE rbncurs_addchnstr(VALUE dummy, VALUE arg1, VALUE arg2) { chtype * chstr = RB2CHSTR(arg1); VALUE return_value = INT2NUM(addchnstr(chstr, NUM2INT(arg2))); xfree(chstr); return return_value; @@ -591,61 +600,61 @@ } static VALUE rbncurs_attron(VALUE dummy, VALUE arg1) { return INT2NUM(attron(NUM2ULONG(arg1))); } static VALUE rbncurs_attrset(VALUE dummy, VALUE arg1) { - return INT2NUM(attrset(NUM2ULONG(arg1))); + return INT2NUM(attrset((int) NUM2ULONG(arg1))); } #if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR > 4 #ifdef HAVE_ATTR_OFF static VALUE rbncurs_attr_off(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(attr_off(NUM2ULONG(arg1), ((void)(arg2),NULL))); + return INT2NUM(attr_off((int) NUM2ULONG(arg1), ((void)(arg2),NULL))); } #endif #ifdef HAVE_ATTR_ON static VALUE rbncurs_attr_on(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(attr_on(NUM2ULONG(arg1), ((void)(arg2),NULL))); + return INT2NUM(attr_on((int) NUM2ULONG(arg1), ((void)(arg2),NULL))); } #endif #ifdef HAVE_ATTR_SET static VALUE rbncurs_attr_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { - return INT2NUM(attr_set(NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL))); + return INT2NUM(attr_set((int) NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL))); } #endif #if defined(HAVE_SLK_ATTR_OFF) || defined(slk_attr_off) static VALUE rbncurs_slk_attr_off(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(slk_attr_off(NUM2ULONG(arg1), ((void)(arg2),NULL))); + return INT2NUM(slk_attr_off((int) NUM2ULONG(arg1), ((void)(arg2),NULL))); } #endif #if defined(HAVE_SLK_ATTR_ON) || defined(slk_attr_on) static VALUE rbncurs_slk_attr_on(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(slk_attr_on(NUM2ULONG(arg1), ((void)(arg2),NULL))); + return INT2NUM(slk_attr_on((int) NUM2ULONG(arg1), ((void)(arg2),NULL))); } #endif #ifdef HAVE_SLK_ATTR_SET static VALUE rbncurs_slk_attr_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { - return INT2NUM(slk_attr_set(NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL))); + return INT2NUM(slk_attr_set((int) NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL))); } #endif #ifdef HAVE_WATTR_ON static VALUE rbncurs_wattr_on(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { - return INT2NUM(wattr_on(get_window(arg1), NUM2ULONG(arg2), ((void)(arg3),NULL))); + return INT2NUM(wattr_on(get_window(arg1), (int) NUM2ULONG(arg2), ((void)(arg3),NULL))); } #endif #ifdef HAVE_WATTR_OFF static VALUE rbncurs_wattr_off(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { - return INT2NUM(wattr_off(get_window(arg1), NUM2ULONG(arg2), ((void)(arg3),NULL))); + return INT2NUM(wattr_off(get_window(arg1), (int) NUM2ULONG(arg2), ((void)(arg3),NULL))); } #endif #ifdef HAVE_WATTR_SET static VALUE rbncurs_wattr_set(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { - return INT2NUM(wattr_set(get_window(arg1), NUM2ULONG(arg2), NUM2INT(arg3), ((void)(arg4),NULL))); + return INT2NUM(wattr_set(get_window(arg1), (int) NUM2ULONG(arg2), NUM2INT(arg3), ((void)(arg4),NULL))); } #endif #if defined(HAVE_VID_ATTR) || defined(vid_attr) static VALUE rbncurs_vid_attr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { - return INT2NUM(vid_attr(NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL))); + return INT2NUM(vid_attr((int) NUM2ULONG(arg1), NUM2INT(arg2), ((void)(arg3),NULL))); } #endif #ifdef HAVE_ATTR_GET static VALUE rbncurs_attr_get(VALUE dummy, VALUE rb_attrs, VALUE rb_pair, VALUE dummy2) @@ -691,20 +700,20 @@ } static VALUE rbncurs_beep(VALUE dummy) { return INT2NUM(beep()); } static VALUE rbncurs_bkgd(VALUE dummy, VALUE arg1) { - return INT2NUM(bkgd(NUM2ULONG(arg1))); + return INT2NUM(bkgd((int) NUM2ULONG(arg1))); } static VALUE rbncurs_bkgdset(VALUE dummy, VALUE arg1) { - return ((bkgdset(NUM2ULONG(arg1))),Qnil); + return ((bkgdset((int) NUM2ULONG(arg1))),Qnil); } static VALUE rbncurs_border(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7, VALUE arg8) { - return INT2NUM(border(NUM2ULONG(arg1), NUM2ULONG(arg2), NUM2ULONG(arg3), NUM2ULONG(arg4), NUM2ULONG(arg5), NUM2ULONG(arg6), NUM2ULONG(arg7), NUM2ULONG(arg8))); + 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))); } static VALUE rbncurs_box(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { - return INT2NUM(box(get_window(arg1), NUM2ULONG(arg2), NUM2ULONG(arg3))); + return INT2NUM(box(get_window(arg1), (int) NUM2ULONG(arg2), (int) NUM2ULONG(arg3))); } static VALUE rbncurs_can_change_color(VALUE dummy) { return (can_change_color()) ? Qtrue : Qfalse; } @@ -727,11 +736,11 @@ static VALUE rbncurs_cbreak(VALUE dummy) { return INT2NUM(rbncurshelper_halfdelay_cbreak(0, 1)); } #ifdef HAVE_CHGAT static VALUE rbncurs_chgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { - return INT2NUM(chgat(NUM2INT(arg1), NUM2ULONG(arg2), NUM2INT(arg3), + return INT2NUM(chgat(NUM2INT(arg1), (int) NUM2ULONG(arg2), NUM2INT(arg3), ((void)(arg4),NULL))); } #endif static VALUE rbncurs_clear(VALUE dummy) { return INT2NUM(clear()); @@ -785,11 +794,11 @@ } static VALUE rbncurs_echo(VALUE dummy) { return INT2NUM(echo()); } static VALUE rbncurs_echochar(VALUE dummy, VALUE arg1) { - return INT2NUM(echochar(NUM2ULONG(arg1))); + return INT2NUM(echochar((int) NUM2ULONG(arg1))); } static VALUE rbncurs_endwin(VALUE dummy) { return INT2NUM(endwin()); } static VALUE rbncurs_erasechar(VALUE dummy) { @@ -808,11 +817,15 @@ } static VALUE rbncurs_getbkgd(VALUE dummy, VALUE arg1) { return INT2NUM(getbkgd(get_window(arg1))); } -static int rbncurshelper_nonblocking_wgetch(WINDOW *c_win) { +/* typedef of a pointer to a wgetch function */ +typedef int (*wgetch_func) (WINDOW *); + +/* functor for getting a char nonblocking, pass getchar function */ +static int rbncurshelper_do_wgetch_functor (WINDOW *c_win, wgetch_func _wgetch_func) { /* nonblocking wgetch only implemented for Ncurses */ int halfdelay = NUM2INT(rb_iv_get(mNcurses, "@halfdelay")); int infd = NUM2INT(rb_iv_get(mNcurses, "@infd")); double screen_delay = halfdelay * 0.1; #if defined(NCURSES_VERSION) && defined(NCURSES_OPAQUE) && !NCURSES_OPAQUE @@ -822,45 +835,113 @@ #endif double window_delay = (windelay >= 0) ? 0.001 * windelay : (1e200*1e200); /* FIXME: ^ Infinity ^*/ double delay = (screen_delay > 0) ? screen_delay : window_delay; int result; - struct timeval tv; - struct timezone tz = {0,0}; double starttime, nowtime, finishtime; double resize_delay = NUM2INT(get_RESIZEDELAY()) / 1000.0; fd_set in_fds; +#ifdef HAVE_CLOCK_GETTIME + struct timespec tv; + struct timeval ts; + clock_gettime (CLOCK_MONOTONIC, &tv); + starttime = tv.tv_sec + tv.tv_nsec * 1e-9; +#else + struct timeval tv; + struct timezone tz = {0,0}; gettimeofday(&tv, &tz); starttime = tv.tv_sec + tv.tv_usec * 1e-6; +#endif finishtime = starttime + delay; #if defined(NCURSES_VERSION) && defined(NCURSES_OPAQUE) && !NCURSES_OPAQUE c_win->_delay = 0; #endif - while (doupdate() /* detects resize */, (result = wgetch(c_win)) == ERR) { - gettimeofday(&tv, &tz); - nowtime = tv.tv_sec + tv.tv_usec * 1e-6; - delay = finishtime - nowtime; - if (delay <= 0) break; + while (doupdate() /* detects resize */, (result = _wgetch_func(c_win)) == ERR) { +#ifdef HAVE_RB_THREAD_FD_SELECT + rb_fdset_t fdsets[3]; + rb_fdset_t *rfds = NULL; +#endif +#ifdef HAVE_CLOCK_GETTIME + clock_gettime (CLOCK_MONOTONIC, &tv); + nowtime = tv.tv_sec + tv.tv_nsec * 1e-9; +#else + gettimeofday(&tv, &tz); + nowtime = tv.tv_sec + tv.tv_usec * 1e-6; +#endif + delay = finishtime - nowtime; + if (delay <= 0) break; - /* Check for terminal size change every resize_delay seconds */ - if (resize_delay > delay) resize_delay = delay; - tv.tv_sec = (time_t)resize_delay; - tv.tv_usec = (unsigned)( (resize_delay - tv.tv_sec) * 1e6 ); + /* Check for terminal size change every resize_delay seconds */ + if (resize_delay > delay) resize_delay = delay; + tv.tv_sec = (time_t)resize_delay; +#ifdef HAVE_CLOCK_GETTIME + tv.tv_nsec = (unsigned)( (resize_delay - tv.tv_sec) * 1e9 ); +#else + tv.tv_usec = (unsigned)( (resize_delay - tv.tv_sec) * 1e6 ); +#endif - /* sleep on infd until input is available or tv reaches timeout */ - FD_ZERO(&in_fds); - FD_SET(infd, &in_fds); - rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv); +#if HAVE_CLOCK_GETTIME + ts.tv_sec = tv.tv_sec; + ts.tv_usec = tv.tv_nsec * 1e-3; +#endif + + /* sleep on infd until input is available or tv reaches timeout */ + FD_ZERO(&in_fds); + FD_SET(infd, &in_fds); + +#ifdef HAVE_RB_THREAD_FD_SELECT + rfds = &fdsets[0]; + rb_fd_init(rfds); + rb_fd_copy(rfds, &in_fds, infd +1); + +#if HAVE_CLOCK_GETTIME + rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &ts); +#else + rb_thread_fd_select(infd + 1, rfds, NULL, NULL, &tv); +#endif + +#else +#if HAVE_CLOCK_GETTIME + rb_thread_select(infd + 1, &in_fds, NULL, NULL, &ts); +#else + rb_thread_select(infd + 1, &in_fds, NULL, NULL, &tv); +#endif +#endif } #if defined(NCURSES_VERSION) && defined(NCURSES_OPAQUE) && !NCURSES_OPAQUE c_win->_delay = windelay; #endif return result; } + +/* non-wide char getch */ +static int rbncurshelper_nonblocking_wgetch(WINDOW *c_win) { + return rbncurshelper_do_wgetch_functor (c_win, &wgetch); +} + +/* not thread safe: wide char getch */ +static wint_t wget_wch_back; +static int my_wget_wch (WINDOW *c_win) { + return wget_wch (c_win, &wget_wch_back); +} + +/* return array with first element being return key code status, + * and second element the key code */ +static VALUE rbncurshelper_nonblocking_wget_wch(WINDOW *c_win) { + int retcode = rbncurshelper_do_wgetch_functor (c_win, &my_wget_wch); + VALUE r = rb_assoc_new (INT2NUM(retcode), LONG2NUM(wget_wch_back)); + return r; +} + static VALUE rbncurs_getch(VALUE dummy) { return INT2NUM(rbncurshelper_nonblocking_wgetch(stdscr)); } + +static VALUE rbncurs_get_wch(VALUE dummy) { + return rbncurshelper_nonblocking_wget_wch(stdscr); +} + static VALUE rbncurs_halfdelay(VALUE dummy, VALUE arg1) { return INT2NUM(rbncurshelper_halfdelay_cbreak(NUM2INT(arg1), 1)); } static VALUE rbncurs_has_colors(VALUE dummy) { return (has_colors()) ? Qtrue : Qfalse; @@ -870,11 +951,11 @@ } static VALUE rbncurs_has_il(VALUE dummy) { return (has_il()) ? Qtrue : Qfalse; } static VALUE rbncurs_hline(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(hline(NUM2ULONG(arg1), NUM2INT(arg2))); + return INT2NUM(hline((int) NUM2ULONG(arg1), NUM2INT(arg2))); } static VALUE rbncurs_idcok(VALUE dummy, VALUE arg1, VALUE arg2) { return ((idcok(get_window(arg1), RTEST(arg2))),Qnil); } static VALUE rbncurs_idlok(VALUE dummy, VALUE arg1, VALUE arg2) { @@ -886,11 +967,11 @@ static VALUE rbncurs_inch(VALUE dummy) { return INT2NUM(inch()); } static VALUE rbncurs_initscr(VALUE dummy) { VALUE v = wrap_window(initscr()); - if (!RTEST(v)) + if (!RTEST(v)) return v; Init_ncurses_full(); /* Some constants defined by the initscr call. */ @@ -1001,11 +1082,11 @@ } static VALUE rbncurs_init_pair(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { return INT2NUM(init_pair(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3))); } static VALUE rbncurs_insch(VALUE dummy, VALUE arg1) { - return INT2NUM(insch(NUM2ULONG(arg1))); + return INT2NUM(insch((int) NUM2ULONG(arg1))); } static VALUE rbncurs_insdelln(VALUE dummy, VALUE arg1) { return INT2NUM(insdelln(NUM2INT(arg1))); } static VALUE rbncurs_insertln(VALUE dummy) { @@ -1051,11 +1132,11 @@ } static VALUE rbncurs_move(VALUE dummy, VALUE arg1, VALUE arg2) { return INT2NUM(move(NUM2INT(arg1), NUM2INT(arg2))); } static VALUE rbncurs_mvaddch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { - return INT2NUM(mvaddch(NUM2INT(arg1), NUM2INT(arg2), NUM2ULONG(arg3))); + return INT2NUM(mvaddch(NUM2INT(arg1), NUM2INT(arg2), (int) NUM2ULONG(arg3))); } static VALUE rbncurs_mvaddchnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { chtype * chstr = RB2CHSTR(arg3); VALUE return_value = INT2NUM(mvaddchnstr(NUM2INT(arg1), NUM2INT(arg2), @@ -1076,11 +1157,11 @@ static VALUE rbncurs_mvaddstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { return INT2NUM(mvaddstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3))); } #ifdef HAVE_MVCHGAT static VALUE rbncurs_mvchgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6) { - return INT2NUM(mvchgat(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2ULONG(arg4), NUM2INT(arg5), ((void)(arg6),NULL))); + return INT2NUM(mvchgat(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), (int) NUM2ULONG(arg4), NUM2INT(arg5), ((void)(arg6),NULL))); } #endif static VALUE rbncurs_mvcur(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { return INT2NUM(mvcur(NUM2INT(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4))); } @@ -1095,32 +1176,32 @@ return INT2NUM(ERR); return INT2NUM(rbncurshelper_nonblocking_wgetch(stdscr)); } #ifdef HAVE_MVHLINE static VALUE rbncurs_mvhline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { - return INT2NUM(mvhline(NUM2INT(arg1), NUM2INT(arg2), NUM2ULONG(arg3), NUM2INT(arg4))); + return INT2NUM(mvhline(NUM2INT(arg1), NUM2INT(arg2), (int) NUM2ULONG(arg3), NUM2INT(arg4))); } #endif static VALUE rbncurs_mvinch(VALUE dummy, VALUE arg1, VALUE arg2) { return INT2NUM(mvinch(NUM2INT(arg1), NUM2INT(arg2))); } static VALUE rbncurs_mvinsch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { - return INT2NUM(mvinsch(NUM2INT(arg1), NUM2INT(arg2), NUM2ULONG(arg3))); + return INT2NUM(mvinsch(NUM2INT(arg1), NUM2INT(arg2), (int) NUM2ULONG(arg3))); } static VALUE rbncurs_mvinsnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { return INT2NUM(mvinsnstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3), NUM2INT(arg4))); } static VALUE rbncurs_mvinsstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { return INT2NUM(mvinsstr(NUM2INT(arg1), NUM2INT(arg2), STR2CSTR(arg3))); } #ifdef HAVE_MVVLINE static VALUE rbncurs_mvvline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { - return INT2NUM(mvvline(NUM2INT(arg1), NUM2INT(arg2), NUM2ULONG(arg3), NUM2INT(arg4))); + return INT2NUM(mvvline(NUM2INT(arg1), NUM2INT(arg2), (int) NUM2ULONG(arg3), NUM2INT(arg4))); } #endif static VALUE rbncurs_mvwaddch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { - return INT2NUM(mvwaddch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2ULONG(arg4))); + return INT2NUM(mvwaddch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), (int) NUM2ULONG(arg4))); } static VALUE rbncurs_mvwaddchnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) { chtype * chstr = RB2CHSTR(arg4); VALUE return_value = INT2NUM(mvwaddchnstr(get_window(arg1), NUM2INT(arg2), @@ -1143,11 +1224,11 @@ static VALUE rbncurs_mvwaddstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { return INT2NUM(mvwaddstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4))); } #ifdef HAVE_MVWCHGAT static VALUE rbncurs_mvwchgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7) { - return INT2NUM(mvwchgat(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2ULONG(arg5), NUM2INT(arg6), ((void)(arg7),NULL))); + return INT2NUM(mvwchgat(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), (int) NUM2ULONG(arg5), NUM2INT(arg6), ((void)(arg7),NULL))); } #endif static VALUE rbncurs_mvwdelch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { return INT2NUM(mvwdelch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3))); } @@ -1157,31 +1238,31 @@ return INT2NUM(ERR); return INT2NUM(rbncurshelper_nonblocking_wgetch(c_win)); } #ifdef HAVE_MVWHLINE static VALUE rbncurs_mvwhline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) { - return INT2NUM(mvwhline(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2ULONG(arg4), NUM2INT(arg5))); + return INT2NUM(mvwhline(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), (int) NUM2ULONG(arg4), NUM2INT(arg5))); } #endif static VALUE rbncurs_mvwin(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { return INT2NUM(mvwin(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3))); } static VALUE rbncurs_mvwinch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { return INT2NUM(mvwinch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3))); } static VALUE rbncurs_mvwinsch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { - return INT2NUM(mvwinsch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2ULONG(arg4))); + return INT2NUM(mvwinsch(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), (int) NUM2ULONG(arg4))); } static VALUE rbncurs_mvwinsnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) { return INT2NUM(mvwinsnstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4), NUM2INT(arg5))); } static VALUE rbncurs_mvwinsstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { return INT2NUM(mvwinsstr(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), STR2CSTR(arg4))); } #ifdef HAVE_MVWVLINE static VALUE rbncurs_mvwvline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) { - return INT2NUM(mvwvline(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2ULONG(arg4), NUM2INT(arg5))); + return INT2NUM(mvwvline(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), (int) NUM2ULONG(arg4), NUM2INT(arg5))); } #endif static VALUE rbncurs_napms(VALUE dummy, VALUE arg1) { return INT2NUM(napms(NUM2INT(arg1))); } @@ -1226,11 +1307,11 @@ static VALUE rbncurs_PAIR_NUMBER(VALUE dummy, VALUE arg1) { return INT2NUM(PAIR_NUMBER(NUM2INT(arg1))); } #ifndef __PDCURSES__ /* pdcurses "pechochar" macro won't compile*/ static VALUE rbncurs_pechochar(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(pechochar(get_window(arg1), NUM2ULONG(arg2))); + return INT2NUM(pechochar(get_window(arg1), (int) NUM2ULONG(arg2))); } #endif static VALUE rbncurs_pnoutrefresh(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7) { return INT2NUM(pnoutrefresh(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4), NUM2INT(arg5), NUM2INT(arg6), NUM2INT(arg7))); } @@ -1313,17 +1394,17 @@ rbncurshelper_halfdelay_cbreak_restore(); return rb_old_screen; } static VALUE rbncurs_slk_attroff(VALUE dummy, VALUE arg1) { - return INT2NUM(slk_attroff(NUM2ULONG(arg1))); + return INT2NUM(slk_attroff((int) NUM2ULONG(arg1))); } static VALUE rbncurs_slk_attron(VALUE dummy, VALUE arg1) { - return INT2NUM(slk_attron(NUM2ULONG(arg1))); + return INT2NUM(slk_attron((int) NUM2ULONG(arg1))); } static VALUE rbncurs_slk_attrset(VALUE dummy, VALUE arg1) { - return INT2NUM(slk_attrset(NUM2ULONG(arg1))); + return INT2NUM(slk_attrset((int) NUM2ULONG(arg1))); } #ifdef HAVE_SLK_ATTR static VALUE rbncurs_slk_attr(VALUE dummy) { return INT2NUM(slk_attr()); } @@ -1414,19 +1495,23 @@ return ((use_env(RTEST(arg1))),Qnil); } #endif #ifdef HAVE_VIDATTR static VALUE rbncurs_vidattr(VALUE dummy, VALUE arg1) { - return INT2NUM(vidattr(NUM2ULONG(arg1))); + return INT2NUM(vidattr((int) NUM2ULONG(arg1))); } #endif static VALUE rbncurs_vline(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(vline(NUM2ULONG(arg1), NUM2INT(arg2))); + return INT2NUM(vline((int) NUM2ULONG(arg1), NUM2INT(arg2))); } static VALUE rbncurs_waddch(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(waddch(get_window(arg1), NUM2ULONG(arg2))); + return INT2NUM(waddch(get_window(arg1), (int) NUM2ULONG(arg2))); } +static VALUE rbncurs_wadd_wch(VALUE dummy, VALUE arg1, VALUE arg2) { + cchar_t t = { 0, { NUM2ULONG(arg2), 0 } }; + return INT2NUM(wadd_wch(get_window(arg1), &t)); +} static VALUE rbncurs_waddchnstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { chtype * chstr = RB2CHSTR(arg2); VALUE return_value = INT2NUM(waddchnstr(get_window(arg1), chstr, NUM2INT(arg3))); xfree(chstr); @@ -1452,21 +1537,21 @@ } static VALUE rbncurs_wattrset(VALUE dummy, VALUE arg1, VALUE arg2) { return INT2NUM(wattrset(get_window(arg1), NUM2INT(arg2))); } static VALUE rbncurs_wbkgd(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(wbkgd(get_window(arg1), NUM2ULONG(arg2))); + return INT2NUM(wbkgd(get_window(arg1), (int) NUM2ULONG(arg2))); } static VALUE rbncurs_wbkgdset(VALUE dummy, VALUE arg1, VALUE arg2) { - return ((wbkgdset(get_window(arg1), NUM2ULONG(arg2))),Qnil); + return ((wbkgdset(get_window(arg1), (int) NUM2ULONG(arg2))),Qnil); } static VALUE rbncurs_wborder(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5, VALUE arg6, VALUE arg7, VALUE arg8, VALUE arg9) { - return INT2NUM(wborder(get_window(arg1), NUM2ULONG(arg2), NUM2ULONG(arg3), NUM2ULONG(arg4), NUM2ULONG(arg5), NUM2ULONG(arg6), NUM2ULONG(arg7), NUM2ULONG(arg8), NUM2ULONG(arg9))); + 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))); } #ifdef HAVE_WCHGAT static VALUE rbncurs_wchgat(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4, VALUE arg5) { - return INT2NUM(wchgat(get_window(arg1), NUM2INT(arg2), NUM2ULONG(arg3), NUM2INT(arg4), ((void)(arg5),NULL))); + return INT2NUM(wchgat(get_window(arg1), NUM2INT(arg2), (int) NUM2ULONG(arg3), NUM2INT(arg4), ((void)(arg5),NULL))); } #endif static VALUE rbncurs_wclear(VALUE dummy, VALUE arg1) { return INT2NUM(wclear(get_window(arg1))); } @@ -1489,26 +1574,31 @@ } static VALUE rbncurs_wdeleteln(VALUE dummy, VALUE arg1) { return INT2NUM(wdeleteln(get_window(arg1))); } static VALUE rbncurs_wechochar(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(wechochar(get_window(arg1), NUM2ULONG(arg2))); + return INT2NUM(wechochar(get_window(arg1), (int) NUM2ULONG(arg2))); } static VALUE rbncurs_werase(VALUE dummy, VALUE arg1) { return INT2NUM(werase(get_window(arg1))); } static VALUE rbncurs_wgetch(VALUE dummy, VALUE arg1) { return INT2NUM(rbncurshelper_nonblocking_wgetch(get_window(arg1))); } + +static VALUE rbncurs_wget_wch(VALUE dummy, VALUE arg1) { + return rbncurshelper_nonblocking_wget_wch(get_window(arg1)); +} + static VALUE rbncurs_whline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { - return INT2NUM(whline(get_window(arg1), NUM2ULONG(arg2), NUM2INT(arg3))); + return INT2NUM(whline(get_window(arg1), (int) NUM2ULONG(arg2), NUM2INT(arg3))); } static VALUE rbncurs_winch(VALUE dummy, VALUE arg1) { return INT2NUM(winch(get_window(arg1))); } static VALUE rbncurs_winsch(VALUE dummy, VALUE arg1, VALUE arg2) { - return INT2NUM(winsch(get_window(arg1), NUM2ULONG(arg2))); + return INT2NUM(winsch(get_window(arg1), (int) NUM2ULONG(arg2))); } static VALUE rbncurs_winsdelln(VALUE dummy, VALUE arg1, VALUE arg2) { return INT2NUM(winsdelln(get_window(arg1), NUM2INT(arg2))); } static VALUE rbncurs_winsertln(VALUE dummy, VALUE arg1) { @@ -1555,11 +1645,11 @@ } static VALUE rbncurs_wtouchln(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, VALUE arg4) { return INT2NUM(wtouchln(get_window(arg1), NUM2INT(arg2), NUM2INT(arg3), NUM2INT(arg4))); } static VALUE rbncurs_wvline(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) { - return INT2NUM(wvline(get_window(arg1), NUM2ULONG(arg2), NUM2INT(arg3))); + return INT2NUM(wvline(get_window(arg1), (int)NUM2ULONG(arg2), NUM2INT(arg3))); } static VALUE rbncurs_color_content(VALUE dummy, VALUE color, VALUE r, VALUE g, VALUE b) { if (rb_obj_is_instance_of(r, rb_cArray) != Qtrue || rb_obj_is_instance_of(g, rb_cArray) != Qtrue || rb_obj_is_instance_of(b, rb_cArray) != Qtrue) { @@ -1615,11 +1705,11 @@ close(fd); return INT2NUM(return_value); } #endif static VALUE rbncurs_unctrl(VALUE dummy, VALUE ch) -{ return rb_str_new2(unctrl(NUM2ULONG(ch))); } +{ return rb_str_new2(unctrl((int)NUM2ULONG(ch))); } static VALUE rbncurs_newterm(VALUE dummy, VALUE rb_type, VALUE rb_outfd, VALUE rb_infd) { char * type = (rb_type == Qnil) ? (char*)0 : STR2CSTR(rb_type); int outfd = NUM2INT(rb_funcall(rb_outfd, rb_intern("to_i"), 0)); int infd = NUM2INT(rb_funcall(rb_infd, rb_intern("to_i"), 0)); @@ -1639,10 +1729,11 @@ } static void init_functions_2(void) { NCFUNC(addch, 1); + NCFUNC(add_wch, 1); NCFUNC(addchnstr, 2); NCFUNC(addchstr, 1); NCFUNC(addnstr, 2); NCFUNC(addstr, 1); NCFUNC(attroff, 1); @@ -1721,10 +1812,12 @@ NCFUNC(erasechar, 0); NCFUNC(flash, 0); NCFUNC(flushinp, 0); NCFUNC(getbkgd, 1); NCFUNC(getch, 0); + NCFUNC(get_wch, 0); + NCFUNC(wget_wch, 1); NCFUNC(halfdelay, 1); rb_define_module_function(mNcurses, "has_colors?", (&rbncurs_has_colors), 0); rb_define_module_function(mNcurses, "has_ic?", @@ -1900,10 +1993,11 @@ #ifdef HAVE_VIDATTR NCFUNC(vidattr, 1); #endif NCFUNC(vline, 2); NCFUNC(waddch, 2); + NCFUNC(wadd_wch, 2); NCFUNC(waddchnstr, 3); NCFUNC(waddchstr, 2); NCFUNC(waddnstr, 3); NCFUNC(waddstr, 2); NCFUNC(wattron, 2); @@ -2347,11 +2441,12 @@ rb_ary_push(rb_x, INT2NUM(x)); return Qnil; } static VALUE rbncurs_getsyx(VALUE dummy, VALUE rb_y, VALUE rb_x) { - int y,x; + int y = 0; + int x = 0; if ((rb_obj_is_instance_of(rb_y, rb_cArray) != Qtrue) || (rb_obj_is_instance_of(rb_x, rb_cArray) != Qtrue)) { rb_raise(rb_eArgError, "y and x arguments must be empty Arrays"); return Qnil; @@ -2601,11 +2696,11 @@ VALUE current_screen = \ rbncurs_set_term(mNcurses, rb_screen); \ VALUE rb_ACS_CONST = INT2NUM(ACS); \ rbncurs_set_term(mNcurses, current_screen); \ return rb_ACS_CONST; \ -} +} #define wrap_ACS(ACS) \ rb_define_method(cSCREEN, #ACS, \ (&rb_ ## ACS), \ 0) rb_ACS(ACS_ULCORNER) @@ -2725,12 +2820,10 @@ NCFUNC(setlocale, 2); #endif } void Init_ncursesw_bin(void) { - setlocale(LC_ALL, ""); - mNcurses = rb_define_module("Ncurses"); eNcurses = rb_define_class_under(mNcurses, "Exception", rb_eRuntimeError); rb_iv_set(mNcurses, "@windows_hash", rb_hash_new()); rb_iv_set(mNcurses, "@screens_hash", rb_hash_new()); @@ -2757,15 +2850,15 @@ init_functions_1(); init_functions_2(); init_functions_3(); init_SCREEN_methods(); -#ifdef HAVE_PANEL_H +#if defined(HAVE_PANEL_H) || defined(HAVE_NCURSESW_PANEL_H) init_panel(); #endif -#ifdef HAVE_FORM_H +#if defined(HAVE_FORM_H) || defined(HAVE_NCURSESW_FORM_H) init_form(); #endif -#ifdef HAVE_MENU_H +#if defined(HAVE_MENU_H) || defined(HAVE_NCURSESW_MENU_H) init_menu(); #endif }