scummvm/debug.cpp

109 lines
2.4 KiB
C++
Raw Normal View History

2003-08-15 18:00:22 +00:00
// Residual - Virtual machine to run LucasArts' 3D adventure games
2005-01-01 10:23:18 +00:00
// Copyright (C) 2003-2005 The ScummVM-Residual Team (www.scummvm.org)
2003-08-15 18:00:22 +00:00
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "stdafx.h"
#include "debug.h"
2005-01-01 12:27:57 +00:00
2003-08-15 18:00:22 +00:00
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <SDL.h>
2004-02-01 12:38:33 +00:00
const char *tag2str(uint32 tag) {
static char str[5];
str[0] = (char)(tag >> 24);
str[1] = (char)(tag >> 16);
str[2] = (char)(tag >> 8);
str[3] = (char)tag;
str[4] = '\0';
return str;
2004-02-01 12:38:33 +00:00
}
void hexdump(const byte * data, int len, int bytesPerLine) {
assert(1 <= bytesPerLine && bytesPerLine <= 32);
int i;
byte c;
int offset = 0;
2004-12-09 23:55:43 +00:00
while (len >= bytesPerLine) {
printf("%06x: ", offset);
for (i = 0; i < bytesPerLine; i++) {
printf("%02x ", data[i]);
if (i % 4 == 3)
printf(" ");
}
printf(" |");
for (i = 0; i < bytesPerLine; i++) {
c = data[i];
if (c < 32 || c >= 127)
c = '.';
printf("%c", c);
}
printf("|\n");
data += bytesPerLine;
len -= bytesPerLine;
offset += bytesPerLine;
}
2004-02-01 12:38:33 +00:00
if (len <= 0)
return;
2004-02-01 12:38:33 +00:00
printf("%06x: ", offset);
for (i = 0; i < bytesPerLine; i++) {
if (i < len)
printf("%02x ", data[i]);
else
printf(" ");
if (i % 4 == 3)
printf(" ");
}
printf(" |");
for (i = 0; i < len; i++) {
c = data[i];
if (c < 32 || c >= 127)
c = '.';
printf("%c", c);
}
for (; i < bytesPerLine; i++)
printf(" ");
printf("|\n");
2004-02-01 12:38:33 +00:00
}
2003-08-15 18:00:22 +00:00
void warning(const char *fmt, ...) {
std::fprintf(stderr, "WARNING: ");
2003-08-15 18:00:22 +00:00
std::va_list va;
2003-08-15 18:00:22 +00:00
va_start(va, fmt);
std::vfprintf(stderr, fmt, va);
va_end(va);
std::fprintf(stderr, "\n");
2003-08-15 18:00:22 +00:00
}
void error(const char *fmt, ...) {
std::fprintf(stderr, "ERROR: ");
2003-08-15 18:00:22 +00:00
std::va_list va;
2003-08-15 18:00:22 +00:00
va_start(va, fmt);
std::vfprintf(stderr, fmt, va);
va_end(va);
std::fprintf(stderr, "\n");
2003-08-15 18:00:22 +00:00
exit(1);
2003-08-15 18:00:22 +00:00
}