From 1f1e3232c68e05afc46bebec836e0d022c965dee Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 2 Nov 2004 17:44:06 +0000 Subject: [PATCH] Since neither I nor Owen know why the IDM_ values for the saved-sessions 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. git-svn-id: svn://svn.tartarus.org/sgt/putty@4731 cda61777-01e9-0310-a592-d414129be87e --- window.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/window.c b/window.c index 9f1dbe33..cd5dda49 100644 --- 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) { -- 2.11.0