2012-12-15 01:16:06 +01:00
|
|
|
//convert text characters
|
2015-07-22 20:32:54 +02:00
|
|
|
#ifndef INCLUDE_LIBICONV_H
|
|
|
|
#define INCLUDE_LIBICONV_H
|
|
|
|
|
|
|
|
#ifndef INCLUDE_KOLIBRI_H
|
|
|
|
#include "../lib/kolibri.h"
|
|
|
|
#endif
|
|
|
|
|
2012-12-15 00:55:44 +01:00
|
|
|
dword iconv_lib = #a_iconv_lib;
|
2018-04-21 14:28:00 +02:00
|
|
|
char a_iconv_lib[]="/sys/lib/iconv.obj";
|
2012-12-15 00:55:44 +01:00
|
|
|
|
|
|
|
dword iconv_open = #aIconv_open;
|
|
|
|
dword iconv = #aIconv;
|
2013-07-26 16:41:31 +02:00
|
|
|
$DD 2 dup 0
|
2012-12-15 00:55:44 +01:00
|
|
|
|
2018-04-21 14:28:00 +02:00
|
|
|
char aIconv_open[] = "iconv_open";
|
|
|
|
char aIconv[] = "iconv";
|
2012-12-15 00:55:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
dword ChangeCharset(dword from_chs, to_chs, conv_buf)
|
|
|
|
{
|
|
|
|
dword cd, in_len, out_len, new_buf;
|
|
|
|
|
|
|
|
iconv_open stdcall (from_chs, to_chs); //CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5
|
2012-12-19 18:37:24 +01:00
|
|
|
if (EAX==-1)
|
|
|
|
{
|
2016-01-08 03:19:41 +01:00
|
|
|
debugln(from_chs);
|
|
|
|
debugln(to_chs);
|
|
|
|
debugln("iconv: wrong charset,\nuse only CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5");
|
2012-12-19 18:37:24 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2012-12-15 00:55:44 +01:00
|
|
|
cd = EAX;
|
|
|
|
|
2012-12-19 18:37:24 +01:00
|
|
|
in_len = out_len = strlen(conv_buf)+1;
|
2012-12-15 00:55:44 +01:00
|
|
|
new_buf = mem_Alloc(in_len);
|
|
|
|
iconv stdcall (cd, #conv_buf, #in_len, #new_buf, #out_len);
|
|
|
|
cd = EAX;
|
|
|
|
if (cd!=0)
|
|
|
|
{
|
2020-03-22 20:50:16 +01:00
|
|
|
debugval("iconv: something is wrong with stdcall iconv()", cd);
|
|
|
|
debugval("in_len", in_len);
|
|
|
|
debugval("out_len", out_len);
|
2013-03-11 19:16:24 +01:00
|
|
|
new_buf = free(new_buf);
|
2012-12-19 18:37:24 +01:00
|
|
|
return 0;
|
2012-12-15 00:55:44 +01:00
|
|
|
}
|
2012-12-19 18:37:24 +01:00
|
|
|
strcpy(conv_buf, new_buf);
|
|
|
|
free(new_buf);
|
|
|
|
return conv_buf;
|
2013-03-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-07 00:37:34 +02:00
|
|
|
:int cur_charset;
|
2015-09-06 14:34:30 +02:00
|
|
|
:char *charsets[] = { "UTF-8", "KOI8-RU", "CP1251", "CP1252", "ISO8859-5", "CP866", 0 };
|
|
|
|
enum { CH_UTF8, CH_KOI8, CH_CP1251, CH_CP1252, CH_ISO8859_5, CH_CP866, CH_NULL };
|
2015-07-22 20:32:54 +02:00
|
|
|
|
|
|
|
#endif
|