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