2018-12-10 02:08:41 +08:00
|
|
|
#include <iostream>
|
2018-12-07 06:22:22 +08:00
|
|
|
#include <unistd.h>
|
2020-03-03 06:23:19 +08:00
|
|
|
#include "simdjson.h"
|
2018-12-07 06:22:22 +08:00
|
|
|
|
2020-04-19 07:37:11 +08:00
|
|
|
void usage(const char *exe) {
|
|
|
|
std::cerr << exe << " v" << STRINGIFY(SIMDJSON_VERSION) << " (" << simdjson::active_implementation->name() << ")" << std::endl;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << "Reads json in, out the result of the parsing. " << std::endl;
|
|
|
|
std::cerr << "Usage: " << exe << " <jsonfile>" << std::endl;
|
|
|
|
std::cerr << "The -d flag dumps the raw content of the tape." << std::endl;
|
|
|
|
}
|
2018-12-07 06:22:22 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
2019-07-31 05:18:10 +08:00
|
|
|
bool rawdump = false;
|
2018-12-31 10:00:19 +08:00
|
|
|
|
2018-12-07 06:22:22 +08:00
|
|
|
int c;
|
|
|
|
|
2020-04-19 07:37:11 +08:00
|
|
|
while ((c = getopt(argc, argv, "dh")) != -1) {
|
2018-12-10 02:08:41 +08:00
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
|
|
|
rawdump = true;
|
|
|
|
break;
|
2020-04-19 07:37:11 +08:00
|
|
|
case 'h':
|
|
|
|
usage(argv[0]);
|
|
|
|
return EXIT_SUCCESS;
|
2018-12-10 02:08:41 +08:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2019-07-31 05:18:10 +08:00
|
|
|
}
|
2018-12-07 06:22:22 +08:00
|
|
|
if (optind >= argc) {
|
2020-04-19 07:37:11 +08:00
|
|
|
usage(argv[0]);
|
|
|
|
return EXIT_FAILURE;
|
2018-12-07 06:22:22 +08:00
|
|
|
}
|
2018-12-10 02:08:41 +08:00
|
|
|
const char *filename = argv[optind];
|
|
|
|
if (optind + 1 < argc) {
|
2019-07-31 05:18:10 +08:00
|
|
|
std::cerr << "warning: ignoring everything after " << argv[optind + 1]
|
|
|
|
<< std::endl;
|
2018-12-07 06:22:22 +08:00
|
|
|
}
|
2020-03-29 02:43:41 +08:00
|
|
|
simdjson::dom::parser parser;
|
2020-03-25 23:22:16 +08:00
|
|
|
auto [doc, error] = parser.load(filename); // do the parsing, return false on error
|
|
|
|
if (error != simdjson::SUCCESS) {
|
|
|
|
std::cerr << " Parsing failed. Error is '" << simdjson::error_message(error)
|
2019-07-31 05:18:10 +08:00
|
|
|
<< "'." << std::endl;
|
2018-12-07 06:22:22 +08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2020-03-25 23:22:16 +08:00
|
|
|
if(rawdump) {
|
|
|
|
doc.dump_raw_tape(std::cout);
|
2018-12-08 12:35:53 +08:00
|
|
|
} else {
|
2020-03-25 23:22:16 +08:00
|
|
|
std::cout << doc;
|
2018-12-07 06:22:22 +08:00
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|