trio.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*************************************************************************
  2. *
  3. * $Id$
  4. *
  5. * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg.
  6. *
  7. * Permission to use, copy, modify, and distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  12. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  13. * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
  14. * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
  15. *
  16. *************************************************************************
  17. *
  18. * http://ctrio.sourceforge.net/
  19. *
  20. ************************************************************************/
  21. #ifndef TRIO_TRIO_H
  22. #define TRIO_TRIO_H
  23. #if !defined(WITHOUT_TRIO)
  24. /*
  25. * Use autoconf defines if present. Packages using trio must define
  26. * HAVE_CONFIG_H as a compiler option themselves.
  27. */
  28. #if defined(HAVE_CONFIG_H)
  29. # include "config.h"
  30. #endif
  31. #include "triodef.h"
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #if defined(TRIO_COMPILER_ANCIENT)
  35. # include <varargs.h>
  36. #else
  37. # include <stdarg.h>
  38. #endif
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /*
  43. * Error codes.
  44. *
  45. * Remember to add a textual description to trio_strerror.
  46. */
  47. enum {
  48. TRIO_EOF = 1,
  49. TRIO_EINVAL = 2,
  50. TRIO_ETOOMANY = 3,
  51. TRIO_EDBLREF = 4,
  52. TRIO_EGAP = 5,
  53. TRIO_ENOMEM = 6,
  54. TRIO_ERANGE = 7,
  55. TRIO_ERRNO = 8,
  56. TRIO_ECUSTOM = 9
  57. };
  58. /* Error macros */
  59. #define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
  60. #define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
  61. #define TRIO_ERROR_NAME(x) trio_strerror(x)
  62. typedef int (*trio_outstream_t) TRIO_PROTO((trio_pointer_t, int));
  63. typedef int (*trio_instream_t) TRIO_PROTO((trio_pointer_t));
  64. TRIO_CONST char *trio_strerror TRIO_PROTO((int));
  65. /*************************************************************************
  66. * Print Functions
  67. */
  68. int trio_printf TRIO_PROTO((TRIO_CONST char *format, ...));
  69. int trio_vprintf TRIO_PROTO((TRIO_CONST char *format, va_list args));
  70. int trio_printfv TRIO_PROTO((TRIO_CONST char *format, void **args));
  71. int trio_fprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...));
  72. int trio_vfprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args));
  73. int trio_fprintfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args));
  74. int trio_dprintf TRIO_PROTO((int fd, TRIO_CONST char *format, ...));
  75. int trio_vdprintf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args));
  76. int trio_dprintfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args));
  77. int trio_cprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
  78. TRIO_CONST char *format, ...));
  79. int trio_vcprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
  80. TRIO_CONST char *format, va_list args));
  81. int trio_cprintfv TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure,
  82. TRIO_CONST char *format, void **args));
  83. int trio_sprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, ...));
  84. int trio_vsprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, va_list args));
  85. int trio_sprintfv TRIO_PROTO((char *buffer, TRIO_CONST char *format, void **args));
  86. int trio_snprintf TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...));
  87. int trio_vsnprintf TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
  88. va_list args));
  89. int trio_snprintfv TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
  90. void **args));
  91. int trio_snprintfcat TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...));
  92. int trio_vsnprintfcat TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format,
  93. va_list args));
  94. char *trio_aprintf TRIO_PROTO((TRIO_CONST char *format, ...));
  95. char *trio_vaprintf TRIO_PROTO((TRIO_CONST char *format, va_list args));
  96. int trio_asprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, ...));
  97. int trio_vasprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, va_list args));
  98. /*************************************************************************
  99. * Scan Functions
  100. */
  101. int trio_scanf TRIO_PROTO((TRIO_CONST char *format, ...));
  102. int trio_vscanf TRIO_PROTO((TRIO_CONST char *format, va_list args));
  103. int trio_scanfv TRIO_PROTO((TRIO_CONST char *format, void **args));
  104. int trio_fscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...));
  105. int trio_vfscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args));
  106. int trio_fscanfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args));
  107. int trio_dscanf TRIO_PROTO((int fd, TRIO_CONST char *format, ...));
  108. int trio_vdscanf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args));
  109. int trio_dscanfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args));
  110. int trio_cscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
  111. TRIO_CONST char *format, ...));
  112. int trio_vcscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
  113. TRIO_CONST char *format, va_list args));
  114. int trio_cscanfv TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure,
  115. TRIO_CONST char *format, void **args));
  116. int trio_sscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, ...));
  117. int trio_vsscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, va_list args));
  118. int trio_sscanfv TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, void **args));
  119. /*************************************************************************
  120. * Locale Functions
  121. */
  122. void trio_locale_set_decimal_point TRIO_PROTO((char *decimalPoint));
  123. void trio_locale_set_thousand_separator TRIO_PROTO((char *thousandSeparator));
  124. void trio_locale_set_grouping TRIO_PROTO((char *grouping));
  125. /*************************************************************************
  126. * Renaming
  127. */
  128. #ifdef TRIO_REPLACE_STDIO
  129. /* Replace the <stdio.h> functions */
  130. #ifndef HAVE_PRINTF
  131. # define printf trio_printf
  132. #endif
  133. #ifndef HAVE_VPRINTF
  134. # define vprintf trio_vprintf
  135. #endif
  136. #ifndef HAVE_FPRINTF
  137. # define fprintf trio_fprintf
  138. #endif
  139. #ifndef HAVE_VFPRINTF
  140. # define vfprintf trio_vfprintf
  141. #endif
  142. #ifndef HAVE_SPRINTF
  143. # define sprintf trio_sprintf
  144. #endif
  145. #ifndef HAVE_VSPRINTF
  146. # define vsprintf trio_vsprintf
  147. #endif
  148. #ifndef HAVE_SNPRINTF
  149. # define snprintf trio_snprintf
  150. #endif
  151. #ifndef HAVE_VSNPRINTF
  152. # define vsnprintf trio_vsnprintf
  153. #endif
  154. #ifndef HAVE_SCANF
  155. # define scanf trio_scanf
  156. #endif
  157. #ifndef HAVE_VSCANF
  158. # define vscanf trio_vscanf
  159. #endif
  160. #ifndef HAVE_FSCANF
  161. # define fscanf trio_fscanf
  162. #endif
  163. #ifndef HAVE_VFSCANF
  164. # define vfscanf trio_vfscanf
  165. #endif
  166. #ifndef HAVE_SSCANF
  167. # define sscanf trio_sscanf
  168. #endif
  169. #ifndef HAVE_VSSCANF
  170. # define vsscanf trio_vsscanf
  171. #endif
  172. /* These aren't stdio functions, but we make them look similar */
  173. #define dprintf trio_dprintf
  174. #define vdprintf trio_vdprintf
  175. #define aprintf trio_aprintf
  176. #define vaprintf trio_vaprintf
  177. #define asprintf trio_asprintf
  178. #define vasprintf trio_vasprintf
  179. #define dscanf trio_dscanf
  180. #define vdscanf trio_vdscanf
  181. #endif
  182. #ifdef __cplusplus
  183. } /* extern "C" */
  184. #endif
  185. #endif /* WITHOUT_TRIO */
  186. #endif /* TRIO_TRIO_H */