Code_Saturne
CFD tool
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-2012 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 /* Standard C library headers */
31 
32 #include <stdarg.h>
33 
34 /* BFT library headers */
35 
36 /*-----------------------------------------------------------------------------*/
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #if 0
41 } /* Fake brace to force Emacs auto-indentation back to column 0 */
42 #endif
43 #endif /* __cplusplus */
44 
45 /*============================================================================
46  * Public types
47  *============================================================================*/
48 
49 /* Function pointers for printf() and fflush(stdout) type functions */
50 
51 typedef int (bft_printf_proxy_t) (const char *const format,
52  va_list arg_ptr);
53 
54 typedef int (bft_printf_flush_proxy_t) (void);
55 
56 /*============================================================================
57  * Public function prototypes
58  *============================================================================*/
59 
60 /*
61  * Replacement for printf() with modifiable behavior.
62  *
63  * This function calls vprintf() by default, or a function with similar
64  * arguments indicated by bft_printf_proxy_set().
65  *
66  * parameters:
67  * format: <-- format string, as printf() and family.
68  * ... : <-- variable arguments based on format string.
69  *
70  * returns:
71  * number of characters printed, not counting the trailing '\0' used
72  * to end output strings
73  */
74 
75 #if defined(__GNUC__)
76 
77 int
78 bft_printf(const char *const format,
79  ...)
80  __attribute__((format(printf, 1, 2)));
81 
82 #else
83 
84 int
85 bft_printf(const char *const format,
86  ...);
87 
88 #endif
89 
90 /*
91  * Flush for output of bft_printf() with modifiable behavior.
92  *
93  * This function calls fflush(stdout) if bft_printf()'s default behavior is
94  * used. If bft_printf's behavior is modified with bft_printf_proxy_set(),
95  * bft_printf_flush()'s behavior may have to be also adjusted with
96  * bft_printf_flush_proxy_set().
97  *
98  * returns:
99  * using the default behavior, the return value is that of
100  * fflush(stdout): O upon successful completion, EOF otherwise
101  * (with errno set to indicate the error).
102  */
103 
104 int
105 bft_printf_flush(void);
106 
107 /*
108  * Returns function associated with the bft_printf() function.
109  *
110  * returns:
111  * pointer to the vprintf() or replacement function.
112  */
113 
116 
117 /*
118  * Associates a vprintf() type function with the bft_printf() function.
119  *
120  * parameters:
121  * fct: <-- pointer to a vprintf() type function.
122  */
123 
124 void
126 
127 /*
128  * Returns function associated with bft_printf_flush().
129  *
130  * returns:
131  * pointer to the bft_printf_flush() proxy.
132  */
133 
136 
137 /*
138  * Associates a proxy function with bft_printf_flush().
139  *
140  * warning:
141  * bft_printf() is called by the default bft_error() error handler
142  * (so as to ensure that the error text appears at the end of the
143  * program output), so a bft_print_flush replacement must not itself
144  * call (directly or indirectly) bft_error() if the default error
145  * handler is used.
146  *
147  * parameter:
148  * fct <-- pointer to a function similar to {return fflush(stdout)}.
149  */
150 
151 void
153 
154 /*----------------------------------------------------------------------------*/
155 
156 #ifdef __cplusplus
157 }
158 #endif /* __cplusplus */
159 
160 #endif /* __BFT_PRINTF_H__ */
int bft_printf(const char *const format,...)
Replacement for printf() with modifiable behavior.
Definition: bft_printf.c:137
void bft_printf_flush_proxy_set(bft_printf_flush_proxy_t *const fct)
Associates a proxy function with bft_printf_flush().
Definition: bft_printf.c:221
int() bft_printf_proxy_t(const char *const format, va_list arg_ptr)
Function pointer for printf() type functions.
Definition: bft_printf.h:51
int() bft_printf_flush_proxy_t(void)
Function pointer for fflush(stdout) type functions.
Definition: bft_printf.h:54
bft_printf_proxy_t * bft_printf_proxy_get(void)
Returns function associated with the bft_printf() function.
Definition: bft_printf.c:178
int bft_printf_flush(void)
Flush for output of bft_printf() with modifiable behavior.
Definition: bft_printf.c:166
void bft_printf_proxy_set(bft_printf_proxy_t *const fct)
Associates a vprintf() type function with the bft_printf() function.
Definition: bft_printf.c:190
bft_printf_flush_proxy_t * bft_printf_flush_proxy_get(void)
Returns function associated with bft_printf_flush().
Definition: bft_printf.c:202