1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-24 16:52:24 +00:00

Fix sorting of saved sessions list box so Default Settings is back at

the top of the list instead of being filed under D

[originally from svn r686]
This commit is contained in:
Simon Tatham 2000-10-06 16:19:44 +00:00
parent 0129f94d1c
commit 82dcef256f
2 changed files with 22 additions and 8 deletions

View File

@ -280,6 +280,21 @@ void do_defaults (char *session, Config *cfg) {
load_settings ("Default Settings", FALSE, cfg); load_settings ("Default Settings", FALSE, cfg);
} }
static int sessioncmp(const void *av, const void *bv) {
const char *a = *(const char *const *)av;
const char *b = *(const char *const *)bv;
/*
* Alphabetical order, except that "Default Settings" is a
* special case and comes first.
*/
if (!strcmp(a, "Default Settings"))
return -1; /* a comes first */
if (!strcmp(b, "Default Settings"))
return +1; /* b comes first */
return strcmp(a, b); /* otherwise, compare normally */
}
void get_sesslist(int allocate) { void get_sesslist(int allocate) {
static char otherbuf[2048]; static char otherbuf[2048];
static char *buffer; static char *buffer;
@ -311,24 +326,23 @@ void get_sesslist(int allocate) {
buffer[buflen] = '\0'; buffer[buflen] = '\0';
p = buffer; p = buffer;
nsessions = 1; /* "Default Settings" counts as one */ nsessions = 0;
while (*p) { while (*p) {
if (strcmp(p, "Default Settings")) nsessions++;
nsessions++;
while (*p) p++; while (*p) p++;
p++; p++;
} }
sessions = smalloc(nsessions * sizeof(char *)); sessions = smalloc(nsessions * sizeof(char *));
sessions[0] = "Default Settings";
p = buffer; p = buffer;
i = 1; i = 0;
while (*p) { while (*p) {
if (strcmp(p, "Default Settings")) sessions[i++] = p;
sessions[i++] = p;
while (*p) p++; while (*p) p++;
p++; p++;
} }
qsort(sessions, i, sizeof(char *), sessioncmp);
} else { } else {
sfree (buffer); sfree (buffer);
sfree (sessions); sfree (sessions);

View File

@ -568,7 +568,7 @@ static void sesssaver(struct ctlpos *cp, char *text,
cp->ypos += y + GAPBETWEEN; cp->ypos += y + GAPBETWEEN;
doctl(cp, r, "LISTBOX", doctl(cp, r, "LISTBOX",
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL |
LBS_STANDARD | LBS_HASSTRINGS, LBS_NOTIFY | LBS_HASSTRINGS,
WS_EX_CLIENTEDGE, WS_EX_CLIENTEDGE,
"", listid); "", listid);
} }