Subversion Repositories Kolibri OS

Rev

Rev 7781 | Rev 7893 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3107 leency 1
//convert text characters
5598 pavelyakov 2
#ifndef INCLUDE_LIBICONV_H
3
#define INCLUDE_LIBICONV_H
3106 leency 4
 
5598 pavelyakov 5
#ifndef INCLUDE_KOLIBRI_H
6
#include "../lib/kolibri.h"
7
#endif
8
 
3106 leency 9
dword iconv_lib = #a_iconv_lib;
7252 leency 10
char a_iconv_lib[]="/sys/lib/iconv.obj";
3106 leency 11
 
12
dword iconv_open     = #aIconv_open;
13
dword iconv          = #aIconv;
3839 Asper 14
$DD 2 dup 0
3106 leency 15
 
7252 leency 16
char aIconv_open[] = "iconv_open";
17
char aIconv[]       = "iconv";
3106 leency 18
 
7872 leency 19
char charsets[] = "UTF-8\0    KOI8-RU\0  CP1251\0   CP1252\0   ISO8859-5\0CP866    \0AUTO";
20
enum { CH_UTF8, CH_KOI8, CH_CP1251, CH_CP1252, CH_ISO8859_5, CH_CP866, CH_AUTO };
3106 leency 21
 
22
dword ChangeCharset(dword from_chs, to_chs, conv_buf)
23
{
24
	dword cd, in_len, out_len, new_buf;
25
 
7781 leency 26
	from_chs = from_chs*10+#charsets;
27
 
7759 leency 28
	debug("iconv: from_chs = "); debugln(from_chs);
29
	debug("iconv: to_chs = "); debugln(to_chs);
30
 
3106 leency 31
	iconv_open stdcall (from_chs, to_chs); //CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5
7759 leency 32
	if (EAX==-1) {
33
		debugln("iconv: unsupported charset");
3128 leency 34
		return 0;
35
	}
3106 leency 36
	cd = EAX;
37
 
3128 leency 38
	in_len = out_len = strlen(conv_buf)+1;
3106 leency 39
	new_buf = mem_Alloc(in_len);
40
	iconv stdcall (cd, #conv_buf, #in_len, #new_buf, #out_len);
41
	cd = EAX;
42
	if (cd!=0)
43
	{
7746 leency 44
		debugval("iconv: something is wrong with stdcall iconv()", cd);
45
		debugval("in_len", in_len);
46
		debugval("out_len", out_len);
3363 leency 47
		new_buf = free(new_buf);
7759 leency 48
		return conv_buf;
3106 leency 49
	}
3128 leency 50
	strcpy(conv_buf, new_buf);
51
	free(new_buf);
52
	return conv_buf;
3363 leency 53
}
54
 
5598 pavelyakov 55
#endif