From c9b119217829f976a7830a0555650401cf9df2cb Mon Sep 17 00:00:00 2001 From: axtloss Date: Tue, 27 Feb 2024 01:44:26 +0100 Subject: add functionality to read from bvg file --- fbwarn/src/warn.c | 113 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 54 deletions(-) (limited to 'fbwarn/src/warn.c') diff --git a/fbwarn/src/warn.c b/fbwarn/src/warn.c index db2750d..a495f6b 100644 --- a/fbwarn/src/warn.c +++ b/fbwarn/src/warn.c @@ -1,76 +1,81 @@ #include "raylib.h" #include "parseBVG.h" +#include "extString.h" +#include #include #include #include int main(void) { - char *rectA, *rectB, *rectC, *rectD, *rectAFree, *rectBFree, *rectCFree, *rectDFree, *singleA, *singleB, *singleC, *singleD; - char *rectE, *rectF, *rectEFree, *rectFFree, *singleE, *singleF; - rectAFree = rectA = strdup("rectangle (x=10,y=20,\nwidth=100,\nheight=100,\ncolor='#9787CFFF',\nfill=true,\nthickness=1.0)\n"); - if (rectA == NULL) - return 1; - singleA = multiToSingle(rectA); - free(rectAFree); - - rectBFree = rectB = strdup("rectangle (x=130,y=160,\nwidth=100,\nheight=60,\ncolor='#88C2B1FF',\nfill=false,\nthickness=5.0)\n"); - if (rectB == NULL) - return 1; - singleB = multiToSingle(rectB); - free(rectBFree); + FILE *bvgfile = readFile("./test.bvg"); + char *line = NULL; + size_t len = 0; + ssize_t nread = 0; + ssize_t totallinesize = 0; + ssize_t funcCount = 0; + int inComment = 0; + char *funcline = strdup(""); + char **funcs = malloc(1*sizeof(char)); + + while ((nread = getline(&line, &len, bvgfile)) != -1) { + if (strstr(line, "/*")) { + inComment += 1; + continue; + } + if (strstr(line, "*/")) { + inComment -= 1; + continue; + } + if (inComment != 0 || strstr(line, "//") || line[0] == '\n') + continue; + void *newfuncline = realloc(funcline, sizeof(char)*(strlen(funcline)+strlen(line)+1)); + if (newfuncline) + funcline = newfuncline; + else + exit(2); + totallinesize=totallinesize+nread; + sprintf(funcline, "%s%s", funcline, line); + if (line[nread-2] == ')') { + funcCount += 1; + void *newfuncs = realloc(funcs, sizeof(char)*(sizeof(funcs)+1+strlen(funcline)*2)); + if (newfuncs) + funcs = newfuncs; + else + exit(2); + funcs[funcCount-1]=strdup(funcline); + totallinesize = 0; + free(funcline); + funcline = strdup(""); + } + } + free(line); - rectCFree = rectC = strdup("circlesegment (x=300, y=200,radius=100,color='#BE79A7FF',startangle=0.0,endangle=90.0,segments=10)"); - if (rectC == NULL) - return 1; - singleC = multiToSingle(rectC); - printf("SingleC %s", rectC); - free(rectCFree); + for (int i = 0; iwidth, imgsize->height, ":3"); while (!WindowShouldClose ()) { BeginDrawing (); ClearBackground (RAYWHITE); - char *parseA = strdup(singleA); - matchFunctionCall(parseA); - - char *parseB = strdup(singleB); - matchFunctionCall(parseB); - - char *parseC = strdup(singleC); - matchFunctionCall(parseC); - char *parseD = strdup(singleD); - matchFunctionCall(parseD); - - char *parseE = strdup(singleE); - matchFunctionCall(parseE); + for (int i = 0; i