mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-12-25 11:14:15 +01:00
Create jsonproc tool
Add custom function hooks to jsonproc Add jsonproc to build_tools.sh Newer g++
This commit is contained in:
parent
fe59902b8a
commit
483648e372
@ -22,9 +22,15 @@ install:
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-7
|
||||
env: _="Build"
|
||||
script:
|
||||
- ./build_tools.sh
|
||||
- ./build_tools.sh g++-7
|
||||
- make -j2 compare
|
||||
after_success:
|
||||
- .travis/calcrom/webhook.sh pokeemerald
|
||||
|
@ -9,3 +9,4 @@ make -C tools/ramscrgen CXX=${1:-g++}
|
||||
make -C tools/gbafix CXX=${1:-g++}
|
||||
make -C tools/mid2agb CXX=${1:-g++}
|
||||
make -C tools/mapjson CXX=${1:-g++}
|
||||
make -C tools/jsonproc CXX=${1:-g++}
|
||||
|
1
tools/jsonproc/.gitignore
vendored
Executable file
1
tools/jsonproc/.gitignore
vendored
Executable file
@ -0,0 +1 @@
|
||||
jsonproc
|
17
tools/jsonproc/Makefile
Executable file
17
tools/jsonproc/Makefile
Executable file
@ -0,0 +1,17 @@
|
||||
CXX := g++
|
||||
|
||||
CXXFLAGS := -Wall -std=c++11 -O2
|
||||
|
||||
INCLUDES := -I .
|
||||
|
||||
SRCS := jsonproc.cpp
|
||||
|
||||
HEADERS := jsonproc.h inja.hpp nlohmann/json.hpp
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
jsonproc: $(SRCS) $(HEADERS)
|
||||
$(CXX) $(CXXFLAGS) $(INCLUDES) $(SRCS) -o $@ $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) jsonproc jsonproc.exe
|
3396
tools/jsonproc/inja.hpp
Executable file
3396
tools/jsonproc/inja.hpp
Executable file
File diff suppressed because it is too large
Load Diff
91
tools/jsonproc/jsonproc.cpp
Executable file
91
tools/jsonproc/jsonproc.cpp
Executable file
@ -0,0 +1,91 @@
|
||||
// jsonproc.cpp
|
||||
|
||||
#include "jsonproc.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <string>
|
||||
using std::string;
|
||||
|
||||
#include <inja.hpp>
|
||||
using namespace inja;
|
||||
using json = nlohmann::json;
|
||||
|
||||
std::map<string, string> customVars;
|
||||
|
||||
void set_custom_var(string key, string value)
|
||||
{
|
||||
customVars[key] = value;
|
||||
}
|
||||
|
||||
string get_custom_var(string key)
|
||||
{
|
||||
return customVars[key];
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 4)
|
||||
FATAL_ERROR("USAGE: jsonproc <json-filepath> <template-filepath> <output-filepath>\n");
|
||||
|
||||
string jsonfilepath = argv[1];
|
||||
string templateFilepath = argv[2];
|
||||
string outputFilepath = argv[3];
|
||||
|
||||
Environment env;
|
||||
|
||||
// Add custom command callbacks.
|
||||
env.add_callback("doNotModifyHeader", 0, [jsonfilepath, templateFilepath](Arguments& args) {
|
||||
return "//\n// DO NOT MODIFY THIS FILE! IT IS AUTO-GENERATED FROM " + jsonfilepath +" and Inja template " + templateFilepath + "\n//\n";
|
||||
});
|
||||
|
||||
env.add_callback("setVar", 2, [=](Arguments& args) {
|
||||
string key = args.at(0)->get<string>();
|
||||
string value = args.at(1)->get<string>();
|
||||
set_custom_var(key, value);
|
||||
return "";
|
||||
});
|
||||
|
||||
env.add_callback("getVar", 1, [=](Arguments& args) {
|
||||
string key = args.at(0)->get<string>();
|
||||
return get_custom_var(key);
|
||||
});
|
||||
|
||||
env.add_callback("concat", 2, [](Arguments& args) {
|
||||
string first = args.at(0)->get<string>();
|
||||
string second = args.at(1)->get<string>();
|
||||
return first + second;
|
||||
});
|
||||
|
||||
env.add_callback("removePrefix", 2, [](Arguments& args) {
|
||||
string rawValue = args.at(0)->get<string>();
|
||||
string prefix = args.at(1)->get<string>();
|
||||
string::size_type i = rawValue.find(prefix);
|
||||
if (i != 0)
|
||||
return rawValue;
|
||||
|
||||
return rawValue.erase(0, prefix.length());
|
||||
});
|
||||
|
||||
// Add custom command callbacks.
|
||||
env.add_callback("removeSuffix", 2, [](Arguments& args) {
|
||||
string rawValue = args.at(0)->get<string>();
|
||||
string suffix = args.at(1)->get<string>();
|
||||
string::size_type i = rawValue.rfind(suffix);
|
||||
if (i == string::npos)
|
||||
return rawValue;
|
||||
|
||||
return rawValue.substr(0, i);
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
env.write_with_json_file(templateFilepath, jsonfilepath, outputFilepath);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
FATAL_ERROR("JSONPROC_ERROR: %s\n", e.what());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
32
tools/jsonproc/jsonproc.h
Executable file
32
tools/jsonproc/jsonproc.h
Executable file
@ -0,0 +1,32 @@
|
||||
// jsonproc.h
|
||||
|
||||
#ifndef JSONPROC_H
|
||||
#define JSONPROC_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
using std::fprintf; using std::exit;
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#define FATAL_ERROR(format, ...) \
|
||||
do \
|
||||
{ \
|
||||
fprintf(stderr, format, __VA_ARGS__); \
|
||||
exit(1); \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define FATAL_ERROR(format, ...) \
|
||||
do \
|
||||
{ \
|
||||
fprintf(stderr, format, ##__VA_ARGS__); \
|
||||
exit(1); \
|
||||
} while (0)
|
||||
|
||||
#endif // _MSC_VER
|
||||
|
||||
#endif // JSONPROC_H
|
20842
tools/jsonproc/nlohmann/json.hpp
Executable file
20842
tools/jsonproc/nlohmann/json.hpp
Executable file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user