| 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; |
| 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); |
|
| 103 |
toLower(decodeFileNameBuf); |
toLower(decodeFileNameBuf); |
| 104 |
found = TRUE; |
found = normalSearch(tokenList, fp, decodeFileNameBuf); |
|
for(i = 0; tokenList[i] != NULL; i++){ |
|
|
toLower(tokenList[i]); |
|
|
if(strstr((const char*)buf, (const char*)tokenList[i]) || |
|
|
strstr((const char*)decodeFileNameBuf, (const char*)tokenList[i]) || |
|
|
strcmp((const char*)tokenList[i], (const char*)ALLMEMO_TAG) == 0) { |
|
|
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; |