* to catch it now.
*/
filename = make_filename(INDEX_SESSIONDIR, NULL);
- if (!mkdir(filename, 0700)) {
+ if (mkdir(filename, 0700) != 0) {
char *filename2 = make_filename(INDEX_DIR, NULL);
mkdir(filename2, 0700);
sfree(filename2);
* FIXME: the above comment is a bit out of date. Did it happen?
*/
-struct keyval {
+struct skeyval {
const char *key;
const char *value;
};
int keycmp(void *av, void *bv)
{
- struct keyval *a = (struct keyval *)av;
- struct keyval *b = (struct keyval *)bv;
+ struct skeyval *a = (struct skeyval *)av;
+ struct skeyval *b = (struct skeyval *)bv;
return strcmp(a->key, b->key);
}
void provide_xrm_string(char *string)
{
char *p, *q, *key;
- struct keyval *xrms, *ret;
+ struct skeyval *xrms, *ret;
p = q = strchr(string, ':');
if (!q) {
q++;
while (p > string && p[-1] != '.' && p[-1] != '*')
p--;
- xrms = snew(struct keyval);
+ xrms = snew(struct skeyval);
key = snewn(q-p, char);
memcpy(key, p, q-p);
key[q-p-1] = '\0';
const char *get_setting(const char *key)
{
- struct keyval tmp, *ret;
+ struct skeyval tmp, *ret;
tmp.key = key;
if (xrmtree) {
ret = find234(xrmtree, &tmp, NULL);
while ( (line = fgetline(fp)) ) {
char *value = strchr(line, '=');
- struct keyval *kv;
+ struct skeyval *kv;
if (!value)
continue;
*value++ = '\0';
value[strcspn(value, "\r\n")] = '\0'; /* trim trailing NL */
- kv = snew(struct keyval);
+ kv = snew(struct skeyval);
kv->key = dupstr(line);
kv->value = dupstr(value);
add234(ret, kv);
return ret;
}
-char *read_setting_s(void *handle, const char *key, char *buffer, int buflen)
+char *read_setting_s(void *handle, const char *key)
{
tree234 *tree = (tree234 *)handle;
const char *val;
- struct keyval tmp, *kv;
+ struct skeyval tmp, *kv;
tmp.key = key;
if (tree != NULL &&
if (!val)
return NULL;
- else {
- strncpy(buffer, val, buflen);
- buffer[buflen-1] = '\0';
- return buffer;
- }
+ else
+ return dupstr(val);
}
int read_setting_i(void *handle, const char *key, int defvalue)
{
tree234 *tree = (tree234 *)handle;
const char *val;
- struct keyval tmp, *kv;
+ struct skeyval tmp, *kv;
tmp.key = key;
if (tree != NULL &&
return atoi(val);
}
-int read_setting_fontspec(void *handle, const char *name, FontSpec *result)
+FontSpec *read_setting_fontspec(void *handle, const char *name)
{
- return !!read_setting_s(handle, name, result->name, sizeof(result->name));
+ /*
+ * In GTK1-only PuTTY, we used to store font names simply as a
+ * valid X font description string (logical or alias), under a
+ * bare key such as "Font".
+ *
+ * In GTK2 PuTTY, we have a prefix system where "client:"
+ * indicates a Pango font and "server:" an X one; existing
+ * configuration needs to be reinterpreted as having the
+ * "server:" prefix, so we change the storage key from the
+ * provided name string (e.g. "Font") to a suffixed one
+ * ("FontName").
+ */
+ char *suffname = dupcat(name, "Name", NULL);
+ char *tmp;
+
+ if ((tmp = read_setting_s(handle, suffname)) != NULL) {
+ FontSpec *fs = fontspec_new(tmp);
+ sfree(suffname);
+ sfree(tmp);
+ return fs; /* got new-style name */
+ }
+ sfree(suffname);
+
+ /* Fall back to old-style name. */
+ tmp = read_setting_s(handle, name);
+ if (tmp && *tmp) {
+ char *tmp2 = dupcat("server:", tmp, NULL);
+ FontSpec *fs = fontspec_new(tmp2);
+ sfree(tmp2);
+ sfree(tmp);
+ return fs;
+ } else {
+ sfree(tmp);
+ return NULL;
+ }
}
-int read_setting_filename(void *handle, const char *name, Filename *result)
+Filename *read_setting_filename(void *handle, const char *name)
{
- return !!read_setting_s(handle, name, result->path, sizeof(result->path));
+ char *tmp = read_setting_s(handle, name);
+ if (tmp) {
+ Filename *ret = filename_from_str(tmp);
+ sfree(tmp);
+ return ret;
+ } else
+ return NULL;
}
-void write_setting_fontspec(void *handle, const char *name, FontSpec result)
+void write_setting_fontspec(void *handle, const char *name, FontSpec *fs)
{
- write_setting_s(handle, name, result.name);
+ /*
+ * read_setting_fontspec had to handle two cases, but when
+ * writing our settings back out we simply always generate the
+ * new-style name.
+ */
+ char *suffname = dupcat(name, "Name", NULL);
+ write_setting_s(handle, suffname, fs->name);
+ sfree(suffname);
}
-void write_setting_filename(void *handle, const char *name, Filename result)
+void write_setting_filename(void *handle, const char *name, Filename *result)
{
- write_setting_s(handle, name, result.path);
+ write_setting_s(handle, name, result->path);
}
void close_settings_r(void *handle)
{
tree234 *tree = (tree234 *)handle;
- struct keyval *kv;
+ struct skeyval *kv;
if (!tree)
return;
fname = make_filename(INDEX_RANDSEED, NULL);
fd = open(fname, O_RDONLY);
sfree(fname);
- if (fd) {
+ if (fd >= 0) {
char buf[512];
int ret;
while ( (ret = read(fd, buf, sizeof(buf))) > 0)