| 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 ************************/ |
| 33 |
|
|
| 34 |
WikiList* mnModel::search(const char* searchStr) |
WikiList* mnModel::search(const char* searchStr) |
| 35 |
{ |
{ |
| 36 |
|
int i; |
| 37 |
wxDir* dir; |
wxDir* dir; |
| 38 |
FILE* fp; |
FILE* fp; |
| 39 |
wxString fullPathName; |
wxString fullPathName; |
| 41 |
WikiData* wikiData; |
WikiData* wikiData; |
| 42 |
WikiList* list = new WikiList(); |
WikiList* list = new WikiList(); |
| 43 |
wxString* fileName = new wxString(); |
wxString* fileName = new wxString(); |
| 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]; |
| 52 |
wxCSConv sysConv(wxT(CODE_SET_SYSTEM)); |
char* token; |
| 53 |
|
char* tokenList[32]; |
| 54 |
|
bool found; |
| 55 |
|
|
| 56 |
|
memset(tokenList, 0, sizeof(char*)*32); |
| 57 |
|
memset(outbuf, 0, outbufSize); |
| 58 |
|
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
| 59 |
|
if(codeSet == (iconv_t)-1) { |
| 60 |
|
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 61 |
|
} |
| 62 |
|
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 63 |
|
iconv_close(codeSet); |
| 64 |
|
|
| 65 |
|
/* searchStr to Tokens */ |
| 66 |
|
token = strtok(outbuf, " "); |
| 67 |
|
tokenList[0] = (char*)malloc(strlen(token)+1); |
| 68 |
|
snprintf(tokenList[0], strlen(token)+1, "%s", token); |
| 69 |
|
i = 1; |
| 70 |
|
while((token = strtok(NULL, " ")) != NULL) { |
| 71 |
|
tokenList[i] = (char*)malloc(strlen(token)+1); |
| 72 |
|
snprintf(tokenList[i], strlen(token)+1, "%s", token); |
| 73 |
|
i++; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
dir = new wxDir(*wikiDataDir); |
dir = new wxDir(*wikiDataDir); |
| 77 |
if ( !dir->IsOpened() ) |
if ( !dir->IsOpened() ) |
| 86 |
if(fp == NULL) { |
if(fp == NULL) { |
| 87 |
MN_FATAL_ERROR(wxT("fopen faild")); |
MN_FATAL_ERROR(wxT("fopen faild")); |
| 88 |
} |
} |
| 89 |
|
|
| 90 |
while(1){ |
while(1){ |
| 91 |
memset(buf, 0, MAX_BUF_SIZE); |
memset(buf, 0, MAX_BUF_SIZE); |
| 92 |
fread(buf, MAX_BUF_SIZE-1, 1, fp); |
fread(buf, MAX_BUF_SIZE-1, 1, fp); |
| 93 |
if(buf[0] == 0) break; |
if(buf[0] == 0) break; |
| 94 |
decodeFileName = decode(fileName->mb_str()); |
decodeFileName = decode(fileName->mb_str()); |
| 95 |
wxString strbuf(buf, eucConv); |
snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName); |
| 96 |
wxString strSearch(searchStr, sysConv); |
toLower(buf); |
| 97 |
wxString strDecodeFileName(decodeFileName, eucConv); |
toLower(outbuf); |
| 98 |
wxRegEx regStr(strSearch, wxRE_DEFAULT|wxRE_NEWLINE|wxRE_ICASE); |
toLower(decodeFileNameBuf); |
| 99 |
if(regStr.Matches(strbuf) || regStr.Matches(strDecodeFileName)){ |
found = TRUE; |
| 100 |
|
for(i = 0; tokenList[i] != NULL; i++){ |
| 101 |
|
if(strstr((const char*)buf, (const char*)tokenList[i]) || |
| 102 |
|
strstr((const char*)decodeFileName, (const char*)tokenList[i])) { |
| 103 |
|
found = TRUE; |
| 104 |
|
} |
| 105 |
|
else { |
| 106 |
|
found = FALSE; |
| 107 |
|
break; |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
if(found){ |
| 112 |
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
| 113 |
list->Append(wikiData); |
list->Append(wikiData); |
| 114 |
break; |
break; |
| 120 |
} |
} |
| 121 |
delete dir; |
delete dir; |
| 122 |
delete fileName; |
delete fileName; |
| 123 |
|
for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]); |
| 124 |
|
|
| 125 |
list->Sort(compWikiData); |
list->Sort(compWikiData); |
| 126 |
return list; |
return list; |
| 309 |
FILE* fp; |
FILE* fp; |
| 310 |
char buf[MAX_BUF_SIZE]; |
char buf[MAX_BUF_SIZE]; |
| 311 |
char fullPath[MAX_BUF_SIZE]; |
char fullPath[MAX_BUF_SIZE]; |
|
iconv_t codeSet; |
|
|
char outbuf[MAX_BUF_SIZE]; |
|
|
char* inbufPtr; |
|
|
char* outbufPtr; |
|
|
int inbufSize; |
|
|
int outbufSize; |
|
| 312 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 313 |
|
wxCSConv eucConv(wxT(CODE_SET_EUC_JP)); |
| 314 |
wxString* tmpStr; |
wxString* tmpStr; |
| 315 |
|
|
|
codeSet = iconv_open(CODE_SET_SYSTEM, CODE_SET_EUC_JP); |
|
|
if(codeSet == (iconv_t)-1) { |
|
|
MN_FATAL_ERROR(wxT("failed iconv_open")); |
|
|
} |
|
|
|
|
| 316 |
if(text) { |
if(text) { |
|
iconv_close(codeSet); |
|
| 317 |
return text; |
return text; |
| 318 |
} |
} |
| 319 |
|
|
| 325 |
} |
} |
| 326 |
|
|
| 327 |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
| 328 |
inbufPtr = buf; |
tmpStr = new wxString(buf, eucConv); |
|
inbufSize = sizeof(buf); |
|
|
outbufPtr = outbuf; |
|
|
outbufSize = sizeof(outbuf); |
|
|
memset(outbuf, 0, outbufSize); |
|
|
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
|
|
tmpStr = new wxString((char*)outbuf, conv); |
|
| 329 |
*text += *tmpStr; |
*text += *tmpStr; |
| 330 |
delete tmpStr; |
delete tmpStr; |
| 331 |
} |
} |
|
iconv_close(codeSet); |
|
| 332 |
fclose(fp); |
fclose(fp); |
|
|
|
| 333 |
return text; |
return text; |
| 334 |
} |
} |
| 335 |
|
|
| 390 |
|
|
| 391 |
/******* Tools ************************/ |
/******* Tools ************************/ |
| 392 |
|
|
| 393 |
|
static void toLower(char* string) |
| 394 |
|
{ |
| 395 |
|
int i; |
| 396 |
|
|
| 397 |
|
for(i = 0; string[i] != 0; i++) { |
| 398 |
|
string[i] = tolower(string[i]); |
| 399 |
|
} |
| 400 |
|
} |
| 401 |
|
|
| 402 |
|
|
| 403 |
static char* decode(const char* string) |
static char* decode(const char* string) |
| 404 |
{ |
{ |
| 405 |
static char buf[MAX_BUF_SIZE]; |
static char buf[MAX_BUF_SIZE]; |