Skip to content

Commit

Permalink
* regerror.c (onig_vsnprintf_with_pattern): added.
Browse files Browse the repository at this point in the history
* regparse.c (onig_syntax_warn): use above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nurse committed Oct 11, 2009
1 parent 2503de6 commit c506f19
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Sun Oct 11 09:44:46 2009 NARUSE, Yui <naruse@ruby-lang.org>

* regerror.c (onig_vsnprintf_with_pattern): added.

* regparse.c (onig_syntax_warn): use above.

Sun Oct 11 09:04:08 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>

* include/ruby/ruby.h (RB_GC_GUARD_PTR): workaround for gcc
Expand Down
42 changes: 25 additions & 17 deletions regerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,31 +312,16 @@ onig_error_code_to_str(s, code, va_alist)
return (int)len;
}


void
#ifdef HAVE_STDARG_PROTOTYPES
onig_snprintf_with_pattern(UChar buf[], int bufsize, OnigEncoding enc,
UChar* pat, UChar* pat_end, const UChar *fmt, ...)
#else
onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist)
UChar buf[];
int bufsize;
OnigEncoding enc;
UChar* pat;
UChar* pat_end;
const UChar *fmt;
va_dcl
#endif
onig_vsnprintf_with_pattern(UChar buf[], int bufsize, OnigEncoding enc,
UChar* pat, UChar* pat_end, const UChar *fmt, va_list args)
{
size_t need;
int n, len;
UChar *p, *s, *bp;
UChar bs[6];
va_list args;

va_init_list(args, fmt);
n = xvsnprintf((char* )buf, bufsize, (const char* )fmt, args);
va_end(args);

need = (pat_end - pat) * 4 + 4;

Expand Down Expand Up @@ -387,3 +372,26 @@ onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist)
*s = '\0';
}
}

void
#ifdef HAVE_STDARG_PROTOTYPES
onig_snprintf_with_pattern(UChar buf[], int bufsize, OnigEncoding enc,
UChar* pat, UChar* pat_end, const UChar *fmt, ...)
#else
onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist)
UChar buf[];
int bufsize;
OnigEncoding enc;
UChar* pat;
UChar* pat_end;
const UChar *fmt;
va_dcl
#endif
{
va_list args;
va_init_list(args, fmt);
onig_vsnprintf_with_pattern(buf, bufsize, enc,
pat, pat_end, fmt, args);
va_end(args);
}

9 changes: 6 additions & 3 deletions regparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2844,20 +2844,23 @@ fetch_name(OnigCodePoint start_code, UChar** src, UChar* end,
}
#endif /* USE_NAMED_GROUP */

void onig_vsnprintf_with_pattern(UChar buf[], int bufsize, OnigEncoding enc,
UChar* pat, UChar* pat_end, const UChar *fmt, va_list args);

static void
onig_syntax_warn(ScanEnv *env, const char *fmt, ...)
{
va_list args;
UChar buf[WARN_BUFSIZE];
va_start(args, fmt);
onig_snprintf_with_pattern(buf, WARN_BUFSIZE, env->enc,
onig_vsnprintf_with_pattern(buf, WARN_BUFSIZE, env->enc,
env->pattern, env->pattern_end,
(const UChar *)fmt, args);
va_end(args);
if (env->sourcefile == NULL)
rb_warn(fmt, buf);
rb_warn((char *)buf);
else
rb_compile_warn(env->sourcefile, env->sourceline, fmt, buf);
rb_compile_warn(env->sourcefile, env->sourceline, (char *)buf);
}

static void
Expand Down

0 comments on commit c506f19

Please sign in to comment.