| 37 |
wxDir* dir; |
wxDir* dir; |
| 38 |
FILE* fp; |
FILE* fp; |
| 39 |
wxString fullPathName; |
wxString fullPathName; |
|
char buf[MAX_BUF_SIZE]; |
|
| 40 |
WikiData* wikiData; |
WikiData* wikiData; |
| 41 |
WikiList* list = new WikiList(); |
WikiList* list = new WikiList(); |
| 42 |
wxString* fileName = new wxString(); |
wxString* fileName = new wxString(); |
| 43 |
|
const char* decodeFileName; |
| 44 |
|
char decodeFileNameBuf[MAX_BUF_SIZE]; |
| 45 |
iconv_t codeSet; |
iconv_t codeSet; |
| 46 |
char outbuf[MAX_BUF_SIZE]; |
char outbuf[MAX_BUF_SIZE]; |
| 47 |
const char* inbufPtr = searchStr; |
const char* inbufPtr = searchStr; |
| 48 |
char* outbufPtr = outbuf; |
char* outbufPtr = outbuf; |
| 49 |
int inbufSize = strlen(searchStr); |
int inbufSize = strlen(searchStr); |
| 50 |
int outbufSize = sizeof(outbuf); |
int outbufSize = sizeof(outbuf); |
|
const char* decodeFileName; |
|
|
char decodeFileNameBuf[MAX_BUF_SIZE]; |
|
| 51 |
char* token; |
char* token; |
| 52 |
char* tokenList[32]; |
char* tokenList[32]; |
| 53 |
bool found; |
bool found; |
| 63 |
|
|
| 64 |
/* searchStr to Tokens */ |
/* searchStr to Tokens */ |
| 65 |
token = strtok(outbuf, " "); |
token = strtok(outbuf, " "); |
| 66 |
|
if(token == NULL) return list; |
| 67 |
tokenList[0] = (char*)malloc(strlen(token)+1); |
tokenList[0] = (char*)malloc(strlen(token)+1); |
| 68 |
snprintf(tokenList[0], strlen(token)+1, "%s", token); |
snprintf(tokenList[0], strlen(token)+1, "%s", token); |
| 69 |
i = 1; |
i = 1; |
| 87 |
MN_FATAL_ERROR(wxT("fopen faild")); |
MN_FATAL_ERROR(wxT("fopen faild")); |
| 88 |
} |
} |
| 89 |
|
|
| 90 |
while(1){ |
/* TYPE search */ |
| 91 |
memset(buf, 0, MAX_BUF_SIZE); |
if(strstr(tokenList[0], TYPESEARCH_TAG) == tokenList[0]) |
| 92 |
fread(buf, MAX_BUF_SIZE-1, 1, fp); |
{ |
| 93 |
if(buf[0] == 0) break; |
found = typeSearch(tokenList[0], fp); |
| 94 |
|
if(found){ |
| 95 |
|
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
| 96 |
|
list->Append(wikiData); |
| 97 |
|
} |
| 98 |
|
} |
| 99 |
|
/* Normal search */ |
| 100 |
|
else{ |
| 101 |
decodeFileName = decode(fileName->mb_str()); |
decodeFileName = decode(fileName->mb_str()); |
| 102 |
snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName); |
snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName); |
|
toLower(buf); |
|
|
toLower(outbuf); |
|
| 103 |
toLower(decodeFileNameBuf); |
toLower(decodeFileNameBuf); |
| 104 |
found = TRUE; |
found = normalSearch(tokenList, fp, decodeFileNameBuf); |
|
for(i = 0; tokenList[i] != NULL; i++){ |
|
|
if(strstr((const char*)buf, (const char*)tokenList[i]) || |
|
|
strstr((const char*)decodeFileName, (const char*)tokenList[i])) { |
|
|
found = TRUE; |
|
|
} |
|
|
else { |
|
|
found = FALSE; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
| 105 |
if(found){ |
if(found){ |
| 106 |
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp); |
| 107 |
list->Append(wikiData); |
list->Append(wikiData); |
|
break; |
|
| 108 |
} |
} |
|
buf[0] = 0; |
|
| 109 |
} |
} |
| 110 |
fclose(fp); |
fclose(fp); |
| 111 |
cont = dir->GetNext(fileName); |
cont = dir->GetNext(fileName); |
| 118 |
return list; |
return list; |
| 119 |
} |
} |
| 120 |
|
|
| 121 |
|
bool mnModel::normalSearch(char* tokenList[], FILE*fp, char* decodeFileNameBuf) |
| 122 |
|
{ |
| 123 |
|
char buf[MAX_BUF_SIZE]; |
| 124 |
|
bool found; |
| 125 |
|
int i; |
| 126 |
|
while(1){ |
| 127 |
|
memset(buf, 0, MAX_BUF_SIZE); |
| 128 |
|
fread(buf, MAX_BUF_SIZE-1, 1, fp); |
| 129 |
|
if(buf[0] == 0) break; |
| 130 |
|
toLower(buf); |
| 131 |
|
found = TRUE; |
| 132 |
|
for(i = 0; tokenList[i] != NULL; i++){ |
| 133 |
|
toLower(tokenList[i]); |
| 134 |
|
if(strstr((const char*)buf, (const char*)tokenList[i]) || /* search in file context */ |
| 135 |
|
strstr((const char*)decodeFileNameBuf, (const char*)tokenList[i]) || /* search in file name */ |
| 136 |
|
strcmp((const char*)tokenList[i], (const char*)ALLMEMO_TAG) == 0) { /* SHOW ALL MEMO */ |
| 137 |
|
found = TRUE; |
| 138 |
|
} |
| 139 |
|
else { |
| 140 |
|
found = FALSE; |
| 141 |
|
break; |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
if(found){ /* all tokens found */ |
| 146 |
|
break; |
| 147 |
|
} |
| 148 |
|
buf[0] = 0; |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
return found; |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
bool mnModel::typeSearch(char* typeStr, FILE*fp) |
| 155 |
|
{ |
| 156 |
|
char buf[MAX_BUF_SIZE]; |
| 157 |
|
bool found; |
| 158 |
|
int i; |
| 159 |
|
char* typeToken; |
| 160 |
|
char typeStrCopy[MAX_BUF_SIZE]; |
| 161 |
|
|
| 162 |
|
snprintf(typeStrCopy, MAX_BUF_SIZE, "%s", typeStr); |
| 163 |
|
while(1){ |
| 164 |
|
memset(buf, 0, MAX_BUF_SIZE); |
| 165 |
|
fgets(buf, MAX_BUF_SIZE, fp); |
| 166 |
|
if(buf[0] == 0) break; |
| 167 |
|
if(strstr((const char*)buf, TYPE_TAG)){ /* search TYPE line */ |
| 168 |
|
typeToken = strtok(typeStrCopy, ":"); |
| 169 |
|
typeToken = strtok(NULL, ":"); /* second field separated by colon(:) */ |
| 170 |
|
toLower(typeToken); |
| 171 |
|
toLower(buf); |
| 172 |
|
if(strstr(buf, typeToken)) return true; |
| 173 |
|
} |
| 174 |
|
} |
| 175 |
|
return false; |
| 176 |
|
} |
| 177 |
|
|
| 178 |
void mnModel::addSearchStr(wxString* searchStr) |
void mnModel::addSearchStr(wxString* searchStr) |
| 179 |
{ |
{ |
| 180 |
wxString *string; |
wxString *string; |
| 181 |
|
|
| 182 |
if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){ |
if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){ |
| 183 |
string = new wxString(searchStr->c_str()); |
string = new wxString(searchStr->c_str()); |
| 184 |
searchStrList->Add(*string, 1); |
//searchStrList->Add(*string, 1); |
| 185 |
|
searchStrList->Insert(*string, 0); |
| 186 |
} |
} |
| 187 |
} |
} |
| 188 |
|
|
| 337 |
sprintf(newFullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str()); |
sprintf(newFullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str()); |
| 338 |
|
|
| 339 |
if((fp = fopen(newFullPath, "r")) == NULL) { |
if((fp = fopen(newFullPath, "r")) == NULL) { |
| 340 |
rename(oldFullPath, newFullPath); |
if(rename(oldFullPath, newFullPath) < 0) wxLogMessage(wxT("rename error: errno=[%d]"), errno); |
| 341 |
} |
} |
| 342 |
else if(strcmp(oldFullPath, newFullPath)){ |
else if(strcmp(oldFullPath, newFullPath)){ |
| 343 |
wxLogMessage(wxT("File has already exist. [%s]"), fileName->c_str()); |
wxLogMessage(wxT("File has already exist. [%s]"), fileName->c_str()); |
| 344 |
fclose(fp); |
fclose(fp); |
| 345 |
} |
} |
| 346 |
|
else { |
| 347 |
|
fclose(fp); |
| 348 |
|
} |
| 349 |
|
|
| 350 |
delete oldSubject; |
delete oldSubject; |
| 351 |
delete oldFileName; |
delete oldFileName; |
| 389 |
} |
} |
| 390 |
|
|
| 391 |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
while(fgets(buf, MAX_BUF_SIZE, fp)) { |
| 392 |
|
#ifdef __WXMAC__ |
| 393 |
|
for(int i = 0; buf[i] != 0; i++) if(buf[i] == (char)MAC_BACKSLASH) buf[i] = '\\'; |
| 394 |
|
#endif |
| 395 |
inbufPtr = buf; |
inbufPtr = buf; |
| 396 |
inbufSize = sizeof(buf); |
inbufSize = sizeof(buf); |
| 397 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |
| 452 |
|
|
| 453 |
memset(inbuf, 0, sizeof(inbuf)); |
memset(inbuf, 0, sizeof(inbuf)); |
| 454 |
strcpy(inbuf,(const char*)text->mb_str()); |
strcpy(inbuf,(const char*)text->mb_str()); |
| 455 |
|
|
| 456 |
|
#ifdef __WXMAC__ |
| 457 |
|
for(int i = 0; inbuf[i] != 0; i++) if(inbuf[i] == (char)MAC_BACKSLASH) inbuf[i] = '\\'; |
| 458 |
|
#endif |
| 459 |
|
|
| 460 |
inbufPtr = inbuf; |
inbufPtr = inbuf; |
| 461 |
inbufSize = strlen(inbufPtr); |
inbufSize = strlen(inbufPtr); |
| 462 |
outbufPtr = outbuf; |
outbufPtr = outbuf; |