Skip to content

Commit

Permalink
re-define regoff_t and regmatch_t as macros
Browse files Browse the repository at this point in the history
  • Loading branch information
kkos committed Oct 1, 2020
1 parent c59f489 commit 6d26197
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
14 changes: 8 additions & 6 deletions src/onigposix.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ extern "C" {
#define REG_POSIX_ENCODING_UTF16_LE 5


typedef int regoff_t;
typedef int onig_posix_regoff_t;

typedef struct {
regoff_t rm_so;
regoff_t rm_eo;
} regmatch_t;
onig_posix_regoff_t rm_so;
onig_posix_regoff_t rm_eo;
} onig_posix_regmatch_t;

/* POSIX regex_t */
typedef struct {
Expand Down Expand Up @@ -161,7 +161,7 @@ ONIG_EXTERN int onig_end P_((void));


ONIG_EXTERN int onig_posix_regcomp P_((onig_posix_regex_t* reg, const char* pat, int options));
ONIG_EXTERN int onig_posix_regexec P_((onig_posix_regex_t* reg, const char* str, size_t nmatch, regmatch_t* matches, int options));
ONIG_EXTERN int onig_posix_regexec P_((onig_posix_regex_t* reg, const char* str, size_t nmatch, onig_posix_regmatch_t* matches, int options));
ONIG_EXTERN void onig_posix_regfree P_((onig_posix_regex_t* reg));
ONIG_EXTERN size_t onig_posix_regerror P_((int code, const onig_posix_regex_t* reg, char* buf, size_t size));

Expand All @@ -173,7 +173,9 @@ ONIG_EXTERN int onig_posix_reg_number_of_names P_((onig_posix_regex_t* reg));


/* aliases */
#define regex_t onig_posix_regex_t
#define regex_t onig_posix_regex_t
#define regmatch_t onig_posix_regmatch_t
#define regoff_t onig_posix_regoff_t

#define regcomp onig_posix_regcomp
#define regexec onig_posix_regexec
Expand Down
2 changes: 2 additions & 0 deletions src/regposerr.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "onigposix.h"

#undef regex_t
#undef regmatch_t
#undef regoff_t
#undef regcomp
#undef regexec
#undef regfree
Expand Down
14 changes: 8 additions & 6 deletions src/regposix.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "onigposix.h"

#undef regex_t
#undef regmatch_t
#undef regoff_t
#undef regcomp
#undef regexec
#undef regfree
Expand Down Expand Up @@ -190,23 +192,23 @@ onig_posix_regcomp(onig_posix_regex_t* reg, const char* pattern, int posix_optio

extern int
onig_posix_regexec(onig_posix_regex_t* reg, const char* str, size_t nmatch,
regmatch_t pmatch[], int posix_options)
onig_posix_regmatch_t pmatch[], int posix_options)
{
int r, i, len;
UChar* end;
regmatch_t* pm;
onig_posix_regmatch_t* pm;
OnigOptionType options;

options = ONIG_OPTION_POSIX_REGION;
if ((posix_options & REG_NOTBOL) != 0) options |= ONIG_OPTION_NOTBOL;
if ((posix_options & REG_NOTEOL) != 0) options |= ONIG_OPTION_NOTEOL;

if (nmatch == 0 || (reg->comp_options & REG_NOSUB) != 0) {
pm = (regmatch_t* )NULL;
pm = (onig_posix_regmatch_t* )NULL;
nmatch = 0;
}
else if ((int )nmatch < ONIG_C(reg)->num_mem + 1) {
pm = (regmatch_t* )xmalloc(sizeof(regmatch_t)
pm = (onig_posix_regmatch_t* )xmalloc(sizeof(onig_posix_regmatch_t)
* (ONIG_C(reg)->num_mem + 1));
if (pm == NULL)
return REG_ESPACE;
Expand All @@ -223,7 +225,7 @@ onig_posix_regexec(onig_posix_regex_t* reg, const char* str, size_t nmatch,
if (r >= 0) {
r = 0; /* Match */
if (pm != pmatch && pm != NULL) {
xmemcpy(pmatch, pm, sizeof(regmatch_t) * nmatch);
xmemcpy(pmatch, pm, sizeof(onig_posix_regmatch_t) * nmatch);
}
}
else if (r == ONIG_MISMATCH) {
Expand Down Expand Up @@ -342,7 +344,7 @@ regcomp(onig_posix_regex_t* reg, const char* pattern, int posix_options)

extern int
regexec(onig_posix_regex_t* reg, const char* str, size_t nmatch,
regmatch_t pmatch[], int posix_options)
onig_posix_regmatch_t pmatch[], int posix_options)
{
return onig_posix_regexec(reg, str, nmatch, pmatch, posix_options);
}
Expand Down

0 comments on commit 6d26197

Please sign in to comment.