libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

j2b.c (1210B)


      1 //
      2 
      3 #include "../release/libsheepyObject.h"
      4 
      5 #define internal static
      6 
      7 #include <stdlib.h>
      8 #include <stdio.h>
      9 
     10 #ifndef unitTest
     11 #endif
     12 int MAIN(int ARGC, char** ARGV);
     13 
     14 int argc; char **argv;
     15 
     16 #ifndef unitTest
     17 // Remove main when running the unit tests
     18 #define MAIN   main
     19 #endif
     20 int MAIN(int ARGC, char** ARGV) {
     21   int dummy UNUSED;
     22 
     23   argc = ARGC; argv = ARGV;;// load json in command parameter and convert to bin
     24 
     25   // Steps
     26   // create json object
     27   // load text to file
     28   // parse
     29   // write in bin format
     30 
     31   if (argc < 2) {
     32     puts(BLD RED "Usage: " RST "j2b <file.bin>");
     33     XFAILURE
     34   }
     35 
     36   char *iFName = argv[1];
     37   char *oFName = dupG(iFName);
     38   char *p      = findG(oFName, ".");
     39   if (p) {
     40     // remove extension
     41     *p = 0;
     42   }
     43   pErrorNULL(appendG(&oFName, ".bin"));
     44 
     45   // create json object
     46   createAllocateSmallJson(json);
     47 
     48   // parse json
     49   // load text to file
     50   createAllocateSmallString(file);
     51   readFileG(file, iFName);
     52 
     53   // parse
     54   parseG(json, ssGet(file));
     55 
     56   // write in bin format
     57   if (fileExistsG(oFName)) {
     58     puts(BLD RED "Overwriting: " RST);
     59     puts(oFName);
     60   }
     61   smallBytest *B = serialG(json);
     62   writeFileG(B, oFName);
     63 
     64   free(oFName);
     65   terminateManyG(B, json, file);
     66 }