#include <windows.h>
#include <commctrl.h>
+#ifndef AUTO_WINSOCK
+#ifdef WINSOCK_TWO
+#include <winsock2.h>
+#else
#include <winsock.h>
+#endif
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define WM_IGNORE_SIZE (WM_XUSER + 1)
#define WM_IGNORE_CLIP (WM_XUSER + 2)
-#define WM_IGNORE_KEYMENU (WM_XUSER + 3)
static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, unsigned char *output);
static char *window_name, *icon_name;
+static Ldisc *real_ldisc;
+
+void begin_session(void) {
+ ldisc = real_ldisc;
+}
+
int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) {
static char appname[] = "PuTTY";
WORD winsock_ver;
tolower(p[1]) == 'o' &&
tolower(p[2]) == 'g') {
logfile = "putty.log";
+ } else if (q == p + 7 &&
+ tolower(p[0]) == 'c' &&
+ tolower(p[1]) == 'l' &&
+ tolower(p[2]) == 'e' &&
+ tolower(p[3]) == 'a' &&
+ tolower(p[4]) == 'n' &&
+ tolower(p[5]) == 'u' &&
+ tolower(p[6]) == 'p') {
+ /*
+ * `putty -cleanup'. Remove all registry entries
+ * associated with PuTTY, and also find and delete
+ * the random seed file.
+ */
+ if (MessageBox(NULL,
+ "This procedure will remove ALL Registry\n"
+ "entries associated with PuTTY, and will\n"
+ "also remove the PuTTY random seed file.\n"
+ "\n"
+ "THIS PROCESS WILL DESTROY YOUR SAVED\n"
+ "SESSIONS. Are you really sure you want\n"
+ "to continue?",
+ "PuTTY Warning",
+ MB_YESNO | MB_ICONWARNING) == IDYES) {
+ random_destroy_seed();
+ registry_cleanup();
+ }
+ exit(0);
}
p = q + strspn(q, " \t");
}
return 0;
}
}
+
+ /* See if host is of the form user@host */
+ if (cfg.host[0] != '\0') {
+ char *atsign = strchr(cfg.host, '@');
+ /* Make sure we're not overflowing the user field */
+ if (atsign) {
+ if (atsign-cfg.host < sizeof cfg.username) {
+ strncpy (cfg.username, cfg.host, atsign-cfg.host);
+ cfg.username[atsign-cfg.host] = '\0';
+ }
+ memmove(cfg.host, atsign+1, 1+strlen(atsign+1));
+ }
+ }
}
/*
}
}
- ldisc = (cfg.ldisc_term ? &ldisc_term : &ldisc_simple);
+ real_ldisc = (cfg.ldisc_term ? &ldisc_term : &ldisc_simple);
+ /* To start with, we use the simple line discipline, so we can
+ * type passwords etc without fear of them being echoed... */
+ ldisc = &ldisc_simple;
if (!prev) {
wndclass.style = 0;
}
/*
+ * Print a message box and close the connection.
+ */
+void connection_fatal(char *fmt, ...) {
+ va_list ap;
+ char stuff[200];
+
+ va_start(ap, fmt);
+ vsprintf(stuff, fmt, ap);
+ va_end(ap);
+ MessageBox(hwnd, stuff, "PuTTY Fatal Error", MB_ICONERROR | MB_OK);
+ if (cfg.close_on_exit)
+ PostQuitMessage(1);
+ else {
+ session_closed = TRUE;
+ SetWindowText (hwnd, "PuTTY (inactive)");
+ }
+}
+
+/*
* Actually do the job requested by a WM_NETEVENT
*/
static void enact_pending_netevent(void) {
sprintf(buf, "Unexpected network error %d", -i);
break;
}
- MessageBox(hwnd, buf, "PuTTY Fatal Error",
- MB_ICONERROR | MB_OK);
- PostQuitMessage(1);
- } else if (i == 0) {
+ connection_fatal(buf);
+ }
+ if (i <= 0) {
if (cfg.close_on_exit)
PostQuitMessage(0);
else {
HDC hdc;
static int ignore_size = FALSE;
static int ignore_clip = FALSE;
- static int ignore_keymenu = TRUE;
static int just_reconfigged = FALSE;
+ static int resizing = FALSE;
switch (message) {
case WM_TIMER:
return 0;
case WM_SYSCOMMAND:
switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */
- case SC_KEYMENU:
- if (ignore_keymenu)
- return 0; /* don't put up system menu on Alt */
- break;
case IDM_SHOWLOG:
showeventlog(hwnd);
break;
case WM_IGNORE_CLIP:
ignore_clip = wParam; /* don't panic on DESTROYCLIPBOARD */
break;
- case WM_IGNORE_KEYMENU:
- ignore_keymenu = wParam; /* do or don't ignore SC_KEYMENU */
- break;
case WM_DESTROYCLIPBOARD:
if (!ignore_clip)
term_deselect();
return 0;
case WM_SETFOCUS:
has_focus = TRUE;
+ CreateCaret(hwnd, NULL, font_width, font_height);
term_out();
term_update();
break;
case WM_KILLFOCUS:
has_focus = FALSE;
+ DestroyCaret();
term_out();
term_update();
break;
break;
case WM_ENTERSIZEMOVE:
EnableSizeTip(1);
+ resizing = TRUE;
break;
case WM_EXITSIZEMOVE:
EnableSizeTip(0);
+ resizing = FALSE;
+ back->size();
break;
case WM_SIZING:
{
if (w != cols || h != rows || just_reconfigged) {
term_invalidate();
term_size (h, w, cfg.savelines);
- back->size();
+ /*
+ * Don't call back->size in mid-resize. (To prevent
+ * massive numbers of resize events getting sent
+ * down the connection during an NT opaque drag.)
+ */
+ if (!resizing)
+ back->size();
just_reconfigged = FALSE;
}
}
}
/*
+ * Move the system caret. (We maintain one, even though it's
+ * invisible, for the benefit of blind people: apparently some
+ * helper software tracks the system caret, so we should arrange to
+ * have one.)
+ */
+void sys_cursor(int x, int y) {
+ SetCaretPos(x * font_width, y * font_height);
+}
+
+/*
* Draw a line of text in the window, at given character
* coordinates, in given attributes.
*
SendMessage (hwnd, WM_VSCROLL, SB_PAGEDOWN, 0);
return 0;
}
+ if (wParam == VK_INSERT && shift_state == 1) {
+ term_mouse (MB_PASTE, MA_CLICK, 0, 0);
+ term_mouse (MB_PASTE, MA_RELEASE, 0, 0);
+ return 0;
+ }
if (left_alt && wParam == VK_F4 && cfg.alt_f4) {
return -1;
}
if (left_alt && wParam == VK_SPACE && cfg.alt_space) {
- SendMessage (hwnd, WM_IGNORE_KEYMENU, FALSE, 0);
SendMessage (hwnd, WM_SYSCOMMAND, SC_KEYMENU, 0);
- SendMessage (hwnd, WM_IGNORE_KEYMENU, TRUE, 0);
return -1;
}
if ( cfg.funky_type == 0 ||
( cfg.funky_type == 1 && app_keypad_keys)) switch(wParam) {
- case VK_EXECUTE: xkey = 'P'; break;
+ case VK_EXECUTE: if (app_keypad_keys) xkey = 'P'; break;
case VK_DIVIDE: xkey = 'Q'; break;
case VK_MULTIPLY:xkey = 'R'; break;
case VK_SUBTRACT:xkey = 'S'; break;
}
/* This stops ALT press-release doing a 'COMMAND MENU' function */
-#if 0
if (message == WM_SYSKEYUP && wParam == VK_MENU)
{
keystate[VK_MENU] = 0;
return 0;
}
-#endif
return -1;
}