mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Introduce a conf value type of bool.
It's not actually used anywhere yet, though. This is just adding the accessor functions, which will enforce a rigorous separation between conf keys typed as int and as bool.
This commit is contained in:
parent
a6f1709c2f
commit
5691805cbd
38
conf.c
38
conf.c
@ -13,7 +13,9 @@
|
||||
/*
|
||||
* Enumeration of types used in keys and values.
|
||||
*/
|
||||
typedef enum { TYPE_NONE, TYPE_INT, TYPE_STR, TYPE_FILENAME, TYPE_FONT } Type;
|
||||
typedef enum {
|
||||
TYPE_NONE, TYPE_BOOL, TYPE_INT, TYPE_STR, TYPE_FILENAME, TYPE_FONT
|
||||
} Type;
|
||||
|
||||
/*
|
||||
* Arrays which allow us to look up the subkey and value types for a
|
||||
@ -51,6 +53,7 @@ struct constkey {
|
||||
|
||||
struct value {
|
||||
union {
|
||||
bool boolval;
|
||||
int intval;
|
||||
char *stringval;
|
||||
Filename *fileval;
|
||||
@ -171,6 +174,9 @@ static void free_value(struct value *val, int type)
|
||||
static void copy_value(struct value *to, struct value *from, int type)
|
||||
{
|
||||
switch (type) {
|
||||
case TYPE_BOOL:
|
||||
to->u.boolval = from->u.boolval;
|
||||
break;
|
||||
case TYPE_INT:
|
||||
to->u.intval = from->u.intval;
|
||||
break;
|
||||
@ -256,6 +262,19 @@ Conf *conf_copy(Conf *oldconf)
|
||||
return newconf;
|
||||
}
|
||||
|
||||
bool conf_get_bool(Conf *conf, int primary)
|
||||
{
|
||||
struct key key;
|
||||
struct conf_entry *entry;
|
||||
|
||||
assert(subkeytypes[primary] == TYPE_NONE);
|
||||
assert(valuetypes[primary] == TYPE_BOOL);
|
||||
key.primary = primary;
|
||||
entry = find234(conf->tree, &key, NULL);
|
||||
assert(entry);
|
||||
return entry->value.u.boolval;
|
||||
}
|
||||
|
||||
int conf_get_int(Conf *conf, int primary)
|
||||
{
|
||||
struct key key;
|
||||
@ -384,6 +403,17 @@ FontSpec *conf_get_fontspec(Conf *conf, int primary)
|
||||
return entry->value.u.fontval;
|
||||
}
|
||||
|
||||
void conf_set_bool(Conf *conf, int primary, bool value)
|
||||
{
|
||||
struct conf_entry *entry = snew(struct conf_entry);
|
||||
|
||||
assert(subkeytypes[primary] == TYPE_NONE);
|
||||
assert(valuetypes[primary] == TYPE_BOOL);
|
||||
entry->key.primary = primary;
|
||||
entry->value.u.boolval = value;
|
||||
conf_insert(conf, entry);
|
||||
}
|
||||
|
||||
void conf_set_int(Conf *conf, int primary, int value)
|
||||
{
|
||||
struct conf_entry *entry = snew(struct conf_entry);
|
||||
@ -486,6 +516,9 @@ void conf_serialise(BinarySink *bs, Conf *conf)
|
||||
break;
|
||||
}
|
||||
switch (valuetypes[entry->key.primary]) {
|
||||
case TYPE_BOOL:
|
||||
put_bool(bs, entry->value.u.boolval);
|
||||
break;
|
||||
case TYPE_INT:
|
||||
put_uint32(bs, entry->value.u.intval);
|
||||
break;
|
||||
@ -532,6 +565,9 @@ int conf_deserialise(Conf *conf, BinarySource *src)
|
||||
}
|
||||
|
||||
switch (valuetypes[entry->key.primary]) {
|
||||
case TYPE_BOOL:
|
||||
entry->value.u.boolval = get_bool(src);
|
||||
break;
|
||||
case TYPE_INT:
|
||||
entry->value.u.intval = toint(get_uint32(src));
|
||||
break;
|
||||
|
2
putty.h
2
putty.h
@ -1410,6 +1410,7 @@ void conf_free(Conf *conf);
|
||||
Conf *conf_copy(Conf *oldconf);
|
||||
void conf_copy_into(Conf *dest, Conf *src);
|
||||
/* Mandatory accessor functions: enforce by assertion that keys exist. */
|
||||
bool conf_get_bool(Conf *conf, int key);
|
||||
int conf_get_int(Conf *conf, int key);
|
||||
int conf_get_int_int(Conf *conf, int key, int subkey);
|
||||
char *conf_get_str(Conf *conf, int key); /* result still owned by conf */
|
||||
@ -1426,6 +1427,7 @@ char *conf_get_str_strs(Conf *conf, int key, char *subkeyin, char **subkeyout);
|
||||
/* Return the nth string subkey in a list. Owned by conf. NULL if beyond end */
|
||||
char *conf_get_str_nthstrkey(Conf *conf, int key, int n);
|
||||
/* Functions to set entries in configuration. Always copy their inputs. */
|
||||
void conf_set_bool(Conf *conf, int key, bool value);
|
||||
void conf_set_int(Conf *conf, int key, int value);
|
||||
void conf_set_int_int(Conf *conf, int key, int subkey, int value);
|
||||
void conf_set_str(Conf *conf, int key, const char *value);
|
||||
|
Loading…
Reference in New Issue
Block a user