Added qse_awk_rtx_formatmbs().

enhanced the builtin printf to handle the byte array format
This commit is contained in:
hyung-hwan 2019-04-21 15:54:49 +00:00
parent eed3853765
commit 146cc6436b
5 changed files with 1083 additions and 167 deletions

View File

@ -683,24 +683,29 @@ typedef int qse_mcint_t;
* #QSE_CHAR_EOF.
*/
#if defined(QSE_CHAR_IS_MCHAR)
# define QSE_SIZEOF_CHAR_T QSE_SIZEOF_MCHAR_T
typedef qse_mchar_t qse_char_t;
typedef qse_mchau_t qse_chau_t;
typedef qse_mcint_t qse_cint_t;
#elif defined(QSE_CHAR_IS_WCHAR)
# define QSE_SIZEOF_CHAR_T QSE_SIZEOF_WCHAR_T
typedef qse_wchar_t qse_char_t;
typedef qse_wchau_t qse_chau_t;
typedef qse_wcint_t qse_cint_t;
#else
/* If the character type is not determined in the conf_xxx files */
# if defined(_WIN32)
# if defined(UNICODE) || defined(_UNICODE)
# define QSE_CHAR_IS_WCHAR
# define QSE_SIZEOF_CHAR_T QSE_SIZEOF_WCHAR_T
typedef qse_wchar_t qse_char_t;
typedef qse_wchau_t qse_chau_t;
typedef qse_wcint_t qse_cint_t;
# else
# define QSE_CHAR_IS_MCHAR
# define QSE_SIZEOF_CHAR_T QSE_SIZEOF_MCHAR_T
typedef qse_mchar_t qse_char_t;
typedef qse_mchau_t qse_chau_t;
typedef qse_mcint_t qse_cint_t;

View File

@ -379,6 +379,19 @@ struct qse_awk_rtx_t
} tmp;
} format;
struct
{
qse_mbs_t fmt;
qse_mbs_t out;
struct
{
qse_mchar_t* ptr;
qse_size_t len; /* length */
qse_size_t inc; /* increment */
} tmp;
} formatmbs;
struct
{
qse_size_t block;

View File

@ -524,18 +524,23 @@ int qse_awk_fnc_length (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
v = qse_awk_rtx_getarg (rtx, 0);
vtype = QSE_AWK_RTX_GETVALTYPE (rtx, v);
if (vtype == QSE_AWK_VAL_MAP)
switch (vtype)
{
case QSE_AWK_VAL_MAP:
/* map size */
len = QSE_HTB_SIZE(((qse_awk_val_map_t*)v)->map);
}
else if (vtype == QSE_AWK_VAL_STR)
{
break;
case QSE_AWK_VAL_STR:
/* string length */
len = ((qse_awk_val_str_t*)v)->val.len;
}
else
{
break;
case QSE_AWK_VAL_MBS:
len = ((qse_awk_val_mbs_t*)v)->val.len;
break;
default:
/* convert to string and get length */
str = qse_awk_rtx_valtostrdup (rtx, v, &len);
if (str == QSE_NULL) return -1;
@ -781,12 +786,10 @@ int qse_awk_fnc_split (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
if (t2 == QSE_NULL) goto oops;
/* put it into the map */
key_len = qse_awk_inttostr (
rtx->awk, ++nflds, 10, QSE_NULL, key_buf, QSE_COUNTOF(key_buf));
key_len = qse_awk_inttostr (rtx->awk, ++nflds, 10, QSE_NULL, key_buf, QSE_COUNTOF(key_buf));
QSE_ASSERT (key_len != (qse_size_t)-1);
if (qse_awk_rtx_setmapvalfld (
rtx, t1, key_buf, key_len, t2) == QSE_NULL)
if (qse_awk_rtx_setmapvalfld(rtx, t1, key_buf, key_len, t2) == QSE_NULL)
{
qse_awk_rtx_refupval (rtx, t2);
qse_awk_rtx_refdownval (rtx, t2);
@ -1028,17 +1031,14 @@ static int __substitute (qse_awk_rtx_t* rtx, qse_awk_int_t max_count)
break;
}
if (mat.len == 0 &&
pmat.ptr != QSE_NULL &&
mat.ptr == pmat.ptr + pmat.len)
if (mat.len == 0 && pmat.ptr != QSE_NULL && mat.ptr == pmat.ptr + pmat.len)
{
/* match length is 0 and the match is still at the
* end of the previous match */
goto skip_one_char;
}
if (qse_str_ncat (
&new, cur.ptr, mat.ptr - cur.ptr) == (qse_size_t)-1)
if (qse_str_ncat(&new, cur.ptr, mat.ptr - cur.ptr) == (qse_size_t)-1)
{
qse_awk_rtx_seterrnum (rtx, QSE_AWK_ENOMEM, QSE_NULL);
goto oops;
@ -1046,9 +1046,7 @@ static int __substitute (qse_awk_rtx_t* rtx, qse_awk_int_t max_count)
for (i = 0; i < s1.len; i++)
{
if ((i+1) < s1.len &&
s1.ptr[i] == QSE_T('\\') &&
s1.ptr[i+1] == QSE_T('&'))
if ((i+1) < s1.len && s1.ptr[i] == QSE_T('\\') && s1.ptr[i+1] == QSE_T('&'))
{
m = qse_str_ccat (&new, QSE_T('&'));
i++;
@ -1221,8 +1219,7 @@ int qse_awk_fnc_match (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
qse_awk_rtx_refupval (rtx, x0);
/* RLENGTH: -1 on no match */
x1 = qse_awk_rtx_makeintval (rtx,
((n == 0)? (qse_awk_int_t)-1: (qse_awk_int_t)mat.len));
x1 = qse_awk_rtx_makeintval(rtx, ((n == 0)? (qse_awk_int_t)-1: (qse_awk_int_t)mat.len));
if (!x1) goto oops;
qse_awk_rtx_refupval (rtx, x1);

File diff suppressed because it is too large Load Diff

View File

@ -123,6 +123,17 @@ qse_char_t* qse_awk_rtx_format (
qse_size_t* len
);
qse_mchar_t* qse_awk_rtx_formatmbs (
qse_awk_rtx_t* run,
qse_mbs_t* out,
qse_mbs_t* fbu,
const qse_mchar_t* fmt,
qse_size_t fmt_len,
qse_size_t nargs_on_stack,
qse_awk_nde_t* args,
qse_size_t* len
);
#if defined(__cplusplus)
}
#endif