aboutsummaryrefslogtreecommitdiff
path: root/fbwarn/src/warn.c
blob: a495f6b3ab687a1958cf48dbbb3b5b9bda4e57cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "raylib.h"
#include "parseBVG.h"
#include "extString.h"
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

int main(void) {
  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);

  for (int i = 0; i<funcCount; i++) {
    printf("%s", funcs[i]);
  }

  fclose(bvgfile);

  char *call = strdup(multiToSingle(funcs[0]));
  char *args[2];
  call=call+strlen("IMG (");
  char *callTrim = trim(call);
  callTrim[strlen(callTrim)-1]='\0';
  collectArgs(args, callTrim, 2);
  BVGIMG *imgsize = BVGParseIMG(args);

  InitWindow (imgsize->width, imgsize->height, ":3");


  while (!WindowShouldClose ()) {
    
    BeginDrawing ();
    ClearBackground (RAYWHITE);

    for (int i = 0; i<funcCount; i++) {
      matchFunctionCall(multiToSingle(funcs[i]));
    }

    char *text = malloc(strlen("100")*100);
    sprintf(text, "%d", GetFPS());
    DrawText(text, 2, 2, 20, MAROON);
    EndDrawing ();
  }

  CloseWindow ();
  
  return 0;
}