| 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; |
|
|
char buf[MAX_BUF_SIZE]; |
|
|
WikiData* wikiData; |
|
|
WikiList* list = new WikiList(); |
|
|
wxString* fileName = new wxString(); |
|
| 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); |
|
const char* decodeFileName; |
|
|
char decodeFileNameBuf[MAX_BUF_SIZE]; |
|
| 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 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; |
| 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; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
bool mnModel::matchWithToken(wxString* fileName, char* tokenList[]) |
| 74 |
|
{ |
| 75 |
|
const char* decodeFileName; |
| 76 |
|
char decodeFileNameBuf[MAX_BUF_SIZE]; |
| 77 |
|
wxString fullPathName; |
| 78 |
|
FILE* fp; |
| 79 |
|
bool ans = false; |
| 80 |
|
bool found; |
| 81 |
|
|
| 82 |
|
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
| 83 |
|
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
| 84 |
|
if(fp == NULL) { |
| 85 |
|
return false; /* because of removed */ |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
/* TYPE search */ |
| 89 |
|
if(strstr(tokenList[0], TYPESEARCH_TAG) == tokenList[0]) |
| 90 |
|
{ |
| 91 |
|
found = typeSearch(tokenList[0], fp); |
| 92 |
|
if(found){ |
| 93 |
|
ans = true; |
| 94 |
|
} |
| 95 |
|
} |
| 96 |
|
/* Normal search */ |
| 97 |
|
else{ |
| 98 |
|
decodeFileName = decode(fileName->mb_str()); |
| 99 |
|
snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName); |
| 100 |
|
toLower(decodeFileNameBuf); |
| 101 |
|
found = normalSearch(tokenList, fp, decodeFileNameBuf); |
| 102 |
|
if(found){ |
| 103 |
|
ans = true; |
| 104 |
|
} |
| 105 |
|
} |
| 106 |
|
fclose(fp); |
| 107 |
|
|
| 108 |
|
return ans; |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
WikiList* mnModel::search(const char* searchStr) |
| 112 |
|
{ |
| 113 |
|
int i; |
| 114 |
|
wxDir* dir; |
| 115 |
|
WikiData* wikiData; |
| 116 |
|
WikiList* list = new WikiList(); |
| 117 |
|
wxString* fileName = new wxString(); |
| 118 |
|
char* tokenList[MAX_TOKEN]; |
| 119 |
|
|
| 120 |
|
memset(tokenList, 0, sizeof(char*)*MAX_TOKEN); |
| 121 |
|
if( makeSearchToken(searchStr, tokenList) == false) return list; |
| 122 |
|
|
| 123 |
dir = new wxDir(*wikiDataDir); |
dir = new wxDir(*wikiDataDir); |
| 124 |
if ( !dir->IsOpened() ) |
if ( !dir->IsOpened() ) |
| 126 |
MN_FATAL_ERROR(wxT("wxDir has faild\n")); |
MN_FATAL_ERROR(wxT("wxDir has faild\n")); |
| 127 |
return NULL; |
return NULL; |
| 128 |
} |
} |
| 129 |
|
|
| 130 |
|
bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES); |
| 131 |
|
while(cont){ |
| 132 |
|
|
| 133 |
|
if( matchWithToken(fileName, tokenList) ) { /* match with token list */ |
| 134 |
|
wikiData = new WikiData(wikiDataDir, fileName); |
| 135 |
|
list->Append(wikiData); |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
cont = dir->GetNext(fileName); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
delete dir; |
| 142 |
|
delete fileName; |
| 143 |
|
for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]); |
| 144 |
|
|
| 145 |
|
list->Sort(compWikiData); |
| 146 |
|
return list; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
/* |
| 150 |
|
* add malon-type:xxx to search list |
| 151 |
|
*/ |
| 152 |
|
void mnModel::group() |
| 153 |
|
{ |
| 154 |
|
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 155 |
|
char buf[MAX_BUF_SIZE]; |
| 156 |
|
wxDir* dir; |
| 157 |
|
FILE* fp; |
| 158 |
|
wxString* fileName = new wxString(); |
| 159 |
|
wxString fullPathName; |
| 160 |
|
int typeTagLen = strlen(TYPE_TAG); |
| 161 |
|
char* token; |
| 162 |
|
char* inbufPtr; |
| 163 |
|
int inbufSize; |
| 164 |
|
char outbuf[MAX_BUF_SIZE]; |
| 165 |
|
char* outbufPtr = outbuf; |
| 166 |
|
int outbufSize; |
| 167 |
|
wxString* typeToken; |
| 168 |
|
char* ptr; |
| 169 |
|
int i; |
| 170 |
|
|
| 171 |
|
iconv_t codeSet = iconv_open(CODE_SET_SYSTEM, CODE_SET_EUC_JP); |
| 172 |
|
if(codeSet == (iconv_t)-1) { |
| 173 |
|
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
dir = new wxDir(*wikiDataDir); |
| 177 |
|
if ( !dir->IsOpened() ) |
| 178 |
|
{ |
| 179 |
|
MN_FATAL_ERROR(wxT("wxDir has faild\n")); |
| 180 |
|
return ; |
| 181 |
|
} |
| 182 |
bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES); |
bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES); |
| 183 |
while(cont){ |
while(cont){ |
| 184 |
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
fullPathName = *wikiDataDir + wxT("/") + *fileName; |
| 186 |
if(fp == NULL) { |
if(fp == NULL) { |
| 187 |
MN_FATAL_ERROR(wxT("fopen faild")); |
MN_FATAL_ERROR(wxT("fopen faild")); |
| 188 |
} |
} |
| 189 |
|
while(1) { |
| 190 |
while(1){ |
memset(buf, 0, MAX_BUF_SIZE); |
| 191 |
memset(buf, 0, MAX_BUF_SIZE); |
fgets(buf, MAX_BUF_SIZE, fp); |
| 192 |
fread(buf, MAX_BUF_SIZE-1, 1, fp); |
if(buf[0] == 0) break; |
| 193 |
if(buf[0] == 0) break; |
if(strstr(buf, TYPE_TAG)){ |
| 194 |
decodeFileName = decode(fileName->mb_str()); |
ptr = &buf[typeTagLen]; |
| 195 |
snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName); |
while((token = strtok(ptr, " /\r\n:"))!= NULL) { |
| 196 |
toLower(buf); |
memset(outbuf, 0, MAX_BUF_SIZE); |
| 197 |
toLower(decodeFileNameBuf); |
snprintf(outbuf, MAX_BUF_SIZE, "%s", TYPESEARCH_TAG); |
| 198 |
found = TRUE; |
inbufPtr = token; |
| 199 |
for(i = 0; tokenList[i] != NULL; i++){ |
inbufSize = strlen(token); |
| 200 |
toLower(tokenList[i]); |
outbufPtr = &outbuf[strlen(TYPESEARCH_TAG)]; |
| 201 |
if(strstr((const char*)buf, (const char*)tokenList[i]) || |
outbufSize = sizeof(outbuf) - strlen(TYPESEARCH_TAG); |
| 202 |
strstr((const char*)decodeFileName, (const char*)tokenList[i])) { |
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 203 |
found = TRUE; |
|
| 204 |
} |
typeToken = new wxString(outbuf, conv); |
| 205 |
else { |
if( addSearchStr(typeToken) ) { |
| 206 |
found = FALSE; |
WikiList* wikiList = search(typeToken->mb_str()); |
| 207 |
break; |
addSearchList(typeToken, wikiList); |
| 208 |
|
} |
| 209 |
|
delete typeToken; |
| 210 |
|
ptr = NULL; |
| 211 |
} |
} |
| 212 |
} |
} |
|
|
|
|
if(found){ |
|
|
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
|
|
list->Append(wikiData); |
|
|
break; |
|
|
} |
|
|
buf[0] = 0; |
|
| 213 |
} |
} |
| 214 |
fclose(fp); |
fclose(fp); |
| 215 |
cont = dir->GetNext(fileName); |
cont = dir->GetNext(fileName); |
| 216 |
} |
} |
| 217 |
delete dir; |
delete dir; |
| 218 |
delete fileName; |
delete fileName; |
| 219 |
for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]); |
iconv_close(codeSet); |
| 220 |
|
} |
| 221 |
|
|
| 222 |
list->Sort(compWikiData); |
bool mnModel::normalSearch(char* tokenList[], FILE*fp, char* decodeFileNameBuf) |
| 223 |
return list; |
{ |
| 224 |
|
char buf[MAX_BUF_SIZE]; |
| 225 |
|
bool found; |
| 226 |
|
int i; |
| 227 |
|
while(1){ |
| 228 |
|
memset(buf, 0, MAX_BUF_SIZE); |
| 229 |
|
fread(buf, MAX_BUF_SIZE-1, 1, fp); |
| 230 |
|
if(buf[0] == 0) break; |
| 231 |
|
toLower(buf); |
| 232 |
|
found = TRUE; |
| 233 |
|
for(i = 0; tokenList[i] != NULL; i++){ |
| 234 |
|
toLower(tokenList[i]); |
| 235 |
|
if(strstr((const char*)buf, (const char*)tokenList[i]) || /* search in file context */ |
| 236 |
|
strstr((const char*)decodeFileNameBuf, (const char*)tokenList[i]) || /* search in file name */ |
| 237 |
|
strcmp((const char*)tokenList[i], (const char*)ALLMEMO_TAG) == 0) { /* SHOW ALL MEMO */ |
| 238 |
|
found = TRUE; |
| 239 |
|
} |
| 240 |
|
else { |
| 241 |
|
found = FALSE; |
| 242 |
|
break; |
| 243 |
|
} |
| 244 |
|
} |
| 245 |
|
|
| 246 |
|
if(found){ /* all tokens found */ |
| 247 |
|
break; |
| 248 |
|
} |
| 249 |
|
buf[0] = 0; |
| 250 |
|
} |
| 251 |
|
|
| 252 |
|
return found; |
| 253 |
|
} |
| 254 |
|
|
| 255 |
|
bool mnModel::typeSearch(char* typeStr, FILE*fp) |
| 256 |
|
{ |
| 257 |
|
char buf[MAX_BUF_SIZE]; |
| 258 |
|
bool found; |
| 259 |
|
int i; |
| 260 |
|
char* typeToken; |
| 261 |
|
char typeStrCopy[MAX_BUF_SIZE]; |
| 262 |
|
|
| 263 |
|
snprintf(typeStrCopy, MAX_BUF_SIZE, "%s", typeStr); |
| 264 |
|
while(1){ |
| 265 |
|
memset(buf, 0, MAX_BUF_SIZE); |
| 266 |
|
fgets(buf, MAX_BUF_SIZE, fp); |
| 267 |
|
if(buf[0] == 0) break; |
| 268 |
|
if(strstr((const char*)buf, TYPE_TAG)){ /* search TYPE line */ |
| 269 |
|
typeToken = strtok(typeStrCopy, ":"); |
| 270 |
|
typeToken = strtok(NULL, ":"); /* second field separated by colon(:) */ |
| 271 |
|
if(typeToken == NULL) return false; |
| 272 |
|
toLower(typeToken); |
| 273 |
|
toLower(buf); |
| 274 |
|
if(strstr(buf, typeToken)) return true; |
| 275 |
|
} |
| 276 |
|
} |
| 277 |
|
return false; |
| 278 |
} |
} |
| 279 |
|
|
| 280 |
void mnModel::addSearchStr(wxString* searchStr) |
bool mnModel::addSearchStr(wxString* searchStr) |
| 281 |
{ |
{ |
| 282 |
wxString *string; |
wxString *string; |
| 283 |
|
|
| 284 |
if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){ |
if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){ |
| 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); |
| 288 |
|
return true; /* Add */ |
| 289 |
} |
} |
| 290 |
|
return false; /* does'nt add because of duplicating */ |
| 291 |
|
} |
| 292 |
|
|
| 293 |
|
void mnModel::addSearchList(wxString* searchStr, WikiList* list) |
| 294 |
|
{ |
| 295 |
|
wikiHash[*searchStr] = list; |
| 296 |
} |
} |
| 297 |
|
|
| 298 |
void mnModel::removeSearchStr(wxString searchStr) |
void mnModel::removeSearchStr(wxString searchStr) |
| 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; |
| 339 |
|
|
| 340 |
return data; |
return data; |
| 341 |
} |
} |
| 342 |
|
const WikiList* mnModel::getSearchResultList(wxString* searchStr) |
| 343 |
|
{ |
| 344 |
|
return wikiHash[*searchStr]; |
| 345 |
|
} |
| 346 |
|
|
| 347 |
|
/* add "addData's" clone. if already exist same data, overwrite it*/ |
| 348 |
|
void mnModel::addSearchResultList(wxString* searchStr, WikiData* addData) |
| 349 |
|
{ |
| 350 |
|
WikiList* wikiList = wikiHash[*searchStr]; |
| 351 |
|
WikiList::Node* node; |
| 352 |
|
WikiData* data; |
| 353 |
|
|
| 354 |
|
if(wikiList == NULL) { |
| 355 |
|
MN_FATAL_ERROR(wxT("wikiList is null")); |
| 356 |
|
return; |
| 357 |
|
} |
| 358 |
|
|
| 359 |
|
node = wikiList->GetFirst(); |
| 360 |
|
while(node) { |
| 361 |
|
data = node->GetData(); |
| 362 |
|
if(data == addData) return; |
| 363 |
|
if( *(data->getSubject()) == *(addData->getOldSubject()) ) { |
| 364 |
|
if(wikiList->DeleteObject(data)) { |
| 365 |
|
//delete data; /* may be wrong.. */ |
| 366 |
|
break; |
| 367 |
|
} |
| 368 |
|
else { |
| 369 |
|
MN_FATAL_ERROR(wxT("Can't find delete data")); |
| 370 |
|
} |
| 371 |
|
} |
| 372 |
|
node = node->GetNext(); |
| 373 |
|
} |
| 374 |
|
WikiData* copy = new WikiData((wxString*)wikiDataDir, (wxString*)addData->getFileName()); |
| 375 |
|
wikiList->Append(copy); |
| 376 |
|
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, const char* file, FILE* fp) |
WikiData::WikiData(wxString* dataDir, wxString* inFileName) |
| 419 |
{ |
{ |
| 420 |
|
FILE* fp; |
| 421 |
|
wxString fullPathName; |
| 422 |
char* decodeStr; |
char* decodeStr; |
| 423 |
char buf[MAX_BUF_SIZE]; |
char buf[MAX_BUF_SIZE]; |
| 424 |
char* inbuf; |
char* inbuf; |
| 435 |
|
|
| 436 |
text = NULL; |
text = NULL; |
| 437 |
memset(outbuf, 0, MAX_BUF_SIZE); |
memset(outbuf, 0, MAX_BUF_SIZE); |
| 438 |
fileName = new wxString((const char*)file, conv); |
fileName = new wxString(inFileName->mb_str(), conv); |
| 439 |
dataDirName = dataDir; |
dataDirName = new wxString(dataDir->mb_str(), conv); |
| 440 |
decodeStr = decode(file); |
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; |
| 449 |
|
|
| 450 |
rewind(fp); |
fullPathName = *dataDir + wxT("/") + *fileName; |
| 451 |
|
fp = fopen((const char*)fullPathName.mb_str(), "r"); |
| 452 |
|
if(fp == NULL) { |
| 453 |
|
MN_FATAL_ERROR(wxT("fopen faild")); |
| 454 |
|
} |
| 455 |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
| 456 |
if(strstr( (const char*)buf, (const char*)DATE_TAG)) { |
if(strstr( (const char*)buf, (const char*)DATE_TAG)) { |
| 457 |
strtok(buf, "\n"); |
strtok(buf, "\n"); |
| 460 |
break; |
break; |
| 461 |
} |
} |
| 462 |
} |
} |
| 463 |
|
fclose(fp); |
| 464 |
|
|
| 465 |
|
isWriteToFile = true; |
| 466 |
} |
} |
| 467 |
|
|
| 468 |
WikiData::WikiData(wxString* dataDir) { |
WikiData::WikiData(wxString* dataDir) { |
| 469 |
|
FILE* fp; |
| 470 |
time_t now; |
time_t now; |
| 471 |
char buf[MAX_BUF_SIZE]; |
char buf[MAX_BUF_SIZE]; |
| 472 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
char fname[MAX_BUF_SIZE]; |
| 473 |
|
char templateBuf[MAX_BUF_SIZE]; |
| 474 |
|
char* inbufPtr; |
| 475 |
|
int inbufSize; |
| 476 |
|
char outbuf[MAX_BUF_SIZE]; |
| 477 |
|
char* outbufPtr; |
| 478 |
|
int outbufSize; |
| 479 |
|
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 480 |
|
|
| 481 |
dataDirName = dataDir; |
dataDirName = new wxString(dataDir->mb_str(), conv); |
| 482 |
|
|
| 483 |
time(&now); |
time(&now); |
| 484 |
memset(buf, 0, sizeof(buf)); |
memset(buf, 0, sizeof(buf)); |
| 485 |
strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now)); |
strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now)); |
| 486 |
subject = new wxString(buf, conv); |
subject = new wxString(buf, conv); |
| 487 |
|
oldSubject = new wxString(buf, conv); |
| 488 |
|
|
| 489 |
fileName = new wxString(encode(buf), conv); |
fileName = new wxString(encode(buf), conv); |
| 490 |
fileName->Append(wxT(EXT_TAG)); |
fileName->Append(wxT(EXT_TAG)); |
| 492 |
memset(buf, 0, sizeof(buf)); |
memset(buf, 0, sizeof(buf)); |
| 493 |
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)); |
| 494 |
date = new wxString(buf, conv); |
date = new wxString(buf, conv); |
| 495 |
|
|
| 496 |
|
/* try to open template file */ |
| 497 |
|
snprintf(fname, sizeof(fname), "%s/%s", (const char*)(dataDir->mb_str()), NEW_DATA_TEMPLATE); |
| 498 |
|
fp = fopen(fname, "r"); |
| 499 |
|
if(fp == NULL){ |
| 500 |
|
memset(buf, 0, sizeof(buf)); |
| 501 |
|
strftime(buf, sizeof(buf), NEW_DATA,localtime(&now)); |
| 502 |
|
} |
| 503 |
|
else { |
| 504 |
|
memset(buf, 0, sizeof(buf)); |
| 505 |
|
memset(templateBuf, 0, sizeof(templateBuf)); |
| 506 |
|
memset(outbuf, 0, sizeof(outbuf)); |
| 507 |
|
fread(templateBuf, sizeof(templateBuf), 1, fp); |
| 508 |
|
|
| 509 |
memset(buf, 0, sizeof(buf)); |
iconv_t codeSet = iconv_open(CODE_SET_SYSTEM, CODE_SET_EUC_JP); |
| 510 |
strftime(buf, sizeof(buf), NEW_DATA,localtime(&now)); |
if(codeSet == (iconv_t)-1) { |
| 511 |
|
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 512 |
|
} |
| 513 |
|
inbufPtr = templateBuf; |
| 514 |
|
outbufPtr = outbuf; |
| 515 |
|
inbufSize = strlen(templateBuf); |
| 516 |
|
outbufSize = sizeof(outbuf); |
| 517 |
|
iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize); |
| 518 |
|
|
| 519 |
|
strftime(buf, sizeof(buf), outbuf,localtime(&now)); |
| 520 |
|
|
| 521 |
|
} |
| 522 |
text = new wxString(buf, conv); |
text = new wxString(buf, conv); |
| 523 |
|
|
| 524 |
|
if(fp) fclose(fp); |
| 525 |
|
|
| 526 |
|
isWriteToFile = false; |
| 527 |
} |
} |
| 528 |
|
|
| 529 |
WikiData::~WikiData() |
WikiData::~WikiData() |
| 530 |
{ |
{ |
| 531 |
delete subject; |
delete subject; |
| 532 |
|
delete oldSubject; |
| 533 |
delete fileName; |
delete fileName; |
| 534 |
delete date; |
delete date; |
| 535 |
delete text; |
delete text; |
| 536 |
|
delete dataDirName; |
| 537 |
} |
} |
| 538 |
|
|
| 539 |
const wxString* WikiData::getFileName() |
const wxString* WikiData::getFileName() |
| 546 |
return subject; |
return subject; |
| 547 |
} |
} |
| 548 |
|
|
| 549 |
|
const wxString* WikiData::getOldSubject() |
| 550 |
|
{ |
| 551 |
|
return oldSubject; |
| 552 |
|
} |
| 553 |
|
|
| 554 |
|
void WikiData::setOldSubjectFromCurrent() |
| 555 |
|
{ |
| 556 |
|
oldSubject = new wxString(*subject); |
| 557 |
|
} |
| 558 |
|
|
| 559 |
void WikiData::modSubject(wxString* newSubject) |
void WikiData::modSubject(wxString* newSubject) |
| 560 |
{ |
{ |
| 561 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 562 |
wxString* oldFileName = fileName; |
wxString* oldFileName = fileName; |
|
wxString* oldSubject = subject; |
|
| 563 |
char oldFullPath[MAX_BUF_SIZE]; |
char oldFullPath[MAX_BUF_SIZE]; |
| 564 |
char newFullPath[MAX_BUF_SIZE]; |
char newFullPath[MAX_BUF_SIZE]; |
| 565 |
iconv_t codeSet; |
iconv_t codeSet; |
| 571 |
int outbufSize = sizeof(outbuf); |
int outbufSize = sizeof(outbuf); |
| 572 |
FILE* fp; |
FILE* fp; |
| 573 |
|
|
| 574 |
|
oldSubject = subject; |
| 575 |
|
|
| 576 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 577 |
memset(inbuf, 0, sizeof(inbuf)); |
memset(inbuf, 0, sizeof(inbuf)); |
| 578 |
strcpy(inbuf, (const char*)newSubject->mb_str()); |
strcpy(inbuf, (const char*)newSubject->mb_str()); |
| 601 |
fclose(fp); |
fclose(fp); |
| 602 |
} |
} |
| 603 |
|
|
|
delete oldSubject; |
|
| 604 |
delete oldFileName; |
delete oldFileName; |
| 605 |
} |
} |
| 606 |
|
|
| 629 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 630 |
} |
} |
| 631 |
|
|
| 632 |
if(text) { |
if(text && isWriteToFile == true) { |
| 633 |
iconv_close(codeSet); |
delete text; |
| 634 |
|
text = NULL; |
| 635 |
|
} |
| 636 |
|
else if(text && isWriteToFile == false) { |
| 637 |
return text; |
return text; |
| 638 |
} |
} |
| 639 |
|
|
| 645 |
} |
} |
| 646 |
|
|
| 647 |
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 |
|
| 648 |
inbufPtr = buf; |
inbufPtr = buf; |
| 649 |
inbufSize = sizeof(buf); |
inbufSize = sizeof(buf); |
| 650 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 666 |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
wxCSConv conv(wxT(CODE_SET_SYSTEM)); |
| 667 |
delete text; |
delete text; |
| 668 |
//text = new wxString(intext->c_str()); |
//text = new wxString(intext->c_str()); |
| 669 |
text = new wxString(*intext); |
//text = new wxString(*intext); |
| 670 |
//text = new wxString(intext->mb_str(), conv); |
text = new wxString(intext->mb_str(), conv); |
| 671 |
} |
} |
| 672 |
|
|
| 673 |
void WikiData::removeDataFile() |
void WikiData::removeDataFile() |
| 685 |
char fullPath[MAX_BUF_SIZE]; |
char fullPath[MAX_BUF_SIZE]; |
| 686 |
FILE* fp; |
FILE* fp; |
| 687 |
iconv_t codeSet; |
iconv_t codeSet; |
| 688 |
char inbuf[MAX_WIKI_TEXT_SIZE]; |
char* inbuf; |
| 689 |
char outbuf[MAX_WIKI_TEXT_SIZE]; |
char* outbuf; |
| 690 |
const char* inbufPtr; |
const char* inbufPtr; |
| 691 |
char* outbufPtr; |
char* outbufPtr; |
| 692 |
int inbufSize; |
int inbufSize; |
| 693 |
int outbufSize; |
int outbufSize; |
| 694 |
|
|
| 695 |
|
inbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE); |
| 696 |
|
outbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE); |
| 697 |
|
if(inbuf == NULL || outbuf == NULL) { |
| 698 |
|
MN_FATAL_ERROR(wxT("It's too big data. Max size is 5MB.")); |
| 699 |
|
} |
| 700 |
|
|
| 701 |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM); |
| 702 |
if(codeSet == (iconv_t)-1) { |
if(codeSet == (iconv_t)-1) { |
| 703 |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
MN_FATAL_ERROR(wxT("failed iconv_open")); |
| 709 |
MN_FATAL_ERROR(wxT("File open error.")); |
MN_FATAL_ERROR(wxT("File open error.")); |
| 710 |
} |
} |
| 711 |
|
|
| 712 |
memset(inbuf, 0, sizeof(inbuf)); |
memset(inbuf, 0, MAX_WIKI_TEXT_SIZE); |
| 713 |
strcpy(inbuf,(const char*)text->mb_str()); |
strcpy(inbuf,(const char*)text->mb_str()); |
| 714 |
|
|
| 715 |
#ifdef __WXMAC__ |
//#ifdef __WXMAC__ |
| 716 |
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] = '\\'; |
| 717 |
#endif |
//#endif |
| 718 |
|
|
| 719 |
inbufPtr = inbuf; |
inbufPtr = inbuf; |
| 720 |
inbufSize = strlen(inbufPtr); |
inbufSize = strlen(inbufPtr); |
| 721 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 722 |
outbufSize = sizeof(outbuf); |
outbufSize = MAX_WIKI_TEXT_SIZE; |
| 723 |
memset(outbuf, 0, outbufSize); |
memset(outbuf, 0, outbufSize); |
| 724 |
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); |
| 725 |
fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp); |
if(inbufSize != 0) { // iconv error |
| 726 |
|
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); |
| 727 |
|
} |
| 728 |
|
fwrite(outbuf, MAX_WIKI_TEXT_SIZE-outbufSize, 1, fp); |
| 729 |
fclose(fp); |
fclose(fp); |
| 730 |
iconv_close(codeSet); |
iconv_close(codeSet); |
| 731 |
|
|
| 732 |
|
free(inbuf); |
| 733 |
|
free(outbuf); |
| 734 |
|
|
| 735 |
|
isWriteToFile = true; |
| 736 |
} |
} |
| 737 |
|
|
| 738 |
/******* Tools ************************/ |
/******* Tools ************************/ |