diff --git a/hawk/bin/main.c b/hawk/bin/main.c index 2ec429a9..f83ba3a9 100644 --- a/hawk/bin/main.c +++ b/hawk/bin/main.c @@ -280,6 +280,7 @@ static void stop_run (int signo) int e = errno; #endif + /*hawk_haltall(hawk_rtx_gethawk(app_rtx));*/ hawk_rtx_halt (app_rtx); #if !defined(_WIN32) && !defined(__OS2__) && !defined(__DOS__) diff --git a/hawk/lib/err.c b/hawk/lib/err.c index 5dbe3018..34e8251a 100644 --- a/hawk/lib/err.c +++ b/hawk/lib/err.c @@ -49,7 +49,8 @@ const hawk_ooch_t* hawk_dflerrstr (hawk_t* awk, hawk_errnum_t errnum) HAWK_T("I/O error"), HAWK_T("buffer full"), HAWK_T("encoding conversion error"), - HAWK_T("not directory"), + HAWK_T("is a directory"), + HAWK_T("not a directory"), HAWK_T("resource temporarily unavailable"), HAWK_T("interrupted"), HAWK_T("broken pipe"), @@ -256,11 +257,6 @@ const hawk_ooch_t* hawk_backuperrmsg (hawk_t* hawk) return hawk->errmsg_backup; } -void hawk_seterrnum (hawk_t* hawk, hawk_errnum_t errnum, const hawk_oocs_t* errarg) -{ - hawk_seterror (hawk, errnum, errarg, HAWK_NULL); -} - void hawk_seterrinf (hawk_t* hawk, const hawk_errinf_t* errinf) { hawk->_gem.errnum = errinf->num; diff --git a/hawk/lib/fnc.c b/hawk/lib/fnc.c index 26d5893b..a3f58151 100644 --- a/hawk/lib/fnc.c +++ b/hawk/lib/fnc.c @@ -105,7 +105,7 @@ static hawk_fnc_t* add_fnc (hawk_t* hawk, const hawk_ooch_t* name, const hawk_fn ncs.len = hawk_count_oocstr(name); if (ncs.len <= 0) { - hawk_seterrnum (hawk, HAWK_EINVAL, HAWK_NULL); + hawk_seterrnum (hawk, HAWK_NULL, HAWK_EINVAL); return HAWK_NULL; } @@ -115,7 +115,7 @@ static hawk_fnc_t* add_fnc (hawk_t* hawk, const hawk_ooch_t* name, const hawk_fn if (hawk_findfncwithoocs(hawk, &ncs) != HAWK_NULL) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_EEXIST, "unable to add existing function - %js", name); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EEXIST, HAWK_T("unable to add existing function - %js"), name); return HAWK_NULL; } @@ -142,7 +142,7 @@ static hawk_fnc_t* add_fnc (hawk_t* hawk, const hawk_ooch_t* name, const hawk_fn if (hawk_htb_insert(hawk->fnc.user, (hawk_ooch_t*)ncs.ptr, ncs.len, fnc, 0) == HAWK_NULL) { const hawk_ooch_t* bem = hawk_backuperrmsg(hawk); - hawk_seterrbfmt (hawk, HAWK_NULL, hawk_geterrnum(hawk), "unable to add function - %js - %js", name, bem); + hawk_seterrfmt (hawk, HAWK_NULL, hawk_geterrnum(hawk), HAWK_T("unable to add function - %js - %js"), name, bem); hawk_freemem (hawk, fnc); fnc = HAWK_NULL; } @@ -228,7 +228,7 @@ int hawk_delfncwithbcstr (hawk_t* hawk, const hawk_bch_t* name) #if defined(HAWK_OOCH_IS_BCH) if (hawk_htb_delete(hawk->fnc.user, ncs.ptr, ncs.len) <= -1) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such function - %hs", name); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such function - %hs"), name); return -1; } #else @@ -236,7 +236,7 @@ int hawk_delfncwithbcstr (hawk_t* hawk, const hawk_bch_t* name) if (!wcs.ptr) return -1; if (hawk_htb_delete(hawk->fnc.user, wcs.ptr, wcs.len) <= -1) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such function - %hs", name); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such function - %hs"), name); hawk_freemem (hawk, wcs.ptr); return -1; } @@ -259,7 +259,7 @@ int hawk_delfncwithucstr (hawk_t* hawk, const hawk_uch_t* name) if (!mbs.ptr) return -1; if (hawk_htb_delete(hawk->fnc.user, mbs.ptr, mbs.len) <= -1) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such function - %ls", name); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such function - %ls"), name); hawk_freemem (hawk, mbs.ptr); return -1; } @@ -267,7 +267,7 @@ int hawk_delfncwithucstr (hawk_t* hawk, const hawk_uch_t* name) #else if (hawk_htb_delete(hawk->fnc.user, ncs.ptr, ncs.len) <= -1) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such function - %ls", name); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such function - %ls"), name); return -1; } #endif @@ -304,7 +304,7 @@ static hawk_fnc_t* find_fnc (hawk_t* awk, const hawk_oocs_t* name) if ((awk->opt.trait & fnc->spec.trait) == fnc->spec.trait) return fnc; } - hawk_seterrbfmt (awk, HAWK_NULL, HAWK_ENOENT, "no such function - %js", name); + hawk_seterrfmt (awk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such function - %js"), name); return HAWK_NULL; } diff --git a/hawk/lib/hawk-cmn.h b/hawk/lib/hawk-cmn.h index 8adfc800..709b46d5 100644 --- a/hawk/lib/hawk-cmn.h +++ b/hawk/lib/hawk-cmn.h @@ -777,6 +777,7 @@ enum hawk_errnum_t HAWK_EIOERR, /**< I/O error */ HAWK_EBUFFULL, /**< buffer full */ HAWK_EECERR, /**< encoding conversion error */ + HAWK_EISDIR, /**< is directory */ HAWK_ENOTDIR, /**< not directory */ HAWK_EAGAIN, /**< resource temporarily unavailable */ HAWK_EINTR, /**< interrupted */ diff --git a/hawk/lib/hawk.c b/hawk/lib/hawk.c index 3e84d1cc..cde02015 100644 --- a/hawk/lib/hawk.c +++ b/hawk/lib/hawk.c @@ -165,7 +165,7 @@ int hawk_init (hawk_t* awk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_prm prm->math.pow == HAWK_NULL || prm->math.mod == HAWK_NULL) { - hawk_seterrnum (awk, HAWK_EINVAL, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EINVAL); goto oops; } awk->prm = *prm; @@ -218,7 +218,7 @@ int hawk_init (hawk_t* awk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_prm awk->fnc.user == HAWK_NULL || awk->modtab == HAWK_NULL) { - hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM); goto oops; } @@ -511,7 +511,7 @@ int hawk_setopt (hawk_t* hawk, hawk_opt_t id, const void* value) } - hawk_seterrnum (hawk, HAWK_EINVAL, HAWK_NULL); + hawk_seterrnum (hawk, HAWK_NULL, HAWK_EINVAL); return -1; } @@ -556,14 +556,13 @@ int hawk_getopt (hawk_t* hawk, hawk_opt_t id, void* value) }; - hawk_seterrnum (hawk, HAWK_EINVAL, HAWK_NULL); + hawk_seterrnum (hawk, HAWK_NULL, HAWK_EINVAL); return -1; } void hawk_haltall (hawk_t* awk) { awk->haltall = 1; - hawk_seterrnum (awk, HAWK_EINVAL, HAWK_NULL); } hawk_ecb_t* hawk_popecb (hawk_t* awk) diff --git a/hawk/lib/hawk.h b/hawk/lib/hawk.h index 55c675ca..ad8dbf5e 100644 --- a/hawk/lib/hawk.h +++ b/hawk/lib/hawk.h @@ -1598,12 +1598,11 @@ HAWK_EXPORT void hawk_geterrinf ( * error number \a errnum requires one or more arguments to format an * error message. */ -HAWK_EXPORT void hawk_seterrnum ( - hawk_t* awk, /**< awk */ - hawk_errnum_t errnum, /**< error number */ - const hawk_oocs_t* errarg /**< argument array for formatting - * an error message */ -); +#if defined(HAWK_HAVE_INLINE) +static HAWK_INLINE void hawk_seterrnum (hawk_t* hawk, hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_getgem(hawk), errloc, errnum); } +#else +#define hawk_seterrnum(hawk, errloc, errnum) hawk_gem_seterrnum(hawk_getgem(hawk), errloc, errnum) +#endif HAWK_EXPORT void hawk_seterrbfmt ( hawk_t* awk, diff --git a/hawk/lib/parse.c b/hawk/lib/parse.c index 2df2e178..58a71847 100644 --- a/hawk/lib/parse.c +++ b/hawk/lib/parse.c @@ -412,10 +412,6 @@ static global_t gtab[] = #define MATCH_TERMINATOR(awk) \ (MATCH_TERMINATOR_NORMAL(awk) || MATCH_TERMINATOR_RBRACE(awk)) -#define ISNOERR(awk) ((awk)->_gem.errnum == HAWK_ENOERR) - -#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) @@ -469,17 +465,11 @@ static int get_char (hawk_t* awk) if (awk->sio.inp->b.pos >= awk->sio.inp->b.len) { - CLRERR (awk); n = awk->sio.inf( awk, HAWK_SIO_CMD_READ, awk->sio.inp, awk->sio.inp->b.buf, HAWK_COUNTOF(awk->sio.inp->b.buf) ); - if (n <= -1) - { - if (ISNOERR(awk)) - SETERR_ARG (awk, HAWK_EREAD, HAWK_T(""), 5); - return -1; - } + if (n <= -1) return -1; if (n == 0) { @@ -541,14 +531,11 @@ static int parse (hawk_t* awk) HAWK_ASSERT (awk->sio.inf != HAWK_NULL); - CLRERR (awk); op = awk->sio.inf(awk, HAWK_SIO_CMD_OPEN, awk->sio.inp, HAWK_NULL, 0); if (op <= -1) { /* cannot open the source file. * it doesn't even have to call CLOSE */ - if (ISNOERR(awk)) - SETERR_ARG (awk, HAWK_EOPEN, HAWK_T(""), 5); return -1; } @@ -595,6 +582,7 @@ static int parse (hawk_t* awk) } HAWK_ASSERT (awk->tree.ngbls == HAWK_ARR_SIZE(awk->parse.gbls)); + HAWK_ASSERT (awk->sio.inp == &awk->sio.arg); ret = 0; oops: @@ -618,30 +606,11 @@ oops: awk->sio.inp = prev; } } - else if (ret == 0) - { - /* no error occurred so far */ - HAWK_ASSERT (awk->sio.inp == &awk->sio.arg); - CLRERR (awk); - } - if (awk->sio.inf(awk, HAWK_SIO_CMD_CLOSE, awk->sio.inp, HAWK_NULL, 0) != 0) - { - if (ret == 0) - { - /* this is to keep the earlier error above - * that might be more critical than this */ - if (ISNOERR(awk)) - SETERR_ARG (awk, HAWK_ECLOSE, HAWK_T(""), 5); - ret = -1; - } - } + if (awk->sio.inf(awk, HAWK_SIO_CMD_CLOSE, awk->sio.inp, HAWK_NULL, 0) != 0 && ret == 0) ret = -1; - if (ret <= -1) - { - /* clear the parse tree partially constructed on error */ - hawk_clear (awk); - } + /* clear the parse tree partially constructed on error */ + if (ret <= -1) hawk_clear (awk); return ret; } @@ -775,7 +744,6 @@ static int end_include (hawk_t* awk) /* if it is an included file, close it and * retry to read a character from an outer file */ - CLRERR (awk); x = awk->sio.inf(awk, HAWK_SIO_CMD_CLOSE, awk->sio.inp, HAWK_NULL, 0); /* if closing has failed, still destroy the @@ -796,7 +764,6 @@ static int end_include (hawk_t* awk) if (x != 0) { /* the failure mentioned above is returned here */ - if (ISNOERR(awk)) SETERR_ARG (awk, HAWK_ECLOSE, HAWK_T(""), 5); return -1; } @@ -884,11 +851,9 @@ static int begin_include (hawk_t* awk, int once) /* let the argument's prev field point to the current */ arg->prev = awk->sio.inp; - CLRERR (awk); if (awk->sio.inf(awk, HAWK_SIO_CMD_OPEN, arg, HAWK_NULL, 0) <= -1) { - if (ISNOERR(awk)) SETERR_TOK (awk, HAWK_EOPEN); - else awk->_gem.errloc = awk->tok.loc; /* adjust error location */ + ADJERR_LOC (awk, &awk->tok.loc); goto oops; } @@ -2048,7 +2013,7 @@ int hawk_delgblwithbcstr (hawk_t* hawk, const hawk_bch_t* name) if (hawk->tree.ngbls > hawk->tree.ngbls_base) { /* this function is not allow after hawk_parse is called */ - hawk_seterrnum (hawk, HAWK_EPERM, HAWK_NULL); + hawk_seterrnum (hawk, HAWK_NULL, HAWK_EPERM); return -1; } @@ -2056,7 +2021,7 @@ int hawk_delgblwithbcstr (hawk_t* hawk, const hawk_bch_t* name) n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len); if (n == HAWK_ARR_NIL) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*hs", ncs.len, ncs.ptr); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such global variable - %.*hs"), ncs.len, ncs.ptr); return -1; } #else @@ -2065,7 +2030,7 @@ int hawk_delgblwithbcstr (hawk_t* hawk, const hawk_bch_t* name) n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, wcs.ptr, wcs.len); if (n == HAWK_ARR_NIL) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*ls", wcs.len, wcs.ptr); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such global variable - %.*ls"), wcs.len, wcs.ptr); hawk_freemem (hawk, wcs.ptr); return -1; } @@ -2099,7 +2064,7 @@ int hawk_delgblwithucstr (hawk_t* hawk, const hawk_uch_t* name) if (hawk->tree.ngbls > hawk->tree.ngbls_base) { /* this function is not allow after hawk_parse is called */ - hawk_seterrnum (hawk, HAWK_EPERM, HAWK_NULL); + hawk_seterrnum (hawk, HAWK_NULL, HAWK_EPERM); return -1; } @@ -2109,7 +2074,7 @@ int hawk_delgblwithucstr (hawk_t* hawk, const hawk_uch_t* name) n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, mbs.ptr, mbs.len); if (n == HAWK_ARR_NIL) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*hs", mbs.len, mbs.ptr); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such global variable - %.*hs"), mbs.len, mbs.ptr); hawk_freemem (hawk, mbs.ptr); return -1; } @@ -2118,7 +2083,7 @@ int hawk_delgblwithucstr (hawk_t* hawk, const hawk_uch_t* name) n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len); if (n == HAWK_ARR_NIL) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*ls", ncs.len, ncs.ptr); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such global variable - %.*ls"), ncs.len, ncs.ptr); return -1; } #endif @@ -2151,7 +2116,7 @@ int hawk_findgblwithbcstr (hawk_t* hawk, const hawk_bch_t* name) n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len); if (n == HAWK_ARR_NIL) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*hs", ncs.len, ncs.ptr); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such global variable - %.*hs"), ncs.len, ncs.ptr); return -1; } #else @@ -2160,7 +2125,7 @@ int hawk_findgblwithbcstr (hawk_t* hawk, const hawk_bch_t* name) n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, wcs.ptr, wcs.len); if (n == HAWK_ARR_NIL) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*ls", wcs.len, wcs.ptr); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such global variable - %.*ls"), wcs.len, wcs.ptr); hawk_freemem (hawk, wcs.ptr); return -1; } @@ -2185,7 +2150,7 @@ int hawk_findgblwithucstr (hawk_t* hawk, const hawk_uch_t* name) n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, mbs.ptr, mbs.len); if (n == HAWK_ARR_NIL) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*hs", mbs.len, mbs.ptr); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such global variable - %.*hs"), mbs.len, mbs.ptr); hawk_freemem (hawk, mbs.ptr); return -1; } @@ -2194,7 +2159,7 @@ int hawk_findgblwithucstr (hawk_t* hawk, const hawk_uch_t* name) n = hawk_arr_search(hawk->parse.gbls, HAWK_NUM_STATIC_GBLS, ncs.ptr, ncs.len); if (n == HAWK_ARR_NIL) { - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_ENOENT, "no such global variable - %.*ls", ncs.len, ncs.ptr); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_ENOENT, HAWK_T("no such global variable - %.*ls"), ncs.len, ncs.ptr); return -1; } #endif @@ -2316,7 +2281,7 @@ static hawk_t* collect_locals (hawk_t* awk, hawk_oow_t nlcls, int istop) n = hawk_arr_search(awk->parse.lcls, nlcls, lcl.ptr, lcl.len); if (n != HAWK_ARR_NIL) { - hawk_seterrbfmt (awk, &awk->tok.loc, HAWK_EDUPLCL, "duplicate local variable - %.*js", lcl.len, lcl.ptr); + hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EDUPLCL, HAWK_T("duplicate local variable - %.*js"), lcl.len, lcl.ptr); return HAWK_NULL; } @@ -2328,14 +2293,14 @@ static hawk_t* collect_locals (hawk_t* awk, hawk_oow_t nlcls, int istop) { /* it is a conflict only if it is one of a * static global variable */ - hawk_seterrbfmt (awk, &awk->tok.loc, HAWK_EDUPLCL, "duplicate local variable - %.*js", lcl.len, lcl.ptr); + hawk_seterrfmt (awk, &awk->tok.loc, HAWK_EDUPLCL, HAWK_T("duplicate local variable - %.*js"), lcl.len, lcl.ptr); return HAWK_NULL; } } if (HAWK_ARR_SIZE(awk->parse.lcls) >= HAWK_MAX_LCLS) { - hawk_seterrbfmt (awk, &awk->tok.loc, HAWK_ELCLTM, "too many local variables defined - %.*js", lcl.len, lcl.ptr); + hawk_seterrfmt (awk, &awk->tok.loc, HAWK_ELCLTM, HAWK_T("too many local variables defined - %.*js"), lcl.len, lcl.ptr); return HAWK_NULL; } @@ -3609,7 +3574,7 @@ static int fold_constants_for_binop ( case HAWK_BINOP_DIV: if (((hawk_nde_int_t*)right)->val == 0) { - hawk_seterrnum (awk, HAWK_EDIVBY0, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EDIVBY0); fold = -2; /* error */ } else if (INT_BINOP_INT(left,%,right)) @@ -3627,7 +3592,7 @@ static int fold_constants_for_binop ( case HAWK_BINOP_IDIV: if (((hawk_nde_int_t*)right)->val == 0) { - hawk_seterrnum (awk, HAWK_EDIVBY0, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EDIVBY0); fold = -2; /* error */ } else @@ -5455,12 +5420,10 @@ static hawk_nde_t* parse_primary_ident_segs (hawk_t* awk, const hawk_loc_t* xloc hawk_mod_sym_t sym; hawk_fnc_t fnc; - CLRERR (awk); mod = query_module(awk, segs, nsegs, &sym); if (mod == HAWK_NULL) { - if (ISNOERR(awk)) SETERR_LOC (awk, HAWK_ENOSUP, xloc); - else ADJERR_LOC (awk, xloc); + ADJERR_LOC (awk, xloc); } else { @@ -6757,13 +6720,8 @@ static int deparse (hawk_t* awk) HAWK_MEMSET (&awk->sio.arg, 0, HAWK_SIZEOF(awk->sio.arg)); - CLRERR (awk); op = awk->sio.outf(awk, HAWK_SIO_CMD_OPEN, &awk->sio.arg, HAWK_NULL, 0); - if (op <= -1) - { - if (ISNOERR(awk)) SETERR_ARG (awk, HAWK_EOPEN, HAWK_T(""), 6); - return -1; - } + if (op <= -1) return -1; #define EXIT_DEPARSE() do { n = -1; goto exit_deparse; } while(0) @@ -6911,16 +6869,7 @@ static int deparse (hawk_t* awk) if (flush_out (awk) <= -1) EXIT_DEPARSE (); exit_deparse: - if (n == 0) CLRERR (awk); - if (awk->sio.outf(awk, HAWK_SIO_CMD_CLOSE, &awk->sio.arg, HAWK_NULL, 0) != 0) - { - if (n == 0) - { - if (ISNOERR(awk)) SETERR_ARG (awk, HAWK_ECLOSE, HAWK_T(""), 6); - n = -1; - } - } - + if (awk->sio.outf(awk, HAWK_SIO_CMD_CLOSE, &awk->sio.arg, HAWK_NULL, 0) != 0 && n == 0) n = -1; return n; } @@ -7001,19 +6950,12 @@ static int flush_out (hawk_t* awk) while (awk->sio.arg.b.pos < awk->sio.arg.b.len) { - CLRERR (awk); n = awk->sio.outf ( awk, HAWK_SIO_CMD_WRITE, &awk->sio.arg, &awk->sio.arg.b.buf[awk->sio.arg.b.pos], awk->sio.arg.b.len - awk->sio.arg.b.pos ); - if (n <= 0) - { - if (ISNOERR(awk)) - SETERR_ARG (awk, HAWK_EWRITE, HAWK_T(""), 6); - return -1; - } - + if (n <= 0) return -1; awk->sio.arg.b.pos += n; } @@ -7176,7 +7118,7 @@ static hawk_mod_t* query_module (hawk_t* awk, const hawk_oocs_t segs[], int nseg pair = hawk_rbt_insert(awk->modtab, segs[0].ptr, segs[0].len, &md, HAWK_SIZEOF(md)); if (pair == HAWK_NULL) { - hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM); return HAWK_NULL; } @@ -7190,7 +7132,7 @@ static hawk_mod_t* query_module (hawk_t* awk, const hawk_oocs_t segs[], int nseg goto done; } #endif - hawk_seterrnum (awk, HAWK_ENOERR, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOERR); /* attempt to find an external module */ HAWK_MEMSET (&spec, 0, HAWK_SIZEOF(spec)); @@ -7233,7 +7175,7 @@ static hawk_mod_t* query_module (hawk_t* awk, const hawk_oocs_t segs[], int nseg load = awk->prm.modgetsym(awk, md.handle, &buf[0]); if (!load) { - hawk_seterrnum (awk, HAWK_ENOERR, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOERR); /* attempt hawk_mod_xxx_ */ buf[13 + buflen] = HAWK_T('_'); @@ -7261,7 +7203,7 @@ static hawk_mod_t* query_module (hawk_t* awk, const hawk_oocs_t segs[], int nseg pair = hawk_rbt_insert (awk->modtab, segs[0].ptr, segs[0].len, &md, HAWK_SIZEOF(md)); if (pair == HAWK_NULL) { - hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM); awk->prm.modclose (awk, md.handle); return HAWK_NULL; } @@ -7276,7 +7218,7 @@ static hawk_mod_t* query_module (hawk_t* awk, const hawk_oocs_t segs[], int nseg } done: - hawk_seterrnum (awk, HAWK_ENOERR, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOERR); n = mdp->mod.query(&mdp->mod, awk, segs[1].ptr, sym); if (n <= -1) { diff --git a/hawk/lib/rec.c b/hawk/lib/rec.c index ca4f8a3b..7efd764e 100644 --- a/hawk/lib/rec.c +++ b/hawk/lib/rec.c @@ -103,9 +103,7 @@ static int split_record (hawk_rtx_t* rtx) hawk_val_type_t fsvtype; hawk_ooch_t* fs_ptr, * fs_free; hawk_oow_t fs_len; - hawk_errnum_t errnum; int how; - /* inrec should be cleared before split_record is called */ HAWK_ASSERT (rtx->inrec.nflds == 0); diff --git a/hawk/lib/rio.c b/hawk/lib/rio.c index 16efe1cb..3594f81e 100644 --- a/hawk/lib/rio.c +++ b/hawk/lib/rio.c @@ -222,7 +222,6 @@ static HAWK_INLINE int resolve_rs (hawk_rtx_t* rtx, hawk_val_t* rs, hawk_oocs_t* static HAWK_INLINE int match_long_rs (hawk_rtx_t* rtx, hawk_ooecs_t* buf, hawk_rio_arg_t* p) { hawk_oocs_t match; - hawk_errnum_t errnum; int ret; HAWK_ASSERT (rtx->gbl.rs[0] != HAWK_NULL); diff --git a/hawk/lib/run.c b/hawk/lib/run.c index 48793a05..01cf1fae 100644 --- a/hawk/lib/run.c +++ b/hawk/lib/run.c @@ -749,7 +749,7 @@ hawk_rtx_t* hawk_rtx_open (hawk_t* awk, hawk_oow_t xtnsize, hawk_rio_cbs_t* rio) struct module_init_ctx_t mic; /* clear the awk error code */ - hawk_seterrnum (awk, HAWK_ENOERR, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOERR); /* check if the code has ever been parsed */ if (awk->tree.ngbls == 0 && @@ -758,7 +758,7 @@ hawk_rtx_t* hawk_rtx_open (hawk_t* awk, hawk_oow_t xtnsize, hawk_rio_cbs_t* rio) awk->tree.chain_size == 0 && hawk_htb_getsize(awk->tree.funs) == 0) { - hawk_seterrnum (awk, HAWK_EPERM, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EPERM); return HAWK_NULL; } diff --git a/hawk/lib/std.c b/hawk/lib/std.c index d8b0b50f..cb508999 100644 --- a/hawk/lib/std.c +++ b/hawk/lib/std.c @@ -294,7 +294,7 @@ static void* std_mod_open_checked (hawk_t* awk, const hawk_mod_spec_t* spec) { /* hawk_stdmodstartup() must have failed upon start-up. * return failure immediately */ - hawk_seterrnum (awk, HAWK_ENOIMPL, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOIMPL); return HAWK_NULL; } @@ -327,7 +327,7 @@ void* hawk_stdmodopen (hawk_t* awk, const hawk_mod_spec_t* spec) { /* the only failure of lt_dladvise_init() seems to be caused * by memory allocation failured */ - hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM); return HAWK_NULL; } @@ -457,7 +457,7 @@ void* hawk_stdmodopen (hawk_t* awk, const hawk_mod_spec_t* spec) return h; #else - hawk_seterrnum (awk, HAWK_ENOIMPL, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOIMPL); return HAWK_NULL; #endif } @@ -902,7 +902,7 @@ static hawk_sio_t* open_sio (hawk_t* hawk, const hawk_ooch_t* file, int flags) if (sio == HAWK_NULL) { const hawk_ooch_t* bem = hawk_backuperrmsg(hawk); - hawk_seterrbfmt (hawk, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", file, bem); + hawk_seterrfmt (hawk, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), file, bem); } return sio; } @@ -914,7 +914,7 @@ static hawk_sio_t* open_sio_rtx (hawk_rtx_t* rtx, const hawk_ooch_t* file, int f if (sio == HAWK_NULL) { const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(rtx); - hawk_rtx_seterrbfmt (rtx, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", file, bem); + hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), file, bem); } return sio; } @@ -933,7 +933,7 @@ static hawk_sio_t* open_sio_std (hawk_t* awk, hawk_sio_std_t std, int flags) if (sio == HAWK_NULL) { const hawk_ooch_t* bem = hawk_backuperrmsg(awk); - hawk_seterrbfmt (awk, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", &sio_std_names[std], bem); + hawk_seterrfmt (awk, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), &sio_std_names[std], bem); } return sio; } @@ -946,7 +946,7 @@ static hawk_sio_t* open_sio_std_rtx (hawk_rtx_t* rtx, hawk_sio_std_t std, int fl if (sio == HAWK_NULL) { const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(rtx); - hawk_rtx_seterrbfmt (rtx, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", &sio_std_names[std], bem); + hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), &sio_std_names[std], bem); } return sio; } @@ -1050,7 +1050,7 @@ static int open_parsestd (hawk_t* awk, hawk_sio_arg_t* arg, xtn_t* xtn, hawk_oow return 0; default: - hawk_seterrnum (awk, HAWK_EINTERN, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EINTERN); return -1; } } @@ -1167,7 +1167,7 @@ static hawk_ooi_t sf_in_open (hawk_t* awk, hawk_sio_arg_t* arg, xtn_t* xtn) const hawk_ooch_t* bem; fail: bem = hawk_backuperrmsg(awk); - hawk_seterrbfmt (awk, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", arg->name, bem); + hawk_seterrfmt (awk, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), arg->name, bem); return -1; } @@ -1237,9 +1237,9 @@ static hawk_ooi_t sf_in_read (hawk_t* awk, hawk_sio_arg_t* arg, hawk_ooch_t* dat const hawk_uch_t* path; path = xtn->s.in.x[xtn->s.in.xindex].u.fileu.path; if (path) - hawk_seterrbfmt (awk, HAWK_NULL, HAWK_EREAD, "unable to read %ls - %js", path, bem); + hawk_seterrfmt (awk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %ls - %js"), path, bem); else - hawk_seterrbfmt (awk, HAWK_NULL, HAWK_EREAD, "unable to read %js - %js", sio_std_names[HAWK_SIO_STDIN].ptr, bem); + hawk_seterrfmt (awk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %js - %js"), sio_std_names[HAWK_SIO_STDIN].ptr, bem); } break; @@ -1255,9 +1255,9 @@ static hawk_ooi_t sf_in_read (hawk_t* awk, hawk_sio_arg_t* arg, hawk_ooch_t* dat const hawk_bch_t* path; path = xtn->s.in.x[xtn->s.in.xindex].u.fileb.path; if (path) - hawk_seterrbfmt (awk, HAWK_NULL, HAWK_EREAD, "unable to read %hs - %js", path, bem); + hawk_seterrfmt (awk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %hs - %js"), path, bem); else - hawk_seterrbfmt (awk, HAWK_NULL, HAWK_EREAD, "unable to read %js - %js", sio_std_names[HAWK_SIO_STDIN].ptr, bem); + hawk_seterrfmt (awk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %js - %js"), sio_std_names[HAWK_SIO_STDIN].ptr, bem); } break; @@ -1283,7 +1283,7 @@ static hawk_ooi_t sf_in_read (hawk_t* awk, hawk_sio_arg_t* arg, hawk_ooch_t* dat wcslen = size; if ((m = hawk_conv_bchars_to_uchars_with_cmgr(xtn->s.in.u.bcs.ptr, &mbslen, data, &wcslen, hawk_getcmgr(awk), 0)) <= -1 && m != -2) { - hawk_seterrnum (awk, HAWK_EINVAL, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EINVAL); n = -1; } else @@ -1305,7 +1305,7 @@ static hawk_ooi_t sf_in_read (hawk_t* awk, hawk_sio_arg_t* arg, hawk_ooch_t* dat mbslen = size; if ((m = hawk_conv_uchars_to_bchars_with_cmgr(xtn->s.in.u.ucs.ptr, &wcslen, data, &mbslen, hawk_getcmgr(awk))) <= -1 && m != -2) { - hawk_seterrnum (awk, HAWK_EINVAL, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EINVAL); n = -1; } else @@ -1321,7 +1321,7 @@ static hawk_ooi_t sf_in_read (hawk_t* awk, hawk_sio_arg_t* arg, hawk_ooch_t* dat default: /* this should never happen */ - hawk_seterrnum (awk, HAWK_EINTERN, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EINTERN); n = -1; break; } @@ -1355,12 +1355,11 @@ static hawk_ooi_t sf_in_read (hawk_t* awk, hawk_sio_arg_t* arg, hawk_ooch_t* dat HAWK_ASSERT (arg->handle != HAWK_NULL); n = hawk_sio_getoochars(arg->handle, data, size); + if (n <= -1) { - hawk_oocs_t ea; - ea.ptr = (hawk_ooch_t*)arg->name; - ea.len = hawk_count_oocstr(ea.ptr); - hawk_seterrnum (awk, HAWK_EREAD, &ea); + const hawk_ooch_t* bem = hawk_backuperrmsg(awk); + hawk_seterrfmt (awk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to read %js - %js"), arg->name, bem); } return n; } @@ -1382,7 +1381,7 @@ static hawk_ooi_t sf_in (hawk_t* awk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg, h return sf_in_read(awk, arg, data, size, xtn); default: - hawk_seterrnum (awk, HAWK_EINTERN, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EINTERN); return -1; } } @@ -1509,11 +1508,11 @@ static hawk_ooi_t sf_out (hawk_t* awk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg, n = hawk_sio_putoochars(xtn->s.out.u.file.sio, data, size); if (n <= -1) { - hawk_oocs_t ea; - ea.ptr = (hawk_ooch_t*)xtn->s.out.x->u.file.path; - if (ea.ptr == HAWK_NULL) ea.ptr = sio_std_names[HAWK_SIO_STDOUT].ptr; - ea.len = hawk_count_oocstr(ea.ptr); - hawk_seterrnum (awk, HAWK_EWRITE, &ea); + const hawk_ooch_t* ioname; + const hawk_ooch_t* bem = hawk_backuperrmsg(awk); + ioname = xtn->s.out.x->u.file.path; + if (!ioname) ioname = sio_std_names[HAWK_SIO_STDOUT].ptr; + hawk_seterrfmt (awk, HAWK_NULL, HAWK_EREAD, HAWK_T("unable to write to %js - %js"), ioname, bem); } return n; } @@ -1523,7 +1522,7 @@ static hawk_ooi_t sf_out (hawk_t* awk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg, if (size > HAWK_TYPE_MAX(hawk_ooi_t)) size = HAWK_TYPE_MAX(hawk_ooi_t); if (hawk_ooecs_ncat(xtn->s.out.u.oocs.buf, data, size) == (hawk_oow_t)-1) { - hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM); return -1; } return size; @@ -1543,7 +1542,7 @@ static hawk_ooi_t sf_out (hawk_t* awk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg, orglen = hawk_becs_getlen(xtn->s.out.u.bcs.buf); if (hawk_becs_setlen(xtn->s.out.u.bcs.buf, orglen + mbslen) == (hawk_oow_t)-1) { - hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM); return -1; } @@ -1568,7 +1567,7 @@ static hawk_ooi_t sf_out (hawk_t* awk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg, orglen = hawk_becs_getlen(xtn->s.out.u.ucs.buf); if (hawk_uecs_setlen(xtn->s.out.u.ucs.buf, orglen + wcslen) == (hawk_oow_t)-1) { - hawk_seterrnum (awk, HAWK_ENOMEM, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOMEM); return -1; } @@ -1591,7 +1590,7 @@ static hawk_ooi_t sf_out (hawk_t* awk, hawk_sio_cmd_t cmd, hawk_sio_arg_t* arg, break; } - hawk_seterrnum (awk, HAWK_EINTERN, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EINTERN); return -1; } @@ -1610,7 +1609,7 @@ int hawk_parsestd (hawk_t* awk, hawk_parsestd_t in[], hawk_parsestd_t* out) { /* the input is a must. at least 1 file or 1 string * must be specified */ - hawk_seterrnum (awk, HAWK_EINVAL, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EINVAL); return -1; } @@ -1627,7 +1626,7 @@ int hawk_parsestd (hawk_t* awk, hawk_parsestd_t in[], hawk_parsestd_t* out) out->type != HAWK_PARSESTD_BCS && out->type != HAWK_PARSESTD_UCS) { - hawk_seterrnum (awk, HAWK_EINVAL, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EINVAL); return -1; } sio.out = sf_out; @@ -1944,7 +1943,7 @@ static hawk_ooi_t awk_rio_file (hawk_rtx_t* rtx, hawk_rio_cmd_t cmd, hawk_rio_ar if (handle == HAWK_NULL) { const hawk_ooch_t* bem = hawk_rtx_backuperrmsg(rtx); - hawk_rtx_seterrbfmt (rtx, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", riod->name, bem); + hawk_rtx_seterrfmt (rtx, HAWK_NULL, HAWK_EOPEN, HAWK_T("unable to open %js - %js"), riod->name, bem); return -1; } @@ -2093,7 +2092,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_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_seterrfmt (rtx, HAWK_NULL, HAWK_EIONMNL, HAWK_T("invalid I/O name beginning with '%js' of length %zu containing '\\0'"), as.ptr, as.len); hawk_rtx_freevaloocstr (rtx, v, as.ptr); return -1; } diff --git a/hawk/lib/syserr.h b/hawk/lib/syserr.h index cd0f3c15..fe59b9fc 100644 --- a/hawk/lib/syserr.h +++ b/hawk/lib/syserr.h @@ -148,6 +148,7 @@ case EBUSY: return _SYSERRNUM__(obj2, EBUSY); \ case EACCES: return __SYSERRNUM__(obj2, EACCES); \ case EPERM: return __SYSERRNUM__(obj2, EPERM); \ + case EISDIR: return __SYSERRNUM__(obj2, EISDIR); \ case ENOTDIR: return __SYSERRNUM__(obj2, ENOTDIR); \ case ENXIO: \ case ENODEV: \ @@ -176,6 +177,7 @@ case EBUSY: return __SYSERRNUM__(obj2, EBUSY); \ case EACCES: return __SYSERRNUM__(obj2, EACCES); \ case EPERM: return __SYSERRNUM__(obj2, EPERM); \ + case EISDIR: return __SYSERRNUM__(obj2, EISDIR); \ case ENOTDIR: return __SYSERRNUM__(obj2, ENOTDIR); \ case ENXIO: \ case ENODEV: \ @@ -203,6 +205,7 @@ case EBUSY: return __SYSERRNUM__(obj2, EBUSY); \ case EACCES: return __SYSERRNUM__(obj2, EACCES); \ case EPERM: return __SYSERRNUM__(obj2, EPERM); \ + case EISDIR: return __SYSERRNUM__(obj2, EISDIR); \ case ENOTDIR: return __SYSERRNUM__(obj2, ENOTDIR); \ case ENXIO: \ case ENODEV: \ @@ -230,6 +233,7 @@ case EBUSY: return __SYSERRNUM__(obj2, EBUSY); \ case EACCES: return __SYSERRNUM__(obj2, EACCES); \ case EPERM: return __SYSERRNUM__(obj2, EPERM); \ + case EISDIR: return __SYSERRNUM__(obj2, EISDIR); \ case ENOTDIR: return __SYSERRNUM__(obj2, ENOTDIR); \ case ENXIO: \ case ENODEV: \ diff --git a/hawk/lib/tree.c b/hawk/lib/tree.c index 09097fee..0214470c 100644 --- a/hawk/lib/tree.c +++ b/hawk/lib/tree.c @@ -762,7 +762,7 @@ static int print_expr (hawk_t* awk, hawk_nde_t* nde) default: { - hawk_seterrnum (awk, HAWK_EINTERN, HAWK_NULL); + hawk_seterrnum (awk, HAWK_NULL, HAWK_EINTERN); return -1; } }