enhanced code a little

This commit is contained in:
hyung-hwan 2009-03-19 08:25:27 +00:00
parent 9a4897ee91
commit 3eb225fd22
2 changed files with 65 additions and 17 deletions

View File

@ -40,7 +40,8 @@ enum qse_sed_errnum_t
QSE_SED_ESCEXP, /* ; is expected */ QSE_SED_ESCEXP, /* ; is expected */
QSE_SED_ELABTL, /* label too long */ QSE_SED_ELABTL, /* label too long */
QSE_SED_ELABEM, /* label name is empty */ QSE_SED_ELABEM, /* label name is empty */
QSE_SED_ELABDU /* duplicate label name */ QSE_SED_ELABDU, /* duplicate label name */
QSE_SED_ETSINV /* invalid translation set */
}; };
enum qse_sed_option_t enum qse_sed_option_t

View File

@ -132,7 +132,8 @@ const qse_char_t* qse_sed_geterrmsg (qse_sed_t* sed)
QSE_T("a semicolon expected"), QSE_T("a semicolon expected"),
QSE_T("label name too long"), QSE_T("label name too long"),
QSE_T("empty label name"), QSE_T("empty label name"),
QSE_T("duplicate label name") QSE_T("duplicate label name"),
QSE_T("invalid translation set")
}; };
return (sed->errnum > 0 && sed->errnum < QSE_COUNTOF(errmsg))? return (sed->errnum > 0 && sed->errnum < QSE_COUNTOF(errmsg))?
@ -499,31 +500,77 @@ oops:
static int get_trans_set (qse_sed_t* sed, qse_sed_cmd_t* cmd) static int get_trans_set (qse_sed_t* sed, qse_sed_cmd_t* cmd)
{ {
qse_str_t* t1 = QSE_NULL; qse_cint_t c, delim;
qse_str_t* t2 = QSE_NULL; qse_str_t* t = QSE_NULL;
t1 = qse_str_open (sed->mmgr, 0, 32); c = CURSC (sed);
if (t1 == QSE_NULL) if (c == QSE_CHAR_EOF || IS_LINTERM(c))
{
/* invalid translation set */
sed->errnum = QSE_SED_ETSINV;
goto oops;
}
delim = c;
t = qse_str_open (sed->mmgr, 0, 32);
if (t == QSE_NULL)
{ {
sed->errnum = QSE_SED_ENOMEM; sed->errnum = QSE_SED_ENOMEM;
goto oops; goto oops;
} }
t2 = qse_str_open (sed->mmgr, 0, 32); c = NXTSC (sed);
if (t2 == QSE_NULL) while (c != delim)
{ {
sed->errnum = QSE_SED_ENOMEM; qse_char_t b[2];
goto oops;
if (c == QSE_CHAR_EOF || IS_LINTERM(c))
{
/* invalid translation set */
sed->errnum = QSE_SED_ETSINV;
goto oops;
}
if (c == QSE_T('\\'))
{
c = NXTSC (sed);
if (c == QSE_CHAR_EOF || IS_LINTERM(c))
{
/* invalid translation set */
sed->errnum = QSE_SED_ETSINV;
goto oops;
}
}
b[0] = c;
if (qse_str_ncat (t, b, 2) == (qse_size_t)-1)
{
sed->errnum = QSE_SED_ENOMEM;
goto oops;
}
}
c = NXTSC (sed);
while (c != delim)
{
if (c == QSE_CHAR_EOF || IS_LINTERM(c))
{
/* invalid translation set */
sed->errnum = QSE_SED_ETSINV;
goto oops;
}
if (c == QSE_T('\n'))
{
}
} }
qse_str_close (t2); qse_str_close (t);
qse_str_close (t1);
return 0; return 0;
oops: oops:
if (t2 != QSE_NULL) qse_str_close (t2); if (t != QSE_NULL) qse_str_close (t);
if (t1 != QSE_NULL) qse_str_close (t1);
return -1; return -1;
} }
@ -660,11 +707,11 @@ printf ("command %c\n", cmd->type);
if (get_branch_target (sed, cmd) == -1) return -1; if (get_branch_target (sed, cmd) == -1) return -1;
if (cmd->u.branch.text != NULL) if (cmd->u.branch.text != NULL)
{ {
printf ("cmd->u.branch.text = [%s]\n", cmd->u.branch.text->ptr); qse_printf (QSE_T("cmd->u.branch.text = [%s]\n"), cmd->u.branch.text->ptr);
} }
else else
{ {
printf ("cmd->u.branch.target = [%p]\n", cmd->u.branch.target); qse_printf (QSE_T("cmd->u.branch.target = [%p]\n"), cmd->u.branch.target);
} }
break; break;