Skip to content

Commit

Permalink
add prefix onig_posix_ to POSIX API
Browse files Browse the repository at this point in the history
  • Loading branch information
kkos committed Sep 30, 2020
1 parent 79ebf1e commit f7ca475
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
31 changes: 22 additions & 9 deletions src/onigposix.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ typedef struct {
void* onig; /* Oniguruma regex_t* */
size_t re_nsub;
int comp_options;
} regex_t;
} onig_posix_regex_t;


#ifndef P_
Expand Down Expand Up @@ -160,16 +160,29 @@ ONIG_EXTERN int onig_end P_((void));
#endif /* ONIGURUMA_H */


ONIG_EXTERN int regcomp P_((regex_t* reg, const char* pat, int options));
ONIG_EXTERN int regexec P_((regex_t* reg, const char* str, size_t nmatch, regmatch_t* matches, int options));
ONIG_EXTERN void regfree P_((regex_t* reg));
ONIG_EXTERN size_t regerror P_((int code, const regex_t* reg, char* buf, size_t size));
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 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));

/* extended API */
ONIG_EXTERN void reg_set_encoding P_((int enc));
ONIG_EXTERN int reg_name_to_group_numbers P_((regex_t* reg, const unsigned char* name, const unsigned char* name_end, int** nums));
ONIG_EXTERN int reg_foreach_name P_((regex_t* reg, int (*func)(const unsigned char*, const unsigned char*,int,int*,regex_t*,void*), void* arg));
ONIG_EXTERN int reg_number_of_names P_((regex_t* reg));
ONIG_EXTERN void onig_posix_reg_set_encoding P_((int enc));
ONIG_EXTERN int onig_posix_reg_name_to_group_numbers P_((onig_posix_regex_t* reg, const unsigned char* name, const unsigned char* name_end, int** nums));
ONIG_EXTERN int onig_posix_reg_foreach_name P_((onig_posix_regex_t* reg, int (*func)(const unsigned char*, const unsigned char*,int,int*,onig_posix_regex_t*,void*), void* arg));
ONIG_EXTERN int onig_posix_reg_number_of_names P_((onig_posix_regex_t* reg));


/* aliases */
#define regex_t onig_posix_regex_t

#define regcomp onig_posix_regcomp
#define regexec onig_posix_regexec
#define regfree onig_posix_regfree
#define regerror onig_posix_regerror
#define reg_set_encoding onig_posix_reg_set_encoding
#define reg_name_to_group_numbers onig_posix_reg_name_to_group_numbers
#define reg_foreach_name onig_posix_reg_foreach_name
#define reg_number_of_names onig_posix_reg_number_of_names

#ifdef __cplusplus
}
Expand Down
15 changes: 12 additions & 3 deletions src/regposerr.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
#include "config.h"
#include "onigposix.h"

#undef regex_t
#undef regcomp
#undef regexec
#undef regfree
#undef regerror
#undef reg_set_encoding
#undef reg_name_to_group_numbers
#undef reg_foreach_name
#undef reg_number_of_names

#ifndef ONIG_NO_STANDARD_C_HEADERS
#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -92,10 +102,9 @@ static char* ESTRING[] = {
};



extern size_t
regerror(int posix_ecode, const regex_t* reg ARG_UNUSED, char* buf,
size_t size)
onig_posix_regerror(int posix_ecode, const onig_posix_regex_t* reg ARG_UNUSED,
char* buf, size_t size)
{
char* s;
char tbuf[35];
Expand Down
32 changes: 21 additions & 11 deletions src/regposix.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@

#include "onigposix.h"

#undef regex_t
#undef regcomp
#undef regexec
#undef regfree
#undef regerror
#undef reg_set_encoding
#undef reg_name_to_group_numbers
#undef reg_foreach_name
#undef reg_number_of_names

#define ONIG_C(reg) ((onig_regex_t* )((reg)->onig))
#define PONIG_C(reg) ((onig_regex_t** )(&(reg)->onig))

Expand Down Expand Up @@ -145,7 +155,7 @@ onig2posix_error_code(int code)
}

extern int
regcomp(regex_t* reg, const char* pattern, int posix_options)
onig_posix_regcomp(onig_posix_regex_t* reg, const char* pattern, int posix_options)
{
int r, len;
OnigSyntaxType* syntax = OnigDefaultSyntax;
Expand Down Expand Up @@ -179,8 +189,8 @@ regcomp(regex_t* reg, const char* pattern, int posix_options)
}

extern int
regexec(regex_t* reg, const char* str, size_t nmatch,
regmatch_t pmatch[], int posix_options)
onig_posix_regexec(onig_posix_regex_t* reg, const char* str, size_t nmatch,
regmatch_t pmatch[], int posix_options)
{
int r, i, len;
UChar* end;
Expand Down Expand Up @@ -237,15 +247,15 @@ regexec(regex_t* reg, const char* str, size_t nmatch,
}

extern void
regfree(regex_t* reg)
onig_posix_regfree(onig_posix_regex_t* reg)
{
onig_free(ONIG_C(reg));
reg->onig = (void* )0;
}


extern void
reg_set_encoding(int mb_code)
onig_posix_reg_set_encoding(int mb_code)
{
OnigEncoding enc;

Expand Down Expand Up @@ -280,15 +290,15 @@ reg_set_encoding(int mb_code)
}

extern int
reg_name_to_group_numbers(regex_t* reg,
onig_posix_reg_name_to_group_numbers(onig_posix_regex_t* reg,
const unsigned char* name, const unsigned char* name_end, int** nums)
{
return onig_name_to_group_numbers(ONIG_C(reg), name, name_end, nums);
}

typedef struct {
int (*func)(const unsigned char*, const unsigned char*,int,int*,regex_t*,void*);
regex_t* reg;
int (*func)(const unsigned char*, const unsigned char*,int,int*,onig_posix_regex_t*,void*);
onig_posix_regex_t* reg;
void* arg;
} i_wrap;

Expand All @@ -302,8 +312,8 @@ i_wrapper(const UChar* name, const UChar* name_end, int ng, int* gs,
}

extern int
reg_foreach_name(regex_t* reg,
int (*func)(const unsigned char*, const unsigned char*,int,int*,regex_t*,void*),
onig_posix_reg_foreach_name(onig_posix_regex_t* reg,
int (*func)(const unsigned char*, const unsigned char*,int,int*,onig_posix_regex_t*,void*),
void* arg)
{
i_wrap warg;
Expand All @@ -316,7 +326,7 @@ reg_foreach_name(regex_t* reg,
}

extern int
reg_number_of_names(regex_t* reg)
onig_posix_reg_number_of_names(onig_posix_regex_t* reg)
{
return onig_number_of_names(ONIG_C(reg));
}

0 comments on commit f7ca475

Please sign in to comment.