mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
gets speed up patch
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e8fea3f8dd
commit
5864923425
32 changed files with 837 additions and 976 deletions
21
ChangeLog
21
ChangeLog
|
@ -1,5 +1,26 @@
|
|||
Wed Mar 11 02:14:17 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* io.c (io_gets): handle normal case specially for speed.
|
||||
|
||||
* eval.c (rb_disable_super): function to disable superclass's
|
||||
method explicitly.
|
||||
|
||||
* eval.c (rb_eval): inherits previous method definition's
|
||||
NOEX_UNDEF-ness, if exists.
|
||||
|
||||
* class.c (rb_define_method): disables superclass's overriding
|
||||
method by default.
|
||||
|
||||
Tue Mar 10 00:03:24 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* ruby.c (load_file): understands multiple options in #! line.
|
||||
|
||||
* regex.c (re_compile_pattern): support for [:alpha:] etc.
|
||||
|
||||
Mon Mar 9 16:53:51 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* io.h (GetOpenFile): embed io_check_closed in GetOpenFile.
|
||||
|
||||
* sprintf.c (f_sprintf): zero padding failed for negative
|
||||
integers.
|
||||
|
||||
|
|
1
MANIFEST
1
MANIFEST
|
@ -142,6 +142,7 @@ missing/nt.c
|
|||
missing/nt.h
|
||||
missing/setenv.c
|
||||
missing/strcasecmp.c
|
||||
missing/strchr.c
|
||||
missing/strdup.c
|
||||
missing/strerror.c
|
||||
missing/strftime.c
|
||||
|
|
3
array.c
3
array.c
|
@ -1229,7 +1229,4 @@ Init_Array()
|
|||
rb_define_method(cArray, "nitems", ary_nitems, 0);
|
||||
|
||||
cmp = rb_intern("<=>");
|
||||
|
||||
/* turn on premitive flag for the class */
|
||||
FL_SET(cArray, FL_PRIMITIVE);
|
||||
}
|
||||
|
|
2
bignum.c
2
bignum.c
|
@ -1248,6 +1248,4 @@ Init_Bignum()
|
|||
rb_define_method(cBignum, "to_f", big_to_f, 0);
|
||||
rb_define_method(cBignum, "abs", big_abs, 0);
|
||||
rb_define_method(cBignum, "size", big_size, 0);
|
||||
|
||||
FL_SET(cBignum, FL_PRIMITIVE);
|
||||
}
|
||||
|
|
12
class.c
12
class.c
|
@ -98,9 +98,6 @@ rb_define_class_id(id, super)
|
|||
RBASIC(klass)->klass = singleton_class_new(RBASIC(super)->klass);
|
||||
singleton_class_attached(RBASIC(klass)->klass, klass);
|
||||
rb_funcall(super, rb_intern("inherited"), 1, klass);
|
||||
if (FL_TEST(super, FL_PRIMITIVE)) {
|
||||
FL_SET(klass, FL_PRIMITIVE);
|
||||
}
|
||||
|
||||
return klass;
|
||||
}
|
||||
|
@ -414,7 +411,7 @@ rb_define_method_id(klass, name, func, argc)
|
|||
VALUE (*func)();
|
||||
int argc;
|
||||
{
|
||||
rb_add_method(klass, name, NEW_CFUNC(func, argc), NOEX_PUBLIC);
|
||||
rb_add_method(klass, name, NEW_CFUNC(func,argc), NOEX_PUBLIC|NOEX_CFUNC);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -427,8 +424,8 @@ rb_define_method(klass, name, func, argc)
|
|||
ID id = rb_intern(name);
|
||||
|
||||
rb_add_method(klass, id, NEW_CFUNC(func, argc),
|
||||
(name[0] == 'i' && id == rb_intern("initialize"))?
|
||||
NOEX_PRIVATE:NOEX_PUBLIC);
|
||||
((name[0] == 'i' && id == rb_intern("initialize"))?
|
||||
NOEX_PRIVATE:NOEX_PUBLIC)|NOEX_CFUNC);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -438,7 +435,8 @@ rb_define_private_method(klass, name, func, argc)
|
|||
VALUE (*func)();
|
||||
int argc;
|
||||
{
|
||||
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PRIVATE);
|
||||
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc),
|
||||
NOEX_PRIVATE|NOEX_CFUNC);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
2
configure
vendored
2
configure
vendored
|
@ -2553,7 +2553,7 @@ echo "$ac_t""$ac_cv_func_memcmp_clean" 1>&6
|
|||
test $ac_cv_func_memcmp_clean = no && LIBOBJS="$LIBOBJS memcmp.o"
|
||||
|
||||
for ac_func in dup2 setenv memmove mkdir strcasecmp strerror strftime\
|
||||
strstr strtoul strdup crypt flock
|
||||
strchr strstr strtoul strdup crypt flock
|
||||
do
|
||||
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
|
||||
echo "configure:2560: checking for $ac_func" >&5
|
||||
|
|
|
@ -110,7 +110,7 @@ AC_FUNC_ALLOCA
|
|||
AC_FUNC_VFORK
|
||||
AC_FUNC_MEMCMP
|
||||
AC_REPLACE_FUNCS(dup2 setenv memmove mkdir strcasecmp strerror strftime\
|
||||
strstr strtoul strdup crypt flock)
|
||||
strchr strstr strtoul strdup crypt flock)
|
||||
AC_CHECK_FUNCS(fmod killpg random wait4 waitpid syscall getcwd\
|
||||
truncate chsize times utimes fcntl lockf setitimer\
|
||||
setruid seteuid setreuid setrgid setegid setregid\
|
||||
|
|
113
eval.c
113
eval.c
|
@ -35,8 +35,6 @@ char *strrchr();
|
|||
#endif
|
||||
#endif
|
||||
|
||||
extern VALUE cData;
|
||||
|
||||
VALUE cProc;
|
||||
static VALUE cBinding;
|
||||
static VALUE proc_call _((VALUE,VALUE));
|
||||
|
@ -106,20 +104,6 @@ rb_add_method(klass, mid, node, noex)
|
|||
st_insert(RCLASS(klass)->m_tbl, mid, body);
|
||||
}
|
||||
|
||||
void
|
||||
rb_remove_method(klass, mid)
|
||||
VALUE klass;
|
||||
ID mid;
|
||||
{
|
||||
NODE *body;
|
||||
|
||||
if (!st_delete(RCLASS(klass)->m_tbl, &mid, &body)) {
|
||||
NameError("method `%s' not defined in %s",
|
||||
rb_id2name(mid), rb_class2name(klass));
|
||||
}
|
||||
rb_clear_cache_by_id(mid);
|
||||
}
|
||||
|
||||
static NODE*
|
||||
search_method(klass, id, origin)
|
||||
VALUE klass, *origin;
|
||||
|
@ -206,6 +190,68 @@ rb_alias(klass, name, def)
|
|||
NEW_METHOD(NEW_FBODY(body, def, origin), orig->nd_noex));
|
||||
}
|
||||
|
||||
static void
|
||||
remove_method(klass, mid)
|
||||
VALUE klass;
|
||||
ID mid;
|
||||
{
|
||||
NODE *body;
|
||||
|
||||
if (!st_delete(RCLASS(klass)->m_tbl, &mid, &body)) {
|
||||
NameError("method `%s' not defined in %s",
|
||||
rb_id2name(mid), rb_class2name(klass));
|
||||
}
|
||||
rb_clear_cache_by_id(mid);
|
||||
}
|
||||
|
||||
void
|
||||
rb_remove_method(klass, name)
|
||||
VALUE klass;
|
||||
char *name;
|
||||
{
|
||||
remove_method(klass, rb_intern(name));
|
||||
}
|
||||
|
||||
void
|
||||
rb_disable_super(klass, name)
|
||||
VALUE klass;
|
||||
char *name;
|
||||
{
|
||||
VALUE origin;
|
||||
NODE *body;
|
||||
ID mid = rb_intern(name);
|
||||
|
||||
body = search_method(klass, mid, &origin);
|
||||
if (!body || !body->nd_body) {
|
||||
NameError("undefined method `%s' for `%s'",
|
||||
rb_id2name(mid), rb_class2name(klass));
|
||||
}
|
||||
if (origin == klass) {
|
||||
body->nd_noex |= NOEX_UNDEF;
|
||||
}
|
||||
else {
|
||||
rb_clear_cache_by_id(mid);
|
||||
rb_add_method(the_class, mid, 0, NOEX_UNDEF);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_enable_super(klass, name)
|
||||
VALUE klass;
|
||||
char *name;
|
||||
{
|
||||
VALUE origin;
|
||||
NODE *body;
|
||||
ID mid = rb_intern(name);
|
||||
|
||||
body = search_method(klass, mid, &origin);
|
||||
if (!body || !body->nd_body || origin != klass) {
|
||||
NameError("undefined method `%s' for `%s'",
|
||||
rb_id2name(mid), rb_class2name(klass));
|
||||
}
|
||||
body->nd_noex &= ~NOEX_UNDEF;
|
||||
}
|
||||
|
||||
static void
|
||||
rb_export_method(klass, name, noex)
|
||||
VALUE klass;
|
||||
|
@ -243,7 +289,7 @@ method_boundp(klass, id, ex)
|
|||
int noex;
|
||||
|
||||
if (rb_get_method_body(&klass, &id, &noex)) {
|
||||
if (ex && noex == NOEX_PRIVATE)
|
||||
if (ex && noex & NOEX_PRIVATE)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1083,7 +1129,7 @@ static VALUE
|
|||
mod_remove_method(mod, name)
|
||||
VALUE mod, name;
|
||||
{
|
||||
rb_remove_method(mod, rb_to_id(name));
|
||||
remove_method(mod, rb_to_id(name));
|
||||
return mod;
|
||||
}
|
||||
|
||||
|
@ -1818,6 +1864,10 @@ rb_eval(self, node)
|
|||
int argc; VALUE *argv; /* used in SETUP_ARGS */
|
||||
TMP_PROTECT;
|
||||
|
||||
if (the_frame->last_class == 0) {
|
||||
NameError("superclass method `%s' disabled",
|
||||
rb_id2name(the_frame->last_func));
|
||||
}
|
||||
if (nd_type(node) == NODE_ZSUPER) {
|
||||
argc = the_frame->argc;
|
||||
argv = the_frame->argv;
|
||||
|
@ -1830,7 +1880,7 @@ rb_eval(self, node)
|
|||
|
||||
PUSH_ITER(the_iter->iter?ITER_PRE:ITER_NOT);
|
||||
result = rb_call(RCLASS(the_frame->last_class)->super, self,
|
||||
the_frame->last_func, argc, argv, 1);
|
||||
the_frame->last_func, argc, argv, 3);
|
||||
POP_ITER();
|
||||
}
|
||||
break;
|
||||
|
@ -2157,6 +2207,9 @@ rb_eval(self, node)
|
|||
else {
|
||||
noex = NOEX_PUBLIC;
|
||||
}
|
||||
if (body && origin == the_class && body->nd_noex & NOEX_UNDEF) {
|
||||
noex |= NOEX_UNDEF;
|
||||
}
|
||||
rb_add_method(the_class, node->nd_mid, node->nd_defn, noex);
|
||||
if (FL_TEST(the_scope,SCOPE_MODFUNC)) {
|
||||
rb_add_method(rb_singleton_class(the_class),
|
||||
|
@ -2201,7 +2254,8 @@ rb_eval(self, node)
|
|||
Warning("redefine %s", rb_id2name(node->nd_mid));
|
||||
}
|
||||
rb_clear_cache_by_id(node->nd_mid);
|
||||
rb_add_method(klass, node->nd_mid, node->nd_defn, NOEX_PUBLIC);
|
||||
rb_add_method(klass, node->nd_mid, node->nd_defn,
|
||||
NOEX_PUBLIC|(body?body->nd_noex&NOEX_UNDEF:0));
|
||||
rb_funcall(recv, rb_intern("singleton_method_added"),
|
||||
1, INT2FIX(node->nd_mid));
|
||||
result = Qnil;
|
||||
|
@ -3084,13 +3138,13 @@ stack_length()
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_call0(klass, recv, id, argc, argv, scope, body)
|
||||
rb_call0(klass, recv, id, argc, argv, body, nosuper)
|
||||
VALUE klass, recv;
|
||||
ID id;
|
||||
int argc; /* OK */
|
||||
VALUE *argv; /* OK */
|
||||
int scope;
|
||||
NODE *body;
|
||||
int nosuper;
|
||||
{
|
||||
NODE *b2; /* OK */
|
||||
volatile VALUE result = Qnil;
|
||||
|
@ -3114,7 +3168,7 @@ rb_call0(klass, recv, id, argc, argv, scope, body)
|
|||
PUSH_ITER(itr);
|
||||
PUSH_FRAME();
|
||||
the_frame->last_func = id;
|
||||
the_frame->last_class = klass;
|
||||
the_frame->last_class = nosuper?0:klass;
|
||||
the_frame->argc = argc;
|
||||
the_frame->argv = argv;
|
||||
|
||||
|
@ -3393,14 +3447,17 @@ rb_call(klass, recv, mid, argc, argv, scope)
|
|||
body = ent->method;
|
||||
}
|
||||
else if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) {
|
||||
if (scope == 3) {
|
||||
NameError("super: no superclass method `%s'", rb_id2name(mid));
|
||||
}
|
||||
return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
|
||||
}
|
||||
|
||||
/* receiver specified form for private method */
|
||||
if (noex == NOEX_PRIVATE && scope == 0)
|
||||
if (noex & NOEX_PRIVATE && scope == 0)
|
||||
return rb_undefined(recv, mid, argc, argv, CSTAT_NOEX);
|
||||
|
||||
return rb_call0(klass, recv, id, argc, argv, scope, body);
|
||||
return rb_call0(klass, recv, id, argc, argv, body, noex & NOEX_UNDEF);
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
@ -4323,7 +4380,7 @@ Init_eval()
|
|||
rb_define_method(cModule, "private_class_method", mod_private_method, -1);
|
||||
rb_define_method(cModule, "module_eval", mod_module_eval, 1);
|
||||
|
||||
rb_define_method(cModule, "remove_method", mod_remove_method, -1);
|
||||
rb_define_method(cModule, "remove_method", mod_remove_method, 1);
|
||||
rb_define_method(cModule, "undef_method", mod_undef_method, 1);
|
||||
rb_define_method(cModule, "alias_method", mod_alias_method, 2);
|
||||
|
||||
|
@ -4761,7 +4818,7 @@ method_call(argc, argv, method)
|
|||
Data_Get_Struct(method, struct METHOD, data);
|
||||
PUSH_ITER(iterator_p()?ITER_PRE:ITER_NOT);
|
||||
result = rb_call0(data->klass, data->recv, data->id,
|
||||
argc, argv, 1, data->body);
|
||||
argc, argv, data->body, 0);
|
||||
POP_ITER();
|
||||
return result;
|
||||
}
|
||||
|
@ -4833,7 +4890,7 @@ Init_Proc()
|
|||
rb_define_global_function("proc", f_lambda, 0);
|
||||
rb_define_global_function("lambda", f_lambda, 0);
|
||||
rb_define_global_function("binding", f_binding, 0);
|
||||
cBinding = rb_define_class("Binding", cData);
|
||||
cBinding = rb_define_class("Binding", cObject);
|
||||
|
||||
cMethod = rb_define_class("Method", cObject);
|
||||
rb_undef_method(CLASS_OF(cMethod), "new");
|
||||
|
|
|
@ -239,6 +239,65 @@ fdbm_clear(obj)
|
|||
return obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
fdbm_invert(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
datum key, val;
|
||||
struct dbmdata *dbmp;
|
||||
DBM *dbm;
|
||||
VALUE keystr, valstr;
|
||||
VALUE hash = hash_new();
|
||||
|
||||
GetDBM(obj, dbmp);
|
||||
dbm = dbmp->di_dbm;
|
||||
for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) {
|
||||
val = dbm_fetch(dbm, key);
|
||||
keystr = str_taint(str_new(key.dptr, key.dsize));
|
||||
valstr = str_taint(str_new(val.dptr, val.dsize));
|
||||
hash_aset(hash, valstr, keystr);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
each_pair(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
return rb_funcall(obj, rb_intern("each_pair"), 0, 0);
|
||||
}
|
||||
|
||||
static VALUE fdbm_store _((VALUE,VALUE,VALUE));
|
||||
|
||||
static VALUE
|
||||
update_i(pair, dbm)
|
||||
VALUE pair, dbm;
|
||||
{
|
||||
Check_Type(pair, T_ARRAY);
|
||||
if (RARRAY(pair)->len < 2) {
|
||||
ArgError("pair must be [key, value]");
|
||||
}
|
||||
fdbm_store(dbm, RARRAY(pair)->ptr[0], RARRAY(pair)->ptr[1]);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
fdbm_update(obj, other)
|
||||
VALUE obj, other;
|
||||
{
|
||||
rb_iterate(each_pair, other, update_i, obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
fdbm_replace(obj, other)
|
||||
VALUE obj, other;
|
||||
{
|
||||
fdbm_clear(obj);
|
||||
rb_iterate(each_pair, other, update_i, obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
fdbm_store(obj, keystr, valstr)
|
||||
VALUE obj, keystr, valstr;
|
||||
|
@ -487,6 +546,7 @@ Init_dbm()
|
|||
rb_include_module(cDBM, mEnumerable);
|
||||
|
||||
rb_define_singleton_method(cDBM, "open", fdbm_s_open, -1);
|
||||
rb_define_singleton_method(cDBM, "new", fdbm_s_open, -1);
|
||||
rb_define_method(cDBM, "close", fdbm_close, 0);
|
||||
rb_define_method(cDBM, "[]", fdbm_fetch, 1);
|
||||
rb_define_method(cDBM, "[]=", fdbm_store, 2);
|
||||
|
@ -505,6 +565,10 @@ Init_dbm()
|
|||
rb_define_method(cDBM, "delete", fdbm_delete, 1);
|
||||
rb_define_method(cDBM, "delete_if", fdbm_delete_if, 0);
|
||||
rb_define_method(cDBM, "clear", fdbm_clear, 0);
|
||||
rb_define_method(cDBM,"invert", fdbm_invert, 0);
|
||||
rb_define_method(cDBM,"update", fdbm_update, 1);
|
||||
rb_define_method(cDBM,"replace", fdbm_replace, 1);
|
||||
|
||||
rb_define_method(cDBM, "include?", fdbm_has_key, 1);
|
||||
rb_define_method(cDBM, "has_key?", fdbm_has_key, 1);
|
||||
rb_define_method(cDBM, "has_value?", fdbm_has_value, 1);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#! /usr/local/bin/ruby
|
||||
|
||||
$".push 'mkmf.rb'
|
||||
$".push 'mkmf.rb' #"
|
||||
|
||||
if ARGV[0] == 'static'
|
||||
$force_static = TRUE
|
||||
|
|
1147
ext/gtk/gtk.c
1147
ext/gtk/gtk.c
File diff suppressed because it is too large
Load diff
|
@ -13,59 +13,59 @@ window.border_width(0)
|
|||
window.realize
|
||||
|
||||
toolbar = Gtk::Toolbar::new(Gtk::ORIENTATION_HORIZONTAL, Gtk::TOOLBAR_BOTH)
|
||||
toolbar.append_item "Horizontal", "Horizontal toolbar layout",
|
||||
toolbar.append_item "Horizontal", "Horizontal toolbar layout", "Toolbar/Horizontal",
|
||||
Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
|
||||
nil,
|
||||
#window.style.bg[Gtk::STATE_NORMAL],
|
||||
"test.xpm")), nil do
|
||||
toolbar.set_orientation Gtk::ORIENTATION_HORIZONTAL
|
||||
end
|
||||
toolbar.append_item "Vertival", "Vertical toolbar layout",
|
||||
toolbar.append_item "Vertival", "Vertical toolbar layout", "Toolbar/Vertical",
|
||||
Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
|
||||
nil, #window.style.bg[Gtk::STATE_NORMAL],
|
||||
"test.xpm")), nil do
|
||||
toolbar.set_orientation Gtk::ORIENTATION_VERTICAL
|
||||
end
|
||||
toolbar.append_space
|
||||
toolbar.append_item "Icons", "Only show toolbar icons",
|
||||
toolbar.append_item "Icons", "Only show toolbar icons", "Toolbar/IconsOnly",
|
||||
Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
|
||||
nil, #window.style.bg[Gtk::STATE_NORMAL],
|
||||
"test.xpm")), nil do
|
||||
toolbar.set_style Gtk::TOOLBAR_ICONS
|
||||
end
|
||||
toolbar.append_item "Text", "Only show toolbar text",
|
||||
toolbar.append_item "Text", "Only show toolbar text", "Toolbar/TextOnly",
|
||||
Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
|
||||
nil,#window.style.bg[Gtk::STATE_NORMAL],
|
||||
"test.xpm")), nil do
|
||||
toolbar.set_style Gtk::TOOLBAR_TEXT
|
||||
end
|
||||
toolbar.append_item "Both", "Show toolbar icons and text",
|
||||
toolbar.append_item "Both", "Show toolbar icons and text", "Toolbar/Both",
|
||||
Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
|
||||
nil, #window.style.bg[Gtk::STATE_NORMAL],
|
||||
"test.xpm")), nil do
|
||||
toolbar.set_style Gtk::TOOLBAR_BOTH
|
||||
end
|
||||
toolbar.append_space
|
||||
toolbar.append_item "Small", "User small spaces",
|
||||
toolbar.append_item "Small", "User small spaces", "Toolbar/Small",
|
||||
Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
|
||||
nil,#window.style.bg[Gtk::STATE_NORMAL],
|
||||
"test.xpm")), nil do
|
||||
toolbar.set_space_size 5
|
||||
end
|
||||
toolbar.append_item "Big", "User big spaces",
|
||||
toolbar.append_item "Big", "User big spaces", "Toolbar/Big",
|
||||
Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
|
||||
nil,#window.style.bg[Gtk::STATE_NORMAL],
|
||||
"test.xpm")), nil do
|
||||
toolbar.set_space_size 10
|
||||
end
|
||||
toolbar.append_space
|
||||
toolbar.append_item "Enable", "Enable tooltips",
|
||||
toolbar.append_item "Enable", "Enable tooltips",nil,
|
||||
Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
|
||||
nil,#window.style.bg[Gtk::STATE_NORMAL],
|
||||
"test.xpm")), nil do
|
||||
toolbar.set_tooltips TRUE
|
||||
end
|
||||
toolbar.append_item "Disable", "Disable tooltips",
|
||||
toolbar.append_item "Disable", "Disable tooltips",nil,
|
||||
Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
|
||||
nil,#window.style.bg[Gtk::STATE_NORMAL],
|
||||
"test.xpm")), nil do
|
||||
|
|
|
@ -17,11 +17,8 @@ def create_menu(depth)
|
|||
end
|
||||
menu.append menuitem
|
||||
menuitem.show
|
||||
if depth > 0
|
||||
unless submenu
|
||||
submenu = create_menu(depth - 1)
|
||||
end
|
||||
menuitem.set_submenu submenu
|
||||
if depth > 1
|
||||
menuitem.set_submenu create_menu(depth - 1)
|
||||
end
|
||||
end
|
||||
return menu
|
||||
|
@ -52,12 +49,12 @@ menubar.append menuitem
|
|||
menuitem.show
|
||||
|
||||
menuitem = Gtk::MenuItem::new("foo")
|
||||
menuitem.set_submenu menu
|
||||
menuitem.set_submenu create_menu(3)
|
||||
menubar.append menuitem
|
||||
menuitem.show
|
||||
|
||||
menuitem = Gtk::MenuItem::new("bar")
|
||||
menuitem.set_submenu menu
|
||||
menuitem.set_submenu create_menu(4)
|
||||
menubar.append menuitem
|
||||
menuitem.show
|
||||
|
||||
|
|
13
file.c
13
file.c
|
@ -186,7 +186,6 @@ file_tell(obj)
|
|||
long pos;
|
||||
|
||||
GetOpenFile(obj, fptr);
|
||||
io_check_closed(fptr);
|
||||
pos = ftell(fptr->f);
|
||||
if (ferror(fptr->f) != 0) rb_sys_fail(0);
|
||||
|
||||
|
@ -201,7 +200,6 @@ file_seek(obj, offset, ptrname)
|
|||
long pos;
|
||||
|
||||
GetOpenFile(obj, fptr);
|
||||
io_check_closed(fptr);
|
||||
pos = fseek(fptr->f, NUM2INT(offset), NUM2INT(ptrname));
|
||||
if (pos != 0) rb_sys_fail(0);
|
||||
clearerr(fptr->f);
|
||||
|
@ -217,7 +215,6 @@ file_set_pos(obj, offset)
|
|||
long pos;
|
||||
|
||||
GetOpenFile(obj, fptr);
|
||||
io_check_closed(fptr);
|
||||
pos = fseek(fptr->f, NUM2INT(offset), 0);
|
||||
if (pos != 0) rb_sys_fail(0);
|
||||
clearerr(fptr->f);
|
||||
|
@ -232,7 +229,6 @@ file_rewind(obj)
|
|||
OpenFile *fptr;
|
||||
|
||||
GetOpenFile(obj, fptr);
|
||||
io_check_closed(fptr);
|
||||
if (fseek(fptr->f, 0L, 0) != 0) rb_sys_fail(0);
|
||||
clearerr(fptr->f);
|
||||
|
||||
|
@ -246,7 +242,6 @@ file_eof(obj)
|
|||
OpenFile *fptr;
|
||||
|
||||
GetOpenFile(obj, fptr);
|
||||
io_check_closed(fptr);
|
||||
if (feof(fptr->f) == 0) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -376,7 +371,6 @@ file_lstat(obj)
|
|||
struct stat st;
|
||||
|
||||
GetOpenFile(obj, fptr);
|
||||
io_check_closed(fptr);
|
||||
if (lstat(fptr->path, &st) == -1) {
|
||||
rb_sys_fail(fptr->path);
|
||||
}
|
||||
|
@ -936,7 +930,6 @@ file_chmod(obj, vmode)
|
|||
|
||||
GetOpenFile(obj, fptr);
|
||||
#if defined(DJGPP) || defined(__CYGWIN32__) || defined(NT)
|
||||
io_check_closed(fptr);
|
||||
if (chmod(fptr->path, mode) == -1)
|
||||
rb_sys_fail(fptr->path);
|
||||
#else
|
||||
|
@ -996,7 +989,6 @@ file_chown(obj, owner, group)
|
|||
rb_secure(2);
|
||||
GetOpenFile(obj, fptr);
|
||||
#if defined(DJGPP) || defined(__CYGWIN32__) || defined(NT)
|
||||
io_check_closed(fptr);
|
||||
if (chown(fptr->path, NUM2INT(owner), NUM2INT(group)) == -1)
|
||||
rb_sys_fail(fptr->path);
|
||||
#else
|
||||
|
@ -1399,9 +1391,8 @@ file_truncate(obj, len)
|
|||
{
|
||||
OpenFile *fptr;
|
||||
|
||||
GetOpenFile(obj, fptr);
|
||||
|
||||
rb_secure(2);
|
||||
GetOpenFile(obj, fptr);
|
||||
if (!(fptr->mode & FMODE_WRITABLE)) {
|
||||
Fail("not opened for writing");
|
||||
}
|
||||
|
@ -1426,9 +1417,9 @@ file_flock(obj, operation)
|
|||
{
|
||||
OpenFile *fptr;
|
||||
|
||||
rb_secure(2);
|
||||
GetOpenFile(obj, fptr);
|
||||
|
||||
rb_secure(2);
|
||||
if (flock(fileno(fptr->f), NUM2INT(operation)) < 0) {
|
||||
#ifdef EWOULDBLOCK
|
||||
if (errno == EWOULDBLOCK) {
|
||||
|
|
3
gc.c
3
gc.c
|
@ -261,9 +261,6 @@ data_object_alloc(klass, datap, dmark, dfree)
|
|||
data->dfree = dfree;
|
||||
data->dmark = dmark;
|
||||
|
||||
/* turn on premitive flag for the class */
|
||||
FL_SET(klass, FL_PRIMITIVE);
|
||||
|
||||
return (VALUE)data;
|
||||
}
|
||||
|
||||
|
|
3
hash.c
3
hash.c
|
@ -1172,7 +1172,4 @@ Init_Hash()
|
|||
rb_define_singleton_method(envtbl,"value?", env_has_value, 1);
|
||||
|
||||
rb_define_global_const("ENV", envtbl);
|
||||
|
||||
/* turn on premitive flag for the class */
|
||||
FL_SET(cHash, FL_PRIMITIVE);
|
||||
}
|
||||
|
|
3
intern.h
3
intern.h
|
@ -93,6 +93,9 @@ void IndexError();
|
|||
void LoadError();
|
||||
#endif
|
||||
/* eval.c */
|
||||
void rb_remove_method _((VALUE, char *));
|
||||
void rb_disable_super _((VALUE, char *));
|
||||
void rb_enable_super _((VALUE, char *));
|
||||
void rb_clear_cache _((void));
|
||||
void rb_alias _((VALUE, ID, ID));
|
||||
int rb_method_boundp _((VALUE, ID, int));
|
||||
|
|
76
io.c
76
io.c
|
@ -119,7 +119,6 @@ void
|
|||
io_readable(fptr)
|
||||
OpenFile *fptr;
|
||||
{
|
||||
io_check_closed(fptr);
|
||||
if (!(fptr->mode & FMODE_READABLE)) {
|
||||
Raise(eIOError, "not opened for reading");
|
||||
}
|
||||
|
@ -129,7 +128,6 @@ void
|
|||
io_writable(fptr)
|
||||
OpenFile *fptr;
|
||||
{
|
||||
io_check_closed(fptr);
|
||||
if (!(fptr->mode & FMODE_WRITABLE)) {
|
||||
Raise(eIOError, "not opened for writing");
|
||||
}
|
||||
|
@ -370,16 +368,14 @@ io_gets_method(argc, argv, io)
|
|||
int rslen, rspara = 0;
|
||||
VALUE rs;
|
||||
|
||||
if (argc == 0) rs = RS;
|
||||
if (argc == 0) {
|
||||
return io_gets(io);
|
||||
}
|
||||
else {
|
||||
rb_scan_args(argc, argv, "1", &rs);
|
||||
if (!NIL_P(rs)) Check_Type(rs, T_STRING);
|
||||
}
|
||||
|
||||
GetOpenFile(io, fptr);
|
||||
io_readable(fptr);
|
||||
f = fptr->f;
|
||||
|
||||
if (!NIL_P(rs)) {
|
||||
rslen = RSTRING(rs)->len;
|
||||
if (rslen == 0) {
|
||||
|
@ -387,6 +383,9 @@ io_gets_method(argc, argv, io)
|
|||
rslen = 2;
|
||||
rspara = 1;
|
||||
}
|
||||
else if (rslen == 1 && RSTRING(rs)->ptr[0] == '\n') {
|
||||
return io_gets(io);
|
||||
}
|
||||
else {
|
||||
rsptr = RSTRING(rs)->ptr;
|
||||
}
|
||||
|
@ -397,6 +396,10 @@ io_gets_method(argc, argv, io)
|
|||
}
|
||||
newline = rslen ? rsptr[rslen - 1] : 0777;
|
||||
|
||||
GetOpenFile(io, fptr);
|
||||
io_readable(fptr);
|
||||
f = fptr->f;
|
||||
|
||||
if (rspara) {
|
||||
do {
|
||||
READ_CHECK(f);
|
||||
|
@ -488,7 +491,58 @@ VALUE
|
|||
io_gets(io)
|
||||
VALUE io;
|
||||
{
|
||||
return io_gets_method(0, 0, io);
|
||||
OpenFile *fptr;
|
||||
FILE *f;
|
||||
VALUE str = Qnil;
|
||||
int c;
|
||||
char buf[8192];
|
||||
char *bp, *bpe = buf + sizeof buf - 3;
|
||||
int cnt;
|
||||
int append = 0;
|
||||
|
||||
GetOpenFile(io, fptr);
|
||||
io_readable(fptr);
|
||||
f = fptr->f;
|
||||
|
||||
again:
|
||||
bp = buf;
|
||||
for (;;) {
|
||||
READ_CHECK(f);
|
||||
TRAP_BEG;
|
||||
c = getc(f);
|
||||
TRAP_END;
|
||||
if (c == EOF) break;
|
||||
if ((*bp++ = c) == '\n') break;
|
||||
if (bp == bpe) break;
|
||||
}
|
||||
cnt = bp - buf;
|
||||
|
||||
if (c == EOF) {
|
||||
if (!append && cnt == 0) {
|
||||
str = Qnil;
|
||||
goto return_gets;
|
||||
}
|
||||
}
|
||||
|
||||
if (append)
|
||||
str_cat(str, buf, cnt);
|
||||
else
|
||||
str = str_new(buf, cnt);
|
||||
|
||||
if (c != EOF && RSTRING(str)->ptr[RSTRING(str)->len-1] != '\n') {
|
||||
append = 1;
|
||||
goto again;
|
||||
}
|
||||
|
||||
return_gets:
|
||||
if (!NIL_P(str)) {
|
||||
fptr->lineno++;
|
||||
lineno = INT2FIX(fptr->lineno);
|
||||
str_taint(str);
|
||||
}
|
||||
lastline_set(str);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -616,7 +670,6 @@ io_isatty(io)
|
|||
OpenFile *fptr;
|
||||
|
||||
GetOpenFile(io, fptr);
|
||||
io_check_closed(fptr);
|
||||
if (isatty(fileno(fptr->f)) == 0)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
|
@ -1746,7 +1799,6 @@ f_select(argc, argv, obj)
|
|||
for (i=0; i<RARRAY(read)->len; i++) {
|
||||
Check_Type(RARRAY(read)->ptr[i], T_FILE);
|
||||
GetOpenFile(RARRAY(read)->ptr[i], fptr);
|
||||
io_check_closed(fptr);
|
||||
FD_SET(fileno(fptr->f), rp);
|
||||
if (READ_DATA_PENDING(fptr->f)) { /* check for buffered data */
|
||||
pending++;
|
||||
|
@ -1769,7 +1821,6 @@ f_select(argc, argv, obj)
|
|||
for (i=0; i<RARRAY(write)->len; i++) {
|
||||
Check_Type(RARRAY(write)->ptr[i], T_FILE);
|
||||
GetOpenFile(RARRAY(write)->ptr[i], fptr);
|
||||
io_check_closed(fptr);
|
||||
FD_SET(fileno(fptr->f), wp);
|
||||
if (max > fileno(fptr->f)) max = fileno(fptr->f);
|
||||
if (fptr->f2) {
|
||||
|
@ -1788,7 +1839,6 @@ f_select(argc, argv, obj)
|
|||
for (i=0; i<RARRAY(except)->len; i++) {
|
||||
Check_Type(RARRAY(except)->ptr[i], T_FILE);
|
||||
GetOpenFile(RARRAY(except)->ptr[i], fptr);
|
||||
io_check_closed(fptr);
|
||||
FD_SET(fileno(fptr->f), ep);
|
||||
if (max < fileno(fptr->f)) max = fileno(fptr->f);
|
||||
if (fptr->f2) {
|
||||
|
@ -2458,7 +2508,5 @@ Init_IO()
|
|||
atexit(pipe_atexit);
|
||||
#endif
|
||||
|
||||
/* turn on premitive flag for the class */
|
||||
FL_SET(cIO, FL_PRIMITIVE);
|
||||
Init_File();
|
||||
}
|
||||
|
|
2
io.h
2
io.h
|
@ -34,7 +34,7 @@ typedef struct OpenFile {
|
|||
#define FMODE_BINMODE 4
|
||||
#define FMODE_SYNC 8
|
||||
|
||||
#define GetOpenFile(obj,fp) ((fp) = RFILE(obj)->fptr)
|
||||
#define GetOpenFile(obj,fp) io_check_closed((fp) = RFILE(obj)->fptr)
|
||||
|
||||
#define MakeOpenFile(obj, fp) do {\
|
||||
fp = RFILE(obj)->fptr = ALLOC(OpenFile);\
|
||||
|
|
49
lib/date2.rb
49
lib/date2.rb
|
@ -192,52 +192,3 @@ class Date
|
|||
end
|
||||
|
||||
end
|
||||
[3 goodfriday.rb <text/plain; us-ascii (7bit)>]
|
||||
#! /usr/local/bin/ruby
|
||||
|
||||
# goodfriday.rb: Written by Tadayoshi Funaba 1998
|
||||
# $Id: goodfriday.rb,v 1.1 1998/03/08 09:44:44 tadf Exp $
|
||||
|
||||
require 'date'
|
||||
|
||||
def easter(y)
|
||||
g = (y % 19) + 1
|
||||
c = (y / 100) + 1
|
||||
x = (3 * c / 4) - 12
|
||||
z = ((8 * c + 5) / 25) - 5
|
||||
d = (5 * y / 4) - x - 10
|
||||
e = (11 * g + 20 + z - x) % 30
|
||||
e += 1 if e == 25 and g > 11 or e == 24
|
||||
n = 44 - e
|
||||
n += 30 if n < 21
|
||||
n = n + 7 - ((d + n) % 7)
|
||||
if n <= 31 then [y, 3, n] else [y, 4, n - 31] end
|
||||
end
|
||||
|
||||
es = Date.new3(*easter(Time.now.year))
|
||||
[[-9*7, 'Septuagesima Sunday'],
|
||||
[-8*7, 'Sexagesima Sunday'],
|
||||
[-7*7, 'Quinquagesima Sunday (Shrove Sunday)'],
|
||||
[-48, 'Shrove Monday'],
|
||||
[-47, 'Shrove Tuesday'],
|
||||
[-46, 'Ash Wednesday'],
|
||||
[-6*7, 'Quadragesima Sunday'],
|
||||
[-3*7, 'Mothering Sunday'],
|
||||
[-2*7, 'Passion Sunday'],
|
||||
[-7, 'Palm Sunday'],
|
||||
[-3, 'Maunday Thursday'],
|
||||
[-2, 'Good Friday'],
|
||||
[-1, 'Easter Eve'],
|
||||
[0, 'Easter Day'],
|
||||
[1, 'Easter Monday'],
|
||||
[7, 'Low Sunday'],
|
||||
[5*7, 'Rogation Sunday'],
|
||||
[39, 'Ascension Day (Holy Thursday)'],
|
||||
[42, 'Sunday after Ascension Day'],
|
||||
[7*7, 'Pentecost (Whitsunday)'],
|
||||
[50, 'Whitmonday'],
|
||||
[8*7, 'Trinity Sunday'],
|
||||
[60, 'Corpus Christi (Thursday after Trinity)']].
|
||||
each do |xs|
|
||||
puts ((es + xs.shift).to_s + ' ' + xs.shift)
|
||||
end
|
||||
|
|
|
@ -222,7 +222,7 @@ def create_makefile(target)
|
|||
end
|
||||
$libs = "" unless $libs
|
||||
|
||||
if !$objs then
|
||||
unless $objs then
|
||||
$objs = Dir["*.c"]
|
||||
for f in $objs
|
||||
f.sub!(/\.(c|cc)$/, ".o")
|
||||
|
|
|
@ -81,7 +81,6 @@ if __FILE__ == $0
|
|||
f = Tempfile.new("foo")
|
||||
f.print("foo\n")
|
||||
f.close
|
||||
f = nil
|
||||
f.open
|
||||
p f.gets # => "foo\n"
|
||||
f.close(true)
|
||||
|
|
45
missing/strchr.c
Normal file
45
missing/strchr.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* strchr --- search a string for a character
|
||||
*
|
||||
* We supply this routine for those systems that aren't standard yet.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
char *
|
||||
strchr(str, c)
|
||||
register const char *str, c;
|
||||
{
|
||||
if (c == '\0') {
|
||||
/* thanks to Mike Brennan ... */
|
||||
do {
|
||||
if (*str == c)
|
||||
return (char *) str;
|
||||
} while (*str++);
|
||||
} else {
|
||||
for (; *str; str++)
|
||||
if (*str == c)
|
||||
return (char *) str;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* strrchr --- find the last occurrence of a character in a string
|
||||
*
|
||||
* We supply this routine for those systems that aren't standard yet.
|
||||
*/
|
||||
|
||||
char *
|
||||
strrchr(str, c)
|
||||
register const char *str, c;
|
||||
{
|
||||
register const char *save = NULL;
|
||||
|
||||
for (; *str; str++)
|
||||
if (*str == c)
|
||||
save = str;
|
||||
|
||||
return (char *) save;
|
||||
}
|
3
node.h
3
node.h
|
@ -307,12 +307,13 @@ VALUE rb_method_booundp();
|
|||
|
||||
#define NOEX_PUBLIC 0
|
||||
#define NOEX_PRIVATE 1
|
||||
#define NOEX_UNDEF 2
|
||||
#define NOEX_CFUNC 2
|
||||
|
||||
NODE *compile_string _((char *, char *, int));
|
||||
NODE *compile_file _((char *, VALUE, int));
|
||||
|
||||
void rb_add_method _((VALUE, ID, NODE *, int));
|
||||
void rb_remove_method _((VALUE, ID));
|
||||
NODE *node_newnode();
|
||||
|
||||
enum node_type nodetype _((NODE *));
|
||||
|
|
|
@ -1145,7 +1145,6 @@ Init_Numeric()
|
|||
rb_define_method(cFixnum, "downto", fix_downto, 1);
|
||||
rb_define_method(cFixnum, "step", fix_step, 2);
|
||||
rb_define_method(cFixnum, "times", fix_dotimes, 0);
|
||||
FL_SET(cFixnum, FL_PRIMITIVE);
|
||||
|
||||
cFloat = rb_define_class("Float", cNumeric);
|
||||
|
||||
|
@ -1167,5 +1166,4 @@ Init_Numeric()
|
|||
rb_define_method(cFloat, "to_i", flo_to_i, 0);
|
||||
rb_define_method(cFloat, "to_f", flo_to_f, 0);
|
||||
rb_define_method(cFloat, "abs", flo_abs, 0);
|
||||
FL_SET(cFloat, FL_PRIMITIVE);
|
||||
}
|
||||
|
|
11
object.c
11
object.c
|
@ -369,17 +369,12 @@ VALUE
|
|||
obj_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
if (FL_TEST(klass, FL_PRIMITIVE)) {
|
||||
TypeError("allocating normal object for primitive class");
|
||||
}
|
||||
else {
|
||||
NEWOBJ(obj, struct RObject);
|
||||
OBJSETUP(obj, klass, T_OBJECT);
|
||||
obj->iv_tbl = 0;
|
||||
|
||||
return (VALUE)obj;
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
mod_clone(module)
|
||||
|
@ -825,9 +820,6 @@ Init_Object()
|
|||
rb_include_module(cObject, mKernel);
|
||||
rb_define_private_method(cClass, "inherited", obj_dummy, 1);
|
||||
|
||||
FL_SET(cModule, FL_PRIMITIVE);
|
||||
FL_SET(cClass, FL_PRIMITIVE);
|
||||
|
||||
/*
|
||||
* Ruby's Class Hierarchy Chart
|
||||
*
|
||||
|
@ -899,7 +891,6 @@ Init_Object()
|
|||
rb_define_method(cNilClass, "nil?", rb_true, 0);
|
||||
rb_undef_method(CLASS_OF(cNilClass), "new");
|
||||
rb_define_global_const("NIL", Qnil);
|
||||
FL_SET(cNilClass, FL_PRIMITIVE);
|
||||
|
||||
/* default addition */
|
||||
rb_define_method(cNilClass, "+", nil_plus, 1);
|
||||
|
@ -955,7 +946,6 @@ Init_Object()
|
|||
rb_define_method(cTrueClass, "type", true_type, 0);
|
||||
rb_undef_method(CLASS_OF(cTrueClass), "new");
|
||||
rb_define_global_const("TRUE", TRUE);
|
||||
FL_SET(cTrueClass, FL_PRIMITIVE);
|
||||
|
||||
cFalseClass = rb_define_class("FalseClass", cObject);
|
||||
rb_define_method(cFalseClass, "to_s", false_to_s, 0);
|
||||
|
@ -963,7 +953,6 @@ Init_Object()
|
|||
rb_define_method(cFalseClass, "type", false_type, 0);
|
||||
rb_undef_method(CLASS_OF(cFalseClass), "new");
|
||||
rb_define_global_const("FALSE", FALSE);
|
||||
FL_SET(cFalseClass, FL_PRIMITIVE);
|
||||
|
||||
eq = rb_intern("==");
|
||||
eql = rb_intern("eql?");
|
||||
|
|
5
re.c
5
re.c
|
@ -329,7 +329,6 @@ make_regexp(s, len, flag)
|
|||
return rp;
|
||||
}
|
||||
|
||||
extern VALUE cData;
|
||||
static VALUE cMatch;
|
||||
|
||||
static VALUE
|
||||
|
@ -1055,6 +1054,7 @@ Init_Regexp()
|
|||
| RE_INTERVALS
|
||||
| RE_NO_BK_BRACES
|
||||
| RE_CONTEXTUAL_INVALID_OPS
|
||||
| RE_CHAR_CLASSES
|
||||
| RE_BACKSLASH_ESCAPE_IN_LISTS);
|
||||
|
||||
rb_define_virtual_variable("$~", match_getter, match_setter);
|
||||
|
@ -1085,9 +1085,6 @@ Init_Regexp()
|
|||
rb_global_variable(®_cache);
|
||||
rb_global_variable(&matchcache);
|
||||
|
||||
/* turn on premitive flag for the class */
|
||||
FL_SET(cRegexp, FL_PRIMITIVE);
|
||||
|
||||
cMatch = rb_define_class("MatchingData", cData);
|
||||
rb_define_method(cMatch, "to_a", match_to_a, 0);
|
||||
rb_define_method(cMatch, "[]", match_aref, -1);
|
||||
|
|
96
regex.c
96
regex.c
|
@ -452,6 +452,17 @@ long re_syntax_options = 0;
|
|||
} \
|
||||
}
|
||||
|
||||
#define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
|
||||
|
||||
#define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
|
||||
|
||||
#define IS_CHAR_CLASS(string) \
|
||||
(STREQ (string, "alpha") || STREQ (string, "upper") \
|
||||
|| STREQ (string, "lower") || STREQ (string, "digit") \
|
||||
|| STREQ (string, "alnum") || STREQ (string, "xdigit") \
|
||||
|| STREQ (string, "space") || STREQ (string, "print") \
|
||||
|| STREQ (string, "punct") || STREQ (string, "graph") \
|
||||
|| STREQ (string, "cntrl") || STREQ (string, "blank"))
|
||||
|
||||
#define STORE_MBC(p, c) \
|
||||
((p)[0] = (unsigned char)(c >> 8), (p)[1] = (unsigned char)(c))
|
||||
|
@ -993,7 +1004,9 @@ re_compile_pattern(pattern, size, bufp)
|
|||
command. */
|
||||
|
||||
int regnum = 1;
|
||||
|
||||
int range = 0;
|
||||
int had_char_class = 0;
|
||||
|
||||
/* How to translate the characters in the pattern. */
|
||||
char *translate = bufp->translate;
|
||||
|
@ -1191,7 +1204,7 @@ re_compile_pattern(pattern, size, bufp)
|
|||
if ((re_syntax_options & RE_HAT_NOT_NEWLINE) && b[-2] == charset_not)
|
||||
SET_LIST_BIT('\n');
|
||||
|
||||
|
||||
had_char_class = 0;
|
||||
/* Read in characters and ranges, setting map bits. */
|
||||
for (;;)
|
||||
{
|
||||
|
@ -1221,6 +1234,10 @@ re_compile_pattern(pattern, size, bufp)
|
|||
expression. */
|
||||
break;
|
||||
}
|
||||
/* Look ahead to see if it's a range when the last thing
|
||||
was a character class. */
|
||||
if (had_char_class && c == '-' && *p != ']')
|
||||
goto invalid_pattern;
|
||||
if (ismbchar(c)) {
|
||||
PATFETCH(c1);
|
||||
c = c << BYTEWIDTH | c1;
|
||||
|
@ -1329,6 +1346,83 @@ re_compile_pattern(pattern, size, bufp)
|
|||
range = 1;
|
||||
goto range_retry;
|
||||
}
|
||||
else if ((re_syntax_options & RE_CHAR_CLASSES)
|
||||
&& c == '[' && *p == ':') {
|
||||
/* Leave room for the null. */
|
||||
char str[CHAR_CLASS_MAX_LENGTH + 1];
|
||||
|
||||
PATFETCH_RAW (c);
|
||||
c1 = 0;
|
||||
|
||||
/* If pattern is `[[:'. */
|
||||
if (p == pend)
|
||||
goto invalid_pattern;
|
||||
|
||||
for (;;) {
|
||||
PATFETCH (c);
|
||||
if (c == ':' || c == ']' || p == pend
|
||||
|| c1 == CHAR_CLASS_MAX_LENGTH)
|
||||
break;
|
||||
str[c1++] = c;
|
||||
}
|
||||
str[c1] = '\0';
|
||||
|
||||
/* If isn't a word bracketed by `[:' and:`]':
|
||||
undo the ending character, the letters, and leave
|
||||
the leading `:' and `[' (but set bits for them). */
|
||||
if (c == ':' && *p == ']') {
|
||||
int ch;
|
||||
char is_alnum = STREQ (str, "alnum");
|
||||
char is_alpha = STREQ (str, "alpha");
|
||||
char is_blank = STREQ (str, "blank");
|
||||
char is_cntrl = STREQ (str, "cntrl");
|
||||
char is_digit = STREQ (str, "digit");
|
||||
char is_graph = STREQ (str, "graph");
|
||||
char is_lower = STREQ (str, "lower");
|
||||
char is_print = STREQ (str, "print");
|
||||
char is_punct = STREQ (str, "punct");
|
||||
char is_space = STREQ (str, "space");
|
||||
char is_upper = STREQ (str, "upper");
|
||||
char is_xdigit = STREQ (str, "xdigit");
|
||||
|
||||
if (!IS_CHAR_CLASS (str))
|
||||
goto invalid_pattern;
|
||||
|
||||
/* Throw away the ] at the end of the character
|
||||
class. */
|
||||
PATFETCH (c);
|
||||
|
||||
if (p == pend)
|
||||
goto invalid_pattern;
|
||||
|
||||
|
||||
for (ch = 0; ch < 1 << BYTEWIDTH; ch++) {
|
||||
if ( (is_alnum && ISALNUM (ch))
|
||||
|| (is_alpha && ISALPHA (ch))
|
||||
|| (is_blank && ISBLANK (ch))
|
||||
|| (is_cntrl && ISCNTRL (ch))
|
||||
|| (is_digit && ISDIGIT (ch))
|
||||
|| (is_graph && ISGRAPH (ch))
|
||||
|| (is_lower && ISLOWER (ch))
|
||||
|| (is_print && ISPRINT (ch))
|
||||
|| (is_punct && ISPUNCT (ch))
|
||||
|| (is_space && ISSPACE (ch))
|
||||
|| (is_upper && ISUPPER (ch))
|
||||
|| (is_xdigit && ISXDIGIT (ch)))
|
||||
SET_LIST_BIT (ch);
|
||||
}
|
||||
had_char_class = 1;
|
||||
}
|
||||
else {
|
||||
c1++;
|
||||
while (c1--)
|
||||
PATUNFETCH;
|
||||
SET_LIST_BIT(translate?translate['[']:'[');
|
||||
SET_LIST_BIT(translate?translate[':']:':');
|
||||
had_char_class = 0;
|
||||
last = ':';
|
||||
}
|
||||
}
|
||||
else if (c < 1 << BYTEWIDTH)
|
||||
SET_LIST_BIT(c);
|
||||
else
|
||||
|
|
30
ruby.c
30
ruby.c
|
@ -422,6 +422,7 @@ proc_options(argcp, argvp)
|
|||
else {
|
||||
rb_gvar_set2(argv[0], TRUE);
|
||||
}
|
||||
argv[0][0] = '-';
|
||||
}
|
||||
*argcp = argc; *argvp = argv;
|
||||
}
|
||||
|
@ -448,6 +449,7 @@ load_file(fname, script)
|
|||
VALUE c;
|
||||
VALUE line;
|
||||
VALUE rs = RS;
|
||||
char *p;
|
||||
|
||||
RS = RS_default;
|
||||
if (xflag) {
|
||||
|
@ -458,7 +460,7 @@ load_file(fname, script)
|
|||
if (RSTRING(line)->len > 2
|
||||
&& RSTRING(line)->ptr[0] == '#'
|
||||
&& RSTRING(line)->ptr[1] == '!') {
|
||||
if (strstr(RSTRING(line)->ptr, "ruby")) {
|
||||
if (p = strstr(RSTRING(line)->ptr, "ruby")) {
|
||||
goto start_read;
|
||||
}
|
||||
}
|
||||
|
@ -475,8 +477,6 @@ load_file(fname, script)
|
|||
if (RSTRING(line)->len > 2
|
||||
&& RSTRING(line)->ptr[0] == '!') {
|
||||
|
||||
char *p;
|
||||
|
||||
if ((p = strstr(RSTRING(line)->ptr, "ruby")) == 0) {
|
||||
/* not ruby script, kick the program */
|
||||
char **argv;
|
||||
|
@ -509,19 +509,25 @@ load_file(fname, script)
|
|||
}
|
||||
|
||||
start_read:
|
||||
if (p = strstr(RSTRING(line)->ptr, "ruby -")) {
|
||||
int argc; char *argv[2]; char **argvp = argv;
|
||||
UCHAR *s;
|
||||
|
||||
s = RSTRING(line)->ptr;
|
||||
while (isspace(*s))
|
||||
s++;
|
||||
*s = '\0';
|
||||
p += 4;
|
||||
RSTRING(line)->ptr[RSTRING(line)->len-1] = '\0';
|
||||
if (RSTRING(line)->ptr[RSTRING(line)->len-2] == '\r')
|
||||
RSTRING(line)->ptr[RSTRING(line)->len-2] = '\0';
|
||||
argc = 2; argv[0] = 0; argv[1] = p + 5;
|
||||
if (p = strstr(p, " -")) {
|
||||
int argc; char *argv[2]; char **argvp = argv;
|
||||
UCHAR *s = ++p;
|
||||
|
||||
argc = 2; argv[0] = 0;
|
||||
while (*p == '-') {
|
||||
while (*s && !isspace(*s))
|
||||
s++;
|
||||
*s = '\0';
|
||||
argv[1] = p;
|
||||
proc_options(&argc, &argvp);
|
||||
p = ++s;
|
||||
while (*p && isspace(*p))
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
4
ruby.h
4
ruby.h
|
@ -250,6 +250,8 @@ struct RData {
|
|||
void *data;
|
||||
};
|
||||
|
||||
extern VALUE cData;
|
||||
|
||||
#define DATA_PTR(dta) (RDATA(dta)->data)
|
||||
|
||||
VALUE data_object_alloc _((VALUE,void*,void (*)(),void (*)()));
|
||||
|
@ -319,8 +321,6 @@ struct RBignum {
|
|||
#define FL_UNSET(x,f) if(FL_ABLE(x)){RBASIC(x)->flags &= ~(f);}
|
||||
#define FL_REVERSE(x,f) if(FL_ABLE(x)){RBASIC(x)->flags ^= f;}
|
||||
|
||||
#define FL_PRIMITIVE FL_USER1
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(RUBY_NO_INLINE)
|
||||
extern __inline__ int
|
||||
rb_type(VALUE obj)
|
||||
|
|
48
sample/goodfriday.rb
Normal file
48
sample/goodfriday.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
#! /usr/local/bin/ruby
|
||||
|
||||
# goodfriday.rb: Written by Tadayoshi Funaba 1998
|
||||
# $Id: goodfriday.rb,v 1.1 1998/03/08 09:44:44 tadf Exp $
|
||||
|
||||
require 'date2'
|
||||
|
||||
def easter(y)
|
||||
g = (y % 19) + 1
|
||||
c = (y / 100) + 1
|
||||
x = (3 * c / 4) - 12
|
||||
z = ((8 * c + 5) / 25) - 5
|
||||
d = (5 * y / 4) - x - 10
|
||||
e = (11 * g + 20 + z - x) % 30
|
||||
e += 1 if e == 25 and g > 11 or e == 24
|
||||
n = 44 - e
|
||||
n += 30 if n < 21
|
||||
n = n + 7 - ((d + n) % 7)
|
||||
if n <= 31 then [y, 3, n] else [y, 4, n - 31] end
|
||||
end
|
||||
|
||||
es = Date.new3(*easter(Time.now.year))
|
||||
[[-9*7, 'Septuagesima Sunday'],
|
||||
[-8*7, 'Sexagesima Sunday'],
|
||||
[-7*7, 'Quinquagesima Sunday (Shrove Sunday)'],
|
||||
[-48, 'Shrove Monday'],
|
||||
[-47, 'Shrove Tuesday'],
|
||||
[-46, 'Ash Wednesday'],
|
||||
[-6*7, 'Quadragesima Sunday'],
|
||||
[-3*7, 'Mothering Sunday'],
|
||||
[-2*7, 'Passion Sunday'],
|
||||
[-7, 'Palm Sunday'],
|
||||
[-3, 'Maunday Thursday'],
|
||||
[-2, 'Good Friday'],
|
||||
[-1, 'Easter Eve'],
|
||||
[0, 'Easter Day'],
|
||||
[1, 'Easter Monday'],
|
||||
[7, 'Low Sunday'],
|
||||
[5*7, 'Rogation Sunday'],
|
||||
[39, 'Ascension Day (Holy Thursday)'],
|
||||
[42, 'Sunday after Ascension Day'],
|
||||
[7*7, 'Pentecost (Whitsunday)'],
|
||||
[50, 'Whitmonday'],
|
||||
[8*7, 'Trinity Sunday'],
|
||||
[60, 'Corpus Christi (Thursday after Trinity)']].
|
||||
each do |xs|
|
||||
puts ((es + xs.shift).to_s + ' ' + xs.shift)
|
||||
end
|
3
string.c
3
string.c
|
@ -2516,7 +2516,4 @@ Init_String()
|
|||
rb_define_global_function("split", f_split, -1);
|
||||
|
||||
pr_str = rb_intern("to_s");
|
||||
|
||||
/* turn on premitive flag for the class */
|
||||
FL_SET(cString, FL_PRIMITIVE);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue