removed unneeded code from tre
This commit is contained in:
parent
62664a4e58
commit
9387994622
@ -167,18 +167,18 @@ const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum)
|
|||||||
HAWK_T("invalid character in CONVFMT"),
|
HAWK_T("invalid character in CONVFMT"),
|
||||||
HAWK_T("invalid character in OFMT"),
|
HAWK_T("invalid character in OFMT"),
|
||||||
|
|
||||||
HAWK_T("failed to build regular expression"),
|
|
||||||
HAWK_T("failed to match regular expression"),
|
HAWK_T("failed to match regular expression"),
|
||||||
HAWK_T("recursion too deep in regular expression"),
|
HAWK_T("invalid regular expression in regular expression"),
|
||||||
HAWK_T("right parenthesis expected in regular expression"),
|
HAWK_T("unknown collating element in regular expression"),
|
||||||
HAWK_T("right bracket expected in regular expression"),
|
HAWK_T("unknown character clas name in regular expression"),
|
||||||
HAWK_T("right brace expected in regular expression"),
|
HAWK_T("trailing backslash in regular expression"),
|
||||||
HAWK_T("colon expected in regular expression"),
|
HAWK_T("invalid backreference in regular expression"),
|
||||||
HAWK_T("invalid character range in regular expression"),
|
HAWK_T("imbalanced bracket in regular expression"),
|
||||||
HAWK_T("invalid character class in regular expression"),
|
HAWK_T("imbalanced parenthesis in regular expression"),
|
||||||
HAWK_T("invalid occurrence bound in regular expression"),
|
HAWK_T("imbalanced brace in regular expression"),
|
||||||
HAWK_T("special character at wrong position"),
|
HAWK_T("invalid content inside braces in regular expression"),
|
||||||
HAWK_T("premature end of regular expression")
|
HAWK_T("invalid use of range operator in regular expression"),
|
||||||
|
HAWK_T("invalid use of repetition operator in regular expression")
|
||||||
};
|
};
|
||||||
|
|
||||||
return (errnum >= 0 && errnum < HAWK_COUNTOF(errstr))? errstr[errnum]: HAWK_T("unknown error");
|
return (errnum >= 0 && errnum < HAWK_COUNTOF(errstr))? errstr[errnum]: HAWK_T("unknown error");
|
||||||
|
@ -808,8 +808,8 @@ int hawk_fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
hawk_ooch_t* fs_free = HAWK_NULL;
|
hawk_ooch_t* fs_free = HAWK_NULL;
|
||||||
const hawk_ooch_t* p;
|
const hawk_ooch_t* p;
|
||||||
hawk_oow_t str_left, org_len;
|
hawk_oow_t str_left, org_len;
|
||||||
void* fs_rex = HAWK_NULL;
|
hawk_tre_t* fs_rex = HAWK_NULL;
|
||||||
void* fs_rex_free = HAWK_NULL;
|
hawk_tre_t* fs_rex_free = HAWK_NULL;
|
||||||
|
|
||||||
hawk_oocs_t tok;
|
hawk_oocs_t tok;
|
||||||
hawk_int_t nflds;
|
hawk_int_t nflds;
|
||||||
@ -1082,8 +1082,8 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
|
|||||||
hawk_ooch_t* s0_free = HAWK_NULL;
|
hawk_ooch_t* s0_free = HAWK_NULL;
|
||||||
hawk_ooch_t* s2_free = HAWK_NULL;
|
hawk_ooch_t* s2_free = HAWK_NULL;
|
||||||
|
|
||||||
void* rex = HAWK_NULL;
|
hawk_tre_t* rex = HAWK_NULL;
|
||||||
void* rex_free = HAWK_NULL;
|
hawk_tre_t* rex_free = HAWK_NULL;
|
||||||
|
|
||||||
hawk_ooecs_t new;
|
hawk_ooecs_t new;
|
||||||
int new_inited = 0;
|
int new_inited = 0;
|
||||||
|
@ -898,18 +898,18 @@ enum hawk_errnum_t
|
|||||||
HAWK_EOFMTCHR, /**< invalid character in OFMT */
|
HAWK_EOFMTCHR, /**< invalid character in OFMT */
|
||||||
|
|
||||||
/* regular expression error */
|
/* regular expression error */
|
||||||
HAWK_EREXBL, /**< failed to build regular expression */
|
HAWK_EREXNOMAT, /**< failed to match regular expression */
|
||||||
HAWK_EREXMA, /**< failed to match regular expression */
|
HAWK_EREXBADPAT, /**< invalid regular expression */
|
||||||
HAWK_EREXRECUR, /**< recursion too deep */
|
HAWK_EREXCOLLATE, /**< unknown collating element */
|
||||||
HAWK_EREXRPAREN, /**< a right parenthesis is expected */
|
HAWK_EREXCTYPE, /**< unknown character clas name */
|
||||||
HAWK_EREXRBRACK, /**< a right bracket is expected */
|
HAWK_EREXESCAPE, /**< trailing backslash */
|
||||||
HAWK_EREXRBRACE, /**< a right brace is expected */
|
HAWK_EREXSUBREG, /**< invalid backreference */
|
||||||
HAWK_EREXCOLON, /**< a colon is expected */
|
HAWK_EREXBRACK, /**< imbalanced bracket */
|
||||||
HAWK_EREXCRANGE, /**< invalid character range */
|
HAWK_EREXPAREN, /**< imbalanced parenthesis */
|
||||||
HAWK_EREXCCLASS, /**< invalid character class */
|
HAWK_EREXBRACE, /**< imbalanced brace */
|
||||||
HAWK_EREXBOUND, /**< invalid occurrence bound */
|
HAWK_EREXBADBR, /**< invalid content inside braces */
|
||||||
HAWK_EREXSPCAWP, /**< special character at wrong position */
|
HAWK_EREXRANGE, /**< invalid use of range operator */
|
||||||
HAWK_EREXPREEND, /**< premature end of regular expression */
|
HAWK_EREXBADRPT, /**< invalid use of repetition operator */
|
||||||
|
|
||||||
/* the number of error numbers, internal use only */
|
/* the number of error numbers, internal use only */
|
||||||
HAWK_NUMERRNUM
|
HAWK_NUMERRNUM
|
||||||
|
@ -499,7 +499,14 @@ int hawk_init (hawk_t* awk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_prm
|
|||||||
void hawk_fini (hawk_t* awk);
|
void hawk_fini (hawk_t* awk);
|
||||||
|
|
||||||
|
|
||||||
/* TODO: should i make this public? */
|
/* TODO: should i make these public? */
|
||||||
|
|
||||||
|
#if defined(HAWK_HAVE_INLINE)
|
||||||
|
static HAWK_INLINE hawk_errnum_t hawk_gem_geterrnum (hawk_gem_t* gem) { return gem->errnum; }
|
||||||
|
#else
|
||||||
|
#define hawk_gem_geterrnum(gem) (((hawk_gem_t*)(gem))->errnum)
|
||||||
|
#endif
|
||||||
|
|
||||||
void hawk_gem_seterrnum (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnum_t errnum);
|
void hawk_gem_seterrnum (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnum_t errnum);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
@ -161,10 +161,10 @@ HAWK_EXPORT void hawk_tio_setcmgr (
|
|||||||
* @return 0 on success, -1 on failure
|
* @return 0 on success, -1 on failure
|
||||||
*/
|
*/
|
||||||
HAWK_EXPORT int hawk_tio_attachin (
|
HAWK_EXPORT int hawk_tio_attachin (
|
||||||
hawk_tio_t* tio,
|
hawk_tio_t* tio,
|
||||||
hawk_tio_io_impl_t input,
|
hawk_tio_io_impl_t input,
|
||||||
hawk_bch_t* bufptr,
|
hawk_bch_t* bufptr,
|
||||||
hawk_oow_t bufcapa
|
hawk_oow_t bufcapa
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,42 +29,14 @@
|
|||||||
|
|
||||||
#include <hawk-cmn.h>
|
#include <hawk-cmn.h>
|
||||||
|
|
||||||
enum hawk_tre_errnum_t
|
|
||||||
{
|
|
||||||
HAWK_TRE_ENOERR,
|
|
||||||
HAWK_TRE_EOTHER,
|
|
||||||
HAWK_TRE_ENOIMPL,
|
|
||||||
HAWK_TRE_ESYSERR,
|
|
||||||
HAWK_TRE_EINTERN,
|
|
||||||
|
|
||||||
HAWK_TRE_ENOMEM, /* Out of memory */
|
|
||||||
HAWK_TRE_ENOMATCH, /* No match */
|
|
||||||
HAWK_TRE_EBADPAT, /* Invalid regular expression */
|
|
||||||
HAWK_TRE_ECOLLATE, /* Unknown collating element */
|
|
||||||
HAWK_TRE_ECTYPE, /* Unknown character class name */
|
|
||||||
HAWK_TRE_EESCAPE, /* Traling backslash */
|
|
||||||
HAWK_TRE_ESUBREG, /* Invalid backreference */
|
|
||||||
HAWK_TRE_EBRACK, /* "[]" imbalance */
|
|
||||||
HAWK_TRE_EPAREN, /* "\(\)" or "()" imbalance */
|
|
||||||
HAWK_TRE_EBRACE, /* "\{\}" or "{}" imbalance */
|
|
||||||
HAWK_TRE_EBADBR, /* Invalid content of {} */
|
|
||||||
HAWK_TRE_ERANGE, /* Invalid use of range operator */
|
|
||||||
HAWK_TRE_EBADRPT /* Invalid use of repetition operators */
|
|
||||||
};
|
|
||||||
typedef enum hawk_tre_errnum_t hawk_tre_errnum_t;
|
|
||||||
|
|
||||||
typedef struct hawk_tre_t hawk_tre_t;
|
typedef struct hawk_tre_t hawk_tre_t;
|
||||||
struct hawk_tre_t
|
struct hawk_tre_t
|
||||||
{
|
{
|
||||||
hawk_gem_t* gem;
|
hawk_gem_t* gem;
|
||||||
hawk_tre_errnum_t errnum;
|
|
||||||
|
|
||||||
hawk_oow_t re_nsub; /* Number of parenthesized subexpressions. */
|
hawk_oow_t re_nsub; /* Number of parenthesized subexpressions. */
|
||||||
void* value; /* For internal use only. */
|
void* value; /* For internal use only. */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define HAWK_TRE_ERRNUM(tre) ((const hawk_tre_errnum_t)((tre)->errnum))
|
|
||||||
|
|
||||||
typedef int hawk_tre_off_t;
|
typedef int hawk_tre_off_t;
|
||||||
|
|
||||||
typedef struct hawk_tre_match_t hawk_tre_match_t;
|
typedef struct hawk_tre_match_t hawk_tre_match_t;
|
||||||
@ -132,15 +104,6 @@ static HAWK_INLINE void* hawk_tre_getxtn (hawk_tre_t* tre) { return (void*)(tre
|
|||||||
#define hawk_tre_getxtn(awk) ((void*)((hawk_tre_t*)(tre) + 1))
|
#define hawk_tre_getxtn(awk) ((void*)((hawk_tre_t*)(tre) + 1))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
HAWK_EXPORT hawk_tre_errnum_t hawk_tre_geterrnum (
|
|
||||||
hawk_tre_t* tre
|
|
||||||
);
|
|
||||||
|
|
||||||
HAWK_EXPORT const hawk_ooch_t* hawk_tre_geterrmsg (
|
|
||||||
hawk_tre_t* tre
|
|
||||||
);
|
|
||||||
|
|
||||||
HAWK_EXPORT int hawk_tre_compx (
|
HAWK_EXPORT int hawk_tre_compx (
|
||||||
hawk_tre_t* tre,
|
hawk_tre_t* tre,
|
||||||
const hawk_ooch_t* regex,
|
const hawk_ooch_t* regex,
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <hawk-ecs.h>
|
#include <hawk-ecs.h>
|
||||||
#include <hawk-gem.h>
|
#include <hawk-gem.h>
|
||||||
#include <hawk-htb.h>
|
#include <hawk-htb.h>
|
||||||
|
#include <hawk-tre.h>
|
||||||
#include <hawk-utl.h>
|
#include <hawk-utl.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
@ -224,7 +225,7 @@ struct hawk_val_rex_t
|
|||||||
{
|
{
|
||||||
HAWK_VAL_HDR;
|
HAWK_VAL_HDR;
|
||||||
hawk_oocs_t str;
|
hawk_oocs_t str;
|
||||||
void* code[2];
|
hawk_tre_t* code[2];
|
||||||
};
|
};
|
||||||
typedef struct hawk_val_rex_t hawk_val_rex_t;
|
typedef struct hawk_val_rex_t hawk_val_rex_t;
|
||||||
|
|
||||||
@ -1245,7 +1246,7 @@ enum hawk_trait_t
|
|||||||
HAWK_STRIPSTRSPC | HAWK_STRICTNAMING,
|
HAWK_STRIPSTRSPC | HAWK_STRICTNAMING,
|
||||||
|
|
||||||
HAWK_MODERN =
|
HAWK_MODERN =
|
||||||
HAWK_CLASSIC | HAWK_FLEXMAP |
|
HAWK_CLASSIC | HAWK_FLEXMAP | HAWK_REXBOUND |
|
||||||
HAWK_RWPIPE | HAWK_TOLERANT | HAWK_NEXTOFILE /*| HAWK_NCMPONSTR*/
|
HAWK_RWPIPE | HAWK_TOLERANT | HAWK_NEXTOFILE /*| HAWK_NCMPONSTR*/
|
||||||
};
|
};
|
||||||
typedef enum hawk_trait_t hawk_trait_t;
|
typedef enum hawk_trait_t hawk_trait_t;
|
||||||
@ -2684,7 +2685,7 @@ hawk_val_t* hawk_rtx_makembsvalwithbcs (
|
|||||||
HAWK_EXPORT hawk_val_t* hawk_rtx_makerexval (
|
HAWK_EXPORT hawk_val_t* hawk_rtx_makerexval (
|
||||||
hawk_rtx_t* rtx,
|
hawk_rtx_t* rtx,
|
||||||
const hawk_oocs_t* str,
|
const hawk_oocs_t* str,
|
||||||
void* code[2]
|
hawk_tre_t* code[2]
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
#ifndef _HAWK_MISC_PRV_H_
|
#ifndef _HAWK_MISC_PRV_H_
|
||||||
#define _HAWK_MISC_PRV_H_
|
#define _HAWK_MISC_PRV_H_
|
||||||
|
|
||||||
|
#include <hawk-tre.h>
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -74,17 +76,17 @@ int hawk_buildrex (
|
|||||||
const hawk_ooch_t* ptn,
|
const hawk_ooch_t* ptn,
|
||||||
hawk_oow_t len,
|
hawk_oow_t len,
|
||||||
hawk_errnum_t* errnum,
|
hawk_errnum_t* errnum,
|
||||||
void** code,
|
hawk_tre_t** code,
|
||||||
void** icode
|
hawk_tre_t** icode
|
||||||
);
|
);
|
||||||
|
|
||||||
int hawk_matchrex (
|
int hawk_matchrex (
|
||||||
hawk_t* awk, void* code, int icase,
|
hawk_t* awk, hawk_tre_t* code, int icase,
|
||||||
const hawk_oocs_t* str, const hawk_oocs_t* substr,
|
const hawk_oocs_t* str, const hawk_oocs_t* substr,
|
||||||
hawk_oocs_t* match, hawk_oocs_t submat[9], hawk_errnum_t* errnum
|
hawk_oocs_t* match, hawk_oocs_t submat[9], hawk_errnum_t* errnum
|
||||||
);
|
);
|
||||||
|
|
||||||
void hawk_freerex (hawk_t* awk, void* code, void* icode);
|
void hawk_freerex (hawk_t* awk, hawk_tre_t* code, hawk_tre_t* icode);
|
||||||
|
|
||||||
int hawk_rtx_matchrex (
|
int hawk_rtx_matchrex (
|
||||||
hawk_rtx_t* rtx, hawk_val_t* val,
|
hawk_rtx_t* rtx, hawk_val_t* val,
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "hawk-prv.h"
|
#include "hawk-prv.h"
|
||||||
#include <hawk-tre.h>
|
|
||||||
|
|
||||||
hawk_ooch_t* hawk_rtx_strtok (
|
hawk_ooch_t* hawk_rtx_strtok (
|
||||||
hawk_rtx_t* rtx, const hawk_ooch_t* s,
|
hawk_rtx_t* rtx, const hawk_ooch_t* s,
|
||||||
@ -338,15 +337,13 @@ exit_loop:
|
|||||||
{
|
{
|
||||||
/* if the match reached the last character in the input string,
|
/* if the match reached the last character in the input string,
|
||||||
* it returns HAWK_NULL to terminate tokenization. */
|
* it returns HAWK_NULL to terminate tokenization. */
|
||||||
return (match.ptr+match.len >= substr+sublen)?
|
return (match.ptr+match.len >= substr+sublen)? HAWK_NULL: ((hawk_ooch_t*)match.ptr+match.len);
|
||||||
HAWK_NULL: ((hawk_ooch_t*)match.ptr+match.len);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* if the match went beyond the the last character in the input
|
/* if the match went beyond the the last character in the input
|
||||||
* string, it returns HAWK_NULL to terminate tokenization. */
|
* string, it returns HAWK_NULL to terminate tokenization. */
|
||||||
return (match.ptr+match.len > substr+sublen)?
|
return (match.ptr+match.len > substr+sublen)? HAWK_NULL: ((hawk_ooch_t*)match.ptr+match.len);
|
||||||
HAWK_NULL: ((hawk_ooch_t*)match.ptr+match.len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,9 +436,7 @@ hawk_ooch_t* hawk_rtx_strxnfld (
|
|||||||
return HAWK_NULL;
|
return HAWK_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_buildrex (
|
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_t* awk, const hawk_ooch_t* ptn, hawk_oow_t len,
|
|
||||||
hawk_errnum_t* errnum, void** code, void** icode)
|
|
||||||
{
|
{
|
||||||
hawk_tre_t* tre = HAWK_NULL;
|
hawk_tre_t* tre = HAWK_NULL;
|
||||||
hawk_tre_t* itre = HAWK_NULL;
|
hawk_tre_t* itre = HAWK_NULL;
|
||||||
@ -452,7 +447,7 @@ int hawk_buildrex (
|
|||||||
tre = hawk_tre_open(hawk_getgem(awk), 0);
|
tre = hawk_tre_open(hawk_getgem(awk), 0);
|
||||||
if (tre == HAWK_NULL)
|
if (tre == HAWK_NULL)
|
||||||
{
|
{
|
||||||
*errnum = HAWK_ENOMEM;
|
*errnum = hawk_geterrnum(awk);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,14 +455,7 @@ int hawk_buildrex (
|
|||||||
|
|
||||||
if (hawk_tre_compx(tre, ptn, len, HAWK_NULL, opt) <= -1)
|
if (hawk_tre_compx(tre, ptn, len, HAWK_NULL, opt) <= -1)
|
||||||
{
|
{
|
||||||
#if 0 /* TODO */
|
*errnum = hawk_gem_geterrnum(tre->gem);
|
||||||
|
|
||||||
if (HAWK_TRE_ERRNUM(tre) == HAWK_TRE_ENOMEM) *errnum = HAWK_ENOMEM;
|
|
||||||
else
|
|
||||||
SETERR1 (awk, HAWK_EREXBL, str->ptr, str->len, loc);
|
|
||||||
#endif
|
|
||||||
*errnum = (HAWK_TRE_ERRNUM(tre) == HAWK_TRE_ENOMEM)?
|
|
||||||
HAWK_ENOMEM: HAWK_EREXBL;
|
|
||||||
hawk_tre_close (tre);
|
hawk_tre_close (tre);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -478,22 +466,15 @@ int hawk_buildrex (
|
|||||||
itre = hawk_tre_open(hawk_getgem(awk), 0);
|
itre = hawk_tre_open(hawk_getgem(awk), 0);
|
||||||
if (itre == HAWK_NULL)
|
if (itre == HAWK_NULL)
|
||||||
{
|
{
|
||||||
|
*errnum = hawk_geterrnum(awk);
|
||||||
if (tre) hawk_tre_close (tre);
|
if (tre) hawk_tre_close (tre);
|
||||||
*errnum = HAWK_ENOMEM;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ignorecase is a compile option for TRE */
|
/* ignorecase is a compile option for TRE */
|
||||||
if (hawk_tre_compx(itre, ptn, len, HAWK_NULL, opt | HAWK_TRE_IGNORECASE) <= -1)
|
if (hawk_tre_compx(itre, ptn, len, HAWK_NULL, opt | HAWK_TRE_IGNORECASE) <= -1)
|
||||||
{
|
{
|
||||||
#if 0 /* TODO */
|
*errnum = hawk_gem_geterrnum(itre->gem);
|
||||||
|
|
||||||
if (HAWK_TRE_ERRNUM(tre) == HAWK_TRE_ENOMEM) *errnum = HAWK_ENOMEM;
|
|
||||||
else
|
|
||||||
SETERR1 (awk, HAWK_EREXBL, str->ptr, str->len, loc);
|
|
||||||
#endif
|
|
||||||
*errnum = (HAWK_TRE_ERRNUM(tre) == HAWK_TRE_ENOMEM)?
|
|
||||||
HAWK_ENOMEM: HAWK_EREXBL;
|
|
||||||
hawk_tre_close (itre);
|
hawk_tre_close (itre);
|
||||||
if (tre) hawk_tre_close (tre);
|
if (tre) hawk_tre_close (tre);
|
||||||
return -1;
|
return -1;
|
||||||
@ -506,7 +487,7 @@ int hawk_buildrex (
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int matchtre (
|
static int matchtre (
|
||||||
hawk_t* awk, hawk_tre_t* tre, int opt,
|
hawk_tre_t* tre, int opt,
|
||||||
const hawk_oocs_t* str, hawk_oocs_t* mat,
|
const hawk_oocs_t* str, hawk_oocs_t* mat,
|
||||||
hawk_oocs_t submat[9], hawk_errnum_t* errnum)
|
hawk_oocs_t submat[9], hawk_errnum_t* errnum)
|
||||||
{
|
{
|
||||||
@ -518,19 +499,12 @@ static int matchtre (
|
|||||||
n = hawk_tre_execx(tre, str->ptr, str->len, match, HAWK_COUNTOF(match), opt);
|
n = hawk_tre_execx(tre, str->ptr, str->len, match, HAWK_COUNTOF(match), opt);
|
||||||
if (n <= -1)
|
if (n <= -1)
|
||||||
{
|
{
|
||||||
if (HAWK_TRE_ERRNUM(tre) == HAWK_TRE_ENOMATCH) return 0;
|
if (hawk_gem_geterrnum(tre->gem) == HAWK_EREXNOMAT) return 0;
|
||||||
|
*errnum = hawk_gem_geterrnum(tre->gem);
|
||||||
#if 0 /* TODO: */
|
|
||||||
*errnum = (HAWK_TRE_ERRNUM(tre) == HAWK_TRE_ENOMEM)?
|
|
||||||
HAWK_ENOMEM: HAWK_EREXMA;
|
|
||||||
SETERR0 (sed, errnum, loc);
|
|
||||||
#endif
|
|
||||||
*errnum = (HAWK_TRE_ERRNUM(tre) == HAWK_TRE_ENOMEM)?
|
|
||||||
HAWK_ENOMEM: HAWK_EREXMA;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAWK_ASSERT (awk, match[0].rm_so != -1);
|
/* HAWK_ASSERT (awk, match[0].rm_so != -1); <--- add back with gem*/
|
||||||
if (mat)
|
if (mat)
|
||||||
{
|
{
|
||||||
mat->ptr = &str->ptr[match[0].rm_so];
|
mat->ptr = &str->ptr[match[0].rm_so];
|
||||||
@ -556,7 +530,7 @@ static int matchtre (
|
|||||||
}
|
}
|
||||||
|
|
||||||
int hawk_matchrex (
|
int hawk_matchrex (
|
||||||
hawk_t* awk, void* code, int icase,
|
hawk_t* awk, hawk_tre_t* code, int ignorecase,
|
||||||
const hawk_oocs_t* str, const hawk_oocs_t* substr,
|
const hawk_oocs_t* str, const hawk_oocs_t* substr,
|
||||||
hawk_oocs_t* match, hawk_oocs_t submat[9], hawk_errnum_t* errnum)
|
hawk_oocs_t* match, hawk_oocs_t submat[9], hawk_errnum_t* errnum)
|
||||||
{
|
{
|
||||||
@ -564,39 +538,32 @@ int hawk_matchrex (
|
|||||||
int opt = HAWK_TRE_BACKTRACKING; /* TODO: option... HAWK_TRE_BACKTRACKING ??? */
|
int opt = HAWK_TRE_BACKTRACKING; /* TODO: option... HAWK_TRE_BACKTRACKING ??? */
|
||||||
|
|
||||||
x = matchtre (
|
x = matchtre (
|
||||||
awk, code,
|
code, ((str->ptr == substr->ptr)? opt: (opt | HAWK_TRE_NOTBOL)),
|
||||||
((str->ptr == substr->ptr)? opt: (opt | HAWK_TRE_NOTBOL)),
|
|
||||||
substr, match, submat, errnum
|
substr, match, submat, errnum
|
||||||
);
|
);
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hawk_freerex (hawk_t* awk, void* code, void* icode)
|
void hawk_freerex (hawk_t* awk, hawk_tre_t* code, hawk_tre_t* icode)
|
||||||
{
|
{
|
||||||
if (code)
|
if (icode && icode != code) hawk_tre_close (icode);
|
||||||
{
|
if (code) hawk_tre_close (code);
|
||||||
hawk_tre_close (code);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (icode && icode != code)
|
|
||||||
{
|
|
||||||
hawk_tre_close (icode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_rtx_matchrex (
|
int hawk_rtx_matchrex (
|
||||||
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, hawk_oocs_t* match, hawk_oocs_t submat[9])
|
const hawk_oocs_t* str, const hawk_oocs_t* substr, hawk_oocs_t* match, hawk_oocs_t submat[9])
|
||||||
{
|
{
|
||||||
void* code;
|
hawk_tre_t* code;
|
||||||
int icase, x;
|
int ignorecase, x;
|
||||||
hawk_errnum_t awkerr;
|
hawk_errnum_t awkerr;
|
||||||
|
|
||||||
icase = rtx->gbl.ignorecase;
|
ignorecase = rtx->gbl.ignorecase;
|
||||||
|
|
||||||
if (HAWK_RTX_GETVALTYPE (rtx, val) == HAWK_VAL_REX)
|
if (HAWK_RTX_GETVALTYPE (rtx, val) == HAWK_VAL_REX)
|
||||||
{
|
{
|
||||||
code = ((hawk_val_rex_t*)val)->code[icase];
|
code = ((hawk_val_rex_t*)val)->code[ignorecase];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -606,8 +573,8 @@ int hawk_rtx_matchrex (
|
|||||||
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;
|
||||||
|
|
||||||
x = icase? hawk_buildrex(rtx->awk, tmp.ptr, tmp.len, &awkerr, HAWK_NULL, &code):
|
x = ignorecase? hawk_buildrex(rtx->awk, tmp.ptr, tmp.len, &awkerr, HAWK_NULL, &code):
|
||||||
hawk_buildrex(rtx->awk, tmp.ptr, tmp.len, &awkerr, &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)
|
||||||
{
|
{
|
||||||
@ -617,8 +584,7 @@ int hawk_rtx_matchrex (
|
|||||||
}
|
}
|
||||||
|
|
||||||
x = matchtre (
|
x = matchtre (
|
||||||
rtx->awk, code,
|
code, ((str->ptr == substr->ptr)? HAWK_TRE_BACKTRACKING: (HAWK_TRE_BACKTRACKING | HAWK_TRE_NOTBOL)),
|
||||||
((str->ptr == substr->ptr)? HAWK_TRE_BACKTRACKING: (HAWK_TRE_BACKTRACKING | HAWK_TRE_NOTBOL)),
|
|
||||||
substr, match, submat, &awkerr
|
substr, match, submat, &awkerr
|
||||||
);
|
);
|
||||||
if (x <= -1) hawk_rtx_seterrnum (rtx, awkerr, HAWK_NULL);
|
if (x <= -1) hawk_rtx_seterrnum (rtx, awkerr, HAWK_NULL);
|
||||||
@ -629,7 +595,7 @@ int hawk_rtx_matchrex (
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (icase)
|
if (ignorecase)
|
||||||
hawk_freerex (rtx->awk, HAWK_NULL, code);
|
hawk_freerex (rtx->awk, HAWK_NULL, code);
|
||||||
else
|
else
|
||||||
hawk_freerex (rtx->awk, code, HAWK_NULL);
|
hawk_freerex (rtx->awk, code, HAWK_NULL);
|
||||||
|
@ -91,7 +91,7 @@ void hawk_pma_fini (hawk_pma_t* pma)
|
|||||||
|
|
||||||
void hawk_pma_clear (hawk_pma_t* pma)
|
void hawk_pma_clear (hawk_pma_t* pma)
|
||||||
{
|
{
|
||||||
hawk_t* gem = pma->gem;
|
hawk_gem_t* gem = pma->gem;
|
||||||
hawk_pma_blk_t* tmp, * l = pma->blocks;
|
hawk_pma_blk_t* tmp, * l = pma->blocks;
|
||||||
|
|
||||||
while (l != HAWK_NULL)
|
while (l != HAWK_NULL)
|
||||||
|
@ -219,22 +219,22 @@ static HAWK_INLINE int resolve_rs (hawk_rtx_t* rtx, hawk_val_t* rs, hawk_oocs_t*
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HAWK_INLINE int match_long_rs (hawk_rtx_t* run, hawk_ooecs_t* buf, hawk_rio_arg_t* p)
|
static HAWK_INLINE int match_long_rs (hawk_rtx_t* rtx, hawk_ooecs_t* buf, hawk_rio_arg_t* p)
|
||||||
{
|
{
|
||||||
hawk_oocs_t match;
|
hawk_oocs_t match;
|
||||||
hawk_errnum_t errnum;
|
hawk_errnum_t errnum;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
HAWK_ASSERT (hawk_rtx_gethawk(rtx), run->gbl.rs[0] != HAWK_NULL);
|
HAWK_ASSERT (hawk_rtx_gethawk(rtx), rtx->gbl.rs[0] != HAWK_NULL);
|
||||||
HAWK_ASSERT (hawk_rtx_gethawk(rtx), run->gbl.rs[1] != HAWK_NULL);
|
HAWK_ASSERT (hawk_rtx_gethawk(rtx), rtx->gbl.rs[1] != HAWK_NULL);
|
||||||
|
|
||||||
ret = hawk_matchrex (
|
ret = hawk_matchrex(
|
||||||
run->awk, run->gbl.rs[run->gbl.ignorecase],
|
rtx->awk, rtx->gbl.rs[rtx->gbl.ignorecase],
|
||||||
run->gbl.ignorecase, HAWK_OOECS_OOCS(buf), HAWK_OOECS_OOCS(buf),
|
rtx->gbl.ignorecase, HAWK_OOECS_OOCS(buf), HAWK_OOECS_OOCS(buf),
|
||||||
&match, HAWK_NULL, &errnum);
|
&match, HAWK_NULL, &errnum);
|
||||||
if (ret <= -1)
|
if (ret <= -1)
|
||||||
{
|
{
|
||||||
hawk_rtx_seterrnum (run, errnum, HAWK_NULL);
|
hawk_rtx_seterrnum (rtx, errnum, HAWK_NULL);
|
||||||
}
|
}
|
||||||
else if (ret >= 1)
|
else if (ret >= 1)
|
||||||
{
|
{
|
||||||
@ -246,10 +246,7 @@ static HAWK_INLINE int match_long_rs (hawk_rtx_t* run, hawk_ooecs_t* buf, hawk_r
|
|||||||
* as the previous call to this function.
|
* as the previous call to this function.
|
||||||
* A match in this case must end at the end of
|
* A match in this case must end at the end of
|
||||||
* the current record buffer */
|
* the current record buffer */
|
||||||
HAWK_ASSERT (hawk_rtx_gethawk(rtx),
|
HAWK_ASSERT (hawk_rtx_gethawk(rtx), HAWK_OOECS_PTR(buf) + HAWK_OOECS_LEN(buf) == match.ptr + match.len);
|
||||||
HAWK_OOECS_PTR(buf) + HAWK_OOECS_LEN(buf) ==
|
|
||||||
match.ptr + match.len
|
|
||||||
);
|
|
||||||
|
|
||||||
/* drop the RS part. no extra character after RS to drop
|
/* drop the RS part. no extra character after RS to drop
|
||||||
* because we're at EOF and the EOF condition didn't
|
* because we're at EOF and the EOF condition didn't
|
||||||
|
@ -429,14 +429,13 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t
|
|||||||
/* it's a regular expression if FS contains multiple characters.
|
/* it's a regular expression if FS contains multiple characters.
|
||||||
* 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. */
|
||||||
void* rex, * irex;
|
hawk_tre_t* rex, * irex;
|
||||||
hawk_errnum_t errnum;
|
hawk_errnum_t errnum;
|
||||||
|
|
||||||
if (hawk_buildrex (hawk_rtx_gethawk(rtx), fs_ptr, fs_len, &errnum, &rex, &irex) <= -1)
|
if (hawk_buildrex(hawk_rtx_gethawk(rtx), fs_ptr, fs_len, &errnum, &rex, &irex) <= -1)
|
||||||
{
|
{
|
||||||
SETERR_COD (rtx, errnum);
|
SETERR_COD (rtx, errnum);
|
||||||
if (vtype != HAWK_VAL_STR)
|
if (vtype != HAWK_VAL_STR) hawk_rtx_freemem (rtx, fs_ptr);
|
||||||
hawk_rtx_freemem (rtx, fs_ptr);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,7 +582,7 @@ 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)
|
||||||
{
|
{
|
||||||
void* rex, * irex;
|
hawk_tre_t* rex, * irex;
|
||||||
hawk_errnum_t errnum;
|
hawk_errnum_t errnum;
|
||||||
|
|
||||||
/* compile the regular expression */
|
/* compile the regular expression */
|
||||||
|
@ -180,23 +180,22 @@ typedef hawk_ooci_t tre_cint_t;
|
|||||||
#define size_t hawk_oow_t
|
#define size_t hawk_oow_t
|
||||||
#define regex_t hawk_tre_t
|
#define regex_t hawk_tre_t
|
||||||
#define regmatch_t hawk_tre_match_t
|
#define regmatch_t hawk_tre_match_t
|
||||||
#define reg_errcode_t hawk_tre_errnum_t
|
#define reg_errcode_t hawk_errnum_t
|
||||||
|
|
||||||
|
#define REG_OK HAWK_ENOERR
|
||||||
#define REG_OK HAWK_TRE_ENOERR
|
#define REG_ESPACE HAWK_ENOMEM
|
||||||
#define REG_ESPACE HAWK_TRE_ENOMEM
|
#define REG_NOMATCH HAWK_EREXNOMAT
|
||||||
#define REG_NOMATCH HAWK_TRE_ENOMATCH
|
#define REG_BADPAT HAWK_EREXBADPAT
|
||||||
#define REG_BADPAT HAWK_TRE_EBADPAT
|
#define REG_ECOLLATE HAWK_EREXCOLLATE
|
||||||
#define REG_ECOLLATE HAWK_TRE_ECOLLATE
|
#define REG_ECTYPE HAWK_EREXCTYPE
|
||||||
#define REG_ECTYPE HAWK_TRE_ECTYPE
|
#define REG_EESCAPE HAWK_EREXESCAPE
|
||||||
#define REG_EESCAPE HAWK_TRE_EESCAPE
|
#define REG_ESUBREG HAWK_EREXSUBREG
|
||||||
#define REG_ESUBREG HAWK_TRE_ESUBREG
|
#define REG_EBRACK HAWK_EREXBRACK
|
||||||
#define REG_EBRACK HAWK_TRE_EBRACK
|
#define REG_EPAREN HAWK_EREXPAREN
|
||||||
#define REG_EPAREN HAWK_TRE_EPAREN
|
#define REG_EBRACE HAWK_EREXBRACE
|
||||||
#define REG_EBRACE HAWK_TRE_EBRACE
|
#define REG_BADBR HAWK_EREXBADBR
|
||||||
#define REG_BADBR HAWK_TRE_EBADBR
|
#define REG_ERANGE HAWK_EREXRANGE
|
||||||
#define REG_ERANGE HAWK_TRE_ERANGE
|
#define REG_BADRPT HAWK_EREXBADRPT
|
||||||
#define REG_BADRPT HAWK_TRE_EBADRPT
|
|
||||||
|
|
||||||
/* The maximum number of iterations in a bound expression. */
|
/* The maximum number of iterations in a bound expression. */
|
||||||
#undef RE_DUP_MAX
|
#undef RE_DUP_MAX
|
||||||
|
@ -80,7 +80,7 @@ int hawk_tre_compx (hawk_tre_t* tre, const hawk_ooch_t* regex, hawk_oow_t n, uns
|
|||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
tre->TRE_REGEX_T_FIELD = HAWK_NULL; /* just to make sure */
|
tre->TRE_REGEX_T_FIELD = HAWK_NULL; /* just to make sure */
|
||||||
tre->errnum = ret;
|
hawk_gem_seterrnum (tre->gem, HAWK_NULL, ret);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ int hawk_tre_execx (
|
|||||||
if (tre->TRE_REGEX_T_FIELD == HAWK_NULL)
|
if (tre->TRE_REGEX_T_FIELD == HAWK_NULL)
|
||||||
{
|
{
|
||||||
/* regular expression is bad as none is compiled yet */
|
/* regular expression is bad as none is compiled yet */
|
||||||
tre->errnum = HAWK_TRE_EBADPAT;
|
hawk_gem_seterrnum (tre->gem, HAWK_NULL, HAWK_EREXBADPAT);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#if defined(HAWK_OOCH_IS_UCH)
|
#if defined(HAWK_OOCH_IS_UCH)
|
||||||
@ -230,7 +230,7 @@ int hawk_tre_execx (
|
|||||||
#endif
|
#endif
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
{
|
{
|
||||||
tre->errnum = ret;
|
hawk_gem_seterrnum (tre->gem, HAWK_NULL, ret);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,33 +243,3 @@ int hawk_tre_exec (
|
|||||||
{
|
{
|
||||||
return hawk_tre_execx (tre, str, (hawk_oow_t)-1, pmatch, nmatch, eflags);
|
return hawk_tre_execx (tre, str, (hawk_oow_t)-1, pmatch, nmatch, eflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
hawk_tre_errnum_t hawk_tre_geterrnum (hawk_tre_t* tre)
|
|
||||||
{
|
|
||||||
return tre->errnum;
|
|
||||||
}
|
|
||||||
|
|
||||||
const hawk_ooch_t* hawk_tre_geterrmsg (hawk_tre_t* tre)
|
|
||||||
{
|
|
||||||
static const hawk_ooch_t* errstr[] =
|
|
||||||
{
|
|
||||||
HAWK_T("no error"),
|
|
||||||
HAWK_T("no sufficient memory available"),
|
|
||||||
HAWK_T("no match"),
|
|
||||||
HAWK_T("invalid regular expression"),
|
|
||||||
HAWK_T("unknown collating element"),
|
|
||||||
HAWK_T("unknown character class name"),
|
|
||||||
HAWK_T("trailing backslash"),
|
|
||||||
HAWK_T("invalid backreference"),
|
|
||||||
HAWK_T("bracket imbalance"),
|
|
||||||
HAWK_T("parenthesis imbalance"),
|
|
||||||
HAWK_T("brace imbalance"),
|
|
||||||
HAWK_T("invalid bracket content"),
|
|
||||||
HAWK_T("invalid use of range operator"),
|
|
||||||
HAWK_T("invalid use of repetition operators")
|
|
||||||
};
|
|
||||||
|
|
||||||
return (tre->errnum >= 0 && tre->errnum < HAWK_COUNTOF(errstr))?
|
|
||||||
errstr[tre->errnum]: HAWK_T("unknown error");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ struct hawk_nde_rex_t
|
|||||||
{
|
{
|
||||||
HAWK_NDE_HDR;
|
HAWK_NDE_HDR;
|
||||||
hawk_oocs_t str;
|
hawk_oocs_t str;
|
||||||
void* code[2]; /* [0]: case sensitive, [1]: case insensitive */
|
hawk_tre_t* code[2]; /* [0]: case sensitive, [1]: case insensitive */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* HAWK_NDE_FUN - function as a value */
|
/* HAWK_NDE_FUN - function as a value */
|
||||||
|
@ -142,7 +142,7 @@ extern hawk_val_t* hawk_val_zls;
|
|||||||
void hawk_rtx_freeval (
|
void hawk_rtx_freeval (
|
||||||
hawk_rtx_t* rtx,
|
hawk_rtx_t* rtx,
|
||||||
hawk_val_t* val,
|
hawk_val_t* val,
|
||||||
int cache
|
int cache
|
||||||
);
|
);
|
||||||
|
|
||||||
void hawk_rtx_freevalchunk (
|
void hawk_rtx_freevalchunk (
|
||||||
|
@ -400,7 +400,7 @@ hawk_val_t* hawk_rtx_makembsvalwithbcs (hawk_rtx_t* rtx, const hawk_bcs_t* mxstr
|
|||||||
return hawk_rtx_makembsval(rtx, mxstr->ptr, mxstr->len);
|
return hawk_rtx_makembsval(rtx, mxstr->ptr, mxstr->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
hawk_val_t* hawk_rtx_makerexval (hawk_rtx_t* rtx, const hawk_oocs_t* str, void* code[2])
|
hawk_val_t* hawk_rtx_makerexval (hawk_rtx_t* rtx, const hawk_oocs_t* str, hawk_tre_t* code[2])
|
||||||
{
|
{
|
||||||
hawk_val_rex_t* val;
|
hawk_val_rex_t* val;
|
||||||
hawk_oow_t totsz;
|
hawk_oow_t totsz;
|
||||||
@ -1371,19 +1371,13 @@ int hawk_rtx_valtostr (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_rtx_valtostr_o
|
|||||||
switch (vtype)
|
switch (vtype)
|
||||||
{
|
{
|
||||||
case HAWK_VAL_NIL:
|
case HAWK_VAL_NIL:
|
||||||
{
|
|
||||||
return str_to_str(rtx, HAWK_T(""), 0, out);
|
return str_to_str(rtx, HAWK_T(""), 0, out);
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_INT:
|
case HAWK_VAL_INT:
|
||||||
{
|
|
||||||
return val_int_to_str(rtx, (hawk_val_int_t*)v, out);
|
return val_int_to_str(rtx, (hawk_val_int_t*)v, out);
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_FLT:
|
case HAWK_VAL_FLT:
|
||||||
{
|
|
||||||
return val_flt_to_str(rtx, (hawk_val_flt_t*)v, out);
|
return val_flt_to_str(rtx, (hawk_val_flt_t*)v, out);
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_STR:
|
case HAWK_VAL_STR:
|
||||||
{
|
{
|
||||||
@ -1402,31 +1396,27 @@ int hawk_rtx_valtostr (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_rtx_valtostr_o
|
|||||||
}
|
}
|
||||||
|
|
||||||
case HAWK_VAL_FUN:
|
case HAWK_VAL_FUN:
|
||||||
{
|
|
||||||
return str_to_str(rtx, ((hawk_val_fun_t*)v)->fun->name.ptr, ((hawk_val_fun_t*)v)->fun->name.len, out);
|
return str_to_str(rtx, ((hawk_val_fun_t*)v)->fun->name.ptr, ((hawk_val_fun_t*)v)->fun->name.len, out);
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_MAP:
|
case HAWK_VAL_MAP:
|
||||||
{
|
|
||||||
if (rtx->awk->opt.trait & HAWK_FLEXMAP)
|
if (rtx->awk->opt.trait & HAWK_FLEXMAP)
|
||||||
{
|
{
|
||||||
return str_to_str(rtx, HAWK_T("#MAP"), 4, out);
|
return str_to_str(rtx, HAWK_T("#MAP"), 4, out);
|
||||||
}
|
}
|
||||||
break;
|
goto invalid;
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_REF:
|
case HAWK_VAL_REF:
|
||||||
{
|
|
||||||
return val_ref_to_str(rtx, (hawk_val_ref_t*)v, out);
|
return val_ref_to_str(rtx, (hawk_val_ref_t*)v, out);
|
||||||
}
|
|
||||||
|
case HAWK_VAL_REX:
|
||||||
|
default:
|
||||||
|
invalid:
|
||||||
|
#if defined(DEBUG_VAL)
|
||||||
|
hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_T(">>WRONG VALUE TYPE [%d] in hawk_rtx_valtostr\n"), v->type);
|
||||||
|
#endif
|
||||||
|
hawk_rtx_seterrnum (rtx, HAWK_EVALTOSTR, HAWK_NULL);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(DEBUG_VAL)
|
|
||||||
hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_T(">>WRONG VALUE TYPE [%d] in hawk_rtx_valtostr\n"), v->type);
|
|
||||||
#endif
|
|
||||||
hawk_rtx_seterrnum (rtx, HAWK_EVALTOSTR, HAWK_NULL);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hawk_bch_t* hawk_rtx_valtobcstrdupwithcmgr (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_oow_t* len, hawk_cmgr_t* cmgr)
|
hawk_bch_t* hawk_rtx_valtobcstrdupwithcmgr (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_oow_t* len, hawk_cmgr_t* cmgr)
|
||||||
@ -1664,71 +1654,57 @@ int hawk_rtx_valtonum (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_int_t* l, hawk
|
|||||||
switch (vtype)
|
switch (vtype)
|
||||||
{
|
{
|
||||||
case HAWK_VAL_NIL:
|
case HAWK_VAL_NIL:
|
||||||
{
|
|
||||||
*l = 0;
|
*l = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_INT:
|
case HAWK_VAL_INT:
|
||||||
{
|
|
||||||
*l = HAWK_RTX_GETINTFROMVAL(rtx, v);
|
*l = HAWK_RTX_GETINTFROMVAL(rtx, v);
|
||||||
return 0; /* long */
|
return 0; /* long */
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_FLT:
|
case HAWK_VAL_FLT:
|
||||||
{
|
|
||||||
*r = ((hawk_val_flt_t*)v)->val;
|
*r = ((hawk_val_flt_t*)v)->val;
|
||||||
return 1; /* real */
|
return 1; /* real */
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_STR:
|
case HAWK_VAL_STR:
|
||||||
{
|
|
||||||
return hawk_oochars_to_num(
|
return hawk_oochars_to_num(
|
||||||
HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0),
|
HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0),
|
||||||
((hawk_val_str_t*)v)->val.ptr,
|
((hawk_val_str_t*)v)->val.ptr,
|
||||||
((hawk_val_str_t*)v)->val.len,
|
((hawk_val_str_t*)v)->val.len,
|
||||||
l, r
|
l, r
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_MBS:
|
case HAWK_VAL_MBS:
|
||||||
{
|
|
||||||
return hawk_bchars_to_num(
|
return hawk_bchars_to_num(
|
||||||
HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0),
|
HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0),
|
||||||
((hawk_val_mbs_t*)v)->val.ptr,
|
((hawk_val_mbs_t*)v)->val.ptr,
|
||||||
((hawk_val_mbs_t*)v)->val.len,
|
((hawk_val_mbs_t*)v)->val.len,
|
||||||
l, r
|
l, r
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_FUN:
|
case HAWK_VAL_FUN:
|
||||||
{
|
|
||||||
/* unable to convert a function to a number */
|
/* unable to convert a function to a number */
|
||||||
break;
|
goto invalid;
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_MAP:
|
case HAWK_VAL_MAP:
|
||||||
{
|
|
||||||
if (rtx->awk->opt.trait & HAWK_FLEXMAP)
|
if (rtx->awk->opt.trait & HAWK_FLEXMAP)
|
||||||
{
|
{
|
||||||
*l = HAWK_HTB_SIZE(((hawk_val_map_t*)v)->map);
|
*l = HAWK_HTB_SIZE(((hawk_val_map_t*)v)->map);
|
||||||
return 0; /* long */
|
return 0; /* long */
|
||||||
}
|
}
|
||||||
break;
|
goto invalid;
|
||||||
}
|
|
||||||
|
|
||||||
case HAWK_VAL_REF:
|
case HAWK_VAL_REF:
|
||||||
{
|
|
||||||
return val_ref_to_num(rtx, (hawk_val_ref_t*)v, l, r);
|
return val_ref_to_num(rtx, (hawk_val_ref_t*)v, l, r);
|
||||||
}
|
|
||||||
|
case HAWK_VAL_REX:
|
||||||
|
default:
|
||||||
|
invalid:
|
||||||
|
#if defined(DEBUG_VAL)
|
||||||
|
hawk_logfmt (hawk, HAWK_T(">>WRONG VALUE TYPE [%d] in hawk_rtx_valtonum()\n"), v->type);
|
||||||
|
#endif
|
||||||
|
hawk_rtx_seterrnum (rtx, HAWK_EVALTONUM, HAWK_NULL);
|
||||||
|
return -1; /* error */
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG_VAL)
|
|
||||||
hawk_logfmt (hawk, HAWK_T(">>WRONG VALUE TYPE [%d] in hawk_rtx_valtonum()\n"), v->type);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
hawk_rtx_seterrnum (rtx, HAWK_EVALTONUM, HAWK_NULL);
|
|
||||||
return -1; /* error */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int hawk_rtx_valtoint (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_int_t* l)
|
int hawk_rtx_valtoint (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_int_t* l)
|
||||||
|
Loading…
Reference in New Issue
Block a user