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
|
|
|
|
2020-04-04 01:17:28 +02:00
|
|
|
char charsets[] = "UTF-8\0 KOI8-RU\0 CP1251\0 CP1252\0 ISO8859-5\0CP866";
|
|
|
|
enum { CH_UTF8, CH_KOI8, CH_CP1251, CH_CP1252, CH_ISO8859_5, CH_CP866, CH_NULL };
|
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;
|
|
|
|
|
2020-04-13 15:16:55 +02:00
|
|
|
from_chs = from_chs*10+#charsets;
|
|
|
|
|
2020-04-04 01:17:28 +02:00
|
|
|
debug("iconv: from_chs = "); debugln(from_chs);
|
|
|
|
debug("iconv: to_chs = "); debugln(to_chs);
|
|
|
|
|
2012-12-15 00:55:44 +01:00
|
|
|
iconv_open stdcall (from_chs, to_chs); //CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5
|
2020-04-04 01:17:28 +02:00
|
|
|
if (EAX==-1) {
|
|
|
|
debugln("iconv: unsupported charset");
|
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);
|
2020-04-04 01:17:28 +02:00
|
|
|
return conv_buf;
|
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-07-22 20:32:54 +02:00
|
|
|
#endif
|