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_unicode
|
||||
enable_full_liw
|
||||
enable_fltmax
|
||||
enable_cxx
|
||||
enable_dynamic_module
|
||||
enable_static_module
|
||||
@ -1492,6 +1493,8 @@ Optional Features:
|
||||
no:4 (default. yes)
|
||||
--enable-full-liw Use a full word as a large integer word (default.
|
||||
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
|
||||
available (default. yes)
|
||||
--enable-dynamic-module enable dynamic module capability(default. yes)
|
||||
@ -18505,7 +18508,7 @@ fi
|
||||
|
||||
done
|
||||
|
||||
for ac_header in ffi.h dyncall.h libunwind.h
|
||||
for ac_header in ffi.h dyncall.h libunwind.h quadmath.h
|
||||
do :
|
||||
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"
|
||||
@ -21793,6 +21796,21 @@ $as_echo "#define MOO_ENABLE_FULL_LIW 1" >>confdefs.h
|
||||
|
||||
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.
|
||||
if test "${enable_cxx+set}" = set; then :
|
||||
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([netinet/in.h sys/un.h netpacket/packet.h net/if_dl.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 AC_CHECK_TYPE([wchar_t],
|
||||
@ -650,12 +650,14 @@ AC_C_BIGENDIAN(
|
||||
[AC_DEFINE([MOO_ENDIAN_LITTLE],[],[Little Endian])],
|
||||
[AC_DEFINE([MOO_ENDIAN_UNKNOWN],[],[Unknown Endian])])
|
||||
|
||||
dnl ===== enable-experimental =====
|
||||
AC_ARG_ENABLE([experimental],
|
||||
[AS_HELP_STRING([--enable-experimental],[enable experimental feature(default. no)])],
|
||||
enable_experimental_is=$enableval,
|
||||
enable_experimental_is=no)
|
||||
AM_CONDITIONAL(ENABLE_EXPERIMENTAL, test "${enable_experimental_is}" = "yes" )
|
||||
|
||||
dnl ===== enable-debug =====
|
||||
AC_ARG_ENABLE([debug],
|
||||
[AS_HELP_STRING([--enable-debug],[compile the code in the debug mode (default. no)])],
|
||||
enable_debug_is=$enableval,
|
||||
@ -673,6 +675,7 @@ else
|
||||
AC_SUBST(BUILD_MODE, "release")
|
||||
fi
|
||||
|
||||
dnl ===== 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)])],
|
||||
enable_unicode=$enableval,
|
||||
@ -715,6 +718,7 @@ else
|
||||
AC_DEFINE([MOO_UNICODE_SIZE],[1],[Unicode character type size])
|
||||
fi
|
||||
|
||||
dnl ===== 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)])],
|
||||
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])
|
||||
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],
|
||||
[AS_HELP_STRING([--enable-cxx],[build the library for C++ if a C++ compiler is available (default. yes)])],
|
||||
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_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
||||
fo.mmgr = moo_getmmgr(moo);
|
||||
fo.putbchars = err_bchars;
|
||||
fo.putuchars = err_uchars;
|
||||
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_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
||||
fo.mmgr = moo_getmmgr(moo);
|
||||
fo.putbchars = err_bchars;
|
||||
fo.putuchars = err_uchars;
|
||||
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_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
||||
fo.mmgr = moo_getmmgr(moo);
|
||||
fo.putbchars = err_bchars;
|
||||
fo.putuchars = err_uchars;
|
||||
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_MEMSET (&fo, 0, MOO_SIZEOF(fo));
|
||||
fo.mmgr = moo_getmmgr(moo);
|
||||
fo.putbchars = err_bchars;
|
||||
fo.putuchars = err_uchars;
|
||||
fo.putobj = moo_fmt_object_;
|
||||
|
167
moo/lib/fmt.c
167
moo/lib/fmt.c
@ -67,8 +67,6 @@
|
||||
|
||||
#include "moo-prv.h"
|
||||
|
||||
|
||||
#if 0
|
||||
#include <stdio.h> /* for snrintf(). used for floating-point number formatting */
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
|
||||
# define snprintf _snprintf
|
||||
@ -79,7 +77,6 @@
|
||||
#if defined(HAVE_QUADMATH_H)
|
||||
# include <quadmath.h> /* for quadmath_snprintf() */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Max number conversion buffer length:
|
||||
* 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];
|
||||
const moo_bch_t* nbufp;
|
||||
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);
|
||||
|
||||
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 */
|
||||
/* fmtout->count = 0; */
|
||||
|
||||
#if 0
|
||||
fltfmt = &moo->d->fltfmt;
|
||||
fltout = &moo->d->fltout;
|
||||
|
||||
fltfmt->ptr = fltfmt->buf;
|
||||
fltfmt->capa = MOO_COUNTOF(fltfmt->buf) - 1;
|
||||
|
||||
fltout->ptr = fltout->buf;
|
||||
fltout->capa = MOO_COUNTOF(fltout->buf) - 1;
|
||||
#endif
|
||||
fmtout->fb.fmt.ptr = fmtout->fb.fmt.sbuf;
|
||||
fmtout->fb.fmt.capa = MOO_COUNTOF(fmtout->fb.fmt.sbuf) - 1;
|
||||
fmtout->fb.out.ptr = fmtout->fb.out.sbuf;
|
||||
fmtout->fb.out.capa = MOO_COUNTOF(fmtout->fb.out.sbuf) - 1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -1009,7 +996,6 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
||||
break;
|
||||
}
|
||||
|
||||
#if 0
|
||||
case 'e':
|
||||
case 'E':
|
||||
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 */
|
||||
int q;
|
||||
moo_oow_t fmtlen;
|
||||
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||
__float128 v_qd;
|
||||
#endif
|
||||
long double v_ld;
|
||||
double v_d;
|
||||
union
|
||||
{
|
||||
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||
__float128 qd;
|
||||
#endif
|
||||
long double ld;
|
||||
double d;
|
||||
} v;
|
||||
int dtype = 0;
|
||||
moo_oow_t newcapa;
|
||||
moo_bch_t* bsp;
|
||||
|
||||
if (lm_flag & LF_J)
|
||||
{
|
||||
#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;
|
||||
#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
|
||||
v_ld = va_arg(ap, moo_fltmax_t);
|
||||
v.ld = va_arg(ap, moo_fltmax_t);
|
||||
dtype = LF_LD;
|
||||
#else
|
||||
#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.
|
||||
*/
|
||||
#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
|
||||
v_ld = va_arg(ap, moo_flt_t);
|
||||
v.ld = va_arg(ap, moo_flt_t);
|
||||
dtype = LF_LD;
|
||||
#else
|
||||
#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))
|
||||
{
|
||||
v_ld = va_arg(ap, long double);
|
||||
v.ld = va_arg(ap, long double);
|
||||
dtype = LF_LD;
|
||||
}
|
||||
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||
else if (lm_flag & (LF_QD | LF_Q))
|
||||
{
|
||||
v_qd = va_arg(ap, __float128);
|
||||
v.qd = va_arg(ap, __float128);
|
||||
dtype = LF_QD;
|
||||
}
|
||||
#endif
|
||||
@ -1081,63 +1071,63 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
||||
}
|
||||
else
|
||||
{
|
||||
v_d = va_arg(ap, double);
|
||||
v.d = va_arg(ap, double);
|
||||
}
|
||||
|
||||
fmtlen = fmt - percent;
|
||||
if (fmtlen > fltfmt->capa)
|
||||
fmtlen = fmtptr - percent;
|
||||
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));
|
||||
if (!fltfmt->ptr) goto oops;
|
||||
fmtout->fb.fmt.ptr = (moo_bch_t*)MOO_MMGR_ALLOC(fmtout->mmgr, MOO_SIZEOF(*fmtout->fb.fmt.ptr) * (fmtlen + 1));
|
||||
if (!fmtout->fb.fmt.ptr) goto oops;
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
fltfmt->ptr = tmpptr;
|
||||
fmtout->fb.fmt.ptr = tmpptr;
|
||||
}
|
||||
|
||||
fltfmt->capa = fmtlen;
|
||||
fmtout->fb.fmt.capa = fmtlen;
|
||||
}
|
||||
|
||||
/* compose back the format specifier */
|
||||
fmtlen = 0;
|
||||
fltfmt->ptr[fmtlen++] = '%';
|
||||
if (flagc & FLAGC_SPACE) fltfmt->ptr[fmtlen++] = ' ';
|
||||
if (flagc & FLAGC_SHARP) fltfmt->ptr[fmtlen++] = '#';
|
||||
if (flagc & FLAGC_SIGN) fltfmt->ptr[fmtlen++] = '+';
|
||||
if (flagc & FLAGC_LEFTADJ) fltfmt->ptr[fmtlen++] = '-';
|
||||
if (flagc & FLAGC_ZEROPAD) fltfmt->ptr[fmtlen++] = '0';
|
||||
fmtout->fb.fmt.ptr[fmtlen++] = '%';
|
||||
if (flagc & FLAGC_SPACE) fmtout->fb.fmt.ptr[fmtlen++] = ' ';
|
||||
if (flagc & FLAGC_SHARP) fmtout->fb.fmt.ptr[fmtlen++] = '#';
|
||||
if (flagc & FLAGC_SIGN) fmtout->fb.fmt.ptr[fmtlen++] = '+';
|
||||
if (flagc & FLAGC_LEFTADJ) fmtout->fb.fmt.ptr[fmtlen++] = '-';
|
||||
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)
|
||||
{
|
||||
fmtlen += moo_fmt_uintmax_to_bcs (
|
||||
&fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen,
|
||||
fmtlen += moo_fmt_uintmax_to_bcstr(
|
||||
&fmtout->fb.fmt.ptr[fmtlen], fmtout->fb.fmt.capa - fmtlen,
|
||||
width, 10, -1, '\0', MOO_NULL);
|
||||
}
|
||||
if (flagc & FLAGC_DOT) fltfmt->ptr[fmtlen++] = '.';
|
||||
if (flagc & FLAGC_STAR2) fltfmt->ptr[fmtlen++] = '*';
|
||||
if (flagc & FLAGC_DOT) fmtout->fb.fmt.ptr[fmtlen++] = '.';
|
||||
if (flagc & FLAGC_STAR2) fmtout->fb.fmt.ptr[fmtlen++] = '*';
|
||||
else if (flagc & FLAGC_PRECISION)
|
||||
{
|
||||
fmtlen += moo_fmt_uintmax_to_bcs (
|
||||
&fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen,
|
||||
fmtlen += moo_fmt_uintmax_to_bcstr(
|
||||
&fmtout->fb.fmt.ptr[fmtlen], fmtout->fb.fmt.capa - fmtlen,
|
||||
precision, 10, -1, '\0', MOO_NULL);
|
||||
}
|
||||
|
||||
if (dtype == LF_LD)
|
||||
fltfmt->ptr[fmtlen++] = 'L';
|
||||
fmtout->fb.fmt.ptr[fmtlen++] = 'L';
|
||||
#if (MOO_SIZEOF___FLOAT128 > 0)
|
||||
else if (dtype == LF_QD)
|
||||
fltfmt->ptr[fmtlen++] = 'Q';
|
||||
fmtout->fb.fmt.ptr[fmtlen++] = 'Q';
|
||||
#endif
|
||||
|
||||
fltfmt->ptr[fmtlen++] = ch;
|
||||
fltfmt->ptr[fmtlen] = '\0';
|
||||
fmtout->fb.fmt.ptr[fmtlen++] = uch;
|
||||
fmtout->fb.fmt.ptr[fmtlen] = '\0';
|
||||
|
||||
#if defined(HAVE_SNPRINTF)
|
||||
/* 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);
|
||||
|
||||
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;
|
||||
fltout->capa = newcapa;
|
||||
}
|
||||
@ -1161,64 +1151,84 @@ static int fmt_outv (moo_fmtout_t* fmtout, va_list ap)
|
||||
if (dtype == LF_LD)
|
||||
{
|
||||
#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
|
||||
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
|
||||
}
|
||||
#if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
|
||||
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
|
||||
else
|
||||
{
|
||||
#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
|
||||
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
|
||||
}
|
||||
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 (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));
|
||||
if (!fltout->ptr) goto oops;
|
||||
fmtout->fb.out.ptr = (moo_bch_t*)MOO_MMGR_ALLOC(fmtout->mmgr, MOO_SIZEOF(char_t) * (newcapa + 1));
|
||||
if (!fmtout->fb.out.ptr) goto oops;
|
||||
}
|
||||
else
|
||||
{
|
||||
char_t* tmpptr;
|
||||
|
||||
tmpptr = MOO_MMGR_REALLOC(MOO_MMGR_GETDFL(), fltout->ptr, MOO_SIZEOF(char_t) * (newcapa + 1));
|
||||
moo_bch_t* tmpptr;
|
||||
tmpptr = (moo_bch_t*)MOO_MMGR_REALLOC(fmtout->mmgr, fmtout->fb.out.ptr, MOO_SIZEOF(char_t) * (newcapa + 1));
|
||||
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))
|
||||
{
|
||||
fltout->ptr[q] = '\0';
|
||||
fmtout->fb.out.ptr[q] = '\0';
|
||||
while (q > 0)
|
||||
{
|
||||
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;
|
||||
width = 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
|
||||
}
|
||||
|
||||
handle_nosign:
|
||||
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.ctx = moo;
|
||||
fo.mask = mask;
|
||||
fo.mmgr = moo_getmmgr(moo);
|
||||
fo.putbchars = log_bcs;
|
||||
fo.putuchars = log_ucs;
|
||||
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.ctx = moo;
|
||||
fo.mask = mask;
|
||||
fo.mmgr = moo_getmmgr(moo);
|
||||
fo.putbchars = log_bcs;
|
||||
fo.putuchars = log_ucs;
|
||||
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));
|
||||
fo.ctx = moo;
|
||||
fo.mmgr = moo_getmmgr(moo);
|
||||
fo.putbchars = sprint_bchars;
|
||||
fo.putuchars = sprint_uchars;
|
||||
fo.putobj = moo_fmt_object_;
|
||||
|
@ -174,6 +174,9 @@
|
||||
/* 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. */
|
||||
#undef HAVE_QUADMATH_SNPRINTF
|
||||
|
||||
@ -498,6 +501,9 @@
|
||||
/* Unicode character type 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. */
|
||||
#undef NUMVALOF_MB_LEN_MAX
|
||||
|
||||
|
@ -337,6 +337,50 @@
|
||||
# error UNKNOWN INTMAX SIZE
|
||||
#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
|
||||
* ========================================================================= */
|
||||
|
@ -174,6 +174,7 @@ struct moo_fmtout_t
|
||||
{
|
||||
moo_oow_t count; /* out */
|
||||
|
||||
moo_mmgr_t* mmgr; /* in */
|
||||
moo_fmtout_putbchars_t putbchars; /* in */
|
||||
moo_fmtout_putuchars_t putuchars; /* in */
|
||||
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;
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user