| 4 |
#include <wx/regex.h> |
#include <wx/regex.h> |
| 5 |
#include <iconv.h> |
#include <iconv.h> |
| 6 |
|
|
| 7 |
/* プロトタイプ */ |
static void toLower(char* string); |
| 8 |
static char* decode(const char* string); |
static char* decode(const char* string); |
| 9 |
static char* encode(const char* string); |
static char* encode(const char* string); |
| 10 |
static int compWikiData(const void* wiki1, const void* wiki2); |
static int compWikiData(const void* wiki1, const void* wiki2); |
| 11 |
|
|
| 12 |
|
|
| 13 |
/******* WikiList ************************/ |
/******* WikiList ************************/ |
| 40 |
WikiData* wikiData; |
WikiData* wikiData; |
| 41 |
WikiList* list = new WikiList(); |
WikiList* list = new WikiList(); |
| 42 |
wxString* fileName = new wxString(); |
wxString* fileName = new wxString(); |
| 43 |
|
wxRegEx* regStr; |
| 44 |
|
iconv_t codeSet; |
| 45 |
|
char outbuf[MAX_BUF_SIZE]; |
| 46 |
|
const char* inbufPtr = searchStr; |
| 47 |
|
char* outbufPtr = outbuf; |
| 48 |
|
int inbufSize = strlen(searchStr); |
| 49 |
|
int outbufSize = sizeof(outbuf); |
| 50 |
const char* decodeFileName; |
const char* decodeFileName; |
| 51 |
wxCSConv eucConv(wxT(CODE_SET_EUC_JP)); |
char decodeFileNameBuf[MAX_BUF_SIZE]; |
|
wxCSConv sysConv(wxT(CODE_SET_SYSTEM)); |
|
| 52 |
|
|
| 53 |
|
memset(outbuf, 0, outbufSize); |
| 54 |
|
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
| 55 |
|
if(codeSet == (iconv_t)-1) { |
| 56 |
|
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 57 |
|
} |
| 58 |
|
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 59 |
|
iconv_close(codeSet); |
| 60 |
|
|
| 61 |
dir = new wxDir(*wikiDataDir); |
dir = new wxDir(*wikiDataDir); |
| 62 |
if ( !dir->IsOpened() ) |
if ( !dir->IsOpened() ) |
| 76 |
fread(buf, MAX_BUF_SIZE-1, 1, fp); |
fread(buf, MAX_BUF_SIZE-1, 1, fp); |
| 77 |
if(buf[0] == 0) break; |
if(buf[0] == 0) break; |
| 78 |
decodeFileName = decode(fileName->mb_str()); |
decodeFileName = decode(fileName->mb_str()); |
| 79 |
wxString strbuf(buf, eucConv); |
snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName); |
| 80 |
wxString strSearch(searchStr, sysConv); |
toLower(buf); |
| 81 |
wxString strDecodeFileName(decodeFileName, eucConv); |
toLower(outbuf); |
| 82 |
wxRegEx regStr(strSearch, wxRE_DEFAULT|wxRE_NEWLINE|wxRE_ICASE); |
toLower(decodeFileNameBuf); |
| 83 |
if(regStr.Matches(strbuf) || regStr.Matches(strDecodeFileName)){ |
if(strstr((const char*)buf, (const char*)outbuf) || |
| 84 |
|
strstr((const char*)decodeFileName, (const char*)outbuf)) { |
| 85 |
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
| 86 |
list->Append(wikiData); |
list->Append(wikiData); |
| 87 |
break; |
break; |
| 92 |
cont = dir->GetNext(fileName); |
cont = dir->GetNext(fileName); |
| 93 |
} |
} |
| 94 |
delete dir; |
delete dir; |
|
delete fileName; |
|
| 95 |
|
|
| 96 |
list->Sort(compWikiData); |
list->Sort(compWikiData); |
| 97 |
return list; |
return list; |
| 380 |
|
|
| 381 |
/******* Tools ************************/ |
/******* Tools ************************/ |
| 382 |
|
|
| 383 |
|
static void toLower(char* string) |
| 384 |
|
{ |
| 385 |
|
int i; |
| 386 |
|
|
| 387 |
|
for(i = 0; string[i] != 0; i++) { |
| 388 |
|
string[i] = tolower(string[i]); |
| 389 |
|
} |
| 390 |
|
} |
| 391 |
|
|
| 392 |
|
|
| 393 |
static char* decode(const char* string) |
static char* decode(const char* string) |
| 394 |
{ |
{ |
| 395 |
static char buf[MAX_BUF_SIZE]; |
static char buf[MAX_BUF_SIZE]; |