added qse_fmtintmaxtombs()/qse_fmtintmaxtowcs() and related functions.
changed qse_awk_t to use these new formatting functions. redefined some primitive types
This commit is contained in:
@ -1108,25 +1108,6 @@ void qse_awk_rtx_freemem (qse_awk_rtx_t* rtx, void* ptr)
|
||||
qse_awk_freemem (rtx->awk, ptr);
|
||||
}
|
||||
|
||||
int qse_awk_sprintlong (
|
||||
qse_awk_t* awk, qse_char_t* buf, qse_size_t len, qse_long_t num)
|
||||
{
|
||||
return awk->prm.sprintf (
|
||||
awk, buf, len,
|
||||
#if QSE_SIZEOF_LONG_LONG > 0
|
||||
QSE_T("%lld"), (long long)num
|
||||
#elif QSE_SIZEOF___INT64 > 0
|
||||
QSE_T("%I64d"), (__int64)num
|
||||
#elif QSE_SIZEOF_LONG > 0
|
||||
QSE_T("%ld"), (long)num
|
||||
#elif QSE_SIZEOF_INT > 0
|
||||
QSE_T("%d"), (int)num
|
||||
#else
|
||||
#error unsupported size
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
int qse_awk_sprintreal (
|
||||
qse_awk_t* awk, qse_char_t* buf, qse_size_t len, qse_real_t num)
|
||||
{
|
||||
|
@ -76,14 +76,6 @@ int qse_awk_matchrex (
|
||||
qse_cstr_t* match, qse_awk_errnum_t* errnum
|
||||
);
|
||||
|
||||
int qse_awk_sprintlong (
|
||||
qse_awk_t* awk,
|
||||
qse_char_t* buf,
|
||||
qse_size_t len,
|
||||
qse_long_t num
|
||||
);
|
||||
|
||||
|
||||
int qse_awk_sprintreal (
|
||||
qse_awk_t* awk,
|
||||
qse_char_t* buf,
|
||||
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "awk.h"
|
||||
#include <qse/cmn/fmt.h>
|
||||
|
||||
#ifdef DEBUG_RUN
|
||||
#include <qse/cmn/stdio.h>
|
||||
@ -6777,14 +6778,19 @@ qse_char_t* qse_awk_rtx_format (
|
||||
|
||||
do
|
||||
{
|
||||
n = qse_awk_sprintlong (
|
||||
rtx->awk,
|
||||
n = qse_fmtintmax (
|
||||
rtx->format.tmp.ptr,
|
||||
rtx->format.tmp.len,
|
||||
width
|
||||
);
|
||||
if (n == -1)
|
||||
width,
|
||||
10 | QSE_FMTINTMAX_NOTRUNC,
|
||||
QSE_T('\0')
|
||||
);
|
||||
if (n <= -1)
|
||||
{
|
||||
/* TODO: utilize n in GROW.
|
||||
* since -n is the number of characters required
|
||||
* including terminating null, it can be used there
|
||||
* this doesn't have to be in the loop any more */
|
||||
GROW (&rtx->format.tmp);
|
||||
if (rtx->format.tmp.ptr == QSE_NULL)
|
||||
{
|
||||
@ -6799,6 +6805,8 @@ qse_char_t* qse_awk_rtx_format (
|
||||
}
|
||||
while (1);
|
||||
|
||||
/* TODO: we know that n is the length.
|
||||
* the contents can be added without scanning the whole string again */
|
||||
p = rtx->format.tmp.ptr;
|
||||
while (*p != QSE_T('\0'))
|
||||
{
|
||||
@ -6870,14 +6878,19 @@ qse_char_t* qse_awk_rtx_format (
|
||||
|
||||
do
|
||||
{
|
||||
n = qse_awk_sprintlong (
|
||||
rtx->awk,
|
||||
n = qse_fmtintmax (
|
||||
rtx->format.tmp.ptr,
|
||||
rtx->format.tmp.len,
|
||||
prec
|
||||
);
|
||||
if (n == -1)
|
||||
prec,
|
||||
10 | QSE_FMTINTMAX_NOTRUNC,
|
||||
QSE_T('\0')
|
||||
);
|
||||
if (n <= -1)
|
||||
{
|
||||
/* TODO: utilize n in GROW.
|
||||
* since -n is the number of characters required
|
||||
* including terminating null, it can be used there.
|
||||
* this doesn't have to be in the loop any more */
|
||||
GROW (&rtx->format.tmp);
|
||||
if (rtx->format.tmp.ptr == QSE_NULL)
|
||||
{
|
||||
@ -6891,6 +6904,8 @@ qse_char_t* qse_awk_rtx_format (
|
||||
}
|
||||
while (1);
|
||||
|
||||
/* TODO: we know that n is the length.
|
||||
* the contents can be added without scanning the whole string again */
|
||||
p = rtx->format.tmp.ptr;
|
||||
while (*p != QSE_T('\0'))
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "awk.h"
|
||||
#include <qse/cmn/fmt.h>
|
||||
|
||||
static const qse_char_t* assop_str[] =
|
||||
{
|
||||
@ -268,10 +269,24 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_char_t buf[64];
|
||||
qse_awk_sprintlong (
|
||||
awk, buf, QSE_COUNTOF(buf),
|
||||
((qse_awk_nde_int_t*)nde)->val);
|
||||
/* Note that the array sizing fomula is not accurate
|
||||
* but should be good enoug consiering the followings.
|
||||
*
|
||||
* size minval digits sign
|
||||
* 1 -128 3 1
|
||||
* 2 -32768 5 1
|
||||
* 4 -2147483648 10 1
|
||||
* 8 -9223372036854775808 19 1
|
||||
* 16 -170141183460469231731687303715884105728 39 1
|
||||
*/
|
||||
qse_char_t buf[QSE_SIZEOF(qse_long_t) * 3 + 2];
|
||||
|
||||
qse_fmtintmax (
|
||||
buf, QSE_COUNTOF(buf),
|
||||
((qse_awk_nde_int_t*)nde)->val,
|
||||
10,
|
||||
QSE_T('\0')
|
||||
);
|
||||
PUT_SRCSTR (awk, buf);
|
||||
}
|
||||
break;
|
||||
|
Reference in New Issue
Block a user