summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.in1
-rw-r--r--defines.h10
-rw-r--r--re.c35
-rw-r--r--regex.c29
4 files changed, 35 insertions, 40 deletions
diff --git a/Makefile.in b/Makefile.in
index c41f0c1..09ae22c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -206,6 +206,7 @@ process.o: process.c ruby.h config.h defines.h intern.h rubysig.h st.h
random.o: random.c ruby.h config.h defines.h intern.h
range.o: range.c ruby.h config.h defines.h intern.h
re.o: re.c ruby.h config.h defines.h intern.h re.h regex.h
+regex.o: regex.c config.h regex.h util.h
ruby.o: ruby.c ruby.h config.h defines.h intern.h dln.h
signal.o: signal.c ruby.h config.h defines.h intern.h rubysig.h
sprintf.o: sprintf.c ruby.h config.h defines.h intern.h
diff --git a/defines.h b/defines.h
index 0a3aae5..95a2b80 100644
--- a/defines.h
+++ b/defines.h
@@ -12,13 +12,13 @@
#define RUBY
-/* define EUC/SJIS for default kanji-code */
+/* define RUBY_USE_EUC/SJIS for default kanji-code */
#if defined(MSDOS) || defined(__CYGWIN32__) || defined(__human68k__) || defined(__MACOS__)
-#undef EUC
-#define SJIS
+#undef RUBY_USE_EUC
+#define RUBY_USE_SJIS
#else
-#define EUC
-#undef SJIS
+#define RUBY_USE_EUC
+#undef RUBY_USE_SJIS
#endif
#ifdef NeXT
diff --git a/re.c b/re.c
index 31dab7c..8e2f6ec 100644
--- a/re.c
+++ b/re.c
@@ -98,10 +98,10 @@ str_cicmp(str1, str2)
#define KCODE_MASK (KCODE_EUC|KCODE_SJIS)
static int reg_kcode =
-#ifdef EUC
+#ifdef RUBY_USE_EUC
KCODE_EUC;
#else
-# ifdef SJIS
+# ifdef RUBY_USE_SJIS
KCODE_SJIS;
# else
KCODE_NONE;
@@ -783,20 +783,16 @@ reg_s_new(argc, argv, self)
}
src = argv[0];
- switch (TYPE(src)) {
- case T_STRING:
- return reg_new_1(self, RSTRING(src)->ptr, RSTRING(src)->len, flag);
- break;
-
- case T_REGEXP:
+ if (TYPE(src) == T_REGEXP) {
return reg_new_1(self, RREGEXP(src)->str, RREGEXP(src)->len, flag);
- break;
-
- default:
- Check_Type(src, T_STRING);
}
+ else {
+ char *p;
+ int len;
- return Qnil; /* not reached */
+ p = str2cstr(src, &len);
+ return reg_new_1(self, p, len, flag);
+ }
}
static VALUE
@@ -992,8 +988,7 @@ static void
kcode_setter(val)
struct RString *val;
{
- Check_Type(val, T_STRING);
- rb_set_kcode(val->ptr);
+ rb_set_kcode(STR2CSTR(val));
}
static VALUE
@@ -1023,6 +1018,16 @@ Init_Regexp()
| RE_BACKSLASH_ESCAPE_IN_LISTS);
re_set_casetable(casetable);
+#ifdef RUBY_USE_EUC
+ mbcinit(MBCTYPE_EUC);
+#else
+#ifdef RUBY_USE_SJIS
+ mbcinit(MBCTYPE_SJIS);
+#else
+ mbcinit(MBCTYPE_ASCII);
+#endif
+#endif
+
rb_define_virtual_variable("$~", match_getter, match_setter);
rb_define_virtual_variable("$&", last_match_getter, 0);
rb_define_virtual_variable("$`", prematch_getter, 0);
diff --git a/regex.c b/regex.c
index 9f0707a..17212be 100644
--- a/regex.c
+++ b/regex.c
@@ -43,7 +43,6 @@
#endif
#include "config.h"
-#include "defines.h"
void *xmalloc P((unsigned long));
void *xcalloc P((unsigned long,unsigned long));
@@ -54,17 +53,17 @@ void free P((void*));
#ifndef NO_ALLOCA
/* Make alloca work the best possible way. */
#ifdef __GNUC__
-#ifndef atarist
-#ifndef alloca
-#define alloca __builtin_alloca
-#endif
-#endif /* atarist */
-#else
-#if defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
-#include <alloca.h>
+# ifndef atarist
+# ifndef alloca
+# define alloca __builtin_alloca
+# endif
+# endif /* atarist */
#else
+# if defined(HAVE_ALLOCA_H)
+# include <alloca.h>
+# else
char *alloca();
-#endif
+# endif
#endif /* __GNUC__ */
#ifdef _AIX
@@ -4120,18 +4119,8 @@ static const unsigned char mbctab_sjis[] = {
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
mbcinit(mbctype)