changed hawk_rtx_seterrnum() to be consistent with hawk_gem_seterrnum()

This commit is contained in:
hyung-hwan 2019-12-31 15:52:28 +00:00
parent fffc474b9c
commit 988dc83bf4
12 changed files with 125 additions and 205 deletions

View File

@ -437,11 +437,6 @@ const hawk_ooch_t* hawk_rtx_backuperrmsg (hawk_rtx_t* rtx)
return rtx->errmsg_backup;
}
void hawk_rtx_seterrnum (hawk_rtx_t* rtx, hawk_errnum_t errnum, const hawk_oocs_t* errarg)
{
hawk_rtx_seterror (rtx, errnum, errarg, HAWK_NULL);
}
void hawk_rtx_seterrinf (hawk_rtx_t* rtx, const hawk_errinf_t* errinf)
{
rtx->_gem.errnum = errinf->num;

View File

@ -889,6 +889,7 @@ int hawk_fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{
int x;
// TODO: hawk_rtx_buildrex
if (rtx->gbl.ignorecase)
x = hawk_buildrex(hawk_rtx_gethawk(rtx), fs.ptr, fs.len, &errnum, HAWK_NULL, &fs_rex);
else
@ -896,7 +897,7 @@ int hawk_fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
if (x <= -1)
{
hawk_rtx_seterrnum (rtx, errnum, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, errnum);
goto oops;
}
@ -1143,6 +1144,7 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
hawk_errnum_t errnum;
int x;
// TODO: hawk_rtx_buildrex...
if (rtx->gbl.ignorecase)
x = hawk_buildrex(hawk_rtx_gethawk(rtx), s0.ptr, s0.len, &errnum, HAWK_NULL, &rex);
else
@ -1150,7 +1152,7 @@ static int __substitute (hawk_rtx_t* rtx, hawk_int_t max_count)
if (x <= -1)
{
hawk_rtx_seterrnum (rtx, errnum, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, errnum);
goto oops;
}

View File

@ -416,6 +416,37 @@ HAWK_EXPORT int hawk_gem_getifcfg (
hawk_ifcfg_t* cfg
);
/* ----------------------------------------------------------------------- */
#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
HAWK_EXPORT void hawk_gem_seterrnum (
hawk_gem_t* gem,
const hawk_loc_t* errloc,
hawk_errnum_t errnum
);
HAWK_EXPORT void hawk_gem_seterrbfmt (
hawk_gem_t* gem,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_bch_t* errfmt,
...
);
HAWK_EXPORT void hawk_gem_seterrufmt (
hawk_gem_t* gem,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_uch_t* errfmt,
...
);
#if defined(__cplusplus)
}
#endif

View File

@ -498,35 +498,6 @@ extern "C" {
int hawk_init (hawk_t* awk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_prm_t* prm);
void hawk_fini (hawk_t* awk);
/* 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_seterrbfmt (
hawk_gem_t* gem,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_bch_t* errfmt,
...
);
void hawk_gem_seterrufmt (
hawk_gem_t* gem,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_uch_t* errfmt,
...
);
#if defined(__cplusplus)
}
#endif

View File

@ -2428,15 +2428,11 @@ HAWK_EXPORT void hawk_rtx_geterror (
hawk_loc_t* errloc /**< error location */
);
/**
* The hawk_rtx_seterrnum() function sets the error information omitting
* the error location.
*/
HAWK_EXPORT void hawk_rtx_seterrnum (
hawk_rtx_t* rtx, /**< runtime context */
hawk_errnum_t errnum, /**< error number */
const hawk_oocs_t* errarg /**< arguments to format error message */
);
#if defined(HAWK_HAVE_INLINE)
static HAWK_INLINE void hawk_rtx_seterrnum (hawk_rtx_t* rtx, hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_rtx_getgem(rtx), errloc, errnum); }
#else
#define hawk_rtx_seterrnum(rtx, errloc, errnum) hawk_gem_seterrnum(hawk_rtx_getgem(rtx), errloc, errnum)
#endif
/**
* The hawk_rtx_seterrinf() function sets error information.

View File

@ -267,7 +267,7 @@ hawk_ooch_t* hawk_rtx_strxntokbyrex (
if (n == 0)
{
/* no match has been found. return the entire string as a token */
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL); /* reset HAWK_EREXNOMAT to no error */
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR); /* reset HAWK_EREXNOMAT to no error */
tok->ptr = realsub.ptr;
tok->len = realsub.len;
return HAWK_NULL;
@ -307,7 +307,7 @@ hawk_ooch_t* hawk_rtx_strxntokbyrex (
}
exit_loop:
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
if (cursub.len <= 0)
{
@ -548,12 +548,13 @@ int hawk_rtx_matchval (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_oocs_t* str,
tmp.ptr = hawk_rtx_getvaloocstr(rtx, val, &tmp.len);
if (tmp.ptr == HAWK_NULL) return -1;
// TODO: create hawk_rtx_buildrex....
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_rtx_freevaloocstr (rtx, val, tmp.ptr);
if (x <= -1)
{
hawk_rtx_seterrnum (rtx, awkerr, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, awkerr);
return -1;
}
}

View File

@ -414,8 +414,7 @@ static global_t gtab[] =
#define ISNOERR(awk) ((awk)->_gem.errnum == HAWK_ENOERR)
#define CLRERR(awk) \
hawk_seterror (awk, HAWK_ENOERR, HAWK_NULL, HAWK_NULL)
#define CLRERR(awk) hawk_seterror (awk, HAWK_ENOERR, HAWK_NULL, HAWK_NULL)
#define SETERR_TOK(awk,code) \
hawk_seterror (awk, code, HAWK_OOECS_OOCS((awk)->tok.name), &(awk)->tok.loc)

View File

@ -47,7 +47,6 @@ int hawk_rtx_setrec (hawk_rtx_t* rtx, hawk_oow_t idx, const hawk_oocs_t* str)
if (hawk_ooecs_ncpy(&rtx->inrec.line, str->ptr, str->len) == (hawk_oow_t)-1)
{
hawk_rtx_clrrec (rtx, 0);
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
}
@ -136,14 +135,9 @@ static int split_record (hawk_rtx_t* rtx)
/* scan the input record to count the fields */
if (fs_len == 5 && fs_ptr[0] == HAWK_T('?'))
{
if (hawk_ooecs_ncpy (
&rtx->inrec.linew,
HAWK_OOECS_PTR(&rtx->inrec.line),
HAWK_OOECS_LEN(&rtx->inrec.line)) == (hawk_oow_t)-1)
if (hawk_ooecs_ncpy(&rtx->inrec.linew, HAWK_OOECS_PTR(&rtx->inrec.line), HAWK_OOECS_LEN(&rtx->inrec.line)) == (hawk_oow_t)-1)
{
if (fs_free != HAWK_NULL)
hawk_rtx_freemem (rtx, fs_free);
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
if (fs_free) hawk_rtx_freemem (rtx, fs_free);
return -1;
}
@ -219,13 +213,9 @@ static int split_record (hawk_rtx_t* rtx)
/* scan again and split it */
if (how == 1)
{
if (hawk_ooecs_ncpy (
&rtx->inrec.linew,
HAWK_OOECS_PTR(&rtx->inrec.line),
HAWK_OOECS_LEN(&rtx->inrec.line)) == (hawk_oow_t)-1)
if (hawk_ooecs_ncpy(&rtx->inrec.linew, HAWK_OOECS_PTR(&rtx->inrec.line), HAWK_OOECS_LEN(&rtx->inrec.line)) == (hawk_oow_t)-1)
{
if (fs_free) hawk_rtx_freemem (rtx, fs_free);
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
px = HAWK_OOECS_PTR(&rtx->inrec.linew):
@ -411,11 +401,7 @@ static int recomp_record_fields (hawk_rtx_t* rtx, hawk_oow_t lv, const hawk_oocs
{
if (i > 0)
{
if (hawk_ooecs_ncat(&rtx->inrec.line, rtx->gbl.ofs.ptr, rtx->gbl.ofs.len) == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
if (hawk_ooecs_ncat(&rtx->inrec.line, rtx->gbl.ofs.ptr, rtx->gbl.ofs.len) == (hawk_oow_t)-1) return -1;
}
if (i == lv)
@ -425,11 +411,7 @@ static int recomp_record_fields (hawk_rtx_t* rtx, hawk_oow_t lv, const hawk_oocs
rtx->inrec.flds[i].ptr = HAWK_OOECS_PTR(&rtx->inrec.line) + HAWK_OOECS_LEN(&rtx->inrec.line);
rtx->inrec.flds[i].len = str->len;
if (hawk_ooecs_ncat(&rtx->inrec.line, str->ptr, str->len) == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
if (hawk_ooecs_ncat(&rtx->inrec.line, str->ptr, str->len) == (hawk_oow_t)-1) return -1;
tmp = hawk_rtx_makestrvalwithoocs (rtx, str);
if (tmp == HAWK_NULL) return -1;
@ -446,11 +428,7 @@ static int recomp_record_fields (hawk_rtx_t* rtx, hawk_oow_t lv, const hawk_oocs
rtx->inrec.flds[i].ptr = HAWK_OOECS_PTR(&rtx->inrec.line) + HAWK_OOECS_LEN(&rtx->inrec.line);
rtx->inrec.flds[i].len = 0;
if (hawk_ooecs_cat(&rtx->inrec.line, HAWK_T("")) == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
if (hawk_ooecs_cat(&rtx->inrec.line, HAWK_T("")) == (hawk_oow_t)-1) return -1;
/* hawk_rtx_refdownval should not be called over
* rtx->inrec.flds[i].val as it is not initialized
@ -469,11 +447,7 @@ static int recomp_record_fields (hawk_rtx_t* rtx, hawk_oow_t lv, const hawk_oocs
rtx->inrec.flds[i].ptr = HAWK_OOECS_PTR(&rtx->inrec.line) + HAWK_OOECS_LEN(&rtx->inrec.line);
rtx->inrec.flds[i].len = tmp->val.len;
if (hawk_ooecs_ncat(&rtx->inrec.line, tmp->val.ptr, tmp->val.len) == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
if (hawk_ooecs_ncat(&rtx->inrec.line, tmp->val.ptr, tmp->val.len) == (hawk_oow_t)-1) return -1;
}
}

View File

@ -115,7 +115,7 @@ static int find_rio_in (
if (handler == HAWK_NULL)
{
/* no I/O handler provided */
hawk_rtx_seterrnum (rtx, HAWK_EIOUSER, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOUSER);
return -1;
}
@ -160,7 +160,7 @@ static int find_rio_in (
p->in.eos = 0;
*/
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
/* request to open the stream */
x = handler(rtx, HAWK_RIO_CMD_OPEN, p, HAWK_NULL, 0);
@ -173,7 +173,7 @@ static int find_rio_in (
{
/* if the error number has not been
* set by the user handler */
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
}
return -1;
@ -331,7 +331,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
break;
}
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
x = handler(rtx, HAWK_RIO_CMD_READ, p, p->in.buf, HAWK_COUNTOF(p->in.buf));
if (x <= -1)
{
@ -340,7 +340,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
/* if the error number has not been
* set by the user handler, we set
* it here to HAWK_EIOIMPL. */
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
}
ret = -1;
@ -442,7 +442,6 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
tmp = hawk_ooecs_ncat(buf, &p->in.buf[start_pos], end_pos - start_pos);
if (tmp == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
ret = -1;
break;
}
@ -527,7 +526,7 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
if (hawk_ooecs_ccat(buf, c) == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
ret = -1;
done = 1;
break;
@ -557,7 +556,6 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
tmp = hawk_ooecs_ncat(buf, &p->in.buf[start_pos], end_pos - start_pos);
if (tmp == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
ret = -1;
break;
}
@ -580,7 +578,6 @@ int hawk_rtx_readio (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name, hawk
tmp = hawk_ooecs_ncat(buf, &p->in.buf[p->in.pos], p->in.len - p->in.pos);
if (tmp == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
ret = -1;
break;
}
@ -655,7 +652,7 @@ static int prepare_for_write_io_data (hawk_rtx_t* rtx, int out_type, const hawk_
if (handler == HAWK_NULL)
{
/* no I/O handler provided */
hawk_rtx_seterrnum (rtx, HAWK_EIOUSER, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOUSER);
return -1;
}
@ -703,7 +700,7 @@ static int prepare_for_write_io_data (hawk_rtx_t* rtx, int out_type, const hawk_
p->out.eos = 0;
*/
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
n = handler(rtx, HAWK_RIO_CMD_OPEN, p, HAWK_NULL, 0);
if (n <= -1)
{
@ -711,7 +708,7 @@ static int prepare_for_write_io_data (hawk_rtx_t* rtx, int out_type, const hawk_
hawk_rtx_freemem (rtx, p);
if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR)
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
return -1;
}
@ -740,12 +737,12 @@ int hawk_rtx_writeiostr (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name,
{
hawk_ooi_t n;
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
n = wid.handler(rtx, HAWK_RIO_CMD_WRITE, wid.p, str, len);
if (n <= -1)
{
if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR)
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
return -1;
}
@ -773,12 +770,12 @@ int hawk_rtx_writeiobytes (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* nam
{
hawk_ooi_t n;
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
n = wid.handler(rtx, HAWK_RIO_CMD_WRITE_BYTES, wid.p, str, len);
if (n <= -1)
{
if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR)
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
return -1;
}
@ -816,7 +813,7 @@ int hawk_rtx_flushio (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name)
if (!handler)
{
/* no I/O handler provided */
hawk_rtx_seterrnum (rtx, HAWK_EIOUSER, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOUSER);
return -1;
}
@ -830,12 +827,12 @@ int hawk_rtx_flushio (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name)
if (p->type == (io_type | io_mask) && p->mode == io_mode &&
(name == HAWK_NULL || hawk_comp_oocstr(p->name, name, 0) == 0))
{
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
n = handler(rtx, HAWK_RIO_CMD_FLUSH, p, HAWK_NULL, 0);
if (n <= -1)
{
if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR)
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
return -1;
}
@ -848,7 +845,7 @@ int hawk_rtx_flushio (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* name)
if (ok) return 0;
/* there is no corresponding rio for name */
hawk_rtx_seterrnum (rtx, HAWK_EIONMNF, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIONMNF);
return -1;
}
@ -872,7 +869,7 @@ int hawk_rtx_nextio_read (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name)
if (!handler)
{
/* no I/O handler provided */
hawk_rtx_seterrnum (rtx, HAWK_EIOUSER, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOUSER);
return -1;
}
@ -886,7 +883,7 @@ int hawk_rtx_nextio_read (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name)
{
/* something is totally wrong */
HAWK_ASSERT (!"should never happen - cannot find the relevant rio entry");
hawk_rtx_seterrnum (rtx, HAWK_EINTERN, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
@ -896,12 +893,12 @@ int hawk_rtx_nextio_read (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name)
return 0;
}
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
n = handler(rtx, HAWK_RIO_CMD_NEXT, p, HAWK_NULL, 0);
if (n <= -1)
{
if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR)
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
return -1;
}
@ -947,7 +944,7 @@ int hawk_rtx_nextio_write (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* nam
if (!handler)
{
/* no I/O handler provided */
hawk_rtx_seterrnum (rtx, HAWK_EIOUSER, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOUSER);
return -1;
}
@ -962,7 +959,7 @@ int hawk_rtx_nextio_write (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* nam
/* something is totally wrong */
HAWK_ASSERT (!"should never happen - cannot find the relevant rio entry");
hawk_rtx_seterrnum (rtx, HAWK_EINTERN, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
@ -972,12 +969,12 @@ int hawk_rtx_nextio_write (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* nam
return 0;
}
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
n = handler(rtx, HAWK_RIO_CMD_NEXT, p, HAWK_NULL, 0);
if (n <= -1)
{
if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR)
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
return -1;
}
@ -1017,7 +1014,7 @@ int hawk_rtx_closio_read (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name)
if (!handler)
{
/* no I/O handler provided */
hawk_rtx_seterrnum (rtx, HAWK_EIOUSER, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOUSER);
return -1;
}
@ -1033,7 +1030,7 @@ int hawk_rtx_closio_read (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name)
if (handler (rtx, HAWK_RIO_CMD_CLOSE, p, HAWK_NULL, 0) <= -1)
{
/* this is not a rtx-time error.*/
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
return -1;
}
}
@ -1051,7 +1048,7 @@ int hawk_rtx_closio_read (hawk_rtx_t* rtx, int in_type, const hawk_ooch_t* name)
}
/* the name given is not found */
hawk_rtx_seterrnum (rtx, HAWK_EIONMNF, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIONMNF);
return -1;
}
@ -1074,7 +1071,7 @@ int hawk_rtx_closio_write (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* nam
if (!handler)
{
/* no io handler provided */
hawk_rtx_seterrnum (rtx, HAWK_EIOUSER, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOUSER);
return -1;
}
@ -1087,11 +1084,11 @@ int hawk_rtx_closio_write (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* nam
handler = rtx->rio.handler[p->type & IO_MASK_CLEAR];
if (handler)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
if (handler (rtx, HAWK_RIO_CMD_CLOSE, p, HAWK_NULL, 0) <= -1)
{
if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR)
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
return -1;
}
}
@ -1108,7 +1105,7 @@ int hawk_rtx_closio_write (hawk_rtx_t* rtx, int out_type, const hawk_ooch_t* nam
p = p->next;
}
hawk_rtx_seterrnum (rtx, HAWK_EIONMNF, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIONMNF);
return -1;
}
@ -1161,13 +1158,13 @@ int hawk_rtx_closeio (hawk_rtx_t* rtx, const hawk_ooch_t* name, const hawk_ooch_
handler = rtx->rio.handler[p->type & IO_MASK_CLEAR];
if (handler)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
p->rwcmode = rwcmode;
if (handler(rtx, HAWK_RIO_CMD_CLOSE, p, HAWK_NULL, 0) <= -1)
{
/* this is not a run-time error.*/
if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR)
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
return -1;
}
}
@ -1200,7 +1197,7 @@ int hawk_rtx_closeio (hawk_rtx_t* rtx, const hawk_ooch_t* name, const hawk_ooch_
p = p->next;
}
hawk_rtx_seterrnum (rtx, HAWK_EIONMNF, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIONMNF);
return -1;
}
@ -1217,13 +1214,13 @@ void hawk_rtx_cleario (hawk_rtx_t* rtx)
if (handler)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
rtx->rio.chain->rwcmode = 0;
n = handler(rtx, HAWK_RIO_CMD_CLOSE, rtx->rio.chain, HAWK_NULL, 0);
if (n <= -1)
{
if (hawk_rtx_geterrnum(rtx) == HAWK_ENOERR)
hawk_rtx_seterrnum (rtx, HAWK_EIOIMPL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EIOIMPL);
/* TODO: some warnings need to be shown??? */
}
}

View File

@ -3310,7 +3310,7 @@ static hawk_val_t* eval_expression0 (hawk_rtx_t* rtx, hawk_nde_t* nde)
* clears the error number. run_main will
* detect this condition and treat it as a
* non-error condition.*/
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
return HAWK_NULL;
}
@ -5986,7 +5986,7 @@ static hawk_val_t* __eval_call (
if (call->u.fnc.spec.impl)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOERR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ENOERR);
n = call->u.fnc.spec.impl(rtx, &call->u.fnc.info);

View File

@ -1706,7 +1706,7 @@ static hawk_ooi_t nwio_handler_rest (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_r
switch (cmd)
{
case HAWK_RIO_CMD_OPEN:
hawk_rtx_seterrnum (rtx, HAWK_EINTERN, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
case HAWK_RIO_CMD_CLOSE:
@ -1730,7 +1730,7 @@ static hawk_ooi_t nwio_handler_rest (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_r
break;
}
hawk_rtx_seterrnum (rtx, HAWK_EINTERN, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
@ -1786,7 +1786,7 @@ static hawk_ooi_t pio_handler_open (hawk_rtx_t* rtx, hawk_rio_arg_t* riod)
else
{
/* this must not happen */
hawk_rtx_seterrnum (rtx, HAWK_EINTERN, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
@ -1820,7 +1820,7 @@ static hawk_ooi_t pio_handler_rest (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_ri
switch (cmd)
{
case HAWK_RIO_CMD_OPEN:
hawk_rtx_seterrnum (rtx, HAWK_EINTERN, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
case HAWK_RIO_CMD_CLOSE:
@ -1864,7 +1864,7 @@ static hawk_ooi_t pio_handler_rest (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_ri
break;
}
hawk_rtx_seterrnum (rtx, HAWK_EINTERN, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
@ -1936,7 +1936,7 @@ static hawk_ooi_t awk_rio_file (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_ar
break;
default:
/* this must not happen */
hawk_rtx_seterrnum (rtx, HAWK_EINTERN, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}
@ -2093,15 +2093,7 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod)
if (hawk_count_oocstr(as.ptr) < as.len)
{
/* the name contains one or more '\0' */
hawk_oocs_t errarg;
errarg.ptr = as.ptr;
/* use this length not to contains '\0'
* in an error message */
errarg.len = hawk_count_oocstr(as.ptr);
hawk_rtx_seterrnum (rtx, HAWK_EIONMNL, &errarg);
hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EIONMNL, HAWK_T("I/O name beginning with '%js' of length %zu containing '\\0'"), as.ptr, as.len);
hawk_rtx_freevaloocstr (rtx, v, as.ptr);
return -1;
}
@ -2117,7 +2109,7 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod)
return -1;
}
if (rxtn->c.cmgr) hawk_sio_setcmgr (sio, rxtn->c.cmgr);
if (rxtn->c.cmgr) hawk_sio_setcmgr (sio, rxtn->c.cmgr);
if (hawk_rtx_setfilename (
rtx, file, hawk_count_oocstr(file)) <= -1)
@ -2263,7 +2255,7 @@ static hawk_ooi_t awk_rio_console (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio
}
hawk_rtx_seterrnum (rtx, HAWK_EINTERN, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINTERN);
return -1;
}

View File

@ -487,7 +487,6 @@ hawk_val_t* hawk_rtx_makemapval (hawk_rtx_t* rtx)
if (val->map == HAWK_NULL)
{
hawk_rtx_freemem (rtx, val);
hawk_rtx_seterrnum (run, HAWK_ENOMEM, HAWK_NULL);
return HAWK_NULL;
}
*/
@ -563,7 +562,7 @@ hawk_val_t* hawk_rtx_makemapvalwithdata (hawk_rtx_t* rtx, hawk_val_map_data_t da
default:
tmp = HAWK_NULL;
hawk_rtx_seterrnum (rtx, HAWK_EINVAL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL);
break;
}
@ -963,7 +962,7 @@ static int str_to_str (hawk_rtx_t* rtx, const hawk_ooch_t* str, hawk_oow_t str_l
{
if (str_len >= out->u.cplcpy.len)
{
hawk_rtx_seterrnum (rtx, HAWK_EINVAL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL);
/*out->u.cplcpy.len = str_len + 1;*/ /* set the required length */
return -1;
}
@ -987,32 +986,22 @@ static int str_to_str (hawk_rtx_t* rtx, const hawk_ooch_t* str, hawk_oow_t str_l
case HAWK_RTX_VALTOSTR_STRP:
{
hawk_oow_t n;
hawk_ooecs_clear (out->u.strp);
n = hawk_ooecs_ncat(out->u.strp, str, str_len);
if (n == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
if (n == (hawk_oow_t)-1) return -1;
return 0;
}
case HAWK_RTX_VALTOSTR_STRPCAT:
{
hawk_oow_t n;
n = hawk_ooecs_ncat(out->u.strpcat, str, str_len);
if (n == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
if (n == (hawk_oow_t)-1) return -1;
return 0;
}
}
hawk_rtx_seterrnum (rtx, HAWK_EINVAL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL);
return -1;
}
@ -1033,7 +1022,7 @@ static int mbs_to_str (hawk_rtx_t* rtx, const hawk_bch_t* str, hawk_oow_t str_le
hawk_oow_t ucslen;
if (HAWK_UNLIKELY(out->u.cplcpy.len <= 0))
{
hawk_rtx_seterrnum (rtx, HAWK_EBUFFULL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EBUFFULL);
return -1;
}
/* hawk_rtx_convbtouchars() doesn't null terminate the result. -1 to secure space for '\0' */
@ -1061,23 +1050,15 @@ static int mbs_to_str (hawk_rtx_t* rtx, const hawk_bch_t* str, hawk_oow_t str_le
case HAWK_RTX_VALTOSTR_STRP:
hawk_ooecs_clear (out->u.strp);
if (hawk_uecs_ncatbchars(out->u.strp, str, str_len, hawk_rtx_getcmgr(rtx), 1) == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
if (hawk_uecs_ncatbchars(out->u.strp, str, str_len, hawk_rtx_getcmgr(rtx), 1) == (hawk_oow_t)-1) return -1;
return 0;
case HAWK_RTX_VALTOSTR_STRPCAT:
if (hawk_uecs_ncatbchars(out->u.strpcat, str, str_len, hawk_rtx_getcmgr(rtx), 1) == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
if (hawk_uecs_ncatbchars(out->u.strpcat, str, str_len, hawk_rtx_getcmgr(rtx), 1) == (hawk_oow_t)-1) return -1;
return 0;
}
hawk_rtx_seterrnum (rtx, HAWK_EINVAL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL);
return -1;
}
#endif
@ -1116,7 +1097,7 @@ static int val_int_to_str (hawk_rtx_t* rtx, const hawk_val_int_t* v, hawk_rtx_va
case HAWK_RTX_VALTOSTR_CPLCPY:
if (rlen >= out->u.cplcpy.len)
{
hawk_rtx_seterrnum (rtx, HAWK_EINVAL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL);
/* store the buffer size needed */
out->u.cplcpy.len = rlen + 1;
return -1;
@ -1148,11 +1129,7 @@ static int val_int_to_str (hawk_rtx_t* rtx, const hawk_val_int_t* v, hawk_rtx_va
/* extend the buffer */
n = hawk_ooecs_nccat(out->u.strp, HAWK_T(' '), rlen);
if (n == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
if (n == (hawk_oow_t)-1) return -1;
break;
}
@ -1165,17 +1142,13 @@ static int val_int_to_str (hawk_rtx_t* rtx, const hawk_val_int_t* v, hawk_rtx_va
/* extend the buffer */
n = hawk_ooecs_nccat(out->u.strpcat, HAWK_T(' '), rlen);
if (n == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
return -1;
}
if (n == (hawk_oow_t)-1) return -1;
break;
}
default:
{
hawk_rtx_seterrnum (rtx, HAWK_EINVAL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL);
return -1;
}
}
@ -1244,7 +1217,7 @@ static int val_flt_to_str (hawk_rtx_t* rtx, const hawk_val_flt_t* v, hawk_rtx_va
case HAWK_RTX_VALTOSTR_CPLCPY:
if (out->u.cplcpy.len <= tmp_len)
{
hawk_rtx_seterrnum (rtx, HAWK_EINVAL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL);
/* store the buffer size required */
out->u.cplcpy.len = tmp_len + 1;
goto oops;
@ -1265,34 +1238,23 @@ static int val_flt_to_str (hawk_rtx_t* rtx, const hawk_val_flt_t* v, hawk_rtx_va
case HAWK_RTX_VALTOSTR_STRP:
{
hawk_oow_t n;
hawk_ooecs_clear (out->u.strp);
n = hawk_ooecs_ncat(out->u.strp, tmp, tmp_len);
if (n == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
goto oops;
}
if (n == (hawk_oow_t)-1) goto oops;
break;
}
case HAWK_RTX_VALTOSTR_STRPCAT:
{
hawk_oow_t n;
n = hawk_ooecs_ncat(out->u.strpcat, tmp, tmp_len);
if (n == (hawk_oow_t)-1)
{
hawk_rtx_seterrnum (rtx, HAWK_ENOMEM, HAWK_NULL);
goto oops;
}
if (n == (hawk_oow_t)-1) goto oops;
break;
}
default:
{
hawk_rtx_seterrnum (rtx, HAWK_EINVAL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL);
goto oops;
}
}
@ -1414,7 +1376,7 @@ int hawk_rtx_valtostr (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_rtx_valtostr_o
#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);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EVALTOSTR);
return -1;
}
}
@ -1702,7 +1664,7 @@ int hawk_rtx_valtonum (hawk_rtx_t* rtx, const hawk_val_t* v, hawk_int_t* l, hawk
#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);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EVALTONUM);
return -1; /* error */
}
}
@ -1788,7 +1750,7 @@ hawk_int_t hawk_rtx_hashval (hawk_rtx_t* rtx, hawk_val_t* v)
#if defined(DEBUG_VAL)
hawk_logfmt (hawk_rtx_gethawk(rtx), HAWK_T(">>WRONG VALUE TYPE [%d] in hawk_rtx_hashval()\n"), v->type);
#endif
hawk_rtx_seterrnum (rtx, HAWK_EHASHVAL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EHASHVAL);
return -1;
}
@ -1872,7 +1834,7 @@ int hawk_rtx_setrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref, hawk_val_t* val)
* avoid potential chaos. the nature of performing '/rex/ ~ $0'
* for a regular expression without the match operator
* makes it difficult to be implemented. */
hawk_rtx_seterrnum (rtx, HAWK_EINVAL, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EINVAL);
return -1;
}
@ -1884,7 +1846,7 @@ int hawk_rtx_setrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref, hawk_val_t* val)
{
case HAWK_VAL_MAP:
/* a map is assigned to a positional. this is disallowed. */
hawk_rtx_seterrnum (rtx, HAWK_EMAPTOPOS, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EMAPTOPOS);
return -1;
case HAWK_VAL_STR:
@ -1939,7 +1901,7 @@ int hawk_rtx_setrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref, hawk_val_t* val)
{
/* an indexed variable cannot be assigned a map.
* in other cases, it falls down to the default case. */
hawk_rtx_seterrnum (rtx, HAWK_EMAPTOIDX, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EMAPTOIDX);
return -1;
}
/* fall through */
@ -1959,7 +1921,7 @@ int hawk_rtx_setrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref, hawk_val_t* val)
if (!(rtx->awk->opt.trait & HAWK_FLEXMAP))
{
/* cannot change a scalar value to a map */
hawk_rtx_seterrnum (rtx, HAWK_ESCALARTOMAP, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_ESCALARTOMAP);
return -1;
}
}
@ -1971,7 +1933,7 @@ int hawk_rtx_setrefval (hawk_rtx_t* rtx, hawk_val_ref_t* ref, hawk_val_t* val)
{
if (!(rtx->awk->opt.trait & HAWK_FLEXMAP))
{
hawk_rtx_seterrnum (rtx, HAWK_EMAPTOSCALAR, HAWK_NULL);
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EMAPTOSCALAR);
return -1;
}
}