diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-03-09 07:57:00 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-03-09 07:57:00 +0000 |
commit | 2b6ab941234426b8891f1bad036fd75611038312 (patch) | |
tree | 22ae6172fcc75cb8073529cb7f2719b11f0cf036 | |
parent | 6a3fdf70f18a7b67808f23ddbd28e9631f7f905a (diff) |
1.1b9_00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | eval.c | 20 | ||||
-rw-r--r-- | ext/Setup | 2 | ||||
-rw-r--r-- | ext/curses/curses.c | 4 | ||||
-rw-r--r-- | parse.y | 8 | ||||
-rw-r--r-- | re.c | 29 | ||||
-rw-r--r-- | regex.c | 169 | ||||
-rw-r--r-- | regex.h | 44 | ||||
-rw-r--r-- | sprintf.c | 5 | ||||
-rw-r--r-- | string.c | 6 |
10 files changed, 221 insertions, 79 deletions
@@ -1,5 +1,18 @@ +Mon Mar 9 16:53:51 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + + * sprintf.c (f_sprintf): zero padding failed for negative + integers. + + * sprintf.c (remove_sign_bits): failed to remove some bits. + +Sat Mar 7 00:43:32 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + + * parse.y (logop): short cut syntax tree. + Fri Mar 6 17:23:07 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + * regex.c (mbcinit): table driven mbchar detection. + * object.c (obj_alloc): check for allocating instance for the primitive classes (mostly perfect). @@ -2165,8 +2165,8 @@ rb_eval(self, node) 1, INT2FIX(node->nd_mid)); } if (FL_TEST(the_class, FL_SINGLETON)) { - VALUE recv = rb_iv_get(the_class, "__attached__"); - rb_funcall(recv, rb_intern("singleton_method_added"), + rb_funcall(rb_iv_get(the_class, "__attached__"), + rb_intern("singleton_method_added"), 1, INT2FIX(node->nd_mid)); } else { @@ -2215,8 +2215,20 @@ rb_eval(self, node) body = search_method(the_class, node->nd_mid, &origin); if (!body || !body->nd_body) { - NameError("undefined method `%s' for class `%s'", - rb_id2name(node->nd_mid), rb_class2name(the_class)); + char *s0 = " class"; + VALUE klass = the_class; + + if (FL_TEST(the_class, FL_SINGLETON)) { + VALUE obj = rb_iv_get(the_class, "__attached__"); + switch (TYPE(obj)) { + case T_MODULE: + case T_CLASS: + klass = obj; + s0 = ""; + } + } + NameError("undefined method `%s' for%s `%s'", + rb_id2name(node->nd_mid),s0,rb_class2name(klass)); } rb_clear_cache_by_id(node->nd_mid); rb_add_method(the_class, node->nd_mid, 0, NOEX_PUBLIC); @@ -1,7 +1,7 @@ #option nodynamic #GD -curses +#curses #dbm #etc #fcntl diff --git a/ext/curses/curses.c b/ext/curses/curses.c index 127f51a0cb..c502d3faf6 100644 --- a/ext/curses/curses.c +++ b/ext/curses/curses.c @@ -109,9 +109,11 @@ curses_close_screen() static void curses_finalize() { + if (stdscr #ifdef HAVE_ISENDWIN - if (!isendwin()) + && !isendwin() #endif + ) endwin(); } @@ -3649,6 +3649,14 @@ logop(type, left, right) { value_expr(left); + switch (nd_type(left)) { + case NODE_NIL: /* always false */ + case NODE_FALSE: + return type == NODE_OR ? right : left; + case NODE_LIT: /* always true */ + return type == NODE_AND ? right : left; + } + return node_newnode(type, cond(left), cond(right)); } @@ -139,35 +139,33 @@ kcode_set_option(reg) { if (!FL_TEST(reg, KCODE_FIXED)) return; - re_syntax_options &= ~RE_MBCTYPE_MASK; switch ((RBASIC(reg)->flags & KCODE_MASK)) { case KCODE_NONE: + mbcinit(MBCTYPE_ASCII); break; case KCODE_EUC: - re_syntax_options |= RE_MBCTYPE_EUC; + mbcinit(MBCTYPE_EUC); break; case KCODE_SJIS: - re_syntax_options |= RE_MBCTYPE_SJIS; + mbcinit(MBCTYPE_EUC); break; } - re_set_syntax(re_syntax_options); } void kcode_reset_option() { - re_syntax_options &= ~RE_MBCTYPE_MASK; switch (reg_kcode) { case KCODE_NONE: + mbcinit(MBCTYPE_ASCII); break; case KCODE_EUC: - re_syntax_options |= RE_MBCTYPE_EUC; + mbcinit(MBCTYPE_EUC); break; case KCODE_SJIS: - re_syntax_options |= RE_MBCTYPE_SJIS; + mbcinit(MBCTYPE_SJIS); break; } - re_set_syntax(re_syntax_options); } extern int rb_in_eval; @@ -997,28 +995,29 @@ void rb_set_kcode(code) char *code; { - re_syntax_options &= ~RE_MBCTYPE_MASK; if (code == 0) goto set_no_conversion; switch (code[0]) { case 'E': case 'e': reg_kcode = KCODE_EUC; - re_syntax_options |= RE_MBCTYPE_EUC; + mbcinit(MBCTYPE_EUC); break; case 'S': case 's': reg_kcode = KCODE_SJIS; - re_syntax_options |= RE_MBCTYPE_SJIS; + mbcinit(MBCTYPE_SJIS); break; default: case 'N': case 'n': + case 'A': + case 'a': set_no_conversion: reg_kcode = KCODE_NONE; + mbcinit(MBCTYPE_ASCII); break; } - re_set_syntax(re_syntax_options); } static void @@ -1056,11 +1055,7 @@ Init_Regexp() | RE_INTERVALS | RE_NO_BK_BRACES | RE_CONTEXTUAL_INVALID_OPS - | RE_BACKSLASH_ESCAPE_IN_LISTS -#ifdef DEFAULT_MBCTYPE - | DEFAULT_MBCTYPE -#endif - ); + | RE_BACKSLASH_ESCAPE_IN_LISTS); rb_define_virtual_variable("$~", match_getter, match_setter); rb_define_virtual_variable("$&", last_match_getter, 0); @@ -73,7 +73,11 @@ char *alloca(); #endif #define RE_ALLOCATE alloca +#ifdef C_ALLOCA #define FREE_VARIABLES() alloca(0) +#else +#define FREE_VARIABLES() 0 +#endif #define FREE_AND_RETURN_VOID(stackb) return #define FREE_AND_RETURN(stackb,val) return(val) @@ -113,7 +117,7 @@ char *alloca(); stackp = stackx + (stackp - stackb); \ stackb = stackx; \ stacke = stackb + 2 * len; \ - } while (0); \ + } while (0) /* Get the interface, including the syntax bits. */ #include "regex.h" @@ -176,11 +180,43 @@ init_syntax_once() done = 1; } -/* Sequents are missing isgraph. */ -#ifndef isgraph -#define isgraph(c) (isprint((c)) && !isspace((c))) +/* Jim Meyering writes: + + "... Some ctype macros are valid only for character codes that + isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when + using /bin/cc or gcc but without giving an ansi option). So, all + ctype uses should be through macros like ISPRINT... If + STDC_HEADERS is defined, then autoconf has verified that the ctype + macros don't need to be guarded with references to isascii. ... + Defining isascii to 1 should let any compiler worth its salt + eliminate the && through constant folding." */ +#if ! defined (isascii) || defined (STDC_HEADERS) +#undef isascii +#define isascii(c) 1 +#endif + +#ifdef isblank +#define ISBLANK(c) (isascii (c) && isblank (c)) +#else +#define ISBLANK(c) ((c) == ' ' || (c) == '\t') +#endif +#ifdef isgraph +#define ISGRAPH(c) (isascii (c) && isgraph (c)) +#else +#define ISGRAPH(c) (isascii (c) && isprint (c) && !isspace (c)) #endif +#define ISPRINT(c) (isascii (c) && isprint (c)) +#define ISDIGIT(c) (isascii (c) && isdigit (c)) +#define ISALNUM(c) (isascii (c) && isalnum (c)) +#define ISALPHA(c) (isascii (c) && isalpha (c)) +#define ISCNTRL(c) (isascii (c) && iscntrl (c)) +#define ISLOWER(c) (isascii (c) && islower (c)) +#define ISPUNCT(c) (isascii (c) && ispunct (c)) +#define ISSPACE(c) (isascii (c) && isspace (c)) +#define ISUPPER(c) (isascii (c) && isupper (c)) +#define ISXDIGIT(c) (isascii (c) && isxdigit (c)) + /* These are the command codes that appear in compiled regular expressions, one per byte. Some command codes are followed by argument bytes. A command code can specify any interpretation @@ -328,7 +364,7 @@ re_set_syntax(syntax) } /* Set by re_set_syntax to the current regexp syntax to recognize. */ -long re_syntax_options = DEFAULT_MBCTYPE; +long re_syntax_options = 0; /* Macros for re_compile_pattern, which is found below these definitions. */ @@ -404,7 +440,7 @@ long re_syntax_options = DEFAULT_MBCTYPE; { if (p != pend) \ { \ PATFETCH(c); \ - while (isdigit(c)) \ + while (ISDIGIT(c)) \ { \ if (num < 0) \ num = 0; \ @@ -1205,7 +1241,7 @@ re_compile_pattern(pattern, size, bufp) for (c = 0; c < (1 << BYTEWIDTH); c++) if (SYNTAX(c) != Sword) SET_LIST_BIT(c); - if (re_syntax_options & RE_MBCTYPE_MASK) { + if (current_mbctype) { set_list_bits(0x8000, 0xffff, (unsigned char*)b); } last = -1; @@ -1213,16 +1249,16 @@ re_compile_pattern(pattern, size, bufp) case 's': for (c = 0; c < 256; c++) - if (isspace(c)) + if (ISSPACE(c)) SET_LIST_BIT(c); last = -1; continue; case 'S': for (c = 0; c < 256; c++) - if (!isspace(c)) + if (!ISSPACE(c)) SET_LIST_BIT(c); - if (re_syntax_options & RE_MBCTYPE_MASK) { + if (current_mbctype) { set_list_bits(0x8000, 0xffff, (unsigned char*)b); } last = -1; @@ -1236,9 +1272,9 @@ re_compile_pattern(pattern, size, bufp) case 'D': for (c = 0; c < 256; c++) - if (!isdigit(c)) + if (!ISDIGIT(c)) SET_LIST_BIT(c); - if (re_syntax_options & RE_MBCTYPE_MASK) { + if (current_mbctype) { set_list_bits(0x8000, 0xffff, (unsigned char*)b); } last = -1; @@ -1246,7 +1282,7 @@ re_compile_pattern(pattern, size, bufp) case 'x': c = scan_hex(p, 2, &numlen); - if ((re_syntax_options & RE_MBCTYPE_MASK) && c > 0x7f) + if (current_mbctype && c > 0x7f) c = 0xff00 | c; p += numlen; break; @@ -1255,8 +1291,8 @@ re_compile_pattern(pattern, size, bufp) case '5': case '6': case '7': case '8': case '9': PATUNFETCH; c = scan_oct(p, 3, &numlen); - if ((re_syntax_options & RE_MBCTYPE_MASK) && ismbchar(c)) - c = 0xff00 | c; + if (ismbchar(c)) + c |= 0xff00; p += numlen; break; @@ -1693,7 +1729,7 @@ re_compile_pattern(pattern, size, bufp) c1 = 0; c = scan_hex(p, 2, &numlen); p += numlen; - if ((re_syntax_options & RE_MBCTYPE_MASK) && c > 0x7f) + if (current_mbctype && c > 0x7f) c1 = 0xff; goto numeric_char; @@ -1702,7 +1738,7 @@ re_compile_pattern(pattern, size, bufp) c1 = 0; c = scan_oct(p, 3, &numlen); p += numlen; - if ((re_syntax_options & RE_MBCTYPE_MASK) && c > 0x7f) + if (current_mbctype && c > 0x7f) c1 = 0xff; goto numeric_char; @@ -1726,7 +1762,7 @@ re_compile_pattern(pattern, size, bufp) c = scan_oct(p_save, 3, &numlen); p = p_save + numlen; c1 = 0; - if ((re_syntax_options & RE_MBCTYPE_MASK) && c > 0x7f) + if (current_mbctype && c > 0x7f) c1 = 0xff; goto numeric_char; } @@ -3394,3 +3430,100 @@ re_free_registers(regs) if (regs->beg) free(regs->beg); if (regs->end) free(regs->end); } + +/* Functions for multi-byte support. + Created for grep multi-byte extension Jul., 1993 by t^2 (Takahiro Tanimoto) + Last change: Jul. 9, 1993 by t^2 */ +static const unsigned char mbctab_ascii[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +#ifdef EUC +const unsigned char *mbctab = mbctab_euc; +int current_mbctype = MBCTYPE_EUC; +#else +#ifdef SJIS +const unsigned char *mbctab = mbctab_sjis; +int current_mbctype = MBCTYPE_SJIS; +#else +const unsigned char *mbctab = mbctab_ascii; +int current_mbctype = MBCTYPE_ASCII; +#endif +#endif + +void +#ifdef __STDC__ +mbcinit(int mbctype) +#else +mbcinit(mbctype) + int mbctype; +#endif +{ + switch (mbctype) { + case MBCTYPE_ASCII: + mbctab = mbctab_ascii; + current_mbctype = MBCTYPE_ASCII; + break; + case MBCTYPE_EUC: + mbctab = mbctab_euc; + current_mbctype = MBCTYPE_EUC; + break; + case MBCTYPE_SJIS: + mbctab = mbctab_sjis; + current_mbctype = MBCTYPE_SJIS; + break; + } +} @@ -165,43 +165,17 @@ extern long re_syntax_options; | RE_NO_HYPHEN_RANGE_END) /* For multi-byte char support */ -#define RE_MBCTYPE_EUC (1L << 20) -#define RE_MBCTYPE_SJIS (1L << 21) -#define RE_MBCTYPE_MASK (RE_MBCTYPE_EUC | RE_MBCTYPE_SJIS) - -#ifdef EUC -#define DEFAULT_MBCTYPE RE_MBCTYPE_EUC -#else -#ifdef SJIS -#define DEFAULT_MBCTYPE RE_MBCTYPE_SJIS -#else -#define DEFAULT_MBCTYPE 0 -#endif -#endif +#define MBCTYPE_ASCII 0 +#define MBCTYPE_EUC 1 +#define MBCTYPE_SJIS 2 + +extern const unsigned char *mbctab; +extern int current_mbctype; + +void mbcinit (int); #undef ismbchar -#define ismbchar(c) \ - (re_syntax_options & RE_MBCTYPE_EUC \ - ? ( 0xa1 <= (unsigned char) (c) \ - && (unsigned char) (c) <= 0xfe) \ - : (re_syntax_options & RE_MBCTYPE_SJIS \ - ? (( 0x81 <= (unsigned char) (c) \ - && (unsigned char) (c) <= 0x9f) \ - || ((0xe0 <= (unsigned char) (c)) \ - && (unsigned char) (c) <= 0xef)) \ - : 0)) - -#undef ismbchar2 -#define ismbchar2(c) \ - (re_syntax_options & RE_MBCTYPE_EUC \ - ? ( 0xa1 <= (unsigned char) (c) \ - && (unsigned char) (c) <= 0xfe) \ - : (re_syntax_options & RE_MBCTYPE_SJIS \ - ? (( 0x40 <= (unsigned char) (c) \ - && (unsigned char) (c) <= 0x7e) \ - || ((0x80 <= (unsigned char) (c)) \ - && (unsigned char) (c) <= 0xfc)) \ - : 0)) +#define ismbchar(c) mbctab[(unsigned char)(c)] /* This data structure is used to represent a compiled pattern. */ @@ -28,10 +28,10 @@ remove_sign_bits(str, base) x_retry: switch (*t) { case 'c': - *t = '8'; + *t = '4'; break; case 'd': - *t = '9'; + *t = '5'; break; case 'e': *t = '2'; @@ -418,6 +418,7 @@ f_sprintf(argc, argv) int n = slen-len; char d = ' '; if (flags & FZERO) d = '0'; + if (s[0] == '.') d = '.'; CHECK(n); while (n--) { buf[blen++] = d; @@ -1375,11 +1375,15 @@ str_inspect(str) while (p < pend) { UCHAR c = *p++; - if (ismbchar(c) && p < pend && ismbchar2(*p)) { + if (ismbchar(c) && p < pend) { CHECK(2); *b++ = c; *b++ = *p++; } + if (c & 0x80) { + CHECK(1); + *b++ = c; + } else if (c == '"') { CHECK(2); *b++ = '\\'; |