[aquaskk-changes 229] CVS update: AquaSKK

Back to archive index

Tomotaka SUWA t-suw****@users*****
2006年 6月 10日 (土) 10:51:02 JST


Index: AquaSKK/ChangeLog
diff -u AquaSKK/ChangeLog:1.27 AquaSKK/ChangeLog:1.28
--- AquaSKK/ChangeLog:1.27	Mon Jun  5 21:27:01 2006
+++ AquaSKK/ChangeLog	Sat Jun 10 10:51:01 2006
@@ -1,3 +1,12 @@
+2006-06-10  Tomotaka SUWA  <t.suw****@mac*****>
+
+	* SKKDictionary.*: SKKDictionary ƒNƒ‰ƒX‚Í 10 •ªŠÔŠu‚Ńtƒ@ƒCƒ‹‚̍XV
+	“ú•t‚ðƒ`ƒFƒbƒN‚µAÅV‚Ì“à—e‚𔽉f‚·‚é‚悤‚ɏC³B‚Ü‚½AURL ‚̐[“x
+	‚ÉŠÖ‚í‚炸AŽ«‘‚̓‰ƒCƒuƒ‰ƒŠ’¼‰º‚Ƀ_ƒEƒ“ƒ[ƒh‚·‚é‚悤‚ɏC³B
+
+	* NumericConverter.cpp (NumericConverter::Apply): #[0-59] ‚̃vƒŒ[
+	ƒXƒzƒ‹ƒ_‚ªŒ©‚‚©‚ç‚È‚¢‚Æ–³ŒÀƒ‹[ƒv‚·‚é•s‹ï‡‚ðC³B
+
 2006-06-05  Tomotaka SUWA  <t.suw****@mac*****>
 
 	* SKKDictionary.cpp: •âŠ®Žž‚Ɉê‰ñu‹óU‚èv‚·‚錻Û‚ðC³B
Index: AquaSKK/NumericConverter.cpp
diff -u AquaSKK/NumericConverter.cpp:1.1 AquaSKK/NumericConverter.cpp:1.2
--- AquaSKK/NumericConverter.cpp:1.1	Sat Jun  3 10:23:18 2006
+++ AquaSKK/NumericConverter.cpp	Sat Jun 10 10:51:01 2006
@@ -1,5 +1,5 @@
 /*
-  $Id: NumericConverter.cpp,v 1.1 2006/06/03 01:23:18 t-suwa Exp $
+  $Id: NumericConverter.cpp,v 1.2 2006/06/10 01:51:01 t-suwa Exp $
 
   MacOS X implementation of the SKK input method.
 
@@ -268,8 +268,8 @@
     int index = 0;
 
     do {
-	pos = src.find_first_of(numbers, pos);
-	if(0 < pos && src[pos - 1] == '#') {
+	pos = src.find_first_of(numbers, pos + 1);
+	if(src[pos - 1] == '#') {
 	    switch(src[pos]) {
 	    case '0':		// 無変換
 		src.replace(pos - 1, 2, params_[index]);
@@ -293,7 +293,7 @@
 		src.replace(pos - 1, 2, ConvertType9(params_[index]));
 		break;
 	    }
-	    pos += params_[index].size();
+	    pos = pos - 1 + params_[index].size();
 	    ++ index;
 	}
     } while(pos != std::string::npos);
Index: AquaSKK/SKKDictionary.cpp
diff -u AquaSKK/SKKDictionary.cpp:1.9 AquaSKK/SKKDictionary.cpp:1.10
--- AquaSKK/SKKDictionary.cpp:1.9	Mon Jun  5 21:27:01 2006
+++ AquaSKK/SKKDictionary.cpp	Sat Jun 10 10:51:01 2006
@@ -1,5 +1,5 @@
 /*
-  $Id: SKKDictionary.cpp,v 1.9 2006/06/05 12:27:01 t-suwa Exp $
+  $Id: SKKDictionary.cpp,v 1.10 2006/06/10 01:51:01 t-suwa Exp $
 
   MacOS X implementation of the SKK input method.
 
@@ -37,7 +37,9 @@
 #include "SKKConfig.h"
 #include "socketstream.h"
 
-#pragma mark --- SKK common functions ---
+// ======================================================================
+// ‹¤’ʊ֐”
+// ======================================================================
 
 // SKKDictionary ‚Æ SKKUserDictionary ‚É‹¤’Ê‚·‚é’萔‚â‘€ì
 namespace skkdic {
@@ -45,6 +47,9 @@
     const std::string OkuriNasiMark = ";; okuri-nasi entries.";
     const int SAVE_LIMIT_COUNT = 50;
     const int SAVE_TIMEOUT = 10 * 60; // 10 •ª
+    const std::string RemoteHOST = "openlab.ring.gr.jp";
+    const std::string RemoteURL = "/skk/skk/dic/";
+    const int DOWNLOAD_INTERVAL = 60 * 60 * 6; // 6 ŽžŠÔ
 
     // Ž«‘ƒtƒ@ƒCƒ‹‚ðŠJ‚¢‚āAokuri-ari ‚̐擪‚܂ŃV[ƒN‚·‚é
     bool OpenAndSeek(const std::string& path, std::ifstream& dic) {
@@ -133,7 +138,9 @@
     };
 };
 
-#pragma mark --- SKKDictionary ---
+// ======================================================================
+// SKKDictionary ƒCƒ“ƒ^ƒtƒF[ƒX
+// ======================================================================
 
 SKKDictionary::SKKDictionary() {
     // empty
@@ -143,52 +150,37 @@
     // empty
 }
 
-void SKKDictionary::initializeContainer(EntryContainer& okuriAri, EntryContainer& okuriNasi) {
-    std::string line;
-    std::string index;
-    std::ifstream dic;
-
-    if(!skkdic::OpenAndSeek(path_, dic)) {
-	return;
-    }
-
-    while(skkdic::GetEntry(dic, index, line)) {
-	if(skkdic::OkuriNasiMark.find(line) != std::string::npos) break;
-
-	// ‘—‚è‚È‚µƒGƒ“ƒgƒŠ‚͍~‡‚Ń\[ƒg‚³‚ê‚Ä‚¢‚é‚Í‚¸
-	okuriAri.push_front(SKKPair(index, line));
-    }
-
-    while(skkdic::GetEntry(dic, index, line)) {
-	// ‘—‚è‚ ‚èƒGƒ“ƒgƒŠ‚͏¸‡‚Ń\[ƒg‚³‚ê‚Ä‚¢‚é‚Í‚¸
-	okuriNasi.push_back(SKKPair(index, line));
-    }
-}
-
 void SKKDictionary::load(const std::string& path) {
     path_ = path;
 
     // Ž«‘‚ðƒ[ƒh
-    initializeContainer(okuriAri_, okuriNasi_);
-
-    // ƒGƒ“ƒgƒŠ‚ðƒ\[ƒg‚·‚é
-    std::sort(okuriAri_.begin(), okuriAri_.end(), skkdic::EntryCompare());
-    std::sort(okuriNasi_.begin(), okuriNasi_.end(), skkdic::EntryCompare());
+    reloadContainer();
 
     std::cerr << "SKK Dictionary(" << path_ << ")" << std::endl
 	      << "  okuri-ari: " << countOkuriAri() << " entries." << std::endl
 	      << "  okuri-nasi: " << countOkuriNasi() << " entries." << std::endl << std::endl;
+
+    // ƒŠƒtƒŒƒbƒVƒ…—p‚̃XƒŒƒbƒh‚𑖂点‚é
+    pthread_t pth = 0;
+    if(pthread_create(&pth, NULL, SKKDictionary::refresh, this) == 0) {
+	pthread_detach(pth);
+    } else {
+	std::cerr << "pthread_create() failed: " << errno << std::endl;
+    }
 }
 
 int SKKDictionary::countOkuriAri() {
+    Guard g(mutex_);
     return okuriAri_.size();
 }
 
 int SKKDictionary::countOkuriNasi() {
+    Guard g(mutex_);
     return okuriNasi_.size();
 }
 
 std::vector<OkuriganaEntry> SKKDictionary::findOkuriAri(const CppCFString& query) {
+    Guard g(mutex_);
     std::string index = query.toStdString();
 
     // Œ©•t‚©‚ç‚È‚¢H
@@ -202,6 +194,7 @@
 }
 
 std::vector<CppCFString> SKKDictionary::findOkuriNasi(const CppCFString& query) {
+    Guard g(mutex_);
     std::string index = query.toStdString();
 
     // Œ©‚‚©‚ç‚È‚¢H
@@ -214,9 +207,69 @@
     return SKKEntryConverter::OkuriNasi(SKKEntry::ParseOkuriNasi(i->first, i->second));
 }
 
-#pragma mark --- SKKAutoUpdateDictionary ---
+// ----------------------------------------------------------------------
+
+bool SKKDictionary::reloadContainer() {
+    std::string line;
+    std::string index;
+    std::ifstream dic;
+    struct stat st;
+    static std::time_t lastupdate = 0;
+
+    EntryContainer tmpOkuriAri;
+    EntryContainer tmpOkuriNasi;
+
+    if(!skkdic::OpenAndSeek(path_, dic)) {
+	return false;
+    }
+
+    // Ž«‘ƒtƒ@ƒCƒ‹‚ªXV‚³‚ê‚Ä‚¢‚È‚¯‚ê‚΁A‰½‚à‚µ‚È‚¢
+    if(stat(path_.c_str(), &st) < 0 || lastupdate == st.st_mtime) {
+	return false;
+    }
+    lastupdate = st.st_mtime;
+
+    while(skkdic::GetEntry(dic, index, line)) {
+	if(skkdic::OkuriNasiMark.find(line) != std::string::npos) break;
+
+	// ‘—‚è‚È‚µƒGƒ“ƒgƒŠ‚͍~‡‚Ń\[ƒg‚³‚ê‚Ä‚¢‚é‚Í‚¸
+	tmpOkuriAri.push_front(SKKPair(index, line));
+    }
+
+    while(skkdic::GetEntry(dic, index, line)) {
+	// ‘—‚è‚ ‚èƒGƒ“ƒgƒŠ‚͏¸‡‚Ń\[ƒg‚³‚ê‚Ä‚¢‚é‚Í‚¸
+	tmpOkuriNasi.push_back(SKKPair(index, line));
+    }
+
+    // ƒGƒ“ƒgƒŠ‚ðƒ\[ƒg‚·‚é
+    std::sort(tmpOkuriAri.begin(), tmpOkuriAri.end(), skkdic::EntryCompare());
+    std::sort(tmpOkuriNasi.begin(), tmpOkuriNasi.end(), skkdic::EntryCompare());
+
+    // ’u‚«Š·‚¦
+    Guard g(mutex_);
+    tmpOkuriAri.swap(okuriAri_);
+    tmpOkuriNasi.swap(okuriNasi_);
+
+    return true;
+}
+
+void* SKKDictionary::refresh(void* param) {
+    SKKDictionary* obj = reinterpret_cast<SKKDictionary*>(param);
+
+    while(true) {
+	sleep(skkdic::SAVE_TIMEOUT);
 
-SKKAutoUpdateDictionary::SKKAutoUpdateDictionary() : host_("openlab.ring.gr.jp"), url_("/skk/skk/dic/") {
+	if(obj->reloadContainer()) {
+	    std::cerr << "SKKDictionary: " << obj->path_ << " has been updated";
+	}
+    }
+}
+
+// ======================================================================
+// SKKAutoUpdateDictionary ƒCƒ“ƒ^ƒtƒF[ƒX
+// ======================================================================
+
+SKKAutoUpdateDictionary::SKKAutoUpdateDictionary() : host_(skkdic::RemoteHOST), url_(skkdic::RemoteURL) {
     // empty
 }
 
@@ -226,8 +279,17 @@
 
 void SKKAutoUpdateDictionary::load(const std::string& path) {
     url_ += path;
-    path_  = SKKConfig::LibraryDirectory() + path;
-    initializeContainer(okuriAri_, okuriNasi_);
+
+    // Ž«‘‚̃_ƒEƒ“ƒ[ƒhæ‚̓‰ƒCƒuƒ‰ƒŠ’¼‰º(URL ‚̐[‚³‚Ɉˑ¶‚µ‚È‚¢)
+    std::string::size_type pos = path.find_last_of('/');
+    if(pos != std::string::npos) {
+	path_  = SKKConfig::LibraryDirectory() + path.substr(pos + 1);
+    } else {
+	path_  = SKKConfig::LibraryDirectory() + path;
+    }
+
+    // Ž«‘‚ðƒ[ƒh
+    reloadContainer();
 
     std::cerr << "SKK AutoUpdate Dictionary(" << path_ << ")" << std::endl
 	      << "  okuri-ari: " << countOkuriAri() << " entries." << std::endl
@@ -242,31 +304,12 @@
     }
 }
 
-int SKKAutoUpdateDictionary::countOkuriAri() {
-    Guard g(mutex_);
-    return SKKDictionary::countOkuriAri();
-}
-
-int SKKAutoUpdateDictionary::countOkuriNasi() {
-    Guard g(mutex_);
-    return SKKDictionary::countOkuriNasi();
-}
-
-std::vector<OkuriganaEntry> SKKAutoUpdateDictionary::findOkuriAri(const CppCFString& query) {
-    Guard g(mutex_);
-    return SKKDictionary::findOkuriAri(query);
-}
-
-std::vector<CppCFString> SKKAutoUpdateDictionary::findOkuriNasi(const CppCFString& query) {
-    Guard g(mutex_);
-    return SKKDictionary::findOkuriNasi(query);
-}
+// ----------------------------------------------------------------------
 
 void* SKKAutoUpdateDictionary::download(void* param) {
-    SKKAutoUpdateDictionary* obj = static_cast<SKKAutoUpdateDictionary*>(param);
+    SKKAutoUpdateDictionary* obj = reinterpret_cast<SKKAutoUpdateDictionary*>(param);
 
     while(true) {
-	std::cerr << "SKKAutoUpdateDictionary: checking " << obj->host_ << obj->url_ << " ..." << std::endl;
 	socket_stream session(obj->host_.c_str(), 80);
 	if(session) {
 	    // Ž«‘‚̍XV“ú•t‚ðŽæ“¾
@@ -295,8 +338,8 @@
 		if(response == "\r") break;
 	    }
 
+	    // •ÏX‚³‚ê‚Ä‚¢‚ê‚΁Aƒ_ƒEƒ“ƒ[ƒh‚µ‚ăŠƒ[ƒh‚·‚é
 	    if(modified) {
-		// •Û‘¶
 		std::ofstream ofs(obj->path_.c_str());
 		while(true) {
 		    getline(session, response);
@@ -305,16 +348,7 @@
 		}
 		ofs.close();
 
-		// ƒŠƒ[ƒh
-		EntryContainer tmpOkuriAri;
-		EntryContainer tmpOkuriNasi;
-		obj->initializeContainer(tmpOkuriAri, tmpOkuriNasi);
-
-		// ’u‚«Š·‚¦
-		Guard g(obj->mutex_);
-		tmpOkuriAri.swap(obj->okuriAri_);
-		tmpOkuriNasi.swap(obj->okuriNasi_);
-
+		obj->reloadContainer();
 		std::cerr << "SKKAutoUpdateDictionary: " << obj->path_ << " has been updated" << std::endl;
 	    }
 	} else {
@@ -322,13 +356,15 @@
 	}
 
 	// 10 •ªŠÔŠu‚ŁA6 ŽžŠÔŒo‰ß‚·‚é‚Ì‚ðƒ`ƒFƒbƒN‚·‚é
-	for(time_t nextTime = time(0) + (60 * 60 * 6); time(0) < nextTime; sleep(60 * 10)) {
+	for(time_t nextTime = time(0) + skkdic::DOWNLOAD_INTERVAL; time(0) < nextTime; sleep(skkdic::SAVE_TIMEOUT)) {
 	    // ‚±‚¤‚µ‚È‚¢‚ƁAOS ‚ªƒXƒŠ[ƒvƒ‚[ƒh‚©‚ç•œ‹A‚µ‚½Žž‚É‹~‚¦‚È‚¢
 	}
     }
 }
 
-#pragma mark --- SKKUserDictionary ---
+// ======================================================================
+// SKKUserDictionary ƒCƒ“ƒ^ƒtƒF[ƒX
+// ======================================================================
 
 SKKUserDictionary::SKKUserDictionary() {
     // empty
@@ -492,7 +528,7 @@
     save();
 }
 
-// ------------------------------------------------------------------
+// ----------------------------------------------------------------------
 
 void SKKUserDictionary::save(bool force) {
     static int updateCount = 0;
Index: AquaSKK/SKKDictionary.h
diff -u AquaSKK/SKKDictionary.h:1.6 AquaSKK/SKKDictionary.h:1.7
--- AquaSKK/SKKDictionary.h:1.6	Wed Apr 26 22:36:12 2006
+++ AquaSKK/SKKDictionary.h	Sat Jun 10 10:51:01 2006
@@ -1,5 +1,5 @@
 /*
-  $Id: SKKDictionary.h,v 1.6 2006/04/26 13:36:12 t-suwa Exp $
+  $Id: SKKDictionary.h,v 1.7 2006/06/10 01:51:01 t-suwa Exp $
 
   MacOS X implementation of the SKK input method.
 
@@ -21,7 +21,8 @@
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-#pragma once
+#ifndef INC__SKKDictionary__
+#define INC__SKKDictionary__
 
 #include <deque>
 #include "Dictionary.h"
@@ -39,12 +40,15 @@
 
 // SKK ‹¤—LŽ«‘
 class SKKDictionary: public Dictionary {
+    static void* refresh(void* param);
+
 protected:
     std::string path_;
     EntryContainer okuriAri_;
     EntryContainer okuriNasi_;
+    Mutex mutex_;
 
-    void initializeContainer(EntryContainer& okuriAri, EntryContainer& okuriNasi);
+    bool reloadContainer();
 
 public:
     SKKDictionary();
@@ -63,7 +67,6 @@
 class SKKAutoUpdateDictionary: public SKKDictionary {
     std::string host_;
     std::string url_;
-    Mutex mutex_;
 
     static void* download(void* param);
 
@@ -72,12 +75,6 @@
     virtual ~SKKAutoUpdateDictionary();
 
     virtual void load(const std::string& path);
-
-    virtual int countOkuriAri();
-    virtual int countOkuriNasi();
-
-    virtual std::vector<OkuriganaEntry> findOkuriAri(const CppCFString& query);
-    virtual std::vector<CppCFString> findOkuriNasi(const CppCFString& query);
 };
 
 // SKK ƒ†[ƒU[Ž«‘
@@ -108,3 +105,5 @@
     virtual void removeOkuriAri(const CppCFString& index, const CppCFString& kanji);
     virtual void removeOkuriNasi(const CppCFString& index, const CppCFString& kanji);
 };
+
+#endif	// INC__SKKDictionary__


aquaskk-changes メーリングリストの案内
Back to archive index