author | pohly <pohly> | 2005-05-05 14:39:33 (UTC) |
---|---|---|
committer | pohly <pohly> | 2005-05-05 14:39:33 (UTC) |
commit | 39fbfd5eb7e45d73d38e8a2ce9437a3d7e1b8e91 (patch) (unidiff) | |
tree | 96e66fdc18dca4d4ab8611133e072f57dea224b9 /noncore/apps/opie-reader/arrierego.cpp | |
parent | 279fc4fd1986074acbadd3a8e86fcf3968a8dd5c (diff) | |
download | opie-39fbfd5eb7e45d73d38e8a2ce9437a3d7e1b8e91.zip opie-39fbfd5eb7e45d73d38e8a2ce9437a3d7e1b8e91.tar.gz opie-39fbfd5eb7e45d73d38e8a2ce9437a3d7e1b8e91.tar.bz2 |
new opie-reader sources with support for ArriereGo, Reb input and flite output plugins
Diffstat (limited to 'noncore/apps/opie-reader/arrierego.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/arrierego.cpp | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/arrierego.cpp b/noncore/apps/opie-reader/arrierego.cpp new file mode 100644 index 0000000..be2a3fa --- a/dev/null +++ b/noncore/apps/opie-reader/arrierego.cpp | |||
@@ -0,0 +1,188 @@ | |||
1 | #ifdef USENEF | ||
2 | #include <qimage.h> | ||
3 | #include "arrierego.h" | ||
4 | |||
5 | struct CArriere_dataRecord | ||
6 | { | ||
7 | UInt16 uid; | ||
8 | UInt16 nParagraphs; | ||
9 | UInt32 size; | ||
10 | UInt8 type; | ||
11 | UInt8 reserved; | ||
12 | }; | ||
13 | |||
14 | int CArriere::HeaderSize() | ||
15 | { | ||
16 | return 10; | ||
17 | } | ||
18 | |||
19 | void CArriere::GetHeader(UInt16& uid, UInt16& nParagraphs, UInt32& size, UInt8& type, UInt8& reserved) | ||
20 | { | ||
21 | CArriere_dataRecord thishdr; | ||
22 | unsuspend(); | ||
23 | fread(&thishdr, 1, HeaderSize(), fin); | ||
24 | uid = ntohs(thishdr.uid); | ||
25 | nParagraphs = ntohs(thishdr.nParagraphs); | ||
26 | size = ntohl(thishdr.size); | ||
27 | type = thishdr.type; | ||
28 | reserved = thishdr.reserved; | ||
29 | // qDebug("UID:%u Paras:%u Size:%u Type:%u Reserved:%u", uid, nParagraphs, size, (unsigned int)type, (unsigned int)reserved); | ||
30 | // for (int i = 0; i < sizeof(thishdr); i++) | ||
31 | //printf("%d %x\n", i, (int)(((char *)(&thishdr))[i])); | ||
32 | } | ||
33 | |||
34 | bool CArriere::CorrectDecoder() | ||
35 | { | ||
36 | char * type = (char*)(&(head.type)); | ||
37 | for (int i = 0; i < 8; ++i) qDebug("%c", type[i]); | ||
38 | return (memcmp(&head.type, "ArriereG", 8) == 0); | ||
39 | } | ||
40 | |||
41 | int CArriere::bgetch() | ||
42 | { | ||
43 | int ch = EOF; | ||
44 | if (bufferpos >= buffercontent) | ||
45 | { | ||
46 | if (bufferrec >= ntohs(head.recordList.numRecords) - 1) | ||
47 | { | ||
48 | return EOF; | ||
49 | } | ||
50 | if (isEndOfSection(bufferrec)) | ||
51 | { | ||
52 | return EOF; | ||
53 | } | ||
54 | if (!expand(bufferrec+1)) | ||
55 | { | ||
56 | return EOF; | ||
57 | } | ||
58 | mystyle.unset(); | ||
59 | if (m_ParaOffsets[m_nextParaIndex] == 0) | ||
60 | { | ||
61 | while (m_ParaOffsets[m_nextParaIndex+1] == 0) | ||
62 | { | ||
63 | m_nextParaIndex++; | ||
64 | } | ||
65 | } | ||
66 | mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2); | ||
67 | } | ||
68 | if (bufferpos == m_nextPara) | ||
69 | { | ||
70 | while (bufferpos == m_nextPara) | ||
71 | { | ||
72 | m_nextParaIndex++; | ||
73 | if (m_nextParaIndex == m_nParas) | ||
74 | { | ||
75 | m_nextPara = -1; | ||
76 | } | ||
77 | else | ||
78 | { | ||
79 | m_nextPara += m_ParaOffsets[m_nextParaIndex]; | ||
80 | } | ||
81 | } | ||
82 | mystyle.unset(); | ||
83 | mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2); | ||
84 | if (m_lastBreak == locate()) | ||
85 | { | ||
86 | currentpos++; | ||
87 | ch = expandedtextbuffer[bufferpos++]; | ||
88 | } | ||
89 | else | ||
90 | { | ||
91 | ch = 10; | ||
92 | } | ||
93 | } | ||
94 | else | ||
95 | { | ||
96 | currentpos++; | ||
97 | ch = expandedtextbuffer[bufferpos++]; | ||
98 | } | ||
99 | return ch; | ||
100 | } | ||
101 | |||
102 | tchar CArriere::getch(bool fast) | ||
103 | { | ||
104 | mystyle.clearPicture(); | ||
105 | return getch_base(fast); | ||
106 | } | ||
107 | |||
108 | /* | ||
109 | void CArriere::setlink(QString& fn, const QString& wrd) | ||
110 | { | ||
111 | fn = wrd; | ||
112 | } | ||
113 | */ | ||
114 | |||
115 | QImage* CArriere::imagefromdata(UInt8* imgbuffer, UInt32 imgsize) | ||
116 | { | ||
117 | QByteArray arr; | ||
118 | arr.assign((const char*)imgbuffer, imgsize); | ||
119 | |||
120 | QImage* qimage = new QImage(arr); | ||
121 | |||
122 | return qimage; | ||
123 | } | ||
124 | |||
125 | void CArriere::start2endSection() | ||
126 | { | ||
127 | m_currentstart = NEFstartSection(); | ||
128 | m_currentend = NEFendSection(); | ||
129 | } | ||
130 | |||
131 | unsigned long CArriere::NEFstartSection() | ||
132 | { | ||
133 | //inefficient - Should calc start/end of section on entry to section? | ||
134 | UInt16 thishdr_uid, thishdr_nParagraphs; | ||
135 | UInt32 thishdr_size; | ||
136 | UInt8 thishdr_type, thishdr_reserved; | ||
137 | unsigned long textlength = currentpos-bufferpos; | ||
138 | for (UInt16 recptr = bufferrec-1; recptr >= 1; recptr--) | ||
139 | { | ||
140 | gotorecordnumber(recptr); | ||
141 | //qDebug("recptr:%u", recptr); | ||
142 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | ||
143 | if (thishdr_type < 2) | ||
144 | { | ||
145 | if ((thishdr_reserved && continuation_bit) == 0) break; | ||
146 | textlength -= thishdr_size; | ||
147 | //qDebug("Textlength:%u, reserved:%u, recptr:%u", textlength, thishdr_reserved, recptr); | ||
148 | } | ||
149 | } | ||
150 | return textlength; | ||
151 | } | ||
152 | |||
153 | unsigned long CArriere::NEFendSection() | ||
154 | { | ||
155 | //inefficient - Should calc start/end of section on entry to section? | ||
156 | unsigned long textlength = currentpos-bufferpos+buffercontent; | ||
157 | gotorecordnumber(bufferrec); | ||
158 | UInt16 thishdr_uid, thishdr_nParagraphs; | ||
159 | UInt32 thishdr_size; | ||
160 | UInt8 thishdr_type, thishdr_reserved; | ||
161 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | ||
162 | if ((thishdr_reserved && continuation_bit) != 0) | ||
163 | { | ||
164 | for (UInt16 recptr = bufferrec+1; recptr < ntohs(head.recordList.numRecords); recptr++) | ||
165 | { | ||
166 | gotorecordnumber(recptr); | ||
167 | UInt16 thishdr_uid, thishdr_nParagraphs; | ||
168 | UInt32 thishdr_size; | ||
169 | UInt8 thishdr_type, thishdr_reserved; | ||
170 | GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); | ||
171 | //qDebug("recptr %u bufferrec %u type %u m_reserved %u", recptr, bufferrec, typ | ||
172 | if (thishdr_type < 2) | ||
173 | { | ||
174 | textlength += thishdr_size; | ||
175 | if ((thishdr_reserved && continuation_bit) == 0) break; | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | return textlength; | ||
180 | } | ||
181 | |||
182 | #ifndef __STATIC | ||
183 | extern "C" | ||
184 | { | ||
185 | CExpander* newcodec() { return new CArriere; } | ||
186 | } | ||
187 | #endif | ||
188 | #endif | ||