| 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 |
|
if(token == NULL) return list; |
| 68 |
|
tokenList[0] = (char*)malloc(strlen(token)+1); |
| 69 |
|
snprintf(tokenList[0], strlen(token)+1, "%s", token); |
| 70 |
|
i = 1; |
| 71 |
|
while((token = strtok(NULL, " ")) != NULL) { |
| 72 |
|
tokenList[i] = (char*)malloc(strlen(token)+1); |
| 73 |
|
snprintf(tokenList[i], strlen(token)+1, "%s", token); |
| 74 |
|
i++; |
| 75 |
|
} |
| 76 |
|
|
| 77 |
dir = new wxDir(*wikiDataDir); |
dir = new wxDir(*wikiDataDir); |
| 78 |
if ( !dir->IsOpened() ) |
if ( !dir->IsOpened() ) |
| 79 |
{ |
{ |
| 87 |
if(fp == NULL) { |
if(fp == NULL) { |
| 88 |
MN_FATAL_ERROR(wxT("fopen faild")); |
MN_FATAL_ERROR(wxT("fopen faild")); |
| 89 |
} |
} |
| 90 |
|
|
| 91 |
while(1){ |
while(1){ |
| 92 |
memset(buf, 0, MAX_BUF_SIZE); |
memset(buf, 0, MAX_BUF_SIZE); |
| 93 |
fread(buf, MAX_BUF_SIZE-1, 1, fp); |
fread(buf, MAX_BUF_SIZE-1, 1, fp); |
| 94 |
if(buf[0] == 0) break; |
if(buf[0] == 0) break; |
| 95 |
decodeFileName = decode(fileName->mb_str()); |
decodeFileName = decode(fileName->mb_str()); |
| 96 |
if(strstr((const char*)buf, (const char*)outbuf) || |
snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName); |
| 97 |
strstr((const char*)decodeFileName, (const char*)outbuf)) { |
toLower(buf); |
| 98 |
|
toLower(decodeFileNameBuf); |
| 99 |
|
found = TRUE; |
| 100 |
|
for(i = 0; tokenList[i] != NULL; i++){ |
| 101 |
|
toLower(tokenList[i]); |
| 102 |
|
if(strstr((const char*)buf, (const char*)tokenList[i]) || |
| 103 |
|
strstr((const char*)decodeFileNameBuf, (const char*)tokenList[i]) || |
| 104 |
|
strcmp((const char*)tokenList[i], (const char*)ALLMEMO_TAG) == 0) { |
| 105 |
|
found = TRUE; |
| 106 |
|
} |
| 107 |
|
else { |
| 108 |
|
found = FALSE; |
| 109 |
|
break; |
| 110 |
|
} |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
if(found){ |
| 114 |
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
| 115 |
list->Append(wikiData); |
list->Append(wikiData); |
| 116 |
break; |
break; |
| 121 |
cont = dir->GetNext(fileName); |
cont = dir->GetNext(fileName); |
| 122 |
} |
} |
| 123 |
delete dir; |
delete dir; |
| 124 |
|
delete fileName; |
| 125 |
|
for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]); |
| 126 |
|
|
| 127 |
list->Sort(compWikiData); |
list->Sort(compWikiData); |
| 128 |
return list; |
return list; |
| 134 |
|
|
| 135 |
if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){ |
if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){ |
| 136 |
string = new wxString(searchStr->c_str()); |
string = new wxString(searchStr->c_str()); |
| 137 |
searchStrList->Add(*string, 1); |
//searchStrList->Add(*string, 1); |
| 138 |
|
searchStrList->Insert(*string, 0); |
| 139 |
} |
} |
| 140 |
} |
} |
| 141 |
|
|
| 196 |
decodeStr = decode(file); |
decodeStr = decode(file); |
| 197 |
inbufSize = strlen(decodeStr); |
inbufSize = strlen(decodeStr); |
| 198 |
outbufSize = sizeof(outbuf); |
outbufSize = sizeof(outbuf); |
| 199 |
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); |
| 200 |
subject = new wxString((const char*)outbuf, conv); |
subject = new wxString((const char*)outbuf, conv); |
| 201 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 202 |
|
|
| 280 |
if(codeSet == (iconv_t)-1) { |
if(codeSet == (iconv_t)-1) { |
| 281 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 282 |
} |
} |
| 283 |
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); |
| 284 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 285 |
subject = new wxString(newSubject->c_str()); |
subject = new wxString(newSubject->c_str()); |
| 286 |
fileName = new wxString(encode(outbuf), conv); |
fileName = new wxString(encode(outbuf), conv); |
| 290 |
sprintf(newFullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str()); |
sprintf(newFullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str()); |
| 291 |
|
|
| 292 |
if((fp = fopen(newFullPath, "r")) == NULL) { |
if((fp = fopen(newFullPath, "r")) == NULL) { |
| 293 |
rename(oldFullPath, newFullPath); |
if(rename(oldFullPath, newFullPath) < 0) wxLogMessage(wxT("rename error: errno=[%d]"), errno); |
| 294 |
} |
} |
| 295 |
else if(strcmp(oldFullPath, newFullPath)){ |
else if(strcmp(oldFullPath, newFullPath)){ |
| 296 |
wxLogMessage(wxT("File has already exist. [%s]"), fileName->c_str()); |
wxLogMessage(wxT("File has already exist. [%s]"), fileName->c_str()); |
| 297 |
fclose(fp); |
fclose(fp); |
| 298 |
} |
} |
| 299 |
|
else { |
| 300 |
|
fclose(fp); |
| 301 |
|
} |
| 302 |
|
|
| 303 |
delete oldSubject; |
delete oldSubject; |
| 304 |
delete oldFileName; |
delete oldFileName; |
| 342 |
} |
} |
| 343 |
|
|
| 344 |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
| 345 |
|
#ifdef __WXMAC__ |
| 346 |
|
for(int i = 0; buf[i] != 0; i++) if(buf[i] == (char)MAC_BACKSLASH) buf[i] = '\\'; |
| 347 |
|
#endif |
| 348 |
inbufPtr = buf; |
inbufPtr = buf; |
| 349 |
inbufSize = sizeof(buf); |
inbufSize = sizeof(buf); |
| 350 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 351 |
outbufSize = sizeof(outbuf); |
outbufSize = sizeof(outbuf); |
| 352 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 353 |
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); |
| 354 |
tmpStr = new wxString((char*)outbuf, conv); |
tmpStr = new wxString((char*)outbuf, conv); |
| 355 |
*text += *tmpStr; |
*text += *tmpStr; |
| 356 |
delete tmpStr; |
delete tmpStr; |
| 405 |
|
|
| 406 |
memset(inbuf, 0, sizeof(inbuf)); |
memset(inbuf, 0, sizeof(inbuf)); |
| 407 |
strcpy(inbuf,(const char*)text->mb_str()); |
strcpy(inbuf,(const char*)text->mb_str()); |
| 408 |
|
|
| 409 |
|
#ifdef __WXMAC__ |
| 410 |
|
for(int i = 0; inbuf[i] != 0; i++) if(inbuf[i] == (char)MAC_BACKSLASH) inbuf[i] = '\\'; |
| 411 |
|
#endif |
| 412 |
|
|
| 413 |
inbufPtr = inbuf; |
inbufPtr = inbuf; |
| 414 |
inbufSize = strlen(inbufPtr); |
inbufSize = strlen(inbufPtr); |
| 415 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 416 |
outbufSize = sizeof(outbuf); |
outbufSize = sizeof(outbuf); |
| 417 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 418 |
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); |
| 419 |
fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp); |
fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp); |
| 420 |
fclose(fp); |
fclose(fp); |
| 421 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 423 |
|
|
| 424 |
/******* Tools ************************/ |
/******* Tools ************************/ |
| 425 |
|
|
| 426 |
|
static void toLower(char* string) |
| 427 |
|
{ |
| 428 |
|
int i; |
| 429 |
|
|
| 430 |
|
for(i = 0; string[i] != 0; i++) { |
| 431 |
|
string[i] = tolower(string[i]); |
| 432 |
|
} |
| 433 |
|
} |
| 434 |
|
|
| 435 |
|
|
| 436 |
static char* decode(const char* string) |
static char* decode(const char* string) |
| 437 |
{ |
{ |
| 438 |
static char buf[MAX_BUF_SIZE]; |
static char buf[MAX_BUF_SIZE]; |