make parser more robuust, add string literals and escapes
[ccc.git] / util.h
1 #ifndef UTIL_H
2 #define UTIL_H
3
4 #include <stdarg.h>
5 #include <stdbool.h>
6
7 struct list { void *el; struct list *tail; };
8 struct list *list_cons(void *el, struct list *tail);
9 void list_free(struct list *head, void (*freefun)(void *));
10 void **list_to_array(struct list *list, int *num, bool reverse);
11 int list_length(struct list *head);
12
13 void die(const char *msg, ...);
14 void pdie(const char *msg);
15
16 /* if buf == NULL, a fresh buffer is allocated */
17 char *escape_char(char c, char *buf, bool str);
18 /* unescaped character will be in position 0 and the rest from position 1 on */
19 char *unescape_char(char *c);
20 /* Remove the last and first character from the string */
21 char *trimquotes(char *c);
22 void pindent(int indent, FILE *out);
23
24 void safe_fprintf(FILE *out, const char *msg, ...);
25 void *safe_malloc(size_t size);
26 void *safe_strdup(const char *c);
27
28 #endif