1
/*============================================================================
2
* Base user-definable printf() wrapper or replacement.
3
*============================================================================*/
6
This file is part of Code_Saturne, a general-purpose CFD tool.
8
Copyright (C) 1998-2011 EDF S.A.
10
This program is free software; you can redistribute it and/or modify it under
11
the terms of the GNU General Public License as published by the Free Software
12
Foundation; either version 2 of the License, or (at your option) any later
15
This program is distributed in the hope that it will be useful, but WITHOUT
16
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20
You should have received a copy of the GNU General Public License along with
21
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22
Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
/*----------------------------------------------------------------------------*/
27
#if defined(HAVE_CONFIG_H)
28
#include "cs_config.h"
31
#include "bft_config_defs.h"
34
* Standard C library headers
44
* Optional library and BFT headers
47
#include "bft_printf.h"
49
/*-----------------------------------------------------------------------------*/
54
} /* Fake brace to force back Emacs auto-indentation back to column 0 */
56
#endif /* __cplusplus */
58
/*-----------------------------------------------------------------------------*/
60
/*-----------------------------------------------------------------------------
61
* Local type definitions
62
*-----------------------------------------------------------------------------*/
64
/* Associated typedef documentation (for bft_printf.h) */
67
* \typedef bft_printf_proxy_t
69
* \brief Function pointer for printf() type functions.
71
* \param [in] format format string, as printf() and family.
72
* \param [in, out] arg_ptr pointer to variable argument list based on format
77
* \typedef bft_printf_flush_proxy_t
79
* \brief Function pointer for fflush(stdout) type functions.
82
/*-----------------------------------------------------------------------------
83
* Local function prototypes
84
*-----------------------------------------------------------------------------*/
87
* Default bft_printf_flush() proxy.
90
* return code of fflush(stdout).
94
_bft_printf_flush_proxy_default(void);
96
/*-----------------------------------------------------------------------------
97
* Local static variable definitions
98
*-----------------------------------------------------------------------------*/
100
static bft_printf_proxy_t *_bft_printf_proxy = vprintf;
101
static bft_printf_flush_proxy_t *_bft_printf_flush_proxy
102
= _bft_printf_flush_proxy_default;
104
/*-----------------------------------------------------------------------------
105
* Local function definitions
106
*-----------------------------------------------------------------------------*/
109
* Default bft_printf_flush() proxy.
112
* return code of fflush(stdout).
116
_bft_printf_flush_proxy_default(void)
118
return fflush(stdout);
121
/*============================================================================
122
* Public function definitions
123
*============================================================================*/
126
* \brief Replacement for printf() with modifiable behavior.
128
* This function calls vprintf() by default, or a function with similar
129
* arguments indicated by bft_printf_proxy_set().
131
* \param [in] format format string, as printf() and family.
132
* \param [in] ... variable arguments based on format string.
134
* \return number of characters printed, not counting the trailing '\\0'
135
* used to end output strings
139
bft_printf(const char *const format,
145
va_start(arg_ptr, format);
147
retval = _bft_printf_proxy(format, arg_ptr);
155
* \brief Flush for output of bft_printf() with modifiable behavior.
157
* This function calls fflush(stdout) if bft_printf()'s default behavior is
158
* used. If bft_printf's behavior is modified with bft_printf_proxy_set(),
159
* bft_printf_flush()'s behavior may have to be also adjusted with
160
* bft_printf_flush_proxy_set().
162
* \return using the default behavior, the return value is that of
163
* fflush(stdout): O upon successful completion, EOF otherwise
164
* (with errno set to indicate the error).
168
bft_printf_flush(void)
170
return _bft_printf_flush_proxy();
174
* \brief Returns function associated with the bft_printf() function.
176
* \return pointer to the vprintf() or replacement function.
180
bft_printf_proxy_get(void)
182
return _bft_printf_proxy;
186
* \brief Associates a vprintf() type function with the bft_printf() function.
188
* \param [in] fct pointer to a vprintf() type function.
192
bft_printf_proxy_set(bft_printf_proxy_t *const fct)
194
_bft_printf_proxy = fct;
198
* \brief Returns function associated with bft_printf_flush().
200
* \return pointer to the bft_printf_flush() proxy.
203
bft_printf_flush_proxy_t *
204
bft_printf_flush_proxy_get(void)
206
return _bft_printf_flush_proxy;
210
* \brief Associates a proxy function with bft_printf_flush().
213
* bft_printf() is called by the default bft_error() error handler
214
* (so as to ensure that the error text appears at the end of the
215
* program output), so a bft_print_flush replacement must not itself
216
* call (directly or indirectly) bft_error() if the default error
219
* \param [in] fct pointer to a function similar to {return fflush(stdout)}.
223
bft_printf_flush_proxy_set(bft_printf_flush_proxy_t *const fct)
225
_bft_printf_flush_proxy = fct;
228
/*-----------------------------------------------------------------------------*/
232
#endif /* __cplusplus */