summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/otodoaccessxml.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/otodoaccessxml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index 22b2469..cda300b 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -8,24 +8,52 @@
8#include <unistd.h> 8#include <unistd.h>
9 9
10 10
11#include <qfile.h> 11#include <qfile.h>
12#include <qvector.h> 12#include <qvector.h>
13 13
14#include <qpe/global.h> 14#include <qpe/global.h>
15#include <qpe/stringutil.h> 15#include <qpe/stringutil.h>
16#include <qpe/timeconversion.h> 16#include <qpe/timeconversion.h>
17 17
18#include "otodoaccessxml.h" 18#include "otodoaccessxml.h"
19 19
20namespace {
21 // FROM TT again
22char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
23{
24 char needleChar;
25 char haystackChar;
26 if (!needle || !haystack || !hLen || !nLen)
27 return 0;
28
29 const char* hsearch = haystack;
30
31 if ((needleChar = *needle++) != 0) {
32 nLen--; //(to make up for needle++)
33 do {
34 do {
35 if ((haystackChar = *hsearch++) == 0)
36 return (0);
37 if (hsearch >= haystack + hLen)
38 return (0);
39 } while (haystackChar != needleChar);
40 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
41 hsearch--;
42 }
43 return ((char *)hsearch);
44}
45}
46
47
20OTodoAccessXML::OTodoAccessXML( const QString& appName, 48OTodoAccessXML::OTodoAccessXML( const QString& appName,
21 const QString& fileName ) 49 const QString& fileName )
22 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) 50 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
23{ 51{
24 if (!fileName.isEmpty() ) 52 if (!fileName.isEmpty() )
25 m_file = fileName; 53 m_file = fileName;
26 else 54 else
27 m_file = Global::applicationFileName( "todolist", "todolist.xml" ); 55 m_file = Global::applicationFileName( "todolist", "todolist.xml" );
28} 56}
29OTodoAccessXML::~OTodoAccessXML() { 57OTodoAccessXML::~OTodoAccessXML() {
30 58
31} 59}
@@ -76,25 +104,25 @@ bool OTodoAccessXML::load() {
76 } 104 }
77 /* advise the kernel who we want to read it */ 105 /* advise the kernel who we want to read it */
78 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); 106 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL );
79 /* we do not the file any more */ 107 /* we do not the file any more */
80 ::close( fd ); 108 ::close( fd );
81 109
82 char* dt = (char*)map_addr; 110 char* dt = (char*)map_addr;
83 int len = attribut.st_size; 111 int len = attribut.st_size;
84 int i = 0; 112 int i = 0;
85 char *point; 113 char *point;
86 const char* collectionString = "<Task "; 114 const char* collectionString = "<Task ";
87 int strLen = strlen(collectionString); 115 int strLen = strlen(collectionString);
88 while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) { 116 while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) {
89 i = point -dt; 117 i = point -dt;
90 i+= strLen; 118 i+= strLen;
91 qWarning("Found a start at %d %d", i, (point-dt) ); 119 qWarning("Found a start at %d %d", i, (point-dt) );
92 120
93 OTodo ev; 121 OTodo ev;
94 m_year = m_month = m_day = 0; 122 m_year = m_month = m_day = 0;
95 123
96 while ( TRUE ) { 124 while ( TRUE ) {
97 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 125 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
98 ++i; 126 ++i;
99 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 127 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
100 break; 128 break;