| 2 |
#include "mnModel.h" |
#include "mnModel.h" |
| 3 |
#include <wx/dir.h> |
#include <wx/dir.h> |
| 4 |
#include <wx/regex.h> |
#include <wx/regex.h> |
| 5 |
|
#include <wx/progdlg.h> |
| 6 |
#include <iconv.h> |
#include <iconv.h> |
| 7 |
|
#include <ctype.h> |
| 8 |
|
|
| 9 |
static void toLower(char* string); |
static void toLower(char* string); |
| 10 |
static char* decode(const char* string); |
static char* decode(const char* string); |
| 110 |
return ans; |
return ans; |
| 111 |
} |
} |
| 112 |
|
|
| 113 |
|
void mnModel::readAll(bool progBarFlag) |
| 114 |
|
{ |
| 115 |
|
int fileCount = 0; |
| 116 |
|
wxDir* dir; |
| 117 |
|
WikiData* wikiData; |
| 118 |
|
wxString* fileName = new wxString(); |
| 119 |
|
char* tokenList[MAX_TOKEN]; |
| 120 |
|
bool cont; |
| 121 |
|
wxProgressDialog* progBar = NULL; |
| 122 |
|
|
| 123 |
|
memset(tokenList, 0, sizeof(char*)*MAX_TOKEN); |
| 124 |
|
tokenList[0] = ""; |
| 125 |
|
|
| 126 |
|
dir = new wxDir(*wikiDataDir); |
| 127 |
|
if ( !dir->IsOpened() ) |
| 128 |
|
{ |
| 129 |
|
MN_FATAL_ERROR(wxT("wxDir has faild\n")); |
| 130 |
|
return ; |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
/* count number of files */ |
| 134 |
|
if (progBarFlag) { |
| 135 |
|
cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES); |
| 136 |
|
while(cont){ |
| 137 |
|
fileCount++; |
| 138 |
|
cont = dir->GetNext(fileName); |
| 139 |
|
} |
| 140 |
|
progBar = new wxProgressDialog(wxT("Loading Data"), (wxT("Now loading... ") + *wikiDataDir), fileCount); |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
fileCount = 0; |
| 144 |
|
cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES); |
| 145 |
|
while(cont){ |
| 146 |
|
fileCount++; |
| 147 |
|
if (progBarFlag) progBar->Update(fileCount); |
| 148 |
|
matchWithToken(fileName, tokenList); /* match with token list, but never match, just read. */ |
| 149 |
|
cont = dir->GetNext(fileName); |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
if (progBarFlag) { |
| 153 |
|
delete progBar; |
| 154 |
|
} |
| 155 |
|
delete dir; |
| 156 |
|
delete fileName; |
| 157 |
|
} |
| 158 |
|
|
| 159 |
WikiList* mnModel::search(const char* searchStr) |
WikiList* mnModel::search(const char* searchStr) |
| 160 |
{ |
{ |
| 161 |
int i; |
int i; |
| 509 |
} |
} |
| 510 |
} |
} |
| 511 |
fclose(fp); |
fclose(fp); |
| 512 |
|
|
| 513 |
|
isWriteToFile = true; |
| 514 |
} |
} |
| 515 |
|
|
| 516 |
WikiData::WikiData(wxString* dataDir) { |
WikiData::WikiData(wxString* dataDir) { |
| 570 |
text = new wxString(buf, conv); |
text = new wxString(buf, conv); |
| 571 |
|
|
| 572 |
if(fp) fclose(fp); |
if(fp) fclose(fp); |
| 573 |
|
|
| 574 |
|
isWriteToFile = false; |
| 575 |
} |
} |
| 576 |
|
|
| 577 |
WikiData::~WikiData() |
WikiData::~WikiData() |
| 677 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 678 |
} |
} |
| 679 |
|
|
| 680 |
if(text) { |
if(text && isWriteToFile == true) { |
| 681 |
iconv_close(codeSet); |
delete text; |
| 682 |
|
text = NULL; |
| 683 |
|
} |
| 684 |
|
else if(text && isWriteToFile == false) { |
| 685 |
return text; |
return text; |
| 686 |
} |
} |
| 687 |
|
|
| 733 |
char fullPath[MAX_BUF_SIZE]; |
char fullPath[MAX_BUF_SIZE]; |
| 734 |
FILE* fp; |
FILE* fp; |
| 735 |
iconv_t codeSet; |
iconv_t codeSet; |
| 736 |
char inbuf[MAX_WIKI_TEXT_SIZE]; |
char* inbuf; |
| 737 |
char outbuf[MAX_WIKI_TEXT_SIZE]; |
char* outbuf; |
| 738 |
const char* inbufPtr; |
const char* inbufPtr; |
| 739 |
char* outbufPtr; |
char* outbufPtr; |
| 740 |
int inbufSize; |
int inbufSize; |
| 741 |
int outbufSize; |
int outbufSize; |
| 742 |
|
|
| 743 |
|
inbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE); |
| 744 |
|
outbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE); |
| 745 |
|
if(inbuf == NULL || outbuf == NULL) { |
| 746 |
|
MN_FATAL_ERROR(wxT("It's too big data. Max size is 5MB.")); |
| 747 |
|
} |
| 748 |
|
|
| 749 |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
| 750 |
if(codeSet == (iconv_t)-1) { |
if(codeSet == (iconv_t)-1) { |
| 751 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 757 |
MN_FATAL_ERROR(wxT("File open error.")); |
MN_FATAL_ERROR(wxT("File open error.")); |
| 758 |
} |
} |
| 759 |
|
|
| 760 |
memset(inbuf, 0, sizeof(inbuf)); |
memset(inbuf, 0, MAX_WIKI_TEXT_SIZE); |
| 761 |
strcpy(inbuf,(const char*)text->mb_str()); |
strcpy(inbuf,(const char*)text->mb_str()); |
| 762 |
|
|
| 763 |
//#ifdef __WXMAC__ |
//#ifdef __WXMAC__ |
| 767 |
inbufPtr = inbuf; |
inbufPtr = inbuf; |
| 768 |
inbufSize = strlen(inbufPtr); |
inbufSize = strlen(inbufPtr); |
| 769 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 770 |
outbufSize = sizeof(outbuf); |
outbufSize = MAX_WIKI_TEXT_SIZE; |
| 771 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 772 |
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); |
| 773 |
if(inbufSize != 0) { // iconv error |
if(inbufSize != 0) { // iconv error |
| 774 |
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); |
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); |
| 775 |
} |
} |
| 776 |
fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp); |
fwrite(outbuf, MAX_WIKI_TEXT_SIZE-outbufSize, 1, fp); |
| 777 |
fclose(fp); |
fclose(fp); |
| 778 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 779 |
|
|
| 780 |
|
free(inbuf); |
| 781 |
|
free(outbuf); |
| 782 |
|
|
| 783 |
|
isWriteToFile = true; |
| 784 |
} |
} |
| 785 |
|
|
| 786 |
/******* Tools ************************/ |
/******* Tools ************************/ |