From 7e1933d79bcdc6e34bb1fd6d0508b82ff4c3b3af Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sat, 2 Feb 2019 12:18:20 -0800 Subject: [PATCH] Give makerd a cwd argument, and upgrade cpptoml --- src/tools/makerd/cpptoml.h | 31 +++++++++++++++++++++---------- src/tools/makerd/main.cpp | 13 +++++++++++-- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/tools/makerd/cpptoml.h b/src/tools/makerd/cpptoml.h index db8ed69..5ad8120 100644 --- a/src/tools/makerd/cpptoml.h +++ b/src/tools/makerd/cpptoml.h @@ -4,8 +4,8 @@ * @date May 2013 */ -#ifndef _CPPTOML_H_ -#define _CPPTOML_H_ +#ifndef CPPTOML_H +#define CPPTOML_H #include #include @@ -84,11 +84,12 @@ class option return &value_; } - const T& value_or(const T& alternative) const + template + T value_or(U&& alternative) const { if (!empty_) return value_; - return alternative; + return static_cast(std::forward(alternative)); } private: @@ -2874,8 +2875,14 @@ class parser std::string::iterator find_end_of_date(std::string::iterator it, std::string::iterator end) { - return std::find_if(it, end, [](char c) { - return !is_number(c) && c != 'T' && c != ' ' && c != 'Z' && c != ':' + auto end_of_date = std::find_if(it, end, [](char c) { + return !is_number(c) && c != '-'; + }); + if (end_of_date != end && *end_of_date == ' ' && end_of_date + 1 != end + && is_number(end_of_date[1])) + end_of_date++; + return std::find_if(end_of_date, end, [](char c) { + return !is_number(c) && c != 'T' && c != 'Z' && c != ':' && c != '-' && c != '+' && c != '.'; }); } @@ -3097,8 +3104,11 @@ class parser throw_parse_exception("Unterminated inline table"); consume_whitespace(it, end); - parse_key_value(it, end, tbl.get()); - consume_whitespace(it, end); + if (it != end && *it != '}') + { + parse_key_value(it, end, tbl.get()); + consume_whitespace(it, end); + } } while (*it == ','); if (it == end || *it != '}') @@ -3435,7 +3445,7 @@ class toml_writer { res += "\\\\"; } - else if ((const uint32_t)*it <= 0x001f) + else if (static_cast(*it) <= UINT32_C(0x001f)) { res += "\\u"; std::stringstream ss; @@ -3655,4 +3665,5 @@ inline std::ostream& operator<<(std::ostream& stream, const array& a) return stream; } } // namespace cpptoml -#endif +#endif // CPPTOML_H + diff --git a/src/tools/makerd/main.cpp b/src/tools/makerd/main.cpp index c96d1ef..36e082b 100644 --- a/src/tools/makerd/main.cpp +++ b/src/tools/makerd/main.cpp @@ -3,14 +3,23 @@ #include #include #include + +#include #include "cpptoml.h" #include "initrd/headers.h" #include "entry.h" int main(int argc, char **argv) { - if (argc != 3) { - std::cerr << "Usage: " << argv[0] << " " << std::endl; + if (argc < 3 && argc > 4) { + std::cerr << "Usage: " << argv[0] << " [sourceroot]" << std::endl; + return 1; + } + + if (argc == 4 && chdir(argv[3]) != 0) { + std::cerr + << "Failed to change to " << argv[3] << ": " + << std::strerror(errno) << std::endl; return 1; }