summaryrefslogtreecommitdiffstats
path: root/src/librcc.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2005-07-04 04:14:58 +0000
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2005-07-04 04:14:58 +0000
commita21deef1c62467b21500f94dfb2ab3d58e69cb85 (patch)
tree742d2c1e2592fbcb580ebce9fac7f4f867e6218b /src/librcc.c
parent97e76f4c979d7a0c4ed296c512c3024e3c6afa18 (diff)
downloadlibrcc-a21deef1c62467b21500f94dfb2ab3d58e69cb85.tar.gz
librcc-a21deef1c62467b21500f94dfb2ab3d58e69cb85.tar.bz2
librcc-a21deef1c62467b21500f94dfb2ab3d58e69cb85.tar.xz
librcc-a21deef1c62467b21500f94dfb2ab3d58e69cb85.zip
04.07.2005
Diffstat (limited to 'src/librcc.c')
-rw-r--r--src/librcc.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/src/librcc.c b/src/librcc.c
index 684e76a..d6acc72 100644
--- a/src/librcc.c
+++ b/src/librcc.c
@@ -9,6 +9,7 @@
#include "rcclist.h"
+
int rccInit() {
/*DS: Load addition languages from config! */
return rccEncaInit();
@@ -18,7 +19,7 @@ void rccFree() {
rccEncaFree();
}
-rcc_context rccCreateContext(rcc_init_flags flags, unsigned int max_languages, unsigned int max_classes, const char *locale) {
+rcc_context rccCreateContext(const char *locale_variable, unsigned int max_languages, unsigned int max_classes, rcc_class_ptr defclasses, rcc_init_flags flags) {
int err;
unsigned int i;
@@ -27,9 +28,21 @@ rcc_context rccCreateContext(rcc_init_flags flags, unsigned int max_languages, u
rcc_class_ptr *classes;
rcc_language_config configs;
iconv_t *from, *to;
+
+ if (!max_languages) {
+ if (flags&RCC_NO_DEFAULT_CONFIGURATION) max_languages = RCC_MAX_LANGUAGES;
+ else {
+ for (i=0;rcc_default_languages[i].sn;i++);
+ max_languages = i;
+ }
+ }
- if (!max_languages) max_languages = RCC_MAX_LANGUAGES;
- if (!max_classes) max_classes = RCC_MAX_CLASSES;
+ if (!max_classes) {
+ if (defclasses) {
+ for (i=0;defclasses[i].name;i++);
+ max_classes = i;
+ } else max_classes = RCC_MAX_CLASSES;
+ }
ctx = (rcc_context)malloc(sizeof(struct rcc_context_t));
languages = (rcc_language_ptr*)malloc((max_languages+1)*sizeof(rcc_language_ptr));
@@ -49,6 +62,8 @@ rcc_context rccCreateContext(rcc_init_flags flags, unsigned int max_languages, u
return NULL;
}
+ ctx->configuration_lock = 0;
+
ctx->aliases[0] = NULL;
for (i=0;rcc_default_aliases[i].alias;i++)
rccRegisterLanguageAlias(ctx, rcc_default_aliases + i);
@@ -87,17 +102,20 @@ rcc_context rccCreateContext(rcc_init_flags flags, unsigned int max_languages, u
ctx->current_language = 0;
- if (locale) {
- if (strlen(locale)>=RCC_MAX_VARIABLE_CHARS) {
+ if (locale_variable) {
+ if (strlen(locale_variable)>=RCC_MAX_VARIABLE_CHARS) {
rccFree(ctx);
return NULL;
}
- strcpy(ctx->locale_variable, locale);
+ strcpy(ctx->locale_variable, locale_variable);
} else {
strcpy(ctx->locale_variable, RCC_LOCALE_VARIABLE);
}
- if (flags&RCC_DEFAULT_CONFIGURATION) {
+ if (flags&RCC_NO_DEFAULT_CONFIGURATION) {
+ rccRegisterLanguage(ctx, rcc_default_languages);
+ ctx->current_config = NULL;
+ } else {
for (i=0;rcc_default_languages[i].sn;i++)
rccRegisterLanguage(ctx, rcc_default_languages+i);
@@ -107,15 +125,21 @@ rcc_context rccCreateContext(rcc_init_flags flags, unsigned int max_languages, u
}
ctx->current_config = rccGetCurrentConfig(ctx);
- } else {
- rccRegisterLanguage(ctx, rcc_default_languages);
- ctx->current_config = NULL;
}
+
+ if (defclasses) {
+ for (i=0;defclasses[i].name;i++)
+ rccRegisterClass(ctx, defclasses+i);
+
+ if (max_classes < i) {
+ rccFree(ctx);
+ return NULL;
+ }
+ }
for (i=0;i<RCC_MAX_OPTIONS;i++)
ctx->options[i] = 0;
- ctx->configuration_lock = 0;
ctx->configure = 1;
return ctx;
@@ -153,14 +177,14 @@ void rccFreeContext(rcc_context ctx) {
unsigned int i;
if (ctx) {
- rccFreeEngine(&ctx->engine_ctx);
+ rccEngineFree(&ctx->engine_ctx);
rccFreeIConv(ctx);
if (ctx->iconv_from) free(ctx->iconv_from);
if (ctx->iconv_to) free(ctx->iconv_to);
if (ctx->configs) {
for (i=0;i<ctx->max_languages;i++)
- rccFreeConfig(ctx->configs+i);
+ rccConfigFree(ctx->configs+i);
free(ctx->configs);
}
if (ctx->classes) free(ctx->classes);
@@ -234,13 +258,15 @@ rcc_alias_id rccRegisterLanguageAlias(rcc_context ctx, rcc_language_alias *alias
}
rcc_class_id rccRegisterClass(rcc_context ctx, rcc_class *cl) {
+ puts("yes");
if ((!ctx)||(!cl)) return -1;
if (ctx->configuration_lock) return -3;
if (ctx->n_classes == ctx->max_classes) return -2;
+ puts(" -----> New class");
ctx->configure = 1;
- ctx->classes[ctx->n_languages++] = cl;
- ctx->classes[ctx->n_languages] = NULL;
+ ctx->classes[ctx->n_classes++] = cl;
+ ctx->classes[ctx->n_classes] = NULL;
return ctx->n_classes-1;
}