aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-07-09 19:48:06 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2025-07-09 19:48:06 +0530
commitb365f7cdd0882c1fe974e9e08d607341876a0d34 (patch)
treeca44b484fd020bc48a8b77da93b7c328a94b00fb
parentb71c27f403d82d5ab1db971887b9bdeae408cd5d (diff)
(lexer): implement find_all_keys
-rw-r--r--include/lexer.h1
-rw-r--r--src/lexer.c46
2 files changed, 47 insertions, 0 deletions
diff --git a/include/lexer.h b/include/lexer.h
index ca2b351..17a2825 100644
--- a/include/lexer.h
+++ b/include/lexer.h
@@ -19,6 +19,7 @@ typedef struct {
unsigned int length;
} contentfor_operand_t;
+list_t *parse_file(char *content);
directive_t *find_directive(char *content, key_match_t *match);
key_match_t *find_next_key(char *buffer);
diff --git a/src/lexer.c b/src/lexer.c
index 28dee8a..3237296 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -2,11 +2,57 @@
#include <ctype.h>
#include <lexer.h>
+#include <list.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+static list_t *
+find_all_keys(char *buffer)
+{
+ list_t *keys = list_create(sizeof(key_match_t));
+ key_match_t *match;
+ size_t match_offset = 0;
+ size_t current_offset = 0;
+
+ while (true) {
+ match = find_next_key(buffer);
+ if (match == NULL)
+ break;
+
+ match_offset = match->offset;
+
+ buffer += match->offset + match->length;
+ match->offset += current_offset;
+ current_offset += match->length + match_offset;
+
+ list_add(keys, match);
+ }
+
+ return keys;
+}
+
+list_t *
+parse_file(char *content)
+{
+ list_t *keys = find_all_keys(content);
+
+ for (size_t i = 0; i < keys->size; i++) {
+ key_match_t *match = list_get(keys, i);
+#ifdef DEBUG
+ printf("%lu: (%u) %.*s\n",
+ i,
+ match->length,
+ match->length,
+ content + match->offset);
+#endif
+ }
+
+ list_delete(keys);
+ return NULL;
+}
+
key_match_t *
find_next_key(char *buffer)
{