File: mod_aux.c

package info (click to toggle)
libchewing 0.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,588 kB
  • ctags: 878
  • sloc: sh: 9,738; ansic: 7,644; makefile: 234; python: 49
file content (242 lines) | stat: -rw-r--r-- 5,466 bytes parent folder | download
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
 * mod_aux.c
 *
 * Copyright (c) 2005, 2006, 2008
 *	libchewing Core Team. See ChangeLog for details.
 *
 * See the file "COPYING" for information on usage and redistribution
 * of this file.
 */

/**
 * @file mod_aux.c
 * @brief Auxiliary module
 */

#include <string.h>
#include <stdlib.h>

#include "global.h"
#include "chewing-private.h"
#include "zuin-private.h"
#include "chewingio.h"
#include "private.h"

/**
 * @param ctx handle to Chewing IM context
 * @retval TRUE if it currnet input state is at the "end-of-a-char"
 */
CHEWING_API int chewing_commit_Check( ChewingContext *ctx )
{
	return (ctx->output->keystrokeRtn & KEYSTROKE_COMMIT);
}

/**
 * @param ctx handle to Chewing IM context
 *
 * retrun current commit string, regardless current input state.
 * Alwasy returns a char pointer, caller must free it.
 */
CHEWING_API char *chewing_commit_String( ChewingContext *ctx )
{
	int i;
	char *s = (char *) calloc(
		1 + ctx->output->nCommitStr,
		sizeof(char) * MAX_UTF8_SIZE );
	for ( i = 0; i < ctx->output->nCommitStr; i++ ) {
		strcat( s, (char *) (ctx->output->commitStr[ i ].s) );
	}
	return s;
}

CHEWING_API int chewing_buffer_Check( ChewingContext *ctx )
{
	return (ctx->output->chiSymbolBufLen != 0);
}

CHEWING_API int chewing_buffer_Len( ChewingContext *ctx )
{
	return ctx->output->chiSymbolBufLen;
}

CHEWING_API char *chewing_buffer_String( ChewingContext *ctx )
{
	int i;
	char *s = (char *) calloc(
		1 + ctx->output->chiSymbolBufLen,
		sizeof(char) * MAX_UTF8_SIZE );
	for ( i = 0; i < ctx->output->chiSymbolBufLen; i++ ) {
		strcat( s, (char *) (ctx->output->chiSymbolBuf[ i ].s) );
	}
	return s;
}

/**
 * @param ctx handle to Chewing IM context
 * @param zuin_count pointer to the integer of available Zuin preedit string
 *
 * Always returns a char pointer, caller must free it.
 */
CHEWING_API char *chewing_zuin_String( ChewingContext *ctx, int *zuin_count )
{
	char *s;
	int i;
	if ( zuin_count )
		*zuin_count = 0;
	s = (char*) calloc(
		1 + ZUIN_SIZE,
		sizeof(char) * WCH_SIZE );
	for ( i = 0; i < ZUIN_SIZE; i++ ) {
		if ( ctx->output->zuinBuf[ i ].s[ 0 ] != '\0' ) {
			strcat( s, (char *) (ctx->output->zuinBuf[ i ].s) );
			if ( zuin_count )
				*zuin_count++;
		}
	}
	return s;
}

CHEWING_API int chewing_zuin_Check( ChewingContext *ctx )
{
	int ret = 0;
	if ( ctx->output->zuinBuf[ 0 ].s[ 0 ] == '\0' ) {
		ret = 1;
	}
	return ret;
}

CHEWING_API int chewing_cursor_Current( ChewingContext *ctx )
{
	return (ctx->output->chiSymbolCursor);
}

CHEWING_API int chewing_cand_CheckDone( ChewingContext *ctx )
{
	return (! ctx->output->pci);
}

CHEWING_API int chewing_cand_TotalPage( ChewingContext *ctx )
{
	return (ctx->output->pci ? ctx->output->pci->nPage : 0);
}

CHEWING_API int chewing_cand_ChoicePerPage( ChewingContext *ctx )
{
	return (ctx->output->pci ? ctx->output->pci->nChoicePerPage : 0);
}

CHEWING_API int chewing_cand_TotalChoice( ChewingContext *ctx )
{
	return (ctx->output->pci ? ctx->output->pci->nTotalChoice : 0);
}

CHEWING_API int chewing_cand_CurrentPage( ChewingContext *ctx )
{
	return (ctx->output->pci ? ctx->output->pci->pageNo : -1);
}

CHEWING_API void chewing_cand_Enumerate( ChewingContext *ctx )
{
	ctx->cand_no = ctx->output->pci->pageNo * ctx->output->pci->nChoicePerPage;
}

CHEWING_API int chewing_cand_hasNext( ChewingContext *ctx )
{
	return (ctx->cand_no < ctx->output->pci->nTotalChoice);	
}

CHEWING_API char *chewing_cand_String( ChewingContext *ctx )
{
	char *s;
	if ( chewing_cand_hasNext( ctx ) ||
	     (ctx->cand_no < ctx->output->pci->nTotalChoice) ) {
		s = strdup( ctx->output->pci->totalChoiceStr[ ctx->cand_no ] );
		ctx->cand_no++;
	} else {
		s = strdup( "" );
	}
	return s;
}

CHEWING_API void chewing_interval_Enumerate( ChewingContext *ctx )
{
	ctx->it_no = 0;
}

CHEWING_API int chewing_interval_hasNext( ChewingContext *ctx )
{
	return (ctx->it_no < ctx->output->nDispInterval);
}

CHEWING_API void chewing_interval_Get( ChewingContext *ctx, IntervalType *it )
{
	if ( chewing_interval_hasNext( ctx ) ) {
		if ( it ) {
			it->from = ctx->output->dispInterval[ ctx->it_no ].from;
			it->to = ctx->output->dispInterval[ ctx->it_no ].to;
		}
		ctx->it_no++;
	}
}

CHEWING_API int chewing_aux_Check( ChewingContext *ctx )
{
	return (ctx->output->bShowMsg);
}

CHEWING_API int chewing_aux_Length( ChewingContext *ctx )
{
	return (ctx->output->bShowMsg ? ctx->output->showMsgLen : 0);
}

CHEWING_API char *chewing_aux_String( ChewingContext *ctx )
{
	int i;
	char *msg = (char *) calloc(
		1 + ctx->output->showMsgLen,
		sizeof(char) * MAX_UTF8_SIZE );
	for ( i = 0; i < ctx->output->showMsgLen; ++i )
		strcat( msg, (char *)(ctx->output->showMsg[ i ].s) );
	return msg;

}

CHEWING_API int chewing_keystroke_CheckIgnore( ChewingContext *ctx )
{ 
	return (ctx->output->keystrokeRtn & KEYSTROKE_IGNORE);
} 

CHEWING_API int chewing_keystroke_CheckAbsorb( ChewingContext *ctx )
{ 
	return (ctx->output->keystrokeRtn & KEYSTROKE_ABSORB);
}

CHEWING_API int chewing_kbtype_Total( ChewingContext *ctx )
{
	return KB_TYPE_NUM;
}

CHEWING_API void chewing_kbtype_Enumerate( ChewingContext *ctx )
{
	ctx->kb_no = 0;
}

CHEWING_API int chewing_kbtype_hasNext( ChewingContext *ctx )
{
	return ctx->kb_no < KB_TYPE_NUM;
}

extern char *kb_type_str[];

CHEWING_API char *chewing_kbtype_String( ChewingContext *ctx )
{
	char *s;
	if ( chewing_kbtype_hasNext( ctx ) ) {
		s = strdup( kb_type_str[ ctx->kb_no ] );
		ctx->kb_no++;
	}
	else {
		s = strdup( "" );
	}
	return s;
}