added more string copy functions

This commit is contained in:
hyung-hwan 2022-03-28 11:32:12 +00:00
parent 36394eaef8
commit 7922df9b57
5 changed files with 331 additions and 144 deletions

View File

@ -231,36 +231,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) return hawk_gem_geterrbmsg(hawk_getgem(hawk));
return (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg;
#else
const hawk_ooch_t* msg;
hawk_oow_t wcslen, mbslen;
msg = (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg;
mbslen = HAWK_COUNTOF(hawk->xerrmsg);
hawk_conv_ucstr_to_bcstr_with_cmgr (msg, &wcslen, hawk->xerrmsg, &mbslen, hawk_getcmgr(hawk));
return hawk->xerrmsg;
#endif
} }
const hawk_uch_t* hawk_geterrumsg (hawk_t* hawk) const hawk_uch_t* hawk_geterrumsg (hawk_t* hawk)
{ {
#if defined(HAWK_OOCH_IS_BCH) return hawk_gem_geterrumsg(hawk_getgem(hawk));
const hawk_ooch_t* msg;
hawk_oow_t wcslen, mbslen;
msg = (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg;
wcslen = HAWK_COUNTOF(hawk->xerrmsg);
hawk_conv_bcstr_to_ucstr_with_cmgr (msg, &mbslen, hawk->xerrmsg, &wcslen, hawk_getcmgr(hawk), 1);
return hawk->xerrmsg;
#else
return (hawk->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk)(hawk->_gem.errnum): hawk->_gem.errmsg;
#endif
} }
void hawk_geterrinf (hawk_t* hawk, hawk_errinf_t* errinf) void hawk_geterrinf (hawk_t* hawk, hawk_errinf_t* errinf)
@ -319,36 +295,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) return hawk_gem_geterrbmsg(hawk_rtx_getgem(rtx));
return (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(rtx->_gem.errnum): rtx->_gem.errmsg;
#else
const hawk_ooch_t* msg;
hawk_oow_t wcslen, mbslen;
msg = (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(rtx->_gem.errnum): rtx->_gem.errmsg;
mbslen = HAWK_COUNTOF(rtx->xerrmsg);
hawk_conv_ucstr_to_bcstr_with_cmgr (msg, &wcslen, rtx->xerrmsg, &mbslen, hawk_rtx_getcmgr(rtx));
return rtx->xerrmsg;
#endif
} }
const hawk_uch_t* hawk_rtx_geterrumsg (hawk_rtx_t* rtx) const hawk_uch_t* hawk_rtx_geterrumsg (hawk_rtx_t* rtx)
{ {
#if defined(HAWK_OOCH_IS_BCH) return hawk_gem_geterrumsg(hawk_rtx_getgem(rtx));
const hawk_ooch_t* msg;
hawk_oow_t wcslen, mbslen;
msg = (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(rtx->_gem.errnum): rtx->_gem.errmsg;
wcslen = HAWK_COUNTOF(rtx->xerrmsg);
hawk_conv_bcstr_to_ucstr_with_cmgr (msg, &mbslen, rtx->xerrmsg, &wcslen, hawk_rtx_getcmgr(rtx), 1);
return rtx->xerrmsg;
#else
return (rtx->_gem.errmsg[0] == '\0')? hawk_geterrstr(hawk_rtx_gethawk(rtx))(rtx->_gem.errnum): rtx->_gem.errmsg;
#endif
} }
void hawk_rtx_geterrinf (hawk_rtx_t* rtx, hawk_errinf_t* errinf) void hawk_rtx_geterrinf (hawk_rtx_t* rtx, hawk_errinf_t* errinf)
@ -597,3 +549,18 @@ void hawk_gem_seterruvfmt (hawk_gem_t* gem, const hawk_loc_t* errloc, hawk_errnu
gem->errnum = errnum; gem->errnum = errnum;
gem->errloc = (errloc? *errloc: _nullloc); gem->errloc = (errloc? *errloc: _nullloc);
} }
void hawk_gem_seterror (hawk_gem_t* gem, hawk_errnum_t errnum, const hawk_oocs_t* errarg, const hawk_loc_t* errloc)
{
const hawk_ooch_t* errfmt;
gem->errnum = errnum;
errfmt = gem->errstr(gem->errnum);
HAWK_ASSERT (errfmt != HAWK_NULL);
hawk_copy_oocses_to_oochars (gem->errmsg, HAWK_COUNTOF(gem->errmsg), errfmt, errarg);
if (errloc != HAWK_NULL) gem->errloc = *errloc;
else HAWK_MEMSET (&gem->errloc, 0, HAWK_SIZEOF(gem->errloc));
}

View File

@ -451,6 +451,14 @@ HAWK_EXPORT void hawk_gem_geterror (
hawk_loc_t* errloc hawk_loc_t* errloc
); );
HAWK_EXPORT const hawk_bch_t* hawk_gem_geterrbmsg (
hawk_gem_t* gem
);
HAWK_EXPORT const hawk_uch_t* hawk_gem_geterrumsg (
hawk_gem_t* gem
);
HAWK_EXPORT void hawk_gem_seterrinf ( HAWK_EXPORT void hawk_gem_seterrinf (
hawk_gem_t* gem, hawk_gem_t* gem,
const hawk_errinf_t* errinf const hawk_errinf_t* errinf

View File

@ -338,10 +338,12 @@ struct hawk_t
/* housekeeping */ /* housekeeping */
//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 0
#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];
#else #else
hawk_bch_t xerrmsg[HAWK_ERRMSG_CAPA * 2]; hawk_bch_t xerrmsg[HAWK_ERRMSG_CAPA * 2];
#endif
#endif #endif
struct struct
@ -546,10 +548,12 @@ struct hawk_rtx_t
//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 0
#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];
#else #else
hawk_bch_t xerrmsg[HAWK_ERRMSG_CAPA * 2]; hawk_bch_t xerrmsg[HAWK_ERRMSG_CAPA * 2];
#endif
#endif #endif
hawk_rtx_ecb_t* ecb; hawk_rtx_ecb_t* ecb;

View File

@ -42,14 +42,11 @@ static int emit_output (hawk_sed_t* sed, int skipline);
#define ADJERR_LOC(sed,l) do { (sed)->_gem.errloc = *(l); } while (0) #define ADJERR_LOC(sed,l) do { (sed)->_gem.errloc = *(l); } while (0)
#define SETERR0(sed,num,loc) \
do { hawk_sed_seterror (sed, num, HAWK_NULL, loc); } while (0)
#define SETERR1(sed,num,argp,argl,loc) \ #define SETERR1(sed,num,argp,argl,loc) \
do { \ do { \
hawk_oocs_t __ea__; \ hawk_oocs_t __ea__; \
__ea__.ptr = argp; __ea__.len = argl; \ __ea__.ptr = argp; __ea__.len = argl; \
hawk_sed_seterror (sed, num, &__ea__, loc); \ hawk_sed_seterror (sed, loc, num, &__ea__); \
} while (0) } while (0)
static void free_all_cut_selector_blocks (hawk_sed_t* sed, hawk_sed_cmd_t* cmd); static void free_all_cut_selector_blocks (hawk_sed_t* sed, hawk_sed_cmd_t* cmd);
@ -654,19 +651,11 @@ static int pickup_rex (
{ {
if (cmd) if (cmd)
{ {
SETERR1 ( SETERR1 (sed, HAWK_SED_ECMDIC, &cmd->type, 1, &sed->src.loc);
sed, HAWK_SED_ECMDIC,
&cmd->type, 1,
&sed->src.loc
);
} }
else else
{ {
SETERR1 ( SETERR1 (sed, HAWK_SED_EREXIC, HAWK_OOECS_PTR(buf), HAWK_OOECS_LEN(buf), &sed->src.loc);
sed, HAWK_SED_EREXIC,
HAWK_OOECS_PTR(buf), HAWK_OOECS_LEN(buf),
&sed->src.loc
);
} }
return -1; return -1;
} }
@ -682,20 +671,11 @@ static int pickup_rex (
{ {
if (cmd) if (cmd)
{ {
SETERR1 ( SETERR1 (sed, HAWK_SED_ECMDIC, &cmd->type, 1, &sed->src.loc);
sed, HAWK_SED_ECMDIC,
&cmd->type, 1,
&sed->src.loc
);
} }
else else
{ {
SETERR1 ( SETERR1 (sed, HAWK_SED_EREXIC, HAWK_OOECS_PTR(buf), HAWK_OOECS_LEN(buf), &sed->src.loc);
sed, HAWK_SED_EREXIC,
HAWK_OOECS_PTR(buf),
HAWK_OOECS_LEN(buf),
&sed->src.loc
);
} }
return -1; return -1;
} }
@ -847,8 +827,7 @@ static hawk_sed_adr_t* get_address (hawk_sed_t* sed, hawk_sed_adr_t* a, int exte
NXTSC (sed, c, HAWK_NULL); NXTSC (sed, c, HAWK_NULL);
if (c == HAWK_OOCI_EOF || IS_LINTERM(c)) if (c == HAWK_OOCI_EOF || IS_LINTERM(c))
{ {
SETERR1 (sed, HAWK_SED_EREXIC, SETERR1 (sed, HAWK_SED_EREXIC, HAWK_T(""), 0, &sed->src.loc);
HAWK_T(""), 0, &sed->src.loc);
return HAWK_NULL; return HAWK_NULL;
} }
@ -866,7 +845,7 @@ static hawk_sed_adr_t* get_address (hawk_sed_t* sed, hawk_sed_adr_t* a, int exte
NXTSC (sed, c, HAWK_NULL); NXTSC (sed, c, HAWK_NULL);
if (!(c >= HAWK_T('0') && c <= HAWK_T('9'))) if (!(c >= HAWK_T('0') && c <= HAWK_T('9')))
{ {
SETERR0 (sed, HAWK_SED_EA2MOI, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EA2MOI);
return HAWK_NULL; return HAWK_NULL;
} }
@ -990,7 +969,7 @@ static int get_label (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
/* label name is empty */ /* label name is empty */
if (sed->opt.trait & HAWK_SED_STRICT) if (sed->opt.trait & HAWK_SED_STRICT)
{ {
SETERR0 (sed, HAWK_SED_ELABEM, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ELABEM);
return -1; return -1;
} }
@ -1012,12 +991,7 @@ static int get_label (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
HAWK_OOECS_PTR(&sed->tmp.lab), HAWK_OOECS_PTR(&sed->tmp.lab),
HAWK_OOECS_LEN(&sed->tmp.lab)) != HAWK_NULL) HAWK_OOECS_LEN(&sed->tmp.lab)) != HAWK_NULL)
{ {
SETERR1 ( SETERR1 (sed, HAWK_SED_ELABDU, HAWK_OOECS_PTR(&sed->tmp.lab), HAWK_OOECS_LEN(&sed->tmp.lab), &sed->src.loc);
sed, HAWK_SED_ELABDU,
HAWK_OOECS_PTR(&sed->tmp.lab),
HAWK_OOECS_LEN(&sed->tmp.lab),
&sed->src.loc
);
return -1; return -1;
} }
@ -1052,7 +1026,7 @@ static int terminate_command (hawk_sed_t* sed)
while (IS_SPACE(c)) NXTSC (sed, c, -1); while (IS_SPACE(c)) NXTSC (sed, c, -1);
if (!IS_CMDTERM(c)) if (!IS_CMDTERM(c))
{ {
SETERR0 (sed, HAWK_SED_ESCEXP, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ESCEXP);
return -1; return -1;
} }
@ -1133,7 +1107,7 @@ static int get_file (hawk_sed_t* sed, hawk_oocs_t* xstr)
if (IS_CMDTERM(c)) if (IS_CMDTERM(c))
{ {
SETERR0 (sed, HAWK_SED_EFILEM, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EFILEM);
goto oops; goto oops;
} }
@ -1145,7 +1119,7 @@ static int get_file (hawk_sed_t* sed, hawk_oocs_t* xstr)
if (c == HAWK_T('\0')) if (c == HAWK_T('\0'))
{ {
/* the file name should not contain '\0' */ /* the file name should not contain '\0' */
SETERR0 (sed, HAWK_SED_EFILIL, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EFILIL);
goto oops; goto oops;
} }
@ -1157,7 +1131,7 @@ static int get_file (hawk_sed_t* sed, hawk_oocs_t* xstr)
NXTSC_GOTO (sed, c, oops); NXTSC_GOTO (sed, c, oops);
if (c == HAWK_T('\0') || c == HAWK_OOCI_EOF || IS_LINTERM(c)) if (c == HAWK_T('\0') || c == HAWK_OOCI_EOF || IS_LINTERM(c))
{ {
SETERR0 (sed, HAWK_SED_EFILIL, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EFILIL);
goto oops; goto oops;
} }
@ -1194,8 +1168,7 @@ oops:
do { \ do { \
if (c == HAWK_OOCI_EOF || IS_LINTERM(c)) \ if (c == HAWK_OOCI_EOF || IS_LINTERM(c)) \
{ \ { \
SETERR1 (sed, HAWK_SED_ECMDIC, \ SETERR1 (sed, HAWK_SED_ECMDIC, &cmd->type, 1, &sed->src.loc); \
&cmd->type, 1, &sed->src.loc); \
action; \ action; \
} \ } \
} while (0) } while (0)
@ -1204,8 +1177,7 @@ do { \
do { \ do { \
if (c == HAWK_OOCI_EOF) \ if (c == HAWK_OOCI_EOF) \
{ \ { \
SETERR1 (sed, HAWK_SED_ECMDIC, \ SETERR1 (sed, HAWK_SED_ECMDIC, &cmd->type, 1, &sed->src.loc); \
&cmd->type, 1, &sed->src.loc); \
action; \ action; \
} \ } \
} while (0) } while (0)
@ -1226,7 +1198,7 @@ static int get_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (delim == HAWK_T('\\')) if (delim == HAWK_T('\\'))
{ {
/* backspace is an illegal delimiter */ /* backspace is an illegal delimiter */
SETERR0 (sed, HAWK_SED_EBSDEL, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EBSDEL);
goto oops; goto oops;
} }
@ -1271,7 +1243,8 @@ static int get_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (cmd->u.subst.occ != 0) if (cmd->u.subst.occ != 0)
{ {
SETERR0 (sed, HAWK_SED_EOCSDU, &sed->src.loc); /* multiple occurrence specifiers */
hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EOCSDU);
goto oops; goto oops;
} }
@ -1282,7 +1255,8 @@ static int get_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
occ = occ * 10 + (c - HAWK_T('0')); occ = occ * 10 + (c - HAWK_T('0'));
if (occ > HAWK_TYPE_MAX(unsigned short)) if (occ > HAWK_TYPE_MAX(unsigned short))
{ {
SETERR0 (sed, HAWK_SED_EOCSTL, &sed->src.loc); /* occurrence specifier too large */
hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EOCSTL);
goto oops; goto oops;
} }
NXTSC_GOTO (sed, c, oops); NXTSC_GOTO (sed, c, oops);
@ -1291,7 +1265,8 @@ static int get_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (occ == 0) if (occ == 0)
{ {
SETERR0 (sed, HAWK_SED_EOCSZE, &sed->src.loc); /* zero not allowed as occurrence specifier */
hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EOCSZE);
goto oops; goto oops;
} }
@ -1345,7 +1320,7 @@ static int get_transet (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (delim == HAWK_T('\\')) if (delim == HAWK_T('\\'))
{ {
/* backspace is an illegal delimiter */ /* backspace is an illegal delimiter */
SETERR0 (sed, HAWK_SED_EBSDEL, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EBSDEL);
goto oops; goto oops;
} }
@ -1387,7 +1362,7 @@ static int get_transet (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (pos >= HAWK_OOECS_LEN(t)) if (pos >= HAWK_OOECS_LEN(t))
{ {
/* source and target not the same length */ /* source and target not the same length */
SETERR0 (sed, HAWK_SED_ETSNSL, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ETSNSL);
goto oops; goto oops;
} }
@ -1398,7 +1373,7 @@ static int get_transet (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (pos < HAWK_OOECS_LEN(t)) if (pos < HAWK_OOECS_LEN(t))
{ {
/* source and target not the same length */ /* source and target not the same length */
SETERR0 (sed, HAWK_SED_ETSNSL, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ETSNSL);
goto oops; goto oops;
} }
@ -1469,7 +1444,7 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (delim == HAWK_T('\\')) if (delim == HAWK_T('\\'))
{ {
/* backspace is an illegal delimiter */ /* backspace is an illegal delimiter */
SETERR0 (sed, HAWK_SED_EBSDEL, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EBSDEL);
goto oops; goto oops;
} }
@ -1490,7 +1465,7 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops); while (IS_SPACE(c)) NXTSC_GOTO (sed, c, oops);
if (c == HAWK_OOCI_EOF) if (c == HAWK_OOCI_EOF)
{ {
SETERR0 (sed, HAWK_SED_ECSLNV, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ECSLNV);
goto oops; goto oops;
} }
@ -1501,7 +1476,7 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
NXTSC_GOTO (sed, c, oops); NXTSC_GOTO (sed, c, oops);
if (c == HAWK_OOCI_EOF) if (c == HAWK_OOCI_EOF)
{ {
SETERR0 (sed, HAWK_SED_ECSLNV, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ECSLNV);
goto oops; goto oops;
} }
cmd->u.cut.delim[delim_idx] = c; cmd->u.cut.delim[delim_idx] = c;
@ -1557,7 +1532,8 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (!(mask & (MASK_START | MASK_END))) if (!(mask & (MASK_START | MASK_END)))
{ {
SETERR0 (sed, HAWK_SED_ECSLNV, &sed->src.loc); /* invalid cut selector */
hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ECSLNV);
goto oops; goto oops;
} }
@ -1581,7 +1557,7 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (c == HAWK_OOCI_EOF) if (c == HAWK_OOCI_EOF)
{ {
SETERR0 (sed, HAWK_SED_ECSLNV, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ECSLNV);
goto oops; goto oops;
} }
@ -1589,7 +1565,7 @@ static int get_cut (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (c != HAWK_T(',')) if (c != HAWK_T(','))
{ {
SETERR0 (sed, HAWK_SED_ECSLNV, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ECSLNV);
goto oops; goto oops;
} }
NXTSC_GOTO (sed, c, oops); /* skip a comma */ NXTSC_GOTO (sed, c, oops); /* skip a comma */
@ -1646,17 +1622,14 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
case HAWK_OOCI_EOF: case HAWK_OOCI_EOF:
case HAWK_T('\n'): case HAWK_T('\n'):
SETERR0 (sed, HAWK_SED_ECMDMS, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_ECMDMS);
return -1; return -1;
case HAWK_T(':'): case HAWK_T(':'):
if (cmd->a1.type != HAWK_SED_ADR_NONE) if (cmd->a1.type != HAWK_SED_ADR_NONE)
{ {
/* label cannot have an address */ /* label cannot have an address */
SETERR1 ( SETERR1 (sed, HAWK_SED_EA1PHB, &cmd->type, 1, &sed->src.loc);
sed, HAWK_SED_EA1PHB,
&cmd->type, 1, &sed->src.loc
);
return -1; return -1;
} }
@ -1680,7 +1653,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (sed->tmp.grp.level >= HAWK_COUNTOF(sed->tmp.grp.cmd)) if (sed->tmp.grp.level >= HAWK_COUNTOF(sed->tmp.grp.cmd))
{ {
/* group nesting too deep */ /* group nesting too deep */
SETERR0 (sed, HAWK_SED_EGRNTD, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EGRNTD);
return -1; return -1;
} }
@ -1695,10 +1668,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (cmd->a1.type != HAWK_SED_ADR_NONE) if (cmd->a1.type != HAWK_SED_ADR_NONE)
{ {
hawk_ooch_t tmpc = c; hawk_ooch_t tmpc = c;
SETERR1 ( SETERR1 (sed, HAWK_SED_EA1PHB, &tmpc, 1, &sed->src.loc);
sed, HAWK_SED_EA1PHB,
&tmpc, 1, &sed->src.loc
);
return -1; return -1;
} }
@ -1707,7 +1677,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (sed->tmp.grp.level <= 0) if (sed->tmp.grp.level <= 0)
{ {
/* group not balanced */ /* group not balanced */
SETERR0 (sed, HAWK_SED_EGRNBA, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EGRNBA);
return -1; return -1;
} }
@ -1724,10 +1694,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
if (sed->opt.trait & HAWK_SED_STRICT && if (sed->opt.trait & HAWK_SED_STRICT &&
cmd->a2.type != HAWK_SED_ADR_NONE) cmd->a2.type != HAWK_SED_ADR_NONE)
{ {
SETERR1 ( SETERR1 (sed, HAWK_SED_EA2PHB, &cmd->type, 1, &sed->src.loc);
sed, HAWK_SED_EA2PHB,
&cmd->type, 1, &sed->src.loc
);
return -1; return -1;
} }
@ -1741,10 +1708,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
cmd->a2.type != HAWK_SED_ADR_NONE) cmd->a2.type != HAWK_SED_ADR_NONE)
{ {
hawk_ooch_t tmpc = c; hawk_ooch_t tmpc = c;
SETERR1 ( SETERR1 (sed, HAWK_SED_EA2PHB, &tmpc, 1, &sed->src.loc);
sed, HAWK_SED_EA2PHB,
&tmpc, 1, &sed->src.loc
);
return -1; return -1;
} }
case HAWK_T('c'): case HAWK_T('c'):
@ -1764,7 +1728,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
goto sameline_ok; goto sameline_ok;
} }
SETERR0 (sed, HAWK_SED_EBSEXP, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EBSEXP);
return -1; return -1;
} }
@ -1780,7 +1744,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
goto sameline_ok; goto sameline_ok;
} }
SETERR0 (sed, HAWK_SED_EGBABS, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EGBABS);
return -1; return -1;
} }
@ -1798,10 +1762,7 @@ static int get_command (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
cmd->a2.type != HAWK_SED_ADR_NONE) cmd->a2.type != HAWK_SED_ADR_NONE)
{ {
hawk_ooch_t tmpc = c; hawk_ooch_t tmpc = c;
SETERR1 ( SETERR1 (sed, HAWK_SED_EA2PHB, &tmpc, 1, &sed->src.loc);
sed, HAWK_SED_EA2PHB,
&tmpc, 1, &sed->src.loc
);
return -1; return -1;
} }
@ -1931,7 +1892,7 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf)
if (get_address (sed, &cmd->a1, 0) == HAWK_NULL) if (get_address (sed, &cmd->a1, 0) == HAWK_NULL)
{ {
cmd = HAWK_NULL; cmd = HAWK_NULL;
SETERR0 (sed, HAWK_SED_EA1MOI, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EA1MOI);
goto oops; goto oops;
} }
@ -1951,7 +1912,7 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf)
if (get_address (sed, &cmd->a2, (sed->opt.trait & HAWK_SED_EXTENDEDADR)) == HAWK_NULL) if (get_address (sed, &cmd->a2, (sed->opt.trait & HAWK_SED_EXTENDEDADR)) == HAWK_NULL)
{ {
HAWK_ASSERT (cmd->a2.type == HAWK_SED_ADR_NONE); HAWK_ASSERT (cmd->a2.type == HAWK_SED_ADR_NONE);
SETERR0 (sed, HAWK_SED_EA2MOI, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EA2MOI);
goto oops; goto oops;
} }
@ -1959,7 +1920,7 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf)
{ {
if (cmd->a2.type == HAWK_SED_ADR_NONE) if (cmd->a2.type == HAWK_SED_ADR_NONE)
{ {
SETERR0 (sed, HAWK_SED_EA2MOI, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EA2MOI);
goto oops; goto oops;
} }
if (cmd->a2.type == HAWK_SED_ADR_RELLINE || if (cmd->a2.type == HAWK_SED_ADR_RELLINE ||
@ -1978,7 +1939,7 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf)
if (cmd->a1.type != HAWK_SED_ADR_LINE || if (cmd->a1.type != HAWK_SED_ADR_LINE ||
cmd->a2.type != HAWK_SED_ADR_LINE) cmd->a2.type != HAWK_SED_ADR_LINE)
{ {
SETERR0 (sed, HAWK_SED_EA2MOI, &sed->src.loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EA2MOI);
goto oops; goto oops;
} }
@ -2018,7 +1979,7 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf)
} }
else else
{ {
SETERR0 (sed, HAWK_SED_EA1MOI, &a1_loc); hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EA1MOI);
goto oops; goto oops;
} }
} }
@ -2058,7 +2019,8 @@ int hawk_sed_comp (hawk_sed_t* sed, hawk_sed_io_impl_t inf)
if (sed->tmp.grp.level != 0) if (sed->tmp.grp.level != 0)
{ {
SETERR0 (sed, HAWK_SED_EGRNBA, &sed->src.loc); /* group brackets not balanced - since it's not 0, probably no balancing closing brakcets */
hawk_sed_seterrnum (sed, &sed->src.loc, HAWK_SED_EGRNBA);
goto oops; goto oops;
} }
@ -2655,7 +2617,8 @@ static int do_subst (hawk_sed_t* sed, hawk_sed_cmd_t* cmd)
rex = sed->e.last_rex; rex = sed->e.last_rex;
if (rex == HAWK_NULL) if (rex == HAWK_NULL)
{ {
SETERR0 (sed, HAWK_SED_ENPREX, &cmd->loc); /* no previous regular expression */
hawk_sed_seterrnum (sed, &cmd->loc, HAWK_SED_ENPREX);
return -1; return -1;
} }
} }
@ -3610,10 +3573,7 @@ static int init_command_block_for_exec (hawk_sed_t* sed, hawk_sed_cmd_blk_t* b)
&sed->tmp.labs, lab->ptr, lab->len); &sed->tmp.labs, lab->ptr, lab->len);
if (pair == HAWK_NULL) if (pair == HAWK_NULL)
{ {
SETERR1 ( SETERR1 (sed, HAWK_SED_ELABNF, lab->ptr, lab->len, &c->loc);
sed, HAWK_SED_ELABNF,
lab->ptr, lab->len, &c->loc
);
return -1; return -1;
} }

View File

@ -537,6 +537,254 @@ hawk_oow_t hawk_copy_bcstr_unlimited (hawk_bch_t* dst, const hawk_bch_t* src)
return dst - org - 1; return dst - org - 1;
} }
hawk_oow_t hawk_copy_ucstrs_to_uchars (hawk_uch_t* buf, hawk_oow_t bsz, const hawk_uch_t* fmt, const hawk_uch_t* str[])
{
hawk_uch_t* b = buf;
hawk_uch_t* end = buf + bsz - 1;
const hawk_uch_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != HAWK_UT('\0'))
{
if (*f == HAWK_UT('\\'))
{
/* get the escaped character and treat it normally.
* if the escaper is the last character, treat it
* normally also. */
if (f[1] != HAWK_UT('\0')) f++;
}
else if (*f == HAWK_UT('$'))
{
if (f[1] == HAWK_UT('{') &&
(f[2] >= HAWK_UT('0') && f[2] <= HAWK_UT('9')))
{
const hawk_uch_t* tmp;
hawk_oow_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - HAWK_UT('0'));
while (*f >= HAWK_UT('0') && *f <= HAWK_UT('9'));
if (*f != HAWK_UT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx];
while (*tmp != HAWK_UT('\0'))
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == HAWK_UT('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = HAWK_UT('\0');
return b - buf;
}
hawk_oow_t hawk_copy_bcstrs_to_bchars (hawk_bch_t* buf, hawk_oow_t bsz, const hawk_bch_t* fmt, const hawk_bch_t* str[])
{
hawk_bch_t* b = buf;
hawk_bch_t* end = buf + bsz - 1;
const hawk_bch_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != HAWK_BT('\0'))
{
if (*f == HAWK_BT('\\'))
{
/* get the escaped character and treat it normally.
* if the escaper is the last character, treat it
* normally also. */
if (f[1] != HAWK_BT('\0')) f++;
}
else if (*f == HAWK_BT('$'))
{
if (f[1] == HAWK_BT('{') &&
(f[2] >= HAWK_BT('0') && f[2] <= HAWK_BT('9')))
{
const hawk_bch_t* tmp;
hawk_oow_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - HAWK_BT('0'));
while (*f >= HAWK_BT('0') && *f <= HAWK_BT('9'));
if (*f != HAWK_BT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx];
while (*tmp != HAWK_BT('\0'))
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == HAWK_BT('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = HAWK_BT('\0');
return b - buf;
}
hawk_oow_t hawk_copy_ucses_to_uchars (hawk_uch_t* buf, hawk_oow_t bsz, const hawk_uch_t* fmt, const hawk_ucs_t str[])
{
hawk_uch_t* b = buf;
hawk_uch_t* end = buf + bsz - 1;
const hawk_uch_t* f = fmt;
if (bsz <= 0) return 0;
while (*f != HAWK_UT('\0'))
{
if (*f == HAWK_UT('\\'))
{
/* get the escaped character and treat it normally.
* if the escaper is the last character, treat it
* normally also. */
if (f[1] != HAWK_UT('\0')) f++;
}
else if (*f == HAWK_UT('$'))
{
if (f[1] == HAWK_UT('{') &&
(f[2] >= HAWK_UT('0') && f[2] <= HAWK_UT('9')))
{
const hawk_uch_t* tmp, * tmpend;
hawk_oow_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - HAWK_UT('0'));
while (*f >= HAWK_UT('0') && *f <= HAWK_UT('9'));
if (*f != HAWK_UT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend)
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == HAWK_UT('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = HAWK_UT('\0');
return b - buf;
}
hawk_oow_t hawk_copy_bcses_to_bchars (hawk_bch* buf, hawk_oow_t bsz, const hawk_bch* fmt, const hawk_bcs_t str[])
{
hawk_bch* b = buf;
hawk_bch* end = buf + bsz - 1;
const hawk_bch* f = fmt;
if (bsz <= 0) return 0;
while (*f != HAWK_BT('\0'))
{
if (*f == HAWK_BT('\\'))
{
/* get the escaped character and treat it normally.
* if the escaper is the last character, treat it
* normally also. */
if (f[1] != HAWK_BT('\0')) f++;
}
else if (*f == HAWK_BT('$'))
{
if (f[1] == HAWK_BT('{') &&
(f[2] >= HAWK_BT('0') && f[2] <= HAWK_BT('9')))
{
const hawk_bch* tmp, * tmpend;
hawk_oow_t idx = 0;
tmp = f;
f += 2;
do idx = idx * 10 + (*f++ - HAWK_BT('0'));
while (*f >= HAWK_BT('0') && *f <= HAWK_BT('9'));
if (*f != HAWK_BT('}'))
{
f = tmp;
goto normal;
}
f++;
tmp = str[idx].ptr;
tmpend = tmp + str[idx].len;
while (tmp < tmpend)
{
if (b >= end) goto fini;
*b++ = *tmp++;
}
continue;
}
else if (f[1] == HAWK_BT('$')) f++;
}
normal:
if (b >= end) break;
*b++ = *f++;
}
fini:
*b = HAWK_BT('\0');
return b - buf;
}
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
hawk_oow_t hawk_count_ucstr (const hawk_uch_t* str) hawk_oow_t hawk_count_ucstr (const hawk_uch_t* str)