| 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(); |
|
wxRegEx* regStr; |
|
| 44 |
iconv_t codeSet; |
iconv_t codeSet; |
| 45 |
char outbuf[MAX_BUF_SIZE]; |
char outbuf[MAX_BUF_SIZE]; |
| 46 |
const char* inbufPtr = searchStr; |
const char* inbufPtr = searchStr; |
| 48 |
int inbufSize = strlen(searchStr); |
int inbufSize = strlen(searchStr); |
| 49 |
int outbufSize = sizeof(outbuf); |
int outbufSize = sizeof(outbuf); |
| 50 |
const char* decodeFileName; |
const char* decodeFileName; |
| 51 |
|
char decodeFileNameBuf[MAX_BUF_SIZE]; |
| 52 |
|
char* token; |
| 53 |
|
char* tokenList[32]; |
| 54 |
|
bool found; |
| 55 |
|
|
| 56 |
|
memset(tokenList, 0, sizeof(char*)*32); |
| 57 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 58 |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
| 59 |
if(codeSet == (iconv_t)-1) { |
if(codeSet == (iconv_t)-1) { |
| 60 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 61 |
} |
} |
| 62 |
iconv(codeSet, (const char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 63 |
iconv_close(codeSet); |
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() ) |
| 78 |
{ |
{ |
| 79 |
MN_FATAL_ERROR(wxT("wxDir has faild\n")); |
MN_FATAL_ERROR(wxT("wxDir has faild\n")); |
| 80 |
return NULL; |
return NULL; |
| 81 |
} |
} |
| 82 |
bool cont = dir->GetFirst(fileName, wxEmptyString, wxDIR_FILES); |
bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES); |
| 83 |
while(cont){ |
while(cont){ |
| 84 |
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
| 85 |
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
| 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 |
if(strstr((const char*)buf, (const char*)outbuf) || |
snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName); |
| 96 |
strstr((const char*)decodeFileName, (const char*)outbuf)) { |
toLower(buf); |
| 97 |
|
toLower(outbuf); |
| 98 |
|
toLower(decodeFileNameBuf); |
| 99 |
|
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; |
| 119 |
cont = dir->GetNext(fileName); |
cont = dir->GetNext(fileName); |
| 120 |
} |
} |
| 121 |
delete dir; |
delete dir; |
| 122 |
|
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; |
| 152 |
itemStr.sprintf(wxT("%s"), newStr->c_str()); |
itemStr.sprintf(wxT("%s"), newStr->c_str()); |
| 153 |
} |
} |
| 154 |
} |
} |
| 155 |
|
const wxString* mnModel::getWikiDataDir() |
| 156 |
|
{ |
| 157 |
|
return wikiDataDir; |
| 158 |
|
} |
| 159 |
|
|
| 160 |
const wxArrayString* mnModel::getSearchStrList() |
const wxArrayString* mnModel::getSearchStrList() |
| 161 |
{ |
{ |
| 193 |
decodeStr = decode(file); |
decodeStr = decode(file); |
| 194 |
inbufSize = strlen(decodeStr); |
inbufSize = strlen(decodeStr); |
| 195 |
outbufSize = sizeof(outbuf); |
outbufSize = sizeof(outbuf); |
| 196 |
iconv(codeSet, (const char**)&decodeStr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
iconv(codeSet, (ICONV_CONST char**)&decodeStr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 197 |
subject = new wxString((const char*)outbuf, conv); |
subject = new wxString((const char*)outbuf, conv); |
| 198 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 199 |
|
|
| 277 |
if(codeSet == (iconv_t)-1) { |
if(codeSet == (iconv_t)-1) { |
| 278 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 279 |
} |
} |
| 280 |
iconv(codeSet, (const char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 281 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 282 |
subject = new wxString(newSubject->c_str()); |
subject = new wxString(newSubject->c_str()); |
| 283 |
fileName = new wxString(encode(outbuf), conv); |
fileName = new wxString(encode(outbuf), conv); |
| 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, (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 |
|
|
| 382 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 383 |
outbufSize = sizeof(outbuf); |
outbufSize = sizeof(outbuf); |
| 384 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 385 |
iconv(codeSet, (const char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 386 |
fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp); |
fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp); |
| 387 |
fclose(fp); |
fclose(fp); |
| 388 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 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]; |