From ffe3bd3207de868ae0e59bfb535be3499f40d3b9 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 1 May 2014 14:35:17 +0000 Subject: [PATCH] added str::value(). --- qse/lib/awk/mod-str.c | 28 +++++++++++++++++++++++++++- qse/lib/cmn/glob.c | 17 +++++++++++++++++ qse/lib/cmn/slmb.c | 17 +++++++++++++---- qse/lib/cmn/time.c | 9 +++++++++ 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/qse/lib/awk/mod-str.c b/qse/lib/awk/mod-str.c index f855e77e..9ee1db8c 100644 --- a/qse/lib/awk/mod-str.c +++ b/qse/lib/awk/mod-str.c @@ -262,6 +262,31 @@ static int fnc_isxdigit (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) return is_class (rtx, QSE_CTYPE_XDIGIT); } +static int fnc_value (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) +{ + /* return the numeric value for the first character */ + qse_xstr_t path; + qse_awk_val_t* retv; + qse_awk_val_t* a0; + + a0 = qse_awk_rtx_getarg(rtx, 0); + + path.ptr = qse_awk_rtx_getvalstr (rtx, a0, &path.len); + if (path.ptr && path.len >= 1) + { + #if defined(QSE_CHAR_IS_MCHAR) + /* typecasting in case qse_mchar_t is signed */ + retv = qse_awk_rtx_makeintval (rtx, (unsigned char)path.ptr[0]); + #else + retv = qse_awk_rtx_makeintval (rtx, path.ptr[0]); + #endif + qse_awk_rtx_freevalstr (rtx, a0, path.ptr); + if (retv) qse_awk_rtx_setretval (rtx, retv); + } + + return 0; +} + typedef struct fnctab_t fnctab_t; struct fnctab_t { @@ -289,7 +314,8 @@ static fnctab_t fnctab[] = { QSE_T("normspace"), { { 1, 1, QSE_NULL }, fnc_normspace, 0 } }, { QSE_T("rindex"), { { 2, 3, QSE_NULL }, fnc_rindex, 0 } }, { QSE_T("rtrim"), { { 1, 1, QSE_NULL }, fnc_rtrim, 0 } }, - { QSE_T("trim"), { { 1, 1, QSE_NULL }, fnc_trim, 0 } } + { QSE_T("trim"), { { 1, 1, QSE_NULL }, fnc_trim, 0 } }, + { QSE_T("value"), { { 1, 1, QSE_NULL }, fnc_value, 0 } } }; static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym) diff --git a/qse/lib/cmn/glob.c b/qse/lib/cmn/glob.c index 4735be23..4fc1aeab 100644 --- a/qse/lib/cmn/glob.c +++ b/qse/lib/cmn/glob.c @@ -34,6 +34,8 @@ #elif defined(__DOS__) # include # include +#elif defined(macintosh) +# include #else # include "syscall.h" #endif @@ -155,6 +157,21 @@ static int path_exists (glob_t* g, const qse_char_t* name) (errno == ENOENT)? 0: -1; /* ------------------------------------------------------------------- */ +#elif defined(macintosh) + HFileInfo fpb; + const qse_mchar_t* mptr; + +#if defined(QSE_CHAR_IS_MCHAR) + mptr = name; +#else + mptr = wcs_to_mbuf (g, name, &g->mbuf); + if (mptr == QSE_NULL) return -1; +#endif + + QSE_MEMSET (&fpb, 0, QSE_SIZEOF(fpb)); + fpb.ioNamePtr = (unsigned char*)mptr; + + return (PBGetCatInfoSync ((CInfoPBRec*)&fpb) == noErr)? 1: 0; #else /* ------------------------------------------------------------------- */ diff --git a/qse/lib/cmn/slmb.c b/qse/lib/cmn/slmb.c index 2308047b..61b564d3 100644 --- a/qse/lib/cmn/slmb.c +++ b/qse/lib/cmn/slmb.c @@ -28,6 +28,9 @@ # define HAVE_MBRLEN # define HAVE_MBRTOWC # define HAVE_WCRTOMB +# elif defined(macintosh) && defined(__MWERKS__) +# define HAVE_WCHAR_H +# define HAVE_STDLIB_H # endif #endif @@ -92,8 +95,10 @@ qse_size_t qse_slwcrtoslmb ( } return n; /* number of bytes written to the buffer */ + #else - #error #### NOT SUPPORTED #### + /* not supported */ + return 0; #endif } @@ -168,8 +173,10 @@ qse_size_t qse_slmbrtoslwc ( if (n == (size_t)-1) return 0; /* invalid sequence */ if (n == (size_t)-2) return mbl + 1; /* incomplete sequence */ return (qse_size_t)n; + #else - #error #### NOT SUPPORTED #### + /* not supported */ + return 0; #endif } @@ -247,7 +254,8 @@ qse_size_t qse_slmbrlen ( return (qse_size_t)n; #endif #else - #error #### NOT SUPPORTED #### + /* not supported */ + return 0; #endif } @@ -283,9 +291,10 @@ qse_size_t qse_slmblenmax (void) #if defined(_WIN32) /* Windows doesn't handle utf8 properly even when your code page * is CP_UTF8(65001). you should use functions in utf8.c for utf8 - * handleing on windows. 2 is the maximum for DBCS encodings. */ + * handling on windows. 2 is the maximum for DBCS encodings. */ return 2; #else return MB_CUR_MAX; #endif } + diff --git a/qse/lib/cmn/time.c b/qse/lib/cmn/time.c index fc9ab288..a7c27876 100644 --- a/qse/lib/cmn/time.c +++ b/qse/lib/cmn/time.c @@ -152,6 +152,15 @@ int qse_gettime (qse_ntime_t* t) t->nsec = QSE_MSEC_TO_NSEC(dt.hsecond * 10); return 0; +#elif defined(macintosh) + unsigned long tv; + + GetDateTime (&tv); + + t->sec = tv; + tv->nsec = 0; + + return 0; #else struct timeval tv; int n;