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.27 by maloninc, Fri Oct 7 12:49:26 2005 UTC revision 1.33 by maloninc, Fri Oct 20 11:58:52 2006 UTC
# Line 2  Line 2 
2  #include "mnModel.h"  #include "mnModel.h"
3  #include <wx/dir.h>  #include <wx/dir.h>
4  #include <wx/regex.h>  #include <wx/regex.h>
5    #include <wx/progdlg.h>
6  #include <iconv.h>  #include <iconv.h>
7    #include <ctype.h>
8    
9  static void   toLower(char* string);  static void   toLower(char* string);
10  static char*  decode(const char* string);  static char*  decode(const char* string);
# Line 108  bool mnModel::matchWithToken(wxString* f Line 110  bool mnModel::matchWithToken(wxString* f
110          return ans;          return ans;
111  }  }
112    
113    void mnModel::readAll(wxString* title, bool progBarFlag)
114    {
115            int         fileCount = 0;
116            wxDir*      dir;
117            WikiData*   wikiData;
118        wxString*   fileName = new wxString();
119            char*       tokenList[MAX_TOKEN];
120            bool        cont;
121            wxProgressDialog* progBar;
122    
123            memset(tokenList, 0, sizeof(char*)*MAX_TOKEN);
124            tokenList[0] = "";
125    
126            dir = new wxDir(*wikiDataDir);
127        if ( !dir->IsOpened() )
128        {
129                    MN_FATAL_ERROR(wxT("wxDir has faild\n"));
130            return ;
131        }
132      
133            /* count number of files */
134            if (progBarFlag) {
135                    cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES);
136                    while(cont){
137                            fileCount++;
138                            cont = dir->GetNext(fileName);
139                    }
140                    progBar = new wxProgressDialog(wxT("Loading Data"), (wxT("Now loading... ") + *title), fileCount);
141            }
142    
143            fileCount = 0;
144        cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES);
145            while(cont){
146                    fileCount++;
147                    if (progBarFlag) progBar->Update(fileCount);
148                    matchWithToken(fileName, tokenList); /* match with token list, but never match, just read. */
149            cont = dir->GetNext(fileName);
150            }
151    
152            delete progBar;
153            delete dir;
154            delete fileName;
155    }
156    
157  WikiList* mnModel::search(const char* searchStr)  WikiList* mnModel::search(const char* searchStr)
158  {  {
159          int         i;          int         i;
# Line 461  WikiData::WikiData(wxString* dataDir, wx Line 507  WikiData::WikiData(wxString* dataDir, wx
507                  }                  }
508          }          }
509          fclose(fp);          fclose(fp);
510    
511            isWriteToFile = true;
512  }  }
513    
514  WikiData::WikiData(wxString* dataDir) {  WikiData::WikiData(wxString* dataDir) {
# Line 520  WikiData::WikiData(wxString* dataDir) { Line 568  WikiData::WikiData(wxString* dataDir) {
568          text    = new wxString(buf, conv);          text    = new wxString(buf, conv);
569    
570          if(fp) fclose(fp);          if(fp) fclose(fp);
571    
572            isWriteToFile = false;
573  }  }
574    
575  WikiData::~WikiData()  WikiData::~WikiData()
# Line 625  const wxString* WikiData::getText() Line 675  const wxString* WikiData::getText()
675                  MN_FATAL_ERROR(wxT("failed iconv_open"));                  MN_FATAL_ERROR(wxT("failed iconv_open"));
676          }          }
677    
678          if(text) {          if(text && isWriteToFile == true) {
679                  iconv_close(codeSet);                  delete text;
680                    text = NULL;
681            }
682            else if(text && isWriteToFile == false) {
683                  return text;                  return text;
684          }          }
685    
# Line 638  const wxString* WikiData::getText() Line 691  const wxString* WikiData::getText()
691          }          }
692    
693          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  
694                  inbufPtr = buf;                  inbufPtr = buf;
695                  inbufSize = sizeof(buf);                  inbufSize = sizeof(buf);
696                  outbufPtr = outbuf;                  outbufPtr = outbuf;
# Line 681  void WikiData::save() Line 731  void WikiData::save()
731          char fullPath[MAX_BUF_SIZE];          char fullPath[MAX_BUF_SIZE];
732          FILE* fp;          FILE* fp;
733          iconv_t     codeSet;          iconv_t     codeSet;
734          char        inbuf[MAX_WIKI_TEXT_SIZE];          char*        inbuf;
735          char        outbuf[MAX_WIKI_TEXT_SIZE];          char*        outbuf;
736          const char*       inbufPtr;          const char*  inbufPtr;
737          char*       outbufPtr;          char*       outbufPtr;
738          int         inbufSize;          int         inbufSize;
739          int         outbufSize;          int         outbufSize;
740    
741            inbuf  = (char*)malloc(MAX_WIKI_TEXT_SIZE);
742            outbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE);
743            if(inbuf == NULL || outbuf == NULL) {
744                    MN_FATAL_ERROR(wxT("It's too big data. Max size is 5MB."));
745            }
746    
747          codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);          codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);
748          if(codeSet == (iconv_t)-1) {          if(codeSet == (iconv_t)-1) {
749                  MN_FATAL_ERROR(wxT("failed iconv_open"));                  MN_FATAL_ERROR(wxT("failed iconv_open"));
# Line 699  void WikiData::save() Line 755  void WikiData::save()
755                  MN_FATAL_ERROR(wxT("File open error."));                  MN_FATAL_ERROR(wxT("File open error."));
756          }          }
757    
758          memset(inbuf, 0, sizeof(inbuf));          memset(inbuf, 0, MAX_WIKI_TEXT_SIZE);
759          strcpy(inbuf,(const char*)text->mb_str());          strcpy(inbuf,(const char*)text->mb_str());
760    
761  #ifdef __WXMAC__  //#ifdef __WXMAC__
762          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] = '\\';
763  #endif  //#endif
764    
765          inbufPtr = inbuf;          inbufPtr = inbuf;
766          inbufSize = strlen(inbufPtr);          inbufSize = strlen(inbufPtr);
767          outbufPtr = outbuf;          outbufPtr = outbuf;
768          outbufSize = sizeof(outbuf);          outbufSize = MAX_WIKI_TEXT_SIZE;
769          memset(outbuf, 0, outbufSize);          memset(outbuf, 0, outbufSize);
770          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);
771          if(inbufSize != 0) { // iconv error          if(inbufSize != 0) { // iconv error
772                  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);                  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);
773          }          }
774          fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp);          fwrite(outbuf, MAX_WIKI_TEXT_SIZE-outbufSize, 1, fp);
775          fclose(fp);          fclose(fp);
776          iconv_close(codeSet);          iconv_close(codeSet);
777            
778            free(inbuf);
779            free(outbuf);
780            
781            isWriteToFile = true;
782  }  }
783    
784  /******* Tools ************************/  /******* Tools ************************/

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.33

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