summaryrefslogtreecommitdiff
path: root/ext/curses
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-10 07:18:16 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-10 07:18:16 +0000
commit2f8d3bdc21b37f0d6881b817c8fd9c5b4b351cd4 (patch)
treeeb88114284c1e7a35677815487d122a68fdf9f57 /ext/curses
parent3493ea5c7acfeaf187873d4986181a5fda446aa3 (diff)
* array.c (rb_ary_modify): should copy the internal buffer if the
modifying buffer is shared. * array.c (ary_make_shared): make an internal buffer of an array to be shared. * array.c (rb_ary_shift): avoid sliding an internal buffer by using shared buffer. * array.c (rb_ary_subseq): avoid copying the buffer. * parse.y (gettable): should freeze __LINE__ string. * io.c (rb_io_puts): old behavoir restored. rationale: a) if you want to call to_s for arrays, you can just call print a, "\n". b) to_s wastes memory if array (and sum of its contents) is huge. c) now any object that has to_ary is treated as an array, using rb_check_convert_type(). * hash.c (rb_hash_initialize): now accepts a block to calculate the default value. [new] * hash.c (rb_hash_aref): call "default" method to get the value corrensponding to the non existing key. * hash.c (rb_hash_default): get the default value based on the block given to 'new'. Now it takes an optinal "key" argument. "default" became the method to get the value for non existing key. Users may override "default" method to change the hash behavior. * hash.c (rb_hash_set_default): clear the flag if a block is given to 'new' * object.c (Init_Object): undef Data.allocate, left Data.new. * ext/curses/curses.c (window_scrollok): use RTEST(). * ext/curses/curses.c (window_idlok): ditto. * ext/curses/curses.c (window_keypad): ditto. * ext/curses/curses.c (window_idlok): idlok() may return void on some platforms; so don't use return value. * ext/curses/curses.c (window_scrollok): ditto for consistency. * ext/curses/curses.c: replace FIX2INT() by typechecking NUM2INT(). * parse.y (str_extend): should not process immature #$x and #@x interpolation, e.g #@#@ etc. * enum.c (enum_sort_by): sort_by does not have to be stable always. * enum.c (enum_sort_by): call qsort directly to gain performance. * util.c (ruby_qsort): ruby_qsort(qs6) is now native thread safe. * error.c (rb_sys_fail): it must be a bug if it's called when errno == 0. * regex.c (WC2MBC1ST): should not pass through > 0x80 number in UTF-8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/curses')
-rw-r--r--ext/curses/curses.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/ext/curses/curses.c b/ext/curses/curses.c
index c756c47..c152382 100644
--- a/ext/curses/curses.c
+++ b/ext/curses/curses.c
@@ -460,18 +460,20 @@ static VALUE
curses_curs_set(VALUE obj, VALUE visibility)
{
int n;
- return (n = curs_set(FIX2INT(visibility)) != ERR) ? INT2FIX(n) : Qnil;
+ return (n = curs_set(NUM2INT(visibility)) != ERR) ? INT2FIX(n) : Qnil;
}
static VALUE
curses_scrl(VALUE obj, VALUE n)
{
+ /* may have to raise exception on ERR */
return (scrl(NUM2INT(n)) == OK) ? Qtrue : Qfalse;
}
static VALUE
curses_setscrreg(VALUE obj, VALUE top, VALUE bottom)
{
+ /* may have to raise exception on ERR */
return (setscrreg(NUM2INT(top), NUM2INT(bottom)) == OK) ? Qtrue : Qfalse;
}
@@ -479,21 +481,21 @@ static VALUE
curses_attroff(VALUE obj, VALUE attrs)
{
return window_attroff(rb_stdscr,attrs);
- /* return INT2FIX(attroff(FIX2INT(attrs))); */
+ /* return INT2FIX(attroff(NUM2INT(attrs))); */
}
static VALUE
curses_attron(VALUE obj, VALUE attrs)
{
return window_attron(rb_stdscr,attrs);
- /* return INT2FIX(attroff(FIX2INT(attrs))); */
+ /* return INT2FIX(attroff(NUM2INT(attrs))); */
}
static VALUE
curses_attrset(VALUE obj, VALUE attrs)
{
return window_attrset(rb_stdscr,attrs);
- /* return INT2FIX(attroff(FIX2INT(attrs))); */
+ /* return INT2FIX(attroff(NUM2INT(attrs))); */
}
static VALUE
@@ -513,20 +515,23 @@ curses_bkgd(VALUE obj, VALUE ch)
static VALUE
curses_start_color(VALUE obj)
{
+ /* may have to raise exception on ERR */
return (start_color() == OK) ? Qtrue : Qfalse;
}
static VALUE
curses_init_pair(VALUE obj, VALUE pair, VALUE f, VALUE b)
{
- return (init_pair(FIX2INT(pair),FIX2INT(f),FIX2INT(b)) == OK) ? Qtrue : Qfalse;
+ /* may have to raise exception on ERR */
+ return (init_pair(NUM2INT(pair),NUM2INT(f),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
}
static VALUE
curses_init_color(VALUE obj, VALUE color, VALUE r, VALUE g, VALUE b)
{
- return (init_color(FIX2INT(color),FIX2INT(r),
- FIX2INT(g),FIX2INT(b)) == OK) ? Qtrue : Qfalse;
+ /* may have to raise exception on ERR */
+ return (init_color(NUM2INT(color),NUM2INT(r),
+ NUM2INT(g),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
}
static VALUE
@@ -546,7 +551,7 @@ curses_color_content(VALUE obj, VALUE color)
{
short r,g,b;
- color_content(FIX2INT(color),&r,&g,&b);
+ color_content(NUM2INT(color),&r,&g,&b);
return rb_ary_new3(3,INT2FIX(r),INT2FIX(g),INT2FIX(b));
}
@@ -555,20 +560,20 @@ curses_pair_content(VALUE obj, VALUE pair)
{
short f,b;
- pair_content(FIX2INT(pair),&f,&b);
+ pair_content(NUM2INT(pair),&f,&b);
return rb_ary_new3(2,INT2FIX(f),INT2FIX(b));
}
static VALUE
curses_color_pair(VALUE obj, VALUE attrs)
{
- return INT2FIX(COLOR_PAIR(FIX2INT(attrs)));
+ return INT2FIX(COLOR_PAIR(NUM2INT(attrs)));
}
static VALUE
curses_pair_number(VALUE obj, VALUE attrs)
{
- return INT2FIX(PAIR_NUMBER(FIX2INT(attrs)));
+ return INT2FIX(PAIR_NUMBER(NUM2INT(attrs)));
}
#endif
@@ -591,7 +596,7 @@ no_mevent()
static void
curses_mousedata_free(struct mousedata *mdata)
{
- if( mdata->mevent )
+ if (mdata->mevent)
free(mdata->mevent);
};
@@ -604,7 +609,7 @@ curses_getmouse(VALUE obj)
val = Data_Make_Struct(cMouseEvent,struct mousedata,
0,curses_mousedata_free,mdata);
mdata->mevent = (MEVENT*)malloc(sizeof(MEVENT));
- return ( getmouse(mdata->mevent) == OK ) ? val : Qnil;
+ return (getmouse(mdata->mevent) == OK) ? val : Qnil;
};
static VALUE
@@ -898,8 +903,8 @@ window_box(argc, argv, self)
c = NUM2CHR(corn);
getyx(winp->window, cur_y, cur_x);
- x = FIX2INT(window_maxx(self)) - 1;
- y = FIX2INT(window_maxy(self)) - 1;
+ x = NUM2INT(window_maxx(self)) - 1;
+ y = NUM2INT(window_maxy(self)) - 1;
wmove(winp->window, 0, 0);
waddch(winp->window, c);
wmove(winp->window, y, 0);
@@ -1062,11 +1067,10 @@ static VALUE
window_scrollok(VALUE obj, VALUE bf)
{
struct windata *winp;
- int res;
GetWINDOW(obj, winp);
- res = scrollok(winp->window, (bf == Qtrue) ? TRUE : FALSE);
- return (res == OK) ? Qtrue : Qfalse;
+ scrollok(winp->window, RTEST(bf) ? TRUE : FALSE);
+ return Qnil;
}
static VALUE
@@ -1076,8 +1080,8 @@ window_idlok(VALUE obj, VALUE bf)
int res;
GetWINDOW(obj, winp);
- res = idlok(winp->window, (bf == Qtrue) ? TRUE : FALSE);
- return (res == OK) ? Qtrue : Qfalse;
+ idlok(winp->window, RTEST(bf) ? TRUE : FALSE);
+ return Qnil;
}
static VALUE
@@ -1088,6 +1092,7 @@ window_setscrreg(VALUE obj, VALUE top, VALUE bottom)
GetWINDOW(obj, winp);
res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom));
+ /* may have to raise exception on ERR */
return (res == OK) ? Qtrue : Qfalse;
};
@@ -1097,6 +1102,7 @@ window_scroll(VALUE obj)
struct windata *winp;
GetWINDOW(obj, winp);
+ /* may have to raise exception on ERR */
return (scroll(winp->window) == OK) ? Qtrue : Qfalse;
}
@@ -1106,6 +1112,7 @@ window_scrl(VALUE obj, VALUE n)
struct windata *winp;
GetWINDOW(obj, winp);
+ /* may have to raise exception on ERR */
return (wscrl(winp->window,NUM2INT(n)) == OK) ? Qtrue : Qfalse;
}
@@ -1115,7 +1122,7 @@ window_attroff(VALUE obj, VALUE attrs)
struct windata *winp;
GetWINDOW(obj,winp);
- return INT2FIX(wattroff(winp->window,FIX2INT(attrs)));
+ return INT2FIX(wattroff(winp->window,NUM2INT(attrs)));
};
static VALUE
@@ -1125,10 +1132,10 @@ window_attron(VALUE obj, VALUE attrs)
VALUE val;
GetWINDOW(obj,winp);
- val = INT2FIX(wattron(winp->window,FIX2INT(attrs)));
+ val = INT2FIX(wattron(winp->window,NUM2INT(attrs)));
if( rb_block_given_p() ){
rb_yield(val);
- wattroff(winp->window,FIX2INT(attrs));
+ wattroff(winp->window,NUM2INT(attrs));
return val;
}
else{
@@ -1142,7 +1149,7 @@ window_attrset(VALUE obj, VALUE attrs)
struct windata *winp;
GetWINDOW(obj,winp);
- return INT2FIX(wattrset(winp->window,FIX2INT(attrs)));
+ return INT2FIX(wattrset(winp->window,NUM2INT(attrs)));
}
static VALUE
@@ -1182,10 +1189,11 @@ window_keypad(VALUE obj, VALUE val)
GetWINDOW(obj,winp);
/* keypad() of NetBSD's libcurses returns no value */
#if defined(__NetBSD__) && !defined(NCURSES_VERSION)
- keypad(winp->window,(val == Qtrue ? TRUE : FALSE));
+ keypad(winp->window,(RTEST(val) ? TRUE : FALSE));
return Qnil;
#else
- return (keypad(winp->window,(val == Qtrue) ? TRUE : FALSE)) == OK ?
+ /* may have to raise exception on ERR */
+ return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ?
Qtrue : Qfalse;
#endif
};