Further deglobalisation: settings.c now has a more sensible interface.

[originally from svn r2162]
This commit is contained in:
Simon Tatham 2002-10-30 18:12:46 +00:00
Родитель fda97938f3
Коммит 79b086658d
5 изменённых файлов: 69 добавлений и 50 удалений

26
putty.h
Просмотреть файл

@ -92,15 +92,14 @@ typedef struct terminal_tag Terminal;
#define ATTR_CUR_AND (~(ATTR_BOLD|ATTR_REVERSE|ATTR_BLINK|ATTR_COLOURS)) #define ATTR_CUR_AND (~(ATTR_BOLD|ATTR_REVERSE|ATTR_BLINK|ATTR_COLOURS))
#define ATTR_CUR_XOR 0x00BA0000UL #define ATTR_CUR_XOR 0x00BA0000UL
GLOBAL int session_closed; struct sesslist {
int nsessions;
char **sessions;
char *buffer; /* so memory can be freed later */
};
GLOBAL int nsessions;
GLOBAL char **sessions;
GLOBAL int utf;
GLOBAL int dbcs_screenfont; GLOBAL int dbcs_screenfont;
GLOBAL int font_codepage; GLOBAL int font_codepage;
GLOBAL int kbd_codepage;
GLOBAL int line_codepage; GLOBAL int line_codepage;
GLOBAL wchar_t unitab_scoacs[256]; GLOBAL wchar_t unitab_scoacs[256];
GLOBAL wchar_t unitab_line[256]; GLOBAL wchar_t unitab_line[256];
@ -375,16 +374,27 @@ struct config_tag {
* being run, _either_ because no remote command has been provided * being run, _either_ because no remote command has been provided
* _or_ because the application is GUI and can't run non- * _or_ because the application is GUI and can't run non-
* interactively. * interactively.
*
* These flags describe the type of _application_ - they wouldn't
* vary between individual sessions - and so it's OK to have this
* variable be GLOBAL.
*/ */
#define FLAG_VERBOSE 0x0001 #define FLAG_VERBOSE 0x0001
#define FLAG_STDERR 0x0002 #define FLAG_STDERR 0x0002
#define FLAG_INTERACTIVE 0x0004 #define FLAG_INTERACTIVE 0x0004
GLOBAL int flags; GLOBAL int flags;
GLOBAL Config cfg; /*
* Likewise, these two variables are set up when the application
* initialises, and inform all default-settings accesses after
* that.
*/
GLOBAL int default_protocol; GLOBAL int default_protocol;
GLOBAL int default_port; GLOBAL int default_port;
/* This variable, OTOH, needs to be made non-global ASAP. FIXME. */
GLOBAL Config cfg;
struct RSAKey; /* be a little careful of scope */ struct RSAKey; /* be a little careful of scope */
/* /*
@ -445,7 +455,7 @@ void random_destroy_seed(void);
*/ */
void save_settings(char *section, int do_host, Config * cfg); void save_settings(char *section, int do_host, Config * cfg);
void load_settings(char *section, int do_host, Config * cfg); void load_settings(char *section, int do_host, Config * cfg);
void get_sesslist(int allocate); void get_sesslist(struct sesslist *, int allocate);
void do_defaults(char *, Config *); void do_defaults(char *, Config *);
void registry_cleanup(void); void registry_cleanup(void);

Просмотреть файл

@ -659,10 +659,9 @@ static int sessioncmp(const void *av, const void *bv)
return strcmp(a, b); /* otherwise, compare normally */ return strcmp(a, b); /* otherwise, compare normally */
} }
void get_sesslist(int allocate) void get_sesslist(struct sesslist *list, int allocate)
{ {
static char otherbuf[2048]; char otherbuf[2048];
static char *buffer;
int buflen, bufsize, i; int buflen, bufsize, i;
char *p, *ret; char *p, *ret;
void *handle; void *handle;
@ -670,7 +669,7 @@ void get_sesslist(int allocate)
if (allocate) { if (allocate) {
buflen = bufsize = 0; buflen = bufsize = 0;
buffer = NULL; list->buffer = NULL;
if ((handle = enum_settings_start())) { if ((handle = enum_settings_start())) {
do { do {
ret = enum_settings_next(handle, otherbuf, sizeof(otherbuf)); ret = enum_settings_next(handle, otherbuf, sizeof(otherbuf));
@ -678,16 +677,16 @@ void get_sesslist(int allocate)
int len = strlen(otherbuf) + 1; int len = strlen(otherbuf) + 1;
if (bufsize < buflen + len) { if (bufsize < buflen + len) {
bufsize = buflen + len + 2048; bufsize = buflen + len + 2048;
buffer = srealloc(buffer, bufsize); list->buffer = srealloc(list->buffer, bufsize);
} }
strcpy(buffer + buflen, otherbuf); strcpy(list->buffer + buflen, otherbuf);
buflen += strlen(buffer + buflen) + 1; buflen += strlen(list->buffer + buflen) + 1;
} }
} while (ret); } while (ret);
enum_settings_finish(handle); enum_settings_finish(handle);
} }
buffer = srealloc(buffer, buflen + 1); list->buffer = srealloc(list->buffer, buflen + 1);
buffer[buflen] = '\0'; list->buffer[buflen] = '\0';
/* /*
* Now set up the list of sessions. Note that "Default * Now set up the list of sessions. Note that "Default
@ -695,31 +694,31 @@ void get_sesslist(int allocate)
* doesn't really. * doesn't really.
*/ */
p = buffer; p = list->buffer;
nsessions = 1; /* "Default Settings" counts as one */ list->nsessions = 1; /* "Default Settings" counts as one */
while (*p) { while (*p) {
if (strcmp(p, "Default Settings")) if (strcmp(p, "Default Settings"))
nsessions++; list->nsessions++;
while (*p) while (*p)
p++; p++;
p++; p++;
} }
sessions = smalloc((nsessions + 1) * sizeof(char *)); list->sessions = smalloc((list->nsessions + 1) * sizeof(char *));
sessions[0] = "Default Settings"; list->sessions[0] = "Default Settings";
p = buffer; p = list->buffer;
i = 1; i = 1;
while (*p) { while (*p) {
if (strcmp(p, "Default Settings")) if (strcmp(p, "Default Settings"))
sessions[i++] = p; list->sessions[i++] = p;
while (*p) while (*p)
p++; p++;
p++; p++;
} }
qsort(sessions, i, sizeof(char *), sessioncmp); qsort(list->sessions, i, sizeof(char *), sessioncmp);
} else { } else {
sfree(buffer); sfree(list->buffer);
sfree(sessions); sfree(list->sessions);
} }
} }

Просмотреть файл

@ -27,6 +27,8 @@ static int requested_help;
static struct prefslist cipherlist; static struct prefslist cipherlist;
struct sesslist sesslist; /* exported to window.c */
#define PRINTER_DISABLED_STRING "None (printing disabled)" #define PRINTER_DISABLED_STRING "None (printing disabled)"
void force_normal(HWND hwnd) void force_normal(HWND hwnd)
@ -1069,9 +1071,9 @@ static void init_dlg_ctrls(HWND hwnd, int keepsess)
n = SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_GETCOUNT, 0, 0); n = SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_GETCOUNT, 0, 0);
for (i = n; i-- > 0;) for (i = n; i-- > 0;)
SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_DELETESTRING, i, 0); SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_DELETESTRING, i, 0);
for (i = 0; i < nsessions; i++) for (i = 0; i < sesslist.nsessions; i++)
SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_ADDSTRING, SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_ADDSTRING,
0, (LPARAM) (sessions[i])); 0, (LPARAM) (sesslist.sessions[i]));
} }
SetDlgItemInt(hwnd, IDC_PORT, cfg.port, FALSE); SetDlgItemInt(hwnd, IDC_PORT, cfg.port, FALSE);
CheckRadioButton(hwnd, IDC_PROTRAW, IDC_PROTSSH, CheckRadioButton(hwnd, IDC_PROTRAW, IDC_PROTSSH,
@ -2059,11 +2061,11 @@ static int load_selected_session(HWND hwnd)
MessageBeep(0); MessageBeep(0);
return 0; return 0;
} }
isdef = !strcmp(sessions[n], "Default Settings"); isdef = !strcmp(sesslist.sessions[n], "Default Settings");
load_settings(sessions[n], !isdef, &cfg); load_settings(sesslist.sessions[n], !isdef, &cfg);
init_dlg_ctrls(hwnd, TRUE); init_dlg_ctrls(hwnd, TRUE);
if (!isdef) if (!isdef)
SetDlgItemText(hwnd, IDC_SESSEDIT, sessions[n]); SetDlgItemText(hwnd, IDC_SESSEDIT, sesslist.sessions[n]);
else else
SetDlgItemText(hwnd, IDC_SESSEDIT, ""); SetDlgItemText(hwnd, IDC_SESSEDIT, "");
/* Restore the selection, which will have been clobbered by /* Restore the selection, which will have been clobbered by
@ -2413,20 +2415,20 @@ static int GenericMainDlgProc(HWND hwnd, UINT msg,
MessageBeep(0); MessageBeep(0);
break; break;
} }
strcpy(str, sessions[n]); strcpy(str, sesslist.sessions[n]);
} }
save_settings(str, !!strcmp(str, "Default Settings"), save_settings(str, !!strcmp(str, "Default Settings"),
&cfg); &cfg);
get_sesslist(FALSE); get_sesslist(&sesslist, FALSE);
get_sesslist(TRUE); get_sesslist(&sesslist, TRUE);
SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW, SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
FALSE, 0); FALSE, 0);
SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_RESETCONTENT, SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_RESETCONTENT,
0, 0); 0, 0);
for (i = 0; i < nsessions; i++) for (i = 0; i < sesslist.nsessions; i++)
SendDlgItemMessage(hwnd, IDC_SESSLIST, SendDlgItemMessage(hwnd, IDC_SESSLIST,
LB_ADDSTRING, 0, LB_ADDSTRING, 0,
(LPARAM) (sessions[i])); (LPARAM) (sesslist.sessions[i]));
SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL, SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL,
(WPARAM) - 1, 0); (WPARAM) - 1, 0);
SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW, SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
@ -2472,17 +2474,17 @@ static int GenericMainDlgProc(HWND hwnd, UINT msg,
MessageBeep(0); MessageBeep(0);
break; break;
} }
del_settings(sessions[n]); del_settings(sesslist.sessions[n]);
get_sesslist(FALSE); get_sesslist(&sesslist, FALSE);
get_sesslist(TRUE); get_sesslist(&sesslist, TRUE);
SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW, SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
FALSE, 0); FALSE, 0);
SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_RESETCONTENT, SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_RESETCONTENT,
0, 0); 0, 0);
for (i = 0; i < nsessions; i++) for (i = 0; i < sesslist.nsessions; i++)
SendDlgItemMessage(hwnd, IDC_SESSLIST, SendDlgItemMessage(hwnd, IDC_SESSLIST,
LB_ADDSTRING, 0, LB_ADDSTRING, 0,
(LPARAM) (sessions[i])); (LPARAM) (sesslist.sessions[i]));
SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL, SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL,
(WPARAM) - 1, 0); (WPARAM) - 1, 0);
SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW, SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
@ -3726,11 +3728,11 @@ int do_config(void)
{ {
int ret; int ret;
get_sesslist(TRUE); get_sesslist(&sesslist, TRUE);
savedsession[0] = '\0'; savedsession[0] = '\0';
ret = ret =
DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL, MainDlgProc); DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL, MainDlgProc);
get_sesslist(FALSE); get_sesslist(&sesslist, FALSE);
return ret; return ret;
} }

Просмотреть файл

@ -115,10 +115,16 @@ static time_t last_movement = 0;
static int caret_x = -1, caret_y = -1; static int caret_x = -1, caret_y = -1;
static int kbd_codepage;
static void *ldisc; static void *ldisc;
static Backend *back; static Backend *back;
static void *backhandle; static void *backhandle;
static int session_closed;
extern struct sesslist sesslist; /* imported from windlg.c */
#define FONT_NORMAL 0 #define FONT_NORMAL 0
#define FONT_BOLD 1 #define FONT_BOLD 1
#define FONT_UNDERLINE 2 #define FONT_UNDERLINE 2
@ -683,10 +689,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_NEWSESS, "Ne&w Session...");
AppendMenu(m, MF_ENABLED, IDM_DUPSESS, "&Duplicate Session"); AppendMenu(m, MF_ENABLED, IDM_DUPSESS, "&Duplicate Session");
s = CreateMenu(); s = CreateMenu();
get_sesslist(TRUE); get_sesslist(&sesslist, TRUE);
for (i = 1; i < ((nsessions < 256) ? nsessions : 256); i++) for (i = 1;
i < ((sesslist.nsessions < 256) ? sesslist.nsessions : 256);
i++)
AppendMenu(s, MF_ENABLED, IDM_SAVED_MIN + (16 * 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_POPUP | MF_ENABLED, (UINT) s, "Sa&ved Sessions");
AppendMenu(m, MF_ENABLED, IDM_RECONF, "Chan&ge Settings..."); AppendMenu(m, MF_ENABLED, IDM_RECONF, "Chan&ge Settings...");
AppendMenu(m, MF_SEPARATOR, 0, 0); AppendMenu(m, MF_SEPARATOR, 0, 0);
@ -1692,9 +1700,9 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
sprintf(c, "putty &%p", filemap); sprintf(c, "putty &%p", filemap);
cl = c; cl = c;
} else if (wParam == IDM_SAVEDSESS) { } else if (wParam == IDM_SAVEDSESS) {
if ((lParam - IDM_SAVED_MIN) / 16 < nsessions) { if ((lParam - IDM_SAVED_MIN) / 16 < sesslist.nsessions) {
char *session = char *session =
sessions[(lParam - IDM_SAVED_MIN) / 16]; sesslist.sessions[(lParam - IDM_SAVED_MIN) / 16];
cl = smalloc(16 + strlen(session)); cl = smalloc(16 + strlen(session));
/* 8, but play safe */ /* 8, but play safe */
if (!cl) if (!cl)

Просмотреть файл

@ -59,7 +59,7 @@ GLOBAL int help_has_contents;
/* /*
* The terminal and logging context are notionally local to the * The terminal and logging context are notionally local to the
* Windows front end, but they must be shared between window.c and * Windows front end, but they must be shared between window.c and
* windlg.c. * windlg.c. Likewise the saved-sessions list.
*/ */
GLOBAL Terminal *term; GLOBAL Terminal *term;
GLOBAL void *logctx; GLOBAL void *logctx;