diff options
-rw-r--r-- | gui/debugger.cpp | 53 | ||||
-rw-r--r-- | gui/debugger.h | 5 |
2 files changed, 49 insertions, 9 deletions
diff --git a/gui/debugger.cpp b/gui/debugger.cpp index 466681e89d..209a787be8 100644 --- a/gui/debugger.cpp +++ b/gui/debugger.cpp @@ -87,6 +87,19 @@ Debugger::~Debugger() { // Initialisation Functions +int Debugger::getCharsPerLine() { +#ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER + const int charsPerLine = _debuggerDialog->getCharsPerLine(); +#elif defined(USE_READLINE) + int charsPerLine, rows; + rl_get_screen_size(&rows, &charsPerLine); +#else + // Can we do better? + const int charsPerLine = 80; +#endif + return charsPerLine; +} + int Debugger::debugPrintf(const char *format, ...) { va_list argptr; @@ -101,6 +114,36 @@ int Debugger::debugPrintf(const char *format, ...) { return count; } +void Debugger::debugPrintColumns(const Common::StringArray &list) { + uint maxLength = 0; + uint i, j; + + for (i = 0; i < list.size(); i++) { + if (list[i].size() > maxLength) + maxLength = list[i].size(); + } + + uint charsPerLine = getCharsPerLine(); + uint columnWidth = maxLength + 2; + uint columns = charsPerLine / columnWidth; + + uint lines = list.size() / columns; + + if (list.size() % columns) + lines++; + + + for (i = 0; i < lines; i++) { + for (j = 0; j < columns; j++) { + uint pos = i + j * lines; + if (pos < list.size()) { + debugPrintf("%*s", -columnWidth, list[pos].c_str()); + } + } + debugPrintf("\n"); + } +} + void Debugger::preEnter() { g_engine->pauseEngine(true); } @@ -447,15 +490,7 @@ bool Debugger::cmdExit(int argc, const char **argv) { // Print a list of all registered commands (and variables, if any), // nicely word-wrapped. bool Debugger::cmdHelp(int argc, const char **argv) { -#ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER - const int charsPerLine = _debuggerDialog->getCharsPerLine(); -#elif defined(USE_READLINE) - int charsPerLine, rows; - rl_get_screen_size(&rows, &charsPerLine); -#else - // Can we do better? - const int charsPerLine = 80; -#endif + const int charsPerLine = getCharsPerLine(); int width, size; uint i; diff --git a/gui/debugger.h b/gui/debugger.h index ef6f900974..bc9306c1de 100644 --- a/gui/debugger.h +++ b/gui/debugger.h @@ -28,6 +28,7 @@ #include "common/hashmap.h" #include "common/hash-str.h" #include "common/array.h" +#include "common/str-array.h" namespace GUI { @@ -40,8 +41,12 @@ public: Debugger(); virtual ~Debugger(); + int getCharsPerLine(); + int debugPrintf(const char *format, ...) GCC_PRINTF(2, 3); + void debugPrintColumns(const Common::StringArray &list); + /** * The onFrame() method should be invoked by the engine at regular * intervals (usually once per main loop iteration) whenever the |