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.2 by maloninc, Sun Jul 31 06:54:12 2005 UTC revision 1.24 by maloninc, Fri Sep 16 04:12:58 2005 UTC
# Line 4  Line 4 
4  #include <wx/regex.h>  #include <wx/regex.h>
5  #include <iconv.h>  #include <iconv.h>
6    
7  /* プロトタイプ */  static void   toLower(char* string);
8  static char*  decode(const char* string);  static char*  decode(const char* string);
9  static char*  encode(const char* string);  static char*  encode(const char* string);
10  static int compWikiData(const void* wiki1, const void* wiki2);  static int    compWikiData(const void* wiki1, const void* wiki2);
11    
12    
13  /******* WikiList ************************/  /******* WikiList ************************/
# Line 30  mnModel::~mnModel() Line 30  mnModel::~mnModel()
30          delete wikiDataDir;          delete wikiDataDir;
31  }  }
32    
33    /*
34     * 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    {
41            iconv_t     codeSet;
42            char        outbuf[MAX_BUF_SIZE];
43            const char* inbufPtr   = searchStr;
44            char*       outbufPtr  = outbuf;
45            int         inbufSize  = strlen(searchStr);
46            int         outbufSize = sizeof(outbuf);
47            char*       token;
48            int         i;
49    
50            memset(outbuf, 0, outbufSize);
51            codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);
52            if(codeSet == (iconv_t)-1) {
53                    MN_FATAL_ERROR(wxT("failed iconv_open"));
54            }
55            iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
56            iconv_close(codeSet);
57    
58            /* searchStr to Tokens */
59            token = strtok(outbuf, " ");
60            if(token == NULL) return false;
61            tokenList[0] = (char*)malloc(strlen(token)+1);
62            snprintf(tokenList[0], strlen(token)+1, "%s", token);
63            i = 1;
64            while((token = strtok(NULL, " ")) != NULL) {
65                    tokenList[i] = (char*)malloc(strlen(token)+1);
66                    snprintf(tokenList[i], strlen(token)+1, "%s", token);
67                    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                    return false;  /* because of removed */
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)  WikiList* mnModel::search(const char* searchStr)
111  {  {
112            int         i;
113          wxDir*      dir;          wxDir*      dir;
         FILE*       fp;  
     wxString    fullPathName;  
     char        buf[MAX_BUF_SIZE];  
114          WikiData*   wikiData;          WikiData*   wikiData;
115      WikiList*   list = new WikiList();      WikiList*   list = new WikiList();
116      wxString*   fileName = new wxString();      wxString*   fileName = new wxString();
117          wxRegEx*        regStr;          char*       tokenList[32];
118          iconv_t     codeSet;  
119            memset(tokenList, 0, sizeof(char*)*32);
120            if( makeSearchToken(searchStr, tokenList) == false) return list;
121    
122            dir = new wxDir(*wikiDataDir);
123        if ( !dir->IsOpened() )
124        {
125                    MN_FATAL_ERROR(wxT("wxDir has faild\n"));
126            return NULL;
127        }
128    
129        bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES);
130            while(cont){
131    
132                    if( matchWithToken(fileName, tokenList) ) { /* match with token list */
133                            wikiData = new WikiData(wikiDataDir, fileName);
134                            list->Append(wikiData);
135                    }
136    
137            cont = dir->GetNext(fileName);
138            }
139    
140            delete dir;
141            delete fileName;
142            for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]);
143    
144            list->Sort(compWikiData);
145            return list;
146    }
147    
148    /*
149     *  add malon-type:xxx to search list
150     */
151    void mnModel::group()
152    {
153            wxCSConv    conv(wxT(CODE_SET_SYSTEM));
154        char        buf[MAX_BUF_SIZE];
155            wxDir*      dir;
156            FILE*       fp;
157        wxString*   fileName = new wxString();
158        wxString    fullPathName;
159            int         typeTagLen = strlen(TYPE_TAG);
160            char*       token;
161            char*           inbufPtr;
162            int         inbufSize;
163          char        outbuf[MAX_BUF_SIZE];          char        outbuf[MAX_BUF_SIZE];
         const char*       inbufPtr  = searchStr;  
164          char*       outbufPtr = outbuf;          char*       outbufPtr = outbuf;
165          int         inbufSize = strlen(searchStr);          int         outbufSize;
166          int         outbufSize = sizeof(outbuf);          wxString*   typeToken;
167          const char* decodeFileName;          char*       ptr;
168            int         i;
169    
170          memset(outbuf, 0, outbufSize);          iconv_t codeSet = iconv_open(CODE_SET_SYSTEM, CODE_SET_EUC_JP);
         codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);  
171          if(codeSet == (iconv_t)-1) {          if(codeSet == (iconv_t)-1) {
172                  MN_FATAL_ERROR(wxT("failed iconv_open"));                  MN_FATAL_ERROR(wxT("failed iconv_open"));
173          }          }
         iconv(codeSet, (const char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);  
         iconv_close(codeSet);  
174    
175          dir = new wxDir(*wikiDataDir);          dir = new wxDir(*wikiDataDir);
176      if ( !dir->IsOpened() )      if ( !dir->IsOpened() )
177      {      {
178                  MN_FATAL_ERROR(wxT("wxDir has faild\n"));                  MN_FATAL_ERROR(wxT("wxDir has faild\n"));
179          return NULL;          return ;
180      }      }
181      bool cont = dir->GetFirst(fileName, wxEmptyString, wxDIR_FILES);      bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES);
182          while(cont){          while(cont){
183          fullPathName = *wikiDataDir + wxT("/") + *fileName;          fullPathName = *wikiDataDir + wxT("/") + *fileName;
184                  fp = fopen((const char*)fullPathName.mb_str(), "r");                  fp = fopen((const char*)fullPathName.mb_str(), "r");
185                  if(fp == NULL) {                  if(fp == NULL) {
186                          MN_FATAL_ERROR(wxT("fopen faild"));                          MN_FATAL_ERROR(wxT("fopen faild"));
187                  }                  }
188          while(1){                  while(1) {
189                  memset(buf, 0, MAX_BUF_SIZE);                          memset(buf, 0, MAX_BUF_SIZE);
190              fread(buf, MAX_BUF_SIZE-1, 1, fp);                          fgets(buf, MAX_BUF_SIZE, fp);
191              if(buf[0] == 0) break;                          if(buf[0] == 0) break;
192                          decodeFileName = decode(fileName->mb_str());                          if(strstr(buf, TYPE_TAG)){
193                  if(strstr((const char*)buf, (const char*)outbuf) ||                                  ptr = &buf[typeTagLen];
194                                  strstr((const char*)decodeFileName, (const char*)outbuf)) {                                  while((token = strtok(ptr, " /\r\n:"))!= NULL) {
195                                  wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp);                                          memset(outbuf, 0, MAX_BUF_SIZE);
196                                  list->Append(wikiData);                                          snprintf(outbuf, MAX_BUF_SIZE, "%s", TYPESEARCH_TAG);
197                                  break;                                          inbufPtr = token;
198                                            inbufSize = strlen(token);
199                                            outbufPtr = &outbuf[strlen(TYPESEARCH_TAG)];
200                                            outbufSize = sizeof(outbuf) - strlen(TYPESEARCH_TAG);
201                                            iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
202    
203                                            typeToken = new wxString(outbuf, conv);
204                                            if( addSearchStr(typeToken) ) {
205                                                    WikiList* wikiList = search(typeToken->mb_str());
206                                                    addSearchList(typeToken, wikiList);
207                                            }
208                                            delete typeToken;
209                                            ptr = NULL;
210                                    }
211                          }                          }
             buf[0] = 0;  
212                  }                  }
213                  fclose(fp);                  fclose(fp);
214          cont = dir->GetNext(fileName);          cont = dir->GetNext(fileName);
215          }          }
216          delete dir;          delete dir;
217            delete fileName;
218            iconv_close(codeSet);
219    }
220    
221          list->Sort(compWikiData);  bool mnModel::normalSearch(char* tokenList[], FILE*fp, char* decodeFileNameBuf)
222          return list;  {
223        char        buf[MAX_BUF_SIZE];
224            bool        found;
225            int         i;
226            while(1){
227            memset(buf, 0, MAX_BUF_SIZE);
228            fread(buf, MAX_BUF_SIZE-1, 1, fp);
229            if(buf[0] == 0) break;
230                    toLower(buf);
231                    found = TRUE;
232                    for(i = 0; tokenList[i] != NULL; i++){
233                            toLower(tokenList[i]);
234                            if(strstr((const char*)buf, (const char*)tokenList[i]) ||                 /* search in file context */
235                                    strstr((const char*)decodeFileNameBuf, (const char*)tokenList[i]) ||  /* search in file name    */
236                                    strcmp((const char*)tokenList[i], (const char*)ALLMEMO_TAG) == 0) {   /* SHOW  ALL MEMO         */
237                                    found = TRUE;
238                            }
239                            else {
240                                    found = FALSE;
241                                    break;
242                            }
243                    }
244    
245                    if(found){ /* all tokens found */
246                            break;
247                    }
248            buf[0] = 0;
249            }
250    
251            return found;
252    }
253    
254    bool mnModel::typeSearch(char* typeStr, FILE*fp)
255    {
256        char        buf[MAX_BUF_SIZE];
257            bool        found;
258            int         i;
259            char*       typeToken;
260            char        typeStrCopy[MAX_BUF_SIZE];
261    
262            snprintf(typeStrCopy, MAX_BUF_SIZE, "%s", typeStr);
263            while(1){
264            memset(buf, 0, MAX_BUF_SIZE);
265            fgets(buf, MAX_BUF_SIZE, fp);
266            if(buf[0] == 0) break;
267                    if(strstr((const char*)buf, TYPE_TAG)){  /* search TYPE line */
268                            typeToken = strtok(typeStrCopy, ":");
269                            typeToken = strtok(NULL, ":");    /* second field separated by colon(:) */
270                            if(typeToken == NULL) return false;
271                            toLower(typeToken);
272                            toLower(buf);
273                            if(strstr(buf, typeToken)) return true;
274                    }
275            }
276            return false;
277  }  }
278    
279  void mnModel::addSearchStr(wxString* searchStr)  bool mnModel::addSearchStr(wxString* searchStr)
280  {  {
281          wxString *string;          wxString *string;
282    
283          if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){          if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){
284                  string = new wxString(searchStr->c_str());                  string = new wxString(searchStr->c_str());
285                  searchStrList->Add(*string, 1);                  searchStrList->Add(*string, 1);
286                    //searchStrList->Insert(*string, 0);
287                    return true;  /* Add */
288          }          }
289            return false; /* does'nt add because of duplicating */
290    }
291    
292    void mnModel::addSearchList(wxString* searchStr, WikiList* list)
293    {
294            wikiHash[*searchStr] = list;
295  }  }
296    
297  void mnModel::removeSearchStr(wxString searchStr)  void mnModel::removeSearchStr(wxString searchStr)
298  {  {
299          if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) {          if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) {
300                  searchStrList->Remove(searchStr.c_str());                  searchStrList->Remove(searchStr.c_str());
301                    wikiHash[*searchStr] = NULL;
302          }          }
303  }  }
304    
# Line 119  void mnModel::modSearchStr(wxString* old Line 312  void mnModel::modSearchStr(wxString* old
312          }          }
313  }  }
314    
315    void mnModel::clearSearchStrList()
316    {
317            searchStrList->Clear();
318    }
319    
320    void mnModel::clearSearchResultList()
321    {
322            wikiHash.clear();
323    }
324    
325    const wxString* mnModel::getWikiDataDir()
326    {
327            return wikiDataDir;
328    }
329    
330  const wxArrayString* mnModel::getSearchStrList()  const wxArrayString* mnModel::getSearchStrList()
331  {  {
332          return searchStrList;          return searchStrList;
# Line 130  WikiData* mnModel::newWikiData() Line 338  WikiData* mnModel::newWikiData()
338    
339          return data;          return data;
340  }  }
341    const WikiList* mnModel::getSearchResultList(wxString* searchStr)
342    {
343            return wikiHash[*searchStr];
344    }
345    
346    /* add "addData's" clone. if already exist same data, overwrite it*/
347    void mnModel::addSearchResultList(wxString* searchStr, WikiData* addData)
348    {
349            WikiList* wikiList = wikiHash[*searchStr];
350            WikiList::Node* node;
351            WikiData* data;
352    
353            if(wikiList == NULL) {
354                    MN_FATAL_ERROR(wxT("wikiList is null"));
355                    return;
356            }
357    
358            node = wikiList->GetFirst();
359            while(node) {
360                    data = node->GetData();
361                    if(data == addData) return;
362                    if( *(data->getSubject()) == *(addData->getOldSubject()) ) {
363                            if(wikiList->DeleteObject(data)) {
364                                    //delete data; /* may be wrong.. */
365                                    break;
366                            }
367                            else {
368                                    MN_FATAL_ERROR(wxT("Can't find delete data"));
369                            }
370                    }
371                    node = node->GetNext();
372            }
373            WikiData* copy = new WikiData((wxString*)wikiDataDir, (wxString*)addData->getFileName());
374            wikiList->Append(copy);
375            wikiList->Sort(compWikiData);
376    }
377    
378    bool mnModel::delSearchResultList(wxString* searchStr, WikiData* delData)
379    {
380            WikiList* wikiList = wikiHash[*searchStr];
381            WikiList::Node* node;
382            WikiData* data;
383            bool      found = false;
384    
385            if(wikiList == NULL) {
386                    MN_FATAL_ERROR(wxT("wikiList is null"));
387                    return false;
388            }
389    
390            node = wikiList->GetFirst();
391            while(node) {
392                    data = node->GetData();
393                    if(data == delData) {
394                            if(!wikiList->DeleteObject(data)) {
395                                    MN_FATAL_ERROR(wxT("Can't find delete data"));
396                            }
397                            found = true;
398                            break;
399                    }
400                    else if( *(data->getSubject()) == *(delData->getOldSubject()) ) {
401                            if(wikiList->DeleteObject(data)) {
402                                    //delete data;  /* may be wrong.. */
403                                    found = true;
404                                    break;
405                            }
406                            else {
407                                    MN_FATAL_ERROR(wxT("Can't find delete data"));
408                            }
409                    }
410                    node = node->GetNext();
411            }
412            wikiList->Sort(compWikiData);
413            return found;
414    }
415    
416  /******* WikiData ************************/  /******* WikiData ************************/
417  WikiData::WikiData(wxString* dataDir, const char* file, FILE* fp)  WikiData::WikiData(wxString* dataDir, wxString* inFileName)
418  {  {
419            FILE* fp;
420        wxString    fullPathName;
421          char* decodeStr;          char* decodeStr;
422          char  buf[MAX_BUF_SIZE];          char  buf[MAX_BUF_SIZE];
423          char* inbuf;          char* inbuf;
# Line 150  WikiData::WikiData(wxString* dataDir, co Line 434  WikiData::WikiData(wxString* dataDir, co
434    
435          text = NULL;          text = NULL;
436          memset(outbuf, 0, MAX_BUF_SIZE);          memset(outbuf, 0, MAX_BUF_SIZE);
437          fileName = new wxString((const char*)file, conv);          fileName = new wxString(inFileName->mb_str(), conv);
438          dataDirName = dataDir;          dataDirName = new wxString(dataDir->mb_str(), conv);
439          decodeStr = decode(file);          decodeStr = decode(fileName->mb_str());
440          inbufSize = strlen(decodeStr);          inbufSize = strlen(decodeStr);
441          outbufSize = sizeof(outbuf);          outbufSize = sizeof(outbuf);
442          iconv(codeSet, (const char**)&decodeStr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);          iconv(codeSet, (ICONV_CONST char**)&decodeStr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
443          subject  = new wxString((const char*)outbuf, conv);          subject  = new wxString((const char*)outbuf, conv);
444            oldSubject  = new wxString((const char*)outbuf, conv);
445          iconv_close(codeSet);          iconv_close(codeSet);
446    
447          date     = NULL;          date     = NULL;
448    
449      rewind(fp);      fullPathName = *dataDir + wxT("/") + *fileName;
450            fp = fopen((const char*)fullPathName.mb_str(), "r");
451            if(fp == NULL) {
452                    MN_FATAL_ERROR(wxT("fopen faild"));
453            }
454          while(fgets(buf, MAX_BUF_SIZE, fp)) {          while(fgets(buf, MAX_BUF_SIZE, fp)) {
455                  if(strstr( (const char*)buf, (const char*)DATE_TAG)) {                  if(strstr( (const char*)buf, (const char*)DATE_TAG)) {
456                          strtok(buf, "\n");                          strtok(buf, "\n");
# Line 170  WikiData::WikiData(wxString* dataDir, co Line 459  WikiData::WikiData(wxString* dataDir, co
459                          break;                          break;
460                  }                  }
461          }          }
462            fclose(fp);
463  }  }
464    
465  WikiData::WikiData(wxString* dataDir) {  WikiData::WikiData(wxString* dataDir) {
# Line 177  WikiData::WikiData(wxString* dataDir) { Line 467  WikiData::WikiData(wxString* dataDir) {
467          char       buf[MAX_BUF_SIZE];          char       buf[MAX_BUF_SIZE];
468          wxCSConv    conv(wxT(CODE_SET_SYSTEM));          wxCSConv    conv(wxT(CODE_SET_SYSTEM));
469    
470          dataDirName = dataDir;          dataDirName = new wxString(dataDir->mb_str(), conv);
471    
472      time(&now);      time(&now);
473          memset(buf, 0, sizeof(buf));          memset(buf, 0, sizeof(buf));
474          strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now));          strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now));
475          subject  = new wxString(buf, conv);          subject  = new wxString(buf, conv);
476            oldSubject  = new wxString(buf, conv);
477    
478          fileName = new wxString(encode(buf), conv);          fileName = new wxString(encode(buf), conv);
479          fileName->Append(wxT(EXT_TAG));          fileName->Append(wxT(EXT_TAG));
# Line 200  WikiData::WikiData(wxString* dataDir) { Line 491  WikiData::WikiData(wxString* dataDir) {
491  WikiData::~WikiData()  WikiData::~WikiData()
492  {  {
493          delete subject;          delete subject;
494            delete oldSubject;
495          delete fileName;          delete fileName;
496          delete date;          delete date;
497          delete text;          delete text;
498            delete dataDirName;
499  }  }
500    
501  const wxString* WikiData::getFileName()  const wxString* WikiData::getFileName()
# Line 215  const wxString* WikiData::getSubject() Line 508  const wxString* WikiData::getSubject()
508          return subject;          return subject;
509  }  }
510    
511    const wxString* WikiData::getOldSubject()
512    {
513            return oldSubject;
514    }
515    
516  void WikiData::modSubject(wxString* newSubject)  void WikiData::modSubject(wxString* newSubject)
517  {  {
518          wxCSConv    conv(wxT(CODE_SET_SYSTEM));          wxCSConv    conv(wxT(CODE_SET_SYSTEM));
519          wxString*   oldFileName = fileName;          wxString*   oldFileName = fileName;
         wxString*   oldSubject  = subject;  
520          char        oldFullPath[MAX_BUF_SIZE];          char        oldFullPath[MAX_BUF_SIZE];
521          char        newFullPath[MAX_BUF_SIZE];          char        newFullPath[MAX_BUF_SIZE];
522          iconv_t     codeSet;          iconv_t     codeSet;
# Line 231  void WikiData::modSubject(wxString* newS Line 528  void WikiData::modSubject(wxString* newS
528          int         outbufSize = sizeof(outbuf);          int         outbufSize = sizeof(outbuf);
529          FILE*       fp;          FILE*       fp;
530    
531            oldSubject = subject;
532    
533          memset(outbuf, 0, outbufSize);          memset(outbuf, 0, outbufSize);
534          memset(inbuf,  0, sizeof(inbuf));          memset(inbuf,  0, sizeof(inbuf));
535          strcpy(inbuf, (const char*)newSubject->mb_str());          strcpy(inbuf, (const char*)newSubject->mb_str());
# Line 239  void WikiData::modSubject(wxString* newS Line 538  void WikiData::modSubject(wxString* newS
538          if(codeSet == (iconv_t)-1) {          if(codeSet == (iconv_t)-1) {
539                  MN_FATAL_ERROR(wxT("failed iconv_open"));                  MN_FATAL_ERROR(wxT("failed iconv_open"));
540          }          }
541          iconv(codeSet, (const char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);          iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
542          iconv_close(codeSet);          iconv_close(codeSet);
543          subject  = new wxString(newSubject->c_str());          subject  = new wxString(newSubject->c_str());
544          fileName = new wxString(encode(outbuf), conv);          fileName = new wxString(encode(outbuf), conv);
# Line 249  void WikiData::modSubject(wxString* newS Line 548  void WikiData::modSubject(wxString* newS
548          sprintf(newFullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str());          sprintf(newFullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str());
549    
550          if((fp = fopen(newFullPath, "r")) == NULL) {          if((fp = fopen(newFullPath, "r")) == NULL) {
551                  rename(oldFullPath, newFullPath);                  if(rename(oldFullPath, newFullPath) < 0) wxLogMessage(wxT("rename error: errno=[%d]"), errno);
552          }          }
553          else if(strcmp(oldFullPath, newFullPath)){          else if(strcmp(oldFullPath, newFullPath)){
554                  wxLogMessage(wxT("File has already exist. [%s]"), fileName->c_str());                  wxLogMessage(wxT("File has already exist. [%s]"), fileName->c_str());
555                  fclose(fp);                  fclose(fp);
556          }          }
557            else {
558                    fclose(fp);
559            }
560    
         delete oldSubject;  
561          delete oldFileName;          delete oldFileName;
562  }  }
563    
# Line 298  const wxString* WikiData::getText() Line 599  const wxString* WikiData::getText()
599          }          }
600    
601          while(fgets(buf, MAX_BUF_SIZE, fp)) {          while(fgets(buf, MAX_BUF_SIZE, fp)) {
602    #ifdef __WXMAC__
603                    for(int i = 0; buf[i] != 0; i++) if(buf[i] == (char)MAC_BACKSLASH) buf[i] = '\\';
604    #endif
605                  inbufPtr = buf;                  inbufPtr = buf;
606                  inbufSize = sizeof(buf);                  inbufSize = sizeof(buf);
607                  outbufPtr = outbuf;                  outbufPtr = outbuf;
608                  outbufSize = sizeof(outbuf);                  outbufSize = sizeof(outbuf);
609                  memset(outbuf, 0, outbufSize);                  memset(outbuf, 0, outbufSize);
610                  iconv(codeSet, (const char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);                  iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
611                  tmpStr = new wxString((char*)outbuf, conv);                  tmpStr = new wxString((char*)outbuf, conv);
612                  *text += *tmpStr;                  *text += *tmpStr;
613                  delete tmpStr;                  delete tmpStr;
# Line 316  const wxString* WikiData::getText() Line 620  const wxString* WikiData::getText()
620    
621  void WikiData::modText(wxString* intext)  void WikiData::modText(wxString* intext)
622  {  {
623            wxCSConv conv(wxT(CODE_SET_SYSTEM));
624          delete text;          delete text;
625          text = new wxString(intext->c_str());          //text = new wxString(intext->c_str());
626            //text = new wxString(*intext);
627            text = new wxString(intext->mb_str(), conv);
628  }  }
629    
630  void WikiData::removeDataFile()  void WikiData::removeDataFile()
# Line 355  void WikiData::save() Line 662  void WikiData::save()
662    
663          memset(inbuf, 0, sizeof(inbuf));          memset(inbuf, 0, sizeof(inbuf));
664          strcpy(inbuf,(const char*)text->mb_str());          strcpy(inbuf,(const char*)text->mb_str());
665    
666    #ifdef __WXMAC__
667            for(int i = 0; inbuf[i] != 0; i++) if(inbuf[i] == (char)MAC_BACKSLASH) inbuf[i] = '\\';
668    #endif
669    
670          inbufPtr = inbuf;          inbufPtr = inbuf;
671          inbufSize = strlen(inbufPtr);          inbufSize = strlen(inbufPtr);
672          outbufPtr = outbuf;          outbufPtr = outbuf;
673          outbufSize = sizeof(outbuf);          outbufSize = sizeof(outbuf);
674          memset(outbuf, 0, outbufSize);          memset(outbuf, 0, outbufSize);
675          iconv(codeSet, (const char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);          iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
676          fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp);          fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp);
677          fclose(fp);          fclose(fp);
678          iconv_close(codeSet);          iconv_close(codeSet);
# Line 368  void WikiData::save() Line 680  void WikiData::save()
680    
681  /******* Tools ************************/  /******* Tools ************************/
682    
683    static void toLower(char* string)
684    {
685            int i;
686    
687            for(i = 0; string[i] != 0; i++) {
688                    string[i] = tolower(string[i]);
689            }
690    }
691    
692    
693  static char* decode(const char* string)  static char* decode(const char* string)
694  {  {
695          static char buf[MAX_BUF_SIZE];          static char buf[MAX_BUF_SIZE];

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.24

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