renamed hawk_dflerrstr() to hawk_dfl_errstr().

removed the hawk_t* argument from hawk_dfl_errstr().
added the _cmd field to Hawk
This commit is contained in:
hyung-hwan 2020-01-15 04:59:36 +00:00
parent b7fecc3172
commit 27e0b5f4f7
8 changed files with 30 additions and 28 deletions

View File

@ -1338,13 +1338,15 @@ Hawk::Hawk (Mmgr* mmgr):
{ {
HAWK_MEMSET (&errinf, 0, HAWK_SIZEOF(errinf)); HAWK_MEMSET (&errinf, 0, HAWK_SIZEOF(errinf));
errinf.num = HAWK_ENOERR; errinf.num = HAWK_ENOERR;
this->_cmgr = hawk_get_cmgr_by_id(HAWK_CMGR_UTF8);
} }
const hawk_ooch_t* Hawk::getErrorString (hawk_errnum_t num) const const hawk_ooch_t* Hawk::getErrorString (hawk_errnum_t num) const
{ {
HAWK_ASSERT (awk != HAWK_NULL); HAWK_ASSERT (awk != HAWK_NULL);
HAWK_ASSERT (this->dflerrstr != HAWK_NULL); HAWK_ASSERT (this->dflerrstr != HAWK_NULL);
return this->dflerrstr(this->hawk, num); return this->dflerrstr(num);
} }
const hawk_ooch_t* Hawk::xerrstr (hawk_t* a, hawk_errnum_t num) const hawk_ooch_t* Hawk::xerrstr (hawk_t* a, hawk_errnum_t num)
@ -1376,7 +1378,7 @@ const hawk_uch_t* Hawk::getErrorLocationFileU () const
if (!this->errinf.loc.file) return HAWK_NULL; if (!this->errinf.loc.file) return HAWK_NULL;
hawk_oow_t wcslen, mbslen; hawk_oow_t wcslen, mbslen;
wcslen = HAWK_COUNTOF(this->xerrlocfile); wcslen = HAWK_COUNTOF(this->xerrlocfile);
hawk_conv_bcstr_to_ucstr_with_cmgr (this->errinf.loc.file, &mbslen, hawk->xerrlocfile, &wcslen, hawk_getcmgr(this->hawk), 1); hawk_conv_bcstr_to_ucstr_with_cmgr (this->errinf.loc.file, &mbslen, hawk->xerrlocfile, &wcslen, this->getCmgr(), 1);
return hawk->xerrlocfile; return hawk->xerrlocfile;
#endif #endif
} }
@ -1387,7 +1389,7 @@ const hawk_bch_t* Hawk::getErrorLocationFileB () const
if (!this->errinf.loc.file) return HAWK_NULL; if (!this->errinf.loc.file) return HAWK_NULL;
hawk_oow_t wcslen, mbslen; hawk_oow_t wcslen, mbslen;
mbslen = HAWK_COUNTOF(this->xerrlocfile); mbslen = HAWK_COUNTOF(this->xerrlocfile);
hawk_conv_ucstr_to_bcstr_with_cmgr (this->errinf.loc.file, &wcslen, this->xerrlocfile, &mbslen, hawk_getcmgr(this->hawk)); hawk_conv_ucstr_to_bcstr_with_cmgr (this->errinf.loc.file, &wcslen, this->xerrlocfile, &mbslen, this->getCmgr());
return this->xerrlocfile; return this->xerrlocfile;
#else #else
return this->errinf.loc.file; return this->errinf.loc.file;
@ -1406,7 +1408,7 @@ const hawk_uch_t* Hawk::getErrorMessageU () const
#else #else
hawk_oow_t wcslen, mbslen; hawk_oow_t wcslen, mbslen;
wcslen = HAWK_COUNTOF(this->xerrmsg); wcslen = HAWK_COUNTOF(this->xerrmsg);
hawk_conv_bcstr_to_ucstr_with_cmgr (this->errinf.msg, &mbslen, this->xerrmsg, &wcslen, hawk_getcmgr(this->hawk), 1); hawk_conv_bcstr_to_ucstr_with_cmgr (this->errinf.msg, &mbslen, this->xerrmsg, &wcslen, this->getCmgr(), 1);
return this->xerrmsg; return this->xerrmsg;
#endif #endif
} }
@ -1416,7 +1418,7 @@ const hawk_bch_t* Hawk::getErrorMessageB () const
#if defined(HAWK_OOCH_IS_UCH) #if defined(HAWK_OOCH_IS_UCH)
hawk_oow_t wcslen, mbslen; hawk_oow_t wcslen, mbslen;
mbslen = HAWK_COUNTOF(this->xerrmsg); mbslen = HAWK_COUNTOF(this->xerrmsg);
hawk_conv_ucstr_to_bcstr_with_cmgr (this->errinf.msg, &wcslen, this->xerrmsg, &mbslen, hawk_getcmgr(this->hawk)); hawk_conv_ucstr_to_bcstr_with_cmgr (this->errinf.msg, &wcslen, this->xerrmsg, &mbslen, this->getCmgr());
return this->xerrmsg; return this->xerrmsg;
#else #else
return this->errinf.msg; return this->errinf.msg;
@ -1435,7 +1437,7 @@ void Hawk::setError (hawk_errnum_t code, const hawk_loc_t* loc)
HAWK_MEMSET (&this->errinf, 0, HAWK_SIZEOF(this->errinf)); HAWK_MEMSET (&this->errinf, 0, HAWK_SIZEOF(this->errinf));
this->errinf.num = code; this->errinf.num = code;
if (loc != HAWK_NULL) this->errinf.loc = *loc; if (loc != HAWK_NULL) this->errinf.loc = *loc;
hawk_copy_oocstr (this->errinf.msg, HAWK_COUNTOF(this->errinf.msg), HAWK_T("not ready to set an error message")); hawk_copy_oocstr (this->errinf.msg, HAWK_COUNTOF(this->errinf.msg), hawk_dfl_errstr(code));
} }
} }
@ -1454,7 +1456,7 @@ void Hawk::formatError (hawk_errnum_t code, const hawk_loc_t* loc, const hawk_bc
HAWK_MEMSET (&this->errinf, 0, HAWK_SIZEOF(this->errinf)); HAWK_MEMSET (&this->errinf, 0, HAWK_SIZEOF(this->errinf));
this->errinf.num = code; this->errinf.num = code;
if (loc != HAWK_NULL) this->errinf.loc = *loc; if (loc != HAWK_NULL) this->errinf.loc = *loc;
hawk_copy_oocstr (this->errinf.msg, HAWK_COUNTOF(this->errinf.msg), HAWK_T("not ready to set an error message")); hawk_copy_oocstr (this->errinf.msg, HAWK_COUNTOF(this->errinf.msg), hawk_dfl_errstr(code));
} }
} }
@ -1531,7 +1533,7 @@ int Hawk::open ()
prm.modgetsym = Hawk::modgetsym; prm.modgetsym = Hawk::modgetsym;
hawk_errnum_t errnum; hawk_errnum_t errnum;
this->hawk = hawk_open(this->getMmgr(), HAWK_SIZEOF(xtn_t), hawk_get_cmgr_by_id(HAWK_CMGR_UTF8), &prm, &errnum); this->hawk = hawk_open(this->getMmgr(), HAWK_SIZEOF(xtn_t), this->getCmgr(), &prm, &errnum);
if (!this->hawk) if (!this->hawk)
{ {
this->setError (errnum); this->setError (errnum);
@ -1616,7 +1618,7 @@ void Hawk::close ()
hawk_cmgr_t* Hawk::getCmgr () const hawk_cmgr_t* Hawk::getCmgr () const
{ {
if (!this->hawk) return HAWK_NULL; if (!this->hawk) return this->_cmgr;
return hawk_getcmgr(this->hawk); return hawk_getcmgr(this->hawk);
} }

View File

@ -1741,7 +1741,7 @@ protected:
static void* modgetsym (hawk_t* awk, void* handle, const hawk_ooch_t* name); static void* modgetsym (hawk_t* awk, void* handle, const hawk_ooch_t* name);
public: public:
// use this with care // use these with care
hawk_t* getHandle() const { return this->hawk; } hawk_t* getHandle() const { return this->hawk; }
protected: protected:
@ -1797,6 +1797,7 @@ protected:
xstrs_t runarg; xstrs_t runarg;
private: private:
hawk_cmgr_t* _cmgr;
Run runctx; Run runctx;
int init_runctx (); int init_runctx ();

View File

@ -125,7 +125,7 @@ public:
const hawk_ooch_t* ptr; const hawk_ooch_t* ptr;
}; };
HawkStd (Mmgr* mmgr = HAWK_NULL): Hawk(mmgr), stdmod_up(false), console_cmgr(HAWK_NULL) HawkStd (Mmgr* mmgr = HAWK_NULL): Hawk(mmgr), cmgrtab_inited(false), stdmod_up(false), console_cmgr(HAWK_NULL)
{ {
} }

View File

@ -31,7 +31,7 @@
extern "C" { extern "C" {
#endif #endif
const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum); const hawk_ooch_t* hawk_dfl_errstr (hawk_errnum_t errnum);
hawk_errnum_t hawk_syserr_to_errnum (hawk_intptr_t e); hawk_errnum_t hawk_syserr_to_errnum (hawk_intptr_t e);

View File

@ -28,7 +28,7 @@
static hawk_loc_t _nullloc = { 0, 0, HAWK_NULL }; static hawk_loc_t _nullloc = { 0, 0, HAWK_NULL };
const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum) const hawk_ooch_t* hawk_dfl_errstr (hawk_errnum_t errnum)
{ {
static const hawk_ooch_t* errstr[] = static const hawk_ooch_t* errstr[] =
{ {
@ -199,12 +199,12 @@ const hawk_loc_t* hawk_geterrloc (hawk_t* hawk)
const hawk_bch_t* hawk_geterrbmsg (hawk_t* hawk) const hawk_bch_t* hawk_geterrbmsg (hawk_t* hawk)
{ {
#if defined(HAWK_OOCH_IS_BCH) #if defined(HAWK_OOCH_IS_BCH)
return (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk, hawk->_gem.errnum): hawk->_gem.errmsg; return (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg;
#else #else
const hawk_ooch_t* msg; const hawk_ooch_t* msg;
hawk_oow_t wcslen, mbslen; hawk_oow_t wcslen, mbslen;
msg = (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk, hawk->_gem.errnum): hawk->_gem.errmsg; msg = (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg;
mbslen = HAWK_COUNTOF(hawk->xerrmsg); mbslen = HAWK_COUNTOF(hawk->xerrmsg);
hawk_conv_ucstr_to_bcstr_with_cmgr (msg, &wcslen, hawk->xerrmsg, &mbslen, hawk_getcmgr(hawk)); hawk_conv_ucstr_to_bcstr_with_cmgr (msg, &wcslen, hawk->xerrmsg, &mbslen, hawk_getcmgr(hawk));
@ -219,14 +219,14 @@ const hawk_uch_t* hawk_geterrumsg (hawk_t* hawk)
const hawk_ooch_t* msg; const hawk_ooch_t* msg;
hawk_oow_t wcslen, mbslen; hawk_oow_t wcslen, mbslen;
msg = (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk, hawk->_gem.errnum): hawk->_gem.errmsg; msg = (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg;
wcslen = HAWK_COUNTOF(hawk->xerrmsg); wcslen = HAWK_COUNTOF(hawk->xerrmsg);
hawk_conv_bcstr_to_ucstr_with_cmgr (msg, &mbslen, hawk->xerrmsg, &wcslen, hawk_getcmgr(hawk), 1); hawk_conv_bcstr_to_ucstr_with_cmgr (msg, &mbslen, hawk->xerrmsg, &wcslen, hawk_getcmgr(hawk), 1);
return hawk->xerrmsg; return hawk->xerrmsg;
#else #else
return (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk, hawk->_gem.errnum): hawk->_gem.errmsg; return (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg;
#endif #endif
} }
@ -234,13 +234,13 @@ void hawk_geterrinf (hawk_t* hawk, hawk_errinf_t* errinf)
{ {
errinf->num = hawk->_gem.errnum; errinf->num = hawk->_gem.errnum;
errinf->loc = hawk->_gem.errloc; errinf->loc = hawk->_gem.errloc;
hawk_copy_oocstr (errinf->msg, HAWK_COUNTOF(errinf->msg), (hawk->_gem.errmsg[0] == '\0'? hawk_geterrstr(hawk)(hawk, hawk->_gem.errnum): hawk->_gem.errmsg)); 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; if (errnum) *errnum = hawk->_gem.errnum;
if (errmsg) *errmsg = (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk, hawk->_gem.errnum): hawk->_gem.errmsg; if (errmsg) *errmsg = (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg;
if (errloc) *errloc = hawk->_gem.errloc; if (errloc) *errloc = hawk->_gem.errloc;
} }
@ -398,12 +398,12 @@ const hawk_loc_t* hawk_rtx_geterrloc (hawk_rtx_t* rtx)
const hawk_bch_t* hawk_rtx_geterrbmsg (hawk_rtx_t* rtx) const hawk_bch_t* hawk_rtx_geterrbmsg (hawk_rtx_t* rtx)
{ {
#if defined(HAWK_OOCH_IS_BCH) #if defined(HAWK_OOCH_IS_BCH)
return (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(hawk_rtx_gethawk(rtx), rtx->_gem.errnum): rtx->_gem.errmsg; return (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(rtx->_gem.errnum): rtx->_gem.errmsg;
#else #else
const hawk_ooch_t* msg; const hawk_ooch_t* msg;
hawk_oow_t wcslen, mbslen; hawk_oow_t wcslen, mbslen;
msg = (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(hawk_rtx_gethawk(rtx), rtx->_gem.errnum): rtx->_gem.errmsg; msg = (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(rtx->_gem.errnum): rtx->_gem.errmsg;
mbslen = HAWK_COUNTOF(rtx->xerrmsg); mbslen = HAWK_COUNTOF(rtx->xerrmsg);
hawk_conv_ucstr_to_bcstr_with_cmgr (msg, &wcslen, rtx->xerrmsg, &mbslen, hawk_rtx_getcmgr(rtx)); hawk_conv_ucstr_to_bcstr_with_cmgr (msg, &wcslen, rtx->xerrmsg, &mbslen, hawk_rtx_getcmgr(rtx));
@ -418,14 +418,14 @@ const hawk_uch_t* hawk_rtx_geterrumsg (hawk_rtx_t* rtx)
const hawk_ooch_t* msg; const hawk_ooch_t* msg;
hawk_oow_t wcslen, mbslen; hawk_oow_t wcslen, mbslen;
msg = (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(hawk_rtx_gethawk(rtx), rtx->_gem.errnum): rtx->_gem.errmsg; msg = (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(rtx->_gem.errnum): rtx->_gem.errmsg;
wcslen = HAWK_COUNTOF(rtx->xerrmsg); wcslen = HAWK_COUNTOF(rtx->xerrmsg);
hawk_conv_bcstr_to_ucstr_with_cmgr (msg, &mbslen, rtx->xerrmsg, &wcslen, hawk_rtx_getcmgr(rtx), 1); hawk_conv_bcstr_to_ucstr_with_cmgr (msg, &mbslen, rtx->xerrmsg, &wcslen, hawk_rtx_getcmgr(rtx), 1);
return rtx->xerrmsg; return rtx->xerrmsg;
#else #else
return (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(hawk_rtx_gethawk(rtx), rtx->_gem.errnum): rtx->_gem.errmsg; return (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(rtx->_gem.errnum): rtx->_gem.errmsg;
#endif #endif
} }
@ -433,13 +433,13 @@ void hawk_rtx_geterrinf (hawk_rtx_t* rtx, hawk_errinf_t* errinf)
{ {
errinf->num = rtx->_gem.errnum; errinf->num = rtx->_gem.errnum;
errinf->loc = rtx->_gem.errloc; 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))(hawk_rtx_gethawk(rtx), rtx->_gem.errnum): rtx->_gem.errmsg)); 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; if (errnum) *errnum = rtx->_gem.errnum;
if (errmsg) *errmsg = (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(hawk_rtx_gethawk(rtx), rtx->_gem.errnum): rtx->_gem.errmsg; 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; if (errloc) *errloc = rtx->_gem.errloc;
} }

View File

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

View File

@ -1278,7 +1278,6 @@ typedef struct hawk_errinf_t hawk_errinf_t;
* object with the hawk_seterrstr() function to customize an error string. * object with the hawk_seterrstr() function to customize an error string.
*/ */
typedef const hawk_ooch_t* (*hawk_errstr_t) ( typedef const hawk_ooch_t* (*hawk_errstr_t) (
hawk_t* awk, /**< awk */
hawk_errnum_t num /**< error number */ hawk_errnum_t num /**< error number */
); );

View File

@ -158,7 +158,7 @@ static hawk_int_t set_error_on_sys_list (hawk_rtx_t* rtx, sys_list_t* sys_list,
} }
else else
{ {
hawk_rtx_fmttooocstr (rtx, sys_list->ctx.errmsg, HAWK_COUNTOF(sys_list->ctx.errmsg), HAWK_T("%js"), hawk_geterrstr(hawk_rtx_gethawk(rtx))(hawk_rtx_gethawk(rtx), errnum)); hawk_rtx_fmttooocstr (rtx, sys_list->ctx.errmsg, HAWK_COUNTOF(sys_list->ctx.errmsg), HAWK_T("%js"), hawk_geterrstr(hawk_rtx_gethawk(rtx))(errnum));
} }
return ERRNUM_TO_RC(errnum); return ERRNUM_TO_RC(errnum);
} }