Subversion Repositories Kolibri OS

Rev

Rev 7746 | Rev 7781 | 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
 
7759 leency 19
char charsets[] = "UTF-8\0    KOI8-RU\0  CP1251\0   CP1252\0   ISO8859-5\0CP866";
20
enum { CH_UTF8, CH_KOI8, CH_CP1251, CH_CP1252, CH_ISO8859_5, CH_CP866, CH_NULL };
3106 leency 21
 
22
dword ChangeCharset(dword from_chs, to_chs, conv_buf)
23
{
24
	dword cd, in_len, out_len, new_buf;
25
 
7759 leency 26
	debug("iconv: from_chs = "); debugln(from_chs);
27
	debug("iconv: to_chs = "); debugln(to_chs);
28
 
3106 leency 29
	iconv_open stdcall (from_chs, to_chs); //CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5
7759 leency 30
	if (EAX==-1) {
31
		debugln("iconv: unsupported charset");
3128 leency 32
		return 0;
33
	}
3106 leency 34
	cd = EAX;
35
 
3128 leency 36
	in_len = out_len = strlen(conv_buf)+1;
3106 leency 37
	new_buf = mem_Alloc(in_len);
38
	iconv stdcall (cd, #conv_buf, #in_len, #new_buf, #out_len);
39
	cd = EAX;
40
	if (cd!=0)
41
	{
7746 leency 42
		debugval("iconv: something is wrong with stdcall iconv()", cd);
43
		debugval("in_len", in_len);
44
		debugval("out_len", out_len);
3363 leency 45
		new_buf = free(new_buf);
7759 leency 46
		return conv_buf;
3106 leency 47
	}
3128 leency 48
	strcpy(conv_buf, new_buf);
49
	free(new_buf);
50
	return conv_buf;
3363 leency 51
}
52
 
5598 pavelyakov 53
#endif