From 8f14d83955bfe03393065ed731792a783460e0b8 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 14 May 2014 00:05:22 -0400 Subject: [PATCH] Hooks - Implemented ::onExit. --- src/Hooks.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 8495d0a30..1884e9100 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -119,18 +119,23 @@ void Hooks::onExit () std::vector ::iterator i; for (i = _scripts.begin (); i != _scripts.end (); ++i) { - if (i->substr (0, 7) == "on-exit") + if (i->find ("/on-exit") != std::string::npos) { File script (*i); if (script.executable ()) { - // TODO Call all exit 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 + for (line = lines.begin (); line != lines.end (); ++line) + if (status == 0) + context.footnote (*line); + else + context.error (*line); } } }