json.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "JSONParser.h"
  4. #include "Filesystem.h"
  5. #include "FileStream.h"
  6. using namespace crown;
  7. int main(int argc, char** argv)
  8. {
  9. if (argc != 2)
  10. {
  11. printf("Configuration root path must be provided. Aborting!");
  12. return -1;
  13. }
  14. Filesystem conf_root(argv[1]);
  15. if (!conf_root.exists("json.json"))
  16. {
  17. printf("Configuration file does not exists. Aborting!\n");
  18. return -1;
  19. }
  20. char dst[10][256];
  21. FileStream* stream = (FileStream*)conf_root.open("json.json", SOM_READ);
  22. JSONParser* parser = new JSONParser(stream);
  23. json_error error;
  24. JSONToken* tokens;
  25. parser->init();
  26. error = parser->parse();
  27. tokens = parser->get_tokens();
  28. for (int i = 0; i < parser->get_tokens_number(); i++)
  29. {
  30. printf("token[%d]\n", i);
  31. printf("type: %d\n", tokens[i].m_type);
  32. printf("size: %d\n", tokens[i].m_size);
  33. printf("start: %d\n",tokens[i].m_start);
  34. printf("end: %d\n",tokens[i].m_end);
  35. printf("parent token: %d\n",tokens[i].m_parent);
  36. printf("\n");
  37. }
  38. parser->shutdown();
  39. printf("return: %d\n", error);
  40. conf_root.close(stream);
  41. return 0;
  42. }