summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--VERSION2
-rw-r--r--examples/Makefile.am11
-rw-r--r--examples/example.c48
-rw-r--r--examples/input-russian.txt (renamed from examples/input.txt)0
-rw-r--r--examples/rcc-example.xml94
-rw-r--r--librcc.spec.in12
-rw-r--r--src/internal.h1
-rw-r--r--src/rccdb4.c5
-rw-r--r--src/rcclocale.c2
-rw-r--r--src/rccstring.c3
10 files changed, 145 insertions, 33 deletions
diff --git a/VERSION b/VERSION
index f0dbca4..6e8bf73 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.0CVS
+0.1.0
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 837a3cf..abf3ebb 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,7 +1,10 @@
bin_PROGRAMS= example
example_SOURCES= example.c
-example_LDADD= @RCD_LIBS@
-EXTRA_DIST= input.txt
+example_LDADD= ../src/librcc.la
-test: example
- cat input.txt | ./example
+EXTRA_DIST= input-russian.txt rcc.xml rcc-example.xml
+
+test-russian: example
+ cat input-russian.txt | ./example
+
+INCLUDES = -I../src -I../ui
diff --git a/examples/example.c b/examples/example.c
index 9666ae5..2053c61 100644
--- a/examples/example.c
+++ b/examples/example.c
@@ -1,31 +1,37 @@
#include <stdio.h>
-#include <string.h>
-#include <librcd.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" },
+ { NULL }
+};
main() {
- enum russian_charsets res;
+ const char *language;
char buf[255];
+ char *recoded;
int l;
+
+ setlocale(LC_ALL, "");
+
+ rccInit();
+ rccInitDefaultContext(NULL, 0, 0, classes, 0);
+
+ language = rccGetCurrentLanguageName(NULL);
+ if (language) printf("Current Language: %s\n\n", language);
+ else printf("Unable Detect Language\n\n");
while (fgets(buf,255,stdin)) {
if (strlen(buf)<2) break;
-
- res = get_russian_charset(buf,0);
- switch(res) {
- case RUSSIAN_CHARSET_WIN:
- printf("CP1251: ");
- break;
- case RUSSIAN_CHARSET_ALT:
- printf("CP866 : ");
- break;
- case RUSSIAN_CHARSET_KOI:
- printf("KOI8-R: ");
- break;
- case RUSSIAN_CHARSET_UTF8:
- printf("UTF8 : ");
- break;
- }
- printf("%s",buf);
- if (buf[strlen(buf)-1]!='\n') printf("\n");
+ recoded = rccRecode(NULL, 0, 1, buf, 0, NULL);
+ if (recoded) {
+ printf(recoded);
+ free(recoded);
+ } else printf(buf);
}
+
+ rccFree();
}
diff --git a/examples/input.txt b/examples/input-russian.txt
index 8ea6e44..8ea6e44 100644
--- a/examples/input.txt
+++ b/examples/input-russian.txt
diff --git a/examples/rcc-example.xml b/examples/rcc-example.xml
index 3eeada9..5bf50b6 100644
--- a/examples/rcc-example.xml
+++ b/examples/rcc-example.xml
@@ -1,6 +1,12 @@
<?xml version='1.0' encoding="UTF-8"?>
<LibRCC>
<Languages>
+ <Language name="default">
+ <FullName locale="ru">Автоопределение</FullName>
+ </Language>
+ <Language name="off">
+ <FullName locale="ru">Отключить</FullName>
+ </Language>
<Language name="ru">
<FullName>Russian</FullName>
<FullName locale="ru">Русский</FullName>
@@ -52,4 +58,92 @@
<FullName locale="ru">Поиск файлов</FullName>
</Option>
</Options>
+ <Classes>
+ <Class name="id3">
+ <FullName>ID3 Encoding</FullName>
+ <FullName locale="ru">Кодировка ID3 Тэгов</FullName>
+ </Class>
+ <Class name="pl">
+ <FullName>PlayList Encoding</FullName>
+ <FullName locale="ru">Кодировка Списка Песен</FullName>
+ </Class>
+ <Class name="plfs">
+ <FullName>PlayList File Encoding</FullName>
+ <FullName locale="ru">Кодировка Файлов в Списке</FullName>
+ </Class>
+ <Class name="fs">
+ <FullName>FileSystem Encoding</FullName>
+ <FullName locale="ru">Кодировка Файловой Системы</FullName>
+ </Class>
+ <Class name="out">
+ <FullName>Output Encoding</FullName>
+ <FullName locale="ru">Отображение</FullName>
+ </Class>
+ </Classes>
+ <Charsets>
+ <Charset name="Default">
+ <FullName locale="ru">Авто-определение</FullName>
+ </Charset>
+ <Charset name="KOI8-R">
+ <FullName locale="ru">KOI8-R (Кои)</FullName>
+ </Charset>
+ <Charset name="CP1251">
+ <FullName locale="ru">CP1251 (Кодировка Windows)</FullName>
+ </Charset>
+ <Charset name="ISO8859-5">
+ <FullName locale="ru">ISO8859-5 (Кодировка ISO)</FullName>
+ </Charset>
+ <Charset name="IBM866">
+ <FullName locale="ru">CP866 (Кодировка DOS)</FullName>
+ </Charset>
+ <Charset name="MACCYRILLIC">
+ <FullName locale="ru">Маковская Кодировка</FullName>
+ </Charset>
+ <Charset name="UTF-8">
+ <FullName locale="ru">UTF-8 (Юникод)</FullName>
+ </Charset>
+ </Charsets>
+ <Engines>
+ <Engine name="off">
+ <FullName locale="ru">Отключить</FullName>
+ </Engine>
+ <Engine name="Russian">
+ <FullName locale="ru">Библиотека LibRCD</FullName>
+ </Engine>
+ <Engine name="Enca Library">
+ <FullName locale="ru">Библиотека Enca</FullName>
+ </Engine>
+ </Engines>
+ <Pages>
+ <Page name="RusXMMS">
+ <FullName>RusXMMS</FullName>
+ <FullName locale="ru">РусXMMS</FullName>
+ <Frames>
+ <Frame name="Language">
+ <FullName>Language</FullName>
+ <FullName locale="ru">Язык</FullName>
+ <Boxes>
+ <Box name="Language">
+ <FullName>Current Language</FullName>
+ <FullName locale="ru">Текущий Язык</FullName>
+ </Box>
+ </Boxes>
+ </Frame>
+ <Frame name="Engine">
+ <FullName>AutoDetection</FullName>
+ <FullName locale="ru">Авто-определение</FullName>
+ <Boxes>
+ <Box name="Engine">
+ <FullName>Engine</FullName>
+ <FullName locale="ru">Движок</FullName>
+ </Box>
+ </Boxes>
+ </Frame>
+ <Frame name="Charset">
+ <FullName>Encodings</FullName>
+ <FullName locale="ru">Кодировки</FullName>
+ </Frame>
+ </Frames>
+ </Page>
+ </Pages>
</LibRCC> \ No newline at end of file
diff --git a/librcc.spec.in b/librcc.spec.in
index f89af8b..a0778dc 100644
--- a/librcc.spec.in
+++ b/librcc.spec.in
@@ -50,10 +50,16 @@ is part of rusxmms patch.
%configure
%install
+rm -rf $RPM_BUILD_ROOT
+
+mkdir -p $RPM_BUILD_ROOT/etc
+mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/rcc/
%makeinstall prefix=$RPM_BUILD_ROOT%{prefix}
rm -f $RPM_BUILD_ROOT%{prefix}/lib/*.la
-mkdir -p $RPM_BUILD_ROOT/etc
-install -m 644 example/rcc.xml $RPM_BUILD_ROOT/etc
+rm -f $RPM_BUILD_ROOT%{prefix}/lib/rcc/engines/*.?a
+rm -f $RPM_BUILD_ROOT%{prefix}/lib/rcc/engines/*.la
+
+install -m 644 examples/rcc.xml $RPM_BUILD_ROOT/etc
%clean
rm -rf $RPM_BUILD_ROOT
@@ -65,8 +71,10 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(-, root, root)
%doc AUTHORS ChangeLog NEWS README COPYING
+%doc examples/rcc-example.xml
/etc/rcc.xml
%{prefix}/lib/lib*.so.*
+%{prefix}/lib/rcc/
%files devel
%defattr(-, root, root)
diff --git a/src/internal.h b/src/internal.h
index 83a8028..1d3a532 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -18,6 +18,7 @@
#define RCC_MAX_PLUGINS 32
#define RCC_MAX_STRING_CHARS 1024
#define RCC_MAX_PREFIX_CHARS 32
+#define RCC_MIN_DB4_CHARS 3
struct rcc_context_t {
char locale_variable[RCC_MAX_VARIABLE_CHARS+1];
diff --git a/src/rccdb4.c b/src/rccdb4.c
index 5e0894a..fc821a8 100644
--- a/src/rccdb4.c
+++ b/src/rccdb4.c
@@ -4,7 +4,6 @@
#include "rccdb4.h"
#define DATABASE "autolearn.db"
-#define MIN_CHARS 3
int rccInitDb4(rcc_context ctx, const char *name, rcc_db4_flags flags) {
size_t size;
@@ -98,7 +97,7 @@ int rccDb4SetKey(db4_context ctx, const char *orig, size_t olen, const rcc_strin
data.data = (char*)string;
data.size = strlen(string)+1;
- if (key.size < MIN_CHARS) return -1;
+ if (key.size < RCC_MIN_DB4_CHARS) return -1;
err = ctx->db->put(ctx->db, NULL, &key, &data, 0);
return err;
@@ -117,6 +116,8 @@ rcc_string rccDb4GetKey(db4_context ctx, const char *orig, size_t olen) {
key.size = STRNLEN(orig, olen); /* No ending zero */
data.flags = DB_DBT_REALLOC;
+
+ if (key.size < RCC_MIN_DB4_CHARS) return NULL;
err = ctx->db->get(ctx->db, NULL, &key, &data, 0);
if (err) return NULL;
diff --git a/src/rcclocale.c b/src/rcclocale.c
index 9095bca..7bfa54b 100644
--- a/src/rcclocale.c
+++ b/src/rcclocale.c
@@ -46,7 +46,7 @@ int rccLocaleGetLanguage(char *result, const char *lv, unsigned int n) {
else if (!strcasecmp(lv, "LANGUAGE")) l = getenv("LANGUAGE");
else l = NULL;
}
- if ((!l)||(strcmp(l,"C")==0)||(strcmp(l,"POSIX")==0)) return -1;
+ if ((!l)||(!strcmp(l,"C"))||(!strcmp(l,"POSIX"))) return -1;
for (i=0;((l[i])&&(l[i]!='.')&&(l[i]!=':'));i++);
diff --git a/src/rccstring.c b/src/rccstring.c
index d520693..bd5ef15 100644
--- a/src/rccstring.c
+++ b/src/rccstring.c
@@ -80,10 +80,9 @@ size_t rccStringSizedCheck(const char *str, size_t len) {
newlen = STRNLEN(str, len);
if (newlen>sizeof(rcc_string_header)) {
- if ((len==newlen)&&(str[newlen-1])) return 0;
+ if ((len==newlen)&&(!str[newlen-2])) return 0;
newlen-=sizeof(rcc_string_header);
} else return 0;
-
if (((rcc_string_header*)str)->magic == RCC_STRING_MAGIC) return newlen;
return 0;
}