Subversion Repositories Kolibri OS

Rev

Rev 5499 | Rev 5676 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5499 Rev 5598
1
//convert text characters
1
//convert text characters
-
 
2
#ifndef INCLUDE_LIBICONV_H
-
 
3
#define INCLUDE_LIBICONV_H
-
 
4
 
-
 
5
#ifndef INCLUDE_KOLIBRI_H
-
 
6
#include "../lib/kolibri.h"
-
 
7
#endif
-
 
8
 
-
 
9
#ifndef INCLUDE_DLL_H
-
 
10
#include "../lib/dll.h"
-
 
11
#endif
2
 
12
 
3
dword iconv_lib = #a_iconv_lib;
13
dword iconv_lib = #a_iconv_lib;
4
char a_iconv_lib[19]="/sys/lib/iconv.obj\0";
14
char a_iconv_lib[19]="/sys/lib/iconv.obj\0";
5
 
15
 
6
dword iconv_open     = #aIconv_open;
16
dword iconv_open     = #aIconv_open;
7
dword iconv          = #aIconv;
17
dword iconv          = #aIconv;
8
$DD 2 dup 0
18
$DD 2 dup 0
9
 
19
 
10
char aIconv_open[11] = "iconv_open\0";
20
char aIconv_open[11] = "iconv_open\0";
11
char aIconv[6]       = "iconv\0";
21
char aIconv[6]       = "iconv\0";
12
 
22
 
13
 
23
 
14
dword ChangeCharset(dword from_chs, to_chs, conv_buf)
24
dword ChangeCharset(dword from_chs, to_chs, conv_buf)
15
{
25
{
16
	dword cd, in_len, out_len, new_buf;	
26
	dword cd, in_len, out_len, new_buf;	
17
 
27
 
18
	iconv_open stdcall (from_chs, to_chs); //CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5
28
	iconv_open stdcall (from_chs, to_chs); //CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5
19
	if (EAX==-1)
29
	if (EAX==-1)
20
	{
30
	{
21
		debug(from_chs);
31
		debug(from_chs);
22
		debug(to_chs);
32
		debug(to_chs);
23
		debug("iconv: wrong charset,\nuse only CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5");
33
		debug("iconv: wrong charset,\nuse only CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5");
24
		return 0; 
34
		return 0; 
25
	}
35
	}
26
	cd = EAX;
36
	cd = EAX;
27
 
37
 
28
	in_len = out_len = strlen(conv_buf)+1;
38
	in_len = out_len = strlen(conv_buf)+1;
29
	new_buf = mem_Alloc(in_len);
39
	new_buf = mem_Alloc(in_len);
30
	iconv stdcall (cd, #conv_buf, #in_len, #new_buf, #out_len);
40
	iconv stdcall (cd, #conv_buf, #in_len, #new_buf, #out_len);
31
	cd = EAX;
41
	cd = EAX;
32
	if (cd!=0)
42
	if (cd!=0)
33
	{
43
	{
34
		debug("iconv: something is wrong with stdcall iconv()");
44
		debug("iconv: something is wrong with stdcall iconv()");
35
		debugi(cd);
45
		debugi(cd);
36
		debug("in_len");
46
		debug("in_len");
37
		debugi(in_len);
47
		debugi(in_len);
38
		debug("out_len");
48
		debug("out_len");
39
		debugi(out_len);
49
		debugi(out_len);
40
		new_buf = free(new_buf);
50
		new_buf = free(new_buf);
41
		return 0;
51
		return 0;
42
	}
52
	}
43
	strcpy(conv_buf, new_buf);
53
	strcpy(conv_buf, new_buf);
44
	free(new_buf);
54
	free(new_buf);
45
	return conv_buf;
55
	return conv_buf;
46
}
56
}
47
 
57
 
48
 
58
 
49
char *charsets[] = { " ", "UTF-8", "KOI8-RU", "CP1251",  "CP1252", "ISO8859-5", "CP866"};
59
char *charsets[] = { " ", "UTF-8", "KOI8-RU", "CP1251",  "CP1252", "ISO8859-5", "CP866"};
50
int cur_charset;
60
int cur_charset;
51
enum {
61
enum {
52
	CH_NULL,
62
	CH_NULL,
53
	CH_UTF8,
63
	CH_UTF8,
54
	CH_KOI8,
64
	CH_KOI8,
55
	CH_CP1251,
65
	CH_CP1251,
56
	CH_CP1252,
66
	CH_CP1252,
57
	CH_ISO8859_5,
67
	CH_ISO8859_5,
58
	CH_CP866
68
	CH_CP866
59
};
69
};
60
70
 
-
 
71
#endif
-
 
72
61
73