diff --git a/.gitignore b/.gitignore index 9633f8a158f6..734b36c2e162 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -!src/chkjson *.7z *.a *.d @@ -41,7 +40,6 @@ cataclysm-tiles cataclysm-tiles.exe.manifest cataclysm-vcpkg cataclysmdda-* -chkjson* debug.log logg.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index c38a126a9d33..700800055b7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -390,9 +390,7 @@ endif () add_subdirectory(src) add_subdirectory(data) add_subdirectory(lang) -if (NOT MSVC) - add_subdirectory(src/chkjson) -endif () + add_subdirectory(tests) if (JSON_FORMAT) add_subdirectory(tools/format) diff --git a/Makefile b/Makefile index 4a1bf0ec72bb..14f76f4dd1f7 100644 --- a/Makefile +++ b/Makefile @@ -163,7 +163,6 @@ else endif W32TILESTARGET = $(BUILD_PREFIX)$(TILES_TARGET_NAME).exe W32TARGET = $(BUILD_PREFIX)$(TARGET_NAME).exe -CHKJSON_BIN = $(BUILD_PREFIX)chkjson BINDIST_DIR = $(BUILD_PREFIX)bindist BUILD_DIR = $(CURDIR) SRC_DIR = src @@ -578,7 +577,6 @@ endif # Global settings for Windows targets ifeq ($(TARGETSYSTEM),WINDOWS) - CHKJSON_BIN = chkjson.exe TARGET = $(W32TARGET) BINDIST = $(W32BINDIST) BINDIST_CMD = $(W32BINDIST_CMD) @@ -802,7 +800,6 @@ HEADERS := $(wildcard $(SRC_DIR)/*.h) TESTSRC := $(wildcard tests/*.cpp) TESTHDR := $(wildcard tests/*.h) JSON_FORMATTER_SOURCES := tools/format/format.cpp src/json.cpp -CHKJSON_SOURCES := src/chkjson/chkjson.cpp src/json.cpp LUA_SOURCES := $(wildcard $(LUA_SRC_DIR)/*.c) CLANG_TIDY_PLUGIN_SOURCES := \ $(wildcard tools/clang-tidy-plugin/*.cpp tools/clang-tidy-plugin/*/*.cpp) @@ -814,7 +811,6 @@ ASTYLE_SOURCES := $(sort \ $(TESTSRC) \ $(TESTHDR) \ $(JSON_FORMATTER_SOURCES) \ - $(CHKJSON_SOURCES) \ $(CLANG_TIDY_PLUGIN_SOURCES) \ $(TOOLHDR)) @@ -961,19 +957,12 @@ src/version.cpp: src/version.h localization: lang/compile_mo.sh $(LANGUAGES) -$(CHKJSON_BIN): $(CHKJSON_SOURCES) - $(CXX) $(CXXFLAGS) $(TOOL_CXXFLAGS) -Isrc/chkjson -Isrc $(CHKJSON_SOURCES) -o $(CHKJSON_BIN) - -json-check: $(CHKJSON_BIN) - ./$(CHKJSON_BIN) - clean: clean-tests rm -rf *$(TARGET_NAME) *$(TILES_TARGET_NAME) rm -rf *$(TILES_TARGET_NAME).exe *$(TARGET_NAME).exe *$(TARGET_NAME).a rm -rf *obj *objwin rm -rf *$(BINDIST_DIR) *cataclysmbn-*.tar.gz *cataclysmbn-*.zip rm -f $(SRC_DIR)/version.h - rm -f $(CHKJSON_BIN) rm -f pch/*pch.hpp.gch rm -f pch/*pch.hpp.pch rm -f pch/*pch.hpp.d @@ -1222,7 +1211,6 @@ cmake-format: ./CMakeLists.txt \ ./data/CMakeLists.txt \ ./lang/CMakeLists.txt \ - ./src/chkjson/CMakeLists.txt \ ./src/CMakeLists.txt \ ./src/version.cmake \ ./tests/CMakeLists.txt \ diff --git a/build-scripts/build.sh b/build-scripts/build.sh index 20b89748c375..fbf51ab4f924 100755 --- a/build-scripts/build.sh +++ b/build-scripts/build.sh @@ -24,9 +24,6 @@ then make style-all-json-parallel RELEASE=1 tools/dialogue_validator.py data/json/npcs/* data/json/npcs/*/* data/json/npcs/*/*/* - # Also build chkjson (even though we're not using it), to catch any - # compile errors there - make -j "$num_jobs" chkjson elif [ -n "$JUST_JSON" ] then echo "Early exit on just-json change" diff --git a/src/chkjson/CMakeLists.txt b/src/chkjson/CMakeLists.txt deleted file mode 100644 index 198d403d26b2..000000000000 --- a/src/chkjson/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# JSON check utility -cmake_minimum_required(VERSION 3.16) - -set(CHKJSON_SOURCES ${CMAKE_SOURCE_DIR}/src/json.cpp ${CMAKE_SOURCE_DIR}/src/chkjson/chkjson.cpp) - -set(CHKJSON_HEADERS ${CMAKE_SOURCE_DIR}/src/json.h) - -# test chain -add_custom_target(check_json WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) - -add_custom_command( - TARGET check_json - PRE_BUILD - COMMAND chkjson - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) - -include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/chkjson) - -# Add the actual executable -if (WIN32) - add_executable(chkjson WIN32 EXCLUDE_FROM_ALL ${CHKJSON_SOURCES} ${CHKJSON_HEADERS}) -else () - add_executable(chkjson EXCLUDE_FROM_ALL ${CHKJSON_SOURCES} ${CHKJSON_HEADERS}) -endif () diff --git a/src/chkjson/chkjson.cpp b/src/chkjson/chkjson.cpp deleted file mode 100644 index 46d08471de32..000000000000 --- a/src/chkjson/chkjson.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* Main Loop for cataclysm - * Linux only I guess - * But maybe not - * Who knows - */ -#include -#include -#include -#include -#include // for strcmp -#include // for stack (obviously) -#include -#include -#include -#include // for throwing errors -#include -#include -#include - -#include "json.h" - -// copypasta: file_finder.cpp -static std::vector get_files_from_path( std::string extension, std::string root_path, - bool recursive_search, bool match_extension ) -{ - std::vector files; - const size_t extsz = extension.size(); - const char *c_extension = extension.c_str(); - // test for empty root path - if( root_path.empty() ) { - root_path = "."; - } - - std::stack directories, tempstack; - directories.push( root_path ); - std::string path; - - while( !directories.empty() ) { - path = directories.top(); - directories.pop(); - - DIR *root = opendir( path.c_str() ); - - if( root ) { - struct dirent *root_file; - struct stat _buff; - DIR *subdir; - - while( ( root_file = readdir( root ) ) ) { - // check to see if it is a folder! - if( stat( root_file->d_name, &_buff ) != 0x4 ) { - // ignore '.' and '..' folder names, which are current and parent folder relative paths - if( ( strcmp( root_file->d_name, "." ) != 0 ) && ( strcmp( root_file->d_name, ".." ) != 0 ) ) { - std::string subpath = path + "/" + root_file->d_name; - - if( recursive_search ) { - subdir = opendir( subpath.c_str() ); - if( subdir ) { - tempstack.push( subpath ); - closedir( subdir ); - } - } - } - } - // check to see if it is a file with the appropriate extension - std::string tmp = root_file->d_name; - if( tmp.find( c_extension, match_extension ? tmp.size() - extsz : 0 ) != std::string::npos ) { - std::string fullpath = path + "/" + tmp; - files.push_back( fullpath ); - } - } - closedir( root ); - } - // Directories are added to tempstack in A->Z order, which makes them pop from Z->A. This Makes sure that directories are - // searched in the proper order and that the final output is in the proper order. - while( !tempstack.empty() ) { - directories.push( tempstack.top() ); - tempstack.pop(); - } - } - return files; -} - -// copypasta: init.cpp -static void load_object( JsonObject &jo ) -{ - std::string type = jo.get_string( "type" ); - if( !jo.has_string( "type" ) ) { - jo.throw_error( "JSON object has no type" ); - } -} -static void load_all_from_json( JsonIn &jsin ) -{ - char ch; - jsin.eat_whitespace(); - // examine first non-whitespace char - ch = jsin.peek(); - if( ch == '{' ) { - // find type and dispatch single object - JsonObject jo = jsin.get_object(); - load_object( jo ); - jo.finish(); - // if there's anything else in the file, it's an error. - jsin.eat_whitespace(); - if( jsin.good() ) { - std::stringstream err; - err << "expected single-object file but found '"; - err << jsin.peek() << "'"; - jsin.error( err.str() ); - } - } else if( ch == '[' ) { - jsin.start_array(); - // find type and dispatch each object until array close - while( !jsin.end_array() ) { - jsin.eat_whitespace(); - ch = jsin.peek(); - if( ch != '{' ) { - std::stringstream err; - err << "expected array of objects but found '"; - err << ch << "', not '{'"; - jsin.error( err.str() ); - } - JsonObject jo = jsin.get_object(); - load_object( jo ); - jo.finish(); - } - } else { - // not an object or an array? - std::stringstream err; - err << "expected object or array, but found '" << ch << "'"; - jsin.error( err.str() ); - } -} - -static void load_json_dir( const std::string &dirname ) -{ - // get a list of all files in the directory - std::vector dir = - get_files_from_path( ".json", dirname, true, true ); - // iterate over each file - std::vector::iterator it; - for( it = dir.begin(); it != dir.end(); it++ ) { - // open the file as a stream - std::ifstream infile( it->c_str(), std::ifstream::in | std::ifstream::binary ); - // and stuff it into ram - std::istringstream iss( - std::string( - ( std::istreambuf_iterator( infile ) ), - std::istreambuf_iterator() - ) - ); - infile.close(); - // parse it - try { - JsonIn jsin( iss ); - load_all_from_json( jsin ); - } catch( const JsonError &err ) { - throw std::runtime_error( *( it ) + ": " + err.what() ); - } - } -} - -int main( int, char ** ) -{ - setlocale( LC_ALL, "" ); - try { - load_json_dir( "data/json" ); - } catch( const std::exception &err ) { - printf( "Error: %s\n", err.what() ); - return 1; - } - return 0; -}