spaces fix

This commit is contained in:
Gergely Polonkai 2015-10-04 14:07:19 +02:00
parent 0e332f2709
commit 311bdf84bc
3 changed files with 82 additions and 82 deletions

View File

@ -18,15 +18,15 @@ Random rndGen;
static void initScreen()
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
throw Exception(std::wstring(L"Error initializing SDL: ") +
throw Exception(std::wstring(L"Error initializing SDL: ") +
fromMbcs(SDL_GetError()));
atexit(SDL_Quit);
if (TTF_Init())
throw Exception(L"Error initializing font engine");
screen.setMode(VideoMode(800, 600, 24,
screen.setMode(VideoMode(800, 600, 24,
getStorage()->get(L"fullscreen", 1) != 0));
screen.initCursors();
SDL_Surface *mouse = loadImage(L"cursor.bmp");
SDL_SetColorKey(mouse, SDL_SRCCOLORKEY, SDL_MapRGB(mouse->format, 0, 0, 0));
screen.setMouseImage(mouse);
@ -51,7 +51,7 @@ static void initAudio()
static std::wstring getResourcesPath(const std::wstring& path)
{
int idx = path.find_last_of(L'/');
return path.substr(0, idx) + L"/../../";
return path.substr(0, idx) + L"/../../";
}
#endif
@ -59,7 +59,7 @@ static void loadResources(const std::wstring &selfPath)
{
StringList dirs;
#ifdef WIN32
dirs.push_back(getStorage()->get(L"path", L"") + L"\\res");
dirs.push_back(getStorage()->get(L"path", L"") + L"\\res");
#else
#ifdef __APPLE__
dirs.push_back(getResourcesPath(selfPath));
@ -80,8 +80,8 @@ static void loadResources(const std::wstring &selfPath)
if (1124832535L + 60L*60L*24L*40L < time(NULL)) {
Font font(L"laudcn2.ttf", 16);
Area area;
showMessageWindow(&area, L"darkpattern.bmp",
700, 100, &font, 255,255,255,
showMessageWindow(&area, L"darkpattern.bmp",
700, 100, &font, 255,255,255,
msg(L"expired"));
}
}*/
@ -93,7 +93,7 @@ int main(int argc, char *argv[])
#ifndef WIN32
ensureDirExists(fromMbcs(getenv("HOME")) + std::wstring(L"/.einstein"));
#endif
try {
loadResources(fromUtf8(argv[0]));
initScreen();
@ -107,7 +107,6 @@ int main(int argc, char *argv[])
std::cerr << L"ERROR: Unknown exception" << std::endl;
}
screen.doneCursors();
return 0;
}

View File

@ -28,9 +28,9 @@ class UnpackedResourceStream: public ResourceStream
size_t size;
long offset;
long pos;
public:
UnpackedResourceStream(std::ifstream &stream, long offset,
UnpackedResourceStream(std::ifstream &stream, long offset,
size_t size);
public:
@ -40,7 +40,7 @@ class UnpackedResourceStream: public ResourceStream
virtual long getPos() { return pos; };
};
UnpackedResourceStream::UnpackedResourceStream(std::ifstream &s,
UnpackedResourceStream::UnpackedResourceStream(std::ifstream &s,
long off, size_t sz): stream(s)
{
offset = off;
@ -81,7 +81,7 @@ class MemoryResourceStream: public ResourceStream
size_t size;
ResVariant *resource;
long pos;
public:
MemoryResourceStream(ResVariant *resource);
virtual ~MemoryResourceStream();
@ -140,15 +140,15 @@ ResourceFile::ResourceFile(const std::wstring &fileName, Buffer *buf):
buffer = new Buffer();
ownBuffer = true;
}
stream.open(toMbcs(fileName).c_str(), std::ios::in | std::ios::binary);
if (stream.fail())
throw Exception(L"Error loading resource file '" + name + L"'");
char sign[4];
stream.read(sign, 4);
int readed = stream.gcount();
if (stream.fail() || (readed != 4) || (sign[0] != 'C') ||
if (stream.fail() || (readed != 4) || (sign[0] != 'C') ||
(sign[1] != 'R') || (sign[2] != 'F') || sign[3])
throw Exception(L"Invalid resource file '" + name + L"'");
@ -159,7 +159,7 @@ ResourceFile::ResourceFile(const std::wstring &fileName, Buffer *buf):
priority = readInt(stream);
readed += stream.gcount();
if (stream.fail() || (readed != 12) || (major != 2) || (minor < 0))
throw Exception(L"Incompatible version of resource file '" +
throw Exception(L"Incompatible version of resource file '" +
name + L"'");
}
@ -193,7 +193,7 @@ void ResourceFile::getDirectory(Directory &directory)
entry.group = readString(stream);
directory.push_back(entry);
}
if (stream.fail())
throw Exception(L"Error reading " + name + L" directory");
}
@ -202,29 +202,29 @@ void ResourceFile::getDirectory(Directory &directory)
void ResourceFile::unpack(char *in, int inSize, char *out, int outSize)
{
z_stream zs;
memset(&zs, 0, sizeof(z_stream));
zs.next_in = (Bytef*)in;
zs.avail_in = inSize;
zs.next_out = (Bytef*)out;
zs.avail_out = outSize;
if (inflateInit(&zs) != Z_OK)
if (inflateInit(&zs) != Z_OK)
throw Exception(name + L": Error initializing inflate stream.");
if (inflate(&zs, Z_FINISH) != Z_STREAM_END)
throw Exception(name + L": Error decompresing element.");
if (inflateEnd(&zs) != Z_OK)
throw Exception(name + L": Error finishing decompresing.");
}
void ResourceFile::load(char *buf, long offset, long packedSize,
void ResourceFile::load(char *buf, long offset, long packedSize,
long unpackedSize, int level)
{
char *inBuf=NULL;
try {
if (! level) {
stream.seekg(offset, std::ios::beg);
@ -250,7 +250,7 @@ void* ResourceFile::load(long offset, long packedSize, long unpackedSize,
int level)
{
char *outBuf=NULL;
try {
outBuf = (char*)malloc(unpackedSize);
if (! outBuf)
@ -278,7 +278,7 @@ void* ResourceFile::load(long offset, long packedSize, long unpackedSize,
SimpleResourceFile::SimpleResourceFile(const std::wstring &fileName,
Buffer *buf): ResourceFile(fileName, buf)
{
Directory entries;
Directory entries;
getDirectory(entries);
for (Directory::iterator i = entries.begin(); i != entries.end(); i++) {
DirectoryEntry &e = *i;
@ -304,7 +304,7 @@ void SimpleResourceFile::load(const std::wstring &name, Buffer &outBuf)
if (i != directory.end()) {
DirectoryEntry &e = (*i).second;
outBuf.setSize(e.unpackedSize);
ResourceFile::load((char*)outBuf.getData(), e.offset,
ResourceFile::load((char*)outBuf.getData(), e.offset,
e.packedSize, e.unpackedSize, e.level);
} else
throw Exception(L"Resource '" + name + L"' not found");
@ -349,7 +349,7 @@ void* ResVariant::getRef()
memcpy(d, &self, sizeof(self));
data = d + sizeof(self);
}
refCnt++;
return data;
}
@ -389,7 +389,7 @@ void ResVariant::getData(Buffer &buffer)
{
buffer.setSize(unpackedSize);
if (! refCnt)
file->load((char*)buffer.getData(), offset, packedSize,
file->load((char*)buffer.getData(), offset, packedSize,
unpackedSize, level);
else
memcpy((char*)buffer.getData(), data, unpackedSize);
@ -400,7 +400,7 @@ ResourceStream* ResVariant::createStream()
if (refCnt || level)
return new MemoryResourceStream(this);
else
return new UnpackedResourceStream(file->getStream(), offset,
return new UnpackedResourceStream(file->getStream(), offset,
packedSize);
}
@ -429,7 +429,7 @@ class ScorePredicate
{
public:
int score;
ScorePredicate(int sc) { score = sc; }
bool operator() (const ResVariant *r) const {
@ -452,7 +452,7 @@ void Resource::addVariant(ResourceFile *file, int i18nScore,
variants.push_back(new ResVariant(file, i18nScore, entry));
return;
}
ScorePredicate p(i18nScore);
Variants::iterator i = std::find_if(variants.begin(), variants.end(), p);
if (i != variants.end()) {
@ -543,7 +543,7 @@ void ResourcesCollection::loadResourceFiles(StringList &directories)
while ((de = readdir(dir)))
if (de->d_name[0] != '.') {
std::wstring s(fromMbcs(de->d_name));
if ((s.length() > 4) &&
if ((s.length() > 4) &&
(toLowerCase(s.substr(s.length() - 4)) == L".res"))
files.push_back(new ResourceFile(d + L"/" + s, &buffer));
}
@ -556,13 +556,13 @@ void ResourcesCollection::loadResourceFiles(StringList &directories)
void ResourcesCollection::processFiles()
{
ResourceFile::Directory dir;
for (std::vector<ResourceFile*>::iterator i = files.begin();
i != files.end(); i++)
for (std::vector<ResourceFile*>::iterator i = files.begin();
i != files.end(); i++)
{
ResourceFile *file = *i;
file->getDirectory(dir);
for (ResourceFile::Directory::iterator j = dir.begin();
j != dir.end(); j++)
for (ResourceFile::Directory::iterator j = dir.begin();
j != dir.end(); j++)
{
ResourceFile::DirectoryEntry &de = *j;
std::wstring name, ext, language, country;
@ -622,7 +622,7 @@ void ResourcesCollection::delRef(void *data)
v->delRef(data);
}
void ResourcesCollection::forEachInGroup(const std::wstring &name,
void ResourcesCollection::forEachInGroup(const std::wstring &name,
Visitor<Resource*> &visitor)
{
if (groups.count(name) > 0) {
@ -671,4 +671,3 @@ void ResDataHolder::load(const std::wstring &name)
data = resources->getRef(name, s);
size = (size_t)s;
}

View File

@ -87,7 +87,7 @@ const char * const g_utf8_skip = utf8_skip_data;
*/
static inline wchar_t
g_utf8_get_char_extended (const char *p,
size_t max_len)
size_t max_len)
{
unsigned int i, len;
wchar_t wc = (unsigned char) *p;
@ -129,7 +129,7 @@ g_utf8_get_char_extended (const char *p,
{
return (wchar_t)-1;
}
if (max_len >= 0 && len > max_len)
{
for (i = 1; i < max_len; i++)
@ -143,7 +143,7 @@ g_utf8_get_char_extended (const char *p,
for (i = 1; i < len; ++i)
{
wchar_t ch = ((unsigned char *)p)[i];
if ((ch & 0xc0) != 0x80)
{
if (ch)
@ -158,20 +158,20 @@ g_utf8_get_char_extended (const char *p,
if (UTF8_LENGTH(wc) != len)
return (wchar_t)-1;
return wc;
}
/**
* g_utf8_get_char:
* @p: a pointer to Unicode character encoded as UTF-8
*
*
* Converts a sequence of bytes encoded as UTF-8 to a Unicode character.
* If @p does not point to a valid UTF-8 encoded character, results are
* undefined. If you are not sure that the bytes are complete
* valid Unicode characters, you should use g_utf8_get_char_validated()
* instead.
*
*
* Return value: the resulting character
**/
wchar_t
@ -202,7 +202,7 @@ g_utf8_get_char (const char *p)
* invalid input is stored here.
* @items_written: location to store number of characters written or %NULL.
* The value here stored does not include the trailing 0
* character.
* character.
* @error: location to store the error occuring, or %NULL to ignore
* errors. Any of the errors in #GConvertError other than
* %G_CONVERT_ERROR_NO_CONVERSION may occur.
@ -210,7 +210,7 @@ g_utf8_get_char (const char *p)
* Convert a string from UTF-8 to a 32-bit fixed width
* representation as UCS-4. A trailing 0 will be added to the
* string after the converted text.
*
*
* Return value: a pointer to a newly allocated UCS-4 string.
* This value must be freed with g_free(). If an
* error occurs, %NULL will be returned and
@ -218,15 +218,15 @@ g_utf8_get_char (const char *p)
**/
wchar_t *
g_utf8_to_ucs4 (const char *str,
long len,
long *items_read,
long *items_written,
wchar_t **error)
long len,
long *items_read,
long *items_written,
const wchar_t **error)
{
wchar_t *result = NULL;
int n_chars, i;
const char *in;
in = str;
n_chars = 0;
while ((len < 0 || str + len - in > 0) && *in)
@ -255,7 +255,7 @@ g_utf8_to_ucs4 (const char *str,
}
result = (wchar_t*)malloc((n_chars + 1) * sizeof(wchar_t));
in = str;
for (i=0; i < n_chars; i++)
{
@ -280,16 +280,16 @@ g_utf8_to_ucs4 (const char *str,
* @outbuf: output buffer, must have at least 6 bytes of space.
* If %NULL, the length will be computed and returned
* and nothing will be written to @outbuf.
*
*
* Converts a single character to UTF-8.
*
*
* Return value: number of bytes written
**/
int
g_unichar_to_utf8 (wchar_t c,
char *outbuf)
{
unsigned int len = 0;
unsigned int len = 0;
int first;
int i;
@ -345,14 +345,14 @@ g_unichar_to_utf8 (wchar_t c,
* @items_read: location to store number of characters read read, or %NULL.
* @items_written: location to store number of bytes written or %NULL.
* The value here stored does not include the trailing 0
* byte.
* byte.
* @error: location to store the error occuring, or %NULL to ignore
* errors. Any of the errors in #GConvertError other than
* %G_CONVERT_ERROR_NO_CONVERSION may occur.
*
* Convert a string from a 32-bit fixed width representation as UCS-4.
* to UTF-8. The result will be terminated with a 0 byte.
*
*
* Return value: a pointer to a newly allocated UTF-8 string.
* This value must be freed with g_free(). If an
* error occurs, %NULL will be returned and
@ -360,10 +360,10 @@ g_unichar_to_utf8 (wchar_t c,
**/
char *
g_ucs4_to_utf8 (const wchar_t *str,
long len,
long *items_read,
long *items_written,
wchar_t **error)
long len,
long *items_read,
long *items_written,
const wchar_t **error)
{
int result_length;
char *result = NULL;
@ -384,7 +384,7 @@ g_ucs4_to_utf8 (const wchar_t *str,
*error = L"Character out of range for UTF-8";
goto err_out;
}
result_length += UTF8_LENGTH (str[i]);
}
@ -394,7 +394,7 @@ g_ucs4_to_utf8 (const wchar_t *str,
i = 0;
while (p < result + result_length)
p += g_unichar_to_utf8 (str[i++], p);
*p = '\0';
if (items_written)
@ -410,8 +410,8 @@ g_ucs4_to_utf8 (const wchar_t *str,
std::string toUtf8(const std::wstring &str)
{
long readed, writed;
wchar_t *errMsg = NULL;
const wchar_t *errMsg = NULL;
char *res = g_ucs4_to_utf8(str.c_str(), str.length(), &readed,
&writed, &errMsg);
if (! res) {
@ -430,10 +430,9 @@ std::string toUtf8(const std::wstring &str)
std::wstring fromUtf8(const std::string &str)
{
long readed, writed;
wchar_t *errMsg = NULL;
wchar_t *res = g_utf8_to_ucs4(str.c_str(), str.length(), &readed,
&writed, &errMsg);
const wchar_t *errMsg = NULL;
wchar_t *res = g_utf8_to_ucs4(str.c_str(), str.length(), &readed, &writed, &errMsg);
if (! res) {
if (errMsg)
throw Exception(errMsg);
@ -443,7 +442,7 @@ std::wstring fromUtf8(const std::string &str)
std::wstring s(res);
free(res);
return s;
}
@ -456,7 +455,7 @@ std::string toUtf8(const std::wstring &str)
{
if (! str.length())
return "";
int len = str.length();
int bufSize = (len + 1) * 6 + 1;
char buf[bufSize];
@ -472,11 +471,11 @@ std::wstring fromUtf8(const std::string &str)
{
if (! str.length())
return L"";
int len = str.length();
wchar_t buf[len + 1];
int res = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), len + 1,
int res = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), len + 1,
buf, len + 1);
if (! res)
throw Exception(L"Error converting UTF-8 to UCS-2");
@ -488,7 +487,7 @@ std::string toOem(const std::wstring &str)
{
if (! str.length())
return "";
int len = str.length();
int bufSize = (len + 1) * 6 + 1;
char buf[bufSize];
@ -504,11 +503,11 @@ std::wstring fromOem(const std::string &str)
{
if (! str.length())
return L"";
int len = str.length();
wchar_t buf[len + 1];
int res = MultiByteToWideChar(CP_OEMCP, 0, str.c_str(), len + 1,
int res = MultiByteToWideChar(CP_OEMCP, 0, str.c_str(), len + 1,
buf, len + 1);
if (! res)
throw Exception(L"Error converting OEM to UCS-2");
@ -574,7 +573,7 @@ std::wstring fromMbcs(const std::string &str)
std::ostream& operator << (std::ostream &stream, const std::wstring &str)
{
#ifdef WIN32
if ((stream == std::cout) || (stream == std::cerr) ||
if ((stream == std::cout) || (stream == std::cerr) ||
(stream == std::clog))
stream << toOem(str);
else
@ -587,10 +586,13 @@ std::ostream& operator << (std::ostream &stream, const std::wstring &str)
int getUtf8Length(unsigned char c)
{
int mask, len;
UTF8_COMPUTE(c, mask, len);
if (-1 == len)
if (-1 == len) {
throw Exception(L"Invalid utf-8 character");
else
} else {
return len;
}
}