touched up error handling in sed

This commit is contained in:
hyung-hwan 2009-05-23 08:11:03 +00:00
parent 4005bd68e8
commit f7d8234c21
4 changed files with 31 additions and 18 deletions

View File

@ -62,10 +62,10 @@ enum qse_sed_errnum_t
{ {
QSE_SED_ENOERR, /**< no error occurred */ QSE_SED_ENOERR, /**< no error occurred */
QSE_SED_ENOMEM, /**< insufficient memory is available */ QSE_SED_ENOMEM, /**< insufficient memory is available */
QSE_SED_ETMTXT, /**< too much text */
QSE_SED_ECMDNR, /**< a command is not recognized */ QSE_SED_ECMDNR, /**< a command is not recognized */
QSE_SED_ECMDMS, /**< a command is missing */ QSE_SED_ECMDMS, /**< a command is missing */
QSE_SED_ECMDIC, /**< a command is incomplete */ QSE_SED_ECMDIC, /**< a command is incomplete */
QSE_SED_EREXIC, /**< regular expression incomplete */
QSE_SED_EREXBL, /**< regular expression build error */ QSE_SED_EREXBL, /**< regular expression build error */
QSE_SED_EREXMA, /**< regular expression match error */ QSE_SED_EREXMA, /**< regular expression match error */
QSE_SED_EA1PHB, /**< address 1 prohibited */ QSE_SED_EA1PHB, /**< address 1 prohibited */

View File

@ -24,13 +24,13 @@ static const qse_char_t* geterrstr (int errnum)
{ {
QSE_T("no error"), QSE_T("no error"),
QSE_T("out of memory"), QSE_T("out of memory"),
QSE_T("too much text"), QSE_T("command '${0}' not recognized"),
QSE_T("command ${0} not recognized"),
QSE_T("command code missing"), QSE_T("command code missing"),
QSE_T("command ${0} not terminated properly"), QSE_T("command '${0}' not terminated properly"),
QSE_T("regular expression build error"), QSE_T("regular expression '${0}' incomplete"),
QSE_T("regular expression match error"), QSE_T("failed to compile regular expression '${0}'"),
QSE_T("address 1 prohibited"), QSE_T("failed to match regular expression"),
QSE_T("address 1 prohibited for '${0}'"),
QSE_T("address 2 prohibited"), QSE_T("address 2 prohibited"),
QSE_T("invalid step address"), QSE_T("invalid step address"),
QSE_T("a new line expected"), QSE_T("a new line expected"),
@ -39,8 +39,8 @@ static const qse_char_t* geterrstr (int errnum)
QSE_T("garbage after a backslash"), QSE_T("garbage after a backslash"),
QSE_T("a semicolon expected"), QSE_T("a semicolon expected"),
QSE_T("empty label name"), QSE_T("empty label name"),
QSE_T("duplicate label name ${0}"), QSE_T("duplicate label name '${0}'"),
QSE_T("label ${0} not found"), QSE_T("label '${0}' not found"),
QSE_T("empty file name"), QSE_T("empty file name"),
QSE_T("illegal file name"), QSE_T("illegal file name"),
QSE_T("strings in translation set not the same length"), QSE_T("strings in translation set not the same length"),

View File

@ -262,7 +262,10 @@ static void* compile_rex (qse_sed_t* sed, qse_char_t rxend)
c = NXTSC (sed); c = NXTSC (sed);
if (c == QSE_CHAR_EOF || c == QSE_T('\n')) if (c == QSE_CHAR_EOF || c == QSE_T('\n'))
{ {
sed->errnum = QSE_SED_ETMTXT; SETERR1 (sed, QSE_SED_EREXIC, 0,
QSE_STR_PTR(&sed->rexbuf),
QSE_STR_LEN(&sed->rexbuf)
);
return QSE_NULL; return QSE_NULL;
} }
@ -274,7 +277,10 @@ static void* compile_rex (qse_sed_t* sed, qse_char_t rxend)
c = CURSC (sed); c = CURSC (sed);
if (c == QSE_CHAR_EOF || c == QSE_T('\n')) if (c == QSE_CHAR_EOF || c == QSE_T('\n'))
{ {
sed->errnum = QSE_SED_ETMTXT; SETERR1 (sed, QSE_SED_EREXIC, 0,
QSE_STR_PTR(&sed->rexbuf),
QSE_STR_LEN(&sed->rexbuf)
);
return QSE_NULL; return QSE_NULL;
} }
@ -298,7 +304,10 @@ static void* compile_rex (qse_sed_t* sed, qse_char_t rxend)
); );
if (code == QSE_NULL) if (code == QSE_NULL)
{ {
sed->errnum = QSE_SED_EREXBL; SETERR1 (sed, QSE_SED_EREXBL, 0,
QSE_STR_PTR(&sed->rexbuf),
QSE_STR_LEN(&sed->rexbuf)
);
return QSE_NULL; return QSE_NULL;
} }
@ -343,9 +352,7 @@ static qse_sed_adr_t* get_address (qse_sed_t* sed, qse_sed_adr_t* a)
c = NXTSC (sed); c = NXTSC (sed);
if (c == QSE_CHAR_EOF || c == QSE_T('\n')) if (c == QSE_CHAR_EOF || c == QSE_T('\n'))
{ {
/* TODO: change error code - SETERR1 (sed, QSE_SED_EREXIC, 0, QSE_T(""), 0);
* unterminated address regular expression */
sed->errnum = QSE_SED_ETMTXT;
return QSE_NULL; return QSE_NULL;
} }
@ -811,7 +818,10 @@ static int get_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
); );
if (cmd->u.subst.rex == QSE_NULL) if (cmd->u.subst.rex == QSE_NULL)
{ {
sed->errnum = QSE_SED_EREXBL; SETERR1 (sed, QSE_SED_EREXBL, 0,
QSE_STR_PTR(t[0]),
QSE_STR_LEN(t[0])
);
goto oops; goto oops;
} }
@ -968,7 +978,7 @@ restart:
if (cmd->a1.type != QSE_SED_ADR_NONE) if (cmd->a1.type != QSE_SED_ADR_NONE)
{ {
/* label cannot have an address */ /* label cannot have an address */
sed->errnum = QSE_SED_EA1PHB; SETERR1 (sed, QSE_SED_EA1PHB, 0, &cmd->type, 1);
return -1; return -1;
} }

View File

@ -1,11 +1,14 @@
AM_CPPFLAGS = -I$(top_srcdir)/include AM_CPPFLAGS = -I$(top_srcdir)/include
bin_PROGRAMS = sed01 sed02 bin_PROGRAMS = sed01
LDFLAGS = -L../../lib/cmn -L../../lib/utl -L../../lib/sed LDFLAGS = -L../../lib/cmn -L../../lib/utl -L../../lib/sed
LDADD = -lqsesed -lqseutl -lqsecmn $(LIBM) LDADD = -lqsesed -lqseutl -lqsecmn $(LIBM)
sed01_SOURCES = sed01.c sed01_SOURCES = sed01.c
if ENABLE_CXX
bin_PROGRAMS += sed02
sed02_SOURCES = sed02.cpp sed02_SOURCES = sed02.cpp
sed02_LDADD = -lqsesed++ $(LDADD) sed02_LDADD = -lqsesed++ $(LDADD)
endif