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