cleanup for curses, gdbm [ruby-core:502], [ruby-core:503]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
53178fc7db
commit
f3376759ab
@ -13,31 +13,27 @@
|
|||||||
* - Takaaki Tateishi (ttate@kt.jaist.ac.jp)
|
* - Takaaki Tateishi (ttate@kt.jaist.ac.jp)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_NCURSES_H
|
#if defined(HAVE_NCURSES_H)
|
||||||
# include <ncurses.h>
|
# include <ncurses.h>
|
||||||
|
#elif defined(HAVE_NCURSES_CURSES_H)
|
||||||
|
# include <ncurses/curses.h>
|
||||||
|
#elif defined(HAVE_CURSES_COLR_CURSES_H)
|
||||||
|
# include <varargs.h>
|
||||||
|
# include <curses_colr/curses.h>
|
||||||
#else
|
#else
|
||||||
# ifdef HAVE_NCURSES_CURSES_H
|
# include <curses.h>
|
||||||
# include <ncurses/curses.h>
|
# if (defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__)) && !defined(_maxx)
|
||||||
#else
|
# define _maxx maxx
|
||||||
# ifdef HAVE_CURSES_COLR_CURSES_H
|
# endif
|
||||||
# include <varargs.h>
|
# if (defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__)) && !defined(_maxy)
|
||||||
# include <curses_colr/curses.h>
|
# define _maxy maxy
|
||||||
# else
|
# endif
|
||||||
# include <curses.h>
|
# if (defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__)) && !defined(_begx)
|
||||||
# if (defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__)) && !defined(_maxx)
|
# define _begx begx
|
||||||
# define _maxx maxx
|
# endif
|
||||||
# endif
|
# if (defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__)) && !defined(_begy)
|
||||||
# if (defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__)) && !defined(_maxy)
|
# define _begy begy
|
||||||
# define _maxy maxy
|
|
||||||
# endif
|
|
||||||
# if (defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__)) && !defined(_begx)
|
|
||||||
# define _begx begx
|
|
||||||
# endif
|
|
||||||
# if (defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__)) && !defined(_begy)
|
|
||||||
# define _begy begy
|
|
||||||
# endif
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_INIT_COLOR
|
#ifdef HAVE_INIT_COLOR
|
||||||
@ -49,7 +45,7 @@
|
|||||||
# define USE_MOUSE 1
|
# define USE_MOUSE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "stdio.h"
|
#include <stdio.h>
|
||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
#include "rubyio.h"
|
#include "rubyio.h"
|
||||||
|
|
||||||
@ -78,12 +74,10 @@ no_window()
|
|||||||
rb_raise(rb_eRuntimeError, "already closed window");
|
rb_raise(rb_eRuntimeError, "already closed window");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define GetWINDOW(obj, winp) do {\
|
||||||
#define GetWINDOW(obj, winp) {\
|
|
||||||
Data_Get_Struct(obj, struct windata, winp);\
|
Data_Get_Struct(obj, struct windata, winp);\
|
||||||
if (winp->window == 0) no_window();\
|
if (winp->window == 0) no_window();\
|
||||||
}
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_window(winp)
|
free_window(winp)
|
||||||
@ -596,19 +590,19 @@ static void
|
|||||||
no_mevent()
|
no_mevent()
|
||||||
{
|
{
|
||||||
rb_raise(rb_eRuntimeError, "no such mouse event");
|
rb_raise(rb_eRuntimeError, "no such mouse event");
|
||||||
};
|
}
|
||||||
|
|
||||||
#define GetMOUSE(obj, data) {\
|
#define GetMOUSE(obj, data) do {\
|
||||||
Data_Get_Struct(obj, struct mousedata, data);\
|
Data_Get_Struct(obj, struct mousedata, data);\
|
||||||
if (data->mevent == 0) no_mevent();\
|
if (data->mevent == 0) no_mevent();\
|
||||||
}
|
} while (0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
curses_mousedata_free(struct mousedata *mdata)
|
curses_mousedata_free(struct mousedata *mdata)
|
||||||
{
|
{
|
||||||
if (mdata->mevent)
|
if (mdata->mevent)
|
||||||
free(mdata->mevent);
|
free(mdata->mevent);
|
||||||
};
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
curses_getmouse(VALUE obj)
|
curses_getmouse(VALUE obj)
|
||||||
@ -620,7 +614,7 @@ curses_getmouse(VALUE obj)
|
|||||||
0,curses_mousedata_free,mdata);
|
0,curses_mousedata_free,mdata);
|
||||||
mdata->mevent = (MEVENT*)malloc(sizeof(MEVENT));
|
mdata->mevent = (MEVENT*)malloc(sizeof(MEVENT));
|
||||||
return (getmouse(mdata->mevent) == OK) ? val : Qnil;
|
return (getmouse(mdata->mevent) == OK) ? val : Qnil;
|
||||||
};
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
curses_ungetmouse(VALUE obj, VALUE mevent)
|
curses_ungetmouse(VALUE obj, VALUE mevent)
|
||||||
@ -629,19 +623,19 @@ curses_ungetmouse(VALUE obj, VALUE mevent)
|
|||||||
|
|
||||||
GetMOUSE(mevent,mdata);
|
GetMOUSE(mevent,mdata);
|
||||||
return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse;
|
return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse;
|
||||||
};
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
curses_mouseinterval(VALUE obj, VALUE interval)
|
curses_mouseinterval(VALUE obj, VALUE interval)
|
||||||
{
|
{
|
||||||
return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse;
|
return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse;
|
||||||
};
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
curses_mousemask(VALUE obj, VALUE mask)
|
curses_mousemask(VALUE obj, VALUE mask)
|
||||||
{
|
{
|
||||||
return INT2NUM(mousemask(NUM2UINT(mask),NULL));
|
return INT2NUM(mousemask(NUM2UINT(mask),NULL));
|
||||||
};
|
}
|
||||||
|
|
||||||
#define DEFINE_MOUSE_GET_MEMBER(func_name,mem) \
|
#define DEFINE_MOUSE_GET_MEMBER(func_name,mem) \
|
||||||
static VALUE func_name (VALUE mouse) \
|
static VALUE func_name (VALUE mouse) \
|
||||||
@ -651,11 +645,11 @@ static VALUE func_name (VALUE mouse) \
|
|||||||
return (UINT2NUM(mdata->mevent -> mem)); \
|
return (UINT2NUM(mdata->mevent -> mem)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_MOUSE_GET_MEMBER(curs_mouse_id, id);
|
DEFINE_MOUSE_GET_MEMBER(curs_mouse_id, id)
|
||||||
DEFINE_MOUSE_GET_MEMBER(curs_mouse_x, x);
|
DEFINE_MOUSE_GET_MEMBER(curs_mouse_x, x)
|
||||||
DEFINE_MOUSE_GET_MEMBER(curs_mouse_y, y);
|
DEFINE_MOUSE_GET_MEMBER(curs_mouse_y, y)
|
||||||
DEFINE_MOUSE_GET_MEMBER(curs_mouse_z, z);
|
DEFINE_MOUSE_GET_MEMBER(curs_mouse_z, z)
|
||||||
DEFINE_MOUSE_GET_MEMBER(curs_mouse_bstate, bstate);
|
DEFINE_MOUSE_GET_MEMBER(curs_mouse_bstate, bstate)
|
||||||
#undef define_curs_mouse_member
|
#undef define_curs_mouse_member
|
||||||
#endif /* USE_MOUSE */
|
#endif /* USE_MOUSE */
|
||||||
|
|
||||||
@ -832,19 +826,19 @@ window_maxy(obj)
|
|||||||
VALUE obj;
|
VALUE obj;
|
||||||
{
|
{
|
||||||
struct windata *winp;
|
struct windata *winp;
|
||||||
int x, y;
|
|
||||||
|
|
||||||
GetWINDOW(obj, winp);
|
GetWINDOW(obj, winp);
|
||||||
#ifdef getmaxy
|
#if defined(getmaxy)
|
||||||
return INT2FIX(getmaxy(winp->window));
|
return INT2FIX(getmaxy(winp->window));
|
||||||
#else
|
#elif defined(getmaxyx)
|
||||||
#ifdef getmaxyx
|
{
|
||||||
getmaxyx(winp->window, y, x);
|
int x, y;
|
||||||
return INT2FIX(y);
|
getmaxyx(winp->window, y, x);
|
||||||
|
return INT2FIX(y);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return INT2FIX(winp->window->_maxy+1);
|
return INT2FIX(winp->window->_maxy+1);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* def maxx */
|
/* def maxx */
|
||||||
@ -853,19 +847,19 @@ window_maxx(obj)
|
|||||||
VALUE obj;
|
VALUE obj;
|
||||||
{
|
{
|
||||||
struct windata *winp;
|
struct windata *winp;
|
||||||
int x, y;
|
|
||||||
|
|
||||||
GetWINDOW(obj, winp);
|
GetWINDOW(obj, winp);
|
||||||
#ifdef getmaxx
|
#if defined(getmaxx)
|
||||||
return INT2FIX(getmaxx(winp->window));
|
return INT2FIX(getmaxx(winp->window));
|
||||||
#else
|
#elif defined(getmaxyx)
|
||||||
#ifdef getmaxyx
|
{
|
||||||
getmaxyx(winp->window, y, x);
|
int x, y;
|
||||||
return INT2FIX(x);
|
getmaxyx(winp->window, y, x);
|
||||||
|
return INT2FIX(x);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return INT2FIX(winp->window->_maxx+1);
|
return INT2FIX(winp->window->_maxx+1);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* def begy */
|
/* def begy */
|
||||||
@ -916,7 +910,7 @@ window_box(argc, argv, self)
|
|||||||
GetWINDOW(self, winp);
|
GetWINDOW(self, winp);
|
||||||
box(winp->window, NUM2CHR(vert), NUM2CHR(hor));
|
box(winp->window, NUM2CHR(vert), NUM2CHR(hor));
|
||||||
|
|
||||||
if( argc == 3 ){
|
if (!NIL_P(corn)) {
|
||||||
int cur_x, cur_y, x, y;
|
int cur_x, cur_y, x, y;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
@ -1096,7 +1090,6 @@ static VALUE
|
|||||||
window_idlok(VALUE obj, VALUE bf)
|
window_idlok(VALUE obj, VALUE bf)
|
||||||
{
|
{
|
||||||
struct windata *winp;
|
struct windata *winp;
|
||||||
int res;
|
|
||||||
|
|
||||||
GetWINDOW(obj, winp);
|
GetWINDOW(obj, winp);
|
||||||
idlok(winp->window, RTEST(bf) ? TRUE : FALSE);
|
idlok(winp->window, RTEST(bf) ? TRUE : FALSE);
|
||||||
@ -1113,7 +1106,7 @@ window_setscrreg(VALUE obj, VALUE top, VALUE bottom)
|
|||||||
res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom));
|
res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom));
|
||||||
/* may have to raise exception on ERR */
|
/* may have to raise exception on ERR */
|
||||||
return (res == OK) ? Qtrue : Qfalse;
|
return (res == OK) ? Qtrue : Qfalse;
|
||||||
};
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
window_scroll(VALUE obj)
|
window_scroll(VALUE obj)
|
||||||
@ -1142,7 +1135,7 @@ window_attroff(VALUE obj, VALUE attrs)
|
|||||||
|
|
||||||
GetWINDOW(obj,winp);
|
GetWINDOW(obj,winp);
|
||||||
return INT2FIX(wattroff(winp->window,NUM2INT(attrs)));
|
return INT2FIX(wattroff(winp->window,NUM2INT(attrs)));
|
||||||
};
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
window_attron(VALUE obj, VALUE attrs)
|
window_attron(VALUE obj, VALUE attrs)
|
||||||
@ -1159,8 +1152,8 @@ window_attron(VALUE obj, VALUE attrs)
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return val;
|
return val;
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
window_attrset(VALUE obj, VALUE attrs)
|
window_attrset(VALUE obj, VALUE attrs)
|
||||||
@ -1229,7 +1222,7 @@ window_keypad(VALUE obj, VALUE val)
|
|||||||
return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ?
|
return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ?
|
||||||
Qtrue : Qfalse;
|
Qtrue : Qfalse;
|
||||||
#endif
|
#endif
|
||||||
};
|
}
|
||||||
#endif /* HAVE_KEYPAD */
|
#endif /* HAVE_KEYPAD */
|
||||||
|
|
||||||
/*------------------------- Initialization -------------------------*/
|
/*------------------------- Initialization -------------------------*/
|
||||||
@ -1537,8 +1530,8 @@ Init_curses()
|
|||||||
rb_define_const(mCurses, c, INT2NUM(KEY_F(i)));
|
rb_define_const(mCurses, c, INT2NUM(KEY_F(i)));
|
||||||
sprintf(c, "F%d", i);
|
sprintf(c, "F%d", i);
|
||||||
rb_define_const(mKey, c, INT2NUM(KEY_F(i)));
|
rb_define_const(mKey, c, INT2NUM(KEY_F(i)));
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef KEY_DL
|
#ifdef KEY_DL
|
||||||
rb_curses_define_const(KEY_DL);
|
rb_curses_define_const(KEY_DL);
|
||||||
@ -1878,7 +1871,7 @@ Init_curses()
|
|||||||
for( c = 'A'; c <= 'Z'; c++ ){
|
for( c = 'A'; c <= 'Z'; c++ ){
|
||||||
sprintf(name, "KEY_CTRL_%c", c);
|
sprintf(name, "KEY_CTRL_%c", c);
|
||||||
rb_define_const(mCurses, name, INT2FIX(c - 'A' + 1));
|
rb_define_const(mCurses, name, INT2FIX(c - 'A' + 1));
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
#undef rb_curses_define_const
|
#undef rb_curses_define_const
|
||||||
|
|
||||||
|
@ -36,11 +36,11 @@ closed_dbm()
|
|||||||
rb_raise(rb_eRuntimeError, "closed GDBM file");
|
rb_raise(rb_eRuntimeError, "closed GDBM file");
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GetDBM(obj, dbmp) {\
|
#define GetDBM(obj, dbmp) do {\
|
||||||
Data_Get_Struct(obj, struct dbmdata, dbmp);\
|
Data_Get_Struct(obj, struct dbmdata, dbmp);\
|
||||||
if (dbmp == 0) closed_dbm();\
|
if (dbmp == 0) closed_dbm();\
|
||||||
if (dbmp->di_dbm == 0) closed_dbm();\
|
if (dbmp->di_dbm == 0) closed_dbm();\
|
||||||
}
|
} while (0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_dbm(dbmp)
|
free_dbm(dbmp)
|
||||||
@ -66,14 +66,12 @@ fgdbm_close(obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
fgdbm_s_new(argc, argv, klass)
|
fgdbm_s_alloc(klass)
|
||||||
int argc;
|
int argc;
|
||||||
VALUE *argv;
|
VALUE *argv;
|
||||||
VALUE klass;
|
VALUE klass;
|
||||||
{
|
{
|
||||||
VALUE obj = Data_Wrap_Struct(klass, 0, free_dbm, 0);
|
return Data_Wrap_Struct(klass, 0, free_dbm, 0);
|
||||||
rb_obj_call_init(obj, argc, argv);
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -125,6 +123,7 @@ fgdbm_initialize(argc, argv, obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbmp = ALLOC(struct dbmdata);
|
dbmp = ALLOC(struct dbmdata);
|
||||||
|
free_dbm(DATA_PTR(obj));
|
||||||
DATA_PTR(obj) = dbmp;
|
DATA_PTR(obj) = dbmp;
|
||||||
dbmp->di_dbm = dbm;
|
dbmp->di_dbm = dbm;
|
||||||
dbmp->di_size = -1;
|
dbmp->di_size = -1;
|
||||||
@ -924,7 +923,7 @@ Init_gdbm()
|
|||||||
rb_eGDBMFatalError = rb_define_class("GDBMFatalError", rb_eException);
|
rb_eGDBMFatalError = rb_define_class("GDBMFatalError", rb_eException);
|
||||||
rb_include_module(rb_cGDBM, rb_mEnumerable);
|
rb_include_module(rb_cGDBM, rb_mEnumerable);
|
||||||
|
|
||||||
rb_define_singleton_method(rb_cGDBM, "new", fgdbm_s_new, -1);
|
rb_define_singleton_method(rb_cGDBM, "allocate", fgdbm_s_alloc, 0);
|
||||||
rb_define_singleton_method(rb_cGDBM, "open", fgdbm_s_open, -1);
|
rb_define_singleton_method(rb_cGDBM, "open", fgdbm_s_open, -1);
|
||||||
|
|
||||||
rb_define_method(rb_cGDBM, "initialize", fgdbm_initialize, -1);
|
rb_define_method(rb_cGDBM, "initialize", fgdbm_initialize, -1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user