10 #include <stdio.h> /* for FILE * */
11 #include <stdarg.h> /* for va_list */
12 #include <time.h> /* for struct tm */
21 typedef struct Filename Filename;
22 typedef struct FontSpec FontSpec;
24 unsigned long parse_blocksize(const char *bs);
25 char ctrlparse(char *s, char **next);
27 size_t host_strcspn(const char *s, const char *set);
28 char *host_strchr(const char *s, int c);
29 char *host_strrchr(const char *s, int c);
30 char *host_strduptrim(const char *s);
32 char *dupstr(const char *s);
33 char *dupcat(const char *s1, ...);
34 char *dupprintf(const char *fmt, ...)
36 __attribute__ ((format (printf, 1, 2)))
39 char *dupvprintf(const char *fmt, va_list ap);
40 void burnstr(char *string);
44 char *fgetline(FILE *fp);
46 void base64_encode_atom(unsigned char *data, int n, char *out);
47 int base64_decode_atom(char *atom, unsigned char *out);
49 struct bufchain_granule;
50 typedef struct bufchain_tag {
51 struct bufchain_granule *head, *tail;
52 int buffersize; /* current amount of buffered data */
55 void bufchain_init(bufchain *ch);
56 void bufchain_clear(bufchain *ch);
57 int bufchain_size(bufchain *ch);
58 void bufchain_add(bufchain *ch, const void *data, int len);
59 void bufchain_prefix(bufchain *ch, void **data, int *len);
60 void bufchain_consume(bufchain *ch, int len);
61 void bufchain_fetch(bufchain *ch, void *data, int len);
63 struct tm ltime(void);
65 void smemclr(void *b, size_t len);
68 * Debugging functions.
70 * Output goes to debug.log
72 * debug(()) (note the double brackets) is like printf().
74 * dmemdump() and dmemdumpl() both do memory dumps. The difference
75 * is that dmemdumpl() is more suited for when the memory address is
76 * important (say because you'll be recording pointer values later
77 * on). dmemdump() is more concise.
81 void debug_printf(char *fmt, ...);
82 void debug_memdump(void *buf, int len, int L);
83 #define debug(x) (debug_printf x)
84 #define dmemdump(buf,len) debug_memdump (buf, len, 0);
85 #define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
88 #define dmemdump(buf,len)
89 #define dmemdumpl(buf,len)
93 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
97 #define min(x,y) ( (x) < (y) ? (x) : (y) )
100 #define max(x,y) ( (x) > (y) ? (x) : (y) )
103 #define GET_32BIT_LSB_FIRST(cp) \
104 (((unsigned long)(unsigned char)(cp)[0]) | \
105 ((unsigned long)(unsigned char)(cp)[1] << 8) | \
106 ((unsigned long)(unsigned char)(cp)[2] << 16) | \
107 ((unsigned long)(unsigned char)(cp)[3] << 24))
109 #define PUT_32BIT_LSB_FIRST(cp, value) ( \
110 (cp)[0] = (unsigned char)(value), \
111 (cp)[1] = (unsigned char)((value) >> 8), \
112 (cp)[2] = (unsigned char)((value) >> 16), \
113 (cp)[3] = (unsigned char)((value) >> 24) )
115 #define GET_16BIT_LSB_FIRST(cp) \
116 (((unsigned long)(unsigned char)(cp)[0]) | \
117 ((unsigned long)(unsigned char)(cp)[1] << 8))
119 #define PUT_16BIT_LSB_FIRST(cp, value) ( \
120 (cp)[0] = (unsigned char)(value), \
121 (cp)[1] = (unsigned char)((value) >> 8) )
123 #define GET_32BIT_MSB_FIRST(cp) \
124 (((unsigned long)(unsigned char)(cp)[0] << 24) | \
125 ((unsigned long)(unsigned char)(cp)[1] << 16) | \
126 ((unsigned long)(unsigned char)(cp)[2] << 8) | \
127 ((unsigned long)(unsigned char)(cp)[3]))
129 #define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
131 #define PUT_32BIT_MSB_FIRST(cp, value) ( \
132 (cp)[0] = (unsigned char)((value) >> 24), \
133 (cp)[1] = (unsigned char)((value) >> 16), \
134 (cp)[2] = (unsigned char)((value) >> 8), \
135 (cp)[3] = (unsigned char)(value) )
137 #define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
139 #define GET_16BIT_MSB_FIRST(cp) \
140 (((unsigned long)(unsigned char)(cp)[0] << 8) | \
141 ((unsigned long)(unsigned char)(cp)[1]))
143 #define PUT_16BIT_MSB_FIRST(cp, value) ( \
144 (cp)[0] = (unsigned char)((value) >> 8), \
145 (cp)[1] = (unsigned char)(value) )