File: im_common.h

package info (click to toggle)
mlterm 2.9.4-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,728 kB
  • ctags: 5,338
  • sloc: ansic: 74,649; sh: 8,532; cpp: 1,451; makefile: 1,126; perl: 496; sed: 16
file content (77 lines) | stat: -rw-r--r-- 970 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef __IM_COMMON_H__
#define __IM_COMMON_H__

static inline u_int
im_convert_encoding(
	mkf_parser_t *  parser , /* must be initialized */
	mkf_conv_t *  conv ,
	u_char *  from ,
	u_char **  to ,
	u_int  from_len
	)
{
	u_int  len ;
	u_int  filled_len ;

	if( from == NULL || parser == NULL || conv == NULL)
	{
		return  0 ;
	}

	*to = NULL ;

	len = 0 ;

	(*parser->set_str)( parser , from , from_len) ;
	(*conv->init)( conv) ;

#define  UNIT__ 32

	while( 1)
	{
		u_char *  p ;

		if( ! ( p = realloc( *to , len + UNIT__ + 1)))
		{
		#ifdef  DEBUG
			kik_warn_printf( KIK_DEBUG_TAG " malloc failed.\n") ;
		#endif

			if( *to)
			{
				free( *to) ;
			}

			return  0 ;
		}

		*to = p ;

		p += len ;


		filled_len = (*conv->convert)( conv , p , UNIT__ , parser) ;

		len += filled_len ;

		if( filled_len == 0 && parser->is_eos)
		{
			/* finished converting */

			break ;
		}

	}

#undef  UNIT__

	if( len)
	{
		(*to)[len] = '\0' ;
	}

	return  len ;
}

#endif