]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - putty.h
Various cleanups, mostly Mac-related.
[PuTTY.git] / putty.h
1 #ifndef PUTTY_PUTTY_H
2 #define PUTTY_PUTTY_H
3
4 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
5
6 #ifdef macintosh
7 #include <MacTypes.h>
8 typedef UInt32 DWORD;
9 #endif /* macintosh */
10
11 #ifndef TRUE
12 #define TRUE 1
13 #endif
14 #ifndef FALSE
15 #define FALSE 0
16 #endif
17
18 #define ATTR_ACTCURS 0x80000000UL      /* active cursor (block) */
19 #define ATTR_PASCURS 0x40000000UL      /* passive cursor (box) */
20 #define ATTR_INVALID 0x20000000UL
21 #define ATTR_WRAPPED 0x10000000UL
22
23 #define ATTR_ASCII   0x00000000UL      /* normal ASCII charset ESC ( B */
24 #define ATTR_GBCHR   0x00100000UL      /* UK variant   charset ESC ( A */
25 #define ATTR_LINEDRW 0x00200000UL      /* line drawing charset ESC ( 0 */
26
27 #define ATTR_BOLD    0x00000100UL
28 #define ATTR_UNDER   0x00000200UL
29 #define ATTR_REVERSE 0x00000400UL
30 #define ATTR_FGMASK  0x0000F000UL
31 #define ATTR_BGMASK  0x000F0000UL
32 #define ATTR_FGSHIFT 12
33 #define ATTR_BGSHIFT 16
34
35 #define ATTR_DEFAULT 0x00098000UL
36 #define ATTR_DEFFG   0x00008000UL
37 #define ATTR_DEFBG   0x00090000UL
38 #define ATTR_CUR_XOR 0x000BA000UL
39 #define ERASE_CHAR   (ATTR_DEFAULT | ' ')
40 #define ATTR_MASK    0xFFFFFF00UL
41 #define CHAR_MASK    0x000000FFUL
42
43 #ifdef macintosh
44 typedef void *Context; /* Temporarily until I work out what it should really be */
45 #else /* not macintosh */
46 typedef HDC Context;
47 #endif /* not macintosh */
48
49 #define SEL_NL { 13, 10 }
50
51 /*
52  * Global variables. Most modules declare these `extern', but
53  * window.c will do `#define PUTTY_DO_GLOBALS' before including this
54  * module, and so will get them properly defined.
55  */
56 #ifdef PUTTY_DO_GLOBALS
57 #define GLOBAL
58 #else
59 #define GLOBAL extern
60 #endif
61
62 GLOBAL int rows, cols, savelines;
63
64 GLOBAL int font_width, font_height;
65
66 #define INBUF_SIZE 2048
67 #define INBUF_MASK (INBUF_SIZE-1)
68 GLOBAL unsigned char inbuf[INBUF_SIZE];
69 GLOBAL int inbuf_head, inbuf_reap;
70
71 #define OUTBUF_SIZE 2048
72 #define OUTBUF_MASK (OUTBUF_SIZE-1)
73 GLOBAL unsigned char outbuf[OUTBUF_SIZE];
74 GLOBAL int outbuf_head, outbuf_reap;
75
76 GLOBAL int has_focus;
77
78 GLOBAL int app_cursor_keys, app_keypad_keys;
79
80 #define WM_NETEVENT  (WM_USER + 1)
81
82 typedef enum {
83     TS_AYT, TS_BRK, TS_SYNCH, TS_EC, TS_EL, TS_GA, TS_NOP, TS_ABORT,
84     TS_AO, TS_IP, TS_SUSP, TS_EOR, TS_EOF
85 } Telnet_Special;
86
87 typedef enum {
88     MB_NOTHING, MB_SELECT, MB_EXTEND, MB_PASTE
89 } Mouse_Button;
90
91 typedef enum {
92     MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
93 } Mouse_Action;
94
95 typedef enum {
96     VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN
97 } VT_Mode;
98
99 typedef struct {
100 #ifdef macintosh
101         char *(*init) (char *host, int port, char **realhost);
102         int (*msg)(void);
103 #else /* not macintosh */
104     char *(*init) (HWND hwnd, char *host, int port, char **realhost);
105     int (*msg) (WPARAM wParam, LPARAM lParam);
106 #endif /* not macintosh */
107     void (*send) (char *buf, int len);
108     void (*size) (void);
109     void (*special) (Telnet_Special code);
110 } Backend;
111
112 GLOBAL Backend *back;
113
114 typedef struct {
115     /* Basic options */
116     char host[512];
117     int port;
118     enum { PROT_TELNET, PROT_SSH } protocol;
119     int close_on_exit;
120     /* SSH options */
121     int nopty;
122     /* Telnet options */
123     char termtype[32];
124     char termspeed[32];
125     char environmt[1024];                    /* VAR\tvalue\0VAR\tvalue\0\0 */
126     char username[32];
127     int rfc_environ;
128     /* Keyboard options */
129     int bksp_is_delete;
130     int rxvt_homeend;
131     int linux_funkeys;
132     int app_cursor;
133     int app_keypad;
134     /* Terminal options */
135     int savelines;
136     int dec_om;
137     int wrap_mode;
138     int lfhascr;
139     int win_name_always;
140     int width, height;
141     char font[64];
142     int fontisbold;
143     int fontheight;
144     VT_Mode vtmode;
145     /* Colour options */
146     int try_palette;
147     int bold_colour;
148     unsigned char colours[22][3];
149     /* Selection options */
150     int mouse_is_xterm;
151     short wordness[256];
152 } Config;
153
154 GLOBAL Config cfg;
155
156 /*
157  * Exports from window.c.
158  */
159 void request_resize (int, int);
160 void do_text (Context, int, int, char *, int, unsigned long);
161 void set_title (char *);
162 void set_icon (char *);
163 void set_sbar (int, int, int);
164 Context get_ctx();
165 void free_ctx (Context);
166 void palette_set (int, int, int, int);
167 void palette_reset (void);
168 void write_clip (void *, int);
169 void get_clip (void **, int *);
170 void optimised_move (int, int, int);
171 void fatalbox (const char *, ...);
172 void beep (void);
173 #define OPTIMISE_IS_SCROLL 1
174
175 /*
176  * Exports from noise.c.
177  */
178 void noise_get_heavy(void (*func) (void *, int));
179 void noise_get_light(void (*func) (void *, int));
180 void noise_ultralight(DWORD data);
181 void random_save_seed(void);
182
183 #ifndef macintosh
184 /*
185  * Exports from windlg.c.
186  */
187 int do_config (void);
188 int do_reconfig (HWND);
189 void do_defaults (char *);
190 void lognegot (char *);
191 void shownegot (HWND);
192 void showabout (HWND);
193 void verify_ssh_host_key(char *host, struct RSAKey *key);
194 #endif
195
196 /*
197  * Exports from terminal.c.
198  */
199
200 void term_init (void);
201 void term_size (int, int, int);
202 void term_out (void);
203 void term_paint (Context, int, int, int, int);
204 void term_scroll (int, int);
205 void term_pwron (void);
206 void term_clrsb (void);
207 void term_mouse (Mouse_Button, Mouse_Action, int, int);
208 void term_deselect (void);
209 void term_update (void);
210 void term_invalidate(void);
211
212 /*
213  * Exports from telnet.c.
214  */
215
216 Backend telnet_backend;
217
218 /*
219  * Exports from ssh.c.
220  */
221
222 Backend ssh_backend;
223
224 /*
225  * Exports from sshrand.c.
226  */
227
228 void random_add_noise(void *noise, int length);
229 void random_init(void);
230 int random_byte(void);
231 void random_get_savedata(void **data, int *len);
232
233 /*
234  * Exports from misc.c.
235  */
236
237 /* #define MALLOC_LOG  do this if you suspect putty of leaking memory */
238 #ifdef MALLOC_LOG
239 #define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
240 #define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
241 #define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
242 void mlog(char *, int);
243 #else
244 #define smalloc safemalloc
245 #define srealloc saferealloc
246 #define sfree safefree
247 #endif
248
249 void *safemalloc(size_t);
250 void *saferealloc(void *, size_t);
251 void safefree(void *);
252
253 /*
254  * Exports from version.c.
255  */
256 extern char ver[];
257
258 /*
259  * A debug system.
260  */
261 #ifdef DEBUG
262 #include <stdarg.h>
263 #define debug(x) (dprintf x)
264 static void dprintf(char *fmt, ...) {
265     char buf[2048];
266     DWORD dw;
267     va_list ap;
268     static int gotconsole = 0;
269
270     if (!gotconsole) {
271         AllocConsole();
272         gotconsole = 1;
273     }
274
275     va_start(ap, fmt);
276     vsprintf(buf, fmt, ap);
277     WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);
278     va_end(ap);
279 }
280 #else
281 #define debug(x)
282 #endif
283
284 #endif