aboutsummaryrefslogtreecommitdiff
path: root/fbwarn/src/parseBVG.c
diff options
context:
space:
mode:
authoraxtloss <axtlos@getcryst.al>2024-02-25 01:54:04 +0100
committeraxtloss <axtlos@getcryst.al>2024-02-25 01:54:04 +0100
commitcab4804979e8c60cc8ccc0612b759d2c3637539f (patch)
treee2c4e90de2c73defd37d86f78b19423f5fa653be /fbwarn/src/parseBVG.c
parente6c12b02674a04ca34e27b46f6ca3261fca3c677 (diff)
downloadfsverify-cab4804979e8c60cc8ccc0612b759d2c3637539f.tar.gz
fsverify-cab4804979e8c60cc8ccc0612b759d2c3637539f.tar.bz2
Add initial fswarn and BVG code
Diffstat (limited to 'fbwarn/src/parseBVG.c')
-rw-r--r--fbwarn/src/parseBVG.c63
1 files changed, 63 insertions, 0 deletions
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;
+}