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