2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-07-12 16:24:11 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-07-12 16:24:11 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-28 00:15:49 +00:00
|
|
|
#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
|
2012-12-13 19:52:09 +00:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_isprint
|
2012-01-28 00:15:49 +00:00
|
|
|
|
|
|
|
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/util.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/debug.h"
|
2002-07-12 16:24:11 +00:00
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
namespace Common {
|
2002-07-12 16:24:11 +00:00
|
|
|
|
2002-09-16 10:42:12 +00:00
|
|
|
//
|
2003-05-02 21:29:05 +00:00
|
|
|
// Print hexdump of the data passed in
|
2002-09-16 10:42:12 +00:00
|
|
|
//
|
2010-06-26 15:48:03 +00:00
|
|
|
void hexdump(const byte *data, int len, int bytesPerLine, int startOffset) {
|
2003-10-04 11:50:21 +00:00
|
|
|
assert(1 <= bytesPerLine && bytesPerLine <= 32);
|
2002-07-25 16:29:07 +00:00
|
|
|
int i;
|
|
|
|
byte c;
|
2009-05-12 07:07:17 +00:00
|
|
|
int offset = startOffset;
|
2003-10-04 11:50:21 +00:00
|
|
|
while (len >= bytesPerLine) {
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN("%06x: ", offset);
|
2003-10-04 11:50:21 +00:00
|
|
|
for (i = 0; i < bytesPerLine; i++) {
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN("%02x ", data[i]);
|
2003-05-04 13:46:06 +00:00
|
|
|
if (i % 4 == 3)
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN(" ");
|
2003-05-04 13:46:06 +00:00
|
|
|
}
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN(" |");
|
2003-10-04 11:50:21 +00:00
|
|
|
for (i = 0; i < bytesPerLine; i++) {
|
2002-07-25 16:29:07 +00:00
|
|
|
c = data[i];
|
2002-08-31 14:14:24 +00:00
|
|
|
if (c < 32 || c >= 127)
|
2002-07-25 16:29:07 +00:00
|
|
|
c = '.';
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN("%c", c);
|
2002-07-25 16:29:07 +00:00
|
|
|
}
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN("|\n");
|
2003-10-04 11:50:21 +00:00
|
|
|
data += bytesPerLine;
|
|
|
|
len -= bytesPerLine;
|
|
|
|
offset += bytesPerLine;
|
2002-07-25 16:29:07 +00:00
|
|
|
}
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
if (len <= 0)
|
2002-07-26 17:40:04 +00:00
|
|
|
return;
|
|
|
|
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN("%06x: ", offset);
|
2003-12-13 17:33:21 +00:00
|
|
|
for (i = 0; i < bytesPerLine; i++) {
|
|
|
|
if (i < len)
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN("%02x ", data[i]);
|
2003-12-13 17:33:21 +00:00
|
|
|
else
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN(" ");
|
2003-05-04 13:46:06 +00:00
|
|
|
if (i % 4 == 3)
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN(" ");
|
2003-05-04 13:46:06 +00:00
|
|
|
}
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN(" |");
|
2002-07-25 16:29:07 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
c = data[i];
|
2002-08-31 14:14:24 +00:00
|
|
|
if (c < 32 || c >= 127)
|
2002-07-25 16:29:07 +00:00
|
|
|
c = '.';
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN("%c", c);
|
2002-07-25 16:29:07 +00:00
|
|
|
}
|
2003-10-04 11:50:21 +00:00
|
|
|
for (; i < bytesPerLine; i++)
|
2010-11-01 16:04:18 +00:00
|
|
|
debugN(" ");
|
|
|
|
debugN("|\n");
|
2002-07-25 16:29:07 +00:00
|
|
|
}
|
2002-09-15 09:06:58 +00:00
|
|
|
|
2009-01-30 01:17:12 +00:00
|
|
|
|
2003-10-17 15:35:46 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
2011-08-06 07:47:19 +00:00
|
|
|
bool parseBool(const String &val, bool &valAsBool) {
|
2010-04-06 09:27:13 +00:00
|
|
|
if (val.equalsIgnoreCase("true") ||
|
|
|
|
val.equalsIgnoreCase("yes") ||
|
|
|
|
val.equals("1")) {
|
|
|
|
valAsBool = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (val.equalsIgnoreCase("false") ||
|
|
|
|
val.equalsIgnoreCase("no") ||
|
|
|
|
val.equals("0")) {
|
|
|
|
valAsBool = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
2012-02-20 15:15:10 +00:00
|
|
|
#define ENSURE_ASCII_CHAR(c) \
|
|
|
|
if (c < 0 || c > 127) \
|
|
|
|
return false
|
|
|
|
|
2012-01-28 00:15:49 +00:00
|
|
|
bool isAlnum(int c) {
|
2012-02-20 15:15:10 +00:00
|
|
|
ENSURE_ASCII_CHAR(c);
|
2012-01-28 00:15:49 +00:00
|
|
|
return isalnum((byte)c);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAlpha(int c) {
|
2012-02-20 15:15:10 +00:00
|
|
|
ENSURE_ASCII_CHAR(c);
|
2012-01-28 00:15:49 +00:00
|
|
|
return isalpha((byte)c);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDigit(int c) {
|
2012-02-20 15:15:10 +00:00
|
|
|
ENSURE_ASCII_CHAR(c);
|
2012-01-28 00:15:49 +00:00
|
|
|
return isdigit((byte)c);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isLower(int c) {
|
2012-02-20 15:15:10 +00:00
|
|
|
ENSURE_ASCII_CHAR(c);
|
2012-01-28 00:15:49 +00:00
|
|
|
return islower((byte)c);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSpace(int c) {
|
2012-02-20 15:15:10 +00:00
|
|
|
ENSURE_ASCII_CHAR(c);
|
2012-01-28 00:15:49 +00:00
|
|
|
return isspace((byte)c);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isUpper(int c) {
|
2012-02-20 15:15:10 +00:00
|
|
|
ENSURE_ASCII_CHAR(c);
|
2012-01-28 00:15:49 +00:00
|
|
|
return isupper((byte)c);
|
|
|
|
}
|
2012-02-20 15:03:39 +00:00
|
|
|
|
2012-12-13 19:52:09 +00:00
|
|
|
bool isPrint(int c) {
|
|
|
|
ENSURE_ASCII_CHAR(c);
|
|
|
|
return isprint((byte)c);
|
|
|
|
}
|
2012-02-20 15:03:39 +00:00
|
|
|
} // End of namespace Common
|