aboutsummaryrefslogtreecommitdiff
path: root/src/parse.c
diff options
context:
space:
mode:
authorkoekeishiya <aasvi93@hotmail.com>2017-08-08 13:56:57 +0200
committerkoekeishiya <aasvi93@hotmail.com>2017-08-08 13:56:57 +0200
commita58d0c8980560bde4c2ab6635584ed830fd06eed (patch)
treee5ba46f1c93d4e56ae8c6787e053ce0e0dea99fb /src/parse.c
parent03b74b16c003137e123032ea70f392533ce87355 (diff)
downloadskhd-a58d0c8980560bde4c2ab6635584ed830fd06eed.tar.gz
skhd-a58d0c8980560bde4c2ab6635584ed830fd06eed.zip
linked list -> hashmap; optimizations
Diffstat (limited to 'src/parse.c')
-rw-r--r--src/parse.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/parse.c b/src/parse.c
index 559d23d..b59e4cd 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -2,6 +2,7 @@
#include "tokenize.h"
#include "locale.h"
#include "hotkey.h"
+#include "hashtable.h"
#include <stdlib.h>
#include <stdio.h>
@@ -180,35 +181,30 @@ parse_hotkey(struct parser *parser)
printf("}\n");
- hotkey->next = NULL;
return hotkey;
}
-struct hotkey *
-parse_config(struct parser *parser)
+void parse_config(struct parser *parser, struct table *hotkey_map)
{
- struct hotkey hotkeys;
- struct hotkey *current_hotkey = &hotkeys;
-
+ struct hotkey *hotkey;
while(!parser_eof(parser)) {
if((parser_check(parser, Token_Modifier)) ||
(parser_check(parser, Token_Key_Hex)) ||
(parser_check(parser, Token_Key))) {
- current_hotkey->next = parse_hotkey(parser);
- current_hotkey = current_hotkey->next;
+ hotkey = parse_hotkey(parser);
+ table_add(hotkey_map, hotkey, hotkey);
if(parser->error) {
- return NULL;
+ free_hotkeys(hotkey_map);
+ return;
}
} else {
fprintf(stderr, "(#%d:%d) expected token 'Token_Modifier', 'Token_Key_Hex' or 'Token_Key', but got '%.*s'\n",
parser->current_token.line, parser->current_token.cursor,
parser->current_token.length, parser->current_token.text);
parser->error = true;
- return NULL;
+ return;
}
}
-
- return hotkeys.next;
}
struct token