| 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); |
| 109 |
return ans; |
return ans; |
| 110 |
} |
} |
| 111 |
|
|
| 112 |
|
void mnModel::readAll( void ) |
| 113 |
|
{ |
| 114 |
|
int i; |
| 115 |
|
wxDir* dir; |
| 116 |
|
WikiData* wikiData; |
| 117 |
|
wxString* fileName = new wxString(); |
| 118 |
|
char* tokenList[MAX_TOKEN]; |
| 119 |
|
|
| 120 |
|
memset(tokenList, 0, sizeof(char*)*MAX_TOKEN); |
| 121 |
|
tokenList[0] = ""; |
| 122 |
|
|
| 123 |
|
dir = new wxDir(*wikiDataDir); |
| 124 |
|
if ( !dir->IsOpened() ) |
| 125 |
|
{ |
| 126 |
|
MN_FATAL_ERROR(wxT("wxDir has faild\n")); |
| 127 |
|
return ; |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES); |
| 131 |
|
while(cont){ |
| 132 |
|
|
| 133 |
|
matchWithToken(fileName, tokenList); /* match with token list, but never match, just read. */ |
| 134 |
|
|
| 135 |
|
cont = dir->GetNext(fileName); |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
delete dir; |
| 139 |
|
delete fileName; |
| 140 |
|
} |
| 141 |
|
|
| 142 |
WikiList* mnModel::search(const char* searchStr) |
WikiList* mnModel::search(const char* searchStr) |
| 143 |
{ |
{ |
| 144 |
int i; |
int i; |
| 492 |
} |
} |
| 493 |
} |
} |
| 494 |
fclose(fp); |
fclose(fp); |
| 495 |
|
|
| 496 |
|
isWriteToFile = true; |
| 497 |
} |
} |
| 498 |
|
|
| 499 |
WikiData::WikiData(wxString* dataDir) { |
WikiData::WikiData(wxString* dataDir) { |
| 500 |
|
FILE* fp; |
| 501 |
time_t now; |
time_t now; |
| 502 |
char buf[MAX_BUF_SIZE]; |
char buf[MAX_BUF_SIZE]; |
| 503 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
char fname[MAX_BUF_SIZE]; |
| 504 |
|
char templateBuf[MAX_BUF_SIZE]; |
| 505 |
|
char* inbufPtr; |
| 506 |
|
int inbufSize; |
| 507 |
|
char outbuf[MAX_BUF_SIZE]; |
| 508 |
|
char* outbufPtr; |
| 509 |
|
int outbufSize; |
| 510 |
|
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 511 |
|
|
| 512 |
dataDirName = new wxString(dataDir->mb_str(), conv); |
dataDirName = new wxString(dataDir->mb_str(), conv); |
| 513 |
|
|
| 523 |
memset(buf, 0, sizeof(buf)); |
memset(buf, 0, sizeof(buf)); |
| 524 |
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)); |
| 525 |
date = new wxString(buf, conv); |
date = new wxString(buf, conv); |
| 526 |
|
|
| 527 |
|
/* try to open template file */ |
| 528 |
|
snprintf(fname, sizeof(fname), "%s/%s", (const char*)(dataDir->mb_str()), NEW_DATA_TEMPLATE); |
| 529 |
|
fp = fopen(fname, "r"); |
| 530 |
|
if(fp == NULL){ |
| 531 |
|
memset(buf, 0, sizeof(buf)); |
| 532 |
|
strftime(buf, sizeof(buf), NEW_DATA,localtime(&now)); |
| 533 |
|
} |
| 534 |
|
else { |
| 535 |
|
memset(buf, 0, sizeof(buf)); |
| 536 |
|
memset(templateBuf, 0, sizeof(templateBuf)); |
| 537 |
|
memset(outbuf, 0, sizeof(outbuf)); |
| 538 |
|
fread(templateBuf, sizeof(templateBuf), 1, fp); |
| 539 |
|
|
| 540 |
memset(buf, 0, sizeof(buf)); |
iconv_t codeSet = iconv_open(CODE_SET_SYSTEM, CODE_SET_EUC_JP); |
| 541 |
strftime(buf, sizeof(buf), NEW_DATA,localtime(&now)); |
if(codeSet == (iconv_t)-1) { |
| 542 |
|
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 543 |
|
} |
| 544 |
|
inbufPtr = templateBuf; |
| 545 |
|
outbufPtr = outbuf; |
| 546 |
|
inbufSize = strlen(templateBuf); |
| 547 |
|
outbufSize = sizeof(outbuf); |
| 548 |
|
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 549 |
|
|
| 550 |
|
strftime(buf, sizeof(buf), outbuf,localtime(&now)); |
| 551 |
|
|
| 552 |
|
} |
| 553 |
text = new wxString(buf, conv); |
text = new wxString(buf, conv); |
| 554 |
|
|
| 555 |
|
if(fp) fclose(fp); |
| 556 |
|
|
| 557 |
|
isWriteToFile = false; |
| 558 |
} |
} |
| 559 |
|
|
| 560 |
WikiData::~WikiData() |
WikiData::~WikiData() |
| 660 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 661 |
} |
} |
| 662 |
|
|
| 663 |
if(text) { |
if(text && isWriteToFile == true) { |
| 664 |
iconv_close(codeSet); |
delete text; |
| 665 |
|
text = NULL; |
| 666 |
|
} |
| 667 |
|
else if(text && isWriteToFile == false) { |
| 668 |
return text; |
return text; |
| 669 |
} |
} |
| 670 |
|
|
| 676 |
} |
} |
| 677 |
|
|
| 678 |
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 |
|
| 679 |
inbufPtr = buf; |
inbufPtr = buf; |
| 680 |
inbufSize = sizeof(buf); |
inbufSize = sizeof(buf); |
| 681 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 716 |
char fullPath[MAX_BUF_SIZE]; |
char fullPath[MAX_BUF_SIZE]; |
| 717 |
FILE* fp; |
FILE* fp; |
| 718 |
iconv_t codeSet; |
iconv_t codeSet; |
| 719 |
char inbuf[MAX_WIKI_TEXT_SIZE]; |
char* inbuf; |
| 720 |
char outbuf[MAX_WIKI_TEXT_SIZE]; |
char* outbuf; |
| 721 |
const char* inbufPtr; |
const char* inbufPtr; |
| 722 |
char* outbufPtr; |
char* outbufPtr; |
| 723 |
int inbufSize; |
int inbufSize; |
| 724 |
int outbufSize; |
int outbufSize; |
| 725 |
|
|
| 726 |
|
inbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE); |
| 727 |
|
outbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE); |
| 728 |
|
if(inbuf == NULL || outbuf == NULL) { |
| 729 |
|
MN_FATAL_ERROR(wxT("It's too big data. Max size is 5MB.")); |
| 730 |
|
} |
| 731 |
|
|
| 732 |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
| 733 |
if(codeSet == (iconv_t)-1) { |
if(codeSet == (iconv_t)-1) { |
| 734 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 740 |
MN_FATAL_ERROR(wxT("File open error.")); |
MN_FATAL_ERROR(wxT("File open error.")); |
| 741 |
} |
} |
| 742 |
|
|
| 743 |
memset(inbuf, 0, sizeof(inbuf)); |
memset(inbuf, 0, MAX_WIKI_TEXT_SIZE); |
| 744 |
strcpy(inbuf,(const char*)text->mb_str()); |
strcpy(inbuf,(const char*)text->mb_str()); |
| 745 |
|
|
| 746 |
#ifdef __WXMAC__ |
//#ifdef __WXMAC__ |
| 747 |
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] = '\\'; |
| 748 |
#endif |
//#endif |
| 749 |
|
|
| 750 |
inbufPtr = inbuf; |
inbufPtr = inbuf; |
| 751 |
inbufSize = strlen(inbufPtr); |
inbufSize = strlen(inbufPtr); |
| 752 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 753 |
outbufSize = sizeof(outbuf); |
outbufSize = MAX_WIKI_TEXT_SIZE; |
| 754 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 755 |
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); |
| 756 |
fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp); |
if(inbufSize != 0) { // iconv error |
| 757 |
|
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); |
| 758 |
|
} |
| 759 |
|
fwrite(outbuf, MAX_WIKI_TEXT_SIZE-outbufSize, 1, fp); |
| 760 |
fclose(fp); |
fclose(fp); |
| 761 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 762 |
|
|
| 763 |
|
free(inbuf); |
| 764 |
|
free(outbuf); |
| 765 |
|
|
| 766 |
|
isWriteToFile = true; |
| 767 |
} |
} |
| 768 |
|
|
| 769 |
/******* Tools ************************/ |
/******* Tools ************************/ |