diff options
Diffstat (limited to '')
-rw-r--r-- | fbwarn/src/Makefile.am | 3 | ||||
-rw-r--r-- | fbwarn/src/parseBVG.c | 63 | ||||
-rw-r--r-- | fbwarn/src/parseBVG.h | 4 | ||||
-rw-r--r-- | fbwarn/src/warn.c | 30 |
4 files changed, 100 insertions, 0 deletions
diff --git a/fbwarn/src/Makefile.am b/fbwarn/src/Makefile.am new file mode 100644 index 0000000..15711b4 --- /dev/null +++ b/fbwarn/src/Makefile.am @@ -0,0 +1,3 @@ +bin_PROGRAMS = fbwarn +fbwarn_SOURCES = warn.c parseBVG.c +AM_LDFLAGS = -lraylib diff --git a/fbwarn/src/parseBVG.c b/fbwarn/src/parseBVG.c new file mode 100644 index 0000000..235253b --- /dev/null +++ b/fbwarn/src/parseBVG.c @@ -0,0 +1,63 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "raylib.h" + +// reads a given file +FILE *readFile(char *path) { + FILE *fp = fopen (path, "r"); + if (fp == NULL) { + perror ("Failed to open file!"); + exit(1); + } + return fp; +} + +/* + Converts a multiline function + call into a single line call +*/ +char *multiToSingle(char *lines) { + // allocating the size of lines is safe since characters arent added + char *result = malloc (strlen(lines)+1); + char *line; + while ((line = strsep(&lines, "\n")) != NULL) + sprintf(result, "%s%s", result, line); + + free(line); + return result; +} + +void BVGRectangle(char *argv[5]) { + printf("Drawing rectangle\n"); + argv[4][strlen(argv[4])-2] = '\0'; + printf("%s, %s\n %s, %s,\n %s\n", argv[0], argv[1], argv[2], argv[3], argv[4]); + int x, y, width, height, color; + sscanf(argv[0]+strlen("x="), "%d", &x); + sscanf(argv[1]+strlen("y="), "%d", &y); + sscanf(argv[2]+strlen("width="), "%d", &width); + sscanf(argv[3]+strlen("height="), "%d", &height); + color = (int)strtol(argv[4]+strlen("color='#"), NULL, 16); + printf("X: %d, Y: %d\n", x, y); + printf("Width: %d, Height: %d\n", width, height); + printf("Color: %d\n", color); + DrawRectangle(x, y, width, height, PINK); + return; +} + +void matchFunctionCall(char *call) { + printf("Matching %s\n", call); + char *funcCall = strdup(call); + char *funcName = strsep(&funcCall, "("); + printf("Got function %s\n", funcName); + if (strcmp(funcName, "rectangle ") == 0) { + char **arg, *argv[5]; + call = call+strlen("rectangle ("); + for (arg = argv; (*arg = strsep(&call, ",")) != NULL;) + if (**arg != '\0') + if (++arg >= &argv[5]) + break; + BVGRectangle(argv); + } + return; +} diff --git a/fbwarn/src/parseBVG.h b/fbwarn/src/parseBVG.h new file mode 100644 index 0000000..87cf4a4 --- /dev/null +++ b/fbwarn/src/parseBVG.h @@ -0,0 +1,4 @@ +#include <stdio.h> +FILE readFile(char*); +char *multiToSingle(char*); +void matchFunctionCall(char*); diff --git a/fbwarn/src/warn.c b/fbwarn/src/warn.c new file mode 100644 index 0000000..65995d2 --- /dev/null +++ b/fbwarn/src/warn.c @@ -0,0 +1,30 @@ +#include "raylib.h" +#include "parseBVG.h" +#include <string.h> +#include <stdlib.h> + +int main(void) { + char *str, *single, *toFree; + toFree = str = strdup("rectangle (x=20,y=30,\nwidth=200,\nheight=300,\ncolor='#F5A9B8')\n"); + if (str == NULL) + return 1; + printf("Multi:\n %s", str); + single = multiToSingle(str); + printf("Single:\n %s\n", single); + free(toFree); + + InitWindow (800, 450, "raylib"); + + while (!WindowShouldClose ()) { + BeginDrawing (); + ClearBackground (RAYWHITE); + DrawText ("TEXT", 190, 200, 20, LIGHTGRAY); + char *parse = strdup(single); + matchFunctionCall(parse); + EndDrawing (); + } + + CloseWindow (); + + return 0; +} |