Skip to content

Commit

Permalink
fix: Removes nohlman:json and use jsoncpp instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Tingan Ho committed Aug 24, 2017
1 parent 852837d commit 4e1a6bb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
6 changes: 2 additions & 4 deletions src/Program/CommandController.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@


#include <string>
#include <iostream>
#include "CommandParser.cpp"
#include "Configurations.h"
#include "Utils.cpp"
#include "json.hpp"
#include "Extension.cpp"
#include "ExtensionTestRunner.cpp"

using namespace std;
using json = nlohmann::json;

namespace L10ns {

Expand Down Expand Up @@ -50,7 +48,7 @@ void print_default_help_info() {
}

inline Command* get_command(CommandKind command) {
for (int i = 0; i < commands.size(); i++) {
for (unsigned int i = 0; i < commands.size(); i++) {
if (commands[i].kind == command) {
return &commands[i];
}
Expand Down
6 changes: 4 additions & 2 deletions src/Program/ExtensionTestRunner.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

#include "Types.cpp"
#include "Utils.cpp"
#include "json.hpp"
#include "Diagnostics.cpp"
#include "Extension.cpp"
#include "Core.cpp"
#include <signal.h>

using namespace L10ns;
using namespace TestFramework;
using json = nlohmann::json;

int child;

void kill_all_processes(int signum) {
#ifdef __unix__
kill(child, SIGTERM);
unlink("/tmp/l10ns.sock");
exit(signum);
#endif
}

void run_extension_tests(Session* session) {
Expand All @@ -25,12 +25,14 @@ void run_extension_tests(Session* session) {

auto start_extension_server = [&]() -> void {
extension = Extension::create(session, extension_file);
#ifdef __unix__
int fd[2];
pipe(fd);
child = extension->start_server(fd);
signal(SIGINT, kill_all_processes);
char buf[1];
read(fd[0], buf, 1);
#endif
};

auto for_each_compilation_test_file = [&](std::function<void (const string&)> callback) -> void {
Expand Down
4 changes: 1 addition & 3 deletions src/Program/Types.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@


#ifndef TYPES_H
#define TYPES_H

#include <string>
#include <Utils.cpp>
#include "json.hpp"

using namespace std;
using json = nlohmann::json;

enum class CommandKind {
None,
Expand Down
14 changes: 10 additions & 4 deletions src/Program/Utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


#ifndef UTILS_H
#define UTILS_H

Expand All @@ -8,7 +8,6 @@
#include <iostream>
#include <fstream>
#include <string>
#include <sys/ioctl.h>
#include <exception>
#include <boost/asio.hpp>
#include <boost/algorithm/string/replace.hpp>
Expand Down Expand Up @@ -56,14 +55,17 @@ void add_diagnostic(Session* session, DiagnosticTemplate* d, string arg1, string
string execute_command(const string command) {
char buffer[128];
string result = "";
#ifdef __unix__
shared_ptr<FILE> pipe(popen(command.c_str(), "r"), pclose);
if (!pipe) {
throw runtime_error("popen() failed!");
}
while (!feof(pipe.get())) {
if (fgets(buffer, 128, pipe.get()) != NULL)
if (fgets(buffer, 128, pipe.get()) != NULL) {
result += buffer;
}
}
#endif
return result;
}

Expand Down Expand Up @@ -157,16 +159,20 @@ class TextWriter {
this->window_width = *(int *)(getenv("COLUMNS"));
}
else {
#ifdef __unix__
struct winsize w;
ioctl(0, TIOCGWINSZ, &w);
this->window_width = w.ws_col;
#endif

}
}

private:
int window_width;
unsigned int column = 0;
unsigned int indentation = 0;

int indentation = 0;
static const unsigned int indentation_step = 2;

void print_indentation() {
Expand Down
13 changes: 7 additions & 6 deletions tasks/GenerateDiagnostics.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

#include "json.hpp"
#include "Utils.cpp"
#include "Configurations.h"
#include <string>
#include <iostream>
#include <boost/algorithm/string/replace.hpp>
#include <boost/regex.hpp>
#include <json/json.h>

using namespace std;
using namespace L10ns;
using json = nlohmann::json;

string output =
"// This code is auto generate. Don't edit!\n"
Expand Down Expand Up @@ -50,10 +49,12 @@ string remove_comments(string json) {

int main() {
string json = read_file(PROJECT_DIR "src/Program/Diagnostics.json");
auto diagnostics = json::parse(remove_comments(json));
for (json::iterator it = diagnostics.begin(); it != diagnostics.end(); ++it) {
string key = format_diagnostic_key(it.key());
output += " auto " + key + " = new DiagnosticTemplate(\"" + it.key() + "\");\n";
Json::Value diagnostics;
Json::Reader reader;
reader.parse(remove_comments(json).c_str(), diagnostics);
for (Json::ValueIterator it = diagnostics.begin(); it != diagnostics.end(); ++it) {
string key = format_diagnostic_key(it.key().as_string());
output += " auto " + key + " = new DiagnosticTemplate(\"" + key + "\");\n";
if (!is_unique(key)) {
throw invalid_argument("Duplicate formatted key: " + key + ".");
}
Expand Down

0 comments on commit 4e1a6bb

Please sign in to comment.