From 398bec3dbe81170c576eae136e3d6450905f5403 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 14 May 2014 00:04:51 -0400 Subject: [PATCH] Hooks - Implemented ::onLaunch. --- src/Hooks.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index ca2671b10..8495d0a30 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -73,19 +73,30 @@ void Hooks::onLaunch () std::vector ::iterator i; for (i = _scripts.begin (); i != _scripts.end (); ++i) { - if (i->substr (0, 9) == "on-launch") + if (i->find ("/on-launch") != std::string::npos) { File script (*i); if (script.executable ()) { - // TODO Call all launch hook scripts. + std::string output; + int status = execute (*i, "", output); - // TODO On zero status: - // - all stdout --> context.footnote + std::vector lines; + split (lines, output, '\n'); + std::vector ::iterator line; - // TODO On non-zero status: - // - all stdout --> context.error - // - throw std::string ("Hook termination"); + if (status == 0) + { + for (line = lines.begin (); line != lines.end (); ++line) + context.header (*line); + } + else + { + for (line = lines.begin (); line != lines.end (); ++line) + context.error (*line); + + throw 0; // This is how hooks silently terminate processing. + } } } }