Created new data types `Filename' and `FontSpec', intended to be
[u/mdw/putty] / misc.h
1 #ifndef PUTTY_MISC_H
2 #define PUTTY_MISC_H
3
4 #include "puttymem.h"
5
6 #include <stdarg.h> /* for va_list */
7
8 #ifndef FALSE
9 #define FALSE 0
10 #endif
11 #ifndef TRUE
12 #define TRUE 1
13 #endif
14
15 typedef struct Filename Filename;
16 typedef struct FontSpec FontSpec;
17
18 char *dupstr(const char *s);
19 char *dupcat(const char *s1, ...);
20 char *dupprintf(const char *fmt, ...);
21 char *dupvprintf(const char *fmt, va_list ap);
22
23 void base64_encode_atom(unsigned char *data, int n, char *out);
24
25 struct bufchain_granule;
26 typedef struct bufchain_tag {
27 struct bufchain_granule *head, *tail;
28 int buffersize; /* current amount of buffered data */
29 } bufchain;
30
31 void bufchain_init(bufchain *ch);
32 void bufchain_clear(bufchain *ch);
33 int bufchain_size(bufchain *ch);
34 void bufchain_add(bufchain *ch, const void *data, int len);
35 void bufchain_prefix(bufchain *ch, void **data, int *len);
36 void bufchain_consume(bufchain *ch, int len);
37 void bufchain_fetch(bufchain *ch, void *data, int len);
38
39 /*
40 * Debugging functions.
41 *
42 * Output goes to debug.log
43 *
44 * debug(()) (note the double brackets) is like printf().
45 *
46 * dmemdump() and dmemdumpl() both do memory dumps. The difference
47 * is that dmemdumpl() is more suited for when where the memory is is
48 * important (say because you'll be recording pointer values later
49 * on). dmemdump() is more concise.
50 */
51
52 #ifdef DEBUG
53 void dprintf(char *fmt, ...);
54 void debug_memdump(void *buf, int len, int L);
55 #define debug(x) (dprintf x)
56 #define dmemdump(buf,len) debug_memdump (buf, len, 0);
57 #define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
58 #else
59 #define debug(x)
60 #define dmemdump(buf,len)
61 #define dmemdumpl(buf,len)
62 #endif
63
64 #ifndef lenof
65 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
66 #endif
67
68 #ifndef min
69 #define min(x,y) ( (x) < (y) ? (x) : (y) )
70 #endif
71 #ifndef max
72 #define max(x,y) ( (x) > (y) ? (x) : (y) )
73 #endif
74
75 #endif