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.6 by maloninc, Wed Aug 10 05:35:03 2005 UTC revision 1.17 by maloninc, Tue Sep 13 01:37:43 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 33  mnModel::~mnModel() Line 33  mnModel::~mnModel()
33    
34  WikiList* mnModel::search(const char* searchStr)  WikiList* mnModel::search(const char* searchStr)
35  {  {
36            int         i;
37          wxDir*      dir;          wxDir*      dir;
38          FILE*       fp;          FILE*       fp;
39      wxString    fullPathName;      wxString    fullPathName;
# Line 40  WikiList* mnModel::search(const char* se Line 41  WikiList* mnModel::search(const char* se
41          WikiData*   wikiData;          WikiData*   wikiData;
42      WikiList*   list = new WikiList();      WikiList*   list = new WikiList();
43      wxString*   fileName = new wxString();      wxString*   fileName = new wxString();
44            iconv_t     codeSet;
45            char        outbuf[MAX_BUF_SIZE];
46            const char*       inbufPtr  = searchStr;
47            char*       outbufPtr = outbuf;
48            int         inbufSize = strlen(searchStr);
49            int         outbufSize = sizeof(outbuf);
50          const char* decodeFileName;          const char* decodeFileName;
51          wxCSConv eucConv(wxT(CODE_SET_EUC_JP));          char decodeFileNameBuf[MAX_BUF_SIZE];
52          wxCSConv sysConv(wxT(CODE_SET_SYSTEM));          char*       token;
53            char*       tokenList[32];
54            bool        found;
55    
56            memset(tokenList, 0, sizeof(char*)*32);
57            memset(outbuf, 0, outbufSize);
58            codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);
59            if(codeSet == (iconv_t)-1) {
60                    MN_FATAL_ERROR(wxT("failed iconv_open"));
61            }
62            iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
63            iconv_close(codeSet);
64    
65            /* searchStr to Tokens */
66            token = strtok(outbuf, " ");
67            if(token == NULL) return list;
68            tokenList[0] = (char*)malloc(strlen(token)+1);
69            snprintf(tokenList[0], strlen(token)+1, "%s", token);
70            i = 1;
71            while((token = strtok(NULL, " ")) != NULL) {
72                    tokenList[i] = (char*)malloc(strlen(token)+1);
73                    snprintf(tokenList[i], strlen(token)+1, "%s", token);
74                    i++;
75            }
76    
77          dir = new wxDir(*wikiDataDir);          dir = new wxDir(*wikiDataDir);
78      if ( !dir->IsOpened() )      if ( !dir->IsOpened() )
# Line 58  WikiList* mnModel::search(const char* se Line 87  WikiList* mnModel::search(const char* se
87                  if(fp == NULL) {                  if(fp == NULL) {
88                          MN_FATAL_ERROR(wxT("fopen faild"));                          MN_FATAL_ERROR(wxT("fopen faild"));
89                  }                  }
90    
91          while(1){          while(1){
92                  memset(buf, 0, MAX_BUF_SIZE);                  memset(buf, 0, MAX_BUF_SIZE);
93              fread(buf, MAX_BUF_SIZE-1, 1, fp);              fread(buf, MAX_BUF_SIZE-1, 1, fp);
94              if(buf[0] == 0) break;              if(buf[0] == 0) break;
95                          decodeFileName = decode(fileName->mb_str());                          decodeFileName = decode(fileName->mb_str());
96                          wxString strbuf(buf, eucConv);                          snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName);
97                          wxString strSearch(searchStr, sysConv);                          toLower(buf);
98                          wxString strDecodeFileName(decodeFileName, eucConv);                          toLower(decodeFileNameBuf);
99                          wxRegEx regStr(strSearch, wxRE_DEFAULT|wxRE_NEWLINE|wxRE_ICASE);                          found = TRUE;
100                          if(regStr.Matches(strbuf) || regStr.Matches(strDecodeFileName)){                          for(i = 0; tokenList[i] != NULL; i++){
101                                    toLower(tokenList[i]);
102                                    if(strstr((const char*)buf, (const char*)tokenList[i]) ||
103                                            strstr((const char*)decodeFileNameBuf, (const char*)tokenList[i])) {
104                                            found = TRUE;
105                                    }
106                                    else {
107                                            found = FALSE;
108                                            break;
109                                    }
110                            }
111    
112                            if(found){
113                                  wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp);                                  wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp);
114                                  list->Append(wikiData);                                  list->Append(wikiData);
115                                  break;                                  break;
# Line 79  WikiList* mnModel::search(const char* se Line 121  WikiList* mnModel::search(const char* se
121          }          }
122          delete dir;          delete dir;
123          delete fileName;          delete fileName;
124            for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]);
125    
126          list->Sort(compWikiData);          list->Sort(compWikiData);
127          return list;          return list;
# Line 90  void mnModel::addSearchStr(wxString* sea Line 133  void mnModel::addSearchStr(wxString* sea
133    
134          if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){          if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){
135                  string = new wxString(searchStr->c_str());                  string = new wxString(searchStr->c_str());
136                  searchStrList->Add(*string, 1);                  //searchStrList->Add(*string, 1);
137                    searchStrList->Insert(*string, 0);
138          }          }
139  }  }
140    
# Line 245  void WikiData::modSubject(wxString* newS Line 289  void WikiData::modSubject(wxString* newS
289          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());
290    
291          if((fp = fopen(newFullPath, "r")) == NULL) {          if((fp = fopen(newFullPath, "r")) == NULL) {
292                  rename(oldFullPath, newFullPath);                  if(rename(oldFullPath, newFullPath) < 0) wxLogMessage(wxT("rename error: errno=[%d]"), errno);
293          }          }
294          else if(strcmp(oldFullPath, newFullPath)){          else if(strcmp(oldFullPath, newFullPath)){
295                  wxLogMessage(wxT("File has already exist. [%s]"), fileName->c_str());                  wxLogMessage(wxT("File has already exist. [%s]"), fileName->c_str());
296                  fclose(fp);                  fclose(fp);
297          }          }
298            else {
299                    fclose(fp);
300            }
301    
302          delete oldSubject;          delete oldSubject;
303          delete oldFileName;          delete oldFileName;
# Line 294  const wxString* WikiData::getText() Line 341  const wxString* WikiData::getText()
341          }          }
342    
343          while(fgets(buf, MAX_BUF_SIZE, fp)) {          while(fgets(buf, MAX_BUF_SIZE, fp)) {
344    #ifdef __WXMAC__
345                    for(int i = 0; buf[i] != 0; i++) if(buf[i] == (char)MAC_BACKSLASH) buf[i] = '\\';
346    #endif
347                  inbufPtr = buf;                  inbufPtr = buf;
348                  inbufSize = sizeof(buf);                  inbufSize = sizeof(buf);
349                  outbufPtr = outbuf;                  outbufPtr = outbuf;
# Line 354  void WikiData::save() Line 404  void WikiData::save()
404    
405          memset(inbuf, 0, sizeof(inbuf));          memset(inbuf, 0, sizeof(inbuf));
406          strcpy(inbuf,(const char*)text->mb_str());          strcpy(inbuf,(const char*)text->mb_str());
407    
408    #ifdef __WXMAC__
409            for(int i = 0; inbuf[i] != 0; i++) if(inbuf[i] == (char)MAC_BACKSLASH) inbuf[i] = '\\';
410    #endif
411    
412          inbufPtr = inbuf;          inbufPtr = inbuf;
413          inbufSize = strlen(inbufPtr);          inbufSize = strlen(inbufPtr);
414          outbufPtr = outbuf;          outbufPtr = outbuf;
# Line 367  void WikiData::save() Line 422  void WikiData::save()
422    
423  /******* Tools ************************/  /******* Tools ************************/
424    
425    static void toLower(char* string)
426    {
427            int i;
428    
429            for(i = 0; string[i] != 0; i++) {
430                    string[i] = tolower(string[i]);
431            }
432    }
433    
434    
435  static char* decode(const char* string)  static char* decode(const char* string)
436  {  {
437          static char buf[MAX_BUF_SIZE];          static char buf[MAX_BUF_SIZE];

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.17

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