[DRE-commits] [ruby-ncurses] 02/08: Imported Upstream version 1.4.3
Per Andersson
avtobiff-guest at moszumanska.debian.org
Wed Jan 22 02:12:18 UTC 2014
This is an automated email from the git hooks/post-receive script.
avtobiff-guest pushed a commit to branch newer-stuff
in repository ruby-ncurses.
commit f4078d22c20dad301bf11efdfeb50d19f6e7d1e8
Author: Per Andersson <avtobiff at gmail.com>
Date: Tue Jan 21 23:14:40 2014 +0100
Imported Upstream version 1.4.3
---
THANKS | 3 +-
VERSION | 1 -
compat.h | 8 ++
examples/form_get_wch.rb | 121 +++++++++++++++++++++
extconf.rb | 70 ++++++++++--
form_wrap.c | 150 +++++++++++++++-----------
form_wrap.h | 7 +-
lib/ncurses_sugar.rb | 31 +++---
lib/ncursesw.rb | 1 +
make_dist.rb | 38 -------
menu_wrap.c | 7 +-
ncurses_wrap.c | 272 +++++++++++++++++++++++++++++++++--------------
ncurses_wrap.h | 3 +
ncursesw.gemspec | 50 +++++++++
panel_wrap.c | 1 +
panel_wrap.h | 0
16 files changed, 547 insertions(+), 216 deletions(-)
diff --git a/THANKS b/THANKS
index e2b7ed9..43c611d 100644
--- a/THANKS
+++ b/THANKS
@@ -1,4 +1,4 @@
-$Id: THANKS,v 1.10 2011-05-30 23:36:12 t-peters Exp $
+$Id: THANKS,v 1.9 2009-05-03 10:37:54 t-peters Exp $
A list of people that helped me with ncurses-ruby
@@ -13,4 +13,3 @@ Simon Strandgaard
Paul Duncan
Tim Sutherland
Earle Clubb
-graaf (Berlios user)
\ No newline at end of file
diff --git a/VERSION b/VERSION
deleted file mode 100644
index 3a3cd8c..0000000
--- a/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-1.3.1
diff --git a/compat.h b/compat.h
new file mode 100644
index 0000000..27aa53f
--- /dev/null
+++ b/compat.h
@@ -0,0 +1,8 @@
+#ifndef _COMPAT_H
+#define _COMPAT_H
+
+#ifndef STR2CSTR
+#define STR2CSTR(x) ({ VALUE y = x; StringValuePtr (y); })
+#endif
+
+#endif
diff --git a/examples/form_get_wch.rb b/examples/form_get_wch.rb
new file mode 100644
index 0000000..b65caa3
--- /dev/null
+++ b/examples/form_get_wch.rb
@@ -0,0 +1,121 @@
+#!/usr/bin/ruby
+# Copyright (c) 2004 by Simon Kaczor <skaczor at cox.net>
+# Example from the NCurses Programming HOWTO
+# This example uses module functions that are documented in the ncurses man page.
+# For a more rubyish approach that uses Ruby objects see form2.rb
+#
+# The original example contained the following copyright:
+# Copyright (c) 2001 by Pradeep Padala. This document may be distributed
+# under the terms set forth in the LDP license at linuxdoc.org/COPYRIGHT.html.
+
+require 'ncursesw.rb'
+
+begin
+ scr = Ncurses.initscr()
+ Ncurses.cbreak()
+ Ncurses.noecho()
+ Ncurses.keypad(scr, true)
+
+ #create some fields
+ fields = Array.new
+ fields.push(Ncurses::Form.new_field(1,10,4,18,0,0))
+ fields.push(Ncurses::Form.new_field(1,10,6,18,0,0))
+
+ # set field options
+ Ncurses::Form.set_field_back(fields[0], Ncurses::A_UNDERLINE)
+ Ncurses::Form.field_opts_off(fields[0], Ncurses::Form::O_AUTOSKIP)
+
+ Ncurses::Form.set_field_back(fields[1], Ncurses::A_UNDERLINE)
+ Ncurses::Form.field_opts_off(fields[1], Ncurses::Form::O_AUTOSKIP)
+
+
+ # create a form
+ form = Ncurses::Form.new_form(fields)
+
+ # post the form and refresh the screen
+ Ncurses::Form.post_form(form)
+ scr.refresh()
+
+ Ncurses.mvprintw(4, 10, "Value 1:")
+ Ncurses.mvprintw(6, 10, "Value 2:")
+ scr.refresh()
+
+ buf = ""
+
+ # Loop through to get user requests
+ while(true) do
+ ret = Ncurses.get_wch()
+
+ ch = ret[1]
+
+ Ncurses.mvprintw(8, 10, "Got: #{ch.inspect} (#{[ch].pack("U")})")
+
+ case (ret[0])
+ when Ncurses::OK
+ # If this is a normal character, it gets Printed
+ #prbuf = fields[0].field_buffer 0
+ ##buf = buf.force_encoding('utf-8') + [ch].pack('U')
+ #buf = prbuf + [ch].pack('U')
+
+
+ ##buf = sbuf.force_encoding('utf-8') + [ch].pack('U')
+ #fields[0].set_field_buffer(0, buf)
+ #sbuf = fields[0].field_buffer 0
+ ##fields[0].working.add_wch 'a'
+ #Ncurses.mvprintw(12, 10, "buf: #{sbuf}")
+ #Ncurses.mvprintw(13, 10, "pbuf: #{prbuf}")
+ #Ncurses.mvprintw(14, 10, "mbuf: #{buf}")
+
+ #Ncurses.wadd_wch(form.win, ch)
+
+ #buf = fields[0].field_buffer(0)
+ #buf = buf.force_encoding('utf-8') + [ch].pack("U")
+ #fields[0].set_field_buffer(0, buf)
+ #fields[0].set_field_buffer(0, [ch].pack("U"))
+
+ Ncurses::Form.form_driver_w(form, ret[0], ret[1])
+ #puts "{fields[0].methods}"
+
+ #puts "#{form.methods}"
+ #puts "#{fields[0].methods}"
+ #Ncurses.mvprintw(9, 10, "Type: OK ")
+ when Ncurses::KEY_CODE_YES
+ Ncurses.mvprintw(9, 10, "Type: KEY_CODE_YES")
+ case(ch)
+ when Ncurses::KEY_DOWN
+ # Go to next field
+ Ncurses::Form.form_driver(form, Ncurses::Form::REQ_NEXT_FIELD)
+ # Go to the end of the present buffer
+ # Leaves nicely at the last character
+ Ncurses::Form.form_driver(form, Ncurses::Form::REQ_END_LINE)
+
+ when Ncurses::KEY_UP
+ #Go to previous field
+ Ncurses::Form.form_driver(form, Ncurses::Form::REQ_PREV_FIELD)
+ Ncurses::Form.form_driver(form, Ncurses::Form::REQ_END_LINE);
+ end
+ else
+ Ncurses.mvprintw(9, 10, "Type: Unknown: #{ret[0].inspect} ")
+ end
+ end
+
+ # unpost and free form
+ Ncurses::Form.unpost_form(form);
+ Ncurses::Form.free_form(form)
+ Ncurses::Form.free_field(fields[0]);
+ Ncurses::Form.free_field(fields[1]);
+
+
+ #using class methods this time
+# form = Ncurses::Form::FORM.new(fields)
+# puts "Created form: #{form.inspect}\n"
+# form.free()
+
+ensure
+ # put the screen back in its normal state
+ Ncurses.echo()
+ Ncurses.nocbreak()
+ Ncurses.nl()
+ Ncurses.endwin()
+end
+
diff --git a/extconf.rb b/extconf.rb
index 0b4203f..19ff299 100644
--- a/extconf.rb
+++ b/extconf.rb
@@ -3,6 +3,7 @@
# ncurses-ruby is a ruby module for accessing the FSF's ncurses library
# (C) 2002, 2004 Tobias Peters <t-peters at users.berlios.de>
# (C) 2005, 2009, 2011 Tobias Herzke
+# (C) 2013 Gaute Hope <eg at 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
@@ -22,22 +23,29 @@
require "mkmf"
-$CFLAGS += " -g"
-$CXXFLAGS = $CFLAGS
+$CFLAGS += " -g -Wformat -Werror=format-security -Waddress"
have_header("unistd.h")
have_header("locale.h")
-if have_header("ncursesw/curses.h")
+if have_header ("ncursesw/curses.h") # ubuntu 13
curses_header = "ncursesw/curses.h"
+elsif have_header("ncurses.h")
+ curses_header = "ncurses.h"
+elsif have_header("ncurses/curses.h")
+ curses_header = "ncurses/curses.h"
+elsif have_header("curses.h")
+ curses_header = "curses.h"
else
- raise "ncursesw header file not found"
+ raise "ncurses header file not found"
end
if have_library("ncursesw", "wmove")
curses_lib = "ncursesw"
+elsif have_library("pdcurses", "wmove")
+ curses_lib = "pdcurses"
else
- raise "ncursesw library not found"
+ raise "ncurses library not found"
end
have_func("newscr")
@@ -100,6 +108,11 @@ have_func("wchgat")
have_func("wcolor_set")
have_func("getattrs")
+puts "checking for ncursesw (wide char) functions..."
+if not have_func("wget_wch")
+ raise "no wget_wch found."
+end
+
puts "checking which debugging functions to wrap..."
have_func("_tracef")
have_func("_tracedump")
@@ -116,16 +129,53 @@ have_func("assume_default_colors")
have_func("attr_get")
puts "checking for the panel library..."
-if have_header("ncursesw/panel.h")
+if have_header("panel.h")
have_library("panelw", "panel_hidden")
+else
+ raise "panel library not found"
end
+
puts "checking for the form library..."
-if have_header("ncursesw/form.h")
- have_library("formw", "new_form")
+if have_header("form.h")
+ if not have_library("formw", "new_form")
+ raise "formw library not found"
+ end
+else
+ raise "form library not found."
end
+
+if have_library("formw", "form_driver_w")
+ $CFLAGS += " -DHAVE_FORM_DRIVER_W"
+end
+
+have_func("add_wch")
+have_func("get_wch")
+
puts "checking for the menu library..."
-if have_header("ncursesw/menu.h")
- have_library("menuw", "new_menu")
+if have_header("menu.h")
+ have_library("menu", "new_menu")
+else
+ raise "menu library not found."
end
+puts "checking for various ruby and standard functions.."
+if have_func("rb_thread_fd_select")
+ $CFLAGS += " -DHAVE_RB_THREAD_FD_SELECT"
+end
+
+# Avoid dereferencing WINDOW pointers on FreeBSD
+if RUBY_PLATFORM =~ /freebsd/
+ $CFLAGS += " -DNCURSES_OPAQUE=1"
+else
+ # add NCURSES_OPAQUE for mac
+ $CFLAGS += " -DNCURSES_OPAQUE=0"
+end
+
+if have_func("clock_gettime")
+ $CFLAGS += " -DHAVE_CLOCK_GETTIME"
+end
+
+$CXXFLAGS = $CFLAGS
+
create_makefile('ncursesw_bin')
+
diff --git a/form_wrap.c b/form_wrap.c
index 346d443..7f1d0db 100644
--- a/form_wrap.c
+++ b/form_wrap.c
@@ -3,10 +3,11 @@
* Contributed by Simon Kaczor <skaczor at cox.net>
* Prognosoft Inc. <http://www.prognosoft.biz>
* Copyright 2004
- *
+ *
* Changes:
* (C) 2004 Tobias Peters
* (C) 2005 2009 Tobias Herzke
+ * (C) 2013 Gaute Hope <eg at 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
@@ -29,15 +30,18 @@
#if defined(HAVE_FORM_H) || defined(HAVE_NCURSESW_FORM_H)
+# include <wchar.h>
+
#include "form_wrap.h"
#include "ncurses_wrap.h"
+#include "compat.h"
VALUE mForm;
VALUE cFIELD;
VALUE cFIELDTYPE;
VALUE cFORM;
-void init_err_codes()
+void init_err_codes()
{
/* The routine succeeded. */
FORM_DEF_CONST(E_OK);
@@ -361,14 +365,14 @@ static VALUE get_proc_hash(int hook) {
}
/*
- * Returns an existing Ruby Proc for a given owning "object" and hook type.
+ * Returns an existing Ruby Proc for a given owning "object" and hook type.
* Qnil will be returned if no Proc was associated with the owner
*/
static VALUE get_proc(void* owner, int hook) {
if (owner == 0) return Qnil;
{
VALUE owner_adress = INT2NUM((long)(owner));
- VALUE proc_hash = get_proc_hash(hook);
+ VALUE proc_hash = get_proc_hash(hook);
VALUE proc = rb_hash_aref(proc_hash, owner_adress);
return proc;
}
@@ -399,12 +403,12 @@ static VALUE rbncurs_m_new_form(VALUE dummy, VALUE rb_field_array)
long n = rbncurs_array_length(rb_field_array);
/* Will ncurses free this array? If not, must do it after calling free_form(). */
FIELD** fields = ALLOC_N(FIELD*, (n+1));
- long i;
+ long i;
for (i=0; i<n; i++){
- fields[i] = get_field(rb_ary_entry(rb_field_array, i));
+ fields[i] = get_field(rb_ary_entry(rb_field_array, i));
}
fields[n] = NULL;
- return wrap_form(new_form(fields));
+ return wrap_form(new_form(fields));
}
static VALUE rbncurs_c_free_form(VALUE rb_form) {
@@ -445,12 +449,22 @@ static VALUE rbncurs_c_form_driver(VALUE rb_form, VALUE c) {
static VALUE rbncurs_m_form_driver(VALUE dummy, VALUE rb_form, VALUE c)
{ return rbncurs_c_form_driver(rb_form, c); }
+# ifdef HAVE_FORM_DRIVER_W
+/* Form driver W */
+static VALUE rbncurs_c_form_driver_w(VALUE rb_form, VALUE type, VALUE c) {
+ FORM* form = get_form(rb_form);
+ return INT2NUM(form_driver_w(form, NUM2INT(type), NUM2INT(c)));
+}
+static VALUE rbncurs_m_form_driver_w(VALUE dummy, VALUE rb_form, VALUE type, VALUE c)
+{ return rbncurs_c_form_driver_w(rb_form, type, c); }
+# endif
+
/*
* form_page(3x)
*/
static VALUE rbncurs_c_set_current_field(VALUE rb_form, VALUE rb_field) {
FORM* form = get_form(rb_form);
- FIELD* field = get_field(rb_field);
+ FIELD* field = get_field(rb_field);
return INT2NUM(set_current_field(form, field));
}
static VALUE rbncurs_m_set_current_field(VALUE dummy, VALUE rb_form, VALUE rb_field)
@@ -539,12 +553,12 @@ static VALUE rbncurs_c_free_field(VALUE rb_field) {
}
static VALUE rbncurs_m_free_field(VALUE dummy, VALUE rb_field)
{ return rbncurs_c_free_field(rb_field); }
-
+
/*
* form_field_info(3x)
*/
-static VALUE rbncurs_c_field_info(VALUE rb_field, VALUE rows, VALUE cols,
+static VALUE rbncurs_c_field_info(VALUE rb_field, VALUE rows, VALUE cols,
VALUE frow, VALUE fcol, VALUE nrow, VALUE nbuf) {
if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue
|| rb_obj_is_instance_of(cols, rb_cArray) != Qtrue
@@ -559,7 +573,7 @@ static VALUE rbncurs_c_field_info(VALUE rb_field, VALUE rows, VALUE cols,
else {
FIELD* field = get_field(rb_field);
int vals[6] = {0,0,0,0,0,0};
-
+
int result = field_info(field, &vals[0],&vals[1],&vals[2],&vals[3],&vals[4],&vals[5]);
rb_ary_push(rows, INT2NUM(vals[0]));
rb_ary_push(cols, INT2NUM(vals[1]));
@@ -570,15 +584,15 @@ static VALUE rbncurs_c_field_info(VALUE rb_field, VALUE rows, VALUE cols,
return INT2NUM(result);
}
}
-static VALUE rbncurs_m_field_info(VALUE dummy, VALUE rb_field, VALUE rows, VALUE cols,
+static VALUE rbncurs_m_field_info(VALUE dummy, VALUE rb_field, VALUE rows, VALUE cols,
VALUE frow, VALUE fcol, VALUE nrow, VALUE nbuf)
{ return rbncurs_c_field_info(rb_field, rows, cols, frow, fcol, nrow, nbuf); }
-static VALUE rbncurs_c_dynamic_field_info(VALUE rb_field, VALUE rows, VALUE cols,
+static VALUE rbncurs_c_dynamic_field_info(VALUE rb_field, VALUE rows, VALUE cols,
VALUE max) {
if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue
|| rb_obj_is_instance_of(cols, rb_cArray) != Qtrue
- || rb_obj_is_instance_of(max, rb_cArray) != Qtrue) {
+ || rb_obj_is_instance_of(max, rb_cArray) != Qtrue) {
rb_raise(rb_eArgError,
"rows, cols and max arguments must be empty Arrays");
return Qnil;
@@ -586,7 +600,7 @@ static VALUE rbncurs_c_dynamic_field_info(VALUE rb_field, VALUE rows, VALUE cols
else {
FIELD* field = get_field(rb_field);
int vals[3] = {0,0,0};
-
+
int result = dynamic_field_info(field, &vals[0],&vals[1],&vals[2]);
rb_ary_push(rows, INT2NUM(vals[0]));
rb_ary_push(cols, INT2NUM(vals[1]));
@@ -594,7 +608,7 @@ static VALUE rbncurs_c_dynamic_field_info(VALUE rb_field, VALUE rows, VALUE cols
return INT2NUM(result);
}
}
-static VALUE rbncurs_m_dynamic_field_info(VALUE dummy, VALUE rb_field, VALUE rows, VALUE cols,
+static VALUE rbncurs_m_dynamic_field_info(VALUE dummy, VALUE rb_field, VALUE rows, VALUE cols,
VALUE max)
{ return rbncurs_c_dynamic_field_info(rb_field, rows, cols, max); }
/*
@@ -607,12 +621,12 @@ static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) {
rb_scan_args(argc, argv, "13", &rb_fieldtype, &arg3, &arg4, &arg5);
ftype = get_fieldtype(rb_fieldtype);
-
+
if (ftype == TYPE_ALNUM ||
ftype == TYPE_ALPHA) {
if (argc != 2)
rb_raise(rb_eArgError, "TYPE_ALNUM and TYPE_ALPHA require one additional argument");
- return INT2NUM(set_field_type(field, ftype,
+ return INT2NUM(set_field_type(field, ftype,
NUM2INT(arg3)));
}
if (ftype == TYPE_ENUM) {
@@ -620,7 +634,7 @@ static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) {
rb_raise(rb_eArgError, "TYPE_ENUM requires three additional arguments");
}
else {
- int n = rbncurs_array_length(arg3);
+ int n = (int) rbncurs_array_length(arg3);
/* Will ncurses free this array of strings in free_field()? */
char** list = ALLOC_N(char*, n+1);
int i;
@@ -628,7 +642,7 @@ static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) {
list[i] = STR2CSTR(rb_ary_entry(arg3, (long)i));
}
list[n] = NULL;
- return INT2NUM(set_field_type(field, ftype,
+ return INT2NUM(set_field_type(field, ftype,
list,
RTEST(arg4),
RTEST(arg5)));
@@ -637,7 +651,7 @@ static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) {
else if (ftype == TYPE_INTEGER) {
if (argc != 4)
rb_raise(rb_eArgError, "TYPE_INTEGER requires three additional arguments");
- return INT2NUM(set_field_type(field, ftype,
+ return INT2NUM(set_field_type(field, ftype,
NUM2INT(arg3),
NUM2LONG(arg4),
NUM2LONG(arg5)));
@@ -645,7 +659,7 @@ static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) {
else if (ftype == TYPE_NUMERIC) {
if (argc != 4)
rb_raise(rb_eArgError, "TYPE_NUMERIC requires three additional arguments");
- return INT2NUM(set_field_type(field, ftype,
+ return INT2NUM(set_field_type(field, ftype,
NUM2INT(arg3),
NUM2DBL(arg4),
NUM2DBL(arg5)));
@@ -653,15 +667,15 @@ static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) {
else if (ftype == TYPE_REGEXP){
if (argc != 2)
rb_raise(rb_eArgError, "TYPE_REGEXP requires one additional argument");
- return INT2NUM(set_field_type(field, ftype,
+ return INT2NUM(set_field_type(field, ftype,
STR2CSTR(arg3)));
}
- else if (ftype == TYPE_IPV4){
+ else if (ftype == TYPE_IPV4){
if (argc != 1)
rb_raise(rb_eArgError, "TYPE_IPV4 has no additional arguments");
return INT2NUM(set_field_type(field, ftype));
}
- else {
+ else {
/* It is a user-defined field type. */
/* Will store the arguments associated with this field */
/* for use in the callback function. */
@@ -672,7 +686,7 @@ static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) {
/* the block-argument used in finding the appropriate Ruby Proc */
return INT2NUM(set_field_type(field, ftype, field));
}
-
+
}
static VALUE rbncurs_m_set_field_type(int argc, VALUE* argv, VALUE dummy)
{ return rbncurs_c_set_field_type(argc-1, argv+1, argv[0]); }
@@ -697,7 +711,7 @@ static VALUE rbncurs_m_field_arg(VALUE dummy, VALUE rb_field)
*/
static VALUE rbncurs_c_set_field_fore(VALUE rb_field, VALUE attr) {
FIELD* field = get_field(rb_field);
- return INT2NUM(set_field_fore(field, NUM2ULONG(attr)));
+ return INT2NUM(set_field_fore(field, (int) NUM2ULONG(attr)));
}
static VALUE rbncurs_m_set_field_fore(VALUE dummy, VALUE rb_field, VALUE attr)
{ return rbncurs_c_set_field_fore(rb_field, attr); }
@@ -711,7 +725,7 @@ static VALUE rbncurs_m_field_fore(VALUE dummy, VALUE rb_field)
static VALUE rbncurs_c_set_field_back(VALUE rb_field, VALUE attr) {
FIELD* field = get_field(rb_field);
- return INT2NUM(set_field_back(field, NUM2ULONG(attr)));
+ return INT2NUM(set_field_back(field, (int) NUM2ULONG(attr)));
}
static VALUE rbncurs_m_set_field_back(VALUE dummy, VALUE rb_field, VALUE attr)
{ return rbncurs_c_set_field_back(rb_field, attr); }
@@ -786,7 +800,7 @@ static VALUE rbncurs_c_set_form_fields(VALUE rb_form, VALUE rb_field_array) {
long i;
FORM* form = NULL;
for (i=0; i<n; i++){
- fields[i] = get_field(rb_ary_entry(rb_field_array, i));
+ fields[i] = get_field(rb_ary_entry(rb_field_array, i));
}
fields[n] = NULL;
form = get_form(rb_form);
@@ -800,7 +814,7 @@ static VALUE rbncurs_c_form_fields(VALUE rb_form) {
FIELD** fields = form_fields(form);
VALUE arr = Qundef;
int i;
- if (fields == NULL)
+ if (fields == NULL)
rb_raise(rb_eRuntimeError, "Error retrieving form fields");
arr = rb_ary_new();
i=0;
@@ -842,12 +856,12 @@ static void field_init_hook(FORM* form) {
static VALUE rbncurs_c_set_field_init(VALUE rb_form, VALUE proc) {
FORM* form = NULL;
if (!rb_obj_is_kind_of(rb_form, cFORM))
- rb_raise(rb_eArgError, "arg1 must be a FORM object");
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
if (!rb_obj_is_kind_of(proc, rb_cProc))
- rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
form = get_form(rb_form);
reg_proc(form, FIELD_INIT_HOOK, proc);
- if (proc != Qnil) {
+ if (proc != Qnil) {
return INT2NUM(set_field_init(form, field_init_hook));
}
else {
@@ -875,12 +889,12 @@ static void field_term_hook(FORM* form) {
static VALUE rbncurs_c_set_field_term(VALUE rb_form, VALUE proc) {
FORM * form = NULL;
if (!rb_obj_is_kind_of(rb_form, cFORM))
- rb_raise(rb_eArgError, "arg1 must be a FORM object");
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
if (!rb_obj_is_kind_of(proc, rb_cProc))
- rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
form = get_form(rb_form);
reg_proc(form, FIELD_TERM_HOOK, proc);
- if (proc != Qnil) {
+ if (proc != Qnil) {
return INT2NUM(set_field_term(form, field_term_hook));
}
else {
@@ -908,12 +922,12 @@ static void form_init_hook(FORM* form) {
static VALUE rbncurs_c_set_form_init(VALUE rb_form, VALUE proc) {
FORM * form = NULL;
if (!rb_obj_is_kind_of(rb_form, cFORM))
- rb_raise(rb_eArgError, "arg1 must be a FORM object");
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
if (!rb_obj_is_kind_of(proc, rb_cProc))
- rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
form = get_form(rb_form);
reg_proc(form, FORM_INIT_HOOK, proc);
- if (proc != Qnil) {
+ if (proc != Qnil) {
return INT2NUM(set_form_init(form, form_init_hook));
}
else {
@@ -941,12 +955,12 @@ static void form_term_hook(FORM* form) {
static VALUE rbncurs_c_set_form_term(VALUE rb_form, VALUE proc) {
FORM * form = NULL;
if (!rb_obj_is_kind_of(rb_form, cFORM))
- rb_raise(rb_eArgError, "arg1 must be a FORM object");
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
if (!rb_obj_is_kind_of(proc, rb_cProc))
- rb_raise(rb_eArgError, "arg2 must be a Proc object");
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
form = get_form(rb_form);
reg_proc(form, FORM_TERM_HOOK, proc);
- if (proc != Qnil) {
+ if (proc != Qnil) {
return INT2NUM(set_form_term(form, form_term_hook));
}
else {
@@ -1099,7 +1113,7 @@ static VALUE rbncurs_c_scale_form(VALUE rb_form, VALUE rows, VALUE columns) {
return Qnil;
}
else {
- int vals[2] = {0,0};
+ int vals[2] = {0,0};
int result = scale_form(form, &vals[0],&vals[1]);
rb_ary_push(rows, INT2NUM(vals[0]));
rb_ary_push(columns, INT2NUM(vals[1]));
@@ -1112,28 +1126,28 @@ static VALUE rbncurs_m_scale_form(VALUE dummy, VALUE rb_form, VALUE rows, VALUE
/*
* form_fieldtype
*/
-static void* make_arg(va_list* ap) {
+static void* make_arg(va_list* ap) {
/* This method creates a list of arguments to be passed */
/* to the validation functions (char_check and field_check). */
- FIELD* field = va_arg(*ap, FIELD*);
+ FIELD* field = va_arg(*ap, FIELD*);
FIELDTYPE* fieldtype = field_type(field);
VALUE proc = get_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK);
if (proc == Qnil) {
proc = get_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK);
}
-
+
/* Compare number of arguments in Ruby Proc with that of set_field_type */
- if (proc != Qnil) {
+ if (proc != Qnil) {
VALUE argc = rb_funcall(proc, rb_intern("arity"),0);
VALUE args = get_proc(field, FIELDTYPE_ARGS);
- if (args != Qnil) {
- if (NUM2INT(argc)-1 != rbncurs_array_length(args)) {
+ if (args != Qnil) {
+ if (NUM2INT(argc)-1 != rbncurs_array_length(args)) {
char msg[500];
snprintf(msg, 500, "The validation functions for this field type need %d additional arguments.",(int)(NUM2INT(argc)-1));
msg[499]=0;
- rb_raise(rb_eArgError, msg);
+ rb_raise(rb_eArgError, "%s", msg);
}
- }
+ }
}
/* field will be the only argument in field_check/char_check callback */
/* and will be used to locate the appropriate Ruby Proc */
@@ -1142,10 +1156,10 @@ static void* make_arg(va_list* ap) {
static bool field_check(FIELD* field, const void* argblock) {
FIELDTYPE* fieldtype = field_type(field);
VALUE proc = get_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK);
- if (proc != Qnil)
+ if (proc != Qnil)
{
VALUE args = rb_ary_dup(get_proc(field, FIELDTYPE_ARGS));
- rb_ary_unshift(args, wrap_field(field));
+ rb_ary_unshift(args, wrap_field(field));
return RTEST(rb_apply(proc, rb_intern("call"), args));
}
return 1;
@@ -1164,18 +1178,18 @@ static bool char_check(int c, const void* argblock) {
}
return 1;
}
-static VALUE rbncurs_m_new_fieldtype(VALUE dummy, VALUE field_check_proc, VALUE char_check_proc)
+static VALUE rbncurs_m_new_fieldtype(VALUE dummy, VALUE field_check_proc, VALUE char_check_proc)
{
FIELDTYPE* fieldtype = new_fieldtype(field_check_proc == Qnil ? NULL : field_check,
- char_check_proc == Qnil ? NULL : char_check);
+ char_check_proc == Qnil ? NULL : char_check);
set_fieldtype_arg(fieldtype, make_arg, NULL, NULL);
if (field_check_proc != Qnil) {
reg_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK, field_check_proc);
- }
+ }
if (char_check_proc != Qnil) {
reg_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK, char_check_proc);
}
-
+
return wrap_fieldtype(fieldtype);
}
@@ -1207,13 +1221,13 @@ static bool prev_choice(FIELD* field, const void* argblock) {
static VALUE rbncurs_c_set_fieldtype_choice(VALUE rb_fieldtype, VALUE next_choice_proc, VALUE prev_choice_proc) {
FIELDTYPE* fieldtype = get_fieldtype(rb_fieldtype);
- int result = set_fieldtype_choice(fieldtype,
- next_choice_proc == Qnil ? NULL : next_choice,
+ int result = set_fieldtype_choice(fieldtype,
+ next_choice_proc == Qnil ? NULL : next_choice,
prev_choice_proc == Qnil ? NULL : prev_choice);
if (next_choice_proc != Qnil)
reg_proc(fieldtype, FIELDTYPE_NEXT_CHOICE_HOOK, next_choice_proc);
if (prev_choice_proc != Qnil)
- reg_proc(fieldtype, FIELDTYPE_PREV_CHOICE_HOOK, prev_choice_proc);
+ reg_proc(fieldtype, FIELDTYPE_PREV_CHOICE_HOOK, prev_choice_proc);
return INT2NUM(result);
}
static VALUE rbncurs_m_set_fieldtype_choice(VALUE dummy, VALUE rb_fieldtype, VALUE next_choice_proc, VALUE prev_choice_proc)
@@ -1253,9 +1267,9 @@ static VALUE rbncurs_m_pos_form_cursor(VALUE dummy, VALUE rb_form)
void init_form(void)
{
-
+
mForm = rb_define_module_under(mNcurses, "Form");
-
+
FORM_SNG_FUNC(current_field,1);
FORM_SNG_FUNC(data_ahead,1);
FORM_SNG_FUNC(data_behind,1);
@@ -1279,6 +1293,11 @@ void init_form(void)
FORM_SNG_FUNC(field_type,1);
/* FORM_SNG_FUNC(field_userptr,1); */
FORM_SNG_FUNC(form_driver,2);
+
+ # ifdef HAVE_FORM_DRIVER_W
+ FORM_SNG_FUNC(form_driver_w,3);
+ #endif
+
FORM_SNG_FUNC(form_fields,1);
FORM_SNG_FUNC(form_init,1);
FORM_SNG_FUNC(form_opts,1);
@@ -1334,7 +1353,7 @@ void init_form(void)
init_opts_constants();
init_just_constants();
init_form_opts_constants();
-
+
/* Hashes to store registered blocks (Proc) */
{
VALUE hashes = rb_iv_set(mForm, "@proc_hashes", rb_ary_new());
@@ -1359,6 +1378,11 @@ void init_form(void)
RB_CLASS_METH(cFORM, NULL, field_init,0);
RB_CLASS_METH(cFORM, NULL, field_term,0);
RB_CLASS_METH(cFORM, "driver", form_driver,1);
+
+ # ifdef HAVE_FORM_DRIVER_W
+ RB_CLASS_METH(cFORM, "driver_w", form_driver_w,2);
+ #endif
+
RB_CLASS_METH(cFORM, "fields", form_fields,0);
RB_CLASS_METH(cFORM, "init", form_init,0);
RB_CLASS_METH(cFORM, "opts", form_opts,0);
diff --git a/form_wrap.h b/form_wrap.h
index f8a015c..11110b8 100644
--- a/form_wrap.h
+++ b/form_wrap.h
@@ -3,7 +3,7 @@
* Contributed by Simon Kaczor <skaczor at cox.net>
* Prognosoft Inc. <http://www.prognosoft.biz>
* Copyright 2004
- *
+ *
* 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
@@ -20,11 +20,14 @@
*
* Changes
* (C) 2011 Tobias Herzke
+ * (C) 2013 Gaute Hope <eg at gaute.vetsj.com>
*/
#if !defined(FORM_HH) && (defined(HAVE_FORM_H) || defined(HAVE_NCURSESW_FORM_H))
#define FORM_HH
+# define _XOPEN_SOURCE_EXTENDED
+
#ifdef HAVE_FORM_H
#include <form.h>
#else
@@ -40,7 +43,7 @@ extern VALUE cFORM;
/*extern VALUE cPAGE;*/
typedef struct {
- bool (* field_check)(FIELD *,const void *);
+ bool (* field_check)(FIELD *,const void *);
FIELDTYPE* fieldtype;
} FLDCHKFUNC;
diff --git a/lib/ncurses_sugar.rb b/lib/ncurses_sugar.rb
index b0e462b..61d691c 100644
--- a/lib/ncurses_sugar.rb
+++ b/lib/ncurses_sugar.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
# ncurses-ruby is a ruby module for accessing the FSF's ncurses library
# (C) 2002, 2003, 2004 Tobias Peters <t-peters at users.berlios.de>
# (C) 2004 Simon Kaczor <skaczor at cox.net>
@@ -23,25 +24,25 @@
def Ncurses._XOPEN_CURSES
Ncurses::XOPEN_CURSES
end
-def Ncurses._SUBWIN
+def Ncurses._SUBWIN
Ncurses::SUBWIN
end
-def Ncurses._ENDLINE
+def Ncurses._ENDLINE
Ncurses::ENDLINE
end
-def Ncurses._FULLWIN
+def Ncurses._FULLWIN
Ncurses::FULLWIN
end
def Ncurses._SCROLLWIN
Ncurses::SCROLLWIN
end
-def Ncurses._ISPAD
+def Ncurses._ISPAD
Ncurses::ISPAD
end
def Ncurses._HASMOVED
Ncurses::HASMOVED
end
-def Ncurses._WRAPPED
+def Ncurses._WRAPPED
Ncurses::WRAPPED
end
def Ncurses._NOCHANGE
@@ -98,7 +99,7 @@ module Ncurses
end
GETSTR_LIMIT = 1024
- module Panel
+ module Panel
class PANEL; end
end
@@ -111,7 +112,7 @@ module Ncurses
@user_object = obj
end
end
-
+
class FIELD
attr_reader :user_object
@@ -134,7 +135,7 @@ module Ncurses
@user_object = obj
end
end
-
+
class ITEM
attr_reader :user_object
@@ -158,7 +159,7 @@ def Ncurses.mvinchstr(y,x, str)
Ncurses.mvwinchstr(Ncurses.stdscr, y,x, str)
end
def Ncurses.mvwinchnstr(win, y,x, str, n)
- if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
Ncurses::ERR
else
Ncurses.winchnstr(win,str,n)
@@ -182,7 +183,7 @@ def Ncurses.mvgetnstr(y,x, str, n)
Ncurses.mvwgetnstr(Ncurses.stdscr, y,x, str, n)
end
def Ncurses.mvwgetnstr(win, y,x, str, n)
- if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
Ncurses::ERR
else
Ncurses.wgetnstr(win,str,n)
@@ -202,7 +203,7 @@ def Ncurses.mvinstr(y,x, str)
Ncurses.mvwinstr(Ncurses.stdscr, y,x, str)
end
def Ncurses.mvwinnstr(win, y,x, str, n)
- if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
Ncurses::ERR
else
Ncurses.winnstr(win,str,n)
@@ -270,7 +271,7 @@ def Ncurses.mvscanw(y,x, format, result)
Ncurses.mvwscanw(Ncurses.stdscr, y,x, format, result)
end
def Ncurses.mvwscanw(win, y,x, format, result)
- if (Ncurses.wmove(win, y,x) == Ncurses::ERR)
+ if (Ncurses.wmove(win, y,x) == Ncurses::ERR)
Ncurses::ERR
else
Ncurses.wscanw(win, format, result)
@@ -278,7 +279,7 @@ def Ncurses.mvwscanw(win, y,x, format, result)
end
def Ncurses.wscanw(win, format, result)
str = ""
- if (Ncurses.wgetstr(win, str) == Ncurses::ERR)
+ if (Ncurses.wgetstr(win, str) == Ncurses::ERR)
Ncurses::ERR
else
require "scanf.rb" # Use ruby's implementation of scanf
@@ -290,7 +291,7 @@ def Ncurses.mvprintw(*args)
Ncurses.mvwprintw(Ncurses.stdscr, *args)
end
def Ncurses.mvwprintw(win, y,x, *args)
- if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
+ if (Ncurses.wmove(win,y,x) == Ncurses::ERR)
Ncurses::ERR
else
wprintw(win, *args)
@@ -317,7 +318,7 @@ module Ncurses
unless target.ancestors.member?(Ncurses)
target.__send__(:include, Ncurses)
end
-
+
# make methods available
unless target.respond_to?(:pre_Ncurses_method_missing)
target.module_eval{
diff --git a/lib/ncursesw.rb b/lib/ncursesw.rb
index e84b65b..b2e99b2 100644
--- a/lib/ncursesw.rb
+++ b/lib/ncursesw.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
# ncurses-ruby is a ruby module for accessing the FSF's ncurses library
# (C) 2002, 2003, 2004 Tobias Peters <t-peters at users.berlios.de>
# (C) 2004 Simon Kaczor <skaczor at cox.net>
diff --git a/make_dist.rb b/make_dist.rb
deleted file mode 100755
index 11e08f8..0000000
--- a/make_dist.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env ruby
-# (C) 2002-2011 Tobias Herzke
-# License: LGPL v2.1
-# $Id: make_dist.rb,v 1.8 2011-05-30 23:05:50 t-peters Exp $
-
-require "fileutils"
-
-def sys(i)
- puts("\"#{i}\"")
- system(i)
-end
-
-dir = File.dirname(__FILE__)
-
-%w(ncurses ncursesw).each{|flavor|
-
-base = flavor+"-ruby"
-
-files = IO.readlines(dir + "/MANIFEST_"+flavor).collect{|filename|filename.chomp}
-
-Version = File.new("#{dir}/VERSION").readline.chomp
-
-FileUtils.mkdir "#{base}-#{Version}"
-files.each{|filename|
- if filename.index "/"
- FileUtils.mkdir_p "#{base}-#{Version}/#{File.dirname(filename)}"
- end
- if filename.index("example")
- sys "sed -e '/require/ s/ncurses/#{flavor}/' <#{dir}/#{filename} >#{base}-#{Version}/#{filename}"
- else
- sys "cp #{dir}/#{filename} #{base}-#{Version}/#{filename}"
- end
-}
-sys "cp #{dir}/extconf_#{flavor}.rb #{base}-#{Version}/extconf.rb"
-sys "tar cjf #{base}-#{Version}.tar.bz2 --owner=0 --group=0 #{base}-#{Version}"
-
-sys "rm -r #{base}-#{Version}/"
-}
diff --git a/menu_wrap.c b/menu_wrap.c
index f76582f..942896c 100644
--- a/menu_wrap.c
+++ b/menu_wrap.c
@@ -30,6 +30,7 @@
#include "menu_wrap.h"
#include "ncurses_wrap.h"
+#include "compat.h"
VALUE mMenu;
VALUE cITEM;
@@ -807,7 +808,7 @@ static VALUE rbncurs_m_item_visible(VALUE dummy, VALUE rb_item)
static VALUE rbncurs_c_set_menu_fore(VALUE rb_menu, VALUE attr)
{
MENU *menu = get_menu(rb_menu);
- return INT2NUM(set_menu_fore(menu, NUM2ULONG(attr)));
+ return INT2NUM(set_menu_fore(menu, (int) NUM2ULONG(attr)));
}
static VALUE rbncurs_m_set_menu_fore(VALUE dummy, VALUE rb_menu, VALUE attr)
{ return rbncurs_c_set_menu_fore(rb_menu, attr); }
@@ -823,7 +824,7 @@ static VALUE rbncurs_m_menu_fore(VALUE dummy, VALUE rb_menu)
static VALUE rbncurs_c_set_menu_back(VALUE rb_menu, VALUE attr)
{
MENU *menu = get_menu(rb_menu);
- return INT2NUM(set_menu_back(menu, NUM2ULONG(attr)));
+ return INT2NUM(set_menu_back(menu, (int) NUM2ULONG(attr)));
}
static VALUE rbncurs_m_set_menu_back(VALUE dummy, VALUE rb_menu, VALUE attr)
{ return rbncurs_c_set_menu_back(rb_menu, attr); }
@@ -839,7 +840,7 @@ static VALUE rbncurs_m_menu_back(VALUE dummy, VALUE rb_menu)
static VALUE rbncurs_c_set_menu_grey(VALUE rb_menu, VALUE attr)
{
MENU *menu = get_menu(rb_menu);
- return INT2NUM(set_menu_grey(menu, NUM2ULONG(attr)));
+ return INT2NUM(set_menu_grey(menu, (int) NUM2ULONG(attr)));
}
static VALUE rbncurs_m_set_menu_grey(VALUE dummy, VALUE rb_menu, VALUE attr)
{ return rbncurs_c_set_menu_grey(rb_menu, attr); }
diff --git a/ncurses_wrap.c b/ncurses_wrap.c
old mode 100755
new mode 100644
index 09609d1..be76b72
--- a/ncurses_wrap.c
+++ b/ncurses_wrap.c
@@ -3,6 +3,7 @@
* (C) 2002, 2003, 2004 Tobias Peters <t-peters at berlios.de>
* (C) 2004 Simon Kaczor <skaczor at cox.net>
* (C) 2005 2006 2009 2011 Tobias Herzke
+ * (C) 2013 Gaute Hope <eg at 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
@@ -18,7 +19,7 @@
* 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.20 2011-05-30 23:28:23 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:
@@ -65,10 +66,15 @@
*/
#include "ncurses_wrap.h"
+#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 */
@@ -427,17 +433,17 @@ init_globals_2(void)
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",
@@ -557,7 +563,7 @@ static chtype * RB2CHSTR(VALUE array)
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;
@@ -565,8 +571,14 @@ static chtype * RB2CHSTR(VALUE array)
}
static VALUE rbncurs_addch(VALUE dummy, VALUE arg1) {
- return INT2NUM(addch(NUM2ULONG(arg1)));
+ return INT2NUM(addch((int) NUM2ULONG(arg1)));
}
+#ifdef HAVE_ADD_WCH
+static VALUE rbncurs_add_wch(VALUE dummy, VALUE arg1) {
+ wchar_t c = NUM2ULONG(arg1);
+ return INT2NUM(add_wch((cchar_t *)&c));
+}
+#endif
static VALUE rbncurs_addchnstr(VALUE dummy, VALUE arg1, VALUE arg2) {
chtype * chstr = RB2CHSTR(arg1);
VALUE return_value = INT2NUM(addchnstr(chstr, NUM2INT(arg2)));
@@ -592,57 +604,57 @@ 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
@@ -692,16 +704,16 @@ 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;
@@ -728,7 +740,7 @@ static VALUE rbncurs_cbreak(VALUE dummy) {
}
#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
@@ -786,7 +798,7 @@ 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());
@@ -809,12 +821,16 @@ 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;
-#ifdef NCURSES_VERSION
+#if defined(NCURSES_VERSION) && defined(NCURSES_OPAQUE) && !NCURSES_OPAQUE
int windelay = c_win->_delay;
#else
int windelay = 0;
@@ -823,41 +839,113 @@ static int rbncurshelper_nonblocking_wgetch(WINDOW *c_win) {
/* 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;
-#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;
- 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 );
-
- /* 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);
+ 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;
+#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
+
+#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
}
-#ifdef NCURSES_VERSION
+#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);
+}
+
+#ifdef HAVE_GET_WCH
+/* 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;
+}
+#endif
+
static VALUE rbncurs_getch(VALUE dummy) {
return INT2NUM(rbncurshelper_nonblocking_wgetch(stdscr));
}
+
+#ifdef HAVE_GET_WCH
+static VALUE rbncurs_get_wch(VALUE dummy) {
+ return rbncurshelper_nonblocking_wget_wch(stdscr);
+}
+#endif
+
static VALUE rbncurs_halfdelay(VALUE dummy, VALUE arg1) {
return INT2NUM(rbncurshelper_halfdelay_cbreak(NUM2INT(arg1), 1));
}
@@ -871,7 +959,7 @@ 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);
@@ -887,7 +975,7 @@ static VALUE rbncurs_inch(VALUE dummy) {
}
static VALUE rbncurs_initscr(VALUE dummy) {
VALUE v = wrap_window(initscr());
- if (!RTEST(v))
+ if (!RTEST(v))
return v;
Init_ncurses_full();
@@ -1002,7 +1090,7 @@ 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)));
@@ -1052,7 +1140,7 @@ 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) {
@@ -1077,7 +1165,7 @@ static VALUE rbncurs_mvaddstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE 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) {
@@ -1096,14 +1184,14 @@ static VALUE rbncurs_mvgetch(VALUE dummy, VALUE arg1, VALUE arg2) {
}
#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)));
@@ -1113,11 +1201,11 @@ static VALUE rbncurs_mvinsstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE 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) {
@@ -1144,7 +1232,7 @@ static VALUE rbncurs_mvwaddstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3,
}
#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) {
@@ -1158,7 +1246,7 @@ static VALUE rbncurs_mvwgetch(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3) {
}
#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) {
@@ -1168,7 +1256,7 @@ 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)));
@@ -1178,7 +1266,7 @@ static VALUE rbncurs_mvwinsstr(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3,
}
#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) {
@@ -1227,7 +1315,7 @@ static VALUE rbncurs_PAIR_NUMBER(VALUE dummy, VALUE 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) {
@@ -1314,13 +1402,13 @@ static VALUE rbncurs_set_term(VALUE dummy, VALUE rb_new_screen) {
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) {
@@ -1415,15 +1503,21 @@ static VALUE rbncurs_use_env(VALUE dummy, VALUE arg1) {
#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)));
+}
+#ifdef HAVE_ADD_WCH
+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));
}
+#endif
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,
@@ -1453,17 +1547,17 @@ 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) {
@@ -1490,7 +1584,7 @@ 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)));
@@ -1498,14 +1592,21 @@ static VALUE rbncurs_werase(VALUE dummy, VALUE arg1) {
static VALUE rbncurs_wgetch(VALUE dummy, VALUE arg1) {
return INT2NUM(rbncurshelper_nonblocking_wgetch(get_window(arg1)));
}
+
+#ifdef HAVE_GET_WCH
+static VALUE rbncurs_wget_wch(VALUE dummy, VALUE arg1) {
+ return rbncurshelper_nonblocking_wget_wch(get_window(arg1));
+}
+#endif
+
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)));
@@ -1556,7 +1657,7 @@ static VALUE rbncurs_wtouchln(VALUE dummy, VALUE arg1, VALUE arg2, VALUE arg3, V
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
@@ -1616,7 +1717,7 @@ static VALUE rbncurs_putwin(VALUE dummy, VALUE rb_win, VALUE io)
}
#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);
@@ -1640,6 +1741,9 @@ static VALUE rbncurs_newterm(VALUE dummy, VALUE rb_type, VALUE rb_outfd, VALUE r
static void init_functions_2(void) {
NCFUNC(addch, 1);
+#ifdef HAVE_ADD_WCH
+ NCFUNC(add_wch, 1);
+#endif
NCFUNC(addchnstr, 2);
NCFUNC(addchstr, 1);
NCFUNC(addnstr, 2);
@@ -1722,6 +1826,10 @@ static void init_functions_2(void) {
NCFUNC(flushinp, 0);
NCFUNC(getbkgd, 1);
NCFUNC(getch, 0);
+#ifdef HAVE_GET_WCH
+ NCFUNC(get_wch, 0);
+ NCFUNC(wget_wch, 1);
+#endif
NCFUNC(halfdelay, 1);
rb_define_module_function(mNcurses, "has_colors?",
(&rbncurs_has_colors),
@@ -1901,6 +2009,9 @@ static void init_functions_2(void) {
#endif
NCFUNC(vline, 2);
NCFUNC(waddch, 2);
+#ifdef HAVE_ADD_WCH
+ NCFUNC(wadd_wch, 2);
+#endif
NCFUNC(waddchnstr, 3);
NCFUNC(waddchstr, 2);
NCFUNC(waddnstr, 3);
@@ -2348,7 +2459,8 @@ static VALUE rbncurs_getparyx(VALUE dummy, VALUE rb_win, VALUE rb_y, VALUE rb_x)
}
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,
@@ -2394,7 +2506,7 @@ static VALUE rbncurs_tracef(int argc, VALUE * argv, VALUE dummy)
return Qnil;
}
_tracef("%s",
- STR2CSTR(rb_funcall3(rb_mKernel, rb_intern("sprintf"), argc, argv)));
+ STR2CSTR(funcall3(rb_mKernel, rb_intern("sprintf"), argc, argv)));
return Qnil;
}
#endif /* HAVE__TRACEF */
@@ -2602,7 +2714,7 @@ VALUE rb_## ACS (VALUE 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), \
@@ -2724,11 +2836,7 @@ static void init_safe_functions(void)
NCFUNC(setlocale, 2);
#endif
}
-#ifdef HAVE_NCURSESW_CURSES_H
void Init_ncursesw_bin(void)
-#else
-void Init_ncurses_bin(void)
-#endif
{
mNcurses = rb_define_module("Ncurses");
eNcurses = rb_define_class_under(mNcurses, "Exception", rb_eRuntimeError);
diff --git a/ncurses_wrap.h b/ncurses_wrap.h
index 97cc61a..177c693 100644
--- a/ncurses_wrap.h
+++ b/ncurses_wrap.h
@@ -3,6 +3,7 @@
* (C) 2002, 2003 Tobias Peters <t-peters at berlios.de>
* (C) 2004 Simon Kaczor <skaczor at cox.net>
* (C) 2009 2011 Tobias Herzke
+ * (C) 2013 Gaute Hope <eg at 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
@@ -64,6 +65,8 @@
- v*printw functions (but normal printw functions are supported!)
*/
+# define _XOPEN_SOURCE_EXTENDED
+
#if defined(HAVE_GETWIN) || defined(HAVE_PUTWIN)
# ifdef HAVE_UNISTD_H
# include <unistd.h>
diff --git a/ncursesw.gemspec b/ncursesw.gemspec
new file mode 100644
index 0000000..c3f3299
--- /dev/null
+++ b/ncursesw.gemspec
@@ -0,0 +1,50 @@
+# -*- encoding: utf-8 -*-
+
+SUMMARY = 'This wrapper provides access to the functions, macros, global variables and constants ' +
+ 'of the ncurses library. These are mapped to a Ruby Module named "Ncurses": ' +
+ 'Functions and external variables are implemented as singleton functions of the Module Ncurses.'
+
+spec = Gem::Specification.new do |s|
+ s.name = 'ncursesw'
+ s.version = '1.4.3'
+ s.platform = Gem::Platform::RUBY
+ s.authors = ['Tobias Herzke', 'Sup developers']
+ s.email = ['sup-talk at rubyforge.org']
+ s.has_rdoc = false
+ s.homepage = 'http://github.com/sup-heliotrope/ncursesw-ruby'
+ s.summary = SUMMARY
+ s.description = "Tweaked version of ncursesw from http://ncurses-ruby.berlios.de/."
+
+ s.require_paths = ['lib']
+ s.files = [
+ "Changes",
+ "COPYING",
+ "README",
+ "THANKS",
+ "TODO",
+ "examples/example.rb",
+ "examples/form.rb",
+ "examples/form2.rb",
+ "examples/form_get_wch.rb",
+ "examples/hello_ncurses.rb",
+ "examples/LICENSES_for_examples",
+ "examples/rain.rb",
+ "examples/tclock.rb",
+ "examples/read_line.rb",
+ "examples/test_scanw.rb",
+ "extconf.rb",
+ "form_wrap.c",
+ "form_wrap.h",
+ "ncurses_wrap.c",
+ "ncurses_wrap.h",
+ "lib/ncursesw.rb",
+ "lib/ncurses_sugar.rb",
+ "panel_wrap.c",
+ "panel_wrap.h",
+ "menu_wrap.c",
+ "menu_wrap.h",
+ "compat.h",
+ ]
+ s.extensions = ['extconf.rb']
+end
+
diff --git a/panel_wrap.c b/panel_wrap.c
index 9680b25..53b282b 100644
--- a/panel_wrap.c
+++ b/panel_wrap.c
@@ -24,6 +24,7 @@
#include "panel_wrap.h"
#include "ncurses_wrap.h"
+#include "compat.h"
VALUE mPanel;
VALUE cPANEL;
diff --git a/panel_wrap.h b/panel_wrap.h
old mode 100755
new mode 100644
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-ncurses.git
More information about the Pkg-ruby-extras-commits
mailing list