summaryrefslogtreecommitdiffstats
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
parent97e76f4c979d7a0c4ed296c512c3024e3c6afa18 (diff)
downloadlibrcc-a21deef1c62467b21500f94dfb2ab3d58e69cb85.tar.gz
librcc-a21deef1c62467b21500f94dfb2ab3d58e69cb85.tar.bz2
librcc-a21deef1c62467b21500f94dfb2ab3d58e69cb85.tar.xz
librcc-a21deef1c62467b21500f94dfb2ab3d58e69cb85.zip
04.07.2005
-rw-r--r--configure.in18
-rw-r--r--librcc.spec.in25
-rw-r--r--src/Makefile.am1
-rw-r--r--src/fs.c1
-rw-r--r--src/internal.h2
-rw-r--r--src/librcc.c56
-rw-r--r--src/librcc.h14
-rw-r--r--src/lng.c2
-rw-r--r--src/lngconfig.c4
-rw-r--r--src/lngconfig.h4
-rw-r--r--src/opt.c4
-rw-r--r--src/rccconfig.c4
-rw-r--r--src/rccenca.c7
-rw-r--r--src/rcciconv.c72
-rw-r--r--src/rcciconv.h6
-rw-r--r--src/rcclist.c6
-rw-r--r--src/rcclocale.c34
-rw-r--r--src/rccstring.c2
-rw-r--r--src/rccstring.h9
-rw-r--r--src/recode.c77
-rw-r--r--src/xml.c4
-rw-r--r--ui/gtk.c43
-rw-r--r--ui/internal.h2
-rw-r--r--ui/librccui.c77
-rw-r--r--ui/rccnames.c2
25 files changed, 320 insertions, 156 deletions
diff --git a/configure.in b/configure.in
index 4cf04d4..ae98654 100644
--- a/configure.in
+++ b/configure.in
@@ -16,6 +16,17 @@ AC_SUBST(LIBRCC_VERSION_MINOR)
AC_SUBST(LIBRCC_VERSION_SUBMINOR)
AC_SUBST(LIBRCC_VERSION_INFO)
+LIBRCC_CVS=`cat VERSION | sed -e s/.*CVS.*/CVS/`
+if test "x$LIBRCC_CVS" = "x"; then
+LIBRCC_CVS=0
+LIBRCC_CVS_DATE=0
+else
+LIBRCC_CVS=1
+LIBRCC_CVS_DATE=`date +%y%m%d.%H`
+fi
+AC_SUBST(LIBRCC_CVS)
+AC_SUBST(LIBRCC_CVS_DATE)
+
AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
AC_PROG_CC
@@ -32,6 +43,11 @@ dnl Checks for header files.
AC_CHECK_HEADERS(iconv.h,, [AC_MSG_ERROR(Missing iconv header)])
AC_CHECK_HEADERS(mntent.h)
+AC_TRY_COMPILE([#include <langinfo.h>],
+ [char *codeset = nl_langinfo (CODESET);],
+ [AC_DEFINE(HAVE_CODESET,,[Define if nl_langinfo(CODESET) is available.])]
+)
+
dnl Checks for libraries.
AC_PATH_PROG(XML2_CONFIG, xml2-config, no)
@@ -82,4 +98,4 @@ AC_C_CONST
dnl Checks for library functions.
AC_CHECK_FUNCS(strcasecmp strncasecmp strdup)
-AC_OUTPUT(src/Makefile ui/Makefile examples/Makefile librcc.spec)
+AC_OUTPUT(src/Makefile ui/Makefile examples/Makefile Makefile librcc.spec)
diff --git a/librcc.spec.in b/librcc.spec.in
index 718106c..998b8ca 100644
--- a/librcc.spec.in
+++ b/librcc.spec.in
@@ -1,13 +1,25 @@
+%define realrelease 1
+%define cvs @LIBRCC_CVS@
+
+%if %cvs
+%define buildname @LIBRCC_CVS_DATE@
+%define release 0.%{buildname}.%{realrelease}csa
+%else
+%define buildname @VERSION@
+%define release %{realrelease}
+%endif
+
+
Summary: Russian Charset Conversion Library
Name: librcc
Version: @VERSION@
-Release: csa
+Release: %{release}
License: GPL
Group: Development/Libraries
Vendor: DarkSoft <ds7fff@myrealbox.com>
Distribution: DarkLin <ds7fff@myrealbox.com>
Packager: Suren A. Chilingaryan <ds7fff@myrealbox.com>
-Source: librcc-%{version}.tar.bz2
+Source: librcc-%{buildname}.tar.bz2
BuildRoot: %{_tmppath}/%{name}-%{version}-root
URL: http://rusxmms.sourceforge.net
Prefix: %{_prefix}
@@ -23,7 +35,8 @@ is part of rusxmms patch.
%package devel
Summary: Russian Encoding Conversion Library
Group: Development/Libraries
-Requires: librcd = %{version}
+Requires: librcc = %{version}
+Requires: librcd
%description devel
Provides posibility to automaticaly convert considered encodings (a lot of
@@ -31,13 +44,14 @@ languages is supported, not only russian one) to/from UTF-8. The library
is part of rusxmms patch.
%prep
-%setup -q
+%setup -q -n %{name}-%{buildname}
%build
%configure
%install
%makeinstall prefix=$RPM_BUILD_ROOT%{prefix}
+rm -f $RPM_BUILD_ROOT%{prefix}/lib/*.la
%clean
rm -rf $RPM_BUILD_ROOT
@@ -48,12 +62,11 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(-, root, root)
-#%doc AUTHORS ChangeLog NEWS README Copyright
+%doc AUTHORS ChangeLog NEWS README COPYING
%{prefix}/lib/lib*.so.*
%files devel
%defattr(-, root, root)
-%doc example
%{prefix}/include/
%{prefix}/lib/lib*.so
%{prefix}/lib/*.a
diff --git a/src/Makefile.am b/src/Makefile.am
index 72cf0ec..b45d4b1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,7 @@ librcc_la_SOURCES = librcc.c \
engine.c engine.h \
rccstring.c rccstring.h \
xml.c xml.h \
+ rcciconv.c rcciconv.h \
fs.c fs.h \
recode.c recode.h \
internal.h
diff --git a/src/fs.c b/src/fs.c
index d4323e6..5064b6f 100644
--- a/src/fs.c
+++ b/src/fs.c
@@ -7,6 +7,7 @@
#include <mntent.h>
#include "internal.h"
+#include "rcciconv.h"
#ifndef strndup
static char *rccStrndup(const char *str, size_t n) {
diff --git a/src/internal.h b/src/internal.h
index c943384..24e9cc8 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -7,6 +7,8 @@
#include "engine.h"
#include "lngconfig.h"
+#define STRNLEN(str,n) (n?strnlen(str,n):strlen(str))
+
struct rcc_context_t {
char locale_variable[RCC_MAX_VARIABLE_CHARS+1];
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;
}
diff --git a/src/librcc.h b/src/librcc.h
index 2e06911..6e40130 100644
--- a/src/librcc.h
+++ b/src/librcc.h
@@ -31,6 +31,7 @@ typedef int rcc_class_id;
typedef struct rcc_context_t *rcc_context;
typedef struct rcc_engine_context_t *rcc_engine_context;
typedef struct rcc_language_config_t *rcc_language_config;
+typedef const struct rcc_class_t *rcc_class_ptr;
#ifdef __cplusplus
extern "C" {
@@ -43,8 +44,8 @@ void rccFree();
**************************** Initialization ************************************
*******************************************************************************/
typedef unsigned int rcc_init_flags;
-#define RCC_DEFAULT_CONFIGURATION 1
-rcc_context rccCreateContext(rcc_init_flags flags, unsigned int max_languages, unsigned int max_classes, const char *locale);
+#define RCC_NO_DEFAULT_CONFIGURATION 1
+rcc_context rccCreateContext(const char *locale_variable, unsigned int max_languages, unsigned int max_classes, rcc_class_ptr classes, rcc_init_flags flags);
void rccFreeContext(rcc_context ctx);
int rccLockConfiguration(rcc_context ctx, unsigned int lock_code);
@@ -112,7 +113,6 @@ typedef enum rcc_class_type_t {
RCC_CLASS_KNOWN,
RCC_CLASS_FS
} rcc_class_type;
-typedef const struct rcc_class_t rcc_class;
struct rcc_class_t {
const char *name;
@@ -120,7 +120,7 @@ struct rcc_class_t {
const rcc_class_type class_type;
const char *fullname;
};
-typedef rcc_class *rcc_class_ptr;
+typedef const struct rcc_class_t rcc_class;
typedef rcc_class_ptr rcc_class_list[RCC_MAX_CLASSES+1];
rcc_class_id rccRegisterClass(rcc_context ctx, rcc_class *cl);
@@ -161,8 +161,6 @@ rcc_option_value rccGetOption(rcc_context ctx, rcc_option option);
int rccSetOption(rcc_context ctx, rcc_option option, rcc_option_value value);
/* lngconfig.c */
-int rccConfigInit(rcc_language_config config, rcc_context ctx);
-int rccConfigFree(rcc_language_config config);
const char *rccConfigGetEngineName(rcc_language_config config, rcc_engine_id engine_id);
const char *rccConfigGetCharsetName(rcc_language_config config, rcc_charset_id charset_id);
@@ -260,8 +258,8 @@ char *rccFS(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *fsp
*******************************************************************************/
/* xml.c */
-int rccSave(rcc_context ctx);
-int rccLoad(rcc_context ctx);
+int rccSave(rcc_context ctx, const char *name);
+int rccLoad(rcc_context ctx, const char *name);
#ifdef __cplusplus
}
diff --git a/src/lng.c b/src/lng.c
index a365615..3937cd7 100644
--- a/src/lng.c
+++ b/src/lng.c
@@ -48,6 +48,7 @@ static rcc_language_id rccGetDefaultLanguage(rcc_context ctx) {
}
rcc_language_id rccGetRealLanguage(rcc_context ctx, rcc_language_id language_id) {
+ printf("CRL: %i\n", language_id);
if ((!ctx)||(language_id<0)||(language_id>=ctx->n_languages)) return -1;
if (language_id) return language_id;
return rccGetDefaultLanguage(ctx);
@@ -76,6 +77,7 @@ const char *rccGetSelectedLanguageName(rcc_context ctx) {
rcc_language_id rccGetCurrentLanguage(rcc_context ctx) {
if (!ctx) return -1;
+ printf("CL: %i\n", ctx->current_language);
return rccGetRealLanguage(ctx, ctx->current_language);
}
diff --git a/src/lngconfig.c b/src/lngconfig.c
index 5de0fae..ad87189 100644
--- a/src/lngconfig.c
+++ b/src/lngconfig.c
@@ -134,7 +134,7 @@ rcc_language_config rccGetConfig(rcc_context ctx, rcc_language_id language_id) {
language_id = rccGetRealLanguage(ctx, language_id);
if (language_id < 0) return NULL;
if (!ctx->configs[language_id].charset) {
- if (rccInitConfig(ctx->configs+language_id, ctx)) return NULL;
+ if (rccConfigInit(ctx->configs+language_id, ctx)) return NULL;
}
ctx->configs[language_id].language = ctx->languages[language_id];
@@ -343,6 +343,8 @@ rcc_charset_id rccConfigGetLocaleCharset(rcc_language_config config, const char
}
/*
+ rcc_option_value options[RCC_MAX_OPTIONS];
+
int rccConfigInit(rcc_language_config config, rcc_context ctx) {
for (i=0;i<RCC_MAX_OPTIONS;i++)
config->options[i] = 0;
diff --git a/src/lngconfig.h b/src/lngconfig.h
index ced4784..4e9681c 100644
--- a/src/lngconfig.h
+++ b/src/lngconfig.h
@@ -7,10 +7,12 @@ struct rcc_language_config_t {
rcc_engine_id engine;
rcc_charset_id *charset;
- rcc_option_value options[RCC_MAX_OPTIONS];
};
typedef struct rcc_language_config_t rcc_language_config_s;
rcc_engine_ptr rccConfigGetEnginePointer(rcc_language_config config, rcc_engine_id engine_id);
+int rccConfigInit(rcc_language_config config, rcc_context ctx);
+int rccConfigFree(rcc_language_config config);
+
#endif /* _RCC_LNGCONFIG_H */
diff --git a/src/opt.c b/src/opt.c
index ec4684f..85960df 100644
--- a/src/opt.c
+++ b/src/opt.c
@@ -3,13 +3,13 @@
#include "internal.h"
#include "opt.h"
-rcc_option_value rccConfigGetOption(rcc_context ctx, rcc_option option) {
+rcc_option_value rccGetOption(rcc_context ctx, rcc_option option) {
if ((!ctx)||(option<0)||(option>=RCC_MAX_OPTIONS)) return -1;
return ctx->options[option];
}
-int rccConfigSetOption(rcc_context ctx, rcc_option option, rcc_option_value value) {
+int rccSetOption(rcc_context ctx, rcc_option option, rcc_option_value value) {
if ((!ctx)||(option>=RCC_MAX_OPTIONS)) return -1;
if (ctx->options[option] != value) {
diff --git a/src/rccconfig.c b/src/rccconfig.c
index c77b27a..6d0a372 100644
--- a/src/rccconfig.c
+++ b/src/rccconfig.c
@@ -34,13 +34,13 @@ rcc_language rcc_default_languages[] = {
NULL
}},
{"ru", {"Default","KOI8-R","CP1251","UTF-8","IBM866","MACCYRILLIC","ISO8859-5", NULL}, {
- &rcc_russian_engine,
&rcc_default_engine,
+ &rcc_russian_engine,
NULL
}},
{"uk", {"Default","KOI8-U","CP1251","UTF-8","IBM855","MACCYRILLIC","ISO8859-5","CP1125", NULL}, {
- &rcc_russian_engine,
&rcc_default_engine,
+ &rcc_russian_engine,
NULL
}},
{"be", {"Default", "UTF-8", "CP1251", "IBM866", "ISO-8859-5", "KOI8-UNI", "maccyr" "IBM855", NULL},{
diff --git a/src/rccenca.c b/src/rccenca.c
index 20e1eb4..1aabf7a 100644
--- a/src/rccenca.c
+++ b/src/rccenca.c
@@ -59,7 +59,7 @@ rcc_charset_id rccEnca(rcc_engine_context ctx, const char *buf, int len) {
if ((!internal)||(!buf)) return -1;
- len = STRLEN(buf, len);
+ len = STRNLEN(buf, len);
ee = enca_analyse_const((EncaAnalyser)ctx->internal,buf,len);
if (ee.charset<0) return -1;
@@ -145,7 +145,10 @@ int rccEncaInit() {
for (j=0;engines[j];j++)
if (j >= RCC_MAX_ENGINES) continue;
- charsets = enca_get_language_charsets(rcc_default_languages[i].sn, &n_charsets);
+ if (strlen(rcc_default_languages[i].sn)==2)
+ charsets = enca_get_language_charsets(rcc_default_languages[i].sn, &n_charsets);
+ else
+ charsets = NULL;
if (charsets) {
memcpy(enca_engines+i, &rcc_enca_engine, sizeof(rcc_engine));
for (k=0;enca_engines[i].charsets[k];k++);
diff --git a/src/rcciconv.c b/src/rcciconv.c
new file mode 100644
index 0000000..d309a5f
--- /dev/null
+++ b/src/rcciconv.c
@@ -0,0 +1,72 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <iconv.h>
+
+#include "internal.h"
+#include "rcciconv.h"
+
+static void rccIConvCopySymbol(char **in_buf, int *in_left, char **out_buf, int *out_left) {
+ if ((out_left>0)&&(in_left>0)) {
+ (**out_buf)=(**in_buf);
+ (*out_buf)++;
+ (*in_buf)++;
+ (*in_left)--;
+ (*out_left)--;
+ }
+}
+
+static int rccIConvUTFBytes(unsigned char c) {
+ int j;
+ if (c<128) return 1;
+
+ for (j=6;j>=0;j--)
+ if ((c&(1<<j))==0) break;
+
+ if ((j==0)||(j==6)) return 1;
+ return 6-j;
+}
+
+int rccIConv(rcc_context ctx, iconv_t icnv, const char *buf, int len) {
+ char *in_buf, *out_buf, *res, err;
+ int in_left, out_left, olen;
+ int ub, utf_mode=0;
+ int errors=0;
+
+ if ((!buf)||(!ctx)||(icnv == (iconv_t)-1)) return -1;
+
+ len = STRNLEN(buf,len);
+
+ if (iconv(icnv, NULL, NULL, NULL, NULL) == -1) return -1;
+
+loop_restart:
+ errors = 0;
+ in_buf = (char*)buf; /*DS*/
+ in_left = len;
+ out_buf = ctx->tmpbuffer;
+ out_left = RCC_MAX_STRING_CHARS;
+
+loop:
+ err=iconv(icnv, &in_buf, &in_left, &out_buf, &out_left);
+ if (err<0) {
+ if (errno==E2BIG) {
+ *(int*)(ctx->tmpbuffer+(RCC_MAX_STRING_CHARS-sizeof(int)))=0;
+ } else if (errno==EILSEQ) {
+ if (errors++<RCC_MAX_ERRORS) {
+ for (ub=utf_mode?rccIConvUTFBytes(*in_buf):1;ub>0;ub--)
+ rccIConvCopySymbol(&in_buf, &in_left, &out_buf, &out_left);
+ if (in_left>0) goto loop;
+ } else if (!utf_mode) {
+ utf_mode = 1;
+ goto loop_restart;
+ } else {
+ return -1;
+ }
+ } else {
+ return -1;
+ }
+ }
+
+ return RCC_MAX_STRING_CHARS - out_left;
+}
diff --git a/src/rcciconv.h b/src/rcciconv.h
new file mode 100644
index 0000000..1c899a9
--- /dev/null
+++ b/src/rcciconv.h
@@ -0,0 +1,6 @@
+#ifndef _RCC_ICONV_H
+#define _RCC_ICONV_H
+
+int rccIConv(rcc_context ctx, iconv_t icnv, const char *buf, int len);
+
+#endif /* _RCC_ICONV_H */
diff --git a/src/rcclist.c b/src/rcclist.c
index dc26d7e..522077e 100644
--- a/src/rcclist.c
+++ b/src/rcclist.c
@@ -8,11 +8,17 @@ rcc_language_ptr *rccGetLanguageList(rcc_context ctx) {
rcc_charset *rccGetCharsetList(rcc_context ctx, rcc_language_id language_id) {
if ((!ctx)||(language_id<0)||(language_id>=ctx->n_languages)) return NULL;
+ if (!language_id) language_id = rccGetCurrentLanguage(ctx);
+ printf("=====> LanguageID: %i\n", language_id);
+
return ctx->languages[language_id]->charsets;
}
rcc_engine_ptr *rccGetEngineList(rcc_context ctx, rcc_language_id language_id) {
if ((!ctx)||(language_id<0)||(language_id>=ctx->n_languages)) return NULL;
+ if (!language_id) language_id = rccGetCurrentLanguage(ctx);
+ printf("=====> LanguageID: %i\n", language_id);
+
return ctx->languages[language_id]->engines;
}
diff --git a/src/rcclocale.c b/src/rcclocale.c
index d2ff610..d3efaa6 100644
--- a/src/rcclocale.c
+++ b/src/rcclocale.c
@@ -1,7 +1,12 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <locale.h>
+#ifdef HAVE_CODESET
+# include <langinfo.h>
+#endif
+
#include "rccconfig.h"
static int rccLocaleGetClassByName(const char *locale) {
@@ -22,25 +27,27 @@ static int rccLocaleGetClassByName(const char *locale) {
return -1;
}
-static int rccLocaleGetLanguage(char *result, const char *lv, unsigned int n) {
- unsigned int i;
+int rccLocaleGetLanguage(char *result, const char *lv, unsigned int n) {
+ unsigned int i, j;
int locale_class;
const char *l;
+ printf("Locale: %p\n", lv);
if (!lv) return -1;
locale_class = rccLocaleGetClassByName(lv);
if (locale_class >= 0) {
l = setlocale(locale_class, NULL);
+ puts(l);
if (!l) return -1;
else if ((strcmp(l,"C")==0)||(strcmp(l,"POSIX")==0)) return -1;
- } return -1;
+ } else return -1;
for (i=0;((l[i])&&(l[i]!='.'));i++);
- for (i=0;rcc_default_aliases[i].alias;i++)
- if (strncmp(l,rcc_default_aliases[i].alias,i)==0) {
- l = rcc_default_aliases[i].alias;
+ for (j=0;rcc_default_aliases[j].alias;j++)
+ if (strncmp(l,rcc_default_aliases[j].alias,i)==0) {
+ l = rcc_default_aliases[j].alias;
break;
}
@@ -49,6 +56,8 @@ static int rccLocaleGetLanguage(char *result, const char *lv, unsigned int n) {
strncpy(result,l,i);
result[i]=0;
+ puts("------------------->");
+ puts(result);
return 0;
}
@@ -61,6 +70,19 @@ int rccLocaleGetCharset(char *result, const char *lv, unsigned int n) {
if (!lv) return -1;
locale_class = rccLocaleGetClassByName(lv);
+
+ if (locale_class == LC_CTYPE) {
+ l = getenv("CHARSET");
+#ifdef HAVE_CODESET
+ if (!l) l = nl_langinfo(CODESET);
+#endif
+ if (l) {
+ if (strlen(l)>=n) return -1;
+ strcpy(result, l);
+ return 0;
+ }
+ }
+
if (locale_class >= 0) {
l = setlocale(locale_class, NULL);
if (!l) return -1;
diff --git a/src/rccstring.c b/src/rccstring.c
index e2db6be..e03a22f 100644
--- a/src/rccstring.c
+++ b/src/rccstring.c
@@ -39,7 +39,7 @@ rcc_language_id rccStringCheck(const rcc_string str) {
}
const char *rccStringGet(const rcc_string str) {
- if (rccStringCheck(str)) return str + sizeof(rcc_string_header);
+ if (rccStringCheck(str)) return (const char *)str + sizeof(rcc_string_header);
return (const char *)str;
}
diff --git a/src/rccstring.h b/src/rccstring.h
index eceab96..4f7d411 100644
--- a/src/rccstring.h
+++ b/src/rccstring.h
@@ -4,4 +4,13 @@
rcc_string rccCreateString(rcc_language_id language_id, const char *buf, int len, int *rlen);
void rccStringFree(rcc_string str);
+rcc_language_id rccStringCheck(const rcc_string str);
+const char *rccStringGet(const rcc_string str);
+char *rccStringExtract(const rcc_string buf, int len, int *rlen);
+
+int rccStringCmp(const rcc_string str1, const rcc_string str2);
+int rccStringNCmp(const rcc_string str1, const rcc_string str2, size_t n);
+int rccStringCaseCmp(const rcc_string str1, const rcc_string str2);
+int rccStringNCaseCmp(const rcc_string str1, const rcc_string str2, size_t n);
+
#endif /* _RCC_STRING_H */
diff --git a/src/recode.c b/src/recode.c
index be4d98c..80b59eb 100644
--- a/src/recode.c
+++ b/src/recode.c
@@ -1,80 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <locale.h>
-#include <errno.h>
-#include <iconv.h>
#include "internal.h"
+#include "rcciconv.h"
#include "fs.h"
#include "lng.h"
#include "rccstring.h"
#include "rccconfig.h"
-static void rccIConvCopySymbol(char **in_buf, int *in_left, char **out_buf, int *out_left) {
- if ((out_left>0)&&(in_left>0)) {
- (**out_buf)=(**in_buf);
- (*out_buf)++;
- (*in_buf)++;
- (*in_left)--;
- (*out_left)--;
- }
-}
-
-static int rccIConvUTFBytes(unsigned char c) {
- int j;
- if (c<128) return 1;
-
- for (j=6;j>=0;j--)
- if ((c&bit(j))==0) break;
-
- if ((j==0)||(j==6)) return 1;
- return 6-j;
-}
-
-static int rccIConv(rcc_context ctx, iconv_t icnv, const char *buf, int len) {
- char *in_buf, *out_buf, *res, err;
- int in_left, out_left, olen;
- int ub, utf_mode=0;
- int errors=0;
-
- if ((!buf)||(!ctx)||(icnv == (iconv_t)-1)) return -1;
-
- len = STRNLEN(buf,len);
-
- if (iconv(icnv, NULL, NULL, NULL, NULL) == -1) return -1;
-
-loop_restart:
- errors = 0;
- in_buf = (char*)buf; /*DS*/
- in_left = len;
- out_buf = ctx->tmpbuffer;
- out_left = RCC_MAX_STRING_CHARS;
-
-loop:
- err=iconv(icnv, &in_buf, &in_left, &out_buf, &out_left);
- if (err<0) {
- if (errno==E2BIG) {
- *(int*)(ctx->tmpbuffer+(RCC_MAX_STRING_CHARS-sizeof(int)))=0;
- } else if (errno==EILSEQ) {
- if (errors++<RCC_MAX_ERRORS) {
- for (ub=utf_mode?rccIConvUTFBytes(*in_buf):1;ub>0;ub--)
- rccIConvCopySymbol(&in_buf, &in_left, &out_buf, &out_left);
- if (in_left>0) goto loop;
- } else if (!utf_mode) {
- utf_mode = 1;
- goto loop_restart;
- } else {
- return -1;
- }
- } else {
- return -1;
- }
- }
-
- return RCC_MAX_STRING_CHARS - out_left;
-}
static rcc_charset_id rccIConvAuto(rcc_context ctx, rcc_class_id class_id, const char *buf, int len) {
@@ -86,7 +21,7 @@ static rcc_charset_id rccIConvAuto(rcc_context ctx, rcc_class_id class_id, const
class_type = rccGetClassType(ctx, class_id);
if ((class_type == RCC_CLASS_STANDARD)||((class_type == RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_AUTODETECT_FS_TITLES)))) {
engine = rccGetEnginePointer(ctx, rccGetCurrentEngine(ctx));
- if ((!engine)||(!engine->func)||(!stricmp(engine->title, "off"))||(!strcmp(engine->title, "dissable"))) return -1;
+ if ((!engine)||(!engine->func)||(!strcasecmp(engine->title, "off"))||(!strcasecmp(engine->title, "dissable"))) return -1;
return engine->func(&ctx->engine_ctx, buf, len);
}
@@ -105,6 +40,10 @@ rcc_string rccFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, int
err = rccConfigure(ctx);
if (err) return NULL;
+ // Checking if rcc_string passed
+ language_id = rccStringCheck((const rcc_string)buf);
+ if (language_id) return NULL;
+
language_id = rccGetCurrentLanguage(ctx);
// DS: Learning. check database (language_id)
@@ -139,7 +78,7 @@ char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, int le
if ((!ctx)||(class_id<0)||(class_id>=ctx->n_classes)||(!buf)) return NULL;
- language_id = rccCheckString(ctx, buf);
+ language_id = rccStringCheck(buf);
if (!language_id) return NULL;
err = rccConfigure(ctx);
@@ -189,7 +128,7 @@ char *rccRecode(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char
if (from_charset_id>0) {
from_charset = rccGetAutoCharsetName(ctx, from_charset_id);
to_charset = rccGetCurrentCharsetName(ctx, to);
- if ((from_charset)&&(to_charset)&&(!stricmp(from_charset, to_charset))) return NULL;
+ if ((from_charset)&&(to_charset)&&(!strcasecmp(from_charset, to_charset))) return NULL;
} else {
from_charset_id = rccGetCurrentCharset(ctx, from);
to_charset_id = rccGetCurrentCharset(ctx, to);
diff --git a/src/xml.c b/src/xml.c
index 5026fec..459bccf 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -5,10 +5,10 @@
/* Load and Then Save */
/* flock */
-int rccSave(rcc_context ctx) {
+int rccSave(rcc_context ctx, const char *name) {
return 0;
}
-int rccLoad(rcc_context ctx) {
+int rccLoad(rcc_context ctx, const char *name) {
return 0;
}
diff --git a/ui/gtk.c b/ui/gtk.c
index d299a8e..16b51db 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -3,6 +3,14 @@
#include "internal.h"
#include "rccnames.h"
+#define TITLE_WIDTH 160
+#define TITLE_HEIGHT 10
+#define BOX_SPACING 1
+#define BOX_BORDER 0
+#define FRAME_SPACING 1
+#define FRAME_BORDER 0
+#define PAGE_SPACING 0
+
rcc_ui_internal rccUiCreateInternal(rcc_ui_context ctx) {
return NULL;
}
@@ -14,7 +22,7 @@ rcc_ui_widget rccUiMenuCreateWidget(rcc_ui_menu_context ctx) {
return NULL;
}
-void rccUiMenuDestroyWidget(rcc_ui_menu_context ctx) {
+void rccUiMenuFreeWidget(rcc_ui_menu_context ctx) {
}
rcc_ui_id rccUiMenuGet(rcc_ui_menu_context ctx) {
@@ -24,7 +32,7 @@ rcc_ui_id rccUiMenuGet(rcc_ui_menu_context ctx) {
if (ctx->type == RCC_UI_MENU_OPTION)
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ctx->widget));
-
+
menu = gtk_option_menu_get_menu(ctx->widget);
return g_list_index(GTK_MENU_SHELL(menu)->children, gtk_menu_get_active(GTK_MENU(menu)));
}
@@ -45,6 +53,7 @@ int rccUiMenuSet(rcc_ui_menu_context ctx, rcc_ui_id id) {
static int rccGtkMenuLanguageCB(GtkWidget * w, gpointer item) {
+ puts("LanguageCB!!!!!!!!!!!!!!!!!!!!!!");
rccUiRestoreLanguage(((rcc_ui_menu_context)item)->uictx);
}
@@ -94,20 +103,18 @@ 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);
gtk_option_menu_set_history(GTK_OPTION_MENU(menu), language_id);
-
- return 0;
break;
case RCC_UI_MENU_CHARSET:
-
list = gtk_menu_new();
language_id = (rcc_language_id)rccUiMenuGet(uictx->language);
charsets = rccGetCharsetList(rccctx, language_id);
for (i=0;charsets[i];i++) {
- list = gtk_menu_item_new_with_label(charsets[i]);
+ item = gtk_menu_item_new_with_label(charsets[i]);
gtk_widget_show(item);
gtk_menu_append(GTK_MENU(list), item);
+ puts(charsets[i]);
}
if (ctx->widget) menu = ctx->widget;
@@ -130,9 +137,10 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
language_id = (rcc_language_id)rccUiMenuGet(uictx->language);
engines = rccGetEngineList(rccctx, language_id);
for (i=0;engines[i];i++) {
- list = gtk_menu_item_new_with_label(engines[i]->title);
+ item = gtk_menu_item_new_with_label(engines[i]->title);
gtk_widget_show(item);
gtk_menu_append(GTK_MENU(list), item);
+ puts(engines[i]->title);
}
if (ctx->widget) menu = ctx->widget;
@@ -151,8 +159,11 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
break;
case RCC_UI_MENU_OPTION:
- item = gtk_check_button_new_with_label(rccUiGetOptionName(uictx, (rcc_option)ctx->id));
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(item), rccGetOption(rccctx, (rcc_option)ctx->id));
+ if (!ctx->widget) {
+ item = gtk_check_button_new_with_label(rccUiGetOptionName(uictx, (rcc_option)ctx->id));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(item), rccGetOption(rccctx, (rcc_option)ctx->id));
+ ctx->widget = item;
+ }
break;
}
@@ -162,11 +173,11 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
rcc_ui_box rccUiBoxCreate(rcc_ui_menu_context ctx, const char *title) {
GtkWidget *hbox, *label;
- hbox = gtk_hbox_new(FALSE, 10);
- gtk_container_border_width(GTK_CONTAINER(hbox), 5);
+ hbox = gtk_hbox_new(FALSE, BOX_SPACING);
+ gtk_container_border_width(GTK_CONTAINER(hbox), BOX_BORDER);
if (ctx->type != RCC_UI_MENU_OPTION) {
label = gtk_label_new(title);
- gtk_widget_set_usize(label, 120, 17);
+ gtk_widget_set_usize(label, TITLE_WIDTH, TITLE_HEIGHT);
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
}
gtk_box_pack_start(GTK_BOX(hbox), (GtkWidget*)ctx->widget, TRUE, TRUE, 0);
@@ -176,9 +187,9 @@ rcc_ui_box rccUiBoxCreate(rcc_ui_menu_context ctx, const char *title) {
rcc_ui_frame rccUiFrameCreate(rcc_ui_context ctx, const char *title) {
GtkWidget *frame, *box;
frame = gtk_frame_new(title?title:"");
- gtk_container_border_width(GTK_CONTAINER(frame), 5);
+ gtk_container_border_width(GTK_CONTAINER(frame), FRAME_BORDER);
- box = gtk_vbox_new(FALSE, 3);
+ box = gtk_vbox_new(FALSE, FRAME_SPACING);
gtk_container_add(GTK_CONTAINER(frame), box);
return (rcc_ui_frame)frame;
@@ -187,13 +198,13 @@ rcc_ui_frame rccUiFrameCreate(rcc_ui_context ctx, const char *title) {
int rccUiFrameAdd(rcc_ui_frame frame, rcc_ui_box box) {
GtkWidget *vbox;
- vbox = gtk_container_get_toplevels()->data;
+ vbox = gtk_container_children(GTK_CONTAINER(frame))->data;
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(box), FALSE, FALSE, 0);
return 0;
}
rcc_ui_page rccUiPageCreate(rcc_ui_context ctx, const char *title) {
- return (rcc_ui_page)gtk_vbox_new(FALSE, 0);
+ return (rcc_ui_page)gtk_vbox_new(FALSE, PAGE_SPACING);
}
int rccUiPageAdd(rcc_ui_page page, rcc_ui_frame frame) {
diff --git a/ui/internal.h b/ui/internal.h
index afc0a08..a16c506 100644
--- a/ui/internal.h
+++ b/ui/internal.h
@@ -56,7 +56,7 @@ rcc_ui_internal rccUiCreateInternal(rcc_ui_context ctx);
void rccUiFreeInternal(rcc_ui_context ctx);
rcc_ui_widget rccUiMenuCreateWidget(rcc_ui_menu_context ctx);
-void rccUiMenuDestroyWidget(rcc_ui_menu_context ctx);
+void rccUiMenuFreeWidget(rcc_ui_menu_context ctx);
int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx);
rcc_ui_id rccUiMenuGet(rcc_ui_menu_context ctx);
diff --git a/ui/librccui.c b/ui/librccui.c
index 0700b8b..060ada3 100644
--- a/ui/librccui.c
+++ b/ui/librccui.c
@@ -60,6 +60,7 @@ rcc_ui_context rccUiCreateContext(rcc_context rccctx) {
ctx->engine_frame = NULL;
ctx->page = NULL;
+ ctx->options = options;
ctx->charsets = charsets;
ctx->rccctx = rccctx;
@@ -136,31 +137,44 @@ int rccUiSetOptionNames(rcc_ui_context ctx, rcc_option_name *names) {
int rccUiRestoreLanguage(rcc_ui_context ctx) {
unsigned int i;
rcc_class_ptr *classes;
- rcc_context rccctx;
-
- if (!ctx) return -1;
-
- rccctx = ctx->rccctx;
+ rcc_language_id language_id;
- rccUiMenuSet(ctx->engine, (rcc_ui_id)rccGetSelectedEngine(rccctx));
+ rcc_language_config config;
- for (i=0;i<RCC_MAX_OPTIONS;i++)
- rccUiMenuSet(ctx->options[i], rccGetOption(rccctx, (rcc_option)i));
+ if (!ctx) return -1;
+
+ language_id = (rcc_language_id)rccUiMenuGet(ctx->language);
+ config = rccGetConfig(ctx->rccctx, language_id);
- classes = rccGetClassList(rccctx);
+ rccUiMenuConfigureWidget(ctx->engine);
+ //rccUiMenuSet(ctx->engine, (rcc_ui_id)rccConfigGetSelectedEngine(config));
+
+ classes = rccGetClassList(ctx->rccctx);
for (i=0;classes[i];i++)
- rccUiMenuSet(ctx->charsets[i], rccGetSelectedCharset(rccctx, (rcc_class_id)i));
+ if (classes[i]->fullname) {
+ rccUiMenuConfigureWidget(ctx->charsets[i]);
+// rccUiMenuSet(ctx->charsets[i], rccConfigGetSelectedCharset(config, (rcc_class_id)i));
+ }
+
return 0;
}
int rccUiRestore(rcc_ui_context ctx) {
+ unsigned int i;
+ rcc_context rccctx;
rcc_language_id language_id;
if (!ctx) return -1;
+
+ rccctx = ctx->rccctx;
- language_id = rccGetSelectedLanguage(ctx->rccctx);
+ language_id = rccGetSelectedLanguage(rccctx);
rccUiMenuSet(ctx->language, (rcc_ui_id)language_id);
+
+ for (i=0;i<RCC_MAX_OPTIONS;i++)
+ rccUiMenuSet(ctx->options[i], rccGetOption(rccctx, (rcc_option)i));
+
return 0;
}
@@ -182,7 +196,8 @@ int rccUiUpdate(rcc_ui_context ctx) {
classes = rccGetClassList(rccctx);
for (i=0;classes[i];i++)
- rccSetCharset(rccctx, (rcc_class_id)i, rccUiMenuGet(ctx->charsets[i]));
+ if (classes[i]->fullname)
+ rccSetCharset(rccctx, (rcc_class_id)i, rccUiMenuGet(ctx->charsets[i]));
return 0;
}
@@ -197,17 +212,18 @@ rcc_ui_widget rccUiGetLanguageMenu(rcc_ui_context ctx) {
}
rcc_ui_widget rccUiGetCharsetMenu(rcc_ui_context ctx, rcc_class_id id) {
- rcc_charset *charsets;
+ rcc_class_ptr *classes;
unsigned int i;
if ((!ctx)||(id<0)) return NULL;
- charsets = rccGetCurrentCharsetList(ctx->rccctx);
- for (i=0;charsets[i];i++);
+ classes = rccGetClassList(ctx->rccctx);
+ for (i=0;classes[i];i++);
+ printf("Recalc: %i %i\n", id, i);
if (id>=i) return NULL;
- if (rccUiMenuConfigureWidget(ctx->charsets[i])) return NULL;
- return ctx->charsets[i]->widget;
+ if (rccUiMenuConfigureWidget(ctx->charsets[id])) return NULL;
+ return ctx->charsets[id]->widget;
}
@@ -249,6 +265,7 @@ rcc_ui_box rccUiGetCharsetBox(rcc_ui_context ctx, rcc_class_id id, const char *t
classes = rccGetClassList(ctx->rccctx);
for (i=0; classes[i]; i++);
+ printf("Charset Box: %i %i\n", id, i);
if (id>=i) return NULL;
if (ctx->charsets[id]->box) return ctx->charsets[id]->box;
@@ -256,8 +273,11 @@ rcc_ui_box rccUiGetCharsetBox(rcc_ui_context ctx, rcc_class_id id, const char *t
charset = rccUiGetCharsetMenu(ctx, id);
if (!charset) return NULL;
-
+
+ puts("Charset Box Pre");
+ printf("%p %p\n", ctx->charsets[id], ctx->charsets[id]->widget);
ctx->charsets[id]->box = rccUiBoxCreate(ctx->charsets[id], title);
+ puts("Charset Box Post");
return ctx->charsets[id]->box;
}
@@ -277,13 +297,17 @@ rcc_ui_box rccUiGetEngineBox(rcc_ui_context ctx, const char *title) {
rcc_ui_box rccUiGetOptionBox(rcc_ui_context ctx, rcc_option option, const char *title) {
rcc_ui_widget opt;
+ printf("Option Strt: %i %p\n", option, title);
if ((!ctx)||(option<0)||(option>=RCC_MAX_OPTIONS)) return NULL;
if (ctx->options[option]->box) return ctx->options[option]->box;
+ puts("=== Option Box ===");
opt = rccUiGetOptionMenu(ctx, option);
if (!opt) return NULL;
+ puts("Option Menu");
ctx->options[option]->box = rccUiBoxCreate(ctx->options[option], title);
+ puts("Option Finish");
return ctx->options[option]->box;
}
@@ -324,8 +348,10 @@ rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, const char *title) {
classes = rccGetClassList(ctx->rccctx);
for (i=0; classes[i]; i++) {
- charset = rccUiGetCharsetBox(ctx, (rcc_class_id)i, classes[i]->fullname);
- rccUiFrameAdd(frame, charset);
+ if (classes[i]->fullname) {
+ charset = rccUiGetCharsetBox(ctx, (rcc_class_id)i, classes[i]->fullname);
+ rccUiFrameAdd(frame, charset);
+ }
}
ctx->charset_frame = frame;
@@ -348,9 +374,12 @@ rcc_ui_frame rccUiGetEngineFrame(rcc_ui_context ctx, const char *title) {
if (!frame) return NULL;
engine = rccUiGetEngineBox(ctx, title);
+ puts("Engine");
rccUiFrameAdd(frame, engine);
+ puts("Added");
for (i=0; i<RCC_MAX_OPTIONS; i++) {
+ printf("OptionBox: %u\n", i);
opt = rccUiGetOptionBox(ctx, (rcc_option)i, rccUiGetOptionName(ctx, i));
rccUiFrameAdd(frame, opt);
}
@@ -368,18 +397,22 @@ rcc_ui_page rccUiGetPage(rcc_ui_context ctx, const char *title, const char *lang
if (!ctx) return NULL;
if (ctx->page) return ctx->page;
-
+
page = rccUiPageCreate(ctx, title);
if (!page) return NULL;
-
+
+ puts("P C");
frame = rccUiGetLanguageFrame(ctx, language_title);
rccUiPageAdd(page, frame);
+ puts("L C");
frame = rccUiGetCharsetsFrame(ctx, charset_title);
rccUiPageAdd(page, frame);
+ puts("C C");
frame = rccUiGetEngineFrame(ctx, engine_title);
rccUiPageAdd(page, frame);
+ puts("E C");
ctx->page = page;
diff --git a/ui/rccnames.c b/ui/rccnames.c
index e4f4b48..961dbbc 100644
--- a/ui/rccnames.c
+++ b/ui/rccnames.c
@@ -24,7 +24,7 @@ const char *rccUiGetOptionName(rcc_ui_context ctx, rcc_option option) {
names = ctx->option_names;
- for (i=0;i<RCC_MAX_OPTIONS;i++)
+ for (i=0;((i<RCC_MAX_OPTIONS)&&(names[i].option!=RCC_MAX_OPTIONS));i++)
if (names[i].option == option) return names[i].name;
return NULL;