chore: format code

This commit is contained in:
LordMZTE 2022-11-09 22:02:26 +01:00
parent 8d2041e946
commit 10adb7a9b2
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
15 changed files with 335 additions and 298 deletions

14
.astylerc Normal file
View file

@ -0,0 +1,14 @@
--style=attach
--indent-switches
--indent-namespaces
--indent-after-parens
--indent-col1-comments
--break-blocks
--pad-oper
--pad-header
--unpad-paren
--break-one-line-headers
--convert-tabs
--max-code-length=90
--break-after-logical
--lineend=linux

View file

@ -17,6 +17,7 @@ void sendMsg(int msqid, data::RequestMapMsg *msg) {
std::string recvMsg(int msqid) {
data::ResponseMapMsg msg;
if (msgrcv(msqid, &msg, sizeof(data::ResponseMapMsg) - sizeof(long),
data::clientbound_msg, 0) < 0) {
throw std::runtime_error(std::string("receive error ") + strerror(errno));

View file

@ -12,6 +12,7 @@ void readCSVRow(const std::string &row, std::vector<std::string> &fields) {
fields.push_back("");
CSVState state = CSVState::UnquotedField;
size_t i = 0; // index of the current field
for (char c : row) {
switch (state) {
case CSVState::UnquotedField:
@ -20,24 +21,31 @@ void readCSVRow(const std::string &row, std::vector<std::string> &fields) {
fields.push_back("");
i++;
break;
case '"':
state = CSVState::QuotedField;
break;
default:
fields[i].push_back(c);
break;
}
break;
case CSVState::QuotedField:
switch (c) {
case '"':
state = CSVState::QuotedQuote;
break;
default:
fields[i].push_back(c);
break;
}
break;
case CSVState::QuotedQuote:
switch (c) {
case ',': // , after closing quote
@ -45,20 +53,24 @@ void readCSVRow(const std::string &row, std::vector<std::string> &fields) {
i++;
state = CSVState::UnquotedField;
break;
case '"': // "" -> "
fields[i].push_back('"');
state = CSVState::QuotedField;
break;
default: // end of quote
state = CSVState::UnquotedField;
break;
}
break;
}
}
}
bool CsvReader::operator>>(std::vector<std::string> &line) {
line.clear();
if (!m_stream) {
return false;
}

View file

@ -24,6 +24,7 @@ Mappings Mappings::load() {
// load mappings
fs::directory_iterator end_itr;
try {
for (fs::directory_iterator itr("mappings"); itr != end_itr; ++itr) {
if (fs::is_directory(itr->status()) ||
@ -33,13 +34,16 @@ Mappings Mappings::load() {
csv::CsvReader csv(itr->path().string());
std::vector<std::string> l;
while (csv >> l) {
if (l.size() < 2) {
BOOST_LOG_TRIVIAL(warning) << "found invalid mapping";
continue;
}
mappings[l[0]] = {l[0], l[1],
l.size() >= 4 ? std::optional(l[3]) : std::nullopt};
l.size() >= 4 ? std::optional(l[3]) : std::nullopt
};
}
}
} catch (boost::filesystem::filesystem_error &e) {
@ -47,6 +51,7 @@ Mappings Mappings::load() {
throw std::runtime_error(
std::string("The mappings directory is missing!\n") + e.what());
}
throw;
}
@ -54,6 +59,7 @@ Mappings Mappings::load() {
csv::CsvReader csv("renames.csv");
std::vector<std::string> l;
while (csv >> l) {
if (l.size() < 2) {
BOOST_LOG_TRIVIAL(warning) << "found invalid rename";
@ -75,6 +81,7 @@ void showMapInfo(Mapping mapping, std::optional<std::string> rename) {
auto doc = mapping.doc.has_value()
? std::string(ansi::yellow) + "\n\n\t" + *mapping.doc + "\n"
: "";
if (rename.has_value()) {
BOOST_LOG_TRIVIAL(info)
<< "\nFound mapping:\n"

View file

@ -21,8 +21,10 @@ std::string resolve(std::string inp) {
}
std::string path_component;
for (unsigned int i = 3; i < components.size(); i++) {
path_component += components[i];
if (i != components.size() - 1) {
path_component += "/";
}

View file

@ -36,6 +36,7 @@ void run(key_t key) {
auto mappings = mappings::Mappings::load();
data::RequestMapMsg msg;
for (;;) {
if (msgrcv(msqid, &msg, sizeof(data::RequestMapMsg) - sizeof(long),
data::serverbound_msg, 0) < 0) {