From 01105c999b6ff14f8ba9dae9031c3adfc8391193 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Thu, 17 Oct 2019 21:12:42 -0500 Subject: hscript: Make dynamic_casts fit on a single line --- hscript/script.cc | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'hscript/script.cc') diff --git a/hscript/script.cc b/hscript/script.cc index 444b6c0..f45c5f2 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -88,12 +88,12 @@ struct Script::ScriptPrivate { /*! Store +key_obj+ representing the key +key_name+. * @param key_name The name of the key that is being stored. - * @param key_obj The Key object associated with the key. + * @param obj The Key object associated with the key. * @param errors Output parameter: if given, incremented on error. * @param warnings Output parameter: if given, incremented on warning. * @param opts Script parsing options. */ - bool store_key(const std::string key_name, Keys::Key *key_obj, int lineno, + bool store_key(const std::string key_name, Keys::Key *obj, int lineno, int *errors, int *warnings, ScriptOptions opts) { #define DUPLICATE_ERROR(OBJ, KEY, OLD_VAL) \ std::string err_str("previous value was ");\ @@ -103,15 +103,15 @@ struct Script::ScriptPrivate { output_error("installfile:" + std::to_string(lineno),\ "duplicate value for key '" + KEY + "'", err_str); + using namespace Horizon::Keys; + if(key_name == "network") { if(this->network) { DUPLICATE_ERROR(this->network, std::string("network"), this->network->test() ? "true" : "false") return false; } - std::unique_ptr net( - dynamic_cast(key_obj) - ); + std::unique_ptr net(dynamic_cast(obj)); this->network = std::move(net); return true; } else if(key_name == "hostname") { @@ -120,19 +120,17 @@ struct Script::ScriptPrivate { this->hostname->value()) return false; } - std::unique_ptr name( - dynamic_cast(key_obj) - ); + std::unique_ptr name(dynamic_cast(obj)); this->hostname = std::move(name); return true; } else if(key_name == "pkginstall") { - Keys::PkgInstall *install = dynamic_cast(key_obj); + PkgInstall *install = dynamic_cast(obj); for(auto &pkg : install->packages()) { if(opts.test(StrictMode) && packages.find(pkg) != packages.end()) { if(warnings) *warnings += 1; output_warning("installfile:" + std::to_string(lineno), - "package '" + pkg + "' has already been specified", - ""); + "pkginstall: package '" + pkg + + "' has already been specified"); continue; } packages.insert(pkg); @@ -145,33 +143,25 @@ struct Script::ScriptPrivate { "an encrypted passphrase") return false; } - std::unique_ptr name( - dynamic_cast(key_obj) + std::unique_ptr name( + dynamic_cast(obj) ); this->rootpw = std::move(name); return true; } else if(key_name == "mount") { - std::unique_ptr mount( - dynamic_cast(key_obj) - ); + std::unique_ptr mount(dynamic_cast(obj)); this->mounts.push_back(std::move(mount)); return true; } else if(key_name == "netaddress") { - std::unique_ptr addr( - dynamic_cast(key_obj) - ); + std::unique_ptr addr(dynamic_cast(obj)); this->addresses.push_back(std::move(addr)); return true; } else if(key_name == "netssid") { - std::unique_ptr ssid( - dynamic_cast(key_obj) - ); + std::unique_ptr ssid(dynamic_cast(obj)); this->ssids.push_back(std::move(ssid)); return true; } else if(key_name == "repository") { - std::unique_ptr repo( - dynamic_cast(key_obj) - ); + std::unique_ptr repo(dynamic_cast(obj)); this->repos.push_back(std::move(repo)); return true; } else { -- cgit v1.2.3-60-g2f50