enhanced __float128 handling

added qse_strvfmt() and qse_strxvfmt()
This commit is contained in:
hyung-hwan 2013-11-03 16:01:39 +00:00
parent fa47ad2965
commit 91c9182ad7
54 changed files with 447 additions and 248 deletions

View File

@ -217,6 +217,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -198,6 +198,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -203,6 +203,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -226,6 +226,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -197,6 +197,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -197,6 +197,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

118
qse/configure vendored
View File

@ -667,6 +667,7 @@ SSL_LIBS
UNICOWS_LIBS
SENDFILE_LIBS
SOCKET_LIBS
QUADMATH_LIBS
LIBM
WIN32_FALSE
WIN32_TRUE
@ -17091,6 +17092,10 @@ case "$host" in
*-*-mingw*|*-*-cygwin*)
#CFLAGS="$CFLAGS -D_WIN32_WINNT=0x0400"
platform_win32=yes
;;
*)
platform_win32=no
;;
esac
if test "${platform_win32}" = "yes" ; then
WIN32_TRUE=
@ -17442,7 +17447,7 @@ fi
done
for ac_header in crt_externs.h sys/prctl.h uci.h
for ac_header in quadmath.h crt_externs.h sys/prctl.h uci.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"
@ -17661,6 +17666,117 @@ done
LIBS="$OLDLIBS"
if test "${platform_win32}" = "no"
then
for ac_func in quadmath_snprintf
do :
ac_fn_c_check_func "$LINENO" "quadmath_snprintf" "ac_cv_func_quadmath_snprintf"
if test "x$ac_cv_func_quadmath_snprintf" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_QUADMATH_SNPRINTF 1
_ACEOF
fi
done
if test "$ac_cv_func_quadmath_snprintf" = "no"
then
OLDLIBS="$LIBS"
LIBS="$LIBM $LIBS"
for ac_func in quadmath_snprintf
do :
ac_fn_c_check_func "$LINENO" "quadmath_snprintf" "ac_cv_func_quadmath_snprintf"
if test "x$ac_cv_func_quadmath_snprintf" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_QUADMATH_SNPRINTF 1
_ACEOF
fi
done
LIBS="$OLDLIBS"
if test "$ac_cv_func_quadmath_snprintf" = "no"
then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for quadmath_snprintf in -lquadmath" >&5
$as_echo_n "checking for quadmath_snprintf in -lquadmath... " >&6; }
if ${ac_cv_lib_quadmath_quadmath_snprintf+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lquadmath $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char quadmath_snprintf ();
int
main ()
{
return quadmath_snprintf ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_quadmath_quadmath_snprintf=yes
else
ac_cv_lib_quadmath_quadmath_snprintf=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_quadmath_quadmath_snprintf" >&5
$as_echo "$ac_cv_lib_quadmath_quadmath_snprintf" >&6; }
if test "x$ac_cv_lib_quadmath_quadmath_snprintf" = xyes; then :
QUADMATH_LIBS="-lquadmath"
LIBM="$LIBM -lquadmath"
$as_echo "#define HAVE_QUADMATH_SNPRINTF 1" >>confdefs.h
fi
else
QUADMATH_LIBS="$LIBM"
fi
fi
OLDLIBS="$LIBS"
LIBS="$LIBM $LIBS"
for ac_func in powq fmodq sinq cosq tanq atanq atan2q logq log10q expq sqrtq ceilq floorq roundq
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
done
for ac_func in strtoflt128
do :
ac_fn_c_check_func "$LINENO" "strtoflt128" "ac_cv_func_strtoflt128"
if test "x$ac_cv_func_strtoflt128" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_STRTOFLT128 1
_ACEOF
fi
done
LIBS="$OLDLIBS"
fi
for ac_func in connect gethostbyname
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`

View File

@ -103,6 +103,10 @@ case "$host" in
*-*-mingw*|*-*-cygwin*)
#CFLAGS="$CFLAGS -D_WIN32_WINNT=0x0400"
platform_win32=yes
;;
*)
platform_win32=no
;;
esac
AM_CONDITIONAL(WIN32, test "${platform_win32}" = "yes" )
@ -121,7 +125,7 @@ AC_CHECK_HEADERS([net/if.h net/if_dl.h], [], [], [
#include <sys/types.h>
#include <sys/socket.h>])
AC_CHECK_HEADERS([sys/stropts.h sys/macstat.h linux/ethtool.h linux/sockios.h])
AC_CHECK_HEADERS([crt_externs.h sys/prctl.h uci.h])
AC_CHECK_HEADERS([quadmath.h crt_externs.h sys/prctl.h uci.h])
dnl check data types
AC_CHECK_TYPE([wchar_t],
@ -152,6 +156,36 @@ AC_CHECK_FUNCS([pow fmod sin cos tan atan atan2 log log10 exp sqrt ceil floor ro
AC_CHECK_FUNCS([powf fmodf sinf cosf tanf atanf atan2f logf log10f expf sqrtf ceilf floorf roundf])
LIBS="$OLDLIBS"
if test "${platform_win32}" = "no"
then
AC_CHECK_FUNCS([quadmath_snprintf])
if test "$ac_cv_func_quadmath_snprintf" = "no"
then
OLDLIBS="$LIBS"
LIBS="$LIBM $LIBS"
AC_CHECK_FUNCS([quadmath_snprintf])
LIBS="$OLDLIBS"
if test "$ac_cv_func_quadmath_snprintf" = "no"
then
AC_CHECK_LIB([quadmath], [quadmath_snprintf], [
QUADMATH_LIBS="-lquadmath"
LIBM="$LIBM -lquadmath"
AC_DEFINE(HAVE_QUADMATH_SNPRINTF, 1)
])
else
QUADMATH_LIBS="$LIBM"
fi
fi
OLDLIBS="$LIBS"
LIBS="$LIBM $LIBS"
AC_CHECK_FUNCS([powq fmodq sinq cosq tanq atanq atan2q logq log10q expq sqrtq ceilq floorq roundq])
AC_CHECK_FUNCS([strtoflt128])
LIBS="$OLDLIBS"
fi
AC_SUBST(QUADMATH_LIBS)
dnl OLDLIBS="$LIBS"
dnl AC_SEARCH_LIBS([connect], [socket])
dnl LIBS="$OLDLIBS"

View File

@ -162,6 +162,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -199,6 +199,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -234,6 +234,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -1280,9 +1280,6 @@ protected:
/// @}
// primitive handlers
virtual int vsprintf (char_t* buf, size_t size,
const char_t* fmt, va_list arg) = 0;
virtual flt_t pow (flt_t x, flt_t y) = 0;
virtual flt_t mod (flt_t x, flt_t y) = 0;
virtual flt_t sin (flt_t x) = 0;
@ -1320,8 +1317,6 @@ protected:
static int functionHandler (rtx_t* rtx, const fnc_info_t* fi);
static int sprintf (awk_t* awk, char_t* buf, size_t size,
const char_t* fmt, ...);
static flt_t pow (awk_t* awk, flt_t x, flt_t y);
static flt_t mod (awk_t* awk, flt_t x, flt_t y);
static flt_t sin (awk_t* awk, flt_t x);

View File

@ -194,6 +194,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -156,9 +156,6 @@ protected:
void* reallocMem (void* ptr, size_t n);
void freeMem (void* ptr);
int vsprintf (char_t* buf, size_t size,
const char_t* fmt, va_list arg);
flt_t pow (flt_t x, flt_t y);
flt_t mod (flt_t x, flt_t y);
flt_t sin (flt_t x);

View File

@ -396,14 +396,6 @@ typedef struct qse_awk_fun_t qse_awk_fun_t;
/* ------------------------------------------------------------------------ */
typedef int (*qse_awk_sprintf_t) (
qse_awk_t* awk,
qse_char_t* buf,
qse_size_t size,
const qse_char_t* fmt,
...
);
typedef qse_flt_t (*qse_awk_math1_t) (
qse_awk_t* awk,
qse_flt_t x
@ -651,8 +643,6 @@ typedef qse_ssize_t (*qse_awk_rio_impl_t) (
*/
struct qse_awk_prm_t
{
qse_awk_sprintf_t sprintf;
struct
{
qse_awk_math2_t pow; /**< floating-point power function */

View File

@ -199,6 +199,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -23,6 +23,7 @@
#include <qse/types.h>
#include <qse/macros.h>
#include <stdarg.h>
/** \file
* This file provides various functions, types, macros for string manipulation.
@ -692,6 +693,12 @@ QSE_EXPORT qse_size_t qse_mbsfmt (
...
);
QSE_EXPORT qse_size_t qse_mbsvfmt (
qse_mchar_t* buf,
const qse_mchar_t* fmt,
va_list ap
);
/**
* The qse_mbsxfmt() function writes a formatted string into the buffer \a buf
* of the size \a bsz using the format \a fmt and the variable arguments. It
@ -714,12 +721,25 @@ QSE_EXPORT qse_size_t qse_mbsxfmt (
...
);
QSE_EXPORT qse_size_t qse_mbsxvfmt (
qse_mchar_t* buf,
qse_size_t bsz,
const qse_mchar_t* fmt,
va_list ap
);
QSE_EXPORT qse_size_t qse_wcsfmt (
qse_wchar_t* buf,
const qse_wchar_t* fmt,
...
);
QSE_EXPORT qse_size_t qse_wcsvfmt (
qse_wchar_t* buf,
const qse_wchar_t* fmt,
va_list ap
);
/**
* The qse_wcsxfmt() function writes a formatted string into the buffer \a buf
* of the size \a bsz using the format \a fmt and the variable arguments. It
@ -742,13 +762,24 @@ QSE_EXPORT qse_size_t qse_wcsxfmt (
...
);
QSE_EXPORT qse_size_t qse_wcsxvfmt (
qse_wchar_t* buf,
qse_size_t bsz,
const qse_wchar_t* fmt,
va_list ap
);
#if defined(QSE_CHAR_IS_MCHAR)
# define qse_strfmt qse_mbsfmt
# define qse_strvfmt qse_mbsvfmt
# define qse_strxfmt qse_mbsxfmt
# define qse_strxvfmt qse_mbsxvfmt
#else
# define qse_strfmt qse_wcsfmt
# define qse_strvfmt qse_wcsvfmt
# define qse_strxfmt qse_wcsxfmt
# define qse_strxvfmt qse_wcsxvfmt
#endif
/**

View File

@ -39,12 +39,18 @@
/* Define to 1 if you have the `atan2l' function. */
#undef HAVE_ATAN2L
/* Define to 1 if you have the `atan2q' function. */
#undef HAVE_ATAN2Q
/* Define to 1 if you have the `atanf' function. */
#undef HAVE_ATANF
/* Define to 1 if you have the `atanl' function. */
#undef HAVE_ATANL
/* Define to 1 if you have the `atanq' function. */
#undef HAVE_ATANQ
/* Define to 1 if you have the `backtrace' function. */
#undef HAVE_BACKTRACE
@ -60,6 +66,9 @@
/* Define to 1 if you have the `ceill' function. */
#undef HAVE_CEILL
/* Define to 1 if you have the `ceilq' function. */
#undef HAVE_CEILQ
/* Define to 1 if you have the `closedir' function. */
#undef HAVE_CLOSEDIR
@ -75,6 +84,9 @@
/* Define to 1 if you have the `cosl' function. */
#undef HAVE_COSL
/* Define to 1 if you have the `cosq' function. */
#undef HAVE_COSQ
/* Define to 1 if you have the <crt_externs.h> header file. */
#undef HAVE_CRT_EXTERNS_H
@ -131,6 +143,9 @@
/* Define to 1 if you have the `expl' function. */
#undef HAVE_EXPL
/* Define to 1 if you have the `expq' function. */
#undef HAVE_EXPQ
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
@ -146,6 +161,9 @@
/* Define to 1 if you have the `floorl' function. */
#undef HAVE_FLOORL
/* Define to 1 if you have the `floorq' function. */
#undef HAVE_FLOORQ
/* Define to 1 if you have the `fmod' function. */
#undef HAVE_FMOD
@ -155,6 +173,9 @@
/* Define to 1 if you have the `fmodl' function. */
#undef HAVE_FMODL
/* Define to 1 if you have the `fmodq' function. */
#undef HAVE_FMODQ
/* Define to 1 if you have the `fork' function. */
#undef HAVE_FORK
@ -239,12 +260,18 @@
/* Define to 1 if you have the `log10l' function. */
#undef HAVE_LOG10L
/* Define to 1 if you have the `log10q' function. */
#undef HAVE_LOG10Q
/* Define to 1 if you have the `logf' function. */
#undef HAVE_LOGF
/* Define to 1 if you have the `logl' function. */
#undef HAVE_LOGL
/* Define to 1 if you have the `logq' function. */
#undef HAVE_LOGQ
/* Define to 1 if you have the `lseek64' function. */
#undef HAVE_LSEEK64
@ -305,6 +332,9 @@
/* Define to 1 if you have the `powl' function. */
#undef HAVE_POWL
/* Define to 1 if you have the `powq' function. */
#undef HAVE_POWQ
/* Define to 1 if you have the `prctl' function. */
#undef HAVE_PRCTL
@ -317,6 +347,12 @@
/* 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
/* Define to 1 if you have the `readdir' function. */
#undef HAVE_READDIR
@ -332,6 +368,9 @@
/* Define to 1 if you have the `roundl' function. */
#undef HAVE_ROUNDL
/* Define to 1 if you have the `roundq' function. */
#undef HAVE_ROUNDQ
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
@ -368,6 +407,9 @@
/* Define to 1 if you have the `sinl' function. */
#undef HAVE_SINL
/* Define to 1 if you have the `sinq' function. */
#undef HAVE_SINQ
/* Define it socklen_t typedef is in sys/socket.h. */
#undef HAVE_SOCKLEN_T
@ -383,6 +425,9 @@
/* Define to 1 if you have the `sqrtl' function. */
#undef HAVE_SQRTL
/* Define to 1 if you have the `sqrtq' function. */
#undef HAVE_SQRTQ
/* ssl support */
#undef HAVE_SSL
@ -413,6 +458,9 @@
/* Define to 1 if you have the `strlcpy' function. */
#undef HAVE_STRLCPY
/* Define to 1 if you have the `strtoflt128' function. */
#undef HAVE_STRTOFLT128
/* Define to 1 if `d_type' is a member of `struct dirent'. */
#undef HAVE_STRUCT_DIRENT_D_TYPE
@ -523,6 +571,9 @@
/* Define to 1 if you have the `tanl' function. */
#undef HAVE_TANL
/* Define to 1 if you have the `tanq' function. */
#undef HAVE_TANQ
/* Define to 1 if you have the `timegm' function. */
#undef HAVE_TIMEGM

View File

@ -192,6 +192,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -194,6 +194,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -456,7 +456,7 @@ typedef qse_int_t qse_intptr_t;
* The qse_flt_t type defines the largest floating-pointer number type
* naturally supported.
*/
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) || defined(__MINGW32__)
/* TODO: check if the support for long double is complete.
* if so, use long double for qse_flt_t */
typedef double qse_flt_t;
@ -473,7 +473,9 @@ typedef qse_int_t qse_intptr_t;
* The qse_fltmax_t type defines the largest floating-pointer number type
* ever supported.
*/
#if QSE_SIZEOF__FLOAT128 > QSE_SIZEOF_FLT_T
#if QSE_SIZEOF___FLOAT128 >= QSE_SIZEOF_FLT_T
/* the size of long double may be equal to the size of __float128
* for alignment on some platforms */
typedef __float128 qse_fltmax_t;
# define QSE_SIZEOF_FLTMAX_T QSE_SIZEOF___FLOAT128
#else
@ -481,7 +483,6 @@ typedef qse_int_t qse_intptr_t;
# define QSE_SIZEOF_FLTMAX_T QSE_SIZEOF_FLT_T
#endif
/** @typedef qse_ptrdiff_t
*/
typedef qse_ssize_t qse_ptrdiff_t;

View File

@ -192,6 +192,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -198,6 +198,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -1110,7 +1110,6 @@ int Awk::open ()
qse_awk_prm_t prm;
QSE_MEMSET (&prm, 0, QSE_SIZEOF(prm));
prm.sprintf = sprintf;
prm.math.pow = pow;
prm.math.mod = mod;
prm.math.sin = sin;
@ -1994,18 +1993,6 @@ int Awk::functionHandler (rtx_t* rtx, const fnc_info_t* fi)
return rxtn->run->awk->dispatch_function (rxtn->run, fi);
}
int Awk::sprintf (awk_t* awk, char_t* buf, size_t size,
const char_t* fmt, ...)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);
va_list ap;
va_start (ap, fmt);
int n = xtn->awk->vsprintf (buf, size, fmt, ap);
va_end (ap);
return n;
}
Awk::flt_t Awk::pow (awk_t* awk, flt_t x, flt_t y)
{
xtn_t* xtn = (xtn_t*) QSE_XTN (awk);

View File

@ -354,6 +354,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -1163,11 +1163,6 @@ void StdAwk::freeMem (void* ptr)
}
// miscellaneous primitive
int StdAwk::vsprintf (
char_t* buf, size_t size, const char_t* fmt, va_list arg)
{
return qse_vsprintf (buf, size, fmt, arg);
}
StdAwk::flt_t StdAwk::pow (flt_t x, flt_t y)
{

View File

@ -118,7 +118,6 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_awk_prm_t* pr
/* progagate the primitive functions */
QSE_ASSERT (prm != QSE_NULL);
QSE_ASSERT (prm->sprintf != QSE_NULL);
QSE_ASSERT (prm->math.pow != QSE_NULL);
QSE_ASSERT (prm->math.sin != QSE_NULL);
QSE_ASSERT (prm->math.cos != QSE_NULL);
@ -130,7 +129,6 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_awk_prm_t* pr
QSE_ASSERT (prm->math.exp != QSE_NULL);
QSE_ASSERT (prm->math.sqrt != QSE_NULL);
if (prm == QSE_NULL ||
prm->sprintf == QSE_NULL ||
prm->math.pow == QSE_NULL ||
prm->math.sin == QSE_NULL ||
prm->math.cos == QSE_NULL ||

View File

@ -164,7 +164,7 @@ qse_long_t qse_awk_strxtolong (
/*
* qse_awk_strtoreal is almost a replica of strtod.
* qse_awk_strtoflt is almost a replica of strtod.
*
* strtod.c --
*
@ -184,7 +184,7 @@ qse_long_t qse_awk_strxtolong (
#define MAX_EXPONENT 511
qse_flt_t qse_awk_strtoreal (qse_awk_t* awk, const qse_char_t* str)
qse_flt_t qse_awk_strtoflt (qse_awk_t* awk, const qse_char_t* str)
{
/*
* Table giving binary powers of 10. Entry is 10^2^i.
@ -1383,17 +1383,3 @@ void qse_awk_rtx_freemem (qse_awk_rtx_t* rtx, void* ptr)
QSE_AWK_FREE (rtx->awk, ptr);
}
int qse_awk_sprintflt (
qse_awk_t* awk, qse_char_t* buf, qse_size_t len, qse_flt_t num)
{
return awk->prm.sprintf (
awk, buf, len,
#if QSE_SIZEOF_LONG_DOUBLE > 0
QSE_T("%Lf"), (long double)num
#elif QSE_SIZEOF_DOUBLE > 0
QSE_T("%f"), (double)num
#else
#error unsupported size
#endif
);
}

View File

@ -86,14 +86,6 @@ int qse_awk_rtx_matchrex (
qse_cstr_t* match
);
int qse_awk_sprintflt (
qse_awk_t* awk,
qse_char_t* buf,
qse_size_t len,
qse_flt_t num
);
#ifdef __cplusplus
}
#endif

View File

@ -7290,7 +7290,7 @@ wp_mod_main:
qse_flt_t r;
int n;
FMT_CHAR (QSE_T('L'));
FMT_CHAR (QSE_T('z'));
FMT_CHAR (fmt[i]);
if (args == QSE_NULL)
@ -7325,31 +7325,11 @@ wp_mod_main:
qse_awk_rtx_refdownval (rtx, v);
if (n <= -1) return QSE_NULL;
do
if (qse_str_fcat (out, QSE_STR_PTR(fbu), r) == (qse_size_t)-1)
{
n = rtx->awk->prm.sprintf (
rtx->awk,
rtx->format.tmp.ptr,
rtx->format.tmp.len,
QSE_STR_PTR(fbu),
#if defined(__MINGW32__)
(double)r
#else
(long double)r
#endif
);
if (n == -1)
{
GROW (&rtx->format.tmp);
continue;
}
break;
SETERR_COD (rtx, QSE_AWK_ENOMEM);
return QSE_NULL;
}
while (1);
OUT_STR (rtx->format.tmp.ptr, n);
}
else if (fmt[i] == QSE_T('c'))
{

View File

@ -30,12 +30,14 @@
#include <qse/cmn/htb.h>
#include <qse/cmn/env.h>
#include <qse/cmn/alg.h>
#include <qse/cmn/stdio.h> /* TODO: remove dependency on qse_vsprintf */
#include "../cmn/mem.h"
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
#if defined(HAVE_QUADMATH_H)
# include <quadmath.h>
#endif
#if defined(_WIN32)
# include <windows.h>
@ -299,20 +301,6 @@ static qse_flt_t custom_awk_sqrt (qse_awk_t* awk, qse_flt_t x)
#endif
}
static int custom_awk_sprintf (
qse_awk_t* awk, qse_char_t* buf, qse_size_t size,
const qse_char_t* fmt, ...)
{
int n;
va_list ap;
va_start (ap, fmt);
n = qse_vsprintf (buf, size, fmt, ap);
va_end (ap);
return n;
}
static void* custom_awk_modopen (qse_awk_t* awk, const qse_awk_mod_spec_t* spec)
{
#if defined(QSE_ENABLE_STATIC_MODULE)
@ -541,8 +529,6 @@ qse_awk_t* qse_awk_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize)
qse_awk_prm_t prm;
xtn_t* xtn;
prm.sprintf = custom_awk_sprintf;
prm.math.pow = custom_awk_pow;
prm.math.mod = custom_awk_mod;
prm.math.sin = custom_awk_sin;

View File

@ -341,10 +341,14 @@ static int print_expr (qse_awk_t* awk, qse_awk_nde_t* nde)
}
else
{
qse_char_t buf[64];
qse_awk_sprintflt (
awk, buf, QSE_COUNTOF(buf),
((qse_awk_nde_flt_t*)nde)->val);
qse_char_t buf[96];
qse_strxfmt (
buf, QSE_COUNTOF(buf),
QSE_T("%zf"),
((qse_awk_nde_flt_t*)nde)->val
);
PUT_SRCSTR (awk, buf);
}
break;

View File

@ -126,9 +126,8 @@ if ENABLE_XCMGRS
libqsecmn_la_SOURCES += cp949.c cp950.c
endif
libqsecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined
libqsecmn_la_LIBADD = $(SOCKET_LIBS)
libqsecmn_la_LIBADD = $(SOCKET_LIBS) $(QUADMATH_LIBS)
if ENABLE_CXX

View File

@ -84,7 +84,8 @@ am__uninstall_files_from_dir = { \
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
libqsecmn_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
libqsecmn_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1)
am__libqsecmn_la_SOURCES_DIST = alg-base64.c alg-rand.c alg-search.c \
alg-sort.c assert.c chr.c dir.c dll.c env.c gdl.c htb.c fio.c \
fma.c fmt-intmax.c fmt-out.c fs.c fs-err.c fs-move.c glob.c \
@ -286,6 +287,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@
@ -402,7 +404,7 @@ libqsecmn_la_SOURCES = alg-base64.c alg-rand.c alg-search.c alg-sort.c \
tre-match-parallel.c tre-parse.c tre-stack.c uri.c utf8.c \
xma.c $(am__append_1) $(am__append_2)
libqsecmn_la_LDFLAGS = -version-info 1:0:0 -no-undefined
libqsecmn_la_LIBADD = $(SOCKET_LIBS)
libqsecmn_la_LIBADD = $(SOCKET_LIBS) $(QUADMATH_LIBS)
@ENABLE_CXX_TRUE@libqsecmnxx_la_SOURCES = \
@ENABLE_CXX_TRUE@ Mmgr.cpp StdMmgr.cpp

View File

@ -30,7 +30,10 @@
#if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
# define snprintf _snprintf
#endif
/* TODO: remove stdio.h once snprintf gets replaced by own
#if defined(HAVE_QUADMATH_H)
# include <quadmath.h> /* for quadmath_snprintf */
#endif
/* TODO: remove stdio.h and quadmath.h once snprintf gets replaced by own
floting-point conversion implementation*/
/* number of bits in a byte */
@ -52,7 +55,9 @@ enum
LF_Z = (1 << 6),
/* long double */
LF_LD = (1 << 7)
LF_LD = (1 << 7),
/* __float128 */
LF_QD = (1 << 8)
};
static struct
@ -93,9 +98,9 @@ static struct
enum
{
FLAGC_DOT = (1 << 0),
FLAGC_SHARP = (1 << 1),
FLAGC_SIGN = (1 << 2),
FLAGC_SPACE = (1 << 3),
FLAGC_SPACE = (1 << 1),
FLAGC_SHARP = (1 << 2),
FLAGC_SIGN = (1 << 3),
FLAGC_LEFTADJ = (1 << 4),
FLAGC_ZEROPAD = (1 << 5),
FLAGC_WIDTH = (1 << 6),

View File

@ -264,7 +264,7 @@ reswitch:
case T('j'): /* uintmax_t */
case T('z'): /* size_t */
case T('t'): /* ptrdiff_t */
if (lm_flag & LF_LD) goto invalid_format;
if (lm_flag & (LF_LD | LF_QD)) goto invalid_format;
flagc |= FLAGC_LENMOD;
if (lm_dflag)
@ -297,12 +297,23 @@ reswitch:
case T('L'): /* long double */
if (flagc & FLAGC_LENMOD)
{
/* conflict integral length modifier */
/* conflict with other length modifier */
goto invalid_format;
}
flagc |= FLAGC_LENMOD;
lm_flag |= LF_LD;
goto reswitch;
case T('Q'): /* __float128 */
if (flagc & FLAGC_LENMOD)
{
/* conflict with other length modifier */
goto invalid_format;
}
flagc |= FLAGC_LENMOD;
lm_flag |= LF_QD;
goto reswitch;
/* end of length modifiers */
case T('n'):
@ -320,6 +331,8 @@ reswitch:
*(va_arg(ap, short int*)) = data->count;
else if (lm_flag & LF_C) /* hh */
*(va_arg(ap, char*)) = data->count;
else if (flagc & FLAGC_LENMOD)
goto oops;
else
*(va_arg(ap, int*)) = data->count;
break;
@ -531,20 +544,62 @@ reswitch:
case T('A'):
*/
{
/* 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;
qse_size_t fmtlen;
qse_fltmax_t v_fltmax;
#if (QSE_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
__float128 v_qd;
#endif
long double v_ld;
double v_d;
int dtype = 0;
if (lm_flag & LF_J)
v_fltmax = va_arg (ap, qse_fltmax_t);
else if (lm_flag & (LF_LD | LF_L | LF_Q | LF_Z))
{
#if (QSE_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) && (QSE_SIZEOF_FLTMAX_T == QSE_SIZEOF___FLOAT128)
v_qd = va_arg (ap, qse_fltmax_t);
dtype = LF_QD;
#elif QSE_SIZEOF_FLTMAX_T == QSE_SIZEOF_LONG_DOUBLE
v_ld = va_arg (ap, qse_fltmax_t);
dtype = LF_LD;
#elif QSE_SIZEOF_FLTMAX_T == QSE_SIZEOF_DOUBLE
v_d = va_arg (ap, qse_fltmax_t);
#else
#error Unsupported qse_flt_t
#endif
}
else if (lm_flag & LF_Z)
{
/* qse_flt_t is limited to double or long double */
#if QSE_SIZEOF_FLT_T == QSE_SIZEOF_LONG_DOUBLE
v_ld = va_arg (ap, qse_flt_t);
dtype = LF_LD;
#elif QSE_SIZEOF_FLT_T == QSE_SIZEOF_DOUBLE
v_d = va_arg (ap, qse_flt_t);
#else
#error Unsupported qse_flt_t
#endif
}
else if (lm_flag & (LF_LD | LF_L))
{
v_ld = va_arg (ap, long double);
dtype = LF_LD;
}
#if (QSE_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
else if (lm_flag & (LF_QD | LF_Q))
{
v_qd = va_arg (ap, __float128);
dtype = LF_QD;
}
#endif
else if (flagc & FLAGC_LENMOD)
{
goto oops;
}
else
{
v_d = va_arg (ap, double);
}
fmtlen = fmt - percent;
if (fmtlen > fltfmt.capa)
@ -566,27 +621,59 @@ reswitch:
fltfmt.capa = fmtlen;
}
fltfmt.ptr[fmtlen] = QSE_MT('\0');
while (fmtlen > 0)
/* compose back the format specifier */
fmtlen = 0;
fltfmt.ptr[fmtlen++] = QSE_MT('%');
if (flagc & FLAGC_SPACE) fltfmt.ptr[fmtlen++] = QSE_T(' ');
if (flagc & FLAGC_SHARP) fltfmt.ptr[fmtlen++] = QSE_T('#');
if (flagc & FLAGC_SIGN) fltfmt.ptr[fmtlen++] = QSE_T('+');
if (flagc & FLAGC_LEFTADJ) fltfmt.ptr[fmtlen++] = QSE_T('-');
if (flagc & FLAGC_ZEROPAD) fltfmt.ptr[fmtlen++] = QSE_T('0');
if (flagc & FLAGC_STAR1) fltfmt.ptr[fmtlen++] = QSE_T('*');
else if (flagc & FLAGC_WIDTH)
{
fmtlen--;
fltfmt.ptr[fmtlen] = percent[fmtlen];
fmtlen += qse_fmtuintmaxtombs (
&fltfmt.ptr[fmtlen], fltfmt.capa - fmtlen,
width, 10, -1, QSE_MT('\0'), QSE_NULL);
}
if (flagc & FLAGC_DOT) fltfmt.ptr[fmtlen++] = QSE_T('.');
if (flagc & FLAGC_STAR2) fltfmt.ptr[fmtlen++] = QSE_T('*');
else if (flagc & FLAGC_PRECISION)
{
fmtlen += qse_fmtuintmaxtombs (
&fltfmt.ptr[fmtlen], fltfmt.capa - fmtlen,
precision, 10, -1, QSE_MT('\0'), QSE_NULL);
}
if (dtype == LF_LD)
fltfmt.ptr[fmtlen++] = QSE_MT('L');
#if (QSE_SIZEOF___FLOAT128 > 0)
else if (dtype == LF_QD)
fltfmt.ptr[fmtlen++] = QSE_MT('Q');
#endif
fltfmt.ptr[fmtlen++] = ch;
fltfmt.ptr[fmtlen] = QSE_MT('\0');
while (1)
{
qse_size_t newcapa;
if (lm_flag & LF_J)
q = snprintf ((qse_mchar_t*)fltout.ptr, fltout.capa + 1, fltfmt.ptr, v_fltmax);
else if (lm_flag & (LF_LD | LF_L | LF_Q | LF_Z))
if (dtype == LF_LD)
q = snprintf ((qse_mchar_t*)fltout.ptr, fltout.capa + 1, fltfmt.ptr, v_ld);
#if (QSE_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF)
else if (dtype == LF_QD)
q = quadmath_snprintf ((qse_mchar_t*)fltout.ptr, fltout.capa + 1, fltfmt.ptr, v_qd);
#endif
else
q = snprintf ((qse_mchar_t*)fltout.ptr, fltout.capa + 1, fltfmt.ptr, v_d);
if (q <= -1) goto oops;
if (q <= fltout.capa) break;
newcapa = fltout.capa * 2;
if (newcapa < q) newcapa = q;
if (fltout.ptr == fltout.sbuf)
{
fltout.ptr = QSE_MMGR_ALLOC (QSE_MMGR_GETDFL(), QSE_SIZEOF(char_t) * (newcapa + 1));

View File

@ -53,7 +53,7 @@ static int put_mchar_nocheck (qse_mchar_t c, void* ctx)
return 1;
}
static int put_wchar_nocheck (qse_wchar_t* c, void* ctx)
static int put_wchar_nocheck (qse_wchar_t c, void* ctx)
{
qse_wcs_t* str = (qse_wcs_t*)ctx;
str->val.ptr[str->val.len++] = c;

View File

@ -425,8 +425,6 @@ qse_size_t str_pac (str_t* str)
return str->val.len;
}
qse_size_t str_vfcat (str_t* str, const char_t* fmt, va_list ap)
{
va_list orgap;
@ -471,50 +469,6 @@ qse_size_t str_vfcat (str_t* str, const char_t* fmt, va_list ap)
qse_size_t str_fcat (str_t* str, const char_t* fmt, ...)
{
#if 0
va_list ap;
fmtout_t fo;
int x;
qse_size_t old_len, inc;
old_len = str->val.len;
fo.limit = QSE_TYPE_MAX(qse_size_t) - 1;
fo.ctx = str;
fo.put = str->val.ptr? put_char: put_char_null;
fo.conv = conv_char;
va_start (ap, fmt);
x = fmtout (fmt, &fo, ap);
va_end (ap);
if (x <= -1)
{
str->val.len = old_len;
return (qse_size_t)-1;
}
if (str->val.ptr == QSE_NULL || str->val.len - old_len < fo.count)
{
str->val.len = old_len;
/* resizing is required */
x = resize_for_ncat (str, fo.count);
if (x <= -1) return (qse_size_t)-1;
if (x >= 1)
{
fo.put = put_char;
va_start (ap, fmt);
x = fmtout (fmt, &fo, ap);
va_end (ap);
}
}
str->val.ptr[str->val.len] = T('\0');
return str->val.len;
#endif
qse_size_t x;
va_list ap;

View File

@ -103,6 +103,8 @@ static int mbs_to_wcs (
#undef conv_char
#undef strfmt
#undef strxfmt
#undef strvfmt
#undef strxvfmt
#define T(x) QSE_MT(x)
#define char_t qse_mchar_t
@ -114,6 +116,8 @@ static int mbs_to_wcs (
#define conv_char wcs_to_mbs
#define strfmt qse_mbsfmt
#define strxfmt qse_mbsxfmt
#define strvfmt qse_mbsvfmt
#define strxvfmt qse_mbsxvfmt
#include "str-fmt.h"
/* ----------------------------------- */
@ -128,6 +132,8 @@ static int mbs_to_wcs (
#undef conv_char
#undef strfmt
#undef strxfmt
#undef strvfmt
#undef strxvfmt
#define T(x) QSE_WT(x)
#define char_t qse_wchar_t
@ -139,5 +145,7 @@ static int mbs_to_wcs (
#define conv_char mbs_to_wcs
#define strfmt qse_wcsfmt
#define strxfmt qse_wcsxfmt
#define strvfmt qse_wcsvfmt
#define strxvfmt qse_wcsxvfmt
#include "str-fmt.h"

View File

@ -19,10 +19,9 @@
*/
qse_size_t strfmt (char_t* buf, const char_t* fmt, ...)
qse_size_t strvfmt (char_t* buf, const char_t* fmt, va_list ap)
{
buf_t b;
va_list ap;
fmtout_t fo;
int x;
@ -37,9 +36,7 @@ qse_size_t strfmt (char_t* buf, const char_t* fmt, ...)
/* no I/O error must occurred by fmtout but there can be
* encoding conversion error by fmtout */
va_start (ap, fmt);
x = fmtout (fmt, &fo, ap);
va_end (ap);
/* fmtout must produce no I/O error but it can produce
* an encoding conversion error. if you didn't use a conversion
@ -57,10 +54,21 @@ qse_size_t strfmt (char_t* buf, const char_t* fmt, ...)
return fo.count;
}
qse_size_t strxfmt (char_t* buf, qse_size_t len, const char_t* fmt, ...)
qse_size_t strfmt (char_t* buf, const char_t* fmt, ...)
{
qse_size_t x;
va_list ap;
va_start (ap, fmt);
x = strvfmt (buf, fmt, ap);
va_end (ap);
return x;
}
qse_size_t strxvfmt (char_t* buf, qse_size_t len, const char_t* fmt, va_list ap)
{
buf_t b;
va_list ap;
fmtout_t fo;
int x;
@ -79,9 +87,7 @@ qse_size_t strxfmt (char_t* buf, qse_size_t len, const char_t* fmt, ...)
fo.put = b.ptr? put_char: put_char_null;
fo.conv = conv_char;
va_start (ap, fmt);
x = fmtout (fmt, &fo, ap);
va_end (ap);
/* fmtout must produce no I/O error but it can produce
* an encoding conversion error. if you didn't use a conversion
@ -99,3 +105,14 @@ qse_size_t strxfmt (char_t* buf, qse_size_t len, const char_t* fmt, ...)
return fo.count;
}
qse_size_t strxfmt (char_t* buf, qse_size_t len, const char_t* fmt, ...)
{
qse_size_t x;
va_list ap;
va_start (ap, fmt);
x = strxvfmt (buf, len, fmt, ap);
va_end (ap);
return x;
}

View File

@ -225,6 +225,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -20,13 +20,8 @@
#include "httpd.h"
#include <qse/cmn/str.h>
#include <qse/cmn/fmt.h>
#include "../cmn/mem.h"
#include <stdarg.h>
#include <stdio.h> /* TODO: remove this */
/* TODO:
* many functions in this file use qse_size_t.
* so the size data transfers is limited by this type.
@ -115,61 +110,27 @@ qse_httpd_task_t* qse_httpd_entaskformat (
task_format_t data;
va_list ap;
qse_mchar_t n[2];
qse_mchar_t* buf;
int bytes_req, l;
va_start (ap, fmt);
bytes_req = vsnprintf (n, 1, fmt, ap);
bytes_req = qse_mbsxvfmt (QSE_NULL, 0, fmt, ap);
va_end (ap);
if (bytes_req == -1)
buf = (qse_mchar_t*) qse_httpd_allocmem (
httpd, (bytes_req + 1) * QSE_SIZEOF(*buf));
if (buf == QSE_NULL) return QSE_NULL;
va_start (ap, fmt);
l = qse_mbsxvfmt (buf, bytes_req + 1, fmt, ap);
va_end (ap);
if (l != bytes_req)
{
qse_size_t capa = 256;
buf = (qse_mchar_t*) qse_httpd_allocmem (
httpd, (capa + 1) * QSE_SIZEOF(*buf));
if (buf == QSE_NULL) return QSE_NULL;
/* an old vsnprintf behaves differently from C99 standard.
* thus, it returns -1 when it can't write all the input given. */
for (;;)
{
va_start (ap, fmt);
l = vsnprintf (buf, capa + 1, fmt, ap);
va_end (ap);
if (l == -1)
{
qse_httpd_freemem (httpd, buf);
capa = capa * 2;
buf = (qse_mchar_t*) qse_httpd_allocmem (httpd, (capa + 1) * QSE_SIZEOF(*buf));
if (buf == QSE_NULL) return QSE_NULL;
}
else break;
}
}
else
{
/* vsnprintf returns the number of characters that would
* have been written not including the terminating '\0'
* if the _data buffer were large enough */
buf = (qse_mchar_t*) qse_httpd_allocmem (
httpd, (bytes_req + 1) * QSE_SIZEOF(*buf));
if (buf == QSE_NULL) return QSE_NULL;
va_start (ap, fmt);
l = vsnprintf (buf, bytes_req + 1, fmt, ap);
va_end (ap);
if (l != bytes_req)
{
/* something got wrong ... */
qse_httpd_freemem (httpd, buf);
httpd->errnum = QSE_HTTPD_EINTERN;
return QSE_NULL;
}
/* something got wrong ... */
qse_httpd_freemem (httpd, buf);
httpd->errnum = QSE_HTTPD_EINTERN;
return QSE_NULL;
}
QSE_MEMSET (&data, 0, QSE_SIZEOF(data));

View File

@ -107,11 +107,6 @@ struct qse_httpd_real_task_t
#define CLIENT_HANDLE_IN_MUX (CLIENT_HANDLE_READ_IN_MUX|CLIENT_HANDLE_WRITE_IN_MUX)
#define CLIENT_TASK_TRIGGER_IN_MUX(i) (1 << ((i) + 8))
#if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
# define snprintf _snprintf
# define vsnprintf _vsnprintf
#endif
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -247,6 +247,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -220,6 +220,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -199,6 +199,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -162,6 +162,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -164,6 +164,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -199,6 +199,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -322,6 +322,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -373,6 +373,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -204,6 +204,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -233,6 +233,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@

View File

@ -161,6 +161,7 @@ QSE_SIZEOF_OFF_T = @QSE_SIZEOF_OFF_T@
QSE_SIZEOF_SHORT = @QSE_SIZEOF_SHORT@
QSE_SIZEOF_VOID_P = @QSE_SIZEOF_VOID_P@
QSE_SIZEOF_WCHAR_T = @QSE_SIZEOF_WCHAR_T@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@