Make sure SIGINT and SIGQUIT haven't been nobbled in our child
[u/mdw/putty] / window.c
index 987a845..3b60154 100644 (file)
--- a/window.c
+++ b/window.c
@@ -312,7 +312,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
            int argc, i;
            char **argv;
            
-           split_into_argv(cmdline, &argc, &argv);
+           split_into_argv(cmdline, &argc, &argv, NULL);
 
            for (i = 0; i < argc; i++) {
                char *p = argv[i];
@@ -430,6 +430,21 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
         * Trim a colon suffix off the hostname if it's there.
         */
        cfg.host[strcspn(cfg.host, ":")] = '\0';
+
+       /*
+        * Remove any remaining whitespace from the hostname.
+        */
+       {
+           int p1 = 0, p2 = 0;
+           while (cfg.host[p2] != '\0') {
+               if (cfg.host[p2] != ' ' && cfg.host[p2] != '\t') {
+                   cfg.host[p1] = cfg.host[p2];
+                   p1++;
+               }
+               p2++;
+           }
+           cfg.host[p1] = '\0';
+       }
     }
 
     /*
@@ -2061,6 +2076,17 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                                    colours[(ATTR_DEFBG>>ATTR_BGSHIFT)*2]);
                oldpen = SelectObject(hdc, edge);
 
+               /*
+                * Jordan Russell reports that this apparently
+                * ineffectual IntersectClipRect() call masks a
+                * Windows NT/2K bug causing strange display
+                * problems when the PuTTY window is taller than
+                * the primary monitor. It seems harmless enough...
+                */
+               IntersectClipRect(hdc,
+                       p.rcPaint.left, p.rcPaint.top,
+                       p.rcPaint.right, p.rcPaint.bottom);
+
                ExcludeClipRect(hdc, 
                        offset_width, offset_height,
                        offset_width+font_width*cols,
@@ -2413,6 +2439,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                     * messages. We _have_ to buffer everything
                     * we're sent.
                     */
+                   term_seen_key_event();
                    ldisc_send(buf, len, 1);
                    show_mouseptr(0);
                }
@@ -2459,8 +2486,10 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                 * luni_send() covering the whole of buff. So
                 * instead we luni_send the characters one by one.
                 */
-               for (i = 0; i < n; i += 2)
+               term_seen_key_event();
+               for (i = 0; i < n; i += 2) {
                    luni_send((unsigned short *)(buff+i), 1, 1);
+               }
                free(buff);
            }
            ImmReleaseContext(hwnd, hIMC);
@@ -2473,9 +2502,11 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
 
            buf[1] = wParam;
            buf[0] = wParam >> 8;
+           term_seen_key_event();
            lpage_send(kbd_codepage, buf, 2, 1);
        } else {
            char c = (unsigned char) wParam;
+           term_seen_key_event();
            lpage_send(kbd_codepage, &c, 1, 1);
        }
        return (0);
@@ -2489,6 +2520,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
         */
        {
            char c = (unsigned char)wParam;
+           term_seen_key_event();
            lpage_send(CP_ACP, &c, 1, 1);
        }
        return 0;
@@ -3158,15 +3190,6 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
     } else if (compose_state == 1 && wParam != VK_CONTROL)
        compose_state = 0;
 
-    /* 
-     * Record that we pressed key so the scroll window can be reset, but
-     * be careful to avoid Shift-UP/Down
-     */
-    if (wParam != VK_SHIFT && wParam != VK_PRIOR && wParam != VK_NEXT &&
-       wParam != VK_MENU && wParam != VK_CONTROL) {
-       seen_key_event = 1;
-    }
-
     if (compose_state > 1 && left_alt)
        compose_state = 0;
 
@@ -3393,6 +3416,12 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
            *p++ = 0;
            return -2;
        }
+       if (wParam == VK_BACK && shift_state == 1) {    /* Shift Backspace */
+           /* We do the opposite of what is configured */
+           *p++ = (cfg.bksp_is_delete ? 0x08 : 0x7F);
+           *p++ = 0;
+           return -2;
+       }
        if (wParam == VK_TAB && shift_state == 1) {     /* Shift tab */
            *p++ = 0x1B;
            *p++ = '[';
@@ -3737,6 +3766,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
                        return 0;
                    }
                    keybuf = nc;
+                   term_seen_key_event();
                    luni_send(&keybuf, 1, 1);
                    continue;
                }
@@ -3747,6 +3777,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
                    if (alt_sum) {
                        if (in_utf || dbcs_screenfont) {
                            keybuf = alt_sum;
+                           term_seen_key_event();
                            luni_send(&keybuf, 1, 1);
                        } else {
                            ch = (char) alt_sum;
@@ -3759,21 +3790,25 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
                             * messages. We _have_ to buffer
                             * everything we're sent.
                             */
+                           term_seen_key_event();
                            ldisc_send(&ch, 1, 1);
                        }
                        alt_sum = 0;
                    } else
+                       term_seen_key_event();
                        lpage_send(kbd_codepage, &ch, 1, 1);
                } else {
                    if(capsOn && ch < 0x80) {
                        WCHAR cbuf[2];
                        cbuf[0] = 27;
                        cbuf[1] = xlat_uskbd2cyrllic(ch);
+                       term_seen_key_event();
                        luni_send(cbuf+!left_alt, 1+!!left_alt, 1);
                    } else {
                        char cbuf[2];
                        cbuf[0] = '\033';
                        cbuf[1] = ch;
+                       term_seen_key_event();
                        lpage_send(kbd_codepage, cbuf+!left_alt, 1+!!left_alt, 1);
                    }
                }
@@ -3806,6 +3841,16 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
     return -1;
 }
 
+void request_paste(void)
+{
+    /*
+     * In Windows, pasting is synchronous: we can read the
+     * clipboard with no difficulty, so request_paste() can just go
+     * ahead and paste.
+     */
+    term_do_paste();
+}
+
 void set_title(char *title)
 {
     sfree(window_name);
@@ -4191,6 +4236,22 @@ void fatalbox(char *fmt, ...)
 }
 
 /*
+ * Print a modal (Really Bad) message box and perform a fatal exit.
+ */
+void modalfatalbox(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_SYSTEMMODAL | MB_ICONERROR | MB_OK);
+    cleanup_exit(1);
+}
+
+/*
  * Manage window caption / taskbar flashing, if enabled.
  * 0 = stop, 1 = maintain, 2 = start
  */