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.31 by maloninc, Tue Jan 3 11:24:44 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 461  WikiData::WikiData(wxString* dataDir, wx Line 462  WikiData::WikiData(wxString* dataDir, wx
462                  }                  }
463          }          }
464          fclose(fp);          fclose(fp);
465    
466            isWriteToFile = true;
467  }  }
468    
469  WikiData::WikiData(wxString* dataDir) {  WikiData::WikiData(wxString* dataDir) {
# Line 520  WikiData::WikiData(wxString* dataDir) { Line 523  WikiData::WikiData(wxString* dataDir) {
523          text    = new wxString(buf, conv);          text    = new wxString(buf, conv);
524    
525          if(fp) fclose(fp);          if(fp) fclose(fp);
526    
527            isWriteToFile = false;
528  }  }
529    
530  WikiData::~WikiData()  WikiData::~WikiData()
# Line 625  const wxString* WikiData::getText() Line 630  const wxString* WikiData::getText()
630                  MN_FATAL_ERROR(wxT("failed iconv_open"));                  MN_FATAL_ERROR(wxT("failed iconv_open"));
631          }          }
632    
633          if(text) {          if(text && isWriteToFile == true) {
634                  iconv_close(codeSet);                  delete text;
635                    text = NULL;
636            }
637            else if(text && isWriteToFile == false) {
638                  return text;                  return text;
639          }          }
640    
# Line 638  const wxString* WikiData::getText() Line 646  const wxString* WikiData::getText()
646          }          }
647    
648          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  
649                  inbufPtr = buf;                  inbufPtr = buf;
650                  inbufSize = sizeof(buf);                  inbufSize = sizeof(buf);
651                  outbufPtr = outbuf;                  outbufPtr = outbuf;
# Line 681  void WikiData::save() Line 686  void WikiData::save()
686          char fullPath[MAX_BUF_SIZE];          char fullPath[MAX_BUF_SIZE];
687          FILE* fp;          FILE* fp;
688          iconv_t     codeSet;          iconv_t     codeSet;
689          char        inbuf[MAX_WIKI_TEXT_SIZE];          char*        inbuf;
690          char        outbuf[MAX_WIKI_TEXT_SIZE];          char*        outbuf;
691          const char*       inbufPtr;          const char*  inbufPtr;
692          char*       outbufPtr;          char*       outbufPtr;
693          int         inbufSize;          int         inbufSize;
694          int         outbufSize;          int         outbufSize;
695    
696            inbuf  = (char*)malloc(MAX_WIKI_TEXT_SIZE);
697            outbuf = (char*)malloc(MAX_WIKI_TEXT_SIZE);
698            if(inbuf == NULL || outbuf == NULL) {
699                    MN_FATAL_ERROR(wxT("It's too big data. Max size is 5MB."));
700            }
701    
702          codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);          codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);
703          if(codeSet == (iconv_t)-1) {          if(codeSet == (iconv_t)-1) {
704                  MN_FATAL_ERROR(wxT("failed iconv_open"));                  MN_FATAL_ERROR(wxT("failed iconv_open"));
# Line 699  void WikiData::save() Line 710  void WikiData::save()
710                  MN_FATAL_ERROR(wxT("File open error."));                  MN_FATAL_ERROR(wxT("File open error."));
711          }          }
712    
713          memset(inbuf, 0, sizeof(inbuf));          memset(inbuf, 0, MAX_WIKI_TEXT_SIZE);
714          strcpy(inbuf,(const char*)text->mb_str());          strcpy(inbuf,(const char*)text->mb_str());
715    
716  #ifdef __WXMAC__  //#ifdef __WXMAC__
717          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] = '\\';
718  #endif  //#endif
719    
720          inbufPtr = inbuf;          inbufPtr = inbuf;
721          inbufSize = strlen(inbufPtr);          inbufSize = strlen(inbufPtr);
722          outbufPtr = outbuf;          outbufPtr = outbuf;
723          outbufSize = sizeof(outbuf);          outbufSize = MAX_WIKI_TEXT_SIZE;
724          memset(outbuf, 0, outbufSize);          memset(outbuf, 0, outbufSize);
725          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);
726          if(inbufSize != 0) { // iconv error          if(inbufSize != 0) { // iconv error
727                  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);
728          }          }
729          fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp);          fwrite(outbuf, MAX_WIKI_TEXT_SIZE-outbufSize, 1, fp);
730          fclose(fp);          fclose(fp);
731          iconv_close(codeSet);          iconv_close(codeSet);
732            
733            free(inbuf);
734            free(outbuf);
735            
736            isWriteToFile = true;
737  }  }
738    
739  /******* Tools ************************/  /******* Tools ************************/

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

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