summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2005-08-09 23:22:36 +0000
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2005-08-09 23:22:36 +0000
commit63bf2a90a6d6fb0859e4c9dd9fcac85de9adc0f1 (patch)
treef18ef0378e787945d5fd722b2c2793b878143221
parent9d4628df369b92016b7fc3bfc7fed6d06ff2ca9a (diff)
downloadlibrcc-63bf2a90a6d6fb0859e4c9dd9fcac85de9adc0f1.tar.gz
librcc-63bf2a90a6d6fb0859e4c9dd9fcac85de9adc0f1.tar.bz2
librcc-63bf2a90a6d6fb0859e4c9dd9fcac85de9adc0f1.tar.xz
librcc-63bf2a90a6d6fb0859e4c9dd9fcac85de9adc0f1.zip
- Russian Engine is really renamed
- Translate to English is fixed - Default charset for "all" languages - Support for per-class additional and dissabled charsets - Use 'GetSomethingNumber' instead of 'GetSomethingList'. 'GetSomethingList' functions are depricated. - rccUiGetSomethingName gets id's on the input instead of names
-rw-r--r--ToDo3
-rw-r--r--docs/api/Doxyfile4
-rw-r--r--engines/Makefile.am4
-rw-r--r--examples/rcc-gtk-config.c1
-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
-rw-r--r--ui/gtk.c55
-rw-r--r--ui/internal.h3
-rw-r--r--ui/librccui.c56
-rw-r--r--ui/librccui.h8
-rw-r--r--ui/rccnames.c26
19 files changed, 579 insertions, 120 deletions
diff --git a/ToDo b/ToDo
index db0515f..6c0cfa3 100644
--- a/ToDo
+++ b/ToDo
@@ -18,7 +18,7 @@
+ Language detection (same as charsets, but for UTF8...)
* Consider word recognition based on probability
+ Autolearning is triggered by large enough dictionary words
-
+ - Configurable common classes
1.x:
- Common encodings:
@@ -31,6 +31,7 @@
- Recoding options:
+ Skip Translation
- Switch to Get/Ref/UnRef system
+ - Drop down 'Class' keywords in all 'ClassCharset' function. Make it default behaviour.
on request:
- Multibyte(not-UTF8) support for FS classes
diff --git a/docs/api/Doxyfile b/docs/api/Doxyfile
index 8f0ab9c..c5208e0 100644
--- a/docs/api/Doxyfile
+++ b/docs/api/Doxyfile
@@ -63,7 +63,9 @@ INPUT = /root/xmms/librcc--main--0.1--patch-9/src/ \
/root/xmms/librcc--main--0.1--patch-9/examples/
FILE_PATTERNS = librcc.h \
librccui.h \
- example.c
+ example1.c \
+ example2.c \
+ rcc-gtk-config.c
RECURSIVE = NO
EXCLUDE =
EXCLUDE_SYMLINKS = NO
diff --git a/engines/Makefile.am b/engines/Makefile.am
index 678fc8b..2b7bb26 100644
--- a/engines/Makefile.am
+++ b/engines/Makefile.am
@@ -4,8 +4,8 @@ libdir = $(pkgdatadir)/engines
if HAVE_RCD
lib_LTLIBRARIES += librcd.la
-librussian_la_SOURCES = librcd.c
-librussian_la_LDFLAGS = -module -avoid-version -export-symbols-regex "rccGetInfo"
+librcd_la_SOURCES = librcd.c
+librcd_la_LDFLAGS = -module -avoid-version -export-symbols-regex "rccGetInfo"
endif
libwestern_la_SOURCES = western.c
diff --git a/examples/rcc-gtk-config.c b/examples/rcc-gtk-config.c
index b055597..9a3f988 100644
--- a/examples/rcc-gtk-config.c
+++ b/examples/rcc-gtk-config.c
@@ -7,6 +7,7 @@
static rcc_class classes[] = {
{ "id3", RCC_CLASS_STANDARD, NULL, NULL, "ID3 Encoding", 0 },
+ { "id3v2", RCC_CLASS_STANDARD, "id3", NULL, "ID3 v.2 Encoding", 0},
{ "pl", RCC_CLASS_STANDARD, "id3", NULL, "PlayList Title Encoding", 0},
{ "plfs", RCC_CLASS_STANDARD, "pl", NULL, "PlayList File Encoding", 0 },
{ "fs", RCC_CLASS_FS, "LC_CTYPE", NULL, "FileSystem Encoding", 0 },
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;
}
diff --git a/ui/gtk.c b/ui/gtk.c
index 7de5406..5b728bd 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -83,19 +83,21 @@ static void rccGtkMenuLanguageCB(GtkWidget * w, gpointer item) {
int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
unsigned int i;
+ unsigned long num;
rcc_context rccctx;
rcc_ui_context uictx;
rcc_language_config config;
- rcc_language_ptr *languages;
rcc_language_id language_id;
- rcc_charset *charsets;
- rcc_engine_ptr *engines;
-
+ rcc_class_id class_id;
rcc_charset_id charset_id;
rcc_engine_id engine_id;
+
+ const char *language;
+ const char *charset;
+ const char *engine;
rcc_option_range *range;
rcc_option_name *option_name;
@@ -111,12 +113,14 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
switch (ctx->type) {
case RCC_UI_MENU_LANGUAGE:
- languages=rccGetLanguageList(rccctx);
- if (!languages) return -1;
+ num = rccGetLanguageNumber(rccctx);
list = gtk_menu_new();
- for (i=0; languages[i]; i++) {
- item = gtk_menu_item_new_with_label(rccUiGetLanguageName(uictx, languages[i]->sn));
+ for (i=0; i<(num?num:1); i++) {
+ language = rccUiGetLanguageName(uictx, (rcc_language_id)i);
+ if (!language) continue;
+
+ item = gtk_menu_item_new_with_label(language);
gtk_widget_show(item);
gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(rccGtkMenuLanguageCB), ctx);
gtk_menu_append(GTK_MENU(list), item);
@@ -135,15 +139,21 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
gtk_option_menu_set_history(GTK_OPTION_MENU(menu), language_id);
break;
case RCC_UI_MENU_CHARSET:
-
language_id = (rcc_language_id)rccUiMenuGet(uictx->language);
- charsets = rccGetCharsetList(rccctx, language_id);
- if (!charsets) return -1;
+ class_id = rccUiMenuGetClassId(ctx);
+ config = rccGetConfig(rccctx, language_id);
+ num = rccConfigGetClassCharsetNumber(config, class_id);
list = gtk_menu_new();
- for (i=0;charsets[i];i++) {
- item = gtk_menu_item_new_with_label(rccUiGetCharsetName(uictx,charsets[i]));
- gtk_widget_show(item);
+ for (i=0;i<(num?num:1);i++) {
+ charset = rccUiGetCharsetName(uictx, language_id, class_id, (rcc_charset_id)i);
+ if (!charset) continue;
+
+ item = gtk_menu_item_new_with_label(charset);
+ if (rccIsDisabledCharsetName(rccctx, class_id, charset))
+ gtk_widget_set_sensitive(item, 0);
+ else
+ gtk_widget_show(item);
gtk_menu_append(GTK_MENU(list), item);
}
@@ -156,20 +166,22 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
gtk_option_menu_remove_menu(GTK_OPTION_MENU(menu));
gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list);
- config = rccGetConfig(rccctx, language_id);
- charset_id = rccConfigGetSelectedCharset(config, rccUiMenuGetClassId(ctx));
+ charset_id = rccConfigGetSelectedCharset(config, class_id);
if (charset_id == (rcc_charset_id)-1) charset_id = 0;
gtk_option_menu_set_history(GTK_OPTION_MENU(menu), charset_id);
break;
case RCC_UI_MENU_ENGINE:
language_id = (rcc_language_id)rccUiMenuGet(uictx->language);
- engines = rccGetEngineList(rccctx, language_id);
- if (!engines) return -1;
-
+ config = rccGetConfig(rccctx, language_id);
+ num = rccConfigGetEngineNumber(config);
+
list = gtk_menu_new();
- for (i=0;engines[i];i++) {
- item = gtk_menu_item_new_with_label(rccUiGetEngineName(uictx,engines[i]->title));
+ for (i=0;i<(num?num:1);i++) {
+ engine = rccUiGetEngineName(uictx, language_id, (rcc_engine_id)i);
+ if (!engine) continue;
+
+ item = gtk_menu_item_new_with_label(engine);
gtk_widget_show(item);
gtk_menu_append(GTK_MENU(list), item);
}
@@ -182,7 +194,6 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
gtk_option_menu_remove_menu(GTK_OPTION_MENU(menu));
gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list);
- config = rccGetConfig(rccctx, language_id);
engine_id = rccConfigGetCurrentEngine(config);
if (engine_id == (rcc_engine_id)-1) engine_id = 0;
gtk_option_menu_set_history(GTK_OPTION_MENU(menu), engine_id);
diff --git a/ui/internal.h b/ui/internal.h
index e814a9f..49a932f 100644
--- a/ui/internal.h
+++ b/ui/internal.h
@@ -35,7 +35,8 @@ typedef void *rcc_ui_internal;
struct rcc_ui_context_t {
rcc_context rccctx;
-
+
+ int n_classes;
rcc_ui_menu_context language;
rcc_ui_menu_context engine;
rcc_ui_menu_context *charsets;
diff --git a/ui/librccui.c b/ui/librccui.c
index c38cb58..17e7281 100644
--- a/ui/librccui.c
+++ b/ui/librccui.c
@@ -426,9 +426,8 @@ static void rccUiFrameFreeContext(rcc_ui_frame_context ctx) {
rcc_ui_context rccUiCreateContext(rcc_context rccctx) {
int err = 0;
- unsigned int i;
+ unsigned int i, n_classes;
- rcc_class_ptr *classes;
rcc_ui_context ctx;
rcc_ui_menu_context *charsets;
rcc_ui_menu_context *options;
@@ -440,11 +439,10 @@ rcc_ui_context rccUiCreateContext(rcc_context rccctx) {
err = rccLockConfiguration(rccctx, RCC_UI_LOCK_CODE);
if (err) return NULL;
- classes = rccGetClassList(rccctx);
- for (i=0; classes[i]; i++);
+ n_classes = rccGetClassNumber(rccctx);
ctx = (rcc_ui_context)malloc(sizeof(struct rcc_ui_context_t));
- charsets = (rcc_ui_menu_context*)malloc((i+1)*sizeof(rcc_ui_menu_context));
+ charsets = (rcc_ui_menu_context*)malloc((n_classes+1)*sizeof(rcc_ui_menu_context));
options = (rcc_ui_menu_context*)malloc((RCC_MAX_OPTIONS)*sizeof(rcc_ui_menu_context));
if ((!ctx)||(!charsets)) {
if (ctx) free(ctx);
@@ -453,6 +451,8 @@ rcc_ui_context rccUiCreateContext(rcc_context rccctx) {
return NULL;
}
+ ctx->n_classes = n_classes;
+
ctx->options = options;
ctx->charsets = charsets;
ctx->rccctx = rccctx;
@@ -467,7 +467,7 @@ rcc_ui_context rccUiCreateContext(rcc_context rccctx) {
ctx->language = rccUiMenuCreateContext(RCC_UI_MENU_LANGUAGE, ctx);
ctx->engine = rccUiMenuCreateContext(RCC_UI_MENU_ENGINE, ctx);
- for (i=0; classes[i]; i++) {
+ for (i=0; i<n_classes; i++) {
charsets[i] = rccUiCharsetMenuCreateContext(RCC_UI_MENU_CHARSET, (rcc_charset_id)i, ctx);
if (!charsets[i]) err = 1;
}
@@ -495,7 +495,6 @@ rcc_ui_context rccUiCreateContext(rcc_context rccctx) {
void rccUiFreeContext(rcc_ui_context ctx) {
unsigned int i;
- rcc_class_ptr *classes;
if (!ctx) return;
@@ -506,8 +505,7 @@ void rccUiFreeContext(rcc_ui_context ctx) {
if (ctx->language_frame) rccUiFrameFreeContext(ctx->language_frame);
if (ctx->charsets) {
- classes = rccGetClassList(ctx->rccctx);
- for (i=0; classes[i]; i++)
+ for (i=0; i<ctx->n_classes; i++)
if (ctx->charsets[i]) rccUiMenuFreeContext(ctx->charsets[i]);
free(ctx->charsets);
}
@@ -585,19 +583,20 @@ int rccUiSetClassNames(rcc_ui_context ctx) {
int rccUiRestoreLanguage(rcc_ui_context ctx) {
unsigned int i;
- rcc_class_ptr *classes;
+ rcc_context rccctx;
rcc_language_id language_id;
if (!ctx) return -1;
+ rccctx = ctx->rccctx;
+
language_id = (rcc_language_id)rccUiMenuGet(ctx->language);
rccUiMenuConfigureWidget(ctx->engine);
//rccUiMenuSet(ctx->engine, (rcc_ui_id)rccConfigGetSelectedEngine(config));
- classes = rccGetClassList(ctx->rccctx);
- for (i=0;classes[i];i++)
- if (classes[i]->fullname) {
+ for (i=0;i<ctx->n_classes;i++)
+ if (rccUiGetClassName(ctx, (rcc_class_id)i)) {
rccUiMenuConfigureWidget(ctx->charsets[i]);
// rccUiMenuSet(ctx->charsets[i], rccConfigGetSelectedCharset(config, (rcc_class_id)i));
}
@@ -629,7 +628,6 @@ int rccUiRestore(rcc_ui_context ctx) {
int rccUiUpdate(rcc_ui_context ctx) {
unsigned int i;
- rcc_class_ptr *classes;
rcc_context rccctx;
if (!ctx) return -1;
@@ -645,9 +643,8 @@ int rccUiUpdate(rcc_ui_context ctx) {
rccSetEngine(rccctx, (rcc_language_id)rccUiMenuGet(ctx->engine));
- classes = rccGetClassList(rccctx);
- for (i=0;classes[i];i++)
- if (classes[i]->fullname)
+ for (i=0;i<ctx->n_classes;i++)
+ if (rccUiGetClassName(ctx, (rcc_class_id)i))
rccSetCharset(rccctx, (rcc_class_id)i, rccUiMenuGet(ctx->charsets[i]));
return 0;
@@ -663,14 +660,9 @@ rcc_ui_widget rccUiGetLanguageMenu(rcc_ui_context ctx) {
}
rcc_ui_widget rccUiGetCharsetMenu(rcc_ui_context ctx, rcc_class_id id) {
- rcc_class_ptr *classes;
- unsigned int i;
-
if ((!ctx)||(id<0)) return NULL;
- classes = rccGetClassList(ctx->rccctx);
- for (i=0;classes[i];i++);
- if (id>=i) return NULL;
+ if (id>=ctx->n_classes) return NULL;
if (rccUiMenuConfigureWidget(ctx->charsets[id])) return NULL;
return ctx->charsets[id]->widget;
@@ -707,15 +699,11 @@ rcc_ui_box rccUiGetLanguageBox(rcc_ui_context ctx, const char *title) {
}
rcc_ui_box rccUiGetCharsetBox(rcc_ui_context ctx, rcc_class_id id, const char *title) {
- unsigned int i;
- rcc_class_ptr *classes;
rcc_ui_widget charset;
if (!ctx) return NULL;
- classes = rccGetClassList(ctx->rccctx);
- for (i=0; classes[i]; i++);
- if (id>=i) return NULL;
+ if (id>=ctx->n_classes) return NULL;
if (ctx->charsets[id]->box) return ctx->charsets[id]->box;
@@ -781,12 +769,14 @@ rcc_ui_frame rccUiGetLanguageFrame(rcc_ui_context ctx, rcc_ui_language_frame_nam
rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, rcc_ui_charset_frame_name *name) {
unsigned int i;
const char *class_name;
- rcc_class_ptr *classes;
+ rcc_context rccctx;
rcc_ui_frame_context framectx;
rcc_ui_frame frame;
rcc_ui_box charset;
if (!ctx) return NULL;
+
+ rccctx = ctx->rccctx;
framectx = ctx->charset_frame;
if (framectx->frame) return framectx->frame;
@@ -797,11 +787,9 @@ rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, rcc_ui_charset_frame_name
if (frame) framectx->frame = frame;
else return NULL;
- classes = rccGetClassList(ctx->rccctx);
- for (i=0; classes[i]; i++) {
- if (classes[i]->fullname) {
- class_name = rccUiGetClassName(ctx, classes[i]->name);
- if (!class_name) class_name = classes[i]->fullname;
+ for (i=0; i<ctx->n_classes; i++) {
+ class_name = rccUiGetClassName(ctx, (rcc_class_id)i);
+ if (class_name) {
charset = rccUiGetCharsetBox(ctx, (rcc_class_id)i, class_name);
rccUiFrameAdd(framectx, charset);
}
diff --git a/ui/librccui.h b/ui/librccui.h
index 6ae36d7..b0a4cef 100644
--- a/ui/librccui.h
+++ b/ui/librccui.h
@@ -62,10 +62,10 @@ typedef struct rcc_ui_page_name_t rcc_ui_page_name;
rcc_ui_page_name *rccUiGetDefaultPageName();
-const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang);
-const char *rccUiGetCharsetName(rcc_ui_context ctx, const char *charset);
-const char *rccUiGetEngineName(rcc_ui_context ctx, const char *engine);
-const char *rccUiGetClassName(rcc_ui_context ctx, const char *cl);
+const char *rccUiGetLanguageName(rcc_ui_context ctx, rcc_language_id language_id);
+const char *rccUiGetClassName(rcc_ui_context ctx, rcc_class_id class_id);
+const char *rccUiGetCharsetName(rcc_ui_context ctx, rcc_language_id language_id, rcc_class_id class_id, rcc_charset_id charset_id);
+const char *rccUiGetEngineName(rcc_ui_context ctx, rcc_language_id language_id, rcc_engine_id engine_id);
const char *rccUiGetOptionName(rcc_ui_context ctx, rcc_option option);
const char *rccUiGetOptionValueName(rcc_ui_context ctx, rcc_option option, rcc_option_value value);
diff --git a/ui/rccnames.c b/ui/rccnames.c
index 8b5b4a0..d3d54d7 100644
--- a/ui/rccnames.c
+++ b/ui/rccnames.c
@@ -113,9 +113,12 @@ rcc_name *rccUiGetLanguageRccName(rcc_ui_context ctx, const char *lang) {
return rccUiGetRccName(ctx, lang, RCC_NAME_TYPE_LANGUAGE);
}
-const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang) {
+const char *rccUiGetLanguageName(rcc_ui_context ctx, rcc_language_id language_id) {
+ const char *lang;
rcc_name *names;
+ lang = rccGetLanguageName(ctx->rccctx, language_id);
+
names = rccUiGetLanguageRccName(ctx, lang);
if ((names)&&(names->name)) return names->name;
@@ -126,8 +129,13 @@ rcc_name *rccUiGetCharsetRccName(rcc_ui_context ctx, const char *charset) {
return rccUiGetRccName(ctx, charset, RCC_NAME_TYPE_CHARSET);
}
-const char *rccUiGetCharsetName(rcc_ui_context ctx, const char *charset) {
+const char *rccUiGetCharsetName(rcc_ui_context ctx, rcc_language_id language_id, rcc_class_id class_id, rcc_charset_id charset_id) {
+ rcc_language_config config;
+ const char *charset;
rcc_name *names;
+
+ config = rccGetConfig(ctx->rccctx, language_id);
+ charset = rccConfigGetClassCharsetName(config, class_id, charset_id);
names = rccUiGetCharsetRccName(ctx, charset);
if ((names)&&(names->name)) return names->name;
@@ -139,9 +147,14 @@ rcc_name *rccUiGetEngineRccName(rcc_ui_context ctx, const char *engine) {
return rccUiGetRccName(ctx, engine, RCC_NAME_TYPE_ENGINE);
}
-const char *rccUiGetEngineName(rcc_ui_context ctx, const char *engine) {
+const char *rccUiGetEngineName(rcc_ui_context ctx, rcc_language_id language_id, rcc_engine_id engine_id) {
+ rcc_language_config config;
+ const char *engine;
rcc_name *names;
+ config = rccGetConfig(ctx->rccctx, language_id);
+ engine = rccConfigGetEngineName(config, engine_id);
+
names = rccUiGetEngineRccName(ctx, engine);
if ((names)&&(names->name)) return names->name;
@@ -152,13 +165,16 @@ rcc_name *rccUiGetClassRccName(rcc_ui_context ctx, const char *cl) {
return rccUiGetRccName(ctx, cl, RCC_NAME_TYPE_CLASS);
}
-const char *rccUiGetClassName(rcc_ui_context ctx, const char *cl) {
+const char *rccUiGetClassName(rcc_ui_context ctx, rcc_class_id class_id) {
+ const char *cl;
rcc_name *names;
+ cl = rccGetClassName(ctx->rccctx, class_id);
+
names = rccUiGetClassRccName(ctx, cl);
if ((names)&&(names->name)) return names->name;
- return NULL;
+ return rccGetClassFullName(ctx->rccctx, (rcc_class_id)class_id);
}