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