mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-03-16 05:34:14 -04:00
feat: add a source-optional keyword
This commit is contained in:
parent
ae6c4b9a31
commit
f33cb859f5
1 changed files with 15 additions and 9 deletions
|
|
@ -342,7 +342,7 @@ typedef struct {
|
||||||
typedef int32_t (*FuncType)(const Arg *);
|
typedef int32_t (*FuncType)(const Arg *);
|
||||||
Config config;
|
Config config;
|
||||||
|
|
||||||
bool parse_config_file(Config *config, const char *file_path);
|
bool parse_config_file(Config *config, const char *file_path, bool must_exist);
|
||||||
|
|
||||||
// Helper function to trim whitespace from start and end of a string
|
// Helper function to trim whitespace from start and end of a string
|
||||||
void trim_whitespace(char *str) {
|
void trim_whitespace(char *str) {
|
||||||
|
|
@ -2527,8 +2527,10 @@ bool parse_option(Config *config, char *key, char *value) {
|
||||||
config->gesture_bindings_count++;
|
config->gesture_bindings_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (strncmp(key, "source-optional", 15) == 0) {
|
||||||
|
parse_config_file(config, value, false);
|
||||||
} else if (strncmp(key, "source", 6) == 0) {
|
} else if (strncmp(key, "source", 6) == 0) {
|
||||||
parse_config_file(config, value);
|
parse_config_file(config, value, true);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"\033[1m\033[31m[ERROR]:\033[33m Unknown keyword: "
|
"\033[1m\033[31m[ERROR]:\033[33m Unknown keyword: "
|
||||||
|
|
@ -2556,7 +2558,7 @@ bool parse_config_line(Config *config, const char *line) {
|
||||||
return parse_option(config, key, value);
|
return parse_option(config, key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parse_config_file(Config *config, const char *file_path) {
|
bool parse_config_file(Config *config, const char *file_path, bool must_exist) {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char full_path[1024];
|
char full_path[1024];
|
||||||
|
|
||||||
|
|
@ -2601,11 +2603,15 @@ bool parse_config_file(Config *config, const char *file_path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
fprintf(stderr,
|
if (must_exist) {
|
||||||
"\033[1;31m\033[1;33m[ERROR]:\033[0m Failed to open "
|
fprintf(stderr,
|
||||||
"config file: %s\n",
|
"\033[1;31m\033[1;33m[ERROR]:\033[0m Failed to open "
|
||||||
file_path);
|
"config file: %s\n",
|
||||||
return false;
|
file_path);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char line[512];
|
char line[512];
|
||||||
|
|
@ -3320,7 +3326,7 @@ bool parse_config(void) {
|
||||||
|
|
||||||
bool parse_correct = true;
|
bool parse_correct = true;
|
||||||
set_value_default();
|
set_value_default();
|
||||||
parse_correct = parse_config_file(&config, filename);
|
parse_correct = parse_config_file(&config, filename, true);
|
||||||
set_default_key_bindings(&config);
|
set_default_key_bindings(&config);
|
||||||
override_config();
|
override_config();
|
||||||
return parse_correct;
|
return parse_correct;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue