From 5b9413b02c5aa0379b73be4b8c27bd44eb4698b8 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 3 Jul 2014 19:04:48 -0400 Subject: [PATCH] Alias - Removal of alias load/resolve code, which (1) needs a rewrite, and (2) belongs in the Parser. --- src/Alias.cpp | 122 --------------------------------------------- src/Alias.h | 47 ----------------- src/CMakeLists.txt | 3 +- src/Context.cpp | 4 -- src/Context.h | 2 - 5 files changed, 1 insertion(+), 177 deletions(-) delete mode 100644 src/Alias.cpp delete mode 100644 src/Alias.h diff --git a/src/Alias.cpp b/src/Alias.cpp deleted file mode 100644 index 4bfdc4141..000000000 --- a/src/Alias.cpp +++ /dev/null @@ -1,122 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include // TODO Remove -#include -#include -#include -#include -#include -#include - -extern Context context; - -// Alias expansion limit. Any more indicates some kind of error. -const int safetyValveDefault = 10; - -//////////////////////////////////////////////////////////////////////////////// -Alias::Alias () -{ -} - -//////////////////////////////////////////////////////////////////////////////// -Alias::~Alias () -{ -} - -//////////////////////////////////////////////////////////////////////////////// -void Alias::load () -{ - _aliases.clear (); - - std::vector vars; - context.config.all (vars); - - std::vector ::iterator var; - for (var = vars.begin (); var != vars.end (); ++var) - if (var->substr (0, 6) == "alias.") - _aliases[var->substr (6)] = context.config.get (*var); -} - -//////////////////////////////////////////////////////////////////////////////// -// An alias must be a distinct word on the command line. -// -// TODO This is straight word substitution. What this really needs is node -// insertion, for more advanced aliases. -void Alias::resolve (Tree* tree) -{ - bool something; - int safety_valve = safetyValveDefault; - - do - { - something = false; - - std::string command; - std::vector ::iterator i; - for (i = tree->_branches.begin (); i != tree->_branches.end (); ++i) - { - // Parser override operator. - if ((*i)->attribute ("raw") == "--") - break; - - // Skip known args. - if (! (*i)->hasTag ("?")) - continue; - - std::map ::iterator a; - if ((*i)->_branches.size ()) - { - std::vector ::iterator b; - for (b = (*i)->_branches.begin (); b != (*i)->_branches.end (); ++b) - { - a = _aliases.find ((*b)->attribute ("raw")); - if (a != _aliases.end ()) - { - (*b)->attribute ("raw", a->second); - something = true; - } - } - } - else - { - a = _aliases.find ((*i)->attribute ("raw")); - if (a != _aliases.end ()) - { - (*i)->attribute ("raw", a->second); - something = true; - } - } - } - } - while (something && --safety_valve > 0); - - if (safety_valve <= 0) - context.debug (format ("Nested alias limit of {1} reached.", safetyValveDefault)); -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Alias.h b/src/Alias.h deleted file mode 100644 index 8fe2b387f..000000000 --- a/src/Alias.h +++ /dev/null @@ -1,47 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#ifndef INCLUDED_ALIAS -#define INCLUDED_ALIAS - -#include -#include -#include - -class Alias -{ -public: - Alias (); - ~Alias (); - void load (); - void resolve (Tree*); - -public: - std::map _aliases; -}; - -#endif - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 66c054ee0..0db4188ed 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,8 +5,7 @@ include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/columns ${TASK_INCLUDE_DIRS}) -set (task_SRCS Alias.cpp Alias.h - Color.cpp Color.h +set (task_SRCS Color.cpp Color.h Config.cpp Config.h Context.cpp Context.h DOM.cpp DOM.h diff --git a/src/Context.cpp b/src/Context.cpp index 69096413a..21083f169 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -144,10 +144,6 @@ int Context::initialize (int argc, const char** argv) parser.applyOverrides (); createDefaultConfig (); - // Handle Aliases. - alias.load (); - alias.resolve (parser.tree ()); - // Initialize the color rules, if necessary. if (color ()) initializeColorRules (); diff --git a/src/Context.h b/src/Context.h index 7f9c31501..0fc73be11 100644 --- a/src/Context.h +++ b/src/Context.h @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -89,7 +88,6 @@ public: Config config; TDB2 tdb2; - Alias alias; Hooks hooks; DOM dom;