]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Since neither I nor Owen know why the IDM_ values for the saved-sessions
authorJacob Nevins <jacobn@chiark.greenend.org.uk>
Tue, 2 Nov 2004 17:44:06 +0000 (17:44 +0000)
committerJacob Nevins <jacobn@chiark.greenend.org.uk>
Tue, 2 Nov 2004 17:44:06 +0000 (17:44 +0000)
submenu were going up in steps of 16, I've changed to steps of 1, thus
increasing the possible number of sessions from ~256 to 4096, since a
recent report seemed to indicate that the previous limit might not be
enough for someone (!)
I can't find any documentation that puts an upper limit on the number of
menu items, and it seems to work on Win98, which is where I'd expect it to
break if anywhere.
Also a number of other tweaks to this code.

[originally from svn r4731]

window.c

index 9f1dbe33c91740bb62ee0726149ab708c06d2cf8..cd5dda49b835c008e6d6f6293694dd6e479cf48e 100644 (file)
--- a/window.c
+++ b/window.c
@@ -45,6 +45,8 @@
 
 #define IDM_SAVED_MIN 0x1000
 #define IDM_SAVED_MAX 0x2000
+/* Maximum number of sessions on saved-session submenu */
+#define MENU_SAVED_MAX (IDM_SAVED_MAX-IDM_SAVED_MIN)
 
 #define WM_IGNORE_CLIP (WM_XUSER + 2)
 #define WM_FULLSCR_ON_MAX (WM_XUSER + 3)
@@ -708,10 +710,12 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 
        s = CreateMenu();
        get_sesslist(&sesslist, TRUE);
+       /* skip sesslist.sessions[0] == Default Settings */
        for (i = 1;
-            i < ((sesslist.nsessions < 256) ? sesslist.nsessions : 256);
+            i < ((sesslist.nsessions <= MENU_SAVED_MAX+1) ? sesslist.nsessions
+                                                          : MENU_SAVED_MAX+1);
             i++)
-           AppendMenu(s, MF_ENABLED, IDM_SAVED_MIN + (16 * i),
+           AppendMenu(s, MF_ENABLED, IDM_SAVED_MIN + i-1,
                       sesslist.sessions[i]);
 
        for (j = 0; j < lenof(popup_menus); j++) {
@@ -1883,18 +1887,12 @@ 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 < sesslist.nsessions) {
-                       char *session =
-                           sesslist.sessions[(lParam - IDM_SAVED_MIN) / 16];
-                       cl = snewn(16 + strlen(session), char);
-                                      /* 8, but play safe */
-                       if (!cl)
-                           cl = NULL;    
-                                      /* not a very important failure mode */
-                       else {
-                           sprintf(cl, "putty @%s", session);
-                           freecl = TRUE;
-                       }
+                   unsigned int sessno = lParam - IDM_SAVED_MIN + 1;
+                   if (sessno < sesslist.nsessions) {
+                       char *session = sesslist.sessions[sessno];
+                       /* XXX spaces? quotes? "-load"? */
+                       cl = dupprintf("putty @%s", session);
+                       freecl = TRUE;
                    } else
                        break;
                } else
@@ -2112,7 +2110,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
            flip_full_screen();
            break;
          default:
-           if (wParam >= IDM_SAVED_MIN && wParam <= IDM_SAVED_MAX) {
+           if (wParam >= IDM_SAVED_MIN && wParam < IDM_SAVED_MAX) {
                SendMessage(hwnd, WM_SYSCOMMAND, IDM_SAVEDSESS, wParam);
            }
            if (wParam >= IDM_SPECIAL_MIN && wParam <= IDM_SPECIAL_MAX) {