From a123725a12e948d78badb2cb686d38548f1c633b Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Thu, 6 Apr 2023 23:23:46 +0200 Subject: Implement window handling Also implement searching. fix undo boundaries when it checked for other save point, it used && instead of == which caused it to overwrite other types. Fix bytes vs chars bug in text_get_region --- src/dged/settings.h | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 src/dged/settings.h (limited to 'src/dged/settings.h') diff --git a/src/dged/settings.h b/src/dged/settings.h new file mode 100644 index 0000000..5d245d9 --- /dev/null +++ b/src/dged/settings.h @@ -0,0 +1,137 @@ +#include "hashmap.h" + +#include +#include + +struct commands; + +/** + * The type of setting value. + */ +enum setting_type { + /** String setting. */ + Setting_String = 0, + + /** Number setting (a signed 64 bit integer). */ + Setting_Number, + + /** Boolean setting. */ + Setting_Bool, +}; + +/** + * Value for a setting. + */ +struct setting_value { + /** Type of setting. */ + enum setting_type type; + + union { + /** String setting. */ + char *string_value; + + /** Real number setting. */ + int64_t number_value; + + /** Boolean setting value. */ + bool bool_value; + }; +}; + +/** + * A single setting. + * + * A setting has a "path", denoted by a string + * containing a number (0-) of dots. + * Example: editor.tab-width. + */ +struct setting { + + /** Path of the setting. */ + char path[128]; + + /** Value of the setting. */ + struct setting_value value; +}; + +HASHMAP_ENTRY_TYPE(setting_entry, struct setting); + +/** + * A collection of settings. + */ +struct settings { + HASHMAP(struct setting_entry) settings; +}; + +/** + * Initialize the global collection of settings. + * + * @param initial_capacity Initial capacity of the settings collection. + * @returns Nothing, the settings collection is a global instance. + */ +void settings_init(uint32_t initial_capacity); + +/** + * Destroy the global collection of settings. + */ +void settings_destroy(); + +/** + * Register a new setting. + * + * @param path The path of the new setting on + * the form ... + * @param default_value The default value for the setting. + * All settings are required to declare a default value. + */ +void settings_register_setting(const char *path, + struct setting_value default_value); + +/** + * Retrieve a single setting by path. + * + * @param path The exact path of the setting on + * the form ... + * @returns A pointer to the setting if found, NULL otherwise. + */ +struct setting *settings_get(const char *path); + +/** + * Retrieve a collection of settings by prefix + * + * @param prefix Path prefix for the settings to retrieve. + * @param settings_out Pointer to an array that will be modified to point to the + * result. + * @param nsettings_out Pointer to an integer that will be set to the number of + * settings pointers in the result. + */ +void settings_get_prefix(const char *prefix, struct setting **settings_out[], + uint32_t *nsettings_out); + +/** + * Set a value for a setting. + * + * @param path The exact path of the setting on + * the form ... + * @param value The new value of the setting. The type has to match the declared + * type for the setting. If not, the new value is ignored. + */ +void settings_set(const char *path, struct setting_value value); + +/** + * Set a value for a setting. + * + * @param setting Pointer to a setting to set. + * @param value The new value of the setting. The type has to match the declared + * type for the setting. If not, the new value is ignored. + */ +void setting_set_value(struct setting *setting, struct setting_value val); + +/** + * Create a string representation for a setting. + * + * @param setting Pointer to a setting to turn into a string. + * @param buf Character buffer to store resulting string in. + * @param n Size in bytes of @ref buf. + */ +void setting_to_string(struct setting *setting, char *buf, size_t n); -- cgit v1.2.3