removed qse_ccls_t and related functions and added qse_strtrm()
This commit is contained in:
parent
4896b3d82c
commit
c221321cda
@ -247,9 +247,6 @@ int lsp_main (int argc, qse_char_t* argv[])
|
|||||||
prmfns.mmgr.data = QSE_NULL;
|
prmfns.mmgr.data = QSE_NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TODO: change prmfns ...... lsp_oepn... etc */
|
|
||||||
qse_memcpy (&prmfns.ccls, QSE_CCLS_GETDFL(), QSE_SIZEOF(prmfns.ccls));
|
|
||||||
|
|
||||||
prmfns.misc.sprintf = custom_lsp_sprintf;
|
prmfns.misc.sprintf = custom_lsp_sprintf;
|
||||||
prmfns.misc.dprintf = custom_lsp_dprintf;
|
prmfns.misc.dprintf = custom_lsp_dprintf;
|
||||||
prmfns.misc.data = QSE_NULL;
|
prmfns.misc.data = QSE_NULL;
|
||||||
|
@ -57,7 +57,7 @@ options:
|
|||||||
--cmode
|
--cmode
|
||||||
--nopre
|
--nopre
|
||||||
--documenttitle "QSE"
|
--documenttitle "QSE"
|
||||||
--source_line_numbers
|
# --source_line_numbers
|
||||||
--tabsize 4
|
--tabsize 4
|
||||||
--sections
|
--sections
|
||||||
--toc "no"
|
--toc "no"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: Awk.hpp 75 2009-02-22 14:10:34Z hyunghwan.chung $
|
* $Id: Awk.hpp 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -54,7 +54,6 @@ public:
|
|||||||
typedef qse_map_pair_t pair_t;
|
typedef qse_map_pair_t pair_t;
|
||||||
|
|
||||||
typedef qse_mmgr_t mmgr_t;
|
typedef qse_mmgr_t mmgr_t;
|
||||||
typedef qse_ccls_t ccls_t;
|
|
||||||
|
|
||||||
/** Represents an internal awk value */
|
/** Represents an internal awk value */
|
||||||
typedef qse_awk_val_t val_t;
|
typedef qse_awk_val_t val_t;
|
||||||
@ -68,21 +67,6 @@ public:
|
|||||||
/** Represents an runtime I/O data */
|
/** Represents an runtime I/O data */
|
||||||
typedef qse_awk_riod_t riod_t;
|
typedef qse_awk_riod_t riod_t;
|
||||||
|
|
||||||
enum ccls_id_t
|
|
||||||
{
|
|
||||||
CCLS_UPPER = QSE_CCLS_UPPER,
|
|
||||||
CCLS_LOWER = QSE_CCLS_LOWER,
|
|
||||||
CCLS_ALPHA = QSE_CCLS_ALPHA,
|
|
||||||
CCLS_DIGIT = QSE_CCLS_DIGIT,
|
|
||||||
CCLS_XDIGIT = QSE_CCLS_XDIGIT,
|
|
||||||
CCLS_ALNUM = QSE_CCLS_ALNUM,
|
|
||||||
CCLS_SPACE = QSE_CCLS_SPACE,
|
|
||||||
CCLS_PRINT = QSE_CCLS_PRINT,
|
|
||||||
CCLS_GRAPH = QSE_CCLS_GRAPH,
|
|
||||||
CCLS_CNTRL = QSE_CCLS_CNTRL,
|
|
||||||
CCLS_PUNCT = QSE_CCLS_PUNCT
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the source code I/O context for Awk::parse.
|
* Represents the source code I/O context for Awk::parse.
|
||||||
* An instance of Awk::Source is passed to Awk::openSource,
|
* An instance of Awk::Source is passed to Awk::openSource,
|
||||||
@ -774,16 +758,6 @@ public:
|
|||||||
return qse_awk_getmmgr (awk);
|
return qse_awk_getmmgr (awk);
|
||||||
}
|
}
|
||||||
|
|
||||||
ccls_t* getCcls()
|
|
||||||
{
|
|
||||||
return qse_awk_getccls (awk);
|
|
||||||
}
|
|
||||||
|
|
||||||
const ccls_t* getCcls() const
|
|
||||||
{
|
|
||||||
return qse_awk_getccls (awk);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setError (ErrorCode code);
|
void setError (ErrorCode code);
|
||||||
void setError (ErrorCode code, size_t line);
|
void setError (ErrorCode code, size_t line);
|
||||||
@ -1052,9 +1026,6 @@ protected:
|
|||||||
virtual void* reallocMem (void* ptr, size_t n) = 0;
|
virtual void* reallocMem (void* ptr, size_t n) = 0;
|
||||||
virtual void freeMem (void* ptr) = 0;
|
virtual void freeMem (void* ptr) = 0;
|
||||||
|
|
||||||
virtual bool_t isType (cint_t c, ccls_id_t type) = 0;
|
|
||||||
virtual cint_t transCase (cint_t c, ccls_id_t type) = 0;
|
|
||||||
|
|
||||||
virtual real_t pow (real_t x, real_t y) = 0;
|
virtual real_t pow (real_t x, real_t y) = 0;
|
||||||
virtual int vsprintf (char_t* buf, size_t size,
|
virtual int vsprintf (char_t* buf, size_t size,
|
||||||
const char_t* fmt, va_list arg) = 0;
|
const char_t* fmt, va_list arg) = 0;
|
||||||
@ -1087,9 +1058,6 @@ protected:
|
|||||||
static void* reallocMem (void* data, void* ptr, size_t n);
|
static void* reallocMem (void* data, void* ptr, size_t n);
|
||||||
static void freeMem (void* data, void* ptr);
|
static void freeMem (void* data, void* ptr);
|
||||||
|
|
||||||
static bool_t isType (awk_t* awk, cint_t c, qse_ccls_id_t type);
|
|
||||||
static cint_t transCase (awk_t* awk, cint_t c, qse_ccls_id_t type);
|
|
||||||
|
|
||||||
static real_t pow (awk_t* data, real_t x, real_t y);
|
static real_t pow (awk_t* data, real_t x, real_t y);
|
||||||
static int sprintf (awk_t* data, char_t* buf, size_t size,
|
static int sprintf (awk_t* data, char_t* buf, size_t size,
|
||||||
const char_t* fmt, ...);
|
const char_t* fmt, ...);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: StdAwk.hpp 75 2009-02-22 14:10:34Z hyunghwan.chung $
|
* $Id: StdAwk.hpp 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -84,9 +84,6 @@ protected:
|
|||||||
void* reallocMem (void* ptr, size_t n);
|
void* reallocMem (void* ptr, size_t n);
|
||||||
void freeMem (void* ptr);
|
void freeMem (void* ptr);
|
||||||
|
|
||||||
bool_t isType (cint_t c, ccls_id_t type);
|
|
||||||
cint_t transCase (cint_t c, ccls_id_t type);
|
|
||||||
|
|
||||||
real_t pow (real_t x, real_t y);
|
real_t pow (real_t x, real_t y);
|
||||||
int vsprintf (char_t* buf, size_t size,
|
int vsprintf (char_t* buf, size_t size,
|
||||||
const char_t* fmt, va_list arg);
|
const char_t* fmt, va_list arg);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: awk.h 100 2009-03-14 03:14:39Z hyunghwan.chung $
|
* $Id: awk.h 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -199,18 +199,6 @@ typedef int (*qse_awk_sprintf_t) (
|
|||||||
...
|
...
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef qse_bool_t (*qse_awk_isccls_t) (
|
|
||||||
qse_awk_t* awk,
|
|
||||||
qse_cint_t c,
|
|
||||||
qse_ccls_id_t type
|
|
||||||
);
|
|
||||||
|
|
||||||
typedef qse_cint_t (*qse_awk_toccls_t) (
|
|
||||||
qse_awk_t* awk,
|
|
||||||
qse_cint_t c,
|
|
||||||
qse_ccls_id_t type
|
|
||||||
);
|
|
||||||
|
|
||||||
/****e* AWK/qse_awk_sio_cmd_t
|
/****e* AWK/qse_awk_sio_cmd_t
|
||||||
* NAME
|
* NAME
|
||||||
* qse_awk_sio_cmd_t - define source IO commands
|
* qse_awk_sio_cmd_t - define source IO commands
|
||||||
@ -308,8 +296,6 @@ struct qse_awk_prm_t
|
|||||||
{
|
{
|
||||||
qse_awk_pow_t pow;
|
qse_awk_pow_t pow;
|
||||||
qse_awk_sprintf_t sprintf;
|
qse_awk_sprintf_t sprintf;
|
||||||
qse_awk_isccls_t isccls;
|
|
||||||
qse_awk_toccls_t toccls;
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* TODO: accept regular expression handling functions */
|
/* TODO: accept regular expression handling functions */
|
||||||
@ -885,21 +871,6 @@ qse_awk_prm_t* qse_awk_getprm (
|
|||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
/****f* AWK/qse_awk_getccls
|
|
||||||
* NAME
|
|
||||||
* qse_awk_getccls - get the character classifier
|
|
||||||
* DESCRIPTION
|
|
||||||
* The qse_awk_getccls() function returns the character classifier composed
|
|
||||||
* from the primitive functions in a call to qse_awk_open(). The data field
|
|
||||||
* is set to the awk object. The classifier returned is valid while the
|
|
||||||
* associated awk object is alive.
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
|
||||||
qse_ccls_t* qse_awk_getccls (
|
|
||||||
qse_awk_t* awk
|
|
||||||
);
|
|
||||||
/******/
|
|
||||||
|
|
||||||
/****f* AWK/qse_awk_clear
|
/****f* AWK/qse_awk_clear
|
||||||
* NAME
|
* NAME
|
||||||
* qse_awk_clear - clear a qse_awk_t object
|
* qse_awk_clear - clear a qse_awk_t object
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: chr.h 75 2009-02-22 14:10:34Z hyunghwan.chung $
|
* $Id: chr.h 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -22,35 +22,82 @@
|
|||||||
#include <qse/types.h>
|
#include <qse/types.h>
|
||||||
#include <qse/macros.h>
|
#include <qse/macros.h>
|
||||||
|
|
||||||
/* gets a pointer to the default memory manager */
|
/****t* Common/qse_ccls_id_t
|
||||||
#define QSE_CCLS_GETDFL() (qse_ccls)
|
* NAME
|
||||||
|
* qse_ccls_id_t - define character class types
|
||||||
|
* SYNOPSIS
|
||||||
|
*/
|
||||||
|
enum qse_ccls_id_t
|
||||||
|
{
|
||||||
|
QSE_CCLS_UPPER,
|
||||||
|
QSE_CCLS_LOWER,
|
||||||
|
QSE_CCLS_ALPHA,
|
||||||
|
QSE_CCLS_DIGIT,
|
||||||
|
QSE_CCLS_XDIGIT,
|
||||||
|
QSE_CCLS_ALNUM,
|
||||||
|
QSE_CCLS_SPACE,
|
||||||
|
QSE_CCLS_PRINT,
|
||||||
|
QSE_CCLS_GRAPH,
|
||||||
|
QSE_CCLS_CNTRL,
|
||||||
|
QSE_CCLS_PUNCT
|
||||||
|
};
|
||||||
|
typedef enum qse_ccls_id_t qse_ccls_id_t;
|
||||||
|
/******/
|
||||||
|
|
||||||
/* sets a pointer to the default memory manager */
|
#ifdef USE_STDC
|
||||||
#define QSE_CCLS_SETDFL(m) ((qse_ccls)=(m))
|
# if defined(QSE_CHAR_IS_MCHAR)
|
||||||
|
# include <ctype.h>
|
||||||
#define QSE_CCLS_IS(ccls,c,type) ((ccls)->is((ccls)->data,c,type))
|
# define QSE_ISUPPER(c) isupper(c)
|
||||||
#define QSE_CCLS_TO(ccls,c,type) ((ccls)->to((ccls)->data,c,type))
|
# define QSE_ISLOWER(c) islower(c)
|
||||||
|
# define QSE_ISALPHA(c) isalpha(c)
|
||||||
#define QSE_CCLS_ISUPPER(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_UPPER)
|
# define QSE_ISDIGIT(c) isdigit(c)
|
||||||
#define QSE_CCLS_ISLOWER(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_LOWER)
|
# define QSE_ISXDIGIT(c) isxdigit(c)
|
||||||
#define QSE_CCLS_ISALPHA(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_ALPHA)
|
# define QSE_ISALNUM(c) isalnum(c)
|
||||||
#define QSE_CCLS_ISDIGIT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_DIGIT)
|
# define QSE_ISSPACE(c) isspace(c)
|
||||||
#define QSE_CCLS_ISXDIGIT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_XDIGIT)
|
# define QSE_ISPRINT(c) isprint(c)
|
||||||
#define QSE_CCLS_ISALNUM(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_ALNUM)
|
# define QSE_ISGRAPH(c) isgraph(c)
|
||||||
#define QSE_CCLS_ISSPACE(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_SPACE)
|
# define QSE_ISCNTRL(c) iscntrl(c)
|
||||||
#define QSE_CCLS_ISPRINT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_PRINT)
|
# define QSE_ISPUNCT(c) ispunct(c)
|
||||||
#define QSE_CCLS_ISGRAPH(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_GRAPH)
|
# define QSE_TOUPPER(c) toupper(c)
|
||||||
#define QSE_CCLS_ISCNTRL(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_CNTRL)
|
# define QSE_TOLOWER(c) tolower(c)
|
||||||
#define QSE_CCLS_ISPUNCT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_PUNCT)
|
# elif defined(QSE_CHAR_IS_WCHAR)
|
||||||
#define QSE_CCLS_TOUPPER(ccls,c) QSE_CCLS_TO(ccls,c,QSE_CCLS_UPPER)
|
# include <wctype.h>
|
||||||
#define QSE_CCLS_TOLOWER(ccls,c) QSE_CCLS_TO(ccls,c,QSE_CCLS_LOWER)
|
# 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
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern qse_ccls_t* qse_ccls;
|
|
||||||
|
|
||||||
qse_bool_t qse_ccls_is (
|
qse_bool_t qse_ccls_is (
|
||||||
qse_cint_t c,
|
qse_cint_t c,
|
||||||
qse_ccls_id_t type
|
qse_ccls_id_t type
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: rex.h 75 2009-02-22 14:10:34Z hyunghwan.chung $
|
* $Id: rex.h 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ void* qse_buildrex (
|
|||||||
const qse_char_t* ptn, qse_size_t len, int* errnum);
|
const qse_char_t* ptn, qse_size_t len, int* errnum);
|
||||||
|
|
||||||
int qse_matchrex (
|
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,
|
void* code, int option,
|
||||||
const qse_char_t* str, qse_size_t len,
|
const qse_char_t* str, qse_size_t len,
|
||||||
const qse_char_t** match_ptr, qse_size_t* match_len, int* errnum);
|
const qse_char_t** match_ptr, qse_size_t* match_len, int* errnum);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: str.h 126 2009-05-05 02:12:38Z hyunghwan.chung $
|
* $Id: str.h 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -109,6 +109,12 @@ struct qse_str_t
|
|||||||
if (__ston_f > 0) value *= -1; \
|
if (__ston_f > 0) value *= -1; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum qse_strtrm_opt_t
|
||||||
|
{
|
||||||
|
QSE_STRTRM_LEFT = (1 << 0),
|
||||||
|
QSE_STRTRM_RIGHT = (1 << 1)
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -238,8 +244,7 @@ int qse_strxncmp (
|
|||||||
const qse_char_t* s1, qse_size_t len1,
|
const qse_char_t* s1, qse_size_t len1,
|
||||||
const qse_char_t* s2, qse_size_t len2);
|
const qse_char_t* s2, qse_size_t len2);
|
||||||
|
|
||||||
int qse_strcasecmp (
|
int qse_strcasecmp (const qse_char_t* s1, const qse_char_t* s2);
|
||||||
const qse_char_t* s1, const qse_char_t* s2, qse_ccls_t* ccls);
|
|
||||||
|
|
||||||
/****f* Common/qse_strxncasecmp
|
/****f* Common/qse_strxncasecmp
|
||||||
* NAME
|
* NAME
|
||||||
@ -248,9 +253,7 @@ int qse_strcasecmp (
|
|||||||
* The qse_strxncasecmp() function compares characters at the same position
|
* The qse_strxncasecmp() function compares characters at the same position
|
||||||
* in each string after converting them to the same case temporarily.
|
* in each string after converting them to the same case temporarily.
|
||||||
* It accepts two strings and a character class handler. A string is
|
* It accepts two strings and a character class handler. A string is
|
||||||
* represented by its beginning pointer and length. You can write your own
|
* represented by its beginning pointer and length.
|
||||||
* character class handler or use QSE_CCLS_GETDFL() to get the default
|
|
||||||
* character class handler.
|
|
||||||
*
|
*
|
||||||
* For two strings to be equal, they need to have the same length and all
|
* For two strings to be equal, they need to have the same length and all
|
||||||
* characters in the first string should be equal to their counterpart in the
|
* characters in the first string should be equal to their counterpart in the
|
||||||
@ -259,15 +262,15 @@ int qse_strcasecmp (
|
|||||||
* The qse_strxncasecmp() returns 0 if two strings are equal, a positive
|
* The qse_strxncasecmp() returns 0 if two strings are equal, a positive
|
||||||
* number if the first string is larger, -1 if the second string is larger.
|
* number if the first string is larger, -1 if the second string is larger.
|
||||||
* EXAMPLES
|
* EXAMPLES
|
||||||
* qse_strxncasecmp (QSE_T("foo"), 3, QSE_T("FoO"), 3, QSE_CCLS_GETDFL());
|
* The example compares "foo" and "FoO" case-insenstively.
|
||||||
|
* qse_strxncasecmp (QSE_T("foo"), 3, QSE_T("FoO"), 3);
|
||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
int qse_strxncasecmp (
|
int qse_strxncasecmp (
|
||||||
const qse_char_t* s1 /* the pointer to the first string */,
|
const qse_char_t* s1 /* the pointer to the first string */,
|
||||||
qse_size_t len1 /* the length of the first string */,
|
qse_size_t len1 /* the length of the first string */,
|
||||||
const qse_char_t* s2 /* the pointer to the second string */,
|
const qse_char_t* s2 /* the pointer to the second string */,
|
||||||
qse_size_t len2 /* the length of the second string */,
|
qse_size_t len2 /* the length of the second string */
|
||||||
qse_ccls_t* ccls /* character class handler */
|
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
@ -396,6 +399,7 @@ int qse_str_yield (
|
|||||||
* qse_str_getsizer - get the sizer
|
* qse_str_getsizer - get the sizer
|
||||||
* RETURN
|
* RETURN
|
||||||
* a sizer function set or QSE_NULL if no sizer is set.
|
* a sizer function set or QSE_NULL if no sizer is set.
|
||||||
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
qse_str_sizer_t qse_str_getsizer (
|
qse_str_sizer_t qse_str_getsizer (
|
||||||
qse_str_t* str
|
qse_str_t* str
|
||||||
@ -428,6 +432,7 @@ void qse_str_setsizer (
|
|||||||
* You may use QSE_STR_CAPA(str) macro for performance sake.
|
* You may use QSE_STR_CAPA(str) macro for performance sake.
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* current capacity in number of characters.
|
* current capacity in number of characters.
|
||||||
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
qse_size_t qse_str_getcapa (
|
qse_size_t qse_str_getcapa (
|
||||||
qse_str_t* str
|
qse_str_t* str
|
||||||
@ -443,6 +448,7 @@ qse_size_t qse_str_getcapa (
|
|||||||
* from the buffer.
|
* from the buffer.
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* (qse_size_t)-1 on failure, new capacity on success
|
* (qse_size_t)-1 on failure, new capacity on success
|
||||||
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
qse_size_t qse_str_setcapa (
|
qse_size_t qse_str_setcapa (
|
||||||
qse_str_t* str,
|
qse_str_t* str,
|
||||||
@ -453,6 +459,7 @@ qse_size_t qse_str_setcapa (
|
|||||||
/****f* Common/qse_str_getlen
|
/****f* Common/qse_str_getlen
|
||||||
* NAME
|
* NAME
|
||||||
* qse_str_getlen - get length
|
* qse_str_getlen - get length
|
||||||
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
qse_size_t qse_str_getlen (
|
qse_size_t qse_str_getlen (
|
||||||
qse_str_t* str
|
qse_str_t* str
|
||||||
@ -464,6 +471,7 @@ qse_size_t qse_str_getlen (
|
|||||||
* qse_str_setlen - change length
|
* qse_str_setlen - change length
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* (qse_size_t)-1 on failure, new length on success
|
* (qse_size_t)-1 on failure, new length on success
|
||||||
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
qse_size_t qse_str_setlen (
|
qse_size_t qse_str_setlen (
|
||||||
qse_str_t* str,
|
qse_str_t* str,
|
||||||
@ -477,6 +485,7 @@ qse_size_t qse_str_setlen (
|
|||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* The qse_str_clear() funtion deletes all characters in a string and sets
|
* The qse_str_clear() funtion deletes all characters in a string and sets
|
||||||
* the length to 0. It doesn't resize the internal buffer.
|
* the length to 0. It doesn't resize the internal buffer.
|
||||||
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
void qse_str_clear (
|
void qse_str_clear (
|
||||||
qse_str_t* str
|
qse_str_t* str
|
||||||
@ -489,6 +498,7 @@ void qse_str_clear (
|
|||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* The qse_str_swap() function exchanges the pointers to a buffer between
|
* The qse_str_swap() function exchanges the pointers to a buffer between
|
||||||
* two strings. It updates the length and the capacity accordingly.
|
* two strings. It updates the length and the capacity accordingly.
|
||||||
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
void qse_str_swap (
|
void qse_str_swap (
|
||||||
qse_str_t* str1,
|
qse_str_t* str1,
|
||||||
@ -529,37 +539,77 @@ qse_size_t qse_str_nccat (
|
|||||||
qse_size_t len
|
qse_size_t len
|
||||||
);
|
);
|
||||||
|
|
||||||
/****f* Common/qse_strspltr
|
/****f* Common/qse_strspl
|
||||||
* NAME
|
* NAME
|
||||||
* qse_strspltr - split a string translating special escane sequences
|
* qse_strspl - split a string into fields
|
||||||
|
* SEE ALSO
|
||||||
|
* qse_strspltrn
|
||||||
|
* SYNOPSIS
|
||||||
|
*/
|
||||||
|
int qse_strspl (
|
||||||
|
qse_char_t* str,
|
||||||
|
const qse_char_t* delim,
|
||||||
|
qse_char_t lquote,
|
||||||
|
qse_char_t rquote,
|
||||||
|
qse_char_t escape
|
||||||
|
);
|
||||||
|
/******/
|
||||||
|
|
||||||
|
/****f* Common/qse_strspltrn
|
||||||
|
* NAME
|
||||||
|
* qse_strspltrn - split a string translating special escape sequences
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* The argument trset is translation character set which is composed
|
* The argument trset is a translation character set which is composed
|
||||||
* of multiple character pairs. An escape character followed by the
|
* of multiple character pairs. An escape character followed by the
|
||||||
* first character in a pair is translated into the second character
|
* first character in a pair is translated into the second character
|
||||||
* in the pair. If trset is QSE_NULL, no translation is performed.
|
* in the pair. If trset is QSE_NULL, no translation is performed.
|
||||||
|
* EXAMPLES
|
||||||
|
* Let's translate a sequence of '\n' and '\r' to a new line and a carriage
|
||||||
|
* return respectively.
|
||||||
|
* qse_strspltrn (str, QSE_T(':'), QSE_T('['), QSE_T(']'), QSE_T('\\'), QSE_T("n\nr\r"), &nfields);
|
||||||
|
* Given [xxx]:[\rabc\ndef]:[] as an input, the example breaks the second
|
||||||
|
* fields to <CR>abc<NL>def where <CR> is a carriage return and <NL> is a
|
||||||
|
* new line.
|
||||||
|
* SEE ALSO
|
||||||
|
* If you don't need any translation, you may call qse_strspl() alternatively.
|
||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
int qse_strspltr (
|
int qse_strspltrn (
|
||||||
qse_char_t* str,
|
qse_char_t* str,
|
||||||
const qse_char_t* delim,
|
const qse_char_t* delim,
|
||||||
qse_char_t lquote,
|
qse_char_t lquote,
|
||||||
qse_char_t rquote,
|
qse_char_t rquote,
|
||||||
qse_char_t escape,
|
qse_char_t escape,
|
||||||
const qse_char_t* trset
|
const qse_char_t* trset
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
/****f* Common/qse_strspl
|
/****f* Common/qse_strtrm
|
||||||
* NAME
|
* NAME
|
||||||
* qse_strspl - split a string
|
* qse_strtrm - remove leading and/or trailing spaces from a string
|
||||||
|
* DESCRIPTION
|
||||||
|
* The qse_strtrm() function removes leading spaces and/or trailing
|
||||||
|
* spaces from a string depending on the opt parameter. You can form
|
||||||
|
* the opt parameter by bitwise-OR'ing one or more of the following
|
||||||
|
* values.
|
||||||
|
* * QSE_STRTRM_LEFT - remove leading spaces
|
||||||
|
* * QSE_STRTRM_RIGHT - remove trailing spaces
|
||||||
|
* It returns the pointer to the trimmed string.
|
||||||
|
* NOTE
|
||||||
|
* Should it remove leading spaces, it just returns the pointer to
|
||||||
|
* the first non-space character in the string. Should it remove trailing
|
||||||
|
* spaces, it inserts a QSE_T('\0') character after the last non-space
|
||||||
|
* characters.
|
||||||
|
* EXAMPLES
|
||||||
|
* The example removes leading and trailing spaces from the string a.
|
||||||
|
* qse_char_t a[] = QSE_T(" this is a test string ");
|
||||||
|
* qse_printf (QSE_T("[%s]\n"), a);
|
||||||
|
* qse_printf (QSE_T("[%s]\n"), qse_strtrm (a, QSE_STRTRM_LEFT|QSE_STRTRM_RIGHT));
|
||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
int qse_strspl (
|
qse_char_t* qse_strtrm (
|
||||||
qse_char_t* str,
|
qse_char_t* str,
|
||||||
const qse_char_t* delim,
|
int opt
|
||||||
qse_char_t lquote,
|
|
||||||
qse_char_t rquote,
|
|
||||||
qse_char_t escape
|
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
@ -569,8 +619,8 @@ int qse_strspl (
|
|||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
qse_size_t qse_mbstowcs (
|
qse_size_t qse_mbstowcs (
|
||||||
const qse_mchar_t* mbs,
|
const qse_mchar_t* mbs,
|
||||||
qse_wchar_t* wcs,
|
qse_wchar_t* wcs,
|
||||||
qse_size_t* wcslen
|
qse_size_t* wcslen
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
@ -583,9 +633,9 @@ qse_size_t qse_mbstowcs (
|
|||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
qse_size_t qse_mbsntowcsn (
|
qse_size_t qse_mbsntowcsn (
|
||||||
const qse_mchar_t* mbs,
|
const qse_mchar_t* mbs,
|
||||||
qse_size_t mbslen,
|
qse_size_t mbslen,
|
||||||
qse_wchar_t* wcs,
|
qse_wchar_t* wcs,
|
||||||
qse_size_t* wcslen
|
qse_size_t* wcslen
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
@ -646,8 +696,8 @@ qse_size_t qse_wcsntombsnlen (
|
|||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
qse_size_t qse_wcstombs (
|
qse_size_t qse_wcstombs (
|
||||||
const qse_wchar_t* wcs,
|
const qse_wchar_t* wcs,
|
||||||
qse_mchar_t* mbs,
|
qse_mchar_t* mbs,
|
||||||
qse_size_t* mbslen
|
qse_size_t* mbslen
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
@ -660,9 +710,9 @@ qse_size_t qse_wcstombs (
|
|||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
qse_size_t qse_wcsntombsn (
|
qse_size_t qse_wcsntombsn (
|
||||||
const qse_wchar_t* wcs,
|
const qse_wchar_t* wcs,
|
||||||
qse_size_t wcslen,
|
qse_size_t wcslen,
|
||||||
qse_mchar_t* mbs,
|
qse_mchar_t* mbs,
|
||||||
qse_size_t* mbslen
|
qse_size_t* mbslen
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
@ -679,8 +729,8 @@ qse_size_t qse_wcsntombsn (
|
|||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
*/
|
*/
|
||||||
int qse_wcstombs_strict (
|
int qse_wcstombs_strict (
|
||||||
const qse_wchar_t* wcs,
|
const qse_wchar_t* wcs,
|
||||||
qse_mchar_t* mbs,
|
qse_mchar_t* mbs,
|
||||||
qse_size_t mbslen
|
qse_size_t mbslen
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
@ -48,7 +48,6 @@ typedef void (*qse_lsp_dprintf_t) (void* data, const qse_char_t* fmt, ...);
|
|||||||
struct qse_lsp_prmfns_t
|
struct qse_lsp_prmfns_t
|
||||||
{
|
{
|
||||||
qse_mmgr_t mmgr;
|
qse_mmgr_t mmgr;
|
||||||
qse_ccls_t ccls;
|
|
||||||
|
|
||||||
/* utilities */
|
/* utilities */
|
||||||
struct
|
struct
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: types.h 90 2009-03-01 09:58:19Z hyunghwan.chung $
|
* $Id: types.h 127 2009-05-07 13:15:04Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -419,46 +419,4 @@ struct qse_mmgr_t
|
|||||||
typedef struct qse_mmgr_t qse_mmgr_t;
|
typedef struct qse_mmgr_t qse_mmgr_t;
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
/****t* Base/qse_ccls_id_t
|
|
||||||
* NAME
|
|
||||||
* qse_ccls_id_t - define character class types
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
|
||||||
enum qse_ccls_id_t
|
|
||||||
{
|
|
||||||
QSE_CCLS_UPPER,
|
|
||||||
QSE_CCLS_LOWER,
|
|
||||||
QSE_CCLS_ALPHA,
|
|
||||||
QSE_CCLS_DIGIT,
|
|
||||||
QSE_CCLS_XDIGIT,
|
|
||||||
QSE_CCLS_ALNUM,
|
|
||||||
QSE_CCLS_SPACE,
|
|
||||||
QSE_CCLS_PRINT,
|
|
||||||
QSE_CCLS_GRAPH,
|
|
||||||
QSE_CCLS_CNTRL,
|
|
||||||
QSE_CCLS_PUNCT
|
|
||||||
};
|
|
||||||
/******/
|
|
||||||
|
|
||||||
typedef enum qse_ccls_id_t qse_ccls_id_t;
|
|
||||||
|
|
||||||
typedef qse_bool_t (*qse_ccls_is_t) (
|
|
||||||
void* data, qse_cint_t c, qse_ccls_id_t type);
|
|
||||||
typedef qse_cint_t (*qse_ccls_to_t) (
|
|
||||||
void* data, qse_cint_t c, qse_ccls_id_t type);
|
|
||||||
|
|
||||||
/****t* Base/qse_ccls_t
|
|
||||||
* NAME
|
|
||||||
* qse_mmgr_t - define a character classifier
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
|
||||||
struct qse_ccls_t
|
|
||||||
{
|
|
||||||
qse_ccls_is_t is;
|
|
||||||
qse_ccls_to_t to;
|
|
||||||
void* data;
|
|
||||||
};
|
|
||||||
typedef struct qse_ccls_t qse_ccls_t;
|
|
||||||
/******/
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -85,42 +85,15 @@ typedef qse_ssize_t (*qse_sed_iof_t) (
|
|||||||
qse_size_t count
|
qse_size_t count
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef qse_bool_t (*qse_sed_isccls_t) (
|
|
||||||
qse_sed_t* sed,
|
|
||||||
qse_cint_t c,
|
|
||||||
qse_ccls_id_t type
|
|
||||||
);
|
|
||||||
|
|
||||||
typedef qse_cint_t (*qse_sed_toccls_t) (
|
|
||||||
qse_sed_t* sed,
|
|
||||||
qse_cint_t c,
|
|
||||||
qse_ccls_id_t type
|
|
||||||
);
|
|
||||||
|
|
||||||
typedef struct qse_sed_cmd_t qse_sed_cmd_t; /* command */
|
typedef struct qse_sed_cmd_t qse_sed_cmd_t; /* command */
|
||||||
typedef enum qse_sed_errnum_t qse_sed_errnum_t;
|
typedef enum qse_sed_errnum_t qse_sed_errnum_t;
|
||||||
|
|
||||||
/****f* Text Processor/qse_sed_prm_t
|
|
||||||
* NAME
|
|
||||||
* qse_sed_prm_t - define primitive functions
|
|
||||||
* SYNOPSIS
|
|
||||||
*/
|
|
||||||
struct qse_sed_prm_t
|
|
||||||
{
|
|
||||||
qse_sed_isccls_t isccls;
|
|
||||||
qse_sed_toccls_t toccls;
|
|
||||||
};
|
|
||||||
typedef struct qse_sed_prm_t qse_sed_prm_t;
|
|
||||||
/******/
|
|
||||||
|
|
||||||
struct qse_sed_t
|
struct qse_sed_t
|
||||||
{
|
{
|
||||||
QSE_DEFINE_COMMON_FIELDS (sed)
|
QSE_DEFINE_COMMON_FIELDS (sed)
|
||||||
qse_sed_errnum_t errnum;
|
qse_sed_errnum_t errnum;
|
||||||
int option;
|
int option;
|
||||||
|
|
||||||
qse_ccls_t ccls;
|
|
||||||
|
|
||||||
/* source code pointers */
|
/* source code pointers */
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -191,8 +164,7 @@ QSE_DEFINE_COMMON_FUNCTIONS (sed)
|
|||||||
*/
|
*/
|
||||||
qse_sed_t* qse_sed_open (
|
qse_sed_t* qse_sed_open (
|
||||||
qse_mmgr_t* mmgr,
|
qse_mmgr_t* mmgr,
|
||||||
qse_size_t xtn,
|
qse_size_t xtn
|
||||||
qse_sed_prm_t* prm
|
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
@ -213,8 +185,7 @@ void qse_sed_close (
|
|||||||
*/
|
*/
|
||||||
qse_sed_t* qse_sed_init (
|
qse_sed_t* qse_sed_init (
|
||||||
qse_sed_t* sed,
|
qse_sed_t* sed,
|
||||||
qse_mmgr_t* mmgr,
|
qse_mmgr_t* mmgr
|
||||||
qse_sed_prm_t* prm
|
|
||||||
);
|
);
|
||||||
/******/
|
/******/
|
||||||
|
|
||||||
|
@ -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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -1192,8 +1192,6 @@ int Awk::open ()
|
|||||||
qse_awk_prm_t prm;
|
qse_awk_prm_t prm;
|
||||||
prm.pow = pow;
|
prm.pow = pow;
|
||||||
prm.sprintf = sprintf;
|
prm.sprintf = sprintf;
|
||||||
prm.isccls = isType;
|
|
||||||
prm.toccls = transCase;
|
|
||||||
|
|
||||||
awk = qse_awk_open (&mmgr, QSE_SIZEOF(xtn_t), &prm);
|
awk = qse_awk_open (&mmgr, QSE_SIZEOF(xtn_t), &prm);
|
||||||
if (awk == QSE_NULL)
|
if (awk == QSE_NULL)
|
||||||
@ -1771,18 +1769,6 @@ void Awk::freeMem (void* data, void* ptr)
|
|||||||
((Awk*)data)->freeMem (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)
|
Awk::real_t Awk::pow (awk_t* awk, real_t x, real_t y)
|
||||||
{
|
{
|
||||||
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
|
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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -411,17 +411,6 @@ void StdAwk::freeMem (void* ptr)
|
|||||||
::free (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
|
// miscellaneous primitive
|
||||||
StdAwk::real_t StdAwk::pow (real_t x, real_t y)
|
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.
|
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 != QSE_NULL);
|
||||||
QSE_ASSERT (prm->pow != QSE_NULL);
|
QSE_ASSERT (prm->pow != QSE_NULL);
|
||||||
QSE_ASSERT (prm->sprintf != QSE_NULL);
|
QSE_ASSERT (prm->sprintf != QSE_NULL);
|
||||||
QSE_ASSERT (prm->isccls != QSE_NULL);
|
|
||||||
QSE_ASSERT (prm->toccls != QSE_NULL);
|
|
||||||
if (prm == QSE_NULL ||
|
if (prm == QSE_NULL ||
|
||||||
prm->pow == QSE_NULL ||
|
prm->pow == QSE_NULL ||
|
||||||
prm->sprintf == QSE_NULL ||
|
prm->sprintf == QSE_NULL)
|
||||||
prm->isccls == QSE_NULL ||
|
|
||||||
prm->toccls == QSE_NULL)
|
|
||||||
{
|
{
|
||||||
QSE_AWK_FREE (awk, awk);
|
QSE_AWK_FREE (awk, awk);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
}
|
}
|
||||||
awk->prm = *prm;
|
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);
|
awk->token.name = qse_str_open (mmgr, 0, 128);
|
||||||
if (awk->token.name == QSE_NULL) goto oops;
|
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;
|
return &awk->prm;
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_ccls_t* qse_awk_getccls (qse_awk_t* awk)
|
|
||||||
{
|
|
||||||
return &awk->ccls;
|
|
||||||
}
|
|
||||||
|
|
||||||
int qse_awk_getoption (qse_awk_t* awk)
|
int qse_awk_getoption (qse_awk_t* awk)
|
||||||
{
|
{
|
||||||
return awk->option;
|
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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
#define _QSE_LIB_AWK_AWK_H_
|
#define _QSE_LIB_AWK_AWK_H_
|
||||||
|
|
||||||
#include "../cmn/mem.h"
|
#include "../cmn/mem.h"
|
||||||
#include "../cmn/chr.h"
|
#include <qse/cmn/chr.h>
|
||||||
#include <qse/cmn/str.h>
|
#include <qse/cmn/str.h>
|
||||||
#include <qse/cmn/map.h>
|
#include <qse/cmn/map.h>
|
||||||
#include <qse/cmn/lda.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;
|
typedef struct qse_awk_tree_t qse_awk_tree_t;
|
||||||
|
|
||||||
#include <qse/awk/awk.h>
|
#include <qse/awk/awk.h>
|
||||||
|
#include <qse/cmn/chr.h>
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
#include "fnc.h"
|
#include "fnc.h"
|
||||||
#include "parse.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_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_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_ISUPPER(awk,c) QSE_ISUPPER(c)
|
||||||
#define QSE_AWK_ISLOWER(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_UPPER)
|
#define QSE_AWK_ISLOWER(awk,c) QSE_ISLOWER(c)
|
||||||
#define QSE_AWK_ISALPHA(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_ALPHA)
|
#define QSE_AWK_ISALPHA(awk,c) QSE_ISALPHA(c)
|
||||||
#define QSE_AWK_ISDIGIT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_DIGIT)
|
#define QSE_AWK_ISDIGIT(awk,c) QSE_ISDIGIT(c)
|
||||||
#define QSE_AWK_ISXDIGIT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_XDIGIT)
|
#define QSE_AWK_ISXDIGIT(awk,c) QSE_ISXDIGIT(c)
|
||||||
#define QSE_AWK_ISALNUM(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_ALNUM)
|
#define QSE_AWK_ISALNUM(awk,c) QSE_ISALNUM(c)
|
||||||
#define QSE_AWK_ISSPACE(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_SPACE)
|
#define QSE_AWK_ISSPACE(awk,c) QSE_ISSPACE(c)
|
||||||
#define QSE_AWK_ISPRINT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_PRINT)
|
#define QSE_AWK_ISPRINT(awk,c) QSE_ISPRINT(c)
|
||||||
#define QSE_AWK_ISGRAPH(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_GRAPH)
|
#define QSE_AWK_ISGRAPH(awk,c) QSE_ISGRAPH(c)
|
||||||
#define QSE_AWK_ISCNTRL(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_CNTRL)
|
#define QSE_AWK_ISCNTRL(awk,c) QSE_ISCNTRL(c)
|
||||||
#define QSE_AWK_ISPUNCT(awk,c) awk->prm.isccls(awk,c,QSE_CCLS_PUNCT)
|
#define QSE_AWK_ISPUNCT(awk,c) QSE_ISPUNCT(c)
|
||||||
#define QSE_AWK_TOUPPER(awk,c) awk->prm.toccls(awk,c,QSE_CCLS_UPPER)
|
#define QSE_AWK_TOUPPER(awk,c) QSE_TOUPPER(c)
|
||||||
#define QSE_AWK_TOLOWER(awk,c) awk->prm.toccls(awk,c,QSE_CCLS_LOWER)
|
#define QSE_AWK_TOLOWER(awk,c) QSE_TOLOWER(c)
|
||||||
|
|
||||||
#define QSE_AWK_STRDUP(awk,str) (qse_strdup(str,(awk)->mmgr))
|
#define QSE_AWK_STRDUP(awk,str) (qse_strdup(str,(awk)->mmgr))
|
||||||
#define QSE_AWK_STRXDUP(awk,str,len) (qse_strxdup(str,len,(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 */
|
/* primitive functions */
|
||||||
qse_awk_prm_t prm;
|
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 */
|
/* options */
|
||||||
int option;
|
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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -961,7 +961,7 @@ int qse_awk_matchrex (
|
|||||||
int err, x;
|
int err, x;
|
||||||
|
|
||||||
x = qse_matchrex (
|
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);
|
code, option, str, len, match_ptr, match_len, &err);
|
||||||
if (x < 0) *errnum = QSE_AWK_REXERRTOERR(err);
|
if (x < 0) *errnum = QSE_AWK_REXERRTOERR(err);
|
||||||
return x;
|
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.
|
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.pow != QSE_NULL, "Call qse_awk_setprm() first");
|
||||||
QSE_ASSERTX (awk->prm.sprintf != 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 */
|
/* clear the awk error code */
|
||||||
qse_awk_seterror (awk, QSE_AWK_ENOERR, 0, QSE_NULL);
|
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)
|
if (ret == -1 && rtx->errnum == QSE_AWK_ENOERR)
|
||||||
{
|
{
|
||||||
/* an error is returned with no error number set.
|
/* 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
|
* abort the evaluation when exit() is executed
|
||||||
* during function evaluation */
|
* during function evaluation */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -1374,7 +1372,7 @@ static int run_bpae_loop (qse_awk_rtx_t* rtx)
|
|||||||
if (ret == -1 && rtx->errnum == QSE_AWK_ENOERR)
|
if (ret == -1 && rtx->errnum == QSE_AWK_ENOERR)
|
||||||
{
|
{
|
||||||
/* an error is returned with no error number set.
|
/* 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
|
* abort the evaluation when exit() is executed
|
||||||
* during function evaluation */
|
* during function evaluation */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -1407,7 +1405,7 @@ static int run_bpae_loop (qse_awk_rtx_t* rtx)
|
|||||||
if (ret == -1 && rtx->errnum == QSE_AWK_ENOERR)
|
if (ret == -1 && rtx->errnum == QSE_AWK_ENOERR)
|
||||||
{
|
{
|
||||||
/* an error is returned with no error number set.
|
/* 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
|
* abort the evaluation when exit() is executed
|
||||||
* during function evaluation */
|
* during function evaluation */
|
||||||
ret = 0;
|
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.
|
/* 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;
|
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)
|
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;
|
if (val == QSE_NULL) return -1;
|
||||||
|
|
||||||
qse_awk_rtx_refdownval (run, STACK_RETVAL_GBL(run));
|
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);
|
qse_awk_rtx_refupval (run, val);
|
||||||
}
|
}
|
||||||
@ -4099,8 +4050,7 @@ static int __cmp_int_str (
|
|||||||
out.u.cpldup.ptr,
|
out.u.cpldup.ptr,
|
||||||
out.u.cpldup.len,
|
out.u.cpldup.len,
|
||||||
((qse_awk_val_str_t*)right)->ptr,
|
((qse_awk_val_str_t*)right)->ptr,
|
||||||
((qse_awk_val_str_t*)right)->len,
|
((qse_awk_val_str_t*)right)->len
|
||||||
&run->awk->ccls
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -4177,8 +4127,7 @@ static int __cmp_real_str (
|
|||||||
out.u.cpldup.ptr,
|
out.u.cpldup.ptr,
|
||||||
out.u.cpldup.len,
|
out.u.cpldup.len,
|
||||||
((qse_awk_val_str_t*)right)->ptr,
|
((qse_awk_val_str_t*)right)->ptr,
|
||||||
((qse_awk_val_str_t*)right)->len,
|
((qse_awk_val_str_t*)right)->len
|
||||||
&run->awk->ccls
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -4224,14 +4173,11 @@ static int __cmp_str_str (
|
|||||||
|
|
||||||
if (run->gbl.ignorecase)
|
if (run->gbl.ignorecase)
|
||||||
{
|
{
|
||||||
n = qse_strxncasecmp (
|
n = qse_strxncasecmp (ls->ptr, ls->len, rs->ptr, rs->len);
|
||||||
ls->ptr, ls->len, rs->ptr, rs->len,
|
|
||||||
&run->awk->ccls);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
n = qse_strxncmp (
|
n = qse_strxncmp (ls->ptr, ls->len, rs->ptr, rs->len);
|
||||||
ls->ptr, ls->len, rs->ptr, rs->len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
@ -5579,10 +5525,8 @@ static qse_awk_val_t* __eval_call (
|
|||||||
* ---------------------
|
* ---------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QSE_ASSERT (
|
QSE_ASSERT (QSE_SIZEOF(void*) >= QSE_SIZEOF(run->stack_top));
|
||||||
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_base));
|
|
||||||
|
|
||||||
saved_stack_top = run->stack_top;
|
saved_stack_top = run->stack_top;
|
||||||
|
|
||||||
@ -5729,11 +5673,29 @@ static qse_awk_val_t* __eval_call (
|
|||||||
v = STACK_RETVAL(run);
|
v = STACK_RETVAL(run);
|
||||||
if (n == -1)
|
if (n == -1)
|
||||||
{
|
{
|
||||||
if (errhandler != QSE_NULL)
|
if (run->errnum == QSE_AWK_ENOERR && errhandler != QSE_NULL)
|
||||||
{
|
{
|
||||||
/* capture_retval_on_exit takes advantage of
|
/* errhandler is passed only when __eval_call() is
|
||||||
* this handler to retrieve the return value
|
* invoked from qse_awk_rtx_call(). Under this
|
||||||
* when exit() is used to terminate the program. */
|
* 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);
|
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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -122,20 +122,6 @@ static int custom_awk_sprintf (
|
|||||||
return n;
|
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);
|
static int add_functions (qse_awk_t* awk);
|
||||||
|
|
||||||
qse_awk_t* qse_awk_openstd (qse_size_t xtnsize)
|
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.pow = custom_awk_pow;
|
||||||
prm.sprintf = custom_awk_sprintf;
|
prm.sprintf = custom_awk_sprintf;
|
||||||
prm.isccls = custom_awk_isccls;
|
|
||||||
prm.toccls = custom_awk_toccls;
|
|
||||||
|
|
||||||
/* create an object */
|
/* create an object */
|
||||||
awk = qse_awk_open (
|
awk = qse_awk_open (
|
||||||
|
@ -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.
|
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
|
#error unsupported character type
|
||||||
#endif
|
#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;
|
|
||||||
|
|
||||||
|
@ -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
|
|
@ -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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -17,8 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <qse/cmn/rex.h>
|
#include <qse/cmn/rex.h>
|
||||||
|
#include <qse/cmn/chr.h>
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "chr.h"
|
|
||||||
|
|
||||||
#ifdef DEBUG_REX
|
#ifdef DEBUG_REX
|
||||||
#include <qse/bas/sio.h>
|
#include <qse/bas/sio.h>
|
||||||
@ -113,7 +113,6 @@ struct builder_t
|
|||||||
struct matcher_t
|
struct matcher_t
|
||||||
{
|
{
|
||||||
qse_mmgr_t* mmgr;
|
qse_mmgr_t* mmgr;
|
||||||
qse_ccls_t* ccls;
|
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -230,18 +229,66 @@ static const qse_byte_t* match_occurrences (
|
|||||||
static qse_bool_t __test_charset (
|
static qse_bool_t __test_charset (
|
||||||
matcher_t* matcher, const qse_byte_t* p, qse_size_t csc, qse_char_t c);
|
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_isalnum (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);
|
return QSE_ISALNUM (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_isalpha (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);
|
return QSE_ISALPHA (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_isblank (qse_char_t c)
|
||||||
static qse_bool_t cc_isxdigit (qse_ccls_t* ccls, 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
|
#if 0
|
||||||
XXX
|
XXX
|
||||||
@ -254,7 +301,7 @@ struct __char_class_t
|
|||||||
{
|
{
|
||||||
const qse_char_t* name;
|
const qse_char_t* name;
|
||||||
qse_size_t name_len;
|
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[] =
|
static struct __char_class_t __char_class[] =
|
||||||
@ -349,7 +396,7 @@ void* qse_buildrex (
|
|||||||
}
|
}
|
||||||
|
|
||||||
int qse_matchrex (
|
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,
|
void* code, int option,
|
||||||
const qse_char_t* str, qse_size_t len,
|
const qse_char_t* str, qse_size_t len,
|
||||||
const qse_char_t** match_ptr, qse_size_t* match_len, int* errnum)
|
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;*/
|
/*const qse_char_t* match_ptr_zero = QSE_NULL;*/
|
||||||
|
|
||||||
matcher.mmgr = mmgr;
|
matcher.mmgr = mmgr;
|
||||||
matcher.ccls = ccls;
|
|
||||||
|
|
||||||
/* store the source string */
|
/* store the source string */
|
||||||
matcher.match.str.ptr = str;
|
matcher.match.str.ptr = str;
|
||||||
@ -1393,7 +1439,7 @@ static const qse_byte_t* match_ord_char (
|
|||||||
ubound = cp->ubound;
|
ubound = cp->ubound;
|
||||||
|
|
||||||
cc = *(qse_char_t*)p; p += QSE_SIZEOF(cc);
|
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
|
/* merge the same consecutive codes
|
||||||
* for example, a{1,10}a{0,10} is shortened to a{1,20} */
|
* 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 &&
|
while (p < mat->branch_end &&
|
||||||
cp->cmd == ((const code_t*)p)->cmd)
|
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;
|
lbound += ((const code_t*)p)->lbound;
|
||||||
ubound += ((const code_t*)p)->ubound;
|
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"),
|
QSE_T("match_ord_char: <ignorecase> %c %c\n"),
|
||||||
cc, mat->match_ptr[si]);
|
cc, mat->match_ptr[si]);
|
||||||
#endif
|
#endif
|
||||||
if (cc != QSE_CCLS_TOUPPER (matcher->ccls, mat->match_ptr[si])) break;
|
if (cc != QSE_TOUPPER (mat->match_ptr[si])) break;
|
||||||
si++;
|
si++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1507,7 +1553,7 @@ static const qse_byte_t* match_charset (
|
|||||||
if (&mat->match_ptr[si] >= matcher->match.str.end) break;
|
if (&mat->match_ptr[si] >= matcher->match.str.end) break;
|
||||||
|
|
||||||
c = mat->match_ptr[si];
|
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);
|
n = __test_charset (matcher, p, cshdr->csc, c);
|
||||||
if (cp->negate) n = !n;
|
if (cp->negate) n = !n;
|
||||||
@ -1772,7 +1818,7 @@ static qse_bool_t __test_charset (
|
|||||||
{
|
{
|
||||||
c1 = *(const qse_char_t*)p;
|
c1 = *(const qse_char_t*)p;
|
||||||
if (matcher->ignorecase)
|
if (matcher->ignorecase)
|
||||||
c1 = QSE_CCLS_TOUPPER(matcher->ccls, c1);
|
c1 = QSE_TOUPPER(c1);
|
||||||
#ifdef DEBUG_REX
|
#ifdef DEBUG_REX
|
||||||
qse_dprintf (
|
qse_dprintf (
|
||||||
QSE_T("match_charset: <one> %c %c\n"), c, c1);
|
QSE_T("match_charset: <one> %c %c\n"), c, c1);
|
||||||
@ -1787,8 +1833,8 @@ static qse_bool_t __test_charset (
|
|||||||
|
|
||||||
if (matcher->ignorecase)
|
if (matcher->ignorecase)
|
||||||
{
|
{
|
||||||
c1 = QSE_CCLS_TOUPPER(matcher->ccls, c1);
|
c1 = QSE_TOUPPER(c1);
|
||||||
c2 = QSE_CCLS_TOUPPER(matcher->ccls, c2);
|
c2 = QSE_TOUPPER(c2);
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_REX
|
#ifdef DEBUG_REX
|
||||||
qse_dprintf (
|
qse_dprintf (
|
||||||
@ -1804,8 +1850,7 @@ static qse_bool_t __test_charset (
|
|||||||
QSE_T("match_charset: <class> %c %s\n"),
|
QSE_T("match_charset: <class> %c %s\n"),
|
||||||
c, __char_class[c1].name);
|
c, __char_class[c1].name);
|
||||||
#endif
|
#endif
|
||||||
if (__char_class[c1].func (
|
if (__char_class[c1].func(c)) return QSE_TRUE;
|
||||||
matcher->ccls, c)) return QSE_TRUE;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1819,66 +1864,6 @@ static qse_bool_t __test_charset (
|
|||||||
return QSE_FALSE;
|
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
|
#if 0
|
||||||
#define DPRINTF awk->prmfns.misc.dprintf
|
#define DPRINTF awk->prmfns.misc.dprintf
|
||||||
#define DCUSTOM awk->prmfns.misc.custom_data
|
#define DCUSTOM awk->prmfns.misc.custom_data
|
||||||
|
@ -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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <qse/cmn/str.h>
|
#include <qse/cmn/str.h>
|
||||||
#include "chr.h"
|
#include <qse/cmn/chr.h>
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
|
||||||
qse_size_t qse_strlen (const qse_char_t* str)
|
qse_size_t qse_strlen (const qse_char_t* str)
|
||||||
@ -401,21 +401,20 @@ int qse_strxncmp (
|
|||||||
return (s2 < end2)? -1: 0;
|
return (s2 < end2)? -1: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int qse_strcasecmp (
|
int qse_strcasecmp (const qse_char_t* s1, const qse_char_t* s2)
|
||||||
const qse_char_t* s1, const qse_char_t* s2, qse_ccls_t* ccls)
|
|
||||||
{
|
{
|
||||||
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;
|
if (*s1 == QSE_C('\0')) return 0;
|
||||||
s1++, s2++;
|
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 (
|
int qse_strxncasecmp (
|
||||||
const qse_char_t* s1, qse_size_t len1,
|
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;
|
qse_char_t c1, c2;
|
||||||
const qse_char_t* end1 = s1 + len1;
|
const qse_char_t* end1 = s1 + len1;
|
||||||
@ -423,10 +422,10 @@ int qse_strxncasecmp (
|
|||||||
|
|
||||||
while (s1 < end1)
|
while (s1 < end1)
|
||||||
{
|
{
|
||||||
c1 = QSE_CCLS_TOUPPER (ccls, *s1);
|
c1 = QSE_TOUPPER (*s1);
|
||||||
if (s2 < end2)
|
if (s2 < end2)
|
||||||
{
|
{
|
||||||
c2 = QSE_CCLS_TOUPPER (ccls, *s2);
|
c2 = QSE_TOUPPER (*s2);
|
||||||
if (c1 > c2) return 1;
|
if (c1 > c2) return 1;
|
||||||
if (c1 < c2) return -1;
|
if (c1 < c2) return -1;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -17,9 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <qse/cmn/str.h>
|
#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* s, const qse_char_t* delim,
|
||||||
qse_char_t lquote, qse_char_t rquote,
|
qse_char_t lquote, qse_char_t rquote,
|
||||||
qse_char_t escape, const qse_char_t* trset)
|
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* s, const qse_char_t* delim,
|
||||||
qse_char_t lquote, qse_char_t rquote, qse_char_t escape)
|
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;
|
||||||
}
|
}
|
||||||
|
@ -25,20 +25,6 @@ qse_lsp_t* qse_lsp_open (
|
|||||||
if (prmfns->mmgr.malloc == QSE_NULL ||
|
if (prmfns->mmgr.malloc == QSE_NULL ||
|
||||||
prmfns->mmgr.realloc == QSE_NULL ||
|
prmfns->mmgr.realloc == QSE_NULL ||
|
||||||
prmfns->mmgr.free == QSE_NULL) return 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 ||
|
if (prmfns->misc.sprintf == QSE_NULL ||
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#define _QSE_LIB_LSP_LSP_H_
|
#define _QSE_LIB_LSP_LSP_H_
|
||||||
|
|
||||||
#include "../cmn/mem.h"
|
#include "../cmn/mem.h"
|
||||||
#include "../cmn/chr.h"
|
#include <qse/cmn/chr.h>
|
||||||
#include <qse/cmn/str.h>
|
#include <qse/cmn/str.h>
|
||||||
|
|
||||||
#include <qse/lsp/lsp.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_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_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_ISUPPER(lsp,c) QSE_ISUPPER(c)
|
||||||
#define QSE_LSP_ISLOWER(lsp,c) QSE_CCLS_ISLOWER(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_ISLOWER(lsp,c) QSE_ISLOWER(c)
|
||||||
#define QSE_LSP_ISALPHA(lsp,c) QSE_CCLS_ISALPHA(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_ISALPHA(lsp,c) QSE_ISALPHA(c)
|
||||||
#define QSE_LSP_ISDIGIT(lsp,c) QSE_CCLS_ISDIGIT(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_ISDIGIT(lsp,c) QSE_ISDIGIT(c)
|
||||||
#define QSE_LSP_ISXDIGIT(lsp,c) QSE_CCLS_ISXDIGIT(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_ISXDIGIT(lsp,c) QSE_ISXDIGIT(c)
|
||||||
#define QSE_LSP_ISALNUM(lsp,c) QSE_CCLS_ISALNUM(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_ISALNUM(lsp,c) QSE_ISALNUM(c)
|
||||||
#define QSE_LSP_ISSPACE(lsp,c) QSE_CCLS_ISSPACE(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_ISSPACE(lsp,c) QSE_ISSPACE(c)
|
||||||
#define QSE_LSP_ISPRINT(lsp,c) QSE_CCLS_ISPRINT(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_ISPRINT(lsp,c) QSE_ISPRINT(c)
|
||||||
#define QSE_LSP_ISGRAPH(lsp,c) QSE_CCLS_ISGRAPH(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_ISGRAPH(lsp,c) QSE_ISGRAPH(c)
|
||||||
#define QSE_LSP_ISCNTRL(lsp,c) QSE_CCLS_ISCNTRL(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_ISCNTRL(lsp,c) QSE_ISCNTRL(c)
|
||||||
#define QSE_LSP_ISPUNCT(lsp,c) QSE_CCLS_ISPUNCT(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_ISPUNCT(lsp,c) QSE_ISPUNCT(c)
|
||||||
#define QSE_LSP_TOUPPER(lsp,c) QSE_CCLS_TOUPPER(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_TOUPPER(lsp,c) QSE_TOUPPER(c)
|
||||||
#define QSE_LSP_TOLOWER(lsp,c) QSE_CCLS_TOLOWER(&(lsp)->prmfns.ccls,c)
|
#define QSE_LSP_TOLOWER(lsp,c) QSE_TOLOWER(c)
|
||||||
|
|
||||||
struct qse_lsp_t
|
struct qse_lsp_t
|
||||||
{
|
{
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <qse/utl/http.h>
|
#include <qse/utl/http.h>
|
||||||
|
#include <qse/cmn/chr.h>
|
||||||
#include "../cmn/mem.h"
|
#include "../cmn/mem.h"
|
||||||
#include "../cmn/chr.h"
|
|
||||||
|
|
||||||
static int is_http_space (qse_char_t c)
|
static int is_http_space (qse_char_t c)
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ QSE_IMPLEMENT_COMMON_FUNCTIONS (sed)
|
|||||||
|
|
||||||
static void free_command (qse_sed_t* sed, qse_sed_cmd_t* cmd);
|
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;
|
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);
|
sed = (qse_sed_t*) QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_sed_t) + xtn);
|
||||||
if (sed == QSE_NULL) return QSE_NULL;
|
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);
|
QSE_MMGR_FREE (sed->mmgr, sed);
|
||||||
return QSE_NULL;
|
return QSE_NULL;
|
||||||
@ -59,7 +59,7 @@ void qse_sed_close (qse_sed_t* sed)
|
|||||||
QSE_MMGR_FREE (sed->mmgr, 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));
|
QSE_MEMSET (sed, 0, sizeof(*sed));
|
||||||
sed->mmgr = mmgr;
|
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;
|
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;
|
return sed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,11 +166,6 @@ int qse_sed_getoption (qse_sed_t* sed)
|
|||||||
return sed->option;
|
return sed->option;
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_ccls_t* qse_sed_getccls (qse_sed_t* sed)
|
|
||||||
{
|
|
||||||
return &sed->ccls;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the current charanter of the source code */
|
/* get the current charanter of the source code */
|
||||||
#define CURSC(sed) \
|
#define CURSC(sed) \
|
||||||
(((sed)->src.cur < (sed)->src.end)? (*(sed)->src.cur): QSE_CHAR_EOF)
|
(((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 (
|
n = qse_matchrex (
|
||||||
sed->mmgr,
|
sed->mmgr,
|
||||||
&sed->ccls,
|
|
||||||
0,
|
0,
|
||||||
cmd->a1.u.rex,
|
cmd->a1.u.rex,
|
||||||
0,
|
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);
|
QSE_ASSERT (cmd->a2.u.rex != QSE_NULL);
|
||||||
n = qse_matchrex (
|
n = qse_matchrex (
|
||||||
sed->mmgr,
|
sed->mmgr,
|
||||||
&sed->ccls,
|
|
||||||
0,
|
0,
|
||||||
cmd->a2.u.rex,
|
cmd->a2.u.rex,
|
||||||
0,
|
0,
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <qse/utl/stdio.h>
|
#include <qse/utl/stdio.h>
|
||||||
#include "../cmn/chr.h"
|
#include <qse/cmn/chr.h>
|
||||||
|
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -16,11 +16,10 @@
|
|||||||
static int test1 (void)
|
static int test1 (void)
|
||||||
{
|
{
|
||||||
qse_char_t c;
|
qse_char_t c;
|
||||||
qse_ccls_t* ccls = QSE_CCLS_GETDFL();
|
|
||||||
|
|
||||||
for (c = QSE_T('a'); c <= QSE_T('z'); c++)
|
for (c = QSE_T('a'); c <= QSE_T('z'); c++)
|
||||||
{
|
{
|
||||||
qse_printf (QSE_T("%c => %c\n"), c, QSE_CCLS_TOUPPER(ccls,c));
|
qse_printf (QSE_T("%c => %c\n"), c, QSE_TOUPPER(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -193,7 +193,7 @@ static int comp_key (qse_map_t* map,
|
|||||||
const void* kptr1, qse_size_t klen1,
|
const void* kptr1, qse_size_t klen1,
|
||||||
const void* kptr2, qse_size_t klen2)
|
const void* kptr2, qse_size_t klen2)
|
||||||
{
|
{
|
||||||
return qse_strxncasecmp (kptr1, klen1, kptr2, klen2, QSE_CCLS_GETDFL());
|
return qse_strxncasecmp (kptr1, klen1, kptr2, klen2);
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_map_walk_t print_map_pair_3 (qse_map_t* map, qse_map_pair_t* pair, void* arg)
|
qse_map_walk_t print_map_pair_3 (qse_map_t* map, qse_map_pair_t* pair, void* arg)
|
||||||
|
@ -508,6 +508,25 @@ static int test11 (void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int test12 (void)
|
||||||
|
{
|
||||||
|
qse_char_t a1[] = QSE_T(" this is a test string ");
|
||||||
|
qse_char_t a2[] = QSE_T(" this is a test string ");
|
||||||
|
qse_char_t a3[] = QSE_T(" this is a test string ");
|
||||||
|
|
||||||
|
qse_printf (QSE_T("[%s] =>"), a1);
|
||||||
|
qse_printf (QSE_T("[%s]\n"), qse_strtrm (a1, QSE_STRTRM_LEFT));
|
||||||
|
|
||||||
|
qse_printf (QSE_T("[%s] =>"), a2);
|
||||||
|
qse_printf (QSE_T("[%s]\n"), qse_strtrm (a2, QSE_STRTRM_RIGHT));
|
||||||
|
|
||||||
|
qse_printf (QSE_T("[%s] =>"), a3);
|
||||||
|
qse_printf (QSE_T("[%s]\n"),
|
||||||
|
qse_strtrm (a3, QSE_STRTRM_LEFT|QSE_STRTRM_RIGHT));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
{
|
{
|
||||||
setlocale (LC_ALL, "");
|
setlocale (LC_ALL, "");
|
||||||
@ -527,6 +546,7 @@ int main ()
|
|||||||
R (test9);
|
R (test9);
|
||||||
R (test10);
|
R (test10);
|
||||||
R (test11);
|
R (test11);
|
||||||
|
R (test12);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user