Ver código fonte

jimp: introduce jimp_begin()

rexim 1 mês atrás
pai
commit
8b04432bca
2 arquivos alterados com 15 adições e 12 exclusões
  1. 5 12
      examples/03_parsing_database.c
  2. 10 0
      jimp.h

+ 5 - 12
examples/03_parsing_database.c

@@ -70,22 +70,15 @@ typedef struct {
     size_t capacity;
 } Numbers;
 
-int main()
+int main(void)
 {
-    // const char *file_path = "profile.json";
-    // const char *file_path = "numbers.json";
-    // const char *file_path = "profiles.json";
-    // const char *file_path = "empty.json";
-    // const char *file_path = "one.json";
     const char *file_path = "database.json";
+
     String_Builder sb = {0};
     if (!read_entire_file(file_path, &sb)) return 1;
-    Jimp jimp = {
-        .file_path = file_path,
-        .start = sb.items,
-        .end = sb.items + sb.count,
-        .point = sb.items,
-    };
+
+    Jimp jimp = {0};
+    jimp_begin(&jimp, file_path, sb.items, sb.count);
 
     People ps = {0};
     Numbers xs = {0};

+ 10 - 0
jimp.h

@@ -53,6 +53,8 @@ typedef struct {
 
 // TODO: how do null-s fit into this entire system?
 
+void jimp_begin(Jimp *jimp, const char *file_path, const char *input, size_t input_size);
+
 /// If succeeds puts the freshly parsed boolean into jimp->boolean.
 /// Any consequent calls to the jimp_* functions may invalidate jimp->boolean.
 bool jimp_boolean(Jimp *jimp);
@@ -206,6 +208,14 @@ static bool jimp__get_token(Jimp *jimp)
     return false;
 }
 
+void jimp_begin(Jimp *jimp, const char *file_path, const char *input, size_t input_size)
+{
+    jimp->file_path = file_path;
+    jimp->start     = input;
+    jimp->end       = input + input_size;
+    jimp->point     = input;
+}
+
 void jimp_diagf(Jimp *jimp, const char *fmt, ...)
 {
     long line_number = 0;