improved sed error handling

This commit is contained in:
hyung-hwan 2009-08-26 21:03:51 +00:00
parent 1f29eb2521
commit cefda5ffc6
8 changed files with 176 additions and 153 deletions

View File

@ -44,7 +44,7 @@ static qse_ssize_t in (
qse_cstr_t errarg; qse_cstr_t errarg;
errarg.ptr = g_infile; errarg.ptr = g_infile;
errarg.len = qse_strlen(g_infile); errarg.len = qse_strlen(g_infile);
qse_sed_seterror (sed, QSE_SED_EIOFIL, 0, &errarg); qse_sed_seterror (sed, QSE_SED_EIOFIL, &errarg, QSE_NULL);
return -1; return -1;
} }
} }
@ -209,13 +209,14 @@ int sed_main (int argc, qse_char_t* argv[])
if (qse_sed_comp (sed, g_script, qse_strlen(g_script)) == -1) if (qse_sed_comp (sed, g_script, qse_strlen(g_script)) == -1)
{ {
qse_size_t errlin = qse_sed_geterrlin(sed); const qse_sed_loc_t* errloc = qse_sed_geterrloc(sed);
if (errlin > 0) if (errloc->lin > 0 || errloc->col > 0)
{ {
qse_fprintf (QSE_STDERR, qse_fprintf (QSE_STDERR,
QSE_T("cannot compile - %s at line %lu\n"), QSE_T("cannot compile - %s at line %lu column %lu\n"),
qse_sed_geterrmsg(sed), qse_sed_geterrmsg(sed),
(unsigned long)errlin (unsigned long)errloc->lin,
(unsigned long)errloc->col
); );
} }
else else
@ -230,13 +231,14 @@ int sed_main (int argc, qse_char_t* argv[])
if (qse_sed_exec (sed, in, out) == -1) if (qse_sed_exec (sed, in, out) == -1)
{ {
qse_size_t errlin = qse_sed_geterrlin(sed); const qse_sed_loc_t* errloc = qse_sed_geterrloc(sed);
if (errlin > 0) if (errloc->lin > 0 || errloc->col > 0)
{ {
qse_fprintf (QSE_STDERR, qse_fprintf (QSE_STDERR,
QSE_T("cannot execute - %s at line %lu\n"), QSE_T("cannot execute - %s at line %lu column %lu\n"),
qse_sed_geterrmsg(sed), qse_sed_geterrmsg(sed),
(unsigned long)errlin (unsigned long)errloc->lin,
(unsigned long)errloc->col
); );
} }
else else

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Sed.hpp 258 2009-08-19 14:04:15Z hyunghwan.chung $ * $Id: Sed.hpp 269 2009-08-26 03:03:51Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -36,8 +36,10 @@ QSE_BEGIN_NAMESPACE(QSE)
class Sed: public Mmgr class Sed: public Mmgr
{ {
public: public:
/// Type sed_t type redefines a stream editor type /// The sed_t type redefines a stream editor type
typedef qse_sed_t sed_t; typedef qse_sed_t sed_t;
/// The loc_t type redefines the location type
typedef qse_sed_loc_t loc_t;
/// The errnum_t type redefines an error number type /// The errnum_t type redefines an error number type
typedef qse_sed_errnum_t errnum_t; typedef qse_sed_errnum_t errnum_t;
/// The errstr_t type redefines an error formattering string getter type /// The errstr_t type redefines an error formattering string getter type
@ -138,11 +140,12 @@ public:
const char_t* getErrorMessage() const; const char_t* getErrorMessage() const;
/** /**
* The getErrorLine() function gets the number of the line where * The getErrorLocation() function gets the location where
* the last error occurred. It returns 0 if the stream editor has * the last error occurred. The line and the column of the ::loc_t
* not been initialized with the open() function. * structure retruend are 0 if the stream editor has not been
* initialized with the open() function.
*/ */
size_t getErrorLine () const; loc_t getErrorLocation () const;
/** /**
* The getErrorNumber() function gets the number of the last * The getErrorNumber() function gets the number of the last
@ -155,9 +158,10 @@ public:
* The setError() function sets information on an error occurred. * The setError() function sets information on an error occurred.
*/ */
void setError ( void setError (
errnum_t err, ///< an error number errnum_t num, ///< error number
const cstr_t* args = QSE_NULL, ///< strings for formatting an error message const cstr_t* args = QSE_NULL, ///< string array for formatting
size_t lin = 0 ///< a line number /// an error message
const loc_t* loc = QSE_NULL ///< error location
); );
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* $Id: sed.h 268 2009-08-25 13:07:54Z hyunghwan.chung $ * $Id: sed.h 269 2009-08-26 03:03:51Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -304,11 +304,11 @@ qse_sed_errnum_t qse_sed_geterrnum (
); );
/** /**
* The qse_sed_geterrlin() function gets the number of the line where * The qse_sed_geterrloc() function gets the location where the last error
* the last error has occurred. * has occurred.
* @return the line number of the last error * @return error location
*/ */
qse_size_t qse_sed_geterrlin ( const qse_sed_loc_t* qse_sed_geterrloc (
qse_sed_t* sed /**< stream editor */ qse_sed_t* sed /**< stream editor */
); );
@ -321,15 +321,15 @@ const qse_char_t* qse_sed_geterrmsg (
); );
/** /**
* The qse_sed_geterror() function gets an error number, an error line, and * The qse_sed_geterror() function gets an error number, an error location,
* an error message. The information is set to the memory area pointed to by * and an error message. The information is set to the memory area pointed
* each parameter. * to by each parameter.
*/ */
void qse_sed_geterror ( void qse_sed_geterror (
qse_sed_t* sed, /**< stream editor */ qse_sed_t* sed, /**< stream editor */
qse_sed_errnum_t* errnum, /**< pointer to an error number holder */ qse_sed_errnum_t* errnum, /**< error number */
qse_size_t* errlin, /**< pointer to an error line holder */ const qse_char_t** errmsg, /**< error message */
const qse_char_t** errmsg /**< pointer to an error message */ qse_sed_loc_t* errloc /**< error location */
); );
/** /**
@ -347,22 +347,23 @@ void qse_sed_seterrnum (
* message for a given error number. * message for a given error number.
*/ */
void qse_sed_seterrmsg ( void qse_sed_seterrmsg (
qse_sed_t* sed, /**< stream editor */ qse_sed_t* sed, /**< stream editor */
qse_sed_errnum_t errnum, /**< error number */ qse_sed_errnum_t errnum, /**< error number */
const qse_char_t* errmsg, /**< error message */ const qse_char_t* errmsg, /**< error message */
qse_size_t errlin /**< error line */ const qse_sed_loc_t* errloc /**< error location */
); );
/** /**
* The qse_sed_seterror() function sets an error number, an error line, and * The qse_sed_seterror() function sets an error number, an error location, and
* an error message. An error string is composed of a formatting string * an error message. An error string is composed of a formatting string
* and an array of formatting parameters. * and an array of formatting parameters.
*/ */
void qse_sed_seterror ( void qse_sed_seterror (
qse_sed_t* sed, /**< stream editor */ qse_sed_t* sed, /**< stream editor */
qse_sed_errnum_t errnum, /**< error number */ qse_sed_errnum_t errnum, /**< error number */
const qse_cstr_t* errarg, /**< argument array for formatting error message */ const qse_cstr_t* errarg, /**< array of arguments for formatting
qse_size_t errlin /**< error line */ * an error message */
const qse_sed_loc_t* errloc /**< error location */
); );
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* $Id: err.c 267 2009-08-25 09:50:07Z hyunghwan.chung $ * $Id: err.c 269 2009-08-26 03:03:51Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -195,13 +195,13 @@ void qse_awk_geterror (
const qse_char_t** errmsg, qse_awk_loc_t* errloc) const qse_char_t** errmsg, qse_awk_loc_t* errloc)
{ {
if (errnum != QSE_NULL) *errnum = awk->errinf.num; if (errnum != QSE_NULL) *errnum = awk->errinf.num;
if (errloc != QSE_NULL) *errloc = awk->errinf.loc;
if (errmsg != QSE_NULL) if (errmsg != QSE_NULL)
{ {
*errmsg = (awk->errinf.msg[0] == QSE_T('\0'))? *errmsg = (awk->errinf.msg[0] == QSE_T('\0'))?
qse_awk_geterrstr(awk)(awk,awk->errinf.num): qse_awk_geterrstr(awk)(awk,awk->errinf.num):
awk->errinf.msg; awk->errinf.msg;
} }
if (errloc != QSE_NULL) *errloc = awk->errinf.loc;
} }
void qse_awk_seterrnum ( void qse_awk_seterrnum (

View File

@ -1,5 +1,5 @@
/* /*
* $Id: Sed.cpp 257 2009-08-17 12:10:30Z hyunghwan.chung $ * $Id: Sed.cpp 269 2009-08-26 03:03:51Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -91,9 +91,15 @@ const Sed::char_t* Sed::getErrorMessage () const
return (sed == QSE_NULL)? QSE_T(""): qse_sed_geterrmsg (sed); return (sed == QSE_NULL)? QSE_T(""): qse_sed_geterrmsg (sed);
} }
Sed::size_t Sed::getErrorLine () const Sed::loc_t Sed::getErrorLocation () const
{ {
return (sed == QSE_NULL)? 0: qse_sed_geterrlin (sed); if (sed == QSE_NULL)
{
loc_t loc;
loc.lin = 0; loc.col = 0;
return loc;
}
return *qse_sed_geterrloc (sed);
} }
Sed::errnum_t Sed::getErrorNumber () const Sed::errnum_t Sed::getErrorNumber () const
@ -101,10 +107,10 @@ Sed::errnum_t Sed::getErrorNumber () const
return (sed == QSE_NULL)? QSE_SED_ENOERR: qse_sed_geterrnum (sed); return (sed == QSE_NULL)? QSE_SED_ENOERR: qse_sed_geterrnum (sed);
} }
void Sed::setError (errnum_t err, const cstr_t* args, size_t lin) void Sed::setError (errnum_t err, const cstr_t* args, const loc_t* loc)
{ {
QSE_ASSERT (sed != QSE_NULL); QSE_ASSERT (sed != QSE_NULL);
qse_sed_seterror (sed, err, args, lin); qse_sed_seterror (sed, err, args, loc);
} }
Sed::size_t Sed::getConsoleLine () Sed::size_t Sed::getConsoleLine ()

View File

@ -1,5 +1,5 @@
/* /*
* $Id: err.c 257 2009-08-17 12:10:30Z hyunghwan.chung $ * $Id: err.c 269 2009-08-26 03:03:51Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -17,6 +17,7 @@
*/ */
#include "sed.h" #include "sed.h"
#include "../cmn/mem.h"
const qse_char_t* qse_sed_dflerrstr (qse_sed_t* sed, qse_sed_errnum_t errnum) const qse_char_t* qse_sed_dflerrstr (qse_sed_t* sed, qse_sed_errnum_t errnum)
{ {
@ -72,9 +73,9 @@ qse_sed_errnum_t qse_sed_geterrnum (qse_sed_t* sed)
return sed->errnum; return sed->errnum;
} }
qse_size_t qse_sed_geterrlin (qse_sed_t* sed) const qse_sed_loc_t* qse_sed_geterrloc (qse_sed_t* sed)
{ {
return sed->errlin; return &sed->errloc;
} }
const qse_char_t* qse_sed_geterrmsg (qse_sed_t* sed) const qse_char_t* qse_sed_geterrmsg (qse_sed_t* sed)
@ -85,44 +86,47 @@ const qse_char_t* qse_sed_geterrmsg (qse_sed_t* sed)
void qse_sed_geterror ( void qse_sed_geterror (
qse_sed_t* sed, qse_sed_errnum_t* errnum, qse_sed_t* sed, qse_sed_errnum_t* errnum,
qse_size_t* errlin, const qse_char_t** errmsg) const qse_char_t** errmsg, qse_sed_loc_t* errloc)
{ {
if (errnum != QSE_NULL) *errnum = sed->errnum; if (errnum != QSE_NULL) *errnum = sed->errnum;
if (errlin != QSE_NULL) *errlin = sed->errlin;
if (errmsg != QSE_NULL) if (errmsg != QSE_NULL)
{ {
*errmsg = (sed->errmsg[0] == QSE_T('\0'))? *errmsg = (sed->errmsg[0] == QSE_T('\0'))?
qse_sed_geterrstr(sed)(sed,sed->errnum): qse_sed_geterrstr(sed)(sed,sed->errnum):
sed->errmsg; sed->errmsg;
} }
if (errloc != QSE_NULL) *errloc = sed->errloc;
} }
void qse_sed_seterrnum ( void qse_sed_seterrnum (
qse_sed_t* sed, qse_sed_errnum_t errnum, const qse_cstr_t* errarg) qse_sed_t* sed, qse_sed_errnum_t errnum, const qse_cstr_t* errarg)
{ {
qse_sed_seterror (sed, errnum, errarg, 0); qse_sed_seterror (sed, errnum, errarg, QSE_NULL);
} }
void qse_sed_seterrmsg ( void qse_sed_seterrmsg (
qse_sed_t* sed, qse_sed_errnum_t errnum, qse_sed_t* sed, qse_sed_errnum_t errnum,
const qse_char_t* errmsg, qse_size_t errlin) const qse_char_t* errmsg, const qse_sed_loc_t* errloc)
{ {
sed->errnum = errnum; sed->errnum = errnum;
sed->errlin = errlin;
qse_strxcpy (sed->errmsg, QSE_COUNTOF(sed->errmsg), errmsg); qse_strxcpy (sed->errmsg, QSE_COUNTOF(sed->errmsg), errmsg);
if (errloc != QSE_NULL) sed->errloc = *errloc;
else QSE_MEMSET (&sed->errloc, 0, QSE_SIZEOF(sed->errloc));
} }
void qse_sed_seterror ( void qse_sed_seterror (
qse_sed_t* sed, qse_sed_errnum_t errnum, qse_sed_t* sed, qse_sed_errnum_t errnum,
const qse_cstr_t* errarg, qse_size_t errlin) const qse_cstr_t* errarg, const qse_sed_loc_t* errloc)
{ {
const qse_char_t* errfmt; const qse_char_t* errfmt;
sed->errnum = errnum; sed->errnum = errnum;
sed->errlin = errlin;
errfmt = qse_sed_geterrstr(sed)(sed,sed->errnum); errfmt = qse_sed_geterrstr(sed)(sed,sed->errnum);
QSE_ASSERT (errfmt != QSE_NULL); QSE_ASSERT (errfmt != QSE_NULL);
qse_strxfncpy (sed->errmsg, QSE_COUNTOF(sed->errmsg), errfmt, errarg); qse_strxfncpy (sed->errmsg, QSE_COUNTOF(sed->errmsg), errfmt, errarg);
if (errloc != QSE_NULL) sed->errloc = *errloc;
else QSE_MEMSET (&sed->errloc, 0, QSE_SIZEOF(sed->errloc));
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: sed.c 268 2009-08-25 13:07:54Z hyunghwan.chung $ * $Id: sed.c 269 2009-08-26 03:03:51Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -29,14 +29,14 @@ static void free_all_command_blocks (qse_sed_t* sed);
static qse_sed_t* qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr); static qse_sed_t* qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr);
static void qse_sed_fini (qse_sed_t* sed); static void qse_sed_fini (qse_sed_t* sed);
#define SETERR0(sed,num,line) \ #define SETERR0(sed,num,loc) \
do { qse_sed_seterror (sed, num, QSE_NULL, line); } while (0) do { qse_sed_seterror (sed, num, QSE_NULL, loc); } while (0)
#define SETERR1(sed,num,line,argp,argl) \ #define SETERR1(sed,num,argp,argl,loc) \
do { \ do { \
qse_cstr_t __ea__; \ qse_cstr_t __ea__; \
__ea__.ptr = argp; __ea__.len = argl; \ __ea__.ptr = argp; __ea__.len = argl; \
qse_sed_seterror (sed, num, &__ea__, line); \ qse_sed_seterror (sed, num, &__ea__, loc); \
} while (0) } while (0)
qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtn) qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtn)
@ -79,14 +79,14 @@ static qse_sed_t* qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr)
if (qse_str_init (&sed->tmp.rex, mmgr, 0) == QSE_NULL) if (qse_str_init (&sed->tmp.rex, mmgr, 0) == QSE_NULL)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
if (qse_str_init (&sed->tmp.lab, mmgr, 0) == QSE_NULL) if (qse_str_init (&sed->tmp.lab, mmgr, 0) == QSE_NULL)
{ {
qse_str_fini (&sed->tmp.lab); qse_str_fini (&sed->tmp.lab);
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
@ -94,7 +94,7 @@ static qse_sed_t* qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr)
{ {
qse_str_fini (&sed->tmp.lab); qse_str_fini (&sed->tmp.lab);
qse_str_fini (&sed->tmp.rex); qse_str_fini (&sed->tmp.rex);
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
qse_map_setcopier (&sed->tmp.labs, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); qse_map_setcopier (&sed->tmp.labs, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE);
@ -243,7 +243,7 @@ static int add_command_block (qse_sed_t* sed)
b = (qse_sed_cmd_blk_t*) QSE_MMGR_ALLOC (sed->mmgr, QSE_SIZEOF(*b)); b = (qse_sed_cmd_blk_t*) QSE_MMGR_ALLOC (sed->mmgr, QSE_SIZEOF(*b));
if (b == QSE_NULL) if (b == QSE_NULL)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
@ -337,9 +337,9 @@ static void* compile_rex (qse_sed_t* sed, qse_char_t rxend)
{ {
SETERR1 ( SETERR1 (
sed, QSE_SED_EREXIC, sed, QSE_SED_EREXIC,
sed->src.loc.lin,
QSE_STR_PTR(&sed->tmp.rex), QSE_STR_PTR(&sed->tmp.rex),
QSE_STR_LEN(&sed->tmp.rex) QSE_STR_LEN(&sed->tmp.rex),
&sed->src.loc
); );
return QSE_NULL; return QSE_NULL;
} }
@ -353,9 +353,9 @@ static void* compile_rex (qse_sed_t* sed, qse_char_t rxend)
{ {
SETERR1 ( SETERR1 (
sed, QSE_SED_EREXIC, sed, QSE_SED_EREXIC,
sed->src.loc.lin,
QSE_STR_PTR(&sed->tmp.rex), QSE_STR_PTR(&sed->tmp.rex),
QSE_STR_LEN(&sed->tmp.rex) QSE_STR_LEN(&sed->tmp.rex),
&sed->src.loc
); );
return QSE_NULL; return QSE_NULL;
} }
@ -366,7 +366,7 @@ static void* compile_rex (qse_sed_t* sed, qse_char_t rxend)
if (qse_str_ccat (&sed->tmp.rex, c) == (qse_size_t)-1) if (qse_str_ccat (&sed->tmp.rex, c) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
} }
@ -382,9 +382,10 @@ static void* compile_rex (qse_sed_t* sed, qse_char_t rxend)
if (code == QSE_NULL) if (code == QSE_NULL)
{ {
SETERR1 ( SETERR1 (
sed, QSE_SED_EREXBL, sed->src.loc.lin, sed, QSE_SED_EREXBL,
QSE_STR_PTR(&sed->tmp.rex), QSE_STR_PTR(&sed->tmp.rex),
QSE_STR_LEN(&sed->tmp.rex) QSE_STR_LEN(&sed->tmp.rex),
&sed->src.loc
); );
return QSE_NULL; return QSE_NULL;
} }
@ -431,7 +432,7 @@ static qse_sed_adr_t* get_address (qse_sed_t* sed, qse_sed_adr_t* a)
if (c == QSE_CHAR_EOF || c == QSE_T('\n')) if (c == QSE_CHAR_EOF || c == QSE_T('\n'))
{ {
SETERR1 (sed, QSE_SED_EREXIC, SETERR1 (sed, QSE_SED_EREXIC,
sed->src.loc.lin, QSE_T(""), 0); QSE_T(""), 0, &sed->src.loc);
return QSE_NULL; return QSE_NULL;
} }
@ -461,7 +462,7 @@ static int get_text (qse_sed_t* sed, qse_sed_cmd_t* cmd)
do { \ do { \
if (qse_str_ccat (str, c) == (qse_size_t)-1) \ if (qse_str_ccat (str, c) == (qse_size_t)-1) \
{ \ { \
SETERR0 (sed, QSE_SED_ENOMEM, 0); \ SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL); \
goto errlabel; \ goto errlabel; \
} \ } \
} while (0) } while (0)
@ -542,7 +543,7 @@ static int get_label (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (!IS_LABC(c)) if (!IS_LABC(c))
{ {
/* label name is empty */ /* label name is empty */
SETERR0 (sed, QSE_SED_ELABEM, sed->src.loc.lin); SETERR0 (sed, QSE_SED_ELABEM, &sed->src.loc);
return -1; return -1;
} }
@ -552,7 +553,7 @@ static int get_label (qse_sed_t* sed, qse_sed_cmd_t* cmd)
{ {
if (qse_str_ccat (&sed->tmp.lab, c) == (qse_size_t)-1) if (qse_str_ccat (&sed->tmp.lab, c) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
c = NXTSC (sed); c = NXTSC (sed);
@ -564,8 +565,12 @@ static int get_label (qse_sed_t* sed, qse_sed_cmd_t* cmd)
QSE_STR_PTR(&sed->tmp.lab), QSE_STR_PTR(&sed->tmp.lab),
QSE_STR_LEN(&sed->tmp.lab)) != QSE_NULL) QSE_STR_LEN(&sed->tmp.lab)) != QSE_NULL)
{ {
SETERR1 (sed, QSE_SED_ELABDU, sed->src.loc.lin, SETERR1 (
QSE_STR_PTR(&sed->tmp.lab), QSE_STR_LEN(&sed->tmp.lab)); sed, QSE_SED_ELABDU,
QSE_STR_PTR(&sed->tmp.lab),
QSE_STR_LEN(&sed->tmp.lab),
&sed->src.loc
);
return -1; return -1;
} }
@ -574,7 +579,7 @@ static int get_label (qse_sed_t* sed, qse_sed_cmd_t* cmd)
QSE_STR_PTR(&sed->tmp.lab), QSE_STR_LEN(&sed->tmp.lab), QSE_STR_PTR(&sed->tmp.lab), QSE_STR_LEN(&sed->tmp.lab),
cmd, 0) == QSE_NULL) cmd, 0) == QSE_NULL)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
@ -598,7 +603,7 @@ static int terminate_command (qse_sed_t* sed)
while (IS_SPACE(c)) c = NXTSC (sed); while (IS_SPACE(c)) c = NXTSC (sed);
if (!IS_CMDTERM(c)) if (!IS_CMDTERM(c))
{ {
SETERR0 (sed, QSE_SED_ESCEXP, sed->src.loc.lin); SETERR0 (sed, QSE_SED_ESCEXP, &sed->src.loc);
return -1; return -1;
} }
@ -637,7 +642,7 @@ static int get_branch_target (qse_sed_t* sed, qse_sed_cmd_t* cmd)
t = qse_str_open (sed->mmgr, 0, 32); t = qse_str_open (sed->mmgr, 0, 32);
if (t == QSE_NULL) if (t == QSE_NULL)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
goto oops; goto oops;
} }
@ -645,7 +650,7 @@ static int get_branch_target (qse_sed_t* sed, qse_sed_cmd_t* cmd)
{ {
if (qse_str_ccat (t, c) == (qse_size_t)-1) if (qse_str_ccat (t, c) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
goto oops; goto oops;
} }
@ -688,14 +693,14 @@ static int get_file (qse_sed_t* sed, qse_xstr_t* xstr)
if (IS_CMDTERM(c)) if (IS_CMDTERM(c))
{ {
SETERR0 (sed, QSE_SED_EFILEM, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EFILEM, &sed->src.loc);
goto oops; goto oops;
} }
t = qse_str_open (sed->mmgr, 0, 32); t = qse_str_open (sed->mmgr, 0, 32);
if (t == QSE_NULL) if (t == QSE_NULL)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
goto oops; goto oops;
} }
@ -704,7 +709,7 @@ static int get_file (qse_sed_t* sed, qse_xstr_t* xstr)
if (c == QSE_T('\0')) if (c == QSE_T('\0'))
{ {
/* the file name should not contain '\0' */ /* the file name should not contain '\0' */
SETERR0 (sed, QSE_SED_EFILIL, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EFILIL, &sed->src.loc);
goto oops; goto oops;
} }
@ -716,7 +721,7 @@ static int get_file (qse_sed_t* sed, qse_xstr_t* xstr)
c = NXTSC (sed); c = NXTSC (sed);
if (c == QSE_T('\0') || c == QSE_CHAR_EOF || IS_LINTERM(c)) if (c == QSE_T('\0') || c == QSE_CHAR_EOF || IS_LINTERM(c))
{ {
SETERR0 (sed, QSE_SED_EFILIL, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EFILIL, &sed->src.loc);
goto oops; goto oops;
} }
@ -725,7 +730,7 @@ static int get_file (qse_sed_t* sed, qse_xstr_t* xstr)
if (qse_str_ccat (t, c) == (qse_size_t)-1) if (qse_str_ccat (t, c) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, sed->src.loc.lin); SETERR0 (sed, QSE_SED_ENOMEM, &sed->src.loc);
goto oops; goto oops;
} }
@ -754,8 +759,7 @@ do { \
if (c == QSE_CHAR_EOF || IS_LINTERM(c)) \ if (c == QSE_CHAR_EOF || IS_LINTERM(c)) \
{ \ { \
SETERR1 (sed, QSE_SED_ECMDIC, \ SETERR1 (sed, QSE_SED_ECMDIC, \
sed->src.loc.lin, \ &cmd->type, 1, &sed->src.loc); \
&cmd->type, 1); \
action; \ action; \
} \ } \
} while (0) } while (0)
@ -773,7 +777,7 @@ static int get_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (delim == QSE_T('\\')) if (delim == QSE_T('\\'))
{ {
/* backspace is an illegal delimiter */ /* backspace is an illegal delimiter */
SETERR0 (sed, QSE_SED_EBSDEL, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EBSDEL, &sed->src.loc);
goto oops; goto oops;
} }
@ -783,7 +787,7 @@ static int get_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
t[1] = qse_str_open (sed->mmgr, 0, 32); t[1] = qse_str_open (sed->mmgr, 0, 32);
if (t[1] == QSE_NULL) if (t[1] == QSE_NULL)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
goto oops; goto oops;
} }
@ -804,7 +808,7 @@ static int get_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (qse_str_ccat (t[i], c) == (qse_size_t)-1) if (qse_str_ccat (t[i], c) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
goto oops; goto oops;
} }
@ -839,7 +843,7 @@ static int get_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (cmd->u.subst.occ != 0) if (cmd->u.subst.occ != 0)
{ {
SETERR0 (sed, QSE_SED_EOCSDU, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EOCSDU, &sed->src.loc);
goto oops; goto oops;
} }
@ -850,7 +854,7 @@ static int get_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
occ = occ * 10 + (c - QSE_T('0')); occ = occ * 10 + (c - QSE_T('0'));
if (occ > QSE_TYPE_MAX(unsigned short)) if (occ > QSE_TYPE_MAX(unsigned short))
{ {
SETERR0 (sed, QSE_SED_EOCSTL, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EOCSTL, &sed->src.loc);
goto oops; goto oops;
} }
c = NXTSC (sed); c = NXTSC (sed);
@ -859,7 +863,7 @@ static int get_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (occ == 0) if (occ == 0)
{ {
SETERR0 (sed, QSE_SED_EOCSZE, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EOCSZE, &sed->src.loc);
goto oops; goto oops;
} }
@ -892,8 +896,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)
{ {
SETERR1 ( SETERR1 (
sed, QSE_SED_EREXBL, sed->src.loc.lin, sed, QSE_SED_EREXBL,
QSE_STR_PTR(t[0]), QSE_STR_LEN(t[0]) QSE_STR_PTR(t[0]),
QSE_STR_LEN(t[0]),
&sed->src.loc
); );
goto oops; goto oops;
} }
@ -922,14 +928,14 @@ static int get_transet (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (delim == QSE_T('\\')) if (delim == QSE_T('\\'))
{ {
/* backspace is an illegal delimiter */ /* backspace is an illegal delimiter */
SETERR0 (sed, QSE_SED_EBSDEL, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EBSDEL, &sed->src.loc);
goto oops; goto oops;
} }
t = qse_str_open (sed->mmgr, 0, 32); t = qse_str_open (sed->mmgr, 0, 32);
if (t == QSE_NULL) if (t == QSE_NULL)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
goto oops; goto oops;
} }
@ -950,7 +956,7 @@ static int get_transet (qse_sed_t* sed, qse_sed_cmd_t* cmd)
b[0] = c; b[0] = c;
if (qse_str_ncat (t, b, 2) == (qse_size_t)-1) if (qse_str_ncat (t, b, 2) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
goto oops; goto oops;
} }
@ -972,7 +978,7 @@ static int get_transet (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (pos >= QSE_STR_LEN(t)) if (pos >= QSE_STR_LEN(t))
{ {
/* source and target not the same length */ /* source and target not the same length */
SETERR0 (sed, QSE_SED_ETSNSL, sed->src.loc.lin); SETERR0 (sed, QSE_SED_ETSNSL, &sed->src.loc);
goto oops; goto oops;
} }
@ -983,7 +989,7 @@ static int get_transet (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (pos < QSE_STR_LEN(t)) if (pos < QSE_STR_LEN(t))
{ {
/* source and target not the same length */ /* source and target not the same length */
SETERR0 (sed, QSE_SED_ETSNSL, sed->src.loc.lin); SETERR0 (sed, QSE_SED_ETSNSL, &sed->src.loc);
goto oops; goto oops;
} }
@ -1011,13 +1017,13 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
default: default:
{ {
qse_char_t cc = c; qse_char_t cc = c;
SETERR1 (sed, QSE_SED_ECMDNR, sed->src.loc.lin, &cc, 1); SETERR1 (sed, QSE_SED_ECMDNR, &cc, 1, &sed->src.loc);
return -1; return -1;
} }
case QSE_CHAR_EOF: case QSE_CHAR_EOF:
case QSE_T('\n'): case QSE_T('\n'):
SETERR0 (sed, QSE_SED_ECMDMS, sed->src.loc.lin); SETERR0 (sed, QSE_SED_ECMDMS, &sed->src.loc);
return -1; return -1;
case QSE_T(':'): case QSE_T(':'):
@ -1026,7 +1032,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
/* label cannot have an address */ /* label cannot have an address */
SETERR1 ( SETERR1 (
sed, QSE_SED_EA1PHB, sed, QSE_SED_EA1PHB,
sed->src.loc.lin, &cmd->type, 1 &cmd->type, 1, &sed->src.loc
); );
return -1; return -1;
} }
@ -1051,7 +1057,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (sed->tmp.grp.level >= QSE_COUNTOF(sed->tmp.grp.cmd)) if (sed->tmp.grp.level >= QSE_COUNTOF(sed->tmp.grp.cmd))
{ {
/* group nesting too deep */ /* group nesting too deep */
SETERR0 (sed, QSE_SED_EGRNTD, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EGRNTD, &sed->src.loc);
return -1; return -1;
} }
@ -1068,7 +1074,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
qse_char_t tmpc = c; qse_char_t tmpc = c;
SETERR1 ( SETERR1 (
sed, QSE_SED_EA1PHB, sed, QSE_SED_EA1PHB,
sed->src.loc.lin, &tmpc, 1 &tmpc, 1, &sed->src.loc
); );
return -1; return -1;
} }
@ -1078,7 +1084,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (sed->tmp.grp.level <= 0) if (sed->tmp.grp.level <= 0)
{ {
/* group not balanced */ /* group not balanced */
SETERR0 (sed, QSE_SED_EGRNBA, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EGRNBA, &sed->src.loc);
return -1; return -1;
} }
@ -1097,7 +1103,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
{ {
SETERR1 ( SETERR1 (
sed, QSE_SED_EA2PHB, sed, QSE_SED_EA2PHB,
sed->src.loc.lin, &cmd->type, 1 &cmd->type, 1, &sed->src.loc
); );
return -1; return -1;
} }
@ -1114,7 +1120,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
qse_char_t tmpc = c; qse_char_t tmpc = c;
SETERR1 ( SETERR1 (
sed, QSE_SED_EA2PHB, sed, QSE_SED_EA2PHB,
sed->src.loc.lin, &tmpc, 1 &tmpc, 1, &sed->src.loc
); );
return -1; return -1;
} }
@ -1127,7 +1133,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (c != QSE_T('\\')) if (c != QSE_T('\\'))
{ {
SETERR0 (sed, QSE_SED_EBSEXP, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EBSEXP, &sed->src.loc);
return -1; return -1;
} }
@ -1136,7 +1142,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (c != QSE_CHAR_EOF && c != QSE_T('\n')) if (c != QSE_CHAR_EOF && c != QSE_T('\n'))
{ {
SETERR0 (sed, QSE_SED_EGBABS, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EGBABS, &sed->src.loc);
return -1; return -1;
} }
@ -1155,7 +1161,7 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
qse_char_t tmpc = c; qse_char_t tmpc = c;
SETERR1 ( SETERR1 (
sed, QSE_SED_EA2PHB, sed, QSE_SED_EA2PHB,
sed->src.loc.lin, &tmpc, 1 &tmpc, 1, &sed->src.loc
); );
return -1; return -1;
} }
@ -1293,7 +1299,7 @@ int qse_sed_comp (qse_sed_t* sed, const qse_char_t* sptr, qse_size_t slen)
{ {
if (cmd->a2.type == QSE_SED_ADR_NONE) if (cmd->a2.type == QSE_SED_ADR_NONE)
{ {
SETERR0 (sed, QSE_SED_EA2MOI, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EA2MOI, &sed->src.loc);
free_address(sed, cmd); free_address(sed, cmd);
return -1; return -1;
} }
@ -1304,7 +1310,7 @@ int qse_sed_comp (qse_sed_t* sed, const qse_char_t* sptr, qse_size_t slen)
if (cmd->a1.type != QSE_SED_ADR_LINE || if (cmd->a1.type != QSE_SED_ADR_LINE ||
cmd->a2.type != QSE_SED_ADR_LINE) cmd->a2.type != QSE_SED_ADR_LINE)
{ {
SETERR0 (sed, QSE_SED_EA2MOI, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EA2MOI, &sed->src.loc);
free_address(sed, cmd); free_address(sed, cmd);
return -1; return -1;
} }
@ -1349,7 +1355,7 @@ int qse_sed_comp (qse_sed_t* sed, const qse_char_t* sptr, qse_size_t slen)
if (sed->tmp.grp.level != 0) if (sed->tmp.grp.level != 0)
{ {
SETERR0 (sed, QSE_SED_EGRNBA, sed->src.loc.lin); SETERR0 (sed, QSE_SED_EGRNBA, &sed->src.loc);
return -1; return -1;
} }
@ -1373,7 +1379,7 @@ static int read_char (qse_sed_t* sed, qse_char_t* c)
if (n <= -1) if (n <= -1)
{ {
if (sed->errnum == QSE_SED_ENOERR) if (sed->errnum == QSE_SED_ENOERR)
SETERR0 (sed, QSE_SED_EIOUSR, 0); SETERR0 (sed, QSE_SED_EIOUSR, QSE_NULL);
return -1; return -1;
} }
@ -1413,7 +1419,7 @@ static int read_file (
if (n <= -1) if (n <= -1)
{ {
/*if (sed->errnum != QSE_SED_ENOERR) /*if (sed->errnum != QSE_SED_ENOERR)
* SETERR0 (sed, QSE_SED_EIOUSR, cmd->loc.lin); * SETERR0 (sed, QSE_SED_EIOUSR, &cmd->loc);
*return -1;*/ *return -1;*/
/* it is ok if it is not able to open a file */ /* it is ok if it is not able to open a file */
return 0; return 0;
@ -1436,8 +1442,8 @@ static int read_file (
{ {
sed->e.in.fun (sed, QSE_SED_IO_CLOSE, &arg); sed->e.in.fun (sed, QSE_SED_IO_CLOSE, &arg);
if (sed->errnum == QSE_SED_ENOERR) if (sed->errnum == QSE_SED_ENOERR)
SETERR1 (sed, QSE_SED_EIOFIL, 0, path, plen); SETERR1 (sed, QSE_SED_EIOFIL, path, plen, &cmd->loc);
sed->errlin = cmd->loc.lin; else sed->errloc = cmd->loc;
return -1; return -1;
} }
if (n == 0) break; if (n == 0) break;
@ -1451,7 +1457,7 @@ static int read_file (
if (qse_str_ccat (&sed->e.txt.read, buf[i]) == (qse_size_t)-1) if (qse_str_ccat (&sed->e.txt.read, buf[i]) == (qse_size_t)-1)
{ {
sed->e.in.fun (sed, QSE_SED_IO_CLOSE, &arg); sed->e.in.fun (sed, QSE_SED_IO_CLOSE, &arg);
SETERR0 (sed, QSE_SED_ENOMEM, cmd->loc.lin); SETERR0 (sed, QSE_SED_ENOMEM, &cmd->loc);
return -1; return -1;
} }
@ -1464,7 +1470,7 @@ static int read_file (
if (qse_str_ncat (&sed->e.txt.read, buf, n) == (qse_size_t)-1) if (qse_str_ncat (&sed->e.txt.read, buf, n) == (qse_size_t)-1)
{ {
sed->e.in.fun (sed, QSE_SED_IO_CLOSE, &arg); sed->e.in.fun (sed, QSE_SED_IO_CLOSE, &arg);
SETERR0 (sed, QSE_SED_ENOMEM, cmd->loc.lin); SETERR0 (sed, QSE_SED_ENOMEM, &cmd->loc);
return -1; return -1;
} }
} }
@ -1508,7 +1514,7 @@ static int read_line (qse_sed_t* sed, int append)
if (qse_str_ccat (&sed->e.in.line, c) == (qse_size_t)-1) if (qse_str_ccat (&sed->e.in.line, c) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
len++; len++;
@ -1537,7 +1543,7 @@ static int flush (qse_sed_t* sed)
if (n <= -1) if (n <= -1)
{ {
if (sed->errnum == QSE_SED_ENOERR) if (sed->errnum == QSE_SED_ENOERR)
SETERR0 (sed, QSE_SED_EIOUSR, 0); SETERR0 (sed, QSE_SED_EIOUSR, QSE_NULL);
return -1; return -1;
} }
@ -1545,7 +1551,7 @@ static int flush (qse_sed_t* sed)
{ {
/* reached the end of file - this is also an error */ /* reached the end of file - this is also an error */
if (sed->errnum == QSE_SED_ENOERR) if (sed->errnum == QSE_SED_ENOERR)
SETERR0 (sed, QSE_SED_EIOUSR, 0); SETERR0 (sed, QSE_SED_EIOUSR, QSE_NULL);
return -1; return -1;
} }
@ -1738,7 +1744,7 @@ static int write_str_to_file (
(void*)path, plen, &arg, QSE_SIZEOF(arg)); (void*)path, plen, &arg, QSE_SIZEOF(arg));
if (pair == QSE_NULL) if (pair == QSE_NULL)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, cmd->loc.lin); SETERR0 (sed, QSE_SED_ENOMEM, &cmd->loc);
return -1; return -1;
} }
} }
@ -1752,8 +1758,8 @@ static int write_str_to_file (
if (n <= -1) if (n <= -1)
{ {
if (sed->errnum == QSE_SED_ENOERR) if (sed->errnum == QSE_SED_ENOERR)
SETERR1 (sed, QSE_SED_EIOFIL, 0, path, plen); SETERR1 (sed, QSE_SED_EIOFIL, path, plen, &cmd->loc);
sed->errlin = cmd->loc.lin; else sed->errloc = cmd->loc;
return -1; return -1;
} }
if (n == 0) if (n == 0)
@ -1763,7 +1769,7 @@ static int write_str_to_file (
* a requested string */ * a requested string */
sed->e.out.fun (sed, QSE_SED_IO_CLOSE, ap); sed->e.out.fun (sed, QSE_SED_IO_CLOSE, ap);
ap->handle = QSE_NULL; ap->handle = QSE_NULL;
SETERR1 (sed, QSE_SED_EIOFIL, cmd->loc.lin, path, plen); SETERR1 (sed, QSE_SED_EIOFIL, path, plen, &cmd->loc);
return -1; return -1;
} }
} }
@ -1779,8 +1785,8 @@ static int write_str_to_file (
sed->e.out.fun (sed, QSE_SED_IO_CLOSE, ap); sed->e.out.fun (sed, QSE_SED_IO_CLOSE, ap);
ap->handle = QSE_NULL; ap->handle = QSE_NULL;
if (sed->errnum == QSE_SED_ENOERR) if (sed->errnum == QSE_SED_ENOERR)
SETERR1 (sed, QSE_SED_EIOFIL, 0, path, plen); SETERR1 (sed, QSE_SED_EIOFIL, path, plen, &cmd->loc);
sed->errlin = cmd->loc.lin; sed->errloc = cmd->loc;
return -1; return -1;
} }
@ -1790,7 +1796,7 @@ static int write_str_to_file (
* it is also an error as it can't write any more */ * it is also an error as it can't write any more */
sed->e.out.fun (sed, QSE_SED_IO_CLOSE, ap); sed->e.out.fun (sed, QSE_SED_IO_CLOSE, ap);
ap->handle = QSE_NULL; ap->handle = QSE_NULL;
SETERR1 (sed, QSE_SED_EIOFIL, cmd->loc.lin, path, plen); SETERR1 (sed, QSE_SED_EIOFIL, path, plen, &cmd->loc);
return -1; return -1;
} }
@ -1849,7 +1855,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (n <= -1) if (n <= -1)
{ {
SETERR0 (sed, QSE_SED_EREXMA, cmd->loc.lin); SETERR0 (sed, QSE_SED_EREXMA, &cmd->loc);
return -1; return -1;
} }
@ -1860,7 +1866,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
&sed->e.txt.subst, &sed->e.txt.subst,
cur_ptr, cur_len) == (qse_size_t)-1) cur_ptr, cur_len) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
break; break;
@ -1884,7 +1890,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (m == (qse_size_t)-1) if (m == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
} }
@ -1896,7 +1902,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
&sed->e.txt.subst, cur_ptr, mat.ptr-cur_ptr); &sed->e.txt.subst, cur_ptr, mat.ptr-cur_ptr);
if (m == (qse_size_t)-1) if (m == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
@ -1925,7 +1931,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
if (m == (qse_size_t)-1) if (m == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
} }
@ -1945,7 +1951,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
m = qse_str_ncat (&sed->e.txt.subst, cur_ptr, 1); m = qse_str_ncat (&sed->e.txt.subst, cur_ptr, 1);
if (m == (qse_size_t)-1) if (m == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
@ -1959,7 +1965,7 @@ static int do_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
m = qse_str_ccat (&sed->e.txt.subst, QSE_T('\n')); m = qse_str_ccat (&sed->e.txt.subst, QSE_T('\n'));
if (m == (qse_size_t)-1) if (m == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
} }
@ -2029,7 +2035,7 @@ static int match_a (qse_sed_t* sed, qse_sed_cmd_t* cmd, qse_sed_adr_t* a)
&match, &errnum); &match, &errnum);
if (n <= -1) if (n <= -1)
{ {
SETERR0 (sed, QSE_SED_EREXMA, cmd->loc.lin); SETERR0 (sed, QSE_SED_EREXMA, &cmd->loc);
return -1; return -1;
} }
@ -2186,7 +2192,7 @@ static qse_sed_cmd_t* exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd)
QSE_LDA_SIZE(&sed->e.txt.appended), QSE_LDA_SIZE(&sed->e.txt.appended),
&cmd->u.text, 0) == (qse_size_t)-1) &cmd->u.text, 0) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
break; break;
@ -2208,7 +2214,7 @@ static qse_sed_cmd_t* exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd)
QSE_STR_LEN(&cmd->u.text)); QSE_STR_LEN(&cmd->u.text));
if (n == (qse_size_t)-1) if (n == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
} }
@ -2300,7 +2306,7 @@ static qse_sed_cmd_t* exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd)
QSE_STR_PTR(&sed->e.in.line), QSE_STR_PTR(&sed->e.in.line),
QSE_STR_LEN(&sed->e.in.line)) == (qse_size_t)-1) QSE_STR_LEN(&sed->e.in.line)) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
break; break;
@ -2311,7 +2317,7 @@ static qse_sed_cmd_t* exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd)
QSE_STR_PTR(&sed->e.in.line), QSE_STR_PTR(&sed->e.in.line),
QSE_STR_LEN(&sed->e.in.line)) == (qse_size_t)-1) QSE_STR_LEN(&sed->e.in.line)) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
break; break;
@ -2322,7 +2328,7 @@ static qse_sed_cmd_t* exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd)
QSE_STR_PTR(&sed->e.txt.held), QSE_STR_PTR(&sed->e.txt.held),
QSE_STR_LEN(&sed->e.txt.held)) == (qse_size_t)-1) QSE_STR_LEN(&sed->e.txt.held)) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
break; break;
@ -2333,7 +2339,7 @@ static qse_sed_cmd_t* exec_cmd (qse_sed_t* sed, qse_sed_cmd_t* cmd)
QSE_STR_PTR(&sed->e.txt.held), QSE_STR_PTR(&sed->e.txt.held),
QSE_STR_LEN(&sed->e.txt.held)) == (qse_size_t)-1) QSE_STR_LEN(&sed->e.txt.held)) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return QSE_NULL; return QSE_NULL;
} }
break; break;
@ -2529,7 +2535,7 @@ static int init_command_block_for_exec (qse_sed_t* sed, qse_sed_cmd_blk_t* b)
{ {
SETERR1 ( SETERR1 (
sed, QSE_SED_ELABNF, sed, QSE_SED_ELABNF,
c->loc.lin, lab->ptr, lab->len lab->ptr, lab->len, &c->loc
); );
return -1; return -1;
} }
@ -2595,7 +2601,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_fun_t inf, qse_sed_io_fun_t outf)
qse_str_clear (&sed->e.txt.held); qse_str_clear (&sed->e.txt.held);
if (qse_str_ccat (&sed->e.txt.held, QSE_T('\n')) == (qse_size_t)-1) if (qse_str_ccat (&sed->e.txt.held, QSE_T('\n')) == (qse_size_t)-1)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
@ -2604,7 +2610,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_fun_t inf, qse_sed_io_fun_t outf)
sed->e.out.len = 0; sed->e.out.len = 0;
if (qse_map_init (&sed->e.out.files, sed->mmgr, 128, 70) == QSE_NULL) if (qse_map_init (&sed->e.out.files, sed->mmgr, 128, 70) == QSE_NULL)
{ {
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
*(qse_sed_t**)QSE_XTN(&sed->e.out.files) = sed; *(qse_sed_t**)QSE_XTN(&sed->e.out.files) = sed;
@ -2625,7 +2631,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_fun_t inf, qse_sed_io_fun_t outf)
if (qse_str_init (&sed->e.in.line, QSE_MMGR(sed), 256) == QSE_NULL) if (qse_str_init (&sed->e.in.line, QSE_MMGR(sed), 256) == QSE_NULL)
{ {
qse_map_fini (&sed->e.out.files); qse_map_fini (&sed->e.out.files);
SETERR0 (sed, QSE_SED_ENOMEM, 0); SETERR0 (sed, QSE_SED_ENOMEM, QSE_NULL);
return -1; return -1;
} }
@ -2636,7 +2642,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_fun_t inf, qse_sed_io_fun_t outf)
{ {
ret = -1; ret = -1;
if (sed->errnum == QSE_SED_ENOERR) if (sed->errnum == QSE_SED_ENOERR)
SETERR0 (sed, QSE_SED_EIOUSR, 0); SETERR0 (sed, QSE_SED_EIOUSR, QSE_NULL);
goto done3; goto done3;
} }
if (n == 0) if (n == 0)
@ -2653,7 +2659,7 @@ int qse_sed_exec (qse_sed_t* sed, qse_sed_io_fun_t inf, qse_sed_io_fun_t outf)
{ {
ret = -1; ret = -1;
if (sed->errnum == QSE_SED_ENOERR) if (sed->errnum == QSE_SED_ENOERR)
SETERR0 (sed, QSE_SED_EIOUSR, 0); SETERR0 (sed, QSE_SED_EIOUSR, QSE_NULL);
goto done2; goto done2;
} }
if (n == 0) if (n == 0)

View File

@ -1,5 +1,5 @@
/* /*
* $Id: sed.h 268 2009-08-25 13:07:54Z hyunghwan.chung $ * $Id: sed.h 269 2009-08-26 03:03:51Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -143,7 +143,7 @@ struct qse_sed_t
qse_sed_errstr_t errstr; /**< error string getter */ qse_sed_errstr_t errstr; /**< error string getter */
qse_sed_errnum_t errnum; /**< stores an error number */ qse_sed_errnum_t errnum; /**< stores an error number */
qse_char_t errmsg[128]; /**< error message holder */ qse_char_t errmsg[128]; /**< error message holder */
qse_size_t errlin; /**< no of the line where an error occurred */ qse_sed_loc_t errloc; /**< location of the last error */
int option; /**< stores options */ int option; /**< stores options */