removed qse_ccls_t and related functions and added qse_strtrm()
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.cpp 90 2009-03-01 09:58:19Z hyunghwan.chung $
|
||||
* $Id: Awk.cpp 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -1192,8 +1192,6 @@ int Awk::open ()
|
||||
qse_awk_prm_t prm;
|
||||
prm.pow = pow;
|
||||
prm.sprintf = sprintf;
|
||||
prm.isccls = isType;
|
||||
prm.toccls = transCase;
|
||||
|
||||
awk = qse_awk_open (&mmgr, QSE_SIZEOF(xtn_t), &prm);
|
||||
if (awk == QSE_NULL)
|
||||
@ -1771,18 +1769,6 @@ void Awk::freeMem (void* data, void* ptr)
|
||||
((Awk*)data)->freeMem (ptr);
|
||||
}
|
||||
|
||||
Awk::bool_t Awk::isType (awk_t* awk, cint_t c, qse_ccls_id_t type)
|
||||
{
|
||||
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
|
||||
return xtn->awk->isType (c, (ccls_id_t)type);
|
||||
}
|
||||
|
||||
Awk::cint_t Awk::transCase (awk_t* awk, cint_t c, qse_ccls_id_t type)
|
||||
{
|
||||
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
|
||||
return xtn->awk->transCase (c, (ccls_id_t)type);
|
||||
}
|
||||
|
||||
Awk::real_t Awk::pow (awk_t* awk, real_t x, real_t y)
|
||||
{
|
||||
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: StdAwk.cpp 75 2009-02-22 14:10:34Z hyunghwan.chung $
|
||||
* $Id: StdAwk.cpp 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -411,17 +411,6 @@ void StdAwk::freeMem (void* ptr)
|
||||
::free (ptr);
|
||||
}
|
||||
|
||||
// character handling primitive
|
||||
Awk::bool_t StdAwk::isType (cint_t c, ccls_id_t type)
|
||||
{
|
||||
return qse_ccls_is (c, (qse_ccls_id_t)type);
|
||||
}
|
||||
|
||||
Awk::cint_t StdAwk::transCase (cint_t c, ccls_id_t type)
|
||||
{
|
||||
return qse_ccls_to (c, (qse_ccls_id_t)type);
|
||||
}
|
||||
|
||||
// miscellaneous primitive
|
||||
StdAwk::real_t StdAwk::pow (real_t x, real_t y)
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c 89 2009-02-28 15:27:03Z hyunghwan.chung $
|
||||
* $Id: awk.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -80,24 +80,15 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
|
||||
QSE_ASSERT (prm != QSE_NULL);
|
||||
QSE_ASSERT (prm->pow != QSE_NULL);
|
||||
QSE_ASSERT (prm->sprintf != QSE_NULL);
|
||||
QSE_ASSERT (prm->isccls != QSE_NULL);
|
||||
QSE_ASSERT (prm->toccls != QSE_NULL);
|
||||
if (prm == QSE_NULL ||
|
||||
prm->pow == QSE_NULL ||
|
||||
prm->sprintf == QSE_NULL ||
|
||||
prm->isccls == QSE_NULL ||
|
||||
prm->toccls == QSE_NULL)
|
||||
prm->sprintf == QSE_NULL)
|
||||
{
|
||||
QSE_AWK_FREE (awk, awk);
|
||||
return QSE_NULL;
|
||||
}
|
||||
awk->prm = *prm;
|
||||
|
||||
/* build a character classifier from the primitive functions */
|
||||
awk->ccls.is = (qse_ccls_is_t) prm->isccls;
|
||||
awk->ccls.to = (qse_ccls_to_t) prm->toccls;
|
||||
awk->ccls.data = awk;
|
||||
|
||||
awk->token.name = qse_str_open (mmgr, 0, 128);
|
||||
if (awk->token.name == QSE_NULL) goto oops;
|
||||
|
||||
@ -358,11 +349,6 @@ qse_awk_prm_t* qse_awk_getprm (qse_awk_t* awk)
|
||||
return &awk->prm;
|
||||
}
|
||||
|
||||
qse_ccls_t* qse_awk_getccls (qse_awk_t* awk)
|
||||
{
|
||||
return &awk->ccls;
|
||||
}
|
||||
|
||||
int qse_awk_getoption (qse_awk_t* awk)
|
||||
{
|
||||
return awk->option;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h 75 2009-02-22 14:10:34Z hyunghwan.chung $
|
||||
* $Id: awk.h 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
#define _QSE_LIB_AWK_AWK_H_
|
||||
|
||||
#include "../cmn/mem.h"
|
||||
#include "../cmn/chr.h"
|
||||
#include <qse/cmn/chr.h>
|
||||
#include <qse/cmn/str.h>
|
||||
#include <qse/cmn/map.h>
|
||||
#include <qse/cmn/lda.h>
|
||||
@ -30,6 +30,7 @@ typedef struct qse_awk_chain_t qse_awk_chain_t;
|
||||
typedef struct qse_awk_tree_t qse_awk_tree_t;
|
||||
|
||||
#include <qse/awk/awk.h>
|
||||
#include <qse/cmn/chr.h>
|
||||
#include "tree.h"
|
||||
#include "fnc.h"
|
||||
#include "parse.h"
|
||||
@ -46,19 +47,19 @@ typedef struct qse_awk_tree_t qse_awk_tree_t;
|
||||
#define QSE_AWK_REALLOC(awk,ptr,size) QSE_MMGR_REALLOC((awk)->mmgr,ptr,size)
|
||||
#define QSE_AWK_FREE(awk,ptr) QSE_MMGR_FREE((awk)->mmgr,ptr)
|
||||
|
||||
#define QSE_AWK_ISUPPER(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_UPPER)
|
||||
#define QSE_AWK_ISLOWER(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_UPPER)
|
||||
#define QSE_AWK_ISALPHA(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_ALPHA)
|
||||
#define QSE_AWK_ISDIGIT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_DIGIT)
|
||||
#define QSE_AWK_ISXDIGIT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_XDIGIT)
|
||||
#define QSE_AWK_ISALNUM(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_ALNUM)
|
||||
#define QSE_AWK_ISSPACE(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_SPACE)
|
||||
#define QSE_AWK_ISPRINT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_PRINT)
|
||||
#define QSE_AWK_ISGRAPH(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_GRAPH)
|
||||
#define QSE_AWK_ISCNTRL(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_CNTRL)
|
||||
#define QSE_AWK_ISPUNCT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_PUNCT)
|
||||
#define QSE_AWK_TOUPPER(awk,c) awk->prm.toccls(awk,c,QSE_CCLS_UPPER)
|
||||
#define QSE_AWK_TOLOWER(awk,c) awk->prm.toccls(awk,c,QSE_CCLS_LOWER)
|
||||
#define QSE_AWK_ISUPPER(awk,c) QSE_ISUPPER(c)
|
||||
#define QSE_AWK_ISLOWER(awk,c) QSE_ISLOWER(c)
|
||||
#define QSE_AWK_ISALPHA(awk,c) QSE_ISALPHA(c)
|
||||
#define QSE_AWK_ISDIGIT(awk,c) QSE_ISDIGIT(c)
|
||||
#define QSE_AWK_ISXDIGIT(awk,c) QSE_ISXDIGIT(c)
|
||||
#define QSE_AWK_ISALNUM(awk,c) QSE_ISALNUM(c)
|
||||
#define QSE_AWK_ISSPACE(awk,c) QSE_ISSPACE(c)
|
||||
#define QSE_AWK_ISPRINT(awk,c) QSE_ISPRINT(c)
|
||||
#define QSE_AWK_ISGRAPH(awk,c) QSE_ISGRAPH(c)
|
||||
#define QSE_AWK_ISCNTRL(awk,c) QSE_ISCNTRL(c)
|
||||
#define QSE_AWK_ISPUNCT(awk,c) QSE_ISPUNCT(c)
|
||||
#define QSE_AWK_TOUPPER(awk,c) QSE_TOUPPER(c)
|
||||
#define QSE_AWK_TOLOWER(awk,c) QSE_TOLOWER(c)
|
||||
|
||||
#define QSE_AWK_STRDUP(awk,str) (qse_strdup(str,(awk)->mmgr))
|
||||
#define QSE_AWK_STRXDUP(awk,str,len) (qse_strxdup(str,len,(awk)->mmgr))
|
||||
@ -91,11 +92,6 @@ struct qse_awk_t
|
||||
/* primitive functions */
|
||||
qse_awk_prm_t prm;
|
||||
|
||||
/* character classifier composed from primitive functions.
|
||||
* it is used in calling some functions that require a character
|
||||
* classifier */
|
||||
qse_ccls_t ccls;
|
||||
|
||||
/* options */
|
||||
int option;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: misc.c 89 2009-02-28 15:27:03Z hyunghwan.chung $
|
||||
* $Id: misc.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -961,7 +961,7 @@ int qse_awk_matchrex (
|
||||
int err, x;
|
||||
|
||||
x = qse_matchrex (
|
||||
awk->mmgr, &awk->ccls, awk->rex.depth.max.match,
|
||||
awk->mmgr, awk->rex.depth.max.match,
|
||||
code, option, str, len, match_ptr, match_len, &err);
|
||||
if (x < 0) *errnum = QSE_AWK_REXERRTOERR(err);
|
||||
return x;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: run.c 92 2009-03-02 03:34:43Z hyunghwan.chung $
|
||||
* $Id: run.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -641,8 +641,6 @@ qse_awk_rtx_t* qse_awk_rtx_open (
|
||||
|
||||
QSE_ASSERTX (awk->prm.pow != QSE_NULL, "Call qse_awk_setprm() first");
|
||||
QSE_ASSERTX (awk->prm.sprintf != QSE_NULL, "Call qse_awk_setprm() first");
|
||||
QSE_ASSERTX (awk->prm.isccls != QSE_NULL, "Call qse_awk_setprm() first");
|
||||
QSE_ASSERTX (awk->prm.toccls != QSE_NULL, "Call qse_awk_setprm() first");
|
||||
|
||||
/* clear the awk error code */
|
||||
qse_awk_seterror (awk, QSE_AWK_ENOERR, 0, QSE_NULL);
|
||||
@ -1354,7 +1352,7 @@ static int run_bpae_loop (qse_awk_rtx_t* rtx)
|
||||
if (ret == -1 && rtx->errnum == QSE_AWK_ENOERR)
|
||||
{
|
||||
/* an error is returned with no error number set.
|
||||
* this feature is used by eval_expression to
|
||||
* this feature is used by eval_expression() to
|
||||
* abort the evaluation when exit() is executed
|
||||
* during function evaluation */
|
||||
ret = 0;
|
||||
@ -1374,7 +1372,7 @@ static int run_bpae_loop (qse_awk_rtx_t* rtx)
|
||||
if (ret == -1 && rtx->errnum == QSE_AWK_ENOERR)
|
||||
{
|
||||
/* an error is returned with no error number set.
|
||||
* this feature is used by eval_expression to
|
||||
* this feature is used by eval_expression() to
|
||||
* abort the evaluation when exit() is executed
|
||||
* during function evaluation */
|
||||
ret = 0;
|
||||
@ -1407,7 +1405,7 @@ static int run_bpae_loop (qse_awk_rtx_t* rtx)
|
||||
if (ret == -1 && rtx->errnum == QSE_AWK_ENOERR)
|
||||
{
|
||||
/* an error is returned with no error number set.
|
||||
* this feature is used by eval_expression to
|
||||
* this feature is used by eval_expression() to
|
||||
* abort the evaluation when exit() is executed
|
||||
* during function evaluation */
|
||||
ret = 0;
|
||||
@ -1556,55 +1554,8 @@ qse_awk_val_t* qse_awk_rtx_call (
|
||||
}
|
||||
|
||||
/* return the return value with its reference count at least 1.
|
||||
* the caller of this function should reference-count it down. */
|
||||
* the caller of this function should count down its reference. */
|
||||
return v;
|
||||
|
||||
|
||||
#if 0
|
||||
if (v == QSE_NULL)
|
||||
{
|
||||
/* an error occurred. but this might have been
|
||||
* caused by exit(). so let's check it */
|
||||
|
||||
if (crdata.val == QSE_NULL)
|
||||
{
|
||||
/* no return value has been caputured. this must
|
||||
* be an error */
|
||||
QSE_ASSERT (rtx->errnum != QSE_AWK_ENOERR);
|
||||
v = qse_awk_val_nil; /* defaults to nil */
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rtx->errnum == QSE_AWK_ENOERR)
|
||||
{
|
||||
/* exiting with exit() */
|
||||
v = crdata.val;
|
||||
/* no need to ref-up as it is done in
|
||||
* capture_retval_on_exit() */
|
||||
}
|
||||
else
|
||||
{
|
||||
v = qse_awk_val_nil; /* defaults to nil */
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the return value captured in termination by exit()
|
||||
* is reference-counted up in capture_retval_on_exit().
|
||||
* let's do the same thing for the return value normally
|
||||
* returned. */
|
||||
qse_awk_rtx_refupval (rtx, v);
|
||||
}
|
||||
|
||||
if (rtx->rcb.on_exit != QSE_NULL)
|
||||
rtx->rcb.on_exit (rtx, v, rtx->rcb.data);
|
||||
|
||||
qse_awk_rtx_refdownval (rtx, v);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int run_pattern_blocks (qse_awk_rtx_t* run)
|
||||
@ -2376,7 +2327,7 @@ static int run_exit (qse_awk_rtx_t* run, qse_awk_nde_exit_t* nde)
|
||||
if (val == QSE_NULL) return -1;
|
||||
|
||||
qse_awk_rtx_refdownval (run, STACK_RETVAL_GBL(run));
|
||||
STACK_RETVAL_GBL(run) = val; /* gbl return value */
|
||||
STACK_RETVAL_GBL(run) = val; /* global return value */
|
||||
|
||||
qse_awk_rtx_refupval (run, val);
|
||||
}
|
||||
@ -4099,8 +4050,7 @@ static int __cmp_int_str (
|
||||
out.u.cpldup.ptr,
|
||||
out.u.cpldup.len,
|
||||
((qse_awk_val_str_t*)right)->ptr,
|
||||
((qse_awk_val_str_t*)right)->len,
|
||||
&run->awk->ccls
|
||||
((qse_awk_val_str_t*)right)->len
|
||||
);
|
||||
}
|
||||
else
|
||||
@ -4177,8 +4127,7 @@ static int __cmp_real_str (
|
||||
out.u.cpldup.ptr,
|
||||
out.u.cpldup.len,
|
||||
((qse_awk_val_str_t*)right)->ptr,
|
||||
((qse_awk_val_str_t*)right)->len,
|
||||
&run->awk->ccls
|
||||
((qse_awk_val_str_t*)right)->len
|
||||
);
|
||||
}
|
||||
else
|
||||
@ -4224,14 +4173,11 @@ static int __cmp_str_str (
|
||||
|
||||
if (run->gbl.ignorecase)
|
||||
{
|
||||
n = qse_strxncasecmp (
|
||||
ls->ptr, ls->len, rs->ptr, rs->len,
|
||||
&run->awk->ccls);
|
||||
n = qse_strxncasecmp (ls->ptr, ls->len, rs->ptr, rs->len);
|
||||
}
|
||||
else
|
||||
{
|
||||
n = qse_strxncmp (
|
||||
ls->ptr, ls->len, rs->ptr, rs->len);
|
||||
n = qse_strxncmp (ls->ptr, ls->len, rs->ptr, rs->len);
|
||||
}
|
||||
|
||||
return n;
|
||||
@ -5579,10 +5525,8 @@ static qse_awk_val_t* __eval_call (
|
||||
* ---------------------
|
||||
*/
|
||||
|
||||
QSE_ASSERT (
|
||||
QSE_SIZEOF(void*) >= QSE_SIZEOF(run->stack_top));
|
||||
QSE_ASSERT (
|
||||
QSE_SIZEOF(void*) >= QSE_SIZEOF(run->stack_base));
|
||||
QSE_ASSERT (QSE_SIZEOF(void*) >= QSE_SIZEOF(run->stack_top));
|
||||
QSE_ASSERT (QSE_SIZEOF(void*) >= QSE_SIZEOF(run->stack_base));
|
||||
|
||||
saved_stack_top = run->stack_top;
|
||||
|
||||
@ -5729,11 +5673,29 @@ static qse_awk_val_t* __eval_call (
|
||||
v = STACK_RETVAL(run);
|
||||
if (n == -1)
|
||||
{
|
||||
if (errhandler != QSE_NULL)
|
||||
if (run->errnum == QSE_AWK_ENOERR && errhandler != QSE_NULL)
|
||||
{
|
||||
/* capture_retval_on_exit takes advantage of
|
||||
* this handler to retrieve the return value
|
||||
* when exit() is used to terminate the program. */
|
||||
/* errhandler is passed only when __eval_call() is
|
||||
* invoked from qse_awk_rtx_call(). Under this
|
||||
* circumstance, this stack frame is the first
|
||||
* activated and the stack base is the first element
|
||||
* after the global variables. so STACK_RETVAL(run)
|
||||
* effectively becomes STACK_RETVAL_GBL(run).
|
||||
* As __eval_call() returns QSE_NULL on error and
|
||||
* the reference count of STACK_RETVAL(run) should be
|
||||
* decremented, it can't get the return value
|
||||
* if it turns out to be terminated by exit().
|
||||
* The return value could be destroyed by then.
|
||||
* Unlikely, run_bpae_loop() just checks if run->errnum
|
||||
* is QSE_AWK_ENOERR and gets STACK_RETVAL_GBL(run)
|
||||
* to determine if it is terminated by exit().
|
||||
*
|
||||
* The handler capture_retval_on_exit()
|
||||
* increments the reference of STACK_RETVAL(run)
|
||||
* and stores the pointer into accompanying space.
|
||||
* This way, the return value is preserved upon
|
||||
* termination by exit() out to the caller.
|
||||
*/
|
||||
errhandler (eharg);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: std.c 90 2009-03-01 09:58:19Z hyunghwan.chung $
|
||||
* $Id: std.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -122,20 +122,6 @@ static int custom_awk_sprintf (
|
||||
return n;
|
||||
}
|
||||
|
||||
static qse_bool_t custom_awk_isccls (
|
||||
qse_awk_t* awk, qse_cint_t c, qse_ccls_id_t id)
|
||||
{
|
||||
qse_ccls_t* ccls = QSE_CCLS_GETDFL();
|
||||
return ccls->is (ccls->data, c, id);
|
||||
}
|
||||
|
||||
static qse_cint_t custom_awk_toccls (
|
||||
qse_awk_t* awk, qse_cint_t c, qse_ccls_id_t id)
|
||||
{
|
||||
qse_ccls_t* ccls = QSE_CCLS_GETDFL();
|
||||
return ccls->to (ccls->data, c, id);
|
||||
}
|
||||
|
||||
static int add_functions (qse_awk_t* awk);
|
||||
|
||||
qse_awk_t* qse_awk_openstd (qse_size_t xtnsize)
|
||||
@ -146,8 +132,6 @@ qse_awk_t* qse_awk_openstd (qse_size_t xtnsize)
|
||||
|
||||
prm.pow = custom_awk_pow;
|
||||
prm.sprintf = custom_awk_sprintf;
|
||||
prm.isccls = custom_awk_isccls;
|
||||
prm.toccls = custom_awk_toccls;
|
||||
|
||||
/* create an object */
|
||||
awk = qse_awk_open (
|
||||
|
Reference in New Issue
Block a user