Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
・約16KBを超過する行がSKK辞書ファイルにあるとき検索に失敗することがあるバグを修正しました。

・SKK辞書ファイルの読み込み、SKK辞書サーバーとの通信、Google CGI API for Japanese Input での通信における最大サイズの制限を設けないようにしました。
  • Loading branch information
nathancorvussolis committed Aug 2, 2014
1 parent 4d8c8cf commit 7cd8d75
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 204 deletions.
8 changes: 5 additions & 3 deletions README.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

-------------------------------------------------------------------------------

crvskkserv 1.2.0
crvskkserv 2.0.0

-------------------------------------------------------------------------------

Expand All @@ -17,8 +17,8 @@ SKK辞書サーバです。IPv4、IPv6に対応しています。
改行LFでEUC-JIS-2004やUTF-8(BOMなし)等ASCIIと互換性のある文字コードのSKK辞書
ファイルが使用できます。

文字コードの変換は行っていないので、クライアント側のSKK辞書サーバ通信に使用する
文字コードとSKK辞書ファイルの文字コードを揃える必要があります
SKK辞書の文字コード変換は行っていないので、クライアント側のSKK辞書サーバ通信に
使用する文字コードとSKK辞書ファイルの文字コードを揃える必要があります

Google CGI APIの「見出し語の検索除外条件」設定は、おそらく送りあり(と思われる)
見出し語を除外する正規表現がデフォルトとなっています。
Expand All @@ -28,6 +28,8 @@ http://msdn.microsoft.com/en-us/library/bb982727%28v=vs.120%29.aspx
Google CGI APIの設定でクライアントの文字コードをEUC-JIS-2004にしたとき、
UTF-8からEUC-JIS-2004に変換できない文字を含む候補は除外されます。



-------------------------------------------------------------------------------

LICENSE
Expand Down
7 changes: 7 additions & 0 deletions crvskkserv/crvskkserv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ INT_PTR CALLBACK DlgProcGoogleCGIAPI(HWND hDlg, UINT message, WPARAM wParam, LPA
}
GetDlgItemTextW(hDlg, IDC_EDIT_GOOGLECGIAPI_FILTER, filter, _countof(filter));
GetDlgItemTextW(hDlg, IDC_EDIT_GOOGLECGIAPI_ANNOTATION, comment, _countof(comment));
for(index = 0; index < _countof(comment) && comment[index] != L'\0'; index++)
{
if(comment[index] == L'/' || comment[index] == L';')
{
comment[index] = L'\x20';
}
}
GetDlgItemTextW(hDlg, IDC_EDIT_GOOGLECGIAPI_TIMEOUT, timeout, _countof(timeout));
_snwprintf_s(path, _TRUNCATE, L"%s%c%s%c%s%c%s%c%s%c", INIVAL_GOOGLECGIAPI, INIVAL_SVR_SEP,
filter, INIVAL_SVR_SEP, comment, INIVAL_SVR_SEP, timeout, INIVAL_SVR_SEP, encoding, INIVAL_SVR_SEP);
Expand Down
18 changes: 9 additions & 9 deletions crvskkserv/crvskkserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
#pragma once

#define RC_PRODUCT "crvskkserv"
#define RC_VERSION "1.2.0"
#define RC_VERSION_D 1,2,0,0
#define RC_TITLE "crvskkserv (ver. 1.2.0)"
#define RC_VERSION "2.0.0"
#define RC_VERSION_D 2,0,0,0
#define RC_TITLE "crvskkserv (ver. 2.0.0)"
#define RC_AUTHOR "nathancorvussolis"

#define APP_TITLE L"crvskkserv"
#define APP_VERSION L"1.2.0"
#define APP_VERSION L"2.0.0"
#define RES_VER RC_PRODUCT " (" RC_VERSION ") "

#define REQ_END '0'
#define REQ_KEY '1'
#define REQ_VER '2'
#define REQ_ADR '3'
#define REQ_CMP '4'

#define REP_OK '1'
#define REP_NG '4'
Expand All @@ -23,8 +24,7 @@
#define INIVAL_GOOGLECGIAPI L"googlecgiapi"
#define INIVAL_SVR_SEP L'/'

#define KEYSIZE 0x100
#define BUFSIZE 0x4000
#define DICBUFSIZE 0x1000
#define RBUFSIZE 0x800

#define WM_TASKBARICON_0 (WM_USER + 1)
Expand Down Expand Up @@ -71,12 +71,12 @@ void listen_thread(void *p);

// search_dictionary
void init_search_dictionary(DICINFO &dicinfo);
void search_dictionary(DICINFO &dicinfo, LPCSTR key, std::string &s);
void search_dictionary(DICINFO &dicinfo, const std::string &key, std::string &s);

// search_skkserv
void search_skkserv(DICINFO &dicinfo, LPCSTR key, std::string &s);
void search_skkserv(DICINFO &dicinfo, const std::string &key, std::string &s);
void connect_skkserv(DICINFO &dicinfo);
BOOL get_skkserv_version(SOCKET &sock);

// search_google_cgiapi
void search_google_cgiapi(DICINFO &dicinfo, LPCSTR key, std::string &s);
void search_google_cgiapi(DICINFO &dicinfo, const std::string &key, std::string &s);
2 changes: 2 additions & 0 deletions crvskkserv/crvskkserv.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<ClInclude Include="eucjis2004table.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="utf8.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="crvskkserv.cpp" />
Expand All @@ -98,6 +99,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="utf8.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="crvskkserv.rc" />
Expand Down
6 changes: 6 additions & 0 deletions crvskkserv/crvskkserv.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<ClInclude Include="eucjis2004table.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utf8.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand All @@ -56,6 +59,9 @@
<ClCompile Include="eucjis2004table.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="utf8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="crvskkserv.rc">
Expand Down
62 changes: 60 additions & 2 deletions crvskkserv/eucjis2004.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,17 @@ BOOL EucJis2004ToWideChar(LPCSTR src, size_t *srcsize, LPWSTR dst, size_t *dstsi
WCHAR utf16[2][2];
size_t utf16num[2];

if(src == NULL || dstsize == NULL)
if(dstsize == NULL)
{
return FALSE;
}

if(src == NULL)
{
*dstsize = 0;
return FALSE;
}

if(srcsize != NULL)
{
ss = *srcsize;
Expand Down Expand Up @@ -271,8 +277,14 @@ BOOL WideCharToEucJis2004(LPCWSTR src, size_t *srcsize, LPSTR dst, size_t *dstsi
UCSCHAR ucp;
BOOL exist;

if(src == NULL || dstsize == NULL)
if(dstsize == NULL)
{
return FALSE;
}

if(src == NULL)
{
*dstsize = 0;
return FALSE;
}

Expand Down Expand Up @@ -495,3 +507,49 @@ BOOL WideCharToEucJis2004(LPCWSTR src, size_t *srcsize, LPSTR dst, size_t *dstsi
}
return TRUE;
}

std::string wstring_to_eucjis2004_string(const std::wstring &s)
{
std::string ret;
size_t len = -1;

WideCharToEucJis2004(s.c_str(), NULL, NULL, &len);
if(len > 0)
{
try
{
LPSTR euc = new CHAR[len];
WideCharToEucJis2004(s.c_str(), NULL, euc, &len);
ret = euc;
delete[] euc;
}
catch(...)
{
}
}

return ret;
}

std::wstring eucjis2004_string_to_wstring(const std::string &s)
{
std::wstring ret;
size_t len = -1;

EucJis2004ToWideChar(s.c_str(), NULL, NULL, &len);
if(len > 0)
{
try
{
LPWSTR wcs = new WCHAR[len];
EucJis2004ToWideChar(s.c_str(), NULL, wcs, &len);
ret = wcs;
delete[] wcs;
}
catch(...)
{
}
}

return ret;
}
6 changes: 6 additions & 0 deletions crvskkserv/eucjis2004.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ BOOL EucJis2004ToWideChar(LPCSTR src, size_t *srcsize, LPWSTR dst, size_t *dstsi
// NULLのとき戻り値はFALSEになる
BOOL WideCharToEucJis2004(LPCWSTR src, size_t *srcsize, LPSTR dst, size_t *dstsize);

std::string wstring_to_eucjis2004_string(const std::wstring &s);
std::wstring eucjis2004_string_to_wstring(const std::string &s);

#define WCTOEUC(w) wstring_to_eucjis2004_string(w).c_str()
#define EUCTOWC(u) eucjis2004_string_to_wstring(u).c_str()

#endif //EUCJIS2004_H
73 changes: 51 additions & 22 deletions crvskkserv/search_dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

void init_search_dictionary(DICINFO &dicinfo)
{
CHAR buf[BUFSIZE];
CHAR buf[DICBUFSIZE];
LPSTR pb;
std::string sbuf;
FILE *fpdic;
long pos;
int okuri = -1;
MAP map;
MAP::iterator map_itr;
char *p;
size_t pidx;
#if USEIDXFILE
FILE *fpidx;
wchar_t idxpath[MAX_PATH];
Expand All @@ -37,25 +38,41 @@ void init_search_dictionary(DICINFO &dicinfo)
}

pos = ftell(fpdic);
while(fgets(buf, sizeof(buf), fpdic) != NULL)
while(true)
{
if(strcmp(EntriesAri, buf) == 0)
sbuf.clear();

while((pb = fgets(buf, sizeof(buf), fpdic)) != NULL)
{
sbuf.append(buf);

if(!sbuf.empty() && sbuf.back() == '\n')
{
break;
}
}

if(pb == NULL)
{
break;
}

if(sbuf.compare(EntriesAri) == 0)
{
okuri = 1;
}
else if(strcmp(EntriesNasi, buf) == 0)
else if(sbuf.compare(EntriesNasi) == 0)
{
okuri = 0;
}
else if(okuri != -1)
{
p = strchr(buf, '\x20');
if(p != NULL)
if((pidx = sbuf.find_first_of('\x20')) != std::string::npos)
{
*p = '\0';
map.insert(PAIR(buf, pos));
map.insert(PAIR(sbuf.substr(0, pidx), pos));
}
}

pos = ftell(fpdic);
}

Expand All @@ -66,7 +83,7 @@ void init_search_dictionary(DICINFO &dicinfo)
#endif

dicinfo.pos.clear();
for(map_itr = map.begin(); map_itr != map.end(); map_itr++)
for(auto map_itr = map.begin(); map_itr != map.end(); map_itr++)
{
dicinfo.pos.push_back(map_itr->second);

Expand All @@ -86,22 +103,23 @@ void init_search_dictionary(DICINFO &dicinfo)
#endif
}

void search_dictionary(DICINFO &dicinfo, LPCSTR key, std::string &s)
void search_dictionary(DICINFO &dicinfo, const std::string &key, std::string &s)
{
CHAR buf[BUFSIZE];
FILE *fpdic;
CHAR buf[DICBUFSIZE];
std::string sbuf, ckey;
long pos, left, mid, right;
int comp;
char *p;

s.clear();

size_t pidx;

_wfopen_s(&fpdic, dicinfo.path.c_str(), RB);
if(fpdic == NULL)
{
return;
}

ckey = key + "\x20";

left = 0;
right = dicinfo.pos.size() - 1;

Expand All @@ -112,16 +130,27 @@ void search_dictionary(DICINFO &dicinfo, LPCSTR key, std::string &s)

fseek(fpdic, pos, SEEK_SET);
memset(buf, 0, sizeof(buf));
fgets(buf, _countof(buf), fpdic);

sbuf.clear();

while(fgets(buf, _countof(buf), fpdic) != NULL)
{
sbuf += buf;

if(!sbuf.empty() && sbuf.back() == '\n')
{
break;
}
}

comp = strncmp(key, buf, strlen(key));
comp = strncmp(ckey.c_str(), sbuf.c_str(), ckey.size());
if(comp == 0)
{
if((p = strchr(buf, '\x20')) != NULL)
if((pidx = sbuf.find_first_of('\x20')) != std::string::npos)
{
if((p = strchr(p, '/')) != NULL)
if((pidx = sbuf.find_first_of('/', pidx)) != std::string::npos)
{
s = p;
s = sbuf.substr(pidx);
}
}
break;
Expand Down
Loading

0 comments on commit 7cd8d75

Please sign in to comment.