8 #include "puttymem.h"
\r
10 #include <stdio.h> /* for FILE * */
\r
11 #include <stdarg.h> /* for va_list */
\r
12 #include <time.h> /* for struct tm */
\r
21 typedef struct Filename Filename;
\r
22 typedef struct FontSpec FontSpec;
\r
24 unsigned long parse_blocksize(const char *bs);
\r
25 char ctrlparse(char *s, char **next);
\r
27 char *dupstr(const char *s);
\r
28 char *dupcat(const char *s1, ...);
\r
29 char *dupprintf(const char *fmt, ...);
\r
30 char *dupvprintf(const char *fmt, va_list ap);
\r
31 void burnstr(char *string);
\r
33 int toint(unsigned);
\r
35 char *fgetline(FILE *fp);
\r
37 void base64_encode_atom(unsigned char *data, int n, char *out);
\r
39 struct bufchain_granule;
\r
40 typedef struct bufchain_tag {
\r
41 struct bufchain_granule *head, *tail;
\r
42 int buffersize; /* current amount of buffered data */
\r
45 void bufchain_init(bufchain *ch);
\r
46 void bufchain_clear(bufchain *ch);
\r
47 int bufchain_size(bufchain *ch);
\r
48 void bufchain_add(bufchain *ch, const void *data, int len);
\r
49 void bufchain_prefix(bufchain *ch, void **data, int *len);
\r
50 void bufchain_consume(bufchain *ch, int len);
\r
51 void bufchain_fetch(bufchain *ch, void *data, int len);
\r
53 struct tm ltime(void);
\r
55 void smemclr(void *b, size_t len);
\r
58 * Debugging functions.
\r
60 * Output goes to debug.log
\r
62 * debug(()) (note the double brackets) is like printf().
\r
64 * dmemdump() and dmemdumpl() both do memory dumps. The difference
\r
65 * is that dmemdumpl() is more suited for when the memory address is
\r
66 * important (say because you'll be recording pointer values later
\r
67 * on). dmemdump() is more concise.
\r
71 void debug_printf(char *fmt, ...);
\r
72 void debug_memdump(void *buf, int len, int L);
\r
73 #define debug(x) (debug_printf x)
\r
74 #define dmemdump(buf,len) debug_memdump (buf, len, 0);
\r
75 #define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
\r
78 #define dmemdump(buf,len)
\r
79 #define dmemdumpl(buf,len)
\r
83 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
\r
87 #define min(x,y) ( (x) < (y) ? (x) : (y) )
\r
90 #define max(x,y) ( (x) > (y) ? (x) : (y) )
\r
93 #define GET_32BIT_LSB_FIRST(cp) \
\r
94 (((unsigned long)(unsigned char)(cp)[0]) | \
\r
95 ((unsigned long)(unsigned char)(cp)[1] << 8) | \
\r
96 ((unsigned long)(unsigned char)(cp)[2] << 16) | \
\r
97 ((unsigned long)(unsigned char)(cp)[3] << 24))
\r
99 #define PUT_32BIT_LSB_FIRST(cp, value) ( \
\r
100 (cp)[0] = (unsigned char)(value), \
\r
101 (cp)[1] = (unsigned char)((value) >> 8), \
\r
102 (cp)[2] = (unsigned char)((value) >> 16), \
\r
103 (cp)[3] = (unsigned char)((value) >> 24) )
\r
105 #define GET_16BIT_LSB_FIRST(cp) \
\r
106 (((unsigned long)(unsigned char)(cp)[0]) | \
\r
107 ((unsigned long)(unsigned char)(cp)[1] << 8))
\r
109 #define PUT_16BIT_LSB_FIRST(cp, value) ( \
\r
110 (cp)[0] = (unsigned char)(value), \
\r
111 (cp)[1] = (unsigned char)((value) >> 8) )
\r
113 #define GET_32BIT_MSB_FIRST(cp) \
\r
114 (((unsigned long)(unsigned char)(cp)[0] << 24) | \
\r
115 ((unsigned long)(unsigned char)(cp)[1] << 16) | \
\r
116 ((unsigned long)(unsigned char)(cp)[2] << 8) | \
\r
117 ((unsigned long)(unsigned char)(cp)[3]))
\r
119 #define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
\r
121 #define PUT_32BIT_MSB_FIRST(cp, value) ( \
\r
122 (cp)[0] = (unsigned char)((value) >> 24), \
\r
123 (cp)[1] = (unsigned char)((value) >> 16), \
\r
124 (cp)[2] = (unsigned char)((value) >> 8), \
\r
125 (cp)[3] = (unsigned char)(value) )
\r
127 #define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
\r
129 #define GET_16BIT_MSB_FIRST(cp) \
\r
130 (((unsigned long)(unsigned char)(cp)[0] << 8) | \
\r
131 ((unsigned long)(unsigned char)(cp)[1]))
\r
133 #define PUT_16BIT_MSB_FIRST(cp, value) ( \
\r
134 (cp)[0] = (unsigned char)((value) >> 8), \
\r
135 (cp)[1] = (unsigned char)(value) )
\r