added hawk_rtx_buildrex() and hawk_rtx_freertx()

This commit is contained in:
hyung-hwan 2020-01-01 14:02:27 +00:00
parent 49e3eec642
commit 9a24d57b8f
12 changed files with 160 additions and 158 deletions

View File

@ -889,17 +889,10 @@ int hawk_fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{ {
int x; int x;
// TODO: hawk_rtx_buildrex x = rtx->gbl.ignorecase?
if (rtx->gbl.ignorecase) hawk_rtx_buildrex(rtx, fs.ptr, fs.len, HAWK_NULL, &fs_rex):
x = hawk_buildrex(hawk_rtx_gethawk(rtx), fs.ptr, fs.len, &errnum, HAWK_NULL, &fs_rex); hawk_rtx_buildrex(rtx, fs.ptr, fs.len, &fs_rex, HAWK_NULL);
else if (x <= -1) goto oops;
x = hawk_buildrex(hawk_rtx_gethawk(rtx), fs.ptr, fs.len, &errnum, &fs_rex, HAWK_NULL);
if (x <= -1)
{
hawk_rtx_seterrnum (rtx, HAWK_NULL, errnum);
goto oops;
}
fs_rex_free = fs_rex; fs_rex_free = fs_rex;
} }
@ -972,9 +965,9 @@ int hawk_fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
if (fs_rex_free) if (fs_rex_free)
{ {
if (rtx->gbl.ignorecase) if (rtx->gbl.ignorecase)
hawk_freerex (hawk_rtx_gethawk(rtx), HAWK_NULL, fs_rex_free); hawk_rtx_freerex (rtx, HAWK_NULL, fs_rex_free);
else else
hawk_freerex (hawk_rtx_gethawk(rtx), fs_rex_free, HAWK_NULL); hawk_rtx_freerex (rtx, fs_rex_free, HAWK_NULL);
} }
/*nflds--;*/ /*nflds--;*/
@ -994,9 +987,9 @@ oops:
if (fs_rex_free) if (fs_rex_free)
{ {
if (rtx->gbl.ignorecase) if (rtx->gbl.ignorecase)
hawk_freerex (hawk_rtx_gethawk(rtx), HAWK_NULL, fs_rex_free); hawk_rtx_freerex (rtx, HAWK_NULL, fs_rex_free);
else else
hawk_freerex (hawk_rtx_gethawk(rtx), fs_rex_free, HAWK_NULL); hawk_rtx_freerex (rtx, fs_rex_free, HAWK_NULL);
} }
return -1; return -1;
} }
@ -1141,20 +1134,12 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
if (a0_vtype != HAWK_VAL_REX) if (a0_vtype != HAWK_VAL_REX)
{ {
hawk_errnum_t errnum;
int x; int x;
// TODO: hawk_rtx_buildrex... x = rtx->gbl.ignorecase?
if (rtx->gbl.ignorecase) hawk_rtx_buildrex(rtx, s0.ptr, s0.len, HAWK_NULL, &rex):
x = hawk_buildrex(hawk_rtx_gethawk(rtx), s0.ptr, s0.len, &errnum, HAWK_NULL, &rex); hawk_rtx_buildrex(rtx, s0.ptr, s0.len, &rex, HAWK_NULL);
else if (x <= -1) goto oops;
x = hawk_buildrex(hawk_rtx_gethawk(rtx), s0.ptr, s0.len, &errnum, &rex, HAWK_NULL);
if (x <= -1)
{
hawk_rtx_seterrnum (rtx, HAWK_NULL, errnum);
goto oops;
}
rex_free = rex; rex_free = rex;
} }
@ -1237,9 +1222,9 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
if (rex_free) if (rex_free)
{ {
if (rtx->gbl.ignorecase) if (rtx->gbl.ignorecase)
hawk_freerex (hawk_rtx_gethawk(rtx), HAWK_NULL, rex_free); hawk_rtx_freerex (rtx, HAWK_NULL, rex_free);
else else
hawk_freerex (hawk_rtx_gethawk(rtx), rex_free, HAWK_NULL); hawk_rtx_freerex (rtx, rex_free, HAWK_NULL);
rex_free = HAWK_NULL; rex_free = HAWK_NULL;
} }
@ -1282,9 +1267,9 @@ oops:
if (rex_free) if (rex_free)
{ {
if (rtx->gbl.ignorecase) if (rtx->gbl.ignorecase)
hawk_freerex (hawk_rtx_gethawk(rtx), HAWK_NULL, rex_free); hawk_rtx_freerex (rtx, HAWK_NULL, rex_free);
else else
hawk_freerex (hawk_rtx_gethawk(rtx), rex_free, HAWK_NULL); hawk_rtx_freerex (rtx, rex_free, HAWK_NULL);
} }
if (new_inited) hawk_ooecs_fini (&new); if (new_inited) hawk_ooecs_fini (&new);
if (s2_free) hawk_rtx_freemem (rtx, s2_free); if (s2_free) hawk_rtx_freemem (rtx, s2_free);

View File

@ -622,3 +622,53 @@ hawk_oow_t hawk_gem_fmttobcstr (hawk_gem_t* gem, hawk_bch_t* buf, hawk_oow_t buf
return x; return x;
} }
/* ------------------------------------------------------------------------ */
int hawk_gem_buildrex (hawk_gem_t* gem, const hawk_ooch_t* ptn, hawk_oow_t len, int nobound, hawk_tre_t** code, hawk_tre_t** icode)
{
hawk_tre_t* tre = HAWK_NULL;
hawk_tre_t* itre = HAWK_NULL;
int opt = HAWK_TRE_EXTENDED;
if (nobound) opt |= HAWK_TRE_NOBOUND;
if (code)
{
tre = hawk_tre_open(gem, 0);
if (!tre) return -1;
if (hawk_tre_compx(tre, ptn, len, HAWK_NULL, opt) <= -1)
{
hawk_tre_close (tre);
return -1;
}
}
if (icode)
{
itre = hawk_tre_open(gem, 0);
if (itre == HAWK_NULL)
{
if (tre) hawk_tre_close (tre);
return -1;
}
/* ignorecase is a compile option for TRE */
if (hawk_tre_compx(itre, ptn, len, HAWK_NULL, opt | HAWK_TRE_IGNORECASE) <= -1)
{
hawk_tre_close (itre);
if (tre) hawk_tre_close (tre);
return -1;
}
}
if (code) *code = tre;
if (icode) *icode = itre;
return 0;
}
void hawk_gem_freerex (hawk_gem_t* gem, hawk_tre_t* code, hawk_tre_t* icode)
{
if (icode && icode != code) hawk_tre_close (icode);
if (code) hawk_tre_close (code);
}

View File

@ -751,6 +751,7 @@ struct hawk_cmgr_t
typedef struct hawk_t hawk_t; typedef struct hawk_t hawk_t;
typedef struct hawk_val_t hawk_val_t; typedef struct hawk_val_t hawk_val_t;
typedef struct hawk_gem_t hawk_gem_t; typedef struct hawk_gem_t hawk_gem_t;
typedef struct hawk_tre_t hawk_tre_t;
#define HAWK_ERRMSG_CAPA 2048 #define HAWK_ERRMSG_CAPA 2048

View File

@ -446,6 +446,20 @@ HAWK_EXPORT void hawk_gem_seterrufmt (
... ...
); );
HAWK_EXPORT int hawk_gem_buildrex (
hawk_gem_t* gem,
const hawk_ooch_t* ptn,
hawk_oow_t len,
int nobound,
hawk_tre_t** code,
hawk_tre_t** icode
);
HAWK_EXPORT void hawk_gem_freerex (
hawk_gem_t* gem,
hawk_tre_t* code,
hawk_tre_t* icode
);
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@ -29,7 +29,6 @@
#include <hawk-cmn.h> #include <hawk-cmn.h>
typedef struct hawk_tre_t hawk_tre_t;
struct hawk_tre_t struct hawk_tre_t
{ {
hawk_gem_t* gem; hawk_gem_t* gem;

View File

@ -599,3 +599,9 @@ hawk_oow_t hawk_fmttobcstr_ (hawk_t* hawk, hawk_bch_t* buf, hawk_oow_t bufsz, co
va_end(ap); va_end(ap);
return n; return n;
} }
int hawk_buildrex (hawk_t* hawk, const hawk_ooch_t* ptn, hawk_oow_t len, hawk_tre_t** code, hawk_tre_t** icode)
{
return hawk_gem_buildrex(hawk_getgem(hawk), ptn, len, !(hawk->opt.trait & HAWK_REXBOUND), code, icode);
}

View File

@ -1987,6 +1987,22 @@ static HAWK_INLINE hawk_oow_t hawk_fmttobcstr (hawk_t* hawk, hawk_bch_t* buf, ha
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
HAWK_EXPORT int hawk_buildrex (
hawk_t* hawk,
const hawk_ooch_t* ptn,
hawk_oow_t len,
hawk_tre_t** code,
hawk_tre_t** icode
);
#if defined(HAWK_HAVE_INLINE)
static HAWK_INLINE void hawk_freerex (hawk_t* hawk, hawk_tre_t* code, hawk_tre_t* icode) { hawk_gem_freerex (hawk_getgem(hawk), code, icode); }
#else
#define hawk_freerex(hawk, code, icode) hawk_gem_freerex(hawk_getgem(hawk), code, icode)
#endif
/* ----------------------------------------------------------------------- */
HAWK_EXPORT hawk_ooi_t hawk_logufmtv ( HAWK_EXPORT hawk_ooi_t hawk_logufmtv (
hawk_t* hawk, hawk_t* hawk,
hawk_bitmask_t mask, hawk_bitmask_t mask,
@ -3226,6 +3242,24 @@ static HAWK_INLINE hawk_oow_t hawk_rtx_fmttobcstr (hawk_rtx_t* rtx, hawk_bch_t*
# define hawk_rtx_fmttooocstr hawk_rtx_fmttobcstr # define hawk_rtx_fmttooocstr hawk_rtx_fmttobcstr
#endif #endif
/* ----------------------------------------------------------------------- */
HAWK_EXPORT int hawk_rtx_buildrex (
hawk_rtx_t* rtx,
const hawk_ooch_t* ptn,
hawk_oow_t len,
hawk_tre_t** code,
hawk_tre_t** icode
);
#if defined(HAWK_HAVE_INLINE)
static HAWK_INLINE void hawk_rtx_freerex (hawk_rtx_t* rtx, hawk_tre_t* code, hawk_tre_t* icode) { hawk_gem_freerex (hawk_rtx_getgem(rtx), code, icode); }
#else
#define hawk_rtx_freerex(rtx, code, icode) hawk_gem_freerex(hawk_rtx_getgem(rtx), code, icode)
#endif
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**

View File

@ -70,17 +70,6 @@ hawk_ooch_t* hawk_rtx_strxnfld (
hawk_oocs_t* tok hawk_oocs_t* tok
); );
int hawk_buildrex (
hawk_t* awk,
const hawk_ooch_t* ptn,
hawk_oow_t len,
hawk_errnum_t* errnum,
hawk_tre_t** code,
hawk_tre_t** icode
);
void hawk_freerex (hawk_t* awk, hawk_tre_t* code, hawk_tre_t* icode);
int hawk_rtx_matchval ( int hawk_rtx_matchval (
hawk_rtx_t* rtx, hawk_val_t* val, hawk_rtx_t* rtx, hawk_val_t* val,
const hawk_oocs_t* str, const hawk_oocs_t* substr, const hawk_oocs_t* str, const hawk_oocs_t* substr,

View File

@ -432,56 +432,6 @@ hawk_ooch_t* hawk_rtx_strxnfld (
return HAWK_NULL; return HAWK_NULL;
} }
int hawk_buildrex (hawk_t* awk, const hawk_ooch_t* ptn, hawk_oow_t len, hawk_errnum_t* errnum, hawk_tre_t** code, hawk_tre_t** icode)
{
hawk_tre_t* tre = HAWK_NULL;
hawk_tre_t* itre = HAWK_NULL;
int opt = HAWK_TRE_EXTENDED;
if (code)
{
tre = hawk_tre_open(hawk_getgem(awk), 0);
if (tre == HAWK_NULL)
{
*errnum = hawk_geterrnum(awk);
return -1;
}
if (!(awk->opt.trait & HAWK_REXBOUND)) opt |= HAWK_TRE_NOBOUND;
if (hawk_tre_compx(tre, ptn, len, HAWK_NULL, opt) <= -1)
{
*errnum = hawk_gem_geterrnum(tre->gem);
hawk_tre_close (tre);
return -1;
}
}
if (icode)
{
itre = hawk_tre_open(hawk_getgem(awk), 0);
if (itre == HAWK_NULL)
{
*errnum = hawk_geterrnum(awk);
if (tre) hawk_tre_close (tre);
return -1;
}
/* ignorecase is a compile option for TRE */
if (hawk_tre_compx(itre, ptn, len, HAWK_NULL, opt | HAWK_TRE_IGNORECASE) <= -1)
{
*errnum = hawk_gem_geterrnum(itre->gem);
hawk_tre_close (itre);
if (tre) hawk_tre_close (tre);
return -1;
}
}
if (code) *code = tre;
if (icode) *icode = itre;
return 0;
}
static int matchtre (hawk_tre_t* tre, int opt, const hawk_oocs_t* str, hawk_oocs_t* mat, hawk_oocs_t submat[9], hawk_gem_t* errgem) static int matchtre (hawk_tre_t* tre, int opt, const hawk_oocs_t* str, hawk_oocs_t* mat, hawk_oocs_t submat[9], hawk_gem_t* errgem)
{ {
int n; int n;
@ -521,18 +471,11 @@ static int matchtre (hawk_tre_t* tre, int opt, const hawk_oocs_t* str, hawk_oocs
return 1; return 1;
} }
void hawk_freerex (hawk_t* awk, hawk_tre_t* code, hawk_tre_t* icode)
{
if (icode && icode != code) hawk_tre_close (icode);
if (code) hawk_tre_close (code);
}
int hawk_rtx_matchval (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_oocs_t* str, const hawk_oocs_t* substr, hawk_oocs_t* match, hawk_oocs_t submat[9]) int hawk_rtx_matchval (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_oocs_t* str, const hawk_oocs_t* substr, hawk_oocs_t* match, hawk_oocs_t submat[9])
{ {
int ignorecase, x; int ignorecase, x;
int opt = HAWK_TRE_BACKTRACKING; /* TODO: option... HAWK_TRE_BACKTRACKING ??? */ int opt = HAWK_TRE_BACKTRACKING; /* TODO: option... HAWK_TRE_BACKTRACKING ??? */
hawk_tre_t* code; hawk_tre_t* code;
hawk_errnum_t awkerr; /*TODO: get rid of this */
ignorecase = rtx->gbl.ignorecase; ignorecase = rtx->gbl.ignorecase;
@ -548,15 +491,10 @@ int hawk_rtx_matchval (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_oocs_t* str,
tmp.ptr = hawk_rtx_getvaloocstr(rtx, val, &tmp.len); tmp.ptr = hawk_rtx_getvaloocstr(rtx, val, &tmp.len);
if (tmp.ptr == HAWK_NULL) return -1; if (tmp.ptr == HAWK_NULL) return -1;
// TODO: create hawk_rtx_buildrex.... x = ignorecase? hawk_rtx_buildrex(rtx, tmp.ptr, tmp.len, HAWK_NULL, &code):
x = ignorecase? hawk_buildrex(rtx->awk, tmp.ptr, tmp.len, &awkerr, HAWK_NULL, &code): hawk_rtx_buildrex(rtx, tmp.ptr, tmp.len, &code, HAWK_NULL);
hawk_buildrex(rtx->awk, tmp.ptr, tmp.len, &awkerr, &code, HAWK_NULL);
hawk_rtx_freevaloocstr (rtx, val, tmp.ptr); hawk_rtx_freevaloocstr (rtx, val, tmp.ptr);
if (x <= -1) if (x <= -1) return -1;
{
hawk_rtx_seterrnum (rtx, HAWK_NULL, awkerr);
return -1;
}
} }
x = matchtre( x = matchtre(
@ -578,7 +516,7 @@ int hawk_rtx_matchval (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_oocs_t* str,
int hawk_rtx_matchrex (hawk_rtx_t* rtx, hawk_tre_t* code, const hawk_oocs_t* str, const hawk_oocs_t* substr, hawk_oocs_t* match, hawk_oocs_t submat[9]) int hawk_rtx_matchrex (hawk_rtx_t* rtx, hawk_tre_t* code, const hawk_oocs_t* str, const hawk_oocs_t* substr, hawk_oocs_t* match, hawk_oocs_t submat[9])
{ {
int opt = HAWK_TRE_BACKTRACKING; /* TODO: option... HAWK_TRE_BACKTRACKING ??? */ int opt = HAWK_TRE_BACKTRACKING; /* TODO: option... HAWK_TRE_BACKTRACKING or others??? */
return matchtre( return matchtre(
code, ((str->ptr == substr->ptr)? opt: (opt | HAWK_TRE_NOTBOL)), code, ((str->ptr == substr->ptr)? opt: (opt | HAWK_TRE_NOTBOL)),
substr, match, submat, hawk_rtx_getgem(rtx) substr, match, submat, hawk_rtx_getgem(rtx)

View File

@ -369,7 +369,7 @@ static global_t gtab[] =
do { \ do { \
if (hawk_ooecs_ccat((tok)->name,(c)) == (hawk_oow_t)-1) \ if (hawk_ooecs_ccat((tok)->name,(c)) == (hawk_oow_t)-1) \
{ \ { \
hawk_seterror (awk, HAWK_ENOMEM, HAWK_NULL, &(tok)->loc); \ ADJERR_LOC (awk, &(tok)->loc); \
return -1; \ return -1; \
} \ } \
} while (0) } while (0)
@ -378,7 +378,7 @@ static global_t gtab[] =
do { \ do { \
if (hawk_ooecs_ncat((tok)->name,(s),(l)) == (hawk_oow_t)-1) \ if (hawk_ooecs_ncat((tok)->name,(s),(l)) == (hawk_oow_t)-1) \
{ \ { \
hawk_seterror (awk, HAWK_ENOMEM, HAWK_NULL, &(tok)->loc); \ ADJERR_LOC (awk, &(tok)->loc); \
return -1; \ return -1; \
} \ } \
} while (0) } while (0)
@ -4294,11 +4294,11 @@ static hawk_nde_t* parse_unary (hawk_t* awk, const hawk_loc_t* xloc)
{ {
hawk_nde_exp_t* nde; hawk_nde_exp_t* nde;
nde = (hawk_nde_exp_t*) hawk_callocmem (awk, HAWK_SIZEOF(*nde)); nde = (hawk_nde_exp_t*)hawk_callocmem(awk, HAWK_SIZEOF(*nde));
if (nde == HAWK_NULL) if (nde == HAWK_NULL)
{ {
hawk_clrpt (awk, left); hawk_clrpt (awk, left);
SETERR_LOC (awk, HAWK_ENOMEM, xloc); ADJERR_LOC (awk, xloc);
return HAWK_NULL; return HAWK_NULL;
} }
@ -4633,7 +4633,11 @@ static hawk_nde_t* parse_primary_mbs (hawk_t* awk, const hawk_loc_t* xloc)
#if defined(HAWK_OOCH_IS_BCH) #if defined(HAWK_OOCH_IS_BCH)
nde->len = HAWK_OOECS_LEN(awk->tok.name); nde->len = HAWK_OOECS_LEN(awk->tok.name);
nde->ptr = hawk_dupoocs(awk, HAWK_OOECS_OOCS(awk->tok.name)); nde->ptr = hawk_dupoocs(awk, HAWK_OOECS_OOCS(awk->tok.name));
if (!nde->ptr) goto oops; if (!nde->ptr)
{
ADJERR_LOC (awk, xloc);
goto oops;
}
#else #else
{ {
/* the MBS token doesn't include a character greater than 0xFF in awk->tok.name /* the MBS token doesn't include a character greater than 0xFF in awk->tok.name
@ -4642,7 +4646,7 @@ static hawk_nde_t* parse_primary_mbs (hawk_t* awk, const hawk_loc_t* xloc)
nde->ptr = hawk_allocmem(awk, (nde->len + 1) * HAWK_SIZEOF(*nde->ptr)); nde->ptr = hawk_allocmem(awk, (nde->len + 1) * HAWK_SIZEOF(*nde->ptr));
if (!nde->ptr) if (!nde->ptr)
{ {
hawk_seterror (awk, HAWK_ENOMEM, HAWK_NULL, xloc); ADJERR_LOC (awk, xloc);
goto oops; goto oops;
} }
@ -4665,7 +4669,6 @@ oops:
static hawk_nde_t* parse_primary_rex (hawk_t* awk, const hawk_loc_t* xloc) static hawk_nde_t* parse_primary_rex (hawk_t* awk, const hawk_loc_t* xloc)
{ {
hawk_nde_rex_t* nde; hawk_nde_rex_t* nde;
hawk_errnum_t errnum;
/* the regular expression is tokenized here because /* the regular expression is tokenized here because
* of the context-sensitivity of the slash symbol. * of the context-sensitivity of the slash symbol.
@ -4673,10 +4676,9 @@ static hawk_nde_t* parse_primary_rex (hawk_t* awk, const hawk_loc_t* xloc)
* it as a regular expression */ * it as a regular expression */
hawk_ooecs_clear (awk->tok.name); hawk_ooecs_clear (awk->tok.name);
if (MATCH(awk,TOK_DIV_ASSN) && if (MATCH(awk,TOK_DIV_ASSN) && hawk_ooecs_ccat(awk->tok.name, HAWK_T('=')) == (hawk_oow_t)-1)
hawk_ooecs_ccat (awk->tok.name, HAWK_T('=')) == (hawk_oow_t)-1)
{ {
SETERR_LOC (awk, HAWK_ENOMEM, xloc); ADJERR_LOC (awk, xloc);
return HAWK_NULL; return HAWK_NULL;
} }
@ -4685,7 +4687,7 @@ static hawk_nde_t* parse_primary_rex (hawk_t* awk, const hawk_loc_t* xloc)
HAWK_ASSERT (MATCH(awk,TOK_REX)); HAWK_ASSERT (MATCH(awk,TOK_REX));
nde = (hawk_nde_rex_t*) hawk_callocmem (awk, HAWK_SIZEOF(*nde)); nde = (hawk_nde_rex_t*)hawk_callocmem(awk, HAWK_SIZEOF(*nde));
if (nde == HAWK_NULL) if (nde == HAWK_NULL)
{ {
ADJERR_LOC (awk, xloc); ADJERR_LOC (awk, xloc);
@ -4698,9 +4700,9 @@ static hawk_nde_t* parse_primary_rex (hawk_t* awk, const hawk_loc_t* xloc)
nde->str.ptr = hawk_dupoocs(awk, HAWK_OOECS_OOCS(awk->tok.name)); nde->str.ptr = hawk_dupoocs(awk, HAWK_OOECS_OOCS(awk->tok.name));
if (nde->str.ptr == HAWK_NULL) goto oops; if (nde->str.ptr == HAWK_NULL) goto oops;
if (hawk_buildrex (awk, HAWK_OOECS_PTR(awk->tok.name), HAWK_OOECS_LEN(awk->tok.name), &errnum, &nde->code[0], &nde->code[1]) <= -1) if (hawk_buildrex(awk, HAWK_OOECS_PTR(awk->tok.name), HAWK_OOECS_LEN(awk->tok.name), &nde->code[0], &nde->code[1]) <= -1)
{ {
SETERR_LOC (awk, errnum, xloc); ADJERR_LOC (awk, xloc);
goto oops; goto oops;
} }
@ -7116,11 +7118,7 @@ static hawk_mod_t* query_module (hawk_t* awk, const hawk_oocs_t segs[], int nseg
/* i copy-insert 'md' into the table before calling 'load'. /* i copy-insert 'md' into the table before calling 'load'.
* to pass the same address to load(), query(), etc */ * to pass the same address to load(), query(), etc */
pair = hawk_rbt_insert(awk->modtab, segs[0].ptr, segs[0].len, &md, HAWK_SIZEOF(md)); pair = hawk_rbt_insert(awk->modtab, segs[0].ptr, segs[0].len, &md, HAWK_SIZEOF(md));
if (pair == HAWK_NULL) if (pair == HAWK_NULL) return HAWK_NULL;
{
hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM);
return HAWK_NULL;
}
mdp = (hawk_mod_data_t*)HAWK_RBT_VPTR(pair); mdp = (hawk_mod_data_t*)HAWK_RBT_VPTR(pair);
if (load (&mdp->mod, awk) <= -1) if (load (&mdp->mod, awk) <= -1)
@ -7200,10 +7198,9 @@ static hawk_mod_t* query_module (hawk_t* awk, const hawk_oocs_t segs[], int nseg
/* i copy-insert 'md' into the table before calling 'load'. /* i copy-insert 'md' into the table before calling 'load'.
* to pass the same address to load(), query(), etc */ * to pass the same address to load(), query(), etc */
pair = hawk_rbt_insert (awk->modtab, segs[0].ptr, segs[0].len, &md, HAWK_SIZEOF(md)); pair = hawk_rbt_insert(awk->modtab, segs[0].ptr, segs[0].len, &md, HAWK_SIZEOF(md));
if (pair == HAWK_NULL) if (pair == HAWK_NULL)
{ {
hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM);
awk->prm.modclose (awk, md.handle); awk->prm.modclose (awk, md.handle);
return HAWK_NULL; return HAWK_NULL;
} }

View File

@ -430,16 +430,14 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t
* however, it's not a regular expression if it's 5 character * however, it's not a regular expression if it's 5 character
* string beginning with a question mark. */ * string beginning with a question mark. */
hawk_tre_t* rex, * irex; hawk_tre_t* rex, * irex;
hawk_errnum_t errnum;
if (hawk_buildrex(hawk_rtx_gethawk(rtx), fs_ptr, fs_len, &errnum, &rex, &irex) <= -1) if (hawk_rtx_buildrex(rtx, fs_ptr, fs_len, &rex, &irex) <= -1)
{ {
SETERR_COD (rtx, errnum);
if (vtype != HAWK_VAL_STR) hawk_rtx_freemem (rtx, fs_ptr); if (vtype != HAWK_VAL_STR) hawk_rtx_freemem (rtx, fs_ptr);
return -1; return -1;
} }
if (rtx->gbl.fs[0]) hawk_freerex (hawk_rtx_gethawk(rtx), rtx->gbl.fs[0], rtx->gbl.fs[1]); if (rtx->gbl.fs[0]) hawk_rtx_freerex (rtx, rtx->gbl.fs[0], rtx->gbl.fs[1]);
rtx->gbl.fs[0] = rex; rtx->gbl.fs[0] = rex;
rtx->gbl.fs[1] = irex; rtx->gbl.fs[1] = irex;
@ -575,7 +573,7 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t
if (rtx->gbl.rs[0]) if (rtx->gbl.rs[0])
{ {
hawk_freerex (hawk_rtx_gethawk(rtx), rtx->gbl.rs[0], rtx->gbl.rs[1]); hawk_rtx_freerex (rtx, rtx->gbl.rs[0], rtx->gbl.rs[1]);
rtx->gbl.rs[0] = HAWK_NULL; rtx->gbl.rs[0] = HAWK_NULL;
rtx->gbl.rs[1] = HAWK_NULL; rtx->gbl.rs[1] = HAWK_NULL;
} }
@ -583,12 +581,10 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t
if (rss.len > 1) if (rss.len > 1)
{ {
hawk_tre_t* rex, * irex; hawk_tre_t* rex, * irex;
hawk_errnum_t errnum;
/* compile the regular expression */ /* compile the regular expression */
if (hawk_buildrex(hawk_rtx_gethawk(rtx), rss.ptr, rss.len, &errnum, &rex, &irex) <= -1) if (hawk_rtx_buildrex(rtx, rss.ptr, rss.len, &rex, &irex) <= -1)
{ {
SETERR_COD (rtx, errnum);
if (vtype != HAWK_VAL_STR) hawk_rtx_freemem (rtx, rss.ptr); if (vtype != HAWK_VAL_STR) hawk_rtx_freemem (rtx, rss.ptr);
return -1; return -1;
} }
@ -1014,13 +1010,13 @@ static void fini_rtx (hawk_rtx_t* rtx, int fini_globals)
if (rtx->gbl.rs[0]) if (rtx->gbl.rs[0])
{ {
hawk_freerex (hawk_rtx_gethawk(rtx), rtx->gbl.rs[0], rtx->gbl.rs[1]); hawk_rtx_freerex (rtx, rtx->gbl.rs[0], rtx->gbl.rs[1]);
rtx->gbl.rs[0] = HAWK_NULL; rtx->gbl.rs[0] = HAWK_NULL;
rtx->gbl.rs[1] = HAWK_NULL; rtx->gbl.rs[1] = HAWK_NULL;
} }
if (rtx->gbl.fs[0]) if (rtx->gbl.fs[0])
{ {
hawk_freerex (hawk_rtx_gethawk(rtx), rtx->gbl.fs[0], rtx->gbl.fs[1]); hawk_rtx_freerex (rtx, rtx->gbl.fs[0], rtx->gbl.fs[1]);
rtx->gbl.fs[0] = HAWK_NULL; rtx->gbl.fs[0] = HAWK_NULL;
rtx->gbl.fs[1] = HAWK_NULL; rtx->gbl.fs[1] = HAWK_NULL;
} }
@ -6150,7 +6146,7 @@ static hawk_oow_t push_arg_from_vals (hawk_rtx_t* rtx, hawk_nde_fncall_t* call,
if (!v) if (!v)
{ {
UNWIND_RTX_STACK_ARG (rtx, nargs); UNWIND_RTX_STACK_ARG (rtx, nargs);
SETERR_LOC (rtx, HAWK_ENOMEM, &call->loc); ADJERR_LOC (rtx, &call->loc);
return (hawk_oow_t)-1; return (hawk_oow_t)-1;
} }
@ -7885,7 +7881,6 @@ hawk_bch_t* hawk_rtx_formatmbs (
(buf)->ptr = (hawk_bch_t*)hawk_rtx_allocmem(rtx, (buf)->len * HAWK_SIZEOF(hawk_bch_t)); \ (buf)->ptr = (hawk_bch_t*)hawk_rtx_allocmem(rtx, (buf)->len * HAWK_SIZEOF(hawk_bch_t)); \
if ((buf)->ptr == HAWK_NULL) \ if ((buf)->ptr == HAWK_NULL) \
{ \ { \
SETERR_COD (rtx, HAWK_ENOMEM); \
(buf)->len = 0; \ (buf)->len = 0; \
return HAWK_NULL; \ return HAWK_NULL; \
} \ } \
@ -7901,7 +7896,6 @@ hawk_bch_t* hawk_rtx_formatmbs (
(buf)->ptr = (hawk_bch_t*)hawk_rtx_allocmem(rtx, (buf)->len * HAWK_SIZEOF(hawk_bch_t)); \ (buf)->ptr = (hawk_bch_t*)hawk_rtx_allocmem(rtx, (buf)->len * HAWK_SIZEOF(hawk_bch_t)); \
if ((buf)->ptr == HAWK_NULL) \ if ((buf)->ptr == HAWK_NULL) \
{ \ { \
SETERR_COD (rtx, HAWK_ENOMEM); \
(buf)->len = 0; \ (buf)->len = 0; \
return HAWK_NULL; \ return HAWK_NULL; \
} \ } \
@ -8703,3 +8697,10 @@ hawk_oow_t hawk_rtx_fmttobcstr_ (hawk_rtx_t* rtx, hawk_bch_t* buf, hawk_oow_t bu
va_end(ap); va_end(ap);
return n; return n;
} }
/* ------------------------------------------------------------------------ */
int hawk_rtx_buildrex (hawk_rtx_t* rtx, const hawk_ooch_t* ptn, hawk_oow_t len, hawk_tre_t** code, hawk_tre_t** icode)
{
return hawk_gem_buildrex(hawk_rtx_getgem(rtx), ptn, len, !(hawk_rtx_gethawk(rtx)->opt.trait & HAWK_REXBOUND), code, icode);
}

View File

@ -1520,11 +1520,7 @@ static hawk_ooi_t sf_out (hawk_t* awk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg,
case HAWK_PARSESTD_OOCS: case HAWK_PARSESTD_OOCS:
parsestd_str: parsestd_str:
if (size > HAWK_TYPE_MAX(hawk_ooi_t)) size = HAWK_TYPE_MAX(hawk_ooi_t); if (size > HAWK_TYPE_MAX(hawk_ooi_t)) size = HAWK_TYPE_MAX(hawk_ooi_t);
if (hawk_ooecs_ncat(xtn->s.out.u.oocs.buf, data, size) == (hawk_oow_t)-1) if (hawk_ooecs_ncat(xtn->s.out.u.oocs.buf, data, size) == (hawk_oow_t)-1) return -1;
{
hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM);
return -1;
}
return size; return size;
case HAWK_PARSESTD_BCS: case HAWK_PARSESTD_BCS:
@ -1540,11 +1536,7 @@ static hawk_ooi_t sf_out (hawk_t* awk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg,
if (mbslen > HAWK_TYPE_MAX(hawk_ooi_t)) mbslen = HAWK_TYPE_MAX(hawk_ooi_t); if (mbslen > HAWK_TYPE_MAX(hawk_ooi_t)) mbslen = HAWK_TYPE_MAX(hawk_ooi_t);
orglen = hawk_becs_getlen(xtn->s.out.u.bcs.buf); orglen = hawk_becs_getlen(xtn->s.out.u.bcs.buf);
if (hawk_becs_setlen(xtn->s.out.u.bcs.buf, orglen + mbslen) == (hawk_oow_t)-1) if (hawk_becs_setlen(xtn->s.out.u.bcs.buf, orglen + mbslen) == (hawk_oow_t)-1) return -1;
{
hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM);
return -1;
}
wcslen = size; wcslen = size;
hawk_convutobchars (awk, data, &wcslen, HAWK_BECS_CPTR(xtn->s.out.u.bcs.buf, orglen), &mbslen); hawk_convutobchars (awk, data, &wcslen, HAWK_BECS_CPTR(xtn->s.out.u.bcs.buf, orglen), &mbslen);
@ -1565,11 +1557,7 @@ static hawk_ooi_t sf_out (hawk_t* awk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg,
if (wcslen > HAWK_TYPE_MAX(hawk_ooi_t)) wcslen = HAWK_TYPE_MAX(hawk_ooi_t); if (wcslen > HAWK_TYPE_MAX(hawk_ooi_t)) wcslen = HAWK_TYPE_MAX(hawk_ooi_t);
orglen = hawk_becs_getlen(xtn->s.out.u.ucs.buf); orglen = hawk_becs_getlen(xtn->s.out.u.ucs.buf);
if (hawk_uecs_setlen(xtn->s.out.u.ucs.buf, orglen + wcslen) == (hawk_oow_t)-1) if (hawk_uecs_setlen(xtn->s.out.u.ucs.buf, orglen + wcslen) == (hawk_oow_t)-1) return -1;
{
hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM);
return -1;
}
mbslen = size; mbslen = size;
hawk_convbtouchars (awk, data, &mbslen, HAWK_UECS_CPTR(xtn->s.out.u.ucs.buf, orglen), &wcslen, 0); hawk_convbtouchars (awk, data, &mbslen, HAWK_UECS_CPTR(xtn->s.out.u.ucs.buf, orglen), &wcslen, 0);