bechordal_draw: Remove the write-only attribute max_color from struct draw_chordal_env_t.
[libfirm] / ir / libcore / lc_printf.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 IPD Goos, Universit"at Karlsruhe, Germany
4  */
5
6 /**
7  * Flexible printf().
8  * @author Sebastian Hack
9  * @date 3.1.2005
10  */
11 #ifndef _LIBCORE_LC_PRINTF_H
12 #define _LIBCORE_LC_PRINTF_H
13
14 #include <stddef.h>
15 #include <stdarg.h>
16 #include <stdio.h>
17 #include <stdint.h>
18
19 #include <obstack.h>
20
21 #include "lc_appendable.h"
22
23 typedef struct lc_arg_occ_t {
24         int width;                 /**< The width, or 0 if not given. */
25         int precision;             /**< The precision, or 0 if not given */
26
27         const char *modifier;      /**< A string of of modifiers preceding the
28                                         conversion specifier. Attention: This string
29                                         is not zero terminated. Use
30                                         @c modifier_length to get the number of
31                                         valid chars in it. */
32         size_t modifier_length;    /**< The number of valid chars in @c modifier. */
33         char conversion;           /**< The conversion specifier. */
34         int lc_arg_type;           /**< The type of the argument as determined by
35                                         the @c get_lc_arg_type member function of
36                                         the handler. */
37
38         unsigned flag_hash : 1;    /**< @c # flag was seen. */
39         unsigned flag_zero : 1;    /**< @c 0 flag was seen. */
40         unsigned flag_minus : 1;   /**< @c - flag was seen. */
41         unsigned flag_plus : 1;    /**< @c + flag was seen. */
42         unsigned flag_space : 1;   /**< A space flag was seen. */
43 } lc_arg_occ_t;
44
45 /**
46  * A value from the ... arguments of the printf function.
47  * Look at the file 'xprintf_lc_arg_types.def'. The second argument of the
48  * @c ARG_TYPE macro is the name of the union member preceded by $c v_
49  */
50 typedef union {
51 #define LC_ARG_TYPE(type,name,va_type) type v_ ## name;
52 #include "lc_printf_arg_types.def"
53 #undef LC_ARG_TYPE
54 } lc_arg_value_t;
55
56 enum {
57 #define LC_ARG_TYPE(type,name,va_type) lc_arg_type_ ## name,
58 #include "lc_printf_arg_types.def"
59 #undef LC_ARG_TYPE
60   lc_arg_type_last
61 };
62
63 typedef struct lc_arg_handler {
64         int (*get_lc_arg_type)(const lc_arg_occ_t *occ);
65         int (*emit)(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_value_t *arg);
66 } lc_arg_handler_t;
67
68 typedef struct lc_arg_env_t lc_arg_env_t;
69
70 lc_arg_env_t *lc_arg_new_env(void);
71 void lc_arg_free_env(lc_arg_env_t *env);
72 lc_arg_env_t *lc_arg_get_default_env(void);
73
74 int lc_arg_register(lc_arg_env_t *env, const char *name, char letter, const lc_arg_handler_t *handler);
75 void lc_arg_unregister(lc_arg_env_t *env, const char *name);
76
77 lc_arg_env_t *lc_arg_add_std(lc_arg_env_t *env);
78
79 int lc_arg_append(lc_appendable_t *app, const lc_arg_occ_t *occ, const char *str, size_t len);
80
81 int lc_epprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt, ...);
82 int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt, va_list args);
83 int lc_pprintf(lc_appendable_t *app, const char *fmt, ...);
84 int lc_vpprintf(lc_appendable_t *app, const char *fmt, va_list args);
85
86 int lc_eprintf(const lc_arg_env_t *env, const char *fmt, ...);
87 int lc_esnprintf(const lc_arg_env_t *env, char *buf, size_t len, const char *fmt, ...);
88 int lc_efprintf(const lc_arg_env_t *env, FILE *file, const char *fmt, ...);
89 int lc_eoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, ...);
90
91 int lc_evprintf(const lc_arg_env_t *env, const char *fmt, va_list args);
92 int lc_evsnprintf(const lc_arg_env_t *env, char *buf, size_t len, const char *fmt, va_list args);
93 int lc_evfprintf(const lc_arg_env_t *env, FILE *f, const char *fmt, va_list args);
94 int lc_evoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, va_list args);
95
96 int lc_printf(const char *fmt, ...);
97 int lc_snprintf(char *buf, size_t len, const char *fmt, ...);
98 int lc_fprintf(FILE *f, const char *fmt, ...);
99 int lc_oprintf(struct obstack *obst, const char *fmt, ...);
100
101 int lc_vprintf(const char *fmt, va_list args);
102 int lc_vsnprintf(char *buf, size_t len, const char *fmt, va_list args);
103 int lc_vfprintf(FILE *f, const char *fmt, va_list args);
104 int lc_voprintf(struct obstack *obst, const char *fmt, va_list args);
105
106 #endif