Created new data types `Filename' and `FontSpec', intended to be
[u/mdw/putty] / misc.h
... / ...
CommitLineData
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
15typedef struct Filename Filename;
16typedef struct FontSpec FontSpec;
17
18char *dupstr(const char *s);
19char *dupcat(const char *s1, ...);
20char *dupprintf(const char *fmt, ...);
21char *dupvprintf(const char *fmt, va_list ap);
22
23void base64_encode_atom(unsigned char *data, int n, char *out);
24
25struct bufchain_granule;
26typedef struct bufchain_tag {
27 struct bufchain_granule *head, *tail;
28 int buffersize; /* current amount of buffered data */
29} bufchain;
30
31void bufchain_init(bufchain *ch);
32void bufchain_clear(bufchain *ch);
33int bufchain_size(bufchain *ch);
34void bufchain_add(bufchain *ch, const void *data, int len);
35void bufchain_prefix(bufchain *ch, void **data, int *len);
36void bufchain_consume(bufchain *ch, int len);
37void 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
53void dprintf(char *fmt, ...);
54void 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