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.12 by maloninc, Sat Aug 13 02:00:29 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            tokenList[0] = (char*)malloc(strlen(token)+1);
68            snprintf(tokenList[0], strlen(token)+1, "%s", token);
69            i = 1;
70            while((token = strtok(NULL, " ")) != NULL) {
71                    tokenList[i] = (char*)malloc(strlen(token)+1);
72                    snprintf(tokenList[i], strlen(token)+1, "%s", token);
73                    i++;
74            }
75    
76          dir = new wxDir(*wikiDataDir);          dir = new wxDir(*wikiDataDir);
77      if ( !dir->IsOpened() )      if ( !dir->IsOpened() )
# Line 58  WikiList* mnModel::search(const char* se Line 86  WikiList* mnModel::search(const char* se
86                  if(fp == NULL) {                  if(fp == NULL) {
87                          MN_FATAL_ERROR(wxT("fopen faild"));                          MN_FATAL_ERROR(wxT("fopen faild"));
88                  }                  }
89    
90          while(1){          while(1){
91                  memset(buf, 0, MAX_BUF_SIZE);                  memset(buf, 0, MAX_BUF_SIZE);
92              fread(buf, MAX_BUF_SIZE-1, 1, fp);              fread(buf, MAX_BUF_SIZE-1, 1, fp);
93              if(buf[0] == 0) break;              if(buf[0] == 0) break;
94                          decodeFileName = decode(fileName->mb_str());                          decodeFileName = decode(fileName->mb_str());
95                          wxString strbuf(buf, eucConv);                          snprintf(decodeFileNameBuf, MAX_BUF_SIZE, "%s", decodeFileName);
96                          wxString strSearch(searchStr, sysConv);                          toLower(buf);
97                          wxString strDecodeFileName(decodeFileName, eucConv);                          toLower(outbuf);
98                          wxRegEx regStr(strSearch, wxRE_DEFAULT|wxRE_NEWLINE|wxRE_ICASE);                          toLower(decodeFileNameBuf);
99                          if(regStr.Matches(strbuf) || regStr.Matches(strDecodeFileName)){                          found = TRUE;
100                            for(i = 0; tokenList[i] != NULL; i++){
101                                    if(strstr((const char*)buf, (const char*)tokenList[i]) ||
102                                            strstr((const char*)decodeFileName, (const char*)tokenList[i])) {
103                                            found = TRUE;
104                                    }
105                                    else {
106                                            found = FALSE;
107                                            break;
108                                    }
109                            }
110    
111                            if(found){
112                                  wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp);                                  wikiData = new WikiData(wikiDataDir, (const char*)fileName->mb_str(), fp);
113                                  list->Append(wikiData);                                  list->Append(wikiData);
114                                  break;                                  break;
# Line 79  WikiList* mnModel::search(const char* se Line 120  WikiList* mnModel::search(const char* se
120          }          }
121          delete dir;          delete dir;
122          delete fileName;          delete fileName;
123            for(i = 0; tokenList[i] != NULL; i++) free(tokenList[i]);
124    
125          list->Sort(compWikiData);          list->Sort(compWikiData);
126          return list;          return list;
# Line 294  const wxString* WikiData::getText() Line 336  const wxString* WikiData::getText()
336          }          }
337    
338          while(fgets(buf, MAX_BUF_SIZE, fp)) {          while(fgets(buf, MAX_BUF_SIZE, fp)) {
339    #ifdef __WXMAC__
340                    for(int i = 0; buf[i] != 0; i++) if(buf[i] == (char)MAC_BACKSLASH) buf[i] = '\\';
341    #endif
342                  inbufPtr = buf;                  inbufPtr = buf;
343                  inbufSize = sizeof(buf);                  inbufSize = sizeof(buf);
344                  outbufPtr = outbuf;                  outbufPtr = outbuf;
# Line 354  void WikiData::save() Line 399  void WikiData::save()
399    
400          memset(inbuf, 0, sizeof(inbuf));          memset(inbuf, 0, sizeof(inbuf));
401          strcpy(inbuf,(const char*)text->mb_str());          strcpy(inbuf,(const char*)text->mb_str());
402    
403    #ifdef __WXMAC__
404            for(int i = 0; inbuf[i] != 0; i++) if(inbuf[i] == (char)MAC_BACKSLASH) inbuf[i] = '\\';
405    #endif
406    
407          inbufPtr = inbuf;          inbufPtr = inbuf;
408          inbufSize = strlen(inbufPtr);          inbufSize = strlen(inbufPtr);
409          outbufPtr = outbuf;          outbufPtr = outbuf;
# Line 367  void WikiData::save() Line 417  void WikiData::save()
417    
418  /******* Tools ************************/  /******* Tools ************************/
419    
420    static void toLower(char* string)
421    {
422            int i;
423    
424            for(i = 0; string[i] != 0; i++) {
425                    string[i] = tolower(string[i]);
426            }
427    }
428    
429    
430  static char* decode(const char* string)  static char* decode(const char* string)
431  {  {
432          static char buf[MAX_BUF_SIZE];          static char buf[MAX_BUF_SIZE];

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

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