factory.c: remove #include <windows.h>

This commit is contained in:
Thomas Bernard 2020-04-12 23:53:59 +02:00
parent 857ae29be8
commit 7caddaee89
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
3 changed files with 52 additions and 22 deletions

View File

@ -62,9 +62,6 @@ char * Bound_script[10];
#include <limits.h> //for INT_MIN
#include <string.h> // strncpy()
#include <stdlib.h> // for atof()
#if defined(WIN32)
#include <windows.h>
#endif
#if defined(_MSC_VER)
#define strdup _strdup
#define putenv _putenv
@ -2002,30 +1999,16 @@ int L_GetFileName(lua_State* L)
else
{
// convert Filename_unicode to UTF8 (Lua strings are 8bits)
size_t unicode_len = Unicode_strlen(Main.backups->Pages->Filename_unicode);
int len = WideCharToMultiByte(CP_UTF8, 0, Main.backups->Pages->Filename_unicode, unicode_len, NULL, 0, NULL, NULL);
if (len <= 0)
size_t len = 0;
char * utf8name = Unicode_to_utf8(Main.backups->Pages->Filename_unicode, &len);
if (utf8name == NULL)
{
GFX2_Log(GFX2_WARNING, "WideCharToMultiByte() failed\n");
lua_pushstring(L, Main.backups->Pages->Filename);
}
else
{
char * utf8name = (char *)GFX2_malloc(len);
if (utf8name == NULL)
lua_pushstring(L, Main.backups->Pages->Filename);
else
{
if (WideCharToMultiByte(CP_UTF8, 0, Main.backups->Pages->Filename_unicode, unicode_len, utf8name, len, NULL, NULL) > 0)
lua_pushlstring(L, utf8name, len);
else
{
DWORD error = GetLastError();
GFX2_Log(GFX2_WARNING, "WideCharToMultiByte() failed error=%u\n", error);
lua_pushstring(L, Main.backups->Pages->Filename);
}
free(utf8name);
}
lua_pushlstring(L, utf8name, len);
free(utf8name);
}
}
// still using the "short name" directory path at the moment

View File

@ -22,6 +22,11 @@
You should have received a copy of the GNU General Public License
along with Grafx2; if not, see <http://www.gnu.org/licenses/>
*/
//////////////////////////////////////////////////////////////////////////////
///@file osdep.c
/// OS Dependend code
//////////////////////////////////////////////////////////////////////////////
#if defined(USE_SDL) || defined(USE_SDL2)
#include <SDL.h>
#elif !defined(WIN32)
@ -59,7 +64,9 @@
#endif
#include "struct.h"
#include "unicode.h"
#include "gfx2log.h"
#include "gfx2mem.h"
dword GFX2_GetTicks(void)
{
@ -253,3 +260,39 @@ unsigned long Memory_free(void)
#endif
}
#endif
#if defined(WIN32)
/**
* Converts an unicode string to UTF8
* @param str the unicode string
* @param utf8len pointer to receive the utf8 string length (excluding null terminator)
* @return malloc'ed UTF8 string
*/
char * Unicode_to_utf8(const word * str, size_t * utf8len)
{
size_t unicode_len = Unicode_strlen(str);
int len = WideCharToMultiByte(CP_UTF8, 0, str, unicode_len, NULL, 0, NULL, NULL);
if (len <= 0)
{
GFX2_Log(GFX2_WARNING, "WideCharToMultiByte() failed\n");
return NULL;
}
else
{
char * utf8 = (char *)GFX2_malloc(len+1);
if (utf8 == NULL)
return NULL;
if (WideCharToMultiByte(CP_UTF8, 0, str, unicode_len, utf8, len, NULL, NULL) <= 0)
{
DWORD error = GetLastError();
GFX2_Log(GFX2_WARNING, "WideCharToMultiByte() failed error=%u\n", error);
free(utf8);
return NULL;
}
if (utf8len != NULL)
*utf8len = (size_t)len;
utf8[len] = '\0';
return utf8;
}
}
#endif

View File

@ -54,4 +54,8 @@ void Atari_Memory_free(unsigned long *stRam, unsigned long *ttRam);
unsigned long Memory_free(void);
#endif
#if defined(WIN32)
char * Unicode_to_utf8(const word * str, size_t * utf8len);
#endif
#endif