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
|
2015-08-04 17:48:36 +02:00
|
|
|
#print "[include <obj/iconv.h>]\n"
|
2015-07-22 20:32:54 +02:00
|
|
|
|
|
|
|
#ifndef INCLUDE_KOLIBRI_H
|
|
|
|
#include "../lib/kolibri.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef INCLUDE_DLL_H
|
|
|
|
#include "../lib/dll.h"
|
|
|
|
#endif
|
2012-12-15 00:55:44 +01:00
|
|
|
|
|
|
|
dword iconv_lib = #a_iconv_lib;
|
|
|
|
char a_iconv_lib[19]="/sys/lib/iconv.obj\0";
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
char aIconv_open[11] = "iconv_open\0";
|
|
|
|
char aIconv[6] = "iconv\0";
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2013-03-11 19:16:24 +01:00
|
|
|
debug(from_chs);
|
|
|
|
debug(to_chs);
|
2012-12-19 18:37:24 +01:00
|
|
|
debug("iconv: wrong charset,\nuse only CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5");
|
|
|
|
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)
|
|
|
|
{
|
2012-12-15 01:16:06 +01:00
|
|
|
debug("iconv: something is wrong with stdcall iconv()");
|
2013-03-11 19:16:24 +01:00
|
|
|
debugi(cd);
|
2012-12-15 00:55:44 +01:00
|
|
|
debug("in_len");
|
2013-03-11 19:16:24 +01:00
|
|
|
debugi(in_len);
|
2012-12-15 00:55:44 +01:00
|
|
|
debug("out_len");
|
2013-03-11 19:16:24 +01:00
|
|
|
debugi(out_len);
|
|
|
|
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-08-10 09:09:10 +02:00
|
|
|
:char *charsets[] = { " ", "UTF-8", "KOI8-RU", "CP1251", "CP1252", "ISO8859-5", "CP866" };
|
|
|
|
enum { CH_NULL, CH_UTF8, CH_KOI8, CH_CP1251, CH_CP1252, CH_ISO8859_5, CH_CP866 };
|
2015-07-22 20:32:54 +02:00
|
|
|
|
|
|
|
#endif
|