y2b.c (1209B)
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 yml in command parameter and convert to yml 24 25 // Steps 26 // create yml object 27 // load text to file 28 // parse 29 // write in yml format 30 31 if (argc < 2) { 32 puts(BLD RED "Usage: " RST "y2b <file.yml>"); 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 yml object 46 createAllocateSmallJson(json); 47 48 // parse yml 49 // load text to file 50 createAllocateSmallString(file); 51 readFileG(file, iFName); 52 53 // parse 54 parseYMLG(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 }