X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/a9422f39e34f55d1925d1ebef35ace1a0f1c2f6a..123bc6eac92a14c79345ef7f0b94ce7e277b1a98:/settings.c diff --git a/settings.c b/settings.c index 6204227c..1bbf6fb6 100644 --- a/settings.c +++ b/settings.c @@ -280,6 +280,21 @@ void do_defaults (char *session, Config *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) { static char otherbuf[2048]; static char *buffer; @@ -311,24 +326,23 @@ void get_sesslist(int allocate) { buffer[buflen] = '\0'; p = buffer; - nsessions = 1; /* "Default Settings" counts as one */ + nsessions = 0; while (*p) { - if (strcmp(p, "Default Settings")) - nsessions++; + nsessions++; while (*p) p++; p++; } sessions = smalloc(nsessions * sizeof(char *)); - sessions[0] = "Default Settings"; p = buffer; - i = 1; + i = 0; while (*p) { - if (strcmp(p, "Default Settings")) - sessions[i++] = p; + sessions[i++] = p; while (*p) p++; p++; } + + qsort(sessions, i, sizeof(char *), sessioncmp); } else { sfree (buffer); sfree (sessions);