| 3 |
#include <wx/dir.h> |
#include <wx/dir.h> |
| 4 |
#include <wx/regex.h> |
#include <wx/regex.h> |
| 5 |
#include <iconv.h> |
#include <iconv.h> |
| 6 |
|
#include <ctype.h> |
| 7 |
|
|
| 8 |
static void toLower(char* string); |
static void toLower(char* string); |
| 9 |
static char* decode(const char* string); |
static char* decode(const char* string); |
| 66 |
tokenList[i] = (char*)malloc(strlen(token)+1); |
tokenList[i] = (char*)malloc(strlen(token)+1); |
| 67 |
snprintf(tokenList[i], strlen(token)+1, "%s", token); |
snprintf(tokenList[i], strlen(token)+1, "%s", token); |
| 68 |
i++; |
i++; |
| 69 |
|
if(i >= MAX_TOKEN) break; |
| 70 |
} |
} |
| 71 |
return true; |
return true; |
| 72 |
} |
} |
| 83 |
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
| 84 |
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
| 85 |
if(fp == NULL) { |
if(fp == NULL) { |
| 86 |
MN_FATAL_ERROR(wxT("fopen faild")); |
return false; /* because of removed */ |
| 87 |
} |
} |
| 88 |
|
|
| 89 |
/* TYPE search */ |
/* TYPE search */ |
| 116 |
WikiData* wikiData; |
WikiData* wikiData; |
| 117 |
WikiList* list = new WikiList(); |
WikiList* list = new WikiList(); |
| 118 |
wxString* fileName = new wxString(); |
wxString* fileName = new wxString(); |
| 119 |
char* tokenList[32]; |
char* tokenList[MAX_TOKEN]; |
| 120 |
|
|
| 121 |
memset(tokenList, 0, sizeof(char*)*32); |
memset(tokenList, 0, sizeof(char*)*MAX_TOKEN); |
| 122 |
if( makeSearchToken(searchStr, tokenList) == false) return list; |
if( makeSearchToken(searchStr, tokenList) == false) return list; |
| 123 |
|
|
| 124 |
dir = new wxDir(*wikiDataDir); |
dir = new wxDir(*wikiDataDir); |
| 147 |
return list; |
return list; |
| 148 |
} |
} |
| 149 |
|
|
| 150 |
|
/* |
| 151 |
|
* add malon-type:xxx to search list |
| 152 |
|
*/ |
| 153 |
void mnModel::group() |
void mnModel::group() |
| 154 |
{ |
{ |
| 155 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 203 |
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); |
| 204 |
|
|
| 205 |
typeToken = new wxString(outbuf, conv); |
typeToken = new wxString(outbuf, conv); |
| 206 |
addSearchStr(typeToken); |
if( addSearchStr(typeToken) ) { |
| 207 |
|
WikiList* wikiList = search(typeToken->mb_str()); |
| 208 |
|
addSearchList(typeToken, wikiList); |
| 209 |
|
} |
| 210 |
delete typeToken; |
delete typeToken; |
| 211 |
ptr = NULL; |
ptr = NULL; |
| 212 |
} |
} |
| 278 |
return false; |
return false; |
| 279 |
} |
} |
| 280 |
|
|
| 281 |
void mnModel::addSearchStr(wxString* searchStr) |
bool mnModel::addSearchStr(wxString* searchStr) |
| 282 |
{ |
{ |
| 283 |
wxString *string; |
wxString *string; |
| 284 |
|
|
| 286 |
string = new wxString(searchStr->c_str()); |
string = new wxString(searchStr->c_str()); |
| 287 |
searchStrList->Add(*string, 1); |
searchStrList->Add(*string, 1); |
| 288 |
//searchStrList->Insert(*string, 0); |
//searchStrList->Insert(*string, 0); |
| 289 |
|
return true; /* Add */ |
| 290 |
} |
} |
| 291 |
|
return false; /* does'nt add because of duplicating */ |
| 292 |
} |
} |
| 293 |
|
|
| 294 |
void mnModel::addSearchList(wxString* searchStr, WikiList* list) |
void mnModel::addSearchList(wxString* searchStr, WikiList* list) |
| 300 |
{ |
{ |
| 301 |
if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) { |
if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) { |
| 302 |
searchStrList->Remove(searchStr.c_str()); |
searchStrList->Remove(searchStr.c_str()); |
| 303 |
|
wikiHash[*searchStr] = NULL; |
| 304 |
} |
} |
| 305 |
} |
} |
| 306 |
|
|
| 313 |
itemStr.sprintf(wxT("%s"), newStr->c_str()); |
itemStr.sprintf(wxT("%s"), newStr->c_str()); |
| 314 |
} |
} |
| 315 |
} |
} |
| 316 |
|
|
| 317 |
|
void mnModel::clearSearchStrList() |
| 318 |
|
{ |
| 319 |
|
searchStrList->Clear(); |
| 320 |
|
} |
| 321 |
|
|
| 322 |
|
void mnModel::clearSearchResultList() |
| 323 |
|
{ |
| 324 |
|
wikiHash.clear(); |
| 325 |
|
} |
| 326 |
|
|
| 327 |
const wxString* mnModel::getWikiDataDir() |
const wxString* mnModel::getWikiDataDir() |
| 328 |
{ |
{ |
| 329 |
return wikiDataDir; |
return wikiDataDir; |
| 352 |
WikiList::Node* node; |
WikiList::Node* node; |
| 353 |
WikiData* data; |
WikiData* data; |
| 354 |
|
|
| 355 |
node = wikiList->GetFirst(); |
if(wikiList == NULL) { |
| 356 |
if(!node) { |
MN_FATAL_ERROR(wxT("wikiList is null")); |
| 357 |
MN_FATAL_ERROR(wxT("Search Result List is empty")); |
return; |
| 358 |
} |
} |
| 359 |
|
|
| 360 |
|
node = wikiList->GetFirst(); |
| 361 |
while(node) { |
while(node) { |
| 362 |
data = node->GetData(); |
data = node->GetData(); |
| 363 |
if(data == addData) return; |
if(data == addData) return; |
| 364 |
if( *(data->getSubject()) == *(addData->getSubject()) ) { |
if( *(data->getSubject()) == *(addData->getOldSubject()) ) { |
| 365 |
if(wikiList->DeleteObject(data)) { |
if(wikiList->DeleteObject(data)) { |
| 366 |
delete data; |
//delete data; /* may be wrong.. */ |
| 367 |
break; |
break; |
| 368 |
} |
} |
| 369 |
else { |
else { |
| 377 |
wikiList->Sort(compWikiData); |
wikiList->Sort(compWikiData); |
| 378 |
} |
} |
| 379 |
|
|
| 380 |
|
bool mnModel::delSearchResultList(wxString* searchStr, WikiData* delData) |
| 381 |
|
{ |
| 382 |
|
WikiList* wikiList = wikiHash[*searchStr]; |
| 383 |
|
WikiList::Node* node; |
| 384 |
|
WikiData* data; |
| 385 |
|
bool found = false; |
| 386 |
|
|
| 387 |
|
if(wikiList == NULL) { |
| 388 |
|
MN_FATAL_ERROR(wxT("wikiList is null")); |
| 389 |
|
return false; |
| 390 |
|
} |
| 391 |
|
|
| 392 |
|
node = wikiList->GetFirst(); |
| 393 |
|
while(node) { |
| 394 |
|
data = node->GetData(); |
| 395 |
|
if(data == delData) { |
| 396 |
|
if(!wikiList->DeleteObject(data)) { |
| 397 |
|
MN_FATAL_ERROR(wxT("Can't find delete data")); |
| 398 |
|
} |
| 399 |
|
found = true; |
| 400 |
|
break; |
| 401 |
|
} |
| 402 |
|
else if( *(data->getSubject()) == *(delData->getOldSubject()) ) { |
| 403 |
|
if(wikiList->DeleteObject(data)) { |
| 404 |
|
//delete data; /* may be wrong.. */ |
| 405 |
|
found = true; |
| 406 |
|
break; |
| 407 |
|
} |
| 408 |
|
else { |
| 409 |
|
MN_FATAL_ERROR(wxT("Can't find delete data")); |
| 410 |
|
} |
| 411 |
|
} |
| 412 |
|
node = node->GetNext(); |
| 413 |
|
} |
| 414 |
|
wikiList->Sort(compWikiData); |
| 415 |
|
return found; |
| 416 |
|
} |
| 417 |
|
|
| 418 |
/******* WikiData ************************/ |
/******* WikiData ************************/ |
| 419 |
WikiData::WikiData(wxString* dataDir, wxString* inFileName) |
WikiData::WikiData(wxString* dataDir, wxString* inFileName) |
| 420 |
{ |
{ |
| 436 |
|
|
| 437 |
text = NULL; |
text = NULL; |
| 438 |
memset(outbuf, 0, MAX_BUF_SIZE); |
memset(outbuf, 0, MAX_BUF_SIZE); |
| 439 |
fileName = new wxString(*inFileName); |
fileName = new wxString(inFileName->mb_str(), conv); |
| 440 |
dataDirName = dataDir; |
dataDirName = new wxString(dataDir->mb_str(), conv); |
| 441 |
decodeStr = decode(fileName->mb_str()); |
decodeStr = decode(fileName->mb_str()); |
| 442 |
inbufSize = strlen(decodeStr); |
inbufSize = strlen(decodeStr); |
| 443 |
outbufSize = sizeof(outbuf); |
outbufSize = sizeof(outbuf); |
| 444 |
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); |
| 445 |
subject = new wxString((const char*)outbuf, conv); |
subject = new wxString((const char*)outbuf, conv); |
| 446 |
|
oldSubject = new wxString((const char*)outbuf, conv); |
| 447 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 448 |
|
|
| 449 |
date = NULL; |
date = NULL; |
| 462 |
} |
} |
| 463 |
} |
} |
| 464 |
fclose(fp); |
fclose(fp); |
| 465 |
|
|
| 466 |
|
isWriteToFile = true; |
| 467 |
} |
} |
| 468 |
|
|
| 469 |
WikiData::WikiData(wxString* dataDir) { |
WikiData::WikiData(wxString* dataDir) { |
| 470 |
|
FILE* fp; |
| 471 |
time_t now; |
time_t now; |
| 472 |
char buf[MAX_BUF_SIZE]; |
char buf[MAX_BUF_SIZE]; |
| 473 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
char fname[MAX_BUF_SIZE]; |
| 474 |
|
char templateBuf[MAX_BUF_SIZE]; |
| 475 |
|
char* inbufPtr; |
| 476 |
|
int inbufSize; |
| 477 |
|
char outbuf[MAX_BUF_SIZE]; |
| 478 |
|
char* outbufPtr; |
| 479 |
|
int outbufSize; |
| 480 |
|
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 481 |
|
|
| 482 |
dataDirName = dataDir; |
dataDirName = new wxString(dataDir->mb_str(), conv); |
| 483 |
|
|
| 484 |
time(&now); |
time(&now); |
| 485 |
memset(buf, 0, sizeof(buf)); |
memset(buf, 0, sizeof(buf)); |
| 486 |
strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now)); |
strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now)); |
| 487 |
subject = new wxString(buf, conv); |
subject = new wxString(buf, conv); |
| 488 |
|
oldSubject = new wxString(buf, conv); |
| 489 |
|
|
| 490 |
fileName = new wxString(encode(buf), conv); |
fileName = new wxString(encode(buf), conv); |
| 491 |
fileName->Append(wxT(EXT_TAG)); |
fileName->Append(wxT(EXT_TAG)); |
| 493 |
memset(buf, 0, sizeof(buf)); |
memset(buf, 0, sizeof(buf)); |
| 494 |
strftime(buf, sizeof(buf), DATE_TAG "%Y/%m/%d %H:%M:%S",localtime(&now)); |
strftime(buf, sizeof(buf), DATE_TAG "%Y/%m/%d %H:%M:%S",localtime(&now)); |
| 495 |
date = new wxString(buf, conv); |
date = new wxString(buf, conv); |
| 496 |
|
|
| 497 |
|
/* try to open template file */ |
| 498 |
|
snprintf(fname, sizeof(fname), "%s/%s", (const char*)(dataDir->mb_str()), NEW_DATA_TEMPLATE); |
| 499 |
|
fp = fopen(fname, "r"); |
| 500 |
|
if(fp == NULL){ |
| 501 |
|
memset(buf, 0, sizeof(buf)); |
| 502 |
|
strftime(buf, sizeof(buf), NEW_DATA,localtime(&now)); |
| 503 |
|
} |
| 504 |
|
else { |
| 505 |
|
memset(buf, 0, sizeof(buf)); |
| 506 |
|
memset(templateBuf, 0, sizeof(templateBuf)); |
| 507 |
|
memset(outbuf, 0, sizeof(outbuf)); |
| 508 |
|
fread(templateBuf, sizeof(templateBuf), 1, fp); |
| 509 |
|
|
| 510 |
memset(buf, 0, sizeof(buf)); |
iconv_t codeSet = iconv_open(CODE_SET_SYSTEM, CODE_SET_EUC_JP); |
| 511 |
strftime(buf, sizeof(buf), NEW_DATA,localtime(&now)); |
if(codeSet == (iconv_t)-1) { |
| 512 |
|
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 513 |
|
} |
| 514 |
|
inbufPtr = templateBuf; |
| 515 |
|
outbufPtr = outbuf; |
| 516 |
|
inbufSize = strlen(templateBuf); |
| 517 |
|
outbufSize = sizeof(outbuf); |
| 518 |
|
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 519 |
|
|
| 520 |
|
strftime(buf, sizeof(buf), outbuf,localtime(&now)); |
| 521 |
|
|
| 522 |
|
} |
| 523 |
text = new wxString(buf, conv); |
text = new wxString(buf, conv); |
| 524 |
|
|
| 525 |
|
if(fp) fclose(fp); |
| 526 |
|
|
| 527 |
|
isWriteToFile = false; |
| 528 |
} |
} |
| 529 |
|
|
| 530 |
WikiData::~WikiData() |
WikiData::~WikiData() |
| 531 |
{ |
{ |
| 532 |
delete subject; |
delete subject; |
| 533 |
|
delete oldSubject; |
| 534 |
delete fileName; |
delete fileName; |
| 535 |
delete date; |
delete date; |
| 536 |
delete text; |
delete text; |
| 537 |
|
delete dataDirName; |
| 538 |
} |
} |
| 539 |
|
|
| 540 |
const wxString* WikiData::getFileName() |
const wxString* WikiData::getFileName() |
| 547 |
return subject; |
return subject; |
| 548 |
} |
} |
| 549 |
|
|
| 550 |
|
const wxString* WikiData::getOldSubject() |
| 551 |
|
{ |
| 552 |
|
return oldSubject; |
| 553 |
|
} |
| 554 |
|
|
| 555 |
|
void WikiData::setOldSubjectFromCurrent() |
| 556 |
|
{ |
| 557 |
|
oldSubject = new wxString(*subject); |
| 558 |
|
} |
| 559 |
|
|
| 560 |
void WikiData::modSubject(wxString* newSubject) |
void WikiData::modSubject(wxString* newSubject) |
| 561 |
{ |
{ |
| 562 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 563 |
wxString* oldFileName = fileName; |
wxString* oldFileName = fileName; |
|
wxString* oldSubject = subject; |
|
| 564 |
char oldFullPath[MAX_BUF_SIZE]; |
char oldFullPath[MAX_BUF_SIZE]; |
| 565 |
char newFullPath[MAX_BUF_SIZE]; |
char newFullPath[MAX_BUF_SIZE]; |
| 566 |
iconv_t codeSet; |
iconv_t codeSet; |
| 572 |
int outbufSize = sizeof(outbuf); |
int outbufSize = sizeof(outbuf); |
| 573 |
FILE* fp; |
FILE* fp; |
| 574 |
|
|
| 575 |
|
oldSubject = subject; |
| 576 |
|
|
| 577 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 578 |
memset(inbuf, 0, sizeof(inbuf)); |
memset(inbuf, 0, sizeof(inbuf)); |
| 579 |
strcpy(inbuf, (const char*)newSubject->mb_str()); |
strcpy(inbuf, (const char*)newSubject->mb_str()); |
| 602 |
fclose(fp); |
fclose(fp); |
| 603 |
} |
} |
| 604 |
|
|
|
delete oldSubject; |
|
| 605 |
delete oldFileName; |
delete oldFileName; |
| 606 |
} |
} |
| 607 |
|
|
| 630 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 631 |
} |
} |
| 632 |
|
|
| 633 |
if(text) { |
if(text && isWriteToFile == true) { |
| 634 |
iconv_close(codeSet); |
delete text; |
| 635 |
|
text = NULL; |
| 636 |
|
} |
| 637 |
|
else if(text && isWriteToFile == false) { |
| 638 |
return text; |
return text; |
| 639 |
} |
} |
| 640 |
|
|
| 646 |
} |
} |
| 647 |
|
|
| 648 |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
|
#ifdef __WXMAC__ |
|
|
for(int i = 0; buf[i] != 0; i++) if(buf[i] == (char)MAC_BACKSLASH) buf[i] = '\\'; |
|
|
#endif |
|
| 649 |
inbufPtr = buf; |
inbufPtr = buf; |
| 650 |
inbufSize = sizeof(buf); |
inbufSize = sizeof(buf); |
| 651 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 667 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 668 |
delete text; |
delete text; |
| 669 |
//text = new wxString(intext->c_str()); |
//text = new wxString(intext->c_str()); |
| 670 |
text = new wxString(*intext); |
//text = new wxString(*intext); |
| 671 |
//text = new wxString(intext->mb_str(), conv); |
text = new wxString(intext->mb_str(), conv); |
| 672 |
} |
} |
| 673 |
|
|
| 674 |
void WikiData::removeDataFile() |
void WikiData::removeDataFile() |
| 686 |
char fullPath[MAX_BUF_SIZE]; |
char fullPath[MAX_BUF_SIZE]; |
| 687 |
FILE* fp; |
FILE* fp; |
| 688 |
iconv_t codeSet; |
iconv_t codeSet; |
| 689 |
char inbuf[MAX_WIKI_TEXT_SIZE]; |
char* inbuf; |
| 690 |
char outbuf[MAX_WIKI_TEXT_SIZE]; |
char* outbuf; |
| 691 |
const char* inbufPtr; |
const char* inbufPtr; |
| 692 |
char* outbufPtr; |
char* outbufPtr; |
| 693 |
int inbufSize; |
int inbufSize; |
| 694 |
int outbufSize; |
int outbufSize; |
| 695 |
|
|
| 696 |
|
inbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE); |
| 697 |
|
outbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE); |
| 698 |
|
if(inbuf == NULL || outbuf == NULL) { |
| 699 |
|
MN_FATAL_ERROR(wxT("It's too big data. Max size is 5MB.")); |
| 700 |
|
} |
| 701 |
|
|
| 702 |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
| 703 |
if(codeSet == (iconv_t)-1) { |
if(codeSet == (iconv_t)-1) { |
| 704 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 710 |
MN_FATAL_ERROR(wxT("File open error.")); |
MN_FATAL_ERROR(wxT("File open error.")); |
| 711 |
} |
} |
| 712 |
|
|
| 713 |
memset(inbuf, 0, sizeof(inbuf)); |
memset(inbuf, 0, MAX_WIKI_TEXT_SIZE); |
| 714 |
strcpy(inbuf,(const char*)text->mb_str()); |
strcpy(inbuf,(const char*)text->mb_str()); |
| 715 |
|
|
| 716 |
#ifdef __WXMAC__ |
//#ifdef __WXMAC__ |
| 717 |
for(int i = 0; inbuf[i] != 0; i++) if(inbuf[i] == (char)MAC_BACKSLASH) inbuf[i] = '\\'; |
// for(int i = 0; inbuf[i] != 0; i++) if(inbuf[i] == (char)MAC_BACKSLASH) inbuf[i] = '\\'; |
| 718 |
#endif |
//#endif |
| 719 |
|
|
| 720 |
inbufPtr = inbuf; |
inbufPtr = inbuf; |
| 721 |
inbufSize = strlen(inbufPtr); |
inbufSize = strlen(inbufPtr); |
| 722 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 723 |
outbufSize = sizeof(outbuf); |
outbufSize = MAX_WIKI_TEXT_SIZE; |
| 724 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 725 |
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); |
| 726 |
fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp); |
if(inbufSize != 0) { // iconv error |
| 727 |
|
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); |
| 728 |
|
} |
| 729 |
|
fwrite(outbuf, MAX_WIKI_TEXT_SIZE-outbufSize, 1, fp); |
| 730 |
fclose(fp); |
fclose(fp); |
| 731 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 732 |
|
|
| 733 |
|
free(inbuf); |
| 734 |
|
free(outbuf); |
| 735 |
|
|
| 736 |
|
isWriteToFile = true; |
| 737 |
} |
} |
| 738 |
|
|
| 739 |
/******* Tools ************************/ |
/******* Tools ************************/ |