summaryrefslogtreecommitdiff
path: root/source/engine.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/engine.c')
-rw-r--r--source/engine.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/source/engine.c b/source/engine.c
index 1cfbab0..9797d8a 100644
--- a/source/engine.c
+++ b/source/engine.c
@@ -40,7 +40,7 @@ is_delimiter(u8 point)
40typedef struct query_token query_token; 40typedef struct query_token query_token;
41struct query_token 41struct query_token
42{ 42{
43 string8 *lexeme; 43 string8 lexeme;
44 query_token *next; 44 query_token *next;
45}; 45};
46 46
@@ -72,8 +72,9 @@ query_tokenizer(mem_arena *arena, string8 *buffer)
72 72
73 s32 new_token_size = end - start; 73 s32 new_token_size = end - start;
74 74
75 tok->lexeme->data = &buffer->data[index]; 75 tok->lexeme = PushString(arena, new_token_size);
76 tok->lexeme->size = new_token_size; 76 tok->lexeme.data = &buffer->data[index];
77 tok->lexeme.size = new_token_size;
77 78
78 tok->next = tok; 79 tok->next = tok;
79 start = index + 1; 80 start = index + 1;
@@ -83,21 +84,18 @@ query_tokenizer(mem_arena *arena, string8 *buffer)
83 return tok; 84 return tok;
84} 85}
85 86
86int main(int c, char **v) 87int main(int count, char **value)
87{ 88{
88 89 if(count < 2) value[1] = "./test/data.csv";
89 if(c < 2)
90 {
91 print("bad file, setting default file\n");
92 }
93 else v[1] = "./test/customers-10000.csv";
94 90
95 local_persist b32 running = 1; 91 local_persist b32 running = 1;
96 92
97 mem_arena *global_arena = arena_create(MiB(30)); 93 mem_arena *global_arena = arena_create(MiB(30));
98 csv_table *global_table = PushStruct(global_arena, csv_table);
99 94
100 string8 buffer = load_file(v[1]); 95 // NOTE(nasr): see note down below
96 // csv_table *global_table = PushStruct(global_arena, csv_table);
97
98 string8 buffer = load_file(global_arena, value[1]);
101 99
102 print("\nDatabase Engine\n"); 100 print("\nDatabase Engine\n");
103 101
@@ -106,23 +104,41 @@ int main(int c, char **v)
106 if (running) 104 if (running)
107 { 105 {
108 { 106 {
109 u8 lbuf[256] = {}; 107 u8 *lbuf = PushArray(global_arena, u8, 256);
110 s32 err = os_read(STDIN_FD, lbuf, 256); 108 s32 err = os_read(STDIN_FD, lbuf, 256);
109
111 if(err < 0) 110 if(err < 0)
112 { 111 {
113 print("error reading from stdin"); 112 print("error reading from stdin");
114 } 113 }
115 114
116 query_tokenizer(global_arena, &StringLit(lbuf)); 115 // TODO(nasr): extract this later in the future and make a string copy function/macro
116 // @params (s32 lbuf_size , string8 lbuf_stringified)
117 s32 lbuf_size = sizeof(lbuf) - 1;
118 string8 lbuf_stringified = PushString(global_arena, lbuf_size);
119 {
120 memcpy(lbuf_stringified.data, lbuf, lbuf_size);
121 lbuf_stringified.size = sizeof(lbuf) - 1;
122 }
117 123
124 query_tokenizer(global_arena, &lbuf_stringified);
118 } 125 }
119 126
120 { 127 {
121 read_csv(buffer); 128 read_csv(buffer);
122 token *tokens = tokenize_csv(buffer, global_arena); 129 token *tokens = tokenize_csv(buffer, global_arena);
123 global_table = parse_csv(tokens, global_table); 130
131 assert_msg(tokens != NULL, "Tokens are NULL.");
132
133 b_tree *bt = parse_csv(global_arena, tokens);
134 b_tree_write(bt);
124 } 135 }
125 136
137
138 // NOTE(nasr): not sure on how to approach the b-tree and the table format thing
139 // we kind of want our table format i think? but i wouldnt be sure about the use case
140 // so we stick to the regular b_tree for now. commenting out the tables.
141
126 sleep(1); 142 sleep(1);
127 } 143 }
128 } 144 }