ncursesw 0.9.1.a

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