From 658080deeda79d20ea40643569fbcb072573e7cf Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 28 Jan 2012 01:15:49 +0100 Subject: [PATCH 1/3] ALL: Avoid using is* macros from ctype.h On some systems, passing signed chars to macros like isspace() etc. lead to a runtime error. Hence, mark these macros as forbidden by default, and introduce otherwise equivalent alternatives for them. --- base/commandLine.cpp | 2 +- common/config-file.cpp | 6 ++-- common/config-manager.cpp | 6 ++-- common/forbidden.h | 43 +++++++++++++++++++++++++++ common/str.cpp | 8 ++--- common/util.cpp | 43 +++++++++++++++++++++++++++ common/util.h | 11 +++++++ common/xmlparser.cpp | 10 +++---- common/xmlparser.h | 2 +- engines/agi/agi.cpp | 14 +-------- engines/agi/wagparser.cpp | 4 +-- engines/agos/script_pn.cpp | 8 ++--- engines/agos/string.cpp | 2 +- engines/agos/string_pn.cpp | 2 +- engines/cge/text.cpp | 4 +-- engines/cine/detection.cpp | 2 +- engines/drascula/interface.cpp | 2 +- engines/hugo/util.cpp | 2 +- engines/kyra/gui.cpp | 2 +- engines/mohawk/livingbooks_code.cpp | 8 ++--- engines/parallaction/dialogue.cpp | 2 +- engines/parallaction/parser_br.cpp | 12 ++++---- engines/parallaction/parser_ns.cpp | 2 +- engines/queen/talk.cpp | 2 +- engines/saga/interface.cpp | 4 +-- engines/sci/engine/kstring.cpp | 6 ++-- engines/sci/graphics/text16.cpp | 2 +- engines/sci/parser/vocabulary.cpp | 2 +- engines/sci/resource.cpp | 4 +-- engines/sci/resource_audio.cpp | 2 +- engines/scumm/smush/smush_player.cpp | 4 +-- engines/scumm/string.cpp | 8 ++--- engines/sky/control.cpp | 2 +- engines/sky/detection.cpp | 2 +- engines/sword1/animation.cpp | 4 +-- engines/sword25/util/lua/lbaselib.cpp | 7 ++--- engines/sword25/util/lua/llex.cpp | 26 ++++++++-------- engines/sword25/util/lua/lobject.cpp | 8 ++--- engines/sword25/util/lua/lstrlib.cpp | 2 ++ graphics/font.cpp | 4 +-- gui/launcher.cpp | 2 +- 41 files changed, 183 insertions(+), 105 deletions(-) diff --git a/base/commandLine.cpp b/base/commandLine.cpp index c3059ced2f30..16a2b6f9f0c9 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -277,7 +277,7 @@ void registerDefaults() { // resp. between "--some-option" and "--no-some-option". #define DO_OPTION_BOOL(shortCmd, longCmd) \ if (isLongCmd ? (!strcmp(s+2, longCmd) || !strcmp(s+2, "no-"longCmd)) : (tolower(s[1]) == shortCmd)) { \ - bool boolValue = (islower(static_cast(s[1])) != 0); \ + bool boolValue = (isLower(s[1]) != 0); \ s += 2; \ if (isLongCmd) { \ boolValue = !strcmp(s, longCmd); \ diff --git a/common/config-file.cpp b/common/config-file.cpp index 81e0ae6b458d..4224d7491ded 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -30,7 +30,7 @@ namespace Common { bool ConfigFile::isValidName(const String &name) { const char *p = name.c_str(); - while (*p && (isalnum(static_cast(*p)) || *p == '-' || *p == '_' || *p == '.')) + while (*p && (isAlnum(*p) || *p == '-' || *p == '_' || *p == '.')) p++; return *p == 0; } @@ -108,7 +108,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { // is, verify that it only consists of alphanumerics, // periods, dashes and underscores). Mohawk Living Books games // can have periods in their section names. - while (*p && (isalnum(static_cast(*p)) || *p == '-' || *p == '_' || *p == '.')) + while (*p && (isAlnum(*p) || *p == '-' || *p == '_' || *p == '.')) p++; if (*p == '\0') @@ -131,7 +131,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { // Skip leading whitespaces const char *t = line.c_str(); - while (isspace(static_cast(*t))) + while (isSpace(*t)) t++; // Skip empty lines / lines with only whitespace diff --git a/common/config-manager.cpp b/common/config-manager.cpp index c62dee8bea78..d4035e8b9261 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -29,7 +29,7 @@ static bool isValidDomainName(const Common::String &domName) { const char *p = domName.c_str(); - while (*p && (isalnum(static_cast(*p)) || *p == '-' || *p == '_')) + while (*p && (isAlnum(*p) || *p == '-' || *p == '_')) p++; return *p == 0; } @@ -187,7 +187,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) { // Get the domain name, and check whether it's valid (that // is, verify that it only consists of alphanumerics, // dashes and underscores). - while (*p && (isalnum(static_cast(*p)) || *p == '-' || *p == '_')) + while (*p && (isAlnum(*p) || *p == '-' || *p == '_')) p++; if (*p == '\0') @@ -205,7 +205,7 @@ void ConfigManager::loadFromStream(SeekableReadStream &stream) { // Skip leading whitespaces const char *t = line.c_str(); - while (isspace(static_cast(*t))) + while (isSpace(*t)) t++; // Skip empty lines / lines with only whitespace diff --git a/common/forbidden.h b/common/forbidden.h index 8b5a2f738ea2..eec80bba590a 100644 --- a/common/forbidden.h +++ b/common/forbidden.h @@ -317,6 +317,49 @@ #endif // FORBIDDEN_SYMBOL_EXCEPTION_unistd_h + +// +// Disable various symbols from ctype.h +// +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_ctype_h + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isalnum + #undef isalnum + #define isalnum(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isalpha + #undef isalpha + #define isalpha(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isdigit + #undef isdigit + #define isdigit(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isnumber + #undef isnumber + #define isnumber(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_islower + #undef islower + #define islower(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isspace + #undef isspace + #define isspace(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isupper + #undef isupper + #define isupper(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + +#endif // FORBIDDEN_SYMBOL_EXCEPTION_ctype_h + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_mkdir #undef mkdir #define mkdir(a,b) FORBIDDEN_SYMBOL_REPLACEMENT diff --git a/common/str.cpp b/common/str.cpp index 32f4b44e798d..a48a290c0b28 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -405,13 +405,13 @@ void String::trim() { makeUnique(); // Trim trailing whitespace - while (_size >= 1 && isspace(static_cast(_str[_size - 1]))) + while (_size >= 1 && isSpace(_str[_size - 1])) --_size; _str[_size] = 0; // Trim leading whitespace char *t = _str; - while (isspace((unsigned char)*t)) + while (isSpace(*t)) t++; if (t != _str) { @@ -606,14 +606,14 @@ String operator+(const String &x, char y) { } char *ltrim(char *t) { - while (isspace(static_cast(*t))) + while (isSpace(*t)) t++; return t; } char *rtrim(char *t) { int l = strlen(t) - 1; - while (l >= 0 && isspace(static_cast(t[l]))) + while (l >= 0 && isSpace(t[l])) t[l--] = 0; return t; } diff --git a/common/util.cpp b/common/util.cpp index 1c4df8b6cd38..0a7d0f1e89d1 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -19,6 +19,15 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#define FORBIDDEN_SYMBOL_EXCEPTION_isalnum +#define FORBIDDEN_SYMBOL_EXCEPTION_isalpha +#define FORBIDDEN_SYMBOL_EXCEPTION_isdigit +#define FORBIDDEN_SYMBOL_EXCEPTION_isnumber +#define FORBIDDEN_SYMBOL_EXCEPTION_islower +#define FORBIDDEN_SYMBOL_EXCEPTION_isspace +#define FORBIDDEN_SYMBOL_EXCEPTION_isupper + + #include "common/util.h" #include "common/translation.h" #include "common/config-manager.h" @@ -407,3 +416,37 @@ void updateGameGUIOptions(const String &options, const String &langOption) { } } // End of namespace Common + + +// +// TODO: Instead of a blind cast, we might want to verify +// if c equals EOS; and/or is in the range -255..+255; +// and return false if it isn't. +// +bool isAlnum(int c) { + return isalnum((byte)c); +} + +bool isAlpha(int c) { + return isalpha((byte)c); +} + +bool isDigit(int c) { + return isdigit((byte)c); +} + +bool isNumber(int c) { + return isnumber((byte)c); +} + +bool isLower(int c) { + return islower((byte)c); +} + +bool isSpace(int c) { + return isspace((byte)c); +} + +bool isUpper(int c) { + return isupper((byte)c); +} diff --git a/common/util.h b/common/util.h index dfa57d725997..1df7bbb9c3ac 100644 --- a/common/util.h +++ b/common/util.h @@ -34,6 +34,17 @@ ((((size_t)value) & ((alignment) - 1)) == 0) +//namespace{ +bool isAlnum(int c); +bool isAlpha(int c); +bool isDigit(int c); +bool isNumber(int c); +bool isLower(int c); +bool isSpace(int c); +bool isUpper(int c); +//} + + #ifdef MIN #undef MIN #endif diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index f768e4438251..d37bfeb99a6b 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -263,7 +263,7 @@ bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) { int *num_ptr; while (count--) { - while (isspace(static_cast(*key))) + while (isSpace(*key)) key++; num_ptr = va_arg(args, int*); @@ -271,7 +271,7 @@ bool XMLParser::vparseIntegerKey(const char *key, int count, va_list args) { key = parseEnd; - while (isspace(static_cast(*key))) + while (isSpace(*key)) key++; if (count && *key++ != ',') @@ -463,10 +463,10 @@ bool XMLParser::parse() { } bool XMLParser::skipSpaces() { - if (!isspace(static_cast(_char))) + if (!isSpace(_char)) return false; - while (_char && isspace(static_cast(_char))) + while (_char && isSpace(_char)) _char = _stream->readByte(); return true; @@ -516,7 +516,7 @@ bool XMLParser::parseToken() { _char = _stream->readByte(); } - return isspace(static_cast(_char)) != 0 || _char == '>' || _char == '=' || _char == '/'; + return isSpace(_char) != 0 || _char == '>' || _char == '=' || _char == '/'; } } // End of namespace Common diff --git a/common/xmlparser.h b/common/xmlparser.h index 93433b71326c..81752543c25e 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -295,7 +295,7 @@ class XMLParser { * in their name. */ virtual inline bool isValidNameChar(char c) { - return isalnum(static_cast(c)) || c == '_'; + return isAlnum(c) || c == '_'; } /** diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp index 4ed606c3babf..e1c52c7c5e45 100644 --- a/engines/agi/agi.cpp +++ b/engines/agi/agi.cpp @@ -250,19 +250,7 @@ void AgiEngine::processEvents() { // Not a special key, so get the ASCII code for it key = event.kbd.ascii; - // Function isalpha is defined in so the following applies to it: - // - // The C Programming Language Standard states: - // The header declares several functions useful for classifying - // and mapping characters. In all cases the argument is an int, the value - // of which shall be representable as an unsigned char or shall equal the - // value of the macro EOF. If the argument has any other value, the - // behavior is undefined. - // - // For a concrete example (e.g. in Microsoft Visual Studio 2003): - // When used with a debug CRT library, isalpha will display a CRT assert - // if passed a parameter that isn't EOF or in the range of 0 through 0xFF. - if (key >= 0 && key <= 0xFF && isalpha(key)) { + if (isAlpha(key)) { // Key is A-Z. // Map Ctrl-A to 1, Ctrl-B to 2, etc. if (event.kbd.flags & Common::KBD_CTRL) { diff --git a/engines/agi/wagparser.cpp b/engines/agi/wagparser.cpp index 39f9e0dd92e9..00602420e2df 100644 --- a/engines/agi/wagparser.cpp +++ b/engines/agi/wagparser.cpp @@ -112,11 +112,11 @@ WagFileParser::~WagFileParser() { bool WagFileParser::checkAgiVersionProperty(const WagProperty &version) const { if (version.getCode() == WagProperty::PC_INTVERSION && // Must be AGI interpreter version property version.getSize() >= 3 && // Need at least three characters for a version number like "X.Y" - isdigit(static_cast(version.getData()[0])) && // And the first character must be a digit + isDigit(version.getData()[0]) && // And the first character must be a digit (version.getData()[1] == ',' || version.getData()[1] == '.')) { // And the second a comma or a period for (int i = 2; i < version.getSize(); i++) // And the rest must all be digits - if (!isdigit(static_cast(version.getData()[i]))) + if (!isDigit(version.getData()[i])) return false; // Bail out if found a non-digit after the decimal point return true; diff --git a/engines/agos/script_pn.cpp b/engines/agos/script_pn.cpp index 196350b9bfa6..70540343ed7a 100644 --- a/engines/agos/script_pn.cpp +++ b/engines/agos/script_pn.cpp @@ -466,8 +466,8 @@ void AGOSEngine_PN::opn_opcode35() { void AGOSEngine_PN::opn_opcode36() { for (int i = 0; i < _dataBase[57] + 1; ++i) _wordcp[i] = 0; - if (isspace(static_cast(*_inpp))) - while ((*_inpp) && (isspace(static_cast(*_inpp)))) + if (isSpace(*_inpp)) + while ((*_inpp) && (isSpace(*_inpp))) _inpp++; if (*_inpp == 0) { setScriptReturn(false); @@ -481,7 +481,7 @@ void AGOSEngine_PN::opn_opcode36() { } int ct = 1; - while ((*_inpp != '.') && (*_inpp != ',') && (!isspace(static_cast(*_inpp))) && (*_inpp != '\0') && + while ((*_inpp != '.') && (*_inpp != ',') && (!isSpace(*_inpp)) && (*_inpp != '\0') && (*_inpp!='"')) { if (ct < _dataBase[57]) _wordcp[ct++] = *_inpp; @@ -581,7 +581,7 @@ void AGOSEngine_PN::opn_opcode46() { return; } x++; - while ((*x != '.') && (*x != ',') && (*x != '"') && (!isspace(static_cast(*x))) && (*x != '\0')) + while ((*x != '.') && (*x != ',') && (*x != '"') && (!isSpace(*x)) && (*x != '\0')) pcf(*x++); setScriptReturn(true); } diff --git a/engines/agos/string.cpp b/engines/agos/string.cpp index 410fd5a1ce9b..4298ff615504 100644 --- a/engines/agos/string.cpp +++ b/engines/agos/string.cpp @@ -152,7 +152,7 @@ const byte *AGOSEngine::getStringPtrByID(uint16 stringId, bool upperCase) { } if (upperCase && *dst) { - if (islower(*dst)) + if (isLower(*dst)) *dst = toupper(*dst); } diff --git a/engines/agos/string_pn.cpp b/engines/agos/string_pn.cpp index ac8c263da390..8f31da6f587f 100644 --- a/engines/agos/string_pn.cpp +++ b/engines/agos/string_pn.cpp @@ -137,7 +137,7 @@ void AGOSEngine_PN::pcf(uint8 ch) { if ((ch != 32) || (_bp + _xofs != 50)) _buffer[_bp++] = ch; } - if ((ch != 254) && (!isspace(ch)) && (_bp < 60)) + if ((ch != 254) && (!isSpace(ch)) && (_bp < 60)) return; /* We know have a case of needing to print the text */ if (_bp + _xofs > 50) { diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 331dc8ac2da7..9fb3c95e9387 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -72,7 +72,7 @@ int16 Text::count() { strcpy(tmpStr, line.c_str()); if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL) continue; - if (!isdigit(*s)) + if (!isDigit(*s)) continue; counter++; @@ -105,7 +105,7 @@ void Text::load() { strcpy(tmpStr, line.c_str()); if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL) continue; - if (!isdigit(*s)) + if (!isDigit(*s)) continue; int r = atoi(s); diff --git a/engines/cine/detection.cpp b/engines/cine/detection.cpp index ed656682eeb6..65b2285f11ea 100644 --- a/engines/cine/detection.cpp +++ b/engines/cine/detection.cpp @@ -141,7 +141,7 @@ SaveStateList CineMetaEngine::listSaves(const char *target) const { for (file = filenames.begin(); file != filenames.end(); ++file) { // Jump over savegame files that don't end with a digit (e.g. "fw.3" is ok, "fw.a" is not). - if (!isdigit(static_cast(file->lastChar()))) + if (!isDigit(file->lastChar())) continue; // Obtain the last digit of the filename, since they correspond to the save slot diff --git a/engines/drascula/interface.cpp b/engines/drascula/interface.cpp index 5e4f7a154167..c08bcea01f75 100644 --- a/engines/drascula/interface.cpp +++ b/engines/drascula/interface.cpp @@ -168,7 +168,7 @@ void DrasculaEngine::enterName() { key = getScan(); if (key != 0) { - if (key >= 0 && key <= 0xFF && isalpha(static_cast(key))) + if (key >= 0 && key <= 0xFF && isAlpha(key)) select2[v] = tolower(key); else if ((key >= Common::KEYCODE_0 && key <= Common::KEYCODE_9) || key == Common::KEYCODE_SPACE) select2[v] = key; diff --git a/engines/hugo/util.cpp b/engines/hugo/util.cpp index 6dc9890c3aa1..1428fc93a30e 100644 --- a/engines/hugo/util.cpp +++ b/engines/hugo/util.cpp @@ -119,7 +119,7 @@ char *strlwr(char *buffer) { char *result = buffer; while (*buffer != '\0') { - if (isupper(static_cast(*buffer))) + if (isUpper(*buffer)) *buffer = tolower(*buffer); buffer++; } diff --git a/engines/kyra/gui.cpp b/engines/kyra/gui.cpp index 9e08ae0fb9cb..07d8b307f3af 100644 --- a/engines/kyra/gui.cpp +++ b/engines/kyra/gui.cpp @@ -56,7 +56,7 @@ void GUI::updateSaveFileList(Common::String targetName, bool excludeQuickSaves) s1 = (*i)[i->size() - 3]; s2 = (*i)[i->size() - 2]; s3 = (*i)[i->size() - 1]; - if (!isdigit(static_cast(s1)) || !isdigit(static_cast(s2)) || !isdigit(static_cast(s3))) + if (!isDigit(s1) || !isDigit(s2) || !isDigit(s3)) continue; s1 -= '0'; s2 -= '0'; diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp index 41acea19c4d9..b961e20f7875 100644 --- a/engines/mohawk/livingbooks_code.cpp +++ b/engines/mohawk/livingbooks_code.cpp @@ -1766,7 +1766,7 @@ uint LBCode::parseCode(const Common::String &source) { { Common::String tempString; while (pos < source.size()) { - if (!isalpha(source[pos]) && !isdigit(source[pos])) + if (!isAlpha(source[pos]) && !isDigit(source[pos])) break; tempString += source[pos++]; } @@ -1777,7 +1777,7 @@ uint LBCode::parseCode(const Common::String &source) { } break; default: - if (isdigit(token)) { + if (isDigit(token)) { const char *in = source.c_str() + pos - 1; // FIXME: handle floats? char *endptr; @@ -1792,11 +1792,11 @@ uint LBCode::parseCode(const Common::String &source) { WRITE_BE_UINT16(tmp, (int16)intValue); code.push_back(tmp[0]); code.push_back(tmp[1]); - } else if (isalpha(token)) { + } else if (isAlpha(token)) { Common::String tempString; tempString += token; while (pos < source.size()) { - if (!isalpha(source[pos]) && !isdigit(source[pos])) + if (!isAlpha(source[pos]) && !isDigit(source[pos])) break; tempString += source[pos++]; } diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp index a908152bf863..3bb4404b98bc 100644 --- a/engines/parallaction/dialogue.cpp +++ b/engines/parallaction/dialogue.cpp @@ -381,7 +381,7 @@ class DialogueManager_ns : public DialogueManager { } void accumPassword(uint16 ascii) { - if (!isdigit(ascii)) { + if (!isDigit(ascii)) { return; } diff --git a/engines/parallaction/parser_br.cpp b/engines/parallaction/parser_br.cpp index df53ecca3f0d..fb6a4102d199 100644 --- a/engines/parallaction/parser_br.cpp +++ b/engines/parallaction/parser_br.cpp @@ -524,14 +524,14 @@ DECLARE_COMMAND_PARSER(location) { ctxt.cmd->_startPos.x = -1000; ctxt.cmd->_startPos2.x = -1000; if (_tokens[ctxt.nextToken][0] != '\0') { - if (isdigit(static_cast(_tokens[ctxt.nextToken][0])) || _tokens[ctxt.nextToken][0] == '-') { + if (isDigit(_tokens[ctxt.nextToken][0]) || _tokens[ctxt.nextToken][0] == '-') { ctxt.cmd->_startPos.x = atoi(_tokens[ctxt.nextToken]); ctxt.nextToken++; ctxt.cmd->_startPos.y = atoi(_tokens[ctxt.nextToken]); ctxt.nextToken++; } - if (isdigit(static_cast(_tokens[ctxt.nextToken][0])) || _tokens[ctxt.nextToken][0] == '-') { + if (isDigit(_tokens[ctxt.nextToken][0]) || _tokens[ctxt.nextToken][0] == '-') { ctxt.cmd->_startPos2.x = atoi(_tokens[ctxt.nextToken]); ctxt.nextToken++; ctxt.cmd->_startPos2.y = atoi(_tokens[ctxt.nextToken]); @@ -677,7 +677,7 @@ DECLARE_COMMAND_PARSER(text) { createCommand(_parser->_lookup); - if (isdigit(static_cast(_tokens[1][1]))) { + if (isDigit(_tokens[1][1])) { ctxt.cmd->_zeta0 = atoi(_tokens[1]); ctxt.nextToken++; } else { @@ -714,7 +714,7 @@ DECLARE_COMMAND_PARSER(unary) { DECLARE_ZONE_PARSER(limits) { debugC(7, kDebugParser, "ZONE_PARSER(limits) "); - if (isalpha(static_cast(_tokens[1][1]))) { + if (isAlpha(_tokens[1][1])) { ctxt.z->_flags |= kFlagsAnimLinked; ctxt.z->_linkedName = _tokens[1]; } else { @@ -1003,7 +1003,7 @@ DECLARE_INSTRUCTION_PARSER(text) { int _si = 1; - if (isdigit(static_cast(_tokens[1][1]))) { + if (isDigit(_tokens[1][1])) { ctxt.inst->_y = atoi(_tokens[1]); _si = 2; } else { @@ -1066,7 +1066,7 @@ DECLARE_INSTRUCTION_PARSER(endif) { void ProgramParser_br::parseRValue(ScriptVar &v, const char *str) { - if (isdigit(static_cast(str[0])) || str[0] == '-') { + if (isDigit(str[0]) || str[0] == '-') { v.setImmediate(atoi(str)); return; } diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp index a73f1558e8d7..13c42b30e156 100644 --- a/engines/parallaction/parser_ns.cpp +++ b/engines/parallaction/parser_ns.cpp @@ -534,7 +534,7 @@ DECLARE_INSTRUCTION_PARSER(endscript) { void ProgramParser_ns::parseRValue(ScriptVar &v, const char *str) { - if (isdigit(static_cast(str[0])) || str[0] == '-') { + if (isDigit(str[0]) || str[0] == '-') { v.setImmediate(atoi(str)); return; } diff --git a/engines/queen/talk.cpp b/engines/queen/talk.cpp index f38c78c82554..72cb40bd7a5e 100644 --- a/engines/queen/talk.cpp +++ b/engines/queen/talk.cpp @@ -657,7 +657,7 @@ void Talk::stringAnimation(const SpeechParameters *parameters, int startFrame, i } else if (parameters->animation[0] == 'E') { // Talking head animation return; - } else if (!isdigit(static_cast(parameters->animation[0]))) { + } else if (!isDigit(parameters->animation[0])) { debug(6, "Error in speak string animation: '%s'", parameters->animation); return; } else diff --git a/engines/saga/interface.cpp b/engines/saga/interface.cpp index 994b35cbf827..dd99f5854a35 100644 --- a/engines/saga/interface.cpp +++ b/engines/saga/interface.cpp @@ -1151,7 +1151,7 @@ void Interface::processStatusTextInput(Common::KeyState keystate) { if (_statusTextInputPos >= STATUS_TEXT_INPUT_MAX) { break; } - if (isalnum(keystate.ascii) || (keystate.ascii == ' ')) { + if (isAlnum(keystate.ascii) || (keystate.ascii == ' ')) { _statusTextInputString[_statusTextInputPos++] = keystate.ascii; _statusTextInputString[_statusTextInputPos] = 0; } @@ -1209,7 +1209,7 @@ bool Interface::processTextInput(Common::KeyState keystate) { _textInputPos = _textInputStringLength + 1; break; default: - if (((keystate.ascii <= 255) && (isalnum(keystate.ascii))) || (keystate.ascii == ' ') || + if (((keystate.ascii <= 255) && (isAlnum(keystate.ascii))) || (keystate.ascii == ' ') || (keystate.ascii == '-') || (keystate.ascii == '_')) { if (_textInputStringLength < save_title_size - 1) { ch[0] = keystate.ascii; diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index a1cd571e8981..735b1b218701 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -147,7 +147,7 @@ reg_t kReadNumber(EngineState *s, int argc, reg_t *argv) { Common::String source_str = s->_segMan->getString(argv[0]); const char *source = source_str.c_str(); - while (isspace((unsigned char)*source)) + while (isSpace(*source)) source++; /* Skip whitespace */ int16 result = 0; @@ -246,14 +246,14 @@ reg_t kFormat(EngineState *s, int argc, reg_t *argv) { /* int writelength; -- unused atm */ - if (xfer && (isdigit(static_cast(xfer)) || xfer == '-' || xfer == '=')) { + if (xfer && (isDigit(xfer) || xfer == '-' || xfer == '=')) { char *destp; if (xfer == '0') fillchar = '0'; else if (xfer == '=') align = ALIGN_CENTER; - else if (isdigit(static_cast(xfer)) || (xfer == '-')) + else if (isDigit(xfer) || (xfer == '-')) source--; // Go to start of length argument strLength = strtol(source, &destp, 10); diff --git a/engines/sci/graphics/text16.cpp b/engines/sci/graphics/text16.cpp index 84547d98287a..bd89e237f0ee 100644 --- a/engines/sci/graphics/text16.cpp +++ b/engines/sci/graphics/text16.cpp @@ -100,7 +100,7 @@ int16 GfxText16::CodeProcessing(const char *&text, GuiResourceId orgFontId, int1 // cX -> sets textColor to _textColors[X-1] curCode = textCode[0]; curCodeParm = textCode[1]; - if (isdigit(static_cast(curCodeParm))) { + if (isDigit(curCodeParm)) { curCodeParm -= '0'; } else { curCodeParm = -1; diff --git a/engines/sci/parser/vocabulary.cpp b/engines/sci/parser/vocabulary.cpp index a5c4686b3b5f..44e11d5b1f6d 100644 --- a/engines/sci/parser/vocabulary.cpp +++ b/engines/sci/parser/vocabulary.cpp @@ -534,7 +534,7 @@ bool Vocabulary::tokenizeString(ResultWordListList &retval, const char *sentence do { c = sentence[pos_in_sentence++]; - if (isalnum(c) || (c == '-' && wordLen) || (c >= 0x80)) { + if (isAlnum(c) || (c == '-' && wordLen) || (c >= 0x80)) { currentWord[wordLen] = lowerCaseMap[c]; ++wordLen; } diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index 41062eb19bb1..a95a7e9b35ca 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -1558,7 +1558,7 @@ void ResourceManager::readResourcePatches() { name = (*x)->getName(); // SCI1 scheme - if (isdigit(static_cast(name[0]))) { + if (isDigit(name[0])) { char *end = 0; resourceNr = strtol(name.c_str(), &end, 10); bAdd = (*end == '.'); // Ensure the next character is the period @@ -1566,7 +1566,7 @@ void ResourceManager::readResourcePatches() { // SCI0 scheme int resname_len = strlen(szResType); if (scumm_strnicmp(name.c_str(), szResType, resname_len) == 0 - && !isalpha(static_cast(name[resname_len + 1]))) { + && !isAlpha(name[resname_len + 1])) { resourceNr = atoi(name.c_str() + resname_len + 1); bAdd = true; } diff --git a/engines/sci/resource_audio.cpp b/engines/sci/resource_audio.cpp index 764f4785b7a3..4eb94cca69f5 100644 --- a/engines/sci/resource_audio.cpp +++ b/engines/sci/resource_audio.cpp @@ -198,7 +198,7 @@ void ResourceManager::readWaveAudioPatches() { for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) { Common::String name = (*x)->getName(); - if (isdigit(static_cast(name[0]))) + if (isDigit(name[0])) processWavePatch(ResourceId(kResourceTypeAudio, atoi(name.c_str())), name); } } diff --git a/engines/scumm/smush/smush_player.cpp b/engines/scumm/smush/smush_player.cpp index 2f4e86bf610b..36de5e470bd5 100644 --- a/engines/scumm/smush/smush_player.cpp +++ b/engines/scumm/smush/smush_player.cpp @@ -90,13 +90,13 @@ class StringResource { assert(def_end != NULL); char *id_end = def_end; - while (id_end >= def_start && !isdigit(static_cast(*(id_end-1)))) { + while (id_end >= def_start && !isDigit(*(id_end-1))) { id_end--; } assert(id_end > def_start); char *id_start = id_end; - while (isdigit(static_cast(*(id_start - 1)))) { + while (isDigit(*(id_start - 1))) { id_start--; } diff --git a/engines/scumm/string.cpp b/engines/scumm/string.cpp index 61bb89328d44..8a689fffa96c 100644 --- a/engines/scumm/string.cpp +++ b/engines/scumm/string.cpp @@ -1389,10 +1389,10 @@ void ScummEngine_v7::loadLanguageBundle() { } else if (*ptr == '#') { // Number of subtags following a given basetag. We don't need that // information so we just skip it - } else if (isdigit(static_cast(*ptr))) { + } else if (isDigit(*ptr)) { int idx = 0; // A number (up to three digits)... - while (isdigit(static_cast(*ptr))) { + while (isDigit(*ptr)) { idx = idx * 10 + (*ptr - '0'); ptr++; } @@ -1430,12 +1430,12 @@ void ScummEngine_v7::loadLanguageBundle() { for (i = 0; i < _languageIndexSize; i++) { // First 8 chars in the line give the string ID / 'tag' int j; - for (j = 0; j < 8 && !isspace(static_cast(*ptr)); j++, ptr++) + for (j = 0; j < 8 && !isSpace(*ptr); j++, ptr++) _languageIndex[i].tag[j] = toupper(*ptr); _languageIndex[i].tag[j] = 0; // After that follows a single space which we skip - assert(isspace(static_cast(*ptr))); + assert(isSpace(*ptr)); ptr++; // Then comes the translated string: we record an offset to that. diff --git a/engines/sky/control.cpp b/engines/sky/control.cpp index a40e77d1cb3c..6363789d3a2b 100644 --- a/engines/sky/control.cpp +++ b/engines/sky/control.cpp @@ -974,7 +974,7 @@ void Control::handleKeyPress(Common::KeyState kbd, Common::String &textBuf) { // Allow the key only if is a letter, a digit, or one of a selected // list of extra characters - if (isalnum(kbd.ascii) || strchr(" ,().='-&+!?\"", kbd.ascii) != 0) { + if (isAlnum(kbd.ascii) || strchr(" ,().='-&+!?\"", kbd.ascii) != 0) { textBuf += kbd.ascii; } } diff --git a/engines/sky/detection.cpp b/engines/sky/detection.cpp index a078200edd20..51f7330f0931 100644 --- a/engines/sky/detection.cpp +++ b/engines/sky/detection.cpp @@ -206,7 +206,7 @@ SaveStateList SkyMetaEngine::listSaves(const char *target) const { // Extract the extension Common::String ext = file->c_str() + file->size() - 3; ext.toUppercase(); - if (isdigit(static_cast(ext[0])) && isdigit(static_cast(ext[1])) && isdigit(static_cast(ext[2]))){ + if (isDigit(ext[0]) && isDigit(ext[1]) && isDigit(ext[2])) { int slotNum = atoi(ext.c_str()); Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp index 5ad84d995f9a..a1c02c861a82 100644 --- a/engines/sword1/animation.cpp +++ b/engines/sword1/animation.cpp @@ -115,7 +115,7 @@ bool MoviePlayer::load(uint32 id) { int startFrame = strtoul(ptr, const_cast(&ptr), 10); int endFrame = strtoul(ptr, const_cast(&ptr), 10); - while (*ptr && isspace(static_cast(*ptr))) + while (*ptr && isSpace(*ptr)) ptr++; if (startFrame > endFrame) { @@ -132,7 +132,7 @@ bool MoviePlayer::load(uint32 id) { if (*ptr == '@') { ++ptr; color = strtoul(ptr, const_cast(&ptr), 10); - while (*ptr && isspace(static_cast(*ptr))) + while (*ptr && isSpace(*ptr)) ptr++; } diff --git a/engines/sword25/util/lua/lbaselib.cpp b/engines/sword25/util/lua/lbaselib.cpp index 3f0b645164b6..940ddcd4f951 100644 --- a/engines/sword25/util/lua/lbaselib.cpp +++ b/engines/sword25/util/lua/lbaselib.cpp @@ -6,10 +6,7 @@ -#include -#include -#include -#include +#include "common/util.h" #define lbaselib_c #define LUA_LIB @@ -62,7 +59,7 @@ static int luaB_tonumber (lua_State *L) { luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); n = strtoul(s1, &s2, base); if (s1 != s2) { /* at least one valid digit? */ - while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ + while (isSpace(*s2)) s2++; /* skip trailing spaces */ if (*s2 == '\0') { /* no invalid trailing characters? */ lua_pushnumber(L, (lua_Number)n); return 1; diff --git a/engines/sword25/util/lua/llex.cpp b/engines/sword25/util/lua/llex.cpp index 464ab3ec1574..6c7eb7806022 100644 --- a/engines/sword25/util/lua/llex.cpp +++ b/engines/sword25/util/lua/llex.cpp @@ -5,9 +5,7 @@ */ -#include -#include -#include +#include "common/util.h" #define llex_c #define LUA_CORE @@ -188,7 +186,7 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) { sprintf(buf, "%.1f", 1.0); ls->decpoint = '.'; for (i = 0; buf[i]; i++) { - if (!isspace(static_cast(buf[i])) && !isdigit(static_cast(buf[i]))) { + if (!isSpace(buf[i]) && !isDigit(buf[i])) { ls->decpoint = buf[i]; break; } @@ -204,13 +202,13 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) { /* LUA_NUMBER */ static void read_numeral (LexState *ls, SemInfo *seminfo) { - lua_assert(isdigit(ls->current)); + lua_assert(isDigit(ls->current)); do { save_and_next(ls); - } while (isdigit(ls->current) || ls->current == '.'); + } while (isDigit(ls->current) || ls->current == '.'); if (check_next(ls, "Ee")) /* `E'? */ check_next(ls, "+-"); /* optional exponent sign */ - while (isalnum(ls->current) || ls->current == '_') + while (isAlnum(ls->current) || ls->current == '_') save_and_next(ls); save(ls, '\0'); buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ @@ -313,7 +311,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { case '\r': save(ls, '\n'); inclinenumber(ls); continue; case EOZ: continue; /* will raise an error next loop */ default: { - if (!isdigit(ls->current)) + if (!isDigit(ls->current)) save_and_next(ls); /* handles \\, \", \', and \? */ else { /* \xxx */ int i = 0; @@ -321,7 +319,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { do { c = 10*c + (ls->current-'0'); next(ls); - } while (++i<3 && isdigit(ls->current)); + } while (++i<3 && isDigit(ls->current)); if (c > UCHAR_MAX) luaX_lexerror(ls, "escape sequence too large", TK_STRING); save(ls, c); @@ -412,7 +410,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { return TK_DOTS; /* ... */ else return TK_CONCAT; /* .. */ } - else if (!isdigit(ls->current)) return '.'; + else if (!isDigit(ls->current)) return '.'; else { read_numeral(ls, seminfo); return TK_NUMBER; @@ -422,21 +420,21 @@ static int llex (LexState *ls, SemInfo *seminfo) { return TK_EOS; } default: { - if (isspace(ls->current)) { + if (isSpace(ls->current)) { lua_assert(!currIsNewline(ls)); next(ls); continue; } - else if (isdigit(ls->current)) { + else if (isDigit(ls->current)) { read_numeral(ls, seminfo); return TK_NUMBER; } - else if (isalpha(ls->current) || ls->current == '_') { + else if (isAlpha(ls->current) || ls->current == '_') { /* identifier or reserved word */ TString *ts; do { save_and_next(ls); - } while (isalnum(ls->current) || ls->current == '_'); + } while (isAlnum(ls->current) || ls->current == '_'); ts = luaX_newstring(ls, luaZ_buffer(ls->buff), luaZ_bufflen(ls->buff)); if (ts->tsv.reserved > 0) /* reserved word? */ diff --git a/engines/sword25/util/lua/lobject.cpp b/engines/sword25/util/lua/lobject.cpp index 24718931ed4a..1890aaae6876 100644 --- a/engines/sword25/util/lua/lobject.cpp +++ b/engines/sword25/util/lua/lobject.cpp @@ -4,11 +4,7 @@ ** See Copyright Notice in lua.h */ -#include -#include -#include -#include -#include +#include "common/util.h" #define lobject_c #define LUA_CORE @@ -94,7 +90,7 @@ int luaO_str2d (const char *s, lua_Number *result) { if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ *result = cast_num(strtoul(s, &endptr, 16)); if (*endptr == '\0') return 1; /* most common case */ - while (isspace(cast(unsigned char, *endptr))) endptr++; + while (isSpace(*endptr)) endptr++; if (*endptr != '\0') return 0; /* invalid trailing characters? */ return 1; } diff --git a/engines/sword25/util/lua/lstrlib.cpp b/engines/sword25/util/lua/lstrlib.cpp index bcc869cb9848..ed68a2fa00d7 100644 --- a/engines/sword25/util/lua/lstrlib.cpp +++ b/engines/sword25/util/lua/lstrlib.cpp @@ -5,6 +5,8 @@ */ +#define FORBIDDEN_SYMBOL_EXCEPTION_ctype_h + #include #include #include diff --git a/graphics/font.cpp b/graphics/font.cpp index 8775bccc7bff..7b48fe999907 100644 --- a/graphics/font.cpp +++ b/graphics/font.cpp @@ -184,7 +184,7 @@ int Font::wordWrapText(const Common::String &str, int maxWidth, Common::Array 0) { wrapper.add(line, lineWidth); // Trim left side - while (tmpStr.size() && isspace(static_cast(tmpStr[0]))) { + while (tmpStr.size() && isSpace(tmpStr[0])) { tmpStr.deleteChar(0); // This is not very fast, but it is the simplest way to // assure we do not mess something up because of kerning. diff --git a/gui/launcher.cpp b/gui/launcher.cpp index c737b81b334d..b23ef23511a0 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -90,7 +90,7 @@ class DomainEditTextWidget : public EditTextWidget { protected: bool tryInsertChar(byte c, int pos) { - if (isalnum(c) || c == '-' || c == '_') { + if (isAlnum(c) || c == '-' || c == '_') { _editString.insertChar(c, pos); return true; } From 4f8665fc836898ebf54fc73b1061125b748183bc Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 20 Feb 2012 16:03:39 +0100 Subject: [PATCH 2/3] COMMON: Move isFoo functions to namespace Common, add doxygen comments --- base/commandLine.cpp | 2 +- common/config-manager.cpp | 2 +- common/util.cpp | 9 +--- common/util.h | 75 +++++++++++++++++++++++---- engines/agi/agi.cpp | 2 +- engines/agi/wagparser.cpp | 4 +- engines/agos/script_pn.cpp | 8 +-- engines/agos/string.cpp | 2 +- engines/agos/string_pn.cpp | 2 +- engines/cge/text.cpp | 4 +- engines/cine/detection.cpp | 2 +- engines/hugo/util.cpp | 2 +- engines/kyra/gui.cpp | 2 +- engines/mohawk/livingbooks_code.cpp | 8 +-- engines/parallaction/dialogue.cpp | 2 +- engines/parallaction/parser_br.cpp | 12 ++--- engines/parallaction/parser_ns.cpp | 2 +- engines/queen/talk.cpp | 2 +- engines/saga/interface.cpp | 4 +- engines/sci/engine/kstring.cpp | 6 +-- engines/sci/graphics/text16.cpp | 2 +- engines/sci/parser/vocabulary.cpp | 2 +- engines/sci/resource.cpp | 4 +- engines/sci/resource_audio.cpp | 2 +- engines/scumm/smush/smush_player.cpp | 4 +- engines/scumm/string.cpp | 8 +-- engines/sky/control.cpp | 2 +- engines/sky/detection.cpp | 2 +- engines/sword1/animation.cpp | 4 +- engines/sword25/util/lua/lbaselib.cpp | 2 +- engines/sword25/util/lua/llex.cpp | 22 ++++---- engines/sword25/util/lua/lobject.cpp | 2 +- graphics/font.cpp | 4 +- gui/launcher.cpp | 2 +- 34 files changed, 131 insertions(+), 83 deletions(-) diff --git a/base/commandLine.cpp b/base/commandLine.cpp index 16a2b6f9f0c9..aa589ed15f55 100644 --- a/base/commandLine.cpp +++ b/base/commandLine.cpp @@ -277,7 +277,7 @@ void registerDefaults() { // resp. between "--some-option" and "--no-some-option". #define DO_OPTION_BOOL(shortCmd, longCmd) \ if (isLongCmd ? (!strcmp(s+2, longCmd) || !strcmp(s+2, "no-"longCmd)) : (tolower(s[1]) == shortCmd)) { \ - bool boolValue = (isLower(s[1]) != 0); \ + bool boolValue = (Common::isLower(s[1]) != 0); \ s += 2; \ if (isLongCmd) { \ boolValue = !strcmp(s, longCmd); \ diff --git a/common/config-manager.cpp b/common/config-manager.cpp index d4035e8b9261..aaa812bc94f8 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -29,7 +29,7 @@ static bool isValidDomainName(const Common::String &domName) { const char *p = domName.c_str(); - while (*p && (isAlnum(*p) || *p == '-' || *p == '_')) + while (*p && (Common::isAlnum(*p) || *p == '-' || *p == '_')) p++; return *p == 0; } diff --git a/common/util.cpp b/common/util.cpp index 0a7d0f1e89d1..e605a267d5bb 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -415,9 +415,6 @@ void updateGameGUIOptions(const String &options, const String &langOption) { } } -} // End of namespace Common - - // // TODO: Instead of a blind cast, we might want to verify // if c equals EOS; and/or is in the range -255..+255; @@ -435,10 +432,6 @@ bool isDigit(int c) { return isdigit((byte)c); } -bool isNumber(int c) { - return isnumber((byte)c); -} - bool isLower(int c) { return islower((byte)c); } @@ -450,3 +443,5 @@ bool isSpace(int c) { bool isUpper(int c) { return isupper((byte)c); } + +} // End of namespace Common diff --git a/common/util.h b/common/util.h index 1df7bbb9c3ac..617bc3dcfa53 100644 --- a/common/util.h +++ b/common/util.h @@ -34,17 +34,6 @@ ((((size_t)value) & ((alignment) - 1)) == 0) -//namespace{ -bool isAlnum(int c); -bool isAlpha(int c); -bool isDigit(int c); -bool isNumber(int c); -bool isLower(int c); -bool isSpace(int c); -bool isUpper(int c); -//} - - #ifdef MIN #undef MIN #endif @@ -144,6 +133,70 @@ extern void hexdump(const byte * data, int len, int bytesPerLine = 16, int start */ bool parseBool(const String &val, bool &valAsBool); + +/** + * Test whether the given character is alphanumeric (a-z, A-Z, 0-9). + * If the parameter is outside the range of a signed or unsigned char, then + * false is returned. + * + * @param c the character to test + * @return true if the character is alphanumeric, false otherwise. + */ +bool isAlnum(int c); + +/** + * Test whether the given character is an alphabetic letter (a-z, A-Z). + * If the parameter is outside the range of a signed or unsigned char, then + * false is returned. + * + * @param c the character to test + * @return true if the character is TODO, false otherwise. + */ +bool isAlpha(int c); + +/** + * Test whether the given character is a decimal-digit (0-9). + * If the parameter is outside the range of a signed or unsigned char, then + * false is returned. + * + * @param c the character to test + * @return true if the character is a decimal-digit, false otherwise. + */ +bool isDigit(int c); + +/** + * Test whether the given character is a lower-case letter (a-z). + * If the parameter is outside the range of a signed or unsigned char, then + * false is returned. + * + * @param c the character to test + * @return true if the character is a lower-case letter, false otherwise. + */ +bool isLower(int c); + +/** + * Test whether the given character is a white-space. + * White-space characters are ' ', '\t', '\r', '\n', '\v', '\f'. + * + * If the parameter is outside the range of a signed or unsigned char, then + * false is returned. + * + * @param c the character to test + * @return true if the character is a white-space, false otherwise. + */ +bool isSpace(int c); + +/** + * Test whether the given character is an upper-case letter (A-Z). + * If the parameter is outside the range of a signed or unsigned char, then + * false is returned. + * + * @param c the character to test + * @return true if the character is an upper-case letter, false otherwise. + */ +bool isUpper(int c); + + /** * List of game language. */ diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp index e1c52c7c5e45..e9c964576866 100644 --- a/engines/agi/agi.cpp +++ b/engines/agi/agi.cpp @@ -250,7 +250,7 @@ void AgiEngine::processEvents() { // Not a special key, so get the ASCII code for it key = event.kbd.ascii; - if (isAlpha(key)) { + if (Common::isAlpha(key)) { // Key is A-Z. // Map Ctrl-A to 1, Ctrl-B to 2, etc. if (event.kbd.flags & Common::KBD_CTRL) { diff --git a/engines/agi/wagparser.cpp b/engines/agi/wagparser.cpp index 00602420e2df..61feac5d171b 100644 --- a/engines/agi/wagparser.cpp +++ b/engines/agi/wagparser.cpp @@ -112,11 +112,11 @@ WagFileParser::~WagFileParser() { bool WagFileParser::checkAgiVersionProperty(const WagProperty &version) const { if (version.getCode() == WagProperty::PC_INTVERSION && // Must be AGI interpreter version property version.getSize() >= 3 && // Need at least three characters for a version number like "X.Y" - isDigit(version.getData()[0]) && // And the first character must be a digit + Common::isDigit(version.getData()[0]) && // And the first character must be a digit (version.getData()[1] == ',' || version.getData()[1] == '.')) { // And the second a comma or a period for (int i = 2; i < version.getSize(); i++) // And the rest must all be digits - if (!isDigit(version.getData()[i])) + if (!Common::isDigit(version.getData()[i])) return false; // Bail out if found a non-digit after the decimal point return true; diff --git a/engines/agos/script_pn.cpp b/engines/agos/script_pn.cpp index 70540343ed7a..60a1376f2588 100644 --- a/engines/agos/script_pn.cpp +++ b/engines/agos/script_pn.cpp @@ -466,8 +466,8 @@ void AGOSEngine_PN::opn_opcode35() { void AGOSEngine_PN::opn_opcode36() { for (int i = 0; i < _dataBase[57] + 1; ++i) _wordcp[i] = 0; - if (isSpace(*_inpp)) - while ((*_inpp) && (isSpace(*_inpp))) + if (Common::isSpace(*_inpp)) + while ((*_inpp) && (Common::isSpace(*_inpp))) _inpp++; if (*_inpp == 0) { setScriptReturn(false); @@ -481,7 +481,7 @@ void AGOSEngine_PN::opn_opcode36() { } int ct = 1; - while ((*_inpp != '.') && (*_inpp != ',') && (!isSpace(*_inpp)) && (*_inpp != '\0') && + while ((*_inpp != '.') && (*_inpp != ',') && (!Common::isSpace(*_inpp)) && (*_inpp != '\0') && (*_inpp!='"')) { if (ct < _dataBase[57]) _wordcp[ct++] = *_inpp; @@ -581,7 +581,7 @@ void AGOSEngine_PN::opn_opcode46() { return; } x++; - while ((*x != '.') && (*x != ',') && (*x != '"') && (!isSpace(*x)) && (*x != '\0')) + while ((*x != '.') && (*x != ',') && (*x != '"') && (!Common::isSpace(*x)) && (*x != '\0')) pcf(*x++); setScriptReturn(true); } diff --git a/engines/agos/string.cpp b/engines/agos/string.cpp index 4298ff615504..ee1b9df24679 100644 --- a/engines/agos/string.cpp +++ b/engines/agos/string.cpp @@ -152,7 +152,7 @@ const byte *AGOSEngine::getStringPtrByID(uint16 stringId, bool upperCase) { } if (upperCase && *dst) { - if (isLower(*dst)) + if (Common::isLower(*dst)) *dst = toupper(*dst); } diff --git a/engines/agos/string_pn.cpp b/engines/agos/string_pn.cpp index 8f31da6f587f..4d4e2be16a45 100644 --- a/engines/agos/string_pn.cpp +++ b/engines/agos/string_pn.cpp @@ -137,7 +137,7 @@ void AGOSEngine_PN::pcf(uint8 ch) { if ((ch != 32) || (_bp + _xofs != 50)) _buffer[_bp++] = ch; } - if ((ch != 254) && (!isSpace(ch)) && (_bp < 60)) + if ((ch != 254) && (!Common::isSpace(ch)) && (_bp < 60)) return; /* We know have a case of needing to print the text */ if (_bp + _xofs > 50) { diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 9fb3c95e9387..fd4120d49dbf 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -72,7 +72,7 @@ int16 Text::count() { strcpy(tmpStr, line.c_str()); if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL) continue; - if (!isDigit(*s)) + if (!Common::isDigit(*s)) continue; counter++; @@ -105,7 +105,7 @@ void Text::load() { strcpy(tmpStr, line.c_str()); if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL) continue; - if (!isDigit(*s)) + if (!Common::isDigit(*s)) continue; int r = atoi(s); diff --git a/engines/cine/detection.cpp b/engines/cine/detection.cpp index 65b2285f11ea..823b8e38b561 100644 --- a/engines/cine/detection.cpp +++ b/engines/cine/detection.cpp @@ -141,7 +141,7 @@ SaveStateList CineMetaEngine::listSaves(const char *target) const { for (file = filenames.begin(); file != filenames.end(); ++file) { // Jump over savegame files that don't end with a digit (e.g. "fw.3" is ok, "fw.a" is not). - if (!isDigit(file->lastChar())) + if (!Common::isDigit(file->lastChar())) continue; // Obtain the last digit of the filename, since they correspond to the save slot diff --git a/engines/hugo/util.cpp b/engines/hugo/util.cpp index 1428fc93a30e..fdc676e6a7ba 100644 --- a/engines/hugo/util.cpp +++ b/engines/hugo/util.cpp @@ -119,7 +119,7 @@ char *strlwr(char *buffer) { char *result = buffer; while (*buffer != '\0') { - if (isUpper(*buffer)) + if (Common::isUpper(*buffer)) *buffer = tolower(*buffer); buffer++; } diff --git a/engines/kyra/gui.cpp b/engines/kyra/gui.cpp index 07d8b307f3af..1156b179572c 100644 --- a/engines/kyra/gui.cpp +++ b/engines/kyra/gui.cpp @@ -56,7 +56,7 @@ void GUI::updateSaveFileList(Common::String targetName, bool excludeQuickSaves) s1 = (*i)[i->size() - 3]; s2 = (*i)[i->size() - 2]; s3 = (*i)[i->size() - 1]; - if (!isDigit(s1) || !isDigit(s2) || !isDigit(s3)) + if (!Common::isDigit(s1) || !Common::isDigit(s2) || !Common::isDigit(s3)) continue; s1 -= '0'; s2 -= '0'; diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp index b961e20f7875..bb8f7a0d0538 100644 --- a/engines/mohawk/livingbooks_code.cpp +++ b/engines/mohawk/livingbooks_code.cpp @@ -1766,7 +1766,7 @@ uint LBCode::parseCode(const Common::String &source) { { Common::String tempString; while (pos < source.size()) { - if (!isAlpha(source[pos]) && !isDigit(source[pos])) + if (!Common::isAlpha(source[pos]) && !Common::isDigit(source[pos])) break; tempString += source[pos++]; } @@ -1777,7 +1777,7 @@ uint LBCode::parseCode(const Common::String &source) { } break; default: - if (isDigit(token)) { + if (Common::isDigit(token)) { const char *in = source.c_str() + pos - 1; // FIXME: handle floats? char *endptr; @@ -1792,11 +1792,11 @@ uint LBCode::parseCode(const Common::String &source) { WRITE_BE_UINT16(tmp, (int16)intValue); code.push_back(tmp[0]); code.push_back(tmp[1]); - } else if (isAlpha(token)) { + } else if (Common::isAlpha(token)) { Common::String tempString; tempString += token; while (pos < source.size()) { - if (!isAlpha(source[pos]) && !isDigit(source[pos])) + if (!Common::isAlpha(source[pos]) && !Common::isDigit(source[pos])) break; tempString += source[pos++]; } diff --git a/engines/parallaction/dialogue.cpp b/engines/parallaction/dialogue.cpp index 3bb4404b98bc..e0bd6a6677b3 100644 --- a/engines/parallaction/dialogue.cpp +++ b/engines/parallaction/dialogue.cpp @@ -381,7 +381,7 @@ class DialogueManager_ns : public DialogueManager { } void accumPassword(uint16 ascii) { - if (!isDigit(ascii)) { + if (!Common::isDigit(ascii)) { return; } diff --git a/engines/parallaction/parser_br.cpp b/engines/parallaction/parser_br.cpp index fb6a4102d199..82940340bcdf 100644 --- a/engines/parallaction/parser_br.cpp +++ b/engines/parallaction/parser_br.cpp @@ -524,14 +524,14 @@ DECLARE_COMMAND_PARSER(location) { ctxt.cmd->_startPos.x = -1000; ctxt.cmd->_startPos2.x = -1000; if (_tokens[ctxt.nextToken][0] != '\0') { - if (isDigit(_tokens[ctxt.nextToken][0]) || _tokens[ctxt.nextToken][0] == '-') { + if (Common::isDigit(_tokens[ctxt.nextToken][0]) || _tokens[ctxt.nextToken][0] == '-') { ctxt.cmd->_startPos.x = atoi(_tokens[ctxt.nextToken]); ctxt.nextToken++; ctxt.cmd->_startPos.y = atoi(_tokens[ctxt.nextToken]); ctxt.nextToken++; } - if (isDigit(_tokens[ctxt.nextToken][0]) || _tokens[ctxt.nextToken][0] == '-') { + if (Common::isDigit(_tokens[ctxt.nextToken][0]) || _tokens[ctxt.nextToken][0] == '-') { ctxt.cmd->_startPos2.x = atoi(_tokens[ctxt.nextToken]); ctxt.nextToken++; ctxt.cmd->_startPos2.y = atoi(_tokens[ctxt.nextToken]); @@ -677,7 +677,7 @@ DECLARE_COMMAND_PARSER(text) { createCommand(_parser->_lookup); - if (isDigit(_tokens[1][1])) { + if (Common::isDigit(_tokens[1][1])) { ctxt.cmd->_zeta0 = atoi(_tokens[1]); ctxt.nextToken++; } else { @@ -714,7 +714,7 @@ DECLARE_COMMAND_PARSER(unary) { DECLARE_ZONE_PARSER(limits) { debugC(7, kDebugParser, "ZONE_PARSER(limits) "); - if (isAlpha(_tokens[1][1])) { + if (Common::isAlpha(_tokens[1][1])) { ctxt.z->_flags |= kFlagsAnimLinked; ctxt.z->_linkedName = _tokens[1]; } else { @@ -1003,7 +1003,7 @@ DECLARE_INSTRUCTION_PARSER(text) { int _si = 1; - if (isDigit(_tokens[1][1])) { + if (Common::isDigit(_tokens[1][1])) { ctxt.inst->_y = atoi(_tokens[1]); _si = 2; } else { @@ -1066,7 +1066,7 @@ DECLARE_INSTRUCTION_PARSER(endif) { void ProgramParser_br::parseRValue(ScriptVar &v, const char *str) { - if (isDigit(str[0]) || str[0] == '-') { + if (Common::isDigit(str[0]) || str[0] == '-') { v.setImmediate(atoi(str)); return; } diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp index 13c42b30e156..36b8640a60e4 100644 --- a/engines/parallaction/parser_ns.cpp +++ b/engines/parallaction/parser_ns.cpp @@ -534,7 +534,7 @@ DECLARE_INSTRUCTION_PARSER(endscript) { void ProgramParser_ns::parseRValue(ScriptVar &v, const char *str) { - if (isDigit(str[0]) || str[0] == '-') { + if (Common::isDigit(str[0]) || str[0] == '-') { v.setImmediate(atoi(str)); return; } diff --git a/engines/queen/talk.cpp b/engines/queen/talk.cpp index 72cb40bd7a5e..94bc105bb050 100644 --- a/engines/queen/talk.cpp +++ b/engines/queen/talk.cpp @@ -657,7 +657,7 @@ void Talk::stringAnimation(const SpeechParameters *parameters, int startFrame, i } else if (parameters->animation[0] == 'E') { // Talking head animation return; - } else if (!isDigit(parameters->animation[0])) { + } else if (!Common::isDigit(parameters->animation[0])) { debug(6, "Error in speak string animation: '%s'", parameters->animation); return; } else diff --git a/engines/saga/interface.cpp b/engines/saga/interface.cpp index dd99f5854a35..a7bd7edbe521 100644 --- a/engines/saga/interface.cpp +++ b/engines/saga/interface.cpp @@ -1151,7 +1151,7 @@ void Interface::processStatusTextInput(Common::KeyState keystate) { if (_statusTextInputPos >= STATUS_TEXT_INPUT_MAX) { break; } - if (isAlnum(keystate.ascii) || (keystate.ascii == ' ')) { + if (Common::isAlnum(keystate.ascii) || (keystate.ascii == ' ')) { _statusTextInputString[_statusTextInputPos++] = keystate.ascii; _statusTextInputString[_statusTextInputPos] = 0; } @@ -1209,7 +1209,7 @@ bool Interface::processTextInput(Common::KeyState keystate) { _textInputPos = _textInputStringLength + 1; break; default: - if (((keystate.ascii <= 255) && (isAlnum(keystate.ascii))) || (keystate.ascii == ' ') || + if (((keystate.ascii <= 255) && (Common::isAlnum(keystate.ascii))) || (keystate.ascii == ' ') || (keystate.ascii == '-') || (keystate.ascii == '_')) { if (_textInputStringLength < save_title_size - 1) { ch[0] = keystate.ascii; diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 735b1b218701..fe8d63149797 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -147,7 +147,7 @@ reg_t kReadNumber(EngineState *s, int argc, reg_t *argv) { Common::String source_str = s->_segMan->getString(argv[0]); const char *source = source_str.c_str(); - while (isSpace(*source)) + while (Common::isSpace(*source)) source++; /* Skip whitespace */ int16 result = 0; @@ -246,14 +246,14 @@ reg_t kFormat(EngineState *s, int argc, reg_t *argv) { /* int writelength; -- unused atm */ - if (xfer && (isDigit(xfer) || xfer == '-' || xfer == '=')) { + if (xfer && (Common::isDigit(xfer) || xfer == '-' || xfer == '=')) { char *destp; if (xfer == '0') fillchar = '0'; else if (xfer == '=') align = ALIGN_CENTER; - else if (isDigit(xfer) || (xfer == '-')) + else if (Common::isDigit(xfer) || (xfer == '-')) source--; // Go to start of length argument strLength = strtol(source, &destp, 10); diff --git a/engines/sci/graphics/text16.cpp b/engines/sci/graphics/text16.cpp index bd89e237f0ee..7eaa0168b8ed 100644 --- a/engines/sci/graphics/text16.cpp +++ b/engines/sci/graphics/text16.cpp @@ -100,7 +100,7 @@ int16 GfxText16::CodeProcessing(const char *&text, GuiResourceId orgFontId, int1 // cX -> sets textColor to _textColors[X-1] curCode = textCode[0]; curCodeParm = textCode[1]; - if (isDigit(curCodeParm)) { + if (Common::isDigit(curCodeParm)) { curCodeParm -= '0'; } else { curCodeParm = -1; diff --git a/engines/sci/parser/vocabulary.cpp b/engines/sci/parser/vocabulary.cpp index 44e11d5b1f6d..e56158ecc1b9 100644 --- a/engines/sci/parser/vocabulary.cpp +++ b/engines/sci/parser/vocabulary.cpp @@ -534,7 +534,7 @@ bool Vocabulary::tokenizeString(ResultWordListList &retval, const char *sentence do { c = sentence[pos_in_sentence++]; - if (isAlnum(c) || (c == '-' && wordLen) || (c >= 0x80)) { + if (Common::isAlnum(c) || (c == '-' && wordLen) || (c >= 0x80)) { currentWord[wordLen] = lowerCaseMap[c]; ++wordLen; } diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp index a95a7e9b35ca..50b3387159a1 100644 --- a/engines/sci/resource.cpp +++ b/engines/sci/resource.cpp @@ -1558,7 +1558,7 @@ void ResourceManager::readResourcePatches() { name = (*x)->getName(); // SCI1 scheme - if (isDigit(name[0])) { + if (Common::isDigit(name[0])) { char *end = 0; resourceNr = strtol(name.c_str(), &end, 10); bAdd = (*end == '.'); // Ensure the next character is the period @@ -1566,7 +1566,7 @@ void ResourceManager::readResourcePatches() { // SCI0 scheme int resname_len = strlen(szResType); if (scumm_strnicmp(name.c_str(), szResType, resname_len) == 0 - && !isAlpha(name[resname_len + 1])) { + && !Common::isAlpha(name[resname_len + 1])) { resourceNr = atoi(name.c_str() + resname_len + 1); bAdd = true; } diff --git a/engines/sci/resource_audio.cpp b/engines/sci/resource_audio.cpp index 4eb94cca69f5..684e1a1d0d5a 100644 --- a/engines/sci/resource_audio.cpp +++ b/engines/sci/resource_audio.cpp @@ -198,7 +198,7 @@ void ResourceManager::readWaveAudioPatches() { for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) { Common::String name = (*x)->getName(); - if (isDigit(name[0])) + if (Common::isDigit(name[0])) processWavePatch(ResourceId(kResourceTypeAudio, atoi(name.c_str())), name); } } diff --git a/engines/scumm/smush/smush_player.cpp b/engines/scumm/smush/smush_player.cpp index 36de5e470bd5..a53b808ba1d8 100644 --- a/engines/scumm/smush/smush_player.cpp +++ b/engines/scumm/smush/smush_player.cpp @@ -90,13 +90,13 @@ class StringResource { assert(def_end != NULL); char *id_end = def_end; - while (id_end >= def_start && !isDigit(*(id_end-1))) { + while (id_end >= def_start && !Common::isDigit(*(id_end-1))) { id_end--; } assert(id_end > def_start); char *id_start = id_end; - while (isDigit(*(id_start - 1))) { + while (Common::isDigit(*(id_start - 1))) { id_start--; } diff --git a/engines/scumm/string.cpp b/engines/scumm/string.cpp index 8a689fffa96c..bcb45e2e92e7 100644 --- a/engines/scumm/string.cpp +++ b/engines/scumm/string.cpp @@ -1389,10 +1389,10 @@ void ScummEngine_v7::loadLanguageBundle() { } else if (*ptr == '#') { // Number of subtags following a given basetag. We don't need that // information so we just skip it - } else if (isDigit(*ptr)) { + } else if (Common::isDigit(*ptr)) { int idx = 0; // A number (up to three digits)... - while (isDigit(*ptr)) { + while (Common::isDigit(*ptr)) { idx = idx * 10 + (*ptr - '0'); ptr++; } @@ -1430,12 +1430,12 @@ void ScummEngine_v7::loadLanguageBundle() { for (i = 0; i < _languageIndexSize; i++) { // First 8 chars in the line give the string ID / 'tag' int j; - for (j = 0; j < 8 && !isSpace(*ptr); j++, ptr++) + for (j = 0; j < 8 && !Common::isSpace(*ptr); j++, ptr++) _languageIndex[i].tag[j] = toupper(*ptr); _languageIndex[i].tag[j] = 0; // After that follows a single space which we skip - assert(isSpace(*ptr)); + assert(Common::isSpace(*ptr)); ptr++; // Then comes the translated string: we record an offset to that. diff --git a/engines/sky/control.cpp b/engines/sky/control.cpp index 6363789d3a2b..036659a677a5 100644 --- a/engines/sky/control.cpp +++ b/engines/sky/control.cpp @@ -974,7 +974,7 @@ void Control::handleKeyPress(Common::KeyState kbd, Common::String &textBuf) { // Allow the key only if is a letter, a digit, or one of a selected // list of extra characters - if (isAlnum(kbd.ascii) || strchr(" ,().='-&+!?\"", kbd.ascii) != 0) { + if (Common::isAlnum(kbd.ascii) || strchr(" ,().='-&+!?\"", kbd.ascii) != 0) { textBuf += kbd.ascii; } } diff --git a/engines/sky/detection.cpp b/engines/sky/detection.cpp index 51f7330f0931..2b702e99ea89 100644 --- a/engines/sky/detection.cpp +++ b/engines/sky/detection.cpp @@ -206,7 +206,7 @@ SaveStateList SkyMetaEngine::listSaves(const char *target) const { // Extract the extension Common::String ext = file->c_str() + file->size() - 3; ext.toUppercase(); - if (isDigit(ext[0]) && isDigit(ext[1]) && isDigit(ext[2])) { + if (Common::isDigit(ext[0]) && Common::isDigit(ext[1]) && Common::isDigit(ext[2])) { int slotNum = atoi(ext.c_str()); Common::InSaveFile *in = saveFileMan->openForLoading(*file); if (in) { diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp index a1c02c861a82..e274e02cfd78 100644 --- a/engines/sword1/animation.cpp +++ b/engines/sword1/animation.cpp @@ -115,7 +115,7 @@ bool MoviePlayer::load(uint32 id) { int startFrame = strtoul(ptr, const_cast(&ptr), 10); int endFrame = strtoul(ptr, const_cast(&ptr), 10); - while (*ptr && isSpace(*ptr)) + while (*ptr && Common::isSpace(*ptr)) ptr++; if (startFrame > endFrame) { @@ -132,7 +132,7 @@ bool MoviePlayer::load(uint32 id) { if (*ptr == '@') { ++ptr; color = strtoul(ptr, const_cast(&ptr), 10); - while (*ptr && isSpace(*ptr)) + while (*ptr && Common::isSpace(*ptr)) ptr++; } diff --git a/engines/sword25/util/lua/lbaselib.cpp b/engines/sword25/util/lua/lbaselib.cpp index 940ddcd4f951..659c61d95607 100644 --- a/engines/sword25/util/lua/lbaselib.cpp +++ b/engines/sword25/util/lua/lbaselib.cpp @@ -59,7 +59,7 @@ static int luaB_tonumber (lua_State *L) { luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); n = strtoul(s1, &s2, base); if (s1 != s2) { /* at least one valid digit? */ - while (isSpace(*s2)) s2++; /* skip trailing spaces */ + while (Common::isSpace(*s2)) s2++; /* skip trailing spaces */ if (*s2 == '\0') { /* no invalid trailing characters? */ lua_pushnumber(L, (lua_Number)n); return 1; diff --git a/engines/sword25/util/lua/llex.cpp b/engines/sword25/util/lua/llex.cpp index 6c7eb7806022..f8433d3afa36 100644 --- a/engines/sword25/util/lua/llex.cpp +++ b/engines/sword25/util/lua/llex.cpp @@ -186,7 +186,7 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) { sprintf(buf, "%.1f", 1.0); ls->decpoint = '.'; for (i = 0; buf[i]; i++) { - if (!isSpace(buf[i]) && !isDigit(buf[i])) { + if (!Common::isSpace(buf[i]) && !Common::isDigit(buf[i])) { ls->decpoint = buf[i]; break; } @@ -202,13 +202,13 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) { /* LUA_NUMBER */ static void read_numeral (LexState *ls, SemInfo *seminfo) { - lua_assert(isDigit(ls->current)); + lua_assert(Common::isDigit(ls->current)); do { save_and_next(ls); - } while (isDigit(ls->current) || ls->current == '.'); + } while (Common::isDigit(ls->current) || ls->current == '.'); if (check_next(ls, "Ee")) /* `E'? */ check_next(ls, "+-"); /* optional exponent sign */ - while (isAlnum(ls->current) || ls->current == '_') + while (Common::isAlnum(ls->current) || ls->current == '_') save_and_next(ls); save(ls, '\0'); buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ @@ -311,7 +311,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { case '\r': save(ls, '\n'); inclinenumber(ls); continue; case EOZ: continue; /* will raise an error next loop */ default: { - if (!isDigit(ls->current)) + if (!Common::isDigit(ls->current)) save_and_next(ls); /* handles \\, \", \', and \? */ else { /* \xxx */ int i = 0; @@ -319,7 +319,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { do { c = 10*c + (ls->current-'0'); next(ls); - } while (++i<3 && isDigit(ls->current)); + } while (++i<3 && Common::isDigit(ls->current)); if (c > UCHAR_MAX) luaX_lexerror(ls, "escape sequence too large", TK_STRING); save(ls, c); @@ -410,7 +410,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { return TK_DOTS; /* ... */ else return TK_CONCAT; /* .. */ } - else if (!isDigit(ls->current)) return '.'; + else if (!Common::isDigit(ls->current)) return '.'; else { read_numeral(ls, seminfo); return TK_NUMBER; @@ -420,21 +420,21 @@ static int llex (LexState *ls, SemInfo *seminfo) { return TK_EOS; } default: { - if (isSpace(ls->current)) { + if (Common::isSpace(ls->current)) { lua_assert(!currIsNewline(ls)); next(ls); continue; } - else if (isDigit(ls->current)) { + else if (Common::isDigit(ls->current)) { read_numeral(ls, seminfo); return TK_NUMBER; } - else if (isAlpha(ls->current) || ls->current == '_') { + else if (Common::isAlpha(ls->current) || ls->current == '_') { /* identifier or reserved word */ TString *ts; do { save_and_next(ls); - } while (isAlnum(ls->current) || ls->current == '_'); + } while (Common::isAlnum(ls->current) || ls->current == '_'); ts = luaX_newstring(ls, luaZ_buffer(ls->buff), luaZ_bufflen(ls->buff)); if (ts->tsv.reserved > 0) /* reserved word? */ diff --git a/engines/sword25/util/lua/lobject.cpp b/engines/sword25/util/lua/lobject.cpp index 1890aaae6876..1ffee525562a 100644 --- a/engines/sword25/util/lua/lobject.cpp +++ b/engines/sword25/util/lua/lobject.cpp @@ -90,7 +90,7 @@ int luaO_str2d (const char *s, lua_Number *result) { if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ *result = cast_num(strtoul(s, &endptr, 16)); if (*endptr == '\0') return 1; /* most common case */ - while (isSpace(*endptr)) endptr++; + while (Common::isSpace(*endptr)) endptr++; if (*endptr != '\0') return 0; /* invalid trailing characters? */ return 1; } diff --git a/graphics/font.cpp b/graphics/font.cpp index 7b48fe999907..3b00cd85686c 100644 --- a/graphics/font.cpp +++ b/graphics/font.cpp @@ -184,7 +184,7 @@ int Font::wordWrapText(const Common::String &str, int maxWidth, Common::Array 0) { wrapper.add(line, lineWidth); // Trim left side - while (tmpStr.size() && isSpace(tmpStr[0])) { + while (tmpStr.size() && Common::isSpace(tmpStr[0])) { tmpStr.deleteChar(0); // This is not very fast, but it is the simplest way to // assure we do not mess something up because of kerning. diff --git a/gui/launcher.cpp b/gui/launcher.cpp index b23ef23511a0..d1e6569c56c3 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -90,7 +90,7 @@ class DomainEditTextWidget : public EditTextWidget { protected: bool tryInsertChar(byte c, int pos) { - if (isAlnum(c) || c == '-' || c == '_') { + if (Common::isAlnum(c) || c == '-' || c == '_') { _editString.insertChar(c, pos); return true; } From 02ebd552141173775b9462f4414083d3b8d49a80 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 20 Feb 2012 16:15:10 +0100 Subject: [PATCH 3/3] COMMON: Filter non-ASCII values in ctype.h-style isFOO functions --- common/util.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/common/util.cpp b/common/util.cpp index e605a267d5bb..3f97308d8ea9 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -415,32 +415,37 @@ void updateGameGUIOptions(const String &options, const String &langOption) { } } -// -// TODO: Instead of a blind cast, we might want to verify -// if c equals EOS; and/or is in the range -255..+255; -// and return false if it isn't. -// +#define ENSURE_ASCII_CHAR(c) \ + if (c < 0 || c > 127) \ + return false + bool isAlnum(int c) { + ENSURE_ASCII_CHAR(c); return isalnum((byte)c); } bool isAlpha(int c) { + ENSURE_ASCII_CHAR(c); return isalpha((byte)c); } bool isDigit(int c) { + ENSURE_ASCII_CHAR(c); return isdigit((byte)c); } bool isLower(int c) { + ENSURE_ASCII_CHAR(c); return islower((byte)c); } bool isSpace(int c) { + ENSURE_ASCII_CHAR(c); return isspace((byte)c); } bool isUpper(int c) { + ENSURE_ASCII_CHAR(c); return isupper((byte)c); }