3 * File name: ir/common/xprintf.h
4 * Purpose: Declarations for xprintf & friends.
5 * Author: Christian von Roques
7 * Created: 1999 by getting from fiasco
9 * Copyright: (c) 1995, 1996 Christian von Roques
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
14 /* Parts of this file are adapted from the GNU C Library.
15 Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
17 The GNU C Library is free software; you can redistribute it and/or
18 modify it under the terms of the GNU Library General Public License as
19 published by the Free Software Foundation; either version 2 of the
20 License, or (at your option) any later version.
22 The GNU C Library is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 Library General Public License for more details.
27 You should have received a copy of the GNU Library General Public
28 License along with the GNU C Library; see the file COPYING.LIB. If
29 not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
30 Cambridge, MA 02139, USA. */
37 /* This code is just an incomplete sketch how GNU libc could be used,
38 if it provided the necessary functionality. Problems:
39 o obstack_printf() is not yet available, it will be in version 2.
40 o User defined conversion specifiers cannot take struct arguments.
41 Using GNU libc should be *significantly* faster. */
45 # define XP_PAR1 FILE *stream
46 # define XP_PARN const void **args
48 typedef struct printf_info xprintf_info;
50 /* @@@ GNU libc version 2's register_printf_function *requires*
51 non-NULL 3rd argument */
52 # define xprintf_register(spec, func) \
53 register_printf_function ((spec), (func), NULL)
55 # define xprintf printf
56 # define xvprintf vprintf
57 # define xfprintf fprintf
58 # define xvfprintf vfprintf
59 # define xoprintf obstack_printf
60 # define xvoprintf obstack_vprintf
62 #else /* !USE_PRINTF */
64 /* Emulate GNU libc functionality on top of standard libc */
71 # define XP_PAR1 xgprintf_func *f, void *a
72 # define XP_PARN va_list *ap
74 /* Type of a generic print function */
75 typedef int xgprintf_func (void *, const char *, size_t);
79 int prec; /* Precision. */
80 int width; /* Width. */
81 unsigned char spec; /* Format letter. */
82 unsigned int is_long_double:1;/* L flag. */
83 unsigned int is_short:1; /* h flag. */
84 unsigned int is_long:1; /* l flag. */
85 unsigned int alt:1; /* # flag. */
86 unsigned int space:1; /* Space flag. */
87 unsigned int left:1; /* - flag. */
88 unsigned int showsign:1; /* + flag. */
89 char pad; /* Padding character. */
92 /* Type of a printf specifier-handler function.
93 `printer' is the generic print function to be called with first
94 argument `out'. `info' gives information about the format
95 specification. Arguments can be read from `args'. The function
96 shall return the number of characters written, or -1 for errors. */
97 typedef int xprintf_function (xgprintf_func *printer, void *out,
98 const xprintf_info *info,
101 void xprintf_register (char spec, xprintf_function *);
103 int xgprintf(xgprintf_func *, void *, const char *, ...);
104 int xvgprintf(xgprintf_func *, void *, const char *, va_list);
106 int xprintf (const char *, ...);
107 int xvprintf (const char *, va_list);
108 int xfprintf (FILE *, const char *, ...);
109 int xvfprintf (FILE *, const char *, va_list);
112 int xoprintf (struct obstack *, const char *, ...);
113 int xvoprintf (struct obstack *, const char *, va_list);
115 #endif /* !USE_PRINTF */
116 #endif /* _XPRINTF_H_ */