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