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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
#include <stdio.h>
#include <string.h>
#include "internal.h"
#include "rccconfig.h"
#include "rcclocale.h"
rcc_engine_ptr rccConfigGetEnginePointer(rcc_language_config config, rcc_engine_id engine_id) {
unsigned int i;
rcc_engine_ptr *engines;
if ((!config)||(!config->language)||(engine_id<0)) return NULL;
engines = config->language->engines;
for (i=0;engines[i];i++);
if (engine_id>=i) return NULL;
return engines[engine_id];
}
const char *rccConfigGetEngineName(rcc_language_config config, rcc_engine_id engine_id) {
rcc_engine_ptr engine;
engine = rccConfigGetEnginePointer(config, engine_id);
if (!engine) return NULL;
return engine->title;
}
const char *rccConfigGetCharsetName(rcc_language_config config, rcc_charset_id charset_id) {
unsigned int i;
rcc_charset *charsets;
if ((!config)||(!config->language)||(charset_id<0)) return NULL;
charsets = config->language->charsets;
for (i=0;charsets[i];i++);
if (charset_id>=i) return NULL;
return charsets[charset_id];
}
const char *rccConfigGetAutoCharsetName(rcc_language_config config, rcc_charset_id charset_id) {
unsigned int i;
rcc_charset *charsets;
rcc_engine_ptr *engines;
if ((!config)||(!config->language)||(charset_id<0)) return NULL;
engines = config->language->engines;
charsets = engines[config->engine]->charsets;
for (i=0;charsets[i];i++);
if (charset_id>=i) return NULL;
return charsets[charset_id];
}
rcc_engine_id rccConfigGetEngineByName(rcc_language_config config, const char *name) {
unsigned int i;
rcc_engine **engines;
if ((!config)||(!config->language)||(!name)) return -1;
engines = config->language->engines;
for (i=0;engines[i];i++)
if (!strcmp(engines[i]->title,name)) return i;
return -1;
}
rcc_charset_id rccConfigGetCharsetByName(rcc_language_config config, const char *name) {
unsigned int i;
rcc_charset *charsets;
if ((!config)||(!config->language)||(!name)) return -1;
charsets = config->language->charsets;
for (i=0;charsets[i];i++)
if (!strcmp(charsets[i],name)) return i;
return 0;
}
rcc_charset_id rccConfigGetAutoCharsetByName(rcc_language_config config, const char *name) {
unsigned int i;
rcc_charset *charsets;
rcc_engine_ptr *engines;
if ((!config)||(!config->language)||(!name)) return -1;
engines = config->language->engines;
charsets = engines[config->engine]->charsets;
for (i=0;charsets[i];i++)
if (!strcmp(charsets[i],name)) return i;
return -1;
}
int rccConfigInit(rcc_language_config config, rcc_context ctx) {
unsigned int i;
rcc_charset_id *charsets;
if ((!ctx)||(!config)) return -1;
charsets = (rcc_charset_id*)malloc((ctx->max_classes)*sizeof(rcc_charset_id));
if (!charsets) return -1;
for (i=0;i<ctx->max_classes;i++)
charsets[i] = 0;
config->ctx = ctx;
config->language = NULL;
config->charset = charsets;
config->engine = -1;
for (i=0;i<RCC_MAX_OPTIONS;i++)
config->options[i] = 0;
return 0;
}
int rccConfigFree(rcc_language_config config) {
if (config->charset) {
free(config->charset);
config->charset = NULL;
}
}
rcc_language_config rccGetConfig(rcc_context ctx, rcc_language_id language_id) {
int err;
language_id = rccGetRealLanguage(ctx, language_id);
if (language_id < 0) return NULL;
if (!ctx->configs[language_id].charset) {
if (rccInitConfig(ctx->configs+language_id, ctx)) return NULL;
}
ctx->configs[language_id].language = ctx->languages[language_id];
return ctx->configs + language_id;
}
rcc_language_config rccGetConfigByName(rcc_context ctx, const char *name) {
rcc_language_id language_id;
language_id = rccGetLanguageByName(ctx, name);
if (language_id < 0) return NULL;
return rccGetConfig(ctx, language_id);
}
rcc_language_config rccGetCurrentConfig(rcc_context ctx) {
rcc_language_id language_id;
language_id = rccGetCurrentLanguage(ctx);
if (language_id < 0) return NULL;
return rccGetConfig(ctx, language_id);
}
rcc_engine_id rccConfigGetSelectedEngine(rcc_language_config config) {
if (!config) return -1;
return config->engine;
}
const char *rccConfigGetSelectedEngineName(rcc_language_config config) {
rcc_engine_id engine_id;
engine_id = rccConfigGetSelectedEngine(config);
if (engine_id == -1) return rcc_engine_nonconfigured;
if ((engine_id < 0)||(!config->language)) return NULL;
return rccConfigGetEngineName(config, engine_id);
}
rcc_engine_id rccConfigGetCurrentEngine(rcc_language_config config) {
rcc_engine **enginelist;
rcc_engine_id engine_id;
engine_id = rccConfigGetSelectedEngine(config);
if (engine_id>=0) return engine_id;
if (!config->language) return -1;
else enginelist = config->language->engines;
if (enginelist[0]) {
if (enginelist[1]) return 1;
return 0;
}
return -1;
}
const char *rccConfigGetCurrentEngineName(rcc_language_config config) {
rcc_engine_id engine_id;
engine_id = rccConfigGetCurrentEngine(config);
if ((engine_id < 0)||(!config->language)) return NULL;
return rccConfigGetEngineName(config, engine_id);
}
rcc_charset_id rccConfigGetSelectedCharset(rcc_language_config config, rcc_class_id class_id) {
if ((!config)||(!config->ctx)||(class_id<0)||(class_id>=config->ctx->n_classes)) return -1;
return config->charset[class_id];
}
const char *rccConfigGetSelectedCharsetName(rcc_language_config config, rcc_class_id class_id) {
rcc_charset_id charset_id;
charset_id = rccConfigGetSelectedCharset(config, class_id);
if ((charset_id < 0)||(!config->language)) return NULL;
return rccConfigGetCharsetName(config, charset_id);
}
rcc_charset_id rccConfigGetCurrentCharset(rcc_language_config config, rcc_class_id class_id) {
int err;
unsigned int i;
rcc_language_id language_id;
rcc_charset_id charset_id;
rcc_language *language;
rcc_class_ptr *classes;
rcc_charset *charsets;
rcc_class *cl;
char stmp[RCC_MAX_CHARSET_CHARS + 1];
const char *defvalue;
if ((!config)||(!config->ctx)||(class_id<0)||(class_id>=config->ctx->n_classes)) return -1;
charset_id = config->charset[class_id];
if (charset_id) return charset_id;
if (!config->language) return -1;
else language = config->language;
classes = config->ctx->classes;
cl = classes[class_id];
defvalue = cl->defvalue;
if (defvalue) {
for (i=0;classes[i];i++) {
if (!strcmp(classes[i]->name, defvalue))
return rccConfigGetCurrentCharset(config, i);
}
} else defvalue = config->ctx->locale_variable;
charset_id = rccConfigGetLocaleCharset(config, defvalue);
if (charset_id > 0) return charset_id;
charsets=config->ctx->languages[language_id]->charsets;
if ((charsets[0])&&(charsets[1])) return 1;
return -1;
}
const char *rccConfigGetCurrentCharsetName(rcc_language_config config, rcc_class_id class_id) {
rcc_charset_id charset_id;
charset_id = rccConfigGetCurrentCharset(config, class_id);
if ((charset_id < 0)||(!config->language)) return NULL;
return rccConfigGetCharsetName(config, charset_id);
}
rcc_option_value rccConfigGetOption(rcc_language_config config, rcc_option option) {
if ((!config)||(option<0)||(option>=RCC_MAX_OPTIONS)) return -1;
return config->options[option];
}
int rccConfigSetEngine(rcc_language_config config, rcc_engine_id engine_id) {
unsigned int i;
if ((!config)||(!config->language)||(engine_id < 0)) return -1;
for (i=0;config->language->engines[i];i++);
if (engine_id >= i) return -1;
if (config->engine != engine_id) {
if (config->ctx->current_config == config) config->ctx->configure = 1;
config->engine = engine_id;
}
return 0;
}
int rccConfigSetEngineByName(rcc_language_config config, const char *name) {
rcc_engine_id engine_id;
engine_id = rccConfigGetEngineByName(config, name);
if (engine_id < 0) return -1;
return rccConfigSetEngine(config, engine_id);
}
int rccConfigSetCharset(rcc_language_config config, rcc_class_id class_id, rcc_charset_id charset_id) {
unsigned int i;
if ((!config)||(!config->language)||(class_id < 0)||(class_id >= config->ctx->n_classes)||(charset_id<0)) return -1;
for (i=0;config->language->charsets[i];i++);
if (charset_id >= i) return -1;
if (config->charset[class_id] != charset_id) {
if (config->ctx->current_config == config) config->ctx->configure = 1;
config->charset[class_id] = charset_id;
}
return 0;
}
int rccConfigSetCharsetByName(rcc_language_config config, rcc_class_id class_id, const char *name) {
rcc_charset_id charset_id;
charset_id = rccConfigGetCharsetByName(config, name);
if (charset_id < 0) return -1;
return rccConfigSetCharset(config, class_id, charset_id);
}
int rccConfigSetOption(rcc_language_config config, rcc_option option, rcc_option_value value) {
if ((!config)||(option>=RCC_MAX_OPTIONS)) return -1;
if (config->options[option] != value) {
if (config->ctx->current_config == config) config->ctx->configure = 1;
config->options[option]=value;
}
return 0;
}
rcc_charset_id rccConfigGetLocaleCharset(rcc_language_config config, const char *locale_variable) {
int err;
rcc_charset *charsets;
rcc_language_id language_id;
char stmp[RCC_MAX_CHARSET_CHARS+1];
if ((!config)||(!config->language)) return -1;
language_id = rccGetCurrentLanguage(config->ctx);
if (language_id) err = rccLocaleGetLanguage(stmp, locale_variable?locale_variable:config->ctx->locale_variable, RCC_MAX_CHARSET_CHARS);
if ((language_id == 0)||((!err)&&(!strcmp(rccGetCurrentLanguageName(config->ctx), stmp))))
err = rccLocaleGetCharset(stmp, locale_variable?locale_variable:config->ctx->locale_variable, RCC_MAX_CHARSET_CHARS);
else
err = 1;
if (err) {
charsets=config->language->charsets;
if ((charsets[0])&&(charsets[1])) return 1;
return -1;
}
return rccConfigGetCharsetByName(config, stmp);
}
|