//

#include "../release/libsheepyObject.h"

#define internal static

#include <stdlib.h>

#ifndef unitTest
#endif
int MAIN(int ARGC, char** ARGV);

int argc; char **argv;

#ifndef unitTest
// Remove main when running the unit tests
#define MAIN   main
#endif
int MAIN(int ARGC, char** ARGV) {
  int dummy UNUSED;

  argc = ARGC; argv = ARGV;;// load yml in command parameter and convert to yml

  // Steps
  // create yml object
  // load text to file
  // parse
  // write in yml format

  if (argc < 2) {
    puts(BLD RED "Usage: " RST "y2b <file.yml>");
    XFAILURE
  }

  char *iFName = argv[1];
  char *oFName = dupG(iFName);
  char *p      = findG(oFName, ".");
  if (p) {
    // remove extension
    *p = 0;
  }
  appendG(&oFName, ".bin");

  // create yml object
  createAllocateSmallJson(json);

  // parse yml
  // load text to file
  createAllocateSmallString(file);
  readFileG(file, iFName);

  // parse
  parseYMLG(json, ssGet(file));

  // write in bin format
  if (fileExistsG(oFName)) {
    puts(BLD RED "Overwriting: " RST);
    puts(oFName);
  }
  smallBytest *B = serialG(json);
  writeFileG(B, oFName);

  free(oFName);
  terminateManyG(B, json, file);
}
