Subversion Repositories Kolibri OS

Rev

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

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