]> asedeno.scripts.mit.edu Git - PuTTY_svn.git/blob - misc.h
Enable xterm mouse reporting of wheel actions in GTK.
[PuTTY_svn.git] / misc.h
1 /*
2  * Header for misc.c.
3  */
4
5 #ifndef PUTTY_MISC_H
6 #define PUTTY_MISC_H
7
8 #include "puttymem.h"
9
10 #include <stdio.h>                     /* for FILE * */
11 #include <stdarg.h>                    /* for va_list */
12 #include <time.h>                      /* for struct tm */
13
14 #ifndef FALSE
15 #define FALSE 0
16 #endif
17 #ifndef TRUE
18 #define TRUE 1
19 #endif
20
21 typedef struct Filename Filename;
22 typedef struct FontSpec FontSpec;
23
24 unsigned long parse_blocksize(const char *bs);
25 char ctrlparse(char *s, char **next);
26
27 size_t host_strcspn(const char *s, const char *set);
28 char *host_strchr(const char *s, int c);
29 char *host_strrchr(const char *s, int c);
30 char *host_strduptrim(const char *s);
31
32 char *dupstr(const char *s);
33 char *dupcat(const char *s1, ...);
34 char *dupprintf(const char *fmt, ...)
35 #ifdef __GNUC__
36     __attribute__ ((format (printf, 1, 2)))
37 #endif
38     ;
39 char *dupvprintf(const char *fmt, va_list ap);
40 void burnstr(char *string);
41
42 int toint(unsigned);
43
44 char *fgetline(FILE *fp);
45
46 void base64_encode_atom(unsigned char *data, int n, char *out);
47
48 struct bufchain_granule;
49 typedef struct bufchain_tag {
50     struct bufchain_granule *head, *tail;
51     int buffersize;                    /* current amount of buffered data */
52 } bufchain;
53
54 void bufchain_init(bufchain *ch);
55 void bufchain_clear(bufchain *ch);
56 int bufchain_size(bufchain *ch);
57 void bufchain_add(bufchain *ch, const void *data, int len);
58 void bufchain_prefix(bufchain *ch, void **data, int *len);
59 void bufchain_consume(bufchain *ch, int len);
60 void bufchain_fetch(bufchain *ch, void *data, int len);
61
62 struct tm ltime(void);
63
64 void smemclr(void *b, size_t len);
65
66 /*
67  * Debugging functions.
68  *
69  * Output goes to debug.log
70  *
71  * debug(()) (note the double brackets) is like printf().
72  *
73  * dmemdump() and dmemdumpl() both do memory dumps.  The difference
74  * is that dmemdumpl() is more suited for when the memory address is
75  * important (say because you'll be recording pointer values later
76  * on).  dmemdump() is more concise.
77  */
78
79 #ifdef DEBUG
80 void debug_printf(char *fmt, ...);
81 void debug_memdump(void *buf, int len, int L);
82 #define debug(x) (debug_printf x)
83 #define dmemdump(buf,len) debug_memdump (buf, len, 0);
84 #define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
85 #else
86 #define debug(x)
87 #define dmemdump(buf,len)
88 #define dmemdumpl(buf,len)
89 #endif
90
91 #ifndef lenof
92 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
93 #endif
94
95 #ifndef min
96 #define min(x,y) ( (x) < (y) ? (x) : (y) )
97 #endif
98 #ifndef max
99 #define max(x,y) ( (x) > (y) ? (x) : (y) )
100 #endif
101
102 #define GET_32BIT_LSB_FIRST(cp) \
103   (((unsigned long)(unsigned char)(cp)[0]) | \
104   ((unsigned long)(unsigned char)(cp)[1] << 8) | \
105   ((unsigned long)(unsigned char)(cp)[2] << 16) | \
106   ((unsigned long)(unsigned char)(cp)[3] << 24))
107
108 #define PUT_32BIT_LSB_FIRST(cp, value) ( \
109   (cp)[0] = (unsigned char)(value), \
110   (cp)[1] = (unsigned char)((value) >> 8), \
111   (cp)[2] = (unsigned char)((value) >> 16), \
112   (cp)[3] = (unsigned char)((value) >> 24) )
113
114 #define GET_16BIT_LSB_FIRST(cp) \
115   (((unsigned long)(unsigned char)(cp)[0]) | \
116   ((unsigned long)(unsigned char)(cp)[1] << 8))
117
118 #define PUT_16BIT_LSB_FIRST(cp, value) ( \
119   (cp)[0] = (unsigned char)(value), \
120   (cp)[1] = (unsigned char)((value) >> 8) )
121
122 #define GET_32BIT_MSB_FIRST(cp) \
123   (((unsigned long)(unsigned char)(cp)[0] << 24) | \
124   ((unsigned long)(unsigned char)(cp)[1] << 16) | \
125   ((unsigned long)(unsigned char)(cp)[2] << 8) | \
126   ((unsigned long)(unsigned char)(cp)[3]))
127
128 #define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
129
130 #define PUT_32BIT_MSB_FIRST(cp, value) ( \
131   (cp)[0] = (unsigned char)((value) >> 24), \
132   (cp)[1] = (unsigned char)((value) >> 16), \
133   (cp)[2] = (unsigned char)((value) >> 8), \
134   (cp)[3] = (unsigned char)(value) )
135
136 #define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
137
138 #define GET_16BIT_MSB_FIRST(cp) \
139   (((unsigned long)(unsigned char)(cp)[0] << 8) | \
140   ((unsigned long)(unsigned char)(cp)[1]))
141
142 #define PUT_16BIT_MSB_FIRST(cp, value) ( \
143   (cp)[0] = (unsigned char)((value) >> 8), \
144   (cp)[1] = (unsigned char)(value) )
145
146 #endif