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
|
|
|
|
|
2021-11-24 11:52:23 +01:00
|
|
|
#ifndef INCLUDE_ENCODING_H
|
|
|
|
#include "../lib/encoding.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-05-07 23:13:43 +02:00
|
|
|
char charsets[] = "UTF-8\0 KOI8-RU\0 CP1251\0 CP1252\0 ISO8859-5\0CP866\0 AUTO";
|
2020-05-06 00:38:26 +02:00
|
|
|
enum { CH_UTF8, CH_KOI8, CH_CP1251, CH_CP1252, CH_ISO8859_5, CH_CP866, CH_AUTO };
|
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;
|
|
|
|
|
2021-11-24 11:52:23 +01:00
|
|
|
iconv_open stdcall (from_chs*10+#charsets, to_chs*10+#charsets);
|
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;
|
|
|
|
|
2021-11-24 11:52:23 +01:00
|
|
|
in_len = strlen(conv_buf)+1;
|
|
|
|
out_len = in_len * 2;
|
|
|
|
new_buf = mem_Alloc(out_len);
|
2012-12-15 00:55:44 +01:00
|
|
|
iconv stdcall (cd, #conv_buf, #in_len, #new_buf, #out_len);
|
2020-11-30 01:55:04 +01:00
|
|
|
if (EAX!=0)
|
2012-12-15 00:55:44 +01:00
|
|
|
{
|
2020-11-30 01:55:04 +01:00
|
|
|
cd = EAX;
|
2021-11-24 11:52:23 +01:00
|
|
|
debugval("iconv failed", cd);
|
|
|
|
if (from_chs == CH_UTF8) && (to_chs == CH_CP866) {
|
|
|
|
utf8rutodos(conv_buf);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
strcpy(conv_buf, new_buf);
|
2012-12-15 00:55:44 +01:00
|
|
|
}
|
2021-11-24 11:52:23 +01:00
|
|
|
free(new_buf);
|
2012-12-19 18:37:24 +01:00
|
|
|
return conv_buf;
|
2013-03-11 19:16:24 +01:00
|
|
|
}
|
|
|
|
|
2015-07-22 20:32:54 +02:00
|
|
|
#endif
|