2009-05-22 00:17:17 +00:00
|
|
|
/*
|
2012-08-16 03:47:55 +00:00
|
|
|
* $Id$
|
2009-05-22 00:17:17 +00:00
|
|
|
*
|
2019-06-06 05:28:23 +00:00
|
|
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
2009-05-22 00:17:17 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2009-05-22 00:17:17 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2009-05-22 00:17:17 +00:00
|
|
|
*/
|
|
|
|
|
2016-04-29 03:55:42 +00:00
|
|
|
#include "sed-prv.h"
|
|
|
|
#include "../cmn/mem-prv.h"
|
2009-05-22 00:17:17 +00:00
|
|
|
|
2019-06-25 01:21:00 +00:00
|
|
|
const qse_char_t* qse_sed_dflerrstr (qse_sed_t* sed, qse_sed_errnum_t errnum)
|
2009-06-23 07:01:28 +00:00
|
|
|
{
|
|
|
|
static const qse_char_t* errstr[] =
|
|
|
|
{
|
|
|
|
QSE_T("no error"),
|
2012-09-05 10:40:58 +00:00
|
|
|
QSE_T("other error"),
|
2012-08-09 10:23:32 +00:00
|
|
|
QSE_T("not implemented"),
|
2012-09-05 10:40:58 +00:00
|
|
|
QSE_T("subsystem error"),
|
|
|
|
QSE_T("internal error that should never have happened"),
|
2011-09-27 22:51:26 +00:00
|
|
|
|
2009-06-23 07:01:28 +00:00
|
|
|
QSE_T("insufficient memory"),
|
2011-09-18 09:41:26 +00:00
|
|
|
QSE_T("invalid parameter or data"),
|
2009-06-23 07:01:28 +00:00
|
|
|
QSE_T("command '${0}' not recognized"),
|
|
|
|
QSE_T("command code missing"),
|
|
|
|
QSE_T("command '${0}' incomplete"),
|
|
|
|
QSE_T("regular expression '${0}' incomplete"),
|
|
|
|
QSE_T("failed to compile regular expression '${0}'"),
|
|
|
|
QSE_T("failed to match regular expression"),
|
|
|
|
QSE_T("address 1 prohibited for '${0}'"),
|
2011-09-08 09:36:08 +00:00
|
|
|
QSE_T("address 1 missing or invalid"),
|
2009-06-23 07:01:28 +00:00
|
|
|
QSE_T("address 2 prohibited for '${0}'"),
|
|
|
|
QSE_T("address 2 missing or invalid"),
|
|
|
|
QSE_T("newline expected"),
|
|
|
|
QSE_T("backslash expected"),
|
|
|
|
QSE_T("backslash used as delimiter"),
|
|
|
|
QSE_T("garbage after backslash"),
|
|
|
|
QSE_T("semicolon expected"),
|
|
|
|
QSE_T("empty label name"),
|
|
|
|
QSE_T("duplicate label name '${0}'"),
|
|
|
|
QSE_T("label '${0}' not found"),
|
|
|
|
QSE_T("empty file name"),
|
|
|
|
QSE_T("illegal file name"),
|
|
|
|
QSE_T("strings in translation set not the same length"),
|
|
|
|
QSE_T("group brackets not balanced"),
|
|
|
|
QSE_T("group nesting too deep"),
|
|
|
|
QSE_T("multiple occurrence specifiers"),
|
|
|
|
QSE_T("occurrence specifier zero"),
|
|
|
|
QSE_T("occurrence specifier too large"),
|
2011-09-07 08:18:36 +00:00
|
|
|
QSE_T("no previous regular expression"),
|
2012-08-19 14:20:05 +00:00
|
|
|
QSE_T("cut selector not valid"),
|
2011-09-07 08:18:36 +00:00
|
|
|
QSE_T("I/O error with file '${0}'"),
|
|
|
|
QSE_T("error returned by user I/O handler")
|
2009-06-23 07:01:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (errnum >= 0 && errnum < QSE_COUNTOF(errstr))?
|
|
|
|
errstr[errnum]: QSE_T("unknown error");
|
|
|
|
}
|
|
|
|
|
2019-06-25 01:21:00 +00:00
|
|
|
qse_sed_errstr_t qse_sed_geterrstr (qse_sed_t* sed)
|
2009-05-22 00:17:17 +00:00
|
|
|
{
|
2009-05-28 07:55:17 +00:00
|
|
|
return sed->errstr;
|
2009-05-22 00:17:17 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 07:55:17 +00:00
|
|
|
void qse_sed_seterrstr (qse_sed_t* sed, qse_sed_errstr_t errstr)
|
2009-05-22 00:17:17 +00:00
|
|
|
{
|
2009-05-28 07:55:17 +00:00
|
|
|
sed->errstr = errstr;
|
2009-05-22 00:17:17 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 01:21:00 +00:00
|
|
|
qse_sed_errnum_t qse_sed_geterrnum (qse_sed_t* sed)
|
2009-05-22 00:17:17 +00:00
|
|
|
{
|
|
|
|
return sed->errnum;
|
|
|
|
}
|
|
|
|
|
2019-06-25 01:21:00 +00:00
|
|
|
const qse_sed_loc_t* qse_sed_geterrloc (qse_sed_t* sed)
|
2009-05-22 00:17:17 +00:00
|
|
|
{
|
2009-08-26 21:03:51 +00:00
|
|
|
return &sed->errloc;
|
2009-05-22 00:17:17 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 01:21:00 +00:00
|
|
|
const qse_char_t* qse_sed_geterrmsg (qse_sed_t* sed)
|
2009-05-22 00:17:17 +00:00
|
|
|
{
|
2009-05-28 07:55:17 +00:00
|
|
|
return (sed->errmsg[0] == QSE_T('\0'))?
|
|
|
|
qse_sed_geterrstr(sed)(sed,sed->errnum): sed->errmsg;
|
2009-05-22 00:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qse_sed_geterror (
|
2019-06-25 01:21:00 +00:00
|
|
|
qse_sed_t* sed, qse_sed_errnum_t* errnum,
|
2009-08-26 21:03:51 +00:00
|
|
|
const qse_char_t** errmsg, qse_sed_loc_t* errloc)
|
2009-05-22 00:17:17 +00:00
|
|
|
{
|
|
|
|
if (errnum != QSE_NULL) *errnum = sed->errnum;
|
|
|
|
if (errmsg != QSE_NULL)
|
|
|
|
{
|
|
|
|
*errmsg = (sed->errmsg[0] == QSE_T('\0'))?
|
2009-05-28 07:55:17 +00:00
|
|
|
qse_sed_geterrstr(sed)(sed,sed->errnum):
|
2009-05-22 00:17:17 +00:00
|
|
|
sed->errmsg;
|
|
|
|
}
|
2009-08-26 21:03:51 +00:00
|
|
|
if (errloc != QSE_NULL) *errloc = sed->errloc;
|
2009-05-22 00:17:17 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 06:10:30 +00:00
|
|
|
void qse_sed_seterrnum (
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_sed_t* sed, qse_sed_errnum_t errnum, const qse_cstr_t* errarg)
|
2009-05-22 00:17:17 +00:00
|
|
|
{
|
2009-08-26 21:03:51 +00:00
|
|
|
qse_sed_seterror (sed, errnum, errarg, QSE_NULL);
|
2009-05-22 00:17:17 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 07:55:17 +00:00
|
|
|
void qse_sed_seterrmsg (
|
|
|
|
qse_sed_t* sed, qse_sed_errnum_t errnum,
|
2009-08-26 21:03:51 +00:00
|
|
|
const qse_char_t* errmsg, const qse_sed_loc_t* errloc)
|
2009-05-22 00:17:17 +00:00
|
|
|
{
|
|
|
|
sed->errnum = errnum;
|
|
|
|
qse_strxcpy (sed->errmsg, QSE_COUNTOF(sed->errmsg), errmsg);
|
2009-08-26 21:03:51 +00:00
|
|
|
if (errloc != QSE_NULL) sed->errloc = *errloc;
|
|
|
|
else QSE_MEMSET (&sed->errloc, 0, QSE_SIZEOF(sed->errloc));
|
2009-05-22 00:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qse_sed_seterror (
|
2009-05-28 07:55:17 +00:00
|
|
|
qse_sed_t* sed, qse_sed_errnum_t errnum,
|
2014-07-08 14:30:42 +00:00
|
|
|
const qse_cstr_t* errarg, const qse_sed_loc_t* errloc)
|
2009-05-22 00:17:17 +00:00
|
|
|
{
|
|
|
|
const qse_char_t* errfmt;
|
|
|
|
|
|
|
|
sed->errnum = errnum;
|
|
|
|
|
2009-05-28 07:55:17 +00:00
|
|
|
errfmt = qse_sed_geterrstr(sed)(sed,sed->errnum);
|
2009-05-22 00:17:17 +00:00
|
|
|
QSE_ASSERT (errfmt != QSE_NULL);
|
|
|
|
qse_strxfncpy (sed->errmsg, QSE_COUNTOF(sed->errmsg), errfmt, errarg);
|
2009-08-26 21:03:51 +00:00
|
|
|
|
|
|
|
if (errloc != QSE_NULL) sed->errloc = *errloc;
|
|
|
|
else QSE_MEMSET (&sed->errloc, 0, QSE_SIZEOF(sed->errloc));
|
2009-05-22 00:17:17 +00:00
|
|
|
}
|
|
|
|
|