ncurses_wrap.c in ncursesw-0.9.2 vs ncurses_wrap.c in ncursesw-1.2.4.1

- old
+ new

@@ -1,10 +1,10 @@ /* * 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 Tobias Herzke + * (C) 2005 2006 2009 Tobias Herzke * * 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 +16,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.13 2006/06/19 09:46:59 t-peters Exp $ + * $Id: ncurses_wrap.c,v 1.18 2009/07/31 10:49:24 t-peters Exp $ * * This file was adapted from the original ncurses header file which * has the following copyright statements: */ @@ -63,10 +63,13 @@ - rippoffline - v*printw functions (but normal printw functions are supported!) */ #include "ncurses_wrap.h" +#ifdef HAVE_LOCALE_H +#include <locale.h> +#endif VALUE mNcurses; /* module Ncurses */ VALUE cWINDOW; /* class Ncurses::WINDOW */ VALUE cSCREEN; /* class Ncurses::SCREEN */ VALUE eNcurses; /* Ncurses::Exception thrown by this extension */ @@ -118,10 +121,21 @@ rb_define_const(mNcurses, "WA_LOW", INT2NUM(WA_LOW)); rb_define_const(mNcurses, "WA_RIGHT", INT2NUM(WA_RIGHT)); rb_define_const(mNcurses, "WA_TOP", INT2NUM(WA_TOP)); rb_define_const(mNcurses, "WA_VERTICAL", INT2NUM(WA_VERTICAL)); #endif + + /* locale flags */ +#ifdef HAVE_LOCALE_H + rb_define_const(mNcurses, "LC_ALL", INT2NUM(LC_ALL)); + rb_define_const(mNcurses, "LC_COLLATE", INT2NUM(LC_COLLATE)); + rb_define_const(mNcurses, "LC_CTYPE", INT2NUM(LC_CTYPE)); + rb_define_const(mNcurses, "LC_MESSAGES", INT2NUM(LC_MESSAGES)); + rb_define_const(mNcurses, "LC_MONETARY", INT2NUM(LC_MONETARY)); + rb_define_const(mNcurses, "LC_NUMERIC", INT2NUM(LC_NUMERIC)); + rb_define_const(mNcurses, "LC_TIME", INT2NUM(LC_TIME)); +#endif } static VALUE rbncurs_COLORS() {return INT2NUM(COLORS);} static VALUE rbncurs_COLOR_PAIRS() @@ -191,10 +205,16 @@ #ifdef CCHARW_MAX rb_define_const(mNcurses, "CCHARW_MAX", INT2NUM(CCHARW_MAX)); #endif } +/// Portable (1.8,1.9) determination of array length (calling #length) +long rbncurs_array_length(VALUE array) +{ + return NUM2LONG(rb_funcall(array, rb_intern("length"), 0)); +} + VALUE wrap_window(WINDOW* window) { if (window == 0) return Qnil; { VALUE windows_hash = rb_iv_get(mNcurses, "@windows_hash"); @@ -321,10 +341,14 @@ #ifdef HAVE_FORM_H #include "form_wrap.h" /* needs init_form */ #endif +#ifdef HAVE_MENU_H +#include "menu_wrap.h" /* needs init_menu */ +#endif + static void init_functions_0(void) { #ifdef HAVE_DELSCREEN @@ -788,11 +812,11 @@ static int rbncurshelper_nonblocking_wgetch(WINDOW *c_win) { /* 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; -#ifdef NCURSES_VERSION +#if defined(NCURSES_VERSION) && defined(NCURSES_OPAQUE) && !NCURSES_OPAQUE int windelay = c_win->_delay; #else int windelay = 0; #endif double window_delay = (windelay >= 0) ? 0.001 * windelay : (1e200*1e200); @@ -805,11 +829,11 @@ double resize_delay = NUM2INT(get_RESIZEDELAY()) / 1000.0; fd_set in_fds; gettimeofday(&tv, &tz); starttime = tv.tv_sec + tv.tv_usec * 1e-6; finishtime = starttime + delay; -#ifdef NCURSES_VERSION +#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; @@ -824,11 +848,11 @@ /* 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); } -#ifdef NCURSES_VERSION +#if defined(NCURSES_VERSION) && defined(NCURSES_OPAQUE) && !NCURSES_OPAQUE c_win->_delay = windelay; #endif return result; } static VALUE rbncurs_getch(VALUE dummy) { @@ -2678,10 +2702,15 @@ #ifdef ACS_STERLING wrap_ACS(ACS_STERLING); #endif } +#ifdef HAVE_LOCALE_H +static VALUE rbncurs_setlocale(VALUE dummy, VALUE category, VALUE locale) +{ return rb_str_new2(setlocale(NUM2INT(category), STR2CSTR(locale)));} +#endif + static void init_safe_functions(void) { NCFUNC(initscr, 0); NCFUNC(newterm, 3); NCFUNC(slk_init, 1); @@ -2689,10 +2718,13 @@ NCFUNC(filter, 0); #endif #ifdef HAVE_USE_ENV NCFUNC(use_env, 1); #endif +#ifdef HAVE_LOCALE_H + NCFUNC(setlocale, 2); +#endif } void Init_ncursesw_bin(void) { setlocale(LC_ALL, ""); @@ -2729,7 +2761,10 @@ #ifdef HAVE_PANEL_H init_panel(); #endif #ifdef HAVE_FORM_H init_form(); +#endif +#ifdef HAVE_MENU_H + init_menu(); #endif }