fixed StdAwk to set the MODPREFIX when dlfcn is activated.

added Awk::getCmgr()
enhanced some string functions to handle byte strings
This commit is contained in:
hyung-hwan 2019-04-23 15:32:23 +00:00
parent 03301b79bf
commit 7811171dff
14 changed files with 383 additions and 157 deletions

View File

@ -959,6 +959,8 @@ public:
/// called close() for finalization before the destructor is executed. /// called close() for finalization before the destructor is executed.
virtual ~Awk () {} virtual ~Awk () {}
qse_cmgr_t* getCmgr () const;
/// ///
/// The open() function initializes an interpreter. /// The open() function initializes an interpreter.
/// You must call this function before doing anything meaningful. /// You must call this function before doing anything meaningful.

View File

@ -2231,6 +2231,11 @@ QSE_EXPORT qse_mmgr_t* qse_awk_rtx_getmmgr (
qse_awk_rtx_t* rtx /**< runtime context */ qse_awk_rtx_t* rtx /**< runtime context */
); );
QSE_EXPORT qse_cmgr_t* qse_awk_rtx_getcmgr (
qse_awk_rtx_t* rtx /**< runtime context */
);
/** /**
* The qse_awk_rtx_getxtn() function gets the pointer to the extension area * The qse_awk_rtx_getxtn() function gets the pointer to the extension area
* created with qse_awk_rtx_open(). * created with qse_awk_rtx_open().

View File

@ -1228,6 +1228,12 @@ void Awk::close ()
this->clearError (); this->clearError ();
} }
qse_cmgr_t* Awk::getCmgr () const
{
if (!this->awk) return QSE_NULL;
return this->awk->cmgr;
}
void Awk::uponClosing () void Awk::uponClosing ()
{ {
// nothing to do // nothing to do

View File

@ -45,6 +45,17 @@
# endif # endif
#endif #endif
// TODO: remove the following definitions and find a way to share the similar definitions in std.c
#if defined(QSE_ENABLE_LIBLTDL)
# define USE_LTDL
#elif defined(HAVE_DLFCN_H)
# define USE_DLFCN
#else
# error UNSUPPORTED DYNAMIC LINKER
#endif
///////////////////////////////// /////////////////////////////////
QSE_BEGIN_NAMESPACE(QSE) QSE_BEGIN_NAMESPACE(QSE)
///////////////////////////////// /////////////////////////////////
@ -117,6 +128,10 @@ int StdAwk::open ()
if (!this->stdmod_up) if (!this->stdmod_up)
{ {
#if defined(USE_DLFCN)
if (qse_awk_setopt(awk, QSE_AWK_MODPOSTFIX, QSE_T(".so")) <= -1) goto oops;
#endif
if (qse_awk_stdmodstartup (this->awk) <= -1) goto oops; if (qse_awk_stdmodstartup (this->awk) <= -1) goto oops;
this->stdmod_up = true; this->stdmod_up = true;
} }
@ -233,6 +248,7 @@ int StdAwk::__build_environ (Run* run, void* envptr)
qse_char_t* kptr, * vptr; qse_char_t* kptr, * vptr;
qse_size_t klen, count; qse_size_t klen, count;
qse_mmgr_t* mmgr = ((Awk*)*run)->getMmgr(); qse_mmgr_t* mmgr = ((Awk*)*run)->getMmgr();
qse_cmgr_t* cmgr = ((Awk*)*run)->getCmgr();
for (count = 0; envarr[count]; count++) for (count = 0; envarr[count]; count++)
{ {
@ -250,8 +266,8 @@ int StdAwk::__build_environ (Run* run, void* envptr)
*eq = QSE_MT('\0'); *eq = QSE_MT('\0');
kptr = qse_mbstowcsdup (envarr[count], &klen, mmgr); kptr = qse_mbstowcsalldupwithcmgr(envarr[count], &klen, mmgr, cmgr);
vptr = qse_mbstowcsdup (eq + 1, QSE_NULL, mmgr); vptr = qse_mbstowcsalldupwithcmgr(eq + 1, QSE_NULL, mmgr, cmgr);
if (kptr == QSE_NULL || vptr == QSE_NULL) if (kptr == QSE_NULL || vptr == QSE_NULL)
{ {
if (kptr) QSE_MMGR_FREE (mmgr, kptr); if (kptr) QSE_MMGR_FREE (mmgr, kptr);
@ -271,8 +287,8 @@ int StdAwk::__build_environ (Run* run, void* envptr)
*eq = QSE_WT('\0'); *eq = QSE_WT('\0');
kptr = qse_wcstombsdup (envarr[count], &klen, mmgr); kptr = qse_wcstombsdupwithcmgr(envarr[count], &klen, mmgr, cmgr);
vptr = qse_wcstombsdup (eq + 1, QSE_NULL, mmgr); vptr = qse_wcstombsdupwithcmgr(eq + 1, QSE_NULL, mmgr, cmgr);
if (kptr == QSE_NULL || vptr == QSE_NULL) if (kptr == QSE_NULL || vptr == QSE_NULL)
{ {
if (kptr) QSE_MMGR_FREE (mmgr, kptr); if (kptr) QSE_MMGR_FREE (mmgr, kptr);

View File

@ -423,9 +423,9 @@ static int index_or_rindex (qse_awk_rtx_t* rtx, int rindex)
qse_size_t len0, len1; qse_size_t len0, len1;
qse_awk_int_t idx, boundary = 1; qse_awk_int_t idx, boundary = 1;
nargs = qse_awk_rtx_getnargs (rtx); nargs = qse_awk_rtx_getnargs(rtx);
a0 = qse_awk_rtx_getarg (rtx, 0); a0 = qse_awk_rtx_getarg(rtx, 0);
a1 = qse_awk_rtx_getarg (rtx, 1); a1 = qse_awk_rtx_getarg(rtx, 1);
/* /*
index ("abc", "d", 3); index ("abc", "d", 3);
@ -437,15 +437,15 @@ static int index_or_rindex (qse_awk_rtx_t* rtx, int rindex)
qse_awk_val_t* a2; qse_awk_val_t* a2;
int n; int n;
a2 = qse_awk_rtx_getarg (rtx, 2); a2 = qse_awk_rtx_getarg(rtx, 2);
n = qse_awk_rtx_valtoint (rtx, a2, &boundary); n = qse_awk_rtx_valtoint(rtx, a2, &boundary);
if (n <= -1) return -1; if (n <= -1) return -1;
} }
str0 = qse_awk_rtx_getvalstr (rtx, a0, &len0); str0 = qse_awk_rtx_getvalstr(rtx, a0, &len0);
if (str0 == QSE_NULL) return -1; if (str0 == QSE_NULL) return -1;
str1 = qse_awk_rtx_getvalstr (rtx, a1, &len1); str1 = qse_awk_rtx_getvalstr(rtx, a1, &len1);
if (str1 == QSE_NULL) if (str1 == QSE_NULL)
{ {
qse_awk_rtx_freevalstr (rtx, a0, str0); qse_awk_rtx_freevalstr (rtx, a0, str0);
@ -470,15 +470,15 @@ static int index_or_rindex (qse_awk_rtx_t* rtx, int rindex)
{ {
/* 'boundary' acts as an end position */ /* 'boundary' acts as an end position */
ptr = rtx->gbl.ignorecase? ptr = rtx->gbl.ignorecase?
qse_strxnrcasestr (&str0[0], boundary, str1, len1): qse_strxnrcasestr(&str0[0], boundary, str1, len1):
qse_strxnrstr (&str0[0], boundary, str1, len1); qse_strxnrstr(&str0[0], boundary, str1, len1);
} }
else else
{ {
/* 'boundary' acts as an start position */ /* 'boundary' acts as an start position */
ptr = rtx->gbl.ignorecase? ptr = rtx->gbl.ignorecase?
qse_strxncasestr (&str0[boundary-1], len0-boundary+1, str1, len1): qse_strxncasestr(&str0[boundary-1], len0-boundary+1, str1, len1):
qse_strxnstr (&str0[boundary-1], len0-boundary+1, str1, len1); qse_strxnstr(&str0[boundary-1], len0-boundary+1, str1, len1);
} }
idx = (ptr == QSE_NULL)? 0: ((qse_awk_int_t)(ptr-str0) + 1); idx = (ptr == QSE_NULL)? 0: ((qse_awk_int_t)(ptr-str0) + 1);
@ -486,7 +486,7 @@ static int index_or_rindex (qse_awk_rtx_t* rtx, int rindex)
qse_awk_rtx_freevalstr (rtx, a1, str1); qse_awk_rtx_freevalstr (rtx, a1, str1);
qse_awk_rtx_freevalstr (rtx, a0, str0); qse_awk_rtx_freevalstr (rtx, a0, str0);
a0 = qse_awk_rtx_makeintval (rtx, idx); a0 = qse_awk_rtx_makeintval(rtx, idx);
if (a0 == QSE_NULL) return -1; if (a0 == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, a0); qse_awk_rtx_setretval (rtx, a0);

View File

@ -37,18 +37,33 @@ static int fnc_normspace (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
* - trim leading and trailing spaces * - trim leading and trailing spaces
* - replace a series of spaces to a single space * - replace a series of spaces to a single space
*/ */
qse_cstr_t path;
qse_awk_val_t* retv; qse_awk_val_t* retv;
qse_awk_val_t* a0; qse_awk_val_t* a0;
a0 = qse_awk_rtx_getarg(rtx, 0); a0 = qse_awk_rtx_getarg(rtx, 0);
if (QSE_AWK_RTX_GETVALTYPE(rtx, a0) == QSE_AWK_VAL_MBS)
{
qse_mchar_t* str0;
qse_size_t len0;
path.ptr = qse_awk_rtx_getvalstr (rtx, a0, &path.len); str0 = qse_awk_rtx_valtombsdup(rtx, a0, &len0);
if (!path.ptr) return -1; if (!str0) return -1;
len0 = qse_mbsxpac(str0, len0);
retv = qse_awk_rtx_makembsval(rtx, str0, len0);
qse_awk_rtx_freemem (rtx, str0);
}
else
{
qse_char_t* str0;
qse_size_t len0;
str0 = qse_awk_rtx_valtostrdup(rtx, a0, &len0);
if (!str0) return -1;
len0 = qse_strxpac(str0, len0);
retv = qse_awk_rtx_makestrval(rtx, str0, len0);
qse_awk_rtx_freemem (rtx, str0);
}
path.len = qse_strxpac (path.ptr, path.len);
retv = qse_awk_rtx_makestrval (rtx, path.ptr, path.len);
qse_awk_rtx_freevalstr (rtx, a0, path.ptr);
if (!retv) return -1; if (!retv) return -1;
qse_awk_rtx_setretval (rtx, retv); qse_awk_rtx_setretval (rtx, retv);
@ -57,48 +72,90 @@ static int fnc_normspace (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
static int trim (qse_awk_rtx_t* rtx, int flags) static int trim (qse_awk_rtx_t* rtx, int flags)
{ {
qse_cstr_t path;
qse_char_t* npath;
qse_awk_val_t* retv; qse_awk_val_t* retv;
qse_awk_val_t* a0; qse_awk_val_t* a0;
a0 = qse_awk_rtx_getarg(rtx, 0); a0 = qse_awk_rtx_getarg(rtx, 0);
path.ptr = qse_awk_rtx_getvalstr (rtx, a0, &path.len); if (QSE_AWK_RTX_GETVALTYPE(rtx, a0) == QSE_AWK_VAL_MBS)
{
qse_mcstr_t path;
qse_mchar_t* npath;
path.ptr = ((qse_awk_val_mbs_t*)a0)->val.ptr;
path.len = ((qse_awk_val_mbs_t*)a0)->val.len;
npath = qse_mbsxtrmx(path.ptr, &path.len, flags);
retv = qse_awk_rtx_makembsval(rtx, npath, path.len);
}
else
{
qse_cstr_t path;
qse_char_t* npath;
path.ptr = qse_awk_rtx_getvalstr(rtx, a0, &path.len);
if (!path.ptr) return -1; if (!path.ptr) return -1;
/* because qse_strxtrmx() returns the pointer and the legnth without
npath = qse_strxtrmx (path.ptr, &path.len, flags); * affecting the string given, it's safe to pass the original value.
retv = qse_awk_rtx_makestrval (rtx, npath, path.len); * qse_awk_rtx_getvalstr() doesn't duplicate the value if it's of
* the string type. */
npath = qse_strxtrmx(path.ptr, &path.len, flags);
retv = qse_awk_rtx_makestrval(rtx, npath, path.len);
qse_awk_rtx_freevalstr (rtx, a0, path.ptr); qse_awk_rtx_freevalstr (rtx, a0, path.ptr);
}
if (!retv) return -1; if (!retv) return -1;
qse_awk_rtx_setretval (rtx, retv); qse_awk_rtx_setretval (rtx, retv);
return 0; return 0;
} }
static int fnc_trim (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_trim (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return trim (rtx, QSE_STRTRMX_LEFT | QSE_STRTRMX_RIGHT); return trim(rtx, QSE_STRTRMX_LEFT | QSE_STRTRMX_RIGHT);
} }
static int fnc_ltrim (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_ltrim (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return trim (rtx, QSE_STRTRMX_LEFT); return trim(rtx, QSE_STRTRMX_LEFT);
} }
static int fnc_rtrim (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_rtrim (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return trim (rtx, QSE_STRTRMX_RIGHT); return trim(rtx, QSE_STRTRMX_RIGHT);
} }
static int is_class (qse_awk_rtx_t* rtx, qse_ctype_t ctype) static int is_class (qse_awk_rtx_t* rtx, qse_ctype_t ctype)
{ {
qse_awk_val_t* a0; qse_awk_val_t* a0;
qse_char_t* str0;
qse_size_t len0;
int tmp; int tmp;
a0 = qse_awk_rtx_getarg (rtx, 0); a0 = qse_awk_rtx_getarg (rtx, 0);
str0 = qse_awk_rtx_getvalstr (rtx, a0, &len0); if (QSE_AWK_RTX_GETVALTYPE(rtx, a0) == QSE_AWK_VAL_MBS)
{
qse_mchar_t* str0;
qse_size_t len0;
str0 = ((qse_awk_val_mbs_t*)a0)->val.ptr;
len0 = ((qse_awk_val_mbs_t*)a0)->val.len;
if (len0 <= 0) tmp = 0;
else
{
tmp = 1;
do
{
len0--;
if (!qse_ismctype(str0[len0], ctype))
{
tmp = 0;
break;
}
}
while (len0 > 0);
}
}
else
{
qse_char_t* str0;
qse_size_t len0;
str0 = qse_awk_rtx_getvalstr(rtx, a0, &len0);
if (!str0) return -1; if (!str0) return -1;
if (len0 <= 0) tmp = 0; if (len0 <= 0) tmp = 0;
@ -115,6 +172,7 @@ static int is_class (qse_awk_rtx_t* rtx, qse_ctype_t ctype)
} }
} }
while (len0 > 0); while (len0 > 0);
}
qse_awk_rtx_freevalstr (rtx, a0, str0); qse_awk_rtx_freevalstr (rtx, a0, str0);
} }
@ -127,85 +185,116 @@ static int is_class (qse_awk_rtx_t* rtx, qse_ctype_t ctype)
static int fnc_isalnum (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_isalnum (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_ALNUM); return is_class(rtx, QSE_CTYPE_ALNUM);
} }
static int fnc_isalpha (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_isalpha (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_ALPHA); return is_class(rtx, QSE_CTYPE_ALPHA);
} }
static int fnc_isblank (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_isblank (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_BLANK); return is_class(rtx, QSE_CTYPE_BLANK);
} }
static int fnc_iscntrl (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_iscntrl (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_CNTRL); return is_class(rtx, QSE_CTYPE_CNTRL);
} }
static int fnc_isdigit (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_isdigit (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_DIGIT); return is_class(rtx, QSE_CTYPE_DIGIT);
} }
static int fnc_isgraph (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_isgraph (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_GRAPH); return is_class(rtx, QSE_CTYPE_GRAPH);
} }
static int fnc_islower (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_islower (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_LOWER); return is_class(rtx, QSE_CTYPE_LOWER);
} }
static int fnc_isprint (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_isprint (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_PRINT); return is_class(rtx, QSE_CTYPE_PRINT);
} }
static int fnc_ispunct (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_ispunct (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_PUNCT); return is_class(rtx, QSE_CTYPE_PUNCT);
} }
static int fnc_isspace (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_isspace (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_SPACE); return is_class(rtx, QSE_CTYPE_SPACE);
} }
static int fnc_isupper (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_isupper (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_UPPER); return is_class(rtx, QSE_CTYPE_UPPER);
} }
static int fnc_isxdigit (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_isxdigit (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
return is_class (rtx, QSE_CTYPE_XDIGIT); return is_class(rtx, QSE_CTYPE_XDIGIT);
} }
static int fnc_value (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_value (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
/* return the numeric value for the first character. /* return the numeric value for the first character.
* you can use sprintf("%c", num_val) for reverse conversion. */ * you can use sprintf("%c", num_val) for reverse conversion. */
qse_cstr_t path;
qse_awk_val_t* retv; qse_awk_val_t* retv;
qse_awk_val_t* a0; qse_awk_val_t* a0;
qse_awk_int_t iv = -1;
a0 = qse_awk_rtx_getarg(rtx, 0); a0 = qse_awk_rtx_getarg(rtx, 0);
path.ptr = qse_awk_rtx_getvalstr (rtx, a0, &path.len); if (QSE_AWK_RTX_GETVALTYPE(rtx, a0) == QSE_AWK_VAL_MBS)
if (path.ptr && path.len >= 1) {
qse_mchar_t* str0;
qse_size_t len0;
str0 = ((qse_awk_val_mbs_t*)a0)->val.ptr;
len0 = ((qse_awk_val_mbs_t*)a0)->val.len;
if (len0 >= 1)
{ {
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
/* typecasting in case qse_mchar_t is signed */ /* typecasting in case qse_mchar_t is signed */
retv = qse_awk_rtx_makeintval (rtx, (unsigned char)path.ptr[0]); iv = (unsigned char)str0[0];
#else #else
retv = qse_awk_rtx_makeintval (rtx, path.ptr[0]); iv = str0[0];
#endif #endif
qse_awk_rtx_freevalstr (rtx, a0, path.ptr); }
}
else
{
qse_char_t* str0;
qse_size_t len0;
str0 = qse_awk_rtx_getvalstr(rtx, a0, &len0);
if (!str0) return -1;
if (len0 >= 1)
{
#if defined(QSE_CHAR_IS_MCHAR)
/* typecasting in case qse_mchar_t is signed */
iv = (unsigned char)str0[0];
#else
iv = str0[0];
#endif
}
qse_awk_rtx_freevalstr(rtx, a0, str0);
}
if (iv >= 0)
{
retv = qse_awk_rtx_makeintval(rtx, iv);
if (!retv) return -1; if (!retv) return -1;
qse_awk_rtx_setretval (rtx, retv); qse_awk_rtx_setretval (rtx, retv);
} }
@ -215,8 +304,8 @@ static int fnc_value (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
static int fnc_tonum (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_tonum (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
/* str::tonum (value) */ /* str::tonum(value) */
/* str::tonum (string, base) */ /* str::tonum(string, base) */
qse_awk_val_t* retv; qse_awk_val_t* retv;
qse_awk_val_t* a0; qse_awk_val_t* a0;
@ -226,6 +315,22 @@ static int fnc_tonum (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
a0 = qse_awk_rtx_getarg(rtx, 0); a0 = qse_awk_rtx_getarg(rtx, 0);
if (QSE_AWK_RTX_GETVALTYPE(rtx, a0) == QSE_AWK_VAL_MBS && qse_awk_rtx_getnargs(rtx) >= 2)
{
/* if the value is known to be a byte string, it supports the optional
* base parameter */
qse_awk_val_t* a1 = qse_awk_rtx_getarg(rtx, 1);
qse_awk_int_t base;
if (qse_awk_rtx_valtoint(rtx, a1, &base) <= -1) return -1;
rx = qse_awk_rtx_mbstonum (
rtx,
QSE_AWK_RTX_STRTONUM_MAKE_OPTION(0, base),
((qse_awk_val_mbs_t*)a0)->val.ptr,
((qse_awk_val_mbs_t*)a0)->val.len,
&lv, &rv
);
}
if (QSE_AWK_RTX_GETVALTYPE(rtx, a0) == QSE_AWK_VAL_STR && qse_awk_rtx_getnargs(rtx) >= 2) if (QSE_AWK_RTX_GETVALTYPE(rtx, a0) == QSE_AWK_VAL_STR && qse_awk_rtx_getnargs(rtx) >= 2)
{ {
/* if the value is known to be a string, it supports the optional /* if the value is known to be a string, it supports the optional

View File

@ -619,7 +619,7 @@ static int fnc_strftime (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
qse_size_t len; qse_size_t len;
qse_awk_val_t* retv; qse_awk_val_t* retv;
fmt = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg (rtx, 0), &len); fmt = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 0), &len);
if (fmt) if (fmt)
{ {
qse_ntime_t nt; qse_ntime_t nt;
@ -636,7 +636,7 @@ static int fnc_strftime (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
nt.sec = tmpsec; nt.sec = tmpsec;
} }
if (qse_localtime (&nt, &bt) >= 0) if (qse_localtime(&nt, &bt) >= 0)
{ {
qse_mchar_t tmpbuf[64], * tmpptr; qse_mchar_t tmpbuf[64], * tmpptr;
struct tm tm; struct tm tm;
@ -721,7 +721,7 @@ I use 'count' to limit the maximum number of retries when 0 is returned.
} }
qse_awk_rtx_freemem (rtx, fmt); qse_awk_rtx_freemem (rtx, fmt);
retv = qse_awk_rtx_makestrvalwithmbs (rtx, tmpptr); retv = qse_awk_rtx_makestrvalwithmbs(rtx, tmpptr);
if (tmpptr && tmpptr != tmpbuf) qse_awk_rtx_freemem (rtx, tmpptr); if (tmpptr && tmpptr != tmpbuf) qse_awk_rtx_freemem (rtx, tmpptr);
if (retv == QSE_NULL) return -1; if (retv == QSE_NULL) return -1;
@ -741,7 +741,7 @@ static int fnc_getenv (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
qse_size_t len; qse_size_t len;
qse_awk_val_t* retv; qse_awk_val_t* retv;
var = qse_awk_rtx_valtombsdup ( var = qse_awk_rtx_valtombsdup(
rtx, qse_awk_rtx_getarg (rtx, 0), &len); rtx, qse_awk_rtx_getarg (rtx, 0), &len);
if (var) if (var)
{ {
@ -878,7 +878,7 @@ static int fnc_system (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* mbs; qse_mchar_t* mbs;
mbs = qse_wcstombsdup (str, QSE_NULL, qse_awk_rtx_getmmgr(rtx)); mbs = qse_wcstombsdupwithcmgr(str, QSE_NULL, qse_awk_rtx_getmmgr(rtx), qse_awk_rtx_getcmgr(rtx));
if (mbs == QSE_NULL) if (mbs == QSE_NULL)
{ {
n = -1; n = -1;
@ -1000,7 +1000,7 @@ static int fnc_openlog (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
mbs_ident = qse_mbsdup(actual_ident, qse_awk_rtx_getmmgr(rtx)); mbs_ident = qse_mbsdup(actual_ident, qse_awk_rtx_getmmgr(rtx));
#else #else
mbs_ident = qse_wcstombsdup(actual_ident, QSE_NULL, qse_awk_rtx_getmmgr(rtx)); mbs_ident = qse_wcstombsdupwithcmgr(actual_ident, QSE_NULL, qse_awk_rtx_getmmgr(rtx), qse_awk_rtx_getcmgr(rtx));
#endif #endif
if (!mbs_ident) goto done; if (!mbs_ident) goto done;
@ -1135,7 +1135,7 @@ static int fnc_writelog (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
#else #else
{ {
qse_mchar_t* mbs; qse_mchar_t* mbs;
mbs = qse_wcstombsdup(msg, QSE_NULL, qse_awk_rtx_getmmgr(rtx)); mbs = qse_wcstombsdupwithcmgr(msg, QSE_NULL, qse_awk_rtx_getmmgr(rtx), qse_awk_rtx_getcmgr(rtx));
if (!mbs) goto done; if (!mbs) goto done;
syslog(pri, "%s", mbs); syslog(pri, "%s", mbs);
qse_awk_rtx_freemem (rtx, mbs); qse_awk_rtx_freemem (rtx, mbs);

View File

@ -770,7 +770,7 @@ static int fnc_uci_load (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = load_byid (rtx, list, id, item); ret = load_byid (rtx, list, id, item);
@ -833,7 +833,7 @@ static int fnc_uci_save (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = save_byid (rtx, list, id, item); ret = save_byid (rtx, list, id, item);
@ -870,7 +870,7 @@ static int fnc_uci_commit (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = commit_byid (rtx, list, id, item); ret = commit_byid (rtx, list, id, item);
@ -907,7 +907,7 @@ static int fnc_uci_revert (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = revert_byid (rtx, list, id, item); ret = revert_byid (rtx, list, id, item);
@ -944,7 +944,7 @@ static int fnc_uci_delete (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = delete_byid (rtx, list, id, item); ret = delete_byid (rtx, list, id, item);
@ -981,7 +981,7 @@ static int fnc_uci_rename (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = rename_byid (rtx, list, id, item); ret = rename_byid (rtx, list, id, item);
@ -1018,7 +1018,7 @@ static int fnc_uci_set (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = set_byid (rtx, list, id, item); ret = set_byid (rtx, list, id, item);
@ -1055,8 +1055,8 @@ static int fnc_uci_addsection (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* item, * type; qse_mchar_t* item, * type;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
type = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 2), QSE_NULL); type = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 2), QSE_NULL);
if (item && type) if (item && type)
{ {
ret = addsection_byid (rtx, list, id, item, type); ret = addsection_byid (rtx, list, id, item, type);
@ -1095,7 +1095,7 @@ static int fnc_uci_addlist (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = addlist_byid (rtx, list, id, item); ret = addlist_byid (rtx, list, id, item);
@ -1132,7 +1132,7 @@ static int fnc_uci_setconfdir (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = setconfdir_byid (rtx, list, id, item); ret = setconfdir_byid (rtx, list, id, item);
@ -1170,7 +1170,7 @@ static int fnc_uci_setsavedir (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = setsavedir_byid (rtx, list, id, item); ret = setsavedir_byid (rtx, list, id, item);
@ -1207,7 +1207,7 @@ static int fnc_uci_adddeltapath (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t*
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = adddeltapath_byid (rtx, list, id, item); ret = adddeltapath_byid (rtx, list, id, item);
@ -1243,7 +1243,7 @@ static int fnc_uci_getoption (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg(rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = getoption_byid (rtx, list, id, item, qse_awk_rtx_getarg (rtx, 2)); ret = getoption_byid (rtx, list, id, item, qse_awk_rtx_getarg (rtx, 2));
@ -1272,16 +1272,16 @@ static int fnc_uci_getsection (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
list = rtx_to_list (rtx, fi); list = rtx_to_list (rtx, fi);
ret = qse_awk_rtx_valtoint (rtx, qse_awk_rtx_getarg (rtx, 0), &id); ret = qse_awk_rtx_valtoint(rtx, qse_awk_rtx_getarg (rtx, 0), &id);
if (ret <= -1) ret = -UCI_ERR_INVAL; if (ret <= -1) ret = -UCI_ERR_INVAL;
else else
{ {
qse_mchar_t* item; qse_mchar_t* item;
item = qse_awk_rtx_valtombsdup (rtx, qse_awk_rtx_getarg (rtx, 1), QSE_NULL); item = qse_awk_rtx_valtombsdup(rtx, qse_awk_rtx_getarg (rtx, 1), QSE_NULL);
if (item) if (item)
{ {
ret = getsection_byid (rtx, list, id, item, qse_awk_rtx_getarg (rtx, 2)); ret = getsection_byid(rtx, list, id, item, qse_awk_rtx_getarg (rtx, 2));
qse_awk_rtx_freemem (rtx, item); qse_awk_rtx_freemem (rtx, item);
if (ret == -9999) return -1; if (ret == -9999) return -1;
} }

View File

@ -54,6 +54,7 @@
#endif #endif
#define MMGR(rtx) ((rtx)->awk->mmgr) #define MMGR(rtx) ((rtx)->awk->mmgr)
#define CMGR(rtx) ((rtx)->awk->cmgr)
enum exit_level_t enum exit_level_t
{ {
@ -779,6 +780,11 @@ qse_mmgr_t* qse_awk_rtx_getmmgr (qse_awk_rtx_t* rtx)
return MMGR(rtx); return MMGR(rtx);
} }
qse_cmgr_t* qse_awk_rtx_getcmgr (qse_awk_rtx_t* rtx)
{
return CMGR(rtx);
}
qse_htb_t* qse_awk_rtx_getnvmap (qse_awk_rtx_t* rtx) qse_htb_t* qse_awk_rtx_getnvmap (qse_awk_rtx_t* rtx)
{ {
return rtx->named; return rtx->named;
@ -960,14 +966,12 @@ void qse_awk_rtx_pushecb (qse_awk_rtx_t* rtx, qse_awk_rtx_ecb_t* ecb)
static void free_namedval (qse_htb_t* map, void* dptr, qse_size_t dlen) static void free_namedval (qse_htb_t* map, void* dptr, qse_size_t dlen)
{ {
qse_awk_rtx_refdownval ( qse_awk_rtx_refdownval (*(qse_awk_rtx_t**)QSE_XTN(map), dptr);
*(qse_awk_rtx_t**)QSE_XTN(map), dptr);
} }
static void same_namedval (qse_htb_t* map, void* dptr, qse_size_t dlen) static void same_namedval (qse_htb_t* map, void* dptr, qse_size_t dlen)
{ {
qse_awk_rtx_refdownval_nofree ( qse_awk_rtx_refdownval_nofree (*(qse_awk_rtx_t**)QSE_XTN(map), dptr);
*(qse_awk_rtx_t**)QSE_XTN(map), dptr);
} }
static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio) static int init_rtx (qse_awk_rtx_t* rtx, qse_awk_t* awk, qse_awk_rio_t* rio)
@ -1328,7 +1332,6 @@ static int defaultify_globals (qse_awk_rtx_t* rtx)
qse_size_t i, j; qse_size_t i, j;
int stridx; int stridx;
stridx = (rtx->awk->opt.trait & QSE_AWK_CRLF)? 1: 0; stridx = (rtx->awk->opt.trait & QSE_AWK_CRLF)? 1: 0;
for (i = 0; i < QSE_COUNTOF(gtab); i++) for (i = 0; i < QSE_COUNTOF(gtab); i++)
{ {
@ -4514,7 +4517,7 @@ static QSE_INLINE int __cmp_str_bytearr (qse_awk_rtx_t* rtx, qse_awk_val_t* left
qse_size_t mbslen; qse_size_t mbslen;
int n; int n;
mbsptr = qse_wcsntombsdup(ls->val.ptr, ls->val.len, &mbslen, qse_awk_rtx_getmmgr(rtx)); mbsptr = qse_wcsntombsdupwithcmgr(ls->val.ptr, ls->val.len, &mbslen, MMGR(rtx), CMGR(rtx));
if (!mbsptr) if (!mbsptr)
{ {
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);

View File

@ -252,7 +252,7 @@ void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr); modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr);
#else #else
modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr); modpath = qse_wcsatombsdupwithcmgr(tmp, QSE_NULL, awk->mmgr, awk->cmgr);
#endif #endif
if (!modpath) if (!modpath)
{ {
@ -324,7 +324,7 @@ void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr); modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr);
#else #else
modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr); modpath = qse_wcsatombsdupwithcmgr(tmp, QSE_NULL, awk->mmgr, awk->cmgr);
#endif #endif
if (!modpath) if (!modpath)
{ {
@ -359,9 +359,9 @@ void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
tmp[count] = QSE_NULL; tmp[count] = QSE_NULL;
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr); modpath = qse_mbsadup(tmp, QSE_NULL, awk->mmgr);
#else #else
modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr); modpath = qse_wcsatombsdupwithcmgr(tmp, QSE_NULL, awk->mmgr, awk->cmgr);
#endif #endif
if (!modpath) if (!modpath)
{ {
@ -390,9 +390,9 @@ void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
tmp[count] = QSE_NULL; tmp[count] = QSE_NULL;
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr); modpath = qse_mbsadup(tmp, QSE_NULL, awk->mmgr);
#else #else
modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr); modpath = qse_wcsatombsdupwithcmgr(tmp, QSE_NULL, awk->mmgr, awk->cmgr);
#endif #endif
if (!modpath) if (!modpath)
{ {
@ -437,7 +437,7 @@ void* qse_awk_stdmodsym (qse_awk_t* awk, void* handle, const qse_char_t* name)
#if defined(QSE_CHAR_IS_MCHAR) #if defined(QSE_CHAR_IS_MCHAR)
mname = name; mname = name;
#else #else
mname = qse_wcstombsdup (name, QSE_NULL, awk->mmgr); mname = qse_wcstombsdupwithcmgr(name, QSE_NULL, awk->mmgr, awk->cmgr);
if (!mname) if (!mname)
{ {
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
@ -1818,8 +1818,8 @@ static int __build_environ (
/* mbstowcsdup() may fail for invalid encoding. as the environment /* mbstowcsdup() may fail for invalid encoding. as the environment
* variaables are not under control, call mbstowcsalldup() instead * variaables are not under control, call mbstowcsalldup() instead
* to go on despite encoding failure */ * to go on despite encoding failure */
kptr = qse_mbstowcsalldup (envarr[count], &klen, rtx->awk->mmgr); kptr = qse_mbstowcsalldupwithcmgr(envarr[count], &klen, rtx->awk->mmgr, rtx->awk->cmgr);
vptr = qse_mbstowcsalldup (eq + 1, QSE_NULL, rtx->awk->mmgr); vptr = qse_mbstowcsalldupwithcmgr(eq + 1, QSE_NULL, rtx->awk->mmgr, rtx->awk->cmgr);
if (kptr == QSE_NULL || vptr == QSE_NULL) if (kptr == QSE_NULL || vptr == QSE_NULL)
{ {
if (kptr) QSE_MMGR_FREE (rtx->awk->mmgr, kptr); if (kptr) QSE_MMGR_FREE (rtx->awk->mmgr, kptr);
@ -1832,13 +1832,13 @@ static int __build_environ (
*eq = QSE_MT('='); *eq = QSE_MT('=');
#else #else
eq = qse_wcschr (envarr[count], QSE_WT('=')); eq = qse_wcschr(envarr[count], QSE_WT('='));
if (eq == QSE_NULL || eq == envarr[count]) continue; if (eq == QSE_NULL || eq == envarr[count]) continue;
*eq = QSE_WT('\0'); *eq = QSE_WT('\0');
kptr = qse_wcstombsdup (envarr[count], &klen, rtx->awk->mmgr); kptr = qse_wcstombsdupwithcmgr(envarr[count], &klen, rtx->awk->mmgr, rtx->awk->cmgr);
vptr = qse_wcstombsdup (eq + 1, QSE_NULL, rtx->awk->mmgr); vptr = qse_wcstombsdupwithcmgr(eq + 1, QSE_NULL, rtx->awk->mmgr, rtx->awk->cmgr);
if (kptr == QSE_NULL || vptr == QSE_NULL) if (kptr == QSE_NULL || vptr == QSE_NULL)
{ {
if (kptr) QSE_MMGR_FREE (rtx->awk->mmgr, kptr); if (kptr) QSE_MMGR_FREE (rtx->awk->mmgr, kptr);

View File

@ -226,7 +226,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithmbs (qse_awk_rtx_t* rtx, const qse_mcha
qse_awk_val_t* v; qse_awk_val_t* v;
qse_wcstr_t tmp; qse_wcstr_t tmp;
tmp.ptr = qse_mbstowcsdup(mbs, &tmp.len, rtx->awk->mmgr); tmp.ptr = qse_mbstowcsalldupwithcmgr(mbs, &tmp.len, rtx->awk->mmgr, rtx->awk->cmgr);
if (tmp.ptr == QSE_NULL) if (tmp.ptr == QSE_NULL)
{ {
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
@ -245,7 +245,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithwcs (qse_awk_rtx_t* rtx, const qse_wcha
qse_awk_val_t* v; qse_awk_val_t* v;
qse_mcstr_t tmp; qse_mcstr_t tmp;
tmp.ptr = qse_wcstombsdup(wcs, &tmp.len, rtx->awk->mmgr); tmp.ptr = qse_wcstombsdupwithcmgr(wcs, &tmp.len, rtx->awk->mmgr, rtx->awk->cmgr);
if (tmp.ptr == QSE_NULL) if (tmp.ptr == QSE_NULL)
{ {
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
@ -275,7 +275,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithmxstr (qse_awk_rtx_t* rtx, const qse_mc
qse_size_t mbslen; qse_size_t mbslen;
mbslen = mxstr->len; mbslen = mxstr->len;
tmp.ptr = qse_mbsntowcsdup(mxstr->ptr, &mbslen, &tmp.len, rtx->awk->mmgr); tmp.ptr = qse_mbsntowcsalldupwithcmgr(mxstr->ptr, &mbslen, &tmp.len, rtx->awk->mmgr, rtx->awk->cmgr);
if (tmp.ptr == QSE_NULL) if (tmp.ptr == QSE_NULL)
{ {
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
@ -296,7 +296,7 @@ qse_awk_val_t* qse_awk_rtx_makestrvalwithwxstr (qse_awk_rtx_t* rtx, const qse_wc
qse_size_t wcslen; qse_size_t wcslen;
wcslen = wxstr->len; wcslen = wxstr->len;
tmp.ptr = qse_wcsntombsdup(wxstr->ptr, &wcslen, &tmp.len, rtx->awk->mmgr); tmp.ptr = qse_wcsntombsdupwithcmgr(wxstr->ptr, &wcslen, &tmp.len, rtx->awk->mmgr, rtx->awk->cmgr);
if (tmp.ptr == QSE_NULL) if (tmp.ptr == QSE_NULL)
{ {
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL); qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
@ -1444,9 +1444,7 @@ static int val_ref_to_str (qse_awk_rtx_t* rtx, const qse_awk_val_ref_t* ref, qse
} }
} }
int qse_awk_rtx_valtostr ( int qse_awk_rtx_valtostr (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_awk_rtx_valtostr_out_t* out)
qse_awk_rtx_t* rtx, const qse_awk_val_t* v,
qse_awk_rtx_valtostr_out_t* out)
{ {
qse_awk_val_type_t vtype = QSE_AWK_RTX_GETVALTYPE (rtx, v); qse_awk_val_type_t vtype = QSE_AWK_RTX_GETVALTYPE (rtx, v);
@ -1522,48 +1520,113 @@ qse_char_t* qse_awk_rtx_valtostrdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v,
qse_mchar_t* qse_awk_rtx_valtombsdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len) qse_mchar_t* qse_awk_rtx_valtombsdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len)
{ {
#if defined(QSE_CHAR_IS_MCHAR)
qse_awk_rtx_valtostr_out_t out;
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL;
if (len) *len = out.u.cpldup.len;
return out.u.cpldup.ptr;
#else
qse_awk_rtx_valtostr_out_t out;
qse_mchar_t* mbs; qse_mchar_t* mbs;
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP; if (QSE_AWK_RTX_GETVALTYPE(rtx,v) == QSE_AWK_VAL_MBS)
if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL; {
mbs = qse_mbsxdup(((qse_awk_val_mbs_t*)v)->val.ptr, ((qse_awk_val_mbs_t*)v)->val.len, rtx->awk->mmgr);
if (!mbs)
{
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
return QSE_NULL;
}
if (len) *len = ((qse_awk_val_mbs_t*)v)->val.len;
}
else
{
qse_char_t* str0;
qse_size_t len0, len1;
str0 = qse_awk_rtx_getvalstr(rtx, v, &len0);
if (!str0) return -1;
mbs = qse_wcsntombsdupwithcmgr(str0, len0, &len1, rtx->awk->mmgr, rtx->awk->cmgr);
qse_awk_rtx_freevalstr (rtx, v, str0);
if (!mbs)
{
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
return QSE_NULL;
}
if (len) *len = len1;
}
mbs = qse_wcsntombsdup(out.u.cpldup.ptr, out.u.cpldup.len, len, rtx->awk->mmgr);
QSE_AWK_FREE (rtx->awk, out.u.cpldup.ptr);
return mbs; return mbs;
#endif
} }
qse_wchar_t* qse_awk_rtx_valtowcsdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len) qse_wchar_t* qse_awk_rtx_valtowcsdup (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len)
{ {
#if defined(QSE_CHAR_IS_MCHAR)
qse_awk_rtx_valtostr_out_t out;
qse_wchar_t* wcs; qse_wchar_t* wcs;
qse_awk_val_type_t vtype;
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP; vtype = QSE_AWK_RTX_GETVALTYPE(rtx,v);
if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL;
wcs = qse_mbsntowcsdup(out.u.cpldup.ptr, out.u.cpldup.len, len, rtx->awk->mmgr); switch (vtype)
QSE_AWK_FREE (rtx->awk, out.u.cpldup.ptr); {
case QSE_AWK_VAL_MBS:
{
qse_size_t wcslen;
wcs = qse_mbsntowcsalldupwithcmgr(((qse_awk_val_mbs_t*)v)->val.ptr, ((qse_awk_val_mbs_t*)v)->val.len, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr);
if (!wcs)
{
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
return QSE_NULL;
}
if (len) *len = wcslen;
break;
}
case QSE_AWK_VAL_STR:
{
#if defined(QSE_CHAR_IS_MCHAR)
qse_size_t wcslen;
wcs = qse_mbsntowcsalldupwithcmgr(((qse_awk_val_str_t*)v)->val.ptr, ((qse_awk_val_str_t*)v)->val.len, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr);
#else
wcs = qse_strxdup(((qse_awk_val_str_t*)v)->val.ptr, ((qse_awk_val_str_t*)v)->val.len, rtx->awk->mmgr);
#endif
if (!wcs)
{
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
return QSE_NULL;
}
#if defined(QSE_CHAR_IS_MCHAR)
if (len) *len = wcslen;
#else
if (len) *len = ((qse_awk_val_str_t*)v)->val.len;
#endif
break;
}
default:
{
#if defined(QSE_CHAR_IS_MCHAR)
qse_size_t duplen, wcslen;
qse_char_t* dup;
dup = qse_awk_rtx_valtostrdup(rtx, v, &duplen);
if (!dup) return QSE_NULL;
wcs = qse_mbsntowcsalldupwithcmgr(dup, duplen, &wcslen, rtx->awk->mmgr, rtx->awk->cmgr);
qse_awk_rtx_freemem (rtx, dup);
if (!wcs)
{
qse_awk_rtx_seterror (rtx, QSE_AWK_ENOMEM, QSE_NULL, QSE_NULL);
return QSE_NULL;
}
if (len) *len = wcslen;
#else
qse_size_t wcslen;
wcs = qse_awk_rtx_valtostrdup(rtx, v, &wcslen);
if (!wcs) return QSE_NULL;
if (len) *len = wcslen;
#endif
break;
}
}
return wcs; return wcs;
#else
qse_awk_rtx_valtostr_out_t out;
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
if (qse_awk_rtx_valtostr (rtx, v, &out) <= -1) return QSE_NULL;
if (len) *len = out.u.cpldup.len;
return out.u.cpldup.ptr;
#endif
} }
qse_char_t* qse_awk_rtx_getvalstr (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len) qse_char_t* qse_awk_rtx_getvalstr (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len)

View File

@ -10,6 +10,14 @@ bin_PROGRAMS = awk01 awk02 awk03 awk04 awk05 awk06 awk07 awk08 awk09 awk10 awk11
AM_LDFLAGS = -L../../lib/awk -L../../lib/cmn AM_LDFLAGS = -L../../lib/awk -L../../lib/cmn
LDADD = -lqseawk -lqsecmn $(LIBM) LDADD = -lqseawk -lqsecmn $(LIBM)
if WIN32
# you must adjust the value of DEFAULT_MODPOSTFIX according to
# -version-info in ../../lib/awk/Makefile.am
AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\"
else
AM_CPPFLAGS += -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\"
endif
if WIN32 if WIN32
if WCHAR if WCHAR
LDADD += $(UNICOWS_LIBS) LDADD += $(UNICOWS_LIBS)

View File

@ -92,8 +92,13 @@ bin_PROGRAMS = awk01$(EXEEXT) awk02$(EXEEXT) awk03$(EXEEXT) \
awk04$(EXEEXT) awk05$(EXEEXT) awk06$(EXEEXT) awk07$(EXEEXT) \ awk04$(EXEEXT) awk05$(EXEEXT) awk06$(EXEEXT) awk07$(EXEEXT) \
awk08$(EXEEXT) awk09$(EXEEXT) awk10$(EXEEXT) awk11$(EXEEXT) \ awk08$(EXEEXT) awk09$(EXEEXT) awk10$(EXEEXT) awk11$(EXEEXT) \
awk12$(EXEEXT) awk15$(EXEEXT) $(am__EXEEXT_1) awk12$(EXEEXT) awk15$(EXEEXT) $(am__EXEEXT_1)
@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
@ENABLE_CXX_TRUE@am__append_2 = awk21 awk22 awk23 awk24 awk25 awk26 awk27 awk28 # you must adjust the value of DEFAULT_MODPOSTFIX according to
# -version-info in ../../lib/awk/Makefile.am
@WIN32_TRUE@am__append_1 = -DDEFAULT_MODPREFIX=\"libqseawk-\" -DDEFAULT_MODPOSTFIX=\"-1\"
@WIN32_FALSE@am__append_2 = -DDEFAULT_MODPREFIX=\"$(libdir)/libqseawk-\" -DDEFAULT_MODPOSTFIX=\"\"
@WCHAR_TRUE@@WIN32_TRUE@am__append_3 = $(UNICOWS_LIBS)
@ENABLE_CXX_TRUE@am__append_4 = awk21 awk22 awk23 awk24 awk25 awk26 awk27 awk28
subdir = samples/awk subdir = samples/awk
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
@ -466,6 +471,7 @@ pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@ psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@ srcdir = @srcdir@
@ -475,13 +481,10 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = nostdinc AUTOMAKE_OPTIONS = nostdinc
AM_CPPFLAGS = \ AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include \
-I$(top_builddir)/include \ -I$(includedir) $(am__append_1) $(am__append_2)
-I$(top_srcdir)/include \
-I$(includedir)
AM_LDFLAGS = -L../../lib/awk -L../../lib/cmn AM_LDFLAGS = -L../../lib/awk -L../../lib/cmn
LDADD = -lqseawk -lqsecmn $(LIBM) $(am__append_1) LDADD = -lqseawk -lqsecmn $(LIBM) $(am__append_3)
CMNFILES = awk00.c awk00.h CMNFILES = awk00.c awk00.h
awk01_SOURCES = awk01.c awk01_SOURCES = awk01.c
awk02_SOURCES = awk02.c $(CMNFILES) awk02_SOURCES = awk02.c $(CMNFILES)

View File

@ -121,6 +121,21 @@ protected:
} }
return size; return size;
} }
StdAwk::ssize_t writeBytes (StdAwk::Console& io, const qse_mchar_t* data, size_t size)
{
/*
try { this->output.append (data, size); }
catch (...)
{
((StdAwk::Run*)io)->setError (QSE_AWK_ENOMEM);
return -1;
}
return size;
*/
((StdAwk::Run*)io)->setError (QSE_AWK_ENOIMPL);
return -1;
}
}; };
static void print_error ( static void print_error (