From 7a6b6a56dabe1e62a0fbc6222c090aa077bcadc7 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 14 Jul 2005 19:39:08 +0000 Subject: Example --- VERSION | 2 +- examples/Makefile.am | 11 ++++-- examples/example.c | 48 ++++++++++++----------- examples/input-russian.txt | 4 ++ examples/input.txt | 4 -- examples/rcc-example.xml | 94 ++++++++++++++++++++++++++++++++++++++++++++++ librcc.spec.in | 12 +++++- src/internal.h | 1 + src/rccdb4.c | 5 ++- src/rcclocale.c | 2 +- src/rccstring.c | 3 +- 11 files changed, 149 insertions(+), 37 deletions(-) create mode 100644 examples/input-russian.txt delete mode 100644 examples/input.txt 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 -#include -#include +#include + +#include + +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-russian.txt b/examples/input-russian.txt new file mode 100644 index 0000000..8ea6e44 --- /dev/null +++ b/examples/input-russian.txt @@ -0,0 +1,4 @@ + + +ਢ +привет diff --git a/examples/input.txt b/examples/input.txt deleted file mode 100644 index 8ea6e44..0000000 --- a/examples/input.txt +++ /dev/null @@ -1,4 +0,0 @@ - - -ਢ -привет 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 @@ + + Автоопределение + + + Отключить + Russian Русский @@ -52,4 +58,92 @@ Поиск файлов + + + ID3 Encoding + Кодировка ID3 Тэгов + + + PlayList Encoding + Кодировка Списка Песен + + + PlayList File Encoding + Кодировка Файлов в Списке + + + FileSystem Encoding + Кодировка Файловой Системы + + + Output Encoding + Отображение + + + + + Авто-определение + + + KOI8-R (Кои) + + + CP1251 (Кодировка Windows) + + + ISO8859-5 (Кодировка ISO) + + + CP866 (Кодировка DOS) + + + Маковская Кодировка + + + UTF-8 (Юникод) + + + + + Отключить + + + Библиотека LibRCD + + + Библиотека Enca + + + + + RusXMMS + РусXMMS + + + Language + Язык + + + Current Language + Текущий Язык + + + + + AutoDetection + Авто-определение + + + Engine + Движок + + + + + Encodings + Кодировки + + + + \ 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; } -- cgit v1.2.3