removed qse_ccls_t and related functions and added qse_strtrm()

This commit is contained in:
2009-05-08 07:15:04 +00:00
parent 4896b3d82c
commit c221321cda
31 changed files with 372 additions and 609 deletions

View File

@ -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);

View File

@ -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)
{

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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 (

View File

@ -1,5 +1,5 @@
/*
* $Id: chr.c 76 2009-02-22 14:18:06Z hyunghwan.chung $
* $Id: chr.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -136,22 +136,4 @@ qse_cint_t qse_ccls_to (qse_cint_t c, qse_ccls_id_t type)
#error unsupported character type
#endif
static qse_bool_t ccls_is (void* data, qse_cint_t c, qse_ccls_id_t type)
{
return qse_ccls_is (c, type);
}
static qse_cint_t ccls_to (void* data, qse_cint_t c, qse_ccls_id_t type)
{
return qse_ccls_to (c, type);
}
static qse_ccls_t ccls =
{
ccls_is,
ccls_to,
QSE_NULL
};
qse_ccls_t* qse_ccls = &ccls;

View File

@ -1,82 +0,0 @@
/*
* $Id: chr.h 97 2009-03-10 10:39:18Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _QSE_LIB_CMN_CHR_H_
#define _QSE_LIB_CMN_CHR_H_
#include <qse/cmn/chr.h>
#ifdef USE_STDC
#if defined(QSE_CHAR_IS_MCHAR)
#include <ctype.h>
#define QSE_ISUPPER(c) isupper(c)
#define QSE_ISLOWER(c) islower(c)
#define QSE_ISALPHA(c) isalpha(c)
#define QSE_ISDIGIT(c) isdigit(c)
#define QSE_ISXDIGIT(c) isxdigit(c)
#define QSE_ISALNUM(c) isalnum(c)
#define QSE_ISSPACE(c) isspace(c)
#define QSE_ISPRINT(c) isprint(c)
#define QSE_ISGRAPH(c) isgraph(c)
#define QSE_ISCNTRL(c) iscntrl(c)
#define QSE_ISPUNCT(c) ispunct(c)
#define QSE_TOUPPER(c) toupper(c)
#define QSE_TOLOWER(c) tolower(c)
#elif defined(QSE_CHAR_IS_WCHAR)
#include <wctype.h>
#define QSE_ISUPPER(c) iswupper(c)
#define QSE_ISLOWER(c) iswlower(c)
#define QSE_ISALPHA(c) iswalpha(c)
#define QSE_ISDIGIT(c) iswdigit(c)
#define QSE_ISXDIGIT(c) iswxdigit(c)
#define QSE_ISALNUM(c) iswalnum(c)
#define QSE_ISSPACE(c) iswspace(c)
#define QSE_ISPRINT(c) iswprint(c)
#define QSE_ISGRAPH(c) iswgraph(c)
#define QSE_ISCNTRL(c) iswcntrl(c)
#define QSE_ISPUNCT(c) iswpunct(c)
#define QSE_TOUPPER(c) towupper(c)
#define QSE_TOLOWER(c) towlower(c)
#else
#error Unsupported character type
#endif
#else
#define QSE_ISUPPER(c) (qse_ccls_is(c,QSE_CCLS_UPPER))
#define QSE_ISLOWER(c) (qse_ccls_is(c,QSE_CCLS_LOWER))
#define QSE_ISALPHA(c) (qse_ccls_is(c,QSE_CCLS_ALPHA))
#define QSE_ISDIGIT(c) (qse_ccls_is(c,QSE_CCLS_DIGIT))
#define QSE_ISXDIGIT(c) (qse_ccls_is(c,QSE_CCLS_XDIGIT))
#define QSE_ISALNUM(c) (qse_ccls_is(c,QSE_CCLS_ALNUM))
#define QSE_ISSPACE(c) (qse_ccls_is(c,QSE_CCLS_SPACE))
#define QSE_ISPRINT(c) (qse_ccls_is(c,QSE_CCLS_PRINT))
#define QSE_ISGRAPH(c) (qse_ccls_is(c,QSE_CCLS_GRAPH))
#define QSE_ISCNTRL(c) (qse_ccls_is(c,QSE_CCLS_CNTRL))
#define QSE_ISPUNCT(c) (qse_ccls_is(c,QSE_CCLS_PUNCT))
#define QSE_TOUPPER(c) (qse_ccls_to(c,QSE_CCLS_UPPER))
#define QSE_TOLOWER(c) (qse_ccls_to(c,QSE_CCLS_LOWER))
#endif
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: rex.c 76 2009-02-22 14:18:06Z hyunghwan.chung $
* $Id: rex.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -17,8 +17,8 @@
*/
#include <qse/cmn/rex.h>
#include <qse/cmn/chr.h>
#include "mem.h"
#include "chr.h"
#ifdef DEBUG_REX
#include <qse/bas/sio.h>
@ -113,7 +113,6 @@ struct builder_t
struct matcher_t
{
qse_mmgr_t* mmgr;
qse_ccls_t* ccls;
struct
{
@ -230,18 +229,66 @@ static const qse_byte_t* match_occurrences (
static qse_bool_t __test_charset (
matcher_t* matcher, const qse_byte_t* p, qse_size_t csc, qse_char_t c);
static qse_bool_t cc_isalnum (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_isalpha (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_isblank (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_iscntrl (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_isdigit (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_isgraph (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_islower (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_isprint (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_ispunct (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_isspace (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_isupper (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_isxdigit (qse_ccls_t* ccls, qse_char_t c);
static qse_bool_t cc_isalnum (qse_char_t c)
{
return QSE_ISALNUM (c);
}
static qse_bool_t cc_isalpha (qse_char_t c)
{
return QSE_ISALPHA (c);
}
static qse_bool_t cc_isblank (qse_char_t c)
{
return c == QSE_T(' ') || c == QSE_T('\t');
}
static qse_bool_t cc_iscntrl (qse_char_t c)
{
return QSE_ISCNTRL (c);
}
static qse_bool_t cc_isdigit (qse_char_t c)
{
return QSE_ISDIGIT (c);
}
static qse_bool_t cc_isgraph (qse_char_t c)
{
return QSE_ISGRAPH (c);
}
static qse_bool_t cc_islower (qse_char_t c)
{
return QSE_ISLOWER (c);
}
static qse_bool_t cc_isprint (qse_char_t c)
{
return QSE_ISPRINT (c);
}
static qse_bool_t cc_ispunct (qse_char_t c)
{
return QSE_ISPUNCT (c);
}
static qse_bool_t cc_isspace (qse_char_t c)
{
return QSE_ISSPACE (c);
}
static qse_bool_t cc_isupper (qse_char_t c)
{
return QSE_ISUPPER (c);
}
static qse_bool_t cc_isxdigit (qse_char_t c)
{
return QSE_ISXDIGIT (c);
}
#if 0
XXX
@ -254,7 +301,7 @@ struct __char_class_t
{
const qse_char_t* name;
qse_size_t name_len;
qse_bool_t (*func) (qse_ccls_t* ccls, qse_char_t c);
qse_bool_t (*func) (qse_char_t c);
};
static struct __char_class_t __char_class[] =
@ -349,7 +396,7 @@ void* qse_buildrex (
}
int qse_matchrex (
qse_mmgr_t* mmgr, qse_ccls_t* ccls, qse_size_t depth,
qse_mmgr_t* mmgr, qse_size_t depth,
void* code, int option,
const qse_char_t* str, qse_size_t len,
const qse_char_t** match_ptr, qse_size_t* match_len, int* errnum)
@ -360,7 +407,6 @@ int qse_matchrex (
/*const qse_char_t* match_ptr_zero = QSE_NULL;*/
matcher.mmgr = mmgr;
matcher.ccls = ccls;
/* store the source string */
matcher.match.str.ptr = str;
@ -1393,7 +1439,7 @@ static const qse_byte_t* match_ord_char (
ubound = cp->ubound;
cc = *(qse_char_t*)p; p += QSE_SIZEOF(cc);
if (matcher->ignorecase) cc = QSE_CCLS_TOUPPER(matcher->ccls, cc);
if (matcher->ignorecase) cc = QSE_TOUPPER(cc);
/* merge the same consecutive codes
* for example, a{1,10}a{0,10} is shortened to a{1,20} */
@ -1402,7 +1448,7 @@ static const qse_byte_t* match_ord_char (
while (p < mat->branch_end &&
cp->cmd == ((const code_t*)p)->cmd)
{
if (QSE_CCLS_TOUPPER (matcher->ccls, *(qse_char_t*)(p+QSE_SIZEOF(*cp))) != cc) break;
if (QSE_TOUPPER (*(qse_char_t*)(p+QSE_SIZEOF(*cp))) != cc) break;
lbound += ((const code_t*)p)->lbound;
ubound += ((const code_t*)p)->ubound;
@ -1444,7 +1490,7 @@ static const qse_byte_t* match_ord_char (
QSE_T("match_ord_char: <ignorecase> %c %c\n"),
cc, mat->match_ptr[si]);
#endif
if (cc != QSE_CCLS_TOUPPER (matcher->ccls, mat->match_ptr[si])) break;
if (cc != QSE_TOUPPER (mat->match_ptr[si])) break;
si++;
}
}
@ -1507,7 +1553,7 @@ static const qse_byte_t* match_charset (
if (&mat->match_ptr[si] >= matcher->match.str.end) break;
c = mat->match_ptr[si];
if (matcher->ignorecase) c = QSE_CCLS_TOUPPER(matcher->ccls, c);
if (matcher->ignorecase) c = QSE_TOUPPER(c);
n = __test_charset (matcher, p, cshdr->csc, c);
if (cp->negate) n = !n;
@ -1772,7 +1818,7 @@ static qse_bool_t __test_charset (
{
c1 = *(const qse_char_t*)p;
if (matcher->ignorecase)
c1 = QSE_CCLS_TOUPPER(matcher->ccls, c1);
c1 = QSE_TOUPPER(c1);
#ifdef DEBUG_REX
qse_dprintf (
QSE_T("match_charset: <one> %c %c\n"), c, c1);
@ -1787,8 +1833,8 @@ static qse_bool_t __test_charset (
if (matcher->ignorecase)
{
c1 = QSE_CCLS_TOUPPER(matcher->ccls, c1);
c2 = QSE_CCLS_TOUPPER(matcher->ccls, c2);
c1 = QSE_TOUPPER(c1);
c2 = QSE_TOUPPER(c2);
}
#ifdef DEBUG_REX
qse_dprintf (
@ -1804,8 +1850,7 @@ static qse_bool_t __test_charset (
QSE_T("match_charset: <class> %c %s\n"),
c, __char_class[c1].name);
#endif
if (__char_class[c1].func (
matcher->ccls, c)) return QSE_TRUE;
if (__char_class[c1].func(c)) return QSE_TRUE;
}
else
{
@ -1819,66 +1864,6 @@ static qse_bool_t __test_charset (
return QSE_FALSE;
}
static qse_bool_t cc_isalnum (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISALNUM (ccls, c);
}
static qse_bool_t cc_isalpha (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISALPHA (ccls, c);
}
static qse_bool_t cc_isblank (qse_ccls_t* ccls, qse_char_t c)
{
return c == QSE_T(' ') || c == QSE_T('\t');
}
static qse_bool_t cc_iscntrl (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISCNTRL (ccls, c);
}
static qse_bool_t cc_isdigit (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISDIGIT (ccls, c);
}
static qse_bool_t cc_isgraph (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISGRAPH (ccls, c);
}
static qse_bool_t cc_islower (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISLOWER (ccls, c);
}
static qse_bool_t cc_isprint (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISPRINT (ccls, c);
}
static qse_bool_t cc_ispunct (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISPUNCT (ccls, c);
}
static qse_bool_t cc_isspace (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISSPACE (ccls, c);
}
static qse_bool_t cc_isupper (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISUPPER (ccls, c);
}
static qse_bool_t cc_isxdigit (qse_ccls_t* ccls, qse_char_t c)
{
return QSE_CCLS_ISXDIGIT (ccls, c);
}
#if 0
#define DPRINTF awk->prmfns.misc.dprintf
#define DCUSTOM awk->prmfns.misc.custom_data

View File

@ -1,5 +1,5 @@
/*
* $Id: str_bas.c 76 2009-02-22 14:18:06Z hyunghwan.chung $
* $Id: str_bas.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -17,7 +17,7 @@
*/
#include <qse/cmn/str.h>
#include "chr.h"
#include <qse/cmn/chr.h>
#include "mem.h"
qse_size_t qse_strlen (const qse_char_t* str)
@ -401,21 +401,20 @@ int qse_strxncmp (
return (s2 < end2)? -1: 0;
}
int qse_strcasecmp (
const qse_char_t* s1, const qse_char_t* s2, qse_ccls_t* ccls)
int qse_strcasecmp (const qse_char_t* s1, const qse_char_t* s2)
{
while (QSE_CCLS_TOUPPER(ccls,*s1) == QSE_CCLS_TOUPPER(ccls,*s2))
while (QSE_TOUPPER(*s1) == QSE_TOUPPER(*s2))
{
if (*s1 == QSE_C('\0')) return 0;
s1++, s2++;
}
return (QSE_CCLS_TOUPPER(ccls,*s1) > QSE_CCLS_TOUPPER(ccls,*s2))? 1: -1;
return (QSE_TOUPPER(*s1) > QSE_TOUPPER(*s2))? 1: -1;
}
int qse_strxncasecmp (
const qse_char_t* s1, qse_size_t len1,
const qse_char_t* s2, qse_size_t len2, qse_ccls_t* ccls)
const qse_char_t* s2, qse_size_t len2)
{
qse_char_t c1, c2;
const qse_char_t* end1 = s1 + len1;
@ -423,10 +422,10 @@ int qse_strxncasecmp (
while (s1 < end1)
{
c1 = QSE_CCLS_TOUPPER (ccls, *s1);
c1 = QSE_TOUPPER (*s1);
if (s2 < end2)
{
c2 = QSE_CCLS_TOUPPER (ccls, *s2);
c2 = QSE_TOUPPER (*s2);
if (c1 > c2) return 1;
if (c1 < c2) return -1;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: str_utl.c 83 2009-02-24 14:05:17Z hyunghwan.chung $
* $Id: str_utl.c 127 2009-05-07 13:15:04Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -17,9 +17,13 @@
*/
#include <qse/cmn/str.h>
#include "chr.h"
#include <qse/cmn/chr.h>
int qse_strspltr (
#define ISSPACE(c) \
((c) == QSE_T(' ') || (c) == QSE_T('\t') || (c) == QSE_T('\n') || \
(c) == QSE_T('\r') || (c) == QSE_T('\v') && (c) == QSE_T('\f'))
int qse_strspltrn (
qse_char_t* s, const qse_char_t* delim,
qse_char_t lquote, qse_char_t rquote,
qse_char_t escape, const qse_char_t* trset)
@ -302,5 +306,26 @@ int qse_strspl (
qse_char_t* s, const qse_char_t* delim,
qse_char_t lquote, qse_char_t rquote, qse_char_t escape)
{
return qse_strspltr (s, delim, lquote, rquote, escape, QSE_NULL);
return qse_strspltrn (s, delim, lquote, rquote, escape, QSE_NULL);
}
qse_char_t* qse_strtrm (qse_char_t* str, int opt)
{
qse_char_t* p = str;
qse_char_t* s = QSE_NULL, * e = QSE_NULL;
while (*p != QSE_T('\0'))
{
if (!QSE_ISSPACE(*p))
{
if (s == QSE_NULL) s = p;
e = p;
}
p++;
}
if (opt & QSE_STRTRM_RIGHT) e[1] = QSE_T('\0');
if (opt & QSE_STRTRM_LEFT) str = s;
return str;
}

View File

@ -25,20 +25,6 @@ qse_lsp_t* qse_lsp_open (
if (prmfns->mmgr.malloc == QSE_NULL ||
prmfns->mmgr.realloc == QSE_NULL ||
prmfns->mmgr.free == QSE_NULL) return QSE_NULL;
if (prmfns->ccls.is_upper == QSE_NULL ||
prmfns->ccls.is_lower == QSE_NULL ||
prmfns->ccls.is_alpha == QSE_NULL ||
prmfns->ccls.is_digit == QSE_NULL ||
prmfns->ccls.is_xdigit == QSE_NULL ||
prmfns->ccls.is_alnum == QSE_NULL ||
prmfns->ccls.is_space == QSE_NULL ||
prmfns->ccls.is_print == QSE_NULL ||
prmfns->ccls.is_graph == QSE_NULL ||
prmfns->ccls.is_cntrl == QSE_NULL ||
prmfns->ccls.is_punct == QSE_NULL ||
prmfns->ccls.to_upper == QSE_NULL ||
prmfns->ccls.to_lower == QSE_NULL) return QSE_NULL;
*/
if (prmfns->misc.sprintf == QSE_NULL ||

View File

@ -8,7 +8,7 @@
#define _QSE_LIB_LSP_LSP_H_
#include "../cmn/mem.h"
#include "../cmn/chr.h"
#include <qse/cmn/chr.h>
#include <qse/cmn/str.h>
#include <qse/lsp/lsp.h>
@ -27,19 +27,19 @@
#define QSE_LSP_REALLOC(lsp,ptr,size) QSE_MMGR_REALLOC(&(lsp)->prmfns.mmgr,ptr,size)
#define QSE_LSP_FREE(lsp,ptr) QSE_MMGR_FREE(&(lsp)->prmfns.mmgr,ptr)
#define QSE_LSP_ISUPPER(lsp,c) QSE_CCLS_ISUPPER(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISLOWER(lsp,c) QSE_CCLS_ISLOWER(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISALPHA(lsp,c) QSE_CCLS_ISALPHA(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISDIGIT(lsp,c) QSE_CCLS_ISDIGIT(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISXDIGIT(lsp,c) QSE_CCLS_ISXDIGIT(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISALNUM(lsp,c) QSE_CCLS_ISALNUM(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISSPACE(lsp,c) QSE_CCLS_ISSPACE(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISPRINT(lsp,c) QSE_CCLS_ISPRINT(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISGRAPH(lsp,c) QSE_CCLS_ISGRAPH(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISCNTRL(lsp,c) QSE_CCLS_ISCNTRL(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISPUNCT(lsp,c) QSE_CCLS_ISPUNCT(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_TOUPPER(lsp,c) QSE_CCLS_TOUPPER(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_TOLOWER(lsp,c) QSE_CCLS_TOLOWER(&(lsp)->prmfns.ccls,c)
#define QSE_LSP_ISUPPER(lsp,c) QSE_ISUPPER(c)
#define QSE_LSP_ISLOWER(lsp,c) QSE_ISLOWER(c)
#define QSE_LSP_ISALPHA(lsp,c) QSE_ISALPHA(c)
#define QSE_LSP_ISDIGIT(lsp,c) QSE_ISDIGIT(c)
#define QSE_LSP_ISXDIGIT(lsp,c) QSE_ISXDIGIT(c)
#define QSE_LSP_ISALNUM(lsp,c) QSE_ISALNUM(c)
#define QSE_LSP_ISSPACE(lsp,c) QSE_ISSPACE(c)
#define QSE_LSP_ISPRINT(lsp,c) QSE_ISPRINT(c)
#define QSE_LSP_ISGRAPH(lsp,c) QSE_ISGRAPH(c)
#define QSE_LSP_ISCNTRL(lsp,c) QSE_ISCNTRL(c)
#define QSE_LSP_ISPUNCT(lsp,c) QSE_ISPUNCT(c)
#define QSE_LSP_TOUPPER(lsp,c) QSE_TOUPPER(c)
#define QSE_LSP_TOLOWER(lsp,c) QSE_TOLOWER(c)
struct qse_lsp_t
{

View File

@ -5,8 +5,8 @@
*/
#include <qse/utl/http.h>
#include <qse/cmn/chr.h>
#include "../cmn/mem.h"
#include "../cmn/chr.h"
static int is_http_space (qse_char_t c)
{

View File

@ -27,7 +27,7 @@ QSE_IMPLEMENT_COMMON_FUNCTIONS (sed)
static void free_command (qse_sed_t* sed, qse_sed_cmd_t* cmd);
qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_sed_prm_t* prm)
qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtn)
{
qse_sed_t* sed;
@ -44,7 +44,7 @@ qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_sed_prm_t* prm)
sed = (qse_sed_t*) QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_sed_t) + xtn);
if (sed == QSE_NULL) return QSE_NULL;
if (qse_sed_init (sed, mmgr, prm) == QSE_NULL)
if (qse_sed_init (sed, mmgr) == QSE_NULL)
{
QSE_MMGR_FREE (sed->mmgr, sed);
return QSE_NULL;
@ -59,7 +59,7 @@ void qse_sed_close (qse_sed_t* sed)
QSE_MMGR_FREE (sed->mmgr, sed);
}
qse_sed_t* qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr, qse_sed_prm_t* prm)
qse_sed_t* qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr)
{
QSE_MEMSET (sed, 0, sizeof(*sed));
sed->mmgr = mmgr;
@ -99,11 +99,6 @@ qse_sed_t* qse_sed_init (qse_sed_t* sed, qse_mmgr_t* mmgr, qse_sed_prm_t* prm)
return QSE_NULL;
}
/* build a character classifier from the primitive functions */
sed->ccls.is = (qse_ccls_is_t) prm->isccls;
sed->ccls.to = (qse_ccls_to_t) prm->toccls;
sed->ccls.data = sed;
return sed;
}
@ -171,11 +166,6 @@ int qse_sed_getoption (qse_sed_t* sed)
return sed->option;
}
qse_ccls_t* qse_sed_getccls (qse_sed_t* sed)
{
return &sed->ccls;
}
/* get the current charanter of the source code */
#define CURSC(sed) \
(((sed)->src.cur < (sed)->src.end)? (*(sed)->src.cur): QSE_CHAR_EOF)
@ -1464,7 +1454,6 @@ static int match_a1 (qse_sed_t* sed, qse_sed_cmd_t* cmd)
n = qse_matchrex (
sed->mmgr,
&sed->ccls,
0,
cmd->a1.u.rex,
0,
@ -1502,7 +1491,6 @@ static int match_a2 (qse_sed_t* sed, qse_sed_cmd_t* cmd)
QSE_ASSERT (cmd->a2.u.rex != QSE_NULL);
n = qse_matchrex (
sed->mmgr,
&sed->ccls,
0,
cmd->a2.u.rex,
0,

View File

@ -5,7 +5,7 @@
*/
#include <qse/utl/stdio.h>
#include "../cmn/chr.h"
#include <qse/cmn/chr.h>
#include <wchar.h>
#include <stdlib.h>