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.22 by maloninc, Thu Sep 15 03:02:37 2005 UTC revision 1.23 by maloninc, Thu Sep 15 09:20:48 2005 UTC
# Line 30  mnModel::~mnModel() Line 30  mnModel::~mnModel()
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;  
         WikiData*   wikiData;  
     WikiList*   list = new WikiList();  
     wxString*   fileName = new wxString();  
         const char* decodeFileName;  
         char decodeFileNameBuf[MAX_BUF_SIZE];  
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);
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) {
# Line 63  WikiList* mnModel::search(const char* se Line 57  WikiList* mnModel::search(const char* se
57    
58          /* searchStr to Tokens */          /* searchStr to Tokens */
59          token = strtok(outbuf, " ");          token = strtok(outbuf, " ");
60          if(token == NULL) return list;          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;
# Line 72  WikiList* mnModel::search(const char* se Line 66  WikiList* mnModel::search(const char* se
66                  snprintf(tokenList[i], strlen(token)+1, "%s", token);                  snprintf(tokenList[i], strlen(token)+1, "%s", token);
67                  i++;                  i++;
68          }          }
69            return true;
70    }
71    
72    bool mnModel::matchWithToken(wxString* fileName, char* tokenList[])
73    {
74            const char* decodeFileName;
75            char decodeFileNameBuf[MAX_BUF_SIZE];
76        wxString    fullPathName;
77            FILE*       fp;
78            bool        ans = false;
79            bool        found;
80    
81        fullPathName = *wikiDataDir + wxT("/") + *fileName;
82            fp = fopen((const char*)fullPathName.mb_str(), "r");
83            if(fp == NULL) {
84                    MN_FATAL_ERROR(wxT("fopen faild"));
85            }
86    
87            /* TYPE search */
88            if(strstr(tokenList[0], TYPESEARCH_TAG) == tokenList[0])
89            {
90                    found = typeSearch(tokenList[0], fp);
91                    if(found){
92                            ans = true;
93                    }
94            }
95            /* Normal search */
96            else{
97                    decodeFileName = decode(fileName->mb_str());
98                    snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName);
99                    toLower(decodeFileNameBuf);
100                    found = normalSearch(tokenList, fp, decodeFileNameBuf);
101                    if(found){
102                            ans = true;
103                    }
104            }
105            fclose(fp);
106    
107            return ans;
108    }
109    
110    WikiList* mnModel::search(const char* searchStr)
111    {
112            int         i;
113            wxDir*      dir;
114            WikiData*   wikiData;
115        WikiList*   list = new WikiList();
116        wxString*   fileName = new wxString();
117            char*       tokenList[32];
118    
119            memset(tokenList, 0, sizeof(char*)*32);
120            if( makeSearchToken(searchStr, tokenList) == false) return list;
121    
122          dir = new wxDir(*wikiDataDir);          dir = new wxDir(*wikiDataDir);
123      if ( !dir->IsOpened() )      if ( !dir->IsOpened() )
# Line 79  WikiList* mnModel::search(const char* se Line 125  WikiList* mnModel::search(const char* se
125                  MN_FATAL_ERROR(wxT("wxDir has faild\n"));                  MN_FATAL_ERROR(wxT("wxDir has faild\n"));
126          return NULL;          return NULL;
127      }      }
128    
129      bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES);      bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES);
130          while(cont){          while(cont){
         fullPathName = *wikiDataDir + wxT("/") + *fileName;  
                 fp = fopen((const char*)fullPathName.mb_str(), "r");  
                 if(fp == NULL) {  
                         MN_FATAL_ERROR(wxT("fopen faild"));  
                 }  
131    
132                  /* TYPE search */                  if( matchWithToken(fileName, tokenList) ) { /* match with token list */
133                  if(strstr(tokenList[0], TYPESEARCH_TAG) == tokenList[0])                          wikiData = new WikiData(wikiDataDir, fileName);
134                  {                          list->Append(wikiData);
                         found = typeSearch(tokenList[0], fp);  
                         if(found){  
                                 wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp);  
                                 list->Append(wikiData);  
                         }  
                 }  
                 /* Normal search */  
                 else{  
                         decodeFileName = decode(fileName->mb_str());  
                         snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName);  
                         toLower(decodeFileNameBuf);  
                         found = normalSearch(tokenList, fp, decodeFileNameBuf);  
                         if(found){  
                                 wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp);  
                                 list->Append(wikiData);  
                         }  
135                  }                  }
136                  fclose(fp);  
137          cont = dir->GetNext(fileName);          cont = dir->GetNext(fileName);
138          }          }
139    
140          delete dir;          delete dir;
141          delete fileName;          delete fileName;
142          for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]);          for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]);
# Line 254  void mnModel::addSearchStr(wxString* sea Line 281  void mnModel::addSearchStr(wxString* sea
281          }          }
282  }  }
283    
284    void mnModel::addSearchList(wxString* searchStr, WikiList* list)
285    {
286            wikiHash[*searchStr] = list;
287    }
288    
289  void mnModel::removeSearchStr(wxString searchStr)  void mnModel::removeSearchStr(wxString searchStr)
290  {  {
291          if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) {          if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) {
# Line 286  WikiData* mnModel::newWikiData() Line 318  WikiData* mnModel::newWikiData()
318    
319          return data;          return data;
320  }  }
321    const WikiList* mnModel::getSearchResultList(wxString* searchStr)
322    {
323            return wikiHash[*searchStr];
324    }
325    
326    /* add "addData's" clone. if already exist same data, overwrite it*/
327    void mnModel::addSearchResultList(wxString* searchStr, WikiData* addData)
328    {
329            WikiList* wikiList = wikiHash[*searchStr];
330            WikiList::Node* node;
331            WikiData* data;
332    
333            node = wikiList->GetFirst();
334            if(!node) {
335                    MN_FATAL_ERROR(wxT("Search Result List is empty"));
336            }
337    
338            while(node) {
339                    data = node->GetData();
340                    if(data == addData) return;
341                    if( *(data->getSubject()) == *(addData->getSubject()) ) {
342                            if(wikiList->DeleteObject(data)) {
343                                    delete data;
344                                    break;
345                            }
346                            else {
347                                    MN_FATAL_ERROR(wxT("Can't find delete data"));
348                            }
349                    }
350                    node = node->GetNext();
351            }
352            WikiData* copy = new WikiData((wxString*)wikiDataDir, (wxString*)addData->getFileName());
353            wikiList->Append(copy);
354            wikiList->Sort(compWikiData);
355    }
356    
357  /******* WikiData ************************/  /******* WikiData ************************/
358  WikiData::WikiData(wxString* dataDir, const char* file, FILE* fp)  WikiData::WikiData(wxString* dataDir, wxString* inFileName)
359  {  {
360            FILE* fp;
361        wxString    fullPathName;
362          char* decodeStr;          char* decodeStr;
363          char  buf[MAX_BUF_SIZE];          char  buf[MAX_BUF_SIZE];
364          char* inbuf;          char* inbuf;
# Line 306  WikiData::WikiData(wxString* dataDir, co Line 375  WikiData::WikiData(wxString* dataDir, co
375    
376          text = NULL;          text = NULL;
377          memset(outbuf, 0, MAX_BUF_SIZE);          memset(outbuf, 0, MAX_BUF_SIZE);
378          fileName = new wxString((const char*)file, conv);          fileName = new wxString(*inFileName);
379          dataDirName = dataDir;          dataDirName = dataDir;
380          decodeStr = decode(file);          decodeStr = decode(fileName->mb_str());
381          inbufSize = strlen(decodeStr);          inbufSize = strlen(decodeStr);
382          outbufSize = sizeof(outbuf);          outbufSize = sizeof(outbuf);
383          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);
# Line 317  WikiData::WikiData(wxString* dataDir, co Line 386  WikiData::WikiData(wxString* dataDir, co
386    
387          date     = NULL;          date     = NULL;
388    
389      rewind(fp);      fullPathName = *dataDir + wxT("/") + *fileName;
390            fp = fopen((const char*)fullPathName.mb_str(), "r");
391            if(fp == NULL) {
392                    MN_FATAL_ERROR(wxT("fopen faild"));
393            }
394          while(fgets(buf, MAX_BUF_SIZE, fp)) {          while(fgets(buf, MAX_BUF_SIZE, fp)) {
395                  if(strstr( (const char*)buf, (const char*)DATE_TAG)) {                  if(strstr( (const char*)buf, (const char*)DATE_TAG)) {
396                          strtok(buf, "\n");                          strtok(buf, "\n");
# Line 326  WikiData::WikiData(wxString* dataDir, co Line 399  WikiData::WikiData(wxString* dataDir, co
399                          break;                          break;
400                  }                  }
401          }          }
402            fclose(fp);
403  }  }
404    
405  WikiData::WikiData(wxString* dataDir) {  WikiData::WikiData(wxString* dataDir) {

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23

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