From d04c7a58aa5d72f62f49c5c3246d5e5c0af8920a Mon Sep 17 00:00:00 2001 From: Martin Kiewitz Date: Sat, 22 May 2010 21:46:40 +0000 Subject: SCI: adding ability to specify hexadecimal number as index for debug command vmvars - also report error if invalid index is given to us svn-id: r49148 --- engines/sci/console.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 16bc69115f..540b7c84d8 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -1762,7 +1762,7 @@ bool Console::cmdVMVars(int argc, const char **argv) { const char *varabbrev = "gltp"; const char *vartype_pre = strchr(varabbrev, *argv[1]); int vartype; - int idx = atoi(argv[2]); + int idx; if (!vartype_pre) { DebugPrintf("Invalid variable type '%c'\n", *argv[1]); @@ -1771,6 +1771,26 @@ bool Console::cmdVMVars(int argc, const char **argv) { vartype = vartype_pre - varabbrev; + char *endPtr = 0; + int idxLen = strlen(argv[2]); + const char *lastChar = argv[2] + idxLen - (idxLen == 0 ? 0 : 1); + + if ((strncmp(argv[2], "0x", 2) == 0) || (*lastChar == 'h')) { + // hexadecimal number + idx = strtol(argv[2], &endPtr, 16); + if ((*endPtr != 0) && (*endPtr != 'h')) { + DebugPrintf("Invalid hexadecimal index '%s'\n", argv[2]); + return true; + } + } else { + // decimal number + idx = strtol(argv[2], &endPtr, 10); + if (*endPtr != 0) { + DebugPrintf("Invalid decimal index '%s'\n", argv[2]); + return true; + } + } + if (idx < 0) { DebugPrintf("Invalid: negative index\n"); return true; -- cgit v1.2.3