summaryrefslogtreecommitdiff
authorar <ar>2004-05-27 22:04:46 (UTC)
committer ar <ar>2004-05-27 22:04:46 (UTC)
commit4f7c3c4d0d634706d13950b3827714b168e279e3 (patch) (unidiff)
tree2df448e7a4dcd538c26365873e194be2b55e83b7
parent46f81a089ba8febdb79e0d150b69f74bb1ea7d18 (diff)
downloadopie-4f7c3c4d0d634706d13950b3827714b168e279e3.zip
opie-4f7c3c4d0d634706d13950b3827714b168e279e3.tar.gz
opie-4f7c3c4d0d634706d13950b3827714b168e279e3.tar.bz2
- convert qDebug to odebug
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/keyz-cfg/zkb.cpp716
-rw-r--r--noncore/apps/opie-gutenbrowser/gutenbrowser.cpp15
-rw-r--r--noncore/apps/opie-reader/BuffDoc.h116
-rw-r--r--noncore/apps/opie-reader/CEncoding.h16
-rw-r--r--noncore/apps/opie-reader/CExpander.h140
-rw-r--r--noncore/apps/opie-reader/Filedata.h56
-rw-r--r--noncore/apps/opie-reader/FontControl.h178
-rw-r--r--noncore/apps/opie-reader/Palm2QImage.cpp125
-rw-r--r--noncore/apps/opie-reader/QTReader.h124
-rw-r--r--noncore/apps/opie-reader/QTReaderApp.h112
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.h14
-rw-r--r--noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp2282
12 files changed, 1957 insertions, 1937 deletions
diff --git a/noncore/apps/keyz-cfg/zkb.cpp b/noncore/apps/keyz-cfg/zkb.cpp
index 58bde2a..c9e1dc5 100644
--- a/noncore/apps/keyz-cfg/zkb.cpp
+++ b/noncore/apps/keyz-cfg/zkb.cpp
@@ -1,4 +1,8 @@
1#include "zkb.h" 1#include "zkb.h"
2
3/* OPIE */
4#include <opie2/odebug.h>
5
2#include <stdio.h> 6#include <stdio.h>
3 7
4// Implementation of Action class 8// Implementation of Action class
@@ -6,584 +10,580 @@ Action::Action():state(0), keycode(0), unicode(0), flags(0) {
6} 10}
7 11
8Action::Action(State* s, ushort kc, ushort uni, int f): 12Action::Action(State* s, ushort kc, ushort uni, int f):
9 state(s), keycode(kc), unicode(uni), flags(f) { 13 state(s), keycode(kc), unicode(uni), flags(f) {
10} 14}
11 15
12Action::~Action() { 16Action::~Action() {
13} 17}
14 18
15State* Action::getState() const { 19State* Action::getState() const {
16 return state; 20 return state;
17} 21}
18 22
19void Action::setState(State* s) { 23void Action::setState(State* s) {
20 state = s; 24 state = s;
21 setDefined(true); 25 setDefined(true);
22} 26}
23 27
24bool Action::hasEvent() const { 28bool Action::hasEvent() const {
25 return flags & Event; 29 return flags & Event;
26} 30}
27 31
28void Action::setEvent(bool e) { 32void Action::setEvent(bool e) {
29 flags = (flags & ~Event) | ((e) ? Event : 0); 33 flags = (flags & ~Event) | ((e) ? Event : 0);
30 34
31 if (e) { 35 if (e) {
32 setDefined(true); 36 setDefined(true);
33 } else { 37 } else {
34 if (state == 0) { 38 if (state == 0) {
35 setDefined(false); 39 setDefined(false);
36 } 40 }
37 } 41 }
38} 42}
39 43
40bool Action::isDefined() const { 44bool Action::isDefined() const {
41 return flags & Defined; 45 return flags & Defined;
42} 46}
43 47
44void Action::setDefined(bool d) { 48void Action::setDefined(bool d) {
45 flags = (flags & ~Defined) | ((d) ? Defined : 0); 49 flags = (flags & ~Defined) | ((d) ? Defined : 0);
46} 50}
47 51
48int Action::getKeycode() const { 52int Action::getKeycode() const {
49 return keycode; 53 return keycode;
50} 54}
51 55
52void Action::setKeycode(int c) { 56void Action::setKeycode(int c) {
53 keycode = (ushort) c; 57 keycode = (ushort) c;
54 setEvent(true); 58 setEvent(true);
55} 59}
56 60
57int Action::getUnicode() const { 61int Action::getUnicode() const {
58 return unicode; 62 return unicode;
59} 63}
60 64
61void Action::setUnicode(int u) { 65void Action::setUnicode(int u) {
62 unicode = (ushort) u; 66 unicode = (ushort) u;
63 setEvent(true); 67 setEvent(true);
64} 68}
65 69
66int Action::getModifiers() const { 70int Action::getModifiers() const {
67 int ret = 0; 71 int ret = 0;
68 if (flags & Shift_Mod) { 72 if (flags & Shift_Mod) {
69 ret |= Qt::ShiftButton; 73 ret |= Qt::ShiftButton;
70 } 74 }
71 75
72 if (flags & Ctrl_Mod) { 76 if (flags & Ctrl_Mod) {
73 ret |= Qt::ControlButton; 77 ret |= Qt::ControlButton;
74 } 78 }
75 79
76 if (flags & Alt_Mod) { 80 if (flags & Alt_Mod) {
77 ret |= Qt::AltButton; 81 ret |= Qt::AltButton;
78 } 82 }
79 83
80 if (flags & Keypad_Mod) { 84 if (flags & Keypad_Mod) {
81 ret |= Qt::Keypad; 85 ret |= Qt::Keypad;
82 } 86 }
83 87
84 return ret; 88 return ret;
85} 89}
86 90
87void Action::setModifiers(int m) { 91void Action::setModifiers(int m) {
88 int n = 0; 92 int n = 0;
89 93
90 if (m & Qt::ShiftButton) { 94 if (m & Qt::ShiftButton) {
91 n |= Shift_Mod; 95 n |= Shift_Mod;
92 } 96 }
93 97
94 if (m & Qt::ControlButton) { 98 if (m & Qt::ControlButton) {
95 n |= Ctrl_Mod; 99 n |= Ctrl_Mod;
96 } 100 }
97 101
98 if (m & Qt::AltButton) { 102 if (m & Qt::AltButton) {
99 n |= Alt_Mod; 103 n |= Alt_Mod;
100 } 104 }
101 105
102 if (m & Qt::Keypad) { 106 if (m & Qt::Keypad) {
103 n |= Keypad_Mod; 107 n |= Keypad_Mod;
104 } 108 }
105 109
106 flags = flags & ~Mod_Bits | n; 110 flags = flags & ~Mod_Bits | n;
107 setEvent(true); 111 setEvent(true);
108} 112}
109 113
110bool Action::isPressed() const { 114bool Action::isPressed() const {
111 return (flags & Press) != 0; 115 return (flags & Press) != 0;
112} 116}
113 117
114void Action::setPressed(bool p) { 118void Action::setPressed(bool p) {
115 flags = (flags & ~Press) | ((p) ? Press : 0); 119 flags = (flags & ~Press) | ((p) ? Press : 0);
116 setEvent(true); 120 setEvent(true);
117} 121}
118 122
119bool Action::isAutorepeat() const { 123bool Action::isAutorepeat() const {
120 return (flags & Autorepeat) != 0; 124 return (flags & Autorepeat) != 0;
121} 125}
122 126
123void Action::setAutorepeat(bool p) { 127void Action::setAutorepeat(bool p) {
124 flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0); 128 flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0);
125 setEvent(true); 129 setEvent(true);
126} 130}
127 131
128// Implementation of State class 132// Implementation of State class
129const short State::x1[] = { /* from 0x20 to 0x5f */ 133const short State::x1[] = { /* from 0x20 to 0x5f */
130 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */ 134 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */
131 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */ 135 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */
132 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */ 136 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */
133 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */ 137 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */
134 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */ 138 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */
135 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */ 139 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */
136 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */ 140 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */
137 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */ 141 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */
138 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */ 142 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */
139 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */ 143 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */
140 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */ 144 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */
141 -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */ 145 -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */
142}; 146};
143 147
144const short State::x2[] = { /* from 0x1000 to 0x1057*/ 148const short State::x2[] = { /* from 0x1000 to 0x1057*/
145 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */ 149 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */
146 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */ 150 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */
147 -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */ 151 -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */
148 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */ 152 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */
149 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */ 153 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */
150 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */ 154 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */
151 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */ 155 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */
152 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */ 156 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */
153 -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */ 157 -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */
154 -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */ 158 -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */
155 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */ 159 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */
156}; 160};
157 161
158State::State(State* p):parent(p), keys(0) { 162State::State(State* p):parent(p), keys(0) {
159 keys = new Action[Key_Max * 2 + 1]; 163 keys = new Action[Key_Max * 2 + 1];
160} 164}
161 165
162State::State(const State& s) { 166State::State(const State& s) {
163 parent = s.parent; 167 parent = s.parent;
164 keys = new Action[Key_Max * 2 + 1]; 168 keys = new Action[Key_Max * 2 + 1];
165 memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); 169 memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1));
166} 170}
167 171
168State::~State() { 172State::~State() {
169 if (keys!=0) { 173 if (keys!=0) {
170 delete [] keys; 174 delete [] keys;
171 } 175 }
172} 176}
173 177
174Action* State::get(int keycode, bool pressed, bool follow) const { 178Action* State::get(int keycode, bool pressed, bool follow) const {
175 Action* ret = 0; 179 Action* ret = 0;
176 int n = translateKeycode(keycode); 180 int n = translateKeycode(keycode);
177 181
178 if (n != -1 && keys != 0) { 182 if (n != -1 && keys != 0) {
179 if (pressed) { 183 if (pressed) {
180 n += Key_Max; 184 n += Key_Max;
181 } 185 }
182 ret = &keys[n]; 186 ret = &keys[n];
183 } 187 }
184 188
185 if (ret==0 || !ret->isDefined()) { 189 if (ret==0 || !ret->isDefined()) {
186 if (follow && parent!=0) { 190 if (follow && parent!=0) {
187 ret = parent->get(keycode, pressed, follow); 191 ret = parent->get(keycode, pressed, follow);
188 } 192 }
189 } 193 }
190 194
191 return ret; 195 return ret;
192} 196}
193 197
194bool State::set(int keycode, bool pressed, Action& action) { 198bool State::set(int keycode, bool pressed, Action& action) {
195 int n = translateKeycode(keycode); 199 int n = translateKeycode(keycode);
196 200
197 if (n==-1 || keys==0) { 201 if (n==-1 || keys==0) {
198 return false; 202 return false;
199 } 203 }
200 204
201 if (pressed) { 205 if (pressed) {
202 n += Key_Max + 1; 206 n += Key_Max + 1;
203 } 207 }
204 208
205 keys[n] = action; 209 keys[n] = action;
206 return true; 210 return true;
207} 211}
208 212
209State* State::getParent() const { 213State* State::getParent() const {
210 return parent; 214 return parent;
211} 215}
212 216
213void State::setParent(State* s) { 217void State::setParent(State* s) {
214 parent = s; 218 parent = s;
215} 219}
216 220
217int State::translateKeycode(int keycode) const { 221int State::translateKeycode(int keycode) const {
218 if (keycode < 0x20) { 222 if (keycode < 0x20) {
219 return -1; 223 return -1;
220 } 224 }
221 225
222 if (keycode < 0x80) { 226 if (keycode < 0x80) {
223 return x1[keycode - 0x20]; 227 return x1[keycode - 0x20];
224 } 228 }
225 229
226 if (keycode < 0x1000) { 230 if (keycode < 0x1000) {
227 return -1; 231 return -1;
228 } 232 }
229 233
230 if (keycode < 0x1057) { 234 if (keycode < 0x1057) {
231 return x2[keycode - 0x1000]; 235 return x2[keycode - 0x1000];
232 } 236 }
233 237
234 return -1; 238 return -1;
235} 239}
236 240
237// Implementation of Keymap class 241// Implementation of Keymap class
238Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { 242Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) {
239 repeatDelay=400; 243 repeatDelay=400;
240 repeatPeriod=80; 244 repeatPeriod=80;
241 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); 245 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat()));
242} 246}
243 247
244Keymap::~Keymap() { 248Keymap::~Keymap() {
245 QMap<QString, State*>::Iterator it; 249 QMap<QString, State*>::Iterator it;
246 for(it = states.begin(); it != states.end(); ++it) { 250 for(it = states.begin(); it != states.end(); ++it) {
247 delete it.data(); 251 delete it.data();
248 } 252 }
249 states.clear(); 253 states.clear();
250} 254}
251 255
252bool Keymap::filter(int unicode, int keycode, int modifiers, 256bool Keymap::filter(int unicode, int keycode, int modifiers,
253 bool isPress, bool autoRepeat) { 257 bool isPress, bool autoRepeat) {
254 258
255 qDebug("filter: >>> unicode=%x, keycode=%x, modifiers=%x, " 259 odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode
256 "ispressed=%x\n", unicode, keycode, modifiers, isPress); 260 << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl;
257 261
258 if (!enabled) { 262 if (!enabled) {
259 return false; 263 return false;
260 } 264 }
261 265
262 // the second check is workaround to make suspend work if 266 // the second check is workaround to make suspend work if
263 // the user pressed it right after he did resume. for some 267 // the user pressed it right after he did resume. for some
264 // reason the event sent by qt has autoRepeat true in this 268 // reason the event sent by qt has autoRepeat true in this
265 // case 269 // case
266 if (autoRepeat && keycode != 4177) { 270 if (autoRepeat && keycode != 4177) {
267 return true; 271 return true;
268 } 272 }
269 273
270 (void) unicode; (void) modifiers; 274 (void) unicode; (void) modifiers;
271 275
272 Action* action = currentState->get(keycode, isPress, true); 276 Action* action = currentState->get(keycode, isPress, true);
273 if (action==0 || !action->isDefined()) { 277 if (action==0 || !action->isDefined()) {
274 return true; 278 return true;
275 } 279 }
276 280
277 if (action->hasEvent()) { 281 if (action->hasEvent()) {
278 qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, " 282 odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode()
279 "ispressed=%x\n", action->getUnicode(), 283 << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl;
280 action->getKeycode(), action->getModifiers(),
281 action->isPressed());
282 284
283 QWSServer::sendKeyEvent(action->getUnicode(), 285 QWSServer::sendKeyEvent(action->getUnicode(),
284 action->getKeycode(), action->getModifiers(), 286 action->getKeycode(), action->getModifiers(),
285 action->isPressed(), false); 287 action->isPressed(), false);
286 } 288 }
287 289
288 if (action->isAutorepeat()) { 290 if (action->isAutorepeat()) {
289 autoRepeatAction = action; 291 autoRepeatAction = action;
290 repeater.start(repeatDelay, TRUE); 292 repeater.start(repeatDelay, TRUE);
291 } else { 293 } else {
292 autoRepeatAction = 0; 294 autoRepeatAction = 0;
293 } 295 }
294 296
295 State* nstate = action->getState(); 297 State* nstate = action->getState();
296 if (nstate != 0) { 298 if (nstate != 0) {
297 setCurrentState(nstate); 299 setCurrentState(nstate);
298 QString lbl = getCurrentLabel(); 300 QString lbl = getCurrentLabel();
299 if (!lbl.isEmpty()) { 301 if (!lbl.isEmpty()) {
300 emit stateChanged(lbl); 302 emit stateChanged(lbl);
301 } 303 }
302 } 304 }
303 305
304 306
305 return true; 307 return true;
306} 308}
307 309
308void Keymap::enable() { 310void Keymap::enable() {
309 enabled = true; 311 enabled = true;
310} 312}
311 313
312void Keymap::disable() { 314void Keymap::disable() {
313 enabled = false; 315 enabled = false;
314} 316}
315 317
316QStringList Keymap::listStates() { 318QStringList Keymap::listStates() {
317 QStringList ret; 319 QStringList ret;
318 320
319 QMap<QString, State*>::Iterator it; 321 QMap<QString, State*>::Iterator it;
320 for(it = states.begin(); it != states.end(); ++it) { 322 for(it = states.begin(); it != states.end(); ++it) {
321 ret.append(it.key()); 323 ret.append(it.key());
322 } 324 }
323 325
324 return ret; 326 return ret;
325} 327}
326 328
327State* Keymap::getStateByName(const QString& name) { 329State* Keymap::getStateByName(const QString& name) {
328 QMap<QString, State*>::Iterator it = states.find(name); 330 QMap<QString, State*>::Iterator it = states.find(name);
329 331
330 if (it == states.end()) { 332 if (it == states.end()) {
331 return 0; 333 return 0;
332 } 334 }
333 335
334 return it.data(); 336 return it.data();
335} 337}
336 338
337QStringList Keymap::listLabels() { 339QStringList Keymap::listLabels() {
338 QStringList ret; 340 QStringList ret;
339 341
340 for(uint i = 0; i < labelList.count(); i++) { 342 for(uint i = 0; i < labelList.count(); i++) {
341 ret.append(*labelList.at(i)); 343 ret.append(*labelList.at(i));
342 } 344 }
343 345
344 return ret; 346 return ret;
345} 347}
346 348
347State* Keymap::getStateByLabel(const QString& label) { 349State* Keymap::getStateByLabel(const QString& label) {
348 QMap<QString, QString>::Iterator lit = labels.find(label); 350 QMap<QString, QString>::Iterator lit = labels.find(label);
349 State* state = 0; 351 State* state = 0;
350 352
351 if (lit == labels.end()) { 353 if (lit == labels.end()) {
352 return 0; 354 return 0;
353 } 355 }
354 356
355 QString name = lit.data(); 357 QString name = lit.data();
356 358
357 int n = name.find(":*"); 359 int n = name.find(":*");
358 if (n>=0 && n==(int)(name.length()-2)) { 360 if (n>=0 && n==(int)(name.length()-2)) {
359 name=name.left(name.length() - 1); 361 name=name.left(name.length() - 1);
360 362
361 n = currentStateName.findRev(":"); 363 n = currentStateName.findRev(":");
362 if (n >= 0) { 364 if (n >= 0) {
363 name += currentStateName.mid(n+1); 365 name += currentStateName.mid(n+1);
364 } 366 }
365 } 367 }
366 368
367 //odebug << "look for: " << name.utf8() << "\n" << oendl; 369// odebug << "look for: " << name.utf8() << "\n" << oendl;
368 QMap<QString, State*>::Iterator sit = states.find(name); 370 QMap<QString, State*>::Iterator sit = states.find(name);
369 if (sit != states.end()) { 371 if (sit != states.end()) {
370 state = sit.data(); 372 state = sit.data();
371 } 373 }
372 374
373 return state; 375 return state;
374} 376}
375 377
376bool Keymap::addState(const QString& name, State* state) { 378bool Keymap::addState(const QString& name, State* state) {
377 if (states.find(name) != states.end()) { 379 if (states.find(name) != states.end()) {
378 return false; 380 return false;
379 } 381 }
380 382
381 states.insert(name, state); 383 states.insert(name, state);
382 lsmapInSync = false; 384 lsmapInSync = false;
383 385
384 if (currentState == 0) { 386 if (currentState == 0) {
385 setCurrentState(state); 387 setCurrentState(state);
386 } 388 }
387 389
388 return true; 390 return true;
389} 391}
390 392
391State* Keymap::getCurrentState() const { 393State* Keymap::getCurrentState() const {
392 return currentState; 394 return currentState;
393} 395}
394 396
395QString Keymap::getCurrentLabel() { 397QString Keymap::getCurrentLabel() {
396 return currentLabel; 398 return currentLabel;
397} 399}
398 400
399bool Keymap::setCurrentState(State* state) { 401bool Keymap::setCurrentState(State* state) {
400 QMap<QString, State*>::Iterator it; 402 QMap<QString, State*>::Iterator it;
401 for(it = states.begin(); it != states.end(); ++it) { 403 for(it = states.begin(); it != states.end(); ++it) {
402 State* s = it.data(); 404 State* s = it.data();
403 if (s == state) { 405 if (s == state) {
404 currentState = s; 406 currentState = s;
405 currentStateName = it.key(); 407 currentStateName = it.key();
406 408
407 qDebug("state changed: %s\n", (const char*) 409 odebug << "state changed: " << (const char*)currentStateName.utf8() << oendl;
408 currentStateName.utf8());
409 410
410 if (!lsmapInSync) { 411 if (!lsmapInSync) {
411 generateLabelStateMaps(); 412 generateLabelStateMaps();
412 } 413 }
413 414
414 QMap<State*, QString>::Iterator tit; 415 QMap<State*, QString>::Iterator tit;
415 tit = stateLabelMap.find(state); 416 tit = stateLabelMap.find(state);
416 if (tit != stateLabelMap.end()) { 417 if (tit != stateLabelMap.end()) {
417 currentLabel = tit.data(); 418 currentLabel = tit.data();
418 } else { 419 } else {
419 // odebug << "no label for: " + currentStateName + "\n" << oendl; 420// odebug << "no label for: " + currentStateName + "\n" << oendl;
420 currentLabel = ""; 421 currentLabel = "";
421 } 422 }
422 423
423 return true; 424 return true;
424 } 425 }
425 } 426 }
426 427
427 return false; 428 return false;
428} 429}
429 430
430bool Keymap::removeState(const QString& name, bool force) { 431bool Keymap::removeState(const QString& name, bool force) {
431 QMap<QString, State*>::Iterator it = states.find(name); 432 QMap<QString, State*>::Iterator it = states.find(name);
432 433
433 if (it == states.end()) { 434 if (it == states.end()) {
434 return false; 435 return false;
435 } 436 }
436 437
437 State* state = it.data(); 438 State* state = it.data();
438 QList<Action> acts = findStateUsage(state); 439 QList<Action> acts = findStateUsage(state);
439 440
440 if (!acts.isEmpty()) { 441 if (!acts.isEmpty()) {
441 if (!force) { 442 if (!force) {
442 return false; 443 return false;
443 } else { 444 } else {
444 for(Action* a = acts.first(); a != 0; a = acts.next()) { 445 for(Action* a = acts.first(); a != 0; a = acts.next()) {
445 a->setState(0); 446 a->setState(0);
446 } 447 }
447 } 448 }
448 } 449 }
449 450
450 if (state == currentState) { 451 if (state == currentState) {
451 if (states.begin() != states.end()) { 452 if (states.begin() != states.end()) {
452 setCurrentState(states.begin().data()); 453 setCurrentState(states.begin().data());
453 } 454 }
454 } 455 }
455 456
456 states.remove(it); 457 states.remove(it);
457 delete state; 458 delete state;
458 459
459 lsmapInSync = false; 460 lsmapInSync = false;
460 461
461 return true; 462 return true;
462} 463}
463 464
464void Keymap::autoRepeat() { 465void Keymap::autoRepeat() {
465 if (autoRepeatAction != 0) { 466 if (autoRepeatAction != 0) {
466 qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, " 467 odebug << "filter:<<< unicode=" << autoRepeatAction->getUnicode()
467 "ispressed=%x\n", autoRepeatAction->getUnicode(), 468 << ", keycode=" << autoRepeatAction->getKeycode()
468 autoRepeatAction->getKeycode(), 469 << ", modifiers=" << autoRepeatAction->getModifiers()
469 autoRepeatAction->getModifiers(), 470 << "ispressed=" << autoRepeatAction->isPressed() << oendl;
470 autoRepeatAction->isPressed());
471 471
472 QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(), 472 QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(),
473 autoRepeatAction->getKeycode(), 473 autoRepeatAction->getKeycode(),
474 autoRepeatAction->getModifiers(), 474 autoRepeatAction->getModifiers(),
475 autoRepeatAction->isPressed(), true); 475 autoRepeatAction->isPressed(), true);
476 } 476 }
477 477
478 repeater.start(repeatPeriod, TRUE); 478 repeater.start(repeatPeriod, TRUE);
479} 479}
480 480
481bool Keymap::addLabel(const QString& label, const QString& state, int index) { 481bool Keymap::addLabel(const QString& label, const QString& state, int index) {
482 if (labels.find(label) != labels.end()) { 482 if (labels.find(label) != labels.end()) {
483 return false; 483 return false;
484 } 484 }
485 485
486 labels.insert(label, state); 486 labels.insert(label, state);
487 const QString& l = labels.find(label).key(); 487 const QString& l = labels.find(label).key();
488 if (index == -1) { 488 if (index == -1) {
489 labelList.append(l); 489 labelList.append(l);
490 } else { 490 } else {
491 labelList.insert(labelList.at(index), l); 491 labelList.insert(labelList.at(index), l);
492 } 492 }
493 493
494 lsmapInSync = false; 494 lsmapInSync = false;
495 495
496 return true; 496 return true;
497} 497}
498 498
499bool Keymap::removeLabel(const QString& label) { 499bool Keymap::removeLabel(const QString& label) {
500 500
501 if (labels.find(label) == labels.end()) { 501 if (labels.find(label) == labels.end()) {
502 return false; 502 return false;
503 } 503 }
504 504
505 labels.remove(label); 505 labels.remove(label);
506 labelList.remove(label); 506 labelList.remove(label);
507 lsmapInSync = false; 507 lsmapInSync = false;
508 508
509 if (label == currentLabel) { 509 if (label == currentLabel) {
510 currentLabel = ""; 510 currentLabel = "";
511 } 511 }
512 512
513 return true; 513 return true;
514} 514}
515 515
516int Keymap::getAutorepeatDelay() const { 516int Keymap::getAutorepeatDelay() const {
517 return repeatDelay; 517 return repeatDelay;
518} 518}
519 519
520void Keymap::setAutorepeatDelay(int n) { 520void Keymap::setAutorepeatDelay(int n) {
521 repeatDelay = n; 521 repeatDelay = n;
522} 522}
523 523
524int Keymap::getAutorepeatPeriod() const { 524int Keymap::getAutorepeatPeriod() const {
525 return repeatPeriod; 525 return repeatPeriod;
526} 526}
527 527
528void Keymap::setAutorepeatPeriod(int n) { 528void Keymap::setAutorepeatPeriod(int n) {
529 repeatPeriod = n; 529 repeatPeriod = n;
530} 530}
531 531
532QList<Action> Keymap::findStateUsage(State* s) { 532QList<Action> Keymap::findStateUsage(State* s) {
533 QList<Action> ret; 533 QList<Action> ret;
534 534
535 QMap<QString, State*>::Iterator it; 535 QMap<QString, State*>::Iterator it;
536 for(it = states.begin(); it != states.end(); ++it) { 536 for(it = states.begin(); it != states.end(); ++it) {
537 State* state = it.data(); 537 State* state = it.data();
538 538
539 for(int i = 0; i < 0x1100; i++) { 539 for(int i = 0; i < 0x1100; i++) {
540 Action* action = state->get(i, false); 540 Action* action = state->get(i, false);
541 if (action!=0 && action->getState()==s) { 541 if (action!=0 && action->getState()==s) {
542 ret.append(action); 542 ret.append(action);
543 } 543 }
544 544
545 action = state->get(i, true); 545 action = state->get(i, true);
546 if (action!=0 && action->getState()==s) { 546 if (action!=0 && action->getState()==s) {
547 ret.append(action); 547 ret.append(action);
548 } 548 }
549 } 549 }
550 } 550 }
551 551
552 return ret; 552 return ret;
553} 553}
554 554
555void Keymap::generateLabelStateMaps() { 555void Keymap::generateLabelStateMaps() {
556 stateLabelMap.clear(); 556 stateLabelMap.clear();
557 557
558 QMap<QString, QString>::Iterator lit; 558 QMap<QString, QString>::Iterator lit;
559 for(lit = labels.begin(); lit != labels.end(); ++lit) { 559 for(lit = labels.begin(); lit != labels.end(); ++lit) {
560 QString label = lit.key(); 560 QString label = lit.key();
561 QString name = lit.data(); 561 QString name = lit.data();
562 562
563 bool wc = false; 563 bool wc = false;
564 int n = name.find("*"); 564 int n = name.find("*");
565 if (n>=0 && n==(int)(name.length()-1)) { 565 if (n>=0 && n==(int)(name.length()-1)) {
566 name=name.left(name.length() - 1); 566 name=name.left(name.length() - 1);
567 wc = true; 567 wc = true;
568 } 568 }
569 569
570 QMap<QString, State*>::Iterator sit; 570 QMap<QString, State*>::Iterator sit;
571 for(sit = states.begin(); sit != states.end(); ++sit) { 571 for(sit = states.begin(); sit != states.end(); ++sit) {
572 QString sname = sit.key(); 572 QString sname = sit.key();
573 State* state = sit.data(); 573 State* state = sit.data();
574 574
575 if (sname.length() < name.length()) { 575 if (sname.length() < name.length()) {
576 continue; 576 continue;
577 } 577 }
578 578
579 if (sname.left(name.length()) == name) { 579 if (sname.left(name.length()) == name) {
580 if (wc || sname.length()==name.length()) { 580 if (wc || sname.length()==name.length()) {
581 stateLabelMap.insert(state, label); 581 stateLabelMap.insert(state, label);
582 } 582 }
583 583
584 } 584 }
585 } 585 }
586 } 586 }
587 587
588 lsmapInSync = true; 588 lsmapInSync = true;
589} 589}
diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
index be2b897..f14080f 100644
--- a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
+++ b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
@@ -421,8 +421,9 @@ void Gutenbrowser::ForwardBtn() {
421 // int length = Lview->length(); 421 // int length = Lview->length();
422 422
423 pageStopArray[i_pageNum ] = currentFilePos; 423 pageStopArray[i_pageNum ] = currentFilePos;
424 // qDebug("%d current page is number %d, pagesize %d, length %d, current %d", 424 // odebug << currentFilePos << " current page is number " << i_pageNum
425 // currentFilePos, i_pageNum, pageSize, Lview->length(), pageStopArray[i_pageNum] ); 425 // << ", pagesize " << pageSize << ", length " << Lview->length()
426 // << ", current " << pageStopArray[i_pageNum] << oendl;
426 setStatus(); 427 setStatus();
427 Lview->setCursorPosition( 0, 0, FALSE); 428 Lview->setCursorPosition( 0, 0, FALSE);
428 // } 429 // }
@@ -455,8 +456,9 @@ void Gutenbrowser::BackBtn() {
455 i_pageNum--; 456 i_pageNum--;
456 currentFilePos = f.at(); 457 currentFilePos = f.at();
457 458
458 // qDebug("%d move back to %d, current page number %d, %d, length %d", 459 // odebug << currentFilePos << " move back to " << pageStopArray[i_pageNum - 1 ]
459 // currentFilePos, pageStopArray[i_pageNum - 1 ], i_pageNum, pageSize, Lview->length() ); 460 // << ", current page number " << i_pageNum
461 // << ", " << pageSize << ", length " << Lview->length() << oendl;
460 462
461 if( i_pageNum < 2) { 463 if( i_pageNum < 2) {
462 f.at( 0); 464 f.at( 0);
@@ -799,8 +801,9 @@ bool Gutenbrowser::load( const char *fileName) {
799 801
800 pageStopArray[1] = currentFilePos; 802 pageStopArray[1] = currentFilePos;
801 803
802 qDebug("<<<<<<<<<<<%d current page is number %d, length %d, current %d, pageSize %d", 804 odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum
803 currentFilePos, i_pageNum, Lview->length(), pageStopArray[i_pageNum], Lview->PageSize() ); 805 << ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum]
806 << ", pageSize " << Lview->PageSize() << oendl;
804 807
805 Lview->setMaxLines(Lview->PageSize()*2); 808 Lview->setMaxLines(Lview->PageSize()*2);
806 odebug << "Gulped " << currentLine << "" << oendl; 809 odebug << "Gulped " << currentLine << "" << oendl;
diff --git a/noncore/apps/opie-reader/BuffDoc.h b/noncore/apps/opie-reader/BuffDoc.h
index 29d0329..61531c0 100644
--- a/noncore/apps/opie-reader/BuffDoc.h
+++ b/noncore/apps/opie-reader/BuffDoc.h
@@ -21,24 +21,24 @@ class BuffDoc
21 CFilterChain* filt; 21 CFilterChain* filt;
22 public: 22 public:
23 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) 23 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
24 { 24 {
25 if (exp == NULL) 25 if (exp == NULL)
26 { 26 {
27 data = NULL; 27 data = NULL;
28 len = 0; 28 len = 0;
29 } 29 }
30 else 30 else
31 { 31 {
32 exp->setSaveData(data, len, src, srclen); 32 exp->setSaveData(data, len, src, srclen);
33 } 33 }
34 } 34 }
35 void putSaveData(unsigned char*& src, unsigned short& srclen) 35 void putSaveData(unsigned char*& src, unsigned short& srclen)
36 { 36 {
37 if (exp != NULL) 37 if (exp != NULL)
38 { 38 {
39 exp->putSaveData(src, srclen); 39 exp->putSaveData(src, srclen);
40 } 40 }
41 } 41 }
42#ifdef USEQPE 42#ifdef USEQPE
43 void suspend() { if (exp != NULL) exp->suspend(); } 43 void suspend() { if (exp != NULL) exp->suspend(); }
44 void unsuspend() { if (exp != NULL) exp->unsuspend(); } 44 void unsuspend() { if (exp != NULL) exp->unsuspend(); }
@@ -47,47 +47,47 @@ class BuffDoc
47 void unsuspend() {} 47 void unsuspend() {}
48#endif 48#endif
49 ~BuffDoc() 49 ~BuffDoc()
50 { 50 {
51 delete filt; 51 delete filt;
52 delete exp; 52 delete exp;
53 } 53 }
54 BuffDoc() 54 BuffDoc()
55 { 55 {
56 exp = NULL; 56 exp = NULL;
57 filt = NULL; 57 filt = NULL;
58 lastword.empty(); 58 lastword.empty();
59 // // qDebug("Buffdoc created"); 59 // odebug << "Buffdoc created" << oendl;
60 } 60 }
61 bool empty() { return (exp == NULL); } 61 bool empty() { return (exp == NULL); }
62 void setfilter(CFilterChain* _f) 62 void setfilter(CFilterChain* _f)
63 { 63 {
64 if (filt != NULL) delete filt; 64 if (filt != NULL) delete filt;
65 filt = _f; 65 filt = _f;
66 filt->setsource(exp); 66 filt->setsource(exp);
67 } 67 }
68 CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); } 68 CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); }
69 bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); } 69 bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); }
70 bool iseol() { return (lastword[0] == '\0'); } 70 bool iseol() { return (lastword[0] == '\0'); }
71 int openfile(QWidget* _parent, const char *src); 71 int openfile(QWidget* _parent, const char *src);
72 tchar getch() 72 tchar getch()
73 { 73 {
74 tchar ch = UEOF; 74 tchar ch = UEOF;
75 CStyle sty; 75 CStyle sty;
76 if (exp != NULL) 76 if (exp != NULL)
77 { 77 {
78 filt->getch(ch, sty); 78 filt->getch(ch, sty);
79 } 79 }
80 return ch; 80 return ch;
81 } 81 }
82 void getch(tchar& ch, CStyle& sty) 82 void getch(tchar& ch, CStyle& sty)
83 { 83 {
84 if (exp != NULL) 84 if (exp != NULL)
85 { 85 {
86 filt->getch(ch, sty); 86 filt->getch(ch, sty);
87 } 87 }
88 else 88 else
89 ch = UEOF; 89 ch = UEOF;
90 } 90 }
91 void setwidth(int w) { if (exp != NULL) exp->setwidth(w); } 91 void setwidth(int w) { if (exp != NULL) exp->setwidth(w); }
92 QImage* getPicture(unsigned long tgt) { return (exp == NULL) ? NULL : exp->getPicture(tgt); } 92 QImage* getPicture(unsigned long tgt) { return (exp == NULL) ? NULL : exp->getPicture(tgt); }
93 unsigned int startSection() { return (exp == NULL) ? 0 : exp->startSection(); } 93 unsigned int startSection() { return (exp == NULL) ? 0 : exp->startSection(); }
@@ -103,15 +103,15 @@ class BuffDoc
103 bool getline(CDrawBuffer* buff, int w, int cw, unsigned char _border); 103 bool getline(CDrawBuffer* buff, int w, int cw, unsigned char _border);
104 void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); } 104 void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); }
105 int getpara(CBuffer& buff) 105 int getpara(CBuffer& buff)
106 { 106 {
107 tchar ch; 107 tchar ch;
108 int i = 0; 108 int i = 0;
109 while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch; 109 while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch;
110 buff[i] = '\0'; 110 buff[i] = '\0';
111 if (i == 0 && ch == UEOF) i = -1; 111 if (i == 0 && ch == UEOF) i = -1;
112 laststartline = exp->locate(); 112 laststartline = exp->locate();
113 return i; 113 return i;
114 } 114 }
115 void saveposn(size_t posn) { exp->saveposn(posn); } 115 void saveposn(size_t posn) { exp->saveposn(posn); }
116 void writeposn(size_t posn) { exp->writeposn(posn); } 116 void writeposn(size_t posn) { exp->writeposn(posn); }
117 bool forward(size_t& loc) { return exp->forward(loc); } 117 bool forward(size_t& loc) { return exp->forward(loc); }
diff --git a/noncore/apps/opie-reader/CEncoding.h b/noncore/apps/opie-reader/CEncoding.h
index 463fba9..df0104a 100644
--- a/noncore/apps/opie-reader/CEncoding.h
+++ b/noncore/apps/opie-reader/CEncoding.h
@@ -60,15 +60,15 @@ class CGeneral8Bit : public CEncoding
60 int m_index; 60 int m_index;
61 public: 61 public:
62 CGeneral8Bit(int _i) : m_index(_i) 62 CGeneral8Bit(int _i) : m_index(_i)
63 { 63 {
64 // qDebug("8Bit:%d", _i); 64// odebug << "8Bit: " << _i << oendl;
65 // qDebug("%s", unicodetable::iterator(_i)->mime); 65// odebug << unicodetable::iterator(_i)->mime << oendl;
66 } 66 }
67 void getch(tchar& ch, CStyle& sty) 67 void getch(tchar& ch, CStyle& sty)
68 { 68 {
69 parent->getch(ch, sty); 69 parent->getch(ch, sty);
70 ch = unicodetable::unicodevalue(m_index, ch); 70 ch = unicodetable::unicodevalue(m_index, ch);
71 } 71 }
72}; 72};
73 73
74#endif 74#endif
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h
index 7b21d3e..9fae245 100644
--- a/noncore/apps/opie-reader/CExpander.h
+++ b/noncore/apps/opie-reader/CExpander.h
@@ -40,18 +40,18 @@ class CExpander
40 unsigned long m_currentstart, m_currentend; 40 unsigned long m_currentstart, m_currentend;
41 public: 41 public:
42#ifdef USEQPE 42#ifdef USEQPE
43 virtual void suspend() = 0; 43 virtual void suspend() = 0;
44 virtual void unsuspend() = 0; 44 virtual void unsuspend() = 0;
45#endif 45#endif
46 size_t getHome() { return m_homepos; } 46 size_t getHome() { return m_homepos; }
47 CExpander() : m_homepos(0), fname(NULL), m_scrWidth(240), m_currentstart(1), m_currentend(0) {}; 47 CExpander() : m_homepos(0), fname(NULL), m_scrWidth(240), m_currentstart(1), m_currentend(0) {};
48 virtual ~CExpander() { if (fname != NULL) delete [] fname; }; 48 virtual ~CExpander() { if (fname != NULL) delete [] fname; };
49 int openfile(const char *src) 49 int openfile(const char *src)
50 { 50 {
51 bSuspended = false; 51 bSuspended = false;
52 fname = strdup(src); 52 fname = strdup(src);
53 return OpenFile(src); 53 return OpenFile(src);
54 } 54 }
55 virtual int OpenFile(const char *src) = 0; 55 virtual int OpenFile(const char *src) = 0;
56 virtual unsigned int locate() = 0; 56 virtual unsigned int locate() = 0;
57 virtual void locate(unsigned int n) = 0; 57 virtual void locate(unsigned int n) = 0;
@@ -59,17 +59,17 @@ class CExpander
59 virtual void sizes(unsigned long& file, unsigned long& text) = 0; 59 virtual void sizes(unsigned long& file, unsigned long& text) = 0;
60 virtual CList<Bkmk>* getbkmklist() { return NULL; } 60 virtual CList<Bkmk>* getbkmklist() { return NULL; }
61 virtual void getch(tchar& ch, CStyle& sty) 61 virtual void getch(tchar& ch, CStyle& sty)
62 { 62 {
63 int ich = getch(); 63 int ich = getch();
64 ch = (ich == EOF) ? UEOF : ich; 64 ch = (ich == EOF) ? UEOF : ich;
65 sty.unset(); 65 sty.unset();
66 } 66 }
67 virtual int getch() = 0; 67 virtual int getch() = 0;
68 virtual linkType hyperlink(unsigned int n, QString& wrd) 68 virtual linkType hyperlink(unsigned int n, QString& wrd)
69 { 69 {
70 locate(n); 70 locate(n);
71 return eLink; 71 return eLink;
72 } 72 }
73 virtual MarkupType PreferredMarkup() = 0; 73 virtual MarkupType PreferredMarkup() = 0;
74 virtual void saveposn(size_t posn) {} 74 virtual void saveposn(size_t posn) {}
75 virtual void writeposn(size_t posn) {} 75 virtual void writeposn(size_t posn) {}
@@ -77,75 +77,75 @@ class CExpander
77 virtual bool back(size_t& loc) { return false; } 77 virtual bool back(size_t& loc) { return false; }
78 virtual bool hasnavigation() { return false; } 78 virtual bool hasnavigation() { return false; }
79 unsigned long startSection() 79 unsigned long startSection()
80 { 80 {
81 unsigned long current = locate(); 81 unsigned long current = locate();
82 if (m_currentstart > current || current > m_currentend) 82 if (m_currentstart > current || current > m_currentend)
83 { 83 {
84 start2endSection(); 84 start2endSection();
85 } 85 }
86 return m_currentstart; 86 return m_currentstart;
87 } 87 }
88 unsigned long endSection() 88 unsigned long endSection()
89 { 89 {
90 unsigned long current = locate(); 90 unsigned long current = locate();
91 if (m_currentstart > current || current > m_currentend) 91 if (m_currentstart > current || current > m_currentend)
92 { 92 {
93 start2endSection(); 93 start2endSection();
94 } 94 }
95 return m_currentend; 95 return m_currentend;
96 } 96 }
97 virtual void start2endSection() 97 virtual void start2endSection()
98 { 98 {
99 m_currentstart = 0; 99 m_currentstart = 0;
100 unsigned long file; 100 unsigned long file;
101 sizes(file, m_currentend); 101 sizes(file, m_currentend);
102 } 102 }
103 virtual QImage* getPicture(unsigned long tgt) { return NULL; } 103 virtual QImage* getPicture(unsigned long tgt) { return NULL; }
104 void setContinuous(bool _b) { m_continuous = _b; } 104 void setContinuous(bool _b) { m_continuous = _b; }
105#ifdef USEQPE 105#ifdef USEQPE
106 virtual void suspend(FILE*& fin) 106 virtual void suspend(FILE*& fin)
107 { 107 {
108 bSuspended = true; 108 bSuspended = true;
109 suspos = ftell(fin); 109 suspos = ftell(fin);
110 fclose(fin); 110 fclose(fin);
111 fin = NULL; 111 fin = NULL;
112 sustime = time(NULL); 112 sustime = time(NULL);
113 } 113 }
114 virtual void unsuspend(FILE*& fin) 114 virtual void unsuspend(FILE*& fin)
115 { 115 {
116 if (bSuspended) 116 if (bSuspended)
117 { 117 {
118 bSuspended = false; 118 bSuspended = false;
119 int delay = time(NULL) - sustime; 119 int delay = time(NULL) - sustime;
120 if (delay < 10) sleep(10-delay); 120 if (delay < 10) sleep(10-delay);
121 fin = fopen(fname, "rb"); 121 fin = fopen(fname, "rb");
122 for (int i = 0; fin == NULL && i < 5; i++) 122 for (int i = 0; fin == NULL && i < 5; i++)
123 { 123 {
124 sleep(5); 124 sleep(5);
125 fin = fopen(fname, "rb"); 125 fin = fopen(fname, "rb");
126 } 126 }
127 if (fin == NULL) 127 if (fin == NULL)
128 { 128 {
129 QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file"); 129 QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file");
130 exit(0); 130 exit(0);
131 } 131 }
132 suspos = fseek(fin, suspos, SEEK_SET); 132 suspos = fseek(fin, suspos, SEEK_SET);
133 } 133 }
134 } 134 }
135#endif 135#endif
136 virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) 136 virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
137 { 137 {
138 len = srclen; 138 len = srclen;
139 data = new unsigned char[len]; 139 data = new unsigned char[len];
140 memcpy(data, src, len); 140 memcpy(data, src, len);
141 } 141 }
142 virtual void putSaveData(unsigned char*& src, unsigned short& srclen) 142 virtual void putSaveData(unsigned char*& src, unsigned short& srclen)
143 { 143 {
144 if (srclen != 0) 144 if (srclen != 0)
145 { 145 {
146 qDebug("Don't know what to do with non-zero save data"); 146 qDebug("Don't know what to do with non-zero save data");
147 } 147 }
148 } 148 }
149 void setwidth(int w) { m_scrWidth = w; } 149 void setwidth(int w) { m_scrWidth = w; }
150}; 150};
151#endif 151#endif
diff --git a/noncore/apps/opie-reader/Filedata.h b/noncore/apps/opie-reader/Filedata.h
index 096dd31..1b85b71 100644
--- a/noncore/apps/opie-reader/Filedata.h
+++ b/noncore/apps/opie-reader/Filedata.h
@@ -9,43 +9,43 @@ class CFiledata
9 bool m_own; 9 bool m_own;
10 public: 10 public:
11 CFiledata(tchar* d) 11 CFiledata(tchar* d)
12 { 12 {
13 data = (unsigned char*)d; 13 data = (unsigned char*)d;
14 m_own = false; 14 m_own = false;
15 } 15 }
16 CFiledata(time_t dt, tchar* nm) 16 CFiledata(time_t dt, tchar* nm)
17 { 17 {
18 int nlen = ustrlen(nm)+1; 18 int nlen = ustrlen(nm)+1;
19 data = new unsigned char[sizeof(time_t)+sizeof(tchar)*nlen]; 19 data = new unsigned char[sizeof(time_t)+sizeof(tchar)*nlen];
20 *((time_t *)data) = dt; 20 *((time_t *)data) = dt;
21 memcpy(data+sizeof(time_t), nm, sizeof(tchar)*nlen); 21 memcpy(data+sizeof(time_t), nm, sizeof(tchar)*nlen);
22 m_own = true; 22 m_own = true;
23 } 23 }
24 ~CFiledata() 24 ~CFiledata()
25 { 25 {
26 if (m_own && data != NULL) 26 if (m_own && data != NULL)
27 { 27 {
28 delete [] data; 28 delete [] data;
29 // qDebug("~Filedata: deleting"); 29// odebug << "~Filedata: deleting" << oendl;
30 } 30 }
31 else 31 else
32 { 32 {
33 // qDebug("~Filedata: not deleting"); 33// odebug << "~Filedata: not deleting" << oendl;
34 } 34 }
35 } 35 }
36 tchar* name() const { return (tchar*)(data+sizeof(time_t)); } 36 tchar* name() const { return (tchar*)(data+sizeof(time_t)); }
37 time_t date() { return *((time_t *)data); } 37 time_t date() { return *((time_t *)data); }
38 void setdate(time_t _t) { *((time_t *)data) = _t; } 38 void setdate(time_t _t) { *((time_t *)data) = _t; }
39 unsigned char* content() { return data; } 39 unsigned char* content() { return data; }
40 size_t length() const { return sizeof(time_t)+sizeof(tchar)*(ustrlen(name())+1); } 40 size_t length() const { return sizeof(time_t)+sizeof(tchar)*(ustrlen(name())+1); }
41 bool operator==(const CFiledata& rhs) 41 bool operator==(const CFiledata& rhs)
42 { 42 {
43 return ((length() == rhs.length()) && (memcmp(data, rhs.data, length()) == 0)); 43 return ((length() == rhs.length()) && (memcmp(data, rhs.data, length()) == 0));
44 } 44 }
45 bool samename(const CFiledata& rhs) 45 bool samename(const CFiledata& rhs)
46 { 46 {
47 return (ustrcmp((tchar *)(data+sizeof(time_t)),(tchar *)(rhs.data+sizeof(time_t))) == 0); 47 return (ustrcmp((tchar *)(data+sizeof(time_t)),(tchar *)(rhs.data+sizeof(time_t))) == 0);
48 } 48 }
49}; 49};
50 50
51#endif 51#endif
diff --git a/noncore/apps/opie-reader/FontControl.h b/noncore/apps/opie-reader/FontControl.h
index 5681496..e56b619 100644
--- a/noncore/apps/opie-reader/FontControl.h
+++ b/noncore/apps/opie-reader/FontControl.h
@@ -20,134 +20,134 @@ class FontControl
20 unsigned char getBaseSize() { return m_basesize; } 20 unsigned char getBaseSize() { return m_basesize; }
21 int gzoom(); 21 int gzoom();
22 FontControl(QString n = "helvetica", int size = 10) 22 FontControl(QString n = "helvetica", int size = 10)
23 : 23 :
24 m_fontsizes(NULL), m_hasCourier(false), m_leading(0), m_extraspace(0) 24 m_fontsizes(NULL), m_hasCourier(false), m_leading(0), m_extraspace(0)
25 { 25 {
26 ChangeFont(n, size); 26 ChangeFont(n, size);
27 } 27 }
28 ~FontControl() 28 ~FontControl()
29 { 29 {
30 if (m_fontsizes != NULL) delete [] m_fontsizes; 30 if (m_fontsizes != NULL) delete [] m_fontsizes;
31 } 31 }
32 void hasCourier(bool _b, const QString& _nm) 32 void hasCourier(bool _b, const QString& _nm)
33 { 33 {
34 m_hasCourier = _b; 34 m_hasCourier = _b;
35 m_fixedfontname = _nm; 35 m_fixedfontname = _nm;
36 } 36 }
37 QString& fixedfontname() { return m_fixedfontname; } 37 QString& fixedfontname() { return m_fixedfontname; }
38 bool hasCourier() { return m_hasCourier; } 38 bool hasCourier() { return m_hasCourier; }
39 QString name() { return m_fontname; } 39 QString name() { return m_fontname; }
40 int currentsize() { return m_fontsizes[m_size]; } 40 int currentsize() { return m_fontsizes[m_size]; }
41 int getsize(const CStyle& size) 41 int getsize(const CStyle& size)
42 { 42 {
43 int tgt = m_size+size.getFontSize(); 43 int tgt = m_size+size.getFontSize();
44 if (tgt < 0) 44 if (tgt < 0)
45 { 45 {
46 tgt = 0; 46 tgt = 0;
47 } 47 }
48 if (tgt >= m_maxsize) 48 if (tgt >= m_maxsize)
49 { 49 {
50 tgt = m_maxsize - 1; 50 tgt = m_maxsize - 1;
51 } 51 }
52 return m_fontsizes[tgt]; 52 return m_fontsizes[tgt];
53 } 53 }
54 int ascent() 54 int ascent()
55 { 55 {
56 QFont f(name(), currentsize()); 56 QFont f(name(), currentsize());
57 QFontMetrics fm(f); 57 QFontMetrics fm(f);
58 return fm.ascent(); 58 return fm.ascent();
59 } 59 }
60 int ascent(const CStyle& ch) 60 int ascent(const CStyle& ch)
61 { 61 {
62 QFont f(name(), getsize(ch)); 62 QFont f(name(), getsize(ch));
63 QFontMetrics fm(f); 63 QFontMetrics fm(f);
64 return fm.ascent(); 64 return fm.ascent();
65 } 65 }
66 int descent() 66 int descent()
67 { 67 {
68 QFont f(name(), currentsize()); 68 QFont f(name(), currentsize());
69 QFontMetrics fm(f); 69 QFontMetrics fm(f);
70 return fm.descent(); 70 return fm.descent();
71 } 71 }
72 int descent(const CStyle& ch) 72 int descent(const CStyle& ch)
73 { 73 {
74 QFont f(name(), getsize(ch)); 74 QFont f(name(), getsize(ch));
75 QFontMetrics fm(f); 75 QFontMetrics fm(f);
76 return fm.descent(); 76 return fm.descent();
77 } 77 }
78 int lineSpacing() 78 int lineSpacing()
79 { 79 {
80 QFont f(name(), currentsize()); 80 QFont f(name(), currentsize());
81 QFontMetrics fm(f); 81 QFontMetrics fm(f);
82 return fm.lineSpacing(); 82 return fm.lineSpacing();
83 } 83 }
84 int lineSpacing(const CStyle& ch) 84 int lineSpacing(const CStyle& ch)
85 { 85 {
86 QFont f(name(), getsize(ch)); 86 QFont f(name(), getsize(ch));
87 QFontMetrics fm(f); 87 QFontMetrics fm(f);
88 return fm.lineSpacing(); 88 return fm.lineSpacing();
89 } 89 }
90 bool decreasesize() 90 bool decreasesize()
91 { 91 {
92/* 92/*
93 if (--m_size < 0) 93 if (--m_size < 0)
94 { 94 {
95 m_size = 0; 95 m_size = 0;
96 return false; 96 return false;
97 } 97 }
98 else return true; 98 else return true;
99*/ 99*/
100 if (g_size-- == m_size) 100 if (g_size-- == m_size)
101 { 101 {
102 if (--m_size < 0) 102 if (--m_size < 0)
103 { 103 {
104 m_size = 0; 104 m_size = 0;
105 } 105 }
106 } 106 }
107 // qDebug("Font:%d Graphics:%d", m_size, g_size); 107// odebug << "Font:" << m_size << " Graphics:" << g_size << oendl;
108 return true; 108 return true;
109 } 109 }
110 bool increasesize() 110 bool increasesize()
111 { 111 {
112/* 112/*
113 if (++m_size >= m_maxsize) 113 if (++m_size >= m_maxsize)
114 { 114 {
115 m_size = m_maxsize - 1; 115 m_size = m_maxsize - 1;
116 return false; 116 return false;
117 } 117 }
118 else return true; 118 else return true;
119*/ 119*/
120 if (g_size++ == m_size) 120 if (g_size++ == m_size)
121 { 121 {
122 if (++m_size >= m_maxsize) 122 if (++m_size >= m_maxsize)
123 { 123 {
124 m_size = m_maxsize - 1; 124 m_size = m_maxsize - 1;
125 } 125 }
126 } 126 }
127 // qDebug("Font:%d Graphics:%d", m_size, g_size); 127// odebug << "Font:" << m_size << " Graphics:" << g_size << oendl;
128 return true; 128 return true;
129 } 129 }
130 bool ChangeFont(QString& n) 130 bool ChangeFont(QString& n)
131 { 131 {
132 return ChangeFont(n, currentsize()); 132 return ChangeFont(n, currentsize());
133 } 133 }
134 bool ChangeFont(QString& n, int tgt); 134 bool ChangeFont(QString& n, int tgt);
135 void setlead(int _lead) 135 void setlead(int _lead)
136 { 136 {
137 m_leading = _lead; 137 m_leading = _lead;
138 } 138 }
139 int getlead() 139 int getlead()
140 { 140 {
141 return m_leading; 141 return m_leading;
142 } 142 }
143 void setextraspace(int _lead) 143 void setextraspace(int _lead)
144 { 144 {
145 m_extraspace = _lead; 145 m_extraspace = _lead;
146 } 146 }
147 int getextraspace() 147 int getextraspace()
148 { 148 {
149 return m_extraspace; 149 return m_extraspace;
150 } 150 }
151}; 151};
152 152
153#endif 153#endif
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp
index 9339595..b0d4e00 100644
--- a/noncore/apps/opie-reader/Palm2QImage.cpp
+++ b/noncore/apps/opie-reader/Palm2QImage.cpp
@@ -1,4 +1,12 @@
1/* -*- mode: c; indent-tabs-mode: nil; -*- */ 1/* -*- mode: c; indent-tabs-mode: nil; -*- */
2
3/* OPIE */
4#include <opie2/odebug.h>
5
6/* QT */
7#include <qimage.h>
8
9/* STD */
2#include <stdio.h> 10#include <stdio.h>
3#include <stdlib.h> 11#include <stdlib.h>
4#include <string.h> 12#include <string.h>
@@ -9,7 +17,6 @@
9#include <sys/stat.h> 17#include <sys/stat.h>
10#include <stdarg.h> 18#include <stdarg.h>
11 19
12#include <qimage.h>
13 20
14/***********************************************************************/ 21/***********************************************************************/
15/***********************************************************************/ 22/***********************************************************************/
@@ -42,10 +49,10 @@ typedef struct {
42} ColorMapEntry; 49} ColorMapEntry;
43 50
44static ColorMapEntry Palm8BitColormap[] = { 51static ColorMapEntry Palm8BitColormap[] = {
45 { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 }, 52 { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 },
46 { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 }, 53 { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 },
47 { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 }, 54 { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 },
48 { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 }, 55 { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 },
49 { 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 }, 56 { 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 },
50 { 204, 153, 255 }, { 204, 102, 255 }, { 204, 51, 255 }, { 204, 0, 255 }, 57 { 204, 153, 255 }, { 204, 102, 255 }, { 204, 51, 255 }, { 204, 0, 255 },
51 { 204, 255, 204 }, { 204, 204, 204 }, { 204, 153, 204 }, { 204, 102, 204 }, 58 { 204, 255, 204 }, { 204, 204, 204 }, { 204, 153, 204 }, { 204, 102, 204 },
@@ -139,36 +146,38 @@ QImage* Palm2QImage
139 transparent_index = palmimage[12]; 146 transparent_index = palmimage[12];
140 compression_type = palmimage[13]; 147 compression_type = palmimage[13];
141 /* bytes 14 and 15 are reserved by Palm and always 0 */ 148 /* bytes 14 and 15 are reserved by Palm and always 0 */
142 149
143#if 0 150#if 0
144// qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d", width, height, bits_per_pixel, version, flags, compression_type); 151// odebug << "Palm image is " << width << "x" << height
152// << ", " << bits_per_pixel << " bpp, version " << version
153// << ", flags 0x" << flags << ", compression " << compression_type << oendl;
145#endif 154#endif
146 155
147 if (compression_type == PALM_COMPRESSION_PACKBITS) { 156 if (compression_type == PALM_COMPRESSION_PACKBITS) {
148// qDebug ("Image uses packbits compression; not yet supported"); 157// odebug << "Image uses packbits compression; not yet supported" << oendl;
149 return NULL; 158 return NULL;
150 } else if ((compression_type != PALM_COMPRESSION_NONE) && 159 } else if ((compression_type != PALM_COMPRESSION_NONE) &&
151 (compression_type != PALM_COMPRESSION_RLE) && 160 (compression_type != PALM_COMPRESSION_RLE) &&
152 (compression_type != PALM_COMPRESSION_SCANLINE)) { 161 (compression_type != PALM_COMPRESSION_SCANLINE)) {
153// qDebug ("Image uses unknown compression, code 0x%x", compression_type); 162// odebug << "Image uses unknown compression, code 0x" << compression_type << oendl;
154 return NULL; 163 return NULL;
155 } 164 }
156 165
157 /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps: 166 /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps:
158 167
159 1, 2, or 4 bit grayscale 168 1, 2, or 4 bit grayscale
160 8-bit StaticColor using the Palm standard colormap 169 8-bit StaticColor using the Palm standard colormap
161 8-bit PseudoColor using a user-specified colormap 170 8-bit PseudoColor using a user-specified colormap
162 16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue 171 16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue
163 172
164 Each of these can be compressed with one of four compression schemes, 173 Each of these can be compressed with one of four compression schemes,
165 "RLE", "Scanline", "PackBits", or none. 174 "RLE", "Scanline", "PackBits", or none.
166 175
167 We begin by constructing the colormap. 176 We begin by constructing the colormap.
168 */ 177 */
169 178
170 if (flags & PALM_HAS_COLORMAP_FLAG) { 179 if (flags & PALM_HAS_COLORMAP_FLAG) {
171// qDebug("Palm images with custom colormaps are not currently supported.\n"); 180// odebug << "Palm images with custom colormaps are not currently supported." << oendl;
172 return NULL; 181 return NULL;
173 } else if (bits_per_pixel == 1) { 182 } else if (bits_per_pixel == 1) {
174 colormap = Palm1BitColormap; 183 colormap = Palm1BitColormap;
@@ -187,18 +196,20 @@ QImage* Palm2QImage
187 palm_red_bits = palmimage[16]; 196 palm_red_bits = palmimage[16];
188 palm_green_bits = palmimage[17]; 197 palm_green_bits = palmimage[17];
189 palm_blue_bits = palmimage[18]; 198 palm_blue_bits = palmimage[18];
190// qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits); 199// odebug << "Bits:" << palm_red_bits << ", " << palm_green_bits << ", " << palm_blue_bits << oendl;
191 if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) { 200 if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) {
192// qDebug("Can't handle this format DirectColor image -- too wide in some color (%d:%d:%d)\n", palm_red_bits, palm_green_bits, palm_blue_bits); 201// odebug << "Can't handle this format DirectColor image -- too wide in some color ("
202// << palm_red_bits << ":" << palm_green_bits << ":" << palm_blue_bits << oendl;
193 return NULL; 203 return NULL;
194 } 204 }
195 if (bits_per_pixel > (8 * sizeof(unsigned long))) { 205 if (bits_per_pixel > (8 * sizeof(unsigned long))) {
196// qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel); 206// odebug << "Can't handle this format DirectColor image -- too many bits per pixel ("
207// << bits_per_pixel << ")" << oendl;
197 return NULL; 208 return NULL;
198 } 209 }
199 imagedatastart = palmimage + 24; 210 imagedatastart = palmimage + 24;
200 } else { 211 } else {
201// qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel); 212// odebug << "Unknown bits-per-pixel of " << bits_per_pixel << " encountered" << oendl;
202 return NULL; 213 return NULL;
203 } 214 }
204 215
@@ -213,26 +224,27 @@ QImage* Palm2QImage
213 lastrow = new unsigned char[bytes_per_row * width]; 224 lastrow = new unsigned char[bytes_per_row * width];
214 225
215 for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) { 226 for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) {
216// qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row); 227// odebug << "inval:" << inval << " palm_ptr:" << palm_ptr << " x_ptr:" << x_ptr
228// << " bpr:" << bytes_per_row << oendl;
217 229
218 /* first, uncompress the Palm image */ 230 /* first, uncompress the Palm image */
219 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { 231 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) {
220 for (j = 0; j < bytes_per_row; ) { 232 for (j = 0; j < bytes_per_row; ) {
221 incount = *palm_ptr++; 233 incount = *palm_ptr++;
222 inval = *palm_ptr++; 234 inval = *palm_ptr++;
223 memset(rowbuf + j, inval, incount); 235 memset(rowbuf + j, inval, incount);
224 j += incount; 236 j += incount;
225 } 237 }
226 } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) { 238 } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) {
227 for (j = 0; j < bytes_per_row; j += 8) { 239 for (j = 0; j < bytes_per_row; j += 8) {
228 incount = *palm_ptr++; 240 incount = *palm_ptr++;
229 inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8; 241 inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8;
230 for (inbit = 0; inbit < inval; inbit += 1) { 242 for (inbit = 0; inbit < inval; inbit += 1) {
231 if (incount & (1 << (7 - inbit))) 243 if (incount & (1 << (7 - inbit)))
232 rowbuf[j + inbit] = *palm_ptr++; 244 rowbuf[j + inbit] = *palm_ptr++;
233 else 245 else
234 rowbuf[j + inbit] = lastrow[j + inbit]; 246 rowbuf[j + inbit] = lastrow[j + inbit];
235 } 247 }
236 } 248 }
237 memcpy (lastrow, rowbuf, bytes_per_row); 249 memcpy (lastrow, rowbuf, bytes_per_row);
238 } else if (((flags & PALM_IS_COMPRESSED_FLAG) && 250 } else if (((flags & PALM_IS_COMPRESSED_FLAG) &&
@@ -243,12 +255,12 @@ QImage* Palm2QImage
243 palm_ptr += bytes_per_row; 255 palm_ptr += bytes_per_row;
244 } 256 }
245 else { 257 else {
246 qDebug("Case 4"); 258 odebug << "Case 4" << oendl;
247 qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true"); 259 odebug << "Is compressed:" << (((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true") << oendl;
248 qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true"); 260 odebug << "Has colourmap:" << (((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true") << oendl;
249 qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true"); 261 odebug << "Has transparency:" << (((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true") << oendl;
250 qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true"); 262 odebug << "Direct colour:" << (((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true") << oendl;
251 qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true"); 263 odebug << "four byte field:" << (((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true") << oendl;
252 memcpy (rowbuf, palm_ptr, bytes_per_row); 264 memcpy (rowbuf, palm_ptr, bytes_per_row);
253 palm_ptr += bytes_per_row; 265 palm_ptr += bytes_per_row;
254 } 266 }
@@ -256,37 +268,36 @@ QImage* Palm2QImage
256 if (colormap) { 268 if (colormap) {
257 mask = (1 << bits_per_pixel) - 1; 269 mask = (1 << bits_per_pixel) - 1;
258 for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) { 270 for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) {
259 inval = ((*inbyte) & (mask << inbit)) >> inbit; 271 inval = ((*inbyte) & (mask << inbit)) >> inbit;
260 /* correct for oddity of the 8-bit color Palm pixmap... */ 272 /* correct for oddity of the 8-bit color Palm pixmap... */
261 if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231; 273 if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231;
262 /* now lookup the correct color and set the pixel in the GTK bitmap */ 274 /* now lookup the correct color and set the pixel in the GTK bitmap */
263 QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue); 275 QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue);
264 qimage->setPixel(j, i, colour); 276 qimage->setPixel(j, i, colour);
265 if (!inbit) { 277 if (!inbit) {
266 ++inbyte; 278 ++inbyte;
267 inbit = 8 - bits_per_pixel; 279 inbit = 8 - bits_per_pixel;
268 } else { 280 } else {
269 inbit -= bits_per_pixel; 281 inbit -= bits_per_pixel;
270 } 282 }
271 } 283 }
272 } else if (!colormap && 284 } else if (!colormap &&
273 bits_per_pixel == 16) { 285 bits_per_pixel == 16) {
274 for (inbyte = rowbuf, j = 0; j < width; ++j) { 286 for (inbyte = rowbuf, j = 0; j < width; ++j) {
275 inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1]; 287 inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1];
276 288
277/* 289/*
278 qDebug ("pixel is %d,%d (%d:%d:%d)", 290 odebug << "pixel is " << j << "," << i << " ("
279 j, i, 291 << (((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits)) << ":"
280 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), 292 << (((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits)) << ":"
281 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), 293 << (((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)) << ")" << oendl;
282 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
283*/ 294*/
284 QRgb colour = qRgb( 295 QRgb colour = qRgb(
285 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), 296 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
286 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), 297 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
287 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)); 298 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
288 qimage->setPixel(j, i, colour); 299 qimage->setPixel(j, i, colour);
289 inbyte += 2; 300 inbyte += 2;
290 } 301 }
291 } 302 }
292 } 303 }
@@ -299,7 +310,7 @@ QImage* Palm2QImage
299 310
300QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b) 311QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b)
301{ 312{
302//// qDebug("hrule [%d, %d]", w, h); 313// odebug << "hrule [" << w << ", " << h << "]" << oendl;
303 QPixmap* qimage = new QPixmap(w, h); 314 QPixmap* qimage = new QPixmap(w, h);
304 qimage->fill(QColor(r,g,b)); 315 qimage->fill(QColor(r,g,b));
305 QImage* ret = new QImage(qimage->convertToImage()); 316 QImage* ret = new QImage(qimage->convertToImage());
diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h
index dfbdfb9..f89de63 100644
--- a/noncore/apps/opie-reader/QTReader.h
+++ b/noncore/apps/opie-reader/QTReader.h
@@ -21,8 +21,8 @@ class QTReader : public QWidget
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23 23
24 static tchar pluckernextpart[]; 24 static tchar pluckernextpart[];
25 static tchar jplucknextpart[]; 25 static tchar jplucknextpart[];
26 friend class QTReaderApp; 26 friend class QTReaderApp;
27 void suspend(); 27 void suspend();
28 void increaseScroll(); 28 void increaseScroll();
@@ -59,13 +59,13 @@ public:
59 void zoomin(); 59 void zoomin();
60 void zoomout(); 60 void zoomout();
61 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) 61 void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
62 { 62 {
63 buffdoc.setSaveData(data, len, src, srclen); 63 buffdoc.setSaveData(data, len, src, srclen);
64 } 64 }
65 void putSaveData(unsigned char*& src, unsigned short& srclen) 65 void putSaveData(unsigned char*& src, unsigned short& srclen)
66 { 66 {
67 buffdoc.putSaveData(src, srclen); 67 buffdoc.putSaveData(src, srclen);
68 } 68 }
69 bool empty(); 69 bool empty();
70 void setContinuous(bool _b); 70 void setContinuous(bool _b);
71 void toggle_autoscroll(); 71 void toggle_autoscroll();
@@ -75,7 +75,7 @@ public:
75 { 75 {
76/* 76/*
77 size_t nd = locate(); 77 size_t nd = locate();
78 jumpto(m_mark); 78 jumpto(m_mark);
79 QString text; 79 QString text;
80 while (m_mark < nd) 80 while (m_mark < nd)
81 { 81 {
@@ -91,73 +91,73 @@ public:
91 /* 91 /*
92 void setText(bool oldfile) 92 void setText(bool oldfile)
93 { 93 {
94 if (oldfile) 94 if (oldfile)
95 { 95 {
96 m_string = m_lastfile; 96 m_string = m_lastfile;
97 load_file((const tchar*)m_string); 97 load_file((const tchar*)m_string);
98 } 98 }
99 else 99 else
100 { 100 {
101 m_string = QString::null; 101 m_string = QString::null;
102 } 102 }
103 }; 103 };
104 */ 104 */
105 void setlead(int _lead) 105 void setlead(int _lead)
106 { 106 {
107 m_fontControl.setlead(_lead); 107 m_fontControl.setlead(_lead);
108 } 108 }
109 int getlead() 109 int getlead()
110 { 110 {
111 return m_fontControl.getlead(); 111 return m_fontControl.getlead();
112 } 112 }
113 void setextraspace(int _lead) 113 void setextraspace(int _lead)
114 { 114 {
115 m_fontControl.setextraspace(_lead); 115 m_fontControl.setextraspace(_lead);
116 } 116 }
117 int getextraspace() 117 int getextraspace()
118 { 118 {
119 return m_fontControl.getextraspace(); 119 return m_fontControl.getextraspace();
120 } 120 }
121 void setpagemode(bool _b) 121 void setpagemode(bool _b)
122 { 122 {
123 m_bpagemode = _b; 123 m_bpagemode = _b;
124 } 124 }
125 void setmono(bool _b) 125 void setmono(bool _b)
126 { 126 {
127 m_bMonoSpaced = _b; 127 m_bMonoSpaced = _b;
128 ChangeFont(m_fontControl.currentsize()); 128 ChangeFont(m_fontControl.currentsize());
129 locate(pagelocate()); 129 locate(pagelocate());
130 } 130 }
131 void setencoding(int _f) 131 void setencoding(int _f)
132 { 132 {
133 m_encd = _f; 133 m_encd = _f;
134 setfilter(getfilter()); 134 setfilter(getfilter());
135 } 135 }
136 MarkupType PreferredMarkup(); 136 MarkupType PreferredMarkup();
137 CEncoding* getencoding() 137 CEncoding* getencoding()
138 { 138 {
139 // qDebug("m_encd:%d", m_encd); 139// odebug << "m_encd:" << m_encd << oendl;
140 switch (m_encd) 140 switch (m_encd)
141 { 141 {
142 case 4: 142 case 4:
143 // qDebug("palm"); 143// odebug << "palm" << oendl;
144 return new CPalm; 144 return new CPalm;
145 case 1: 145 case 1:
146 // qDebug("utf8"); 146// odebug << "utf8" << oendl;
147 return new CUtf8; 147 return new CUtf8;
148 case 2: 148 case 2:
149 // qDebug("ucs16be"); 149// odebug << "ucs16be" << oendl;
150 return new CUcs16be; 150 return new CUcs16be;
151 case 3: 151 case 3:
152 // qDebug("ucs16le"); 152// odebug << "ucs16le" << oendl;
153 return new CUcs16le; 153 return new CUcs16le;
154 case 0: 154 case 0:
155 // qDebug("ascii"); 155// odebug << "ascii" << oendl;
156 return new CAscii; 156 return new CAscii;
157 default: 157 default:
158 return new CGeneral8Bit(m_encd-MAX_ENCODING+1); 158 return new CGeneral8Bit(m_encd-MAX_ENCODING+1);
159 } 159 }
160 } 160 }
161 CFilterChain* getfilter() 161 CFilterChain* getfilter()
162 { 162 {
163 CFilterChain * filt = new CFilterChain(getencoding()); 163 CFilterChain * filt = new CFilterChain(getencoding());
@@ -189,7 +189,7 @@ private slots:
189 void goHome(); 189 void goHome();
190 void goBack(); 190 void goBack();
191 void goForward(); 191 void goForward();
192 void doscroll(); 192 void doscroll();
193 void drawIt( QPainter * ); 193 void drawIt( QPainter * );
194 void paintEvent( QPaintEvent * ); 194 void paintEvent( QPaintEvent * );
195// void resizeEvent( QResizeEvent * p ) { update(); } 195// void resizeEvent( QResizeEvent * p ) { update(); }
diff --git a/noncore/apps/opie-reader/QTReaderApp.h b/noncore/apps/opie-reader/QTReaderApp.h
index ab6f60e..fe3eebf 100644
--- a/noncore/apps/opie-reader/QTReaderApp.h
+++ b/noncore/apps/opie-reader/QTReaderApp.h
@@ -43,9 +43,9 @@ class QWidgetStack;
43class QToolButton; 43class QToolButton;
44class QPopupMenu; 44class QPopupMenu;
45class QToolBar; 45class QToolBar;
46#ifdef USEQPE 46#ifdef USEQPE
47class QToolBar; 47class QToolBar;
48class QMenuBar; 48class QMenuBar;
49#endif 49#endif
50class CBkmkSelector; 50class CBkmkSelector;
51class QProgressBar; 51class QProgressBar;
@@ -140,7 +140,7 @@ class QTReaderApp : public QMainWindow
140{ 140{
141 Q_OBJECT 141 Q_OBJECT
142 142
143 unsigned long m_savedpos; 143 unsigned long m_savedpos;
144 int m_debounce; 144 int m_debounce;
145 timeb m_lastkeytime; 145 timeb m_lastkeytime;
146 bool m_annoIsEditing; 146 bool m_annoIsEditing;
@@ -149,15 +149,15 @@ class QTReaderApp : public QMainWindow
149 fontselector_action m_fontAction; 149 fontselector_action m_fontAction;
150 void doAction(ActionTypes a, QKeyEvent* e); 150 void doAction(ActionTypes a, QKeyEvent* e);
151 151
152 public: 152 public:
153 QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); 153 QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
154 ~QTReaderApp(); 154 ~QTReaderApp();
155 155
156 void handlekey(QKeyEvent* e); 156 void handlekey(QKeyEvent* e);
157 void hideEvent(QHideEvent*) 157 void hideEvent(QHideEvent*)
158 { 158 {
159 suspend(); 159 suspend();
160 } 160 }
161 161
162 void suspend(); 162 void suspend();
163 void openFile( const QString & ); 163 void openFile( const QString & );
@@ -171,24 +171,24 @@ class QTReaderApp : public QMainWindow
171 Bkmk* m_anno; 171 Bkmk* m_anno;
172// void resizeEvent(QResizeEvent* e); 172// void resizeEvent(QResizeEvent* e);
173 void closeEvent( QCloseEvent *e ); 173 void closeEvent( QCloseEvent *e );
174 void readbkmks(); 174 void readbkmks();
175 void do_mono(const QString&); 175 void do_mono(const QString&);
176 void do_jump(const QString&); 176 void do_jump(const QString&);
177 void do_settarget(const QString&); 177 void do_settarget(const QString&);
178#ifdef _SCROLLPIPE 178#ifdef _SCROLLPIPE
179 //void do_setpipetarget(const QString&); 179// void do_setpipetarget(const QString&);
180#endif 180#endif
181 void do_saveconfig(const QString&, bool); 181 void do_saveconfig(const QString&, bool);
182 bool readconfig(const QString&, bool); 182 bool readconfig(const QString&, bool);
183 bool PopulateConfig(const char*); 183 bool PopulateConfig(const char*);
184 ActionTypes ActNameToInt(const QString&); 184 ActionTypes ActNameToInt(const QString&);
185 bool m_doAnnotation; 185 bool m_doAnnotation;
186 bool m_doDictionary; 186 bool m_doDictionary;
187 bool m_doClipboard; 187 bool m_doClipboard;
188 bool m_fullscreen; 188 bool m_fullscreen;
189 bool m_loadedconfig; 189 bool m_loadedconfig;
190 public: 190 public:
191 void saveprefs(); 191 void saveprefs();
192public slots: 192public slots:
193 void setDocument(const QString&); 193 void setDocument(const QString&);
194private slots: 194private slots:
@@ -207,17 +207,17 @@ private slots:
207 void setTwoTouch(bool _b); 207 void setTwoTouch(bool _b);
208 void restoreFocus(); 208 void restoreFocus();
209 void OnAnnotation(bool _b) 209 void OnAnnotation(bool _b)
210 { 210 {
211 m_doAnnotation = _b; 211 m_doAnnotation = _b;
212 } 212 }
213 void OnDictionary(bool _b) 213 void OnDictionary(bool _b)
214 { 214 {
215 m_doDictionary = _b; 215 m_doDictionary = _b;
216 } 216 }
217 void OnClipboard(bool _b) 217 void OnClipboard(bool _b)
218 { 218 {
219 m_doClipboard = _b; 219 m_doClipboard = _b;
220 } 220 }
221 void OnWordSelected(const QString&, size_t, const QString&); 221 void OnWordSelected(const QString&, size_t, const QString&);
222 void OnURLSelected(const QString& href); 222 void OnURLSelected(const QString& href);
223 void showgraphic(QImage&); 223 void showgraphic(QImage&);
@@ -226,30 +226,30 @@ private slots:
226 void addanno(); 226 void addanno();
227 void showAnnotation(); 227 void showAnnotation();
228 void do_setencoding(int i); 228 void do_setencoding(int i);
229 void do_setfont(const QString&); 229 void do_setfont(const QString&);
230 void buttonActionSelected(QAction*); 230 void buttonActionSelected(QAction*);
231 //void msgHandler(const QCString&, const QByteArray&); 231// void msgHandler(const QCString&, const QByteArray&);
232 void monospace(bool); 232 void monospace(bool);
233 void jump(); 233 void jump();
234 void settarget(); 234 void settarget();
235#ifdef _SCROLLPIPE 235#ifdef _SCROLLPIPE
236 //void setpipetarget(); 236// void setpipetarget();
237 //void setpause(bool); 237// void setpause(bool);
238#endif 238#endif
239 //void setspacing(); 239// void setspacing();
240 void setfont(); 240 void setfont();
241 void clearBkmkList(); 241 void clearBkmkList();
242 void listBkmkFiles(); 242 void listBkmkFiles();
243 void editMark(); 243 void editMark();
244 void autoScroll(bool); 244 void autoScroll(bool);
245 void addbkmk(); 245 void addbkmk();
246 void savebkmks(); 246 void savebkmks();
247 //void importFiles(); 247// void importFiles();
248 void showprefs(); 248 void showprefs();
249 void showtoolbarprefs(); 249 void showtoolbarprefs();
250 void infoClose(); 250 void infoClose();
251 // void oldFile(); 251 // void oldFile();
252 void showinfo(); 252 void showinfo();
253 253
254// void indentplus(); 254// void indentplus();
255// void indentminus(); 255// void indentminus();
@@ -367,7 +367,7 @@ private slots:
367 CBkmkSelector* bkmkselector; 367 CBkmkSelector* bkmkselector;
368 368
369 ActionTypes m_spaceTarget, m_escapeTarget, m_returnTarget, m_leftTarget, m_rightTarget, 369 ActionTypes m_spaceTarget, m_escapeTarget, m_returnTarget, m_leftTarget, m_rightTarget,
370 m_upTarget, m_downTarget; 370 m_upTarget, m_downTarget;
371 bool m_leftScroll, m_rightScroll, m_upScroll, m_downScroll; 371 bool m_leftScroll, m_rightScroll, m_upScroll, m_downScroll;
372 bool m_bcloseDisabled, m_disableesckey; 372 bool m_bcloseDisabled, m_disableesckey;
373 size_t searchStart; 373 size_t searchStart;
@@ -382,11 +382,11 @@ private slots:
382 QComboBox* m_fontSelector; 382 QComboBox* m_fontSelector;
383// QToolBar /* *menu,*/ *fileBar; 383// QToolBar /* *menu,*/ *fileBar;
384 QToolBar *menubar, *fileBar, *navBar, *viewBar, *markBar; 384 QToolBar *menubar, *fileBar, *navBar, *viewBar, *markBar;
385#ifdef USEQPE 385#ifdef USEQPE
386 QMenuBar *mb; 386 QMenuBar *mb;
387#else 387#else
388 QMenuBar *mb; 388 QMenuBar *mb;
389#endif 389#endif
390 QFloatBar *searchBar, *regBar/*, *m_fontBar*/; 390 QFloatBar *searchBar, *regBar/*, *m_fontBar*/;
391 QToolBar /* *searchBar, *regBar,*/ *m_fontBar; 391 QToolBar /* *searchBar, *regBar,*/ *m_fontBar;
392 QLineEdit *searchEdit, *regEdit; 392 QLineEdit *searchEdit, *regEdit;
@@ -399,8 +399,8 @@ private slots:
399 /* 399 /*
400 void resizeEvent( QResizeEvent * r) 400 void resizeEvent( QResizeEvent * r)
401 { 401 {
402// qDebug("resize:(%u,%u)", r->oldSize().width(), r->oldSize().height()); 402// odebug << "resize:(" << r->oldSize().width() << "," << r->oldSize().height() << ")" << oendl;
403// qDebug("resize:(%u,%u)", r->size().width(), r->size().height()); 403// odebug << "resize:(" << r->size().width() << "," << r->size().height() << ")" << oendl;
404 // bgroup->move( width()-bgroup->width(), 0 ); 404 // bgroup->move( width()-bgroup->width(), 0 );
405 } 405 }
406 */ 406 */
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.h b/noncore/apps/tinykate/libkate/document/katedocument.h
index 9d8ec6a..969be87 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.h
+++ b/noncore/apps/tinykate/libkate/document/katedocument.h
@@ -6,7 +6,7 @@
6 (C) 2002 by Joseph Wenninger 6 (C) 2002 by Joseph Wenninger
7 email : crossfire@babylon2k.de 7 email : crossfire@babylon2k.de
8 jowenn@kde.org 8 jowenn@kde.org
9 9
10***************************************************************************/ 10***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
@@ -76,7 +76,7 @@ public:
76 uchar row=c.row(); 76 uchar row=c.row();
77 short *wa=warray[row]; 77 short *wa=warray[row];
78 if (!wa) { 78 if (!wa) {
79 // qDebug("create row: %d",row); 79 // odebug << "create row: " << row << oendl;
80 wa=warray[row]=new short[256]; 80 wa=warray[row]=new short[256];
81 for (int i=0; i<256; i++) wa[i]=-1; 81 for (int i=0; i<256; i++) wa[i]=-1;
82 } 82 }
@@ -179,7 +179,7 @@ class KateDocument: public Kate::Document
179 179
180 void insert_Line(const QString& s,int line=-1, bool update=true); 180 void insert_Line(const QString& s,int line=-1, bool update=true);
181 void remove_Line(int line,bool update=true); 181 void remove_Line(int line,bool update=true);
182 void replaceLine(const QString& s,int line=-1); 182 void replaceLine(const QString& s,int line=-1);
183 virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE ); 183 virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE );
184 virtual void removeLine( int line ); 184 virtual void removeLine( int line );
185 virtual int length() const; 185 virtual int length() const;
@@ -534,15 +534,15 @@ class KateDocument: public Kate::Document
534 public: 534 public:
535 bool hlSetByUser; 535 bool hlSetByUser;
536 }; 536 };
537 537
538 538
539// BCI: Add a real d-pointer in the next BIC release 539// BCI: Add a real d-pointer in the next BIC release
540static QPtrDict<KateDocPrivate>* d_ptr; 540static QPtrDict<KateDocPrivate>* d_ptr;
541static void cleanup_d_ptr() 541static void cleanup_d_ptr()
542 { 542 {
543 delete d_ptr; 543 delete d_ptr;
544 } 544 }
545 545
546KateDocPrivate* d( const KateDocument* foo ) 546KateDocPrivate* d( const KateDocument* foo )
547 { 547 {
548 if ( !d_ptr ) { 548 if ( !d_ptr ) {
@@ -556,7 +556,7 @@ KateDocPrivate* d( const KateDocument* foo )
556 } 556 }
557 return ret; 557 return ret;
558 } 558 }
559 559
560void delete_d( const KateDocument* foo ) 560void delete_d( const KateDocument* foo )
561 { 561 {
562 if ( d_ptr ) 562 if ( d_ptr )
diff --git a/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp b/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
index a2c680f..78635b2 100644
--- a/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
+++ b/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
@@ -38,20 +38,26 @@
38#error QRegExp3 is now in QT 3 use QRegExp instead 38#error QRegExp3 is now in QT 3 use QRegExp instead
39#endif 39#endif
40 40
41#include "qarray.h"
42#include "qbitarray.h"
43#include "qcache.h"
44#include "qintdict.h"
45#include "qmap.h"
46#if QT_VERSION < 300 41#if QT_VERSION < 300
47#include "./qregexp3.h" 42#include "./qregexp3.h"
48#else 43#else
49#include "qregexp.h" 44#include "qregexp.h"
50#endif 45#endif
51#include "qstring.h"
52#include "qtl.h"
53#include "qvector.h"
54 46
47/* OPIE */
48#include <opie2/odebug.h>
49
50/* QT */
51#include <qarray.h>
52#include <qbitarray.h>
53#include <qcache.h>
54#include <qintdict.h>
55#include <qmap.h>
56#include <qstring.h>
57#include <qtl.h>
58#include <qvector.h>
59
60/* STD */
55#include <limits.h> 61#include <limits.h>
56 62
57/* 63/*
@@ -515,19 +521,19 @@
515 <a name="code-examples"><b>Code Examples</b></a> 521 <a name="code-examples"><b>Code Examples</b></a>
516 522
517 \code 523 \code
518 QRegExp rx( "^\\d\\d?$" );// Match integers 0 to 99 524 QRegExp rx( "^\\d\\d?$" ); // Match integers 0 to 99
519 rx.search( "123" ); // Returns -1 (no match) 525 rx.search( "123" ); // Returns -1 (no match)
520 rx.search( "-6" ); // Returns -1 (no match) 526 rx.search( "-6" ); // Returns -1 (no match)
521 rx.search( "6" ); // Returns 0 (matched as position 0) 527 rx.search( "6" ); // Returns 0 (matched as position 0)
522 \endcode 528 \endcode
523 529
524 The third string matches '<u>6</u>'. This is a simple validation 530 The third string matches '<u>6</u>'. This is a simple validation
525 regexp for integers in the range 0 to 99. 531 regexp for integers in the range 0 to 99.
526 532
527 \code 533 \code
528 QRegExp rx( "^\\S+$" );// Match strings which have no whitespace 534 QRegExp rx( "^\\S+$" ); // Match strings which have no whitespace
529 rx.search( "Hello world" );// Returns -1 (no match) 535 rx.search( "Hello world" ); // Returns -1 (no match)
530 rx.search( "This_is-OK" );// Returns 0 (matched at position 0) 536 rx.search( "This_is-OK" ); // Returns 0 (matched at position 0)
531 \endcode 537 \endcode
532 538
533 The second string matches '<u>This_is-OK</u>'. We've used the 539 The second string matches '<u>This_is-OK</u>'. We've used the
@@ -540,7 +546,7 @@
540 546
541 \code 547 \code
542 QRegExp rx( "\\b(mail|letter|correspondence)\\b" ); 548 QRegExp rx( "\\b(mail|letter|correspondence)\\b" );
543 rx.search( "I sent you an email" ); // Returns -1 (no match) 549 rx.search( "I sent you an email" ); // Returns -1 (no match)
544 rx.search( "Please write the letter" ); // Returns 17 (matched at position 17) 550 rx.search( "Please write the letter" ); // Returns 17 (matched at position 17)
545 \endcode 551 \endcode
546 552
@@ -558,7 +564,7 @@
558 whole matched regexp (equivalent to '&' in most regexp engines). 564 whole matched regexp (equivalent to '&' in most regexp engines).
559 565
560 \code 566 \code
561 QRegExp rx( "&(?!amp;)" ); // Match ampersands but not &amp; 567 QRegExp rx( "&(?!amp;)" ); // Match ampersands but not &amp;
562 QString line1 = "This & that"; 568 QString line1 = "This & that";
563 line1.replace( rx, "&amp;" ); 569 line1.replace( rx, "&amp;" );
564 // line1 == "This &amp; that" 570 // line1 == "This &amp; that"
@@ -572,15 +578,15 @@
572 578
573 \code 579 \code
574 QString str = "One Eric another Eirik, and an Ericsson. How many Eiriks, Eric?"; 580 QString str = "One Eric another Eirik, and an Ericsson. How many Eiriks, Eric?";
575 QRegExp rx( "\\b(Eric|Eirik)\\b" );// Match Eric or Eirik 581 QRegExp rx( "\\b(Eric|Eirik)\\b" ); // Match Eric or Eirik
576 int pos = 0; // Where we are in the string 582 int pos = 0; // Where we are in the string
577 int count = 0; // How many Eric and Eirik's we've counted 583 int count = 0; // How many Eric and Eirik's we've counted
578 while ( pos >= 0 ) { 584 while ( pos >= 0 ) {
579 pos = rx.search( str, pos ); 585 pos = rx.search( str, pos );
580 if ( pos >= 0 ) { 586 if ( pos >= 0 ) {
581 pos++;// Move along in str 587 pos++; // Move along in str
582 count++;// Count our Eric or Eirik 588 count++; // Count our Eric or Eirik
583 } 589 }
584 } 590 }
585 \endcode 591 \endcode
586 592
@@ -601,9 +607,9 @@
601 QString company, web, country; 607 QString company, web, country;
602 rx.setPattern( "^([^\t]+)\t([^\t]+)\t([^\t]+)$" ); 608 rx.setPattern( "^([^\t]+)\t([^\t]+)\t([^\t]+)$" );
603 if ( rx.search( str ) != -1 ) { 609 if ( rx.search( str ) != -1 ) {
604 company = rx.cap( 1 ); 610 company = rx.cap( 1 );
605 web= rx.cap( 2 ); 611 web = rx.cap( 2 );
606 country = rx.cap( 3 ); 612 country = rx.cap( 3 );
607 } 613 }
608 \endcode 614 \endcode
609 615
@@ -624,11 +630,11 @@
624 To immitate the matching of a shell we can use wildcard mode. 630 To immitate the matching of a shell we can use wildcard mode.
625 631
626 \code 632 \code
627 QRegExp rx( "*.html" );// Invalid regexp: * doesn't quantify anything 633 QRegExp rx( "*.html" ); // Invalid regexp: * doesn't quantify anything
628 rx.setWildcard( TRUE );// Now its a valid wildcard regexp 634 rx.setWildcard( TRUE ); // Now its a valid wildcard regexp
629 rx.search( "index.html" );// Returns 0 (matched at position 0) 635 rx.search( "index.html" ); // Returns 0 (matched at position 0)
630 rx.search( "default.htm" );// Returns -1 (no match) 636 rx.search( "default.htm" ); // Returns -1 (no match)
631 rx.search( "readme.txt" );// Returns -1 (no match) 637 rx.search( "readme.txt" ); // Returns -1 (no match)
632 \endcode 638 \endcode
633 639
634 Wildcard matching can be convenient because of its simplicity, but 640 Wildcard matching can be convenient because of its simplicity, but
@@ -676,36 +682,36 @@ static void mergeInto( QArray<int> *a, const QArray<int>& b )
676 int asize = a->size(); 682 int asize = a->size();
677 int bsize = b.size(); 683 int bsize = b.size();
678 if ( asize == 0 ) { 684 if ( asize == 0 ) {
679 *a = b.copy(); 685 *a = b.copy();
680#ifndef QT_NO_REGEXP_OPTIM 686#ifndef QT_NO_REGEXP_OPTIM
681 } else if ( bsize == 1 && (*a)[asize - 1] < b[0] ) { 687 } else if ( bsize == 1 && (*a)[asize - 1] < b[0] ) {
682 a->resize( asize + 1 ); 688 a->resize( asize + 1 );
683 (*a)[asize] = b[0]; 689 (*a)[asize] = b[0];
684#endif 690#endif
685 } else if ( bsize >= 1 ) { 691 } else if ( bsize >= 1 ) {
686 int csize = asize + bsize; 692 int csize = asize + bsize;
687 QArray<int> c( csize ); 693 QArray<int> c( csize );
688 int i = 0, j = 0, k = 0; 694 int i = 0, j = 0, k = 0;
689 while ( i < asize ) { 695 while ( i < asize ) {
690 if ( j < bsize ) { 696 if ( j < bsize ) {
691 if ( (*a)[i] == b[j] ) { 697 if ( (*a)[i] == b[j] ) {
692 i++; 698 i++;
693 csize--; 699 csize--;
694 } else if ( (*a)[i] < b[j] ) { 700 } else if ( (*a)[i] < b[j] ) {
695 c[k++] = (*a)[i++]; 701 c[k++] = (*a)[i++];
696 } else { 702 } else {
697 c[k++] = b[j++]; 703 c[k++] = b[j++];
698 } 704 }
699 } else { 705 } else {
700 memcpy( c.data() + k, (*a).data() + i, 706 memcpy( c.data() + k, (*a).data() + i,
701 (asize - i) * sizeof(int) ); 707 (asize - i) * sizeof(int) );
702 break; 708 break;
703 } 709 }
704 } 710 }
705 c.resize( csize ); 711 c.resize( csize );
706 if ( j < bsize ) 712 if ( j < bsize )
707 memcpy( c.data() + k, b.data() + j, (bsize - j) * sizeof(int) ); 713 memcpy( c.data() + k, b.data() + j, (bsize - j) * sizeof(int) );
708 *a = c; 714 *a = c;
709 } 715 }
710} 716}
711 717
@@ -717,7 +723,7 @@ static void mergeInto( QMap<int, int> *a, const QMap<int, int>& b )
717{ 723{
718 QMap<int, int>::ConstIterator it; 724 QMap<int, int>::ConstIterator it;
719 for ( it = b.begin(); it != b.end(); ++it ) 725 for ( it = b.begin(); it != b.end(); ++it )
720 a->insert( it.key(), *it ); 726 a->insert( it.key(), *it );
721} 727}
722 728
723/* 729/*
@@ -728,9 +734,9 @@ static int at( const QMap<int, int>& m, int k )
728{ 734{
729 QMap<int, int>::ConstIterator it = m.find( k ); 735 QMap<int, int>::ConstIterator it = m.find( k );
730 if ( it == m.end() ) 736 if ( it == m.end() )
731 return 0; 737 return 0;
732 else 738 else
733 return *it; 739 return *it;
734} 740}
735 741
736#ifndef QT_NO_REGEXP_WILDCARD 742#ifndef QT_NO_REGEXP_WILDCARD
@@ -744,44 +750,44 @@ static QString wc2rx( const QString& wc )
744 QString rx = QString::fromLatin1( "" ); 750 QString rx = QString::fromLatin1( "" );
745 int i = 0; 751 int i = 0;
746 while ( i < wclen ) { 752 while ( i < wclen ) {
747 QChar c = wc[i++]; 753 QChar c = wc[i++];
748 switch ( c.unicode() ) { 754 switch ( c.unicode() ) {
749 case '*': 755 case '*':
750 rx += QString::fromLatin1( ".*" ); 756 rx += QString::fromLatin1( ".*" );
751 break; 757 break;
752 case '?': 758 case '?':
753 rx += QChar( '.' ); 759 rx += QChar( '.' );
754 break; 760 break;
755 case '$': 761 case '$':
756 case '(': 762 case '(':
757 case ')': 763 case ')':
758 case '+': 764 case '+':
759 case '.': 765 case '.':
760 case '\\': 766 case '\\':
761 case '^': 767 case '^':
762 case '{': 768 case '{':
763 case '|': 769 case '|':
764 case '}': 770 case '}':
765 rx += QChar( '\\' ); 771 rx += QChar( '\\' );
766 rx += c; 772 rx += c;
767 break; 773 break;
768 case '[': 774 case '[':
769 rx += c; 775 rx += c;
770 if ( wc[i] == QChar('^') ) 776 if ( wc[i] == QChar('^') )
771 rx += wc[i++]; 777 rx += wc[i++];
772 if ( i < wclen ) { 778 if ( i < wclen ) {
773 if ( rx[i] == ']' ) 779 if ( rx[i] == ']' )
774 rx += wc[i++]; 780 rx += wc[i++];
775 while ( i < wclen && wc[i] != QChar(']') ) { 781 while ( i < wclen && wc[i] != QChar(']') ) {
776 if ( wc[i] == '\\' ) 782 if ( wc[i] == '\\' )
777 rx += QChar( '\\' ); 783 rx += QChar( '\\' );
778 rx += wc[i++]; 784 rx += wc[i++];
779 } 785 }
780 } 786 }
781 break; 787 break;
782 default: 788 default:
783 rx += c; 789 rx += c;
784 } 790 }
785 } 791 }
786 return rx; 792 return rx;
787} 793}
@@ -802,54 +808,54 @@ public:
802 class CharClass 808 class CharClass
803 { 809 {
804 public: 810 public:
805 CharClass(); 811 CharClass();
806 CharClass( const CharClass& cc ) { operator=( cc ); } 812 CharClass( const CharClass& cc ) { operator=( cc ); }
807 813
808 CharClass& operator=( const CharClass& cc ); 814 CharClass& operator=( const CharClass& cc );
809 815
810 void clear(); 816 void clear();
811 bool negative() const { return n; } 817 bool negative() const { return n; }
812 void setNegative( bool negative ); 818 void setNegative( bool negative );
813 void addCategories( int cats ); 819 void addCategories( int cats );
814 void addRange( ushort from, ushort to ); 820 void addRange( ushort from, ushort to );
815 void addSingleton( ushort ch ) { addRange( ch, ch ); } 821 void addSingleton( ushort ch ) { addRange( ch, ch ); }
816 822
817 bool in( QChar ch ) const; 823 bool in( QChar ch ) const;
818#ifndef QT_NO_REGEXP_OPTIM 824#ifndef QT_NO_REGEXP_OPTIM
819 const QArray<int>& firstOccurrence() const { return occ1; } 825 const QArray<int>& firstOccurrence() const { return occ1; }
820#endif 826#endif
821 827
822#if defined(QT_DEBUG) 828#if defined(QT_DEBUG)
823 void dump() const; 829 void dump() const;
824#endif 830#endif
825 831
826 private: 832 private:
827 /* 833 /*
828 The struct Range represents a range of characters (e.g., [0-9] denotes 834 The struct Range represents a range of characters (e.g., [0-9] denotes
829 range 48 to 57). 835 range 48 to 57).
830 */ 836 */
831 struct Range 837 struct Range
832 { 838 {
833 ushort from; // 48 839 ushort from; // 48
834 ushort to; // 57 840 ushort to; // 57
835 }; 841 };
836 842
837 int c; // character classes 843 int c; // character classes
838 QArray<Range> r; // character ranges 844 QArray<Range> r; // character ranges
839 bool n; // negative? 845 bool n; // negative?
840#ifndef QT_NO_REGEXP_OPTIM 846#ifndef QT_NO_REGEXP_OPTIM
841 QArray<int> occ1; // first-occurrence array 847 QArray<int> occ1; // first-occurrence array
842#endif 848#endif
843 }; 849 };
844#else 850#else
845 struct CharClass 851 struct CharClass
846 { 852 {
847 int x; // dummy 853 int x; // dummy
848 854
849#ifndef QT_NO_REGEXP_OPTIM 855#ifndef QT_NO_REGEXP_OPTIM
850 const QArray<int>& firstOccurrence() const { 856 const QArray<int>& firstOccurrence() const {
851 return *firstOccurrenceAtZero; 857 return *firstOccurrenceAtZero;
852 } 858 }
853#endif 859#endif
854 }; 860 };
855#endif 861#endif
@@ -864,7 +870,7 @@ public:
864 bool caseSensitive() const { return cs; } 870 bool caseSensitive() const { return cs; }
865 int numCaptures() const { return realncap; } 871 int numCaptures() const { return realncap; }
866 QArray<int> match( const QString& str, int pos, bool minimal, 872 QArray<int> match( const QString& str, int pos, bool minimal,
867 bool oneTest ); 873 bool oneTest );
868 int matchedLength() const { return mmMatchedLen; } 874 int matchedLength() const { return mmMatchedLen; }
869 875
870 int createState( QChar ch ); 876 int createState( QChar ch );
@@ -876,7 +882,7 @@ public:
876 void addCatTransitions( const QArray<int>& from, const QArray<int>& to ); 882 void addCatTransitions( const QArray<int>& from, const QArray<int>& to );
877#ifndef QT_NO_REGEXP_CAPTURE 883#ifndef QT_NO_REGEXP_CAPTURE
878 void addPlusTransitions( const QArray<int>& from, const QArray<int>& to, 884 void addPlusTransitions( const QArray<int>& from, const QArray<int>& to,
879 int atom ); 885 int atom );
880#endif 886#endif
881 887
882#ifndef QT_NO_REGEXP_ANCHOR_ALT 888#ifndef QT_NO_REGEXP_ANCHOR_ALT
@@ -890,7 +896,7 @@ public:
890 896
891#ifndef QT_NO_REGEXP_OPTIM 897#ifndef QT_NO_REGEXP_OPTIM
892 void setupGoodStringHeuristic( int earlyStart, int lateStart, 898 void setupGoodStringHeuristic( int earlyStart, int lateStart,
893 const QString& str ); 899 const QString& str );
894 void setupBadCharHeuristic( int minLen, const QArray<int>& firstOcc ); 900 void setupBadCharHeuristic( int minLen, const QArray<int>& firstOcc );
895 void heuristicallyChooseHeuristic(); 901 void heuristicallyChooseHeuristic();
896#endif 902#endif
@@ -910,21 +916,21 @@ private:
910 struct State 916 struct State
911 { 917 {
912#ifndef QT_NO_REGEXP_CAPTURE 918#ifndef QT_NO_REGEXP_CAPTURE
913 int atom; // which atom does this state belong to? 919 int atom; // which atom does this state belong to?
914#endif 920#endif
915 int match; // what does it match? (see CharClassBit and BackRefBit) 921 int match; // what does it match? (see CharClassBit and BackRefBit)
916 QArray<int> outs; // out-transitions 922 QArray<int> outs; // out-transitions
917 QMap<int, int> *reenter; // atoms reentered when transiting out 923 QMap<int, int> *reenter; // atoms reentered when transiting out
918 QMap<int, int> *anchors; // anchors met when transiting out 924 QMap<int, int> *anchors; // anchors met when transiting out
919 925
920#ifndef QT_NO_REGEXP_CAPTURE 926#ifndef QT_NO_REGEXP_CAPTURE
921 State( int a, int m ) 927 State( int a, int m )
922 : atom( a ), match( m ), reenter( 0 ), anchors( 0 ) { } 928 : atom( a ), match( m ), reenter( 0 ), anchors( 0 ) { }
923#else 929#else
924 State( int m ) 930 State( int m )
925 : match( m ), reenter( 0 ), anchors( 0 ) { } 931 : match( m ), reenter( 0 ), anchors( 0 ) { }
926#endif 932#endif
927 ~State() { delete reenter; delete anchors; } 933 ~State() { delete reenter; delete anchors; }
928 }; 934 };
929 935
930#ifndef QT_NO_REGEXP_LOOKAHEAD 936#ifndef QT_NO_REGEXP_LOOKAHEAD
@@ -934,12 +940,12 @@ private:
934 */ 940 */
935 struct Lookahead 941 struct Lookahead
936 { 942 {
937 QRegExpEngine *eng; // NFA representing the embedded regular expression 943 QRegExpEngine *eng; // NFA representing the embedded regular expression
938 bool neg; // negative lookahead? 944 bool neg; // negative lookahead?
939 945
940 Lookahead( QRegExpEngine *eng0, bool neg0 ) 946 Lookahead( QRegExpEngine *eng0, bool neg0 )
941 : eng( eng0 ), neg( neg0 ) { } 947 : eng( eng0 ), neg( neg0 ) { }
942 ~Lookahead() { delete eng; } 948 ~Lookahead() { delete eng; }
943 }; 949 };
944#endif 950#endif
945 951
@@ -950,8 +956,8 @@ private:
950 */ 956 */
951 struct Atom 957 struct Atom
952 { 958 {
953 int parent; // index of parent in array of atoms 959 int parent; // index of parent in array of atoms
954 int capture; // index of capture, from 1 to ncap 960 int capture; // index of capture, from 1 to ncap
955 }; 961 };
956#endif 962#endif
957 963
@@ -962,8 +968,8 @@ private:
962 */ 968 */
963 struct AnchorAlternation 969 struct AnchorAlternation
964 { 970 {
965 int a; // this anchor... 971 int a; // this anchor...
966 int b; // ...or this one 972 int b; // ...or this one
967 }; 973 };
968#endif 974#endif
969 975
@@ -976,14 +982,14 @@ private:
976 */ 982 */
977 enum { MaxLookaheads = 13, MaxBackRefs = 14 }; 983 enum { MaxLookaheads = 13, MaxBackRefs = 14 };
978 enum { Anchor_Dollar = 0x00000001, Anchor_Caret = 0x00000002, 984 enum { Anchor_Dollar = 0x00000001, Anchor_Caret = 0x00000002,
979 Anchor_Word = 0x00000004, Anchor_NonWord = 0x00000008, 985 Anchor_Word = 0x00000004, Anchor_NonWord = 0x00000008,
980 Anchor_FirstLookahead = 0x00000010, 986 Anchor_FirstLookahead = 0x00000010,
981 Anchor_BackRef1Empty = Anchor_FirstLookahead << MaxLookaheads, 987 Anchor_BackRef1Empty = Anchor_FirstLookahead << MaxLookaheads,
982 Anchor_BackRef0Empty = Anchor_BackRef1Empty >> 1, 988 Anchor_BackRef0Empty = Anchor_BackRef1Empty >> 1,
983 Anchor_Alternation = Anchor_BackRef1Empty << MaxBackRefs, 989 Anchor_Alternation = Anchor_BackRef1Empty << MaxBackRefs,
984 990
985 Anchor_LookaheadMask = ( Anchor_FirstLookahead - 1 ) ^ 991 Anchor_LookaheadMask = ( Anchor_FirstLookahead - 1 ) ^
986 ( (Anchor_FirstLookahead << MaxLookaheads) - 1 ) }; 992 ( (Anchor_FirstLookahead << MaxLookaheads) - 1 ) };
987#ifndef QT_NO_REGEXP_CAPTURE 993#ifndef QT_NO_REGEXP_CAPTURE
988 int startAtom( bool capture ); 994 int startAtom( bool capture );
989 void finishAtom( int atom ) { cf = f[atom].parent; } 995 void finishAtom( int atom ) { cf = f[atom].parent; }
@@ -995,7 +1001,7 @@ private:
995 1001
996#ifndef QT_NO_REGEXP_CAPTURE 1002#ifndef QT_NO_REGEXP_CAPTURE
997 bool isBetterCapture( const int *begin1, const int *end1, const int *begin2, 1003 bool isBetterCapture( const int *begin1, const int *end1, const int *begin2,
998 const int *end2 ); 1004 const int *end2 );
999#endif 1005#endif
1000 bool testAnchor( int i, int a, const int *capBegin ); 1006 bool testAnchor( int i, int a, const int *capBegin );
1001 1007
@@ -1055,53 +1061,53 @@ private:
1055 class Box 1061 class Box
1056 { 1062 {
1057 public: 1063 public:
1058 Box( QRegExpEngine *engine ); 1064 Box( QRegExpEngine *engine );
1059 Box( const Box& b ) { operator=( b ); } 1065 Box( const Box& b ) { operator=( b ); }
1060 1066
1061 Box& operator=( const Box& b ); 1067 Box& operator=( const Box& b );
1062 1068
1063 void clear() { operator=(Box(eng)); } 1069 void clear() { operator=(Box(eng)); }
1064 void set( QChar ch ); 1070 void set( QChar ch );
1065 void set( const CharClass& cc ); 1071 void set( const CharClass& cc );
1066#ifndef QT_NO_REGEXP_BACKREF 1072#ifndef QT_NO_REGEXP_BACKREF
1067 void set( int bref ); 1073 void set( int bref );
1068#endif 1074#endif
1069 1075
1070 void cat( const Box& b ); 1076 void cat( const Box& b );
1071 void orx( const Box& b ); 1077 void orx( const Box& b );
1072 void plus( int atom ); 1078 void plus( int atom );
1073 void opt(); 1079 void opt();
1074 void catAnchor( int a ); 1080 void catAnchor( int a );
1075#ifndef QT_NO_REGEXP_OPTIM 1081#ifndef QT_NO_REGEXP_OPTIM
1076 void setupHeuristics(); 1082 void setupHeuristics();
1077#endif 1083#endif
1078 1084
1079#if defined(QT_DEBUG) 1085#if defined(QT_DEBUG)
1080 void dump() const; 1086 void dump() const;
1081#endif 1087#endif
1082 1088
1083 private: 1089 private:
1084 void addAnchorsToEngine( const Box& to ) const; 1090 void addAnchorsToEngine( const Box& to ) const;
1085 1091
1086 QRegExpEngine *eng; // the automaton under construction 1092 QRegExpEngine *eng; // the automaton under construction
1087 QArray<int> ls; // the left states (firstpos) 1093 QArray<int> ls; // the left states (firstpos)
1088 QArray<int> rs; // the right states (lastpos) 1094 QArray<int> rs; // the right states (lastpos)
1089 QMap<int, int> lanchors; // the left anchors 1095 QMap<int, int> lanchors; // the left anchors
1090 QMap<int, int> ranchors; // the right anchors 1096 QMap<int, int> ranchors; // the right anchors
1091 int skipanchors; // the anchors to match if the box is skipped 1097 int skipanchors; // the anchors to match if the box is skipped
1092 1098
1093#ifndef QT_NO_REGEXP_OPTIM 1099#ifndef QT_NO_REGEXP_OPTIM
1094 int earlyStart; // the index where str can first occur 1100 int earlyStart; // the index where str can first occur
1095 int lateStart; // the index where str can last occur 1101 int lateStart; // the index where str can last occur
1096 QString str; // a string that has to occur in any match 1102 QString str; // a string that has to occur in any match
1097 QString leftStr; // a string occurring at the left of this box 1103 QString leftStr; // a string occurring at the left of this box
1098 QString rightStr; // a string occurring at the right of this box 1104 QString rightStr; // a string occurring at the right of this box
1099 int maxl; // the maximum length of this box (possibly InftyLen) 1105 int maxl; // the maximum length of this box (possibly InftyLen)
1100#endif 1106#endif
1101 1107
1102 int minl; // the minimum length of this box 1108 int minl; // the minimum length of this box
1103#ifndef QT_NO_REGEXP_OPTIM 1109#ifndef QT_NO_REGEXP_OPTIM
1104 QArray<int> occ1; // first-occurrence array 1110 QArray<int> occ1; // first-occurrence array
1105#endif 1111#endif
1106 }; 1112 };
1107 friend class Box; 1113 friend class Box;
@@ -1110,9 +1116,9 @@ private:
1110 This is the lexical analyzer for regular expressions. 1116 This is the lexical analyzer for regular expressions.
1111 */ 1117 */
1112 enum { Tok_Eos, Tok_Dollar, Tok_LeftParen, Tok_MagicLeftParen, 1118 enum { Tok_Eos, Tok_Dollar, Tok_LeftParen, Tok_MagicLeftParen,
1113 Tok_PosLookahead, Tok_NegLookahead, Tok_RightParen, Tok_CharClass, 1119 Tok_PosLookahead, Tok_NegLookahead, Tok_RightParen, Tok_CharClass,
1114 Tok_Caret, Tok_Quantifier, Tok_Bar, Tok_Word, Tok_NonWord, 1120 Tok_Caret, Tok_Quantifier, Tok_Bar, Tok_Word, Tok_NonWord,
1115 Tok_Char = 0x10000, Tok_BackRef = 0x20000 }; 1121 Tok_Char = 0x10000, Tok_BackRef = 0x20000 };
1116 int getChar(); 1122 int getChar();
1117 int getEscape(); 1123 int getEscape();
1118#ifndef QT_NO_REGEXP_INTERVAL 1124#ifndef QT_NO_REGEXP_INTERVAL
@@ -1189,10 +1195,10 @@ QRegExpEngine::QRegExpEngine( const QString& rx, bool caseSensitive )
1189QRegExpEngine::~QRegExpEngine() 1195QRegExpEngine::~QRegExpEngine()
1190{ 1196{
1191 if ( --engCount == 0 ) { 1197 if ( --engCount == 0 ) {
1192 delete noOccurrences; 1198 delete noOccurrences;
1193 noOccurrences = 0; 1199 noOccurrences = 0;
1194 delete firstOccurrenceAtZero; 1200 delete firstOccurrenceAtZero;
1195 firstOccurrenceAtZero = 0; 1201 firstOccurrenceAtZero = 0;
1196 } 1202 }
1197} 1203}
1198#endif 1204#endif
@@ -1202,12 +1208,12 @@ QRegExpEngine::~QRegExpEngine()
1202 captured text. If there is no match, all pairs are (-1, -1). 1208 captured text. If there is no match, all pairs are (-1, -1).
1203*/ 1209*/
1204QArray<int> QRegExpEngine::match( const QString& str, int pos, bool minimal, 1210QArray<int> QRegExpEngine::match( const QString& str, int pos, bool minimal,
1205 bool oneTest ) 1211 bool oneTest )
1206{ 1212{
1207 mmStr = &str; 1213 mmStr = &str;
1208 mmIn = str.unicode(); 1214 mmIn = str.unicode();
1209 if ( mmIn == 0 ) 1215 if ( mmIn == 0 )
1210 mmIn = &QChar::null; 1216 mmIn = &QChar::null;
1211 mmPos = pos; 1217 mmPos = pos;
1212 mmLen = str.length(); 1218 mmLen = str.length();
1213 mmMinimal = minimal; 1219 mmMinimal = minimal;
@@ -1216,31 +1222,31 @@ QArray<int> QRegExpEngine::match( const QString& str, int pos, bool minimal,
1216 bool matched = FALSE; 1222 bool matched = FALSE;
1217 if ( valid && mmPos >= 0 && mmPos <= mmLen ) { 1223 if ( valid && mmPos >= 0 && mmPos <= mmLen ) {
1218#ifndef QT_NO_REGEXP_OPTIM 1224#ifndef QT_NO_REGEXP_OPTIM
1219 if ( mmPos <= mmLen - minl ) { 1225 if ( mmPos <= mmLen - minl ) {
1220 if ( caretAnchored || oneTest ) 1226 if ( caretAnchored || oneTest )
1221 matched = matchHere(); 1227 matched = matchHere();
1222 else if ( useGoodStringHeuristic ) 1228 else if ( useGoodStringHeuristic )
1223 matched = goodStringMatch(); 1229 matched = goodStringMatch();
1224 else 1230 else
1225 matched = badCharMatch(); 1231 matched = badCharMatch();
1226 } 1232 }
1227#else 1233#else
1228 matched = oneTest ? matchHere() : bruteMatch(); 1234 matched = oneTest ? matchHere() : bruteMatch();
1229#endif 1235#endif
1230 } 1236 }
1231 1237
1232 if ( matched ) { 1238 if ( matched ) {
1233 mmCaptured.detach(); 1239 mmCaptured.detach();
1234 mmCaptured[0] = mmPos; 1240 mmCaptured[0] = mmPos;
1235 mmCaptured[1] = mmMatchedLen; 1241 mmCaptured[1] = mmMatchedLen;
1236 for ( int j = 0; j < realncap; j++ ) { 1242 for ( int j = 0; j < realncap; j++ ) {
1237 int len = mmCapEnd[j] - mmCapBegin[j]; 1243 int len = mmCapEnd[j] - mmCapBegin[j];
1238 mmCaptured[2 + 2 * j] = len > 0 ? mmPos + mmCapBegin[j] : 0; 1244 mmCaptured[2 + 2 * j] = len > 0 ? mmPos + mmCapBegin[j] : 0;
1239 mmCaptured[2 + 2 * j + 1] = len; 1245 mmCaptured[2 + 2 * j + 1] = len;
1240 } 1246 }
1241 return mmCaptured; 1247 return mmCaptured;
1242 } else { 1248 } else {
1243 return mmCapturedNoMatch; 1249 return mmCapturedNoMatch;
1244 } 1250 }
1245} 1251}
1246 1252
@@ -1271,11 +1277,11 @@ int QRegExpEngine::createState( const CharClass& cc )
1271int QRegExpEngine::createState( int bref ) 1277int QRegExpEngine::createState( int bref )
1272{ 1278{
1273 if ( bref > nbrefs ) { 1279 if ( bref > nbrefs ) {
1274 nbrefs = bref; 1280 nbrefs = bref;
1275 if ( nbrefs > MaxBackRefs ) { 1281 if ( nbrefs > MaxBackRefs ) {
1276 yyError = TRUE; 1282 yyError = TRUE;
1277 return 0; 1283 return 0;
1278 } 1284 }
1279 } 1285 }
1280 return setupState( BackRefBit | bref ); 1286 return setupState( BackRefBit | bref );
1281} 1287}
@@ -1289,31 +1295,31 @@ int QRegExpEngine::createState( int bref )
1289*/ 1295*/
1290 1296
1291void QRegExpEngine::addCatTransitions( const QArray<int>& from, 1297void QRegExpEngine::addCatTransitions( const QArray<int>& from,
1292 const QArray<int>& to ) 1298 const QArray<int>& to )
1293{ 1299{
1294 for ( int i = 0; i < (int) from.size(); i++ ) { 1300 for ( int i = 0; i < (int) from.size(); i++ ) {
1295 State *st = s[from[i]]; 1301 State *st = s[from[i]];
1296 mergeInto( &st->outs, to ); 1302 mergeInto( &st->outs, to );
1297 } 1303 }
1298} 1304}
1299 1305
1300#ifndef QT_NO_REGEXP_CAPTURE 1306#ifndef QT_NO_REGEXP_CAPTURE
1301void QRegExpEngine::addPlusTransitions( const QArray<int>& from, 1307void QRegExpEngine::addPlusTransitions( const QArray<int>& from,
1302 const QArray<int>& to, int atom ) 1308 const QArray<int>& to, int atom )
1303{ 1309{
1304 for ( int i = 0; i < (int) from.size(); i++ ) { 1310 for ( int i = 0; i < (int) from.size(); i++ ) {
1305 State *st = s[from[i]]; 1311 State *st = s[from[i]];
1306 QArray<int> oldOuts = st->outs.copy(); 1312 QArray<int> oldOuts = st->outs.copy();
1307 mergeInto( &st->outs, to ); 1313 mergeInto( &st->outs, to );
1308 if ( f[atom].capture >= 0 ) { 1314 if ( f[atom].capture >= 0 ) {
1309 if ( st->reenter == 0 ) 1315 if ( st->reenter == 0 )
1310 st->reenter = new QMap<int, int>; 1316 st->reenter = new QMap<int, int>;
1311 for ( int j = 0; j < (int) to.size(); j++ ) { 1317 for ( int j = 0; j < (int) to.size(); j++ ) {
1312 if ( !st->reenter->contains(to[j]) && 1318 if ( !st->reenter->contains(to[j]) &&
1313 oldOuts.bsearch(to[j]) < 0 ) 1319 oldOuts.bsearch(to[j]) < 0 )
1314 st->reenter->insert( to[j], atom ); 1320 st->reenter->insert( to[j], atom );
1315 } 1321 }
1316 } 1322 }
1317 } 1323 }
1318} 1324}
1319#endif 1325#endif
@@ -1325,7 +1331,7 @@ void QRegExpEngine::addPlusTransitions( const QArray<int>& from,
1325int QRegExpEngine::anchorAlternation( int a, int b ) 1331int QRegExpEngine::anchorAlternation( int a, int b )
1326{ 1332{
1327 if ( ((a & b) == a || (a & b) == b) && ((a | b) & Anchor_Alternation) == 0 ) 1333 if ( ((a & b) == a || (a & b) == b) && ((a | b) & Anchor_Alternation) == 0 )
1328 return a & b; 1334 return a & b;
1329 1335
1330 int n = aa.size(); 1336 int n = aa.size();
1331 aa.resize( n + 1 ); 1337 aa.resize( n + 1 );
@@ -1340,9 +1346,9 @@ int QRegExpEngine::anchorAlternation( int a, int b )
1340int QRegExpEngine::anchorConcatenation( int a, int b ) 1346int QRegExpEngine::anchorConcatenation( int a, int b )
1341{ 1347{
1342 if ( ((a | b) & Anchor_Alternation) == 0 ) 1348 if ( ((a | b) & Anchor_Alternation) == 0 )
1343 return a | b; 1349 return a | b;
1344 if ( (b & Anchor_Alternation) != 0 ) 1350 if ( (b & Anchor_Alternation) != 0 )
1345 qSwap( a, b ); 1351 qSwap( a, b );
1346 int aprime = anchorConcatenation( aa[a ^ Anchor_Alternation].a, b ); 1352 int aprime = anchorConcatenation( aa[a ^ Anchor_Alternation].a, b );
1347 int bprime = anchorConcatenation( aa[a ^ Anchor_Alternation].b, b ); 1353 int bprime = anchorConcatenation( aa[a ^ Anchor_Alternation].b, b );
1348 return anchorAlternation( aprime, bprime ); 1354 return anchorAlternation( aprime, bprime );
@@ -1356,9 +1362,9 @@ void QRegExpEngine::addAnchors( int from, int to, int a )
1356{ 1362{
1357 State *st = s[from]; 1363 State *st = s[from];
1358 if ( st->anchors == 0 ) 1364 if ( st->anchors == 0 )
1359 st->anchors = new QMap<int, int>; 1365 st->anchors = new QMap<int, int>;
1360 if ( st->anchors->contains(to) ) 1366 if ( st->anchors->contains(to) )
1361 a = anchorAlternation( (*st->anchors)[to], a ); 1367 a = anchorAlternation( (*st->anchors)[to], a );
1362 st->anchors->insert( to, a ); 1368 st->anchors->insert( to, a );
1363} 1369}
1364 1370
@@ -1369,7 +1375,7 @@ void QRegExpEngine::addAnchors( int from, int to, int a )
1369*/ 1375*/
1370 1376
1371void QRegExpEngine::setupGoodStringHeuristic( int earlyStart, int lateStart, 1377void QRegExpEngine::setupGoodStringHeuristic( int earlyStart, int lateStart,
1372 const QString& str ) 1378 const QString& str )
1373{ 1379{
1374 goodEarlyStart = earlyStart; 1380 goodEarlyStart = earlyStart;
1375 goodLateStart = lateStart; 1381 goodLateStart = lateStart;
@@ -1377,7 +1383,7 @@ void QRegExpEngine::setupGoodStringHeuristic( int earlyStart, int lateStart,
1377} 1383}
1378 1384
1379void QRegExpEngine::setupBadCharHeuristic( int minLen, 1385void QRegExpEngine::setupBadCharHeuristic( int minLen,
1380 const QArray<int>& firstOcc ) 1386 const QArray<int>& firstOcc )
1381{ 1387{
1382 minl = minLen; 1388 minl = minLen;
1383 occ1 = cs ? firstOcc : *firstOccurrenceAtZero; 1389 occ1 = cs ? firstOcc : *firstOccurrenceAtZero;
@@ -1400,14 +1406,14 @@ void QRegExpEngine::heuristicallyChooseHeuristic()
1400 int i; 1406 int i;
1401 1407
1402 if ( minl == 0 ) 1408 if ( minl == 0 )
1403 return; 1409 return;
1404 1410
1405 /* 1411 /*
1406 Magic formula: The good string has to constitute a good proportion of the 1412 Magic formula: The good string has to constitute a good proportion of the
1407 minimum-length string, and appear at a more-or-less known index. 1413 minimum-length string, and appear at a more-or-less known index.
1408 */ 1414 */
1409 int goodStringScore = ( 64 * goodStr.length() / minl ) - 1415 int goodStringScore = ( 64 * goodStr.length() / minl ) -
1410 ( goodLateStart - goodEarlyStart ); 1416 ( goodLateStart - goodEarlyStart );
1411 1417
1412 /* 1418 /*
1413 Less magic formula: We pick a couple of characters at random, and check 1419 Less magic formula: We pick a couple of characters at random, and check
@@ -1416,10 +1422,10 @@ void QRegExpEngine::heuristicallyChooseHeuristic()
1416 int badCharScore = 0; 1422 int badCharScore = 0;
1417 int step = QMAX( 1, NumBadChars / 32 ); 1423 int step = QMAX( 1, NumBadChars / 32 );
1418 for ( i = 1; i < NumBadChars; i += step ) { 1424 for ( i = 1; i < NumBadChars; i += step ) {
1419 if ( occ1[i] == NoOccurrence ) 1425 if ( occ1[i] == NoOccurrence )
1420 badCharScore += minl; 1426 badCharScore += minl;
1421 else 1427 else
1422 badCharScore += occ1[i]; 1428 badCharScore += occ1[i];
1423 } 1429 }
1424 badCharScore /= minl; 1430 badCharScore /= minl;
1425 1431
@@ -1431,50 +1437,50 @@ void QRegExpEngine::heuristicallyChooseHeuristic()
1431void QRegExpEngine::dump() const 1437void QRegExpEngine::dump() const
1432{ 1438{
1433 int i, j; 1439 int i, j;
1434 qDebug( "Case %ssensitive engine", cs ? "" : "in" ); 1440 odebug << "Case " << (cs ? "" : "in") << "sensitive engine" << oendl;
1435 qDebug( " States" ); 1441 odebug << " States" << oendl;
1436 for ( i = 0; i < ns; i++ ) { 1442 for ( i = 0; i < ns; i++ ) {
1437 qDebug( " %d%s", i, 1443 odebug << " " << i
1438 i == InitialState ? " (initial)" : 1444 << (i == InitialState ? " (initial)" : i == FinalState ? " (final)" : "") << oendl;
1439 i == FinalState ? " (final)" : "" ); 1445
1440#ifndef QT_NO_REGEXP_CAPTURE 1446#ifndef QT_NO_REGEXP_CAPTURE
1441 qDebug( " in atom %d", s[i]->atom ); 1447 odebug << " in atom " << s[i]->atom << oendl;
1442#endif 1448#endif
1443 int m = s[i]->match; 1449 int m = s[i]->match;
1444 if ( (m & CharClassBit) != 0 ) { 1450 if ( (m & CharClassBit) != 0 ) {
1445 qDebug( " match character class %d", m ^ CharClassBit ); 1451 odebug << " match character class " << (m ^ CharClassBit) << oendl;
1446#ifndef QT_NO_REGEXP_CCLASS 1452#ifndef QT_NO_REGEXP_CCLASS
1447 cl[m ^ CharClassBit]->dump(); 1453 cl[m ^ CharClassBit]->dump();
1448#else 1454#else
1449 qDebug( " negative character class" ); 1455 odebug << " negative character class" << oendl;
1450#endif 1456#endif
1451 } else if ( (m & BackRefBit) != 0 ) { 1457 } else if ( (m & BackRefBit) != 0 ) {
1452 qDebug( " match back-reference %d", m ^ BackRefBit ); 1458 odebug << " match back-reference " << (m ^ BackRefBit) << oendl;
1453 } else if ( m >= 0x20 && m <= 0x7e ) { 1459 } else if ( m >= 0x20 && m <= 0x7e ) {
1454 qDebug( " match 0x%.4x (%c)", m, m ); 1460 odebug << " match " << QString().sprintf( "0x%.4x", m) << " (" << m << ")" << oendl;
1455 } else { 1461
1456 qDebug( " match 0x%.4x", m ); 1462 } else {
1457 } 1463 odebug << " match " << QString().sprintf( "0x%.4x", m) << oendl;
1458 for ( j = 0; j < (int) s[i]->outs.size(); j++ ) { 1464 }
1459 int next = s[i]->outs[j]; 1465 for ( j = 0; j < (int) s[i]->outs.size(); j++ ) {
1460 qDebug( " -> %d", next ); 1466 int next = s[i]->outs[j];
1461 if ( s[i]->reenter != 0 && s[i]->reenter->contains(next) ) 1467 odebug << " -> " << next << oendl;
1462 qDebug( " [reenter %d]", (*s[i]->reenter)[next] ); 1468 if ( s[i]->reenter != 0 && s[i]->reenter->contains(next) )
1463 if ( s[i]->anchors != 0 && at(*s[i]->anchors, next) != 0 ) 1469 odebug << " [reenter " << (*s[i]->reenter)[next] << "]" << oendl;
1464 qDebug( " [anchors 0x%.8x]", (*s[i]->anchors)[next] ); 1470 if ( s[i]->anchors != 0 && at(*s[i]->anchors, next) != 0 )
1465 } 1471 odebug << " [anchors " << QString().sprintf( "0x%.8x]", (*s[i]->anchors)[next] ) << oendl;
1472 }
1466 } 1473 }
1467#ifndef QT_NO_REGEXP_CAPTURE 1474#ifndef QT_NO_REGEXP_CAPTURE
1468 if ( nf > 0 ) { 1475 if ( nf > 0 ) {
1469 qDebug( " Atom Parent Capture" ); 1476 odebug << " Atom Parent Capture" << oendl;
1470 for ( i = 0; i < nf; i++ ) 1477 for ( i = 0; i < nf; i++ )
1471 qDebug( " %6d %6d %6d", i, f[i].parent, f[i].capture ); 1478 odebug << QString().sprintf(" %6d %6d %6d", i, f[i].parent, f[i].capture ) << oendl;
1472 } 1479 }
1473#endif 1480#endif
1474#ifndef QT_NO_REGEXP_ANCHOR_ALT 1481#ifndef QT_NO_REGEXP_ANCHOR_ALT
1475 for ( i = 0; i < (int) aa.size(); i++ ) 1482 for ( i = 0; i < (int) aa.size(); i++ )
1476 qDebug( " Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i, aa[i].a, 1483 odebug << QString().sprintf(" Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i, aa[i].a, aa[i].b ) << oendl;
1477 aa[i].b );
1478#endif 1484#endif
1479} 1485}
1480#endif 1486#endif
@@ -1483,10 +1489,10 @@ void QRegExpEngine::setup( bool caseSensitive )
1483{ 1489{
1484#ifndef QT_NO_REGEXP_OPTIM 1490#ifndef QT_NO_REGEXP_OPTIM
1485 if ( engCount++ == 0 ) { 1491 if ( engCount++ == 0 ) {
1486 noOccurrences = new QArray<int>( NumBadChars ); 1492 noOccurrences = new QArray<int>( NumBadChars );
1487 firstOccurrenceAtZero = new QArray<int>( NumBadChars ); 1493 firstOccurrenceAtZero = new QArray<int>( NumBadChars );
1488 noOccurrences->fill( NoOccurrence ); 1494 noOccurrences->fill( NoOccurrence );
1489 firstOccurrenceAtZero->fill( 0 ); 1495 firstOccurrenceAtZero->fill( 0 );
1490 } 1496 }
1491#endif 1497#endif
1492 s.setAutoDelete( TRUE ); 1498 s.setAutoDelete( TRUE );
@@ -1524,7 +1530,7 @@ void QRegExpEngine::setup( bool caseSensitive )
1524int QRegExpEngine::setupState( int match ) 1530int QRegExpEngine::setupState( int match )
1525{ 1531{
1526 if ( (ns & (ns + 1)) == 0 && ns + 1 >= (int) s.size() ) 1532 if ( (ns & (ns + 1)) == 0 && ns + 1 >= (int) s.size() )
1527 s.resize( (ns + 1) << 1 ); 1533 s.resize( (ns + 1) << 1 );
1528#ifndef QT_NO_REGEXP_CAPTURE 1534#ifndef QT_NO_REGEXP_CAPTURE
1529 s.insert( ns, new State(cf, match) ); 1535 s.insert( ns, new State(cf, match) );
1530#else 1536#else
@@ -1542,7 +1548,7 @@ int QRegExpEngine::setupState( int match )
1542int QRegExpEngine::startAtom( bool capture ) 1548int QRegExpEngine::startAtom( bool capture )
1543{ 1549{
1544 if ( (nf & (nf + 1)) == 0 && nf + 1 >= (int) f.size() ) 1550 if ( (nf & (nf + 1)) == 0 && nf + 1 >= (int) f.size() )
1545 f.resize( (nf + 1) << 1 ); 1551 f.resize( (nf + 1) << 1 );
1546 f[nf].parent = cf; 1552 f[nf].parent = cf;
1547 cf = nf++; 1553 cf = nf++;
1548 f[cf].capture = capture ? ncap++ : -1; 1554 f[cf].capture = capture ? ncap++ : -1;
@@ -1558,8 +1564,8 @@ int QRegExpEngine::addLookahead( QRegExpEngine *eng, bool negative )
1558{ 1564{
1559 int n = ahead.size(); 1565 int n = ahead.size();
1560 if ( n == MaxLookaheads ) { 1566 if ( n == MaxLookaheads ) {
1561 yyError = TRUE; 1567 yyError = TRUE;
1562 return 0; 1568 return 0;
1563 } 1569 }
1564 ahead.resize( n + 1 ); 1570 ahead.resize( n + 1 );
1565 ahead.insert( n, new Lookahead(eng, negative) ); 1571 ahead.insert( n, new Lookahead(eng, negative) );
@@ -1572,15 +1578,15 @@ int QRegExpEngine::addLookahead( QRegExpEngine *eng, bool negative )
1572 We want the longest leftmost captures. 1578 We want the longest leftmost captures.
1573*/ 1579*/
1574bool QRegExpEngine::isBetterCapture( const int *begin1, const int *end1, 1580bool QRegExpEngine::isBetterCapture( const int *begin1, const int *end1,
1575 const int *begin2, const int *end2 ) 1581 const int *begin2, const int *end2 )
1576{ 1582{
1577 for ( int i = 0; i < ncap; i++ ) { 1583 for ( int i = 0; i < ncap; i++ ) {
1578 int delta = begin2[i] - begin1[i]; // it has to start early... 1584 int delta = begin2[i] - begin1[i]; // it has to start early...
1579 if ( delta == 0 ) 1585 if ( delta == 0 )
1580 delta = end1[i] - end2[i]; // ...and end late (like a party) 1586 delta = end1[i] - end2[i]; // ...and end late (like a party)
1581 1587
1582 if ( delta != 0 ) 1588 if ( delta != 0 )
1583 return delta > 0; 1589 return delta > 0;
1584 } 1590 }
1585 return FALSE; 1591 return FALSE;
1586} 1592}
@@ -1596,55 +1602,55 @@ bool QRegExpEngine::testAnchor( int i, int a, const int *capBegin )
1596 1602
1597#ifndef QT_NO_REGEXP_ANCHOR_ALT 1603#ifndef QT_NO_REGEXP_ANCHOR_ALT
1598 if ( (a & Anchor_Alternation) != 0 ) { 1604 if ( (a & Anchor_Alternation) != 0 ) {
1599 return testAnchor( i, aa[a ^ Anchor_Alternation].a, capBegin ) || 1605 return testAnchor( i, aa[a ^ Anchor_Alternation].a, capBegin ) ||
1600 testAnchor( i, aa[a ^ Anchor_Alternation].b, capBegin ); 1606 testAnchor( i, aa[a ^ Anchor_Alternation].b, capBegin );
1601 } 1607 }
1602#endif 1608#endif
1603 1609
1604 if ( (a & Anchor_Caret) != 0 ) { 1610 if ( (a & Anchor_Caret) != 0 ) {
1605 if ( mmPos + i != 0 ) 1611 if ( mmPos + i != 0 )
1606 return FALSE; 1612 return FALSE;
1607 } 1613 }
1608 if ( (a & Anchor_Dollar) != 0 ) { 1614 if ( (a & Anchor_Dollar) != 0 ) {
1609 if ( mmPos + i != mmLen ) 1615 if ( mmPos + i != mmLen )
1610 return FALSE; 1616 return FALSE;
1611 } 1617 }
1612#ifndef QT_NO_REGEXP_ESCAPE 1618#ifndef QT_NO_REGEXP_ESCAPE
1613 if ( (a & (Anchor_Word | Anchor_NonWord)) != 0 ) { 1619 if ( (a & (Anchor_Word | Anchor_NonWord)) != 0 ) {
1614 bool before = FALSE, after = FALSE; 1620 bool before = FALSE, after = FALSE;
1615 if ( mmPos + i != 0 ) 1621 if ( mmPos + i != 0 )
1616 before = mmIn[mmPos + i - 1].isLetterOrNumber(); 1622 before = mmIn[mmPos + i - 1].isLetterOrNumber();
1617 if ( mmPos + i != mmLen ) 1623 if ( mmPos + i != mmLen )
1618 after = mmIn[mmPos + i].isLetterOrNumber(); 1624 after = mmIn[mmPos + i].isLetterOrNumber();
1619 if ( (a & Anchor_Word) != 0 && (before == after) ) 1625 if ( (a & Anchor_Word) != 0 && (before == after) )
1620 return FALSE; 1626 return FALSE;
1621 if ( (a & Anchor_NonWord) != 0 && (before != after) ) 1627 if ( (a & Anchor_NonWord) != 0 && (before != after) )
1622 return FALSE; 1628 return FALSE;
1623 } 1629 }
1624#endif 1630#endif
1625#ifndef QT_NO_REGEXP_LOOKAHEAD 1631#ifndef QT_NO_REGEXP_LOOKAHEAD
1626 bool catchx = TRUE; 1632 bool catchx = TRUE;
1627 1633
1628 if ( (a & Anchor_LookaheadMask) != 0 ) { 1634 if ( (a & Anchor_LookaheadMask) != 0 ) {
1629 QConstString cstr = QConstString( (QChar *) mmIn + mmPos + i, 1635 QConstString cstr = QConstString( (QChar *) mmIn + mmPos + i,
1630 mmLen - mmPos - i ); 1636 mmLen - mmPos - i );
1631 for ( j = 0; j < (int) ahead.size(); j++ ) { 1637 for ( j = 0; j < (int) ahead.size(); j++ ) {
1632 if ( (a & (Anchor_FirstLookahead << j)) != 0 ) { 1638 if ( (a & (Anchor_FirstLookahead << j)) != 0 ) {
1633 catchx = ( ahead[j]->eng->match(cstr.string(), 0, TRUE, 1639 catchx = ( ahead[j]->eng->match(cstr.string(), 0, TRUE,
1634 TRUE)[0] == 0 ); 1640 TRUE)[0] == 0 );
1635 if ( catchx == ahead[j]->neg ) 1641 if ( catchx == ahead[j]->neg )
1636 return FALSE; 1642 return FALSE;
1637 } 1643 }
1638 } 1644 }
1639 } 1645 }
1640#endif 1646#endif
1641#ifndef QT_NO_REGEXP_CAPTURE 1647#ifndef QT_NO_REGEXP_CAPTURE
1642#ifndef QT_NO_REGEXP_BACKREF 1648#ifndef QT_NO_REGEXP_BACKREF
1643 for ( j = 0; j < nbrefs; j++ ) { 1649 for ( j = 0; j < nbrefs; j++ ) {
1644 if ( (a & (Anchor_BackRef1Empty << j)) != 0 ) { 1650 if ( (a & (Anchor_BackRef1Empty << j)) != 0 ) {
1645 if ( capBegin[j] != EmptyCapture ) 1651 if ( capBegin[j] != EmptyCapture )
1646 return FALSE; 1652 return FALSE;
1647 } 1653 }
1648 } 1654 }
1649#endif 1655#endif
1650#endif 1656#endif
@@ -1663,17 +1669,17 @@ bool QRegExpEngine::goodStringMatch()
1663 int k = mmPos + goodEarlyStart; 1669 int k = mmPos + goodEarlyStart;
1664 1670
1665 while ( (k = mmStr->find(goodStr, k, cs)) != -1 ) { 1671 while ( (k = mmStr->find(goodStr, k, cs)) != -1 ) {
1666 int from = k - goodLateStart; 1672 int from = k - goodLateStart;
1667 int to = k - goodEarlyStart; 1673 int to = k - goodEarlyStart;
1668 if ( from > mmPos ) 1674 if ( from > mmPos )
1669 mmPos = from; 1675 mmPos = from;
1670 1676
1671 while ( mmPos <= to ) { 1677 while ( mmPos <= to ) {
1672 if ( matchHere() ) 1678 if ( matchHere() )
1673 return TRUE; 1679 return TRUE;
1674 mmPos++; 1680 mmPos++;
1675 } 1681 }
1676 k++; 1682 k++;
1677 } 1683 }
1678 return FALSE; 1684 return FALSE;
1679} 1685}
@@ -1691,54 +1697,54 @@ bool QRegExpEngine::badCharMatch()
1691 the table of first occurrence of each character. 1697 the table of first occurrence of each character.
1692 */ 1698 */
1693 for ( i = 0; i < minl; i++ ) { 1699 for ( i = 0; i < minl; i++ ) {
1694 int sk = occ1[BadChar(mmIn[mmPos + i])]; 1700 int sk = occ1[BadChar(mmIn[mmPos + i])];
1695 if ( sk == NoOccurrence ) 1701 if ( sk == NoOccurrence )
1696 sk = i + 1; 1702 sk = i + 1;
1697 if ( sk > 0 ) { 1703 if ( sk > 0 ) {
1698 int k = i + 1 - sk; 1704 int k = i + 1 - sk;
1699 if ( k < 0 ) { 1705 if ( k < 0 ) {
1700 sk = i + 1; 1706 sk = i + 1;
1701 k = 0; 1707 k = 0;
1702 } 1708 }
1703 if ( sk > mmSlideTab[k] ) 1709 if ( sk > mmSlideTab[k] )
1704 mmSlideTab[k] = sk; 1710 mmSlideTab[k] = sk;
1705 } 1711 }
1706 } 1712 }
1707 1713
1708 if ( mmPos > lastPos ) 1714 if ( mmPos > lastPos )
1709 return FALSE; 1715 return FALSE;
1710 1716
1711 while ( TRUE ) { 1717 while ( TRUE ) {
1712 if ( ++slideNext >= mmSlideTabSize ) 1718 if ( ++slideNext >= mmSlideTabSize )
1713 slideNext = 0; 1719 slideNext = 0;
1714 if ( mmSlideTab[slideHead] > 0 ) { 1720 if ( mmSlideTab[slideHead] > 0 ) {
1715 if ( mmSlideTab[slideHead] - 1 > mmSlideTab[slideNext] ) 1721 if ( mmSlideTab[slideHead] - 1 > mmSlideTab[slideNext] )
1716 mmSlideTab[slideNext] = mmSlideTab[slideHead] - 1; 1722 mmSlideTab[slideNext] = mmSlideTab[slideHead] - 1;
1717 mmSlideTab[slideHead] = 0; 1723 mmSlideTab[slideHead] = 0;
1718 } else { 1724 } else {
1719 if ( matchHere() ) 1725 if ( matchHere() )
1720 return TRUE; 1726 return TRUE;
1721 } 1727 }
1722 1728
1723 if ( mmPos == lastPos ) 1729 if ( mmPos == lastPos )
1724 break; 1730 break;
1725 1731
1726 /* 1732 /*
1727 Update the slide table. This code has much in common with the 1733 Update the slide table. This code has much in common with the
1728 initialization code. 1734 initialization code.
1729 */ 1735 */
1730 int sk = occ1[BadChar(mmIn[mmPos + minl])]; 1736 int sk = occ1[BadChar(mmIn[mmPos + minl])];
1731 if ( sk == NoOccurrence ) { 1737 if ( sk == NoOccurrence ) {
1732 mmSlideTab[slideNext] = minl; 1738 mmSlideTab[slideNext] = minl;
1733 } else if ( sk > 0 ) { 1739 } else if ( sk > 0 ) {
1734 int k = slideNext + minl - sk; 1740 int k = slideNext + minl - sk;
1735 if ( k >= mmSlideTabSize ) 1741 if ( k >= mmSlideTabSize )
1736 k -= mmSlideTabSize; 1742 k -= mmSlideTabSize;
1737 if ( sk > mmSlideTab[k] ) 1743 if ( sk > mmSlideTab[k] )
1738 mmSlideTab[k] = sk; 1744 mmSlideTab[k] = sk;
1739 } 1745 }
1740 slideHead = slideNext; 1746 slideHead = slideNext;
1741 mmPos++; 1747 mmPos++;
1742 } 1748 }
1743 return FALSE; 1749 return FALSE;
1744} 1750}
@@ -1746,9 +1752,9 @@ bool QRegExpEngine::badCharMatch()
1746bool QRegExpEngine::bruteMatch() 1752bool QRegExpEngine::bruteMatch()
1747{ 1753{
1748 while ( mmPos <= mmLen ) { 1754 while ( mmPos <= mmLen ) {
1749 if ( matchHere() ) 1755 if ( matchHere() )
1750 return TRUE; 1756 return TRUE;
1751 mmPos++; 1757 mmPos++;
1752 } 1758 }
1753 return FALSE; 1759 return FALSE;
1754} 1760}
@@ -1768,10 +1774,10 @@ bool QRegExpEngine::matchHere()
1768 1774
1769#ifndef QT_NO_REGEXP_CAPTURE 1775#ifndef QT_NO_REGEXP_CAPTURE
1770 if ( ncap > 0 ) { 1776 if ( ncap > 0 ) {
1771 for ( j = 0; j < ncap; j++ ) { 1777 for ( j = 0; j < ncap; j++ ) {
1772 mmCurCapBegin[j] = EmptyCapture; 1778 mmCurCapBegin[j] = EmptyCapture;
1773 mmCurCapEnd[j] = EmptyCapture; 1779 mmCurCapEnd[j] = EmptyCapture;
1774 } 1780 }
1775 } 1781 }
1776#endif 1782#endif
1777 1783
@@ -1779,311 +1785,311 @@ bool QRegExpEngine::matchHere()
1779 int *zzZ = 0; 1785 int *zzZ = 0;
1780 1786
1781 while ( (ncur > 0 || mmSleeping.count() > 0) && i <= mmLen - mmPos && 1787 while ( (ncur > 0 || mmSleeping.count() > 0) && i <= mmLen - mmPos &&
1782 !match ) 1788 !match )
1783#else 1789#else
1784 while ( ncur > 0 && i <= mmLen - mmPos && !match ) 1790 while ( ncur > 0 && i <= mmLen - mmPos && !match )
1785#endif 1791#endif
1786 { 1792 {
1787 int ch = ( i < mmLen - mmPos ) ? mmIn[mmPos + i].unicode() : 0; 1793 int ch = ( i < mmLen - mmPos ) ? mmIn[mmPos + i].unicode() : 0;
1788 for ( j = 0; j < ncur; j++ ) { 1794 for ( j = 0; j < ncur; j++ ) {
1789 int cur = mmCurStack[j]; 1795 int cur = mmCurStack[j];
1790 State *scur = s[cur]; 1796 State *scur = s[cur];
1791 QArray<int>& outs = scur->outs; 1797 QArray<int>& outs = scur->outs;
1792 for ( k = 0; k < (int) outs.size(); k++ ) { 1798 for ( k = 0; k < (int) outs.size(); k++ ) {
1793 int next = outs[k]; 1799 int next = outs[k];
1794 State *snext = s[next]; 1800 State *snext = s[next];
1795 bool in = TRUE; 1801 bool in = TRUE;
1796#ifndef QT_NO_REGEXP_BACKREF 1802#ifndef QT_NO_REGEXP_BACKREF
1797 int needSomeSleep = 0; 1803 int needSomeSleep = 0;
1798#endif 1804#endif
1799 1805
1800 /* 1806 /*
1801 First, check if the anchors are anchored properly. 1807 First, check if the anchors are anchored properly.
1802 */ 1808 */
1803 if ( scur->anchors != 0 ) { 1809 if ( scur->anchors != 0 ) {
1804 int a = at( *scur->anchors, next ); 1810 int a = at( *scur->anchors, next );
1805 if ( a != 0 && !testAnchor(i, a, mmCurCapBegin + j * ncap) ) 1811 if ( a != 0 && !testAnchor(i, a, mmCurCapBegin + j * ncap) )
1806 in = FALSE; 1812 in = FALSE;
1807 } 1813 }
1808 /* 1814 /*
1809 If indeed they are, check if the input character is correct 1815 If indeed they are, check if the input character is correct
1810 for this transition. 1816 for this transition.
1811 */ 1817 */
1812 if ( in ) { 1818 if ( in ) {
1813 m = snext->match; 1819 m = snext->match;
1814 if ( (m & (CharClassBit | BackRefBit)) == 0 ) { 1820 if ( (m & (CharClassBit | BackRefBit)) == 0 ) {
1815 if ( cs ) 1821 if ( cs )
1816 in = ( m == ch ); 1822 in = ( m == ch );
1817 else 1823 else
1818 in = ( QChar(m).lower() == QChar(ch).lower() ); 1824 in = ( QChar(m).lower() == QChar(ch).lower() );
1819 } else if ( next == FinalState ) { 1825 } else if ( next == FinalState ) {
1820 mmMatchedLen = i; 1826 mmMatchedLen = i;
1821 match = mmMinimal; 1827 match = mmMinimal;
1822 in = TRUE; 1828 in = TRUE;
1823 } else if ( (m & CharClassBit) != 0 ) { 1829 } else if ( (m & CharClassBit) != 0 ) {
1824#ifndef QT_NO_REGEXP_CCLASS 1830#ifndef QT_NO_REGEXP_CCLASS
1825 const CharClass *cc = cl[m ^ CharClassBit]; 1831 const CharClass *cc = cl[m ^ CharClassBit];
1826 if ( cs ) 1832 if ( cs )
1827 in = cc->in( ch ); 1833 in = cc->in( ch );
1828 else if ( cc->negative() ) 1834 else if ( cc->negative() )
1829 in = cc->in( QChar(ch).lower() ) && 1835 in = cc->in( QChar(ch).lower() ) &&
1830 cc->in( QChar(ch).upper() ); 1836 cc->in( QChar(ch).upper() );
1831 else 1837 else
1832 in = cc->in( QChar(ch).lower() ) || 1838 in = cc->in( QChar(ch).lower() ) ||
1833 cc->in( QChar(ch).upper() ); 1839 cc->in( QChar(ch).upper() );
1834#endif 1840#endif
1835#ifndef QT_NO_REGEXP_BACKREF 1841#ifndef QT_NO_REGEXP_BACKREF
1836 } else { /* ( (m & BackRefBit) != 0 ) */ 1842 } else { /* ( (m & BackRefBit) != 0 ) */
1837 int bref = m ^ BackRefBit; 1843 int bref = m ^ BackRefBit;
1838 int ell = j * ncap + ( bref - 1 ); 1844 int ell = j * ncap + ( bref - 1 );
1839 1845
1840 in = bref <= ncap && mmCurCapBegin[ell] != EmptyCapture; 1846 in = bref <= ncap && mmCurCapBegin[ell] != EmptyCapture;
1841 if ( in ) { 1847 if ( in ) {
1842 if ( cs ) 1848 if ( cs )
1843 in = ( mmIn[mmPos + mmCurCapBegin[ell]] 1849 in = ( mmIn[mmPos + mmCurCapBegin[ell]]
1844 == QChar(ch) ); 1850 == QChar(ch) );
1845 else 1851 else
1846 in = ( mmIn[mmPos + mmCurCapBegin[ell]].lower() 1852 in = ( mmIn[mmPos + mmCurCapBegin[ell]].lower()
1847 == QChar(ch).lower() ); 1853 == QChar(ch).lower() );
1848 } 1854 }
1849 1855
1850 if ( in ) { 1856 if ( in ) {
1851 int delta; 1857 int delta;
1852 if ( mmCurCapEnd[ell] == EmptyCapture ) 1858 if ( mmCurCapEnd[ell] == EmptyCapture )
1853 delta = i - mmCurCapBegin[ell]; 1859 delta = i - mmCurCapBegin[ell];
1854 else 1860 else
1855 delta = mmCurCapEnd[ell] - mmCurCapBegin[ell]; 1861 delta = mmCurCapEnd[ell] - mmCurCapBegin[ell];
1856 1862
1857 in = ( delta <= mmLen - mmPos ); 1863 in = ( delta <= mmLen - mmPos );
1858 if ( in && delta > 1 ) { 1864 if ( in && delta > 1 ) {
1859 int n; 1865 int n;
1860 if ( cs ) { 1866 if ( cs ) {
1861 for ( n = 1; n < delta; n++ ) { 1867 for ( n = 1; n < delta; n++ ) {
1862 if ( mmIn[mmPos + 1868 if ( mmIn[mmPos +
1863 mmCurCapBegin[ell] + n] != 1869 mmCurCapBegin[ell] + n] !=
1864 mmIn[mmPos + i + n] ) 1870 mmIn[mmPos + i + n] )
1865 break; 1871 break;
1866 } 1872 }
1867 } else { 1873 } else {
1868 for ( n = 1; n < delta; n++ ) { 1874 for ( n = 1; n < delta; n++ ) {
1869 QChar a = mmIn[mmPos + 1875 QChar a = mmIn[mmPos +
1870 mmCurCapBegin[ell] + n]; 1876 mmCurCapBegin[ell] + n];
1871 QChar b = mmIn[mmPos + i + n]; 1877 QChar b = mmIn[mmPos + i + n];
1872 if ( a.lower() != b.lower() ) 1878 if ( a.lower() != b.lower() )
1873 break; 1879 break;
1874 } 1880 }
1875 } 1881 }
1876 in = ( n == delta ); 1882 in = ( n == delta );
1877 if ( in ) 1883 if ( in )
1878 needSomeSleep = delta - 1; 1884 needSomeSleep = delta - 1;
1879 } 1885 }
1880 } 1886 }
1881#endif 1887#endif
1882 } 1888 }
1883 } 1889 }
1884 1890
1885 /* 1891 /*
1886 All is right. We must now update our data structures. 1892 All is right. We must now update our data structures.
1887 */ 1893 */
1888 if ( in ) { 1894 if ( in ) {
1889#ifndef QT_NO_REGEXP_CAPTURE 1895#ifndef QT_NO_REGEXP_CAPTURE
1890 int *capBegin, *capEnd; 1896 int *capBegin, *capEnd;
1891#endif 1897#endif
1892 /* 1898 /*
1893 If the next state was not encountered yet, all is fine. 1899 If the next state was not encountered yet, all is fine.
1894 */ 1900 */
1895 if ( (m = mmInNextStack[next]) == -1 ) { 1901 if ( (m = mmInNextStack[next]) == -1 ) {
1896 m = nnext++; 1902 m = nnext++;
1897 mmNextStack[m] = next; 1903 mmNextStack[m] = next;
1898 mmInNextStack[next] = m; 1904 mmInNextStack[next] = m;
1899#ifndef QT_NO_REGEXP_CAPTURE 1905#ifndef QT_NO_REGEXP_CAPTURE
1900 capBegin = mmNextCapBegin + m * ncap; 1906 capBegin = mmNextCapBegin + m * ncap;
1901 capEnd = mmNextCapEnd + m * ncap; 1907 capEnd = mmNextCapEnd + m * ncap;
1902 1908
1903 /* 1909 /*
1904 Otherwise, we'll first maintain captures in temporary 1910 Otherwise, we'll first maintain captures in temporary
1905 arrays, and decide at the end whether it's best to keep 1911 arrays, and decide at the end whether it's best to keep
1906 the previous capture zones or the new ones. 1912 the previous capture zones or the new ones.
1907 */ 1913 */
1908 } else { 1914 } else {
1909 capBegin = mmTempCapBegin; 1915 capBegin = mmTempCapBegin;
1910 capEnd = mmTempCapEnd; 1916 capEnd = mmTempCapEnd;
1911#endif 1917#endif
1912 } 1918 }
1913 1919
1914#ifndef QT_NO_REGEXP_CAPTURE 1920#ifndef QT_NO_REGEXP_CAPTURE
1915 /* 1921 /*
1916 Updating the capture zones is much of a task. 1922 Updating the capture zones is much of a task.
1917 */ 1923 */
1918 if ( ncap > 0 ) { 1924 if ( ncap > 0 ) {
1919 memcpy( capBegin, mmCurCapBegin + j * ncap, 1925 memcpy( capBegin, mmCurCapBegin + j * ncap,
1920 ncap * sizeof(int) ); 1926 ncap * sizeof(int) );
1921 memcpy( capEnd, mmCurCapEnd + j * ncap, 1927 memcpy( capEnd, mmCurCapEnd + j * ncap,
1922 ncap * sizeof(int) ); 1928 ncap * sizeof(int) );
1923 int c = scur->atom, n = snext->atom; 1929 int c = scur->atom, n = snext->atom;
1924 int p = -1, q = -1; 1930 int p = -1, q = -1;
1925 int cap; 1931 int cap;
1926 1932
1927 /* 1933 /*
1928 Lemma 1. For any x in the range [0..nf), we have 1934 Lemma 1. For any x in the range [0..nf), we have
1929 f[x].parent < x. 1935 f[x].parent < x.
1930 1936
1931 Proof. By looking at startAtom(), it is clear that 1937 Proof. By looking at startAtom(), it is clear that
1932 cf < nf holds all the time, and thus that 1938 cf < nf holds all the time, and thus that
1933 f[nf].parent < nf. 1939 f[nf].parent < nf.
1934 */ 1940 */
1935 1941
1936 /* 1942 /*
1937 If we are reentering an atom, we empty all capture 1943 If we are reentering an atom, we empty all capture
1938 zones inside it. 1944 zones inside it.
1939 */ 1945 */
1940 if ( scur->reenter != 0 && 1946 if ( scur->reenter != 0 &&
1941 (q = at(*scur->reenter, next)) != 0 ) { 1947 (q = at(*scur->reenter, next)) != 0 ) {
1942 QBitArray b; 1948 QBitArray b;
1943 b.fill( FALSE, nf ); 1949 b.fill( FALSE, nf );
1944 b.setBit( q, TRUE ); 1950 b.setBit( q, TRUE );
1945 for ( int ell = q + 1; ell < nf; ell++ ) { 1951 for ( int ell = q + 1; ell < nf; ell++ ) {
1946 if ( b.testBit(f[ell].parent) ) { 1952 if ( b.testBit(f[ell].parent) ) {
1947 b.setBit( ell, TRUE ); 1953 b.setBit( ell, TRUE );
1948 cap = f[ell].capture; 1954 cap = f[ell].capture;
1949 if ( cap >= 0 ) { 1955 if ( cap >= 0 ) {
1950 capBegin[cap] = EmptyCapture; 1956 capBegin[cap] = EmptyCapture;
1951 capEnd[cap] = EmptyCapture; 1957 capEnd[cap] = EmptyCapture;
1952 } 1958 }
1953 } 1959 }
1954 } 1960 }
1955 p = f[q].parent; 1961 p = f[q].parent;
1956 1962
1957 /* 1963 /*
1958 Otherwise, close the capture zones we are leaving. 1964 Otherwise, close the capture zones we are leaving.
1959 We are leaving f[c].capture, f[f[c].parent].capture, 1965 We are leaving f[c].capture, f[f[c].parent].capture,
1960 f[f[f[c].parent].parent].capture, ..., until 1966 f[f[f[c].parent].parent].capture, ..., until
1961 f[x].capture, with x such that f[x].parent is the 1967 f[x].capture, with x such that f[x].parent is the
1962 youngest common ancestor for c and n. 1968 youngest common ancestor for c and n.
1963 1969
1964 We go up along c's and n's ancestry until we find x. 1970 We go up along c's and n's ancestry until we find x.
1965 */ 1971 */
1966 } else { 1972 } else {
1967 p = c; 1973 p = c;
1968 q = n; 1974 q = n;
1969 while ( p != q ) { 1975 while ( p != q ) {
1970 if ( p > q ) { 1976 if ( p > q ) {
1971 cap = f[p].capture; 1977 cap = f[p].capture;
1972 if ( cap >= 0 ) { 1978 if ( cap >= 0 ) {
1973 if ( capBegin[cap] == i ) { 1979 if ( capBegin[cap] == i ) {
1974 capBegin[cap] = EmptyCapture; 1980 capBegin[cap] = EmptyCapture;
1975 capEnd[cap] = EmptyCapture; 1981 capEnd[cap] = EmptyCapture;
1976 } else { 1982 } else {
1977 capEnd[cap] = i; 1983 capEnd[cap] = i;
1978 } 1984 }
1979 } 1985 }
1980 p = f[p].parent; 1986 p = f[p].parent;
1981 } else { 1987 } else {
1982 q = f[q].parent; 1988 q = f[q].parent;
1983 } 1989 }
1984 } 1990 }
1985 } 1991 }
1986 1992
1987 /* 1993 /*
1988 In any case, we now open the capture zones we are 1994 In any case, we now open the capture zones we are
1989 entering. We work upwards from n until we reach p 1995 entering. We work upwards from n until we reach p
1990 (the parent of the atom we reenter or the youngest 1996 (the parent of the atom we reenter or the youngest
1991 common ancestor). 1997 common ancestor).
1992 */ 1998 */
1993 while ( n > p ) { 1999 while ( n > p ) {
1994 cap = f[n].capture; 2000 cap = f[n].capture;
1995 if ( cap >= 0 ) { 2001 if ( cap >= 0 ) {
1996 capBegin[cap] = i; 2002 capBegin[cap] = i;
1997 capEnd[cap] = EmptyCapture; 2003 capEnd[cap] = EmptyCapture;
1998 } 2004 }
1999 n = f[n].parent; 2005 n = f[n].parent;
2000 } 2006 }
2001 /* 2007 /*
2002 If the next state was already in mmNextStack, we must 2008 If the next state was already in mmNextStack, we must
2003 choose carefully which capture zones we want to keep. 2009 choose carefully which capture zones we want to keep.
2004 */ 2010 */
2005 if ( capBegin == mmTempCapBegin && 2011 if ( capBegin == mmTempCapBegin &&
2006 isBetterCapture(capBegin, capEnd, 2012 isBetterCapture(capBegin, capEnd,
2007 mmNextCapBegin + m * ncap, 2013 mmNextCapBegin + m * ncap,
2008 mmNextCapEnd + m * ncap) ) { 2014 mmNextCapEnd + m * ncap) ) {
2009 memcpy( mmNextCapBegin + m * ncap, capBegin, 2015 memcpy( mmNextCapBegin + m * ncap, capBegin,
2010 ncap * sizeof(int) ); 2016 ncap * sizeof(int) );
2011 memcpy( mmNextCapEnd + m * ncap, capEnd, 2017 memcpy( mmNextCapEnd + m * ncap, capEnd,
2012 ncap * sizeof(int) ); 2018 ncap * sizeof(int) );
2013 } 2019 }
2014 } 2020 }
2015#ifndef QT_NO_REGEXP_BACKREF 2021#ifndef QT_NO_REGEXP_BACKREF
2016 /* 2022 /*
2017 We are done with updating the capture zones. It's now 2023 We are done with updating the capture zones. It's now
2018 time to put the next state to sleep, if it needs to, and 2024 time to put the next state to sleep, if it needs to, and
2019 to remove it from mmNextStack. 2025 to remove it from mmNextStack.
2020 */ 2026 */
2021 if ( needSomeSleep > 0 ) { 2027 if ( needSomeSleep > 0 ) {
2022 zzZ = new int[1 + 2 * ncap]; 2028 zzZ = new int[1 + 2 * ncap];
2023 zzZ[0] = next; 2029 zzZ[0] = next;
2024 if ( ncap > 0 ) { 2030 if ( ncap > 0 ) {
2025 memcpy( zzZ + 1, capBegin, ncap * sizeof(int) ); 2031 memcpy( zzZ + 1, capBegin, ncap * sizeof(int) );
2026 memcpy( zzZ + 1 + ncap, capEnd, 2032 memcpy( zzZ + 1 + ncap, capEnd,
2027 ncap * sizeof(int) ); 2033 ncap * sizeof(int) );
2028 } 2034 }
2029 mmInNextStack[mmNextStack[--nnext]] = -1; 2035 mmInNextStack[mmNextStack[--nnext]] = -1;
2030 mmSleeping.insert( i + needSomeSleep, zzZ ); 2036 mmSleeping.insert( i + needSomeSleep, zzZ );
2031 } 2037 }
2032#endif 2038#endif
2033#endif 2039#endif
2034 } 2040 }
2035 } 2041 }
2036 } 2042 }
2037#ifndef QT_NO_REGEXP_CAPTURE 2043#ifndef QT_NO_REGEXP_CAPTURE
2038 /* 2044 /*
2039 If we reached the final state, hurray! Copy the captured zone. 2045 If we reached the final state, hurray! Copy the captured zone.
2040 */ 2046 */
2041 if ( ncap > 0 && (m = mmInNextStack[FinalState]) != -1 ) { 2047 if ( ncap > 0 && (m = mmInNextStack[FinalState]) != -1 ) {
2042 memcpy( mmCapBegin, mmNextCapBegin + m * ncap, ncap * sizeof(int) ); 2048 memcpy( mmCapBegin, mmNextCapBegin + m * ncap, ncap * sizeof(int) );
2043 memcpy( mmCapEnd, mmNextCapEnd + m * ncap, ncap * sizeof(int) ); 2049 memcpy( mmCapEnd, mmNextCapEnd + m * ncap, ncap * sizeof(int) );
2044 } 2050 }
2045#ifndef QT_NO_REGEXP_BACKREF 2051#ifndef QT_NO_REGEXP_BACKREF
2046 /* 2052 /*
2047 It's time to wake up the sleepers. 2053 It's time to wake up the sleepers.
2048 */ 2054 */
2049 if ( mmSleeping.count() > 0 ) { 2055 if ( mmSleeping.count() > 0 ) {
2050 while ( (zzZ = mmSleeping.take(i)) != 0 ) { 2056 while ( (zzZ = mmSleeping.take(i)) != 0 ) {
2051 int next = zzZ[0]; 2057 int next = zzZ[0];
2052 int *capBegin = zzZ + 1; 2058 int *capBegin = zzZ + 1;
2053 int *capEnd = zzZ + 1 + ncap; 2059 int *capEnd = zzZ + 1 + ncap;
2054 bool copyOver = TRUE; 2060 bool copyOver = TRUE;
2055 2061
2056 if ( (m = mmInNextStack[zzZ[0]]) == -1 ) { 2062 if ( (m = mmInNextStack[zzZ[0]]) == -1 ) {
2057 m = nnext++; 2063 m = nnext++;
2058 mmNextStack[m] = next; 2064 mmNextStack[m] = next;
2059 mmInNextStack[next] = m; 2065 mmInNextStack[next] = m;
2060 } else { 2066 } else {
2061 copyOver = isBetterCapture( mmNextCapBegin + m * ncap, 2067 copyOver = isBetterCapture( mmNextCapBegin + m * ncap,
2062 mmNextCapEnd + m * ncap, 2068 mmNextCapEnd + m * ncap,
2063 capBegin, capEnd ); 2069 capBegin, capEnd );
2064 } 2070 }
2065 if ( copyOver ) { 2071 if ( copyOver ) {
2066 memcpy( mmNextCapBegin + m * ncap, capBegin, 2072 memcpy( mmNextCapBegin + m * ncap, capBegin,
2067 ncap * sizeof(int) ); 2073 ncap * sizeof(int) );
2068 memcpy( mmNextCapEnd + m * ncap, capEnd, 2074 memcpy( mmNextCapEnd + m * ncap, capEnd,
2069 ncap * sizeof(int) ); 2075 ncap * sizeof(int) );
2070 } 2076 }
2071 delete[] zzZ; 2077 delete[] zzZ;
2072 } 2078 }
2073 } 2079 }
2074#endif 2080#endif
2075#endif 2081#endif
2076 for ( j = 0; j < nnext; j++ ) 2082 for ( j = 0; j < nnext; j++ )
2077 mmInNextStack[mmNextStack[j]] = -1; 2083 mmInNextStack[mmNextStack[j]] = -1;
2078 2084
2079 qSwap( mmCurStack, mmNextStack ); 2085 qSwap( mmCurStack, mmNextStack );
2080#ifndef QT_NO_REGEXP_CAPTURE 2086#ifndef QT_NO_REGEXP_CAPTURE
2081 qSwap( mmCurCapBegin, mmNextCapBegin ); 2087 qSwap( mmCurCapBegin, mmNextCapBegin );
2082 qSwap( mmCurCapEnd, mmNextCapEnd ); 2088 qSwap( mmCurCapEnd, mmNextCapEnd );
2083#endif 2089#endif
2084 ncur = nnext; 2090 ncur = nnext;
2085 nnext = 0; 2091 nnext = 0;
2086 i++; 2092 i++;
2087 } 2093 }
2088 2094
2089#ifndef QT_NO_REGEXP_BACKREF 2095#ifndef QT_NO_REGEXP_BACKREF
@@ -2091,14 +2097,14 @@ bool QRegExpEngine::matchHere()
2091 If minimal matching is enabled, we might have some sleepers left. 2097 If minimal matching is enabled, we might have some sleepers left.
2092 */ 2098 */
2093 while ( !mmSleeping.isEmpty() ) { 2099 while ( !mmSleeping.isEmpty() ) {
2094 zzZ = mmSleeping.take( *QIntDictIterator<int>(mmSleeping) ); 2100 zzZ = mmSleeping.take( *QIntDictIterator<int>(mmSleeping) );
2095 delete[] zzZ; 2101 delete[] zzZ;
2096 } 2102 }
2097#endif 2103#endif
2098 2104
2099 match = ( mmMatchedLen >= 0 ); 2105 match = ( mmMatchedLen >= 0 );
2100 if ( !match ) 2106 if ( !match )
2101 mmMatchedLen = i - 1; 2107 mmMatchedLen = i - 1;
2102 return match; 2108 return match;
2103} 2109}
2104 2110
@@ -2113,7 +2119,7 @@ QRegExpEngine::CharClass::CharClass()
2113} 2119}
2114 2120
2115QRegExpEngine::CharClass& QRegExpEngine::CharClass::operator=( 2121QRegExpEngine::CharClass& QRegExpEngine::CharClass::operator=(
2116 const CharClass& cc ) 2122 const CharClass& cc )
2117{ 2123{
2118 c = cc.c; 2124 c = cc.c;
2119 r = cc.r.copy(); 2125 r = cc.r.copy();
@@ -2150,7 +2156,7 @@ void QRegExpEngine::CharClass::addCategories( int cats )
2150void QRegExpEngine::CharClass::addRange( ushort from, ushort to ) 2156void QRegExpEngine::CharClass::addRange( ushort from, ushort to )
2151{ 2157{
2152 if ( from > to ) 2158 if ( from > to )
2153 qSwap( from, to ); 2159 qSwap( from, to );
2154 int n = r.size(); 2160 int n = r.size();
2155 r.resize( n + 1 ); 2161 r.resize( n + 1 );
2156 r[n].from = from; 2162 r[n].from = from;
@@ -2160,18 +2166,18 @@ void QRegExpEngine::CharClass::addRange( ushort from, ushort to )
2160 int i; 2166 int i;
2161 2167
2162 if ( to - from < NumBadChars ) { 2168 if ( to - from < NumBadChars ) {
2163 occ1.detach(); 2169 occ1.detach();
2164 if ( from % NumBadChars <= to % NumBadChars ) { 2170 if ( from % NumBadChars <= to % NumBadChars ) {
2165 for ( i = from % NumBadChars; i <= to % NumBadChars; i++ ) 2171 for ( i = from % NumBadChars; i <= to % NumBadChars; i++ )
2166 occ1[i] = 0; 2172 occ1[i] = 0;
2167 } else {
2168 for ( i = 0; i <= to % NumBadChars; i++ )
2169 occ1[i] = 0;
2170 for ( i = from % NumBadChars; i < NumBadChars; i++ )
2171 occ1[i] = 0;
2172 }
2173 } else { 2173 } else {
2174 occ1 = *firstOccurrenceAtZero; 2174 for ( i = 0; i <= to % NumBadChars; i++ )
2175 occ1[i] = 0;
2176 for ( i = from % NumBadChars; i < NumBadChars; i++ )
2177 occ1[i] = 0;
2178 }
2179 } else {
2180 occ1 = *firstOccurrenceAtZero;
2175 } 2181 }
2176#endif 2182#endif
2177} 2183}
@@ -2180,14 +2186,14 @@ bool QRegExpEngine::CharClass::in( QChar ch ) const
2180{ 2186{
2181#ifndef QT_NO_REGEXP_OPTIM 2187#ifndef QT_NO_REGEXP_OPTIM
2182 if ( occ1[BadChar(ch)] == NoOccurrence ) 2188 if ( occ1[BadChar(ch)] == NoOccurrence )
2183 return n; 2189 return n;
2184#endif 2190#endif
2185 2191
2186 if ( c != 0 && (c & (1 << (int) ch.category())) != 0 ) 2192 if ( c != 0 && (c & (1 << (int) ch.category())) != 0 )
2187 return !n; 2193 return !n;
2188 for ( int i = 0; i < (int) r.size(); i++ ) { 2194 for ( int i = 0; i < (int) r.size(); i++ ) {
2189 if ( ch.unicode() >= r[i].from && ch.unicode() <= r[i].to ) 2195 if ( ch.unicode() >= r[i].from && ch.unicode() <= r[i].to )
2190 return !n; 2196 return !n;
2191 } 2197 }
2192 return n; 2198 return n;
2193} 2199}
@@ -2196,13 +2202,13 @@ bool QRegExpEngine::CharClass::in( QChar ch ) const
2196void QRegExpEngine::CharClass::dump() const 2202void QRegExpEngine::CharClass::dump() const
2197{ 2203{
2198 int i; 2204 int i;
2199 qDebug( " %stive character class", n ? "nega" : "posi" ); 2205 odebug << " " << (n ? "nega" : "posi") << "tive character class" << oendl;
2200#ifndef QT_NO_REGEXP_CCLASS 2206#ifndef QT_NO_REGEXP_CCLASS
2201 if ( c != 0 ) 2207 if ( c != 0 )
2202 qDebug( " categories 0x%.8x", c ); 2208 odebug << QString().sprintf(" categories 0x%.8x", c ) << oendl;
2203#endif 2209#endif
2204 for ( i = 0; i < (int) r.size(); i++ ) 2210 for ( i = 0; i < (int) r.size(); i++ )
2205 qDebug( " 0x%.4x through 0x%.4x", r[i].from, r[i].to ); 2211 odebug << QString().sprintf(" 0x%.4x through 0x%.4x", r[i].from, r[i].to ) << oendl;
2206} 2212}
2207#endif 2213#endif
2208#endif 2214#endif
@@ -2275,7 +2281,7 @@ void QRegExpEngine::Box::set( int bref )
2275 rs = ls; 2281 rs = ls;
2276 rs.detach(); 2282 rs.detach();
2277 if ( bref >= 1 && bref <= MaxBackRefs ) 2283 if ( bref >= 1 && bref <= MaxBackRefs )
2278 skipanchors = Anchor_BackRef0Empty << bref; 2284 skipanchors = Anchor_BackRef0Empty << bref;
2279#ifndef QT_NO_REGEXP_OPTIM 2285#ifndef QT_NO_REGEXP_OPTIM
2280 maxl = InftyLen; 2286 maxl = InftyLen;
2281#endif 2287#endif
@@ -2288,69 +2294,69 @@ void QRegExpEngine::Box::cat( const Box& b )
2288 eng->addCatTransitions( rs, b.ls ); 2294 eng->addCatTransitions( rs, b.ls );
2289 addAnchorsToEngine( b ); 2295 addAnchorsToEngine( b );
2290 if ( minl == 0 ) { 2296 if ( minl == 0 ) {
2291 mergeInto( &lanchors, b.lanchors ); 2297 mergeInto( &lanchors, b.lanchors );
2292 if ( skipanchors != 0 ) { 2298 if ( skipanchors != 0 ) {
2293 for ( int i = 0; i < (int) b.ls.size(); i++ ) { 2299 for ( int i = 0; i < (int) b.ls.size(); i++ ) {
2294 int a = eng->anchorConcatenation( at(lanchors, b.ls[i]), 2300 int a = eng->anchorConcatenation( at(lanchors, b.ls[i]),
2295 skipanchors ); 2301 skipanchors );
2296 lanchors.insert( b.ls[i], a ); 2302 lanchors.insert( b.ls[i], a );
2297 } 2303 }
2298 } 2304 }
2299 mergeInto( &ls, b.ls ); 2305 mergeInto( &ls, b.ls );
2300 } 2306 }
2301 if ( b.minl == 0 ) { 2307 if ( b.minl == 0 ) {
2302 mergeInto( &ranchors, b.ranchors ); 2308 mergeInto( &ranchors, b.ranchors );
2303 if ( b.skipanchors != 0 ) { 2309 if ( b.skipanchors != 0 ) {
2304 for ( int i = 0; i < (int) rs.size(); i++ ) { 2310 for ( int i = 0; i < (int) rs.size(); i++ ) {
2305 int a = eng->anchorConcatenation( at(ranchors, rs[i]), 2311 int a = eng->anchorConcatenation( at(ranchors, rs[i]),
2306 b.skipanchors ); 2312 b.skipanchors );
2307 ranchors.insert( rs[i], a ); 2313 ranchors.insert( rs[i], a );
2308 } 2314 }
2309 } 2315 }
2310 mergeInto( &rs, b.rs ); 2316 mergeInto( &rs, b.rs );
2311 } else { 2317 } else {
2312 ranchors = b.ranchors; 2318 ranchors = b.ranchors;
2313 rs = b.rs; 2319 rs = b.rs;
2314 } 2320 }
2315 2321
2316#ifndef QT_NO_REGEXP_OPTIM 2322#ifndef QT_NO_REGEXP_OPTIM
2317 if ( maxl != InftyLen ) { 2323 if ( maxl != InftyLen ) {
2318 if ( rightStr.length() + b.leftStr.length() > 2324 if ( rightStr.length() + b.leftStr.length() >
2319 QMAX(str.length(), b.str.length()) ) { 2325 QMAX(str.length(), b.str.length()) ) {
2320 earlyStart = minl - rightStr.length(); 2326 earlyStart = minl - rightStr.length();
2321 lateStart = maxl - rightStr.length(); 2327 lateStart = maxl - rightStr.length();
2322 str = rightStr + b.leftStr; 2328 str = rightStr + b.leftStr;
2323 } else if ( b.str.length() > str.length() ) { 2329 } else if ( b.str.length() > str.length() ) {
2324 earlyStart = minl + b.earlyStart; 2330 earlyStart = minl + b.earlyStart;
2325 lateStart = maxl + b.lateStart; 2331 lateStart = maxl + b.lateStart;
2326 str = b.str; 2332 str = b.str;
2327 } 2333 }
2328 } 2334 }
2329 2335
2330 if ( (int) leftStr.length() == maxl ) 2336 if ( (int) leftStr.length() == maxl )
2331 leftStr += b.leftStr; 2337 leftStr += b.leftStr;
2332 if ( (int) b.rightStr.length() == b.maxl ) 2338 if ( (int) b.rightStr.length() == b.maxl )
2333 rightStr += b.rightStr; 2339 rightStr += b.rightStr;
2334 else 2340 else
2335 rightStr = b.rightStr; 2341 rightStr = b.rightStr;
2336 2342
2337 if ( maxl == InftyLen || b.maxl == InftyLen ) 2343 if ( maxl == InftyLen || b.maxl == InftyLen )
2338 maxl = InftyLen; 2344 maxl = InftyLen;
2339 else 2345 else
2340 maxl += b.maxl; 2346 maxl += b.maxl;
2341 2347
2342 occ1.detach(); 2348 occ1.detach();
2343 for ( int i = 0; i < NumBadChars; i++ ) { 2349 for ( int i = 0; i < NumBadChars; i++ ) {
2344 if ( b.occ1[i] != NoOccurrence && minl + b.occ1[i] < occ1[i] ) 2350 if ( b.occ1[i] != NoOccurrence && minl + b.occ1[i] < occ1[i] )
2345 occ1[i] = minl + b.occ1[i]; 2351 occ1[i] = minl + b.occ1[i];
2346 } 2352 }
2347#endif 2353#endif
2348 2354
2349 minl += b.minl; 2355 minl += b.minl;
2350 if ( minl == 0 ) 2356 if ( minl == 0 )
2351 skipanchors = eng->anchorConcatenation( skipanchors, b.skipanchors ); 2357 skipanchors = eng->anchorConcatenation( skipanchors, b.skipanchors );
2352 else 2358 else
2353 skipanchors = 0; 2359 skipanchors = 0;
2354} 2360}
2355 2361
2356void QRegExpEngine::Box::orx( const Box& b ) 2362void QRegExpEngine::Box::orx( const Box& b )
@@ -2364,8 +2370,8 @@ void QRegExpEngine::Box::orx( const Box& b )
2364#ifndef QT_NO_REGEXP_OPTIM 2370#ifndef QT_NO_REGEXP_OPTIM
2365 occ1.detach(); 2371 occ1.detach();
2366 for ( int i = 0; i < NumBadChars; i++ ) { 2372 for ( int i = 0; i < NumBadChars; i++ ) {
2367 if ( occ1[i] > b.occ1[i] ) 2373 if ( occ1[i] > b.occ1[i] )
2368 occ1[i] = b.occ1[i]; 2374 occ1[i] = b.occ1[i];
2369 } 2375 }
2370 earlyStart = 0; 2376 earlyStart = 0;
2371 lateStart = 0; 2377 lateStart = 0;
@@ -2373,10 +2379,10 @@ void QRegExpEngine::Box::orx( const Box& b )
2373 leftStr = QString::null; 2379 leftStr = QString::null;
2374 rightStr = QString::null; 2380 rightStr = QString::null;
2375 if ( b.maxl > maxl ) 2381 if ( b.maxl > maxl )
2376 maxl = b.maxl; 2382 maxl = b.maxl;
2377#endif 2383#endif
2378 if ( b.minl < minl ) 2384 if ( b.minl < minl )
2379 minl = b.minl; 2385 minl = b.minl;
2380} 2386}
2381 2387
2382void QRegExpEngine::Box::plus( int atom ) 2388void QRegExpEngine::Box::plus( int atom )
@@ -2409,12 +2415,12 @@ void QRegExpEngine::Box::opt()
2409void QRegExpEngine::Box::catAnchor( int a ) 2415void QRegExpEngine::Box::catAnchor( int a )
2410{ 2416{
2411 if ( a != 0 ) { 2417 if ( a != 0 ) {
2412 for ( int i = 0; i < (int) rs.size(); i++ ) { 2418 for ( int i = 0; i < (int) rs.size(); i++ ) {
2413 a = eng->anchorConcatenation( at(ranchors, rs[i]), a ); 2419 a = eng->anchorConcatenation( at(ranchors, rs[i]), a );
2414 ranchors.insert( rs[i], a ); 2420 ranchors.insert( rs[i], a );
2415 } 2421 }
2416 if ( minl == 0 ) 2422 if ( minl == 0 )
2417 skipanchors = eng->anchorConcatenation( skipanchors, a ); 2423 skipanchors = eng->anchorConcatenation( skipanchors, a );
2418 } 2424 }
2419} 2425}
2420 2426
@@ -2433,8 +2439,8 @@ void QRegExpEngine::Box::setupHeuristics()
2433 (112|1)34. 2439 (112|1)34.
2434 */ 2440 */
2435 for ( int i = 0; i < NumBadChars; i++ ) { 2441 for ( int i = 0; i < NumBadChars; i++ ) {
2436 if ( occ1[i] != NoOccurrence && occ1[i] >= minl ) 2442 if ( occ1[i] != NoOccurrence && occ1[i] >= minl )
2437 occ1[i] = minl; 2443 occ1[i] = minl;
2438 } 2444 }
2439 eng->setupBadCharHeuristic( minl, occ1 ); 2445 eng->setupBadCharHeuristic( minl, occ1 );
2440 2446
@@ -2446,33 +2452,33 @@ void QRegExpEngine::Box::setupHeuristics()
2446void QRegExpEngine::Box::dump() const 2452void QRegExpEngine::Box::dump() const
2447{ 2453{
2448 int i; 2454 int i;
2449 qDebug( "Box of at least %d character%s", minl, minl == 1 ? "" : "s" ); 2455 odebug << "Box of at least " << minl << " character" << (minl == 1 ? "" : "s") << oendl;
2450 qDebug( " Left states:" ); 2456 odebug << " Left states:" << oendl;
2451 for ( i = 0; i < (int) ls.size(); i++ ) { 2457 for ( i = 0; i < (int) ls.size(); i++ ) {
2452 if ( at(lanchors, ls[i]) == 0 ) 2458 if ( at(lanchors, ls[i]) == 0 )
2453 qDebug( " %d", ls[i] ); 2459 odebug << " " << ls[i] << oendl;
2454 else 2460 else
2455 qDebug( " %d [anchors 0x%.8x]", ls[i], lanchors[ls[i]] ); 2461 odebug << " " << ls[i] << QString().sprintf(" [anchors 0x%.8x]", lanchors[ls[i]]) << oendl;
2456 } 2462 }
2457 qDebug( " Right states:" ); 2463 odebug << " Right states:" << oendl;
2458 for ( i = 0; i < (int) rs.size(); i++ ) { 2464 for ( i = 0; i < (int) rs.size(); i++ ) {
2459 if ( at(ranchors, ls[i]) == 0 ) 2465 if ( at(ranchors, ls[i]) == 0 )
2460 qDebug( " %d", rs[i] ); 2466 odebug << " " << rs[i] << oendl;
2461 else 2467 else
2462 qDebug( " %d [anchors 0x%.8x]", rs[i], ranchors[rs[i]] ); 2468 odebug << " " << rs[i] << QString().sprintf(" [anchors 0x%.8x]", ranchors[rs[i]]) << oendl;
2463 } 2469 }
2464 qDebug( " Skip anchors: 0x%.8x", skipanchors ); 2470 odebug << QString().sprintf(" Skip anchors: 0x%.8x", skipanchors) << oendl;
2465} 2471}
2466#endif 2472#endif
2467 2473
2468void QRegExpEngine::Box::addAnchorsToEngine( const Box& to ) const 2474void QRegExpEngine::Box::addAnchorsToEngine( const Box& to ) const
2469{ 2475{
2470 for ( int i = 0; i < (int) to.ls.size(); i++ ) { 2476 for ( int i = 0; i < (int) to.ls.size(); i++ ) {
2471 for ( int j = 0; j < (int) rs.size(); j++ ) { 2477 for ( int j = 0; j < (int) rs.size(); j++ ) {
2472 int a = eng->anchorConcatenation( at(ranchors, rs[j]), 2478 int a = eng->anchorConcatenation( at(ranchors, rs[j]),
2473 at(to.lanchors, to.ls[i]) ); 2479 at(to.lanchors, to.ls[i]) );
2474 eng->addAnchors( rs[j], to.ls[i], a ); 2480 eng->addAnchors( rs[j], to.ls[i], a );
2475 } 2481 }
2476 } 2482 }
2477} 2483}
2478 2484
@@ -2493,102 +2499,102 @@ int QRegExpEngine::getEscape()
2493 int prevCh = yyCh; 2499 int prevCh = yyCh;
2494 2500
2495 if ( prevCh == EOS ) { 2501 if ( prevCh == EOS ) {
2496 yyError = TRUE; 2502 yyError = TRUE;
2497 return Tok_Char | '\\'; 2503 return Tok_Char | '\\';
2498 } 2504 }
2499 yyCh = getChar(); 2505 yyCh = getChar();
2500#ifndef QT_NO_REGEXP_ESCAPE 2506#ifndef QT_NO_REGEXP_ESCAPE
2501 if ( (prevCh & ~0xff) == 0 ) { 2507 if ( (prevCh & ~0xff) == 0 ) {
2502 const char *p = strchr( tab, prevCh ); 2508 const char *p = strchr( tab, prevCh );
2503 if ( p != 0 ) 2509 if ( p != 0 )
2504 return Tok_Char | backTab[p - tab]; 2510 return Tok_Char | backTab[p - tab];
2505 } 2511 }
2506#endif 2512#endif
2507 2513
2508 switch ( prevCh ) { 2514 switch ( prevCh ) {
2509#ifndef QT_NO_REGEXP_ESCAPE 2515#ifndef QT_NO_REGEXP_ESCAPE
2510 case '0': 2516 case '0':
2511 val = 0; 2517 val = 0;
2512 for ( i = 0; i < 3; i++ ) { 2518 for ( i = 0; i < 3; i++ ) {
2513 if ( yyCh >= '0' && yyCh <= '7' ) 2519 if ( yyCh >= '0' && yyCh <= '7' )
2514 val = ( val << 3 ) | ( yyCh - '0' ); 2520 val = ( val << 3 ) | ( yyCh - '0' );
2515 else 2521 else
2516 break; 2522 break;
2517 yyCh = getChar(); 2523 yyCh = getChar();
2518 } 2524 }
2519 if ( (val & ~0377) != 0 ) 2525 if ( (val & ~0377) != 0 )
2520 yyError = TRUE; 2526 yyError = TRUE;
2521 return Tok_Char | val; 2527 return Tok_Char | val;
2522#endif 2528#endif
2523#ifndef QT_NO_REGEXP_ESCAPE 2529#ifndef QT_NO_REGEXP_ESCAPE
2524 case 'B': 2530 case 'B':
2525 return Tok_NonWord; 2531 return Tok_NonWord;
2526#endif 2532#endif
2527#ifndef QT_NO_REGEXP_CCLASS 2533#ifndef QT_NO_REGEXP_CCLASS
2528 case 'D': 2534 case 'D':
2529 // see QChar::isDigit() 2535 // see QChar::isDigit()
2530 yyCharClass->addCategories( 0x7fffffef ); 2536 yyCharClass->addCategories( 0x7fffffef );
2531 return Tok_CharClass; 2537 return Tok_CharClass;
2532 case 'S': 2538 case 'S':
2533 // see QChar::isSpace() 2539 // see QChar::isSpace()
2534 yyCharClass->addCategories( 0x7ffff87f ); 2540 yyCharClass->addCategories( 0x7ffff87f );
2535 yyCharClass->addRange( 0x0000, 0x0008 ); 2541 yyCharClass->addRange( 0x0000, 0x0008 );
2536 yyCharClass->addRange( 0x000e, 0x001f ); 2542 yyCharClass->addRange( 0x000e, 0x001f );
2537 yyCharClass->addRange( 0x007f, 0x009f ); 2543 yyCharClass->addRange( 0x007f, 0x009f );
2538 return Tok_CharClass; 2544 return Tok_CharClass;
2539 case 'W': 2545 case 'W':
2540 // see QChar::isLetterOrNumber() 2546 // see QChar::isLetterOrNumber()
2541 yyCharClass->addCategories( 0x7ff07f8f ); 2547 yyCharClass->addCategories( 0x7ff07f8f );
2542 return Tok_CharClass; 2548 return Tok_CharClass;
2543#endif 2549#endif
2544#ifndef QT_NO_REGEXP_ESCAPE 2550#ifndef QT_NO_REGEXP_ESCAPE
2545 case 'b': 2551 case 'b':
2546 return Tok_Word; 2552 return Tok_Word;
2547#endif 2553#endif
2548#ifndef QT_NO_REGEXP_CCLASS 2554#ifndef QT_NO_REGEXP_CCLASS
2549 case 'd': 2555 case 'd':
2550 // see QChar::isDigit() 2556 // see QChar::isDigit()
2551 yyCharClass->addCategories( 0x00000010 ); 2557 yyCharClass->addCategories( 0x00000010 );
2552 return Tok_CharClass; 2558 return Tok_CharClass;
2553 case 's': 2559 case 's':
2554 // see QChar::isSpace() 2560 // see QChar::isSpace()
2555 yyCharClass->addCategories( 0x00000380 ); 2561 yyCharClass->addCategories( 0x00000380 );
2556 yyCharClass->addRange( 0x0009, 0x000d ); 2562 yyCharClass->addRange( 0x0009, 0x000d );
2557 return Tok_CharClass; 2563 return Tok_CharClass;
2558 case 'w': 2564 case 'w':
2559 // see QChar::isLetterOrNumber() 2565 // see QChar::isLetterOrNumber()
2560 yyCharClass->addCategories( 0x000f8070 ); 2566 yyCharClass->addCategories( 0x000f8070 );
2561 return Tok_CharClass; 2567 return Tok_CharClass;
2562#endif 2568#endif
2563#ifndef QT_NO_REGEXP_ESCAPE 2569#ifndef QT_NO_REGEXP_ESCAPE
2564 case 'x': 2570 case 'x':
2565 val = 0; 2571 val = 0;
2566 for ( i = 0; i < 4; i++ ) { 2572 for ( i = 0; i < 4; i++ ) {
2567 low = QChar( yyCh ).lower(); 2573 low = QChar( yyCh ).lower();
2568 if ( low >= '0' && low <= '9' ) 2574 if ( low >= '0' && low <= '9' )
2569 val = ( val << 4 ) | ( low - '0' ); 2575 val = ( val << 4 ) | ( low - '0' );
2570 else if ( low >= 'a' && low <= 'f' ) 2576 else if ( low >= 'a' && low <= 'f' )
2571 val = ( val << 4 ) | ( low - 'a' + 10 ); 2577 val = ( val << 4 ) | ( low - 'a' + 10 );
2572 else 2578 else
2573 break; 2579 break;
2574 yyCh = getChar(); 2580 yyCh = getChar();
2575 } 2581 }
2576 return Tok_Char | val; 2582 return Tok_Char | val;
2577#endif 2583#endif
2578 default: 2584 default:
2579 if ( prevCh >= '1' && prevCh <= '9' ) { 2585 if ( prevCh >= '1' && prevCh <= '9' ) {
2580#ifndef QT_NO_REGEXP_BACKREF 2586#ifndef QT_NO_REGEXP_BACKREF
2581 val = prevCh - '0'; 2587 val = prevCh - '0';
2582 while ( yyCh >= '0' && yyCh <= '9' ) { 2588 while ( yyCh >= '0' && yyCh <= '9' ) {
2583 val = ( val *= 10 ) | ( yyCh - '0' ); 2589 val = ( val *= 10 ) | ( yyCh - '0' );
2584 yyCh = getChar(); 2590 yyCh = getChar();
2585 } 2591 }
2586 return Tok_BackRef | val; 2592 return Tok_BackRef | val;
2587#else 2593#else
2588 yyError = TRUE; 2594 yyError = TRUE;
2589#endif 2595#endif
2590 } 2596 }
2591 return Tok_Char | prevCh; 2597 return Tok_Char | prevCh;
2592 } 2598 }
2593} 2599}
2594 2600
@@ -2596,18 +2602,18 @@ int QRegExpEngine::getEscape()
2596int QRegExpEngine::getRep( int def ) 2602int QRegExpEngine::getRep( int def )
2597{ 2603{
2598 if ( yyCh >= '0' && yyCh <= '9' ) { 2604 if ( yyCh >= '0' && yyCh <= '9' ) {
2599 int rep = 0; 2605 int rep = 0;
2600 do { 2606 do {
2601 rep = 10 * rep + yyCh - '0'; 2607 rep = 10 * rep + yyCh - '0';
2602 if ( rep >= InftyRep ) { 2608 if ( rep >= InftyRep ) {
2603 yyError = TRUE; 2609 yyError = TRUE;
2604 rep = def; 2610 rep = def;
2605 } 2611 }
2606 yyCh = getChar(); 2612 yyCh = getChar();
2607 } while ( yyCh >= '0' && yyCh <= '9' ); 2613 } while ( yyCh >= '0' && yyCh <= '9' );
2608 return rep; 2614 return rep;
2609 } else { 2615 } else {
2610 return def; 2616 return def;
2611 } 2617 }
2612} 2618}
2613#endif 2619#endif
@@ -2616,8 +2622,8 @@ int QRegExpEngine::getRep( int def )
2616void QRegExpEngine::skipChars( int n ) 2622void QRegExpEngine::skipChars( int n )
2617{ 2623{
2618 if ( n > 0 ) { 2624 if ( n > 0 ) {
2619 yyPos += n - 1; 2625 yyPos += n - 1;
2620 yyCh = getChar(); 2626 yyCh = getChar();
2621 } 2627 }
2622} 2628}
2623#endif 2629#endif
@@ -2654,141 +2660,141 @@ int QRegExpEngine::getToken()
2654 yyCh = getChar(); 2660 yyCh = getChar();
2655 switch ( prevCh ) { 2661 switch ( prevCh ) {
2656 case EOS: 2662 case EOS:
2657 yyPos0 = yyPos; 2663 yyPos0 = yyPos;
2658 return Tok_Eos; 2664 return Tok_Eos;
2659 case '$': 2665 case '$':
2660 return Tok_Dollar; 2666 return Tok_Dollar;
2661 case '(': 2667 case '(':
2662 if ( yyCh == '?' ) { 2668 if ( yyCh == '?' ) {
2663 prevCh = getChar(); 2669 prevCh = getChar();
2664 yyCh = getChar(); 2670 yyCh = getChar();
2665 switch ( prevCh ) { 2671 switch ( prevCh ) {
2666#ifndef QT_NO_REGEXP_LOOKAHEAD 2672#ifndef QT_NO_REGEXP_LOOKAHEAD
2667 case '!': 2673 case '!':
2668 return Tok_NegLookahead; 2674 return Tok_NegLookahead;
2669 case '=': 2675 case '=':
2670 return Tok_PosLookahead; 2676 return Tok_PosLookahead;
2671#endif 2677#endif
2672 case ':': 2678 case ':':
2673 return Tok_MagicLeftParen; 2679 return Tok_MagicLeftParen;
2674 default: 2680 default:
2675 yyError = TRUE; 2681 yyError = TRUE;
2676 return Tok_MagicLeftParen; 2682 return Tok_MagicLeftParen;
2677 } 2683 }
2678 } else { 2684 } else {
2679 return Tok_LeftParen; 2685 return Tok_LeftParen;
2680 } 2686 }
2681 case ')': 2687 case ')':
2682 return Tok_RightParen; 2688 return Tok_RightParen;
2683 case '*': 2689 case '*':
2684 yyMinRep = 0; 2690 yyMinRep = 0;
2685 yyMaxRep = InftyRep; 2691 yyMaxRep = InftyRep;
2686 return Tok_Quantifier; 2692 return Tok_Quantifier;
2687 case '+': 2693 case '+':
2688 yyMinRep = 1; 2694 yyMinRep = 1;
2689 yyMaxRep = InftyRep; 2695 yyMaxRep = InftyRep;
2690 return Tok_Quantifier; 2696 return Tok_Quantifier;
2691 case '.': 2697 case '.':
2692#ifndef QT_NO_REGEXP_CCLASS 2698#ifndef QT_NO_REGEXP_CCLASS
2693 yyCharClass->setNegative( TRUE ); 2699 yyCharClass->setNegative( TRUE );
2694#endif 2700#endif
2695 return Tok_CharClass; 2701 return Tok_CharClass;
2696 case '?': 2702 case '?':
2697 yyMinRep = 0; 2703 yyMinRep = 0;
2698 yyMaxRep = 1; 2704 yyMaxRep = 1;
2699 return Tok_Quantifier; 2705 return Tok_Quantifier;
2700 case '[': 2706 case '[':
2701#ifndef QT_NO_REGEXP_CCLASS 2707#ifndef QT_NO_REGEXP_CCLASS
2702 if ( yyCh == '^' ) { 2708 if ( yyCh == '^' ) {
2703 yyCharClass->setNegative( TRUE ); 2709 yyCharClass->setNegative( TRUE );
2704 yyCh = getChar(); 2710 yyCh = getChar();
2705 } 2711 }
2706 charPending = FALSE; 2712 charPending = FALSE;
2707 rangePending = FALSE; 2713 rangePending = FALSE;
2708 do { 2714 do {
2709 if ( yyCh == '-' && charPending && !rangePending ) { 2715 if ( yyCh == '-' && charPending && !rangePending ) {
2710 rangePending = TRUE; 2716 rangePending = TRUE;
2711 yyCh = getChar(); 2717 yyCh = getChar();
2712 } else { 2718 } else {
2713 if ( charPending && !rangePending ) { 2719 if ( charPending && !rangePending ) {
2714 yyCharClass->addSingleton( pendingCh ); 2720 yyCharClass->addSingleton( pendingCh );
2715 charPending = FALSE; 2721 charPending = FALSE;
2716 } 2722 }
2717 if ( yyCh == '\\' ) { 2723 if ( yyCh == '\\' ) {
2718 yyCh = getChar(); 2724 yyCh = getChar();
2719 tok = getEscape(); 2725 tok = getEscape();
2720 if ( tok == Tok_Word ) 2726 if ( tok == Tok_Word )
2721 tok = '\b'; 2727 tok = '\b';
2722 } else { 2728 } else {
2723 tok = Tok_Char | yyCh; 2729 tok = Tok_Char | yyCh;
2724 yyCh = getChar(); 2730 yyCh = getChar();
2725 } 2731 }
2726 if ( tok == Tok_CharClass ) { 2732 if ( tok == Tok_CharClass ) {
2727 if ( rangePending ) { 2733 if ( rangePending ) {
2728 yyCharClass->addSingleton( '-' ); 2734 yyCharClass->addSingleton( '-' );
2729 yyCharClass->addSingleton( pendingCh ); 2735 yyCharClass->addSingleton( pendingCh );
2730 charPending = FALSE; 2736 charPending = FALSE;
2731 rangePending = FALSE; 2737 rangePending = FALSE;
2732 } 2738 }
2733 } else if ( (tok & Tok_Char) != 0 ) { 2739 } else if ( (tok & Tok_Char) != 0 ) {
2734 if ( rangePending ) { 2740 if ( rangePending ) {
2735 yyCharClass->addRange( pendingCh, tok ^ Tok_Char ); 2741 yyCharClass->addRange( pendingCh, tok ^ Tok_Char );
2736 charPending = FALSE; 2742 charPending = FALSE;
2737 rangePending = FALSE; 2743 rangePending = FALSE;
2738 } else { 2744 } else {
2739 pendingCh = tok ^ Tok_Char; 2745 pendingCh = tok ^ Tok_Char;
2740 charPending = TRUE; 2746 charPending = TRUE;
2741 } 2747 }
2742 } else { 2748 } else {
2743 yyError = TRUE; 2749 yyError = TRUE;
2744 } 2750 }
2745 } 2751 }
2746 } while ( yyCh != ']' && yyCh != EOS ); 2752 } while ( yyCh != ']' && yyCh != EOS );
2747 if ( rangePending ) 2753 if ( rangePending )
2748 yyCharClass->addSingleton( '-' ); 2754 yyCharClass->addSingleton( '-' );
2749 if ( charPending ) 2755 if ( charPending )
2750 yyCharClass->addSingleton( pendingCh ); 2756 yyCharClass->addSingleton( pendingCh );
2751 if ( yyCh == EOS ) 2757 if ( yyCh == EOS )
2752 yyError = TRUE; 2758 yyError = TRUE;
2753 else 2759 else
2754 yyCh = getChar(); 2760 yyCh = getChar();
2755 return Tok_CharClass; 2761 return Tok_CharClass;
2756#else 2762#else
2757 yyError = TRUE; 2763 yyError = TRUE;
2758 return Tok_Char | '['; 2764 return Tok_Char | '[';
2759#endif 2765#endif
2760 case '\\': 2766 case '\\':
2761 return getEscape(); 2767 return getEscape();
2762 case ']': 2768 case ']':
2763 yyError = TRUE; 2769 yyError = TRUE;
2764 return Tok_Char | ']'; 2770 return Tok_Char | ']';
2765 case '^': 2771 case '^':
2766 return Tok_Caret; 2772 return Tok_Caret;
2767#ifndef QT_NO_REGEXP_INTERVAL 2773#ifndef QT_NO_REGEXP_INTERVAL
2768 case '{': 2774 case '{':
2769 yyMinRep = getRep( 0 ); 2775 yyMinRep = getRep( 0 );
2770 yyMaxRep = yyMinRep; 2776 yyMaxRep = yyMinRep;
2771 if ( yyCh == ',' ) { 2777 if ( yyCh == ',' ) {
2772 yyCh = getChar(); 2778 yyCh = getChar();
2773 yyMaxRep = getRep( InftyRep ); 2779 yyMaxRep = getRep( InftyRep );
2774 } 2780 }
2775 if ( yyMaxRep < yyMinRep ) 2781 if ( yyMaxRep < yyMinRep )
2776 qSwap( yyMinRep, yyMaxRep ); 2782 qSwap( yyMinRep, yyMaxRep );
2777 if ( yyCh != '}' ) 2783 if ( yyCh != '}' )
2778 yyError = TRUE; 2784 yyError = TRUE;
2779 yyCh = getChar(); 2785 yyCh = getChar();
2780 return Tok_Quantifier; 2786 return Tok_Quantifier;
2781#else 2787#else
2782 yyError = TRUE; 2788 yyError = TRUE;
2783 return Tok_Char | '{'; 2789 return Tok_Char | '{';
2784#endif 2790#endif
2785 case '|': 2791 case '|':
2786 return Tok_Bar; 2792 return Tok_Bar;
2787 case '}': 2793 case '}':
2788 yyError = TRUE; 2794 yyError = TRUE;
2789 return Tok_Char | '}'; 2795 return Tok_Char | '}';
2790 default: 2796 default:
2791 return Tok_Char | prevCh; 2797 return Tok_Char | prevCh;
2792 } 2798 }
2793} 2799}
2794 2800
@@ -2828,7 +2834,7 @@ int QRegExpEngine::parse( const QChar *pattern, int len )
2828 realncap = ncap; 2834 realncap = ncap;
2829#ifndef QT_NO_REGEXP_BACKREF 2835#ifndef QT_NO_REGEXP_BACKREF
2830 if ( nbrefs > ncap ) 2836 if ( nbrefs > ncap )
2831 ncap = nbrefs; 2837 ncap = nbrefs;
2832#endif 2838#endif
2833 2839
2834 mmCaptured.resize( 2 + 2 * realncap ); 2840 mmCaptured.resize( 2 + 2 * realncap );
@@ -2863,24 +2869,24 @@ int QRegExpEngine::parse( const QChar *pattern, int len )
2863 mmSlideTab = mmTempCapBegin + 4 * ncap; 2869 mmSlideTab = mmTempCapBegin + 4 * ncap;
2864 2870
2865 if ( yyError ) 2871 if ( yyError )
2866 return -1; 2872 return -1;
2867 2873
2868#ifndef QT_NO_REGEXP_OPTIM 2874#ifndef QT_NO_REGEXP_OPTIM
2869 State *sinit = s[InitialState]; 2875 State *sinit = s[InitialState];
2870 caretAnchored = ( sinit->anchors != 0 ); 2876 caretAnchored = ( sinit->anchors != 0 );
2871 if ( caretAnchored ) { 2877 if ( caretAnchored ) {
2872 QMap<int, int>& anchors = *sinit->anchors; 2878 QMap<int, int>& anchors = *sinit->anchors;
2873 QMap<int, int>::ConstIterator a; 2879 QMap<int, int>::ConstIterator a;
2874 for ( a = anchors.begin(); a != anchors.end(); ++a ) { 2880 for ( a = anchors.begin(); a != anchors.end(); ++a ) {
2875#ifndef QT_NO_REGEXP_ANCHOR_ALT 2881#ifndef QT_NO_REGEXP_ANCHOR_ALT
2876 if ( (*a & Anchor_Alternation) != 0 ) 2882 if ( (*a & Anchor_Alternation) != 0 )
2877 break; 2883 break;
2878#endif 2884#endif
2879 if ( (*a & Anchor_Caret) == 0 ) { 2885 if ( (*a & Anchor_Caret) == 0 ) {
2880 caretAnchored = FALSE; 2886 caretAnchored = FALSE;
2881 break; 2887 break;
2882 } 2888 }
2883 } 2889 }
2884 } 2890 }
2885#endif 2891#endif
2886 return yyPos0; 2892 return yyPos0;
@@ -2896,54 +2902,54 @@ void QRegExpEngine::parseAtom( Box *box )
2896 2902
2897 switch ( yyTok ) { 2903 switch ( yyTok ) {
2898 case Tok_Dollar: 2904 case Tok_Dollar:
2899 box->catAnchor( Anchor_Dollar ); 2905 box->catAnchor( Anchor_Dollar );
2900 break; 2906 break;
2901 case Tok_Caret: 2907 case Tok_Caret:
2902 box->catAnchor( Anchor_Caret ); 2908 box->catAnchor( Anchor_Caret );
2903 break; 2909 break;
2904#ifndef QT_NO_REGEXP_LOOKAHEAD 2910#ifndef QT_NO_REGEXP_LOOKAHEAD
2905 case Tok_PosLookahead: 2911 case Tok_PosLookahead:
2906 case Tok_NegLookahead: 2912 case Tok_NegLookahead:
2907 neg = ( yyTok == Tok_NegLookahead ); 2913 neg = ( yyTok == Tok_NegLookahead );
2908 eng = new QRegExpEngine( cs ); 2914 eng = new QRegExpEngine( cs );
2909 len = eng->parse( yyIn + yyPos - 1, yyLen - yyPos + 1 ); 2915 len = eng->parse( yyIn + yyPos - 1, yyLen - yyPos + 1 );
2910 if ( len >= 0 ) 2916 if ( len >= 0 )
2911 skipChars( len ); 2917 skipChars( len );
2912 else 2918 else
2913 yyError = TRUE; 2919 yyError = TRUE;
2914 box->catAnchor( addLookahead(eng, neg) ); 2920 box->catAnchor( addLookahead(eng, neg) );
2915 yyTok = getToken(); 2921 yyTok = getToken();
2916 if ( yyTok != Tok_RightParen ) 2922 if ( yyTok != Tok_RightParen )
2917 yyError = TRUE; 2923 yyError = TRUE;
2918 break; 2924 break;
2919#endif 2925#endif
2920#ifndef QT_NO_REGEXP_ESCAPE 2926#ifndef QT_NO_REGEXP_ESCAPE
2921 case Tok_Word: 2927 case Tok_Word:
2922 box->catAnchor( Anchor_Word ); 2928 box->catAnchor( Anchor_Word );
2923 break; 2929 break;
2924 case Tok_NonWord: 2930 case Tok_NonWord:
2925 box->catAnchor( Anchor_NonWord ); 2931 box->catAnchor( Anchor_NonWord );
2926 break; 2932 break;
2927#endif 2933#endif
2928 case Tok_LeftParen: 2934 case Tok_LeftParen:
2929 case Tok_MagicLeftParen: 2935 case Tok_MagicLeftParen:
2930 yyTok = getToken(); 2936 yyTok = getToken();
2931 parseExpression( box ); 2937 parseExpression( box );
2932 if ( yyTok != Tok_RightParen ) 2938 if ( yyTok != Tok_RightParen )
2933 yyError = TRUE; 2939 yyError = TRUE;
2934 break; 2940 break;
2935 case Tok_CharClass: 2941 case Tok_CharClass:
2936 box->set( *yyCharClass ); 2942 box->set( *yyCharClass );
2937 break; 2943 break;
2938 default: 2944 default:
2939 if ( (yyTok & Tok_Char) != 0 ) 2945 if ( (yyTok & Tok_Char) != 0 )
2940 box->set( QChar(yyTok ^ Tok_Char) ); 2946 box->set( QChar(yyTok ^ Tok_Char) );
2941#ifndef QT_NO_REGEXP_BACKREF 2947#ifndef QT_NO_REGEXP_BACKREF
2942 else if ( (yyTok & Tok_BackRef) != 0 ) 2948 else if ( (yyTok & Tok_BackRef) != 0 )
2943 box->set( yyTok ^ Tok_BackRef ); 2949 box->set( yyTok ^ Tok_BackRef );
2944#endif 2950#endif
2945 else 2951 else
2946 yyError = TRUE; 2952 yyError = TRUE;
2947 } 2953 }
2948 yyTok = getToken(); 2954 yyTok = getToken();
2949} 2955}
@@ -2958,8 +2964,8 @@ void QRegExpEngine::parseFactor( Box *box )
2958 2964
2959#ifndef QT_NO_REGEXP_INTERVAL 2965#ifndef QT_NO_REGEXP_INTERVAL
2960#define YYREDO() \ 2966#define YYREDO() \
2961 yyIn = in, yyPos0 = pos0, yyPos = pos, yyLen = len, yyCh = ch, \ 2967 yyIn = in, yyPos0 = pos0, yyPos = pos, yyLen = len, yyCh = ch, \
2962 *yyCharClass = charClass, yyMinRep = 0, yyMaxRep = 0, yyTok = tok 2968 *yyCharClass = charClass, yyMinRep = 0, yyMaxRep = 0, yyTok = tok
2963 2969
2964 const QChar *in = yyIn; 2970 const QChar *in = yyIn;
2965 int pos0 = yyPos0; 2971 int pos0 = yyPos0;
@@ -2968,7 +2974,7 @@ void QRegExpEngine::parseFactor( Box *box )
2968 int ch = yyCh; 2974 int ch = yyCh;
2969 CharClass charClass; 2975 CharClass charClass;
2970 if ( yyTok == Tok_CharClass ) 2976 if ( yyTok == Tok_CharClass )
2971 charClass = *yyCharClass; 2977 charClass = *yyCharClass;
2972 int tok = yyTok; 2978 int tok = yyTok;
2973 bool mayCapture = yyMayCapture; 2979 bool mayCapture = yyMayCapture;
2974#endif 2980#endif
@@ -2979,45 +2985,45 @@ void QRegExpEngine::parseFactor( Box *box )
2979#endif 2985#endif
2980 2986
2981 if ( yyTok == Tok_Quantifier ) { 2987 if ( yyTok == Tok_Quantifier ) {
2982 if ( yyMaxRep == InftyRep ) { 2988 if ( yyMaxRep == InftyRep ) {
2983 box->plus( atom ); 2989 box->plus( atom );
2984#ifndef QT_NO_REGEXP_INTERVAL 2990#ifndef QT_NO_REGEXP_INTERVAL
2985 } else if ( yyMaxRep == 0 ) { 2991 } else if ( yyMaxRep == 0 ) {
2986 box->clear(); 2992 box->clear();
2987#endif 2993#endif
2988 } 2994 }
2989 if ( yyMinRep == 0 ) 2995 if ( yyMinRep == 0 )
2990 box->opt(); 2996 box->opt();
2991 2997
2992#ifndef QT_NO_REGEXP_INTERVAL 2998#ifndef QT_NO_REGEXP_INTERVAL
2993 yyMayCapture = FALSE; 2999 yyMayCapture = FALSE;
2994 int alpha = ( yyMinRep == 0 ) ? 0 : yyMinRep - 1; 3000 int alpha = ( yyMinRep == 0 ) ? 0 : yyMinRep - 1;
2995 int beta = ( yyMaxRep == InftyRep ) ? 0 : yyMaxRep - ( alpha + 1 ); 3001 int beta = ( yyMaxRep == InftyRep ) ? 0 : yyMaxRep - ( alpha + 1 );
2996 3002
2997 Box rightBox( this ); 3003 Box rightBox( this );
2998 int i; 3004 int i;
2999 3005
3000 for ( i = 0; i < beta; i++ ) { 3006 for ( i = 0; i < beta; i++ ) {
3001 YYREDO(); 3007 YYREDO();
3002 Box leftBox( this ); 3008 Box leftBox( this );
3003 parseAtom( &leftBox ); 3009 parseAtom( &leftBox );
3004 leftBox.cat( rightBox ); 3010 leftBox.cat( rightBox );
3005 leftBox.opt(); 3011 leftBox.opt();
3006 rightBox = leftBox; 3012 rightBox = leftBox;
3007 } 3013 }
3008 for ( i = 0; i < alpha; i++ ) { 3014 for ( i = 0; i < alpha; i++ ) {
3009 YYREDO(); 3015 YYREDO();
3010 Box leftBox( this ); 3016 Box leftBox( this );
3011 parseAtom( &leftBox ); 3017 parseAtom( &leftBox );
3012 leftBox.cat( rightBox ); 3018 leftBox.cat( rightBox );
3013 rightBox = leftBox; 3019 rightBox = leftBox;
3014 } 3020 }
3015 rightBox.cat( *box ); 3021 rightBox.cat( *box );
3016 *box = rightBox; 3022 *box = rightBox;
3017#endif 3023#endif
3018 yyTok = getToken(); 3024 yyTok = getToken();
3019#ifndef QT_NO_REGEXP_INTERVAL 3025#ifndef QT_NO_REGEXP_INTERVAL
3020 yyMayCapture = mayCapture; 3026 yyMayCapture = mayCapture;
3021#endif 3027#endif
3022 } 3028 }
3023#undef YYREDO 3029#undef YYREDO
@@ -3027,12 +3033,12 @@ void QRegExpEngine::parseTerm( Box *box )
3027{ 3033{
3028#ifndef QT_NO_REGEXP_OPTIM 3034#ifndef QT_NO_REGEXP_OPTIM
3029 if ( yyTok != Tok_Eos && yyTok != Tok_RightParen && yyTok != Tok_Bar ) 3035 if ( yyTok != Tok_Eos && yyTok != Tok_RightParen && yyTok != Tok_Bar )
3030 parseFactor( box ); 3036 parseFactor( box );
3031#endif 3037#endif
3032 while ( yyTok != Tok_Eos && yyTok != Tok_RightParen && yyTok != Tok_Bar ) { 3038 while ( yyTok != Tok_Eos && yyTok != Tok_RightParen && yyTok != Tok_Bar ) {
3033 Box rightBox( this ); 3039 Box rightBox( this );
3034 parseFactor( &rightBox ); 3040 parseFactor( &rightBox );
3035 box->cat( rightBox ); 3041 box->cat( rightBox );
3036 } 3042 }
3037} 3043}
3038 3044
@@ -3040,10 +3046,10 @@ void QRegExpEngine::parseExpression( Box *box )
3040{ 3046{
3041 parseTerm( box ); 3047 parseTerm( box );
3042 while ( yyTok == Tok_Bar ) { 3048 while ( yyTok == Tok_Bar ) {
3043 Box rightBox( this ); 3049 Box rightBox( this );
3044 yyTok = getToken(); 3050 yyTok = getToken();
3045 parseTerm( &rightBox ); 3051 parseTerm( &rightBox );
3046 box->orx( rightBox ); 3052 box->orx( rightBox );
3047 } 3053 }
3048} 3054}
3049 3055
@@ -3077,13 +3083,13 @@ static QRegExpEngine *newEngine( const QString& pattern, bool caseSensitive )
3077{ 3083{
3078#ifndef QT_NO_REGEXP_OPTIM 3084#ifndef QT_NO_REGEXP_OPTIM
3079 if ( engineCache != 0 ) { 3085 if ( engineCache != 0 ) {
3080 QRegExpEngine *eng = engineCache->take( pattern ); 3086 QRegExpEngine *eng = engineCache->take( pattern );
3081 if ( eng == 0 || eng->caseSensitive() != caseSensitive ) { 3087 if ( eng == 0 || eng->caseSensitive() != caseSensitive ) {
3082 delete eng; 3088 delete eng;
3083 } else { 3089 } else {
3084 eng->ref(); 3090 eng->ref();
3085 return eng; 3091 return eng;
3086 } 3092 }
3087 } 3093 }
3088#endif 3094#endif
3089 return new QRegExpEngine( pattern, caseSensitive ); 3095 return new QRegExpEngine( pattern, caseSensitive );
@@ -3093,17 +3099,17 @@ static void derefEngine( QRegExpEngine *eng, const QString& pattern )
3093{ 3099{
3094 if ( eng != 0 && eng->deref() ) { 3100 if ( eng != 0 && eng->deref() ) {
3095#ifndef QT_NO_REGEXP_OPTIM 3101#ifndef QT_NO_REGEXP_OPTIM
3096 if ( engineCache == 0 ) { 3102 if ( engineCache == 0 ) {
3097 engineCache = new QCache<QRegExpEngine>; 3103 engineCache = new QCache<QRegExpEngine>;
3098 engineCache->setAutoDelete( TRUE ); 3104 engineCache->setAutoDelete( TRUE );
3099 } 3105 }
3100 if ( !pattern.isNull() && 3106 if ( !pattern.isNull() &&
3101 engineCache->insert(pattern, eng, 4 + pattern.length() / 4) ) 3107 engineCache->insert(pattern, eng, 4 + pattern.length() / 4) )
3102 return; 3108 return;
3103#else 3109#else
3104 Q_UNUSED( pattern ); 3110 Q_UNUSED( pattern );
3105#endif 3111#endif
3106 delete eng; 3112 delete eng;
3107 } 3113 }
3108} 3114}
3109 3115
@@ -3201,11 +3207,11 @@ QRegExp3& QRegExp3::operator=( const QRegExp3& rx )
3201bool QRegExp3::operator==( const QRegExp3& rx ) const 3207bool QRegExp3::operator==( const QRegExp3& rx ) const
3202{ 3208{
3203 return priv->pattern == rx.priv->pattern && 3209 return priv->pattern == rx.priv->pattern &&
3204 eng->caseSensitive() == rx.eng->caseSensitive() && 3210 eng->caseSensitive() == rx.eng->caseSensitive() &&
3205#ifndef QT_NO_REGEXP_WILDCARD 3211#ifndef QT_NO_REGEXP_WILDCARD
3206 priv->wc == rx.priv->wc && 3212 priv->wc == rx.priv->wc &&
3207#endif 3213#endif
3208 priv->min == rx.priv->min; 3214 priv->min == rx.priv->min;
3209} 3215}
3210 3216
3211/*! \fn bool QRegExp3::operator!=( const QRegExp& rx ) const 3217/*! \fn bool QRegExp3::operator!=( const QRegExp& rx ) const
@@ -3272,8 +3278,8 @@ QString QRegExp3::pattern() const
3272void QRegExp3::setPattern( const QString& pattern ) 3278void QRegExp3::setPattern( const QString& pattern )
3273{ 3279{
3274 if ( priv->pattern != pattern ) { 3280 if ( priv->pattern != pattern ) {
3275 priv->pattern = pattern; 3281 priv->pattern = pattern;
3276 compile( caseSensitive() ); 3282 compile( caseSensitive() );
3277 } 3283 }
3278} 3284}
3279 3285
@@ -3299,7 +3305,7 @@ bool QRegExp3::caseSensitive() const
3299void QRegExp3::setCaseSensitive( bool sensitive ) 3305void QRegExp3::setCaseSensitive( bool sensitive )
3300{ 3306{
3301 if ( sensitive != eng->caseSensitive() ) 3307 if ( sensitive != eng->caseSensitive() )
3302 compile( sensitive ); 3308 compile( sensitive );
3303} 3309}
3304 3310
3305#ifndef QT_NO_REGEXP_WILDCARD 3311#ifndef QT_NO_REGEXP_WILDCARD
@@ -3328,8 +3334,8 @@ bool QRegExp3::wildcard() const
3328void QRegExp3::setWildcard( bool wildcard ) 3334void QRegExp3::setWildcard( bool wildcard )
3329{ 3335{
3330 if ( wildcard != priv->wc ) { 3336 if ( wildcard != priv->wc ) {
3331 priv->wc = wildcard; 3337 priv->wc = wildcard;
3332 compile( caseSensitive() ); 3338 compile( caseSensitive() );
3333 } 3339 }
3334} 3340}
3335#endif 3341#endif
@@ -3391,12 +3397,12 @@ bool QRegExp3::exactMatch( const QString& str )
3391 3397
3392 priv->captured = eng->match( str, 0, priv->min, TRUE ); 3398 priv->captured = eng->match( str, 0, priv->min, TRUE );
3393 if ( priv->captured[1] == (int) str.length() ) { 3399 if ( priv->captured[1] == (int) str.length() ) {
3394 return TRUE; 3400 return TRUE;
3395 } else { 3401 } else {
3396 priv->captured.detach(); 3402 priv->captured.detach();
3397 priv->captured[0] = 0; 3403 priv->captured[0] = 0;
3398 priv->captured[1] = eng->matchedLength(); 3404 priv->captured[1] = eng->matchedLength();
3399 return FALSE; 3405 return FALSE;
3400 } 3406 }
3401} 3407}
3402 3408
@@ -3407,7 +3413,7 @@ bool QRegExp3::exactMatch( const QString& str )
3407bool QRegExp3::exactMatch( const QString& str ) const 3413bool QRegExp3::exactMatch( const QString& str ) const
3408{ 3414{
3409 return eng->match(str, 0, priv->min, TRUE)[0] == 0 && 3415 return eng->match(str, 0, priv->min, TRUE)[0] == 0 &&
3410 eng->matchedLength() == (int) str.length(); 3416 eng->matchedLength() == (int) str.length();
3411} 3417}
3412 3418
3413/*! \obsolete 3419/*! \obsolete
@@ -3429,29 +3435,29 @@ bool QRegExp3::exactMatch( const QString& str ) const
3429 QRegExp3 rx( "some pattern" ); 3435 QRegExp3 rx( "some pattern" );
3430 int pos = rx.search( str.mid( index ) ); 3436 int pos = rx.search( str.mid( index ) );
3431 if ( pos != -1 ) 3437 if ( pos != -1 )
3432 pos += index; 3438 pos += index;
3433 int len = rx.matchedLength(); 3439 int len = rx.matchedLength();
3434 \endcode 3440 \endcode
3435*/ 3441*/
3436#ifndef QT_NO_COMPAT 3442#ifndef QT_NO_COMPAT
3437int QRegExp3::match( const QString& str, int index, int *len, 3443int QRegExp3::match( const QString& str, int index, int *len,
3438 bool indexIsStart ) 3444 bool indexIsStart )
3439{ 3445{
3440 int pos; 3446 int pos;
3441 if ( indexIsStart ) { 3447 if ( indexIsStart ) {
3442 pos = search( str.mid(index) ); 3448 pos = search( str.mid(index) );
3443 if ( pos >= 0 ) { 3449 if ( pos >= 0 ) {
3444 pos += index; 3450 pos += index;
3445 if ( len != 0 ) 3451 if ( len != 0 )
3446 *len = matchedLength(); 3452 *len = matchedLength();
3447 } else { 3453 } else {
3448 if ( len != 0 ) 3454 if ( len != 0 )
3449 *len = 0; 3455 *len = 0;
3450 } 3456 }
3451 } else { 3457 } else {
3452 pos = search( str, index ); 3458 pos = search( str, index );
3453 if ( len != 0 ) 3459 if ( len != 0 )
3454 *len = matchedLength(); 3460 *len = matchedLength();
3455 } 3461 }
3456 return pos; 3462 return pos;
3457} 3463}
@@ -3474,8 +3480,8 @@ int QRegExp3::match( const QString& str, int index, int *len,
3474 int count = 0; 3480 int count = 0;
3475 int pos = 0; 3481 int pos = 0;
3476 while ( pos >= 0 ) { 3482 while ( pos >= 0 ) {
3477 pos = rx.search( str, pos ); 3483 pos = rx.search( str, pos );
3478 count++; 3484 count++;
3479 } 3485 }
3480 // pos will be 9, 14, 18 and finally 24; count will end up as 4. 3486 // pos will be 9, 14, 18 and finally 24; count will end up as 4.
3481 \endcode 3487 \endcode
@@ -3488,44 +3494,44 @@ int QRegExp3::match( const QString& str, int index, int *len,
3488const QString makeString(const QChar *str) 3494const QString makeString(const QChar *str)
3489{ 3495{
3490// A sentinel value checked in case the QChar *ptr is never null terminated 3496// A sentinel value checked in case the QChar *ptr is never null terminated
3491 const uint MAXLENGTH=65535; 3497 const uint MAXLENGTH=65535;
3492 3498
3493 const QChar *s=str; 3499 const QChar *s=str;
3494 uint i=0; 3500 uint i=0;
3495 while(i < MAXLENGTH && *s != QChar::null) { i++;s++ ;} 3501 while(i < MAXLENGTH && *s != QChar::null) { i++;s++ ;}
3496 return QString(str,i); 3502 return QString(str,i);
3497 3503
3498} 3504}
3499int QRegExp3::search(const QChar *str,int start) 3505int QRegExp3::search(const QChar *str,int start)
3500{ 3506{
3501 return search(makeString(str),start); 3507 return search(makeString(str),start);
3502} 3508}
3503int QRegExp3::search(const QChar *str,int start) const 3509int QRegExp3::search(const QChar *str,int start) const
3504{ 3510{
3505 return search(makeString(str),start); 3511 return search(makeString(str),start);
3506} 3512}
3507int QRegExp3::searchRev(const QChar *str,int start) 3513int QRegExp3::searchRev(const QChar *str,int start)
3508{ 3514{
3509 return searchRev(makeString(str),start); 3515 return searchRev(makeString(str),start);
3510} 3516}
3511int QRegExp3::searchRev(const QChar *str,int start) const 3517int QRegExp3::searchRev(const QChar *str,int start) const
3512{ 3518{
3513 return searchRev(makeString(str),start); 3519 return searchRev(makeString(str),start);
3514} 3520}
3515bool QRegExp3::exactMatch(const QChar *str) 3521bool QRegExp3::exactMatch(const QChar *str)
3516{ 3522{
3517 return exactMatch(makeString(str)); 3523 return exactMatch(makeString(str));
3518} 3524}
3519bool QRegExp3::exactMatch(const QChar *str) const 3525bool QRegExp3::exactMatch(const QChar *str) const
3520{ 3526{
3521 return exactMatch(makeString(str)); 3527 return exactMatch(makeString(str));
3522} 3528}
3523#endif // QCHAR_SUPPORT 3529#endif // QCHAR_SUPPORT
3524 3530
3525int QRegExp3::search( const QString& str, int start ) 3531int QRegExp3::search( const QString& str, int start )
3526{ 3532{
3527 if ( start < 0 ) 3533 if ( start < 0 )
3528 start += str.length(); 3534 start += str.length();
3529#ifndef QT_NO_REGEXP_CAPTURE 3535#ifndef QT_NO_REGEXP_CAPTURE
3530 priv->t = str; 3536 priv->t = str;
3531 priv->capturedCache.clear(); 3537 priv->capturedCache.clear();
@@ -3541,7 +3547,7 @@ int QRegExp3::search( const QString& str, int start )
3541int QRegExp3::search( const QString& str, int start ) const 3547int QRegExp3::search( const QString& str, int start ) const
3542{ 3548{
3543 if ( start < 0 ) 3549 if ( start < 0 )
3544 start += str.length(); 3550 start += str.length();
3545 return eng->match( str, start, priv->min, FALSE )[0]; 3551 return eng->match( str, start, priv->min, FALSE )[0];
3546} 3552}
3547 3553
@@ -3559,22 +3565,22 @@ int QRegExp3::search( const QString& str, int start ) const
3559int QRegExp3::searchRev( const QString& str, int start ) 3565int QRegExp3::searchRev( const QString& str, int start )
3560{ 3566{
3561 if ( start < 0 ) 3567 if ( start < 0 )
3562 start += str.length(); 3568 start += str.length();
3563#ifndef QT_NO_REGEXP_CAPTURE 3569#ifndef QT_NO_REGEXP_CAPTURE
3564 priv->t = str; 3570 priv->t = str;
3565 priv->capturedCache.clear(); 3571 priv->capturedCache.clear();
3566#endif 3572#endif
3567 if ( start < 0 || start > (int) str.length() ) { 3573 if ( start < 0 || start > (int) str.length() ) {
3568 priv->captured.detach(); 3574 priv->captured.detach();
3569 priv->captured.fill( -1 ); 3575 priv->captured.fill( -1 );
3570 return -1; 3576 return -1;
3571 } 3577 }
3572 3578
3573 while ( start >= 0 ) { 3579 while ( start >= 0 ) {
3574 priv->captured = eng->match( str, start, priv->min, TRUE ); 3580 priv->captured = eng->match( str, start, priv->min, TRUE );
3575 if ( priv->captured[0] == start ) 3581 if ( priv->captured[0] == start )
3576 return start; 3582 return start;
3577 start--; 3583 start--;
3578 } 3584 }
3579 return -1; 3585 return -1;
3580} 3586}
@@ -3586,14 +3592,14 @@ int QRegExp3::searchRev( const QString& str, int start )
3586int QRegExp3::searchRev( const QString& str, int start ) const 3592int QRegExp3::searchRev( const QString& str, int start ) const
3587{ 3593{
3588 if ( start < 0 ) 3594 if ( start < 0 )
3589 start += str.length(); 3595 start += str.length();
3590 if ( start < 0 || start > (int) str.length() ) 3596 if ( start < 0 || start > (int) str.length() )
3591 return -1; 3597 return -1;
3592 3598
3593 while ( start >= 0 ) { 3599 while ( start >= 0 ) {
3594 if ( eng->match(str, start, priv->min, TRUE)[0] == start ) 3600 if ( eng->match(str, start, priv->min, TRUE)[0] == start )
3595 return start; 3601 return start;
3596 start--; 3602 start--;
3597 } 3603 }
3598 return -1; 3604 return -1;
3599} 3605}
@@ -3656,16 +3662,16 @@ int QRegExp3::matchedLength()
3656QStringList QRegExp3::capturedTexts() 3662QStringList QRegExp3::capturedTexts()
3657{ 3663{
3658 if ( priv->capturedCache.isEmpty() ) { 3664 if ( priv->capturedCache.isEmpty() ) {
3659 for ( int i = 0; i < (int) priv->captured.size(); i += 2 ) { 3665 for ( int i = 0; i < (int) priv->captured.size(); i += 2 ) {
3660 QString m; 3666 QString m;
3661 if ( priv->captured[i + 1] == 0 ) 3667 if ( priv->captured[i + 1] == 0 )
3662 m = QString::fromLatin1( "" ); 3668 m = QString::fromLatin1( "" );
3663 else if ( priv->captured[i] >= 0 ) 3669 else if ( priv->captured[i] >= 0 )
3664 m = priv->t.mid( priv->captured[i], 3670 m = priv->t.mid( priv->captured[i],
3665 priv->captured[i + 1] ); 3671 priv->captured[i + 1] );
3666 priv->capturedCache.append( m ); 3672 priv->capturedCache.append( m );
3667 } 3673 }
3668 priv->t = QString::null; 3674 priv->t = QString::null;
3669 } 3675 }
3670 return priv->capturedCache; 3676 return priv->capturedCache;
3671} 3677}
@@ -3678,9 +3684,9 @@ QStringList QRegExp3::capturedTexts()
3678 QRegExp3 rxlen( "(\\d+)(?:\\s*)(cm|inch)" ); 3684 QRegExp3 rxlen( "(\\d+)(?:\\s*)(cm|inch)" );
3679 int pos = rxlen.search( "Length: 189cm" ); 3685 int pos = rxlen.search( "Length: 189cm" );
3680 if ( pos > -1 ) { 3686 if ( pos > -1 ) {
3681 QString value = rxlen.cap( 1 );// "189" 3687 QString value = rxlen.cap( 1 ); // "189"
3682 QString unit = rxlen.cap( 2 ); // "cm" 3688 QString unit = rxlen.cap( 2 ); // "cm"
3683 // ... 3689 // ...
3684 } 3690 }
3685 \endcode 3691 \endcode
3686 3692
@@ -3694,11 +3700,11 @@ QStringList QRegExp3::capturedTexts()
3694 QStringList list; 3700 QStringList list;
3695 pos = 0; 3701 pos = 0;
3696 while ( pos >= 0 ) { 3702 while ( pos >= 0 ) {
3697 pos = rx.search( str, pos ); 3703 pos = rx.search( str, pos );
3698 if ( pos > -1 ) { 3704 if ( pos > -1 ) {
3699 list += rx.cap( 1 ); 3705 list += rx.cap( 1 );
3700 pos += rx.matchedLength(); 3706 pos += rx.matchedLength();
3701 } 3707 }
3702 } 3708 }
3703 // list contains: ( "12", "14", "99", "231", "7" ). 3709 // list contains: ( "12", "14", "99", "231", "7" ).
3704 \endcode 3710 \endcode
@@ -3714,9 +3720,9 @@ QStringList QRegExp3::capturedTexts()
3714QString QRegExp3::cap( int nth ) 3720QString QRegExp3::cap( int nth )
3715{ 3721{
3716 if ( nth < 0 || nth >= (int) priv->captured.size() / 2 ) 3722 if ( nth < 0 || nth >= (int) priv->captured.size() / 2 )
3717 return QString::null; 3723 return QString::null;
3718 else 3724 else
3719 return capturedTexts()[nth]; 3725 return capturedTexts()[nth];
3720} 3726}
3721 3727
3722/*! Returns the position of the \a nth captured text in the 3728/*! Returns the position of the \a nth captured text in the
@@ -3726,7 +3732,7 @@ QString QRegExp3::cap( int nth )
3726 Example: 3732 Example:
3727 \code 3733 \code
3728 QRegExp3 rx( "/([a-z]+)/([a-z]+)" ); 3734 QRegExp3 rx( "/([a-z]+)/([a-z]+)" );
3729 rx.search( "Output /dev/null" );// Returns 7 (position of /dev/null) 3735 rx.search( "Output /dev/null" ); // Returns 7 (position of /dev/null)
3730 rx.pos( 0 ); // Returns 7 (position of /dev/null) 3736 rx.pos( 0 ); // Returns 7 (position of /dev/null)
3731 rx.pos( 1 ); // Returns 8 (position of dev) 3737 rx.pos( 1 ); // Returns 8 (position of dev)
3732 rx.pos( 2 ); // Returns 12 (position of null) 3738 rx.pos( 2 ); // Returns 12 (position of null)
@@ -3741,9 +3747,9 @@ QString QRegExp3::cap( int nth )
3741int QRegExp3::pos( int nth ) 3747int QRegExp3::pos( int nth )
3742{ 3748{
3743 if ( nth < 0 || nth >= (int) priv->captured.size() / 2 ) 3749 if ( nth < 0 || nth >= (int) priv->captured.size() / 2 )
3744 return -1; 3750 return -1;
3745 else 3751 else
3746 return priv->captured[2 * nth]; 3752 return priv->captured[2 * nth];
3747} 3753}
3748#endif 3754#endif
3749 3755
@@ -3752,11 +3758,11 @@ void QRegExp3::compile( bool caseSensitive )
3752 derefEngine( eng, priv->rxpattern ); 3758 derefEngine( eng, priv->rxpattern );
3753#ifndef QT_NO_REGEXP_WILDCARD 3759#ifndef QT_NO_REGEXP_WILDCARD
3754 if ( priv->wc ) 3760 if ( priv->wc )
3755 priv->rxpattern = wc2rx( priv->pattern ); 3761 priv->rxpattern = wc2rx( priv->pattern );
3756 else 3762 else
3757#endif 3763#endif
3758 priv->rxpattern = priv->pattern.isNull() ? QString::fromLatin1( "" ) 3764 priv->rxpattern = priv->pattern.isNull() ? QString::fromLatin1( "" )
3759 : priv->pattern; 3765 : priv->pattern;
3760 eng = newEngine( priv->rxpattern, caseSensitive ); 3766 eng = newEngine( priv->rxpattern, caseSensitive );
3761#ifndef QT_NO_REGEXP_CAPTURE 3767#ifndef QT_NO_REGEXP_CAPTURE
3762 priv->t = QString::null; 3768 priv->t = QString::null;