save_settings(ssd->savedsession, isdef, cfg);
save_settings(ssd->savedsession, !isdef, cfg);
static void sessionsaver_handler(union control *ctrl, void *dlg,				 void *data, int event){    Config *cfg = (Config *)data;    struct sessionsaver_data *ssd =	(struct sessionsaver_data *)ctrl->generic.context.p;    if (event == EVENT_REFRESH) {	if (ctrl == ssd->editbox) {	    dlg_editbox_set(ctrl, dlg, ssd->savedsession);	} else if (ctrl == ssd->listbox) {	    int i;	    dlg_update_start(ctrl, dlg);	    dlg_listbox_clear(ctrl, dlg);	    for (i = 0; i < ssd->sesslist->nsessions; i++)		dlg_listbox_add(ctrl, dlg, ssd->sesslist->sessions[i]);	    dlg_update_done(ctrl, dlg);	}    } else if (event == EVENT_VALCHANGE) {	if (ctrl == ssd->editbox) {	    dlg_editbox_get(ctrl, dlg, ssd->savedsession,			    sizeof(ssd->savedsession));	}    } else if (event == EVENT_ACTION) {	if (ctrl == ssd->listbox || ctrl == ssd->loadbutton) {	    /*	     * The user has double-clicked a session, or hit Load.	     * We must load the selected session, and then	     * terminate the configuration dialog _if_ there was a	     * double-click on the list box _and_ that session	     * contains a hostname.	     */	    if (load_selected_session(ssd, dlg, cfg) &&		(ctrl == ssd->listbox && cfg->host[0])) {		dlg_end(dlg, 1);       /* it's all over, and succeeded */	    }	} else if (ctrl == ssd->savebutton) {	    int isdef = !strcmp(ssd->savedsession, "Default Settings");	    if (!ssd->savedsession[0]) {		int i = dlg_listbox_index(ctrl, dlg);		if (i < 0) {		    dlg_beep(dlg);		    return;		}		isdef = !strcmp(ssd->sesslist->sessions[i], "Default Settings");		if (!isdef) {		    strncpy(ssd->savedsession, ssd->sesslist->sessions[i],			    sizeof(ssd->savedsession));		    ssd->savedsession[sizeof(ssd->savedsession)-1] = '\0';		} else {		    ssd->savedsession[0] = '\0';		}	    }	    save_settings(ssd->savedsession, isdef, cfg);	    get_sesslist(ssd->sesslist, FALSE);	    get_sesslist(ssd->sesslist, TRUE);	    dlg_refresh(ssd->editbox, dlg);	    dlg_refresh(ssd->listbox, dlg);	} else if (ctrl == ssd->delbutton) {	    int i = dlg_listbox_index(ssd->listbox, dlg);	    if (i <= 0) {		dlg_beep(dlg);	    } else {		del_settings(ssd->sesslist->sessions[i]);		get_sesslist(ssd->sesslist, FALSE);		get_sesslist(ssd->sesslist, TRUE);		dlg_refresh(ssd->listbox, dlg);	    }	} else if (ctrl == ssd->okbutton) {	    /*	     * Annoying special case. If the `Open' button is	     * pressed while no host name is currently set, _and_	     * the session list previously had the focus, _and_	     * there was a session selected in that which had a	     * valid host name in it, then load it and go.	     */	    if (dlg_last_focused(dlg) == ssd->listbox && !*cfg->host) {		Config cfg2;		if (!load_selected_session(ssd, dlg, &cfg2)) {		    dlg_beep(dlg);		    return;		}		/* If at this point we have a valid session, go! */		if (*cfg2.host) {		    *cfg = cfg2;       /* structure copy */		    dlg_end(dlg, 1);		} else		    dlg_beep(dlg);	    }	    /*	     * Otherwise, do the normal thing: if we have a valid	     * session, get going.	     */	    if (*cfg->host) {		dlg_end(dlg, 1);	    } else		dlg_beep(dlg);	} else if (ctrl == ssd->cancelbutton) {	    dlg_end(dlg, 0);	}    }}