| 30 |
delete wikiDataDir; |
delete wikiDataDir; |
| 31 |
} |
} |
| 32 |
|
|
| 33 |
|
/* |
| 34 |
WikiList* mnModel::search(const char* searchStr) |
* iconv encode and create token list, |
| 35 |
|
* so you must free tokenLis after you used |
| 36 |
|
* |
| 37 |
|
* if failed to make token list, return FALSE. |
| 38 |
|
*/ |
| 39 |
|
bool mnModel::makeSearchToken(const char* searchStr, char* tokenList[]) |
| 40 |
{ |
{ |
|
int i; |
|
|
wxDir* dir; |
|
|
FILE* fp; |
|
|
wxString fullPathName; |
|
|
WikiData* wikiData; |
|
|
WikiList* list = new WikiList(); |
|
|
wxString* fileName = new wxString(); |
|
|
const char* decodeFileName; |
|
|
char decodeFileNameBuf[MAX_BUF_SIZE]; |
|
| 41 |
iconv_t codeSet; |
iconv_t codeSet; |
| 42 |
char outbuf[MAX_BUF_SIZE]; |
char outbuf[MAX_BUF_SIZE]; |
| 43 |
const char* inbufPtr = searchStr; |
const char* inbufPtr = searchStr; |
| 44 |
char* outbufPtr = outbuf; |
char* outbufPtr = outbuf; |
| 45 |
int inbufSize = strlen(searchStr); |
int inbufSize = strlen(searchStr); |
| 46 |
int outbufSize = sizeof(outbuf); |
int outbufSize = sizeof(outbuf); |
| 47 |
char* token; |
char* token; |
| 48 |
char* tokenList[32]; |
int i; |
|
bool found; |
|
| 49 |
|
|
|
memset(tokenList, 0, sizeof(char*)*32); |
|
| 50 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 51 |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
| 52 |
if(codeSet == (iconv_t)-1) { |
if(codeSet == (iconv_t)-1) { |
| 57 |
|
|
| 58 |
/* searchStr to Tokens */ |
/* searchStr to Tokens */ |
| 59 |
token = strtok(outbuf, " "); |
token = strtok(outbuf, " "); |
| 60 |
if(token == NULL) return list; |
if(token == NULL) return false; |
| 61 |
tokenList[0] = (char*)malloc(strlen(token)+1); |
tokenList[0] = (char*)malloc(strlen(token)+1); |
| 62 |
snprintf(tokenList[0], strlen(token)+1, "%s", token); |
snprintf(tokenList[0], strlen(token)+1, "%s", token); |
| 63 |
i = 1; |
i = 1; |
| 66 |
snprintf(tokenList[i], strlen(token)+1, "%s", token); |
snprintf(tokenList[i], strlen(token)+1, "%s", token); |
| 67 |
i++; |
i++; |
| 68 |
} |
} |
| 69 |
|
return true; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
bool mnModel::matchWithToken(wxString* fileName, char* tokenList[]) |
| 73 |
|
{ |
| 74 |
|
const char* decodeFileName; |
| 75 |
|
char decodeFileNameBuf[MAX_BUF_SIZE]; |
| 76 |
|
wxString fullPathName; |
| 77 |
|
FILE* fp; |
| 78 |
|
bool ans = false; |
| 79 |
|
bool found; |
| 80 |
|
|
| 81 |
|
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
| 82 |
|
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
| 83 |
|
if(fp == NULL) { |
| 84 |
|
return false; /* because of removed */ |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
/* TYPE search */ |
| 88 |
|
if(strstr(tokenList[0], TYPESEARCH_TAG) == tokenList[0]) |
| 89 |
|
{ |
| 90 |
|
found = typeSearch(tokenList[0], fp); |
| 91 |
|
if(found){ |
| 92 |
|
ans = true; |
| 93 |
|
} |
| 94 |
|
} |
| 95 |
|
/* Normal search */ |
| 96 |
|
else{ |
| 97 |
|
decodeFileName = decode(fileName->mb_str()); |
| 98 |
|
snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName); |
| 99 |
|
toLower(decodeFileNameBuf); |
| 100 |
|
found = normalSearch(tokenList, fp, decodeFileNameBuf); |
| 101 |
|
if(found){ |
| 102 |
|
ans = true; |
| 103 |
|
} |
| 104 |
|
} |
| 105 |
|
fclose(fp); |
| 106 |
|
|
| 107 |
|
return ans; |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
WikiList* mnModel::search(const char* searchStr) |
| 111 |
|
{ |
| 112 |
|
int i; |
| 113 |
|
wxDir* dir; |
| 114 |
|
WikiData* wikiData; |
| 115 |
|
WikiList* list = new WikiList(); |
| 116 |
|
wxString* fileName = new wxString(); |
| 117 |
|
char* tokenList[32]; |
| 118 |
|
|
| 119 |
|
memset(tokenList, 0, sizeof(char*)*32); |
| 120 |
|
if( makeSearchToken(searchStr, tokenList) == false) return list; |
| 121 |
|
|
| 122 |
dir = new wxDir(*wikiDataDir); |
dir = new wxDir(*wikiDataDir); |
| 123 |
if ( !dir->IsOpened() ) |
if ( !dir->IsOpened() ) |
| 125 |
MN_FATAL_ERROR(wxT("wxDir has faild\n")); |
MN_FATAL_ERROR(wxT("wxDir has faild\n")); |
| 126 |
return NULL; |
return NULL; |
| 127 |
} |
} |
| 128 |
|
|
| 129 |
bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES); |
bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES); |
| 130 |
while(cont){ |
while(cont){ |
|
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
|
|
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
|
|
if(fp == NULL) { |
|
|
MN_FATAL_ERROR(wxT("fopen faild")); |
|
|
} |
|
| 131 |
|
|
| 132 |
/* TYPE search */ |
if( matchWithToken(fileName, tokenList) ) { /* match with token list */ |
| 133 |
if(strstr(tokenList[0], TYPESEARCH_TAG) == tokenList[0]) |
wikiData = new WikiData(wikiDataDir, fileName); |
| 134 |
{ |
list->Append(wikiData); |
|
found = typeSearch(tokenList[0], fp); |
|
|
if(found){ |
|
|
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
|
|
list->Append(wikiData); |
|
|
} |
|
|
} |
|
|
/* Normal search */ |
|
|
else{ |
|
|
decodeFileName = decode(fileName->mb_str()); |
|
|
snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName); |
|
|
toLower(decodeFileNameBuf); |
|
|
found = normalSearch(tokenList, fp, decodeFileNameBuf); |
|
|
if(found){ |
|
|
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
|
|
list->Append(wikiData); |
|
|
} |
|
| 135 |
} |
} |
| 136 |
fclose(fp); |
|
| 137 |
cont = dir->GetNext(fileName); |
cont = dir->GetNext(fileName); |
| 138 |
} |
} |
| 139 |
|
|
| 140 |
delete dir; |
delete dir; |
| 141 |
delete fileName; |
delete fileName; |
| 142 |
for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]); |
for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]); |
| 145 |
return list; |
return list; |
| 146 |
} |
} |
| 147 |
|
|
| 148 |
|
/* |
| 149 |
|
* add malon-type:xxx to search list |
| 150 |
|
*/ |
| 151 |
void mnModel::group() |
void mnModel::group() |
| 152 |
{ |
{ |
| 153 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 201 |
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 202 |
|
|
| 203 |
typeToken = new wxString(outbuf, conv); |
typeToken = new wxString(outbuf, conv); |
| 204 |
addSearchStr(typeToken); |
if( addSearchStr(typeToken) ) { |
| 205 |
|
WikiList* wikiList = search(typeToken->mb_str()); |
| 206 |
|
addSearchList(typeToken, wikiList); |
| 207 |
|
} |
| 208 |
delete typeToken; |
delete typeToken; |
| 209 |
ptr = NULL; |
ptr = NULL; |
| 210 |
} |
} |
| 276 |
return false; |
return false; |
| 277 |
} |
} |
| 278 |
|
|
| 279 |
void mnModel::addSearchStr(wxString* searchStr) |
bool mnModel::addSearchStr(wxString* searchStr) |
| 280 |
{ |
{ |
| 281 |
wxString *string; |
wxString *string; |
| 282 |
|
|
| 283 |
if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){ |
if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){ |
| 284 |
string = new wxString(searchStr->c_str()); |
string = new wxString(searchStr->c_str()); |
| 285 |
//searchStrList->Add(*string, 1); |
searchStrList->Add(*string, 1); |
| 286 |
searchStrList->Insert(*string, 0); |
//searchStrList->Insert(*string, 0); |
| 287 |
|
return true; /* Add */ |
| 288 |
} |
} |
| 289 |
|
return false; /* does'nt add because of duplicating */ |
| 290 |
|
} |
| 291 |
|
|
| 292 |
|
void mnModel::addSearchList(wxString* searchStr, WikiList* list) |
| 293 |
|
{ |
| 294 |
|
wikiHash[*searchStr] = list; |
| 295 |
} |
} |
| 296 |
|
|
| 297 |
void mnModel::removeSearchStr(wxString searchStr) |
void mnModel::removeSearchStr(wxString searchStr) |
| 298 |
{ |
{ |
| 299 |
if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) { |
if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) { |
| 300 |
searchStrList->Remove(searchStr.c_str()); |
searchStrList->Remove(searchStr.c_str()); |
| 301 |
|
wikiHash[*searchStr] = NULL; |
| 302 |
} |
} |
| 303 |
} |
} |
| 304 |
|
|
| 311 |
itemStr.sprintf(wxT("%s"), newStr->c_str()); |
itemStr.sprintf(wxT("%s"), newStr->c_str()); |
| 312 |
} |
} |
| 313 |
} |
} |
| 314 |
|
|
| 315 |
|
void mnModel::clearSearchStrList() |
| 316 |
|
{ |
| 317 |
|
searchStrList->Clear(); |
| 318 |
|
} |
| 319 |
|
|
| 320 |
|
void mnModel::clearSearchResultList() |
| 321 |
|
{ |
| 322 |
|
wikiHash.clear(); |
| 323 |
|
} |
| 324 |
|
|
| 325 |
const wxString* mnModel::getWikiDataDir() |
const wxString* mnModel::getWikiDataDir() |
| 326 |
{ |
{ |
| 327 |
return wikiDataDir; |
return wikiDataDir; |
| 338 |
|
|
| 339 |
return data; |
return data; |
| 340 |
} |
} |
| 341 |
|
const WikiList* mnModel::getSearchResultList(wxString* searchStr) |
| 342 |
|
{ |
| 343 |
|
return wikiHash[*searchStr]; |
| 344 |
|
} |
| 345 |
|
|
| 346 |
|
/* add "addData's" clone. if already exist same data, overwrite it*/ |
| 347 |
|
void mnModel::addSearchResultList(wxString* searchStr, WikiData* addData) |
| 348 |
|
{ |
| 349 |
|
WikiList* wikiList = wikiHash[*searchStr]; |
| 350 |
|
WikiList::Node* node; |
| 351 |
|
WikiData* data; |
| 352 |
|
|
| 353 |
|
if(wikiList == NULL) { |
| 354 |
|
MN_FATAL_ERROR(wxT("wikiList is null")); |
| 355 |
|
return; |
| 356 |
|
} |
| 357 |
|
|
| 358 |
|
node = wikiList->GetFirst(); |
| 359 |
|
while(node) { |
| 360 |
|
data = node->GetData(); |
| 361 |
|
if(data == addData) return; |
| 362 |
|
if( *(data->getSubject()) == *(addData->getOldSubject()) ) { |
| 363 |
|
if(wikiList->DeleteObject(data)) { |
| 364 |
|
//delete data; /* may be wrong.. */ |
| 365 |
|
break; |
| 366 |
|
} |
| 367 |
|
else { |
| 368 |
|
MN_FATAL_ERROR(wxT("Can't find delete data")); |
| 369 |
|
} |
| 370 |
|
} |
| 371 |
|
node = node->GetNext(); |
| 372 |
|
} |
| 373 |
|
WikiData* copy = new WikiData((wxString*)wikiDataDir, (wxString*)addData->getFileName()); |
| 374 |
|
wikiList->Append(copy); |
| 375 |
|
wikiList->Sort(compWikiData); |
| 376 |
|
} |
| 377 |
|
|
| 378 |
|
bool mnModel::delSearchResultList(wxString* searchStr, WikiData* delData) |
| 379 |
|
{ |
| 380 |
|
WikiList* wikiList = wikiHash[*searchStr]; |
| 381 |
|
WikiList::Node* node; |
| 382 |
|
WikiData* data; |
| 383 |
|
bool found = false; |
| 384 |
|
|
| 385 |
|
if(wikiList == NULL) { |
| 386 |
|
MN_FATAL_ERROR(wxT("wikiList is null")); |
| 387 |
|
return false; |
| 388 |
|
} |
| 389 |
|
|
| 390 |
|
node = wikiList->GetFirst(); |
| 391 |
|
while(node) { |
| 392 |
|
data = node->GetData(); |
| 393 |
|
if(data == delData) { |
| 394 |
|
if(!wikiList->DeleteObject(data)) { |
| 395 |
|
MN_FATAL_ERROR(wxT("Can't find delete data")); |
| 396 |
|
} |
| 397 |
|
found = true; |
| 398 |
|
break; |
| 399 |
|
} |
| 400 |
|
else if( *(data->getSubject()) == *(delData->getOldSubject()) ) { |
| 401 |
|
if(wikiList->DeleteObject(data)) { |
| 402 |
|
//delete data; /* may be wrong.. */ |
| 403 |
|
found = true; |
| 404 |
|
break; |
| 405 |
|
} |
| 406 |
|
else { |
| 407 |
|
MN_FATAL_ERROR(wxT("Can't find delete data")); |
| 408 |
|
} |
| 409 |
|
} |
| 410 |
|
node = node->GetNext(); |
| 411 |
|
} |
| 412 |
|
wikiList->Sort(compWikiData); |
| 413 |
|
return found; |
| 414 |
|
} |
| 415 |
|
|
| 416 |
/******* WikiData ************************/ |
/******* WikiData ************************/ |
| 417 |
WikiData::WikiData(wxString* dataDir, const char* file, FILE* fp) |
WikiData::WikiData(wxString* dataDir, wxString* inFileName) |
| 418 |
{ |
{ |
| 419 |
|
FILE* fp; |
| 420 |
|
wxString fullPathName; |
| 421 |
char* decodeStr; |
char* decodeStr; |
| 422 |
char buf[MAX_BUF_SIZE]; |
char buf[MAX_BUF_SIZE]; |
| 423 |
char* inbuf; |
char* inbuf; |
| 434 |
|
|
| 435 |
text = NULL; |
text = NULL; |
| 436 |
memset(outbuf, 0, MAX_BUF_SIZE); |
memset(outbuf, 0, MAX_BUF_SIZE); |
| 437 |
fileName = new wxString((const char*)file, conv); |
fileName = new wxString(inFileName->mb_str(), conv); |
| 438 |
dataDirName = dataDir; |
dataDirName = new wxString(dataDir->mb_str(), conv); |
| 439 |
decodeStr = decode(file); |
decodeStr = decode(fileName->mb_str()); |
| 440 |
inbufSize = strlen(decodeStr); |
inbufSize = strlen(decodeStr); |
| 441 |
outbufSize = sizeof(outbuf); |
outbufSize = sizeof(outbuf); |
| 442 |
iconv(codeSet, (ICONV_CONST char**)&decodeStr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
iconv(codeSet, (ICONV_CONST char**)&decodeStr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 443 |
subject = new wxString((const char*)outbuf, conv); |
subject = new wxString((const char*)outbuf, conv); |
| 444 |
|
oldSubject = new wxString((const char*)outbuf, conv); |
| 445 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 446 |
|
|
| 447 |
date = NULL; |
date = NULL; |
| 448 |
|
|
| 449 |
rewind(fp); |
fullPathName = *dataDir + wxT("/") + *fileName; |
| 450 |
|
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
| 451 |
|
if(fp == NULL) { |
| 452 |
|
MN_FATAL_ERROR(wxT("fopen faild")); |
| 453 |
|
} |
| 454 |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
| 455 |
if(strstr( (const char*)buf, (const char*)DATE_TAG)) { |
if(strstr( (const char*)buf, (const char*)DATE_TAG)) { |
| 456 |
strtok(buf, "\n"); |
strtok(buf, "\n"); |
| 459 |
break; |
break; |
| 460 |
} |
} |
| 461 |
} |
} |
| 462 |
|
fclose(fp); |
| 463 |
} |
} |
| 464 |
|
|
| 465 |
WikiData::WikiData(wxString* dataDir) { |
WikiData::WikiData(wxString* dataDir) { |
| 467 |
char buf[MAX_BUF_SIZE]; |
char buf[MAX_BUF_SIZE]; |
| 468 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 469 |
|
|
| 470 |
dataDirName = dataDir; |
dataDirName = new wxString(dataDir->mb_str(), conv); |
| 471 |
|
|
| 472 |
time(&now); |
time(&now); |
| 473 |
memset(buf, 0, sizeof(buf)); |
memset(buf, 0, sizeof(buf)); |
| 474 |
strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now)); |
strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now)); |
| 475 |
subject = new wxString(buf, conv); |
subject = new wxString(buf, conv); |
| 476 |
|
oldSubject = new wxString(buf, conv); |
| 477 |
|
|
| 478 |
fileName = new wxString(encode(buf), conv); |
fileName = new wxString(encode(buf), conv); |
| 479 |
fileName->Append(wxT(EXT_TAG)); |
fileName->Append(wxT(EXT_TAG)); |
| 491 |
WikiData::~WikiData() |
WikiData::~WikiData() |
| 492 |
{ |
{ |
| 493 |
delete subject; |
delete subject; |
| 494 |
|
delete oldSubject; |
| 495 |
delete fileName; |
delete fileName; |
| 496 |
delete date; |
delete date; |
| 497 |
delete text; |
delete text; |
| 498 |
|
delete dataDirName; |
| 499 |
} |
} |
| 500 |
|
|
| 501 |
const wxString* WikiData::getFileName() |
const wxString* WikiData::getFileName() |
| 508 |
return subject; |
return subject; |
| 509 |
} |
} |
| 510 |
|
|
| 511 |
|
const wxString* WikiData::getOldSubject() |
| 512 |
|
{ |
| 513 |
|
return oldSubject; |
| 514 |
|
} |
| 515 |
|
|
| 516 |
void WikiData::modSubject(wxString* newSubject) |
void WikiData::modSubject(wxString* newSubject) |
| 517 |
{ |
{ |
| 518 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 519 |
wxString* oldFileName = fileName; |
wxString* oldFileName = fileName; |
|
wxString* oldSubject = subject; |
|
| 520 |
char oldFullPath[MAX_BUF_SIZE]; |
char oldFullPath[MAX_BUF_SIZE]; |
| 521 |
char newFullPath[MAX_BUF_SIZE]; |
char newFullPath[MAX_BUF_SIZE]; |
| 522 |
iconv_t codeSet; |
iconv_t codeSet; |
| 528 |
int outbufSize = sizeof(outbuf); |
int outbufSize = sizeof(outbuf); |
| 529 |
FILE* fp; |
FILE* fp; |
| 530 |
|
|
| 531 |
|
oldSubject = subject; |
| 532 |
|
|
| 533 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 534 |
memset(inbuf, 0, sizeof(inbuf)); |
memset(inbuf, 0, sizeof(inbuf)); |
| 535 |
strcpy(inbuf, (const char*)newSubject->mb_str()); |
strcpy(inbuf, (const char*)newSubject->mb_str()); |
| 558 |
fclose(fp); |
fclose(fp); |
| 559 |
} |
} |
| 560 |
|
|
|
delete oldSubject; |
|
| 561 |
delete oldFileName; |
delete oldFileName; |
| 562 |
} |
} |
| 563 |
|
|
| 623 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 624 |
delete text; |
delete text; |
| 625 |
//text = new wxString(intext->c_str()); |
//text = new wxString(intext->c_str()); |
| 626 |
text = new wxString(*intext); |
//text = new wxString(*intext); |
| 627 |
//text = new wxString(intext->mb_str(), conv); |
text = new wxString(intext->mb_str(), conv); |
| 628 |
} |
} |
| 629 |
|
|
| 630 |
void WikiData::removeDataFile() |
void WikiData::removeDataFile() |