Skip to content

Commit

Permalink
COMMON: Replace MKID_BE by MKTAG
Browse files Browse the repository at this point in the history
MKID_BE relied on unspecified behavior of the C++ compiler,
and as such was always a bit unsafe. The new MKTAG macro
is slightly less elegant, but does no longer depend on the
behavior of the compiler.
Inspired by FFmpeg, which has an almost identical macro.
  • Loading branch information
fingolfin committed Apr 12, 2011
1 parent a8b3501 commit 0ce2ca4
Show file tree
Hide file tree
Showing 95 changed files with 801 additions and 817 deletions.
2 changes: 1 addition & 1 deletion audio/mods/module.cpp
Expand Up @@ -113,7 +113,7 @@ const int16 Module::periods[16][60] = {
108 , 101 , 96 , 90 , 85 , 80 , 76 , 72 , 68 , 64 , 60 , 57 }};

const uint32 Module::signatures[] = {
MKID_BE('M.K.'), MKID_BE('M!K!'), MKID_BE('FLT4')
MKTAG('M','.','K','.'), MKTAG('M','!','K','!'), MKTAG('F','L','T','4')
};

bool Module::load(Common::SeekableReadStream &st, int offs) {
Expand Down
4 changes: 2 additions & 2 deletions audio/mods/rjp1.cpp
Expand Up @@ -138,7 +138,7 @@ Rjp1::~Rjp1() {
}

bool Rjp1::load(Common::SeekableReadStream *songData, Common::SeekableReadStream *instrumentsData) {
if (songData->readUint32BE() == MKID_BE('RJP1') && songData->readUint32BE() == MKID_BE('SMOD')) {
if (songData->readUint32BE() == MKTAG('R','J','P','1') && songData->readUint32BE() == MKTAG('S','M','O','D')) {
for (int i = 0; i < 7; ++i) {
uint32 size = songData->readUint32BE();
_vars.songData[i] = (uint8 *)malloc(size);
Expand Down Expand Up @@ -167,7 +167,7 @@ bool Rjp1::load(Common::SeekableReadStream *songData, Common::SeekableReadStream
}
}

if (instrumentsData->readUint32BE() == MKID_BE('RJP1')) {
if (instrumentsData->readUint32BE() == MKTAG('R','J','P','1')) {
uint32 size = instrumentsData->size() - 4;
_vars.instData = (int8 *)malloc(size);
if (!_vars.instData)
Expand Down
20 changes: 2 additions & 18 deletions common/endian.h
Expand Up @@ -141,27 +141,13 @@

/**
* A wrapper macro used around four character constants, like 'DATA', to
* ensure portability. Typical usage: MKID_BE('DATA').
* ensure portability. Typical usage: MKTAG('D','A','T','A').
*
* Why is this necessary? The C/C++ standard does not define the endianess to
* be used for character constants. Hence if one uses multi-byte character
* constants, a potential portability problem opens up.
*
* Fortunately, a semi-standard has been established: On almost all systems
* and compilers, multi-byte character constants are encoded using the big
* endian convention (probably in analogy to the encoding of string constants).
* Still some systems differ. This is why we provide the MKID_BE macro. If
* you wrap your four character constants with it, the result will always be
* BE encoded, even on systems which differ from the default BE encoding.
*
* For the latter systems we provide the INVERSE_MKID override.
*/
#if defined(INVERSE_MKID)
#define MKID_BE(a) SWAP_CONSTANT_32(a)

#else
# define MKID_BE(a) ((uint32)(a))
#endif
#define MKTAG(a0,a1,a2,a3) ((a0) | ((a1) << 8) | ((a2) << 16) | ((a3) << 24))

// Functions for reading/writing native Integers,
// this transparently handles the need for alignment
Expand Down Expand Up @@ -331,8 +317,6 @@

#elif defined(SCUMM_BIG_ENDIAN)

#define MKID_BE(a) ((uint32)(a))

#define READ_BE_UINT16(a) READ_UINT16(a)
#define READ_BE_UINT32(a) READ_UINT32(a)

Expand Down
96 changes: 48 additions & 48 deletions common/iff_container.h
Expand Up @@ -35,111 +35,111 @@ namespace Common {

typedef uint32 IFF_ID;

#define ID_FORM MKID_BE('FORM')
#define ID_FORM MKTAG('F','O','R','M')
/* EA IFF 85 group identifier */
#define ID_CAT MKID_BE('CAT ')
#define ID_CAT MKTAG('C','A','T',' ')
/* EA IFF 85 group identifier */
#define ID_LIST MKID_BE('LIST')
#define ID_LIST MKTAG('L','I','S','T')
/* EA IFF 85 group identifier */
#define ID_PROP MKID_BE('PROP')
#define ID_PROP MKTAG('P','R','O','P')
/* EA IFF 85 group identifier */
#define ID_END MKID_BE('END ')
#define ID_END MKTAG('E','N','D',' ')
/* unofficial END-of-FORM identifier (see Amiga RKM Devices Ed.3
page 376) */
#define ID_ILBM MKID_BE('ILBM')
#define ID_ILBM MKTAG('I','L','B','M')
/* EA IFF 85 raster bitmap form */
#define ID_DEEP MKID_BE('DEEP')
#define ID_DEEP MKTAG('D','E','E','P')
/* Chunky pixel image files (Used in TV Paint) */
#define ID_RGB8 MKID_BE('RGB8')
#define ID_RGB8 MKTAG('R','G','B','8')
/* RGB image forms, Turbo Silver (Impulse) */
#define ID_RGBN MKID_BE('RGBN')
#define ID_RGBN MKTAG('R','G','B','N')
/* RGB image forms, Turbo Silver (Impulse) */
#define ID_PBM MKID_BE('PBM ')
#define ID_PBM MKTAG('P','B','M',' ')
/* 256-color chunky format (DPaint 2 ?) */
#define ID_ACBM MKID_BE('ACBM')
#define ID_ACBM MKTAG('A','C','B','M')
/* Amiga Contiguous Bitmap (AmigaBasic) */
#define ID_8SVX MKID_BE('8SVX')
#define ID_8SVX MKTAG('8','S','V','X')
/* Amiga 8 bits voice */

/* generic */

#define ID_FVER MKID_BE('FVER')
#define ID_FVER MKTAG('F','V','E','R')
/* AmigaOS version string */
#define ID_JUNK MKID_BE('JUNK')
#define ID_JUNK MKTAG('J','U','N','K')
/* always ignore this chunk */
#define ID_ANNO MKID_BE('ANNO')
#define ID_ANNO MKTAG('A','N','N','O')
/* EA IFF 85 Generic Annotation chunk */
#define ID_AUTH MKID_BE('AUTH')
#define ID_AUTH MKTAG('A','U','T','H')
/* EA IFF 85 Generic Author chunk */
#define ID_CHRS MKID_BE('CHRS')
#define ID_CHRS MKTAG('C','H','R','S')
/* EA IFF 85 Generic character string chunk */
#define ID_NAME MKID_BE('NAME')
#define ID_NAME MKTAG('N','A','M','E')
/* EA IFF 85 Generic Name of art, music, etc. chunk */
#define ID_TEXT MKID_BE('TEXT')
#define ID_TEXT MKTAG('T','E','X','T')
/* EA IFF 85 Generic unformatted ASCII text chunk */
#define ID_copy MKID_BE('(c) ')
#define ID_copy MKTAG('(','c',')',' ')
/* EA IFF 85 Generic Copyright text chunk */

/* ILBM chunks */

#define ID_BMHD MKID_BE('BMHD')
#define ID_BMHD MKTAG('B','M','H','D')
/* ILBM BitmapHeader */
#define ID_CMAP MKID_BE('CMAP')
#define ID_CMAP MKTAG('C','M','A','P')
/* ILBM 8bit RGB colormap */
#define ID_GRAB MKID_BE('GRAB')
#define ID_GRAB MKTAG('G','R','A','B')
/* ILBM "hotspot" coordiantes */
#define ID_DEST MKID_BE('DEST')
#define ID_DEST MKTAG('D','E','S','T')
/* ILBM destination image info */
#define ID_SPRT MKID_BE('SPRT')
#define ID_SPRT MKTAG('S','P','R','T')
/* ILBM sprite identifier */
#define ID_CAMG MKID_BE('CAMG')
#define ID_CAMG MKTAG('C','A','M','G')
/* Amiga viewportmodes */
#define ID_BODY MKID_BE('BODY')
#define ID_BODY MKTAG('B','O','D','Y')
/* ILBM image data */
#define ID_CRNG MKID_BE('CRNG')
#define ID_CRNG MKTAG('C','R','N','G')
/* color cycling */
#define ID_CCRT MKID_BE('CCRT')
#define ID_CCRT MKTAG('C','C','R','T')
/* color cycling */
#define ID_CLUT MKID_BE('CLUT')
#define ID_CLUT MKTAG('C','L','U','T')
/* Color Lookup Table chunk */
#define ID_DPI MKID_BE('DPI ')
#define ID_DPI MKTAG('D','P','I',' ')
/* Dots per inch chunk */
#define ID_DPPV MKID_BE('DPPV')
#define ID_DPPV MKTAG('D','P','P','V')
/* DPaint perspective chunk (EA) */
#define ID_DRNG MKID_BE('DRNG')
#define ID_DRNG MKTAG('D','R','N','G')
/* DPaint IV enhanced color cycle chunk (EA) */
#define ID_EPSF MKID_BE('EPSF')
#define ID_EPSF MKTAG('E','P','S','F')
/* Encapsulated Postscript chunk */
#define ID_CMYK MKID_BE('CMYK')
#define ID_CMYK MKTAG('C','M','Y','K')
/* Cyan, Magenta, Yellow, & Black color map (Soft-Logik) */
#define ID_CNAM MKID_BE('CNAM')
#define ID_CNAM MKTAG('C','N','A','M')
/* Color naming chunk (Soft-Logik) */
#define ID_PCHG MKID_BE('PCHG')
#define ID_PCHG MKTAG('P','C','H','G')
/* Line by line palette control information (Sebastiano Vigna) */
#define ID_PRVW MKID_BE('PRVW')
#define ID_PRVW MKTAG('P','R','V','W')
/* A mini duplicate ILBM used for preview (Gary Bonham) */
#define ID_XBMI MKID_BE('XBMI')
#define ID_XBMI MKTAG('X','B','M','I')
/* eXtended BitMap Information (Soft-Logik) */
#define ID_CTBL MKID_BE('CTBL')
#define ID_CTBL MKTAG('C','T','B','L')
/* Newtek Dynamic Ham color chunk */
#define ID_DYCP MKID_BE('DYCP')
#define ID_DYCP MKTAG('D','Y','C','P')
/* Newtek Dynamic Ham chunk */
#define ID_SHAM MKID_BE('SHAM')
#define ID_SHAM MKTAG('S','H','A','M')
/* Sliced HAM color chunk */
#define ID_ABIT MKID_BE('ABIT')
#define ID_ABIT MKTAG('A','B','I','T')
/* ACBM body chunk */
#define ID_DCOL MKID_BE('DCOL')
#define ID_DCOL MKTAG('D','C','O','L')
/* unofficial direct color */
#define ID_DPPS MKID_BE('DPPS')
#define ID_DPPS MKTAG('D','P','P','S')
/* ? */
#define ID_TINY MKID_BE('TINY')
#define ID_TINY MKTAG('T','I','N','Y')
/* ? */
#define ID_DPPV MKID_BE('DPPV')
#define ID_DPPV MKTAG('D','P','P','V')
/* ? */

/* 8SVX chunks */

#define ID_VHDR MKID_BE('VHDR')
#define ID_VHDR MKTAG('V','H','D','R')
/* 8SVX Voice8Header */


Expand Down
2 changes: 1 addition & 1 deletion common/winexe_ne.cpp
Expand Up @@ -95,7 +95,7 @@ bool NEResources::loadFromCompressedEXE(const String &fileName) {
return false;

// First part of the signature
if (file.readUint32BE() != MKID_BE('SZDD'))
if (file.readUint32BE() != MKTAG('S','Z','D','D'))
return false;

// Second part of the signature
Expand Down
2 changes: 1 addition & 1 deletion common/winexe_pe.cpp
Expand Up @@ -78,7 +78,7 @@ bool PEResources::loadFromEXE(SeekableReadStream *stream) {

stream->seek(peOffset);

if (stream->readUint32BE() != MKID_BE('PE\0\0'))
if (stream->readUint32BE() != MKTAG('P','E',0,0))
return false;

stream->skip(2);
Expand Down
4 changes: 2 additions & 2 deletions engines/agi/detection.cpp
Expand Up @@ -218,7 +218,7 @@ bool AgiMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameD
}

SaveStateList AgiMetaEngine::listSaves(const char *target) const {
const uint32 AGIflag = MKID_BE('AGI:');
const uint32 AGIflag = MKTAG('A','G','I',':');
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
char saveDesc[31];
Expand Down Expand Up @@ -257,7 +257,7 @@ void AgiMetaEngine::removeSaveState(const char *target, int slot) const {
}

SaveStateDescriptor AgiMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
const uint32 AGIflag = MKID_BE('AGI:');
const uint32 AGIflag = MKTAG('A','G','I',':');
char fileName[MAXPATHLEN];
sprintf(fileName, "%s.%03d", target, slot);

Expand Down
4 changes: 2 additions & 2 deletions engines/agi/preagi_mickey.cpp
Expand Up @@ -1003,7 +1003,7 @@ bool Mickey::loadGame() {
if (_vm->getSelection(kSelAnyKey) == 0)
return false;
} else {
if (infile->readUint32BE() != MKID_BE('MICK')) {
if (infile->readUint32BE() != MKTAG('M','I','C','K')) {
warning("Mickey::loadGame wrong save game format");
return false;
}
Expand Down Expand Up @@ -1120,7 +1120,7 @@ void Mickey::saveGame() {
if (_vm->getSelection(kSelAnyKey) == 0)
return;
} else {
outfile->writeUint32BE(MKID_BE('MICK')); // header
outfile->writeUint32BE(MKTAG('M','I','C','K')); // header
outfile->writeByte(MSA_SAVEGAME_VERSION);

outfile->writeByte(_game.iRoom);
Expand Down
4 changes: 2 additions & 2 deletions engines/agi/preagi_winnie.cpp
Expand Up @@ -1159,7 +1159,7 @@ void Winnie::saveGame() {
if (!(outfile = _vm->getSaveFileMan()->openForSaving(szFile)))
return;

outfile->writeUint32BE(MKID_BE('WINN')); // header
outfile->writeUint32BE(MKTAG('W','I','N','N')); // header
outfile->writeByte(WTP_SAVEGAME_VERSION);

outfile->writeByte(_game.fSound);
Expand Down Expand Up @@ -1195,7 +1195,7 @@ void Winnie::loadGame() {
if (!(infile = _vm->getSaveFileMan()->openForLoading(szFile)))
return;

if (infile->readUint32BE() == MKID_BE('WINN')) {
if (infile->readUint32BE() == MKTAG('W','I','N','N')) {
saveVersion = infile->readByte();
if (saveVersion != WTP_SAVEGAME_VERSION)
warning("Old save game version (%d, current version is %d). Will try and read anyway, but don't be surprised if bad things happen", saveVersion, WTP_SAVEGAME_VERSION);
Expand Down
2 changes: 1 addition & 1 deletion engines/agi/saveload.cpp
Expand Up @@ -53,7 +53,7 @@

namespace Agi {

static const uint32 AGIflag = MKID_BE('AGI:');
static const uint32 AGIflag = MKTAG('A','G','I',':');

int AgiEngine::saveGame(const char *fileName, const char *description) {
char gameIDstring[8] = "gameIDX";
Expand Down
2 changes: 1 addition & 1 deletion engines/agos/animation.cpp
Expand Up @@ -301,7 +301,7 @@ void MoviePlayerDXA::stopVideo() {
void MoviePlayerDXA::startSound() {
uint32 offset, size;

if (getSoundTag() == MKID_BE('WAVE')) {
if (getSoundTag() == MKTAG('W','A','V','E')) {
size = _fileStream->readUint32BE();

if (_sequenceNum) {
Expand Down
4 changes: 2 additions & 2 deletions engines/cine/saveload.h
Expand Up @@ -71,14 +71,14 @@ enum CineSaveGameFormat {
};

/** Identifier for the temporary Operation Stealth savegame format. */
static const uint32 TEMP_OS_FORMAT_ID = MKID_BE('TEMP');
static const uint32 TEMP_OS_FORMAT_ID = MKTAG('T','E','M','P');

/** The current version number of Operation Stealth's savegame format. */
static const uint32 CURRENT_OS_SAVE_VER = 1;

/** Chunk header used by the temporary Operation Stealth savegame format. */
struct ChunkHeader {
uint32 id; ///< Identifier (e.g. MKID_BE('TEMP'))
uint32 id; ///< Identifier (e.g. MKTAG('T','E','M','P'))
uint32 version; ///< Version number
uint32 size; ///< Size of the chunk after this header in bytes
};
Expand Down
14 changes: 7 additions & 7 deletions engines/gob/save/savefile.h
Expand Up @@ -48,8 +48,8 @@ class SaveHeader {
public:
/** The size of the header. */
static const int kSize = 20;
static const uint32 kID1 = MKID_BE('\0SCV');
static const uint32 kID2 = MKID_BE('MGOB');
static const uint32 kID1 = MKTAG(0,'S','C','V');
static const uint32 kID2 = MKTAG('M','G','O','B');

SaveHeader(uint32 type = 0, uint32 version = 0, uint32 size = 0);

Expand Down Expand Up @@ -106,7 +106,7 @@ class SavePart {
class SavePartMem : public SavePart {
public:
static const uint32 kVersion = 1;
static const uint32 kID = MKID_BE('PMEM');
static const uint32 kID = MKTAG('P','M','E','M');

SavePartMem(uint32 size);
~SavePartMem();
Expand All @@ -128,7 +128,7 @@ class SavePartMem : public SavePart {
class SavePartVars : public SavePart {
public:
static const uint32 kVersion = 1;
static const uint32 kID = MKID_BE('VARS');
static const uint32 kID = MKTAG('V','A','R','S');

SavePartVars(GobEngine *vm, uint32 size);
~SavePartVars();
Expand All @@ -155,7 +155,7 @@ class SavePartVars : public SavePart {
class SavePartSprite : public SavePart {
public:
static const uint32 kVersion = 2;
static const uint32 kID = MKID_BE('SPRT');
static const uint32 kID = MKTAG('S','P','R','T');

SavePartSprite(uint32 width, uint32 height, bool trueColor = false);
~SavePartSprite();
Expand Down Expand Up @@ -193,7 +193,7 @@ class SavePartSprite : public SavePart {
class SavePartInfo : public SavePart {
public:
static const uint32 kVersion = 1;
static const uint32 kID = MKID_BE('INFO');
static const uint32 kID = MKTAG('I','N','F','O');

/**
* The constructor.
Expand Down Expand Up @@ -235,7 +235,7 @@ class SavePartInfo : public SavePart {
class SaveContainer {
public:
static const uint32 kVersion = 1;
static const uint32 kID = MKID_BE('CONT');
static const uint32 kID = MKTAG('C','O','N','T');

/**
* The constructor.
Expand Down
2 changes: 1 addition & 1 deletion engines/groovie/cursor.cpp
Expand Up @@ -404,7 +404,7 @@ GrvCursorMan_v2::GrvCursorMan_v2(OSystem *system) :
// Verify the signature
uint32 tmp32 = iconsFile.readUint32BE();
uint16 tmp16 = iconsFile.readUint16LE();
if (tmp32 != MKID_BE('icon') || tmp16 != 1)
if (tmp32 != MKTAG('i','c','o','n') || tmp16 != 1)
error("Groovie::Cursor: icons.ph signature failed: %s %d", tag2str(tmp32), tmp16);


Expand Down

0 comments on commit 0ce2ca4

Please sign in to comment.