6 #define max(a, b) (((b) > (a))?(b):(a))
7 #define min(a, b) (((b) < (a))?(b):(a))
9 #define smalloc(size) ({void *__result__; ((__result__ = malloc(size)) == NULL)?({exit(-1); (void *)0;}):__result__;})
10 #define srealloc(ptr, size) ({void *__result__; ((__result__ = realloc((ptr), (size))) == NULL)?({exit(-1); (void *)0;}):__result__;})
11 #define szmalloc(size) memset(smalloc(size), 0, size)
12 #define sstrdup(str) ({const char *__strbuf__ = (str); strcpy(smalloc(strlen(__strbuf__) + 1), __strbuf__);})
13 #define omalloc(o) ((o) = szmalloc(sizeof(*(o))))
15 #define bufinit(buf) memset(&(buf), 0, sizeof(buf))
16 #define buffree(buf) do { if((buf).b != NULL) {free((buf).b);} bufinit(buf); } while(0)
17 #define sizebuf(buf, wanted) (_sizebuf((struct buffer *)&(buf), (wanted), sizeof(*((buf).b))))
18 #define bufadd(buf, new) \
20 _sizebuf((struct buffer *)&(buf), (buf).d + 1, sizeof(*((buf).b))); \
21 (buf).b[(buf).d++] = (new); \
23 #define bufcat(buf, new, size) \
25 size_t __bufcat_size__; \
26 __bufcat_size__ = (size); \
27 _sizebuf((struct buffer *)&(buf), (buf).d + __bufcat_size__, sizeof((buf).b)); \
28 memcpy((buf).b + (buf).d, (new), (__bufcat_size__) * sizeof(*((buf).b))); \
29 (buf).d += __bufcat_size__; \
31 #define bufcatstr(buf, str) \
35 bufcat((buf), __buf__, strlen(__buf__)); \
37 #define bufcatstr2(buf, str) \
41 bufcat((buf), __buf__, strlen(__buf__) + 1); \
43 #define bufeat(buf, len) memmove((buf).b, (buf).b + (len), (buf).d -= (len))
50 #define typedbuf(type) struct {type *b; size_t s, d;}
62 void _sizebuf(struct buffer *buf, size_t wanted, size_t el);
63 char *decstr(char **p, size_t *len);
64 char *vsprintf2(char *format, va_list al);
65 char *sprintf2(char *format, ...);
66 char *sprintf3(char *format, ...);
68 char **tokenize(char *src);
69 void freeca(char **ca);
71 void bvprintf(struct charbuf *buf, char *format, va_list al);
72 void bprintf(struct charbuf *buf, char *format, ...);
73 void replstr(char **p, char *n);