Hello community,
here is the log from the commit of package fcitx-cloudpinyin for openSUSE:Factory checked in at 2012-09-20 15:24:17
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/fcitx-cloudpinyin (Old)
and /work/SRC/openSUSE:Factory/.fcitx-cloudpinyin.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "fcitx-cloudpinyin", Maintainer is ""
Changes:
--------
--- /work/SRC/openSUSE:Factory/fcitx-cloudpinyin/fcitx-cloudpinyin.changes 2012-07-22 21:59:09.000000000 +0200
+++ /work/SRC/openSUSE:Factory/.fcitx-cloudpinyin.new/fcitx-cloudpinyin.changes 2012-09-20 15:24:22.000000000 +0200
@@ -1,0 +2,10 @@
+Sat Sep 15 21:01:25 UTC 2012 - i@marguerite.su
+
+- update version 0.3.0
+ * Make sure the first candidate word is always useable
+ (even if cloud pinyin candidate word was set to the first
+ one and there is no response from the server)
+ * Remove the duplicated candidate word if netword is fast,
+ leave a place holder otherwise
+
+-------------------------------------------------------------------
Old:
----
fcitx-cloudpinyin-0.2.3.tar.bz2
New:
----
fcitx-cloudpinyin-0.3.0.tar.bz2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ fcitx-cloudpinyin.spec ++++++
--- /var/tmp/diff_new_pack.IJenEv/_old 2012-09-20 15:24:22.000000000 +0200
+++ /var/tmp/diff_new_pack.IJenEv/_new 2012-09-20 15:24:22.000000000 +0200
@@ -18,7 +18,7 @@
Name: fcitx-cloudpinyin
-Version: 0.2.3
+Version: 0.3.0
Release: 0
Summary: Cloudpinyin module for fcitx
Group: System/I18n/Chinese
++++++ fcitx-cloudpinyin-0.2.3.tar.bz2 -> fcitx-cloudpinyin-0.3.0.tar.bz2 ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/.gitignore new/fcitx-cloudpinyin-0.3.0/.gitignore
--- old/fcitx-cloudpinyin-0.2.3/.gitignore 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/.gitignore 2012-09-12 16:00:12.000000000 +0200
@@ -1,7 +1,13 @@
+*~
build/*
+.*
+!.git*
+.git/
*.kdev4
-.kdev_include_paths
-.directory
*.kate-swp
*.orig
-*~
+tags
+astyle.sh
+cscope.*
+.kdev_include_paths
+.directory
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/CMakeLists.txt new/fcitx-cloudpinyin-0.3.0/CMakeLists.txt
--- old/fcitx-cloudpinyin-0.2.3/CMakeLists.txt 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/CMakeLists.txt 2012-09-12 16:00:12.000000000 +0200
@@ -2,11 +2,12 @@
cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
-find_package(Fcitx 4.2.5 REQUIRED)
+find_package(Fcitx 4.2.6 REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(Gettext REQUIRED)
find_package(Libintl REQUIRED)
find_package(Libiconv REQUIRED)
+find_package(Pthread REQUIRED)
# uninstall target
configure_file(
@@ -24,7 +25,12 @@
pkg_check_modules(CURL "libcurl" REQUIRED)
+set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/locale")
+
configure_file(config.h.in config.h)
+enable_testing()
+
add_subdirectory(src)
add_subdirectory(po)
+add_subdirectory(test)
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/cmake/FindPthread.cmake new/fcitx-cloudpinyin-0.3.0/cmake/FindPthread.cmake
--- old/fcitx-cloudpinyin-0.2.3/cmake/FindPthread.cmake 1970-01-01 01:00:00.000000000 +0100
+++ new/fcitx-cloudpinyin-0.3.0/cmake/FindPthread.cmake 2012-09-12 16:00:12.000000000 +0200
@@ -0,0 +1,46 @@
+# Try to find Pthread functionality
+# Once done this will define
+#
+# PTHREAD_FOUND - system has Pthread
+# PTHREAD_INCLUDE_DIR - Pthread include directory
+# PTHREAD_LIBRARIES - Libraries needed to use Pthread
+#
+# TODO: This will enable translations only if Gettext functionality is
+# present in libc. Must have more robust system for release, where Gettext
+# functionality can also reside in standalone Gettext library, or the one
+# embedded within kdelibs (cf. gettext.m4 from Gettext source).
+
+# Copyright (c) 2006, Chusslove Illich,
+# Copyright (c) 2007, Alexander Neundorf,
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+if(PTHREAD_INCLUDE_DIR AND PTHREAD_LIB_FOUND)
+ set(Pthread_FIND_QUIETLY TRUE)
+endif(PTHREAD_INCLUDE_DIR AND PTHREAD_LIB_FOUND)
+
+find_path(PTHREAD_INCLUDE_DIR pthread.h)
+
+set(PTHREAD_LIB_FOUND FALSE)
+
+if(PTHREAD_INCLUDE_DIR)
+ include(CheckFunctionExists)
+ check_function_exists(pthread_create PTHREAD_LIBC_HAS_PTHREAD_CREATE)
+
+ if (PTHREAD_LIBC_HAS_PTHREAD_CREATE)
+ set(PTHREAD_LIBRARIES)
+ set(PTHREAD_LIB_FOUND TRUE)
+ else (PTHREAD_LIBC_HAS_PTHREAD_CREATE)
+ find_library(PTHREAD_LIBRARIES NAMES pthread libpthread )
+ if(PTHREAD_LIBRARIES)
+ set(PTHREAD_LIB_FOUND TRUE)
+ endif(PTHREAD_LIBRARIES)
+ endif (PTHREAD_LIBC_HAS_PTHREAD_CREATE)
+
+endif(PTHREAD_INCLUDE_DIR)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Pthread DEFAULT_MSG PTHREAD_INCLUDE_DIR PTHREAD_LIB_FOUND)
+
+mark_as_advanced(PTHREAD_INCLUDE_DIR PTHREAD_LIBRARIES PTHREAD_LIBC_HAS_PTHREAD_CREATE PTHREAD_LIB_FOUND)
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/config.h.in new/fcitx-cloudpinyin-0.3.0/config.h.in
--- old/fcitx-cloudpinyin-0.2.3/config.h.in 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/config.h.in 2012-09-12 16:00:12.000000000 +0200
@@ -1 +1,9 @@
-#cmakedefine LIBICONV_SECOND_ARGUMENT_IS_CONST
\ No newline at end of file
+#cmakedefine LIBICONV_SECOND_ARGUMENT_IS_CONST
+#cmakedefine LOCALEDIR "@LOCALEDIR@"
+#define _GNU_SOURCE
+
+#ifdef LIBICONV_SECOND_ARGUMENT_IS_CONST
+typedef const char* IconvStr;
+#else
+typedef char* IconvStr;
+#endif
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/po/CMakeLists.txt new/fcitx-cloudpinyin-0.3.0/po/CMakeLists.txt
--- old/fcitx-cloudpinyin-0.2.3/po/CMakeLists.txt 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/po/CMakeLists.txt 2012-09-12 16:00:12.000000000 +0200
@@ -9,10 +9,7 @@
configure_file(POTFILES.in.in ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in)
extract_fcitx_addon_conf_postring()
-
-add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/desc.po
- COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/getdescpo ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
- DEPENDS getdescpo)
+extract_fcitx_desc_file_postring()
add_custom_target(
pot
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/po/fcitx-cloudpinyin.pot new/fcitx-cloudpinyin-0.3.0/po/fcitx-cloudpinyin.pot
--- old/fcitx-cloudpinyin-0.2.3/po/fcitx-cloudpinyin.pot 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/po/fcitx-cloudpinyin.pot 2012-09-12 16:00:12.000000000 +0200
@@ -8,7 +8,7 @@
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-08-27 22:05+0800\n"
+"POT-Creation-Date: 2012-08-29 18:07-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
@@ -17,23 +17,19 @@
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:4
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:5
msgid "Cloud Pinyin Candidate Word Order"
msgstr ""
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:9
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:11
msgid "Minimum Length of Pinyin To Trigger Cloud Pinyin"
msgstr ""
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:14
-msgid "Only use origin Pinyin to query the result"
-msgstr ""
-
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:19
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:16
msgid "Don't Show the 'via cloud' hint"
msgstr ""
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:24
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:21
msgid "Cloud Pinyin Source"
msgstr ""
@@ -42,6 +38,10 @@
msgstr ""
#: unknown
+msgid "Baidu"
+msgstr ""
+
+#: unknown
msgid "Google"
msgstr ""
@@ -54,13 +54,13 @@
msgstr ""
#: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:1
-msgid "Add Cloud Pinyin Support to Pinyin Input Method"
+msgid "Cloud Pinyin"
msgstr ""
#: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:2
-msgid "Cloud Pinyin"
+msgid "Add Cloud Pinyin Support to Pinyin Input Method"
msgstr ""
-#: /home/saber/Develop/fcitx-cloudpinyin/build/po/../..//src/cloudpinyin.c:487
+#: /home/saber/Develop/fcitx-cloudpinyin/build/po/../..//src/cloudpinyin.c:588
msgid " (via cloud)"
msgstr ""
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/po/getdescpo new/fcitx-cloudpinyin-0.3.0/po/getdescpo
--- old/fcitx-cloudpinyin-0.2.3/po/getdescpo 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/po/getdescpo 1970-01-01 01:00:00.000000000 +0100
@@ -1,46 +0,0 @@
-#!/bin/sh
-filename=desc.po
-indir=$1
-outdir=$2
-
-cd "$outdir"
-
-rm -f "$outdir/$filename"; touch "$outdir/$filename"
-
-cat > "$outdir/$filename" <, YEAR.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
-"Report-Msgid-Bugs-To: fcitx-dev@googlegroups.com\n"
-"POT-Creation-Date: 2010-11-17 11:48+0800\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME \n"
-"Language-Team: LANGUAGE \n"
-"Language: \n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-EOF
-
-cd $indir
-
-descfiles=`find "$indir" -name ".hg" -prune -or -name "test" -prune -or -iname "*.desc" | grep desc`
-
-# Extract Description
-for f in $descfiles
-do
- awk '/^[\t ]*Description=/ { print "\n#: '$f':" NR"\n" "msgid \"" substr($0, 13)"\"\n" "msgstr \"\""}' "$f" >> "$outdir/$filename"
-done
-
-# Extract Group Name
-grep -nH '^\[' $descfiles | grep -v 'DescriptionFile' | awk ' "^[" { split($0, a, ":"); split(a[3], b, "/"); print substr(b[1], 2); }' | sort | uniq | awk '{ print "# unknown\nmsgid \""$0"\"\nmsgstr \"\"\n"; }' >> "$outdir/$filename"
-
-# Extract Enum Name
-grep -h 'Enum[0-9]' $descfiles | sed -e 's/Enum[0-9]=//g' | sort | uniq | awk '{ print "#: unknown\nmsgid \""$0"\"\nmsgstr \"\"\n"; }' >> "$outdir/$filename"
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/po/zh_CN.po new/fcitx-cloudpinyin-0.3.0/po/zh_CN.po
--- old/fcitx-cloudpinyin-0.2.3/po/zh_CN.po 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/po/zh_CN.po 2012-09-12 16:00:12.000000000 +0200
@@ -8,9 +8,9 @@
msgstr ""
"Project-Id-Version: fcitx\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-08-27 22:05+0800\n"
-"PO-Revision-Date: 2011-11-16 06:56+0000\n"
-"Last-Translator: csslayer \n"
+"POT-Creation-Date: 2012-08-29 18:07-0400\n"
+"PO-Revision-Date: 2012-08-29 20:00-0400\n"
+"Last-Translator: Yichao Yu \n"
"Language-Team: Chinese (China) \n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
@@ -18,23 +18,27 @@
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0\n"
-#: /home/saber/Develop/fcitx-cloudpinyin/build/po/../..//src/cloudpinyin.c:487
+#: /home/saber/Develop/fcitx-cloudpinyin/build/po/../..//src/cloudpinyin.c:588
msgid " (via cloud)"
msgstr " (来自云)"
-#: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:1
+#: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:2
msgid "Add Cloud Pinyin Support to Pinyin Input Method"
msgstr "为拼音输入法加入云拼音支持"
-#: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:2
+#: unknown
+msgid "Baidu"
+msgstr "百度"
+
+#: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:1
msgid "Cloud Pinyin"
msgstr "云拼音"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:4
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:5
msgid "Cloud Pinyin Candidate Word Order"
msgstr "云拼音候选词顺序"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:24
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:21
msgid "Cloud Pinyin Source"
msgstr "云拼音来源"
@@ -42,7 +46,7 @@
msgid "CloudPinyin"
msgstr "云拼音"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:19
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:16
msgid "Don't Show the 'via cloud' hint"
msgstr "不显示‘来自云’提示"
@@ -50,14 +54,10 @@
msgid "Google"
msgstr "Google"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:9
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:11
msgid "Minimum Length of Pinyin To Trigger Cloud Pinyin"
msgstr "最小触发云拼音的拼音长度"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:14
-msgid "Only use origin Pinyin to query the result"
-msgstr "只使用原始拼音查询结果"
-
#: unknown
msgid "QQ"
msgstr "QQ"
@@ -65,3 +65,6 @@
#: unknown
msgid "Sogou"
msgstr "搜狗"
+
+#~ msgid "Only use origin Pinyin to query the result"
+#~ msgstr "只使用原始拼音查询结果"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/po/zh_TW.po new/fcitx-cloudpinyin-0.3.0/po/zh_TW.po
--- old/fcitx-cloudpinyin-0.2.3/po/zh_TW.po 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/po/zh_TW.po 2012-09-12 16:00:12.000000000 +0200
@@ -8,7 +8,7 @@
msgstr ""
"Project-Id-Version: fcitx\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2011-08-27 22:05+0800\n"
+"POT-Creation-Date: 2012-08-29 18:07-0400\n"
"PO-Revision-Date: 2012-01-26 16:05+0000\n"
"Last-Translator: Alisha \n"
"Language-Team: Chinese (Taiwan) (http://www.transifex.net/projects/p/fcitx/"
@@ -19,23 +19,27 @@
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0\n"
-#: /home/saber/Develop/fcitx-cloudpinyin/build/po/../..//src/cloudpinyin.c:487
+#: /home/saber/Develop/fcitx-cloudpinyin/build/po/../..//src/cloudpinyin.c:588
msgid " (via cloud)"
msgstr "(來自雲)"
-#: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:1
+#: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:2
msgid "Add Cloud Pinyin Support to Pinyin Input Method"
msgstr "為拼音輸入法加入雲拼音支援"
-#: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:2
+#: unknown
+msgid "Baidu"
+msgstr ""
+
+#: /home/saber/Develop/fcitx-cloudpinyin/build/po/tmp/fcitx-cloudpinyin.conf.in.h:1
msgid "Cloud Pinyin"
msgstr "雲拼音"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:4
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:5
msgid "Cloud Pinyin Candidate Word Order"
msgstr "雲拼音候選字順序"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:24
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:21
msgid "Cloud Pinyin Source"
msgstr "雲拼音來源"
@@ -43,7 +47,7 @@
msgid "CloudPinyin"
msgstr "雲拼音"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:19
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:16
msgid "Don't Show the 'via cloud' hint"
msgstr "不顯示「來自雲」提示"
@@ -51,14 +55,10 @@
msgid "Google"
msgstr "Google"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:9
+#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:11
msgid "Minimum Length of Pinyin To Trigger Cloud Pinyin"
msgstr "最小觸發雲拼音的拼音長度"
-#: /home/saber/Develop/fcitx-cloudpinyin/src/fcitx-cloudpinyin.desc:14
-msgid "Only use origin Pinyin to query the result"
-msgstr "只使用原始拼音查詢結果"
-
#: unknown
msgid "QQ"
msgstr "QQ"
@@ -66,3 +66,6 @@
#: unknown
msgid "Sogou"
msgstr "搜狗"
+
+#~ msgid "Only use origin Pinyin to query the result"
+#~ msgstr "只使用原始拼音查詢結果"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/src/CMakeLists.txt new/fcitx-cloudpinyin-0.3.0/src/CMakeLists.txt
--- old/fcitx-cloudpinyin-0.2.3/src/CMakeLists.txt 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/src/CMakeLists.txt 2012-09-12 16:00:12.000000000 +0200
@@ -2,6 +2,7 @@
${PROJECT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CURL_INCLUDE_DIRS}
+ ${PTHREAD_INCLUDE_DIR}
${FCITX4_FCITX_INCLUDE_DIRS}
${FCITX4_FCITX_CONFIG_INCLUDE_DIRS}
${FCITX4_FCITX_UTILS_INCLUDE_DIRS}
@@ -16,13 +17,14 @@
cloudpinyin.c
cloudpinyinconifg.c
fetch.c
+ parse.c
)
fcitx_add_addon(fcitx-cloudpinyin ${FCITX_CLOUDPINYIN_SRCS})
-add_definitions( -DLOCALEDIR=\"${CMAKE_INSTALL_PREFIX}/share/locale\" -D_GNU_SOURCE )
target_link_libraries( fcitx-cloudpinyin
${CURL_LIBRARIES}
${LIBINTL_LIBRARIES}
+ ${PTHREAD_LIBRARIES}
)
fcitx_add_addon_conf_file(fcitx-cloudpinyin.conf)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/src/cloudpinyin.c new/fcitx-cloudpinyin-0.3.0/src/cloudpinyin.c
--- old/fcitx-cloudpinyin-0.2.3/src/cloudpinyin.c 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/src/cloudpinyin.c 2012-09-12 16:00:12.000000000 +0200
@@ -18,6 +18,8 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+#include "config.h"
+
#include
#include
#include
@@ -27,16 +29,15 @@
#include
#include
-#include
#include
#include
#include
#include
#include
-#include "config.h"
#include "cloudpinyin.h"
#include "fetch.h"
+#include "parse.h"
#define CHECK_VALID_IM (im && \
strcmp(im->langCode, "zh_CN") == 0 && \
@@ -45,20 +46,16 @@
strcmp(im->uniqueName, "shuangpin-libpinyin") == 0 || \
strcmp(im->uniqueName, "googlepinyin") == 0 || \
strcmp(im->uniqueName, "sunpinyin") == 0 || \
- strcmp(im->uniqueName, "shuangpin") == 0))
+ strcmp(im->uniqueName, "shuangpin") == 0 || \
+ strcmp(im->uniqueName, "sogou-pinyin") == 0))
#define CLOUDPINYIN_CHECK_PAGE_NUMBER 3
#define LOGLEVEL DEBUG
-#ifdef LIBICONV_SECOND_ARGUMENT_IS_CONST
-typedef const char* IconvStr;
-#else
-typedef char* IconvStr;
-#endif
-
typedef struct _CloudCandWord {
boolean filled;
+ uint64_t timestamp;
} CloudCandWord;
typedef struct _CloudPinyinEngine {
@@ -85,18 +82,12 @@
static void CloudPinyinFillCandidateWord(FcitxCloudPinyin* cloudpinyin, const char* pinyin);
static boolean LoadCloudPinyinConfig(FcitxCloudPinyinConfig* fs);
static void SaveCloudPinyinConfig(FcitxCloudPinyinConfig* fs);
-static char *GetCurrentString(FcitxCloudPinyin* cloudpinyin);
-static char* SplitHZAndPY(char* string);
+static char *GetCurrentString(FcitxCloudPinyin* cloudpinyin,
+ char **ascii_part);
static void CloudPinyinHookForNewRequest(void* arg);
static CURL* CloudPinyinGetFreeCurlHandle(FcitxCloudPinyin* cloudpinyin);
-static void CloudPinyinReleaseCurlHandle(FcitxCloudPinyin* cloudpinyin, CURL* curl);
-
-void SogouParseKey(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
-char* SogouParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
-void QQParseKey(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
-char* QQParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
-char* GoogleParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
-char* BaiduParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
+static void CloudPinyinReleaseCurlHandle(FcitxCloudPinyin* cloudpinyin,
+ CURL* curl);
CloudPinyinEngine engine[4] =
{
@@ -129,39 +120,46 @@
CONFIG_DESC_DEFINE(GetCloudPinyinConfigDesc, "fcitx-cloudpinyin.desc")
-FCITX_EXPORT_API
-FcitxModule module = {
- CloudPinyinCreate,
- CloudPinyinSetFD,
- CloudPinyinProcessEvent,
- CloudPinyinDestroy,
- CloudPinyinReloadConfig
+FCITX_DEFINE_PLUGIN(fcitx_cloudpinyin, module, FcitxModule) = {
+ .Create = CloudPinyinCreate,
+ .Destroy = CloudPinyinDestroy,
+ .SetFD = CloudPinyinSetFD,
+ .ProcessEvent = CloudPinyinProcessEvent,
+ .ReloadConfig = CloudPinyinReloadConfig
};
-FCITX_EXPORT_API
-int ABI_VERSION = FCITX_ABI_VERSION;
-
-static inline boolean ishex(char ch)
-{
- if ((ch >= '0' && ch <= '9') || (ch >='a' && ch <='f') || (ch >='A' && ch <='F'))
- return true;
- return false;
-}
-
-static inline unsigned char tohex(char ch)
+static uint64_t
+CloudGetTimeStamp()
{
- if (ch >= '0' && ch <= '9')
- return ch - '0';
- if (ch >='a' && ch <='f')
- return ch - 'a' + 10;
- if (ch >='A' && ch <='F')
- return ch - 'A' + 10;
- return 0;
+ struct timeval current_time;
+ gettimeofday(¤t_time, NULL);
+ return (((uint64_t)current_time.tv_sec * 1000)
+ + (current_time.tv_usec / 1000));
+}
+
+static void
+CloudSetClientPreedit(FcitxCloudPinyin *cloudpinyin, const char *str)
+{
+ FcitxInputState *input = FcitxInstanceGetInputState(cloudpinyin->owner);
+ FcitxMessages *message = FcitxInputStateGetClientPreedit(input);
+ char *py;
+ char *string = GetCurrentString(cloudpinyin, &py);
+ FcitxMessagesSetMessageCount(message, 0);
+ if (py) {
+ *py = '\0';
+ FcitxMessagesAddMessageAtLast(message, MSG_INPUT, "%s%s", string, str);
+ } else {
+ FcitxMessagesAddMessageAtLast(message, MSG_INPUT, "%s", str);
+ }
+ if (string)
+ free(string);
+ FcitxInstanceUpdateClientSideUI(
+ cloudpinyin->owner, FcitxInstanceGetCurrentIC(cloudpinyin->owner));
}
void* CloudPinyinCreate(FcitxInstance* instance)
{
- FcitxCloudPinyin* cloudpinyin = fcitx_utils_malloc0(sizeof(FcitxCloudPinyin));
+ FcitxCloudPinyin *cloudpinyin = fcitx_utils_new(FcitxCloudPinyin);
bindtextdomain("fcitx-cloudpinyin", LOCALEDIR);
cloudpinyin->owner = instance;
int pipe1[2];
@@ -277,11 +275,9 @@
if (FcitxInputStateGetRawInputBufferSize(input) >= cloudpinyin->config.iMinimumPinyinLength)
{
char* strToFree = NULL, *inputString;
- strToFree = GetCurrentString(cloudpinyin);
- inputString = SplitHZAndPY(strToFree);
+ strToFree = GetCurrentString(cloudpinyin, &inputString);
- if (inputString)
- {
+ if (inputString) {
CloudPinyinCache* cacheEntry = CloudPinyinCacheLookup(cloudpinyin, inputString);
FcitxLog(LOGLEVEL, "%s", inputString);
if (cacheEntry == NULL)
@@ -446,11 +442,9 @@
FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner);
char* strToFree = NULL, *inputString;
- strToFree = GetCurrentString(cloudpinyin);
- inputString = SplitHZAndPY(strToFree);
+ strToFree = GetCurrentString(cloudpinyin, &inputString);
- if (inputString)
- {
+ if (inputString) {
FcitxLog(LOGLEVEL, "fill: %s %s", inputString, queue->pinyin);
if (strcmp(inputString, queue->pinyin) == 0)
{
@@ -549,41 +543,44 @@
FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner);
FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);
- int order = cloudpinyin->config.iCandidateOrder - 1;
- if (order < 0)
- order = 0;
+ int order = (cloudpinyin->config.iCandidateOrder <= 2) ?
+ 1 : (cloudpinyin->config.iCandidateOrder - 1);
if (cacheEntry) {
FcitxCandidateWord* cand;
/* only check the first three page */
int pagesize = FcitxCandidateWordGetPageSize(candList);
int size = pagesize * CLOUDPINYIN_CHECK_PAGE_NUMBER;
- int i = 0;
- for (cand = FcitxCandidateWordGetFirst(candList);
- cand != NULL;
- cand = FcitxCandidateWordGetNext(candList, cand))
- {
+ int i;
+ if (cloudpinyin->config.iCandidateOrder <= 1) {
+ order = 0;
+ }
+ for (i = 0;i < size &&
+ (cand = FcitxCandidateWordGetByTotalIndex(candList, i));i++) {
if (strcmp(cand->strWord, cacheEntry->str) == 0) {
- if (i > order && i >= pagesize)
+ if (i > order && i >= pagesize) {
FcitxCandidateWordMoveByWord(candList, cand, order);
+ if (order == 0) {
+ CloudSetClientPreedit(cloudpinyin, cacheEntry->str);
+ }
+ }
return;
}
- i ++;
- if (i >= size)
- break;
+ }
+ if (order == 0) {
+ CloudSetClientPreedit(cloudpinyin, cacheEntry->str);
}
}
FcitxCandidateWord candWord;
CloudCandWord* cloudCand = fcitx_utils_malloc0(sizeof(CloudCandWord));
- if (cacheEntry)
- {
+ if (cacheEntry) {
cloudCand->filled = true;
+ cloudCand->timestamp = 0;
candWord.strWord = strdup(cacheEntry->str);
- }
- else
- {
+ } else {
cloudCand->filled = false;
+ cloudCand->timestamp = CloudGetTimeStamp();
candWord.strWord = strdup("..");
}
@@ -601,22 +598,23 @@
FcitxCandidateWordInsert(candList, &candWord, order);
}
-void CloudPinyinFillCandidateWord(FcitxCloudPinyin* cloudpinyin, const char* pinyin)
+#define LOADING_TIME_QUICK_THRESHOLD 300
+#define DUP_PLACE_HOLDER "\xe2\x98\xba"
+
+void CloudPinyinFillCandidateWord(FcitxCloudPinyin* cloudpinyin,
+ const char* pinyin)
{
CloudPinyinCache* cacheEntry = CloudPinyinCacheLookup(cloudpinyin, pinyin);
FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner);
- struct _FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);
- if (cacheEntry)
- {
- int cloudidx = 0;
- FcitxCandidateWord* candWord;
- for (candWord = FcitxCandidateWordGetFirst(candList);
- candWord != NULL;
- candWord = FcitxCandidateWordGetNext(candList, candWord))
- {
+ FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);
+ if (cacheEntry) {
+ int cloudidx;
+ FcitxCandidateWord *candWord;
+ for (cloudidx = 0;
+ (candWord = FcitxCandidateWordGetByTotalIndex(candList, cloudidx));
+ cloudidx++) {
if (candWord->owner == cloudpinyin)
break;
- cloudidx ++;
}
if (candWord == NULL)
@@ -626,28 +624,36 @@
if (cloudCand->filled)
return;
- FcitxCandidateWord* cand;
- int i = 0;
+ FcitxCandidateWord *cand;
+ int i;
int pagesize = FcitxCandidateWordGetPageSize(candList);
int size = pagesize * CLOUDPINYIN_CHECK_PAGE_NUMBER;
- for (cand = FcitxCandidateWordGetFirst(candList);
- cand != NULL;
- cand = FcitxCandidateWordGetNext(candList, cand))
- {
+ for (i = 0;i < size &&
+ (cand = FcitxCandidateWordGetByTotalIndex(candList, i));i++) {
if (strcmp(cand->strWord, cacheEntry->str) == 0) {
FcitxCandidateWordRemove(candList, candWord);
/* if cloud word is not on the first page.. impossible */
if (cloudidx < pagesize) {
/* if the duplication before cloud word */
if (i < cloudidx) {
- FcitxCandidateWordInsertPlaceHolder(candList, cloudidx);
- }
- else {
+ if (CloudGetTimeStamp() - cloudCand->timestamp
+ > LOADING_TIME_QUICK_THRESHOLD) {
+ FcitxCandidateWordInsertPlaceHolder(candList, cloudidx);
+ FcitxCandidateWord* placeHolder = FcitxCandidateWordGetByTotalIndex(candList, cloudidx);
+ if (placeHolder && placeHolder->strWord == NULL)
+ placeHolder->strWord = strdup(DUP_PLACE_HOLDER);
+ }
+ } else {
if (i >= pagesize) {
FcitxCandidateWordMove(candList, i - 1, cloudidx);
- }
- else {
- FcitxCandidateWordInsertPlaceHolder(candList, cloudidx);
+ } else {
+ if (CloudGetTimeStamp() - cloudCand->timestamp
+ > LOADING_TIME_QUICK_THRESHOLD) {
+ FcitxCandidateWordInsertPlaceHolder(candList, cloudidx);
+ FcitxCandidateWord* placeHolder = FcitxCandidateWordGetByTotalIndex(candList, cloudidx);
+ if (placeHolder && placeHolder->strWord == NULL)
+ placeHolder->strWord = strdup(DUP_PLACE_HOLDER);
+ }
}
}
}
@@ -655,18 +661,19 @@
candWord = NULL;
break;
}
- i ++;
- if (i >= size)
- break;
}
- if (candWord)
- {
- if (cloudCand->filled == false)
- {
+ if (candWord) {
+ if (cloudCand->filled == false) {
cloudCand->filled = true;
free(candWord->strWord);
candWord->strWord = strdup(cacheEntry->str);
+ if (cloudpinyin->config.iCandidateOrder <= 1 &&
+ (CloudGetTimeStamp() - cloudCand->timestamp
+ <= LOADING_TIME_QUICK_THRESHOLD)) {
+ FcitxCandidateWordMoveByWord(candList, candWord, 0);
+ CloudSetClientPreedit(cloudpinyin, cacheEntry->str);
+ }
FcitxUIUpdateInputWindow(cloudpinyin->owner);
}
}
@@ -680,10 +687,9 @@
FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner);
if (cloudCand->filled)
{
- char* string = GetCurrentString(cloudpinyin);
- char* py = SplitHZAndPY(string);
- if (py)
- {
+ char *py;
+ char *string = GetCurrentString(cloudpinyin, &py);
+ if (py) {
*py = 0;
snprintf(FcitxInputStateGetOutputString(input), MAX_USER_INPUT, "%s%s", string, candWord->strWord);
@@ -702,14 +708,18 @@
{
FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-libpinyin", 0, args);
}
+ else if (strcmp(im->uniqueName, "sogou-pinyin") == 0)
+ {
+ FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-sogoupinyin", 0, args);
+ }
}
}
if (string)
free(string);
return IRV_COMMIT_STRING;
- }
- else
+ } else {
return IRV_DO_NOTHING;
+ }
}
@@ -755,73 +765,58 @@
fclose(fp);
}
-char *GetCurrentString(FcitxCloudPinyin* cloudpinyin)
+char *GetCurrentString(FcitxCloudPinyin* cloudpinyin, char **ascii_part)
{
FcitxIM* im = FcitxInstanceGetCurrentIM(cloudpinyin->owner);
- if (!im)
+ if (!im) {
+ *ascii_part = NULL;
return NULL;
+ }
FcitxInputState* input = FcitxInstanceGetInputState(cloudpinyin->owner);
char* string = FcitxUIMessagesToCString(FcitxInputStateGetPreedit(input));
char p[MAX_USER_INPUT + 1], *pinyin, *lastpos;
- pinyin = SplitHZAndPY(string);
+ pinyin = fcitx_utils_get_ascii_part(string);
lastpos = pinyin;
boolean endflag;
int hzlength = pinyin - string;
size_t plength = hzlength;
strncpy(p, string, hzlength);
p[hzlength] = '\0';
- do
- {
+ do {
endflag = (*pinyin != '\0');
-
- if (*pinyin == ' ' || *pinyin == '\'' || *pinyin == '\0')
- {
+ if (*pinyin == ' ' || *pinyin == '\'' || *pinyin == '\0') {
*pinyin = 0;
- if (*lastpos != '\0')
- {
+ if (*lastpos != '\0') {
char* result = NULL;
FcitxModuleFunctionArg arg;
arg.args[0] = lastpos;
boolean isshuangpin = false;
- if (strcmp(im->uniqueName, "sunpinyin") == 0)
- {
+ if (strcmp(im->uniqueName, "sunpinyin") == 0) {
boolean issp = false;
arg.args[1] = &issp;
result = FcitxModuleInvokeFunctionByName(cloudpinyin->owner, "fcitx-sunpinyin", 0, arg);
isshuangpin = issp;
- }
- else if (strcmp(im->uniqueName, "shuangpin") == 0)
- {
+ } else if (strcmp(im->uniqueName, "shuangpin") == 0) {
isshuangpin = true;
result = InvokeFunction(cloudpinyin->owner, FCITX_PINYIN, SP2QP, arg);
}
- if (isshuangpin)
- {
- if (result)
- {
- if (plength + strlen(result) < MAX_USER_INPUT)
- {
+ if (isshuangpin) {
+ if (result) {
+ if (plength + strlen(result) < MAX_USER_INPUT) {
strcat(p + plength, result);
plength += strlen(result);
free(result);
- }
- else
- {
+ } else {
p[hzlength] = '\0';
break;
}
}
- }
- else
- {
- if (plength + strlen(lastpos) < MAX_USER_INPUT)
- {
+ } else {
+ if (plength + strlen(lastpos) < MAX_USER_INPUT) {
strcat(p + plength, lastpos);
plength += strlen(lastpos);
- }
- else
- {
+ } else {
p[hzlength] = '\0';
break;
}
@@ -835,30 +830,14 @@
} while(endflag);
free(string);
/* no pinyin append, return NULL for off it */
- if (p[hzlength] == '\0')
- return NULL;
- else
- return strdup(p);
-}
-
-char* SplitHZAndPY(char* string)
-{
- if (string == NULL)
+ if (p[hzlength] == '\0') {
+ *ascii_part = NULL;
return NULL;
-
- char* s = string;
- while (*s)
- {
- char* p;
- unsigned int chr;
-
- p = fcitx_utf8_get_char(s, &chr);
- if (p - s == 1)
- break;
- s = p;
+ } else {
+ char *res = strdup(p);
+ *ascii_part = res + hzlength;
+ return res;
}
-
- return s;
}
void SogouParseKey(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
@@ -879,140 +858,6 @@
free(str);
}
-char* SogouParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
-{
- char *start = NULL, *end = NULL;
- if ((start = strchr(queue->str, '"')) != NULL && (end = strstr(queue->str, "%EF%BC%9A")) != NULL)
- {
- start ++;
- if (start < end)
- {
- size_t length = end - start;
- int conv_length;
- char *unescapedstring = curl_easy_unescape(queue->curl, start, length, &conv_length);
- char *realstring = strdup(unescapedstring);
- curl_free(unescapedstring);
- return realstring;
- }
- }
- return NULL;
-}
-
-void QQParseKey(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
-{
- char* str = fcitx_utils_trim(queue->str);
- const char* ime_patch_key = "{\"key\":\"";
- if (strncmp(str, ime_patch_key, strlen(ime_patch_key)) == 0)
- {
- if (sscanf(str,"{\"key\":\"%32s\",\"ret\":\"suc\"}", cloudpinyin->key) > 0)
- {
- cloudpinyin->initialized = true;
- cloudpinyin->key[QQ_KEY_LENGTH] = '\0';
- }
- }
-
- free(str);
-}
-
-char* QQParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
-{
- char *start = NULL, *end = NULL;
- if ((start = strstr(queue->str, "\"rs\":[\"")) != NULL)
- {
- start += strlen( "\"rs\":[\"");
- if ((end = strstr(start, "\"")) != NULL)
- {
- size_t length = end - start;
- char *realstring = fcitx_utils_malloc0(sizeof(char) * (length + 1));
- strncpy(realstring, start, length);
- realstring[length] = '\0';
- return realstring;
- }
- }
- return NULL;
-}
-
-char* GoogleParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
-{
- char *start = NULL, *end = NULL;
- if ((start = strstr(queue->str, "\",[\"")) != NULL)
- {
- start += strlen( "\",[\"");
- if ((end = strstr(start, "\"")) != NULL)
- {
- size_t length = end - start;
- char *realstring = fcitx_utils_malloc0(sizeof(char) * (length + 1));
- strncpy(realstring, start, length);
- realstring[length] = '\0';
- return realstring;
- }
- }
- return NULL;
-}
-
-char* BaiduParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
-{
- char *start = NULL, *end = NULL;
- static iconv_t conv = 0;
- if (conv == 0)
- conv = iconv_open("utf-8", "utf-16be");
-
- if (conv == (iconv_t)(-1))
- return NULL;
- if ((start = strstr(queue->str, "[[[\"")) != NULL)
- {
- start += strlen( "[[[\"");
- if ((end = strstr(start, "\",")) != NULL)
- {
- size_t length = end - start;
- if (length % 6 != 0 || length == 0)
- return NULL;
-
- size_t i = 0, j = 0;
- char* buf = fcitx_utils_malloc0((length / 6 + 1) * 2);
- while (i < length)
- {
- if (start[i] == '\\' && start[i+1] == 'u')
- {
- if (ishex(start[i+2]) && ishex(start[i+3]) && ishex(start[i+4]) && ishex(start[i+5]))
- {
- buf[j++] = (tohex(start[i+2]) << 4) | tohex(start[i+3]);
- buf[j++] = (tohex(start[i+4]) << 4) | tohex(start[i+5]);
- }
- else
- break;
- }
-
- i += 6;
- }
-
- if (i != length)
- {
- free(buf);
- return NULL;
- }
- buf[j++] = 0;
- buf[j++] = 0;
- size_t len = UTF8_MAX_LENGTH * (length / 6) * sizeof(char);
- char* realstring = fcitx_utils_malloc0(UTF8_MAX_LENGTH * (length / 6) * sizeof(char));
- IconvStr p = buf; char *pp = realstring;
- iconv(conv, &p, &j, &pp, &len);
-
- free(buf);
- if (fcitx_utf8_check_string(realstring))
- return realstring;
- else
- {
- free(realstring);
- return NULL;
- }
- }
- }
- return NULL;
-}
-
-
-
void CloudPinyinHookForNewRequest(void* arg)
{
FcitxCloudPinyin* cloudpinyin = (FcitxCloudPinyin*) arg;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/src/cloudpinyin.h new/fcitx-cloudpinyin-0.3.0/src/cloudpinyin.h
--- old/fcitx-cloudpinyin-0.2.3/src/cloudpinyin.h 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/src/cloudpinyin.h 2012-09-12 16:00:12.000000000 +0200
@@ -22,6 +22,7 @@
#define FCITX_CLOUDPINYIN_H
#include
#include
+#include
#include
#define SOGOU_KEY_LENGTH 32
@@ -32,50 +33,42 @@
#define _(x) dgettext("fcitx-cloudpinyin", (x))
-struct _FcitxInstance;
-
-typedef enum _CloudPinyinSource
-{
+typedef enum {
CloudPinyin_Sogou = 0,
CloudPinyin_QQ = 1,
CloudPinyin_Google = 2,
CloudPinyin_Baidu = 3
} CloudPinyinSource;
-typedef enum _CloudPinyinRequestType
-{
+typedef enum {
RequestKey,
RequestPinyin
} CloudPinyinRequestType ;
-typedef struct _CurlFreeListItem
-{
+typedef struct {
boolean used;
CURL* curl;
} CurlFreeListItem;
-typedef struct _CurlQueue
-{
+typedef struct _CurlQueue {
CURL* curl;
struct _CurlQueue* next;
CloudPinyinRequestType type;
int curl_result;
- int http_code;
+ long http_code;
char* str;
char* pinyin;
size_t size;
CloudPinyinSource source;
} CurlQueue;
-typedef struct _CloudPinyinCache
-{
+typedef struct {
char* pinyin;
char* str;
UT_hash_handle hh;
} CloudPinyinCache;
-typedef struct _FcitxCloudPinyinConfig
-{
+typedef struct {
FcitxGenericConfig config;
int iCandidateOrder;
int iMinimumPinyinLength;
@@ -83,9 +76,8 @@
CloudPinyinSource source;
} FcitxCloudPinyinConfig;
-typedef struct _FcitxCloudPinyin
-{
- struct _FcitxInstance* owner;
+typedef struct {
+ FcitxInstance* owner;
FcitxCloudPinyinConfig config;
CurlQueue* pendingQueue;
CurlQueue* finishQueue;
@@ -101,9 +93,9 @@
CloudPinyinCache* cache;
boolean isrequestkey;
struct _FcitxFetchThread* fetch;
-
+
CurlFreeListItem freeList[MAX_HANDLE];
-
+
pthread_t pid;
} FcitxCloudPinyin;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/src/fcitx-cloudpinyin.desc new/fcitx-cloudpinyin-0.3.0/src/fcitx-cloudpinyin.desc
--- old/fcitx-cloudpinyin-0.2.3/src/fcitx-cloudpinyin.desc 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/src/fcitx-cloudpinyin.desc 2012-09-12 16:00:12.000000000 +0200
@@ -1,11 +1,13 @@
[CloudPinyin/CandidateOrder]
Type=Integer
DefaultValue=2
+Min=1
Description=Cloud Pinyin Candidate Word Order
[CloudPinyin/MinimumPinyinLength]
Type=Integer
DefaultValue=2
+Min=1
Description=Minimum Length of Pinyin To Trigger Cloud Pinyin
[CloudPinyin/DontShowSource]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/src/fetch.c new/fcitx-cloudpinyin-0.3.0/src/fetch.c
--- old/fcitx-cloudpinyin-0.2.3/src/fetch.c 2012-07-12 14:52:15.000000000 +0200
+++ new/fcitx-cloudpinyin-0.3.0/src/fetch.c 2012-09-12 16:00:12.000000000 +0200
@@ -19,7 +19,7 @@
***************************************************************************/
#include
-#include
+#include
#include
#include
@@ -66,11 +66,11 @@
if (maxfd > fetch->maxfd)
fetch->maxfd = maxfd;
-
+
struct timeval t, *pt;
t.tv_sec = 1;
t.tv_usec = 0;
-
+
/* if we have something to fetch, but maxfd is -1 then we give select a time out */
if (maxfd < 0 && fetch->queue->next != NULL)
pt = &t;
@@ -79,7 +79,7 @@
select(fetch->maxfd + 1, &fetch->rfds, &fetch->wfds, &fetch->efds, pt);
}
-
+
return NULL;
}
@@ -101,8 +101,7 @@
previous = fetch->queue;
queue = fetch->queue->next;
while (queue != NULL &&
- queue->curl != curl_message->easy_handle)
- {
+ queue->curl != curl_message->easy_handle) {
previous = queue;
queue = queue->next;
}
@@ -110,7 +109,8 @@
curl_multi_remove_handle(fetch->curlm, queue->curl);
previous->next = queue->next;
queue->curl_result = curl_result;
- curl_easy_getinfo(queue->curl, CURLINFO_HTTP_CODE, &queue->http_code);
+ curl_easy_getinfo(queue->curl, CURLINFO_RESPONSE_CODE,
+ &queue->http_code);
FetchFinish(fetch, queue);
}
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/src/parse.c new/fcitx-cloudpinyin-0.3.0/src/parse.c
--- old/fcitx-cloudpinyin-0.2.3/src/parse.c 1970-01-01 01:00:00.000000000 +0100
+++ new/fcitx-cloudpinyin-0.3.0/src/parse.c 2012-09-12 16:00:12.000000000 +0200
@@ -0,0 +1,198 @@
+
+#include "config.h"
+
+#include
+#include
+#include
+#include
+#include
+#include "cloudpinyin.h"
+
+static inline boolean ishex(char ch)
+{
+ if ((ch >= '0' && ch <= '9') || (ch >='a' && ch <='f') || (ch >='A' && ch <='F'))
+ return true;
+ return false;
+}
+
+static inline unsigned char tohex(char ch)
+{
+ if (ch >= '0' && ch <= '9')
+ return ch - '0';
+ if (ch >='a' && ch <='f')
+ return ch - 'a' + 10;
+ if (ch >='A' && ch <='F')
+ return ch - 'A' + 10;
+ return 0;
+}
+
+char* MapSogouStringToHalf(const char* string)
+{
+ const char* s = string;
+ const char* sn;
+ size_t len = strlen(string);
+ char* half = fcitx_utils_malloc0(sizeof(char) * (len + 1));
+ char* halfp = half;
+ int upperCount = 0;
+
+ while (*s) {
+ unsigned int chr = 0;
+
+ sn = fcitx_utf8_get_char(s, &chr);
+
+ /* from A to Z */
+ if ((chr >= 0xff21 && chr <= 0xff3a) || (chr >= 0xff41 && chr <= 0xff5a)) {
+ *halfp = (char) (chr & 0xff) + 0x20;
+ if (isupper(*halfp))
+ upperCount ++;
+ halfp ++;
+ }
+ else {
+ while(s < sn) {
+ *halfp = *s;
+ if (isupper(*halfp))
+ upperCount ++;
+ s++;
+ halfp++;
+ }
+ }
+
+ s = sn;
+ }
+ if (*half && isupper(*half) && upperCount == 1) {
+ *half = tolower(*half);
+ }
+ return half;
+}
+
+char* SogouParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
+{
+ char *start = NULL, *end = NULL;
+ if ((start = strchr(queue->str, '"')) != NULL && (end = strstr(queue->str, "%EF%BC%9A")) != NULL)
+ {
+ start ++;
+ if (start < end)
+ {
+ size_t length = end - start;
+ int conv_length;
+ char *unescapedstring = curl_easy_unescape(queue->curl, start, length, &conv_length);
+ char *realstring = MapSogouStringToHalf(unescapedstring);
+ curl_free(unescapedstring);
+ return realstring;
+ }
+ }
+ return NULL;
+}
+
+void QQParseKey(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
+{
+ char* str = fcitx_utils_trim(queue->str);
+ const char* ime_patch_key = "{\"key\":\"";
+ if (strncmp(str, ime_patch_key, strlen(ime_patch_key)) == 0)
+ {
+ if (sscanf(str,"{\"key\":\"%32s\",\"ret\":\"suc\"}", cloudpinyin->key) > 0)
+ {
+ cloudpinyin->initialized = true;
+ cloudpinyin->key[QQ_KEY_LENGTH] = '\0';
+ }
+ }
+
+ free(str);
+}
+
+char* QQParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
+{
+ char *start = NULL, *end = NULL;
+ if ((start = strstr(queue->str, "\"rs\":[\"")) != NULL)
+ {
+ start += strlen( "\"rs\":[\"");
+ if ((end = strstr(start, "\"")) != NULL)
+ {
+ size_t length = end - start;
+ char *realstring = fcitx_utils_malloc0(sizeof(char) * (length + 1));
+ strncpy(realstring, start, length);
+ realstring[length] = '\0';
+ return realstring;
+ }
+ }
+ return NULL;
+}
+
+char* GoogleParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
+{
+ char *start = NULL, *end = NULL;
+ if ((start = strstr(queue->str, "\",[\"")) != NULL)
+ {
+ start += strlen( "\",[\"");
+ if ((end = strstr(start, "\"")) != NULL)
+ {
+ size_t length = end - start;
+ char *realstring = fcitx_utils_malloc0(sizeof(char) * (length + 1));
+ strncpy(realstring, start, length);
+ realstring[length] = '\0';
+ return realstring;
+ }
+ }
+ return NULL;
+}
+
+char* BaiduParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue)
+{
+ char *start = NULL, *end = NULL;
+ static iconv_t conv = 0;
+ if (conv == 0)
+ conv = iconv_open("utf-8", "utf-16be");
+
+ if (conv == (iconv_t)(-1))
+ return NULL;
+ if ((start = strstr(queue->str, "[[[\"")) != NULL)
+ {
+ start += strlen( "[[[\"");
+ if ((end = strstr(start, "\",")) != NULL)
+ {
+ size_t length = end - start;
+ if (length % 6 != 0 || length == 0)
+ return NULL;
+
+ size_t i = 0, j = 0;
+ char* buf = fcitx_utils_malloc0((length / 6 + 1) * 2);
+ while (i < length)
+ {
+ if (start[i] == '\\' && start[i+1] == 'u')
+ {
+ if (ishex(start[i+2]) && ishex(start[i+3]) && ishex(start[i+4]) && ishex(start[i+5]))
+ {
+ buf[j++] = (tohex(start[i+2]) << 4) | tohex(start[i+3]);
+ buf[j++] = (tohex(start[i+4]) << 4) | tohex(start[i+5]);
+ }
+ else
+ break;
+ }
+
+ i += 6;
+ }
+
+ if (i != length)
+ {
+ free(buf);
+ return NULL;
+ }
+ buf[j++] = 0;
+ buf[j++] = 0;
+ size_t len = UTF8_MAX_LENGTH * (length / 6) * sizeof(char);
+ char* realstring = fcitx_utils_malloc0(UTF8_MAX_LENGTH * (length / 6) * sizeof(char));
+ IconvStr p = buf; char *pp = realstring;
+ iconv(conv, &p, &j, &pp, &len);
+
+ free(buf);
+ if (fcitx_utf8_check_string(realstring))
+ return realstring;
+ else
+ {
+ free(realstring);
+ return NULL;
+ }
+ }
+ }
+ return NULL;
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/src/parse.h new/fcitx-cloudpinyin-0.3.0/src/parse.h
--- old/fcitx-cloudpinyin-0.2.3/src/parse.h 1970-01-01 01:00:00.000000000 +0100
+++ new/fcitx-cloudpinyin-0.3.0/src/parse.h 2012-09-12 16:00:12.000000000 +0200
@@ -0,0 +1,35 @@
+/***************************************************************************
+ * Copyright (C) 2011~2012 by CSSlayer *
+ * wengxt@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 of the License, 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., *
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef CLOUDPINYIN_PARSE_H
+#define CLOUDPINYIN_PARSE_H
+
+#include "cloudpinyin.h"
+
+char* MapSogouStringToHalf(const char* string);
+
+void SogouParseKey(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
+char* SogouParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
+void QQParseKey(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
+char* QQParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
+char* GoogleParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
+char* BaiduParsePinyin(FcitxCloudPinyin* cloudpinyin, CurlQueue* queue);
+
+#endif
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/test/CMakeLists.txt new/fcitx-cloudpinyin-0.3.0/test/CMakeLists.txt
--- old/fcitx-cloudpinyin-0.2.3/test/CMakeLists.txt 1970-01-01 01:00:00.000000000 +0100
+++ new/fcitx-cloudpinyin-0.3.0/test/CMakeLists.txt 2012-09-12 16:00:12.000000000 +0200
@@ -0,0 +1,27 @@
+include_directories(
+ ${PROJECT_SOURCE_DIR}/src
+ ${PROJECT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CURL_INCLUDE_DIRS}
+ ${FCITX4_FCITX_INCLUDE_DIRS}
+ ${FCITX4_FCITX_CONFIG_INCLUDE_DIRS}
+ ${FCITX4_FCITX_UTILS_INCLUDE_DIRS}
+ ${LIBINTL_INCLUDE_DIR}
+ ${PTHREAD_INCLUDE_DIR}
+)
+
+link_directories(
+ ${CURL_LIBRARY_DIRS}
+ ${FCITX4_FCITX_UTILS_LIBRARY_DIRS}
+)
+
+add_executable(testhalf testhalf.c ../src/parse.c)
+
+target_link_libraries( testhalf
+ ${PTHREAD_LIBRARIES}
+ ${FCITX4_FCITX_UTILS_LIBRARIES}
+ ${CURL_LIBRARIES}
+ ${LIBINTL_LIBRARIES}
+ )
+
+add_test(testhalf testhalf)
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/fcitx-cloudpinyin-0.2.3/test/testhalf.c new/fcitx-cloudpinyin-0.3.0/test/testhalf.c
--- old/fcitx-cloudpinyin-0.2.3/test/testhalf.c 1970-01-01 01:00:00.000000000 +0100
+++ new/fcitx-cloudpinyin-0.3.0/test/testhalf.c 2012-09-12 16:00:12.000000000 +0200
@@ -0,0 +1,19 @@
+#include "parse.h"
+
+#include
+
+int main(int argc, char* argv[])
+{
+ char* result = MapSogouStringToHalf("ABCD");
+ printf("%s\n", result);
+ assert(strcmp(result, "ABCD") == 0);
+
+ free(result);
+
+ result = MapSogouStringToHalf("我a测b你CD的");
+ printf("%s\n", result);
+ assert(strcmp(result, "我a测b你CD的") == 0);
+
+ free(result);
+ return 0;
+}
--
To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse-commit+help@opensuse.org