diff --git a/honoka/src/Makefile.am b/honoka/src/Makefile.am index 3a10a71..dd379e0 100644 --- a/honoka/src/Makefile.am +++ b/honoka/src/Makefile.am @@ -27,7 +27,8 @@ -DHONOKA_PLUGINDIR=\"@SCIM_MODULEDIR@/honoka\" noinst_HEADERS = honoka_imengine.h wnnproto.h romkan.h romkan_table.h \ - wnnconversion.h honoka_def.h kanainput.h anthyconversion.h multiconvertor.h + wnnconversion.h honoka_def.h kanainput.h anthyconversion.h multiconvertor.h skkdic.h \ + skkdicconversion.h moduledir = @SCIM_MODULEDIR@/IMEngine module_LTLIBRARIES = honoka.la @@ -83,7 +84,7 @@ endif plugindir = @SCIM_MODULEDIR@/honoka -plugin_LTLIBRARIES = $(ANTHY_PLUGIN) $(WNN_PLUGIN) plugin-romkan.la plugin-kanainput.la +plugin_LTLIBRARIES = $(ANTHY_PLUGIN) $(WNN_PLUGIN) plugin-skkdic.la plugin-romkan.la plugin-kanainput.la plugin_anthy_la_SOURCES = anthyconversion.cpp plugin_anthy_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ @@ -97,6 +98,12 @@ plugin_wnn_la_LDFLAGS = -avoid-version -module -rpath $(plugindir) @LIBTOOL_EXPORT_OPTIONS@ @INTLLIBS@ @SCIM_LIBS@ @WNN_LIBS@ plugin_wnn_la_LIBADD = $(top_builddir)/src/libhonoka_plugin.la +plugin_skkdic_la_SOURCES = skkdic.cpp skkdicconversion.cpp +plugin_skkdic_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ +plugin_skkdic_la_CXXFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ +plugin_skkdic_la_LDFLAGS = -avoid-version -module -rpath $(plugindir) @LIBTOOL_EXPORT_OPTIONS@ @INTLLIBS@ @SCIM_LIBS@ @ANTHY_LIBS@ +plugin_skkdic_la_LIBADD = $(top_builddir)/src/libhonoka_plugin.la + plugin_romkan_la_SOURCES = romkan.cpp plugin_romkan_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ plugin_romkan_la_CXXFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ diff --git a/honoka/src/multiconvertor.cpp b/honoka/src/multiconvertor.cpp index 9a6f1be..2bc6f47 100644 --- a/honoka/src/multiconvertor.cpp +++ b/honoka/src/multiconvertor.cpp @@ -81,12 +81,12 @@ } int MultiConvertor::setPos(int p){ - instance->m_def_convertor->setPos(p); + int cp = instance->m_def_convertor->setPos(p); for(unsigned int i = 0;i < instance->convertors.size();i ++) { if (instance->m_def_convertor != instance->convertors[i]) - instance->convertors[i]->setPos(instance->m_def_convertor->getPos()); + instance->convertors[i]->setPos(cp); } - return instance->m_def_convertor->getPos(); + return cp; } int MultiConvertor::getPos() { diff --git a/honoka/src/skkdic.cpp b/honoka/src/skkdic.cpp new file mode 100644 index 0000000..d43bdb0 --- /dev/null +++ b/honoka/src/skkdic.cpp @@ -0,0 +1,109 @@ +/*************************************************************************** + * Copyright (C) 2005 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "skkdic.h" + +SKKDic::SKKDic(String file) +{ + filename = file; + iconv.set_encoding("EUC-JP"); + init(); +} + + +SKKDic::~SKKDic() +{ +} + + + + +/*! + \fn SKKDic::init() + */ +void SKKDic::init() +{ + bool okuri = true; + FILE *f = fopen(filename.c_str(),"r"); + if (!f) return; + while(-1) { + char s[1024]; + if(fgets(s,1024,f) == NULL) break; + if (String(s) == String(";; okuri-ari entries.")) { + okuri = true; + continue; + } else if (String(s) == String(";; okuri-nasi entries.")) { + okuri = false; + continue; + } + if (String(s).substr(0,2) == ";;") continue; + vector sList; + WideString wstr; + iconv.convert(wstr,String(s)); + uint pos = 0,count = 0; + // "/"��split�� + while(-1) { + if ((pos + count) >= wstr.size()) break; + if (wstr.at(pos + count) == utf8_mbstowcs(String("/"))[0]) { + if (count) sList.push_back(wstr.substr(pos,count)); + pos += count + 1; + count = 0; + continue; + } + count ++; + } + // �ɤߤζ�������� + // @todo okuri-ari + wstr = WideString(); + if (!sList.size()) continue; + for(unsigned int i = 0;i < sList[0].length();i ++) { + if (sList[0][i] != utf8_mbstowcs(String(" "))[0]) { + wstr = wstr + sList[0][i]; + } + } + sList[0] = wstr; + // ���Υơ������/����Ŧ�С� + vector dic; + for(unsigned int i = 1;i < sList.size();i ++) { + SKKDicEntry e; + /*for(unsigned int j = 0;j < sList[i].size();j ++) { + if ((sList[i][j] == utf8_mbstowcs(String(";"))[0]) && ((j + 1) < sList[i].size()) && (j > 0)) { + e.kouho = sList[i].substr(0,j - 1); + e.annotation = sList[i].substr(j + 1); + } + } + if (!e.annotation.length())*/ e.kouho = sList[i]; + dic.push_back(e); + } + dic_data.insert(pair >(sList[0],dic)); + } + fclose(f); +} + + +/*! + \fn SKKDic::find(WideString text) + */ +const vector SKKDic::find(WideString text) +{ + map >::iterator it = dic_data.find(text); + if (it == dic_data.end()) return vector(); + return it->second; +} diff --git a/honoka/src/skkdic.h b/honoka/src/skkdic.h new file mode 100644 index 0000000..6c7a4ef --- /dev/null +++ b/honoka/src/skkdic.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2005 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef SKKDIC_H +#define SKKDIC_H + +#include +#include +#include +#include +#include +#include + +#define Uses_SCIM_UTILITY +#define Uses_SCIM_ICONV + +using namespace std; +using namespace scim; + + +/** +@author TAM (Teppei Tamra) +*/ +class SKKDicEntry { +public: + WideString annotation; + WideString kouho; +}; + +class SKKDic{ +public: + SKKDic(String file); + + ~SKKDic(); + const vector find(WideString text); + +protected: + String filename; + IConvert iconv; + map< WideString,vector > dic_data; +protected: + void init(); +}; + +#endif diff --git a/honoka/src/skkdicconversion.cpp b/honoka/src/skkdicconversion.cpp new file mode 100644 index 0000000..81b5deb --- /dev/null +++ b/honoka/src/skkdicconversion.cpp @@ -0,0 +1,196 @@ +/*************************************************************************** + * Copyright (C) 2005 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "skkdicconversion.h" + +#include + +#ifdef HAVE_CONFIG_H + #include +#endif + +#ifdef HAVE_GETTEXT + #include + #define _(String) dgettext(GETTEXT_PACKAGE,String) + #define N_(String) (String) +#else + #define _(String) (String) + #define N_(String) (String) + #define bindtextdomain(Package,Directory) + #define textdomain(domain) + #define bind_textdomain_codeset(domain,codeset) +#endif + +// �ץ饤�����󲽤Τ��ޤ��ʤ��Ǥ��� +HonokaPluginRegister(SKKDicConversion); + +SKKDicConversion::SKKDicConversion(ConfigPointer cfg) : Convertor(cfg) +{ + String file = cfg->read(String(HONOKA_SKKDIC_CONFIG_DICFILE), + String("")); + dic = new SKKDic(file); + pos = 0; +} + + +SKKDicConversion::~SKKDicConversion() +{ + delete(dic); +} + +bool SKKDicConversion::isConnected() { + return true; +} + +void SKKDicConversion::reset(){ + buns.clear(); + texts.clear(); + pos = 0; + return; +} + +void SKKDicConversion::setYomiText(WideString yomi) { + buns.clear(); + buns.push_back(yomi); + return; +} + +int SKKDicConversion::ren_conversion() { + texts.push_back(buns[0]); + pos = 0; + return 1; +} + +WideString SKKDicConversion::getText() { + WideString t; + for(unsigned int i = 0;i < texts.size();i ++) { + t = t + texts[i]; + } + return t; +} + +int SKKDicConversion::setPos(int p){ + if ((p >= 0) && (p < buns.size())) pos = p; + return pos; +} + +int SKKDicConversion::getPos() { + return pos; +} + +ResultList SKKDicConversion::getResultList(int p,int kt){ + list.Yomi.clear(); + list.kouho.clear(); + list.Title = utf8_mbstowcs(String(_("lookup result"))); + list.count = 0; + ResultEntry e; + if (kt != 0) return list; + if (p == -1) p = pos; + else if (setPos(p) != p) return list; + e.kanji = buns[pos]; + list.Yomi = buns[pos]; + list.kouho.push_back(e); + list.count = 1; + vector es = dic->find(buns[p]); + for(unsigned int i = 0;i < es.size();i ++) { + e.kanji = es[i].kouho; + list.kouho.push_back(e); + } + list.count = list.kouho.size(); + return list; +} + +ResultList SKKDicConversion::getYosokuList(const WideString &str) { + // ͽ¬�ѡ� + // ���δؿ��Ϥ⤦�Ȥ�ʤ��Dz�������ʬΥͽ��Ǥ��� + return ResultList(); +} + +bool SKKDicConversion::select(int p) { + if ((p < list.kouho.size()) && (p >= 0)) { + texts[pos] = list.kouho[p].kanji; + return true; + } + return false; +} + +AttributeList SKKDicConversion::getAttributeList() { + AttributeList attr; + int l = 0; + for(unsigned int i = 0;i < texts.size();i ++) { + if (pos == i) { + Attribute a(l,texts[i].length(),SCIM_ATTR_DECORATE,SCIM_ATTR_DECORATE_REVERSE); + attr.push_back(a); + } + l += texts[i].length(); + } + return attr; +} + +bool SKKDicConversion::resizeRegion(int w) { + if ((buns[pos].length() + w) < 1) return false; + if ((pos >= (buns.size() - 1)) && (w > 0)) return false; + + int s = buns[pos].length(); + WideString t; + vector ws; + for(unsigned int i = pos;i < buns.size();i ++) t = t + buns[i]; + for(unsigned int i = 0;i < pos;i ++) { + ws.push_back(buns[i]); + } + ws.push_back(t.substr(0,s + w)); + if ((s + w) < t.length()) ws.push_back(t.substr(s + w)); + buns.clear(); + texts.clear(); + buns = ws; + texts = ws; + return true; +} + +void SKKDicConversion::updateFrequency() { + return; +} + +bool SKKDicConversion::connect() { + return true; +} +void SKKDicConversion::disconnect() { + return; +} + +int SKKDicConversion::getCaretPos() { + int l = 0; + for(unsigned int i = 0;i < texts.size();i ++) { + if (pos == i) return l; + l += texts[i].length(); + } + return 0; +} + + +String SKKDicConversion::getName() +{ + return String("SKKDic"); +} + +String SKKDicConversion::getPropertyName() +{ + return getName(); +} diff --git a/honoka/src/skkdicconversion.h b/honoka/src/skkdicconversion.h new file mode 100644 index 0000000..4256669 --- /dev/null +++ b/honoka/src/skkdicconversion.h @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2005 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef SKKDICCONVERSION_H +#define SKKDICCONVERSION_H + +#define Uses_SCIM_CONFIG_BASE + +#include +#include +#include +#include +#include +#include +#include +#include + +#define HONOKA_SKKDIC_CONFIG_DICFILE "/IMEngine/Honoka/SKKDic/File" + +using namespace std; +using namespace scim; + +/** +@author TAM (Teppei Tamra) +*/ +class SKKDicConversion : public Convertor { +public: + SKKDicConversion(ConfigPointer cfg); + + ~SKKDicConversion(); + virtual bool isConnected(); + virtual void reset(); + virtual void setYomiText(WideString yomi); + virtual int ren_conversion(); + virtual WideString getText(); + virtual int setPos(int p); + virtual int getPos(); + virtual ResultList getResultList(int p = -1 ,int kt = 0); + virtual ResultList getYosokuList(const WideString &str); + virtual bool select(int p); + virtual AttributeList getAttributeList(); + virtual bool resizeRegion(int w); + virtual void updateFrequency(); + virtual bool connect(); + virtual void disconnect(); + virtual int getCaretPos(); + virtual String getName(); + virtual String getPropertyName(); + +protected: + SKKDic *dic; + vector buns; + vector texts; + ResultList list; + int pos; + +}; + +#endif