Diffstat (limited to 'noncore/apps/opie-reader/ztxt.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/ztxt.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/ztxt.cpp b/noncore/apps/opie-reader/ztxt.cpp index 35db05e..e04eaa0 100644 --- a/noncore/apps/opie-reader/ztxt.cpp +++ b/noncore/apps/opie-reader/ztxt.cpp | |||
@@ -54,32 +54,33 @@ int ztxt::getch() | |||
54 | 54 | ||
55 | } | 55 | } |
56 | currentpos++; | 56 | currentpos++; |
57 | return expandedtextbuffer[bufferpos++]; | 57 | return expandedtextbuffer[bufferpos++]; |
58 | } | 58 | } |
59 | 59 | ||
60 | unsigned int ztxt::locate() | 60 | unsigned int ztxt::locate() |
61 | { | 61 | { |
62 | return currentpos; | 62 | return currentpos; |
63 | } | 63 | } |
64 | 64 | ||
65 | void ztxt::locate(unsigned int n) | 65 | void ztxt::locate(unsigned int n) |
66 | { | 66 | { |
67 | 67 | ||
68 | if (hasrandomaccess()) | 68 | if (hasrandomaccess()) |
69 | { | 69 | { |
70 | unsuspend(); | ||
70 | bufferrec = n / ntohs(hdr0.recordSize) + 1; | 71 | bufferrec = n / ntohs(hdr0.recordSize) + 1; |
71 | if (bufferrec == 1) | 72 | if (bufferrec == 1) |
72 | { | 73 | { |
73 | inflateEnd(&zstream); | 74 | inflateEnd(&zstream); |
74 | } | 75 | } |
75 | size_t reclen = recordlength(bufferrec); | 76 | size_t reclen = recordlength(bufferrec); |
76 | if (reclen == 0) return; | 77 | if (reclen == 0) return; |
77 | gotorecordnumber(bufferrec); | 78 | gotorecordnumber(bufferrec); |
78 | fread(compressedtextbuffer, reclen, sizeof(char), fin); | 79 | fread(compressedtextbuffer, reclen, sizeof(char), fin); |
79 | 80 | ||
80 | zstream.next_in = compressedtextbuffer; | 81 | zstream.next_in = compressedtextbuffer; |
81 | zstream.next_out = expandedtextbuffer; | 82 | zstream.next_out = expandedtextbuffer; |
82 | zstream.avail_out = buffersize; | 83 | zstream.avail_out = buffersize; |
83 | zstream.avail_in = reclen; | 84 | zstream.avail_in = reclen; |
84 | 85 | ||
85 | if (bufferrec == 1) | 86 | if (bufferrec == 1) |
@@ -94,32 +95,33 @@ void ztxt::locate(unsigned int n) | |||
94 | 95 | ||
95 | int ret = inflate(&zstream, Z_SYNC_FLUSH); | 96 | int ret = inflate(&zstream, Z_SYNC_FLUSH); |
96 | buffercontent = buffersize - zstream.avail_out; | 97 | buffercontent = buffersize - zstream.avail_out; |
97 | bufferpos = 0; | 98 | bufferpos = 0; |
98 | currentpos = n - n % ntohs(hdr0.recordSize); | 99 | currentpos = n - n % ntohs(hdr0.recordSize); |
99 | while (currentpos < n) getch(); | 100 | while (currentpos < n) getch(); |
100 | } | 101 | } |
101 | else | 102 | else |
102 | { | 103 | { |
103 | home(); | 104 | home(); |
104 | while (currentpos < n && getch() != EOF); | 105 | while (currentpos < n && getch() != EOF); |
105 | } | 106 | } |
106 | } | 107 | } |
107 | 108 | ||
108 | void ztxt::home() | 109 | void ztxt::home() |
109 | { | 110 | { |
111 | unsuspend(); | ||
110 | if (bInit) | 112 | if (bInit) |
111 | { | 113 | { |
112 | inflateEnd(&zstream); | 114 | inflateEnd(&zstream); |
113 | } | 115 | } |
114 | bInit = true; | 116 | bInit = true; |
115 | size_t reclen = recordlength(1); | 117 | size_t reclen = recordlength(1); |
116 | gotorecordnumber(1); | 118 | gotorecordnumber(1); |
117 | fread(compressedtextbuffer, reclen, sizeof(char), fin); | 119 | fread(compressedtextbuffer, reclen, sizeof(char), fin); |
118 | 120 | ||
119 | zstream.next_in = compressedtextbuffer; | 121 | zstream.next_in = compressedtextbuffer; |
120 | zstream.next_out = expandedtextbuffer; | 122 | zstream.next_out = expandedtextbuffer; |
121 | zstream.avail_out = buffersize; | 123 | zstream.avail_out = buffersize; |
122 | zstream.avail_in = reclen; | 124 | zstream.avail_in = reclen; |
123 | 125 | ||
124 | zstream.zalloc = Z_NULL; | 126 | zstream.zalloc = Z_NULL; |
125 | zstream.zfree = Z_NULL; | 127 | zstream.zfree = Z_NULL; |
@@ -134,32 +136,33 @@ void ztxt::home() | |||
134 | bufferpos = 0; | 136 | bufferpos = 0; |
135 | bufferrec = 1; | 137 | bufferrec = 1; |
136 | currentpos = 0; | 138 | currentpos = 0; |
137 | buffercontent = buffersize - zstream.avail_out; | 139 | buffercontent = buffersize - zstream.avail_out; |
138 | //printf("buffercontent:%u\n", buffercontent); | 140 | //printf("buffercontent:%u\n", buffercontent); |
139 | } | 141 | } |
140 | 142 | ||
141 | CList<Bkmk>* ztxt::getbkmklist() | 143 | CList<Bkmk>* ztxt::getbkmklist() |
142 | { | 144 | { |
143 | UInt16 recno = ntohs(hdr0.bookmarkRecord); | 145 | UInt16 recno = ntohs(hdr0.bookmarkRecord); |
144 | 146 | ||
145 | // printf("Bookmarks - record %d contains %d\n", recno, ntohs(hdr0.numBookmarks)); | 147 | // printf("Bookmarks - record %d contains %d\n", recno, ntohs(hdr0.numBookmarks)); |
146 | 148 | ||
147 | if (recno == 0) return NULL; | 149 | if (recno == 0) return NULL; |
148 | 150 | ||
149 | CList<Bkmk>* t = new CList<Bkmk>; | 151 | CList<Bkmk>* t = new CList<Bkmk>; |
152 | unsuspend(); | ||
150 | size_t cur = ftell(fin); | 153 | size_t cur = ftell(fin); |
151 | gotorecordnumber(recno); | 154 | gotorecordnumber(recno); |
152 | for (int i = 0; i < ntohs(hdr0.numBookmarks); i++) | 155 | for (int i = 0; i < ntohs(hdr0.numBookmarks); i++) |
153 | { | 156 | { |
154 | zTXTbkmk bkmk; | 157 | zTXTbkmk bkmk; |
155 | if (fread(&bkmk, sizeof(bkmk), 1, fin) != 1) break; | 158 | if (fread(&bkmk, sizeof(bkmk), 1, fin) != 1) break; |
156 | // printf("Bookmark number:%d:%.20s\n", i, bkmk.title); | 159 | // printf("Bookmark number:%d:%.20s\n", i, bkmk.title); |
157 | tchar title[MAX_BMRK_LENGTH]; | 160 | tchar title[MAX_BMRK_LENGTH]; |
158 | for (int j = 0; j < MAX_BMRK_LENGTH; j++) | 161 | for (int j = 0; j < MAX_BMRK_LENGTH; j++) |
159 | { | 162 | { |
160 | title[j] = bkmk.title[j]; | 163 | title[j] = bkmk.title[j]; |
161 | } | 164 | } |
162 | t->push_back(Bkmk(title, NULL, ntohl(bkmk.offset))); | 165 | t->push_back(Bkmk(title, NULL, ntohl(bkmk.offset))); |
163 | } | 166 | } |
164 | fseek(fin, cur, SEEK_SET); | 167 | fseek(fin, cur, SEEK_SET); |
165 | return t; | 168 | return t; |