Use google.db, if open-phrase.db does not exist.
authorPeng Huang <shawn.p.huang@gmail.com>
Mon, 5 Oct 2009 06:24:55 +0000 (14:24 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Mon, 5 Oct 2009 06:24:55 +0000 (14:24 +0800)
15 files changed:
Makefile.am
configure.ac
data/Makefile.am
data/create_index.sql [moved from data/google/create_index.sql with 100% similarity]
data/db/Makefile.am [new file with mode: 0644]
data/db/google/README [moved from data/google/README with 100% similarity]
data/db/google/create_db_from_google.py [moved from data/google/create_db_from_google.py with 100% similarity]
data/db/google/id.py [new symlink]
data/db/google/pydict.py [new symlink]
data/db/google/rawdict_utf16_65105_freq.txt [moved from data/google/rawdict_utf16_65105_freq.txt with 100% similarity]
data/db/google/valid_utf16.txt [moved from data/google/valid_utf16.txt with 100% similarity]
data/db/open-phrase/Makefile.am [new file with mode: 0644]
data/google/id.py [deleted symlink]
data/google/pydict.py [deleted symlink]
src/Database.cc

index 968cefa..a39343d 100644 (file)
@@ -26,6 +26,11 @@ SUBDIRS = \
        po \
        $(NULL)
 
+DISTCHECK_CONFIGURE_FLAGS = \
+       --enable-google \
+       --enable-db-open-phrase \
+       $(NULL)
+
 ACLOCAL_AMFLAGS = -I m4
 
 EXTRA_DIST = \
index 4b2b0fc..9205f21 100644 (file)
@@ -78,18 +78,25 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Define to the read-only
 
 AM_GNU_GETTEXT([external])
 AM_GNU_GETTEXT_VERSION(0.16.1)
-AC_ARG_VAR(DATABASE, AS_HELP_STRING([pinyin database google or open-phrase, the default is google]))
-
-test x"$DATABASE" != x"open-phrase" && DATABASE=google
-# --enable-build-db
-# AC_ARG_ENABLE(pinyin-database,
-#     AS_HELP_STRING([--enable-pinyin-database=[google,open-phrase]],
-#         [do not build pinyin database]),
-#     [enable_pinyin_database=$enableval],
-#     [enable_pinyin_database=google]
-# )
-AM_CONDITIONAL(IBUS_BUILD_DB_GOOGLE, [test x"$DATABASE" = x"google" ])
-AM_CONDITIONAL(IBUS_BUILD_DB_OPEN_PHRASE, [test x"$DATABASE" = x"open-phrase" ])
+
+
+# --enable-db-google
+AC_ARG_ENABLE(db-google,
+    AS_HELP_STRING([--disable-db-google],
+        [do not build database from google android pinyin]),
+    [enable_db_google=$enableval],
+    [enable_db_google=yes]
+)
+AM_CONDITIONAL(IBUS_BUILD_DB_GOOGLE, [test x"$enable_db_google" = x"yes" ])
+
+# --enable-db-open-phrase
+AC_ARG_ENABLE(db-open-phrase,
+    AS_HELP_STRING([--enable-db-open-phrase],
+        [build open-phrase database]),
+    [enable_db_open_phrase=$enableval],
+    [enable_db_open_phrase=no]
+)
+AM_CONDITIONAL(IBUS_BUILD_DB_OPEN_PHRASE, [test x"$enable_db_open_phrase" = x"yes" ])
 
 # OUTPUT files
 AC_CONFIG_FILES([ po/Makefile.in
@@ -100,7 +107,9 @@ src/pinyin.xml.in
 setup/Makefile
 setup/ibus-setup-pinyin
 data/Makefile
-data/google/Makefile
+data/db/Makefile
+data/db/google/Makefile
+data/db/open-phrase/Makefile
 data/icons/Makefile
 m4/Makefile
 ])
@@ -109,9 +118,9 @@ AC_OUTPUT
 
 AC_MSG_RESULT([
 Build options:
-    Version                 $VERSION
-    Install prefix          $prefix
-    Build pinyin database   $enable_pinyin_database
-    Pinyin datatbase        $DATABASE
+    Version                     $VERSION
+    Install prefix              $prefix
+    Build database google       $enable_db_google
+    Build database open-phrase  $enable_db_open_phrase
 ])
 
index 59e0d3d..64ac271 100644 (file)
 
 
 SUBDIRS = \
-       google \
+       db \
        icons \
        $(NULL)
 
-if IBUS_BUILD_DB_OPEN_PHRASE
-main_db_DATA = \
-       db/main.db \
-       db/COPYING \
-       db/create_index.sql \
-       $(NULL)
-main_dbdir = $(pkgdatadir)/db
-
-install-data-hook:
-       @( \
-if test "$(NO_INDEX)" = ""; then \
-  cd $(DESTDIR)$(main_dbdir); \
-  echo "Create INDEX"; \
-  sqlite3 main.db ".read create_index.sql"; \
-fi)
-
-DBVER = 1.2.99
-DBTAR = pinyin-database-$(DBVER).tar.bz2
-
-$(DBTAR):
-       wget http://ibus.googlecode.com/files/$(DBTAR)
-
-stamp-db: $(DBTAR)
-       tar jxvfm $(DBTAR)
-       touch $@
-
-$(main_db_DATA): stamp-db
-
-CLEANFILES = \
-       stamp-db \
-       db/* \
-       $(NULL)
-
-DISTCLEANFILES = \
-       $(DBTAR) \
-       $(NULL)
-endif
-
diff --git a/data/db/Makefile.am b/data/db/Makefile.am
new file mode 100644 (file)
index 0000000..d7340b4
--- /dev/null
@@ -0,0 +1,43 @@
+# vim:set noet ts=4:
+#
+# ibus-pinyin - The Chinese PinYin engine for IBus
+#
+# Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
+#
+# This program 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, or (at your option)
+# any later version.
+#
+# This program 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 program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+
+SUBDIRS = \
+       google \
+       open-phrase \
+       $(NULL)
+
+main_db_DATA = \
+       create_index.sql \
+       $(NULL)
+main_dbdir = $(pkgdatadir)/db
+
+install-data-hook:
+       @( \
+if test "$(NO_INDEX)" = ""; then \
+  cd $(DESTDIR)$(main_dbdir); \
+  echo "Create INDEX"; \
+  sqlite3 main.db ".read create_index.sql"; \
+fi)
+
+EXTRA_DIST = \
+       create_index.sql \
+       $(NULL)
+
similarity index 100%
rename from data/google/README
rename to data/db/google/README
diff --git a/data/db/google/id.py b/data/db/google/id.py
new file mode 120000 (symlink)
index 0000000..feea3e1
--- /dev/null
@@ -0,0 +1 @@
+../../../scripts/id.py
\ No newline at end of file
diff --git a/data/db/google/pydict.py b/data/db/google/pydict.py
new file mode 120000 (symlink)
index 0000000..762c55e
--- /dev/null
@@ -0,0 +1 @@
+../../../scripts/pydict.py
\ No newline at end of file
diff --git a/data/db/open-phrase/Makefile.am b/data/db/open-phrase/Makefile.am
new file mode 100644 (file)
index 0000000..67f6863
--- /dev/null
@@ -0,0 +1,60 @@
+# vim:set noet ts=4:
+#
+# ibus-pinyin - The Chinese PinYin engine for IBus
+#
+# Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
+#
+# This program 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, or (at your option)
+# any later version.
+#
+# This program 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 program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+
+if IBUS_BUILD_DB_OPEN_PHRASE
+db_file = open-phrase.db
+main_db_DATA = \
+       db/$(db_file) \
+       db/COPYING \
+       $(NULL)
+main_dbdir = $(pkgdatadir)/db
+
+install-data-hook:
+       @( \
+if test "$(NO_INDEX)" = ""; then \
+  cd $(DESTDIR)$(main_dbdir); \
+  echo "Create INDEX"; \
+  sqlite3 $(db_file) ".read create_index.sql"; \
+fi)
+
+DBVER = 1.2.99
+DBTAR = pinyin-database-$(DBVER).tar.bz2
+
+$(DBTAR):
+       wget http://ibus.googlecode.com/files/$(DBTAR)
+
+stamp-db: $(DBTAR)
+       tar jxvfm $(DBTAR)
+       mv db/main.db db/$(db_file)
+       touch $@
+
+$(main_db_DATA): stamp-db
+
+CLEANFILES = \
+       stamp-db \
+       db/* \
+       $(NULL)
+
+DISTCLEANFILES = \
+       $(DBTAR) \
+       $(NULL)
+endif
+
diff --git a/data/google/id.py b/data/google/id.py
deleted file mode 120000 (symlink)
index 613c15c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/id.py
\ No newline at end of file
diff --git a/data/google/pydict.py b/data/google/pydict.py
deleted file mode 120000 (symlink)
index 03c0c4a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../scripts/pydict.py
\ No newline at end of file
index ccb9906..29c1b8e 100644 (file)
@@ -57,11 +57,23 @@ Database::init (void)
     sqlite3_initialize ();
 #endif
 
-    if (sqlite3_open_v2 (PKGDATADIR"/db/main.db", &m_db,
-            SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK) {
-        if (sqlite3_open_v2 ("main.db", &m_db,
-                SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK)
-            goto _failed;
+    static const gchar * maindb [] = {
+        PKGDATADIR"/db/open-phrase.db",
+        PKGDATADIR"/db/google.db",
+        "main.db",
+        NULL
+    };
+
+    guint i;
+    for (i = 0; maindb[i] != NULL; i++) {
+        if (sqlite3_open_v2 (maindb[i], &m_db,
+            SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) == SQLITE_OK)
+            break;
+    }
+
+    if (maindb[i] == NULL) {
+        g_warning ("can not open main database");
+        goto _failed;
     }
 
     m_sql.truncate (0);