added some floating point number formatting code
This commit is contained in:
parent
597864a4ba
commit
3ced20346c
20
moo/configure
vendored
20
moo/configure
vendored
@ -831,6 +831,7 @@ enable_experimental
|
|||||||
enable_debug
|
enable_debug
|
||||||
enable_unicode
|
enable_unicode
|
||||||
enable_full_liw
|
enable_full_liw
|
||||||
|
enable_fltmax
|
||||||
enable_cxx
|
enable_cxx
|
||||||
enable_dynamic_module
|
enable_dynamic_module
|
||||||
enable_static_module
|
enable_static_module
|
||||||
@ -1492,6 +1493,8 @@ Optional Features:
|
|||||||
no:4 (default. yes)
|
no:4 (default. yes)
|
||||||
--enable-full-liw Use a full word as a large integer word (default.
|
--enable-full-liw Use a full word as a large integer word (default.
|
||||||
no)
|
no)
|
||||||
|
--enable-awk-fltmax use hawk_fltmax_t for floating-point numbers
|
||||||
|
(default. no)
|
||||||
--enable-cxx build the library for C++ if a C++ compiler is
|
--enable-cxx build the library for C++ if a C++ compiler is
|
||||||
available (default. yes)
|
available (default. yes)
|
||||||
--enable-dynamic-module enable dynamic module capability(default. yes)
|
--enable-dynamic-module enable dynamic module capability(default. yes)
|
||||||
@ -18505,7 +18508,7 @@ fi
|
|||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
for ac_header in ffi.h dyncall.h libunwind.h
|
for ac_header in ffi.h dyncall.h libunwind.h quadmath.h
|
||||||
do :
|
do :
|
||||||
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
||||||
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
|
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
|
||||||
@ -21793,6 +21796,21 @@ $as_echo "#define MOO_ENABLE_FULL_LIW 1" >>confdefs.h
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check whether --enable-fltmax was given.
|
||||||
|
if test "${enable_fltmax+set}" = set; then :
|
||||||
|
enableval=$enable_fltmax; enable_fltmax_is=$enableval
|
||||||
|
else
|
||||||
|
enable_fltmax_is=no
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "${enable_fltmax_is}" = "yes"
|
||||||
|
then
|
||||||
|
|
||||||
|
$as_echo "#define MOO_USE_FLTMAX /**/" >>confdefs.h
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
# Check whether --enable-cxx was given.
|
# Check whether --enable-cxx was given.
|
||||||
if test "${enable_cxx+set}" = set; then :
|
if test "${enable_cxx+set}" = set; then :
|
||||||
enableval=$enable_cxx; enable_cxx_is=$enableval
|
enableval=$enable_cxx; enable_cxx_is=$enableval
|
||||||
|
@ -137,7 +137,7 @@ AC_CHECK_HEADERS([dlfcn.h ltdl.h sys/mman.h])
|
|||||||
AC_CHECK_HEADERS([sys/devpoll.h sys/epoll.h poll.h sys/event.h])
|
AC_CHECK_HEADERS([sys/devpoll.h sys/epoll.h poll.h sys/event.h])
|
||||||
AC_CHECK_HEADERS([netinet/in.h sys/un.h netpacket/packet.h net/if_dl.h])
|
AC_CHECK_HEADERS([netinet/in.h sys/un.h netpacket/packet.h net/if_dl.h])
|
||||||
AC_CHECK_HEADERS([xcb/xcb.h])
|
AC_CHECK_HEADERS([xcb/xcb.h])
|
||||||
AC_CHECK_HEADERS([ffi.h dyncall.h libunwind.h])
|
AC_CHECK_HEADERS([ffi.h dyncall.h libunwind.h quadmath.h])
|
||||||
|
|
||||||
dnl check data types
|
dnl check data types
|
||||||
dnl AC_CHECK_TYPE([wchar_t],
|
dnl AC_CHECK_TYPE([wchar_t],
|
||||||
@ -650,12 +650,14 @@ AC_C_BIGENDIAN(
|
|||||||
[AC_DEFINE([MOO_ENDIAN_LITTLE],[],[Little Endian])],
|
[AC_DEFINE([MOO_ENDIAN_LITTLE],[],[Little Endian])],
|
||||||
[AC_DEFINE([MOO_ENDIAN_UNKNOWN],[],[Unknown Endian])])
|
[AC_DEFINE([MOO_ENDIAN_UNKNOWN],[],[Unknown Endian])])
|
||||||
|
|
||||||
|
dnl ===== enable-experimental =====
|
||||||
AC_ARG_ENABLE([experimental],
|
AC_ARG_ENABLE([experimental],
|
||||||
[AS_HELP_STRING([--enable-experimental],[enable experimental feature(default. no)])],
|
[AS_HELP_STRING([--enable-experimental],[enable experimental feature(default. no)])],
|
||||||
enable_experimental_is=$enableval,
|
enable_experimental_is=$enableval,
|
||||||
enable_experimental_is=no)
|
enable_experimental_is=no)
|
||||||
AM_CONDITIONAL(ENABLE_EXPERIMENTAL, test "${enable_experimental_is}" = "yes" )
|
AM_CONDITIONAL(ENABLE_EXPERIMENTAL, test "${enable_experimental_is}" = "yes" )
|
||||||
|
|
||||||
|
dnl ===== enable-debug =====
|
||||||
AC_ARG_ENABLE([debug],
|
AC_ARG_ENABLE([debug],
|
||||||
[AS_HELP_STRING([--enable-debug],[compile the code in the debug mode (default. no)])],
|
[AS_HELP_STRING([--enable-debug],[compile the code in the debug mode (default. no)])],
|
||||||
enable_debug_is=$enableval,
|
enable_debug_is=$enableval,
|
||||||
@ -673,6 +675,7 @@ else
|
|||||||
AC_SUBST(BUILD_MODE, "release")
|
AC_SUBST(BUILD_MODE, "release")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
dnl ===== enable-unicode =====
|
||||||
AC_ARG_ENABLE([unicode],
|
AC_ARG_ENABLE([unicode],
|
||||||
[AS_HELP_STRING([--enable-unicode],[Use the unicode character type as the default character type. one of yes, no, yes:2, yes:4, no:2, no:4 (default. yes)])],
|
[AS_HELP_STRING([--enable-unicode],[Use the unicode character type as the default character type. one of yes, no, yes:2, yes:4, no:2, no:4 (default. yes)])],
|
||||||
enable_unicode=$enableval,
|
enable_unicode=$enableval,
|
||||||
@ -715,6 +718,7 @@ else
|
|||||||
AC_DEFINE([MOO_UNICODE_SIZE],[1],[Unicode character type size])
|
AC_DEFINE([MOO_UNICODE_SIZE],[1],[Unicode character type size])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
dnl ===== enable-full-liw =====
|
||||||
AC_ARG_ENABLE([full-liw],
|
AC_ARG_ENABLE([full-liw],
|
||||||
[AS_HELP_STRING([--enable-full-liw],[Use a full word as a large integer word (default. no)])],
|
[AS_HELP_STRING([--enable-full-liw],[Use a full word as a large integer word (default. no)])],
|
||||||
enable_full_liw=$enableval,
|
enable_full_liw=$enableval,
|
||||||
@ -725,6 +729,18 @@ then
|
|||||||
AC_DEFINE([MOO_ENABLE_FULL_LIW],[1],[Use a full word as a large integer word])
|
AC_DEFINE([MOO_ENABLE_FULL_LIW],[1],[Use a full word as a large integer word])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
dnl ===== enable-fltmax =====
|
||||||
|
AC_ARG_ENABLE([fltmax],
|
||||||
|
[AS_HELP_STRING([--enable-awk-fltmax],[use hawk_fltmax_t for floating-point numbers (default. no)])],
|
||||||
|
enable_fltmax_is=$enableval,
|
||||||
|
enable_fltmax_is=no
|
||||||
|
)
|
||||||
|
if test "${enable_fltmax_is}" = "yes"
|
||||||
|
then
|
||||||
|
AC_DEFINE([MOO_USE_FLTMAX],[],[use hawk_fltmax_t for floating-point numbers])
|
||||||
|
fi
|
||||||
|
|
||||||
|
dnl ===== enable-cxx =====
|
||||||
AC_ARG_ENABLE([cxx],
|
AC_ARG_ENABLE([cxx],
|
||||||
[AS_HELP_STRING([--enable-cxx],[build the library for C++ if a C++ compiler is available (default. yes)])],
|
[AS_HELP_STRING([--enable-cxx],[build the library for C++ if a C++ compiler is available (default. yes)])],
|
||||||
enable_cxx_is=$enableval,
|
enable_cxx_is=$enableval,
|
||||||
|
@ -274,6 +274,7 @@ void moo_seterrbfmt (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, ...)
|
|||||||
moo->errmsg.len = 0;
|
moo->errmsg.len = 0;
|
||||||
|
|
||||||
MOO_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
MOO_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
||||||
|
fo.mmgr = moo_getmmgr(moo);
|
||||||
fo.putbchars = err_bchars;
|
fo.putbchars = err_bchars;
|
||||||
fo.putuchars = err_uchars;
|
fo.putuchars = err_uchars;
|
||||||
fo.putobj = moo_fmt_object_;
|
fo.putobj = moo_fmt_object_;
|
||||||
@ -295,6 +296,7 @@ void moo_seterrufmt (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, ...)
|
|||||||
moo->errmsg.len = 0;
|
moo->errmsg.len = 0;
|
||||||
|
|
||||||
MOO_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
MOO_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
||||||
|
fo.mmgr = moo_getmmgr(moo);
|
||||||
fo.putbchars = err_bchars;
|
fo.putbchars = err_bchars;
|
||||||
fo.putuchars = err_uchars;
|
fo.putuchars = err_uchars;
|
||||||
fo.putobj = moo_fmt_object_;
|
fo.putobj = moo_fmt_object_;
|
||||||
@ -317,6 +319,7 @@ void moo_seterrbfmtv (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, va_
|
|||||||
moo->errmsg.len = 0;
|
moo->errmsg.len = 0;
|
||||||
|
|
||||||
MOO_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
MOO_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
||||||
|
fo.mmgr = moo_getmmgr(moo);
|
||||||
fo.putbchars = err_bchars;
|
fo.putbchars = err_bchars;
|
||||||
fo.putuchars = err_uchars;
|
fo.putuchars = err_uchars;
|
||||||
fo.putobj = moo_fmt_object_;
|
fo.putobj = moo_fmt_object_;
|
||||||
@ -335,6 +338,7 @@ void moo_seterrufmtv (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, va_
|
|||||||
moo->errmsg.len = 0;
|
moo->errmsg.len = 0;
|
||||||
|
|
||||||
MOO_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
MOO_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
||||||
|
fo.mmgr = moo_getmmgr(moo);
|
||||||
fo.putbchars = err_bchars;
|
fo.putbchars = err_bchars;
|
||||||
fo.putuchars = err_uchars;
|
fo.putuchars = err_uchars;
|
||||||
fo.putobj = moo_fmt_object_;
|
fo.putobj = moo_fmt_object_;
|
||||||
|
167
moo/lib/fmt.c
167
moo/lib/fmt.c
@ -67,8 +67,6 @@
|
|||||||
|
|
||||||
#include "moo-prv.h"
|
#include "moo-prv.h"
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#include <stdio.h> /* for snrintf(). used for floating-point number formatting */
|
#include <stdio.h> /* for snrintf(). used for floating-point number formatting */
|
||||||
#if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
|
#if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
|
||||||
# define snprintf _snprintf
|
# define snprintf _snprintf
|
||||||
@ -79,7 +77,6 @@
|
|||||||
#if defined(HAVE_QUADMATH_H)
|
#if defined(HAVE_QUADMATH_H)
|
||||||
# include <quadmath.h> /* for quadmath_snprintf() */
|
# include <quadmath.h> /* for quadmath_snprintf() */
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Max number conversion buffer length:
|
/* Max number conversion buffer length:
|
||||||
* moo_intmax_t in base 2, plus NUL byte. */
|
* moo_intmax_t in base 2, plus NUL byte. */
|
||||||
@ -416,10 +413,6 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
|||||||
moo_bch_t nbuf[MAXNBUF];
|
moo_bch_t nbuf[MAXNBUF];
|
||||||
const moo_bch_t* nbufp;
|
const moo_bch_t* nbufp;
|
||||||
int stop = 0;
|
int stop = 0;
|
||||||
#if 0
|
|
||||||
moo_bchbuf_t* fltfmt;
|
|
||||||
moo_oochbuf_t* fltout;
|
|
||||||
#endif
|
|
||||||
moo_bch_t* (*sprintn) (moo_bch_t* nbuf, moo_uintmax_t num, int base, moo_ooi_t* lenp);
|
moo_bch_t* (*sprintn) (moo_bch_t* nbuf, moo_uintmax_t num, int base, moo_ooi_t* lenp);
|
||||||
|
|
||||||
fmtptr = (const moo_uint8_t*)fmtout->fmt_str;
|
fmtptr = (const moo_uint8_t*)fmtout->fmt_str;
|
||||||
@ -436,16 +429,10 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
|||||||
/* this is an internal function. it doesn't reset count to 0 */
|
/* this is an internal function. it doesn't reset count to 0 */
|
||||||
/* fmtout->count = 0; */
|
/* fmtout->count = 0; */
|
||||||
|
|
||||||
#if 0
|
fmtout->fb.fmt.ptr = fmtout->fb.fmt.sbuf;
|
||||||
fltfmt = &moo->d->fltfmt;
|
fmtout->fb.fmt.capa = MOO_COUNTOF(fmtout->fb.fmt.sbuf) - 1;
|
||||||
fltout = &moo->d->fltout;
|
fmtout->fb.out.ptr = fmtout->fb.out.sbuf;
|
||||||
|
fmtout->fb.out.capa = MOO_COUNTOF(fmtout->fb.out.sbuf) - 1;
|
||||||
fltfmt->ptr = fltfmt->buf;
|
|
||||||
fltfmt->capa = MOO_COUNTOF(fltfmt->buf) - 1;
|
|
||||||
|
|
||||||
fltout->ptr = fltout->buf;
|
|
||||||
fltout->capa = MOO_COUNTOF(fltout->buf) - 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
@ -1009,7 +996,6 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
case 'f':
|
case 'f':
|
||||||
@ -1024,23 +1010,27 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
|||||||
/* let me rely on snprintf until i implement float-point to string conversion */
|
/* let me rely on snprintf until i implement float-point to string conversion */
|
||||||
int q;
|
int q;
|
||||||
moo_oow_t fmtlen;
|
moo_oow_t fmtlen;
|
||||||
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
union
|
||||||
__float128 v_qd;
|
{
|
||||||
#endif
|
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||||
long double v_ld;
|
__float128 qd;
|
||||||
double v_d;
|
#endif
|
||||||
|
long double ld;
|
||||||
|
double d;
|
||||||
|
} v;
|
||||||
int dtype = 0;
|
int dtype = 0;
|
||||||
moo_oow_t newcapa;
|
moo_oow_t newcapa;
|
||||||
|
moo_bch_t* bsp;
|
||||||
|
|
||||||
if (lm_flag & LF_J)
|
if (lm_flag & LF_J)
|
||||||
{
|
{
|
||||||
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) && (MOO_SIZEOF_FLTMAX_T == MOO_SIZEOF___FLOAT128)
|
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) && (MOO_SIZEOF_FLTMAX_T == MOO_SIZEOF___FLOAT128)
|
||||||
v_qd = va_arg(ap, moo_fltmax_t);
|
v.qd = va_arg(ap, moo_fltmax_t);
|
||||||
dtype = LF_QD;
|
dtype = LF_QD;
|
||||||
#elif MOO_SIZEOF_FLTMAX_T == MOO_SIZEOF_DOUBLE
|
#elif MOO_SIZEOF_FLTMAX_T == MOO_SIZEOF_DOUBLE
|
||||||
v_d = va_arg(ap, moo_fltmax_t);
|
v.d = va_arg(ap, moo_fltmax_t);
|
||||||
#elif MOO_SIZEOF_FLTMAX_T == MOO_SIZEOF_LONG_DOUBLE
|
#elif MOO_SIZEOF_FLTMAX_T == MOO_SIZEOF_LONG_DOUBLE
|
||||||
v_ld = va_arg(ap, moo_fltmax_t);
|
v.ld = va_arg(ap, moo_fltmax_t);
|
||||||
dtype = LF_LD;
|
dtype = LF_LD;
|
||||||
#else
|
#else
|
||||||
#error Unsupported moo_flt_t
|
#error Unsupported moo_flt_t
|
||||||
@ -1055,9 +1045,9 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
|||||||
* so i prefer the format specifier with no modifier.
|
* so i prefer the format specifier with no modifier.
|
||||||
*/
|
*/
|
||||||
#if MOO_SIZEOF_FLT_T == MOO_SIZEOF_DOUBLE
|
#if MOO_SIZEOF_FLT_T == MOO_SIZEOF_DOUBLE
|
||||||
v_d = va_arg(ap, moo_flt_t);
|
v.d = va_arg(ap, moo_flt_t);
|
||||||
#elif MOO_SIZEOF_FLT_T == MOO_SIZEOF_LONG_DOUBLE
|
#elif MOO_SIZEOF_FLT_T == MOO_SIZEOF_LONG_DOUBLE
|
||||||
v_ld = va_arg(ap, moo_flt_t);
|
v.ld = va_arg(ap, moo_flt_t);
|
||||||
dtype = LF_LD;
|
dtype = LF_LD;
|
||||||
#else
|
#else
|
||||||
#error Unsupported moo_flt_t
|
#error Unsupported moo_flt_t
|
||||||
@ -1065,13 +1055,13 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
|||||||
}
|
}
|
||||||
else if (lm_flag & (LF_LD | LF_L))
|
else if (lm_flag & (LF_LD | LF_L))
|
||||||
{
|
{
|
||||||
v_ld = va_arg(ap, long double);
|
v.ld = va_arg(ap, long double);
|
||||||
dtype = LF_LD;
|
dtype = LF_LD;
|
||||||
}
|
}
|
||||||
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||||
else if (lm_flag & (LF_QD | LF_Q))
|
else if (lm_flag & (LF_QD | LF_Q))
|
||||||
{
|
{
|
||||||
v_qd = va_arg(ap, __float128);
|
v.qd = va_arg(ap, __float128);
|
||||||
dtype = LF_QD;
|
dtype = LF_QD;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1081,63 +1071,63 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
v_d = va_arg(ap, double);
|
v.d = va_arg(ap, double);
|
||||||
}
|
}
|
||||||
|
|
||||||
fmtlen = fmt - percent;
|
fmtlen = fmtptr - percent;
|
||||||
if (fmtlen > fltfmt->capa)
|
if (fmtlen > fmtout->fb.fmt.capa)
|
||||||
{
|
{
|
||||||
if (fltfmt->ptr == fltfmt->buf)
|
if (fmtout->fb.fmt.ptr == fmtout->fb.fmt.sbuf)
|
||||||
{
|
{
|
||||||
fltfmt->ptr = MOO_MMGR_ALLOC(MOO_MMGR_GETDFL(), MOO_SIZEOF(*fltfmt->ptr) * (fmtlen + 1));
|
fmtout->fb.fmt.ptr = (moo_bch_t*)MOO_MMGR_ALLOC(fmtout->mmgr, MOO_SIZEOF(*fmtout->fb.fmt.ptr) * (fmtlen + 1));
|
||||||
if (!fltfmt->ptr) goto oops;
|
if (!fmtout->fb.fmt.ptr) goto oops;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
moo_bch_t* tmpptr;
|
moo_bch_t* tmpptr;
|
||||||
|
|
||||||
tmpptr = MOO_MMGR_REALLOC(MOO_MMGR_GETDFL(), fltfmt->ptr, MOO_SIZEOF(*fltfmt->ptr) * (fmtlen + 1));
|
tmpptr = (moo_bch_t*)MOO_MMGR_REALLOC(fmtout->mmgr, fmtout->fb.fmt.ptr, MOO_SIZEOF(*fmtout->fb.fmt.ptr) * (fmtlen + 1));
|
||||||
if (!tmpptr) goto oops;
|
if (!tmpptr) goto oops;
|
||||||
fltfmt->ptr = tmpptr;
|
fmtout->fb.fmt.ptr = tmpptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
fltfmt->capa = fmtlen;
|
fmtout->fb.fmt.capa = fmtlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compose back the format specifier */
|
/* compose back the format specifier */
|
||||||
fmtlen = 0;
|
fmtlen = 0;
|
||||||
fltfmt->ptr[fmtlen++] = '%';
|
fmtout->fb.fmt.ptr[fmtlen++] = '%';
|
||||||
if (flagc & FLAGC_SPACE) fltfmt->ptr[fmtlen++] = ' ';
|
if (flagc & FLAGC_SPACE) fmtout->fb.fmt.ptr[fmtlen++] = ' ';
|
||||||
if (flagc & FLAGC_SHARP) fltfmt->ptr[fmtlen++] = '#';
|
if (flagc & FLAGC_SHARP) fmtout->fb.fmt.ptr[fmtlen++] = '#';
|
||||||
if (flagc & FLAGC_SIGN) fltfmt->ptr[fmtlen++] = '+';
|
if (flagc & FLAGC_SIGN) fmtout->fb.fmt.ptr[fmtlen++] = '+';
|
||||||
if (flagc & FLAGC_LEFTADJ) fltfmt->ptr[fmtlen++] = '-';
|
if (flagc & FLAGC_LEFTADJ) fmtout->fb.fmt.ptr[fmtlen++] = '-';
|
||||||
if (flagc & FLAGC_ZEROPAD) fltfmt->ptr[fmtlen++] = '0';
|
if (flagc & FLAGC_ZEROPAD) fmtout->fb.fmt.ptr[fmtlen++] = '0';
|
||||||
|
|
||||||
if (flagc & FLAGC_STAR1) fltfmt->ptr[fmtlen++] = '*';
|
if (flagc & FLAGC_STAR1) fmtout->fb.fmt.ptr[fmtlen++] = '*';
|
||||||
else if (flagc & FLAGC_WIDTH)
|
else if (flagc & FLAGC_WIDTH)
|
||||||
{
|
{
|
||||||
fmtlen += moo_fmt_uintmax_to_bcs (
|
fmtlen += moo_fmt_uintmax_to_bcstr(
|
||||||
&fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen,
|
&fmtout->fb.fmt.ptr[fmtlen], fmtout->fb.fmt.capa - fmtlen,
|
||||||
width, 10, -1, '\0', MOO_NULL);
|
width, 10, -1, '\0', MOO_NULL);
|
||||||
}
|
}
|
||||||
if (flagc & FLAGC_DOT) fltfmt->ptr[fmtlen++] = '.';
|
if (flagc & FLAGC_DOT) fmtout->fb.fmt.ptr[fmtlen++] = '.';
|
||||||
if (flagc & FLAGC_STAR2) fltfmt->ptr[fmtlen++] = '*';
|
if (flagc & FLAGC_STAR2) fmtout->fb.fmt.ptr[fmtlen++] = '*';
|
||||||
else if (flagc & FLAGC_PRECISION)
|
else if (flagc & FLAGC_PRECISION)
|
||||||
{
|
{
|
||||||
fmtlen += moo_fmt_uintmax_to_bcs (
|
fmtlen += moo_fmt_uintmax_to_bcstr(
|
||||||
&fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen,
|
&fmtout->fb.fmt.ptr[fmtlen], fmtout->fb.fmt.capa - fmtlen,
|
||||||
precision, 10, -1, '\0', MOO_NULL);
|
precision, 10, -1, '\0', MOO_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dtype == LF_LD)
|
if (dtype == LF_LD)
|
||||||
fltfmt->ptr[fmtlen++] = 'L';
|
fmtout->fb.fmt.ptr[fmtlen++] = 'L';
|
||||||
#if (MOO_SIZEOF___FLOAT128 > 0)
|
#if (MOO_SIZEOF___FLOAT128 > 0)
|
||||||
else if (dtype == LF_QD)
|
else if (dtype == LF_QD)
|
||||||
fltfmt->ptr[fmtlen++] = 'Q';
|
fmtout->fb.fmt.ptr[fmtlen++] = 'Q';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fltfmt->ptr[fmtlen++] = ch;
|
fmtout->fb.fmt.ptr[fmtlen++] = uch;
|
||||||
fltfmt->ptr[fmtlen] = '\0';
|
fmtout->fb.fmt.ptr[fmtlen] = '\0';
|
||||||
|
|
||||||
#if defined(HAVE_SNPRINTF)
|
#if defined(HAVE_SNPRINTF)
|
||||||
/* nothing special here */
|
/* nothing special here */
|
||||||
@ -1149,7 +1139,7 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
|||||||
{
|
{
|
||||||
MOO_ASSERT (moo, fltout->ptr == fltout->buf);
|
MOO_ASSERT (moo, fltout->ptr == fltout->buf);
|
||||||
|
|
||||||
fltout->ptr = MOO_MMGR_ALLOC(MOO_MMGR_GETDFL(), MOO_SIZEOF(char_t) * (newcapa + 1));
|
fltout->ptr = MOO_MMGR_ALLOC(fmtout->mmgr, MOO_SIZEOF(char_t) * (newcapa + 1));
|
||||||
if (!fltout->ptr) goto oops;
|
if (!fltout->ptr) goto oops;
|
||||||
fltout->capa = newcapa;
|
fltout->capa = newcapa;
|
||||||
}
|
}
|
||||||
@ -1161,64 +1151,84 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
|||||||
if (dtype == LF_LD)
|
if (dtype == LF_LD)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_SNPRINTF)
|
#if defined(HAVE_SNPRINTF)
|
||||||
q = snprintf ((moo_bch_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_ld);
|
q = snprintf((moo_bch_t*)fmtout->fb.out.ptr, fmtout->fb.out.capa + 1, fmtout->fb.fmt.ptr, v.ld);
|
||||||
#else
|
#else
|
||||||
q = sprintf ((moo_bch_t*)fltout->ptr, fltfmt->ptr, v_ld);
|
q = sprintf((moo_bch_t*)fmtout->fb.out.ptr, fmtout->fb.fmt.ptr, v.ld);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||||
else if (dtype == LF_QD)
|
else if (dtype == LF_QD)
|
||||||
{
|
{
|
||||||
q = quadmath_snprintf((moo_bch_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_qd);
|
q = quadmath_snprintf((moo_bch_t*)fmtout->fb.out.ptr, fmtout->fb.out.capa + 1, fmtout->fb.fmt.ptr, v.qd);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if defined(HAVE_SNPRINTF)
|
#if defined(HAVE_SNPRINTF)
|
||||||
q = snprintf ((moo_bch_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_d);
|
q = snprintf((moo_bch_t*)fmtout->fb.out.ptr, fmtout->fb.out.capa + 1, fmtout->fb.fmt.ptr, v.d);
|
||||||
#else
|
#else
|
||||||
q = sprintf ((moo_bch_t*)fltout->ptr, fltfmt->ptr, v_d);
|
q = sprintf((moo_bch_t*)fmtout->fb.out.ptr, fmtout->fb.fmt.ptr, v.d);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (q <= -1) goto oops;
|
if (q <= -1) goto oops;
|
||||||
if (q <= fltout->capa) break;
|
if (q <= fmtout->fb.out.capa) break;
|
||||||
|
|
||||||
newcapa = fltout->capa * 2;
|
newcapa = fmtout->fb.out.capa * 2;
|
||||||
if (newcapa < q) newcapa = q;
|
if (newcapa < q) newcapa = q;
|
||||||
|
|
||||||
if (fltout->ptr == fltout->sbuf)
|
if (fmtout->fb.out.ptr == fmtout->fb.out.sbuf)
|
||||||
{
|
{
|
||||||
fltout->ptr = MOO_MMGR_ALLOC(MOO_MMGR_GETDFL(), MOO_SIZEOF(char_t) * (newcapa + 1));
|
fmtout->fb.out.ptr = (moo_bch_t*)MOO_MMGR_ALLOC(fmtout->mmgr, MOO_SIZEOF(char_t) * (newcapa + 1));
|
||||||
if (!fltout->ptr) goto oops;
|
if (!fmtout->fb.out.ptr) goto oops;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char_t* tmpptr;
|
moo_bch_t* tmpptr;
|
||||||
|
tmpptr = (moo_bch_t*)MOO_MMGR_REALLOC(fmtout->mmgr, fmtout->fb.out.ptr, MOO_SIZEOF(char_t) * (newcapa + 1));
|
||||||
tmpptr = MOO_MMGR_REALLOC(MOO_MMGR_GETDFL(), fltout->ptr, MOO_SIZEOF(char_t) * (newcapa + 1));
|
|
||||||
if (!tmpptr) goto oops;
|
if (!tmpptr) goto oops;
|
||||||
fltout->ptr = tmpptr;
|
fmtout->fb.out.ptr = tmpptr;
|
||||||
}
|
}
|
||||||
fltout->capa = newcapa;
|
fmtout->fb.out.capa = newcapa;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MOO_SIZEOF(char_t) != MOO_SIZEOF(moo_bch_t))
|
if (MOO_SIZEOF(char_t) != MOO_SIZEOF(moo_bch_t))
|
||||||
{
|
{
|
||||||
fltout->ptr[q] = '\0';
|
fmtout->fb.out.ptr[q] = '\0';
|
||||||
while (q > 0)
|
while (q > 0)
|
||||||
{
|
{
|
||||||
q--;
|
q--;
|
||||||
fltout->ptr[q] = ((moo_bch_t*)fltout->ptr)[q];
|
fmtout->fb.out.ptr[q] = ((moo_bch_t*)fmtout->fb.out.ptr)[q];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sp = fltout->ptr;
|
#if 0
|
||||||
|
bsp = fmtout->fb.out.ptr;
|
||||||
flagc &= ~FLAGC_DOT;
|
flagc &= ~FLAGC_DOT;
|
||||||
width = 0;
|
width = 0;
|
||||||
precision = 0;
|
precision = 0;
|
||||||
goto print_lowercase_s;
|
goto lowercase_s;
|
||||||
}
|
|
||||||
|
#else
|
||||||
|
bsp = fmtout->fb.out.ptr;
|
||||||
|
n = 0;
|
||||||
|
/*
|
||||||
|
if (flagc & FLAGC_DOT)
|
||||||
|
{
|
||||||
|
while (n < precision && bsp[n]) n++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{*/
|
||||||
|
while (bsp[n]) n++;
|
||||||
|
/*}*/
|
||||||
|
|
||||||
|
width -= n;
|
||||||
|
|
||||||
|
if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_BCH (fmtout, padc, width);
|
||||||
|
PUT_BCS (fmtout, bsp, n);
|
||||||
|
if ((flagc & FLAGC_LEFTADJ) && width > 0) PUT_BCH (fmtout, padc, width);
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
handle_nosign:
|
handle_nosign:
|
||||||
sign = 0;
|
sign = 0;
|
||||||
@ -2021,6 +2031,7 @@ moo_ooi_t moo_logbfmtv (moo_t* moo, moo_bitmask_t mask, const moo_bch_t* fmt, va
|
|||||||
fo.fmt_str = fmt;
|
fo.fmt_str = fmt;
|
||||||
fo.ctx = moo;
|
fo.ctx = moo;
|
||||||
fo.mask = mask;
|
fo.mask = mask;
|
||||||
|
fo.mmgr = moo_getmmgr(moo);
|
||||||
fo.putbchars = log_bcs;
|
fo.putbchars = log_bcs;
|
||||||
fo.putuchars = log_ucs;
|
fo.putuchars = log_ucs;
|
||||||
fo.putobj = moo_fmt_object_;
|
fo.putobj = moo_fmt_object_;
|
||||||
@ -2075,6 +2086,7 @@ moo_ooi_t moo_logufmtv (moo_t* moo, moo_bitmask_t mask, const moo_uch_t* fmt, va
|
|||||||
fo.fmt_str = fmt;
|
fo.fmt_str = fmt;
|
||||||
fo.ctx = moo;
|
fo.ctx = moo;
|
||||||
fo.mask = mask;
|
fo.mask = mask;
|
||||||
|
fo.mmgr = moo_getmmgr(moo);
|
||||||
fo.putbchars = log_bcs;
|
fo.putbchars = log_bcs;
|
||||||
fo.putuchars = log_ucs;
|
fo.putuchars = log_ucs;
|
||||||
fo.putobj = moo_fmt_object_;
|
fo.putobj = moo_fmt_object_;
|
||||||
@ -2922,6 +2934,7 @@ int moo_strfmtcallstack (moo_t* moo, moo_ooi_t nargs, int rcv_is_fmtstr)
|
|||||||
|
|
||||||
MOO_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
MOO_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
||||||
fo.ctx = moo;
|
fo.ctx = moo;
|
||||||
|
fo.mmgr = moo_getmmgr(moo);
|
||||||
fo.putbchars = sprint_bchars;
|
fo.putbchars = sprint_bchars;
|
||||||
fo.putuchars = sprint_uchars;
|
fo.putuchars = sprint_uchars;
|
||||||
fo.putobj = moo_fmt_object_;
|
fo.putobj = moo_fmt_object_;
|
||||||
|
@ -174,6 +174,9 @@
|
|||||||
/* Have PTHREAD_PRIO_INHERIT. */
|
/* Have PTHREAD_PRIO_INHERIT. */
|
||||||
#undef HAVE_PTHREAD_PRIO_INHERIT
|
#undef HAVE_PTHREAD_PRIO_INHERIT
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <quadmath.h> header file. */
|
||||||
|
#undef HAVE_QUADMATH_H
|
||||||
|
|
||||||
/* Define to 1 if you have the `quadmath_snprintf' function. */
|
/* Define to 1 if you have the `quadmath_snprintf' function. */
|
||||||
#undef HAVE_QUADMATH_SNPRINTF
|
#undef HAVE_QUADMATH_SNPRINTF
|
||||||
|
|
||||||
@ -498,6 +501,9 @@
|
|||||||
/* Unicode character type size */
|
/* Unicode character type size */
|
||||||
#undef MOO_UNICODE_SIZE
|
#undef MOO_UNICODE_SIZE
|
||||||
|
|
||||||
|
/* use hawk_fltmax_t for floating-point numbers */
|
||||||
|
#undef MOO_USE_FLTMAX
|
||||||
|
|
||||||
/* The size of `MB_LEN_MAX', as computed by valueof. */
|
/* The size of `MB_LEN_MAX', as computed by valueof. */
|
||||||
#undef NUMVALOF_MB_LEN_MAX
|
#undef NUMVALOF_MB_LEN_MAX
|
||||||
|
|
||||||
|
@ -337,6 +337,50 @@
|
|||||||
# error UNKNOWN INTMAX SIZE
|
# error UNKNOWN INTMAX SIZE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* =========================================================================
|
||||||
|
* FLOATING-POINT TYPE
|
||||||
|
* ========================================================================= */
|
||||||
|
/** \typedef moo_fltbas_t
|
||||||
|
* The moo_fltbas_t type defines the largest floating-pointer number type
|
||||||
|
* naturally supported.
|
||||||
|
*/
|
||||||
|
#if defined(__FreeBSD__) || defined(__MINGW32__)
|
||||||
|
/* TODO: check if the support for long double is complete.
|
||||||
|
* if so, use long double for moo_flt_t */
|
||||||
|
typedef double moo_fltbas_t;
|
||||||
|
# define MOO_SIZEOF_FLTBAS_T MOO_SIZEOF_DOUBLE
|
||||||
|
#elif MOO_SIZEOF_LONG_DOUBLE > MOO_SIZEOF_DOUBLE
|
||||||
|
typedef long double moo_fltbas_t;
|
||||||
|
# define MOO_SIZEOF_FLTBAS_T MOO_SIZEOF_LONG_DOUBLE
|
||||||
|
#else
|
||||||
|
typedef double moo_fltbas_t;
|
||||||
|
# define MOO_SIZEOF_FLTBAS_T MOO_SIZEOF_DOUBLE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** \typedef moo_fltmax_t
|
||||||
|
* The moo_fltmax_t type defines the largest floating-pointer number type
|
||||||
|
* ever supported.
|
||||||
|
*/
|
||||||
|
#if MOO_SIZEOF___FLOAT128 >= MOO_SIZEOF_FLT_T
|
||||||
|
/* the size of long double may be equal to the size of __float128
|
||||||
|
* for alignment on some platforms */
|
||||||
|
typedef __float128 moo_fltmax_t;
|
||||||
|
# define MOO_SIZEOF_FLTMAX_T MOO_SIZEOF___FLOAT128
|
||||||
|
# define MOO_FLTMAX_REQUIRE_QUADMATH 1
|
||||||
|
#else
|
||||||
|
typedef moo_flt_t moo_fltmax_t;
|
||||||
|
# define MOO_SIZEOF_FLTMAX_T MOO_SIZEOF_FLT_T
|
||||||
|
# undef MOO_FLTMAX_REQUIRE_QUADMATH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(MOO_USE_FLTMAX)
|
||||||
|
typedef moo_fltmax_t moo_flt_t;
|
||||||
|
#define MOO_SIZEOF_FLT_T MOO_SIZEOF_FLTMAX_T
|
||||||
|
#else
|
||||||
|
typedef moo_fltbas_t moo_flt_t;
|
||||||
|
#define MOO_SIZEOF_FLT_T MOO_SIZEOF_FLTBAS_T
|
||||||
|
#endif
|
||||||
|
|
||||||
/* =========================================================================
|
/* =========================================================================
|
||||||
* BASIC HARD-CODED DEFINES
|
* BASIC HARD-CODED DEFINES
|
||||||
* ========================================================================= */
|
* ========================================================================= */
|
||||||
|
@ -174,6 +174,7 @@ struct moo_fmtout_t
|
|||||||
{
|
{
|
||||||
moo_oow_t count; /* out */
|
moo_oow_t count; /* out */
|
||||||
|
|
||||||
|
moo_mmgr_t* mmgr; /* in */
|
||||||
moo_fmtout_putbchars_t putbchars; /* in */
|
moo_fmtout_putbchars_t putbchars; /* in */
|
||||||
moo_fmtout_putuchars_t putuchars; /* in */
|
moo_fmtout_putuchars_t putuchars; /* in */
|
||||||
moo_fmtout_putobj_t putobj; /* in - %O is not handled if it's not set. */
|
moo_fmtout_putobj_t putobj; /* in - %O is not handled if it's not set. */
|
||||||
@ -182,6 +183,23 @@ struct moo_fmtout_t
|
|||||||
|
|
||||||
moo_fmtout_fmt_type_t fmt_type;
|
moo_fmtout_fmt_type_t fmt_type;
|
||||||
const void* fmt_str;
|
const void* fmt_str;
|
||||||
|
|
||||||
|
/* internal use from here below */
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
moo_bch_t sbuf[32];
|
||||||
|
moo_bch_t* ptr;
|
||||||
|
moo_oow_t capa;
|
||||||
|
} fmt;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
moo_bch_t sbuf[32];
|
||||||
|
moo_bch_t* ptr;
|
||||||
|
moo_oow_t capa;
|
||||||
|
} out;
|
||||||
|
} fb; /* some buffers for handling moo_flt_t/moo_fltmax_t formatting */
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
Loading…
Reference in New Issue
Block a user