mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 11:02:48 -05:00
Change the semantics of 'FontSpec' so that it's a dynamically
allocated type. The main reason for this is to stop it from taking up a fixed large amount of space in every 'struct value' subunion in conf.c, although that makes little difference so far because Filename is still doing the same thing (and is therefore next on my list). However, the removal of its arbitrary length limit is not to be sneezed at. [originally from svn r9314]
This commit is contained in:
@ -926,24 +926,22 @@ void dlg_filesel_get(union control *ctrl, void *dlg, Filename *fn)
|
||||
fn->path[lenof(fn->path)-1] = '\0';
|
||||
}
|
||||
|
||||
void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec fs)
|
||||
void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec *fs)
|
||||
{
|
||||
struct dlgparam *dp = (struct dlgparam *)dlg;
|
||||
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
|
||||
assert(uc->ctrl->generic.type == CTRL_FONTSELECT);
|
||||
assert(uc->entry != NULL);
|
||||
gtk_entry_set_text(GTK_ENTRY(uc->entry), fs.name);
|
||||
gtk_entry_set_text(GTK_ENTRY(uc->entry), fs->name);
|
||||
}
|
||||
|
||||
void dlg_fontsel_get(union control *ctrl, void *dlg, FontSpec *fs)
|
||||
FontSpec *dlg_fontsel_get(union control *ctrl, void *dlg)
|
||||
{
|
||||
struct dlgparam *dp = (struct dlgparam *)dlg;
|
||||
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
|
||||
assert(uc->ctrl->generic.type == CTRL_FONTSELECT);
|
||||
assert(uc->entry != NULL);
|
||||
strncpy(fs->name, gtk_entry_get_text(GTK_ENTRY(uc->entry)),
|
||||
lenof(fs->name));
|
||||
fs->name[lenof(fs->name)-1] = '\0';
|
||||
return fontspec_new(gtk_entry_get_text(GTK_ENTRY(uc->entry)));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -151,14 +151,12 @@ void connection_fatal(void *frontend, char *p, ...)
|
||||
/*
|
||||
* Default settings that are specific to pterm.
|
||||
*/
|
||||
FontSpec platform_default_fontspec(const char *name)
|
||||
FontSpec *platform_default_fontspec(const char *name)
|
||||
{
|
||||
FontSpec ret;
|
||||
if (!strcmp(name, "Font"))
|
||||
strcpy(ret.name, "server:fixed");
|
||||
return fontspec_new("server:fixed");
|
||||
else
|
||||
*ret.name = '\0';
|
||||
return ret;
|
||||
return fontspec_new("");
|
||||
}
|
||||
|
||||
Filename platform_default_filename(const char *name)
|
||||
@ -2541,36 +2539,36 @@ int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch,
|
||||
}
|
||||
|
||||
if (!strcmp(p, "-fn") || !strcmp(p, "-font")) {
|
||||
FontSpec fs;
|
||||
FontSpec *fs;
|
||||
EXPECTS_ARG;
|
||||
SECOND_PASS_ONLY;
|
||||
strncpy(fs.name, val, sizeof(fs.name));
|
||||
fs.name[sizeof(fs.name)-1] = '\0';
|
||||
conf_set_fontspec(conf, CONF_font, &fs);
|
||||
fs = fontspec_new(val);
|
||||
conf_set_fontspec(conf, CONF_font, fs);
|
||||
fontspec_free(fs);
|
||||
|
||||
} else if (!strcmp(p, "-fb")) {
|
||||
FontSpec fs;
|
||||
FontSpec *fs;
|
||||
EXPECTS_ARG;
|
||||
SECOND_PASS_ONLY;
|
||||
strncpy(fs.name, val, sizeof(fs.name));
|
||||
fs.name[sizeof(fs.name)-1] = '\0';
|
||||
conf_set_fontspec(conf, CONF_boldfont, &fs);
|
||||
fs = fontspec_new(val);
|
||||
conf_set_fontspec(conf, CONF_font, fs);
|
||||
fontspec_free(fs);
|
||||
|
||||
} else if (!strcmp(p, "-fw")) {
|
||||
FontSpec fs;
|
||||
FontSpec *fs;
|
||||
EXPECTS_ARG;
|
||||
SECOND_PASS_ONLY;
|
||||
strncpy(fs.name, val, sizeof(fs.name));
|
||||
fs.name[sizeof(fs.name)-1] = '\0';
|
||||
conf_set_fontspec(conf, CONF_widefont, &fs);
|
||||
fs = fontspec_new(val);
|
||||
conf_set_fontspec(conf, CONF_font, fs);
|
||||
fontspec_free(fs);
|
||||
|
||||
} else if (!strcmp(p, "-fwb")) {
|
||||
FontSpec fs;
|
||||
FontSpec *fs;
|
||||
EXPECTS_ARG;
|
||||
SECOND_PASS_ONLY;
|
||||
strncpy(fs.name, val, sizeof(fs.name));
|
||||
fs.name[sizeof(fs.name)-1] = '\0';
|
||||
conf_set_fontspec(conf, CONF_wideboldfont, &fs);
|
||||
fs = fontspec_new(val);
|
||||
conf_set_fontspec(conf, CONF_font, fs);
|
||||
fontspec_free(fs);
|
||||
|
||||
} else if (!strcmp(p, "-cs")) {
|
||||
EXPECTS_ARG;
|
||||
|
@ -18,8 +18,9 @@ struct Filename {
|
||||
FILE *f_open(struct Filename, char const *, int);
|
||||
|
||||
struct FontSpec {
|
||||
char name[256];
|
||||
char *name; /* may be "" to indicate no selected font at all */
|
||||
};
|
||||
struct FontSpec *fontspec_new(const char *name);
|
||||
|
||||
typedef void *Context; /* FIXME: probably needs changing */
|
||||
|
||||
|
@ -150,3 +150,35 @@ FILE *f_open(struct Filename filename, char const *mode, int is_private)
|
||||
return fdopen(fd, mode);
|
||||
}
|
||||
}
|
||||
|
||||
FontSpec *fontspec_new(const char *name)
|
||||
{
|
||||
FontSpec *f = snew(FontSpec);
|
||||
f->name = dupstr(name);
|
||||
return f;
|
||||
}
|
||||
FontSpec *fontspec_copy(const FontSpec *f)
|
||||
{
|
||||
return fontspec_new(f->name);
|
||||
}
|
||||
void fontspec_free(FontSpec *f)
|
||||
{
|
||||
sfree(f->name);
|
||||
sfree(f);
|
||||
}
|
||||
int fontspec_serialise(FontSpec *f, void *data)
|
||||
{
|
||||
int len = strlen(f->name);
|
||||
if (data)
|
||||
strcpy(data, f->name);
|
||||
return len + 1; /* include trailing NUL */
|
||||
}
|
||||
FontSpec *fontspec_deserialise(void *vdata, int maxsize, int *used)
|
||||
{
|
||||
char *data = (char *)vdata;
|
||||
char *end = memchr(data, '\0', maxsize);
|
||||
if (!end)
|
||||
return NULL;
|
||||
*used = end - data + 1;
|
||||
return fontspec_new(data);
|
||||
}
|
||||
|
@ -125,11 +125,9 @@ int platform_default_i(const char *name, int def)
|
||||
return def;
|
||||
}
|
||||
|
||||
FontSpec platform_default_fontspec(const char *name)
|
||||
FontSpec *platform_default_fontspec(const char *name)
|
||||
{
|
||||
FontSpec ret;
|
||||
*ret.name = '\0';
|
||||
return ret;
|
||||
return fontspec_new("");
|
||||
}
|
||||
|
||||
Filename platform_default_filename(const char *name)
|
||||
|
@ -53,11 +53,9 @@ int platform_default_i(const char *name, int def)
|
||||
return def;
|
||||
}
|
||||
|
||||
FontSpec platform_default_fontspec(const char *name)
|
||||
FontSpec *platform_default_fontspec(const char *name)
|
||||
{
|
||||
FontSpec ret;
|
||||
*ret.name = '\0';
|
||||
return ret;
|
||||
return fontspec_new("");
|
||||
}
|
||||
|
||||
Filename platform_default_filename(const char *name)
|
||||
|
@ -357,7 +357,7 @@ int read_setting_i(void *handle, const char *key, int defvalue)
|
||||
return atoi(val);
|
||||
}
|
||||
|
||||
int read_setting_fontspec(void *handle, const char *name, FontSpec *result)
|
||||
FontSpec *read_setting_fontspec(void *handle, const char *name)
|
||||
{
|
||||
/*
|
||||
* In GTK1-only PuTTY, we used to store font names simply as a
|
||||
@ -375,25 +375,24 @@ int read_setting_fontspec(void *handle, const char *name, FontSpec *result)
|
||||
char *tmp;
|
||||
|
||||
if ((tmp = read_setting_s(handle, suffname)) != NULL) {
|
||||
strncpy(result->name, tmp, sizeof(result->name)-1);
|
||||
result->name[sizeof(result->name)-1] = '\0';
|
||||
FontSpec *fs = fontspec_new(tmp);
|
||||
sfree(suffname);
|
||||
sfree(tmp);
|
||||
return TRUE; /* got new-style name */
|
||||
return fs; /* got new-style name */
|
||||
}
|
||||
sfree(suffname);
|
||||
|
||||
/* Fall back to old-style name. */
|
||||
tmp = read_setting_s(handle, name);
|
||||
if (tmp && *tmp) {
|
||||
strcpy(result->name, "server:");
|
||||
strncpy(result->name + 7, tmp, sizeof(result->name) - 8);
|
||||
result->name[sizeof(result->name)-1] = '\0';
|
||||
char *tmp2 = dupcat("server:", tmp, NULL);
|
||||
FontSpec *fs = fontspec_new(tmp2);
|
||||
sfree(tmp2);
|
||||
sfree(tmp);
|
||||
return TRUE;
|
||||
return fs;
|
||||
} else {
|
||||
sfree(tmp);
|
||||
return FALSE;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
int read_setting_filename(void *handle, const char *name, Filename *result)
|
||||
@ -408,7 +407,7 @@ int read_setting_filename(void *handle, const char *name, Filename *result)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void write_setting_fontspec(void *handle, const char *name, FontSpec result)
|
||||
void write_setting_fontspec(void *handle, const char *name, FontSpec *fs)
|
||||
{
|
||||
/*
|
||||
* read_setting_fontspec had to handle two cases, but when
|
||||
@ -416,7 +415,7 @@ void write_setting_fontspec(void *handle, const char *name, FontSpec result)
|
||||
* new-style name.
|
||||
*/
|
||||
char *suffname = dupcat(name, "Name", NULL);
|
||||
write_setting_s(handle, suffname, result.name);
|
||||
write_setting_s(handle, suffname, fs->name);
|
||||
sfree(suffname);
|
||||
}
|
||||
void write_setting_filename(void *handle, const char *name, Filename result)
|
||||
|
Reference in New Issue
Block a user