From 02518e022345cbef51c294b1700a32e5657dab79 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 20 Jun 2009 10:54:01 -0400 Subject: [PATCH] Enhancement - debug support - Added debug=on support. - Added color.debug= support. --- src/Att.cpp | 16 ++++++---------- src/Context.cpp | 29 ++++++++++++++++++++--------- src/Context.h | 2 ++ src/TDB.cpp | 5 +++-- src/command.cpp | 18 +++++++++--------- src/main.h | 1 + src/rules.cpp | 15 +++++++++++++++ 7 files changed, 56 insertions(+), 30 deletions(-) diff --git a/src/Att.cpp b/src/Att.cpp index edd028a0f..f72af973b 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -63,21 +63,17 @@ static const char* modifiableNames[] = "until", }; +// Synonyms on the same line. static const char* modifierNames[] = { - "before", - "after", - "under", - "over", - "below", - "above", + "before", "under", "below", + "after", "over", "above", "none", "any", "is", - "isnt", - "has", + "isnt", "not", + "has", "contains", "hasnt", - "contains", "startswith", "endswith", }; @@ -486,7 +482,7 @@ bool Att::match (const Att& other) const } // isnt = not equal. - else if (mMod == "isnt") // TODO i18n + else if (mMod == "isnt" || mMod == "not") // TODO i18n { if (mValue == other.mValue) return false; diff --git a/src/Context.cpp b/src/Context.cpp index fb8b2ddb7..e61140251 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -146,6 +146,11 @@ int Context::run () message (stringtable.get (100, "Unknown error.")); } + // Dump all debug messages. + if (config.get ("debug", true)) + foreach (d, debugMessages) + std::cout << colorizeDebug (*d) << std::endl; + // Dump all headers. foreach (h, headers) std::cout << colorizeHeader (*h) << std::endl; @@ -367,7 +372,7 @@ void Context::parse ( // The '--' argument shuts off all parsing - everything is an argument. if (*arg == "--") { - header ("parse terminator '" + *arg + "'"); + debug ("parse terminator '" + *arg + "'"); terminated = true; } @@ -377,7 +382,7 @@ void Context::parse ( ! foundSomethingAfterSequence && parseSequence.valid (*arg)) { - header ("parse sequence '" + *arg + "'"); + debug ("parse sequence '" + *arg + "'"); parseSequence.parse (*arg); foundSequence = true; } @@ -387,7 +392,7 @@ void Context::parse ( (*arg)[0] == '+' && validTag (*arg)) { - header ("parse tag addition '" + *arg + "'"); + debug ("parse tag addition '" + *arg + "'"); if (foundSequence) foundSomethingAfterSequence = true; @@ -404,7 +409,7 @@ void Context::parse ( (*arg)[0] == '-' && validTag (*arg)) { - header ("parse tag removal '" + *arg + "'"); + debug ("parse tag removal '" + *arg + "'"); if (foundSequence) foundSomethingAfterSequence = true; @@ -418,7 +423,7 @@ void Context::parse ( // Atributes - name[.mod]:[value] else if (attribute.valid (*arg)) { - header ("parse attribute '" + *arg + "'"); + debug ("parse attribute '" + *arg + "'"); if (foundSequence) foundSomethingAfterSequence = true; @@ -456,7 +461,7 @@ void Context::parse ( if (foundSequence) foundSomethingAfterSequence = true; - header ("parse subst '" + *arg + "'"); + debug ("parse subst '" + *arg + "'"); parseSubst.parse (*arg); } @@ -464,7 +469,7 @@ void Context::parse ( else if (parseCmd.command == "" && parseCmd.valid (*arg)) { - header ("parse cmd '" + *arg + "'"); + debug ("parse cmd '" + *arg + "'"); parseCmd.parse (*arg); if (foundSequence) @@ -486,7 +491,7 @@ void Context::parse ( // terminated, therefore everything subsequently is a description. else { - header ("parse post-termination description '" + *arg + "'"); + debug ("parse post-termination description '" + *arg + "'"); if (foundSequence) foundSomethingAfterSequence = true; @@ -498,7 +503,7 @@ void Context::parse ( if (descCandidate != "" && noVerticalSpace (descCandidate)) { - header ("parse description '" + descCandidate + "'"); + debug ("parse description '" + descCandidate + "'"); parseTask.set ("description", descCandidate); } @@ -603,6 +608,12 @@ void Context::footnote (const std::string& input) footnotes.push_back (input); } +//////////////////////////////////////////////////////////////////////////////// +void Context::debug (const std::string& input) +{ + debugMessages.push_back (input); +} + //////////////////////////////////////////////////////////////////////////////// void Context::clearMessages () { diff --git a/src/Context.h b/src/Context.h index 5b891702e..4e35f5259 100644 --- a/src/Context.h +++ b/src/Context.h @@ -55,6 +55,7 @@ public: void header (const std::string&); // Header sink void message (const std::string&); // Message sink void footnote (const std::string&); // Footnote sink + void debug (const std::string&); // Debug message sink void clearMessages (); void parse (); @@ -83,6 +84,7 @@ private: std::vector headers; std::vector messages; std::vector footnotes; + std::vector debugMessages; bool inShadow; }; diff --git a/src/TDB.cpp b/src/TDB.cpp index 82451ded4..6fafe9d8c 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -389,8 +389,6 @@ int TDB::gc () { int count = 0; - context.header ("gc"); - // Set up a second TDB. Filter filter; TDB tdb; @@ -443,6 +441,9 @@ int TDB::gc () // Close files. tdb.unlock (); + std::stringstream s; + s << "gc " << count << " tasks"; + context.debug (s.str ()); return count; } diff --git a/src/command.cpp b/src/command.cpp index 181090346..037e113d9 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -380,15 +380,15 @@ std::string handleVersion () std::string recognized = " blanklines color color.active color.due color.overdue color.pri.H " "color.pri.L color.pri.M color.pri.none color.recurring color.tagged " - "color.footnote color.message confirmation curses data.location dateformat " - "default.command default.priority defaultwidth displayweeknumber due " - "echo.command locale locking monthsperline nag next project shadow.command " - "shadow.file shadow.notify weekstart editor import.synonym.id " - "import.synonym.uuid import.synonym.status import.synonym.tags " - "import.synonym.entry import.synonym.start import.synonym.due " - "import.synonym.recur import.synonym.end import.synonym.project " - "import.synonym.priority import.synonym.fg import.synonym.bg " - "import.synonym.description "; + "color.footnote color.header color.message color.debug confirmation curses " + "data.location dateformat default.command default.priority defaultwidth " + "displayweeknumber due echo.command locale locking monthsperline nag next " + "project shadow.command shadow.file shadow.notify weekstart editor " + "import.synonym.id import.synonym.uuid import.synonym.status " + "import.synonym.tags import.synonym.entry import.synonym.start " + "import.synonym.due import.synonym.recur import.synonym.end " + "import.synonym.project import.synonym.priority import.synonym.fg " + "import.synonym.bg import.synonym.description "; // This configuration variable is supported, but not documented. It exists // so that unit tests can force color to be on even when the output from task diff --git a/src/main.h b/src/main.h index 6c0f4d76c..7be5e98bd 100644 --- a/src/main.h +++ b/src/main.h @@ -105,6 +105,7 @@ void autoColorize (Task&, Text::color&, Text::color&); std::string colorizeHeader (const std::string&); std::string colorizeMessage (const std::string&); std::string colorizeFootnote (const std::string&); +std::string colorizeDebug (const std::string&); // import.cpp std::string handleImport (); diff --git a/src/rules.cpp b/src/rules.cpp index fa7e2004a..69df64245 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -281,4 +281,19 @@ std::string colorizeFootnote (const std::string& input) } //////////////////////////////////////////////////////////////////////////////// +std::string colorizeDebug (const std::string& input) +{ + if (gsFg["debug.footnote"] != Text::nocolor || + gsBg["debug.footnote"] != Text::nocolor) + { + return Text::colorize ( + gsFg["debug.footnote"], + gsBg["debug.footnote"], + input); + } + + return input; +} + +////////////////////////////////////////////////////////////////////////////////