MS win sdl paths i18n

This commit is contained in:
p.kosyh 2009-12-06 15:28:17 +00:00
parent df4e6b6508
commit 708e1afecd
8 changed files with 111 additions and 38 deletions

1
debian/changelog vendored
View file

@ -2,6 +2,7 @@ instead (1.0.3) unstable; urgency=low
* autojump to text change
* no cursor flickering
* sdl_path (i18n M$ win sdl paths)
-- Peter Kosyh <p.kosyh@gmail.com> Tue, 01 Dec 2009 14:12:36 +0300

View file

@ -1038,7 +1038,7 @@ void game_music_player(void)
instead_eval("return get_music()");
mus = instead_retval(0);
loop = instead_iretval(1);
unix_path(mus);
mus = sdl_path(mus);
instead_clear();
if (mus && loop == -1) { /* disabled, 0 - forever, 1-n - loops */
@ -1138,7 +1138,7 @@ void game_sound_player(void)
}
instead_eval("set_sound(nil, -1)"); instead_clear();
unix_path(snd);
snd = sdl_path(snd);
w = sound_find(snd);
if (!w)
w = sound_add(snd);
@ -1261,7 +1261,7 @@ int game_cmd(char *cmd)
pict = instead_retval(0);
instead_clear();
unix_path(pict);
pict = sdl_path(pict);
new_pict = check_new_pict(pict);

View file

@ -647,9 +647,9 @@ img_t gfx_load_image(char *filename)
img_t img = NULL;
if (!filename)
return NULL;
if (!access(filename, R_OK))
/* if (!access(filename, R_OK)) */
img = _gfx_load_image(filename);
else
if (!img)
img = _gfx_load_combined_image(filename);
return img;
}

View file

@ -181,34 +181,6 @@ static char *fromcp = NULL;
#endif
#ifdef _HAVE_ICONV
#define CHAR_MAX_LEN 4
static char *decode(iconv_t hiconv, const char *s)
{
size_t s_size, chs_size, outsz, insz;
char *inbuf, *outbuf, *chs_buf;
if (!s || hiconv == (iconv_t)(-1))
return NULL;
s_size = strlen(s) + 1;
chs_size = s_size * CHAR_MAX_LEN;
if ((chs_buf = malloc(chs_size + CHAR_MAX_LEN))==NULL)
goto exitf;
outsz = chs_size;
outbuf = chs_buf;
insz = s_size;
inbuf = (char*)s;
while (insz) {
if (iconv(hiconv, &inbuf, &insz, &outbuf, &outsz)
== (size_t)(-1))
goto exitf;
}
*outbuf++ = 0;
return chs_buf;
exitf:
if(chs_buf)
free(chs_buf);
return NULL;
}
char *fromgame(const char *s)
{
iconv_t han;

View file

@ -9,6 +9,11 @@
#include <string.h>
#include <stdlib.h>
#include <locale.h>
#include <langinfo.h>
#ifdef _HAVE_ICONV
#include <iconv.h>
#endif
#include "internals.h"
#ifndef PATH_MAX
@ -110,3 +115,8 @@ void debug_done()
}
char *sdl_path(char *p)
{
unix_path(p);
return p;
}

View file

@ -223,7 +223,7 @@ int parse_full_path(const char *v, void *data)
strcpy(*p, cwd);
strcat(*p,"/");
strcat(*p, v);
unix_path(*p);
*p = sdl_path(*p);
return 0;
}
@ -296,3 +296,32 @@ char *parse_tag(char *line, const char *tag, const char *comm, int *brk)
ns[strcspn(ns, "\n\r")] = 0;
return ns;
}
#ifdef _HAVE_ICONV
#define CHAR_MAX_LEN 4
char *decode(iconv_t hiconv, const char *s)
{
size_t s_size, chs_size, outsz, insz;
char *inbuf, *outbuf, *chs_buf;
if (!s || hiconv == (iconv_t)(-1))
return NULL;
s_size = strlen(s) + 1;
chs_size = s_size * CHAR_MAX_LEN;
if ((chs_buf = malloc(chs_size + CHAR_MAX_LEN))==NULL)
goto exitf;
outsz = chs_size;
outbuf = chs_buf;
insz = s_size;
inbuf = (char*)s;
while (insz) {
if (iconv(hiconv, &inbuf, &insz, &outbuf, &outsz)
== (size_t)(-1))
goto exitf;
}
*outbuf++ = 0;
return chs_buf;
exitf:
if(chs_buf)
free(chs_buf);
return NULL;
}
#endif

View file

@ -22,7 +22,13 @@ extern int parse_string(const char *v, void *data);
extern int parse_int(const char *v, void *data);
extern int parse_full_path(const char *v, void *data);
#ifdef _HAVE_ICONV
extern char *decode(iconv_t hiconv, const char *s);
#endif
extern void unix_path(char *path);
extern char *sdl_path(char *path);
extern char *parse_tag(char *line, const char *tag, const char *comm, int *brk);
#ifndef PATH_MAX

View file

@ -6,7 +6,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#ifdef _HAVE_ICONV
#include <iconv.h>
#endif
#include "internals.h"
extern char *curgame;
@ -32,6 +34,61 @@ char *game_locale(void)
return strdup(buff);
}
static char *game_codepage = NULL;
#ifdef _HAVE_ICONV
static char *game_cp(void)
{
char cpbuff[64];
char buff[64];
buff[0] = 0;
if (!GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE,
buff,sizeof(buff) - 1))
return NULL;
snprintf(cpbuff, sizeof(cpbuff), "WINDOWS-%s", buff);
return strdup(cpbuff);
}
char *mbs2utf8(const char *s)
{
iconv_t han;
char *str;
if (!game_codepage)
game_codepage = game_cp();
if (!s)
return NULL;
if (!game_codepage)
goto out0;
han = iconv_open("UTF-8", game_codepage);
if (han == (iconv_t)-1)
goto out0;
if (!(str = decode(han, s)))
goto out1;
iconv_close(han);
return str;
out1:
iconv_close(han);
out0:
return strdup(s);
}
#else
char *mbs2utf8(const char *s)
{
return strdup(s);
}
#endif
extern void unix_path(char *);
char *sdl_path(char *p)
{
char *r = mbs2utf8(p);
if (p)
free(p);
unix_path(r);
return r;
}
char *app_dir( void );
char *game_local_games_path(void)
@ -46,11 +103,9 @@ char *game_local_themes_path(void)
return local_themes_path;
}
extern void unix_path(char *);
char *app_dir( void )
{
static char appdir[PATH_MAX];
static char appdir[PATH_MAX]="";
SHGetFolderPath( NULL,
CSIDL_FLAG_CREATE | CSIDL_LOCAL_APPDATA,
NULL,