]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - putty.h
The "about" box now behaves approximately as it should (though we still don't
[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 #include <Controls.h>
14 #include <Windows.h>
15 typedef UInt32 DWORD;
16 #endif /* macintosh */
17
18 #ifndef TRUE
19 #define TRUE 1
20 #endif
21 #ifndef FALSE
22 #define FALSE 0
23 #endif
24
25 #define ATTR_ACTCURS 0x80000000UL      /* active cursor (block) */
26 #define ATTR_PASCURS 0x40000000UL      /* passive cursor (box) */
27 #define ATTR_INVALID 0x20000000UL
28 #define ATTR_WRAPPED 0x10000000UL
29
30 #define ATTR_ASCII   0x00000000UL      /* normal ASCII charset ESC ( B */
31 #define ATTR_GBCHR   0x00100000UL      /* UK variant   charset ESC ( A */
32 #define ATTR_LINEDRW 0x00200000UL      /* line drawing charset ESC ( 0 */
33
34 #define ATTR_BOLD    0x00000100UL
35 #define ATTR_UNDER   0x00000200UL
36 #define ATTR_REVERSE 0x00000400UL
37 #define ATTR_FGMASK  0x0000F000UL
38 #define ATTR_BGMASK  0x000F0000UL
39 #define ATTR_FGSHIFT 12
40 #define ATTR_BGSHIFT 16
41
42 #define ATTR_DEFAULT 0x00098000UL
43 #define ATTR_DEFFG   0x00008000UL
44 #define ATTR_DEFBG   0x00090000UL
45 #define ATTR_CUR_XOR 0x000BA000UL
46 #define ERASE_CHAR   (ATTR_DEFAULT | ' ')
47 #define ATTR_MASK    0xFFFFFF00UL
48 #define CHAR_MASK    0x000000FFUL
49
50 #ifdef macintosh
51 #define SEL_NL { 13 }
52 #else
53 #define SEL_NL { 13, 10 }
54 #endif
55
56 /*
57  * Global variables. Most modules declare these `extern', but
58  * window.c will do `#define PUTTY_DO_GLOBALS' before including this
59  * module, and so will get them properly defined.
60  */
61 #ifdef PUTTY_DO_GLOBALS
62 #define GLOBAL
63 #else
64 #define GLOBAL extern
65 #endif
66
67 #define INBUF_SIZE 2048
68 #define INBUF_MASK (INBUF_SIZE-1)
69
70 #define OUTBUF_SIZE 2048
71 #define OUTBUF_MASK (OUTBUF_SIZE-1)
72
73 #define WM_NETEVENT  (WM_USER + 1)
74
75 typedef enum {
76     TS_AYT, TS_BRK, TS_SYNCH, TS_EC, TS_EL, TS_GA, TS_NOP, TS_ABORT,
77     TS_AO, TS_IP, TS_SUSP, TS_EOR, TS_EOF
78 } Telnet_Special;
79
80 typedef enum {
81     MB_NOTHING, MB_SELECT, MB_EXTEND, MB_PASTE
82 } Mouse_Button;
83
84 typedef enum {
85     MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
86 } Mouse_Action;
87
88 typedef enum {
89     VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN
90 } VT_Mode;
91
92 typedef struct Session Session;
93
94 typedef struct {
95 #ifdef macintosh
96         char *(*init) (Session *, char *host, int port, char **realhost);
97         int (*msg)(Session *);
98 #else /* not macintosh */
99     char *(*init) (HWND hwnd, char *host, int port, char **realhost);
100     int (*msg) (WPARAM wParam, LPARAM lParam);
101 #endif /* not macintosh */
102     void (*send) (Session *, char *buf, int len);
103     void (*size) (Session *);
104     void (*special) (Session *, Telnet_Special code);
105 } Backend;
106
107 typedef struct {
108     /* Basic options */
109     char host[512];
110     int port;
111     enum { PROT_TELNET, PROT_SSH } protocol;
112     int close_on_exit;
113     /* SSH options */
114     int nopty;
115     /* Telnet options */
116     char termtype[32];
117     char termspeed[32];
118     char environmt[1024];                    /* VAR\tvalue\0VAR\tvalue\0\0 */
119     char username[32];
120     int rfc_environ;
121     /* Keyboard options */
122     int bksp_is_delete;
123     int rxvt_homeend;
124     int linux_funkeys;
125     int app_cursor;
126     int app_keypad;
127     int meta_modifiers;
128     /* Terminal options */
129     int savelines;
130     int dec_om;
131     int wrap_mode;
132     int lfhascr;
133     int win_name_always;
134     int width, height;
135     char font[64];
136     int fontisbold;
137     int fontheight;
138     VT_Mode vtmode;
139     /* Colour options */
140     int try_palette;
141     int bold_colour;
142 #ifdef macintosh
143     PaletteHandle colours;
144 #else /* not macintosh */
145     unsigned char colours[22][3];
146 #endif /* not macintosh */
147     /* Selection options */
148     int implicit_copy;
149 #ifdef macintosh
150     int mouse_is_xterm;
151 #endif
152     short wordness[256];
153 } Config;
154
155 typedef struct {
156     /* Display buffers and pointers within them */
157     unsigned long *text;               /* buffer of text on terminal screen */
158     unsigned long *scrtop;             /* top of working screen */
159     unsigned long *disptop;            /* top of displayed screen */
160     unsigned long *sbtop;              /* top of scrollback */
161     unsigned long *cpos;               /* cursor position (convenience) */
162     unsigned long *disptext;           /* buffer of text on real screen */
163     unsigned long *wanttext;           /* buffer of text we want on screen */
164     unsigned long *alttext;            /* buffer of text on alt. screen */
165     unsigned char *selspace;           /* buffer for building selections in */
166
167     /* Current state */
168     unsigned long curr_attr;
169     int curs_x, curs_y;        /* cursor */
170     int cset;                  /* 0 or 1: which char set is in GL */
171     unsigned long cset_attr[2]; /* G0 and G1 char sets */
172
173     /* Saved state */
174     unsigned long  save_attr;
175     int save_x, save_y;        /* saved cursor position */
176     int save_cset, save_csattr;     /* saved with cursor position */
177
178     int marg_t, marg_b;        /* scroll margins */
179
180     /* Flags */
181     int dec_om;                /* DEC origin mode flag */
182     int wrap, wrapnext;        /* wrap flags */
183     int insert;                /* insert-mode flag */
184     int rvideo;                /* global reverse video flag */
185
186     /*
187      * Saved settings on the alternate screen.
188      */
189     int alt_x, alt_y, alt_om, alt_wrap, alt_wnext, alt_ins, alt_cset;
190     int alt_t, alt_b;
191     int alt_which;
192
193     /* Escape sequence handler state */
194 #define ARGS_MAX 32                    /* max # of esc sequence arguments */
195     int esc_args[ARGS_MAX];
196     int esc_nargs;
197     int esc_query;
198 #define OSC_STR_MAX 2048
199     int osc_strlen;
200     char osc_string[OSC_STR_MAX+1];
201     int osc_w;
202
203     unsigned char *tabs;
204     int nl_count;
205
206     enum {
207         TOPLEVEL, IGNORE_NEXT,
208         SEEN_ESC, SEEN_CSI, SET_GL, SET_GR,
209         SEEN_OSC, SEEN_OSC_P, SEEN_OSC_W, OSC_STRING, OSC_MAYBE_ST,
210         SEEN_ESCHASH
211     } termstate;
212
213     enum {
214         NO_SELECTION, ABOUT_TO, DRAGGING, SELECTED
215     } selstate;
216     enum {
217         SM_CHAR, SM_WORD, SM_LINE
218     } selmode;
219     unsigned long *selstart, *selend, *selanchor;
220     short wordness[256];
221 } Term_State;
222
223 typedef struct Session {
224     /* Config that created this session */
225     Config cfg;
226     /* Terminal emulator internal state */
227     Term_State ts;
228     /* Display state */
229     int rows, cols, savelines;
230     int font_width, font_height;
231     int has_focus;
232     /* Buffers */
233     unsigned char inbuf[INBUF_SIZE];
234     int inbuf_head, inbuf_reap;
235     unsigned char outbuf[OUTBUF_SIZE];
236     int outbuf_head, outbuf_reap;
237     /* Emulator state */
238     int app_cursor_keys, app_keypad_keys;
239     /* Backend */
240     Backend *back;
241     /* Conveniences */
242     unsigned long attr_mask;            /* Mask of attributes to display */
243 #ifdef macintosh
244     short               fontnum;
245     int                 font_ascent;
246     int                 font_leading;
247     int                 font_boldadjust;
248     WindowPtr           window;
249     PaletteHandle       palette;
250     ControlHandle       scrollbar;
251     WCTabHandle         wctab;
252 #endif
253 } Session;
254
255
256 /*
257  * Exports from display system
258  */
259 extern void request_resize(Session *, int, int);
260 extern void do_text(Session *, int, int, char *, int, unsigned long);
261 extern void set_title(Session *, char *);
262 extern void set_icon(Session *, char *);
263 extern void set_sbar(Session *, int, int, int);
264 extern void pre_paint(Session *);
265 extern void post_paint(Session *);
266 extern void palette_set(Session *, int, int, int, int);
267 extern void palette_reset(Session *);
268 void write_clip (void *, int);
269 void get_clip (void **, int *);
270 extern void do_scroll(Session *, int, int, int);
271 void fatalbox (const char *, ...);
272 #ifdef macintosh
273 #pragma noreturn (fatalbox)
274 #endif
275 extern void beep (Session *s);
276 #define OPTIMISE_IS_SCROLL 1
277
278 /*
279  * Exports from noise.c.
280  */
281 void noise_get_heavy(void (*func) (void *, int));
282 void noise_get_light(void (*func) (void *, int));
283 void noise_ultralight(DWORD data);
284 void random_save_seed(void);
285
286 #ifndef macintosh
287 /*
288  * Exports from windlg.c.
289  */
290 int do_config (void);
291 int do_reconfig (HWND);
292 void do_defaults (char *);
293 void lognegot (char *);
294 void shownegot (HWND);
295 void showabout (HWND);
296 void verify_ssh_host_key(char *host, struct RSAKey *key);
297 #endif
298
299 /*
300  * Exports from terminal.c.
301  */
302
303 extern void term_init(Session *);
304 extern void term_size(Session *, int, int, int);
305 extern void term_out(Session *);
306 extern void term_paint(Session *, int, int, int, int);
307 extern void term_scroll(Session *, int, int);
308 extern void term_pwron(Session *);
309 extern void term_clrsb(Session *);
310 extern void term_mouse(Session *, Mouse_Button, Mouse_Action, int, int);
311 extern void term_copy(Session *);
312 extern void term_paste(Session *);
313 extern int term_hasselection(Session *);
314 extern void term_deselect (Session *);
315 extern void term_update (Session *);
316 extern void term_invalidate(Session *);
317
318 /*
319  * Exports from telnet.c.
320  */
321
322 extern Backend telnet_backend;
323
324 /*
325  * Exports from ssh.c.
326  */
327
328 extern Backend ssh_backend;
329
330 /*
331  * Exports from sshrand.c.
332  */
333
334 void random_add_noise(void *noise, int length);
335 void random_init(void);
336 int random_byte(void);
337 void random_get_savedata(void **data, int *len);
338
339 /*
340  * Exports from misc.c.
341  */
342
343 /* #define MALLOC_LOG  do this if you suspect putty of leaking memory */
344 #ifdef MALLOC_LOG
345 #define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
346 #define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
347 #define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
348 void mlog(char *, int);
349 #else
350 #define smalloc safemalloc
351 #define srealloc saferealloc
352 #define sfree safefree
353 #endif
354
355 void *safemalloc(size_t);
356 void *saferealloc(void *, size_t);
357 void safefree(void *);
358
359 /*
360  * Exports from testback.c
361  */
362
363 extern Backend null_backend;
364 extern Backend loop_backend;
365 extern Backend hexdump_backend;
366
367 /*
368  * Exports from version.c.
369  */
370 extern char ver[];
371
372 /*
373  * A debug system.
374  */
375 #ifdef DEBUG
376 #include <stdarg.h>
377 #define debug(x) (dprintf x)
378 static void dprintf(char *fmt, ...) {
379     char buf[2048];
380     DWORD dw;
381     va_list ap;
382     static int gotconsole = 0;
383
384     if (!gotconsole) {
385         AllocConsole();
386         gotconsole = 1;
387     }
388
389     va_start(ap, fmt);
390     vsprintf(buf, fmt, ap);
391     WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);
392     va_end(ap);
393 }
394 #else
395 #define debug(x)
396 #endif
397
398 #endif