qse/ase/lsp/err.c

125 lines
2.2 KiB
C
Raw Normal View History

2006-10-23 10:57:59 +00:00
/*
2007-02-11 07:36:55 +00:00
* $Id: err.c,v 1.11 2007-02-11 07:36:54 bacon Exp $
2007-02-03 10:52:36 +00:00
*
* {License}
2006-10-23 10:57:59 +00:00
*/
2006-10-25 13:42:31 +00:00
#include <ase/lsp/lsp_i.h>
2006-10-23 10:57:59 +00:00
2007-02-11 07:36:55 +00:00
static const ase_char_t* __geterrstr (int errnum)
2006-10-23 10:57:59 +00:00
{
2006-10-29 13:00:39 +00:00
static const ase_char_t* __errstr[] =
{
ASE_T("no error"),
ASE_T("out of memory"),
2006-10-29 13:40:33 +00:00
ASE_T("exit"),
2007-02-10 13:52:41 +00:00
ASE_T("end of source"),
ASE_T("unexpected end of string"),
2006-10-29 13:00:39 +00:00
ASE_T("input not attached"),
ASE_T("input"),
ASE_T("output not attached"),
ASE_T("output"),
ASE_T("syntax"),
2007-02-11 07:36:55 +00:00
ASE_T("right parenthesis expected"),
2006-10-29 13:00:39 +00:00
ASE_T("bad arguments"),
ASE_T("too few arguments"),
ASE_T("too many arguments"),
2007-02-11 07:36:55 +00:00
ASE_T("undefined function '%s'"),
2006-10-29 13:00:39 +00:00
ASE_T("bad function"),
ASE_T("duplicate formal"),
ASE_T("bad symbol"),
2007-02-11 07:36:55 +00:00
ASE_T("undefined symbol '%s'"),
2006-10-29 13:00:39 +00:00
ASE_T("empty body"),
ASE_T("bad value"),
ASE_T("divide by zero")
};
2006-11-29 02:54:17 +00:00
if (errnum >= 0 && errnum < ASE_COUNTOF(__errstr))
2006-10-23 10:57:59 +00:00
{
return __errstr[errnum];
}
2006-10-24 04:22:40 +00:00
return ASE_T("unknown error");
2006-10-23 10:57:59 +00:00
}
2007-02-11 07:36:55 +00:00
void ase_lsp_geterror (
ase_lsp_t* lsp, int* errnum, const ase_char_t** errmsg)
{
if (errnum != ASE_NULL) *errnum = lsp->errnum;
if (errmsg != ASE_NULL) *errmsg = lsp->errmsg;
}
void ase_lsp_seterror (
ase_lsp_t* lsp, int errnum,
const ase_char_t** errarg, ase_size_t argcnt)
{
const ase_char_t* errfmt;
ASE_LSP_ASSERT (lsp, argcnt <= 5);
lsp->errnum = errnum;
errfmt = __geterrstr (errnum);
switch (argcnt)
{
case 0:
lsp->prmfns.sprintf (
lsp->errmsg,
ASE_COUNTOF(lsp->errmsg),
errfmt);
return;
case 1:
lsp->prmfns.sprintf (
lsp->errmsg,
ASE_COUNTOF(lsp->errmsg),
errfmt,
errarg[0]);
return;
case 2:
lsp->prmfns.sprintf (
lsp->errmsg,
ASE_COUNTOF(lsp->errmsg),
errfmt,
errarg[0],
errarg[1]);
return;
case 3:
lsp->prmfns.sprintf (
lsp->errmsg,
ASE_COUNTOF(lsp->errmsg),
errfmt,
errarg[0],
errarg[1],
errarg[2]);
return;
case 4:
lsp->prmfns.sprintf (
lsp->errmsg,
ASE_COUNTOF(lsp->errmsg),
errfmt,
errarg[0],
errarg[1],
errarg[2],
errarg[3]);
return;
case 5:
lsp->prmfns.sprintf (
lsp->errmsg,
ASE_COUNTOF(lsp->errmsg),
errfmt,
errarg[0],
errarg[1],
errarg[2],
errarg[3],
errarg[4]);
return;
}
}