aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkoekeishiya <aasvi93@hotmail.com>2020-01-01 21:12:27 +0100
committerkoekeishiya <aasvi93@hotmail.com>2020-01-01 21:12:27 +0100
commitf68bc63fd7021898c088f170b0ac403b118597d0 (patch)
tree6a97bb3532af795d5c93368eea059199de75ffcf
parenta3dd7bf7dd5135ae567db7922216b4e09d51cae8 (diff)
downloadskhd-f68bc63fd7021898c088f170b0ac403b118597d0.tar.gz
skhd-f68bc63fd7021898c088f170b0ac403b118597d0.zip
#95 make declaration of 'default'-mode order independent
-rw-r--r--src/hotkey.h1
-rw-r--r--src/parse.c18
2 files changed, 17 insertions, 2 deletions
diff --git a/src/hotkey.h b/src/hotkey.h
index 4611b09..6b6e92a 100644
--- a/src/hotkey.h
+++ b/src/hotkey.h
@@ -64,6 +64,7 @@ struct mode
char *name;
char *command;
bool capture;
+ bool initialized;
struct table hotkey_map;
};
diff --git a/src/parse.c b/src/parse.c
index e2b4c4d..42feca2 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -23,6 +23,7 @@ find_or_init_default_mode(struct parser *parser)
default_mode = malloc(sizeof(struct mode));
default_mode->name = copy_string("default");
+ default_mode->initialized = false;
table_init(&default_mode->hotkey_map, 131,
(table_hash_func) hash_hotkey,
@@ -348,6 +349,7 @@ parse_mode_decl(struct parser *parser)
struct token identifier = parser_previous(parser);
mode->name = copy_string_count(identifier.text, identifier.length);
+ mode->initialized = true;
table_init(&mode->hotkey_map, 131,
(table_hash_func) hash_hotkey,
@@ -374,8 +376,20 @@ void parse_declaration(struct parser *parser)
if (parser_match(parser, Token_Identifier)) {
struct token identifier = parser_previous(parser);
struct mode *mode = parse_mode_decl(parser);
- if (table_find(parser->mode_map, mode->name)) {
- parser_report_error(parser, identifier, "duplicate declaration '%s'\n", mode->name);
+
+ struct mode *existing_mode = table_find(parser->mode_map, mode->name);
+ if (existing_mode) {
+ if (same_string(existing_mode->name, "default") && !existing_mode->initialized) {
+ existing_mode->initialized = true;
+ existing_mode->capture = mode->capture;
+ existing_mode->command = mode->command;
+ } else {
+ parser_report_error(parser, identifier, "duplicate declaration '%s'\n", mode->name);
+ if (mode->command) free(mode->command);
+ }
+
+ free(mode->name);
+ free(mode);
} else {
table_add(parser->mode_map, mode->name, mode);
}