db9c0f86 |
1 | #ifndef PUTTY_MISC_H |
2 | #define PUTTY_MISC_H |
3 | |
4 | #include "puttymem.h" |
5 | |
39934deb |
6 | #include <stdio.h> /* for FILE * */ |
57356d63 |
7 | #include <stdarg.h> /* for va_list */ |
d72d0e81 |
8 | #include <time.h> /* for struct tm */ |
57356d63 |
9 | |
3f2d010c |
10 | #ifndef FALSE |
11 | #define FALSE 0 |
12 | #endif |
13 | #ifndef TRUE |
14 | #define TRUE 1 |
15 | #endif |
16 | |
9a30e26b |
17 | typedef struct Filename Filename; |
18 | typedef struct FontSpec FontSpec; |
19 | |
d57f70af |
20 | unsigned long parse_blocksize(const char *bs); |
d45d4c07 |
21 | char ctrlparse(char *s, char **next); |
d57f70af |
22 | |
57356d63 |
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); |
03f64569 |
27 | |
39934deb |
28 | char *fgetline(FILE *fp); |
29 | |
1549e076 |
30 | void base64_encode_atom(unsigned char *data, int n, char *out); |
31 | |
5471d09a |
32 | struct bufchain_granule; |
33 | typedef struct bufchain_tag { |
34 | struct bufchain_granule *head, *tail; |
35 | int buffersize; /* current amount of buffered data */ |
36 | } bufchain; |
37 | |
38 | void bufchain_init(bufchain *ch); |
39 | void bufchain_clear(bufchain *ch); |
40 | int bufchain_size(bufchain *ch); |
e0e7dff8 |
41 | void bufchain_add(bufchain *ch, const void *data, int len); |
5471d09a |
42 | void bufchain_prefix(bufchain *ch, void **data, int *len); |
43 | void bufchain_consume(bufchain *ch, int len); |
7983f47e |
44 | void bufchain_fetch(bufchain *ch, void *data, int len); |
db9c0f86 |
45 | |
aca589d9 |
46 | struct tm ltime(void); |
47 | |
db9c0f86 |
48 | /* |
49 | * Debugging functions. |
50 | * |
51 | * Output goes to debug.log |
52 | * |
53 | * debug(()) (note the double brackets) is like printf(). |
54 | * |
55 | * dmemdump() and dmemdumpl() both do memory dumps. The difference |
523c5dd3 |
56 | * is that dmemdumpl() is more suited for when the memory address is |
db9c0f86 |
57 | * important (say because you'll be recording pointer values later |
58 | * on). dmemdump() is more concise. |
59 | */ |
60 | |
61 | #ifdef DEBUG |
d0912d1f |
62 | void debug_printf(char *fmt, ...); |
32874aea |
63 | void debug_memdump(void *buf, int len, int L); |
d0912d1f |
64 | #define debug(x) (debug_printf x) |
db9c0f86 |
65 | #define dmemdump(buf,len) debug_memdump (buf, len, 0); |
66 | #define dmemdumpl(buf,len) debug_memdump (buf, len, 1); |
67 | #else |
68 | #define debug(x) |
69 | #define dmemdump(buf,len) |
70 | #define dmemdumpl(buf,len) |
71 | #endif |
72 | |
db9c0f86 |
73 | #ifndef lenof |
74 | #define lenof(x) ( (sizeof((x))) / (sizeof(*(x)))) |
75 | #endif |
76 | |
1709795f |
77 | #ifndef min |
78 | #define min(x,y) ( (x) < (y) ? (x) : (y) ) |
79 | #endif |
80 | #ifndef max |
7ffb2b52 |
81 | #define max(x,y) ( (x) > (y) ? (x) : (y) ) |
1709795f |
82 | #endif |
db9c0f86 |
83 | |
51e9d3c0 |
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)) |
89 | |
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) ) |
95 | |
96 | #define GET_16BIT_LSB_FIRST(cp) \ |
97 | (((unsigned long)(unsigned char)(cp)[0]) | \ |
98 | ((unsigned long)(unsigned char)(cp)[1] << 8)) |
99 | |
100 | #define PUT_16BIT_LSB_FIRST(cp, value) ( \ |
101 | (cp)[0] = (unsigned char)(value), \ |
102 | (cp)[1] = (unsigned char)((value) >> 8) ) |
103 | |
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])) |
109 | |
110 | #define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp) |
111 | |
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) ) |
117 | |
118 | #define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value) |
119 | |
120 | #define GET_16BIT_MSB_FIRST(cp) \ |
121 | (((unsigned long)(unsigned char)(cp)[0] << 8) | \ |
122 | ((unsigned long)(unsigned char)(cp)[1])) |
123 | |
124 | #define PUT_16BIT_MSB_FIRST(cp, value) ( \ |
125 | (cp)[0] = (unsigned char)((value) >> 8), \ |
126 | (cp)[1] = (unsigned char)(value) ) |
127 | |
db9c0f86 |
128 | #endif |