diff options
author | Johannes Schickel | 2006-02-14 23:31:25 +0000 |
---|---|---|
committer | Johannes Schickel | 2006-02-14 23:31:25 +0000 |
commit | 0bea9cf47b027ad8936751f48779046ca0a48bf9 (patch) | |
tree | 3a1f55143f6aefa46367c93ecb97523d87c2c439 /common/util.cpp | |
parent | fc3cdbe5a9ff5feb4c765410d89b378fbf9daf68 (diff) | |
download | scummvm-rg350-0bea9cf47b027ad8936751f48779046ca0a48bf9.tar.gz scummvm-rg350-0bea9cf47b027ad8936751f48779046ca0a48bf9.tar.bz2 scummvm-rg350-0bea9cf47b027ad8936751f48779046ca0a48bf9.zip |
Made the kyra debug extensions more generic, i.e. scumm engine could replace
their debugC calls now with the new introduced debugC calls.
(A mail how to use it will follow shortly on -devel)
Also now these special engine debug flags can be specified from the commandline.
Also made the -c & --config parameter check more secure.
svn-id: r20695
Diffstat (limited to 'common/util.cpp')
-rw-r--r-- | common/util.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/common/util.cpp b/common/util.cpp index d98d8eb275..0502b562f2 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -275,5 +275,82 @@ const char *getRenderModeDescription(RenderMode id) { return 0; } +#pragma mark - + +Array<EngineDebugLevel> gDebugLevels; +uint32 gDebugLevelsEnabled = 0; + +bool addSpecialDebugLevel(uint32 level, const String &option, const String &description) { + for (uint i = 0; i < gDebugLevels.size(); ++i) { + if (!scumm_stricmp(option.c_str(), gDebugLevels[i].option.c_str())) { + warning("Declared engine debug level '%s' again", option.c_str()); + gDebugLevels[i] = EngineDebugLevel(level, option, description); + return true; + } + } + gDebugLevels.push_back(EngineDebugLevel(level, option, description)); + return true; +} + +void clearAllSpecialDebugLevels() { + gDebugLevelsEnabled = 0; + gDebugLevels.clear(); +} + +bool enableSpecialDebugLevel(const String &option) { + for (uint i = 0; i < gDebugLevels.size(); ++i) { + if (!scumm_stricmp(option.c_str(), gDebugLevels[i].option.c_str())) { + gDebugLevelsEnabled |= gDebugLevels[i].level; + gDebugLevels[i].enabled = true; + return true; + } + } + return false; +} + +void enableSpecialDebugLevelList(const String &option) { + uint start = 0; + uint end = 0; + + const char *str = option.c_str(); + for (end = start + 1; end <= option.size(); ++end) { + if (str[end] == ',' || end == option.size()) { + if (!enableSpecialDebugLevel(Common::String(&str[start], end-start))) { + warning("Engine does not support debug level '%s'", Common::String(&str[start], end-start).c_str()); + } + start = end + 1; + } + } +} + +bool disableSpecialDebugLevel(const String &option) { + for (uint i = 0; i < gDebugLevels.size(); ++i) { + if (!scumm_stricmp(option.c_str(), gDebugLevels[i].option.c_str())) { + gDebugLevelsEnabled &= ~gDebugLevels[i].level; + gDebugLevels[i].enabled = false; + return true; + } + } + return false; +} + +const Array<EngineDebugLevel> &listSpecialDebugLevels() { + return gDebugLevels; +} } // End of namespace Common + +void CDECL debugC(int level, uint32 engine_level, const char *s, ...) { + char buf[STRINGBUFLEN]; + va_list va; + + if (level > gDebugLevel || !(Common::gDebugLevelsEnabled & engine_level)) + return; + + va_start(va, s); + vsnprintf(buf, STRINGBUFLEN, s, va); + va_end(va); + + // pass it to debug for now + debug(level, buf); +} |