trio.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. * MERCHANTABILITY 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(TRIO_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. # undef printf
  132. # define printf trio_printf
  133. #endif
  134. #ifndef HAVE_VPRINTF
  135. # undef vprintf
  136. # define vprintf trio_vprintf
  137. #endif
  138. #ifndef HAVE_FPRINTF
  139. # undef fprintf
  140. # define fprintf trio_fprintf
  141. #endif
  142. #ifndef HAVE_VFPRINTF
  143. # undef vfprintf
  144. # define vfprintf trio_vfprintf
  145. #endif
  146. #ifndef HAVE_SPRINTF
  147. # undef sprintf
  148. # define sprintf trio_sprintf
  149. #endif
  150. #ifndef HAVE_VSPRINTF
  151. # undef vsprintf
  152. # define vsprintf trio_vsprintf
  153. #endif
  154. #ifndef HAVE_SNPRINTF
  155. # undef snprintf
  156. # define snprintf trio_snprintf
  157. #endif
  158. #ifndef HAVE_VSNPRINTF
  159. # undef vsnprintf
  160. # define vsnprintf trio_vsnprintf
  161. #endif
  162. #ifndef HAVE_SCANF
  163. # undef scanf
  164. # define scanf trio_scanf
  165. #endif
  166. #ifndef HAVE_VSCANF
  167. # undef vscanf
  168. # define vscanf trio_vscanf
  169. #endif
  170. #ifndef HAVE_FSCANF
  171. # undef fscanf
  172. # define fscanf trio_fscanf
  173. #endif
  174. #ifndef HAVE_VFSCANF
  175. # undef vfscanf
  176. # define vfscanf trio_vfscanf
  177. #endif
  178. #ifndef HAVE_SSCANF
  179. # undef sscanf
  180. # define sscanf trio_sscanf
  181. #endif
  182. #ifndef HAVE_VSSCANF
  183. # undef vsscanf
  184. # define vsscanf trio_vsscanf
  185. #endif
  186. /* These aren't stdio functions, but we make them look similar */
  187. #define dprintf trio_dprintf
  188. #define vdprintf trio_vdprintf
  189. #define aprintf trio_aprintf
  190. #define vaprintf trio_vaprintf
  191. #define asprintf trio_asprintf
  192. #define vasprintf trio_vasprintf
  193. #define dscanf trio_dscanf
  194. #define vdscanf trio_vdscanf
  195. #endif
  196. #ifdef __cplusplus
  197. } /* extern "C" */
  198. #endif
  199. #endif /* WITHOUT_TRIO */
  200. #endif /* TRIO_TRIO_H */