From c221321cdae6b8fa9a449879f4c4a3379412c348 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 8 May 2009 07:15:04 +0000 Subject: [PATCH] removed qse_ccls_t and related functions and added qse_strtrm() --- qse/cmd/lsp/lsp.c | 3 - qse/doc/robodoc.rc | 2 +- qse/include/qse/awk/Awk.hpp | 34 +------ qse/include/qse/awk/StdAwk.hpp | 5 +- qse/include/qse/awk/awk.h | 31 +------ qse/include/qse/cmn/chr.h | 95 +++++++++++++++----- qse/include/qse/cmn/rex.h | 4 +- qse/include/qse/cmn/str.h | 118 +++++++++++++++++------- qse/include/qse/lsp/lsp.h | 1 - qse/include/qse/types.h | 44 +-------- qse/include/qse/utl/sed.h | 33 +------ qse/lib/awk/Awk.cpp | 16 +--- qse/lib/awk/StdAwk.cpp | 13 +-- qse/lib/awk/awk.c | 18 +--- qse/lib/awk/awk.h | 36 ++++---- qse/lib/awk/misc.c | 4 +- qse/lib/awk/run.c | 106 +++++++--------------- qse/lib/awk/std.c | 18 +--- qse/lib/cmn/chr.c | 20 +---- qse/lib/cmn/chr.h | 82 ----------------- qse/lib/cmn/rex.c | 159 +++++++++++++++------------------ qse/lib/cmn/str_bas.c | 17 ++-- qse/lib/cmn/str_utl.c | 33 ++++++- qse/lib/lsp/lsp.c | 14 --- qse/lib/lsp/lsp.h | 28 +++--- qse/lib/utl/http.c | 2 +- qse/lib/utl/sed.c | 18 +--- qse/lib/utl/stdio.c | 2 +- qse/test/cmn/chr.c | 3 +- qse/test/cmn/map.c | 2 +- qse/test/cmn/str.c | 20 +++++ 31 files changed, 372 insertions(+), 609 deletions(-) delete mode 100644 qse/lib/cmn/chr.h diff --git a/qse/cmd/lsp/lsp.c b/qse/cmd/lsp/lsp.c index 5e334a32..d5a756cc 100644 --- a/qse/cmd/lsp/lsp.c +++ b/qse/cmd/lsp/lsp.c @@ -247,9 +247,6 @@ int lsp_main (int argc, qse_char_t* argv[]) prmfns.mmgr.data = QSE_NULL; #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.dprintf = custom_lsp_dprintf; prmfns.misc.data = QSE_NULL; diff --git a/qse/doc/robodoc.rc b/qse/doc/robodoc.rc index c43c7cca..f1018a94 100644 --- a/qse/doc/robodoc.rc +++ b/qse/doc/robodoc.rc @@ -57,7 +57,7 @@ options: --cmode --nopre --documenttitle "QSE" - --source_line_numbers +# --source_line_numbers --tabsize 4 --sections --toc "no" diff --git a/qse/include/qse/awk/Awk.hpp b/qse/include/qse/awk/Awk.hpp index 471300d2..20b7f8d4 100644 --- a/qse/include/qse/awk/Awk.hpp +++ b/qse/include/qse/awk/Awk.hpp @@ -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. @@ -54,7 +54,6 @@ public: typedef qse_map_pair_t pair_t; typedef qse_mmgr_t mmgr_t; - typedef qse_ccls_t ccls_t; /** Represents an internal awk value */ typedef qse_awk_val_t val_t; @@ -68,21 +67,6 @@ public: /** Represents an runtime I/O data */ 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. * An instance of Awk::Source is passed to Awk::openSource, @@ -774,16 +758,6 @@ public: return qse_awk_getmmgr (awk); } - ccls_t* getCcls() - { - return qse_awk_getccls (awk); - } - - const ccls_t* getCcls() const - { - return qse_awk_getccls (awk); - } - protected: void setError (ErrorCode code); void setError (ErrorCode code, size_t line); @@ -1052,9 +1026,6 @@ protected: virtual void* reallocMem (void* ptr, size_t n) = 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 int vsprintf (char_t* buf, size_t size, 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 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 int sprintf (awk_t* data, char_t* buf, size_t size, const char_t* fmt, ...); diff --git a/qse/include/qse/awk/StdAwk.hpp b/qse/include/qse/awk/StdAwk.hpp index 44f5e7a7..b2c180ee 100644 --- a/qse/include/qse/awk/StdAwk.hpp +++ b/qse/include/qse/awk/StdAwk.hpp @@ -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. @@ -84,9 +84,6 @@ protected: void* reallocMem (void* ptr, size_t n); 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); int vsprintf (char_t* buf, size_t size, const char_t* fmt, va_list arg); diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index d6f05279..e74b5f5f 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -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. @@ -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 * NAME * 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_sprintf_t sprintf; - qse_awk_isccls_t isccls; - qse_awk_toccls_t toccls; #if 0 /* 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 * NAME * qse_awk_clear - clear a qse_awk_t object diff --git a/qse/include/qse/cmn/chr.h b/qse/include/qse/cmn/chr.h index ed691916..dafb5814 100644 --- a/qse/include/qse/cmn/chr.h +++ b/qse/include/qse/cmn/chr.h @@ -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. @@ -22,35 +22,82 @@ #include #include -/* gets a pointer to the default memory manager */ -#define QSE_CCLS_GETDFL() (qse_ccls) +/****t* Common/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; +/******/ -/* sets a pointer to the default memory manager */ -#define QSE_CCLS_SETDFL(m) ((qse_ccls)=(m)) - -#define QSE_CCLS_IS(ccls,c,type) ((ccls)->is((ccls)->data,c,type)) -#define QSE_CCLS_TO(ccls,c,type) ((ccls)->to((ccls)->data,c,type)) - -#define QSE_CCLS_ISUPPER(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_UPPER) -#define QSE_CCLS_ISLOWER(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_LOWER) -#define QSE_CCLS_ISALPHA(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_ALPHA) -#define QSE_CCLS_ISDIGIT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_DIGIT) -#define QSE_CCLS_ISXDIGIT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_XDIGIT) -#define QSE_CCLS_ISALNUM(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_ALNUM) -#define QSE_CCLS_ISSPACE(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_SPACE) -#define QSE_CCLS_ISPRINT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_PRINT) -#define QSE_CCLS_ISGRAPH(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_GRAPH) -#define QSE_CCLS_ISCNTRL(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_CNTRL) -#define QSE_CCLS_ISPUNCT(ccls,c) QSE_CCLS_IS(ccls,c,QSE_CCLS_PUNCT) -#define QSE_CCLS_TOUPPER(ccls,c) QSE_CCLS_TO(ccls,c,QSE_CCLS_UPPER) -#define QSE_CCLS_TOLOWER(ccls,c) QSE_CCLS_TO(ccls,c,QSE_CCLS_LOWER) +#ifdef USE_STDC +# if defined(QSE_CHAR_IS_MCHAR) +# include +# 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 +# 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 extern "C" { #endif -extern qse_ccls_t* qse_ccls; - qse_bool_t qse_ccls_is ( qse_cint_t c, qse_ccls_id_t type diff --git a/qse/include/qse/cmn/rex.h b/qse/include/qse/cmn/rex.h index a82b2f5d..cbbae052 100644 --- a/qse/include/qse/cmn/rex.h +++ b/qse/include/qse/cmn/rex.h @@ -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. @@ -86,7 +86,7 @@ void* qse_buildrex ( const qse_char_t* ptn, qse_size_t len, int* errnum); 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); diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index 4aa2b407..77f59707 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -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. @@ -109,6 +109,12 @@ struct qse_str_t if (__ston_f > 0) value *= -1; \ } +enum qse_strtrm_opt_t +{ + QSE_STRTRM_LEFT = (1 << 0), + QSE_STRTRM_RIGHT = (1 << 1) +}; + #ifdef __cplusplus extern "C" { #endif @@ -238,8 +244,7 @@ int qse_strxncmp ( const qse_char_t* s1, qse_size_t len1, const qse_char_t* s2, qse_size_t len2); -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); /****f* Common/qse_strxncasecmp * NAME @@ -248,9 +253,7 @@ int qse_strcasecmp ( * The qse_strxncasecmp() function compares characters at the same position * in each string after converting them to the same case temporarily. * It accepts two strings and a character class handler. A string is - * represented by its beginning pointer and length. You can write your own - * character class handler or use QSE_CCLS_GETDFL() to get the default - * character class handler. + * represented by its beginning pointer and length. * * 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 @@ -259,15 +262,15 @@ int qse_strcasecmp ( * 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. * 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 */ int qse_strxncasecmp ( const qse_char_t* s1 /* the pointer to the first string */, qse_size_t len1 /* the length of the first string */, const qse_char_t* s2 /* the pointer to the second string */, - qse_size_t len2 /* the length of the second string */, - qse_ccls_t* ccls /* character class handler */ + qse_size_t len2 /* the length of the second string */ ); /******/ @@ -396,6 +399,7 @@ int qse_str_yield ( * qse_str_getsizer - get the sizer * RETURN * a sizer function set or QSE_NULL if no sizer is set. + * SYNOPSIS */ qse_str_sizer_t qse_str_getsizer ( qse_str_t* str @@ -428,6 +432,7 @@ void qse_str_setsizer ( * You may use QSE_STR_CAPA(str) macro for performance sake. * RETURNS * current capacity in number of characters. + * SYNOPSIS */ qse_size_t qse_str_getcapa ( qse_str_t* str @@ -443,6 +448,7 @@ qse_size_t qse_str_getcapa ( * from the buffer. * RETURNS * (qse_size_t)-1 on failure, new capacity on success + * SYNOPSIS */ qse_size_t qse_str_setcapa ( qse_str_t* str, @@ -453,6 +459,7 @@ qse_size_t qse_str_setcapa ( /****f* Common/qse_str_getlen * NAME * qse_str_getlen - get length + * SYNOPSIS */ qse_size_t qse_str_getlen ( qse_str_t* str @@ -464,6 +471,7 @@ qse_size_t qse_str_getlen ( * qse_str_setlen - change length * RETURNS * (qse_size_t)-1 on failure, new length on success + * SYNOPSIS */ qse_size_t qse_str_setlen ( qse_str_t* str, @@ -477,6 +485,7 @@ qse_size_t qse_str_setlen ( * DESCRIPTION * The qse_str_clear() funtion deletes all characters in a string and sets * the length to 0. It doesn't resize the internal buffer. + * SYNOPSIS */ void qse_str_clear ( qse_str_t* str @@ -489,6 +498,7 @@ void qse_str_clear ( * DESCRIPTION * The qse_str_swap() function exchanges the pointers to a buffer between * two strings. It updates the length and the capacity accordingly. + * SYNOPSIS */ void qse_str_swap ( qse_str_t* str1, @@ -529,37 +539,77 @@ qse_size_t qse_str_nccat ( qse_size_t len ); -/****f* Common/qse_strspltr +/****f* Common/qse_strspl * 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 - * 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 * first character in a pair is translated into the second character * 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 abcdef where is a carriage return and is a + * new line. + * SEE ALSO + * If you don't need any translation, you may call qse_strspl() alternatively. * SYNOPSIS */ -int qse_strspltr ( - qse_char_t* str, +int qse_strspltrn ( + qse_char_t* str, const qse_char_t* delim, - qse_char_t lquote, + qse_char_t lquote, qse_char_t rquote, - qse_char_t escape, + qse_char_t escape, const qse_char_t* trset ); /******/ -/****f* Common/qse_strspl +/****f* Common/qse_strtrm * 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 */ -int qse_strspl ( - qse_char_t* str, - const qse_char_t* delim, - qse_char_t lquote, - qse_char_t rquote, - qse_char_t escape +qse_char_t* qse_strtrm ( + qse_char_t* str, + int opt ); /******/ @@ -569,8 +619,8 @@ int qse_strspl ( * SYNOPSIS */ qse_size_t qse_mbstowcs ( - const qse_mchar_t* mbs, - qse_wchar_t* wcs, + const qse_mchar_t* mbs, + qse_wchar_t* wcs, qse_size_t* wcslen ); /******/ @@ -583,9 +633,9 @@ qse_size_t qse_mbstowcs ( * SYNOPSIS */ qse_size_t qse_mbsntowcsn ( - const qse_mchar_t* mbs, + const qse_mchar_t* mbs, qse_size_t mbslen, - qse_wchar_t* wcs, + qse_wchar_t* wcs, qse_size_t* wcslen ); /******/ @@ -646,8 +696,8 @@ qse_size_t qse_wcsntombsnlen ( * SYNOPSIS */ qse_size_t qse_wcstombs ( - const qse_wchar_t* wcs, - qse_mchar_t* mbs, + const qse_wchar_t* wcs, + qse_mchar_t* mbs, qse_size_t* mbslen ); /******/ @@ -660,9 +710,9 @@ qse_size_t qse_wcstombs ( * SYNOPSIS */ qse_size_t qse_wcsntombsn ( - const qse_wchar_t* wcs, + const qse_wchar_t* wcs, qse_size_t wcslen, - qse_mchar_t* mbs, + qse_mchar_t* mbs, qse_size_t* mbslen ); /******/ @@ -679,8 +729,8 @@ qse_size_t qse_wcsntombsn ( * SYNOPSIS */ int qse_wcstombs_strict ( - const qse_wchar_t* wcs, - qse_mchar_t* mbs, + const qse_wchar_t* wcs, + qse_mchar_t* mbs, qse_size_t mbslen ); /******/ diff --git a/qse/include/qse/lsp/lsp.h b/qse/include/qse/lsp/lsp.h index 70e5c4ba..23ce0d8e 100644 --- a/qse/include/qse/lsp/lsp.h +++ b/qse/include/qse/lsp/lsp.h @@ -48,7 +48,6 @@ typedef void (*qse_lsp_dprintf_t) (void* data, const qse_char_t* fmt, ...); struct qse_lsp_prmfns_t { qse_mmgr_t mmgr; - qse_ccls_t ccls; /* utilities */ struct diff --git a/qse/include/qse/types.h b/qse/include/qse/types.h index 7cda3b29..6665440e 100644 --- a/qse/include/qse/types.h +++ b/qse/include/qse/types.h @@ -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. @@ -419,46 +419,4 @@ struct 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 diff --git a/qse/include/qse/utl/sed.h b/qse/include/qse/utl/sed.h index 41c00d31..62ea8132 100644 --- a/qse/include/qse/utl/sed.h +++ b/qse/include/qse/utl/sed.h @@ -85,42 +85,15 @@ typedef qse_ssize_t (*qse_sed_iof_t) ( 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 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 { QSE_DEFINE_COMMON_FIELDS (sed) qse_sed_errnum_t errnum; int option; - qse_ccls_t ccls; - /* source code pointers */ struct { @@ -191,8 +164,7 @@ QSE_DEFINE_COMMON_FUNCTIONS (sed) */ qse_sed_t* qse_sed_open ( qse_mmgr_t* mmgr, - qse_size_t xtn, - qse_sed_prm_t* prm + qse_size_t xtn ); /******/ @@ -213,8 +185,7 @@ void qse_sed_close ( */ qse_sed_t* qse_sed_init ( qse_sed_t* sed, - qse_mmgr_t* mmgr, - qse_sed_prm_t* prm + qse_mmgr_t* mmgr ); /******/ diff --git a/qse/lib/awk/Awk.cpp b/qse/lib/awk/Awk.cpp index 7fb2d470..ed09bd3c 100644 --- a/qse/lib/awk/Awk.cpp +++ b/qse/lib/awk/Awk.cpp @@ -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); diff --git a/qse/lib/awk/StdAwk.cpp b/qse/lib/awk/StdAwk.cpp index 5fde041c..cbf455e1 100644 --- a/qse/lib/awk/StdAwk.cpp +++ b/qse/lib/awk/StdAwk.cpp @@ -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) { diff --git a/qse/lib/awk/awk.c b/qse/lib/awk/awk.c index 32c184cb..423d9bd8 100644 --- a/qse/lib/awk/awk.c +++ b/qse/lib/awk/awk.c @@ -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; diff --git a/qse/lib/awk/awk.h b/qse/lib/awk/awk.h index c58b75cc..7294ea8c 100644 --- a/qse/lib/awk/awk.h +++ b/qse/lib/awk/awk.h @@ -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 #include #include #include @@ -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 +#include #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; diff --git a/qse/lib/awk/misc.c b/qse/lib/awk/misc.c index 427735c7..eefa781e 100644 --- a/qse/lib/awk/misc.c +++ b/qse/lib/awk/misc.c @@ -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; diff --git a/qse/lib/awk/run.c b/qse/lib/awk/run.c index 4648ff67..a6ef333b 100644 --- a/qse/lib/awk/run.c +++ b/qse/lib/awk/run.c @@ -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); } diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index db8fd13a..d07ff3a7 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -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 ( diff --git a/qse/lib/cmn/chr.c b/qse/lib/cmn/chr.c index 9b79070c..78d3c2c2 100644 --- a/qse/lib/cmn/chr.c +++ b/qse/lib/cmn/chr.c @@ -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; diff --git a/qse/lib/cmn/chr.h b/qse/lib/cmn/chr.h deleted file mode 100644 index 4a4db959..00000000 --- a/qse/lib/cmn/chr.h +++ /dev/null @@ -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 - -#ifdef USE_STDC - - #if defined(QSE_CHAR_IS_MCHAR) - - #include - #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 - #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 diff --git a/qse/lib/cmn/rex.c b/qse/lib/cmn/rex.c index c5890e67..2d8e1361 100644 --- a/qse/lib/cmn/rex.c +++ b/qse/lib/cmn/rex.c @@ -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 +#include #include "mem.h" -#include "chr.h" #ifdef DEBUG_REX #include @@ -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: %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: %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: %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 diff --git a/qse/lib/cmn/str_bas.c b/qse/lib/cmn/str_bas.c index 6cac9f5f..06683b2f 100644 --- a/qse/lib/cmn/str_bas.c +++ b/qse/lib/cmn/str_bas.c @@ -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 -#include "chr.h" +#include #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; } diff --git a/qse/lib/cmn/str_utl.c b/qse/lib/cmn/str_utl.c index cf036c12..20e33879 100644 --- a/qse/lib/cmn/str_utl.c +++ b/qse/lib/cmn/str_utl.c @@ -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 -#include "chr.h" +#include -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; } diff --git a/qse/lib/lsp/lsp.c b/qse/lib/lsp/lsp.c index 3b978d56..5f9b8ed4 100644 --- a/qse/lib/lsp/lsp.c +++ b/qse/lib/lsp/lsp.c @@ -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 || diff --git a/qse/lib/lsp/lsp.h b/qse/lib/lsp/lsp.h index 616198c6..43171a6b 100644 --- a/qse/lib/lsp/lsp.h +++ b/qse/lib/lsp/lsp.h @@ -8,7 +8,7 @@ #define _QSE_LIB_LSP_LSP_H_ #include "../cmn/mem.h" -#include "../cmn/chr.h" +#include #include #include @@ -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 { diff --git a/qse/lib/utl/http.c b/qse/lib/utl/http.c index 22b2f24a..c43b9ec8 100644 --- a/qse/lib/utl/http.c +++ b/qse/lib/utl/http.c @@ -5,8 +5,8 @@ */ #include +#include #include "../cmn/mem.h" -#include "../cmn/chr.h" static int is_http_space (qse_char_t c) { diff --git a/qse/lib/utl/sed.c b/qse/lib/utl/sed.c index 88c10645..ac0575d5 100644 --- a/qse/lib/utl/sed.c +++ b/qse/lib/utl/sed.c @@ -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, diff --git a/qse/lib/utl/stdio.c b/qse/lib/utl/stdio.c index b26ff89c..abc61e48 100644 --- a/qse/lib/utl/stdio.c +++ b/qse/lib/utl/stdio.c @@ -5,7 +5,7 @@ */ #include -#include "../cmn/chr.h" +#include #include #include diff --git a/qse/test/cmn/chr.c b/qse/test/cmn/chr.c index 72728185..e0498d84 100644 --- a/qse/test/cmn/chr.c +++ b/qse/test/cmn/chr.c @@ -16,11 +16,10 @@ static int test1 (void) { qse_char_t c; - qse_ccls_t* ccls = QSE_CCLS_GETDFL(); 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; diff --git a/qse/test/cmn/map.c b/qse/test/cmn/map.c index f631332f..55cb9711 100644 --- a/qse/test/cmn/map.c +++ b/qse/test/cmn/map.c @@ -193,7 +193,7 @@ static int comp_key (qse_map_t* map, const void* kptr1, qse_size_t klen1, 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) diff --git a/qse/test/cmn/str.c b/qse/test/cmn/str.c index a1348702..3023b9dc 100644 --- a/qse/test/cmn/str.c +++ b/qse/test/cmn/str.c @@ -508,6 +508,25 @@ static int test11 (void) 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 () { setlocale (LC_ALL, ""); @@ -527,6 +546,7 @@ int main () R (test9); R (test10); R (test11); + R (test12); return 0; }