From: Youness Alaoui Date: Sun, 9 Jan 2011 11:20:18 +0000 (-0500) Subject: Remove variable declaration in .h file and clean BOM handling code X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=433cf00c29676c5dbb0fd6040344da53a60c1d54;p=console%2FRCOMage.git Remove variable declaration in .h file and clean BOM handling code --- diff --git a/general.h b/general.h index 198195d..d1457a0 100644 --- a/general.h +++ b/general.h @@ -55,10 +55,10 @@ typedef int16_t int16; typedef uint32_t uint32; typedef int32_t int32; -const uint32 UTF8_BOM = 0xBFBBEF; -const uint16 UTF16_BOM = 0xFEFF; -const uint32 UTF32_BOM = 0x0000FEFF; +#define UTF8_BOM ((uint32) 0xBFBBEF) +#define UTF16_BOM ((uint16) 0xFEFF) +#define UTF32_BOM ((uint32) 0x0000FEFF) #define PACK_STRUCT(nam, struc) typedef struct struc __attribute__ ((packed)) nam diff --git a/xmlread.c b/xmlread.c index 9750f6f..074650d 100644 --- a/xmlread.c +++ b/xmlread.c @@ -538,25 +538,28 @@ void parse_entry(xmlNodePtr node, rRCOEntry* entry, rRCOFile* rco, rcoxml_read_f // do we have a BOM? unsigned char bom[4] = {0x80, 0x80, 0x80, 0x80}; // dummy values that aren't used char srcFmt[10] = "", destFmt[8]; - uint32 tmp32 = ENDIAN_SWAP(UTF32_BOM); - uint16 tmp16 = ENDIAN_SWAP(UTF16_BOM); + uint32 bom32le = UTF32_BOM; + uint32 bom32be = ENDIAN_SWAP(UTF32_BOM); + uint16 bom16le = UTF16_BOM; + uint16 bom16be = ENDIAN_SWAP(UTF16_BOM); + uint32 bom8 = UTF8_BOM; uint bomLen = (te->format == RCO_TEXT_FMT_UTF32 ? 4 : (te->format == RCO_TEXT_FMT_UTF8 ? 3 : 2)); make_iconv_charset(destFmt, te->format, rco->eSwap); fileread(fp, bom, 4); - if(!memcmp(bom, &UTF32_BOM, sizeof(UTF32_BOM))) { + if(!memcmp(bom, &bom32le, sizeof(bom32le))) { strcpy(srcFmt, "utf-32le"); bomLen = 4; - } else if(!memcmp(bom, &tmp32, sizeof(tmp32))) { + } else if(!memcmp(bom, &bom32be, sizeof(bom32be))) { strcpy(srcFmt, "utf-32be"); bomLen = 4; - } else if(!memcmp(bom, &UTF16_BOM, sizeof(UTF16_BOM))) { + } else if(!memcmp(bom, &bom16le, sizeof(bom16le))) { strcpy(srcFmt, "utf-16le"); bomLen = 2; - } else if(!memcmp(bom, &tmp16, sizeof(tmp16))) { + } else if(!memcmp(bom, &bom16be, sizeof(bom16be))) { strcpy(srcFmt, "utf-16be"); bomLen = 2; - } else if(bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF) { + } else if(!memcmp(bom, &bom8, 3)) { strcpy(srcFmt, "utf-8"); bomLen = 3; } else { // don't convert