Add a "Config *" argument to term_init(), and use that instead of the global
[u/mdw/putty] / window.c
index e5f2280..4bfec69 100644 (file)
--- a/window.c
+++ b/window.c
@@ -115,10 +115,16 @@ static time_t last_movement = 0;
 
 static int caret_x = -1, caret_y = -1;
 
+static int kbd_codepage;
+
 static void *ldisc;
 static Backend *back;
 static void *backhandle;
 
+static int session_closed;
+
+extern struct sesslist sesslist;       /* imported from windlg.c */
+
 #define FONT_NORMAL 0
 #define FONT_BOLD 1
 #define FONT_UNDERLINE 2
@@ -400,6 +406,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
                        cfg.host[sizeof(cfg.host) - 1] = '\0';
                        got_host = 1;
                    }
+               } else {
+                   cmdline_error("unknown option \"%s\"", p);
                }
            }
        }
@@ -498,7 +506,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 
     hwnd = NULL;
 
-    term = term_init(NULL);
+    term = term_init(&cfg, NULL);
     logctx = log_init(NULL);
     term_provide_logctx(term, logctx);
 
@@ -683,10 +691,12 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
        AppendMenu(m, MF_ENABLED, IDM_NEWSESS, "Ne&w Session...");
        AppendMenu(m, MF_ENABLED, IDM_DUPSESS, "&Duplicate Session");
        s = CreateMenu();
-       get_sesslist(TRUE);
-       for (i = 1; i < ((nsessions < 256) ? nsessions : 256); i++)
+       get_sesslist(&sesslist, TRUE);
+       for (i = 1;
+            i < ((sesslist.nsessions < 256) ? sesslist.nsessions : 256);
+            i++)
            AppendMenu(s, MF_ENABLED, IDM_SAVED_MIN + (16 * i),
-                      sessions[i]);
+                      sesslist.sessions[i]);
        AppendMenu(m, MF_POPUP | MF_ENABLED, (UINT) s, "Sa&ved Sessions");
        AppendMenu(m, MF_ENABLED, IDM_RECONF, "Chan&ge Settings...");
        AppendMenu(m, MF_SEPARATOR, 0, 0);
@@ -1692,9 +1702,9 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                    sprintf(c, "putty &%p", filemap);
                    cl = c;
                } else if (wParam == IDM_SAVEDSESS) {
-                   if ((lParam - IDM_SAVED_MIN) / 16 < nsessions) {
+                   if ((lParam - IDM_SAVED_MIN) / 16 < sesslist.nsessions) {
                        char *session =
-                           sessions[(lParam - IDM_SAVED_MIN) / 16];
+                           sesslist.sessions[(lParam - IDM_SAVED_MIN) / 16];
                        cl = smalloc(16 + strlen(session));
                                       /* 8, but play safe */
                        if (!cl)
@@ -2082,7 +2092,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                       (p.rcPaint.left-offset_width)/font_width,
                       (p.rcPaint.top-offset_height)/font_height,
                       (p.rcPaint.right-offset_width-1)/font_width,
-                      (p.rcPaint.bottom-offset_height-1)/font_height);
+                      (p.rcPaint.bottom-offset_height-1)/font_height,
+                      is_alt_pressed());
 
            if (p.fErase ||
                p.rcPaint.left  < offset_width  ||
@@ -2189,7 +2200,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
         * 1) Keep the sizetip uptodate
         * 2) Make sure the window size is _stepped_ in units of the font size.
         */
-       if (cfg.resize_action != RESIZE_FONT && !alt_pressed) {
+       if (cfg.resize_action != RESIZE_FONT && !is_alt_pressed()) {
            int width, height, w, h, ew, eh;
            LPRECT r = (LPRECT) lParam;
 
@@ -2350,7 +2361,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
             * down the connection during an NT opaque drag.)
             */
            if (resizing) {
-               if (cfg.resize_action != RESIZE_FONT && !alt_pressed) {
+               if (cfg.resize_action != RESIZE_FONT && !is_alt_pressed()) {
                    need_backend_resize = TRUE;
                    w = (width-cfg.window_border*2) / font_width;
                    if (w < 1) w = 1;
@@ -2554,7 +2565,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
        }
       default:
        if (message == wm_mousewheel || message == WM_MOUSEWHEEL) {
-           int shift_pressed=0, control_pressed=0, alt_pressed=0;
+           int shift_pressed=0, control_pressed=0;
 
            if (message == WM_MOUSEWHEEL) {
                wheel_accumulator += (short)HIWORD(wParam);
@@ -2988,7 +2999,7 @@ void do_cursor(Context ctx, int x, int y, char *text, int len,
 
 /* This function gets the actual width of a character in the normal font.
  */
-int CharWidth(Context ctx, int uc) {
+int char_width(Context ctx, int uc) {
     HDC hdc = ctx;
     int ibuf = 0;
 
@@ -3188,8 +3199,6 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
        }
     }
 
-    alt_pressed = (left_alt && key_down);
-
     scan = (HIWORD(lParam) & (KF_UP | KF_EXTENDED | 0xFF));
     shift_state = ((keystate[VK_SHIFT] & 0x80) != 0)
        + ((keystate[VK_CONTROL] & 0x80) != 0) * 2;