6 #include <stdio.h> /* for FILE * */
7 #include <stdarg.h> /* for va_list */
8 #include <time.h> /* for struct tm */
17 typedef struct Filename Filename;
18 typedef struct FontSpec FontSpec;
20 unsigned long parse_blocksize(const char *bs);
21 char ctrlparse(char *s, char **next);
23 char *dupstr(const char *s);
24 char *dupcat(const char *s1, ...);
25 char *dupprintf(const char *fmt, ...);
26 char *dupvprintf(const char *fmt, va_list ap);
28 char *fgetline(FILE *fp);
30 void base64_encode_atom(unsigned char *data, int n, char *out);
32 struct bufchain_granule;
33 typedef struct bufchain_tag {
34 struct bufchain_granule *head, *tail;
35 int buffersize; /* current amount of buffered data */
38 void bufchain_init(bufchain *ch);
39 void bufchain_clear(bufchain *ch);
40 int bufchain_size(bufchain *ch);
41 void bufchain_add(bufchain *ch, const void *data, int len);
42 void bufchain_prefix(bufchain *ch, void **data, int *len);
43 void bufchain_consume(bufchain *ch, int len);
44 void bufchain_fetch(bufchain *ch, void *data, int len);
46 struct tm ltime(void);
49 * Debugging functions.
51 * Output goes to debug.log
53 * debug(()) (note the double brackets) is like printf().
55 * dmemdump() and dmemdumpl() both do memory dumps. The difference
56 * is that dmemdumpl() is more suited for when the memory address is
57 * important (say because you'll be recording pointer values later
58 * on). dmemdump() is more concise.
62 void debug_printf(char *fmt, ...);
63 void debug_memdump(void *buf, int len, int L);
64 #define debug(x) (debug_printf x)
65 #define dmemdump(buf,len) debug_memdump (buf, len, 0);
66 #define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
69 #define dmemdump(buf,len)
70 #define dmemdumpl(buf,len)
74 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
78 #define min(x,y) ( (x) < (y) ? (x) : (y) )
81 #define max(x,y) ( (x) > (y) ? (x) : (y) )
84 #define GET_32BIT_LSB_FIRST(cp) \
85 (((unsigned long)(unsigned char)(cp)[0]) | \
86 ((unsigned long)(unsigned char)(cp)[1] << 8) | \
87 ((unsigned long)(unsigned char)(cp)[2] << 16) | \
88 ((unsigned long)(unsigned char)(cp)[3] << 24))
90 #define PUT_32BIT_LSB_FIRST(cp, value) ( \
91 (cp)[0] = (unsigned char)(value), \
92 (cp)[1] = (unsigned char)((value) >> 8), \
93 (cp)[2] = (unsigned char)((value) >> 16), \
94 (cp)[3] = (unsigned char)((value) >> 24) )
96 #define GET_16BIT_LSB_FIRST(cp) \
97 (((unsigned long)(unsigned char)(cp)[0]) | \
98 ((unsigned long)(unsigned char)(cp)[1] << 8))
100 #define PUT_16BIT_LSB_FIRST(cp, value) ( \
101 (cp)[0] = (unsigned char)(value), \
102 (cp)[1] = (unsigned char)((value) >> 8) )
104 #define GET_32BIT_MSB_FIRST(cp) \
105 (((unsigned long)(unsigned char)(cp)[0] << 24) | \
106 ((unsigned long)(unsigned char)(cp)[1] << 16) | \
107 ((unsigned long)(unsigned char)(cp)[2] << 8) | \
108 ((unsigned long)(unsigned char)(cp)[3]))
110 #define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
112 #define PUT_32BIT_MSB_FIRST(cp, value) ( \
113 (cp)[0] = (unsigned char)((value) >> 24), \
114 (cp)[1] = (unsigned char)((value) >> 16), \
115 (cp)[2] = (unsigned char)((value) >> 8), \
116 (cp)[3] = (unsigned char)(value) )
118 #define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
120 #define GET_16BIT_MSB_FIRST(cp) \
121 (((unsigned long)(unsigned char)(cp)[0] << 8) | \
122 ((unsigned long)(unsigned char)(cp)[1]))
124 #define PUT_16BIT_MSB_FIRST(cp, value) ( \
125 (cp)[0] = (unsigned char)((value) >> 8), \
126 (cp)[1] = (unsigned char)(value) )