1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1999-11-04 08:39:57 +00:00
parent 0d684beafb
commit a9e9697994
16 changed files with 2126 additions and 80 deletions

View file

@ -1,3 +1,21 @@
Wed Nov 3 08:52:57 1999 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
* io.c (Init_IO): forgot to use INT2FIX() around SEEK_SET, etc.
Wed Nov 3 00:25:20 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
* string.c (rb_str_split_method): use mbclen2() to handle kcode
option of regexp objects.
Mon Nov 1 14:22:15 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
* eval.c (rb_eval): reduce recursive calls to rb_eval()
case of ||= and &&= .
Sun Oct 31 13:12:42 1999 WATANABE Hirofumi <eban@os.rim.or.jp>
* regex.c (re_compile_pattern): wrong [\W] match.
Fri Oct 29 16:57:30 1999 Yukihiro Matsumoto <matz@netlab.co.jp> Fri Oct 29 16:57:30 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
* ext/nkf/lib/kconv.rb: new String methods (kconv, tojis, toeuc, * ext/nkf/lib/kconv.rb: new String methods (kconv, tojis, toeuc,

View file

@ -26,8 +26,11 @@
int sys_nerr = 256; int sys_nerr = 256;
#endif #endif
#if defined __CYGWIN__ && defined _sys_nerr #if defined __CYGWIN__
#define sys_nerr _sys_nerr # include <cygwin/version.h>
# if (CYGWIN_VERSION_API_MAJOR > 0) || (CYGWIN_VERSION_API_MINOR >= 8)
# define sys_nerr _sys_nerr
# endif
#endif #endif
int ruby_nerrs; int ruby_nerrs;
@ -442,7 +445,7 @@ static const syserr_index_entry syserr_index[]= {
static VALUE *syserr_list; static VALUE *syserr_list;
#endif #endif
#ifndef NT #if !defined NT && !defined sys_nerr
extern int sys_nerr; extern int sys_nerr;
#endif #endif

23
eval.c
View file

@ -1771,7 +1771,7 @@ rb_eval(self, node)
/* nodes for speed-up(literal match) */ /* nodes for speed-up(literal match) */
case NODE_MATCH2: case NODE_MATCH2:
result = rb_reg_match(rb_eval(self,node->nd_recv), result = rb_reg_match(rb_eval(self,node->nd_recv),
rb_eval(self,node->nd_value)); rb_eval(self,node->nd_value));
break; break;
/* nodes for speed-up(literal match) */ /* nodes for speed-up(literal match) */
@ -1841,7 +1841,12 @@ rb_eval(self, node)
{ {
VALUE val; VALUE val;
val = rb_eval(self, node->nd_head); if (node->nd_head) {
val = rb_eval(self, node->nd_head);
}
else {
val = Qtrue;
}
node = node->nd_body; node = node->nd_body;
while (node) { while (node) {
NODE *tag; NODE *tag;
@ -2334,17 +2339,15 @@ rb_eval(self, node)
case NODE_OP_ASGN_AND: case NODE_OP_ASGN_AND:
result = rb_eval(self, node->nd_head); result = rb_eval(self, node->nd_head);
if (RTEST(result)) { if (!RTEST(result)) break;
result = rb_eval(self, node->nd_value); node = node->nd_value;
} goto again;
break;
case NODE_OP_ASGN_OR: case NODE_OP_ASGN_OR:
result = rb_eval(self, node->nd_head); result = rb_eval(self, node->nd_head);
if (!RTEST(result)) { if (RTEST(result)) break;
result = rb_eval(self, node->nd_value); node = node->nd_value;
} goto again;
break;
case NODE_MASGN: case NODE_MASGN:
result = massign(self, node, rb_eval(self, node->nd_value),0); result = massign(self, node, rb_eval(self, node->nd_value),0);

View file

@ -72,12 +72,16 @@ fdbm_s_open(argc, argv, klass)
Check_SafeStr(file); Check_SafeStr(file);
dbm = 0; dbm = 0;
if (mode >= 0) if (mode >= 0) {
dbm = dbm_open(RSTRING(file)->ptr, O_RDWR|O_CREAT, mode); dbm = dbm_open(RSTRING(file)->ptr, O_RDWR|O_CREAT, mode);
if (!dbm) }
if (!dbm) {
mode = 0666;
dbm = dbm_open(RSTRING(file)->ptr, O_RDWR, mode); dbm = dbm_open(RSTRING(file)->ptr, O_RDWR, mode);
if (!dbm) }
if (!dbm) {
dbm = dbm_open(RSTRING(file)->ptr, O_RDONLY, mode); dbm = dbm_open(RSTRING(file)->ptr, O_RDONLY, mode);
}
if (!dbm) { if (!dbm) {
if (mode == -1) return Qnil; if (mode == -1) return Qnil;

View file

@ -21,6 +21,7 @@ def find_tcl(tcllib)
find_library(tcllib, func, *paths) find_library(tcllib, func, *paths)
else else
find_library("tcl", func, *paths) or find_library("tcl", func, *paths) or
find_library("tcl8.2", func, *paths) or
find_library("tcl8.0", func, *paths) or find_library("tcl8.0", func, *paths) or
find_library("tcl7.6", func, *paths) find_library("tcl7.6", func, *paths)
end end
@ -33,6 +34,7 @@ def find_tk(tklib)
find_library(tklib, func, *paths) find_library(tklib, func, *paths)
else else
find_library("tk", func, *paths) or find_library("tk", func, *paths) or
find_library("tk8.2", func, *paths) or
find_library("tk8.0", func, *paths) or find_library("tk8.0", func, *paths) or
find_library("tk4.2", func, *paths) find_library("tk4.2", func, *paths)
end end

View file

@ -667,7 +667,20 @@ class TkFont
alias measure_core measure_core_tk8x alias measure_core measure_core_tk8x
alias metrics_core metrics_core_tk8x alias metrics_core metrics_core_tk8x
when /^8\.1/ when /^8\.[12]/
alias create_latinfont create_latinfont_tk8x
alias create_kanjifont create_kanjifont_tk81
alias create_compoundfont create_compoundfont_tk81
alias actual_core actual_core_tk8x
alias configure_core configure_core_tk8x
alias configinfo_core configinfo_core_tk8x
alias delete_core delete_core_tk8x
alias latin_replace_core latin_replace_core_tk8x
alias kanji_replace_core kanji_replace_core_tk81
alias measure_core measure_core_tk8x
alias metrics_core metrics_core_tk8x
when /^8\.*/
alias create_latinfont create_latinfont_tk8x alias create_latinfont create_latinfont_tk8x
alias create_kanjifont create_kanjifont_tk81 alias create_kanjifont create_kanjifont_tk81
alias create_compoundfont create_compoundfont_tk81 alias create_compoundfont create_compoundfont_tk81

View file

@ -210,6 +210,12 @@ VALUE rb_Array _((VALUE));
/* parse.y */ /* parse.y */
extern int ruby_sourceline; extern int ruby_sourceline;
extern char *ruby_sourcefile; extern char *ruby_sourcefile;
#define yyparse rb_yyparse
#define yylex rb_yylex
#define yyerror rb_yyerror
#define yylval rb_yylval
#define yychar rb_yychar
#define yydebug rb_yydebug
int yyparse _((void)); int yyparse _((void));
ID rb_id_attrset _((ID)); ID rb_id_attrset _((ID));
void rb_parser_append_print _((void)); void rb_parser_append_print _((void));

6
io.c
View file

@ -3254,9 +3254,9 @@ Init_IO()
rb_define_method(rb_cIO, "flush", rb_io_flush, 0); rb_define_method(rb_cIO, "flush", rb_io_flush, 0);
rb_define_method(rb_cIO, "tell", rb_io_tell, 0); rb_define_method(rb_cIO, "tell", rb_io_tell, 0);
rb_define_method(rb_cIO, "seek", rb_io_seek, 2); rb_define_method(rb_cIO, "seek", rb_io_seek, 2);
rb_define_const(rb_cIO, "SEEK_SET", SEEK_SET); rb_define_const(rb_cIO, "SEEK_SET", INT2FIX(SEEK_SET));
rb_define_const(rb_cIO, "SEEK_CUR", SEEK_CUR); rb_define_const(rb_cIO, "SEEK_CUR", INT2FIX(SEEK_CUR));
rb_define_const(rb_cIO, "SEEK_END", SEEK_END); rb_define_const(rb_cIO, "SEEK_END", INT2FIX(SEEK_END));
rb_define_method(rb_cIO, "rewind", rb_io_rewind, 0); rb_define_method(rb_cIO, "rewind", rb_io_rewind, 0);
rb_define_method(rb_cIO, "pos", rb_io_tell, 0); rb_define_method(rb_cIO, "pos", rb_io_tell, 0);
rb_define_method(rb_cIO, "pos=", rb_io_set_pos, 1); rb_define_method(rb_cIO, "pos=", rb_io_set_pos, 1);

1949
lib/cgi.rb Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,58 +4,82 @@ $vsave, $VERBOSE = $VERBOSE, FALSE
class String class String
printf STDERR, "feel free for some warnings:\n" if $VERBOSE printf STDERR, "feel free for some warnings:\n" if $VERBOSE
def jlength PATTERN_SJIS = '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]'
self.split(//).length PATTERN_EUC = '[\xa1-\xfe][\xa1-\xfe]'
end PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]'
alias original_succ succ RE_SJIS = Regexp.new(PATTERN_SJIS, 'n')
private :original_succ RE_EUC = Regexp.new(PATTERN_EUC, 'n')
RE_UTF8 = Regexp.new(PATTERN_UTF8, 'n')
SUCC = {}
SUCC['s'] = Hash.new(1)
for i in 0 .. 0x3f
SUCC['s'][i.chr] = 0x40 - i
end
SUCC['s']["\x7e"] = 0x80 - 0x7e
SUCC['s']["\xfd"] = 0x100 - 0xfd
SUCC['s']["\xfe"] = 0x100 - 0xfe
SUCC['s']["\xff"] = 0x100 - 0xff
SUCC['e'] = Hash.new(1)
for i in 0 .. 0xa0
SUCC['e'][i.chr] = 0xa1 - i
end
SUCC['e']["\xfe"] = 2
SUCC['u'] = Hash.new(1)
for i in 0 .. 0x7f
SUCC['u'][i.chr] = 0x80 - i
end
SUCC['u']["\xbf"] = 0x100 - 0xbf
def mbchar? def mbchar?
case $KCODE[0] case $KCODE[0]
when ?s, ?S when ?s, ?S
self =~ /[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]/n self =~ RE_SJIS
when ?e, ?E when ?e, ?E
self =~ /[\xa1-\xfe][\xa1-\xfe]/n self =~ RE_EUC
when ?u, ?U
self =~ RE_UTF8
else else
false nil
end
end
def end_regexp
case $KCODE[0]
when ?s, ?S
/#{PATTERN_SJIS}$/o
when ?e, ?E
/#{PATTERN_EUC}$/o
when ?u, ?U
/#{PATTERN_UTF8}$/o
else
/.$/o
end
end
alias original_succ! succ!
private :original_succ!
alias original_succ succ
private :original_succ
def succ!
reg = end_regexp
if self =~ reg
succ_table = SUCC[$KCODE[0,1].downcase]
begin
self[-1] += succ_table[self[-1]]
self[-2] += 1 if self[-1] == 0
end while self !~ reg
self
else
original_succ!
end end
end end
def succ def succ
if self[-2] and self[-2, 2].mbchar? (str = self.dup).succ! or str
s = self.dup
s[-1] += 1
s[-1] += 1 unless s[-2, 2].mbchar?
return s
else
original_succ
end
end
def upto(to)
return if self > to
curr = self
tail = self[-2..-1]
if tail.length == 2 and tail =~ /^.$/ then
if self[0..-2] == to[0..-2]
first = self[-2].chr
for c in self[-1] .. to[-1]
if (first+c.chr).mbchar?
yield self[0..-2]+c.chr
end
end
end
else
loop do
yield curr
return if curr == to
curr = curr.succ
return if curr.length > to.length
end
end
return nil
end end
private private
@ -159,9 +183,24 @@ class String
(str = self.dup).chop! or str (str = self.dup).chop! or str
end end
def jlength
self.gsub(/[^\Wa-zA-Z_\d]/, ' ').length
end
alias jsize jlength
def jcount(str) def jcount(str)
self.delete("^#{str}").jlength self.delete("^#{str}").jlength
end end
def each_char
if iterator?
scan(/./) do |x|
yield x
end
else
scan(/./)
end
end
end end
$VERBOSE = $vsave $VERBOSE = $vsave

16
re.c
View file

@ -182,6 +182,21 @@ kcode_reset_option()
} }
} }
int
rb_mbclen2(c, re)
unsigned char c;
VALUE re;
{
int len;
if (!FL_TEST(re, KCODE_FIXED))
return mbclen(c);
kcode_set_option(re);
len = mbclen(c);
kcode_reset_option();
return len;
}
extern int ruby_in_compile; extern int ruby_in_compile;
static void static void
@ -538,6 +553,7 @@ rb_reg_search(reg, str, pos, reverse)
} }
result = re_search(RREGEXP(reg)->ptr,RSTRING(str)->ptr,RSTRING(str)->len, result = re_search(RREGEXP(reg)->ptr,RSTRING(str)->ptr,RSTRING(str)->len,
pos, range, regs); pos, range, regs);
if (FL_TEST(reg, KCODE_FIXED)) if (FL_TEST(reg, KCODE_FIXED))
kcode_reset_option(); kcode_reset_option();

3
re.h
View file

@ -36,4 +36,7 @@ VALUE rb_reg_regsub _((VALUE, VALUE, struct re_registers *));
int rb_kcode _((void)); int rb_kcode _((void));
extern int ruby_ignorecase; extern int ruby_ignorecase;
int rb_mbclen2 _((unsigned char, VALUE));
#define mbclen2(c,re) rb_mbclen2((c),(re))
#endif #endif

View file

@ -1406,7 +1406,8 @@ re_compile_pattern(pattern, size, bufp)
case 'W': case 'W':
for (c = 0; c < (1 << BYTEWIDTH); c++) { for (c = 0; c < (1 << BYTEWIDTH); c++) {
if (SYNTAX(c) != Sword && if (SYNTAX(c) != Sword &&
(current_mbctype || SYNTAX(c) != Sword2)) (current_mbctype && !re_mbctab[c] ||
!current_mbctype && SYNTAX(c) != Sword2))
SET_LIST_BIT(c); SET_LIST_BIT(c);
} }
last = -1; last = -1;

View file

@ -757,6 +757,7 @@ rb_str_upto(beg, end, excl)
int excl; int excl;
{ {
VALUE current; VALUE current;
ID succ = rb_intern("succ");
if (TYPE(end) != T_STRING) end = rb_str_to_str(end); if (TYPE(end) != T_STRING) end = rb_str_to_str(end);
@ -764,7 +765,7 @@ rb_str_upto(beg, end, excl)
while (rb_str_cmp(current, end) <= 0) { while (rb_str_cmp(current, end) <= 0) {
rb_yield(current); rb_yield(current);
if (!excl && rb_str_equal(current, end)) break; if (!excl && rb_str_equal(current, end)) break;
current = rb_str_succ(current); current = rb_funcall(current, succ, 0, 0);
if (excl && rb_str_equal(current, end)) break; if (excl && rb_str_equal(current, end)) break;
if (RSTRING(current)->len > RSTRING(end)->len) if (RSTRING(current)->len > RSTRING(end)->len)
break; break;
@ -1110,7 +1111,7 @@ rb_str_gsub_bang(argc, argv, str)
* Always consume at least one character of the input string * Always consume at least one character of the input string
* in order to prevent infinite loops. * in order to prevent infinite loops.
*/ */
len = mbclen(RSTRING(str)->ptr[END(0)]); len = mbclen2(RSTRING(str)->ptr[END(0)], pat);
if (RSTRING(str)->len > END(0)) { if (RSTRING(str)->len > END(0)) {
memcpy(bp, RSTRING(str)->ptr+END(0), len); memcpy(bp, RSTRING(str)->ptr+END(0), len);
bp += len; bp += len;
@ -1342,12 +1343,6 @@ rb_str_inspect(str)
*b++ = *p++; *b++ = *p++;
} }
} }
#if 0
else if ((c & 0x80) && rb_kcode() != MBCTYPE_EUC) {
CHECK(1);
*b++ = c;
}
#endif
else if (c == '"'|| c == '\\') { else if (c == '"'|| c == '\\') {
CHECK(2); CHECK(2);
*b++ = '\\'; *b++ = '\\';
@ -2074,11 +2069,11 @@ rb_str_split_method(argc, argv, str)
regs = RMATCH(rb_backref_get())->regs; regs = RMATCH(rb_backref_get())->regs;
if (start == end && BEG(0) == END(0)) { if (start == end && BEG(0) == END(0)) {
if (last_null == 1) { if (last_null == 1) {
rb_ary_push(result, rb_str_substr(str, beg, mbclen(RSTRING(str)->ptr[beg]))); rb_ary_push(result, rb_str_substr(str, beg, mbclen2(RSTRING(str)->ptr[beg],spat)));
beg = start; beg = start;
} }
else { else {
start += mbclen(RSTRING(str)->ptr[start]); start += mbclen2(RSTRING(str)->ptr[start],spat);
last_null = 1; last_null = 1;
continue; continue;
} }
@ -2384,7 +2379,7 @@ scan_once(str, pat, start)
/* /*
* Always consume at least one character of the input string * Always consume at least one character of the input string
*/ */
*start = END(0)+mbclen(RSTRING(str)->ptr[END(0)]); *start = END(0)+mbclen2(RSTRING(str)->ptr[END(0)],pat);
} }
else { else {
*start = END(0); *start = END(0);

View file

@ -19,7 +19,7 @@ LDFLAGS = $(CFLAGS) -Fm
XLDFLAGS = XLDFLAGS =
#EXTLIBS = #EXTLIBS =
LIBS = advapi32.lib wsock32.lib $(EXTLIBS) LIBS = advapi32.lib wsock32.lib $(EXTLIBS)
MISSING = crypt.obj alloca.obj win32.obj fnmatch.obj isinf.obj isnan.obj MISSING = crypt.obj alloca.obj win32.obj isinf.obj isnan.obj
LDSHARED = LDSHARED =
DLDFLAGS = DLDFLAGS =
SOLIBS = SOLIBS =
@ -166,9 +166,6 @@ isinf.obj: missing/isinf.c
isnan.obj: missing/isnan.c isnan.obj: missing/isnan.c
$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c missing/isnan.c $(CC) -I. $(CFLAGS) $(CPPFLAGS) -c missing/isnan.c
fnmatch.obj: missing/fnmatch.c
$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c missing/fnmatch.c
memcmp.obj: missing/memcmp.c memcmp.obj: missing/memcmp.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c missing/memcmp.c $(CC) $(CFLAGS) $(CPPFLAGS) -c missing/memcmp.c

View file

@ -99,8 +99,6 @@ EXPORTS
definekey definekey
encrypt encrypt
crypt crypt
;missing/fnmatch.c
fnmatch
;missing/isinf.c ;missing/isinf.c
isinf isinf
;missing/isnan.c ;missing/isnan.c
@ -452,7 +450,6 @@ EXPORTS
rb_get_kcode rb_get_kcode
rb_set_kcode rb_set_kcode
;ruby.c ;ruby.c
ruby_require_libraries
rb_load_file rb_load_file
ruby_script ruby_script
ruby_prog_init ruby_prog_init