Develop and Download Open Source Software

Browse CVS Repository

Diff of /malonnote/mnModel.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.18 by maloninc, Tue Sep 13 04:22:15 2005 UTC revision 1.19 by maloninc, Tue Sep 13 09:11:37 2005 UTC
# Line 37  WikiList* mnModel::search(const char* se Line 37  WikiList* mnModel::search(const char* se
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;
# Line 88  WikiList* mnModel::search(const char* se Line 87  WikiList* mnModel::search(const char* se
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);
# Line 128  WikiList* mnModel::search(const char* se Line 118  WikiList* mnModel::search(const char* se
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;

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26