summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
Diffstat (limited to 're.c')
-rw-r--r--re.c285
1 files changed, 84 insertions, 201 deletions
diff --git a/re.c b/re.c
index ccc97e3689..bd76e17f7c 100644
--- a/re.c
+++ b/re.c
@@ -76,9 +76,7 @@ static const char casetable[] = {
#endif
int
-rb_memcicmp(p1, p2, len)
- char *p1, *p2;
- long len;
+rb_memcicmp(char *p1, char *p2, long len)
{
int tmp;
@@ -90,9 +88,7 @@ rb_memcicmp(p1, p2, len)
}
int
-rb_memcmp(p1, p2, len)
- char *p1, *p2;
- long len;
+rb_memcmp(char *p1, char *p2, long len)
{
if (!ruby_ignorecase) {
return memcmp(p1, p2, len);
@@ -101,9 +97,7 @@ rb_memcmp(p1, p2, len)
}
long
-rb_memsearch(x0, m, y0, n)
- char *x0, *y0;
- long m, n;
+rb_memsearch(char *x0, long m, char *y0, long n)
{
unsigned char *x = (unsigned char *)x0, *y = (unsigned char *)y0;
unsigned char *s, *e;
@@ -168,8 +162,7 @@ rb_memsearch(x0, m, y0, n)
static int reg_kcode = DEFAULT_KCODE;
static void
-kcode_euc(re)
- struct RRegexp *re;
+kcode_euc(struct RRegexp *re)
{
FL_UNSET(re, KCODE_MASK);
FL_SET(re, KCODE_EUC);
@@ -177,8 +170,7 @@ kcode_euc(re)
}
static void
-kcode_sjis(re)
- struct RRegexp *re;
+kcode_sjis(struct RRegexp *re)
{
FL_UNSET(re, KCODE_MASK);
FL_SET(re, KCODE_SJIS);
@@ -186,8 +178,7 @@ kcode_sjis(re)
}
static void
-kcode_utf8(re)
- struct RRegexp *re;
+kcode_utf8(struct RRegexp *re)
{
FL_UNSET(re, KCODE_MASK);
FL_SET(re, KCODE_UTF8);
@@ -195,8 +186,7 @@ kcode_utf8(re)
}
static void
-kcode_none(re)
- struct RRegexp *re;
+kcode_none(struct RRegexp *re)
{
FL_UNSET(re, KCODE_MASK);
FL_SET(re, KCODE_FIXED);
@@ -205,8 +195,7 @@ kcode_none(re)
static int curr_kcode;
static void
-kcode_set_option(re)
- VALUE re;
+kcode_set_option(VALUE re)
{
if (!FL_TEST(re, KCODE_FIXED)) return;
@@ -229,7 +218,7 @@ kcode_set_option(re)
}
static void
-kcode_reset_option()
+kcode_reset_option(void)
{
if (reg_kcode == curr_kcode) return;
switch (reg_kcode) {
@@ -249,9 +238,7 @@ kcode_reset_option()
}
int
-rb_reg_mbclen2(c, re)
- unsigned int c;
- VALUE re;
+rb_reg_mbclen2(unsigned int c, VALUE re)
{
int len;
unsigned char uc = (unsigned char)c;
@@ -265,8 +252,7 @@ rb_reg_mbclen2(c, re)
}
static void
-rb_reg_check(re)
- VALUE re;
+rb_reg_check(VALUE re)
{
if (!RREGEXP(re)->ptr || !RREGEXP(re)->str) {
rb_raise(rb_eTypeError, "uninitialized Regexp");
@@ -274,10 +260,7 @@ rb_reg_check(re)
}
static void
-rb_reg_expr_str(str, s, len)
- VALUE str;
- const char *s;
- long len;
+rb_reg_expr_str(VALUE str, const char *s, long len)
{
const char *p, *pend;
int need_escape = 0;
@@ -330,10 +313,7 @@ rb_reg_expr_str(str, s, len)
}
static VALUE
-rb_reg_desc(s, len, re)
- const char *s;
- long len;
- VALUE re;
+rb_reg_desc(const char *s, long len, VALUE re)
{
VALUE str = rb_str_buf_new2("/");
@@ -380,8 +360,7 @@ rb_reg_desc(s, len, re)
*/
static VALUE
-rb_reg_source(re)
- VALUE re;
+rb_reg_source(VALUE re)
{
VALUE str;
@@ -403,8 +382,7 @@ rb_reg_source(re)
*/
static VALUE
-rb_reg_inspect(re)
- VALUE re;
+rb_reg_inspect(VALUE re)
{
rb_reg_check(re);
return rb_reg_desc(RREGEXP(re)->str, RREGEXP(re)->len, re);
@@ -432,8 +410,7 @@ rb_reg_inspect(re)
*/
static VALUE
-rb_reg_to_s(re)
- VALUE re;
+rb_reg_to_s(VALUE re)
{
int options;
const int embeddable = ONIG_OPTION_MULTILINE|ONIG_OPTION_IGNORECASE|ONIG_OPTION_EXTEND;
@@ -530,12 +507,7 @@ rb_reg_to_s(re)
}
static void
-rb_reg_raise(s, len, err, re, ce)
- const char *s;
- long len;
- const char *err;
- VALUE re;
- int ce;
+rb_reg_raise(const char *s, long len, const char *err, VALUE re, int ce)
{
VALUE desc = rb_reg_desc(s, len, re);
@@ -554,8 +526,7 @@ rb_reg_raise(s, len, err, re, ce)
*/
static VALUE
-rb_reg_casefold_p(re)
- VALUE re;
+rb_reg_casefold_p(VALUE re)
{
rb_reg_check(re);
if (RREGEXP(re)->ptr->options & ONIG_OPTION_IGNORECASE) return Qtrue;
@@ -587,8 +558,7 @@ rb_reg_casefold_p(re)
*/
static VALUE
-rb_reg_options_m(re)
- VALUE re;
+rb_reg_options_m(VALUE re)
{
int options = rb_reg_options(re);
return INT2NUM(options);
@@ -603,8 +573,7 @@ rb_reg_options_m(re)
*/
static VALUE
-rb_reg_kcode_m(re)
- VALUE re;
+rb_reg_kcode_m(VALUE re)
{
char *kcode;
@@ -628,11 +597,7 @@ rb_reg_kcode_m(re)
}
static Regexp*
-make_regexp(s, len, flags, ce)
- const char *s;
- long len;
- int flags;
- int ce;
+make_regexp(const char *s, long len, int flags, int ce)
{
Regexp *rp;
char err[ONIG_MAX_ERROR_MESSAGE_LEN];
@@ -682,10 +647,8 @@ make_regexp(s, len, flags, ce)
static VALUE rb_cMatch;
-static VALUE match_alloc _((VALUE));
static VALUE
-match_alloc(klass)
- VALUE klass;
+match_alloc(VALUE klass)
{
NEWOBJ(match, struct RMatch);
OBJSETUP(match, klass, T_MATCH);
@@ -700,8 +663,7 @@ match_alloc(klass)
/* :nodoc: */
static VALUE
-match_init_copy(obj, orig)
- VALUE obj, orig;
+match_init_copy(VALUE obj, VALUE orig)
{
if (obj == orig) return obj;
@@ -730,8 +692,7 @@ match_init_copy(obj, orig)
*/
static VALUE
-match_size(match)
- VALUE match;
+match_size(VALUE match)
{
return INT2FIX(RMATCH(match)->regs->num_regs);
}
@@ -750,8 +711,7 @@ match_size(match)
*/
static VALUE
-match_offset(match, n)
- VALUE match, n;
+match_offset(VALUE match, VALUE n)
{
int i = NUM2INT(n);
@@ -779,8 +739,7 @@ match_offset(match, n)
*/
static VALUE
-match_begin(match, n)
- VALUE match, n;
+match_begin(VALUE match, VALUE n)
{
int i = NUM2INT(n);
@@ -807,8 +766,7 @@ match_begin(match, n)
*/
static VALUE
-match_end(match, n)
- VALUE match, n;
+match_end(VALUE match, VALUE n)
{
int i = NUM2INT(n);
@@ -824,8 +782,7 @@ match_end(match, n)
#define MATCH_BUSY FL_USER2
void
-rb_match_busy(match)
- VALUE match;
+rb_match_busy(VALUE match)
{
FL_SET(match, MATCH_BUSY);
}
@@ -834,8 +791,7 @@ int ruby_ignorecase;
static int may_need_recompile;
static void
-rb_reg_prepare_re(re)
- VALUE re;
+rb_reg_prepare_re(VALUE re)
{
int need_recompile = 0;
int state;
@@ -885,9 +841,7 @@ rb_reg_prepare_re(re)
}
long
-rb_reg_adjust_startpos(re, str, pos, reverse)
- VALUE re, str;
- long pos, reverse;
+rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, long reverse)
{
long range;
OnigEncoding enc;
@@ -926,9 +880,7 @@ rb_reg_adjust_startpos(re, str, pos, reverse)
}
long
-rb_reg_search(re, str, pos, reverse)
- VALUE re, str;
- long pos, reverse;
+rb_reg_search(VALUE re, VALUE str, long pos, long reverse)
{
long result;
VALUE match;
@@ -998,9 +950,7 @@ rb_reg_search(re, str, pos, reverse)
}
VALUE
-rb_reg_nth_defined(nth, match)
- int nth;
- VALUE match;
+rb_reg_nth_defined(int nth, VALUE match)
{
if (NIL_P(match)) return Qnil;
if (nth >= RMATCH(match)->regs->num_regs) {
@@ -1015,9 +965,7 @@ rb_reg_nth_defined(nth, match)
}
VALUE
-rb_reg_nth_match(nth, match)
- int nth;
- VALUE match;
+rb_reg_nth_match(int nth, VALUE match)
{
VALUE str;
long start, end, len;
@@ -1040,8 +988,7 @@ rb_reg_nth_match(nth, match)
}
VALUE
-rb_reg_last_match(match)
- VALUE match;
+rb_reg_last_match(VALUE match)
{
return rb_reg_nth_match(0, match);
}
@@ -1059,8 +1006,7 @@ rb_reg_last_match(match)
*/
VALUE
-rb_reg_match_pre(match)
- VALUE match;
+rb_reg_match_pre(VALUE match)
{
VALUE str;
@@ -1084,8 +1030,7 @@ rb_reg_match_pre(match)
*/
VALUE
-rb_reg_match_post(match)
- VALUE match;
+rb_reg_match_post(VALUE match)
{
VALUE str;
long pos;
@@ -1100,8 +1045,7 @@ rb_reg_match_post(match)
}
VALUE
-rb_reg_match_last(match)
- VALUE match;
+rb_reg_match_last(VALUE match)
{
int i;
@@ -1115,33 +1059,31 @@ rb_reg_match_last(match)
}
static VALUE
-last_match_getter()
+last_match_getter(void)
{
return rb_reg_last_match(rb_backref_get());
}
static VALUE
-prematch_getter()
+prematch_getter(void)
{
return rb_reg_match_pre(rb_backref_get());
}
static VALUE
-postmatch_getter()
+postmatch_getter(void)
{
return rb_reg_match_post(rb_backref_get());
}
static VALUE
-last_paren_match_getter()
+last_paren_match_getter(void)
{
return rb_reg_match_last(rb_backref_get());
}
static VALUE
-match_array(match, start)
- VALUE match;
- int start;
+match_array(VALUE match, int start)
{
struct re_registers *regs = RMATCH(match)->regs;
VALUE ary = rb_ary_new2(regs->num_regs);
@@ -1190,8 +1132,7 @@ match_array(match, start)
*/
static VALUE
-match_to_a(match)
- VALUE match;
+match_to_a(VALUE match)
{
return match_array(match, 0);
}
@@ -1210,8 +1151,7 @@ match_to_a(match)
* f4 #=> "8"
*/
static VALUE
-match_captures(match)
- VALUE match;
+match_captures(VALUE match)
{
return match_array(match, 1);
}
@@ -1237,10 +1177,7 @@ match_captures(match)
*/
static VALUE
-match_aref(argc, argv, match)
- int argc;
- VALUE *argv;
- VALUE match;
+match_aref(int argc, VALUE *argv, VALUE match)
{
VALUE idx, rest;
@@ -1252,11 +1189,8 @@ match_aref(argc, argv, match)
return rb_reg_nth_match(FIX2INT(idx), match);
}
-static VALUE match_entry _((VALUE, long));
static VALUE
-match_entry(match, n)
- VALUE match;
- long n;
+match_entry(VALUE match, long n)
{
return rb_reg_nth_match(n, match);
}
@@ -1275,10 +1209,7 @@ match_entry(match, n)
*/
static VALUE
-match_values_at(argc, argv, match)
- int argc;
- VALUE *argv;
- VALUE match;
+match_values_at(int argc, VALUE *argv, VALUE match)
{
return rb_get_values_at(match, RMATCH(match)->regs->num_regs, argc, argv, match_entry);
}
@@ -1297,10 +1228,7 @@ match_values_at(argc, argv, match)
*/
static VALUE
-match_select(argc, argv, match)
- int argc;
- VALUE *argv;
- VALUE match;
+match_select(int argc, VALUE *argv, VALUE match)
{
if (argc > 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
@@ -1335,8 +1263,7 @@ match_select(argc, argv, match)
*/
static VALUE
-match_to_s(match)
- VALUE match;
+match_to_s(VALUE match)
{
VALUE str = rb_reg_last_match(match);
@@ -1358,8 +1285,7 @@ match_to_s(match)
*/
static VALUE
-match_string(match)
- VALUE match;
+match_string(VALUE match)
{
return RMATCH(match)->str; /* str is frozen */
}
@@ -1367,18 +1293,15 @@ match_string(match)
VALUE rb_cRegexp;
static void
-rb_reg_initialize(obj, s, len, options, ce)
- VALUE obj;
- const char *s;
- long len;
- int options; /* CASEFOLD = 1 */
+rb_reg_initialize(VALUE obj, const char *s, long len,
+ int options, /* CASEFOLD = 1 */
/* EXTENDED = 2 */
/* MULTILINE = 4 */
/* CODE_NONE = 16 */
/* CODE_EUC = 32 */
/* CODE_SJIS = 48 */
/* CODE_UTF8 = 64 */
- int ce; /* call rb_compile_error() */
+ int ce) /* call rb_compile_error() */
{
struct RRegexp *re = RREGEXP(obj);
@@ -1423,10 +1346,8 @@ rb_reg_initialize(obj, s, len, options, ce)
}
}
-static VALUE rb_reg_s_alloc _((VALUE));
static VALUE
-rb_reg_s_alloc(klass)
- VALUE klass;
+rb_reg_s_alloc(VALUE klass)
{
NEWOBJ(re, struct RRegexp);
OBJSETUP(re, klass, T_REGEXP);
@@ -1439,10 +1360,7 @@ rb_reg_s_alloc(klass)
}
VALUE
-rb_reg_new(s, len, options)
- const char *s;
- long len;
- int options;
+rb_reg_new(const char *s, long len, int options)
{
VALUE re = rb_reg_s_alloc(rb_cRegexp);
@@ -1451,10 +1369,7 @@ rb_reg_new(s, len, options)
}
VALUE
-rb_reg_compile(s, len, options)
- const char *s;
- long len;
- int options;
+rb_reg_compile(const char *s, long len, int options)
{
VALUE re = rb_reg_s_alloc(rb_cRegexp);
@@ -1467,8 +1382,7 @@ static int kcode_cache;
static VALUE reg_cache;
VALUE
-rb_reg_regcomp(str)
- VALUE str;
+rb_reg_regcomp(VALUE str)
{
if (reg_cache && RREGEXP(reg_cache)->len == RSTRING(str)->len
&& case_cache == ruby_ignorecase
@@ -1483,8 +1397,7 @@ rb_reg_regcomp(str)
}
static int
-rb_reg_cur_kcode(re)
- VALUE re;
+rb_reg_cur_kcode(VALUE re)
{
if (FL_TEST(re, KCODE_FIXED)) {
return RBASIC(re)->flags & KCODE_MASK;
@@ -1500,8 +1413,7 @@ rb_reg_cur_kcode(re)
*/
static VALUE
-rb_reg_hash(re)
- VALUE re;
+rb_reg_hash(VALUE re)
{
int hashval, len;
char *p;
@@ -1534,8 +1446,7 @@ rb_reg_hash(re)
*/
static VALUE
-rb_reg_equal(re1, re2)
- VALUE re1, re2;
+rb_reg_equal(VALUE re1, VALUE re2)
{
if (re1 == re2) return Qtrue;
if (TYPE(re2) != T_REGEXP) return Qfalse;
@@ -1550,9 +1461,7 @@ rb_reg_equal(re1, re2)
}
static VALUE
-rb_reg_match_pos(re, str, pos)
- VALUE re, str;
- long pos;
+rb_reg_match_pos(VALUE re, VALUE str, long pos)
{
if (NIL_P(str)) {
rb_backref_set(Qnil);
@@ -1585,8 +1494,7 @@ rb_reg_match_pos(re, str, pos)
*/
VALUE
-rb_reg_match(re, str)
- VALUE re, str;
+rb_reg_match(VALUE re, VALUE str)
{
return rb_reg_match_pos(re, str, 0);
}
@@ -1610,8 +1518,7 @@ rb_reg_match(re, str)
*/
VALUE
-rb_reg_eqq(re, str)
- VALUE re, str;
+rb_reg_eqq(VALUE re, VALUE str)
{
long start;
@@ -1643,8 +1550,7 @@ rb_reg_eqq(re, str)
*/
VALUE
-rb_reg_match2(re)
- VALUE re;
+rb_reg_match2(VALUE re)
{
long start;
VALUE line = rb_lastline_get();
@@ -1678,10 +1584,7 @@ rb_reg_match2(re)
*/
static VALUE
-rb_reg_match_m(argc, argv, re)
- int argc;
- VALUE *argv;
- VALUE re;
+rb_reg_match_m(int argc, VALUE *argv, VALUE re)
{
VALUE result, str, initpos;
long pos;
@@ -1735,10 +1638,7 @@ rb_reg_match_m(argc, argv, re)
*/
static VALUE
-rb_reg_initialize_m(argc, argv, self)
- int argc;
- VALUE *argv;
- VALUE self;
+rb_reg_initialize_m(int argc, VALUE *argv, VALUE self)
{
const char *s;
long len;
@@ -1809,8 +1709,7 @@ rb_reg_initialize_m(argc, argv, self)
}
VALUE
-rb_reg_quote(str)
- VALUE str;
+rb_reg_quote(VALUE str)
{
char *s, *send, *t;
VALUE tmp;
@@ -1908,9 +1807,7 @@ rb_reg_quote(str)
*/
static VALUE
-rb_reg_s_quote(argc, argv)
- int argc;
- VALUE *argv;
+rb_reg_s_quote(int argc, VALUE *argv)
{
VALUE str, kcode;
int kcode_saved = reg_kcode;
@@ -1928,7 +1825,7 @@ rb_reg_s_quote(argc, argv)
}
int
-rb_kcode()
+rb_kcode(void)
{
switch (reg_kcode) {
case KCODE_EUC:
@@ -1944,8 +1841,7 @@ rb_kcode()
}
static int
-rb_reg_get_kcode(re)
- VALUE re;
+rb_reg_get_kcode(VALUE re)
{
switch (RBASIC(re)->flags & KCODE_MASK) {
case KCODE_NONE:
@@ -1962,8 +1858,7 @@ rb_reg_get_kcode(re)
}
int
-rb_reg_options(re)
- VALUE re;
+rb_reg_options(VALUE re)
{
int options;
@@ -1992,9 +1887,7 @@ rb_reg_options(re)
* Regexp.union(/dogs/, /cats/i) #=> /(?-mix:dogs)|(?i-mx:cats)/
*/
static VALUE
-rb_reg_s_union(argc, argv)
- int argc;
- VALUE *argv;
+rb_reg_s_union(int argc, VALUE *argv)
{
if (argc == 0) {
VALUE args[1];
@@ -2069,8 +1962,7 @@ rb_reg_s_union(argc, argv)
/* :nodoc: */
static VALUE
-rb_reg_init_copy(copy, re)
- VALUE copy, re;
+rb_reg_init_copy(VALUE copy, VALUE re)
{
if (copy == re) return copy;
rb_check_frozen(copy);
@@ -2085,9 +1977,7 @@ rb_reg_init_copy(copy, re)
}
VALUE
-rb_reg_regsub(str, src, regs)
- VALUE str, src;
- struct re_registers *regs;
+rb_reg_regsub(VALUE str, VALUE src, struct re_registers *regs)
{
VALUE val = 0;
char *p, *s, *e;
@@ -2172,7 +2062,7 @@ rb_reg_regsub(str, src, regs)
}
const char*
-rb_get_kcode()
+rb_get_kcode(void)
{
switch (reg_kcode) {
case KCODE_SJIS:
@@ -2187,14 +2077,13 @@ rb_get_kcode()
}
static VALUE
-kcode_getter()
+kcode_getter(void)
{
return rb_str_new2(rb_get_kcode());
}
void
-rb_set_kcode(code)
- const char *code;
+rb_set_kcode(const char *code)
{
if (code == 0) goto set_no_conversion;
@@ -2227,23 +2116,20 @@ rb_set_kcode(code)
}
static void
-kcode_setter(val)
- VALUE val;
+kcode_setter(VALUE val)
{
may_need_recompile = 1;
rb_set_kcode(StringValuePtr(val));
}
static VALUE
-ignorecase_getter()
+ignorecase_getter(void)
{
return ruby_ignorecase?Qtrue:Qfalse;
}
static void
-ignorecase_setter(val, id)
- VALUE val;
- ID id;
+ignorecase_setter(VALUE val, ID id)
{
rb_warn("modifying %s is deprecated", rb_id2name(id));
may_need_recompile = 1;
@@ -2251,7 +2137,7 @@ ignorecase_setter(val, id)
}
static VALUE
-match_getter()
+match_getter(void)
{
VALUE match = rb_backref_get();
@@ -2261,8 +2147,7 @@ match_getter()
}
static void
-match_setter(val)
- VALUE val;
+match_setter(VALUE val)
{
if (!NIL_P(val)) {
Check_Type(val, T_MATCH);
@@ -2288,9 +2173,7 @@ match_setter(val)
*/
static VALUE
-rb_reg_s_last_match(argc, argv)
- int argc;
- VALUE *argv;
+rb_reg_s_last_match(int argc, VALUE *argv)
{
VALUE nth;
@@ -2312,7 +2195,7 @@ rb_reg_s_last_match(argc, argv)
*/
void
-Init_Regexp()
+Init_Regexp(void)
{
rb_eRegexpError = rb_define_class("RegexpError", rb_eStandardError);