remove unnecessary libcore bits
[libfirm] / ir / libcore / lc_printf.h
1 /*
2   libcore: library for basic data structures and algorithms.
3   Copyright (C) 2005  IPD Goos, Universit"at Karlsruhe, Germany
4
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20 /**
21  * Flexible printf().
22  * @author Sebastian Hack
23  * @date 3.1.2005
24  */
25 #ifndef _LIBCORE_LC_PRINTF_H
26 #define _LIBCORE_LC_PRINTF_H
27
28 #include <stddef.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdint.h>
32
33 #include <obstack.h>
34
35 #include "lc_appendable.h"
36
37 typedef struct lc_arg_occ_t {
38         int width;                 /**< The width, or 0 if not given. */
39         int precision;             /**< The precision, or 0 if not given */
40
41         const char *modifier;      /**< A string of of modifiers preceding the
42                                         conversion specifier. Attention: This string
43                                         is not zero terminated. Use
44                                         @c modifier_length to get the number of
45                                         valid chars in it. */
46         size_t modifier_length;    /**< The number of valid chars in @c modifier. */
47         char conversion;           /**< The conversion specifier. */
48         int lc_arg_type;           /**< The type of the argument as determined by
49                                         the @c get_lc_arg_type member function of
50                                         the handler. */
51
52         unsigned flag_hash : 1;    /**< @c # flag was seen. */
53         unsigned flag_zero : 1;    /**< @c 0 flag was seen. */
54         unsigned flag_minus : 1;   /**< @c - flag was seen. */
55         unsigned flag_plus : 1;    /**< @c + flag was seen. */
56         unsigned flag_space : 1;   /**< A space flag was seen. */
57 } lc_arg_occ_t;
58
59 /**
60  * A value from the ... arguments of the printf function.
61  * Look at the file 'xprintf_lc_arg_types.def'. The second argument of the
62  * @c ARG_TYPE macro is the name of the union member preceded by $c v_
63  */
64 typedef union {
65 #define LC_ARG_TYPE(type,name,va_type) type v_ ## name;
66 #include "lc_printf_arg_types.def"
67 #undef LC_ARG_TYPE
68 } lc_arg_value_t;
69
70 enum {
71 #define LC_ARG_TYPE(type,name,va_type) lc_arg_type_ ## name,
72 #include "lc_printf_arg_types.def"
73 #undef LC_ARG_TYPE
74   lc_arg_type_last
75 };
76
77 typedef struct lc_arg_handler {
78         int (*get_lc_arg_type)(const lc_arg_occ_t *occ);
79         int (*emit)(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_value_t *arg);
80 } lc_arg_handler_t;
81
82 typedef struct lc_arg_env_t lc_arg_env_t;
83
84 lc_arg_env_t *lc_arg_new_env(void);
85 void lc_arg_free_env(lc_arg_env_t *env);
86 lc_arg_env_t *lc_arg_get_default_env(void);
87
88 int lc_arg_register(lc_arg_env_t *env, const char *name, char letter, const lc_arg_handler_t *handler);
89 void lc_arg_unregister(lc_arg_env_t *env, const char *name);
90
91 lc_arg_env_t *lc_arg_add_std(lc_arg_env_t *env);
92
93 int lc_arg_append(lc_appendable_t *app, const lc_arg_occ_t *occ, const char *str, size_t len);
94
95 int lc_epprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt, ...);
96 int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt, va_list args);
97 int lc_pprintf(lc_appendable_t *app, const char *fmt, ...);
98 int lc_vpprintf(lc_appendable_t *app, const char *fmt, va_list args);
99
100 int lc_eprintf(const lc_arg_env_t *env, const char *fmt, ...);
101 int lc_esnprintf(const lc_arg_env_t *env, char *buf, size_t len, const char *fmt, ...);
102 int lc_efprintf(const lc_arg_env_t *env, FILE *file, const char *fmt, ...);
103 int lc_eoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, ...);
104
105 int lc_evprintf(const lc_arg_env_t *env, const char *fmt, va_list args);
106 int lc_evsnprintf(const lc_arg_env_t *env, char *buf, size_t len, const char *fmt, va_list args);
107 int lc_evfprintf(const lc_arg_env_t *env, FILE *f, const char *fmt, va_list args);
108 int lc_evoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, va_list args);
109
110 int lc_printf(const char *fmt, ...);
111 int lc_snprintf(char *buf, size_t len, const char *fmt, ...);
112 int lc_fprintf(FILE *f, const char *fmt, ...);
113 int lc_oprintf(struct obstack *obst, const char *fmt, ...);
114
115 int lc_vprintf(const char *fmt, va_list args);
116 int lc_vsnprintf(char *buf, size_t len, const char *fmt, va_list args);
117 int lc_vfprintf(FILE *f, const char *fmt, va_list args);
118 int lc_voprintf(struct obstack *obst, const char *fmt, va_list args);
119
120 #endif