src/bft/bft_printf.h Source File

| programmer's documentation

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bft_printf.h
Go to the documentation of this file.
1 #ifndef __BFT_PRINTF_H__
2 #define __BFT_PRINTF_H__
3
4 /*============================================================================
5 * Base user-definable printf() wrapper or replacement
6 *============================================================================*/
7
8 /*
9 This file is part of Code_Saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2013 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27
28 /*----------------------------------------------------------------------------*/
29
30 #include "cs_defs.h"
31
32 /*----------------------------------------------------------------------------*/
33
34 /*----------------------------------------------------------------------------
35 * Standard C library headers
36 *----------------------------------------------------------------------------*/
37
38 #include <stdarg.h>
39
40 /*----------------------------------------------------------------------------
41 * Local headers
42 *----------------------------------------------------------------------------*/
43
44 /*-----------------------------------------------------------------------------*/
45
46 BEGIN_C_DECLS
47
48 /*============================================================================
49 * Public types
50 *============================================================================*/
51
52 /* Function pointers for printf() and fflush(stdout) type functions */
53
54 typedef int (bft_printf_proxy_t) (const char *const format,
55 va_list arg_ptr);
56
57 typedef int (bft_printf_flush_proxy_t) (void);
58
59 /*============================================================================
60 * Public function prototypes
61 *============================================================================*/
62
63 /*
64 * Replacement for printf() with modifiable behavior.
65 *
66 * This function calls vprintf() by default, or a function with similar
67 * arguments indicated by bft_printf_proxy_set().
68 *
69 * parameters:
70 * format: <-- format string, as printf() and family.
71 * ... : <-- variable arguments based on format string.
72 *
73 * returns:
74 * number of characters printed, not counting the trailing '\0' used
75 * to end output strings
76 */
77
78 #if defined(__GNUC__)
79
80 int
81 bft_printf(const char *const format,
82 ...)
83 __attribute__((format(printf, 1, 2)));
84
85 #else
86
87 int
88 bft_printf(const char *const format,
89 ...);
90
91 #endif
92
93 /*
94 * Flush for output of bft_printf() with modifiable behavior.
95 *
96 * This function calls fflush(stdout) if bft_printf()'s default behavior is
97 * used. If bft_printf's behavior is modified with bft_printf_proxy_set(),
98 * bft_printf_flush()'s behavior may have to be also adjusted with
99 * bft_printf_flush_proxy_set().
100 *
101 * returns:
102 * using the default behavior, the return value is that of
103 * fflush(stdout): O upon successful completion, EOF otherwise
104 * (with errno set to indicate the error).
105 */
106
107 int
108 bft_printf_flush(void);
109
110 /*
111 * Returns function associated with the bft_printf() function.
112 *
113 * returns:
114 * pointer to the vprintf() or replacement function.
115 */
116
117 bft_printf_proxy_t *
118 bft_printf_proxy_get(void);
119
120 /*
121 * Associates a vprintf() type function with the bft_printf() function.
122 *
123 * parameters:
124 * fct: <-- pointer to a vprintf() type function.
125 */
126
127 void
128 bft_printf_proxy_set(bft_printf_proxy_t *const fct);
129
130 /*
131 * Returns function associated with bft_printf_flush().
132 *
133 * returns:
134 * pointer to the bft_printf_flush() proxy.
135 */
136
137 bft_printf_flush_proxy_t *
138 bft_printf_flush_proxy_get(void);
139
140 /*
141 * Associates a proxy function with bft_printf_flush().
142 *
143 * warning:
144 * bft_printf() is called by the default bft_error() error handler
145 * (so as to ensure that the error text appears at the end of the
146 * program output), so a bft_print_flush replacement must not itself
147 * call (directly or indirectly) bft_error() if the default error
148 * handler is used.
149 *
150 * parameter:
151 * fct <-- pointer to a function similar to {return fflush(stdout)}.
152 */
153
154 void
155 bft_printf_flush_proxy_set(bft_printf_flush_proxy_t *const fct);
156
157 /*----------------------------------------------------------------------------*/
158
159 END_C_DECLS
160
161 #endif /* __BFT_PRINTF_H__ */