mirror of https://github.com/OpenTTD/OpenTTD
(svn r23801) -Fix: reading the utf-8 BOM from AI/GS files on big-endian machines failed
parent
48717ade9c
commit
f5b6a9db5c
|
@ -183,7 +183,7 @@ typedef char SQChar;
|
||||||
#define scstrdup strdup
|
#define scstrdup strdup
|
||||||
#define scstrrchr strrchr
|
#define scstrrchr strrchr
|
||||||
#define scstrcat strcat
|
#define scstrcat strcat
|
||||||
#define MAX_CHAR 0xFF
|
#define MAX_CHAR 0xFFFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SQUIRREL_VERSION _SC("Squirrel 2.2.5 stable - With custom OpenTTD modifications")
|
#define SQUIRREL_VERSION _SC("Squirrel 2.2.5 stable - With custom OpenTTD modifications")
|
||||||
|
|
|
@ -2,11 +2,7 @@
|
||||||
#ifndef _SQLEXER_H_
|
#ifndef _SQLEXER_H_
|
||||||
#define _SQLEXER_H_
|
#define _SQLEXER_H_
|
||||||
|
|
||||||
#ifdef SQUNICODE
|
typedef unsigned short LexChar;
|
||||||
typedef SQChar LexChar;
|
|
||||||
#else
|
|
||||||
typedef unsigned char LexChar;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct SQLexer
|
struct SQLexer
|
||||||
{
|
{
|
||||||
|
|
|
@ -413,14 +413,14 @@ static SQInteger _io_file_lexfeed_UTF8(SQUserPointer file)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SQInteger _io_file_lexfeed_UCS2_LE(SQUserPointer file)
|
static SQInteger _io_file_lexfeed_UCS2_no_swap(SQUserPointer file)
|
||||||
{
|
{
|
||||||
wchar_t c;
|
wchar_t c;
|
||||||
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) return (SQChar)c;
|
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) return (SQChar)c;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SQInteger _io_file_lexfeed_UCS2_BE(SQUserPointer file)
|
static SQInteger _io_file_lexfeed_UCS2_swap(SQUserPointer file)
|
||||||
{
|
{
|
||||||
unsigned short c;
|
unsigned short c;
|
||||||
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) {
|
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) {
|
||||||
|
@ -472,9 +472,15 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printer
|
||||||
FioFCloseFile(file);
|
FioFCloseFile(file);
|
||||||
return sq_throwerror(vm, _SC("Couldn't read bytecode"));
|
return sq_throwerror(vm, _SC("Couldn't read bytecode"));
|
||||||
}
|
}
|
||||||
case 0xFFFE: func = _io_file_lexfeed_UCS2_BE; break; // UTF-16 little endian
|
case 0xFFFE:
|
||||||
case 0xFEFF: func = _io_file_lexfeed_UCS2_LE; break; // UTF-16 big endian
|
/* Either this file is encoded as big-endian and we're on a little-endian
|
||||||
|
* machine, or this file is encoded as little-endian and we're on a big-endian
|
||||||
|
* machine. Either way, swap the bytes of every word we read. */
|
||||||
|
func = _io_file_lexfeed_UCS2_swap;
|
||||||
|
break;
|
||||||
|
case 0xFEFF: func = _io_file_lexfeed_UCS2_no_swap; break;
|
||||||
case 0xBBEF: // UTF-8
|
case 0xBBEF: // UTF-8
|
||||||
|
case 0xEFBB: // UTF-8 on big-endian machine
|
||||||
if (fread(&uc, 1, sizeof(uc), file) == 0) {
|
if (fread(&uc, 1, sizeof(uc), file) == 0) {
|
||||||
FioFCloseFile(file);
|
FioFCloseFile(file);
|
||||||
return sq_throwerror(vm, _SC("I/O error"));
|
return sq_throwerror(vm, _SC("I/O error"));
|
||||||
|
|
Loading…
Reference in New Issue