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