summaryrefslogtreecommitdiff
path: root/hscript/script.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-08 19:55:53 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-08 19:55:53 -0500
commit5b0d0916b27f271fc12a8c0c6b595e11673d306d (patch)
treed8d2f3413caac49c1410c539b43be4630924666b /hscript/script.cc
parent57307442c5d707591dfc4d5e7671364fa564fa5c (diff)
downloadhorizon-5b0d0916b27f271fc12a8c0c6b595e11673d306d.tar.gz
horizon-5b0d0916b27f271fc12a8c0c6b595e11673d306d.tar.bz2
horizon-5b0d0916b27f271fc12a8c0c6b595e11673d306d.tar.xz
horizon-5b0d0916b27f271fc12a8c0c6b595e11673d306d.zip
hscript: Implement 'hostname' parsing; add rest of existing manual tests
Diffstat (limited to 'hscript/script.cc')
-rw-r--r--hscript/script.cc34
1 files changed, 23 insertions, 11 deletions
diff --git a/hscript/script.cc b/hscript/script.cc
index a8101dc..8c0c380 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -85,24 +85,36 @@ struct Script::ScriptPrivate {
*/
bool store_key(const std::string key_name, Keys::Key *key_obj, int lineno,
int *errors, int *warnings) {
+#define DUPLICATE_ERROR(OBJ, KEY, OLD_VAL) \
+ std::string err_str("previous value was ");\
+ err_str += OLD_VAL;\
+ err_str += " at installfile:" + std::to_string(OBJ->lineno());\
+ if(errors) *errors += 1;\
+ output_error("installfile:" + std::to_string(lineno),\
+ "duplicate value for key '" + KEY + "'", err_str);
+
if(key_name == "network") {
if(this->network) {
- std::string err_str("previous value was ");
- err_str += this->network->test() ? "true" : "false";
- err_str += " at installfile:";
- err_str += std::to_string(this->network->lineno());
- if(errors) *errors += 1;
- output_error("installfile:" + std::to_string(lineno),
- "duplicate value for key 'network'",
- err_str);
+ DUPLICATE_ERROR(this->network, std::string("network"),
+ this->network->test() ? "true" : "false")
return false;
}
- std::unique_ptr<Keys::Network> net(dynamic_cast<Keys::Network *>(key_obj));
+ std::unique_ptr<Keys::Network> net(
+ dynamic_cast<Keys::Network *>(key_obj)
+ );
this->network = std::move(net);
return true;
} else if(key_name == "hostname") {
- /*! TODO: implement */
- return false;
+ if(this->hostname) {
+ DUPLICATE_ERROR(this->hostname, std::string("hostname"),
+ this->hostname->name())
+ return false;
+ }
+ std::unique_ptr<Keys::Hostname> name(
+ dynamic_cast<Keys::Hostname *>(key_obj)
+ );
+ this->hostname = std::move(name);
+ return true;
} else if(key_name == "pkginstall") {
/*! TODO: implement */
return false;