Lua: Don't lua_error() out of context with pending dtors
[lsnes.git] / src / util / jsonlint.cpp
blob5026552fa3cce732f1f4341a42638eef27b02770
1 #include "library/json.hpp"
2 #include <iostream>
3 #include <fstream>
4 #include <list>
5 #include <string>
7 int main(int argc, char** argv)
9 int ret = 0;
10 bool print_parsed = false;
11 bool end_opt = false;
12 std::list<std::string> files;
13 for(int i = 1; i < argc; i++) {
14 std::string opt = argv[i];
15 if(end_opt)
16 files.push_back(opt);
17 else if(opt == "--")
18 end_opt = true;
19 else if(opt == "--print")
20 print_parsed = true;
21 else if(opt.substr(0, 2) == "--") {
22 std::cerr << "Unknown option '" << opt << "'" << std::endl;
23 return 2;
24 } else
25 files.push_back(opt);
27 for(auto i : files) {
28 std::string doc;
29 try {
31 std::ifstream strm(i, std::ios::binary);
32 if(!strm)
33 throw std::runtime_error("Can't open");
34 while(strm) {
35 std::string line;
36 std::getline(strm, line);
37 doc = doc + line + "\n";
40 JSON::node n(doc);
41 if(print_parsed) {
42 JSON::printer_indenting ip;
43 std::cout << n.serialize(&ip) << std::endl;
45 } catch(JSON::error& e) {
46 std::cerr << i << ": " << e.extended_error(doc) << std::endl;
47 ret = 1;
48 } catch(std::exception& e) {
49 std::cerr << i << ": " << e.what() << std::endl;
50 ret = 1;
53 return ret;