From da61cde8fdf9a49c12f805a41bbd2ce06771b255 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 30 Dec 2008 04:49:25 +0000 Subject: [PATCH] finished interim implementation of qse_timegm() and qse_timelocal(). - currently, they use timegm() and timelocal() provided by libc. added test programs. --- qse/Makefile.am | 8 +- qse/Makefile.in | 9 +- qse/README | 9 +- qse/cmd/awk/Awk.cpp | 22 +- qse/configure | 99 +++++- qse/configure.ac | 6 +- qse/doc/robodoc.rc | 2 + qse/include/qse/awk/Awk.hpp | 25 +- qse/include/qse/awk/StdAwk.hpp | 24 +- qse/include/qse/awk/awk.h | 67 ++-- qse/include/qse/cmn/str.h | 3 +- qse/include/qse/config.h.in | 6 + qse/lib/awk/Awk.cpp | 26 +- qse/lib/awk/Makefile.am | 2 +- qse/lib/awk/Makefile.in | 2 +- qse/lib/awk/StdAwk.cpp | 115 ++----- qse/lib/awk/awk.h | 19 +- qse/lib/awk/extio.c | 4 +- qse/lib/awk/extio.h | 16 +- qse/lib/awk/func.c | 41 ++- qse/lib/awk/func.h | 14 +- qse/lib/awk/misc.h | 14 +- qse/lib/awk/parse.c | 14 +- qse/lib/awk/parse.h | 14 +- qse/lib/awk/rec.c | 4 +- qse/lib/awk/run.c | 56 ++-- qse/lib/awk/run.h | 14 +- qse/lib/awk/std.c | 205 ++++++++----- qse/lib/awk/tree.c | 8 +- qse/lib/awk/tree.h | 22 +- qse/lib/awk/val.c | 40 +-- qse/lib/cmn/time.c | 68 ++++- qse/lib/lsp/Makefile.am | 2 +- qse/lib/lsp/Makefile.in | 2 +- qse/test/Makefile.am | 1 + qse/test/Makefile.in | 498 ++++++++++++++++++++++++++++++ qse/test/cmn/Makefile.am | 15 + qse/test/cmn/Makefile.in | 544 +++++++++++++++++++++++++++++++++ qse/test/cmn/chr.c | 156 ++++++++++ qse/test/cmn/fio.c | 207 +++++++++++++ qse/test/cmn/lda.c | 369 ++++++++++++++++++++++ qse/test/cmn/map.c | 307 +++++++++++++++++++ qse/test/cmn/sio.c | 86 ++++++ qse/test/cmn/sll.c | 65 ++++ qse/test/cmn/str.c | 436 ++++++++++++++++++++++++++ qse/test/cmn/time.c | 105 +++++++ 46 files changed, 3415 insertions(+), 356 deletions(-) create mode 100644 qse/test/Makefile.am create mode 100644 qse/test/Makefile.in create mode 100644 qse/test/cmn/Makefile.am create mode 100644 qse/test/cmn/Makefile.in create mode 100644 qse/test/cmn/chr.c create mode 100644 qse/test/cmn/fio.c create mode 100644 qse/test/cmn/lda.c create mode 100644 qse/test/cmn/map.c create mode 100644 qse/test/cmn/sio.c create mode 100644 qse/test/cmn/sll.c create mode 100644 qse/test/cmn/str.c create mode 100644 qse/test/cmn/time.c diff --git a/qse/Makefile.am b/qse/Makefile.am index 27ee99a7..8ecc0f74 100644 --- a/qse/Makefile.am +++ b/qse/Makefile.am @@ -1,15 +1,9 @@ -############################################################################## -# -# ASE -# Copyright (c) Chung,Hyung-Hwan (bacon@abiyo.net) -# -############################################################################## AUTOMAKE_OPTION = foreign # EXTRA_DIST = SUBDIRS = lib cmd -DIST_SUBDIRS = $(SUBDIRS) include +DIST_SUBDIRS = $(__COREDIRS) include test install-data-hook: cd include && $(MAKE) install diff --git a/qse/Makefile.in b/qse/Makefile.in index a1d1ca32..d89143e7 100644 --- a/qse/Makefile.in +++ b/qse/Makefile.in @@ -13,13 +13,6 @@ # PARTICULAR PURPOSE. @SET_MAKE@ - -############################################################################## -# -# ASE -# Copyright (c) Chung,Hyung-Hwan (bacon@abiyo.net) -# -############################################################################## VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -204,7 +197,7 @@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTION = foreign # EXTRA_DIST = SUBDIRS = lib cmd -DIST_SUBDIRS = $(SUBDIRS) include +DIST_SUBDIRS = $(__COREDIRS) include test all: all-recursive .SUFFIXES: diff --git a/qse/README b/qse/README index a3db0cfd..b01247d6 100644 --- a/qse/README +++ b/qse/README @@ -1 +1,8 @@ -QSE + +QSE is a script engine library designed to be embedded into an application. + +[INSTALL] + +Cross compiling for WIN32 with MINGW32 +./configure --host=i586-mingw32msvc --target=i586-mingw32msvc --enable-syscall +make diff --git a/qse/cmd/awk/Awk.cpp b/qse/cmd/awk/Awk.cpp index e5cb65a6..4d78a04d 100644 --- a/qse/cmd/awk/Awk.cpp +++ b/qse/cmd/awk/Awk.cpp @@ -27,7 +27,7 @@ static bool verbose = false; -class TestAwk: public ASE::StdAwk +class TestAwk: public QSE::StdAwk { public: TestAwk (): srcInName(QSE_NULL), srcOutName(QSE_NULL), @@ -54,7 +54,7 @@ public: #if defined(_MSC_VER) && (_MSC_VER<1400) int n = StdAwk::open (); #else - int n = ASE::StdAwk::open (); + int n = QSE::StdAwk::open (); #endif if (n == -1) { @@ -82,7 +82,7 @@ public: #if defined(_MSC_VER) && (_MSC_VER<1400) StdAwk::close (); #else - ASE::StdAwk::close (); + QSE::StdAwk::close (); #endif #ifdef _WIN32 @@ -97,7 +97,7 @@ public: #if defined(_MSC_VER) && (_MSC_VER<1400) StdAwk::close (); #else - ASE::StdAwk::close (); + QSE::StdAwk::close (); #endif numConInFiles = 0; @@ -216,7 +216,7 @@ public: #if defined(_MSC_VER) && (_MSC_VER<1400) return StdAwk::parse (); #else - return ASE::StdAwk::parse (); + return QSE::StdAwk::parse (); #endif } @@ -344,7 +344,7 @@ protected: #if defined(_MSC_VER) && (_MSC_VER<1400) StdAwk::Console::Mode mode = io.getMode(); #else - ASE::StdAwk::Console::Mode mode = io.getMode(); + QSE::StdAwk::Console::Mode mode = io.getMode(); #endif FILE* fp = QSE_NULL; const char_t* fn = QSE_NULL; @@ -354,7 +354,7 @@ protected: #if defined(_MSC_VER) && (_MSC_VER<1400) case StdAwk::Console::READ: #else - case ASE::StdAwk::Console::READ: + case QSE::StdAwk::Console::READ: #endif if (numConInFiles == 0) fp = stdin; else @@ -367,7 +367,7 @@ protected: #if defined(_MSC_VER) && (_MSC_VER<1400) case StdAwk::Console::WRITE: #else - case ASE::StdAwk::Console::WRITE: + case QSE::StdAwk::Console::WRITE: #endif if (numConOutFiles == 0) fp = stdout; else @@ -494,7 +494,7 @@ protected: #if defined(_MSC_VER) && (_MSC_VER<1400) StdAwk::Console::Mode mode = io.getMode(); #else - ASE::StdAwk::Console::Mode mode = io.getMode(); + QSE::StdAwk::Console::Mode mode = io.getMode(); #endif ConTrack* t = (ConTrack*)io.getHandle(); FILE* ofp = t->handle; @@ -506,7 +506,7 @@ protected: #if defined(_MSC_VER) && (_MSC_VER<1400) case StdAwk::Console::READ: #else - case ASE::StdAwk::Console::READ: + case QSE::StdAwk::Console::READ: #endif if (t->nextConIdx >= numConInFiles) return 0; fn = conInFile[t->nextConIdx]; @@ -516,7 +516,7 @@ protected: #if defined(_MSC_VER) && (_MSC_VER<1400) case StdAwk::Console::WRITE: #else - case ASE::StdAwk::Console::WRITE: + case QSE::StdAwk::Console::WRITE: #endif if (t->nextConIdx >= numConOutFiles) return 0; fn = conOutFile[t->nextConIdx]; diff --git a/qse/configure b/qse/configure index 030e9df2..2e6359f4 100755 --- a/qse/configure +++ b/qse/configure @@ -21828,6 +21828,101 @@ fi done + +for ac_func in timegm timelocal +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +{ echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; } +if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$ac_func || defined __stub___$ac_func +choke me +#endif + +int +main () +{ +return $ac_func (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && + $as_test_x conftest$ac_exeext; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + eval "$as_ac_var=no" +fi + +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext +fi +ac_res=`eval echo '${'$as_ac_var'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + OLDLIBS="$LIBS" LIBS="$LIBM $LIBS" @@ -28849,7 +28944,7 @@ CJFLAGS=$CJFLAGS BUILD_CJ=$BUILD_CJ -ac_config_files="$ac_config_files Makefile include/Makefile include/qse/Makefile include/qse/cmn/Makefile include/qse/awk/Makefile include/qse/lsp/Makefile include/qse/tgp/Makefile include/qse/utl/Makefile lib/Makefile lib/cmn/Makefile lib/awk/Makefile lib/lsp/Makefile lib/tgp/Makefile lib/utl/Makefile cmd/Makefile cmd/awk/Makefile cmd/lsp/Makefile cmd/tgp/Makefile" +ac_config_files="$ac_config_files Makefile include/Makefile include/qse/Makefile include/qse/cmn/Makefile include/qse/awk/Makefile include/qse/lsp/Makefile include/qse/tgp/Makefile include/qse/utl/Makefile lib/Makefile lib/cmn/Makefile lib/awk/Makefile lib/lsp/Makefile lib/tgp/Makefile lib/utl/Makefile cmd/Makefile cmd/awk/Makefile cmd/lsp/Makefile cmd/tgp/Makefile test/Makefile test/cmn/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -29469,6 +29564,8 @@ do "cmd/awk/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/awk/Makefile" ;; "cmd/lsp/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/lsp/Makefile" ;; "cmd/tgp/Makefile") CONFIG_FILES="$CONFIG_FILES cmd/tgp/Makefile" ;; + "test/Makefile") CONFIG_FILES="$CONFIG_FILES test/Makefile" ;; + "test/cmn/Makefile") CONFIG_FILES="$CONFIG_FILES test/cmn/Makefile" ;; *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 echo "$as_me: error: invalid argument: $ac_config_target" >&2;} diff --git a/qse/configure.ac b/qse/configure.ac index 6b1757dc..14602f8a 100644 --- a/qse/configure.ac +++ b/qse/configure.ac @@ -101,6 +101,7 @@ AC_CHECK_FUNCS([uselocale]) AC_CHECK_FUNCS([mbrlen mbrtowc wcrtomb]) AC_CHECK_FUNCS([mbsnrtowcs mbsrtowcs wcsnrtombs wcsrtombs]) AC_CHECK_FUNCS([lseek64 stat64 fstat64 ftruncate64]) +AC_CHECK_FUNCS([timegm timelocal]) OLDLIBS="$LIBS" LIBS="$LIBM $LIBS" @@ -330,7 +331,10 @@ AC_CONFIG_FILES([ cmd/Makefile cmd/awk/Makefile cmd/lsp/Makefile - cmd/tgp/Makefile]) + cmd/tgp/Makefile + test/Makefile + test/cmn/Makefile +]) AC_OUTPUT [ diff --git a/qse/doc/robodoc.rc b/qse/doc/robodoc.rc index 316a3a6f..e562d9f4 100644 --- a/qse/doc/robodoc.rc +++ b/qse/doc/robodoc.rc @@ -7,6 +7,7 @@ items: OUTPUT OUTPUTS RETURN + RETURNS EXAMPLE EXAMPLES NOTES @@ -23,6 +24,7 @@ item order: OUTPUT OUTPUTS RETURN + RETURNS EXAMPLE EXAMPLES NOTES diff --git a/qse/include/qse/awk/Awk.hpp b/qse/include/qse/awk/Awk.hpp index 5bd5327a..5ec25ce3 100644 --- a/qse/include/qse/awk/Awk.hpp +++ b/qse/include/qse/awk/Awk.hpp @@ -1,7 +1,19 @@ /* * $Id: Awk.hpp 468 2008-12-10 10:19:59Z baconevi $ * - * {License} + Copyright 2006-2008 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_AWK_AWK_HPP_ @@ -13,7 +25,7 @@ #include ///////////////////////////////// -QSE_BEGIN_NAMESPACE(ASE) +QSE_BEGIN_NAMESPACE(QSE) ///////////////////////////////// /** @@ -730,12 +742,15 @@ public: /** * Sets a value into the data data area */ - void setCustom (void* data); + void setData (void* data); /** * Gets the value stored in the data data area */ - void* getCustom () const; + void* getData () const; + + void* alloc (size_t size); + void free (void* ptr); protected: Awk* awk; @@ -1103,7 +1118,7 @@ private: }; ///////////////////////////////// -QSE_END_NAMESPACE(ASE) +QSE_END_NAMESPACE(QSE) ///////////////////////////////// #endif diff --git a/qse/include/qse/awk/StdAwk.hpp b/qse/include/qse/awk/StdAwk.hpp index 340384bf..62861a76 100644 --- a/qse/include/qse/awk/StdAwk.hpp +++ b/qse/include/qse/awk/StdAwk.hpp @@ -1,7 +1,19 @@ /* * $Id: StdAwk.hpp 499 2008-12-16 09:42:48Z baconevi $ * - * {License} + Copyright 2006-2008 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_AWK_STDAWK_HPP_ @@ -10,7 +22,7 @@ #include ///////////////////////////////// -QSE_BEGIN_NAMESPACE(ASE) +QSE_BEGIN_NAMESPACE(QSE) ///////////////////////////////// /** @@ -50,12 +62,6 @@ protected: const char_t* name, size_t len); int srand (Run& run, Return& ret, const Argument* args, size_t nargs, const char_t* name, size_t len); - int systime (Run& run, Return& ret, const Argument* args, size_t nargs, - const char_t* name, size_t len); - int strftime (Run& run, Return& ret, const Argument* args, size_t nargs, - const char_t* name, size_t len); - int strfgmtime (Run& run, Return& ret, const Argument* args, size_t nargs, - const char_t* name, size_t len); int system (Run& run, Return& ret, const Argument* args, size_t nargs, const char_t* name, size_t len); @@ -90,7 +96,7 @@ protected: }; ///////////////////////////////// -QSE_END_NAMESPACE(ASE) +QSE_END_NAMESPACE(QSE) ///////////////////////////////// #endif diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index 64313f16..7a82102b 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -1,7 +1,19 @@ /* * $Id: awk.h 501 2008-12-17 08:39:15Z baconevi $ * - * {License} + Copyright 2006-2008 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_AWK_AWK_H_ @@ -519,7 +531,7 @@ struct qse_awk_val_int_t { QSE_AWK_VAL_HDR; qse_long_t val; - void* nde; + void* nde; }; /* QSE_AWK_VAL_REAL */ @@ -527,14 +539,14 @@ struct qse_awk_val_real_t { QSE_AWK_VAL_HDR; qse_real_t val; - void* nde; + void* nde; }; /* QSE_AWK_VAL_STR */ struct qse_awk_val_str_t { QSE_AWK_VAL_HDR; - qse_char_t* buf; + qse_char_t* ptr; qse_size_t len; }; @@ -542,9 +554,9 @@ struct qse_awk_val_str_t struct qse_awk_val_rex_t { QSE_AWK_VAL_HDR; - qse_char_t* buf; + qse_char_t* ptr; qse_size_t len; - void* code; + void* code; }; /* QSE_AWK_VAL_MAP */ @@ -761,7 +773,7 @@ void qse_awk_unsetallwords ( * it unsets the replacement for okw and olen. If all of them are valid, * it sets the word replace for okw and olen to nkw and nlen. * - * RETURNS: 0 on success, -1 on failure + * RETURN: 0 on success, -1 on failure */ int qse_awk_setword ( /* the pointer to an qse_awk_t instance */ @@ -1037,35 +1049,30 @@ void qse_awk_clrbfn (qse_awk_t* awk); int qse_awk_clrrec (qse_awk_run_t* run, qse_bool_t skip_inrec_line); int qse_awk_setrec (qse_awk_run_t* run, qse_size_t idx, const qse_char_t* str, qse_size_t len); -/* utility functions exported by awk.h */ - -/* - * NAME allocate dynamic memory - * - * DESCRIPTION - * - * - * RETURNS +/****f* qse.awk/qse_awk_alloc + * NAME + * qse_awk_alloc - allocate dynamic memory + * RETURN * the pointer to the memory area allocated on success, QSE_NULL on failure + * SYNOPSIS */ void* qse_awk_alloc ( - /* the pointer to an qse_awk_t instance */ - qse_awk_t* awk, - /* the size of memory to allocate in bytes */ - qse_size_t size + qse_awk_t* awk /* the pointer to an qse_awk_t instance */, + qse_size_t size /* the size of memory to allocate in bytes */ ); +/******/ -/* - * NAME free dynamic memory +/****f* qse.awk/qse_awk_free + * NAME + * qse_awk_free - free dynamic memory * - * DESCRIPTION + * SYNOSPSIS */ void qse_awk_free ( - /* the pointer to an qse_awk_t instance */ - qse_awk_t* awk, - /* the pointer to the memory area to free */ - void* ptr + qse_awk_t* awk /* the pointer to an qse_awk_t instance */, + void* ptr /* the pointer to the memory area to free */ ); +/******/ /* * NAME duplicate a string @@ -1149,9 +1156,9 @@ qse_bool_t qse_awk_valtobool ( qse_char_t* qse_awk_valtostr ( qse_awk_run_t* run, qse_awk_val_t* val, - int opt, - qse_str_t* buf, - qse_size_t* len + int opt, + qse_str_t* buf, + qse_size_t* len ); /****f* qse.awk/qse_awk_valtonum diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index 288f3636..b6350fe6 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -419,7 +419,8 @@ qse_size_t qse_mbsntowcsn ( * passed to the function as the third parameter. After conversion, it holds * the length of the multibyte string excluding the terminating-null. * It may not null-terminate the resulting multibyte string if the buffer - * is not large enough. + * is not large enough. You can check if the resulting mbslen is equal to + * the input mbslen to know it. * * RETURN * The qse_wcstombs() function returns the number of wide characters handled. diff --git a/qse/include/qse/config.h.in b/qse/include/qse/config.h.in index 6f6b1f48..9ae7a9a2 100644 --- a/qse/include/qse/config.h.in +++ b/qse/include/qse/config.h.in @@ -138,6 +138,12 @@ /* Define to 1 if you have the `tanl' function. */ #undef HAVE_TANL +/* Define to 1 if you have the `timegm' function. */ +#undef HAVE_TIMEGM + +/* Define to 1 if you have the `timelocal' function. */ +#undef HAVE_TIMELOCAL + /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H diff --git a/qse/lib/awk/Awk.cpp b/qse/lib/awk/Awk.cpp index abec5772..187713b3 100644 --- a/qse/lib/awk/Awk.cpp +++ b/qse/lib/awk/Awk.cpp @@ -1,7 +1,19 @@ /* * $Id: Awk.cpp 496 2008-12-15 09:56:48Z baconevi $ * - * {License} + Copyright 2006-2008 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. */ @@ -10,7 +22,7 @@ #include "../cmn/mem.h" ///////////////////////////////// -QSE_BEGIN_NAMESPACE(ASE) +QSE_BEGIN_NAMESPACE(QSE) ///////////////////////////////// ////////////////////////////////////////////////////////////////// @@ -288,14 +300,14 @@ int Awk::Argument::init (val_t* v) if (n == 0) { this->rnum = (qse_real_t)this->inum; - this->str.ptr = ((qse_awk_val_str_t*)this->val)->buf; + this->str.ptr = ((qse_awk_val_str_t*)this->val)->ptr; this->str.len = ((qse_awk_val_str_t*)this->val)->len; return 0; } else if (n == 1) { this->inum = (qse_long_t)this->rnum; - this->str.ptr = ((qse_awk_val_str_t*)this->val)->buf; + this->str.ptr = ((qse_awk_val_str_t*)this->val)->ptr; this->str.len = ((qse_awk_val_str_t*)this->val)->len; return 0; } @@ -1018,12 +1030,12 @@ int Awk::Run::getGlobal (int id, Argument& global) const return global.init (qse_awk_getglobal(this->run,id)); } -void Awk::Run::setCustom (void* data) +void Awk::Run::setData (void* data) { this->data = data; } -void* Awk::Run::getCustom () const +void* Awk::Run::getData () const { return this->data; } @@ -1777,6 +1789,6 @@ int Awk::sprintf (void* data, char_t* buf, size_t size, } ///////////////////////////////// -QSE_END_NAMESPACE(ASE) +QSE_END_NAMESPACE(QSE) ///////////////////////////////// diff --git a/qse/lib/awk/Makefile.am b/qse/lib/awk/Makefile.am index fe5d512c..b4d341c7 100644 --- a/qse/lib/awk/Makefile.am +++ b/qse/lib/awk/Makefile.am @@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = nostdinc AM_CPPFLAGS = -I$(top_srcdir)/include lib_LTLIBRARIES = libqseawk.la -libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c func.c misc.c extio.c std.c awk_i.h extio.h func.h misc.h parse.h run.h tree.h +libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c func.c misc.c extio.c std.c awk.h extio.h func.h misc.h parse.h run.h tree.h libqseawk_la_LDFLAGS= -L../cmn -L../utl -version-info 1:0:0 -no-undefined libqseawk_la_LIBADD= -lqsecmn -lqseutl diff --git a/qse/lib/awk/Makefile.in b/qse/lib/awk/Makefile.in index 4b81213c..915be10f 100644 --- a/qse/lib/awk/Makefile.in +++ b/qse/lib/awk/Makefile.in @@ -221,7 +221,7 @@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = nostdinc AM_CPPFLAGS = -I$(top_srcdir)/include lib_LTLIBRARIES = libqseawk.la $(am__append_1) -libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c func.c misc.c extio.c std.c awk_i.h extio.h func.h misc.h parse.h run.h tree.h +libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c func.c misc.c extio.c std.c awk.h extio.h func.h misc.h parse.h run.h tree.h libqseawk_la_LDFLAGS = -L../cmn -L../utl -version-info 1:0:0 -no-undefined libqseawk_la_LIBADD = -lqsecmn -lqseutl @ENABLE_CXX_TRUE@libqseawk___la_SOURCES = Awk.cpp StdAwk.cpp diff --git a/qse/lib/awk/StdAwk.cpp b/qse/lib/awk/StdAwk.cpp index 7c469226..2ce4a223 100644 --- a/qse/lib/awk/StdAwk.cpp +++ b/qse/lib/awk/StdAwk.cpp @@ -1,12 +1,20 @@ /* * $Id: StdAwk.cpp 501 2008-12-17 08:39:15Z baconevi $ * - * {License} - */ + Copyright 2006-2008 Chung, Hyung-Hwan. -#if defined(hpux) || defined(__hpux) || defined(__hpux__) - #define _INCLUDE__STDC_A1_SOURCE -#endif + 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. + */ #include #include @@ -15,7 +23,6 @@ #include #include -#include #ifdef _WIN32 #include @@ -24,7 +31,7 @@ #endif ///////////////////////////////// -QSE_BEGIN_NAMESPACE(ASE) +QSE_BEGIN_NAMESPACE(QSE) ///////////////////////////////// StdAwk::StdAwk () @@ -57,9 +64,6 @@ int StdAwk::open () ADD_FUNC (QSE_T("int"), 1, 1, &StdAwk::fnint); ADD_FUNC (QSE_T("rand"), 0, 0, &StdAwk::rand); ADD_FUNC (QSE_T("srand"), 0, 1, &StdAwk::srand); - ADD_FUNC (QSE_T("systime"), 0, 0, &StdAwk::systime); - ADD_FUNC (QSE_T("strftime"), 0, 2, &StdAwk::strftime); - ADD_FUNC (QSE_T("strfgmtime"), 0, 2, &StdAwk::strfgmtime); ADD_FUNC (QSE_T("system"), 1, 1, &StdAwk::system); return 0; @@ -239,78 +243,6 @@ int StdAwk::srand (Run& run, Return& ret, const Argument* args, size_t nargs, return ret.set ((long_t)prevSeed); } -#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER>=1400) - #define time_t __time64_t - #define time _time64 - #define localtime _localtime64 - #define gmtime _gmtime64 -#endif - -int StdAwk::systime (Run& run, Return& ret, const Argument* args, size_t nargs, - const char_t* name, size_t len) -{ - qse_ntime_t now; - - if (qse_gettime(&now) == -1) - return ret.set (QSE_TYPE_MIN(long_t)); - else - return ret.set ((long_t)now / QSE_MSECS_PER_SEC); -} - -int StdAwk::strftime (Run& run, Return& ret, const Argument* args, size_t nargs, - const char_t* name, size_t len) -{ - const char_t* fmt; - size_t fln; - - fmt = (nargs < 1)? QSE_T("%c"): args[0].toStr(&fln); - time_t t = (nargs < 2)? ::time(NULL): (time_t)args[1].toInt(); - - char_t buf[128]; - struct tm* tm; -#ifdef _WIN32 - tm = ::localtime (&t); -#else - struct tm tmb; - tm = ::localtime_r (&t, &tmb); -#endif - -#ifdef QSE_CHAR_IS_MCHAR - size_t l = ::strftime (buf, QSE_COUNTOF(buf), fmt, tm); -#else - size_t l = ::wcsftime (buf, QSE_COUNTOF(buf), fmt, tm); -#endif - - return ret.set (buf, l); -} - -int StdAwk::strfgmtime (Run& run, Return& ret, const Argument* args, size_t nargs, - const char_t* name, size_t len) -{ - const char_t* fmt; - size_t fln; - - fmt = (nargs < 1)? QSE_T("%c"): args[0].toStr(&fln); - time_t t = (nargs < 2)? ::time(NULL): (time_t)args[1].toInt(); - - char_t buf[128]; - struct tm* tm; -#ifdef _WIN32 - tm = ::gmtime (&t); -#else - struct tm tmb; - tm = ::gmtime_r (&t, &tmb); -#endif - -#ifdef QSE_CHAR_IS_MCHAR - size_t l = ::strftime (buf, QSE_COUNTOF(buf), fmt, tm); -#else - size_t l = ::wcsftime (buf, QSE_COUNTOF(buf), fmt, tm); -#endif - - return ret.set (buf, l); -} - int StdAwk::system (Run& run, Return& ret, const Argument* args, size_t nargs, const char_t* name, size_t len) { @@ -322,19 +254,26 @@ int StdAwk::system (Run& run, Return& ret, const Argument* args, size_t nargs, #elif defined(QSE_CHAR_IS_MCHAR) return ret.set ((long_t)::system(ptr)); #else - char* mbs = (char*) qse_awk_alloc (awk, l*5+1); + char* mbs = (char*) qse_awk_alloc ((awk_t*)(Awk*)run, l*5+1); if (mbs == QSE_NULL) return -1; - ::size_t mbl = ::wcstombs (mbs, ptr, l*5); - if (mbl == (::size_t)-1) + /* at this point, the string is guaranteed to be + * null-terminating. so qse_wcstombs() can be used to convert + * the string, not qse_wcsntombsn(). */ + + qse_size_t mbl = l * 5; + if (qse_wcstombs (ptr, mbs, &mbl) != l && mbl >= l * 5) { - qse_awk_free (awk, mbs); + /* not the entire string is converted. + * mbs is not null-terminated properly. */ + qse_awk_free ((awk_t*)(Awk*)run, mbs); return -1; } + mbs[mbl] = '\0'; int n = ret.set ((long_t)::system(mbs)); - qse_awk_free (awk, mbs); + qse_awk_free ((awk_t*)(Awk*)run, mbs); return n; #endif } @@ -563,6 +502,6 @@ int StdAwk::vsprintf ( } ///////////////////////////////// -QSE_END_NAMESPACE(ASE) +QSE_END_NAMESPACE(QSE) ///////////////////////////////// diff --git a/qse/lib/awk/awk.h b/qse/lib/awk/awk.h index 73f9e23e..4b580a29 100644 --- a/qse/lib/awk/awk.h +++ b/qse/lib/awk/awk.h @@ -1,7 +1,19 @@ /* * $Id: awk_i.h 332 2008-08-18 11:21:48Z baconevi $ * - * {License} + Copyright 2006-2008 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_AWK_AWK_H_ @@ -25,11 +37,6 @@ typedef struct qse_awk_tree_t qse_awk_tree_t; #include "extio.h" #include "misc.h" -#ifdef _MSC_VER -#pragma warning (disable: 4996) -#pragma warning (disable: 4296) -#endif - #define QSE_AWK_MAX_GLOBALS 9999 #define QSE_AWK_MAX_LOCALS 9999 #define QSE_AWK_MAX_PARAMS 9999 diff --git a/qse/lib/awk/extio.c b/qse/lib/awk/extio.c index 4ed44fc7..b7308afe 100644 --- a/qse/lib/awk/extio.c +++ b/qse/lib/awk/extio.c @@ -209,7 +209,7 @@ int qse_awk_readextio ( } else if (rs->type == QSE_AWK_VAL_STR) { - rs_ptr = ((qse_awk_val_str_t*)rs)->buf; + rs_ptr = ((qse_awk_val_str_t*)rs)->ptr; rs_len = ((qse_awk_val_str_t*)rs)->len; } else @@ -417,7 +417,7 @@ int qse_awk_writeextio_val ( if (v->type == QSE_AWK_VAL_STR) { - str = ((qse_awk_val_str_t*)v)->buf; + str = ((qse_awk_val_str_t*)v)->ptr; len = ((qse_awk_val_str_t*)v)->len; } else diff --git a/qse/lib/awk/extio.h b/qse/lib/awk/extio.h index 192d0c5d..b37d5dfa 100644 --- a/qse/lib/awk/extio.h +++ b/qse/lib/awk/extio.h @@ -1,14 +1,26 @@ /* * $Id: extio.h 363 2008-09-04 10:58:08Z baconevi $ * - * {License} + Copyright 2006-2008 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_AWK_EXTIO_H_ #define _QSE_LIB_AWK_EXTIO_H_ #ifdef __cplusplus -extern "C" +extern "C" { #endif int qse_awk_readextio ( diff --git a/qse/lib/awk/func.c b/qse/lib/awk/func.c index 5effc2fb..aeab74bd 100644 --- a/qse/lib/awk/func.c +++ b/qse/lib/awk/func.c @@ -244,7 +244,7 @@ static int bfn_close ( if (a0->type == QSE_AWK_VAL_STR) { - name = ((qse_awk_val_str_t*)a0)->buf; + name = ((qse_awk_val_str_t*)a0)->ptr; len = ((qse_awk_val_str_t*)a0)->len; } else @@ -264,7 +264,6 @@ static int bfn_close ( * an empty string for its identification because closeextio * closes any extios that match the name given unlike * closeextio_read or closeextio_write. */ - if (a0->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, name); n = -1; goto skip_close; } @@ -275,8 +274,6 @@ static int bfn_close ( { /* the name contains a null string. * make close return -1 */ - if (a0->type != QSE_AWK_VAL_STR) - QSE_AWK_FREE (run->awk, name); n = -1; goto skip_close; } @@ -292,9 +289,9 @@ static int bfn_close ( } */ +skip_close: if (a0->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, name); -skip_close: v = qse_awk_makeintval (run, (qse_long_t)n); if (v == QSE_NULL) { @@ -361,7 +358,7 @@ static int bfn_fflush ( a0 = qse_awk_getarg (run, 0); if (a0->type == QSE_AWK_VAL_STR) { - str0 = ((qse_awk_val_str_t*)a0)->buf; + str0 = ((qse_awk_val_str_t*)a0)->ptr; len0 = ((qse_awk_val_str_t*)a0)->len; } else @@ -379,8 +376,6 @@ static int bfn_fflush ( { if (*ptr == QSE_T('\0')) { - if (a0->type != QSE_AWK_VAL_STR) - QSE_AWK_FREE (run->awk, str0); n = -1; goto skip_flush; } @@ -408,10 +403,10 @@ static int bfn_fflush ( * if n is -1, the io handler has returned an error */ if (n != 0) n = -1; + skip_flush: if (a0->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, str0); } -skip_flush: a0 = qse_awk_makeintval (run, (qse_long_t)n); if (a0 == QSE_NULL) { @@ -440,7 +435,7 @@ static int bfn_index ( if (a0->type == QSE_AWK_VAL_STR) { - str0 = ((qse_awk_val_str_t*)a0)->buf; + str0 = ((qse_awk_val_str_t*)a0)->ptr; len0 = ((qse_awk_val_str_t*)a0)->len; } else @@ -452,7 +447,7 @@ static int bfn_index ( if (a1->type == QSE_AWK_VAL_STR) { - str1 = ((qse_awk_val_str_t*)a1)->buf; + str1 = ((qse_awk_val_str_t*)a1)->ptr; len1 = ((qse_awk_val_str_t*)a1)->len; } else @@ -541,7 +536,7 @@ static int bfn_substr ( if (a0->type == QSE_AWK_VAL_STR) { - str = ((qse_awk_val_str_t*)a0)->buf; + str = ((qse_awk_val_str_t*)a0)->ptr; len = ((qse_awk_val_str_t*)a0)->len; } else @@ -646,7 +641,7 @@ static int bfn_split ( if (a0->type == QSE_AWK_VAL_STR) { - str = ((qse_awk_val_str_t*)a0)->buf; + str = ((qse_awk_val_str_t*)a0)->ptr; str_len = ((qse_awk_val_str_t*)a0)->len; str_free = QSE_NULL; } @@ -670,7 +665,7 @@ static int bfn_split ( } else if (t1->type == QSE_AWK_VAL_STR) { - fs_ptr = ((qse_awk_val_str_t*)t1)->buf; + fs_ptr = ((qse_awk_val_str_t*)t1)->ptr; fs_len = ((qse_awk_val_str_t*)t1)->len; fs_free = QSE_NULL; } @@ -697,7 +692,7 @@ static int bfn_split ( { if (a2->type == QSE_AWK_VAL_STR) { - fs_ptr = ((qse_awk_val_str_t*)a2)->buf; + fs_ptr = ((qse_awk_val_str_t*)a2)->ptr; fs_len = ((qse_awk_val_str_t*)a2)->len; fs_free = QSE_NULL; } @@ -867,7 +862,7 @@ static int bfn_tolower ( if (a0->type == QSE_AWK_VAL_STR) { - str = ((qse_awk_val_str_t*)a0)->buf; + str = ((qse_awk_val_str_t*)a0)->ptr; len = ((qse_awk_val_str_t*)a0)->len; } else @@ -907,7 +902,7 @@ static int bfn_toupper ( if (a0->type == QSE_AWK_VAL_STR) { - str = ((qse_awk_val_str_t*)a0)->buf; + str = ((qse_awk_val_str_t*)a0)->ptr; len = ((qse_awk_val_str_t*)a0)->len; } else @@ -974,7 +969,7 @@ static int __substitute (qse_awk_run_t* run, qse_long_t max_count) } else if (a0->type == QSE_AWK_VAL_STR) { - a0_ptr = ((qse_awk_val_str_t*)a0)->buf; + a0_ptr = ((qse_awk_val_str_t*)a0)->ptr; a0_len = ((qse_awk_val_str_t*)a0)->len; } else @@ -991,7 +986,7 @@ static int __substitute (qse_awk_run_t* run, qse_long_t max_count) if (a1->type == QSE_AWK_VAL_STR) { - a1_ptr = ((qse_awk_val_str_t*)a1)->buf; + a1_ptr = ((qse_awk_val_str_t*)a1)->ptr; a1_len = ((qse_awk_val_str_t*)a1)->len; } else @@ -1047,7 +1042,7 @@ static int __substitute (qse_awk_run_t* run, qse_long_t max_count) if ((*a2_ref)->type == QSE_AWK_VAL_STR) { - a2_ptr = ((qse_awk_val_str_t*)(*a2_ref))->buf; + a2_ptr = ((qse_awk_val_str_t*)(*a2_ref))->ptr; a2_len = ((qse_awk_val_str_t*)(*a2_ref))->len; } else @@ -1256,7 +1251,7 @@ static int bfn_match ( if (a0->type == QSE_AWK_VAL_STR) { - str0 = ((qse_awk_val_str_t*)a0)->buf; + str0 = ((qse_awk_val_str_t*)a0)->ptr; len0 = ((qse_awk_val_str_t*)a0)->len; } else @@ -1274,7 +1269,7 @@ static int bfn_match ( { if (a1->type == QSE_AWK_VAL_STR) { - str1 = ((qse_awk_val_str_t*)a1)->buf; + str1 = ((qse_awk_val_str_t*)a1)->ptr; len1 = ((qse_awk_val_str_t*)a1)->len; } else @@ -1381,7 +1376,7 @@ static int bfn_sprintf ( a0 = qse_awk_getarg (run, 0); if (a0->type == QSE_AWK_VAL_STR) { - cs0.ptr = ((qse_awk_val_str_t*)a0)->buf; + cs0.ptr = ((qse_awk_val_str_t*)a0)->ptr; cs0.len = ((qse_awk_val_str_t*)a0)->len; } else diff --git a/qse/lib/awk/func.h b/qse/lib/awk/func.h index c32c28aa..4c346cb3 100644 --- a/qse/lib/awk/func.h +++ b/qse/lib/awk/func.h @@ -1,7 +1,19 @@ /* * $Id: func.h 363 2008-09-04 10:58:08Z baconevi $ * - * {License} + Copyright 2006-2008 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_AWK_FUNC_H_ diff --git a/qse/lib/awk/misc.h b/qse/lib/awk/misc.h index a06360a8..c466e35a 100644 --- a/qse/lib/awk/misc.h +++ b/qse/lib/awk/misc.h @@ -1,7 +1,19 @@ /* * $Id: misc.h 363 2008-09-04 10:58:08Z baconevi $ * - * {License} + Copyright 2006-2008 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_AWK_MISC_H_ diff --git a/qse/lib/awk/parse.c b/qse/lib/awk/parse.c index 1f755586..7732aafe 100644 --- a/qse/lib/awk/parse.c +++ b/qse/lib/awk/parse.c @@ -2899,9 +2899,9 @@ static qse_awk_nde_t* parse_primary (qse_awk_t* awk, qse_size_t line) nde->line = line; nde->next = QSE_NULL; nde->len = QSE_STR_LEN(awk->token.name); - nde->buf = QSE_AWK_STRXDUP (awk, + nde->ptr = QSE_AWK_STRXDUP (awk, QSE_STR_PTR(awk->token.name), nde->len); - if (nde->buf == QSE_NULL) + if (nde->ptr == QSE_NULL) { QSE_AWK_FREE (awk, nde); SETERRLIN (awk, QSE_AWK_ENOMEM, line); @@ -2910,7 +2910,7 @@ static qse_awk_nde_t* parse_primary (qse_awk_t* awk, qse_size_t line) if (get_token(awk) == -1) { - QSE_AWK_FREE (awk, nde->buf); + QSE_AWK_FREE (awk, nde->ptr); QSE_AWK_FREE (awk, nde); return QSE_NULL; } @@ -2943,10 +2943,10 @@ static qse_awk_nde_t* parse_primary (qse_awk_t* awk, qse_size_t line) nde->next = QSE_NULL; nde->len = QSE_STR_LEN(awk->token.name); - nde->buf = QSE_AWK_STRXDUP (awk, + nde->ptr = QSE_AWK_STRXDUP (awk, QSE_STR_PTR(awk->token.name), QSE_STR_LEN(awk->token.name)); - if (nde->buf == QSE_NULL) + if (nde->ptr == QSE_NULL) { QSE_AWK_FREE (awk, nde); SETERRLIN (awk, QSE_AWK_ENOMEM, line); @@ -2959,7 +2959,7 @@ static qse_awk_nde_t* parse_primary (qse_awk_t* awk, qse_size_t line) &errnum); if (nde->code == QSE_NULL) { - QSE_AWK_FREE (awk, nde->buf); + QSE_AWK_FREE (awk, nde->ptr); QSE_AWK_FREE (awk, nde); SETERRLIN (awk, errnum, line); @@ -2968,7 +2968,7 @@ static qse_awk_nde_t* parse_primary (qse_awk_t* awk, qse_size_t line) if (get_token(awk) == -1) { - QSE_AWK_FREE (awk, nde->buf); + QSE_AWK_FREE (awk, nde->ptr); QSE_AWK_FREE (awk, nde->code); QSE_AWK_FREE (awk, nde); return QSE_NULL; diff --git a/qse/lib/awk/parse.h b/qse/lib/awk/parse.h index 91979cbc..2fa4cdf5 100644 --- a/qse/lib/awk/parse.h +++ b/qse/lib/awk/parse.h @@ -1,7 +1,19 @@ /* * $Id: parse.h 363 2008-09-04 10:58:08Z baconevi $ * - * {License} + Copyright 2006-2008 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_AWK_PARSE_H_ diff --git a/qse/lib/awk/rec.c b/qse/lib/awk/rec.c index 275340a3..393b409e 100644 --- a/qse/lib/awk/rec.c +++ b/qse/lib/awk/rec.c @@ -116,7 +116,7 @@ static int split_record (qse_awk_run_t* run) } else if (fs->type == QSE_AWK_VAL_STR) { - fs_ptr = ((qse_awk_val_str_t*)fs)->buf; + fs_ptr = ((qse_awk_val_str_t*)fs)->ptr; fs_len = ((qse_awk_val_str_t*)fs)->len; fs_free = QSE_NULL; } @@ -423,7 +423,7 @@ static int recomp_record_fields ( run->inrec.flds[i].len = tmp->len; if (qse_str_ncat (&run->inrec.line, - tmp->buf, tmp->len) == (qse_size_t)-1) + tmp->ptr, tmp->len) == (qse_size_t)-1) { qse_awk_setrunerror ( run, QSE_AWK_ENOMEM, 0, QSE_NULL, 0); diff --git a/qse/lib/awk/run.c b/qse/lib/awk/run.c index 1e010025..400e812d 100644 --- a/qse/lib/awk/run.c +++ b/qse/lib/awk/run.c @@ -349,7 +349,7 @@ static int set_global ( if (val->type == QSE_AWK_VAL_STR) { - fs_ptr = ((qse_awk_val_str_t*)val)->buf; + fs_ptr = ((qse_awk_val_str_t*)val)->ptr; fs_len = ((qse_awk_val_str_t*)val)->len; } else @@ -494,7 +494,7 @@ static int set_global ( if (val->type == QSE_AWK_VAL_STR) { - rs_ptr = ((qse_awk_val_str_t*)val)->buf; + rs_ptr = ((qse_awk_val_str_t*)val)->ptr; rs_len = ((qse_awk_val_str_t*)val)->len; } else @@ -1328,7 +1328,7 @@ static int run_main ( while (tmp != QSE_NULL) { tmp2 = (qse_awk_nde_str_t*)tmp->next; - QSE_AWK_FREE (run->awk, tmp->buf); + QSE_AWK_FREE (run->awk, tmp->ptr); QSE_AWK_FREE (run->awk, tmp); tmp = tmp2; } @@ -1340,16 +1340,16 @@ static int run_main ( } tmp->type = QSE_AWK_NDE_STR; - tmp->buf = QSE_AWK_STRXDUP (run->awk, + tmp->ptr = QSE_AWK_STRXDUP (run->awk, runarg[i].ptr, runarg[i].len); - if (tmp->buf == QSE_NULL) + if (tmp->ptr == QSE_NULL) { QSE_AWK_FREE (run->awk, tmp); tmp = (qse_awk_nde_str_t*)nde.args; while (tmp != QSE_NULL) { tmp2 = (qse_awk_nde_str_t*)tmp->next; - QSE_AWK_FREE (run->awk, tmp->buf); + QSE_AWK_FREE (run->awk, tmp->ptr); QSE_AWK_FREE (run->awk, tmp); tmp = tmp2; } @@ -3034,7 +3034,7 @@ static int run_printf (qse_awk_run_t* run, qse_awk_nde_print_t* nde) /* perform the formatted output */ if (output_formatted ( run, nde->out_type, dst, - ((qse_awk_val_str_t*)v)->buf, + ((qse_awk_val_str_t*)v)->ptr, ((qse_awk_val_str_t*)v)->len, head->next) == -1) { @@ -3113,7 +3113,7 @@ static qse_awk_val_t* eval_expression (qse_awk_run_t* run, qse_awk_nde_t* nde) ((qse_awk_run_t*)run)->awk, ((qse_awk_val_rex_t*)v)->code, ((((qse_awk_run_t*)run)->global.ignorecase)? QSE_REX_IGNORECASE: 0), - ((qse_awk_val_str_t*)run->inrec.d0)->buf, + ((qse_awk_val_str_t*)run->inrec.d0)->ptr, ((qse_awk_val_str_t*)run->inrec.d0)->len, QSE_NULL, QSE_NULL, &errnum); @@ -3599,7 +3599,7 @@ static qse_awk_val_t* do_assignment_pos ( if (val->type == QSE_AWK_VAL_STR) { - str = ((qse_awk_val_str_t*)val)->buf; + str = ((qse_awk_val_str_t*)val)->ptr; len = ((qse_awk_val_str_t*)val)->len; } else @@ -4032,9 +4032,9 @@ static int __cmp_int_str ( int n; r = qse_awk_strxtolong (run->awk, - ((qse_awk_val_str_t*)right)->buf, + ((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->len, 0, (const qse_char_t**)&str); - if (str == ((qse_awk_val_str_t*)right)->buf + + if (str == ((qse_awk_val_str_t*)right)->ptr + ((qse_awk_val_str_t*)right)->len) { if (((qse_awk_val_int_t*)left)->val > r) return 1; @@ -4045,10 +4045,10 @@ static int __cmp_int_str ( else if (*str == QSE_T('.') || *str == QSE_T('E') || *str == QSE_T('e')) { rr = qse_awk_strxtoreal (run->awk, - ((qse_awk_val_str_t*)right)->buf, + ((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->len, (const qse_char_t**)&str); - if (str == ((qse_awk_val_str_t*)right)->buf + + if (str == ((qse_awk_val_str_t*)right)->ptr + ((qse_awk_val_str_t*)right)->len) { if (((qse_awk_val_int_t*)left)->val > rr) return 1; @@ -4065,7 +4065,7 @@ static int __cmp_int_str ( { n = qse_strxncasecmp ( str, len, - ((qse_awk_val_str_t*)right)->buf, + ((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->len, CCLS(run)); } @@ -4073,7 +4073,7 @@ static int __cmp_int_str ( { n = qse_strxncmp ( str, len, - ((qse_awk_val_str_t*)right)->buf, + ((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->len); } @@ -4118,10 +4118,10 @@ static int __cmp_real_str ( int n; rr = qse_awk_strxtoreal (run->awk, - ((qse_awk_val_str_t*)right)->buf, + ((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->len, (const qse_char_t**)&str); - if (str == ((qse_awk_val_str_t*)right)->buf + + if (str == ((qse_awk_val_str_t*)right)->ptr + ((qse_awk_val_str_t*)right)->len) { if (((qse_awk_val_real_t*)left)->val > rr) return 1; @@ -4137,7 +4137,7 @@ static int __cmp_real_str ( { n = qse_strxncasecmp ( str, len, - ((qse_awk_val_str_t*)right)->buf, + ((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->len, CCLS(run)); } @@ -4145,7 +4145,7 @@ static int __cmp_real_str ( { n = qse_strxncmp ( str, len, - ((qse_awk_val_str_t*)right)->buf, + ((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->len); } @@ -4183,12 +4183,12 @@ static int __cmp_str_str ( if (run->global.ignorecase) { n = qse_strxncasecmp ( - ls->buf, ls->len, rs->buf, rs->len, CCLS(run)); + ls->ptr, ls->len, rs->ptr, rs->len, CCLS(run)); } else { n = qse_strxncmp ( - ls->buf, ls->len, rs->buf, rs->len); + ls->ptr, ls->len, rs->ptr, rs->len); } return n; @@ -4745,7 +4745,7 @@ static qse_awk_val_t* eval_binop_match0 ( { rex_code = QSE_AWK_BUILDREX ( run->awk, - ((qse_awk_val_str_t*)right)->buf, + ((qse_awk_val_str_t*)right)->ptr, ((qse_awk_val_str_t*)right)->len, &errnum); if (rex_code == QSE_NULL) { @@ -4776,7 +4776,7 @@ static qse_awk_val_t* eval_binop_match0 ( n = QSE_AWK_MATCHREX ( run->awk, rex_code, ((run->global.ignorecase)? QSE_REX_IGNORECASE: 0), - ((qse_awk_val_str_t*)left)->buf, + ((qse_awk_val_str_t*)left)->ptr, ((qse_awk_val_str_t*)left)->len, QSE_NULL, QSE_NULL, &errnum); if (n == -1) @@ -5993,7 +5993,7 @@ static qse_awk_val_t* eval_str (qse_awk_run_t* run, qse_awk_nde_t* nde) qse_awk_val_t* val; val = qse_awk_makestrval (run, - ((qse_awk_nde_str_t*)nde)->buf, + ((qse_awk_nde_str_t*)nde)->ptr, ((qse_awk_nde_str_t*)nde)->len); if (val == QSE_NULL) { @@ -6009,7 +6009,7 @@ static qse_awk_val_t* eval_rex (qse_awk_run_t* run, qse_awk_nde_t* nde) qse_awk_val_t* val; val = qse_awk_makerexval (run, - ((qse_awk_nde_rex_t*)nde)->buf, + ((qse_awk_nde_rex_t*)nde)->ptr, ((qse_awk_nde_rex_t*)nde)->len, ((qse_awk_nde_rex_t*)nde)->code); if (val == QSE_NULL) @@ -6402,7 +6402,7 @@ static int shorten_record (qse_awk_run_t* run, qse_size_t nflds) } else if (v->type == QSE_AWK_VAL_STR) { - ofs = ((qse_awk_val_str_t*)v)->buf; + ofs = ((qse_awk_val_str_t*)v)->ptr; ofs_len = ((qse_awk_val_str_t*)v)->len; } else @@ -7100,7 +7100,7 @@ qse_char_t* qse_awk_format ( ch_len = ((qse_awk_val_str_t*)v)->len; if (ch_len > 0) { - ch = ((qse_awk_val_str_t*)v)->buf[0]; + ch = ((qse_awk_val_str_t*)v)->ptr[0]; ch_len = 1; } else ch = QSE_T('\0'); @@ -7197,7 +7197,7 @@ qse_char_t* qse_awk_format ( } else if (v->type == QSE_AWK_VAL_STR) { - str = ((qse_awk_val_str_t*)v)->buf; + str = ((qse_awk_val_str_t*)v)->ptr; str_len = ((qse_awk_val_str_t*)v)->len; } else diff --git a/qse/lib/awk/run.h b/qse/lib/awk/run.h index dfeee21e..375c3073 100644 --- a/qse/lib/awk/run.h +++ b/qse/lib/awk/run.h @@ -1,7 +1,19 @@ /* * $Id: run.h 363 2008-09-04 10:58:08Z baconevi $ * - * {License} + Copyright 2006-2008 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_AWK_RUN_H_ diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index b73e729e..0d4fbea5 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -20,11 +20,11 @@ #include #include #include +#include /* TODO: remove dependency on qse_vsprintf */ #include #include #include -#include typedef struct xtn_t { @@ -296,8 +296,14 @@ int qse_awk_parsesimple ( return -1; } - if (ist == QSE_AWK_PARSE_FILES) sf.in.p.files = isp; - else if (ist == QSE_AWK_PARSE_STRING) sf.in.p.str = isp; + if (ist == QSE_AWK_PARSE_FILES) + { + sf.in.p.files = (const qse_char_t* const*)isp; + } + else if (ist == QSE_AWK_PARSE_STRING) + { + sf.in.p.str = (const qse_char_t*)isp; + } else { qse_awk_seterrnum (awk, QSE_AWK_EINVAL); @@ -856,13 +862,14 @@ static int bfn_math_2 ( static int bfn_sin (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) { - return bfn_math_1 (run, fnm, fnl, + return bfn_math_1 ( + run, fnm, fnl, #if defined(HAVE_SINL) - BFN_MATH_LD, sinl + BFN_MATH_LD, (void*)sinl #elif defined(HAVE_SIN) - BFN_MATH_D, sin + BFN_MATH_D, (void*)sin #elif defined(HAVE_SINF) - BFN_MATH_F, sinf + BFN_MATH_F, (void*)sinf #else #error ### no sin function available ### #endif @@ -871,13 +878,14 @@ static int bfn_sin (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) static int bfn_cos (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) { - return bfn_math_1 (run, fnm, fnl, + return bfn_math_1 ( + run, fnm, fnl, #if defined(HAVE_COSL) - BFN_MATH_LD, cosl + BFN_MATH_LD, (void*)cosl #elif defined(HAVE_COS) - BFN_MATH_D, cos + BFN_MATH_D, (void*)cos #elif defined(HAVE_COSF) - BFN_MATH_F, cosf + BFN_MATH_F, (void*)cosf #else #error ### no cos function available ### #endif @@ -886,13 +894,14 @@ static int bfn_cos (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) static int bfn_tan (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) { - return bfn_math_1 (run, fnm, fnl, + return bfn_math_1 ( + run, fnm, fnl, #if defined(HAVE_TANL) - BFN_MATH_LD, tanl + BFN_MATH_LD, (void*)tanl #elif defined(HAVE_TAN) - BFN_MATH_D, tan + BFN_MATH_D, (void*)tan #elif defined(HAVE_TANF) - BFN_MATH_F, tanf + BFN_MATH_F, (void*)tanf #else #error ### no tan function available ### #endif @@ -901,13 +910,14 @@ static int bfn_tan (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) static int bfn_atan (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) { - return bfn_math_1 (run, fnm, fnl, + return bfn_math_1 ( + run, fnm, fnl, #if defined(HAVE_ATANL) - BFN_MATH_LD, atanl + BFN_MATH_LD, (void*)atanl #elif defined(HAVE_ATAN) - BFN_MATH_D, atan + BFN_MATH_D, (void*)atan #elif defined(HAVE_ATANF) - BFN_MATH_F, atanf + BFN_MATH_F, (void*)atanf #else #error ### no atan function available ### #endif @@ -916,13 +926,14 @@ static int bfn_atan (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) static int bfn_atan2 (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) { - return bfn_math_2 (run, fnm, fnl, + return bfn_math_2 ( + run, fnm, fnl, #if defined(HAVE_ATAN2L) - BFN_MATH_LD, atan2l + BFN_MATH_LD, (void*)atan2l #elif defined(HAVE_ATAN2) - BFN_MATH_D, atan2 + BFN_MATH_D, (void*)atan2 #elif defined(HAVE_ATAN2F) - BFN_MATH_F, atan2f + BFN_MATH_F, (void*)atan2f #else #error ### no atan2 function available ### #endif @@ -931,13 +942,14 @@ static int bfn_atan2 (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) static int bfn_log (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) { - return bfn_math_1 (run, fnm, fnl, + return bfn_math_1 ( + run, fnm, fnl, #if defined(HAVE_LOGL) - BFN_MATH_LD, logl + BFN_MATH_LD, (void*)logl #elif defined(HAVE_LOG) - BFN_MATH_D, log + BFN_MATH_D, (void*)log #elif defined(HAVE_LOGF) - BFN_MATH_F, logf + BFN_MATH_F, (void*)logf #else #error ### no log function available ### #endif @@ -946,13 +958,14 @@ static int bfn_log (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) static int bfn_exp (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) { - return bfn_math_1 (run, fnm, fnl, + return bfn_math_1 ( + run, fnm, fnl, #if defined(HAVE_EXPL) - BFN_MATH_LD, expl + BFN_MATH_LD, (void*)expl #elif defined(HAVE_EXP) - BFN_MATH_D, exp + BFN_MATH_D, (void*)exp #elif defined(HAVE_EXPF) - BFN_MATH_F, expf + BFN_MATH_F, (void*)expf #else #error ### no exp function available ### #endif @@ -961,13 +974,14 @@ static int bfn_exp (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) static int bfn_sqrt (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) { - return bfn_math_1 (run, fnm, fnl, + return bfn_math_1 ( + run, fnm, fnl, #if defined(HAVE_SQRTL) - BFN_MATH_LD, sqrtl + BFN_MATH_LD, (void*)sqrtl #elif defined(HAVE_SQRT) - BFN_MATH_D, sqrt + BFN_MATH_D, (void*)sqrt #elif defined(HAVE_SQRTF) - BFN_MATH_F, sqrtf + BFN_MATH_F, (void*)sqrtf #else #error ### no sqrt function available ### #endif @@ -1029,7 +1043,7 @@ static int bfn_srand (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) unsigned int prev; rxtn_t* rxtn; - rxtn = qse_awk_getrundata (run); + rxtn = (rxtn_t*)qse_awk_getrundata (run); nargs = qse_awk_getnargs (run); QSE_ASSERT (nargs == 0 || nargs == 1); @@ -1066,46 +1080,94 @@ static int bfn_srand (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) return 0; } -static int bfn_systime (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) +static int bfn_system (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) { - qse_awk_val_t* r; - qse_ntime_t now; - int n; - - if (qse_gettime(&now) == -1) - r = qse_awk_makeintval (run, QSE_TYPE_MIN(qse_long_t)); - else - r = qse_awk_makeintval (run, now / QSE_MSECS_PER_SEC); + qse_size_t nargs; + qse_awk_val_t* v; + qse_char_t* str, * ptr, * end; + qse_size_t len; + int n = 0; - if (r == QSE_NULL) + nargs = qse_awk_getnargs (run); + QSE_ASSERT (nargs == 1); + + v = qse_awk_getarg (run, 0); + if (v->type == QSE_AWK_VAL_STR) { - qse_awk_setrunerrnum (run, QSE_AWK_ENOMEM); + str = ((qse_awk_val_str_t*)v)->ptr; + len = ((qse_awk_val_str_t*)v)->len; + } + else + { + str = qse_awk_valtostr ( + run, v, QSE_AWK_VALTOSTR_CLEAR, QSE_NULL, &len); + if (str == QSE_NULL) return -1; + } + + /* the target name contains a null character. + * make system return -1 */ + ptr = str; end = str + len; + while (ptr < end) + { + if (*ptr == QSE_T('\0')) + { + n = -1; + goto skip_system; + } + + ptr++; + } + +#if defined(_WIN32) + n = _tsystem (str); +#elif defined(QSE_CHAR_IS_MCHAR) + n = system (str); +#else + { + char* mbs; + qse_size_t mbl; + + mbs = (char*) qse_awk_alloc (run->awk, len*5+1); + if (mbs == QSE_NULL) + { + n = -1; + goto skip_system; + } + + /* at this point, the string is guaranteed to be + * null-terminating. so qse_wcstombs() can be used to convert + * the string, not qse_wcsntombsn(). */ + + mbl = len * 5; + if (qse_wcstombs (str, mbs, &mbl) != len && mbl >= len * 5) + { + /* not the entire string is converted. + * mbs is not null-terminated properly. */ + n = -1; + goto skip_system_mbs; + } + + mbs[mbl] = '\0'; + n = system (mbs); + + skip_system_mbs: + qse_awk_free (run->awk, mbs); + } +#endif + +skip_system: + if (v->type != QSE_AWK_VAL_STR) QSE_AWK_FREE (run->awk, str); + + v = qse_awk_makeintval (run, (qse_long_t)n); + if (v == QSE_NULL) + { + /*qse_awk_setrunerrnum (run, QSE_AWK_ENOMEM);*/ return -1; } - qse_awk_setretval (run, r); + qse_awk_setretval (run, v); return 0; } - -static int bfn_gmtime (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) -{ -/* TODO: *********************** */ - qse_ntime_t nt; - qse_btime_t bt; - - - qse_gmtime (nt, &bt); - /* TODO: create an array containing - * ..... - */ - return -1; -} - -static int bfn_localtime (qse_awk_run_t* run, const qse_char_t* fnm, qse_size_t fnl) -{ - return -1; -} - #define ADD_FUNC(awk,name,min,max,bfn) \ if (qse_awk_addfunc (\ (awk), (name), qse_strlen(name), \ @@ -1124,14 +1186,7 @@ static int add_functions (qse_awk_t* awk) ADD_FUNC (awk, QSE_T("int"), 1, 1, bfn_int); ADD_FUNC (awk, QSE_T("rand"), 0, 0, bfn_rand); ADD_FUNC (awk, QSE_T("srand"), 0, 1, bfn_srand); - ADD_FUNC (awk, QSE_T("systime"), 0, 0, bfn_systime); - ADD_FUNC (awk, QSE_T("gmtime"), 0, 0, bfn_gmtime); - ADD_FUNC (awk, QSE_T("localtime"), 0, 0, bfn_localtime); -/* - ADD_FUNC (awk, QSE_T("strftime"), 0, 2, bfn_strftime); - ADD_FUNC (awk, QSE_T("strfgmtime"), 0, 2, bfn_strfgmtime); ADD_FUNC (awk, QSE_T("system"), 1, 1, bfn_system); -*/ return 0; } diff --git a/qse/lib/awk/tree.c b/qse/lib/awk/tree.c index e6f4d385..f2fbe317 100644 --- a/qse/lib/awk/tree.c +++ b/qse/lib/awk/tree.c @@ -307,7 +307,7 @@ static int print_expression (qse_awk_t* awk, qse_awk_nde_t* nde) PUT_SRCSTR (awk, QSE_T("\"")); - ptr = ((qse_awk_nde_str_t*)nde)->buf; + ptr = ((qse_awk_nde_str_t*)nde)->ptr; len = ((qse_awk_nde_str_t*)nde)->len; for (i = 0; i < len; i++) { @@ -337,7 +337,7 @@ static int print_expression (qse_awk_t* awk, qse_awk_nde_t* nde) { PUT_SRCSTR (awk, QSE_T("/")); PUT_SRCSTRX (awk, - ((qse_awk_nde_rex_t*)nde)->buf, + ((qse_awk_nde_rex_t*)nde)->ptr, ((qse_awk_nde_rex_t*)nde)->len); PUT_SRCSTR (awk, QSE_T("/")); break; @@ -1209,14 +1209,14 @@ void qse_awk_clrpt (qse_awk_t* awk, qse_awk_nde_t* tree) case QSE_AWK_NDE_STR: { - QSE_AWK_FREE (awk, ((qse_awk_nde_str_t*)p)->buf); + QSE_AWK_FREE (awk, ((qse_awk_nde_str_t*)p)->ptr); QSE_AWK_FREE (awk, p); break; } case QSE_AWK_NDE_REX: { - QSE_AWK_FREE (awk, ((qse_awk_nde_rex_t*)p)->buf); + QSE_AWK_FREE (awk, ((qse_awk_nde_rex_t*)p)->ptr); QSE_AWK_FREE (awk, ((qse_awk_nde_rex_t*)p)->code); QSE_AWK_FREE (awk, p); break; diff --git a/qse/lib/awk/tree.h b/qse/lib/awk/tree.h index 5aea445e..13742c5d 100644 --- a/qse/lib/awk/tree.h +++ b/qse/lib/awk/tree.h @@ -1,7 +1,19 @@ /* * $Id: tree.h 381 2008-09-24 11:07:24Z baconevi $ * - * {License} + Copyright 2006-2008 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_AWK_TREE_H_ @@ -207,7 +219,7 @@ struct qse_awk_nde_int_t struct qse_awk_nde_real_t { QSE_AWK_NDE_HDR; - qse_real_t val; + qse_real_t val; qse_char_t* str; qse_size_t len; }; @@ -216,7 +228,7 @@ struct qse_awk_nde_real_t struct qse_awk_nde_str_t { QSE_AWK_NDE_HDR; - qse_char_t* buf; + qse_char_t* ptr; qse_size_t len; }; @@ -224,9 +236,9 @@ struct qse_awk_nde_str_t struct qse_awk_nde_rex_t { QSE_AWK_NDE_HDR; - qse_char_t* buf; + qse_char_t* ptr; qse_size_t len; - void* code; + void* code; }; /* QSE_AWK_NDE_NAMED, QSE_AWK_NDE_GLOBAL, diff --git a/qse/lib/awk/val.c b/qse/lib/awk/val.c index 94942be4..847398f7 100644 --- a/qse/lib/awk/val.c +++ b/qse/lib/awk/val.c @@ -294,9 +294,9 @@ init: val->type = QSE_AWK_VAL_STR; val->ref = 0; val->len = len; - val->buf = (qse_char_t*)(val + 1); - /*qse_strxncpy (val->buf, len+1, str, len);*/ - qse_strncpy (val->buf, str, len); + val->ptr = (qse_char_t*)(val + 1); + /*qse_strxncpy (val->ptr, len+1, str, len);*/ + qse_strncpy (val->ptr, str, len); #ifdef DEBUG_VAL qse_dprintf (QSE_T("makestrval => %p\n"), val); @@ -320,7 +320,7 @@ qse_awk_val_t* qse_awk_makestrval_nodup ( val->type = QSE_AWK_VAL_STR; val->ref = 0; val->len = len; - val->buf = str; + val->ptr = str; return (qse_awk_val_t*)val; } @@ -365,11 +365,11 @@ init: val->type = QSE_AWK_VAL_STR; val->ref = 0; val->len = len1 + len2; - val->buf = (qse_char_t*)(val + 1); - /*qse_strxncpy (val->buf, len1+1, str1, len1); - qse_strxncpy (val->buf[len1], len2+1, str2, len2);*/ - qse_strncpy (val->buf, str1, len1); - qse_strncpy (&val->buf[len1], str2, len2); + val->ptr = (qse_char_t*)(val + 1); + /*qse_strxncpy (val->ptr, len1+1, str1, len1); + qse_strxncpy (val->ptr[len1], len2+1, str2, len2);*/ + qse_strncpy (val->ptr, str1, len1); + qse_strncpy (&val->ptr[len1], str2, len2); #ifdef DEBUG_VAL qse_dprintf (QSE_T("makestrval2 => %p\n"), val); @@ -391,27 +391,27 @@ qse_awk_val_t* qse_awk_makerexval ( val->ref = 0; val->len = len; /* - val->buf = QSE_AWK_STRXDUP (run->awk, buf, len); - if (val->buf == QSE_NULL) + val->ptr = QSE_AWK_STRXDUP (run->awk, buf, len); + if (val->ptr == QSE_NULL) { QSE_AWK_FREE (run->awk, val); qse_awk_setrunerrnum (run, QSE_AWK_ENOMEM); return QSE_NULL; }*/ - val->buf = (qse_char_t*)(val + 1); - qse_strncpy (val->buf, buf, len); + val->ptr = (qse_char_t*)(val + 1); + qse_strncpy (val->ptr, buf, len); /* val->code = QSE_AWK_ALLOC (run->awk, QSE_REX_LEN(code)); if (val->code == QSE_NULL) { - QSE_AWK_FREE (run->awk, val->buf); + QSE_AWK_FREE (run->awk, val->ptr); QSE_AWK_FREE (run->awk, val); qse_awk_setrunerrnum (run, QSE_AWK_ENOMEM); return QSE_NULL; } */ - val->code = val->buf + len + 1; + val->code = val->ptr + len + 1; QSE_MEMCPY (val->code, code, QSE_REX_LEN(code)); return (qse_awk_val_t*)val; @@ -635,7 +635,7 @@ void qse_awk_freeval (qse_awk_run_t* run, qse_awk_val_t* val, qse_bool_t cache) else if (val->type == QSE_AWK_VAL_REX) { /* - QSE_AWK_FREE (run->awk, ((qse_awk_val_rex_t*)val)->buf); + QSE_AWK_FREE (run->awk, ((qse_awk_val_rex_t*)val)->ptr); QSE_AWK_FREEREX (run->awk, ((qse_awk_val_rex_t*)val)->code); */ QSE_AWK_FREE (run->awk, val); @@ -793,7 +793,7 @@ qse_char_t* qse_awk_valtostr ( qse_awk_val_str_t* vs = (qse_awk_val_str_t*)v; return str_to_str ( - run, vs->buf, vs->len, opt, buf, len); + run, vs->ptr, vs->len, opt, buf, len); } #ifdef DEBUG_VAL @@ -1107,7 +1107,7 @@ int qse_awk_valtonum ( if (v->type == QSE_AWK_VAL_STR) { return qse_awk_strtonum (run, - ((qse_awk_val_str_t*)v)->buf, + ((qse_awk_val_str_t*)v)->ptr, ((qse_awk_val_str_t*)v)->len, l, r); } @@ -1202,11 +1202,11 @@ void qse_awk_dprintval (qse_awk_run_t* run, qse_awk_val_t* val) break; case QSE_AWK_VAL_STR: - DPRINTF (DCUSTOM, QSE_T("%s"), ((qse_awk_val_str_t*)val)->buf); + DPRINTF (DCUSTOM, QSE_T("%s"), ((qse_awk_val_str_t*)val)->ptr); break; case QSE_AWK_VAL_REX: - DPRINTF (DCUSTOM, QSE_T("REX[%s]"), ((qse_awk_val_rex_t*)val)->buf); + DPRINTF (DCUSTOM, QSE_T("REX[%s]"), ((qse_awk_val_rex_t*)val)->ptr); break; case QSE_AWK_VAL_MAP: diff --git a/qse/lib/cmn/time.c b/qse/lib/cmn/time.c index 0b232028..7f1b5cea 100644 --- a/qse/lib/cmn/time.c +++ b/qse/lib/cmn/time.c @@ -17,9 +17,9 @@ #endif #ifdef _WIN32 - #define WIN_EPOCH_YEAR ((qse_ntime_t)1601) - #define WIN_EPOCH_MON ((qse_ntime_t)1) - #define WIN_EPOCH_DAY ((qse_ntime_t)1) + #define WIN_EPOCH_YEAR (1601) + #define WIN_EPOCH_MON (1) + #define WIN_EPOCH_DAY (1) #define EPOCH_DIFF_YEARS (QSE_EPOCH_YEAR-WIN_EPOCH_YEAR) #define EPOCH_DIFF_DAYS (EPOCH_DIFF_YEARS*365+EPOCH_DIFF_YEARS/4-3) @@ -108,7 +108,7 @@ int qse_settime (qse_ntime_t t) #endif } -static void brkdntime (qse_ntime_t nt, qse_btime_t* bt, qse_ntime_t offset) +static void breakdown_time (qse_ntime_t nt, qse_btime_t* bt, qse_ntime_t offset) { int midx; qse_ntime_t days; /* total days */ @@ -178,7 +178,7 @@ static void brkdntime (qse_ntime_t nt, qse_btime_t* bt, qse_ntime_t offset) int qse_gmtime (qse_ntime_t nt, qse_btime_t* bt) { - brkdntime (nt, bt, 0); + breakdown_time (nt, bt, 0); return 0; } @@ -216,11 +216,69 @@ int qse_localtime (qse_ntime_t nt, qse_btime_t* bt) int qse_timegm (const qse_btime_t* bt, qse_ntime_t* nt) { +#ifdef _WIN32 + /* TODO: verify qse_timegm for WIN32 */ + SYSTEMTIME st; + FILETIME ft; + + st.wYear = bt->tm_year + QSE_EPOCH_YEAR; + st.wMonth = bt->tm_mon + WIN_EPOCH_MON; + st.wDayOfWeek = bt->tm_wday; + st.wDay = bt->tm_mday; + st.wHour = bt->tm_hour; + st.wMinute = bt->tm_min; + st.mSecond = bt->tm_sec; + st.mMilliseconds = bt->tm_msec; + + if (SystemTimeToFileTime (&st, &ft) == FALSE) return -1; + *nt = ((qse_ntime_t)(*((qse_int64_t*)&ft)) / (10 * 1000)); + *nt -= EPOCH_DIFF_MSECS; + + return 0; +#else + /* TODO: qse_timegm - remove dependency on timegm */ + struct tm tm; + + tm.tm_sec = bt->sec; + tm.tm_min = bt->min; + tm.tm_hour = bt->hour; + tm.tm_mday = bt->mday; + tm.tm_mon = bt->mon; + tm.tm_year = bt->year; + tm.tm_wday = bt->wday; + tm.tm_yday = bt->yday; + tm.tm_isdst = bt->isdst; + +#ifdef HAVE_TIMEGM + *nt = ((qse_ntime_t)timegm(&tm)*QSE_MSECS_PER_SEC) + bt->msec; +#else + #warning #### timegm() is not available on this platform #### return -1; +#endif + +#endif } int qse_timelocal (const qse_btime_t* bt, qse_ntime_t* nt) { + /* TODO: qse_timelocal - remove dependency on timelocal */ + struct tm tm; + + tm.tm_sec = bt->sec; + tm.tm_min = bt->min; + tm.tm_hour = bt->hour; + tm.tm_mday = bt->mday; + tm.tm_mon = bt->mon; + tm.tm_year = bt->year; + tm.tm_wday = bt->wday; + tm.tm_yday = bt->yday; + tm.tm_isdst = bt->isdst; + +#ifdef HAVE_TIMELOCAL + *nt = ((qse_ntime_t)timelocal(&tm)*QSE_MSECS_PER_SEC) + bt->msec; +#else + #warning #### timelocal() is not available on this platform #### return -1; +#endif } diff --git a/qse/lib/lsp/Makefile.am b/qse/lib/lsp/Makefile.am index 47160475..20ef0bd4 100644 --- a/qse/lib/lsp/Makefile.am +++ b/qse/lib/lsp/Makefile.am @@ -5,6 +5,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/include lib_LTLIBRARIES = libqselsp.la -libqselsp_la_SOURCES = lsp.c err.c env.c eval.c mem.c mem.h misc.c name.c prim.c prim_compar.c prim.h prim_let.c prim_math.c prim_prog.c print.c read.c lsp_i.h env.h misc.h name.h obj.h +libqselsp_la_SOURCES = lsp.c err.c env.c eval.c mem.c mem.h misc.c name.c prim.c prim_compar.c prim.h prim_let.c prim_math.c prim_prog.c print.c read.c lsp.h env.h misc.h name.h obj.h libqselsp_la_LDFLAGS = -L../cmn -version-info 1:0:0 -no-undefined libqselsp_la_LIBADD = -lqsecmn diff --git a/qse/lib/lsp/Makefile.in b/qse/lib/lsp/Makefile.in index 4a0f71be..21cae6db 100644 --- a/qse/lib/lsp/Makefile.in +++ b/qse/lib/lsp/Makefile.in @@ -203,7 +203,7 @@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = nostdinc AM_CPPFLAGS = -I$(top_srcdir)/include lib_LTLIBRARIES = libqselsp.la -libqselsp_la_SOURCES = lsp.c err.c env.c eval.c mem.c mem.h misc.c name.c prim.c prim_compar.c prim.h prim_let.c prim_math.c prim_prog.c print.c read.c lsp_i.h env.h misc.h name.h obj.h +libqselsp_la_SOURCES = lsp.c err.c env.c eval.c mem.c mem.h misc.c name.c prim.c prim_compar.c prim.h prim_let.c prim_math.c prim_prog.c print.c read.c lsp.h env.h misc.h name.h obj.h libqselsp_la_LDFLAGS = -L../cmn -version-info 1:0:0 -no-undefined libqselsp_la_LIBADD = -lqsecmn all: all-am diff --git a/qse/test/Makefile.am b/qse/test/Makefile.am new file mode 100644 index 00000000..9e2bd116 --- /dev/null +++ b/qse/test/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = cmn diff --git a/qse/test/Makefile.in b/qse/test/Makefile.in new file mode 100644 index 00000000..c3923bb7 --- /dev/null +++ b/qse/test/Makefile.in @@ -0,0 +1,498 @@ +# Makefile.in generated by automake 1.10.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = test +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/include/qse/config.h +CONFIG_CLEAN_FILES = +SOURCES = +DIST_SOURCES = +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-dvi-recursive install-exec-recursive \ + install-html-recursive install-info-recursive \ + install-pdf-recursive install-ps-recursive install-recursive \ + installcheck-recursive installdirs-recursive pdf-recursive \ + ps-recursive uninstall-recursive +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BUILD_CJ = @BUILD_CJ@ +BUILD_JNI = @BUILD_JNI@ +BUILD_MODE = @BUILD_MODE@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CFLAGS_JNI = @CFLAGS_JNI@ +CJ = @CJ@ +CJFLAGS = @CJFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +HAVE_CXX = @HAVE_CXX@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAR_PATH = @JAR_PATH@ +JAVAC = @JAVAC@ +JAVAC_PATH = @JAVAC_PATH@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +RM = @RM@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +SUBDIRS = cmn +all: all-recursive + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign test/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --foreign test/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +$(RECURSIVE_CLEAN_TARGETS): + @failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done + list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + distdir=`$(am__cd) $(distdir) && pwd`; \ + top_distdir=`$(am__cd) $(top_distdir) && pwd`; \ + (cd $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$top_distdir" \ + distdir="$$distdir/$$subdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-recursive +all-am: Makefile +installdirs: installdirs-recursive +installdirs-am: +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-recursive + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +info: info-recursive + +info-am: + +install-data-am: + +install-dvi: install-dvi-recursive + +install-exec-am: + +install-html: install-html-recursive + +install-info: install-info-recursive + +install-man: + +install-pdf: install-pdf-recursive + +install-ps: install-ps-recursive + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: + +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) install-am \ + install-strip + +.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ + all all-am check check-am clean clean-generic clean-libtool \ + ctags ctags-recursive distclean distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \ + uninstall uninstall-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/qse/test/cmn/Makefile.am b/qse/test/cmn/Makefile.am new file mode 100644 index 00000000..cd750803 --- /dev/null +++ b/qse/test/cmn/Makefile.am @@ -0,0 +1,15 @@ +AM_CPPFLAGS = -I$(top_srcdir)/include + +bin_PROGRAMS = chr str sll map lda fio sio time + +LDFLAGS = -L../../lib/cmn -L../../lib/utl +LDADD = -lqseutl -lqsecmn + +chr_SOURCES = chr.c +str_SOURCES = str.c +sll_SOURCES = sll.c +map_SOURCES = map.c +lda_SOURCES = lda.c +fio_SOURCES = fio.c +sio_SOURCES = sio.c +time_SOURCES = time.c diff --git a/qse/test/cmn/Makefile.in b/qse/test/cmn/Makefile.in new file mode 100644 index 00000000..a59bc00f --- /dev/null +++ b/qse/test/cmn/Makefile.in @@ -0,0 +1,544 @@ +# Makefile.in generated by automake 1.10.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +bin_PROGRAMS = chr$(EXEEXT) str$(EXEEXT) sll$(EXEEXT) map$(EXEEXT) \ + lda$(EXEEXT) fio$(EXEEXT) sio$(EXEEXT) time$(EXEEXT) +subdir = test/cmn +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/include/qse/config.h +CONFIG_CLEAN_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) +PROGRAMS = $(bin_PROGRAMS) +am_chr_OBJECTS = chr.$(OBJEXT) +chr_OBJECTS = $(am_chr_OBJECTS) +chr_LDADD = $(LDADD) +chr_DEPENDENCIES = +am_fio_OBJECTS = fio.$(OBJEXT) +fio_OBJECTS = $(am_fio_OBJECTS) +fio_LDADD = $(LDADD) +fio_DEPENDENCIES = +am_lda_OBJECTS = lda.$(OBJEXT) +lda_OBJECTS = $(am_lda_OBJECTS) +lda_LDADD = $(LDADD) +lda_DEPENDENCIES = +am_map_OBJECTS = map.$(OBJEXT) +map_OBJECTS = $(am_map_OBJECTS) +map_LDADD = $(LDADD) +map_DEPENDENCIES = +am_sio_OBJECTS = sio.$(OBJEXT) +sio_OBJECTS = $(am_sio_OBJECTS) +sio_LDADD = $(LDADD) +sio_DEPENDENCIES = +am_sll_OBJECTS = sll.$(OBJEXT) +sll_OBJECTS = $(am_sll_OBJECTS) +sll_LDADD = $(LDADD) +sll_DEPENDENCIES = +am_str_OBJECTS = str.$(OBJEXT) +str_OBJECTS = $(am_str_OBJECTS) +str_LDADD = $(LDADD) +str_DEPENDENCIES = +am_time_OBJECTS = time.$(OBJEXT) +time_OBJECTS = $(am_time_OBJECTS) +time_LDADD = $(LDADD) +time_DEPENDENCIES = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include/qse +depcomp = $(SHELL) $(top_srcdir)/autoconf/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(chr_SOURCES) $(fio_SOURCES) $(lda_SOURCES) $(map_SOURCES) \ + $(sio_SOURCES) $(sll_SOURCES) $(str_SOURCES) $(time_SOURCES) +DIST_SOURCES = $(chr_SOURCES) $(fio_SOURCES) $(lda_SOURCES) \ + $(map_SOURCES) $(sio_SOURCES) $(sll_SOURCES) $(str_SOURCES) \ + $(time_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BUILD_CJ = @BUILD_CJ@ +BUILD_JNI = @BUILD_JNI@ +BUILD_MODE = @BUILD_MODE@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CFLAGS_JNI = @CFLAGS_JNI@ +CJ = @CJ@ +CJFLAGS = @CJFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GREP = @GREP@ +HAVE_CXX = @HAVE_CXX@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAR_PATH = @JAR_PATH@ +JAVAC = @JAVAC@ +JAVAC_PATH = @JAVAC_PATH@ +LD = @LD@ +LDFLAGS = -L../../lib/cmn -L../../lib/utl +LIBM = @LIBM@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +RM = @RM@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AM_CPPFLAGS = -I$(top_srcdir)/include +LDADD = -lqseutl -lqsecmn +chr_SOURCES = chr.c +str_SOURCES = str.c +sll_SOURCES = sll.c +map_SOURCES = map.c +lda_SOURCES = lda.c +fio_SOURCES = fio.c +sio_SOURCES = sio.c +time_SOURCES = time.c +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign test/cmn/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --foreign test/cmn/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + if test -f $$p \ + || test -f $$p1 \ + ; then \ + f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ + else :; fi; \ + done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ + rm -f "$(DESTDIR)$(bindir)/$$f"; \ + done + +clean-binPROGRAMS: + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +chr$(EXEEXT): $(chr_OBJECTS) $(chr_DEPENDENCIES) + @rm -f chr$(EXEEXT) + $(LINK) $(chr_OBJECTS) $(chr_LDADD) $(LIBS) +fio$(EXEEXT): $(fio_OBJECTS) $(fio_DEPENDENCIES) + @rm -f fio$(EXEEXT) + $(LINK) $(fio_OBJECTS) $(fio_LDADD) $(LIBS) +lda$(EXEEXT): $(lda_OBJECTS) $(lda_DEPENDENCIES) + @rm -f lda$(EXEEXT) + $(LINK) $(lda_OBJECTS) $(lda_LDADD) $(LIBS) +map$(EXEEXT): $(map_OBJECTS) $(map_DEPENDENCIES) + @rm -f map$(EXEEXT) + $(LINK) $(map_OBJECTS) $(map_LDADD) $(LIBS) +sio$(EXEEXT): $(sio_OBJECTS) $(sio_DEPENDENCIES) + @rm -f sio$(EXEEXT) + $(LINK) $(sio_OBJECTS) $(sio_LDADD) $(LIBS) +sll$(EXEEXT): $(sll_OBJECTS) $(sll_DEPENDENCIES) + @rm -f sll$(EXEEXT) + $(LINK) $(sll_OBJECTS) $(sll_LDADD) $(LIBS) +str$(EXEEXT): $(str_OBJECTS) $(str_DEPENDENCIES) + @rm -f str$(EXEEXT) + $(LINK) $(str_OBJECTS) $(str_LDADD) $(LIBS) +time$(EXEEXT): $(time_OBJECTS) $(time_DEPENDENCIES) + @rm -f time$(EXEEXT) + $(LINK) $(time_OBJECTS) $(time_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chr.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fio.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lda.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/map.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sio.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sll.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-exec-am: install-binPROGRAMS + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic clean-libtool ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-binPROGRAMS install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-binPROGRAMS + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/qse/test/cmn/chr.c b/qse/test/cmn/chr.c new file mode 100644 index 00000000..47e535a3 --- /dev/null +++ b/qse/test/cmn/chr.c @@ -0,0 +1,156 @@ +#include +#include +#include +#include +#include + +#include +#include + +#define R(f) \ + do { \ + qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \ + if (f() == -1) return -1; \ + } while (0) + +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)); + } + + return 0; +} + +static int test2 (void) +{ + int i; + const qse_mchar_t* x[] = + { + "\0", + "뛰어 올라봐", + "Fly to the universe" + }; + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + qse_size_t k = strlen(x[i]); + qse_size_t j = 0; + qse_wchar_t wc; + + if (k == 0) k++; /* for x[0] */ + + qse_printf (QSE_T("[")); + while (j < k) + { + qse_size_t y = qse_mblen (&x[i][j], k-j); + + if (y == 0) + { + qse_printf (QSE_T("***illegal sequence***")); + break; + } + else if (y > k-j) + { + qse_printf (QSE_T("***incomplete sequence***")); + break; + } + else + { + qse_size_t y2 = qse_mbtowc (&x[i][j], y, &wc); + if (y2 != y) + { + qse_printf (QSE_T("***y(%d) != y2(%d). something is wrong*** "), (int)y, (int)y2); + break; + } + + if (wc == L'\0') + { + qse_printf (QSE_T("'\\0'")); + } + else + { + #if QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("%C"), wc); + #else + qse_printf (QSE_T("%c"), wc); + #endif + } + j += y; + } + } + + qse_printf (QSE_T("] => %d bytes\n"), (int)k); + } + + return 0; +} + +static int test3 (void) +{ + const qse_wchar_t* x[] = + { + L"\0", + L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"Fly to the universe" + }; + char buf[100]; + int i, j; + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + int len = wcslen (x[i]); + if (len == 0) len++; /* for x[0] */ + + qse_printf (QSE_T("[")); + for (j = 0; j < len; j++) + { + qse_size_t n = qse_wctomb (x[i][j], buf, sizeof(buf)); + + if (n == 0) + { + qse_printf (QSE_T("***illegal character***")); + } + else if (n > sizeof(buf)) + { + qse_printf (QSE_T("***buffer too small***")); + } + else + { + if (n == 1 && buf[0] == '\0') + { + qse_printf (QSE_T("'\\0'")); + } + else + { + #if QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("%.*s"), (int)n, buf); + #else + qse_printf (QSE_T("%.*S"), (int)n, buf); + #endif + } + } + } + qse_printf (QSE_T("] => %d chars\n"), (int)len); + } + return 0; +} + +int main () +{ + setlocale (LC_ALL, ""); + + qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); + qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n")); + qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); + + R (test1); + R (test2); + R (test3); + + return 0; +} diff --git a/qse/test/cmn/fio.c b/qse/test/cmn/fio.c new file mode 100644 index 00000000..de724e0b --- /dev/null +++ b/qse/test/cmn/fio.c @@ -0,0 +1,207 @@ +#include +#include + +#include +#include + +#define R(f) \ + do { \ + qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \ + if (f() == -1) return -1; \ + } while (0) + +static int test1 (void) +{ + qse_fio_t* fio; + qse_ssize_t n; + char x[] = "fio test"; + char x2[] = "fio test2"; + qse_fio_off_t off; + char buf[1000]; + + fio = qse_fio_open ( + QSE_NULL, + 0, + QSE_T("fio1.txt"), + QSE_FIO_READ|QSE_FIO_WRITE|QSE_FIO_CREATE|QSE_FIO_TRUNCATE, + QSE_FIO_RUSR|QSE_FIO_WUSR|QSE_FIO_RGRP|QSE_FIO_ROTH + ); + if (fio == QSE_NULL) + { + qse_printf (QSE_T("cannot open file\n")); + return -1; + } + + n = qse_fio_write (fio, x, strlen(x)); + qse_printf (QSE_T("written %d bytes\n"), (int)n); + + off = qse_fio_seek (fio, 0, QSE_FIO_CURRENT); + if (off == (qse_fio_off_t)-1) + { + qse_printf (QSE_T("failed to get file offset\n")); + } + else + { + qse_printf (QSE_T("file offset at %lld\n"), (long long)off); + } + + off = qse_fio_seek (fio, 0, QSE_FIO_BEGIN); + if (off == (qse_fio_off_t)-1) + { + qse_printf (QSE_T("failed to set file offset\n")); + } + else + { + qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off); + } + + n = qse_fio_read (fio, buf, sizeof(buf)); + qse_printf (QSE_T("read %d bytes \n"), (int)n); + if (n > 0) + { + #ifdef QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("buf => [%.*s]\n"), (int)n. buf); + #else + qse_printf (QSE_T("buf => [%.*S]\n"), (int)n, buf); + #endif + } + + off = qse_fio_seek (fio, QSE_TYPE_MAX(int) * 3llu, QSE_FIO_BEGIN); + if (off == (qse_fio_off_t)-1) + { + qse_printf (QSE_T("failed to set file offset\n")); + } + else + { + qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off); + } + + n = qse_fio_write (fio, x2, strlen(x2)); + qse_printf (QSE_T("written %d bytes\n"), (int)n); + + qse_fio_close (fio); + + return 0; +} + +static int test2 (void) +{ + qse_fio_t* fio; + qse_ssize_t n; + char x[] = "fio test"; + char x2[] = "fio test2"; + qse_fio_off_t off; + char buf[1000]; + int i; + + fio = qse_fio_open ( + QSE_NULL, + 0, + QSE_T("fio2.txt"), + QSE_FIO_CREATE | QSE_FIO_TRUNCATE | QSE_FIO_APPEND, + QSE_FIO_RUSR|QSE_FIO_WUSR|QSE_FIO_RGRP|QSE_FIO_ROTH + ); + if (fio == QSE_NULL) + { + qse_printf (QSE_T("cannot open file\n")); + return -1; + } + + for (i = 0; i < 2; i++) + { + n = qse_fio_write (fio, x, strlen(x)); + qse_printf (QSE_T("written %d bytes\n"), (int)n); + + off = qse_fio_seek (fio, 0, QSE_FIO_CURRENT); + if (off == (qse_fio_off_t)-1) + { + qse_printf (QSE_T("failed to get file offset\n")); + } + else + { + qse_printf (QSE_T("file offset at %lld\n"), (long long)off); + } + + off = qse_fio_seek (fio, 0, QSE_FIO_BEGIN); + if (off == (qse_fio_off_t)-1) + { + qse_printf (QSE_T("failed to set file offset\n")); + } + else + { + qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off); + } + } + + + n = qse_fio_read (fio, buf, sizeof(buf)); + qse_printf (QSE_T("read %d bytes \n"), (int)n); + if (n > 0) + { + #ifdef QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("buf => [%.*s]\n"), (int)n. buf); + #else + qse_printf (QSE_T("buf => [%.*S]\n"), (int)n, buf); + #endif + } + + off = qse_fio_seek (fio, QSE_TYPE_MAX(int) * 2llu, QSE_FIO_BEGIN); + if (off == (qse_fio_off_t)-1) + { + qse_printf (QSE_T("failed to set file offset\n")); + } + else + { + qse_printf (QSE_T("moved file offset to %lld\n"), (long long)off); + } + + n = qse_fio_write (fio, x2, strlen(x2)); + qse_printf (QSE_T("written %d bytes\n"), (int)n); + + off = qse_fio_seek (fio, 0, QSE_FIO_CURRENT); + if (off == (qse_fio_off_t)-1) + { + qse_printf (QSE_T("failed to get file offset\n")); + } + else + { + qse_printf (QSE_T("file offset at %lld\n"), (long long)off); + } + + if (qse_fio_truncate (fio, 20000) == -1) + { + qse_printf (QSE_T("failed to truncate the file\n")); + } + + n = qse_fio_write (fio, x2, strlen(x2)); + qse_printf (QSE_T("written %d bytes\n"), (int)n); + + off = qse_fio_seek (fio, 0, QSE_FIO_CURRENT); + if (off == (qse_fio_off_t)-1) + { + qse_printf (QSE_T("failed to get file offset\n")); + } + else + { + qse_printf (QSE_T("file offset at %lld\n"), (long long)off); + } + + qse_fio_chmod (fio, QSE_FIO_RUSR|QSE_FIO_RGRP); + qse_fio_close (fio); + + return 0; +} + +int main () +{ + setlocale (LC_ALL, ""); + + qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); + qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n")); + qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); + + R (test1); + R (test2); + + return 0; +} diff --git a/qse/test/cmn/lda.c b/qse/test/cmn/lda.c new file mode 100644 index 00000000..eab6f635 --- /dev/null +++ b/qse/test/cmn/lda.c @@ -0,0 +1,369 @@ +#include +#include +#include +#include + + +#define R(f) \ + do { \ + qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \ + if (f() == -1) return -1; \ + } while (0) + +void keeper1 (qse_lda_t* lda, void* dptr, qse_size_t dlen) +{ + qse_printf (QSE_T("[%.*s] has been kept\n"), (int)dlen, dptr); +} + +qse_lda_walk_t walker1 (qse_lda_t* lda, qse_size_t index, void* arg) +{ + qse_printf (QSE_T("%d => [%.*s]\n"), + index, (int)QSE_LDA_DLEN(lda,index), QSE_LDA_DPTR(lda,index)); + return QSE_LDA_WALK_FORWARD; +} +qse_lda_walk_t rwalker1 (qse_lda_t* lda, qse_size_t index, void* arg) +{ + qse_printf (QSE_T("%d => [%.*s]\n"), + index, (int)QSE_LDA_DLEN(lda,index), QSE_LDA_DPTR(lda,index)); + return QSE_LDA_WALK_BACKWARD; +} + +static int test1 () +{ + qse_lda_t* s1; + qse_char_t* x[] = + { + QSE_T("this is so good"), + QSE_T("what the fuck"), + QSE_T("do you like it?"), + QSE_T("oopsy!") + }; + int i; + + s1 = qse_lda_open (QSE_MMGR_GETDFL(), 0, 0); + if (s1 == QSE_NULL) + { + qse_printf (QSE_T("cannot open a string\n")); + return -1; + } + + qse_lda_setcopier (s1, QSE_LDA_COPIER_INLINE); + qse_lda_setkeeper (s1, keeper1); + qse_lda_setscale (s1, QSE_SIZEOF(qse_char_t)); + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + if (qse_lda_insert (s1, 0, x[i], qse_strlen(x[i])) == QSE_LDA_INVALID) + { + qse_printf (QSE_T("failed to add at 0 => [%.*s]\n"), + (int)qse_strlen(x[i]), x[i]); + } + else + { + qse_printf (QSE_T("add at 0 => [%.*s]\n"), + (int)qse_strlen(x[i]), x[i]); + } + } + + if (qse_lda_update (s1, 0, QSE_LDA_DPTR(s1,0), QSE_LDA_DLEN(s1,0)) == QSE_LDA_INVALID) + { + qse_printf (QSE_T("failed to update index 0 with [%.*s]\n"), (int)QSE_LDA_DLEN(s1,0), QSE_LDA_DPTR(s1,0)); + } + else + { + qse_printf (QSE_T("updated index 0 with [%.*s]\n"), (int)QSE_LDA_DLEN(s1,0), QSE_LDA_DPTR(s1,0)); + } + + if (qse_lda_update (s1, 0, QSE_LDA_DPTR(s1,1), QSE_LDA_DLEN(s1,1)) == QSE_LDA_INVALID) + { + qse_printf (QSE_T("updated index 0 with [%.*s]\n"), (int)QSE_LDA_DLEN(s1,1), QSE_LDA_DPTR(s1,1)); + } + else + { + qse_printf (QSE_T("updated index 0 with [%.*s]\n"), (int)QSE_LDA_DLEN(s1,0), QSE_LDA_DPTR(s1,0)); + } + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + if (qse_lda_insert (s1, 10, x[i], qse_strlen(x[i])) == QSE_LDA_INVALID) + { + qse_printf (QSE_T("failed to add at 10 => [%.*s]\n"), + (int)qse_strlen(x[i]), x[i]); + } + else + { + qse_printf (QSE_T("add at 10 => [%.*s]\n"), + (int)qse_strlen(x[i]), x[i]); + } + } + + qse_printf (QSE_T("lda size => %lu\n"), QSE_LDA_SIZE(s1)); + qse_lda_walk (s1, walker1, QSE_NULL); + qse_printf (QSE_T("lda size => %lu\n"), QSE_LDA_SIZE(s1)); + qse_lda_rwalk (s1, rwalker1, QSE_NULL); + + qse_lda_close (s1); + return 0; +} + +static int test2 () +{ + qse_lda_t* s1; + qse_lda_node_t* p; + const qse_char_t* x[] = + { + QSE_T("this is so good"), + QSE_T("what the fuck"), + QSE_T("do you like it?"), + QSE_T("oopsy!"), + QSE_T("hello hello!"), + QSE_T("oopsy!") + }; + const qse_char_t* y[] = + { + QSE_T("tipsy!"), + QSE_T("oopsy!") + }; + int i, j; + + s1 = qse_lda_open (QSE_MMGR_GETDFL(), 0, 0); + if (s1 == QSE_NULL) + { + qse_printf (QSE_T("cannot open a string\n")); + return -1; + } + + qse_lda_setcopier (s1, QSE_LDA_COPIER_INLINE); + qse_lda_setscale (s1, QSE_SIZEOF(qse_char_t)); + + for (j = 0; j < 20; j++) + { + qse_size_t index; + for (i = 0; i < QSE_COUNTOF(x); i++) + { + if (qse_lda_insert (s1, (i + 1) * j - 1, x[i], qse_strlen(x[i])) == QSE_LDA_INVALID) + { + + qse_printf (QSE_T("failed to add at %u => [%.*s]\n"), + (unsigned int)((i + 1) * j - 1), + (int)qse_strlen(x[i]), x[i]); + } + else + { + qse_printf (QSE_T("add at %u => [%.*s]\n"), + (unsigned int)((i + 1) * j - 1), + (int)qse_strlen(x[i]), x[i]); + } + } + + for (i = 0; i < QSE_LDA_SIZE(s1); i++) + { + if (QSE_LDA_NODE(s1,i)) + { + qse_printf (QSE_T("[%d] %d => [%.*s]\n"), + j, i, (int)QSE_LDA_DLEN(s1,i), QSE_LDA_DPTR(s1,i)); + } + } + + + for (i = 0; i < QSE_COUNTOF(y); i++) + { + index = qse_lda_search (s1, 0, y[i], qse_strlen(y[i])); + if (index == QSE_LDA_INVALID) + { + qse_printf (QSE_T("failed to find [%s]\n"), y[i]); + } + else + { + qse_printf (QSE_T("found [%.*s] at %lu\n"), + (int)QSE_LDA_DLEN(s1,index), QSE_LDA_DPTR(s1,index), (unsigned long)index); + } + + index = qse_lda_rsearch (s1, QSE_LDA_SIZE(s1), y[i], qse_strlen(y[i])); + if (index == QSE_LDA_INVALID) + { + qse_printf (QSE_T("failed to find [%s]\n"), y[i]); + } + else + { + qse_printf (QSE_T("found [%.*s] at %lu\n"), + (int)QSE_LDA_DLEN(s1,index), QSE_LDA_DPTR(s1,index), (unsigned long)index); + } + } + + + qse_lda_clear (s1); + qse_printf (QSE_T("~~~~~~~~\n")); + } + + qse_lda_close (s1); + return 0; +} + +static int test3 () +{ + qse_lda_t* s1; + const qse_char_t* x[] = + { + QSE_T("this is so good"), + QSE_T("what the fuck"), + QSE_T("do you like it?"), + QSE_T("oopsy!") + }; + const qse_char_t* y = + QSE_T("We Accept MasterCard, VISA, JCB, Dinner & eCheck"); + int i, j; + + s1 = qse_lda_open (QSE_MMGR_GETDFL(), 0, 0); + if (s1 == QSE_NULL) + { + qse_printf (QSE_T("cannot open a string\n")); + return -1; + } + + qse_lda_setcopier (s1, QSE_LDA_COPIER_INLINE); + qse_lda_setscale (s1, QSE_SIZEOF(qse_char_t)); + + for (j = 0; j < 20; j++) + { + for (i = 0; i < QSE_COUNTOF(x); i++) + { + if (qse_lda_insert (s1, (i + 1) * j - 1, x[i], qse_strlen(x[i])) == QSE_LDA_INVALID) + { + + qse_printf (QSE_T("failed to add at %u => [%.*s]\n"), + (unsigned int)((i + 1) * j - 1), + (int)qse_strlen(x[i]), x[i]); + } + else + { + qse_printf (QSE_T("add at %u => [%.*s]\n"), + (unsigned int)((i + 1) * j - 1), + (int)qse_strlen(x[i]), x[i]); + } + } + + + for (i = 2; i < 3; i++) + { + if (i < QSE_LDA_SIZE(s1)) + { + if (QSE_LDA_NODE(s1,i)) + { + qse_printf (QSE_T("deleted at %d => [%.*s]\n"), + i, (int)QSE_LDA_DLEN(s1,i), QSE_LDA_DPTR(s1,i)); + } + + qse_lda_delete (s1, i, 1); + } + + if (i < QSE_LDA_SIZE(s1)) + { + if (qse_lda_update (s1, i, y, qse_strlen(y)) == QSE_LDA_INVALID) + { + qse_printf (QSE_T("failed to update at %d => [%.*s]\n"), + i, (int)qse_strlen(y), y); + } + else + { + qse_printf (QSE_T("updated at %d => [%.*s]\n"), + i, (int)QSE_LDA_DLEN(s1,i), QSE_LDA_DPTR(s1,i)); + } + } + + } + + qse_printf (QSE_T("array size => %lu\n"), (unsigned long)QSE_LDA_SIZE(s1)); + + for (i = 0; i < QSE_LDA_SIZE(s1); i++) + { + if (QSE_LDA_NODE(s1,i)) + { + qse_printf (QSE_T("[%d] %d => [%.*s]\n"), + j, i, (int)QSE_LDA_DLEN(s1,i), QSE_LDA_DPTR(s1,i)); + } + } + + { + qse_size_t count = qse_lda_uplete (s1, 3, 20); + qse_printf (QSE_T("upleted %lu items from index 3\n"), (unsigned long)count); + } + + qse_printf (QSE_T("array size => %lu\n"), (unsigned long)QSE_LDA_SIZE(s1)); + + for (i = 0; i < QSE_LDA_SIZE(s1); i++) + { + if (QSE_LDA_NODE(s1,i)) + { + qse_printf (QSE_T("[%d] %d => [%.*s]\n"), + j, i, (int)QSE_LDA_DLEN(s1,i), QSE_LDA_DPTR(s1,i)); + } + } + + qse_lda_clear (s1); + qse_printf (QSE_T("~~~~~~~~\n")); + } + + qse_lda_close (s1); + return 0; +} + +qse_size_t sizer1 (qse_lda_t* lda, qse_size_t hint) +{ + return 2; +} + +static int test4 () +{ + int i; + qse_lda_t* s1; + const qse_char_t* x[] = + { + QSE_T("this is so good"), + QSE_T("what the fuck"), + QSE_T("do you like it?"), + QSE_T("oopsy!") + }; + + s1 = qse_lda_open (QSE_MMGR_GETDFL(), 0, 3); + if (s1 == QSE_NULL) + { + qse_printf (QSE_T("cannot open a string\n")); + return -1; + } + + qse_lda_setcopier (s1, QSE_LDA_COPIER_INLINE); + qse_lda_setsizer (s1, sizer1); + qse_lda_setscale (s1, QSE_SIZEOF(qse_char_t)); + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + if (qse_lda_insert (s1, 0, x[i], qse_strlen(x[i])) == QSE_LDA_INVALID) + { + qse_printf (QSE_T("failed to add at 0 => [%.*s]\n"), + (int)qse_strlen(x[i]), x[i]); + } + else + { + qse_printf (QSE_T("add at 0 => [%.*s]\n"), + (int)qse_strlen(x[i]), x[i]); + } + } + + qse_printf (QSE_T("lda size => %lu\n"), QSE_LDA_SIZE(s1)); + qse_lda_walk (s1, walker1, QSE_NULL); + qse_printf (QSE_T("lda size => %lu\n"), QSE_LDA_SIZE(s1)); + qse_lda_rwalk (s1, rwalker1, QSE_NULL); + + qse_lda_close (s1); + return 0; +} + +int main () +{ + R (test1); + R (test2); + R (test3); + R (test4); + return 0; +} diff --git a/qse/test/cmn/map.c b/qse/test/cmn/map.c new file mode 100644 index 00000000..f631332f --- /dev/null +++ b/qse/test/cmn/map.c @@ -0,0 +1,307 @@ +#include +#include +#include +#include +#include + +#define R(f) \ + do { \ + qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \ + if (f() == -1) return -1; \ + } while (0) + +static int test1_build (qse_map_t* s1) +{ + int i; + + + for (i = 1; i < 50; i++) + { + int j = i * 2; + qse_printf (QSE_T("inserting a key %d and a value %d: "), i, j); + + if (qse_map_insert (s1, &i, sizeof(i), &j, sizeof(j)) == QSE_NULL) + { + qse_printf (QSE_T("[FAILED]\n")); + return -1; + } + + qse_printf (QSE_T("[OK]\n")); + } + + return 0; +} + +static void test1_delete (qse_map_t* s1) +{ + int i; + int t[] = { 20, 11, 13, 40 }; + int t2[] = { 22, 21, 31, 14, 48, 32, 29 }; + + for (i = 1; i < 53; i+=2) + { + qse_printf (QSE_T("deleting a key %d: "), i); + if (qse_map_delete (s1, &i, sizeof(i)) == -1) + qse_printf (QSE_T("[FAILED]\n")); + else + qse_printf (QSE_T("[OK]\n")); + } + + + for (i = 0; i < QSE_COUNTOF(t); i++) + { + int k = t[i]; + int v = k * 1000; + + qse_printf (QSE_T("updating a key %d value %d: "), k, v); + if (qse_map_update (s1, &k, sizeof(k), &v, sizeof(v)) == QSE_NULL) + qse_printf (QSE_T("[FAILED]\n")); + else + qse_printf (QSE_T("[OK]\n")); + } + + for (i = 0; i < QSE_COUNTOF(t); i++) + { + int k = t[i]; + int v = k * 1000; + + qse_printf (QSE_T("inserting a key %d value %d: "), k, v); + if (qse_map_insert (s1, &k, sizeof(k), &v, sizeof(v)) == QSE_NULL) + qse_printf (QSE_T("[FAILED]\n")); + else + qse_printf (QSE_T("[OK]\n")); + } + + for (i = 0; i < QSE_COUNTOF(t2); i++) + { + int k = t2[i]; + int v = k * 2000; + + qse_printf (QSE_T("upserting a key %d value %d: "), k, v); + if (qse_map_upsert (s1, &k, sizeof(k), &v, sizeof(v)) == QSE_NULL) + qse_printf (QSE_T("[FAILED]\n")); + else + qse_printf (QSE_T("[OK]\n")); + } +} + +static void test1_dump (qse_map_t* s1) +{ + int i; + + qse_printf (QSE_T("map contains %u pairs\n"), (unsigned)QSE_MAP_SIZE(s1)); + for (i = 1; i < 50; i++) + { + qse_map_pair_t* p = qse_map_search (s1, &i, sizeof(i)); + if (p == QSE_NULL) + { + qse_printf (QSE_T("%d => unknown\n"), i); + } + else + { + qse_printf (QSE_T("%d => %d(%d)\n"), + i, *(int*)QSE_MAP_VPTR(p), (int)QSE_MAP_VLEN(p)); + } + } +} + +static int test1 () +{ + qse_map_t* s1; + + s1 = qse_map_open (QSE_MMGR_GETDFL(), 0, 5, 70); + if (s1 == QSE_NULL) + { + qse_printf (QSE_T("cannot open a map\n")); + return -1; + } + + qse_map_setcopier (s1, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); + qse_map_setcopier (s1, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE); + + if (test1_build(s1) == -1) + { + qse_map_close (s1); + return -1; + } + test1_dump (s1); + + test1_delete (s1); + test1_dump (s1); + + qse_map_close (s1); + return 0; +} + +qse_map_walk_t print_map_pair (qse_map_t* map, qse_map_pair_t* pair, void* arg) +{ + qse_printf (QSE_T("%.*s[%d] => %.*s[%d]\n"), + (int)QSE_MAP_KLEN(pair), QSE_MAP_KPTR(pair), (int)QSE_MAP_KLEN(pair), + (int)QSE_MAP_VLEN(pair), QSE_MAP_VPTR(pair), (int)QSE_MAP_VLEN(pair)); + + return QSE_MAP_WALK_FORWARD; +} + +static int test2 () +{ + qse_map_t* s1; + int i; + qse_char_t* keys[] = + { + QSE_T("if you ever happen"), + QSE_T("to want to link againt"), + QSE_T("installed libraries"), + QSE_T("in a given directory") + }; + + s1 = qse_map_open (QSE_MMGR_GETDFL(), 0, 1, 70); + if (s1 == QSE_NULL) + { + qse_printf (QSE_T("cannot open a map\n")); + return -1; + } + + qse_map_setcopier (s1, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); + qse_map_setcopier (s1, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE); + qse_map_setscale (s1, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t)); + qse_map_setscale (s1, QSE_MAP_VAL, QSE_SIZEOF(qse_char_t)); + + for (i = 0; i < QSE_COUNTOF(keys); i++) + { + int vi = QSE_COUNTOF(keys)-i-1; + + qse_printf (QSE_T("inserting a key [%s] and a value [%s]: "), keys[i], keys[vi]); + if (qse_map_insert (s1, + keys[i], qse_strlen(keys[i]), + keys[vi], qse_strlen(keys[vi])) == QSE_NULL) + { + qse_printf (QSE_T("[FAILED]\n")); + } + else + { + qse_printf (QSE_T("[OK]\n")); + } + } + + qse_map_walk (s1, print_map_pair, QSE_NULL); + + qse_map_close (s1); + return 0; +} + +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()); +} + +qse_map_walk_t print_map_pair_3 (qse_map_t* map, qse_map_pair_t* pair, void* arg) +{ + qse_printf (QSE_T("%.*s[%d] => %d\n"), + (int)QSE_MAP_KLEN(pair), QSE_MAP_KPTR(pair), (int)QSE_MAP_KLEN(pair), + *(int*)QSE_MAP_VPTR(pair)); + + return QSE_MAP_WALK_FORWARD; +} + +static int test3 () +{ + qse_map_t* s1; + int i; + qse_char_t* keys[] = + { + QSE_T("one"), + QSE_T("two"), + QSE_T("three"), + QSE_T("four"), + QSE_T("ONE"), + QSE_T("Two"), + QSE_T("thRee") + }; + + s1 = qse_map_open (QSE_MMGR_GETDFL(), 0, 1, 70); + if (s1 == QSE_NULL) + { + qse_printf (QSE_T("cannot open a map\n")); + return -1; + } + + qse_map_setcopier (s1, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); + qse_map_setcopier (s1, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE); + qse_map_setcomper (s1, comp_key); + qse_map_setscale (s1, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t)); + + for (i = 0; i < QSE_COUNTOF(keys); i++) + { + qse_printf (QSE_T("inserting a key [%s] and a value %d: "), keys[i], i); + if (qse_map_insert (s1, keys[i], qse_strlen(keys[i]), &i, sizeof(i)) == QSE_NULL) + { + qse_printf (QSE_T("[FAILED]\n")); + } + else + { + qse_printf (QSE_T("[OK]\n")); + } + } + + qse_map_walk (s1, print_map_pair_3, QSE_NULL); + + qse_map_close (s1); + return 0; +} + +static int test4 () +{ + qse_map_t* s1; + int i; + qse_char_t* keys[] = + { + QSE_T("one"), + QSE_T("two"), + QSE_T("three"), + QSE_T("four"), + QSE_T("ONE"), + QSE_T("Two"), + QSE_T("thRee") + }; + + s1 = qse_map_open (QSE_MMGR_GETDFL(), 0, 1, 70); + if (s1 == QSE_NULL) + { + qse_printf (QSE_T("cannot open a map\n")); + return -1; + } + + qse_map_setcopier (s1, QSE_MAP_KEY, QSE_MAP_COPIER_INLINE); + qse_map_setcopier (s1, QSE_MAP_VAL, QSE_MAP_COPIER_INLINE); + qse_map_setcomper (s1, comp_key); + qse_map_setscale (s1, QSE_MAP_KEY, QSE_SIZEOF(qse_char_t)); + + for (i = 0; i < QSE_COUNTOF(keys); i++) + { + qse_printf (QSE_T("upserting a key [%s] and a value %d: "), keys[i], i); + if (qse_map_upsert (s1, keys[i], qse_strlen(keys[i]), &i, sizeof(i)) == QSE_NULL) + { + qse_printf (QSE_T("[FAILED]\n")); + } + else + { + qse_printf (QSE_T("[OK]\n")); + } + } + + qse_map_walk (s1, print_map_pair_3, QSE_NULL); + + qse_map_close (s1); + return 0; +} + +int main () +{ + R (test1); + R (test2); + R (test3); + R (test4); + return 0; +} diff --git a/qse/test/cmn/sio.c b/qse/test/cmn/sio.c new file mode 100644 index 00000000..9b442eeb --- /dev/null +++ b/qse/test/cmn/sio.c @@ -0,0 +1,86 @@ +#include +#include +#include + +#define R(f) \ + do { \ + qse_sio_puts (qse_sio_out,QSE_T("== ")); \ + qse_sio_puts (qse_sio_out,QSE_T(#f)); \ + qse_sio_puts (qse_sio_out,QSE_T(" ==\n")); \ + if (f() == -1) return -1; \ + } while (0) + +static int test1 (void) +{ + qse_sio_t* sio; + int i; + const qse_wchar_t* x[] = + { + L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"Fly to the universe, kick you ass", + L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"Fly to the universe, kick you ass", + L"Fly to the universe, kick you ass", + L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?" + }; + + sio = qse_sio_open (QSE_NULL, 0, QSE_T("sio.txt"), + QSE_SIO_WRITE | QSE_SIO_CREATE | QSE_SIO_TRUNCATE); + + if (sio == QSE_NULL) + { + qse_sio_puts (qse_sio_err, QSE_T("cannot open file\n")); + return -1; + } + + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + qse_sio_puts (qse_sio_out, QSE_T("written: [")); + qse_sio_puts (qse_sio_out, x[i]); + qse_sio_puts (qse_sio_out, QSE_T("]\n")); + + qse_sio_puts (sio, x[i]); + qse_sio_putc (sio, QSE_T('\n')); + } + + qse_sio_close (sio); + + return 0; +} + +static int test2 (void) +{ + qse_ssize_t n; + qse_char_t buf[20]; + + qse_sio_puts (qse_sio_out, QSE_T("type somthing...\n")); + while (1) + { + n = qse_sio_gets (qse_sio_in, buf, QSE_COUNTOF(buf)); + if (n == 0) break; + if (n < 0) + { + qse_sio_puts (qse_sio_err, QSE_T("error ....\n")); + break; + } + + qse_sio_puts (qse_sio_out, buf); + } + + return 0; +} + +int main () +{ + setlocale (LC_ALL, ""); + + qse_sio_puts (qse_sio_out, QSE_T("--------------------------------------------------------------------------------\n")); + qse_sio_puts (qse_sio_out, QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n")); + qse_sio_puts (qse_sio_out, QSE_T("--------------------------------------------------------------------------------\n")); + + R (test1); + R (test2); + + return 0; +} diff --git a/qse/test/cmn/sll.c b/qse/test/cmn/sll.c new file mode 100644 index 00000000..ed6fb52c --- /dev/null +++ b/qse/test/cmn/sll.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + + +#define R(f) \ + do { \ + qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \ + if (f() == -1) return -1; \ + } while (0) + +static qse_sll_walk_t walk_sll (qse_sll_t* sll, qse_sll_node_t* n, void* arg) +{ + qse_printf (QSE_T("[%.*s]\n"), (int)QSE_SLL_DLEN(n), QSE_SLL_DPTR(n)); + return QSE_SLL_WALK_FORWARD; +} + +static int test1 () +{ + qse_sll_t* s1; + qse_sll_node_t* p; + qse_char_t* x[] = + { + QSE_T("this is so good"), + QSE_T("what the hack"), + QSE_T("do you like it?") + }; + int i; + + s1 = qse_sll_open (QSE_MMGR_GETDFL(), 0); + if (s1 == QSE_NULL) + { + qse_printf (QSE_T("cannot open a string\n")); + return -1; + } + + qse_sll_setcopier (s1, QSE_SLL_COPIER_INLINE); + qse_sll_setscale (s1, QSE_SIZEOF(qse_char_t)); + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + qse_sll_pushtail (s1, x[i], qse_strlen(x[i])); + } + qse_printf (QSE_T("s1 holding [%d] nodes\n"), QSE_SLL_SIZE(s1)); + qse_sll_walk (s1, walk_sll, QSE_NULL); + + + p = qse_sll_search (s1, QSE_NULL, x[0], qse_strlen(x[0])); + if (p != QSE_NULL) + { + qse_sll_delete (s1, p); + } + qse_printf (QSE_T("s1 holding [%d] nodes\n"), QSE_SLL_SIZE(s1)); + qse_sll_walk (s1, walk_sll, QSE_NULL); + + qse_sll_close (s1); + return 0; +} + +int main () +{ + R (test1); + return 0; +} diff --git a/qse/test/cmn/str.c b/qse/test/cmn/str.c new file mode 100644 index 00000000..10b39605 --- /dev/null +++ b/qse/test/cmn/str.c @@ -0,0 +1,436 @@ +#include +#include +#include + +#include +#include +#include + +#define R(f) \ + do { \ + qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \ + if (f() == -1) return -1; \ + } while (0) + +static int test1 () +{ + qse_str_t* s1; + + s1 = qse_str_open (QSE_MMGR_GETDFL(), 0, 5); + if (s1 == QSE_NULL) + { + qse_printf (QSE_T("cannot open a string\n")); + return -1; + } + + qse_printf (QSE_T("LEN=%u\n"), + (unsigned)qse_str_ncat (s1, QSE_T("i love you this is great"), 24)); + qse_printf (QSE_T("LEN=%u CAPA=%u [%.*s]\n"), + (unsigned)QSE_STR_LEN(s1), (unsigned)QSE_STR_CAPA(s1), + (int)QSE_STR_LEN(s1), QSE_STR_PTR(s1)); + + qse_str_close (s1); + return 0; +} + +static int test2 () +{ + qse_str_t s1; + + qse_str_init (&s1, QSE_MMGR_GETDFL(), 5); + + qse_printf (QSE_T("LEN=%u\n"), + (unsigned)qse_str_ncat (&s1, QSE_T("i love you this is great"), 24)); + qse_printf (QSE_T("LEN=%u CAPA=%u [%.*s]\n"), + (unsigned)QSE_STR_LEN(&s1), (unsigned)QSE_STR_CAPA(&s1), + (int)QSE_STR_LEN(&s1), QSE_STR_PTR(&s1)); + + qse_str_fini (&s1); + return 0; +} + +static qse_size_t resize_str_1 (qse_str_t* str, qse_size_t hint) +{ + return QSE_STR_CAPA(str) + 1; +} + +static qse_size_t resize_str_2 (qse_str_t* str, qse_size_t hint) +{ + return hint; +} + +static qse_size_t resize_str_3 (qse_str_t* str, qse_size_t hint) +{ + return hint * 2 + hint / 2; +} + +static qse_size_t resize_str_4 (qse_str_t* str, qse_size_t hint) +{ + return 0; +} + +static int test3 () +{ + qse_str_t s1; + int i; + + qse_str_init (&s1, QSE_MMGR_GETDFL(), 5); + + for (i = 0; i < 9; i++) + { + if (i == 0) qse_str_setsizer (&s1, resize_str_1); + if (i == 1) + { + qse_str_setsizer (&s1, resize_str_2); + qse_str_clear (&s1); + } + if (i == 2) qse_str_setsizer (&s1, resize_str_3); + if (i == 3) qse_str_setsizer (&s1, resize_str_4); + if (i == 8) qse_str_setsizer (&s1, resize_str_2); + + if (qse_str_ncat (&s1, QSE_T("i love you this is great"), 24) == (qse_size_t)-1) + { + qse_printf (QSE_T("cannot add string\n")); + qse_str_fini (&s1); + return -1; + } + + qse_printf (QSE_T("LEN=%u CAPA=%u [%.*s]\n"), + (unsigned)QSE_STR_LEN(&s1), (unsigned)QSE_STR_CAPA(&s1), + (int)QSE_STR_LEN(&s1), QSE_STR_PTR(&s1)); + } + + qse_str_fini (&s1); + return 0; +} + +static int test4 () +{ + qse_str_t s1; + qse_xstr_t out; + + qse_str_init (&s1, QSE_MMGR_GETDFL(), 0); + + if (qse_str_yield (&s1, &out, 0) == -1) + { + qse_printf (QSE_T("cannot yield string\n")); + qse_str_fini (&s1); + return -1; + } + + qse_printf (QSE_T("out.ptr=%p LEN=%u [.*s]\n"), + out.ptr, (unsigned)out.len, (int)out.len, out.ptr); + + if (qse_str_ncat (&s1, QSE_T("i love you this is great"), 24) == (qse_size_t)-1) + { + qse_printf (QSE_T("cannot add string\n")); + qse_str_fini (&s1); + return -1; + } + + if (qse_str_yield (&s1, &out, 0) == -1) + { + qse_printf (QSE_T("cannot yield string\n")); + qse_str_fini (&s1); + return -1; + } + + qse_printf (QSE_T("out.ptr=%p LEN=%u, [%.*s]\n"), + out.ptr, (unsigned)out.len, (int)out.len, out.ptr); + + qse_str_fini (&s1); + + QSE_MMGR_FREE (QSE_MMGR_GETDFL(), out.ptr); + return 0; +} + +static int test5 (void) +{ + int i; + const qse_mchar_t* x[] = + { + "\0\0\0", + "뛰어 올라봐. 멀리멀리 잘난척하기는", + "Fly to the universe" + }; + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + qse_size_t k = strlen(x[i]); + qse_size_t j = 0; + qse_wchar_t wc; + qse_wchar_t buf[10]; + + if (k == 0) k = 3; /* for x[0] */ + + qse_printf (QSE_T("[")); + + while (j < k) + { + qse_size_t wlen = QSE_COUNTOF(buf); + qse_size_t y = qse_mbsntowcsn (&x[i][j], k-j, buf, &wlen); + + if (y <= 0) + { + qse_printf (QSE_T("***illegal or incomplete sequence***")); + break; + } + + if (wlen > 0 && buf[0] == QSE_T('\0')) + { + while (wlen > 0 && buf[--wlen] == QSE_T('\0')) + { + qse_printf (QSE_T("\\0")); + } + } + else + { + qse_printf (QSE_T("%.*s"), (int)wlen, buf); + } + + j += y; + } + + qse_printf (QSE_T("] => %d bytes\n"), (int)k); + } + + return 0; +} + +static int test6 (void) +{ + int i; + const qse_mchar_t* x[] = + { + "", + "뛰어 올라봐. 멀리멀리 잘난척하기는", + "Fly to the universe. eat my shorts." + }; + qse_wchar_t buf[5]; + qse_wchar_t buf2[50]; + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + qse_size_t n; + qse_size_t wlen = QSE_COUNTOF(buf); + n = qse_mbstowcs (x[i], buf, &wlen); + + qse_printf (QSE_T("[%S]=>"),x[i]); + + #ifdef QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("[%S] %d chars %d bytes\n"), buf, (int)wlen, (int)n); + #else + qse_printf (QSE_T("[%s] %d chars %d bytes\n"), buf, (int)wlen, (int)n); + #endif + } + + qse_printf (QSE_T("-----------------\n")); + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + qse_size_t n; + qse_size_t wlen = QSE_COUNTOF(buf2); + n = qse_mbstowcs (x[i], buf2, &wlen); + + #ifdef QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("[%S] %d chars %d bytes\n"), buf2, (int)wlen, (int)n); + #else + qse_printf (QSE_T("[%s] %d chars %d bytes\n"), buf2, (int)wlen, (int)n); + #endif + } + + return 0; +} + +static int test7 (void) +{ + const qse_wchar_t* x[] = + { + L"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", + L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"Fly to the universe, kick you ass" + }; + qse_mchar_t buf[15]; + int i, j; + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + size_t len = wcslen(x[i]); + qse_size_t n; + + if (len == 0) len = 20; /* for x[0] */ + + qse_printf (QSE_T("[")); + + for (j = 0; j < len; j += n) + { + qse_size_t mlen = sizeof(buf); + n = qse_wcsntombsn (&x[i][j], len-j, buf, &mlen); + + if (n <= 0) + { + qse_printf (QSE_T("***illegal character or buffer not large***")); + break; + } + + if (mlen > 0 && buf[0] == QSE_T('\0')) + { + while (mlen > 0 && buf[--mlen] == QSE_T('\0')) + { + qse_printf (QSE_T("\\0")); + } + } + else + { + #ifdef QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("%.*s"), (int)mlen, buf); + #else + #ifdef _WIN32 + qse_printf (QSE_T("%.*S"), (int)mlen, buf); + #else + /* at least on linux and macosx, wprintf seems + * to taks preceision as the number of wide + * characters with %s. */ + qse_printf (QSE_T("%.*S"), n, buf); + #endif + #endif + } + } + + qse_printf (QSE_T("] => %d chars\n"), (int)len); + } + return 0; +} + +static int test8 (void) +{ + const qse_wchar_t* x[] = + { + L"", + L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"Fly to the universe, kick you ass" + }; + qse_mchar_t buf[10]; + qse_mchar_t buf2[100]; + int i, j; + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + qse_size_t n; + qse_size_t mlen = sizeof(buf); + + memset (buf, 'A', sizeof(buf)); + n = qse_wcstombs (x[i], buf, &mlen); + + #ifdef QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("[%s] chars=%d bytes=%d\n"), buf, (int)n, (int)mlen); + #else + qse_printf (QSE_T("[%S] chars=%d bytes=%d\n"), buf, (int)n, (int)mlen); + #endif + } + + qse_printf (QSE_T("-----------------\n")); + for (i = 0; i < QSE_COUNTOF(x); i++) + { + qse_size_t n; + qse_size_t mlen = sizeof(buf2); + + memset (buf2, 'A', sizeof(buf2)); + n = qse_wcstombs (x[i], buf2, &mlen); + + #ifdef QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("[%s] chars=%d bytes=%d\n"), buf2, (int)n, (int)mlen); + #else + qse_printf (QSE_T("[%S] chars=%d bytes=%d\n"), buf2, (int)n, (int)mlen); + #endif + } + + qse_printf (QSE_T("-----------------\n")); + for (i = 0; i < QSE_COUNTOF(x); i++) + { + qse_size_t n; + const qse_wchar_t* p = x[i]; + + while (1) + { + memset (buf, 'A', sizeof(buf)); + qse_size_t mlen = sizeof(buf); + n = qse_wcstombs (p, buf, &mlen); + if (n == 0) break; + + #ifdef QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("[%s] chars=%d bytes=%d\n"), buf, (int)n, (int)mlen); + #else + qse_printf (QSE_T("[%S] chars=%d bytes=%d\n"), buf, (int)n, (int)mlen); + #endif + p += n; + } + } + + return 0; +} + +static int test9 (void) +{ + char buf[24]; + int i; + + const qse_wchar_t* x[] = + { + L"", + L"\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"A\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"AB\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"ABC\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"ABCD\uB108 \uBB50\uAC00 \uC798\uB0AC\uC5B4?", + L"ABCDEFGHIJKLMNOPQRSTUV", + L"ABCDEFGHIJKLMNOPQRSTUVW", + L"ABCDEFGHIJKLMNOPQRSTUVWX", + L"ABCDEFGHIJKLMNOPQRSTUVWXY", + L"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + }; + + for (i = 0; i < QSE_COUNTOF(x); i++) + { + #ifdef QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("[%S] => "), x[i]); + #else + qse_printf (QSE_T("[%s] => "), x[i]); + #endif + + if (qse_wcstombs_strict (x[i], buf, QSE_COUNTOF(buf)) == -1) + { + qse_printf (QSE_T("ERROR\n")); + } + else + { + #ifdef QSE_CHAR_IS_MCHAR + qse_printf (QSE_T("[%s]\n"), buf); + #else + qse_printf (QSE_T("[%S]\n"), buf); + #endif + } + } +} + + +int main () +{ + setlocale (LC_ALL, ""); + + qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); + qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n")); + qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); + + R (test1); + R (test2); + R (test3); + R (test4); + R (test5); + R (test6); + R (test7); + R (test8); + R (test9); + + return 0; +} diff --git a/qse/test/cmn/time.c b/qse/test/cmn/time.c new file mode 100644 index 00000000..946d0f41 --- /dev/null +++ b/qse/test/cmn/time.c @@ -0,0 +1,105 @@ +#include +#include +#include + +#include +#include + +#define R(f) \ + do { \ + qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \ + if (f() == -1) return -1; \ + } while (0) + +void print_time (qse_ntime_t nt, const qse_btime_t* bt) +{ + qse_printf (QSE_T("TIME: %lld\n"), (long long)nt); + qse_printf (QSE_T("year: %d\n"), bt->year + QSE_BTIME_YEAR_BASE); + qse_printf (QSE_T("mon: %d\n"), bt->mon + 1); + qse_printf (QSE_T("mday: %d\n"), bt->mday); + qse_printf (QSE_T("wday: %d\n"), bt->wday); + qse_printf (QSE_T("hour: %d\n"), bt->hour); + qse_printf (QSE_T("min: %d\n"), bt->min); + qse_printf (QSE_T("sec: %d\n"), bt->sec); + qse_printf (QSE_T("msec: %d\n"), bt->msec); +} + +static int test1 (void) +{ + qse_ntime_t nt; + qse_btime_t bt; + + if (qse_gettime (&nt) == -1) + { + qse_printf (QSE_T("cannot get the current time\n")); + return -1; + } + + qse_gmtime (nt, &bt); + print_time (nt, &bt); + qse_printf (QSE_T("-------------------------------\n")); + + nt = 9999999; + if (qse_timegm (&bt, &nt) == -1) + { + qse_printf (QSE_T("cannot covert back to ntime\n")); + qse_printf (QSE_T("-------------------------------\n")); + } + else + { + qse_printf (QSE_T("back to ntime: %lld\n"), (long long)nt); + qse_gmtime (nt, &bt); + print_time (nt, &bt); + qse_printf (QSE_T("-------------------------------\n")); + } + + nt *= -1; + qse_gmtime (nt, &bt); + print_time (nt, &bt); + qse_printf (QSE_T("-------------------------------\n")); + + + for (nt = (qse_ntime_t)QSE_TYPE_MIN(int); + nt <= (qse_ntime_t)QSE_TYPE_MAX(int); nt += QSE_SECS_PER_DAY) + { + time_t t = (time_t)nt; + struct tm* tm; + + tm = gmtime (&t); + qse_gmtime (nt * 1000, &bt); + + qse_printf (QSE_T(">>> time %lld: "), (long long)nt*1000); + + if (tm->tm_year != bt.year || + tm->tm_mon != bt.mon || + tm->tm_mday != bt.mday || + tm->tm_wday != bt.wday || + tm->tm_hour != bt.hour || + tm->tm_min != bt.min || + tm->tm_sec != bt.sec) + { + qse_printf (QSE_T("[ERROR]\n")); + print_time (nt, &bt); + qse_printf (QSE_T("-------------------------------\n")); + } + else + { + qse_printf (QSE_T("[OK]\n")); + } + } + + return 0; +} + +int main () +{ + setlocale (LC_ALL, ""); + + qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); + qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n")); + qse_printf (QSE_T("--------------------------------------------------------------------------------\n")); + + R (test1); + + return 0; +}