From d09a0791991266e20894b80c4819ce4926f66a00 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 30 Jan 2010 17:43:33 -0500 Subject: [PATCH] Enhancement - Hooks - Implemented a master switch rc.hooks=off that can shut off all hooks. Seems like a good idea. - Added support for 'hooks' and 'hook.*' as valid configuration entries. --- src/Config.cpp | 1 + src/Hooks.cpp | 67 +++++++++++++++++++++++++++---------------------- src/command.cpp | 5 ++-- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index dd1e0c5f9..75cb4da61 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -119,6 +119,7 @@ std::string Config::defaults = "complete.all.projects=no # Include old project names in 'projects' command\n" // TODO "complete.all.tags=no # Include old tag names in 'tags' command\n" // TODO "debug=no # Display diagnostics\n" + "hooks=off # Hook system master switch\n" "fontunderline=yes # Uses underlines rather than -------\n" "shell.prompt=task> # Prompt used by the shell command\n" // TODO "\n" diff --git a/src/Hooks.cpp b/src/Hooks.cpp index ec2e7020a..91e7212e4 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -89,46 +89,53 @@ void Hooks::initialize () api.initialize (); #endif - std::vector vars; - context.config.all (vars); - - std::vector ::iterator it; - for (it = vars.begin (); it != vars.end (); ++it) + // Allow a master switch to turn the whole thing off. + bool big_red_switch = context.config.getBoolean ("hooks"); + if (big_red_switch) { - std::string type; - std::string name; - std::string value; + std::vector vars; + context.config.all (vars); - // "." - Nibbler n (*it); - if (n.getUntil ('.', type) && - type == "hook" && - n.skip ('.') && - n.getUntilEOS (name)) + std::vector ::iterator it; + for (it = vars.begin (); it != vars.end (); ++it) { - std::string value = context.config.get (*it); - Nibbler n (value); + std::string type; + std::string name; + std::string value; - // : [, ...] - while (!n.depleted ()) + // "." + Nibbler n (*it); + if (n.getUntil ('.', type) && + type == "hook" && + n.skip ('.') && + n.getUntilEOS (name)) { - std::string file; - std::string function; - if (n.getUntil (':', file) && - n.skip (':') && - n.getUntil (',', function)) - { - context.debug (std::string ("Event '") + name + "' hooked by " + file + ", function " + function); - Hook h (name, Path::expand (file), function); - all.push_back (h); + std::string value = context.config.get (*it); + Nibbler n (value); - (void) n.skip (','); + // : [, ...] + while (!n.depleted ()) + { + std::string file; + std::string function; + if (n.getUntil (':', file) && + n.skip (':') && + n.getUntil (',', function)) + { + context.debug (std::string ("Event '") + name + "' hooked by " + file + ", function " + function); + Hook h (name, Path::expand (file), function); + all.push_back (h); + + (void) n.skip (','); + } + else + throw std::string ("Malformed hook definition '") + *it + "'"; } - else - throw std::string ("Malformed hook definition '") + *it + "'"; } } } + else + context.debug ("Hooks::initialize - hook system shut off"); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/command.cpp b/src/command.cpp index 0e3cfa8ea..7e7ec1940 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -671,7 +671,7 @@ int handleConfig (std::string &outs) "displayweeknumber echo.command fontunderline locking monthsperline nag " "next project shadow.command shadow.file shadow.notify weekstart editor " "import.synonym.id import.synonym.uuid complete.all.projects " - "complete.all.tags search.case.sensitive " + "complete.all.tags search.case.sensitive hooks " #ifdef FEATURE_SHELL "shell.prompt " #endif @@ -700,7 +700,8 @@ int handleConfig (std::string &outs) i->substr (0, 10) != "color.tag." && i->substr (0, 8) != "holiday." && i->substr (0, 7) != "report." && - i->substr (0, 6) != "alias.") + i->substr (0, 6) != "alias." && + i->substr (0, 5) != "hook.") { unrecognized.push_back (*i); }