| 65 |
tokenList[i] = (char*)malloc(strlen(token)+1); |
tokenList[i] = (char*)malloc(strlen(token)+1); |
| 66 |
snprintf(tokenList[i], strlen(token)+1, "%s", token); |
snprintf(tokenList[i], strlen(token)+1, "%s", token); |
| 67 |
i++; |
i++; |
| 68 |
|
if(i >= MAX_TOKEN) break; |
| 69 |
} |
} |
| 70 |
return true; |
return true; |
| 71 |
} |
} |
| 82 |
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
| 83 |
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
| 84 |
if(fp == NULL) { |
if(fp == NULL) { |
| 85 |
MN_FATAL_ERROR(wxT("fopen faild")); |
return false; /* because of removed */ |
| 86 |
} |
} |
| 87 |
|
|
| 88 |
/* TYPE search */ |
/* TYPE search */ |
| 115 |
WikiData* wikiData; |
WikiData* wikiData; |
| 116 |
WikiList* list = new WikiList(); |
WikiList* list = new WikiList(); |
| 117 |
wxString* fileName = new wxString(); |
wxString* fileName = new wxString(); |
| 118 |
char* tokenList[32]; |
char* tokenList[MAX_TOKEN]; |
| 119 |
|
|
| 120 |
memset(tokenList, 0, sizeof(char*)*32); |
memset(tokenList, 0, sizeof(char*)*MAX_TOKEN); |
| 121 |
if( makeSearchToken(searchStr, tokenList) == false) return list; |
if( makeSearchToken(searchStr, tokenList) == false) return list; |
| 122 |
|
|
| 123 |
dir = new wxDir(*wikiDataDir); |
dir = new wxDir(*wikiDataDir); |
| 146 |
return list; |
return list; |
| 147 |
} |
} |
| 148 |
|
|
| 149 |
|
/* |
| 150 |
|
* add malon-type:xxx to search list |
| 151 |
|
*/ |
| 152 |
void mnModel::group() |
void mnModel::group() |
| 153 |
{ |
{ |
| 154 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 202 |
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); |
| 203 |
|
|
| 204 |
typeToken = new wxString(outbuf, conv); |
typeToken = new wxString(outbuf, conv); |
| 205 |
addSearchStr(typeToken); |
if( addSearchStr(typeToken) ) { |
| 206 |
|
WikiList* wikiList = search(typeToken->mb_str()); |
| 207 |
|
addSearchList(typeToken, wikiList); |
| 208 |
|
} |
| 209 |
delete typeToken; |
delete typeToken; |
| 210 |
ptr = NULL; |
ptr = NULL; |
| 211 |
} |
} |
| 277 |
return false; |
return false; |
| 278 |
} |
} |
| 279 |
|
|
| 280 |
void mnModel::addSearchStr(wxString* searchStr) |
bool mnModel::addSearchStr(wxString* searchStr) |
| 281 |
{ |
{ |
| 282 |
wxString *string; |
wxString *string; |
| 283 |
|
|
| 285 |
string = new wxString(searchStr->c_str()); |
string = new wxString(searchStr->c_str()); |
| 286 |
searchStrList->Add(*string, 1); |
searchStrList->Add(*string, 1); |
| 287 |
//searchStrList->Insert(*string, 0); |
//searchStrList->Insert(*string, 0); |
| 288 |
|
return true; /* Add */ |
| 289 |
} |
} |
| 290 |
|
return false; /* does'nt add because of duplicating */ |
| 291 |
} |
} |
| 292 |
|
|
| 293 |
void mnModel::addSearchList(wxString* searchStr, WikiList* list) |
void mnModel::addSearchList(wxString* searchStr, WikiList* list) |
| 299 |
{ |
{ |
| 300 |
if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) { |
if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) { |
| 301 |
searchStrList->Remove(searchStr.c_str()); |
searchStrList->Remove(searchStr.c_str()); |
| 302 |
|
wikiHash[*searchStr] = NULL; |
| 303 |
} |
} |
| 304 |
} |
} |
| 305 |
|
|
| 312 |
itemStr.sprintf(wxT("%s"), newStr->c_str()); |
itemStr.sprintf(wxT("%s"), newStr->c_str()); |
| 313 |
} |
} |
| 314 |
} |
} |
| 315 |
|
|
| 316 |
|
void mnModel::clearSearchStrList() |
| 317 |
|
{ |
| 318 |
|
searchStrList->Clear(); |
| 319 |
|
} |
| 320 |
|
|
| 321 |
|
void mnModel::clearSearchResultList() |
| 322 |
|
{ |
| 323 |
|
wikiHash.clear(); |
| 324 |
|
} |
| 325 |
|
|
| 326 |
const wxString* mnModel::getWikiDataDir() |
const wxString* mnModel::getWikiDataDir() |
| 327 |
{ |
{ |
| 328 |
return wikiDataDir; |
return wikiDataDir; |
| 351 |
WikiList::Node* node; |
WikiList::Node* node; |
| 352 |
WikiData* data; |
WikiData* data; |
| 353 |
|
|
| 354 |
node = wikiList->GetFirst(); |
if(wikiList == NULL) { |
| 355 |
if(!node) { |
MN_FATAL_ERROR(wxT("wikiList is null")); |
| 356 |
MN_FATAL_ERROR(wxT("Search Result List is empty")); |
return; |
| 357 |
} |
} |
| 358 |
|
|
| 359 |
|
node = wikiList->GetFirst(); |
| 360 |
while(node) { |
while(node) { |
| 361 |
data = node->GetData(); |
data = node->GetData(); |
| 362 |
if(data == addData) return; |
if(data == addData) return; |
| 363 |
if( *(data->getSubject()) == *(addData->getSubject()) ) { |
if( *(data->getSubject()) == *(addData->getOldSubject()) ) { |
| 364 |
if(wikiList->DeleteObject(data)) { |
if(wikiList->DeleteObject(data)) { |
| 365 |
delete data; |
//delete data; /* may be wrong.. */ |
| 366 |
break; |
break; |
| 367 |
} |
} |
| 368 |
else { |
else { |
| 376 |
wikiList->Sort(compWikiData); |
wikiList->Sort(compWikiData); |
| 377 |
} |
} |
| 378 |
|
|
| 379 |
|
bool mnModel::delSearchResultList(wxString* searchStr, WikiData* delData) |
| 380 |
|
{ |
| 381 |
|
WikiList* wikiList = wikiHash[*searchStr]; |
| 382 |
|
WikiList::Node* node; |
| 383 |
|
WikiData* data; |
| 384 |
|
bool found = false; |
| 385 |
|
|
| 386 |
|
if(wikiList == NULL) { |
| 387 |
|
MN_FATAL_ERROR(wxT("wikiList is null")); |
| 388 |
|
return false; |
| 389 |
|
} |
| 390 |
|
|
| 391 |
|
node = wikiList->GetFirst(); |
| 392 |
|
while(node) { |
| 393 |
|
data = node->GetData(); |
| 394 |
|
if(data == delData) { |
| 395 |
|
if(!wikiList->DeleteObject(data)) { |
| 396 |
|
MN_FATAL_ERROR(wxT("Can't find delete data")); |
| 397 |
|
} |
| 398 |
|
found = true; |
| 399 |
|
break; |
| 400 |
|
} |
| 401 |
|
else if( *(data->getSubject()) == *(delData->getOldSubject()) ) { |
| 402 |
|
if(wikiList->DeleteObject(data)) { |
| 403 |
|
//delete data; /* may be wrong.. */ |
| 404 |
|
found = true; |
| 405 |
|
break; |
| 406 |
|
} |
| 407 |
|
else { |
| 408 |
|
MN_FATAL_ERROR(wxT("Can't find delete data")); |
| 409 |
|
} |
| 410 |
|
} |
| 411 |
|
node = node->GetNext(); |
| 412 |
|
} |
| 413 |
|
wikiList->Sort(compWikiData); |
| 414 |
|
return found; |
| 415 |
|
} |
| 416 |
|
|
| 417 |
/******* WikiData ************************/ |
/******* WikiData ************************/ |
| 418 |
WikiData::WikiData(wxString* dataDir, wxString* inFileName) |
WikiData::WikiData(wxString* dataDir, wxString* inFileName) |
| 419 |
{ |
{ |
| 435 |
|
|
| 436 |
text = NULL; |
text = NULL; |
| 437 |
memset(outbuf, 0, MAX_BUF_SIZE); |
memset(outbuf, 0, MAX_BUF_SIZE); |
| 438 |
fileName = new wxString(*inFileName); |
fileName = new wxString(inFileName->mb_str(), conv); |
| 439 |
dataDirName = dataDir; |
dataDirName = new wxString(dataDir->mb_str(), conv); |
| 440 |
decodeStr = decode(fileName->mb_str()); |
decodeStr = decode(fileName->mb_str()); |
| 441 |
inbufSize = strlen(decodeStr); |
inbufSize = strlen(decodeStr); |
| 442 |
outbufSize = sizeof(outbuf); |
outbufSize = sizeof(outbuf); |
| 443 |
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); |
| 444 |
subject = new wxString((const char*)outbuf, conv); |
subject = new wxString((const char*)outbuf, conv); |
| 445 |
|
oldSubject = new wxString((const char*)outbuf, conv); |
| 446 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 447 |
|
|
| 448 |
date = NULL; |
date = NULL; |
| 468 |
char buf[MAX_BUF_SIZE]; |
char buf[MAX_BUF_SIZE]; |
| 469 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 470 |
|
|
| 471 |
dataDirName = dataDir; |
dataDirName = new wxString(dataDir->mb_str(), conv); |
| 472 |
|
|
| 473 |
time(&now); |
time(&now); |
| 474 |
memset(buf, 0, sizeof(buf)); |
memset(buf, 0, sizeof(buf)); |
| 475 |
strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now)); |
strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now)); |
| 476 |
subject = new wxString(buf, conv); |
subject = new wxString(buf, conv); |
| 477 |
|
oldSubject = new wxString(buf, conv); |
| 478 |
|
|
| 479 |
fileName = new wxString(encode(buf), conv); |
fileName = new wxString(encode(buf), conv); |
| 480 |
fileName->Append(wxT(EXT_TAG)); |
fileName->Append(wxT(EXT_TAG)); |
| 492 |
WikiData::~WikiData() |
WikiData::~WikiData() |
| 493 |
{ |
{ |
| 494 |
delete subject; |
delete subject; |
| 495 |
|
delete oldSubject; |
| 496 |
delete fileName; |
delete fileName; |
| 497 |
delete date; |
delete date; |
| 498 |
delete text; |
delete text; |
| 499 |
|
delete dataDirName; |
| 500 |
} |
} |
| 501 |
|
|
| 502 |
const wxString* WikiData::getFileName() |
const wxString* WikiData::getFileName() |
| 509 |
return subject; |
return subject; |
| 510 |
} |
} |
| 511 |
|
|
| 512 |
|
const wxString* WikiData::getOldSubject() |
| 513 |
|
{ |
| 514 |
|
return oldSubject; |
| 515 |
|
} |
| 516 |
|
|
| 517 |
|
void WikiData::setOldSubjectFromCurrent() |
| 518 |
|
{ |
| 519 |
|
oldSubject = new wxString(*subject); |
| 520 |
|
} |
| 521 |
|
|
| 522 |
void WikiData::modSubject(wxString* newSubject) |
void WikiData::modSubject(wxString* newSubject) |
| 523 |
{ |
{ |
| 524 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 525 |
wxString* oldFileName = fileName; |
wxString* oldFileName = fileName; |
|
wxString* oldSubject = subject; |
|
| 526 |
char oldFullPath[MAX_BUF_SIZE]; |
char oldFullPath[MAX_BUF_SIZE]; |
| 527 |
char newFullPath[MAX_BUF_SIZE]; |
char newFullPath[MAX_BUF_SIZE]; |
| 528 |
iconv_t codeSet; |
iconv_t codeSet; |
| 534 |
int outbufSize = sizeof(outbuf); |
int outbufSize = sizeof(outbuf); |
| 535 |
FILE* fp; |
FILE* fp; |
| 536 |
|
|
| 537 |
|
oldSubject = subject; |
| 538 |
|
|
| 539 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 540 |
memset(inbuf, 0, sizeof(inbuf)); |
memset(inbuf, 0, sizeof(inbuf)); |
| 541 |
strcpy(inbuf, (const char*)newSubject->mb_str()); |
strcpy(inbuf, (const char*)newSubject->mb_str()); |
| 564 |
fclose(fp); |
fclose(fp); |
| 565 |
} |
} |
| 566 |
|
|
|
delete oldSubject; |
|
| 567 |
delete oldFileName; |
delete oldFileName; |
| 568 |
} |
} |
| 569 |
|
|
| 629 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 630 |
delete text; |
delete text; |
| 631 |
//text = new wxString(intext->c_str()); |
//text = new wxString(intext->c_str()); |
| 632 |
text = new wxString(*intext); |
//text = new wxString(*intext); |
| 633 |
//text = new wxString(intext->mb_str(), conv); |
text = new wxString(intext->mb_str(), conv); |
| 634 |
} |
} |
| 635 |
|
|
| 636 |
void WikiData::removeDataFile() |
void WikiData::removeDataFile() |
| 679 |
outbufSize = sizeof(outbuf); |
outbufSize = sizeof(outbuf); |
| 680 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 681 |
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); |
| 682 |
|
if(inbufSize != 0) { // iconv error |
| 683 |
|
wxMessageBox(wxT("Fail to save, because this memo include KISHU-IZON-MOJI.\nPlease remove KISHU-IZON-MOJI, and try again"), wxT("Fail to save"), wxOK|wxICON_WARNING); |
| 684 |
|
} |
| 685 |
fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp); |
fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp); |
| 686 |
fclose(fp); |
fclose(fp); |
| 687 |
iconv_close(codeSet); |
iconv_close(codeSet); |