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:
parent
03301b79bf
commit
7811171dff
@ -959,6 +959,8 @@ public:
|
||||
/// called close() for finalization before the destructor is executed.
|
||||
virtual ~Awk () {}
|
||||
|
||||
qse_cmgr_t* getCmgr () const;
|
||||
|
||||
///
|
||||
/// The open() function initializes an interpreter.
|
||||
/// You must call this function before doing anything meaningful.
|
||||
|
@ -2231,6 +2231,11 @@ QSE_EXPORT qse_mmgr_t* qse_awk_rtx_getmmgr (
|
||||
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
|
||||
* created with qse_awk_rtx_open().
|
||||
|
@ -1228,6 +1228,12 @@ void Awk::close ()
|
||||
this->clearError ();
|
||||
}
|
||||
|
||||
qse_cmgr_t* Awk::getCmgr () const
|
||||
{
|
||||
if (!this->awk) return QSE_NULL;
|
||||
return this->awk->cmgr;
|
||||
}
|
||||
|
||||
void Awk::uponClosing ()
|
||||
{
|
||||
// nothing to do
|
||||
|
@ -45,6 +45,17 @@
|
||||
# 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)
|
||||
/////////////////////////////////
|
||||
@ -117,6 +128,10 @@ int StdAwk::open ()
|
||||
|
||||
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;
|
||||
this->stdmod_up = true;
|
||||
}
|
||||
@ -233,6 +248,7 @@ int StdAwk::__build_environ (Run* run, void* envptr)
|
||||
qse_char_t* kptr, * vptr;
|
||||
qse_size_t klen, count;
|
||||
qse_mmgr_t* mmgr = ((Awk*)*run)->getMmgr();
|
||||
qse_cmgr_t* cmgr = ((Awk*)*run)->getCmgr();
|
||||
|
||||
for (count = 0; envarr[count]; count++)
|
||||
{
|
||||
@ -250,8 +266,8 @@ int StdAwk::__build_environ (Run* run, void* envptr)
|
||||
|
||||
*eq = QSE_MT('\0');
|
||||
|
||||
kptr = qse_mbstowcsdup (envarr[count], &klen, mmgr);
|
||||
vptr = qse_mbstowcsdup (eq + 1, QSE_NULL, mmgr);
|
||||
kptr = qse_mbstowcsalldupwithcmgr(envarr[count], &klen, mmgr, cmgr);
|
||||
vptr = qse_mbstowcsalldupwithcmgr(eq + 1, QSE_NULL, mmgr, cmgr);
|
||||
if (kptr == QSE_NULL || vptr == QSE_NULL)
|
||||
{
|
||||
if (kptr) QSE_MMGR_FREE (mmgr, kptr);
|
||||
@ -271,8 +287,8 @@ int StdAwk::__build_environ (Run* run, void* envptr)
|
||||
|
||||
*eq = QSE_WT('\0');
|
||||
|
||||
kptr = qse_wcstombsdup (envarr[count], &klen, mmgr);
|
||||
vptr = qse_wcstombsdup (eq + 1, QSE_NULL, mmgr);
|
||||
kptr = qse_wcstombsdupwithcmgr(envarr[count], &klen, mmgr, cmgr);
|
||||
vptr = qse_wcstombsdupwithcmgr(eq + 1, QSE_NULL, mmgr, cmgr);
|
||||
if (kptr == QSE_NULL || vptr == QSE_NULL)
|
||||
{
|
||||
if (kptr) QSE_MMGR_FREE (mmgr, kptr);
|
||||
|
@ -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
|
||||
* - replace a series of spaces to a single space
|
||||
*/
|
||||
qse_cstr_t path;
|
||||
qse_awk_val_t* retv;
|
||||
qse_awk_val_t* a0;
|
||||
|
||||
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);
|
||||
if (!path.ptr) return -1;
|
||||
str0 = qse_awk_rtx_valtombsdup(rtx, a0, &len0);
|
||||
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;
|
||||
qse_awk_rtx_setretval (rtx, retv);
|
||||
|
||||
@ -57,22 +72,37 @@ 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)
|
||||
{
|
||||
qse_cstr_t path;
|
||||
qse_char_t* npath;
|
||||
qse_awk_val_t* retv;
|
||||
qse_awk_val_t* a0;
|
||||
|
||||
a0 = qse_awk_rtx_getarg(rtx, 0);
|
||||
|
||||
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;
|
||||
|
||||
/* because qse_strxtrmx() returns the pointer and the legnth without
|
||||
* affecting the string given, it's safe to pass the original value.
|
||||
* 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);
|
||||
}
|
||||
|
||||
if (!retv) return -1;
|
||||
qse_awk_rtx_setretval (rtx, retv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -92,12 +122,39 @@ static int fnc_rtrim (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
static int is_class (qse_awk_rtx_t* rtx, qse_ctype_t ctype)
|
||||
{
|
||||
qse_awk_val_t* a0;
|
||||
qse_char_t* str0;
|
||||
qse_size_t len0;
|
||||
int tmp;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
@ -115,6 +172,7 @@ static int is_class (qse_awk_rtx_t* rtx, qse_ctype_t ctype)
|
||||
}
|
||||
}
|
||||
while (len0 > 0);
|
||||
}
|
||||
qse_awk_rtx_freevalstr (rtx, a0, str0);
|
||||
}
|
||||
|
||||
@ -189,23 +247,54 @@ static int fnc_value (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
{
|
||||
/* return the numeric value for the first character.
|
||||
* you can use sprintf("%c", num_val) for reverse conversion. */
|
||||
|
||||
qse_cstr_t path;
|
||||
qse_awk_val_t* retv;
|
||||
qse_awk_val_t* a0;
|
||||
qse_awk_int_t iv = -1;
|
||||
|
||||
a0 = qse_awk_rtx_getarg(rtx, 0);
|
||||
|
||||
path.ptr = qse_awk_rtx_getvalstr (rtx, a0, &path.len);
|
||||
if (path.ptr && path.len >= 1)
|
||||
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 >= 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]);
|
||||
iv = (unsigned char)str0[0];
|
||||
#else
|
||||
retv = qse_awk_rtx_makeintval (rtx, path.ptr[0]);
|
||||
iv = str0[0];
|
||||
#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;
|
||||
qse_awk_rtx_setretval (rtx, retv);
|
||||
}
|
||||
@ -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);
|
||||
|
||||
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 the value is known to be a string, it supports the optional
|
||||
|
@ -878,7 +878,7 @@ static int fnc_system (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
mbs_ident = qse_mbsdup(actual_ident, qse_awk_rtx_getmmgr(rtx));
|
||||
#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
|
||||
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
|
||||
{
|
||||
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;
|
||||
syslog(pri, "%s", mbs);
|
||||
qse_awk_rtx_freemem (rtx, mbs);
|
||||
|
@ -54,6 +54,7 @@
|
||||
#endif
|
||||
|
||||
#define MMGR(rtx) ((rtx)->awk->mmgr)
|
||||
#define CMGR(rtx) ((rtx)->awk->cmgr)
|
||||
|
||||
enum exit_level_t
|
||||
{
|
||||
@ -779,6 +780,11 @@ qse_mmgr_t* qse_awk_rtx_getmmgr (qse_awk_rtx_t* 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
qse_awk_rtx_refdownval (
|
||||
*(qse_awk_rtx_t**)QSE_XTN(map), dptr);
|
||||
qse_awk_rtx_refdownval (*(qse_awk_rtx_t**)QSE_XTN(map), dptr);
|
||||
}
|
||||
|
||||
static void same_namedval (qse_htb_t* map, void* dptr, qse_size_t dlen)
|
||||
{
|
||||
qse_awk_rtx_refdownval_nofree (
|
||||
*(qse_awk_rtx_t**)QSE_XTN(map), dptr);
|
||||
qse_awk_rtx_refdownval_nofree (*(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)
|
||||
@ -1328,7 +1332,6 @@ static int defaultify_globals (qse_awk_rtx_t* rtx)
|
||||
qse_size_t i, j;
|
||||
int stridx;
|
||||
|
||||
|
||||
stridx = (rtx->awk->opt.trait & QSE_AWK_CRLF)? 1: 0;
|
||||
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;
|
||||
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)
|
||||
{
|
||||
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
|
@ -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)
|
||||
modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr);
|
||||
#else
|
||||
modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr);
|
||||
modpath = qse_wcsatombsdupwithcmgr(tmp, QSE_NULL, awk->mmgr, awk->cmgr);
|
||||
#endif
|
||||
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)
|
||||
modpath = qse_mbsadup (tmp, QSE_NULL, awk->mmgr);
|
||||
#else
|
||||
modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr);
|
||||
modpath = qse_wcsatombsdupwithcmgr(tmp, QSE_NULL, awk->mmgr, awk->cmgr);
|
||||
#endif
|
||||
if (!modpath)
|
||||
{
|
||||
@ -361,7 +361,7 @@ void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
modpath = qse_mbsadup(tmp, QSE_NULL, awk->mmgr);
|
||||
#else
|
||||
modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr);
|
||||
modpath = qse_wcsatombsdupwithcmgr(tmp, QSE_NULL, awk->mmgr, awk->cmgr);
|
||||
#endif
|
||||
if (!modpath)
|
||||
{
|
||||
@ -392,7 +392,7 @@ void* qse_awk_stdmodopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
modpath = qse_mbsadup(tmp, QSE_NULL, awk->mmgr);
|
||||
#else
|
||||
modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr);
|
||||
modpath = qse_wcsatombsdupwithcmgr(tmp, QSE_NULL, awk->mmgr, awk->cmgr);
|
||||
#endif
|
||||
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)
|
||||
mname = name;
|
||||
#else
|
||||
mname = qse_wcstombsdup (name, QSE_NULL, awk->mmgr);
|
||||
mname = qse_wcstombsdupwithcmgr(name, QSE_NULL, awk->mmgr, awk->cmgr);
|
||||
if (!mname)
|
||||
{
|
||||
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
|
||||
* variaables are not under control, call mbstowcsalldup() instead
|
||||
* to go on despite encoding failure */
|
||||
kptr = qse_mbstowcsalldup (envarr[count], &klen, rtx->awk->mmgr);
|
||||
vptr = qse_mbstowcsalldup (eq + 1, QSE_NULL, rtx->awk->mmgr);
|
||||
kptr = qse_mbstowcsalldupwithcmgr(envarr[count], &klen, rtx->awk->mmgr, rtx->awk->cmgr);
|
||||
vptr = qse_mbstowcsalldupwithcmgr(eq + 1, QSE_NULL, rtx->awk->mmgr, rtx->awk->cmgr);
|
||||
if (kptr == QSE_NULL || vptr == QSE_NULL)
|
||||
{
|
||||
if (kptr) QSE_MMGR_FREE (rtx->awk->mmgr, kptr);
|
||||
@ -1837,8 +1837,8 @@ static int __build_environ (
|
||||
|
||||
*eq = QSE_WT('\0');
|
||||
|
||||
kptr = qse_wcstombsdup (envarr[count], &klen, rtx->awk->mmgr);
|
||||
vptr = qse_wcstombsdup (eq + 1, QSE_NULL, rtx->awk->mmgr);
|
||||
kptr = qse_wcstombsdupwithcmgr(envarr[count], &klen, rtx->awk->mmgr, rtx->awk->cmgr);
|
||||
vptr = qse_wcstombsdupwithcmgr(eq + 1, QSE_NULL, rtx->awk->mmgr, rtx->awk->cmgr);
|
||||
if (kptr == QSE_NULL || vptr == QSE_NULL)
|
||||
{
|
||||
if (kptr) QSE_MMGR_FREE (rtx->awk->mmgr, kptr);
|
||||
|
@ -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_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)
|
||||
{
|
||||
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_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)
|
||||
{
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
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 (
|
||||
qse_awk_rtx_t* rtx, const qse_awk_val_t* v,
|
||||
qse_awk_rtx_valtostr_out_t* out)
|
||||
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_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)
|
||||
{
|
||||
#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;
|
||||
|
||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
||||
if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL;
|
||||
if (QSE_AWK_RTX_GETVALTYPE(rtx,v) == QSE_AWK_VAL_MBS)
|
||||
{
|
||||
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;
|
||||
#endif
|
||||
}
|
||||
|
||||
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_awk_val_type_t vtype;
|
||||
|
||||
out.type = QSE_AWK_RTX_VALTOSTR_CPLDUP;
|
||||
if (qse_awk_rtx_valtostr(rtx, v, &out) <= -1) return QSE_NULL;
|
||||
vtype = QSE_AWK_RTX_GETVALTYPE(rtx,v);
|
||||
|
||||
wcs = qse_mbsntowcsdup(out.u.cpldup.ptr, out.u.cpldup.len, len, rtx->awk->mmgr);
|
||||
QSE_AWK_FREE (rtx->awk, out.u.cpldup.ptr);
|
||||
return wcs;
|
||||
switch (vtype)
|
||||
{
|
||||
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
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
qse_char_t* qse_awk_rtx_getvalstr (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_size_t* len)
|
||||
|
@ -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
|
||||
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 WCHAR
|
||||
LDADD += $(UNICOWS_LIBS)
|
||||
|
@ -92,8 +92,13 @@ bin_PROGRAMS = awk01$(EXEEXT) awk02$(EXEEXT) awk03$(EXEEXT) \
|
||||
awk04$(EXEEXT) awk05$(EXEEXT) awk06$(EXEEXT) awk07$(EXEEXT) \
|
||||
awk08$(EXEEXT) awk09$(EXEEXT) awk10$(EXEEXT) awk11$(EXEEXT) \
|
||||
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
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
|
||||
@ -466,6 +471,7 @@ pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
runstatedir = @runstatedir@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
@ -475,13 +481,10 @@ top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
AUTOMAKE_OPTIONS = nostdinc
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(includedir)
|
||||
|
||||
AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include \
|
||||
-I$(includedir) $(am__append_1) $(am__append_2)
|
||||
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
|
||||
awk01_SOURCES = awk01.c
|
||||
awk02_SOURCES = awk02.c $(CMNFILES)
|
||||
|
@ -121,6 +121,21 @@ protected:
|
||||
}
|
||||
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 (
|
||||
|
Loading…
Reference in New Issue
Block a user