Skip to content
Browse files

applied a trio update patch from Bjorn Reese which should work with M…

…inGW

* trio.c trio.h triodef.h trionan.c trionan.h triop.h
  triostr.c triostr.h: applied a trio update patch from
  Bjorn Reese which should work with MinGW
Daniel
  • Loading branch information...
1 parent bd9afb5 commit b7c29c38f507ac62cc85df9b897762fc84f05a68 Daniel Veillard committed Sep 25, 2002
Showing with 2,744 additions and 1,357 deletions.
  1. +6 −0 ChangeLog
  2. +1 −1 doc/FAQ.html
  3. +2 −3 doc/downloads.html
  4. +1,779 −812 trio.c
  5. +76 −57 trio.h
  6. +59 −9 triodef.h
  7. +120 −65 trionan.c
  8. +14 −9 trionan.h
  9. +60 −53 triop.h
  10. +551 −280 triostr.c
  11. +76 −68 triostr.h
View
6 ChangeLog
@@ -1,3 +1,9 @@
+Thu Sep 26 00:31:46 CEST 2002 Daniel Veillard <daniel@veillard.com>
+
+ * trio.c trio.h triodef.h trionan.c trionan.h triop.h
+ triostr.c triostr.h: applied a trio update patch from
+ Bjorn Reese which should work with MinGW
+
Thu Sep 26 00:21:18 CEST 2002 Daniel Veillard <daniel@veillard.com>
* tree.c: improving some documentation comments
View
2 doc/FAQ.html
@@ -119,7 +119,7 @@
Not Use libxml1</span></strong>, use libxml2</li>
<li>
<em>Where can I get libxml</em> ?
- <p>The original distribution comes from <a href="ftp://rpmfind.net/pub/libxml/">rpmfind.net</a> or <a href="ftp://ftp.gnome.org/pub/GNOME/stable/sources/libxml/">gnome.org</a>
+ <p>The original distribution comes from <a href="ftp://rpmfind.net/pub/libxml/">rpmfind.net</a> or <a href="ftp://ftp.gnome.org/pub/GNOME/sources/libxml2/2.4/">gnome.org</a>
</p>
<p>Most Linux and BSD distributions include libxml, this is probably the
safer way for end-users to use libxml.</p>
View
5 doc/downloads.html
@@ -89,9 +89,8 @@
</td></tr></table></td>
<td valign="top" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%"><tr><td><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table border="0" cellpadding="3" cellspacing="1" width="100%"><tr><td bgcolor="#fffacd">
<p>The latest versions of libxml can be found on <a href="ftp://xmlsoft.org/">xmlsoft.org</a> (<a href="ftp://speakeasy.rpmfind.net/pub/libxml/">Seattle</a>, <a href="ftp://fr.rpmfind.net/pub/libxml/">France</a>) or on the <a href="ftp://ftp.gnome.org/pub/GNOME/MIRRORS.html">Gnome FTP server</a> either
-as a <a href="ftp://ftp.gnome.org/pub/GNOME/stable/sources/libxml/">source
-archive</a> or <a href="ftp://ftp.gnome.org/pub/GNOME/stable/redhat/i386/libxml/">RPM
-packages</a>, Antonin Sprinzl also provide <a href="ftp://gd.tuwien.ac.at/pub/libxml/">a mirror in Austria</a>. (NOTE that
+as a <a href="ftp://ftp.gnome.org/pub/GNOME/sources/libxml2/2.4/">source
+archive</a>, Antonin Sprinzl also provide <a href="ftp://gd.tuwien.ac.at/pub/libxml/">a mirror in Austria</a>. (NOTE that
you need both the <a href="http://rpmfind.net/linux/RPM/libxml2.html">libxml(2)</a> and <a href="http://rpmfind.net/linux/RPM/libxml2-devel.html">libxml(2)-devel</a>
packages installed to compile applications using libxml.) <a href="mailto:igor@stud.fh-frankfurt.de">Igor Zlatkovic</a> is now the
maintainer of the Windows port, <a href="http://www.fh-frankfurt.de/~igor/projects/libxml/index.html">he
View
2,591 trio.c
1,779 additions, 812 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
133 trio.h
@@ -23,8 +23,14 @@
#define TRIO_TRIO_H
#include <stdio.h>
-#include <stdarg.h>
#include <stdlib.h>
+#if defined(TRIO_COMPILER_ANCIENT)
+# include <varargs.h>
+#else
+# include <stdarg.h>
+#endif
+
+#if !defined(WITHOUT_TRIO)
/*
* Use autoconf defines if present. Packages using trio must define
@@ -34,22 +40,12 @@
# include <config.h>
#endif
-#if !defined(WITHOUT_TRIO)
+#include "triodef.h"
#ifdef __cplusplus
extern "C" {
#endif
-/* make utility and C++ compiler in Windows NT fails to find this symbol */
-#if defined(WIN32) && !defined(isascii)
-# define isascii ((unsigned)(x) < 0x80)
-#endif
-
-/* Error macros */
-#define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
-#define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
-#define TRIO_ERROR_NAME(x) trio_strerror(x)
-
/*
* Error codes.
*
@@ -63,72 +59,95 @@ enum {
TRIO_EGAP = 5,
TRIO_ENOMEM = 6,
TRIO_ERANGE = 7,
- TRIO_ERRNO = 8
+ TRIO_ERRNO = 8,
+ TRIO_ECUSTOM = 9
};
-const char *trio_strerror(int);
+/* Error macros */
+#define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
+#define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
+#define TRIO_ERROR_NAME(x) trio_strerror(x)
+
+typedef int (*trio_outstream_t) TRIO_PROTO((trio_pointer_t, int));
+typedef int (*trio_instream_t) TRIO_PROTO((trio_pointer_t));
+
+TRIO_CONST char *trio_strerror TRIO_PROTO((int));
/*************************************************************************
* Print Functions
*/
-int trio_printf(const char *format, ...);
-int trio_vprintf(const char *format, va_list args);
-int trio_printfv(const char *format, void **args);
+int trio_printf TRIO_PROTO((TRIO_CONST char *format, ...));
+int trio_vprintf TRIO_PROTO((TRIO_CONST char *format, va_list args));
+int trio_printfv TRIO_PROTO((TRIO_CONST char *format, void **args));
-int trio_fprintf(FILE *file, const char *format, ...);
-int trio_vfprintf(FILE *file, const char *format, va_list args);
-int trio_fprintfv(FILE *file, const char *format, void **args);
+int trio_fprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...));
+int trio_vfprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args));
+int trio_fprintfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args));
-int trio_dprintf(int fd, const char *format, ...);
-int trio_vdprintf(int fd, const char *format, va_list args);
-int trio_dprintfv(int fd, const char *format, void **args);
+int trio_dprintf TRIO_PROTO((int fd, TRIO_CONST char *format, ...));
+int trio_vdprintf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args));
+int trio_dprintfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args));
-/* trio_sprintf(target, format, ...)
- * trio_snprintf(target, maxsize, format, ...)
- *
- * Build 'target' according to 'format' and succesive
- * arguments. This is equal to the sprintf() and
- * snprintf() functions.
- */
-int trio_sprintf(char *buffer, const char *format, ...);
-int trio_vsprintf(char *buffer, const char *format, va_list args);
-int trio_sprintfv(char *buffer, const char *format, void **args);
+int trio_cprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
+ TRIO_CONST char *format, ...));
+int trio_vcprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
+ TRIO_CONST char *format, va_list args));
+int trio_cprintfv TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
+ TRIO_CONST char *format, void **args));
+
+int trio_sprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, ...));
+int trio_vsprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, va_list args));
+int trio_sprintfv TRIO_PROTO((char *buffer, TRIO_CONST char *format, void **args));
-int trio_snprintf(char *buffer, size_t max, const char *format, ...);
-int trio_vsnprintf(char *buffer, size_t bufferSize, const char *format,
- va_list args);
-int trio_snprintfv(char *buffer, size_t bufferSize, const char *format,
- void **args);
+int trio_snprintf TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...));
+int trio_vsnprintf TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
+ va_list args));
+int trio_snprintfv TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
+ void **args));
-int trio_snprintfcat(char *buffer, size_t max, const char *format, ...);
-int trio_vsnprintfcat(char *buffer, size_t bufferSize, const char *format,
- va_list args);
+int trio_snprintfcat TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...));
+int trio_vsnprintfcat TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
+ va_list args));
-char *trio_aprintf(const char *format, ...);
-char *trio_vaprintf(const char *format, va_list args);
+char *trio_aprintf TRIO_PROTO((TRIO_CONST char *format, ...));
+char *trio_vaprintf TRIO_PROTO((TRIO_CONST char *format, va_list args));
-int trio_asprintf(char **ret, const char *format, ...);
-int trio_vasprintf(char **ret, const char *format, va_list args);
+int trio_asprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, ...));
+int trio_vasprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, va_list args));
/*************************************************************************
* Scan Functions
*/
-int trio_scanf(const char *format, ...);
-int trio_vscanf(const char *format, va_list args);
-int trio_scanfv(const char *format, void **args);
+int trio_scanf TRIO_PROTO((TRIO_CONST char *format, ...));
+int trio_vscanf TRIO_PROTO((TRIO_CONST char *format, va_list args));
+int trio_scanfv TRIO_PROTO((TRIO_CONST char *format, void **args));
+
+int trio_fscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...));
+int trio_vfscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args));
+int trio_fscanfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args));
-int trio_fscanf(FILE *file, const char *format, ...);
-int trio_vfscanf(FILE *file, const char *format, va_list args);
-int trio_fscanfv(FILE *file, const char *format, void **args);
+int trio_dscanf TRIO_PROTO((int fd, TRIO_CONST char *format, ...));
+int trio_vdscanf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args));
+int trio_dscanfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args));
-int trio_dscanf(int fd, const char *format, ...);
-int trio_vdscanf(int fd, const char *format, va_list args);
-int trio_dscanfv(int fd, const char *format, void **args);
+int trio_cscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
+ TRIO_CONST char *format, ...));
+int trio_vcscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
+ TRIO_CONST char *format, va_list args));
+int trio_cscanfv TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
+ TRIO_CONST char *format, void **args));
-int trio_sscanf(const char *buffer, const char *format, ...);
-int trio_vsscanf(const char *buffer, const char *format, va_list args);
-int trio_sscanfv(const char *buffer, const char *format, void **args);
+int trio_sscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, ...));
+int trio_vsscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, va_list args));
+int trio_sscanfv TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, void **args));
+
+/*************************************************************************
+ * Locale Functions
+ */
+void trio_locale_set_decimal_point TRIO_PROTO((char *decimalPoint));
+void trio_locale_set_thousand_separator TRIO_PROTO((char *thousandSeparator));
+void trio_locale_set_grouping TRIO_PROTO((char *grouping));
/*************************************************************************
* Renaming
View
68 triodef.h
@@ -34,8 +34,12 @@
# define TRIO_COMPILER_XLC /* Workaround for old xlc */
#elif defined(__DECC) || defined(__DECCXX)
# define TRIO_COMPILER_DECC
+#elif defined(__osf__) && defined(__LANGUAGE_C__)
+# define TRIO_COMPILER_DECC /* Workaround for old DEC C compilers */
#elif defined(_MSC_VER)
# define TRIO_COMPILER_MSVC
+#elif defined(__BORLANDC__)
+# define TRIO_COMPILER_BCB
#endif
#if defined(unix) || defined(__unix) || defined(__unix__)
@@ -61,9 +65,10 @@
# define TRIO_PLATFORM_MPEIX
#endif
-#if defined(__STDC__)
-# define TRIO_COMPILER_SUPPORTS_C90
+#if defined(__STDC__) || defined(TRIO_COMPILER_MSVC)
+# define TRIO_COMPILER_SUPPORTS_C89
# if defined(__STDC_VERSION__)
+# define TRIO_COMPILER_SUPPORTS_C90
# if (__STDC_VERSION__ >= 199409L)
# define TRIO_COMPILER_SUPPORTS_C94
# endif
@@ -84,6 +89,9 @@
# if (_XOPEN_VERSION >= 500)
# define TRIO_COMPILER_SUPPORTS_UNIX98
# endif
+# if (_XOPEN_VERSION >= 600)
+# define TRIO_COMPILER_SUPPORTS_UNIX01
+# endif
#endif
/*************************************************************************
@@ -97,22 +105,64 @@
# define TRIO_PRIVATE static
#endif
-#if defined(TRIO_COMPILER_SUPPORTS_C90) || defined(__cplusplus)
-# define TRIO_CONST const
-# define TRIO_VOLATILE volatile
-# define TRIO_POINTER void *
-# define TRIO_PROTO(x) x
-#else
+#if !(defined(TRIO_COMPILER_SUPPORTS_C89) || defined(__cplusplus))
+# define TRIO_COMPILER_ANCIENT
+#endif
+
+#if defined(TRIO_COMPILER_ANCIENT)
# define TRIO_CONST
# define TRIO_VOLATILE
-# define TRIO_POINTER char *
+# define TRIO_SIGNED
+typedef double trio_long_double_t;
+typedef char * trio_pointer_t;
+# define TRIO_SUFFIX_LONG(x) x
# define TRIO_PROTO(x) ()
+# define TRIO_NOARGS
+# define TRIO_ARGS1(list,a1) list a1;
+# define TRIO_ARGS2(list,a1,a2) list a1; a2;
+# define TRIO_ARGS3(list,a1,a2,a3) list a1; a2; a3;
+# define TRIO_ARGS4(list,a1,a2,a3,a4) list a1; a2; a3; a4;
+# define TRIO_ARGS5(list,a1,a2,a3,a4,a5) list a1; a2; a3; a4; a5;
+# define TRIO_ARGS6(list,a1,a2,a3,a4,a5,a6) list a1; a2; a3; a4; a5; a6;
+# define TRIO_VARGS2(list,a1,a2) list a1; a2
+# define TRIO_VARGS3(list,a1,a2,a3) list a1; a2; a3
+# define TRIO_VARGS4(list,a1,a2,a3,a4) list a1; a2; a3; a4
+# define TRIO_VARGS5(list,a1,a2,a3,a4,a5) list a1; a2; a3; a4; a5
+# define TRIO_VA_DECL va_dcl
+# define TRIO_VA_START(x,y) va_start((x))
+# define TRIO_VA_END(x) va_end(x)
+#else /* ANSI C */
+# define TRIO_CONST const
+# define TRIO_VOLATILE volatile
+# define TRIO_SIGNED signed
+typedef long double trio_long_double_t;
+typedef void * trio_pointer_t;
+# define TRIO_SUFFIX_LONG(x) x ## L
+# define TRIO_PROTO(x) x
+# define TRIO_NOARGS void
+# define TRIO_ARGS1(list,a1) (a1)
+# define TRIO_ARGS2(list,a1,a2) (a1,a2)
+# define TRIO_ARGS3(list,a1,a2,a3) (a1,a2,a3)
+# define TRIO_ARGS4(list,a1,a2,a3,a4) (a1,a2,a3,a4)
+# define TRIO_ARGS5(list,a1,a2,a3,a4,a5) (a1,a2,a3,a4,a5)
+# define TRIO_ARGS6(list,a1,a2,a3,a4,a5,a6) (a1,a2,a3,a4,a5,a6)
+# define TRIO_VARGS2 TRIO_ARGS2
+# define TRIO_VARGS3 TRIO_ARGS3
+# define TRIO_VARGS4 TRIO_ARGS4
+# define TRIO_VARGS5 TRIO_ARGS5
+# define TRIO_VA_DECL ...
+# define TRIO_VA_START(x,y) va_start((x),(y))
+# define TRIO_VA_END(x) va_end(x)
#endif
#if defined(TRIO_COMPILER_SUPPORTS_C99) || defined(__cplusplus)
# define TRIO_INLINE inline
#elif defined(TRIO_COMPILER_GCC)
# define TRIO_INLINE __inline__
+#elif defined(TRIO_COMPILER_MSVC)
+# define TRIO_INLINE _inline
+#elif defined(TRIO_COMPILER_BCB)
+# define TRIO_INLINE __inline
#else
# define TRIO_INLINE
#endif
View
185 trionan.c
@@ -29,40 +29,13 @@
* 2. Use IEEE 754 bit-patterns if possible.
* 3. Use platform-specific techniques.
*
- * This program has been tested on the following platforms (in
- * alphabetic order)
- *
- * OS CPU Compiler
- * -------------------------------------------------
- * AIX 4.1.4 PowerPC gcc
- * Darwin 1.3.7 PowerPC gcc
- * FreeBSD 2.2 x86 gcc
- * FreeBSD 3.3 x86 gcc
- * FreeBSD 4.3 x86 gcc
- * FreeBSD 4.3 Alpha gcc
- * HP-UX 10.20 PA-RISC gcc
- * HP-UX 10.20 PA-RISC HP C++
- * IRIX 6.5 MIPS MIPSpro C
- * Linux 2.2 x86 gcc
- * Linux 2.2 Alpha gcc
- * Linux 2.4 IA64 gcc
- * Linux 2.4 StrongARM gcc
- * NetBSD 1.4 x86 gcc
- * NetBSD 1.4 StrongARM gcc
- * NetBSD 1.5 Alpha gcc
- * OpenVMS 7.1 Alpha DEC C 6.0
- * RISC OS 4 StrongARM Norcroft C
- * Solaris 2.5.1 x86 gcc
- * Solaris 2.5.1 Sparc gcc
- * Solaris 2.6 Sparc WorkShop 4.2
- * Solaris 8 Sparc Forte C 6
- * Tru64 4.0D Alpha gcc
- * Tru64 5.1 Alpha gcc
- * WinNT x86 MSVC 5.0 & 6.0
- *
************************************************************************/
-static const char rcsid[] = "@(#)$Id$";
+/*
+ * TODO:
+ * o Put all the magic into trio_fpclassify_and_signbit(), and use this from
+ * trio_isnan() etc.
+ */
/*************************************************************************
* Include files
@@ -102,7 +75,9 @@ static const char rcsid[] = "@(#)$Id$";
# if defined(TRIO_PLATFORM_VMS)
# error "Must be compiled with option /IEEE_MODE=UNDERFLOW_TO_ZERO/FLOAT=IEEE"
# else
-# error "Must be compiled with option -ieee"
+# if !defined(_CFE)
+# error "Must be compiled with option -ieee"
+# endif
# endif
# elif defined(TRIO_COMPILER_GCC) && (defined(__osf__) || defined(__linux__))
# error "Must be compiled with option -mieee"
@@ -128,9 +103,11 @@ static const char rcsid[] = "@(#)$Id$";
/*************************************************************************
- * Data
+ * Constants
*/
+static TRIO_CONST char rcsid[] = "@(#)$Id$";
+
#if defined(USE_IEEE_754)
/*
@@ -187,7 +164,9 @@ static TRIO_CONST unsigned char ieee_754_qnan_array[] = {
* trio_make_double
*/
TRIO_PRIVATE double
-trio_make_double(TRIO_CONST unsigned char *values)
+trio_make_double
+TRIO_ARGS1((values),
+ TRIO_CONST unsigned char *values)
{
TRIO_VOLATILE double result;
int i;
@@ -202,8 +181,10 @@ trio_make_double(TRIO_CONST unsigned char *values)
* trio_is_special_quantity
*/
TRIO_PRIVATE int
-trio_is_special_quantity(double number,
- int *has_mantissa)
+trio_is_special_quantity
+TRIO_ARGS2((number, has_mantissa),
+ double number,
+ int *has_mantissa)
{
unsigned int i;
unsigned char current;
@@ -224,7 +205,9 @@ trio_is_special_quantity(double number,
* trio_is_negative
*/
TRIO_PRIVATE int
-trio_is_negative(double number)
+trio_is_negative
+TRIO_ARGS1((number),
+ double number)
{
unsigned int i;
int is_negative = TRIO_FALSE;
@@ -236,22 +219,33 @@ trio_is_negative(double number)
return is_negative;
}
+#endif /* USE_IEEE_754 */
+
+
+/**
+ Generate negative zero.
+
+ @return Floating-point representation of negative zero.
+*/
TRIO_PUBLIC double
-trio_nzero(void)
+trio_nzero(TRIO_NOARGS)
{
+#if defined(USE_IEEE_754)
return trio_make_double(ieee_754_negzero_array);
-}
-
-#endif /* USE_IEEE_754 */
+#else
+ TRIO_VOLATILE double zero = 0.0;
+ return -zero;
+#endif
+}
/**
Generate positive infinity.
@return Floating-point representation of positive infinity.
*/
TRIO_PUBLIC double
-trio_pinf(void)
+trio_pinf(TRIO_NOARGS)
{
/* Cache the result */
static double result = 0.0;
@@ -295,7 +289,7 @@ trio_pinf(void)
@return Floating-point value of negative infinity.
*/
TRIO_PUBLIC double
-trio_ninf(void)
+trio_ninf(TRIO_NOARGS)
{
static double result = 0.0;
@@ -316,7 +310,7 @@ trio_ninf(void)
@return Floating-point representation of NaN.
*/
TRIO_PUBLIC double
-trio_nan(void)
+trio_nan(TRIO_NOARGS)
{
/* Cache the result */
static double result = 0.0;
@@ -364,9 +358,12 @@ trio_nan(void)
@return Boolean value indicating whether or not the number is a NaN.
*/
TRIO_PUBLIC int
-trio_isnan(TRIO_VOLATILE double number)
+trio_isnan
+TRIO_ARGS1((number),
+ double number)
{
-#if defined(isnan) || defined(TRIO_COMPILER_SUPPORTS_UNIX95)
+#if (defined(TRIO_COMPILER_SUPPORTS_C99) && defined(isnan)) \
+ || defined(TRIO_COMPILER_SUPPORTS_UNIX95)
/*
* C99 defines isnan() as a macro. UNIX95 defines isnan() as a
* function. This function was already present in XPG4, but this
@@ -407,7 +404,7 @@ trio_isnan(TRIO_VOLATILE double number)
status = (/*
* NaN is the only number which does not compare to itself
*/
- (number != number) ||
+ ((TRIO_VOLATILE double)number != (TRIO_VOLATILE double)number) ||
/*
* Fallback solution if NaN compares to NaN
*/
@@ -431,7 +428,9 @@ trio_isnan(TRIO_VOLATILE double number)
@return 1 if positive infinity, -1 if negative infinity, 0 otherwise.
*/
TRIO_PUBLIC int
-trio_isinf(TRIO_VOLATILE double number)
+trio_isinf
+TRIO_ARGS1((number),
+ double number)
{
#if defined(TRIO_COMPILER_DECC)
/*
@@ -441,12 +440,14 @@ trio_isinf(TRIO_VOLATILE double number)
return ((fp_class(number) == FP_POS_INF)
? 1
: ((fp_class(number) == FP_NEG_INF) ? -1 : 0));
-
+
#elif defined(isinf)
/*
* C99 defines isinf() as a macro.
*/
- return isinf(number);
+ return isinf(number)
+ ? ((number > 0.0) ? 1 : -1)
+ : 0;
#elif defined(TRIO_COMPILER_MSVC)
/*
@@ -503,9 +504,11 @@ trio_isinf(TRIO_VOLATILE double number)
@return Boolean value indicating whether or not the number is a finite.
*/
TRIO_PUBLIC int
-trio_isfinite(TRIO_VOLATILE double number)
+trio_isfinite
+TRIO_ARGS1((number),
+ double number)
{
-#if defined(isfinite)
+#if defined(TRIO_COMPILER_SUPPORTS_C99) && defined(isfinite)
/*
* C99 defines isfinite() as a macro.
*/
@@ -538,9 +541,11 @@ trio_isfinite(TRIO_VOLATILE double number)
/*
* The sign of NaN is always false
*/
-TRIO_PRIVATE int
-trio_fpclass(TRIO_VOLATILE double number,
- int *is_negative)
+TRIO_PUBLIC int
+trio_fpclassify_and_signbit
+TRIO_ARGS2((number, is_negative),
+ double number,
+ int *is_negative)
{
#if defined(fpclassify) && defined(signbit)
/*
@@ -637,7 +642,46 @@ trio_fpclass(TRIO_VOLATILE double number,
*is_negative = (number < 0.0);
return TRIO_FP_NORMAL;
}
-
+
+#elif defined(FP_PLUS_NORM) || defined(__hpux)
+
+ /*
+ * HP-UX 9.x and 10.x have an fpclassify() function, that is different
+ * from the C99 fpclassify() macro supported on HP-UX 11.x.
+ */
+ switch (fpclassify(number)) {
+ case FP_QNAN:
+ case FP_SNAN:
+ *is_negative = TRIO_FALSE;
+ return TRIO_FP_NAN;
+ case FP_PLUS_INF:
+ *is_negative = TRIO_FALSE;
+ return TRIO_FP_INFINITE;
+ case FP_MINUS_INF:
+ *is_negative = TRIO_TRUE;
+ return TRIO_FP_INFINITE;
+ case FP_PLUS_DENORM:
+ *is_negative = TRIO_FALSE;
+ return TRIO_FP_SUBNORMAL;
+ case FP_MINUS_DENORM:
+ *is_negative = TRIO_TRUE;
+ return TRIO_FP_SUBNORMAL;
+ case FP_PLUS_ZERO:
+ *is_negative = TRIO_FALSE;
+ return TRIO_FP_ZERO;
+ case FP_MINUS_ZERO:
+ *is_negative = TRIO_TRUE;
+ return TRIO_FP_ZERO;
+ case FP_PLUS_NORM:
+ *is_negative = TRIO_FALSE;
+ return TRIO_FP_NORMAL;
+ case FP_MINUS_NORM:
+ *is_negative = TRIO_TRUE;
+ return TRIO_FP_NORMAL;
+ default:
+ assert(0);
+ }
+
#else
/*
* Fallback solution.
@@ -687,11 +731,13 @@ trio_fpclass(TRIO_VOLATILE double number,
sign bit set (i.e. is negative).
*/
TRIO_PUBLIC int
-trio_signbit(TRIO_VOLATILE double number)
+trio_signbit
+TRIO_ARGS1((number),
+ double number)
{
int is_negative;
- (void)trio_fpclass(number, &is_negative);
+ (void)trio_fpclassify_and_signbit(number, &is_negative);
return is_negative;
}
@@ -702,11 +748,13 @@ trio_signbit(TRIO_VOLATILE double number)
@return Enumerable value indicating the class of @p number
*/
TRIO_PUBLIC int
-trio_fpclassify(TRIO_VOLATILE double number)
+trio_fpclassify
+TRIO_ARGS1((number),
+ double number)
{
int dummy;
- return trio_fpclass(number, &dummy);
+ return trio_fpclassify_and_signbit(number, &dummy);
}
@@ -723,7 +771,10 @@ trio_fpclassify(TRIO_VOLATILE double number)
#if defined(STANDALONE)
# include <stdio.h>
-static const char *getClassification(int type)
+static TRIO_CONST char *
+getClassification
+TRIO_ARGS1((type)
+ int type)
{
switch (type) {
case TRIO_FP_INFINITE:
@@ -741,7 +792,11 @@ static const char *getClassification(int type)
}
}
-static void print_class(const char *prefix, double number)
+static void
+print_class
+TRIO_ARGS2((prefix, number)
+ TRIO_CONST char *prefix,
+ double number)
{
printf("%-6s: %s %-15s %g\n",
prefix,
@@ -750,13 +805,13 @@ static void print_class(const char *prefix, double number)
number);
}
-int main(void)
+int main(TRIO_NOARGS)
{
double my_nan;
double my_pinf;
double my_ninf;
# if defined(TRIO_PLATFORM_UNIX)
- void (*signal_handler)(int);
+ void (*signal_handler) TRIO_PROTO((int));
# endif
my_nan = trio_nan();
View
23 trionan.h
@@ -35,39 +35,44 @@ enum {
/*
* Return NaN (Not-a-Number).
*/
-TRIO_PUBLIC double trio_nan(void);
+TRIO_PUBLIC double trio_nan TRIO_PROTO((void));
/*
* Return positive infinity.
*/
-TRIO_PUBLIC double trio_pinf(void);
+TRIO_PUBLIC double trio_pinf TRIO_PROTO((void));
/*
* Return negative infinity.
*/
-TRIO_PUBLIC double trio_ninf(void);
+TRIO_PUBLIC double trio_ninf TRIO_PROTO((void));
/*
+ * Return negative zero.
+ */
+TRIO_PUBLIC double trio_nzero TRIO_PROTO((TRIO_NOARGS));
+
+/*
* If number is a NaN return non-zero, otherwise return zero.
*/
-TRIO_PUBLIC int trio_isnan(double number);
+TRIO_PUBLIC int trio_isnan TRIO_PROTO((double number));
/*
* If number is positive infinity return 1, if number is negative
* infinity return -1, otherwise return 0.
*/
-TRIO_PUBLIC int trio_isinf(double number);
+TRIO_PUBLIC int trio_isinf TRIO_PROTO((double number));
/*
* If number is finite return non-zero, otherwise return zero.
*/
-TRIO_PUBLIC int trio_isfinite(double number);
+TRIO_PUBLIC int trio_isfinite TRIO_PROTO((double number));
-TRIO_PUBLIC int trio_signbit(double number);
+TRIO_PUBLIC int trio_signbit TRIO_PROTO((double number));
-TRIO_PUBLIC int trio_fpclassify(double number);
+TRIO_PUBLIC int trio_fpclassify TRIO_PROTO((double number));
-TRIO_PUBLIC double trio_nzero(void);
+TRIO_PUBLIC int trio_fpclassify_and_signbit TRIO_PROTO((double number, int *is_negative));
#ifdef __cplusplus
}
View
113 triop.h
@@ -26,8 +26,14 @@
#ifndef TRIO_TRIOP_H
#define TRIO_TRIOP_H
+#include "triodef.h"
+
#include <stdlib.h>
-#include <stdarg.h>
+#if defined(TRIO_COMPILER_ANCIENT)
+# include <varargs.h>
+#else
+# include <stdarg.h>
+#endif
#ifdef __cplusplus
extern "C" {
@@ -71,70 +77,71 @@ extern "C" {
# define TRIO_FREE(x) free(x)
#endif
+
/*************************************************************************
* User-defined specifiers
*/
-typedef int (*trio_callback_t)(void *);
+typedef int (*trio_callback_t) TRIO_PROTO((trio_pointer_t));
-void *trio_register(trio_callback_t callback, const char *name);
-void trio_unregister(void *handle);
+trio_pointer_t trio_register TRIO_PROTO((trio_callback_t callback, const char *name));
+void trio_unregister TRIO_PROTO((trio_pointer_t handle));
-const char *trio_get_format(void *ref);
-void *trio_get_argument(void *ref);
+TRIO_CONST char *trio_get_format TRIO_PROTO((trio_pointer_t ref));
+trio_pointer_t trio_get_argument TRIO_PROTO((trio_pointer_t ref));
/* Modifiers */
-int trio_get_width(void *ref);
-void trio_set_width(void *ref, int width);
-int trio_get_precision(void *ref);
-void trio_set_precision(void *ref, int precision);
-int trio_get_base(void *ref);
-void trio_set_base(void *ref, int base);
-int trio_get_padding(void *ref);
-void trio_set_padding(void *ref, int is_padding);
-int trio_get_short(void *ref); /* h */
-void trio_set_shortshort(void *ref, int is_shortshort);
-int trio_get_shortshort(void *ref); /* hh */
-void trio_set_short(void *ref, int is_short);
-int trio_get_long(void *ref); /* l */
-void trio_set_long(void *ref, int is_long);
-int trio_get_longlong(void *ref); /* ll */
-void trio_set_longlong(void *ref, int is_longlong);
-int trio_get_longdouble(void *ref); /* L */
-void trio_set_longdouble(void *ref, int is_longdouble);
-int trio_get_alternative(void *ref); /* # */
-void trio_set_alternative(void *ref, int is_alternative);
-int trio_get_alignment(void *ref); /* - */
-void trio_set_alignment(void *ref, int is_leftaligned);
-int trio_get_spacing(void *ref); /* (space) */
-void trio_set_spacing(void *ref, int is_space);
-int trio_get_sign(void *ref); /* + */
-void trio_set_sign(void *ref, int is_showsign);
-int trio_get_quote(void *ref); /* ' */
-void trio_set_quote(void *ref, int is_quote);
-int trio_get_upper(void *ref);
-void trio_set_upper(void *ref, int is_upper);
+int trio_get_width TRIO_PROTO((trio_pointer_t ref));
+void trio_set_width TRIO_PROTO((trio_pointer_t ref, int width));
+int trio_get_precision TRIO_PROTO((trio_pointer_t ref));
+void trio_set_precision TRIO_PROTO((trio_pointer_t ref, int precision));
+int trio_get_base TRIO_PROTO((trio_pointer_t ref));
+void trio_set_base TRIO_PROTO((trio_pointer_t ref, int base));
+int trio_get_padding TRIO_PROTO((trio_pointer_t ref));
+void trio_set_padding TRIO_PROTO((trio_pointer_t ref, int is_padding));
+int trio_get_short TRIO_PROTO((trio_pointer_t ref)); /* h */
+void trio_set_shortshort TRIO_PROTO((trio_pointer_t ref, int is_shortshort));
+int trio_get_shortshort TRIO_PROTO((trio_pointer_t ref)); /* hh */
+void trio_set_short TRIO_PROTO((trio_pointer_t ref, int is_short));
+int trio_get_long TRIO_PROTO((trio_pointer_t ref)); /* l */
+void trio_set_long TRIO_PROTO((trio_pointer_t ref, int is_long));
+int trio_get_longlong TRIO_PROTO((trio_pointer_t ref)); /* ll */
+void trio_set_longlong TRIO_PROTO((trio_pointer_t ref, int is_longlong));
+int trio_get_longdouble TRIO_PROTO((trio_pointer_t ref)); /* L */
+void trio_set_longdouble TRIO_PROTO((trio_pointer_t ref, int is_longdouble));
+int trio_get_alternative TRIO_PROTO((trio_pointer_t ref)); /* # */
+void trio_set_alternative TRIO_PROTO((trio_pointer_t ref, int is_alternative));
+int trio_get_alignment TRIO_PROTO((trio_pointer_t ref)); /* - */
+void trio_set_alignment TRIO_PROTO((trio_pointer_t ref, int is_leftaligned));
+int trio_get_spacing TRIO_PROTO((trio_pointer_t ref)); /* TRIO_PROTO((space) */
+void trio_set_spacing TRIO_PROTO((trio_pointer_t ref, int is_space));
+int trio_get_sign TRIO_PROTO((trio_pointer_t ref)); /* + */
+void trio_set_sign TRIO_PROTO((trio_pointer_t ref, int is_showsign));
+int trio_get_quote TRIO_PROTO((trio_pointer_t ref)); /* ' */
+void trio_set_quote TRIO_PROTO((trio_pointer_t ref, int is_quote));
+int trio_get_upper TRIO_PROTO((trio_pointer_t ref));
+void trio_set_upper TRIO_PROTO((trio_pointer_t ref, int is_upper));
#if TRIO_C99
-int trio_get_largest(void *ref); /* j */
-void trio_set_largest(void *ref, int is_largest);
-int trio_get_ptrdiff(void *ref); /* t */
-void trio_set_ptrdiff(void *ref, int is_ptrdiff);
-int trio_get_size(void *ref); /* z / Z */
-void trio_set_size(void *ref, int is_size);
+int trio_get_largest TRIO_PROTO((trio_pointer_t ref)); /* j */
+void trio_set_largest TRIO_PROTO((trio_pointer_t ref, int is_largest));
+int trio_get_ptrdiff TRIO_PROTO((trio_pointer_t ref)); /* t */
+void trio_set_ptrdiff TRIO_PROTO((trio_pointer_t ref, int is_ptrdiff));
+int trio_get_size TRIO_PROTO((trio_pointer_t ref)); /* z / Z */
+void trio_set_size TRIO_PROTO((trio_pointer_t ref, int is_size));
#endif
/* Printing */
-int trio_print_ref(void *ref, const char *format, ...);
-int trio_vprint_ref(void *ref, const char *format, va_list args);
-int trio_printv_ref(void *ref, const char *format, void **args);
-
-void trio_print_int(void *ref, int number);
-void trio_print_uint(void *ref, unsigned int number);
-/* void trio_print_long(void *ref, long number); */
-/* void trio_print_ulong(void *ref, unsigned long number); */
-void trio_print_double(void *ref, double number);
-void trio_print_string(void *ref, char *string);
-void trio_print_pointer(void *ref, void *pointer);
+int trio_print_ref TRIO_PROTO((trio_pointer_t ref, const char *format, ...));
+int trio_vprint_ref TRIO_PROTO((trio_pointer_t ref, const char *format, va_list args));
+int trio_printv_ref TRIO_PROTO((trio_pointer_t ref, const char *format, trio_pointer_t *args));
+
+void trio_print_int TRIO_PROTO((trio_pointer_t ref, int number));
+void trio_print_uint TRIO_PROTO((trio_pointer_t ref, unsigned int number));
+/* void trio_print_long TRIO_PROTO((trio_pointer_t ref, long number)); */
+/* void trio_print_ulong TRIO_PROTO((trio_pointer_t ref, unsigned long number)); */
+void trio_print_double TRIO_PROTO((trio_pointer_t ref, double number));
+void trio_print_string TRIO_PROTO((trio_pointer_t ref, char *string));
+void trio_print_pointer TRIO_PROTO((trio_pointer_t ref, trio_pointer_t pointer));
#ifdef __cplusplus
} /* extern "C" */
View
831 triostr.c
@@ -15,8 +15,6 @@
*
************************************************************************/
-static const char rcsid[] = "@(#)$Id$";
-
/*************************************************************************
* Include files
*/
@@ -26,21 +24,33 @@ static const char rcsid[] = "@(#)$Id$";
#include <string.h>
#include <ctype.h>
#include <math.h>
+#include "triodef.h"
#include "triostr.h"
/*************************************************************************
* Definitions
*/
-#ifndef NULL
+#if !defined(TRIO_STRING_PUBLIC)
+# define TRIO_STRING_PUBLIC TRIO_PUBLIC
+#endif
+#if !defined(TRIO_STRING_PRIVATE)
+# define TRIO_STRING_PRIVATE TRIO_PRIVATE
+#endif
+
+#if !defined(NULL)
# define NULL 0
#endif
-#define NIL ((char)0)
-#ifndef FALSE
+#if !defined(NIL)
+# define NIL ((char)0)
+#endif
+#if !defined(FALSE)
# define FALSE (1 == 0)
# define TRUE (! FALSE)
#endif
-#define BOOLEAN_T int
+#if !defined(BOOLEAN_T)
+# define BOOLEAN_T int
+#endif
#if defined(TRIO_COMPILER_SUPPORTS_C99)
# define USE_STRTOD
@@ -74,6 +84,14 @@ struct _trio_string_t
};
/*************************************************************************
+ * Constants
+ */
+
+#if !defined(TRIO_MINIMAL)
+static TRIO_CONST char rcsid[] = "@(#)$Id$";
+#endif
+
+/*************************************************************************
* Static String Functions
*/
@@ -90,8 +108,10 @@ struct _trio_string_t
@param size Size of new string.
@return Pointer to string, or NULL if allocation failed.
*/
-TRIO_PUBLIC TRIO_INLINE char *
-trio_create(size_t size)
+TRIO_STRING_PUBLIC char *
+trio_create
+TRIO_ARGS1((size),
+ size_t size)
{
return (char *)TRIO_MALLOC(size);
}
@@ -102,8 +122,10 @@ trio_create(size_t size)
@param string String to be freed.
*/
-TRIO_PUBLIC TRIO_INLINE void
-trio_destroy(char *string)
+TRIO_STRING_PUBLIC void
+trio_destroy
+TRIO_ARGS1((string),
+ char *string)
{
if (string)
{
@@ -118,34 +140,16 @@ trio_destroy(char *string)
@param string String to measure.
@return Number of characters in @string.
*/
-TRIO_PUBLIC TRIO_INLINE size_t
-trio_length(const char *string)
+TRIO_STRING_PUBLIC size_t
+trio_length
+TRIO_ARGS1((string),
+ TRIO_CONST char *string)
{
return strlen(string);
}
-/*
- * TrioDuplicateMax
- */
-TRIO_PRIVATE char *
-TrioDuplicateMax(const char *source, size_t size)
-{
- char *target;
-
- assert(source);
-
- /* Make room for string plus a terminating zero */
- size++;
- target = trio_create(size);
- if (target)
- {
- trio_copy_max(target, size, source);
- }
- return target;
-}
-
-
+#if !defined(TRIO_MINIMAL)
/**
Append @p source at the end of @p target.
@@ -159,17 +163,20 @@ TrioDuplicateMax(const char *source, size_t size)
result in a buffer overrun.
@post @p target will be zero terminated.
*/
-TRIO_PUBLIC int
-trio_append(char *target,
- const char *source)
+TRIO_STRING_PUBLIC int
+trio_append
+TRIO_ARGS2((target, source),
+ char *target,
+ TRIO_CONST char *source)
{
assert(target);
assert(source);
return (strcat(target, source) != NULL);
}
+#endif /* !defined(TRIO_MINIMAL) */
-
+#if !defined(TRIO_MINIMAL)
/**
Append at most @p max characters from @p source to @p target.
@@ -185,10 +192,12 @@ trio_append(char *target,
result in a buffer overrun.
@post @p target will be zero terminated.
*/
-TRIO_PUBLIC int
-trio_append_max(char *target,
- size_t max,
- const char *source)
+TRIO_STRING_PUBLIC int
+trio_append_max
+TRIO_ARGS3((target, max, source),
+ char *target,
+ size_t max,
+ TRIO_CONST char *source)
{
size_t length;
@@ -203,26 +212,32 @@ trio_append_max(char *target,
}
return TRUE;
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Determine if a string contains a substring.
@param string String to be searched.
@param substring String to be found.
@return Boolean value indicating success or failure.
*/
-TRIO_PUBLIC TRIO_INLINE int
-trio_contains(const char *string,
- const char *substring)
+TRIO_STRING_PUBLIC int
+trio_contains
+TRIO_ARGS2((string, substring),
+ TRIO_CONST char *string,
+ TRIO_CONST char *substring)
{
assert(string);
assert(substring);
return (0 != strstr(string, substring));
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Copy @p source to @p target.
@@ -236,16 +251,19 @@ trio_contains(const char *string,
result in a buffer overrun.
@post @p target will be zero terminated.
*/
-TRIO_PUBLIC int
-trio_copy(char *target,
- const char *source)
+TRIO_STRING_PUBLIC int
+trio_copy
+TRIO_ARGS2((target, source),
+ char *target,
+ TRIO_CONST char *source)
{
assert(target);
assert(source);
-
+
(void)strcpy(target, source);
return TRUE;
}
+#endif /* !defined(TRIO_MINIMAL) */
/**
@@ -262,10 +280,12 @@ trio_copy(char *target,
result in a buffer overrun.
@post @p target will be zero terminated.
*/
-TRIO_PUBLIC int
-trio_copy_max(char *target,
- size_t max,
- const char *source)
+TRIO_STRING_PUBLIC int
+trio_copy_max
+TRIO_ARGS3((target, max, source),
+ char *target,
+ size_t max,
+ TRIO_CONST char *source)
{
assert(target);
assert(source);
@@ -277,6 +297,30 @@ trio_copy_max(char *target,
}
+/*
+ * TrioDuplicateMax
+ */
+TRIO_STRING_PRIVATE char *
+TrioDuplicateMax
+TRIO_ARGS2((source, size),
+ TRIO_CONST char *source,
+ size_t size)
+{
+ char *target;
+
+ assert(source);
+
+ /* Make room for string plus a terminating zero */
+ size++;
+ target = trio_create(size);
+ if (target)
+ {
+ trio_copy_max(target, size, source);
+ }
+ return target;
+}
+
+
/**
Duplicate @p source.
@@ -285,13 +329,16 @@ trio_copy_max(char *target,
@post @p target will be zero terminated.
*/
-TRIO_PUBLIC char *
-trio_duplicate(const char *source)
+TRIO_STRING_PUBLIC char *
+trio_duplicate
+TRIO_ARGS1((source),
+ TRIO_CONST char *source)
{
return TrioDuplicateMax(source, trio_length(source));
}
+#if !defined(TRIO_MINIMAL)
/**
Duplicate at most @p max characters of @p source.
@@ -301,9 +348,10 @@ trio_duplicate(const char *source)
@post @p target will be zero terminated.
*/
-TRIO_PUBLIC char *
-trio_duplicate_max(const char *source,
- size_t max)
+TRIO_STRING_PUBLIC char *
+trio_duplicate_max TRIO_ARGS2((source, max),
+ TRIO_CONST char *source,
+ size_t max)
{
size_t length;
@@ -317,6 +365,7 @@ trio_duplicate_max(const char *source,
}
return TrioDuplicateMax(source, length);
}
+#endif /* !defined(TRIO_MINIMAL) */
/**
@@ -328,9 +377,11 @@ trio_duplicate_max(const char *source,
Case-insensitive comparison.
*/
-TRIO_PUBLIC int
-trio_equal(const char *first,
- const char *second)
+TRIO_STRING_PUBLIC int
+trio_equal
+TRIO_ARGS2((first, second),
+ TRIO_CONST char *first,
+ TRIO_CONST char *second)
{
assert(first);
assert(second);
@@ -365,9 +416,11 @@ trio_equal(const char *first,
Case-sensitive comparison.
*/
-TRIO_PUBLIC int
-trio_equal_case(const char *first,
- const char *second)
+TRIO_STRING_PUBLIC int
+trio_equal_case
+TRIO_ARGS2((first, second),
+ TRIO_CONST char *first,
+ TRIO_CONST char *second)
{
assert(first);
assert(second);
@@ -380,6 +433,7 @@ trio_equal_case(const char *first,
}
+#if !defined(TRIO_MINIMAL)
/**
Compare if two strings up until the first @p max characters are equal.
@@ -390,10 +444,12 @@ trio_equal_case(const char *first,
Case-sensitive comparison.
*/
-TRIO_PUBLIC int
-trio_equal_case_max(const char *first,
- size_t max,
- const char *second)
+TRIO_STRING_PUBLIC int
+trio_equal_case_max
+TRIO_ARGS3((first, max, second),
+ TRIO_CONST char *first,
+ size_t max,
+ TRIO_CONST char *second)
{
assert(first);
assert(second);
@@ -404,6 +460,7 @@ trio_equal_case_max(const char *first,
}
return FALSE;
}
+#endif /* !defined(TRIO_MINIMAL) */
/**
@@ -415,9 +472,11 @@ trio_equal_case_max(const char *first,
Collating characters are considered equal.
*/
-TRIO_PUBLIC int
-trio_equal_locale(const char *first,
- const char *second)
+TRIO_STRING_PUBLIC int
+trio_equal_locale
+TRIO_ARGS2((first, second),
+ TRIO_CONST char *first,
+ TRIO_CONST char *second)
{
assert(first);
assert(second);
@@ -440,10 +499,12 @@ trio_equal_locale(const char *first,
Case-insensitive comparison.
*/
-TRIO_PUBLIC int
-trio_equal_max(const char *first,
- size_t max,
- const char *second)
+TRIO_STRING_PUBLIC int
+trio_equal_max
+TRIO_ARGS3((first, max, second),
+ TRIO_CONST char *first,
+ size_t max,
+ TRIO_CONST char *second)
{
assert(first);
assert(second);
@@ -478,8 +539,10 @@ trio_equal_max(const char *first,
@param error_number Error number.
@return Textual description of @p error_number.
*/
-TRIO_PUBLIC const char *
-trio_error(int error_number)
+TRIO_STRING_PUBLIC TRIO_CONST char *
+trio_error
+TRIO_ARGS1((error_number),
+ int error_number)
{
#if defined(USE_STRERROR)
return strerror(error_number);
@@ -489,6 +552,7 @@ trio_error(int error_number)
}
+#if !defined(TRIO_MINIMAL)
/**
Format the date/time according to @p format.
@@ -501,11 +565,13 @@ trio_error(int error_number)
The formatting string accepts the same specifiers as the standard C
function strftime.
*/
-TRIO_PUBLIC size_t
-trio_format_date_max(char *target,
- size_t max,
- const char *format,
- const struct tm *datetime)
+TRIO_STRING_PUBLIC size_t
+trio_format_date_max
+TRIO_ARGS4((target, max, format, datetime),
+ char *target,
+ size_t max,
+ TRIO_CONST char *format,
+ TRIO_CONST struct tm *datetime)
{
assert(target);
assert(format);
@@ -514,8 +580,10 @@ trio_format_date_max(char *target,
return strftime(target, max, format, datetime);
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Calculate a hash value for a string.
@@ -526,9 +594,11 @@ trio_format_date_max(char *target,
@p type can be one of the following
@li @c TRIO_HASH_PLAIN Plain hash function.
*/
-TRIO_PUBLIC unsigned long
-trio_hash(const char *string,
- int type)
+TRIO_STRING_PUBLIC unsigned long
+trio_hash
+TRIO_ARGS2((string, type),
+ TRIO_CONST char *string,
+ int type)
{
unsigned long value = 0L;
char ch;
@@ -550,57 +620,71 @@ trio_hash(const char *string,
}
return value;
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Find first occurrence of a character in a string.
@param string String to be searched.
@param character Character to be found.
@param A pointer to the found character, or NULL if character was not found.
*/
-TRIO_PUBLIC TRIO_INLINE char *
-trio_index(const char *string,
- char character)
+TRIO_STRING_PUBLIC char *
+trio_index
+TRIO_ARGS2((string, character),
+ TRIO_CONST char *string,
+ int character)
{
assert(string);
return strchr(string, character);
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Find last occurrence of a character in a string.
@param string String to be searched.
@param character Character to be found.
@param A pointer to the found character, or NULL if character was not found.
*/
-TRIO_PUBLIC TRIO_INLINE char *
-trio_index_last(const char *string,
- char character)
+TRIO_STRING_PUBLIC char *
+trio_index_last
+TRIO_ARGS2((string, character),
+ TRIO_CONST char *string,
+ int character)
{
assert(string);
return strchr(string, character);
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Convert the alphabetic letters in the string to lower-case.
@param target String to be converted.
@return Number of processed characters (converted or not).
*/
-TRIO_PUBLIC TRIO_INLINE int
-trio_lower(char *target)
+TRIO_STRING_PUBLIC int
+trio_lower
+TRIO_ARGS1((target),
+ char *target)
{
assert(target);
return trio_span_function(target, target, tolower);
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Compare two strings using wildcards.
@@ -614,9 +698,11 @@ trio_lower(char *target)
@li @c * Match any number of characters.
@li @c ? Match a single character.
*/
-TRIO_PUBLIC int
-trio_match(const char *string,
- const char *pattern)
+TRIO_STRING_PUBLIC int
+trio_match
+TRIO_ARGS2((string, pattern),
+ TRIO_CONST char *string,
+ TRIO_CONST char *pattern)
{
assert(string);
assert(pattern);
@@ -648,8 +734,10 @@ trio_match(const char *string,
return FALSE;
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Compare two strings using wildcards.
@@ -663,9 +751,11 @@ trio_match(const char *string,
@li @c * Match any number of characters.
@li @c ? Match a single character.
*/
-TRIO_PUBLIC int
-trio_match_case(const char *string,
- const char *pattern)
+TRIO_STRING_PUBLIC int
+trio_match_case
+TRIO_ARGS2((string, pattern),
+ TRIO_CONST char *string,
+ TRIO_CONST char *pattern)
{
assert(string);
assert(pattern);
@@ -697,8 +787,10 @@ trio_match_case(const char *string,
return FALSE;
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Execute a function on each character in string.
@@ -707,10 +799,12 @@ trio_match_case(const char *string,
@param Function Function to be executed.
@return Number of processed characters.
*/
-TRIO_PUBLIC size_t
-trio_span_function(char *target,
- const char *source,
- int (*Function)(int))
+TRIO_STRING_PUBLIC size_t
+trio_span_function
+TRIO_ARGS3((target, source, Function),
+ char *target,
+ TRIO_CONST char *source,
+ int (*Function) TRIO_PROTO((int)))
{
size_t count = 0;
@@ -725,8 +819,10 @@ trio_span_function(char *target,
}
return count;
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Search for a substring in a string.
@@ -735,17 +831,21 @@ trio_span_function(char *target,
@return Pointer to first occurrence of @p substring in @p string, or NULL
if no match was found.
*/
-TRIO_PUBLIC TRIO_INLINE char *
-trio_substring(const char *string,
- const char *substring)
+TRIO_STRING_PUBLIC char *
+trio_substring
+TRIO_ARGS2((string, substring),
+ TRIO_CONST char *string,
+ TRIO_CONST char *substring)
{
assert(string);
assert(substring);
return strstr(string, substring);
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Search for a substring in the first @p max characters of a string.
@@ -755,10 +855,12 @@ trio_substring(const char *string,
@return Pointer to first occurrence of @p substring in @p string, or NULL
if no match was found.
*/
-TRIO_PUBLIC char *
-trio_substring_max(const char *string,
- size_t max,
- const char *substring)
+TRIO_STRING_PUBLIC char *
+trio_substring_max
+TRIO_ARGS3((string, max, substring),
+ TRIO_CONST char *string,
+ size_t max,
+ TRIO_CONST char *substring)
{
size_t count;
size_t size;
@@ -781,8 +883,10 @@ trio_substring_max(const char *string,
}
return result;
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Tokenize string.
@@ -792,13 +896,17 @@ trio_substring_max(const char *string,
@warning @p string will be destroyed.
*/
-TRIO_PUBLIC TRIO_INLINE char *
-trio_tokenize(char *string, const char *delimiters)
+TRIO_STRING_PUBLIC char *
+trio_tokenize
+TRIO_ARGS2((string, delimiters),
+ char *string,
+ TRIO_CONST char *delimiters)
{
assert(delimiters);
return strtok(string, delimiters);
}
+#endif /* !defined(TRIO_MINIMAL) */
/**
@@ -823,29 +931,32 @@ trio_tokenize(char *string, const char *delimiters)
@endverbatim
*/
/* FIXME: Add EBNF for hex-floats */
-TRIO_PUBLIC double
-trio_to_double(const char *source,
- const char **endp)
-{
-#if defined(USE_STRTOD)
- return strtod(source, (char **)endp);
+TRIO_STRING_PUBLIC trio_long_double_t
+trio_to_long_double
+TRIO_ARGS2((source, endp),
+ TRIO_CONST char *source,
+ char **endp)
+{
+#if defined(USE_STRTOLD)
+ return strtold(source, endp);
#else
- /* Preliminary code */
int isNegative = FALSE;
int isExponentNegative = FALSE;
- unsigned long integer = 0;
- unsigned long fraction = 0;
- unsigned long fracdiv = 1;
+ trio_long_double_t integer = 0.0;
+ trio_long_double_t fraction = 0.0;
unsigned long exponent = 0;
- double value = 0.0;
+ trio_long_double_t base;
+ trio_long_double_t fracdiv = 1.0;
+ trio_long_double_t value = 0.0;
/* First try hex-floats */
if ((source[0] == '0') && ((source[1] == 'x') || (source[1] == 'X')))
{
+ base = 16.0;
source += 2;
while (isxdigit((int)*source))
{
- integer *= 16;
+ integer *= base;
integer += (isdigit((int)*source)
? (*source - '0')
: 10 + (toupper((int)*source) - 'A'));
@@ -856,11 +967,10 @@ trio_to_double(const char *source,
source++;
while (isxdigit((int)*source))
{
- fraction *= 16;
- fraction += (isdigit((int)*source)
- ? (*source - '0')
- : 10 + (toupper((int)*source) - 'A'));
- fracdiv *= 16;
+ fracdiv /= base;
+ fraction += fracdiv * (isdigit((int)*source)
+ ? (*source - '0')
+ : 10 + (toupper((int)*source) - 'A'));
source++;
}
if ((*source == 'p') || (*source == 'P'))
@@ -873,7 +983,7 @@ trio_to_double(const char *source,
}
while (isdigit((int)*source))
{
- exponent *= 10;
+ exponent *= (int)base;
exponent += (*source - '0');
source++;
}
@@ -882,6 +992,7 @@ trio_to_double(const char *source,
}
else /* Then try normal decimal floats */
{
+ base = 10.0;
isNegative = (*source == '-');
/* Skip sign */
if ((*source == '+') || (*source == '-'))
@@ -890,7 +1001,7 @@ trio_to_double(const char *source,
/* Integer part */
while (isdigit((int)*source))
{
- integer *= 10;
+ integer *= base;
integer += (*source - '0');
source++;
}
@@ -900,9 +1011,8 @@ trio_to_double(const char *source,
source++; /* skip decimal point */
while (isdigit((int)*source))
{
- fraction *= 10;
- fraction += (*source - '0');
- fracdiv *= 10;
+ fracdiv /= base;
+ fraction += (*source - '0') * fracdiv;
source++;
}
}
@@ -920,30 +1030,26 @@ trio_to_double(const char *source,
source++;
while (isdigit((int)*source))
{
- exponent *= 10;
+ exponent *= (int)base;
exponent += (*source - '0');
source++;
}
}
}
- value = (double)integer;
- if (fraction != 0)
- {
- value += (double)fraction / (double)fracdiv;
- }
+ value = integer + fraction;
if (exponent != 0)
{
if (isExponentNegative)
- value /= pow((double)10, (double)exponent);
+ value /= pow(base, (double)exponent);
else
- value *= pow((double)10, (double)exponent);
+ value *= pow(base, (double)exponent);
}
if (isNegative)
value = -value;
if (endp)
- *endp = source;
+ *endp = (char *)source;
return value;
#endif
}
@@ -956,18 +1062,44 @@ trio_to_double(const char *source,
@param endp Pointer to end of the converted string.
@return A floating-point number.
- See @ref trio_to_double.
+ See @ref trio_to_long_double.
+*/
+TRIO_STRING_PUBLIC double
+trio_to_double
+TRIO_ARGS2((source, endp),
+ TRIO_CONST char *source,
+ char **endp)
+{
+#if defined(USE_STRTOD)
+ return strtod(source, endp);
+#else
+ return (double)trio_to_long_double(source, endp);
+#endif
+}
+
+#if !defined(TRIO_MINIMAL)
+/**
+ Convert string to floating-point number.
+
+ @param source String to be converted.
+ @param endp Pointer to end of the converted string.
+ @return A floating-point number.
+
+ See @ref trio_to_long_double.
*/
-TRIO_PUBLIC TRIO_INLINE float
-trio_to_float(const char *source,
- const char **endp)
+TRIO_STRING_PUBLIC float
+trio_to_float
+TRIO_ARGS2((source, endp),
+ TRIO_CONST char *source,
+ char **endp)
{
#if defined(USE_STRTOF)
- return strtof(source, (char **)endp);
+ return strtof(source, endp);
#else
- return (float)trio_to_double(source, endp);
+ return (float)trio_to_long_double(source, endp);
#endif
}
+#endif /* !defined(TRIO_MINIMAL) */
/**
@@ -977,10 +1109,12 @@ trio_to_float(const char *source,
@param endp Pointer to end of converted string.
@param base Radix number of number.
*/
-TRIO_PUBLIC TRIO_INLINE long
-trio_to_long(const char *string,
- char **endp,
- int base)
+TRIO_STRING_PUBLIC long
+trio_to_long
+TRIO_ARGS3((string, endp, base),
+ TRIO_CONST char *string,
+ char **endp,
+ int base)
{
assert(string);
assert((base >= 2) && (base <= 36));
@@ -989,38 +1123,46 @@ trio_to_long(const char *string,
}
+#if !defined(TRIO_MINIMAL)
/**
Convert string to unsigned integer.
@param string String to be converted.
@param endp Pointer to end of converted string.
@param base Radix number of number.
*/
-TRIO_PUBLIC TRIO_INLINE unsigned long
-trio_to_unsigned_long(const char *string,
- char **endp,
- int base)
+TRIO_STRING_PUBLIC unsigned long
+trio_to_unsigned_long
+TRIO_ARGS3((string, endp, base),
+ TRIO_CONST char *string,
+ char **endp,
+ int base)
{
assert(string);
assert((base >= 2) && (base <= 36));
return strtoul(string, endp, base);
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/**
Convert the alphabetic letters in the string to upper-case.
@param target The string to be converted.
@return The number of processed characters (converted or not).
*/
-TRIO_PUBLIC TRIO_INLINE int
-trio_upper(char *target)
+TRIO_STRING_PUBLIC int
+trio_upper
+TRIO_ARGS1((target),
+ char *target)
{
assert(target);
return trio_span_function(target, target, toupper);
}
+#endif /* !defined(TRIO_MINIMAL) */
/** @} End of StaticStrings */
@@ -1040,8 +1182,8 @@ trio_upper(char *target)
/*
* TrioStringAlloc
*/
-TRIO_PRIVATE trio_string_t *
-TrioStringAlloc(void)
+TRIO_STRING_PRIVATE trio_string_t *
+TrioStringAlloc(TRIO_NOARGS)
{
trio_string_t *self;
@@ -1062,9 +1204,11 @@ TrioStringAlloc(void)
* The size of the string will be increased by 'delta' characters. If
* 'delta' is zero, the size will be doubled.
*/
-TRIO_PRIVATE BOOLEAN_T
-TrioStringGrow(trio_string_t *self,
- size_t delta)
+TRIO_STRING_PRIVATE BOOLEAN_T
+TrioStringGrow
+TRIO_ARGS2((self, delta),
+ trio_string_t *self,
+ size_t delta)
{
BOOLEAN_T status = FALSE;
char *new_content;
@@ -1092,9 +1236,11 @@ TrioStringGrow(trio_string_t *self,
* If 'length' is less than the original size, the original size will be
* used (that is, the size of the string is never decreased).
*/
-TRIO_PRIVATE BOOLEAN_T
-TrioStringGrowTo(trio_string_t *self,
- size_t length)
+TRIO_STRING_PRIVATE BOOLEAN_T
+TrioStringGrowTo
+TRIO_ARGS2((self, length),
+ trio_string_t *self,
+ size_t length)
{
length++; /* Room for terminating zero */
return (self->allocated < length)
@@ -1103,14 +1249,17 @@ TrioStringGrowTo(trio_string_t *self,
}
+#if !defined(TRIO_MINIMAL)
/**
Create a new dynamic string.
@param initial_size Initial size of the buffer.
@return Newly allocated dynamic string, or NULL if memory allocation failed.
*/
-TRIO_PUBLIC trio_string_t *
-trio_string_create(int initial_size)
+TRIO_STRING_PUBLIC trio_string_t *
+trio_string_create
+TRIO_ARGS1((initial_size),
+ int initial_size)
{
trio_string_t *self;
@@ -1131,15 +1280,18 @@ trio_string_create(int initial_size)
}
return self;
}
+#endif /* !defined(TRIO_MINIMAL) */
/**
Deallocate the dynamic string and its contents.
@param self Dynamic string
*/
-TRIO_PUBLIC void
-trio_string_destroy(trio_string_t *self)
+TRIO_STRING_PUBLIC void
+trio_string_destroy
+TRIO_ARGS1((self),
+ trio_string_t *self)
{
assert(self);
@@ -1151,6 +1303,7 @@ trio_string_destroy(trio_string_t *self)
}
+#if !defined(TRIO_MINIMAL)
/**
Get a pointer to the content.
@@ -1165,8 +1318,11 @@ trio_string_destroy(trio_string_t *self)
number of characters from the ending of the string, starting at the
terminating zero, is returned.
*/
-TRIO_PUBLIC char *
-trio_string_get(trio_string_t *self, int offset)
+TRIO_STRING_PUBLIC char *
+trio_string_get
+TRIO_ARGS2((self, offset),
+ trio_string_t *self,
+ int offset)
{
char *result = NULL;
@@ -1180,7 +1336,7 @@ trio_string_get(trio_string_t *self, int offset)
}
if (offset >= 0)
{
- if (offset > self->length)
+ if (offset > (int)self->length)
{
offset = self->length;
}
@@ -1197,6 +1353,7 @@ trio_string_get(trio_string_t *self, int offset)
}
return result;
}
+#endif /* !defined(TRIO_MINIMAL) */
/**
@@ -1208,8 +1365,10 @@ trio_string_get(trio_string_t *self, int offset)
The content is removed from the dynamic string. This enables destruction
of the dynamic string without deallocation of the content.
*/
-TRIO_PUBLIC char *
-trio_string_extract(trio_string_t *self)
+TRIO_STRING_PUBLIC char *
+trio_string_extract
+TRIO_ARGS1((self),
+ trio_string_t *self)
{
char *result;
@@ -1223,6 +1382,7 @@ trio_string_extract(trio_string_t *self)
}
+#if !defined(TRIO_MINIMAL)
/**
Set the content of the dynamic string.
@@ -1236,22 +1396,27 @@ trio_string_extract(trio_string_t *self)
This function will make a copy of @p buffer.
You are responsible for deallocating @p buffer yourself.
*/
-TRIO_PUBLIC void
-trio_xstring_set(trio_string_t *self,
- char *buffer)
+TRIO_STRING_PUBLIC void
+trio_xstring_set
+TRIO_ARGS2((self, buffer),
+ trio_string_t *self,
+ char *buffer)
{
assert(self);
trio_destroy(self->content);
self->content = trio_duplicate(buffer);
}
+#endif /* !defined(TRIO_MINIMAL) */
/*
* trio_string_size
*/
-TRIO_PUBLIC int
-trio_string_size(trio_string_t *self)
+TRIO_STRING_PUBLIC int
+trio_string_size
+TRIO_ARGS1((self),
+ trio_string_t *self)
{
assert(self);
@@ -1262,31 +1427,28 @@ trio_string_size(trio_string_t *self)
/*
* trio_string_terminate
*/
-TRIO_PUBLIC void
-trio_string_terminate(trio_string_t *self)
+TRIO_STRING_PUBLIC void
+trio_string_terminate
+TRIO_ARGS1((self),
+ trio_string_t *self)
{
- char *end;
-
- assert(self);
-
- end = trio_string_get(self, -1);
- if (end)
- {
- *end = NIL;
- }
+ trio_xstring_append_char(self, 0);
}
+#if !defined(TRIO_MINIMAL)
/**
Append the second string to the first.
@param self Dynamic string to be modified.
@param other Dynamic string to copy from.
@return Boolean value indicating success or failure.
*/
-TRIO_PUBLIC int
-trio_string_append(trio_string_t *self,
- trio_string_t *other)
+TRIO_STRING_PUBLIC int
+trio_string_append
+TRIO_ARGS2((self, other),
+ trio_string_t *self,
+ trio_string_t *other)
{
size_t length;
@@ -1303,14 +1465,18 @@ trio_string_append(trio_string_t *self,
error:
return FALSE;
}
+#endif /* !defined(TRIO_MINIMAL) */
+#if !defined(TRIO_MINIMAL)
/*
* trio_xstring_append
*/
-TRIO_PUBLIC int
-trio_xstring_append(trio_string_t *self,
- const char *other)
+TRIO_STRING_PUBLIC int
+trio_xstring_append
+TRIO_ARGS2((self, other),
+ trio_string_t *self,
+ TRIO_CONST char *other)
{
size_t length;
@@ -1327,18 +1493,21 @@ trio_xstring_append(trio_string_t *self,
error:
return FALSE;
}
+#endif /* !defined(TRIO_MINIMAL) */
/*
* trio_xstring_append_char
*/
-TRIO_PUBLIC int
-trio_xstring_append_char(trio_string_t *self,
- char character)
+TRIO_STRING_PUBLIC int
+trio_xstring_append_char
+TRIO_ARGS2((self, character),
+ trio_string_t *self,
+ char character)
{
assert(self);
- if (self->length >= trio_string_size(self))
+ if ((int)self->length >= trio_string_size(self))
{
if (!TrioStringGrow(self, 0))
goto error;
@@ -1352,73 +1521,92 @@ trio_xstring_append_char(trio