From de52acd37ea5634712ed78c624f77566e3ac634e Mon Sep 17 00:00:00 2001 From: bpc2003 Date: Mon, 10 Mar 2025 15:26:32 -0400 Subject: Removed need for parser and revised readdb to return struct keytablist * --- src/parser.c | 71 ------------------------------------------------------------ 1 file changed, 71 deletions(-) delete mode 100644 src/parser.c (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c deleted file mode 100644 index a45c945..0000000 --- a/src/parser.c +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include - -#include "include/mdb.h" - -int blen; - -static void addbyte(struct byte *bytes, int *pos, enum btype type, char *value); -static char *getpair(uint8_t *buf, int *pos); - -struct byte *parse(uint8_t *buf) -{ - char *value; - int len = 2; - struct byte *bytes = calloc(len, sizeof(struct byte)); - for (int i = 0, j = 0; buf[i]; ++i) { - if (j >= len) - len *= 2; - bytes = realloc(bytes, len * sizeof(struct byte)); - switch (buf[i]) { - case 250: - value = getpair(buf, &i); - if (value == NULL) - addbyte(bytes, &j, ERROR, "Invalid Key-Value pair"); - else - addbyte(bytes, &j, PAIR, value); - break; - case 251: - addbyte(bytes, &j, BEGIN, NULL); - break; - case 254: - addbyte(bytes, &j, END, NULL); - break; - default: - addbyte(bytes, &j, ERROR, "Invalid chunk"); - } - blen = j; - } - return bytes; -} - -static void addbyte(struct byte *bytes, int *pos, enum btype type, char *value) -{ - bytes[*pos].type = type; - - if (value != NULL) { - bytes[*pos].value = value; - } - else - bytes[*pos].value = NULL; - - (*pos)++; -} - -static char *getpair(uint8_t *buf, int *pos) -{ - int i; - for (i = *pos + 1; buf[i] != 250 && buf[i] != 254 && buf[i]; ++i) - ; - if (buf[i] != 250 && buf[i] != 254) - return NULL; - - char *pair = calloc(i - *pos, sizeof(char)); - int j; - for (j = *pos + 1; j < i; ++j) - pair[j - (*pos + 1)] = buf[j]; - pair[j - (*pos + 1)] = '\0'; - *pos = i - 1; - return pair; -} -- cgit v1.2.3