summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/curconfig.c63
-rw-r--r--src/internal.h10
-rw-r--r--src/librcc.c93
-rw-r--r--src/librcc.h144
-rw-r--r--src/lng.c18
-rw-r--r--src/lngconfig.c186
-rw-r--r--src/rccconfig.c10
-rw-r--r--src/rccconfig.h6
-rw-r--r--src/rcclist.h7
-rw-r--r--src/recode.c2
10 files changed, 489 insertions, 50 deletions
diff --git a/src/curconfig.c b/src/curconfig.c
index ac1b722..6877f87 100644
--- a/src/curconfig.c
+++ b/src/curconfig.c
@@ -1,6 +1,34 @@
#include <stdio.h>
#include "internal.h"
+int rccGetCharsetNumber(rcc_context ctx) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return 0;
+ }
+
+ return rccConfigGetCharsetNumber(ctx->current_config);
+}
+
+int rccGetClassCharsetNumber(rcc_context ctx, rcc_class_id class_id) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return 0;
+ }
+
+ return rccConfigGetClassCharsetNumber(ctx->current_config, class_id);
+}
+
+int rccGetEngineNumber(rcc_context ctx) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return 0;
+ }
+
+ return rccConfigGetEngineNumber(ctx->current_config);
+}
+
+
const char *rccGetEngineName(rcc_context ctx, rcc_engine_id engine_id) {
if (!ctx) {
if (rcc_default_ctx) ctx = rcc_default_ctx;
@@ -19,6 +47,15 @@ const char *rccGetCharsetName(rcc_context ctx, rcc_charset_id charset_id) {
return rccConfigGetCharsetName(ctx->current_config, charset_id);
}
+const char *rccGetClassCharsetName(rcc_context ctx, rcc_class_id class_id, rcc_charset_id charset_id) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return NULL;
+ }
+
+ return rccConfigGetClassCharsetName(ctx->current_config, class_id, charset_id);
+}
+
const char *rccGetAutoCharsetName(rcc_context ctx, rcc_autocharset_id charset_id) {
if (!ctx) {
if (rcc_default_ctx) ctx = rcc_default_ctx;
@@ -46,6 +83,15 @@ rcc_charset_id rccGetCharsetByName(rcc_context ctx, const char *name) {
return rccConfigGetCharsetByName(ctx->current_config, name);
}
+rcc_charset_id rccGetClassCharsetByName(rcc_context ctx, rcc_class_id class_id, const char *name) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return (rcc_charset_id)-1;
+ }
+
+ return rccConfigGetClassCharsetByName(ctx->current_config, class_id, name);
+}
+
rcc_autocharset_id rccGetAutoCharsetByName(rcc_context ctx, const char *name) {
if (!ctx) {
if (rcc_default_ctx) ctx = rcc_default_ctx;
@@ -161,6 +207,14 @@ rcc_charset_id rccGetLocaleCharset(rcc_context ctx, const char *locale_variable)
return rccConfigGetLocaleCharset(ctx->current_config, locale_variable);
}
+rcc_charset_id rccGetLocaleClassCharset(rcc_context ctx, rcc_class_id class_id, const char *locale_variable) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return -1;
+ }
+ return rccConfigGetLocaleClassCharset(ctx->current_config, class_id, locale_variable);
+}
+
rcc_autocharset_id rccDetectCharset(rcc_context ctx, rcc_class_id class_id, const char *buf, size_t len) {
if (!ctx) {
if (rcc_default_ctx) ctx = rcc_default_ctx;
@@ -169,3 +223,12 @@ rcc_autocharset_id rccDetectCharset(rcc_context ctx, rcc_class_id class_id, cons
return rccConfigDetectCharset(ctx->current_config, class_id, buf, len);
}
+
+int rccIsDisabledCharset(rcc_context ctx, rcc_class_id class_id, rcc_charset_id charset_id) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return -1;
+ }
+
+ return rccConfigIsDisabledCharset(ctx->current_config, class_id, charset_id);
+}
diff --git a/src/internal.h b/src/internal.h
index 089311f..5e64551 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -30,6 +30,8 @@
#include "rccmutex.h"
#include "rcclocale.h"
+#define RCC_MAX_ADDITION_CHARSETS 8
+#define RCC_MAX_DISABLED_CHARSETS 64
typedef rcc_language_id rcc_language_parrent_list[RCC_MAX_LANGUAGE_PARRENTS];
@@ -42,6 +44,13 @@ struct rcc_language_internal_t {
typedef struct rcc_language_internal_t rcc_language_internal;
typedef rcc_language_internal *rcc_language_internal_ptr;
+struct rcc_class_internal_t {
+ rcc_class cl;
+ rcc_charset *additional;
+ rcc_charset *disabled;
+};
+typedef struct rcc_class_internal_t rcc_class_internal;
+
struct rcc_context_t {
char locale_variable[RCC_MAX_VARIABLE_CHARS+1];
@@ -58,6 +67,7 @@ struct rcc_context_t {
unsigned int max_classes;
unsigned int n_classes;
+ rcc_class_internal *iclass;
rcc_class_ptr *classes;
rcc_iconv *iconv_from;
diff --git a/src/librcc.c b/src/librcc.c
index c27c47d..98b609e 100644
--- a/src/librcc.c
+++ b/src/librcc.c
@@ -142,6 +142,7 @@ rcc_context rccCreateContext(const char *locale_variable, unsigned int max_langu
rcc_language_ptr *languages;
rcc_language_internal *ilang;
rcc_class_ptr *classes;
+ rcc_class_internal *iclass;
rcc_language_config configs;
rcc_iconv *from;
rcc_mutex mutex;
@@ -168,17 +169,19 @@ rcc_context rccCreateContext(const char *locale_variable, unsigned int max_langu
classes = (rcc_class_ptr*)malloc((max_classes+1)*sizeof(rcc_class_ptr));
from = (rcc_iconv*)malloc((max_classes)*sizeof(rcc_iconv));
ilang = (rcc_language_internal*)malloc((max_languages+1)*sizeof(rcc_language_internal));
+ iclass = (rcc_class_internal*)malloc((max_classes+1)*sizeof(rcc_class_internal));
mutex = rccMutexCreate();
configs = (rcc_language_config)malloc((max_languages)*sizeof(struct rcc_language_config_t));
- if ((!ctx)||(!languages)||(!classes)||(!mutex)||(!from)||(!ilang)||(!mutex)) {
+ if ((!ctx)||(!languages)||(!classes)||(!mutex)||(!from)||(!ilang)||(!iclass)||(!mutex)) {
if (mutex) rccMutexFree(mutex);
if (from) free(from);
if (configs) free(configs);
if (classes) free(classes);
if (languages) free(languages);
if (ilang) free(ilang);
+ if (iclass) free(iclass);
if (ctx) free(ctx);
return NULL;
}
@@ -194,6 +197,7 @@ rcc_context rccCreateContext(const char *locale_variable, unsigned int max_langu
rccRegisterLanguageAlias(ctx, rcc_default_aliases + i);
ctx->ilang = ilang;
+ ctx->iclass = iclass;
ctx->languages = languages;
ctx->max_languages = max_languages;
@@ -304,6 +308,7 @@ void rccFreeContext(rcc_context ctx) {
rccConfigClear(ctx->configs+i);
free(ctx->configs);
}
+ if (ctx->iclass) free(ctx->iclass);
if (ctx->classes) free(ctx->classes);
if (ctx->ilang) free(ctx->ilang);
if (ctx->languages) free(ctx->languages);
@@ -489,11 +494,46 @@ rcc_class_id rccRegisterClass(rcc_context ctx, rcc_class *cl) {
if (ctx->n_classes == ctx->max_classes) return (rcc_class_id)-1;
ctx->configure = 1;
- ctx->classes[ctx->n_classes++] = cl;
+
+ memcpy(ctx->iclass + ctx->n_classes, cl, sizeof(rcc_class));
+ ctx->iclass[ctx->n_classes].disabled = NULL;
+ ctx->iclass[ctx->n_classes].additional = NULL;
+
+ ctx->classes[ctx->n_classes++] = (rcc_class_ptr)(ctx->iclass + ctx->n_classes);
ctx->classes[ctx->n_classes] = NULL;
+
+ if (!strcasecmp(cl->name, "id3")) {
+ rccRegisterDisabledCharsets(ctx, ctx->n_classes - 1, rcc_default_disabled_id3_charsets);
+ } else if (!strcasecmp(cl->name, "id3v2")) {
+ rccRegisterAdditionalCharsets(ctx, ctx->n_classes - 1, rcc_default_additional_id3v2_charsets);
+ }
+
return ctx->n_classes-1;
}
+int rccRegisterDisabledCharsets(rcc_context ctx, rcc_class_id class_id, rcc_charset *charsets) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return -1;
+ }
+ if (ctx->configuration_lock) return -1;
+ if ((class_id == (rcc_class_id)-1)||(class_id >= ctx->n_classes)) return -1;
+
+ ctx->iclass[class_id].disabled = charsets;
+ return 0;
+}
+
+int rccRegisterAdditionalCharsets(rcc_context ctx, rcc_class_id class_id, rcc_charset *charsets) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return -1;
+ }
+ if (ctx->configuration_lock) return -1;
+ if ((class_id == (rcc_class_id)-1)||(class_id >= ctx->n_classes)) return -1;
+
+ ctx->iclass[class_id].additional = charsets;
+ return 0;
+}
rcc_class_type rccGetClassType(rcc_context ctx, rcc_class_id class_id) {
rcc_class_type clt;
@@ -515,6 +555,55 @@ rcc_class_type rccGetClassType(rcc_context ctx, rcc_class_id class_id) {
return clt;
}
+const char *rccGetClassName(rcc_context ctx, rcc_class_id class_id) {
+ if ((class_id<0)||(class_id>=ctx->n_classes)) return NULL;
+
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return NULL;
+ }
+
+ return ctx->classes[class_id]->name;
+}
+
+const char *rccGetClassFullName(rcc_context ctx, rcc_class_id class_id) {
+ if ((class_id<0)||(class_id>=ctx->n_classes)) return NULL;
+
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return NULL;
+ }
+
+ return ctx->classes[class_id]->fullname;
+}
+
+
+int rccIsDisabledCharsetName(rcc_context ctx, rcc_class_id class_id, const char *charset) {
+ unsigned int i;
+ rcc_charset *charsets;
+
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return RCC_CLASS_INVALID;
+ }
+
+ if ((!charset)||(class_id<0)||(class_id>=ctx->n_classes)) return -1;
+
+ charsets = ctx->iclass[class_id].disabled;
+ if (!charsets) return 0;
+
+ for (i=0;charsets[i];i++) {
+ if (!strcasecmp(charsets[i], charset)) return 1;
+ else if (!strcasecmp(charsets[i], rcc_default_unicode_charsets)) {
+ if (rccIsUnicode(charset)) return 1;
+ }
+ else if (!strcasecmp(charsets[i], rcc_default_nonunicode_charsets)) {
+ if (!rccIsUnicode(charset)) return 1;
+ }
+ }
+ return 0;
+}
+
int rccConfigure(rcc_context ctx) {
unsigned int i;
diff --git a/src/librcc.h b/src/librcc.h
index 0529682..9b064d1 100644
--- a/src/librcc.h
+++ b/src/librcc.h
@@ -365,12 +365,51 @@ typedef rcc_class_ptr rcc_class_list[RCC_MAX_CLASSES+1];
*/
rcc_class_id rccRegisterClass(rcc_context ctx, rcc_class *cl);
/**
+ * Register additional charsets for the current class.
+ * @param ctx is working context ( or default one if NULL supplied )
+ * @param class_id is class id.
+ * @param charsets is NULL terminated list of classes.
+ * @return non zero value in the case of a error.
+ */
+int rccRegisterAdditionalCharsets(rcc_context ctx, rcc_class_id class_id, rcc_charset *charsets);
+/**
+ * Register names of charsets disabled in the specified class.
+ * @param ctx is working context ( or default one if NULL supplied )
+ * @param class_id is class id.
+ * @param charsets is NULL terminated list of classes ("unicode" / "nonunicode" specifies corespondent group of charsets).
+ * @return non zero value in the case of a error.
+ */
+int rccRegisterDisabledCharsets(rcc_context ctx, rcc_class_id class_id, rcc_charset *charsets);
+/**
+ * Checks if charset is disabled for the specified class.
+ * @param ctx is working context ( or default one if NULL supplied )
+ * @param class_id is class id.
+ * @param charset is charset name.
+ * @return 1 if charset is disabled, 0 if charset is enabled, -1 in the case of error.
+ */
+int rccIsDisabledCharsetName(rcc_context ctx, rcc_class_id class_id, const char *charset);
+
+/**
* Determines 'class type' of supplied class.
* @param ctx is working context ( or default one if NULL supplied )
* @param class_id is class id
* @return class type or -1 in case of a error.
*/
rcc_class_type rccGetClassType(rcc_context ctx, rcc_class_id class_id);
+/**
+ * Returns name of supplied class.
+ * @param ctx is working context ( or default one if NULL supplied )
+ * @param class_id is class id
+ * @return class name or NULL in case of a error.
+ */
+const char *rccGetClassName(rcc_context ctx, rcc_class_id class_id);
+/**
+ * Returns full name of supplied class.
+ * @param ctx is working context ( or default one if NULL supplied )
+ * @param class_id is class id
+ * @return class full name or NULL in case of a error.
+ */
+const char *rccGetClassFullName(rcc_context ctx, rcc_class_id class_id);
/*******************************************************************************
************************ Altering Configuaration *******************************
@@ -441,6 +480,21 @@ typedef struct rcc_option_range_t {
}rcc_option_range;
/* lng.c */
+
+/**
+ * Return number of configured languages
+ *
+ * @param ctx is working context ( or default one if NULL supplied )
+ * @return number of configured languages or 0 in the case of error
+ */
+int rccGetLanguageNumber(rcc_context ctx);
+/**
+ * Return number of configured classes
+ *
+ * @param ctx is working context ( or default one if NULL supplied )
+ * @return number of configured classes or 0 in the case of error
+ */
+int rccGetClassNumber(rcc_context ctx);
/**
* Determines name of the supplied language.
*
@@ -636,7 +690,7 @@ rcc_language_config rccCheckConfig(rcc_context ctx, rcc_language_id language_id)
* @param ctx is working context ( or default one if NULL supplied )
* @param language_id is concerned language id
* @return configuration context. The NULL is returned in the case of errors or
- * dummy (Dissable LibRCC) language is selected.
+ * dummy (Disable LibRCC) language is selected.
*/
rcc_language_config rccGetConfig(rcc_context ctx, rcc_language_id language_id);
/**
@@ -690,6 +744,29 @@ rcc_language_id rccConfigGetLanguage(rcc_language_config config);
const char *rccConfigGetLanguageName(rcc_language_config config);
/**
+ * Return number of configured charsets
+ *
+ * @param config is language configuration
+ * @return number of charsets available in the configuration or 0 in the case of error
+ */
+int rccConfigGetCharsetNumber(rcc_language_config config);
+/**
+ * Return number of configured charsets
+ *
+ * @param config is language configuration
+ * @param class_id is class id.
+ * @return number of charsets available in the configuration or 0 in the case of error
+ */
+int rccConfigGetClassCharsetNumber(rcc_language_config config, rcc_class_id class_id);
+/**
+ * Return number of configured encoding auto-detection engines
+ *
+ * @param config is language configuration
+ * @return number of engines or 0 in the case of error
+ */
+int rccConfigGetEngineNumber(rcc_language_config config);
+
+/**
* Return supplied engine name
*
* @param config is language configuration
@@ -706,6 +783,16 @@ const char *rccConfigGetEngineName(rcc_language_config config, rcc_engine_id eng
*/
const char *rccConfigGetCharsetName(rcc_language_config config, rcc_charset_id charset_id);
/**
+ * Return supplied encoding name
+ *
+ * @param config is language configuration
+ * @param class_id is charset encodings
+ * @param charset_id is desired charset
+ * @return selected encoding name or NULL in case of error.
+ */
+const char *rccConfigGetClassCharsetName(rcc_language_config config, rcc_class_id class_id, rcc_charset_id charset_id);
+
+/**
* Function finds engine id by the supplied name.
*
* @param config is language configuration
@@ -721,14 +808,30 @@ rcc_engine_id rccConfigGetEngineByName(rcc_language_config config, const char *n
* @return encoding id [0-n] or -1 if not found.
*/
rcc_charset_id rccConfigGetCharsetByName(rcc_language_config config, const char *name);
-
+/**
+ * Function finds encoding id by the supplied name.
+ *
+ * @param config is language configuration
+ * @param class_id is encoding class
+ * @param name is encoding name
+ * @return encoding id [0-n] or -1 if not found.
+ */
+rcc_charset_id rccConfigGetClassCharsetByName(rcc_language_config config, rcc_class_id class_id, const char *name);
+/**
+ * Checks if charset is disabled for the specified class.
+ * @param config is language configuration
+ * @param class_id is class id.
+ * @param charset is charset name.
+ * @return 1 if charset is disabled, 0 if charset is enabled, -1 in the case of error.
+ */
+int rccConfigIsDisabledCharset(rcc_language_config config, rcc_class_id class_id, rcc_charset_id charset_id);
/**
* Return selected engin id.
*
* @param config is language configuration
* @return selected engine id [-1-n]
* - -1 engine is not configured and first available will be used
- * - 0 engines are dissabled
+ * - 0 engines are disabled
* - >0 paticular engine id
*/
rcc_engine_id rccConfigGetSelectedEngine(rcc_language_config config);
@@ -743,11 +846,11 @@ const char *rccConfigGetSelectedEngineName(rcc_language_config config);
/**
* Return current engine_id. The default value will be resolved to paticular engine id. Normally,
* the id of the first available engine will be returned. If no engines registered for supplied
- * language the 0 will be returned, indicating id of dummy(dissabled) engine.
+ * language the 0 will be returned, indicating id of dummy(disabled) engine.
*
* @param config is language configuration
* @return selected engine id [0-n] or -1 in case of error
- * - 0 engines are dissabled
+ * - 0 engines are disabled
* - >0 paticular engine id
*/
rcc_engine_id rccConfigGetCurrentEngine(rcc_language_config config);
@@ -845,14 +948,30 @@ int rccConfigSetCharsetByName(rcc_language_config config, rcc_class_id class_id,
* @return encoding id
*/
rcc_charset_id rccConfigGetLocaleCharset(rcc_language_config config, const char *locale_variable);
-
+/**
+ * Function will return encoding id of charset specified by locale configuration.
+ *
+ * @param config is language configuration
+ * @param class_id is encoding class
+ * @param locale_variable is locale variable (Default(NULL) is LC_CTYPE)
+ * @return encoding id
+ */
+rcc_charset_id rccConfigGetLocaleClassCharset(rcc_language_config config, rcc_class_id class_id, const char *locale_variable);
/* curconfig.c */
+int rccGetCharsetNumber(rcc_context ctx);
+int rccGetClassCharsetNumber(rcc_context ctx, rcc_class_id class_id);
+int rccGetEngineNumber(rcc_context ctx);
+
const char *rccGetEngineName(rcc_context ctx, rcc_engine_id engine_id);
const char *rccGetCharsetName(rcc_context ctx, rcc_charset_id charset_id);
+const char *rccGetClassCharsetName(rcc_context ctx, rcc_class_id class_id, rcc_charset_id charset_id);
rcc_engine_id rccGetEngineByName(rcc_context ctx, const char *name);
rcc_charset_id rccGetCharsetByName(rcc_context ctx, const char *name);
+rcc_charset_id rccGetClassCharsetByName(rcc_context ctx, rcc_class_id class_id, const char *name);
+
+int rccIsDisabledCharset(rcc_context ctx, rcc_class_id class_id, rcc_charset_id charset_id);
rcc_engine_id rccGetSelectedEngine(rcc_context ctx);
const char *rccGetSelectedEngineName(rcc_context ctx);
@@ -869,20 +988,13 @@ int rccSetEngineByName(rcc_context ctx, const char *name);
int rccSetCharsetByName(rcc_context ctx, rcc_class_id class_id, const char *name);
rcc_charset_id rccGetLocaleCharset(rcc_context ctx, const char *locale_variable);
+rcc_charset_id rccGetLocaleClassCharset(rcc_context ctx, rcc_class_id class_id, const char *locale_variable);
rcc_autocharset_id rccDetectCharset(rcc_context ctx, rcc_class_id class_id, const char *buf, size_t len);
/*******************************************************************************
************************ Language Configuaration *******************************
*******************************************************************************/
-/* rcclist.c */
-rcc_language_ptr *rccGetLanguageList(rcc_context ctx);
-rcc_charset *rccGetCharsetList(rcc_context ctx, rcc_language_id language_id);
-rcc_engine_ptr *rccGetEngineList(rcc_context ctx, rcc_language_id language_id);
-rcc_charset *rccGetCurrentCharsetList(rcc_context ctx);
-rcc_engine_ptr *rccGetCurrentEngineList(rcc_context ctx);
-rcc_charset *rccGetCurrentAutoCharsetList(rcc_context ctx);
-rcc_class_ptr *rccGetClassList(rcc_context ctx);
/*******************************************************************************
************************ RCC_STRING Manipulations ******************************
@@ -1283,9 +1395,11 @@ char *rccConfigSizedRecode(rcc_language_config config, rcc_class_id from, rcc_cl
* Recode string from specified encoding to #rcc_string.
*
* @param config is language configuration
+ * @param class_id is encoding class
* @param charset is source encoding
* @param buf is original string (perhaps not zero terminated)
* @param len is exact size of string or 0. In the last case the size is determined using 'strlen' function.
+ * @param rlen in rlen the size of recoded string will be returned.
* @result is recoded string or NULL if recoding is not required or failed. It is up to the caller to free memory.
*/
rcc_string rccConfigSizedRecodeFromCharset(rcc_language_config config, rcc_class_id class_id, const char *charset, const char *buf, size_t len, size_t *rlen);
@@ -1293,8 +1407,10 @@ rcc_string rccConfigSizedRecodeFromCharset(rcc_language_config config, rcc_class
* Recode string from #rcc_string to specified encoding.
*
* @param config is language configuration
+ * @param class_id is encoding class
* @param charset is destination encoding
* @param buf is original zero terminated string
+ * @param len is exact size of string or 0. In the last case the size is determined using 'strlen' function.
* @param rlen in rlen the size of recoded string will be returned.
* @result is recoded string or NULL if recoding is not required or failed. It is up to the caller to free memory.
*/
diff --git a/src/lng.c b/src/lng.c
index 4b0676d..5605768 100644
--- a/src/lng.c
+++ b/src/lng.c
@@ -5,6 +5,24 @@
#include "rccconfig.h"
#include "rcclocale.h"
+int rccGetLanguageNumber(rcc_context ctx) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return 0;
+ }
+
+ return ctx->n_languages;
+}
+
+int rccGetClassNumber(rcc_context ctx) {
+ if (!ctx) {
+ if (rcc_default_ctx) ctx = rcc_default_ctx;
+ else return 0;
+ }
+
+ return ctx->n_classes;
+}
+
rcc_language_ptr rccGetLanguagePointer(rcc_context ctx, rcc_language_id language_id) {
if (!ctx) {
if (rcc_default_ctx) ctx = rcc_default_ctx;
diff --git a/src/lngconfig.c b/src/lngconfig.c
index 7e5a428..20aff63 100644
--- a/src/lngconfig.c
+++ b/src/lngconfig.c
@@ -7,6 +7,7 @@
#include "internal.h"
#include "rccconfig.h"
#include "rcclocale.h"
+#include "rcclist.h"
#include "lng.h"
rcc_language_id rccConfigGetLanguage(rcc_language_config config) {
@@ -34,19 +35,54 @@ const char *rccConfigGetLanguageName(rcc_language_config config) {
return config->language->sn;
}
+int rccConfigGetCharsetNumber(rcc_language_config config) {
+ int i;
+ rcc_charset *charsets;
-rcc_engine_ptr rccConfigGetEnginePointer(rcc_language_config config, rcc_engine_id engine_id) {
- unsigned int i;
- rcc_engine_ptr *engines;
+ if ((!config)||(!config->language)) return 0;
- if ((!config)||(!config->language)) return NULL;
- if (engine_id == (rcc_engine_id)-1) return NULL;
+ charsets = config->language->charsets;
+
+ for (i=0;charsets[i];i++);
+
+ return i;
+}
+
+int rccConfigGetClassCharsetNumber(rcc_language_config config, rcc_class_id class_id) {
+ int sum, i;
+ rcc_charset *charsets;
+
+ if ((!config)||(!config->language)) return 0;
+ if ((class_id<0)||(class_id>=config->ctx->n_classes)) return 0;
+
+ sum = rccConfigGetCharsetNumber(config);
+
+ charsets = config->ctx->iclass[class_id].additional;
+ if (charsets) {
+ for (i=0;charsets[i];i++)
+ if (rccConfigGetCharsetByName(config, charsets[i]) == (rcc_language_id)-1) sum++;
+ }
+
+ return sum;
+}
+
+int rccConfigGetEngineNumber(rcc_language_config config) {
+ int i;
+ rcc_engine_ptr *engines;
+ if ((!config)||(!config->language)) return 0;
engines = config->language->engines;
for (i=0;engines[i];i++);
- if (engine_id>=i) return NULL;
+ return i;
+}
+
+
+rcc_engine_ptr rccConfigGetEnginePointer(rcc_language_config config, rcc_engine_id engine_id) {
+ if ((!config)||(!config->language)) return NULL;
+ if (engine_id == (rcc_engine_id)-1) return NULL;
+ if (engine_id>=rccConfigGetEngineNumber(config)) return NULL;
- return engines[engine_id];
+ return config->language->engines[engine_id];
}
rcc_engine_ptr rccConfigCheckEnginePointer(rcc_language_config config, rcc_engine_id engine_id) {
@@ -78,6 +114,7 @@ rcc_engine_ptr rccConfigCheckCurrentEnginePointer(rcc_language_config config) {
const char *rccConfigGetEngineName(rcc_language_config config, rcc_engine_id engine_id) {
rcc_engine_ptr engine;
+ if (!engine_id) return rcc_disabled_engine_sn;
if ((!config)||(!config->language)) return NULL;
if (engine_id == (rcc_engine_id)-1) return rcc_engine_nonconfigured;
@@ -89,17 +126,38 @@ const char *rccConfigGetEngineName(rcc_language_config config, rcc_engine_id eng
}
const char *rccConfigGetCharsetName(rcc_language_config config, rcc_charset_id charset_id) {
- unsigned int i;
+ if (!charset_id) return rcc_default_charset;
+
+ if ((!config)||(!config->language)) return NULL;
+ if (charset_id>=rccConfigGetCharsetNumber(config)) return NULL;
+
+ return config->language->charsets[charset_id];
+}
+
+const char *rccConfigGetClassCharsetName(rcc_language_config config, rcc_class_id class_id, rcc_charset_id charset_id) {
+ unsigned int i, pos;
rcc_charset *charsets;
+ if (!charset_id) return rcc_default_charset;
+
if ((!config)||(!config->language)) return NULL;
+ if ((class_id<0)||(class_id>=config->ctx->n_classes)) return NULL;
- charsets = config->language->charsets;
+ pos = rccConfigGetCharsetNumber(config);
+ if (charset_id < pos) return rccConfigGetCharsetName(config, charset_id);
+
+ charset_id -= pos;
- for (i=0;charsets[i];i++);
- if (charset_id>=i) return NULL;
+ charsets = config->ctx->iclass[class_id].additional;
+ if (!charsets) return NULL;
- return charsets[charset_id];
+ for (i=0;charsets[i];i++)
+ if (rccConfigGetCharsetByName(config, charsets[i]) == (rcc_language_id)-1) {
+ if (!charset_id) break;
+ charset_id--;
+ }
+
+ return charsets[i];
}
const char *rccConfigGetAutoCharsetName(rcc_language_config config, rcc_autocharset_id charset_id) {
@@ -148,6 +206,31 @@ rcc_charset_id rccConfigGetCharsetByName(rcc_language_config config, const char
return (rcc_charset_id)-1;
}
+rcc_charset_id rccConfigGetClassCharsetByName(rcc_language_config config, rcc_class_id class_id, const char *name) {
+ unsigned int pos, i = 0;
+ rcc_charset_id charset_id;
+ rcc_charset *charsets;
+
+ if ((!config)||(!config->language)||(!name)) return (rcc_charset_id)-1;
+ if ((class_id<0)||(class_id>=config->ctx->n_classes)) return (rcc_charset_id)-1;
+
+ charset_id = rccConfigGetCharsetByName(config, name);
+ if (charset_id != (rcc_charset_id)-1) return charset_id;
+
+ pos = rccConfigGetCharsetNumber(config);
+
+ charsets = config->ctx->iclass[class_id].additional;
+ if (!charsets) return (rcc_charset_id)-1;
+
+ for (i=0;charsets[i];i++)
+ if (rccConfigGetCharsetByName(config, charsets[i]) == (rcc_language_id)-1) {
+ if (!strcasecmp(charsets[i], name)) return pos;
+ pos++;
+ }
+
+ return (rcc_charset_id)-1;
+}
+
rcc_autocharset_id rccConfigGetAutoCharsetByName(rcc_language_config config, const char *name) {
unsigned int i;
rcc_engine_id engine_id;
@@ -168,6 +251,17 @@ rcc_autocharset_id rccConfigGetAutoCharsetByName(rcc_language_config config, con
return (rcc_autocharset_id)-1;
}
+int rccConfigIsDisabledCharset(rcc_language_config config, rcc_class_id class_id, rcc_charset_id charset_id) {
+ rcc_charset charset;
+
+ if ((!config)||(!config->language)) return (rcc_autocharset_id)-1;
+
+ charset = rccConfigGetClassCharsetName(config, class_id, charset_id);
+ if (!charset) return -1;
+
+ return rccIsDisabledCharsetName(config->ctx, class_id, charset);
+}
+
int rccConfigInit(rcc_language_config config, rcc_context ctx) {
int err;
unsigned int i;
@@ -469,19 +563,19 @@ const char *rccConfigGetSelectedCharsetName(rcc_language_config config, rcc_clas
charset_id = rccConfigGetSelectedCharset(config, class_id);
if ((charset_id == (rcc_charset_id)-1)||(!config->language)) return NULL;
- return rccConfigGetCharsetName(config, charset_id);
+ return rccConfigGetClassCharsetName(config, class_id, charset_id);
}
rcc_charset_id rccConfigGetCurrentCharset(rcc_language_config config, rcc_class_id class_id) {
- unsigned int i;
+ unsigned int i, max;
rcc_charset_id charset_id;
+ rcc_charset_id all_charset_id = (rcc_language_id)-1;
rcc_class_default_charset *defcharset;
const char *lang;
rcc_language *language;
rcc_class_ptr *classes;
- rcc_charset *charsets;
rcc_class *cl;
@@ -509,7 +603,7 @@ rcc_charset_id rccConfigGetCurrentCharset(rcc_language_config config, rcc_class_
if (config->default_charset[class_id]) return config->default_charset[class_id];
if (cl->defvalue) {
- charset_id = rccConfigGetLocaleCharset(config, defvalue);
+ charset_id = rccConfigGetLocaleClassCharset(config, class_id, defvalue);
if ((charset_id != 0)&&(charset_id != (rcc_charset_id)-1)) {
config->default_charset[class_id] = charset_id;
return charset_id;
@@ -517,7 +611,7 @@ rcc_charset_id rccConfigGetCurrentCharset(rcc_language_config config, rcc_class_
}
if (cl->defvalue) {
- charset_id = rccConfigGetCharsetByName(config, defvalue);
+ charset_id = rccConfigGetClassCharsetByName(config, class_id, defvalue);
if ((charset_id != 0)&&(charset_id != (rcc_charset_id)-1)) {
config->default_charset[class_id] = charset_id;
return charset_id;
@@ -530,26 +624,35 @@ rcc_charset_id rccConfigGetCurrentCharset(rcc_language_config config, rcc_class_
for (i = 0; cl->defcharset[i].lang; i++) {
if (!strcasecmp(lang, defcharset[i].lang)) {
- charset_id = rccConfigGetCharsetByName(config, defcharset[i].charset);
+ charset_id = rccConfigGetClassCharsetByName(config, class_id, defcharset[i].charset);
if ((charset_id != 0)&&(charset_id != (rcc_charset_id)-1)) {
config->default_charset[class_id] = charset_id;
return charset_id;
} else break;
+ } else if (!strcasecmp(rcc_default_all, defcharset[i].lang)) {
+ charset_id = rccConfigGetClassCharsetByName(config, class_id, defcharset[i].charset);
+ if ((charset_id != 0)&&(charset_id != (rcc_charset_id)-1)) {
+ all_charset_id = charset_id;
+ }
}
}
+
+ if (all_charset_id != (rcc_language_id)-1) {
+ config->default_charset[class_id] = all_charset_id;
+ return all_charset_id;
+ }
}
- charset_id = rccConfigGetLocaleCharset(config, defvalue);
+ charset_id = rccConfigGetLocaleClassCharset(config, class_id, defvalue);
if ((charset_id != 0)&&(charset_id != (rcc_charset_id)-1)) {
config->default_charset[class_id] = charset_id;
return charset_id;
}
- charsets=language->charsets;
- if ((charsets[0])&&(charsets[1])) {
- config->default_charset[class_id]=(rcc_charset_id)1;
- return (rcc_charset_id)1;
- }
+ max = rccConfigGetClassCharsetNumber(config, class_id);
+ for (i = 1; i< max; i++)
+ if (!rccConfigIsDisabledCharset(config, class_id, (rcc_charset_id)i)) return (rcc_charset_id)i;
+
return (rcc_charset_id)-1;
}
@@ -559,7 +662,7 @@ const char *rccConfigGetCurrentCharsetName(rcc_language_config config, rcc_class
charset_id = rccConfigGetCurrentCharset(config, class_id);
if ((charset_id == (rcc_charset_id)-1)||(!config->language)) return NULL;
- return rccConfigGetCharsetName(config, charset_id);
+ return rccConfigGetClassCharsetName(config, class_id, charset_id);
}
@@ -601,13 +704,10 @@ int rccConfigSetEngineByName(rcc_language_config config, const char *name) {
}
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)) return -1;
-
- for (i=0;config->language->charsets[i];i++);
- if (charset_id >= i) return -1;
+ if (charset_id >= rccConfigGetClassCharsetNumber(config, class_id)) return -1;
+ if (rccConfigIsDisabledCharset(config, class_id, charset_id)) return -1;
if (config->charset[class_id] != charset_id) {
if (config->ctx->classes[class_id]->flags&RCC_CLASS_FLAG_CONST) return -1;
@@ -627,7 +727,7 @@ int rccConfigSetCharset(rcc_language_config config, rcc_class_id class_id, rcc_c
int rccConfigSetCharsetByName(rcc_language_config config, rcc_class_id class_id, const char *name) {
rcc_charset_id charset_id;
- charset_id = rccConfigGetCharsetByName(config, name);
+ charset_id = rccConfigGetClassCharsetByName(config, class_id, name);
if (charset_id == (rcc_charset_id)-1) return -1;
return rccConfigSetCharset(config, class_id, charset_id);
@@ -656,6 +756,30 @@ rcc_charset_id rccConfigGetLocaleCharset(rcc_language_config config, const char
return (rcc_charset_id)-1;
}
+rcc_charset_id rccConfigGetLocaleClassCharset(rcc_language_config config, rcc_class_id class_id, const char *locale_variable) {
+ const char *lv;
+ rcc_language_id language_id;
+ char lang[RCC_MAX_CHARSET_CHARS+1];
+ char stmp[RCC_MAX_CHARSET_CHARS+1];
+
+ if ((!config)||(!config->language)) return (rcc_charset_id)-1;
+
+ lv = locale_variable?locale_variable:config->ctx->locale_variable;
+
+ language_id = rccGetLanguageByName(config->ctx, config->language->sn);
+ if (language_id != (rcc_language_id)-1) {
+ if (!rccLocaleGetCharset(stmp, lv, RCC_MAX_CHARSET_CHARS)) {
+ if (rccIsUnicode(stmp))
+ return rccConfigGetClassCharsetByName(config, class_id, stmp);
+ if ((!rccLocaleGetLanguage(lang, lv, RCC_MAX_CHARSET_CHARS))&&(!strcmp(config->language->sn, lang)))
+ return rccConfigGetClassCharsetByName(config, class_id, stmp);
+ }
+ }
+
+ return (rcc_charset_id)-1;
+}
+
+
int rccConfigConfigure(rcc_language_config config) {
int err;
rcc_context ctx;
diff --git a/src/rccconfig.c b/src/rccconfig.c
index 5fecb6b..0752ee3 100644
--- a/src/rccconfig.c
+++ b/src/rccconfig.c
@@ -22,6 +22,12 @@ rcc_language_relation rcc_default_relations_embeded[RCC_MAX_RELATIONS + 1] = {
{ NULL, NULL }
};
+const char rcc_default_unicode_charsets[] = "unicode";
+const char rcc_default_nonunicode_charsets[] = "nonunicode";
+rcc_charset rcc_default_disabled_id3_charsets[] = { rcc_default_unicode_charsets, NULL };
+rcc_charset rcc_default_additional_id3v2_charsets[] = { "UTF-8", "UTF-16", "UTF-16BE", NULL };
+
+const char rcc_default_all[] = "all";
const char rcc_default_language_sn[] = "default";
const char rcc_disabled_language_sn[] = "Off";
const char rcc_english_language_sn[] = "en";
@@ -37,11 +43,11 @@ rcc_engine rcc_default_engine = {
};
rcc_engine rcc_russian_engine = {
- "Russian", NULL, NULL, &rccAutoengineRussian, {"CP1251","KOI8-R","UTF-8","IBM866", NULL}
+ "LibRCD", NULL, NULL, &rccAutoengineRussian, {"CP1251","KOI8-R","UTF-8","IBM866", NULL}
};
rcc_engine rcc_ukrainian_engine = {
- "Russian", NULL, NULL, &rccAutoengineRussian, {"CP1251","KOI8-U","UTF-8","IBM865", NULL}
+ "LibRCD", NULL, NULL, &rccAutoengineRussian, {"CP1251","KOI8-U","UTF-8","IBM865", NULL}
};
rcc_language rcc_default_languages[RCC_MAX_LANGUAGES + 1];
diff --git a/src/rccconfig.h b/src/rccconfig.h
index 7361910..f7f70dd 100644
--- a/src/rccconfig.h
+++ b/src/rccconfig.h
@@ -7,6 +7,7 @@
#undef RCC_DEBUG_LANGDETECT
#define RCC_LOCALE_VARIABLE "LC_CTYPE"
+extern const char rcc_default_all[];
extern const char rcc_default_language_sn[];
extern const char rcc_english_language_sn[];
extern const char rcc_disabled_language_sn[];
@@ -19,6 +20,11 @@ extern rcc_language_relation rcc_default_relations_embeded[];
extern const char rcc_default_charset[];
extern const char rcc_utf8_charset[];
+extern const char rcc_default_unicode_charsets[];
+extern const char rcc_default_nonunicode_charsets[];
+extern rcc_charset rcc_default_disabled_id3_charsets[];
+extern rcc_charset rcc_default_additional_id3v2_charsets[];
+
extern const char rcc_engine_nonconfigured[];
extern const char rcc_option_nonconfigured[];
diff --git a/src/rcclist.h b/src/rcclist.h
index 000e09c..71076b7 100644
--- a/src/rcclist.h
+++ b/src/rcclist.h
@@ -1,5 +1,12 @@
#ifndef _RCC_LIST_H
#define _RCC_LIST_H
+rcc_language_ptr *rccGetLanguageList(rcc_context ctx);
+rcc_charset *rccGetCharsetList(rcc_context ctx, rcc_language_id language_id);
+rcc_engine_ptr *rccGetEngineList(rcc_context ctx, rcc_language_id language_id);
+rcc_charset *rccGetCurrentCharsetList(rcc_context ctx);
+rcc_engine_ptr *rccGetCurrentEngineList(rcc_context ctx);
+rcc_charset *rccGetCurrentAutoCharsetList(rcc_context ctx);
+rcc_class_ptr *rccGetClassList(rcc_context ctx);
#endif /* _RCC_LIST_H */
diff --git a/src/recode.c b/src/recode.c
index ee9ac53..a528481 100644
--- a/src/recode.c
+++ b/src/recode.c
@@ -368,7 +368,7 @@ static char *rccRecodeTranslate(rcc_language_config *config, rcc_class_id class_
if (trans) {
translated = rccTranslate(trans, utfstring);
if (translated) {
- if ((!((rcc_language_internal*)curconfig->language)->latin)&&(rccIsASCII(translated))) {
+ if (((translate != RCC_OPTION_TRANSLATE_TO_ENGLISH))&&(!((rcc_language_internal*)curconfig->language)->latin)&&(rccIsASCII(translated))) {
free(translated);
translated = NULL;
}