4 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
7 #define OPTIMISE_SCROLL
16 #endif /* macintosh */
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
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 */
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
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
53 #define SEL_NL { 13, 10 }
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.
61 #ifdef PUTTY_DO_GLOBALS
67 #define INBUF_SIZE 2048
68 #define INBUF_MASK (INBUF_SIZE-1)
70 #define OUTBUF_SIZE 2048
71 #define OUTBUF_MASK (OUTBUF_SIZE-1)
73 #define WM_NETEVENT (WM_USER + 1)
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
81 MB_NOTHING, MB_SELECT, MB_EXTEND, MB_PASTE
85 MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
89 VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN
92 typedef struct Session Session;
93 typedef struct Socket Socket;
95 /* Types of network event */
98 NE_NULL, /* Nothing happened */
99 NE_OPEN, /* Connection successfully opened */
100 NE_NOHOST, /* DNS lookup failed for some reason */
101 NE_REFUSED, /* Port unreachable */
102 NE_NOOPEN, /* Connection failed to open for some other reason */
103 NE_DATA, /* Incoming normal data */
104 NE_URGENT, /* Incoming urgent data */
105 NE_SENT, /* Used internally by Mac network stack */
106 NE_CLOSING, /* Connection closed by remote host */
107 NE_CLOSED, /* Connection close completed */
108 NE_TIMEOUT, /* Remote host vanished */
109 NE_ABORT, /* Remote host reset connection */
110 NE_DIED, /* Connection has failed for some other reason */
114 typedef void *SOCKET;
115 #define INVALID_SOCKET NULL
119 char *(*init) (Session *);
120 int (*msg)(Session *, SOCKET, Net_Event_Type);
121 void (*send) (Session *, char *buf, int len);
122 void (*size) (Session *);
123 void (*special) (Session *, Telnet_Special code);
124 void (*shutdown) (Session *);
130 SOCKET (*open)(Session *, char const *, int);
131 int (*recv)(SOCKET, void *, int, int);
132 int (*send)(SOCKET, void *, int, int);
134 void (*close)(SOCKET);
135 void (*destroy)(SOCKET);
136 void (*shutdown)(void);
139 GLOBAL Network_Stack *net_stack;
141 #define net_open(s, h, p) ((*net_stack->open)((s), (h), (p)))
142 #define net_recv(s, b, l, f) ((*net_stack->recv)((s), (b), (l), (f)))
143 #define net_send(s, b, l, f) ((*net_stack->send)((s), (b), (l), (f)))
144 #define net_poll() ((*net_stack->poll)())
145 #define net_close(s) ((*net_stack->close)(s))
146 #define net_destroy(s) ((*net_stack->destroy)(s))
147 #define net_shutdown() ((*net_stack->shutdown)())
154 enum { PROT_TELNET, PROT_SSH } protocol;
161 char environmt[1024]; /* VAR\tvalue\0VAR\tvalue\0\0 */
164 /* Keyboard options */
171 /* Terminal options */
186 PaletteHandle colours;
187 #else /* not macintosh */
188 unsigned char colours[22][3];
189 #endif /* not macintosh */
190 /* Selection options */
199 /* Display buffers and pointers within them */
200 unsigned long *text; /* buffer of text on terminal screen */
201 unsigned long *scrtop; /* top of working screen */
202 unsigned long *disptop; /* top of displayed screen */
203 unsigned long *sbtop; /* top of scrollback */
204 unsigned long *cpos; /* cursor position (convenience) */
205 unsigned long *disptext; /* buffer of text on real screen */
206 unsigned long *wanttext; /* buffer of text we want on screen */
207 unsigned long *alttext; /* buffer of text on alt. screen */
208 unsigned char *selspace; /* buffer for building selections in */
211 unsigned long curr_attr;
212 int curs_x, curs_y; /* cursor */
213 int cset; /* 0 or 1: which char set is in GL */
214 unsigned long cset_attr[2]; /* G0 and G1 char sets */
217 unsigned long save_attr;
218 int save_x, save_y; /* saved cursor position */
219 int save_cset, save_csattr; /* saved with cursor position */
221 int marg_t, marg_b; /* scroll margins */
224 int dec_om; /* DEC origin mode flag */
225 int wrap, wrapnext; /* wrap flags */
226 int insert; /* insert-mode flag */
227 int rvideo; /* global reverse video flag */
230 * Saved settings on the alternate screen.
232 int alt_x, alt_y, alt_om, alt_wrap, alt_wnext, alt_ins, alt_cset;
236 /* Escape sequence handler state */
237 #define ARGS_MAX 32 /* max # of esc sequence arguments */
238 int esc_args[ARGS_MAX];
241 #define OSC_STR_MAX 2048
243 char osc_string[OSC_STR_MAX+1];
250 TOPLEVEL, IGNORE_NEXT,
251 SEEN_ESC, SEEN_CSI, SET_GL, SET_GR,
252 SEEN_OSC, SEEN_OSC_P, SEEN_OSC_W, OSC_STRING, OSC_MAYBE_ST,
257 NO_SELECTION, ABOUT_TO, DRAGGING, SELECTED
260 SM_CHAR, SM_WORD, SM_LINE
262 unsigned long *selstart, *selend, *selanchor;
266 typedef struct Session {
267 /* Config that created this session */
269 /* Terminal emulator internal state */
272 int rows, cols, savelines;
273 int font_width, font_height;
276 unsigned char inbuf[INBUF_SIZE];
277 int inbuf_head, inbuf_reap;
278 unsigned char outbuf[OUTBUF_SIZE];
279 int outbuf_head, outbuf_reap;
281 int app_cursor_keys, app_keypad_keys;
285 unsigned long attr_mask; /* Mask of attributes to display */
292 PaletteHandle palette;
293 ControlHandle scrollbar;
298 typedef struct Socket Socket;
301 * Exports from display system
303 extern void request_resize(Session *, int, int);
304 extern void do_text(Session *, int, int, char *, int, unsigned long);
305 extern void set_title(Session *, char *);
306 extern void set_icon(Session *, char *);
307 extern void set_sbar(Session *, int, int, int);
308 extern void pre_paint(Session *);
309 extern void post_paint(Session *);
310 extern void palette_set(Session *, int, int, int, int);
311 extern void palette_reset(Session *);
312 extern void write_clip (void *, int);
313 extern void get_clip (void **, int *);
314 extern void do_scroll(Session *, int, int, int);
315 extern void fatalbox(const char *, ...);
317 #pragma noreturn (fatalbox)
319 extern void beep(Session *s);
320 extern void lognegot(const char *);
323 * Exports from the network system
327 extern Socket *net_open(Session *, char *host, int port);
328 extern char *net_realname(Socket *);
329 extern int net_recv(Socket *, void *, int, int);
330 extern int net_send(Socket *, void *, int, int);
331 extern void net_close(Socket *); /* ask the remote end to close */
332 extern void net_destroy(Socket *); /* Tidy up */
334 #define SEND_PUSH 0x01
335 #define SEND_URG 0x02
339 * Exports from noise.c.
341 void noise_get_heavy(void (*func) (void *, int));
342 void noise_get_light(void (*func) (void *, int));
343 void noise_ultralight(DWORD data);
344 void random_save_seed(void);
348 * Exports from windlg.c.
350 int do_config (void);
351 int do_reconfig (HWND);
352 void do_defaults (char *);
353 void lognegot (char *);
354 void shownegot (HWND);
355 void showabout (HWND);
356 void verify_ssh_host_key(char *host, struct RSAKey *key);
360 * Exports from terminal.c.
363 extern void term_init(Session *);
364 extern void term_size(Session *, int, int, int);
365 extern void term_out(Session *);
366 extern void term_paint(Session *, int, int, int, int);
367 extern void term_scroll(Session *, int, int);
368 extern void term_pwron(Session *);
369 extern void term_clrsb(Session *);
370 extern void term_mouse(Session *, Mouse_Button, Mouse_Action, int, int);
371 extern void term_copy(Session *);
372 extern void term_paste(Session *);
373 extern int term_hasselection(Session *);
374 extern void term_deselect (Session *);
375 extern void term_update (Session *);
376 extern void term_invalidate(Session *);
379 * Exports from telnet.c.
382 extern Backend telnet_backend;
385 * Exports from ssh.c.
388 extern Backend ssh_backend;
391 * Exports from sshrand.c.
394 void random_add_noise(void *noise, int length);
395 void random_init(void);
396 int random_byte(void);
397 void random_get_savedata(void **data, int *len);
400 * Exports from misc.c.
403 /* #define MALLOC_LOG do this if you suspect putty of leaking memory */
405 #define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
406 #define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
407 #define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
408 void mlog(char *, int);
410 #define smalloc safemalloc
411 #define srealloc saferealloc
412 #define sfree safefree
415 void *safemalloc(size_t);
416 void *saferealloc(void *, size_t);
417 void safefree(void *);
420 * Exports from testback.c
423 extern Backend null_backend;
424 extern Backend loop_backend;
425 extern Backend hexdump_backend;
428 * Exports from version.c.
437 #define debug(x) (dprintf x)
438 static void dprintf(char *fmt, ...) {
442 static int gotconsole = 0;
450 vsprintf(buf, fmt, ap);
451 WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);