Develop and Download Open Source Software

Browse CVS Repository

Contents of /malonnote/mnModel.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.24 - (show annotations) (download) (as text)
Fri Sep 16 04:12:58 2005 UTC (18 years, 6 months ago) by maloninc
Branch: MAIN
CVS Tags: dev_1_3-0006
Changes since 1.23: +83 -15 lines
File MIME type: text/x-c++src
implement group by TYPE, but it may be bugy? (9/16)

1 #include "mnDef.h"
2 #include "mnModel.h"
3 #include <wx/dir.h>
4 #include <wx/regex.h>
5 #include <iconv.h>
6
7 static void toLower(char* string);
8 static char* decode(const char* string);
9 static char* encode(const char* string);
10 static int compWikiData(const void* wiki1, const void* wiki2);
11
12
13 /******* WikiList ************************/
14 #include <wx/listimpl.cpp>
15 WX_DEFINE_LIST(WikiList);
16
17
18 /******* mnModel ************************/
19
20 mnModel::mnModel(const char* dataDir)
21 {
22 wxCSConv conv(wxT(CODE_SET_SYSTEM));
23
24 wikiDataDir = new wxString(dataDir, conv);
25 searchStrList = new wxArrayString();
26 }
27
28 mnModel::~mnModel()
29 {
30 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)
111 {
112 int i;
113 wxDir* dir;
114 WikiData* wikiData;
115 WikiList* list = new WikiList();
116 wxString* fileName = new wxString();
117 char* tokenList[32];
118
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];
164 char* outbufPtr = outbuf;
165 int outbufSize;
166 wxString* typeToken;
167 char* ptr;
168 int i;
169
170 iconv_t codeSet = iconv_open(CODE_SET_SYSTEM, CODE_SET_EUC_JP);
171 if(codeSet == (iconv_t)-1) {
172 MN_FATAL_ERROR(wxT("failed iconv_open"));
173 }
174
175 dir = new wxDir(*wikiDataDir);
176 if ( !dir->IsOpened() )
177 {
178 MN_FATAL_ERROR(wxT("wxDir has faild\n"));
179 return ;
180 }
181 bool cont = dir->GetFirst(fileName, wxT("*.txt"), wxDIR_FILES);
182 while(cont){
183 fullPathName = *wikiDataDir + wxT("/") + *fileName;
184 fp = fopen((const char*)fullPathName.mb_str(), "r");
185 if(fp == NULL) {
186 MN_FATAL_ERROR(wxT("fopen faild"));
187 }
188 while(1) {
189 memset(buf, 0, MAX_BUF_SIZE);
190 fgets(buf, MAX_BUF_SIZE, fp);
191 if(buf[0] == 0) break;
192 if(strstr(buf, TYPE_TAG)){
193 ptr = &buf[typeTagLen];
194 while((token = strtok(ptr, " /\r\n:"))!= NULL) {
195 memset(outbuf, 0, MAX_BUF_SIZE);
196 snprintf(outbuf, MAX_BUF_SIZE, "%s", TYPESEARCH_TAG);
197 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 }
212 }
213 fclose(fp);
214 cont = dir->GetNext(fileName);
215 }
216 delete dir;
217 delete fileName;
218 iconv_close(codeSet);
219 }
220
221 bool mnModel::normalSearch(char* tokenList[], FILE*fp, char* decodeFileNameBuf)
222 {
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 bool mnModel::addSearchStr(wxString* searchStr)
280 {
281 wxString *string;
282
283 if(searchStrList->Index(searchStr->c_str()) == wxNOT_FOUND){
284 string = new wxString(searchStr->c_str());
285 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)
298 {
299 if(searchStrList->Index(searchStr.c_str()) != wxNOT_FOUND) {
300 searchStrList->Remove(searchStr.c_str());
301 wikiHash[*searchStr] = NULL;
302 }
303 }
304
305 void mnModel::modSearchStr(wxString* oldStr, wxString* newStr)
306 {
307 int index;
308
309 if((index = searchStrList->Index(oldStr->c_str())) != wxNOT_FOUND){
310 wxString& itemStr = searchStrList->Item(index);
311 itemStr.sprintf(wxT("%s"), newStr->c_str());
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()
331 {
332 return searchStrList;
333 }
334
335 WikiData* mnModel::newWikiData()
336 {
337 WikiData* data = new WikiData(wikiDataDir);
338
339 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 ************************/
417 WikiData::WikiData(wxString* dataDir, wxString* inFileName)
418 {
419 FILE* fp;
420 wxString fullPathName;
421 char* decodeStr;
422 char buf[MAX_BUF_SIZE];
423 char* inbuf;
424 int inbufSize;
425 char outbuf[MAX_BUF_SIZE];
426 char* outbufPtr = outbuf;
427 int outbufSize;
428 wxCSConv conv(wxT(CODE_SET_SYSTEM));
429
430 iconv_t codeSet = iconv_open(CODE_SET_SYSTEM, CODE_SET_EUC_JP);
431 if(codeSet == (iconv_t)-1) {
432 MN_FATAL_ERROR(wxT("failed iconv_open"));
433 }
434
435 text = NULL;
436 memset(outbuf, 0, MAX_BUF_SIZE);
437 fileName = new wxString(inFileName->mb_str(), conv);
438 dataDirName = new wxString(dataDir->mb_str(), conv);
439 decodeStr = decode(fileName->mb_str());
440 inbufSize = strlen(decodeStr);
441 outbufSize = sizeof(outbuf);
442 iconv(codeSet, (ICONV_CONST char**)&decodeStr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
443 subject = new wxString((const char*)outbuf, conv);
444 oldSubject = new wxString((const char*)outbuf, conv);
445 iconv_close(codeSet);
446
447 date = NULL;
448
449 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)) {
455 if(strstr( (const char*)buf, (const char*)DATE_TAG)) {
456 strtok(buf, "\n");
457 strtok(buf, "\r");
458 date = new wxString((const char*)buf, conv);
459 break;
460 }
461 }
462 fclose(fp);
463 }
464
465 WikiData::WikiData(wxString* dataDir) {
466 time_t now;
467 char buf[MAX_BUF_SIZE];
468 wxCSConv conv(wxT(CODE_SET_SYSTEM));
469
470 dataDirName = new wxString(dataDir->mb_str(), conv);
471
472 time(&now);
473 memset(buf, 0, sizeof(buf));
474 strftime(buf, sizeof(buf), "%Y/%m/%d-%H%M%S",localtime(&now));
475 subject = new wxString(buf, conv);
476 oldSubject = new wxString(buf, conv);
477
478 fileName = new wxString(encode(buf), conv);
479 fileName->Append(wxT(EXT_TAG));
480
481 memset(buf, 0, sizeof(buf));
482 strftime(buf, sizeof(buf), DATE_TAG "%Y/%m/%d %H:%M:%S",localtime(&now));
483 date = new wxString(buf, conv);
484
485 memset(buf, 0, sizeof(buf));
486 strftime(buf, sizeof(buf), NEW_DATA,localtime(&now));
487 text = new wxString(buf, conv);
488
489 }
490
491 WikiData::~WikiData()
492 {
493 delete subject;
494 delete oldSubject;
495 delete fileName;
496 delete date;
497 delete text;
498 delete dataDirName;
499 }
500
501 const wxString* WikiData::getFileName()
502 {
503 return fileName;
504 }
505
506 const wxString* WikiData::getSubject()
507 {
508 return subject;
509 }
510
511 const wxString* WikiData::getOldSubject()
512 {
513 return oldSubject;
514 }
515
516 void WikiData::modSubject(wxString* newSubject)
517 {
518 wxCSConv conv(wxT(CODE_SET_SYSTEM));
519 wxString* oldFileName = fileName;
520 char oldFullPath[MAX_BUF_SIZE];
521 char newFullPath[MAX_BUF_SIZE];
522 iconv_t codeSet;
523 char outbuf[MAX_BUF_SIZE];
524 char inbuf[MAX_BUF_SIZE];
525 const char* inbufPtr = inbuf;
526 char* outbufPtr = outbuf;
527 int inbufSize;
528 int outbufSize = sizeof(outbuf);
529 FILE* fp;
530
531 oldSubject = subject;
532
533 memset(outbuf, 0, outbufSize);
534 memset(inbuf, 0, sizeof(inbuf));
535 strcpy(inbuf, (const char*)newSubject->mb_str());
536 inbufSize = strlen(inbuf);
537 codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);
538 if(codeSet == (iconv_t)-1) {
539 MN_FATAL_ERROR(wxT("failed iconv_open"));
540 }
541 iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
542 iconv_close(codeSet);
543 subject = new wxString(newSubject->c_str());
544 fileName = new wxString(encode(outbuf), conv);
545 fileName->Append(wxT(EXT_TAG));
546
547 sprintf(oldFullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)oldFileName->mb_str());
548 sprintf(newFullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str());
549
550 if((fp = fopen(newFullPath, "r")) == NULL) {
551 if(rename(oldFullPath, newFullPath) < 0) wxLogMessage(wxT("rename error: errno=[%d]"), errno);
552 }
553 else if(strcmp(oldFullPath, newFullPath)){
554 wxLogMessage(wxT("File has already exist. [%s]"), fileName->c_str());
555 fclose(fp);
556 }
557 else {
558 fclose(fp);
559 }
560
561 delete oldFileName;
562 }
563
564 const wxString* WikiData::getDate()
565 {
566 return date;
567 }
568
569
570 const wxString* WikiData::getText()
571 {
572 FILE* fp;
573 char buf[MAX_BUF_SIZE];
574 char fullPath[MAX_BUF_SIZE];
575 iconv_t codeSet;
576 char outbuf[MAX_BUF_SIZE];
577 char* inbufPtr;
578 char* outbufPtr;
579 int inbufSize;
580 int outbufSize;
581 wxCSConv conv(wxT(CODE_SET_SYSTEM));
582 wxString* tmpStr;
583
584 codeSet = iconv_open(CODE_SET_SYSTEM, CODE_SET_EUC_JP);
585 if(codeSet == (iconv_t)-1) {
586 MN_FATAL_ERROR(wxT("failed iconv_open"));
587 }
588
589 if(text) {
590 iconv_close(codeSet);
591 return text;
592 }
593
594 text = new wxString();
595 sprintf(fullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str());
596 fp = fopen(fullPath, "r");
597 if(fp == NULL) {
598 MN_FATAL_ERROR(wxT("File open error."));
599 }
600
601 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;
606 inbufSize = sizeof(buf);
607 outbufPtr = outbuf;
608 outbufSize = sizeof(outbuf);
609 memset(outbuf, 0, outbufSize);
610 iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
611 tmpStr = new wxString((char*)outbuf, conv);
612 *text += *tmpStr;
613 delete tmpStr;
614 }
615 iconv_close(codeSet);
616 fclose(fp);
617
618 return text;
619 }
620
621 void WikiData::modText(wxString* intext)
622 {
623 wxCSConv conv(wxT(CODE_SET_SYSTEM));
624 delete text;
625 //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()
631 {
632 char fullPath[MAX_BUF_SIZE];
633
634 sprintf(fullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str());
635 if(remove(fullPath)) {
636 MN_FATAL_ERROR(wxT("remove file error"));
637 }
638 }
639
640 void WikiData::save()
641 {
642 char fullPath[MAX_BUF_SIZE];
643 FILE* fp;
644 iconv_t codeSet;
645 char inbuf[MAX_WIKI_TEXT_SIZE];
646 char outbuf[MAX_WIKI_TEXT_SIZE];
647 const char* inbufPtr;
648 char* outbufPtr;
649 int inbufSize;
650 int outbufSize;
651
652 codeSet = iconv_open(CODE_SET_EUC_JP, CODE_SET_SYSTEM);
653 if(codeSet == (iconv_t)-1) {
654 MN_FATAL_ERROR(wxT("failed iconv_open"));
655 }
656
657 sprintf(fullPath, "%s/%s", (const char*)dataDirName->mb_str(), (const char*)fileName->mb_str());
658 fp = fopen(fullPath, "wb");
659 if(fp == NULL) {
660 MN_FATAL_ERROR(wxT("File open error."));
661 }
662
663 memset(inbuf, 0, sizeof(inbuf));
664 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;
671 inbufSize = strlen(inbufPtr);
672 outbufPtr = outbuf;
673 outbufSize = sizeof(outbuf);
674 memset(outbuf, 0, outbufSize);
675 iconv(codeSet, (ICONV_CONST char**)&inbufPtr, (size_t*)&inbufSize, &outbufPtr, (size_t*)&outbufSize);
676 fwrite(outbuf, sizeof(outbuf)-outbufSize, 1, fp);
677 fclose(fp);
678 iconv_close(codeSet);
679 }
680
681 /******* 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)
694 {
695 static char buf[MAX_BUF_SIZE];
696 char c[5];
697 int i,j;
698 char* endPtr = NULL;
699
700 j = 0;
701 memset(buf, 0, MAX_BUF_SIZE);
702 for(i = 0; string[i] != 0; i+=2) {
703 c[0] = '0'; c[1] = 'x';
704 c[2] = string[i]; c[3] = string[i+1]; c[4] = 0;
705 buf[j] = strtol(c, &endPtr, 0);
706 j++;
707 if(j >= MAX_BUF_SIZE) {
708 buf[MAX_BUF_SIZE] = 0;
709 break;
710 }
711 }
712
713 return buf;
714 }
715
716 static char* encode(const char* string)
717 {
718 static char buf[MAX_BUF_SIZE];
719 int i,j;
720
721 j = 0;
722 memset(buf, 0, MAX_BUF_SIZE);
723 for(i = 0; string[i] != 0; i++) {
724 snprintf(&buf[j], 3, "%02X", (unsigned char)(string[i]));
725 j+=2;
726 if(j >= MAX_BUF_SIZE) {
727 buf[MAX_BUF_SIZE] = 0;
728 break;
729 }
730 }
731 return buf;
732 }
733
734 /*
735 * wiki1 > wiki2 -> return < 0
736 * wiki1 = wiki2 -> return = 0
737 * wiki1 < wiki2 -> return > 0
738 */
739 static int compWikiData(const void* wiki1, const void* wiki2)
740 {
741 WikiData* data1 = *(WikiData**)wiki1;
742 WikiData* data2 = *(WikiData**)wiki2;
743 const wxString* str1 = NULL;
744 const wxString* str2 = NULL;
745
746 str1 = data1->getDate();
747 str2 = data2->getDate();
748
749 if(str1 != NULL && str2 != NULL) {
750 return (strcmp(str2->mb_str(), str1->mb_str()));
751 }
752 else{
753 return 0;
754 }
755 }
756

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