2 * This file is part of cparser.
3 * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
14 static void print_char_file(const char c)
19 static void print_string_file(const char *str)
24 static void print_vformat_file(const char *format, va_list ap)
26 vfprintf(out, format, ap);
29 void print_to_file(FILE *new_out)
32 print_string = print_string_file;
33 print_vformat = print_vformat_file;
34 print_char = print_char_file;
39 static struct obstack *obst;
41 static void print_char_obstack(const char c)
43 obstack_1grow(obst, c);
46 static void print_string_obstack(const char *str)
48 size_t len = strlen(str);
49 obstack_grow(obst, str, len);
52 static void print_vformat_obstack(const char *format, va_list ap)
54 obstack_vprintf(obst, format, ap);
57 void print_to_obstack(struct obstack *new_obst)
60 print_string = print_string_obstack;
61 print_vformat = print_vformat_obstack;
62 print_char = print_char_obstack;
67 static char *buffer_pos;
68 static char *buffer_end;
70 static void print_char_buffer(const char c)
72 if (buffer_pos == buffer_end)
77 static void print_string_buffer(const char *str)
79 for (const char *c = str; *c != '\0'; ++c) {
80 print_char_buffer(*c);
84 static void print_vformat_buffer(const char *format, va_list ap)
86 size_t size = buffer_end - buffer_pos;
87 size_t written = (size_t) vsnprintf(buffer_pos, size, format, ap);
88 buffer_pos += written < size ? written : size;
91 void print_to_buffer(char *buffer, size_t buffer_size)
94 buffer_end = buffer + buffer_size - 2;
96 print_string = print_string_buffer;
97 print_vformat = print_vformat_buffer;
98 print_char = print_char_buffer;
101 void finish_print_to_buffer(void)
109 void (*print_string)(const char *str) = print_string_file;
110 void (*print_vformat)(const char *format, va_list ap) = print_vformat_file;
111 void (*print_char)(const char c) = print_char_file;
113 void printer_push(void)
118 void printer_pop(void)