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.28 by maloninc, Thu Dec 22 10:48:29 2005 UTC revision 1.32 by maloninc, Fri Oct 20 09:36:08 2006 UTC
# Line 3  Line 3 
3  #include <wx/dir.h>  #include <wx/dir.h>
4  #include <wx/regex.h>  #include <wx/regex.h>
5  #include <iconv.h>  #include <iconv.h>
6    #include <ctype.h>
7    
8  static void   toLower(char* string);  static void   toLower(char* string);
9  static char*  decode(const char* string);  static char*  decode(const char* string);
# Line 108  bool mnModel::matchWithToken(wxString* f Line 109  bool mnModel::matchWithToken(wxString* f
109          return ans;          return ans;
110  }  }
111    
112    void mnModel::readAll( void )
113    {
114            int         i;
115            wxDir*      dir;
116            WikiData*   wikiData;
117        wxString*   fileName = new wxString();
118            char*       tokenList[MAX_TOKEN];
119    
120            memset(tokenList, 0, sizeof(char*)*MAX_TOKEN);
121            tokenList[0] = "";
122    
123            dir = new wxDir(*wikiDataDir);
124        if ( !dir->IsOpened() )
125        {
126                    MN_FATAL_ERROR(wxT("wxDir has faild\n"));
127            return ;
128        }
129    
130        bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES);
131            while(cont){
132    
133                    matchWithToken(fileName, tokenList); /* match with token list, but never match, just read. */
134    
135            cont = dir->GetNext(fileName);
136            }
137    
138            delete dir;
139            delete fileName;
140    }
141    
142  WikiList* mnModel::search(const char* searchStr)  WikiList* mnModel::search(const char* searchStr)
143  {  {
144          int         i;          int         i;
# Line 461  WikiData::WikiData(wxString* dataDir, wx Line 492  WikiData::WikiData(wxString* dataDir, wx
492                  }                  }
493          }          }
494          fclose(fp);          fclose(fp);
495    
496            isWriteToFile = true;
497  }  }
498    
499  WikiData::WikiData(wxString* dataDir) {  WikiData::WikiData(wxString* dataDir) {
# Line 520  WikiData::WikiData(wxString* dataDir) { Line 553  WikiData::WikiData(wxString* dataDir) {
553          text    = new wxString(buf, conv);          text    = new wxString(buf, conv);
554    
555          if(fp) fclose(fp);          if(fp) fclose(fp);
556    
557            isWriteToFile = false;
558  }  }
559    
560  WikiData::~WikiData()  WikiData::~WikiData()
# Line 625  const wxString* WikiData::getText() Line 660  const wxString* WikiData::getText()
660                  MN_FATAL_ERROR(wxT("failed iconv_open"));                  MN_FATAL_ERROR(wxT("failed iconv_open"));
661          }          }
662    
663          if(text) {          if(text && isWriteToFile == true) {
664                  iconv_close(codeSet);                  delete text;
665                    text = NULL;
666            }
667            else if(text && isWriteToFile == false) {
668                  return text;                  return text;
669          }          }
670    
# Line 678  void WikiData::save() Line 716  void WikiData::save()
716          char fullPath[MAX_BUF_SIZE];          char fullPath[MAX_BUF_SIZE];
717          FILE* fp;          FILE* fp;
718          iconv_t     codeSet;          iconv_t     codeSet;
719          char        inbuf[MAX_WIKI_TEXT_SIZE];          char*        inbuf;
720          char        outbuf[MAX_WIKI_TEXT_SIZE];          char*        outbuf;
721          const char*       inbufPtr;          const char*  inbufPtr;
722          char*       outbufPtr;          char*       outbufPtr;
723          int         inbufSize;          int         inbufSize;
724          int         outbufSize;          int         outbufSize;
725    
726            inbuf  = (char*)malloc(MAX_WIKI_TEXT_SIZE);
727            outbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE);
728            if(inbuf == NULL || outbuf == NULL) {
729                    MN_FATAL_ERROR(wxT("It's too big data. Max size is 5MB."));
730            }
731    
732          codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);          codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);
733          if(codeSet == (iconv_t)-1) {          if(codeSet == (iconv_t)-1) {
734                  MN_FATAL_ERROR(wxT("failed iconv_open"));                  MN_FATAL_ERROR(wxT("failed iconv_open"));
# Line 696  void WikiData::save() Line 740  void WikiData::save()
740                  MN_FATAL_ERROR(wxT("File open error."));                  MN_FATAL_ERROR(wxT("File open error."));
741          }          }
742    
743          memset(inbuf, 0, sizeof(inbuf));          memset(inbuf, 0, MAX_WIKI_TEXT_SIZE);
744          strcpy(inbuf,(const char*)text->mb_str());          strcpy(inbuf,(const char*)text->mb_str());
745    
746  //#ifdef __WXMAC__  //#ifdef __WXMAC__
# Line 706  void WikiData::save() Line 750  void WikiData::save()
750          inbufPtr = inbuf;          inbufPtr = inbuf;
751          inbufSize = strlen(inbufPtr);          inbufSize = strlen(inbufPtr);
752          outbufPtr = outbuf;          outbufPtr = outbuf;
753          outbufSize = sizeof(outbuf);          outbufSize = MAX_WIKI_TEXT_SIZE;
754          memset(outbuf, 0, outbufSize);          memset(outbuf, 0, outbufSize);
755          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);
756          if(inbufSize != 0) { // iconv error          if(inbufSize != 0) { // iconv error
757                  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);
758          }          }
759          fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp);          fwrite(outbuf, MAX_WIKI_TEXT_SIZE-outbufSize, 1, fp);
760          fclose(fp);          fclose(fp);
761          iconv_close(codeSet);          iconv_close(codeSet);
762            
763            free(inbuf);
764            free(outbuf);
765            
766            isWriteToFile = true;
767  }  }
768    
769  /******* Tools ************************/  /******* Tools ************************/

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.32

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