[tracker] Remove QDBM support
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] Remove QDBM support
- Date: Wed, 22 Apr 2009 07:16:45 -0400 (EDT)
commit a18967a90b6c41dc1313997f89f440de312c31bc
Author: Jürg Billeter <j bitron ch>
Date: Wed Apr 22 12:02:48 2009 +0200
Remove QDBM support
---
configure.ac | 57 +-
po/POTFILES.in | 2 -
src/Makefile.am | 14 +-
src/libtracker-data/Makefile.am | 14 -
src/libtracker-data/libtracker-data.vapi | 3 +-
src/libtracker-data/tracker-data-manager.c | 19 -
src/libtracker-data/tracker-data-manager.h | 3 -
src/libtracker-data/tracker-data-query.c | 2 -
src/libtracker-data/tracker-data-query.h | 1 -
src/libtracker-data/tracker-data-search.c | 76 -
src/libtracker-data/tracker-data-search.h | 44 -
src/libtracker-data/tracker-data-update.c | 163 --
src/libtracker-data/tracker-query-tree.c | 767 --------
src/libtracker-data/tracker-query-tree.h | 74 -
src/libtracker-data/tracker-sparql-query.vala | 17 -
src/libtracker-db/Makefile.am | 16 +-
src/libtracker-db/tracker-db-index-item.c | 37 -
src/libtracker-db/tracker-db-index-item.h | 47 -
src/libtracker-db/tracker-db-index-manager.c | 309 ----
src/libtracker-db/tracker-db-index-manager.h | 54 -
src/libtracker-db/tracker-db-index.c | 1300 -------------
src/libtracker-db/tracker-db-index.h | 98 -
src/libtracker-db/tracker-db-interface-sqlite.c | 2 -
src/libtracker-db/tracker-db-manager.c | 7 -
src/qdbm/Makefile.am | 23 -
src/qdbm/depot.c | 2227 -----------------------
src/qdbm/depot.h | 493 -----
src/qdbm/myconf.c | 1114 ------------
src/qdbm/myconf.h | 594 ------
src/tracker-indexer/tracker-indexer.c | 101 +-
src/tracker-indexer/tracker-main.c | 3 +-
src/tracker-utils/tracker-processes.c | 7 -
src/trackerd/Makefile.am | 2 -
src/trackerd/tracker-daemon.c | 1 -
src/trackerd/tracker-dbus.c | 6 +-
src/trackerd/tracker-dbus.h | 3 -
src/trackerd/tracker-main.c | 20 +-
src/trackerd/tracker-processor.c | 22 -
src/trackerd/tracker-resources.c | 1 -
src/trackerd/tracker-resources.h | 2 -
src/trackerd/tracker-search.c | 19 +-
src/trackerd/tracker-search.h | 5 +-
tests/libtracker-data/Makefile.am | 1 -
tests/libtracker-data/tracker-ontology-test.c | 3 +-
tests/libtracker-data/tracker-sparql-test.c | 3 +-
tests/libtracker-db/Makefile.am | 40 +-
tests/libtracker-db/tracker-index-reader-test.c | 132 --
tests/libtracker-db/tracker-index-writer-test.c | 346 ----
utils/Makefile.am | 15 +-
utils/qdbm/.gitignore | 2 -
utils/qdbm/Makefile.am | 29 -
utils/qdbm/print-words.c | 160 --
utils/qdbm/search-word.c | 155 --
53 files changed, 19 insertions(+), 8636 deletions(-)
diff --git a/configure.ac b/configure.ac
index e16e113..63ceb9c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -132,7 +132,6 @@ GLIB_REQUIRED=2.16.0
PANGO_REQUIRED=1.0.0
GTK_REQUIRED=2.8.0
GLADE_REQUIRED=2.5
-QDBM_REQUIRED=1.8
GMIME_REQUIRED=2.1.0
LIBXML2_REQUIRED=0.6
LIBNOTIFY_REQUIRED=0.4.3
@@ -342,58 +341,6 @@ fi
AM_CONDITIONAL(HAVE_UNIT_TESTS, test "x$have_unit_tests" = "xyes")
##################################################################
-# Enable SQLite FTS support?
-##################################################################
-
-AC_ARG_ENABLE([sqlite_fts],
- AS_HELP_STRING([--enable-sqlite-fts],
- [enable SQLite FTS support (default=yes)]),,
- [enable_sqlite_fts=yes])
-
-if test "x$enable_sqlite_fts" != "xno" ; then
- AC_DEFINE(HAVE_SQLITE_FTS, 1, [Define if we have SQLite FTS support])
-else
- enable_sqlite_fts="no (disabled)"
-fi
-
-AM_CONDITIONAL(ENABLE_SQLITE_FTS, test "$enable_sqlite_fts" = "yes")
-
-####################################################################
-# QDBM check
-####################################################################
-
-AC_ARG_ENABLE(external-qdbm,
- AS_HELP_STRING([--enable-external-qdbm],
- [enable external QDBM, not our imported version (default=no)]),,
- [enable_external_qdbm=no])
-
-if test "x$enable_external_qdbm" != "xno"; then
- PKG_CHECK_MODULES(QDBM,
- [qdbm >= $QDBM_REQUIRED],
- [have_external_qdbm=yes],
- [have_external_qdbm=no])
-
- if test "x$have_external_qdbm" = "xyes"; then
- AC_DEFINE(HAVE_EXTERNAL_QDBM, [], [Define if we have external QDBM])
- fi
-elif test "x$enable_sqlite_fts" != "xyes" ; then
- QDBM_CFLAGS="-I\$(top_srcdir)/src/qdbm"
- QDBM_LIBS="\$(top_builddir)/src/qdbm/libqdbm-private.la"
- AC_DEFINE(HAVE_QDBM, [], [Define if we have QDBM (our imported version)])
-fi
-
-if test "x$enable_external_qdbm" = "xyes"; then
- if test "x$have_external_qdbm" != "xyes"; then
- AC_MSG_ERROR([Couldn't find QDBM >= $QDBM_REQUIRED.])
- fi
-fi
-
-AC_SUBST(QDBM_CFLAGS)
-AC_SUBST(QDBM_LIBS)
-
-AM_CONDITIONAL(HAVE_EXTERNAL_QDBM, test "x$have_external_qdbm" = "xyes")
-
-##################################################################
# Check for HAL
##################################################################
@@ -1418,7 +1365,6 @@ AC_CONFIG_FILES([
src/libtracker-gtk/Makefile
src/libtracker/Makefile
src/Makefile
- src/qdbm/Makefile
src/rasqal/Makefile
src/tracker-applet/Makefile
src/tracker-applet/tracker-applet.desktop.in
@@ -1444,7 +1390,6 @@ AC_CONFIG_FILES([
tests/tracker-indexer/Makefile
tests/tracker-extract/Makefile
utils/Makefile
- utils/qdbm/Makefile
utils/tracker-fts/Makefile
utils/services/Makefile
])
@@ -1470,7 +1415,7 @@ Build Configuration:
Applications:
- Build with SQLite FTS support: $enable_sqlite_fts
+ Build with SQLite FTS support: yes
Build deskbar-applet: $have_deskbar_applet
Build tracker-search-tool: $have_tracker_search_tool
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3871b85..6ad47ba 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,7 +6,6 @@ data/trackerd.desktop.in.in
python/deskbar-handler/tracker-handler-static.py
python/deskbar-handler/tracker-handler.py
python/deskbar-handler/tracker-module.py
-src/libtracker-db/tracker-db-index.c
src/libtracker-common/tracker-dbus.c
src/libtracker-common/tracker-utils.c
src/libtracker-gtk/tracker-metadata-tile.c
@@ -27,7 +26,6 @@ src/tracker-search-tool/tracker-search-tool.c
src/tracker-search-tool/tracker-search-tool.desktop.in.in
src/tracker-utils/tracker-import.c
src/tracker-utils/tracker-info.c
-src/tracker-utils/tracker-meta-folder.c
src/tracker-utils/tracker-processes.c
src/tracker-utils/tracker-search.c
src/tracker-utils/tracker-sparql.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 9ceacb9..1cdbf90 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,16 +4,6 @@ if HAVE_INOTIFY
build_libinotify = libinotify
endif
-if !HAVE_EXTERNAL_QDBM
-if !ENABLE_SQLITE_FTS
-build_qdbm = qdbm
-endif
-endif
-
-if ENABLE_SQLITE_FTS
-build_sqlite_fts = tracker-fts
-endif
-
if HAVE_TRACKER_PREFERENCES
build_tracker_preferences = tracker-preferences
endif
@@ -32,14 +22,13 @@ endif
SUBDIRS = \
libstemmer \
- $(build_qdbm) \
$(build_libinotify) \
rasqal \
libtracker-common \
libtracker-db \
libtracker-data \
libtracker \
- $(build_sqlite_fts) \
+ tracker-fts \
plugins \
trackerd \
tracker-utils \
@@ -52,7 +41,6 @@ SUBDIRS = \
DIST_SUBDIRS = \
libstemmer \
- qdbm \
libinotify \
rasqal \
libtracker-common \
diff --git a/src/libtracker-data/Makefile.am b/src/libtracker-data/Makefile.am
index 982165a..b9ee48a 100644
--- a/src/libtracker-data/Makefile.am
+++ b/src/libtracker-data/Makefile.am
@@ -38,20 +38,6 @@ noinst_HEADERS = \
tracker-sparql-query.h \
tracker-turtle.h
-if ENABLE_SQLITE_FTS
-VALAFLAGS = -D HAVE_SQLITE_FTS
-endif
-
-if !ENABLE_SQLITE_FTS
-libtracker_data_la_SOURCES += \
- tracker-data-search.c \
- tracker-query-tree.c
-
-noinst_HEADERS += \
- tracker-data-search.h \
- tracker-query-tree.h
-endif
-
libtracker-data.vala.stamp: $(libtracker_data_la_VALASOURCES)
$(VALAC) -C $(VALAFLAGS) -H tracker-sparql-query.h ../rasqal/rasqal.vapi ../libtracker-common/libtracker-common.vapi libtracker-data.vapi ../libtracker-db/libtracker-db.vapi $^
touch $@
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index db0aba8..629fdd4 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -18,14 +18,13 @@
*/
namespace Tracker {
- [CCode (cheader_filename = "libtracker-data/tracker-data-query.h,libtracker-data/tracker-data-search.h,libtracker-data/tracker-data-update.h")]
+ [CCode (cheader_filename = "libtracker-data/tracker-data-query.h,libtracker-data/tracker-data-update.h")]
namespace Data {
public int query_resource_id (string uri);
public void begin_transaction ();
public void commit_transaction ();
public void delete_statement (string subject, string predicate, string object);
public void insert_statement (string subject, string predicate, string object);
- public int[] search_get_matches (string search_string);
}
}
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index c3a6799..16f7ef0 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -37,9 +37,7 @@
#include <libtracker-common/tracker-utils.h>
#include <libtracker-common/tracker-ontology.h>
-#include <libtracker-db/tracker-db-index.h>
#include <libtracker-db/tracker-db-interface-sqlite.h>
-#include <libtracker-db/tracker-db-index-manager.h>
#include <libtracker-db/tracker-db-manager.h>
#include "tracker-data-manager.h"
@@ -745,7 +743,6 @@ create_decomposed_transient_metadata_tables (TrackerDBInterface *iface)
g_free (properties);
}
-#ifdef HAVE_SQLITE_FTS
static void
create_fts_table (TrackerDBInterface *iface)
{
@@ -775,13 +772,11 @@ create_fts_table (TrackerDBInterface *iface)
g_string_free (sql, TRUE);
}
-#endif
gboolean
tracker_data_manager_init (TrackerConfig *config,
TrackerLanguage *language,
TrackerDBManagerFlags flags,
- TrackerDBIndexManagerFlags index_flags,
const gchar *test_schema,
gboolean *first_time)
{
@@ -808,16 +803,7 @@ tracker_data_manager_init (TrackerConfig *config,
private,
private_free);
-#ifdef HAVE_SQLITE_FTS
tracker_db_manager_init (flags, &is_first_time_index, FALSE);
-#else
- tracker_db_manager_init (flags, &is_first_time_index, TRUE);
- if (!tracker_db_index_manager_init (index_flags,
- tracker_config_get_min_bucket_count (config),
- tracker_config_get_max_bucket_count (config))) {
- return FALSE;
- }
-#endif
if (first_time != NULL) {
*first_time = is_first_time_index;
@@ -891,9 +877,7 @@ tracker_data_manager_init (TrackerConfig *config,
create_decomposed_metadata_tables (iface, *cl, &max_id);
}
-#ifdef HAVE_SQLITE_FTS
create_fts_table (iface);
-#endif
/* store ontology in database */
for (l = sorted; l; l = l->next) {
@@ -927,9 +911,6 @@ tracker_data_manager_shutdown (void)
{
TrackerDBPrivate *private;
-#ifndef HAVE_SQLITE_FTS
- tracker_db_index_manager_shutdown ();
-#endif
tracker_db_manager_shutdown ();
private = g_static_private_get (&private_key);
diff --git a/src/libtracker-data/tracker-data-manager.h b/src/libtracker-data/tracker-data-manager.h
index 1241573..4f9183d 100644
--- a/src/libtracker-data/tracker-data-manager.h
+++ b/src/libtracker-data/tracker-data-manager.h
@@ -32,8 +32,6 @@
#include <libtracker-db/tracker-db-interface.h>
#include <libtracker-db/tracker-db-file-info.h>
-#include <libtracker-db/tracker-db-index.h>
-#include <libtracker-db/tracker-db-index-manager.h>
#include <libtracker-db/tracker-db-manager.h>
G_BEGIN_DECLS
@@ -41,7 +39,6 @@ G_BEGIN_DECLS
gboolean tracker_data_manager_init (TrackerConfig *config,
TrackerLanguage *language,
TrackerDBManagerFlags flags,
- TrackerDBIndexManagerFlags index_flags,
const gchar *test_schema,
gboolean *first_time);
void tracker_data_manager_shutdown (void);
diff --git a/src/libtracker-data/tracker-data-query.c b/src/libtracker-data/tracker-data-query.c
index cc79296..c6fbe1e 100644
--- a/src/libtracker-data/tracker-data-query.c
+++ b/src/libtracker-data/tracker-data-query.c
@@ -33,9 +33,7 @@
#include <libtracker-common/tracker-utils.h>
#include <libtracker-db/tracker-db-dbus.h>
-#include <libtracker-db/tracker-db-index.h>
#include <libtracker-db/tracker-db-interface-sqlite.h>
-#include <libtracker-db/tracker-db-index-manager.h>
#include <libtracker-db/tracker-db-manager.h>
#include "tracker-data-manager.h"
diff --git a/src/libtracker-data/tracker-data-query.h b/src/libtracker-data/tracker-data-query.h
index 0d56441..ba5a1b3 100644
--- a/src/libtracker-data/tracker-data-query.h
+++ b/src/libtracker-data/tracker-data-query.h
@@ -33,7 +33,6 @@
#include <libtracker-db/tracker-db-interface.h>
#include <libtracker-db/tracker-db-file-info.h>
-#include <libtracker-db/tracker-db-index.h>
G_BEGIN_DECLS
diff --git a/src/libtracker-data/tracker-data-search.c b/src/libtracker-data/tracker-data-search.c
deleted file mode 100644
index a10dbfd..0000000
--- a/src/libtracker-data/tracker-data-search.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
- * Copyright (C) 2007, Jason Kivlighn (jkivlighn gmail com)
- * Copyright (C) 2007, Creative Commons (http://creativecommons.org)
- * Copyright (C) 2008, Nokia
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <stdlib.h>
-
-#include <libtracker-common/tracker-dbus.h>
-#include <libtracker-common/tracker-type-utils.h>
-#include <libtracker-common/tracker-utils.h>
-
-#include <libtracker-db/tracker-db-index.h>
-#include <libtracker-db/tracker-db-interface-sqlite.h>
-#include <libtracker-db/tracker-db-index-manager.h>
-#include <libtracker-db/tracker-db-manager.h>
-
-#include "tracker-data-manager.h"
-#include "tracker-data-query.h"
-#include "tracker-data-search.h"
-#include "tracker-query-tree.h"
-
-#define DEFAULT_METADATA_MAX_HITS 1024
-
-gint *
-tracker_data_search_get_matches (const gchar *search_string,
- gint *result_length)
-{
- GArray *hits;
- TrackerQueryTree *tree;
- gint *result;
- gint i;
-
- g_return_val_if_fail (search_string != NULL, NULL);
- g_return_val_if_fail (result_length != NULL, NULL);
-
- tree = tracker_query_tree_new (search_string,
- tracker_data_manager_get_config (),
- tracker_data_manager_get_language ());
- hits = tracker_query_tree_get_hits (tree, 0, 0);
-
- result = g_new0 (gint, hits->len);
- *result_length = hits->len;
-
- for (i = 0; i < hits->len; i++) {
- TrackerDBIndexItemRank rank;
-
- rank = g_array_index (hits, TrackerDBIndexItemRank, i);
-
- result[i] = rank.service_id;
- }
-
- return result;
-}
-
-
diff --git a/src/libtracker-data/tracker-data-search.h b/src/libtracker-data/tracker-data-search.h
deleted file mode 100644
index 3205e48..0000000
--- a/src/libtracker-data/tracker-data-search.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
- * Copyright (C) 2007, Jason Kivlighn (jkivlighn gmail com)
- * Copyright (C) 2007, Creative Commons (http://creativecommons.org)
- * Copyright (C) 2008, Nokia
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef __TRACKER_DATA_SEARCH_H__
-#define __TRACKER_DATA_SEARCH_H__
-
-#include <glib.h>
-
-#include <libtracker-common/tracker-language.h>
-#include <libtracker-common/tracker-ontology.h>
-
-#include <libtracker-db/tracker-db-interface.h>
-#include <libtracker-db/tracker-db-file-info.h>
-#include <libtracker-db/tracker-db-index.h>
-
-G_BEGIN_DECLS
-
-/* Search API */
-gint *tracker_data_search_get_matches (const gchar *search_string,
- gint *result_length);
-
-G_END_DECLS
-
-#endif /* __TRACKER_DATA_SEARCH_H__ */
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 9f969ef..5ee57cf 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -30,7 +30,6 @@
#include <libtracker-common/tracker-file-utils.h>
#include <libtracker-common/tracker-ontology.h>
-#include <libtracker-db/tracker-db-index-manager.h>
#include <libtracker-db/tracker-db-manager.h>
#include <libtracker-db/tracker-db-dbus.h>
@@ -278,12 +277,10 @@ ensure_resource_id (const gchar *uri)
tracker_db_statement_execute (stmt, NULL);
g_object_unref (stmt);
-#ifdef HAVE_SQLITE_FTS
stmt = tracker_db_interface_create_statement (iface, "INSERT INTO \"fts\" (rowid) VALUES (?)");
tracker_db_statement_bind_int (stmt, 0, id);
tracker_db_statement_execute (stmt, NULL);
g_object_unref (stmt);
-#endif
g_hash_table_insert (update_buffer.resource_cache, g_strdup (uri), GUINT_TO_POINTER (id));
}
@@ -386,7 +383,6 @@ tracker_data_update_buffer_flush (void)
g_string_free (sql, TRUE);
}
-#ifdef HAVE_SQLITE_FTS
fts_sql = g_string_new ("UPDATE \"fts\" SET ");
fts_index = 0;
@@ -423,7 +419,6 @@ tracker_data_update_buffer_flush (void)
g_object_unref (stmt);
}
g_string_free (fts_sql, TRUE);
-#endif
}
g_hash_table_remove_all (update_buffer.tables);
@@ -633,119 +628,6 @@ cache_set_metadata_decomposed (TrackerProperty *property,
g_free (table_name);
}
-
-static void
-send_text_to_index (TrackerConfig *config,
- TrackerLanguage*language,
- gint service_id,
- const gchar *text,
- gboolean full_parsing,
- gint weight_factor)
-{
-#ifndef HAVE_SQLITE_FTS
- TrackerDBIndex *lindex;
- GHashTable *parsed;
- GHashTableIter iter;
- gpointer key, value;
-
- if (!text) {
- return;
- }
-
- if (full_parsing) {
- parsed = tracker_parser_text (NULL,
- text,
- weight_factor,
- language,
- tracker_config_get_max_words_to_index (config),
- tracker_config_get_max_word_length (config),
- tracker_config_get_min_word_length (config),
- tracker_config_get_enable_stemmer (config),
- FALSE);
- } else {
- /* We dont know the exact property weight.
- Big value works.
- */
- parsed = tracker_parser_text_fast (NULL,
- text,
- weight_factor);
- }
-
- g_hash_table_iter_init (&iter, parsed);
-
- lindex = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
-
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- tracker_db_index_add_word (lindex,
- key,
- service_id,
- GPOINTER_TO_INT (value));
- }
-
- g_hash_table_unref (parsed);
-#endif
-}
-
-static void
-index_text_with_parsing (TrackerConfig *config,
- TrackerLanguage*language,
- gint service_id,
- const gchar *content,
- gint weight_factor)
-{
- send_text_to_index (config,
- language,
- service_id,
- content,
- TRUE,
- weight_factor);
-}
-
-static void
-unindex_text_with_parsing (TrackerConfig *config,
- TrackerLanguage*language,
- gint service_id,
- const gchar *content,
- gint weight_factor)
-{
- send_text_to_index (config,
- language,
- service_id,
- content,
- TRUE,
- weight_factor * -1);
-}
-
-static void
-index_text_no_parsing (TrackerConfig *config,
- TrackerLanguage*language,
- gint service_id,
- const gchar *content,
- gchar weight_factor)
-{
- send_text_to_index (config,
- language,
- service_id,
- content,
- FALSE,
- weight_factor);
-}
-
-static void
-unindex_text_no_parsing (TrackerConfig *config,
- TrackerLanguage*language,
- gint service_id,
- const gchar *content,
- gint weight_factor)
-{
- send_text_to_index (config,
- language,
- service_id,
- content,
- FALSE,
- weight_factor * -1);
-}
-
static void
delete_resource_type (gint resource_id,
TrackerClass *cl)
@@ -979,7 +861,6 @@ tracker_data_delete_statement (const gchar *subject,
}
if (object && tracker_property_get_fulltext_indexed (field)) {
-#ifdef HAVE_SQLITE_FTS
TrackerDBInterface *iface;
TrackerDBStatement *stmt;
@@ -996,27 +877,6 @@ tracker_data_delete_statement (const gchar *subject,
tracker_db_statement_execute (stmt, NULL);
g_object_unref (stmt);
-#else
- TrackerConfig *config;
- TrackerLanguage *language;
-
- config = tracker_data_manager_get_config ();
- language = tracker_data_manager_get_language ();
-
- if (tracker_property_get_filtered (field)) {
- unindex_text_no_parsing (config,
- language,
- subject_id,
- object,
- tracker_property_get_weight (field));
- } else {
- unindex_text_with_parsing (config,
- language,
- subject_id,
- object,
- tracker_property_get_weight (field));
- }
-#endif
}
} else {
g_warning ("Property '%s' not found in the ontology", predicate);
@@ -1144,29 +1004,6 @@ tracker_data_insert_statement (const gchar *subject,
if (field != NULL) {
/* add value to metadata database */
cache_set_metadata_decomposed (field, object);
-
- if (tracker_property_get_fulltext_indexed (field)) {
- /* add value to fulltext index */
- TrackerConfig *config;
- TrackerLanguage *language;
-
- config = tracker_data_manager_get_config ();
- language = tracker_data_manager_get_language ();
-
- if (tracker_property_get_filtered (field)) {
- index_text_with_parsing (config,
- language,
- update_buffer.id,
- object,
- tracker_property_get_weight (field));
- } else {
- index_text_no_parsing (config,
- language,
- update_buffer.id,
- object,
- tracker_property_get_weight (field));
- }
- }
} else {
g_warning ("Property '%s' not found in the ontology", predicate);
}
diff --git a/src/libtracker-data/tracker-query-tree.c b/src/libtracker-data/tracker-query-tree.c
deleted file mode 100644
index 9d38815..0000000
--- a/src/libtracker-data/tracker-query-tree.c
+++ /dev/null
@@ -1,767 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2008, Nokia
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-/* These defines are required to allow lrintf() without warnings when
- * building.
- */
-#define _ISOC9X_SOURCE 1
-#define _ISOC99_SOURCE 1
-
-#define __USE_ISOC9X 1
-#define __USE_ISOC99 1
-
-#include <string.h>
-#include <math.h>
-
-#include <glib-object.h>
-
-#include <libtracker-common/tracker-config.h>
-#include <libtracker-common/tracker-parser.h>
-#include <libtracker-common/tracker-ontology.h>
-
-#include <libtracker-db/tracker-db-index-item.h>
-#include <libtracker-db/tracker-db-index-manager.h>
-#include <libtracker-db/tracker-db-interface.h>
-#include <libtracker-db/tracker-db-manager.h>
-
-#include "tracker-query-tree.h"
-
-#define TRACKER_QUERY_TREE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_QUERY_TREE, TrackerQueryTreePrivate))
-
-#define MAX_HIT_BUFFER 480000
-#define SCORE_MULTIPLIER 100000
-
-typedef enum OperationType OperationType;
-typedef enum TreeNodeType TreeNodeType;
-typedef struct TreeNode TreeNode;
-typedef struct TrackerQueryTreePrivate TrackerQueryTreePrivate;
-typedef struct ComposeHitsData ComposeHitsData;
-typedef struct SearchHitData SearchHitData;
-
-enum OperationType {
- OP_NONE,
- OP_AND,
- OP_OR
-};
-
-struct TreeNode {
- TreeNode *left;
- TreeNode *right;
- OperationType op;
- gchar *term;
-};
-
-struct TrackerQueryTreePrivate {
- gchar *query_str;
- TreeNode *tree;
- TrackerConfig *config;
- TrackerLanguage *language;
-};
-
-struct ComposeHitsData {
- OperationType op;
- GHashTable *other_table;
- GHashTable *dest_table;
-};
-
-struct SearchHitData {
- guint32 score;
-};
-
-enum {
- PROP_0,
- PROP_QUERY
-};
-
-static void tracker_query_tree_finalize (GObject *object);
-static void tracker_query_tree_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void tracker_query_tree_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE (TrackerQueryTree, tracker_query_tree, G_TYPE_OBJECT)
-
-static void
-tracker_query_tree_class_init (TrackerQueryTreeClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = tracker_query_tree_finalize;
- object_class->set_property = tracker_query_tree_set_property;
- object_class->get_property = tracker_query_tree_get_property;
-
- g_object_class_install_property (object_class,
- PROP_QUERY,
- g_param_spec_string ("query",
- "Query",
- "Query",
- NULL,
- G_PARAM_READWRITE));
- g_type_class_add_private (object_class,
- sizeof (TrackerQueryTreePrivate));
-}
-
-static void
-tracker_query_tree_init (TrackerQueryTree *tree)
-{
-}
-
-static TreeNode *
-tree_node_leaf_new (const gchar *term)
-{
- TreeNode *node;
-
- node = g_slice_new0 (TreeNode);
- node->term = g_strdup (term);
- node->op = OP_NONE;
-
- return node;
-}
-
-static TreeNode *
-tree_node_operator_new (OperationType op)
-{
- TreeNode *node;
-
- node = g_slice_new0 (TreeNode);
- node->op = op;
-
- return node;
-}
-
-static void
-tree_node_free (TreeNode *node)
-{
- if (!node)
- return;
-
- /* Free string if any */
- g_free (node->term);
-
- /* free subnodes */
- tree_node_free (node->left);
- tree_node_free (node->right);
-
- g_slice_free (TreeNode, node);
-}
-
-static void
-tracker_query_tree_finalize (GObject *object)
-{
- TrackerQueryTreePrivate *priv;
-
- priv = TRACKER_QUERY_TREE_GET_PRIVATE (object);
-
- tree_node_free (priv->tree);
- g_free (priv->query_str);
-
- G_OBJECT_CLASS (tracker_query_tree_parent_class)->finalize (object);
-}
-
-static void
-tracker_query_tree_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- switch (prop_id) {
- case PROP_QUERY:
- tracker_query_tree_set_query (TRACKER_QUERY_TREE (object),
- g_value_get_string (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-tracker_query_tree_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- TrackerQueryTreePrivate *priv;
-
- priv = TRACKER_QUERY_TREE_GET_PRIVATE (object);
-
- switch (prop_id) {
- case PROP_QUERY:
- g_value_set_string (value, priv->query_str);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-TrackerQueryTree *
-tracker_query_tree_new (const gchar *query_str,
- TrackerConfig *config,
- TrackerLanguage *language)
-{
- TrackerQueryTree *object;
- TrackerQueryTreePrivate *priv;
-
- g_return_val_if_fail (query_str != NULL, NULL);
- g_return_val_if_fail (TRACKER_IS_CONFIG (config), NULL);
- g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
-
- /* NOTE: The "query" has to come AFTER the "config" and
- * "language" properties since setting the query actually
- * uses the priv->config and priv->language settings.
- * Changing this order results in warnings.
- */
-
- object = g_object_new (TRACKER_TYPE_QUERY_TREE, NULL);
-
- priv = TRACKER_QUERY_TREE_GET_PRIVATE (object);
-
- priv->config = g_object_ref (config);
- priv->language = g_object_ref (language);
-
- tracker_query_tree_set_query (object, query_str);
-
- return object;
-}
-
-#if 0
-static void
-print_tree (TreeNode *node)
-{
- if (!node) {
- g_print ("NULL ");
- return;
- }
-
- switch (node->op) {
- case OP_AND:
- g_print ("AND ");
- print_tree (node->left);
- print_tree (node->right);
- break;
- case OP_OR:
- g_print ("OR ");
- print_tree (node->left);
- print_tree (node->right);
- break;
- default:
- g_print ("%s ", node->term);
- }
-}
-#endif
-
-static void
-create_query_tree (TrackerQueryTree *tree)
-{
- TrackerQueryTreePrivate *priv;
- TreeNode *node, *stack_node;
- GQueue *queue, *stack;
- gboolean last_element_is_term = FALSE;
- gchar *parsed_str, **strings;
- gint i;
-
- priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-
- strings = g_strsplit (priv->query_str, " ", -1);
- queue = g_queue_new ();
- stack = g_queue_new ();
-
- /* Create a parse tree that recognizes queries such as:
- * "foo"
- * "foo and bar"
- * "foo or bar"
- * "foo and bar or baz"
- * "foo or bar and baz"
- *
- * The operator "and" will have higher priority than the operator "or",
- * and will also be assumed to exist if there is no operator between two
- * search terms.
- */
-
- /* Step 1. Create polish notation for the search term, the
- * stack will be used to store operators temporarily
- */
- for (i = 0; strings[i]; i++) {
- OperationType op;
-
- if (!strings[i] || !*strings[i])
- continue;
-
- /* get operator type */
- if (strcmp (strings[i], "and") == 0) {
- op = OP_AND;
- } else if (strcmp (strings [i], "or") == 0) {
- op = OP_OR;
- } else {
- if (last_element_is_term) {
- /* last element was a search term, assume the "and"
- * operator between these two elements, and wait
- * for actually parsing the second term */
- op = OP_AND;
- i--;
- } else {
- op = OP_NONE;
- }
- }
-
- /* create node for the operation type */
- switch (op) {
- case OP_AND:
- node = tree_node_operator_new (OP_AND);
- stack_node = g_queue_peek_head (stack);
-
- /* push in the queue operators with fewer priority, "or" in this case */
- while (stack_node && stack_node->op == OP_OR) {
- stack_node = g_queue_pop_head (stack);
- g_queue_push_head (queue, stack_node);
-
- stack_node = g_queue_peek_head (stack);
- }
-
- g_queue_push_head (stack, node);
- last_element_is_term = FALSE;
- break;
- case OP_OR:
- node = tree_node_operator_new (OP_OR);
- g_queue_push_head (stack, node);
- last_element_is_term = FALSE;
- break;
- default:
- case OP_NONE:
- /* search term */
- parsed_str = tracker_parser_text_to_string (strings[i],
- priv->language,
- tracker_config_get_max_word_length (priv->config),
- tracker_config_get_min_word_length (priv->config),
- TRUE,
- FALSE,
- FALSE);
- node = tree_node_leaf_new (g_strstrip (parsed_str));
- g_queue_push_head (queue, node);
- last_element_is_term = TRUE;
-
- g_free (parsed_str);
- }
- }
-
- /* we've finished parsing, queue all remaining operators in the stack */
- while ((stack_node = g_queue_pop_head (stack)) != NULL) {
- g_queue_push_head (queue, stack_node);
- }
-
- /* step 2: run through the reverse polish notation and connect nodes to
- * create a tree, the stack will be used to store temporarily nodes
- * until they're connected to a parent node */
- while ((node = g_queue_pop_tail (queue)) != NULL) {
- switch (node->op) {
- case OP_AND:
- case OP_OR:
- node->left = g_queue_pop_head (stack);
- node->right = g_queue_pop_head (stack);
- g_queue_push_head (stack, node);
- break;
- default:
- case OP_NONE:
- g_queue_push_head (stack, node);
- break;
- }
-
- priv->tree = node;
- }
-
- g_strfreev (strings);
- g_queue_free (stack);
- g_queue_free (queue);
-}
-
-void
-tracker_query_tree_set_query (TrackerQueryTree *tree,
- const gchar *query_str)
-{
- TrackerQueryTreePrivate *priv;
- gchar *str;
-
- g_return_if_fail (TRACKER_IS_QUERY_TREE (tree));
- g_return_if_fail (query_str != NULL);
-
- priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-
- str = g_strdup (query_str);
- g_free (priv->query_str);
- priv->query_str = str;
-
- /* construct the parse tree */
- create_query_tree (tree);
-
- g_object_notify (G_OBJECT (tree), "query");
-}
-
-G_CONST_RETURN gchar *
-tracker_query_tree_get_query (TrackerQueryTree *tree)
-{
- TrackerQueryTreePrivate *priv;
-
- g_return_val_if_fail (TRACKER_IS_QUERY_TREE (tree), NULL);
-
- priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
- return priv->query_str;
-}
-
-static void
-get_tree_words (TreeNode *node, GSList **list)
-{
- if (!node)
- return;
-
- if (node->op == OP_NONE)
- *list = g_slist_prepend (*list, node->term);
- else {
- get_tree_words (node->left, list);
- get_tree_words (node->right, list);
- }
-}
-
-static gint
-get_idf_score (TrackerDBIndexItem *details,
- gfloat idf)
-{
- guint32 score;
- gfloat f;
-
- score = tracker_db_index_item_get_score (details);
- f = idf * score * SCORE_MULTIPLIER;
-
- return (f > 1.0) ? lrintf (f) : 1;
-}
-
-static void
-search_hit_data_free (gpointer data)
-{
- g_slice_free (SearchHitData, data);
-}
-
-static void
-add_search_term_hits_to_hash_table (TrackerDBIndexItem *items,
- guint item_count,
- GHashTable *result)
-{
- guint i;
-
- for (i = 0; i < item_count; i++) {
- SearchHitData *data;
-
- data = g_slice_new (SearchHitData);
- data->score = get_idf_score (&items[i], (float) 1 / item_count);
-
- g_hash_table_insert (result, GINT_TO_POINTER (items[i].id), data);
- }
-}
-
-static GHashTable *
-get_search_term_hits (TrackerQueryTree *tree,
- const gchar *term)
-{
- TrackerQueryTreePrivate *priv;
- TrackerDBIndex *index;
- TrackerDBIndexItem *items;
- guint item_count;
- GHashTable *result;
-
- priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-
- result = g_hash_table_new_full (NULL,
- NULL,
- NULL,
- search_hit_data_free);
-
- index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
-
- items = tracker_db_index_get_word_hits (index, term, &item_count);
-
- if (items) {
- add_search_term_hits_to_hash_table (items,
- item_count,
- result);
- g_free (items);
- }
-
- return result;
-}
-
-static void
-compose_hits_foreach (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- SearchHitData *hit1, *hit2, *hit;
- ComposeHitsData *data;
-
- data = (ComposeHitsData *) user_data;
- hit1 = (SearchHitData *) value;
- hit2 = g_hash_table_lookup (data->other_table, key);
-
- if (data->op == OP_OR) {
- /* compose both scores in the same entry */
- hit = g_slice_dup (SearchHitData, hit1);
-
- if (hit2)
- hit->score += hit2->score;
-
- g_hash_table_insert (data->dest_table, key, hit);
- } else if (data->op == OP_AND) {
- /* only compose if the key is in both tables */
- if (hit2) {
- hit = g_slice_dup (SearchHitData, hit1);
- hit->score += hit2->score;
- g_hash_table_insert (data->dest_table, key, hit);
- }
- } else {
- g_assert_not_reached ();
- }
-}
-
-static GHashTable *
-compose_hits (OperationType op,
- GHashTable *left_table,
- GHashTable *right_table)
-{
- ComposeHitsData data;
- GHashTable *foreach_table;
-
- data.op = op;
-
- /* try to run the foreach in the table with less hits */
- if (g_hash_table_size (left_table) < g_hash_table_size (right_table)) {
- foreach_table = left_table;
- data.other_table = right_table;
- } else {
- foreach_table = right_table;
- data.other_table = left_table;
- }
-
- if (op == OP_OR) {
- data.dest_table = g_hash_table_ref (data.other_table);
- } else {
- data.dest_table = g_hash_table_new_full (NULL,
- NULL,
- NULL,
- search_hit_data_free);
- }
-
- g_hash_table_foreach (foreach_table, (GHFunc) compose_hits_foreach, &data);
-
- return data.dest_table;
-}
-
-static GHashTable *
-get_node_hits (TrackerQueryTree *tree,
- TreeNode *node)
-{
- GHashTable *left_table, *right_table, *result;
-
- if (!node)
- return NULL;
-
- switch (node->op) {
- case OP_NONE:
- result = get_search_term_hits (tree, node->term);
- break;
- case OP_AND:
- case OP_OR:
- left_table = get_node_hits (tree, node->left);
- right_table = get_node_hits (tree, node->right);
- result = compose_hits (node->op, left_table, right_table);
-
- g_hash_table_unref (left_table);
- g_hash_table_unref (right_table);
- break;
- default:
- g_assert_not_reached ();
- }
-
- return result;
-}
-
-static void
-get_hits_foreach (gpointer key,
- gpointer value,
- gpointer user_data)
-{
- GArray *array;
- TrackerDBIndexItemRank rank;
- SearchHitData *hit_data;
-
- array = (GArray *) user_data;
- hit_data = (SearchHitData *) value;
-
- rank.service_id = GPOINTER_TO_UINT (key);
- rank.score = hit_data->score;
-
- g_array_append_val (array, rank);
-}
-
-static gint
-compare_search_hits (gconstpointer a,
- gconstpointer b)
-{
- TrackerDBIndexItemRank *ap, *bp;
-
- ap = (TrackerDBIndexItemRank *) a;
- bp = (TrackerDBIndexItemRank *) b;
-
- return (bp->score - ap->score);
-}
-
-GSList *
-tracker_query_tree_get_words (TrackerQueryTree *tree)
-{
- TrackerQueryTreePrivate *priv;
- GSList *list = NULL;
-
- g_return_val_if_fail (TRACKER_IS_QUERY_TREE (tree), NULL);
-
- priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
- get_tree_words (priv->tree, &list);
-
- return list;
-}
-
-GArray *
-tracker_query_tree_get_hits (TrackerQueryTree *tree,
- guint offset,
- guint limit)
-{
- TrackerQueryTreePrivate *priv;
- GHashTable *table;
- GArray *array;
-
- g_return_val_if_fail (TRACKER_IS_QUERY_TREE (tree), NULL);
-
- priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
-
- g_return_val_if_fail (priv->tree != NULL, NULL);
-
- table = get_node_hits (tree, priv->tree);
- array = g_array_sized_new (TRUE, TRUE, sizeof (TrackerDBIndexItemRank),
- g_hash_table_size (table));
-
- g_hash_table_foreach (table, (GHFunc) get_hits_foreach, array);
- g_array_sort (array, compare_search_hits);
-
- if (offset > 0) {
- g_array_remove_range (array, 0, CLAMP (offset, 0, array->len));
- }
-
- if (limit > 0 && limit < array->len) {
- g_array_remove_range (array, limit, array->len - limit);
- }
-
- g_hash_table_destroy (table);
-
- return array;
-}
-
-gint
-tracker_query_tree_get_hit_count (TrackerQueryTree *tree)
-{
- TrackerQueryTreePrivate *priv;
- GHashTable *table;
- gint count;
-
- g_return_val_if_fail (TRACKER_IS_QUERY_TREE (tree), 0);
-
- priv = TRACKER_QUERY_TREE_GET_PRIVATE (tree);
- table = get_node_hits (tree, priv->tree);
-
- if (!table)
- return 0;
-
- count = g_hash_table_size (table);
- g_hash_table_destroy (table);
-
- return count;
-}
-
-GArray *
-tracker_query_tree_get_hit_counts (TrackerQueryTree *tree)
-{
- TrackerDBInterface *iface;
- TrackerDBResultSet *result_set;
- GArray *hits, *counts;
- guint i;
- GString *sql;
-
- g_return_val_if_fail (TRACKER_IS_QUERY_TREE (tree), NULL);
-
- iface = tracker_db_manager_get_db_interface ();
-
- hits = tracker_query_tree_get_hits (tree, 0, 0);
- counts = g_array_sized_new (TRUE, TRUE, sizeof (TrackerHitCount), 10);
-
- /* count RDF types for each text search result */
- sql = g_string_new ("SELECT ");
- g_string_append (sql, "(SELECT Uri FROM \"rdfs:Resource\" WHERE ID = \"rdf:type\"), COUNT(*) ");
- g_string_append (sql, "FROM (SELECT * FROM \"rdfs:Resource_rdf:type\" ");
- g_string_append (sql, "WHERE ID IN (");
-
- for (i = 0; i < hits->len; i++) {
- TrackerDBIndexItemRank rank;
-
- rank = g_array_index (hits, TrackerDBIndexItemRank, i);
-
- if (i > 0) {
- g_string_append (sql, ",");
- }
- g_string_append_printf (sql, "%d", rank.service_id);
- }
-
- g_string_append (sql, ")) GROUP BY \"rdf:type\"");
-
- result_set = tracker_db_interface_execute_query (iface, NULL, "%s", sql->str);
-
- if (result_set) {
- gboolean valid = TRUE;
- while (valid) {
- TrackerHitCount count;
- TrackerClass *class;
- gchar *class_uri;
-
- tracker_db_result_set_get (result_set, 0, &class_uri, 1, &count.count, -1);
-
- class = tracker_ontology_get_class_by_uri (class_uri);
- count.class = class;
-
- g_array_append_val (counts, count);
-
- g_free (class_uri);
-
- valid = tracker_db_result_set_iter_next (result_set);
- }
- g_object_unref (result_set);
- }
-
- g_array_free (hits, TRUE);
- g_string_free (sql, TRUE);
-
- return counts;
-}
diff --git a/src/libtracker-data/tracker-query-tree.h b/src/libtracker-data/tracker-query-tree.h
deleted file mode 100644
index 58442af..0000000
--- a/src/libtracker-data/tracker-query-tree.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2008, Nokia
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef __TRACKERD_QUERY_TREE_H__
-#define __TRACKERD_QUERY_TREE_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-#include <glib-object.h>
-
-#include <libtracker-common/tracker-config.h>
-#include <libtracker-common/tracker-language.h>
-
-#define TRACKER_TYPE_QUERY_TREE (tracker_query_tree_get_type())
-#define TRACKER_QUERY_TREE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_QUERY_TREE, TrackerQueryTree))
-#define TRACKER_QUERY_TREE_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_QUERY_TREE, TrackerQueryTreeClass))
-#define TRACKER_IS_QUERY_TREE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_QUERY_TREE))
-#define TRACKER_IS_QUERY_TREE_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_QUERY_TREE))
-#define TRACKER_QUERY_TREE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_QUERY_TREE, TrackerQueryTreeClass))
-
-typedef struct TrackerQueryTree TrackerQueryTree;
-typedef struct TrackerQueryTreeClass TrackerQueryTreeClass;
-typedef struct TrackerHitCount TrackerHitCount;
-
-struct TrackerQueryTree {
- GObject parent;
-};
-
-struct TrackerQueryTreeClass {
- GObjectClass parent_class;
-};
-
-struct TrackerHitCount {
- TrackerClass *class;
- guint count;
-};
-
-GType tracker_query_tree_get_type (void);
-TrackerQueryTree * tracker_query_tree_new (const gchar *query_str,
- TrackerConfig *config,
- TrackerLanguage *language);
-G_CONST_RETURN gchar *tracker_query_tree_get_query (TrackerQueryTree *tree);
-void tracker_query_tree_set_query (TrackerQueryTree *tree,
- const gchar *query_str);
-
-GSList * tracker_query_tree_get_words (TrackerQueryTree *tree);
-GArray * tracker_query_tree_get_hits (TrackerQueryTree *tree,
- guint offset,
- guint limit);
-gint tracker_query_tree_get_hit_count (TrackerQueryTree *tree);
-GArray * tracker_query_tree_get_hit_counts (TrackerQueryTree *tree);
-
-G_END_DECLS
-
-#endif /* __TRACKERD_QUERY_TREE_H__ */
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index c714eda..a237127 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -681,26 +681,9 @@ public class Tracker.SparqlQuery : Object {
pattern_sql.append (binding.sql_db_column_name);
pattern_sql.append ("\"");
if (binding.is_fts_match) {
-#if HAVE_SQLITE_FTS
// parameters do not work with fts MATCH
string escaped_literal = string.joinv ("''", binding.literal.split ("'"));
pattern_sql.append_printf (" IN (SELECT rowid FROM fts WHERE fts MATCH '%s')", escaped_literal);
-#else
- pattern_sql.append (" IN (");
-
- // include matches from fulltext search
- first = true;
- foreach (int match_id in Data.search_get_matches (binding.literal)) {
- if (!first) {
- pattern_sql.append (",");
- } else {
- first = false;
- }
- pattern_sql.append_printf ("%d", match_id);
- }
-
- pattern_sql.append (")");
-#endif
} else {
pattern_sql.append (" = ");
if (binding.is_uri) {
diff --git a/src/libtracker-db/Makefile.am b/src/libtracker-db/Makefile.am
index 02f2302..22e133f 100644
--- a/src/libtracker-db/Makefile.am
+++ b/src/libtracker-db/Makefile.am
@@ -10,8 +10,7 @@ INCLUDES = \
$(GLIB2_CFLAGS) \
$(GCOV_CFLAGS) \
$(DBUS_CFLAGS) \
- $(SQLITE3_CFLAGS) \
- $(QDBM_CFLAGS)
+ $(SQLITE3_CFLAGS)
libtracker_dbdir = $(libdir)/tracker-$(TRACKER_API_VERSION)
libtracker_db_LTLIBRARIES = libtracker-db.la
@@ -32,25 +31,12 @@ noinst_HEADERS = \
tracker-db-interface-sqlite.h \
tracker-db-manager.h
-if !ENABLE_SQLITE_FTS
-libtracker_db_la_SOURCES += \
- tracker-db-index.c \
- tracker-db-index-item.c \
- tracker-db-index-manager.c
-
-noinst_HEADERS += \
- tracker-db-index.h \
- tracker-db-index-item.h \
- tracker-db-index-manager.h
-endif
-
libtracker_db_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
libtracker_db_la_LIBADD = \
$(top_builddir)/src/libtracker-common/libtracker-common.la \
$(SQLITE3_LIBS) \
- $(QDBM_LIBS) \
$(DBUS_LIBS) \
$(GCOV_LIBS) \
$(GLIB2_LIBS) \
diff --git a/src/libtracker-db/tracker-db-index-item.c b/src/libtracker-db/tracker-db-index-item.c
deleted file mode 100644
index b4467e8..0000000
--- a/src/libtracker-db/tracker-db-index-item.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2008, Nokia
-
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "tracker-db-index-item.h"
-
-gint
-tracker_db_index_item_get_score (TrackerDBIndexItem *item)
-{
- g_return_val_if_fail (item != NULL, 0);
-
- return item->score;
-}
-
-guint32
-tracker_db_index_item_get_id (TrackerDBIndexItem *item)
-{
- g_return_val_if_fail (item != NULL, 0);
-
- return item->id;
-}
diff --git a/src/libtracker-db/tracker-db-index-item.h b/src/libtracker-db/tracker-db-index-item.h
deleted file mode 100644
index a62cea1..0000000
--- a/src/libtracker-db/tracker-db-index-item.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2008, Nokia
-
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef __TRACKER_DB_INDEX_ITEM_H__
-#define __TRACKER_DB_INDEX_ITEM_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-typedef struct {
- /* Service ID number of the document */
- guint32 id;
-
- /* Score of the word in the document's metadata.
- */
- gint score;
-} TrackerDBIndexItem;
-
-typedef struct {
- guint32 service_id; /* Service ID of the document */
- guint32 score; /* Ranking score */
-} TrackerDBIndexItemRank;
-
-gint tracker_db_index_item_get_score (TrackerDBIndexItem *details);
-guint32 tracker_db_index_item_get_id (TrackerDBIndexItem *details);
-
-G_END_DECLS
-
-#endif /* __TRACKER_DB_INDEX_ITEM_H__ */
diff --git a/src/libtracker-db/tracker-db-index-manager.c b/src/libtracker-db/tracker-db-index-manager.c
deleted file mode 100644
index 6eadeb9..0000000
--- a/src/libtracker-db/tracker-db-index-manager.c
+++ /dev/null
@@ -1,309 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2008, Nokia
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include <stdio.h>
-
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gio/gio.h>
-
-#include <libtracker-common/tracker-file-utils.h>
-#include <libtracker-common/tracker-ontology.h>
-
-#include "tracker-db-index-manager.h"
-
-#define MIN_BUCKET_DEFAULT 10
-#define MAX_BUCKET_DEFAULT 20
-
-#define MAX_INDEX_FILE_SIZE 2000000000
-
-typedef struct {
- TrackerDBIndexType type;
- TrackerDBIndex *index;
- const gchar *file;
- const gchar *name;
- gchar *abs_filename;
-} TrackerDBIndexDefinition;
-
-static gboolean initialized;
-static gchar *data_dir;
-
-static TrackerDBIndexDefinition indexes[] = {
- { TRACKER_DB_INDEX_UNKNOWN,
- NULL,
- NULL,
- NULL,
- NULL },
- { TRACKER_DB_INDEX_RESOURCES,
- NULL,
- "index.db",
- "index",
- NULL }
-};
-
-static gboolean
-has_tmp_merge_files (TrackerDBIndexType type)
-{
- GFile *file;
- GFileEnumerator *enumerator;
- GFileInfo *info;
- GError *error = NULL;
- gchar *prefix;
- gchar *dirname;
- gboolean found;
-
- if (type == TRACKER_DB_INDEX_UNKNOWN) {
- return FALSE;
- }
-
- prefix = g_strconcat (indexes[type].name, ".tmp", NULL);
-
- dirname = g_path_get_dirname (indexes[type].abs_filename);
- file = g_file_new_for_path (dirname);
-
- enumerator = g_file_enumerate_children (file,
- G_FILE_ATTRIBUTE_STANDARD_NAME ","
- G_FILE_ATTRIBUTE_STANDARD_TYPE,
- G_PRIORITY_DEFAULT,
- NULL,
- &error);
-
- if (error) {
- g_warning ("Could not check for temporary index files in "
- "directory:'%s', %s",
- dirname,
- error->message);
-
- g_error_free (error);
- g_object_unref (file);
- g_free (dirname);
- g_free (prefix);
-
- return FALSE;
- }
-
- found = FALSE;
-
- for (info = g_file_enumerator_next_file (enumerator, NULL, &error);
- info && !error && !found;
- info = g_file_enumerator_next_file (enumerator, NULL, &error)) {
- /* Check each file has or hasn't got the prefix */
- if (g_str_has_prefix (g_file_info_get_name (info), prefix)) {
- found = TRUE;
- }
-
- g_object_unref (info);
- }
-
- if (error) {
- g_warning ("Could not get file information for temporary "
- "index files, %s",
- error->message);
- g_error_free (error);
- }
-
- g_object_unref (enumerator);
- g_object_unref (file);
- g_free (dirname);
- g_free (prefix);
-
- return found;
-}
-
-gboolean
-tracker_db_index_manager_init (TrackerDBIndexManagerFlags flags,
- gint min_bucket,
- gint max_bucket)
-{
- gchar *final_index_filename;
- gchar *name;
- gboolean need_reindex = FALSE;
- gboolean force_reindex;
- gboolean readonly;
- guint i;
-
- g_return_val_if_fail (min_bucket >= 0, FALSE);
- g_return_val_if_fail (max_bucket >= min_bucket, FALSE);
-
- if (initialized) {
- return TRUE;
- }
-
- g_message ("Setting index database locations");
-
- data_dir = g_build_filename (g_get_user_cache_dir (),
- "tracker",
- NULL);
-
- g_message ("Checking index directories exist");
-
- g_mkdir_with_parents (data_dir, 00755);
-
- g_message ("Checking index files exist");
-
- for (i = 1; i < G_N_ELEMENTS (indexes); i++) {
- indexes[i].abs_filename = g_build_filename (data_dir, indexes[i].file, NULL);
-
- if (need_reindex) {
- continue;
- }
-
- if (!g_file_test (indexes[i].abs_filename, G_FILE_TEST_EXISTS)) {
- g_message ("Could not find index file:'%s'", indexes[i].abs_filename);
- }
- }
-
- /* If we are just initializing to remove the databases,
- * return here.
- */
- if ((flags & TRACKER_DB_INDEX_MANAGER_REMOVE_ALL) != 0) {
- initialized = TRUE;
- return TRUE;
- }
-
- g_message ("Merging old temporary indexes");
-
- i = TRACKER_DB_INDEX_RESOURCES;
- name = g_strconcat (indexes[i].name, "-final", NULL);
- final_index_filename = g_build_filename (data_dir, name, NULL);
- g_free (name);
-
- if (g_file_test (final_index_filename, G_FILE_TEST_EXISTS) &&
- !has_tmp_merge_files (i)) {
- g_message (" Overwriting '%s' with '%s'",
- indexes[i].abs_filename,
- final_index_filename);
-
- g_rename (final_index_filename, indexes[i].abs_filename);
- }
-
- g_free (final_index_filename);
-
- /* Now we have cleaned up merge files, see if we are supposed
- * to be reindexing.
- */
-
- force_reindex = (flags & TRACKER_DB_INDEX_MANAGER_FORCE_REINDEX) != 0;
-
- if (force_reindex || need_reindex) {
- g_message ("Cleaning up index files for reindex");
-
- for (i = 1; i < G_N_ELEMENTS (indexes); i++) {
- g_unlink (indexes[i].abs_filename);
- }
- }
-
- g_message ("Creating index files, this may take a few moments...");
-
- readonly = (flags & TRACKER_DB_INDEX_MANAGER_READONLY) != 0;
-
- for (i = 1; i < G_N_ELEMENTS (indexes); i++) {
- indexes[i].index = tracker_db_index_new (indexes[i].abs_filename,
- min_bucket,
- max_bucket,
- readonly);
- }
-
- initialized = TRUE;
-
- return TRUE;
-}
-
-void
-tracker_db_index_manager_shutdown (void)
-{
- guint i;
-
- if (!initialized) {
- return;
- }
-
- for (i = 1; i < G_N_ELEMENTS (indexes); i++) {
- if (indexes[i].index) {
- g_object_unref (indexes[i].index);
- indexes[i].index = NULL;
- }
-
- g_free (indexes[i].abs_filename);
- indexes[i].abs_filename = NULL;
- }
-
- g_free (data_dir);
-
- initialized = FALSE;
-}
-
-void
-tracker_db_index_manager_remove_all (void)
-{
- guint i;
-
- g_message ("Removing all database index files");
-
- /* NOTE: We don't have to be initialized for this so we
- * calculate the absolute directories here.
- */
- for (i = 1; i < G_N_ELEMENTS (indexes); i++) {
- g_message (" Removing database index:'%s'",
- indexes[i].abs_filename);
- g_unlink (indexes[i].abs_filename);
- }
-}
-
-TrackerDBIndex *
-tracker_db_index_manager_get_index (TrackerDBIndexType type)
-{
- return indexes[type].index;
-}
-
-TrackerDBIndex *
-tracker_db_index_manager_get_index_by_service (const gchar *service)
-{
- g_return_val_if_fail (initialized == TRUE, NULL);
- g_return_val_if_fail (service != NULL, NULL);
-
- return indexes[TRACKER_DB_INDEX_RESOURCES].index;
-}
-
-const gchar *
-tracker_db_index_manager_get_filename (TrackerDBIndexType type)
-{
- return indexes[type].abs_filename;
-}
-
-gboolean
-tracker_db_index_manager_are_indexes_too_big (void)
-{
- gboolean too_big;
- guint i;
-
- g_return_val_if_fail (initialized == TRUE, FALSE);
-
- for (i = 1, too_big = FALSE; i < G_N_ELEMENTS (indexes) && !too_big; i++) {
- too_big = tracker_file_get_size (indexes[i].abs_filename) > MAX_INDEX_FILE_SIZE;
- }
-
- if (too_big) {
- g_critical ("One or more index files are too big, indexing disabled");
- return TRUE;
- }
-
- return FALSE;
-}
diff --git a/src/libtracker-db/tracker-db-index-manager.h b/src/libtracker-db/tracker-db-index-manager.h
deleted file mode 100644
index e899dcb..0000000
--- a/src/libtracker-db/tracker-db-index-manager.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
- * Copyright (C) 2008, Nokia
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef __TRACKERD_INDEX_MANAGER_H__
-#define __TRACKERD_INDEX_MANAGER_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-#include "tracker-db-index.h"
-
-typedef enum {
- TRACKER_DB_INDEX_UNKNOWN,
- TRACKER_DB_INDEX_RESOURCES,
-} TrackerDBIndexType;
-
-typedef enum {
- TRACKER_DB_INDEX_MANAGER_FORCE_REINDEX = 1 << 1,
- TRACKER_DB_INDEX_MANAGER_READONLY = 1 << 2,
- TRACKER_DB_INDEX_MANAGER_REMOVE_ALL = 1 << 3
-} TrackerDBIndexManagerFlags;
-
-gboolean tracker_db_index_manager_init (TrackerDBIndexManagerFlags flags,
- gint min_bucket,
- gint max_bucket);
-void tracker_db_index_manager_shutdown (void);
-void tracker_db_index_manager_remove_all (void);
-TrackerDBIndex *tracker_db_index_manager_get_index (TrackerDBIndexType index);
-TrackerDBIndex *tracker_db_index_manager_get_index_by_service (const gchar *service);
-const gchar * tracker_db_index_manager_get_filename (TrackerDBIndexType index);
-gboolean tracker_db_index_manager_are_indexes_too_big (void);
-
-G_END_DECLS
-
-#endif /* __TRACKERD_INDEX_MANAGER_H__ */
diff --git a/src/libtracker-db/tracker-db-index.c b/src/libtracker-db/tracker-db-index.c
deleted file mode 100644
index 9d30720..0000000
--- a/src/libtracker-db/tracker-db-index.c
+++ /dev/null
@@ -1,1300 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
- * Copyright (C) 2008, Nokia
-
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-
-#include <string.h>
-
-#include <depot.h>
-
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <glib/gstdio.h>
-
-#include <libtracker-common/tracker-log.h>
-#include <libtracker-common/tracker-file-utils.h>
-
-#include <libtracker-db/tracker-db-manager.h>
-
-#include "tracker-db-index.h"
-
-/* Size of free block pool of inverted index */
-#define MAX_HIT_BUFFER 480000
-#define MAX_CACHE_DEPTH 2
-#define MAX_FLUSH_TIME 0.5 /* In fractions of a second */
-
-#define TRACKER_DB_INDEX_ERROR_DOMAIN "TrackerDBIndex"
-
-#define TRACKER_DB_INDEX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_DB_INDEX, TrackerDBIndexPrivate))
-
-typedef struct TrackerDBIndexPrivate TrackerDBIndexPrivate;
-
-struct TrackerDBIndexPrivate {
- /* From the daemon */
- DEPOT *index;
-
- guint min_bucket;
- guint max_bucket;
-
- guint reload : 1;
- guint readonly : 1;
- guint in_pause : 1;
- guint in_flush : 1;
- guint overloaded : 1;
-
- /* Internal caches */
- guint idle_flush_id;
- GList *cache_layers;
- GHashTable *cur_cache;
-
- /* From the indexer */
- gchar *filename;
- gint bucket_count;
-};
-
-static void tracker_db_index_finalize (GObject *object);
-static void tracker_db_index_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void tracker_db_index_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void free_cache_values (GArray *array);
-
-
-enum {
- PROP_0,
- PROP_FILENAME,
- PROP_MIN_BUCKET,
- PROP_MAX_BUCKET,
- PROP_RELOAD,
- PROP_READONLY,
- PROP_FLUSHING,
- PROP_OVERLOADED
-};
-
-enum {
- ERROR_RECEIVED,
- LAST_SIGNAL
-};
-
-static guint signals [LAST_SIGNAL] = { 0, };
-
-G_DEFINE_TYPE (TrackerDBIndex, tracker_db_index, G_TYPE_OBJECT)
-
-static void
-tracker_db_index_class_init (TrackerDBIndexClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = tracker_db_index_finalize;
- object_class->set_property = tracker_db_index_set_property;
- object_class->get_property = tracker_db_index_get_property;
-
- g_object_class_install_property (object_class,
- PROP_FILENAME,
- g_param_spec_string ("filename",
- "Filename",
- "Filename",
- NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
- g_object_class_install_property (object_class,
- PROP_MIN_BUCKET,
- g_param_spec_int ("min-bucket",
- "Minimum bucket",
- "Minimum bucket",
- 0,
- 1000000, /* FIXME MAX_GUINT ?? */
- 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_MAX_BUCKET,
- g_param_spec_int ("max-bucket",
- "Maximum bucket",
- "Maximum bucket",
- 0,
- 1000000, /* FIXME MAX_GUINT ?? */
- 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_RELOAD,
- g_param_spec_boolean ("reload",
- "Reload the index file before read",
- "Reload the index file before read",
- TRUE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT));
-
- g_object_class_install_property (object_class,
- PROP_READONLY,
- g_param_spec_boolean ("readonly",
- "Open the index for readonly purposes",
- "Open the index for readonly purposes",
- TRUE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT));
-
- g_object_class_install_property (object_class,
- PROP_FLUSHING,
- g_param_spec_boolean ("flushing",
- "Whether the index is currently being flushed",
- "Whether the index is currently being flushed",
- FALSE,
- G_PARAM_READABLE));
- g_object_class_install_property (object_class,
- PROP_OVERLOADED,
- g_param_spec_boolean ("overloaded",
- "Whether the index cache is overloaded",
- "Whether the index cache is overloaded",
- FALSE,
- G_PARAM_READABLE));
- signals[ERROR_RECEIVED] =
- g_signal_new ("error-received",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (TrackerDBIndexClass, error_received),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
-
- g_type_class_add_private (object_class, sizeof (TrackerDBIndexPrivate));
-}
-
-static GHashTable *
-index_cache_new (void)
-{
- return g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) free_cache_values);
-}
-
-static void
-tracker_db_index_init (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- priv->reload = TRUE;
-}
-
-static void
-tracker_db_index_finalize (GObject *object)
-{
- TrackerDBIndex *indez;
- TrackerDBIndexPrivate *priv;
-
- indez = TRACKER_DB_INDEX (object);
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- tracker_db_index_flush_sync (indez);
- tracker_db_index_close (indez);
-
- if (priv->idle_flush_id) {
- g_source_remove (priv->idle_flush_id);
- priv->idle_flush_id = 0;
- }
-
- g_list_foreach (priv->cache_layers, (GFunc) g_hash_table_destroy, NULL);
- g_list_free (priv->cache_layers);
-
- if (priv->cur_cache) {
- g_hash_table_destroy (priv->cur_cache);
- }
-
- g_free (priv->filename);
-
- G_OBJECT_CLASS (tracker_db_index_parent_class)->finalize (object);
-}
-
-static void
-tracker_db_index_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- switch (prop_id) {
- case PROP_FILENAME:
- tracker_db_index_set_filename (TRACKER_DB_INDEX (object),
- g_value_get_string (value));
- break;
- case PROP_MIN_BUCKET:
- tracker_db_index_set_min_bucket (TRACKER_DB_INDEX (object),
- g_value_get_int (value));
- break;
- case PROP_MAX_BUCKET:
- tracker_db_index_set_max_bucket (TRACKER_DB_INDEX (object),
- g_value_get_int (value));
- break;
- case PROP_RELOAD:
- tracker_db_index_set_reload (TRACKER_DB_INDEX (object),
- g_value_get_boolean (value));
- break;
- case PROP_READONLY:
- tracker_db_index_set_readonly (TRACKER_DB_INDEX (object),
- g_value_get_boolean (value));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-tracker_db_index_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- TrackerDBIndexPrivate *priv;
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (object);
-
- switch (prop_id) {
- case PROP_FILENAME:
- g_value_set_string (value, priv->filename);
- break;
- case PROP_MIN_BUCKET:
- g_value_set_int (value, priv->min_bucket);
- break;
- case PROP_MAX_BUCKET:
- g_value_set_int (value, priv->max_bucket);
- break;
- case PROP_RELOAD:
- g_value_set_boolean (value, priv->reload);
- break;
- case PROP_READONLY:
- g_value_set_boolean (value, priv->readonly);
- break;
- case PROP_FLUSHING:
- g_value_set_boolean (value, priv->in_flush);
- break;
- case PROP_OVERLOADED:
- g_value_set_boolean (value, priv->overloaded);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
-static void
-free_cache_values (GArray *array)
-{
- g_array_free (array, TRUE);
-}
-
-TrackerDBIndex *
-tracker_db_index_new (const gchar *filename,
- gint min_bucket,
- gint max_bucket,
- gboolean readonly)
-{
- TrackerDBIndex *indez;
-
- g_return_val_if_fail (filename != NULL, NULL);
- g_return_val_if_fail (min_bucket > 0, NULL);
- g_return_val_if_fail (min_bucket < max_bucket, NULL);
-
- indez = g_object_new (TRACKER_TYPE_DB_INDEX,
- "filename", filename,
- "min-bucket", min_bucket,
- "max-bucket", max_bucket,
- "readonly", readonly,
- NULL);
-
- tracker_db_index_open (indez);
-
- return indez;
-}
-
-void
-tracker_db_index_set_filename (TrackerDBIndex *indez,
- const gchar *filename)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_if_fail (TRACKER_IS_DB_INDEX (indez));
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- if (priv->filename) {
- g_free (priv->filename);
- }
-
- priv->filename = g_strdup (filename);
-
- g_object_notify (G_OBJECT (indez), "filename");
-}
-
-void
-tracker_db_index_set_min_bucket (TrackerDBIndex *indez,
- gint min_bucket)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_if_fail (TRACKER_IS_DB_INDEX (indez));
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- priv->min_bucket = min_bucket;
-
- g_object_notify (G_OBJECT (indez), "min-bucket");
-}
-
-void
-tracker_db_index_set_max_bucket (TrackerDBIndex *indez,
- gint max_bucket)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_if_fail (TRACKER_IS_DB_INDEX (indez));
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- priv->max_bucket = max_bucket;
-
- g_object_notify (G_OBJECT (indez), "max-bucket");
-}
-
-void
-tracker_db_index_set_reload (TrackerDBIndex *indez,
- gboolean reload)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_if_fail (TRACKER_IS_DB_INDEX (indez));
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- priv->reload = reload;
-
- g_object_notify (G_OBJECT (indez), "reload");
-}
-
-void
-tracker_db_index_set_readonly (TrackerDBIndex *indez,
- gboolean readonly)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_if_fail (TRACKER_IS_DB_INDEX (indez));
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- priv->readonly = readonly;
-
- g_object_notify (G_OBJECT (indez), "readonly");
-}
-
-gboolean
-tracker_db_index_get_reload (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (indez), FALSE);
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- return priv->reload;
-}
-
-gboolean
-tracker_db_index_get_readonly (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (indez), TRUE);
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- return priv->readonly;
-}
-
-static inline gboolean
-has_word (TrackerDBIndex *indez,
- const gchar *word)
-{
- TrackerDBIndexPrivate *priv;
- gchar buffer[32];
- gint count;
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- count = dpgetwb (priv->index, word, -1, 0, 32, buffer);
-
- return count > 7;
-}
-
-static inline gint
-count_hit_size_for_word (TrackerDBIndex *indez,
- const gchar *word)
-{
- TrackerDBIndexPrivate *priv;
- gint tsiz;
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- tsiz = dpvsiz (priv->index, word, -1);
-
- return tsiz;
-}
-
-/* int levenshtein ()
- * Original license: GNU Lesser Public License
- * from the Dixit project, (http://dixit.sourceforge.net/)
- * Author: Octavian Procopiuc <oprocopiuc gmail com>
- * Created: July 25, 2004
- * Copied into tracker, by Edward Duffy
- */
-static gint
-levenshtein (const gchar *source,
- gchar *target,
- gint maxdist)
-{
- gchar n, m;
- gint l;
- gchar mincolval;
- gchar matrix[51][51];
- gchar j;
- gchar i;
- gchar cell;
-
- l = strlen (source);
- if (l > 50)
- return -1;
- n = l;
-
- l = strlen (target);
- if (l > 50)
- return -1;
- m = l;
-
- if (maxdist == 0)
- maxdist = MAX(m, n);
- if (n == 0)
- return MIN(m, maxdist);
- if (m == 0)
- return MIN(n, maxdist);
-
- /* Store the min. value on each column, so that, if it
- * reaches. maxdist, we break early.
- */
- for (j = 0; j <= m; j++)
- matrix[0][(gint)j] = j;
-
- for (i = 1; i <= n; i++) {
- gchar s_i;
-
- mincolval = MAX(m, i);
- matrix[(gint)i][0] = i;
-
- s_i = source[i-1];
-
- for (j = 1; j <= m; j++) {
- gchar t_j = target[j-1];
- gchar cost = (s_i == t_j ? 0 : 1);
- gchar above = matrix[i-1][(gint)j];
- gchar left = matrix[(gint)i][j-1];
- gchar diag = matrix[i-1][j-1];
-
- cell = MIN(above + 1, MIN(left + 1, diag + cost));
-
- /* Cover transposition, in addition to deletion,
- * insertion and substitution. This step is taken from:
- * Berghel, Hal ; Roach, David : "An Extension of Ukkonen's
- * Enhanced Dynamic Programming ASM Algorithm"
- * (http://www.acm.org/~hlb/publications/asm/asm.html)
- */
- if (i > 2 && j > 2) {
- gchar trans = matrix[i-2][j-2] + 1;
-
- if (source[i-2] != t_j)
- trans++;
- if (s_i != target[j-2])
- trans++;
- if (cell > trans)
- cell = trans;
- }
-
- mincolval = MIN(mincolval, cell);
- matrix[(gint)i][(gint)j] = cell;
- }
-
- if (mincolval >= maxdist)
- break;
- }
-
- if (i == n + 1) {
- return (gint) matrix[(gint)n][(gint)m];
- } else {
- return maxdist;
- }
-}
-
-static gint
-count_hits_for_word (TrackerDBIndex *indez,
- const gchar *str)
-{
-
- gint tsiz;
- gint hits = 0;
-
- tsiz = count_hit_size_for_word (indez, str);
-
- if (tsiz == -1 ||
- tsiz % sizeof (TrackerDBIndexItem) != 0) {
- return -1;
- }
-
- hits = tsiz / sizeof (TrackerDBIndexItem);
-
- return hits;
-}
-
-static gboolean
-check_index_is_up_to_date (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (indez), FALSE);
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- if (priv->reload) {
- g_message ("Reloading index:'%s'", priv->filename);
- tracker_db_index_close (indez);
- }
-
- if (!priv->index) {
- tracker_db_index_open (indez);
- }
-
- return !priv->reload;
-}
-
-static void
-update_overloaded_status (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
- gboolean overloaded;
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- overloaded = g_list_length (priv->cache_layers) > MAX_CACHE_DEPTH;
-
- if (priv->overloaded != overloaded) {
- priv->overloaded = overloaded;
- g_object_notify (G_OBJECT (indez), "overloaded");
- }
-}
-
-static void
-emit_error_received (TrackerDBIndex *indez,
- const gchar *error_str)
-{
- GQuark domain;
- GError *error;
-
- domain = g_quark_from_static_string (TRACKER_DB_INDEX_ERROR_DOMAIN);
-
- error = g_error_new_literal (domain, 0, error_str);
- g_signal_emit (indez, signals[ERROR_RECEIVED], 0, error);
- g_error_free (error);
-}
-
-/* Use for deletes or updates of multiple entities when they are not
- * new.
- */
-static gboolean
-indexer_update_word (const gchar *word,
- GArray *new_hits,
- DEPOT *indez)
-{
- TrackerDBIndexItem *new_hit;
- TrackerDBIndexItem *previous_hits;
- GArray *pending_hits;
- gboolean write_back;
- gboolean edited;
- gboolean result;
- gint old_hit_count;
- gint score;
- gint tsiz;
- guint j;
-
- g_return_val_if_fail (indez != NULL, FALSE);
- g_return_val_if_fail (word != NULL, FALSE);
- g_return_val_if_fail (new_hits != NULL, FALSE);
-
- write_back = FALSE;
- edited = FALSE;
- old_hit_count = 0;
- pending_hits = NULL;
-
- previous_hits = (TrackerDBIndexItem *) dpget (indez,
- word,
- -1,
- 0,
- MAX_HIT_BUFFER,
- &tsiz);
-
- /* New word in the index */
- if (previous_hits == NULL) {
- pending_hits = g_array_new (FALSE, TRUE, sizeof (TrackerDBIndexItem));
- result = TRUE;
-
- /* Ensure weights are correct before inserting */
- for (j = 0; j < new_hits->len; j++) {
- new_hit = &g_array_index (new_hits, TrackerDBIndexItem, j);
- score = tracker_db_index_item_get_score (new_hit);
-
- if (score > 0) {
- g_array_append_val (pending_hits, *new_hit);
- }
- }
-
- if (pending_hits->len > 0) {
- result = dpput (indez,
- word, -1,
- (char *) pending_hits->data,
- pending_hits->len * sizeof (TrackerDBIndexItem),
- DP_DOVER);
-
- if (!result) {
- g_warning ("Could not store word '%s': %s", word, dperrmsg (dpecode));
- }
- }
-
- g_array_free (pending_hits, TRUE);
-
- return result;
- }
-
- /* Word already exists */
- old_hit_count = tsiz / sizeof (TrackerDBIndexItem);
-
- for (j = 0; j < new_hits->len; j++) {
- gint left, right, center;
-
- new_hit = &g_array_index (new_hits, TrackerDBIndexItem, j);
- edited = FALSE;
-
- left = 0;
- right = old_hit_count - 1;
- center = (right - left) / 2;
-
- /* New items are going to have always a higher service ID,
- * so the insertion is sorted, perform a binary search.
- */
-
- do {
- center += left;
-
- if (new_hit->id > previous_hits[center].id) {
- left = center + 1;
- } else if (new_hit->id < previous_hits[center].id) {
- right = center - 1;
- } else if (new_hit->id == previous_hits[center].id) {
- write_back = TRUE;
-
- /* NB the paramter score can be negative */
- score = tracker_db_index_item_get_score (&previous_hits[center]);
- score += tracker_db_index_item_get_score (new_hit);
-
-
- /* Check for deletion */
- if (score < 1) {
- /* Shift all subsequent records in array down one place */
- g_memmove (&previous_hits[center], &previous_hits[center + 1],
- (old_hit_count - center - 1) * sizeof (TrackerDBIndexItem));
- old_hit_count--;
- } else {
- previous_hits[center].score = score;
- }
-
- edited = TRUE;
- break;
- }
-
- center = (right - left) / 2;
- } while (left <= right);
-
- /* Add hits that could not be updated directly here so
- * they can be appended later
- */
- if (!edited) {
- if (!pending_hits) {
- pending_hits = g_array_new (FALSE,
- TRUE,
- sizeof (TrackerDBIndexItem));
- }
-
- g_array_append_val (pending_hits, *new_hit);
- }
- }
-
- /* Write back if we have modded anything */
- if (write_back) {
- /* If the word has no hits, remove it! Otherwise
- * overwrite the value with the new hits array
- */
- if (old_hit_count < 1) {
- result = dpout (indez, word, -1);
- } else {
- result = dpput (indez,
- word, -1,
- (char *) previous_hits,
- old_hit_count * sizeof (TrackerDBIndexItem),
- DP_DOVER);
- }
-
- if (!result) {
- g_warning ("Could not modify word '%s': %s", word, dperrmsg (dpecode));
- }
- }
-
- /* Append new occurences */
- if (pending_hits) {
- result = dpput (indez,
- word, -1,
- (char*) pending_hits->data,
- pending_hits->len * sizeof (TrackerDBIndexItem),
- DP_DCAT);
- g_array_free (pending_hits, TRUE);
-
- if (!result) {
- g_warning ("Could not insert pending word '%s': %s", word, dperrmsg (dpecode));
- }
- }
-
- g_free (previous_hits);
-
- return TRUE;
-}
-
-static void
-set_in_flush (TrackerDBIndex *indez,
- gboolean in_flush)
-{
- TrackerDBIndexPrivate *priv;
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- if (in_flush != priv->in_flush) {
- priv->in_flush = in_flush;
- g_object_notify (G_OBJECT (indez), "flushing");
- }
-}
-
-static gboolean
-index_flush_item (gpointer user_data)
-{
- TrackerDBIndex *indez;
- TrackerDBIndexPrivate *priv;
- GHashTableIter iter;
- gpointer key, value;
-
- indez = TRACKER_DB_INDEX (user_data);
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- if (priv->in_pause || !priv->index) {
- g_debug ("Flushing was paused or index was closed, waiting...");
- priv->idle_flush_id = 0;
- return FALSE;
- }
-
- if (priv->cache_layers && g_hash_table_size (priv->cache_layers->data) > 0) {
- GTimer *timer;
-
- timer = g_timer_new ();
- g_hash_table_iter_init (&iter, (GHashTable *) priv->cache_layers->data);
-
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- /* Process words from cache */
- if (indexer_update_word (key, value, priv->index)) {
- g_hash_table_iter_remove (&iter);
- } else {
- emit_error_received (indez, _("Index corrupted"));
- break;
- }
-
- if (g_timer_elapsed (timer, NULL) > MAX_FLUSH_TIME) {
- break;
- }
- }
-
- g_timer_destroy (timer);
-
- return TRUE;
- } else {
- GList *link;
-
- if (priv->cache_layers) {
- /* Current cache being flushed is already empty, proceed with the next one */
- link = priv->cache_layers;
- priv->cache_layers = g_list_remove_link (priv->cache_layers, link);
- g_hash_table_destroy (link->data);
- g_list_free_1 (link);
-
- update_overloaded_status (indez);
- }
-
- if (priv->cache_layers) {
- g_debug ("Flushing next batch (%d words) to index...",
- g_hash_table_size (priv->cache_layers->data));
- return TRUE;
- } else {
- g_debug ("Finished flushing elements to index");
-
- set_in_flush (indez, FALSE);
- priv->idle_flush_id = 0;
-
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-static void
-init_flush (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- if (priv->in_pause) {
- g_debug ("Index was paused, waiting for it being resumed...");
- return;
- }
-
- if (!priv->index) {
- g_debug ("Index was not open for flush, waiting...");
- return;
- }
-
- if (priv->idle_flush_id == 0) {
- priv->idle_flush_id = g_idle_add (index_flush_item, indez);
- }
-}
-
-gboolean
-tracker_db_index_open (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
- gint flags;
- gint bucket_count;
- gint rec_count;
-
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (indez), FALSE);
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- g_return_val_if_fail (priv->filename != NULL, FALSE);
-
- if (priv->index) {
- return TRUE;
- }
-
- g_debug ("Opening index:'%s' (%s)",
- priv->filename,
- priv->readonly ? "readonly" : "read/write");
-
- if (priv->readonly) {
- flags = DP_OREADER | DP_ONOLCK;
- } else {
- flags = DP_OWRITER | DP_OCREAT | DP_ONOLCK;
- }
-
- priv->index = dpopen (priv->filename,
- flags,
- priv->max_bucket);
-
- if (!priv->index) {
- if (!g_file_test (priv->filename, G_FILE_TEST_EXISTS)) {
- g_debug ("Index doesnt exists yet:'%s'",
- priv->filename);
- } else {
- g_debug ("Index was not closed properly:'%s', %s",
- priv->filename,
- dperrmsg (dpecode));
-
- if (dprepair (priv->filename)) {
- priv->index = dpopen (priv->filename,
- flags,
- priv->max_bucket);
- } else {
- g_critical ("Corrupted index file %s.",
- priv->filename);
- }
- }
- }
-
- if (priv->index) {
- dpsetalign (priv->index, 8);
-
- /* Reoptimize database if bucket count < rec count */
- bucket_count = dpbnum (priv->index);
- rec_count = dprnum (priv->index);
-
- g_debug ("Bucket count (max is %d) is %d and record count is %d",
- priv->max_bucket,
- bucket_count,
- rec_count);
-
- priv->reload = FALSE;
-
- if (priv->in_flush) {
- g_debug ("Resuming flushing...");
- init_flush (indez);
- }
- } else {
- priv->reload = TRUE;
- }
-
- return !priv->reload;
-}
-
-gboolean
-tracker_db_index_close (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
- gboolean retval;
-
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (indez), FALSE);
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- retval = TRUE;
-
- if (priv->index) {
- g_debug ("Closing index:'%s'", priv->filename);
-
- if (!dpclose (priv->index)) {
- g_message ("Could not close index, %s",
- dperrmsg (dpecode));
- retval = FALSE;
- }
-
- priv->index = NULL;
- }
-
- return retval;
-}
-
-void
-tracker_db_index_set_paused (TrackerDBIndex *indez,
- gboolean paused)
-{
- TrackerDBIndexPrivate *priv;
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- if (!priv->in_pause && paused) {
- priv->in_pause = paused;
- tracker_db_index_close (indez);
- } else if (priv->in_pause && !paused) {
- priv->in_pause = paused;
- tracker_db_index_open (indez);
- }
-}
-
-void
-tracker_db_index_flush (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_if_fail (TRACKER_IS_DB_INDEX (indez));
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- if (!priv->in_flush) {
- set_in_flush (indez, TRUE);
- }
-
- if (priv->cur_cache && g_hash_table_size (priv->cur_cache) > 0) {
- g_debug ("Pushing a new batch (%d words) to be flushed to index...",
- g_hash_table_size (priv->cur_cache));
-
- /* Put current cache into the queue and create a
- * new one for keeping appending words
- */
- priv->cache_layers = g_list_append (priv->cache_layers, priv->cur_cache);
- priv->cur_cache = index_cache_new ();
-
- update_overloaded_status (indez);
- }
-
- init_flush (indez);
-}
-
-void
-tracker_db_index_flush_sync (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
- GList *cache;
-
- g_return_if_fail (TRACKER_IS_DB_INDEX (indez));
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- if (priv->idle_flush_id) {
- g_source_remove (priv->idle_flush_id);
- priv->idle_flush_id = 0;
- }
-
- set_in_flush (indez, TRUE);
-
- if (priv->cur_cache && g_hash_table_size (priv->cur_cache) > 0) {
- priv->cache_layers = g_list_append (priv->cache_layers, priv->cur_cache);
- priv->cur_cache = NULL;
- }
-
- for (cache = priv->cache_layers; cache; cache = cache->next) {
- g_hash_table_foreach_remove (cache->data,
- (GHRFunc) indexer_update_word,
- priv->index);
- }
-
- g_list_foreach (priv->cache_layers, (GFunc) g_hash_table_destroy, NULL);
- g_list_free (priv->cache_layers);
- priv->cache_layers = NULL;
-
- set_in_flush (indez, FALSE);
- update_overloaded_status (indez);
-}
-
-guint32
-tracker_db_index_get_size (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
- guint32 size;
-
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (indez), 0);
-
- if (!check_index_is_up_to_date (indez)) {
- return 0;
- }
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- size = dpfsiz (priv->index);
-
- return size;
-}
-
-gchar *
-tracker_db_index_get_suggestion (TrackerDBIndex *indez,
- const gchar *term,
- gint maxdist)
-{
- TrackerDBIndexPrivate *priv;
- gchar *str;
- gint dist;
- gchar *winner_str;
- gint winner_dist;
- gint hits;
- GTimeVal start, current;
-
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (indez), NULL);
- g_return_val_if_fail (term != NULL, NULL);
- g_return_val_if_fail (maxdist >= 0, NULL);
-
- if (!check_index_is_up_to_date (indez)) {
- return NULL;
- }
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- winner_str = g_strdup (term);
- winner_dist = G_MAXINT; /* Initialize to the worst case */
-
- dpiterinit (priv->index);
-
- g_get_current_time (&start);
-
- str = dpiternext (priv->index, NULL);
-
- while (str != NULL) {
- dist = levenshtein (term, str, 0);
-
- if (dist != -1 &&
- dist < maxdist &&
- dist < winner_dist) {
- hits = count_hits_for_word (indez, str);
-
- if (hits < 0) {
- g_free (winner_str);
- g_free (str);
-
- return NULL;
- } else if (hits > 0) {
- g_free (winner_str);
- winner_str = g_strdup (str);
- winner_dist = dist;
- } else {
- g_message ("No hits for:'%s'!", str);
- }
- }
-
- g_free (str);
-
- g_get_current_time (¤t);
-
- /* 2 second time out */
- if (current.tv_sec - start.tv_sec >= 2) {
- g_message ("Timed out in %s, not collecting more suggestions.",
- __FUNCTION__);
- break;
- }
-
- str = dpiternext (priv->index, NULL);
- }
-
- return winner_str;
-}
-
-TrackerDBIndexItem *
-tracker_db_index_get_word_hits (TrackerDBIndex *indez,
- const gchar *word,
- guint *count)
-{
- TrackerDBIndexPrivate *priv;
- TrackerDBIndexItem *details;
- gint tsiz;
- gchar *tmp;
-
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (indez), NULL);
- g_return_val_if_fail (word != NULL, NULL);
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- if (!check_index_is_up_to_date (indez)) {
- return NULL;
- }
-
- details = NULL;
-
- if (count) {
- *count = 0;
- }
-
- if ((tmp = dpget (priv->index, word, -1, 0, MAX_HIT_BUFFER, &tsiz)) != NULL) {
- if (tsiz >= sizeof (TrackerDBIndexItem)) {
- details = (TrackerDBIndexItem *) tmp;
-
- if (count) {
- *count = tsiz / sizeof (TrackerDBIndexItem);
- }
- }
- }
-
- return details;
-}
-
-void
-tracker_db_index_add_word (TrackerDBIndex *indez,
- const gchar *word,
- guint32 service_id,
- gint weight)
-{
- TrackerDBIndexPrivate *priv;
- TrackerDBIndexItem elem;
- TrackerDBIndexItem *current;
- GArray *array;
- guint i, new_score;
-
- g_return_if_fail (TRACKER_IS_DB_INDEX (indez));
- g_return_if_fail (word != NULL);
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- g_return_if_fail (priv->readonly == FALSE);
-
- if (G_UNLIKELY (!priv->cur_cache)) {
- priv->cur_cache = index_cache_new ();
- }
-
- elem.id = service_id;
- elem.score = weight;
-
- array = g_hash_table_lookup (priv->cur_cache, word);
-
- if (!array) {
- /* Create the array if it didn't exist (first time we
- * find the word)
- */
- array = g_array_new (FALSE, TRUE, sizeof (TrackerDBIndexItem));
- g_hash_table_insert (priv->cur_cache, g_strdup (word), array);
- g_array_append_val (array, elem);
-
- return;
- }
-
- /* It is not the first time we find the word */
- for (i = 0; i < array->len; i++) {
- current = &g_array_index (array, TrackerDBIndexItem, i);
-
- if (current->id == service_id) {
- /* The word was already found in the same
- * service_id (file), modify score
- */
- new_score = tracker_db_index_item_get_score (current) + weight;
- current->score = new_score;
-
- return;
- }
- }
-
- /* First time in the file */
- g_array_append_val (array, elem);
-}
-
-gboolean
-tracker_db_index_get_flushing (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (indez), FALSE);
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- return priv->in_flush;
-}
-
-gboolean
-tracker_db_index_get_overloaded (TrackerDBIndex *indez)
-{
- TrackerDBIndexPrivate *priv;
-
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (indez), FALSE);
-
- priv = TRACKER_DB_INDEX_GET_PRIVATE (indez);
-
- return priv->overloaded;
-}
-
diff --git a/src/libtracker-db/tracker-db-index.h b/src/libtracker-db/tracker-db-index.h
deleted file mode 100644
index 21882dc..0000000
--- a/src/libtracker-db/tracker-db-index.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
- * Copyright (C) 2008, Nokia
-
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef __TRACKER_DB_INDEX_H__
-#define __TRACKER_DB_INDEX_H__
-
-G_BEGIN_DECLS
-
-#include <glib-object.h>
-
-#include <libtracker-db/tracker-db-index-item.h>
-
-
-#define TRACKER_TYPE_DB_INDEX (tracker_db_index_get_type())
-#define TRACKER_DB_INDEX(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_DB_INDEX, TrackerDBIndex))
-#define TRACKER_DB_INDEX_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_DB_INDEX, TrackerDBIndexClass))
-#define TRACKER_IS_DB_INDEX(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_DB_INDEX))
-#define TRACKER_IS_DB_INDEX_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_DB_INDEX))
-#define TRACKER_DB_INDEX_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_DB_INDEX, TrackerDBIndexClass))
-
-typedef struct TrackerDBIndex TrackerDBIndex;
-typedef struct TrackerDBIndexClass TrackerDBIndexClass;
-typedef struct TrackerDBIndexWordDetails TrackerDBIndexWordDetails;
-
-struct TrackerDBIndex {
- GObject parent;
-};
-
-struct TrackerDBIndexClass {
- GObjectClass parent_class;
-
- void (* error_received) (TrackerDBIndex *indez,
- GError *error);
-};
-
-GType tracker_db_index_get_type (void);
-TrackerDBIndex * tracker_db_index_new (const gchar *filename,
- gint min_bucket,
- gint max_bucket,
- gboolean readonly);
-void tracker_db_index_set_filename (TrackerDBIndex *index,
- const gchar *filename);
-void tracker_db_index_set_min_bucket (TrackerDBIndex *index,
- gint min_bucket);
-void tracker_db_index_set_max_bucket (TrackerDBIndex *index,
- gint max_bucket);
-void tracker_db_index_set_reload (TrackerDBIndex *index,
- gboolean reload);
-void tracker_db_index_set_readonly (TrackerDBIndex *index,
- gboolean readonly);
-gboolean tracker_db_index_get_reload (TrackerDBIndex *index);
-gboolean tracker_db_index_get_readonly (TrackerDBIndex *index);
-
-void tracker_db_index_set_paused (TrackerDBIndex *index,
- gboolean paused);
-
-/* Open/Close/Flush */
-gboolean tracker_db_index_open (TrackerDBIndex *index);
-gboolean tracker_db_index_close (TrackerDBIndex *index);
-void tracker_db_index_flush (TrackerDBIndex *index);
-void tracker_db_index_flush_sync (TrackerDBIndex *index);
-
-/* Using the index */
-guint32 tracker_db_index_get_size (TrackerDBIndex *index);
-char * tracker_db_index_get_suggestion (TrackerDBIndex *index,
- const gchar *term,
- gint maxdist);
-TrackerDBIndexItem *tracker_db_index_get_word_hits (TrackerDBIndex *index,
- const gchar *word,
- guint *count);
-void tracker_db_index_add_word (TrackerDBIndex *index,
- const gchar *word,
- guint32 service_id,
- gint weight);
-gboolean tracker_db_index_get_flushing (TrackerDBIndex *indez);
-gboolean tracker_db_index_get_overloaded (TrackerDBIndex *indez);
-
-G_END_DECLS
-
-#endif /* __TRACKER_DB_INDEX_H__ */
diff --git a/src/libtracker-db/tracker-db-interface-sqlite.c b/src/libtracker-db/tracker-db-interface-sqlite.c
index c9c1419..2126c8b 100644
--- a/src/libtracker-db/tracker-db-interface-sqlite.c
+++ b/src/libtracker-db/tracker-db-interface-sqlite.c
@@ -126,7 +126,6 @@ tracker_db_interface_sqlite_constructor (GType type,
sqlite3_extended_result_codes (priv->db, 0);
sqlite3_busy_timeout (priv->db, 10000000);
-#ifdef HAVE_SQLITE_FTS
sqlite3_enable_load_extension (priv->db, 1);
sqlite3_load_extension (priv->db, PKGLIBDIR "/tracker-fts.so", NULL, &err_msg);
@@ -136,7 +135,6 @@ tracker_db_interface_sqlite_constructor (GType type,
} else {
g_message ("Loaded tracker fts extension");
}
-#endif
return object;
}
diff --git a/src/libtracker-db/tracker-db-manager.c b/src/libtracker-db/tracker-db-manager.c
index 5dc29c1..b6b83d6 100644
--- a/src/libtracker-db/tracker-db-manager.c
+++ b/src/libtracker-db/tracker-db-manager.c
@@ -1205,18 +1205,11 @@ tracker_db_manager_init (TrackerDBManagerFlags flags,
initialized = TRUE;
-#ifdef HAVE_SQLITE_FTS
resources_iface = tracker_db_manager_get_db_interfaces (4,
TRACKER_DB_METADATA,
TRACKER_DB_FULLTEXT,
TRACKER_DB_CONTENTS,
TRACKER_DB_COMMON);
-#else
- resources_iface = tracker_db_manager_get_db_interfaces (3,
- TRACKER_DB_METADATA,
- TRACKER_DB_CONTENTS,
- TRACKER_DB_COMMON);
-#endif
}
void
diff --git a/src/qdbm/Makefile.am b/src/qdbm/Makefile.am
deleted file mode 100644
index 9a673bf..0000000
--- a/src/qdbm/Makefile.am
+++ /dev/null
@@ -1,23 +0,0 @@
-include $(top_srcdir)/Makefile.decl
-
-INCLUDES = \
- -D_XOPEN_SOURCE_EXTENDED=1 \
- -D_GNU_SOURCE=1 \
- -D__EXTENSIONS__=1 \
- -D_HPUX_SOURCE=1 \
- -D_POSIX_MAPPED_FILES=1 \
- -D_POSIX_SYNCHRONIZED_IO=1 \
- -DPIC=1 \
- -D_THREAD_SAFE=1 \
- -D_REENTRANT=1 \
- -DNDEBUG \
- -DMYNOMMAP \
- $(GCOV_CFLAGS)
-
-noinst_LTLIBRARIES = libqdbm-private.la
-
-libqdbm_private_la_SOURCES = \
- depot.c \
- depot.h \
- myconf.c \
- myconf.h
diff --git a/src/qdbm/depot.c b/src/qdbm/depot.c
deleted file mode 100644
index e41fc97..0000000
--- a/src/qdbm/depot.c
+++ /dev/null
@@ -1,2227 +0,0 @@
-/*************************************************************************************************
- * Implementation of Depot
- * Copyright (C) 2000-2006 Mikio Hirabayashi
- * This file is part of QDBM, Quick Database Manager.
- * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU
- * Lesser General Public License as published by the Free Software Foundation; either version
- * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- * You should have received a copy of the GNU Lesser General Public License along with QDBM; if
- * not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *************************************************************************************************/
-
-
-#define QDBM_INTERNAL 1
-
-#include "depot.h"
-#include "myconf.h"
-
-#define DP_FILEMODE 00644 /* permission of a creating file */
-#define DP_MAGICNUMB "[DEPOT]\n\f" /* magic number on environments of big endian */
-#define DP_MAGICNUML "[depot]\n\f" /* magic number on environments of little endian */
-#define DP_HEADSIZ 48 /* size of the reagion of the header */
-#define DP_LIBVEROFF 12 /* offset of the region for the library version */
-#define DP_FLAGSOFF 16 /* offset of the region for flags */
-#define DP_FSIZOFF 24 /* offset of the region for the file size */
-#define DP_BNUMOFF 32 /* offset of the region for the bucket number */
-#define DP_RNUMOFF 40 /* offset of the region for the record number */
-#define DP_DEFBNUM 8191 /* default bucket number */
-#define DP_FBPOOLSIZ 16 /* size of free block pool */
-#define DP_ENTBUFSIZ 128 /* size of the entity buffer */
-#define DP_STKBUFSIZ 256 /* size of the stack key buffer */
-#define DP_WRTBUFSIZ 8192 /* size of the writing buffer */
-#define DP_FSBLKSIZ 4096 /* size of a block of the file system */
-#define DP_TMPFSUF MYEXTSTR "dptmp" /* suffix of a temporary file */
-#define DP_OPTBLOAD 0.25 /* ratio of bucket loading at optimization */
-#define DP_OPTRUNIT 256 /* number of records in a process of optimization */
-#define DP_NUMBUFSIZ 32 /* size of a buffer for a number */
-#define DP_IOBUFSIZ 8192 /* size of an I/O buffer */
-
-/* get the first hash value */
-#define DP_FIRSTHASH(DP_res, DP_kbuf, DP_ksiz) \
- do { \
- int _DP_i; \
- if((DP_ksiz) == sizeof(int)){ \
- memcpy(&(DP_res), (DP_kbuf), sizeof(int)); \
- } else { \
- (DP_res) = 751; \
- } \
- for(_DP_i = 0; _DP_i < (DP_ksiz); _DP_i++){ \
- (DP_res) = (DP_res) * 31 + ((const unsigned char *)(DP_kbuf))[_DP_i]; \
- } \
- (DP_res) = ((DP_res) * 87767623) & 0x7FFFFFFF; \
- } while(FALSE)
-
-/* get the second hash value */
-#define DP_SECONDHASH(DP_res, DP_kbuf, DP_ksiz) \
- do { \
- int _DP_i; \
- (DP_res) = 19780211; \
- for(_DP_i = (DP_ksiz) - 1; _DP_i >= 0; _DP_i--){ \
- (DP_res) = (DP_res) * 37 + ((const unsigned char *)(DP_kbuf))[_DP_i]; \
- } \
- (DP_res) = ((DP_res) * 43321879) & 0x7FFFFFFF; \
- } while(FALSE)
-
-/* get the third hash value */
-#define DP_THIRDHASH(DP_res, DP_kbuf, DP_ksiz) \
- do { \
- int _DP_i; \
- (DP_res) = 774831917; \
- for(_DP_i = (DP_ksiz) - 1; _DP_i >= 0; _DP_i--){ \
- (DP_res) = (DP_res) * 29 + ((const unsigned char *)(DP_kbuf))[_DP_i]; \
- } \
- (DP_res) = ((DP_res) * 5157883) & 0x7FFFFFFF; \
- } while(FALSE)
-
-enum { /* enumeration for a record header */
- DP_RHIFLAGS, /* offset of flags */
- DP_RHIHASH, /* offset of value of the second hash function */
- DP_RHIKSIZ, /* offset of the size of the key */
- DP_RHIVSIZ, /* offset of the size of the value */
- DP_RHIPSIZ, /* offset of the size of the padding bytes */
- DP_RHILEFT, /* offset of the offset of the left child */
- DP_RHIRIGHT, /* offset of the offset of the right child */
- DP_RHNUM /* number of elements of a header */
-};
-
-enum { /* enumeration for the flag of a record */
- DP_RECFDEL = 1 << 0, /* deleted */
- DP_RECFREUSE = 1 << 1 /* reusable */
-};
-
-
-/* private function prototypes */
-static int dpbigendian(void);
-static char *dpstrdup(const char *str);
-static int dplock(int fd, int ex, int nb);
-static int dpwrite(int fd, const void *buf, int size);
-static int dpseekwrite(int fd, int off, const void *buf, int size);
-static int dpseekwritenum(int fd, int off, int num);
-static int dpread(int fd, void *buf, int size);
-static int dpseekread(int fd, int off, void *buf, int size);
-static int dpfcopy(int destfd, int destoff, int srcfd, int srcoff);
-static int dpgetprime(int num);
-static int dppadsize(DEPOT *depot, int ksiz, int vsiz);
-static int dprecsize(int *head);
-static int dprechead(DEPOT *depot, int off, int *head, char *ebuf, int *eep);
-static char *dpreckey(DEPOT *depot, int off, int *head);
-static char *dprecval(DEPOT *depot, int off, int *head, int start, int max);
-static int dprecvalwb(DEPOT *depot, int off, int *head, int start, int max, char *vbuf);
-static int dpkeycmp(const char *abuf, int asiz, const char *bbuf, int bsiz);
-static int dprecsearch(DEPOT *depot, const char *kbuf, int ksiz, int hash, int *bip, int *offp,
- int *entp, int *head, char *ebuf, int *eep, int delhit);
-static int dprecrewrite(DEPOT *depot, int off, int rsiz, const char *kbuf, int ksiz,
- const char *vbuf, int vsiz, int hash, int left, int right);
-static int dprecappend(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- int hash, int left, int right);
-static int dprecover(DEPOT *depot, int off, int *head, const char *vbuf, int vsiz, int cat);
-static int dprecdelete(DEPOT *depot, int off, int *head, int reusable);
-static void dpfbpoolcoal(DEPOT *depot);
-static int dpfbpoolcmp(const void *a, const void *b);
-
-
-
-/*************************************************************************************************
- * public objects
- *************************************************************************************************/
-
-
-/* String containing the version information. */
-const char *dpversion = _QDBM_VERSION;
-
-
-/* Get a message string corresponding to an error code. */
-const char *dperrmsg(int ecode){
- switch(ecode){
- case DP_ENOERR: return "no error";
- case DP_EFATAL: return "with fatal error";
- case DP_EMODE: return "invalid mode";
- case DP_EBROKEN: return "broken database file";
- case DP_EKEEP: return "existing record";
- case DP_ENOITEM: return "no item found";
- case DP_EALLOC: return "memory allocation error";
- case DP_EMAP: return "memory mapping error";
- case DP_EOPEN: return "open error";
- case DP_ECLOSE: return "close error";
- case DP_ETRUNC: return "trunc error";
- case DP_ESYNC: return "sync error";
- case DP_ESTAT: return "stat error";
- case DP_ESEEK: return "seek error";
- case DP_EREAD: return "read error";
- case DP_EWRITE: return "write error";
- case DP_ELOCK: return "lock error";
- case DP_EUNLINK: return "unlink error";
- case DP_EMKDIR: return "mkdir error";
- case DP_ERMDIR: return "rmdir error";
- case DP_EMISC: return "miscellaneous error";
- }
- return "(invalid ecode)";
-}
-
-
-/* Get a database handle. */
-DEPOT *dpopen(const char *name, int omode, int bnum){
- char hbuf[DP_HEADSIZ], *map, c, *tname;
- int i, mode, fd, inode, fsiz, rnum, msiz, *fbpool;
- struct stat sbuf;
- time_t mtime;
- DEPOT *depot;
- assert(name);
- mode = O_RDONLY;
- if(omode & DP_OWRITER){
- mode = O_RDWR;
- if(omode & DP_OCREAT) mode |= O_CREAT;
- }
-
-#if defined(__linux__)
-
- fd = open(name, mode|O_NOATIME, DP_FILEMODE);
-
- if (fd == -1) {
- fd = open(name, mode, DP_FILEMODE);
- }
-#else
- fd = open(name, mode, DP_FILEMODE);
-#endif
-
- if(fd == -1){
- dpecodeset(DP_EOPEN, __FILE__, __LINE__);
- return NULL;
- }
- if(!(omode & DP_ONOLCK)){
- if(!dplock(fd, omode & DP_OWRITER, omode & DP_OLCKNB)){
- close(fd);
- return NULL;
- }
- }
- if((omode & DP_OWRITER) && (omode & DP_OTRUNC)){
- if(ftruncate(fd, 0) == -1){
- close(fd);
- dpecodeset(DP_ETRUNC, __FILE__, __LINE__);
- return NULL;
- }
- }
- if(fstat(fd, &sbuf) == -1 || !S_ISREG(sbuf.st_mode) ||
- (sbuf.st_ino == 0 && lstat(name, &sbuf) == -1)){
- close(fd);
- dpecodeset(DP_ESTAT, __FILE__, __LINE__);
- return NULL;
- }
- inode = sbuf.st_ino;
- mtime = sbuf.st_mtime;
- fsiz = sbuf.st_size;
- if((omode & DP_OWRITER) && fsiz == 0){
- memset(hbuf, 0, DP_HEADSIZ);
- if(dpbigendian()){
- memcpy(hbuf, DP_MAGICNUMB, strlen(DP_MAGICNUMB));
- } else {
- memcpy(hbuf, DP_MAGICNUML, strlen(DP_MAGICNUML));
- }
- sprintf(hbuf + DP_LIBVEROFF, "%d", _QDBM_LIBVER / 100);
- bnum = bnum < 1 ? DP_DEFBNUM : bnum;
- bnum = dpgetprime(bnum);
- memcpy(hbuf + DP_BNUMOFF, &bnum, sizeof(int));
- rnum = 0;
- memcpy(hbuf + DP_RNUMOFF, &rnum, sizeof(int));
- fsiz = DP_HEADSIZ + bnum * sizeof(int);
- memcpy(hbuf + DP_FSIZOFF, &fsiz, sizeof(int));
- if(!dpseekwrite(fd, 0, hbuf, DP_HEADSIZ)){
- close(fd);
- return NULL;
- }
- if(omode & DP_OSPARSE){
- c = 0;
- if(!dpseekwrite(fd, fsiz - 1, &c, 1)){
- close(fd);
- return NULL;
- }
- } else {
- if(!(map = malloc(bnum * sizeof(int)))){
- close(fd);
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- return NULL;
- }
- memset(map, 0, bnum * sizeof(int));
- if(!dpseekwrite(fd, DP_HEADSIZ, map, bnum * sizeof(int))){
- free(map);
- close(fd);
- return NULL;
- }
- free(map);
- }
- }
- if(!dpseekread(fd, 0, hbuf, DP_HEADSIZ)){
- close(fd);
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- return NULL;
- }
- if(!(omode & DP_ONOLCK) &&
- ((dpbigendian() ? memcmp(hbuf, DP_MAGICNUMB, strlen(DP_MAGICNUMB)) != 0 :
- memcmp(hbuf, DP_MAGICNUML, strlen(DP_MAGICNUML)) != 0) ||
- *((int *)(hbuf + DP_FSIZOFF)) != fsiz)){
- close(fd);
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- return NULL;
- }
- bnum = *((int *)(hbuf + DP_BNUMOFF));
- rnum = *((int *)(hbuf + DP_RNUMOFF));
- if(bnum < 1 || rnum < 0 || fsiz < DP_HEADSIZ + bnum * sizeof(int)){
- close(fd);
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- return NULL;
- }
- msiz = DP_HEADSIZ + bnum * sizeof(int);
- map = mmap(0, msiz, PROT_READ | ((mode & DP_OWRITER) ? PROT_WRITE : 0), MAP_SHARED, fd, 0);
- if(map == MAP_FAILED){
- close(fd);
- dpecodeset(DP_EMAP, __FILE__, __LINE__);
- return NULL;
- }
- tname = NULL;
- fbpool = NULL;
- if(!(depot = malloc(sizeof(DEPOT))) || !(tname = dpstrdup(name)) ||
- !(fbpool = malloc(DP_FBPOOLSIZ * 2 * sizeof(int)))){
- free(fbpool);
- free(tname);
- free(depot);
- munmap(map, msiz);
- close(fd);
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- return NULL;
- }
- depot->name = tname;
- depot->wmode = (mode & DP_OWRITER);
- depot->inode = inode;
- depot->mtime = mtime;
- depot->fd = fd;
- depot->fsiz = fsiz;
- depot->map = map;
- depot->msiz = msiz;
- depot->buckets = (int *)(map + DP_HEADSIZ);
- depot->bnum = bnum;
- depot->rnum = rnum;
- depot->fatal = FALSE;
- depot->ioff = 0;
- depot->fbpool = fbpool;
- for(i = 0; i < DP_FBPOOLSIZ * 2; i += 2){
- depot->fbpool[i] = -1;
- depot->fbpool[i+1] = -1;
- }
- depot->fbpsiz = DP_FBPOOLSIZ * 2;
- depot->fbpinc = 0;
- depot->align = 0;
- return depot;
-}
-
-
-/* Close a database handle. */
-int dpclose(DEPOT *depot){
- int fatal, err;
- assert(depot);
- fatal = depot->fatal;
- err = FALSE;
- if(depot->wmode){
- *((int *)(depot->map + DP_FSIZOFF)) = depot->fsiz;
- *((int *)(depot->map + DP_RNUMOFF)) = depot->rnum;
- }
- if(depot->map != MAP_FAILED){
- if(munmap(depot->map, depot->msiz) == -1){
- err = TRUE;
- dpecodeset(DP_EMAP, __FILE__, __LINE__);
- }
- }
- if(close(depot->fd) == -1){
- err = TRUE;
- dpecodeset(DP_ECLOSE, __FILE__, __LINE__);
- }
- free(depot->fbpool);
- free(depot->name);
- free(depot);
- if(fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return FALSE;
- }
- return err ? FALSE : TRUE;
-}
-
-
-/* Store a record. */
-int dpput(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode){
- int head[DP_RHNUM], next[DP_RHNUM];
- int i, hash, bi, off, entoff, ee, newoff, rsiz, nsiz, fdel, mroff, mrsiz, mi, min;
- char ebuf[DP_ENTBUFSIZ], *tval, *swap;
- assert(depot && kbuf && vbuf);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return FALSE;
- }
- if(!depot->wmode){
- dpecodeset(DP_EMODE, __FILE__, __LINE__);
- return FALSE;
- }
- if(ksiz < 0) ksiz = strlen(kbuf);
- if(vsiz < 0) vsiz = strlen(vbuf);
- newoff = -1;
- DP_SECONDHASH(hash, kbuf, ksiz);
- switch(dprecsearch(depot, kbuf, ksiz, hash, &bi, &off, &entoff, head, ebuf, &ee, TRUE)){
- case -1:
- depot->fatal = TRUE;
- return FALSE;
- case 0:
- fdel = head[DP_RHIFLAGS] & DP_RECFDEL;
- if(dmode == DP_DKEEP && !fdel){
- dpecodeset(DP_EKEEP, __FILE__, __LINE__);
- return FALSE;
- }
- if(fdel){
- head[DP_RHIPSIZ] += head[DP_RHIVSIZ];
- head[DP_RHIVSIZ] = 0;
- }
- rsiz = dprecsize(head);
- nsiz = DP_RHNUM * sizeof(int) + ksiz + vsiz;
- if(dmode == DP_DCAT) nsiz += head[DP_RHIVSIZ];
- if(off + rsiz >= depot->fsiz){
- if(rsiz < nsiz){
- head[DP_RHIPSIZ] += nsiz - rsiz;
- rsiz = nsiz;
- depot->fsiz = off + rsiz;
- }
- } else {
- while(nsiz > rsiz && off + rsiz < depot->fsiz){
- if(!dprechead(depot, off + rsiz, next, NULL, NULL)) return FALSE;
- if(!(next[DP_RHIFLAGS] & DP_RECFREUSE)) break;
- head[DP_RHIPSIZ] += dprecsize(next);
- rsiz += dprecsize(next);
- }
- for(i = 0; i < depot->fbpsiz; i += 2){
- if(depot->fbpool[i] >= off && depot->fbpool[i] < off + rsiz){
- depot->fbpool[i] = -1;
- depot->fbpool[i+1] = -1;
- }
- }
- }
- if(nsiz <= rsiz){
- if(!dprecover(depot, off, head, vbuf, vsiz, dmode == DP_DCAT)){
- depot->fatal = TRUE;
- return FALSE;
- }
- } else {
- tval = NULL;
- if(dmode == DP_DCAT){
- if(ee && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] <= DP_ENTBUFSIZ){
- if(!(tval = malloc(head[DP_RHIVSIZ] + vsiz + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return FALSE;
- }
- memcpy(tval, ebuf + (DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ]), head[DP_RHIVSIZ]);
- } else {
- if(!(tval = dprecval(depot, off, head, 0, -1))){
- depot->fatal = TRUE;
- return FALSE;
- }
- if(!(swap = realloc(tval, head[DP_RHIVSIZ] + vsiz + 1))){
- free(tval);
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return FALSE;
- }
- tval = swap;
- }
- memcpy(tval + head[DP_RHIVSIZ], vbuf, vsiz);
- vsiz += head[DP_RHIVSIZ];
- vbuf = tval;
- }
- mi = -1;
- min = -1;
- for(i = 0; i < depot->fbpsiz; i += 2){
- if(depot->fbpool[i+1] < nsiz) continue;
- if(mi == -1 || depot->fbpool[i+1] < min){
- mi = i;
- min = depot->fbpool[i+1];
- }
- }
- if(mi >= 0){
- mroff = depot->fbpool[mi];
- mrsiz = depot->fbpool[mi+1];
- depot->fbpool[mi] = -1;
- depot->fbpool[mi+1] = -1;
- } else {
- mroff = -1;
- mrsiz = -1;
- }
- if(!dprecdelete(depot, off, head, TRUE)){
- free(tval);
- depot->fatal = TRUE;
- return FALSE;
- }
- if(mroff > 0 && nsiz <= mrsiz){
- if(!dprecrewrite(depot, mroff, mrsiz, kbuf, ksiz, vbuf, vsiz,
- hash, head[DP_RHILEFT], head[DP_RHIRIGHT])){
- free(tval);
- depot->fatal = TRUE;
- return FALSE;
- }
- newoff = mroff;
- } else {
- if((newoff = dprecappend(depot, kbuf, ksiz, vbuf, vsiz,
- hash, head[DP_RHILEFT], head[DP_RHIRIGHT])) == -1){
- free(tval);
- depot->fatal = TRUE;
- return FALSE;
- }
- }
- free(tval);
- }
- if(fdel) depot->rnum++;
- break;
- default:
- if((newoff = dprecappend(depot, kbuf, ksiz, vbuf, vsiz, hash, 0, 0)) == -1){
- depot->fatal = TRUE;
- return FALSE;
- }
- depot->rnum++;
- break;
- }
- if(newoff > 0){
- if(entoff > 0){
- if(!dpseekwritenum(depot->fd, entoff, newoff)){
- depot->fatal = TRUE;
- return FALSE;
- }
- } else {
- depot->buckets[bi] = newoff;
- }
- }
- return TRUE;
-}
-
-
-/* Delete a record. */
-int dpout(DEPOT *depot, const char *kbuf, int ksiz){
- int head[DP_RHNUM], hash, bi, off, entoff, ee;
- char ebuf[DP_ENTBUFSIZ];
- assert(depot && kbuf);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return FALSE;
- }
- if(!depot->wmode){
- dpecodeset(DP_EMODE, __FILE__, __LINE__);
- return FALSE;
- }
- if(ksiz < 0) ksiz = strlen(kbuf);
- DP_SECONDHASH(hash, kbuf, ksiz);
- switch(dprecsearch(depot, kbuf, ksiz, hash, &bi, &off, &entoff, head, ebuf, &ee, FALSE)){
- case -1:
- depot->fatal = TRUE;
- return FALSE;
- case 0:
- break;
- default:
- dpecodeset(DP_ENOITEM, __FILE__, __LINE__);
- return FALSE;
- }
- if(!dprecdelete(depot, off, head, FALSE)){
- depot->fatal = TRUE;
- return FALSE;
- }
- depot->rnum--;
- return TRUE;
-}
-
-
-/* Retrieve a record. */
-char *dpget(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, int *sp){
- int head[DP_RHNUM], hash, bi, off, entoff, ee, vsiz;
- char ebuf[DP_ENTBUFSIZ], *vbuf;
- assert(depot && kbuf && start >= 0);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return NULL;
- }
- if(ksiz < 0) ksiz = strlen(kbuf);
- DP_SECONDHASH(hash, kbuf, ksiz);
- switch(dprecsearch(depot, kbuf, ksiz, hash, &bi, &off, &entoff, head, ebuf, &ee, FALSE)){
- case -1:
- depot->fatal = TRUE;
- return NULL;
- case 0:
- break;
- default:
- dpecodeset(DP_ENOITEM, __FILE__, __LINE__);
- return NULL;
- }
- if(start > head[DP_RHIVSIZ]){
- dpecodeset(DP_ENOITEM, __FILE__, __LINE__);
- return NULL;
- }
- if(ee && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] <= DP_ENTBUFSIZ){
- head[DP_RHIVSIZ] -= start;
- if(max < 0){
- vsiz = head[DP_RHIVSIZ];
- } else {
- vsiz = max < head[DP_RHIVSIZ] ? max : head[DP_RHIVSIZ];
- }
- if(!(vbuf = malloc(vsiz + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return NULL;
- }
- memcpy(vbuf, ebuf + (DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + start), vsiz);
- vbuf[vsiz] = '\0';
- } else {
- if(!(vbuf = dprecval(depot, off, head, start, max))){
- depot->fatal = TRUE;
- return NULL;
- }
- }
- if(sp){
- if(max < 0){
- *sp = head[DP_RHIVSIZ];
- } else {
- *sp = max < head[DP_RHIVSIZ] ? max : head[DP_RHIVSIZ];
- }
- }
- return vbuf;
-}
-
-
-/* Retrieve a record and write the value into a buffer. */
-int dpgetwb(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, char *vbuf){
- int head[DP_RHNUM], hash, bi, off, entoff, ee, vsiz;
- char ebuf[DP_ENTBUFSIZ];
- assert(depot && kbuf && start >= 0 && max >= 0 && vbuf);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return -1;
- }
- if(ksiz < 0) ksiz = strlen(kbuf);
- DP_SECONDHASH(hash, kbuf, ksiz);
- switch(dprecsearch(depot, kbuf, ksiz, hash, &bi, &off, &entoff, head, ebuf, &ee, FALSE)){
- case -1:
- depot->fatal = TRUE;
- return -1;
- case 0:
- break;
- default:
- dpecodeset(DP_ENOITEM, __FILE__, __LINE__);
- return -1;
- }
- if(start > head[DP_RHIVSIZ]){
- dpecodeset(DP_ENOITEM, __FILE__, __LINE__);
- return -1;
- }
- if(ee && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] <= DP_ENTBUFSIZ){
- head[DP_RHIVSIZ] -= start;
- vsiz = max < head[DP_RHIVSIZ] ? max : head[DP_RHIVSIZ];
- memcpy(vbuf, ebuf + (DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + start), vsiz);
- } else {
- if((vsiz = dprecvalwb(depot, off, head, start, max, vbuf)) == -1){
- depot->fatal = TRUE;
- return -1;
- }
- }
- return vsiz;
-}
-
-
-/* Get the size of the value of a record. */
-int dpvsiz(DEPOT *depot, const char *kbuf, int ksiz){
- int head[DP_RHNUM], hash, bi, off, entoff, ee;
- char ebuf[DP_ENTBUFSIZ];
- assert(depot && kbuf);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return -1;
- }
- if(ksiz < 0) ksiz = strlen(kbuf);
- DP_SECONDHASH(hash, kbuf, ksiz);
- switch(dprecsearch(depot, kbuf, ksiz, hash, &bi, &off, &entoff, head, ebuf, &ee, FALSE)){
- case -1:
- depot->fatal = TRUE;
- return -1;
- case 0:
- break;
- default:
- dpecodeset(DP_ENOITEM, __FILE__, __LINE__);
- return -1;
- }
- return head[DP_RHIVSIZ];
-}
-
-
-/* Initialize the iterator of a database handle. */
-int dpiterinit(DEPOT *depot){
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return FALSE;
- }
- depot->ioff = 0;
- return TRUE;
-}
-
-
-/* Get the next key of the iterator. */
-char *dpiternext(DEPOT *depot, int *sp){
- int off, head[DP_RHNUM], ee;
- char ebuf[DP_ENTBUFSIZ], *kbuf;
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return NULL;
- }
- off = DP_HEADSIZ + depot->bnum * sizeof(int);
- off = off > depot->ioff ? off : depot->ioff;
- while(off < depot->fsiz){
- if(!dprechead(depot, off, head, ebuf, &ee)){
- depot->fatal = TRUE;
- return NULL;
- }
- if(head[DP_RHIFLAGS] & DP_RECFDEL){
- off += dprecsize(head);
- } else {
- if(ee && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] <= DP_ENTBUFSIZ){
- if(!(kbuf = malloc(head[DP_RHIKSIZ] + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return NULL;
- }
- memcpy(kbuf, ebuf + (DP_RHNUM * sizeof(int)), head[DP_RHIKSIZ]);
- kbuf[head[DP_RHIKSIZ]] = '\0';
- } else {
- if(!(kbuf = dpreckey(depot, off, head))){
- depot->fatal = TRUE;
- return NULL;
- }
- }
- depot->ioff = off + dprecsize(head);
- if(sp) *sp = head[DP_RHIKSIZ];
- return kbuf;
- }
- }
- dpecodeset(DP_ENOITEM, __FILE__, __LINE__);
- return NULL;
-}
-
-
-/* Set alignment of a database handle. */
-int dpsetalign(DEPOT *depot, int align){
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return FALSE;
- }
- if(!depot->wmode){
- dpecodeset(DP_EMODE, __FILE__, __LINE__);
- return FALSE;
- }
- depot->align = align;
- return TRUE;
-}
-
-
-/* Set the size of the free block pool of a database handle. */
-int dpsetfbpsiz(DEPOT *depot, int size){
- int *fbpool;
- int i;
- assert(depot && size >= 0);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return FALSE;
- }
- if(!depot->wmode){
- dpecodeset(DP_EMODE, __FILE__, __LINE__);
- return FALSE;
- }
- size *= 2;
- if(!(fbpool = realloc(depot->fbpool, size * sizeof(int) + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- return FALSE;
- }
- for(i = 0; i < size; i += 2){
- fbpool[i] = -1;
- fbpool[i+1] = -1;
- }
- depot->fbpool = fbpool;
- depot->fbpsiz = size;
- return TRUE;
-}
-
-
-
-/* Synchronize contents of updating a database with the file and the device. */
-int dpsync(DEPOT *depot){
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return FALSE;
- }
- if(!depot->wmode){
- dpecodeset(DP_EMODE, __FILE__, __LINE__);
- return FALSE;
- }
- *((int *)(depot->map + DP_FSIZOFF)) = depot->fsiz;
- *((int *)(depot->map + DP_RNUMOFF)) = depot->rnum;
- if(msync(depot->map, depot->msiz, MS_SYNC) == -1){
- dpecodeset(DP_EMAP, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return FALSE;
- }
- if(fdatasync(depot->fd) == -1){
- dpecodeset(DP_ESYNC, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return FALSE;
- }
- return TRUE;
-}
-
-
-/* Optimize a database. */
-int dpoptimize(DEPOT *depot, int bnum){
- DEPOT *tdepot;
- char *name;
- int i, err, off, head[DP_RHNUM], ee, ksizs[DP_OPTRUNIT], vsizs[DP_OPTRUNIT], unum;
- char ebuf[DP_ENTBUFSIZ], *kbufs[DP_OPTRUNIT], *vbufs[DP_OPTRUNIT];
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return FALSE;
- }
- if(!depot->wmode){
- dpecodeset(DP_EMODE, __FILE__, __LINE__);
- return FALSE;
- }
- if(!(name = malloc(strlen(depot->name) + strlen(DP_TMPFSUF) + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- depot->fatal = FALSE;
- return FALSE;
- }
- sprintf(name, "%s%s", depot->name, DP_TMPFSUF);
- if(bnum < 0){
- bnum = (int)(depot->rnum * (1.0 / DP_OPTBLOAD)) + 1;
- if(bnum < DP_DEFBNUM / 2) bnum = DP_DEFBNUM / 2;
- }
- if(!(tdepot = dpopen(name, DP_OWRITER | DP_OCREAT | DP_OTRUNC, bnum))){
- free(name);
- depot->fatal = TRUE;
- return FALSE;
- }
- free(name);
- if(!dpsetflags(tdepot, dpgetflags(depot))){
- dpclose(tdepot);
- depot->fatal = TRUE;
- return FALSE;
- }
- tdepot->align = depot->align;
- err = FALSE;
- off = DP_HEADSIZ + depot->bnum * sizeof(int);
- unum = 0;
- while(off < depot->fsiz){
- if(!dprechead(depot, off, head, ebuf, &ee)){
- err = TRUE;
- break;
- }
- if(!(head[DP_RHIFLAGS] & DP_RECFDEL)){
- if(ee && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] <= DP_ENTBUFSIZ){
- if(!(kbufs[unum] = malloc(head[DP_RHIKSIZ] + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- err = TRUE;
- break;
- }
- memcpy(kbufs[unum], ebuf + (DP_RHNUM * sizeof(int)), head[DP_RHIKSIZ]);
- if(DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] <= DP_ENTBUFSIZ){
- if(!(vbufs[unum] = malloc(head[DP_RHIVSIZ] + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- err = TRUE;
- break;
- }
- memcpy(vbufs[unum], ebuf + (DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ]),
- head[DP_RHIVSIZ]);
- } else {
- vbufs[unum] = dprecval(depot, off, head, 0, -1);
- }
- } else {
- kbufs[unum] = dpreckey(depot, off, head);
- vbufs[unum] = dprecval(depot, off, head, 0, -1);
- }
- ksizs[unum] = head[DP_RHIKSIZ];
- vsizs[unum] = head[DP_RHIVSIZ];
- unum++;
- if(unum >= DP_OPTRUNIT){
- for(i = 0; i < unum; i++){
- if(kbufs[i] && vbufs[i]){
- if(!dpput(tdepot, kbufs[i], ksizs[i], vbufs[i], vsizs[i], DP_DKEEP)) err = TRUE;
- } else {
- err = TRUE;
- }
- free(kbufs[i]);
- free(vbufs[i]);
- if(err) break;
- }
- unum = 0;
- }
- }
- off += dprecsize(head);
- if(err) break;
- }
- for(i = 0; i < unum; i++){
- if(kbufs[i] && vbufs[i]){
- if(!dpput(tdepot, kbufs[i], ksizs[i], vbufs[i], vsizs[i], DP_DKEEP)) err = TRUE;
- } else {
- err = TRUE;
- }
- free(kbufs[i]);
- free(vbufs[i]);
- if(err) break;
- }
- if(!dpsync(tdepot)) err = TRUE;
- if(err){
- unlink(tdepot->name);
- dpclose(tdepot);
- depot->fatal = TRUE;
- return FALSE;
- }
- if(munmap(depot->map, depot->msiz) == -1){
- dpclose(tdepot);
- dpecodeset(DP_EMAP, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return FALSE;
- }
- depot->map = MAP_FAILED;
- if(ftruncate(depot->fd, 0) == -1){
- dpclose(tdepot);
- unlink(tdepot->name);
- dpecodeset(DP_ETRUNC, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return FALSE;
- }
- if(dpfcopy(depot->fd, 0, tdepot->fd, 0) == -1){
- dpclose(tdepot);
- unlink(tdepot->name);
- depot->fatal = TRUE;
- return FALSE;
- }
- depot->fsiz = tdepot->fsiz;
- depot->bnum = tdepot->bnum;
- depot->ioff = 0;
- for(i = 0; i < depot->fbpsiz; i += 2){
- depot->fbpool[i] = -1;
- depot->fbpool[i+1] = -1;
- }
- depot->msiz = tdepot->msiz;
- depot->map = mmap(0, depot->msiz, PROT_READ | PROT_WRITE, MAP_SHARED, depot->fd, 0);
- if(depot->map == MAP_FAILED){
- dpecodeset(DP_EMAP, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return FALSE;
- }
- depot->buckets = (int *)(depot->map + DP_HEADSIZ);
- if(!(name = dpname(tdepot))){
- dpclose(tdepot);
- unlink(tdepot->name);
- depot->fatal = TRUE;
- return FALSE;
- }
- if(!dpclose(tdepot)){
- free(name);
- unlink(tdepot->name);
- depot->fatal = TRUE;
- return FALSE;
- }
- if(unlink(name) == -1){
- free(name);
- dpecodeset(DP_EUNLINK, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return FALSE;
- }
- free(name);
- return TRUE;
-}
-
-
-/* Get the name of a database. */
-char *dpname(DEPOT *depot){
- char *name;
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return NULL;
- }
- if(!(name = dpstrdup(depot->name))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return NULL;
- }
- return name;
-}
-
-
-/* Get the size of a database file. */
-int dpfsiz(DEPOT *depot){
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return -1;
- }
- return depot->fsiz;
-}
-
-
-/* Get the number of the elements of the bucket array. */
-int dpbnum(DEPOT *depot){
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return -1;
- }
- return depot->bnum;
-}
-
-
-/* Get the number of the used elements of the bucket array. */
-int dpbusenum(DEPOT *depot){
- int i, hits;
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return -1;
- }
- hits = 0;
- for(i = 0; i < depot->bnum; i++){
- if(depot->buckets[i]) hits++;
- }
- return hits;
-}
-
-
-/* Get the number of the records stored in a database. */
-int dprnum(DEPOT *depot){
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return -1;
- }
- return depot->rnum;
-}
-
-
-/* Check whether a database handle is a writer or not. */
-int dpwritable(DEPOT *depot){
- assert(depot);
- return depot->wmode;
-}
-
-
-/* Check whether a database has a fatal error or not. */
-int dpfatalerror(DEPOT *depot){
- assert(depot);
- return depot->fatal;
-}
-
-
-/* Get the inode number of a database file. */
-int dpinode(DEPOT *depot){
- assert(depot);
- return depot->inode;
-}
-
-
-/* Get the last modified time of a database. */
-time_t dpmtime(DEPOT *depot){
- assert(depot);
- return depot->mtime;
-}
-
-
-/* Get the file descriptor of a database file. */
-int dpfdesc(DEPOT *depot){
- assert(depot);
- return depot->fd;
-}
-
-
-/* Remove a database file. */
-int dpremove(const char *name){
- struct stat sbuf;
- DEPOT *depot;
- assert(name);
- if(lstat(name, &sbuf) == -1){
- dpecodeset(DP_ESTAT, __FILE__, __LINE__);
- return FALSE;
- }
- if((depot = dpopen(name, DP_OWRITER | DP_OTRUNC, -1)) != NULL) dpclose(depot);
- if(unlink(name) == -1){
- dpecodeset(DP_EUNLINK, __FILE__, __LINE__);
- return FALSE;
- }
- return TRUE;
-}
-
-
-/* Repair a broken database file. */
-int dprepair(const char *name){
- DEPOT *tdepot;
- char dbhead[DP_HEADSIZ], *tname, *kbuf, *vbuf;
- int fd, fsiz, flags, bnum, tbnum, err, head[DP_RHNUM], off, rsiz, ksiz, vsiz;
- struct stat sbuf;
- assert(name);
- if(lstat(name, &sbuf) == -1){
- dpecodeset(DP_ESTAT, __FILE__, __LINE__);
- return FALSE;
- }
- fsiz = sbuf.st_size;
- if((fd = open(name, O_RDWR, DP_FILEMODE)) == -1){
- dpecodeset(DP_EOPEN, __FILE__, __LINE__);
- return FALSE;
- }
- if(!dpseekread(fd, 0, dbhead, DP_HEADSIZ)){
- close(fd);
- return FALSE;
- }
- flags = *(int *)(dbhead + DP_FLAGSOFF);
- bnum = *(int *)(dbhead + DP_BNUMOFF);
- tbnum = *(int *)(dbhead + DP_RNUMOFF) * 2;
- if(tbnum < DP_DEFBNUM) tbnum = DP_DEFBNUM;
- if(!(tname = malloc(strlen(name) + strlen(DP_TMPFSUF) + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- return FALSE;
- }
- sprintf(tname, "%s%s", name, DP_TMPFSUF);
- if(!(tdepot = dpopen(tname, DP_OWRITER | DP_OCREAT | DP_OTRUNC, tbnum))){
- free(tname);
- close(fd);
- return FALSE;
- }
- err = FALSE;
- off = DP_HEADSIZ + bnum * sizeof(int);
- while(off < fsiz){
- if(!dpseekread(fd, off, head, DP_RHNUM * sizeof(int))) break;
- if(head[DP_RHIFLAGS] & DP_RECFDEL){
- if((rsiz = dprecsize(head)) < 0) break;
- off += rsiz;
- continue;
- }
- ksiz = head[DP_RHIKSIZ];
- vsiz = head[DP_RHIVSIZ];
- if(ksiz >= 0 && vsiz >= 0){
- kbuf = malloc(ksiz + 1);
- vbuf = malloc(vsiz + 1);
- if(kbuf && vbuf){
- if(dpseekread(fd, off + DP_RHNUM * sizeof(int), kbuf, ksiz) &&
- dpseekread(fd, off + DP_RHNUM * sizeof(int) + ksiz, vbuf, vsiz)){
- if(!dpput(tdepot, kbuf, ksiz, vbuf, vsiz, DP_DKEEP)) err = TRUE;
- } else {
- err = TRUE;
- }
- } else {
- if(!err) dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- err = TRUE;
- }
- free(vbuf);
- free(kbuf);
- } else {
- if(!err) dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- err = TRUE;
- }
- if((rsiz = dprecsize(head)) < 0) break;
- off += rsiz;
- }
- if(!dpsetflags(tdepot, flags)) err = TRUE;
- if(!dpsync(tdepot)) err = TRUE;
- if(ftruncate(fd, 0) == -1){
- if(!err) dpecodeset(DP_ETRUNC, __FILE__, __LINE__);
- err = TRUE;
- }
- if(dpfcopy(fd, 0, tdepot->fd, 0) == -1) err = TRUE;
- if(!dpclose(tdepot)) err = TRUE;
- if(close(fd) == -1){
- if(!err) dpecodeset(DP_ECLOSE, __FILE__, __LINE__);
- err = TRUE;
- }
- if(unlink(tname) == -1){
- if(!err) dpecodeset(DP_EUNLINK, __FILE__, __LINE__);
- err = TRUE;
- }
- free(tname);
- return err ? FALSE : TRUE;
-}
-
-
-/* Dump all records as endian independent data. */
-int dpexportdb(DEPOT *depot, const char *name){
- char *kbuf, *vbuf, *pbuf;
- int fd, err, ksiz, vsiz, psiz;
- assert(depot && name);
- if(!(dpiterinit(depot))) return FALSE;
- if((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, DP_FILEMODE)) == -1){
- dpecodeset(DP_EOPEN, __FILE__, __LINE__);
- return FALSE;
- }
- err = FALSE;
- while(!err && (kbuf = dpiternext(depot, &ksiz)) != NULL){
- if((vbuf = dpget(depot, kbuf, ksiz, 0, -1, &vsiz)) != NULL){
- if((pbuf = malloc(ksiz + vsiz + DP_NUMBUFSIZ * 2)) != NULL){
- psiz = 0;
- psiz += sprintf(pbuf + psiz, "%X\n%X\n", ksiz, vsiz);
- memcpy(pbuf + psiz, kbuf, ksiz);
- psiz += ksiz;
- pbuf[psiz++] = '\n';
- memcpy(pbuf + psiz, vbuf, vsiz);
- psiz += vsiz;
- pbuf[psiz++] = '\n';
- if(!dpwrite(fd, pbuf, psiz)){
- dpecodeset(DP_EWRITE, __FILE__, __LINE__);
- err = TRUE;
- }
- free(pbuf);
- } else {
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- err = TRUE;
- }
- free(vbuf);
- } else {
- err = TRUE;
- }
- free(kbuf);
- }
- if(close(fd) == -1){
- if(!err) dpecodeset(DP_ECLOSE, __FILE__, __LINE__);
- return FALSE;
- }
- return !err && !dpfatalerror(depot);
-}
-
-
-/* Load all records from endian independent data. */
-int dpimportdb(DEPOT *depot, const char *name){
- char mbuf[DP_IOBUFSIZ], *rbuf;
- int i, j, fd, err, fsiz, off, msiz, ksiz, vsiz, hlen;
- struct stat sbuf;
- assert(depot && name);
- if(!depot->wmode){
- dpecodeset(DP_EMODE, __FILE__, __LINE__);
- return FALSE;
- }
- if(dprnum(depot) > 0){
- dpecodeset(DP_EMISC, __FILE__, __LINE__);
- return FALSE;
- }
- if((fd = open(name, O_RDONLY, DP_FILEMODE)) == -1){
- dpecodeset(DP_EOPEN, __FILE__, __LINE__);
- return FALSE;
- }
- if(fstat(fd, &sbuf) == -1 || !S_ISREG(sbuf.st_mode)){
- dpecodeset(DP_ESTAT, __FILE__, __LINE__);
- close(fd);
- return FALSE;
- }
- err = FALSE;
- fsiz = sbuf.st_size;
- off = 0;
- while(!err && off < fsiz){
- msiz = fsiz - off;
- if(msiz > DP_IOBUFSIZ) msiz = DP_IOBUFSIZ;
- if(!dpseekread(fd, off, mbuf, msiz)){
- err = TRUE;
- break;
- }
- hlen = 0;
- ksiz = -1;
- vsiz = -1;
- for(i = 0; i < msiz; i++){
- if(mbuf[i] == '\n'){
- mbuf[i] = '\0';
- ksiz = strtol(mbuf, NULL, 16);
- for(j = i + 1; j < msiz; j++){
- if(mbuf[j] == '\n'){
- mbuf[j] = '\0';
- vsiz = strtol(mbuf + i + 1, NULL, 16);
- hlen = j + 1;
- break;
- }
- }
- break;
- }
- }
- if(ksiz < 0 || vsiz < 0 || hlen < 4){
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- err = TRUE;
- break;
- }
- if(hlen + ksiz + vsiz + 2 < DP_IOBUFSIZ){
- if(!dpput(depot, mbuf + hlen, ksiz, mbuf + hlen + ksiz + 1, vsiz, DP_DKEEP)) err = TRUE;
- } else {
- if((rbuf = malloc(ksiz + vsiz + 2)) != NULL){
- if(dpseekread(fd, off + hlen, rbuf, ksiz + vsiz + 2)){
- if(!dpput(depot, rbuf, ksiz, rbuf + ksiz + 1, vsiz, DP_DKEEP)) err = TRUE;
- } else {
- err = TRUE;
- }
- free(rbuf);
- } else {
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- err = TRUE;
- }
- }
- off += hlen + ksiz + vsiz + 2;
- }
- if(close(fd) == -1){
- if(!err) dpecodeset(DP_ECLOSE, __FILE__, __LINE__);
- return FALSE;
- }
- return !err && !dpfatalerror(depot);
-}
-
-
-/* Retrieve a record directly from a database file. */
-char *dpsnaffle(const char *name, const char* kbuf, int ksiz, int *sp){
- char hbuf[DP_HEADSIZ], *map, *vbuf, *tkbuf;
- int fd, fsiz, bnum, msiz, *buckets, hash, thash, head[DP_RHNUM], err, off, vsiz, tksiz, kcmp;
- struct stat sbuf;
- assert(name && kbuf);
- if(ksiz < 0) ksiz = strlen(kbuf);
- if((fd = open(name, O_RDONLY, DP_FILEMODE)) == -1){
- dpecodeset(DP_EOPEN, __FILE__, __LINE__);
- return NULL;
- }
- if(fstat(fd, &sbuf) == -1 || !S_ISREG(sbuf.st_mode)){
- close(fd);
- dpecodeset(DP_ESTAT, __FILE__, __LINE__);
- return NULL;
- }
- fsiz = sbuf.st_size;
- if(!dpseekread(fd, 0, hbuf, DP_HEADSIZ)){
- close(fd);
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- return NULL;
- }
- if(dpbigendian() ? memcmp(hbuf, DP_MAGICNUMB, strlen(DP_MAGICNUMB)) != 0 :
- memcmp(hbuf, DP_MAGICNUML, strlen(DP_MAGICNUML)) != 0){
- close(fd);
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- return NULL;
- }
- bnum = *((int *)(hbuf + DP_BNUMOFF));
- if(bnum < 1 || fsiz < DP_HEADSIZ + bnum * sizeof(int)){
- close(fd);
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- return NULL;
- }
- msiz = DP_HEADSIZ + bnum * sizeof(int);
- map = mmap(0, msiz, PROT_READ, MAP_SHARED, fd, 0);
- if(map == MAP_FAILED){
- close(fd);
- dpecodeset(DP_EMAP, __FILE__, __LINE__);
- return NULL;
- }
- buckets = (int *)(map + DP_HEADSIZ);
- err = FALSE;
- vbuf = NULL;
- vsiz = 0;
- DP_SECONDHASH(hash, kbuf, ksiz);
- DP_FIRSTHASH(thash, kbuf, ksiz);
- off = buckets[thash%bnum];
- while(off != 0){
- if(!dpseekread(fd, off, head, DP_RHNUM * sizeof(int))){
- err = TRUE;
- break;
- }
- if(head[DP_RHIKSIZ] < 0 || head[DP_RHIVSIZ] < 0 || head[DP_RHIPSIZ] < 0 ||
- head[DP_RHILEFT] < 0 || head[DP_RHIRIGHT] < 0){
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- err = TRUE;
- break;
- }
- thash = head[DP_RHIHASH];
- if(hash > thash){
- off = head[DP_RHILEFT];
- } else if(hash < thash){
- off = head[DP_RHIRIGHT];
- } else {
- tksiz = head[DP_RHIKSIZ];
- if(!(tkbuf = malloc(tksiz + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- err = TRUE;
- break;
- }
- if(!dpseekread(fd, off + DP_RHNUM * sizeof(int), tkbuf, tksiz)){
- free(tkbuf);
- err = TRUE;
- break;
- }
- tkbuf[tksiz] = '\0';
- kcmp = dpkeycmp(kbuf, ksiz, tkbuf, tksiz);
- free(tkbuf);
- if(kcmp > 0){
- off = head[DP_RHILEFT];
- } else if(kcmp < 0){
- off = head[DP_RHIRIGHT];
- } else if(head[DP_RHIFLAGS] & DP_RECFDEL){
- break;
- } else {
- vsiz = head[DP_RHIVSIZ];
- if(!(vbuf = malloc(vsiz + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- err = TRUE;
- break;
- }
- if(!dpseekread(fd, off + DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ], vbuf, vsiz)){
- free(vbuf);
- vbuf = NULL;
- err = TRUE;
- break;
- }
- vbuf[vsiz] = '\0';
- break;
- }
- }
- }
- if(vbuf){
- if(sp) *sp = vsiz;
- } else if(!err){
- dpecodeset(DP_ENOITEM, __FILE__, __LINE__);
- }
- munmap(map, msiz);
- close(fd);
- return vbuf;
-}
-
-
-/* Hash function used inside Depot. */
-int dpinnerhash(const char *kbuf, int ksiz){
- int res;
- assert(kbuf);
- if(ksiz < 0) ksiz = strlen(kbuf);
- DP_FIRSTHASH(res, kbuf, ksiz);
- return res;
-}
-
-
-/* Hash function which is independent from the hash functions used inside Depot. */
-int dpouterhash(const char *kbuf, int ksiz){
- int res;
- assert(kbuf);
- if(ksiz < 0) ksiz = strlen(kbuf);
- DP_THIRDHASH(res, kbuf, ksiz);
- return res;
-}
-
-
-/* Get a natural prime number not less than a number. */
-int dpprimenum(int num){
- assert(num > 0);
- return dpgetprime(num);
-}
-
-
-
-/*************************************************************************************************
- * features for experts
- *************************************************************************************************/
-
-
-/* Name of the operating system. */
-const char *dpsysname = _QDBM_SYSNAME;
-
-
-/* File descriptor for debugging output. */
-int dpdbgfd = -1;
-
-
-/* Whether this build is reentrant. */
-const int dpisreentrant = _qdbm_ptsafe;
-
-
-/* Set the last happened error code. */
-void dpecodeset(int ecode, const char *file, int line){
- char iobuf[DP_IOBUFSIZ];
- assert(ecode >= DP_ENOERR && file && line >= 0);
- dpecode = ecode;
- if(dpdbgfd >= 0){
- fflush(stdout);
- fflush(stderr);
- sprintf(iobuf, "* dpecodeset: %s:%d: [%d] %s\n", file, line, ecode, dperrmsg(ecode));
- dpwrite(dpdbgfd, iobuf, strlen(iobuf));
- }
-}
-
-
-/* Get the pointer of the variable of the last happened error code. */
-int *dpecodeptr(void){
- static int defdpecode = DP_ENOERR;
- void *ptr;
- if(_qdbm_ptsafe){
- if(!(ptr = _qdbm_settsd(&defdpecode, sizeof(int), &defdpecode))){
- defdpecode = DP_EMISC;
- return &defdpecode;
- }
- return (int *)ptr;
- }
- return &defdpecode;
-}
-
-
-/* Synchronize updating contents on memory. */
-int dpmemsync(DEPOT *depot){
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return FALSE;
- }
- if(!depot->wmode){
- dpecodeset(DP_EMODE, __FILE__, __LINE__);
- return FALSE;
- }
- *((int *)(depot->map + DP_FSIZOFF)) = depot->fsiz;
- *((int *)(depot->map + DP_RNUMOFF)) = depot->rnum;
- if(msync(depot->map, depot->msiz, MS_SYNC) == -1){
- dpecodeset(DP_EMAP, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return FALSE;
- }
- return TRUE;
-}
-
-
-/* Synchronize updating contents on memory, not physically. */
-int dpmemflush(DEPOT *depot){
- assert(depot);
- if(depot->fatal){
- dpecodeset(DP_EFATAL, __FILE__, __LINE__);
- return FALSE;
- }
- if(!depot->wmode){
- dpecodeset(DP_EMODE, __FILE__, __LINE__);
- return FALSE;
- }
- *((int *)(depot->map + DP_FSIZOFF)) = depot->fsiz;
- *((int *)(depot->map + DP_RNUMOFF)) = depot->rnum;
- if(mflush(depot->map, depot->msiz, MS_SYNC) == -1){
- dpecodeset(DP_EMAP, __FILE__, __LINE__);
- depot->fatal = TRUE;
- return FALSE;
- }
- return TRUE;
-}
-
-
-/* Get flags of a database. */
-int dpgetflags(DEPOT *depot){
- int flags;
- assert(depot);
- memcpy(&flags, depot->map + DP_FLAGSOFF, sizeof(int));
- return flags;
-}
-
-
-/* Set flags of a database. */
-int dpsetflags(DEPOT *depot, int flags){
- assert(depot);
- if(!depot->wmode){
- dpecodeset(DP_EMODE, __FILE__, __LINE__);
- return FALSE;
- }
- memcpy(depot->map + DP_FLAGSOFF, &flags, sizeof(int));
- return TRUE;
-}
-
-
-
-/*************************************************************************************************
- * private objects
- *************************************************************************************************/
-
-
-/* Check whether the byte order of the platform is big endian or not.
- The return value is true if bigendian, else, it is false. */
-static int dpbigendian(void){
- char buf[sizeof(int)];
- *(int *)buf = 1;
- return !buf[0];
-}
-
-
-/* Get a copied string.
- `str' specifies an original string.
- The return value is a copied string whose region is allocated by `malloc'. */
-static char *dpstrdup(const char *str){
- int len;
- char *buf;
- assert(str);
- len = strlen(str);
- if(!(buf = malloc(len + 1))) return NULL;
- memcpy(buf, str, len + 1);
- return buf;
-}
-
-
-/* Lock a file descriptor.
- `fd' specifies a file descriptor.
- `ex' specifies whether an exclusive lock or a shared lock is performed.
- `nb' specifies whether to request with non-blocking.
- The return value is true if successful, else, it is false. */
-static int dplock(int fd, int ex, int nb){
- struct flock lock;
- assert(fd >= 0);
- memset(&lock, 0, sizeof(struct flock));
- lock.l_type = ex ? F_WRLCK : F_RDLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0;
- lock.l_len = 0;
- lock.l_pid = 0;
- while(fcntl(fd, nb ? F_SETLK : F_SETLKW, &lock) == -1){
- if(errno != EINTR){
- dpecodeset(DP_ELOCK, __FILE__, __LINE__);
- return FALSE;
- }
- }
- return TRUE;
-}
-
-
-/* Write into a file.
- `fd' specifies a file descriptor.
- `buf' specifies a buffer to write.
- `size' specifies the size of the buffer.
- The return value is the size of the written buffer, or, -1 on failure. */
-static int dpwrite(int fd, const void *buf, int size){
- const char *lbuf;
- int rv, wb;
- assert(fd >= 0 && buf && size >= 0);
- lbuf = buf;
- rv = 0;
- do {
- wb = write(fd, lbuf, size);
- switch(wb){
- case -1: if(errno != EINTR) return -1;
- case 0: break;
- default:
- lbuf += wb;
- size -= wb;
- rv += wb;
- break;
- }
- } while(size > 0);
- return rv;
-}
-
-
-/* Write into a file at an offset.
- `fd' specifies a file descriptor.
- `off' specifies an offset of the file.
- `buf' specifies a buffer to write.
- `size' specifies the size of the buffer.
- The return value is true if successful, else, it is false. */
-static int dpseekwrite(int fd, int off, const void *buf, int size){
- assert(fd >= 0 && buf && size >= 0);
- if(size < 1) return TRUE;
- if(off < 0){
- if(lseek(fd, 0, SEEK_END) == -1){
- dpecodeset(DP_ESEEK, __FILE__, __LINE__);
- return FALSE;
- }
- } else {
- if(lseek(fd, off, SEEK_SET) != off){
- dpecodeset(DP_ESEEK, __FILE__, __LINE__);
- return FALSE;
- }
- }
- if(dpwrite(fd, buf, size) != size){
- dpecodeset(DP_EWRITE, __FILE__, __LINE__);
- return FALSE;
- }
- return TRUE;
-}
-
-
-/* Write an integer into a file at an offset.
- `fd' specifies a file descriptor.
- `off' specifies an offset of the file.
- `num' specifies an integer.
- The return value is true if successful, else, it is false. */
-static int dpseekwritenum(int fd, int off, int num){
- assert(fd >= 0);
- return dpseekwrite(fd, off, &num, sizeof(int));
-}
-
-
-/* Read from a file and store the data into a buffer.
- `fd' specifies a file descriptor.
- `buffer' specifies a buffer to store into.
- `size' specifies the size to read with.
- The return value is the size read with, or, -1 on failure. */
-static int dpread(int fd, void *buf, int size){
- char *lbuf;
- int i, bs;
- assert(fd >= 0 && buf && size >= 0);
- lbuf = buf;
- for(i = 0; i < size && (bs = read(fd, lbuf + i, size - i)) != 0; i += bs){
- if(bs == -1 && errno != EINTR) return -1;
- }
- return i;
-}
-
-
-/* Read from a file at an offset and store the data into a buffer.
- `fd' specifies a file descriptor.
- `off' specifies an offset of the file.
- `buffer' specifies a buffer to store into.
- `size' specifies the size to read with.
- The return value is true if successful, else, it is false. */
-static int dpseekread(int fd, int off, void *buf, int size){
- char *lbuf;
- assert(fd >= 0 && off >= 0 && buf && size >= 0);
- lbuf = (char *)buf;
- if(lseek(fd, off, SEEK_SET) != off){
- dpecodeset(DP_ESEEK, __FILE__, __LINE__);
- return FALSE;
- }
- if(dpread(fd, lbuf, size) != size){
- dpecodeset(DP_EREAD, __FILE__, __LINE__);
- return FALSE;
- }
- return TRUE;
-}
-
-
-/* Copy data between files.
- `destfd' specifies a file descriptor of a destination file.
- `destoff' specifies an offset of the destination file.
- `srcfd' specifies a file descriptor of a source file.
- `srcoff' specifies an offset of the source file.
- The return value is the size copied with, or, -1 on failure. */
-static int dpfcopy(int destfd, int destoff, int srcfd, int srcoff){
- char iobuf[DP_IOBUFSIZ];
- int sum, iosiz;
- if(lseek(srcfd, srcoff, SEEK_SET) == -1 || lseek(destfd, destoff, SEEK_SET) == -1){
- dpecodeset(DP_ESEEK, __FILE__, __LINE__);
- return -1;
- }
- sum = 0;
- while((iosiz = dpread(srcfd, iobuf, DP_IOBUFSIZ)) > 0){
- if(dpwrite(destfd, iobuf, iosiz) == -1){
- dpecodeset(DP_EWRITE, __FILE__, __LINE__);
- return -1;
- }
- sum += iosiz;
- }
- if(iosiz < 0){
- dpecodeset(DP_EREAD, __FILE__, __LINE__);
- return -1;
- }
- return sum;
-}
-
-
-/* Get a natural prime number not less than a number.
- `num' specified a natural number.
- The return value is a prime number not less than the specified number. */
-static int dpgetprime(int num){
- int primes[] = {
- 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 43, 47, 53, 59, 61, 71, 79, 83,
- 89, 103, 109, 113, 127, 139, 157, 173, 191, 199, 223, 239, 251, 283, 317, 349,
- 383, 409, 443, 479, 509, 571, 631, 701, 761, 829, 887, 953, 1021, 1151, 1279,
- 1399, 1531, 1663, 1789, 1913, 2039, 2297, 2557, 2803, 3067, 3323, 3583, 3833,
- 4093, 4603, 5119, 5623, 6143, 6653, 7159, 7673, 8191, 9209, 10223, 11261,
- 12281, 13309, 14327, 15359, 16381, 18427, 20479, 22511, 24571, 26597, 28669,
- 30713, 32749, 36857, 40949, 45053, 49139, 53239, 57331, 61417, 65521, 73727,
- 81919, 90107, 98299, 106487, 114679, 122869, 131071, 147451, 163819, 180221,
- 196597, 212987, 229373, 245759, 262139, 294911, 327673, 360439, 393209, 425977,
- 458747, 491503, 524287, 589811, 655357, 720887, 786431, 851957, 917503, 982981,
- 1048573, 1179641, 1310719, 1441771, 1572853, 1703903, 1835003, 1966079,
- 2097143, 2359267, 2621431, 2883577, 3145721, 3407857, 3670013, 3932153,
- 4194301, 4718579, 5242877, 5767129, 6291449, 6815741, 7340009, 7864301,
- 8388593, 9437179, 10485751, 11534329, 12582893, 13631477, 14680063, 15728611,
- 16777213, 18874367, 20971507, 23068667, 25165813, 27262931, 29360087, 31457269,
- 33554393, 37748717, 41943023, 46137319, 50331599, 54525917, 58720253, 62914549,
- 67108859, 75497467, 83886053, 92274671, 100663291, 109051903, 117440509,
- 125829103, 134217689, 150994939, 167772107, 184549373, 201326557, 218103799,
- 234881011, 251658227, 268435399, 301989881, 335544301, 369098707, 402653171,
- 436207613, 469762043, 503316469, 536870909, 603979769, 671088637, 738197503,
- 805306357, 872415211, 939524087, 1006632947, 1073741789, 1207959503,
- 1342177237, 1476394991, 1610612711, 1744830457, 1879048183, 2013265907, -1
- };
- int i;
- assert(num > 0);
- for(i = 0; primes[i] > 0; i++){
- if(num <= primes[i]) return primes[i];
- }
- return primes[i-1];
-}
-
-
-/* Get the padding size of a record.
- `vsiz' specifies the size of the value of a record.
- The return value is the padding size of a record. */
-static int dppadsize(DEPOT *depot, int ksiz, int vsiz){
- int pad;
- assert(depot && vsiz >= 0);
- if(depot->align > 0){
- return depot->align - (depot->fsiz + DP_RHNUM * sizeof(int) + ksiz + vsiz) % depot->align;
- } else if(depot->align < 0){
- pad = (int)(vsiz * (2.0 / (1 << -(depot->align))));
- if(vsiz + pad >= DP_FSBLKSIZ){
- if(vsiz <= DP_FSBLKSIZ) pad = 0;
- if(depot->fsiz % DP_FSBLKSIZ == 0){
- return (pad / DP_FSBLKSIZ) * DP_FSBLKSIZ + DP_FSBLKSIZ -
- (depot->fsiz + DP_RHNUM * sizeof(int) + ksiz + vsiz) % DP_FSBLKSIZ;
- } else {
- return (pad / (DP_FSBLKSIZ / 2)) * (DP_FSBLKSIZ / 2) + (DP_FSBLKSIZ / 2) -
- (depot->fsiz + DP_RHNUM * sizeof(int) + ksiz + vsiz) % (DP_FSBLKSIZ / 2);
- }
- } else {
- return pad >= DP_RHNUM * sizeof(int) ? pad : DP_RHNUM * sizeof(int);
- }
- }
- return 0;
-}
-
-
-/* Get the size of a record in a database file.
- `head' specifies the header of a record.
- The return value is the size of a record in a database file. */
-static int dprecsize(int *head){
- assert(head);
- return DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] + head[DP_RHIPSIZ];
-}
-
-
-/* Read the header of a record.
- `depot' specifies a database handle.
- `off' specifies an offset of the database file.
- `head' specifies a buffer for the header.
- `ebuf' specifies the pointer to the entity buffer.
- `eep' specifies the pointer to a variable to which whether ebuf was used is assigned.
- The return value is true if successful, else, it is false. */
-static int dprechead(DEPOT *depot, int off, int *head, char *ebuf, int *eep){
- assert(depot && off >= 0 && head);
- if(off > depot->fsiz){
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- return FALSE;
- }
- if(ebuf){
- *eep = FALSE;
- if(off < depot->fsiz - DP_ENTBUFSIZ){
- *eep = TRUE;
- if(!dpseekread(depot->fd, off, ebuf, DP_ENTBUFSIZ)) return FALSE;
- memcpy(head, ebuf, DP_RHNUM * sizeof(int));
- if(head[DP_RHIKSIZ] < 0 || head[DP_RHIVSIZ] < 0 || head[DP_RHIPSIZ] < 0 ||
- head[DP_RHILEFT] < 0 || head[DP_RHIRIGHT] < 0){
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- return FALSE;
- }
- return TRUE;
- }
- }
- if(!dpseekread(depot->fd, off, head, DP_RHNUM * sizeof(int))) return FALSE;
- if(head[DP_RHIKSIZ] < 0 || head[DP_RHIVSIZ] < 0 || head[DP_RHIPSIZ] < 0 ||
- head[DP_RHILEFT] < 0 || head[DP_RHIRIGHT] < 0){
- dpecodeset(DP_EBROKEN, __FILE__, __LINE__);
- return FALSE;
- }
- return TRUE;
-}
-
-
-/* Read the entitiy of the key of a record.
- `depot' specifies a database handle.
- `off' specifies an offset of the database file.
- `head' specifies the header of a record.
- The return value is a key data whose region is allocated by `malloc', or NULL on failure. */
-static char *dpreckey(DEPOT *depot, int off, int *head){
- char *kbuf;
- int ksiz;
- assert(depot && off >= 0);
- ksiz = head[DP_RHIKSIZ];
- if(!(kbuf = malloc(ksiz + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- return NULL;
- }
- if(!dpseekread(depot->fd, off + DP_RHNUM * sizeof(int), kbuf, ksiz)){
- free(kbuf);
- return NULL;
- }
- kbuf[ksiz] = '\0';
- return kbuf;
-}
-
-
-/* Read the entitiy of the value of a record.
- `depot' specifies a database handle.
- `off' specifies an offset of the database file.
- `head' specifies the header of a record.
- `start' specifies the offset address of the beginning of the region of the value to be read.
- `max' specifies the max size to be read. If it is negative, the size to read is unlimited.
- The return value is a value data whose region is allocated by `malloc', or NULL on failure. */
-static char *dprecval(DEPOT *depot, int off, int *head, int start, int max){
- char *vbuf;
- int vsiz;
- assert(depot && off >= 0 && start >= 0);
- head[DP_RHIVSIZ] -= start;
- if(max < 0){
- vsiz = head[DP_RHIVSIZ];
- } else {
- vsiz = max < head[DP_RHIVSIZ] ? max : head[DP_RHIVSIZ];
- }
- if(!(vbuf = malloc(vsiz + 1))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- return NULL;
- }
- if(!dpseekread(depot->fd, off + DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + start, vbuf, vsiz)){
- free(vbuf);
- return NULL;
- }
- vbuf[vsiz] = '\0';
- return vbuf;
-}
-
-
-/* Read the entitiy of the value of a record and write it into a given buffer.
- `depot' specifies a database handle.
- `off' specifies an offset of the database file.
- `head' specifies the header of a record.
- `start' specifies the offset address of the beginning of the region of the value to be read.
- `max' specifies the max size to be read. It shuld be less than the size of the writing buffer.
- If successful, the return value is the size of the written data, else, it is -1. */
-static int dprecvalwb(DEPOT *depot, int off, int *head, int start, int max, char *vbuf){
- int vsiz;
- assert(depot && off >= 0 && start >= 0 && max >= 0 && vbuf);
- head[DP_RHIVSIZ] -= start;
- vsiz = max < head[DP_RHIVSIZ] ? max : head[DP_RHIVSIZ];
- if(!dpseekread(depot->fd, off + DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + start, vbuf, vsiz))
- return -1;
- return vsiz;
-}
-
-
-/* Compare two keys.
- `abuf' specifies the pointer to the region of the former.
- `asiz' specifies the size of the region.
- `bbuf' specifies the pointer to the region of the latter.
- `bsiz' specifies the size of the region.
- The return value is 0 if two equals, positive if the formar is big, else, negative. */
-static int dpkeycmp(const char *abuf, int asiz, const char *bbuf, int bsiz){
- assert(abuf && asiz >= 0 && bbuf && bsiz >= 0);
- if(asiz > bsiz) return 1;
- if(asiz < bsiz) return -1;
- return memcmp(abuf, bbuf, asiz);
-}
-
-
-/* Search for a record.
- `depot' specifies a database handle.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region.
- `hash' specifies the second hash value of the key.
- `bip' specifies the pointer to the region to assign the index of the corresponding record.
- `offp' specifies the pointer to the region to assign the last visited node in the hash chain,
- or, -1 if the hash chain is empty.
- `entp' specifies the offset of the last used joint, or, -1 if the hash chain is empty.
- `head' specifies the pointer to the region to store the header of the last visited record in.
- `ebuf' specifies the pointer to the entity buffer.
- `eep' specifies the pointer to a variable to which whether ebuf was used is assigned.
- `delhit' specifies whether a deleted record corresponds or not.
- The return value is 0 if successful, 1 if there is no corresponding record, -1 on error. */
-static int dprecsearch(DEPOT *depot, const char *kbuf, int ksiz, int hash, int *bip, int *offp,
- int *entp, int *head, char *ebuf, int *eep, int delhit){
- int off, entoff, thash, kcmp;
- char stkey[DP_STKBUFSIZ], *tkey;
- assert(depot && kbuf && ksiz >= 0 && hash >= 0 && bip && offp && entp && head && ebuf && eep);
- DP_FIRSTHASH(thash, kbuf, ksiz);
- *bip = thash % depot->bnum;
- off = depot->buckets[*bip];
- *offp = -1;
- *entp = -1;
- entoff = -1;
- *eep = FALSE;
- while(off != 0){
- if(!dprechead(depot, off, head, ebuf, eep)) return -1;
- thash = head[DP_RHIHASH];
- if(hash > thash){
- entoff = off + DP_RHILEFT * sizeof(int);
- off = head[DP_RHILEFT];
- } else if(hash < thash){
- entoff = off + DP_RHIRIGHT * sizeof(int);
- off = head[DP_RHIRIGHT];
- } else {
- if(*eep && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] <= DP_ENTBUFSIZ){
- kcmp = dpkeycmp(kbuf, ksiz, ebuf + (DP_RHNUM * sizeof(int)), head[DP_RHIKSIZ]);
- } else if(head[DP_RHIKSIZ] > DP_STKBUFSIZ){
- if(!(tkey = dpreckey(depot, off, head))) return -1;
- kcmp = dpkeycmp(kbuf, ksiz, tkey, head[DP_RHIKSIZ]);
- free(tkey);
- } else {
- if(!dpseekread(depot->fd, off + DP_RHNUM * sizeof(int), stkey, head[DP_RHIKSIZ]))
- return -1;
- kcmp = dpkeycmp(kbuf, ksiz, stkey, head[DP_RHIKSIZ]);
- }
- if(kcmp > 0){
- entoff = off + DP_RHILEFT * sizeof(int);
- off = head[DP_RHILEFT];
- } else if(kcmp < 0){
- entoff = off + DP_RHIRIGHT * sizeof(int);
- off = head[DP_RHIRIGHT];
- } else {
- if(!delhit && (head[DP_RHIFLAGS] & DP_RECFDEL)){
- entoff = off + DP_RHILEFT * sizeof(int);
- off = head[DP_RHILEFT];
- } else {
- *offp = off;
- *entp = entoff;
- return 0;
- }
- }
- }
- }
- *offp = off;
- *entp = entoff;
- return 1;
-}
-
-
-/* Overwrite a record.
- `depot' specifies a database handle.
- `off' specifies the offset of the database file.
- `rsiz' specifies the size of the existing record.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region.
- `vbuf' specifies the pointer to the region of a value.
- `vsiz' specifies the size of the region.
- `hash' specifies the second hash value of the key.
- `left' specifies the offset of the left child.
- `right' specifies the offset of the right child.
- The return value is true if successful, or, false on failure. */
-static int dprecrewrite(DEPOT *depot, int off, int rsiz, const char *kbuf, int ksiz,
- const char *vbuf, int vsiz, int hash, int left, int right){
- char ebuf[DP_WRTBUFSIZ];
- int i, head[DP_RHNUM], asiz, hoff, koff, voff, mi, min, size;
- assert(depot && off >= 1 && rsiz > 0 && kbuf && ksiz >= 0 && vbuf && vsiz >= 0);
- head[DP_RHIFLAGS] = 0;
- head[DP_RHIHASH] = hash;
- head[DP_RHIKSIZ] = ksiz;
- head[DP_RHIVSIZ] = vsiz;
- head[DP_RHIPSIZ] = rsiz - sizeof(head) - ksiz - vsiz;
- head[DP_RHILEFT] = left;
- head[DP_RHIRIGHT] = right;
- asiz = sizeof(head) + ksiz + vsiz;
- if(depot->fbpsiz > DP_FBPOOLSIZ * 4 && head[DP_RHIPSIZ] > asiz){
- rsiz = (head[DP_RHIPSIZ] - asiz) / 2 + asiz;
- head[DP_RHIPSIZ] -= rsiz;
- } else {
- rsiz = 0;
- }
- if(asiz <= DP_WRTBUFSIZ){
- memcpy(ebuf, head, sizeof(head));
- memcpy(ebuf + sizeof(head), kbuf, ksiz);
- memcpy(ebuf + sizeof(head) + ksiz, vbuf, vsiz);
- if(!dpseekwrite(depot->fd, off, ebuf, asiz)) return FALSE;
- } else {
- hoff = off;
- koff = hoff + sizeof(head);
- voff = koff + ksiz;
- if(!dpseekwrite(depot->fd, hoff, head, sizeof(head)) ||
- !dpseekwrite(depot->fd, koff, kbuf, ksiz) || !dpseekwrite(depot->fd, voff, vbuf, vsiz))
- return FALSE;
- }
- if(rsiz > 0){
- off += sizeof(head) + ksiz + vsiz + head[DP_RHIPSIZ];
- head[DP_RHIFLAGS] = DP_RECFDEL | DP_RECFREUSE;
- head[DP_RHIHASH] = hash;
- head[DP_RHIKSIZ] = ksiz;
- head[DP_RHIVSIZ] = vsiz;
- head[DP_RHIPSIZ] = rsiz - sizeof(head) - ksiz - vsiz;
- head[DP_RHILEFT] = 0;
- head[DP_RHIRIGHT] = 0;
- if(!dpseekwrite(depot->fd, off, head, sizeof(head))) return FALSE;
- size = dprecsize(head);
- mi = -1;
- min = -1;
- for(i = 0; i < depot->fbpsiz; i += 2){
- if(depot->fbpool[i] == -1){
- depot->fbpool[i] = off;
- depot->fbpool[i+1] = size;
- dpfbpoolcoal(depot);
- mi = -1;
- break;
- }
- if(mi == -1 || depot->fbpool[i+1] < min){
- mi = i;
- min = depot->fbpool[i+1];
- }
- }
- if(mi >= 0 && size > min){
- depot->fbpool[mi] = off;
- depot->fbpool[mi+1] = size;
- dpfbpoolcoal(depot);
- }
- }
- return TRUE;
-}
-
-
-/* Write a record at the end of a database file.
- `depot' specifies a database handle.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region.
- `vbuf' specifies the pointer to the region of a value.
- `vsiz' specifies the size of the region.
- `hash' specifies the second hash value of the key.
- `left' specifies the offset of the left child.
- `right' specifies the offset of the right child.
- The return value is the offset of the record, or, -1 on failure. */
-static int dprecappend(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- int hash, int left, int right){
- char ebuf[DP_WRTBUFSIZ], *hbuf;
- int head[DP_RHNUM], asiz, psiz, off;
- assert(depot && kbuf && ksiz >= 0 && vbuf && vsiz >= 0);
- psiz = dppadsize(depot, ksiz, vsiz);
- head[DP_RHIFLAGS] = 0;
- head[DP_RHIHASH] = hash;
- head[DP_RHIKSIZ] = ksiz;
- head[DP_RHIVSIZ] = vsiz;
- head[DP_RHIPSIZ] = psiz;
- head[DP_RHILEFT] = left;
- head[DP_RHIRIGHT] = right;
- asiz = sizeof(head) + ksiz + vsiz + psiz;
- off = depot->fsiz;
- if(asiz <= DP_WRTBUFSIZ){
- memcpy(ebuf, head, sizeof(head));
- memcpy(ebuf + sizeof(head), kbuf, ksiz);
- memcpy(ebuf + sizeof(head) + ksiz, vbuf, vsiz);
- memset(ebuf + sizeof(head) + ksiz + vsiz, 0, psiz);
- if(!dpseekwrite(depot->fd, off, ebuf, asiz)) return -1;
- } else {
- if(!(hbuf = malloc(asiz))){
- dpecodeset(DP_EALLOC, __FILE__, __LINE__);
- return -1;
- }
- memcpy(hbuf, head, sizeof(head));
- memcpy(hbuf + sizeof(head), kbuf, ksiz);
- memcpy(hbuf + sizeof(head) + ksiz, vbuf, vsiz);
- memset(hbuf + sizeof(head) + ksiz + vsiz, 0, psiz);
- if(!dpseekwrite(depot->fd, off, hbuf, asiz)){
- free(hbuf);
- return -1;
- }
- free(hbuf);
- }
- depot->fsiz += asiz;
- return off;
-}
-
-
-/* Overwrite the value of a record.
- `depot' specifies a database handle.
- `off' specifies the offset of the database file.
- `head' specifies the header of the record.
- `vbuf' specifies the pointer to the region of a value.
- `vsiz' specifies the size of the region.
- `cat' specifies whether it is concatenate mode or not.
- The return value is true if successful, or, false on failure. */
-static int dprecover(DEPOT *depot, int off, int *head, const char *vbuf, int vsiz, int cat){
- int i, hsiz, hoff, voff;
- assert(depot && off >= 0 && head && vbuf && vsiz >= 0);
- for(i = 0; i < depot->fbpsiz; i += 2){
- if(depot->fbpool[i] == off){
- depot->fbpool[i] = -1;
- depot->fbpool[i+1] = -1;
- break;
- }
- }
- if(cat){
- head[DP_RHIFLAGS] = 0;
- head[DP_RHIPSIZ] -= vsiz;
- head[DP_RHIVSIZ] += vsiz;
- hsiz = DP_RHNUM * sizeof(int);
- hoff = off;
- voff = hoff + DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] - vsiz;
- } else {
- head[DP_RHIFLAGS] = 0;
- head[DP_RHIPSIZ] += head[DP_RHIVSIZ] - vsiz;
- head[DP_RHIVSIZ] = vsiz;
- hsiz = DP_RHNUM * sizeof(int);
- hoff = off;
- voff = hoff + DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ];
- }
- if(!dpseekwrite(depot->fd, hoff, head, hsiz) ||
- !dpseekwrite(depot->fd, voff, vbuf, vsiz)) return FALSE;
- return TRUE;
-}
-
-
-/* Delete a record.
- `depot' specifies a database handle.
- `off' specifies the offset of the database file.
- `head' specifies the header of the record.
- `reusable' specifies whether the region is reusable or not.
- The return value is true if successful, or, false on failure. */
-static int dprecdelete(DEPOT *depot, int off, int *head, int reusable){
- int i, mi, min, size;
- assert(depot && off >= 0 && head);
- if(reusable){
- size = dprecsize(head);
- mi = -1;
- min = -1;
- for(i = 0; i < depot->fbpsiz; i += 2){
- if(depot->fbpool[i] == -1){
- depot->fbpool[i] = off;
- depot->fbpool[i+1] = size;
- dpfbpoolcoal(depot);
- mi = -1;
- break;
- }
- if(mi == -1 || depot->fbpool[i+1] < min){
- mi = i;
- min = depot->fbpool[i+1];
- }
- }
- if(mi >= 0 && size > min){
- depot->fbpool[mi] = off;
- depot->fbpool[mi+1] = size;
- dpfbpoolcoal(depot);
- }
- }
- return dpseekwritenum(depot->fd, off + DP_RHIFLAGS * sizeof(int),
- DP_RECFDEL | (reusable ? DP_RECFREUSE : 0));
-}
-
-
-/* Make contiguous records of the free block pool coalesce.
- `depot' specifies a database handle. */
-static void dpfbpoolcoal(DEPOT *depot){
- int i;
- assert(depot);
- if(depot->fbpinc++ <= depot->fbpsiz / 4) return;
- depot->fbpinc = 0;
- qsort(depot->fbpool, depot->fbpsiz / 2, sizeof(int) * 2, dpfbpoolcmp);
- for(i = 2; i < depot->fbpsiz; i += 2){
- if(depot->fbpool[i-2] > 0 &&
- depot->fbpool[i-2] + depot->fbpool[i-1] - depot->fbpool[i] == 0){
- depot->fbpool[i] = depot->fbpool[i-2];
- depot->fbpool[i+1] += depot->fbpool[i-1];
- depot->fbpool[i-2] = -1;
- depot->fbpool[i-1] = -1;
- }
- }
-}
-
-
-/* Compare two records of the free block pool.
- `a' specifies the pointer to one record.
- `b' specifies the pointer to the other record.
- The return value is 0 if two equals, positive if the formar is big, else, negative. */
-static int dpfbpoolcmp(const void *a, const void *b){
- assert(a && b);
- return *(int *)a - *(int *)b;
-}
-
-
-
-/* END OF FILE */
diff --git a/src/qdbm/depot.h b/src/qdbm/depot.h
deleted file mode 100644
index f93aeea..0000000
--- a/src/qdbm/depot.h
+++ /dev/null
@@ -1,493 +0,0 @@
-/*************************************************************************************************
- * The basic API of QDBM
- * Copyright (C) 2000-2006 Mikio Hirabayashi
- * This file is part of QDBM, Quick Database Manager.
- * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU
- * Lesser General Public License as published by the Free Software Foundation; either version
- * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- * You should have received a copy of the GNU Lesser General Public License along with QDBM; if
- * not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *************************************************************************************************/
-
-
-#ifndef _DEPOT_H /* duplication check */
-#define _DEPOT_H
-
-#if defined(__cplusplus) /* export for C++ */
-extern "C" {
-#endif
-
-
-#include <stdlib.h>
-#include <time.h>
-
-
-#if defined(_MSC_VER) && !defined(QDBM_INTERNAL) && !defined(QDBM_STATIC)
-#define MYEXTERN extern __declspec(dllimport)
-#else
-#define MYEXTERN extern
-#endif
-
-
-
-/*************************************************************************************************
- * API
- *************************************************************************************************/
-
-
-typedef struct { /* type of structure for a database handle */
- char *name; /* name of the database file */
- int wmode; /* whether to be writable */
- int inode; /* inode of the database file */
- time_t mtime; /* last modified time of the database */
- int fd; /* file descriptor of the database file */
- int fsiz; /* size of the database file */
- char *map; /* pointer to the mapped memory */
- int msiz; /* size of the mapped memory */
- int *buckets; /* pointer to the bucket array */
- int bnum; /* number of the bucket array */
- int rnum; /* number of records */
- int fatal; /* whether a fatal error occured */
- int ioff; /* offset of the iterator */
- int *fbpool; /* free block pool */
- int fbpsiz; /* size of the free block pool */
- int fbpinc; /* incrementor of update of the free block pool */
- int align; /* basic size of alignment */
-} DEPOT;
-
-enum { /* enumeration for error codes */
- DP_ENOERR, /* no error */
- DP_EFATAL, /* with fatal error */
- DP_EMODE, /* invalid mode */
- DP_EBROKEN, /* broken database file */
- DP_EKEEP, /* existing record */
- DP_ENOITEM, /* no item found */
- DP_EALLOC, /* memory allocation error */
- DP_EMAP, /* memory mapping error */
- DP_EOPEN, /* open error */
- DP_ECLOSE, /* close error */
- DP_ETRUNC, /* trunc error */
- DP_ESYNC, /* sync error */
- DP_ESTAT, /* stat error */
- DP_ESEEK, /* seek error */
- DP_EREAD, /* read error */
- DP_EWRITE, /* write error */
- DP_ELOCK, /* lock error */
- DP_EUNLINK, /* unlink error */
- DP_EMKDIR, /* mkdir error */
- DP_ERMDIR, /* rmdir error */
- DP_EMISC /* miscellaneous error */
-};
-
-enum { /* enumeration for open modes */
- DP_OREADER = 1 << 0, /* open as a reader */
- DP_OWRITER = 1 << 1, /* open as a writer */
- DP_OCREAT = 1 << 2, /* a writer creating */
- DP_OTRUNC = 1 << 3, /* a writer truncating */
- DP_ONOLCK = 1 << 4, /* open without locking */
- DP_OLCKNB = 1 << 5, /* lock without blocking */
- DP_OSPARSE = 1 << 6 /* create as a sparse file */
-};
-
-enum { /* enumeration for write modes */
- DP_DOVER, /* overwrite an existing value */
- DP_DKEEP, /* keep an existing value */
- DP_DCAT /* concatenate values */
-};
-
-
-/* String containing the version information. */
-MYEXTERN const char *dpversion;
-
-
-/* Last happened error code. */
-#define dpecode (*dpecodeptr())
-
-
-/* Get a message string corresponding to an error code.
- `ecode' specifies an error code.
- The return value is the message string of the error code. The region of the return value
- is not writable. */
-const char *dperrmsg(int ecode);
-
-
-/* Get a database handle.
- `name' specifies the name of a database file.
- `omode' specifies the connection mode: `DP_OWRITER' as a writer, `DP_OREADER' as a reader.
- If the mode is `DP_OWRITER', the following may be added by bitwise or: `DP_OCREAT', which
- means it creates a new database if not exist, `DP_OTRUNC', which means it creates a new
- database regardless if one exists. Both of `DP_OREADER' and `DP_OWRITER' can be added to by
- bitwise or: `DP_ONOLCK', which means it opens a database file without file locking, or
- `DP_OLCKNB', which means locking is performed without blocking. `DP_OCREAT' can be added to
- by bitwise or: `DP_OSPARSE', which means it creates a database file as a sparse file.
- `bnum' specifies the number of elements of the bucket array. If it is not more than 0,
- the default value is specified. The size of a bucket array is determined on creating,
- and can not be changed except for by optimization of the database. Suggested size of a
- bucket array is about from 0.5 to 4 times of the number of all records to store.
- The return value is the database handle or `NULL' if it is not successful.
- While connecting as a writer, an exclusive lock is invoked to the database file.
- While connecting as a reader, a shared lock is invoked to the database file. The thread
- blocks until the lock is achieved. If `DP_ONOLCK' is used, the application is responsible
- for exclusion control. */
-DEPOT *dpopen(const char *name, int omode, int bnum);
-
-
-/* Close a database handle.
- `depot' specifies a database handle.
- If successful, the return value is true, else, it is false.
- Because the region of a closed handle is released, it becomes impossible to use the handle.
- Updating a database is assured to be written when the handle is closed. If a writer opens
- a database but does not close it appropriately, the database will be broken. */
-int dpclose(DEPOT *depot);
-
-
-/* Store a record.
- `depot' specifies a database handle connected as a writer.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned
- with `strlen(kbuf)'.
- `vbuf' specifies the pointer to the region of a value.
- `vsiz' specifies the size of the region of the value. If it is negative, the size is
- assigned with `strlen(vbuf)'.
- `dmode' specifies behavior when the key overlaps, by the following values: `DP_DOVER',
- which means the specified value overwrites the existing one, `DP_DKEEP', which means the
- existing value is kept, `DP_DCAT', which means the specified value is concatenated at the
- end of the existing value.
- If successful, the return value is true, else, it is false. */
-int dpput(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
-
-
-/* Delete a record.
- `depot' specifies a database handle connected as a writer.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned
- with `strlen(kbuf)'.
- If successful, the return value is true, else, it is false. False is returned when no
- record corresponds to the specified key. */
-int dpout(DEPOT *depot, const char *kbuf, int ksiz);
-
-
-/* Retrieve a record.
- `depot' specifies a database handle.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned
- with `strlen(kbuf)'.
- `start' specifies the offset address of the beginning of the region of the value to be read.
- `max' specifies the max size to be read. If it is negative, the size to read is unlimited.
- `sp' specifies the pointer to a variable to which the size of the region of the return
- value is assigned. If it is `NULL', it is not used.
- If successful, the return value is the pointer to the region of the value of the
- corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to
- the specified key or the size of the value of the corresponding record is less than `start'.
- Because an additional zero code is appended at the end of the region of the return value,
- the return value can be treated as a character string. Because the region of the return
- value is allocated with the `malloc' call, it should be released with the `free' call if it
- is no longer in use. */
-char *dpget(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, int *sp);
-
-
-/* Retrieve a record and write the value into a buffer.
- `depot' specifies a database handle.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned
- with `strlen(kbuf)'.
- `start' specifies the offset address of the beginning of the region of the value to be read.
- `max' specifies the max size to be read. It shuld be equal to or less than the size of the
- writing buffer.
- `vbuf' specifies the pointer to a buffer into which the value of the corresponding record is
- written.
- If successful, the return value is the size of the written data, else, it is -1. -1 is
- returned when no record corresponds to the specified key or the size of the value of the
- corresponding record is less than `start'.
- Note that no additional zero code is appended at the end of the region of the writing buffer. */
-int dpgetwb(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, char *vbuf);
-
-
-/* Get the size of the value of a record.
- `depot' specifies a database handle.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned
- with `strlen(kbuf)'.
- If successful, the return value is the size of the value of the corresponding record, else,
- it is -1.
- Because this function does not read the entity of a record, it is faster than `dpget'. */
-int dpvsiz(DEPOT *depot, const char *kbuf, int ksiz);
-
-
-/* Initialize the iterator of a database handle.
- `depot' specifies a database handle.
- If successful, the return value is true, else, it is false.
- The iterator is used in order to access the key of every record stored in a database. */
-int dpiterinit(DEPOT *depot);
-
-
-/* Get the next key of the iterator.
- `depot' specifies a database handle.
- `sp' specifies the pointer to a variable to which the size of the region of the return
- value is assigned. If it is `NULL', it is not used.
- If successful, the return value is the pointer to the region of the next key, else, it is
- `NULL'. `NULL' is returned when no record is to be get out of the iterator.
- Because an additional zero code is appended at the end of the region of the return value,
- the return value can be treated as a character string. Because the region of the return
- value is allocated with the `malloc' call, it should be released with the `free' call if
- it is no longer in use. It is possible to access every record by iteration of calling
- this function. However, it is not assured if updating the database is occurred while the
- iteration. Besides, the order of this traversal access method is arbitrary, so it is not
- assured that the order of storing matches the one of the traversal access. */
-char *dpiternext(DEPOT *depot, int *sp);
-
-
-/* Set alignment of a database handle.
- `depot' specifies a database handle connected as a writer.
- `align' specifies the size of alignment.
- If successful, the return value is true, else, it is false.
- If alignment is set to a database, the efficiency of overwriting values is improved.
- The size of alignment is suggested to be average size of the values of the records to be
- stored. If alignment is positive, padding whose size is multiple number of the alignment
- is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding
- is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not
- saved in a database, you should specify alignment every opening a database. */
-int dpsetalign(DEPOT *depot, int align);
-
-
-/* Set the size of the free block pool of a database handle.
- `depot' specifies a database handle connected as a writer.
- `size' specifies the size of the free block pool of a database.
- If successful, the return value is true, else, it is false.
- The default size of the free block pool is 16. If the size is greater, the space efficiency
- of overwriting values is improved with the time efficiency sacrificed. */
-int dpsetfbpsiz(DEPOT *depot, int size);
-
-
-/* Synchronize updating contents with the file and the device.
- `depot' specifies a database handle connected as a writer.
- If successful, the return value is true, else, it is false.
- This function is useful when another process uses the connected database file. */
-int dpsync(DEPOT *depot);
-
-
-/* Optimize a database.
- `depot' specifies a database handle connected as a writer.
- `bnum' specifies the number of the elements of the bucket array. If it is not more than 0,
- the default value is specified.
- If successful, the return value is true, else, it is false.
- In an alternating succession of deleting and storing with overwrite or concatenate,
- dispensable regions accumulate. This function is useful to do away with them. */
-int dpoptimize(DEPOT *depot, int bnum);
-
-
-/* Get the name of a database.
- `depot' specifies a database handle.
- If successful, the return value is the pointer to the region of the name of the database,
- else, it is `NULL'.
- Because the region of the return value is allocated with the `malloc' call, it should be
- released with the `free' call if it is no longer in use. */
-char *dpname(DEPOT *depot);
-
-
-/* Get the size of a database file.
- `depot' specifies a database handle.
- If successful, the return value is the size of the database file, else, it is -1. */
-int dpfsiz(DEPOT *depot);
-
-
-/* Get the number of the elements of the bucket array.
- `depot' specifies a database handle.
- If successful, the return value is the number of the elements of the bucket array, else, it
- is -1. */
-int dpbnum(DEPOT *depot);
-
-
-/* Get the number of the used elements of the bucket array.
- `depot' specifies a database handle.
- If successful, the return value is the number of the used elements of the bucket array,
- else, it is -1.
- This function is inefficient because it accesses all elements of the bucket array. */
-int dpbusenum(DEPOT *depot);
-
-
-/* Get the number of the records stored in a database.
- `depot' specifies a database handle.
- If successful, the return value is the number of the records stored in the database, else,
- it is -1. */
-int dprnum(DEPOT *depot);
-
-
-/* Check whether a database handle is a writer or not.
- `depot' specifies a database handle.
- The return value is true if the handle is a writer, false if not. */
-int dpwritable(DEPOT *depot);
-
-
-/* Check whether a database has a fatal error or not.
- `depot' specifies a database handle.
- The return value is true if the database has a fatal error, false if not. */
-int dpfatalerror(DEPOT *depot);
-
-
-/* Get the inode number of a database file.
- `depot' specifies a database handle.
- The return value is the inode number of the database file. */
-int dpinode(DEPOT *depot);
-
-
-/* Get the last modified time of a database.
- `depot' specifies a database handle.
- The return value is the last modified time of the database. */
-time_t dpmtime(DEPOT *depot);
-
-
-/* Get the file descriptor of a database file.
- `depot' specifies a database handle.
- The return value is the file descriptor of the database file.
- Handling the file descriptor of a database file directly is not suggested. */
-int dpfdesc(DEPOT *depot);
-
-
-/* Remove a database file.
- `name' specifies the name of a database file.
- If successful, the return value is true, else, it is false. */
-int dpremove(const char *name);
-
-
-/* Repair a broken database file.
- `name' specifies the name of a database file.
- If successful, the return value is true, else, it is false.
- There is no guarantee that all records in a repaired database file correspond to the original
- or expected state. */
-int dprepair(const char *name);
-
-
-/* Dump all records as endian independent data.
- `depot' specifies a database handle.
- `name' specifies the name of an output file.
- If successful, the return value is true, else, it is false. */
-int dpexportdb(DEPOT *depot, const char *name);
-
-
-/* Load all records from endian independent data.
- `depot' specifies a database handle connected as a writer. The database of the handle must
- be empty.
- `name' specifies the name of an input file.
- If successful, the return value is true, else, it is false. */
-int dpimportdb(DEPOT *depot, const char *name);
-
-
-/* Retrieve a record directly from a database file.
- `name' specifies the name of a database file.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned
- with `strlen(kbuf)'.
- `sp' specifies the pointer to a variable to which the size of the region of the return
- value is assigned. If it is `NULL', it is not used.
- If successful, the return value is the pointer to the region of the value of the
- corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to
- the specified key.
- Because an additional zero code is appended at the end of the region of the return value,
- the return value can be treated as a character string. Because the region of the return
- value is allocated with the `malloc' call, it should be released with the `free' call if it
- is no longer in use. Although this function can be used even while the database file is
- locked by another process, it is not assured that recent updated is reflected. */
-char *dpsnaffle(const char *name, const char *kbuf, int ksiz, int *sp);
-
-
-/* Hash function used inside Depot.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned
- with `strlen(kbuf)'.
- The return value is the hash value of 31 bits length computed from the key.
- This function is useful when an application calculates the state of the inside bucket array. */
-int dpinnerhash(const char *kbuf, int ksiz);
-
-
-/* Hash function which is independent from the hash functions used inside Depot.
- `kbuf' specifies the pointer to the region of a key.
- `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned
- with `strlen(kbuf)'.
- The return value is the hash value of 31 bits length computed from the key.
- This function is useful when an application uses its own hash algorithm outside Depot. */
-int dpouterhash(const char *kbuf, int ksiz);
-
-
-/* Get a natural prime number not less than a number.
- `num' specified a natural number.
- The return value is a natural prime number not less than the specified number.
- This function is useful when an application determines the size of a bucket array of its
- own hash algorithm. */
-int dpprimenum(int num);
-
-
-
-/*************************************************************************************************
- * features for experts
- *************************************************************************************************/
-
-
-#define _QDBM_VERSION "1.8.75"
-#define _QDBM_LIBVER 1411
-
-
-/* Name of the operating system. */
-MYEXTERN const char *dpsysname;
-
-
-/* File descriptor for debugging output. */
-MYEXTERN int dpdbgfd;
-
-
-/* Whether this build is reentrant. */
-MYEXTERN const int dpisreentrant;
-
-
-/* Set the last happened error code.
- `ecode' specifies the error code.
- `line' specifies the number of the line where the error happened. */
-void dpecodeset(int ecode, const char *file, int line);
-
-
-/* Get the pointer of the variable of the last happened error code.
- The return value is the pointer of the variable. */
-int *dpecodeptr(void);
-
-
-/* Synchronize updating contents on memory.
- `depot' specifies a database handle connected as a writer.
- If successful, the return value is true, else, it is false. */
-int dpmemsync(DEPOT *depot);
-
-
-/* Synchronize updating contents on memory, not physically.
- `depot' specifies a database handle connected as a writer.
- If successful, the return value is true, else, it is false. */
-int dpmemflush(DEPOT *depot);
-
-
-/* Get flags of a database.
- `depot' specifies a database handle.
- The return value is the flags of a database. */
-int dpgetflags(DEPOT *depot);
-
-
-/* Set flags of a database.
- `depot' specifies a database handle connected as a writer.
- `flags' specifies flags to set. Least ten bits are reserved for internal use.
- If successful, the return value is true, else, it is false. */
-int dpsetflags(DEPOT *depot, int flags);
-
-
-
-#undef MYEXTERN
-
-#if defined(__cplusplus) /* export for C++ */
-}
-#endif
-
-#endif /* duplication check */
-
-
-/* END OF FILE */
diff --git a/src/qdbm/myconf.c b/src/qdbm/myconf.c
deleted file mode 100644
index ae13aba..0000000
--- a/src/qdbm/myconf.c
+++ /dev/null
@@ -1,1114 +0,0 @@
-/*************************************************************************************************
- * Emulation of system calls
- * Copyright (C) 2000-2006 Mikio Hirabayashi
- * This file is part of QDBM, Quick Database Manager.
- * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU
- * Lesser General Public License as published by the Free Software Foundation; either version
- * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- * You should have received a copy of the GNU Lesser General Public License along with QDBM; if
- * not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *************************************************************************************************/
-
-
-#include "myconf.h"
-
-
-
-/*************************************************************************************************
- * for dosish filesystems
- *************************************************************************************************/
-
-
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || defined(_SYS_CYGWIN_)
-
-
-#define DOSPATHBUFSIZ 8192
-
-
-int _qdbm_win32_lstat(const char *pathname, struct stat *buf){
- char pbuf[DOSPATHBUFSIZ], *p;
- int inode;
- if(stat(pathname, buf) == -1) return -1;
- if(GetFullPathName(pathname, DOSPATHBUFSIZ, pbuf, &p) != 0){
- inode = 11003;
- for(p = pbuf; *p != '\0'; p++){
- inode = inode * 31 + *(unsigned char *)p;
- }
- buf->st_ino = (inode * 911) & 0x7FFF;
- }
- return 0;
-}
-
-
-#endif
-
-
-
-/*************************************************************************************************
- * for POSIX thread
- *************************************************************************************************/
-
-
-#if defined(MYPTHREAD)
-
-
-#include <pthread.h>
-
-
-#define PTKEYMAX 8
-
-
-struct { void *ptr; pthread_key_t key; } _qdbm_ptkeys[PTKEYMAX];
-int _qdbm_ptknum = 0;
-
-
-static void *_qdbm_gettsd(void *ptr, int size, const void *initval);
-
-
-void *_qdbm_settsd(void *ptr, int size, const void *initval){
- static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
- char *val;
- if((val = _qdbm_gettsd(ptr, size, initval)) != NULL) return val;
- if(pthread_mutex_lock(&mutex) != 0) return NULL;
- if((val = _qdbm_gettsd(ptr, size, initval)) != NULL){
- pthread_mutex_unlock(&mutex);
- return val;
- }
- if(_qdbm_ptknum >= PTKEYMAX){
- pthread_mutex_unlock(&mutex);
- return NULL;
- }
- _qdbm_ptkeys[_qdbm_ptknum].ptr = ptr;
- if(pthread_key_create(&(_qdbm_ptkeys[_qdbm_ptknum].key), free) != 0){
- pthread_mutex_unlock(&mutex);
- return NULL;
- }
- if(!(val = malloc(size))){
- pthread_key_delete(_qdbm_ptkeys[_qdbm_ptknum].key);
- pthread_mutex_unlock(&mutex);
- return NULL;
- }
- memcpy(val, initval, size);
- if(pthread_setspecific(_qdbm_ptkeys[_qdbm_ptknum].key, val) != 0){
- free(val);
- pthread_key_delete(_qdbm_ptkeys[_qdbm_ptknum].key);
- pthread_mutex_unlock(&mutex);
- return NULL;
- }
- _qdbm_ptknum++;
- pthread_mutex_unlock(&mutex);
- return val;
-}
-
-
-static void *_qdbm_gettsd(void *ptr, int size, const void *initval){
- char *val;
- int i;
- for(i = 0; i < _qdbm_ptknum; i++){
- if(_qdbm_ptkeys[i].ptr == ptr){
- if(!(val = pthread_getspecific(_qdbm_ptkeys[i].key))){
- if(!(val = malloc(size))) return NULL;
- memcpy(val, initval, size);
- if(pthread_setspecific(_qdbm_ptkeys[i].key, val) != 0){
- free(val);
- return NULL;
- }
- }
- return val;
- }
- }
- return NULL;
-}
-
-
-#endif
-
-
-
-/*************************************************************************************************
- * for systems without mmap
- *************************************************************************************************/
-
-
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
-
-
-#define MMFDESCMAX 2048
-
-
-struct { void *start; HANDLE handle; } mmhandles[MMFDESCMAX];
-int mmhnum = 0;
-CRITICAL_SECTION mmcsec;
-
-
-static void _qdbm_delete_mmap_env(void);
-
-
-void *_qdbm_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset){
- static volatile long first = TRUE;
- static volatile long ready = FALSE;
- HANDLE handle;
- int i;
- if(InterlockedExchange((void *)&first, FALSE)){
- InitializeCriticalSection(&mmcsec);
- atexit(_qdbm_delete_mmap_env);
- InterlockedExchange((void *)&ready, TRUE);
- }
- while(!InterlockedCompareExchange((void *)&ready, TRUE, TRUE)){
- Sleep(1);
- }
- if(fd < 0 || flags & MAP_FIXED) return MAP_FAILED;
- if(!(handle = CreateFileMapping((HANDLE)_get_osfhandle(fd), NULL,
- (prot & PROT_WRITE) ? PAGE_READWRITE : PAGE_READONLY,
- 0, length, NULL))) return MAP_FAILED;
- if(!(start = MapViewOfFile(handle, (prot & PROT_WRITE) ? FILE_MAP_WRITE : FILE_MAP_READ,
- 0, 0, length))){
- CloseHandle(handle);
- return MAP_FAILED;
- }
- EnterCriticalSection(&mmcsec);
- if(mmhnum >= MMFDESCMAX - 1){
- UnmapViewOfFile(start);
- CloseHandle(handle);
- LeaveCriticalSection(&mmcsec);
- return MAP_FAILED;
- }
- for(i = 0; i < MMFDESCMAX; i++){
- if(!mmhandles[i].start){
- mmhandles[i].start = start;
- mmhandles[i].handle = handle;
- break;
- }
- }
- mmhnum++;
- LeaveCriticalSection(&mmcsec);
- return start;
-}
-
-
-int _qdbm_munmap(void *start, size_t length){
- HANDLE handle;
- int i;
- EnterCriticalSection(&mmcsec);
- handle = NULL;
- for(i = 0; i < MMFDESCMAX; i++){
- if(mmhandles[i].start == start){
- handle = mmhandles[i].handle;
- mmhandles[i].start = NULL;
- mmhandles[i].handle = NULL;
- break;
- }
- }
- if(!handle){
- LeaveCriticalSection(&mmcsec);
- return -1;
- }
- mmhnum--;
- LeaveCriticalSection(&mmcsec);
- if(!UnmapViewOfFile(start)){
- CloseHandle(handle);
- return -1;
- }
- if(!CloseHandle(handle)) return -1;
- return 0;
-}
-
-
-int _qdbm_msync(const void *start, size_t length, int flags){
- if(!FlushViewOfFile(start, length)) return -1;
- return 0;
-}
-
-
-static void _qdbm_delete_mmap_env(void){
- DeleteCriticalSection(&mmcsec);
-}
-
-
-#elif defined(_SYS_FREEBSD_) || defined(_SYS_NETBSD_) || defined(_SYS_OPENBSD_) || \
- defined(_SYS_AIX_) || defined(_SYS_RISCOS_) || defined(MYNOMMAP)
-
-
-void *_qdbm_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset){
- char *buf, *wp;
- int rv, rlen;
- if(flags & MAP_FIXED) return MAP_FAILED;
- if(lseek(fd, SEEK_SET, offset) == -1) return MAP_FAILED;
- if(!(buf = malloc(sizeof(int) * 3 + length))) return MAP_FAILED;
- wp = buf;
- *(int *)wp = fd;
- wp += sizeof(int);
- *(int *)wp = offset;
- wp += sizeof(int);
- *(int *)wp = prot;
- wp += sizeof(int);
- rlen = 0;
- while((rv = read(fd, wp + rlen, length - rlen)) > 0){
- rlen += rv;
- }
- if(rv == -1 || rlen != (int) length){
- free(buf);
- return MAP_FAILED;
- }
- return wp;
-}
-
-
-int _qdbm_munmap(void *start, size_t length){
- char *buf, *rp;
- int fd, offset, prot, rv, wlen;
- buf = (char *)start - sizeof(int) * 3;
- rp = buf;
- fd = *(int *)rp;
- rp += sizeof(int);
- offset = *(int *)rp;
- rp += sizeof(int);
- prot = *(int *)rp;
- rp += sizeof(int);
- if(prot & PROT_WRITE){
- if(lseek(fd, offset, SEEK_SET) == -1){
- free(buf);
- return -1;
- }
- wlen = 0;
- while(wlen < (int)length){
- rv = write(fd, rp + wlen, length - wlen);
- if(rv == -1){
- if(errno == EINTR) continue;
- free(buf);
- return -1;
- }
- wlen += rv;
- }
- }
- free(buf);
- return 0;
-}
-
-
-int _qdbm_msync(const void *start, size_t length, int flags){
- char *buf, *rp;
- int fd, offset, prot, rv, wlen;
- buf = (char *)start - sizeof(int) * 3;
- rp = buf;
- fd = *(int *)rp;
- rp += sizeof(int);
- offset = *(int *)rp;
- rp += sizeof(int);
- prot = *(int *)rp;
- rp += sizeof(int);
- if(prot & PROT_WRITE){
- if(lseek(fd, offset, SEEK_SET) == -1) return -1;
- wlen = 0;
- while(wlen < (int)length){
- rv = write(fd, rp + wlen, length - wlen);
- if(rv == -1){
- if(errno == EINTR) continue;
- return -1;
- }
- wlen += rv;
- }
- }
- return 0;
-}
-
-
-#endif
-
-
-
-/*************************************************************************************************
- * for reentrant time routines
- *************************************************************************************************/
-
-
-#if defined(_SYS_LINUX_) || defined(_SYS_FREEBSD_) || defined(_SYS_OPENBSD_) || \
- defined(_SYS_NETBSD_) || defined(_SYS_SUNOS_) || defined(_SYS_HPUX_) || \
- defined(_SYS_MACOSX_) || defined(_SYS_CYGWIN_)
-
-
-struct tm *_qdbm_gmtime(const time_t *timep, struct tm *result){
- return gmtime_r(timep, result);
-}
-
-
-struct tm *_qdbm_localtime(const time_t *timep, struct tm *result){
- return localtime_r(timep, result);
-}
-
-
-# else
-
-
-struct tm *_qdbm_gmtime(const time_t *timep, struct tm *result){
- return gmtime(timep);
-}
-
-
-struct tm *_qdbm_localtime(const time_t *timep, struct tm *result){
- return localtime(timep);
-}
-
-
-# endif
-
-
-
-/*************************************************************************************************
- * for systems without times
- *************************************************************************************************/
-
-
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
-
-
-clock_t _qdbm_times(struct tms *buf){
- buf->tms_utime = clock();
- buf->tms_stime = 0;
- buf->tms_cutime = 0;
- buf->tms_cstime = 0;
- return 0;
-}
-
-
-#endif
-
-
-
-/*************************************************************************************************
- * for Win32
- *************************************************************************************************/
-
-
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
-
-
-#define WINLOCKWAIT 100
-
-
-int _qdbm_win32_fcntl(int fd, int cmd, struct flock *lock){
- HANDLE fh;
- DWORD opt;
- OVERLAPPED ol;
- fh = (HANDLE)_get_osfhandle(fd);
- opt = (cmd == F_SETLK) ? LOCKFILE_FAIL_IMMEDIATELY : 0;
- if(lock->l_type == F_WRLCK) opt |= LOCKFILE_EXCLUSIVE_LOCK;
- memset(&ol, 0, sizeof(OVERLAPPED));
- ol.Offset = INT_MAX;
- ol.OffsetHigh = 0;
- ol.hEvent = 0;
- if(!LockFileEx(fh, opt, 0, 1, 0, &ol)){
- if(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED){
- while(TRUE){
- if(LockFile(fh, 0, 0, 1, 0)) return 0;
- Sleep(WINLOCKWAIT);
- }
- }
- return -1;
- }
- return 0;
-}
-
-
-#endif
-
-
-#if defined(_SYS_MSVC_)
-
-
-DIR *_qdbm_win32_opendir(const char *name){
- char expr[8192];
- int len;
- DIR *dir;
- HANDLE fh;
- WIN32_FIND_DATA data;
- len = strlen(name);
- if(len > 0 && name[len-1] == MYPATHCHR){
- sprintf(expr, "%s*", name);
- } else {
- sprintf(expr, "%s%c*", name, MYPATHCHR);
- }
- if((fh = FindFirstFile(expr, &data)) == INVALID_HANDLE_VALUE) return NULL;
- if(!(dir = malloc(sizeof(DIR)))){
- FindClose(fh);
- return NULL;
- }
- dir->fh = fh;
- dir->data = data;
- dir->first = TRUE;
- return dir;
-}
-
-
-int _qdbm_win32_closedir(DIR *dir){
- if(!FindClose(dir->fh)){
- free(dir);
- return -1;
- }
- free(dir);
- return 0;
-}
-
-
-struct dirent *_qdbm_win32_readdir(DIR *dir){
- if(dir->first){
- sprintf(dir->de.d_name, "%s", dir->data.cFileName);
- dir->first = FALSE;
- return &(dir->de);
- }
- if(!FindNextFile(dir->fh, &(dir->data))) return NULL;
- sprintf(dir->de.d_name, "%s", dir->data.cFileName);
- return &(dir->de);
-}
-
-
-#endif
-
-
-
-/*************************************************************************************************
- * for checking information of the system
- *************************************************************************************************/
-
-
-#if defined(_SYS_LINUX_)
-
-
-int _qdbm_vmemavail(size_t size){
- char buf[4096], *rp;
- int fd, rv, bsiz;
- double avail;
- if((fd = open("/proc/meminfo", O_RDONLY, 00644)) == -1) return TRUE;
- rv = TRUE;
- if((bsiz = read(fd, buf, sizeof(buf) - 1)) > 0){
- buf[bsiz] = '\0';
- avail = -1;
- if((rp = strstr(buf, "MemFree:")) != NULL){
- rp = strchr(rp, ':') + 1;
- avail = strtod(rp, NULL) * 1024.0;
- if((rp = strstr(buf, "SwapFree:")) != NULL){
- rp = strchr(rp, ':') + 1;
- avail += strtod(rp, NULL) * 1024.0;
- }
- if(size >= avail) rv = FALSE;
- }
- }
- close(fd);
- return rv;
-}
-
-
-#elif defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || defined(_SYS_CYGWIN_)
-
-
-int _qdbm_vmemavail(size_t size){
- MEMORYSTATUS sbuf;
- sbuf.dwLength = sizeof(MEMORYSTATUS);
- GlobalMemoryStatus(&sbuf);
- return size < sbuf.dwAvailVirtual;
-}
-
-
-#else
-
-
-int _qdbm_vmemavail(size_t size){
- return TRUE;
-}
-
-
-#endif
-
-
-
-/*************************************************************************************************
- * for ZLIB
- *************************************************************************************************/
-
-
-#if defined(MYZLIB)
-
-
-#include <zlib.h>
-
-#define ZLIBBUFSIZ 8192
-
-
-static char *_qdbm_deflate_impl(const char *ptr, int size, int *sp, int mode);
-static char *_qdbm_inflate_impl(const char *ptr, int size, int *sp, int mode);
-static unsigned int _qdbm_getcrc_impl(const char *ptr, int size);
-
-
-char *(*_qdbm_deflate)(const char *, int, int *, int) = _qdbm_deflate_impl;
-char *(*_qdbm_inflate)(const char *, int, int *, int) = _qdbm_inflate_impl;
-unsigned int (*_qdbm_getcrc)(const char *, int) = _qdbm_getcrc_impl;
-
-
-static char *_qdbm_deflate_impl(const char *ptr, int size, int *sp, int mode){
- z_stream zs;
- char *buf, *swap;
- unsigned char obuf[ZLIBBUFSIZ];
- int rv, asiz, bsiz, osiz;
- if(size < 0) size = strlen(ptr);
- zs.zalloc = Z_NULL;
- zs.zfree = Z_NULL;
- zs.opaque = Z_NULL;
- switch(mode){
- case _QDBM_ZMRAW:
- if(deflateInit2(&zs, 5, Z_DEFLATED, -15, 7, Z_DEFAULT_STRATEGY) != Z_OK)
- return NULL;
- break;
- case _QDBM_ZMGZIP:
- if(deflateInit2(&zs, 6, Z_DEFLATED, 15 + 16, 9, Z_DEFAULT_STRATEGY) != Z_OK)
- return NULL;
- break;
- default:
- if(deflateInit2(&zs, 6, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY) != Z_OK)
- return NULL;
- break;
- }
- asiz = size + 16;
- if(asiz < ZLIBBUFSIZ) asiz = ZLIBBUFSIZ;
- if(!(buf = malloc(asiz))){
- deflateEnd(&zs);
- return NULL;
- }
- bsiz = 0;
- zs.next_in = (unsigned char *)ptr;
- zs.avail_in = size;
- zs.next_out = obuf;
- zs.avail_out = ZLIBBUFSIZ;
- while((rv = deflate(&zs, Z_FINISH)) == Z_OK){
- osiz = ZLIBBUFSIZ - zs.avail_out;
- if(bsiz + osiz > asiz){
- asiz = asiz * 2 + osiz;
- if(!(swap = realloc(buf, asiz))){
- free(buf);
- deflateEnd(&zs);
- return NULL;
- }
- buf = swap;
- }
- memcpy(buf + bsiz, obuf, osiz);
- bsiz += osiz;
- zs.next_out = obuf;
- zs.avail_out = ZLIBBUFSIZ;
- }
- if(rv != Z_STREAM_END){
- free(buf);
- deflateEnd(&zs);
- return NULL;
- }
- osiz = ZLIBBUFSIZ - zs.avail_out;
- if(bsiz + osiz + 1 > asiz){
- asiz = asiz * 2 + osiz;
- if(!(swap = realloc(buf, asiz))){
- free(buf);
- deflateEnd(&zs);
- return NULL;
- }
- buf = swap;
- }
- memcpy(buf + bsiz, obuf, osiz);
- bsiz += osiz;
- buf[bsiz] = '\0';
- if(mode == _QDBM_ZMRAW) bsiz++;
- *sp = bsiz;
- deflateEnd(&zs);
- return buf;
-}
-
-
-static char *_qdbm_inflate_impl(const char *ptr, int size, int *sp, int mode){
- z_stream zs;
- char *buf, *swap;
- unsigned char obuf[ZLIBBUFSIZ];
- int rv, asiz, bsiz, osiz;
- zs.zalloc = Z_NULL;
- zs.zfree = Z_NULL;
- zs.opaque = Z_NULL;
- switch(mode){
- case _QDBM_ZMRAW:
- if(inflateInit2(&zs, -15) != Z_OK) return NULL;
- break;
- case _QDBM_ZMGZIP:
- if(inflateInit2(&zs, 15 + 16) != Z_OK) return NULL;
- break;
- default:
- if(inflateInit2(&zs, 15) != Z_OK) return NULL;
- break;
- }
- asiz = size * 2 + 16;
- if(asiz < ZLIBBUFSIZ) asiz = ZLIBBUFSIZ;
- if(!(buf = malloc(asiz))){
- inflateEnd(&zs);
- return NULL;
- }
- bsiz = 0;
- zs.next_in = (unsigned char *)ptr;
- zs.avail_in = size;
- zs.next_out = obuf;
- zs.avail_out = ZLIBBUFSIZ;
- while((rv = inflate(&zs, Z_NO_FLUSH)) == Z_OK){
- osiz = ZLIBBUFSIZ - zs.avail_out;
- if(bsiz + osiz >= asiz){
- asiz = asiz * 2 + osiz;
- if(!(swap = realloc(buf, asiz))){
- free(buf);
- inflateEnd(&zs);
- return NULL;
- }
- buf = swap;
- }
- memcpy(buf + bsiz, obuf, osiz);
- bsiz += osiz;
- zs.next_out = obuf;
- zs.avail_out = ZLIBBUFSIZ;
- }
- if(rv != Z_STREAM_END){
- free(buf);
- inflateEnd(&zs);
- return NULL;
- }
- osiz = ZLIBBUFSIZ - zs.avail_out;
- if(bsiz + osiz >= asiz){
- asiz = asiz * 2 + osiz;
- if(!(swap = realloc(buf, asiz))){
- free(buf);
- inflateEnd(&zs);
- return NULL;
- }
- buf = swap;
- }
- memcpy(buf + bsiz, obuf, osiz);
- bsiz += osiz;
- buf[bsiz] = '\0';
- if(sp) *sp = bsiz;
- inflateEnd(&zs);
- return buf;
-}
-
-
-static unsigned int _qdbm_getcrc_impl(const char *ptr, int size){
- int crc;
- if(size < 0) size = strlen(ptr);
- crc = crc32(0, Z_NULL, 0);
- return crc32(crc, (unsigned char *)ptr, size);
-}
-
-
-#else
-
-
-char *(*_qdbm_deflate)(const char *, int, int *, int) = NULL;
-char *(*_qdbm_inflate)(const char *, int, int *, int) = NULL;
-unsigned int (*_qdbm_getcrc)(const char *, int) = NULL;
-
-
-#endif
-
-
-
-/*************************************************************************************************
- * for LZO
- *************************************************************************************************/
-
-
-#if defined(MYLZO)
-
-
-#include <lzo/lzo1x.h>
-
-
-static char *_qdbm_lzoencode_impl(const char *ptr, int size, int *sp);
-static char *_qdbm_lzodecode_impl(const char *ptr, int size, int *sp);
-
-
-int _qdbm_lzo_init = FALSE;
-char *(*_qdbm_lzoencode)(const char *, int, int *) = _qdbm_lzoencode_impl;
-char *(*_qdbm_lzodecode)(const char *, int, int *) = _qdbm_lzodecode_impl;
-
-
-static char *_qdbm_lzoencode_impl(const char *ptr, int size, int *sp){
- char wrkmem[LZO1X_1_MEM_COMPRESS];
- lzo_bytep buf;
- lzo_uint bsiz;
- if(!_qdbm_lzo_init){
- if(lzo_init() != LZO_E_OK) return NULL;
- _qdbm_lzo_init = TRUE;
- }
- if(size < 0) size = strlen(ptr);
- if(!(buf = malloc(size + size / 16 + 80))) return NULL;
- if(lzo1x_1_compress((lzo_bytep)ptr, size, buf, &bsiz, wrkmem) != LZO_E_OK){
- free(buf);
- return NULL;
- }
- buf[bsiz] = '\0';
- *sp = bsiz;
- return (char *)buf;
-}
-
-
-static char *_qdbm_lzodecode_impl(const char *ptr, int size, int *sp){
- lzo_bytep buf;
- lzo_uint bsiz;
- int rat, rv;
- if(!_qdbm_lzo_init){
- if(lzo_init() != LZO_E_OK) return NULL;
- _qdbm_lzo_init = TRUE;
- }
- rat = 6;
- while(TRUE){
- bsiz = (size + 256) * rat + 3;
- if(!(buf = malloc(bsiz + 1))) return NULL;
- rv = lzo1x_decompress_safe((lzo_bytep)(ptr), size, buf, &bsiz, NULL);
- if(rv == LZO_E_OK){
- break;
- } else if(rv == LZO_E_OUTPUT_OVERRUN){
- free(buf);
- rat *= 2;
- } else {
- free(buf);
- return NULL;
- }
- }
- buf[bsiz] = '\0';
- if(sp) *sp = bsiz;
- return (char *)buf;
-}
-
-
-#else
-
-
-char *(*_qdbm_lzoencode)(const char *, int, int *) = NULL;
-char *(*_qdbm_lzodecode)(const char *, int, int *) = NULL;
-
-
-#endif
-
-
-
-/*************************************************************************************************
- * for BZIP2
- *************************************************************************************************/
-
-
-#if defined(MYBZIP)
-
-
-#include <bzlib.h>
-
-#define BZIPBUFSIZ 8192
-
-
-static char *_qdbm_bzencode_impl(const char *ptr, int size, int *sp);
-static char *_qdbm_bzdecode_impl(const char *ptr, int size, int *sp);
-
-
-char *(*_qdbm_bzencode)(const char *, int, int *) = _qdbm_bzencode_impl;
-char *(*_qdbm_bzdecode)(const char *, int, int *) = _qdbm_bzdecode_impl;
-
-
-static char *_qdbm_bzencode_impl(const char *ptr, int size, int *sp){
- bz_stream zs;
- char *buf, *swap, obuf[BZIPBUFSIZ];
- int rv, asiz, bsiz, osiz;
- if(size < 0) size = strlen(ptr);
- zs.bzalloc = NULL;
- zs.bzfree = NULL;
- zs.opaque = NULL;
- if(BZ2_bzCompressInit(&zs, 9, 0, 30) != BZ_OK) return NULL;
- asiz = size + 16;
- if(asiz < BZIPBUFSIZ) asiz = BZIPBUFSIZ;
- if(!(buf = malloc(asiz))){
- BZ2_bzCompressEnd(&zs);
- return NULL;
- }
- bsiz = 0;
- zs.next_in = (char *)ptr;
- zs.avail_in = size;
- zs.next_out = obuf;
- zs.avail_out = BZIPBUFSIZ;
- while((rv = BZ2_bzCompress(&zs, BZ_FINISH)) == BZ_FINISH_OK){
- osiz = BZIPBUFSIZ - zs.avail_out;
- if(bsiz + osiz > asiz){
- asiz = asiz * 2 + osiz;
- if(!(swap = realloc(buf, asiz))){
- free(buf);
- BZ2_bzCompressEnd(&zs);
- return NULL;
- }
- buf = swap;
- }
- memcpy(buf + bsiz, obuf, osiz);
- bsiz += osiz;
- zs.next_out = obuf;
- zs.avail_out = BZIPBUFSIZ;
- }
- if(rv != BZ_STREAM_END){
- free(buf);
- BZ2_bzCompressEnd(&zs);
- return NULL;
- }
- osiz = BZIPBUFSIZ - zs.avail_out;
- if(bsiz + osiz + 1 > asiz){
- asiz = asiz * 2 + osiz;
- if(!(swap = realloc(buf, asiz))){
- free(buf);
- BZ2_bzCompressEnd(&zs);
- return NULL;
- }
- buf = swap;
- }
- memcpy(buf + bsiz, obuf, osiz);
- bsiz += osiz;
- buf[bsiz] = '\0';
- *sp = bsiz;
- BZ2_bzCompressEnd(&zs);
- return buf;
-}
-
-
-static char *_qdbm_bzdecode_impl(const char *ptr, int size, int *sp){
- bz_stream zs;
- char *buf, *swap, obuf[BZIPBUFSIZ];
- int rv, asiz, bsiz, osiz;
- zs.bzalloc = NULL;
- zs.bzfree = NULL;
- zs.opaque = NULL;
- if(BZ2_bzDecompressInit(&zs, 0, 0) != BZ_OK) return NULL;
- asiz = size * 2 + 16;
- if(asiz < BZIPBUFSIZ) asiz = BZIPBUFSIZ;
- if(!(buf = malloc(asiz))){
- BZ2_bzDecompressEnd(&zs);
- return NULL;
- }
- bsiz = 0;
- zs.next_in = (char *)ptr;
- zs.avail_in = size;
- zs.next_out = obuf;
- zs.avail_out = BZIPBUFSIZ;
- while((rv = BZ2_bzDecompress(&zs)) == BZ_OK){
- osiz = BZIPBUFSIZ - zs.avail_out;
- if(bsiz + osiz >= asiz){
- asiz = asiz * 2 + osiz;
- if(!(swap = realloc(buf, asiz))){
- free(buf);
- BZ2_bzDecompressEnd(&zs);
- return NULL;
- }
- buf = swap;
- }
- memcpy(buf + bsiz, obuf, osiz);
- bsiz += osiz;
- zs.next_out = obuf;
- zs.avail_out = BZIPBUFSIZ;
- }
- if(rv != BZ_STREAM_END){
- free(buf);
- BZ2_bzDecompressEnd(&zs);
- return NULL;
- }
- osiz = BZIPBUFSIZ - zs.avail_out;
- if(bsiz + osiz >= asiz){
- asiz = asiz * 2 + osiz;
- if(!(swap = realloc(buf, asiz))){
- free(buf);
- BZ2_bzDecompressEnd(&zs);
- return NULL;
- }
- buf = swap;
- }
- memcpy(buf + bsiz, obuf, osiz);
- bsiz += osiz;
- buf[bsiz] = '\0';
- if(sp) *sp = bsiz;
- BZ2_bzDecompressEnd(&zs);
- return buf;
-}
-
-
-#else
-
-
-char *(*_qdbm_bzencode)(const char *, int, int *) = NULL;
-char *(*_qdbm_bzdecode)(const char *, int, int *) = NULL;
-
-
-#endif
-
-
-
-/*************************************************************************************************
- * for ICONV
- *************************************************************************************************/
-
-
-#if defined(MYICONV)
-
-
-#include <iconv.h>
-
-#define ICONVCHECKSIZ 32768
-#define ICONVMISSMAX 256
-#define ICONVALLWRAT 0.001
-
-
-static char *_qdbm_iconv_impl(const char *ptr, int size,
- const char *icode, const char *ocode, int *sp, int *mp);
-static const char *_qdbm_encname_impl(const char *ptr, int size);
-static int _qdbm_encmiss(const char *ptr, int size, const char *icode, const char *ocode);
-
-
-char *(*_qdbm_iconv)(const char *, int, const char *, const char *,
- int *, int *) = _qdbm_iconv_impl;
-const char *(*_qdbm_encname)(const char *, int) = _qdbm_encname_impl;
-
-
-static char *_qdbm_iconv_impl(const char *ptr, int size,
- const char *icode, const char *ocode, int *sp, int *mp){
- iconv_t ic;
- char *obuf, *wp, *rp;
- size_t isiz, osiz;
- int miss;
- if(size < 0) size = strlen(ptr);
- isiz = size;
- if((ic = iconv_open(ocode, icode)) == (iconv_t)-1) return NULL;
- osiz = isiz * 5;
- if(!(obuf = malloc(osiz + 1))){
- iconv_close(ic);
- return NULL;
- }
- wp = obuf;
- rp = (char *)ptr;
- miss = 0;
- while(isiz > 0){
- if(iconv(ic, (void *)&rp, &isiz, &wp, &osiz) == -1){
- if(errno == EILSEQ && (*rp == 0x5c || *rp == 0x7e)){
- *wp = *rp;
- wp++;
- rp++;
- isiz--;
- } else if(errno == EILSEQ || errno == EINVAL){
- rp++;
- isiz--;
- miss++;
- } else {
- break;
- }
- }
- }
- *wp = '\0';
- if(iconv_close(ic) == -1){
- free(obuf);
- return NULL;
- }
- if(sp) *sp = wp - obuf;
- if(mp) *mp = miss;
- return obuf;
-}
-
-
-static const char *_qdbm_encname_impl(const char *ptr, int size){
- const char *hypo;
- int i, miss, cr;
- if(size < 0) size = strlen(ptr);
- if(size > ICONVCHECKSIZ) size = ICONVCHECKSIZ;
- if(size >= 2 && (!memcmp(ptr, "\xfe\xff", 2) || !memcmp(ptr, "\xff\xfe", 2))) return "UTF-16";
- for(i = 0; i < size - 1; i += 2){
- if(ptr[i] == 0 && ptr[i+1] != 0) return "UTF-16BE";
- if(ptr[i+1] == 0 && ptr[i] != 0) return "UTF-16LE";
- }
- for(i = 0; i < size - 3; i++){
- if(ptr[i] == 0x1b){
- i++;
- if(ptr[i] == '(' && strchr("BJHI", ptr[i+1])) return "ISO-2022-JP";
- if(ptr[i] == '$' && strchr("@B(", ptr[i+1])) return "ISO-2022-JP";
- }
- }
- if(_qdbm_encmiss(ptr, size, "US-ASCII", "UTF-16BE") < 1) return "US-ASCII";
- if(_qdbm_encmiss(ptr, size, "UTF-8", "UTF-16BE") < 1) return "UTF-8";
- hypo = NULL;
- cr = FALSE;
- for(i = 0; i < size; i++){
- if(ptr[i] == 0xd){
- cr = TRUE;
- break;
- }
- }
- if(cr){
- if((miss = _qdbm_encmiss(ptr, size, "Shift_JIS", "EUC-JP")) < 1) return "Shift_JIS";
- if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "Shift_JIS";
- if((miss = _qdbm_encmiss(ptr, size, "EUC-JP", "UTF-16BE")) < 1) return "EUC-JP";
- if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "EUC-JP";
- } else {
- if((miss = _qdbm_encmiss(ptr, size, "EUC-JP", "UTF-16BE")) < 1) return "EUC-JP";
- if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "EUC-JP";
- if((miss = _qdbm_encmiss(ptr, size, "Shift_JIS", "EUC-JP")) < 1) return "Shift_JIS";
- if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "Shift_JIS";
- }
- if((miss = _qdbm_encmiss(ptr, size, "UTF-8", "UTF-16BE")) < 1) return "UTF-8";
- if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "UTF-8";
- if((miss = _qdbm_encmiss(ptr, size, "CP932", "UTF-16BE")) < 1) return "CP932";
- if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "CP932";
- return hypo ? hypo : "ISO-8859-1";
-}
-
-
-static int _qdbm_encmiss(const char *ptr, int size, const char *icode, const char *ocode){
- iconv_t ic;
- char obuf[ICONVCHECKSIZ], *wp, *rp;
- size_t isiz, osiz;
- int miss;
- isiz = size;
- if((ic = iconv_open(ocode, icode)) == (iconv_t)-1) return ICONVMISSMAX;
- miss = 0;
- rp = (char *)ptr;
- while(isiz > 0){
- osiz = ICONVCHECKSIZ;
- wp = obuf;
- if(iconv(ic, (void *)&rp, &isiz, &wp, &osiz) == -1){
- if(errno == EILSEQ || errno == EINVAL){
- rp++;
- isiz--;
- miss++;
- if(miss >= ICONVMISSMAX) break;
- } else {
- break;
- }
- }
- }
- if(iconv_close(ic) == -1) return ICONVMISSMAX;
- return miss;
-}
-
-
-#else
-
-
-char *(*_qdbm_iconv)(const char *, int, const char *, const char *, int *, int *) = NULL;
-const char *(*_qdbm_encname)(const char *, int) = NULL;
-
-
-#endif
-
-
-
-/*************************************************************************************************
- * common settings
- *************************************************************************************************/
-
-
-int _qdbm_dummyfunc(void){
- return 0;
-}
-
-
-
-/* END OF FILE */
diff --git a/src/qdbm/myconf.h b/src/qdbm/myconf.h
deleted file mode 100644
index e8fc5a8..0000000
--- a/src/qdbm/myconf.h
+++ /dev/null
@@ -1,594 +0,0 @@
-/*************************************************************************************************
- * System configurations for QDBM
- * Copyright (C) 2000-2006 Mikio Hirabayashi
- * This file is part of QDBM, Quick Database Manager.
- * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU
- * Lesser General Public License as published by the Free Software Foundation; either version
- * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- * You should have received a copy of the GNU Lesser General Public License along with QDBM; if
- * not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *************************************************************************************************/
-
-
-#ifndef _MYCONF_H /* duplication check */
-#define _MYCONF_H
-
-#if defined(__cplusplus) /* export for C++ */
-extern "C" {
-#endif
-
-
-
-/*************************************************************************************************
- * system discrimination
- *************************************************************************************************/
-
-
-#if defined(__linux__)
-
-#define _SYS_LINUX_
-#define _QDBM_SYSNAME "Linux"
-
-#elif defined(__FreeBSD__)
-
-#define _SYS_FREEBSD_
-#define _QDBM_SYSNAME "FreeBSD"
-
-#elif defined(__NetBSD__)
-
-#define _SYS_NETBSD_
-#define _QDBM_SYSNAME "NetBSD"
-
-#elif defined(__OpenBSD__)
-
-#define _SYS_OPENBSD_
-#define _QDBM_SYSNAME "OpenBSD"
-
-#elif defined(__sun__)
-
-#define _SYS_SUNOS_
-#define _QDBM_SYSNAME "SunOS"
-
-#elif defined(__hpux)
-
-#define _SYS_HPUX_
-#define _QDBM_SYSNAME "HP-UX"
-
-#elif defined(__osf)
-
-#define _SYS_TRU64_
-#define _QDBM_SYSNAME "Tru64"
-
-#elif defined(_AIX)
-
-#define _SYS_AIX_
-#define _QDBM_SYSNAME "AIX"
-
-#elif defined(__APPLE__) && defined(__MACH__)
-
-#define _SYS_MACOSX_
-#define _QDBM_SYSNAME "Mac OS X"
-
-#elif defined(_MSC_VER)
-
-#define _SYS_MSVC_
-#define _QDBM_SYSNAME "Windows (VC++)"
-
-#elif defined(_WIN32)
-
-#define _SYS_MINGW_
-#define _QDBM_SYSNAME "Windows (MinGW)"
-
-#elif defined(__CYGWIN__)
-
-#define _SYS_CYGWIN_
-#define _QDBM_SYSNAME "Windows (Cygwin)"
-
-#elif defined(__riscos__) || defined(__riscos)
-
-#define _SYS_RISCOS_
-#define _QDBM_SYSNAME "RISC OS"
-
-#else
-
-#define _SYS_GENERIC_
-#define _QDBM_SYSNAME "Generic"
-
-#endif
-
-
-
-/*************************************************************************************************
- * general headers
- *************************************************************************************************/
-
-
-#if defined(_SYS_MSVC_)
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-#include <assert.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <direct.h>
-#include <windows.h>
-#include <io.h>
-
-#elif defined(_SYS_MINGW_)
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-#include <assert.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <windows.h>
-#include <io.h>
-
-#elif defined(_SYS_CYGWIN_)
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-#include <assert.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/times.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <windows.h>
-#include <io.h>
-
-#else
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-#include <assert.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/times.h>
-#include <fcntl.h>
-#include <dirent.h>
-
-#endif
-
-
-
-/*************************************************************************************************
- * notation of filesystems
- *************************************************************************************************/
-
-
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
-
-#define MYPATHCHR '\\'
-#define MYPATHSTR "\\"
-#define MYEXTCHR '.'
-#define MYEXTSTR "."
-#define MYCDIRSTR "."
-#define MYPDIRSTR ".."
-
-#elif defined(_SYS_RISCOS_)
-
-#define MYPATHCHR '.'
-#define MYPATHSTR "."
-#define MYEXTCHR '/'
-#define MYEXTSTR "/"
-#define MYCDIRSTR "@"
-#define MYPDIRSTR "^"
-
-#else
-
-#define MYPATHCHR '/'
-#define MYPATHSTR "/"
-#define MYEXTCHR '.'
-#define MYEXTSTR "."
-#define MYCDIRSTR "."
-#define MYPDIRSTR ".."
-
-#endif
-
-
-
-/*************************************************************************************************
- * for dosish filesystems
- *************************************************************************************************/
-
-
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || defined(_SYS_CYGWIN_)
-
-#undef UNICODE
-#undef open
-
-#define \
- open(pathname, flags, mode) \
- open(pathname, flags | O_BINARY, mode)
-
-#define \
- lstat(pathname, buf) \
- _qdbm_win32_lstat(pathname, buf)
-
-int _qdbm_win32_lstat(const char *pathname, struct stat *buf);
-
-#else
-
-#undef O_BINARY
-#undef O_TEXT
-#undef setmode
-
-#define O_BINARY 0
-#define O_TEXT 1
-
-#define \
- setmode(fd, mode) \
- (O_BINARY)
-
-#endif
-
-
-
-/*************************************************************************************************
- * for POSIX thread
- *************************************************************************************************/
-
-
-#if defined(MYPTHREAD)
-
-#define _qdbm_ptsafe TRUE
-
-void *_qdbm_settsd(void *ptr, int size, const void *initval);
-
-#else
-
-#define _qdbm_ptsafe FALSE
-
-#define \
- _qdbm_settsd(ptr, size, initval) \
- (NULL)
-
-#endif
-
-
-
-/*************************************************************************************************
- * for systems without file locking
- *************************************************************************************************/
-
-
-#if defined(_SYS_RISCOS_) || defined(MYNOLOCK)
-
-#undef fcntl
-
-#define \
- fcntl(fd, cmd, lock) \
- (0)
-
-#endif
-
-
-
-/*************************************************************************************************
- * for systems without mmap
- *************************************************************************************************/
-
-
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || \
- defined(_SYS_FREEBSD_) || defined(_SYS_NETBSD_) || defined(_SYS_OPENBSD_) || \
- defined(_SYS_AIX_) || defined(_SYS_RISCOS_) || defined(MYNOMMAP)
-
-#undef PROT_EXEC
-#undef PROT_READ
-#undef PROT_WRITE
-#undef PROT_NONE
-#undef MAP_FIXED
-#undef MAP_SHARED
-#undef MAP_PRIVATE
-#undef MAP_FAILED
-#undef MS_ASYNC
-#undef MS_SYNC
-#undef MS_INVALIDATE
-#undef mmap
-#undef munmap
-#undef msync
-#undef mflush
-
-#define PROT_EXEC (1 << 0)
-#define PROT_READ (1 << 1)
-#define PROT_WRITE (1 << 2)
-#define PROT_NONE (1 << 3)
-#define MAP_FIXED 1
-#define MAP_SHARED 2
-#define MAP_PRIVATE 3
-#define MAP_FAILED ((void *)-1)
-#define MS_ASYNC (1 << 0)
-#define MS_SYNC (1 << 1)
-#define MS_INVALIDATE (1 << 2)
-
-#define \
- mmap(start, length, prot, flags, fd, offset) \
- _qdbm_mmap(start, length, prot, flags, fd, offset)
-
-#define \
- munmap(start, length) \
- _qdbm_munmap(start, length)
-
-#define \
- msync(start, length, flags) \
- _qdbm_msync(start, length, flags)
-
-#define \
- mflush(start, length, flags) \
- _qdbm_msync(start, length, flags)
-
-void *_qdbm_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
-int _qdbm_munmap(void *start, size_t length);
-int _qdbm_msync(const void *start, size_t length, int flags);
-
-#else
-
-#undef mflush
-#define \
- mflush(start, length, flags) \
- (0)
-
-#endif
-
-
-
-/*************************************************************************************************
- * for reentrant time routines
- *************************************************************************************************/
-
-
-struct tm *_qdbm_gmtime(const time_t *timep, struct tm *result);
-struct tm *_qdbm_localtime(const time_t *timep, struct tm *result);
-
-
-
-/*************************************************************************************************
- * for systems without times
- *************************************************************************************************/
-
-
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
-
-#undef times
-#undef sysconf
-
-struct tms {
- clock_t tms_utime;
- clock_t tms_stime;
- clock_t tms_cutime;
- clock_t tms_cstime;
-};
-
-#define \
- times(buf) \
- _qdbm_times(buf)
-
-#define \
- sysconf(name) \
- (CLOCKS_PER_SEC)
-
-clock_t _qdbm_times(struct tms *buf);
-
-#endif
-
-
-
-/*************************************************************************************************
- * for Win32
- *************************************************************************************************/
-
-
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
-
-#undef F_WRLCK
-#undef F_RDLCK
-#undef F_SETLK
-#undef F_SETLKW
-#undef fcntl
-#undef ftruncate
-#undef fsync
-#undef mkdir
-#undef rename
-
-#define F_WRLCK 0
-#define F_RDLCK 1
-#define F_SETLK 0
-#define F_SETLKW 1
-
-struct flock {
- int l_type;
- int l_whence;
- int l_start;
- int l_len;
- int l_pid;
-};
-
-#define \
- fcntl(fd, cmd, lock) \
- _qdbm_win32_fcntl(fd, cmd, lock)
-
-#define \
- ftruncate(fd, length) \
- _chsize(fd, length)
-
-#define \
- fsync(fd) \
- (0)
-
-#define \
- mkdir(pathname, mode) \
- mkdir(pathname)
-
-#define \
- rename(oldpath, newpath) \
- (unlink(newpath), rename(oldpath, newpath))
-
-int _qdbm_win32_fcntl(int fd, int cmd, struct flock *lock);
-
-#endif
-
-
-#if defined(_SYS_MSVC_)
-
-#undef S_ISDIR
-#undef S_ISREG
-#undef opendir
-#undef closedir
-#undef readdir
-
-#define S_ISDIR(x) (x & _S_IFDIR)
-#define S_ISREG(x) (x & _S_IFREG)
-
-struct dirent {
- char d_name[1024];
-};
-
-typedef struct {
- HANDLE fh;
- WIN32_FIND_DATA data;
- struct dirent de;
- int first;
-} DIR;
-
-#define \
- opendir(name) \
- _qdbm_win32_opendir(name)
-
-#define \
- closedir(dir) \
- _qdbm_win32_closedir(dir)
-
-#define \
- readdir(dir) \
- _qdbm_win32_readdir(dir)
-
-DIR *_qdbm_win32_opendir(const char *name);
-
-int _qdbm_win32_closedir(DIR *dir);
-
-struct dirent *_qdbm_win32_readdir(DIR *dir);
-
-#endif
-
-
-
-/*************************************************************************************************
- * for checking information of the system
- *************************************************************************************************/
-
-
-int _qdbm_vmemavail(size_t size);
-
-
-
-/*************************************************************************************************
- * for ZLIB
- *************************************************************************************************/
-
-
-enum {
- _QDBM_ZMZLIB,
- _QDBM_ZMRAW,
- _QDBM_ZMGZIP
-};
-
-
-extern char *(*_qdbm_deflate)(const char *, int, int *, int);
-
-extern char *(*_qdbm_inflate)(const char *, int, int *, int);
-
-extern unsigned int (*_qdbm_getcrc)(const char *, int);
-
-
-
-/*************************************************************************************************
- * for LZO
- *************************************************************************************************/
-
-
-extern char *(*_qdbm_lzoencode)(const char *, int, int *);
-
-extern char *(*_qdbm_lzodecode)(const char *, int, int *);
-
-
-
-/*************************************************************************************************
- * for BZIP2
- *************************************************************************************************/
-
-
-extern char *(*_qdbm_bzencode)(const char *, int, int *);
-
-extern char *(*_qdbm_bzdecode)(const char *, int, int *);
-
-
-
-/*************************************************************************************************
- * for ICONV
- *************************************************************************************************/
-
-
-extern char *(*_qdbm_iconv)(const char *, int, const char *, const char *, int *, int *);
-
-extern const char *(*_qdbm_encname)(const char *, int);
-
-
-
-/*************************************************************************************************
- * common settings
- *************************************************************************************************/
-
-
-#undef TRUE
-#define TRUE 1
-#undef FALSE
-#define FALSE 0
-
-#define sizeof(a) ((int)sizeof(a))
-
-int _qdbm_dummyfunc(void);
-
-
-
-#if defined(__cplusplus) /* export for C++ */
-}
-#endif
-
-#endif /* duplication check */
-
-
-/* END OF FILE */
diff --git a/src/tracker-indexer/tracker-indexer.c b/src/tracker-indexer/tracker-indexer.c
index 0645ef9..1e44beb 100644
--- a/src/tracker-indexer/tracker-indexer.c
+++ b/src/tracker-indexer/tracker-indexer.c
@@ -69,13 +69,11 @@
#include <libtracker-common/tracker-utils.h>
#include <libtracker-common/tracker-thumbnailer.h>
-#include <libtracker-db/tracker-db-index-manager.h>
#include <libtracker-db/tracker-db-dbus.h>
#include <libtracker-data/tracker-data-manager.h>
#include <libtracker-data/tracker-data-query.h>
#include <libtracker-data/tracker-data-update.h>
-#include <libtracker-data/tracker-data-search.h>
#include <libtracker-data/tracker-turtle.h>
#include <libtracker-data/tracker-data-backup.h>
@@ -135,8 +133,6 @@ struct TrackerIndexerPrivate {
gchar *db_dir;
- TrackerDBIndex *resources_index;
-
TrackerConfig *config;
TrackerLanguage *language;
@@ -403,10 +399,6 @@ flush_data (TrackerIndexer *indexer)
stop_transaction (indexer);
}
-#ifndef HAVE_SQLITE_FTS
- tracker_db_index_flush (indexer->private->resources_index);
-#endif
-
if ((indexer->private->state & TRACKER_INDEXER_STATE_STOPPED) == 0) {
signal_status (indexer, "flush");
}
@@ -530,47 +522,6 @@ notify_battery_in_use_cb (GObject *gobject,
#endif /* HAVE_HAL */
-#ifndef HAVE_SQLITE_FTS
-static void
-index_flushing_notify_cb (GObject *object,
- GParamSpec *pspec,
- TrackerIndexer *indexer)
-{
- TrackerIndexerState state;
-
- state = indexer->private->state;
-
- if ((state & TRACKER_INDEXER_STATE_STOPPED) != 0 &&
- !tracker_db_index_get_flushing (indexer->private->resources_index)) {
- /* The indexer has been already stopped and all indices are flushed */
- check_finished (indexer, indexer->private->interrupted);
- }
-}
-
-static void
-index_overloaded_notify_cb (GObject *object,
- GParamSpec *pspec,
- TrackerIndexer *indexer)
-{
- if (tracker_db_index_get_overloaded (indexer->private->resources_index)) {
- g_debug ("Index overloaded, stopping indexer to let it process items");
- state_set_flags (indexer, TRACKER_INDEXER_STATE_INDEX_OVERLOADED);
- } else {
- g_debug ("Index no longer overloaded, resuming data harvesting");
- state_unset_flags (indexer, TRACKER_INDEXER_STATE_INDEX_OVERLOADED);
- }
-}
-
-static void
-index_error_received_cb (TrackerDBIndex *index,
- const GError *error,
- TrackerIndexer *indexer)
-{
- g_signal_emit (indexer, signals[INDEXING_ERROR], 0,
- error->message, TRUE);
-}
-#endif
-
static void
check_mount_removal (GQueue *queue,
GFile *mount_root,
@@ -671,16 +622,6 @@ tracker_indexer_finalize (GObject *object)
g_object_unref (priv->language);
g_object_unref (priv->config);
-#ifndef HAVE_SQLITE_FTS
- g_signal_handlers_disconnect_by_func (priv->resources_index,
- index_flushing_notify_cb,
- object);
- g_signal_handlers_disconnect_by_func (priv->resources_index,
- index_overloaded_notify_cb,
- object);
- g_object_unref (priv->resources_index);
-#endif
-
g_free (priv->db_dir);
g_hash_table_unref (priv->indexer_modules);
@@ -871,11 +812,6 @@ check_started (TrackerIndexer *indexer)
indexer->private->timer = g_timer_new ();
-#ifndef HAVE_SQLITE_FTS
- /* Open indexes */
- tracker_db_index_open (indexer->private->resources_index);
-#endif
-
g_signal_emit (indexer, signals[STARTED], 0);
}
@@ -897,11 +833,6 @@ check_finished (TrackerIndexer *indexer,
indexer->private->timer = NULL;
}
-#ifndef HAVE_SQLITE_FTS
- /* Close indexes */
- tracker_db_index_close (indexer->private->resources_index);
-#endif
-
/* Print out how long it took us */
str = tracker_seconds_to_string (seconds_elapsed, FALSE);
@@ -934,15 +865,10 @@ check_stopped (TrackerIndexer *indexer,
state_set_flags (indexer, TRACKER_INDEXER_STATE_STOPPED);
indexer->private->interrupted = (interrupted != FALSE);
} else {
- /* If the indexer is stopped and the indices aren't
- * being flushed, then it's ready for finishing right away
+ /* If the indexer is stopped,
+ * then it's ready for finishing right away
*/
-#ifndef HAVE_SQLITE_FTS
- if (!tracker_db_index_get_flushing (indexer->private->resources_index))
-#endif
- {
- check_finished (indexer, interrupted);
- }
+ check_finished (indexer, interrupted);
}
}
@@ -1023,7 +949,6 @@ static void
tracker_indexer_init (TrackerIndexer *indexer)
{
TrackerIndexerPrivate *priv;
- TrackerDBIndex *lindex;
priv = indexer->private = TRACKER_INDEXER_GET_PRIVATE (indexer);
@@ -1066,19 +991,6 @@ tracker_indexer_init (TrackerIndexer *indexer)
tracker_indexer_load_modules (indexer);
-#ifndef HAVE_SQLITE_FTS
- /* Set up indexer */
- lindex = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
- priv->resources_index = g_object_ref (lindex);
-
- g_signal_connect (priv->resources_index, "notify::flushing",
- G_CALLBACK (index_flushing_notify_cb), indexer);
- g_signal_connect (priv->resources_index, "notify::overloaded",
- G_CALLBACK (index_overloaded_notify_cb), indexer);
- g_signal_connect (priv->resources_index, "error-received",
- G_CALLBACK (index_error_received_cb), indexer);
-#endif
-
/* Set up volume monitor */
priv->volume_monitor = g_volume_monitor_get ();
g_signal_connect (priv->volume_monitor, "mount-pre-unmount",
@@ -2179,15 +2091,8 @@ tracker_indexer_set_running (TrackerIndexer *indexer,
if (running && (state & TRACKER_INDEXER_STATE_PAUSED)) {
state_unset_flags (indexer, TRACKER_INDEXER_STATE_PAUSED);
-#ifndef HAVE_SQLITE_FTS
- tracker_db_index_set_paused (indexer->private->resources_index, FALSE);
-#endif
} else if (!running && !(state & TRACKER_INDEXER_STATE_PAUSED)) {
state_set_flags (indexer, TRACKER_INDEXER_STATE_PAUSED);
-
-#ifndef HAVE_SQLITE_FTS
- tracker_db_index_set_paused (indexer->private->resources_index, TRUE);
-#endif
}
}
diff --git a/src/tracker-indexer/tracker-main.c b/src/tracker-indexer/tracker-main.c
index 6da6005..8293e98 100644
--- a/src/tracker-indexer/tracker-main.c
+++ b/src/tracker-indexer/tracker-main.c
@@ -44,7 +44,6 @@
#include <libtracker-common/tracker-thumbnailer.h>
#include <libtracker-db/tracker-db-manager.h>
-#include <libtracker-db/tracker-db-index-manager.h>
#include <libtracker-db/tracker-db-dbus.h>
#include <libtracker-data/tracker-data-manager.h>
@@ -365,7 +364,7 @@ main (gint argc, gchar *argv[])
flags |= TRACKER_DB_MANAGER_LOW_MEMORY_MODE;
}
- if (!tracker_data_manager_init (config, language, flags, 0, NULL, &is_first_time_index)) {
+ if (!tracker_data_manager_init (config, language, flags, NULL, &is_first_time_index)) {
return EXIT_FAILURE;
}
diff --git a/src/tracker-utils/tracker-processes.c b/src/tracker-utils/tracker-processes.c
index 9b4b696..aa40484 100644
--- a/src/tracker-utils/tracker-processes.c
+++ b/src/tracker-utils/tracker-processes.c
@@ -34,7 +34,6 @@
#include <glib/gprintf.h>
#include <libtracker-db/tracker-db-manager.h>
-#include <libtracker-db/tracker-db-index-manager.h>
static gboolean should_kill;
static gboolean should_terminate;
@@ -253,12 +252,6 @@ main (int argc, char **argv)
tracker_db_manager_remove_all ();
tracker_db_manager_shutdown ();
-#ifndef HAVE_SQLITE_FTS
- tracker_db_index_manager_init (TRACKER_DB_INDEX_MANAGER_REMOVE_ALL, 0, 0);
- tracker_db_index_manager_remove_all ();
- tracker_db_index_manager_shutdown ();
-#endif
-
/* Unset log handler */
g_log_remove_handler (NULL, log_handler_id);
}
diff --git a/src/trackerd/Makefile.am b/src/trackerd/Makefile.am
index 5bd9fa5..f04fb33 100644
--- a/src/trackerd/Makefile.am
+++ b/src/trackerd/Makefile.am
@@ -19,7 +19,6 @@ INCLUDES = \
$(GMIME_CFLAGS) \
$(FAM_CFLAGS) \
$(SQLITE3_CFLAGS) \
- $(QDBM_CFLAGS) \
$(RAPTOR_CFLAGS)
if HAVE_INOTIFY
@@ -78,7 +77,6 @@ trackerd_LDADD = \
$(GMIME_LIBS) \
$(FAM_LIBS) \
$(SQLITE3_LIBS) \
- $(QDBM_LIBS) \
$(DBUS_LIBS) \
$(PANGO_LIBS) \
$(GIO_LIBS) \
diff --git a/src/trackerd/tracker-daemon.c b/src/trackerd/tracker-daemon.c
index cf3038e..7a9ba7c 100644
--- a/src/trackerd/tracker-daemon.c
+++ b/src/trackerd/tracker-daemon.c
@@ -30,7 +30,6 @@
#include <libtracker-common/tracker-dbus.h>
#include <libtracker-db/tracker-db-dbus.h>
-#include <libtracker-db/tracker-db-index.h>
#include <libtracker-db/tracker-db-manager.h>
#include "tracker-dbus.h"
diff --git a/src/trackerd/tracker-dbus.c b/src/trackerd/tracker-dbus.c
index b746d78..6639114 100644
--- a/src/trackerd/tracker-dbus.c
+++ b/src/trackerd/tracker-dbus.c
@@ -261,7 +261,6 @@ tracker_dbus_shutdown (void)
gboolean
tracker_dbus_register_objects (TrackerConfig *config,
TrackerLanguage *language,
- TrackerDBIndex *resources_index,
TrackerProcessor *processor)
{
gpointer object, resources;
@@ -270,9 +269,6 @@ tracker_dbus_register_objects (TrackerConfig *config,
g_return_val_if_fail (TRACKER_IS_CONFIG (config), FALSE);
g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), FALSE);
-#ifndef HAVE_SQLITE_FTS
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (resources_index), FALSE);
-#endif
if (!connection || !gproxy) {
g_critical ("DBus support must be initialized before registering objects!");
@@ -309,7 +305,7 @@ tracker_dbus_register_objects (TrackerConfig *config,
objects = g_slist_prepend (objects, object);
/* Add org.freedesktop.Tracker.Search */
- object = tracker_search_new (config, language, resources_index);
+ object = tracker_search_new (config, language);
if (!object) {
g_critical ("Could not create TrackerSearch object to register");
return FALSE;
diff --git a/src/trackerd/tracker-dbus.h b/src/trackerd/tracker-dbus.h
index 331fb28..0fbf797 100644
--- a/src/trackerd/tracker-dbus.h
+++ b/src/trackerd/tracker-dbus.h
@@ -29,8 +29,6 @@
#include <libtracker-common/tracker-config.h>
#include <libtracker-common/tracker-language.h>
-#include <libtracker-db/tracker-db-index.h>
-
#include "tracker-processor.h"
G_BEGIN_DECLS
@@ -41,7 +39,6 @@ gboolean tracker_dbus_init (TrackerConfig *config);
void tracker_dbus_shutdown (void);
gboolean tracker_dbus_register_objects (TrackerConfig *config,
TrackerLanguage *language,
- TrackerDBIndex *resources_index,
TrackerProcessor *processor);
GObject *tracker_dbus_get_object (GType type);
void tracker_dbus_indexer_check_is_paused (void);
diff --git a/src/trackerd/tracker-main.c b/src/trackerd/tracker-main.c
index 17de536..42abfc0 100644
--- a/src/trackerd/tracker-main.c
+++ b/src/trackerd/tracker-main.c
@@ -54,8 +54,6 @@
#include <libtracker-common/tracker-thumbnailer.h>
#include <libtracker-db/tracker-db-manager.h>
-#include <libtracker-db/tracker-db-index.h>
-#include <libtracker-db/tracker-db-index-manager.h>
#include <libtracker-data/tracker-data-manager.h>
#include <libtracker-data/tracker-turtle.h>
@@ -667,7 +665,7 @@ backup_user_metadata (TrackerConfig *config, TrackerLanguage *language)
/*
* Init the DB stack to get the user metadata
*/
- tracker_data_manager_init (config, language, 0, 0, NULL, &is_first_time_index);
+ tracker_data_manager_init (config, language, 0, NULL, &is_first_time_index);
/*
* If some database is missing or the dbs dont exists, we dont need
@@ -823,10 +821,8 @@ main (gint argc, gchar *argv[])
TrackerConfig *config;
TrackerLanguage *language;
TrackerHal *hal;
- TrackerDBIndex *resources_index;
TrackerRunningLevel runtime_level;
TrackerDBManagerFlags flags = 0;
- TrackerDBIndexManagerFlags index_flags = 0;
gboolean is_first_time_index;
g_type_init ();
@@ -967,21 +963,19 @@ main (gint argc, gchar *argv[])
tracker_thumbnailer_init (config);
flags |= TRACKER_DB_MANAGER_REMOVE_CACHE;
- index_flags |= TRACKER_DB_INDEX_MANAGER_READONLY;
if (force_reindex) {
/* TODO port backup support
backup_user_metadata (config, language); */
flags |= TRACKER_DB_MANAGER_FORCE_REINDEX;
- index_flags |= TRACKER_DB_INDEX_MANAGER_FORCE_REINDEX;
}
if (tracker_config_get_low_memory_mode (config)) {
flags |= TRACKER_DB_MANAGER_LOW_MEMORY_MODE;
}
- tracker_data_manager_init (config, language, flags, index_flags, NULL, &is_first_time_index);
+ tracker_data_manager_init (config, language, flags, NULL, &is_first_time_index);
tracker_status_set_is_first_time_index (is_first_time_index);
@@ -1009,15 +1003,6 @@ main (gint argc, gchar *argv[])
return EXIT_FAILURE;
}
-#ifndef HAVE_SQLITE_FTS
- resources_index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
-
- if (!TRACKER_IS_DB_INDEX (resources_index)) {
- g_critical ("Could not create indexer for resource index");
- return EXIT_FAILURE;
- }
-#endif
-
tracker_volume_cleanup_init ();
#ifdef HAVE_HAL
@@ -1034,7 +1019,6 @@ main (gint argc, gchar *argv[])
/* Make Tracker available for introspection */
if (!tracker_dbus_register_objects (config,
language,
- resources_index,
private->processor)) {
return EXIT_FAILURE;
}
diff --git a/src/trackerd/tracker-processor.c b/src/trackerd/tracker-processor.c
index 00622f3..19a3c5b 100644
--- a/src/trackerd/tracker-processor.c
+++ b/src/trackerd/tracker-processor.c
@@ -28,8 +28,6 @@
#include <libtracker-common/tracker-module-config.h>
#include <libtracker-common/tracker-utils.h>
-#include <libtracker-db/tracker-db-index.h>
-#include <libtracker-db/tracker-db-index-manager.h>
#include <libtracker-db/tracker-db-manager.h>
#include "tracker-processor.h"
@@ -1082,7 +1080,6 @@ indexer_status_cb (DBusGProxy *proxy,
gpointer user_data)
{
TrackerProcessor *processor;
- TrackerDBIndex *index;
GQueue *queue;
GFile *file;
gchar *path = NULL;
@@ -1119,15 +1116,6 @@ indexer_status_cb (DBusGProxy *proxy,
seconds_elapsed);
g_free (path);
-#ifndef HAVE_SQLITE_FTS
- /* Tell the index that it can reload, really we should do
- * module_name->index type so we don't do this for both
- * every time:
- */
- index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
- tracker_db_index_set_reload (index, TRUE);
-#endif
-
/* Message to the console about state */
str1 = tracker_seconds_estimate_to_string (seconds_elapsed,
TRUE,
@@ -1156,7 +1144,6 @@ indexer_finished_cb (DBusGProxy *proxy,
gpointer user_data)
{
TrackerProcessor *processor;
- TrackerDBIndex *index;
GObject *object;
gchar *str;
@@ -1177,15 +1164,6 @@ indexer_finished_cb (DBusGProxy *proxy,
items_processed,
seconds_elapsed);
-#ifndef HAVE_SQLITE_FTS
- /* Tell the index that it can reload, really we should do
- * module_name->index type so we don't do this for both
- * every time:
- */
- index = tracker_db_index_manager_get_index (TRACKER_DB_INDEX_RESOURCES);
- tracker_db_index_set_reload (index, TRUE);
-#endif
-
/* Message to the console about state */
str = tracker_seconds_to_string (seconds_elapsed, FALSE);
diff --git a/src/trackerd/tracker-resources.c b/src/trackerd/tracker-resources.c
index 9f4676f..68d4b49 100644
--- a/src/trackerd/tracker-resources.c
+++ b/src/trackerd/tracker-resources.c
@@ -32,7 +32,6 @@
#include <libtracker-data/tracker-data-manager.h>
#include <libtracker-data/tracker-data-query.h>
-#include <libtracker-data/tracker-data-search.h>
#include "tracker-indexer-client.h"
#include "tracker-dbus.h"
diff --git a/src/trackerd/tracker-resources.h b/src/trackerd/tracker-resources.h
index cedc4d7..d6f3fca 100644
--- a/src/trackerd/tracker-resources.h
+++ b/src/trackerd/tracker-resources.h
@@ -24,8 +24,6 @@
#include <glib-object.h>
-#include <libtracker-db/tracker-db-index.h>
-
#define TRACKER_RESOURCES_SERVICE "org.freedesktop.Tracker"
#define TRACKER_RESOURCES_PATH "/org/freedesktop/Tracker/Resources"
#define TRACKER_RESOURCES_INTERFACE "org.freedesktop.Tracker.Resources"
diff --git a/src/trackerd/tracker-search.c b/src/trackerd/tracker-search.c
index eaebdb0..99314ba 100644
--- a/src/trackerd/tracker-search.c
+++ b/src/trackerd/tracker-search.c
@@ -33,13 +33,10 @@
#include <libtracker-common/tracker-type-utils.h>
#include <libtracker-db/tracker-db-dbus.h>
-#include <libtracker-db/tracker-db-index.h>
#include <libtracker-db/tracker-db-manager.h>
#include <libtracker-data/tracker-data-manager.h>
#include <libtracker-data/tracker-data-query.h>
-#include <libtracker-data/tracker-data-search.h>
-#include <libtracker-data/tracker-query-tree.h>
#include "tracker-dbus.h"
#include "tracker-search.h"
@@ -52,7 +49,6 @@
typedef struct {
TrackerConfig *config;
TrackerLanguage *language;
- TrackerDBIndex *resources_index;
} TrackerSearchPrivate;
static void tracker_search_finalize (GObject *object);
@@ -84,9 +80,6 @@ tracker_search_finalize (GObject *object)
priv = TRACKER_SEARCH_GET_PRIVATE (object);
-#ifndef HAVE_SQLITE_FTS
- g_object_unref (priv->resources_index);
-#endif
g_object_unref (priv->language);
g_object_unref (priv->config);
@@ -95,17 +88,13 @@ tracker_search_finalize (GObject *object)
TrackerSearch *
tracker_search_new (TrackerConfig *config,
- TrackerLanguage *language,
- TrackerDBIndex *resources_index)
+ TrackerLanguage *language)
{
TrackerSearch *object;
TrackerSearchPrivate *priv;
g_return_val_if_fail (TRACKER_IS_CONFIG (config), NULL);
g_return_val_if_fail (TRACKER_IS_LANGUAGE (language), NULL);
-#ifndef HAVE_SQLITE_FTS
- g_return_val_if_fail (TRACKER_IS_DB_INDEX (resources_index), NULL);
-#endif
object = g_object_new (TRACKER_TYPE_SEARCH, NULL);
@@ -113,9 +102,6 @@ tracker_search_new (TrackerConfig *config,
priv->config = g_object_ref (config);
priv->language = g_object_ref (language);
-#ifndef HAVE_SQLITE_FTS
- priv->resources_index = g_object_ref (resources_index);
-#endif
return object;
}
@@ -514,7 +500,8 @@ tracker_search_suggest (TrackerSearch *object,
priv = TRACKER_SEARCH_GET_PRIVATE (object);
-#ifndef HAVE_SQLITE_FTS
+ /* TODO: Port to SPARQL */
+#if 0
value = tracker_db_index_get_suggestion (priv->resources_index,
search_text,
max_dist);
diff --git a/src/trackerd/tracker-search.h b/src/trackerd/tracker-search.h
index 911efb3..1c88029 100644
--- a/src/trackerd/tracker-search.h
+++ b/src/trackerd/tracker-search.h
@@ -26,8 +26,6 @@
#include <libtracker-common/tracker-language.h>
-#include <libtracker-db/tracker-db-index.h>
-
#define TRACKER_SEARCH_SERVICE "org.freedesktop.Tracker"
#define TRACKER_SEARCH_PATH "/org/freedesktop/Tracker/Search"
#define TRACKER_SEARCH_INTERFACE "org.freedesktop.Tracker.Search"
@@ -54,8 +52,7 @@ struct TrackerSearchClass {
GType tracker_search_get_type (void);
TrackerSearch *tracker_search_new (TrackerConfig *config,
- TrackerLanguage *language,
- TrackerDBIndex *resources_index);
+ TrackerLanguage *language);
void tracker_search_get_snippet (TrackerSearch *object,
const gchar *id,
const gchar *search_text,
diff --git a/tests/libtracker-data/Makefile.am b/tests/libtracker-data/Makefile.am
index 69b2c11..ed07c97 100644
--- a/tests/libtracker-data/Makefile.am
+++ b/tests/libtracker-data/Makefile.am
@@ -13,7 +13,6 @@ INCLUDES = \
-I$(top_srcdir)/tests/common \
$(DBUS_CFLAGS) \
$(SQLITE3_CFLAGS) \
- $(QDBM_CFLAGS) \
$(GMODULE_CFLAGS) \
$(GTHREAD_CFLAGS) \
$(GLIB2_CFLAGS) \
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index f9f1e65..39749c4 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -25,7 +25,6 @@
#include <raptor.h>
-#include <libtracker-db/tracker-db-index-manager.h>
#include <libtracker-db/tracker-db-manager.h>
#include <libtracker-data/tracker-data-manager.h>
@@ -107,7 +106,7 @@ test_query (gconstpointer test_data)
tracker_data_manager_init (config, language,
TRACKER_DB_MANAGER_FORCE_REINDEX
| TRACKER_DB_MANAGER_TEST_MODE,
- 0, NULL, NULL);
+ NULL, NULL);
/* load data set */
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index 0b21db7..44c59da 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -25,7 +25,6 @@
#include <raptor.h>
-#include <libtracker-db/tracker-db-index-manager.h>
#include <libtracker-db/tracker-db-manager.h>
#include <libtracker-data/tracker-data-manager.h>
@@ -94,7 +93,7 @@ test_sparql_query (gconstpointer test_data)
tracker_data_manager_init (config, language,
TRACKER_DB_MANAGER_FORCE_REINDEX
| TRACKER_DB_MANAGER_TEST_MODE,
- 0, test_info->data, NULL);
+ test_info->data, NULL);
/* load data set */
diff --git a/tests/libtracker-db/Makefile.am b/tests/libtracker-db/Makefile.am
index 558af6e..fd70a79 100644
--- a/tests/libtracker-db/Makefile.am
+++ b/tests/libtracker-db/Makefile.am
@@ -16,11 +16,6 @@ noinst_PROGRAMS = $(TEST_PROGS)
# tracker-db-manager-custom
#
-if !ENABLE_SQLITE_FTS
-TEST_PROGS += \
- tracker-index-writer
-endif
-
INCLUDES = \
-DG_LOG_DOMAIN=\"Tracker\" \
-DTRACKER_COMPILATION \
@@ -32,11 +27,9 @@ INCLUDES = \
$(GMODULE_CFLAGS) \
$(GTHREAD_CFLAGS) \
$(DBUS_CFLAGS) \
- $(SQLITE3_CFLAGS) \
- $(QDBM_CFLAGS)
+ $(SQLITE3_CFLAGS)
# TEST_PROGS += \
-# tracker-index-reader \
# tracker-db-dbus \
# tracker-db-manager-unattach \
# tracker-db-manager-attach \
@@ -52,7 +45,6 @@ INCLUDES = \
# $(top_builddir)/src/libtracker-common/libtracker-common.la \
# $(top_builddir)/tests/common/libtracker-testcommon.la \
# $(SQLITE3_LIBS) \
-# $(QDBM_LIBS) \
# $(GMODULE_LIBS) \
# $(GTHREAD_LIBS) \
# $(GLIB2_LIBS) \
@@ -68,7 +60,6 @@ INCLUDES = \
# $(top_builddir)/src/libtracker-common/libtracker-common.la \
# $(top_builddir)/tests/common/libtracker-testcommon.la \
# $(SQLITE3_LIBS) \
-# $(QDBM_LIBS) \
# $(GMODULE_LIBS) \
# $(GTHREAD_LIBS) \
# $(GLIB2_LIBS) \
@@ -84,7 +75,6 @@ INCLUDES = \
# $(top_builddir)/src/libtracker-common/libtracker-common.la \
# $(top_builddir)/tests/common/libtracker-testcommon.la \
# $(SQLITE3_LIBS) \
-# $(QDBM_LIBS) \
# $(GMODULE_LIBS) \
# $(GTHREAD_LIBS) \
# $(GLIB2_LIBS) \
@@ -102,32 +92,4 @@ INCLUDES = \
# $(GTHREAD_LIBS) \
# $(GLIB2_LIBS) \
# -lz
-#
-#
-# tracker_index_reader_SOURCES = \
-# tracker-index-reader-test.c
-#
-# tracker_index_reader_LDADD = \
-# $(top_builddir)/src/libtracker-common/libtracker-common.la \
-# $(top_builddir)/src/libtracker-db/libtracker-db.la \
-# $(top_builddir)/tests/common/libtracker-testcommon.la \
-# $(GMODULE_LIBS) \
-# $(GTHREAD_LIBS) \
-# $(GLIB2_LIBS) \
-# $(DBUS_LIBS) \
-# $(GIO_LIBS) \
-# $(QDBM_LIBS)
-
-tracker_index_writer_SOURCES = \
- tracker-index-writer-test.c
-
-tracker_index_writer_LDADD = \
- $(top_builddir)/src/libtracker-common/libtracker-common.la \
- $(top_builddir)/src/libtracker-db/libtracker-db.la \
- $(top_builddir)/tests/common/libtracker-testcommon.la \
- $(QDBM_LIBS) \
- $(GCOV_LIBS) \
- $(GMODULE_LIBS) \
- $(GTHREAD_LIBS) \
- $(GLIB2_LIBS)
diff --git a/tests/libtracker-db/tracker-index-reader-test.c b/tests/libtracker-db/tracker-index-reader-test.c
deleted file mode 100644
index 9fe205c..0000000
--- a/tests/libtracker-db/tracker-index-reader-test.c
+++ /dev/null
@@ -1,132 +0,0 @@
-#include <glib.h>
-#include <tracker-test-helpers.h>
-#include <gio/gio.h>
-
-#include <libtracker-db/tracker-db-index.h>
-#include <libtracker-db/tracker-db-index-item.h>
-
-/* From libtracker-common/tracker-config.c */
-#define DEFAULT_MAX_BUCKET_COUNT 524288
-#define DEFAULT_MIN_BUCKET_COUNT 65536
-
-static void
-test_get_suggestion ()
-{
- TrackerDBIndex *index;
- gchar *suggestion;
-
- index = tracker_db_index_new ("./example.index",
- DEFAULT_MIN_BUCKET_COUNT,
- DEFAULT_MAX_BUCKET_COUNT,
- TRUE);
-
- g_assert (!tracker_db_index_get_reload (index));
-
- suggestion = tracker_db_index_get_suggestion (index, "Thiz", 9);
-
- g_assert (tracker_test_helpers_cmpstr_equal (suggestion, "this"));
-
- g_free (suggestion);
-
- g_object_unref (index);
-}
-
-static void
-test_reloading ()
-{
- TrackerDBIndex *index;
- TrackerDBIndexItem *hits = NULL;
- guint count;
-
- index = tracker_db_index_new ("./example.index",
- DEFAULT_MIN_BUCKET_COUNT,
- DEFAULT_MAX_BUCKET_COUNT,
- TRUE);
-
- tracker_db_index_set_reload (index, TRUE);
- g_assert (tracker_db_index_get_reload (index)); /* Trivial check of get/set */
-
- hits = tracker_db_index_get_word_hits (index, "this", &count);
- g_assert (hits);
- g_free (hits);
-
- g_assert (!tracker_db_index_get_reload (index)); /* Trivial check of get/set */
-}
-
-static void
-test_bad_index ()
-{
- TrackerDBIndex *index;
- guint count;
-
- index = tracker_db_index_new ("unknown-index",
- DEFAULT_MIN_BUCKET_COUNT,
- DEFAULT_MAX_BUCKET_COUNT,
- TRUE);
-
- /* Reload true: the index doesnt exists */
- g_assert (tracker_db_index_get_reload (index));
-
- /* Return NULL, the index cannot reload the file */
- g_assert (!tracker_db_index_get_word_hits (index, "this", &count));
-
- /* Return NULL, the index cannot reload the file */
- g_assert (!tracker_db_index_get_suggestion (index, "Thiz", 9));
-
-}
-
-static void
-test_created_file_in_the_mean_time ()
-{
- TrackerDBIndex *index;
- GFile *good, *bad;
- guint count;
-
- index = tracker_db_index_new ("./unknown-index",
- DEFAULT_MIN_BUCKET_COUNT,
- DEFAULT_MAX_BUCKET_COUNT,
- TRUE);
-
- /* Reload true: the index doesnt exists */
- g_assert (tracker_db_index_get_reload (index));
-
- good = g_file_new_for_path ("./example.index");
- bad = g_file_new_for_path ("./unknown-index");
-
- g_file_copy (good, bad, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL);
-
- /* Now the first operation reload the index */
- g_assert (tracker_db_index_get_word_hits (index, "this", &count));
-
- /* Reload false: It is already reloaded */
- g_assert (!tracker_db_index_get_reload (index));
-
- g_file_delete (bad, NULL, NULL);
-}
-
-
-int
-main (int argc, char **argv) {
-
- int result;
-
- g_type_init ();
- g_thread_init (NULL);
- g_test_init (&argc, &argv, NULL);
-
- /* Init */
-
- g_test_add_func ("/libtracker-db/tracker-index/get_suggestion",
- test_get_suggestion );
- g_test_add_func ("/libtracker-db/tracker-index/reloading",
- test_reloading );
- g_test_add_func ("/libtracker-db/tracker-index/bad_index",
- test_bad_index );
- g_test_add_func ("/libtracker-db/tracker-index/created_file_in_the_mean_time",
- test_created_file_in_the_mean_time);
- result = g_test_run ();
-
- /* End */
-
- return result;
-}
diff --git a/tests/libtracker-db/tracker-index-writer-test.c b/tests/libtracker-db/tracker-index-writer-test.c
deleted file mode 100644
index 83e4877..0000000
--- a/tests/libtracker-db/tracker-index-writer-test.c
+++ /dev/null
@@ -1,346 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2008, Nokia (urho konttori nokia com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include <qdbm/depot.h>
-
-#include <glib.h>
-#include <glib-object.h>
-#include <glib/gstdio.h>
-
-#include <libtracker-db/tracker-db-index.h>
-#include <libtracker-db/tracker-db-index-item.h>
-
-#define MIN_BUCKET_COUNT 1
-#define MAX_BUCKET_COUNT 100
-
-static gint
-insert_in_index (TrackerDBIndex *index,
- const gchar *text)
-{
- gchar **pieces;
- gint i;
- static gint service_id = 0;
-
- service_id += 1;
- pieces = g_strsplit (text, " ", -1);
-
- for (i = 0; pieces[i] != NULL; i++) {
- tracker_db_index_add_word (index, pieces[i], service_id, 1);
- }
-
- g_strfreev (pieces);
-
- return service_id;
-}
-
-static void
-remove_in_index (TrackerDBIndex *index,
- const gchar *text,
- gint service_id)
-{
- gchar **pieces;
- gint i;
-
- pieces = g_strsplit (text, " ", -1);
-
- for (i = 0; pieces[i] != NULL; i++) {
- tracker_db_index_add_word (index, pieces[i], service_id, -1);
- }
-
- g_strfreev (pieces);
-}
-
-/* Helper functions to read the index */
-static gint
-get_number_words_in_index (const gchar *index_file)
-{
- DEPOT *index;
- gint words;
-
- index = dpopen (index_file, DP_OREADER, MAX_BUCKET_COUNT);
-
- words = dprnum (index);
-
- dpclose (index);
-
- return words;
-}
-
-static gint
-get_results_for_word (const gchar *index_file,
- const gchar *word)
-{
- DEPOT *index;
- gint result;
-
- index = dpopen (index_file, DP_OREADER, MAX_BUCKET_COUNT);
-
- result = dpvsiz (index, word, -1);
-
- dpclose (index);
-
- return result / sizeof (TrackerDBIndexItem);
-}
-
-static gint
-get_score_for_word (const gchar *index_file,
- const gchar *word)
-{
- TrackerDBIndexItem *results;
- DEPOT *index;
- gint tsiz;
- gint score;
-
- index = dpopen (index_file, DP_OREADER, MAX_BUCKET_COUNT);
-
- results = (TrackerDBIndexItem *) dpget (index, word, -1, 0, -1, &tsiz);
-
- dpclose (index);
-
- g_return_val_if_fail ((tsiz / sizeof (TrackerDBIndexItem)) == 1, -1);
- g_return_val_if_fail (results, -1);
-
- score = tracker_db_index_item_get_score (&results[0]);
-
- g_free (results);
- return score;
-}
-
-static void
-test_add_one_word (void)
-{
- TrackerDBIndex *index;
- const gchar *indexname = "test-add-one-word.index";
-
- g_remove (indexname);
- index = tracker_db_index_new (indexname, MIN_BUCKET_COUNT, MAX_BUCKET_COUNT, FALSE);
-
- tracker_db_index_add_word (index, "word1", 1, 1);
- tracker_db_index_flush (index);
- g_object_unref (index);
-
- g_assert_cmpint (get_number_words_in_index (indexname), ==, 1);
- g_assert_cmpint (get_results_for_word (indexname, "word1"), ==, 1);
-
- g_remove (indexname);
-}
-
-static void
-test_add_n_words (void)
-{
- TrackerDBIndex *index;
- const gchar *indexname = "test-add-n-words.index";
- gchar *word;
- gint i;
-
- g_remove (indexname);
- index = tracker_db_index_new (indexname, MIN_BUCKET_COUNT, MAX_BUCKET_COUNT, FALSE);
-
- for ( i = 0; i < 20; i++) {
- word = g_strdup_printf ("word%d", i);
- tracker_db_index_add_word (index, word, 1, 1);
- g_free (word);
- }
-
- tracker_db_index_flush (index);
- g_object_unref (index);
-
- g_assert_cmpint (get_number_words_in_index (indexname), ==, 20);
- g_assert_cmpint (get_results_for_word (indexname, "word5"), ==, 1);
- g_remove (indexname);
-}
-
-static void
-test_add_word_n_times (void)
-{
- TrackerDBIndex *index;
- const gchar *indexname = "test-add-word-n-times.index";
- gint i;
-
- g_remove (indexname);
- index = tracker_db_index_new (indexname, MIN_BUCKET_COUNT, MAX_BUCKET_COUNT, FALSE);
-
- for ( i = 0; i < 20; i++) {
- tracker_db_index_add_word (index, "test-word", i, 1);
- }
-
- tracker_db_index_flush (index);
- g_object_unref (index);
-
- g_assert_cmpint (get_number_words_in_index (indexname), ==, 1);
- g_assert_cmpint (get_results_for_word (indexname, "test-word"), ==, 20);
-
- g_remove (indexname);
-}
-
-static void
-test_add_word_multiple_occurrences (void)
-{
- TrackerDBIndex *index;
- const gchar *indexname = "test-word-multiple-ocurrences.index";
- gint i;
-
- g_remove (indexname);
- index = tracker_db_index_new (indexname, MIN_BUCKET_COUNT, MAX_BUCKET_COUNT, FALSE);
-
- for ( i = 0; i < 20; i++) {
- tracker_db_index_add_word (index, "test-word", 1, 1);
- }
-
- tracker_db_index_flush (index);
- g_object_unref (index);
-
- g_assert_cmpint (get_number_words_in_index (indexname), ==, 1);
-
- // There must be only ONE result with a high score
- g_assert_cmpint (get_results_for_word (indexname, "test-word"), ==, 1);
- g_assert_cmpint (get_score_for_word (indexname, "test-word"), ==, 20);
-
- g_remove (indexname);
-}
-
-static void
-test_add_with_flushs (void)
-{
-
- TrackerDBIndex *index;
- const gchar *indexname = "test-add-with-flush.index";
- const gchar *text1 = "this is a text to try a kind of real use case of the indexer";
- const gchar *text2 = "this is another text with some common words";
-
- g_remove (indexname);
- index = tracker_db_index_new (indexname, MIN_BUCKET_COUNT, MAX_BUCKET_COUNT, FALSE);
-
- /* Text 1 */
- insert_in_index (index, text1);
- tracker_db_index_flush (index);
-
- /* Text 2 */
- insert_in_index (index, text2);
- tracker_db_index_flush (index);
-
- g_object_unref (index);
-
- g_assert_cmpint (get_number_words_in_index (indexname), ==, 18);
- g_assert_cmpint (get_results_for_word (indexname, "this"), ==, 2);
- g_assert_cmpint (get_results_for_word (indexname, "common"), ==, 1);
- g_assert_cmpint (get_score_for_word (indexname, "a"), ==, 2);
- g_remove (indexname);
-}
-
-static void
-test_remove_document (void)
-{
- TrackerDBIndex *index;
- const gchar *indexname = "test-remove-document.index";
- const gchar *text1 = "this is a text to try a kind of real use case of the indexer";
- const gchar *text2 = "this is another text with some common words";
- gint service_id1, service_id2;
-
- g_remove (indexname);
- index = tracker_db_index_new (indexname, MIN_BUCKET_COUNT, MAX_BUCKET_COUNT, FALSE);
-
- /* Text 1 */
- service_id1 = insert_in_index (index, text1);
- tracker_db_index_flush (index);
-
- /* Text 2 */
- service_id2 = insert_in_index (index, text2);
- tracker_db_index_flush (index);
-
- g_object_unref (index);
-
- g_assert_cmpint (get_number_words_in_index (indexname), ==, 18);
-
- index = tracker_db_index_new (indexname, MIN_BUCKET_COUNT, MAX_BUCKET_COUNT, FALSE);
-
- /* Remove Text1 */
- remove_in_index (index, text1, service_id1);
- tracker_db_index_flush (index);
-
- g_object_unref (index);
-
- g_assert_cmpint (get_number_words_in_index (indexname), ==, 8);
-
- g_remove (indexname);
-}
-
-static void
-test_remove_before_flush (void)
-{
- TrackerDBIndex *index;
- const gchar *indexname = "test-remove-before-flush.index";
- const gchar *text = "this is a text";
- gint service_id1;
-
- g_remove (indexname);
-
- index = tracker_db_index_new (indexname, MIN_BUCKET_COUNT, MAX_BUCKET_COUNT, FALSE);
-
- /* Text 1 */
- service_id1 = insert_in_index (index, text);
-
- /* Remove before flush */
- remove_in_index (index, text, service_id1);
-
- tracker_db_index_flush (index);
-
- g_object_unref (index);
-
- g_assert_cmpint (get_number_words_in_index (indexname), ==, 0);
-
- g_remove (indexname);
-}
-
-int
-main (int argc, char **argv)
-{
- int result;
-
- g_type_init ();
- g_thread_init (NULL);
-
- g_test_init (&argc, &argv, NULL);
-
- g_test_add_func ("/libtracker-db/tracker-index/add_word",
- test_add_one_word);
-
- g_test_add_func ("/libtracker-db/tracker-index/add_n_words",
- test_add_n_words);
-
- g_test_add_func ("/libtracker-db/tracker-index/add_word_n_times",
- test_add_word_n_times);
-
- g_test_add_func ("/libtracker-db/tracker-index/add_word_multiple_occurrences",
- test_add_word_multiple_occurrences);
-
- g_test_add_func ("/libtracker-db/tracker-index/add_with_flush",
- test_add_with_flushs);
-
- g_test_add_func ("/libtracker-db/tracker-index/remove_document",
- test_remove_document);
-
- g_test_add_func ("/libtracker-db/tracker-index/remove_before_flush",
- test_remove_before_flush);
-
- result = g_test_run ();
-
- return result;
-}
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 5fd1e21..88852c9 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -1,19 +1,6 @@
include $(top_srcdir)/Makefile.decl
-if ENABLE_SQLITE_FTS
-build_sqlite_fts = tracker-fts
-endif
-
-if !ENABLE_SQLITE_FTS
-build_qdbm = qdbm
-endif
-
SUBDIRS = \
services \
- $(build_sqlite_fts) \
- $(build_qdbm)
+ tracker-fts
-DIST_SUBDIRS = \
- services \
- tracker-fts \
- qdbm
diff --git a/utils/qdbm/.gitignore b/utils/qdbm/.gitignore
deleted file mode 100644
index dc1bb23..0000000
--- a/utils/qdbm/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-print
-search
diff --git a/utils/qdbm/Makefile.am b/utils/qdbm/Makefile.am
deleted file mode 100644
index d547742..0000000
--- a/utils/qdbm/Makefile.am
+++ /dev/null
@@ -1,29 +0,0 @@
-include $(top_srcdir)/Makefile.decl
-
-noinst_PROGRAMS = print search
-
-INCLUDES = \
- -DG_LOG_DOMAIN=\"Tracker\" \
- -I$(top_srcdir)/src \
- $(WARN_CFLAGS) \
- $(GLIB2_CFLAGS) \
- $(QDBM_CFLAGS)
-
-print_SOURCES = \
- print-words.c
-
-print_LDADD = \
- $(top_builddir)/src/libtracker-common/libtracker-common.la \
- $(top_builddir)/src/libtracker-db/libtracker-db.la \
- $(QDBM_LIBS) \
- $(GLIB2_LIBS)
-
-search_SOURCES = \
- search-word.c
-
-search_LDADD = \
- $(top_builddir)/src/libtracker-common/libtracker-common.la \
- $(top_builddir)/src/libtracker-db/libtracker-db.la \
- $(QDBM_LIBS) \
- $(GLIB2_LIBS)
-
diff --git a/utils/qdbm/print-words.c b/utils/qdbm/print-words.c
deleted file mode 100644
index f32fb22..0000000
--- a/utils/qdbm/print-words.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2008, Nokia
-
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include <depot.h>
-
-#include <glib.h>
-
-#include <libtracker-db/tracker-db-index-item.h>
-
-#define USAGE "Usage: print -f qdbm-file\n"
-
-static gchar *filename;
-static gboolean print_services;
-
-static GOptionEntry entries[] = {
- { "index-file", 'f', 0,
- G_OPTION_ARG_STRING, &filename,
- "QDBM index file",
- NULL },
- { "print-services", 's', 0,
- G_OPTION_ARG_NONE, &print_services,
- "Print service ID and service type ID for each word",
- NULL },
- { NULL }
-};
-
-static TrackerDBIndexItem *
-get_word_hits (DEPOT *index,
- const gchar *word,
- guint *count)
-{
- TrackerDBIndexItem *details;
- gint tsiz;
- gchar *tmp;
-
- g_return_val_if_fail (word != NULL, NULL);
-
- details = NULL;
-
- if (count) {
- *count = 0;
- }
-
- if ((tmp = dpget (index, word, -1, 0, 100, &tsiz)) != NULL) {
- if (tsiz >= (gint) sizeof (TrackerDBIndexItem)) {
- details = (TrackerDBIndexItem *) tmp;
-
- if (count) {
- *count = tsiz / sizeof (TrackerDBIndexItem);
- }
- }
- }
-
- return details;
-}
-
-static void
-load_terms_from_index (gchar *filename)
-{
- DEPOT *depot;
- gchar *key;
- guint hits, i;
- TrackerDBIndexItem *results;
-
- depot = dpopen (filename, DP_OREADER | DP_ONOLCK, -1);
-
- if (depot == NULL) {
- g_print ("Unable to open file: %s "
- "(Could be a lock problem: is tracker running?)\n",
- filename);
- g_print ("Using version %s of qdbm\n",
- dpversion);
- return;
- }
-
- dpiterinit (depot);
-
- key = dpiternext (depot, NULL);
-
- while (key != NULL) {
- g_print (" - %s ", key);
-
- if (print_services) {
- results = get_word_hits (depot, key, &hits);
- for (i = 0; i < hits; i++) {
- g_print (" (id:%d s:%d) ",
- tracker_db_index_item_get_id (&results[i]),
- tracker_db_index_item_get_score (&results[i]));
- }
- }
-
- g_print ("\n");
- g_free (key);
- key = dpiternext (depot, NULL);
- }
-
- g_print ("Total: %d terms.\n", dprnum (depot));
- dpclose (depot);
-}
-
-int
-main (gint argc, gchar** argv)
-{
- GOptionContext *context;
- GError *error = NULL;
-
- context = g_option_context_new ("- QDBM index printer");
- g_option_context_add_main_entries (context, entries, NULL);
- g_option_context_parse (context, &argc, &argv, &error);
-
- if (error) {
- gchar *help;
-
- g_printerr ("Invalid arguments, %s\n", error->message);
-
- help = g_option_context_get_help (context, TRUE, NULL);
- g_printerr ("%s", help);
-
- g_free (help);
- g_clear_error (&error);
- g_option_context_free (context);
-
- return EXIT_FAILURE;
- }
-
- if (!filename) {
- gchar *help;
-
- help = g_option_context_get_help (context, TRUE, NULL);
- g_printerr ("%s", help);
-
- g_free (help);
- g_option_context_free (context);
-
- return EXIT_FAILURE;
- }
-
- g_option_context_free (context);
-
- load_terms_from_index (filename);
-
- return EXIT_SUCCESS;
-}
diff --git a/utils/qdbm/search-word.c b/utils/qdbm/search-word.c
deleted file mode 100644
index 9fb8913..0000000
--- a/utils/qdbm/search-word.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2008, Nokia
-
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include <glib.h>
-
-#include <depot.h>
-
-#include <libtracker-db/tracker-db-index-item.h>
-
-static gchar *filename;
-static gchar *word;
-
-static GOptionEntry entries[] = {
- { "index-file", 'f', 0,
- G_OPTION_ARG_STRING, &filename,
- "QDBM index file",
- NULL },
- { "word", 'w', 0,
- G_OPTION_ARG_STRING, &word,
- "Print service ID and service type ID of every hit for this word",
- NULL },
- { NULL }
-};
-
-static TrackerDBIndexItem *
-get_word_hits (DEPOT *index,
- const gchar *word,
- guint *count)
-{
- TrackerDBIndexItem *items;
- gchar *tmp;
- gint tsiz;
-
- g_return_val_if_fail (word != NULL, NULL);
-
- items = NULL;
-
- if (count) {
- *count = 0;
- }
-
- if ((tmp = dpget (index, word, -1, 0, 1000000, &tsiz)) != NULL) {
- if (tsiz >= (gint) sizeof (TrackerDBIndexItem)) {
- items = (TrackerDBIndexItem *) tmp;
-
- if (count) {
- *count = tsiz / sizeof (TrackerDBIndexItem);
- }
- }
- }
-
- return items;
-}
-
-static void
-show_term_in_index (const gchar *filename,
- const gchar *word)
-{
- TrackerDBIndexItem *items;
- DEPOT *depot;
- guint hits, i;
-
- hits = 0;
-
- depot = dpopen (filename, DP_OREADER, -1);
-
- if (depot == NULL) {
- g_print ("Unable to open file: %s "
- "(Could be a lock problem: is tracker running?)\n",
- filename);
- g_print ("Using version %s of qdbm\n",
- dpversion);
- return;
- }
-
- items = get_word_hits (depot, word, &hits);
-
- if (hits < 1 ) {
- g_print ("No results for %s\n", word);
- return;
- }
-
- g_print (" - %s ", word);
-
- for (i = 0; i < hits; i++) {
- g_print (" (id:%d) ",
- items[i].id);
- }
-
- g_print ("\n");
-
- g_print ("Total: %d terms.\n", dprnum (depot));
- dpclose (depot);
-}
-
-int
-main (gint argc, gchar** argv)
-{
- GOptionContext *context;
- GError *error = NULL;
-
- context = g_option_context_new ("- QDBM index searcher");
- g_option_context_add_main_entries (context, entries, NULL);
- g_option_context_parse (context, &argc, &argv, &error);
-
- if (error) {
- gchar *help;
-
- g_printerr ("Invalid arguments, %s\n", error->message);
-
- help = g_option_context_get_help (context, TRUE, NULL);
- g_printerr ("%s", help);
-
- g_free (help);
- g_clear_error (&error);
- g_option_context_free (context);
-
- return EXIT_FAILURE;
- }
-
- if (!filename || !word) {
- gchar *help;
-
- help = g_option_context_get_help (context, TRUE, NULL);
- g_printerr ("%s", help);
-
- g_free (help);
- g_option_context_free (context);
-
- return EXIT_FAILURE;
- }
-
- g_option_context_free (context);
-
- show_term_in_index (filename, word);
-
- return 0;
-}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]