summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2005-07-18 15:22:28 +0000
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2005-07-18 15:22:28 +0000
commit537c4b33fdf6e143243d5a0d286eeb247362e806 (patch)
treed8a94cfaa4a71ffc826b7d8176c54445369539f3
parent4032f92867e5570f130e4175b3b4fb61240f9752 (diff)
downloadlibrcc-537c4b33fdf6e143243d5a0d286eeb247362e806.tar.gz
librcc-537c4b33fdf6e143243d5a0d286eeb247362e806.tar.bz2
librcc-537c4b33fdf6e143243d5a0d286eeb247362e806.tar.xz
librcc-537c4b33fdf6e143243d5a0d286eeb247362e806.zip
API Improvements
- Removed 'rlen' return parameters there not necessary for multibyte encodings - Two versions of recode functions: rccRecode -> rccRecode, rccSizedRecode - Class Types: CONST, SKIP_SAVELOAD - New recode functions: rccToCharset, rccFromCharset - More new recode functions: rccRecodeToCharset, rccRecodeFromCharset, rccRecodeCharsets - New function: rccGetCompiledConfiguration - All warnings are fixed - Perform "File Name" search only if there are non ISO8859-1 chars in the name. - Do not copy invalid characters, - skip them. - Fixed error in rccRecode with 'Recoding Cache' switched On. - Strip leading and trailing spaces in rccDB4 get/set
-rw-r--r--AUTHORS2
-rw-r--r--ToDo3
-rw-r--r--VERSION2
-rw-r--r--configure.in4
-rw-r--r--engines/russian.c3
-rw-r--r--examples/example.c12
-rw-r--r--src/curconfig.c6
-rw-r--r--src/engine.c14
-rw-r--r--src/engine.h1
-rw-r--r--src/fs.c13
-rw-r--r--src/internal.h9
-rw-r--r--src/librcc.c26
-rw-r--r--src/librcc.h75
-rw-r--r--src/lng.c7
-rw-r--r--src/lngconfig.c46
-rw-r--r--src/opt.c1
-rw-r--r--src/plugin.c5
-rw-r--r--src/plugin.h2
-rw-r--r--src/rccconfig.c1
-rw-r--r--src/rccdb4.c43
-rw-r--r--src/rccenca.c9
-rw-r--r--src/rcciconv.c12
-rw-r--r--src/rcclist.c4
-rw-r--r--src/rcclocale.h3
-rw-r--r--src/rccstring.c42
-rw-r--r--src/rccstring.h11
-rw-r--r--src/rccxml.c11
-rw-r--r--src/recode.c201
-rw-r--r--ui/gtk.c4
-rw-r--r--ui/librccui.c6
-rw-r--r--ui/rccmenu.c1
-rw-r--r--ui/rccnames.c11
32 files changed, 439 insertions, 151 deletions
diff --git a/AUTHORS b/AUTHORS
index f0e3451..067c215 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1 +1 @@
-Suren A. Chilingaryan \ No newline at end of file
+Suren A. Chilingaryan <darksoft@dside.dyndns.org>
diff --git a/ToDo b/ToDo
new file mode 100644
index 0000000..c9da0eb
--- /dev/null
+++ b/ToDo
@@ -0,0 +1,3 @@
+* Provide way to add to all languages several default Unicode encodings (UTF8, UTF16, UTF16BE)
+* Special type of classes to select only from Unicode encodings (or even just specified subset of encodings)
+* Multibyte(not-UTF8) support for FS classes
diff --git a/VERSION b/VERSION
index 17e51c3..21455b5 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.1
+0.1.1CVS
diff --git a/configure.in b/configure.in
index e4c6027..5c0fb24 100644
--- a/configure.in
+++ b/configure.in
@@ -40,6 +40,8 @@ AM_PROG_LIBTOOL
pkgdatadir=${libdir}/rcc/
AC_SUBST(pkgdatadir)
+CFLAGS="$CFLAGS -Wall -Wpointer-arith"
+
dnl Checks for programs.
AC_PATH_PROG(RM, rm, /bin/rm)
AC_PATH_PROG(MV, mv, /bin/mv)
@@ -165,7 +167,7 @@ dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
dnl Checks for library functions.
-AC_CHECK_FUNCS(strcasecmp strncasecmp strdup)
+AC_CHECK_FUNCS(strcasecmp strncasecmp strdup strnlen)
AC_OUTPUT(src/Makefile engines/Makefile ui/Makefile examples/Makefile Makefile librcc.spec)
diff --git a/engines/russian.c b/engines/russian.c
index f7e5146..08b8310 100644
--- a/engines/russian.c
+++ b/engines/russian.c
@@ -1,9 +1,10 @@
#include <stdio.h>
+#include <string.h>
#include <librcd.h>
#include <librcc.h>
-static rcc_charset_id AutoengineRussian(rcc_engine_context ctx, const char *buf, int len) {
+static rcc_autocharset_id AutoengineRussian(rcc_engine_context ctx, const char *buf, int len) {
return (rcc_charset_id)rcdGetRussianCharset(buf,len);
}
diff --git a/examples/example.c b/examples/example.c
index 2053c61..820bae0 100644
--- a/examples/example.c
+++ b/examples/example.c
@@ -1,19 +1,20 @@
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <locale.h>
#include <librcc.h>
static rcc_class classes[] = {
- { "input", RCC_CLASS_STANDARD, NULL, NULL, "Input Encoding" },
- { "output", RCC_CLASS_STANDARD, "LC_CTYPE", NULL, "Output Encoding" },
+ { "input", RCC_CLASS_STANDARD, NULL, NULL, "Input Encoding", 0 },
+ { "output", RCC_CLASS_STANDARD, "LC_CTYPE", NULL, "Output Encoding", 0 },
{ NULL }
};
-main() {
+int main() {
const char *language;
char buf[255];
char *recoded;
- int l;
setlocale(LC_ALL, "");
@@ -26,7 +27,7 @@ main() {
while (fgets(buf,255,stdin)) {
if (strlen(buf)<2) break;
- recoded = rccRecode(NULL, 0, 1, buf, 0, NULL);
+ recoded = rccRecode(NULL, 0, 1, buf);
if (recoded) {
printf(recoded);
free(recoded);
@@ -34,4 +35,5 @@ main() {
}
rccFree();
+ return 0;
}
diff --git a/src/curconfig.c b/src/curconfig.c
index 49cddee..72aa4c1 100644
--- a/src/curconfig.c
+++ b/src/curconfig.c
@@ -19,7 +19,7 @@ const char *rccGetCharsetName(rcc_context ctx, rcc_charset_id charset_id) {
return rccConfigGetCharsetName(ctx->current_config, charset_id);
}
-const char *rccGetAutoCharsetName(rcc_context ctx, rcc_charset_id charset_id) {
+const char *rccGetAutoCharsetName(rcc_context ctx, rcc_autocharset_id charset_id) {
if (!ctx) {
if (rcc_default_ctx) ctx = rcc_default_ctx;
else return NULL;
@@ -46,10 +46,10 @@ rcc_charset_id rccGetCharsetByName(rcc_context ctx, const char *name) {
return rccConfigGetCharsetByName(ctx->current_config, name);
}
-rcc_charset_id rccGetAutoCharsetByName(rcc_context ctx, const char *name) {
+rcc_autocharset_id rccGetAutoCharsetByName(rcc_context ctx, const char *name) {
if (!ctx) {
if (rcc_default_ctx) ctx = rcc_default_ctx;
- else return (rcc_charset_id)-1;
+ else return (rcc_autocharset_id)-1;
}
return rccConfigGetAutoCharsetByName(ctx->current_config, name);
diff --git a/src/engine.c b/src/engine.c
index 0ff1aa1..d83fbf7 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -4,6 +4,7 @@
#include "internal.h"
#include "plugin.h"
#include "rccconfig.h"
+#include "rccenca.h"
#include "engine.h"
@@ -15,11 +16,12 @@
# endif /* RCC_RCD_DYNAMIC */
#endif /* RCC_RCD_SUPPORT */
+#ifdef RCC_RCD_DYNAMIC
static rcc_library_handle rcd_handle = NULL;
+#endif /* RCC_RCD_DYNAMIC */
-rcc_charset_id rccAutoengineRussian(rcc_engine_context ctx, const char *buf, int len) {
+rcc_autocharset_id rccAutoengineRussian(rcc_engine_context ctx, const char *buf, int len) {
#ifdef RCC_RCD_SUPPORT
- rcc_charset_id id;
# ifdef RCC_RCD_DYNAMIC
if (!rcdGetRussianCharset) return (rcc_charset_id)-1;
# endif /* RCC_RCD_DYNAMIC */
@@ -30,8 +32,8 @@ rcc_charset_id rccAutoengineRussian(rcc_engine_context ctx, const char *buf, int
}
-static int rccRCDLibraryLoad() {
#ifdef RCC_RCD_DYNAMIC
+static int rccRCDLibraryLoad() {
if (rcd_handle) return 0;
rcd_handle = rccLibraryOpen(RCC_RCD_LIB);
@@ -46,19 +48,19 @@ static int rccRCDLibraryLoad() {
# endif /* RCC_DEBUG */
return -1;
}
-#endif /* RCC_RCD_DYNAMIC */
return 0;
}
+#endif /* RCC_RCD_DYNAMIC */
-static void rccRCDLibraryUnload() {
#ifdef RCC_RCD_DYNAMIC
+static void rccRCDLibraryUnload() {
if (rcd_handle) {
rccLibraryClose(rcd_handle);
rcd_handle = NULL;
}
-#endif /* RCC_RCD_DYNAMIC */
}
+#endif /* RCC_RCD_DYNAMIC */
int rccEngineInit() {
#ifdef RCC_RCD_DYNAMIC
diff --git a/src/engine.h b/src/engine.h
index 37fefba..9cae53d 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -36,6 +36,7 @@ void rccEngineFree();
int rccEngineInitContext(rcc_engine_context engine_ctx, rcc_context ctx);
void rccEngineFreeContext(rcc_engine_context engine_ctx);
+int rccEngineConfigure(rcc_engine_context ctx);
rcc_charset_id rccAutoengineRussian(rcc_engine_context ctx, const char *buf, int len);
diff --git a/src/fs.c b/src/fs.c
index abf45b0..c378704 100644
--- a/src/fs.c
+++ b/src/fs.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -22,6 +23,7 @@
#include "internal.h"
#include "rcciconv.h"
+#include "rccconfig.h"
#ifndef strndup
static char *rccStrndup(const char *str, size_t n) {
@@ -142,9 +144,7 @@ returns:
bit 2 Memory cleanup isn't required
*/
int rccFS1(rcc_language_config config, const char *fspath, char **prefix, char **name) {
- int err;
- int prefix_size;
- char *result, *tmp;
+ char *result;
char *path, *filename;
path = *prefix;
@@ -158,7 +158,12 @@ int rccFS1(rcc_language_config config, const char *fspath, char **prefix, char *
else if (path) result = path;
else return -1;
-
+ if (rccIsASCII(result)) {
+ *name = result;
+ if ((path)&&(filename)) return 1;
+ return 3;
+ }
+
// Checking without recoding in case of autodetection
if (rccGetOption(config->ctx, RCC_OPTION_AUTODETECT_FS_NAMES)) {
if (rccIsFile(result)) {
diff --git a/src/internal.h b/src/internal.h
index 1d3a532..3a07a67 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -12,8 +12,13 @@
#include "rccstring.h"
#include "rccdb4.h"
#include "rcciconv.h"
+#include "rccstring.h"
+#ifdef HAVE_STRNLEN
#define STRNLEN(str,n) (n?strnlen(str,n):strlen(str))
+#else
+#define STRNLEN(str,n) (n?rccStrnlen(str,n):strlen(str))
+#endif /* !strnlen */
#define RCC_MAX_PLUGINS 32
#define RCC_MAX_STRING_CHARS 1024
@@ -44,7 +49,7 @@ struct rcc_context_t {
rcc_iconv fsiconv;
- char tmpbuffer[RCC_MAX_STRING_CHARS+sizeof(rcc_string_header)+1];
+ char tmpbuffer[RCC_MAX_STRING_CHARS+sizeof(rcc_string_header)+9];
char lastprefix[RCC_MAX_PREFIX_CHARS+1];
unsigned char configure;
@@ -60,7 +65,7 @@ struct rcc_context_t {
typedef struct rcc_context_t rcc_context_s;
int rccConfigure(rcc_context ctx);
-char *rccCreateResult(rcc_context ctx, size_t len, size_t *rlen);
+char *rccCreateResult(rcc_context ctx, size_t len);
extern rcc_context rcc_default_ctx;
extern char *rcc_home_dir;
diff --git a/src/librcc.c b/src/librcc.c
index 90ec5aa..0a66e9a 100644
--- a/src/librcc.c
+++ b/src/librcc.c
@@ -1,6 +1,6 @@
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
+#include <stdlib.h>
#include "../config.h"
@@ -20,12 +20,32 @@
#include "rccconfig.h"
#include "rccenca.h"
#include "rcclist.h"
+#include "plugin.h"
#include "engine.h"
#include "rccxml.h"
static int initialized = 0;
char *rcc_home_dir = NULL;
rcc_context rcc_default_ctx = NULL;
+static rcc_compiled_configuration_s compiled_configuration;
+
+rcc_compiled_configuration rccGetCompiledConfiguration() {
+ compiled_configuration.flags = 0;
+#ifdef HAVE_RCD
+ compiled_configuration.flags|=RCC_CC_FLAG_HAVE_RCD;
+#endif /* HAVE_RCD */
+#ifdef HAVE_ENCA
+ compiled_configuration.flags|=RCC_CC_FLAG_HAVE_ENCA;
+#endif /* HAVE_ENCA */
+#ifdef HAVE_DLOPEN
+ compiled_configuration.flags|=RCC_CC_FLAG_HAVE_DYNAMIC_ENGINES;
+#endif /* HAVE_DLOPEN */
+#ifdef HAVE_DB_H
+ compiled_configuration.flags|=RCC_CC_FLAG_HAVE_BERKLEY_DB;
+#endif /* HAVE_DB_H */
+
+ return &compiled_configuration;
+}
int rccInit() {
int err;
@@ -398,7 +418,7 @@ int rccConfigure(rcc_context ctx) {
return 0;
}
-char *rccCreateResult(rcc_context ctx, size_t len, size_t *rlen) {
+char *rccCreateResult(rcc_context ctx, size_t len) {
char *res;
if (!len) len = strlen(ctx->tmpbuffer);
@@ -409,7 +429,5 @@ char *rccCreateResult(rcc_context ctx, size_t len, size_t *rlen) {
memcpy(res, ctx->tmpbuffer, len);
res[len] = 0;
- if (rlen) *rlen = len;
-
return res;
}
diff --git a/src/librcc.h b/src/librcc.h
index 87ded50..2032330 100644
--- a/src/librcc.h
+++ b/src/librcc.h
@@ -19,10 +19,11 @@
/* ID's */
-typedef char rcc_language_id;
-typedef char rcc_alias_id;
-typedef char rcc_charset_id;
-typedef char rcc_engine_id;
+typedef unsigned char rcc_language_id;
+typedef unsigned char rcc_alias_id;
+typedef unsigned char rcc_charset_id;
+typedef unsigned char rcc_autocharset_id;
+typedef unsigned char rcc_engine_id;
typedef int rcc_class_id;
@@ -63,7 +64,7 @@ typedef rcc_charset rcc_charset_list[RCC_MAX_CHARSETS+1];
/* Engines */
typedef void *rcc_engine_internal;
typedef rcc_engine_internal (*rcc_engine_init_function)(rcc_engine_context ctx);
-typedef rcc_charset_id (*rcc_engine_function)(rcc_engine_context ctx, const char *buf, int len);
+typedef rcc_autocharset_id (*rcc_engine_function)(rcc_engine_context ctx, const char *buf, int len);
typedef void (*rcc_engine_free_function)(rcc_engine_context ctx);
struct rcc_engine_t {
@@ -117,12 +118,16 @@ struct rcc_class_default_charset_t {
};
typedef const struct rcc_class_default_charset_t rcc_class_default_charset;
+#define RCC_CLASS_FLAG_CONST 0x01
+#define RCC_CLASS_FLAG_SKIP_SAVELOAD 0x02
+
struct rcc_class_t {
const char *name;
const rcc_class_type class_type;
const char *defvalue; /* locale variable name or parrent name or multibyte charset */
rcc_class_default_charset *defcharset;
const char *fullname;
+ const unsigned long flags;
};
typedef const struct rcc_class_t rcc_class;
typedef rcc_class_ptr rcc_class_list[RCC_MAX_CLASSES+1];
@@ -197,10 +202,10 @@ rcc_option_value rccGetOptionValueByName(rcc_option option, const char *name);
const char *rccConfigGetEngineName(rcc_language_config config, rcc_engine_id engine_id);
const char *rccConfigGetCharsetName(rcc_language_config config, rcc_charset_id charset_id);
-const char *rccConfigGetAutoCharsetName(rcc_language_config config, rcc_charset_id charset_id);
+const char *rccConfigGetAutoCharsetName(rcc_language_config config, rcc_autocharset_id charset_id);
rcc_engine_id rccConfigGetEngineByName(rcc_language_config config, const char *name);
rcc_charset_id rccConfigGetCharsetByName(rcc_language_config config, const char *name);
-rcc_charset_id rccConfigGetAutoCharsetByName(rcc_language_config config, const char *name);
+rcc_autocharset_id rccConfigGetAutoCharsetByName(rcc_language_config config, const char *name);
rcc_language_config rccCheckConfig(rcc_context ctx, rcc_language_id language_id);
rcc_language_config rccGetConfig(rcc_context ctx, rcc_language_id language_id);
@@ -226,11 +231,11 @@ rcc_charset_id rccConfigGetLocaleCharset(rcc_language_config config, const char
/* curconfig.c */
const char *rccGetEngineName(rcc_context ctx, rcc_engine_id engine_id);
const char *rccGetCharsetName(rcc_context ctx, rcc_charset_id charset_id);
-const char *rccGetAutoCharsetName(rcc_context ctx, rcc_charset_id charset_id);
+const char *rccGetAutoCharsetName(rcc_context ctx, rcc_autocharset_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 rccGetAutoCharsetByName(rcc_context ctx, const char *name);
+rcc_autocharset_id rccGetAutoCharsetByName(rcc_context ctx, const char *name);
rcc_engine_id rccGetSelectedEngine(rcc_context ctx);
const char *rccGetSelectedEngineName(rcc_context ctx);
@@ -265,16 +270,17 @@ rcc_class_ptr *rccGetClassList(rcc_context ctx);
*******************************************************************************/
/* string.c */
typedef char *rcc_string;
+typedef const char *rcc_const_string;
size_t rccStringCheck(const char *str);
size_t rccStringSizedCheck(const char *str, size_t len);
-rcc_language_id rccStringGetLanguage(const rcc_string str);
-const char *rccStringGetString(const rcc_string str);
-char *rccStringExtractString(const rcc_string str);
+rcc_language_id rccStringGetLanguage(rcc_const_string str);
+const char *rccStringGetString(rcc_const_string str);
+char *rccStringExtractString(rcc_const_string str);
const char *rccGetString(const char *str);
-const char *rccSizedGetString(const char *str, size_t len, size_t *rlen);
+const char *rccSizedGetString(const char *str, size_t len);
int rccStringCmp(const char *str1, const char *str2);
int rccStringNCmp(const char *str1, const char *str2, size_t n);
@@ -292,11 +298,28 @@ void rccIConvClose(rcc_iconv icnv);
size_t rccIConvRecode(rcc_iconv icnv, char *outbuf, size_t outsize, const char *buf, size_t size);
/* recode.c */
-rcc_string rccFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, size_t len, size_t *rlen);
-char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, size_t len, size_t *rlen);
-char *rccRecode(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *buf, size_t len, size_t *rlen);
+rcc_string rccSizedFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, size_t len);
+char *rccSizedTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, size_t *rlen);
+char *rccSizedRecode(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *buf, size_t len, size_t *rlen);
char *rccFS(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *fspath, const char *path, const char *filename);
+rcc_string rccSizedFromCharset(rcc_context ctx, const char *charset, const char *buf, size_t len);
+char *rccSizedToCharset(rcc_context ctx, const char *charset, const rcc_string buf, size_t *rlen);
+char *rccSizedRecodeToCharset(rcc_context ctx, rcc_class_id class_id, const char *charset, const rcc_string buf, size_t len, size_t *rlen);
+char *rccSizedRecodeFromCharset(rcc_context ctx, rcc_class_id class_id, const char *charset, const char *buf, size_t len, size_t *rlen);
+char *rccSizedRecodeCharsets(rcc_context ctx, const char *from, const char *to, const char *buf, size_t len, size_t *rlen);
+
+
+#define rccFrom(ctx, class_id, buf) rccSizedFrom(ctx, class_id, buf, 0)
+#define rccTo(ctx, class_id, buf) rccSizedTo(ctx, class_id, buf, NULL)
+#define rccRecode(ctx, from, to, buf) rccSizedRecode(ctx, from, to, buf, 0, NULL)
+
+#define rccFromCharset(ctx, charset, buf) rccSizedFromCharset(ctx, charset, buf, 0)
+#define rccToCharset(ctx, charset, buf) rccSizedToCharset(ctx, charset, buf, NULL)
+#define rccRecodeToCharset(ctx, class_id, charset, buf) rccSizedRecodeToCharset(ctx, class_id, charset, buf, 0, NULL)
+#define rccRecodeFromCharset(ctx, class_id, charset, buf) rccSizedRecodeFromCharset(ctx, class_id, charset, buf, 0, NULL)
+#define rccRecodeCharsets(ctx, from, to, buf) rccSizedRecodeCharsets(ctx, from, to, buf, 0, NULL)
+
/*******************************************************************************
******************************** Options ***************************************
*******************************************************************************/
@@ -318,6 +341,26 @@ rcc_engine_internal rccEngineGetInternal(rcc_engine_context ctx);
rcc_language *rccEngineGetLanguage(rcc_engine_context ctx);
rcc_context rccEngineGetRccContext(rcc_engine_context ctx);
+/*******************************************************************************
+**************************** Configuration *************************************
+*******************************************************************************/
+
+#define RCC_CC_FLAG_HAVE_BERKLEY_DB 0x01
+#define RCC_CC_FLAG_HAVE_DYNAMIC_ENGINES 0x02
+#define RCC_CC_FLAG_HAVE_ENCA 0x04
+#define RCC_CC_FLAG_HAVE_RCD 0x08
+struct rcc_compiled_configuration_t {
+ unsigned long flags;
+};
+typedef struct rcc_compiled_configuration_t rcc_compiled_configuration_s;
+typedef const struct rcc_compiled_configuration_t *rcc_compiled_configuration;
+
+rcc_compiled_configuration rccGetCompiledConfiguration();
+
+int rccLocaleGetClassByName(const char *locale);
+int rccLocaleGetLanguage(char *result, const char *lv, unsigned int n);
+int rccLocaleGetCharset(char *result, const char *lv, unsigned int n);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/lng.c b/src/lng.c
index 3f02895..b0ce7cd 100644
--- a/src/lng.c
+++ b/src/lng.c
@@ -10,7 +10,7 @@ rcc_language_ptr rccGetLanguagePointer(rcc_context ctx, rcc_language_id language
if (rcc_default_ctx) ctx = rcc_default_ctx;
else return NULL;
}
- if ((language_id<0)||(language_id>=ctx->n_languages)) return NULL;
+ if (language_id>=ctx->n_languages) return NULL;
return ctx->languages[language_id];
}
@@ -37,7 +37,6 @@ rcc_language_id rccGetLanguageByName(rcc_context ctx, const char *name) {
}
static rcc_language_id rccGetDefaultLanguage(rcc_context ctx) {
- int err;
unsigned int i;
rcc_option_value clo;
rcc_engine_ptr *engines;
@@ -74,7 +73,7 @@ rcc_language_id rccGetRealLanguage(rcc_context ctx, rcc_language_id language_id)
if (rcc_default_ctx) ctx = rcc_default_ctx;
else return (rcc_language_id)-1;
}
- if ((language_id<0)||(language_id>=ctx->n_languages)) return (rcc_language_id)-1;
+ if (language_id>=ctx->n_languages) return (rcc_language_id)-1;
if (language_id) return language_id;
return rccGetDefaultLanguage(ctx);
@@ -132,7 +131,7 @@ int rccSetLanguage(rcc_context ctx, rcc_language_id language_id) {
else return -1;
}
- if ((language_id < 0)||(language_id >= ctx->n_languages)) return -1;
+ if (language_id >= ctx->n_languages) return -1;
if ((!ctx->languages[language_id]->engines[0])||(!ctx->languages[language_id]->charsets[0])) return -2;
if (ctx->current_language != language_id) {
diff --git a/src/lngconfig.c b/src/lngconfig.c
index 6e42181..5ffdd75 100644
--- a/src/lngconfig.c
+++ b/src/lngconfig.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "internal.h"
@@ -9,7 +10,7 @@ rcc_engine_ptr rccConfigGetEnginePointer(rcc_language_config config, rcc_engine_
unsigned int i;
rcc_engine_ptr *engines;
- if ((!config)||(!config->language)||(engine_id<0)) return NULL;
+ if ((!config)||(!config->language)) return NULL;
if (engine_id == (rcc_engine_id)-1) return NULL;
engines = config->language->engines;
@@ -28,9 +29,7 @@ rcc_engine_ptr rccConfigCheckEnginePointer(rcc_language_config config, rcc_engin
}
rcc_engine_ptr rccConfigGetCurrentEnginePointer(rcc_language_config config) {
- unsigned int i;
rcc_engine_id engine_id;
- rcc_engine_ptr *engines;
engine_id = rccConfigGetCurrentEngine(config);
if (engine_id == (rcc_engine_id)-1) return NULL;
@@ -48,10 +47,9 @@ rcc_engine_ptr rccConfigCheckCurrentEnginePointer(rcc_language_config config) {
const char *rccConfigGetEngineName(rcc_language_config config, rcc_engine_id engine_id) {
- unsigned int i;
rcc_engine_ptr engine;
- if ((!config)||(!config->language)||(engine_id<-1)) return NULL;
+ if ((!config)||(!config->language)) return NULL;
if (engine_id == (rcc_engine_id)-1) return rcc_engine_nonconfigured;
@@ -65,7 +63,7 @@ const char *rccConfigGetCharsetName(rcc_language_config config, rcc_charset_id c
unsigned int i;
rcc_charset *charsets;
- if ((!config)||(!config->language)||(charset_id<0)) return NULL;
+ if ((!config)||(!config->language)) return NULL;
charsets = config->language->charsets;
@@ -75,13 +73,13 @@ const char *rccConfigGetCharsetName(rcc_language_config config, rcc_charset_id c
return charsets[charset_id];
}
-const char *rccConfigGetAutoCharsetName(rcc_language_config config, rcc_charset_id charset_id) {
+const char *rccConfigGetAutoCharsetName(rcc_language_config config, rcc_autocharset_id charset_id) {
unsigned int i;
rcc_engine_id engine_id;
rcc_charset *charsets;
rcc_engine_ptr *engines;
- if ((!config)||(!config->language)||(charset_id<0)) return NULL;
+ if ((!config)||(!config->language)) return NULL;
engine_id = rccConfigGetCurrentEngine(config);
if (engine_id == (rcc_engine_id)-1) return NULL;
@@ -121,24 +119,24 @@ rcc_charset_id rccConfigGetCharsetByName(rcc_language_config config, const char
return (rcc_charset_id)-1;
}
-rcc_charset_id rccConfigGetAutoCharsetByName(rcc_language_config config, const char *name) {
+rcc_autocharset_id rccConfigGetAutoCharsetByName(rcc_language_config config, const char *name) {
unsigned int i;
rcc_engine_id engine_id;
rcc_charset *charsets;
rcc_engine_ptr *engines;
- if ((!config)||(!config->language)||(!name)) return (rcc_charset_id)-1;
+ if ((!config)||(!config->language)||(!name)) return (rcc_autocharset_id)-1;
engine_id = rccConfigGetCurrentEngine(config);
- if (engine_id == (rcc_engine_id)-1) return (rcc_charset_id)-1;
+ if (engine_id == (rcc_engine_id)-1) return (rcc_autocharset_id)-1;
engines = config->language->engines;
charsets = engines[engine_id]->charsets;
for (i=0;charsets[i];i++)
- if (!strcasecmp(charsets[i],name)) return (rcc_charset_id)i;
+ if (!strcasecmp(charsets[i],name)) return (rcc_autocharset_id)i;
- return (rcc_charset_id)-1;
+ return (rcc_autocharset_id)-1;
}
int rccConfigInit(rcc_language_config config, rcc_context ctx) {
@@ -218,7 +216,6 @@ void rccConfigClear(rcc_language_config config) {
rcc_language_config rccCheckConfig(rcc_context ctx, rcc_language_id language_id) {
rcc_language_id new_language_id;
- int err;
new_language_id = rccGetRealLanguage(ctx, language_id);
if ((new_language_id == (rcc_language_id)-1)||(new_language_id != language_id)) return NULL;
@@ -229,8 +226,6 @@ rcc_language_config rccCheckConfig(rcc_context ctx, rcc_language_id language_id)
}
rcc_language_config rccGetConfig(rcc_context ctx, rcc_language_id language_id) {
- int err;
-
language_id = rccGetRealLanguage(ctx, language_id);
if (language_id == (rcc_language_id)-1) return NULL;
if (!strcasecmp(ctx->languages[language_id]->sn, "off")) return NULL;
@@ -272,7 +267,7 @@ const char *rccConfigGetSelectedEngineName(rcc_language_config config) {
engine_id = rccConfigGetSelectedEngine(config);
if (engine_id == (rcc_engine_id)-1) return rcc_engine_nonconfigured;
- if ((engine_id < 0)||(!config->language)) return NULL;
+ if (!config->language) return NULL;
return rccConfigGetEngineName(config, engine_id);
}
@@ -321,7 +316,6 @@ const char *rccConfigGetSelectedCharsetName(rcc_language_config config, rcc_clas
}
rcc_charset_id rccConfigGetCurrentCharset(rcc_language_config config, rcc_class_id class_id) {
- int err;
unsigned int i;
rcc_charset_id charset_id;
@@ -334,7 +328,6 @@ rcc_charset_id rccConfigGetCurrentCharset(rcc_language_config config, rcc_class_
rcc_class *cl;
- char stmp[RCC_MAX_CHARSET_CHARS + 1];
const char *defvalue;
if ((!config)||(!config->ctx)||(class_id<0)||(class_id>=config->ctx->n_classes)) return -1;
@@ -414,9 +407,7 @@ const char *rccConfigGetCurrentCharsetName(rcc_language_config config, rcc_class
int rccConfigSetEngine(rcc_language_config config, rcc_engine_id engine_id) {
unsigned int i;
- if ((!config)||(!config->language)||(engine_id < -1)) return -1;
-
- config->configured = 1;
+ if ((!config)||(!config->language)) return -1;
if (engine_id != (rcc_engine_id)-1) {
for (i=0;config->language->engines[i];i++);
@@ -428,6 +419,9 @@ int rccConfigSetEngine(rcc_language_config config, rcc_engine_id engine_id) {
config->configure = 1;
config->engine = engine_id;
}
+
+ config->configured = 1;
+
return 0;
}
@@ -448,19 +442,22 @@ 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)||(charset_id<0)) return -1;
+ if ((!config)||(!config->language)||(class_id < 0)||(class_id >= config->ctx->n_classes)) return -1;
- config->configured = 1;
for (i=0;config->language->charsets[i];i++);
if (charset_id >= i) return -1;
if (config->charset[class_id] != charset_id) {
+ if (config->ctx->classes[class_id]->flags&RCC_CLASS_FLAG_CONST) return -1;
+
if (config->ctx->current_config == config) config->ctx->configure = 1;
config->configure = 1;
config->charset[class_id] = charset_id;
}
+ config->configured = 1;
+
return 0;
}
@@ -475,7 +472,6 @@ int rccConfigSetCharsetByName(rcc_language_config config, rcc_class_id class_id,
rcc_charset_id rccConfigGetLocaleCharset(rcc_language_config config, const char *locale_variable) {
const char *lv;
- rcc_charset *charsets;
rcc_language_id language_id;
char stmp[RCC_MAX_CHARSET_CHARS+1];
diff --git a/src/opt.c b/src/opt.c
index c14240c..18d2054 100644
--- a/src/opt.c
+++ b/src/opt.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <string.h>
#include "rccconfig.h"
#include "internal.h"
diff --git a/src/plugin.c b/src/plugin.c
index 274cab9..68e20e8 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "internal.h"
@@ -102,7 +103,6 @@ rcc_plugin_handle rccPluginGetFreeHandle(rcc_plugin_type type) {
}
rcc_plugin_handle rccPluginLoad(rcc_plugin_type type, const char *name) {
- FILE *f;
void *res;
void *infofunc;
char *pluginfn;
@@ -142,6 +142,8 @@ rcc_plugin_handle rccPluginLoad(rcc_plugin_type type, const char *name) {
} else rccLibraryClose(res);
}
break;
+ default:
+ return NULL;
}
return NULL;
@@ -149,7 +151,6 @@ rcc_plugin_handle rccPluginLoad(rcc_plugin_type type, const char *name) {
rcc_engine *rccPluginEngineGetInfo(const char *name, const char *language) {
- int err;
rcc_plugin_handle handle;
rcc_plugin_engine_info_function infofunc;
diff --git a/src/plugin.h b/src/plugin.h
index e742d5f..9c8f512 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -21,7 +21,7 @@ typedef enum rcc_plugin_type_t {
} rcc_plugin_type;
struct rcc_plugin_handle_t {
- const char *sn;
+ char *sn;
rcc_library_handle handle;
void *info_function;
// rcc_library_type type;
diff --git a/src/rccconfig.c b/src/rccconfig.c
index 3956b5f..57d38c3 100644
--- a/src/rccconfig.c
+++ b/src/rccconfig.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <strings.h>
#include "internal.h"
#include "rccconfig.h"
diff --git a/src/rccdb4.c b/src/rccdb4.c
index 60c9606..d3e8cab 100644
--- a/src/rccdb4.c
+++ b/src/rccdb4.c
@@ -1,4 +1,16 @@
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../config.h"
+
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
+
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif /* HAVE_SYS_STAT_H */
#include "internal.h"
#include "rccdb4.h"
@@ -91,6 +103,27 @@ void rccDb4FreeContext(db4_context ctx) {
}
}
+#ifdef HAVE_DB_H
+static void rccDb4Strip(DBT *key) {
+ size_t size;
+ char *str;
+
+ str = (char*)key->data;
+ size = key->size;
+
+ while ((size > 0)&&((*str==' ')||(*str=='\n')||(*str==0))) {
+ str++;
+ size--;
+ }
+ while ((size > 0)&&((str[size-1]==' ')||(str[size-1]=='\n')||(str[size-1]==0))) {
+ size--;
+ }
+
+ key->size = size;
+ key->data = str;
+}
+#endif /* HAVE_DB_H */
+
int rccDb4SetKey(db4_context ctx, const char *orig, size_t olen, const rcc_string string) {
#ifdef HAVE_DB_H
DBT key, data;
@@ -103,10 +136,11 @@ int rccDb4SetKey(db4_context ctx, const char *orig, size_t olen, const rcc_strin
memset(&data, 0, sizeof(data));
key.data = (char*)orig;
- key.size = STRNLEN(orig, olen); /* No ending zero */
+ key.size = olen?olen:strlen(orig); /* No ending zero */
data.data = (char*)string;
data.size = strlen(string)+1;
-
+
+ rccDb4Strip(&key);
if (key.size < RCC_MIN_DB4_CHARS) return -1;
if (!ctx->db->put(ctx->db, NULL, &key, &data, 0)) return 0;
@@ -127,12 +161,13 @@ rcc_string rccDb4GetKey(db4_context ctx, const char *orig, size_t olen) {
memset(&data, 0, sizeof(data));
key.data = (char*)orig;
- key.size = STRNLEN(orig, olen); /* No ending zero */
+ key.size = olen?olen:strlen(orig); /* No ending zero */
data.flags = DB_DBT_REALLOC;
+ rccDb4Strip(&key);
if (key.size < RCC_MIN_DB4_CHARS) return NULL;
-
+
if (!ctx->db->get(ctx->db, NULL, &key, &data, 0)) return data.data;
#endif /* HAVE_DB_H */
diff --git a/src/rccenca.c b/src/rccenca.c
index 8a439bc..8263742 100644
--- a/src/rccenca.c
+++ b/src/rccenca.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <string.h>
#include "internal.h"
#include "plugin.h"
@@ -14,7 +15,9 @@
# endif /* RCC_ENCA_DYNAMIC */
#endif /* RCC_ENCA_SUPPORT */
+#ifdef RCC_ENCA_DYNAMIC
static rcc_library_handle enca_handle = NULL;
+#endif /* RCC_ENCA_DYNAMIC */
static rcc_engine *enca_engines = NULL;
rcc_engine_internal rccEncaInitContext(rcc_engine_context ctx) {
@@ -49,7 +52,7 @@ void rccEncaFreeContext(rcc_engine_context ctx) {
#endif /* RCC_ENCA_SUPPORT */
}
-rcc_charset_id rccEnca(rcc_engine_context ctx, const char *buf, int len) {
+rcc_autocharset_id rccEnca(rcc_engine_context ctx, const char *buf, int len) {
#ifdef RCC_ENCA_SUPPORT
rcc_engine_internal internal;
const char *charset;
@@ -58,9 +61,7 @@ rcc_charset_id rccEnca(rcc_engine_context ctx, const char *buf, int len) {
internal = rccEngineGetInternal(ctx);
if ((!internal)||(!buf)) return (rcc_charset_id)-1;
- len = STRNLEN(buf, len);
-
- ee = enca_analyse_const((EncaAnalyser)ctx->internal,buf,len);
+ ee = enca_analyse_const((EncaAnalyser)ctx->internal,buf,len?len:strlen(buf));
if (ee.charset<0) return (rcc_charset_id)-1;
charset = enca_charset_name(ee.charset, ENCA_NAME_STYLE_ICONV);
diff --git a/src/rcciconv.c b/src/rcciconv.c
index 1add9d9..65b32b3 100644
--- a/src/rcciconv.c
+++ b/src/rcciconv.c
@@ -9,11 +9,11 @@
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);
(*out_buf)++;
+ (*out_left)--;*/
(*in_buf)++;
(*in_left)--;
- (*out_left)--;
}
}
@@ -49,16 +49,16 @@ void rccIConvClose(rcc_iconv icnv) {
}
size_t rccIConvRecode(rcc_iconv icnv, char *outbuf, size_t outsize, const char *buf, size_t size) {
- char *in_buf, *out_buf, *res, err;
- int in_left, out_left, olen;
+ char *in_buf, *out_buf, err;
+ int in_left, out_left;
int ub, utf_mode=0;
int errors=0;
if ((!buf)||(!outbuf)||(!outsize)||(!icnv)||(icnv->icnv == (iconv_t)-1)) return (size_t)-1;
if (iconv(icnv->icnv, NULL, NULL, NULL, NULL) == -1) return (size_t)-1;
- size = STRNLEN(buf,size);
-
+ if (!size) size = strlen(buf);
+
loop_restart:
errors = 0;
in_buf = (char*)buf; /*DS*/
diff --git a/src/rcclist.c b/src/rcclist.c
index 2664ed6..375807e 100644
--- a/src/rcclist.c
+++ b/src/rcclist.c
@@ -16,7 +16,7 @@ rcc_charset *rccGetCharsetList(rcc_context ctx, rcc_language_id language_id) {
else return NULL;
}
- if ((language_id<0)||(language_id>=ctx->n_languages)) return NULL;
+ if (language_id>=ctx->n_languages) return NULL;
if (!language_id) language_id = rccGetCurrentLanguage(ctx);
return ctx->languages[language_id]->charsets;
@@ -28,7 +28,7 @@ rcc_engine_ptr *rccGetEngineList(rcc_context ctx, rcc_language_id language_id) {
else return NULL;
}
- if ((language_id<0)||(language_id>=ctx->n_languages)) return NULL;
+ if (language_id>=ctx->n_languages) return NULL;
if (!language_id) language_id = rccGetCurrentLanguage(ctx);
return ctx->languages[language_id]->engines;
diff --git a/src/rcclocale.h b/src/rcclocale.h
index dbc1364..dc2c4e7 100644
--- a/src/rcclocale.h
+++ b/src/rcclocale.h
@@ -1,8 +1,5 @@
#ifndef _RCC_LOCALE_H
#define _RCC_LOCALE_H
-int rccLocaleGetClassByName(const char *locale);
-int rccLocaleGetLanguage(char *result, const char *lv, unsigned int n);
-int rccLocaleGetCharset(char *result, const char *lv, unsigned int n);
#endif /* _RCC_LOCALE_H */
diff --git a/src/rccstring.c b/src/rccstring.c
index bd5ef15..d6c6805 100644
--- a/src/rccstring.c
+++ b/src/rccstring.c
@@ -1,19 +1,23 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include "../config.h"
+
#include "internal.h"
#include "rccstring.h"
-rcc_string rccCreateString(rcc_language_id language_id, const char *buf, size_t len, size_t *rlen) {
+rcc_string rccCreateString(rcc_language_id language_id, const char *buf, size_t len) {
char *res;
rcc_string_header *header;
-
- len = STRNLEN(buf, len);
+
+ if (!buf) return NULL;
+ if (!len) len = strlen(buf);
res = (char*)malloc(len+sizeof(rcc_string_header)+1);
if (!res) return NULL;
- strncpy(res + sizeof(rcc_string_header), buf, len);
+ memcpy(res + sizeof(rcc_string_header), buf, len);
res[sizeof(rcc_string_header) + len] = 0;
memset(res, 0xFF, sizeof(rcc_string_header));
@@ -21,7 +25,6 @@ rcc_string rccCreateString(rcc_language_id language_id, const char *buf, size_t
header->magic = RCC_STRING_MAGIC;
header->language_id = language_id;
- if (rlen) *rlen = len + sizeof(rcc_string_header);
return (rcc_string)res;
}
@@ -78,7 +81,7 @@ size_t rccStringSizedCheck(const char *str, size_t len) {
if (!str) return 0;
- newlen = STRNLEN(str, len);
+ newlen = len?len:strlen(str);
if (newlen>sizeof(rcc_string_header)) {
if ((len==newlen)&&(!str[newlen-2])) return 0;
newlen-=sizeof(rcc_string_header);
@@ -88,16 +91,16 @@ size_t rccStringSizedCheck(const char *str, size_t len) {
}
-rcc_language_id rccStringGetLanguage(const rcc_string str) {
+rcc_language_id rccStringGetLanguage(rcc_const_string str) {
if (!str) return (rcc_language_id)-1;
return ((rcc_string_header*)str)->language_id;
}
-const char *rccStringGetString(const rcc_string str) {
+const char *rccStringGetString(rcc_const_string str) {
return (const char *)str + sizeof(rcc_string_header);
}
-char *rccStringExtractString(const rcc_string str) {
+char *rccStringExtractString(rcc_const_string str) {
size_t len;
char *res;
@@ -107,7 +110,7 @@ char *rccStringExtractString(const rcc_string str) {
res = (char*)malloc(len+1);
if (!res) return NULL;
- strncpy(res, rccStringGetString(str), len);
+ memcpy(res, rccStringGetString(str), len);
res[len] = 0;
return res;
@@ -119,12 +122,11 @@ const char *rccGetString(const char *str) {
return str;
}
-const char *rccSizedGetString(const char *str, size_t len, size_t *rlen) {
+const char *rccSizedGetString(const char *str, size_t len) {
size_t newlen;
newlen = rccStringSizedCheck(str, len);
if (newlen) {
- if (rlen) *rlen = newlen;
return rccStringGetString((const rcc_string)str);
}
@@ -148,3 +150,19 @@ int rccStringNCaseCmp(const char *str1, const char *str2, size_t n) {
return strncasecmp(rccGetString(str1), rccGetString(str2), n);
}
+#ifndef HAVE_STRNLEN
+int rccStrnlen(const char *str, size_t size) {
+ unsigned int i;
+ for (i=0;((i<size)&&(str[i]));i++);
+ return i;
+}
+#endif /* HAVE_STRNLEN */
+
+
+int rccIsASCII(const char *str) {
+ unsigned int i;
+
+ for (i=0;str[i];i++)
+ if ((unsigned char)str[i]>0x7F) return 0;
+ return 1;
+}
diff --git a/src/rccstring.h b/src/rccstring.h
index dbbd4c2..3c5d8d7 100644
--- a/src/rccstring.h
+++ b/src/rccstring.h
@@ -11,10 +11,19 @@ struct rcc_string_header_t {
typedef struct rcc_string_header_t rcc_string_header;
-rcc_string rccCreateString(rcc_language_id language_id, const char *buf, size_t len, size_t *rlen);
+rcc_string rccCreateString(rcc_language_id language_id, const char *buf, size_t len);
void rccStringFree(rcc_string str);
int rccStringSetLang(rcc_string string, const char *sn);
int rccStringFixID(rcc_string string, rcc_context ctx);
+#ifdef HAVE_STRNLEN
+# ifndef strnlen
+int strnlen(const char *str, size_t size);
+# endif /* !strnlen */
+#else
+int rccStrnlen(const char *str, size_t size);
+#endif /* HAVE_STRNLEN */
+int rccIsASCII(const char *str);
+
#endif /* _RCC_STRING_H */
diff --git a/src/rccxml.c b/src/rccxml.c
index c7ee405..65a9c4d 100644
--- a/src/rccxml.c
+++ b/src/rccxml.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <string.h>
#include <stdarg.h>
#include "../config.h"
@@ -42,6 +43,7 @@ rcc_config rccGetConfiguration() {
static const char *rccXmlGetText(xmlNodePtr node) {
if ((node)&&(node->children)&&(node->children->type == XML_TEXT_NODE)&&(node->children->content)) return node->children->content;
+ return NULL;
}
int rccXmlInit(int LoadConfiguration) {
@@ -49,12 +51,12 @@ int rccXmlInit(int LoadConfiguration) {
char config[MAX_HOME_CHARS + 32];
xmlXPathContextPtr xpathctx;
- xmlXPathObjectPtr obj;
+ xmlXPathObjectPtr obj = NULL;
xmlNodeSetPtr node_set;
unsigned long i, nnodes;
xmlNodePtr enode, cnode, pnode, node;
xmlAttrPtr attr;
- const char *lang, *fullname, *engine_name;
+ const char *lang, *engine_name;
unsigned int pos, lpos, epos, cpos;
rcc_engine *engine;
@@ -159,6 +161,7 @@ clear:
}
}
}
+ return 0;
}
void rccXmlFree() {
@@ -240,7 +243,7 @@ int rccSave(rcc_context ctx, const char *name) {
rcc_class_ptr *classes;
rcc_class_ptr cl;
- xmlXPathContextPtr xpathctx;
+ xmlXPathContextPtr xpathctx = NULL;
xmlDocPtr doc = NULL;
xmlNodePtr pnode, lnode, onode, llnode, cnode, enode, node;
unsigned char oflag = 0, llflag = 0, cflag;
@@ -361,6 +364,7 @@ int rccSave(rcc_context ctx, const char *name) {
for (j=0;classes[j];j++) {
cl = classes[j];
+ if (cl->flags&RCC_CLASS_FLAG_SKIP_SAVELOAD) continue;
if (cflag) node = rccNodeFind(xpathctx, XPATH_SELECTED_CLASS, language->sn, cl->name);
else node = NULL;
@@ -538,6 +542,7 @@ int rccLoad(rcc_context ctx, const char *name) {
for (j=0;classes[j];j++) {
cl = classes[j];
+ if (cl->flags&RCC_CLASS_FLAG_SKIP_SAVELOAD) continue;
node = rccNodeFind(curxpathctx, XPATH_SELECTED_CLASS, language->sn, cl->name);
if (node) {
diff --git a/src/recode.c b/src/recode.c
index 2164a4d..435e1a6 100644
--- a/src/recode.c
+++ b/src/recode.c
@@ -13,27 +13,27 @@
-static rcc_charset_id rccIConvAuto(rcc_context ctx, rcc_class_id class_id, const char *buf, int len) {
+static rcc_autocharset_id rccIConvAuto(rcc_context ctx, rcc_class_id class_id, const char *buf, int len) {
rcc_class_type class_type;
rcc_engine_ptr engine;
- if (!buf) return (rcc_charset_id)-1;
-
+ if (!buf) return (rcc_autocharset_id)-1;
+
class_type = rccGetClassType(ctx, class_id);
- if ((class_type == RCC_CLASS_STANDARD)||((class_type == RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_OPTION_AUTODETECT_FS_TITLES)))) {
+ if ((class_type != RCC_CLASS_FS)||((class_type == RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_OPTION_AUTODETECT_FS_TITLES)))) {
engine = rccGetCurrentEnginePointer(ctx);
- if ((!engine)||(!engine->func)) return (rcc_charset_id)-1;
+ if ((!engine)||(!engine->func)) return (rcc_autocharset_id)-1;
return engine->func(&ctx->engine_ctx, buf, len);
}
- return (rcc_charset_id)-1;
+ return (rcc_autocharset_id)-1;
}
-rcc_string rccFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, size_t len, size_t *rlen) {
+rcc_string rccSizedFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, size_t len) {
int err;
size_t ret;
rcc_language_id language_id;
- rcc_charset_id charset_id;
+ rcc_autocharset_id charset_id;
rcc_iconv icnv = NULL;
rcc_string result;
rcc_option_value usedb4;
@@ -64,15 +64,15 @@ rcc_string rccFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, size
language_id = rccGetCurrentLanguage(ctx);
charset_id = rccIConvAuto(ctx, class_id, buf, len);
- if (charset_id != (rcc_charset_id)-1) icnv = ctx->iconv_auto[charset_id];
+ if (charset_id != (rcc_autocharset_id)-1) icnv = ctx->iconv_auto[charset_id];
else icnv = ctx->iconv_from[class_id];
if (icnv) {
ret = rccIConv(ctx, icnv, buf, len);
if (ret == (size_t)-1) return NULL;
- result = rccCreateString(language_id, ctx->tmpbuffer, ret, rlen);
+ result = rccCreateString(language_id, ctx->tmpbuffer, ret);
} else {
- result = rccCreateString(language_id, buf, len, rlen);
+ result = rccCreateString(language_id, buf, len);
}
if ((result)&&(usedb4&RCC_OPTION_LEARNING_FLAG_LEARN)) {
@@ -84,7 +84,7 @@ rcc_string rccFrom(rcc_context ctx, rcc_class_id class_id, const char *buf, size
return result;
}
-char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, size_t len, size_t *rlen) {
+char *rccSizedTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, size_t *rlen) {
int err;
size_t newlen;
char *result;
@@ -92,7 +92,6 @@ char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, size_t
const char *utfstring;
rcc_language_config config;
rcc_language_id language_id;
- rcc_charset_id charset_id;
rcc_class_type class_type;
rcc_iconv icnv;
@@ -102,7 +101,7 @@ char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, size_t
}
if ((class_id<0)||(class_id>=ctx->n_classes)||(!buf)) return NULL;
- newlen = rccStringSizedCheck((const char*)buf, len);
+ newlen = rccStringCheck((const char*)buf);
if (!newlen) return NULL;
language_id = rccStringGetLanguage(buf);
@@ -117,6 +116,12 @@ char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, size_t
class_type = rccGetClassType(ctx, class_id);
if ((class_type == RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_OPTION_AUTODETECT_FS_NAMES))) {
+ if (rccIsASCII(utfstring)) {
+ result = rccStringExtractString(buf);
+ if ((result)&&(rlen)) *rlen = strlen(result);
+ return result;
+ }
+
name = (char*)utfstring;
prefix = NULL;
@@ -127,17 +132,18 @@ char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, size_t
if (prefix) free(prefix);
free(name);
}
- if ((rlen)&&(result)) *rlen = strlen(result);
+ if (rlen) *rlen = strlen(result);
return result;
}
}
icnv = config->iconv_to[class_id];
if (icnv) {
- newlen = rccIConv(ctx, icnv, rccStringGetString(buf), len?newlen:0);
+ newlen = rccIConv(ctx, icnv, rccStringGetString((const char*)buf), newlen);
if (newlen == (size_t)-1) return NULL;
- result = rccCreateResult(ctx, newlen, rlen);
+ result = rccCreateResult(ctx, newlen);
+ if (rlen) *rlen = newlen;
} else {
result = rccStringExtractString(buf);
if (rlen) *rlen = newlen;
@@ -146,13 +152,13 @@ char *rccTo(rcc_context ctx, rcc_class_id class_id, const rcc_string buf, size_t
return result;
}
-char *rccRecode(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *buf, size_t len, size_t *rlen) {
- size_t nlen;
+char *rccSizedRecode(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *buf, size_t len, size_t *rlen) {
rcc_string stmp;
char *result;
const char *from_charset, *to_charset;
rcc_charset_id from_charset_id, to_charset_id;
rcc_class_type class_type;
+ rcc_option_value usedb4;
if (!ctx) {
if (rcc_default_ctx) ctx = rcc_default_ctx;
@@ -163,6 +169,20 @@ char *rccRecode(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char
class_type = rccGetClassType(ctx, to);
if ((class_type == RCC_CLASS_FS)&&(rccGetOption(ctx, RCC_OPTION_AUTODETECT_FS_NAMES))) goto recoding;
if (rccGetOption(ctx, RCC_OPTION_LEARNING_MODE)&RCC_OPTION_LEARNING_FLAG_LEARN) goto recoding;
+
+ usedb4 = rccGetOption(ctx, RCC_OPTION_LEARNING_MODE);
+ if (usedb4&RCC_OPTION_LEARNING_FLAG_USE) {
+ stmp = rccDb4GetKey(ctx->db4ctx, buf, len);
+ if (stmp) {
+ if (rccStringFixID(stmp, ctx)) free(stmp);
+ else {
+ result = rccSizedTo(ctx, to, stmp, rlen);
+ free(stmp);
+ return result;
+ }
+ }
+ }
+
from_charset_id = rccIConvAuto(ctx, from, buf, len);
if (from_charset_id != (rcc_charset_id)-1) {
@@ -174,11 +194,11 @@ char *rccRecode(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char
to_charset_id = rccGetCurrentCharset(ctx, to);
if (from_charset_id == to_charset_id) return NULL;
}
-
+
recoding:
- stmp = rccFrom(ctx, from, buf, len, &nlen);
+ stmp = rccSizedFrom(ctx, from, buf, len);
if (stmp) {
- result = rccTo(ctx, to, stmp, nlen, rlen);
+ result = rccSizedTo(ctx, to, stmp, rlen);
free(stmp);
return result;
}
@@ -192,7 +212,6 @@ char *rccFS(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *fsp
char *prefix = (char*)path, *name = (char*)filename; /*DS*/
rcc_string string;
- char *stmp;
char *result = NULL;
if (!ctx) {
@@ -209,16 +228,16 @@ char *rccFS(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *fsp
if (err < 0) return NULL;
if (err&1) {
- if (err&2) return NULL;
if (rccGetOption(ctx, RCC_OPTION_LEARNING_MODE)&RCC_OPTION_LEARNING_FLAG_LEARN) {
- string = rccFrom(ctx, from, name, 0, NULL);
+ string = rccFrom(ctx, from, name);
if (string) free(string);
}
+ if (err&2) return NULL;
return name;
}
}
- string = rccFrom(ctx, from, name, 0, NULL);
+ string = rccFrom(ctx, from, name);
if (string) {
config = rccGetConfig(ctx, rccStringGetLanguage(string));
if (config) result = rccFS3(config, to, prefix, rccStringGetString(string));
@@ -233,3 +252,133 @@ char *rccFS(rcc_context ctx, rcc_class_id from, rcc_class_id to, const char *fsp
}
return result;
}
+
+
+rcc_string rccSizedFromCharset(rcc_context ctx, const char *charset, const char *buf, size_t len) {
+ rcc_iconv icnv;
+ rcc_language_config config;
+ rcc_language_id language_id;
+ size_t res;
+
+ if ((!buf)||(!charset)) return NULL;
+
+ language_id = rccGetCurrentLanguage(ctx);
+ if ((language_id == (rcc_language_id)-1)||(language_id == 0)) return NULL;
+ config = rccGetConfig(ctx, language_id);
+ if (!config) return NULL;
+
+ icnv = rccIConvOpen("UTF-8", charset);
+ if (icnv) {
+ res = rccIConv(ctx, icnv, buf, len);
+ rccIConvClose(icnv);
+ if (res == (size_t)-1) return NULL;
+ return rccCreateString(language_id, ctx->tmpbuffer, res);
+ }
+ return rccCreateString(language_id, buf, len);
+}
+
+char *rccSizedToCharset(rcc_context ctx, const char *charset, const rcc_string buf, size_t *rlen) {
+ rcc_iconv icnv;
+ size_t res;
+
+ if ((!buf)||(!charset)) return NULL;
+
+ res = rccStringCheck(buf);
+ if (!res) return NULL;
+
+ icnv = rccIConvOpen(charset, "UTF-8");
+ if (icnv) {
+ res = rccIConv(ctx, icnv, rccStringGetString(buf), res);
+ rccIConvClose(icnv);
+ if (res == (size_t)-1) return NULL;
+
+ if (rlen) *rlen = res;
+ return rccCreateResult(ctx, res);
+ }
+
+ if (rlen) *rlen = res;
+ return rccStringExtractString(buf);
+}
+
+/* Convert from class_id to Charset */
+char *rccSizedRecodeToCharset(rcc_context ctx, rcc_class_id class_id, const char *charset, const rcc_string buf, size_t len, size_t *rlen) {
+ size_t res;
+ rcc_iconv icnv;
+ const char *str;
+ char *utf8, *extracted;
+
+ if (!charset) return NULL;
+
+ utf8 = rccSizedFrom(ctx, class_id, buf, len);
+ if (!utf8) return utf8;
+
+ str = rccStringGetString(utf8);
+
+ icnv = rccIConvOpen(charset, "UTF-8");
+ if (icnv) {
+ res = rccIConv(ctx, icnv, str, 0);
+ rccIConvClose(icnv);
+ free(utf8);
+
+ if (res == (size_t)-1) return NULL;
+ if (rlen) *rlen = res;
+ return rccCreateResult(ctx, res);
+ }
+
+ extracted = rccStringExtractString(utf8);
+ free(utf8);
+
+ if ((rlen)&&(extracted)) *rlen = strlen(extracted);
+ return extracted;
+}
+
+/* Convert to class_id from Charset */
+char *rccSizedRecodeFromCharset(rcc_context ctx, rcc_class_id class_id, const char *charset, const char *buf, size_t len, size_t *rlen) {
+ size_t res;
+ rcc_iconv icnv;
+ rcc_string str;
+ char *extracted;
+
+
+ if (!charset) return NULL;
+
+ icnv = rccIConvOpen("UTF-8", charset);
+ if (icnv) {
+ res = rccIConv(ctx, icnv, buf, len);
+ rccIConvClose(icnv);
+
+ if (res == (size_t)-1) return NULL;
+
+ str = rccCreateString(rccGetCurrentLanguage(ctx), ctx->tmpbuffer, res);
+ } else str = rccCreateString(rccGetCurrentLanguage(ctx), buf, len);
+
+ if (!str) return NULL;
+
+ extracted = rccSizedTo(ctx, class_id, str, rlen);
+ free(str);
+
+ return extracted;
+}
+
+char *rccSizedRecodeCharsets(rcc_context ctx, const char *from, const char *to, const char *buf, size_t len, size_t *rlen) {
+ char *str;
+ size_t res;
+ rcc_iconv icnv;
+
+ icnv = rccIConvOpen(to, from);
+ if (!icnv) return NULL;
+
+ res = rccIConv(ctx, icnv, buf, len);
+ rccIConvClose(icnv);
+
+ if (res == (size_t)-1) return NULL;
+
+
+
+ str = (char*)malloc((res+1)*sizeof(char));
+ if (!str) return NULL;
+ memcpy(str, ctx->tmpbuffer, res);
+ if (rlen) *rlen = res;
+
+ return str;
+}
diff --git a/ui/gtk.c b/ui/gtk.c
index da909eb..749405e 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -64,7 +64,7 @@ int rccUiMenuSet(rcc_ui_menu_context ctx, rcc_ui_id id) {
}
-static int rccGtkMenuLanguageCB(GtkWidget * w, gpointer item) {
+static void rccGtkMenuLanguageCB(GtkWidget * w, gpointer item) {
rccUiRestoreLanguage(((rcc_ui_menu_context)item)->uictx);
}
@@ -108,7 +108,7 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
}
language_id = rccGetSelectedLanguage(rccctx);
- if (language_id < 0) language_id = 0;
+ if (language_id == (rcc_language_id)-1) language_id = 0;
if (ctx->widget) menu = ctx->widget;
else {
diff --git a/ui/librccui.c b/ui/librccui.c
index 608e04a..f072c6e 100644
--- a/ui/librccui.c
+++ b/ui/librccui.c
@@ -54,6 +54,7 @@
static const char *rccUiXmlGetText(xmlNodePtr node) {
if ((node)&&(node->children)&&(node->children->type == XML_TEXT_NODE)&&(node->children->content)) return node->children->content;
+ return NULL;
}
static xmlNodePtr rccUiNodeFind(xmlXPathContextPtr xpathctx, const char *request, ...) {
@@ -178,7 +179,7 @@ int rccUiInit() {
xmlDocPtr xmlctx;
xmlXPathContextPtr xpathctx = NULL;
xmlXPathObjectPtr obj;
- xmlNodeSetPtr node_set;
+ xmlNodeSetPtr node_set = NULL;
xmlNodePtr node, cnode;
xmlAttrPtr attr;
@@ -189,7 +190,7 @@ int rccUiInit() {
char *search[4];
rcc_option option;
- const char *opt, *val;
+ const char *opt;
rcc_option_name *option_name;
const char *value_name;
const char *class_name;
@@ -551,6 +552,7 @@ int rccUiSetOptionNames(rcc_ui_context ctx, rcc_option_name *names) {
int rccUiSetClassNames(rcc_ui_context ctx) {
if (!ctx) return -1;
ctx->class_names = 1;
+ return 0;
}
int rccUiRestoreLanguage(rcc_ui_context ctx) {
diff --git a/ui/rccmenu.c b/ui/rccmenu.c
index da04cbd..5a51c56 100644
--- a/ui/rccmenu.c
+++ b/ui/rccmenu.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "internal.h"
diff --git a/ui/rccnames.c b/ui/rccnames.c
index 933c910..1e79e5b 100644
--- a/ui/rccnames.c
+++ b/ui/rccnames.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <string.h>
#include <librcc.h>
@@ -62,7 +63,6 @@ typedef enum rcc_name_type_t {
} rcc_name_type;
rcc_name *rccUiGetRccName(rcc_ui_context ctx, const char *findname, unsigned char type) {
- const char *res;
unsigned int i,j;
rcc_name *names[2], *nm;
@@ -108,8 +108,6 @@ rcc_name *rccUiGetLanguageRccName(rcc_ui_context ctx, const char *lang) {
}
const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang) {
- const char *res;
- unsigned int i,j;
rcc_name *names;
names = rccUiGetLanguageRccName(ctx, lang);
@@ -123,8 +121,6 @@ rcc_name *rccUiGetCharsetRccName(rcc_ui_context ctx, const char *charset) {
}
const char *rccUiGetCharsetName(rcc_ui_context ctx, const char *charset) {
- const char *res;
- unsigned int i,j;
rcc_name *names;
names = rccUiGetCharsetRccName(ctx, charset);
@@ -138,8 +134,6 @@ rcc_name *rccUiGetEngineRccName(rcc_ui_context ctx, const char *engine) {
}
const char *rccUiGetEngineName(rcc_ui_context ctx, const char *engine) {
- const char *res;
- unsigned int i,j;
rcc_name *names;
names = rccUiGetEngineRccName(ctx, engine);
@@ -153,8 +147,6 @@ rcc_name *rccUiGetClassRccName(rcc_ui_context ctx, const char *cl) {
}
const char *rccUiGetClassName(rcc_ui_context ctx, const char *cl) {
- const char *res;
- unsigned int i,j;
rcc_name *names;
names = rccUiGetClassRccName(ctx, cl);
@@ -185,7 +177,6 @@ rcc_option_name *rccUiGetOptionRccName(rcc_ui_context ctx, rcc_option option) {
}
const char *rccUiGetOptionName(rcc_ui_context ctx, rcc_option option) {
- unsigned int i;
rcc_option_name *name;
name = rccUiGetOptionRccName(ctx, option);