json.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. JSONError error;
  24. JSONToken* tokens;
  25. error = parser->parse();
  26. tokens = parser->get_tokens();
  27. for (int i = 0; i < parser->get_tokens_number(); i++)
  28. {
  29. printf("token[%d]\n", i);
  30. printf("type: %d\n", tokens[i].m_type);
  31. printf("size: %d\n", tokens[i].m_size);
  32. printf("start: %d\n",tokens[i].m_start);
  33. printf("end: %d\n",tokens[i].m_end);
  34. printf("parent token: %d\n",tokens[i].m_parent);
  35. printf("\n");
  36. }
  37. printf("return: %d\n", error);
  38. conf_root.close(stream);
  39. return 0;
  40. }