Explorar o código

Fix parser mess, add different macro for engine/parser

Evgeniy Parfenyuk hai 2 meses
pai
achega
767797c704
Modificáronse 5 ficheiros con 29 adicións e 51 borrados
  1. 0 0
      assets/test.vnrs
  2. 22 1
      src/main.c
  3. 0 27
      src/parser.h
  4. 1 23
      src/vnrs_parser.c
  5. 6 0
      src/vnrs_parser.h

+ 0 - 0
src/test.vnrs → assets/test.vnrs


+ 22 - 1
src/main.c

@@ -19,8 +19,13 @@ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 #include <raylib.h>
 #include <string.h>
+#include <stdio.h>
 
-#include "parser.h"
+#include "vnrs_parser.h"
+
+#define MAIN_ENGINE 1
+#define MAIN_PARSER 2
+#define MAIN MAIN_ENGINE
 
 typedef struct {
     Texture2D img;
@@ -43,6 +48,7 @@ typedef struct {
 
 int main(void)
 {
+#if MAIN == MAIN_ENGINE
     const int screenWidth = 1920;
     const int screenHeight = 1080;
 
@@ -68,6 +74,8 @@ int main(void)
     cur_state.layers[1].pos = (Vector2){0.5, 0.5};
     cur_state.layers_count += 2;
 
+
+    
     while (!WindowShouldClose())
     {
         BeginDrawing();
@@ -99,5 +107,18 @@ int main(void)
 
     CloseWindow();
 
+#elif MAIN == MAIN_PARSER
+    FILE *f;
+    printf("Parser...\n");
+    f = fopen("assets/test.vnrs", "r");
+    if (!f) {
+        perror("assets/test.vnrs");
+        return 2; 
+    }
+
+    parse_vnrs(f, stdout);
+
+    fclose(f);
+#endif
     return 0;
 }

+ 0 - 27
src/parser.h

@@ -1,27 +0,0 @@
-#ifndef PARSER_H
-#define PARSER_H
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define BUF_SIZE 512 // Max size according to specification
-
-char *read_chunk_from_file(char *filename)
-{
-    FILE *fp;
-    if ((fp = fopen(filename, "r")) == NULL) {
-        perror(filename);
-        return NULL;
-    }
-
-    char *result = malloc(BUF_SIZE);
-
-    if (fgets(result, BUF_SIZE, fp) != NULL) { 
-        result[strlen(result) - 1] = 'X';
-    }
-        
-
-    return result;
-}
-
-#endif // PARSER_H

+ 1 - 23
src/vnrs_parser.c

@@ -24,7 +24,7 @@ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 #include "chunks.h"
 #include "text_utils.h"
-
+#include "vnrs_parser.h"
 
 
 static void normalise(char *s)
@@ -77,25 +77,3 @@ void parse_vnrs(FILE *input, FILE *output)
             break;
     }
 }
-
-/*
-int main(int argc, char *argv[])
-{
-    if (argc < 2) {
-        fprintf(stderr, "Usage: ./parser <filename>.vnrs\n");
-        return 1;
-    }
-
-    FILE *f;
-    f = fopen(argv[1], "r");
-    if (!f) {
-        perror(argv[1]);
-        return 2; 
-    }
-
-    parse_vnrs(f, stdout);
-
-    fclose(f);
-    return 0;
-}
-*/

+ 6 - 0
src/vnrs_parser.h

@@ -0,0 +1,6 @@
+#ifndef VNRS_PARSER_H
+#define VNRS_PARSER_H
+
+void parse_vnrs(FILE *input, FILE *output);
+
+#endif // VNRS_PARSER_H