![]() |
dwm-libconfig 6.8
Runtime configuration parsing for dwm using libconfig.
|
#include <errno.h>#include <libconfig.h>#include <libgen.h>#include <stdbool.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <strings.h>#include <sys/stat.h>#include <X11/X.h>#include <X11/Xlib.h>#include <X11/Xutil.h>Runtime configuration parser using libconfig.
This file replaces the need to edit config.h or config.def.h and recompile to make changes to dwm's configuration by parsing a configuration file (see example dwm.conf) at runtime. That configuration file contains all the configuration values traditionally found in config.h or config.def.h, and can be edited at any time without the need to change dwm's source code, allowing you to install dwm once and configure it any time you wish without the source code. For more information, please see the patch's GitHub page: https://github.com/JeffofBread/dwm-libconfig.
Finish documentation. Make sure function arguments are noted for being dynamically allocated in that function or its sub functions.
Overhaul printing / logging to match the new error handling.
Try and reduce the number of unique string literals throughout the parser. Tons are used for logging, inflating binary size by 8kb.
Data Structures | |
| struct | Button_Alias_Map_t |
| Struct to map a string alias to a matching X11 button. More... | |
| struct | Click_Alias_Map_t |
| Struct to map a string alias to a matching click enum. More... | |
| struct | Errors_t |
| Struct containing a count of accumulated Error_t. More... | |
| struct | Function_Alias_Map_t |
| Struct to map a string alias to a matching function pointer, its argument data type, and that argument's acceptable range. More... | |
| struct | Modifier_Alias_Map_t |
| Struct to map a string alias to a matching X11 modifier. More... | |
| struct | Setting_Alias_Map_t |
| Struct to map a string alias to a matching setting pointer, its optional status, argument data type, and that argument's acceptable range. More... | |
| struct | Theme_Alias_Map_t |
| Struct to map a string alias to a matching color string pointer. More... | |
Macros | |
| #define | _LOG(LEVEL, ...) |
| Log a categorized message. | |
| #define | LOG_TRACE(...) |
| Log a trace message. | |
| #define | LOG_DEBUG(...) |
| Log a debug message. | |
| #define | LOG_INFO(...) |
| Log an informational message. | |
| #define | LOG_WARN(...) |
| Log a warning message. | |
| #define | LOG_ERROR(...) |
| Log an error message. | |
| #define | LOG_FATAL(...) |
| Log a fatal issue message. | |
| #define | RETURN_ERRORS_IF_NULL(check, errors, ...) |
| Return function with Errors_t struct if variable is NULL. | |
| #define | RETURN_VALUE_IF_NULL(check, value, ...) |
| Return function with a given value if variable is NULL. | |
| #define | RETURN_IF_NULL(check, ...) |
| Return function if variable is NULL. | |
| #define | SET_STATUS_TEXT(...) |
| Macro to easily set status text before first bar draw. | |
Typedefs | |
| typedef Errors_t(* | Array_Element_Parser_Function_t) (config_setting_t *element_setting, unsigned int element_index, void *parsed_element) |
| Typedef used to abstract config array parsing functions. Allows for more generic parsing of multiple types. | |
Enumerations | |
| enum | Data_Type_t { TYPE_NONE , TYPE_BOOLEAN , TYPE_INT , TYPE_UINT , TYPE_FLOAT , TYPE_STRING } |
| Enum used to keep track of what kind of data is to be stored in an Arg struct. More... | |
| enum | Error_t { ERROR_NONE , ERROR_NOT_FOUND , ERROR_TYPE , ERROR_RANGE , ERROR_NULL_VALUE , ERROR_ALLOCATION , ERROR_IO , ERROR_ENUM_LENGTH } |
| Enum to categorize the types of errors that can occur during parsing. More... | |
Functions | |
| void | config_cleanup (void) |
| Frees dynamically allocated parser data. | |
| Errors_t | parse_config (void) |
| Parse program configuration from a configuration file. | |
| void | add_error (Errors_t *errors, const Error_t error) |
| Adds an error to an Errors_t struct. | |
| void | copy_errors (Errors_t *destination, const Errors_t source) |
Copy errors from source to destination. | |
| int | errors_failure_count (const Errors_t *errors) |
| Counts the number of failure errors present in an Errors_t struct. | |
| char * | estrdup (const char *string) |
| Simple wrapper around strdup() to provide error logging. | |
| void | extend_string (char **source_string, const char *addition) |
| Extend one string with another. | |
| const Layout * | get_layout (void(*arrange)(Monitor *)) |
| Find and return a layout that uses a specific arrange function. | |
| char * | get_xdg_config_home (void) |
| Get the user's XDG configuration directory path. | |
| char * | get_xdg_data_home (void) |
| Get the user's XDG data directory path. | |
| char * | join_strings (const char *string_1, const char *string_2) |
| Join two strings into one. | |
| int | make_directory_path (const char *path) |
| Creates all directories in a given path if they don't exist. | |
| int | normalize_path (const char *original_path, char **normalized_path) |
| Normalize a file or folder path to remove repeat forward slash characters. | |
| void | setlayout_floating (const Arg *arg) |
| Set current layout to floating. | |
| void | setlayout_monocle (const Arg *arg) |
| Set current layout to monocle. | |
| void | setlayout_tiled (const Arg *arg) |
| Set current layout to tile. | |
| void | spawn_string (const Arg *arg) |
| Wrapper around spawn() for simpler program spawning. | |
| static Error_t | _parser_backup_config (config_t *config) |
| Backs up a libconfig configuration to disk. | |
| static Error_t | _parse_bind_argument (config_setting_t *setting, const Data_Type_t argument_type, const long double range_min, const long double range_max, Arg *argument) |
| TODO. | |
| static Errors_t | _parse_bind_core (config_setting_t *setting, const unsigned int bind_index, unsigned int *modifier, void(**function)(const Arg *), Arg *argument) |
| TODO. | |
| static Error_t | _parse_bind_function (config_setting_t *setting, void(**function)(const Arg *), Data_Type_t *argument_type, long double *range_min, long double *range_max) |
| TODO. | |
| static Error_t | _parse_bind_modifier (config_setting_t *setting, unsigned int *modifier) |
| TODO. | |
| static Errors_t | _parse_buttonbind (config_setting_t *setting, const unsigned int index, Button *buttonbind) |
| TODO. | |
| static Errors_t | _parse_buttonbind_adapter (config_setting_t *setting, const unsigned int index, void *buttonbind) |
| Thin adapter function to allow for buttonbind parsing inside a generic array parsing function. | |
| static Error_t | _parse_buttonbind_button (config_setting_t *setting, unsigned int *button) |
| TODO. | |
| static Error_t | _parse_buttonbind_click (config_setting_t *setting, unsigned int *click) |
| TODO. | |
| static Errors_t | _parse_buttonbinds_config (const config_t *config, Button **array, unsigned int *count, bool *malloced) |
| Parse a list of buttonbinds from a libconfig configuration into a list of Button structs. | |
| static Errors_t | _parse_font (config_setting_t *setting, const unsigned int index, const char **font) |
| TODO. | |
| static Errors_t | _parse_font_adapter (config_setting_t *setting, const unsigned int index, void *font) |
| Thin adapter function to allow for font parsing inside a generic array parsing function. | |
| static Errors_t | _parse_generic_settings (const config_t *config) |
| Parse generic configuration settings from a libconfig configuration. | |
| static Errors_t | _parse_keybind (config_setting_t *setting, const unsigned int index, Key *keybind) |
| TODO. | |
| static Errors_t | _parse_keybind_adapter (config_setting_t *setting, const unsigned int index, void *keybind) |
| Thin adapter function to allow for keybind parsing inside a generic array parsing function. | |
| static Error_t | _parse_keybind_keysym (config_setting_t *setting, KeySym *keysym) |
| TODO. | |
| static Errors_t | _parse_keybinds_config (const config_t *config, Key **array, unsigned int *count, bool *malloced) |
| Parse a list of keybinds from a libconfig configuration into a list of Key structs. | |
| static Errors_t | _parser_open_config_file (config_t *config, const char *custom_config_filepath, char **found_config_filepath, bool *fallback_config_loaded) |
| Attempts to find, open, and store a valid libconfig configuration file. | |
| static Errors_t | _parse_rule (config_setting_t *setting, const unsigned int index, Rule *rule) |
| Parse a rule from a libconfig configuration setting. | |
| static Errors_t | _parse_rule_adapter (config_setting_t *setting, const unsigned int index, void *rule) |
| Thin adapter function to allow for rule parsing inside a generic array parsing function. | |
| static Errors_t | _parse_rules_config (const config_t *config, Rule **array, unsigned int *count, bool *malloced) |
| Parse a list of rules from a libconfig configuration into a list of Rule structs. | |
| static Errors_t | _parse_setting_array (const config_setting_t *setting, const size_t element_size, const Array_Element_Parser_Function_t array_element_parser_function, bool *malloced, void **parsed_config, unsigned int *parsed_config_length) |
| TODO. | |
| static Errors_t | _parse_tag (config_setting_t *setting, const unsigned int index) |
| TODO. | |
| static Errors_t | _parse_tags_adapter (config_setting_t *setting, const unsigned int index, void *unused) |
| Thin adapter function to allow for tag parsing inside a generic array parsing function. | |
| static Errors_t | _parse_tags_config (const config_t *config) |
| Parse a list of tags from a libconfig configuration. | |
| static Errors_t | _parse_theme (config_setting_t *setting, const unsigned int index) |
| Parse a theme from a libconfig configuration setting. | |
| static Errors_t | _parse_theme_adapter (config_setting_t *setting, const unsigned int index, void *unused) |
| Thin adapter function to allow for theme parsing inside a generic array parsing function. | |
| static Errors_t | _parse_theme_config (const config_t *config) |
| Parse a list of themes from a libconfig configuration. | |
| static Error_t | _libconfig_generic_lookup (config_setting_t *parent_setting, const char *path, const int expected_type, void *parsed_value) |
| TODO. | |
| static Error_t | _libconfig_get_setting_name (const config_setting_t *setting, const char **found_name) |
| Returns the name of a given setting, or its nearest named parent setting. | |
| static Error_t | _libconfig_lookup_float (config_setting_t *parent_setting, const char *path, const float range_min, const float range_max, float *parsed_value) |
| Look up a float value in a libconfig setting. | |
| static Error_t | _libconfig_lookup_int (config_setting_t *parent_setting, const char *path, const int range_min, const int range_max, int *parsed_value) |
| Look up an integer value in a libconfig setting. | |
| static Error_t | _libconfig_lookup_string (config_setting_t *parent_setting, const char *path, const char **parsed_value) |
| Look up a string value in a libconfig setting. | |
| static Error_t | _libconfig_lookup_uint (config_setting_t *parent_setting, const char *path, const unsigned int range_min, const unsigned int range_max, unsigned int *parsed_value) |
| Look up an unsigned integer value in a libconfig setting. | |
Variables | |
| config_t | libconfig_config |
| Master libconfig configuration context used for parsing. | |
| char * | config_filepath |
| Path to the currently loaded configuration's file. | |
| Key * | keys |
| Array of current keybinds. | |
| Button * | buttons |
| Array of current buttons. | |
| Rule * | rules |
| Array of current rules. | |
| const char ** | fonts |
| Array of current fonts. | |
| unsigned int | keys_count |
| Number of elements in keys. | |
| unsigned int | buttons_count |
| Number of elements in buttons. | |
| unsigned int | rules_count |
| Number of elements in rules. | |
| unsigned int | fonts_count |
| Number of elements in fonts_count. | |
| bool | keys_malloced |
| Boolean tracking whether keys has been dynamically allocated. | |
| bool | buttons_malloced |
| Boolean tracking whether buttons has been dynamically allocated. | |
| bool | rules_malloced |
| Boolean tracking whether rules has been dynamically allocated. | |
| bool | fonts_malloced |
| Boolean tracking whether fonts has been dynamically allocated. | |
| static const char * | _parser_filepath |
| Parser filepath string. | |
| const char * | ERROR_ENUM_STRINGS [] |
| String name pairs to Error_t. | |
| const char * | FAILED_ALLOC_PRINT_STRING |
| Common string used for logging memory allocation issues. | |
| const char * | POINTER_NULL_PRINT_STRING |
| Common string used for logging NULL pointers. | |
| static const Click_Alias_Map_t | CLICK_ALIAS_MAP [] |
| Default alias map for dwm's click enum. | |
| static const Button_Alias_Map_t | BUTTON_ALIAS_MAP [] |
| Default alias map for common X11 buttons. | |
| static const Function_Alias_Map_t | FUNCTION_ALIAS_MAP [] |
| Default alias map for dwm's arg functions. | |
| static const Modifier_Alias_Map_t | MODIFIER_ALIAS_MAP [] |
| Default alias map for common X11 modifiers. | |
| static const Setting_Alias_Map_t | SETTING_ALIAS_MAP [] |
| Default alias map for dwm's global config settings. | |
| static const Theme_Alias_Map_t | THEME_ALIAS_MAP [] |
| Default alias map for dwm's scheme indexes. | |
| #define _LOG | ( | LEVEL, | |
| ... ) |
Log a categorized message.
Logging is more or less intended to be enabled/disabled by uncommenting/commenting individual logging level's macro bodies. I would prefer a proper logging system, but that seems out the scope of this patch, and this works good enough for the patch's needs.
Also, if you would like to include function names in the log, you can use __func__:
| [in] | LEVEL | Log level string literal. |
| #define RETURN_ERRORS_IF_NULL | ( | check, | |
| errors, | |||
| ... ) |
Return function with Errors_t struct if variable is NULL.
| [in] | check | Variable to be checked for NULL. |
| [in,out] | errors | Errors_t struct to be returned with an ERROR_NULL_VALUE error if check is NULL. |
| [in] | ... | Format and message to be given to LOG_ERROR() to be logged. |
Referenced by _parse_bind_core(), _parse_buttonbind(), _parse_buttonbinds_config(), _parse_font(), _parse_generic_settings(), _parse_keybind(), _parse_keybinds_config(), _parse_rule(), _parse_rules_config(), _parse_setting_array(), _parse_tag(), _parse_tags_config(), _parse_theme(), _parse_theme_config(), and _parser_open_config_file().
| #define RETURN_IF_NULL | ( | check, | |
| ... ) |
Return function if variable is NULL.
| [in] | check | Variable to be checked for NULL. |
| [in] | ... | Format and message to be given to LOG_ERROR() to be logged. |
Referenced by add_error(), copy_errors(), extend_string(), setlayout_floating(), setlayout_monocle(), setlayout_tiled(), and spawn_string().
| #define RETURN_VALUE_IF_NULL | ( | check, | |
| value, | |||
| ... ) |
Return function with a given value if variable is NULL.
| [in] | check | Variable to be checked for NULL. |
| [in] | value | Value to be returned if check is NULL. |
| [in] | ... | Format and message to be given to LOG_ERROR() to be logged. |
Referenced by _parse_bind_argument(), _parse_bind_function(), _parse_bind_modifier(), _parse_buttonbind_button(), _parse_buttonbind_click(), _parse_keybind_keysym(), _parser_backup_config(), errors_failure_count(), estrdup(), get_xdg_config_home(), get_xdg_data_home(), join_strings(), make_directory_path(), and normalize_path().
| #define SET_STATUS_TEXT | ( | ... | ) |
Macro to easily set status text before first bar draw.
| [in] | ... | Format and variables to be printed to the status text. |
Referenced by parse_config().
| enum Data_Type_t |
Enum used to keep track of what kind of data is to be stored in an Arg struct.
| Enumerator | |
|---|---|
| TYPE_NONE | No data stored/required. |
| TYPE_BOOLEAN | Boolean data. |
| TYPE_INT | Integer data. |
| TYPE_UINT | Unsigned Integer data. |
| TYPE_FLOAT | Float data. |
| TYPE_STRING | String data. |
| enum Error_t |
Enum to categorize the types of errors that can occur during parsing.
|
static |
TODO.
TODO
| [in] | parent_setting | TODO |
| [in] | path | TODO |
| [in] | expected_type | TODO |
| [out] | parsed_value | TODO |
path does not match expected_type or if there is an unexpected type in the switch case. References ERROR_NONE, ERROR_NOT_FOUND, ERROR_NULL_VALUE, and ERROR_TYPE.
Referenced by _libconfig_lookup_float(), _libconfig_lookup_int(), _libconfig_lookup_string(), _libconfig_lookup_uint(), _parse_bind_argument(), _parse_buttonbinds_config(), _parse_generic_settings(), _parse_keybinds_config(), _parse_rules_config(), _parse_tags_config(), _parse_theme(), and _parse_theme_config().
|
static |
Returns the name of a given setting, or its nearest named parent setting.
TODO
| [in] | setting | TODO |
| [out] | found_name | TODO |
References ERROR_NONE, ERROR_NOT_FOUND, and ERROR_NULL_VALUE.
Referenced by _parse_bind_core(), and _parse_setting_array().
|
static |
Look up a float value in a libconfig setting.
TODO
| [in] | parent_setting | Pointer to the libconfig setting to perform the lookup in. |
| [in] | path | Path expression to search within parent_setting. |
| [in] | range_min | Minimum value that can be saved to parsed_value. |
| [in] | range_max | Maximum value that can be saved to parsed_value. |
| [out] | parsed_value | Pointer to where the parsed value will be stored on success. |
range_min exceeds range_max or if the parsed value at path is outside the provided range. References _libconfig_generic_lookup(), ERROR_NONE, ERROR_NULL_VALUE, and ERROR_RANGE.
Referenced by _parse_bind_argument(), and _parse_generic_settings().
|
static |
Look up an integer value in a libconfig setting.
TODO
| [in] | parent_setting | Pointer to the libconfig setting to perform the lookup in. |
| [in] | path | Path expression to search within parent_setting. |
| [in] | range_min | Minimum value that can be saved to parsed_value. |
| [in] | range_max | Maximum value that can be saved to parsed_value. |
| [out] | parsed_value | Pointer to where the parsed value will be stored on success. |
range_min exceeds range_max or if the parsed value at path is outside the provided range. References _libconfig_generic_lookup(), ERROR_NONE, ERROR_NULL_VALUE, and ERROR_RANGE.
Referenced by _parse_bind_argument(), _parse_generic_settings(), and _parse_rule().
|
static |
Look up a string value in a libconfig setting.
TODO
| [in] | parent_setting | Pointer to the libconfig setting to perform the lookup in. |
| [in] | path | Path expression to search within parent_setting. |
| [out] | parsed_value | Pointer to where the parsed value will be stored on success. |
References _libconfig_generic_lookup(), ERROR_NONE, and ERROR_NULL_VALUE.
Referenced by _parse_bind_argument(), _parse_bind_function(), _parse_bind_modifier(), _parse_buttonbind_button(), _parse_buttonbind_click(), _parse_generic_settings(), _parse_keybind_keysym(), _parse_rule(), and _parse_theme().
|
static |
Look up an unsigned integer value in a libconfig setting.
TODO
| [in] | parent_setting | Pointer to the libconfig setting to perform the lookup in. |
| [in] | path | Path expression to search within parent_setting. |
| [in] | range_min | Minimum value that can be saved to parsed_value. |
| [in] | range_max | Maximum value that can be saved to parsed_value. |
| [out] | parsed_value | Pointer to where the parsed value will be stored on success. |
range_min exceeds range_max or if the parsed value at path is less than zero or outside the provided range. References _libconfig_generic_lookup(), ERROR_NONE, ERROR_NULL_VALUE, and ERROR_RANGE.
Referenced by _parse_bind_argument(), _parse_generic_settings(), and _parse_rule().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [in] | argument_type | Enum describing the type of data stored in parsed_argument. |
| [in] | range_min | Minimum value parsed_argument can have. Only applies to numerical types. |
| [in] | range_max | Maximum value parsed_argument can have. Only applies to numerical types. |
| [out] | argument | Pointer to an Arg struct where the parsed value of type argument_type in range range_min to range_max will be stored. |
argument_type does not match any case in the switch statement. References _libconfig_generic_lookup(), _libconfig_lookup_float(), _libconfig_lookup_int(), _libconfig_lookup_string(), _libconfig_lookup_uint(), ERROR_NONE, ERROR_NULL_VALUE, ERROR_TYPE, LOG_WARN, POINTER_NULL_PRINT_STRING, RETURN_VALUE_IF_NULL, TYPE_BOOLEAN, TYPE_FLOAT, TYPE_INT, TYPE_NONE, TYPE_STRING, and TYPE_UINT.
Referenced by _parse_bind_core().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [in] | bind_index | TODO |
| [out] | modifier | TODO |
| [out] | function | TODO |
| [out] | argument | TODO |
References _libconfig_get_setting_name(), _parse_bind_argument(), _parse_bind_function(), _parse_bind_modifier(), add_error(), ERROR_ENUM_STRINGS, ERROR_NONE, LOG_WARN, POINTER_NULL_PRINT_STRING, RETURN_ERRORS_IF_NULL, and TYPE_NONE.
Referenced by _parse_buttonbind(), and _parse_keybind().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [out] | function | TODO |
| [out] | argument_type | Pointer to where to store the data type of the Arg that can be passed to function. |
| [out] | range_min | Pointer to where to store the minimum value of the Arg that can be passed to function. |
| [out] | range_max | Pointer to where to store the maximum value of the Arg that can be passed to function. |
References _libconfig_lookup_string(), ERROR_NONE, ERROR_NOT_FOUND, ERROR_NULL_VALUE, FUNCTION_ALIAS_MAP, POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by _parse_bind_core().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [out] | modifier | TODO |
References _libconfig_lookup_string(), ERROR_ALLOCATION, ERROR_NONE, ERROR_NOT_FOUND, ERROR_NULL_VALUE, estrdup(), LOG_WARN, MODIFIER_ALIAS_MAP, POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by _parse_bind_core().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [in] | index | TODO |
| [out] | buttonbind | TODO |
References _parse_bind_core(), _parse_buttonbind_button(), _parse_buttonbind_click(), add_error(), copy_errors(), ERROR_ENUM_STRINGS, ERROR_NONE, errors_failure_count(), LOG_WARN, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by _parse_buttonbind_adapter().
|
static |
Thin adapter function to allow for buttonbind parsing inside a generic array parsing function.
See _parse_buttonbind() for function documentation.
References _parse_buttonbind().
Referenced by _parse_buttonbinds_config().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [out] | button | TODO |
References _libconfig_lookup_string(), BUTTON_ALIAS_MAP, ERROR_NONE, ERROR_NULL_VALUE, ERROR_RANGE, POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by _parse_buttonbind().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [out] | click | TODO |
References _libconfig_lookup_string(), CLICK_ALIAS_MAP, ERROR_NONE, ERROR_NOT_FOUND, ERROR_NULL_VALUE, POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by _parse_buttonbind().
|
static |
Parse a list of buttonbinds from a libconfig configuration into a list of Button structs.
TODO
| [in] | config | Pointer to the libconfig configuration containing the buttonbinds to be parsed into array. |
| [out] | array | Pointer to where to dynamically allocate and store all the parsed buttonbinds. |
| [out] | count | Pointer to where to store the number of buttonbinds to be parsed. This value does not take into account any failures during parsing the buttonbinds. |
| [out] | malloced | Boolean to track if array has been dynamically allocated yet or not, analogous to if the default buttonbinds are being used or not. Value is set to false after allocation. |
References _libconfig_generic_lookup(), _parse_buttonbind_adapter(), _parse_setting_array(), add_error(), copy_errors(), ERROR_ENUM_STRINGS, ERROR_NONE, LOG_ERROR, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by parse_config().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [in] | index | TODO |
| [out] | font | TODO |
References add_error(), ERROR_NULL_VALUE, ERROR_TYPE, LOG_WARN, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by _parse_font_adapter().
|
static |
Thin adapter function to allow for font parsing inside a generic array parsing function.
See _parse_font() for function documentation.
References _parse_font().
Referenced by _parse_theme().
|
static |
Parse generic configuration settings from a libconfig configuration.
TODO
| [in] | config | Pointer to the libconfig configuration containing the generic settings to be parsed. |
References _libconfig_generic_lookup(), _libconfig_lookup_float(), _libconfig_lookup_int(), _libconfig_lookup_string(), _libconfig_lookup_uint(), add_error(), ERROR_ENUM_STRINGS, ERROR_NONE, ERROR_NOT_FOUND, ERROR_TYPE, LOG_DEBUG, LOG_WARN, POINTER_NULL_PRINT_STRING, RETURN_ERRORS_IF_NULL, SETTING_ALIAS_MAP, TYPE_BOOLEAN, TYPE_FLOAT, TYPE_INT, TYPE_STRING, and TYPE_UINT.
Referenced by parse_config().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [in] | index | TODO |
| [out] | keybind | TODO |
References _parse_bind_core(), _parse_keybind_keysym(), add_error(), copy_errors(), ERROR_ENUM_STRINGS, ERROR_NONE, errors_failure_count(), LOG_WARN, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by _parse_keybind_adapter().
|
static |
Thin adapter function to allow for keybind parsing inside a generic array parsing function.
See _parse_keybind() for function documentation.
References _parse_keybind().
Referenced by _parse_keybinds_config().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [out] | keysym | Pointer to where to store the parsed keysym value. |
References _libconfig_lookup_string(), ERROR_NONE, ERROR_NOT_FOUND, ERROR_NULL_VALUE, LOG_WARN, POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by _parse_keybind().
|
static |
Parse a list of keybinds from a libconfig configuration into a list of Key structs.
TODO
| [in] | config | Pointer to the libconfig configuration containing the keybinds to be parsed into array. |
| [out] | array | Pointer to where to dynamically allocate memory and store all the parsed keybinds. |
| [out] | count | Pointer to where to store the number of keybinds to be parsed. This value does not take into account any failures during parsing the keybinds. |
| [out] | malloced | Boolean to track if array has been dynamically allocated yet or not, analogous to if the default keybinds are being used or not. Value is set to false after allocation. |
References _libconfig_generic_lookup(), _parse_keybind_adapter(), _parse_setting_array(), add_error(), copy_errors(), ERROR_ENUM_STRINGS, ERROR_NONE, LOG_ERROR, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by parse_config().
|
static |
Parse a rule from a libconfig configuration setting.
TODO
| [in] | setting | Pointer to the libconfig setting containing the rule to be parsed into rule. |
| [in] | index | Index of the current rule in the larger array. Used purely for debug printing. |
| [out] | rule | Pointer to the Rule struct where the values parsed from setting are stored. |
References _libconfig_lookup_int(), _libconfig_lookup_string(), _libconfig_lookup_uint(), add_error(), errors_failure_count(), LOG_DEBUG, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by _parse_rule_adapter().
|
static |
Thin adapter function to allow for rule parsing inside a generic array parsing function.
See _parse_rule() for function documentation.
References _parse_rule().
Referenced by _parse_rules_config().
|
static |
Parse a list of rules from a libconfig configuration into a list of Rule structs.
TODO
| [in] | config | Pointer to the libconfig configuration containing the rules to be parsed into array. |
| [out] | array | Pointer to where to dynamically allocate memory and store all the parsed rules. |
| [out] | count | Pointer to where to store the number of rules to be parsed. This value does not take into account any failures during parsing the rules. |
| [out] | malloced | Boolean to track if array has been dynamically allocated yet or not, analogous to if the default rules are being used or not. Value is set to false after allocation. |
References _libconfig_generic_lookup(), _parse_rule_adapter(), _parse_setting_array(), add_error(), copy_errors(), ERROR_ENUM_STRINGS, ERROR_NONE, LOG_ERROR, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by parse_config().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [in] | element_size | TODO |
| [in] | array_element_parser_function | TODO |
| [in,out] | malloced | TODO |
| [in,out] | parsed_config | TODO |
| [out] | parsed_config_length | TODO |
malloced and null checking parsed_config before allocation is brittle, needs work. References _libconfig_get_setting_name(), add_error(), copy_errors(), ERROR_ALLOCATION, ERROR_ENUM_STRINGS, ERROR_NONE, ERROR_NOT_FOUND, ERROR_RANGE, errors_failure_count(), LOG_DEBUG, LOG_ERROR, LOG_WARN, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by _parse_buttonbinds_config(), _parse_keybinds_config(), _parse_rules_config(), _parse_tags_config(), _parse_theme(), and _parse_theme_config().
|
static |
TODO.
TODO
| [in] | setting | TODO |
| [out] | index | TODO |
References add_error(), ERROR_NULL_VALUE, ERROR_RANGE, ERROR_TYPE, LOG_WARN, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by _parse_tags_adapter().
|
static |
Thin adapter function to allow for tag parsing inside a generic array parsing function.
See _parse_tag() for function documentation.
References _parse_tag().
Referenced by _parse_tags_config().
|
static |
Parse a list of tags from a libconfig configuration.
TODO
| [in] | config | Pointer to the libconfig configuration containing the tags to be parsed. |
References _libconfig_generic_lookup(), _parse_setting_array(), _parse_tags_adapter(), add_error(), copy_errors(), ERROR_ENUM_STRINGS, ERROR_NONE, LOG_ERROR, LOG_WARN, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by parse_config().
|
static |
Parse a theme from a libconfig configuration setting.
TODO
| [in] | setting | Pointer to the libconfig setting containing the theme to be parsed. |
| [in] | index | Index of the current theme being parsed. |
References _libconfig_generic_lookup(), _libconfig_lookup_string(), _parse_font_adapter(), _parse_setting_array(), add_error(), copy_errors(), ERROR_ENUM_STRINGS, ERROR_NONE, ERROR_RANGE, fonts, fonts_count, fonts_malloced, LOG_ERROR, LOG_WARN, POINTER_NULL_PRINT_STRING, RETURN_ERRORS_IF_NULL, and THEME_ALIAS_MAP.
Referenced by _parse_theme_adapter().
|
static |
Thin adapter function to allow for theme parsing inside a generic array parsing function.
See _parse_theme() for function documentation.
References _parse_theme().
Referenced by _parse_theme_config().
|
static |
Parse a list of themes from a libconfig configuration.
TODO
| [in] | config | Pointer to the libconfig configuration containing the theme to be parsed. |
References _libconfig_generic_lookup(), _parse_setting_array(), _parse_theme_adapter(), add_error(), copy_errors(), ERROR_ENUM_STRINGS, ERROR_NONE, LOG_ERROR, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by parse_config().
|
static |
Backs up a libconfig configuration to disk.
This function backs up the given libconfig config_t, config, following the XDG specification. If the function get_xdg_data_home() fails to find the XDG data directory (which is likely), we will default to using "~/.local/share/" instead. Meaning that, in the latter case, the filepath to the backup file will be "~/.local/share/dwm/dwm_last.conf". "/dwm/dwm_last.conf" will always be appended to the end of whatever path is returned by get_xdg_data_home(). The backup file is then created and written to by libconfig's config_write_file().
| [in] | config | Pointer to the libconfig configuration to be backed up. |
config to a file. References ERROR_ALLOCATION, ERROR_IO, ERROR_NONE, ERROR_NOT_FOUND, ERROR_NULL_VALUE, extend_string(), FAILED_ALLOC_PRINT_STRING, get_xdg_data_home(), LOG_ERROR, LOG_INFO, make_directory_path(), POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by parse_config().
|
static |
Attempts to find, open, and store a valid libconfig configuration file.
This function handles most of the high level logic regarding finding, opening, validating, and storing a libconfig configuration file. This function will first search for a custom configuration file, passed in using config_filepath. If that is not found, a list of default directories are searched. If still no user configuration is found, a user's last configuration backup will be attempted to be loaded. If again unsuccessful, a system default configuration file will be loaded. Finally, if all else fails, the function will return and the program will rely on the hardcoded default values loaded from config.h
| [in] | config | TODO |
| [in] | custom_config_filepath | TODO |
| [out] | found_config_filepath | TODO |
| [out] | fallback_config_loaded | TODO |
These error returns may not be the most accurate, not sure exactly the best fits.
Should the parser even look for another config file if one is passed from the CLI? Could be deceptive behavior.
References add_error(), ERROR_ALLOCATION, ERROR_NULL_VALUE, estrdup(), get_xdg_config_home(), get_xdg_data_home(), LOG_DEBUG, LOG_WARN, POINTER_NULL_PRINT_STRING, and RETURN_ERRORS_IF_NULL.
Referenced by parse_config().
Adds an error to an Errors_t struct.
This function acts as a simple way to increment the error count of an Errors_t struct at the correct error index.
| [out] | errors | Pointer to an Errors_t struct to add error to. |
| [in] | error | Error to be added to the error count in errors. |
References ERROR_ENUM_LENGTH, Errors_t::errors_count, POINTER_NULL_PRINT_STRING, and RETURN_IF_NULL.
Referenced by _parse_bind_core(), _parse_buttonbind(), _parse_buttonbinds_config(), _parse_font(), _parse_generic_settings(), _parse_keybind(), _parse_keybinds_config(), _parse_rule(), _parse_rules_config(), _parse_setting_array(), _parse_tag(), _parse_tags_config(), _parse_theme(), _parse_theme_config(), _parser_open_config_file(), and parse_config().
| void config_cleanup | ( | void | ) |
Frees dynamically allocated parser data.
Frees all dynamically allocated data allocated during the parsing process. Intended for use before program exit and after parse_config().
References buttons, buttons_malloced, config_filepath, fonts, fonts_malloced, keys, keys_malloced, libconfig_config, rules, and rules_malloced.
Copy errors from source to destination.
This function copies the errors in source to the Errors_t struct pointed to by destination. It does not alter the errors in source. If the pointer to destination is NULL, an error will be logged and the function will return.
| [out] | destination | Pointer to where to copy errors to. |
| [in] | source | Errors to copy. |
References ERROR_ENUM_LENGTH, Errors_t::errors_count, POINTER_NULL_PRINT_STRING, and RETURN_IF_NULL.
Referenced by _parse_buttonbind(), _parse_buttonbinds_config(), _parse_keybind(), _parse_keybinds_config(), _parse_rules_config(), _parse_setting_array(), _parse_tags_config(), _parse_theme(), _parse_theme_config(), and parse_config().
| int errors_failure_count | ( | const Errors_t * | errors | ) |
Counts the number of failure errors present in an Errors_t struct.
This function acts as a simple way to count the number of failure errors present in an Errors_t struct.
| [in] | errors | Pointer to an Errors_t struct to count errors from. |
errors is NULL, else the total of the number of failure errors present in errors. References ERROR_ENUM_LENGTH, ERROR_NONE, Errors_t::errors_count, POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by _parse_buttonbind(), _parse_keybind(), _parse_rule(), _parse_setting_array(), and parse_config().
| char * estrdup | ( | const char * | string | ) |
Simple wrapper around strdup() to provide error logging.
This function acts as a simple wrapper around strdup() that provides some NULL safety as well as error logging around strdup(). It can be used as a drop in replacement for strdup() safely.
| [in] | string | String to be copied. |
string was NULL, or the pointer to a dynamically allocated duplicate of string.References FAILED_ALLOC_PRINT_STRING, POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by _parse_bind_modifier(), _parser_open_config_file(), extend_string(), get_xdg_config_home(), and get_xdg_data_home().
| void extend_string | ( | char ** | source_string, |
| const char * | addition ) |
Extend one string with another.
This function reallocates and extends the string pointed to by source_string with the string addition. If either the pointer to source_string or addition are NULL, the function will log an error and return. If the string at source_string is NULL, addition will be copied into it's place using dynamic allocation. If all succeeds, then the string pointed to by source_string will be dynamically reallocated to contain both the source string and addition, and will need to be freed manually.
| [in,out] | source_string | Pointer to the string to be extended with addition. Must point to a NULL or heap allocated string. |
| [in] | addition | Additional string to be appended to the string pointed to by source_string. |
source_string must be NULL or heap allocated. If it points to a string literal, realloc() will crash the program. See join_strings() if you wish to append a string literal.source_string is or will be dynamically allocated and must be manually freed.References estrdup(), FAILED_ALLOC_PRINT_STRING, LOG_DEBUG, POINTER_NULL_PRINT_STRING, and RETURN_IF_NULL.
Referenced by _parser_backup_config().
| const Layout * get_layout | ( | void(* | arrange )(Monitor *) | ) |
Find and return a layout that uses a specific arrange function.
This function searches the global array layouts for a layout struct that contains arrange. If it is found, a pointer to it is returned, else NULL is returned.
| [in] | arrange | Arrange function used by the layout to be found and returned. |
arrange was found.Referenced by setlayout_floating(), setlayout_monocle(), and setlayout_tiled().
| char * get_xdg_config_home | ( | void | ) |
Get the user's XDG configuration directory path.
TODO
References estrdup(), join_strings(), LOG_DEBUG, and RETURN_VALUE_IF_NULL.
Referenced by _parser_open_config_file().
| char * get_xdg_data_home | ( | void | ) |
Get the user's XDG data directory path.
TODO
References estrdup(), join_strings(), LOG_DEBUG, and RETURN_VALUE_IF_NULL.
Referenced by _parser_backup_config(), and _parser_open_config_file().
| char * join_strings | ( | const char * | string_1, |
| const char * | string_2 ) |
Join two strings into one.
TODO
| [in] | string_1 | String for string_2 to be appended to. |
| [in] | string_2 | String to be appended to string_1. |
string_1, however. strncpy( joined_string + length_1, string_2, length_2 ) uses bounds depending on the source argument, but joined_string is allocated with length_1 + length_2 + 1, so this strncpy() can't overflow.References FAILED_ALLOC_PRINT_STRING, POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by get_xdg_config_home(), and get_xdg_data_home().
| int make_directory_path | ( | const char * | path | ) |
Creates all directories in a given path if they don't exist.
TODO
| [in] | path | String containing the directory path to attempt to create. |
References LOG_DEBUG, LOG_ERROR, normalize_path(), POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by _parser_backup_config().
| int normalize_path | ( | const char * | original_path, |
| char ** | normalized_path ) |
Normalize a file or folder path to remove repeat forward slash characters.
TODO
| [in] | original_path | String containing the path to be normalized. |
| [out] | normalized_path | Pointer to where to store the normalized path. It is dynamically allocated and will need to be manually freed. |
References FAILED_ALLOC_PRINT_STRING, POINTER_NULL_PRINT_STRING, and RETURN_VALUE_IF_NULL.
Referenced by make_directory_path().
| Errors_t parse_config | ( | void | ) |
Parse program configuration from a configuration file.
This function serves as the entry point into the configuration parser of the dwm-libconfig patch. This function serves as a high level entry to the configuration parser. It largely calls helper functions to handle the actual parsing of the configuration file in various segmented and modular steps.
For more information on the specific details on what actions the parser performs, please reference the helper function related to the functionality you want to learn more about, they all have their own documentation and comments.
Polish the status texts a little. I like the idea but could be refined.
Backup config file logic is clumsily structured, it should be improved. It also probably should include rules_malloced
References _parse_buttonbinds_config(), _parse_generic_settings(), _parse_keybinds_config(), _parse_rules_config(), _parse_tags_config(), _parse_theme_config(), _parser_backup_config(), _parser_open_config_file(), add_error(), buttons, buttons_count, buttons_malloced, config_filepath, copy_errors(), errors_failure_count(), keys, keys_count, keys_malloced, libconfig_config, LOG_DEBUG, LOG_ERROR, LOG_INFO, LOG_WARN, rules, rules_count, rules_malloced, and SET_STATUS_TEXT.
| void setlayout_floating | ( | const Arg * | arg | ) |
Set current layout to floating.
This is a wrapper for the setlayout() function. It sets the currently focused monitor's layout to the floating layout found in the layouts array.
| arg | Unused. |
References get_layout(), and RETURN_IF_NULL.
| void setlayout_monocle | ( | const Arg * | arg | ) |
Set current layout to monocle.
This is a wrapper for the setlayout() function. It sets the currently focused monitor's layout to the monocle layout found in the layouts array.
| arg | Unused. |
References get_layout(), and RETURN_IF_NULL.
| void setlayout_tiled | ( | const Arg * | arg | ) |
Set current layout to tile.
This is a wrapper for the setlayout() function. It sets the currently focused monitor's layout to the tile layout found in the layouts array.
| arg | Unused. |
References get_layout(), and RETURN_IF_NULL.
| void spawn_string | ( | const Arg * | arg | ) |
Wrapper around spawn() for simpler program spawning.
This wrapper is to simplify the parsers interaction with the spawn() function. It takes in the program name and arguments as a string from Arg, prepares them with the necessary shell executable and flag, and then passes it all to spawn().
| [in] | arg | Pointer to the Arg struct containing a null terminated string containing the name and arguments of the program to spawn. |
References LOG_DEBUG, POINTER_NULL_PRINT_STRING, and RETURN_IF_NULL.
|
static |
Parser filepath string.
This variable is to save on binary size. By instead referencing this string when logging, we don't add hundreds of repeat string literals to the binary, saving roughly 4kb on the final binary.
|
static |
Default alias map for common X11 buttons.
Referenced by _parse_buttonbind_button().
|
static |
Default alias map for dwm's click enum.
Referenced by _parse_buttonbind_click().
| const char* ERROR_ENUM_STRINGS[] |
String name pairs to Error_t.
Referenced by _parse_bind_core(), _parse_buttonbind(), _parse_buttonbinds_config(), _parse_generic_settings(), _parse_keybind(), _parse_keybinds_config(), _parse_rules_config(), _parse_setting_array(), _parse_tags_config(), _parse_theme(), and _parse_theme_config().
|
static |
Default alias map for dwm's arg functions.
Referenced by _parse_bind_function().
|
static |
Default alias map for common X11 modifiers.
Referenced by _parse_bind_modifier().
|
static |
Default alias map for dwm's global config settings.
Referenced by _parse_generic_settings().
|
static |
Default alias map for dwm's scheme indexes.
Referenced by _parse_theme().