2 * This file is part of cparser.
3 * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
15 static void print_char_file(const char c)
20 static void print_string_file(const char *str)
25 static void print_vformat_file(const char *format, va_list ap)
27 vfprintf(out, format, ap);
30 void print_to_file(FILE *new_out)
33 print_string = print_string_file;
34 print_vformat = print_vformat_file;
35 print_char = print_char_file;
40 static struct obstack *obst;
42 static void print_char_obstack(const char c)
44 obstack_1grow(obst, c);
47 static void print_string_obstack(const char *str)
49 size_t len = strlen(str);
50 obstack_grow(obst, str, len);
53 static void print_vformat_obstack(const char *format, va_list ap)
55 obstack_vprintf(obst, format, ap);
58 void print_to_obstack(struct obstack *new_obst)
61 print_string = print_string_obstack;
62 print_vformat = print_vformat_obstack;
63 print_char = print_char_obstack;
68 static char *buffer_pos;
69 static char *buffer_end;
71 static void print_char_buffer(const char c)
73 if (buffer_pos == buffer_end)
78 static void print_string_buffer(const char *str)
80 for (const char *c = str; *c != '\0'; ++c) {
81 print_char_buffer(*c);
85 static void print_vformat_buffer(const char *format, va_list ap)
87 size_t size = buffer_end - buffer_pos;
88 size_t written = (size_t) vsnprintf(buffer_pos, size, format, ap);
89 buffer_pos += MIN(written, size);
92 void print_to_buffer(char *buffer, size_t buffer_size)
95 buffer_end = buffer + buffer_size - 2;
97 print_string = print_string_buffer;
98 print_vformat = print_vformat_buffer;
99 print_char = print_char_buffer;
102 void finish_print_to_buffer(void)
110 void (*print_string)(const char *str) = print_string_file;
111 void (*print_vformat)(const char *format, va_list ap) = print_vformat_file;
112 void (*print_char)(const char c) = print_char_file;
114 void printer_push(void)
119 void printer_pop(void)