type: Make an assert()ion independent of the last entry of an enum.
[cparser] / printer.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
4  */
5
6 /**
7  * @file
8  * @brief  Abstracts away printing strings to a stream so we can reuse our
9  *         printing routines for printing to files or into memory
10  */
11 #ifndef PRINTER_H
12 #define PRINTER_H
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <stdarg.h>
17 #include "adt/obst.h"
18 #include "string_rep.h"
19
20 /** print a string into current output */
21 extern void (*print_string)(const char *str);
22 extern void (*print_vformat)(const char *format, va_list ap);
23 extern void (*print_char)(const char c);
24
25 /** print a printf style format string to current output */
26 static inline void __attribute__((format(printf,1,2))) print_format(const char *format, ...)
27 {
28         va_list ap;
29         va_start(ap, format);
30         print_vformat(format, ap);
31         va_end(ap);
32 }
33
34 /** Set current output to be a FILE* stream */
35 void print_to_file(FILE *out);
36
37 /** Set current output to an obstack (grows an object on the obstack) */
38 void print_to_obstack(struct obstack *obst);
39
40 /** Set current output to be a buffer with limited size */
41 void print_to_buffer(char *buffer, size_t buffer_size);
42
43 /** Assures that the string in the buffer is 0 terminated */
44 void finish_print_to_buffer(void);
45
46 /** push current printer output to the (printer output) stack */
47 void printer_push(void);
48
49 /** pop a printer output from the stack */
50 void printer_pop(void);
51
52 #endif