Add simple json validator application

This commit is contained in:
Danny Robson 2012-04-12 14:14:33 +10:00
parent 4ab352036d
commit 937d9522e0
2 changed files with 43 additions and 1 deletions

View File

@ -104,7 +104,8 @@ libutil_la_CXXFLAGS = $(AM_CXXFLAGS)
libutil_la_LIBADD = $(BOOST_SYSTEM_LIB)
bin_PROGRAMS = \
json-clean
json-clean \
json-validate
json_clean_SOURCES = json/clean.cpp
json_clean_DEPENDENCIES = $(top_builddir)/.libs/libutil.la
@ -112,3 +113,11 @@ json_clean_LDFLAGS = \
$(BOOST_LDFLAGS) \
$(BOOST_FILESYSTEM_LIB) \
$(top_builddir)/.libs/libutil.a
json_validate_SOURCES = json/validate.cpp
json_validate_DEPENDENCIES = $(top_builddir)/.libs/libutil.la
json_validate_LDFLAGS = \
$(BOOST_LDFLAGS) \
$(BOOST_FILESYSTEM_LIB) \
$(top_builddir)/.libs/libutil.a

33
json/validate.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "../json.hpp"
#include <iostream>
#include <cstdlib>
#include <boost/filesystem.hpp>
enum {
ARG_CMD,
ARG_PATH,
NUM_ARGS
};
int
main (int argc, char ** argv) {
if (argc != NUM_ARGS) {
std::cerr << "Invalid arguments. "
<< argv[ARG_CMD] << " <path> "
<< std::endl;
return EXIT_FAILURE;
}
try {
json::parse (boost::filesystem::path (argv[ARG_PATH]));
} catch (json::error &x) {
std::cerr << x.what () << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}