libcruft-util/tools/json-clean.cpp

54 lines
1.2 KiB
C++
Raw Normal View History

2012-04-20 18:08:59 +10:00
/*
2018-08-04 15:14:06 +10:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
2012-04-20 18:08:59 +10:00
*
* Copyright 2012-2016 Danny Robson <danny@nerdcruft.net>
2012-04-20 18:08:59 +10:00
*/
#include "io.hpp"
#include "json/except.hpp"
#include "json/tree.hpp"
2012-04-12 14:12:25 +10:00
#include <cstdlib>
#include <iostream>
///////////////////////////////////////////////////////////////////////////////
2012-04-12 14:12:25 +10:00
enum {
ARG_COMMAND,
ARG_INPUT,
NUM_ARGS
};
//-----------------------------------------------------------------------------
2012-04-12 14:12:25 +10:00
void
print_usage (int argc, char **argv)
{
2012-04-12 14:12:25 +10:00
(void)argc;
std::cerr << "usage: " << argv[0] << " <input>\n";
}
//-----------------------------------------------------------------------------
2012-04-12 14:12:25 +10:00
int
main (int argc, char **argv)
{
2012-04-12 14:12:25 +10:00
if (argc != NUM_ARGS) {
print_usage (argc, argv);
return EXIT_FAILURE;
}
try {
const cruft::mapped_file src (argv[ARG_INPUT]);
std::cout << *json::tree::parse (cruft::view{src}.cast<const char*> ()) << '\n';
} catch (const json::error& err) {
2012-04-12 14:12:25 +10:00
std::cerr << err.what () << "\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}