Remove the unused attribute const arch_env_t *arch_env from struct draw_chordal_env_t.
[libfirm] / ir / ir / irprintf.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   A little printf helper unterstanding firm types
23  * @author  Sebastian Hack
24  * @date    29.11.2004
25  * @version $Id$
26  */
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #ifdef HAVE_STRING_H
32 #include <string.h>
33 #endif
34 #ifdef HAVE_INTTYPES_H
35 #include <inttypes.h>
36 #endif
37
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <stdarg.h>
41
42 #include <ctype.h>
43
44 #include "ident.h"
45 #include "irmode_t.h"
46 #include "irnode_t.h"
47 #include "entity_t.h"
48 #include "type_t.h"
49 #include "tv_t.h"
50 #include "irprintf.h"
51 #include "obst.h"
52 #include "pset.h"
53 #include "iterator.h"
54 #include "bitset.h"
55 #include "dbginfo_t.h"
56
57 #define STRNIL "(nil)"
58
59 /**
60  * Init the string.
61  */
62 static void str_init(void *object, size_t n)
63 {
64         (void) n;
65         strcpy(object, "");
66 }
67
68 /**
69  * append a char to a string buffer.
70  */
71 static void str_append_char(void *object, size_t n, char ch)
72 {
73   char buf[2];
74
75   buf[0] = ch;
76   buf[1] = 0;
77
78   strncat(object, buf, n);
79 }
80
81 /**
82  * append a string to a string buffer.
83  */
84 static void str_append_str(void *object, size_t n, const char *str)
85 {
86   strncat(object, str, n);
87 }
88
89
90 /**
91  * Init the file. i.e. do nothing.
92  */
93 static void file_init(void *object, size_t n)
94 {
95         (void) object;
96         (void) n;
97 }
98
99 /**
100  * append a char to a file.
101  */
102 static void file_append_char(void *object, size_t n, char ch)
103 {
104         (void) n;
105         fputc(ch, object);
106 }
107
108 /**
109  * append a string to a file.
110  */
111 static void file_append_str(void *object, size_t n, const char *str)
112 {
113         (void) n;
114         fputs(str, object);
115 }
116
117 /**
118  * Init the obstack. i.e. do nothing.
119  */
120 static void obst_init(void *object, size_t n)
121 {
122         (void) object;
123         (void) n;
124 }
125
126 /**
127  * append a char to a obstack.
128  */
129 static void obst_append_char(void *object, size_t n, char ch)
130 {
131         struct obstack *obst = object;
132         (void) n;
133         obstack_1grow(obst, ch);
134 }
135
136 /**
137  * append a string to a obstack.
138  */
139 static void obst_append_str(void *object, size_t n, const char *str)
140 {
141         struct obstack *obst = object;
142         (void) n;
143         obstack_grow(obst, str, strlen(str));
144 }
145
146
147 /**
148  * the file appender
149  */
150 static const appender_t file_appender = {
151   file_init,
152   file_append_char,
153   file_append_str
154 };
155
156 /**
157  * the string buffer appender
158  */
159 static const appender_t str_appender = {
160   str_init,
161   str_append_char,
162   str_append_str
163 };
164
165 /**
166  * the obstack appender.
167  */
168 static const appender_t obst_appender = {
169   obst_init,
170   obst_append_char,
171   obst_append_str
172 };
173
174 #include "irargs_t.h"
175
176 void ir_printf(const char *fmt, ...)
177 {
178         va_list args;
179
180         va_start(args, fmt);
181         lc_evprintf(firm_get_arg_env(), fmt, args);
182         va_end(args);
183 }
184
185 void ir_fprintf(FILE *f, const char *fmt, ...)
186 {
187         va_list args;
188
189         va_start(args, fmt);
190         lc_evfprintf(firm_get_arg_env(), f, fmt, args);
191         va_end(args);
192 }
193
194 void ir_snprintf(char *buf, size_t n, const char *fmt, ...)
195 {
196         va_list args;
197
198         va_start(args, fmt);
199         lc_evsnprintf(firm_get_arg_env(), buf, n, fmt, args);
200         va_end(args);
201 }
202
203 void ir_vprintf(const char *fmt, va_list args)
204 {
205         lc_evprintf(firm_get_arg_env(), fmt, args);
206 }
207
208 void ir_vfprintf(FILE *f, const char *fmt, va_list args)
209 {
210         lc_evfprintf(firm_get_arg_env(), f, fmt, args);
211 }
212
213 void ir_vsnprintf(char *buf, size_t len, const char *fmt, va_list args)
214 {
215         lc_evsnprintf(firm_get_arg_env(), buf, len, fmt, args);
216 }
217
218 void ir_obst_vprintf(struct obstack *obst, const char *fmt, va_list args)
219 {
220         lc_evoprintf(firm_get_arg_env(), obst, fmt, args);
221 }