summaryrefslogtreecommitdiffstats
path: root/src/rccdb4.c
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 /src/rccdb4.c
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
Diffstat (limited to 'src/rccdb4.c')
-rw-r--r--src/rccdb4.c43
1 files changed, 39 insertions, 4 deletions
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 */