]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - putty.h
First attempt at copying to the clipboard -- doesn't seem to work.
[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 int rows, cols, savelines;
74
75 GLOBAL int font_width, font_height;
76
77 #define INBUF_SIZE 2048
78 #define INBUF_MASK (INBUF_SIZE-1)
79 GLOBAL unsigned char inbuf[INBUF_SIZE];
80 GLOBAL int inbuf_head, inbuf_reap;
81
82 #define OUTBUF_SIZE 2048
83 #define OUTBUF_MASK (OUTBUF_SIZE-1)
84 GLOBAL unsigned char outbuf[OUTBUF_SIZE];
85 GLOBAL int outbuf_head, outbuf_reap;
86
87 GLOBAL int has_focus;
88
89 GLOBAL int app_cursor_keys, app_keypad_keys;
90
91 #define WM_NETEVENT  (WM_USER + 1)
92
93 typedef enum {
94     TS_AYT, TS_BRK, TS_SYNCH, TS_EC, TS_EL, TS_GA, TS_NOP, TS_ABORT,
95     TS_AO, TS_IP, TS_SUSP, TS_EOR, TS_EOF
96 } Telnet_Special;
97
98 typedef enum {
99     MB_NOTHING, MB_SELECT, MB_EXTEND, MB_PASTE
100 } Mouse_Button;
101
102 typedef enum {
103     MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
104 } Mouse_Action;
105
106 typedef enum {
107     VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN
108 } VT_Mode;
109
110 typedef struct {
111 #ifdef macintosh
112         char *(*init) (char *host, int port, char **realhost);
113         int (*msg)(void);
114 #else /* not macintosh */
115     char *(*init) (HWND hwnd, char *host, int port, char **realhost);
116     int (*msg) (WPARAM wParam, LPARAM lParam);
117 #endif /* not macintosh */
118     void (*send) (char *buf, int len);
119     void (*size) (void);
120     void (*special) (Telnet_Special code);
121 } Backend;
122
123 GLOBAL Backend *back;
124
125 typedef struct {
126     /* Basic options */
127     char host[512];
128     int port;
129     enum { PROT_TELNET, PROT_SSH } protocol;
130     int close_on_exit;
131     /* SSH options */
132     int nopty;
133     /* Telnet options */
134     char termtype[32];
135     char termspeed[32];
136     char environmt[1024];                    /* VAR\tvalue\0VAR\tvalue\0\0 */
137     char username[32];
138     int rfc_environ;
139     /* Keyboard options */
140     int bksp_is_delete;
141     int rxvt_homeend;
142     int linux_funkeys;
143     int app_cursor;
144     int app_keypad;
145     /* Terminal options */
146     int savelines;
147     int dec_om;
148     int wrap_mode;
149     int lfhascr;
150     int win_name_always;
151     int width, height;
152     char font[64];
153     int fontisbold;
154     int fontheight;
155     VT_Mode vtmode;
156     /* Colour options */
157     int try_palette;
158     int bold_colour;
159 #ifdef macintosh
160     PaletteHandle colours;
161 #else /* not macintosh */
162     unsigned char colours[22][3];
163 #endif /* not macintosh */
164     /* Selection options */
165 #ifndef macintosh
166     int mouse_is_xterm;
167 #endif
168     short wordness[256];
169 } Config;
170
171 GLOBAL Config cfg;
172
173 typedef struct {
174     /* Display state */
175     int rows, cols, savelines;
176     int font_width, font_height;
177     int has_focus;
178     /* Buffers */
179     unsigned char inbuf[INBUF_SIZE];
180     int inbuf_head, inbuf_reap;
181     unsigned char outbuf[OUTBUF_SIZE];
182     int outbuf_head, outbuf_reap;
183     /* Emulator state */
184     int app_cursor_keys, app_keypad_keys;
185     /* Backend */
186     Backend *back;
187     /* Config that created this session */
188     Config cfg;
189 } Session;
190
191
192 /*
193  * Exports from window.c.
194  */
195 void request_resize (int, int);
196 void do_text (Context, int, int, char *, int, unsigned long);
197 void set_title (char *);
198 void set_icon (char *);
199 void set_sbar (int, int, int);
200 Context get_ctx();
201 void free_ctx (Context);
202 void palette_set (int, int, int, int);
203 void palette_reset (void);
204 void write_clip (void *, int);
205 void get_clip (void **, int *);
206 void optimised_move (int, int, int);
207 void do_scroll(int, int, int);
208 void fatalbox (const char *, ...);
209 void beep (void);
210 #define OPTIMISE_IS_SCROLL 1
211
212 /*
213  * Exports from noise.c.
214  */
215 void noise_get_heavy(void (*func) (void *, int));
216 void noise_get_light(void (*func) (void *, int));
217 void noise_ultralight(DWORD data);
218 void random_save_seed(void);
219
220 #ifndef macintosh
221 /*
222  * Exports from windlg.c.
223  */
224 int do_config (void);
225 int do_reconfig (HWND);
226 void do_defaults (char *);
227 void lognegot (char *);
228 void shownegot (HWND);
229 void showabout (HWND);
230 void verify_ssh_host_key(char *host, struct RSAKey *key);
231 #endif
232
233 /*
234  * Exports from terminal.c.
235  */
236
237 void term_init (void);
238 void term_size (int, int, int);
239 void term_out (void);
240 void term_paint (Context, int, int, int, int);
241 void term_scroll (int, int);
242 void term_pwron (void);
243 void term_clrsb (void);
244 void term_mouse (Mouse_Button, Mouse_Action, int, int);
245 void term_deselect (void);
246 void term_update (void);
247 void term_invalidate(void);
248
249 /*
250  * Exports from telnet.c.
251  */
252
253 Backend telnet_backend;
254
255 /*
256  * Exports from ssh.c.
257  */
258
259 Backend ssh_backend;
260
261 /*
262  * Exports from sshrand.c.
263  */
264
265 void random_add_noise(void *noise, int length);
266 void random_init(void);
267 int random_byte(void);
268 void random_get_savedata(void **data, int *len);
269
270 /*
271  * Exports from misc.c.
272  */
273
274 /* #define MALLOC_LOG  do this if you suspect putty of leaking memory */
275 #ifdef MALLOC_LOG
276 #define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
277 #define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
278 #define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
279 void mlog(char *, int);
280 #else
281 #define smalloc safemalloc
282 #define srealloc saferealloc
283 #define sfree safefree
284 #endif
285
286 void *safemalloc(size_t);
287 void *saferealloc(void *, size_t);
288 void safefree(void *);
289
290 /*
291  * Exports from testback.c
292  */
293
294 extern Backend null_backend;
295 extern Backend loop_backend;
296
297 /*
298  * Exports from version.c.
299  */
300 extern char ver[];
301
302 /*
303  * A debug system.
304  */
305 #ifdef DEBUG
306 #include <stdarg.h>
307 #define debug(x) (dprintf x)
308 static void dprintf(char *fmt, ...) {
309     char buf[2048];
310     DWORD dw;
311     va_list ap;
312     static int gotconsole = 0;
313
314     if (!gotconsole) {
315         AllocConsole();
316         gotconsole = 1;
317     }
318
319     va_start(ap, fmt);
320     vsprintf(buf, fmt, ap);
321     WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);
322     va_end(ap);
323 }
324 #else
325 #define debug(x)
326 #endif
327
328 #endif