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 char *dupstr(const char *s
);
28 char *dupcat(const char *s1
, ...);
29 char *dupprintf(const char *fmt
, ...);
30 char *dupvprintf(const char *fmt
, va_list ap
);
31 void burnstr(char *string
);
33 char *fgetline(FILE *fp
);
35 void base64_encode_atom(unsigned char *data
, int n
, char *out
);
37 struct bufchain_granule
;
38 typedef struct bufchain_tag
{
39 struct bufchain_granule
*head
, *tail
;
40 int buffersize
; /* current amount of buffered data */
43 void bufchain_init(bufchain
*ch
);
44 void bufchain_clear(bufchain
*ch
);
45 int bufchain_size(bufchain
*ch
);
46 void bufchain_add(bufchain
*ch
, const void *data
, int len
);
47 void bufchain_prefix(bufchain
*ch
, void **data
, int *len
);
48 void bufchain_consume(bufchain
*ch
, int len
);
49 void bufchain_fetch(bufchain
*ch
, void *data
, int len
);
51 struct tm
ltime(void);
53 void smemclr(void *b
, size_t len
);
56 * Debugging functions.
58 * Output goes to debug.log
60 * debug(()) (note the double brackets) is like printf().
62 * dmemdump() and dmemdumpl() both do memory dumps. The difference
63 * is that dmemdumpl() is more suited for when the memory address is
64 * important (say because you'll be recording pointer values later
65 * on). dmemdump() is more concise.
69 void debug_printf(char *fmt
, ...);
70 void debug_memdump(void *buf
, int len
, int L
);
71 #define debug(x) (debug_printf x)
72 #define dmemdump(buf,len) debug_memdump (buf, len, 0);
73 #define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
76 #define dmemdump(buf,len)
77 #define dmemdumpl(buf,len)
81 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
85 #define min(x,y) ( (x) < (y) ? (x) : (y) )
88 #define max(x,y) ( (x) > (y) ? (x) : (y) )
91 #define GET_32BIT_LSB_FIRST(cp) \
92 (((unsigned long)(unsigned char)(cp)[0]) | \
93 ((unsigned long)(unsigned char)(cp)[1] << 8) | \
94 ((unsigned long)(unsigned char)(cp)[2] << 16) | \
95 ((unsigned long)(unsigned char)(cp)[3] << 24))
97 #define PUT_32BIT_LSB_FIRST(cp, value) ( \
98 (cp)[0] = (unsigned char)(value), \
99 (cp)[1] = (unsigned char)((value) >> 8), \
100 (cp)[2] = (unsigned char)((value) >> 16), \
101 (cp)[3] = (unsigned char)((value) >> 24) )
103 #define GET_16BIT_LSB_FIRST(cp) \
104 (((unsigned long)(unsigned char)(cp)[0]) | \
105 ((unsigned long)(unsigned char)(cp)[1] << 8))
107 #define PUT_16BIT_LSB_FIRST(cp, value) ( \
108 (cp)[0] = (unsigned char)(value), \
109 (cp)[1] = (unsigned char)((value) >> 8) )
111 #define GET_32BIT_MSB_FIRST(cp) \
112 (((unsigned long)(unsigned char)(cp)[0] << 24) | \
113 ((unsigned long)(unsigned char)(cp)[1] << 16) | \
114 ((unsigned long)(unsigned char)(cp)[2] << 8) | \
115 ((unsigned long)(unsigned char)(cp)[3]))
117 #define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
119 #define PUT_32BIT_MSB_FIRST(cp, value) ( \
120 (cp)[0] = (unsigned char)((value) >> 24), \
121 (cp)[1] = (unsigned char)((value) >> 16), \
122 (cp)[2] = (unsigned char)((value) >> 8), \
123 (cp)[3] = (unsigned char)(value) )
125 #define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
127 #define GET_16BIT_MSB_FIRST(cp) \
128 (((unsigned long)(unsigned char)(cp)[0] << 8) | \
129 ((unsigned long)(unsigned char)(cp)[1]))
131 #define PUT_16BIT_MSB_FIRST(cp, value) ( \
132 (cp)[0] = (unsigned char)((value) >> 8), \
133 (cp)[1] = (unsigned char)(value) )