Skip to content

Commit

Permalink
COMMON: Handle boolean types in the debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegr committed Dec 5, 2011
1 parent 585bd7b commit 411892d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gui/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ bool Debugger::parseCommand(const char *inputOrig) {
*(int32 *)_dvars[i].variable = atoi(param[1]);
DebugPrintf("(int)%s = %d\n", param[0], *(int32 *)_dvars[i].variable);
break;
case DVAR_BOOL:
{
Common::String value = Common::String(param[1]);
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false") ||
value == "1" || value == "0") {
*(bool *)_dvars[i].variable = (value.equalsIgnoreCase("true") || value == "1");
DebugPrintf("(bool)%s = %s\n", param[0], *(bool *)_dvars[i].variable ? "true" : "false");
} else {
DebugPrintf("Invalid value for boolean variable. Valid values are \"true\", \"false\", \"1\", \"0\"");
}
}
break;
// Integer Array
case DVAR_INTARRAY: {
const char *chr = strchr(param[0], '[');
Expand Down Expand Up @@ -278,6 +290,9 @@ bool Debugger::parseCommand(const char *inputOrig) {
case DVAR_INT:
DebugPrintf("(int)%s = %d\n", param[0], *(const int32 *)_dvars[i].variable);
break;
case DVAR_BOOL:
DebugPrintf("(bool)%s = %s\n", param[0], *(const bool *)_dvars[i].variable ? "true" : "false");
break;
// Integer array
case DVAR_INTARRAY: {
const char *chr = strchr(param[0], '[');
Expand Down

2 comments on commit 411892d

@sev-
Copy link
Member

@sev- sev- commented on 411892d Dec 5, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to check beginning of the word, i.e. 't' or 'f', because I myself prefer one letter abbreviations of those

@lordhoto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that, though we have "1" and "0" supported, thus we already have short aliases for ture and false.

In the meantime I changed the code to use parseBool to simplify it. If we want to do it with parseBool one might want to think about whether we want to allow these abbrevations in all cases where parseBool is used. If not we could add a third parameter with a default value of "false" which prevents checks for abbrevations. If we do on the other hand allow that, we could simply add the code to parseBool.

Please sign in to comment.