[aquaskk-changes 84] CVS update: AquaSKK

Tomotaka SUWA t-suw****@users*****
2005年 10月 13日 (木) 23:22:35 JST


Index: AquaSKK/ChangeLog
diff -u AquaSKK/ChangeLog:1.8 AquaSKK/ChangeLog:1.9
--- AquaSKK/ChangeLog:1.8	Sat Oct  8 17:10:48 2005
+++ AquaSKK/ChangeLog	Thu Oct 13 23:22:35 2005
@@ -1,3 +1,8 @@
+2005-10-13  Tomotaka SUWA  <t.suw****@mac*****>
+
+	* SKKDictionary.*: SKK Ž«‘‚̃pƒX‚ɃfƒBƒŒƒNƒgƒŠ‚ðŽw’肳‚ꂽê‡Aƒn
+	ƒ“ƒO‚µ‚Ä‚µ‚Ü‚¤•s‹ï‡‚ðC³(#7238)B
+
 2005-10-08  Tomotaka SUWA  <t.suw****@mac*****>
 
 	* PreferencesController.h: ƒƒ\ƒbƒh‚̐錾‚ð’ljÁB
Index: AquaSKK/SKKDictionary.cpp
diff -u AquaSKK/SKKDictionary.cpp:1.2 AquaSKK/SKKDictionary.cpp:1.3
--- AquaSKK/SKKDictionary.cpp:1.2	Sat Oct  8 00:08:36 2005
+++ AquaSKK/SKKDictionary.cpp	Thu Oct 13 23:22:35 2005
@@ -1,5 +1,5 @@
 /*
-	$Id: SKKDictionary.cpp,v 1.2 2005/10/07 15:08:36 t-suwa Exp $
+	$Id: SKKDictionary.cpp,v 1.3 2005/10/13 14:22:35 t-suwa Exp $
 	---------
 	
     MacOS X implementation of the SKK input method.
@@ -25,89 +25,95 @@
 #include <vector>
 #include <iostream>
 #include <fstream>
+#include <cerrno>
+#include <cstring>
 #include <unistd.h>
 #include <pthread.h>
+#include <sys/stat.h>
 #include "CppCFString.h"
 #include "OkuriganaEntry.h"
 #include "Dictionary.h"
 #include "SKKDictionary.h"
 
-static void parserThreadRoutine(SKKDictionary* dic); // ”ñƒƒ“ƒo
+static void* parserThreadRoutine(void* dic); // ”ñƒƒ“ƒo
 
-SKKDictionary::SKKDictionary(const string& fpath,bool read_only)
-	: read_only(read_only),
-	 fpath(fpath)
-{
-	ifstream ifs(fpath.c_str(),ios::in);
-	
-	if (!ifs.fail())
-	{
-		load(ifs);
-		ifs.close();
-		
-		// ƒp[ƒTƒXƒŒƒbƒh‚ð‹N“®‚·‚é
-		pthread_t parser;
-		pthread_create(&parser,NULL,(void*(*)(void*))parserThreadRoutine,this);
-		pthread_detach(parser);
-	}
-}
-
-SKKDictionary::~SKKDictionary()
-{
-	
-}
-
-void SKKDictionary::changeDictionaryFile(const string& fpath)
-{
-	okuri_ari_table.clear();
-	okuri_nasi_table.clear();
-	okuri_ari_unparsed.clear();
-	okuri_nasi_unparsed.clear();
-	
-	ifstream ifs(fpath.c_str(),ios::in);
-	if (!ifs.fail())
-	{
-		load(ifs);
-		ifs.close();
-	}
-	parseAll();
-}
-
-void SKKDictionary::load(istream& is)
-{	
-	string str_line;
-	while (!is.eof())
-	{
-		getline(is,str_line,'\n');
-		if (str_line == ";; okuri-ari entries.") break;
-	}
-	while (!is.eof())
-	{
-		getline(is,str_line,'\n');
-		if (str_line.length() == 0) continue;
-		if (str_line == ";; okuri-nasi entries.") break;
-		if (str_line[0] == ';') continue;
-		// ‘—‚è—L‚èƒGƒ“ƒgƒŠ
-		//CppCFString line(str_line.c_str(),kCFStringEncodingEUC_JP); // EUC-JP
-		
-		okuri_ari_unparsed.push_back(str_line);
-	}
-	while (!is.eof())
-	{
-		getline(is,str_line,'\n');
-		if (str_line.length() == 0) continue;
-		if (str_line[0] == ';') continue;
-		// ‘—‚è–³‚µƒGƒ“ƒgƒŠ
-		
-		okuri_nasi_unparsed.push_back(str_line);
-	}
+SKKDictionary::SKKDictionary(const string& fpath, bool read_only)
+	: read_only_(read_only), fpath_(fpath) {
+    load();
+}
+
+SKKDictionary::~SKKDictionary() {
+    // empty
+}
+
+void SKKDictionary::changeDictionaryFile(const string& fpath) {
+    std::map<CppCFString,std::vector<OkuriganaEntry>*>().swap(okuri_ari_table);
+    std::map<CppCFString,std::vector<CppCFString>*>().swap(okuri_nasi_table);
+    std::vector<std::string>().swap(okuri_ari_unparsed);
+    std::vector<std::string>().swap(okuri_nasi_unparsed);
+
+    fpath_ = fpath;
+	
+    load();
+}
+
+void SKKDictionary::load() {
+    struct stat st;
+
+    if(stat(fpath_.c_str(), &st) < 0) {
+	std::cerr << "AquaSKK: stat(" << fpath_ << ") failed: "
+		  << std::strerror(errno) << std::endl;
+	return;
+    }
+
+    // ’ʏí‚̃tƒ@ƒCƒ‹‚Å‚Í‚È‚¢H
+    if(!S_ISREG(st.st_mode)) {
+	std::cerr << "AquaSKK: [" << fpath_ << "] is NOT regular file."
+		  << std::endl;
+	return;
+    }
+
+    std::ifstream dic(fpath_.c_str());
+    if(!dic) {
+	return;
+    }
+
+    std::string str_line;
+    while(!dic.eof()) {
+	std::getline(dic, str_line);
+	if(str_line == ";; okuri-ari entries.") break;
+    }
+
+    // ‘—‚è‚ ‚èƒGƒ“ƒgƒŠ
+    while(!dic.eof()) {
+	std::getline(dic, str_line);
+	if(str_line.length() == 0) continue;
+	if(str_line == ";; okuri-nasi entries.") break;
+	if(str_line[0] == ';') continue;
+		
+	okuri_ari_unparsed.push_back(str_line);
+    }
+
+    // ‘—‚è‚È‚µƒGƒ“ƒgƒŠ
+    while(!dic.eof()) {
+	std::getline(dic, str_line);
+	if(str_line.length() == 0) continue;
+	if(str_line[0] == ';') continue;
+		
+	okuri_nasi_unparsed.push_back(str_line);
+    }
+
+    // ƒp[ƒTƒXƒŒƒbƒh‚ð‹N“®‚·‚é
+    pthread_t parser;
+    pthread_create(&parser, NULL, parserThreadRoutine, this);
+    pthread_detach(parser);
 }
 
 void SKKDictionary::save(bool& terminate_flag)
 {
-	if (read_only) return;
+	if (read_only_) return;
 	
-	string dic_tmp_file = fpath + ".tmp";
+	string dic_tmp_file = fpath_ + ".tmp";
 	ofstream ofs(dic_tmp_file.c_str(),ios::out);
 	
 	try {
@@ -121,7 +127,7 @@
 	
 	ofs.flush();
 	ofs.close();
-	rename(dic_tmp_file.c_str(),fpath.c_str());
+	rename(dic_tmp_file.c_str(),fpath_.c_str());
 }
 
 void SKKDictionary::save(ostream& ofs,bool& terminate_flag)
@@ -277,7 +283,7 @@
 
 const string& SKKDictionary::getFilePath() const
 {
-	return fpath;
+	return fpath_;
 }
 
 void SKKDictionary::parseAll()
@@ -328,7 +334,7 @@
 		okuri_nasi_unparsed.erase(ite);
 	}
 	
-	cout << fpath << endl;
+	cout << fpath_ << endl;
 	cout << "  okuri-ari: " << okuri_ari_table.size() << " entries." << endl;
 	cout << "  okuri-nasi: " << okuri_nasi_table.size() << " entries." << endl;
 	cout << endl;
@@ -515,7 +521,7 @@
 	entries = candidates_str.split('/');
 }
 
-static void parserThreadRoutine(SKKDictionary* dic)
-{
-	dic->parseAll();
+static void* parserThreadRoutine(void* dic) {
+    static_cast<SKKDictionary*>(dic)->parseAll();
+    return NULL;
 }
Index: AquaSKK/SKKDictionary.h
diff -u AquaSKK/SKKDictionary.h:1.2 AquaSKK/SKKDictionary.h:1.3
--- AquaSKK/SKKDictionary.h:1.2	Sat Oct  8 00:08:36 2005
+++ AquaSKK/SKKDictionary.h	Thu Oct 13 23:22:35 2005
@@ -1,5 +1,5 @@
 /*
-	$Id: SKKDictionary.h,v 1.2 2005/10/07 15:08:36 t-suwa Exp $
+	$Id: SKKDictionary.h,v 1.3 2005/10/13 14:22:35 t-suwa Exp $
 	---------
 	
     MacOS X implementation of the SKK input method.
@@ -26,8 +26,8 @@
 class SKKDictionary : public Dictionary
 {
 	protected:
-		bool read_only;
-		const string fpath;
+		bool read_only_;
+		std::string fpath_;
 		map<CppCFString,vector<OkuriganaEntry>*> okuri_ari_table;
 		map<CppCFString,vector<CppCFString>*> okuri_nasi_table;
 		//hash_map<CppCFString,vector<OkuriganaEntry>*,hash_CppCFString,equal_to<CppCFString> > okuri_ari_table;
@@ -35,7 +35,7 @@
 		vector<string> okuri_ari_unparsed; // ƒp[ƒX‘O‚Í•¶ŽšƒR[ƒh‚·‚ç”FŽ¯‚µ‚Ä‚¢‚È‚¢B
 		vector<string> okuri_nasi_unparsed;
 		
-		virtual void load(istream& is);
+		virtual void load();
 		virtual void save(ostream& ofs,bool& terminate_flag);
 		
 	public:


aquaskk-changes メーリングリストの案内