added @pragma stripstrspc on/off

added a new global variable STRIPSTRSPC
This commit is contained in:
hyung-hwan 2020-03-09 08:52:42 +00:00
parent c8e805b159
commit fd56a19a79
12 changed files with 206 additions and 144 deletions

View File

@ -1795,8 +1795,8 @@ int Hawk::call (const hawk_uch_t* name, Value* ret, const Value* args, hawk_oow_
int Hawk::exec (Value* ret, const Value* args, hawk_oow_t nargs) int Hawk::exec (Value* ret, const Value* args, hawk_oow_t nargs)
{ {
return (this->runctx.rtx->awk->parse.pragma.entry[0] != '\0')? return (this->runctx.rtx->hawk->parse.pragma.entry[0] != '\0')?
this->call(this->runctx.rtx->awk->parse.pragma.entry, ret, args, nargs): this->loop(ret); this->call(this->runctx.rtx->hawk->parse.pragma.entry, ret, args, nargs): this->loop(ret);
} }
void Hawk::halt () void Hawk::halt ()

View File

@ -1095,7 +1095,7 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
a1 = hawk_rtx_getarg(rtx, 1); a1 = hawk_rtx_getarg(rtx, 1);
a2 = (nargs >= 3)? hawk_rtx_getarg(rtx, 2): HAWK_NULL; a2 = (nargs >= 3)? hawk_rtx_getarg(rtx, 2): HAWK_NULL;
a0_vtype = HAWK_RTX_GETVALTYPE (rtx, a0); a0_vtype = HAWK_RTX_GETVALTYPE(rtx, a0);
HAWK_ASSERT (a2 == HAWK_NULL || HAWK_RTX_GETVALTYPE(rtx, a2) == HAWK_VAL_REF); HAWK_ASSERT (a2 == HAWK_NULL || HAWK_RTX_GETVALTYPE(rtx, a2) == HAWK_VAL_REF);
if (a0_vtype == HAWK_VAL_REX) if (a0_vtype == HAWK_VAL_REX)
@ -1110,12 +1110,12 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
else else
{ {
s0.ptr = hawk_rtx_valtooocstrdup(rtx, a0, &s0.len); s0.ptr = hawk_rtx_valtooocstrdup(rtx, a0, &s0.len);
if (s0.ptr == HAWK_NULL) goto oops; if (HAWK_UNLIKELY(!s0.ptr)) goto oops;
s0_free = (hawk_ooch_t*)s0.ptr; s0_free = (hawk_ooch_t*)s0.ptr;
} }
s1.ptr = hawk_rtx_getvaloocstr(rtx, a1, &s1.len); s1.ptr = hawk_rtx_getvaloocstr(rtx, a1, &s1.len);
if (s1.ptr == HAWK_NULL) goto oops; if (HAWK_UNLIKELY(!s1.ptr)) goto oops;
if (a2 == HAWK_NULL) if (a2 == HAWK_NULL)
{ {
@ -1126,7 +1126,7 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
else else
{ {
s2.ptr = hawk_rtx_valtooocstrdup(rtx, a2, &s2.len); s2.ptr = hawk_rtx_valtooocstrdup(rtx, a2, &s2.len);
if (s2.ptr == HAWK_NULL) goto oops; if (HAWK_UNLIKELY(!s2.ptr)) goto oops;
s2_free = (hawk_ooch_t*)s2.ptr; s2_free = (hawk_ooch_t*)s2.ptr;
} }
@ -1140,7 +1140,7 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
x = rtx->gbl.ignorecase? x = rtx->gbl.ignorecase?
hawk_rtx_buildrex(rtx, s0.ptr, s0.len, HAWK_NULL, &rex): hawk_rtx_buildrex(rtx, s0.ptr, s0.len, HAWK_NULL, &rex):
hawk_rtx_buildrex(rtx, s0.ptr, s0.len, &rex, HAWK_NULL); hawk_rtx_buildrex(rtx, s0.ptr, s0.len, &rex, HAWK_NULL);
if (x <= -1) goto oops; if (HAWK_UNLIKELY(x <= -1)) goto oops;
rex_free = rex; rex_free = rex;
} }
@ -1163,7 +1163,7 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
if (max_count == 0 || sub_count < max_count) if (max_count == 0 || sub_count < max_count)
{ {
n = hawk_rtx_matchrexwithoocs(rtx, rex, &s2, &cur, &mat, HAWK_NULL); n = hawk_rtx_matchrexwithoocs(rtx, rex, &s2, &cur, &mat, HAWK_NULL);
if (n <= -1) goto oops; if (HAWK_UNLIKELY(n <= -1)) goto oops;
} }
else n = 0; else n = 0;
@ -1187,19 +1187,19 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
{ {
if ((i+1) < s1.len && s1.ptr[i] == HAWK_T('\\') && s1.ptr[i+1] == HAWK_T('&')) if ((i+1) < s1.len && s1.ptr[i] == HAWK_T('\\') && s1.ptr[i+1] == HAWK_T('&'))
{ {
m = hawk_ooecs_ccat (&new, HAWK_T('&')); m = hawk_ooecs_ccat(&new, HAWK_T('&'));
i++; i++;
} }
else if (s1.ptr[i] == HAWK_T('&')) else if (s1.ptr[i] == HAWK_T('&'))
{ {
m = hawk_ooecs_ncat (&new, mat.ptr, mat.len); m = hawk_ooecs_ncat(&new, mat.ptr, mat.len);
} }
else else
{ {
m = hawk_ooecs_ccat (&new, s1.ptr[i]); m = hawk_ooecs_ccat(&new, s1.ptr[i]);
} }
if (m == (hawk_oow_t)-1) goto oops; if (HAWK_UNLIKELY(m == (hawk_oow_t)-1)) goto oops;
} }
sub_count++; sub_count++;
@ -1212,10 +1212,11 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
{ {
skip_one_char: skip_one_char:
/* special treatment is needed if match length is 0 */ /* special treatment is needed if match length is 0 */
if (cur.ptr < s2_end) /* $ matches at s2_end. with this check, '\0' or whatever character after the end may get appended redundantly */
m = hawk_ooecs_ncat(&new, cur.ptr, 1); {
if (m == (hawk_oow_t)-1) goto oops; m = hawk_ooecs_ncat(&new, cur.ptr, 1);
if (HAWK_UNLIKELY(m == (hawk_oow_t)-1)) goto oops;
}
cur.ptr++; cur.len--; cur.ptr++; cur.len--;
} }
} }

View File

@ -349,7 +349,7 @@ struct hawk_chain_t
#define RTX_STACK_LCL(rtx,n) RTX_STACK_AT(rtx,3+(hawk_oow_t)RTX_STACK_NARGS(rtx)+1+(n)) #define RTX_STACK_LCL(rtx,n) RTX_STACK_AT(rtx,3+(hawk_oow_t)RTX_STACK_NARGS(rtx)+1+(n))
#define RTX_STACK_RETVAL(rtx) RTX_STACK_AT(rtx,2) #define RTX_STACK_RETVAL(rtx) RTX_STACK_AT(rtx,2)
#define RTX_STACK_GBL(rtx,n) ((rtx)->stack[(n)]) #define RTX_STACK_GBL(rtx,n) ((rtx)->stack[(n)])
#define RTX_STACK_RETVAL_GBL(rtx) ((rtx)->stack[(rtx)->awk->tree.ngbls+2]) #define RTX_STACK_RETVAL_GBL(rtx) ((rtx)->stack[(rtx)->hawk->tree.ngbls+2])
struct hawk_rtx_t struct hawk_rtx_t
{ {
@ -414,6 +414,7 @@ struct hawk_rtx_t
void* fs[2]; void* fs[2];
int ignorecase; int ignorecase;
int striprecspc; int striprecspc;
int stripstrspc;
hawk_int_t nr; hawk_int_t nr;
hawk_int_t fnr; hawk_int_t fnr;
@ -493,6 +494,10 @@ struct hawk_mod_data_t
(refval)->adr = (_adr); \ (refval)->adr = (_adr); \
} while(0); } while(0);
#define HAWK_RTX_IS_STRIPRECSPC_ON(rtx) ((rtx)->gbl.striprecspc > 0 || ((rtx)->gbl.striprecspc < 0 && ((rtx)->hawk->parse.pragma.trait & HAWK_STRIPRECSPC)))
#define HAWK_RTX_IS_STRIPSTRSPC_ON(rtx) ((rtx)->gbl.stripstrspc > 0 || ((rtx)->gbl.stripstrspc < 0 && ((rtx)->hawk->parse.pragma.trait & HAWK_STRIPSTRSPC)))
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif

View File

@ -379,7 +379,7 @@ void hawk_clear (hawk_t* awk)
awk->parse.depth.loop = 0; awk->parse.depth.loop = 0;
awk->parse.depth.expr = 0; awk->parse.depth.expr = 0;
awk->parse.depth.incl = 0; awk->parse.depth.incl = 0;
awk->parse.pragma.trait = (awk->opt.trait & (HAWK_IMPLICIT | HAWK_STRIPRECSPC)); /* implicit on if you didn't mask it off in awk->opt.trait with hawk_setopt */ awk->parse.pragma.trait = (awk->opt.trait & (HAWK_IMPLICIT | HAWK_STRIPRECSPC | HAWK_STRIPSTRSPC)); /* implicit on if you didn't mask it off in awk->opt.trait with hawk_setopt */
awk->parse.pragma.rtx_stack_limit = 0; awk->parse.pragma.rtx_stack_limit = 0;
awk->parse.pragma.entry[0] = '\0'; awk->parse.pragma.entry[0] = '\0';

View File

@ -52,18 +52,18 @@
* AWK script as shown below: * AWK script as shown below:
* *
* \code * \code
* hawk_t* awk; * hawk_t* hawk;
* hawk_rtx_t* rtx; * hawk_rtx_t* rtx;
* hawk_sio_cbs_t sio; // need to initialize it with callback functions * hawk_sio_cbs_t sio; // need to initialize it with callback functions
* hawk_rio_cbs_t rio; // need to initialize it with callback functions * hawk_rio_cbs_t rio; // need to initialize it with callback functions
* *
* awk = hawk_open(mmgr, 0, prm); // create an interpreter * awk = hawk_open(mmgr, 0, prm); // create an interpreter
* hawk_parse (awk, &sio); // parse a script * hawk_parse (hawk, &sio); // parse a script
* rtx = hawk_rtx_open (awk, 0, &rio); // create a runtime context * rtx = hawk_rtx_open(hawk, 0, &rio); // create a runtime context
* retv = hawk_rtx_loop (rtx); // run a standard AWK loop * retv = hawk_rtx_loop(rtx); // run a standard AWK loop
* if (retv) hawk_rtx_refdownval (rtx, retv); // free return value * if (retv) hawk_rtx_refdownval (rtx, retv); // free return value
* hawk_rtx_close (rtx); // destroy the runtime context * hawk_rtx_close (rtx); // destroy the runtime context
* hawk_close (awk); // destroy the interpreter * hawk_close (hawk); // destroy the interpreter
* \endcode * \endcode
* *
* It provides an interface to change the conventional behavior of the * It provides an interface to change the conventional behavior of the
@ -115,7 +115,7 @@ typedef struct hawk_rtx_t hawk_rtx_t;
hawk_oow_t _instsize; \ hawk_oow_t _instsize; \
hawk_gem_t _gem; \ hawk_gem_t _gem; \
int id; \ int id; \
hawk_t* awk hawk_t* hawk
typedef struct hawk_rtx_alt_t hawk_rtx_alt_t; typedef struct hawk_rtx_alt_t hawk_rtx_alt_t;
struct hawk_rtx_alt_t struct hawk_rtx_alt_t
@ -1316,6 +1316,7 @@ enum hawk_gbl_id_t
HAWK_GBL_RSTART, HAWK_GBL_RSTART,
HAWK_GBL_SCRIPTNAME, HAWK_GBL_SCRIPTNAME,
HAWK_GBL_STRIPRECSPC, HAWK_GBL_STRIPRECSPC,
HAWK_GBL_STRIPSTRSPC,
HAWK_GBL_SUBSEP, HAWK_GBL_SUBSEP,
/* these are not not the actual IDs and are used internally only /* these are not not the actual IDs and are used internally only
@ -2054,14 +2055,14 @@ HAWK_EXPORT void hawk_rtx_close (
); );
#if defined(HAWK_HAVE_INLINE) #if defined(HAWK_HAVE_INLINE)
static HAWK_INLINE hawk_t* hawk_rtx_gethawk (hawk_rtx_t* rtx) { return ((hawk_rtx_alt_t*)rtx)->awk; } static HAWK_INLINE hawk_t* hawk_rtx_gethawk (hawk_rtx_t* rtx) { return ((hawk_rtx_alt_t*)rtx)->hawk; }
static HAWK_INLINE void* hawk_rtx_getxtn (hawk_rtx_t* rtx) { return (void*)((hawk_uint8_t*)rtx + ((hawk_rtx_alt_t*)rtx)->_instsize); } static HAWK_INLINE void* hawk_rtx_getxtn (hawk_rtx_t* rtx) { return (void*)((hawk_uint8_t*)rtx + ((hawk_rtx_alt_t*)rtx)->_instsize); }
static HAWK_INLINE hawk_gem_t* hawk_rtx_getgem (hawk_rtx_t* rtx) { return &((hawk_rtx_alt_t*)rtx)->_gem; } static HAWK_INLINE hawk_gem_t* hawk_rtx_getgem (hawk_rtx_t* rtx) { return &((hawk_rtx_alt_t*)rtx)->_gem; }
static HAWK_INLINE hawk_mmgr_t* hawk_rtx_getmmgr (hawk_rtx_t* rtx) { return ((hawk_rtx_alt_t*)rtx)->_gem.mmgr; } static HAWK_INLINE hawk_mmgr_t* hawk_rtx_getmmgr (hawk_rtx_t* rtx) { return ((hawk_rtx_alt_t*)rtx)->_gem.mmgr; }
static HAWK_INLINE hawk_cmgr_t* hawk_rtx_getcmgr (hawk_rtx_t* rtx) { return ((hawk_rtx_alt_t*)rtx)->_gem.cmgr; } static HAWK_INLINE hawk_cmgr_t* hawk_rtx_getcmgr (hawk_rtx_t* rtx) { return ((hawk_rtx_alt_t*)rtx)->_gem.cmgr; }
static HAWK_INLINE void hawk_rtx_setcmgr (hawk_rtx_t* rtx, hawk_cmgr_t* cmgr) { ((hawk_rtx_alt_t*)rtx)->_gem.cmgr = cmgr; } static HAWK_INLINE void hawk_rtx_setcmgr (hawk_rtx_t* rtx, hawk_cmgr_t* cmgr) { ((hawk_rtx_alt_t*)rtx)->_gem.cmgr = cmgr; }
#else #else
#define hawk_rtx_gethawk(rtx) (((hawk_rtx_alt_t*)(rtx))->awk) #define hawk_rtx_gethawk(rtx) (((hawk_rtx_alt_t*)(rtx))->hawk)
#define hawk_rtx_getxtn(rtx) ((void*)((hawk_uint8_t*)rtx + ((hawk_rtx_alt_t*)rtx)->_instsize)) #define hawk_rtx_getxtn(rtx) ((void*)((hawk_uint8_t*)rtx + ((hawk_rtx_alt_t*)rtx)->_instsize))
#define hawk_rtx_getgem(rtx) (&((hawk_rtx_alt_t*)(rtx))->_gem) #define hawk_rtx_getgem(rtx) (&((hawk_rtx_alt_t*)(rtx))->_gem)
#define hawk_rtx_getmmgr(rtx) (((hawk_rtx_alt_t*)(rtx))->_gem.mmgr) #define hawk_rtx_getmmgr(rtx) (((hawk_rtx_alt_t*)(rtx))->_gem.mmgr)

View File

@ -281,7 +281,7 @@ hawk_ooch_t* hawk_rtx_strxntokbyrex (
cursub.ptr++; cursub.ptr++;
cursub.len--; cursub.len--;
} }
else if (rtx->gbl.striprecspc > 0 || (rtx->gbl.striprecspc < 0 && (rtx->awk->parse.pragma.trait & HAWK_STRIPRECSPC))) else if (HAWK_RTX_IS_STRIPRECSPC_ON(rtx))
{ {
/* match at the beginning of the input string */ /* match at the beginning of the input string */
if (match.ptr == substr) if (match.ptr == substr)
@ -329,7 +329,7 @@ exit_loop:
} }
/* the match is all spaces */ /* the match is all spaces */
if (rtx->gbl.striprecspc > 0 || (rtx->gbl.striprecspc < 0 && (rtx->awk->parse.pragma.trait & HAWK_STRIPRECSPC))) if (HAWK_RTX_IS_STRIPRECSPC_ON(rtx))
{ {
/* 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. */

View File

@ -487,7 +487,7 @@ static int fnc_tonum (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
if (hawk_rtx_valtoint(rtx, a1, &base) <= -1) return -1; if (hawk_rtx_valtoint(rtx, a1, &base) <= -1) return -1;
rx = hawk_bchars_to_num( rx = hawk_bchars_to_num(
HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), base), HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), base),
((hawk_val_mbs_t*)a0)->val.ptr, ((hawk_val_mbs_t*)a0)->val.ptr,
((hawk_val_mbs_t*)a0)->val.len, ((hawk_val_mbs_t*)a0)->val.len,
&lv, &rv &lv, &rv
@ -502,7 +502,7 @@ static int fnc_tonum (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
if (hawk_rtx_valtoint(rtx, a1, &base) <= -1) return -1; if (hawk_rtx_valtoint(rtx, a1, &base) <= -1) return -1;
rx = hawk_oochars_to_num( rx = hawk_oochars_to_num(
HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), base), HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), base),
((hawk_val_str_t*)a0)->val.ptr, ((hawk_val_str_t*)a0)->val.ptr,
((hawk_val_str_t*)a0)->val.len, ((hawk_val_str_t*)a0)->val.len,
&lv, &rv &lv, &rv

View File

@ -375,6 +375,8 @@ static global_t gtab[] =
* if not set, the behavior is dependent on the awk->opt.trait & HAWK_STRIPRECSPC */ * if not set, the behavior is dependent on the awk->opt.trait & HAWK_STRIPRECSPC */
{ HAWK_T("STRIPRECSPC"), 11, 0 }, { HAWK_T("STRIPRECSPC"), 11, 0 },
{ HAWK_T("STRIPSTRSPC"), 11, 0 },
{ HAWK_T("SUBSEP"), 6, 0 } { HAWK_T("SUBSEP"), 6, 0 }
}; };
@ -870,7 +872,7 @@ static int begin_include (hawk_t* awk, int once)
arg->pragma_trait = awk->parse.pragma.trait; arg->pragma_trait = awk->parse.pragma.trait;
/* but don't change awk->parse.pragma.trait. it means the included file inherits /* but don't change awk->parse.pragma.trait. it means the included file inherits
* the existing progma values. * the existing progma values.
awk->parse.pragma.trait = (awk->opt.trait & (HAWK_IMPLICIT | HAWK_STRIPRECSPC)); awk->parse.pragma.trait = (awk->opt.trait & (HAWK_IMPLICIT | HAWK_STRIPRECSPC | HAWK_STRIPSTRSPC));
*/ */
/* i update the current pointer after opening is successful */ /* i update the current pointer after opening is successful */
@ -1049,14 +1051,11 @@ static int parse_progunit (hawk_t* awk)
return -1; return -1;
} }
sl = hawk_oochars_to_int(HAWK_OOECS_PTR(awk->tok.name), HAWK_OOECS_LEN(awk->tok.name), sl = hawk_oochars_to_int(HAWK_OOECS_PTR(awk->tok.name), HAWK_OOECS_LEN(awk->tok.name), HAWK_OOCHARS_TO_INT_MAKE_OPTION(0, 0, 0), HAWK_NULL, HAWK_NULL);
HAWK_OOCHARS_TO_INT_MAKE_OPTION((awk->opt.trait & HAWK_STRIPSTRSPC), (awk->opt.trait & HAWK_STRIPSTRSPC), 0),
HAWK_NULL, HAWK_NULL);
if (sl < HAWK_MIN_RTX_STACK_LIMIT) sl = HAWK_MIN_RTX_STACK_LIMIT; if (sl < HAWK_MIN_RTX_STACK_LIMIT) sl = HAWK_MIN_RTX_STACK_LIMIT;
else if (sl > HAWK_MAX_RTX_STACK_LIMIT) sl = HAWK_MAX_RTX_STACK_LIMIT; else if (sl > HAWK_MAX_RTX_STACK_LIMIT) sl = HAWK_MAX_RTX_STACK_LIMIT;
/* take the specified value if it's greater than the existing value */ /* take the specified value if it's greater than the existing value */
if (sl > awk->parse.pragma.rtx_stack_limit) awk->parse.pragma.rtx_stack_limit = sl; if (sl > awk->parse.pragma.rtx_stack_limit) awk->parse.pragma.rtx_stack_limit = sl;
} }
else if (hawk_comp_oochars_oocstr(name.ptr, name.len, HAWK_T("striprecspc")) == 0) else if (hawk_comp_oochars_oocstr(name.ptr, name.len, HAWK_T("striprecspc")) == 0)
{ {
@ -1100,6 +1099,45 @@ static int parse_progunit (hawk_t* awk)
awk->parse.pragma.trait &= ~HAWK_STRIPRECSPC; awk->parse.pragma.trait &= ~HAWK_STRIPRECSPC;
} }
} }
else if (hawk_comp_oochars_oocstr(name.ptr, name.len, HAWK_T("stripstrspc")) == 0)
{
/* @pragma stripstrspc on
* @pragma stripstrspc off
*/
int is_on;
if (get_token(awk) <= -1) return -1;
if (!MATCH(awk, TOK_IDENT))
{
error_ident_on_off_expected_for_stripstrspc:
hawk_seterrfmt (awk, &awk->ptok.loc, HAWK_EIDENT, HAWK_T("identifier 'on' or 'off' expected for 'stripstrspc'"));
return -1;
}
name.len = HAWK_OOECS_LEN(awk->tok.name);
name.ptr = HAWK_OOECS_PTR(awk->tok.name);
if (hawk_comp_oochars_oocstr(name.ptr, name.len, HAWK_T("on")) == 0)
{
is_on = 1;
}
else if (hawk_comp_oochars_oocstr(name.ptr, name.len, HAWK_T("off")) == 0)
{
is_on = 0;
}
else
{
goto error_ident_on_off_expected_for_stripstrspc;
}
if (awk->sio.inp == &awk->sio.arg)
{
/* only the top level source. ignore stripstrspc pragma in other levels */
if (is_on)
awk->parse.pragma.trait |= HAWK_STRIPSTRSPC;
else
awk->parse.pragma.trait &= ~HAWK_STRIPSTRSPC;
}
}
else else
{ {
hawk_seterrfmt (awk, &awk->ptok.loc, HAWK_EIDENT, HAWK_T("unknown @pragma identifier - %.*js"), name.len, name.ptr); hawk_seterrfmt (awk, &awk->ptok.loc, HAWK_EIDENT, HAWK_T("unknown @pragma identifier - %.*js"), name.len, name.ptr);
@ -4621,17 +4659,17 @@ static hawk_nde_t* parse_primary_int (hawk_t* hawk, const hawk_loc_t* xloc)
/* create the node for the literal */ /* create the node for the literal */
nde = (hawk_nde_int_t*)new_int_node ( nde = (hawk_nde_int_t*)new_int_node (
hawk, hawk,
hawk_oochars_to_int (HAWK_OOECS_PTR(hawk->tok.name), HAWK_OOECS_LEN(hawk->tok.name), HAWK_OOCHARS_TO_INT_MAKE_OPTION((hawk->opt.trait & HAWK_STRIPSTRSPC), (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), HAWK_NULL, HAWK_NULL), hawk_oochars_to_int (HAWK_OOECS_PTR(hawk->tok.name), HAWK_OOECS_LEN(hawk->tok.name), HAWK_OOCHARS_TO_INT_MAKE_OPTION(0, 0, 0), HAWK_NULL, HAWK_NULL),
xloc xloc
); );
if (nde == HAWK_NULL) return HAWK_NULL; if (HAWK_UNLIKELY(!nde)) return HAWK_NULL;
HAWK_ASSERT (HAWK_OOECS_LEN(hawk->tok.name) == hawk_count_oocstr(HAWK_OOECS_PTR(hawk->tok.name))); HAWK_ASSERT (HAWK_OOECS_LEN(hawk->tok.name) == hawk_count_oocstr(HAWK_OOECS_PTR(hawk->tok.name)));
/* remember the literal in the original form */ /* remember the literal in the original form */
nde->len = HAWK_OOECS_LEN(hawk->tok.name); nde->len = HAWK_OOECS_LEN(hawk->tok.name);
nde->str = hawk_dupoocs(hawk, HAWK_OOECS_OOCS(hawk->tok.name)); nde->str = hawk_dupoocs(hawk, HAWK_OOECS_OOCS(hawk->tok.name));
if (nde->str == HAWK_NULL || get_token(hawk) <= -1) goto oops; if (!nde->str || get_token(hawk) <= -1) goto oops;
return (hawk_nde_t*)nde; return (hawk_nde_t*)nde;
@ -4649,10 +4687,10 @@ static hawk_nde_t* parse_primary_flt (hawk_t* hawk, const hawk_loc_t* xloc)
/* create the node for the literal */ /* create the node for the literal */
nde = (hawk_nde_flt_t*)new_flt_node( nde = (hawk_nde_flt_t*)new_flt_node(
hawk, hawk,
hawk_oochars_to_flt(HAWK_OOECS_PTR(hawk->tok.name), HAWK_OOECS_LEN(hawk->tok.name), HAWK_NULL, (hawk->opt.trait & HAWK_STRIPSTRSPC)), hawk_oochars_to_flt(HAWK_OOECS_PTR(hawk->tok.name), HAWK_OOECS_LEN(hawk->tok.name), HAWK_NULL, 0),
xloc xloc
); );
if (nde == HAWK_NULL) return HAWK_NULL; if (HAWK_UNLIKELY(!nde)) return HAWK_NULL;
HAWK_ASSERT ( HAWK_ASSERT (
HAWK_OOECS_LEN(hawk->tok.name) == HAWK_OOECS_LEN(hawk->tok.name) ==
@ -4661,7 +4699,7 @@ static hawk_nde_t* parse_primary_flt (hawk_t* hawk, const hawk_loc_t* xloc)
/* remember the literal in the original form */ /* remember the literal in the original form */
nde->len = HAWK_OOECS_LEN(hawk->tok.name); nde->len = HAWK_OOECS_LEN(hawk->tok.name);
nde->str = hawk_dupoocs(hawk, HAWK_OOECS_OOCS(hawk->tok.name)); nde->str = hawk_dupoocs(hawk, HAWK_OOECS_OOCS(hawk->tok.name));
if (nde->str == HAWK_NULL || get_token(hawk) <= -1) goto oops; if (!nde->str || get_token(hawk) <= -1) goto oops;
return (hawk_nde_t*)nde; return (hawk_nde_t*)nde;

View File

@ -437,7 +437,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
if (HAWK_OOECS_LASTCHAR(buf) == HAWK_T('\n')) if (HAWK_OOECS_LASTCHAR(buf) == HAWK_T('\n'))
{ {
HAWK_OOECS_LEN(buf) -= 1; HAWK_OOECS_LEN(buf) -= 1;
if (rtx->awk->opt.trait & HAWK_CRLF) if (rtx->hawk->opt.trait & HAWK_CRLF)
{ {
/* drop preceding CR */ /* drop preceding CR */
if (HAWK_OOECS_LEN(buf) > 0 && HAWK_OOECS_LASTCHAR(buf) == HAWK_T('\r')) HAWK_OOECS_LEN(buf) -= 1; if (HAWK_OOECS_LEN(buf) > 0 && HAWK_OOECS_LASTCHAR(buf) == HAWK_T('\r')) HAWK_OOECS_LEN(buf) -= 1;
@ -541,7 +541,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
/* we don't drop CR from the record buffer /* we don't drop CR from the record buffer
* if we're in CRLF mode. POINT-X */ * if we're in CRLF mode. POINT-X */
if (!(rtx->awk->opt.trait & HAWK_CRLF)) if (!(rtx->hawk->opt.trait & HAWK_CRLF))
HAWK_OOECS_LEN(buf) -= 1; HAWK_OOECS_LEN(buf) -= 1;
} }
@ -549,7 +549,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
{ {
/* we got a blank line */ /* we got a blank line */
if (rtx->awk->opt.trait & HAWK_CRLF) if (rtx->hawk->opt.trait & HAWK_CRLF)
{ {
if (HAWK_OOECS_LEN(buf) > 0 && HAWK_OOECS_LASTCHAR(buf) == HAWK_T('\r')) if (HAWK_OOECS_LEN(buf) > 0 && HAWK_OOECS_LASTCHAR(buf) == HAWK_T('\r'))
{ {
@ -755,7 +755,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
if (HAWK_BECS_LASTCHAR(buf) == '\n') if (HAWK_BECS_LASTCHAR(buf) == '\n')
{ {
HAWK_BECS_LEN(buf) -= 1; HAWK_BECS_LEN(buf) -= 1;
if (rtx->awk->opt.trait & HAWK_CRLF) if (rtx->hawk->opt.trait & HAWK_CRLF)
{ {
/* drop preceding CR */ /* drop preceding CR */
if (HAWK_BECS_LEN(buf) > 0 && HAWK_BECS_LASTCHAR(buf) == '\r') HAWK_BECS_LEN(buf) -= 1; if (HAWK_BECS_LEN(buf) > 0 && HAWK_BECS_LASTCHAR(buf) == '\r') HAWK_BECS_LEN(buf) -= 1;
@ -859,7 +859,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
/* we don't drop CR from the record buffer /* we don't drop CR from the record buffer
* if we're in CRLF mode. POINT-X */ * if we're in CRLF mode. POINT-X */
if (!(rtx->awk->opt.trait & HAWK_CRLF)) if (!(rtx->hawk->opt.trait & HAWK_CRLF))
HAWK_BECS_LEN(buf) -= 1; HAWK_BECS_LEN(buf) -= 1;
} }
@ -867,7 +867,7 @@ int hawk_rtx_readiobytes (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name,
{ {
/* we got a blank line */ /* we got a blank line */
if (rtx->awk->opt.trait & HAWK_CRLF) if (rtx->hawk->opt.trait & HAWK_CRLF)
{ {
if (HAWK_BECS_LEN(buf) > 0 && HAWK_BECS_LASTCHAR(buf) == '\r') if (HAWK_BECS_LEN(buf) > 0 && HAWK_BECS_LASTCHAR(buf) == '\r')
{ {

View File

@ -232,7 +232,7 @@ HAWK_INLINE hawk_val_t* hawk_rtx_getarg (hawk_rtx_t* rtx, hawk_oow_t idx)
HAWK_INLINE hawk_val_t* hawk_rtx_getgbl (hawk_rtx_t* rtx, int id) HAWK_INLINE hawk_val_t* hawk_rtx_getgbl (hawk_rtx_t* rtx, int id)
{ {
HAWK_ASSERT (id >= 0 && id < (int)HAWK_ARR_SIZE(rtx->awk->parse.gbls)); HAWK_ASSERT (id >= 0 && id < (int)HAWK_ARR_SIZE(rtx->hawk->parse.gbls));
return RTX_STACK_GBL(rtx, id); return RTX_STACK_GBL(rtx, id);
} }
@ -255,7 +255,7 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t
vtype = HAWK_RTX_GETVALTYPE (rtx, val); vtype = HAWK_RTX_GETVALTYPE (rtx, val);
old_vtype = HAWK_RTX_GETVALTYPE (rtx, old); old_vtype = HAWK_RTX_GETVALTYPE (rtx, old);
if (!(rtx->awk->opt.trait & HAWK_FLEXMAP)) if (!(rtx->hawk->opt.trait & HAWK_FLEXMAP))
{ {
hawk_errnum_t errnum = HAWK_ENOERR; hawk_errnum_t errnum = HAWK_ENOERR;
const hawk_ooch_t* errfmt; const hawk_ooch_t* errfmt;
@ -619,6 +619,22 @@ static int set_global (hawk_rtx_t* rtx, int idx, hawk_nde_var_t* var, hawk_val_t
break; break;
} }
case HAWK_GBL_STRIPSTRSPC:
{
hawk_int_t l;
hawk_flt_t r;
int vt;
vt = hawk_rtx_valtonum(rtx, val, &l, &r);
if (vt <= -1) return -1;
if (vt == 0)
rtx->gbl.stripstrspc = ((l > 0)? 1: (l < 0)? -1: 0);
else
rtx->gbl.stripstrspc = ((r > 0.0)? 1: (r < 0.0)? -1: 0);
break;
}
case HAWK_GBL_SUBSEP: case HAWK_GBL_SUBSEP:
{ {
hawk_rtx_valtostr_out_t out; hawk_rtx_valtostr_out_t out;
@ -656,7 +672,7 @@ HAWK_INLINE void hawk_rtx_setretval (hawk_rtx_t* rtx, hawk_val_t* val)
HAWK_INLINE int hawk_rtx_setgbl (hawk_rtx_t* rtx, int id, hawk_val_t* val) HAWK_INLINE int hawk_rtx_setgbl (hawk_rtx_t* rtx, int id, hawk_val_t* val)
{ {
HAWK_ASSERT (id >= 0 && id < (int)HAWK_ARR_SIZE(rtx->awk->parse.gbls)); HAWK_ASSERT (id >= 0 && id < (int)HAWK_ARR_SIZE(rtx->hawk->parse.gbls));
return set_global(rtx, id, HAWK_NULL, val, 0); return set_global(rtx, id, HAWK_NULL, val, 0);
} }
@ -762,7 +778,7 @@ int hawk_rtx_setofilenamewithuchars (hawk_rtx_t* rtx, const hawk_uch_t* name, ha
hawk_val_t* tmp; hawk_val_t* tmp;
int n; int n;
if (rtx->awk->opt.trait & HAWK_NEXTOFILE) if (rtx->hawk->opt.trait & HAWK_NEXTOFILE)
{ {
tmp = hawk_rtx_makestrvalwithuchars(rtx, name, len); tmp = hawk_rtx_makestrvalwithuchars(rtx, name, len);
if (HAWK_UNLIKELY(!tmp)) return -1; if (HAWK_UNLIKELY(!tmp)) return -1;
@ -781,7 +797,7 @@ int hawk_rtx_setofilenamewithbchars (hawk_rtx_t* rtx, const hawk_bch_t* name, ha
hawk_val_t* tmp; hawk_val_t* tmp;
int n; int n;
if (rtx->awk->opt.trait & HAWK_NEXTOFILE) if (rtx->hawk->opt.trait & HAWK_NEXTOFILE)
{ {
tmp = hawk_rtx_makestrvalwithbchars(rtx, name, len); tmp = hawk_rtx_makestrvalwithbchars(rtx, name, len);
if (HAWK_UNLIKELY(!tmp)) return -1; if (HAWK_UNLIKELY(!tmp)) return -1;
@ -891,15 +907,15 @@ hawk_rtx_t* hawk_rtx_open (hawk_t* awk, hawk_oow_t xtnsize, hawk_rio_cbs_t* rio)
mic.count = 0; mic.count = 0;
mic.rtx = rtx; mic.rtx = rtx;
hawk_rbt_walk (rtx->awk->modtab, init_module, &mic); hawk_rbt_walk (rtx->hawk->modtab, init_module, &mic);
if (mic.count != HAWK_RBT_SIZE(rtx->awk->modtab)) if (mic.count != HAWK_RBT_SIZE(rtx->hawk->modtab))
{ {
if (mic.count > 0) if (mic.count > 0)
{ {
struct module_fini_ctx_t mfc; struct module_fini_ctx_t mfc;
mfc.limit = mic.count; mfc.limit = mic.count;
mfc.count = 0; mfc.count = 0;
hawk_rbt_walk (rtx->awk->modtab, fini_module, &mfc); hawk_rbt_walk (rtx->hawk->modtab, fini_module, &mfc);
} }
fini_rtx (rtx, 1); fini_rtx (rtx, 1);
@ -918,7 +934,7 @@ void hawk_rtx_close (hawk_rtx_t* rtx)
mfc.limit = 0; mfc.limit = 0;
mfc.count = 0; mfc.count = 0;
mfc.rtx = rtx; mfc.rtx = rtx;
hawk_rbt_walk (rtx->awk->modtab, fini_module, &mfc); hawk_rbt_walk (rtx->hawk->modtab, fini_module, &mfc);
for (ecb = rtx->ecb; ecb; ecb = ecb->next) for (ecb = rtx->ecb; ecb; ecb = ecb->next)
{ {
@ -943,7 +959,7 @@ void hawk_rtx_halt (hawk_rtx_t* rtx)
int hawk_rtx_ishalt (hawk_rtx_t* rtx) int hawk_rtx_ishalt (hawk_rtx_t* rtx)
{ {
return (rtx->exit_level == EXIT_ABORT || rtx->awk->haltall); return (rtx->exit_level == EXIT_ABORT || rtx->hawk->haltall);
} }
void hawk_rtx_getrio (hawk_rtx_t* rtx, hawk_rio_cbs_t* rio) void hawk_rtx_getrio (hawk_rtx_t* rtx, hawk_rio_cbs_t* rio)
@ -1003,7 +1019,7 @@ static int init_rtx (hawk_rtx_t* rtx, hawk_t* awk, hawk_rio_cbs_t* rio)
hawk_oow_t stack_limit; hawk_oow_t stack_limit;
rtx->_gem = awk->_gem; rtx->_gem = awk->_gem;
rtx->awk = awk; rtx->hawk = awk;
CLRERR (rtx); CLRERR (rtx);
@ -1054,11 +1070,11 @@ static int init_rtx (hawk_rtx_t* rtx, hawk_t* awk, hawk_rio_cbs_t* rio)
rtx->formatmbs.tmp.len = 4096; rtx->formatmbs.tmp.len = 4096;
rtx->formatmbs.tmp.inc = 4096 * 2; rtx->formatmbs.tmp.inc = 4096 * 2;
if (rtx->awk->tree.chain_size > 0) if (rtx->hawk->tree.chain_size > 0)
{ {
rtx->pattern_range_state = (hawk_oob_t*)hawk_rtx_allocmem(rtx, rtx->awk->tree.chain_size * HAWK_SIZEOF(hawk_oob_t)); rtx->pattern_range_state = (hawk_oob_t*)hawk_rtx_allocmem(rtx, rtx->hawk->tree.chain_size * HAWK_SIZEOF(hawk_oob_t));
if (!rtx->pattern_range_state) goto oops_12; if (!rtx->pattern_range_state) goto oops_12;
HAWK_MEMSET (rtx->pattern_range_state, 0, rtx->awk->tree.chain_size * HAWK_SIZEOF(hawk_oob_t)); HAWK_MEMSET (rtx->pattern_range_state, 0, rtx->hawk->tree.chain_size * HAWK_SIZEOF(hawk_oob_t));
} }
else rtx->pattern_range_state = HAWK_NULL; else rtx->pattern_range_state = HAWK_NULL;
@ -1075,7 +1091,8 @@ static int init_rtx (hawk_rtx_t* rtx, hawk_t* awk, hawk_rio_cbs_t* rio)
rtx->gbl.fs[0] = HAWK_NULL; rtx->gbl.fs[0] = HAWK_NULL;
rtx->gbl.fs[1] = HAWK_NULL; rtx->gbl.fs[1] = HAWK_NULL;
rtx->gbl.ignorecase = 0; rtx->gbl.ignorecase = 0;
rtx->gbl.striprecspc = -1; rtx->gbl.striprecspc = -1; /* means 'not set' */
rtx->gbl.stripstrspc = -1; /* means 'not set' */
return 0; return 0;
@ -1280,7 +1297,7 @@ static int prepare_globals (hawk_rtx_t* rtx)
hawk_oow_t ngbls; hawk_oow_t ngbls;
saved_stack_top = rtx->stack_top; saved_stack_top = rtx->stack_top;
ngbls = rtx->awk->tree.ngbls; ngbls = rtx->hawk->tree.ngbls;
/* initialize all global variables to nil by push nils to the stack */ /* initialize all global variables to nil by push nils to the stack */
while (ngbls > 0) while (ngbls > 0)
@ -1337,7 +1354,7 @@ static int defaultify_globals (hawk_rtx_t* rtx)
hawk_oow_t i, j; hawk_oow_t i, j;
int stridx; int stridx;
stridx = (rtx->awk->opt.trait & HAWK_CRLF)? 1: 0; stridx = (rtx->hawk->opt.trait & HAWK_CRLF)? 1: 0;
for (i = 0; i < HAWK_COUNTOF(gtab); i++) for (i = 0; i < HAWK_COUNTOF(gtab); i++)
{ {
if (gtab[i].str[stridx] == HAWK_NULL || gtab[i].str[stridx][0] == HAWK_T('\0')) if (gtab[i].str[stridx] == HAWK_NULL || gtab[i].str[stridx][0] == HAWK_T('\0'))
@ -1371,17 +1388,17 @@ static int defaultify_globals (hawk_rtx_t* rtx)
return 0; return 0;
} }
static void refdown_globals (hawk_rtx_t* run, int pop) static void refdown_globals (hawk_rtx_t* rtx, int pop)
{ {
hawk_oow_t ngbls; hawk_oow_t ngbls;
ngbls = run->awk->tree.ngbls; ngbls = rtx->hawk->tree.ngbls;
while (ngbls > 0) while (ngbls > 0)
{ {
--ngbls; --ngbls;
hawk_rtx_refdownval (run, RTX_STACK_GBL(run,ngbls)); hawk_rtx_refdownval (rtx, RTX_STACK_GBL(rtx,ngbls));
if (pop) __raw_pop (run); if (pop) __raw_pop (rtx);
else RTX_STACK_GBL(run,ngbls) = hawk_val_nil; else RTX_STACK_GBL(rtx,ngbls) = hawk_val_nil;
} }
} }
@ -1469,7 +1486,7 @@ static hawk_val_t* run_bpae_loop (hawk_rtx_t* rtx)
RTX_STACK_NARGS(rtx) = (void*)nargs; RTX_STACK_NARGS(rtx) = (void*)nargs;
/* execute the BEGIN block */ /* execute the BEGIN block */
for (nde = rtx->awk->tree.begin; for (nde = rtx->hawk->tree.begin;
ret == 0 && nde != HAWK_NULL && rtx->exit_level < EXIT_GLOBAL; ret == 0 && nde != HAWK_NULL && rtx->exit_level < EXIT_GLOBAL;
nde = nde->next) nde = nde->next)
{ {
@ -1495,8 +1512,8 @@ static hawk_val_t* run_bpae_loop (hawk_rtx_t* rtx)
/* run pattern block loops */ /* run pattern block loops */
if (ret == 0 && if (ret == 0 &&
(rtx->awk->tree.chain != HAWK_NULL || (rtx->hawk->tree.chain != HAWK_NULL ||
rtx->awk->tree.end != HAWK_NULL) && rtx->hawk->tree.end != HAWK_NULL) &&
rtx->exit_level < EXIT_GLOBAL) rtx->exit_level < EXIT_GLOBAL)
{ {
if (run_pblocks(rtx) <= -1) ret = -1; if (run_pblocks(rtx) <= -1) ret = -1;
@ -1514,7 +1531,7 @@ static hawk_val_t* run_bpae_loop (hawk_rtx_t* rtx)
/* execute END blocks. the first END block is executed if the /* execute END blocks. the first END block is executed if the
* program is not explicitly aborted with hawk_rtx_halt().*/ * program is not explicitly aborted with hawk_rtx_halt().*/
for (nde = rtx->awk->tree.end; for (nde = rtx->hawk->tree.end;
ret == 0 && nde != HAWK_NULL && rtx->exit_level < EXIT_ABORT; ret == 0 && nde != HAWK_NULL && rtx->exit_level < EXIT_ABORT;
nde = nde->next) nde = nde->next)
{ {
@ -1585,15 +1602,15 @@ hawk_val_t* hawk_rtx_loop (hawk_rtx_t* rtx)
hawk_val_t* hawk_rtx_execwithucstrarr (hawk_rtx_t* rtx, const hawk_uch_t* args[], hawk_oow_t nargs) hawk_val_t* hawk_rtx_execwithucstrarr (hawk_rtx_t* rtx, const hawk_uch_t* args[], hawk_oow_t nargs)
{ {
return (rtx->awk->parse.pragma.entry[0] != '\0')? return (rtx->hawk->parse.pragma.entry[0] != '\0')?
hawk_rtx_callwithooucstrarr(rtx, rtx->awk->parse.pragma.entry, args, nargs): hawk_rtx_callwithooucstrarr(rtx, rtx->hawk->parse.pragma.entry, args, nargs):
hawk_rtx_loop(rtx); hawk_rtx_loop(rtx);
} }
hawk_val_t* hawk_rtx_execwithbcstrarr (hawk_rtx_t* rtx, const hawk_bch_t* args[], hawk_oow_t nargs) hawk_val_t* hawk_rtx_execwithbcstrarr (hawk_rtx_t* rtx, const hawk_bch_t* args[], hawk_oow_t nargs)
{ {
return (rtx->awk->parse.pragma.entry[0] != '\0')? return (rtx->hawk->parse.pragma.entry[0] != '\0')?
hawk_rtx_callwithoobcstrarr(rtx, rtx->awk->parse.pragma.entry, args, nargs): hawk_rtx_callwithoobcstrarr(rtx, rtx->hawk->parse.pragma.entry, args, nargs):
hawk_rtx_loop(rtx); hawk_rtx_loop(rtx);
} }
@ -1603,7 +1620,7 @@ static hawk_fun_t* find_fun (hawk_rtx_t* rtx, const hawk_ooch_t* name)
{ {
hawk_htb_pair_t* pair; hawk_htb_pair_t* pair;
pair = hawk_htb_search(rtx->awk->tree.funs, name, hawk_count_oocstr(name)); pair = hawk_htb_search(rtx->hawk->tree.funs, name, hawk_count_oocstr(name));
if (!pair) if (!pair)
{ {
hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EFUNNF, HAWK_T("unable to find function '%js'"), name); hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EFUNNF, HAWK_T("unable to find function '%js'"), name);
@ -1870,16 +1887,16 @@ static int run_pblocks (hawk_rtx_t* rtx)
int n; int n;
#define ADJUST_ERROR(run) \ #define ADJUST_ERROR(run) \
if (rtx->awk->tree.chain != HAWK_NULL) \ if (rtx->hawk->tree.chain != HAWK_NULL) \
{ \ { \
if (rtx->awk->tree.chain->pattern != HAWK_NULL) \ if (rtx->hawk->tree.chain->pattern != HAWK_NULL) \
ADJERR_LOC (rtx, &rtx->awk->tree.chain->pattern->loc); \ ADJERR_LOC (rtx, &rtx->hawk->tree.chain->pattern->loc); \
else if (rtx->awk->tree.chain->action != HAWK_NULL) \ else if (rtx->hawk->tree.chain->action != HAWK_NULL) \
ADJERR_LOC (rtx, &rtx->awk->tree.chain->action->loc); \ ADJERR_LOC (rtx, &rtx->hawk->tree.chain->action->loc); \
} \ } \
else if (rtx->awk->tree.end != HAWK_NULL) \ else if (rtx->hawk->tree.end != HAWK_NULL) \
{ \ { \
ADJERR_LOC (run, &rtx->awk->tree.end->loc); \ ADJERR_LOC (run, &rtx->hawk->tree.end->loc); \
} }
rtx->inrec.buf_pos = 0; rtx->inrec.buf_pos = 0;
@ -1899,9 +1916,9 @@ static int run_pblocks (hawk_rtx_t* rtx)
} }
if (n == 0) break; /* end of input */ if (n == 0) break; /* end of input */
if (rtx->awk->tree.chain) if (rtx->hawk->tree.chain)
{ {
if (run_pblock_chain(rtx, rtx->awk->tree.chain) <= -1) return -1; if (run_pblock_chain(rtx, rtx->hawk->tree.chain) <= -1) return -1;
} }
} }
@ -2096,8 +2113,8 @@ static int run_block (hawk_rtx_t* rtx, hawk_nde_blk_t* nde)
{ {
int n; int n;
if (rtx->awk->opt.depth.s.block_run > 0 && if (rtx->hawk->opt.depth.s.block_run > 0 &&
rtx->depth.block >= rtx->awk->opt.depth.s.block_run) rtx->depth.block >= rtx->hawk->opt.depth.s.block_run)
{ {
hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_EBLKNST); hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_EBLKNST);
return -1;; return -1;;
@ -2112,7 +2129,7 @@ static int run_block (hawk_rtx_t* rtx, hawk_nde_blk_t* nde)
#define ON_STATEMENT(rtx,nde) do { \ #define ON_STATEMENT(rtx,nde) do { \
hawk_rtx_ecb_t* ecb; \ hawk_rtx_ecb_t* ecb; \
if ((rtx)->awk->haltall) (rtx)->exit_level = EXIT_ABORT; \ if ((rtx)->hawk->haltall) (rtx)->exit_level = EXIT_ABORT; \
for (ecb = (rtx)->ecb; ecb; ecb = ecb->next) \ for (ecb = (rtx)->ecb; ecb; ecb = ecb->next) \
if (ecb->stmt) ecb->stmt (rtx, nde); \ if (ecb->stmt) ecb->stmt (rtx, nde); \
} while(0) } while(0)
@ -2185,12 +2202,12 @@ static int run_statement (hawk_rtx_t* rtx, hawk_nde_t* nde)
break; break;
case HAWK_NDE_PRINT: case HAWK_NDE_PRINT:
if (rtx->awk->opt.trait & HAWK_TOLERANT) goto __fallback__; if (rtx->hawk->opt.trait & HAWK_TOLERANT) goto __fallback__;
xret = run_print(rtx, (hawk_nde_print_t*)nde); xret = run_print(rtx, (hawk_nde_print_t*)nde);
break; break;
case HAWK_NDE_PRINTF: case HAWK_NDE_PRINTF:
if (rtx->awk->opt.trait & HAWK_TOLERANT) goto __fallback__; if (rtx->hawk->opt.trait & HAWK_TOLERANT) goto __fallback__;
xret = run_printf(rtx, (hawk_nde_print_t*)nde); xret = run_printf(rtx, (hawk_nde_print_t*)nde);
break; break;
@ -2531,7 +2548,7 @@ static int run_return (hawk_rtx_t* rtx, hawk_nde_return_t* nde)
val = eval_expression (rtx, nde->val); val = eval_expression (rtx, nde->val);
if (val == HAWK_NULL) return -1; if (val == HAWK_NULL) return -1;
if (!(rtx->awk->opt.trait & HAWK_FLEXMAP)) if (!(rtx->hawk->opt.trait & HAWK_FLEXMAP))
{ {
if (HAWK_RTX_GETVALTYPE (rtx, val) == HAWK_VAL_MAP) if (HAWK_RTX_GETVALTYPE (rtx, val) == HAWK_VAL_MAP)
{ {
@ -2582,12 +2599,12 @@ static int run_next (hawk_rtx_t* rtx, hawk_nde_next_t* nde)
/* the parser checks if next has been called in the begin/end /* the parser checks if next has been called in the begin/end
* block or whereever inappropriate. so the rtxtime doesn't * block or whereever inappropriate. so the rtxtime doesn't
* check that explicitly */ * check that explicitly */
if (rtx->active_block == (hawk_nde_blk_t*)rtx->awk->tree.begin) if (rtx->active_block == (hawk_nde_blk_t*)rtx->hawk->tree.begin)
{ {
hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_ERNEXTBEG); hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_ERNEXTBEG);
return -1; return -1;
} }
else if (rtx->active_block == (hawk_nde_blk_t*)rtx->awk->tree.end) else if (rtx->active_block == (hawk_nde_blk_t*)rtx->hawk->tree.end)
{ {
hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_ERNEXTEND); hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_ERNEXTEND);
return -1; return -1;
@ -2602,12 +2619,12 @@ static int run_nextinfile (hawk_rtx_t* rtx, hawk_nde_nextfile_t* nde)
int n; int n;
/* normal nextfile statement */ /* normal nextfile statement */
if (rtx->active_block == (hawk_nde_blk_t*)rtx->awk->tree.begin) if (rtx->active_block == (hawk_nde_blk_t*)rtx->hawk->tree.begin)
{ {
hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_ERNEXTFBEG); hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_ERNEXTFBEG);
return -1; return -1;
} }
else if (rtx->active_block == (hawk_nde_blk_t*)rtx->awk->tree.end) else if (rtx->active_block == (hawk_nde_blk_t*)rtx->hawk->tree.end)
{ {
hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_ERNEXTFEND); hawk_rtx_seterrnum (rtx, &nde->loc, HAWK_ERNEXTFEND);
return -1; return -1;
@ -3028,7 +3045,7 @@ static int run_print (hawk_rtx_t* rtx, hawk_nde_print_t* nde)
n = hawk_rtx_writeiostr(rtx, nde->out_type, out.ptr, HAWK_OOECS_PTR(&rtx->inrec.line), HAWK_OOECS_LEN(&rtx->inrec.line)); n = hawk_rtx_writeiostr(rtx, nde->out_type, out.ptr, HAWK_OOECS_PTR(&rtx->inrec.line), HAWK_OOECS_LEN(&rtx->inrec.line));
if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/)
{ {
if (rtx->awk->opt.trait & HAWK_TOLERANT) if (rtx->hawk->opt.trait & HAWK_TOLERANT)
{ {
xret = PRINT_IOERR; xret = PRINT_IOERR;
} }
@ -3060,7 +3077,7 @@ static int run_print (hawk_rtx_t* rtx, hawk_nde_print_t* nde)
n = hawk_rtx_writeiostr(rtx, nde->out_type, out.ptr, rtx->gbl.ofs.ptr, rtx->gbl.ofs.len); n = hawk_rtx_writeiostr(rtx, nde->out_type, out.ptr, rtx->gbl.ofs.ptr, rtx->gbl.ofs.len);
if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/)
{ {
if (rtx->awk->opt.trait & HAWK_TOLERANT) if (rtx->hawk->opt.trait & HAWK_TOLERANT)
{ {
xret = PRINT_IOERR; xret = PRINT_IOERR;
} }
@ -3080,7 +3097,7 @@ static int run_print (hawk_rtx_t* rtx, hawk_nde_print_t* nde)
if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/)
{ {
if (rtx->awk->opt.trait & HAWK_TOLERANT) if (rtx->hawk->opt.trait & HAWK_TOLERANT)
{ {
xret = PRINT_IOERR; xret = PRINT_IOERR;
} }
@ -3096,7 +3113,7 @@ static int run_print (hawk_rtx_t* rtx, hawk_nde_print_t* nde)
n = hawk_rtx_writeiostr(rtx, nde->out_type, out.ptr, rtx->gbl.ors.ptr, rtx->gbl.ors.len); n = hawk_rtx_writeiostr(rtx, nde->out_type, out.ptr, rtx->gbl.ors.ptr, rtx->gbl.ors.len);
if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/)
{ {
if (rtx->awk->opt.trait & HAWK_TOLERANT) if (rtx->hawk->opt.trait & HAWK_TOLERANT)
{ {
xret = PRINT_IOERR; xret = PRINT_IOERR;
} }
@ -3207,7 +3224,7 @@ static int run_printf (hawk_rtx_t* rtx, hawk_nde_print_t* nde)
if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/)
{ {
if (rtx->awk->opt.trait & HAWK_TOLERANT) xret = PRINT_IOERR; if (rtx->hawk->opt.trait & HAWK_TOLERANT) xret = PRINT_IOERR;
else goto oops; else goto oops;
} }
break; break;
@ -3215,7 +3232,7 @@ static int run_printf (hawk_rtx_t* rtx, hawk_nde_print_t* nde)
if (hawk_rtx_flushio(rtx, nde->out_type, out.ptr) <= -1) if (hawk_rtx_flushio(rtx, nde->out_type, out.ptr) <= -1)
{ {
if (rtx->awk->opt.trait & HAWK_TOLERANT) xret = PRINT_IOERR; if (rtx->hawk->opt.trait & HAWK_TOLERANT) xret = PRINT_IOERR;
else goto oops_1; else goto oops_1;
} }
@ -3254,7 +3271,7 @@ static int output_formatted (
n = hawk_rtx_writeiostr(rtx, out_type, dst, ptr, len); n = hawk_rtx_writeiostr(rtx, out_type, dst, ptr, len);
if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/)
{ {
return (rtx->awk->opt.trait & HAWK_TOLERANT)? PRINT_IOERR: -1; return (rtx->hawk->opt.trait & HAWK_TOLERANT)? PRINT_IOERR: -1;
} }
return 0; return 0;
@ -3274,7 +3291,7 @@ static int output_formatted_bytes (
n = hawk_rtx_writeiobytes(rtx, out_type, dst, ptr, len); n = hawk_rtx_writeiobytes(rtx, out_type, dst, ptr, len);
if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/) if (n <= -1 /*&& rtx->errinf.num != HAWK_EIOIMPL*/)
{ {
return (rtx->awk->opt.trait & HAWK_TOLERANT)? PRINT_IOERR: -1; return (rtx->hawk->opt.trait & HAWK_TOLERANT)? PRINT_IOERR: -1;
} }
return 0; return 0;
@ -3602,7 +3619,7 @@ static hawk_val_t* do_assignment_nonidx (hawk_rtx_t* rtx, hawk_nde_var_t* var, h
pair = hawk_htb_search(rtx->named, var->id.name.ptr, var->id.name.len); pair = hawk_htb_search(rtx->named, var->id.name.ptr, var->id.name.len);
if (!(rtx->awk->opt.trait & HAWK_FLEXMAP)) if (!(rtx->hawk->opt.trait & HAWK_FLEXMAP))
{ {
if (pair && HAWK_RTX_GETVALTYPE(rtx, (hawk_val_t*)HAWK_HTB_VPTR(pair)) == HAWK_VAL_MAP) if (pair && HAWK_RTX_GETVALTYPE(rtx, (hawk_val_t*)HAWK_HTB_VPTR(pair)) == HAWK_VAL_MAP)
{ {
@ -3646,7 +3663,7 @@ static hawk_val_t* do_assignment_nonidx (hawk_rtx_t* rtx, hawk_nde_var_t* var, h
{ {
hawk_val_t* old = RTX_STACK_LCL(rtx,var->id.idxa); hawk_val_t* old = RTX_STACK_LCL(rtx,var->id.idxa);
if (!(rtx->awk->opt.trait & HAWK_FLEXMAP)) if (!(rtx->hawk->opt.trait & HAWK_FLEXMAP))
{ {
if (HAWK_RTX_GETVALTYPE(rtx, old) == HAWK_VAL_MAP) if (HAWK_RTX_GETVALTYPE(rtx, old) == HAWK_VAL_MAP)
{ {
@ -3676,7 +3693,7 @@ static hawk_val_t* do_assignment_nonidx (hawk_rtx_t* rtx, hawk_nde_var_t* var, h
{ {
hawk_val_t* old = RTX_STACK_ARG(rtx,var->id.idxa); hawk_val_t* old = RTX_STACK_ARG(rtx,var->id.idxa);
if (!(rtx->awk->opt.trait & HAWK_FLEXMAP)) if (!(rtx->hawk->opt.trait & HAWK_FLEXMAP))
{ {
if (HAWK_RTX_GETVALTYPE(rtx, old) == HAWK_VAL_MAP) if (HAWK_RTX_GETVALTYPE(rtx, old) == HAWK_VAL_MAP)
{ {
@ -3809,7 +3826,7 @@ retry:
} }
else if (mvtype != HAWK_VAL_MAP) else if (mvtype != HAWK_VAL_MAP)
{ {
if (rtx->awk->opt.trait & HAWK_FLEXMAP) if (rtx->hawk->opt.trait & HAWK_FLEXMAP)
{ {
/* if FLEXMAP is on, you can switch a scalar value to a map */ /* if FLEXMAP is on, you can switch a scalar value to a map */
hawk_nde_var_t fake; hawk_nde_var_t fake;
@ -4361,7 +4378,7 @@ static HAWK_INLINE int __cmp_int_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
hawk_flt_t rr; hawk_flt_t rr;
n = hawk_oochars_to_num( n = hawk_oochars_to_num(
HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0),
((hawk_val_str_t*)right)->val.ptr, ((hawk_val_str_t*)right)->val.ptr,
((hawk_val_str_t*)right)->val.len, ((hawk_val_str_t*)right)->val.len,
&ll, &rr &ll, &rr
@ -4401,7 +4418,7 @@ static HAWK_INLINE int __cmp_int_mbs (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
hawk_flt_t rr; hawk_flt_t rr;
n = hawk_bchars_to_num ( n = hawk_bchars_to_num (
HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0),
((hawk_val_mbs_t*)right)->val.ptr, ((hawk_val_mbs_t*)right)->val.ptr,
((hawk_val_mbs_t*)right)->val.len, ((hawk_val_mbs_t*)right)->val.len,
&ll, &rr &ll, &rr
@ -4482,7 +4499,7 @@ static HAWK_INLINE int __cmp_flt_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
const hawk_ooch_t* end; const hawk_ooch_t* end;
hawk_flt_t rr; hawk_flt_t rr;
rr = hawk_oochars_to_flt(((hawk_val_str_t*)right)->val.ptr, ((hawk_val_str_t*)right)->val.len, &end, (hawk->opt.trait & HAWK_STRIPSTRSPC)); rr = hawk_oochars_to_flt(((hawk_val_str_t*)right)->val.ptr, ((hawk_val_str_t*)right)->val.len, &end, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx));
if (end == ((hawk_val_str_t*)right)->val.ptr + ((hawk_val_str_t*)right)->val.len) if (end == ((hawk_val_str_t*)right)->val.ptr + ((hawk_val_str_t*)right)->val.len)
{ {
return (((hawk_val_flt_t*)left)->val > rr)? 1: return (((hawk_val_flt_t*)left)->val > rr)? 1:
@ -4510,7 +4527,7 @@ static HAWK_INLINE int __cmp_flt_mbs (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
const hawk_bch_t* end; const hawk_bch_t* end;
hawk_flt_t rr; hawk_flt_t rr;
rr = hawk_bchars_to_flt(((hawk_val_mbs_t*)right)->val.ptr, ((hawk_val_mbs_t*)right)->val.len, &end, (hawk->opt.trait & HAWK_STRIPSTRSPC)); rr = hawk_bchars_to_flt(((hawk_val_mbs_t*)right)->val.ptr, ((hawk_val_mbs_t*)right)->val.len, &end, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx));
if (end == ((hawk_val_mbs_t*)right)->val.ptr + ((hawk_val_mbs_t*)right)->val.len) if (end == ((hawk_val_mbs_t*)right)->val.ptr + ((hawk_val_mbs_t*)right)->val.len)
{ {
return (((hawk_val_flt_t*)left)->val > rr)? 1: return (((hawk_val_flt_t*)left)->val > rr)? 1:
@ -4572,13 +4589,13 @@ static HAWK_INLINE int __cmp_str_str (hawk_rtx_t* rtx, hawk_val_t* left, hawk_va
ls = (hawk_val_str_t*)left; ls = (hawk_val_str_t*)left;
rs = (hawk_val_str_t*)right; rs = (hawk_val_str_t*)right;
if (ls->nstr == 0 || rs->nstr == 0) if (HAWK_LIKELY(ls->nstr == 0 || rs->nstr == 0))
{ {
/* both are definitely strings */ /* both are definitely strings */
return hawk_comp_oochars(ls->val.ptr, ls->val.len, rs->val.ptr, rs->val.len, rtx->gbl.ignorecase); return hawk_comp_oochars(ls->val.ptr, ls->val.len, rs->val.ptr, rs->val.len, rtx->gbl.ignorecase);
} }
stripspc = (hawk->opt.trait & HAWK_STRIPSTRSPC); stripspc = HAWK_RTX_IS_STRIPSTRSPC_ON(rtx);
if (ls->nstr == 1) if (ls->nstr == 1)
{ {
@ -4831,7 +4848,7 @@ static HAWK_INLINE int __cmp_val (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t*
lvtype = HAWK_RTX_GETVALTYPE(rtx, left); lvtype = HAWK_RTX_GETVALTYPE(rtx, left);
rvtype = HAWK_RTX_GETVALTYPE(rtx, right); rvtype = HAWK_RTX_GETVALTYPE(rtx, right);
if (!(rtx->awk->opt.trait & HAWK_FLEXMAP) && if (!(rtx->hawk->opt.trait & HAWK_FLEXMAP) &&
(lvtype == HAWK_VAL_MAP || rvtype == HAWK_VAL_MAP)) (lvtype == HAWK_VAL_MAP || rvtype == HAWK_VAL_MAP))
{ {
/* a map can't be compared againt other values */ /* a map can't be compared againt other values */
@ -5201,7 +5218,7 @@ static hawk_val_t* eval_binop_mod (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t
hawk_val_t* res; hawk_val_t* res;
/* the mod function must be provided when the awk object is created to be able to calculate floating-pointer remainder */ /* the mod function must be provided when the awk object is created to be able to calculate floating-pointer remainder */
HAWK_ASSERT (rtx->awk->prm.math.mod != HAWK_NULL); HAWK_ASSERT (rtx->hawk->prm.math.mod != HAWK_NULL);
n1 = hawk_rtx_valtonum(rtx, left, &l1, &r1); n1 = hawk_rtx_valtonum(rtx, left, &l1, &r1);
n2 = hawk_rtx_valtonum(rtx, right, &l2, &r2); n2 = hawk_rtx_valtonum(rtx, right, &l2, &r2);
@ -5225,15 +5242,15 @@ static hawk_val_t* eval_binop_mod (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t
break; break;
case 1: case 1:
res = hawk_rtx_makefltval(rtx, rtx->awk->prm.math.mod(hawk_rtx_gethawk(rtx), (hawk_flt_t)r1, (hawk_flt_t)l2)); res = hawk_rtx_makefltval(rtx, rtx->hawk->prm.math.mod(hawk_rtx_gethawk(rtx), (hawk_flt_t)r1, (hawk_flt_t)l2));
break; break;
case 2: case 2:
res = hawk_rtx_makefltval(rtx, rtx->awk->prm.math.mod(hawk_rtx_gethawk(rtx), (hawk_flt_t)l1, (hawk_flt_t)r2)); res = hawk_rtx_makefltval(rtx, rtx->hawk->prm.math.mod(hawk_rtx_gethawk(rtx), (hawk_flt_t)l1, (hawk_flt_t)r2));
break; break;
case 3: case 3:
res = hawk_rtx_makefltval(rtx, rtx->awk->prm.math.mod(hawk_rtx_gethawk(rtx), (hawk_flt_t)r1, (hawk_flt_t)r2)); res = hawk_rtx_makefltval(rtx, rtx->hawk->prm.math.mod(hawk_rtx_gethawk(rtx), (hawk_flt_t)r1, (hawk_flt_t)r2));
break; break;
} }
@ -5307,7 +5324,7 @@ static hawk_val_t* eval_binop_exp (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t
/* left - int, right - real */ /* left - int, right - real */
res = hawk_rtx_makefltval ( res = hawk_rtx_makefltval (
rtx, rtx,
rtx->awk->prm.math.pow(hawk_rtx_gethawk(rtx), (hawk_flt_t)l1, (hawk_flt_t)r2) rtx->hawk->prm.math.pow(hawk_rtx_gethawk(rtx), (hawk_flt_t)l1, (hawk_flt_t)r2)
); );
break; break;
@ -5315,7 +5332,7 @@ static hawk_val_t* eval_binop_exp (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t
/* left - real, right - real */ /* left - real, right - real */
res = hawk_rtx_makefltval ( res = hawk_rtx_makefltval (
rtx, rtx,
rtx->awk->prm.math.pow(hawk_rtx_gethawk(rtx), (hawk_flt_t)r1,(hawk_flt_t)r2) rtx->hawk->prm.math.pow(hawk_rtx_gethawk(rtx), (hawk_flt_t)r1,(hawk_flt_t)r2)
); );
break; break;
} }
@ -5836,7 +5853,7 @@ static HAWK_INLINE hawk_val_t* eval_fncall_fun_ex (hawk_rtx_t* rtx, hawk_nde_t*
* hoping that the pointer assignment is atomic. (call->u.fun.fun = fun). * hoping that the pointer assignment is atomic. (call->u.fun.fun = fun).
* i don't mind each instance performs a search duplicately for a short while */ * i don't mind each instance performs a search duplicately for a short while */
pair = hawk_htb_search(rtx->awk->tree.funs, call->u.fun.name.ptr, call->u.fun.name.len); pair = hawk_htb_search(rtx->hawk->tree.funs, call->u.fun.name.ptr, call->u.fun.name.len);
if (!pair) if (!pair)
{ {
hawk_rtx_seterrfmt (rtx, &nde->loc, HAWK_EFUNNF, HAWK_T("function '%.*js' not found"), call->u.fun.name.len, call->u.fun.name.ptr); hawk_rtx_seterrfmt (rtx, &nde->loc, HAWK_EFUNNF, HAWK_T("function '%.*js' not found"), call->u.fun.name.len, call->u.fun.name.ptr);
@ -6585,7 +6602,7 @@ static hawk_val_t* eval_fun (hawk_rtx_t* rtx, hawk_nde_t* nde)
* the funptr field in the node can be HAWK_NULL */ * the funptr field in the node can be HAWK_NULL */
/* TODO: support builtin functions?, support module functions? */ /* TODO: support builtin functions?, support module functions? */
pair = hawk_htb_search(rtx->awk->tree.funs, ((hawk_nde_fun_t*)nde)->name.ptr, ((hawk_nde_fun_t*)nde)->name.len); pair = hawk_htb_search(rtx->hawk->tree.funs, ((hawk_nde_fun_t*)nde)->name.ptr, ((hawk_nde_fun_t*)nde)->name.len);
if (!pair) if (!pair)
{ {
/* it's unlikely to be not found in the function table for the parser structure. but keep this code in case */ /* it's unlikely to be not found in the function table for the parser structure. but keep this code in case */

View File

@ -2029,7 +2029,7 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod)
/* this part is more complex than the code in the else part. /* this part is more complex than the code in the else part.
* it handles simple assignemnt as well as open files * it handles simple assignemnt as well as open files
* via in ARGV instead of rxtn->c.in.files */ * via in ARGV instead of rxtn->c.in.files */
xtn_t* xtn = (xtn_t*)GET_XTN(rtx->awk); xtn_t* xtn = (xtn_t*)GET_XTN(hawk_rtx_gethawk(rtx));
hawk_val_t* v_argc, * v_argv, * v_pair; hawk_val_t* v_argc, * v_argv, * v_pair;
hawk_int_t i_argc; hawk_int_t i_argc;
const hawk_ooch_t* file; const hawk_ooch_t* file;
@ -2391,7 +2391,7 @@ static hawk_ooi_t awk_rio_console (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio
static void fini_rxtn (hawk_rtx_t* rtx) static void fini_rxtn (hawk_rtx_t* rtx)
{ {
rxtn_t* rxtn = GET_RXTN(rtx); rxtn_t* rxtn = GET_RXTN(rtx);
/*xtn_t* xtn = (xtn_t*)GET_XTN(rtx->awk);*/ /*xtn_t* xtn = (xtn_t*)GET_XTN(hawk_rtx_gethawk(rtx));*/
if (rxtn->c.in.files) if (rxtn->c.in.files)
{ {
@ -2685,7 +2685,7 @@ static hawk_rtx_t* open_rtx_std (
rxtn = GET_RXTN(rtx); rxtn = GET_RXTN(rtx);
if (rtx->awk->opt.trait & HAWK_RIO) if (rtx->hawk->opt.trait & HAWK_RIO)
{ {
if (hawk_htb_init(&rxtn->cmgrtab, hawk_getgem(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1) <= -1) if (hawk_htb_init(&rxtn->cmgrtab, hawk_getgem(awk), 256, 70, HAWK_SIZEOF(hawk_ooch_t), 1) <= -1)
{ {
@ -2990,7 +2990,7 @@ static int fnc_setioattr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
/* no error is returned by hawk_rtx_strnum() if the strict option /* no error is returned by hawk_rtx_strnum() if the strict option
* of the second parameter is 0. so i don't check for an error */ * of the second parameter is 0. so i don't check for an error */
x = hawk_oochars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr[2], len[2], &l, &r); x = hawk_oochars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr[2], len[2], &l, &r);
if (x == 0) r = (hawk_flt_t)l; if (x == 0) r = (hawk_flt_t)l;
ioattr = find_or_make_ioattr(rtx, &rxtn->cmgrtab, ptr[0], len[0]); ioattr = find_or_make_ioattr(rtx, &rxtn->cmgrtab, ptr[0], len[0]);

View File

@ -307,7 +307,7 @@ hawk_val_t* hawk_rtx_makenumorstrvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_
hawk_int_t l; hawk_int_t l;
hawk_flt_t r; hawk_flt_t r;
x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 1, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr, len, &l, &r); x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 1, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r);
if (x == 0) return hawk_rtx_makeintval(rtx, l); if (x == 0) return hawk_rtx_makeintval(rtx, l);
else if (x >= 1) return hawk_rtx_makefltval(rtx, r); else if (x >= 1) return hawk_rtx_makefltval(rtx, r);
@ -321,7 +321,7 @@ hawk_val_t* hawk_rtx_makenumorstrvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_
hawk_int_t l; hawk_int_t l;
hawk_flt_t r; hawk_flt_t r;
x = hawk_bchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 1, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr, len, &l, &r); x = hawk_bchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 1, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r);
if (x == 0) return hawk_rtx_makeintval(rtx, l); if (x == 0) return hawk_rtx_makeintval(rtx, l);
else if (x >= 1) return hawk_rtx_makefltval(rtx, r); else if (x >= 1) return hawk_rtx_makefltval(rtx, r);
@ -339,7 +339,7 @@ hawk_val_t* hawk_rtx_makenstrvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_t* p
hawk_int_t l; hawk_int_t l;
hawk_flt_t r; hawk_flt_t r;
x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr, len, &l, &r); x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r);
v = hawk_rtx_makestrvalwithuchars(rtx, ptr, len); v = hawk_rtx_makestrvalwithuchars(rtx, ptr, len);
if (!v) return HAWK_NULL; if (!v) return HAWK_NULL;
@ -363,7 +363,7 @@ hawk_val_t* hawk_rtx_makenstrvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_t* p
hawk_int_t l; hawk_int_t l;
hawk_flt_t r; hawk_flt_t r;
x = hawk_bchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr, len, &l, &r); x = hawk_bchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r);
v = hawk_rtx_makestrvalwithbchars(rtx, ptr, len); v = hawk_rtx_makestrvalwithbchars(rtx, ptr, len);
if (!v) return HAWK_NULL; if (!v) return HAWK_NULL;
@ -465,7 +465,7 @@ hawk_val_t* hawk_rtx_makenumormbsvalwithuchars (hawk_rtx_t* rtx, const hawk_uch_
hawk_int_t l; hawk_int_t l;
hawk_flt_t r; hawk_flt_t r;
x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 1, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr, len, &l, &r); x = hawk_uchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 1, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r);
if (x == 0) return hawk_rtx_makeintval(rtx, l); if (x == 0) return hawk_rtx_makeintval(rtx, l);
else if (x >= 1) return hawk_rtx_makefltval(rtx, r); else if (x >= 1) return hawk_rtx_makefltval(rtx, r);
@ -479,7 +479,7 @@ hawk_val_t* hawk_rtx_makenumormbsvalwithbchars (hawk_rtx_t* rtx, const hawk_bch_
hawk_int_t l; hawk_int_t l;
hawk_flt_t r; hawk_flt_t r;
x = hawk_bchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 1, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), ptr, len, &l, &r); x = hawk_bchars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(1, 1, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), ptr, len, &l, &r);
if (x == 0) return hawk_rtx_makeintval(rtx, l); if (x == 0) return hawk_rtx_makeintval(rtx, l);
else if (x >= 1) return hawk_rtx_makefltval(rtx, r); else if (x >= 1) return hawk_rtx_makefltval(rtx, r);
@ -858,7 +858,7 @@ void hawk_rtx_freeval (hawk_rtx_t* rtx, hawk_val_t* val, int cache)
/* code is just a pointer to a regular expression stored /* code is just a pointer to a regular expression stored
* in parse tree nodes. so don't free it. * in parse tree nodes. so don't free it.
hawk_freerex (rtx->awk, ((hawk_val_rex_t*)val)->code[0], ((hawk_val_rex_t*)val)->code[1]); hawk_freerex (rtx->hawk, ((hawk_val_rex_t*)val)->code[0], ((hawk_val_rex_t*)val)->code[1]);
*/ */
hawk_rtx_freemem (rtx, val); hawk_rtx_freemem (rtx, val);
@ -1447,7 +1447,7 @@ int hawk_rtx_valtostr (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_rtx_valtostr_o
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->hawk->opt.trait & HAWK_FLEXMAP)
{ {
return str_to_str(rtx, HAWK_T("#MAP"), 4, out); return str_to_str(rtx, HAWK_T("#MAP"), 4, out);
} }
@ -1651,7 +1651,7 @@ static int val_ref_to_num (hawk_rtx_t* rtx, const hawk_val_ref_t* ref, hawk_int_
if (idx == 0) if (idx == 0)
{ {
return hawk_oochars_to_num( return hawk_oochars_to_num(
HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0),
HAWK_OOECS_PTR(&rtx->inrec.line), HAWK_OOECS_PTR(&rtx->inrec.line),
HAWK_OOECS_LEN(&rtx->inrec.line), HAWK_OOECS_LEN(&rtx->inrec.line),
l, r l, r
@ -1660,7 +1660,7 @@ static int val_ref_to_num (hawk_rtx_t* rtx, const hawk_val_ref_t* ref, hawk_int_
else if (idx <= rtx->inrec.nflds) else if (idx <= rtx->inrec.nflds)
{ {
return hawk_oochars_to_num( return hawk_oochars_to_num(
HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0),
rtx->inrec.flds[idx-1].ptr, rtx->inrec.flds[idx-1].ptr,
rtx->inrec.flds[idx-1].len, rtx->inrec.flds[idx-1].len,
l, r l, r
@ -1668,7 +1668,7 @@ static int val_ref_to_num (hawk_rtx_t* rtx, const hawk_val_ref_t* ref, hawk_int_
} }
else else
{ {
return hawk_oochars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), HAWK_T(""), 0, l, r); return hawk_oochars_to_num(HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 0), HAWK_T(""), 0, l, r);
} }
} }
@ -1715,7 +1715,7 @@ int hawk_rtx_valtonum (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_int_t* l, hawk
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, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 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
@ -1723,7 +1723,7 @@ int hawk_rtx_valtonum (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_int_t* l, hawk
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, 0, (hawk->opt.trait & HAWK_STRIPSTRSPC), 0), HAWK_OOCHARS_TO_NUM_MAKE_OPTION(0, 0, HAWK_RTX_IS_STRIPSTRSPC_ON(rtx), 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
@ -1734,7 +1734,7 @@ int hawk_rtx_valtonum (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_int_t* l, hawk
goto invalid; goto invalid;
case HAWK_VAL_MAP: case HAWK_VAL_MAP:
if (rtx->awk->opt.trait & HAWK_FLEXMAP) if (rtx->hawk->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 */
@ -2004,7 +2004,7 @@ int hawk_rtx_setrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref, hawk_val_t* val)
/* new value: map, old value: nil or map => ok */ /* new value: map, old value: nil or map => ok */
if (rref_vtype != HAWK_VAL_NIL && rref_vtype != HAWK_VAL_MAP) if (rref_vtype != HAWK_VAL_NIL && rref_vtype != HAWK_VAL_MAP)
{ {
if (!(rtx->awk->opt.trait & HAWK_FLEXMAP)) if (!(rtx->hawk->opt.trait & HAWK_FLEXMAP))
{ {
/* cannot change a scalar value to a map */ /* cannot change a scalar value to a map */
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ESCALARTOMAP); hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ESCALARTOMAP);
@ -2017,7 +2017,7 @@ int hawk_rtx_setrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref, hawk_val_t* val)
/* new value: scalar, old value: nil or scalar => ok */ /* new value: scalar, old value: nil or scalar => ok */
if (rref_vtype == HAWK_VAL_MAP) if (rref_vtype == HAWK_VAL_MAP)
{ {
if (!(rtx->awk->opt.trait & HAWK_FLEXMAP)) if (!(rtx->hawk->opt.trait & HAWK_FLEXMAP))
{ {
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EMAPTOSCALAR); hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EMAPTOSCALAR);
return -1; return -1;