added str::value().

This commit is contained in:
hyung-hwan 2014-05-01 14:35:17 +00:00
parent 45b2bc5e57
commit ffe3bd3207
4 changed files with 66 additions and 5 deletions

View File

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

View File

@ -34,6 +34,8 @@
#elif defined(__DOS__)
# include <dos.h>
# include <errno.h>
#elif defined(macintosh)
# include <Files.h>
#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
/* ------------------------------------------------------------------- */

View File

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

View File

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