aboutsummaryrefslogtreecommitdiff
path: root/gui/debugger.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/debugger.cpp')
-rw-r--r--gui/debugger.cpp110
1 files changed, 87 insertions, 23 deletions
diff --git a/gui/debugger.cpp b/gui/debugger.cpp
index 216bd626fe..c9b435963d 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,37 @@ 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++;
+
+ // This won't always use all available columns, but even if it did the
+ // number of lines should be the same so that's good enough.
+ 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 +491,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;
@@ -522,11 +558,25 @@ struct ArchiveMemberLess {
bool Debugger::cmdMd5(int argc, const char **argv) {
if (argc < 2) {
- debugPrintf("md5 <filename | pattern>\n");
+ debugPrintf("md5 [-n length] <filename | pattern>\n");
} else {
+ uint32 length = 0;
+ uint paramOffset = 0;
+
+ // If the user supplied an -n parameter, set the bytes to read
+ if (!strcmp(argv[1], "-n")) {
+ // Make sure that we have at least two more parameters
+ if (argc < 4) {
+ debugPrintf("md5 [-n length] <filename | pattern>\n");
+ return true;
+ }
+ length = atoi(argv[2]);
+ paramOffset = 2;
+ }
+
// Assume that spaces are part of a single filename.
- Common::String filename = argv[1];
- for (int i = 2; i < argc; i++) {
+ Common::String filename = argv[1 + paramOffset];
+ for (int i = 2 + paramOffset; i < argc; i++) {
filename = filename + " " + argv[i];
}
Common::ArchiveMemberList list;
@@ -536,9 +586,9 @@ bool Debugger::cmdMd5(int argc, const char **argv) {
} else {
sort(list.begin(), list.end(), ArchiveMemberLess());
for (Common::ArchiveMemberList::iterator iter = list.begin(); iter != list.end(); ++iter) {
- Common::ReadStream *stream = (*iter)->createReadStream();
- Common::String md5 = Common::computeStreamMD5AsString(*stream, 0);
- debugPrintf("%s %s\n", md5.c_str(), (*iter)->getDisplayName().c_str());
+ Common::SeekableReadStream *stream = (*iter)->createReadStream();
+ Common::String md5 = Common::computeStreamMD5AsString(*stream, length);
+ debugPrintf("%s %s %d\n", md5.c_str(), (*iter)->getDisplayName().c_str(), stream->size());
delete stream;
}
}
@@ -548,11 +598,25 @@ bool Debugger::cmdMd5(int argc, const char **argv) {
bool Debugger::cmdMd5Mac(int argc, const char **argv) {
if (argc < 2) {
- debugPrintf("md5mac <base filename>\n");
+ debugPrintf("md5mac [-n length] <base filename>\n");
} else {
+ uint32 length = 0;
+ uint paramOffset = 0;
+
+ // If the user supplied an -n parameter, set the bytes to read
+ if (!strcmp(argv[1], "-n")) {
+ // Make sure that we have at least two more parameters
+ if (argc < 4) {
+ debugPrintf("md5mac [-n length] <base filename>\n");
+ return true;
+ }
+ length = atoi(argv[2]);
+ paramOffset = 2;
+ }
+
// Assume that spaces are part of a single filename.
- Common::String filename = argv[1];
- for (int i = 2; i < argc; i++) {
+ Common::String filename = argv[1 + paramOffset];
+ for (int i = 2 + paramOffset; i < argc; i++) {
filename = filename + " " + argv[i];
}
Common::MacResManager macResMan;
@@ -568,13 +632,13 @@ bool Debugger::cmdMd5Mac(int argc, const char **argv) {
} else {
// The resource fork is probably the most relevant one.
if (macResMan.hasResFork()) {
- Common::String md5 = macResMan.computeResForkMD5AsString(0);
- debugPrintf("%s %s (resource)\n", md5.c_str(), macResMan.getBaseFileName().c_str());
+ Common::String md5 = macResMan.computeResForkMD5AsString(length);
+ debugPrintf("%s %s (resource) %d\n", md5.c_str(), macResMan.getBaseFileName().c_str(), macResMan.getResForkDataSize());
}
if (macResMan.hasDataFork()) {
- Common::ReadStream *stream = macResMan.getDataFork();
- Common::String md5 = Common::computeStreamMD5AsString(*stream, 0);
- debugPrintf("%s %s (data)\n", md5.c_str(), macResMan.getBaseFileName().c_str());
+ Common::SeekableReadStream *stream = macResMan.getDataFork();
+ Common::String md5 = Common::computeStreamMD5AsString(*stream, length);
+ debugPrintf("%s %s (data) %d\n", md5.c_str(), macResMan.getBaseFileName().c_str(), stream->size());
}
}
macResMan.close();