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