interim update while reorganizing error handling code

This commit is contained in:
hyung-hwan 2022-03-26 16:51:48 +00:00
parent 515b27332f
commit 36394eaef8
7 changed files with 207 additions and 255 deletions

View File

@ -180,7 +180,38 @@ const hawk_ooch_t* hawk_dfl_errstr (hawk_errnum_t errnum)
HAWK_T("imbalanced brace in regular expression"), HAWK_T("imbalanced brace in regular expression"),
HAWK_T("invalid content inside braces in regular expression"), HAWK_T("invalid content inside braces in regular expression"),
HAWK_T("invalid use of range operator in regular expression"), HAWK_T("invalid use of range operator in regular expression"),
HAWK_T("invalid use of repetition operator in regular expression") HAWK_T("invalid use of repetition operator in regular expression"),
/* sed error messages */
HAWK_T("command '${0}' not recognized"),
HAWK_T("command code missing"),
HAWK_T("command '${0}' incomplete"),
HAWK_T("regular expression '${0}' incomplete"),
HAWK_T("failed to compile regular expression '${0}'"),
HAWK_T("failed to match regular expression"),
HAWK_T("address 1 prohibited for '${0}'"),
HAWK_T("address 1 missing or invalid"),
HAWK_T("address 2 prohibited for '${0}'"),
HAWK_T("address 2 missing or invalid"),
HAWK_T("newline expected"),
HAWK_T("backslash expected"),
HAWK_T("backslash used as delimiter"),
HAWK_T("garbage after backslash"),
HAWK_T("semicolon expected"),
HAWK_T("empty label name"),
HAWK_T("duplicate label name '${0}'"),
HAWK_T("label '${0}' not found"),
HAWK_T("empty file name"),
HAWK_T("illegal file name"),
HAWK_T("strings in translation set not the same length"),
HAWK_T("group brackets not balanced"),
HAWK_T("group nesting too deep"),
HAWK_T("multiple occurrence specifiers"),
HAWK_T("occurrence specifier zero"),
HAWK_T("occurrence specifier too large"),
HAWK_T("no previous regular expression"),
HAWK_T("cut selector not valid"),
HAWK_T("I/O error with file '${0}'")
}; };
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");
@ -188,7 +219,7 @@ const hawk_ooch_t* hawk_dfl_errstr (hawk_errnum_t errnum)
hawk_errstr_t hawk_geterrstr (hawk_t* hawk) hawk_errstr_t hawk_geterrstr (hawk_t* hawk)
{ {
return hawk->errstr; return hawk->_gem.errstr;
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -234,16 +265,12 @@ const hawk_uch_t* hawk_geterrumsg (hawk_t* hawk)
void hawk_geterrinf (hawk_t* hawk, hawk_errinf_t* errinf) void hawk_geterrinf (hawk_t* hawk, hawk_errinf_t* errinf)
{ {
errinf->num = hawk->_gem.errnum; hawk_gem_geterrinf (hawk_getgem(hawk), errinf);
errinf->loc = hawk->_gem.errloc;
hawk_copy_oocstr (errinf->msg, HAWK_COUNTOF(errinf->msg), (hawk->_gem.errmsg[0] == '\0'? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg));
} }
void hawk_geterror (hawk_t* hawk, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc) void hawk_geterror (hawk_t* hawk, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc)
{ {
if (errnum) *errnum = hawk->_gem.errnum; hawk_gem_geterror (hawk_getgem(hawk), errnum, errmsg, errloc);
if (errmsg) *errmsg = (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg;
if (errloc) *errloc = hawk->_gem.errloc;
} }
const hawk_ooch_t* hawk_backuperrmsg (hawk_t* hawk) const hawk_ooch_t* hawk_backuperrmsg (hawk_t* hawk)
@ -254,140 +281,33 @@ const hawk_ooch_t* hawk_backuperrmsg (hawk_t* hawk)
void hawk_seterrinf (hawk_t* hawk, const hawk_errinf_t* errinf) void hawk_seterrinf (hawk_t* hawk, const hawk_errinf_t* errinf)
{ {
hawk->_gem.errnum = errinf->num; hawk_gem_seterrinf (hawk_getgem(hawk), errinf);
hawk_copy_oocstr(hawk->_gem.errmsg, HAWK_COUNTOF(hawk->_gem.errmsg), errinf->msg);
hawk->_gem.errloc = errinf->loc;
} }
static int err_bchars (hawk_fmtout_t* fmtout, const hawk_bch_t* ptr, hawk_oow_t len)
{
hawk_t* hawk = (hawk_t*)fmtout->ctx;
hawk_oow_t max;
max = HAWK_COUNTOF(hawk->_gem.errmsg) - hawk->errmsg_len - 1;
#if defined(HAWK_OOCH_IS_UCH)
if (max <= 0) return 1;
hawk_conv_bchars_to_uchars_with_cmgr (ptr, &len, &hawk->_gem.errmsg[hawk->errmsg_len], &max, hawk_getcmgr(hawk), 1);
hawk->errmsg_len += max;
#else
if (len > max) len = max;
if (len <= 0) return 1;
HAWK_MEMCPY (&hawk->_gem.errmsg[hawk->errmsg_len], ptr, len * HAWK_SIZEOF(*ptr));
hawk->errmsg_len += len;
#endif
hawk->_gem.errmsg[hawk->errmsg_len] = '\0';
return 1; /* success */
}
static int err_uchars (hawk_fmtout_t* fmtout, const hawk_uch_t* ptr, hawk_oow_t len)
{
hawk_t* hawk = (hawk_t*)fmtout->ctx;
hawk_oow_t max;
max = HAWK_COUNTOF(hawk->_gem.errmsg) - hawk->errmsg_len - 1;
#if defined(HAWK_OOCH_IS_UCH)
if (len > max) len = max;
if (len <= 0) return 1;
HAWK_MEMCPY (&hawk->_gem.errmsg[hawk->errmsg_len], ptr, len * HAWK_SIZEOF(*ptr));
hawk->errmsg_len += len;
#else
if (max <= 0) return 1;
hawk_conv_uchars_to_bchars_with_cmgr (ptr, &len, &hawk->_gem.errmsg[hawk->errmsg_len], &max, hawk_getcmgr(hawk));
hawk->errmsg_len += max;
#endif
hawk->_gem.errmsg[hawk->errmsg_len] = '\0';
return 1; /* success */
}
void hawk_seterrbfmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, ...) void hawk_seterrbfmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, ...)
{ {
va_list ap; va_list ap;
hawk_fmtout_t fo;
/*if (hawk->shuterr) return;*/
hawk->errmsg_len = 0;
hawk->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_getmmgr(hawk);
fo.putbchars = err_bchars;
fo.putuchars = err_uchars;
fo.ctx = hawk;
va_start (ap, errfmt); va_start (ap, errfmt);
hawk_bfmt_outv (&fo, errfmt, ap); hawk_gem_seterrbvfmt (hawk_getgem(hawk), errloc, errnum, errfmt, ap);
va_end (ap); va_end (ap);
hawk->_gem.errnum = errnum;
hawk->_gem.errloc = (errloc? *errloc: _nullloc);
} }
void hawk_seterrufmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, ...) void hawk_seterrufmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, ...)
{ {
va_list ap; va_list ap;
hawk_fmtout_t fo;
/*if (hawk->shuterr) return;*/
hawk->errmsg_len = 0;
hawk->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_getmmgr(hawk);
fo.putbchars = err_bchars;
fo.putuchars = err_uchars;
fo.ctx = hawk;
va_start (ap, errfmt); va_start (ap, errfmt);
hawk_ufmt_outv (&fo, errfmt, ap); hawk_gem_seterruvfmt (hawk_getgem(hawk), errloc, errnum, errfmt, ap);
va_end (ap); va_end (ap);
hawk->_gem.errnum = errnum;
hawk->_gem.errloc = (errloc? *errloc: _nullloc);
} }
void hawk_seterrbvfmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, va_list ap) void hawk_seterrbvfmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, va_list ap)
{ {
hawk_fmtout_t fo; hawk_gem_seterrbvfmt (hawk_getgem(hawk), errloc, errnum, errfmt, ap);
/*if (hawk->shuterr) return;*/
hawk->errmsg_len = 0;
hawk->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_getmmgr(hawk);
fo.putbchars = err_bchars;
fo.putuchars = err_uchars;
fo.ctx = hawk;
hawk_bfmt_outv (&fo, errfmt, ap);
hawk->_gem.errnum = errnum;
hawk->_gem.errloc = (errloc? *errloc: _nullloc);
} }
void hawk_seterruvfmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, va_list ap) void hawk_seterruvfmt (hawk_t* hawk, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, va_list ap)
{ {
hawk_fmtout_t fo; hawk_gem_seterruvfmt (hawk_getgem(hawk), errloc, errnum, errfmt, ap);
/*if (hawk->shuterr) return;*/
hawk->errmsg_len = 0;
hawk->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_getmmgr(hawk);
fo.putbchars = err_bchars;
fo.putuchars = err_uchars;
fo.ctx = hawk;
hawk_ufmt_outv (&fo, errfmt, ap);
hawk->_gem.errnum = errnum;
hawk->_gem.errloc = (errloc? *errloc: _nullloc);
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -433,16 +353,12 @@ const hawk_uch_t* hawk_rtx_geterrumsg (hawk_rtx_t* rtx)
void hawk_rtx_geterrinf (hawk_rtx_t* rtx, hawk_errinf_t* errinf) void hawk_rtx_geterrinf (hawk_rtx_t* rtx, hawk_errinf_t* errinf)
{ {
errinf->num = rtx->_gem.errnum; hawk_gem_geterrinf (hawk_rtx_getgem(rtx), errinf);
errinf->loc = rtx->_gem.errloc;
hawk_copy_oocstr (errinf->msg, HAWK_COUNTOF(errinf->msg), (rtx->_gem.errmsg[0] == '\0'? hawk_geterrstr(hawk_rtx_gethawk(rtx))(rtx->_gem.errnum): rtx->_gem.errmsg));
} }
void hawk_rtx_geterror (hawk_rtx_t* rtx, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc) void hawk_rtx_geterror (hawk_rtx_t* rtx, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc)
{ {
if (errnum) *errnum = rtx->_gem.errnum; hawk_gem_geterror (hawk_rtx_getgem(rtx), errnum, errmsg, errloc);
if (errmsg) *errmsg = (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(rtx->_gem.errnum): rtx->_gem.errmsg;
if (errloc) *errloc = rtx->_gem.errloc;
} }
const hawk_ooch_t* hawk_rtx_backuperrmsg (hawk_rtx_t* rtx) const hawk_ooch_t* hawk_rtx_backuperrmsg (hawk_rtx_t* rtx)
@ -453,140 +369,33 @@ const hawk_ooch_t* hawk_rtx_backuperrmsg (hawk_rtx_t* rtx)
void hawk_rtx_seterrinf (hawk_rtx_t* rtx, const hawk_errinf_t* errinf) void hawk_rtx_seterrinf (hawk_rtx_t* rtx, const hawk_errinf_t* errinf)
{ {
rtx->_gem.errnum = errinf->num; hawk_gem_seterrinf (hawk_rtx_getgem(rtx), errinf);
hawk_copy_oocstr(rtx->_gem.errmsg, HAWK_COUNTOF(rtx->_gem.errmsg), errinf->msg);
rtx->_gem.errloc = errinf->loc;
}
static int rtx_err_bchars (hawk_fmtout_t* fmtout, const hawk_bch_t* ptr, hawk_oow_t len)
{
hawk_rtx_t* rtx = (hawk_rtx_t*)fmtout->ctx;
hawk_oow_t max;
max = HAWK_COUNTOF(rtx->_gem.errmsg) - rtx->errmsg_len - 1;
#if defined(HAWK_OOCH_IS_UCH)
if (max <= 0) return 1;
hawk_conv_bchars_to_uchars_with_cmgr (ptr, &len, &rtx->_gem.errmsg[rtx->errmsg_len], &max, hawk_rtx_getcmgr(rtx), 1);
rtx->errmsg_len += max;
#else
if (len > max) len = max;
if (len <= 0) return 1;
HAWK_MEMCPY (&rtx->_gem.errmsg[rtx->errmsg_len], ptr, len * HAWK_SIZEOF(*ptr));
rtx->errmsg_len += len;
#endif
rtx->_gem.errmsg[rtx->errmsg_len] = '\0';
return 1; /* success */
}
static int rtx_err_uchars (hawk_fmtout_t* fmtout, const hawk_uch_t* ptr, hawk_oow_t len)
{
hawk_rtx_t* rtx = (hawk_rtx_t*)fmtout->ctx;
hawk_oow_t max;
max = HAWK_COUNTOF(rtx->_gem.errmsg) - rtx->errmsg_len - 1;
#if defined(HAWK_OOCH_IS_UCH)
if (len > max) len = max;
if (len <= 0) return 1;
HAWK_MEMCPY (&rtx->_gem.errmsg[rtx->errmsg_len], ptr, len * HAWK_SIZEOF(*ptr));
rtx->errmsg_len += len;
#else
if (max <= 0) return 1;
hawk_conv_uchars_to_bchars_with_cmgr (ptr, &len, &rtx->_gem.errmsg[rtx->errmsg_len], &max, hawk_rtx_getcmgr(rtx));
rtx->errmsg_len += max;
#endif
rtx->_gem.errmsg[rtx->errmsg_len] = '\0';
return 1; /* success */
} }
void hawk_rtx_seterrbfmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, ...) void hawk_rtx_seterrbfmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, ...)
{ {
va_list ap; va_list ap;
hawk_fmtout_t fo;
/*if (hawk->shuterr) return;*/
rtx->errmsg_len = 0;
rtx->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_rtx_getmmgr(rtx);
fo.putbchars = rtx_err_bchars;
fo.putuchars = rtx_err_uchars;
fo.ctx = rtx;
va_start (ap, errfmt); va_start (ap, errfmt);
hawk_bfmt_outv (&fo, errfmt, ap); hawk_gem_seterrbvfmt (hawk_rtx_getgem(rtx), errloc, errnum, errfmt, ap);
va_end (ap); va_end (ap);
rtx->_gem.errnum = errnum;
rtx->_gem.errloc = (errloc? *errloc: _nullloc);
} }
void hawk_rtx_seterrufmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, ...) void hawk_rtx_seterrufmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, ...)
{ {
va_list ap; va_list ap;
hawk_fmtout_t fo;
/*if (hawk->shuterr) return;*/
rtx->errmsg_len = 0;
rtx->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_rtx_getmmgr(rtx);
fo.putbchars = rtx_err_bchars;
fo.putuchars = rtx_err_uchars;
fo.ctx = rtx;
va_start (ap, errfmt); va_start (ap, errfmt);
hawk_ufmt_outv (&fo, errfmt, ap); hawk_gem_seterruvfmt (hawk_rtx_getgem(rtx), errloc, errnum, errfmt, ap);
va_end (ap); va_end (ap);
rtx->_gem.errnum = errnum;
rtx->_gem.errloc = (errloc? *errloc: _nullloc);
} }
void hawk_rtx_seterrbvfmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, va_list ap) void hawk_rtx_seterrbvfmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, va_list ap)
{ {
hawk_fmtout_t fo; hawk_gem_seterrbvfmt (hawk_rtx_getgem(rtx), errloc, errnum, errfmt, ap);
/*if (hawk->shuterr) return;*/
rtx->errmsg_len = 0;
rtx->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_rtx_getmmgr(rtx);
fo.putbchars = rtx_err_bchars;
fo.putuchars = rtx_err_uchars;
fo.ctx = rtx;
hawk_bfmt_outv (&fo, errfmt, ap);
rtx->_gem.errnum = errnum;
rtx->_gem.errloc = (errloc? *errloc: _nullloc);
} }
void hawk_rtx_seterruvfmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, va_list ap) void hawk_rtx_seterruvfmt (hawk_rtx_t* rtx, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, va_list ap)
{ {
hawk_fmtout_t fo; hawk_gem_seterruvfmt (hawk_rtx_getgem(rtx), errloc, errnum, errfmt, ap);
/*if (hawk->shuterr) return;*/
rtx->errmsg_len = 0;
rtx->_gem.errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = hawk_rtx_getmmgr(rtx);
fo.putbchars = rtx_err_bchars;
fo.putuchars = rtx_err_uchars;
fo.ctx = rtx;
hawk_ufmt_outv (&fo, errfmt, ap);
rtx->_gem.errnum = errnum;
rtx->_gem.errloc = (errloc? *errloc: _nullloc);
} }
void hawk_rtx_errortohawk (hawk_rtx_t* rtx, hawk_t* hawk) void hawk_rtx_errortohawk (hawk_rtx_t* rtx, hawk_t* hawk)
@ -599,6 +408,56 @@ void hawk_rtx_errortohawk (hawk_rtx_t* rtx, hawk_t* hawk)
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
void hawk_gem_geterrinf (hawk_gem_t* gem, hawk_errinf_t* errinf)
{
errinf->num = gem->errnum;
errinf->loc = gem->errloc;
hawk_copy_oocstr (errinf->msg, HAWK_COUNTOF(errinf->msg), (gem->errmsg[0] == '\0'? gem->errstr(gem->errnum): gem->errmsg));
}
void hawk_gem_geterror (hawk_gem_t* gem, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc)
{
if (errnum) *errnum = gem->errnum;
if (errmsg) *errmsg = (gem->errmsg[0] == '\0')? gem->errstr(gem->errnum): gem->errmsg;
if (errloc) *errloc = gem->errloc;
}
const hawk_bch_t* hawk_gem_geterrbmsg (hawk_gem_t* gem)
{
#if defined(HAWK_OOCH_IS_BCH)
return (gem->errmsg[0] == '\0')? gem->errstr(gem->errnum): gem->errmsg;
#else
const hawk_ooch_t* msg;
hawk_oow_t wcslen, mbslen;
msg = (gem->errmsg[0] == '\0')? gem->errstr(gem->errnum): gem->errmsg;
mbslen = HAWK_COUNTOF(gem->xerrmsg);
hawk_conv_ucstr_to_bcstr_with_cmgr (msg, &wcslen, gem->xerrmsg, &mbslen, gem->cmgr);
return gem->xerrmsg;
#endif
}
const hawk_uch_t* hawk_gem_geterrumsg (hawk_gem_t* gem)
{
#if defined(HAWK_OOCH_IS_BCH)
const hawk_ooch_t* msg;
hawk_oow_t wcslen, mbslen;
msg = (gem->errmsg[0] == '\0')? gem->errstr(gem->errnum): gem->errmsg;
wcslen = HAWK_COUNTOF(gem->xerrmsg);
hawk_conv_bcstr_to_ucstr_with_cmgr (msg, &mbslen, gem->xerrmsg, &wcslen, gem->cmgr, 1);
return gem->xerrmsg;
#else
return (gem->errmsg[0] == '\0')? gem->errstr(gem->errnum): gem->errmsg;
#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)
{ {
gem->errnum = errnum; gem->errnum = errnum;
@ -606,6 +465,12 @@ void hawk_gem_seterrnum (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnum_
gem->errloc = (errloc? *errloc: _nullloc); gem->errloc = (errloc? *errloc: _nullloc);
} }
void hawk_gem_seterrinf (hawk_gem_t* gem, const hawk_errinf_t* errinf)
{
gem->errnum = errinf->num;
hawk_copy_oocstr(gem->errmsg, HAWK_COUNTOF(gem->errmsg), errinf->msg);
gem->errloc = errinf->loc;
}
static int gem_err_bchars (hawk_fmtout_t* fmtout, const hawk_bch_t* ptr, hawk_oow_t len) static int gem_err_bchars (hawk_fmtout_t* fmtout, const hawk_bch_t* ptr, hawk_oow_t len)
{ {
@ -656,7 +521,6 @@ void hawk_gem_seterrbfmt (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnum
va_list ap; va_list ap;
hawk_fmtout_t fo; hawk_fmtout_t fo;
/*if (hawk->shuterr) return;*/
gem->errmsg_len = 0; gem->errmsg_len = 0;
gem->errmsg[0] = '\0'; gem->errmsg[0] = '\0';
@ -679,7 +543,6 @@ void hawk_gem_seterrufmt (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnum
va_list ap; va_list ap;
hawk_fmtout_t fo; hawk_fmtout_t fo;
/*if (hawk->shuterr) return;*/
gem->errmsg_len = 0; gem->errmsg_len = 0;
gem->errmsg[0] = '\0'; gem->errmsg[0] = '\0';
@ -697,3 +560,40 @@ void hawk_gem_seterrufmt (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnum
gem->errloc = (errloc? *errloc: _nullloc); gem->errloc = (errloc? *errloc: _nullloc);
} }
void hawk_gem_seterrbvfmt (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_bch_t* errfmt, va_list ap)
{
hawk_fmtout_t fo;
gem->errmsg_len = 0;
gem->errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = gem->mmgr;
fo.putbchars = gem_err_bchars;
fo.putuchars = gem_err_uchars;
fo.ctx = gem;
hawk_bfmt_outv (&fo, errfmt, ap);
gem->errnum = errnum;
gem->errloc = (errloc? *errloc: _nullloc);
}
void hawk_gem_seterruvfmt (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_uch_t* errfmt, va_list ap)
{
hawk_fmtout_t fo;
gem->errmsg_len = 0;
gem->errmsg[0] = '\0';
HAWK_MEMSET (&fo, 0, HAWK_SIZEOF(fo));
fo.mmgr = gem->mmgr;
fo.putbchars = gem_err_bchars;
fo.putuchars = gem_err_uchars;
fo.ctx = gem;
hawk_ufmt_outv (&fo, errfmt, ap);
gem->errnum = errnum;
gem->errloc = (errloc? *errloc: _nullloc);
}

View File

@ -1085,6 +1085,30 @@ struct hawk_loc_t
}; };
typedef struct hawk_loc_t hawk_loc_t; typedef struct hawk_loc_t hawk_loc_t;
/**
* The hawk_errinf_t type defines a placeholder for error information.
*/
struct hawk_errinf_t
{
hawk_errnum_t num; /**< error number */
hawk_ooch_t msg[HAWK_ERRMSG_CAPA]; /**< error message */
hawk_loc_t loc; /**< error location */
};
typedef struct hawk_errinf_t hawk_errinf_t;
/**
* The hawk_errstr_t type defines an error string getter. It should return
* an error formatting string for an error number requested. A new string
* should contain the same number of positional parameters (${X}) as in the
* default error formatting string. You can set a new getter into an hawk
* object with the hawk_seterrstr() function to customize an error string.
*/
typedef const hawk_ooch_t* (*hawk_errstr_t) (
hawk_errnum_t num /**< error number */
);
struct hawk_gem_t struct hawk_gem_t
{ {
hawk_mmgr_t* mmgr; hawk_mmgr_t* mmgr;
@ -1092,7 +1116,13 @@ struct hawk_gem_t
hawk_errnum_t errnum; hawk_errnum_t errnum;
hawk_ooch_t errmsg[HAWK_ERRMSG_CAPA]; hawk_ooch_t errmsg[HAWK_ERRMSG_CAPA];
hawk_loc_t errloc; hawk_loc_t errloc;
hawk_errstr_t errstr;
hawk_oow_t errmsg_len; /* it's not the actual length of errmsg. it's kept here for error formatting */ hawk_oow_t errmsg_len; /* it's not the actual length of errmsg. it's kept here for error formatting */
#if defined(HAWK_OOCH_IS_BCH)
hawk_uch_t xerrmsg[HAWK_ERRMSG_CAPA];
#else
hawk_bch_t xerrmsg[HAWK_ERRMSG_CAPA * 2];
#endif
}; };
enum hawk_log_mask_t enum hawk_log_mask_t

View File

@ -439,6 +439,23 @@ static HAWK_INLINE hawk_errnum_t hawk_gem_geterrnum (hawk_gem_t* gem) { return g
#define hawk_gem_geterrnum(gem) (((hawk_gem_t*)(gem))->errnum) #define hawk_gem_geterrnum(gem) (((hawk_gem_t*)(gem))->errnum)
#endif #endif
HAWK_EXPORT void hawk_gem_geterrinf (
hawk_gem_t* gem,
hawk_errinf_t* errinf
);
HAWK_EXPORT void hawk_gem_geterror (
hawk_gem_t* gem,
hawk_errnum_t* errnum,
const hawk_ooch_t** errmsg,
hawk_loc_t* errloc
);
HAWK_EXPORT void hawk_gem_seterrinf (
hawk_gem_t* gem,
const hawk_errinf_t* errinf
);
HAWK_EXPORT void hawk_gem_seterrnum ( HAWK_EXPORT void hawk_gem_seterrnum (
hawk_gem_t* gem, hawk_gem_t* gem,
const hawk_loc_t* errloc, const hawk_loc_t* errloc,
@ -461,6 +478,22 @@ HAWK_EXPORT void hawk_gem_seterrufmt (
... ...
); );
HAWK_EXPORT void hawk_gem_seterrbvfmt (
hawk_gem_t* gem,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_bch_t* errfmt,
va_list ap
);
HAWK_EXPORT void hawk_gem_seterruvfmt (
hawk_gem_t* gem,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_uch_t* errfmt,
va_list ap
);
HAWK_EXPORT int hawk_gem_buildrex ( HAWK_EXPORT int hawk_gem_buildrex (
hawk_gem_t* gem, hawk_gem_t* gem,
const hawk_ooch_t* ptn, const hawk_ooch_t* ptn,

View File

@ -336,8 +336,7 @@ struct hawk_t
} tmp; } tmp;
/* housekeeping */ /* housekeeping */
hawk_errstr_t errstr; //hawk_oow_t errmsg_len; /* used by errbfmt() and errufmt(). don't rely on this. some other funtions don't set this properly */
hawk_oow_t errmsg_len; /* used by errbfmt() and errufmt(). don't rely on this. some other funtions don't set this properly */
hawk_ooch_t errmsg_backup[HAWK_ERRMSG_CAPA]; hawk_ooch_t errmsg_backup[HAWK_ERRMSG_CAPA];
#if defined(HAWK_OOCH_IS_BCH) #if defined(HAWK_OOCH_IS_BCH)
hawk_uch_t xerrmsg[HAWK_ERRMSG_CAPA]; hawk_uch_t xerrmsg[HAWK_ERRMSG_CAPA];
@ -545,7 +544,7 @@ struct hawk_rtx_t
hawk_oow_t capa; hawk_oow_t capa;
} forin; /* keys for for (x in y) ... */ } forin; /* keys for for (x in y) ... */
hawk_oow_t errmsg_len; /* used by errbfmt() and errufmt(). don't rely on this. some other funtions don't set this properly */ //hawk_oow_t errmsg_len; /* used by errbfmt() and errufmt(). don't rely on this. some other funtions don't set this properly */
hawk_ooch_t errmsg_backup[HAWK_ERRMSG_CAPA]; hawk_ooch_t errmsg_backup[HAWK_ERRMSG_CAPA];
#if defined(HAWK_OOCH_IS_BCH) #if defined(HAWK_OOCH_IS_BCH)
hawk_uch_t xerrmsg[HAWK_ERRMSG_CAPA]; hawk_uch_t xerrmsg[HAWK_ERRMSG_CAPA];

View File

@ -154,7 +154,7 @@ int hawk_init (hawk_t* hawk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_pr
hawk->_gem.errloc.line = 0; hawk->_gem.errloc.line = 0;
hawk->_gem.errloc.colm = 0; hawk->_gem.errloc.colm = 0;
hawk->_gem.errloc.file = HAWK_NULL; hawk->_gem.errloc.file = HAWK_NULL;
hawk->errstr = hawk_dfl_errstr; hawk->_gem.errstr = hawk_dfl_errstr;
hawk->haltall = 0; hawk->haltall = 0;
/* progagate the primitive functions */ /* progagate the primitive functions */

View File

@ -1340,17 +1340,6 @@ typedef enum hawk_trait_t hawk_trait_t;
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
/**
* The hawk_errinf_t type defines a placeholder for error information.
*/
struct hawk_errinf_t
{
hawk_errnum_t num; /**< error number */
hawk_ooch_t msg[HAWK_ERRMSG_CAPA]; /**< error message */
hawk_loc_t loc; /**< error location */
};
typedef struct hawk_errinf_t hawk_errinf_t;
/** /**
* The hawk_errstr_t type defines an error string getter. It should return * The hawk_errstr_t type defines an error string getter. It should return
* an error formatting string for an error number requested. A new string * an error formatting string for an error number requested. A new string

View File

@ -99,6 +99,7 @@ int hawk_sed_init (hawk_sed_t* sed, hawk_mmgr_t* mmgr)
sed->_gem.errloc.line = 0; sed->_gem.errloc.line = 0;
sed->_gem.errloc.colm = 0; sed->_gem.errloc.colm = 0;
sed->_gem.errloc.file = HAWK_NULL; sed->_gem.errloc.file = HAWK_NULL;
sed->_gem.errstr = hawk_dfl_errstr;
if (hawk_ooecs_init(&sed->tmp.rex, hawk_sed_getgem(sed), 0) <= -1) goto oops_1; if (hawk_ooecs_init(&sed->tmp.rex, hawk_sed_getgem(sed), 0) <= -1) goto oops_1;
if (hawk_ooecs_init(&sed->tmp.lab, hawk_sed_getgem(sed), 0) <= -1) goto oops_2; if (hawk_ooecs_init(&sed->tmp.lab, hawk_sed_getgem(sed), 0) <= -1) goto oops_2;