Experimenting with tokenizing strings. This commit just focuses on splitting strings up by whitespace.

This commit is contained in:
2022-01-20 18:17:58 +00:00
parent 479dc57ea8
commit 99ebd82996
3 changed files with 203 additions and 22 deletions
+26 -22
View File
@@ -2,6 +2,8 @@
#include <stdio.h>
#include <string.h>
#include "../includes/list.h"
#include "../includes/hash_table.h"
#include "../includes/tokenizer.h"
typedef struct {
char *opcode;
@@ -11,7 +13,6 @@ typedef struct {
void print_file(char*);
List* get_strings(const char*);
void PrintList(const List*);
int main(int argc, char* args[]) {
const char *input_files[argc - 1];
@@ -20,6 +21,9 @@ int main(int argc, char* args[]) {
printf("Input files required.\n");
return -1;
}
// char* test = "user_id";
// printf("Key for '%s' is %d for size %d\n", test, GetKeyIndex(test, HASHTABLEDEFAULTSIZE), HASHTABLEDEFAULTSIZE);
TokenizeString(args[1]);
// for (int i = 1; i < argc; i++) {
// input_files[i - 1] = args[i];
@@ -27,29 +31,29 @@ int main(int argc, char* args[]) {
// }
//print_file(args[1]);
struct test {
int SomeValue;
char* SomeText;
};
struct test* thing = malloc(sizeof(struct test));
thing->SomeText = calloc(1, 16);
List *list = CreateList();
// struct test {
// int SomeValue;
// char* SomeText;
// };
// struct test* thing = malloc(sizeof(struct test));
// thing->SomeText = calloc(1, 16);
// List *list = CreateList();
for (int i = 0; i < 64; i++) {
sprintf(thing->SomeText, "%d", i);
thing->SomeValue = i;
AddListItem(thing, sizeof(struct test), list);
// for (int i = 0; i < 64; i++) {
// sprintf(thing->SomeText, "%d", i);
// thing->SomeValue = i;
// AddListItem(thing, sizeof(struct test), list);
if (i % 4 == 0) printf("Size: %d; Capacity: %d\n", list->size, list->capacity);
// if (i % 4 == 0) printf("Size: %d; Capacity: %d\n", list->size, list->capacity);
printf("Some Value: %d Some Text: '%s'\n", ((struct test*) list->content[list->size - 1])->SomeValue, ((struct test*) list->content[list->size - 1])->SomeText);
}
// printf("Some Value: %d Some Text: '%s'\n", ((struct test*) list->content[list->size - 1])->SomeValue, ((struct test*) list->content[list->size - 1])->SomeText);
// }
//PrintList(list);
free(thing->SomeText);
free(thing);
// //PrintList(list);
// free(thing->SomeText);
// free(thing);
free(list);
//free(list);
}
void print_file(char* file_path) {
@@ -86,7 +90,7 @@ void print_file(char* file_path) {
// free(inst->parameters);
// free(inst);
PrintList(list);
//PrintList(list);
DestroyList(list);
}
@@ -108,7 +112,7 @@ List* get_strings(const char* line) {
if (line[i] == ' ' || line[i] == ',') {
if (index > 0) {
currentWord[index] = '\0';
AddListItem(currentWord, strlen(currentWord) + 1, list);
PushListItem(currentWord, strlen(currentWord) + 1, list);
}
index = 0;
continue;
@@ -121,7 +125,7 @@ List* get_strings(const char* line) {
index++;
}
currentWord[index] = '\0';
AddListItem(currentWord, strlen(currentWord) + 1, list);
PushListItem(currentWord, strlen(currentWord) + 1, list);
}
break;
}