Diffstat (limited to 'noncore/apps/opie-reader/Aportis.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Aportis.cpp | 163 |
1 files changed, 123 insertions, 40 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp index 595b385..1327ff8 100644 --- a/noncore/apps/opie-reader/Aportis.cpp +++ b/noncore/apps/opie-reader/Aportis.cpp | |||
@@ -2,9 +2,55 @@ | |||
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include "Aportis.h" | 3 | #include "Aportis.h" |
4 | #include "my_list.h" | ||
5 | #include "Bkmks.h" | ||
4 | 6 | ||
5 | Aportis::Aportis() { /*printf("constructing:%x\n",fin);*/ } | 7 | Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ } |
8 | |||
9 | void Aportis::dePeanut(int& ch) | ||
10 | { | ||
11 | if (peanutfile && ch != EOF) | ||
12 | { | ||
13 | unsigned char c = ch; | ||
14 | if (peanutfile) c ^= 0xa5; | ||
15 | ch = c; | ||
16 | } | ||
17 | } | ||
6 | 18 | ||
7 | CList<Bkmk>* Aportis::getbkmklist() | 19 | CList<Bkmk>* Aportis::getbkmklist() |
8 | { | 20 | { |
21 | /* | ||
22 | if (peanutfile) | ||
23 | { | ||
24 | if (nRecs2 > nRecs) | ||
25 | { | ||
26 | CList<Bkmk>* t = new CList<Bkmk>; | ||
27 | for (int i = nRecs; i < nRecs2; i++) | ||
28 | { | ||
29 | char name[17]; | ||
30 | name[16] = '\0'; | ||
31 | qDebug("Record:%d, Length:%u",i,recordlength(i)); | ||
32 | gotorecordnumber(i); | ||
33 | fread(name,1,16,fin); | ||
34 | unsigned long lcn; | ||
35 | fread(&lcn,sizeof(lcn),1,fin); | ||
36 | lcn ^= 0xa5a5a5a5; | ||
37 | lcn = SwapLong(lcn); | ||
38 | qDebug("Bookmark:%s:%u", name,lcn); | ||
39 | tchar tname[17]; | ||
40 | memset(tname, 0, sizeof(tname)); | ||
41 | for (int i = 0; name[i] != 0; i++) | ||
42 | { | ||
43 | tname[i] = name[i] ^ 0xa5; | ||
44 | } | ||
45 | t->push_back(Bkmk(tname, NULL, lcn)); | ||
46 | } | ||
47 | return t; | ||
48 | } | ||
49 | else | ||
50 | { | ||
51 | return NULL; | ||
52 | } | ||
53 | } | ||
54 | */ | ||
9 | if (bCompressed != 4) return NULL; | 55 | if (bCompressed != 4) return NULL; |
10 | CList<Bkmk>* t = new CList<Bkmk>; | 56 | CList<Bkmk>* t = new CList<Bkmk>; |
@@ -35,5 +81,5 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
35 | tname[i] = name[i]; | 81 | tname[i] = name[i]; |
36 | } | 82 | } |
37 | t->push_back(Bkmk(tname,lcn)); | 83 | t->push_back(Bkmk(tname, NULL, lcn)); |
38 | #else | 84 | #else |
39 | t->push_back(Bkmk(name,lcn)); | 85 | t->push_back(Bkmk(name,lcn)); |
@@ -47,5 +93,4 @@ CList<Bkmk>* Aportis::getbkmklist() | |||
47 | int Aportis::openfile(const char *src) | 93 | int Aportis::openfile(const char *src) |
48 | { | 94 | { |
49 | |||
50 | // printf("In openfile\n"); | 95 | // printf("In openfile\n"); |
51 | int ret = 0; | 96 | int ret = 0; |
@@ -56,47 +101,78 @@ int Aportis::openfile(const char *src) | |||
56 | || head.type != 0x74584554) // 'tXET') | 101 | || head.type != 0x74584554) // 'tXET') |
57 | { | 102 | { |
58 | return -2; | 103 | |
104 | if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0) | ||
105 | { | ||
106 | peanutfile = true; | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | return -2; | ||
111 | } | ||
59 | } | 112 | } |
60 | 113 | ||
61 | gotorecordnumber(0); | 114 | nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; |
62 | tDocRecord0 hdr0; | ||
63 | fread(&hdr0, sizeof(hdr0), 1, fin); | ||
64 | bCompressed = SwapWord(hdr0.wVersion); | ||
65 | if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) { | ||
66 | ret = bCompressed; | ||
67 | bCompressed = 2; | ||
68 | } | ||
69 | |||
70 | fseek(fin,0,SEEK_END); | 115 | fseek(fin,0,SEEK_END); |
71 | dwLen = ftell(fin); | 116 | dwLen = ftell(fin); |
72 | nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1; | ||
73 | 117 | ||
74 | switch (bCompressed) | 118 | if (peanutfile) |
75 | { | 119 | { |
76 | case 4: | 120 | |
121 | PeanutHeader hdr0; | ||
122 | gotorecordnumber(0); | ||
123 | fread(&hdr0, sizeof(hdr0), 1, fin); | ||
124 | qDebug("Version:%x", ntohs(hdr0.Version)); | ||
125 | if (hdr0.Version && 0x0200) | ||
77 | { | 126 | { |
78 | dwTLen = 0; | 127 | bCompressed = 2; |
79 | int i; | 128 | } |
80 | for (i = 0; i < nRecs; i++) | 129 | else |
130 | { | ||
131 | bCompressed = 1; | ||
132 | } | ||
133 | BlockSize = 4096; | ||
134 | nRecs = SwapWord(hdr0.Records)-1; | ||
135 | dwTLen = nRecs*BlockSize; | ||
136 | } | ||
137 | else | ||
138 | { | ||
139 | gotorecordnumber(0); | ||
140 | tDocRecord0 hdr0; | ||
141 | fread(&hdr0, sizeof(hdr0), 1, fin); | ||
142 | bCompressed = SwapWord(hdr0.wVersion); | ||
143 | if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) { | ||
144 | ret = bCompressed; | ||
145 | bCompressed = 2; | ||
146 | } | ||
147 | switch (bCompressed) | ||
148 | { | ||
149 | case 4: | ||
81 | { | 150 | { |
82 | unsigned int bs = GetBS(i); | 151 | dwTLen = 0; |
83 | if (bs == 0) break; | 152 | int i; |
84 | else dwTLen += bs; | 153 | for (i = 0; i < nRecs; i++) |
154 | { | ||
155 | unsigned int bs = GetBS(i); | ||
156 | if (bs == 0) break; | ||
157 | else dwTLen += bs; | ||
158 | } | ||
159 | nRecs = i; | ||
160 | BlockSize = 0; | ||
85 | } | 161 | } |
86 | nRecs = i; | 162 | break; |
87 | BlockSize = 0; | 163 | case 1: |
164 | case 2: | ||
165 | default: | ||
166 | nRecs = SwapWord(hdr0.wNumRecs); | ||
167 | dwTLen = SwapLong(hdr0.dwStoryLen); | ||
168 | BlockSize = SwapWord(hdr0.wRecSize); | ||
169 | if (BlockSize == 0) | ||
170 | { | ||
171 | BlockSize = 4096; | ||
172 | printf("WARNING: Blocksize not set in source file\n"); | ||
173 | } | ||
88 | } | 174 | } |
89 | break; | 175 | } |
90 | case 1: | 176 | |
91 | case 2: | ||
92 | default: | ||
93 | dwTLen = SwapLong(hdr0.dwStoryLen); | ||
94 | BlockSize = SwapWord(hdr0.wRecSize); | ||
95 | if (BlockSize == 0) | ||
96 | { | ||
97 | BlockSize = 4096; | ||
98 | printf("WARNING: Blocksize not set in source file\n"); | ||
99 | } | ||
100 | } | ||
101 | 177 | ||
102 | 178 | ||
@@ -107,4 +183,5 @@ int Aportis::openfile(const char *src) | |||
107 | outptr = 0; | 183 | outptr = 0; |
108 | refreshbuffer(); | 184 | refreshbuffer(); |
185 | qDebug("Number of records:[%u,%u]", nRecs, nRecs2); | ||
109 | return ret; | 186 | return ret; |
110 | } | 187 | } |
@@ -118,4 +195,5 @@ int Aportis::getch() | |||
118 | { | 195 | { |
119 | int c = getc(fin); | 196 | int c = getc(fin); |
197 | dePeanut(c); | ||
120 | dwRecLen--; | 198 | dwRecLen--; |
121 | currentpos++; | 199 | currentpos++; |
@@ -130,8 +208,9 @@ int Aportis::getch() | |||
130 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; | 208 | if ((dwRecLen == 0) && !refreshbuffer()) return EOF; |
131 | currentpos++; | 209 | currentpos++; |
132 | unsigned int c; | 210 | int c; |
133 | 211 | ||
134 | // take a char from the input buffer | 212 | // take a char from the input buffer |
135 | c = getc(fin); | 213 | c = getc(fin); |
214 | dePeanut(c); | ||
136 | dwRecLen--; | 215 | dwRecLen--; |
137 | // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF | 216 | // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF |
@@ -153,5 +232,7 @@ int Aportis::getch() | |||
153 | while(c--) | 232 | while(c--) |
154 | { | 233 | { |
155 | circbuf[cbptr = (cbptr+1)%2048] = getc(fin); | 234 | int c = getc(fin); |
235 | dePeanut(c); | ||
236 | circbuf[cbptr = (cbptr+1)%2048] = c; | ||
156 | } | 237 | } |
157 | return circbuf[outptr = (outptr+1)%2048]; | 238 | return circbuf[outptr = (outptr+1)%2048]; |
@@ -161,5 +242,7 @@ int Aportis::getch() | |||
161 | int m,n; | 242 | int m,n; |
162 | c <<= 8; | 243 | c <<= 8; |
163 | c += getc(fin); | 244 | int c1 = getc(fin); |
245 | dePeanut(c1); | ||
246 | c += c1; | ||
164 | dwRecLen--; | 247 | dwRecLen--; |
165 | m = (c & 0x3FFF) >> COUNT_BITS; | 248 | m = (c & 0x3FFF) >> COUNT_BITS; |