summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/device/odevice_htc.cpp3
-rw-r--r--libopie2/opiepim/private/opimeventsortvector.cpp9
-rw-r--r--noncore/apps/confedit/listviewitemconffile.cpp59
-rw-r--r--noncore/apps/opie-console/io_irda.cpp1
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp10
-rw-r--r--noncore/apps/opie-reader/CFilter.cpp2
-rw-r--r--noncore/apps/opie-reader/CRegExp.cpp4
-rw-r--r--noncore/apps/opie-reader/Palm2QImage.cpp4
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp2
-rw-r--r--noncore/apps/opie-reader/plucker_base.cpp2
-rw-r--r--noncore/apps/opie-reader/striphtml.cpp2
-rw-r--r--noncore/apps/tinykate/libkate/document/katehighlight.cpp10
-rw-r--r--noncore/net/ftplib/ftplib.c2
-rw-r--r--noncore/settings/sysinfo/contrib/dhry.c2
14 files changed, 56 insertions, 56 deletions
diff --git a/libopie2/opiecore/device/odevice_htc.cpp b/libopie2/opiecore/device/odevice_htc.cpp
index c21e10d..4e5200b 100644
--- a/libopie2/opiecore/device/odevice_htc.cpp
+++ b/libopie2/opiecore/device/odevice_htc.cpp
@@ -1,604 +1,603 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2002-2005 The Opie Team <opie-devel@handhelds.org> 3              Copyright (C) 2002-2005 The Opie Team <opie-devel@handhelds.org>
4 =. Copyright (C) 2002-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> 4 =. Copyright (C) 2002-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; version 2 of the License. 11 - .   .-<_>     .<> Foundation; version 2 of the License.
12     ._= =}       : 12     ._= =}       :
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "odevice_htc.h" 30#include "odevice_htc.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/oinputsystem.h> 33#include <opie2/oinputsystem.h>
34#include <opie2/oresource.h> 34#include <opie2/oresource.h>
35 35
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <qpe/sound.h> 37#include <qpe/sound.h>
38 38
39/* QT */ 39/* QT */
40#include <qapplication.h> 40#include <qapplication.h>
41#include <qfile.h> 41#include <qfile.h>
42#include <qtextstream.h> 42#include <qtextstream.h>
43#include <qwindowsystem_qws.h> 43#include <qwindowsystem_qws.h>
44#include <qcopchannel_qws.h> 44#include <qcopchannel_qws.h>
45 45
46/* STD */ 46/* STD */
47#include <string.h> 47#include <string.h>
48#include <errno.h> 48#include <errno.h>
49#include <fcntl.h> 49#include <fcntl.h>
50#include <math.h> 50#include <math.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <signal.h> 52#include <signal.h>
53#include <sys/ioctl.h> 53#include <sys/ioctl.h>
54#include <sys/time.h> 54#include <sys/time.h>
55#include <unistd.h> 55#include <unistd.h>
56#ifndef QT_NO_SOUND 56#ifndef QT_NO_SOUND
57#include <linux/soundcard.h> 57#include <linux/soundcard.h>
58#endif 58#endif
59 59
60using namespace Opie::Core; 60using namespace Opie::Core;
61using namespace Opie::Core::Internal; 61using namespace Opie::Core::Internal;
62 62
63struct htc_button htc_buttons [] = { 63struct htc_button htc_buttons [] = {
64 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 64 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
65 "devicebuttons/z_calendar", 65 "devicebuttons/z_calendar",
66 "datebook", "nextView()", 66 "datebook", "nextView()",
67 "today", "raise()" }, 67 "today", "raise()" },
68 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 68 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
69 "devicebuttons/z_contact", 69 "devicebuttons/z_contact",
70 "addressbook", "raise()", 70 "addressbook", "raise()",
71 "addressbook", "beamBusinessCard()" }, 71 "addressbook", "beamBusinessCard()" },
72 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 72 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
73 "devicebuttons/z_home", 73 "devicebuttons/z_home",
74 "QPE/Launcher", "home()", 74 "QPE/Launcher", "home()",
75 "buttonsettings", "raise()" }, 75 "buttonsettings", "raise()" },
76 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 76 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
77 "devicebuttons/z_menu", 77 "devicebuttons/z_menu",
78 "QPE/TaskBar", "toggleMenu()", 78 "QPE/TaskBar", "toggleMenu()",
79 "QPE/TaskBar", "toggleStartMenu()" }, 79 "QPE/TaskBar", "toggleStartMenu()" },
80 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 80 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
81 "devicebuttons/z_mail", 81 "devicebuttons/z_mail",
82 "opiemail", "raise()", 82 "opiemail", "raise()",
83 "opiemail", "newMail()" }, 83 "opiemail", "newMail()" },
84}; 84};
85 85
86struct htc_button htc_buttons_universal [] = { 86struct htc_button htc_buttons_universal [] = {
87 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 87 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
88 "devicebuttons/z_calendar", 88 "devicebuttons/z_calendar",
89 "datebook", "nextView()", 89 "datebook", "nextView()",
90 "today", "raise()" }, 90 "today", "raise()" },
91 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 91 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
92 "devicebuttons/z_contact", 92 "devicebuttons/z_contact",
93 "addressbook", "raise()", 93 "addressbook", "raise()",
94 "addressbook", "beamBusinessCard()" }, 94 "addressbook", "beamBusinessCard()" },
95 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 95 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
96 "devicebuttons/z_home", 96 "devicebuttons/z_home",
97 "QPE/Launcher", "home()", 97 "QPE/Launcher", "home()",
98 "buttonsettings", "raise()" }, 98 "buttonsettings", "raise()" },
99 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 99 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
100 "devicebuttons/z_menu", 100 "devicebuttons/z_menu",
101 "QPE/TaskBar", "toggleMenu()", 101 "QPE/TaskBar", "toggleMenu()",
102 "QPE/TaskBar", "toggleStartMenu()" }, 102 "QPE/TaskBar", "toggleStartMenu()" },
103 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 103 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
104 "devicebuttons/z_mail", 104 "devicebuttons/z_mail",
105 "opiemail", "raise()", 105 "opiemail", "raise()",
106 "opiemail", "newMail()" }, 106 "opiemail", "newMail()" },
107 107
108 { Qt::Key_F15, QT_TRANSLATE_NOOP("Button", "Hinge1"), 108 { Qt::Key_F15, QT_TRANSLATE_NOOP("Button", "Hinge1"),
109 "devicebuttons/z_hinge1", 109 "devicebuttons/z_hinge1",
110 "QPE/Rotation", "rotateDefault()",0}, 110 "QPE/Rotation", "rotateDefault()",0},
111 { Qt::Key_F16, QT_TRANSLATE_NOOP("Button", "Hinge2"), 111 { Qt::Key_F16, QT_TRANSLATE_NOOP("Button", "Hinge2"),
112 "devicebuttons/z_hinge2", 112 "devicebuttons/z_hinge2",
113 "QPE/Rotation", "rotateDefault()",0}, 113 "QPE/Rotation", "rotateDefault()",0},
114 { Qt::Key_F17, QT_TRANSLATE_NOOP("Button", "Hinge3"), 114 { Qt::Key_F17, QT_TRANSLATE_NOOP("Button", "Hinge3"),
115 "devicebuttons/z_hinge3", 115 "devicebuttons/z_hinge3",
116 "QPE/Rotation", "rotateDefault()",0}, 116 "QPE/Rotation", "rotateDefault()",0},
117}; 117};
118 118
119 119
120// 120//
121// HTC-Universal (PXA-model w/ 480x640 3.6" lcd) 121// HTC-Universal (PXA-model w/ 480x640 3.6" lcd)
122// HTC-Alpine (PXA-model w/ 240x320 3.5" lcd) 122// HTC-Alpine (PXA-model w/ 240x320 3.5" lcd)
123// HTC-Apache (PXA-model w/ 240x320 2.8" lcd) 123// HTC-Apache (PXA-model w/ 240x320 2.8" lcd)
124// HTC-Beetles (PXA-model w/ 240x240 3.0" lcd) 124// HTC-Beetles (PXA-model w/ 240x240 3.0" lcd)
125// HTC-Blueangel (PXA-model w/ 240x320 3.5" lcd) 125// HTC-Blueangel (PXA-model w/ 240x320 3.5" lcd)
126// HTC-Himalaya (PXA-model w/ 240x320 3.5" lcd) 126// HTC-Himalaya (PXA-model w/ 240x320 3.5" lcd)
127// HTC-Magician (PXA-model w/ 240x320 2.8" lcd) 127// HTC-Magician (PXA-model w/ 240x320 2.8" lcd)
128 128
129void HTC::init(const QString& cpu_info) 129void HTC::init(const QString& cpu_info)
130{ 130{
131 qDebug( "HTC::init()" ); 131 qDebug( "HTC::init()" );
132 // Set the time to wait until the system is really suspended 132 // Set the time to wait until the system is really suspended
133 // the delta between apm --suspend and sleeping 133 // the delta between apm --suspend and sleeping
134 setAPMTimeOut( 15000 ); 134 setAPMTimeOut( 15000 );
135 135
136 d->m_vendorstr = "Xanadux Team"; 136 d->m_vendorstr = "Xanadux Team";
137 d->m_systemstr = "Familiar"; 137 d->m_systemstr = "Familiar";
138 d->m_system = System_Familiar; 138 d->m_system = System_Familiar;
139 139
140 // check the HTC model 140 // check the HTC model
141 QString model; 141 QString model;
142 int loc = cpu_info.find( ":" ); 142 int loc = cpu_info.find( ":" );
143 if ( loc != -1 ) 143 if ( loc != -1 )
144 model = cpu_info.mid( loc+2 ).simplifyWhiteSpace(); 144 model = cpu_info.mid( loc+2 ).simplifyWhiteSpace();
145 else 145 else
146 model = cpu_info; 146 model = cpu_info;
147 147
148 d->m_model = Model_HTC_Universal; 148 d->m_model = Model_HTC_Universal;
149 d->m_modelstr = "Unknown HTC"; 149 d->m_modelstr = "Unknown HTC";
150 150
151 if ( model == "HTC Universal" ) { 151 if ( model == "HTC Universal" ) {
152 d->m_model = Model_HTC_Universal; 152 d->m_model = Model_HTC_Universal;
153 d->m_modelstr = "HTC Universal"; 153 d->m_modelstr = "HTC Universal";
154 } 154 }
155 if ( model == "HTC Alpine" ) { 155 if ( model == "HTC Alpine" ) {
156 d->m_model = Model_HTC_Alpine; 156 d->m_model = Model_HTC_Alpine;
157 d->m_modelstr = "HTC Alpine"; 157 d->m_modelstr = "HTC Alpine";
158 } 158 }
159 if ( model == "HTC Apache" ) { 159 if ( model == "HTC Apache" ) {
160 d->m_model = Model_HTC_Apache; 160 d->m_model = Model_HTC_Apache;
161 d->m_modelstr = "HTC Apache"; 161 d->m_modelstr = "HTC Apache";
162 } 162 }
163 if ( model == "HTC Beetles" ) { 163 if ( model == "HTC Beetles" ) {
164 d->m_model = Model_HTC_Beetles; 164 d->m_model = Model_HTC_Beetles;
165 d->m_modelstr = "HTC Beetles"; 165 d->m_modelstr = "HTC Beetles";
166 } 166 }
167 if ( model == "HTC Blueangel" ) { 167 if ( model == "HTC Blueangel" ) {
168 d->m_model = Model_HTC_Blueangel; 168 d->m_model = Model_HTC_Blueangel;
169 d->m_modelstr = "HTC Blueangel"; 169 d->m_modelstr = "HTC Blueangel";
170 } 170 }
171 if ( model == "HTC Himalaya" ) { 171 if ( model == "HTC Himalaya" ) {
172 d->m_model = Model_HTC_Himalaya; 172 d->m_model = Model_HTC_Himalaya;
173 d->m_modelstr = "HTC Himalaya"; 173 d->m_modelstr = "HTC Himalaya";
174 } 174 }
175 if ( model == "HTC Magician" ) { 175 if ( model == "HTC Magician" ) {
176 d->m_model = Model_HTC_Magician; 176 d->m_model = Model_HTC_Magician;
177 d->m_modelstr = "HTC Magician"; 177 d->m_modelstr = "HTC Magician";
178 } 178 }
179 179
180 180
181 // set path to backlight device 181 // set path to backlight device
182 switch ( d->m_model ) 182 switch ( d->m_model )
183 { 183 {
184 case Model_HTC_Universal: 184 case Model_HTC_Universal:
185 case Model_HTC_Magician: 185 case Model_HTC_Magician:
186 case Model_HTC_Alpine: 186 case Model_HTC_Alpine:
187 case Model_HTC_Beetles: 187 case Model_HTC_Beetles:
188 case Model_HTC_Apache: 188 case Model_HTC_Apache:
189 m_backlightdev = "/sys/class/backlight/pxa2xx-fb/"; 189 m_backlightdev = "/sys/class/backlight/pxa2xx-fb/";
190 break; 190 break;
191 case Model_HTC_Blueangel: 191 case Model_HTC_Blueangel:
192 case Model_HTC_Himalaya: 192 case Model_HTC_Himalaya:
193 m_backlightdev = "/sys/class/backlight/w100fb/"; 193 m_backlightdev = "/sys/class/backlight/w100fb/";
194 break; 194 break;
195 default: 195 default:
196 m_backlightdev = "/sys/class/backlight/pxafb/"; 196 m_backlightdev = "/sys/class/backlight/pxafb/";
197 } 197 }
198 198
199 // set initial rotation 199 // set initial rotation
200 switch( d->m_model ) 200 switch( d->m_model )
201 { 201 {
202 case Model_HTC_Universal: 202 case Model_HTC_Universal:
203 initHingeSensor(); 203 initHingeSensor();
204 d->m_rotation = rotation(); 204 d->m_rotation = rotation();
205 d->m_direction = direction(); 205 d->m_direction = direction();
206 break; 206 break;
207 default: 207 default:
208 d->m_rotation = Rot270; 208 d->m_rotation = Rot270;
209 } 209 }
210 210
211 // set default qte driver 211 // set default qte driver
212 switch( d->m_model ) 212 switch( d->m_model )
213 { 213 {
214 default: 214 default:
215 d->m_qteDriver = "Transformed"; 215 d->m_qteDriver = "Transformed";
216 } 216 }
217 217
218 m_leds[0] = Led_Off; 218 m_leds[0] = Led_Off;
219 219
220 qDebug( "HTC::init() - Using the 2.6 Xanadux on a %s", (const char*) d->m_modelstr ); 220 qDebug( "HTC::init() - Using the 2.6 Xanadux on a %s", (const char*) d->m_modelstr );
221} 221}
222 222
223void HTC::initButtons() 223void HTC::initButtons()
224{ 224{
225 qDebug( "HTC::initButtons()" ); 225 qDebug( "HTC::initButtons()" );
226 if ( d->m_buttons ) 226 if ( d->m_buttons )
227 return; 227 return;
228 228
229 d->m_buttons = new QValueList <ODeviceButton>; 229 d->m_buttons = new QValueList <ODeviceButton>;
230 230
231 struct htc_button * phtc_buttons; 231 struct htc_button * phtc_buttons;
232 int buttoncount; 232 int buttoncount;
233 switch ( d->m_model ) 233 switch ( d->m_model )
234 { 234 {
235 case Model_HTC_Universal: 235 case Model_HTC_Universal:
236 if ( isQWS( ) ) 236 if ( isQWS( ) )
237 { 237 {
238 addPreHandler(this); 238 addPreHandler(this);
239 } 239 }
240 phtc_buttons = htc_buttons_universal; 240 phtc_buttons = htc_buttons_universal;
241 buttoncount = ARRAY_SIZE(htc_buttons_universal); 241 buttoncount = ARRAY_SIZE(htc_buttons_universal);
242 break; 242 break;
243 default: 243 default:
244 phtc_buttons = htc_buttons; 244 phtc_buttons = htc_buttons;
245 buttoncount = ARRAY_SIZE(htc_buttons); 245 buttoncount = ARRAY_SIZE(htc_buttons);
246 break; 246 break;
247 } 247 }
248 248
249 for ( int i = 0; i < buttoncount; i++ ) { 249 for ( int i = 0; i < buttoncount; i++ ) {
250 struct htc_button *zb = phtc_buttons + i; 250 struct htc_button *zb = phtc_buttons + i;
251 ODeviceButton b; 251 ODeviceButton b;
252 252
253 b.setKeycode( zb->code ); 253 b.setKeycode( zb->code );
254 b.setUserText( QObject::tr( "Button", zb->utext )); 254 b.setUserText( QObject::tr( "Button", zb->utext ));
255 b.setPixmap( OResource::loadPixmap( zb->pix )); 255 b.setPixmap( OResource::loadPixmap( zb->pix ));
256 b.setFactoryPresetPressedAction( OQCopMessage( makeChannel ( zb->fpressedservice ), zb->fpressedaction )); 256 b.setFactoryPresetPressedAction( OQCopMessage( makeChannel ( zb->fpressedservice ), zb->fpressedaction ));
257 b.setFactoryPresetHeldAction( OQCopMessage( makeChannel ( zb->fheldservice ), zb->fheldaction )); 257 b.setFactoryPresetHeldAction( OQCopMessage( makeChannel ( zb->fheldservice ), zb->fheldaction ));
258 d->m_buttons->append( b ); 258 d->m_buttons->append( b );
259 } 259 }
260 260
261 reloadButtonMapping(); 261 reloadButtonMapping();
262} 262}
263 263
264 264
265 265
266typedef struct sharp_led_status { 266typedef struct sharp_led_status {
267 int which; /* select which LED status is wanted. */ 267 int which; /* select which LED status is wanted. */
268 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 268 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
269} sharp_led_status; 269} sharp_led_status;
270 270
271void HTC::buzzer( int sound ) 271void HTC::buzzer( int sound )
272{ 272{
273#ifndef QT_NO_SOUND 273#ifndef QT_NO_SOUND
274 Sound *snd = 0; 274 Sound *snd = 0;
275 275
276 // All devices except SL5500 have a DSP device 276 // All devices except SL5500 have a DSP device
277 if ( d->m_model == Model_HTC_Universal ) { 277 if ( d->m_model == Model_HTC_Universal ) {
278 278
279 switch ( sound ){ 279 switch ( sound ){
280 case SHARP_BUZ_TOUCHSOUND: { 280 case SHARP_BUZ_TOUCHSOUND: {
281 static Sound touch_sound("touchsound"); 281 static Sound touch_sound("touchsound");
282 snd = &touch_sound; 282 snd = &touch_sound;
283 } 283 }
284 break; 284 break;
285 case SHARP_BUZ_KEYSOUND: { 285 case SHARP_BUZ_KEYSOUND: {
286 static Sound key_sound( "keysound" ); 286 static Sound key_sound( "keysound" );
287 snd = &key_sound; 287 snd = &key_sound;
288 } 288 }
289 break; 289 break;
290 case SHARP_BUZ_SCHEDULE_ALARM: 290 case SHARP_BUZ_SCHEDULE_ALARM:
291 default: { 291 default: {
292 static Sound alarm_sound("alarm"); 292 static Sound alarm_sound("alarm");
293 snd = &alarm_sound; 293 snd = &alarm_sound;
294 } 294 }
295 break; 295 break;
296 } 296 }
297 } 297 }
298 298
299 // If a soundname is defined, we expect that this device has 299 // If a soundname is defined, we expect that this device has
300 // sound capabilities.. Otherwise we expect to have the buzzer 300 // sound capabilities.. Otherwise we expect to have the buzzer
301 // device.. 301 // device..
302 if ( snd && snd->isFinished() ){ 302 if ( snd && snd->isFinished() ){
303 changeMixerForAlarm( 0, "/dev/sound/mixer", snd ); 303 changeMixerForAlarm( 0, "/dev/sound/mixer", snd );
304 snd->play(); 304 snd->play();
305 } else if( !snd ) { 305 } else if( !snd ) {
306 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); 306 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK );
307 307
308 if ( fd >= 0 ) { 308 if ( fd >= 0 ) {
309 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 309 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
310 ::close ( fd ); 310 ::close ( fd );
311 } 311 }
312 312
313 } 313 }
314#endif 314#endif
315} 315}
316 316
317 317
318void HTC::playAlarmSound() 318void HTC::playAlarmSound()
319{ 319{
320 buzzer( SHARP_BUZ_SCHEDULE_ALARM ); 320 buzzer( SHARP_BUZ_SCHEDULE_ALARM );
321} 321}
322 322
323void HTC::playTouchSound() 323void HTC::playTouchSound()
324{ 324{
325 buzzer( SHARP_BUZ_TOUCHSOUND ); 325 buzzer( SHARP_BUZ_TOUCHSOUND );
326} 326}
327 327
328void HTC::playKeySound() 328void HTC::playKeySound()
329{ 329{
330 buzzer( SHARP_BUZ_KEYSOUND ); 330 buzzer( SHARP_BUZ_KEYSOUND );
331} 331}
332 332
333 333
334QValueList <OLed> HTC::ledList() const 334QValueList <OLed> HTC::ledList() const
335{ 335{
336 QValueList <OLed> vl; 336 QValueList <OLed> vl;
337 vl << Led_Mail; 337 vl << Led_Mail;
338 return vl; 338 return vl;
339} 339}
340 340
341QValueList <OLedState> HTC::ledStateList( OLed l ) const 341QValueList <OLedState> HTC::ledStateList( OLed l ) const
342{ 342{
343 QValueList <OLedState> vl; 343 QValueList <OLedState> vl;
344 344
345 if ( l == Led_Mail ) 345 if ( l == Led_Mail )
346 vl << Led_Off << Led_On << Led_BlinkSlow; 346 vl << Led_Off << Led_On << Led_BlinkSlow;
347 return vl; 347 return vl;
348} 348}
349 349
350OLedState HTC::ledState( OLed which ) const 350OLedState HTC::ledState( OLed which ) const
351{ 351{
352 if ( which == Led_Mail ) 352 if ( which == Led_Mail )
353 return m_leds [0]; 353 return m_leds [0];
354 else 354 else
355 return Led_Off; 355 return Led_Off;
356} 356}
357 357
358bool HTC::setLedState( OLed which, OLedState st ) 358bool HTC::setLedState( OLed which, OLedState st )
359{ 359{
360 qDebug( "HTC::setLedState: ODevice handling not yet implemented" ); 360 qDebug( "HTC::setLedState: ODevice handling not yet implemented" );
361 return false; 361 return false;
362} 362}
363 363
364int HTC::displayBrightnessResolution() const 364int HTC::displayBrightnessResolution() const
365{ 365{
366 int res = 1; 366 int res = 1;
367 367
368 int fd = ::open( m_backlightdev + "max_brightness", O_RDONLY|O_NONBLOCK ); 368 int fd = ::open( m_backlightdev + "max_brightness", O_RDONLY|O_NONBLOCK );
369 369
370 if ( fd ) 370 if ( fd )
371 { 371 {
372 char buf[100]; 372 char buf[100];
373 if ( ::read( fd, &buf[0], sizeof buf ) ) ::sscanf( &buf[0], "%d", &res ); 373 if ( ::read( fd, &buf[0], sizeof buf ) ) ::sscanf( &buf[0], "%d", &res );
374 ::close( fd ); 374 ::close( fd );
375 } 375 }
376 376
377 return res; 377 return res;
378} 378}
379 379
380bool HTC::setDisplayBrightness( int bright ) 380bool HTC::setDisplayBrightness( int bright )
381{ 381{
382 382
383 //qDebug( "HTC::setDisplayBrightness( %d )", bright ); 383 //qDebug( "HTC::setDisplayBrightness( %d )", bright );
384 bool res = false; 384 bool res = false;
385 385
386 if ( bright > 255 ) bright = 255; 386 if ( bright > 255 ) bright = 255;
387 if ( bright < 0 ) bright = 0; 387 if ( bright < 0 ) bright = 0;
388 388
389 int numberOfSteps = displayBrightnessResolution(); 389 int numberOfSteps = displayBrightnessResolution();
390 int val = ( bright == 1 ) ? 1 : ( bright * numberOfSteps ) / 255; 390 int val = ( bright == 1 ) ? 1 : ( bright * numberOfSteps ) / 255;
391 391
392 int fd = ::open( m_backlightdev + "brightness", O_WRONLY|O_NONBLOCK ); 392 int fd = ::open( m_backlightdev + "brightness", O_WRONLY|O_NONBLOCK );
393 if ( fd ) 393 if ( fd )
394 { 394 {
395 char buf[100]; 395 char buf[100];
396 int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); 396 int len = ::snprintf( &buf[0], sizeof buf, "%d", val );
397 res = ( ::write( fd, &buf[0], len ) == 0 ); 397 res = ( ::write( fd, &buf[0], len ) == 0 );
398 ::close( fd ); 398 ::close( fd );
399 } 399 }
400 return res; 400 return res;
401} 401}
402 402
403bool HTC::setDisplayStatus( bool on ) 403bool HTC::setDisplayStatus( bool on )
404{ 404{
405 405
406 bool res = false; 406 bool res = false;
407 407
408 int fd = ::open( m_backlightdev + "power", O_WRONLY|O_NONBLOCK ); 408 int fd = ::open( m_backlightdev + "power", O_WRONLY|O_NONBLOCK );
409 if ( fd ) 409 if ( fd )
410 { 410 {
411 char buf[10]; 411 char buf[10];
412 buf[0] = on ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; 412 buf[0] = on ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
413 buf[1] = '\0'; 413 buf[1] = '\0';
414 res = ( ::write( fd, &buf[0], 2 ) == 0 ); 414 res = ( ::write( fd, &buf[0], 2 ) == 0 );
415 ::close( fd ); 415 ::close( fd );
416 } 416 }
417 return res; 417 return res;
418} 418}
419 419
420Transformation HTC::rotation() const 420Transformation HTC::rotation() const
421{ 421{
422 qDebug( "HTC::rotation()" ); 422 qDebug( "HTC::rotation()" );
423 Transformation rot; 423 Transformation rot = Rot270;
424 424
425 switch ( d->m_model ) { 425 switch ( d->m_model ) {
426 case Model_HTC_Universal: 426 case Model_HTC_Universal:
427 { 427 {
428 OHingeStatus hs = readHingeSensor(); 428 OHingeStatus hs = readHingeSensor();
429 qDebug( "HTC::rotation() - hinge sensor = %d", (int) hs ); 429 qDebug( "HTC::rotation() - hinge sensor = %d", (int) hs );
430 if ( hs == CASE_PORTRAIT ) rot = Rot0; 430 if ( hs == CASE_PORTRAIT ) rot = Rot0;
431 else if ( hs == CASE_UNKNOWN ) rot = Rot270; 431 else if ( hs == CASE_UNKNOWN ) rot = Rot270;
432 else rot = Rot270;
433 } 432 }
434 break; 433 break;
435 } 434 }
436 435
437 qDebug( "HTC::rotation() - returning '%d'", rot ); 436 qDebug( "HTC::rotation() - returning '%d'", rot );
438 return rot; 437 return rot;
439} 438}
440ODirection HTC::direction() const 439ODirection HTC::direction() const
441{ 440{
442 ODirection dir; 441 ODirection dir;
443 442
444 switch ( d->m_model ) { 443 switch ( d->m_model ) {
445 case Model_HTC_Universal: { 444 case Model_HTC_Universal: {
446 OHingeStatus hs = readHingeSensor(); 445 OHingeStatus hs = readHingeSensor();
447 if ( hs == CASE_PORTRAIT ) dir = CCW; 446 if ( hs == CASE_PORTRAIT ) dir = CCW;
448 else if ( hs == CASE_UNKNOWN ) dir = CCW; 447 else if ( hs == CASE_UNKNOWN ) dir = CCW;
449 else dir = CW; 448 else dir = CW;
450 } 449 }
451 break; 450 break;
452 default: dir = d->m_direction; 451 default: dir = d->m_direction;
453 break; 452 break;
454 } 453 }
455 return dir; 454 return dir;
456 455
457} 456}
458 457
459bool HTC::hasHingeSensor() const 458bool HTC::hasHingeSensor() const
460{ 459{
461 return d->m_model == Model_HTC_Universal; 460 return d->m_model == Model_HTC_Universal;
462} 461}
463 462
464OHingeStatus HTC::readHingeSensor() const 463OHingeStatus HTC::readHingeSensor() const
465{ 464{
466 /* 465 /*
467 * The HTC Universal keyboard is event source 1 in kernel 2.6. 466 * The HTC Universal keyboard is event source 1 in kernel 2.6.
468 * Hinge status is reported via Input System Switchs 0 and 1 like that: 467 * Hinge status is reported via Input System Switchs 0 and 1 like that:
469 * 468 *
470 * ------------------------- 469 * -------------------------
471 * | SW0 | SW1 | CASE | 470 * | SW0 | SW1 | CASE |
472 * |-----|-----|-----------| 471 * |-----|-----|-----------|
473 * | 0 0 Unknown | 472 * | 0 0 Unknown |
474 * | 1 0 Portrait | 473 * | 1 0 Portrait |
475 * | 0 1 Closed | 474 * | 0 1 Closed |
476 * | 1 1 Landscape | 475 * | 1 1 Landscape |
477 * ------------------------- 476 * -------------------------
478 */ 477 */
479 OInputDevice* keyboard = OInputSystem::instance()->device( "event1" ); 478 OInputDevice* keyboard = OInputSystem::instance()->device( "event1" );
480 bool switch0 = true; 479 bool switch0 = true;
481 bool switch1 = false; 480 bool switch1 = false;
482 if ( keyboard ) 481 if ( keyboard )
483 { 482 {
484 switch0 = keyboard->isHeld( OInputDevice::Switch0 ); 483 switch0 = keyboard->isHeld( OInputDevice::Switch0 );
485 switch1 = keyboard->isHeld( OInputDevice::Switch1 ); 484 switch1 = keyboard->isHeld( OInputDevice::Switch1 );
486 } 485 }
487 if ( switch0 ) 486 if ( switch0 )
488 { 487 {
489 return switch1 ? CASE_LANDSCAPE : CASE_PORTRAIT; 488 return switch1 ? CASE_LANDSCAPE : CASE_PORTRAIT;
490 } 489 }
491 else 490 else
492 { 491 {
493 return switch1 ? CASE_CLOSED : CASE_UNKNOWN; 492 return switch1 ? CASE_CLOSED : CASE_UNKNOWN;
494 } 493 }
495} 494}
496 495
497void HTC::initHingeSensor() 496void HTC::initHingeSensor()
498{ 497{
499 if ( m_embedix ) return; 498 if ( m_embedix ) return;
500 499
501 m_hinge.setName( "/dev/input/event1" ); 500 m_hinge.setName( "/dev/input/event1" );
502 if ( !m_hinge.open( IO_ReadOnly ) ) 501 if ( !m_hinge.open( IO_ReadOnly ) )
503 { 502 {
504 qWarning( "HTC::init() - Couldn't open /dev/input/event1 for read (%s)", strerror( errno ) ); 503 qWarning( "HTC::init() - Couldn't open /dev/input/event1 for read (%s)", strerror( errno ) );
505 return; 504 return;
506 } 505 }
507 506
508 QSocketNotifier* sn = new QSocketNotifier( m_hinge.handle(), QSocketNotifier::Read, this ); 507 QSocketNotifier* sn = new QSocketNotifier( m_hinge.handle(), QSocketNotifier::Read, this );
509 QObject::connect( sn, SIGNAL(activated(int)), this, SLOT(hingeSensorTriggered()) ); 508 QObject::connect( sn, SIGNAL(activated(int)), this, SLOT(hingeSensorTriggered()) );
510 509
511 qDebug( "HTC::init() - Hinge Sensor Initialization successfully completed" ); 510 qDebug( "HTC::init() - Hinge Sensor Initialization successfully completed" );
512} 511}
513 512
514void HTC::hingeSensorTriggered() 513void HTC::hingeSensorTriggered()
515{ 514{
516 qDebug( "HTC::hingeSensorTriggered() - got event" ); 515 qDebug( "HTC::hingeSensorTriggered() - got event" );
517 struct input_event e; 516 struct input_event e;
518 if ( ::read( m_hinge.handle(), &e, sizeof e ) > 0 ) 517 if ( ::read( m_hinge.handle(), &e, sizeof e ) > 0 )
519 { 518 {
520 qDebug( "HTC::hingeSensorTriggered() - event has type %d, code %d, value %d", e.type, e.code, e.value ); 519 qDebug( "HTC::hingeSensorTriggered() - event has type %d, code %d, value %d", e.type, e.code, e.value );
521 if ( e.type != EV_SW ) return; 520 if ( e.type != EV_SW ) return;
522 if ( readHingeSensor() != CASE_UNKNOWN ) 521 if ( readHingeSensor() != CASE_UNKNOWN )
523 { 522 {
524 qDebug( "HTC::hingeSensorTriggered() - got valid switch event, calling rotateDefault()" ); 523 qDebug( "HTC::hingeSensorTriggered() - got valid switch event, calling rotateDefault()" );
525 QCopChannel::send( "QPE/Rotation", "rotateDefault()" ); 524 QCopChannel::send( "QPE/Rotation", "rotateDefault()" );
526 } 525 }
527 } 526 }
528} 527}
529 528
530void HTC::systemMessage( const QCString &msg, const QByteArray & ) 529void HTC::systemMessage( const QCString &msg, const QByteArray & )
531{ 530{
532 if ( msg == "deviceButtonMappingChanged()" ) { 531 if ( msg == "deviceButtonMappingChanged()" ) {
533 reloadButtonMapping(); 532 reloadButtonMapping();
534 } 533 }
535} 534}
536 535
537/* 536/*
538 * Take code from iPAQ device. 537 * Take code from iPAQ device.
539 * That way we switch the cursor directions depending on status of hinge sensor, eg. hardware direction. 538 * That way we switch the cursor directions depending on status of hinge sensor, eg. hardware direction.
540 * I hope that is ok - Alwin 539 * I hope that is ok - Alwin
541 */ 540 */
542bool HTC::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 541bool HTC::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
543{ 542{
544 int newkeycode = keycode; 543 int newkeycode = keycode;
545 544
546 if ( !hasHingeSensor() ) return false; 545 if ( !hasHingeSensor() ) return false;
547 546
548 /* map cursor keys depending on the hinge status */ 547 /* map cursor keys depending on the hinge status */
549 switch ( keycode ) { 548 switch ( keycode ) {
550 // Rotate cursor keys 549 // Rotate cursor keys
551 case Key_Left : 550 case Key_Left :
552 case Key_Right: 551 case Key_Right:
553 case Key_Up : 552 case Key_Up :
554 case Key_Down : 553 case Key_Down :
555 { 554 {
556 if (rotation()==Rot90) { 555 if (rotation()==Rot90) {
557 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; 556 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4;
558 } 557 }
559 } 558 }
560 break; 559 break;
561 560
562 } 561 }
563 if (newkeycode!=keycode) { 562 if (newkeycode!=keycode) {
564 if ( newkeycode != Key_unknown ) { 563 if ( newkeycode != Key_unknown ) {
565 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 564 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
566 } 565 }
567 return true; 566 return true;
568 } 567 }
569 return false; 568 return false;
570} 569}
571 570
572bool HTC::suspend() { 571bool HTC::suspend() {
573 572
574/* MV */ 573/* MV */
575 return false; 574 return false;
576 575
577 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 576 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
578 return false; 577 return false;
579 578
580 bool res = false; 579 bool res = false;
581 QCopChannel::send( "QPE/System", "aboutToSuspend()" ); 580 QCopChannel::send( "QPE/System", "aboutToSuspend()" );
582 581
583 struct timeval tvs, tvn; 582 struct timeval tvs, tvn;
584 ::gettimeofday ( &tvs, 0 ); 583 ::gettimeofday ( &tvs, 0 );
585 584
586 ::sync(); // flush fs caches 585 ::sync(); // flush fs caches
587 res = ( ::system ( "apm --suspend" ) == 0 ); 586 res = ( ::system ( "apm --suspend" ) == 0 );
588 587
589 // This is needed because some apm implementations are asynchronous and we 588 // This is needed because some apm implementations are asynchronous and we
590 // can not be sure when exactly the device is really suspended 589 // can not be sure when exactly the device is really suspended
591 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 590 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
592 // on non embedix eg. 2.6 kernel line apm is synchronous so we don't need it here. 591 // on non embedix eg. 2.6 kernel line apm is synchronous so we don't need it here.
593 592
594 if ( res && m_embedix) { 593 if ( res && m_embedix) {
595 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 594 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
596 ::usleep ( 200 * 1000 ); 595 ::usleep ( 200 * 1000 );
597 ::gettimeofday ( &tvn, 0 ); 596 ::gettimeofday ( &tvn, 0 );
598 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < m_timeOut ); 597 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < m_timeOut );
599 } 598 }
600 599
601 QCopChannel::send( "QPE/System", "returnFromSuspend()" ); 600 QCopChannel::send( "QPE/System", "returnFromSuspend()" );
602 601
603 return res; 602 return res;
604} 603}
diff --git a/libopie2/opiepim/private/opimeventsortvector.cpp b/libopie2/opiepim/private/opimeventsortvector.cpp
index 4220c63..b85f848 100644
--- a/libopie2/opiepim/private/opimeventsortvector.cpp
+++ b/libopie2/opiepim/private/opimeventsortvector.cpp
@@ -1,134 +1,131 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) 2004 Stefan Eilers <stefan@eilers-online.net> 3 Copyright (C) 2004 Stefan Eilers <stefan@eilers-online.net>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include "opimeventsortvector.h" 30#include "opimeventsortvector.h"
31#include <opie2/ocontactaccess.h> 31#include <opie2/ocontactaccess.h>
32#include <opie2/opimnotifymanager.h> 32#include <opie2/opimnotifymanager.h>
33#include <opie2/odatebookaccess.h> 33#include <opie2/odatebookaccess.h>
34 34
35#include <qvaluelist.h> 35#include <qvaluelist.h>
36 36
37namespace Opie { 37namespace Opie {
38namespace Internal { 38namespace Internal {
39 39
40namespace{ 40int testAlarmNotifiers( const OPimNotifyManager& leftnotifiers, const OPimNotifyManager& rightnotifiers ){
41
42inline int testAlarmNotifiers( const OPimNotifyManager& leftnotifiers, const OPimNotifyManager& rightnotifiers ){
43 OPimNotifyManager::Alarms left_alarms = leftnotifiers.alarms(); 41 OPimNotifyManager::Alarms left_alarms = leftnotifiers.alarms();
44 OPimNotifyManager::Alarms right_alarms = rightnotifiers.alarms(); 42 OPimNotifyManager::Alarms right_alarms = rightnotifiers.alarms();
45 43
46 // Well.. How could we compare two lists of alarms? I think we should find the most early datetimes 44 // Well.. How could we compare two lists of alarms? I think we should find the most early datetimes
47 // and compare them.. (se) 45 // and compare them.. (se)
48 // Find the first alarm of the left list 46 // Find the first alarm of the left list
49 OPimNotifyManager::Alarms::Iterator it; 47 OPimNotifyManager::Alarms::Iterator it;
50 QDateTime left_earliest; // This datetime is initialized as invalid!! 48 QDateTime left_earliest; // This datetime is initialized as invalid!!
51 for ( it = left_alarms.begin(); it != left_alarms.end(); ++it ){ 49 for ( it = left_alarms.begin(); it != left_alarms.end(); ++it ){
52 if ( !left_earliest.isValid() || left_earliest > (*it).dateTime() ){ 50 if ( !left_earliest.isValid() || left_earliest > (*it).dateTime() ){
53 left_earliest = (*it).dateTime(); 51 left_earliest = (*it).dateTime();
54 } 52 }
55 } 53 }
56 QDateTime right_earliest; // This datetime is initialized as invalid!! 54 QDateTime right_earliest; // This datetime is initialized as invalid!!
57 for ( it = right_alarms.begin(); it != right_alarms.end(); ++it ){ 55 for ( it = right_alarms.begin(); it != right_alarms.end(); ++it ){
58 if ( !right_earliest.isValid() || right_earliest > (*it).dateTime() ){ 56 if ( !right_earliest.isValid() || right_earliest > (*it).dateTime() ){
59 right_earliest = (*it).dateTime(); 57 right_earliest = (*it).dateTime();
60 } 58 }
61 } 59 }
62 60
63 int ret; 61 int ret = 0;
64 62
65 // Now compare this found alarms 63 // Now compare this found alarms
66 if ( !left_earliest .isValid() ) ret++; 64 if ( !left_earliest .isValid() ) ret++;
67 if ( !right_earliest.isValid() ) ret--; 65 if ( !right_earliest.isValid() ) ret--;
68 66
69 if ( left_earliest.isValid() && right_earliest.isValid() ){ 67 if ( left_earliest.isValid() && right_earliest.isValid() ){
70 ret += left_earliest < right_earliest ? -1 : 1; 68 left_earliest < right_earliest ? ret-- : ret++;
71 } 69 }
72 70
73 return ret; 71 return ret;
74 72
75} 73}
76}
77 74
78OPimEventSortVector::OPimEventSortVector( uint size, bool asc, int sort ) 75OPimEventSortVector::OPimEventSortVector( uint size, bool asc, int sort )
79 : OPimSortVector<OPimEvent>( size, asc, sort ) {} 76 : OPimSortVector<OPimEvent>( size, asc, sort ) {}
80 77
81int OPimEventSortVector::compareItems( const OPimEvent& left, 78int OPimEventSortVector::compareItems( const OPimEvent& left,
82 const OPimEvent& right ) { 79 const OPimEvent& right ) {
83 if ( left.uid() == right.uid() ) 80 if ( left.uid() == right.uid() )
84 return 0; 81 return 0;
85 82
86 int ret = 0; 83 int ret = 0;
87 bool asc = sortAscending(); 84 bool asc = sortAscending();
88 85
89 switch( sortOrder() ) { 86 switch( sortOrder() ) {
90 case ODateBookAccess::SortDescription: 87 case ODateBookAccess::SortDescription:
91 ret = testString( left.description(), right.description() ); 88 ret = testString( left.description(), right.description() );
92 break; 89 break;
93 case ODateBookAccess::SortLocation: 90 case ODateBookAccess::SortLocation:
94 ret = testString( left.location(), right.location() ); 91 ret = testString( left.location(), right.location() );
95 break; 92 break;
96 case ODateBookAccess::SortNote: 93 case ODateBookAccess::SortNote:
97 ret = testString( left.note(),right.note() ); 94 ret = testString( left.note(),right.note() );
98 break; 95 break;
99 case ODateBookAccess::SortStartTime: 96 case ODateBookAccess::SortStartTime:
100 ret = testTime( left.startDateTime().time(), right.startDateTime().time() ); 97 ret = testTime( left.startDateTime().time(), right.startDateTime().time() );
101 break; 98 break;
102 case ODateBookAccess::SortEndTime: 99 case ODateBookAccess::SortEndTime:
103 ret = testTime( left.endDateTime().time(), right.endDateTime().time() ); 100 ret = testTime( left.endDateTime().time(), right.endDateTime().time() );
104 break; 101 break;
105 case ODateBookAccess::SortStartDate: 102 case ODateBookAccess::SortStartDate:
106 ret = testDate( left.startDateTime().date(), right.startDateTime().date() ); 103 ret = testDate( left.startDateTime().date(), right.startDateTime().date() );
107 break; 104 break;
108 case ODateBookAccess::SortEndDate: 105 case ODateBookAccess::SortEndDate:
109 ret = testDate( left.endDateTime().date(), right.endDateTime().date() ); 106 ret = testDate( left.endDateTime().date(), right.endDateTime().date() );
110 break; 107 break;
111 case ODateBookAccess::SortStartDateTime: 108 case ODateBookAccess::SortStartDateTime:
112 ret = testDateTime( left.startDateTime(), right.startDateTime() ); 109 ret = testDateTime( left.startDateTime(), right.startDateTime() );
113 break; 110 break;
114 case ODateBookAccess::SortEndDateTime: 111 case ODateBookAccess::SortEndDateTime:
115 ret = testDateTime( left.endDateTime(), right.endDateTime() ); 112 ret = testDateTime( left.endDateTime(), right.endDateTime() );
116 break; 113 break;
117 case ODateBookAccess::SortAlarmDateTime: 114 case ODateBookAccess::SortAlarmDateTime:
118 ret = testAlarmNotifiers( left.notifiers(), right.notifiers() ); 115 ret = testAlarmNotifiers( left.notifiers(), right.notifiers() );
119 break; 116 break;
120 default: 117 default:
121 odebug << "OpimEventSortVector: Unknown sortOrder: " << sortOrder() << oendl; 118 odebug << "OpimEventSortVector: Unknown sortOrder: " << sortOrder() << oendl;
122 } 119 }
123 120
124 /* twist to honor ascending/descending setting as QVector only sorts ascending */ 121 /* twist to honor ascending/descending setting as QVector only sorts ascending */
125 if ( !asc ) 122 if ( !asc )
126 ret *= -1; 123 ret *= -1;
127 124
128 // Maybe differentiate as in OPimTodoSortVector ### FIXME 125 // Maybe differentiate as in OPimTodoSortVector ### FIXME
129 // if( ret ) 126 // if( ret )
130 return ret; 127 return ret;
131} 128}
132 129
133} 130}
134} 131}
diff --git a/noncore/apps/confedit/listviewitemconffile.cpp b/noncore/apps/confedit/listviewitemconffile.cpp
index 2958cf5..a7d6b00 100644
--- a/noncore/apps/confedit/listviewitemconffile.cpp
+++ b/noncore/apps/confedit/listviewitemconffile.cpp
@@ -1,165 +1,170 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9// (c) 2002 Patrick S. Vogt <tille@handhelds.org> 9// (c) 2002 Patrick S. Vogt <tille@handhelds.org>
10 10
11#include "listviewitemconffile.h" 11#include "listviewitemconffile.h"
12#include "listviewitemconfigentry.h" 12#include "listviewitemconfigentry.h"
13 13
14/* OPIE */ 14/* OPIE */
15#include <opie2/odebug.h> 15#include <opie2/odebug.h>
16using namespace Opie::Core; 16using namespace Opie::Core;
17 17
18/* QT */ 18/* QT */
19#include <qmessagebox.h> 19#include <qmessagebox.h>
20#include <qtextstream.h> 20#include <qtextstream.h>
21 21
22#define tr QObject::tr 22#define tr QObject::tr
23 23
24ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) 24ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent)
25 : ListViewItemConf(parent), _valid(false) 25 : ListViewItemConf(parent), _valid(false)
26{ 26{
27 confFileInfo = file; 27 confFileInfo = file;
28 // parseFile(); 28 // parseFile();
29 displayText(); 29 displayText();
30} 30}
31 31
32ListViewItemConfFile::~ListViewItemConfFile() 32ListViewItemConfFile::~ListViewItemConfFile()
33{ 33{
34} 34}
35 35
36 36
37void ListViewItemConfFile::displayText() 37void ListViewItemConfFile::displayText()
38{ 38{
39 setText(0,(_changed?"*":"")+confFileInfo->fileName()); 39 setText(0,(_changed?"*":"")+confFileInfo->fileName());
40} 40}
41 41
42QString ListViewItemConfFile::fileName() 42QString ListViewItemConfFile::fileName()
43{ 43{
44 return confFileInfo->fileName(); 44 return confFileInfo->fileName();
45} 45}
46 46
47void ListViewItemConfFile::parseFile() 47void ListViewItemConfFile::parseFile()
48{ 48{
49 //odebug << "ListViewItemConfFile::parseFile BEGIN" << oendl; 49 //odebug << "ListViewItemConfFile::parseFile BEGIN" << oendl;
50 QFile confFile(confFileInfo->absFilePath()); 50 QFile confFile(confFileInfo->absFilePath());
51 if(! confFile.open(IO_ReadOnly)) 51 if(! confFile.open(IO_ReadOnly))
52 QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); 52 QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0);
53 QTextStream t( &confFile ); 53
54 QString s; 54 QTextStream t( &confFile );
55 QString s;
55 QString group; 56 QString group;
56 ListViewItemConfigEntry *groupItem; 57 ListViewItemConfigEntry *groupItem = 0;
57 ListViewItemConfigEntry *item; 58 ListViewItemConfigEntry *item;
58 while ( !t.atEnd() ) 59 while ( !t.atEnd() )
59 { 60 {
60 s = t.readLine().stripWhiteSpace(); 61 s = t.readLine().stripWhiteSpace();
61 //odebug << "line: >" << s.latin1() << "<\n" << oendl; 62 //odebug << "line: >" << s.latin1() << "<\n" << oendl;
62 if (s.contains("<?xml")) 63 if (s.contains("<?xml"))
63 { 64 {
64 _valid = false; 65 _valid = false;
65 break; 66 break;
66 }else 67 }
67 if ( s[0] == '[' && s[s.length()-1] == ']' ) 68 else if ( s[0] == '[' && s[s.length()-1] == ']' )
68 { 69 {
69 // odebug << "got group"+s << oendl; 70 //odebug << "got group"+s << oendl;
70 group = s.mid(1,s.length()-2); 71 group = s.mid(1,s.length()-2);
71 if (!groupItem) groupItem = new ListViewItemConfigEntry(this, tr("no group") ); 72 if (!groupItem)
73 groupItem = new ListViewItemConfigEntry(this, tr("no group") );
74
72 groupItem = new ListViewItemConfigEntry(this, group ); 75 groupItem = new ListViewItemConfigEntry(this, group );
73 insertItem( groupItem ); 76 insertItem( groupItem );
74 } else 77 }
75 if ( int pos = s.find('=') ) 78 else if ( int pos = s.find('=') )
76 { 79 {
77// odebug << "got key"+s << oendl; 80 //odebug << "got key"+s << oendl;
78 if (!groupItem) odebug << "PANIK NO GROUP! >" << group.latin1() << "<" << oendl; 81 if (!groupItem)
79 item = new ListViewItemConfigEntry(this, group, s ); 82 odebug << "PANIC! no group >" << group.latin1() << "<" << oendl;
83
84 item = new ListViewItemConfigEntry(this, group, s );
80 groupItem->insertItem( item ); 85 groupItem->insertItem( item );
81 } 86 }
82 } 87 }
83 confFile.close(); 88 confFile.close();
84 setExpandable( _valid ); 89 setExpandable( _valid );
85 //odebug << "ListViewItemConfFile::parseFile END" << oendl; 90 //odebug << "ListViewItemConfFile::parseFile END" << oendl;
86} 91}
87 92
88 93
89void ListViewItemConfFile::remove() 94void ListViewItemConfFile::remove()
90{ 95{
91 QFile::remove(confFileInfo->absFilePath()); 96 QFile::remove(confFileInfo->absFilePath());
92 QFile::remove(backupFileName()); 97 QFile::remove(backupFileName());
93 delete this; 98 delete this;
94} 99}
95 100
96void ListViewItemConfFile::revert() 101void ListViewItemConfFile::revert()
97{ 102{
98 if (!_changed) 103 if (!_changed)
99 { 104 {
100 // read the backup file 105 // read the backup file
101 QFile conf(confFileInfo->absFilePath()); 106 QFile conf(confFileInfo->absFilePath());
102 QFile back(backupFileName()); 107 QFile back(backupFileName());
103 108
104 if (!back.open(IO_ReadOnly)) return; 109 if (!back.open(IO_ReadOnly)) return;
105 if (!conf.open(IO_WriteOnly)) return; 110 if (!conf.open(IO_WriteOnly)) return;
106 111
107 #define SIZE 124 112 #define SIZE 124
108 char buf[SIZE]; 113 char buf[SIZE];
109 while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); 114 while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c);
110 conf.close(); 115 conf.close();
111 back.close(); 116 back.close();
112 } 117 }
113 parseFile(); 118 parseFile();
114 expand(); 119 expand();
115} 120}
116 121
117void ListViewItemConfFile::save() 122void ListViewItemConfFile::save()
118{ 123{
119 if (!_changed) return; 124 if (!_changed) return;
120 QFile conf(confFileInfo->absFilePath()); 125 QFile conf(confFileInfo->absFilePath());
121 QFile back(backupFileName()); 126 QFile back(backupFileName());
122 127
123 if (!conf.open(IO_ReadOnly)) return; 128 if (!conf.open(IO_ReadOnly)) return;
124 if (!back.open(IO_WriteOnly)) return; 129 if (!back.open(IO_WriteOnly)) return;
125 130
126 char buf[SIZE]; 131 char buf[SIZE];
127 while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); 132 while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c);
128 conf.close(); 133 conf.close();
129 back.close(); 134 back.close();
130 135
131 136
132 if (!conf.open(IO_WriteOnly)) return; 137 if (!conf.open(IO_WriteOnly)) return;
133 QTextStream *t = new QTextStream( &conf ); 138 QTextStream *t = new QTextStream( &conf );
134 for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) 139 for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling())
135 { 140 {
136 ((ListViewItemConfigEntry*)it)->save(t); 141 ((ListViewItemConfigEntry*)it)->save(t);
137 } 142 }
138 conf.close(); 143 conf.close();
139 unchanged(); 144 unchanged();
140} 145}
141 146
142 147
143bool ListViewItemConfFile::revertable() 148bool ListViewItemConfFile::revertable()
144{ 149{
145 return _changed || QFile(backupFileName()).exists(); 150 return _changed || QFile(backupFileName()).exists();
146} 151}
147 152
148QString ListViewItemConfFile::backupFileName() 153QString ListViewItemConfFile::backupFileName()
149{ 154{
150 return confFileInfo->absFilePath()+"~"; 155 return confFileInfo->absFilePath()+"~";
151} 156}
152 157
153 158
154void ListViewItemConfFile::expand() 159void ListViewItemConfFile::expand()
155{ 160{
156 QListViewItem *subItem = firstChild(); 161 QListViewItem *subItem = firstChild();
157 QListViewItem *toDel; 162 QListViewItem *toDel;
158 while(subItem) 163 while(subItem)
159 { 164 {
160 toDel = subItem; 165 toDel = subItem;
161 subItem = subItem->nextSibling(); 166 subItem = subItem->nextSibling();
162 delete toDel; 167 delete toDel;
163 } 168 }
164 parseFile(); 169 parseFile();
165} 170}
diff --git a/noncore/apps/opie-console/io_irda.cpp b/noncore/apps/opie-console/io_irda.cpp
index 9d27c85..a0f72ae 100644
--- a/noncore/apps/opie-console/io_irda.cpp
+++ b/noncore/apps/opie-console/io_irda.cpp
@@ -1,64 +1,65 @@
1#include "io_irda.h" 1#include "io_irda.h"
2 2
3IOIrda::IOIrda( const Profile &config ) : IOSerial( config ) { 3IOIrda::IOIrda( const Profile &config ) : IOSerial( config ) {
4 m_attach = 0; 4 m_attach = 0;
5} 5}
6 6
7 7
8IOIrda::~IOIrda() { 8IOIrda::~IOIrda() {
9 if ( m_attach ) { 9 if ( m_attach ) {
10 delete m_attach; 10 delete m_attach;
11 } 11 }
12} 12}
13 13
14 14
15void IOIrda::close() { 15void IOIrda::close() {
16 16
17 IOSerial::close(); 17 IOSerial::close();
18 // still need error handling 18 // still need error handling
19 delete m_attach; 19 delete m_attach;
20} 20}
21 21
22bool IOIrda::open() { 22bool IOIrda::open() {
23 bool ret; 23 bool ret;
24 24
25 // irdaattach here 25 // irdaattach here
26 m_attach = new Opie::Core::OProcess(); 26 m_attach = new Opie::Core::OProcess();
27 *m_attach << "irattach /dev/ttyS2 -s"; 27 *m_attach << "irattach /dev/ttyS2 -s";
28 28
29 connect( m_attach, SIGNAL( processExited(Opie::Core::OProcess*) ), 29 connect( m_attach, SIGNAL( processExited(Opie::Core::OProcess*) ),
30 this, SLOT( slotExited(Opie::Core::OProcess*) ) ); 30 this, SLOT( slotExited(Opie::Core::OProcess*) ) );
31 31
32 if ( m_attach->start() ) { 32 if ( m_attach->start() ) {
33 ret= IOSerial::open(); 33 ret= IOSerial::open();
34 } else { 34 } else {
35 // emit error!!! 35 // emit error!!!
36 delete m_attach; 36 delete m_attach;
37 m_attach = 0l; 37 m_attach = 0l;
38 ret = false;
38 } 39 }
39 return ret; 40 return ret;
40} 41}
41 42
42void IOIrda::reload( const Profile &config ) { 43void IOIrda::reload( const Profile &config ) {
43 m_device = config.readEntry("Device", IRDA_DEFAULT_DEVICE); 44 m_device = config.readEntry("Device", IRDA_DEFAULT_DEVICE);
44 m_baud = config.readNumEntry("Baud", IRDA_DEFAULT_BAUD); 45 m_baud = config.readNumEntry("Baud", IRDA_DEFAULT_BAUD);
45 m_parity = config.readNumEntry("Parity", IRDA_DEFAULT_PARITY); 46 m_parity = config.readNumEntry("Parity", IRDA_DEFAULT_PARITY);
46 m_dbits = config.readNumEntry("DataBits", IRDA_DEFAULT_DBITS); 47 m_dbits = config.readNumEntry("DataBits", IRDA_DEFAULT_DBITS);
47 m_sbits = config.readNumEntry("StopBits", IRDA_DEFAULT_SBITS); 48 m_sbits = config.readNumEntry("StopBits", IRDA_DEFAULT_SBITS);
48 m_flow = config.readNumEntry("Flow", IRDA_DEFAULT_FLOW); 49 m_flow = config.readNumEntry("Flow", IRDA_DEFAULT_FLOW);
49} 50}
50 51
51 52
52QString IOIrda::identifier() const { 53QString IOIrda::identifier() const {
53 return "irda"; 54 return "irda";
54} 55}
55 56
56QString IOIrda::name() const { 57QString IOIrda::name() const {
57 return "Irda IO Layer"; 58 return "Irda IO Layer";
58} 59}
59 60
60void IOIrda::slotExited(Opie::Core::OProcess* proc ){ 61void IOIrda::slotExited(Opie::Core::OProcess* proc ){
61 close(); 62 close();
62 delete proc; 63 delete proc;
63} 64}
64 65
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index aba7244..a884179 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -1,835 +1,831 @@
1#include "TEmulation.h" 1#include "TEmulation.h"
2#include "profileeditordialog.h" 2#include "profileeditordialog.h"
3#include "configdialog.h" 3#include "configdialog.h"
4#include "default.h" 4#include "default.h"
5#include "profilemanager.h" 5#include "profilemanager.h"
6#include "mainwindow.h" 6#include "mainwindow.h"
7#include "tabwidget.h" 7#include "tabwidget.h"
8#include "transferdialog.h" 8#include "transferdialog.h"
9#include "function_keyboard.h" 9#include "function_keyboard.h"
10#include "emulation_handler.h" 10#include "emulation_handler.h"
11#include "script.h" 11#include "script.h"
12#include "fixit.h" 12#include "fixit.h"
13 13
14/* OPIE */ 14/* OPIE */
15#include <opie2/ofiledialog.h> 15#include <opie2/ofiledialog.h>
16#include <opie2/oresource.h> 16#include <opie2/oresource.h>
17#include <qpe/filemanager.h> 17#include <qpe/filemanager.h>
18using namespace Opie::Ui; 18using namespace Opie::Ui;
19 19
20/* QT */ 20/* QT */
21#include <qaction.h> 21#include <qaction.h>
22#include <qmenubar.h> 22#include <qmenubar.h>
23#include <qtoolbar.h> 23#include <qtoolbar.h>
24#include <qmessagebox.h> 24#include <qmessagebox.h>
25#include <qwhatsthis.h> 25#include <qwhatsthis.h>
26#include <qfileinfo.h> 26#include <qfileinfo.h>
27 27
28/* STD */ 28/* STD */
29#include <assert.h> 29#include <assert.h>
30 30
31#include <opie2/oconfig.h> 31#include <opie2/oconfig.h>
32 32
33MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { 33MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) {
34 34
35#ifdef FSCKED_DISTRI 35#ifdef FSCKED_DISTRI
36 FixIt fix; 36 FixIt fix;
37 fix.fixIt(); 37 fix.fixIt();
38#endif 38#endif
39 39
40 setCaption(QObject::tr("Opie Console") ); 40 setCaption(QObject::tr("Opie Console") );
41 KeyTrans::loadAll(); 41 KeyTrans::loadAll();
42 for (int i = 0; i < KeyTrans::count(); i++ ) { 42 for (int i = 0; i < KeyTrans::count(); i++ ) {
43 KeyTrans* s = KeyTrans::find(i ); 43 KeyTrans* s = KeyTrans::find(i );
44 assert( s ); 44 assert( s );
45 } 45 }
46 m_factory = new MetaFactory(); 46 m_factory = new MetaFactory();
47 Default def(m_factory); 47 Default def(m_factory);
48 m_sessions.setAutoDelete( TRUE ); 48 m_sessions.setAutoDelete( TRUE );
49 m_curSession = 0; 49 m_curSession = 0;
50 m_manager = new ProfileManager( m_factory ); 50 m_manager = new ProfileManager( m_factory );
51 m_manager->load(); 51 m_manager->load();
52 m_scriptsData.setAutoDelete(TRUE); 52 m_scriptsData.setAutoDelete(TRUE);
53 53
54 initUI(); 54 initUI();
55 populateProfiles(); 55 populateProfiles();
56 populateScripts(); 56 populateScripts();
57} 57}
58 58
59void MainWindow::initUI() { 59void MainWindow::initUI() {
60 60
61 setToolBarsMovable( FALSE ); 61 setToolBarsMovable( FALSE );
62 62
63 /* tool bar for the menu */ 63 /* tool bar for the menu */
64 m_tool = new QToolBar( this ); 64 m_tool = new QToolBar( this );
65 m_tool->setHorizontalStretchable( TRUE ); 65 m_tool->setHorizontalStretchable( TRUE );
66 66
67 m_bar = new QMenuBar( m_tool ); 67 m_bar = new QMenuBar( m_tool );
68 m_console = new QPopupMenu( this ); 68 m_console = new QPopupMenu( this );
69 m_scripts = new QPopupMenu( this ); 69 m_scripts = new QPopupMenu( this );
70 m_sessionsPop= new QPopupMenu( this ); 70 m_sessionsPop= new QPopupMenu( this );
71 m_scriptsPop = new QPopupMenu( this ); 71 m_scriptsPop = new QPopupMenu( this );
72 m_scrollbar = new QPopupMenu( this ); 72 m_scrollbar = new QPopupMenu( this );
73 73
74 /* add a toolbar for icons */ 74 /* add a toolbar for icons */
75 m_icons = new QToolBar(this); 75 m_icons = new QToolBar(this);
76 76
77 /* 77 /*
78 * the settings action 78 * the settings action
79 */ 79 */
80 m_setProfiles = new QAction(tr("Configure Profiles"), 80 m_setProfiles = new QAction(tr("Configure Profiles"),
81 Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), 81 Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ),
82 QString::null, 0, this, 0); 82 QString::null, 0, this, 0);
83 m_setProfiles->addTo( m_console ); 83 m_setProfiles->addTo( m_console );
84 connect( m_setProfiles, SIGNAL(activated() ), 84 connect( m_setProfiles, SIGNAL(activated() ),
85 this, SLOT(slotConfigure() ) ); 85 this, SLOT(slotConfigure() ) );
86 86
87 m_console->insertSeparator(); 87 m_console->insertSeparator();
88 /* 88 /*
89 * new Action for new sessions 89 * new Action for new sessions
90 */ 90 */
91 QAction* newCon = new QAction(tr("New Profile"), 91 QAction* newCon = new QAction(tr("New Profile"),
92 Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), 92 Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
93 QString::null, 0, this, 0); 93 QString::null, 0, this, 0);
94 newCon->addTo( m_console ); 94 newCon->addTo( m_console );
95 connect( newCon, SIGNAL(activated() ), 95 connect( newCon, SIGNAL(activated() ),
96 this, SLOT(slotNew() ) ); 96 this, SLOT(slotNew() ) );
97 97
98 m_console->insertSeparator(); 98 m_console->insertSeparator();
99 99
100 QAction *saveCon = new QAction( tr("Save Profile" ), 100 QAction *saveCon = new QAction( tr("Save Profile" ),
101 Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), QString::null, 101 Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), QString::null,
102 0, this, 0 ); 102 0, this, 0 );
103 saveCon->addTo( m_console ); 103 saveCon->addTo( m_console );
104 connect( saveCon, SIGNAL(activated() ), 104 connect( saveCon, SIGNAL(activated() ),
105 this, SLOT(slotSaveSession() ) ); 105 this, SLOT(slotSaveSession() ) );
106 m_console->insertSeparator(); 106 m_console->insertSeparator();
107 107
108 /* 108 /*
109 * connect action 109 * connect action
110 */ 110 */
111 m_connect = new QAction( tr("Connect"), Opie::Core::OResource::loadPixmap("console/connected", 111 m_connect = new QAction( tr("Connect"), Opie::Core::OResource::loadPixmap("console/connected",
112 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); 112 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
113 m_connect->addTo( m_console ); 113 m_connect->addTo( m_console );
114 connect(m_connect, SIGNAL(activated() ), 114 connect(m_connect, SIGNAL(activated() ),
115 this, SLOT(slotConnect() ) ); 115 this, SLOT(slotConnect() ) );
116 116
117 /* 117 /*
118 * disconnect action 118 * disconnect action
119 */ 119 */
120 m_disconnect = new QAction( tr("Disconnect"), Opie::Core::OResource::loadPixmap("console/notconnected", 120 m_disconnect = new QAction( tr("Disconnect"), Opie::Core::OResource::loadPixmap("console/notconnected",
121 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); 121 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
122 m_disconnect->addTo( m_console ); 122 m_disconnect->addTo( m_console );
123 connect(m_disconnect, SIGNAL(activated() ), 123 connect(m_disconnect, SIGNAL(activated() ),
124 this, SLOT(slotDisconnect() ) ); 124 this, SLOT(slotDisconnect() ) );
125 125
126 m_console->insertSeparator(); 126 m_console->insertSeparator();
127 127
128#ifndef EAST 128#ifndef EAST
129 m_quickLaunch = new QAction( tr("QuickLaunch"), 129 m_quickLaunch = new QAction( tr("QuickLaunch"),
130 Opie::Core::OResource::loadPixmap("console/konsole_mini", Opie::Core::OResource::SmallIcon ), 130 Opie::Core::OResource::loadPixmap("console/konsole_mini", Opie::Core::OResource::SmallIcon ),
131 QString::null, 0, this, 0 ); 131 QString::null, 0, this, 0 );
132 m_quickLaunch->addTo( m_icons ); 132 m_quickLaunch->addTo( m_icons );
133 connect( m_quickLaunch, SIGNAL( activated() ), 133 connect( m_quickLaunch, SIGNAL( activated() ),
134 this, SLOT( slotQuickLaunch() ) ); 134 this, SLOT( slotQuickLaunch() ) );
135#endif 135#endif
136 136
137 QWhatsThis::add( m_icons, tr( "The shell button launches the \"default\" profile. If there is none default values are taken" ) ); 137 QWhatsThis::add( m_icons, tr( "The shell button launches the \"default\" profile. If there is none default values are taken" ) );
138 138
139 m_transfer = new QAction( tr("Transfer file..."), Opie::Core::OResource::loadPixmap("pass", Opie::Core::OResource::SmallIcon ), 139 m_transfer = new QAction( tr("Transfer file..."), Opie::Core::OResource::loadPixmap("pass", Opie::Core::OResource::SmallIcon ),
140 QString::null, 0, this, 0 ); 140 QString::null, 0, this, 0 );
141 m_transfer->addTo( m_console ); 141 m_transfer->addTo( m_console );
142 connect(m_transfer, SIGNAL(activated() ), 142 connect(m_transfer, SIGNAL(activated() ),
143 this, SLOT(slotTransfer() ) ); 143 this, SLOT(slotTransfer() ) );
144 144
145 145
146 146
147 /* 147 /*
148 * immediate change of line wrap policy 148 * immediate change of line wrap policy
149 */ 149 */
150 m_isWrapped = true; 150 m_isWrapped = true;
151 m_wrap = new QAction( tr("Line wrap"), Opie::Core::OResource::loadPixmap( "linewrap", Opie::Core::OResource::SmallIcon ), 151 m_wrap = new QAction( tr("Line wrap"), Opie::Core::OResource::loadPixmap( "linewrap", Opie::Core::OResource::SmallIcon ),
152 QString::null, 0, this, 0, true ); 152 QString::null, 0, this, 0, true );
153 m_wrap->addTo( m_console ); 153 m_wrap->addTo( m_console );
154 m_wrap->setOn( true ); 154 m_wrap->setOn( true );
155 connect( m_wrap, SIGNAL( activated() ), SLOT( slotWrap() ) ); 155 connect( m_wrap, SIGNAL( activated() ), SLOT( slotWrap() ) );
156 156
157 /* 157 /*
158 * fullscreen 158 * fullscreen
159 */ 159 */
160 m_isFullscreen = false; 160 m_isFullscreen = false;
161 161
162 m_fullscreen = new QAction( tr("Full screen"), Opie::Core::OResource::loadPixmap( "fullscreen", 162 m_fullscreen = new QAction( tr("Full screen"), Opie::Core::OResource::loadPixmap( "fullscreen",
163 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); 163 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
164 m_fullscreen->addTo( m_console ); 164 m_fullscreen->addTo( m_console );
165 connect( m_fullscreen, SIGNAL( activated() ), 165 connect( m_fullscreen, SIGNAL( activated() ),
166 this, SLOT( slotFullscreen() ) ); 166 this, SLOT( slotFullscreen() ) );
167 167
168 /* 168 /*
169 * scrollbar 169 * scrollbar
170 */ 170 */
171 sm_none = m_scrollbar->insertItem(tr( "None" )); 171 sm_none = m_scrollbar->insertItem(tr( "None" ));
172 sm_left = m_scrollbar->insertItem(tr( "Left" )); 172 sm_left = m_scrollbar->insertItem(tr( "Left" ));
173 sm_right = m_scrollbar->insertItem(tr( "Right" )); 173 sm_right = m_scrollbar->insertItem(tr( "Right" ));
174 174
175 m_console->insertItem(tr("Scrollbar"), m_scrollbar, -1, 0); 175 m_console->insertItem(tr("Scrollbar"), m_scrollbar, -1, 0);
176 connect( m_scrollbar, SIGNAL(activated(int)), 176 connect( m_scrollbar, SIGNAL(activated(int)),
177 this, SLOT(slotScrollbarSelected(int))); 177 this, SLOT(slotScrollbarSelected(int)));
178 178
179 m_console->insertSeparator(); 179 m_console->insertSeparator();
180 180
181 m_recordLog = new QAction(); 181 m_recordLog = new QAction();
182 m_recordLog->setText( tr("Start log") ); 182 m_recordLog->setText( tr("Start log") );
183 m_recordLog->addTo( m_console ); 183 m_recordLog->addTo( m_console );
184 connect(m_recordLog, SIGNAL(activated() ), 184 connect(m_recordLog, SIGNAL(activated() ),
185 this, SLOT( slotSaveLog() ) ); 185 this, SLOT( slotSaveLog() ) );
186 m_recordingLog = false; 186 m_recordingLog = false;
187 187
188 QAction *a = new QAction(); 188 QAction *a = new QAction();
189 a->setText( tr("Save history") ); 189 a->setText( tr("Save history") );
190 a->addTo( m_console ); 190 a->addTo( m_console );
191 connect(a, SIGNAL(activated() ), 191 connect(a, SIGNAL(activated() ),
192 this, SLOT(slotSaveHistory() ) ); 192 this, SLOT(slotSaveHistory() ) );
193 /* 193 /*
194 * terminate action 194 * terminate action
195 */ 195 */
196 m_terminate = new QAction(); 196 m_terminate = new QAction();
197 m_terminate->setText( tr("Terminate") ); 197 m_terminate->setText( tr("Terminate") );
198 m_terminate->addTo( m_console ); 198 m_terminate->addTo( m_console );
199 connect(m_terminate, SIGNAL(activated() ), 199 connect(m_terminate, SIGNAL(activated() ),
200 this, SLOT(slotTerminate() ) ); 200 this, SLOT(slotTerminate() ) );
201 201
202 m_closewindow = new QAction(); 202 m_closewindow = new QAction();
203 m_closewindow->setText( tr("Close Window") ); 203 m_closewindow->setText( tr("Close Window") );
204 m_closewindow->addTo( m_console ); 204 m_closewindow->addTo( m_console );
205 connect( m_closewindow, SIGNAL(activated() ), 205 connect( m_closewindow, SIGNAL(activated() ),
206 this, SLOT(slotClose() ) ); 206 this, SLOT(slotClose() ) );
207 207
208 208
209 /* 209 /*
210 * script actions 210 * script actions
211 */ 211 */
212 m_runScript_id = m_scripts->insertItem(tr("Run Script"), m_scriptsPop, -1, 0); 212 m_runScript_id = m_scripts->insertItem(tr("Run Script"), m_scriptsPop, -1, 0);
213 connect(m_scriptsPop, SIGNAL(activated(int)), this, SLOT(slotRunScript(int))); 213 connect(m_scriptsPop, SIGNAL(activated(int)), this, SLOT(slotRunScript(int)));
214 214
215 m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0); 215 m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0);
216 m_recordScript->addTo(m_scripts); 216 m_recordScript->addTo(m_scripts);
217 connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript())); 217 connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript()));
218 218
219 m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0); 219 m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0);
220 m_saveScript->addTo(m_scripts); 220 m_saveScript->addTo(m_scripts);
221 connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript())); 221 connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript()));
222 222
223 223
224 224
225 225
226 /* 226 /*
227 * action that open/closes the keyboard 227 * action that open/closes the keyboard
228 */ 228 */
229 m_openKeys = new QAction (tr("Open Keyboard..."), 229 m_openKeys = new QAction (tr("Open Keyboard..."),
230 Opie::Core::OResource::loadPixmap( "console/keys/keyboard_icon", Opie::Core::OResource::SmallIcon ), 230 Opie::Core::OResource::loadPixmap( "console/keys/keyboard_icon", Opie::Core::OResource::SmallIcon ),
231 QString::null, 0, this, 0); 231 QString::null, 0, this, 0);
232 m_openKeys->setToggleAction(true); 232 m_openKeys->setToggleAction(true);
233 connect (m_openKeys, SIGNAL(toggled(bool)), this, SLOT(slotOpenKeb(bool))); 233 connect (m_openKeys, SIGNAL(toggled(bool)), this, SLOT(slotOpenKeb(bool)));
234 234
235 /* insert the submenu */ 235 /* insert the submenu */
236 m_console->insertItem(tr("New from Profile"), m_sessionsPop, 236 m_console->insertItem(tr("New from Profile"), m_sessionsPop,
237 -1, 0); 237 -1, 0);
238 238
239 /* insert the connection menu */ 239 /* insert the connection menu */
240 m_bar->insertItem( tr("Connection"), m_console ); 240 m_bar->insertItem( tr("Connection"), m_console );
241 241
242 /* the scripts menu */ 242 /* the scripts menu */
243#ifdef EAST 243#ifdef EAST
244 Opie::Core::OConfig cfg("opie-console"); 244 Opie::Core::OConfig cfg("opie-console");
245 cfg.setGroup("10east"); 245 cfg.setGroup("10east");
246 if( !cfg.readEntry("scripthide",0) ) { 246 if( !cfg.readEntry("scripthide",0) ) {
247 m_bar->insertItem( tr("Scripts"), m_scripts ); 247 m_bar->insertItem( tr("Scripts"), m_scripts );
248 } 248 }
249#endif 249#endif
250 250
251 /* and the keyboard */ 251 /* and the keyboard */
252 m_keyBar = new QToolBar(this); 252 m_keyBar = new QToolBar(this);
253 addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE ); 253 addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE );
254 m_keyBar->setHorizontalStretchable( TRUE ); 254 m_keyBar->setHorizontalStretchable( TRUE );
255 m_keyBar->hide(); 255 m_keyBar->hide();
256 256
257 m_kb = new FunctionKeyboard(m_keyBar); 257 m_kb = new FunctionKeyboard(m_keyBar);
258 connect(m_kb, SIGNAL(keyPressed(FKey,ushort,ushort,bool)), 258 connect(m_kb, SIGNAL(keyPressed(FKey,ushort,ushort,bool)),
259 this, SLOT(slotKeyReceived(FKey,ushort,ushort,bool))); 259 this, SLOT(slotKeyReceived(FKey,ushort,ushort,bool)));
260 260
261 261
262 a = new QAction(tr("Copy"), 262 a = new QAction(tr("Copy"),
263 Opie::Core::OResource::loadPixmap("copy", Opie::Core::OResource::SmallIcon ), QString::null, 263 Opie::Core::OResource::loadPixmap("copy", Opie::Core::OResource::SmallIcon ), QString::null,
264 0, this, 0 ); 264 0, this, 0 );
265 //a->addTo( m_icons ); 265 //a->addTo( m_icons );
266 connect( a, SIGNAL(activated() ), 266 connect( a, SIGNAL(activated() ),
267 this, SLOT(slotCopy() ) ); 267 this, SLOT(slotCopy() ) );
268 268
269 QAction *paste = new QAction(tr("Paste"), 269 QAction *paste = new QAction(tr("Paste"),
270 Opie::Core::OResource::loadPixmap("paste", Opie::Core::OResource::SmallIcon ), QString::null, 270 Opie::Core::OResource::loadPixmap("paste", Opie::Core::OResource::SmallIcon ), QString::null,
271 0, this, 0 ); 271 0, this, 0 );
272 connect( paste, SIGNAL(activated() ), 272 connect( paste, SIGNAL(activated() ),
273 this, SLOT(slotPaste() ) ); 273 this, SLOT(slotPaste() ) );
274 274
275 275
276 newCon->addTo( m_icons ); 276 newCon->addTo( m_icons );
277 //m_setProfiles->addTo( m_icons ); 277 //m_setProfiles->addTo( m_icons );
278 paste->addTo( m_icons ); 278 paste->addTo( m_icons );
279 m_openKeys->addTo(m_icons); 279 m_openKeys->addTo(m_icons);
280 m_fullscreen->addTo( m_icons ); 280 m_fullscreen->addTo( m_icons );
281 281
282 m_connect->setEnabled( false ); 282 m_connect->setEnabled( false );
283 m_disconnect->setEnabled( false ); 283 m_disconnect->setEnabled( false );
284 m_terminate->setEnabled( false ); 284 m_terminate->setEnabled( false );
285 m_transfer->setEnabled( false ); 285 m_transfer->setEnabled( false );
286 m_scripts->setItemEnabled(m_runScript_id, false); 286 m_scripts->setItemEnabled(m_runScript_id, false);
287 m_recordScript->setEnabled( false ); 287 m_recordScript->setEnabled( false );
288 m_saveScript->setEnabled( false ); 288 m_saveScript->setEnabled( false );
289 m_fullscreen->setEnabled( false ); 289 m_fullscreen->setEnabled( false );
290 m_closewindow->setEnabled( false ); 290 m_closewindow->setEnabled( false );
291 m_wrap->setEnabled( false ); 291 m_wrap->setEnabled( false );
292 292
293 /* 293 /*
294 * connect to the menu activation 294 * connect to the menu activation
295 */ 295 */
296 connect( m_sessionsPop, SIGNAL(activated(int) ), 296 connect( m_sessionsPop, SIGNAL(activated(int) ),
297 this, SLOT(slotProfile(int) ) ); 297 this, SLOT(slotProfile(int) ) );
298 298
299 m_consoleWindow = new TabWidget( this, "blah"); 299 m_consoleWindow = new TabWidget( this, "blah");
300 connect(m_consoleWindow, SIGNAL(activated(Session*) ), 300 connect(m_consoleWindow, SIGNAL(activated(Session*) ),
301 this, SLOT(slotSessionChanged(Session*) ) ); 301 this, SLOT(slotSessionChanged(Session*) ) );
302 setCentralWidget( m_consoleWindow ); 302 setCentralWidget( m_consoleWindow );
303 303
304 slotQuickLaunch(); 304 slotQuickLaunch();
305} 305}
306 306
307ProfileManager* MainWindow::manager() { 307ProfileManager* MainWindow::manager() {
308 return m_manager; 308 return m_manager;
309} 309}
310TabWidget* MainWindow::tabWidget() { 310TabWidget* MainWindow::tabWidget() {
311 return m_consoleWindow; 311 return m_consoleWindow;
312} 312}
313void MainWindow::populateProfiles() { 313void MainWindow::populateProfiles() {
314 m_sessionsPop->clear(); 314 m_sessionsPop->clear();
315 Profile::ValueList list = manager()->all(); 315 Profile::ValueList list = manager()->all();
316 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { 316 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) {
317 m_sessionsPop->insertItem( (*it).name() ); 317 m_sessionsPop->insertItem( (*it).name() );
318 } 318 }
319 319
320} 320}
321 321
322void MainWindow::populateScripts() { 322void MainWindow::populateScripts() {
323 m_scriptsPop->clear(); 323 m_scriptsPop->clear();
324 m_scriptsData.clear(); 324 m_scriptsData.clear();
325 DocLnkSet files(QPEApplication::documentDir(), "text/plain"); 325 DocLnkSet files(QPEApplication::documentDir(), "text/plain");
326 QListIterator<DocLnk> dit(files.children()); 326 QListIterator<DocLnk> dit(files.children());
327 for (; dit.current(); ++dit) { 327 for (; dit.current(); ++dit) {
328 if (*dit && (*dit)->name().length()>0) { 328 if (*dit && (*dit)->name().length()>0) {
329 QFileInfo info((*dit)->file()); 329 QFileInfo info((*dit)->file());
330 if (info.extension(false) == "script") { 330 if (info.extension(false) == "script") {
331 m_scriptsData.append(new DocLnk(**dit)); 331 m_scriptsData.append(new DocLnk(**dit));
332 m_scriptsPop->insertItem((*dit)->name()); 332 m_scriptsPop->insertItem((*dit)->name());
333 } 333 }
334 } 334 }
335 } 335 }
336 336
337} 337}
338 338
339MainWindow::~MainWindow() { 339MainWindow::~MainWindow() {
340 delete m_factory; 340 delete m_factory;
341 manager()->save(); 341 manager()->save();
342#ifdef FSCKED_DISTRI 342#ifdef FSCKED_DISTRI
343 FixIt fix; 343 FixIt fix;
344 fix.breakIt(); 344 fix.breakIt();
345#endif 345#endif
346} 346}
347 347
348MetaFactory* MainWindow::factory() { 348MetaFactory* MainWindow::factory() {
349 return m_factory; 349 return m_factory;
350} 350}
351 351
352Session* MainWindow::currentSession() { 352Session* MainWindow::currentSession() {
353 return m_curSession; 353 return m_curSession;
354} 354}
355 355
356QList<Session> MainWindow::sessions() { 356QList<Session> MainWindow::sessions() {
357 return m_sessions; 357 return m_sessions;
358} 358}
359 359
360void MainWindow::slotNew() { 360void MainWindow::slotNew() {
361 ProfileEditorDialog dlg(factory() ); 361 ProfileEditorDialog dlg(factory() );
362 dlg.setCaption( tr("New Connection") ); 362 dlg.setCaption( tr("New Connection") );
363 int ret = QPEApplication::execDialog( &dlg ); 363 int ret = QPEApplication::execDialog( &dlg );
364 364
365 if ( ret == QDialog::Accepted ) { 365 if ( ret == QDialog::Accepted ) {
366 create( dlg.profile() ); 366 create( dlg.profile() );
367 } 367 }
368} 368}
369 369
370void MainWindow::slotRecordScript() { 370void MainWindow::slotRecordScript() {
371 if (currentSession()) { 371 if (currentSession()) {
372 currentSession()->emulationHandler()->startRecording(); 372 currentSession()->emulationHandler()->startRecording();
373 m_saveScript->setEnabled(true); 373 m_saveScript->setEnabled(true);
374 m_recordScript->setEnabled(false); 374 m_recordScript->setEnabled(false);
375 } 375 }
376} 376}
377 377
378void MainWindow::slotSaveScript() { 378void MainWindow::slotSaveScript() {
379 if (currentSession() && currentSession()->emulationHandler()->isRecording()) { 379 if (currentSession() && currentSession()->emulationHandler()->isRecording()) {
380 QMap<QString, QStringList> map; 380 QMap<QString, QStringList> map;
381 QStringList text; 381 QStringList text;
382 text << "text/plain"; 382 text << "text/plain";
383 map.insert(tr("Script"), text ); 383 map.insert(tr("Script"), text );
384 QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map); 384 QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
385 if (!filename.isEmpty()) { 385 if (!filename.isEmpty()) {
386 QFileInfo info(filename); 386 QFileInfo info(filename);
387 if (info.extension(FALSE) != "script") 387 if (info.extension(FALSE) != "script")
388 filename += ".script"; 388 filename += ".script";
389 DocLnk nf; 389 DocLnk nf;
390 nf.setType("text/plain"); 390 nf.setType("text/plain");
391 nf.setFile(filename); 391 nf.setFile(filename);
392 nf.setName(info.fileName()); 392 nf.setName(info.fileName());
393 FileManager fm; 393 FileManager fm;
394 fm.saveFile(nf, currentSession()->emulationHandler()->script()->script()); 394 fm.saveFile(nf, currentSession()->emulationHandler()->script()->script());
395 currentSession()->emulationHandler()->clearScript(); 395 currentSession()->emulationHandler()->clearScript();
396 m_saveScript->setEnabled(false); 396 m_saveScript->setEnabled(false);
397 m_recordScript->setEnabled(true); 397 m_recordScript->setEnabled(true);
398 populateScripts(); 398 populateScripts();
399 } 399 }
400 } 400 }
401} 401}
402 402
403void MainWindow::slotRunScript(int id) { 403void MainWindow::slotRunScript(int id) {
404 if (currentSession()) { 404 if (currentSession()) {
405 int index = m_scriptsPop->indexOf(id); 405 int index = m_scriptsPop->indexOf(id);
406 DocLnk *lnk = m_scriptsData.at(index); 406 DocLnk *lnk = m_scriptsData.at(index);
407 QString filePath = lnk->file(); 407 QString filePath = lnk->file();
408 Script script(filePath); 408 Script script(filePath);
409 currentSession()->emulationHandler()->runScript(&script); 409 currentSession()->emulationHandler()->runScript(&script);
410 } 410 }
411} 411}
412 412
413void MainWindow::slotConnect() { 413void MainWindow::slotConnect() {
414 if ( currentSession() ) { 414 if ( currentSession() ) {
415 bool ret = currentSession()->layer()->open(); 415 bool ret = currentSession()->layer()->open();
416 if(!ret) QMessageBox::warning(currentSession()->widgetStack(), 416 if(!ret) QMessageBox::warning(currentSession()->widgetStack(),
417 QObject::tr("Failed"), 417 QObject::tr("Failed"),
418 QObject::tr("Connecting failed for this session.")); 418 QObject::tr("Connecting failed for this session."));
419 else { 419 else {
420 m_connect->setEnabled( false ); 420 m_connect->setEnabled( false );
421 m_disconnect->setEnabled( true ); 421 m_disconnect->setEnabled( true );
422 422
423 // if it does not support file transfer, disable the menu entry 423 // if it does not support file transfer, disable the menu entry
424 if ( ( m_curSession->layer() )->supports()[1] == 0 ) { 424 if ( ( m_curSession->layer() )->supports()[1] == 0 ) {
425 m_transfer->setEnabled( false ); 425 m_transfer->setEnabled( false );
426 } else { 426 } else {
427 m_transfer->setEnabled( true ); 427 m_transfer->setEnabled( true );
428 } 428 }
429 429
430 m_recordScript->setEnabled( true ); 430 m_recordScript->setEnabled( true );
431 m_scripts->setItemEnabled(m_runScript_id, true); 431 m_scripts->setItemEnabled(m_runScript_id, true);
432 } 432 }
433 } 433 }
434} 434}
435 435
436void MainWindow::slotDisconnect() { 436void MainWindow::slotDisconnect() {
437 if ( currentSession() ) { 437 if ( currentSession() ) {
438 currentSession()->layer()->close(); 438 currentSession()->layer()->close();
439 m_connect->setEnabled( true ); 439 m_connect->setEnabled( true );
440 m_disconnect->setEnabled( false ); 440 m_disconnect->setEnabled( false );
441 m_transfer->setEnabled( false ); 441 m_transfer->setEnabled( false );
442 m_recordScript->setEnabled( false); 442 m_recordScript->setEnabled( false);
443 m_saveScript->setEnabled( false ); 443 m_saveScript->setEnabled( false );
444 m_scripts->setItemEnabled(m_runScript_id, false); 444 m_scripts->setItemEnabled(m_runScript_id, false);
445 } 445 }
446} 446}
447 447
448void MainWindow::slotTerminate() { 448void MainWindow::slotTerminate() {
449 if ( currentSession() ) 449 if ( currentSession() )
450 currentSession()->layer()->close(); 450 currentSession()->layer()->close();
451 451
452 slotClose(); 452 slotClose();
453 /* FIXME move to the next session */ 453 /* FIXME move to the next session */
454} 454}
455 455
456 456
457 457
458void MainWindow::slotQuickLaunch() { 458void MainWindow::slotQuickLaunch() {
459 459
460 Profile prof = manager()->profile( "default" ); 460 Profile prof = manager()->profile( "default" );
461 if ( prof.name() == "default" ) { 461 if ( prof.name() == "default" ) {
462 create( prof ); 462 create( prof );
463 } else { 463 } else {
464 #ifndef EAST 464 #ifndef EAST
465 Profile newProf = Profile( "default", "console", "default" , 0, 3, 0 ); 465 Profile newProf = Profile( "default", "console", "default" , 0, 3, 0 );
466 newProf.setAutoConnect( true ); 466 newProf.setAutoConnect( true );
467 create( newProf ); 467 create( newProf );
468 slotSaveSession(); 468 slotSaveSession();
469 #endif 469 #endif
470 } 470 }
471} 471}
472 472
473void MainWindow::slotConfigure() { 473void MainWindow::slotConfigure() {
474 ConfigDialog conf( manager()->all(), factory() ); 474 ConfigDialog conf( manager()->all(), factory() );
475 475
476 int ret = QPEApplication::execDialog( &conf ); 476 int ret = QPEApplication::execDialog( &conf );
477 477
478 if ( QDialog::Accepted == ret ) { 478 if ( QDialog::Accepted == ret ) {
479 manager()->setProfiles( conf.list() ); 479 manager()->setProfiles( conf.list() );
480 manager()->save(); 480 manager()->save();
481 populateProfiles(); 481 populateProfiles();
482 } 482 }
483} 483}
484/* 484/*
485 * we will remove 485 * we will remove
486 * this window from the tabwidget 486 * this window from the tabwidget
487 * remove it from the list 487 * remove it from the list
488 * delete it 488 * delete it
489 * and set the currentSession() 489 * and set the currentSession()
490 */ 490 */
491void MainWindow::slotClose() { 491void MainWindow::slotClose() {
492 if (!currentSession() ) 492 if (!currentSession() )
493 return; 493 return;
494 494
495 Session* ses = currentSession(); 495 Session* ses = currentSession();
496 /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */ 496 /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */
497 m_curSession = NULL; 497 m_curSession = NULL;
498 tabWidget()->remove( /*currentSession()*/ses ); 498 tabWidget()->remove( /*currentSession()*/ses );
499 /*it's autodelete */ 499 /*it's autodelete */
500 m_sessions.remove( ses ); 500 m_sessions.remove( ses );
501 501
502 if (!currentSession() ) { 502 if (!currentSession() ) {
503 m_connect->setEnabled( false ); 503 m_connect->setEnabled( false );
504 m_disconnect->setEnabled( false ); 504 m_disconnect->setEnabled( false );
505 m_terminate->setEnabled( false ); 505 m_terminate->setEnabled( false );
506 m_transfer->setEnabled( false ); 506 m_transfer->setEnabled( false );
507 m_recordScript->setEnabled( false ); 507 m_recordScript->setEnabled( false );
508 m_saveScript->setEnabled( false ); 508 m_saveScript->setEnabled( false );
509 m_scripts->setItemEnabled(m_runScript_id, false); 509 m_scripts->setItemEnabled(m_runScript_id, false);
510 m_fullscreen->setEnabled( false ); 510 m_fullscreen->setEnabled( false );
511 m_wrap->setEnabled( false ); 511 m_wrap->setEnabled( false );
512 m_closewindow->setEnabled( false ); 512 m_closewindow->setEnabled( false );
513 } 513 }
514 514
515 m_kb->loadDefaults(); 515 m_kb->loadDefaults();
516} 516}
517 517
518/* 518/*
519 * We will get the name 519 * We will get the name
520 * Then the profile 520 * Then the profile
521 * and then we will make a profile 521 * and then we will make a profile
522 */ 522 */
523void MainWindow::slotProfile( int id) { 523void MainWindow::slotProfile( int id) {
524 Profile prof = manager()->profile( m_sessionsPop->text( id) ); 524 Profile prof = manager()->profile( m_sessionsPop->text( id) );
525 create( prof ); 525 create( prof );
526} 526}
527 527
528 528
529 529
530void MainWindow::create( const Profile& prof ) { 530void MainWindow::create( const Profile& prof ) {
531 char *homeDir = getenv("HOME"); 531 char *homeDir = getenv("HOME");
532 532
533 if ( homeDir ) 533 if ( homeDir )
534 ::chdir( homeDir ); 534 ::chdir( homeDir );
535 535
536 if(m_curSession) 536 if(m_curSession)
537 if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide(); 537 if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide();
538 538
539 Session *ses = manager()->fromProfile( prof, tabWidget() ); 539 Session *ses = manager()->fromProfile( prof, tabWidget() );
540 540
541 if((!ses) || (!ses->layer()) || (!ses->widgetStack())) 541 if((!ses) || (!ses->layer()) || (!ses->widgetStack()))
542 { 542 {
543 QMessageBox::warning(this, 543 QMessageBox::warning(this,
544 QObject::tr("Session failed"), 544 QObject::tr("Session failed"),
545 QObject::tr("<qt>Cannot open session: Not all components were found.</qt>")); 545 QObject::tr("<qt>Cannot open session: Not all components were found.</qt>"));
546 //if(ses) delete ses; 546 //if(ses) delete ses;
547 return; 547 return;
548 } 548 }
549 549
550 m_sessions.append( ses ); 550 m_sessions.append( ses );
551 tabWidget()->add( ses ); 551 tabWidget()->add( ses );
552 tabWidget()->repaint(); 552 tabWidget()->repaint();
553 m_curSession = ses; 553 m_curSession = ses;
554 554
555 // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it 555 // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it
556 m_connect->setEnabled( true ); 556 m_connect->setEnabled( true );
557 m_disconnect->setEnabled( false ); 557 m_disconnect->setEnabled( false );
558 m_terminate->setEnabled( true ); 558 m_terminate->setEnabled( true );
559 m_fullscreen->setEnabled( true ); 559 m_fullscreen->setEnabled( true );
560 m_wrap->setEnabled( true ); 560 m_wrap->setEnabled( true );
561 m_closewindow->setEnabled( true ); 561 m_closewindow->setEnabled( true );
562 m_transfer->setEnabled( false ); 562 m_transfer->setEnabled( false );
563 m_recordScript->setEnabled( false ); 563 m_recordScript->setEnabled( false );
564 m_saveScript->setEnabled( false ); 564 m_saveScript->setEnabled( false );
565 m_scripts->setItemEnabled(m_runScript_id, false); 565 m_scripts->setItemEnabled(m_runScript_id, false);
566 566
567 // is io_layer wants direct connection, then autoconnect 567 // is io_layer wants direct connection, then autoconnect
568 //if ( ( m_curSession->layer() )->supports()[0] == 1 ) { 568 //if ( ( m_curSession->layer() )->supports()[0] == 1 ) {
569 if (prof.autoConnect()) { 569 if (prof.autoConnect()) {
570 slotConnect(); 570 slotConnect();
571 } 571 }
572 572
573 QWidget *w = currentSession()->widget(); 573 QWidget *w = currentSession()->widget();
574 if(w) w->setFocus(); 574 if(w) w->setFocus();
575 575
576 if(currentSession()->profile().readNumEntry("Wrap", 80)){ 576 if(currentSession()->profile().readNumEntry("Wrap", 80)){
577 m_isWrapped = true; 577 m_isWrapped = true;
578 } else { 578 } else {
579 m_isWrapped = false; 579 m_isWrapped = false;
580 } 580 }
581 581
582 m_kb->load(currentSession()->profile()); 582 m_kb->load(currentSession()->profile());
583} 583}
584 584
585void MainWindow::slotTransfer() 585void MainWindow::slotTransfer()
586{ 586{
587 if ( currentSession() ) { 587 if ( currentSession() ) {
588 Session *mysession = currentSession(); 588 Session *mysession = currentSession();
589 TransferDialog dlg(/*mysession->widgetStack()*/this, this); 589 TransferDialog dlg(/*mysession->widgetStack()*/this, this);
590 mysession->setTransferDialog(&dlg); 590 mysession->setTransferDialog(&dlg);
591 //dlg.reparent(mysession->widgetStack(), QPoint(0, 0)); 591 //dlg.reparent(mysession->widgetStack(), QPoint(0, 0));
592 //dlg.showMaximized(); 592 //dlg.showMaximized();
593 currentSession()->widgetStack()->addWidget(&dlg, -1); 593 currentSession()->widgetStack()->addWidget(&dlg, -1);
594 dlg.show(); 594 dlg.show();
595 //dlg.exec(); 595 //dlg.exec();
596 while(dlg.isRunning()) qApp->processEvents(); 596 while(dlg.isRunning()) qApp->processEvents();
597 mysession->setTransferDialog(0l); 597 mysession->setTransferDialog(0l);
598 } 598 }
599} 599}
600 600
601 601
602void MainWindow::slotOpenKeb(bool state) { 602void MainWindow::slotOpenKeb(bool state) {
603 603
604 if (state) m_keyBar->show(); 604 if (state) m_keyBar->show();
605 else m_keyBar->hide(); 605 else m_keyBar->hide();
606 606
607} 607}
608 608
609 609
610void MainWindow::slotOpenButtons( bool state ) { 610void MainWindow::slotOpenButtons( bool state ) {
611 611
612 if ( state ) { 612 if ( state ) {
613 m_buttonBar->show(); 613 m_buttonBar->show();
614 } else { 614 } else {
615 m_buttonBar->hide(); 615 m_buttonBar->hide();
616 } 616 }
617} 617}
618 618
619 619
620 620
621void MainWindow::slotSessionChanged( Session* ses ) { 621void MainWindow::slotSessionChanged( Session* ses ) {
622 if(m_curSession) 622 if(m_curSession)
623 if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide(); 623 if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide();
624 if(ses) 624 if(ses)
625 if(ses->transferDialog()) ses->transferDialog()->show(); 625 if(ses->transferDialog()) ses->transferDialog()->show();
626 626
627 if ( ses ) { 627 if ( ses ) {
628 m_curSession = ses; 628 m_curSession = ses;
629 if ( m_curSession->layer()->isConnected() ) { 629 if ( m_curSession->layer()->isConnected() ) {
630 m_connect->setEnabled( false ); 630 m_connect->setEnabled( false );
631 m_disconnect->setEnabled( true ); 631 m_disconnect->setEnabled( true );
632 m_recordScript->setEnabled(!m_curSession->emulationHandler()->isRecording()); 632 m_recordScript->setEnabled(!m_curSession->emulationHandler()->isRecording());
633 m_saveScript->setEnabled(m_curSession->emulationHandler()->isRecording()); 633 m_saveScript->setEnabled(m_curSession->emulationHandler()->isRecording());
634 m_scripts->setItemEnabled(m_runScript_id, true); 634 m_scripts->setItemEnabled(m_runScript_id, true);
635 } else { 635 } else {
636 m_connect->setEnabled( true ); 636 m_connect->setEnabled( true );
637 m_disconnect->setEnabled( false ); 637 m_disconnect->setEnabled( false );
638 m_recordScript->setEnabled( false ); 638 m_recordScript->setEnabled( false );
639 m_saveScript->setEnabled( false ); 639 m_saveScript->setEnabled( false );
640 m_scripts->setItemEnabled(m_runScript_id, false); 640 m_scripts->setItemEnabled(m_runScript_id, false);
641 } 641 }
642 642
643 if ( ( currentSession()->emulationHandler()->isLogging() ) ) { 643 if ( ( currentSession()->emulationHandler()->isLogging() ) ) {
644 m_recordLog->setText( tr("Stop log") ); 644 m_recordLog->setText( tr("Stop log") );
645 } else { 645 } else {
646 m_recordLog->setText( tr("Start log") ); 646 m_recordLog->setText( tr("Start log") );
647 } 647 }
648 648
649 if ( ( m_curSession->layer() )->supports()[1] == 0 ) { 649 if ( ( m_curSession->layer() )->supports()[1] == 0 ) {
650 m_transfer->setEnabled( false ); 650 m_transfer->setEnabled( false );
651 } else { 651 } else {
652 m_transfer->setEnabled( true ); 652 m_transfer->setEnabled( true );
653 } 653 }
654 654
655 QWidget *w = m_curSession->widget(); 655 QWidget *w = m_curSession->widget();
656 if(w) w->setFocus(); 656 if(w) w->setFocus();
657 657
658 if(currentSession()->profile().readNumEntry("Wrap", 80)){ 658 if(currentSession()->profile().readNumEntry("Wrap", 80)){
659 m_isWrapped = true; 659 m_isWrapped = true;
660 } else { 660 } else {
661 m_isWrapped = false; 661 m_isWrapped = false;
662 } 662 }
663 663
664 m_kb->load(currentSession()->profile()); 664 m_kb->load(currentSession()->profile());
665 } 665 }
666} 666}
667 667
668void MainWindow::slotWrap() 668void MainWindow::slotWrap()
669{ 669{
670 if(m_curSession) 670 if(m_curSession)
671 { 671 {
672 EmulationHandler *e = m_curSession->emulationHandler(); 672 EmulationHandler *e = m_curSession->emulationHandler();
673 if(e) 673 if(e)
674 { 674 {
675 e->setWrap( m_isWrapped ? 80:0 ); 675 e->setWrap( m_isWrapped ? 80:0 );
676 m_isWrapped = !m_isWrapped; 676 m_isWrapped = !m_isWrapped;
677 } 677 }
678 } 678 }
679} 679}
680 680
681void MainWindow::slotFullscreen() { 681void MainWindow::slotFullscreen() {
682 682
683 683
684 684
685 if ( m_isFullscreen ) { 685 if ( m_isFullscreen ) {
686 ( m_curSession->widgetStack() )->reparent( savedParentFullscreen, 0, QPoint(0,0), true ); 686 ( m_curSession->widgetStack() )->reparent( savedParentFullscreen, 0, QPoint(0,0), true );
687 ( m_curSession->widgetStack() )->resize( savedParentFullscreen->width(), savedParentFullscreen->height() ); 687 ( m_curSession->widgetStack() )->resize( savedParentFullscreen->width(), savedParentFullscreen->height() );
688 ( m_curSession->emulationHandler() )->cornerButton()->hide(); 688 ( m_curSession->emulationHandler() )->cornerButton()->hide();
689 disconnect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) ); 689 disconnect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
690 690
691 } else { 691 } else {
692 savedParentFullscreen = ( m_curSession->widgetStack() )->parentWidget(); 692 savedParentFullscreen = ( m_curSession->widgetStack() )->parentWidget();
693 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame ); 693 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame );
694 ( m_curSession->widgetStack() )->reparent( 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop 694 ( m_curSession->widgetStack() )->reparent( 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop
695 , QPoint(0,0), false ); 695 , QPoint(0,0), false );
696 ( m_curSession->widgetStack() )->resize( qApp->desktop()->width(), qApp->desktop()->height() ); 696 ( m_curSession->widgetStack() )->resize( qApp->desktop()->width(), qApp->desktop()->height() );
697 ( m_curSession->widgetStack() )->setFocus(); 697 ( m_curSession->widgetStack() )->setFocus();
698 ( m_curSession->widgetStack() )->show(); 698 ( m_curSession->widgetStack() )->show();
699 699
700 ( ( m_curSession->emulationHandler() )->cornerButton() )->show(); 700 ( ( m_curSession->emulationHandler() )->cornerButton() )->show();
701 701
702 connect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) ); 702 connect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
703 } 703 }
704 704
705 m_isFullscreen = !m_isFullscreen; 705 m_isFullscreen = !m_isFullscreen;
706} 706}
707 707
708void MainWindow::slotScrollbarSelected(int index) 708void MainWindow::slotScrollbarSelected(int index)
709{ 709{
710 int loc; 710 int loc = 0;
711 711
712 Config cfg( "Konsole" ); 712 Config cfg( "Konsole" );
713 cfg.setGroup("ScrollBar"); 713 cfg.setGroup("ScrollBar");
714 if(index == sm_none) 714 if(index == sm_left)
715 {
716 loc = 0;
717 }
718 else if(index == sm_left)
719 { 715 {
720 loc = 1; 716 loc = 1;
721 } 717 }
722 else if(index == sm_right) 718 else if(index == sm_right)
723 { 719 {
724 loc = 2; 720 loc = 2;
725 } 721 }
726 722
727 cfg.writeEntry("Position", loc); 723 cfg.writeEntry("Position", loc);
728 724
729 if (currentSession()) { 725 if (currentSession()) {
730 currentSession()->emulationHandler()->setScrollbarLocation(loc); 726 currentSession()->emulationHandler()->setScrollbarLocation(loc);
731 } 727 }
732 728
733 m_scrollbar->setItemChecked(sm_none, index == sm_none); 729 m_scrollbar->setItemChecked(sm_none, index == sm_none);
734 m_scrollbar->setItemChecked(sm_left, index == sm_left); 730 m_scrollbar->setItemChecked(sm_left, index == sm_left);
735 m_scrollbar->setItemChecked(sm_right, index == sm_right); 731 m_scrollbar->setItemChecked(sm_right, index == sm_right);
736} 732}
737 733
738void MainWindow::slotKeyReceived(FKey k, ushort, ushort, bool pressed) { 734void MainWindow::slotKeyReceived(FKey k, ushort, ushort, bool pressed) {
739 735
740 if ( m_curSession ) { 736 if ( m_curSession ) {
741 737
742 QEvent::Type state; 738 QEvent::Type state;
743 739
744 if (pressed) state = QEvent::KeyPress; 740 if (pressed) state = QEvent::KeyPress;
745 else state = QEvent::KeyRelease; 741 else state = QEvent::KeyRelease;
746 742
747 QKeyEvent ke(state, k.qcode, k.unicode, 0, QString(QChar(k.unicode))); 743 QKeyEvent ke(state, k.qcode, k.unicode, 0, QString(QChar(k.unicode)));
748 744
749 // is this the best way to do this? cant figure out any other way to work 745 // is this the best way to do this? cant figure out any other way to work
750 QApplication::sendEvent((QObject *)m_curSession->widget(), &ke); 746 QApplication::sendEvent((QObject *)m_curSession->widget(), &ke);
751 ke.ignore(); 747 ke.ignore();
752 } 748 }
753} 749}
754void MainWindow::slotCopy() { 750void MainWindow::slotCopy() {
755 if (!currentSession() ) return; 751 if (!currentSession() ) return;
756 currentSession()->emulationHandler()->copy(); 752 currentSession()->emulationHandler()->copy();
757} 753}
758void MainWindow::slotPaste() { 754void MainWindow::slotPaste() {
759 if (!currentSession() ) return; 755 if (!currentSession() ) return;
760 currentSession()->emulationHandler()->paste(); 756 currentSession()->emulationHandler()->paste();
761} 757}
762 758
763/* 759/*
764 * Save the session 760 * Save the session
765 */ 761 */
766 762
767void MainWindow::slotSaveSession() { 763void MainWindow::slotSaveSession() {
768 if (!currentSession() ) { 764 if (!currentSession() ) {
769 QMessageBox::information(this, tr("Save Connection"), 765 QMessageBox::information(this, tr("Save Connection"),
770 tr("<qt>There is no Connection.</qt>"), 1 ); 766 tr("<qt>There is no Connection.</qt>"), 1 );
771 return; 767 return;
772 } 768 }
773 manager()->add( currentSession()->profile() ); 769 manager()->add( currentSession()->profile() );
774 manager()->save(); 770 manager()->save();
775 populateProfiles(); 771 populateProfiles();
776} 772}
777 773
778 774
779 775
780void MainWindow::slotSaveLog() { 776void MainWindow::slotSaveLog() {
781 777
782 if( currentSession()->emulationHandler()->isLogging() ) { 778 if( currentSession()->emulationHandler()->isLogging() ) {
783 DocLnk nf; 779 DocLnk nf;
784 QString m_logName = currentSession()->emulationHandler()->logFileName(); 780 QString m_logName = currentSession()->emulationHandler()->logFileName();
785 QFileInfo info(m_logName); 781 QFileInfo info(m_logName);
786 nf.setType("text/plain"); 782 nf.setType("text/plain");
787 nf.setFile(m_logName); 783 nf.setFile(m_logName);
788 nf.setName(info.fileName()); 784 nf.setName(info.fileName());
789 nf.writeLink(); 785 nf.writeLink();
790 m_recordLog->setText( tr("Start log") ); 786 m_recordLog->setText( tr("Start log") );
791 m_recordingLog = false; 787 m_recordingLog = false;
792 currentSession()->emulationHandler()->clearLog(); 788 currentSession()->emulationHandler()->clearLog();
793 } else { 789 } else {
794 QMap<QString, QStringList> map; 790 QMap<QString, QStringList> map;
795 QStringList text; 791 QStringList text;
796 text << "text/plain"; 792 text << "text/plain";
797 map.insert(tr("Log"), text ); 793 map.insert(tr("Log"), text );
798 Opie::Core::OConfig cfg("opie-console"); 794 Opie::Core::OConfig cfg("opie-console");
799 cfg.setGroup("defaults"); 795 cfg.setGroup("defaults");
800 QString startDir = cfg.readEntry("defaultlogdir", QPEApplication::documentDir() ); 796 QString startDir = cfg.readEntry("defaultlogdir", QPEApplication::documentDir() );
801 QString m_logName = OFileDialog::getSaveFileName(2, startDir, QString::null, map, 0, startDir); 797 QString m_logName = OFileDialog::getSaveFileName(2, startDir, QString::null, map, 0, startDir);
802 if (m_logName.isEmpty() ) return; 798 if (m_logName.isEmpty() ) return;
803 799
804 m_recordLog->setText( tr("Stop log") ); 800 m_recordLog->setText( tr("Stop log") );
805 m_recordingLog = true; 801 m_recordingLog = true;
806 currentSession()->emulationHandler()->startLogging(m_logName); 802 currentSession()->emulationHandler()->startLogging(m_logName);
807 } 803 }
808} 804}
809 805
810void MainWindow::slotSaveHistory() { 806void MainWindow::slotSaveHistory() {
811 QMap<QString, QStringList> map; 807 QMap<QString, QStringList> map;
812 QStringList text; 808 QStringList text;
813 text << "text/plain"; 809 text << "text/plain";
814 map.insert(tr("History"), text ); 810 map.insert(tr("History"), text );
815 QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map); 811 QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
816 if (filename.isEmpty() ) return; 812 if (filename.isEmpty() ) return;
817 813
818 QFileInfo info(filename); 814 QFileInfo info(filename);
819 815
820 DocLnk nf; 816 DocLnk nf;
821 nf.setType("text/plain"); 817 nf.setType("text/plain");
822 nf.setFile(filename); 818 nf.setFile(filename);
823 nf.setName(info.fileName()); 819 nf.setName(info.fileName());
824 820
825 821
826 QFile file(filename); 822 QFile file(filename);
827 if ( !file.open(IO_WriteOnly ) ) return; 823 if ( !file.open(IO_WriteOnly ) ) return;
828 824
829 QTextStream str(&file ); 825 QTextStream str(&file );
830 if ( currentSession() ) 826 if ( currentSession() )
831 currentSession()->emulationHandler()->emulation()->streamHistory(&str); 827 currentSession()->emulationHandler()->emulation()->streamHistory(&str);
832 828
833 file.close(); 829 file.close();
834 nf.writeLink(); 830 nf.writeLink();
835} 831}
diff --git a/noncore/apps/opie-reader/CFilter.cpp b/noncore/apps/opie-reader/CFilter.cpp
index 25cdfae..a4ea60a 100644
--- a/noncore/apps/opie-reader/CFilter.cpp
+++ b/noncore/apps/opie-reader/CFilter.cpp
@@ -1,861 +1,861 @@
1#include <qmap.h> 1#include <qmap.h>
2#include <qfileinfo.h> 2#include <qfileinfo.h>
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <qdir.h> 4#include <qdir.h>
5 5
6#ifdef USEQPE 6#ifdef USEQPE
7#include <qpe/global.h> 7#include <qpe/global.h>
8#endif 8#endif
9#include "CDrawBuffer.h" 9#include "CDrawBuffer.h"
10#include "CFilter.h" 10#include "CFilter.h"
11#include "hrule.h" 11#include "hrule.h"
12 12
13#include <qregexp.h> 13#include <qregexp.h>
14#include <qimage.h> 14#include <qimage.h>
15#include <qpixmap.h> 15#include <qpixmap.h>
16//#include <qprogressdialog.h> 16//#include <qprogressdialog.h>
17//#include <qapplication.h> 17//#include <qapplication.h>
18 18
19void textfmt::mygetch(tchar& ch, CStyle& sty, unsigned long& pos) 19void textfmt::mygetch(tchar& ch, CStyle& sty, unsigned long& pos)
20{ 20{
21 if (uselast) 21 if (uselast)
22 { 22 {
23 ch = lastchar; 23 ch = lastchar;
24 uselast = false; 24 uselast = false;
25 } 25 }
26 else 26 else
27 { 27 {
28 parent->getch(ch, sty, pos); 28 parent->getch(ch, sty, pos);
29 } 29 }
30} 30}
31 31
32void textfmt::getch(tchar& ch, CStyle& sty, unsigned long& pos) 32void textfmt::getch(tchar& ch, CStyle& sty, unsigned long& pos)
33{ 33{
34 mygetch(ch, sty, pos); 34 mygetch(ch, sty, pos);
35 do 35 do
36 { 36 {
37 sty = currentstyle; 37 sty = currentstyle;
38 switch (ch) 38 switch (ch)
39 { 39 {
40 case 10: 40 case 10:
41 currentstyle.unset(); 41 currentstyle.unset();
42 sty = currentstyle; 42 sty = currentstyle;
43 break; 43 break;
44// Use this if you want to replace -- by em-dash 44// Use this if you want to replace -- by em-dash
45 case '-': 45 case '-':
46 // parent->getch(ch, sty); 46 // parent->getch(ch, sty);
47 mygetch(ch, sty, pos); 47 mygetch(ch, sty, pos);
48 if (ch == '-') 48 if (ch == '-')
49 { 49 {
50 ch = 0x2014; 50 ch = 0x2014;
51 } 51 }
52 else 52 else
53 { 53 {
54 lastchar = ch; 54 lastchar = ch;
55 uselast = true; 55 uselast = true;
56 ch = '-'; 56 ch = '-';
57 } 57 }
58 break; 58 break;
59 case '*': 59 case '*':
60 if (currentstyle.isBold()) 60 if (currentstyle.isBold())
61 { 61 {
62// Already bold - time to turn it off? 62// Already bold - time to turn it off?
63// The next two lines ensure that * follows a character but it works better without 63// The next two lines ensure that * follows a character but it works better without
64 // QChar c(lastchar); 64 // QChar c(lastchar);
65 // if ((lastchar != '*') && (c.isPunct() || c.isLetterOrNumber())) 65 // if ((lastchar != '*') && (c.isPunct() || c.isLetterOrNumber()))
66 if (lastchar != '*') 66 if (lastchar != '*')
67 { 67 {
68 currentstyle.unsetBold(); 68 currentstyle.unsetBold();
69 CStyle dummy; 69 CStyle dummy;
70 // parent->getch(ch, dummy); 70 // parent->getch(ch, dummy);
71 mygetch(ch, dummy, pos); 71 mygetch(ch, dummy, pos);
72 } 72 }
73 } 73 }
74 else 74 else
75 { 75 {
76// not bold - time to turn it on? 76// not bold - time to turn it on?
77 CStyle dummy; 77 CStyle dummy;
78 // parent->getch(ch, dummy); 78 // parent->getch(ch, dummy);
79 mygetch(ch, dummy, pos); 79 mygetch(ch, dummy, pos);
80 QChar c(ch); 80 QChar c(ch);
81 if ((ch != '*') && (c.isPunct() || c.isLetterOrNumber())) 81 if ((ch != '*') && (c.isPunct() || c.isLetterOrNumber()))
82 { 82 {
83 currentstyle.setBold(); 83 currentstyle.setBold();
84 } 84 }
85 else 85 else
86 { 86 {
87 lastchar = ch; 87 lastchar = ch;
88 uselast = true; 88 uselast = true;
89 ch = '*'; 89 ch = '*';
90 } 90 }
91 91
92 } 92 }
93 break; 93 break;
94 case '_': 94 case '_':
95 if (currentstyle.isItalic()) 95 if (currentstyle.isItalic())
96 { 96 {
97// Already bold - time to turn it off? 97// Already bold - time to turn it off?
98// The next two lines ensure that * follows a character but it works better without 98// The next two lines ensure that * follows a character but it works better without
99 // QChar c(lastchar); 99 // QChar c(lastchar);
100 // if ((lastchar != '_') && (c.isPunct() || c.isLetterOrNumber())) 100 // if ((lastchar != '_') && (c.isPunct() || c.isLetterOrNumber()))
101 if (lastchar != '_') 101 if (lastchar != '_')
102 { 102 {
103 currentstyle.unsetItalic(); 103 currentstyle.unsetItalic();
104 CStyle dummy; 104 CStyle dummy;
105 // parent->getch(ch, dummy); 105 // parent->getch(ch, dummy);
106 mygetch(ch, dummy, pos); 106 mygetch(ch, dummy, pos);
107 } 107 }
108 } 108 }
109 else 109 else
110 { 110 {
111// not bold - time to turn it on? 111// not bold - time to turn it on?
112 CStyle dummy; 112 CStyle dummy;
113 // parent->getch(ch, dummy); 113 // parent->getch(ch, dummy);
114 mygetch(ch, dummy, pos); 114 mygetch(ch, dummy, pos);
115 QChar c(ch); 115 QChar c(ch);
116 if ((ch != '_') && (c.isPunct() || c.isLetterOrNumber())) 116 if ((ch != '_') && (c.isPunct() || c.isLetterOrNumber()))
117 { 117 {
118 currentstyle.setItalic(); 118 currentstyle.setItalic();
119 } 119 }
120 else 120 else
121 { 121 {
122 lastchar = ch; 122 lastchar = ch;
123 uselast = true; 123 uselast = true;
124 ch = '_'; 124 ch = '_';
125 } 125 }
126 126
127 } 127 }
128 break; 128 break;
129 } 129 }
130 } 130 }
131 while (sty != currentstyle); 131 while (sty != currentstyle);
132 if (!uselast) lastchar = ch; 132 if (!uselast) lastchar = ch;
133 return; 133 return;
134} 134}
135 135
136void remap::getch(tchar& ch, CStyle& sty, unsigned long& pos) 136void remap::getch(tchar& ch, CStyle& sty, unsigned long& pos)
137{ 137{
138 if (q[offset] != 0) 138 if (q[offset] != 0)
139 { 139 {
140 q[offset++]; 140 q[offset++];
141 sty = currentstyle; 141 sty = currentstyle;
142 return; 142 return;
143 } 143 }
144 parent->getch(ch, sty, pos); 144 parent->getch(ch, sty, pos);
145 switch (ch) 145 switch (ch)
146 { 146 {
147 case 0x201a: 147 case 0x201a:
148 ch = '\''; 148 ch = '\'';
149 break; 149 break;
150 case 0x0192: 150 case 0x0192:
151 ch = 'f'; 151 ch = 'f';
152 break; 152 break;
153 case 0x201e: 153 case 0x201e:
154 ch = '"'; 154 ch = '"';
155 break; 155 break;
156 case 0x2026: 156 case 0x2026:
157 offset = 0; 157 offset = 0;
158 q[0] = '.'; 158 q[0] = '.';
159 q[1] = '.'; 159 q[1] = '.';
160 q[2] = 0; 160 q[2] = 0;
161 ch = '.'; // should be ... 161 ch = '.'; // should be ...
162 break; 162 break;
163 case 0x0160: 163 case 0x0160:
164 ch = 'S'; 164 ch = 'S';
165 break; 165 break;
166 case 0x2039: 166 case 0x2039:
167 ch = '<'; 167 ch = '<';
168 break; 168 break;
169 case 0x0152: 169 case 0x0152:
170 offset = 0; 170 offset = 0;
171 q[0] = 'E'; 171 q[0] = 'E';
172 q[1] = 0; 172 q[1] = 0;
173 ch = 'O'; 173 ch = 'O';
174 break; 174 break;
175 case 0x017d: 175 case 0x017d:
176 ch = 'Z'; 176 ch = 'Z';
177 break; 177 break;
178 case 0x2018: 178 case 0x2018:
179 ch = '\''; 179 ch = '\'';
180 break; 180 break;
181 case 0x2019: 181 case 0x2019:
182 ch = '\''; 182 ch = '\'';
183 break; 183 break;
184 case 0x201c: 184 case 0x201c:
185 ch = '"'; 185 ch = '"';
186 break; 186 break;
187 case 0x201d: 187 case 0x201d:
188 ch = '"'; 188 ch = '"';
189 break; 189 break;
190 case 0x2022: 190 case 0x2022:
191 ch = '>'; 191 ch = '>';
192 break; 192 break;
193 case 0x2013: 193 case 0x2013:
194 ch = '-'; 194 ch = '-';
195 break; 195 break;
196 case 0x2014: 196 case 0x2014:
197 offset = 0; 197 offset = 0;
198 q[0] = '-'; 198 q[0] = '-';
199 q[1] = 0; 199 q[1] = 0;
200 ch = '-'; // should be -- 200 ch = '-'; // should be --
201 break; 201 break;
202 case 0x02dc: 202 case 0x02dc:
203 ch = '~'; 203 ch = '~';
204 break; 204 break;
205 case 0x0161: 205 case 0x0161:
206 ch = 's'; 206 ch = 's';
207 break; 207 break;
208 case 0x203a: 208 case 0x203a:
209 ch = '>'; 209 ch = '>';
210 break; 210 break;
211 case 0x0153: 211 case 0x0153:
212 offset = 0; 212 offset = 0;
213 q[0] = 'e'; 213 q[0] = 'e';
214 q[1] = 0; 214 q[1] = 0;
215 ch = 'o';// should be oe 215 ch = 'o';// should be oe
216 break; 216 break;
217 /* 217 /*
218 case 0x0009: // tab 218 case 0x0009: // tab
219 offset = 0; 219 offset = 0;
220 q[0] = ' '; 220 q[0] = ' ';
221 q[1] = 0; 221 q[1] = 0;
222 ch = ' '; 222 ch = ' ';
223 break; 223 break;
224 */ 224 */
225 case 0x017e: 225 case 0x017e:
226 ch = 'z'; 226 ch = 'z';
227 break; 227 break;
228 case 0x0178: 228 case 0x0178:
229 ch = 'Y'; 229 ch = 'Y';
230 break; 230 break;
231 } 231 }
232 currentstyle = sty; 232 currentstyle = sty;
233} 233}
234 234
235void PeanutFormatter::getch(tchar& ch, CStyle& sty, unsigned long& pos) 235void PeanutFormatter::getch(tchar& ch, CStyle& sty, unsigned long& pos)
236{ 236{
237 CStyle dummy; 237 CStyle dummy;
238 currentstyle.setColour(0,0,0); 238 currentstyle.setColour(0,0,0);
239 parent->getch(ch, dummy, pos); 239 parent->getch(ch, dummy, pos);
240 while (ch == '\\') 240 while (ch == '\\')
241 { 241 {
242 parent->getch(ch, dummy, pos); 242 parent->getch(ch, dummy, pos);
243 if (ch == '\\') break; 243 if (ch == '\\') break;
244 switch(ch) 244 switch(ch)
245 { 245 {
246 case 'a': 246 case 'a':
247 { 247 {
248 int code = 0; 248 int code = 0;
249 for (int i = 0; i < 3; i++) 249 for (int i = 0; i < 3; i++)
250 { 250 {
251 parent->getch(ch, dummy, pos); 251 parent->getch(ch, dummy, pos);
252 code = 10*code + ch - '0'; 252 code = 10*code + ch - '0';
253 } 253 }
254 ch = code; 254 ch = code;
255 } 255 }
256 break; 256 break;
257 case 'v': 257 case 'v':
258 { 258 {
259 while (1) 259 while (1)
260 { 260 {
261 parent->getch(ch, dummy, pos); 261 parent->getch(ch, dummy, pos);
262 if (ch == '\\') 262 if (ch == '\\')
263 { 263 {
264 parent->getch(ch, dummy, pos); 264 parent->getch(ch, dummy, pos);
265 if (ch == 'v') 265 if (ch == 'v')
266 { 266 {
267 parent->getch(ch, dummy, pos); 267 parent->getch(ch, dummy, pos);
268 break; 268 break;
269 } 269 }
270 } 270 }
271 } 271 }
272 } 272 }
273 break; 273 break;
274 case 's': 274 case 's':
275 case 'n': 275 case 'n':
276 currentstyle.setFontSize(0); 276 currentstyle.setFontSize(0);
277 parent->getch(ch,dummy, pos); 277 parent->getch(ch,dummy, pos);
278 break; 278 break;
279 case 'p': 279 case 'p':
280 currentstyle.unset(); 280 currentstyle.unset();
281 // parent->getch(ch,dummy); 281 // parent->getch(ch,dummy);
282 ch = 10; 282 ch = 10;
283 break; 283 break;
284 case 'l': 284 case 'l':
285 if (currentstyle.getFontSize() == 1) 285 if (currentstyle.getFontSize() == 1)
286 { 286 {
287 currentstyle.setFontSize(0); 287 currentstyle.setFontSize(0);
288 } 288 }
289 else 289 else
290 { 290 {
291 currentstyle.setFontSize(1); 291 currentstyle.setFontSize(1);
292 } 292 }
293 parent->getch(ch, dummy, pos); 293 parent->getch(ch, dummy, pos);
294 break; 294 break;
295 case 'x': 295 case 'x':
296 if (currentstyle.getFontSize() == 0) 296 if (currentstyle.getFontSize() == 0)
297 { 297 {
298 // currentstyle.unset(); 298 // currentstyle.unset();
299 // currentstyle.setBold(); 299 // currentstyle.setBold();
300 currentstyle.setFontSize(1); 300 currentstyle.setFontSize(1);
301 } 301 }
302 else 302 else
303 { 303 {
304 currentstyle.unset(); 304 currentstyle.unset();
305 } 305 }
306 // parent->getch(ch, dummy); 306 // parent->getch(ch, dummy);
307 ch = 10; 307 ch = 10;
308 break; 308 break;
309 case 'i': 309 case 'i':
310 if (currentstyle.isItalic()) 310 if (currentstyle.isItalic())
311 { 311 {
312 currentstyle.unsetItalic(); 312 currentstyle.unsetItalic();
313 } 313 }
314 else 314 else
315 { 315 {
316 currentstyle.setItalic(); 316 currentstyle.setItalic();
317 } 317 }
318 parent->getch(ch, dummy, pos); 318 parent->getch(ch, dummy, pos);
319 break; 319 break;
320 case 'b': 320 case 'b':
321 case 'B': 321 case 'B':
322 if (currentstyle.isBold()) 322 if (currentstyle.isBold())
323 { 323 {
324 currentstyle.unsetBold(); 324 currentstyle.unsetBold();
325 } 325 }
326 else 326 else
327 { 327 {
328 currentstyle.setBold(); 328 currentstyle.setBold();
329 } 329 }
330 parent->getch(ch, dummy, pos); 330 parent->getch(ch, dummy, pos);
331 break; 331 break;
332 case 'c': 332 case 'c':
333 if (currentstyle.getJustify() == m_AlignCentre) 333 if (currentstyle.getJustify() == m_AlignCentre)
334 { 334 {
335 currentstyle.setLeftJustify(); 335 currentstyle.setLeftJustify();
336 } 336 }
337 else 337 else
338 { 338 {
339 currentstyle.setCentreJustify(); 339 currentstyle.setCentreJustify();
340 } 340 }
341 parent->getch(ch, dummy, pos); 341 parent->getch(ch, dummy, pos);
342 break; 342 break;
343 case 'r': 343 case 'r':
344 if (currentstyle.getJustify() == m_AlignRight) 344 if (currentstyle.getJustify() == m_AlignRight)
345 { 345 {
346 currentstyle.setLeftJustify(); 346 currentstyle.setLeftJustify();
347 } 347 }
348 else 348 else
349 { 349 {
350 currentstyle.setRightJustify(); 350 currentstyle.setRightJustify();
351 } 351 }
352 parent->getch(ch, dummy, pos); 352 parent->getch(ch, dummy, pos);
353 break; 353 break;
354 default: 354 default:
355 currentstyle.setColour(255,0,0); 355 currentstyle.setColour(255,0,0);
356 } 356 }
357 } 357 }
358 sty = currentstyle; 358 sty = currentstyle;
359} 359}
360 360
361void OnePara::getch(tchar& ch, CStyle& sty, unsigned long& pos) 361void OnePara::getch(tchar& ch, CStyle& sty, unsigned long& pos)
362{ 362{
363 parent->getch(ch, sty, pos); 363 parent->getch(ch, sty, pos);
364 if (m_lastchar == 10) 364 if (m_lastchar == 10)
365 { 365 {
366 while (ch == 10) parent->getch(ch, sty, pos); 366 while (ch == 10) parent->getch(ch, sty, pos);
367 } 367 }
368 m_lastchar = ch; 368 m_lastchar = ch;
369} 369}
370 370
371void repalm::getch(tchar& ch, CStyle& sty, unsigned long& pos) 371void repalm::getch(tchar& ch, CStyle& sty, unsigned long& pos)
372{ 372{
373 parent->getch(ch, sty, pos); 373 parent->getch(ch, sty, pos);
374 switch (ch) 374 switch (ch)
375 { 375 {
376 case 0x80: 376 case 0x80:
377 ch = 0x20ac; 377 ch = 0x20ac;
378 break; 378 break;
379 case 0x82: 379 case 0x82:
380 ch = 0x201a; 380 ch = 0x201a;
381 break; 381 break;
382 case 0x83: 382 case 0x83:
383 ch = 0x0192; 383 ch = 0x0192;
384 break; 384 break;
385 case 0x84: 385 case 0x84:
386 ch = 0x201e; 386 ch = 0x201e;
387 break; 387 break;
388 case 0x85: 388 case 0x85:
389 ch = 0x2026; 389 ch = 0x2026;
390 break; 390 break;
391 case 0x86: 391 case 0x86:
392 ch = 0x2020; 392 ch = 0x2020;
393 break; 393 break;
394 case 0x87: 394 case 0x87:
395 ch = 0x2021; 395 ch = 0x2021;
396 break; 396 break;
397 case 0x88: 397 case 0x88:
398 ch = 0x02c6; 398 ch = 0x02c6;
399 break; 399 break;
400 case 0x89: 400 case 0x89:
401 ch = 0x2030; 401 ch = 0x2030;
402 break; 402 break;
403 case 0x8a: 403 case 0x8a:
404 ch = 0x0160; 404 ch = 0x0160;
405 break; 405 break;
406 case 0x8b: 406 case 0x8b:
407 ch = 0x2039; 407 ch = 0x2039;
408 break; 408 break;
409 case 0x8c: 409 case 0x8c:
410 ch = 0x0152; 410 ch = 0x0152;
411 break; 411 break;
412/* 412/*
413 case 0x8e: 413 case 0x8e:
414 ch = 0x017d; 414 ch = 0x017d;
415 break; 415 break;
416*/ 416*/
417 case 0x91: 417 case 0x91:
418 ch = 0x2018; 418 ch = 0x2018;
419 break; 419 break;
420 case 0x92: 420 case 0x92:
421 ch = 0x2019; 421 ch = 0x2019;
422 break; 422 break;
423 case 0x93: 423 case 0x93:
424 ch = 0x201c; 424 ch = 0x201c;
425 break; 425 break;
426 case 0x94: 426 case 0x94:
427 ch = 0x201d; 427 ch = 0x201d;
428 break; 428 break;
429 case 0x95: 429 case 0x95:
430 ch = 0x2022; 430 ch = 0x2022;
431 break; 431 break;
432 case 0x96: 432 case 0x96:
433 ch = 0x2013; 433 ch = 0x2013;
434 break; 434 break;
435 case 0x97: 435 case 0x97:
436 ch = 0x2014; 436 ch = 0x2014;
437 break; 437 break;
438 case 0x98: 438 case 0x98:
439 ch = 0x02dc; 439 ch = 0x02dc;
440 break; 440 break;
441 case 0x99: 441 case 0x99:
442 ch = 0x2122; 442 ch = 0x2122;
443 break; 443 break;
444 case 0x9a: 444 case 0x9a:
445 ch = 0x0161; 445 ch = 0x0161;
446 break; 446 break;
447 case 0x9b: 447 case 0x9b:
448 ch = 0x203a; 448 ch = 0x203a;
449 break; 449 break;
450 case 0x9c: 450 case 0x9c:
451 ch = 0x0153; 451 ch = 0x0153;
452 break; 452 break;
453 case 0x9e: 453 case 0x9e:
454 ch = 0x017e; 454 ch = 0x017e;
455 break; 455 break;
456 case 0x9f: 456 case 0x9f:
457 ch = 0x0178; 457 ch = 0x0178;
458 break; 458 break;
459 case 0x18: 459 case 0x18:
460 ch = 0x2026; 460 ch = 0x2026;
461 break; 461 break;
462 case 0x19: 462 case 0x19:
463 ch = 0x2007; 463 ch = 0x2007;
464 break; 464 break;
465 case 0x8d: 465 case 0x8d:
466 ch = 0x2662; 466 ch = 0x2662;
467 break; 467 break;
468 case 0x8e: 468 case 0x8e:
469 ch = 0x2663; 469 ch = 0x2663;
470 break; 470 break;
471 case 0x8f: 471 case 0x8f:
472 ch = 0x2661; 472 ch = 0x2661;
473 break; 473 break;
474 case 0x90: 474 case 0x90:
475 ch = 0x2660; 475 ch = 0x2660;
476 break; 476 break;
477 default: 477 default:
478 break; 478 break;
479 } 479 }
480} 480}
481 481
482//static tchar nextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 }; 482//static tchar nextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 };
483//static tchar prevpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','p','r','e','v','i','o','u','s',' ','p','a','r','t',0 }; 483//static tchar prevpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','p','r','e','v','i','o','u','s',' ','p','a','r','t',0 };
484 484
485void DePluck::getch(tchar& ch, CStyle& sty, unsigned long& pos) 485void DePluck::getch(tchar& ch, CStyle& sty, unsigned long& pos)
486{ 486{
487 if (m_buffed > 0) 487 if (m_buffed > 0)
488 { 488 {
489 sty = m_laststyle; 489 sty = m_laststyle;
490 ch = nextpart[m_current++]; 490 ch = nextpart[m_current++];
491 if (m_current == m_buffed) 491 if (m_current == m_buffed)
492 { 492 {
493 m_current = m_buffed = 0; 493 m_current = m_buffed = 0;
494 } 494 }
495 } 495 }
496 else 496 else
497 { 497 {
498 if (m_buffer != 0) 498 if (m_buffer != 0)
499 { 499 {
500 ch = m_buffer; 500 ch = m_buffer;
501 m_buffer = 0; 501 m_buffer = 0;
502 return; 502 return;
503 } 503 }
504 unsigned long lnk, lnkoff; 504 unsigned long lnk = 0, lnkoff = 0;
505 do 505 do
506 { 506 {
507 if (nextpart[m_buffed] == 0) break; 507 if (nextpart[m_buffed] == 0) break;
508 parent->getch(ch, sty, pos); 508 parent->getch(ch, sty, pos);
509 m_laststyle = sty; 509 m_laststyle = sty;
510 if (sty.getLink()) 510 if (sty.getLink())
511 { 511 {
512 lnk = sty.getData(); 512 lnk = sty.getData();
513 lnkoff = sty.getOffset(); 513 lnkoff = sty.getOffset();
514 } 514 }
515 } while (ch == nextpart[m_buffed] && sty.getLink() && ++m_buffed); 515 } while (ch == nextpart[m_buffed] && sty.getLink() && ++m_buffed);
516 m_current = 0; 516 m_current = 0;
517 if (nextpart[m_buffed] == 0) 517 if (nextpart[m_buffed] == 0)
518 { 518 {
519 m_buffed = 0; 519 m_buffed = 0;
520 QString dmy, dmy2; 520 QString dmy, dmy2;
521 parent->hyperlink(lnk, lnkoff, dmy, dmy2); 521 parent->hyperlink(lnk, lnkoff, dmy, dmy2);
522 do 522 do
523 { 523 {
524 parent->getch(ch, sty, pos); 524 parent->getch(ch, sty, pos);
525 } 525 }
526 while (ch != 10); 526 while (ch != 10);
527 parent->getch(ch, sty, pos); 527 parent->getch(ch, sty, pos);
528 } 528 }
529 else if (m_buffed > 0) 529 else if (m_buffed > 0)
530 { 530 {
531 m_buffer = ch; 531 m_buffer = ch;
532 ch = nextpart[0]; 532 ch = nextpart[0];
533 if (m_buffed == 1) 533 if (m_buffed == 1)
534 { 534 {
535 m_buffed = 0; 535 m_buffed = 0;
536 } 536 }
537 else m_current = 1; 537 else m_current = 1;
538 } 538 }
539 } 539 }
540 540
541 return; 541 return;
542} 542}
543 543
544HighlightFilter::HighlightFilter(QTReader* _p) : pReader(_p), lastpos(0), nextpos(0), red(255), green(255), blue(255) 544HighlightFilter::HighlightFilter(QTReader* _p) : pReader(_p), lastpos(0), nextpos(0), red(255), green(255), blue(255)
545{ 545{
546} 546}
547 547
548#include "Bkmks.h" 548#include "Bkmks.h"
549#include "QTReader.h" 549#include "QTReader.h"
550 550
551void HighlightFilter::refresh(unsigned long pos) 551void HighlightFilter::refresh(unsigned long pos)
552{ 552{
553 bkmks = pReader->Bkmklist(); 553 bkmks = pReader->Bkmklist();
554 554
555 red = green = blue = 255; 555 red = green = blue = 255;
556 556
557 if (bkmks == NULL) 557 if (bkmks == NULL)
558 { 558 {
559 lastpos = 0; 559 lastpos = 0;
560 nextpos = 0xffffffff; 560 nextpos = 0xffffffff;
561 } 561 }
562 else 562 else
563 { 563 {
564 lastpos = 0; 564 lastpos = 0;
565 nextpos = 0xffffffff; 565 nextpos = 0xffffffff;
566 for (CList<Bkmk>::iterator i = bkmks->begin(); i != bkmks->end(); i++) 566 for (CList<Bkmk>::iterator i = bkmks->begin(); i != bkmks->end(); i++)
567 { 567 {
568 if ((*i).value() <= pos && pos < (*i).value2()) 568 if ((*i).value() <= pos && pos < (*i).value2())
569 { 569 {
570 red = i->red(); 570 red = i->red();
571 green = i->green(); 571 green = i->green();
572 blue = i->blue(); 572 blue = i->blue();
573 lastpos = (*i).value(); 573 lastpos = (*i).value();
574 nextpos = (*i).value2(); 574 nextpos = (*i).value2();
575 break; 575 break;
576 } 576 }
577 if ((*i).value() > pos) 577 if ((*i).value() > pos)
578 { 578 {
579 nextpos = (*i).value(); 579 nextpos = (*i).value();
580 break; 580 break;
581 } 581 }
582 lastpos = (*i).value(); 582 lastpos = (*i).value();
583 } 583 }
584 } 584 }
585} 585}
586 586
587void HighlightFilter::getch(tchar& ch, CStyle& sty, unsigned long& pos) 587void HighlightFilter::getch(tchar& ch, CStyle& sty, unsigned long& pos)
588{ 588{
589 parent->getch(ch, sty, pos); 589 parent->getch(ch, sty, pos);
590 if (bkmks != pReader->Bkmklist() || pos <= lastpos || pos >= nextpos) 590 if (bkmks != pReader->Bkmklist() || pos <= lastpos || pos >= nextpos)
591 { 591 {
592 // qDebug("Recalc <%lu, %lu, %lu>", lastpos, pos, nextpos); 592 // qDebug("Recalc <%lu, %lu, %lu>", lastpos, pos, nextpos);
593 refresh(pos); 593 refresh(pos);
594 // qDebug("Recalc(2) <%lu, %lu, %lu>", lastpos, pos, nextpos); 594 // qDebug("Recalc(2) <%lu, %lu, %lu>", lastpos, pos, nextpos);
595 } 595 }
596 int r = sty.bRed(), g = sty.bGreen(), b = sty.bBlue(); 596 int r = sty.bRed(), g = sty.bGreen(), b = sty.bBlue();
597 if (r == 255 && g == 255 && b == 255) 597 if (r == 255 && g == 255 && b == 255)
598 { 598 {
599 sty.setBackground(red, green, blue); 599 sty.setBackground(red, green, blue);
600 } 600 }
601} 601}
602 602
603void kern::getch(tchar& ch, CStyle& sty, unsigned long& pos) 603void kern::getch(tchar& ch, CStyle& sty, unsigned long& pos)
604{ 604{
605 if (uselast) 605 if (uselast)
606 { 606 {
607 ch = lastchar; 607 ch = lastchar;
608 sty = laststy; 608 sty = laststy;
609 uselast = false; 609 uselast = false;
610 return; 610 return;
611 } 611 }
612 else 612 else
613 { 613 {
614 parent->getch(ch, sty, pos); 614 parent->getch(ch, sty, pos);
615 } 615 }
616 switch (ch) 616 switch (ch)
617 { 617 {
618 case 'f': 618 case 'f':
619 { 619 {
620 tchar savedchar = 'f'; 620 tchar savedchar = 'f';
621 parent->getch(ch, sty, pos); 621 parent->getch(ch, sty, pos);
622 switch (ch) 622 switch (ch)
623 { 623 {
624 case 'i': 624 case 'i':
625 ch = (251 << 8) + 1; 625 ch = (251 << 8) + 1;
626 break; 626 break;
627 case 'l': 627 case 'l':
628 ch = (251 << 8) + 2; 628 ch = (251 << 8) + 2;
629 break; 629 break;
630 default: 630 default:
631 lastchar = ch; 631 lastchar = ch;
632 uselast = true; 632 uselast = true;
633 laststy = sty; 633 laststy = sty;
634 ch = savedchar; 634 ch = savedchar;
635 } 635 }
636 } 636 }
637 break; 637 break;
638 default: 638 default:
639 break; 639 break;
640 } 640 }
641} 641}
642 642
643class ErrorFilter : public CFilter 643class ErrorFilter : public CFilter
644{ 644{
645 QString error; 645 QString error;
646 int currentpos; 646 int currentpos;
647 public: 647 public:
648 ErrorFilter(const QString& _s) : error(_s), currentpos(0) {} 648 ErrorFilter(const QString& _s) : error(_s), currentpos(0) {}
649 ~ErrorFilter() {} 649 ~ErrorFilter() {}
650 void getch(tchar& ch, CStyle& sty, unsigned long& pos) 650 void getch(tchar& ch, CStyle& sty, unsigned long& pos)
651 { 651 {
652 if (currentpos == error.length()) 652 if (currentpos == error.length())
653 { 653 {
654 ch = UEOF; 654 ch = UEOF;
655 currentpos = 0; 655 currentpos = 0;
656 } 656 }
657 else 657 else
658 { 658 {
659 ch = error[currentpos++].unicode(); 659 ch = error[currentpos++].unicode();
660 } 660 }
661 } 661 }
662 QString about() { return parent->about(); } 662 QString about() { return parent->about(); }
663}; 663};
664 664
665#ifndef __STATIC 665#ifndef __STATIC
666ExternFilter::ExternFilter(const QString& nm, const QString& optional) : filt(NULL), handle(NULL) 666ExternFilter::ExternFilter(const QString& nm, const QString& optional) : filt(NULL), handle(NULL)
667{ 667{
668#ifdef USEQPE 668#ifdef USEQPE
669#ifdef OPIE 669#ifdef OPIE
670 QString filterpath(getenv("OPIEDIR")); 670 QString filterpath(getenv("OPIEDIR"));
671#else 671#else
672 QString filterpath(getenv("QTDIR")); 672 QString filterpath(getenv("QTDIR"));
673#endif 673#endif
674 filterpath += "/plugins/reader/filters/lib"; 674 filterpath += "/plugins/reader/filters/lib";
675#else 675#else
676 QString filterpath(getenv("READERDIR")); 676 QString filterpath(getenv("READERDIR"));
677 filterpath += "/filters/lib"; 677 filterpath += "/filters/lib";
678#endif 678#endif
679 filterpath += nm; 679 filterpath += nm;
680 filterpath += ".so"; 680 filterpath += ".so";
681 if (QFile::exists(filterpath)) 681 if (QFile::exists(filterpath))
682 { 682 {
683 qDebug("Filter:%s", (const char*)filterpath); 683 qDebug("Filter:%s", (const char*)filterpath);
684 handle = dlopen(filterpath, RTLD_LAZY); 684 handle = dlopen(filterpath, RTLD_LAZY);
685 if (handle == 0) 685 if (handle == 0)
686 { 686 {
687 qDebug("Can't find filter:%s", dlerror()); 687 qDebug("Can't find filter:%s", dlerror());
688 // status = -10; 688 // status = -10;
689 filt = new ErrorFilter(QString("Can't find plugin:")+nm); 689 filt = new ErrorFilter(QString("Can't find plugin:")+nm);
690 return; 690 return;
691 } 691 }
692 CFilter* (*newfilter)(const QString&); 692 CFilter* (*newfilter)(const QString&);
693 newfilter = (CFilter* (*)(const QString&))dlsym(handle, "newfilter"); 693 newfilter = (CFilter* (*)(const QString&))dlsym(handle, "newfilter");
694 if (newfilter == NULL) 694 if (newfilter == NULL)
695 { 695 {
696 qDebug("Can't find newfilter"); 696 qDebug("Can't find newfilter");
697 filt = new ErrorFilter(QString("Can't find entry point in plugin:")+nm); 697 filt = new ErrorFilter(QString("Can't find entry point in plugin:")+nm);
698 return; 698 return;
699 } 699 }
700 filt = (*newfilter)(optional); 700 filt = (*newfilter)(optional);
701 } 701 }
702 else 702 else
703 { 703 {
704 qDebug("No filter path:%s", (const char*)filterpath); 704 qDebug("No filter path:%s", (const char*)filterpath);
705 filt = new ErrorFilter(QString("No filter plugins installed:")+nm); 705 filt = new ErrorFilter(QString("No filter plugins installed:")+nm);
706 } 706 }
707 if (filt == NULL) 707 if (filt == NULL)
708 { 708 {
709 qDebug("Can't do newfilter"); 709 qDebug("Can't do newfilter");
710 filt = new ErrorFilter(QString("Filter creation failed:")+nm); 710 filt = new ErrorFilter(QString("Filter creation failed:")+nm);
711 return; 711 return;
712 } 712 }
713} 713}
714#endif 714#endif
715 715
716void makeInverse::getch(tchar& ch, CStyle& sty, unsigned long& pos) 716void makeInverse::getch(tchar& ch, CStyle& sty, unsigned long& pos)
717{ 717{
718 parent->getch(ch, sty, pos); 718 parent->getch(ch, sty, pos);
719 int r,g,b; 719 int r,g,b;
720 r = 255 - sty.Red(), g = 255 - sty.Green(), b = 255 - sty.Blue(); 720 r = 255 - sty.Red(), g = 255 - sty.Green(), b = 255 - sty.Blue();
721 sty.setColour(r,g,b); 721 sty.setColour(r,g,b);
722 r = 255 - sty.bRed(), g = 255 - sty.bGreen(), b = 255 - sty.bBlue(); 722 r = 255 - sty.bRed(), g = 255 - sty.bGreen(), b = 255 - sty.bBlue();
723 sty.setBackground(r,g,b); 723 sty.setBackground(r,g,b);
724 r = 255 - sty.pRed(), g = 255 - sty.pGreen(), b = 255 - sty.pBlue(); 724 r = 255 - sty.pRed(), g = 255 - sty.pGreen(), b = 255 - sty.pBlue();
725 sty.setPaper(r,g,b); 725 sty.setPaper(r,g,b);
726} 726}
727/* 727/*
728void makeNegative::getch(tchar& ch, CStyle& sty, unsigned long& pos) 728void makeNegative::getch(tchar& ch, CStyle& sty, unsigned long& pos)
729{ 729{
730 parent->getch(ch, sty, pos); 730 parent->getch(ch, sty, pos);
731 QColor fg(sty.Red(), sty.Green(), sty.Blue()); 731 QColor fg(sty.Red(), sty.Green(), sty.Blue());
732 int h,s,v; 732 int h,s,v;
733 fg.hsv(&h,&s,&v); 733 fg.hsv(&h,&s,&v);
734 fg.setHsv(h,s,255-v); 734 fg.setHsv(h,s,255-v);
735 int r,g,b; 735 int r,g,b;
736 fg.rgb(&r,&g,&b); 736 fg.rgb(&r,&g,&b);
737 sty.setColour(r,g,b); 737 sty.setColour(r,g,b);
738 738
739 fg = QColor(sty.bRed(), sty.bGreen(), sty.bBlue()); 739 fg = QColor(sty.bRed(), sty.bGreen(), sty.bBlue());
740 fg.hsv(&h,&s,&v); 740 fg.hsv(&h,&s,&v);
741 fg.setHsv(h,s,255-v); 741 fg.setHsv(h,s,255-v);
742 fg.rgb(&r,&g,&b); 742 fg.rgb(&r,&g,&b);
743 sty.setBackground(r,g,b); 743 sty.setBackground(r,g,b);
744} 744}
745*/ 745*/
746void setbg::getch(tchar& ch, CStyle& sty, unsigned long& pos) 746void setbg::getch(tchar& ch, CStyle& sty, unsigned long& pos)
747{ 747{
748 parent->getch(ch, sty, pos); 748 parent->getch(ch, sty, pos);
749 int r = sty.pRed(), g = sty.pGreen(), b = sty.pBlue(); 749 int r = sty.pRed(), g = sty.pGreen(), b = sty.pBlue();
750 if (r == 255 && g == 255 && b == 255) 750 if (r == 255 && g == 255 && b == 255)
751 { 751 {
752 sty.setPaper(m_r,m_g,m_b); 752 sty.setPaper(m_r,m_g,m_b);
753 } 753 }
754 else 754 else
755 { 755 {
756 qDebug("We have background [%x%x%x]", r, g, b); 756 qDebug("We have background [%x%x%x]", r, g, b);
757 } 757 }
758 r = sty.bRed(), g = sty.bGreen(), b = sty.bBlue(); 758 r = sty.bRed(), g = sty.bGreen(), b = sty.bBlue();
759 if (r == 255 && g == 255 && b == 255) 759 if (r == 255 && g == 255 && b == 255)
760 { 760 {
761 sty.setBackground(m_r,m_g,m_b); 761 sty.setBackground(m_r,m_g,m_b);
762 } 762 }
763 else 763 else
764 { 764 {
765 qDebug("We have background [%x%x%x]", r, g, b); 765 qDebug("We have background [%x%x%x]", r, g, b);
766 } 766 }
767} 767}
768 768
769void setfg::getch(tchar& ch, CStyle& sty, unsigned long& pos) 769void setfg::getch(tchar& ch, CStyle& sty, unsigned long& pos)
770{ 770{
771 parent->getch(ch, sty, pos); 771 parent->getch(ch, sty, pos);
772 int r = sty.Red(), g = sty.Green(), b = sty.Blue(); 772 int r = sty.Red(), g = sty.Green(), b = sty.Blue();
773 if (r == 0 && g == 0 && b == 0) 773 if (r == 0 && g == 0 && b == 0)
774 { 774 {
775 sty.setColour(m_r,m_g,m_b); 775 sty.setColour(m_r,m_g,m_b);
776 } 776 }
777} 777}
778 778
779#include "CRegExp.h" 779#include "CRegExp.h"
780 780
781repara::repara(const QString& pat) : tch(0) 781repara::repara(const QString& pat) : tch(0)
782{ 782{
783 // QString pat("{\\n[A-Z\"]}"); 783 // QString pat("{\\n[A-Z\"]}");
784 flt = new CRegExpFilt(pat, false); 784 flt = new CRegExpFilt(pat, false);
785 qDebug("Construction done"); 785 qDebug("Construction done");
786} 786}
787 787
788repara::~repara() 788repara::~repara()
789{ 789{
790 delete flt; 790 delete flt;
791} 791}
792 792
793void repara::getch(tchar& ch, CStyle& sty, unsigned long& pos) 793void repara::getch(tchar& ch, CStyle& sty, unsigned long& pos)
794{ 794{
795 if (flt->empty()) 795 if (flt->empty())
796 { 796 {
797 while (flt->empty()) 797 while (flt->empty())
798 { 798 {
799 parent->getch(ch, sty, pos); 799 parent->getch(ch, sty, pos);
800 flt->addch(ch); 800 flt->addch(ch);
801 } 801 }
802 } 802 }
803 ch = flt->pop(); 803 ch = flt->pop();
804 /* 804 /*
805 parent->getch(ch, sty, pos); 805 parent->getch(ch, sty, pos);
806 if (ch == 10 || ch == ' ') 806 if (ch == 10 || ch == ' ')
807 { 807 {
808 if (tch == 10) 808 if (tch == 10)
809 { 809 {
810 tch = ch; 810 tch = ch;
811 ch = 10; 811 ch = 10;
812 return; 812 return;
813 } 813 }
814 else 814 else
815 { 815 {
816 tch = ch; 816 tch = ch;
817 ch = ' '; 817 ch = ' ';
818 return; 818 return;
819 } 819 }
820 } 820 }
821 tch = ch; 821 tch = ch;
822 */ 822 */
823 return; 823 return;
824} 824}
825 825
826void tableLink::getch(tchar& ch, CStyle& sty, unsigned long& pos) 826void tableLink::getch(tchar& ch, CStyle& sty, unsigned long& pos)
827{ 827{
828 if (offset >= (int)text.length()) 828 if (offset >= (int)text.length())
829 { 829 {
830 offset = -1; 830 offset = -1;
831 sty.setColour(m_r, m_g, m_b); 831 sty.setColour(m_r, m_g, m_b);
832 do 832 do
833 { 833 {
834 parent->getch(ch, sty, pos); 834 parent->getch(ch, sty, pos);
835 } 835 }
836 while (sty.isTable()); 836 while (sty.isTable());
837 return; 837 return;
838 } 838 }
839 if (offset >= 0) 839 if (offset >= 0)
840 { 840 {
841 ch = text[offset++].unicode(); 841 ch = text[offset++].unicode();
842 return; 842 return;
843 } 843 }
844 parent->getch(ch, sty, pos); 844 parent->getch(ch, sty, pos);
845 if (sty.isTable()) 845 if (sty.isTable())
846 { 846 {
847 offset = 1; 847 offset = 1;
848 ch = text[0].unicode(); 848 ch = text[0].unicode();
849 m_r = sty.Red(), m_g = sty.Green(), m_b = sty.Blue(); 849 m_r = sty.Red(), m_g = sty.Green(), m_b = sty.Blue();
850 sty.setColour(255, 0, 0); 850 sty.setColour(255, 0, 0);
851 } 851 }
852 return; 852 return;
853} 853}
854 854
855void underlineLink::getch(tchar& ch, CStyle& sty, unsigned long& pos) 855void underlineLink::getch(tchar& ch, CStyle& sty, unsigned long& pos)
856{ 856{
857 parent->getch(ch, sty, pos); 857 parent->getch(ch, sty, pos);
858 if (sty.getLink()) sty.setUnderline(); 858 if (sty.getLink()) sty.setUnderline();
859 //if (isLink && !sty.getLink()) sty.unsetUnderline(); 859 //if (isLink && !sty.getLink()) sty.unsetUnderline();
860 //isLink = sty.getLink(); 860 //isLink = sty.getLink();
861} 861}
diff --git a/noncore/apps/opie-reader/CRegExp.cpp b/noncore/apps/opie-reader/CRegExp.cpp
index 6318d28..e3194df 100644
--- a/noncore/apps/opie-reader/CRegExp.cpp
+++ b/noncore/apps/opie-reader/CRegExp.cpp
@@ -1,599 +1,599 @@
1#include "CRegExp.h" 1#include "CRegExp.h"
2 2
3//#include <stdio.h> 3//#include <stdio.h>
4#include <stdlib.h> 4#include <stdlib.h>
5//#include <string.h> 5//#include <string.h>
6 6
7 7
8tchar CRegExpFilt::escapedchar(tchar c) 8tchar CRegExpFilt::escapedchar(tchar c)
9{ 9{
10 switch (c) 10 switch (c)
11 { 11 {
12 case '\\': 12 case '\\':
13 return '\\'; 13 return '\\';
14 break; 14 break;
15 case '"': 15 case '"':
16 return '\"'; 16 return '\"';
17 break; 17 break;
18 case 'a': 18 case 'a':
19 return '\a'; 19 return '\a';
20 break; 20 break;
21 case 'b': 21 case 'b':
22 return '\b'; 22 return '\b';
23 break; 23 break;
24 case 'f': 24 case 'f':
25 return '\f'; 25 return '\f';
26 break; 26 break;
27 case 'n': 27 case 'n':
28 return '\n'; 28 return '\n';
29 break; 29 break;
30 case 'r': 30 case 'r':
31 return '\r'; 31 return '\r';
32 break; 32 break;
33 case 't': 33 case 't':
34 return '\t'; 34 return '\t';
35 break; 35 break;
36 case 'v': 36 case 'v':
37 return '\v'; 37 return '\v';
38 break; 38 break;
39 default: 39 default:
40 return c; 40 return c;
41 break; 41 break;
42 } 42 }
43} 43}
44 44
45void CRegExpFilt::regchar(tchar c, bool insens) 45void CRegExpFilt::regchar(tchar c, bool insens)
46{ 46{
47 if (insens) 47 if (insens)
48 { 48 {
49 tchar t = upper(c); 49 tchar t = upper(c);
50 CV[t] = 0; 50 CV[t] = 0;
51 t = lower(c); 51 t = lower(c);
52 CV[t] = 0; 52 CV[t] = 0;
53 } 53 }
54 else 54 else
55 { 55 {
56 CV[c] = 0; 56 CV[c] = 0;
57 } 57 }
58} 58}
59 59
60void CRegExpFilt::prepreprocessing(const QString& pat, bool insens) 60void CRegExpFilt::prepreprocessing(const QString& pat, bool insens)
61{ 61{
62 for (unsigned int p = 0; p < pat.length(); p++) 62 for (unsigned int p = 0; p < pat.length(); p++)
63 { 63 {
64#ifdef _WINDOWS 64#ifdef _WINDOWS
65 switch (pat.at(p).unicode()) 65 switch (pat.at(p).unicode())
66#else 66#else
67 switch (pat[p].unicode()) 67 switch (pat[p].unicode())
68#endif 68#endif
69 { 69 {
70 case '{': 70 case '{':
71 { 71 {
72 break; 72 break;
73 } 73 }
74 case '}': 74 case '}':
75 { 75 {
76 break; 76 break;
77 } 77 }
78 case '^': 78 case '^':
79 { 79 {
80 break; 80 break;
81 } 81 }
82 case '.' : 82 case '.' :
83 { 83 {
84 break; 84 break;
85 } 85 }
86 case '#': 86 case '#':
87 { 87 {
88 p++; 88 p++;
89#ifdef _WINDOWS 89#ifdef _WINDOWS
90 while ('0' <= pat.at(p).unicode() && pat.at(p).unicode() <= '9') 90 while ('0' <= pat.at(p).unicode() && pat.at(p).unicode() <= '9')
91#else 91#else
92 while ('0' <= pat[p].unicode() && pat[p].unicode() <= '9') 92 while ('0' <= pat[p].unicode() && pat[p].unicode() <= '9')
93#endif 93#endif
94 { 94 {
95 } 95 }
96 p--; 96 p--;
97 break; 97 break;
98 } 98 }
99 case '\\' : 99 case '\\' :
100 { 100 {
101#ifdef _WINDOWS 101#ifdef _WINDOWS
102 tchar c = escapedchar(pat.at(++p).unicode()); 102 tchar c = escapedchar(pat.at(++p).unicode());
103#else 103#else
104 tchar c = escapedchar(pat[++p].unicode()); 104 tchar c = escapedchar(pat[++p].unicode());
105#endif 105#endif
106 regchar(c, insens); 106 regchar(c, insens);
107 break; 107 break;
108 } 108 }
109 109
110 case '[' : 110 case '[' :
111 { 111 {
112 tchar clast; 112 tchar clast = 0;
113 bool invert = false; 113 bool invert = false;
114 tchar c; 114 tchar c;
115#ifdef _WINDOWS 115#ifdef _WINDOWS
116 if (pat.at(p+1).unicode() == '^') 116 if (pat.at(p+1).unicode() == '^')
117#else 117#else
118 if (pat[p+1].unicode() == '^') 118 if (pat[p+1].unicode() == '^')
119#endif 119#endif
120 { 120 {
121 p++; 121 p++;
122 invert = true; 122 invert = true;
123 } 123 }
124#ifdef _WINDOWS 124#ifdef _WINDOWS
125 while ((c = pat.at(++p).unicode()) != ']') 125 while ((c = pat.at(++p).unicode()) != ']')
126#else 126#else
127 while ((c = pat[++p].unicode()) != ']') 127 while ((c = pat[++p].unicode()) != ']')
128#endif 128#endif
129 { 129 {
130 if (c == '\\') 130 if (c == '\\')
131 { 131 {
132#ifdef _WINDOWS 132#ifdef _WINDOWS
133 c = escapedchar(pat.at(++p).unicode()); 133 c = escapedchar(pat.at(++p).unicode());
134#else 134#else
135 c = escapedchar(pat[++p].unicode()); 135 c = escapedchar(pat[++p].unicode());
136#endif 136#endif
137 if (c == ']') break; 137 if (c == ']') break;
138 } 138 }
139 if (c == '-') 139 if (c == '-')
140 { 140 {
141#ifdef _WINDOWS 141#ifdef _WINDOWS
142 c = pat.at(++p).unicode(); 142 c = pat.at(++p).unicode();
143#else 143#else
144 c = pat[++p].unicode(); 144 c = pat[++p].unicode();
145#endif 145#endif
146 for (tchar j = clast; j <= c; j++) 146 for (tchar j = clast; j <= c; j++)
147 { 147 {
148 regchar(j, insens); 148 regchar(j, insens);
149 } 149 }
150 } 150 }
151 else 151 else
152 { 152 {
153 regchar(c, insens); 153 regchar(c, insens);
154 } 154 }
155 clast = c; 155 clast = c;
156 } 156 }
157 break; 157 break;
158 } 158 }
159 default : 159 default :
160 { 160 {
161#ifdef _WINDOWS 161#ifdef _WINDOWS
162 regchar(pat.at(p).unicode(), insens); 162 regchar(pat.at(p).unicode(), insens);
163#else 163#else
164 regchar(pat[p].unicode(), insens); 164 regchar(pat[p].unicode(), insens);
165#endif 165#endif
166 break; 166 break;
167 } 167 }
168 } 168 }
169 } 169 }
170 /* 170 /*
171 for (iter i = CV.begin(); i != CV.end(); ++i) 171 for (iter i = CV.begin(); i != CV.end(); ++i)
172 { 172 {
173 printf("Pre: [%u]\n", i.first()); 173 printf("Pre: [%u]\n", i.first());
174 } 174 }
175 */ 175 */
176 CV[0] = 0; 176 CV[0] = 0;
177} 177}
178 178
179unsigned int CRegExpFilt::preprocessing(const QString& pat, bool insens) 179unsigned int CRegExpFilt::preprocessing(const QString& pat, bool insens)
180{ 180{
181 prepreprocessing(pat, insens); 181 prepreprocessing(pat, insens);
182 qDebug("PrePreProcessing done"); 182 qDebug("PrePreProcessing done");
183 unsigned int p, m; 183 unsigned int p, m;
184 bool inkeep = false; 184 bool inkeep = false;
185 keep = 0; 185 keep = 0;
186 replace = 0; 186 replace = 0;
187 for (unsigned int j = 0; j < WORD_SIZE; j++) 187 for (unsigned int j = 0; j < WORD_SIZE; j++)
188 { 188 {
189 bit[j] = (1 << (WORD_SIZE -j -1)); 189 bit[j] = (1 << (WORD_SIZE -j -1));
190 lfcnt[j] = 0; 190 lfcnt[j] = 0;
191 } 191 }
192 192
193 for (p = 0, m = 0; p < pat.length(); p++) 193 for (p = 0, m = 0; p < pat.length(); p++)
194 { 194 {
195 qDebug("m is %u", m); 195 qDebug("m is %u", m);
196 if (inkeep) keep |= bit[m]; 196 if (inkeep) keep |= bit[m];
197#ifdef _WINDOWS 197#ifdef _WINDOWS
198 switch (pat.at(p).unicode()) 198 switch (pat.at(p).unicode())
199#else 199#else
200 switch (pat[p].unicode()) 200 switch (pat[p].unicode())
201#endif 201#endif
202 { 202 {
203 case '{': 203 case '{':
204 { 204 {
205 inkeep = true; 205 inkeep = true;
206 break; 206 break;
207 } 207 }
208 case '}': 208 case '}':
209 { 209 {
210 keep ^= bit[m]; 210 keep ^= bit[m];
211 inkeep = false; 211 inkeep = false;
212 break; 212 break;
213 } 213 }
214 case '^': 214 case '^':
215 { 215 {
216 replace |= bit[m]; 216 replace |= bit[m];
217 lfcnt[m]++; 217 lfcnt[m]++;
218 break; 218 break;
219 } 219 }
220 case '.' : 220 case '.' :
221 { 221 {
222 for (iter j = CV.begin(); j != CV.end(); ++j) CV[j.first()] |= bit[m]; 222 for (iter j = CV.begin(); j != CV.end(); ++j) CV[j.first()] |= bit[m];
223 m++; 223 m++;
224 break; 224 break;
225 } 225 }
226 case '#': 226 case '#':
227 { 227 {
228 if (m > 0) 228 if (m > 0)
229 { 229 {
230 p++; 230 p++;
231 int count = 0; 231 int count = 0;
232#ifdef _WINDOWS 232#ifdef _WINDOWS
233 while ('0' <= pat.at(p).unicode() && pat.at(p).unicode() <= '9') 233 while ('0' <= pat.at(p).unicode() && pat.at(p).unicode() <= '9')
234#else 234#else
235 while ('0' <= pat[p].unicode() && pat[p].unicode() <= '9') 235 while ('0' <= pat[p].unicode() && pat[p].unicode() <= '9')
236#endif 236#endif
237 { 237 {
238#ifdef _WINDOWS 238#ifdef _WINDOWS
239 count = 10*count + pat.at(p++).unicode() - '0'; 239 count = 10*count + pat.at(p++).unicode() - '0';
240#else 240#else
241 count = 10*count + pat[p++].unicode() - '0'; 241 count = 10*count + pat[p++].unicode() - '0';
242#endif 242#endif
243 } 243 }
244 p--; 244 p--;
245 count = count-1; 245 count = count-1;
246 unsigned int mask = 0; 246 unsigned int mask = 0;
247 for (unsigned int i = m; i < m+count; i++) 247 for (unsigned int i = m; i < m+count; i++)
248 { 248 {
249 mask |= bit[i]; 249 mask |= bit[i];
250 } 250 }
251 251
252 for (iter it = CV.begin(); it != CV.end(); ++it) 252 for (iter it = CV.begin(); it != CV.end(); ++it)
253 { 253 {
254 if (CV[it.first()] & bit[m-1]) 254 if (CV[it.first()] & bit[m-1])
255 { 255 {
256 CV[it.first()] |= mask; 256 CV[it.first()] |= mask;
257 } 257 }
258 } 258 }
259 if (keep & bit[m-1]) keep |= mask; 259 if (keep & bit[m-1]) keep |= mask;
260 m += count; 260 m += count;
261 } 261 }
262 else 262 else
263 { 263 {
264 p++; 264 p++;
265 } 265 }
266 break; 266 break;
267 } 267 }
268 case '\\' : 268 case '\\' :
269 { 269 {
270#ifdef _WINDOWS 270#ifdef _WINDOWS
271 tchar c = escapedchar(pat.at(++p).unicode()); 271 tchar c = escapedchar(pat.at(++p).unicode());
272#else 272#else
273 tchar c = escapedchar(pat[++p].unicode()); 273 tchar c = escapedchar(pat[++p].unicode());
274#endif 274#endif
275 if (insens) 275 if (insens)
276 { 276 {
277 CV[upper(c)] |= bit[m]; 277 CV[upper(c)] |= bit[m];
278 CV[lower(c)] |= bit[m]; 278 CV[lower(c)] |= bit[m];
279 } 279 }
280 else 280 else
281 { 281 {
282 CV[c] |= bit[m]; 282 CV[c] |= bit[m];
283 } 283 }
284 m++; 284 m++;
285 break; 285 break;
286 } 286 }
287 287
288 case '[' : 288 case '[' :
289 { 289 {
290 tchar c, clast; 290 tchar c, clast = 0;
291 bool invert = false; 291 bool invert = false;
292#ifdef _WINDOWS 292#ifdef _WINDOWS
293 if (pat.at(p+1).unicode() == '^') 293 if (pat.at(p+1).unicode() == '^')
294#else 294#else
295 if (pat[p+1].unicode() == '^') 295 if (pat[p+1].unicode() == '^')
296#endif 296#endif
297 { 297 {
298 p++; 298 p++;
299 invert = true; 299 invert = true;
300 } 300 }
301#ifdef _WINDOWS 301#ifdef _WINDOWS
302 while ((c = pat.at(++p).unicode()) != ']') 302 while ((c = pat.at(++p).unicode()) != ']')
303#else 303#else
304 while ((c = pat[++p].unicode()) != ']') 304 while ((c = pat[++p].unicode()) != ']')
305#endif 305#endif
306 { 306 {
307 if (c == '\\') 307 if (c == '\\')
308 { 308 {
309#ifdef _WINDOWS 309#ifdef _WINDOWS
310 c = escapedchar(pat.at(++p).unicode()); 310 c = escapedchar(pat.at(++p).unicode());
311#else 311#else
312 c = escapedchar(pat[++p].unicode()); 312 c = escapedchar(pat[++p].unicode());
313#endif 313#endif
314 if (c == ']') break; 314 if (c == ']') break;
315 } 315 }
316 if (c == '-') 316 if (c == '-')
317 { 317 {
318#ifdef _WINDOWS 318#ifdef _WINDOWS
319 c = pat.at(++p).unicode(); 319 c = pat.at(++p).unicode();
320#else 320#else
321 c = pat[++p].unicode(); 321 c = pat[++p].unicode();
322#endif 322#endif
323 for (tchar j = clast; j <= c; j++) 323 for (tchar j = clast; j <= c; j++)
324 { 324 {
325 if (insens) 325 if (insens)
326 { 326 {
327 iter it; 327 iter it;
328 if ((it = CV.find(upper(j))) != CV.end()) 328 if ((it = CV.find(upper(j))) != CV.end())
329 CV[it] |= bit[m]; 329 CV[it] |= bit[m];
330 else 330 else
331 CV[0] |= bit[m]; 331 CV[0] |= bit[m];
332 if ((it = CV.find(lower(j))) != CV.end()) 332 if ((it = CV.find(lower(j))) != CV.end())
333 CV[it] |= bit[m]; 333 CV[it] |= bit[m];
334 else 334 else
335 CV[0] |= bit[m]; 335 CV[0] |= bit[m];
336 } 336 }
337 else 337 else
338 { 338 {
339 iter it; 339 iter it;
340 if ((it = CV.find(j)) != CV.end()) 340 if ((it = CV.find(j)) != CV.end())
341 CV[it] |= bit[m]; 341 CV[it] |= bit[m];
342 else 342 else
343 { 343 {
344 CV[0] |= bit[m]; 344 CV[0] |= bit[m];
345 } 345 }
346 } 346 }
347 } 347 }
348 } 348 }
349 else 349 else
350 { 350 {
351 if (insens) 351 if (insens)
352 { 352 {
353 iter it; 353 iter it;
354 if ((it = CV.find(upper(c))) != CV.end()) 354 if ((it = CV.find(upper(c))) != CV.end())
355 CV[it] |= bit[m]; 355 CV[it] |= bit[m];
356 else 356 else
357 CV[0] |= bit[m]; 357 CV[0] |= bit[m];
358 if ((it = CV.find(lower(c))) != CV.end()) 358 if ((it = CV.find(lower(c))) != CV.end())
359 CV[it] |= bit[m]; 359 CV[it] |= bit[m];
360 else 360 else
361 CV[0] |= bit[m]; 361 CV[0] |= bit[m];
362 } 362 }
363 else 363 else
364 { 364 {
365 iter it; 365 iter it;
366 if ((it = CV.find(c)) != CV.end()) 366 if ((it = CV.find(c)) != CV.end())
367 CV[it] |= bit[m]; 367 CV[it] |= bit[m];
368 else 368 else
369 CV[0] |= bit[m]; 369 CV[0] |= bit[m];
370 } 370 }
371 } 371 }
372 clast = c; 372 clast = c;
373 } 373 }
374 if (invert) 374 if (invert)
375 { 375 {
376 for (iter i = CV.begin(); i != CV.end(); ++i) 376 for (iter i = CV.begin(); i != CV.end(); ++i)
377 { 377 {
378 CV[i.first()] ^= bit[m]; 378 CV[i.first()] ^= bit[m];
379 } 379 }
380 } 380 }
381 m++; 381 m++;
382 break; 382 break;
383 } 383 }
384 default : 384 default :
385 { 385 {
386#ifdef _WINDOWS 386#ifdef _WINDOWS
387 tchar c = pat.at(p).unicode(); 387 tchar c = pat.at(p).unicode();
388#else 388#else
389 tchar c = pat[p].unicode(); 389 tchar c = pat[p].unicode();
390#endif 390#endif
391 if (insens) 391 if (insens)
392 { 392 {
393 CV[upper(c)] |= bit[m]; 393 CV[upper(c)] |= bit[m];
394 CV[lower(c)] |= bit[m]; 394 CV[lower(c)] |= bit[m];
395 } 395 }
396 else CV[c] |= bit[m]; 396 else CV[c] |= bit[m];
397 m++; 397 m++;
398 break; 398 break;
399 } 399 }
400 } 400 }
401 } 401 }
402 qDebug("Returning:%u",m); 402 qDebug("Returning:%u",m);
403 return m; 403 return m;
404} 404}
405 405
406bool CRegExpFilt::empty() 406bool CRegExpFilt::empty()
407{ 407{
408 return m_outQueue.empty(); 408 return m_outQueue.empty();
409} 409}
410 410
411tchar CRegExpFilt::pop() 411tchar CRegExpFilt::pop()
412{ 412{
413 return m_outQueue.pop(); 413 return m_outQueue.pop();
414} 414}
415 415
416bool CRegExpFilt::addch(tchar ch) 416bool CRegExpFilt::addch(tchar ch)
417{ 417{
418 word[cur] = ch; 418 word[cur] = ch;
419 cur = (cur+1)%patlength; 419 cur = (cur+1)%patlength;
420 if (len < patlength) len++; 420 if (len < patlength) len++;
421 421
422 unsigned int cv = 0; 422 unsigned int cv = 0;
423 iter it; 423 iter it;
424 if ((it = CV.find(ch)) == CV.end()) 424 if ((it = CV.find(ch)) == CV.end())
425 { 425 {
426 cv = CV[0]; 426 cv = CV[0];
427 } 427 }
428 else 428 else
429 { 429 {
430 cv = CV[it]; 430 cv = CV[it];
431 } 431 }
432 432
433 R = ((R >> 1) | bit_0) & cv; /* Exact matches */ 433 R = ((R >> 1) | bit_0) & cv; /* Exact matches */
434 if (R & endpos) 434 if (R & endpos)
435 { 435 {
436 for (unsigned int i = 0; i < patlength; i++) 436 for (unsigned int i = 0; i < patlength; i++)
437 { 437 {
438 if (replace & bit[i]) 438 if (replace & bit[i])
439 { 439 {
440 for (unsigned int j = 0; j < lfcnt[i]; j++) 440 for (unsigned int j = 0; j < lfcnt[i]; j++)
441 { 441 {
442 m_outQueue.push(10); 442 m_outQueue.push(10);
443 } 443 }
444 } 444 }
445 if (keep & bit[i]) 445 if (keep & bit[i])
446 { 446 {
447 m_outQueue.push(word[(cur+i)%patlength]); 447 m_outQueue.push(word[(cur+i)%patlength]);
448 // putchar('*'); 448 // putchar('*');
449 // putchar(i + '0'); 449 // putchar(i + '0');
450 } 450 }
451 len = 0; 451 len = 0;
452 } 452 }
453 return true; 453 return true;
454 } 454 }
455 else 455 else
456 { 456 {
457 if (len == patlength) 457 if (len == patlength)
458 { 458 {
459 tchar ch = word[cur]; 459 tchar ch = word[cur];
460 if (ch == 10) ch = ' '; 460 if (ch == 10) ch = ' ';
461 m_outQueue.push(ch); 461 m_outQueue.push(ch);
462 } 462 }
463 return false; 463 return false;
464 } 464 }
465} 465}
466 466
467void CRegExpFilt::restart() 467void CRegExpFilt::restart()
468{ 468{
469 R = 0; 469 R = 0;
470 len = 0; 470 len = 0;
471} 471}
472 472
473CRegExpFilt::CRegExpFilt(const QString& pat, bool insensflag) : CV(300) 473CRegExpFilt::CRegExpFilt(const QString& pat, bool insensflag) : CV(300)
474{ 474{
475 cur = 0; 475 cur = 0;
476 patlength = preprocessing(pat, insensflag); 476 patlength = preprocessing(pat, insensflag);
477 qDebug("Preprocesing done:%u", patlength); 477 qDebug("Preprocesing done:%u", patlength);
478 endpos = bit[patlength-1]; 478 endpos = bit[patlength-1];
479 bit_0 = bit[0]; 479 bit_0 = bit[0];
480 480
481 restart(); 481 restart();
482 482
483 qDebug("Pattern: %s:%u", (const char*)pat, patlength); 483 qDebug("Pattern: %s:%u", (const char*)pat, patlength);
484 484
485} 485}
486 486
487 487
488CRegExpFilt::~CRegExpFilt() 488CRegExpFilt::~CRegExpFilt()
489{ 489{
490} 490}
491 491
492#ifdef NOWAYISTHISDEFINED 492#ifdef NOWAYISTHISDEFINED
493void reportmatch(tchar *line, /*tchar *text,*/ unsigned int mtype, unsigned int lino) 493void reportmatch(tchar *line, /*tchar *text,*/ unsigned int mtype, unsigned int lino)
494{ 494{
495 /* 495 /*
496 tchar *text = line + strlen(line); 496 tchar *text = line + strlen(line);
497 497
498 tchar *ptr = line; 498 tchar *ptr = line;
499 if (mtype == 0) 499 if (mtype == 0)
500 printf("Exact match at line number %u.\n", lino); 500 printf("Exact match at line number %u.\n", lino);
501 else 501 else
502 printf("%u error match at line number %u.\n", mtype, lino); 502 printf("%u error match at line number %u.\n", mtype, lino);
503 while (ptr < text) putchar(*ptr++); 503 while (ptr < text) putchar(*ptr++);
504 printf("%c[4m^%c[24m%s\n", 27, 27, ptr); 504 printf("%c[4m^%c[24m%s\n", 27, 27, ptr);
505 */ 505 */
506} 506}
507 507
508 508
509void usage(void) 509void usage(void)
510{ 510{
511 printf("Usage: CRegExpFilt [-i] pattern/a file\n"); 511 printf("Usage: CRegExpFilt [-i] pattern/a file\n");
512} 512}
513 513
514int getline(tchar *s,int lim,FILE *f) 514int getline(tchar *s,int lim,FILE *f)
515{ 515{
516 int c, i; 516 int c, i;
517 517
518 for (i = 0; i < lim-1 && (c = getc(f)) != EOF && c != '\n'; ) 518 for (i = 0; i < lim-1 && (c = getc(f)) != EOF && c != '\n'; )
519 { 519 {
520 s[i++] = (tchar)c; 520 s[i++] = (tchar)c;
521 } 521 }
522 s[i] = '\0'; 522 s[i] = '\0';
523 return ((c == EOF && i == 0) ? -1 : i); 523 return ((c == EOF && i == 0) ? -1 : i);
524} 524}
525 525
526 #define BUF_SIZE256 526 #define BUF_SIZE256
527 527
528int main(int argc, char **argv) 528int main(int argc, char **argv)
529{ 529{
530 unsigned int lino = 0; 530 unsigned int lino = 0;
531 unsigned int blino = 0; 531 unsigned int blino = 0;
532 bool insens = false; 532 bool insens = false;
533 int len; 533 int len;
534 tchar line[BUF_SIZE]; 534 tchar line[BUF_SIZE];
535 FILE *inf; 535 FILE *inf;
536 536
537 /* Error checking of cmd ln args! */ 537 /* Error checking of cmd ln args! */
538 if (argc < 3) 538 if (argc < 3)
539 {usage(); return 10; } 539 {usage(); return 10; }
540 /* Corresponds to requiring a minimum of 3 matches */ 540 /* Corresponds to requiring a minimum of 3 matches */
541 for (len = 1; len < argc-2; len++) 541 for (len = 1; len < argc-2; len++)
542 { 542 {
543 if (argv[len][0] != '-') 543 if (argv[len][0] != '-')
544 {usage(); return 10; } 544 {usage(); return 10; }
545 else switch (argv[len][1]) 545 else switch (argv[len][1])
546 { 546 {
547 case 'i' : 547 case 'i' :
548 { 548 {
549 insens = true; 549 insens = true;
550 break; 550 break;
551 } 551 }
552 default : 552 default :
553 {usage(); return 10;} 553 {usage(); return 10;}
554 } 554 }
555 } 555 }
556 556
557 tchar* pattern = new tchar[strlen(argv[argc-2])+1]; 557 tchar* pattern = new tchar[strlen(argv[argc-2])+1];
558 558
559 for (int i = 0; (pattern[i] = argv[argc-2][i]) != 0; i++); 559 for (int i = 0; (pattern[i] = argv[argc-2][i]) != 0; i++);
560 560
561 561
562 562
563 CRegExpFilt test(pattern, insens); 563 CRegExpFilt test(pattern, insens);
564 564
565 delete [] pattern; 565 delete [] pattern;
566 566
567 inf = fopen(argv[argc-1], "r"); 567 inf = fopen(argv[argc-1], "r");
568 if (!inf) 568 if (!inf)
569 { 569 {
570 printf("file not found\n"); 570 printf("file not found\n");
571 return 10; 571 return 10;
572 } 572 }
573 573
574 while ((len = getline(line, BUF_SIZE, inf)) >= 0) 574 while ((len = getline(line, BUF_SIZE, inf)) >= 0)
575 { 575 {
576 lino++; 576 lino++;
577 bool ret = false; 577 bool ret = false;
578 578
579 { 579 {
580 tchar *textend = line+len; 580 tchar *textend = line+len;
581 tchar *text = line; 581 tchar *text = line;
582 while (text < textend) 582 while (text < textend)
583 { 583 {
584 ret |= test.addch(*text++); 584 ret |= test.addch(*text++);
585 } 585 }
586 ret |= test.addch('\n'); 586 ret |= test.addch('\n');
587 while (!test.empty()) 587 while (!test.empty())
588 { 588 {
589 putchar(test.pop()); 589 putchar(test.pop());
590 } 590 }
591 } 591 }
592 // inswt = test.addch(line, len); 592 // inswt = test.addch(line, len);
593 if (ret) reportmatch(line, 0, lino); 593 if (ret) reportmatch(line, 0, lino);
594 } 594 }
595 fclose(inf); 595 fclose(inf);
596 //CloseSTDLIB(); 596 //CloseSTDLIB();
597 return 0; 597 return 0;
598} 598}
599#endif 599#endif
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp
index 361755f..09cad1c 100644
--- a/noncore/apps/opie-reader/Palm2QImage.cpp
+++ b/noncore/apps/opie-reader/Palm2QImage.cpp
@@ -1,299 +1,299 @@
1/* -*- mode: c; indent-tabs-mode: nil; -*- */ 1/* -*- mode: c; indent-tabs-mode: nil; -*- */
2 2
3#include <stdio.h> 3#include <stdio.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <string.h> 5#include <string.h>
6#ifndef _WINDOWS 6#ifndef _WINDOWS
7#include <unistd.h> /* for link */ 7#include <unistd.h> /* for link */
8#endif 8#endif
9#include <sys/types.h> 9#include <sys/types.h>
10#include <sys/stat.h> 10#include <sys/stat.h>
11#include <stdarg.h> 11#include <stdarg.h>
12 12
13#include <qimage.h> 13#include <qimage.h>
14 14
15/***********************************************************************/ 15/***********************************************************************/
16/***********************************************************************/ 16/***********************************************************************/
17/***** *****/ 17/***** *****/
18/***** Code to decode the Palm image format to JPEG *****/ 18/***** Code to decode the Palm image format to JPEG *****/
19/***** *****/ 19/***** *****/
20/***********************************************************************/ 20/***********************************************************************/
21/***********************************************************************/ 21/***********************************************************************/
22 22
23#define READ_BIGENDIAN_SHORT(p) (((p)[0] << 8)|((p)[1])) 23#define READ_BIGENDIAN_SHORT(p) (((p)[0] << 8)|((p)[1]))
24#define READ_BIGENDIAN_LONG(p) (((p)[0] << 24)|((p)[1] << 16)|((p)[2] << 8)|((p)[3])) 24#define READ_BIGENDIAN_LONG(p) (((p)[0] << 24)|((p)[1] << 16)|((p)[2] << 8)|((p)[3]))
25 25
26#define PALM_IS_COMPRESSED_FLAG 0x8000 26#define PALM_IS_COMPRESSED_FLAG 0x8000
27#define PALM_HAS_COLORMAP_FLAG 0x4000 27#define PALM_HAS_COLORMAP_FLAG 0x4000
28#define PALM_HAS_TRANSPARENCY_FLAG 0x2000 28#define PALM_HAS_TRANSPARENCY_FLAG 0x2000
29#define PALM_DIRECT_COLOR_FLAG 0x0400 29#define PALM_DIRECT_COLOR_FLAG 0x0400
30#define PALM_4_BYTE_FIELD_FLAG 0x0200 30#define PALM_4_BYTE_FIELD_FLAG 0x0200
31 31
32#define PALM_COMPRESSION_SCANLINE 0x00 32#define PALM_COMPRESSION_SCANLINE 0x00
33#define PALM_COMPRESSION_RLE 0x01 33#define PALM_COMPRESSION_RLE 0x01
34#define PALM_COMPRESSION_PACKBITS 0x02 34#define PALM_COMPRESSION_PACKBITS 0x02
35#define PALM_COMPRESSION_NONE 0xFF 35#define PALM_COMPRESSION_NONE 0xFF
36 36
37#define PALM_COLORMAP_SIZE 232 37#define PALM_COLORMAP_SIZE 232
38 38
39typedef struct { 39typedef struct {
40 unsigned char red; 40 unsigned char red;
41 unsigned char green; 41 unsigned char green;
42 unsigned char blue; 42 unsigned char blue;
43} ColorMapEntry; 43} ColorMapEntry;
44 44
45static ColorMapEntry Palm8BitColormap[] = { 45static ColorMapEntry Palm8BitColormap[] = {
46 { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 }, 46 { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 },
47 { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 }, 47 { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 },
48 { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 }, 48 { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 },
49 { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 }, 49 { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 },
50 { 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 }, 50 { 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 },
51 { 204, 153, 255 }, { 204, 102, 255 }, { 204, 51, 255 }, { 204, 0, 255 }, 51 { 204, 153, 255 }, { 204, 102, 255 }, { 204, 51, 255 }, { 204, 0, 255 },
52 { 204, 255, 204 }, { 204, 204, 204 }, { 204, 153, 204 }, { 204, 102, 204 }, 52 { 204, 255, 204 }, { 204, 204, 204 }, { 204, 153, 204 }, { 204, 102, 204 },
53 { 204, 51, 204 }, { 204, 0, 204 }, { 204, 255, 153 }, { 204, 204, 153 }, 53 { 204, 51, 204 }, { 204, 0, 204 }, { 204, 255, 153 }, { 204, 204, 153 },
54 { 204, 153, 153 }, { 204, 102, 153 }, { 204, 51, 153 }, { 204, 0, 153 }, 54 { 204, 153, 153 }, { 204, 102, 153 }, { 204, 51, 153 }, { 204, 0, 153 },
55 { 153, 255, 255 }, { 153, 204, 255 }, { 153, 153, 255 }, { 153, 102, 255 }, 55 { 153, 255, 255 }, { 153, 204, 255 }, { 153, 153, 255 }, { 153, 102, 255 },
56 { 153, 51, 255 }, { 153, 0, 255 }, { 153, 255, 204 }, { 153, 204, 204 }, 56 { 153, 51, 255 }, { 153, 0, 255 }, { 153, 255, 204 }, { 153, 204, 204 },
57 { 153, 153, 204 }, { 153, 102, 204 }, { 153, 51, 204 }, { 153, 0, 204 }, 57 { 153, 153, 204 }, { 153, 102, 204 }, { 153, 51, 204 }, { 153, 0, 204 },
58 { 153, 255, 153 }, { 153, 204, 153 }, { 153, 153, 153 }, { 153, 102, 153 }, 58 { 153, 255, 153 }, { 153, 204, 153 }, { 153, 153, 153 }, { 153, 102, 153 },
59 { 153, 51, 153 }, { 153, 0, 153 }, { 102, 255, 255 }, { 102, 204, 255 }, 59 { 153, 51, 153 }, { 153, 0, 153 }, { 102, 255, 255 }, { 102, 204, 255 },
60 { 102, 153, 255 }, { 102, 102, 255 }, { 102, 51, 255 }, { 102, 0, 255 }, 60 { 102, 153, 255 }, { 102, 102, 255 }, { 102, 51, 255 }, { 102, 0, 255 },
61 { 102, 255, 204 }, { 102, 204, 204 }, { 102, 153, 204 }, { 102, 102, 204 }, 61 { 102, 255, 204 }, { 102, 204, 204 }, { 102, 153, 204 }, { 102, 102, 204 },
62 { 102, 51, 204 }, { 102, 0, 204 }, { 102, 255, 153 }, { 102, 204, 153 }, 62 { 102, 51, 204 }, { 102, 0, 204 }, { 102, 255, 153 }, { 102, 204, 153 },
63 { 102, 153, 153 }, { 102, 102, 153 }, { 102, 51, 153 }, { 102, 0, 153 }, 63 { 102, 153, 153 }, { 102, 102, 153 }, { 102, 51, 153 }, { 102, 0, 153 },
64 { 51, 255, 255 }, { 51, 204, 255 }, { 51, 153, 255 }, { 51, 102, 255 }, 64 { 51, 255, 255 }, { 51, 204, 255 }, { 51, 153, 255 }, { 51, 102, 255 },
65 { 51, 51, 255 }, { 51, 0, 255 }, { 51, 255, 204 }, { 51, 204, 204 }, 65 { 51, 51, 255 }, { 51, 0, 255 }, { 51, 255, 204 }, { 51, 204, 204 },
66 { 51, 153, 204 }, { 51, 102, 204 }, { 51, 51, 204 }, { 51, 0, 204 }, 66 { 51, 153, 204 }, { 51, 102, 204 }, { 51, 51, 204 }, { 51, 0, 204 },
67 { 51, 255, 153 }, { 51, 204, 153 }, { 51, 153, 153 }, { 51, 102, 153 }, 67 { 51, 255, 153 }, { 51, 204, 153 }, { 51, 153, 153 }, { 51, 102, 153 },
68 { 51, 51, 153 }, { 51, 0, 153 }, { 0, 255, 255 }, { 0, 204, 255 }, 68 { 51, 51, 153 }, { 51, 0, 153 }, { 0, 255, 255 }, { 0, 204, 255 },
69 { 0, 153, 255 }, { 0, 102, 255 }, { 0, 51, 255 }, { 0, 0, 255 }, 69 { 0, 153, 255 }, { 0, 102, 255 }, { 0, 51, 255 }, { 0, 0, 255 },
70 { 0, 255, 204 }, { 0, 204, 204 }, { 0, 153, 204 }, { 0, 102, 204 }, 70 { 0, 255, 204 }, { 0, 204, 204 }, { 0, 153, 204 }, { 0, 102, 204 },
71 { 0, 51, 204 }, { 0, 0, 204 }, { 0, 255, 153 }, { 0, 204, 153 }, 71 { 0, 51, 204 }, { 0, 0, 204 }, { 0, 255, 153 }, { 0, 204, 153 },
72 { 0, 153, 153 }, { 0, 102, 153 }, { 0, 51, 153 }, { 0, 0, 153 }, 72 { 0, 153, 153 }, { 0, 102, 153 }, { 0, 51, 153 }, { 0, 0, 153 },
73 { 255, 255, 102 }, { 255, 204, 102 }, { 255, 153, 102 }, { 255, 102, 102 }, 73 { 255, 255, 102 }, { 255, 204, 102 }, { 255, 153, 102 }, { 255, 102, 102 },
74 { 255, 51, 102 }, { 255, 0, 102 }, { 255, 255, 51 }, { 255, 204, 51 }, 74 { 255, 51, 102 }, { 255, 0, 102 }, { 255, 255, 51 }, { 255, 204, 51 },
75 { 255, 153, 51 }, { 255, 102, 51 }, { 255, 51, 51 }, { 255, 0, 51 }, 75 { 255, 153, 51 }, { 255, 102, 51 }, { 255, 51, 51 }, { 255, 0, 51 },
76 { 255, 255, 0 }, { 255, 204, 0 }, { 255, 153, 0 }, { 255, 102, 0 }, 76 { 255, 255, 0 }, { 255, 204, 0 }, { 255, 153, 0 }, { 255, 102, 0 },
77 { 255, 51, 0 }, { 255, 0, 0 }, { 204, 255, 102 }, { 204, 204, 102 }, 77 { 255, 51, 0 }, { 255, 0, 0 }, { 204, 255, 102 }, { 204, 204, 102 },
78 { 204, 153, 102 }, { 204, 102, 102 }, { 204, 51, 102 }, { 204, 0, 102 }, 78 { 204, 153, 102 }, { 204, 102, 102 }, { 204, 51, 102 }, { 204, 0, 102 },
79 { 204, 255, 51 }, { 204, 204, 51 }, { 204, 153, 51 }, { 204, 102, 51 }, 79 { 204, 255, 51 }, { 204, 204, 51 }, { 204, 153, 51 }, { 204, 102, 51 },
80 { 204, 51, 51 }, { 204, 0, 51 }, { 204, 255, 0 }, { 204, 204, 0 }, 80 { 204, 51, 51 }, { 204, 0, 51 }, { 204, 255, 0 }, { 204, 204, 0 },
81 { 204, 153, 0 }, { 204, 102, 0 }, { 204, 51, 0 }, { 204, 0, 0 }, 81 { 204, 153, 0 }, { 204, 102, 0 }, { 204, 51, 0 }, { 204, 0, 0 },
82 { 153, 255, 102 }, { 153, 204, 102 }, { 153, 153, 102 }, { 153, 102, 102 }, 82 { 153, 255, 102 }, { 153, 204, 102 }, { 153, 153, 102 }, { 153, 102, 102 },
83 { 153, 51, 102 }, { 153, 0, 102 }, { 153, 255, 51 }, { 153, 204, 51 }, 83 { 153, 51, 102 }, { 153, 0, 102 }, { 153, 255, 51 }, { 153, 204, 51 },
84 { 153, 153, 51 }, { 153, 102, 51 }, { 153, 51, 51 }, { 153, 0, 51 }, 84 { 153, 153, 51 }, { 153, 102, 51 }, { 153, 51, 51 }, { 153, 0, 51 },
85 { 153, 255, 0 }, { 153, 204, 0 }, { 153, 153, 0 }, { 153, 102, 0 }, 85 { 153, 255, 0 }, { 153, 204, 0 }, { 153, 153, 0 }, { 153, 102, 0 },
86 { 153, 51, 0 }, { 153, 0, 0 }, { 102, 255, 102 }, { 102, 204, 102 }, 86 { 153, 51, 0 }, { 153, 0, 0 }, { 102, 255, 102 }, { 102, 204, 102 },
87 { 102, 153, 102 }, { 102, 102, 102 }, { 102, 51, 102 }, { 102, 0, 102 }, 87 { 102, 153, 102 }, { 102, 102, 102 }, { 102, 51, 102 }, { 102, 0, 102 },
88 { 102, 255, 51 }, { 102, 204, 51 }, { 102, 153, 51 }, { 102, 102, 51 }, 88 { 102, 255, 51 }, { 102, 204, 51 }, { 102, 153, 51 }, { 102, 102, 51 },
89 { 102, 51, 51 }, { 102, 0, 51 }, { 102, 255, 0 }, { 102, 204, 0 }, 89 { 102, 51, 51 }, { 102, 0, 51 }, { 102, 255, 0 }, { 102, 204, 0 },
90 { 102, 153, 0 }, { 102, 102, 0 }, { 102, 51, 0 }, { 102, 0, 0 }, 90 { 102, 153, 0 }, { 102, 102, 0 }, { 102, 51, 0 }, { 102, 0, 0 },
91 { 51, 255, 102 }, { 51, 204, 102 }, { 51, 153, 102 }, { 51, 102, 102 }, 91 { 51, 255, 102 }, { 51, 204, 102 }, { 51, 153, 102 }, { 51, 102, 102 },
92 { 51, 51, 102 }, { 51, 0, 102 }, { 51, 255, 51 }, { 51, 204, 51 }, 92 { 51, 51, 102 }, { 51, 0, 102 }, { 51, 255, 51 }, { 51, 204, 51 },
93 { 51, 153, 51 }, { 51, 102, 51 }, { 51, 51, 51 }, { 51, 0, 51 }, 93 { 51, 153, 51 }, { 51, 102, 51 }, { 51, 51, 51 }, { 51, 0, 51 },
94 { 51, 255, 0 }, { 51, 204, 0 }, { 51, 153, 0 }, { 51, 102, 0 }, 94 { 51, 255, 0 }, { 51, 204, 0 }, { 51, 153, 0 }, { 51, 102, 0 },
95 { 51, 51, 0 }, { 51, 0, 0 }, { 0, 255, 102 }, { 0, 204, 102 }, 95 { 51, 51, 0 }, { 51, 0, 0 }, { 0, 255, 102 }, { 0, 204, 102 },
96 { 0, 153, 102 }, { 0, 102, 102 }, { 0, 51, 102 }, { 0, 0, 102 }, 96 { 0, 153, 102 }, { 0, 102, 102 }, { 0, 51, 102 }, { 0, 0, 102 },
97 { 0, 255, 51 }, { 0, 204, 51 }, { 0, 153, 51 }, { 0, 102, 51 }, 97 { 0, 255, 51 }, { 0, 204, 51 }, { 0, 153, 51 }, { 0, 102, 51 },
98 { 0, 51, 51 }, { 0, 0, 51 }, { 0, 255, 0 }, { 0, 204, 0 }, 98 { 0, 51, 51 }, { 0, 0, 51 }, { 0, 255, 0 }, { 0, 204, 0 },
99 { 0, 153, 0 }, { 0, 102, 0 }, { 0, 51, 0 }, { 17, 17, 17 }, 99 { 0, 153, 0 }, { 0, 102, 0 }, { 0, 51, 0 }, { 17, 17, 17 },
100 { 34, 34, 34 }, { 68, 68, 68 }, { 85, 85, 85 }, { 119, 119, 119 }, 100 { 34, 34, 34 }, { 68, 68, 68 }, { 85, 85, 85 }, { 119, 119, 119 },
101 { 136, 136, 136 }, { 170, 170, 170 }, { 187, 187, 187 }, { 221, 221, 221 }, 101 { 136, 136, 136 }, { 170, 170, 170 }, { 187, 187, 187 }, { 221, 221, 221 },
102 { 238, 238, 238 }, { 192, 192, 192 }, { 128, 0, 0 }, { 128, 0, 128 }, 102 { 238, 238, 238 }, { 192, 192, 192 }, { 128, 0, 0 }, { 128, 0, 128 },
103 { 0, 128, 0 }, { 0, 128, 128 }, { 0, 0, 0 }, { 0, 0, 0 }, 103 { 0, 128, 0 }, { 0, 128, 128 }, { 0, 0, 0 }, { 0, 0, 0 },
104 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, 104 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
105 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, 105 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
106 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, 106 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
107 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, 107 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
108 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, 108 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
109 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }}; 109 { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }};
110 110
111static ColorMapEntry Palm1BitColormap[] = {{ 255, 255, 255 }, { 0, 0, 0 }}; 111static ColorMapEntry Palm1BitColormap[] = {{ 255, 255, 255 }, { 0, 0, 0 }};
112 112
113static ColorMapEntry Palm2BitColormap[] = { 113static ColorMapEntry Palm2BitColormap[] = {
114 { 255, 255, 255 }, { 192, 192, 192 }, { 128, 128, 128 }, { 0, 0, 0 }}; 114 { 255, 255, 255 }, { 192, 192, 192 }, { 128, 128, 128 }, { 0, 0, 0 }};
115 115
116static ColorMapEntry Palm4BitColormap[] = { 116static ColorMapEntry Palm4BitColormap[] = {
117 { 255, 255, 255 }, { 238, 238, 238 }, { 221, 221, 221 }, { 204, 204, 204 }, 117 { 255, 255, 255 }, { 238, 238, 238 }, { 221, 221, 221 }, { 204, 204, 204 },
118 { 187, 187, 187 }, { 170, 170, 170 }, { 153, 153, 153 }, { 136, 136, 136 }, 118 { 187, 187, 187 }, { 170, 170, 170 }, { 153, 153, 153 }, { 136, 136, 136 },
119 { 119, 119, 119 }, { 102, 102, 102 }, { 85, 85, 85 }, { 68, 68, 68 }, 119 { 119, 119, 119 }, { 102, 102, 102 }, { 85, 85, 85 }, { 68, 68, 68 },
120 { 51, 51, 51 }, { 34, 34, 34 }, { 17, 17, 17 }, { 0, 0, 0 }}; 120 { 51, 51, 51 }, { 34, 34, 34 }, { 17, 17, 17 }, { 0, 0, 0 }};
121 121
122QImage* Palm2QImage 122QImage* Palm2QImage
123 (unsigned char *image_bytes_in, int byte_count_in) 123 (unsigned char *image_bytes_in, int byte_count_in)
124{ 124{
125 unsigned int width, height, bytes_per_row, flags, next_depth_offset; 125 unsigned int width, height, bytes_per_row, flags, next_depth_offset;
126 unsigned int bits_per_pixel, version, transparent_index, compression_type, i, j, inval, inbit, mask, incount; 126 unsigned int bits_per_pixel, version, transparent_index, compression_type, i, j, inval, inbit, mask, incount;
127 unsigned int palm_red_bits, palm_green_bits, palm_blue_bits; 127 unsigned int palm_red_bits, palm_green_bits, palm_blue_bits;
128 unsigned char *palm_ptr, *x_ptr, *imagedata, *inbyte, *rowbuf, *lastrow, 128 unsigned char *palm_ptr, *x_ptr, *inbyte, *rowbuf, *lastrow,
129 *imagedatastart, *palmimage; 129 *imagedatastart, *palmimage;
130 ColorMapEntry *colormap; 130 ColorMapEntry *colormap;
131 131
132 palmimage = image_bytes_in; 132 palmimage = image_bytes_in;
133 width = READ_BIGENDIAN_SHORT(palmimage + 0); 133 width = READ_BIGENDIAN_SHORT(palmimage + 0);
134 height = READ_BIGENDIAN_SHORT(palmimage + 2); 134 height = READ_BIGENDIAN_SHORT(palmimage + 2);
135 bytes_per_row = READ_BIGENDIAN_SHORT(palmimage + 4); 135 bytes_per_row = READ_BIGENDIAN_SHORT(palmimage + 4);
136 flags = READ_BIGENDIAN_SHORT(palmimage + 6); 136 flags = READ_BIGENDIAN_SHORT(palmimage + 6);
137 bits_per_pixel = palmimage[8]; 137 bits_per_pixel = palmimage[8];
138 version = palmimage[9]; 138 version = palmimage[9];
139 next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10); 139 next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10);
140 transparent_index = palmimage[12]; 140 transparent_index = palmimage[12];
141 compression_type = palmimage[13]; 141 compression_type = palmimage[13];
142 /* bytes 14 and 15 are reserved by Palm and always 0 */ 142 /* bytes 14 and 15 are reserved by Palm and always 0 */
143 143
144#if 0 144#if 0
145// qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d", width, height, bits_per_pixel, version, flags, compression_type); 145// qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d", width, height, bits_per_pixel, version, flags, compression_type);
146#endif 146#endif
147 147
148 if (compression_type == PALM_COMPRESSION_PACKBITS) { 148 if (compression_type == PALM_COMPRESSION_PACKBITS) {
149// qDebug ("Image uses packbits compression; not yet supported"); 149// qDebug ("Image uses packbits compression; not yet supported");
150 return NULL; 150 return NULL;
151 } else if ((compression_type != PALM_COMPRESSION_NONE) && 151 } else if ((compression_type != PALM_COMPRESSION_NONE) &&
152 (compression_type != PALM_COMPRESSION_RLE) && 152 (compression_type != PALM_COMPRESSION_RLE) &&
153 (compression_type != PALM_COMPRESSION_SCANLINE)) { 153 (compression_type != PALM_COMPRESSION_SCANLINE)) {
154// qDebug ("Image uses unknown compression, code 0x%x", compression_type); 154// qDebug ("Image uses unknown compression, code 0x%x", compression_type);
155 return NULL; 155 return NULL;
156 } 156 }
157 157
158 /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps: 158 /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps:
159 159
160 1, 2, or 4 bit grayscale 160 1, 2, or 4 bit grayscale
161 8-bit StaticColor using the Palm standard colormap 161 8-bit StaticColor using the Palm standard colormap
162 8-bit PseudoColor using a user-specified colormap 162 8-bit PseudoColor using a user-specified colormap
163 16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue 163 16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue
164 164
165 Each of these can be compressed with one of four compression schemes, 165 Each of these can be compressed with one of four compression schemes,
166 "RLE", "Scanline", "PackBits", or none. 166 "RLE", "Scanline", "PackBits", or none.
167 167
168 We begin by constructing the colormap. 168 We begin by constructing the colormap.
169 */ 169 */
170 170
171 if (flags & PALM_HAS_COLORMAP_FLAG) { 171 if (flags & PALM_HAS_COLORMAP_FLAG) {
172// qDebug("Palm images with custom colormaps are not currently supported.\n"); 172// qDebug("Palm images with custom colormaps are not currently supported.\n");
173 return NULL; 173 return NULL;
174 } else if (bits_per_pixel == 1) { 174 } else if (bits_per_pixel == 1) {
175 colormap = Palm1BitColormap; 175 colormap = Palm1BitColormap;
176 imagedatastart = palmimage + 16; 176 imagedatastart = palmimage + 16;
177 } else if (bits_per_pixel == 2) { 177 } else if (bits_per_pixel == 2) {
178 colormap = Palm2BitColormap; 178 colormap = Palm2BitColormap;
179 imagedatastart = palmimage + 16; 179 imagedatastart = palmimage + 16;
180 } else if (bits_per_pixel == 4) { 180 } else if (bits_per_pixel == 4) {
181 colormap = Palm4BitColormap; 181 colormap = Palm4BitColormap;
182 imagedatastart = palmimage + 16; 182 imagedatastart = palmimage + 16;
183 } else if (bits_per_pixel == 8) { 183 } else if (bits_per_pixel == 8) {
184 colormap = Palm8BitColormap; 184 colormap = Palm8BitColormap;
185 imagedatastart = palmimage + 16; 185 imagedatastart = palmimage + 16;
186 } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) { 186 } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) {
187 colormap = NULL; 187 colormap = NULL;
188 palm_red_bits = palmimage[16]; 188 palm_red_bits = palmimage[16];
189 palm_green_bits = palmimage[17]; 189 palm_green_bits = palmimage[17];
190 palm_blue_bits = palmimage[18]; 190 palm_blue_bits = palmimage[18];
191// qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits); 191// qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits);
192 if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) { 192 if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) {
193// 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); 193// 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);
194 return NULL; 194 return NULL;
195 } 195 }
196 if (bits_per_pixel > (8 * sizeof(unsigned long))) { 196 if (bits_per_pixel > (8 * sizeof(unsigned long))) {
197// qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel); 197// qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel);
198 return NULL; 198 return NULL;
199 } 199 }
200 imagedatastart = palmimage + 24; 200 imagedatastart = palmimage + 24;
201 } else { 201 } else {
202// qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel); 202// qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel);
203 return NULL; 203 return NULL;
204 } 204 }
205 205
206#ifndef USEQPE 206#ifndef USEQPE
207 QImage* qimage = new QImage(width, height, 32); 207 QImage* qimage = new QImage(width, height, 32);
208#else 208#else
209 QImage* qimage = new QImage(width, height, 16); 209 QImage* qimage = new QImage(width, height, 16);
210#endif 210#endif
211 211
212 /* row by row, uncompress the Palm image and copy it to the JPEG buffer */ 212 /* row by row, uncompress the Palm image and copy it to the JPEG buffer */
213 rowbuf = new unsigned char[bytes_per_row * width]; 213 rowbuf = new unsigned char[bytes_per_row * width];
214 lastrow = new unsigned char[bytes_per_row * width]; 214 lastrow = new unsigned char[bytes_per_row * width];
215 215
216 for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) { 216 for (i=0, palm_ptr = imagedatastart , x_ptr = 0; i < height; ++i) {
217// qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row); 217// qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row);
218 218
219 /* first, uncompress the Palm image */ 219 /* first, uncompress the Palm image */
220 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { 220 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) {
221 for (j = 0; j < bytes_per_row; ) { 221 for (j = 0; j < bytes_per_row; ) {
222 incount = *palm_ptr++; 222 incount = *palm_ptr++;
223 inval = *palm_ptr++; 223 inval = *palm_ptr++;
224 memset(rowbuf + j, inval, incount); 224 memset(rowbuf + j, inval, incount);
225 j += incount; 225 j += incount;
226 } 226 }
227 } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) { 227 } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) {
228 for (j = 0; j < bytes_per_row; j += 8) { 228 for (j = 0; j < bytes_per_row; j += 8) {
229 incount = *palm_ptr++; 229 incount = *palm_ptr++;
230 inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8; 230 inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8;
231 for (inbit = 0; inbit < inval; inbit += 1) { 231 for (inbit = 0; inbit < inval; inbit += 1) {
232 if (incount & (1 << (7 - inbit))) 232 if (incount & (1 << (7 - inbit)))
233 rowbuf[j + inbit] = *palm_ptr++; 233 rowbuf[j + inbit] = *palm_ptr++;
234 else 234 else
235 rowbuf[j + inbit] = lastrow[j + inbit]; 235 rowbuf[j + inbit] = lastrow[j + inbit];
236 } 236 }
237 } 237 }
238 memcpy (lastrow, rowbuf, bytes_per_row); 238 memcpy (lastrow, rowbuf, bytes_per_row);
239 } else if (((flags & PALM_IS_COMPRESSED_FLAG) && 239 } else if (((flags & PALM_IS_COMPRESSED_FLAG) &&
240 (compression_type == PALM_COMPRESSION_NONE)) || 240 (compression_type == PALM_COMPRESSION_NONE)) ||
241 ((flags & PALM_IS_COMPRESSED_FLAG) == 0)) 241 ((flags & PALM_IS_COMPRESSED_FLAG) == 0))
242 { 242 {
243 memcpy (rowbuf, palm_ptr, bytes_per_row); 243 memcpy (rowbuf, palm_ptr, bytes_per_row);
244 palm_ptr += bytes_per_row; 244 palm_ptr += bytes_per_row;
245 } 245 }
246 else { 246 else {
247 qDebug("Case 4"); 247 qDebug("Case 4");
248 qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true"); 248 qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true");
249 qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true"); 249 qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true");
250 qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true"); 250 qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true");
251 qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true"); 251 qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true");
252 qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true"); 252 qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true");
253 memcpy (rowbuf, palm_ptr, bytes_per_row); 253 memcpy (rowbuf, palm_ptr, bytes_per_row);
254 palm_ptr += bytes_per_row; 254 palm_ptr += bytes_per_row;
255 } 255 }
256 /* next, write it to the GDK bitmap */ 256 /* next, write it to the GDK bitmap */
257 if (colormap) { 257 if (colormap) {
258 mask = (1 << bits_per_pixel) - 1; 258 mask = (1 << bits_per_pixel) - 1;
259 for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) { 259 for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) {
260 inval = ((*inbyte) & (mask << inbit)) >> inbit; 260 inval = ((*inbyte) & (mask << inbit)) >> inbit;
261 /* correct for oddity of the 8-bit color Palm pixmap... */ 261 /* correct for oddity of the 8-bit color Palm pixmap... */
262 if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231; 262 if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231;
263 /* now lookup the correct color and set the pixel in the GTK bitmap */ 263 /* now lookup the correct color and set the pixel in the GTK bitmap */
264 QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue); 264 QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue);
265 qimage->setPixel(j, i, colour); 265 qimage->setPixel(j, i, colour);
266 if (!inbit) { 266 if (!inbit) {
267 ++inbyte; 267 ++inbyte;
268 inbit = 8 - bits_per_pixel; 268 inbit = 8 - bits_per_pixel;
269 } else { 269 } else {
270 inbit -= bits_per_pixel; 270 inbit -= bits_per_pixel;
271 } 271 }
272 } 272 }
273 } else if (!colormap && 273 } else if (!colormap &&
274 bits_per_pixel == 16) { 274 bits_per_pixel == 16) {
275 for (inbyte = rowbuf, j = 0; j < width; ++j) { 275 for (inbyte = rowbuf, j = 0; j < width; ++j) {
276 inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1]; 276 inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1];
277 277
278/* 278/*
279 qDebug ("pixel is %d,%d (%d:%d:%d)", 279 qDebug ("pixel is %d,%d (%d:%d:%d)",
280 j, i, 280 j, i,
281 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), 281 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
282 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), 282 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
283 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)); 283 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
284*/ 284*/
285 QRgb colour = qRgb( 285 QRgb colour = qRgb(
286 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), 286 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
287 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), 287 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
288 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)); 288 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
289 qimage->setPixel(j, i, colour); 289 qimage->setPixel(j, i, colour);
290 inbyte += 2; 290 inbyte += 2;
291 } 291 }
292 } 292 }
293 } 293 }
294 294
295 delete [] rowbuf; 295 delete [] rowbuf;
296 delete [] lastrow; 296 delete [] lastrow;
297 297
298 return qimage; 298 return qimage;
299} 299}
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 0c56dd4..75da8ac 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -1,3492 +1,3492 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5** 5**
6** This file is part of an example program for Qt. This example 6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation. 7** program may be used, distributed and modified without limitation.
8** 8**
9*****************************************************************************/ 9*****************************************************************************/
10 10
11const int _SBARHEIGHT = 3; 11const int _SBARHEIGHT = 3;
12 12
13#include <qpainter.h> 13#include <qpainter.h>
14//#include <qdirectpainter_qws.h> 14//#include <qdirectpainter_qws.h>
15#include <qimage.h> 15#include <qimage.h>
16#include <qtimer.h> 16#include <qtimer.h>
17#include "config.h" 17#include "config.h"
18#include "QTReader.h" 18#include "QTReader.h"
19//#include "QTReaderApp.h" 19//#include "QTReaderApp.h"
20#include "CDrawBuffer.h" 20#include "CDrawBuffer.h"
21#ifdef USEQPE 21#ifdef USEQPE
22#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
23#endif 23#endif
24#include <math.h> 24#include <math.h>
25#include <ctype.h> 25#include <ctype.h>
26#include <stdio.h> //for sprintf 26#include <stdio.h> //for sprintf
27#ifdef USEQPE 27#ifdef USEQPE
28#include <qpe/config.h> 28#include <qpe/config.h>
29#include <qpe/applnk.h> 29#include <qpe/applnk.h>
30#include <qpe/global.h> 30#include <qpe/global.h>
31#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
32#endif 32#endif
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qdir.h> 34#include <qdir.h>
35#include "TableDialog.h" 35#include "TableDialog.h"
36#include "outputcodec.h" 36#include "outputcodec.h"
37 37
38/* 38/*
39#ifdef _UNICODE 39#ifdef _UNICODE
40const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; 40const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
41#else 41#else
42const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; 42const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
43#endif 43#endif
44*/ 44*/
45//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 }; 45//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 };
46 46
47//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 }; 47//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 };
48//const int QTReader::fontsizes[] = {10,16,17,22,0}; 48//const int QTReader::fontsizes[] = {10,16,17,22,0};
49//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; 49//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 };
50//const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0}; 50//const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0};
51 51
52tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 }; 52tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 };
53tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; 53tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
54//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; 54//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
55 55
56QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : 56QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
57 QWidget(parent, name, f | WRepaintNoErase | WResizeNoErase), 57 QWidget(parent, name, f | WRepaintNoErase | WResizeNoErase),
58 m_outofdate(true), 58 m_outofdate(true),
59 m_default_fg(0,0,0), 59 m_default_fg(0,0,0),
60 m_default_bg(255,255,255), 60 m_default_bg(255,255,255),
61 m_bg(255,255,255), 61 m_bg(255,255,255),
62 m_delay(100), 62 m_delay(100),
63 m_scrolldy1(0), 63 m_scrolldy1(0),
64 m_scrolldy2(0), 64 m_scrolldy2(0),
65 m_totalscroll(0), 65 m_totalscroll(0),
66 m_autoScroll(false), 66 m_autoScroll(false),
67 //textarray(NULL), 67 //textarray(NULL),
68 //locnarray(NULL), 68 //locnarray(NULL),
69 numlines(0), 69 numlines(0),
70 m_fontname("unifont"), 70 m_fontname("unifont"),
71 m_fm(NULL), 71 m_fm(NULL),
72 mouseUpOn(true), 72 mouseUpOn(true),
73 m_twotouch(true), 73 m_twotouch(true),
74 m_touchone(true), 74 m_touchone(true),
75 bDoUpdates(false), 75 bDoUpdates(false),
76#ifdef _SCROLLPIPE 76#ifdef _SCROLLPIPE
77 m_pipeout(NULL), 77 m_pipeout(NULL),
78#endif 78#endif
79 m_left_border(2), 79 m_left_border(2),
80 m_right_border(2), 80 m_right_border(2),
81 m_rotated(true), 81 m_rotated(true),
82 pBkmklist(NULL), 82 pBkmklist(NULL),
83 m_scrollpos(0), 83 m_scrollpos(0),
84 // bNegative(false), 84 // bNegative(false),
85 bInverse(false), 85 bInverse(false),
86 m_highlightfilter(NULL), 86 m_highlightfilter(NULL),
87 m_bgIsScaled(false), 87 m_bgIsScaled(false),
88 m_scrollstep(2), 88 m_scrollstep(2),
89 m_topmargin(5), 89 m_topmargin(5),
90 m_bottommargin(5), 90 m_bottommargin(5),
91 m_reparastring("{\\n[\\n ]}"), 91 m_reparastring("{\\n[\\n ]}"),
92 m_currentlinkstyle(NULL), 92 m_currentlinkstyle(NULL),
93 m_currentlinkoffset(-1), 93 m_currentlinkoffset(-1),
94 m_currentlink(-1) 94 m_currentlink(-1)
95{ 95{
96 m_output = NULL; 96 m_output = NULL;
97 m_overlap = 1; 97 m_overlap = 1;
98 setKeyCompression ( true ); 98 setKeyCompression ( true );
99 99
100 dbuff = NULL; 100 dbuff = NULL;
101 dbp = NULL; 101 dbp = NULL;
102} 102}
103 103
104/* 104/*
105QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : 105QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) :
106 QWidget(parent, name, f), 106 QWidget(parent, name, f),
107 m_textfont(0), 107 m_textfont(0),
108 m_textsize(1), 108 m_textsize(1),
109 textarray(NULL), 109 textarray(NULL),
110 numlines(0), 110 numlines(0),
111 bstripcr(true), 111 bstripcr(true),
112 bunindent(false), 112 bunindent(false),
113 brepara(false), 113 brepara(false),
114 bdblspce(false), 114 bdblspce(false),
115 btight(false), 115 btight(false),
116 bindenter(0), 116 bindenter(0),
117 m_fm(NULL) 117 m_fm(NULL)
118{ 118{
119 init(); 119 init();
120// // qDeb2ug("Load_file(1)"); 120// // qDeb2ug("Load_file(1)");
121 load_file((const tchar*)filename); 121 load_file((const tchar*)filename);
122} 122}
123*/ 123*/
124 124
125/* 125/*
126void QTReader::mouseMoveEvent(QMouseEvent* _e) 126void QTReader::mouseMoveEvent(QMouseEvent* _e)
127{ 127{
128 128
129 mouseUpOn = !(_e->pos().x() == -1); 129 mouseUpOn = !(_e->pos().x() == -1);
130 130
131 qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y()); 131 qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y());
132} 132}
133*/ 133*/
134long QTReader::real_delay() 134long QTReader::real_delay()
135{ 135{
136 return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); 136 return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
137} 137}
138 138
139void QTReader::mousePressEvent( QMouseEvent* _e ) 139void QTReader::mousePressEvent( QMouseEvent* _e )
140{ 140{
141 m_drageligible = false; 141 m_drageligible = false;
142 qDebug("Mouse pressed at (%u, %u)", _e->x(), _e->y()); 142 qDebug("Mouse pressed at (%u, %u)", _e->x(), _e->y());
143 int x, y, ht, wh; 143 int x, y, ht, wh;
144 if (m_rotated) 144 if (m_rotated)
145 { 145 {
146 x = _e->y(); 146 x = _e->y();
147 y = width()-_e->x(); 147 y = width()-_e->x();
148 ht = width(); 148 ht = width();
149 wh = height(); 149 wh = height();
150 } 150 }
151 else 151 else
152 { 152 {
153 x = _e->x(); 153 x = _e->x();
154 y = _e->y(); 154 y = _e->y();
155 ht = height(); 155 ht = height();
156 wh = width(); 156 wh = width();
157 } 157 }
158 if (x >= m_left_border && x <= wh - m_right_border && y >= m_topmargin && y <= ht-m_bottommargin) 158 if (x >= m_left_border && x <= wh - m_right_border && y >= m_topmargin && y <= ht-m_bottommargin)
159 { 159 {
160 if (_e->button() == RightButton) 160 if (_e->button() == RightButton)
161 { 161 {
162 //qDebug("MousePress"); 162 //qDebug("MousePress");
163 mouseUpOn = false; 163 mouseUpOn = false;
164 if (m_swapmouse) 164 if (m_swapmouse)
165 { 165 {
166 int lineno = 0; 166 int lineno = 0;
167 /* 167 /*
168 int hgt = textarray[0]->lineSpacing(); 168 int hgt = textarray[0]->lineSpacing();
169 while ((hgt < y) && (lineno < numlines)) 169 while ((hgt < y) && (lineno < numlines))
170 { 170 {
171 hgt += textarray[++lineno]->lineSpacing(); 171 hgt += textarray[++lineno]->lineSpacing();
172 } 172 }
173 */ 173 */
174 size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt; 174 size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt;
175 QImage* img; 175 QImage* img;
176 getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img, tabtgt); 176 getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img, tabtgt);
177 processmousewordevent(startpos, startoffset, _e, lineno); 177 processmousewordevent(startpos, startoffset, _e, lineno);
178 } 178 }
179 else 179 else
180 { 180 {
181 processmousepositionevent(_e); 181 processmousepositionevent(_e);
182 } 182 }
183 } 183 }
184 } 184 }
185 else 185 else
186 { 186 {
187 int ln = -1; 187 int ln = -1;
188 int mp; 188 int mp;
189 int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); 189 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
190 switch (m_scrollpos) 190 switch (m_scrollpos)
191 { 191 {
192 case 1: 192 case 1:
193 { 193 {
194 if (m_rotated) 194 if (m_rotated)
195 { 195 {
196 if (_e->x() < m_bottommargin) 196 if (_e->x() < m_bottommargin)
197 { 197 {
198 ln = height(); 198 ln = height();
199 mp = _e->y(); 199 mp = _e->y();
200 } 200 }
201 } 201 }
202 else 202 else
203 { 203 {
204 if (_e->y() > height()-m_bottommargin) 204 if (_e->y() > height()-m_bottommargin)
205 { 205 {
206 ln = width(); 206 ln = width();
207 mp = _e->x(); 207 mp = _e->x();
208 } 208 }
209 } 209 }
210 } 210 }
211 break; 211 break;
212 case 2: 212 case 2:
213 { 213 {
214 if (m_rotated) 214 if (m_rotated)
215 { 215 {
216 if (_e->y() > height() - m_right_border) 216 if (_e->y() > height() - m_right_border)
217 { 217 {
218 ln = width(); 218 ln = width();
219 mp = width()-_e->x(); 219 mp = width()-_e->x();
220 } 220 }
221 } 221 }
222 else 222 else
223 { 223 {
224 if (_e->x() > width() - m_right_border) 224 if (_e->x() > width() - m_right_border)
225 { 225 {
226 ln = height(); 226 ln = height();
227 mp = _e->y(); 227 mp = _e->y();
228 } 228 }
229 } 229 }
230 } 230 }
231 break; 231 break;
232 case 3: 232 case 3:
233 { 233 {
234 if (m_rotated) 234 if (m_rotated)
235 { 235 {
236 if (_e->y() < m_left_border) 236 if (_e->y() < m_left_border)
237 { 237 {
238 ln = width(); 238 ln = width();
239 mp = width()-_e->x(); 239 mp = width()-_e->x();
240 } 240 }
241 } 241 }
242 else 242 else
243 { 243 {
244 if (_e->x() < m_left_border) 244 if (_e->x() < m_left_border)
245 { 245 {
246 ln = height(); 246 ln = height();
247 mp = _e->y(); 247 mp = _e->y();
248 } 248 }
249 } 249 }
250 } 250 }
251 break; 251 break;
252 case 0: 252 case 0:
253 default: 253 default:
254 ln = -1; 254 ln = -1;
255 break; 255 break;
256 } 256 }
257 if (ln >= 0) 257 if (ln >= 0)
258 { 258 {
259 int dp = (sectionsize*mp+ln/2)/ln + buffdoc.startSection(); 259 int dp = (sectionsize*mp+ln/2)/ln + buffdoc.startSection();
260 int winsize = locnarray[numlines]-locnarray[0]; 260 int winsize = locnarray[numlines]-locnarray[0];
261 int slidersize = 10*(sectionsize+ln/2)/ln; 261 int slidersize = 10*(sectionsize+ln/2)/ln;
262 if (slidersize > winsize) 262 if (slidersize > winsize)
263 { 263 {
264 int mid = (locnarray[0] + locnarray[numlines])/2; 264 int mid = (locnarray[0] + locnarray[numlines])/2;
265 slidersize /= 2; 265 slidersize /= 2;
266 if (dp < mid-slidersize) 266 if (dp < mid-slidersize)
267 { 267 {
268 dopageup(); 268 dopageup();
269 } 269 }
270 else if (dp > mid+slidersize) 270 else if (dp > mid+slidersize)
271 { 271 {
272 dopagedn(); 272 dopagedn();
273 } 273 }
274 //if (mid-slidersize < dp && dp < mid+slidersize) 274 //if (mid-slidersize < dp && dp < mid+slidersize)
275 else 275 else
276 { 276 {
277 m_drageligible = true; 277 m_drageligible = true;
278 } 278 }
279 } 279 }
280 else 280 else
281 { 281 {
282 if (dp < locnarray[0]) 282 if (dp < locnarray[0])
283 { 283 {
284 dopageup(); 284 dopageup();
285 } 285 }
286 else if (dp > locnarray[numlines]) 286 else if (dp > locnarray[numlines])
287 { 287 {
288 dopagedn(); 288 dopagedn();
289 } 289 }
290 //if (locnarray[0] < dp && dp < locnarray[numlines]) 290 //if (locnarray[0] < dp && dp < locnarray[numlines])
291 else 291 else
292 { 292 {
293 m_drageligible = true; 293 m_drageligible = true;
294 } 294 }
295 } 295 }
296 qDebug("Drag eligible:%s", (m_drageligible) ? "true" : "false"); 296 qDebug("Drag eligible:%s", (m_drageligible) ? "true" : "false");
297 } 297 }
298 else 298 else
299 { 299 {
300 if (m_scrollpos == 1) 300 if (m_scrollpos == 1)
301 { 301 {
302 if (x < m_left_border) 302 if (x < m_left_border)
303 { 303 {
304 lineUp(); 304 lineUp();
305 } 305 }
306 if (y > ht - m_bottommargin) 306 if (y > ht - m_bottommargin)
307 { 307 {
308 lineDown(); 308 lineDown();
309 } 309 }
310 } 310 }
311 else if (m_scrollpos != 0) 311 else if (m_scrollpos != 0)
312 { 312 {
313 if (y < m_topmargin) 313 if (y < m_topmargin)
314 { 314 {
315 lineUp(); 315 lineUp();
316 } 316 }
317 if (y > ht - m_bottommargin) 317 if (y > ht - m_bottommargin)
318 { 318 {
319 lineDown(); 319 lineDown();
320 } 320 }
321 } 321 }
322 } 322 }
323 } 323 }
324} 324}
325 325
326void QTReader::processmousepositionevent( QMouseEvent* _e ) 326void QTReader::processmousepositionevent( QMouseEvent* _e )
327{ 327{
328 int x, y, ht, wh; 328 int x, y, ht, wh;
329 if (m_rotated) 329 if (m_rotated)
330 { 330 {
331 x = _e->y(); 331 x = _e->y();
332 y = width()-_e->x(); 332 y = width()-_e->x();
333 ht = width(); 333 ht = width();
334 wh = height(); 334 wh = height();
335 } 335 }
336 else 336 else
337 { 337 {
338 x = _e->x(); 338 x = _e->x();
339 y = _e->y(); 339 y = _e->y();
340 ht = height(); 340 ht = height();
341 wh = width(); 341 wh = width();
342 } 342 }
343 if (buffdoc.hasnavigation()) 343 if (buffdoc.hasnavigation())
344 { 344 {
345 if (y > (2*ht)/3) 345 if (y > (2*ht)/3)
346 { 346 {
347 goDown(); 347 goDown();
348 } 348 }
349 else if (y < ht/3) 349 else if (y < ht/3)
350 { 350 {
351 goUp(); 351 goUp();
352 } 352 }
353 else 353 else
354 { 354 {
355 if (x < wh/3) 355 if (x < wh/3)
356 { 356 {
357 goBack(); 357 goBack();
358 } 358 }
359 else if (x > (2*wh)/3) 359 else if (x > (2*wh)/3)
360 { 360 {
361 goForward(); 361 goForward();
362 } 362 }
363 else 363 else
364 { 364 {
365 goHome(); 365 goHome();
366 } 366 }
367 } 367 }
368 } 368 }
369 else 369 else
370 { 370 {
371 if (y > ht/2) 371 if (y > ht/2)
372 { 372 {
373 goDown(); 373 goDown();
374 } 374 }
375 else 375 else
376 { 376 {
377 goUp(); 377 goUp();
378 } 378 }
379 } 379 }
380} 380}
381 381
382void QTReader::goHome() 382void QTReader::goHome()
383{ 383{
384 if (buffdoc.hasnavigation()) 384 if (buffdoc.hasnavigation())
385 { 385 {
386 size_t current=pagelocate(); 386 size_t current=pagelocate();
387 size_t home=buffdoc.getHome(); 387 size_t home=buffdoc.getHome();
388 if (current!=home) 388 if (current!=home)
389 { 389 {
390 buffdoc.saveposn(m_lastfile, current); 390 buffdoc.saveposn(m_lastfile, current);
391 locate(home); 391 locate(home);
392 } 392 }
393 } 393 }
394 else 394 else
395 locate(0); 395 locate(0);
396} 396}
397 397
398void QTReader::goBack() 398void QTReader::goBack()
399{ 399{
400 if (buffdoc.hasnavigation()) 400 if (buffdoc.hasnavigation())
401 { 401 {
402 size_t target = pagelocate(); 402 size_t target = pagelocate();
403 QString nxt = m_lastfile; 403 QString nxt = m_lastfile;
404 buffdoc.writeposn(m_lastfile, target); 404 buffdoc.writeposn(m_lastfile, target);
405 linkType lt = buffdoc.back(nxt, target); 405 linkType lt = buffdoc.back(nxt, target);
406 if ((lt & eFile) != 0) 406 if ((lt & eFile) != 0)
407 { 407 {
408 if (nxt != m_lastfile) 408 if (nxt != m_lastfile)
409 { 409 {
410 emit NewFileRequest(nxt); 410 emit NewFileRequest(nxt);
411 } 411 }
412 locate(target); 412 locate(target);
413 } 413 }
414 else if ((lt & eLink) != 0) 414 else if ((lt & eLink) != 0)
415 { 415 {
416 locate(target); 416 locate(target);
417 } 417 }
418 } 418 }
419} 419}
420 420
421void QTReader::goForward() 421void QTReader::goForward()
422{ 422{
423 if (buffdoc.hasnavigation()) 423 if (buffdoc.hasnavigation())
424 { 424 {
425 size_t target = pagelocate(); 425 size_t target = pagelocate();
426 QString nxt = m_lastfile; 426 QString nxt = m_lastfile;
427 linkType lt = buffdoc.forward(nxt, target); 427 linkType lt = buffdoc.forward(nxt, target);
428 if ((lt & eFile) != 0) 428 if ((lt & eFile) != 0)
429 { 429 {
430 if (nxt != m_lastfile) 430 if (nxt != m_lastfile)
431 { 431 {
432 emit NewFileRequest(nxt); 432 emit NewFileRequest(nxt);
433 } 433 }
434 locate(target); 434 locate(target);
435 } 435 }
436 else if ((lt & eLink) != 0) 436 else if ((lt & eLink) != 0)
437 { 437 {
438 locate(target); 438 locate(target);
439 } 439 }
440 } 440 }
441} 441}
442 442
443linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t& start, size_t& offset, size_t& tgt, size_t& tgtoffset, size_t& pictgt, QImage*& img, size_t& tabtgt) 443linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t& start, size_t& offset, size_t& tgt, size_t& tgtoffset, size_t& pictgt, QImage*& img, size_t& tabtgt)
444{ 444{
445 int ht; 445 int ht;
446 if (m_scrolldy == m_topmargin) 446 if (m_scrolldy == m_topmargin)
447 { 447 {
448 lineno = 0; 448 lineno = 0;
449 ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin; 449 ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin;
450 } 450 }
451 else 451 else
452 { 452 {
453 if (y >= m_scrolldy) 453 if (y >= m_scrolldy)
454 { 454 {
455 lineno = 0; 455 lineno = 0;
456 ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy + m_topmargin; 456 ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy + m_topmargin;
457 } 457 }
458 else 458 else
459 { 459 {
460 lineno = 0; 460 lineno = 0;
461 ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy+m_topmargin; 461 ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy+m_topmargin;
462 while ((ht < h) && (lineno < numlines-1)) 462 while ((ht < h) && (lineno < numlines-1))
463 { 463 {
464 ht += textarray[++lineno]->lineSpacing(); 464 ht += textarray[++lineno]->lineSpacing();
465 } 465 }
466 ht = textarray[lineno]->lineSpacing(); 466 ht = textarray[lineno]->lineSpacing();
467 } 467 }
468 } 468 }
469 while ((ht < y) && (lineno < numlines-1)) 469 while ((ht < y) && (lineno < numlines-1))
470 { 470 {
471 ht += textarray[++lineno]->lineSpacing(); 471 ht += textarray[++lineno]->lineSpacing();
472 } 472 }
473 if (ht < y && textarray[numlines]->showPartial()) lineno = numlines; 473 if (ht < y && textarray[numlines]->showPartial()) lineno = numlines;
474 start = locnarray[lineno]; 474 start = locnarray[lineno];
475 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; 475 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
476 if (m_bMonoSpaced) 476 if (m_bMonoSpaced)
477 { 477 {
478 offset = (x - textarray[lineno]->offset(w, m_left_border, m_right_border, availht))/m_charWidth; 478 offset = (x - textarray[lineno]->offset(w, m_left_border, m_right_border, availht))/m_charWidth;
479 } 479 }
480 else 480 else
481 { 481 {
482 int i; 482 int i;
483 CDrawBuffer* t = textarray[lineno]; 483 CDrawBuffer* t = textarray[lineno];
484 x = x - t->offset(width(), m_left_border, m_right_border, availht); 484 x = x - t->offset(width(), m_left_border, m_right_border, availht);
485 for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--); 485 for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--);
486 offset = i; 486 offset = i;
487 } 487 }
488 return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img, tabtgt); 488 return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img, tabtgt);
489} 489}
490 490
491void QTReader::suspend() 491void QTReader::suspend()
492{ 492{
493 buffdoc.suspend(); 493 buffdoc.suspend();
494 /*#ifdef OPIE 494 /*#ifdef OPIE
495 if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend(); 495 if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend();
496#else 496#else
497 if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend(); 497 if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend();
498#endif 498#endif
499 */ 499 */
500} 500}
501 501
502void QTReader::setDoubleBuffer(bool _b) 502void QTReader::setDoubleBuffer(bool _b)
503{ 503{
504 m_doubleBuffered = _b; 504 m_doubleBuffered = _b;
505 if (_b || m_rotated) 505 if (_b || m_rotated)
506 { 506 {
507 if (dbuff == NULL) 507 if (dbuff == NULL)
508 { 508 {
509 dbuff = new QPixmap(); 509 dbuff = new QPixmap();
510 dbp = new QPainter(); 510 dbp = new QPainter();
511 } 511 }
512 if (m_rotated) 512 if (m_rotated)
513 { 513 {
514 dbuff->resize(height(), width()); 514 dbuff->resize(height(), width());
515 } 515 }
516 else 516 else
517 { 517 {
518 dbuff->resize(width(), height()); 518 dbuff->resize(width(), height());
519 } 519 }
520 m_outofdate = true; 520 m_outofdate = true;
521 } 521 }
522 else 522 else
523 { 523 {
524 if (dbuff != NULL) 524 if (dbuff != NULL)
525 { 525 {
526 delete dbuff; 526 delete dbuff;
527 delete dbp; 527 delete dbp;
528 } 528 }
529 dbuff = NULL; 529 dbuff = NULL;
530 dbp = NULL; 530 dbp = NULL;
531 } 531 }
532} 532}
533 533
534void QTReader::setTwoTouch(bool _b) 534void QTReader::setTwoTouch(bool _b)
535{ 535{
536 setBackgroundColor( m_bg ); 536 setBackgroundColor( m_bg );
537 m_twotouch = m_touchone = _b; 537 m_twotouch = m_touchone = _b;
538} 538}
539 539
540void QTReader::setContinuous(bool _b) 540void QTReader::setContinuous(bool _b)
541{ 541{
542 buffdoc.setContinuous(m_continuousDocument = _b); 542 buffdoc.setContinuous(m_continuousDocument = _b);
543} 543}
544 544
545void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno) 545void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno)
546{ 546{
547 unsigned long wrdstart, wrdend; 547 unsigned long wrdstart = 0, wrdend = 0;
548 QString wrd; 548 QString wrd;
549 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; 549 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
550 if (m_twotouch) 550 if (m_twotouch)
551 { 551 {
552 if (m_touchone) 552 if (m_touchone)
553 { 553 {
554 m_touchone = false; 554 m_touchone = false;
555 m_startpos = startpos; 555 m_startpos = startpos;
556 m_startoffset = startoffset; 556 m_startoffset = startoffset;
557 setBackgroundColor( lightGray ); 557 setBackgroundColor( lightGray );
558 } 558 }
559 else 559 else
560 { 560 {
561 m_touchone = true; 561 m_touchone = true;
562 setBackgroundColor( m_bg ); 562 setBackgroundColor( m_bg );
563 size_t endpos, endoffset; 563 size_t endpos, endoffset;
564 endpos = startpos; 564 endpos = startpos;
565 endoffset = startoffset; 565 endoffset = startoffset;
566 size_t currentpos = locate(); 566 size_t currentpos = locate();
567 if (endpos >= m_startpos) 567 if (endpos >= m_startpos)
568 { 568 {
569 jumpto(m_startpos); 569 jumpto(m_startpos);
570 for (int i = 0; i < m_startoffset; i++) 570 for (int i = 0; i < m_startoffset; i++)
571 { 571 {
572 getch(); 572 getch();
573 } 573 }
574 wrdstart = buffdoc.explocate(); 574 wrdstart = buffdoc.explocate();
575 if (m_startpos == endpos) 575 if (m_startpos == endpos)
576 { 576 {
577 for (int i = m_startoffset; i <= endoffset; i++) 577 for (int i = m_startoffset; i <= endoffset; i++)
578 { 578 {
579 wrd += QChar(getch()); 579 wrd += QChar(getch());
580 } 580 }
581 } 581 }
582 else 582 else
583 { 583 {
584 while (buffdoc.explocate() <= endpos) 584 while (buffdoc.explocate() <= endpos)
585 { 585 {
586 wrd += QChar(getch()); 586 wrd += QChar(getch());
587 } 587 }
588 for (int i = 0; i < endoffset; i++) 588 for (int i = 0; i < endoffset; i++)
589 { 589 {
590 wrd += QChar(getch()); 590 wrd += QChar(getch());
591 } 591 }
592 } 592 }
593 wrdend = buffdoc.explocate(); 593 wrdend = buffdoc.explocate();
594 jumpto(currentpos); 594 jumpto(currentpos);
595 } 595 }
596 } 596 }
597 } 597 }
598 else if (m_bMonoSpaced) 598 else if (m_bMonoSpaced)
599 { 599 {
600 int chno = (m_rotated) ? 600 int chno = (m_rotated) ?
601 (_e->y()-textarray[lineno]->offset(height(), m_left_border, m_right_border, availht))/m_charWidth 601 (_e->y()-textarray[lineno]->offset(height(), m_left_border, m_right_border, availht))/m_charWidth
602 : 602 :
603 (_e->x()-textarray[lineno]->offset(width(), m_left_border, m_right_border, availht))/m_charWidth; 603 (_e->x()-textarray[lineno]->offset(width(), m_left_border, m_right_border, availht))/m_charWidth;
604 if (chno < ustrlen(textarray[lineno]->data())) 604 if (chno < ustrlen(textarray[lineno]->data()))
605 { 605 {
606 wrd[0] = textarray[lineno]->data()[chno]; 606 wrd[0] = textarray[lineno]->data()[chno];
607 } 607 }
608 } 608 }
609 else 609 else
610 { 610 {
611 CDrawBuffer* t = textarray[lineno]; 611 CDrawBuffer* t = textarray[lineno];
612 int first = 0; 612 int first = 0;
613 int tgt = (m_rotated) ? 613 int tgt = (m_rotated) ?
614 _e->y() - t->offset(height(), m_left_border, m_right_border, availht) : 614 _e->y() - t->offset(height(), m_left_border, m_right_border, availht) :
615 _e->x() - t->offset(width(), m_left_border, m_right_border, availht); 615 _e->x() - t->offset(width(), m_left_border, m_right_border, availht);
616 while (1) 616 while (1)
617 { 617 {
618 int i = first+1; 618 int i = first+1;
619 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; 619 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
620 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 620 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
621 if (t->width(availht, i, true, (m_rotated) ? height() : width(), m_left_border, m_right_border) > tgt) 621 if (t->width(availht, i, true, (m_rotated) ? height() : width(), m_left_border, m_right_border) > tgt)
622 { 622 {
623 wrd = toQString(t->data()+first, i - first); 623 wrd = toQString(t->data()+first, i - first);
624 // qDebug("Got %s", (const char *)wrd); 624 // qDebug("Got %s", (const char *)wrd);
625 break; 625 break;
626 } 626 }
627 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 627 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
628 if ((*t)[i] == 0) break; 628 if ((*t)[i] == 0) break;
629 first = i; 629 first = i;
630 } 630 }
631 } 631 }
632 if (!wrd.isEmpty()) 632 if (!wrd.isEmpty())
633 { 633 {
634 qDebug("Selected:%s", (const char*)wrd); 634 qDebug("Selected:%s", (const char*)wrd);
635 if (m_twotouch) 635 if (m_twotouch)
636 { 636 {
637 emit OnWordSelected(wrd, wrdstart, wrdend, wrd); 637 emit OnWordSelected(wrd, wrdstart, wrdend, wrd);
638 } 638 }
639 else 639 else
640 { 640 {
641 QString line = toQString(textarray[lineno]->data()); 641 QString line = toQString(textarray[lineno]->data());
642 emit OnWordSelected(wrd, locnarray[lineno], locnarray[lineno]+line.length(), line); 642 emit OnWordSelected(wrd, locnarray[lineno], locnarray[lineno]+line.length(), line);
643 } 643 }
644 } 644 }
645} 645}
646 646
647#ifdef USETIMER 647#ifdef USETIMER
648void QTReader::actionDrag() 648void QTReader::actionDrag()
649{ 649{
650 if (m_drageligible) 650 if (m_drageligible)
651 { 651 {
652 int fivepages = 5*((2*width()+m_textsize/2)/m_textsize)*((height()+m_textsize/2)/m_textsize); 652 int fivepages = 5*((2*width()+m_textsize/2)/m_textsize)*((height()+m_textsize/2)/m_textsize);
653 if (m_dragtarget > fivepages && locnarray[numlines] < m_dragtarget - fivepages) 653 if (m_dragtarget > fivepages && locnarray[numlines] < m_dragtarget - fivepages)
654 { 654 {
655 int tgt = m_dragtarget - fivepages/2; 655 int tgt = m_dragtarget - fivepages/2;
656 //qDebug("Jumping to %u (%u)", tgt, fivepages); 656 //qDebug("Jumping to %u (%u)", tgt, fivepages);
657 if (tgt < buffdoc.startSection()) 657 if (tgt < buffdoc.startSection())
658 { 658 {
659 tgt = buffdoc.startSection(); 659 tgt = buffdoc.startSection();
660 } 660 }
661 locate(tgt); 661 locate(tgt);
662 drawFonts(); 662 drawFonts();
663 } 663 }
664 else if (locnarray[0] > m_dragtarget+fivepages) 664 else if (locnarray[0] > m_dragtarget+fivepages)
665 { 665 {
666 int tgt = m_dragtarget + fivepages/2; 666 int tgt = m_dragtarget + fivepages/2;
667 //qDebug("Jumping to %u (%u)", tgt, fivepages); 667 //qDebug("Jumping to %u (%u)", tgt, fivepages);
668 if (tgt > buffdoc.endSection()) 668 if (tgt > buffdoc.endSection())
669 { 669 {
670 dopageup(); 670 dopageup();
671 } 671 }
672 else 672 else
673 { 673 {
674 locate(tgt); 674 locate(tgt);
675 drawFonts(); 675 drawFonts();
676 } 676 }
677 } 677 }
678 else if (locnarray[numlines] <= m_dragtarget) 678 else if (locnarray[numlines] <= m_dragtarget)
679 { 679 {
680 dopagedn(); 680 dopagedn();
681 } 681 }
682 else if (locnarray[0] > m_dragtarget) 682 else if (locnarray[0] > m_dragtarget)
683 { 683 {
684 dopageup(); 684 dopageup();
685 } 685 }
686 } 686 }
687 else 687 else
688 { 688 {
689 m_dragtimer->stop(); 689 m_dragtimer->stop();
690 } 690 }
691} 691}
692#endif 692#endif
693 693
694void QTReader::mouseMoveEvent( QMouseEvent* _e ) 694void QTReader::mouseMoveEvent( QMouseEvent* _e )
695{ 695{
696 if (m_drageligible) 696 if (m_drageligible)
697 { 697 {
698 int ht; 698 int ht;
699 int mp; 699 int mp;
700 int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); 700 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
701 //qDebug("Mouse moved to (%u, %u)", _e->x(), _e->y()); 701 //qDebug("Mouse moved to (%u, %u)", _e->x(), _e->y());
702 switch (m_scrollpos) 702 switch (m_scrollpos)
703 { 703 {
704 case 1: 704 case 1:
705 { 705 {
706 if (m_rotated) 706 if (m_rotated)
707 { 707 {
708 ht = height(); 708 ht = height();
709 mp = _e->y(); 709 mp = _e->y();
710 } 710 }
711 else 711 else
712 { 712 {
713 ht = width(); 713 ht = width();
714 mp = _e->x(); 714 mp = _e->x();
715 } 715 }
716 } 716 }
717 break; 717 break;
718 case 2: 718 case 2:
719 case 3: 719 case 3:
720 { 720 {
721 if (m_rotated) 721 if (m_rotated)
722 { 722 {
723 ht = width(); 723 ht = width();
724 mp = width()-_e->x(); 724 mp = width()-_e->x();
725 } 725 }
726 else 726 else
727 { 727 {
728 ht = height(); 728 ht = height();
729 mp = _e->y(); 729 mp = _e->y();
730 } 730 }
731 } 731 }
732 break; 732 break;
733 case 0: 733 case 0:
734 default: 734 default:
735 ht = -1; 735 ht = -1;
736 break; 736 break;
737 } 737 }
738 if (ht >= 0) 738 if (ht >= 0)
739 { 739 {
740#ifdef USETIMER 740#ifdef USETIMER
741 m_dragtarget = (sectionsize*mp+ht/2)/ht + buffdoc.startSection(); 741 m_dragtarget = (sectionsize*mp+ht/2)/ht + buffdoc.startSection();
742 if (!m_dragtimer->isActive()) 742 if (!m_dragtimer->isActive())
743 { 743 {
744 m_dragtimer->start(0, false); 744 m_dragtimer->start(0, false);
745 } 745 }
746#else 746#else
747 int dp = (sectionsize*mp+ht/2)/ht + buffdoc.startSection(); 747 int dp = (sectionsize*mp+ht/2)/ht + buffdoc.startSection();
748 locate(dp); 748 locate(dp);
749#endif 749#endif
750 } 750 }
751 } 751 }
752} 752}
753 753
754void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 754void QTReader::mouseReleaseEvent( QMouseEvent* _e )
755{ 755{
756 qDebug("Mouse released at (%u, %u)", _e->x(), _e->y()); 756 qDebug("Mouse released at (%u, %u)", _e->x(), _e->y());
757 if (m_drageligible) 757 if (m_drageligible)
758 { 758 {
759 m_drageligible = false; 759 m_drageligible = false;
760 } 760 }
761 else 761 else
762 { 762 {
763 int x, y, ht, wh; 763 int x, y, ht, wh;
764 if (m_rotated) 764 if (m_rotated)
765 { 765 {
766 x = _e->y(); 766 x = _e->y();
767 y = width()-_e->x(); 767 y = width()-_e->x();
768 ht = width(); 768 ht = width();
769 wh = height(); 769 wh = height();
770 } 770 }
771 else 771 else
772 { 772 {
773 x = _e->x(); 773 x = _e->x();
774 y = _e->y(); 774 y = _e->y();
775 ht = height(); 775 ht = height();
776 wh = width(); 776 wh = width();
777 } 777 }
778 if (_e->button() == LeftButton) 778 if (_e->button() == LeftButton)
779 { 779 {
780 if (mouseUpOn) 780 if (mouseUpOn)
781 { 781 {
782 // qDebug("MouseRelease"); 782 // qDebug("MouseRelease");
783 /* 783 /*
784 switch(m_scrollpos) 784 switch(m_scrollpos)
785 { 785 {
786 case 1: // Bottom 786 case 1: // Bottom
787 if (y > ht - 5) 787 if (y > ht - 5)
788 { 788 {
789 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh); 789 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh);
790 return; 790 return;
791 } 791 }
792 break; 792 break;
793 case 2: // right 793 case 2: // right
794 if (x > wh - m_right_border) 794 if (x > wh - m_right_border)
795 { 795 {
796 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht); 796 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
797 return; 797 return;
798 } 798 }
799 break; 799 break;
800 case 3: // left 800 case 3: // left
801 if (x < m_left_border) 801 if (x < m_left_border)
802 { 802 {
803 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht); 803 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
804 return; 804 return;
805 } 805 }
806 break; 806 break;
807 case 0: 807 case 0:
808 default: 808 default:
809 break; 809 break;
810 } 810 }
811 */ 811 */
812 if (textarray[0] != NULL) 812 if (textarray[0] != NULL)
813 { 813 {
814 QString line; 814 QString line;
815 // int lineno = _e->y()/m_linespacing; 815 // int lineno = _e->y()/m_linespacing;
816 int lineno = 0; 816 int lineno = 0;
817 /* 817 /*
818 int ht = textarray[0]->lineSpacing(); 818 int ht = textarray[0]->lineSpacing();
819 while ((ht < y) && (lineno < numlines)) 819 while ((ht < y) && (lineno < numlines))
820 { 820 {
821 ht += textarray[++lineno]->lineSpacing(); 821 ht += textarray[++lineno]->lineSpacing();
822 } 822 }
823 */ 823 */
824 size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt; 824 size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt;
825 QImage* img; 825 QImage* img;
826 if (m_currentlinkstyle != NULL) 826 if (m_currentlinkstyle != NULL)
827 { 827 {
828 textarray[m_currentlink]->invertLink(m_currentlinkoffset); 828 textarray[m_currentlink]->invertLink(m_currentlinkoffset);
829 m_currentlinkstyle = NULL; 829 m_currentlinkstyle = NULL;
830 m_currentlink = -1; 830 m_currentlink = -1;
831 m_currentlinkoffset = -1; 831 m_currentlinkoffset = -1;
832 } 832 }
833 linkType glt = getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img, tabtgt); 833 linkType glt = getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img, tabtgt);
834 if (bNoInlineTables && ((glt & eTable) != 0)) 834 if (bNoInlineTables && ((glt & eTable) != 0))
835 { 835 {
836 size_t currentpos = locate(); 836 size_t currentpos = locate();
837 QString tabtext = buffdoc.getTableAsHtml(tabtgt); 837 QString tabtext = buffdoc.getTableAsHtml(tabtgt);
838 qDebug("TABLE:%u:%u:%s", currentpos, tabtgt, (const char*)tabtext); 838 qDebug("TABLE:%u:%u:%s", currentpos, tabtgt, (const char*)tabtext);
839 QFont f(m_fontname, m_fontControl.currentsize()); 839 QFont f(m_fontname, m_fontControl.currentsize());
840#ifdef USEQPE 840#ifdef USEQPE
841 CTableDialog td(f, tabtext, true, this); 841 CTableDialog td(f, tabtext, true, this);
842#else 842#else
843 CTableDialog td(f, tabtext, false, this); 843 CTableDialog td(f, tabtext, false, this);
844#endif 844#endif
845 td.exec(); 845 td.exec();
846 jumpto(currentpos); 846 jumpto(currentpos);
847 } 847 }
848 if ((glt & eLink) != 0) 848 if ((glt & eLink) != 0)
849 { 849 {
850 if ((glt & ePicture) != 0) 850 if ((glt & ePicture) != 0)
851 { 851 {
852 qDebug("Big Picture:%x", pictgt); 852 qDebug("Big Picture:%x", pictgt);
853 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0) 853 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
854 { 854 {
855 QImage* pm = buffdoc.getPicture(pictgt); 855 QImage* pm = buffdoc.getPicture(pictgt);
856 if (pm != NULL) 856 if (pm != NULL)
857 { 857 {
858 emit OnShowPicture(*pm); 858 emit OnShowPicture(*pm);
859 delete pm; 859 delete pm;
860 return; 860 return;
861 } 861 }
862 } 862 }
863 } 863 }
864 else if (img != NULL) 864 else if (img != NULL)
865 { 865 {
866 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0) 866 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
867 { 867 {
868 emit OnShowPicture(*img); 868 emit OnShowPicture(*img);
869 return; 869 return;
870 } 870 }
871 } 871 }
872 size_t saveposn = pagelocate(); 872 size_t saveposn = pagelocate();
873 QString href, nm; 873 QString href, nm;
874 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm); 874 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm);
875 qDebug("URL(1):%s", (const char*)href); 875 qDebug("URL(1):%s", (const char*)href);
876 if ((lt & eFile) != 0) 876 if ((lt & eFile) != 0)
877 { 877 {
878 buffdoc.saveposn(m_lastfile, saveposn); 878 buffdoc.saveposn(m_lastfile, saveposn);
879#ifdef USEQPE 879#ifdef USEQPE
880 { 880 {
881 QCopEnvelope e("QPE/System", "busy()"); 881 QCopEnvelope e("QPE/System", "busy()");
882 } 882 }
883#endif 883#endif
884 ResetScroll(); 884 ResetScroll();
885 if (!href.isEmpty()) 885 if (!href.isEmpty())
886 { 886 {
887 if (!buffdoc.getFile(href, nm)) 887 if (!buffdoc.getFile(href, nm))
888 { 888 {
889 emit NewFileRequest(href); 889 emit NewFileRequest(href);
890 } 890 }
891 else 891 else
892 { 892 {
893 qDebug("BEFORE:%u", pagelocate()); 893 qDebug("BEFORE:%u", pagelocate());
894 buffdoc.resetPos(); 894 buffdoc.resetPos();
895 ResetScroll(); 895 ResetScroll();
896 fillbuffer(); 896 fillbuffer();
897 qDebug("AFTER:%u", pagelocate()); 897 qDebug("AFTER:%u", pagelocate());
898 m_outofdate = true; 898 m_outofdate = true;
899 update(); 899 update();
900 } 900 }
901 } 901 }
902 if (!nm.isEmpty()) 902 if (!nm.isEmpty())
903 { 903 {
904 qDebug("QTReader:Finding %s", (const char*)nm); 904 qDebug("QTReader:Finding %s", (const char*)nm);
905 if (buffdoc.findanchor(nm)) 905 if (buffdoc.findanchor(nm))
906 { 906 {
907 buffdoc.resetPos(); 907 buffdoc.resetPos();
908 fillbuffer(); 908 fillbuffer();
909 m_outofdate = true; 909 m_outofdate = true;
910 update(); 910 update();
911 } 911 }
912 } 912 }
913 //fillbuffer(); 913 //fillbuffer();
914 //update(); 914 //update();
915#ifdef USEQPE 915#ifdef USEQPE
916 { 916 {
917 QCopEnvelope e("QPE/System", "notBusy()"); 917 QCopEnvelope e("QPE/System", "notBusy()");
918 } 918 }
919#endif 919#endif
920 } 920 }
921 else if ((lt & eLink) != 0) 921 else if ((lt & eLink) != 0)
922 { 922 {
923 buffdoc.saveposn(m_lastfile, saveposn); 923 buffdoc.saveposn(m_lastfile, saveposn);
924 ResetScroll(); 924 ResetScroll();
925 fillbuffer(); 925 fillbuffer();
926 m_outofdate = true; 926 m_outofdate = true;
927 update(); 927 update();
928 } 928 }
929 else 929 else
930 { 930 {
931 if ((lt & ePicture) != 0) 931 if ((lt & ePicture) != 0)
932 { 932 {
933 QImage* pm = buffdoc.getPicture(tgt); 933 QImage* pm = buffdoc.getPicture(tgt);
934 if (pm != NULL) 934 if (pm != NULL)
935 { 935 {
936 emit OnShowPicture(*pm); 936 emit OnShowPicture(*pm);
937 delete pm; 937 delete pm;
938 } 938 }
939 } 939 }
940 else 940 else
941 { 941 {
942 // QString anchortext = textarray[lineno]->getanchortext(startoffset); 942 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
943 if (!href.isEmpty()) 943 if (!href.isEmpty())
944 { 944 {
945 emit OnURLSelected(href, tgt); 945 emit OnURLSelected(href, tgt);
946 } 946 }
947 } 947 }
948 } 948 }
949 return; 949 return;
950 } 950 }
951 else if ((glt & ePicture) != 0) 951 else if ((glt & ePicture) != 0)
952 { 952 {
953 qDebug("Big Picture:%x", pictgt); 953 qDebug("Big Picture:%x", pictgt);
954 QImage* pm = buffdoc.getPicture(pictgt); 954 QImage* pm = buffdoc.getPicture(pictgt);
955 if (pm != NULL) 955 if (pm != NULL)
956 { 956 {
957 emit OnShowPicture(*pm); 957 emit OnShowPicture(*pm);
958 delete pm; 958 delete pm;
959 } 959 }
960 else 960 else
961 { 961 {
962 update(); 962 update();
963 } 963 }
964 return; 964 return;
965 } 965 }
966 else if (img != NULL) 966 else if (img != NULL)
967 { 967 {
968 emit OnShowPicture(*img); 968 emit OnShowPicture(*img);
969 return; 969 return;
970 } 970 }
971 if (m_swapmouse) 971 if (m_swapmouse)
972 processmousepositionevent(_e); 972 processmousepositionevent(_e);
973 else 973 else
974 processmousewordevent(startpos, startoffset, _e, lineno); 974 processmousewordevent(startpos, startoffset, _e, lineno);
975 } 975 }
976 } 976 }
977 else 977 else
978 { 978 {
979 mouseUpOn = true; 979 mouseUpOn = true;
980 } 980 }
981 } 981 }
982 } 982 }
983} 983}
984 984
985void QTReader::focusInEvent(QFocusEvent* e) 985void QTReader::focusInEvent(QFocusEvent* e)
986{ 986{
987 if (m_autoScroll && (m_scrolltype != 4)) timer->start(real_delay(), false); 987 if (m_autoScroll && (m_scrolltype != 4)) timer->start(real_delay(), false);
988 update(); 988 update();
989} 989}
990 990
991void QTReader::focusOutEvent(QFocusEvent* e) 991void QTReader::focusOutEvent(QFocusEvent* e)
992{ 992{
993 if (m_autoScroll) 993 if (m_autoScroll)
994 { 994 {
995 if (m_scrolltype != 4) 995 if (m_scrolltype != 4)
996 { 996 {
997 timer->stop(); 997 timer->stop();
998 } 998 }
999 else 999 else
1000 { 1000 {
1001 m_autoScroll = false; 1001 m_autoScroll = false;
1002 } 1002 }
1003 //m_scrolldy1 = m_scrolldy2 = 0; 1003 //m_scrolldy1 = m_scrolldy2 = 0;
1004 } 1004 }
1005} 1005}
1006 1006
1007#include <qapplication.h> 1007#include <qapplication.h>
1008#include <qdrawutil.h> 1008#include <qdrawutil.h>
1009#ifndef _WINDOWS 1009#ifndef _WINDOWS
1010#include <unistd.h> 1010#include <unistd.h>
1011#endif 1011#endif
1012 1012
1013void QTReader::goDown() 1013void QTReader::goDown()
1014{ 1014{
1015 if (m_bpagemode) 1015 if (m_bpagemode)
1016 { 1016 {
1017 dopagedn(); 1017 dopagedn();
1018 } 1018 }
1019 else 1019 else
1020 { 1020 {
1021 lineDown(); 1021 lineDown();
1022 } 1022 }
1023} 1023}
1024 1024
1025void QTReader::goUp() 1025void QTReader::goUp()
1026{ 1026{
1027 if (m_bpagemode) 1027 if (m_bpagemode)
1028 { 1028 {
1029 dopageup(); 1029 dopageup();
1030 } 1030 }
1031 else 1031 else
1032 { 1032 {
1033 lineUp(); 1033 lineUp();
1034 } 1034 }
1035} 1035}
1036 1036
1037void QTReader::NavUp() 1037void QTReader::NavUp()
1038{ 1038{
1039 if (buffdoc.hasnavigation()) 1039 if (buffdoc.hasnavigation())
1040 { 1040 {
1041/* 1041/*
1042 size_t target = pagelocate(); 1042 size_t target = pagelocate();
1043 if (buffdoc.back(target)) 1043 if (buffdoc.back(target))
1044 { 1044 {
1045 locate(target); 1045 locate(target);
1046 } 1046 }
1047*/ 1047*/
1048 locate(buffdoc.startSection()); 1048 locate(buffdoc.startSection());
1049 } 1049 }
1050 else 1050 else
1051 { 1051 {
1052 goUp(); 1052 goUp();
1053 } 1053 }
1054} 1054}
1055 1055
1056void QTReader::NavDown() 1056void QTReader::NavDown()
1057{ 1057{
1058 if (buffdoc.hasnavigation()) 1058 if (buffdoc.hasnavigation())
1059 { 1059 {
1060/* 1060/*
1061 size_t target = pagelocate(); 1061 size_t target = pagelocate();
1062 if (buffdoc.forward(target)) 1062 if (buffdoc.forward(target))
1063 { 1063 {
1064 locate(target); 1064 locate(target);
1065 } 1065 }
1066*/ 1066*/
1067 dopageup(buffdoc.endSection()); 1067 dopageup(buffdoc.endSection());
1068 } 1068 }
1069 else 1069 else
1070 { 1070 {
1071 goDown(); 1071 goDown();
1072 } 1072 }
1073} 1073}
1074 1074
1075void QTReader::zoomin() 1075void QTReader::zoomin()
1076{ 1076{
1077 if (m_fontControl.increasesize()) 1077 if (m_fontControl.increasesize())
1078 { 1078 {
1079 bool sc = m_autoScroll; 1079 bool sc = m_autoScroll;
1080 setautoscroll(false); 1080 setautoscroll(false);
1081 setfont(); 1081 setfont();
1082 refresh(); 1082 refresh();
1083 setautoscroll(sc); 1083 setautoscroll(sc);
1084 } 1084 }
1085} 1085}
1086 1086
1087void QTReader::zoomout() 1087void QTReader::zoomout()
1088{ 1088{
1089 if (m_fontControl.decreasesize()) 1089 if (m_fontControl.decreasesize())
1090 { 1090 {
1091 bool sc = m_autoScroll; 1091 bool sc = m_autoScroll;
1092 setautoscroll(false); 1092 setautoscroll(false);
1093 setfont(); 1093 setfont();
1094 refresh(); 1094 refresh();
1095 setautoscroll(sc); 1095 setautoscroll(sc);
1096 } 1096 }
1097} 1097}
1098 1098
1099void QTReader::reduceScroll() 1099void QTReader::reduceScroll()
1100{ 1100{
1101 if (m_delay < 59049) 1101 if (m_delay < 59049)
1102 { 1102 {
1103 m_delay = (3*m_delay)/2; 1103 m_delay = (3*m_delay)/2;
1104 timer->changeInterval(real_delay()); 1104 timer->changeInterval(real_delay());
1105 } 1105 }
1106 else 1106 else
1107 { 1107 {
1108 m_delay = 59049; 1108 m_delay = 59049;
1109 } 1109 }
1110} 1110}
1111 1111
1112void QTReader::increaseScroll() 1112void QTReader::increaseScroll()
1113{ 1113{
1114 if (m_delay > 454) 1114 if (m_delay > 454)
1115 { 1115 {
1116 m_delay = (2*m_delay)/3; 1116 m_delay = (2*m_delay)/3;
1117 timer->changeInterval(real_delay()); 1117 timer->changeInterval(real_delay());
1118 } 1118 }
1119 else 1119 else
1120 { 1120 {
1121 m_delay = 454; 1121 m_delay = 454;
1122 } 1122 }
1123} 1123}
1124 1124
1125void QTReader::keyPressEvent(QKeyEvent* e) 1125void QTReader::keyPressEvent(QKeyEvent* e)
1126{ 1126{
1127 1127
1128 //((QTReaderApp*)parent()->parent())->handlekey(e); 1128 //((QTReaderApp*)parent()->parent())->handlekey(e);
1129 emit HandleKeyRequest(e); 1129 emit HandleKeyRequest(e);
1130// e->ignore(); 1130// e->ignore();
1131 return; 1131 return;
1132#ifdef _SCROLLPIPE 1132#ifdef _SCROLLPIPE
1133 if (m_isPaused) 1133 if (m_isPaused)
1134 { 1134 {
1135 m_isPaused = false; 1135 m_isPaused = false;
1136 if (e->key() != Key_Space) 1136 if (e->key() != Key_Space)
1137 { 1137 {
1138 m_autoScroll = false; 1138 m_autoScroll = false;
1139 if (m_pipeout != NULL) 1139 if (m_pipeout != NULL)
1140 { 1140 {
1141 pclose(m_pipeout); 1141 pclose(m_pipeout);
1142 m_pipeout = NULL; 1142 m_pipeout = NULL;
1143 } 1143 }
1144 //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); 1144 //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
1145 emit SetScrollState(m_autoScroll); 1145 emit SetScrollState(m_autoScroll);
1146 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1146 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1147 } 1147 }
1148 else 1148 else
1149 { 1149 {
1150 timer->start(real_delay(), false); 1150 timer->start(real_delay(), false);
1151 } 1151 }
1152 e->accept(); 1152 e->accept();
1153 return; 1153 return;
1154 } 1154 }
1155#endif 1155#endif
1156} 1156}
1157 1157
1158void QTReader::CalculateScrollParameters() 1158void QTReader::CalculateScrollParameters()
1159{ 1159{
1160 int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); 1160 int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1161 if (bmargin < m_bottommargin) bmargin = m_bottommargin; 1161 if (bmargin < m_bottommargin) bmargin = m_bottommargin;
1162 switch (m_scrolltype) 1162 switch (m_scrolltype)
1163 { 1163 {
1164 case 0: 1164 case 0:
1165 { 1165 {
1166 if (m_scrolldy == m_topmargin) 1166 if (m_scrolldy == m_topmargin)
1167 { 1167 {
1168 m_scrolldy1 = 0; 1168 m_scrolldy1 = 0;
1169 m_scrolldy2 = 0; 1169 m_scrolldy2 = 0;
1170 m_totalscroll = 0; 1170 m_totalscroll = 0;
1171 return; 1171 return;
1172 } 1172 }
1173 if (m_scrolldy < textarray[0]->lineSpacing()) 1173 if (m_scrolldy < textarray[0]->lineSpacing())
1174 { 1174 {
1175 m_scrolldy2 = m_scrolldy; 1175 m_scrolldy2 = m_scrolldy;
1176 return; 1176 return;
1177 } 1177 }
1178 int ht = m_scrolldy - m_scrolldy1; 1178 int ht = m_scrolldy - m_scrolldy1;
1179 int i; 1179 int i;
1180 for (i = 0; (ht < ((m_rotated) ? width() : height())-bmargin) && (i < numlines); i++) 1180 for (i = 0; (ht < ((m_rotated) ? width() : height())-bmargin) && (i < numlines); i++)
1181 { 1181 {
1182 ht += textarray[i]->lineSpacing(); 1182 ht += textarray[i]->lineSpacing();
1183 } 1183 }
1184 ht = 0; 1184 ht = 0;
1185 int j; 1185 int j;
1186 i--; 1186 i--;
1187 for (j = i; j < numlines; j++) 1187 for (j = i; j < numlines; j++)
1188 { 1188 {
1189 ht += textarray[j]->lineSpacing(); 1189 ht += textarray[j]->lineSpacing();
1190 } 1190 }
1191 ht -= ( 1191 ht -= (
1192 textarray[i]->lineExtraSpacing() 1192 textarray[i]->lineExtraSpacing()
1193 + 1193 +
1194 (i != 0) ? textarray[numlines-1]->lineExtraSpacing() : 0 1194 (i != 0) ? textarray[numlines-1]->lineExtraSpacing() : 0
1195 )/2-2; 1195 )/2-2;
1196 1196
1197 m_scrolldy2 = m_scrolldy-ht; 1197 m_scrolldy2 = m_scrolldy-ht;
1198 } 1198 }
1199 break; 1199 break;
1200 case 1: 1200 case 1:
1201 case 2: 1201 case 2:
1202 case 3: 1202 case 3:
1203 { 1203 {
1204 int ypos = m_topmargin; 1204 int ypos = m_topmargin;
1205 for (int i = 0; i < numlines; i++) 1205 for (int i = 0; i < numlines; i++)
1206 { 1206 {
1207 ypos += textarray[i]->lineSpacing(); 1207 ypos += textarray[i]->lineSpacing();
1208 } 1208 }
1209 ypos -= ( 1209 ypos -= (
1210 textarray[0]->lineExtraSpacing() 1210 textarray[0]->lineExtraSpacing()
1211 + 1211 +
1212 ((numlines > 1) ? textarray[numlines-1]->lineExtraSpacing() : 0) 1212 ((numlines > 1) ? textarray[numlines-1]->lineExtraSpacing() : 0)
1213 )/2 + 1213 )/2 +
1214 m_scrolldy1 - 2; 1214 m_scrolldy1 - 2;
1215 m_scrolldy2 = ((m_rotated) ? width() : height()) - ypos - bmargin; 1215 m_scrolldy2 = ((m_rotated) ? width() : height()) - ypos - bmargin;
1216 } 1216 }
1217 break; 1217 break;
1218 } 1218 }
1219} 1219}
1220 1220
1221void QTReader::setautoscroll(bool _sc) 1221void QTReader::setautoscroll(bool _sc)
1222{ 1222{
1223 m_outofdate = true; 1223 m_outofdate = true;
1224 if (_sc == m_autoScroll) return; 1224 if (_sc == m_autoScroll) return;
1225 if (m_autoScroll) 1225 if (m_autoScroll)
1226 { 1226 {
1227 m_autoScroll = false; 1227 m_autoScroll = false;
1228#ifdef USEQPE 1228#ifdef USEQPE
1229 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1229 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1230#endif 1230#endif
1231#ifdef _SCROLLPIPE 1231#ifdef _SCROLLPIPE
1232 if (m_pipeout != NULL) 1232 if (m_pipeout != NULL)
1233 { 1233 {
1234 pclose(m_pipeout); 1234 pclose(m_pipeout);
1235 m_pipeout = NULL; 1235 m_pipeout = NULL;
1236 } 1236 }
1237#endif 1237#endif
1238 //m_scrolldy1 = 0; 1238 //m_scrolldy1 = 0;
1239 //refresh(); 1239 //refresh();
1240 } 1240 }
1241 else 1241 else
1242 { 1242 {
1243 CDrawBuffer* reusebuffer = textarray[numlines]; 1243 CDrawBuffer* reusebuffer = textarray[numlines];
1244 if (reusebuffer == NULL || reusebuffer->eof()) return; 1244 if (reusebuffer == NULL || reusebuffer->eof()) return;
1245#ifndef __STATIC 1245#ifndef __STATIC
1246 if ((m_scrolltype == 4) && !checkoutput()) return; 1246 if ((m_scrolltype == 4) && !checkoutput()) return;
1247#endif 1247#endif
1248 m_autoScroll = true; 1248 m_autoScroll = true;
1249 CalculateScrollParameters(); 1249 CalculateScrollParameters();
1250 1250
1251#ifdef _SCROLLPIPE 1251#ifdef _SCROLLPIPE
1252 if (!m_pipetarget.isEmpty()) 1252 if (!m_pipetarget.isEmpty())
1253 { 1253 {
1254 // qDebug("Opening pipe to %s", (const char*)m_pipetarget); 1254 // qDebug("Opening pipe to %s", (const char*)m_pipetarget);
1255 m_pipeout = popen((const char*)m_pipetarget, "w"); 1255 m_pipeout = popen((const char*)m_pipetarget, "w");
1256 m_isPaused = false; 1256 m_isPaused = false;
1257 } 1257 }
1258#endif 1258#endif
1259 autoscroll(); 1259 autoscroll();
1260#ifdef USEQPE 1260#ifdef USEQPE
1261 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed 1261 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
1262#endif 1262#endif
1263 } 1263 }
1264} 1264}
1265 1265
1266bool QTReader::getline(CDrawBuffer *buff) 1266bool QTReader::getline(CDrawBuffer *buff)
1267{ 1267{
1268 bool bRet; 1268 bool bRet;
1269 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; 1269 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
1270 if (m_bMonoSpaced) 1270 if (m_bMonoSpaced)
1271 { 1271 {
1272 bRet = buffdoc.getline(buff ,(m_rotated) ? height() : width(), m_charWidth, m_left_border, m_right_border, availht); 1272 bRet = buffdoc.getline(buff ,(m_rotated) ? height() : width(), m_charWidth, m_left_border, m_right_border, availht);
1273 } 1273 }
1274 else 1274 else
1275 { 1275 {
1276 bRet = buffdoc.getline(buff, (m_rotated) ? height() : width(), m_left_border, m_right_border, hyphenate, availht); 1276 bRet = buffdoc.getline(buff, (m_rotated) ? height() : width(), m_left_border, m_right_border, hyphenate, availht);
1277 } 1277 }
1278 buff->resize(availht); 1278 buff->resize(availht);
1279 return bRet; 1279 return bRet;
1280} 1280}
1281 1281
1282void QTReader::doscroll() 1282void QTReader::doscroll()
1283{ 1283{
1284 if (!m_autoScroll) 1284 if (!m_autoScroll)
1285 { 1285 {
1286 timer->stop(); 1286 timer->stop();
1287 return; 1287 return;
1288 } 1288 }
1289 switch (m_scrolltype) 1289 switch (m_scrolltype)
1290 { 1290 {
1291 case 0: 1291 case 0:
1292 doinplacescroll(); 1292 doinplacescroll();
1293 break; 1293 break;
1294 case 1: 1294 case 1:
1295 dorollingscroll(false); 1295 dorollingscroll(false);
1296 break; 1296 break;
1297 case 2: 1297 case 2:
1298 dorollingscroll(true); 1298 dorollingscroll(true);
1299 break; 1299 break;
1300 case 3: 1300 case 3:
1301 dostaticscroll(); 1301 dostaticscroll();
1302 break; 1302 break;
1303 } 1303 }
1304} 1304}
1305 1305
1306void QTReader::doinplacescroll() 1306void QTReader::doinplacescroll()
1307{ 1307{
1308 QPainter p( this ); 1308 QPainter p( this );
1309 // p.setBackgroundMode(OpaqueMode); 1309 // p.setBackgroundMode(OpaqueMode);
1310 int wh, ht; 1310 int wh, ht;
1311 int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); 1311 int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1312 if (bmargin < m_bottommargin) bmargin = m_bottommargin; 1312 if (bmargin < m_bottommargin) bmargin = m_bottommargin;
1313 if (m_rotated) 1313 if (m_rotated)
1314 { 1314 {
1315 ht = width()-bmargin; 1315 ht = width()-bmargin;
1316 wh = height(); 1316 wh = height();
1317 } 1317 }
1318 else 1318 else
1319 { 1319 {
1320 ht = height()-bmargin; 1320 ht = height()-bmargin;
1321 wh = width(); 1321 wh = width();
1322 } 1322 }
1323 int lastdy = m_scrolldy; 1323 int lastdy = m_scrolldy;
1324 m_scrolldy += m_scrollstep; 1324 m_scrolldy += m_scrollstep;
1325 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing()) 1325 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing())
1326 { 1326 {
1327 int ht = textarray[0]->lineSpacing(); 1327 int ht = textarray[0]->lineSpacing();
1328#ifdef _SCROLLPIPE 1328#ifdef _SCROLLPIPE
1329 if (m_pipeout != NULL) 1329 if (m_pipeout != NULL)
1330 { 1330 {
1331 QString outstr = toQString(textarray[0]->data()); 1331 QString outstr = toQString(textarray[0]->data());
1332 if (!outstr.isEmpty()) 1332 if (!outstr.isEmpty())
1333 { 1333 {
1334 fprintf(m_pipeout, "%s\n", (const char*)outstr); 1334 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1335 fflush(m_pipeout); 1335 fflush(m_pipeout);
1336 } 1336 }
1337 else if (m_pauseAfterEachPara) 1337 else if (m_pauseAfterEachPara)
1338 { 1338 {
1339 m_isPaused = true; 1339 m_isPaused = true;
1340 timer->stop(); 1340 timer->stop();
1341 } 1341 }
1342 } 1342 }
1343#endif 1343#endif
1344 CDrawBuffer* buff = textarray[0]; 1344 CDrawBuffer* buff = textarray[0];
1345 for (int i = 1; i <= numlines; i++) 1345 for (int i = 1; i <= numlines; i++)
1346 { 1346 {
1347 textarray[i-1] = textarray[i]; 1347 textarray[i-1] = textarray[i];
1348 locnarray[i-1] = locnarray[i]; 1348 locnarray[i-1] = locnarray[i];
1349 } 1349 }
1350 textarray[numlines] = buff; 1350 textarray[numlines] = buff;
1351 --numlines; 1351 --numlines;
1352 m_scrolldy1 -= ht; 1352 m_scrolldy1 -= ht;
1353 } 1353 }
1354 if ((m_scrolldy2 = m_scrolldy2+m_scrollstep) >= textarray[numlines]->lineSpacing()) 1354 if ((m_scrolldy2 = m_scrolldy2+m_scrollstep) >= textarray[numlines]->lineSpacing())
1355 { 1355 {
1356 m_scrolldy2 -= textarray[numlines]->lineSpacing(); 1356 m_scrolldy2 -= textarray[numlines]->lineSpacing();
1357 numlines++; 1357 numlines++;
1358 1358
1359 if (textarray[numlines] == NULL) 1359 if (textarray[numlines] == NULL)
1360 { 1360 {
1361 textarray[numlines] = new CDrawBuffer(&m_fontControl); 1361 textarray[numlines] = new CDrawBuffer(&m_fontControl);
1362 } 1362 }
1363 locnarray[numlines] = locate(); 1363 locnarray[numlines] = locate();
1364 int ch = getline(textarray[numlines]); 1364 int ch = getline(textarray[numlines]);
1365 if (m_rotated) 1365 if (m_rotated)
1366 { 1366 {
1367 blitRot(width()-m_scrolldy, 0, height(), -1, textarray[numlines-1]); 1367 blitRot(width()-m_scrolldy, 0, height(), -1, textarray[numlines-1]);
1368 } 1368 }
1369 else 1369 else
1370 { 1370 {
1371 if (m_bgpm.isNull()) 1371 if (m_bgpm.isNull())
1372 { 1372 {
1373 p.fillRect(m_left_border,m_scrolldy-textarray[numlines-1]->lineSpacing(),width()-(m_left_border+m_right_border),textarray[numlines-1]->lineSpacing(),m_bg); 1373 p.fillRect(m_left_border,m_scrolldy-textarray[numlines-1]->lineSpacing(),width()-(m_left_border+m_right_border),textarray[numlines-1]->lineSpacing(),m_bg);
1374 } 1374 }
1375 else 1375 else
1376 { 1376 {
1377 int h_tmp = textarray[numlines-1]->lineSpacing(); 1377 int h_tmp = textarray[numlines-1]->lineSpacing();
1378 bitBlt(this, m_left_border, m_scrolldy-h_tmp, dbuff, m_left_border, m_scrolldy-h_tmp, width()-(m_left_border+m_right_border), h_tmp); 1378 bitBlt(this, m_left_border, m_scrolldy-h_tmp, dbuff, m_left_border, m_scrolldy-h_tmp, width()-(m_left_border+m_right_border), h_tmp);
1379 } 1379 }
1380 textarray[numlines-1]->render(&p, m_scrolldy -textarray[numlines-1]->lineSpacing()+ textarray[numlines-1]->ascent(), m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); 1380 textarray[numlines-1]->render(&p, m_scrolldy -textarray[numlines-1]->lineSpacing()+ textarray[numlines-1]->ascent(), m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1381 } 1381 }
1382 mylastpos = locate(); 1382 mylastpos = locate();
1383 if (!ch) 1383 if (!ch)
1384 { 1384 {
1385 m_scrolldy = m_topmargin; 1385 m_scrolldy = m_topmargin;
1386 m_autoScroll = false; 1386 m_autoScroll = false;
1387#ifdef _SCROLLPIPE 1387#ifdef _SCROLLPIPE
1388 for (int i = 0; i < numlines; i++) 1388 for (int i = 0; i < numlines; i++)
1389 { 1389 {
1390 if (m_pipeout != NULL) 1390 if (m_pipeout != NULL)
1391 { 1391 {
1392 QString outstr = toQString(textarray[i]->data()); 1392 QString outstr = toQString(textarray[i]->data());
1393 if (!outstr.isEmpty()) 1393 if (!outstr.isEmpty())
1394 { 1394 {
1395 fprintf(m_pipeout, "%s\n", (const char*)outstr); 1395 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1396 fflush(m_pipeout); 1396 fflush(m_pipeout);
1397 } 1397 }
1398 } 1398 }
1399 } 1399 }
1400#endif 1400#endif
1401 emit SetScrollState(m_autoScroll); 1401 emit SetScrollState(m_autoScroll);
1402#ifdef USEQPE 1402#ifdef USEQPE
1403 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1403 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1404#endif 1404#endif
1405 } 1405 }
1406 if (m_scrolldy > ht-textarray[numlines]->lineSpacing()) 1406 if (m_scrolldy > ht-textarray[numlines]->lineSpacing())
1407 { 1407 {
1408 if (m_rotated) 1408 if (m_rotated)
1409 { 1409 {
1410 if (m_bgpm.isNull()) 1410 if (m_bgpm.isNull())
1411 { 1411 {
1412 p.fillRect(bmargin, m_left_border, ht-m_scrolldy, wh-(m_left_border+m_right_border), m_bg); 1412 p.fillRect(bmargin, m_left_border, ht-m_scrolldy, wh-(m_left_border+m_right_border), m_bg);
1413 } 1413 }
1414 else 1414 else
1415 { 1415 {
1416 blitRot(bmargin, 0,height(), ht-m_scrolldy, NULL); 1416 blitRot(bmargin, 0,height(), ht-m_scrolldy, NULL);
1417 } 1417 }
1418 } 1418 }
1419 else 1419 else
1420 if (m_bgpm.isNull()) 1420 if (m_bgpm.isNull())
1421 { 1421 {
1422 p.fillRect(m_left_border,m_scrolldy,width()-(m_left_border+m_right_border),height()-m_scrolldy,m_bg); 1422 p.fillRect(m_left_border,m_scrolldy,width()-(m_left_border+m_right_border),height()-m_scrolldy,m_bg);
1423 } 1423 }
1424 else 1424 else
1425 { 1425 {
1426 bitBlt(this,m_left_border,m_scrolldy,dbuff,m_left_border,m_scrolldy,width()-(m_left_border+m_right_border), height()-m_scrolldy); 1426 bitBlt(this,m_left_border,m_scrolldy,dbuff,m_left_border,m_scrolldy,width()-(m_left_border+m_right_border), height()-m_scrolldy);
1427 } 1427 }
1428 m_scrolldy = m_topmargin; 1428 m_scrolldy = m_topmargin;
1429 m_scrolldy2 = 0; 1429 m_scrolldy2 = 0;
1430 } 1430 }
1431 redrawScroll(&p); 1431 redrawScroll(&p);
1432 emitRedraw(); 1432 emitRedraw();
1433 lastdy = -1; 1433 lastdy = -1;
1434 } 1434 }
1435 // else 1435 // else
1436 { 1436 {
1437 if (m_rotated) 1437 if (m_rotated)
1438 { 1438 {
1439 if (lastdy >= 0) 1439 if (lastdy >= 0)
1440 { 1440 {
1441 if (m_bgpm.isNull()) 1441 if (m_bgpm.isNull())
1442 { 1442 {
1443 p.fillRect(width()-lastdy, m_left_border, m_scrollstep, wh-(m_left_border+m_right_border),m_bg); 1443 p.fillRect(width()-lastdy, m_left_border, m_scrollstep, wh-(m_left_border+m_right_border),m_bg);
1444 } 1444 }
1445 else 1445 else
1446 { 1446 {
1447 blitRot(width()-lastdy,m_left_border,wh-(m_left_border+m_right_border), m_scrollstep, NULL); 1447 blitRot(width()-lastdy,m_left_border,wh-(m_left_border+m_right_border), m_scrollstep, NULL);
1448 } 1448 }
1449 } 1449 }
1450 p.fillRect(width()-m_scrolldy, m_left_border, 1,wh-(m_left_border+m_right_border),m_scrollcolor); 1450 p.fillRect(width()-m_scrolldy, m_left_border, 1,wh-(m_left_border+m_right_border),m_scrollcolor);
1451 } 1451 }
1452 else 1452 else
1453 { 1453 {
1454 if (lastdy >= 0) 1454 if (lastdy >= 0)
1455 { 1455 {
1456 if (m_bgpm.isNull()) 1456 if (m_bgpm.isNull())
1457 { 1457 {
1458 p.fillRect(m_left_border,lastdy,width()-(m_left_border+m_right_border),m_scrollstep,m_bg); 1458 p.fillRect(m_left_border,lastdy,width()-(m_left_border+m_right_border),m_scrollstep,m_bg);
1459 } 1459 }
1460 else 1460 else
1461 { 1461 {
1462 bitBlt(this, m_left_border, lastdy, dbuff, m_left_border, lastdy, width()-(m_left_border+m_right_border), m_scrollstep); 1462 bitBlt(this, m_left_border, lastdy, dbuff, m_left_border, lastdy, width()-(m_left_border+m_right_border), m_scrollstep);
1463 } 1463 }
1464 } 1464 }
1465 p.fillRect(m_left_border,m_scrolldy,width()-(m_left_border+m_right_border),1,m_scrollcolor); 1465 p.fillRect(m_left_border,m_scrolldy,width()-(m_left_border+m_right_border),1,m_scrollcolor);
1466 } 1466 }
1467 } 1467 }
1468} 1468}
1469 1469
1470void QTReader::dorollingscroll(bool _statbord) 1470void QTReader::dorollingscroll(bool _statbord)
1471{ 1471{
1472 bool bredrawscroll = false; 1472 bool bredrawscroll = false;
1473 QPainter p( this ); 1473 QPainter p( this );
1474 // 2 = right, 3 = left 1474 // 2 = right, 3 = left
1475 int tmargin = (_statbord) ? m_topmargin : 0; 1475 int tmargin = (_statbord) ? m_topmargin : 0;
1476 int lmargin = (m_scrollpos == 3 || _statbord) ? m_left_border : 0; 1476 int lmargin = (m_scrollpos == 3 || _statbord) ? m_left_border : 0;
1477 int rmargin = (m_scrollpos == 2 || _statbord) ? m_right_border : 0; 1477 int rmargin = (m_scrollpos == 2 || _statbord) ? m_right_border : 0;
1478 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); 1478 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1479 if (hmargin < m_bottommargin) hmargin = m_bottommargin; 1479 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1480 if (m_rotated) 1480 if (m_rotated)
1481 { 1481 {
1482 m_totalscroll = (m_totalscroll+m_scrollstep) % width(); 1482 m_totalscroll = (m_totalscroll+m_scrollstep) % width();
1483 bitBlt(this, m_scrollstep+hmargin, lmargin, this, hmargin, lmargin, width()-tmargin-hmargin, height()-(lmargin+rmargin)); 1483 bitBlt(this, m_scrollstep+hmargin, lmargin, this, hmargin, lmargin, width()-tmargin-hmargin, height()-(lmargin+rmargin));
1484 if (!m_bgpm.isNull()) 1484 if (!m_bgpm.isNull())
1485 { 1485 {
1486 blitRot(hmargin, tmargin, height(), m_scrollstep, NULL); 1486 blitRot(hmargin, tmargin, height(), m_scrollstep, NULL);
1487 } 1487 }
1488 else 1488 else
1489 { 1489 {
1490 p.fillRect(hmargin, rmargin, m_scrollstep, height()-lmargin-rmargin, m_bg); 1490 p.fillRect(hmargin, rmargin, m_scrollstep, height()-lmargin-rmargin, m_bg);
1491 } 1491 }
1492 } 1492 }
1493 else 1493 else
1494 { 1494 {
1495 m_totalscroll = (m_totalscroll+m_scrollstep) % height(); 1495 m_totalscroll = (m_totalscroll+m_scrollstep) % height();
1496 bitBlt(this,lmargin,tmargin,this,lmargin,tmargin+m_scrollstep,width()-(lmargin+rmargin),height() - tmargin - hmargin - m_scrollstep); 1496 bitBlt(this,lmargin,tmargin,this,lmargin,tmargin+m_scrollstep,width()-(lmargin+rmargin),height() - tmargin - hmargin - m_scrollstep);
1497 if (m_bgpm.isNull()) 1497 if (m_bgpm.isNull())
1498 { 1498 {
1499 p.fillRect(0, height() - (m_scrollstep+1) - hmargin, width(), (m_scrollstep+1), m_bg); 1499 p.fillRect(0, height() - (m_scrollstep+1) - hmargin, width(), (m_scrollstep+1), m_bg);
1500 } 1500 }
1501 else 1501 else
1502 { 1502 {
1503 int loff = (_statbord) ? 0 : m_totalscroll; 1503 int loff = (_statbord) ? 0 : m_totalscroll;
1504 bitBlt(this,0,height() - (m_scrollstep+1) - hmargin, dbuff, 0, (loff+height() - (m_scrollstep+1) - hmargin) % height(), width(), (m_scrollstep+1)); 1504 bitBlt(this,0,height() - (m_scrollstep+1) - hmargin, dbuff, 0, (loff+height() - (m_scrollstep+1) - hmargin) % height(), width(), (m_scrollstep+1));
1505 } 1505 }
1506 } 1506 }
1507 1507
1508 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing()) 1508 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing())
1509 { 1509 {
1510 int ht = textarray[0]->lineSpacing(); 1510 int ht = textarray[0]->lineSpacing();
1511 bredrawscroll = true; 1511 bredrawscroll = true;
1512#ifdef _SCROLLPIPE 1512#ifdef _SCROLLPIPE
1513 if (m_pipeout != NULL) 1513 if (m_pipeout != NULL)
1514 { 1514 {
1515 QString outstr = toQString(textarray[0]->data()); 1515 QString outstr = toQString(textarray[0]->data());
1516 if (!outstr.isEmpty()) 1516 if (!outstr.isEmpty())
1517 { 1517 {
1518 fprintf(m_pipeout, "%s\n", (const char*)outstr); 1518 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1519 fflush(m_pipeout); 1519 fflush(m_pipeout);
1520 } 1520 }
1521 else if (m_pauseAfterEachPara) 1521 else if (m_pauseAfterEachPara)
1522 { 1522 {
1523 m_isPaused = true; 1523 m_isPaused = true;
1524 timer->stop(); 1524 timer->stop();
1525 } 1525 }
1526 } 1526 }
1527#endif 1527#endif
1528 CDrawBuffer* buff = textarray[0]; 1528 CDrawBuffer* buff = textarray[0];
1529 for (int i = 1; i <= numlines; i++) 1529 for (int i = 1; i <= numlines; i++)
1530 { 1530 {
1531 textarray[i-1] = textarray[i]; 1531 textarray[i-1] = textarray[i];
1532 locnarray[i-1] = locnarray[i]; 1532 locnarray[i-1] = locnarray[i];
1533 } 1533 }
1534 textarray[numlines] = buff; 1534 textarray[numlines] = buff;
1535 --numlines; 1535 --numlines;
1536 m_scrolldy1 -= ht; 1536 m_scrolldy1 -= ht;
1537 } 1537 }
1538 if ((m_scrolldy2 = m_scrolldy2+m_scrollstep) >= textarray[numlines]->lineSpacing()) 1538 if ((m_scrolldy2 = m_scrolldy2+m_scrollstep) >= textarray[numlines]->lineSpacing())
1539 { 1539 {
1540 bredrawscroll = true; 1540 bredrawscroll = true;
1541 m_scrolldy2 -= textarray[numlines]->lineSpacing(); 1541 m_scrolldy2 -= textarray[numlines]->lineSpacing();
1542 numlines++; 1542 numlines++;
1543 1543
1544 if (textarray[numlines] == NULL) 1544 if (textarray[numlines] == NULL)
1545 { 1545 {
1546 textarray[numlines] = new CDrawBuffer(&m_fontControl); 1546 textarray[numlines] = new CDrawBuffer(&m_fontControl);
1547 } 1547 }
1548 locnarray[numlines] = locate(); 1548 locnarray[numlines] = locate();
1549 int ch = getline(textarray[numlines]); 1549 int ch = getline(textarray[numlines]);
1550 if (m_rotated) 1550 if (m_rotated)
1551 { 1551 {
1552 blitRot(hmargin, 0, height(), -1, textarray[numlines-1]); 1552 blitRot(hmargin, 0, height(), -1, textarray[numlines-1]);
1553 } 1553 }
1554 else 1554 else
1555 { 1555 {
1556 // textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2 - hmargin, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg); 1556 // textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2 - hmargin, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg);
1557 textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - textarray[numlines-1]->lineExtraSpacing() - 1 - hmargin, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); 1557 textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - textarray[numlines-1]->lineExtraSpacing() - 1 - hmargin, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1558 1558
1559 } 1559 }
1560 mylastpos = locate(); 1560 mylastpos = locate();
1561 if (!ch) 1561 if (!ch)
1562 { 1562 {
1563 redrawScroll(&p); 1563 redrawScroll(&p);
1564 emitRedraw(); 1564 emitRedraw();
1565 m_autoScroll = false; 1565 m_autoScroll = false;
1566#ifdef _SCROLLPIPE 1566#ifdef _SCROLLPIPE
1567 for (int i = 0; i < numlines; i++) 1567 for (int i = 0; i < numlines; i++)
1568 { 1568 {
1569 if (m_pipeout != NULL) 1569 if (m_pipeout != NULL)
1570 { 1570 {
1571 QString outstr = toQString(textarray[i]->data()); 1571 QString outstr = toQString(textarray[i]->data());
1572 if (!outstr.isEmpty()) 1572 if (!outstr.isEmpty())
1573 { 1573 {
1574 fprintf(m_pipeout, "%s\n", (const char*)outstr); 1574 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1575 fflush(m_pipeout); 1575 fflush(m_pipeout);
1576 } 1576 }
1577 } 1577 }
1578 } 1578 }
1579#endif 1579#endif
1580 emit SetScrollState(m_autoScroll); 1580 emit SetScrollState(m_autoScroll);
1581#ifdef USEQPE 1581#ifdef USEQPE
1582 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1582 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1583#endif 1583#endif
1584 return; 1584 return;
1585 } 1585 }
1586 } 1586 }
1587 if (!bredrawscroll && ((m_scrolldy2/m_scrollstep) % 10 == 5) && textarray[numlines]->showPartial()) 1587 if (!bredrawscroll && ((m_scrolldy2/m_scrollstep) % 10 == 5) && textarray[numlines]->showPartial())
1588 { 1588 {
1589 if (m_rotated) 1589 if (m_rotated)
1590 { 1590 {
1591 blitRot(hmargin + m_scrolldy2 - textarray[numlines]->lineSpacing(), 0, height(), -1, textarray[numlines]); 1591 blitRot(hmargin + m_scrolldy2 - textarray[numlines]->lineSpacing(), 0, height(), -1, textarray[numlines]);
1592 } 1592 }
1593 else 1593 else
1594 { 1594 {
1595 textarray[numlines]->render( &p, height() + textarray[numlines]->lineSpacing() - textarray[numlines]->descent() - 2 - hmargin-m_scrolldy2, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); 1595 textarray[numlines]->render( &p, height() + textarray[numlines]->lineSpacing() - textarray[numlines]->descent() - 2 - hmargin-m_scrolldy2, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1596 } 1596 }
1597 } 1597 }
1598 if (m_scrollpos != 0) 1598 if (m_scrollpos != 0)
1599 { 1599 {
1600 redrawScroll(&p); 1600 redrawScroll(&p);
1601 } 1601 }
1602 if (bredrawscroll) emitRedraw(); 1602 if (bredrawscroll) emitRedraw();
1603} 1603}
1604 1604
1605void QTReader::dostaticscroll() 1605void QTReader::dostaticscroll()
1606{ 1606{
1607 redrawall(); 1607 redrawall();
1608 bool bredraw = false; 1608 bool bredraw = false;
1609 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing()) 1609 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing())
1610 { 1610 {
1611 int ht = textarray[0]->lineSpacing(); 1611 int ht = textarray[0]->lineSpacing();
1612 bredraw = true; 1612 bredraw = true;
1613#ifdef _SCROLLPIPE 1613#ifdef _SCROLLPIPE
1614 if (m_pipeout != NULL) 1614 if (m_pipeout != NULL)
1615 { 1615 {
1616 QString outstr = toQString(textarray[0]->data()); 1616 QString outstr = toQString(textarray[0]->data());
1617 if (!outstr.isEmpty()) 1617 if (!outstr.isEmpty())
1618 { 1618 {
1619 fprintf(m_pipeout, "%s\n", (const char*)outstr); 1619 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1620 fflush(m_pipeout); 1620 fflush(m_pipeout);
1621 } 1621 }
1622 else if (m_pauseAfterEachPara) 1622 else if (m_pauseAfterEachPara)
1623 { 1623 {
1624 m_isPaused = true; 1624 m_isPaused = true;
1625 timer->stop(); 1625 timer->stop();
1626 } 1626 }
1627 } 1627 }
1628#endif 1628#endif
1629 CDrawBuffer* buff = textarray[0]; 1629 CDrawBuffer* buff = textarray[0];
1630 for (int i = 1; i <= numlines; i++) 1630 for (int i = 1; i <= numlines; i++)
1631 { 1631 {
1632 textarray[i-1] = textarray[i]; 1632 textarray[i-1] = textarray[i];
1633 locnarray[i-1] = locnarray[i]; 1633 locnarray[i-1] = locnarray[i];
1634 } 1634 }
1635 textarray[numlines] = buff; 1635 textarray[numlines] = buff;
1636 --numlines; 1636 --numlines;
1637 m_scrolldy1 -= ht; 1637 m_scrolldy1 -= ht;
1638 } 1638 }
1639 if ((m_scrolldy2 = m_scrolldy2 + m_scrollstep) >= textarray[numlines]->lineSpacing()) 1639 if ((m_scrolldy2 = m_scrolldy2 + m_scrollstep) >= textarray[numlines]->lineSpacing())
1640 { 1640 {
1641 bredraw = true; 1641 bredraw = true;
1642 m_scrolldy2 -= textarray[numlines]->lineSpacing(); 1642 m_scrolldy2 -= textarray[numlines]->lineSpacing();
1643 numlines++; 1643 numlines++;
1644 1644
1645 if (textarray[numlines] == NULL) 1645 if (textarray[numlines] == NULL)
1646 { 1646 {
1647 textarray[numlines] = new CDrawBuffer(&m_fontControl); 1647 textarray[numlines] = new CDrawBuffer(&m_fontControl);
1648 } 1648 }
1649 locnarray[numlines] = locate(); 1649 locnarray[numlines] = locate();
1650 int ch = getline(textarray[numlines]); 1650 int ch = getline(textarray[numlines]);
1651 mylastpos = locate(); 1651 mylastpos = locate();
1652 if (!ch) 1652 if (!ch)
1653 { 1653 {
1654 redrawall(); 1654 redrawall();
1655 emitRedraw(); 1655 emitRedraw();
1656 m_autoScroll = false; 1656 m_autoScroll = false;
1657#ifdef _SCROLLPIPE 1657#ifdef _SCROLLPIPE
1658 for (int i = 0; i < numlines; i++) 1658 for (int i = 0; i < numlines; i++)
1659 { 1659 {
1660 if (m_pipeout != NULL) 1660 if (m_pipeout != NULL)
1661 { 1661 {
1662 QString outstr = toQString(textarray[i]->data()); 1662 QString outstr = toQString(textarray[i]->data());
1663 if (!outstr.isEmpty()) 1663 if (!outstr.isEmpty())
1664 { 1664 {
1665 fprintf(m_pipeout, "%s\n", (const char*)outstr); 1665 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1666 fflush(m_pipeout); 1666 fflush(m_pipeout);
1667 } 1667 }
1668 } 1668 }
1669 } 1669 }
1670#endif 1670#endif
1671 emit SetScrollState(m_autoScroll); 1671 emit SetScrollState(m_autoScroll);
1672#ifdef USEQPE 1672#ifdef USEQPE
1673 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1673 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1674#endif 1674#endif
1675 return; 1675 return;
1676 } 1676 }
1677 } 1677 }
1678 if (bredraw) emitRedraw(); 1678 if (bredraw) emitRedraw();
1679} 1679}
1680 1680
1681void QTReader::redrawScroll(QPainter* p) 1681void QTReader::redrawScroll(QPainter* p)
1682{ 1682{
1683 int offset = (m_scrolltype == 1) ? m_totalscroll : 0; 1683 int offset = (m_scrolltype == 1) ? m_totalscroll : 0;
1684 switch (m_scrollpos) 1684 switch (m_scrollpos)
1685 { 1685 {
1686 case 1: 1686 case 1:
1687 { 1687 {
1688 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); 1688 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1689 if (hmargin < m_bottommargin) hmargin = m_bottommargin; 1689 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1690 if (m_rotated) 1690 if (m_rotated)
1691 { 1691 {
1692 if (m_bgpm.isNull()) 1692 if (m_bgpm.isNull())
1693 { 1693 {
1694 p->fillRect(0,0,hmargin,height(),m_bg); 1694 p->fillRect(0,0,hmargin,height(),m_bg);
1695 } 1695 }
1696 else 1696 else
1697 { 1697 {
1698 blitRot(0,0, height(), hmargin, NULL); 1698 blitRot(0,0, height(), hmargin, NULL);
1699 } 1699 }
1700 } 1700 }
1701 else 1701 else
1702 { 1702 {
1703 if (m_bgpm.isNull()) 1703 if (m_bgpm.isNull())
1704 { 1704 {
1705 p->fillRect(0,height() - hmargin,width(),hmargin,m_bg); 1705 p->fillRect(0,height() - hmargin,width(),hmargin,m_bg);
1706 } 1706 }
1707 else 1707 else
1708 { 1708 {
1709 int toffset = (offset+height()-hmargin) % height(); 1709 int toffset = (offset+height()-hmargin) % height();
1710 if (toffset+hmargin > height()) 1710 if (toffset+hmargin > height())
1711 { 1711 {
1712 int fp = height()-toffset; 1712 int fp = height()-toffset;
1713 bitBlt(this, 1713 bitBlt(this,
1714 0,height() - hmargin, 1714 0,height() - hmargin,
1715 dbuff, 1715 dbuff,
1716 0, toffset, width(), fp); 1716 0, toffset, width(), fp);
1717 bitBlt(this, 1717 bitBlt(this,
1718 0,height()-hmargin+fp, 1718 0,height()-hmargin+fp,
1719 dbuff, 1719 dbuff,
1720 0, 0, width(), hmargin-fp); 1720 0, 0, width(), hmargin-fp);
1721 } 1721 }
1722 else 1722 else
1723 { 1723 {
1724 bitBlt(this, 1724 bitBlt(this,
1725 0,height() - hmargin, 1725 0,height() - hmargin,
1726 dbuff, 1726 dbuff,
1727 0, toffset, width(), hmargin); 1727 0, toffset, width(), hmargin);
1728 } 1728 }
1729 } 1729 }
1730 } 1730 }
1731 } 1731 }
1732 break; 1732 break;
1733 case 2: //right 1733 case 2: //right
1734 if (m_rotated) 1734 if (m_rotated)
1735 { 1735 {
1736 if (m_bgpm.isNull()) 1736 if (m_bgpm.isNull())
1737 { 1737 {
1738 p->fillRect(0,height()-m_right_border,width(),m_right_border,m_bg); 1738 p->fillRect(0,height()-m_right_border,width(),m_right_border,m_bg);
1739 } 1739 }
1740 else 1740 else
1741 { 1741 {
1742 blitRot(0,height()-m_right_border, m_right_border, width(), NULL); 1742 blitRot(0,height()-m_right_border, m_right_border, width(), NULL);
1743 } 1743 }
1744 } 1744 }
1745 else 1745 else
1746 { 1746 {
1747 if (m_bgpm.isNull()) 1747 if (m_bgpm.isNull())
1748 { 1748 {
1749 p->fillRect(width()-m_right_border,0,m_right_border,height(),m_bg); 1749 p->fillRect(width()-m_right_border,0,m_right_border,height(),m_bg);
1750 } 1750 }
1751 else 1751 else
1752 { 1752 {
1753 int x = width() - m_right_border; 1753 int x = width() - m_right_border;
1754 int fp = height()-offset; 1754 int fp = height()-offset;
1755 bitBlt(this, x, 0, dbuff, x, offset, m_right_border, fp); 1755 bitBlt(this, x, 0, dbuff, x, offset, m_right_border, fp);
1756 bitBlt(this, x, fp, dbuff, x, 0, m_right_border, height()-fp); 1756 bitBlt(this, x, fp, dbuff, x, 0, m_right_border, height()-fp);
1757 } 1757 }
1758 } 1758 }
1759 break; 1759 break;
1760 case 3: //left 1760 case 3: //left
1761 if (m_rotated) 1761 if (m_rotated)
1762 { 1762 {
1763 if (m_bgpm.isNull()) 1763 if (m_bgpm.isNull())
1764 { 1764 {
1765 p->fillRect(0,0,width(),m_left_border,m_bg); 1765 p->fillRect(0,0,width(),m_left_border,m_bg);
1766 } 1766 }
1767 else 1767 else
1768 { 1768 {
1769 blitRot(0,0, m_left_border, width(), NULL); 1769 blitRot(0,0, m_left_border, width(), NULL);
1770 } 1770 }
1771 } 1771 }
1772 else 1772 else
1773 { 1773 {
1774 if (m_bgpm.isNull()) 1774 if (m_bgpm.isNull())
1775 { 1775 {
1776 p->fillRect(0,0,m_left_border,height(),m_bg); 1776 p->fillRect(0,0,m_left_border,height(),m_bg);
1777 } 1777 }
1778 else 1778 else
1779 { 1779 {
1780 int fp = height()-offset; 1780 int fp = height()-offset;
1781 bitBlt(this, 0, 0, dbuff, 0, offset, m_left_border, fp); 1781 bitBlt(this, 0, 0, dbuff, 0, offset, m_left_border, fp);
1782 bitBlt(this, 0, fp, dbuff, 0, 0, m_left_border, height()-fp); 1782 bitBlt(this, 0, fp, dbuff, 0, 0, m_left_border, height()-fp);
1783 } 1783 }
1784 } 1784 }
1785 break; 1785 break;
1786 case 0: 1786 case 0:
1787 default: 1787 default:
1788 break; 1788 break;
1789 } 1789 }
1790 if (m_scrollpos != 0) DrawScroll(p, width(), height()); 1790 if (m_scrollpos != 0) DrawScroll(p, width(), height());
1791} 1791}
1792 1792
1793void QTReader::autoscroll() 1793void QTReader::autoscroll()
1794{ 1794{
1795 if (m_scrolltype == 4) 1795 if (m_scrolltype == 4)
1796 { 1796 {
1797 readAloud(); 1797 readAloud();
1798 } 1798 }
1799 else 1799 else
1800 { 1800 {
1801 if (dbuff != NULL) 1801 if (dbuff != NULL)
1802 { 1802 {
1803 dbp->begin(dbuff); 1803 dbp->begin(dbuff);
1804 drawBackground(dbp); 1804 drawBackground(dbp);
1805 dbp->end(); 1805 dbp->end();
1806 } 1806 }
1807 timer->start(real_delay(), false); 1807 timer->start(real_delay(), false);
1808 } 1808 }
1809} 1809}
1810 1810
1811void QTReader::setfont() 1811void QTReader::setfont()
1812{ 1812{
1813// m_fontControl.Change 1813// m_fontControl.Change
1814 m_charWidth = (m_charpc*m_fontControl.currentsize())/100; 1814 m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
1815 if (m_charWidth <= 0) m_charWidth = 1; 1815 if (m_charWidth <= 0) m_charWidth = 1;
1816 m_ascent = m_fontControl.ascent(); 1816 m_ascent = m_fontControl.ascent();
1817 m_descent = m_fontControl.descent(); 1817 m_descent = m_fontControl.descent();
1818 m_linespacing = m_fontControl.lineSpacing(); 1818 m_linespacing = m_fontControl.lineSpacing();
1819} 1819}
1820 1820
1821void QTReader::DrawStraight(QPainter* p, int w, int h) 1821void QTReader::DrawStraight(QPainter* p, int w, int h)
1822{ 1822{
1823 if (m_scrolldy == m_topmargin) 1823 if (m_scrolldy == m_topmargin)
1824 { 1824 {
1825 int ypos = textarray[0]->ascent()-m_scrolldy1+m_topmargin; 1825 int ypos = textarray[0]->ascent()-m_scrolldy1+m_topmargin;
1826 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); 1826 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1827 int i; 1827 int i;
1828 for (i = 1; i < numlines; i++) 1828 for (i = 1; i < numlines; i++)
1829 { 1829 {
1830 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+ 1830 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1831 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; 1831 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1832 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); 1832 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1833 } 1833 }
1834 if (textarray[i]->showPartial()) 1834 if (textarray[i]->showPartial())
1835 { 1835 {
1836 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+ 1836 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1837 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; 1837 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1838 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); 1838 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1839 } 1839 }
1840 } 1840 }
1841 else 1841 else
1842 { 1842 {
1843 int ypos = textarray[0]->ascent()-m_scrolldy1+m_scrolldy+m_topmargin; 1843 int ypos = textarray[0]->ascent()-m_scrolldy1+m_scrolldy+m_topmargin;
1844 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); 1844 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1845 // p->fillRect(m_border, 0, w-2*m_border, m_scrolldy, m_bg); 1845 // p->fillRect(m_border, 0, w-2*m_border, m_scrolldy, m_bg);
1846 for (int i = 1; i < numlines; i++) 1846 for (int i = 1; i < numlines; i++)
1847 { 1847 {
1848 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+ 1848 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1849 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; 1849 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1850 if (ypos+textarray[i]->descent() > h) 1850 if (ypos+textarray[i]->descent() > h)
1851 { 1851 {
1852 ypos = textarray[i]->ascent(); 1852 ypos = textarray[i]->ascent();
1853 } 1853 }
1854 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); 1854 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1855 } 1855 }
1856 p->fillRect(m_left_border,m_scrolldy,w-(m_left_border+m_right_border),1,m_scrollcolor); 1856 p->fillRect(m_left_border,m_scrolldy,w-(m_left_border+m_right_border),1,m_scrollcolor);
1857 } 1857 }
1858 bool wasrotated = m_rotated; 1858 bool wasrotated = m_rotated;
1859 m_rotated = false; 1859 m_rotated = false;
1860 DrawScroll(p, w, h); 1860 DrawScroll(p, w, h);
1861 m_rotated = wasrotated; 1861 m_rotated = wasrotated;
1862 1862
1863} 1863}
1864 1864
1865void QTReader::redrawall() 1865void QTReader::redrawall()
1866{ 1866{
1867 if (m_rotated) 1867 if (m_rotated)
1868 { 1868 {
1869 if (dbuff != NULL) 1869 if (dbuff != NULL)
1870 { 1870 {
1871 dbp->begin(dbuff); 1871 dbp->begin(dbuff);
1872 drawBackground(dbp); 1872 drawBackground(dbp);
1873 DrawStraight(dbp, height(), width()); 1873 DrawStraight(dbp, height(), width());
1874 dbp->end(); 1874 dbp->end();
1875 1875
1876 QWMatrix m; 1876 QWMatrix m;
1877 m.rotate(90); 1877 m.rotate(90);
1878 QPixmap rp = dbuff->xForm(m); 1878 QPixmap rp = dbuff->xForm(m);
1879 bitBlt(this, 0,0,&rp,0,0,-1,-1); 1879 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1880 } 1880 }
1881 else 1881 else
1882 { 1882 {
1883 qDebug("This shouldn't happen but it doesn't matter if it does (rotated == double buffered)"); 1883 qDebug("This shouldn't happen but it doesn't matter if it does (rotated == double buffered)");
1884 QPixmap dbuff(height(), width()); 1884 QPixmap dbuff(height(), width());
1885 QPainter dbp(&dbuff); 1885 QPainter dbp(&dbuff);
1886 1886
1887 drawBackground(&dbp); 1887 drawBackground(&dbp);
1888 DrawStraight(&dbp, height(), width()); 1888 DrawStraight(&dbp, height(), width());
1889 1889
1890 QWMatrix m; 1890 QWMatrix m;
1891 m.rotate(90); 1891 m.rotate(90);
1892 QPixmap rp = dbuff.xForm(m); 1892 QPixmap rp = dbuff.xForm(m);
1893 bitBlt(this, 0,0,&rp,0,0,-1,-1); 1893 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1894 } 1894 }
1895 } 1895 }
1896 else 1896 else
1897 { 1897 {
1898 if (dbuff != NULL) 1898 if (dbuff != NULL)
1899 { 1899 {
1900 dbp->begin(dbuff); 1900 dbp->begin(dbuff);
1901 drawBackground(dbp); 1901 drawBackground(dbp);
1902 DrawStraight(dbp, width(), height()); 1902 DrawStraight(dbp, width(), height());
1903 dbp->end(); 1903 dbp->end();
1904 bitBlt(this, 0,0,dbuff,0,0,-1,-1); 1904 bitBlt(this, 0,0,dbuff,0,0,-1,-1);
1905 } 1905 }
1906 else 1906 else
1907 { 1907 {
1908 QPainter p(this); 1908 QPainter p(this);
1909 drawBackground(&p); 1909 drawBackground(&p);
1910 DrawStraight(&p, width(), height()); 1910 DrawStraight(&p, width(), height());
1911 } 1911 }
1912 } 1912 }
1913} 1913}
1914 1914
1915void QTReader::drawFonts() 1915void QTReader::drawFonts()
1916{ 1916{
1917 if (bDoUpdates) 1917 if (bDoUpdates)
1918 { 1918 {
1919 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); 1919 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1920 if (hmargin < m_bottommargin) hmargin = m_bottommargin; 1920 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1921 //qDebug("How refreshing..."); 1921 //qDebug("How refreshing...");
1922 if (buffdoc.empty()) 1922 if (buffdoc.empty())
1923 { 1923 {
1924 if (dbuff != NULL) 1924 if (dbuff != NULL)
1925 { 1925 {
1926 dbp->begin(dbuff); 1926 dbp->begin(dbuff);
1927 drawBackground(dbp); 1927 drawBackground(dbp);
1928 dbp->end(); 1928 dbp->end();
1929 } 1929 }
1930 else 1930 else
1931 { 1931 {
1932 QPainter p(this); 1932 QPainter p(this);
1933 drawBackground(&p); 1933 drawBackground(&p);
1934 } 1934 }
1935 return; 1935 return;
1936 } 1936 }
1937 setfont(); 1937 setfont();
1938 //if (!m_autoScroll) m_scrolldy1 = 0; 1938 //if (!m_autoScroll) m_scrolldy1 = 0;
1939 if (dbuff != NULL && (dbuff->width() != width() || dbuff->height() != height())) 1939 if (dbuff != NULL && (dbuff->width() != width() || dbuff->height() != height()))
1940 { 1940 {
1941 qDebug("Oh no! A resize event was missed..."); 1941 qDebug("Oh no! A resize event was missed...");
1942 if (m_rotated) 1942 if (m_rotated)
1943 { 1943 {
1944 dbuff->resize(height(), width()); 1944 dbuff->resize(height(), width());
1945 } 1945 }
1946 else 1946 else
1947 { 1947 {
1948 dbuff->resize(width(), height()); 1948 dbuff->resize(width(), height());
1949 } 1949 }
1950 m_lastwidth = 0; 1950 m_lastwidth = 0;
1951 } 1951 }
1952 if (m_lastwidth != ((m_rotated) ? height() : width())) 1952 if (m_lastwidth != ((m_rotated) ? height() : width()))
1953 { 1953 {
1954 m_scrolldy = m_topmargin; 1954 m_scrolldy = m_topmargin;
1955 // qDebug("Not Optimised %d", m_lastwidth); 1955 // qDebug("Not Optimised %d", m_lastwidth);
1956 m_lastwidth = ((m_rotated) ? height() : width()); 1956 m_lastwidth = ((m_rotated) ? height() : width());
1957 m_lastheight = ((m_rotated) ? width() : height()); 1957 m_lastheight = ((m_rotated) ? width() : height());
1958 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); 1958 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
1959 buffdoc.locate(pagelocate()); 1959 buffdoc.locate(pagelocate());
1960 fillbuffer(); 1960 fillbuffer();
1961 redrawall(); 1961 redrawall();
1962 // qDebug("Not Optimised %d", m_lastwidth); 1962 // qDebug("Not Optimised %d", m_lastwidth);
1963 } 1963 }
1964 else 1964 else
1965 { 1965 {
1966 int newht = ((m_rotated) ? width() : height()); 1966 int newht = ((m_rotated) ? width() : height());
1967 if (m_lastheight > newht) 1967 if (m_lastheight > newht)
1968 { 1968 {
1969 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht); 1969 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
1970 m_scrolldy = m_topmargin; 1970 m_scrolldy = m_topmargin;
1971 int ypos = m_scrolldy1+m_topmargin; 1971 int ypos = m_scrolldy1+m_topmargin;
1972 for (int i = 0; i < numlines; i++) 1972 for (int i = 0; i < numlines; i++)
1973 { 1973 {
1974 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin) 1974 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin)
1975 { 1975 {
1976 numlines = i; 1976 numlines = i;
1977 jumpto(mylastpos = locnarray[i+1]); 1977 jumpto(mylastpos = locnarray[i+1]);
1978 break; 1978 break;
1979 } 1979 }
1980 } 1980 }
1981 // qDebug("Optimised < %d", numlines); 1981 // qDebug("Optimised < %d", numlines);
1982 m_lastheight = newht; 1982 m_lastheight = newht;
1983 } 1983 }
1984 else if (m_lastheight < newht) 1984 else if (m_lastheight < newht)
1985 { 1985 {
1986 m_scrolldy = m_topmargin; 1986 m_scrolldy = m_topmargin;
1987 // qDebug("Optimised > %d", numlines); 1987 // qDebug("Optimised > %d", numlines);
1988 int ypos = m_scrolldy1+m_topmargin; 1988 int ypos = m_scrolldy1+m_topmargin;
1989 for (int i = 0; i <= numlines; i++) 1989 for (int i = 0; i <= numlines; i++)
1990 { 1990 {
1991 ypos += textarray[i]->lineSpacing(); 1991 ypos += textarray[i]->lineSpacing();
1992 } 1992 }
1993 fillbuffer(numlines+1, ypos, newht); 1993 fillbuffer(numlines+1, ypos, newht);
1994 // qDebug("Optimised > %d", numlines); 1994 // qDebug("Optimised > %d", numlines);
1995 } 1995 }
1996 if (numlines > 0) 1996 if (numlines > 0)
1997 { 1997 {
1998 redrawall(); 1998 redrawall();
1999 } 1999 }
2000 } 2000 }
2001 emitRedraw(); 2001 emitRedraw();
2002 } 2002 }
2003/* 2003/*
2004 else 2004 else
2005 { 2005 {
2006 qDebug("Not so refreshing..."); 2006 qDebug("Not so refreshing...");
2007 } 2007 }
2008*/ 2008*/
2009} 2009}
2010 2010
2011void QTReader::DrawScroll( QPainter *p, int _w, int _h ) 2011void QTReader::DrawScroll( QPainter *p, int _w, int _h )
2012{ 2012{
2013 if (!buffdoc.empty()) 2013 if (!buffdoc.empty())
2014 { 2014 {
2015 QBrush checkered = QBrush( Dense4Pattern ); 2015 QBrush checkered = QBrush( Dense4Pattern );
2016 checkered.setColor(m_scrollbarcolor); 2016 checkered.setColor(m_scrollbarcolor);
2017 switch (m_scrollpos) 2017 switch (m_scrollpos)
2018 { 2018 {
2019 case 1: 2019 case 1:
2020 if (m_rotated) 2020 if (m_rotated)
2021 { 2021 {
2022 p->fillRect(0, 0, 2, _h, checkered); 2022 p->fillRect(0, 0, 2, _h, checkered);
2023 } 2023 }
2024 else 2024 else
2025 { 2025 {
2026 p->fillRect(0, _h-2, _w, 2, checkered); 2026 p->fillRect(0, _h-2, _w, 2, checkered);
2027 } 2027 }
2028 break; 2028 break;
2029 case 2: 2029 case 2:
2030 if (m_rotated) 2030 if (m_rotated)
2031 { 2031 {
2032 p->fillRect(0, _h-2, _w, 2, checkered); 2032 p->fillRect(0, _h-2, _w, 2, checkered);
2033 } 2033 }
2034 else 2034 else
2035 { 2035 {
2036 p->fillRect(_w-2, 0, 2, _h, checkered); 2036 p->fillRect(_w-2, 0, 2, _h, checkered);
2037 } 2037 }
2038 break; 2038 break;
2039 case 3: 2039 case 3:
2040 if (m_rotated) 2040 if (m_rotated)
2041 { 2041 {
2042 p->fillRect(0, 0, _w, 2, checkered); 2042 p->fillRect(0, 0, _w, 2, checkered);
2043 } 2043 }
2044 else 2044 else
2045 { 2045 {
2046 p->fillRect(0, 0, 2, _h, checkered); 2046 p->fillRect(0, 0, 2, _h, checkered);
2047 } 2047 }
2048 break; 2048 break;
2049 case 0: 2049 case 0:
2050 default: 2050 default:
2051 break; 2051 break;
2052 } 2052 }
2053 switch (m_scrollpos) 2053 switch (m_scrollpos)
2054 { 2054 {
2055 case 1: 2055 case 1:
2056 { 2056 {
2057 int ht; 2057 int ht;
2058 if (m_rotated) 2058 if (m_rotated)
2059 { 2059 {
2060 ht = _h; 2060 ht = _h;
2061 } 2061 }
2062 else 2062 else
2063 { 2063 {
2064 ht = _w; 2064 ht = _w;
2065 } 2065 }
2066 int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); 2066 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
2067 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize); 2067 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize);
2068 int sliderheight = ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize; 2068 int sliderheight = ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize;
2069 int sliderpos; 2069 int sliderpos;
2070 if (sliderheight < 10) 2070 if (sliderheight < 10)
2071 { 2071 {
2072 sliderheight = 10; 2072 sliderheight = 10;
2073 sliderpos = mid-5; 2073 sliderpos = mid-5;
2074 } 2074 }
2075 else 2075 else
2076 { 2076 {
2077 sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize; 2077 sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize;
2078 } 2078 }
2079 if (m_rotated) 2079 if (m_rotated)
2080 { 2080 {
2081 p->fillRect(0, sliderpos, 3, sliderheight, m_scrollbarcolor); 2081 p->fillRect(0, sliderpos, 3, sliderheight, m_scrollbarcolor);
2082 } 2082 }
2083 else 2083 else
2084 { 2084 {
2085 p->fillRect(sliderpos, _h-3, sliderheight, 3, m_scrollbarcolor); 2085 p->fillRect(sliderpos, _h-3, sliderheight, 3, m_scrollbarcolor);
2086 } 2086 }
2087 } 2087 }
2088 break; 2088 break;
2089 case 2: 2089 case 2:
2090 case 3: 2090 case 3:
2091 { 2091 {
2092 int ht; 2092 int ht;
2093 if (m_rotated) 2093 if (m_rotated)
2094 { 2094 {
2095 ht = _w; 2095 ht = _w;
2096 } 2096 }
2097 else 2097 else
2098 { 2098 {
2099 ht = _h; 2099 ht = _h;
2100 } 2100 }
2101 int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); 2101 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
2102 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize); 2102 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize);
2103 int sliderheight = ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize; 2103 int sliderheight = ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize;
2104 int sliderpos; 2104 int sliderpos;
2105 if (sliderheight < 10) 2105 if (sliderheight < 10)
2106 { 2106 {
2107 sliderheight = 10; 2107 sliderheight = 10;
2108 sliderpos = mid-5; 2108 sliderpos = mid-5;
2109 } 2109 }
2110 else 2110 else
2111 { 2111 {
2112 sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize; 2112 sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize;
2113 } 2113 }
2114 if (m_rotated) 2114 if (m_rotated)
2115 { 2115 {
2116 int hoff; 2116 int hoff;
2117 if (m_scrollpos == 2) //right 2117 if (m_scrollpos == 2) //right
2118 { 2118 {
2119 hoff = _h-3; 2119 hoff = _h-3;
2120 } 2120 }
2121 else 2121 else
2122 { 2122 {
2123 hoff = 0; 2123 hoff = 0;
2124 } 2124 }
2125 p->fillRect(ht-sliderpos-sliderheight, hoff, sliderheight, 3, m_scrollbarcolor); 2125 p->fillRect(ht-sliderpos-sliderheight, hoff, sliderheight, 3, m_scrollbarcolor);
2126 } 2126 }
2127 else 2127 else
2128 { 2128 {
2129 int hoff; 2129 int hoff;
2130 if (m_scrollpos == 2) //right 2130 if (m_scrollpos == 2) //right
2131 { 2131 {
2132 hoff = _w-3; 2132 hoff = _w-3;
2133 } 2133 }
2134 else 2134 else
2135 { 2135 {
2136 hoff = 0; 2136 hoff = 0;
2137 } 2137 }
2138 p->fillRect(hoff, sliderpos, 3, sliderheight, m_scrollbarcolor); 2138 p->fillRect(hoff, sliderpos, 3, sliderheight, m_scrollbarcolor);
2139 } 2139 }
2140 } 2140 }
2141 break; 2141 break;
2142 case 0: 2142 case 0:
2143 default: 2143 default:
2144 break; 2144 break;
2145 } 2145 }
2146 } 2146 }
2147} 2147}
2148 2148
2149/* 2149/*
2150void QTReader::DrawScroll( QPainter *p ) 2150void QTReader::DrawScroll( QPainter *p )
2151{ 2151{
2152 if (m_border > 5 && !buffdoc.empty()) 2152 if (m_border > 5 && !buffdoc.empty())
2153 { 2153 {
2154 int ht, wh; 2154 int ht, wh;
2155 if (m_rotated) 2155 if (m_rotated)
2156 { 2156 {
2157 ht = width(); 2157 ht = width();
2158 wh = height()g; 2158 wh = height()g;
2159 p->fillRect(0, wh-2, ht, 2, cyan); 2159 p->fillRect(0, wh-2, ht, 2, cyan);
2160 } 2160 }
2161 else 2161 else
2162 { 2162 {
2163 ht = height(); 2163 ht = height();
2164 wh = width(); 2164 wh = width();
2165 p->fillRect(wh-2, 0, 2, ht, cyan); 2165 p->fillRect(wh-2, 0, 2, ht, cyan);
2166 } 2166 }
2167 int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); 2167 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
2168 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize); 2168 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize);
2169 if (m_rotated) 2169 if (m_rotated)
2170 { 2170 {
2171 p->fillRect(ht-mid-5, wh-2, 10, 2, yellow); 2171 p->fillRect(ht-mid-5, wh-2, 10, 2, yellow);
2172 p->fillRect(ht-(ht*(locnarray[numlines]-buffdoc.startSection())+sectionsize/2)/sectionsize, wh-2, ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize, 2, magenta); 2172 p->fillRect(ht-(ht*(locnarray[numlines]-buffdoc.startSection())+sectionsize/2)/sectionsize, wh-2, ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize, 2, magenta);
2173 } 2173 }
2174 else 2174 else
2175 { 2175 {
2176 p->fillRect(wh-2, mid-5, 2, 10, yellow); 2176 p->fillRect(wh-2, mid-5, 2, 10, yellow);
2177 p->fillRect(wh-2, (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize, 2, ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize, magenta); 2177 p->fillRect(wh-2, (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize, 2, ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize, magenta);
2178 } 2178 }
2179 } 2179 }
2180} 2180}
2181*/ 2181*/
2182QString QTReader::firstword() 2182QString QTReader::firstword()
2183{ 2183{
2184 if (m_bMonoSpaced) 2184 if (m_bMonoSpaced)
2185 { 2185 {
2186 return toQString(textarray[0]->data()); 2186 return toQString(textarray[0]->data());
2187 } 2187 }
2188 else 2188 else
2189 { 2189 {
2190 int start, end, len, j; 2190 int start, end, len, j;
2191 for (j = 0; j < numlines; j++) 2191 for (j = 0; j < numlines; j++)
2192 { 2192 {
2193 len = textarray[j]->length(); 2193 len = textarray[j]->length();
2194 for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++); 2194 for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++);
2195 if (start < len) break; 2195 if (start < len) break;
2196 } 2196 }
2197 if (j < numlines) 2197 if (j < numlines)
2198 { 2198 {
2199 QString ret = ""; 2199 QString ret = "";
2200 for (end = start; end < len && isalpha((*textarray[j])[end]); end++) 2200 for (end = start; end < len && isalpha((*textarray[j])[end]); end++)
2201 ret += (*textarray[j])[end]; 2201 ret += (*textarray[j])[end];
2202 if (ret.isEmpty()) ret = "Current position"; 2202 if (ret.isEmpty()) ret = "Current position";
2203 return ret; 2203 return ret;
2204 } 2204 }
2205 else 2205 else
2206 return "Current position"; 2206 return "Current position";
2207 } 2207 }
2208} 2208}
2209 2209
2210// 2210//
2211// Construct the QTReader with buttons. 2211// Construct the QTReader with buttons.
2212// 2212//
2213 2213
2214bool QTReader::ChangeFont(int tgt) 2214bool QTReader::ChangeFont(int tgt)
2215{ 2215{
2216 return m_fontControl.ChangeFont(m_fontname, tgt); 2216 return m_fontControl.ChangeFont(m_fontname, tgt);
2217} 2217}
2218 2218
2219void QTReader::init() 2219void QTReader::init()
2220{ 2220{
2221 setBackgroundColor( m_bg ); 2221 setBackgroundColor( m_bg );
2222 buffdoc.setfilter(getfilter()); 2222 buffdoc.setfilter(getfilter());
2223 ChangeFont(m_textsize); 2223 ChangeFont(m_textsize);
2224 setFocusPolicy(QWidget::StrongFocus); 2224 setFocusPolicy(QWidget::StrongFocus);
2225 timer = new QTimer(this); 2225 timer = new QTimer(this);
2226 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); 2226 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
2227#ifdef USETIMER 2227#ifdef USETIMER
2228 m_dragtimer = new QTimer(this); 2228 m_dragtimer = new QTimer(this);
2229 connect(m_dragtimer, SIGNAL(timeout()), this, SLOT(actionDrag())); 2229 connect(m_dragtimer, SIGNAL(timeout()), this, SLOT(actionDrag()));
2230#endif 2230#endif
2231 // QMessageBox::information(this, "init", m_lastfile, 1); 2231 // QMessageBox::information(this, "init", m_lastfile, 1);
2232 setfont(); 2232 setfont();
2233} 2233}
2234 2234
2235// 2235//
2236// Clean up 2236// Clean up
2237// 2237//
2238QTReader::~QTReader() 2238QTReader::~QTReader()
2239{ 2239{
2240 if (m_output != NULL) 2240 if (m_output != NULL)
2241 { 2241 {
2242 delete m_output; 2242 delete m_output;
2243 } 2243 }
2244 if (dbuff != NULL) 2244 if (dbuff != NULL)
2245 { 2245 {
2246 delete dbuff; 2246 delete dbuff;
2247 delete dbp; 2247 delete dbp;
2248 } 2248 }
2249#ifdef USEQPE 2249#ifdef USEQPE
2250 if (m_autoScroll) 2250 if (m_autoScroll)
2251 { 2251 {
2252 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 2252 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
2253 } 2253 }
2254#endif 2254#endif
2255#ifdef _SCROLLPIPE 2255#ifdef _SCROLLPIPE
2256 if (m_pipeout != NULL) 2256 if (m_pipeout != NULL)
2257 { 2257 {
2258 fclose(m_pipeout); 2258 fclose(m_pipeout);
2259 } 2259 }
2260#endif 2260#endif
2261} 2261}
2262 2262
2263// 2263//
2264// Called when the print button is clicked. 2264// Called when the print button is clicked.
2265// 2265//
2266/* 2266/*
2267void QTReader::printIt() 2267void QTReader::printIt()
2268{ 2268{
2269#ifndef QT_NO_PRINTER 2269#ifndef QT_NO_PRINTER
2270 if ( printer->setup( this ) ) { 2270 if ( printer->setup( this ) ) {
2271 QPainter paint; 2271 QPainter paint;
2272 if ( !paint.begin( printer ) ) 2272 if ( !paint.begin( printer ) )
2273 return; 2273 return;
2274 drawIt( &paint ); 2274 drawIt( &paint );
2275 } 2275 }
2276#endif 2276#endif
2277} 2277}
2278*/ 2278*/
2279// 2279//
2280// Called when the widget needs to be updated. 2280// Called when the widget needs to be updated.
2281// 2281//
2282 2282
2283void QTReader::paintEvent( QPaintEvent * p ) 2283void QTReader::paintEvent( QPaintEvent * p )
2284{ 2284{
2285 if ((dbuff != NULL) && !m_outofdate) 2285 if ((dbuff != NULL) && !m_outofdate)
2286 { 2286 {
2287 if (m_rotated) 2287 if (m_rotated)
2288 { 2288 {
2289 if ((p->rect().width() != width()) || (p->rect().height() != height())) 2289 if ((p->rect().width() != width()) || (p->rect().height() != height()))
2290 { 2290 {
2291 qDebug("Partial paint"); 2291 qDebug("Partial paint");
2292 QRect r; 2292 QRect r;
2293 r.setTop(width()-p->rect().right()-1); 2293 r.setTop(width()-p->rect().right()-1);
2294 r.setLeft(p->rect().top()); 2294 r.setLeft(p->rect().top());
2295 r.setHeight(p->rect().width()); 2295 r.setHeight(p->rect().width());
2296 r.setWidth(p->rect().height()); 2296 r.setWidth(p->rect().height());
2297 QPixmap p1(r.width(), r.height()); 2297 QPixmap p1(r.width(), r.height());
2298 bitBlt(&p1, QPoint(0, 0), dbuff, r); 2298 bitBlt(&p1, QPoint(0, 0), dbuff, r);
2299 QWMatrix m; 2299 QWMatrix m;
2300 m.rotate(90); 2300 m.rotate(90);
2301 QPixmap p2 = p1.xForm(m); 2301 QPixmap p2 = p1.xForm(m);
2302 bitBlt(this, p->rect().left(), p->rect().top(), &p2, 0, 0, -1, -1); 2302 bitBlt(this, p->rect().left(), p->rect().top(), &p2, 0, 0, -1, -1);
2303 } 2303 }
2304 else 2304 else
2305 { 2305 {
2306 qDebug("Full paint"); 2306 qDebug("Full paint");
2307 QWMatrix m; 2307 QWMatrix m;
2308 m.rotate(90); 2308 m.rotate(90);
2309 QPixmap rp = dbuff->xForm(m); 2309 QPixmap rp = dbuff->xForm(m);
2310 bitBlt(this, 0,0,&rp,0,0,-1,-1); 2310 bitBlt(this, 0,0,&rp,0,0,-1,-1);
2311 } 2311 }
2312 } 2312 }
2313 else 2313 else
2314 { 2314 {
2315 //bitBlt(this, 0,0,dbuff,0,0,-1,-1); 2315 //bitBlt(this, 0,0,dbuff,0,0,-1,-1);
2316 bitBlt(this,p->rect().topLeft(),dbuff,p->rect()); 2316 bitBlt(this,p->rect().topLeft(),dbuff,p->rect());
2317 } 2317 }
2318 } 2318 }
2319 else 2319 else
2320 { 2320 {
2321 drawFonts(); 2321 drawFonts();
2322 } 2322 }
2323 m_outofdate = false; 2323 m_outofdate = false;
2324} 2324}
2325 2325
2326// 2326//
2327// Called when the widget has been resized. 2327// Called when the widget has been resized.
2328// Moves the button group to the upper right corner 2328// Moves the button group to the upper right corner
2329// of the widget. 2329// of the widget.
2330 2330
2331/* 2331/*
2332void QTReader::resizeEvent( QResizeEvent * ) 2332void QTReader::resizeEvent( QResizeEvent * )
2333{ 2333{
2334// // qDebug("resize:(%u,%u)", width(), height()); 2334// // qDebug("resize:(%u,%u)", width(), height());
2335 // bgroup->move( width()-bgroup->width(), 0 ); 2335 // bgroup->move( width()-bgroup->width(), 0 );
2336} 2336}
2337*/ 2337*/
2338 2338
2339// 2339//
2340// Create and display our widget. 2340// Create and display our widget.
2341// 2341//
2342/* 2342/*
2343int main( int argc, tchar **argv ) 2343int main( int argc, tchar **argv )
2344{ 2344{
2345 QApplication app( argc, argv ); 2345 QApplication app( argc, argv );
2346 QTReader draw; 2346 QTReader draw;
2347 app.setMainWidget( &draw ); 2347 app.setMainWidget( &draw );
2348 draw.setCaption("Qt Example - Drawdemo"); 2348 draw.setCaption("Qt Example - Drawdemo");
2349 draw.show(); 2349 draw.show();
2350 return app.exec(); 2350 return app.exec();
2351} 2351}
2352*/ 2352*/
2353 2353
2354 2354
2355bool QTReader::locate(unsigned long n) 2355bool QTReader::locate(unsigned long n)
2356{ 2356{
2357 m_outofdate = true; 2357 m_outofdate = true;
2358 m_lastwidth = 0; 2358 m_lastwidth = 0;
2359 locnarray[0] = n; 2359 locnarray[0] = n;
2360 ResetScroll(); 2360 ResetScroll();
2361 update(); 2361 update();
2362 return true; 2362 return true;
2363} 2363}
2364/* 2364/*
2365bool QTReader::locate(unsigned long n) { 2365bool QTReader::locate(unsigned long n) {
2366 //printf("Locate\n"); 2366 //printf("Locate\n");
2367 buffdoc.locate(n); 2367 buffdoc.locate(n);
2368// // qDebug("&buffdoc.located"); 2368// // qDebug("&buffdoc.located");
2369 ResetScroll(); 2369 ResetScroll();
2370 fillbuffer(); 2370 fillbuffer();
2371 m_outofdate = true; 2371 m_outofdate = true;
2372// // qDebug("&Buffer filled"); 2372// // qDebug("&Buffer filled");
2373 update(); 2373 update();
2374// // qDebug("&Located"); 2374// // qDebug("&Located");
2375 emitRedraw(); 2375 emitRedraw();
2376 return true; 2376 return true;
2377} 2377}
2378*/ 2378*/
2379unsigned int QTReader::screenlines() 2379unsigned int QTReader::screenlines()
2380{ 2380{
2381 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 2381 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent;
2382 // return (height()-m_descent)/(m_linespacing); 2382 // return (height()-m_descent)/(m_linespacing);
2383 return (height()-2)/(m_linespacing); 2383 return (height()-2)/(m_linespacing);
2384}; 2384};
2385 2385
2386bool QTReader::fillbuffer(int reuse, int ht, int newht) 2386bool QTReader::fillbuffer(int reuse, int ht, int newht)
2387{ 2387{
2388 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); 2388 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
2389 if (hmargin < m_bottommargin) hmargin = m_bottommargin; 2389 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
2390 if (ht < 0) ht = m_topmargin; 2390 if (ht < 0) ht = m_topmargin;
2391 if (buffdoc.empty()) return false; 2391 if (buffdoc.empty()) return false;
2392 if (newht < 0) 2392 if (newht < 0)
2393 m_lastheight = (m_rotated) ? width() : height(); 2393 m_lastheight = (m_rotated) ? width() : height();
2394 else 2394 else
2395 m_lastheight = newht; 2395 m_lastheight = newht;
2396 int ch; 2396 int ch;
2397 bool ret = false; 2397 bool ret = false;
2398 unsigned int oldpagepos = locnarray[reuse]; 2398 unsigned int oldpagepos = locnarray[reuse];
2399 int lastypos = ht, ypos = ht; 2399 int lastypos = ht, ypos = ht;
2400 numlines = reuse; 2400 numlines = reuse;
2401 while (ypos < m_lastheight - hmargin || numlines < 2) 2401 while (ypos < m_lastheight - hmargin || numlines < 2)
2402 { 2402 {
2403 lastypos = ypos; 2403 lastypos = ypos;
2404 if (textarray[numlines] == NULL) 2404 if (textarray[numlines] == NULL)
2405 { 2405 {
2406 textarray[numlines] = new CDrawBuffer(&m_fontControl); 2406 textarray[numlines] = new CDrawBuffer(&m_fontControl);
2407 } 2407 }
2408 locnarray[numlines] = locate(); 2408 locnarray[numlines] = locate();
2409 int ch = getline(textarray[numlines]); 2409 int ch = getline(textarray[numlines]);
2410 ypos += textarray[numlines]->lineSpacing(); 2410 ypos += textarray[numlines]->lineSpacing();
2411 /* 2411 /*
2412 QString tmp = toQString(textarray[numlines]->data()); 2412 QString tmp = toQString(textarray[numlines]->data());
2413 printf("[%u, %u, %u](%s):%s\n", lastypos, m_lastheight-hmargin, ypos, 2413 printf("[%u, %u, %u](%s):%s\n", lastypos, m_lastheight-hmargin, ypos,
2414 ((textarray[numlines]->showPartial()) ? "TRUE" : "FALSE"), 2414 ((textarray[numlines]->showPartial()) ? "TRUE" : "FALSE"),
2415 (const char*)tmp); 2415 (const char*)tmp);
2416 */ 2416 */
2417 numlines++; 2417 numlines++;
2418 if (!ch) 2418 if (!ch)
2419 { 2419 {
2420 if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/) 2420 if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/)
2421 { 2421 {
2422 qDebug("FALSE"); 2422 qDebug("FALSE");
2423 if (oldpagepos < buffdoc.endSection()) 2423 if (oldpagepos < buffdoc.endSection())
2424 locate(oldpagepos); 2424 locate(oldpagepos);
2425 else 2425 else
2426 dopageup(buffdoc.endSection()); 2426 dopageup(buffdoc.endSection());
2427 return false; 2427 return false;
2428 } 2428 }
2429 else 2429 else
2430 { 2430 {
2431 qDebug("TRUE"); 2431 qDebug("TRUE");
2432 --numlines; 2432 --numlines;
2433 mylastpos = locate(); 2433 mylastpos = locate();
2434 return true; 2434 return true;
2435 } 2435 }
2436 } 2436 }
2437 if (numlines > 1 && textarray[numlines-2]->isBop()) 2437 if (numlines > 1 && textarray[numlines-2]->isBop())
2438 { 2438 {
2439 --numlines; 2439 --numlines;
2440 mylastpos = locate(); 2440 mylastpos = locate();
2441 return true; 2441 return true;
2442 } 2442 }
2443 } 2443 }
2444 2444
2445 --numlines; 2445 --numlines;
2446 mylastpos = locate(); 2446 mylastpos = locate();
2447 m_scrollpart = m_lastheight - lastypos - hmargin; 2447 m_scrollpart = m_lastheight - lastypos - hmargin;
2448 if (m_autoScroll) 2448 if (m_autoScroll)
2449 { 2449 {
2450 CalculateScrollParameters(); 2450 CalculateScrollParameters();
2451 } 2451 }
2452 return true; 2452 return true;
2453} 2453}
2454 2454
2455void QTReader::dopagedn() 2455void QTReader::dopagedn()
2456{ 2456{
2457// qDebug("HEIGHT(2):%d", m_lastheight); 2457// qDebug("HEIGHT(2):%d", m_lastheight);
2458 ResetScroll(); 2458 ResetScroll();
2459 int skip = 0, ypos = m_topmargin; 2459 int skip = 0, ypos = m_topmargin;
2460 if (locate() != mylastpos) 2460 if (locate() != mylastpos)
2461 { 2461 {
2462 jumpto(mylastpos); 2462 jumpto(mylastpos);
2463 } 2463 }
2464 CDrawBuffer* reusebuffer = textarray[numlines]; 2464 CDrawBuffer* reusebuffer = textarray[numlines];
2465 if (reusebuffer != NULL) 2465 if (reusebuffer != NULL)
2466 { 2466 {
2467 if (reusebuffer->eof()) return; 2467 if (reusebuffer->eof()) return;
2468 for (int i = 0; i <= m_overlap; i++) 2468 for (int i = 0; i <= m_overlap; i++)
2469 { 2469 {
2470 int offset = numlines - m_overlap + i; 2470 int offset = numlines - m_overlap + i;
2471 reusebuffer = textarray[offset]; 2471 reusebuffer = textarray[offset];
2472 size_t reuselocn = locnarray[offset]; 2472 size_t reuselocn = locnarray[offset];
2473 textarray[offset] = textarray[i]; 2473 textarray[offset] = textarray[i];
2474 textarray[i] = reusebuffer; 2474 textarray[i] = reusebuffer;
2475 // reusebuffer->empty(); 2475 // reusebuffer->empty();
2476 locnarray[offset] = locnarray[i]; 2476 locnarray[offset] = locnarray[i];
2477 locnarray[i] = reuselocn; 2477 locnarray[i] = reuselocn;
2478 ypos += textarray[i]->lineSpacing(); 2478 ypos += textarray[i]->lineSpacing();
2479 skip++; 2479 skip++;
2480 } 2480 }
2481 } 2481 }
2482 if (numlines <= 1) 2482 if (numlines <= 1)
2483 { 2483 {
2484 skip = 0; 2484 skip = 0;
2485 ypos = 0; 2485 ypos = 0;
2486 qDebug("Doing extra skip"); 2486 qDebug("Doing extra skip");
2487 } 2487 }
2488 if (fillbuffer(skip, ypos)) 2488 if (fillbuffer(skip, ypos))
2489 { 2489 {
2490 drawFonts(); 2490 drawFonts();
2491 } 2491 }
2492} 2492}
2493 2493
2494void QTReader::dopageup() 2494void QTReader::dopageup()
2495{ 2495{
2496 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]); 2496 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]);
2497} 2497}
2498 2498
2499bool QTReader::synch(size_t start, size_t end) 2499bool QTReader::synch(size_t start, size_t end)
2500{ 2500{
2501 jumpto(start); 2501 jumpto(start);
2502 while (start++ < end) 2502 while (start++ < end)
2503 { 2503 {
2504 tchar ch = getch(); 2504 tchar ch = getch();
2505 if (ch == 10) return true; 2505 if (ch == 10) return true;
2506 if ((ch == UEOF) || (ch == 6)) 2506 if ((ch == UEOF) || (ch == 6))
2507 { 2507 {
2508 return false; 2508 return false;
2509 } 2509 }
2510 } 2510 }
2511 return false; 2511 return false;
2512} 2512}
2513 2513
2514void QTReader::dopageup(unsigned int target) 2514void QTReader::dopageup(unsigned int target)
2515{ 2515{
2516 ResetScroll(); 2516 ResetScroll();
2517 CBufferFace<CDrawBuffer*> buff; 2517 CBufferFace<CDrawBuffer*> buff;
2518 CBufferFace<size_t> loc; 2518 CBufferFace<size_t> loc;
2519 size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0; 2519 size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0;
2520 qDebug("dopageup:: locate():%u pagelocate():%u guess:%u", locate(), pagelocate(), guess); 2520 qDebug("dopageup:: locate():%u pagelocate():%u guess:%u", locate(), pagelocate(), guess);
2521 bool ch = true; 2521 bool ch = true;
2522 int nbfl, ypos = m_topmargin; 2522 int nbfl, ypos = m_topmargin;
2523 if (guess < 128) guess = 128; 2523 if (guess < 128) guess = 128;
2524 while (1) 2524 while (1)
2525 { 2525 {
2526 // qDebug("Guess:%u", guess); 2526 // qDebug("Guess:%u", guess);
2527 2527
2528 ch = true; 2528 ch = true;
2529 if (target < guess) 2529 if (target < guess)
2530 { 2530 {
2531 delta = 0; // 0 is a flag to say don't guess any more 2531 delta = 0; // 0 is a flag to say don't guess any more
2532 jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() ); 2532 jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() );
2533 } 2533 }
2534 else if (!m_continuousDocument && (target - guess < buffdoc.startSection())) 2534 else if (!m_continuousDocument && (target - guess < buffdoc.startSection()))
2535 { 2535 {
2536 delta = 0; // 0 is a flag to say don't guess any more 2536 delta = 0; // 0 is a flag to say don't guess any more
2537 qDebug("Jumping to startsection:%d", buffdoc.startSection()); 2537 qDebug("Jumping to startsection:%d", buffdoc.startSection());
2538 jumpto(buffdoc.startSection()); 2538 jumpto(buffdoc.startSection());
2539 } 2539 }
2540 else 2540 else
2541 { 2541 {
2542 delta = guess; 2542 delta = guess;
2543 if (!synch(target-delta, target-lastdelta)) 2543 if (!synch(target-delta, target-lastdelta))
2544 { 2544 {
2545 lastdelta = delta; 2545 lastdelta = delta;
2546 if (guess < 4000) 2546 if (guess < 4000)
2547 { 2547 {
2548 guess <<= 1; 2548 guess <<= 1;
2549 continue; 2549 continue;
2550 } 2550 }
2551 else 2551 else
2552 { 2552 {
2553 jumpto(target-delta); 2553 jumpto(target-delta);
2554 } 2554 }
2555 } 2555 }
2556 } 2556 }
2557 2557
2558 nbfl = 0; 2558 nbfl = 0;
2559 ypos = m_topmargin; 2559 ypos = m_topmargin;
2560 2560
2561 while (locate() < target) 2561 while (locate() < target)
2562 { 2562 {
2563 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); 2563 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
2564 loc[nbfl] = locate(); 2564 loc[nbfl] = locate();
2565 ch = getline(buff[nbfl]); 2565 ch = getline(buff[nbfl]);
2566 ypos += buff[nbfl]->lineSpacing(); 2566 ypos += buff[nbfl]->lineSpacing();
2567 nbfl++; 2567 nbfl++;
2568 if (!ch) break; 2568 if (!ch) break;
2569 } 2569 }
2570 if (guess < 4000 && ypos < ((m_rotated) ? width() : height())-(m_bottommargin) && (delta != 0)) 2570 if (guess < 4000 && ypos < ((m_rotated) ? width() : height())-(m_bottommargin) && (delta != 0))
2571 { 2571 {
2572 for (int i = 0; i < nbfl; i++) 2572 for (int i = 0; i < nbfl; i++)
2573 { 2573 {
2574 delete buff[i]; 2574 delete buff[i];
2575 buff[i] = NULL; 2575 buff[i] = NULL;
2576 } 2576 }
2577 guess <<= 1; 2577 guess <<= 1;
2578 continue; 2578 continue;
2579 } 2579 }
2580 break; 2580 break;
2581 } 2581 }
2582 if (ch) 2582 if (ch)
2583 { 2583 {
2584 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); 2584 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
2585 loc[nbfl] = locate(); 2585 loc[nbfl] = locate();
2586 int ch = getline(buff[nbfl]); 2586 int ch = getline(buff[nbfl]);
2587 nbfl++; 2587 nbfl++;
2588 } 2588 }
2589/* 2589/*
2590 ypos = 0; 2590 ypos = 0;
2591 numlines = 0; 2591 numlines = 0;
2592 while (ypos < height() && numlines <= nbfl-1) 2592 while (ypos < height() && numlines <= nbfl-1)
2593 { 2593 {
2594 ypos += buff[nbfl - numlines - 1]->lineSpacing(); 2594 ypos += buff[nbfl - numlines - 1]->lineSpacing();
2595 numlines++; 2595 numlines++;
2596 } 2596 }
2597 --numlines; 2597 --numlines;
2598*/ 2598*/
2599 2599
2600 ypos = m_topmargin; 2600 ypos = m_topmargin;
2601 numlines = 0; 2601 numlines = 0;
2602 while (ypos < ((m_rotated) ? width() : height())-m_bottommargin && numlines+2 <= nbfl) 2602 while (ypos < ((m_rotated) ? width() : height())-m_bottommargin && numlines+2 <= nbfl)
2603 { 2603 {
2604 ypos += buff[nbfl - numlines - 2]->lineSpacing(); 2604 ypos += buff[nbfl - numlines - 2]->lineSpacing();
2605 numlines++; 2605 numlines++;
2606 } 2606 }
2607 if (numlines > 0) --numlines; 2607 if (numlines > 0) --numlines;
2608 if (numlines == 0 && nbfl > 1) numlines = 1; 2608 if (numlines == 0 && nbfl > 1) numlines = 1;
2609 2609
2610 int offset = nbfl-1; 2610 int offset = nbfl-1;
2611 offset -= numlines; 2611 offset -= numlines;
2612 ypos = m_topmargin; 2612 ypos = m_topmargin;
2613 for (int i = 0; i <= numlines; i++) 2613 for (int i = 0; i <= numlines; i++)
2614 { 2614 {
2615 delete textarray[i]; 2615 delete textarray[i];
2616 textarray[i] = buff[offset+i]; 2616 textarray[i] = buff[offset+i];
2617 locnarray[i] = loc[offset + i]; 2617 locnarray[i] = loc[offset + i];
2618 ypos += textarray[i]->lineSpacing(); 2618 ypos += textarray[i]->lineSpacing();
2619 } 2619 }
2620#ifdef _WINDOWS 2620#ifdef _WINDOWS
2621 for (i = 0; i < nbfl - numlines - 1; i++) 2621 for (i = 0; i < nbfl - numlines - 1; i++)
2622#else 2622#else
2623 for (int i = 0; i < nbfl - numlines - 1; i++) 2623 for (int i = 0; i < nbfl - numlines - 1; i++)
2624#endif 2624#endif
2625 { 2625 {
2626 delete buff[i]; 2626 delete buff[i];
2627 } 2627 }
2628 2628
2629 while (ypos < ((m_rotated) ? width() : height())-m_bottommargin) 2629 while (ypos < ((m_rotated) ? width() : height())-m_bottommargin)
2630 { 2630 {
2631 numlines++; 2631 numlines++;
2632 locnarray[numlines] = locate(); 2632 locnarray[numlines] = locate();
2633 if (textarray[numlines] == NULL) textarray[numlines] = new CDrawBuffer(&m_fontControl); 2633 if (textarray[numlines] == NULL) textarray[numlines] = new CDrawBuffer(&m_fontControl);
2634 if (!getline(textarray[numlines])) break; 2634 if (!getline(textarray[numlines])) break;
2635 ypos += textarray[numlines]->lineSpacing(); 2635 ypos += textarray[numlines]->lineSpacing();
2636 } 2636 }
2637 2637
2638 mylastpos = locate(); 2638 mylastpos = locate();
2639 CalculateScrollParameters(); 2639 CalculateScrollParameters();
2640 drawFonts(); 2640 drawFonts();
2641 // repaint(); 2641 // repaint();
2642} 2642}
2643 2643
2644bool QTReader::load_file(const char *newfile, unsigned int _lcn) 2644bool QTReader::load_file(const char *newfile, unsigned int _lcn)
2645{ 2645{
2646// QMessageBox::information(this, "Name", name, 1); 2646// QMessageBox::information(this, "Name", name, 1);
2647// QMessageBox::information(this, "load_file", newfile, 1); 2647// QMessageBox::information(this, "load_file", newfile, 1);
2648 int prog = 0; 2648 int prog = 0;
2649 bool bRC = false; 2649 bool bRC = false;
2650 unsigned int lcn = _lcn; 2650 unsigned int lcn = _lcn;
2651 bDoUpdates = false; 2651 bDoUpdates = false;
2652 ResetScroll(); 2652 ResetScroll();
2653 if (m_lastfile == newfile && lcn == 0) 2653 if (m_lastfile == newfile && lcn == 0)
2654 { 2654 {
2655 lcn = m_lastposn; 2655 lcn = m_lastposn;
2656 } 2656 }
2657 // QMessageBox::information(0, "Opening...", newfile); 2657 // QMessageBox::information(0, "Opening...", newfile);
2658 if (m_rotated) 2658 if (m_rotated)
2659 { 2659 {
2660 m_lastwidth = height(); 2660 m_lastwidth = height();
2661 m_lastheight = width(); 2661 m_lastheight = width();
2662 } 2662 }
2663 else 2663 else
2664 { 2664 {
2665 m_lastwidth = width(); 2665 m_lastwidth = width();
2666 m_lastheight = height(); 2666 m_lastheight = height();
2667 } 2667 }
2668 if (buffdoc.openfile(this,newfile) == 0) 2668 if (buffdoc.openfile(this,newfile) == 0)
2669 { 2669 {
2670 m_lastfile = newfile; 2670 m_lastfile = newfile;
2671 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); 2671 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
2672 bRC = true; 2672 bRC = true;
2673 buffdoc.setContinuous(m_continuousDocument); 2673 buffdoc.setContinuous(m_continuousDocument);
2674 qDebug("buffdoc.openfile done"); 2674 qDebug("buffdoc.openfile done");
2675 } 2675 }
2676 setfilter(getfilter()); 2676 setfilter(getfilter());
2677 qDebug("Updated"); 2677 qDebug("Updated");
2678 bDoUpdates = true; 2678 bDoUpdates = true;
2679 locate(lcn); 2679 locate(lcn);
2680 return bRC; 2680 return bRC;
2681} 2681}
2682 2682
2683void QTReader::lineDown() 2683void QTReader::lineDown()
2684{ 2684{
2685 int ypos = m_topmargin; 2685 int ypos = m_topmargin;
2686 ResetScroll(); 2686 ResetScroll();
2687 int offset = numlines; 2687 int offset = numlines;
2688 2688
2689 for (int i = 0; i <= numlines; i++) 2689 for (int i = 0; i <= numlines; i++)
2690 { 2690 {
2691 if ((ypos += textarray[numlines-i]->lineSpacing()) > ((m_rotated) ? width() : height())) 2691 if ((ypos += textarray[numlines-i]->lineSpacing()) > ((m_rotated) ? width() : height()))
2692 { 2692 {
2693 offset = i-1; 2693 offset = i-1;
2694 break; 2694 break;
2695 } 2695 }
2696 } 2696 }
2697 offset = numlines - offset; 2697 offset = numlines - offset;
2698#ifdef _WINDOWS 2698#ifdef _WINDOWS
2699 for (i = offset; i <= numlines; i++) 2699 for (i = offset; i <= numlines; i++)
2700#else 2700#else
2701 for (int i = offset; i <= numlines; i++) 2701 for (int i = offset; i <= numlines; i++)
2702#endif 2702#endif
2703 { 2703 {
2704 CDrawBuffer* buff = textarray[i-offset]; 2704 CDrawBuffer* buff = textarray[i-offset];
2705 textarray[i-offset] = textarray[i]; 2705 textarray[i-offset] = textarray[i];
2706 locnarray[i-offset] = locnarray[i]; 2706 locnarray[i-offset] = locnarray[i];
2707 textarray[i] = buff; 2707 textarray[i] = buff;
2708 } 2708 }
2709 numlines = numlines - offset + 1; 2709 numlines = numlines - offset + 1;
2710 locnarray[numlines] = locate(); 2710 locnarray[numlines] = locate();
2711 if (textarray[numlines] == NULL) 2711 if (textarray[numlines] == NULL)
2712 { 2712 {
2713 textarray[numlines] = new CDrawBuffer(&m_fontControl); 2713 textarray[numlines] = new CDrawBuffer(&m_fontControl);
2714 } 2714 }
2715 getline(textarray[numlines]); 2715 getline(textarray[numlines]);
2716 mylastpos = locate(); 2716 mylastpos = locate();
2717 m_outofdate = true; 2717 m_outofdate = true;
2718 update(); 2718 update();
2719} 2719}
2720/* 2720/*
2721void QTReader::lineUp() 2721void QTReader::lineUp()
2722{ 2722{
2723 CBuffer** buff = textarray; 2723 CBuffer** buff = textarray;
2724 unsigned int *loc = new unsigned int[numlines]; 2724 unsigned int *loc = new unsigned int[numlines];
2725 int cbptr = 0; 2725 int cbptr = 0;
2726 if (locate() != mylastpos) jumpto(mylastpos); 2726 if (locate() != mylastpos) jumpto(mylastpos);
2727 unsigned int target = locnarray[numlines-1]; 2727 unsigned int target = locnarray[numlines-1];
2728 if (buffdoc.hasrandomaccess()) 2728 if (buffdoc.hasrandomaccess())
2729 { 2729 {
2730 unsigned int delta = locate()-pagelocate(); 2730 unsigned int delta = locate()-pagelocate();
2731 if (delta < 64) delta = 64; 2731 if (delta < 64) delta = 64;
2732 do 2732 do
2733 { 2733 {
2734 delta <<= 1; 2734 delta <<= 1;
2735 if (delta >= target) 2735 if (delta >= target)
2736 { 2736 {
2737 delta = target; 2737 delta = target;
2738 jumpto(0); 2738 jumpto(0);
2739 for (int i = 0; i < numlines; i++) 2739 for (int i = 0; i < numlines; i++)
2740 { 2740 {
2741 loc[i] = locate(); 2741 loc[i] = locate();
2742 getline(buff[i]); 2742 getline(buff[i]);
2743 } 2743 }
2744 break; 2744 break;
2745 } 2745 }
2746 jumpto(target-delta); 2746 jumpto(target-delta);
2747 do 2747 do
2748 { 2748 {
2749 buffdoc.getline(buff[0],width()); 2749 buffdoc.getline(buff[0],width());
2750#ifdef WS 2750#ifdef WS
2751 //printf("Trying:%s\n",buff[0]); 2751 //printf("Trying:%s\n",buff[0]);
2752#endif 2752#endif
2753 if (locate() > target) continue; 2753 if (locate() > target) continue;
2754 } 2754 }
2755 while (!buffdoc.iseol()); 2755 while (!buffdoc.iseol());
2756 for (int i = 0; i < numlines; i++) 2756 for (int i = 0; i < numlines; i++)
2757 { 2757 {
2758 loc[i] = locate(); 2758 loc[i] = locate();
2759 buffdoc.getline(buff[i],width()); 2759 buffdoc.getline(buff[i],width());
2760#ifdef WS 2760#ifdef WS
2761 //printf("Filling:%s\n",buff[i]); 2761 //printf("Filling:%s\n",buff[i]);
2762#endif 2762#endif
2763 } 2763 }
2764 } 2764 }
2765 while (locate() >= target && delta < 4096); 2765 while (locate() >= target && delta < 4096);
2766#ifdef WS 2766#ifdef WS
2767 //printf("Delta:%u\n",delta); 2767 //printf("Delta:%u\n",delta);
2768#endif 2768#endif
2769 } 2769 }
2770 else 2770 else
2771 { 2771 {
2772 jumpto(0); 2772 jumpto(0);
2773 for (int i = 0; i < numlines; i++) 2773 for (int i = 0; i < numlines; i++)
2774 { 2774 {
2775 loc[i] = locate(); 2775 loc[i] = locate();
2776 buffdoc.getline(buff[i],width()); 2776 buffdoc.getline(buff[i],width());
2777 } 2777 }
2778 } 2778 }
2779 cbptr = 0; 2779 cbptr = 0;
2780 while (locate() < target) 2780 while (locate() < target)
2781 { 2781 {
2782 loc[cbptr] = locate(); 2782 loc[cbptr] = locate();
2783 buffdoc.getline(buff[cbptr], width()); 2783 buffdoc.getline(buff[cbptr], width());
2784#ifdef WS 2784#ifdef WS
2785 //printf("Adding:%s\n",buff[cbptr]->data()); 2785 //printf("Adding:%s\n",buff[cbptr]->data());
2786#endif 2786#endif
2787 cbptr = (cbptr+1) % numlines; 2787 cbptr = (cbptr+1) % numlines;
2788 } 2788 }
2789 pagepos = loc[cbptr]; 2789 pagepos = loc[cbptr];
2790 textarray = new CBuffer*[numlines]; 2790 textarray = new CBuffer*[numlines];
2791 for (int i = 0; i < numlines; i++) 2791 for (int i = 0; i < numlines; i++)
2792 { 2792 {
2793 int j = (cbptr+i)%numlines; 2793 int j = (cbptr+i)%numlines;
2794 textarray[i] = buff[j]; 2794 textarray[i] = buff[j];
2795 locnarray[i] = loc[j]; 2795 locnarray[i] = loc[j];
2796 } 2796 }
2797 delete [] buff; 2797 delete [] buff;
2798 delete [] loc; 2798 delete [] loc;
2799 mylastpos = locate(); 2799 mylastpos = locate();
2800 update(); 2800 update();
2801} 2801}
2802*/ 2802*/
2803 2803
2804void QTReader::ResetScroll() 2804void QTReader::ResetScroll()
2805{ 2805{
2806 m_totalscroll = 0; 2806 m_totalscroll = 0;
2807 m_scrolldy1 = 0; 2807 m_scrolldy1 = 0;
2808 m_scrolldy = m_topmargin; 2808 m_scrolldy = m_topmargin;
2809 if (m_autoScroll && ((m_scrolltype == 0) || !m_bgpm.isNull())) 2809 if (m_autoScroll && ((m_scrolltype == 0) || !m_bgpm.isNull()))
2810 { 2810 {
2811 setautoscroll(false); 2811 setautoscroll(false);
2812 } 2812 }
2813} 2813}
2814 2814
2815void QTReader::lineUp() 2815void QTReader::lineUp()
2816{ 2816{
2817 dopageup(locnarray[numlines-1]); 2817 dopageup(locnarray[numlines-1]);
2818 2818
2819 /* 2819 /*
2820 buffdoc.unsuspend(); 2820 buffdoc.unsuspend();
2821 ResetScroll(); 2821 ResetScroll();
2822 2822
2823 CDrawBuffer* buff = textarray[numlines]; 2823 CDrawBuffer* buff = textarray[numlines];
2824 unsigned int loc; 2824 unsigned int loc;
2825 unsigned int end = locnarray[numlines]; 2825 unsigned int end = locnarray[numlines];
2826 int cbptr = 0; 2826 int cbptr = 0;
2827 if (locate() != mylastpos) jumpto(mylastpos); 2827 if (locate() != mylastpos) jumpto(mylastpos);
2828 unsigned int target = locnarray[0]; 2828 unsigned int target = locnarray[0];
2829 if (target == 0) return; 2829 if (target == 0) return;
2830 if (!m_continuousDocument && (target == buffdoc.startSection())) return; 2830 if (!m_continuousDocument && (target == buffdoc.startSection())) return;
2831 if (buffdoc.hasrandomaccess()) 2831 if (buffdoc.hasrandomaccess())
2832 { 2832 {
2833 unsigned int delta = locate()-pagelocate(); 2833 unsigned int delta = locate()-pagelocate();
2834 if (delta < 64) delta = 64; 2834 if (delta < 64) delta = 64;
2835 do 2835 do
2836 { 2836 {
2837 delta <<= 1; 2837 delta <<= 1;
2838 if (delta >= target) 2838 if (delta >= target)
2839 { 2839 {
2840 delta = target; 2840 delta = target;
2841 jumpto(0); 2841 jumpto(0);
2842 loc = locate(); 2842 loc = locate();
2843 getline(buff); 2843 getline(buff);
2844 break; 2844 break;
2845 } 2845 }
2846 else if (!m_continuousDocument && (target - delta < buffdoc.startSection())) 2846 else if (!m_continuousDocument && (target - delta < buffdoc.startSection()))
2847 { 2847 {
2848 delta = target-buffdoc.startSection(); 2848 delta = target-buffdoc.startSection();
2849 jumpto(buffdoc.startSection()); 2849 jumpto(buffdoc.startSection());
2850 loc = locate(); 2850 loc = locate();
2851 getline(buff); 2851 getline(buff);
2852 break; 2852 break;
2853 } 2853 }
2854 jumpto(target-delta); 2854 jumpto(target-delta);
2855 do 2855 do
2856 { 2856 {
2857 getline(buff); 2857 getline(buff);
2858#ifdef WS 2858#ifdef WS
2859 //printf("Trying:%s\n",buff[0]); 2859 //printf("Trying:%s\n",buff[0]);
2860#endif 2860#endif
2861 if (locate() > target) continue; 2861 if (locate() > target) continue;
2862 } 2862 }
2863 while (!buffdoc.iseol()); 2863 while (!buffdoc.iseol());
2864 loc = locate(); 2864 loc = locate();
2865 getline(buff); 2865 getline(buff);
2866 } 2866 }
2867 while (locate() >= target && delta < 4096); 2867 while (locate() >= target && delta < 4096);
2868 } 2868 }
2869 else 2869 else
2870 { 2870 {
2871 jumpto(0); 2871 jumpto(0);
2872 loc = locate(); 2872 loc = locate();
2873 getline(buff); 2873 getline(buff);
2874 } 2874 }
2875 cbptr = 0; 2875 cbptr = 0;
2876 while (locate() < target) 2876 while (locate() < target)
2877 { 2877 {
2878 loc = locate(); 2878 loc = locate();
2879 getline(buff); 2879 getline(buff);
2880 } 2880 }
2881 for (int i = numlines; i > 0; i--) 2881 for (int i = numlines; i > 0; i--)
2882 { 2882 {
2883 textarray[i] = textarray[i-1]; 2883 textarray[i] = textarray[i-1];
2884 locnarray[i] = locnarray[i-1]; 2884 locnarray[i] = locnarray[i-1];
2885 } 2885 }
2886 textarray[0] = buff; 2886 textarray[0] = buff;
2887 locnarray[0] = loc; 2887 locnarray[0] = loc;
2888 int start = numlines; 2888 int start = numlines;
2889 int ypos = m_topmargin; 2889 int ypos = m_topmargin;
2890#ifdef _WINDOWS 2890#ifdef _WINDOWS
2891 for (i = 0; i <= numlines; i++) 2891 for (i = 0; i <= numlines; i++)
2892#else 2892#else
2893 for (int i = 0; i <= numlines; i++) 2893 for (int i = 0; i <= numlines; i++)
2894#endif 2894#endif
2895 { 2895 {
2896 ypos += textarray[i]->lineSpacing(); 2896 ypos += textarray[i]->lineSpacing();
2897 if (ypos > ((m_rotated) ? width() : height())) 2897 if (ypos > ((m_rotated) ? width() : height()))
2898 { 2898 {
2899 start = i; 2899 start = i;
2900 ypos -= textarray[i]->lineSpacing(); 2900 ypos -= textarray[i]->lineSpacing();
2901 break; 2901 break;
2902 } 2902 }
2903 } 2903 }
2904 jumpto(locnarray[start]); 2904 jumpto(locnarray[start]);
2905 fillbuffer(start, ypos); 2905 fillbuffer(start, ypos);
2906 repaint(); 2906 repaint();
2907 */ 2907 */
2908} 2908}
2909 2909
2910bool QTReader::empty() 2910bool QTReader::empty()
2911{ 2911{
2912 return buffdoc.empty(); 2912 return buffdoc.empty();
2913} 2913}
2914 2914
2915MarkupType QTReader::PreferredMarkup() 2915MarkupType QTReader::PreferredMarkup()
2916{ 2916{
2917 MarkupType m = buffdoc.PreferredMarkup(); 2917 MarkupType m = buffdoc.PreferredMarkup();
2918 if (m == cTEXT) 2918 if (m == cTEXT)
2919 { 2919 {
2920 int ext = m_lastfile.findRev('.'); 2920 int ext = m_lastfile.findRev('.');
2921 if (ext >= 0) 2921 if (ext >= 0)
2922 { 2922 {
2923 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper(); 2923 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper();
2924 if (ft.left(3) == "HTM") 2924 if (ft.left(3) == "HTM")
2925 { 2925 {
2926 m = cHTML; 2926 m = cHTML;
2927 } 2927 }
2928 } 2928 }
2929 } 2929 }
2930 return m; 2930 return m;
2931} 2931}
2932 2932
2933void QTReader::resizeEvent( QResizeEvent * p ) 2933void QTReader::resizeEvent( QResizeEvent * p )
2934{ 2934{
2935 qDebug("Resizing"); 2935 qDebug("Resizing");
2936 m_outofdate = true; 2936 m_outofdate = true;
2937 if (dbuff != NULL) 2937 if (dbuff != NULL)
2938 { 2938 {
2939 if (m_rotated) 2939 if (m_rotated)
2940 { 2940 {
2941 dbuff->resize(p->size().height(),p->size().width()); 2941 dbuff->resize(p->size().height(),p->size().width());
2942 } 2942 }
2943 else 2943 else
2944 { 2944 {
2945 dbuff->resize(p->size()); 2945 dbuff->resize(p->size());
2946 } 2946 }
2947 } 2947 }
2948 m_bgIsScaled = false; 2948 m_bgIsScaled = false;
2949 if (m_bgtype == bgStretched) 2949 if (m_bgtype == bgStretched)
2950 { 2950 {
2951 emit RefreshBitmap(); 2951 emit RefreshBitmap();
2952 } 2952 }
2953 2953
2954 { 2954 {
2955 int h, w; 2955 int h, w;
2956 if (m_rotated) 2956 if (m_rotated)
2957 { 2957 {
2958 h = p->size().width(); 2958 h = p->size().width();
2959 w = p->size().height(); 2959 w = p->size().height();
2960 } 2960 }
2961 else 2961 else
2962 { 2962 {
2963 w = p->size().width(); 2963 w = p->size().width();
2964 h = p->size().height(); 2964 h = p->size().height();
2965 } 2965 }
2966 m_topmargin = (h*m_abstopmargin+500)/1000; 2966 m_topmargin = (h*m_abstopmargin+500)/1000;
2967 m_bottommargin = (h*m_absbottommargin+500)/1000; 2967 m_bottommargin = (h*m_absbottommargin+500)/1000;
2968 m_left_border = (w*m_absleft_border+500)/1000; 2968 m_left_border = (w*m_absleft_border+500)/1000;
2969 m_right_border = (w*m_absright_border+500)/1000; 2969 m_right_border = (w*m_absright_border+500)/1000;
2970 } 2970 }
2971 if (dbuff != NULL && buffdoc.empty()) 2971 if (dbuff != NULL && buffdoc.empty())
2972 { 2972 {
2973 dbp->begin(dbuff); 2973 dbp->begin(dbuff);
2974 drawBackground(dbp); 2974 drawBackground(dbp);
2975 dbp->end(); 2975 dbp->end();
2976 } 2976 }
2977} 2977}
2978 2978
2979void QTReader::setrotated(bool sfs) 2979void QTReader::setrotated(bool sfs)
2980{ 2980{
2981 qDebug("Rotating"); 2981 qDebug("Rotating");
2982 m_rotated = sfs; 2982 m_rotated = sfs;
2983 setDoubleBuffer(m_doubleBuffered); 2983 setDoubleBuffer(m_doubleBuffered);
2984 m_bgIsScaled = false; 2984 m_bgIsScaled = false;
2985 m_outofdate = true; 2985 m_outofdate = true;
2986 /* 2986 /*
2987 int h, w; 2987 int h, w;
2988 if (m_rotated) 2988 if (m_rotated)
2989 { 2989 {
2990 h = width(); 2990 h = width();
2991 w = height(); 2991 w = height();
2992 } 2992 }
2993 else 2993 else
2994 { 2994 {
2995 w = width(); 2995 w = width();
2996 h = height(); 2996 h = height();
2997 } 2997 }
2998 m_topmargin = (h*m_abstopmargin+500)/1000; 2998 m_topmargin = (h*m_abstopmargin+500)/1000;
2999 m_bottommargin = (h*m_absbottommargin+500)/1000; 2999 m_bottommargin = (h*m_absbottommargin+500)/1000;
3000 m_left_border = (w*m_absleft_border+500)/1000; 3000 m_left_border = (w*m_absleft_border+500)/1000;
3001 m_right_border = (w*m_absright_border+500)/1000; 3001 m_right_border = (w*m_absright_border+500)/1000;
3002 3002
3003 qDebug("Top margin:%u", m_topmargin ); 3003 qDebug("Top margin:%u", m_topmargin );
3004 qDebug("Bottom margin:%u", m_bottommargin ); 3004 qDebug("Bottom margin:%u", m_bottommargin );
3005 qDebug("Left margin:%u", m_left_border ); 3005 qDebug("Left margin:%u", m_left_border );
3006 qDebug("Right margin:%u", m_right_border ); 3006 qDebug("Right margin:%u", m_right_border );
3007 */ 3007 */
3008} 3008}
3009 3009
3010void QTReader::drawBackground(QPainter *p) 3010void QTReader::drawBackground(QPainter *p)
3011{ 3011{
3012 // p->setBackgroundMode(OpaqueMode); 3012 // p->setBackgroundMode(OpaqueMode);
3013 p->setBackgroundColor(m_bg); 3013 p->setBackgroundColor(m_bg);
3014 if (dbuff != NULL) 3014 if (dbuff != NULL)
3015 { 3015 {
3016 p->eraseRect(dbuff->rect()); 3016 p->eraseRect(dbuff->rect());
3017 } 3017 }
3018 else 3018 else
3019 { 3019 {
3020 if (m_rotated) 3020 if (m_rotated)
3021 { 3021 {
3022 p->eraseRect(0,0,height(),width()); 3022 p->eraseRect(0,0,height(),width());
3023 } 3023 }
3024 else 3024 else
3025 { 3025 {
3026 p->eraseRect(rect()); 3026 p->eraseRect(rect());
3027 } 3027 }
3028 } 3028 }
3029 if (!m_bgpm.isNull()) 3029 if (!m_bgpm.isNull())
3030 { 3030 {
3031 // p->setBackgroundMode(TransparentMode); 3031 // p->setBackgroundMode(TransparentMode);
3032 switch (m_bgtype) 3032 switch (m_bgtype)
3033 { 3033 {
3034 case bgCentred: 3034 case bgCentred:
3035 { 3035 {
3036 if (dbuff == NULL) 3036 if (dbuff == NULL)
3037 { 3037 {
3038 p->drawPixmap(width(),height(),m_bgpm); 3038 p->drawPixmap(width(),height(),m_bgpm);
3039 } 3039 }
3040 else 3040 else
3041 { 3041 {
3042 int w = (dbuff->rect().width()-m_bgpm.width())/2; 3042 int w = (dbuff->rect().width()-m_bgpm.width())/2;
3043 int h = (dbuff->rect().height()-m_bgpm.height())/2; 3043 int h = (dbuff->rect().height()-m_bgpm.height())/2;
3044 p->drawPixmap(w,h,m_bgpm); 3044 p->drawPixmap(w,h,m_bgpm);
3045 } 3045 }
3046 } 3046 }
3047 break; 3047 break;
3048 case bgTiled: 3048 case bgTiled:
3049 { 3049 {
3050 if (dbuff == NULL) 3050 if (dbuff == NULL)
3051 { 3051 {
3052 p->drawTiledPixmap(0,0,width(),height(),m_bgpm); 3052 p->drawTiledPixmap(0,0,width(),height(),m_bgpm);
3053 } 3053 }
3054 else 3054 else
3055 { 3055 {
3056 p->drawTiledPixmap(0,0,dbuff->rect().width(),dbuff->rect().height(),m_bgpm); 3056 p->drawTiledPixmap(0,0,dbuff->rect().width(),dbuff->rect().height(),m_bgpm);
3057 } 3057 }
3058 } 3058 }
3059 break; 3059 break;
3060 case bgStretched: 3060 case bgStretched:
3061 { 3061 {
3062 if (!m_bgIsScaled) 3062 if (!m_bgIsScaled)
3063 { 3063 {
3064 m_bgIsScaled = true; 3064 m_bgIsScaled = true;
3065 QImage im = m_bgpm.convertToImage(); 3065 QImage im = m_bgpm.convertToImage();
3066 if (dbuff == NULL) 3066 if (dbuff == NULL)
3067 { 3067 {
3068 m_bgpm.convertFromImage(im.smoothScale(width(),height())); 3068 m_bgpm.convertFromImage(im.smoothScale(width(),height()));
3069 } 3069 }
3070 else 3070 else
3071 { 3071 {
3072 m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height())); 3072 m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height()));
3073 } 3073 }
3074 } 3074 }
3075 p->drawPixmap(0,0,m_bgpm); 3075 p->drawPixmap(0,0,m_bgpm);
3076 } 3076 }
3077 break; 3077 break;
3078 default: 3078 default:
3079 qDebug("Unknown background type"); 3079 qDebug("Unknown background type");
3080 } 3080 }
3081 // p->setBackgroundMode(OpaqueMode); 3081 // p->setBackgroundMode(OpaqueMode);
3082 } 3082 }
3083} 3083}
3084 3084
3085void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt) 3085void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt)
3086{ 3086{
3087 if (txt != NULL) 3087 if (txt != NULL)
3088 { 3088 {
3089 sh = txt->lineSpacing(); 3089 sh = txt->lineSpacing();
3090 } 3090 }
3091 int sy = width()-dx-sh; 3091 int sy = width()-dx-sh;
3092 if (m_autoScroll && !(m_scrolltype == 0)) 3092 if (m_autoScroll && !(m_scrolltype == 0))
3093 { 3093 {
3094 sy = (sy+m_totalscroll+1)%width(); 3094 sy = (sy+m_totalscroll+1)%width();
3095 } 3095 }
3096 3096
3097 QPixmap pm(sw, sh); 3097 QPixmap pm(sw, sh);
3098 3098
3099 QPainter pd(&pm, this); 3099 QPainter pd(&pm, this);
3100 if (m_bgpm.isNull()) 3100 if (m_bgpm.isNull())
3101 { 3101 {
3102 pd.eraseRect(pm.rect()); 3102 pd.eraseRect(pm.rect());
3103 } 3103 }
3104 else 3104 else
3105 { 3105 {
3106 if (sy+pm.height() > dbuff->height()) 3106 if (sy+pm.height() > dbuff->height())
3107 { 3107 {
3108 // pd.eraseRect(pm.rect()); 3108 // pd.eraseRect(pm.rect());
3109 int fh = dbuff->height() - sy; 3109 int fh = dbuff->height() - sy;
3110 if (sy+fh > dbuff->height()) 3110 if (sy+fh > dbuff->height())
3111 { 3111 {
3112 qDebug("Oh no!"); 3112 qDebug("Oh no!");
3113 } 3113 }
3114 3114
3115 if (fh > pm.height()) 3115 if (fh > pm.height())
3116 { 3116 {
3117 qDebug("Oh no! - 2"); 3117 qDebug("Oh no! - 2");
3118 } 3118 }
3119 3119
3120 bitBlt(&pm,0,0,dbuff,dy,sy,pm.width(),fh); 3120 bitBlt(&pm,0,0,dbuff,dy,sy,pm.width(),fh);
3121 bitBlt(&pm,0,fh,dbuff,dy,0,pm.width(),pm.height()-fh); 3121 bitBlt(&pm,0,fh,dbuff,dy,0,pm.width(),pm.height()-fh);
3122 } 3122 }
3123 else 3123 else
3124 { 3124 {
3125 bitBlt(&pm,0,0,dbuff,dy,sy,pm.width(),pm.height()); 3125 bitBlt(&pm,0,0,dbuff,dy,sy,pm.width(),pm.height());
3126 } 3126 }
3127 } 3127 }
3128 if (txt != NULL) 3128 if (txt != NULL)
3129 { 3129 {
3130 // txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg); 3130 // txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg);
3131 txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg, width()-m_topmargin-m_bottommargin); 3131 txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg, width()-m_topmargin-m_bottommargin);
3132 } 3132 }
3133 QWMatrix m; 3133 QWMatrix m;
3134 m.rotate(90); 3134 m.rotate(90);
3135 QPixmap rp = pm.xForm(m); 3135 QPixmap rp = pm.xForm(m);
3136 /* 3136 /*
3137 p.drawPixmap(QPoint(dx, dy), rp); 3137 p.drawPixmap(QPoint(dx, dy), rp);
3138 */ 3138 */
3139 bitBlt(this, dx, dy, &rp, 0, 0, -1, -1, CopyROP); 3139 bitBlt(this, dx, dy, &rp, 0, 0, -1, -1, CopyROP);
3140} 3140}
3141 3141
3142QString QTReader::about() 3142QString QTReader::about()
3143{ 3143{
3144 QString ab = QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka"; 3144 QString ab = QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka";
3145 if (m_output != NULL) 3145 if (m_output != NULL)
3146 { 3146 {
3147 ab += QString("\n") + m_output->about(); 3147 ab += QString("\n") + m_output->about();
3148 } 3148 }
3149 return ab; 3149 return ab;
3150} 3150}
3151 3151
3152void QTReader::getNextLink() 3152void QTReader::getNextLink()
3153{ 3153{
3154 if (m_scrolldy != 0) 3154 if (m_scrolldy != 0)
3155 { 3155 {
3156 setautoscroll(false); 3156 setautoscroll(false);
3157 ResetScroll(); 3157 ResetScroll();
3158 redrawall(); 3158 redrawall();
3159 } 3159 }
3160 bool redraw = false; 3160 bool redraw = false;
3161 bool found = false; 3161 bool found = false;
3162 if (m_currentlink >= 0) 3162 if (m_currentlink >= 0)
3163 { 3163 {
3164 m_currentlinkoffset = textarray[m_currentlink]->invertLink(m_currentlinkoffset); 3164 m_currentlinkoffset = textarray[m_currentlink]->invertLink(m_currentlinkoffset);
3165 if ((m_currentlinkstyle = textarray[m_currentlink]->getNextLink(m_currentlinkoffset)) != NULL) 3165 if ((m_currentlinkstyle = textarray[m_currentlink]->getNextLink(m_currentlinkoffset)) != NULL)
3166 { 3166 {
3167 qDebug("Found a link at %u", m_currentlinkoffset); 3167 qDebug("Found a link at %u", m_currentlinkoffset);
3168 int offset = textarray[m_currentlink]->invertLink(m_currentlinkoffset); 3168 int offset = textarray[m_currentlink]->invertLink(m_currentlinkoffset);
3169 qDebug("Finishes at %u", offset); 3169 qDebug("Finishes at %u", offset);
3170 found = true; 3170 found = true;
3171 } 3171 }
3172 redraw = true; 3172 redraw = true;
3173 drawSingleLine(m_currentlink); 3173 drawSingleLine(m_currentlink);
3174 // if (found) return; 3174 // if (found) return;
3175 } 3175 }
3176 if (!found) 3176 if (!found)
3177 { 3177 {
3178 m_currentlinkoffset = -1; 3178 m_currentlinkoffset = -1;
3179 for (int i = m_currentlink+1; i < numlines; ++i) 3179 for (int i = m_currentlink+1; i < numlines; ++i)
3180 { 3180 {
3181 if ((m_currentlinkstyle = textarray[i]->getNextLink(m_currentlinkoffset)) != NULL) 3181 if ((m_currentlinkstyle = textarray[i]->getNextLink(m_currentlinkoffset)) != NULL)
3182 { 3182 {
3183 m_currentlink = i; 3183 m_currentlink = i;
3184 qDebug("Found a link at %u", m_currentlinkoffset); 3184 qDebug("Found a link at %u", m_currentlinkoffset);
3185 int offset = textarray[m_currentlink]->invertLink(m_currentlinkoffset); 3185 int offset = textarray[m_currentlink]->invertLink(m_currentlinkoffset);
3186 qDebug("Finishes at %u", offset); 3186 qDebug("Finishes at %u", offset);
3187 //drawSingleLine(i); 3187 //drawSingleLine(i);
3188 redraw = true; 3188 redraw = true;
3189 found = true; 3189 found = true;
3190 drawSingleLine(m_currentlink); 3190 drawSingleLine(m_currentlink);
3191 break; 3191 break;
3192 } 3192 }
3193 } 3193 }
3194 } 3194 }
3195 if (redraw) 3195 if (redraw)
3196 { 3196 {
3197 // redrawall(); 3197 // redrawall();
3198 } 3198 }
3199 if (!found) 3199 if (!found)
3200 { 3200 {
3201 m_currentlink = -1; 3201 m_currentlink = -1;
3202 m_currentlinkstyle = NULL; 3202 m_currentlinkstyle = NULL;
3203 m_currentlinkoffset = -1; 3203 m_currentlinkoffset = -1;
3204 dopagedn(); 3204 dopagedn();
3205 } 3205 }
3206} 3206}
3207 3207
3208void QTReader::emitRedraw() 3208void QTReader::emitRedraw()
3209{ 3209{
3210 m_currentlinkstyle = NULL; 3210 m_currentlinkstyle = NULL;
3211 m_currentlink = -1; 3211 m_currentlink = -1;
3212 m_currentlinkoffset = -1; 3212 m_currentlinkoffset = -1;
3213 emit OnRedraw(); 3213 emit OnRedraw();
3214}; 3214};
3215 3215
3216void QTReader::drawSingleLine(int lineno) 3216void QTReader::drawSingleLine(int lineno)
3217{ 3217{
3218 QPainter p( this ); 3218 QPainter p( this );
3219 int ypos = textarray[0]->ascent()+m_topmargin; 3219 int ypos = textarray[0]->ascent()+m_topmargin;
3220 if (lineno == 0) 3220 if (lineno == 0)
3221 { 3221 {
3222 if (m_rotated) 3222 if (m_rotated)
3223 { 3223 {
3224 blitRot(width()-(ypos+textarray[lineno]->descent()+textarray[lineno]->lineExtraSpacing()), 0, height(), -1, textarray[lineno]); 3224 blitRot(width()-(ypos+textarray[lineno]->descent()+textarray[lineno]->lineExtraSpacing()), 0, height(), -1, textarray[lineno]);
3225 } 3225 }
3226 else 3226 else
3227 { 3227 {
3228 if (m_bgpm.isNull()) 3228 if (m_bgpm.isNull())
3229 { 3229 {
3230 p.fillRect(m_left_border,ypos-textarray[lineno]->ascent(),width()-(m_left_border+m_right_border),textarray[lineno]->lineSpacing(),m_bg); 3230 p.fillRect(m_left_border,ypos-textarray[lineno]->ascent(),width()-(m_left_border+m_right_border),textarray[lineno]->lineSpacing(),m_bg);
3231 } 3231 }
3232 else 3232 else
3233 { 3233 {
3234 bitBlt(this, m_left_border, ypos-textarray[lineno]->ascent(), dbuff, m_left_border, ypos-textarray[lineno]->ascent(), width()-(m_left_border+m_right_border), textarray[lineno]->lineSpacing()); 3234 bitBlt(this, m_left_border, ypos-textarray[lineno]->ascent(), dbuff, m_left_border, ypos-textarray[lineno]->ascent(), width()-(m_left_border+m_right_border), textarray[lineno]->lineSpacing());
3235 } 3235 }
3236 textarray[lineno]->render( &p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); 3236 textarray[lineno]->render( &p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
3237 } 3237 }
3238 } 3238 }
3239 for (int i = 1; i < numlines; i++) 3239 for (int i = 1; i < numlines; i++)
3240 { 3240 {
3241 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+ 3241 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
3242 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; 3242 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
3243 if (i == lineno) 3243 if (i == lineno)
3244 { 3244 {
3245 if (m_rotated) 3245 if (m_rotated)
3246 { 3246 {
3247 blitRot(width()-(ypos+textarray[i]->descent()+textarray[i]->lineExtraSpacing()), 0, height(), -1, textarray[i]); 3247 blitRot(width()-(ypos+textarray[i]->descent()+textarray[i]->lineExtraSpacing()), 0, height(), -1, textarray[i]);
3248 } 3248 }
3249 else 3249 else
3250 { 3250 {
3251 if (m_bgpm.isNull()) 3251 if (m_bgpm.isNull())
3252 { 3252 {
3253 p.fillRect(m_left_border,ypos-textarray[lineno]->ascent(),width()-(m_left_border+m_right_border),textarray[lineno]->lineSpacing(),m_bg); 3253 p.fillRect(m_left_border,ypos-textarray[lineno]->ascent(),width()-(m_left_border+m_right_border),textarray[lineno]->lineSpacing(),m_bg);
3254 } 3254 }
3255 else 3255 else
3256 { 3256 {
3257 bitBlt(this, m_left_border, ypos-textarray[lineno]->ascent(), dbuff, m_left_border, ypos-textarray[lineno]->ascent(), width()-(m_left_border+m_right_border), textarray[lineno]->lineSpacing()); 3257 bitBlt(this, m_left_border, ypos-textarray[lineno]->ascent(), dbuff, m_left_border, ypos-textarray[lineno]->ascent(), width()-(m_left_border+m_right_border), textarray[lineno]->lineSpacing());
3258 } 3258 }
3259 textarray[i]->render( &p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); 3259 textarray[i]->render( &p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
3260 } 3260 }
3261 } 3261 }
3262 } 3262 }
3263} 3263}
3264 3264
3265 3265
3266void QTReader::gotoLink() 3266void QTReader::gotoLink()
3267{ 3267{
3268 if (m_currentlinkstyle == NULL) return; 3268 if (m_currentlinkstyle == NULL) return;
3269 textarray[m_currentlink]->invertLink(m_currentlinkoffset); 3269 textarray[m_currentlink]->invertLink(m_currentlinkoffset);
3270 size_t saveposn = pagelocate(); 3270 size_t saveposn = pagelocate();
3271 QString href, nm; 3271 QString href, nm;
3272 unsigned long tgt = m_currentlinkstyle->getData(); 3272 unsigned long tgt = m_currentlinkstyle->getData();
3273 unsigned long tgtoffset = m_currentlinkstyle->getOffset(); 3273 unsigned long tgtoffset = m_currentlinkstyle->getOffset();
3274 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm); 3274 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm);
3275 qDebug("URL(1):%s", (const char*)href); 3275 qDebug("URL(1):%s", (const char*)href);
3276 if ((lt & eFile) != 0) 3276 if ((lt & eFile) != 0)
3277 { 3277 {
3278 buffdoc.saveposn(m_lastfile, saveposn); 3278 buffdoc.saveposn(m_lastfile, saveposn);
3279#ifdef USEQPE 3279#ifdef USEQPE
3280 { 3280 {
3281 QCopEnvelope e("QPE/System", "busy()"); 3281 QCopEnvelope e("QPE/System", "busy()");
3282 } 3282 }
3283#endif 3283#endif
3284 ResetScroll(); 3284 ResetScroll();
3285 if (!href.isEmpty()) 3285 if (!href.isEmpty())
3286 { 3286 {
3287 if (!buffdoc.getFile(href, nm)) 3287 if (!buffdoc.getFile(href, nm))
3288 { 3288 {
3289 emit NewFileRequest(href); 3289 emit NewFileRequest(href);
3290 } 3290 }
3291 else 3291 else
3292 { 3292 {
3293 ResetScroll(); 3293 ResetScroll();
3294 fillbuffer(); 3294 fillbuffer();
3295 m_outofdate = true; 3295 m_outofdate = true;
3296 update(); 3296 update();
3297 } 3297 }
3298 } 3298 }
3299 if (!nm.isEmpty()) 3299 if (!nm.isEmpty())
3300 { 3300 {
3301 qDebug("QTReader:Finding %s", (const char*)nm); 3301 qDebug("QTReader:Finding %s", (const char*)nm);
3302 if (buffdoc.findanchor(nm)) 3302 if (buffdoc.findanchor(nm))
3303 { 3303 {
3304 buffdoc.resetPos(); 3304 buffdoc.resetPos();
3305 fillbuffer(); 3305 fillbuffer();
3306 m_outofdate = true; 3306 m_outofdate = true;
3307 update(); 3307 update();
3308 } 3308 }
3309 } 3309 }
3310 //fillbuffer(); 3310 //fillbuffer();
3311 //update(); 3311 //update();
3312#ifdef USEQPE 3312#ifdef USEQPE
3313 { 3313 {
3314 QCopEnvelope e("QPE/System", "notBusy()"); 3314 QCopEnvelope e("QPE/System", "notBusy()");
3315 } 3315 }
3316#endif 3316#endif
3317 } 3317 }
3318 else if ((lt & eLink) != 0) 3318 else if ((lt & eLink) != 0)
3319 { 3319 {
3320 buffdoc.saveposn(m_lastfile, saveposn); 3320 buffdoc.saveposn(m_lastfile, saveposn);
3321 ResetScroll(); 3321 ResetScroll();
3322 fillbuffer(); 3322 fillbuffer();
3323 m_outofdate = true; 3323 m_outofdate = true;
3324 update(); 3324 update();
3325 } 3325 }
3326 else 3326 else
3327 { 3327 {
3328 if ((lt & ePicture) != 0) 3328 if ((lt & ePicture) != 0)
3329 { 3329 {
3330 QImage* pm = buffdoc.getPicture(tgt); 3330 QImage* pm = buffdoc.getPicture(tgt);
3331 if (pm != NULL) 3331 if (pm != NULL)
3332 { 3332 {
3333 emit OnShowPicture(*pm); 3333 emit OnShowPicture(*pm);
3334 delete pm; 3334 delete pm;
3335 } 3335 }
3336 } 3336 }
3337 else 3337 else
3338 { 3338 {
3339 // QString anchortext = textarray[lineno]->getanchortext(startoffset); 3339 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
3340 if (!href.isEmpty()) 3340 if (!href.isEmpty())
3341 { 3341 {
3342 emit OnURLSelected(href, tgt); 3342 emit OnURLSelected(href, tgt);
3343 refresh(); 3343 refresh();
3344 } 3344 }
3345 } 3345 }
3346 } 3346 }
3347 m_currentlinkstyle = NULL; 3347 m_currentlinkstyle = NULL;
3348 m_currentlink = -1; 3348 m_currentlink = -1;
3349 m_currentlinkoffset = -1; 3349 m_currentlinkoffset = -1;
3350} 3350}
3351 3351
3352void QTReader::refresh(bool full) 3352void QTReader::refresh(bool full)
3353{ 3353{
3354 qDebug("Refreshing"); 3354 qDebug("Refreshing");
3355 int h, w; 3355 int h, w;
3356 if (m_rotated) 3356 if (m_rotated)
3357 { 3357 {
3358 h = width(); 3358 h = width();
3359 w = height(); 3359 w = height();
3360 } 3360 }
3361 else 3361 else
3362 { 3362 {
3363 w = width(); 3363 w = width();
3364 h = height(); 3364 h = height();
3365 } 3365 }
3366 m_topmargin = (h*m_abstopmargin+500)/1000; 3366 m_topmargin = (h*m_abstopmargin+500)/1000;
3367 m_bottommargin = (h*m_absbottommargin+500)/1000; 3367 m_bottommargin = (h*m_absbottommargin+500)/1000;
3368 m_left_border = (w*m_absleft_border+500)/1000; 3368 m_left_border = (w*m_absleft_border+500)/1000;
3369 m_right_border = (w*m_absright_border+500)/1000; 3369 m_right_border = (w*m_absright_border+500)/1000;
3370 3370
3371 qDebug("Top margin:%u", m_topmargin ); 3371 qDebug("Top margin:%u", m_topmargin );
3372 qDebug("Bottom margin:%u", m_bottommargin ); 3372 qDebug("Bottom margin:%u", m_bottommargin );
3373 qDebug("Left margin:%u", m_left_border ); 3373 qDebug("Left margin:%u", m_left_border );
3374 qDebug("Right margin:%u", m_right_border ); 3374 qDebug("Right margin:%u", m_right_border );
3375 if (full && m_highlightfilter) m_highlightfilter->refresh(pagelocate()); 3375 if (full && m_highlightfilter) m_highlightfilter->refresh(pagelocate());
3376 m_outofdate = true; 3376 m_outofdate = true;
3377 locate(pagelocate()); 3377 locate(pagelocate());
3378} 3378}
3379 3379
3380#include "striphtml.h" 3380#include "striphtml.h"
3381 3381
3382CFilterChain* QTReader::getfilter() 3382CFilterChain* QTReader::getfilter()
3383{ 3383{
3384 CFilterChain * filt = new CFilterChain(getencoding()); 3384 CFilterChain * filt = new CFilterChain(getencoding());
3385 if (bstripcr) filt->addfilter(new stripcr); 3385 if (bstripcr) filt->addfilter(new stripcr);
3386 3386
3387 if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt); 3387 if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt);
3388 if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter); 3388 if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter);
3389 // if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile)); 3389 // if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile));
3390 3390
3391#ifdef __STATIC 3391#ifdef __STATIC
3392 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile)); 3392 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile));
3393 if (bautofmt && (PreferredMarkup() == cCHM)) 3393 if (bautofmt && (PreferredMarkup() == cCHM))
3394 { 3394 {
3395 striphtml* f = new striphtml(m_lastfile); 3395 striphtml* f = new striphtml(m_lastfile);
3396 f->setchm(true); 3396 f->setchm(true);
3397 filt->addfilter(f); 3397 filt->addfilter(f);
3398 } 3398 }
3399#else 3399#else
3400 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new ExternFilter("HTMLfilter", m_lastfile)); 3400 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new ExternFilter("HTMLfilter", m_lastfile));
3401 if (bautofmt && (PreferredMarkup() == cCHM)) 3401 if (bautofmt && (PreferredMarkup() == cCHM))
3402 { 3402 {
3403 ExternFilter* f = new ExternFilter("HTMLfilter",m_lastfile); 3403 ExternFilter* f = new ExternFilter("HTMLfilter",m_lastfile);
3404 ((striphtml*)f->filter())->setchm(true); 3404 ((striphtml*)f->filter())->setchm(true);
3405 filt->addfilter(f); 3405 filt->addfilter(f);
3406 } 3406 }
3407#endif 3407#endif
3408 m_highlightfilter = new HighlightFilter(this); 3408 m_highlightfilter = new HighlightFilter(this);
3409 filt->addfilter(m_highlightfilter); 3409 filt->addfilter(m_highlightfilter);
3410 3410
3411 if (bdehyphen) filt->addfilter(new dehyphen); 3411 if (bdehyphen) filt->addfilter(new dehyphen);
3412 if (bunindent) filt->addfilter(new unindent); 3412 if (bunindent) filt->addfilter(new unindent);
3413 if (brepara) filt->addfilter(new repara(m_reparastring)); 3413 if (brepara) filt->addfilter(new repara(m_reparastring));
3414 if (bonespace) filt->addfilter(new OnePara); 3414 if (bonespace) filt->addfilter(new OnePara);
3415 if (bindenter) filt->addfilter(new indenter(bindenter)); 3415 if (bindenter) filt->addfilter(new indenter(bindenter));
3416 if (bdblspce) filt->addfilter(new dblspce); 3416 if (bdblspce) filt->addfilter(new dblspce);
3417 if (bdepluck) filt->addfilter(new DePluck(pluckernextpart)); 3417 if (bdepluck) filt->addfilter(new DePluck(pluckernextpart));
3418 if (bdejpluck) filt->addfilter(new DePluck(jplucknextpart)); 3418 if (bdejpluck) filt->addfilter(new DePluck(jplucknextpart));
3419 if (brepalm) filt->addfilter(new repalm); 3419 if (brepalm) filt->addfilter(new repalm);
3420 if (bunderlineLink) filt->addfilter(new underlineLink); 3420 if (bunderlineLink) filt->addfilter(new underlineLink);
3421 if (bkern) filt->addfilter(new kern); 3421 if (bkern) filt->addfilter(new kern);
3422 if (bremap) filt->addfilter(new remap); 3422 if (bremap) filt->addfilter(new remap);
3423 if (bmakebold) filt->addfilter(new embolden); 3423 if (bmakebold) filt->addfilter(new embolden);
3424 if (bfulljust) filt->addfilter(new FullJust); 3424 if (bfulljust) filt->addfilter(new FullJust);
3425 int r,g,b; 3425 int r,g,b;
3426 m_default_bg.rgb(&r, &g, &b); 3426 m_default_bg.rgb(&r, &g, &b);
3427 if (r != 255 || g != 255 || b != 255) 3427 if (r != 255 || g != 255 || b != 255)
3428 filt->addfilter(new setbg(r,g,b)); 3428 filt->addfilter(new setbg(r,g,b));
3429 m_default_fg.rgb(&r, &g, &b); 3429 m_default_fg.rgb(&r, &g, &b);
3430 if (r != 0 || g != 0 || b != 0) 3430 if (r != 0 || g != 0 || b != 0)
3431 filt->addfilter(new setfg(r,g,b)); 3431 filt->addfilter(new setfg(r,g,b));
3432 // if (bNegative) filt->addfilter(new makeNegative); 3432 // if (bNegative) filt->addfilter(new makeNegative);
3433 if (bInverse) filt->addfilter(new makeInverse); 3433 if (bInverse) filt->addfilter(new makeInverse);
3434 if (bNoInlineTables) filt->addfilter(new tableLink); 3434 if (bNoInlineTables) filt->addfilter(new tableLink);
3435 return filt; 3435 return filt;
3436} 3436}
3437 3437
3438void QTReader::readAloud() 3438void QTReader::readAloud()
3439{ 3439{
3440#ifdef __STATIC 3440#ifdef __STATIC
3441 return; 3441 return;
3442#else 3442#else
3443 CBuffer para; 3443 CBuffer para;
3444 jumpto(pagelocate()); 3444 jumpto(pagelocate());
3445 while (m_autoScroll && (buffdoc.getpara(para) != -1)) 3445 while (m_autoScroll && (buffdoc.getpara(para) != -1))
3446 { 3446 {
3447 if (para.length() > 0) 3447 if (para.length() > 0)
3448 { 3448 {
3449 unsigned long lastpos = buffdoc.explocate(); 3449 unsigned long lastpos = buffdoc.explocate();
3450 while (lastpos > mylastpos) 3450 while (lastpos > mylastpos)
3451 { 3451 {
3452 dopagedn(); 3452 dopagedn();
3453 qApp->processEvents(); 3453 qApp->processEvents();
3454 } 3454 }
3455 jumpto(lastpos); 3455 jumpto(lastpos);
3456 QString txt = toQString(para.data()); 3456 QString txt = toQString(para.data());
3457 3457
3458 doOutput(txt); 3458 doOutput(txt);
3459 } 3459 }
3460 qApp->processEvents(); 3460 qApp->processEvents();
3461 } 3461 }
3462#endif 3462#endif
3463} 3463}
3464 3464
3465bool QTReader::doOutput(const QString& wrd) 3465bool QTReader::doOutput(const QString& wrd)
3466{ 3466{
3467 if (m_output != NULL) 3467 if (m_output != NULL)
3468 { 3468 {
3469 m_output->output(wrd); 3469 m_output->output(wrd);
3470 return true; 3470 return true;
3471 } 3471 }
3472 else 3472 else
3473 { 3473 {
3474 return false; 3474 return false;
3475 } 3475 }
3476} 3476}
3477 3477
3478bool QTReader::checkoutput() 3478bool QTReader::checkoutput()
3479{ 3479{
3480 if (m_output == NULL) 3480 if (m_output == NULL)
3481 { 3481 {
3482 m_output = new outputcodec(m_outputName); 3482 m_output = new outputcodec(m_outputName);
3483 if (reinterpret_cast<outputcodec*>(m_output)->getStatus() != 0) 3483 if (reinterpret_cast<outputcodec*>(m_output)->getStatus() != 0)
3484 { 3484 {
3485 delete m_output; 3485 delete m_output;
3486 m_output = NULL; 3486 m_output = NULL;
3487 QMessageBox::warning(this, PROGNAME, QString("Couldn't find output codec\n")+m_outputName); 3487 QMessageBox::warning(this, PROGNAME, QString("Couldn't find output codec\n")+m_outputName);
3488 return false; 3488 return false;
3489 } 3489 }
3490 } 3490 }
3491 return true; 3491 return true;
3492} 3492}
diff --git a/noncore/apps/opie-reader/plucker_base.cpp b/noncore/apps/opie-reader/plucker_base.cpp
index 849edfc..302ac73 100644
--- a/noncore/apps/opie-reader/plucker_base.cpp
+++ b/noncore/apps/opie-reader/plucker_base.cpp
@@ -1,1531 +1,1531 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <string.h> 2#include <string.h>
3#include <qmessagebox.h> 3#include <qmessagebox.h>
4#include <qpixmap.h> 4#include <qpixmap.h>
5#ifdef USEQPE 5#ifdef USEQPE
6#include <qpe/qcopenvelope_qws.h> 6#include <qpe/qcopenvelope_qws.h>
7#endif /* USEQPE */ 7#endif /* USEQPE */
8#ifdef LOCALPICTURES 8#ifdef LOCALPICTURES
9#include <qscrollview.h> 9#include <qscrollview.h>
10#endif 10#endif
11#ifdef USEQPE 11#ifdef USEQPE
12#include <qpe/global.h> 12#include <qpe/global.h>
13#endif /* USEQPE */ 13#endif /* USEQPE */
14#include <qclipboard.h> 14#include <qclipboard.h>
15#ifndef USEQPE 15#ifndef USEQPE
16#include <qapplication.h> 16#include <qapplication.h>
17#else /* USEQPE */ 17#else /* USEQPE */
18#include <qpe/qpeapplication.h> 18#include <qpe/qpeapplication.h>
19#endif /* USEQPE */ 19#endif /* USEQPE */
20#include <qimage.h> 20#include <qimage.h>
21 21
22#include "plucker_base.h" 22#include "plucker_base.h"
23#include "Aportis.h" 23#include "Aportis.h"
24#include "hrule.h" 24#include "hrule.h"
25#include "decompress.h" 25#include "decompress.h"
26 26
27const UInt8 CPlucker_base::continuation_bit = 1; 27const UInt8 CPlucker_base::continuation_bit = 1;
28 28
29CPlucker_base::CPlucker_base() : 29CPlucker_base::CPlucker_base() :
30#ifdef LOCALPICTURES 30#ifdef LOCALPICTURES
31 m_viewer(NULL), 31 m_viewer(NULL),
32 m_picture(NULL), 32 m_picture(NULL),
33#endif 33#endif
34 expandedtextbuffer(NULL), 34 expandedtextbuffer(NULL),
35 compressedtextbuffer(NULL), 35 compressedtextbuffer(NULL),
36 bufferrec(-1), 36 bufferrec(-1),
37 m_offset(0) 37 m_offset(0)
38 //, urls(NULL) 38 //, urls(NULL)
39{ /*printf("constructing:%x\n",fin);*/ } 39{ /*printf("constructing:%x\n",fin);*/ }
40 40
41 41
42void CPlucker_base::Expand(UInt32 reclen, UInt8 type, UInt8* buffer, UInt32 buffersize) 42void CPlucker_base::Expand(UInt32 reclen, UInt8 type, UInt8* buffer, UInt32 buffersize)
43{ 43{
44unsuspend(); 44unsuspend();
45 if ((type%2 == 0) && (type != 14)) 45 if ((type%2 == 0) && (type != 14))
46 { 46 {
47 size_t bytes_read = fread(buffer, reclen, sizeof(char), fin); 47 size_t bytes_read = fread(buffer, reclen, sizeof(char), fin);
48 buffer[bytes_read] = '\0'; 48 buffer[bytes_read] = '\0';
49 } 49 }
50 else 50 else
51 { 51 {
52 UInt8* readbuffer = NULL; 52 UInt8* readbuffer = NULL;
53 if (reclen > compressedbuffersize) 53 if (reclen > compressedbuffersize)
54 { 54 {
55 readbuffer = new UInt8[reclen]; 55 readbuffer = new UInt8[reclen];
56 } 56 }
57 else 57 else
58 { 58 {
59 readbuffer = compressedtextbuffer; 59 readbuffer = compressedtextbuffer;
60 } 60 }
61 if (readbuffer != NULL) 61 if (readbuffer != NULL)
62 { 62 {
63 fread(readbuffer, reclen, sizeof(char), fin); 63 fread(readbuffer, reclen, sizeof(char), fin);
64 size_t bytes_read = (*m_decompress)(readbuffer, reclen, buffer, buffersize); 64 size_t bytes_read = (*m_decompress)(readbuffer, reclen, buffer, buffersize);
65 buffer[bytes_read] = '\0'; 65 buffer[bytes_read] = '\0';
66 if (reclen > compressedbuffersize) 66 if (reclen > compressedbuffersize)
67 { 67 {
68 delete [] readbuffer; 68 delete [] readbuffer;
69 } 69 }
70 } 70 }
71 } 71 }
72} 72}
73 73
74void CPlucker_base::sizes(unsigned long& _file, unsigned long& _text) 74void CPlucker_base::sizes(unsigned long& _file, unsigned long& _text)
75{ 75{
76 _file = file_length; 76 _file = file_length;
77 if (textlength == 0) 77 if (textlength == 0)
78 { 78 {
79 for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) 79 for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++)
80 { 80 {
81 gotorecordnumber(recptr); 81 gotorecordnumber(recptr);
82 UInt16 thishdr_uid, thishdr_nParagraphs; 82 UInt16 thishdr_uid, thishdr_nParagraphs;
83 UInt32 thishdr_size; 83 UInt32 thishdr_size;
84 UInt8 thishdr_type, thishdr_reserved; 84 UInt8 thishdr_type, thishdr_reserved;
85 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 85 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
86 if (thishdr_type < 2) textlength += thishdr_size; 86 if (thishdr_type < 2) textlength += thishdr_size;
87 } 87 }
88 } 88 }
89 _text = textlength; 89 _text = textlength;
90 //ntohl(hdr0.size); 90 //ntohl(hdr0.size);
91} 91}
92 92
93char* CPlucker_base::geturl(UInt16 tgt) 93char* CPlucker_base::geturl(UInt16 tgt)
94{ 94{
95 char * pRet = NULL; 95 char * pRet = NULL;
96 gotorecordnumber(0); 96 gotorecordnumber(0);
97 fread(&hdr0, 1, 6, fin); 97 fread(&hdr0, 1, 6, fin);
98 unsigned int nrecs = ntohs(hdr0.nRecords); 98 unsigned int nrecs = ntohs(hdr0.nRecords);
99 //qDebug("Version %u, no. recs %u", ntohs(hdr0.version), nrecs); 99 //qDebug("Version %u, no. recs %u", ntohs(hdr0.version), nrecs);
100 UInt16 urlid = 0; 100 UInt16 urlid = 0;
101 bool urlsfound = false; 101 bool urlsfound = false;
102 char* urls = NULL; 102 char* urls = NULL;
103 size_t urlsize = 0; 103 size_t urlsize = 0;
104 for (unsigned int i = 0; i < nrecs; i++) 104 for (unsigned int i = 0; i < nrecs; i++)
105 { 105 {
106 UInt16 id, name; 106 UInt16 id, name;
107 fread(&name, 1, sizeof(name), fin); 107 fread(&name, 1, sizeof(name), fin);
108 fread(&id, 1, sizeof(id), fin); 108 fread(&id, 1, sizeof(id), fin);
109 //qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); 109 //qDebug("N:%d, I:%d", ntohs(name), ntohs(id));
110 if (ntohs(name) == 2) 110 if (ntohs(name) == 2)
111 { 111 {
112 urlsfound = true; 112 urlsfound = true;
113 urlid = id; 113 urlid = id;
114 //qDebug("Found url index:%d", ntohs(urlid)); 114 //qDebug("Found url index:%d", ntohs(urlid));
115 } 115 }
116 ////qDebug("%x", id); 116 ////qDebug("%x", id);
117 } 117 }
118 if (urlsfound) 118 if (urlsfound)
119 { 119 {
120 unsigned short recptr = finduid(ntohs(urlid)); 120 unsigned short recptr = finduid(ntohs(urlid));
121 if (recptr != 0) 121 if (recptr != 0)
122 { 122 {
123 gotorecordnumber(recptr); 123 gotorecordnumber(recptr);
124 UInt16 thishdr_uid, thishdr_nParagraphs; 124 UInt16 thishdr_uid, thishdr_nParagraphs;
125 UInt32 thishdr_size; 125 UInt32 thishdr_size;
126 UInt8 thishdr_type, thishdr_reserved; 126 UInt8 thishdr_type, thishdr_reserved;
127 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 127 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
128 UInt16 urlctr = 0; 128 UInt16 urlctr = 0;
129 while (1) 129 while (1)
130 { 130 {
131 UInt16 tctr; 131 UInt16 tctr;
132 fread(&tctr, 1, sizeof(tctr), fin); 132 fread(&tctr, 1, sizeof(tctr), fin);
133 fread(&urlid, 1, sizeof(urlid), fin); 133 fread(&urlid, 1, sizeof(urlid), fin);
134 tctr = ntohs(tctr); 134 tctr = ntohs(tctr);
135 //qDebug("tgt:%u urlctr:%u tctr:%u", tgt, urlctr, tctr); 135 //qDebug("tgt:%u urlctr:%u tctr:%u", tgt, urlctr, tctr);
136 if (tctr >= tgt) 136 if (tctr >= tgt)
137 { 137 {
138 break; 138 break;
139 } 139 }
140 urlctr = tctr; 140 urlctr = tctr;
141 } 141 }
142 //qDebug("urls are in %d", ntohs(urlid)); 142 //qDebug("urls are in %d", ntohs(urlid));
143 recptr = finduid(ntohs(urlid)); 143 recptr = finduid(ntohs(urlid));
144 if (recptr != 0) 144 if (recptr != 0)
145 { 145 {
146 UInt32 reclen = recordlength(recptr) - HeaderSize(); 146 UInt32 reclen = recordlength(recptr) - HeaderSize();
147 gotorecordnumber(recptr); 147 gotorecordnumber(recptr);
148 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 148 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
149 //qDebug("Found urls:%x",thishdr_type); 149 //qDebug("Found urls:%x",thishdr_type);
150 urlsize = thishdr_size; 150 urlsize = thishdr_size;
151 urls = new char[urlsize]; 151 urls = new char[urlsize];
152 Expand(reclen, thishdr_type, (UInt8*)urls, urlsize); 152 Expand(reclen, thishdr_type, (UInt8*)urls, urlsize);
153 char* ptr = urls; 153 char* ptr = urls;
154 int rn = urlctr+1; 154 int rn = urlctr+1;
155 while (ptr - urls < urlsize) 155 while (ptr - urls < urlsize)
156 { 156 {
157 if (rn == tgt) 157 if (rn == tgt)
158 { 158 {
159 //qDebug("URL:%s", ptr); 159 //qDebug("URL:%s", ptr);
160 int len = strlen(ptr)+1; 160 int len = strlen(ptr)+1;
161 pRet = new char[len]; 161 pRet = new char[len];
162 memcpy(pRet, ptr, len); 162 memcpy(pRet, ptr, len);
163 break; 163 break;
164 } 164 }
165 ptr += strlen(ptr)+1; 165 ptr += strlen(ptr)+1;
166 rn++; 166 rn++;
167 } 167 }
168 delete [] urls; 168 delete [] urls;
169 } 169 }
170 } 170 }
171 } 171 }
172 else 172 else
173 { 173 {
174 pRet = NULL; 174 pRet = NULL;
175 } 175 }
176 return pRet; 176 return pRet;
177} 177}
178 178
179CPlucker_base::~CPlucker_base() 179CPlucker_base::~CPlucker_base()
180{ 180{
181 if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; 181 if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
182 if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; 182 if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
183#ifdef LOCALPICTURES 183#ifdef LOCALPICTURES
184 if (m_viewer != NULL) delete m_viewer; 184 if (m_viewer != NULL) delete m_viewer;
185#endif 185#endif
186} 186}
187 187
188int CPlucker_base::getch() { return getch(false); } 188int CPlucker_base::getch() { return getch(false); }
189 189
190void CPlucker_base::getch(tchar& ch, CStyle& sty, unsigned long& pos) 190void CPlucker_base::getch(tchar& ch, CStyle& sty, unsigned long& pos)
191{ 191{
192 pos = locate(); 192 pos = locate();
193 ch = getch(false); 193 ch = getch(false);
194 sty = mystyle; 194 sty = mystyle;
195} 195}
196 196
197unsigned int CPlucker_base::locate() 197unsigned int CPlucker_base::locate()
198{ 198{
199 return currentpos; 199 return currentpos;
200 /* 200 /*
201 UInt16 thisrec = 1; 201 UInt16 thisrec = 1;
202 unsigned long locpos = 0; 202 unsigned long locpos = 0;
203 gotorecordnumber(thisrec); 203 gotorecordnumber(thisrec);
204 UInt16 thishdr_uid, thishdr_nParagraphs; 204 UInt16 thishdr_uid, thishdr_nParagraphs;
205 UInt32 thishdr_size; 205 UInt32 thishdr_size;
206 UInt8 thishdr_type, thishdr_reserved; 206 UInt8 thishdr_type, thishdr_reserved;
207 while (thisrec < bufferrec) 207 while (thisrec < bufferrec)
208 { 208 {
209 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 209 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
210 if (thishdr_type < 2) locpos += thishdr_size; 210 if (thishdr_type < 2) locpos += thishdr_size;
211 thisrec++; 211 thisrec++;
212 gotorecordnumber(thisrec); 212 gotorecordnumber(thisrec);
213 } 213 }
214 return locpos+bufferpos; 214 return locpos+bufferpos;
215 */ 215 */
216} 216}
217 217
218void CPlucker_base::locate(unsigned int n) 218void CPlucker_base::locate(unsigned int n)
219{ 219{
220 220
221 // clock_t start = clock(); 221 // clock_t start = clock();
222 if (n >= currentpos-bufferpos && n < currentpos - bufferpos + buffercontent) 222 if (n >= currentpos-bufferpos && n < currentpos - bufferpos + buffercontent)
223 { 223 {
224 currentpos -= bufferpos; 224 currentpos -= bufferpos;
225 expand(bufferrec); 225 expand(bufferrec);
226 while (currentpos < n && bufferpos < buffercontent) getch_base(true); 226 while (currentpos < n && bufferpos < buffercontent) getch_base(true);
227 return; 227 return;
228 } 228 }
229 /* 229 /*
230 230
231 UInt32 textlength = currentpos - bufferpos; 231 UInt32 textlength = currentpos - bufferpos;
232 UInt16 recptr = bufferrec; 232 UInt16 recptr = bufferrec;
233 if (n < textlength/2) 233 if (n < textlength/2)
234 { 234 {
235 textlength = 0; 235 textlength = 0;
236 UInt16 thishdr_uid, thishdr_nParagraphs; 236 UInt16 thishdr_uid, thishdr_nParagraphs;
237 UInt32 thishdr_size = buffercontent; 237 UInt32 thishdr_size = buffercontent;
238 UInt8 thishdr_type, thishdr_reserved; 238 UInt8 thishdr_type, thishdr_reserved;
239 for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) 239 for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++)
240 { 240 {
241 gotorecordnumber(recptr); 241 gotorecordnumber(recptr);
242 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 242 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
243 if (thishdr_type < 2) 243 if (thishdr_type < 2)
244 { 244 {
245 textlength += thishdr_size; 245 textlength += thishdr_size;
246 if (textlength > n) 246 if (textlength > n)
247 { 247 {
248 textlength -= thishdr_size; 248 textlength -= thishdr_size;
249 break; 249 break;
250 } 250 }
251 } 251 }
252 } 252 }
253 } 253 }
254 else if (n < textlength) 254 else if (n < textlength)
255 { 255 {
256 UInt16 thishdr_uid, thishdr_nParagraphs; 256 UInt16 thishdr_uid, thishdr_nParagraphs;
257 UInt32 thishdr_size; 257 UInt32 thishdr_size;
258 UInt8 thishdr_type, thishdr_reserved; 258 UInt8 thishdr_type, thishdr_reserved;
259 while (n < textlength && recptr > 1) 259 while (n < textlength && recptr > 1)
260 { 260 {
261 recptr--; 261 recptr--;
262 gotorecordnumber(recptr); 262 gotorecordnumber(recptr);
263 //qDebug("recptr:%u", recptr); 263 //qDebug("recptr:%u", recptr);
264 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 264 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
265 if (thishdr_type < 2) 265 if (thishdr_type < 2)
266 { 266 {
267 textlength -= thishdr_size; 267 textlength -= thishdr_size;
268 } 268 }
269 } 269 }
270 } 270 }
271 else 271 else
272 { 272 {
273 UInt16 thishdr_uid, thishdr_nParagraphs; 273 UInt16 thishdr_uid, thishdr_nParagraphs;
274 UInt32 thishdr_size = buffercontent; 274 UInt32 thishdr_size = buffercontent;
275 UInt8 thishdr_type, thishdr_reserved; 275 UInt8 thishdr_type, thishdr_reserved;
276 while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1) 276 while (n > textlength + thishdr_size && recptr < ntohs(head.recordList.numRecords)-1)
277 { 277 {
278 textlength += thishdr_size; 278 textlength += thishdr_size;
279 recptr++; 279 recptr++;
280 gotorecordnumber(recptr); 280 gotorecordnumber(recptr);
281 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 281 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
282 if (!(thishdr_type < 2)) 282 if (!(thishdr_type < 2))
283 { 283 {
284 thishdr_size = 0; 284 thishdr_size = 0;
285 } 285 }
286 } 286 }
287 } 287 }
288 288
289 */ 289 */
290 UInt16 thisrec = 0; 290 UInt16 thisrec = 0;
291 unsigned long locpos = 0; 291 unsigned long locpos = 0;
292 unsigned long bs = 0; 292 unsigned long bs = 0;
293 unsigned int np1 = n+1; 293 unsigned int np1 = n+1;
294 UInt16 thishdr_uid, thishdr_nParagraphs; 294 UInt16 thishdr_uid, thishdr_nParagraphs;
295 UInt32 thishdr_size; 295 UInt32 thishdr_size;
296 UInt8 thishdr_type, thishdr_reserved; 296 UInt8 thishdr_type, thishdr_reserved;
297 do 297 do
298 { 298 {
299 thisrec++; 299 thisrec++;
300 locpos += bs; 300 locpos += bs;
301 gotorecordnumber(thisrec); 301 gotorecordnumber(thisrec);
302 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 302 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
303 if (thishdr_type < 2) 303 if (thishdr_type < 2)
304 { 304 {
305 bs = thishdr_size; 305 bs = thishdr_size;
306 } 306 }
307 else 307 else
308 { 308 {
309 bs = 0; 309 bs = 0;
310 } 310 }
311 } while (locpos + bs < np1); 311 } while (locpos + bs < np1);
312 312
313 // qDebug("Time(2): %u", clock()-start); 313 // qDebug("Time(2): %u", clock()-start);
314 /* 314 /*
315 if (recptr != thisrec) 315 if (recptr != thisrec)
316 { 316 {
317 qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec); 317 qDebug("Disaster:recptr:%u thisrec:%u", recptr, thisrec);
318 UInt16 thishdr_uid, thishdr_nParagraphs; 318 UInt16 thishdr_uid, thishdr_nParagraphs;
319 UInt32 thishdr_size = buffercontent; 319 UInt32 thishdr_size = buffercontent;
320 UInt8 thishdr_type, thishdr_reserved; 320 UInt8 thishdr_type, thishdr_reserved;
321 for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) 321 for (recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++)
322 { 322 {
323 gotorecordnumber(recptr); 323 gotorecordnumber(recptr);
324 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 324 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
325 // qDebug("UID:%u Paras:%u Size:%u Type:%u Reserved:%u", thishdr_uid, thishdr_nParagraphs, thishdr_size, (unsigned int)thishdr_type, (unsigned int)thishdr_reserved); 325 // qDebug("UID:%u Paras:%u Size:%u Type:%u Reserved:%u", thishdr_uid, thishdr_nParagraphs, thishdr_size, (unsigned int)thishdr_type, (unsigned int)thishdr_reserved);
326 } 326 }
327 //QApplication::exit ( 100 ); 327 //QApplication::exit ( 100 );
328 } 328 }
329 */ 329 */
330 currentpos = locpos; 330 currentpos = locpos;
331 expand(thisrec); 331 expand(thisrec);
332 while (currentpos < n && bufferpos < buffercontent) getch_base(true); 332 while (currentpos < n && bufferpos < buffercontent) getch_base(true);
333 333
334 /* // This is faster but the alignment attribute doesn't get set 8^( 334 /* // This is faster but the alignment attribute doesn't get set 8^(
335 bufferpos = n-locpos; 335 bufferpos = n-locpos;
336 currentpos = n; 336 currentpos = n;
337 while (bufferpos >= m_nextPara && m_nextPara >= 0) 337 while (bufferpos >= m_nextPara && m_nextPara >= 0)
338 { 338 {
339 UInt16 attr = m_ParaAttrs[m_nextParaIndex]; 339 UInt16 attr = m_ParaAttrs[m_nextParaIndex];
340 m_nextParaIndex++; 340 m_nextParaIndex++;
341 if (m_nextParaIndex == m_nParas) 341 if (m_nextParaIndex == m_nParas)
342 { 342 {
343 m_nextPara = -1; 343 m_nextPara = -1;
344 } 344 }
345 else 345 else
346 { 346 {
347 m_nextPara += m_ParaOffsets[m_nextParaIndex]; 347 m_nextPara += m_ParaOffsets[m_nextParaIndex];
348 } 348 }
349 } 349 }
350 */ 350 */
351} 351}
352 352
353bool CPlucker_base::expand(int thisrec) 353bool CPlucker_base::expand(int thisrec)
354{ 354{
355 mystyle.unset(); 355 mystyle.unset();
356 if (bufferrec != thisrec) 356 if (bufferrec != thisrec)
357 { 357 {
358 size_t reclen = recordlength(thisrec); 358 size_t reclen = recordlength(thisrec);
359 gotorecordnumber(thisrec); 359 gotorecordnumber(thisrec);
360 UInt16 thishdr_uid, thishdr_nParagraphs; 360 UInt16 thishdr_uid, thishdr_nParagraphs;
361 UInt32 thishdr_size; 361 UInt32 thishdr_size;
362 UInt8 thishdr_type, thishdr_reserved; 362 UInt8 thishdr_type, thishdr_reserved;
363 while (1) 363 while (1)
364 { 364 {
365 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 365 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
366 //qDebug("This (%d) type is %d, uid is %u", thisrec, thishdr_type, thishdr_uid); 366 //qDebug("This (%d) type is %d, uid is %u", thisrec, thishdr_type, thishdr_uid);
367 if (thishdr_type < 2) break; 367 if (thishdr_type < 2) break;
368 //qDebug("Skipping paragraph of type %d", thishdr_type); 368 //qDebug("Skipping paragraph of type %d", thishdr_type);
369 if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false; 369 if (++thisrec >= ntohs(head.recordList.numRecords) - 1) return false;
370 reclen = recordlength(thisrec); 370 reclen = recordlength(thisrec);
371 gotorecordnumber(thisrec); 371 gotorecordnumber(thisrec);
372 } 372 }
373 m_nParas = thishdr_nParagraphs; 373 m_nParas = thishdr_nParagraphs;
374 m_bufferisreserved = (thishdr_reserved != 0); 374 m_bufferisreserved = (thishdr_reserved != 0);
375 //qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size); 375 //qDebug("It has %u paragraphs and is %u bytes", thishdr_nParagraphs, thishdr_size);
376 uid = thishdr_uid; 376 uid = thishdr_uid;
377 // gotorecordnumber(thisrec); 377 // gotorecordnumber(thisrec);
378 // fread(expandedtextbuffer,1,10,fin); 378 // fread(expandedtextbuffer,1,10,fin);
379 for (int i = 0; i < m_nParas; i++) 379 for (int i = 0; i < m_nParas; i++)
380 { 380 {
381 UInt16 ubytes, attrs; 381 UInt16 ubytes, attrs;
382 fread(&ubytes, 1, sizeof(ubytes), fin); 382 fread(&ubytes, 1, sizeof(ubytes), fin);
383 fread(&attrs, 1, sizeof(attrs), fin); 383 fread(&attrs, 1, sizeof(attrs), fin);
384 m_ParaOffsets[i] = ntohs(ubytes); 384 m_ParaOffsets[i] = ntohs(ubytes);
385 m_ParaAttrs[i] = ntohs(attrs); 385 m_ParaAttrs[i] = ntohs(attrs);
386 ////qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs)); 386 ////qDebug("Bytes %u, Attr %x", ntohs(ubytes), ntohs(attrs));
387 } 387 }
388 388
389 reclen -= HeaderSize()+4*m_nParas; 389 reclen -= HeaderSize()+4*m_nParas;
390 390
391 buffercontent = thishdr_size; 391 buffercontent = thishdr_size;
392 392
393 if (thishdr_size > buffersize) 393 if (thishdr_size > buffersize)
394 { 394 {
395 delete [] expandedtextbuffer; 395 delete [] expandedtextbuffer;
396 buffersize = thishdr_size; 396 buffersize = thishdr_size;
397 expandedtextbuffer = new UInt8[buffersize]; 397 expandedtextbuffer = new UInt8[buffersize];
398 } 398 }
399 Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent); 399 Expand(reclen, thishdr_type, expandedtextbuffer, buffercontent);
400 bufferrec = thisrec; 400 bufferrec = thisrec;
401 } 401 }
402 402
403 403
404 if (m_nParas > 0) 404 if (m_nParas > 0)
405 { 405 {
406 m_nextPara = m_ParaOffsets[0]; 406 m_nextPara = m_ParaOffsets[0];
407 //qDebug("First offset = %u", m_nextPara); 407 //qDebug("First offset = %u", m_nextPara);
408 m_nextParaIndex = 0; 408 m_nextParaIndex = 0;
409 } 409 }
410 else 410 else
411 { 411 {
412 m_nextPara = -1; 412 m_nextPara = -1;
413 } 413 }
414 bufferpos = 0; 414 bufferpos = 0;
415 //qDebug("BC:%u, HS:%u", buffercontent, thishdr_size); 415 //qDebug("BC:%u, HS:%u", buffercontent, thishdr_size);
416 return true; 416 return true;
417} 417}
418/* 418/*
419void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) 419void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize)
420{ 420{
421 z_stream zstream; 421 z_stream zstream;
422 memset(&zstream,sizeof(zstream),0); 422 memset(&zstream,sizeof(zstream),0);
423 zstream.next_in = compressedbuffer; 423 zstream.next_in = compressedbuffer;
424 zstream.next_out = tgtbuffer; 424 zstream.next_out = tgtbuffer;
425 zstream.avail_out = bsize; 425 zstream.avail_out = bsize;
426 zstream.avail_in = reclen; 426 zstream.avail_in = reclen;
427 427
428 int keylen = 0; 428 int keylen = 0;
429 429
430 zstream.zalloc = Z_NULL; 430 zstream.zalloc = Z_NULL;
431 zstream.zfree = Z_NULL; 431 zstream.zfree = Z_NULL;
432 zstream.opaque = Z_NULL; 432 zstream.opaque = Z_NULL;
433 433
434 // printf("Initialising\n"); 434 // printf("Initialising\n");
435 435
436 inflateInit(&zstream); 436 inflateInit(&zstream);
437 int err = 0; 437 int err = 0;
438 do { 438 do {
439 if ( zstream.avail_in == 0 && 0 < keylen ) { 439 if ( zstream.avail_in == 0 && 0 < keylen ) {
440 zstream.next_in = compressedbuffer + keylen; 440 zstream.next_in = compressedbuffer + keylen;
441 zstream.avail_in = reclen - keylen; 441 zstream.avail_in = reclen - keylen;
442 keylen = 0; 442 keylen = 0;
443 } 443 }
444 zstream.next_out = tgtbuffer; 444 zstream.next_out = tgtbuffer;
445 zstream.avail_out = bsize; 445 zstream.avail_out = bsize;
446 446
447 err = inflate( &zstream, Z_SYNC_FLUSH ); 447 err = inflate( &zstream, Z_SYNC_FLUSH );
448 448
449 ////qDebug("err:%d - %u", err, zstream.avail_in); 449 ////qDebug("err:%d - %u", err, zstream.avail_in);
450 450
451 } while ( err == Z_OK ); 451 } while ( err == Z_OK );
452 452
453 inflateEnd(&zstream); 453 inflateEnd(&zstream);
454} 454}
455*/ 455*/
456size_t CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) 456size_t CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize)
457{ 457{
458 // UInt16 headerSize; 458 // UInt16 headerSize;
459 UInt16 docSize; 459 UInt16 docSize;
460 UInt16 i; 460 UInt16 i;
461 UInt16 j; 461 UInt16 j;
462 UInt16 k; 462 UInt16 k;
463 463
464 UInt8 *inBuf = compressedbuffer; 464 UInt8 *inBuf = compressedbuffer;
465 UInt8 *outBuf = tgtbuffer; 465 UInt8 *outBuf = tgtbuffer;
466 466
467 // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph ); 467 // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph );
468 docSize = reclen; 468 docSize = reclen;
469 469
470 j = 0; 470 j = 0;
471 k = 0; 471 k = 0;
472 while ( j < docSize ) { 472 while ( j < docSize ) {
473 i = 0; 473 i = 0;
474 while ( i < bsize && j < docSize ) { 474 while ( i < bsize && j < docSize ) {
475 UInt16 c; 475 UInt16 c;
476 476
477 c = (UInt16) inBuf[ j++ ]; 477 c = (UInt16) inBuf[ j++ ];
478 if ( 0 < c && c < 9 ) { 478 if ( 0 < c && c < 9 ) {
479 while ( 0 < c-- ) 479 while ( 0 < c-- )
480 outBuf[ i++ ] = inBuf[ j++ ]; 480 outBuf[ i++ ] = inBuf[ j++ ];
481 } 481 }
482 else if ( c < 0x80 ) 482 else if ( c < 0x80 )
483 outBuf[ i++ ] = c; 483 outBuf[ i++ ] = c;
484 else if ( 0xc0 <= c ) { 484 else if ( 0xc0 <= c ) {
485 outBuf[ i++ ] = ' '; 485 outBuf[ i++ ] = ' ';
486 outBuf[ i++ ] = c ^ 0x80; 486 outBuf[ i++ ] = c ^ 0x80;
487 } 487 }
488 else { 488 else {
489 Int16 m; 489 Int16 m;
490 Int16 n; 490 Int16 n;
491 491
492 c <<= 8; 492 c <<= 8;
493 c += inBuf[ j++ ]; 493 c += inBuf[ j++ ];
494 494
495 m = ( c & 0x3fff ) >> COUNT_BITS; 495 m = ( c & 0x3fff ) >> COUNT_BITS;
496 n = c & ( ( 1 << COUNT_BITS ) - 1 ); 496 n = c & ( ( 1 << COUNT_BITS ) - 1 );
497 n += 2; 497 n += 2;
498 498
499 do { 499 do {
500 outBuf[ i ] = outBuf[ i - m ]; 500 outBuf[ i ] = outBuf[ i - m ];
501 i++; 501 i++;
502 } while ( 0 < n-- ); 502 } while ( 0 < n-- );
503 } 503 }
504 } 504 }
505 k += bsize; 505 k += bsize;
506 } 506 }
507 return i; 507 return i;
508} 508}
509 509
510void CPlucker_base::home() 510void CPlucker_base::home()
511{ 511{
512 currentpos = 0; 512 currentpos = 0;
513 expand(1); 513 expand(1);
514} 514}
515 515
516CList<Bkmk>* CPlucker_base::getbkmklist() 516CList<Bkmk>* CPlucker_base::getbkmklist()
517{ 517{
518 /* 518 /*
519 UInt16 thishdr_uid, thishdr_nParagraphs; 519 UInt16 thishdr_uid, thishdr_nParagraphs;
520 UInt32 thishdr_size; 520 UInt32 thishdr_size;
521 UInt8 thishdr_type, thishdr_reserved; 521 UInt8 thishdr_type, thishdr_reserved;
522 522
523 for (int i = 1; i < ntohs(head.recordList.numRecords); i++) 523 for (int i = 1; i < ntohs(head.recordList.numRecords); i++)
524 { 524 {
525 gotorecordnumber(i); 525 gotorecordnumber(i);
526 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 526 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
527 if (thishdr_type == 8) 527 if (thishdr_type == 8)
528 { 528 {
529 UInt16 n; 529 UInt16 n;
530 fread(&n, 1, sizeof(n), fin); 530 fread(&n, 1, sizeof(n), fin);
531 n = ntohs(n); 531 n = ntohs(n);
532 //qDebug("Found %u bookmarks", n); 532 //qDebug("Found %u bookmarks", n);
533 } 533 }
534 //qDebug("Found:%d, %u", i , thishdr_type); 534 //qDebug("Found:%d, %u", i , thishdr_type);
535 } 535 }
536 */ 536 */
537 return NULL; 537 return NULL;
538} 538}
539 539
540#include <qnamespace.h> 540#include <qnamespace.h>
541 541
542QImage* CPlucker_base::expandimg(UInt16 tgt, bool border) 542QImage* CPlucker_base::expandimg(UInt16 tgt, bool border)
543{ 543{
544 QImage* qimage = getimg(tgt); 544 QImage* qimage = getimg(tgt);
545 QImage* ret; 545 QImage* ret;
546 if (qimage == NULL) return NULL; 546 if (qimage == NULL) return NULL;
547 if (border) 547 if (border)
548 { 548 {
549 QPixmap* image = new QPixmap(0,0); 549 QPixmap* image = new QPixmap(0,0);
550 image->convertFromImage(*qimage); 550 image->convertFromImage(*qimage);
551 delete qimage; 551 delete qimage;
552 QPixmap* pret = new QPixmap(image->width()+4, image->height()+4); 552 QPixmap* pret = new QPixmap(image->width()+4, image->height()+4);
553 pret->fill(Qt::red); 553 pret->fill(Qt::red);
554 bitBlt(pret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP); 554 bitBlt(pret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP);
555 delete image; 555 delete image;
556 ret = new QImage(pret->convertToImage()); 556 ret = new QImage(pret->convertToImage());
557 } 557 }
558 else 558 else
559 { 559 {
560 ret = qimage; 560 ret = qimage;
561 } 561 }
562 return ret; 562 return ret;
563} 563}
564 564
565#ifdef _BUFFERPICS 565#ifdef _BUFFERPICS
566#include <qmap.h> 566#include <qmap.h>
567#endif 567#endif
568 568
569QImage* CPlucker_base::getPicture(unsigned long tgt) 569QImage* CPlucker_base::getPicture(unsigned long tgt)
570{ 570{
571#ifdef _BUFFERPICS 571#ifdef _BUFFERPICS
572 static QMap<unsigned long, QPixmap> pix; 572 static QMap<unsigned long, QPixmap> pix;
573 QMap<unsigned long, QPixmap>::Iterator t = pix.find(tgt); 573 QMap<unsigned long, QPixmap>::Iterator t = pix.find(tgt);
574 if (t == pix.end()) 574 if (t == pix.end())
575 { 575 {
576 pix[tgt] = *expandimg(tgt); 576 pix[tgt] = *expandimg(tgt);
577 return &pix[tgt]; 577 return &pix[tgt];
578 } 578 }
579 else 579 else
580 return &(t.data()); 580 return &(t.data());
581#else 581#else
582 return expandimg(tgt >> 16); 582 return expandimg(tgt >> 16);
583#endif 583#endif
584} 584}
585 585
586#ifdef LOCALPICTURES 586#ifdef LOCALPICTURES
587#include <unistd.h> 587#include <unistd.h>
588#include <qpe/global.h> 588#include <qpe/global.h>
589void CPlucker_base::showimg(UInt16 tgt) 589void CPlucker_base::showimg(UInt16 tgt)
590{ 590{
591 //qDebug("Crassssssh!"); 591 //qDebug("Crassssssh!");
592 QPixmap* qimage = expandimg(tgt); 592 QPixmap* qimage = expandimg(tgt);
593 m_picture->setFixedSize(qimage->size()); 593 m_picture->setFixedSize(qimage->size());
594 m_picture->setBackgroundPixmap(*qimage); 594 m_picture->setBackgroundPixmap(*qimage);
595 delete qimage; 595 delete qimage;
596 m_viewer->show(); 596 m_viewer->show();
597 597
598 /* 598 /*
599 char tmp[] = "uqtreader.XXXXXX"; 599 char tmp[] = "uqtreader.XXXXXX";
600 QImage* qimage = getimg(tgt); 600 QImage* qimage = getimg(tgt);
601 QPixmap* image = new QPixmap(0,0); 601 QPixmap* image = new QPixmap(0,0);
602 // //qDebug("New image"); 602 // //qDebug("New image");
603 image->convertFromImage(*qimage); 603 image->convertFromImage(*qimage);
604 delete qimage; 604 delete qimage;
605 char tmpfile[sizeof(tmp)+1]; 605 char tmpfile[sizeof(tmp)+1];
606 strcpy(tmpfile,tmp); 606 strcpy(tmpfile,tmp);
607 int f = mkstemp(tmpfile); 607 int f = mkstemp(tmpfile);
608 close(f); 608 close(f);
609 //qDebug("TMPFILE:%s", tmpfile); 609 //qDebug("TMPFILE:%s", tmpfile);
610 if (image->save(tmpfile,"PNG")) 610 if (image->save(tmpfile,"PNG"))
611 { 611 {
612 QCopEnvelope e("QPE/Application/showimg", "setDocument(QString)"); 612 QCopEnvelope e("QPE/Application/showimg", "setDocument(QString)");
613 e << QString(tmpfile); 613 e << QString(tmpfile);
614 } 614 }
615 Global::statusMessage("Opening image"); 615 Global::statusMessage("Opening image");
616 sleep(5); 616 sleep(5);
617 delete image; 617 delete image;
618 unlink(tmpfile); 618 unlink(tmpfile);
619 */ 619 */
620} 620}
621 621
622#endif 622#endif
623 623
624unsigned short CPlucker_base::finduid(unsigned short urlid) 624unsigned short CPlucker_base::finduid(unsigned short urlid)
625{ 625{
626 // //qDebug("Finding %u", urlid); 626 // //qDebug("Finding %u", urlid);
627 unsigned short jmin = 1, jmax = ntohs(head.recordList.numRecords); 627 unsigned short jmin = 1, jmax = ntohs(head.recordList.numRecords);
628 unsigned short jmid = (jmin+jmax) >> 1; 628 unsigned short jmid = (jmin+jmax) >> 1;
629 while (jmax - jmin > 1) 629 while (jmax - jmin > 1)
630 { 630 {
631 gotorecordnumber(jmid); 631 gotorecordnumber(jmid);
632 UInt16 thishdr_uid, thishdr_nParagraphs; 632 UInt16 thishdr_uid, thishdr_nParagraphs;
633 UInt32 thishdr_size; 633 UInt32 thishdr_size;
634 UInt8 thishdr_type, thishdr_reserved; 634 UInt8 thishdr_type, thishdr_reserved;
635 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 635 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
636 unsigned short luid = thishdr_uid; 636 unsigned short luid = thishdr_uid;
637 ////qDebug("%u %u %u : %u", jmin, jmid, jmax, urlid); 637 ////qDebug("%u %u %u : %u", jmin, jmid, jmax, urlid);
638 if (luid == urlid) 638 if (luid == urlid)
639 { 639 {
640 return jmid; 640 return jmid;
641 } 641 }
642 if (luid < urlid) 642 if (luid < urlid)
643 { 643 {
644 jmin = jmid; 644 jmin = jmid;
645 } 645 }
646 else 646 else
647 { 647 {
648 jmax = jmid; 648 jmax = jmid;
649 } 649 }
650 jmid = (jmin+jmax) >> 1; 650 jmid = (jmin+jmax) >> 1;
651 } 651 }
652 gotorecordnumber(jmin); 652 gotorecordnumber(jmin);
653 UInt16 thishdr_uid, thishdr_nParagraphs; 653 UInt16 thishdr_uid, thishdr_nParagraphs;
654 UInt32 thishdr_size; 654 UInt32 thishdr_size;
655 UInt8 thishdr_type, thishdr_reserved; 655 UInt8 thishdr_type, thishdr_reserved;
656 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 656 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
657 unsigned short luid = thishdr_uid; 657 unsigned short luid = thishdr_uid;
658 //qDebug("jmin at end:%u,%u", jmin, luid); 658 //qDebug("jmin at end:%u,%u", jmin, luid);
659 if (luid == urlid) 659 if (luid == urlid)
660 { 660 {
661 return jmin; 661 return jmin;
662 } 662 }
663 gotorecordnumber(jmax); 663 gotorecordnumber(jmax);
664 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 664 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
665 luid = thishdr_uid; 665 luid = thishdr_uid;
666 //qDebug("jmax at end:%u,%u", jmax, luid); 666 //qDebug("jmax at end:%u,%u", jmax, luid);
667 if (luid == urlid) 667 if (luid == urlid)
668 { 668 {
669 return jmax; 669 return jmax;
670 } 670 }
671 //qDebug("Couldn't find %u", urlid); 671 //qDebug("Couldn't find %u", urlid);
672 return 0; // Not found! 672 return 0; // Not found!
673} 673}
674 674
675#include <qnamespace.h> 675#include <qnamespace.h>
676 676
677void CPlucker_base::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) 677void CPlucker_base::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
678{ 678{
679 unsigned short sz = 0; 679 unsigned short sz = 0;
680 for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) 680 for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++)
681 { 681 {
682 sz++; 682 sz++;
683 } 683 }
684 size_t newlen = srclen+sizeof(sz)+sz*sizeof(unsigned long); 684 size_t newlen = srclen+sizeof(sz)+sz*sizeof(unsigned long);
685 unsigned char* newdata = new unsigned char[newlen]; 685 unsigned char* newdata = new unsigned char[newlen];
686 unsigned char* pdata = newdata; 686 unsigned char* pdata = newdata;
687 memcpy(newdata, src, srclen); 687 memcpy(newdata, src, srclen);
688 newdata += srclen; 688 newdata += srclen;
689 memcpy(newdata, &sz, sizeof(sz)); 689 memcpy(newdata, &sz, sizeof(sz));
690 newdata += sizeof(sz); 690 newdata += sizeof(sz);
691#ifdef _WINDOWS 691#ifdef _WINDOWS
692 for (it = visited.begin(); it != visited.end(); it++) 692 for (it = visited.begin(); it != visited.end(); it++)
693#else 693#else
694 for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) 694 for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++)
695#endif 695#endif
696 { 696 {
697 unsigned long t = *it; 697 unsigned long t = *it;
698 //qDebug("[%u]", t); 698 //qDebug("[%u]", t);
699 memcpy(newdata, &t, sizeof(t)); 699 memcpy(newdata, &t, sizeof(t));
700 newdata += sizeof(t); 700 newdata += sizeof(t);
701 } 701 }
702 m_nav.setSaveData(data, len, pdata, newlen); 702 m_nav.setSaveData(data, len, pdata, newlen);
703 delete [] pdata; 703 delete [] pdata;
704} 704}
705 705
706void CPlucker_base::putSaveData(unsigned char*& src, unsigned short& srclen) 706void CPlucker_base::putSaveData(unsigned char*& src, unsigned short& srclen)
707{ 707{
708 unsigned short sz; 708 unsigned short sz = 0;
709 if (srclen >= sizeof(sz)) 709 if (srclen >= sizeof(sz))
710 { 710 {
711 memcpy(&sz, src, sizeof(sz)); 711 memcpy(&sz, src, sizeof(sz));
712 src += sizeof(sz); 712 src += sizeof(sz);
713 srclen -= sizeof(sz); 713 srclen -= sizeof(sz);
714 } 714 }
715 for (int i = 0; i < sz; i++) 715 for (int i = 0; i < sz; i++)
716 { 716 {
717 unsigned long t; 717 unsigned long t;
718 if (srclen >= sizeof(t)) 718 if (srclen >= sizeof(t))
719 { 719 {
720 memcpy(&t, src, sizeof(t)); 720 memcpy(&t, src, sizeof(t));
721 // qDebug("[%u]", t); 721 // qDebug("[%u]", t);
722 visited.push_front(t); 722 visited.push_front(t);
723 src += sizeof(t); 723 src += sizeof(t);
724 srclen -= sizeof(t); 724 srclen -= sizeof(t);
725 } 725 }
726 else 726 else
727 { 727 {
728 QMessageBox::warning(NULL, PROGNAME, "File data mismatch\nMight fix itself"); 728 QMessageBox::warning(NULL, PROGNAME, "File data mismatch\nMight fix itself");
729 break; 729 break;
730 } 730 }
731 } 731 }
732 m_nav.putSaveData(src, srclen); 732 m_nav.putSaveData(src, srclen);
733} 733}
734 734
735int CPlucker_base::OpenFile(const char *src) 735int CPlucker_base::OpenFile(const char *src)
736{ 736{
737 qDebug("plucker openfile:%s", src); 737 qDebug("plucker openfile:%s", src);
738 m_lastBreak = 0; 738 m_lastBreak = 0;
739 if (!Cpdb::openpdbfile(src)) 739 if (!Cpdb::openpdbfile(src))
740 { 740 {
741 return -1; 741 return -1;
742 } 742 }
743 743
744 if (!CorrectDecoder()) return -1; 744 if (!CorrectDecoder()) return -1;
745 745
746 gotorecordnumber(0); 746 gotorecordnumber(0);
747 fread(&hdr0, 1, 6, fin); 747 fread(&hdr0, 1, 6, fin);
748 qDebug("Compression type:%u", ntohs(hdr0.version)); 748 qDebug("Compression type:%u", ntohs(hdr0.version));
749 749
750 750
751 switch (ntohs(hdr0.version)) 751 switch (ntohs(hdr0.version))
752 { 752 {
753 case 2: 753 case 2:
754 m_decompress = UnZip; 754 m_decompress = UnZip;
755 break; 755 break;
756 case 1: 756 case 1:
757 m_decompress = UnDoc; 757 m_decompress = UnDoc;
758 break; 758 break;
759#ifdef USENEF 759#ifdef USENEF
760 case 3: 760 case 3:
761 m_decompress = getdecompressor("PluckerDecompress3"); 761 m_decompress = getdecompressor("PluckerDecompress3");
762 break; 762 break;
763 case 4: 763 case 4:
764 m_decompress = getdecompressor("PluckerDecompress4"); 764 m_decompress = getdecompressor("PluckerDecompress4");
765 break; 765 break;
766#endif 766#endif
767 default: 767 default:
768 m_decompress = NULL; 768 m_decompress = NULL;
769 } 769 }
770 if (m_decompress == NULL) return -1; 770 if (m_decompress == NULL) return -1;
771 771
772 setbuffersize(); 772 setbuffersize();
773 compressedtextbuffer = new UInt8[compressedbuffersize]; 773 compressedtextbuffer = new UInt8[compressedbuffersize];
774 expandedtextbuffer = new UInt8[buffersize]; 774 expandedtextbuffer = new UInt8[buffersize];
775 775
776 unsigned int nrecs = ntohs(hdr0.nRecords); 776 unsigned int nrecs = ntohs(hdr0.nRecords);
777 qDebug("Version %u, no. reserved recs %u", ntohs(hdr0.version), nrecs); 777 qDebug("Version %u, no. reserved recs %u", ntohs(hdr0.version), nrecs);
778 textlength = ntohl(head.sortInfoID); 778 textlength = ntohl(head.sortInfoID);
779 qDebug("Textlength at startup:%u", textlength); 779 qDebug("Textlength at startup:%u", textlength);
780 UInt16 homerecid = 1; 780 UInt16 homerecid = 1;
781 for (unsigned int i = 0; i < nrecs; i++) 781 for (unsigned int i = 0; i < nrecs; i++)
782 { 782 {
783 UInt16 id, name; 783 UInt16 id, name;
784 fread(&name, 1, sizeof(name), fin); 784 fread(&name, 1, sizeof(name), fin);
785 fread(&id, 1, sizeof(id), fin); 785 fread(&id, 1, sizeof(id), fin);
786 //qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); 786 //qDebug("N:%d, I:%d", ntohs(name), ntohs(id));
787 if (ntohs(name) == 0) homerecid = ntohs(id); 787 if (ntohs(name) == 0) homerecid = ntohs(id);
788 } 788 }
789 789
790 textlength = 0; 790 textlength = 0;
791 for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) 791 for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++)
792 { 792 {
793 gotorecordnumber(recptr); 793 gotorecordnumber(recptr);
794 UInt16 thishdr_uid, thishdr_nParagraphs; 794 UInt16 thishdr_uid, thishdr_nParagraphs;
795 UInt32 thishdr_size; 795 UInt32 thishdr_size;
796 UInt8 thishdr_type, thishdr_reserved; 796 UInt8 thishdr_type, thishdr_reserved;
797 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 797 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
798 if (thishdr_uid == homerecid) 798 if (thishdr_uid == homerecid)
799 { 799 {
800 m_homepos = textlength; 800 m_homepos = textlength;
801 break; 801 break;
802 } 802 }
803 if (thishdr_type < 2) textlength += thishdr_size; 803 if (thishdr_type < 2) textlength += thishdr_size;
804 } 804 }
805 qDebug("Found home"); 805 qDebug("Found home");
806 textlength = 0; 806 textlength = 0;
807 home(); 807 home();
808 qDebug("Gone home"); 808 qDebug("Gone home");
809#ifdef LOCALPICTURES 809#ifdef LOCALPICTURES
810 if (m_viewer == NULL) 810 if (m_viewer == NULL)
811 { 811 {
812 m_viewer = new QScrollView(NULL); 812 m_viewer = new QScrollView(NULL);
813 m_picture = new QWidget(m_viewer->viewport()); 813 m_picture = new QWidget(m_viewer->viewport());
814 m_viewer->addChild(m_picture); 814 m_viewer->addChild(m_picture);
815 } 815 }
816#endif 816#endif
817 return 0; 817 return 0;
818 818
819} 819}
820 820
821QImage* CPlucker_base::getimg(UInt16 tgt) 821QImage* CPlucker_base::getimg(UInt16 tgt)
822{ 822{
823 size_t reclen; 823 size_t reclen;
824 UInt16 thisrec = finduid(tgt); 824 UInt16 thisrec = finduid(tgt);
825 qDebug("getimg:Found %u from uid:%u", thisrec, tgt); 825 qDebug("getimg:Found %u from uid:%u", thisrec, tgt);
826 reclen = recordlength(thisrec); 826 reclen = recordlength(thisrec);
827 gotorecordnumber(thisrec); 827 gotorecordnumber(thisrec);
828 UInt16 thishdr_uid, thishdr_nParagraphs; 828 UInt16 thishdr_uid, thishdr_nParagraphs;
829 UInt32 thishdr_size; 829 UInt32 thishdr_size;
830 UInt8 thishdr_type, thishdr_reserved; 830 UInt8 thishdr_type, thishdr_reserved;
831 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 831 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
832 if (thishdr_type == 15) 832 if (thishdr_type == 15)
833 { 833 {
834 char *buffer = new char[thishdr_size]; 834 char *buffer = new char[thishdr_size];
835 fread(buffer, thishdr_size, sizeof(char), fin); 835 fread(buffer, thishdr_size, sizeof(char), fin);
836 unsigned short tmp; 836 unsigned short tmp;
837 memcpy(&tmp, buffer, sizeof(tmp)); 837 memcpy(&tmp, buffer, sizeof(tmp));
838 unsigned short cols = ntohs(tmp); 838 unsigned short cols = ntohs(tmp);
839 memcpy(&tmp, buffer+sizeof(tmp), sizeof(tmp)); 839 memcpy(&tmp, buffer+sizeof(tmp), sizeof(tmp));
840 unsigned short rows = ntohs(tmp); 840 unsigned short rows = ntohs(tmp);
841 qDebug("Found a picture of type:%u [%u,%u]", thishdr_type, rows, cols); 841 qDebug("Found a picture of type:%u [%u,%u]", thishdr_type, rows, cols);
842 QImage*** images; 842 QImage*** images;
843 images = new QImage**[rows]; 843 images = new QImage**[rows];
844#ifdef _WINDOWS 844#ifdef _WINDOWS
845 int i; 845 int i;
846 for (i = 0; i < rows; i++) 846 for (i = 0; i < rows; i++)
847#else 847#else
848 for (int i = 0; i < rows; i++) 848 for (int i = 0; i < rows; i++)
849#endif 849#endif
850 { 850 {
851 images[i] = new QImage*[cols]; 851 images[i] = new QImage*[cols];
852 } 852 }
853 int height = 0; 853 int height = 0;
854 int width = 0; 854 int width = 0;
855#ifdef _WINDOWS 855#ifdef _WINDOWS
856 for (i = 0; i < rows; i++) 856 for (i = 0; i < rows; i++)
857#else 857#else
858 for (int i = 0; i < rows; i++) 858 for (int i = 0; i < rows; i++)
859#endif 859#endif
860 { 860 {
861 width = 0; 861 width = 0;
862 for (int j = 0; j < cols; j++) 862 for (int j = 0; j < cols; j++)
863 { 863 {
864 memcpy(&tmp, buffer+(i*cols+j+2)*sizeof(tmp), sizeof(tmp)); 864 memcpy(&tmp, buffer+(i*cols+j+2)*sizeof(tmp), sizeof(tmp));
865 unsigned short uid = ntohs(tmp); 865 unsigned short uid = ntohs(tmp);
866 images[i][j] = getimg(uid); 866 images[i][j] = getimg(uid);
867 width += images[i][j]->width(); 867 width += images[i][j]->width();
868 } 868 }
869 height += images[i][0]->height(); 869 height += images[i][0]->height();
870 } 870 }
871 delete [] buffer; 871 delete [] buffer;
872 QPixmap pm(width, height); 872 QPixmap pm(width, height);
873 int hoffset = 0; 873 int hoffset = 0;
874#ifdef _WINDOWS 874#ifdef _WINDOWS
875 for (i = 0; i < rows; i++) 875 for (i = 0; i < rows; i++)
876#else 876#else
877 for (int i = 0; i < rows; i++) 877 for (int i = 0; i < rows; i++)
878#endif 878#endif
879 { 879 {
880 int woffset = 0; 880 int woffset = 0;
881 int delht = images[i][0]->height(); 881 int delht = images[i][0]->height();
882 for (int j = 0; j < cols; j++) 882 for (int j = 0; j < cols; j++)
883 { 883 {
884 QPixmap pm2; 884 QPixmap pm2;
885 pm2.convertFromImage(*(images[i][j])); 885 pm2.convertFromImage(*(images[i][j]));
886 delete images[i][j]; 886 delete images[i][j];
887 bitBlt(&pm, woffset, hoffset, &pm2, 0, 0, pm2.width(), pm2.height()); 887 bitBlt(&pm, woffset, hoffset, &pm2, 0, 0, pm2.width(), pm2.height());
888 woffset += pm2.width(); 888 woffset += pm2.width();
889 } 889 }
890 hoffset += delht; 890 hoffset += delht;
891 } 891 }
892#ifdef _WINDOWS 892#ifdef _WINDOWS
893 for (i = 0; i < rows; i++) 893 for (i = 0; i < rows; i++)
894#else 894#else
895 for (int i = 0; i < rows; i++) 895 for (int i = 0; i < rows; i++)
896#endif 896#endif
897 { 897 {
898 delete [] images[i]; 898 delete [] images[i];
899 } 899 }
900 delete [] images; 900 delete [] images;
901 return new QImage(pm.convertToImage()); 901 return new QImage(pm.convertToImage());
902 } 902 }
903 else 903 else
904 { 904 {
905 qDebug("Found a picture of type:%u", thishdr_type); 905 qDebug("Found a picture of type:%u", thishdr_type);
906 reclen -= HeaderSize(); 906 reclen -= HeaderSize();
907 907
908 UInt32 imgsize = thishdr_size; 908 UInt32 imgsize = thishdr_size;
909 UInt8* imgbuffer = new UInt8[imgsize]; 909 UInt8* imgbuffer = new UInt8[imgsize];
910 910
911 Expand(reclen, thishdr_type, imgbuffer, imgsize); 911 Expand(reclen, thishdr_type, imgbuffer, imgsize);
912 912
913 return imagefromdata(imgbuffer, imgsize); 913 return imagefromdata(imgbuffer, imgsize);
914 } 914 }
915} 915}
916 916
917linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString& wrd, QString&) 917linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString& wrd, QString&)
918{ 918{
919 visited.push_front(n); 919 visited.push_front(n);
920 UInt16 tuid = (n >> 16); 920 UInt16 tuid = (n >> 16);
921 n &= 0xffff; 921 n &= 0xffff;
922 char *turl = geturl(tuid); 922 char *turl = geturl(tuid);
923 if (turl != NULL) 923 if (turl != NULL)
924 { 924 {
925 qDebug("URL in PB:%s", turl); 925 qDebug("URL in PB:%s", turl);
926 wrd = turl; 926 wrd = turl;
927 delete [] turl; 927 delete [] turl;
928 } 928 }
929 else 929 else
930 { 930 {
931 wrd.truncate(0); 931 wrd.truncate(0);
932 } 932 }
933 qDebug("Hyper: UID:%u, Para:%u, Offset:%u", tuid, n, offset); 933 qDebug("Hyper: UID:%u, Para:%u, Offset:%u", tuid, n, offset);
934 UInt16 thisrec = 1; 934 UInt16 thisrec = 1;
935 currentpos = 0; 935 currentpos = 0;
936 gotorecordnumber(thisrec); 936 gotorecordnumber(thisrec);
937 UInt16 thishdr_uid, thishdr_nParagraphs; 937 UInt16 thishdr_uid, thishdr_nParagraphs;
938 UInt32 thishdr_size; 938 UInt32 thishdr_size;
939 UInt8 thishdr_type, thishdr_reserved; 939 UInt8 thishdr_type, thishdr_reserved;
940 while (1) 940 while (1)
941 { 941 {
942 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 942 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
943 if (tuid == thishdr_uid) break; 943 if (tuid == thishdr_uid) break;
944 if (thishdr_type < 2) currentpos += thishdr_size; 944 if (thishdr_type < 2) currentpos += thishdr_size;
945 ////qDebug("hyper-cp:%u", currentpos); 945 ////qDebug("hyper-cp:%u", currentpos);
946 thisrec++; 946 thisrec++;
947 if (thisrec >= ntohs(head.recordList.numRecords)) 947 if (thisrec >= ntohs(head.recordList.numRecords))
948 { 948 {
949 if (wrd.isEmpty()) 949 if (wrd.isEmpty())
950 { 950 {
951 QMessageBox::information(NULL, 951 QMessageBox::information(NULL,
952 QString(PROGNAME), 952 QString(PROGNAME),
953 QString("Couldn't find link") 953 QString("Couldn't find link")
954 ); 954 );
955 } 955 }
956 else 956 else
957 { 957 {
958#ifdef USEQPE 958#ifdef USEQPE
959 if (wrd.length() > 10) 959 if (wrd.length() > 10)
960 { 960 {
961 Global::statusMessage(wrd.left(8) + ".."); 961 Global::statusMessage(wrd.left(8) + "..");
962 } 962 }
963 else 963 else
964 { 964 {
965 Global::statusMessage(wrd); 965 Global::statusMessage(wrd);
966 } 966 }
967#else 967#else
968#endif /* USEQPE */ 968#endif /* USEQPE */
969 //qDebug("Link:%s", (const char*)wrd); 969 //qDebug("Link:%s", (const char*)wrd);
970 // setlink(fn, wrd); 970 // setlink(fn, wrd);
971 } 971 }
972 return eNone; 972 return eNone;
973 } 973 }
974 gotorecordnumber(thisrec); 974 gotorecordnumber(thisrec);
975 } 975 }
976 if (thishdr_type > 1) 976 if (thishdr_type > 1)
977 { 977 {
978 if (thishdr_type == 4) 978 if (thishdr_type == 4)
979 { 979 {
980 QMessageBox::information(NULL, 980 QMessageBox::information(NULL,
981 QString(PROGNAME), 981 QString(PROGNAME),
982 QString("Mailto links\nnot yet supported (2)")); 982 QString("Mailto links\nnot yet supported (2)"));
983 } 983 }
984 else 984 else
985 { 985 {
986 if (thishdr_type > 3 && thishdr_type != 15) 986 if (thishdr_type > 3 && thishdr_type != 15)
987 { 987 {
988 QMessageBox::information(NULL, 988 QMessageBox::information(NULL,
989 QString(PROGNAME), 989 QString(PROGNAME),
990 QString("External links\nnot yet supported (2)") 990 QString("External links\nnot yet supported (2)")
991 ); 991 );
992 return eNone; 992 return eNone;
993 } 993 }
994 else 994 else
995 { 995 {
996#ifdef LOCALPICTURES 996#ifdef LOCALPICTURES
997 showimg(tuid); 997 showimg(tuid);
998#else 998#else
999 return ePicture; 999 return ePicture;
1000#endif 1000#endif
1001 } 1001 }
1002 } 1002 }
1003 return eNone; 1003 return eNone;
1004 } 1004 }
1005 /* 1005 /*
1006 if (thishdr_type == 2 || thishdr_type == 3) 1006 if (thishdr_type == 2 || thishdr_type == 3)
1007 { 1007 {
1008 expandimg(thisrec); 1008 expandimg(thisrec);
1009 1009
1010 } 1010 }
1011 */ 1011 */
1012 else 1012 else
1013 { 1013 {
1014 expand(thisrec); 1014 expand(thisrec);
1015 unsigned int paraoffset = offset; 1015 unsigned int paraoffset = offset;
1016 // unsigned int noff = 0; 1016 // unsigned int noff = 0;
1017 if (n != 0) 1017 if (n != 0)
1018 { 1018 {
1019 if (n >= m_nParas) 1019 if (n >= m_nParas)
1020 { 1020 {
1021 QMessageBox::information(NULL, 1021 QMessageBox::information(NULL,
1022 QString(PROGNAME), 1022 QString(PROGNAME),
1023 QString("Error in link\nPara # too big") 1023 QString("Error in link\nPara # too big")
1024 ); 1024 );
1025 return eNone; 1025 return eNone;
1026 } 1026 }
1027 unsigned int noff = 0; 1027 unsigned int noff = 0;
1028 for (unsigned int i = 0; i < n; i++) noff += m_ParaOffsets[i]; 1028 for (unsigned int i = 0; i < n; i++) noff += m_ParaOffsets[i];
1029 1029
1030 paraoffset += noff; 1030 paraoffset += noff;
1031 } 1031 }
1032 if (paraoffset > thishdr_size) 1032 if (paraoffset > thishdr_size)
1033 { 1033 {
1034 QMessageBox::information(NULL, 1034 QMessageBox::information(NULL,
1035 QString(PROGNAME), 1035 QString(PROGNAME),
1036 QString("Error in link\nOffset too big") 1036 QString("Error in link\nOffset too big")
1037 ); 1037 );
1038 return eNone; 1038 return eNone;
1039 } 1039 }
1040 while (bufferpos < paraoffset && bufferpos < buffercontent) getch_base(true); 1040 while (bufferpos < paraoffset && bufferpos < buffercontent) getch_base(true);
1041 //qDebug("Hyper:<%u,%u,%u>", paraoffset, bufferpos, currentpos); 1041 //qDebug("Hyper:<%u,%u,%u>", paraoffset, bufferpos, currentpos);
1042 /* // This is faster but the alignment doesn't get set 1042 /* // This is faster but the alignment doesn't get set
1043 mystyle.unset(); 1043 mystyle.unset();
1044 bufferpos = n; 1044 bufferpos = n;
1045 currentpos += n; 1045 currentpos += n;
1046 while (bufferpos >= m_nextPara && m_nextPara >= 0) 1046 while (bufferpos >= m_nextPara && m_nextPara >= 0)
1047 { 1047 {
1048 UInt16 attr = m_ParaAttrs[m_nextParaIndex]; 1048 UInt16 attr = m_ParaAttrs[m_nextParaIndex];
1049 m_nextParaIndex++; 1049 m_nextParaIndex++;
1050 if (m_nextParaIndex == m_nParas) 1050 if (m_nextParaIndex == m_nParas)
1051 { 1051 {
1052 m_nextPara = -1; 1052 m_nextPara = -1;
1053 } 1053 }
1054 else 1054 else
1055 { 1055 {
1056 m_nextPara += m_ParaOffsets[m_nextParaIndex]; 1056 m_nextPara += m_ParaOffsets[m_nextParaIndex];
1057 } 1057 }
1058 } 1058 }
1059 */ 1059 */
1060 } 1060 }
1061 return eLink; 1061 return eLink;
1062} 1062}
1063QString CPlucker_base::getTableAsHtml(unsigned long tgt) 1063QString CPlucker_base::getTableAsHtml(unsigned long tgt)
1064{ 1064{
1065 qDebug("CPlucker_base::getTableAsHtml:%u", tgt); 1065 qDebug("CPlucker_base::getTableAsHtml:%u", tgt);
1066 size_t reclen; 1066 size_t reclen;
1067 UInt16 thisrec = finduid(tgt); 1067 UInt16 thisrec = finduid(tgt);
1068 qDebug("getimg:Found %u from uid:%u", thisrec, tgt); 1068 qDebug("getimg:Found %u from uid:%u", thisrec, tgt);
1069 reclen = recordlength(thisrec); 1069 reclen = recordlength(thisrec);
1070 gotorecordnumber(thisrec); 1070 gotorecordnumber(thisrec);
1071 UInt16 thishdr_uid, thishdr_nParagraphs; 1071 UInt16 thishdr_uid, thishdr_nParagraphs;
1072 UInt32 thishdr_size; 1072 UInt32 thishdr_size;
1073 UInt8 thishdr_type, thishdr_reserved; 1073 UInt8 thishdr_type, thishdr_reserved;
1074 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); 1074 GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
1075 qDebug("Found a table of type:%u", thishdr_type); 1075 qDebug("Found a table of type:%u", thishdr_type);
1076 reclen -= HeaderSize(); 1076 reclen -= HeaderSize();
1077 UInt32 imgsize = thishdr_size; 1077 UInt32 imgsize = thishdr_size;
1078 UInt8* imgbuffer = new UInt8[imgsize]; 1078 UInt8* imgbuffer = new UInt8[imgsize];
1079 Expand(reclen, thishdr_type, imgbuffer, imgsize); 1079 Expand(reclen, thishdr_type, imgbuffer, imgsize);
1080 1080
1081 QString ret; 1081 QString ret;
1082 1082
1083 UInt16 size, columns, rows; 1083 UInt16 size, columns, rows;
1084 UInt8 depth, border; 1084 UInt8 depth, border;
1085 UInt32 borderColour, linkColour; 1085 UInt32 borderColour, linkColour;
1086 UInt8* dp(imgbuffer); 1086 UInt8* dp(imgbuffer);
1087 1087
1088 memcpy(&size, dp, sizeof(size)); 1088 memcpy(&size, dp, sizeof(size));
1089 size = ntohs(size); 1089 size = ntohs(size);
1090 dp += sizeof(size); 1090 dp += sizeof(size);
1091 memcpy(&columns, dp, sizeof(columns)); 1091 memcpy(&columns, dp, sizeof(columns));
1092 columns = ntohs(columns); 1092 columns = ntohs(columns);
1093 dp += sizeof(columns); 1093 dp += sizeof(columns);
1094 memcpy(&rows, dp, sizeof(rows)); 1094 memcpy(&rows, dp, sizeof(rows));
1095 rows = ntohs(rows); 1095 rows = ntohs(rows);
1096 dp += sizeof(rows); 1096 dp += sizeof(rows);
1097 qDebug("Rows:%u Cols:%u", rows, columns); 1097 qDebug("Rows:%u Cols:%u", rows, columns);
1098 1098
1099 memcpy(&depth, dp, sizeof(depth)); 1099 memcpy(&depth, dp, sizeof(depth));
1100 dp += sizeof(depth); 1100 dp += sizeof(depth);
1101 memcpy(&border, dp, sizeof(border)); 1101 memcpy(&border, dp, sizeof(border));
1102 dp += sizeof(border); 1102 dp += sizeof(border);
1103 1103
1104 qDebug("Depth:%u, Border:%u", depth, border); 1104 qDebug("Depth:%u, Border:%u", depth, border);
1105 1105
1106 memcpy(&borderColour, dp, sizeof(borderColour)); 1106 memcpy(&borderColour, dp, sizeof(borderColour));
1107 dp += sizeof(borderColour); 1107 dp += sizeof(borderColour);
1108 memcpy(&linkColour, dp, sizeof(linkColour)); 1108 memcpy(&linkColour, dp, sizeof(linkColour));
1109 dp += sizeof(linkColour); 1109 dp += sizeof(linkColour);
1110 1110
1111 qDebug("Colours: border:%x, link:%x", borderColour, linkColour); 1111 qDebug("Colours: border:%x, link:%x", borderColour, linkColour);
1112 1112
1113 if (border) 1113 if (border)
1114 { 1114 {
1115 ret = "<table border>"; 1115 ret = "<table border>";
1116 } 1116 }
1117 else 1117 else
1118 { 1118 {
1119 ret = "<table>"; 1119 ret = "<table>";
1120 } 1120 }
1121 bool firstrow = true; 1121 bool firstrow = true;
1122 bool firstcol = true; 1122 bool firstcol = true;
1123 while (dp < imgbuffer+imgsize) 1123 while (dp < imgbuffer+imgsize)
1124 { 1124 {
1125 UInt8 ch = *dp++; 1125 UInt8 ch = *dp++;
1126 if (ch == 0x00) 1126 if (ch == 0x00)
1127 { 1127 {
1128 ch = *dp++; 1128 ch = *dp++;
1129 if (ch == 0x90) 1129 if (ch == 0x90)
1130 { 1130 {
1131 if (firstrow) 1131 if (firstrow)
1132 { 1132 {
1133 ret += "<tr>"; 1133 ret += "<tr>";
1134 firstrow = false; 1134 firstrow = false;
1135 firstcol = true; 1135 firstcol = true;
1136 } 1136 }
1137 else 1137 else
1138 { 1138 {
1139 ret += "</tr><tr>"; 1139 ret += "</tr><tr>";
1140 } 1140 }
1141 } 1141 }
1142 else if (ch == 0x97) 1142 else if (ch == 0x97)
1143 { 1143 {
1144 if (firstcol) 1144 if (firstcol)
1145 { 1145 {
1146 ret += "<td"; 1146 ret += "<td";
1147 firstcol = false; 1147 firstcol = false;
1148 } 1148 }
1149 else 1149 else
1150 { 1150 {
1151 ret += "</td><td"; 1151 ret += "</td><td";
1152 } 1152 }
1153 UInt8 align; 1153 UInt8 align;
1154 UInt16 imgid; 1154 UInt16 imgid;
1155 UInt8 cols, rows; 1155 UInt8 cols, rows;
1156 UInt16 len; 1156 UInt16 len;
1157 memcpy(&align, dp, sizeof(align)); 1157 memcpy(&align, dp, sizeof(align));
1158 dp += sizeof(align); 1158 dp += sizeof(align);
1159 memcpy(&imgid, dp, sizeof(imgid)); 1159 memcpy(&imgid, dp, sizeof(imgid));
1160 dp += sizeof(imgid); 1160 dp += sizeof(imgid);
1161 imgid = ntohs(imgid); 1161 imgid = ntohs(imgid);
1162 memcpy(&cols, dp, sizeof(cols)); 1162 memcpy(&cols, dp, sizeof(cols));
1163 dp += sizeof(cols); 1163 dp += sizeof(cols);
1164 memcpy(&rows, dp, sizeof(rows)); 1164 memcpy(&rows, dp, sizeof(rows));
1165 dp += sizeof(rows); 1165 dp += sizeof(rows);
1166 memcpy(&len, dp, sizeof(len)); 1166 memcpy(&len, dp, sizeof(len));
1167 dp += sizeof(len); 1167 dp += sizeof(len);
1168 len = ntohs(len); 1168 len = ntohs(len);
1169 switch (align) 1169 switch (align)
1170 { 1170 {
1171 case 1: 1171 case 1:
1172 ret += " align=right"; 1172 ret += " align=right";
1173 break; 1173 break;
1174 case 2: 1174 case 2:
1175 ret += " align=center"; 1175 ret += " align=center";
1176 break; 1176 break;
1177 case 3: 1177 case 3:
1178 ret += " align=justify"; 1178 ret += " align=justify";
1179 break; 1179 break;
1180 case 0: 1180 case 0:
1181 break; 1181 break;
1182 default: 1182 default:
1183 qDebug("Unknown table cell alignment:%u", align); 1183 qDebug("Unknown table cell alignment:%u", align);
1184 } 1184 }
1185 if (cols != 1) 1185 if (cols != 1)
1186 { 1186 {
1187 QString num; 1187 QString num;
1188 num.setNum(cols); 1188 num.setNum(cols);
1189 ret += " colspan="; 1189 ret += " colspan=";
1190 ret += num; 1190 ret += num;
1191 } 1191 }
1192 if (rows != 1) 1192 if (rows != 1)
1193 { 1193 {
1194 QString num; 1194 QString num;
1195 num.setNum(rows); 1195 num.setNum(rows);
1196 ret += " rowspan="; 1196 ret += " rowspan=";
1197 ret += num; 1197 ret += num;
1198 } 1198 }
1199 ret += ">"; 1199 ret += ">";
1200 } 1200 }
1201 else 1201 else
1202 { 1202 {
1203 dp += (ch & 7); 1203 dp += (ch & 7);
1204 } 1204 }
1205 } 1205 }
1206 else 1206 else
1207 { 1207 {
1208 ret += QChar(ch); 1208 ret += QChar(ch);
1209 } 1209 }
1210 } 1210 }
1211 1211
1212 ret += "</td></tr></table>"; 1212 ret += "</td></tr></table>";
1213 delete [] imgbuffer; 1213 delete [] imgbuffer;
1214 return ret; 1214 return ret;
1215} 1215}
1216 1216
1217tchar CPlucker_base::getch_base(bool fast) 1217tchar CPlucker_base::getch_base(bool fast)
1218{ 1218{
1219 mystyle.setTable(0xffffffff); 1219 mystyle.setTable(0xffffffff);
1220 int ch = bgetch(); 1220 int ch = bgetch();
1221 while (ch == 0) 1221 while (ch == 0)
1222 { 1222 {
1223 ch = bgetch(); 1223 ch = bgetch();
1224 ////qDebug("Function:%x", ch); 1224 ////qDebug("Function:%x", ch);
1225 switch (ch) 1225 switch (ch)
1226 { 1226 {
1227 case 0x38: 1227 case 0x38:
1228 // //qDebug("Break:%u", locate()); 1228 // //qDebug("Break:%u", locate());
1229 if (m_lastBreak == locate()) 1229 if (m_lastBreak == locate())
1230 { 1230 {
1231 ch = bgetch(); 1231 ch = bgetch();
1232 } 1232 }
1233 else 1233 else
1234 { 1234 {
1235 ch = 10; 1235 ch = 10;
1236 } 1236 }
1237 m_lastBreak = locate(); 1237 m_lastBreak = locate();
1238 break; 1238 break;
1239 case 0x0a: 1239 case 0x0a:
1240 case 0x0c: 1240 case 0x0c:
1241 { 1241 {
1242 unsigned long ln = 0; 1242 unsigned long ln = 0;
1243 int skip = ch & 7; 1243 int skip = ch & 7;
1244 for (int i = 0; i < 2; i++) 1244 for (int i = 0; i < 2; i++)
1245 { 1245 {
1246 int ch = bgetch(); 1246 int ch = bgetch();
1247 ln = (ln << 8) + ch; 1247 ln = (ln << 8) + ch;
1248 // //qDebug("ch:%d, ln:%u", ch, ln); 1248 // //qDebug("ch:%d, ln:%u", ch, ln);
1249 } 1249 }
1250 if (skip == 2) 1250 if (skip == 2)
1251 { 1251 {
1252 ln <<= 16; 1252 ln <<= 16;
1253 } 1253 }
1254 else 1254 else
1255 { 1255 {
1256 for (int i = 0; i < 2; i++) 1256 for (int i = 0; i < 2; i++)
1257 { 1257 {
1258 int ch = bgetch(); 1258 int ch = bgetch();
1259 ln = (ln << 8) + ch; 1259 ln = (ln << 8) + ch;
1260 // //qDebug("ch:%d, ln:%u", ch, ln); 1260 // //qDebug("ch:%d, ln:%u", ch, ln);
1261 } 1261 }
1262 } 1262 }
1263 // //qDebug("ln:%u", ln); 1263 // //qDebug("ln:%u", ln);
1264 mystyle.setLink(true); 1264 mystyle.setLink(true);
1265 mystyle.setData(ln); 1265 mystyle.setData(ln);
1266 // mystyle.setColour(255, 0, 0); 1266 // mystyle.setColour(255, 0, 0);
1267 bool hasseen = false; 1267 bool hasseen = false;
1268 for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) 1268 for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++)
1269 { 1269 {
1270 if (*it == ln) 1270 if (*it == ln)
1271 { 1271 {
1272 hasseen = true; 1272 hasseen = true;
1273 break; 1273 break;
1274 } 1274 }
1275 } 1275 }
1276 if (hasseen) 1276 if (hasseen)
1277 { 1277 {
1278 mystyle.setStrikethru(); 1278 mystyle.setStrikethru();
1279 } 1279 }
1280 mystyle.setOffset(m_offset); 1280 mystyle.setOffset(m_offset);
1281 m_offset = 0; 1281 m_offset = 0;
1282 ch = bgetch(); 1282 ch = bgetch();
1283 } 1283 }
1284 break; 1284 break;
1285 case 0x08: 1285 case 0x08:
1286 ch = bgetch(); 1286 ch = bgetch();
1287 // mystyle.setColour(0, 0, 0); 1287 // mystyle.setColour(0, 0, 0);
1288 mystyle.unsetUnderline(); 1288 mystyle.unsetUnderline();
1289 mystyle.unsetStrikethru(); 1289 mystyle.unsetStrikethru();
1290 mystyle.setLink(false); 1290 mystyle.setLink(false);
1291 mystyle.setData(0); 1291 mystyle.setData(0);
1292 break; 1292 break;
1293 case 0x40: 1293 case 0x40:
1294 mystyle.setItalic(); 1294 mystyle.setItalic();
1295 ch = bgetch(); 1295 ch = bgetch();
1296 break; 1296 break;
1297 case 0x48: 1297 case 0x48:
1298 mystyle.unsetItalic(); 1298 mystyle.unsetItalic();
1299 ch = bgetch(); 1299 ch = bgetch();
1300 break; 1300 break;
1301 case 0x11: 1301 case 0x11:
1302 { 1302 {
1303 ch = bgetch(); 1303 ch = bgetch();
1304 // //qDebug("Font:%d",ch); 1304 // //qDebug("Font:%d",ch);
1305 mystyle.setVOffset(0); 1305 mystyle.setVOffset(0);
1306 mystyle.unsetMono(); 1306 mystyle.unsetMono();
1307 mystyle.unsetBold(); 1307 mystyle.unsetBold();
1308 switch (ch) 1308 switch (ch)
1309 { 1309 {
1310 case 0: 1310 case 0:
1311 mystyle.setFontSize(0); 1311 mystyle.setFontSize(0);
1312 break; 1312 break;
1313 case 1: 1313 case 1:
1314 mystyle.setFontSize(3); 1314 mystyle.setFontSize(3);
1315 mystyle.setBold(); 1315 mystyle.setBold();
1316 break; 1316 break;
1317 case 2: 1317 case 2:
1318 mystyle.setFontSize(2); 1318 mystyle.setFontSize(2);
1319 mystyle.setBold(); 1319 mystyle.setBold();
1320 break; 1320 break;
1321 case 3: 1321 case 3:
1322 mystyle.setFontSize(1); 1322 mystyle.setFontSize(1);
1323 mystyle.setBold(); 1323 mystyle.setBold();
1324 break; 1324 break;
1325 case 4: 1325 case 4:
1326 mystyle.setFontSize(0); 1326 mystyle.setFontSize(0);
1327 mystyle.setBold(); 1327 mystyle.setBold();
1328 break; 1328 break;
1329 case 5: 1329 case 5:
1330 mystyle.setFontSize(0); 1330 mystyle.setFontSize(0);
1331 mystyle.setBold(); 1331 mystyle.setBold();
1332 break; 1332 break;
1333 case 6: 1333 case 6:
1334 mystyle.setFontSize(0); 1334 mystyle.setFontSize(0);
1335 mystyle.setBold(); 1335 mystyle.setBold();
1336 break; 1336 break;
1337 case 7: 1337 case 7:
1338 mystyle.setFontSize(0); 1338 mystyle.setFontSize(0);
1339 mystyle.setBold(); 1339 mystyle.setBold();
1340 break; 1340 break;
1341 case 8: // should be fixed width 1341 case 8: // should be fixed width
1342 //qDebug("Trying fixed width"); 1342 //qDebug("Trying fixed width");
1343 mystyle.setFontSize(0); 1343 mystyle.setFontSize(0);
1344 mystyle.setMono(); 1344 mystyle.setMono();
1345 break; 1345 break;
1346 case 9: 1346 case 9:
1347 // mystyle.setFontSize(mystyle.getFontSize()); 1347 // mystyle.setFontSize(mystyle.getFontSize());
1348 mystyle.setFontSize(-1); 1348 mystyle.setFontSize(-1);
1349 break; 1349 break;
1350 case 10: 1350 case 10:
1351 mystyle.setFontSize(-2); 1351 mystyle.setFontSize(-2);
1352 mystyle.setVOffset(1); 1352 mystyle.setVOffset(1);
1353 break; 1353 break;
1354 case 11: 1354 case 11:
1355 mystyle.setFontSize(-2); 1355 mystyle.setFontSize(-2);
1356 mystyle.setVOffset(-1); 1356 mystyle.setVOffset(-1);
1357 break; 1357 break;
1358 default: 1358 default:
1359 qDebug("Unrecognised font"); 1359 qDebug("Unrecognised font");
1360 break; 1360 break;
1361 } 1361 }
1362 ch = bgetch(); 1362 ch = bgetch();
1363 } 1363 }
1364 break; 1364 break;
1365 case 0x29: 1365 case 0x29:
1366 ch = bgetch(); 1366 ch = bgetch();
1367 switch (ch) 1367 switch (ch)
1368 { 1368 {
1369 case 0: 1369 case 0:
1370 mystyle.setLeftJustify(); 1370 mystyle.setLeftJustify();
1371 // //qDebug("left"); 1371 // //qDebug("left");
1372 break; 1372 break;
1373 case 1: 1373 case 1:
1374 mystyle.setRightJustify(); 1374 mystyle.setRightJustify();
1375 // //qDebug("right"); 1375 // //qDebug("right");
1376 break; 1376 break;
1377 case 2: 1377 case 2:
1378 mystyle.setCentreJustify(); 1378 mystyle.setCentreJustify();
1379 // //qDebug("centre"); 1379 // //qDebug("centre");
1380 break; 1380 break;
1381 case 3: 1381 case 3:
1382 mystyle.setFullJustify(); 1382 mystyle.setFullJustify();
1383 // //qDebug("full"); 1383 // //qDebug("full");
1384 break; 1384 break;
1385 1385
1386 } 1386 }
1387 ch = bgetch(); 1387 ch = bgetch();
1388 break; 1388 break;
1389 case 0x53: 1389 case 0x53:
1390 { 1390 {
1391 int r = bgetch(); 1391 int r = bgetch();
1392 int g = bgetch(); 1392 int g = bgetch();
1393 int b = bgetch(); 1393 int b = bgetch();
1394 mystyle.setColour(r,g,b); 1394 mystyle.setColour(r,g,b);
1395 ch = bgetch(); 1395 ch = bgetch();
1396 } 1396 }
1397 break; 1397 break;
1398 case 0x1a: 1398 case 0x1a:
1399 case 0x5c: 1399 case 0x5c:
1400 { 1400 {
1401 bool hasalternate = (ch == 0x5c); 1401 bool hasalternate = (ch == 0x5c);
1402 UInt16 ir = bgetch(); 1402 UInt16 ir = bgetch();
1403 ir = (ir << 8) + bgetch(); 1403 ir = (ir << 8) + bgetch();
1404 if (hasalternate) 1404 if (hasalternate)
1405 { 1405 {
1406 //qDebug("Alternate image:%x", ir); 1406 //qDebug("Alternate image:%x", ir);
1407 UInt16 ir2 = bgetch(); 1407 UInt16 ir2 = bgetch();
1408 ir2 = (ir2 << 8) + bgetch(); 1408 ir2 = (ir2 << 8) + bgetch();
1409 if (!fast) mystyle.setPicture(true, expandimg(ir2, true), true, ir << 16); 1409 if (!fast) mystyle.setPicture(true, expandimg(ir2, true), true, ir << 16);
1410#ifdef LOCALPICTURES 1410#ifdef LOCALPICTURES
1411 UInt32 ln = ir; 1411 UInt32 ln = ir;
1412 ln <<= 16; 1412 ln <<= 16;
1413 mystyle.setLink(true); 1413 mystyle.setLink(true);
1414 mystyle.setData(ln); 1414 mystyle.setData(ln);
1415#endif 1415#endif
1416 } 1416 }
1417 else 1417 else
1418 { 1418 {
1419 if (!fast) mystyle.setPicture(true, expandimg(ir)); 1419 if (!fast) mystyle.setPicture(true, expandimg(ir));
1420 } 1420 }
1421 // if (mystyle.getLink()) qDebug("Picture link!"); 1421 // if (mystyle.getLink()) qDebug("Picture link!");
1422 ch = '#'; 1422 ch = '#';
1423 } 1423 }
1424 // ch = bgetch(); 1424 // ch = bgetch();
1425 break; 1425 break;
1426 case 0x33: 1426 case 0x33:
1427 { 1427 {
1428 UInt8 h = bgetch(); 1428 UInt8 h = bgetch();
1429 UInt8 wc = bgetch(); 1429 UInt8 wc = bgetch();
1430 UInt8 pc = bgetch(); 1430 UInt8 pc = bgetch();
1431 UInt16 w = wc; 1431 UInt16 w = wc;
1432 // //qDebug("h,w,pc [%u, %u, %u]", h, w, pc); 1432 // //qDebug("h,w,pc [%u, %u, %u]", h, w, pc);
1433 if (w == 0) 1433 if (w == 0)
1434 { 1434 {
1435 w = (m_scrWidth*(unsigned long)pc)/100; 1435 w = (m_scrWidth*(unsigned long)pc)/100;
1436 } 1436 }
1437 if (w == 0) w = m_scrWidth; 1437 if (w == 0) w = m_scrWidth;
1438 mystyle.setPicture(false, hRule(w,h,mystyle.Red(),mystyle.Green(),mystyle.Blue())); 1438 mystyle.setPicture(false, hRule(w,h,mystyle.Red(),mystyle.Green(),mystyle.Blue()));
1439 // if (mystyle.getLink()) //qDebug("hRule link!"); 1439 // if (mystyle.getLink()) //qDebug("hRule link!");
1440 ch = '#'; 1440 ch = '#';
1441 } 1441 }
1442 break; 1442 break;
1443 case 0x60: 1443 case 0x60:
1444 mystyle.setUnderline(); 1444 mystyle.setUnderline();
1445 ch = bgetch(); 1445 ch = bgetch();
1446 break; 1446 break;
1447 case 0x68: 1447 case 0x68:
1448 mystyle.unsetUnderline(); 1448 mystyle.unsetUnderline();
1449 ch = bgetch(); 1449 ch = bgetch();
1450 break; 1450 break;
1451 case 0x22: 1451 case 0x22:
1452 ch = bgetch(); 1452 ch = bgetch();
1453 mystyle.setLeftMargin(ch); 1453 mystyle.setLeftMargin(ch);
1454 // //qDebug("Left margin:%d", ch); 1454 // //qDebug("Left margin:%d", ch);
1455 ch = bgetch(); 1455 ch = bgetch();
1456 mystyle.setRightMargin(ch); 1456 mystyle.setRightMargin(ch);
1457 // //qDebug("Right margin:%d", ch); 1457 // //qDebug("Right margin:%d", ch);
1458 ch = bgetch(); 1458 ch = bgetch();
1459 break; 1459 break;
1460 case 0x70: 1460 case 0x70:
1461 mystyle.setStrikethru(); 1461 mystyle.setStrikethru();
1462 ch = bgetch(); 1462 ch = bgetch();
1463 break; 1463 break;
1464 case 0x78: 1464 case 0x78:
1465 mystyle.unsetStrikethru(); 1465 mystyle.unsetStrikethru();
1466 ch = bgetch(); 1466 ch = bgetch();
1467 break; 1467 break;
1468 case 0x83: 1468 case 0x83:
1469 { 1469 {
1470 int tlen = bgetch(); 1470 int tlen = bgetch();
1471 ch = bgetch(); 1471 ch = bgetch();
1472 ch <<= 8; 1472 ch <<= 8;
1473 ch |= (tchar)bgetch(); 1473 ch |= (tchar)bgetch();
1474 for (int i = 0; i < tlen; i++) bgetch(); 1474 for (int i = 0; i < tlen; i++) bgetch();
1475 //qDebug("Function 83"); 1475 //qDebug("Function 83");
1476 } 1476 }
1477 break; 1477 break;
1478 case 0x9a: 1478 case 0x9a:
1479 { 1479 {
1480 m_offset = 255*bgetch(); 1480 m_offset = 255*bgetch();
1481 m_offset += bgetch(); 1481 m_offset += bgetch();
1482 qDebug("Found offset:%u", m_offset); 1482 qDebug("Found offset:%u", m_offset);
1483 ch = bgetch(); 1483 ch = bgetch();
1484 } 1484 }
1485 break; 1485 break;
1486 case 0x92: 1486 case 0x92:
1487 { 1487 {
1488 ch = bgetch(); 1488 ch = bgetch();
1489 ch <<= 8; 1489 ch <<= 8;
1490 ch |= (tchar)bgetch(); 1490 ch |= (tchar)bgetch();
1491 mystyle.setTable(ch); 1491 mystyle.setTable(ch);
1492 ch = 0x16e5; 1492 ch = 0x16e5;
1493 } 1493 }
1494 break; 1494 break;
1495 case 0x85: 1495 case 0x85:
1496 default: 1496 default:
1497 qDebug("Function:%x NOT IMPLEMENTED", ch); 1497 qDebug("Function:%x NOT IMPLEMENTED", ch);
1498 { 1498 {
1499 int skip = ch & 7; 1499 int skip = ch & 7;
1500 for (int i = 0; i < skip; i++) 1500 for (int i = 0; i < skip; i++)
1501 { 1501 {
1502 ch = bgetch(); 1502 ch = bgetch();
1503 //qDebug("Arg %d, %d", i, ch); 1503 //qDebug("Arg %d, %d", i, ch);
1504 } 1504 }
1505 ch = bgetch(); 1505 ch = bgetch();
1506 } 1506 }
1507 } 1507 }
1508 } 1508 }
1509 1509
1510 if (m_lastIsBreak && !mystyle.isMono()) 1510 if (m_lastIsBreak && !mystyle.isMono())
1511 { 1511 {
1512 while (ch == ' ') 1512 while (ch == ' ')
1513 { 1513 {
1514 ch = getch(false); 1514 ch = getch(false);
1515 } 1515 }
1516 } 1516 }
1517 1517
1518 m_lastIsBreak = (ch == 10); 1518 m_lastIsBreak = (ch == 10);
1519 1519
1520 return (ch == EOF) ? UEOF : ch; 1520 return (ch == EOF) ? UEOF : ch;
1521} 1521}
1522 1522
1523QString CPlucker_base::about() 1523QString CPlucker_base::about()
1524{ 1524{
1525 QString abt = "Plucker base codec (c) Tim Wentford"; 1525 QString abt = "Plucker base codec (c) Tim Wentford";
1526 if (m_decompress != UnDoc && m_decompress != UnZip) 1526 if (m_decompress != UnDoc && m_decompress != UnZip)
1527 { 1527 {
1528 abt += "\nSpecial decompression (c) Tim Wentford (ppmd by Dmitry Shkarin"; 1528 abt += "\nSpecial decompression (c) Tim Wentford (ppmd by Dmitry Shkarin";
1529 } 1529 }
1530 return abt; 1530 return abt;
1531} 1531}
diff --git a/noncore/apps/opie-reader/striphtml.cpp b/noncore/apps/opie-reader/striphtml.cpp
index c434dbb..a2ad56b 100644
--- a/noncore/apps/opie-reader/striphtml.cpp
+++ b/noncore/apps/opie-reader/striphtml.cpp
@@ -1,1414 +1,1414 @@
1#include <qmap.h> 1#include <qmap.h>
2#include <qfileinfo.h> 2#include <qfileinfo.h>
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <qdir.h> 4#include <qdir.h>
5#ifdef USEQPE 5#ifdef USEQPE
6#include <qpe/global.h> 6#include <qpe/global.h>
7#endif 7#endif
8#include "CDrawBuffer.h" 8#include "CDrawBuffer.h"
9#include "striphtml.h" 9#include "striphtml.h"
10#include "hrule.h" 10#include "hrule.h"
11 11
12#include <qregexp.h> 12#include <qregexp.h>
13#include <qimage.h> 13#include <qimage.h>
14#include <qpixmap.h> 14#include <qpixmap.h>
15//#include <qprogressdialog.h> 15//#include <qprogressdialog.h>
16//#include <qapplication.h> 16//#include <qapplication.h>
17 17
18static unsigned char h2i(unsigned char c) 18static unsigned char h2i(unsigned char c)
19{ 19{
20 unsigned char ret = 0; 20 unsigned char ret = 0;
21 if ('0' <= c && c <= '9') 21 if ('0' <= c && c <= '9')
22 { 22 {
23 ret = c - '0'; 23 ret = c - '0';
24 } 24 }
25 else if ('a' <= c && c <= 'f') 25 else if ('a' <= c && c <= 'f')
26 { 26 {
27 ret = c - 'a' + 10; 27 ret = c - 'a' + 10;
28 } 28 }
29 return ret; 29 return ret;
30} 30}
31 31
32static void parse_color(const QString& attr, unsigned char& r, unsigned char& g, unsigned char& b) 32static void parse_color(const QString& attr, unsigned char& r, unsigned char& g, unsigned char& b)
33{ 33{
34 r = g = b = 0; 34 r = g = b = 0;
35 if (attr.length() >= 7 && attr[0] == '#') 35 if (attr.length() >= 7 && attr[0] == '#')
36 { 36 {
37 r = h2i(attr[1].unicode()); 37 r = h2i(attr[1].unicode());
38 r = 16*r + h2i(attr[2].unicode()); 38 r = 16*r + h2i(attr[2].unicode());
39 g = h2i(attr[3].unicode()); 39 g = h2i(attr[3].unicode());
40 g = 16*g + h2i(attr[4].unicode()); 40 g = 16*g + h2i(attr[4].unicode());
41 b = h2i(attr[5].unicode()); 41 b = h2i(attr[5].unicode());
42 b = 16*b + h2i(attr[6].unicode()); 42 b = 16*b + h2i(attr[6].unicode());
43 } 43 }
44 else if (attr == "red") 44 else if (attr == "red")
45 { 45 {
46 r = 255; 46 r = 255;
47 } 47 }
48 else if (attr == "green") 48 else if (attr == "green")
49 { 49 {
50 g = 255; 50 g = 255;
51 } 51 }
52 else if (attr == "blue") 52 else if (attr == "blue")
53 { 53 {
54 b = 255; 54 b = 255;
55 } 55 }
56 else if (attr == "white") 56 else if (attr == "white")
57 { 57 {
58 r = g = b = 255; 58 r = g = b = 255;
59 } 59 }
60 else if (attr == "black") 60 else if (attr == "black")
61 { 61 {
62 r = g = b = 0; 62 r = g = b = 0;
63 } 63 }
64 else 64 else
65 { 65 {
66 qDebug("Don't understand colour \"%s\"", (const char*)attr); 66 qDebug("Don't understand colour \"%s\"", (const char*)attr);
67 } 67 }
68} 68}
69 69
70CNavigation_base<htmlmark> striphtml::m_nav; 70CNavigation_base<htmlmark> striphtml::m_nav;
71 71
72void striphtml::skipblock(const QString& _ent) 72void striphtml::skipblock(const QString& _ent)
73{ 73{
74 tchar ch = '>'; 74 tchar ch = '>';
75 CStyle dummy; 75 CStyle dummy;
76 QString ent; 76 QString ent;
77 unsigned long pos; 77 unsigned long pos;
78 do 78 do
79 { 79 {
80 while (ch != '<' && ch != UEOF) 80 while (ch != '<' && ch != UEOF)
81 { 81 {
82 mygetch(ch, dummy, pos); 82 mygetch(ch, dummy, pos);
83 } 83 }
84 84
85 ch = skip_ws(); 85 ch = skip_ws();
86 86
87 ent = getname(ch, " >").lower(); 87 ent = getname(ch, " >").lower();
88 qDebug("Skipblock:%s", (const char*)ent); 88 qDebug("Skipblock:%s", (const char*)ent);
89 } while (ent != _ent && ch != UEOF); 89 } while (ent != _ent && ch != UEOF);
90} 90}
91 91
92void striphtml::reset() 92void striphtml::reset()
93{ 93{
94 m_inblock = false; 94 m_inblock = false;
95 text_q = ""; 95 text_q = "";
96 q = ""; 96 q = "";
97 tablenesteddepth = 0; 97 tablenesteddepth = 0;
98 forcecentre = false; 98 forcecentre = false;
99 ignorespace = false; 99 ignorespace = false;
100 indent = 0; 100 indent = 0;
101 while (!stylestack.isEmpty()) stylestack.pop(); 101 while (!stylestack.isEmpty()) stylestack.pop();
102 currentstyle.unset(); 102 currentstyle.unset();
103} 103}
104 104
105void striphtml::locate(unsigned int n) 105void striphtml::locate(unsigned int n)
106{ 106{
107 qDebug("striphtml:locating:%u", n); 107 qDebug("striphtml:locating:%u", n);
108 reset(); 108 reset();
109 parent->locate(n); 109 parent->locate(n);
110} 110}
111 111
112int striphtml::getpara(CBuffer& buff, unsigned long& startpos) 112int striphtml::getpara(CBuffer& buff, unsigned long& startpos)
113{ 113{
114 tchar ch; 114 tchar ch;
115 CStyle sty; 115 CStyle sty;
116 unsigned long pos; 116 unsigned long pos;
117 int i = 0; 117 int i = 0;
118 parent->getch(ch, sty, startpos); 118 parent->getch(ch, sty, startpos);
119 pos = startpos; 119 pos = startpos;
120 while (1) 120 while (1)
121 { 121 {
122 if (ch == 10 && !isPre) 122 if (ch == 10 && !isPre)
123 { 123 {
124 ch = ' '; 124 ch = ' ';
125 } 125 }
126 if (ch == UEOF) 126 if (ch == UEOF)
127 { 127 {
128 // qDebug("EOF:%d:%u", i, pos); 128 // qDebug("EOF:%d:%u", i, pos);
129 buff[i] = 0; 129 buff[i] = 0;
130 if (i == 0) 130 if (i == 0)
131 { 131 {
132 i = -1; 132 i = -1;
133 } 133 }
134 return i; 134 return i;
135 } 135 }
136 else if (ch == '<') 136 else if (ch == '<')
137 { 137 {
138 tchar ch2 = skip_ws(); 138 tchar ch2 = skip_ws();
139 QString ent = getname(ch2, " >"); 139 QString ent = getname(ch2, " >");
140 ent = ent.lower(); 140 ent = ent.lower();
141 // qDebug("ent:%s", (const char*)ent); 141 // qDebug("ent:%s", (const char*)ent);
142 if (ent == "a") 142 if (ent == "a")
143 { 143 {
144 buff[i++] = '<'; 144 buff[i++] = '<';
145 buff[i++] = 'a'; 145 buff[i++] = 'a';
146 buff[i++] = ch2; 146 buff[i++] = ch2;
147 // buff[i] = 0; qDebug("ANCHOR:%s", (const char*)toQString(buff.data())); 147 // buff[i] = 0; qDebug("ANCHOR:%s", (const char*)toQString(buff.data()));
148 } 148 }
149 else if (ent == "/a") 149 else if (ent == "/a")
150 { 150 {
151 buff[i++] = '<'; 151 buff[i++] = '<';
152 buff[i++] = '/'; 152 buff[i++] = '/';
153 buff[i++] = 'a'; 153 buff[i++] = 'a';
154 buff[i++] = ch2; 154 buff[i++] = ch2;
155 // buff[i] = 0; qDebug("/ANCHOR:%s", (const char*)toQString(buff.data())); 155 // buff[i] = 0; qDebug("/ANCHOR:%s", (const char*)toQString(buff.data()));
156 } 156 }
157 else if (ent == "div") 157 else if (ent == "div")
158 { 158 {
159 // buff[i] = 0; qDebug("DIV:%s", (const char*)toQString(buff.data())); 159 // buff[i] = 0; qDebug("DIV:%s", (const char*)toQString(buff.data()));
160 if (i == 0) 160 if (i == 0)
161 { 161 {
162 buff[i++] = '<'; 162 buff[i++] = '<';
163 buff[i++] = 'd'; 163 buff[i++] = 'd';
164 buff[i++] = 'i'; 164 buff[i++] = 'i';
165 buff[i++] = 'v'; 165 buff[i++] = 'v';
166 buff[i++] = ' '; 166 buff[i++] = ' ';
167 buff[i++] = ch2; 167 buff[i++] = ch2;
168 while (ch2 != '>' && ch2 != UEOF && i < 2048) 168 while (ch2 != '>' && ch2 != UEOF && i < 2048)
169 { 169 {
170 parent->getch(ch2, sty, pos); 170 parent->getch(ch2, sty, pos);
171 buff[i++] = ch2; 171 buff[i++] = ch2;
172 } 172 }
173 } 173 }
174 else 174 else
175 { 175 {
176 locate(pos); 176 locate(pos);
177 } 177 }
178 buff[i++] = 0; 178 buff[i++] = 0;
179 // qDebug("DIV:%s", (const char*)toQString(buff.data())); 179 // qDebug("DIV:%s", (const char*)toQString(buff.data()));
180 return i; 180 return i;
181 } 181 }
182 else if (ent == "p" || (ent[0] == 'h' && ent.length() == 2 && QString("123456789").find(ent[1]) != -1)) 182 else if (ent == "p" || (ent[0] == 'h' && ent.length() == 2 && QString("123456789").find(ent[1]) != -1))
183 { 183 {
184 buff[i++] = 0; 184 buff[i++] = 0;
185 while (ch2 != '>' && ch2 != UEOF) 185 while (ch2 != '>' && ch2 != UEOF)
186 { 186 {
187 parent->getch(ch2, sty, pos); 187 parent->getch(ch2, sty, pos);
188 } 188 }
189 return i; 189 return i;
190 } 190 }
191 else 191 else
192 { 192 {
193 while (ch2 != '>' && ch2 != UEOF) 193 while (ch2 != '>' && ch2 != UEOF)
194 { 194 {
195 parent->getch(ch2, sty, pos); 195 parent->getch(ch2, sty, pos);
196 } 196 }
197 } 197 }
198 } 198 }
199 else 199 else
200 { 200 {
201 buff[i++] = ch; 201 buff[i++] = ch;
202 } 202 }
203 parent->getch(ch, sty, pos); 203 parent->getch(ch, sty, pos);
204 } 204 }
205} 205}
206 206
207QString striphtml::dehtml(const QString& _info) 207QString striphtml::dehtml(const QString& _info)
208{ 208{
209 QString info; 209 QString info;
210 for (int i = 0; i < _info.length(); i++) 210 for (int i = 0; i < _info.length(); i++)
211 { 211 {
212 tchar ch = _info[i]; 212 tchar ch = _info[i];
213 if (ch == '%') 213 if (ch == '%')
214 { 214 {
215 ch = 0; 215 ch = 0;
216 for (int j = 0; j < 2; j++) 216 for (int j = 0; j < 2; j++)
217 { 217 {
218 ch <<= 4; 218 ch <<= 4;
219 tchar ch1 = _info[++i]; 219 tchar ch1 = _info[++i];
220 if ('0' <= ch1 && ch1 <= '9') 220 if ('0' <= ch1 && ch1 <= '9')
221 { 221 {
222 ch += ch1 - '0'; 222 ch += ch1 - '0';
223 } 223 }
224 else if ('a' <= ch1 && ch1 <= 'f') 224 else if ('a' <= ch1 && ch1 <= 'f')
225 { 225 {
226 ch += ch1 - 'a' + 10; 226 ch += ch1 - 'a' + 10;
227 } 227 }
228 else if ('A' <= ch1 && ch1 <= 'F') 228 else if ('A' <= ch1 && ch1 <= 'F')
229 { 229 {
230 ch += ch1 - 'A' + 10; 230 ch += ch1 - 'A' + 10;
231 } 231 }
232 } 232 }
233 } 233 }
234 info += ch; 234 info += ch;
235 } 235 }
236 return info; 236 return info;
237} 237}
238 238
239bool striphtml::findanchor(const QString& _info) 239bool striphtml::findanchor(const QString& _info)
240{ 240{
241 // QProgressDialog dlg("Finding link...", QString::null, 0, NULL, "progress", true); 241 // QProgressDialog dlg("Finding link...", QString::null, 0, NULL, "progress", true);
242 // QProgressBar dlg(0); 242 // QProgressBar dlg(0);
243 if (parent->findanchor(_info)) 243 if (parent->findanchor(_info))
244 { 244 {
245 reset(); 245 reset();
246 return true; 246 return true;
247 } 247 }
248 qDebug("Using html find"); 248 qDebug("Using html find");
249 parent->locate(parent->startSection()); 249 parent->locate(parent->startSection());
250#if defined(USEQPE) || defined(_WINDOWS) 250#if defined(USEQPE) || defined(_WINDOWS)
251 QString info; 251 QString info;
252 for (int i = 0; i < _info.length(); i++) 252 for (int i = 0; i < _info.length(); i++)
253 { 253 {
254 tchar ch = _info[i]; 254 tchar ch = _info[i];
255 if (QString(".^$[]*+?").find(ch) != -1) 255 if (QString(".^$[]*+?").find(ch) != -1)
256 { 256 {
257 info += '\\'; 257 info += '\\';
258 } 258 }
259 info += ch; 259 info += ch;
260 } 260 }
261#else 261#else
262 QString info = QRegExp::escape(_info); 262 QString info = QRegExp::escape(_info);
263#endif 263#endif
264 qDebug("Adjusted searchstring:%s", (const char*)info); 264 qDebug("Adjusted searchstring:%s", (const char*)info);
265 QString sname("<[Aa][^>]*[ \t]+[Nn][Aa][Mm][Ee][ \t]*=[ \t]*\"?"); 265 QString sname("<[Aa][^>]*[ \t]+[Nn][Aa][Mm][Ee][ \t]*=[ \t]*\"?");
266 sname += info + "\"?[ \t>]"; 266 sname += info + "\"?[ \t>]";
267 QString sid("<[A-Za-z][^>]*[ \t]+[Ii][Dd][ \t]*=[ \t]*\"?"); 267 QString sid("<[A-Za-z][^>]*[ \t]+[Ii][Dd][ \t]*=[ \t]*\"?");
268 sid += info+"\"?[ \t>]"; 268 sid += info+"\"?[ \t>]";
269#ifdef USEQPE 269#ifdef USEQPE
270 QRegExp name(sname); 270 QRegExp name(sname);
271 QRegExp id(sid); 271 QRegExp id(sid);
272#else 272#else
273 QRegExp name(sname+"|"+sid); 273 QRegExp name(sname+"|"+sid);
274#endif 274#endif
275 bool ret = true; 275 bool ret = true;
276 locate(0); 276 locate(0);
277 unsigned long pos = 0; 277 unsigned long pos = 0;
278 unsigned long startpos = 0; 278 unsigned long startpos = 0;
279 int offset; 279 int offset;
280 CBuffer test; 280 CBuffer test;
281 qDebug("striphtml::findanchor"); 281 qDebug("striphtml::findanchor");
282 // dlg.show(); 282 // dlg.show();
283 if (getpara(test, pos) >= 0) 283 if (getpara(test, pos) >= 0)
284 { 284 {
285 while (1) 285 while (1)
286 { 286 {
287 // qApp->processEvents(); 287 // qApp->processEvents();
288 if ((offset = name.match(toQString(test.data()))) != -1) break; 288 if ((offset = name.match(toQString(test.data()))) != -1) break;
289#ifdef USEQPE 289#ifdef USEQPE
290 if ((offset = id.match(toQString(test.data()))) != -1) break; 290 if ((offset = id.match(toQString(test.data()))) != -1) break;
291#endif 291#endif
292 if (getpara(test, pos) < 0) 292 if (getpara(test, pos) < 0)
293 { 293 {
294 locate(startpos); 294 locate(startpos);
295 qDebug("Not found"); 295 qDebug("Not found");
296 return false; 296 return false;
297 } 297 }
298 } 298 }
299 locate(pos); 299 locate(pos);
300 qDebug("Found"); 300 qDebug("Found");
301 ret = true; 301 ret = true;
302 } 302 }
303 else 303 else
304 { 304 {
305 locate(startpos); 305 locate(startpos);
306 qDebug("Not found"); 306 qDebug("Not found");
307 ret = false; 307 ret = false;
308 } 308 }
309 return ret; 309 return ret;
310} 310}
311 311
312striphtml::striphtml(const QString& _s) : entmap(NULL), isPre(false), currentid(0), lastch(0), currentfile(_s), indent(0), forcecentre(false), m_inblock(false), m_bchm(false), ignorespace(false), tablenesteddepth(0) 312striphtml::striphtml(const QString& _s) : entmap(NULL), isPre(false), currentid(0), lastch(0), currentfile(_s), indent(0), forcecentre(false), m_inblock(false), m_bchm(false), ignorespace(false), tablenesteddepth(0)
313{ 313{
314 href2filepos = new QMap<QString, unsigned long>; 314 href2filepos = new QMap<QString, unsigned long>;
315 id2href = new QMap<unsigned long, QString>; 315 id2href = new QMap<unsigned long, QString>;
316} 316}
317 317
318striphtml::~striphtml() 318striphtml::~striphtml()
319{ 319{
320 if (entmap != NULL) delete entmap; 320 if (entmap != NULL) delete entmap;
321 delete href2filepos; 321 delete href2filepos;
322 delete id2href; 322 delete id2href;
323} 323}
324 324
325void striphtml::initentmap() 325void striphtml::initentmap()
326{ 326{
327 entmap = new QMap<QString, tchar>; 327 entmap = new QMap<QString, tchar>;
328#ifdef USEQPE 328#ifdef USEQPE
329#ifdef OPIE 329#ifdef OPIE
330 QString fname(getenv("OPIEDIR")); 330 QString fname(getenv("OPIEDIR"));
331#else 331#else
332 QString fname(getenv("QTDIR")); 332 QString fname(getenv("QTDIR"));
333#endif 333#endif
334 fname += "/plugins/reader/data"; 334 fname += "/plugins/reader/data";
335#else 335#else
336 QString fname(getenv("READERDIR")); 336 QString fname(getenv("READERDIR"));
337 fname += "/data"; 337 fname += "/data";
338#endif 338#endif
339 QFileInfo fi; 339 QFileInfo fi;
340 fi.setFile(fname, "HTMLentities"); 340 fi.setFile(fname, "HTMLentities");
341 if (fi.exists()) 341 if (fi.exists())
342 { 342 {
343 fname = fi.absFilePath(); 343 fname = fi.absFilePath();
344 344
345 QFile fl(fname); 345 QFile fl(fname);
346 if (fl.open(IO_ReadOnly)) 346 if (fl.open(IO_ReadOnly))
347 { 347 {
348 QTextStream t(&fl); 348 QTextStream t(&fl);
349 QString key, value; 349 QString key, value;
350 while (!t.eof()) 350 while (!t.eof())
351 { 351 {
352 QString data = t.readLine(); 352 QString data = t.readLine();
353 int colon = data.find(':'); 353 int colon = data.find(':');
354 if (colon > 0) 354 if (colon > 0)
355 { 355 {
356 QString key = data.left(colon); 356 QString key = data.left(colon);
357 QString value = data.right(data.length()-colon-1); 357 QString value = data.right(data.length()-colon-1);
358 bool ok; 358 bool ok;
359 int ret = value.toInt(&ok); 359 int ret = value.toInt(&ok);
360 if (ok) 360 if (ok)
361 { 361 {
362 (*entmap)[key] = ret; 362 (*entmap)[key] = ret;
363 } 363 }
364 } 364 }
365 } 365 }
366 fl.close(); 366 fl.close();
367 } 367 }
368 } 368 }
369} 369}
370 370
371unsigned short striphtml::skip_ws() 371unsigned short striphtml::skip_ws()
372{ 372{
373 tchar ch; 373 tchar ch;
374 CStyle sty; 374 CStyle sty;
375 unsigned long dummy; 375 unsigned long dummy;
376 do 376 do
377 { 377 {
378 mygetch(ch, sty, dummy); 378 mygetch(ch, sty, dummy);
379 } 379 }
380 while (ch < 33 && ch != UEOF); 380 while (ch < 33 && ch != UEOF);
381 return ch; 381 return ch;
382} 382}
383 383
384unsigned short striphtml::skip_ws_end() 384unsigned short striphtml::skip_ws_end()
385{ 385{
386 unsigned long dummy; 386 unsigned long dummy;
387 return skip_ws_end(dummy); 387 return skip_ws_end(dummy);
388} 388}
389 389
390unsigned short striphtml::skip_ws_end(unsigned long& pos) 390unsigned short striphtml::skip_ws_end(unsigned long& pos)
391{ 391{
392 tchar ch; 392 tchar ch;
393 CStyle sty; 393 CStyle sty;
394 do 394 do
395 { 395 {
396 mygetch(ch, sty, pos); 396 mygetch(ch, sty, pos);
397 } 397 }
398 while (ch != '>' && ch != UEOF); 398 while (ch != '>' && ch != UEOF);
399 return ch; 399 return ch;
400} 400}
401 401
402QString striphtml::getname(tchar& ch, const QString& nd) 402QString striphtml::getname(tchar& ch, const QString& nd)
403{ 403{
404 QString nm = ""; 404 QString nm = "";
405 // nm += ch; 405 // nm += ch;
406 CStyle sty; 406 CStyle sty;
407 unsigned long dummy; 407 unsigned long dummy;
408 while (1) 408 while (1)
409 { 409 {
410 // if ( QChar(ch).isLetterOrNumber() ) 410 // if ( QChar(ch).isLetterOrNumber() )
411 if (ch != UEOF && nd.find(ch, 0, false) == -1 && nm.length() < 2048) 411 if (ch != UEOF && nd.find(ch, 0, false) == -1 && nm.length() < 2048)
412 { 412 {
413 nm += ch; 413 nm += ch;
414 } 414 }
415 else 415 else
416 { 416 {
417 break; 417 break;
418 } 418 }
419 mygetch(ch, sty, dummy); 419 mygetch(ch, sty, dummy);
420 } 420 }
421 return nm; 421 return nm;
422} 422}
423 423
424QString striphtml::getattr(tchar& ch) 424QString striphtml::getattr(tchar& ch)
425{ 425{
426 QString ref; 426 QString ref;
427 CStyle sty; 427 CStyle sty;
428 unsigned long pos; 428 unsigned long pos;
429 if (ch == ' ') ch = skip_ws(); 429 if (ch == ' ') ch = skip_ws();
430 if (ch == '=') 430 if (ch == '=')
431 { 431 {
432 ch = skip_ws(); 432 ch = skip_ws();
433 if (ch == '"') 433 if (ch == '"')
434 { 434 {
435 mygetch(ch, sty, pos); 435 mygetch(ch, sty, pos);
436 ref = getname(ch, "\""); 436 ref = getname(ch, "\"");
437 ch = skip_ws(); 437 ch = skip_ws();
438 } 438 }
439 else if (ch == '\'') 439 else if (ch == '\'')
440 { 440 {
441 mygetch(ch, sty, pos); 441 mygetch(ch, sty, pos);
442 ref = getname(ch, "\'"); 442 ref = getname(ch, "\'");
443 ch = skip_ws(); 443 ch = skip_ws();
444 } 444 }
445 else 445 else
446 { 446 {
447 ref = getname(ch, " >"); 447 ref = getname(ch, " >");
448 if (ch == ' ') ch = skip_ws(); 448 if (ch == ' ') ch = skip_ws();
449 } 449 }
450 } 450 }
451 return ref; 451 return ref;
452} 452}
453 453
454linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& nm) 454linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& nm)
455{ 455{
456#if defined(USEQPE) || defined(_WINDOWS) 456#if defined(USEQPE) || defined(_WINDOWS)
457 QMap<unsigned long, QString>::Iterator hrefit = id2href->find(n); 457 QMap<unsigned long, QString>::Iterator hrefit = id2href->find(n);
458#else 458#else
459 QMap<unsigned long, QString>::iterator hrefit = id2href->find(n); 459 QMap<unsigned long, QString>::iterator hrefit = id2href->find(n);
460#endif 460#endif
461 if (hrefit == id2href->end()) 461 if (hrefit == id2href->end())
462 { 462 {
463 return eNone; 463 return eNone;
464 } 464 }
465 QString href = *hrefit; 465 QString href = *hrefit;
466#if defined(USEQPE) || defined(_WINDOWS) 466#if defined(USEQPE) || defined(_WINDOWS)
467 QMap<QString, unsigned long>::Iterator fpit = href2filepos->find(href); 467 QMap<QString, unsigned long>::Iterator fpit = href2filepos->find(href);
468#else 468#else
469 QMap<QString, unsigned long>::iterator fpit = href2filepos->find(href); 469 QMap<QString, unsigned long>::iterator fpit = href2filepos->find(href);
470#endif 470#endif
471 if (fpit == href2filepos->end()) 471 if (fpit == href2filepos->end())
472 { 472 {
473 if (href == "history.back()") 473 if (href == "history.back()")
474 { 474 {
475 QString fc = currentfile; 475 QString fc = currentfile;
476 unsigned long loc; 476 unsigned long loc = 0;
477 htmlmark m(fc, loc); 477 htmlmark m(fc, loc);
478 linkType ret = (m_nav.back(m)) ? eFile : eNone; 478 linkType ret = (m_nav.back(m)) ? eFile : eNone;
479 if (fc == m.filename()) 479 if (fc == m.filename())
480 { 480 {
481 if ((ret & eFile) != 0) 481 if ((ret & eFile) != 0)
482 { 482 {
483 locate(m.posn()); 483 locate(m.posn());
484 return eLink; 484 return eLink;
485 } 485 }
486 } 486 }
487 return eNone; 487 return eNone;
488 } 488 }
489 qDebug("Searching for %s", (const char*)href); 489 qDebug("Searching for %s", (const char*)href);
490 490
491 491
492 QString file, name; 492 QString file, name;
493 493
494 int colon = href.find('#'); 494 int colon = href.find('#');
495 if (colon >= 0) 495 if (colon >= 0)
496 { 496 {
497 file = dehtml(href.left(colon)); 497 file = dehtml(href.left(colon));
498 name = dehtml(href.right(href.length()-colon-1)); 498 name = dehtml(href.right(href.length()-colon-1));
499 } 499 }
500 else 500 else
501 { 501 {
502 file = dehtml(href); 502 file = dehtml(href);
503 } 503 }
504 504
505 qDebug("File:%s", (const char*)file); 505 qDebug("File:%s", (const char*)file);
506 qDebug("Name:%s", (const char*)name); 506 qDebug("Name:%s", (const char*)name);
507 507
508 508
509 if (file.isEmpty()) 509 if (file.isEmpty())
510 { 510 {
511 if (parent->findanchor(name)) 511 if (parent->findanchor(name))
512 { 512 {
513 reset(); 513 reset();
514 return eLink; 514 return eLink;
515 } 515 }
516 fpit = href2filepos->find(name); 516 fpit = href2filepos->find(name);
517 if (fpit != href2filepos->end()) 517 if (fpit != href2filepos->end())
518 { 518 {
519 locate(*fpit); 519 locate(*fpit);
520 return eLink; 520 return eLink;
521 } 521 }
522 else 522 else
523 { 523 {
524 // nm = QString("<a[^>]*name[ \t]*=[ \t]*\"") + name + "\""; 524 // nm = QString("<a[^>]*name[ \t]*=[ \t]*\"") + name + "\"";
525 qDebug("Do a search for:%s", (const char*)name); 525 qDebug("Do a search for:%s", (const char*)name);
526 findanchor(name); 526 findanchor(name);
527 return eLink; 527 return eLink;
528 } 528 }
529 } 529 }
530 else 530 else
531 // if (href.find('#') == -1) 531 // if (href.find('#') == -1)
532 { 532 {
533 if (m_bchm) 533 if (m_bchm)
534 { 534 {
535 w = file; 535 w = file;
536 nm = name; 536 nm = name;
537 return eFile; 537 return eFile;
538 } 538 }
539 else 539 else
540 { 540 {
541 QFileInfo f(currentfile); 541 QFileInfo f(currentfile);
542 QFileInfo f1(f.dir(true), file); 542 QFileInfo f1(f.dir(true), file);
543 if (f1.exists()) 543 if (f1.exists())
544 { 544 {
545 w = f1.absFilePath(); 545 w = f1.absFilePath();
546 nm = name; 546 nm = name;
547 } 547 }
548 else 548 else
549 { 549 {
550 w = file; 550 w = file;
551 } 551 }
552 return (f1.exists() ? eFile : eNone); 552 return (f1.exists() ? eFile : eNone);
553 } 553 }
554 } 554 }
555 return eNone; 555 return eNone;
556 } 556 }
557 locate(*fpit); 557 locate(*fpit);
558 // parent->locate((*href2filepos)[(*id2href)[n]]); 558 // parent->locate((*href2filepos)[(*id2href)[n]]);
559 return eLink; 559 return eLink;
560} 560}
561/* 561/*
562unsigned short striphtml::parse_m() 562unsigned short striphtml::parse_m()
563{ 563{
564 tchar ch; 564 tchar ch;
565 CStyle sty; 565 CStyle sty;
566 unsigned long dummy; 566 unsigned long dummy;
567 mygetch(ch, sty, dummy); 567 mygetch(ch, sty, dummy);
568 if (ch == 'm' || ch == 'M') 568 if (ch == 'm' || ch == 'M')
569 { 569 {
570 ch = skip_ws_end(); 570 ch = skip_ws_end();
571 if (ch == '>') 571 if (ch == '>')
572 { 572 {
573 return 0; 573 return 0;
574 } 574 }
575 } 575 }
576 return ch; 576 return ch;
577} 577}
578*/ 578*/
579 579
580void striphtml::mygetch(tchar& ch, CStyle& sty, unsigned long& pos) 580void striphtml::mygetch(tchar& ch, CStyle& sty, unsigned long& pos)
581{ 581{
582 if (!text_q.isEmpty() && !m_inblock) 582 if (!text_q.isEmpty() && !m_inblock)
583 { 583 {
584 ch = text_q[0].unicode(); 584 ch = text_q[0].unicode();
585 text_q = text_q.right(text_q.length()-1); 585 text_q = text_q.right(text_q.length()-1);
586 } 586 }
587 else 587 else
588 { 588 {
589 parent->getch(ch, sty, pos); 589 parent->getch(ch, sty, pos);
590 if (ch == '<') 590 if (ch == '<')
591 { 591 {
592 m_inblock = true; 592 m_inblock = true;
593 } 593 }
594 if (ch == '>') 594 if (ch == '>')
595 { 595 {
596 m_inblock = false; 596 m_inblock = false;
597 } 597 }
598 } 598 }
599 if (ch == 10 && !isPre) 599 if (ch == 10 && !isPre)
600 { 600 {
601#ifdef REMOVE_LF_BEFORE_ENDTAG 601#ifdef REMOVE_LF_BEFORE_ENDTAG
602 parent->getch(ch, sty, pos); 602 parent->getch(ch, sty, pos);
603 if (ch == '<') 603 if (ch == '<')
604 { 604 {
605 parent->getch(ch, sty, pos); 605 parent->getch(ch, sty, pos);
606 if (ch == '/') 606 if (ch == '/')
607 { 607 {
608 ch = '<'; 608 ch = '<';
609 text_q += '/'; 609 text_q += '/';
610 } 610 }
611 else 611 else
612 { 612 {
613 text_q += '<'; 613 text_q += '<';
614 text_q += ch; 614 text_q += ch;
615 ch = ' '; 615 ch = ' ';
616 } 616 }
617 } 617 }
618 else 618 else
619 { 619 {
620 text_q += ch; 620 text_q += ch;
621 ch = ' '; 621 ch = ' ';
622 } 622 }
623#else 623#else
624 ch = ' '; 624 ch = ' ';
625#endif 625#endif
626 } 626 }
627} 627}
628 628
629void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long pos) 629void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long pos)
630{ 630{
631/* 631/*
632 int count = 0; 632 int count = 0;
633 for (CList<CStyle>::iterator iter = stylestack.begin(); iter != stylestack.end(); ++iter) 633 for (CList<CStyle>::iterator iter = stylestack.begin(); iter != stylestack.end(); ++iter)
634 { 634 {
635 count++; 635 count++;
636 } 636 }
637 qDebug("Currently have %u styles", count); 637 qDebug("Currently have %u styles", count);
638*/ 638*/
639 if (stylestack.isEmpty()) 639 if (stylestack.isEmpty())
640 { 640 {
641 currentstyle.unset(); 641 currentstyle.unset();
642 } 642 }
643 else 643 else
644 { 644 {
645 currentstyle = stylestack.first(); 645 currentstyle = stylestack.first();
646 } 646 }
647 if (forcecentre) 647 if (forcecentre)
648 { 648 {
649 currentstyle.setCentreJustify(); 649 currentstyle.setCentreJustify();
650 } 650 }
651 if (ch == ' ') ch = skip_ws(); 651 if (ch == ' ') ch = skip_ws();
652 while (ch != '>' && ch != UEOF) 652 while (ch != '>' && ch != UEOF)
653 { 653 {
654 QString ent = getname(ch, " =>").lower(); 654 QString ent = getname(ch, " =>").lower();
655 QString attr = getattr(ch).lower(); 655 QString attr = getattr(ch).lower();
656 //qDebug("(Paragraph)Entity:%s Attr:%s", (const char*)ent, (const char*)attr); 656 //qDebug("(Paragraph)Entity:%s Attr:%s", (const char*)ent, (const char*)attr);
657 if (ent == "align") 657 if (ent == "align")
658 { 658 {
659 if (attr == "center") 659 if (attr == "center")
660 { 660 {
661 currentstyle.setCentreJustify(); 661 currentstyle.setCentreJustify();
662 } 662 }
663 if (attr == "right") 663 if (attr == "right")
664 { 664 {
665 currentstyle.setRightJustify(); 665 currentstyle.setRightJustify();
666 } 666 }
667 if (attr == "justify") 667 if (attr == "justify")
668 { 668 {
669 currentstyle.setFullJustify(); 669 currentstyle.setFullJustify();
670 } 670 }
671 } 671 }
672 if (ent == "id") 672 if (ent == "id")
673 { 673 {
674 (*href2filepos)[attr] = pos; 674 (*href2filepos)[attr] = pos;
675 } 675 }
676 if (ent == "bgcolor") 676 if (ent == "bgcolor")
677 { 677 {
678 qDebug("Got paper colour:%s", (const char*)attr); 678 qDebug("Got paper colour:%s", (const char*)attr);
679 unsigned char r,g,b; 679 unsigned char r,g,b;
680 parse_color(attr, r, g, b); 680 parse_color(attr, r, g, b);
681 currentstyle.setPaper(r, g, b); 681 currentstyle.setPaper(r, g, b);
682 } 682 }
683 if (ent == "color") 683 if (ent == "color")
684 { 684 {
685 qDebug("Got foreground colour:%s", (const char*)attr); 685 qDebug("Got foreground colour:%s", (const char*)attr);
686 unsigned char r,g,b; 686 unsigned char r,g,b;
687 parse_color(attr, r, g, b); 687 parse_color(attr, r, g, b);
688 currentstyle.setColour(r, g, b); 688 currentstyle.setColour(r, g, b);
689 } 689 }
690 if (ch == ' ') ch = skip_ws(); 690 if (ch == ' ') ch = skip_ws();
691 } 691 }
692 ch = 10; 692 ch = 10;
693} 693}
694 694
695void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) 695void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos)
696{ 696{
697 currentstyle.clearPicture(); 697 currentstyle.clearPicture();
698 if (!q.isEmpty()) 698 if (!q.isEmpty())
699 { 699 {
700 ch = q[0].unicode(); 700 ch = q[0].unicode();
701 if (ch == '-') 701 if (ch == '-')
702 { 702 {
703 tchar w = q[1].unicode(); 703 tchar w = q[1].unicode();
704 tchar h = q[2].unicode(); 704 tchar h = q[2].unicode();
705 unsigned char r = q[3].unicode(); 705 unsigned char r = q[3].unicode();
706 unsigned char g = q[4].unicode(); 706 unsigned char g = q[4].unicode();
707 unsigned char b = q[5].unicode(); 707 unsigned char b = q[5].unicode();
708 ch = '#'; 708 ch = '#';
709 //qDebug("html:hrule<%u, %u>", w, h); 709 //qDebug("html:hrule<%u, %u>", w, h);
710 currentstyle.setPicture(false, hRule(w,h,r,g,b)); 710 currentstyle.setPicture(false, hRule(w,h,r,g,b));
711 q = q.right(q.length()-6); 711 q = q.right(q.length()-6);
712 } 712 }
713 else 713 else
714 { 714 {
715 q = q.right(q.length()-1); 715 q = q.right(q.length()-1);
716 } 716 }
717 sty = currentstyle; 717 sty = currentstyle;
718 lastch = ch; 718 lastch = ch;
719 return; 719 return;
720 } 720 }
721 do 721 do
722 { 722 {
723 unsigned long npos; 723 unsigned long npos;
724 CStyle dummy; 724 CStyle dummy;
725 mygetch(ch, dummy, pos); 725 mygetch(ch, dummy, pos);
726 while (ch == '<' && ch != UEOF) 726 while (ch == '<' && ch != UEOF)
727 { 727 {
728 ch = skip_ws(); 728 ch = skip_ws();
729 QString ent = getname(ch, " >").lower(); 729 QString ent = getname(ch, " >").lower();
730 730
731 // qDebug("Entity:%s", (const char*)ent); 731 // qDebug("Entity:%s", (const char*)ent);
732 732
733 if (ent == "a"/* || ent == "reference"*/) 733 if (ent == "a"/* || ent == "reference"*/)
734 { 734 {
735 if (ch == ' ') ch = skip_ws(); 735 if (ch == ' ') ch = skip_ws();
736 bool fileposfound = false; 736 bool fileposfound = false;
737 bool ishref = false; 737 bool ishref = false;
738 unsigned int filepos = 0; 738 unsigned int filepos = 0;
739 QString ref, name; 739 QString ref, name;
740 while (ch != '>' && ch != UEOF) 740 while (ch != '>' && ch != UEOF)
741 { 741 {
742 QString ent = getname(ch, " =>").lower(); 742 QString ent = getname(ch, " =>").lower();
743 QString attr = getattr(ch); 743 QString attr = getattr(ch);
744 //qDebug("<A>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); 744 //qDebug("<A>Entity:%s Attr:%s", (const char*)ent, (const char*)attr);
745 if (ent == "name") 745 if (ent == "name")
746 { 746 {
747 name = attr; 747 name = attr;
748 } 748 }
749 if (ent == "onclick") 749 if (ent == "onclick")
750 { 750 {
751 int st = attr.find('\''); 751 int st = attr.find('\'');
752 int nd = attr.findRev('\''); 752 int nd = attr.findRev('\'');
753 ref = attr.mid(st+1, nd-st-1); 753 ref = attr.mid(st+1, nd-st-1);
754 ishref = true; 754 ishref = true;
755 qDebug("Onclick:%s", (const char*)ref); 755 qDebug("Onclick:%s", (const char*)ref);
756 } 756 }
757 if (ent == "href") 757 if (ent == "href")
758 { 758 {
759 ishref = true; 759 ishref = true;
760 ref = attr; 760 ref = attr;
761 } 761 }
762 if (ent == "filepos") 762 if (ent == "filepos")
763 { 763 {
764 filepos = attr.toUInt(&fileposfound); 764 filepos = attr.toUInt(&fileposfound);
765 if (ref.isEmpty()) 765 if (ref.isEmpty())
766 { 766 {
767 ishref = true; 767 ishref = true;
768 ref = attr; 768 ref = attr;
769 } 769 }
770 } 770 }
771 if (ent == "title") 771 if (ent == "title")
772 { 772 {
773 text_q = attr + "</a><p>"; 773 text_q = attr + "</a><p>";
774 } 774 }
775 //qDebug("<a %s=%s>", (const char*)ent, (const char*)ref); 775 //qDebug("<a %s=%s>", (const char*)ent, (const char*)ref);
776 } 776 }
777 if (ishref) 777 if (ishref)
778 { 778 {
779 currentstyle.setColour(0,0,255); 779 currentstyle.setColour(0,0,255);
780 currentstyle.setLink(true); 780 currentstyle.setLink(true);
781 currentstyle.setData(currentid); 781 currentstyle.setData(currentid);
782 if (!text_q.isEmpty()) 782 if (!text_q.isEmpty())
783 { 783 {
784 currentstyle.setBold(); 784 currentstyle.setBold();
785 currentstyle.setCentreJustify(); 785 currentstyle.setCentreJustify();
786 } 786 }
787 (*id2href)[currentid] = ref; 787 (*id2href)[currentid] = ref;
788 currentid++; 788 currentid++;
789 789
790 790
791 if (fileposfound) 791 if (fileposfound)
792 { 792 {
793 (*href2filepos)[ref] = filepos; 793 (*href2filepos)[ref] = filepos;
794 } 794 }
795 } 795 }
796 if (!name.isEmpty()) 796 if (!name.isEmpty())
797 { 797 {
798 (*href2filepos)[name] = pos; 798 (*href2filepos)[name] = pos;
799 } 799 }
800 } 800 }
801 else if (ent == "p") 801 else if (ent == "p")
802 { 802 {
803 parse_paragraph(currentstyle, ch, pos); 803 parse_paragraph(currentstyle, ch, pos);
804 currentstyle.setExtraSpace(3); 804 currentstyle.setExtraSpace(3);
805 continue; 805 continue;
806 } 806 }
807 else if (ent == "div") 807 else if (ent == "div")
808 { 808 {
809 parse_paragraph(currentstyle, ch, pos); 809 parse_paragraph(currentstyle, ch, pos);
810 stylestack.push_front(currentstyle); 810 stylestack.push_front(currentstyle);
811 currentstyle.setExtraSpace(16); 811 currentstyle.setExtraSpace(16);
812 //indent = 0; 812 //indent = 0;
813 continue; 813 continue;
814 } 814 }
815 else if (ent == "sup") 815 else if (ent == "sup")
816 { 816 {
817 currentstyle.setVOffset(-1); 817 currentstyle.setVOffset(-1);
818 } 818 }
819 else if (ent == "sup") 819 else if (ent == "sup")
820 { 820 {
821 currentstyle.setVOffset(1); 821 currentstyle.setVOffset(1);
822 } 822 }
823 else if (ent == "/sup" || ent == "/sub") 823 else if (ent == "/sup" || ent == "/sub")
824 { 824 {
825 currentstyle.setVOffset(0); 825 currentstyle.setVOffset(0);
826 } 826 }
827 else if (ent == "span") 827 else if (ent == "span")
828 { 828 {
829 if (ch == ' ') ch = skip_ws(); 829 if (ch == ' ') ch = skip_ws();
830 while (ch != '>' && ch != UEOF) 830 while (ch != '>' && ch != UEOF)
831 { 831 {
832 QString ent = getname(ch, " =>").lower(); 832 QString ent = getname(ch, " =>").lower();
833 QString attr = getattr(ch).lower(); 833 QString attr = getattr(ch).lower();
834 if (ent == "bgcolor") 834 if (ent == "bgcolor")
835 { 835 {
836 qDebug("Got background colour:%s", (const char*)attr); 836 qDebug("Got background colour:%s", (const char*)attr);
837 unsigned char r,g,b; 837 unsigned char r,g,b;
838 parse_color(attr, r, g, b); 838 parse_color(attr, r, g, b);
839 currentstyle.setBackground(r, g, b); 839 currentstyle.setBackground(r, g, b);
840 } 840 }
841 if (ent == "color") 841 if (ent == "color")
842 { 842 {
843 qDebug("Got foreground colour:%s", (const char*)attr); 843 qDebug("Got foreground colour:%s", (const char*)attr);
844 unsigned char r,g,b; 844 unsigned char r,g,b;
845 parse_color(attr, r, g, b); 845 parse_color(attr, r, g, b);
846 currentstyle.setColour(r, g, b); 846 currentstyle.setColour(r, g, b);
847 } 847 }
848 } 848 }
849 stylestack.push_front(currentstyle); 849 stylestack.push_front(currentstyle);
850 } 850 }
851 else if (ent == "/span") 851 else if (ent == "/span")
852 { 852 {
853 if (ch != '>') ch = skip_ws_end(); 853 if (ch != '>') ch = skip_ws_end();
854 currentstyle.setBackground(255, 255, 255); 854 currentstyle.setBackground(255, 255, 255);
855 currentstyle.setColour(0, 0, 0); 855 currentstyle.setColour(0, 0, 0);
856 if (!stylestack.isEmpty()) 856 if (!stylestack.isEmpty())
857 { 857 {
858 stylestack.pop(); 858 stylestack.pop();
859 } 859 }
860 } 860 }
861 else if (ent == "pre") 861 else if (ent == "pre")
862 { 862 {
863 isPre = true; 863 isPre = true;
864 currentstyle.setNoJustify(); 864 currentstyle.setNoJustify();
865 currentstyle.setMono(); 865 currentstyle.setMono();
866 } 866 }
867 else if (ent == "tt") 867 else if (ent == "tt")
868 { 868 {
869 currentstyle.setMono(); 869 currentstyle.setMono();
870 } 870 }
871 else if (ent == "b" || ent == "strong") 871 else if (ent == "b" || ent == "strong")
872 { 872 {
873 currentstyle.setBold(); 873 currentstyle.setBold();
874 } 874 }
875 else if (ent == "u") 875 else if (ent == "u")
876 { 876 {
877 currentstyle.setUnderline(); 877 currentstyle.setUnderline();
878 } 878 }
879 else if (ent == "/u") 879 else if (ent == "/u")
880 { 880 {
881 currentstyle.unsetUnderline(); 881 currentstyle.unsetUnderline();
882 } 882 }
883 else if (ent == "blockquote") 883 else if (ent == "blockquote")
884 { 884 {
885 if (ch != '>') ch = skip_ws_end(); 885 if (ch != '>') ch = skip_ws_end();
886 ch = 10; 886 ch = 10;
887 currentstyle.setExtraSpace(0); 887 currentstyle.setExtraSpace(0);
888 currentstyle.setLeftMargin(30); 888 currentstyle.setLeftMargin(30);
889 currentstyle.setRightMargin(30); 889 currentstyle.setRightMargin(30);
890 continue; 890 continue;
891 } 891 }
892 else if (ent == "br" || ent == "br/") 892 else if (ent == "br" || ent == "br/")
893 { 893 {
894 if (ch != '>') ch = skip_ws_end(); 894 if (ch != '>') ch = skip_ws_end();
895 ch = 10; 895 ch = 10;
896 currentstyle.setExtraSpace(0); 896 currentstyle.setExtraSpace(0);
897 lastch = 0; 897 lastch = 0;
898 continue; 898 continue;
899 } 899 }
900 else if (ent == "mbp:pagebreak") 900 else if (ent == "mbp:pagebreak")
901 { 901 {
902 /* 902 /*
903 if (ch != '>') ch = skip_ws_end(pos); 903 if (ch != '>') ch = skip_ws_end(pos);
904 q += 10; 904 q += 10;
905 q += QChar(UEOF); 905 q += QChar(UEOF);
906 ch = 10; 906 ch = 10;
907 continue; 907 continue;
908 */ 908 */
909 ch = 6; 909 ch = 6;
910 // currentstyle.setTop(); 910 // currentstyle.setTop();
911 continue; 911 continue;
912 } 912 }
913 else if (ent == "center") 913 else if (ent == "center")
914 { 914 {
915 //forcecentre = true; 915 //forcecentre = true;
916 qDebug("setting centre"); 916 qDebug("setting centre");
917 currentstyle.setCentreJustify(); 917 currentstyle.setCentreJustify();
918 ch = 10; 918 ch = 10;
919 continue; 919 continue;
920 } 920 }
921 else if (ent == "/center") 921 else if (ent == "/center")
922 { 922 {
923 qDebug("unsetting centre"); 923 qDebug("unsetting centre");
924 forcecentre = false; 924 forcecentre = false;
925 } 925 }
926 else if (ent == "li") 926 else if (ent == "li")
927 { 927 {
928 if (ch != '>') ch = skip_ws_end(); 928 if (ch != '>') ch = skip_ws_end();
929 lastch = 0; 929 lastch = 0;
930 ch = 10; 930 ch = 10;
931 if (m_listtype[indent % m_cmaxdepth] == 1) 931 if (m_listtype[indent % m_cmaxdepth] == 1)
932 { 932 {
933 q.setNum(m_ctr[indent % m_cmaxdepth]++); 933 q.setNum(m_ctr[indent % m_cmaxdepth]++);
934 } 934 }
935 else 935 else
936 { 936 {
937 q += QChar(8226); 937 q += QChar(8226);
938 } 938 }
939 q += ' '; 939 q += ' ';
940 currentstyle.setLeftMargin(6*indent); 940 currentstyle.setLeftMargin(6*indent);
941 qDebug("Setting indent:%d", indent); 941 qDebug("Setting indent:%d", indent);
942 continue; 942 continue;
943 } 943 }
944 else if (ent == "ul") 944 else if (ent == "ul")
945 { 945 {
946 indent++; 946 indent++;
947 m_listtype[indent % m_cmaxdepth] = 0; 947 m_listtype[indent % m_cmaxdepth] = 0;
948 } 948 }
949 else if (ent == "/ul") 949 else if (ent == "/ul")
950 { 950 {
951 indent--; 951 indent--;
952 } 952 }
953 else if (ent == "ol") 953 else if (ent == "ol")
954 { 954 {
955 indent++; 955 indent++;
956 m_listtype[indent % m_cmaxdepth] = 1; 956 m_listtype[indent % m_cmaxdepth] = 1;
957 m_ctr[indent % m_cmaxdepth] = 1; 957 m_ctr[indent % m_cmaxdepth] = 1;
958 } 958 }
959 else if (ent == "/ol") 959 else if (ent == "/ol")
960 { 960 {
961 indent--; 961 indent--;
962 } 962 }
963 else if (ent == "i") 963 else if (ent == "i")
964 { 964 {
965 currentstyle.setItalic(); 965 currentstyle.setItalic();
966 } 966 }
967 else if (ent == "em") 967 else if (ent == "em")
968 { 968 {
969 currentstyle.setItalic(); 969 currentstyle.setItalic();
970 } 970 }
971 else if (ent == "small") 971 else if (ent == "small")
972 { 972 {
973 currentstyle.setFontSize(-2); 973 currentstyle.setFontSize(-2);
974 } 974 }
975 else if (ent == "/small") 975 else if (ent == "/small")
976 { 976 {
977 currentstyle.setFontSize(0); 977 currentstyle.setFontSize(0);
978 } 978 }
979 else if (ent == "big") 979 else if (ent == "big")
980 { 980 {
981 currentstyle.setFontSize(2); 981 currentstyle.setFontSize(2);
982 } 982 }
983 else if (ent == "/big") 983 else if (ent == "/big")
984 { 984 {
985 currentstyle.setFontSize(0); 985 currentstyle.setFontSize(0);
986 } 986 }
987 else if (ent[0] == '/' && ent[1] == 'h' && ent.length() == 3 && QString("123456789").find(ent[2]) != -1) 987 else if (ent[0] == '/' && ent[1] == 'h' && ent.length() == 3 && QString("123456789").find(ent[2]) != -1)
988 { 988 {
989 parse_paragraph(currentstyle, ch, pos); 989 parse_paragraph(currentstyle, ch, pos);
990 currentstyle.setExtraSpace(3); 990 currentstyle.setExtraSpace(3);
991 continue; 991 continue;
992 } 992 }
993 else if (ent[0] == 'h' && ent.length() == 2 && QString("123456789").find(ent[1]) != -1) 993 else if (ent[0] == 'h' && ent.length() == 2 && QString("123456789").find(ent[1]) != -1)
994 { 994 {
995 indent = 0; 995 indent = 0;
996 if (ent[1] == '1') 996 if (ent[1] == '1')
997 { 997 {
998 parse_paragraph(currentstyle, ch, pos); 998 parse_paragraph(currentstyle, ch, pos);
999 currentstyle.setFontSize(3); 999 currentstyle.setFontSize(3);
1000 currentstyle.setExtraSpace(8); 1000 currentstyle.setExtraSpace(8);
1001 currentstyle.setBold(); 1001 currentstyle.setBold();
1002 // currentstyle.setExtraSpace(10); 1002 // currentstyle.setExtraSpace(10);
1003 } 1003 }
1004 else if (ent[1] == '2') 1004 else if (ent[1] == '2')
1005 { 1005 {
1006 parse_paragraph(currentstyle, ch, pos); 1006 parse_paragraph(currentstyle, ch, pos);
1007 currentstyle.setFontSize(2); 1007 currentstyle.setFontSize(2);
1008 currentstyle.setExtraSpace(6); 1008 currentstyle.setExtraSpace(6);
1009 currentstyle.setBold(); 1009 currentstyle.setBold();
1010 // currentstyle.setExtraSpace(10); 1010 // currentstyle.setExtraSpace(10);
1011 } 1011 }
1012 else if (ent[1] == '3') 1012 else if (ent[1] == '3')
1013 { 1013 {
1014 parse_paragraph(currentstyle, ch, pos); 1014 parse_paragraph(currentstyle, ch, pos);
1015 currentstyle.setFontSize(1); 1015 currentstyle.setFontSize(1);
1016 currentstyle.setExtraSpace(4); 1016 currentstyle.setExtraSpace(4);
1017 currentstyle.setBold(); 1017 currentstyle.setBold();
1018 // currentstyle.setExtraSpace(10); 1018 // currentstyle.setExtraSpace(10);
1019 } 1019 }
1020 else 1020 else
1021 { 1021 {
1022 parse_paragraph(currentstyle, ch, pos); 1022 parse_paragraph(currentstyle, ch, pos);
1023 currentstyle.setExtraSpace(4); 1023 currentstyle.setExtraSpace(4);
1024 currentstyle.setBold(); 1024 currentstyle.setBold();
1025 // currentstyle.setExtraSpace(10); 1025 // currentstyle.setExtraSpace(10);
1026 } 1026 }
1027 ch = 10; 1027 ch = 10;
1028 continue; 1028 continue;
1029 } 1029 }
1030 1030
1031 1031
1032 else if (ent == "/a") 1032 else if (ent == "/a")
1033 { 1033 {
1034 currentstyle.setColour(0,0,0); 1034 currentstyle.setColour(0,0,0);
1035 currentstyle.setLink(false); 1035 currentstyle.setLink(false);
1036 } 1036 }
1037 else if (ent == "/pre") 1037 else if (ent == "/pre")
1038 { 1038 {
1039 currentstyle.unsetMono(); 1039 currentstyle.unsetMono();
1040 isPre = false; 1040 isPre = false;
1041 } 1041 }
1042 else if (ent == "/tt") 1042 else if (ent == "/tt")
1043 { 1043 {
1044 currentstyle.unsetMono(); 1044 currentstyle.unsetMono();
1045 } 1045 }
1046 else if (ent == "/b" || ent == "/strong") 1046 else if (ent == "/b" || ent == "/strong")
1047 { 1047 {
1048 currentstyle.unsetBold(); 1048 currentstyle.unsetBold();
1049 } 1049 }
1050 else if (ent == "/i") 1050 else if (ent == "/i")
1051 { 1051 {
1052 currentstyle.unsetItalic(); 1052 currentstyle.unsetItalic();
1053 } 1053 }
1054 else if (ent == "/em") 1054 else if (ent == "/em")
1055 { 1055 {
1056 currentstyle.unsetItalic(); 1056 currentstyle.unsetItalic();
1057 } 1057 }
1058 else if (ent == "/div") 1058 else if (ent == "/div")
1059 { 1059 {
1060 currentstyle.unset(); 1060 currentstyle.unset();
1061 if (ch != '>') ch = skip_ws_end(); 1061 if (ch != '>') ch = skip_ws_end();
1062 ch = 10; 1062 ch = 10;
1063 if (!stylestack.isEmpty()) 1063 if (!stylestack.isEmpty())
1064 { 1064 {
1065 stylestack.pop(); 1065 stylestack.pop();
1066 } 1066 }
1067 continue; 1067 continue;
1068 } 1068 }
1069 else if (ent == "tr") 1069 else if (ent == "tr")
1070 { 1070 {
1071 if (ch != '>') ch = skip_ws_end(); 1071 if (ch != '>') ch = skip_ws_end();
1072 ch = 10; 1072 ch = 10;
1073 q += '-'; 1073 q += '-';
1074 q += QChar(parent->getwidth()); 1074 q += QChar(parent->getwidth());
1075 q += 2; 1075 q += 2;
1076 q += '\0'; 1076 q += '\0';
1077 q += '\0'; 1077 q += '\0';
1078 q += '\0'; 1078 q += '\0';
1079 continue; 1079 continue;
1080 } 1080 }
1081 else if (ent == "td") 1081 else if (ent == "td")
1082 { 1082 {
1083 if (ch != '>') ch = skip_ws_end(); 1083 if (ch != '>') ch = skip_ws_end();
1084 ignorespace = false; 1084 ignorespace = false;
1085 } 1085 }
1086 else if (ent == "/td") 1086 else if (ent == "/td")
1087 { 1087 {
1088 ignorespace = true; 1088 ignorespace = true;
1089 // parse_paragraph(currentstyle, ch, pos); 1089 // parse_paragraph(currentstyle, ch, pos);
1090 //stylestack.push_front(currentstyle); 1090 //stylestack.push_front(currentstyle);
1091 if (ch != '>') ch = skip_ws_end(); 1091 if (ch != '>') ch = skip_ws_end();
1092 // ch = '|'; 1092 // ch = '|';
1093 //continue; 1093 //continue;
1094 ch = 10; 1094 ch = 10;
1095 q += '-'; 1095 q += '-';
1096 q += QChar(parent->getwidth()); 1096 q += QChar(parent->getwidth());
1097 q += 1; 1097 q += 1;
1098 q += '\0'; 1098 q += '\0';
1099 q += '\0'; 1099 q += '\0';
1100 q += '\0'; 1100 q += '\0';
1101 continue; 1101 continue;
1102 } 1102 }
1103 /* 1103 /*
1104 else if (ent == "/td") 1104 else if (ent == "/td")
1105 { 1105 {
1106 currentstyle.unset(); 1106 currentstyle.unset();
1107 if (ch != '>') ch = skip_ws_end(); 1107 if (ch != '>') ch = skip_ws_end();
1108 if (!stylestack.isEmpty()) 1108 if (!stylestack.isEmpty())
1109 { 1109 {
1110 stylestack.pop(); 1110 stylestack.pop();
1111 } 1111 }
1112 // ch = 10; 1112 // ch = 10;
1113 continue; 1113 continue;
1114 } 1114 }
1115 */ 1115 */
1116 else if (ent[0] == '/' && ent.length() == 3 && ent[1] == 'h' && QString("123456789").find(ent[2]) != -1) 1116 else if (ent[0] == '/' && ent.length() == 3 && ent[1] == 'h' && QString("123456789").find(ent[2]) != -1)
1117 { 1117 {
1118 currentstyle.unset(); 1118 currentstyle.unset();
1119 if (ch != '>') ch = skip_ws_end(); 1119 if (ch != '>') ch = skip_ws_end();
1120 //ch = 10; 1120 //ch = 10;
1121 //continue; 1121 //continue;
1122 } 1122 }
1123 else if (ent == "table" || ent == "/table") 1123 else if (ent == "table" || ent == "/table")
1124 { 1124 {
1125 currentstyle.unset(); 1125 currentstyle.unset();
1126 ignorespace = (ent == "table"); 1126 ignorespace = (ent == "table");
1127 if (ent == "table") 1127 if (ent == "table")
1128 { 1128 {
1129 if (tablenesteddepth++ == 0) currentstyle.setTable(pos); 1129 if (tablenesteddepth++ == 0) currentstyle.setTable(pos);
1130 } 1130 }
1131 else 1131 else
1132 { 1132 {
1133 if (--tablenesteddepth <= 0) 1133 if (--tablenesteddepth <= 0)
1134 { 1134 {
1135 tablenesteddepth = 0; 1135 tablenesteddepth = 0;
1136 currentstyle.setTable(0xffffffff); 1136 currentstyle.setTable(0xffffffff);
1137 } 1137 }
1138 } 1138 }
1139 if (ch == ' ') ch = skip_ws(); 1139 if (ch == ' ') ch = skip_ws();
1140 while (ch != '>' && ch != UEOF) 1140 while (ch != '>' && ch != UEOF)
1141 { 1141 {
1142 QString ent = getname(ch, " =>").lower(); 1142 QString ent = getname(ch, " =>").lower();
1143 QString attr = getattr(ch); 1143 QString attr = getattr(ch);
1144 qDebug("<table>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); 1144 qDebug("<table>Entity:%s Attr:%s", (const char*)ent, (const char*)attr);
1145 } 1145 }
1146 if (ch != '>') ch = skip_ws_end(); 1146 if (ch != '>') ch = skip_ws_end();
1147 1147
1148 currentstyle.setLeftMargin(6*tablenesteddepth); 1148 currentstyle.setLeftMargin(6*tablenesteddepth);
1149 1149
1150 1150
1151 lastch = 0; // Anything but 10 1151 lastch = 0; // Anything but 10
1152 ch = 10; 1152 ch = 10;
1153 q += '-'; 1153 q += '-';
1154 q += QChar(parent->getwidth()); 1154 q += QChar(parent->getwidth());
1155 q += 3; 1155 q += 3;
1156 q += '\0'; 1156 q += '\0';
1157 q += '\0'; 1157 q += '\0';
1158 q += '\0'; 1158 q += '\0';
1159 continue; 1159 continue;
1160 } 1160 }
1161 else if (ent == "hr") 1161 else if (ent == "hr")
1162 { 1162 {
1163 //bool isPageBreak = false; 1163 //bool isPageBreak = false;
1164 if (ch == ' ') ch = skip_ws(); 1164 if (ch == ' ') ch = skip_ws();
1165 unsigned char red = 0, green = 0, blue = 0; 1165 unsigned char red = 0, green = 0, blue = 0;
1166 while (ch != '>' && ch != UEOF) 1166 while (ch != '>' && ch != UEOF)
1167 { 1167 {
1168 QString ent = getname(ch, " =>").lower(); 1168 QString ent = getname(ch, " =>").lower();
1169 QString attr = getattr(ch); 1169 QString attr = getattr(ch);
1170 if (ent == "color") 1170 if (ent == "color")
1171 { 1171 {
1172 parse_color(attr, red, green, blue); 1172 parse_color(attr, red, green, blue);
1173 } 1173 }
1174 /* 1174 /*
1175 if (ent == "size") 1175 if (ent == "size")
1176 { 1176 {
1177 if (attr == "0") 1177 if (attr == "0")
1178 { 1178 {
1179 isPageBreak = true; 1179 isPageBreak = true;
1180 } 1180 }
1181 } 1181 }
1182 */ 1182 */
1183 qDebug("<hr>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); 1183 qDebug("<hr>Entity:%s Attr:%s", (const char*)ent, (const char*)attr);
1184 } 1184 }
1185 if (ch != '>') ch = skip_ws_end(); 1185 if (ch != '>') ch = skip_ws_end();
1186 /* 1186 /*
1187 if (isPageBreak) 1187 if (isPageBreak)
1188 { 1188 {
1189 ch = UEOF; 1189 ch = UEOF;
1190 } 1190 }
1191 else 1191 else
1192 { 1192 {
1193 */ 1193 */
1194 // if (stylestack.isEmpty()) 1194 // if (stylestack.isEmpty())
1195 // { 1195 // {
1196 currentstyle.unset(); 1196 currentstyle.unset();
1197 // } 1197 // }
1198 /* 1198 /*
1199 else 1199 else
1200 { 1200 {
1201 qDebug("Using stack style"); 1201 qDebug("Using stack style");
1202 currentstyle = stylestack.first(); 1202 currentstyle = stylestack.first();
1203 } 1203 }
1204 */ 1204 */
1205 lastch = 0; //Anything but 10 or ' ' 1205 lastch = 0; //Anything but 10 or ' '
1206 ch = 10; 1206 ch = 10;
1207 q += '-'; 1207 q += '-';
1208 q += QChar(parent->getwidth()); 1208 q += QChar(parent->getwidth());
1209 q += 3; 1209 q += 3;
1210 q += red; 1210 q += red;
1211 q += green; 1211 q += green;
1212 q += blue; 1212 q += blue;
1213 1213
1214 continue; 1214 continue;
1215 } 1215 }
1216 1216
1217 1217
1218 1218
1219 else if (ent == "img") 1219 else if (ent == "img")
1220 { 1220 {
1221 if (ch == ' ') ch = skip_ws(); 1221 if (ch == ' ') ch = skip_ws();
1222 while (ch != '>' && ch != UEOF) 1222 while (ch != '>' && ch != UEOF)
1223 { 1223 {
1224 QString ent = getname(ch, " =>").lower(); 1224 QString ent = getname(ch, " =>").lower();
1225 QString attr = getattr(ch); 1225 QString attr = getattr(ch);
1226 qDebug("<img>Entity:%s Attr:%s", (const char*)ent, (const char*)attr); 1226 qDebug("<img>Entity:%s Attr:%s", (const char*)ent, (const char*)attr);
1227 if (ent == "src") 1227 if (ent == "src")
1228 { 1228 {
1229 /* 1229 /*
1230 if (m_bchm) 1230 if (m_bchm)
1231 { 1231 {
1232 QImage* img = parent->getPicture(attr); 1232 QImage* img = parent->getPicture(attr);
1233 if (img != NULL) 1233 if (img != NULL)
1234 { 1234 {
1235 currentstyle.setPicture(true, img); 1235 currentstyle.setPicture(true, img);
1236 } 1236 }
1237 } 1237 }
1238 */ 1238 */
1239 1239
1240 1240
1241 QImage* img = parent->getPicture(attr); 1241 QImage* img = parent->getPicture(attr);
1242 if (img != NULL) 1242 if (img != NULL)
1243 { 1243 {
1244 currentstyle.setPicture(true, img); 1244 currentstyle.setPicture(true, img);
1245 } 1245 }
1246 else 1246 else
1247 { 1247 {
1248 QFileInfo f(currentfile); 1248 QFileInfo f(currentfile);
1249 QFileInfo f1(f.dir(true), attr); 1249 QFileInfo f1(f.dir(true), attr);
1250 QPixmap pm; 1250 QPixmap pm;
1251 if (pm.load(f1.absFilePath())) 1251 if (pm.load(f1.absFilePath()))
1252 { 1252 {
1253 QImage* img = new QImage(pm.convertToImage()); 1253 QImage* img = new QImage(pm.convertToImage());
1254 currentstyle.setPicture(true, img); 1254 currentstyle.setPicture(true, img);
1255 } 1255 }
1256 } 1256 }
1257 } 1257 }
1258 if (ent == "recindex") 1258 if (ent == "recindex")
1259 { 1259 {
1260 bool ok; 1260 bool ok;
1261 unsigned int picindex = attr.toUInt(&ok); 1261 unsigned int picindex = attr.toUInt(&ok);
1262 qDebug("Looking for image at %u", picindex); 1262 qDebug("Looking for image at %u", picindex);
1263 QImage* img = parent->getPicture(picindex); 1263 QImage* img = parent->getPicture(picindex);
1264 if (img != NULL) 1264 if (img != NULL)
1265 { 1265 {
1266 currentstyle.setPicture(true, img); 1266 currentstyle.setPicture(true, img);
1267 } 1267 }
1268 else 1268 else
1269 { 1269 {
1270 qDebug("No image found"); 1270 qDebug("No image found");
1271 } 1271 }
1272 } 1272 }
1273 } 1273 }
1274 if (ch != '>') ch = skip_ws_end(); 1274 if (ch != '>') ch = skip_ws_end();
1275 ch = '#'; 1275 ch = '#';
1276 break; 1276 break;
1277 } 1277 }
1278 else if (ent.left(2) == "dc") 1278 else if (ent.left(2) == "dc")
1279 { 1279 {
1280 QString nd("/"); 1280 QString nd("/");
1281 skipblock(nd+ent); 1281 skipblock(nd+ent);
1282 } 1282 }
1283 else if (ent == "metadata") 1283 else if (ent == "metadata")
1284 { 1284 {
1285 // skipblock("/metadata"); 1285 // skipblock("/metadata");
1286 } 1286 }
1287 else if (ent == "title") 1287 else if (ent == "title")
1288 { 1288 {
1289 skipblock("/title"); 1289 skipblock("/title");
1290 } 1290 }
1291 else if (ent == "head") 1291 else if (ent == "head")
1292 { 1292 {
1293 skipblock("/head"); 1293 skipblock("/head");
1294 } 1294 }
1295 /* 1295 /*
1296 else if (ent == "metadata") 1296 else if (ent == "metadata")
1297 { 1297 {
1298 currentstyle.setFontSize(-2); 1298 currentstyle.setFontSize(-2);
1299 } 1299 }
1300 else if (ent == "/metadata") 1300 else if (ent == "/metadata")
1301 { 1301 {
1302 currentstyle.unset(); 1302 currentstyle.unset();
1303 ch = 10; 1303 ch = 10;
1304 continue; 1304 continue;
1305 } 1305 }
1306 */ 1306 */
1307 else 1307 else
1308 { 1308 {
1309 if (ent[0] != '/') 1309 if (ent[0] != '/')
1310 qDebug("Not handling:%s", (const char*)ent); 1310 qDebug("Not handling:%s", (const char*)ent);
1311 } 1311 }
1312 1312
1313 if (ch != '>') ch = skip_ws_end(); 1313 if (ch != '>') ch = skip_ws_end();
1314 if (ent[0] == '/') 1314 if (ent[0] == '/')
1315 mygetch(ch, dummy, pos); 1315 mygetch(ch, dummy, pos);
1316 else 1316 else
1317 mygetch(ch, dummy, npos); 1317 mygetch(ch, dummy, npos);
1318 } 1318 }
1319 if (ch == '&') 1319 if (ch == '&')
1320 { 1320 {
1321 mygetch(ch, dummy, npos); 1321 mygetch(ch, dummy, npos);
1322 if (ch == '#') 1322 if (ch == '#')
1323 { 1323 {
1324 int id = 0; 1324 int id = 0;
1325 mygetch(ch, dummy, npos); 1325 mygetch(ch, dummy, npos);
1326 while (ch != ';' && ch != UEOF) 1326 while (ch != ';' && ch != UEOF)
1327 { 1327 {
1328 id = 10*id+ch-'0'; 1328 id = 10*id+ch-'0';
1329 mygetch(ch, dummy, npos); 1329 mygetch(ch, dummy, npos);
1330 } 1330 }
1331 ch = id; 1331 ch = id;
1332 } 1332 }
1333 else 1333 else
1334 { 1334 {
1335 QString en; 1335 QString en;
1336 en += ch; 1336 en += ch;
1337 mygetch(ch, dummy, npos); 1337 mygetch(ch, dummy, npos);
1338 while (ch != ';' && ch != UEOF) 1338 while (ch != ';' && ch != UEOF)
1339 { 1339 {
1340 en += ch; 1340 en += ch;
1341 mygetch(ch, dummy, npos); 1341 mygetch(ch, dummy, npos);
1342 } 1342 }
1343 if (entmap == NULL) initentmap(); 1343 if (entmap == NULL) initentmap();
1344#if defined(USEQPE) || defined(_WINDOWS) 1344#if defined(USEQPE) || defined(_WINDOWS)
1345 QMap<QString, tchar>::Iterator it = entmap->find(en); 1345 QMap<QString, tchar>::Iterator it = entmap->find(en);
1346#else 1346#else
1347 QMap<QString, tchar>::iterator it = entmap->find(en); 1347 QMap<QString, tchar>::iterator it = entmap->find(en);
1348#endif 1348#endif
1349 if (it != entmap->end()) 1349 if (it != entmap->end())
1350 { 1350 {
1351 ch = *it; 1351 ch = *it;
1352 } 1352 }
1353 else 1353 else
1354 { 1354 {
1355 ch = '.'; 1355 ch = '.';
1356 } 1356 }
1357 } 1357 }
1358 } 1358 }
1359 // sty = (dummy == ucFontBase) ? currentstyle : dummy; 1359 // sty = (dummy == ucFontBase) ? currentstyle : dummy;
1360 if (lastch == 10 && ch == 10 && sty.getExtraSpace() > currentstyle.getExtraSpace()) 1360 if (lastch == 10 && ch == 10 && sty.getExtraSpace() > currentstyle.getExtraSpace())
1361 { 1361 {
1362 currentstyle.setExtraSpace(sty.getExtraSpace()); 1362 currentstyle.setExtraSpace(sty.getExtraSpace());
1363 } 1363 }
1364 sty = currentstyle; 1364 sty = currentstyle;
1365 } 1365 }
1366 while (!isPre && (((lastch == ' ' || lastch == 10 || ignorespace) && ch == ' ') || ((ch == 10) && (lastch == 10)))); 1366 while (!isPre && (((lastch == ' ' || lastch == 10 || ignorespace) && ch == ' ') || ((ch == 10) && (lastch == 10))));
1367 // lastch = ch; 1367 // lastch = ch;
1368 lastch = ch; 1368 lastch = ch;
1369 return; 1369 return;
1370} 1370}
1371 1371
1372QString striphtml::getTableAsHtml(unsigned long loc) 1372QString striphtml::getTableAsHtml(unsigned long loc)
1373{ 1373{
1374 qDebug("striphtml::getTableAsHtml"); 1374 qDebug("striphtml::getTableAsHtml");
1375 QString ret; 1375 QString ret;
1376 tchar ch(0); 1376 tchar ch(0);
1377 CStyle sty; 1377 CStyle sty;
1378 unsigned long pos; 1378 unsigned long pos;
1379 locate(loc); 1379 locate(loc);
1380 int endpos(0); 1380 int endpos(0);
1381 QString endmarker("</table>"); 1381 QString endmarker("</table>");
1382 QString startmarker("<table"); 1382 QString startmarker("<table");
1383 int startpos(0); 1383 int startpos(0);
1384 int depth(0); 1384 int depth(0);
1385 while (ch != UEOF) 1385 while (ch != UEOF)
1386 { 1386 {
1387 parent->getch(ch, sty, pos); 1387 parent->getch(ch, sty, pos);
1388 QChar qc(ch); 1388 QChar qc(ch);
1389 ret += qc; 1389 ret += qc;
1390 if (qc.lower() == endmarker[endpos]) 1390 if (qc.lower() == endmarker[endpos])
1391 { 1391 {
1392 if ((++endpos >= endmarker.length()) && (--depth <= 0)) break; 1392 if ((++endpos >= endmarker.length()) && (--depth <= 0)) break;
1393 } 1393 }
1394 else 1394 else
1395 { 1395 {
1396 endpos = 0; 1396 endpos = 0;
1397 } 1397 }
1398 if (qc.lower() == startmarker[startpos]) 1398 if (qc.lower() == startmarker[startpos])
1399 { 1399 {
1400 if (++startpos >= startmarker.length()) ++depth; 1400 if (++startpos >= startmarker.length()) ++depth;
1401 } 1401 }
1402 else 1402 else
1403 { 1403 {
1404 startpos = 0; 1404 startpos = 0;
1405 } 1405 }
1406 } 1406 }
1407 return ret; 1407 return ret;
1408} 1408}
1409 1409
1410 1410
1411extern "C" 1411extern "C"
1412{ 1412{
1413 CFilter* newfilter(const QString& s) { return new striphtml(s); } 1413 CFilter* newfilter(const QString& s) { return new striphtml(s); }
1414} 1414}
diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.cpp b/noncore/apps/tinykate/libkate/document/katehighlight.cpp
index 89024f7..ee6030f 100644
--- a/noncore/apps/tinykate/libkate/document/katehighlight.cpp
+++ b/noncore/apps/tinykate/libkate/document/katehighlight.cpp
@@ -1,1468 +1,1470 @@
1/* 1/*
2 Copyright (C) 1998, 1999 Jochen Wilhelmy 2 Copyright (C) 1998, 1999 Jochen Wilhelmy
3 digisnap@cs.tu-berlin.de 3 digisnap@cs.tu-berlin.de
4 (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> 4 (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org>
5 (C) 2002 Joseph Wenninger <jowenn@kde.org> 5 (C) 2002 Joseph Wenninger <jowenn@kde.org>
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include "katehighlight.h" 22#include "katehighlight.h"
23#include "katetextline.h" 23#include "katetextline.h"
24#include "katedocument.h" 24#include "katedocument.h"
25#include "katesyntaxdocument.h" 25#include "katesyntaxdocument.h"
26 26
27#include "kglobal.h" 27#include "kglobal.h"
28//#include "kinstance.h" 28//#include "kinstance.h"
29//#include "kmimemagic.h" 29//#include "kmimemagic.h"
30#include "klocale.h" 30#include "klocale.h"
31//#include "kregexp.h" 31//#include "kregexp.h"
32#include "kglobalsettings.h" 32#include "kglobalsettings.h"
33#include "kdebug.h" 33#include "kdebug.h"
34#include "kstddirs.h" 34#include "kstddirs.h"
35 35
36/* OPIE */ 36/* OPIE */
37#include <opie2/odebug.h> 37#include <opie2/odebug.h>
38#include <qpe/config.h> 38#include <qpe/config.h>
39 39
40/* QT */ 40/* QT */
41#include <qtextstream.h> 41#include <qtextstream.h>
42 42
43/* STD */ 43/* STD */
44#include <string.h> 44#include <string.h>
45 45
46 46
47HlManager *HlManager::s_pSelf = 0; 47HlManager *HlManager::s_pSelf = 0;
48 48
49enum Item_styles { dsNormal,dsKeyword,dsDataType,dsDecVal,dsBaseN,dsFloat,dsChar,dsString,dsComment,dsOthers}; 49enum Item_styles { dsNormal,dsKeyword,dsDataType,dsDecVal,dsBaseN,dsFloat,dsChar,dsString,dsComment,dsOthers};
50 50
51static bool trueBool = true; 51static bool trueBool = true;
52static QString stdDeliminator = QString ("!%&()*+,-./:;<=>?[]^{|}~ \t\\"); 52static QString stdDeliminator = QString ("!%&()*+,-./:;<=>?[]^{|}~ \t\\");
53 53
54int getDefStyleNum(QString name) 54int getDefStyleNum(QString name)
55{ 55{
56 if (name=="dsNormal") return dsNormal; 56 if (name=="dsNormal") return dsNormal;
57 if (name=="dsKeyword") return dsKeyword; 57 if (name=="dsKeyword") return dsKeyword;
58 if (name=="dsDataType") return dsDataType; 58 if (name=="dsDataType") return dsDataType;
59 if (name=="dsDecVal") return dsDecVal; 59 if (name=="dsDecVal") return dsDecVal;
60 if (name=="dsBaseN") return dsBaseN; 60 if (name=="dsBaseN") return dsBaseN;
61 if (name=="dsFloat") return dsFloat; 61 if (name=="dsFloat") return dsFloat;
62 if (name=="dsChar") return dsChar; 62 if (name=="dsChar") return dsChar;
63 if (name=="dsString") return dsString; 63 if (name=="dsString") return dsString;
64 if (name=="dsComment") return dsComment; 64 if (name=="dsComment") return dsComment;
65 if (name=="dsOthers") return dsOthers; 65 if (name=="dsOthers") return dsOthers;
66 66
67 return dsNormal; 67 return dsNormal;
68} 68}
69 69
70bool ustrchr(const QChar *s, uint len, QChar c) 70bool ustrchr(const QChar *s, uint len, QChar c)
71{ 71{
72 for (int z=0; z < len; z++) 72 for (int z=0; z < len; z++)
73 { 73 {
74 if (*s == c) return true; 74 if (*s == c) return true;
75 s++; 75 s++;
76 } 76 }
77 77
78 return false; 78 return false;
79} 79}
80 80
81HlItem::HlItem(int attribute, int context) 81HlItem::HlItem(int attribute, int context)
82 : attr(attribute), ctx(context) {subItems=0; 82 : attr(attribute), ctx(context) {subItems=0;
83} 83}
84 84
85HlItem::~HlItem() 85HlItem::~HlItem()
86{ 86{
87 //kdDebug(13010)<<"In hlItem::~HlItem()"<<endl; 87 //kdDebug(13010)<<"In hlItem::~HlItem()"<<endl;
88 if (subItems!=0) {subItems->setAutoDelete(true); subItems->clear(); delete subItems;} 88 if (subItems!=0) {subItems->setAutoDelete(true); subItems->clear(); delete subItems;}
89} 89}
90 90
91bool HlItem::startEnable(QChar c) 91bool HlItem::startEnable(QChar c)
92{ 92{
93 return true; 93 return true;
94} 94}
95 95
96HlCharDetect::HlCharDetect(int attribute, int context, QChar c) 96HlCharDetect::HlCharDetect(int attribute, int context, QChar c)
97 : HlItem(attribute,context), sChar(c) { 97 : HlItem(attribute,context), sChar(c) {
98} 98}
99 99
100const QChar *HlCharDetect::checkHgl(const QChar *str, int len, bool) { 100const QChar *HlCharDetect::checkHgl(const QChar *str, int len, bool) {
101 if (*str == sChar) return str + 1; 101 if (*str == sChar) return str + 1;
102 return 0L; 102 return 0L;
103} 103}
104 104
105Hl2CharDetect::Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2) 105Hl2CharDetect::Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2)
106 : HlItem(attribute,context) { 106 : HlItem(attribute,context) {
107 sChar1 = ch1; 107 sChar1 = ch1;
108 sChar2 = ch2; 108 sChar2 = ch2;
109} 109}
110 110
111const QChar *Hl2CharDetect::checkHgl(const QChar *str, int len, bool) { 111const QChar *Hl2CharDetect::checkHgl(const QChar *str, int len, bool) {
112 if (str[0] == sChar1 && str[1] == sChar2) return str + 2; 112 if (str[0] == sChar1 && str[1] == sChar2) return str + 2;
113 return 0L; 113 return 0L;
114} 114}
115 115
116HlStringDetect::HlStringDetect(int attribute, int context, const QString &s, bool inSensitive) 116HlStringDetect::HlStringDetect(int attribute, int context, const QString &s, bool inSensitive)
117 : HlItem(attribute, context), str(inSensitive ? s.upper():s), _inSensitive(inSensitive) { 117 : HlItem(attribute, context), str(inSensitive ? s.upper():s), _inSensitive(inSensitive) {
118} 118}
119 119
120HlStringDetect::~HlStringDetect() { 120HlStringDetect::~HlStringDetect() {
121} 121}
122 122
123const QChar *HlStringDetect::checkHgl(const QChar *s, int len, bool) { 123const QChar *HlStringDetect::checkHgl(const QChar *s, int len, bool) {
124 if (!_inSensitive) {if (memcmp(s, str.unicode(), str.length()*sizeof(QChar)) == 0) return s + str.length();} 124 if (!_inSensitive) {if (memcmp(s, str.unicode(), str.length()*sizeof(QChar)) == 0) return s + str.length();}
125 else 125 else
126 { 126 {
127 QString tmp=QString(s,str.length()).upper(); 127 QString tmp=QString(s,str.length()).upper();
128 if (tmp==str) return s+str.length(); 128 if (tmp==str) return s+str.length();
129 } 129 }
130 return 0L; 130 return 0L;
131} 131}
132 132
133 133
134HlRangeDetect::HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2) 134HlRangeDetect::HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2)
135 : HlItem(attribute,context) { 135 : HlItem(attribute,context) {
136 sChar1 = ch1; 136 sChar1 = ch1;
137 sChar2 = ch2; 137 sChar2 = ch2;
138} 138}
139 139
140const QChar *HlRangeDetect::checkHgl(const QChar *s, int len, bool) { 140const QChar *HlRangeDetect::checkHgl(const QChar *s, int len, bool) {
141 if (*s == sChar1) 141 if (*s == sChar1)
142 { 142 {
143 do 143 do
144 { 144 {
145 s++; 145 s++;
146 len--; 146 len--;
147 if (len == 0) return 0L; 147 if (len == 0) return 0L;
148 } 148 }
149 while (*s != sChar2); 149 while (*s != sChar2);
150 150
151 return s + 1; 151 return s + 1;
152 } 152 }
153 return 0L; 153 return 0L;
154} 154}
155 155
156HlKeyword::HlKeyword (int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen) 156HlKeyword::HlKeyword (int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen)
157 : HlItem(attribute,context), dict (113, casesensitive) 157 : HlItem(attribute,context), dict (113, casesensitive)
158{ 158{
159 deliminatorChars = deliminator; 159 deliminatorChars = deliminator;
160 deliminatorLen = deliLen; 160 deliminatorLen = deliLen;
161 _caseSensitive=casesensitive; 161 _caseSensitive=casesensitive;
162} 162}
163 163
164HlKeyword::~HlKeyword() { 164HlKeyword::~HlKeyword() {
165} 165}
166 166
167bool HlKeyword::startEnable(QChar c) 167bool HlKeyword::startEnable(QChar c)
168{ 168{
169 return ustrchr(deliminatorChars, deliminatorLen, c); 169 return ustrchr(deliminatorChars, deliminatorLen, c);
170} 170}
171 171
172// If we use a dictionary for lookup we don't really need 172// If we use a dictionary for lookup we don't really need
173// an item as such we are using the key to lookup 173// an item as such we are using the key to lookup
174void HlKeyword::addWord(const QString &word) 174void HlKeyword::addWord(const QString &word)
175{ 175{
176 words.append(word); 176 words.append(word);
177 dict.insert(word,&trueBool); 177 dict.insert(word,&trueBool);
178} 178}
179 179
180void HlKeyword::addList(const QStringList& list) 180void HlKeyword::addList(const QStringList& list)
181{ 181{
182 182
183 words+=list; 183 words+=list;
184 for(uint i=0;i<list.count();i++) dict.insert(list[i], &trueBool); 184 for(uint i=0;i<list.count();i++) dict.insert(list[i], &trueBool);
185} 185}
186 186
187const QChar *HlKeyword::checkHgl(const QChar *s, int len, bool b) 187const QChar *HlKeyword::checkHgl(const QChar *s, int len, bool b)
188{ 188{
189 if (len == 0) return 0L; 189 if (len == 0) return 0L;
190 190
191 const QChar *s2 = s; 191 const QChar *s2 = s;
192 192
193 while ( (len > 0) && (!ustrchr(deliminatorChars, deliminatorLen, *s2)) ) 193 while ( (len > 0) && (!ustrchr(deliminatorChars, deliminatorLen, *s2)) )
194 { 194 {
195 s2++; 195 s2++;
196 len--; 196 len--;
197 } 197 }
198 198
199 if (s2 == s) return 0L; 199 if (s2 == s) return 0L;
200 200
201 QString lookup = QString(s,s2-s); 201 QString lookup = QString(s,s2-s);
202 202
203 if ( dict.find(lookup) ) return s2; 203 if ( dict.find(lookup) ) return s2;
204 return 0L; 204 return 0L;
205} 205}
206 206
207HlInt::HlInt(int attribute, int context) 207HlInt::HlInt(int attribute, int context)
208 : HlItem(attribute,context) { 208 : HlItem(attribute,context) {
209} 209}
210 210
211const QChar *HlInt::checkHgl(const QChar *str, int len, bool) { 211const QChar *HlInt::checkHgl(const QChar *str, int len, bool) {
212 const QChar *s,*s1; 212 const QChar *s,*s1;
213 213
214 s = str; 214 s = str;
215 while (s->isDigit()) s++; 215 while (s->isDigit()) s++;
216 if (s > str) 216 if (s > str)
217 { 217 {
218 if (subItems) 218 if (subItems)
219 { 219 {
220 for (HlItem *it=subItems->first();it;it=subItems->next()) 220 for (HlItem *it=subItems->first();it;it=subItems->next())
221 { 221 {
222 s1=it->checkHgl(s, len, false); 222 s1=it->checkHgl(s, len, false);
223 if (s1) return s1; 223 if (s1) return s1;
224 } 224 }
225 } 225 }
226 return s; 226 return s;
227 } 227 }
228 return 0L; 228 return 0L;
229} 229}
230 230
231HlFloat::HlFloat(int attribute, int context) 231HlFloat::HlFloat(int attribute, int context)
232 : HlItem(attribute,context) { 232 : HlItem(attribute,context) {
233} 233}
234 234
235const QChar *HlFloat::checkHgl(const QChar *s, int len, bool) { 235const QChar *HlFloat::checkHgl(const QChar *s, int len, bool) {
236 bool b, p; 236 bool b, p;
237 const QChar *s1; 237 const QChar *s1;
238 238
239 b = false; 239 b = false;
240 while (s->isDigit()){ 240 while (s->isDigit()){
241 s++; 241 s++;
242 b = true; 242 b = true;
243 } 243 }
244 if (p = (*s == '.')) { 244 if (p = (*s == '.')) {
245 s++; 245 s++;
246 while (s->isDigit()) { 246 while (s->isDigit()) {
247 s++; 247 s++;
248 b = true; 248 b = true;
249 } 249 }
250 } 250 }
251 if (!b) return 0L; 251 if (!b) return 0L;
252 if ((*s&0xdf) == 'E') s++; 252 if ((*s&0xdf) == 'E') s++;
253 else 253 else
254 if (!p) return 0L; 254 if (!p) return 0L;
255 else 255 else
256 { 256 {
257 if (subItems) 257 if (subItems)
258 { 258 {
259 for (HlItem *it=subItems->first();it;it=subItems->next()) 259 for (HlItem *it=subItems->first();it;it=subItems->next())
260 { 260 {
261 s1=it->checkHgl(s, len, false); 261 s1=it->checkHgl(s, len, false);
262 if (s1) return s1; 262 if (s1) return s1;
263 } 263 }
264 } 264 }
265 return s; 265 return s;
266 } 266 }
267 if ((*s == '-')||(*s =='+')) s++; 267 if ((*s == '-')||(*s =='+')) s++;
268 b = false; 268 b = false;
269 while (s->isDigit()) { 269 while (s->isDigit()) {
270 s++; 270 s++;
271 b = true; 271 b = true;
272 } 272 }
273 if (b) 273 if (b)
274 { 274 {
275 if (subItems) 275 if (subItems)
276 { 276 {
277 for (HlItem *it=subItems->first();it;it=subItems->next()) 277 for (HlItem *it=subItems->first();it;it=subItems->next())
278 { 278 {
279 s1=it->checkHgl(s, len, false); 279 s1=it->checkHgl(s, len, false);
280 if (s1) return s1; 280 if (s1) return s1;
281 } 281 }
282 } 282 }
283 return s; 283 return s;
284 } 284 }
285 else return 0L; 285 else return 0L;
286} 286}
287 287
288 288
289HlCInt::HlCInt(int attribute, int context) 289HlCInt::HlCInt(int attribute, int context)
290 : HlInt(attribute,context) { 290 : HlInt(attribute,context) {
291} 291}
292 292
293const QChar *HlCInt::checkHgl(const QChar *s, int len, bool lineStart) { 293const QChar *HlCInt::checkHgl(const QChar *s, int len, bool lineStart) {
294 294
295// if (*s == '0') s++; else s = HlInt::checkHgl(s); 295// if (*s == '0') s++; else s = HlInt::checkHgl(s);
296 s = HlInt::checkHgl(s, len, lineStart); 296 s = HlInt::checkHgl(s, len, lineStart);
297 if (s != 0L) { 297 if (s != 0L) {
298 int l = 0; 298 int l = 0;
299 int u = 0; 299 int u = 0;
300 const QChar *str; 300 const QChar *str;
301 301
302 do { 302 do {
303 str = s; 303 str = s;
304 if ((*s&0xdf) == 'L' ) { 304 if ((*s&0xdf) == 'L' ) {
305 l++; 305 l++;
306 if (l > 2) return 0L; 306 if (l > 2) return 0L;
307 s++; 307 s++;
308 } 308 }
309 if ((*s&0xdf) == 'U' ){ 309 if ((*s&0xdf) == 'U' ){
310 u++; 310 u++;
311 if (u > 1) return 0L; 311 if (u > 1) return 0L;
312 s++; 312 s++;
313 } 313 }
314 } while (s != str); 314 } while (s != str);
315 } 315 }
316 return s; 316 return s;
317} 317}
318 318
319HlCOct::HlCOct(int attribute, int context) 319HlCOct::HlCOct(int attribute, int context)
320 : HlItem(attribute,context) { 320 : HlItem(attribute,context) {
321} 321}
322 322
323const QChar *HlCOct::checkHgl(const QChar *str, int len, bool) { 323const QChar *HlCOct::checkHgl(const QChar *str, int len, bool) {
324 const QChar *s; 324 const QChar *s;
325 325
326 if (*str == '0') { 326 if (*str == '0') {
327 str++; 327 str++;
328 s = str; 328 s = str;
329 while (*s >= '0' && *s <= '7') s++; 329 while (*s >= '0' && *s <= '7') s++;
330 if (s > str) { 330 if (s > str) {
331 if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; 331 if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++;
332 return s; 332 return s;
333 } 333 }
334 } 334 }
335 return 0L; 335 return 0L;
336} 336}
337 337
338HlCHex::HlCHex(int attribute, int context) 338HlCHex::HlCHex(int attribute, int context)
339 : HlItem(attribute,context) { 339 : HlItem(attribute,context) {
340} 340}
341 341
342const QChar *HlCHex::checkHgl(const QChar *str, int len, bool) { 342const QChar *HlCHex::checkHgl(const QChar *str, int len, bool) {
343 const QChar *s=str; 343 const QChar *s=str;
344#if 0 344#if 0
345 int i; 345 int i;
346 for (i=0;(*s)!='\0';s++,i++); 346 for (i=0;(*s)!='\0';s++,i++);
347 QString line(str,i); 347 QString line(str,i);
348 QRegExp3 rx("0[xX][a-fA-F\\d]+[UuLl]?"); // this matches but is also matching parenthesis 348 QRegExp3 rx("0[xX][a-fA-F\\d]+[UuLl]?"); // this matches but is also matching parenthesis
349 int pos=rx.search(line,0); 349 int pos=rx.search(line,0);
350 if(pos > -1) return str+rx.matchedLength(); 350 if(pos > -1) return str+rx.matchedLength();
351 else 351 else
352 return 0L; 352 return 0L;
353 353
354#else 354#else
355 if (str[0] == '0' && ((str[1]&0xdf) == 'X' )) { 355 if (str[0] == '0' && ((str[1]&0xdf) == 'X' )) {
356 str += 2; 356 str += 2;
357 s = str; 357 s = str;
358 while (s->isDigit() || ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') /*|| (*s >= 'a' && *s <= 'f')*/) s++; 358 while (s->isDigit() || ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') /*|| (*s >= 'a' && *s <= 'f')*/) s++;
359 if (s > str) { 359 if (s > str) {
360 if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; 360 if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++;
361 return s; 361 return s;
362 } 362 }
363 } 363 }
364 return 0L; 364 return 0L;
365#endif 365#endif
366} 366}
367 367
368HlCFloat::HlCFloat(int attribute, int context) 368HlCFloat::HlCFloat(int attribute, int context)
369 : HlFloat(attribute,context) { 369 : HlFloat(attribute,context) {
370} 370}
371 371
372const QChar *HlCFloat::checkHgl(const QChar *s, int len, bool lineStart) { 372const QChar *HlCFloat::checkHgl(const QChar *s, int len, bool lineStart) {
373 373
374 s = HlFloat::checkHgl(s, len, lineStart); 374 s = HlFloat::checkHgl(s, len, lineStart);
375 if (s && ((*s&0xdf) == 'F' )) s++; 375 if (s && ((*s&0xdf) == 'F' )) s++;
376 return s; 376 return s;
377} 377}
378 378
379HlAnyChar::HlAnyChar(int attribute, int context, const QChar* charList, uint len) 379HlAnyChar::HlAnyChar(int attribute, int context, const QChar* charList, uint len)
380 : HlItem(attribute, context) { 380 : HlItem(attribute, context) {
381 _charList=charList; 381 _charList=charList;
382 _charListLen=len; 382 _charListLen=len;
383} 383}
384 384
385const QChar *HlAnyChar::checkHgl(const QChar *s, int len, bool) 385const QChar *HlAnyChar::checkHgl(const QChar *s, int len, bool)
386{ 386{
387 if (ustrchr(_charList, _charListLen, *s)) return s +1; 387 if (ustrchr(_charList, _charListLen, *s)) return s +1;
388 return 0L; 388 return 0L;
389} 389}
390 390
391HlRegExpr::HlRegExpr(int attribute, int context,QString regexp) 391HlRegExpr::HlRegExpr(int attribute, int context,QString regexp)
392 : HlItem(attribute, context), Expr(0) { 392 : HlItem(attribute, context), Expr(0) {
393 393
394 handlesLinestart=regexp.startsWith("^"); 394 handlesLinestart=regexp.startsWith("^");
395 if(!handlesLinestart) regexp.prepend("^"); 395 if(!handlesLinestart) regexp.prepend("^");
396 Expr=new QRegExp3(regexp); 396 Expr=new QRegExp3(regexp);
397} 397}
398 398
399HlRegExpr::~HlRegExpr() 399HlRegExpr::~HlRegExpr()
400{ 400{
401 delete Expr; 401 delete Expr;
402} 402}
403 403
404const QChar *HlRegExpr::checkHgl(const QChar *s, int len, bool lineStart) 404const QChar *HlRegExpr::checkHgl(const QChar *s, int len, bool lineStart)
405{ 405{
406 if ((!lineStart) && handlesLinestart) return 0; 406 if ((!lineStart) && handlesLinestart) return 0;
407 407
408 QString line(s,len); 408 QString line(s,len);
409 int pos = Expr->search( line, 0 ); 409 int pos = Expr->search( line, 0 );
410 if (pos==-1) return 0L; 410 if (pos==-1) return 0L;
411 else 411 else
412 return (s+Expr->matchedLength()); 412 return (s+Expr->matchedLength());
413}; 413};
414 414
415 415
416HlLineContinue::HlLineContinue(int attribute, int context) 416HlLineContinue::HlLineContinue(int attribute, int context)
417 : HlItem(attribute,context) { 417 : HlItem(attribute,context) {
418} 418}
419 419
420const QChar *HlLineContinue::checkHgl(const QChar *s, int len, bool) { 420const QChar *HlLineContinue::checkHgl(const QChar *s, int len, bool) {
421 421
422 if ((s[0].latin1() == '\\') && (len == 1)) 422 if ((s[0].latin1() == '\\') && (len == 1))
423 { 423 {
424 return s + 1; 424 return s + 1;
425 } 425 }
426 return 0L; 426 return 0L;
427} 427}
428 428
429 429
430HlCStringChar::HlCStringChar(int attribute, int context) 430HlCStringChar::HlCStringChar(int attribute, int context)
431 : HlItem(attribute,context) { 431 : HlItem(attribute,context) {
432} 432}
433 433
434//checks for hex and oct (for example \x1b or \033) 434//checks for hex and oct (for example \x1b or \033)
435const QChar *checkCharHexOct(const QChar *str) { 435const QChar *checkCharHexOct(const QChar *str) {
436 const QChar *s; 436 const QChar *s;
437 s=str; 437 s=str;
438 int n; 438 int n;
439 if (*s == 'x') { 439 if (*s == 'x') {
440 n = 0; 440 n = 0;
441 do { 441 do {
442 s++; 442 s++;
443 n *= 16; 443 n *= 16;
444 if (s->isDigit()) n += *s - '0'; 444 if (s->isDigit()) n += *s - '0';
445 else if ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') n += (*s&0xdf) - 'A' + 10; 445 else if ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') n += (*s&0xdf) - 'A' + 10;
446// else if (*s >= 'a' && *s <= 'f') n += *s - 'a' + 10; 446// else if (*s >= 'a' && *s <= 'f') n += *s - 'a' + 10;
447 else break; 447 else break;
448 if (n >= 256) return 0L; 448 if (n >= 256) return 0L;
449 } while (true); 449 } while (true);
450 if (s - str == 1) return 0L; 450 if (s - str == 1) return 0L;
451 } else { 451 } else {
452 if (!(*s >= '0' && *s <= '7')) return 0L; 452 if (!(*s >= '0' && *s <= '7')) return 0L;
453 n = *s - '0'; 453 n = *s - '0';
454 do { 454 do {
455 s++; 455 s++;
456 n *= 8; 456 n *= 8;
457 if (*s >= '0' && *s <= '7') n += *s - '0'; else break; 457 if (*s >= '0' && *s <= '7') n += *s - '0'; else break;
458 if (n >= 256) return s; 458 if (n >= 256) return s;
459 } while (s - str < 3); 459 } while (s - str < 3);
460 } 460 }
461 return s; 461 return s;
462} 462}
463// checks for C escaped chars \n and escaped hex/octal chars 463// checks for C escaped chars \n and escaped hex/octal chars
464const QChar *checkEscapedChar(const QChar *s, int len) { 464const QChar *checkEscapedChar(const QChar *s, int len) {
465 int i; 465 int i;
466 if (s[0] == '\\' && (len > 1) ) { 466 if (s[0] == '\\' && (len > 1) ) {
467 s++; 467 s++;
468 switch(*s){ 468 switch(*s){
469 case 'a': // checks for control chars 469 case 'a': // checks for control chars
470 case 'b': // we want to fall through 470 case 'b': // we want to fall through
471 case 'e': 471 case 'e':
472 case 'f': 472 case 'f':
473 473
474 case 'n': 474 case 'n':
475 case 'r': 475 case 'r':
476 case 't': 476 case 't':
477 case 'v': 477 case 'v':
478 case '\'': 478 case '\'':
479 case '\"': 479 case '\"':
480 case '?' : // added ? ANSI C classifies this as an escaped char 480 case '?' : // added ? ANSI C classifies this as an escaped char
481 case '\\': s++; 481 case '\\': s++;
482 break; 482 break;
483 case 'x': // if it's like \xff 483 case 'x': // if it's like \xff
484 s++; // eat the x 484 s++; // eat the x
485 // these for loops can probably be 485 // these for loops can probably be
486 // replaced with something else but 486 // replaced with something else but
487 // for right now they work 487 // for right now they work
488 // check for hexdigits 488 // check for hexdigits
489 for(i=0;i<2 &&(*s >= '0' && *s <= '9' || (*s&0xdf) >= 'A' && (*s&0xdf) <= 'F');i++,s++); 489 for(i=0;i<2 &&(*s >= '0' && *s <= '9' || (*s&0xdf) >= 'A' && (*s&0xdf) <= 'F');i++,s++);
490 if(i==0) return 0L; // takes care of case '\x' 490 if(i==0) return 0L; // takes care of case '\x'
491 break; 491 break;
492 492
493 case '0': case '1': case '2': case '3' : 493 case '0': case '1': case '2': case '3' :
494 case '4': case '5': case '6': case '7' : 494 case '4': case '5': case '6': case '7' :
495 for(i=0;i < 3 &&(*s >='0'&& *s<='7');i++,s++); 495 for(i=0;i < 3 &&(*s >='0'&& *s<='7');i++,s++);
496 break; 496 break;
497 default: return 0L; 497 default: return 0L;
498 } 498 }
499 return s; 499 return s;
500 } 500 }
501 return 0L; 501 return 0L;
502} 502}
503 503
504const QChar *HlCStringChar::checkHgl(const QChar *str, int len, bool) { 504const QChar *HlCStringChar::checkHgl(const QChar *str, int len, bool) {
505 return checkEscapedChar(str, len); 505 return checkEscapedChar(str, len);
506} 506}
507 507
508 508
509HlCChar::HlCChar(int attribute, int context) 509HlCChar::HlCChar(int attribute, int context)
510 : HlItem(attribute,context) { 510 : HlItem(attribute,context) {
511} 511}
512 512
513const QChar *HlCChar::checkHgl(const QChar *str, int len, bool) { 513const QChar *HlCChar::checkHgl(const QChar *str, int len, bool) {
514 const QChar *s; 514 const QChar *s;
515 515
516 if ((len > 1) && (str[0] == '\'') && (str[1] != '\'')) 516 if ((len > 1) && (str[0] == '\'') && (str[1] != '\''))
517 { 517 {
518 s = checkEscapedChar(&str[1], len); //try to match escaped char 518 s = checkEscapedChar(&str[1], len); //try to match escaped char
519 if (!s) s = &str[2]; //match single non-escaped char 519 if (!s) s = &str[2]; //match single non-escaped char
520 if (*s == '\'') return s + 1; 520 if (*s == '\'') return s + 1;
521 } 521 }
522 return 0L; 522 return 0L;
523} 523}
524 524
525 525
526//-------- 526//--------
527ItemStyle::ItemStyle() : selCol(Qt::white), bold(false), italic(false) { 527ItemStyle::ItemStyle() : selCol(Qt::white), bold(false), italic(false) {
528} 528}
529 529
530ItemStyle::ItemStyle(const QColor &col, const QColor &selCol, 530ItemStyle::ItemStyle(const QColor &col, const QColor &selCol,
531 bool bold, bool italic) 531 bool bold, bool italic)
532 : col(col), selCol(selCol), bold(bold), italic(italic) { 532 : col(col), selCol(selCol), bold(bold), italic(italic) {
533} 533}
534 534
535ItemData::ItemData(const QString name, int defStyleNum) 535ItemData::ItemData(const QString name, int defStyleNum)
536 : name(name), defStyleNum(defStyleNum), defStyle(true) { 536 : name(name), defStyleNum(defStyleNum), defStyle(true) {
537} 537}
538 538
539ItemData::ItemData(const QString name, int defStyleNum, 539ItemData::ItemData(const QString name, int defStyleNum,
540 const QColor &col, const QColor &selCol, bool bold, bool italic) 540 const QColor &col, const QColor &selCol, bool bold, bool italic)
541 : ItemStyle(col,selCol,bold,italic), name(name), defStyleNum(defStyleNum), 541 : ItemStyle(col,selCol,bold,italic), name(name), defStyleNum(defStyleNum),
542 defStyle(false) { 542 defStyle(false) {
543} 543}
544 544
545HlData::HlData(const QString &wildcards, const QString &mimetypes, const QString &identifier) 545HlData::HlData(const QString &wildcards, const QString &mimetypes, const QString &identifier)
546 : wildcards(wildcards), mimetypes(mimetypes), identifier(identifier) { 546 : wildcards(wildcards), mimetypes(mimetypes), identifier(identifier) {
547 547
548//JW itemDataList.setAutoDelete(true); 548//JW itemDataList.setAutoDelete(true);
549} 549}
550 550
551HlContext::HlContext(int attribute, int lineEndContext, int _lineBeginContext) 551HlContext::HlContext(int attribute, int lineEndContext, int _lineBeginContext)
552 : attr(attribute), ctx(lineEndContext),lineBeginContext(_lineBeginContext) { 552 : attr(attribute), ctx(lineEndContext),lineBeginContext(_lineBeginContext) {
553 items.setAutoDelete(true); 553 items.setAutoDelete(true);
554} 554}
555 555
556Hl2CharDetect::Hl2CharDetect(int attribute, int context, const QChar *s) 556Hl2CharDetect::Hl2CharDetect(int attribute, int context, const QChar *s)
557 : HlItem(attribute,context) { 557 : HlItem(attribute,context) {
558 sChar1 = s[0]; 558 sChar1 = s[0];
559 sChar2 = s[1]; 559 sChar2 = s[1];
560} 560}
561 561
562Highlight::Highlight(syntaxModeListItem *def) : refCount(0) 562Highlight::Highlight(syntaxModeListItem *def) : refCount(0)
563{ 563{
564 noHl = false; 564 noHl = false;
565 565
566 if (def == 0) 566 if (def == 0)
567 { 567 {
568 noHl = true; 568 noHl = true;
569 iName = I18N_NOOP("Normal"); 569 iName = I18N_NOOP("Normal");
570 iSection = ""; 570 iSection = "";
571 } 571 }
572 else 572 else
573 { 573 {
574 iName = def->name; 574 iName = def->name;
575 iSection = def->section; 575 iSection = def->section;
576 iWildcards = def->extension; 576 iWildcards = def->extension;
577 iMimetypes = def->mimetype; 577 iMimetypes = def->mimetype;
578 identifier = def->identifier; 578 identifier = def->identifier;
579 } 579 }
580 deliminator = stdDeliminator; 580 deliminator = stdDeliminator;
581 deliminatorChars = deliminator.unicode(); 581 deliminatorChars = deliminator.unicode();
582 deliminatorLen = deliminator.length(); 582 deliminatorLen = deliminator.length();
583} 583}
584 584
585Highlight::~Highlight() 585Highlight::~Highlight()
586{ 586{
587} 587}
588 588
589int Highlight::doHighlight(int ctxNum, TextLine *textLine) 589int Highlight::doHighlight(int ctxNum, TextLine *textLine)
590{ 590{
591 if (noHl) 591 if (noHl)
592 { 592 {
593 textLine->setAttribs(0,0,textLine->length()); 593 textLine->setAttribs(0,0,textLine->length());
594 textLine->setAttr(0); 594 textLine->setAttr(0);
595 return 0; 595 return 0;
596 } 596 }
597 597
598 HlContext *context; 598 HlContext *context;
599 const QChar *s2; 599 const QChar *s2;
600 HlItem *item; 600 HlItem *item;
601 601
602 context = contextList[ctxNum]; 602 context = contextList[ctxNum];
603 if (context->lineBeginContext!=-1) 603 if (context->lineBeginContext!=-1)
604 { 604 {
605 ctxNum=context->lineBeginContext; 605 ctxNum=context->lineBeginContext;
606 context=contextList[ctxNum]; 606 context=contextList[ctxNum];
607 } 607 }
608 608
609 QChar lastChar = ' '; 609 QChar lastChar = ' ';
610 610
611 // first char 611 // first char
612 const QChar *str = textLine->getText(); 612 const QChar *str = textLine->getText();
613 613
614 // non space char - index of that char 614 // non space char - index of that char
615 const QChar *s1 = textLine->firstNonSpace(); 615 const QChar *s1 = textLine->firstNonSpace();
616 uint z = textLine->firstChar(); 616 uint z = textLine->firstChar();
617 617
618 // length of textline 618 // length of textline
619 uint len = textLine->length(); 619 uint len = textLine->length();
620 620
621 bool found = false; 621 bool found = false;
622 while (z < len) 622 while (z < len)
623 { 623 {
624 found = false; 624 found = false;
625 625
626 for (item = context->items.first(); item != 0L; item = context->items.next()) 626 for (item = context->items.first(); item != 0L; item = context->items.next())
627 { 627 {
628 if (item->startEnable(lastChar)) 628 if (item->startEnable(lastChar))
629 { 629 {
630 s2 = item->checkHgl(s1, len-z, z==0); 630 s2 = item->checkHgl(s1, len-z, z==0);
631 if (s2 > s1) 631 if (s2 > s1)
632 { 632 {
633 odebug << "An item has been detected" << oendl; 633 odebug << "An item has been detected" << oendl;
634 textLine->setAttribs(item->attr,s1 - str,s2 - str); 634 textLine->setAttribs(item->attr,s1 - str,s2 - str);
635 ctxNum = item->ctx; 635 ctxNum = item->ctx;
636 context = contextList[ctxNum]; 636 context = contextList[ctxNum];
637 z = z + s2 - s1 - 1; 637 z = z + s2 - s1 - 1;
638 s1 = s2 - 1; 638 s1 = s2 - 1;
639 found = true; 639 found = true;
640 break; 640 break;
641 } 641 }
642 } 642 }
643 } 643 }
644 644
645 // nothing found: set attribute of one char 645 // nothing found: set attribute of one char
646 if (!found) 646 if (!found)
647 textLine->setAttribs(context->attr,s1 - str,s1 - str + 1); 647 textLine->setAttribs(context->attr,s1 - str,s1 - str + 1);
648 648
649 lastChar = *s1; 649 lastChar = *s1;
650 s1++; 650 s1++;
651 z++; 651 z++;
652 } 652 }
653 653
654 //set "end of line"-properties 654 //set "end of line"-properties
655 textLine->setAttr(context->attr); 655 textLine->setAttr(context->attr);
656 656
657 //return new context 657 //return new context
658 return context->ctx; 658 return context->ctx;
659} 659}
660 660
661KateConfig *Highlight::getKateConfig() { 661KateConfig *Highlight::getKateConfig() {
662 KateConfig *config; 662 KateConfig *config;
663 config=KGlobal::config(); 663 config=KGlobal::config();
664 config->setGroup(iName + QString(" Highlight")); 664 config->setGroup(iName + QString(" Highlight"));
665 return config; 665 return config;
666} 666}
667 667
668QString Highlight::getWildcards() { 668QString Highlight::getWildcards() {
669 KateConfig *config; 669 KateConfig *config;
670 670
671 config = getKateConfig(); 671 config = getKateConfig();
672 672
673 //if wildcards not yet in config, then use iWildCards as default 673 //if wildcards not yet in config, then use iWildCards as default
674 return config->readEntry("Wildcards", iWildcards); 674 return config->readEntry("Wildcards", iWildcards);
675} 675}
676 676
677 677
678QString Highlight::getMimetypes() { 678QString Highlight::getMimetypes() {
679 KateConfig *config; 679 KateConfig *config;
680 680
681 config = getKateConfig(); 681 config = getKateConfig();
682 682
683 return config->readEntry("Mimetypes", iMimetypes); 683 return config->readEntry("Mimetypes", iMimetypes);
684} 684}
685 685
686 686
687HlData *Highlight::getData() { 687HlData *Highlight::getData() {
688 KateConfig *config; 688 KateConfig *config;
689 HlData *hlData; 689 HlData *hlData;
690 690
691 config = getKateConfig(); 691 config = getKateConfig();
692 692
693// iWildcards = config->readEntry("Wildcards"); 693// iWildcards = config->readEntry("Wildcards");
694// iMimetypes = config->readEntry("Mimetypes"); 694// iMimetypes = config->readEntry("Mimetypes");
695// hlData = new HlData(iWildcards,iMimetypes); 695// hlData = new HlData(iWildcards,iMimetypes);
696 hlData = new HlData( 696 hlData = new HlData(
697 config->readEntry("Wildcards", iWildcards), 697 config->readEntry("Wildcards", iWildcards),
698 config->readEntry("Mimetypes", iMimetypes), 698 config->readEntry("Mimetypes", iMimetypes),
699 config->readEntry("Identifier", identifier)); 699 config->readEntry("Identifier", identifier));
700 getItemDataList(hlData->itemDataList, config); 700 getItemDataList(hlData->itemDataList, config);
701 return hlData; 701 return hlData;
702} 702}
703 703
704void Highlight::setData(HlData *hlData) { 704void Highlight::setData(HlData *hlData) {
705 KateConfig *config; 705 KateConfig *config;
706 706
707 config = getKateConfig(); 707 config = getKateConfig();
708 708
709// iWildcards = hlData->wildcards; 709// iWildcards = hlData->wildcards;
710// iMimetypes = hlData->mimetypes; 710// iMimetypes = hlData->mimetypes;
711 711
712 config->writeEntry("Wildcards",hlData->wildcards); 712 config->writeEntry("Wildcards",hlData->wildcards);
713 config->writeEntry("Mimetypes",hlData->mimetypes); 713 config->writeEntry("Mimetypes",hlData->mimetypes);
714 714
715 setItemDataList(hlData->itemDataList,config); 715 setItemDataList(hlData->itemDataList,config);
716} 716}
717 717
718void Highlight::getItemDataList(ItemDataList &list) { 718void Highlight::getItemDataList(ItemDataList &list) {
719 KateConfig *config; 719 KateConfig *config;
720 720
721 config = getKateConfig(); 721 config = getKateConfig();
722 getItemDataList(list, config); 722 getItemDataList(list, config);
723} 723}
724 724
725void Highlight::getItemDataList(ItemDataList &list, KateConfig *config) { 725void Highlight::getItemDataList(ItemDataList &list, KateConfig *config) {
726 ItemData *p; 726 ItemData *p;
727 QString s; 727 QString s;
728 QRgb col, selCol; 728 QRgb col, selCol;
729 729
730 list.clear(); 730 list.clear();
731//JW list.setAutoDelete(true); 731//JW list.setAutoDelete(true);
732 createItemData(list); 732 createItemData(list);
733 733
734 for (p = list.first(); p != 0L; p = list.next()) { 734 for (p = list.first(); p != 0L; p = list.next()) {
735 s = config->readEntry(p->name); 735 s = config->readEntry(p->name);
736 if (!s.isEmpty()) { 736 if (!s.isEmpty()) {
737 sscanf(s.latin1(),"%d,%X,%X,%d,%d", &p->defStyle,&col,&selCol,&p->bold,&p->italic); 737 sscanf(s.latin1(),"%d,%X,%X,%d,%d", &p->defStyle,&col,&selCol,&p->bold,&p->italic);
738 p->col.setRgb(col); 738 p->col.setRgb(col);
739 p->selCol.setRgb(selCol); 739 p->selCol.setRgb(selCol);
740 } 740 }
741 } 741 }
742} 742}
743 743
744/******************************************************************************************* 744/*******************************************************************************************
745 Highlight - setItemDataList 745 Highlight - setItemDataList
746 saves the ItemData / attribute / style definitions to the apps configfile. 746 saves the ItemData / attribute / style definitions to the apps configfile.
747 Especially needed for user overridden values. 747 Especially needed for user overridden values.
748 748
749 * input: ItemDataList &list :reference to the list, whose 749 * input: ItemDataList &list :reference to the list, whose
750 * items should be saved 750 * items should be saved
751 * KateConfig *config :Pointer KDE configuration 751 * KateConfig *config :Pointer KDE configuration
752 * class, which should be used 752 * class, which should be used
753 * as storage 753 * as storage
754 ************* 754 *************
755 * output: none 755 * output: none
756 ************* 756 *************
757 * return value: none 757 * return value: none
758*******************************************************************************************/ 758*******************************************************************************************/
759 759
760void Highlight::setItemDataList(ItemDataList &list, KateConfig *config) { 760void Highlight::setItemDataList(ItemDataList &list, KateConfig *config) {
761 ItemData *p; 761 ItemData *p;
762 QString s; 762 QString s;
763 763
764 for (p = list.first(); p != 0L; p = list.next()) { 764 for (p = list.first(); p != 0L; p = list.next()) {
765 s.sprintf("%d,%X,%X,%d,%d", 765 s.sprintf("%d,%X,%X,%d,%d",
766 p->defStyle,p->col.rgb(),p->selCol.rgb(),p->bold,p->italic); 766 p->defStyle,p->col.rgb(),p->selCol.rgb(),p->bold,p->italic);
767 config->writeEntry(p->name,s); 767 config->writeEntry(p->name,s);
768 } 768 }
769} 769}
770 770
771 771
772/******************************************************************************************* 772/*******************************************************************************************
773 Highlight - use 773 Highlight - use
774 Increase the usage count and trigger initialization if needed 774 Increase the usage count and trigger initialization if needed
775 775
776 * input: none 776 * input: none
777 ************* 777 *************
778 * output: none 778 * output: none
779 ************* 779 *************
780 * return value: none 780 * return value: none
781*******************************************************************************************/ 781*******************************************************************************************/
782 782
783void Highlight::use() 783void Highlight::use()
784{ 784{
785 if (refCount == 0) init(); 785 if (refCount == 0) init();
786 refCount++; 786 refCount++;
787} 787}
788 788
789 789
790/******************************************************************************************* 790/*******************************************************************************************
791 Highlight - release 791 Highlight - release
792 Decrease the usage count and trigger a cleanup if needed 792 Decrease the usage count and trigger a cleanup if needed
793 793
794 * input: none 794 * input: none
795 ************* 795 *************
796 * output: none 796 * output: none
797 ************* 797 *************
798 * return value: none 798 * return value: none
799*******************************************************************************************/ 799*******************************************************************************************/
800 800
801void Highlight::release() 801void Highlight::release()
802{ 802{
803 refCount--; 803 refCount--;
804 if (refCount == 0) done(); 804 if (refCount == 0) done();
805} 805}
806 806
807/******************************************************************************************* 807/*******************************************************************************************
808 Highlight - init 808 Highlight - init
809 If it's the first time a particular highlighting is used create the needed contextlist 809 If it's the first time a particular highlighting is used create the needed contextlist
810 810
811 * input: none 811 * input: none
812 ************* 812 *************
813 * output: none 813 * output: none
814 ************* 814 *************
815 * return value: none 815 * return value: none
816*******************************************************************************************/ 816*******************************************************************************************/
817 817
818void Highlight::init() 818void Highlight::init()
819{ 819{
820 if (noHl) 820 if (noHl)
821 return; 821 return;
822 822
823 for (int z = 0; z < nContexts; z++) contextList[z] = 0L; 823 for (int z = 0; z < nContexts; z++) contextList[z] = 0L;
824 makeContextList(); 824 makeContextList();
825} 825}
826 826
827 827
828/******************************************************************************************* 828/*******************************************************************************************
829 Highlight - done 829 Highlight - done
830 If the there is no document using the highlighting style free the complete context 830 If the there is no document using the highlighting style free the complete context
831 structure. 831 structure.
832 832
833 * input: none 833 * input: none
834 ************* 834 *************
835 * output: none 835 * output: none
836 ************* 836 *************
837 * return value: none 837 * return value: none
838*******************************************************************************************/ 838*******************************************************************************************/
839 839
840void Highlight::done() 840void Highlight::done()
841{ 841{
842 if (noHl) 842 if (noHl)
843 return; 843 return;
844 844
845 for (int z = 0; z < nContexts; z++) delete contextList[z]; 845 for (int z = 0; z < nContexts; z++) delete contextList[z];
846} 846}
847 847
848 848
849/******************************************************************************************* 849/*******************************************************************************************
850 Highlight - createItemData 850 Highlight - createItemData
851 This function reads the itemData entries from the config file, which specifies the 851 This function reads the itemData entries from the config file, which specifies the
852 default attribute styles for matched items/contexts. 852 default attribute styles for matched items/contexts.
853 853
854 * input: none 854 * input: none
855 ************* 855 *************
856 * output: ItemDataList &list :A reference to the internal 856 * output: ItemDataList &list :A reference to the internal
857 list containing the parsed 857 list containing the parsed
858 default config 858 default config
859 ************* 859 *************
860 * return value: none 860 * return value: none
861*******************************************************************************************/ 861*******************************************************************************************/
862 862
863void Highlight::createItemData(ItemDataList &list) 863void Highlight::createItemData(ItemDataList &list)
864{ 864{
865 odebug << "Highlight::createItemData" << oendl; 865 odebug << "Highlight::createItemData" << oendl;
866 866
867 // If no highlighting is selected we need only one default. 867 // If no highlighting is selected we need only one default.
868 if (noHl) 868 if (noHl)
869 { 869 {
870 list.append(new ItemData(I18N_NOOP("Normal Text"), dsNormal)); 870 list.append(new ItemData(I18N_NOOP("Normal Text"), dsNormal));
871 return; 871 return;
872 } 872 }
873 873
874 QString color; 874 QString color;
875 QString selColor; 875 QString selColor;
876 QString bold; 876 QString bold;
877 QString italic; 877 QString italic;
878 878
879 // If the internal list isn't already available read the config file 879 // If the internal list isn't already available read the config file
880 if (internalIDList.count()==0) 880 if (internalIDList.count()==0)
881 { 881 {
882 //if all references to the list are destried the contents will also be deleted 882 //if all references to the list are destried the contents will also be deleted
883 internalIDList.setAutoDelete(true); 883 internalIDList.setAutoDelete(true);
884 syntaxContextData *data; 884 syntaxContextData *data;
885 885
886 odebug << "Trying to read itemData section" << oendl; 886 odebug << "Trying to read itemData section" << oendl;
887 887
888 //Tell the syntax document class which file we want to parse and which data group 888 //Tell the syntax document class which file we want to parse and which data group
889 HlManager::self()->syntax->setIdentifier(identifier); 889 HlManager::self()->syntax->setIdentifier(identifier);
890 data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData"); 890 data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData");
891 //begin with the real parsing 891 //begin with the real parsing
892 while (HlManager::self()->syntax->nextGroup(data)) 892 while (HlManager::self()->syntax->nextGroup(data))
893 { 893 {
894 odebug << "Setting up one itemData element" << oendl; 894 odebug << "Setting up one itemData element" << oendl;
895 // read all attributes 895 // read all attributes
896 color=HlManager::self()->syntax->groupData(data,QString("color")); 896 color=HlManager::self()->syntax->groupData(data,QString("color"));
897 selColor=HlManager::self()->syntax->groupData(data,QString("selColor")); 897 selColor=HlManager::self()->syntax->groupData(data,QString("selColor"));
898 bold=HlManager::self()->syntax->groupData(data,QString("bold")); 898 bold=HlManager::self()->syntax->groupData(data,QString("bold"));
899 italic=HlManager::self()->syntax->groupData(data,QString("italic")); 899 italic=HlManager::self()->syntax->groupData(data,QString("italic"));
900 //check if the user overrides something 900 //check if the user overrides something
901 if ( (!color.isEmpty()) && (!selColor.isEmpty()) && (!bold.isEmpty()) && (!italic.isEmpty())) 901 if ( (!color.isEmpty()) && (!selColor.isEmpty()) && (!bold.isEmpty()) && (!italic.isEmpty()))
902 { 902 {
903 //create a user defined style 903 //create a user defined style
904 internalIDList.append(new ItemData( 904 internalIDList.append(new ItemData(
905 HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), 905 HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(),
906 getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))), 906 getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))),
907 QColor(color),QColor(selColor),(bold=="true") || (bold=="1"), (italic=="true") || (italic=="1") 907 QColor(color),QColor(selColor),(bold=="true") || (bold=="1"), (italic=="true") || (italic=="1")
908 )); 908 ));
909 } 909 }
910 else 910 else
911 { 911 {
912 //assign a default style 912 //assign a default style
913 internalIDList.append(new ItemData( 913 internalIDList.append(new ItemData(
914 HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), 914 HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(),
915 getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))))); 915 getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum")))));
916 916
917 } 917 }
918 } 918 }
919 //clean up 919 //clean up
920 if (data) HlManager::self()->syntax->freeGroupInfo(data); 920 if (data) HlManager::self()->syntax->freeGroupInfo(data);
921 } 921 }
922 922
923 //set the ouput reference 923 //set the ouput reference
924 list=internalIDList; 924 list=internalIDList;
925} 925}
926 926
927 927
928/******************************************************************************************* 928/*******************************************************************************************
929 Highlight - lookupAttrName 929 Highlight - lookupAttrName
930 This function is a helper for makeContextList and createHlItem. It looks the given 930 This function is a helper for makeContextList and createHlItem. It looks the given
931 attribute name in the itemData list up and returns it's index 931 attribute name in the itemData list up and returns it's index
932 932
933 * input: QString &name :the attribute name to lookup 933 * input: QString &name :the attribute name to lookup
934 * ItemDataList &iDl :the list containing all 934 * ItemDataList &iDl :the list containing all
935 * available attributes 935 * available attributes
936 ************* 936 *************
937 * output: none 937 * output: none
938 ************* 938 *************
939 * return value: int :The index of the attribute 939 * return value: int :The index of the attribute
940 * or 0 940 * or 0
941*******************************************************************************************/ 941*******************************************************************************************/
942 942
943int Highlight::lookupAttrName(const QString& name, ItemDataList &iDl) 943int Highlight::lookupAttrName(const QString& name, ItemDataList &iDl)
944{ 944{
945 for (int i=0;i<iDl.count();i++) 945 for (int i=0;i<iDl.count();i++)
946 { 946 {
947 if (iDl.at(i)->name==name) return i; 947 if (iDl.at(i)->name==name) return i;
948 } 948 }
949 kdDebug(13010)<<"Couldn't resolve itemDataName"<<endl; 949 kdDebug(13010)<<"Couldn't resolve itemDataName"<<endl;
950 return 0; 950 return 0;
951} 951}
952 952
953 953
954/******************************************************************************************* 954/*******************************************************************************************
955 Highlight - createHlItem 955 Highlight - createHlItem
956 This function is a helper for makeContextList. It parses the xml file for 956 This function is a helper for makeContextList. It parses the xml file for
957 information, how single or multi line comments are marked 957 information, how single or multi line comments are marked
958 958
959 * input: syntaxContextData *data : Data about the item read from 959 * input: syntaxContextData *data : Data about the item read from
960 * the xml file 960 * the xml file
961 * ItemDataList &iDl : List of all available itemData 961 * ItemDataList &iDl : List of all available itemData
962 * entries. Needed for attribute 962 * entries. Needed for attribute
963 * name->index translation 963 * name->index translation
964 ************* 964 *************
965 * output: none 965 * output: none
966 ************* 966 *************
967 * return value: HlItem * : Pointer to the newly created item 967 * return value: HlItem * : Pointer to the newly created item
968 * object 968 * object
969*******************************************************************************************/ 969*******************************************************************************************/
970 970
971HlItem *Highlight::createHlItem(syntaxContextData *data, ItemDataList &iDl) 971HlItem *Highlight::createHlItem(syntaxContextData *data, ItemDataList &iDl)
972{ 972{
973 // No highlighting -> exit 973 // No highlighting -> exit
974 if (noHl) 974 if (noHl)
975 return 0; 975 return 0;
976 976
977 // get the (tagname) itemd type 977 // get the (tagname) itemd type
978 QString dataname=HlManager::self()->syntax->groupItemData(data,QString("")); 978 QString dataname=HlManager::self()->syntax->groupItemData(data,QString(""));
979 979
980 // BEGIN - Translation of the attribute parameter 980 // BEGIN - Translation of the attribute parameter
981 QString tmpAttr=HlManager::self()->syntax->groupItemData(data,QString("attribute")).simplifyWhiteSpace(); 981 QString tmpAttr=HlManager::self()->syntax->groupItemData(data,QString("attribute")).simplifyWhiteSpace();
982 int attr; 982 int attr;
983 if (QString("%1").arg(tmpAttr.toInt())==tmpAttr) 983 if (QString("%1").arg(tmpAttr.toInt())==tmpAttr)
984 attr=tmpAttr.toInt(); 984 attr=tmpAttr.toInt();
985 else 985 else
986 attr=lookupAttrName(tmpAttr,iDl); 986 attr=lookupAttrName(tmpAttr,iDl);
987 // END - Translation of the attribute parameter 987 // END - Translation of the attribute parameter
988 988
989 // Info about context switch 989 // Info about context switch
990 int context=((HlManager::self()->syntax->groupItemData(data,QString("context"))).toInt()); 990 int context=((HlManager::self()->syntax->groupItemData(data,QString("context"))).toInt());
991 991
992 // Get the char parameter (eg DetectChar) 992 // Get the char parameter (eg DetectChar)
993 char chr; 993 char chr;
994 if (! HlManager::self()->syntax->groupItemData(data,QString("char")).isEmpty()) 994 if (! HlManager::self()->syntax->groupItemData(data,QString("char")).isEmpty())
995 chr= (HlManager::self()->syntax->groupItemData(data,QString("char")).latin1())[0]; 995 chr= (HlManager::self()->syntax->groupItemData(data,QString("char")).latin1())[0];
996 else 996 else
997 chr=0; 997 chr=0;
998 998
999 // Get the String parameter (eg. StringDetect) 999 // Get the String parameter (eg. StringDetect)
1000 QString stringdata=HlManager::self()->syntax->groupItemData(data,QString("String")); 1000 QString stringdata=HlManager::self()->syntax->groupItemData(data,QString("String"));
1001 1001
1002 // Get a second char parameter (char1) (eg Detect2Chars) 1002 // Get a second char parameter (char1) (eg Detect2Chars)
1003 char chr1; 1003 char chr1;
1004 if (! HlManager::self()->syntax->groupItemData(data,QString("char1")).isEmpty()) 1004 if (! HlManager::self()->syntax->groupItemData(data,QString("char1")).isEmpty())
1005 chr1= (HlManager::self()->syntax->groupItemData(data,QString("char1")).latin1())[0]; 1005 chr1= (HlManager::self()->syntax->groupItemData(data,QString("char1")).latin1())[0];
1006 else 1006 else
1007 chr1=0; 1007 chr1=0;
1008 1008
1009 // Will be removed eventuall. Atm used for StringDetect 1009 // Will be removed eventuall. Atm used for StringDetect
1010 bool insensitive=(HlManager::self()->syntax->groupItemData(data,QString("insensitive"))==QString("TRUE")); 1010 bool insensitive=(HlManager::self()->syntax->groupItemData(data,QString("insensitive"))==QString("TRUE"));
1011 1011
1012 1012
1013 //Create the item corresponding to it's type and set it's parameters 1013 //Create the item corresponding to it's type and set it's parameters
1014 if (dataname=="keyword") 1014 if (dataname=="keyword")
1015 { 1015 {
1016 HlKeyword *keyword=new HlKeyword(attr,context,casesensitive, 1016 HlKeyword *keyword=new HlKeyword(attr,context,casesensitive,
1017 deliminatorChars, deliminatorLen); 1017 deliminatorChars, deliminatorLen);
1018 1018
1019 //Get the entries for the keyword lookup list 1019 //Get the entries for the keyword lookup list
1020 keyword->addList(HlManager::self()->syntax->finddata("highlighting",stringdata)); 1020 keyword->addList(HlManager::self()->syntax->finddata("highlighting",stringdata));
1021 return keyword; 1021 return keyword;
1022 } else 1022 } else
1023 if (dataname=="Float") return (new HlFloat(attr,context)); else 1023 if (dataname=="Float") return (new HlFloat(attr,context)); else
1024 if (dataname=="Int") return(new HlInt(attr,context)); else 1024 if (dataname=="Int") return(new HlInt(attr,context)); else
1025 if (dataname=="DetectChar") return(new HlCharDetect(attr,context,chr)); else 1025 if (dataname=="DetectChar") return(new HlCharDetect(attr,context,chr)); else
1026 if (dataname=="Detect2Chars") return(new Hl2CharDetect(attr,context,chr,chr1)); else 1026 if (dataname=="Detect2Chars") return(new Hl2CharDetect(attr,context,chr,chr1)); else
1027 if (dataname=="RangeDetect") return(new HlRangeDetect(attr,context, chr, chr1)); else 1027 if (dataname=="RangeDetect") return(new HlRangeDetect(attr,context, chr, chr1)); else
1028 if (dataname=="LineContinue") return(new HlLineContinue(attr,context)); else 1028 if (dataname=="LineContinue") return(new HlLineContinue(attr,context)); else
1029 if (dataname=="StringDetect") return(new HlStringDetect(attr,context,stringdata,insensitive)); else 1029 if (dataname=="StringDetect") return(new HlStringDetect(attr,context,stringdata,insensitive)); else
1030 if (dataname=="AnyChar") return(new HlAnyChar(attr,context,stringdata.unicode(), stringdata.length())); else 1030 if (dataname=="AnyChar") return(new HlAnyChar(attr,context,stringdata.unicode(), stringdata.length())); else
1031 if (dataname=="RegExpr") return(new HlRegExpr(attr,context,stringdata)); else 1031 if (dataname=="RegExpr") return(new HlRegExpr(attr,context,stringdata)); else
1032 if(dataname=="HlCChar") return ( new HlCChar(attr,context));else 1032 if(dataname=="HlCChar") return ( new HlCChar(attr,context));else
1033 if(dataname=="HlCHex") return (new HlCHex(attr,context));else 1033 if(dataname=="HlCHex") return (new HlCHex(attr,context));else
1034 if(dataname=="HlCOct") return (new HlCOct(attr,context)); else 1034 if(dataname=="HlCOct") return (new HlCOct(attr,context)); else
1035 if(dataname=="HlCStringChar") return (new HlCStringChar(attr,context)); else 1035 if(dataname=="HlCStringChar") return (new HlCStringChar(attr,context)); else
1036 1036
1037 { 1037 {
1038 // oops, unknown type. Perhaps a spelling error in the xml file 1038 // oops, unknown type. Perhaps a spelling error in the xml file
1039 return 0; 1039 return 0;
1040 } 1040 }
1041 1041
1042 1042
1043} 1043}
1044 1044
1045 1045
1046/******************************************************************************************* 1046/*******************************************************************************************
1047 Highlight - isInWord 1047 Highlight - isInWord
1048 1048
1049 * input: Qchar c Character to investigate 1049 * input: Qchar c Character to investigate
1050 ************* 1050 *************
1051 * output: none 1051 * output: none
1052 ************* 1052 *************
1053 * return value: returns true, if c is no deliminator 1053 * return value: returns true, if c is no deliminator
1054*******************************************************************************************/ 1054*******************************************************************************************/
1055 1055
1056bool Highlight::isInWord(QChar c) 1056bool Highlight::isInWord(QChar c)
1057{ 1057{
1058 return !ustrchr(deliminatorChars, deliminatorLen, c); 1058 return !ustrchr(deliminatorChars, deliminatorLen, c);
1059} 1059}
1060 1060
1061 1061
1062 1062
1063/******************************************************************************************* 1063/*******************************************************************************************
1064 Highlight - readCommentConfig 1064 Highlight - readCommentConfig
1065 This function is a helper for makeContextList. It parses the xml file for 1065 This function is a helper for makeContextList. It parses the xml file for
1066 information, how single or multi line comments are marked 1066 information, how single or multi line comments are marked
1067 1067
1068 * input: none 1068 * input: none
1069 ************* 1069 *************
1070 * output: none 1070 * output: none
1071 ************* 1071 *************
1072 * return value: none 1072 * return value: none
1073*******************************************************************************************/ 1073*******************************************************************************************/
1074 1074
1075void Highlight::readCommentConfig() 1075void Highlight::readCommentConfig()
1076{ 1076{
1077 1077
1078 cslStart = ""; 1078 cslStart = "";
1079 HlManager::self()->syntax->setIdentifier(identifier); 1079 HlManager::self()->syntax->setIdentifier(identifier);
1080 1080
1081 syntaxContextData *data=HlManager::self()->syntax->getGroupInfo("general","comment"); 1081 syntaxContextData *data=HlManager::self()->syntax->getGroupInfo("general","comment");
1082 if (data) 1082 if (data)
1083 { 1083 {
1084// kdDebug(13010)<<"COMMENT DATA FOUND"<<endl; 1084// kdDebug(13010)<<"COMMENT DATA FOUND"<<endl;
1085 while (HlManager::self()->syntax->nextGroup(data)) 1085 while (HlManager::self()->syntax->nextGroup(data))
1086 { 1086 {
1087 1087
1088 if (HlManager::self()->syntax->groupData(data,"name")=="singleLine") 1088 if (HlManager::self()->syntax->groupData(data,"name")=="singleLine")
1089 cslStart=HlManager::self()->syntax->groupData(data,"start"); 1089 cslStart=HlManager::self()->syntax->groupData(data,"start");
1090 if (HlManager::self()->syntax->groupData(data,"name")=="multiLine") 1090 if (HlManager::self()->syntax->groupData(data,"name")=="multiLine")
1091 { 1091 {
1092 cmlStart=HlManager::self()->syntax->groupData(data,"start"); 1092 cmlStart=HlManager::self()->syntax->groupData(data,"start");
1093 cmlEnd=HlManager::self()->syntax->groupData(data,"end"); 1093 cmlEnd=HlManager::self()->syntax->groupData(data,"end");
1094 } 1094 }
1095 } 1095 }
1096 HlManager::self()->syntax->freeGroupInfo(data); 1096 HlManager::self()->syntax->freeGroupInfo(data);
1097 } 1097 }
1098 1098
1099} 1099}
1100 1100
1101/******************************************************************************************* 1101/*******************************************************************************************
1102 Highlight - readGlobalKeyWordConfig 1102 Highlight - readGlobalKeyWordConfig
1103 This function is a helper for makeContextList. It parses the xml file for 1103 This function is a helper for makeContextList. It parses the xml file for
1104 information, if keywords should be treated case(in)sensitive and creates the keyword 1104 information, if keywords should be treated case(in)sensitive and creates the keyword
1105 delimiter list. Which is the default list, without any given weak deliminiators 1105 delimiter list. Which is the default list, without any given weak deliminiators
1106 1106
1107 * input: none 1107 * input: none
1108 ************* 1108 *************
1109 * output: none 1109 * output: none
1110 ************* 1110 *************
1111 * return value: none 1111 * return value: none
1112*******************************************************************************************/ 1112*******************************************************************************************/
1113 1113
1114 1114
1115void Highlight::readGlobalKeywordConfig() 1115void Highlight::readGlobalKeywordConfig()
1116{ 1116{
1117 // Tell the syntax document class which file we want to parse 1117 // Tell the syntax document class which file we want to parse
1118 HlManager::self()->syntax->setIdentifier(identifier); 1118 HlManager::self()->syntax->setIdentifier(identifier);
1119 1119
1120 // Get the keywords config entry 1120 // Get the keywords config entry
1121 syntaxContextData * data=HlManager::self()->syntax->getConfig("general","keywords"); 1121 syntaxContextData * data=HlManager::self()->syntax->getConfig("general","keywords");
1122 if (data) 1122 if (data)
1123 { 1123 {
1124 kdDebug(13010)<<"Found global keyword config"<<endl; 1124 kdDebug(13010)<<"Found global keyword config"<<endl;
1125 1125
1126 if (HlManager::self()->syntax->groupItemData(data,QString("casesensitive"))!="0") 1126 if (HlManager::self()->syntax->groupItemData(data,QString("casesensitive"))!="0")
1127 casesensitive=true; else {casesensitive=false; kdDebug(13010)<<"Turning on case insensitiveness"<<endl;} 1127 casesensitive=true; else {casesensitive=false; kdDebug(13010)<<"Turning on case insensitiveness"<<endl;}
1128 //get the weak deliminators 1128 //get the weak deliminators
1129 weakDeliminator=(!HlManager::self()->syntax->groupItemData(data,QString("weakDeliminator"))); 1129 weakDeliminator=(!HlManager::self()->syntax->groupItemData(data,QString("weakDeliminator")));
1130 1130
1131 // remove any weakDelimitars (if any) from the default list and store this list. 1131 // remove any weakDelimitars (if any) from the default list and store this list.
1132 int f; 1132 int f;
1133 for (int s=0; s < weakDeliminator.length(); s++) 1133 for (int s=0; s < weakDeliminator.length(); s++)
1134 { 1134 {
1135 f = 0; 1135 f = 0;
1136 f = deliminator.find (weakDeliminator[s]); 1136 f = deliminator.find (weakDeliminator[s]);
1137 1137
1138 if (f > -1) 1138 if (f > -1)
1139 deliminator.remove (f, 1); 1139 deliminator.remove (f, 1);
1140 } 1140 }
1141 1141
1142 deliminatorChars = deliminator.unicode(); 1142 deliminatorChars = deliminator.unicode();
1143 deliminatorLen = deliminator.length(); 1143 deliminatorLen = deliminator.length();
1144 1144
1145 HlManager::self()->syntax->freeGroupInfo(data); 1145 HlManager::self()->syntax->freeGroupInfo(data);
1146 } 1146 }
1147 else 1147 else
1148 { 1148 {
1149 //Default values 1149 //Default values
1150 casesensitive=true; 1150 casesensitive=true;
1151 weakDeliminator=QString(""); 1151 weakDeliminator=QString("");
1152 } 1152 }
1153 1153
1154} 1154}
1155 1155
1156/******************************************************************************************* 1156/*******************************************************************************************
1157 Highlight - makeContextList 1157 Highlight - makeContextList
1158 That's the most important initialization function for each highlighting. It's called 1158 That's the most important initialization function for each highlighting. It's called
1159 each time a document gets a highlighting style assigned. parses the xml file and 1159 each time a document gets a highlighting style assigned. parses the xml file and
1160 creates a corresponding internal structure 1160 creates a corresponding internal structure
1161 1161
1162 * input: none 1162 * input: none
1163 ************* 1163 *************
1164 * output: none 1164 * output: none
1165 ************* 1165 *************
1166 * return value: none 1166 * return value: none
1167*******************************************************************************************/ 1167*******************************************************************************************/
1168 1168
1169 1169
1170void Highlight::makeContextList() 1170void Highlight::makeContextList()
1171{ 1171{
1172 if (noHl) 1172 if (noHl)
1173 return; 1173 return;
1174 1174
1175 HlKeyword *keyword=0, *dataType=0; 1175 HlKeyword *keyword=0, *dataType=0;
1176 syntaxContextData *data, *datasub; 1176 syntaxContextData *data, *datasub;
1177 HlItem *c; 1177 HlItem *c;
1178 1178
1179 readCommentConfig(); 1179 readCommentConfig();
1180 readGlobalKeywordConfig(); 1180 readGlobalKeywordConfig();
1181 1181
1182 // Let the syntax document class know, which file we'd like to parse 1182 // Let the syntax document class know, which file we'd like to parse
1183 HlManager::self()->syntax->setIdentifier(identifier); 1183 HlManager::self()->syntax->setIdentifier(identifier);
1184 1184
1185 // This list is needed for the translation of the attribute parameter, if the itemData name is given instead of the index 1185 // This list is needed for the translation of the attribute parameter, if the itemData name is given instead of the index
1186 ItemDataList iDl; 1186 ItemDataList iDl;
1187 createItemData(iDl); 1187 createItemData(iDl);
1188 1188
1189 //start the real work 1189 //start the real work
1190 data=HlManager::self()->syntax->getGroupInfo("highlighting","context"); 1190 data=HlManager::self()->syntax->getGroupInfo("highlighting","context");
1191 int i=0; 1191 int i=0;
1192 if (data) 1192 if (data)
1193 { 1193 {
1194 while (HlManager::self()->syntax->nextGroup(data)) 1194 while (HlManager::self()->syntax->nextGroup(data))
1195 { 1195 {
1196 1196
1197 // BEGIN - Translation of the attribute parameter 1197 // BEGIN - Translation of the attribute parameter
1198 QString tmpAttr=HlManager::self()->syntax->groupData(data,QString("attribute")).simplifyWhiteSpace(); 1198 QString tmpAttr=HlManager::self()->syntax->groupData(data,QString("attribute")).simplifyWhiteSpace();
1199 int attr; 1199 int attr;
1200 if (QString("%1").arg(tmpAttr.toInt())==tmpAttr) 1200 if (QString("%1").arg(tmpAttr.toInt())==tmpAttr)
1201 attr=tmpAttr.toInt(); 1201 attr=tmpAttr.toInt();
1202 else 1202 else
1203 attr=lookupAttrName(tmpAttr,iDl); 1203 attr=lookupAttrName(tmpAttr,iDl);
1204 // END - Translation of the attribute parameter 1204 // END - Translation of the attribute parameter
1205 1205
1206 contextList[i]=new HlContext( 1206 contextList[i]=new HlContext(
1207 attr, 1207 attr,
1208 (HlManager::self()->syntax->groupData(data,QString("lineEndContext"))).toInt(), 1208 (HlManager::self()->syntax->groupData(data,QString("lineEndContext"))).toInt(),
1209 (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).isEmpty()?-1: 1209 (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).isEmpty()?-1:
1210 (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).toInt()); 1210 (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).toInt());
1211 1211
1212 1212
1213 //Let's create all items for the context 1213 //Let's create all items for the context
1214 while (HlManager::self()->syntax->nextItem(data)) 1214 while (HlManager::self()->syntax->nextItem(data))
1215 { 1215 {
1216// kdDebug(13010)<< "In make Contextlist: Item:"<<endl; 1216// kdDebug(13010)<< "In make Contextlist: Item:"<<endl;
1217 c=createHlItem(data,iDl); 1217 c=createHlItem(data,iDl);
1218 if (c) 1218 if (c)
1219 { 1219 {
1220 contextList[i]->items.append(c); 1220 contextList[i]->items.append(c);
1221 1221
1222 // Not supported completely atm and only one level. Subitems.(all have to be matched to at once) 1222 // Not supported completely atm and only one level. Subitems.(all have to be matched to at once)
1223 datasub=HlManager::self()->syntax->getSubItems(data); 1223 datasub=HlManager::self()->syntax->getSubItems(data);
1224 bool tmpbool; 1224 bool tmpbool;
1225 if (tmpbool=HlManager::self()->syntax->nextItem(datasub)) 1225 if (tmpbool=HlManager::self()->syntax->nextItem(datasub))
1226 { 1226 {
1227 c->subItems=new QList<HlItem>; 1227 c->subItems=new QList<HlItem>;
1228 for (;tmpbool;tmpbool=HlManager::self()->syntax->nextItem(datasub)) 1228 for (;tmpbool;tmpbool=HlManager::self()->syntax->nextItem(datasub))
1229 c->subItems->append(createHlItem(datasub,iDl)); 1229 c->subItems->append(createHlItem(datasub,iDl));
1230 } 1230 }
1231 HlManager::self()->syntax->freeGroupInfo(datasub); 1231 HlManager::self()->syntax->freeGroupInfo(datasub);
1232 // end of sublevel 1232 // end of sublevel
1233 } 1233 }
1234// kdDebug(13010)<<"Last line in loop"<<endl; 1234// kdDebug(13010)<<"Last line in loop"<<endl;
1235 } 1235 }
1236 i++; 1236 i++;
1237 } 1237 }
1238 } 1238 }
1239 1239
1240 HlManager::self()->syntax->freeGroupInfo(data); 1240 HlManager::self()->syntax->freeGroupInfo(data);
1241 1241
1242 1242
1243} 1243}
1244 1244
1245HlManager::HlManager() : QObject(0L) 1245HlManager::HlManager() : QObject(0L)
1246{ 1246{
1247 syntax = new SyntaxDocument(); 1247 syntax = new SyntaxDocument();
1248 SyntaxModeList modeList = syntax->modeList(); 1248 SyntaxModeList modeList = syntax->modeList();
1249 1249
1250 hlList.setAutoDelete(true); 1250 hlList.setAutoDelete(true);
1251 hlList.append(new Highlight(0)); 1251 hlList.append(new Highlight(0));
1252 1252
1253 uint i=0; 1253 uint i=0;
1254 while (i < modeList.count()) 1254 while (i < modeList.count())
1255 { 1255 {
1256 hlList.append(new Highlight(modeList.at(i))); 1256 hlList.append(new Highlight(modeList.at(i)));
1257 i++; 1257 i++;
1258 } 1258 }
1259} 1259}
1260 1260
1261HlManager::~HlManager() { 1261HlManager::~HlManager() {
1262 if(syntax) delete syntax; 1262 if(syntax) delete syntax;
1263} 1263}
1264 1264
1265HlManager *HlManager::self() 1265HlManager *HlManager::self()
1266{ 1266{
1267 if ( !s_pSelf ) 1267 if ( !s_pSelf )
1268 s_pSelf = new HlManager; 1268 s_pSelf = new HlManager;
1269 return s_pSelf; 1269 return s_pSelf;
1270} 1270}
1271 1271
1272Highlight *HlManager::getHl(int n) { 1272Highlight *HlManager::getHl(int n) {
1273 if (n < 0 || n >= (int) hlList.count()) n = 0; 1273 if (n < 0 || n >= (int) hlList.count()) n = 0;
1274 return hlList.at(n); 1274 return hlList.at(n);
1275} 1275}
1276 1276
1277int HlManager::defaultHl() { 1277int HlManager::defaultHl() {
1278 KateConfig *config; 1278 KateConfig *config;
1279 config = KGlobal::config(); 1279 config = KGlobal::config();
1280 config->setGroup("General Options"); 1280 config->setGroup("General Options");
1281 1281
1282#warning fixme return nameFind(config->readEntry("Highlight")); 1282#warning fixme return nameFind(config->readEntry("Highlight"));
1283 1283
1284} 1284}
1285 1285
1286 1286
1287int HlManager::nameFind(const QString &name) { 1287int HlManager::nameFind(const QString &name) {
1288 int z; 1288 int z;
1289 1289
1290 for (z = hlList.count() - 1; z > 0; z--) { 1290 for (z = hlList.count() - 1; z > 0; z--) {
1291 if (hlList.at(z)->iName == name) break; 1291 if (hlList.at(z)->iName == name) break;
1292 } 1292 }
1293 return z; 1293 return z;
1294} 1294}
1295 1295
1296int HlManager::wildcardFind(const QString &fileName) { 1296int HlManager::wildcardFind(const QString &fileName) {
1297 Highlight *highlight; 1297 Highlight *highlight;
1298 int p1, p2; 1298 int p1, p2;
1299 QString w; 1299 QString w;
1300 for (highlight = hlList.first(); highlight != 0L; highlight = hlList.next()) { 1300 for (highlight = hlList.first(); highlight != 0L; highlight = hlList.next()) {
1301 p1 = 0; 1301 p1 = 0;
1302 w = highlight->getWildcards(); 1302 w = highlight->getWildcards();
1303 while (p1 < (int) w.length()) { 1303 while (p1 < (int) w.length()) {
1304 p2 = w.find(';',p1); 1304 p2 = w.find(';',p1);
1305 if (p2 == -1) p2 = w.length(); 1305 if (p2 == -1) p2 = w.length();
1306 if (p1 < p2) { 1306 if (p1 < p2) {
1307 QRegExp regExp(w.mid(p1,p2 - p1),true,true); 1307 QRegExp regExp(w.mid(p1,p2 - p1),true,true);
1308 if (regExp.match(fileName) == 0) return hlList.at(); 1308 if (regExp.match(fileName) == 0) return hlList.at();
1309 } 1309 }
1310 p1 = p2 + 1; 1310 p1 = p2 + 1;
1311 } 1311 }
1312 } 1312 }
1313 return -1; 1313 return -1;
1314} 1314}
1315 1315
1316 1316
1317int HlManager::makeAttribs(Highlight *highlight, Attribute *a, int maxAttribs) { 1317int HlManager::makeAttribs(Highlight *highlight, Attribute *a, int maxAttribs) {
1318 ItemStyleList defaultStyleList; 1318 ItemStyleList defaultStyleList;
1319 ItemStyle *defaultStyle; 1319 ItemStyle *defaultStyle = 0;
1320 ItemDataList itemDataList; 1320 ItemDataList itemDataList;
1321 ItemData *itemData; 1321 ItemData *itemData;
1322 int nAttribs, z; 1322 int nAttribs, z;
1323 1323
1324 odebug << "HlManager::makeAttribs" << oendl; 1324 odebug << "HlManager::makeAttribs" << oendl;
1325 1325
1326 defaultStyleList.setAutoDelete(true); 1326 defaultStyleList.setAutoDelete(true);
1327 getDefaults(defaultStyleList); 1327 getDefaults(defaultStyleList);
1328 1328
1329// itemDataList.setAutoDelete(true); 1329// itemDataList.setAutoDelete(true);
1330 highlight->getItemDataList(itemDataList); 1330 highlight->getItemDataList(itemDataList);
1331 nAttribs = itemDataList.count(); 1331 nAttribs = itemDataList.count();
1332 for (z = 0; z < nAttribs; z++) { 1332 for (z = 0; z < nAttribs; z++) {
1333 odebug << "HlManager::makeAttribs: createing one attribute definition" << oendl; 1333 odebug << "HlManager::makeAttribs: creating an attribute definition" << oendl;
1334 itemData = itemDataList.at(z); 1334 itemData = itemDataList.at(z);
1335 if (itemData->defStyle) { 1335 if (itemData->defStyle) {
1336 // default style 1336 // default style
1337 defaultStyle = defaultStyleList.at(itemData->defStyleNum); 1337 defaultStyle = defaultStyleList.at(itemData->defStyleNum);
1338 a[z].col = defaultStyle->col; 1338 a[z].col = defaultStyle->col;
1339 a[z].selCol = defaultStyle->selCol; 1339 a[z].selCol = defaultStyle->selCol;
1340 a[z].bold = defaultStyle->bold; 1340 a[z].bold = defaultStyle->bold;
1341 a[z].italic = defaultStyle->italic; 1341 a[z].italic = defaultStyle->italic;
1342 } else { 1342 } else {
1343 // custom style 1343 // custom style
1344 a[z].col = itemData->col; 1344 a[z].col = itemData->col;
1345 a[z].selCol = itemData->selCol; 1345 a[z].selCol = itemData->selCol;
1346 a[z].bold = itemData->bold; 1346 a[z].bold = itemData->bold;
1347 a[z].italic = itemData->italic; 1347 a[z].italic = itemData->italic;
1348 } 1348 }
1349 } 1349 }
1350 1350
1351 for (; z < maxAttribs; z++) { 1351 for (; z < maxAttribs; z++) {
1352 a[z].col = black; 1352 a[z].col = black;
1353 a[z].selCol = black; 1353 a[z].selCol = black;
1354 a[z].bold = defaultStyle->bold; 1354 if (defaultStyle) {
1355 a[z].italic = defaultStyle->italic; 1355 a[z].bold = defaultStyle->bold;
1356 a[z].italic = defaultStyle->italic;
1357 }
1356 } 1358 }
1357 return nAttribs; 1359 return nAttribs;
1358} 1360}
1359 1361
1360int HlManager::defaultStyles() { 1362int HlManager::defaultStyles() {
1361 return 10; 1363 return 10;
1362} 1364}
1363 1365
1364QString HlManager::defaultStyleName(int n) 1366QString HlManager::defaultStyleName(int n)
1365{ 1367{
1366 static QStringList names; 1368 static QStringList names;
1367 1369
1368 if (names.isEmpty()) 1370 if (names.isEmpty())
1369 { 1371 {
1370 names << i18n("Normal"); 1372 names << i18n("Normal");
1371 names << i18n("Keyword"); 1373 names << i18n("Keyword");
1372 names << i18n("Data Type"); 1374 names << i18n("Data Type");
1373 names << i18n("Decimal/Value"); 1375 names << i18n("Decimal/Value");
1374 names << i18n("Base-N Integer"); 1376 names << i18n("Base-N Integer");
1375 names << i18n("Floating Point"); 1377 names << i18n("Floating Point");
1376 names << i18n("Character"); 1378 names << i18n("Character");
1377 names << i18n("String"); 1379 names << i18n("String");
1378 names << i18n("Comment"); 1380 names << i18n("Comment");
1379 names << i18n("Others"); 1381 names << i18n("Others");
1380 } 1382 }
1381 1383
1382 return names[n]; 1384 return names[n];
1383} 1385}
1384 1386
1385void HlManager::getDefaults(ItemStyleList &list) { 1387void HlManager::getDefaults(ItemStyleList &list) {
1386 KateConfig *config; 1388 KateConfig *config;
1387 int z; 1389 int z;
1388 ItemStyle *i; 1390 ItemStyle *i;
1389 QString s; 1391 QString s;
1390 QRgb col, selCol; 1392 QRgb col, selCol;
1391 1393
1392 list.setAutoDelete(true); 1394 list.setAutoDelete(true);
1393 //ItemStyle(color, selected color, bold, italic) 1395 //ItemStyle(color, selected color, bold, italic)
1394 list.append(new ItemStyle(black,white,false,false)); //normal 1396 list.append(new ItemStyle(black,white,false,false)); //normal
1395 list.append(new ItemStyle(black,white,true,false)); //keyword 1397 list.append(new ItemStyle(black,white,true,false)); //keyword
1396 list.append(new ItemStyle(darkRed,white,false,false)); //datatype 1398 list.append(new ItemStyle(darkRed,white,false,false)); //datatype
1397 list.append(new ItemStyle(blue,cyan,false,false)); //decimal/value 1399 list.append(new ItemStyle(blue,cyan,false,false)); //decimal/value
1398 list.append(new ItemStyle(darkCyan,cyan,false,false)); //base n 1400 list.append(new ItemStyle(darkCyan,cyan,false,false)); //base n
1399 list.append(new ItemStyle(darkMagenta,cyan,false,false));//float 1401 list.append(new ItemStyle(darkMagenta,cyan,false,false));//float
1400 list.append(new ItemStyle(magenta,magenta,false,false)); //char 1402 list.append(new ItemStyle(magenta,magenta,false,false)); //char
1401 list.append(new ItemStyle(red,red,false,false)); //string 1403 list.append(new ItemStyle(red,red,false,false)); //string
1402 list.append(new ItemStyle(darkGray,gray,false,true)); //comment 1404 list.append(new ItemStyle(darkGray,gray,false,true)); //comment
1403 list.append(new ItemStyle(darkGreen,green,false,false)); //others 1405 list.append(new ItemStyle(darkGreen,green,false,false)); //others
1404 1406
1405#warning fixme 1407#warning fixme
1406/* 1408/*
1407 config = KateFactory::instance()->config(); 1409 config = KateFactory::instance()->config();
1408 config->setGroup("Default Item Styles"); 1410 config->setGroup("Default Item Styles");
1409 for (z = 0; z < defaultStyles(); z++) { 1411 for (z = 0; z < defaultStyles(); z++) {
1410 i = list.at(z); 1412 i = list.at(z);
1411 s = config->readEntry(defaultStyleName(z)); 1413 s = config->readEntry(defaultStyleName(z));
1412 if (!s.isEmpty()) { 1414 if (!s.isEmpty()) {
1413 sscanf(s.latin1(),"%X,%X,%d,%d",&col,&selCol,&i->bold,&i->italic); 1415 sscanf(s.latin1(),"%X,%X,%d,%d",&col,&selCol,&i->bold,&i->italic);
1414 i->col.setRgb(col); 1416 i->col.setRgb(col);
1415 i->selCol.setRgb(selCol); 1417 i->selCol.setRgb(selCol);
1416 } 1418 }
1417 } 1419 }
1418*/ 1420*/
1419} 1421}
1420 1422
1421void HlManager::setDefaults(ItemStyleList &list) { 1423void HlManager::setDefaults(ItemStyleList &list) {
1422 KateConfig *config; 1424 KateConfig *config;
1423 int z; 1425 int z;
1424 ItemStyle *i; 1426 ItemStyle *i;
1425 char s[64]; 1427 char s[64];
1426#warning fixme 1428#warning fixme
1427/* 1429/*
1428 config = KateFactory::instance()->config(); 1430 config = KateFactory::instance()->config();
1429 config->setGroup("Default Item Styles"); 1431 config->setGroup("Default Item Styles");
1430 for (z = 0; z < defaultStyles(); z++) { 1432 for (z = 0; z < defaultStyles(); z++) {
1431 i = list.at(z); 1433 i = list.at(z);
1432 sprintf(s,"%X,%X,%d,%d",i->col.rgb(),i->selCol.rgb(),i->bold, i->italic); 1434 sprintf(s,"%X,%X,%d,%d",i->col.rgb(),i->selCol.rgb(),i->bold, i->italic);
1433 config->writeEntry(defaultStyleName(z),s); 1435 config->writeEntry(defaultStyleName(z),s);
1434 } 1436 }
1435*/ 1437*/
1436 emit changed(); 1438 emit changed();
1437} 1439}
1438 1440
1439 1441
1440int HlManager::highlights() { 1442int HlManager::highlights() {
1441 return (int) hlList.count(); 1443 return (int) hlList.count();
1442} 1444}
1443 1445
1444QString HlManager::hlName(int n) { 1446QString HlManager::hlName(int n) {
1445 return hlList.at(n)->iName; 1447 return hlList.at(n)->iName;
1446} 1448}
1447 1449
1448QString HlManager::hlSection(int n) { 1450QString HlManager::hlSection(int n) {
1449 return hlList.at(n)->iSection; 1451 return hlList.at(n)->iSection;
1450} 1452}
1451 1453
1452void HlManager::getHlDataList(HlDataList &list) { 1454void HlManager::getHlDataList(HlDataList &list) {
1453 int z; 1455 int z;
1454 1456
1455 for (z = 0; z < (int) hlList.count(); z++) { 1457 for (z = 0; z < (int) hlList.count(); z++) {
1456 list.append(hlList.at(z)->getData()); 1458 list.append(hlList.at(z)->getData());
1457 } 1459 }
1458} 1460}
1459 1461
1460void HlManager::setHlDataList(HlDataList &list) { 1462void HlManager::setHlDataList(HlDataList &list) {
1461 int z; 1463 int z;
1462 1464
1463 for (z = 0; z < (int) hlList.count(); z++) { 1465 for (z = 0; z < (int) hlList.count(); z++) {
1464 hlList.at(z)->setData(list.at(z)); 1466 hlList.at(z)->setData(list.at(z));
1465 } 1467 }
1466 //notify documents about changes in highlight configuration 1468 //notify documents about changes in highlight configuration
1467 emit changed(); 1469 emit changed();
1468} 1470}
diff --git a/noncore/net/ftplib/ftplib.c b/noncore/net/ftplib/ftplib.c
index addf9d2..ce4c05f 100644
--- a/noncore/net/ftplib/ftplib.c
+++ b/noncore/net/ftplib/ftplib.c
@@ -1,1354 +1,1354 @@
1/***************************************************************************/ 1/***************************************************************************/
2/* ftplib.c - callable ftp access routines */ 2/* ftplib.c - callable ftp access routines */
3/* Copyright (C) 1996-2000 Thomas Pfau, pfau@cnj.digex.net */ 3/* Copyright (C) 1996-2000 Thomas Pfau, pfau@cnj.digex.net */
4/* 73 Catherine Street, South Bound Brook, NJ, 08880 */ 4/* 73 Catherine Street, South Bound Brook, NJ, 08880 */
5/* */ 5/* */
6/* This library is free software; you can redistribute it and/or */ 6/* This library is free software; you can redistribute it and/or */
7/* modify it under the terms of the GNU Library General Public */ 7/* modify it under the terms of the GNU Library General Public */
8/* License as published by the Free Software Foundation; either */ 8/* License as published by the Free Software Foundation; either */
9/* version 2 of the License, or (at your option) any later version. */ 9/* version 2 of the License, or (at your option) any later version. */
10/* */ 10/* */
11/* This library is distributed in the hope that it will be useful, */ 11/* This library is distributed in the hope that it will be useful, */
12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
14/* Library General Public License for more details. */ 14/* Library General Public License for more details. */
15/* */ 15/* */
16/* You should have received a copy of the GNU Library General Public */ 16/* You should have received a copy of the GNU Library General Public */
17/* License along with this progam; if not, write to the */ 17/* License along with this progam; if not, write to the */
18/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ 18/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
19/* Boston, MA 02111-1307, USA. */ 19/* Boston, MA 02111-1307, USA. */
20/* */ 20/* */
21/***************************************************************************/ 21/***************************************************************************/
22// changes made by Lorn Potter <llornkcor@handhelds.org> 22// changes made by Lorn Potter <llornkcor@handhelds.org>
23// 23//
24#if defined(__unix__) || defined(__VMS) 24#if defined(__unix__) || defined(__VMS)
25#include <unistd.h> 25#include <unistd.h>
26#endif 26#endif
27#if defined(_WIN32) 27#if defined(_WIN32)
28#include <windows.h> 28#include <windows.h>
29#endif 29#endif
30 30
31#include <stdio.h> 31#include <stdio.h>
32#include <stdlib.h> 32#include <stdlib.h>
33#include <string.h> 33#include <string.h>
34#include <errno.h> 34#include <errno.h>
35#include <ctype.h> 35#include <ctype.h>
36 36
37#if defined(__unix__) 37#if defined(__unix__)
38 38
39#include <sys/types.h> 39#include <sys/types.h>
40#include <unistd.h> 40#include <unistd.h>
41#include <fcntl.h> 41#include <fcntl.h>
42#include <sys/time.h> 42#include <sys/time.h>
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/socket.h> 44#include <sys/socket.h>
45#include <netinet/in.h> 45#include <netinet/in.h>
46#include <netdb.h> 46#include <netdb.h>
47#include <arpa/inet.h> 47#include <arpa/inet.h>
48 48
49#elif defined(VMS) 49#elif defined(VMS)
50 50
51#include <types.h> 51#include <types.h>
52#include <socket.h> 52#include <socket.h>
53#include <in.h> 53#include <in.h>
54#include <netdb.h> 54#include <netdb.h>
55#include <inet.h> 55#include <inet.h>
56 56
57#elif defined(_WIN32) 57#elif defined(_WIN32)
58 58
59#include <winsock.h> 59#include <winsock.h>
60 60
61#endif 61#endif
62 62
63#define BUILDING_LIBRARY 63#define BUILDING_LIBRARY
64#include "ftplib.h" 64#include "ftplib.h"
65 65
66#if defined(_WIN32) 66#if defined(_WIN32)
67#define SETSOCKOPT_OPTVAL_TYPE (const char *) 67#define SETSOCKOPT_OPTVAL_TYPE (const char *)
68#else 68#else
69#define SETSOCKOPT_OPTVAL_TYPE (void *) 69#define SETSOCKOPT_OPTVAL_TYPE (void *)
70#endif 70#endif
71 71
72#define FTPLIB_BUFSIZ 8192 72#define FTPLIB_BUFSIZ 8192
73#define ACCEPT_TIMEOUT 10 73#define ACCEPT_TIMEOUT 10
74 74
75#define FTPLIB_CONTROL 0 75#define FTPLIB_CONTROL 0
76#define FTPLIB_READ 1 76#define FTPLIB_READ 1
77#define FTPLIB_WRITE 2 77#define FTPLIB_WRITE 2
78 78
79#if !defined FTPLIB_DEFMODE 79#if !defined FTPLIB_DEFMODE
80#define FTPLIB_DEFMODE FTPLIB_PASSIVE 80#define FTPLIB_DEFMODE FTPLIB_PASSIVE
81#endif 81#endif
82 82
83struct NetBuf { 83struct NetBuf {
84 char *cput,*cget; 84 char *cput,*cget;
85 int handle; 85 int handle;
86 int cavail,cleft; 86 int cavail,cleft;
87 char *buf; 87 char *buf;
88 int dir; 88 int dir;
89 netbuf *ctrl; 89 netbuf *ctrl;
90 netbuf *data; 90 netbuf *data;
91 int cmode; 91 int cmode;
92 struct timeval idletime; 92 struct timeval idletime;
93 FtpCallback idlecb; 93 FtpCallback idlecb;
94 void *idlearg; 94 void *idlearg;
95 int xfered; 95 int xfered;
96 int cbbytes; 96 int cbbytes;
97 int xfered1; 97 int xfered1;
98 char response[256]; 98 char response[256];
99}; 99};
100 100
101static char *version = 101static char *version =
102"ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau"; 102"ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau";
103 103
104GLOBALDEF int ftplib_debug = 0; 104GLOBALDEF int ftplib_debug = 0;
105 105
106#if defined(__unix__) || defined(VMS) 106#if defined(__unix__) || defined(VMS)
107#define net_read read 107#define net_read read
108#define net_write write 108#define net_write write
109#define net_close close 109#define net_close close
110#elif defined(_WIN32) 110#elif defined(_WIN32)
111#define net_read(x,y,z) recv(x,y,z,0) 111#define net_read(x,y,z) recv(x,y,z,0)
112#define net_write(x,y,z) send(x,y,z,0) 112#define net_write(x,y,z) send(x,y,z,0)
113#define net_close closesocket 113#define net_close closesocket
114#endif 114#endif
115 115
116#if defined(NEED_MEMCCPY) 116#if defined(NEED_MEMCCPY)
117/* 117/*
118 * VAX C does not supply a memccpy routine so I provide my own 118 * VAX C does not supply a memccpy routine so I provide my own
119 */ 119 */
120void *memccpy(void *dest, const void *src, int c, size_t n) 120void *memccpy(void *dest, const void *src, int c, size_t n)
121{ 121{
122 int i=0; 122 int i=0;
123 const unsigned char *ip=src; 123 const unsigned char *ip=src;
124 unsigned char *op=dest; 124 unsigned char *op=dest;
125 125
126 while (i < n) 126 while (i < n)
127 { 127 {
128 if ((*op++ = *ip++) == c) 128 if ((*op++ = *ip++) == c)
129 break; 129 break;
130 i++; 130 i++;
131 } 131 }
132 if (i == n) 132 if (i == n)
133 return NULL; 133 return NULL;
134 return op; 134 return op;
135} 135}
136#endif 136#endif
137#if defined(NEED_STRDUP) 137#if defined(NEED_STRDUP)
138/* 138/*
139 * strdup - return a malloc'ed copy of a string 139 * strdup - return a malloc'ed copy of a string
140 */ 140 */
141char *strdup(const char *src) 141char *strdup(const char *src)
142{ 142{
143 int l = strlen(src) + 1; 143 int l = strlen(src) + 1;
144 char *dst = malloc(l); 144 char *dst = malloc(l);
145 if (dst) 145 if (dst)
146 strcpy(dst,src); 146 strcpy(dst,src);
147 return dst; 147 return dst;
148} 148}
149#endif 149#endif
150 150
151/* 151/*
152 * socket_wait - wait for socket to receive or flush data 152 * socket_wait - wait for socket to receive or flush data
153 * 153 *
154 * return 1 if no user callback, otherwise, return value returned by 154 * return 1 if no user callback, otherwise, return value returned by
155 * user callback 155 * user callback
156 */ 156 */
157static int socket_wait(netbuf *ctl) 157static int socket_wait(netbuf *ctl)
158{ 158{
159 fd_set fd,*rfd = NULL,*wfd = NULL; 159 fd_set fd,*rfd = NULL,*wfd = NULL;
160 struct timeval tv; 160 struct timeval tv;
161 int rv = 0; 161 int rv = 0;
162 if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL)) 162 if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL))
163 return 1; 163 return 1;
164 if (ctl->dir == FTPLIB_WRITE) 164 if (ctl->dir == FTPLIB_WRITE)
165 wfd = &fd; 165 wfd = &fd;
166 else 166 else
167 rfd = &fd; 167 rfd = &fd;
168 FD_ZERO(&fd); 168 FD_ZERO(&fd);
169 do 169 do
170 { 170 {
171 FD_SET(ctl->handle,&fd); 171 FD_SET(ctl->handle,&fd);
172 tv = ctl->idletime; 172 tv = ctl->idletime;
173 rv = select(ctl->handle+1, rfd, wfd, NULL, &tv); 173 rv = select(ctl->handle+1, rfd, wfd, NULL, &tv);
174 if (rv == -1) 174 if (rv == -1)
175 { 175 {
176 rv = 0; 176 rv = 0;
177 strncpy(ctl->ctrl->response, strerror(errno), 177 strncpy(ctl->ctrl->response, strerror(errno),
178 sizeof(ctl->ctrl->response)); 178 sizeof(ctl->ctrl->response));
179 break; 179 break;
180 } 180 }
181 else if (rv > 0) 181 else if (rv > 0)
182 { 182 {
183 rv = 1; 183 rv = 1;
184 break; 184 break;
185 } 185 }
186 } 186 }
187 while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg))); 187 while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg)));
188 return rv; 188 return rv;
189} 189}
190 190
191/* 191/*
192 * read a line of text 192 * read a line of text
193 * 193 *
194 * return -1 on error or bytecount 194 * return -1 on error or bytecount
195 */ 195 */
196static int readline(char *buf,int max,netbuf *ctl) 196static int readline(char *buf,int max,netbuf *ctl)
197{ 197{
198 int x,retval = 0; 198 int x,retval = 0;
199 char *end,*bp=buf; 199 char *end,*bp=buf;
200 int eof = 0; 200 int eof = 0;
201 201
202 if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ)) 202 if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ))
203 return -1; 203 return -1;
204 if (max == 0) 204 if (max == 0)
205 return 0; 205 return 0;
206 do 206 do
207 { 207 {
208 if (ctl->cavail > 0) 208 if (ctl->cavail > 0)
209 { 209 {
210 x = (max >= ctl->cavail) ? ctl->cavail : max-1; 210 x = (max >= ctl->cavail) ? ctl->cavail : max-1;
211 end = memccpy(bp,ctl->cget,'\n',x); 211 end = memccpy(bp,ctl->cget,'\n',x);
212 if (end != NULL) 212 if (end != NULL)
213 x = end - bp; 213 x = end - bp;
214 retval += x; 214 retval += x;
215 bp += x; 215 bp += x;
216 *bp = '\0'; 216 *bp = '\0';
217 max -= x; 217 max -= x;
218 ctl->cget += x; 218 ctl->cget += x;
219 ctl->cavail -= x; 219 ctl->cavail -= x;
220 if (end != NULL) 220 if (end != NULL)
221 { 221 {
222 bp -= 2; 222 bp -= 2;
223 if (strcmp(bp,"\r\n") == 0) 223 if (strcmp(bp,"\r\n") == 0)
224 { 224 {
225 *bp++ = '\n'; 225 *bp++ = '\n';
226 *bp++ = '\0'; 226 *bp++ = '\0';
227 --retval; 227 --retval;
228 } 228 }
229 break; 229 break;
230 } 230 }
231 } 231 }
232 if (max == 1) 232 if (max == 1)
233 { 233 {
234 *buf = '\0'; 234 *buf = '\0';
235 break; 235 break;
236 } 236 }
237 if (ctl->cput == ctl->cget) 237 if (ctl->cput == ctl->cget)
238 { 238 {
239 ctl->cput = ctl->cget = ctl->buf; 239 ctl->cput = ctl->cget = ctl->buf;
240 ctl->cavail = 0; 240 ctl->cavail = 0;
241 ctl->cleft = FTPLIB_BUFSIZ; 241 ctl->cleft = FTPLIB_BUFSIZ;
242 } 242 }
243 if (eof) 243 if (eof)
244 { 244 {
245 if (retval == 0) 245 if (retval == 0)
246 retval = -1; 246 retval = -1;
247 break; 247 break;
248 } 248 }
249 if (!socket_wait(ctl)) 249 if (!socket_wait(ctl))
250 return retval; 250 return retval;
251 if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1) 251 if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1)
252 { 252 {
253 perror("read"); 253 perror("read");
254 retval = -1; 254 retval = -1;
255 break; 255 break;
256 } 256 }
257 if (x == 0) 257 if (x == 0)
258 eof = 1; 258 eof = 1;
259 ctl->cleft -= x; 259 ctl->cleft -= x;
260 ctl->cavail += x; 260 ctl->cavail += x;
261 ctl->cput += x; 261 ctl->cput += x;
262 } 262 }
263 while (1); 263 while (1);
264 return retval; 264 return retval;
265} 265}
266 266
267/* 267/*
268 * write lines of text 268 * write lines of text
269 * 269 *
270 * return -1 on error or bytecount 270 * return -1 on error or bytecount
271 */ 271 */
272static int writeline(char *buf, int len, netbuf *nData) 272static int writeline(char *buf, int len, netbuf *nData)
273{ 273{
274 int x, nb=0, w; 274 int x, nb=0, w;
275 char *ubp = buf, *nbp; 275 char *ubp = buf, *nbp;
276 char lc=0; 276 char lc=0;
277 277
278 if (nData->dir != FTPLIB_WRITE) 278 if (nData->dir != FTPLIB_WRITE)
279 return -1; 279 return -1;
280 nbp = nData->buf; 280 nbp = nData->buf;
281 for (x=0; x < len; x++) 281 for (x=0; x < len; x++)
282 { 282 {
283 if ((*ubp == '\n') && (lc != '\r')) 283 if ((*ubp == '\n') && (lc != '\r'))
284 { 284 {
285 if (nb == FTPLIB_BUFSIZ) 285 if (nb == FTPLIB_BUFSIZ)
286 { 286 {
287 if (!socket_wait(nData)) 287 if (!socket_wait(nData))
288 return x; 288 return x;
289 w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); 289 w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
290 if (w != FTPLIB_BUFSIZ) 290 if (w != FTPLIB_BUFSIZ)
291 { 291 {
292 printf("net_write(1) returned %d, errno = %d\n", w, errno); 292 printf("net_write(1) returned %d, errno = %d\n", w, errno);
293 return(-1); 293 return(-1);
294 } 294 }
295 nb = 0; 295 nb = 0;
296 } 296 }
297 nbp[nb++] = '\r'; 297 nbp[nb++] = '\r';
298 } 298 }
299 if (nb == FTPLIB_BUFSIZ) 299 if (nb == FTPLIB_BUFSIZ)
300 { 300 {
301 if (!socket_wait(nData)) 301 if (!socket_wait(nData))
302 return x; 302 return x;
303 w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); 303 w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
304 if (w != FTPLIB_BUFSIZ) 304 if (w != FTPLIB_BUFSIZ)
305 { 305 {
306 printf("net_write(2) returned %d, errno = %d\n", w, errno); 306 printf("net_write(2) returned %d, errno = %d\n", w, errno);
307 return(-1); 307 return(-1);
308 } 308 }
309 nb = 0; 309 nb = 0;
310 } 310 }
311 nbp[nb++] = lc = *ubp++; 311 nbp[nb++] = lc = *ubp++;
312 } 312 }
313 if (nb) 313 if (nb)
314 { 314 {
315 if (!socket_wait(nData)) 315 if (!socket_wait(nData))
316 return x; 316 return x;
317 w = net_write(nData->handle, nbp, nb); 317 w = net_write(nData->handle, nbp, nb);
318 if (w != nb) 318 if (w != nb)
319 { 319 {
320 printf("net_write(3) returned %d, errno = %d\n", w, errno); 320 printf("net_write(3) returned %d, errno = %d\n", w, errno);
321 return(-1); 321 return(-1);
322 } 322 }
323 } 323 }
324 return len; 324 return len;
325} 325}
326 326
327/* 327/*
328 * read a response from the server 328 * read a response from the server
329 * 329 *
330 * return 0 if first char doesn't match 330 * return 0 if first char doesn't match
331 * return 1 if first char matches 331 * return 1 if first char matches
332 */ 332 */
333static int readresp(char c, netbuf *nControl) 333static int readresp(char c, netbuf *nControl)
334{ 334{
335 char match[5]; 335 char match[5];
336 if (readline(nControl->response,256,nControl) == -1) 336 if (readline(nControl->response,256,nControl) == -1)
337 { 337 {
338 perror("Control socket read failed"); 338 perror("Control socket read failed");
339 return 0; 339 return 0;
340 } 340 }
341 if (ftplib_debug > 1) 341 if (ftplib_debug > 1)
342 fprintf(stderr,"%s",nControl->response); 342 fprintf(stderr,"%s",nControl->response);
343 if (nControl->response[3] == '-') 343 if (nControl->response[3] == '-')
344 { 344 {
345 strncpy(match,nControl->response,3); 345 strncpy(match,nControl->response,3);
346 match[3] = ' '; 346 match[3] = ' ';
347 match[4] = '\0'; 347 match[4] = '\0';
348 do 348 do
349 { 349 {
350 if (readline(nControl->response,256,nControl) == -1) 350 if (readline(nControl->response,256,nControl) == -1)
351 { 351 {
352 perror("Control socket read failed"); 352 perror("Control socket read failed");
353 return 0; 353 return 0;
354 } 354 }
355 if (ftplib_debug > 1) 355 if (ftplib_debug > 1)
356 fprintf(stderr,"%s",nControl->response); 356 fprintf(stderr,"%s",nControl->response);
357 } 357 }
358 while (strncmp(nControl->response,match,4)); 358 while (strncmp(nControl->response,match,4));
359 } 359 }
360 if (nControl->response[0] == c) 360 if (nControl->response[0] == c)
361 return 1; 361 return 1;
362 return 0; 362 return 0;
363} 363}
364 364
365/* 365/*
366 * FtpInit for stupid operating systems that require it (Windows NT) 366 * FtpInit for stupid operating systems that require it (Windows NT)
367 */ 367 */
368GLOBALDEF void FtpInit(void) 368GLOBALDEF void FtpInit(void)
369{ 369{
370#if defined(_WIN32) 370#if defined(_WIN32)
371 WORD wVersionRequested; 371 WORD wVersionRequested;
372 WSADATA wsadata; 372 WSADATA wsadata;
373 int err; 373 int err;
374 wVersionRequested = MAKEWORD(1,1); 374 wVersionRequested = MAKEWORD(1,1);
375 if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0) 375 if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0)
376 fprintf(stderr,"Network failed to start: %d\n",err); 376 fprintf(stderr,"Network failed to start: %d\n",err);
377#endif 377#endif
378} 378}
379 379
380/* 380/*
381 * FtpLastResponse - return a pointer to the last response received 381 * FtpLastResponse - return a pointer to the last response received
382 */ 382 */
383GLOBALDEF char *FtpLastResponse(netbuf *nControl) 383GLOBALDEF char *FtpLastResponse(netbuf *nControl)
384{ 384{
385 if ((nControl) && (nControl->dir == FTPLIB_CONTROL)) 385 if ((nControl) && (nControl->dir == FTPLIB_CONTROL))
386 return nControl->response; 386 return nControl->response;
387 return NULL; 387 return NULL;
388} 388}
389 389
390/* 390/*
391 * FtpConnect - connect to remote server 391 * FtpConnect - connect to remote server
392 * 392 *
393 * return 1 if connected, 0 if not 393 * return 1 if connected, 0 if not
394 */ 394 */
395GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) 395GLOBALDEF int FtpConnect(const char *host, netbuf **nControl)
396{ 396{
397 int sControl, stat, flags, oldflags; 397 int sControl, stat, flags, oldflags;
398 struct sockaddr_in sin; 398 struct sockaddr_in sin;
399 struct hostent *phe; 399 struct hostent *phe;
400 struct servent *pse; 400 struct servent *pse;
401 int on=1; 401 int on=1;
402 netbuf *ctrl; 402 netbuf *ctrl;
403 char *lhost; 403 char *lhost;
404 char *pnum; 404 char *pnum;
405 struct timeval tv; 405 struct timeval tv;
406 fd_set wr; 406 fd_set wr;
407 407
408 memset(&sin,0,sizeof(sin)); 408 memset(&sin,0,sizeof(sin));
409 sin.sin_family = AF_INET; 409 sin.sin_family = AF_INET;
410 lhost = strdup(host); 410 lhost = strdup(host);
411 pnum = strchr(lhost,':'); 411 pnum = strchr(lhost,':');
412 if (pnum == NULL) 412 if (pnum == NULL)
413 { 413 {
414#if defined(VMS) 414#if defined(VMS)
415 sin.sin_port = htons(21); 415 sin.sin_port = htons(21);
416#else 416#else
417 if ((pse = getservbyname("ftp","tcp")) == NULL) 417 if ((pse = getservbyname("ftp","tcp")) == NULL)
418 { 418 {
419 perror("getservbyname"); 419 perror("getservbyname");
420 return 0; 420 return 0;
421 } 421 }
422 sin.sin_port = pse->s_port; 422 sin.sin_port = pse->s_port;
423#endif 423#endif
424 } 424 }
425 else 425 else
426 { 426 {
427 *pnum++ = '\0'; 427 *pnum++ = '\0';
428 if (isdigit(*pnum)) 428 if (isdigit(*pnum))
429 sin.sin_port = htons(atoi(pnum)); 429 sin.sin_port = htons(atoi(pnum));
430 else 430 else
431 { 431 {
432 pse = getservbyname(pnum,"tcp"); 432 pse = getservbyname(pnum,"tcp");
433 sin.sin_port = pse->s_port; 433 sin.sin_port = pse->s_port;
434 } 434 }
435 } 435 }
436 if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1) 436 if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1)
437 { 437 {
438 if ((phe = gethostbyname(lhost)) == NULL) 438 if ((phe = gethostbyname(lhost)) == NULL)
439 { 439 {
440 perror("gethostbyname"); 440 perror("gethostbyname");
441 return 0; 441 return 0;
442 } 442 }
443 443
444 memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length); 444 memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length);
445 445
446 } 446 }
447 free(lhost); 447 free(lhost);
448 448
449 sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); 449 sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
450 if (sControl == -1) 450 if (sControl == -1)
451 { 451 {
452 perror("socket"); 452 perror("socket");
453 return 0; 453 return 0;
454 } 454 }
455 455
456 if ( setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR, 456 if ( setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR,
457 SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1) 457 SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1)
458 { 458 {
459 perror("setsockopt"); 459 perror("setsockopt");
460 net_close(sControl); 460 net_close(sControl);
461 return 0; 461 return 0;
462 } 462 }
463 463
464 //set nonblocking for connection timeout 464 //set nonblocking for connection timeout
465 flags = fcntl( sControl, F_GETFL,0); 465 flags = fcntl( sControl, F_GETFL,0);
466 oldflags=flags; 466 oldflags=flags;
467 fcntl( sControl, F_SETFL, O_NONBLOCK|flags); 467 fcntl( sControl, F_SETFL, O_NONBLOCK|flags);
468 468
469 stat=connect( sControl, (struct sockaddr *)&sin, sizeof(sin)); 469 stat=connect( sControl, (struct sockaddr *)&sin, sizeof(sin));
470 if (stat < 0) 470 if (stat < 0)
471 { 471 {
472 if (errno != EWOULDBLOCK && errno != EINPROGRESS) 472 if (errno != EWOULDBLOCK && errno != EINPROGRESS)
473 { 473 {
474 perror("connect"); 474 perror("connect");
475 net_close(sControl); 475 net_close(sControl);
476 return 0; 476 return 0;
477 } 477 }
478 } 478 }
479 479
480 FD_ZERO(&wr); 480 FD_ZERO(&wr);
481 FD_SET( sControl, &wr); 481 FD_SET( sControl, &wr);
482 482
483 tv.tv_sec = ACCEPT_TIMEOUT; 483 tv.tv_sec = ACCEPT_TIMEOUT;
484 tv.tv_usec = 0; 484 tv.tv_usec = 0;
485 485
486 stat = select(sControl+1, 0, &wr, 0, &tv); 486 stat = select(sControl+1, 0, &wr, 0, &tv);
487 487
488 if (stat < 1) 488 if (stat < 1)
489 { 489 {
490 // time out has expired, 490 // time out has expired,
491 // or an error has ocurred 491 // or an error has ocurred
492 perror("timeout"); 492 perror("timeout");
493 net_close(sControl); 493 net_close(sControl);
494 return 0; 494 return 0;
495 } 495 }
496 496
497 printf("connected\n"); 497 printf("connected\n");
498 498
499 //set original flags 499 //set original flags
500 fcntl( sControl, F_SETFL, oldflags); 500 fcntl( sControl, F_SETFL, oldflags);
501 501
502 ctrl = calloc(1,sizeof(netbuf)); 502 ctrl = calloc(1,sizeof(netbuf));
503 if (ctrl == NULL) 503 if (ctrl == NULL)
504 { 504 {
505 perror("calloc"); 505 perror("calloc");
506 net_close(sControl); 506 net_close(sControl);
507 return 0; 507 return 0;
508 } 508 }
509 ctrl->buf = malloc(FTPLIB_BUFSIZ); 509 ctrl->buf = malloc(FTPLIB_BUFSIZ);
510 if (ctrl->buf == NULL) 510 if (ctrl->buf == NULL)
511 { 511 {
512 perror("calloc"); 512 perror("calloc");
513 net_close(sControl); 513 net_close(sControl);
514 free(ctrl); 514 free(ctrl);
515 return 0; 515 return 0;
516 } 516 }
517 ctrl->handle = sControl; 517 ctrl->handle = sControl;
518 ctrl->dir = FTPLIB_CONTROL; 518 ctrl->dir = FTPLIB_CONTROL;
519 ctrl->ctrl = NULL; 519 ctrl->ctrl = NULL;
520 ctrl->cmode = FTPLIB_DEFMODE; 520 ctrl->cmode = FTPLIB_DEFMODE;
521 ctrl->idlecb = NULL; 521 ctrl->idlecb = NULL;
522 ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0; 522 ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
523 ctrl->idlearg = NULL; 523 ctrl->idlearg = NULL;
524 ctrl->xfered = 0; 524 ctrl->xfered = 0;
525 ctrl->xfered1 = 0; 525 ctrl->xfered1 = 0;
526 ctrl->cbbytes = 0; 526 ctrl->cbbytes = 0;
527 if (readresp('2', ctrl) == 0) 527 if (readresp('2', ctrl) == 0)
528 { 528 {
529 net_close(sControl); 529 net_close(sControl);
530 free(ctrl->buf); 530 free(ctrl->buf);
531 free(ctrl); 531 free(ctrl);
532 return 0; 532 return 0;
533 } 533 }
534 *nControl = ctrl; 534 *nControl = ctrl;
535 return 1; 535 return 1;
536} 536}
537 537
538/* 538/*
539 * FtpOptions - change connection options 539 * FtpOptions - change connection options
540 * 540 *
541 * returns 1 if successful, 0 on error 541 * returns 1 if successful, 0 on error
542 */ 542 */
543GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl) 543GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl)
544{ 544{
545 int v,rv=0; 545 int v,rv=0;
546 switch (opt) 546 switch (opt)
547 { 547 {
548 case FTPLIB_CONNMODE: 548 case FTPLIB_CONNMODE:
549 v = (int) val; 549 v = (int) val;
550 if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT)) 550 if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT))
551 { 551 {
552 nControl->cmode = v; 552 nControl->cmode = v;
553 rv = 1; 553 rv = 1;
554 } 554 }
555 break; 555 break;
556 case FTPLIB_CALLBACK: 556 case FTPLIB_CALLBACK:
557 nControl->idlecb = (FtpCallback) val; 557 nControl->idlecb = (FtpCallback) val;
558 rv = 1; 558 rv = 1;
559 break; 559 break;
560 case FTPLIB_IDLETIME: 560 case FTPLIB_IDLETIME:
561 v = (int) val; 561 v = (int) val;
562 rv = 1; 562 rv = 1;
563 nControl->idletime.tv_sec = v / 1000; 563 nControl->idletime.tv_sec = v / 1000;
564 nControl->idletime.tv_usec = (v % 1000) * 1000; 564 nControl->idletime.tv_usec = (v % 1000) * 1000;
565 break; 565 break;
566 case FTPLIB_CALLBACKARG: 566 case FTPLIB_CALLBACKARG:
567 rv = 1; 567 rv = 1;
568 nControl->idlearg = (void *) val; 568 nControl->idlearg = (void *) val;
569 break; 569 break;
570 case FTPLIB_CALLBACKBYTES: 570 case FTPLIB_CALLBACKBYTES:
571 rv = 1; 571 rv = 1;
572 nControl->cbbytes = (int) val; 572 nControl->cbbytes = (int) val;
573 break; 573 break;
574 } 574 }
575 return rv; 575 return rv;
576} 576}
577 577
578/* 578/*
579 * FtpSendCmd - send a command and wait for expected response 579 * FtpSendCmd - send a command and wait for expected response
580 * 580 *
581 * return 1 if proper response received, 0 otherwise 581 * return 1 if proper response received, 0 otherwise
582 */ 582 */
583static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl) 583static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
584{ 584{
585 char buf[256]; 585 char buf[256];
586 if (nControl->dir != FTPLIB_CONTROL) 586 if (nControl->dir != FTPLIB_CONTROL)
587 return 0; 587 return 0;
588 if (ftplib_debug > 2) 588 if (ftplib_debug > 2)
589 fprintf(stderr,"%s\n",cmd); 589 fprintf(stderr,"%s\n",cmd);
590 if ((strlen(cmd) + 3) > sizeof(buf)) 590 if ((strlen(cmd) + 3) > sizeof(buf))
591 return 0; 591 return 0;
592 sprintf(buf,"%s\r\n",cmd); 592 sprintf(buf,"%s\r\n",cmd);
593 if (net_write(nControl->handle,buf,strlen(buf)) <= 0) 593 if (net_write(nControl->handle,buf,strlen(buf)) <= 0)
594 { 594 {
595 perror("write"); 595 perror("write");
596 return 0; 596 return 0;
597 } 597 }
598 return readresp(expresp, nControl); 598 return readresp(expresp, nControl);
599} 599}
600 600
601/* 601/*
602 * FtpLogin - log in to remote server 602 * FtpLogin - log in to remote server
603 * 603 *
604 * return 1 if logged in, 0 otherwise 604 * return 1 if logged in, 0 otherwise
605 */ 605 */
606GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl) 606GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl)
607{ 607{
608 char tempbuf[64]; 608 char tempbuf[64];
609 609
610 if (((strlen(user) + 7) > sizeof(tempbuf)) || 610 if (((strlen(user) + 7) > sizeof(tempbuf)) ||
611 ((strlen(pass) + 7) > sizeof(tempbuf))) 611 ((strlen(pass) + 7) > sizeof(tempbuf)))
612 return 0; 612 return 0;
613 sprintf(tempbuf,"USER %s",user); 613 sprintf(tempbuf,"USER %s",user);
614 if (!FtpSendCmd(tempbuf,'3',nControl)) 614 if (!FtpSendCmd(tempbuf,'3',nControl))
615 { 615 {
616 if (nControl->response[0] == '2') 616 if (nControl->response[0] == '2')
617 return 1; 617 return 1;
618 return 0; 618 return 0;
619 } 619 }
620 sprintf(tempbuf,"PASS %s",pass); 620 sprintf(tempbuf,"PASS %s",pass);
621 return FtpSendCmd(tempbuf,'2',nControl); 621 return FtpSendCmd(tempbuf,'2',nControl);
622} 622}
623 623
624/* 624/*
625 * FtpOpenPort - set up data connection 625 * FtpOpenPort - set up data connection
626 * 626 *
627 * return 1 if successful, 0 otherwise 627 * return 1 if successful, 0 otherwise
628 */ 628 */
629static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir) 629static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir)
630{ 630{
631 int sData; 631 int sData;
632 union { 632 union {
633 struct sockaddr sa; 633 struct sockaddr sa;
634 struct sockaddr_in in; 634 struct sockaddr_in in;
635 } sin; 635 } sin;
636 struct linger lng = { 0, 0 }; 636 struct linger lng = { 0, 0 };
637 unsigned int l; 637 unsigned int l;
638 int on=1; 638 int on=1;
639 netbuf *ctrl; 639 netbuf *ctrl;
640 char *cp; 640 char *cp;
641 unsigned int v[6]; 641 unsigned int v[6];
642 char buf[256]; 642 char buf[256];
643 643
644 if (nControl->dir != FTPLIB_CONTROL) 644 if (nControl->dir != FTPLIB_CONTROL)
645 return -1; 645 return -1;
646 if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE)) 646 if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE))
647 { 647 {
648 sprintf(nControl->response, "Invalid direction %d\n", dir); 648 sprintf(nControl->response, "Invalid direction %d\n", dir);
649 return -1; 649 return -1;
650 } 650 }
651 if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE)) 651 if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE))
652 { 652 {
653 sprintf(nControl->response, "Invalid mode %c\n", mode); 653 sprintf(nControl->response, "Invalid mode %c\n", mode);
654 return -1; 654 return -1;
655 } 655 }
656 l = sizeof(sin); 656 l = sizeof(sin);
657 if (nControl->cmode == FTPLIB_PASSIVE) 657 if (nControl->cmode == FTPLIB_PASSIVE)
658 { 658 {
659 memset(&sin, 0, l); 659 memset(&sin, 0, l);
660 sin.in.sin_family = AF_INET; 660 sin.in.sin_family = AF_INET;
661 if (!FtpSendCmd("PASV",'2',nControl)) 661 if (!FtpSendCmd("PASV",'2',nControl))
662 return -1; 662 return -1;
663 cp = strchr(nControl->response,'('); 663 cp = strchr(nControl->response,'(');
664 if (cp == NULL) 664 if (cp == NULL)
665 return -1; 665 return -1;
666 cp++; 666 cp++;
667 sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]); 667 sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]);
668 sin.sa.sa_data[2] = v[2]; 668 sin.sa.sa_data[2] = v[2];
669 sin.sa.sa_data[3] = v[3]; 669 sin.sa.sa_data[3] = v[3];
670 sin.sa.sa_data[4] = v[4]; 670 sin.sa.sa_data[4] = v[4];
671 sin.sa.sa_data[5] = v[5]; 671 sin.sa.sa_data[5] = v[5];
672 sin.sa.sa_data[0] = v[0]; 672 sin.sa.sa_data[0] = v[0];
673 sin.sa.sa_data[1] = v[1]; 673 sin.sa.sa_data[1] = v[1];
674 } 674 }
675 else 675 else
676 { 676 {
677 if (getsockname(nControl->handle, &sin.sa, &l) < 0) 677 if (getsockname(nControl->handle, &sin.sa, &l) < 0)
678 { 678 {
679 perror("getsockname"); 679 perror("getsockname");
680 return 0; 680 return 0;
681 } 681 }
682 } 682 }
683 sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); 683 sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
684 if (sData == -1) 684 if (sData == -1)
685 { 685 {
686 perror("socket"); 686 perror("socket");
687 return -1; 687 return -1;
688 } 688 }
689 if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR, 689 if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR,
690 SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1) 690 SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1)
691 { 691 {
692 perror("setsockopt"); 692 perror("setsockopt");
693 net_close(sData); 693 net_close(sData);
694 return -1; 694 return -1;
695 } 695 }
696 if (setsockopt(sData,SOL_SOCKET,SO_LINGER, 696 if (setsockopt(sData,SOL_SOCKET,SO_LINGER,
697 SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1) 697 SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1)
698 { 698 {
699 perror("setsockopt"); 699 perror("setsockopt");
700 net_close(sData); 700 net_close(sData);
701 return -1; 701 return -1;
702 } 702 }
703 if (nControl->cmode == FTPLIB_PASSIVE) 703 if (nControl->cmode == FTPLIB_PASSIVE)
704 { 704 {
705 if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1) 705 if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1)
706 { 706 {
707 perror("connect"); 707 perror("connect");
708 net_close(sData); 708 net_close(sData);
709 return -1; 709 return -1;
710 } 710 }
711 } 711 }
712 else 712 else
713 { 713 {
714 sin.in.sin_port = 0; 714 sin.in.sin_port = 0;
715 if (bind(sData, &sin.sa, sizeof(sin)) == -1) 715 if (bind(sData, &sin.sa, sizeof(sin)) == -1)
716 { 716 {
717 perror("bind"); 717 perror("bind");
718 net_close(sData); 718 net_close(sData);
719 return 0; 719 return 0;
720 } 720 }
721 if (listen(sData, 1) < 0) 721 if (listen(sData, 1) < 0)
722 { 722 {
723 perror("listen"); 723 perror("listen");
724 net_close(sData); 724 net_close(sData);
725 return 0; 725 return 0;
726 } 726 }
727 if (getsockname(sData, &sin.sa, &l) < 0) 727 if (getsockname(sData, &sin.sa, &l) < 0)
728 return 0; 728 return 0;
729 sprintf(buf, "PORT %d,%d,%d,%d,%d,%d", 729 sprintf(buf, "PORT %d,%d,%d,%d,%d,%d",
730 (unsigned char) sin.sa.sa_data[2], 730 (unsigned char) sin.sa.sa_data[2],
731 (unsigned char) sin.sa.sa_data[3], 731 (unsigned char) sin.sa.sa_data[3],
732 (unsigned char) sin.sa.sa_data[4], 732 (unsigned char) sin.sa.sa_data[4],
733 (unsigned char) sin.sa.sa_data[5], 733 (unsigned char) sin.sa.sa_data[5],
734 (unsigned char) sin.sa.sa_data[0], 734 (unsigned char) sin.sa.sa_data[0],
735 (unsigned char) sin.sa.sa_data[1]); 735 (unsigned char) sin.sa.sa_data[1]);
736 if (!FtpSendCmd(buf,'2',nControl)) 736 if (!FtpSendCmd(buf,'2',nControl))
737 { 737 {
738 net_close(sData); 738 net_close(sData);
739 return 0; 739 return 0;
740 } 740 }
741 } 741 }
742 ctrl = calloc(1,sizeof(netbuf)); 742 ctrl = calloc(1,sizeof(netbuf));
743 if (ctrl == NULL) 743 if (ctrl == NULL)
744 { 744 {
745 perror("calloc"); 745 perror("calloc");
746 net_close(sData); 746 net_close(sData);
747 return -1; 747 return -1;
748 } 748 }
749 if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL)) 749 if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL))
750 { 750 {
751 perror("calloc"); 751 perror("calloc");
752 net_close(sData); 752 net_close(sData);
753 free(ctrl); 753 free(ctrl);
754 return -1; 754 return -1;
755 } 755 }
756 ctrl->handle = sData; 756 ctrl->handle = sData;
757 ctrl->dir = dir; 757 ctrl->dir = dir;
758 ctrl->idletime = nControl->idletime; 758 ctrl->idletime = nControl->idletime;
759 ctrl->idlearg = nControl->idlearg; 759 ctrl->idlearg = nControl->idlearg;
760 ctrl->xfered = 0; 760 ctrl->xfered = 0;
761 ctrl->xfered1 = 0; 761 ctrl->xfered1 = 0;
762 ctrl->cbbytes = nControl->cbbytes; 762 ctrl->cbbytes = nControl->cbbytes;
763 if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes) 763 if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes)
764 ctrl->idlecb = nControl->idlecb; 764 ctrl->idlecb = nControl->idlecb;
765 else 765 else
766 ctrl->idlecb = NULL; 766 ctrl->idlecb = NULL;
767 *nData = ctrl; 767 *nData = ctrl;
768 return 1; 768 return 1;
769} 769}
770 770
771/* 771/*
772 * FtpAcceptConnection - accept connection from server 772 * FtpAcceptConnection - accept connection from server
773 * 773 *
774 * return 1 if successful, 0 otherwise 774 * return 1 if successful, 0 otherwise
775 */ 775 */
776static int FtpAcceptConnection(netbuf *nData, netbuf *nControl) 776static int FtpAcceptConnection(netbuf *nData, netbuf *nControl)
777{ 777{
778 int sData; 778 int sData;
779 struct sockaddr addr; 779 struct sockaddr addr;
780 unsigned int l; 780 unsigned int l;
781 int i; 781 int i;
782 struct timeval tv; 782 struct timeval tv;
783 fd_set mask; 783 fd_set mask;
784 int rv; 784 int rv = 1;
785 785
786 FD_ZERO(&mask); 786 FD_ZERO(&mask);
787 FD_SET(nControl->handle, &mask); 787 FD_SET(nControl->handle, &mask);
788 FD_SET(nData->handle, &mask); 788 FD_SET(nData->handle, &mask);
789 tv.tv_usec = 0; 789 tv.tv_usec = 0;
790 tv.tv_sec = ACCEPT_TIMEOUT; 790 tv.tv_sec = ACCEPT_TIMEOUT;
791 printf("<<<<<<<<<<<<<<<<%d\n",ACCEPT_TIMEOUT); 791 printf("<<<<<<<<<<<<<<<<%d\n",ACCEPT_TIMEOUT);
792 i = nControl->handle; 792 i = nControl->handle;
793 if (i < nData->handle) 793 if (i < nData->handle)
794 i = nData->handle; 794 i = nData->handle;
795 i = select(i+1, &mask, NULL, NULL, &tv); 795 i = select(i+1, &mask, NULL, NULL, &tv);
796 if (i == -1) 796 if (i == -1)
797 { 797 {
798 strncpy(nControl->response, strerror(errno), 798 strncpy(nControl->response, strerror(errno),
799 sizeof(nControl->response)); 799 sizeof(nControl->response));
800 net_close(nData->handle); 800 net_close(nData->handle);
801 nData->handle = 0; 801 nData->handle = 0;
802 rv = 0; 802 rv = 0;
803 } 803 }
804 else if (i == 0) 804 else if (i == 0)
805 { 805 {
806 strcpy(nControl->response, "timed out waiting for connection"); 806 strcpy(nControl->response, "timed out waiting for connection");
807 net_close(nData->handle); 807 net_close(nData->handle);
808 nData->handle = 0; 808 nData->handle = 0;
809 rv = 0; 809 rv = 0;
810 } 810 }
811 else 811 else
812 { 812 {
813 if (FD_ISSET(nData->handle, &mask)) 813 if (FD_ISSET(nData->handle, &mask))
814 { 814 {
815 l = sizeof(addr); 815 l = sizeof(addr);
816 sData = accept(nData->handle, &addr, &l); 816 sData = accept(nData->handle, &addr, &l);
817 i = errno; 817 i = errno;
818 net_close(nData->handle); 818 net_close(nData->handle);
819 if (sData > 0) 819 if (sData > 0)
820 { 820 {
821 rv = 1; 821 rv = 1;
822 nData->handle = sData; 822 nData->handle = sData;
823 } 823 }
824 else 824 else
825 { 825 {
826 strncpy(nControl->response, strerror(i), 826 strncpy(nControl->response, strerror(i),
827 sizeof(nControl->response)); 827 sizeof(nControl->response));
828 nData->handle = 0; 828 nData->handle = 0;
829 rv = 0; 829 rv = 0;
830 } 830 }
831 } 831 }
832 else if (FD_ISSET(nControl->handle, &mask)) 832 else if (FD_ISSET(nControl->handle, &mask))
833 { 833 {
834 net_close(nData->handle); 834 net_close(nData->handle);
835 nData->handle = 0; 835 nData->handle = 0;
836 readresp('2', nControl); 836 readresp('2', nControl);
837 rv = 0; 837 rv = 0;
838 } 838 }
839 } 839 }
840 return rv; 840 return rv;
841} 841}
842 842
843/* 843/*
844 * FtpAccess - return a handle for a data stream 844 * FtpAccess - return a handle for a data stream
845 * 845 *
846 * return 1 if successful, 0 otherwise 846 * return 1 if successful, 0 otherwise
847 */ 847 */
848GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl, 848GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl,
849 netbuf **nData) 849 netbuf **nData)
850{ 850{
851 char buf[256]; 851 char buf[256];
852 int dir; 852 int dir;
853 if ((path == NULL) && 853 if ((path == NULL) &&
854 ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ))) 854 ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ)))
855 { 855 {
856 sprintf(nControl->response, 856 sprintf(nControl->response,
857 "Missing path argument for file transfer\n"); 857 "Missing path argument for file transfer\n");
858 return 0; 858 return 0;
859 } 859 }
860 sprintf(buf, "TYPE %c", mode); 860 sprintf(buf, "TYPE %c", mode);
861 if (!FtpSendCmd(buf, '2', nControl)) 861 if (!FtpSendCmd(buf, '2', nControl))
862 return 0; 862 return 0;
863 switch (typ) 863 switch (typ)
864 { 864 {
865 case FTPLIB_DIR: 865 case FTPLIB_DIR:
866 strcpy(buf,"NLST"); 866 strcpy(buf,"NLST");
867 dir = FTPLIB_READ; 867 dir = FTPLIB_READ;
868 break; 868 break;
869 case FTPLIB_DIR_VERBOSE: 869 case FTPLIB_DIR_VERBOSE:
870 strcpy(buf,"LIST"); 870 strcpy(buf,"LIST");
871 dir = FTPLIB_READ; 871 dir = FTPLIB_READ;
872 break; 872 break;
873 case FTPLIB_FILE_READ: 873 case FTPLIB_FILE_READ:
874 strcpy(buf,"RETR"); 874 strcpy(buf,"RETR");
875 dir = FTPLIB_READ; 875 dir = FTPLIB_READ;
876 break; 876 break;
877 case FTPLIB_FILE_WRITE: 877 case FTPLIB_FILE_WRITE:
878 strcpy(buf,"STOR"); 878 strcpy(buf,"STOR");
879 dir = FTPLIB_WRITE; 879 dir = FTPLIB_WRITE;
880 break; 880 break;
881 default: 881 default:
882 sprintf(nControl->response, "Invalid open type %d\n", typ); 882 sprintf(nControl->response, "Invalid open type %d\n", typ);
883 return 0; 883 return 0;
884 } 884 }
885 if (path != NULL) 885 if (path != NULL)
886 { 886 {
887 int i = strlen(buf); 887 int i = strlen(buf);
888 buf[i++] = ' '; 888 buf[i++] = ' ';
889 if ((strlen(path) + i) >= sizeof(buf)) 889 if ((strlen(path) + i) >= sizeof(buf))
890 return 0; 890 return 0;
891 strcpy(&buf[i],path); 891 strcpy(&buf[i],path);
892 } 892 }
893 if (FtpOpenPort(nControl, nData, mode, dir) == -1) 893 if (FtpOpenPort(nControl, nData, mode, dir) == -1)
894 return 0; 894 return 0;
895 if (!FtpSendCmd(buf, '1', nControl)) 895 if (!FtpSendCmd(buf, '1', nControl))
896 { 896 {
897 FtpClose(*nData); 897 FtpClose(*nData);
898 *nData = NULL; 898 *nData = NULL;
899 return 0; 899 return 0;
900 } 900 }
901 (*nData)->ctrl = nControl; 901 (*nData)->ctrl = nControl;
902 nControl->data = *nData; 902 nControl->data = *nData;
903 if (nControl->cmode == FTPLIB_PORT) 903 if (nControl->cmode == FTPLIB_PORT)
904 { 904 {
905 if (!FtpAcceptConnection(*nData,nControl)) 905 if (!FtpAcceptConnection(*nData,nControl))
906 { 906 {
907 FtpClose(*nData); 907 FtpClose(*nData);
908 *nData = NULL; 908 *nData = NULL;
909 nControl->data = NULL; 909 nControl->data = NULL;
910 return 0; 910 return 0;
911 } 911 }
912 } 912 }
913 return 1; 913 return 1;
914} 914}
915 915
916/* 916/*
917 * FtpRead - read from a data connection 917 * FtpRead - read from a data connection
918 */ 918 */
919GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData) 919GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData)
920{ 920{
921 int i; 921 int i;
922 if (nData->dir != FTPLIB_READ) 922 if (nData->dir != FTPLIB_READ)
923 return 0; 923 return 0;
924 if (nData->buf) 924 if (nData->buf)
925 i = readline(buf, max, nData); 925 i = readline(buf, max, nData);
926 else 926 else
927 { 927 {
928 i = socket_wait(nData); 928 i = socket_wait(nData);
929 if (i != 1) 929 if (i != 1)
930 return 0; 930 return 0;
931 i = net_read(nData->handle, buf, max); 931 i = net_read(nData->handle, buf, max);
932 } 932 }
933 if (i == -1) 933 if (i == -1)
934 return 0; 934 return 0;
935 nData->xfered += i; 935 nData->xfered += i;
936 if (nData->idlecb && nData->cbbytes) 936 if (nData->idlecb && nData->cbbytes)
937 { 937 {
938 nData->xfered1 += i; 938 nData->xfered1 += i;
939 if (nData->xfered1 > nData->cbbytes) 939 if (nData->xfered1 > nData->cbbytes)
940 { 940 {
941 if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0) 941 if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0)
942 return 0; 942 return 0;
943 nData->xfered1 = 0; 943 nData->xfered1 = 0;
944 } 944 }
945 } 945 }
946 return i; 946 return i;
947} 947}
948 948
949/* 949/*
950 * FtpWrite - write to a data connection 950 * FtpWrite - write to a data connection
951 */ 951 */
952GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData) 952GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData)
953{ 953{
954 int i; 954 int i;
955 if (nData->dir != FTPLIB_WRITE) 955 if (nData->dir != FTPLIB_WRITE)
956 return 0; 956 return 0;
957 if (nData->buf) 957 if (nData->buf)
958 i = writeline(buf, len, nData); 958 i = writeline(buf, len, nData);
959 else 959 else
960 { 960 {
961 if (socket_wait(nData) < 0) 961 if (socket_wait(nData) < 0)
962 fprintf(stderr, "FtpWrite: socket_wait failed with %s\n", nData->ctrl->response); 962 fprintf(stderr, "FtpWrite: socket_wait failed with %s\n", nData->ctrl->response);
963 i = net_write(nData->handle, buf, len); 963 i = net_write(nData->handle, buf, len);
964 } 964 }
965 if (i == -1) 965 if (i == -1)
966 return 0; 966 return 0;
967 nData->xfered += i; 967 nData->xfered += i;
968 if (nData->idlecb && nData->cbbytes) 968 if (nData->idlecb && nData->cbbytes)
969 { 969 {
970 nData->xfered1 += i; 970 nData->xfered1 += i;
971 if (nData->xfered1 > nData->cbbytes) 971 if (nData->xfered1 > nData->cbbytes)
972 { 972 {
973 nData->idlecb(nData, nData->xfered, nData->idlearg); 973 nData->idlecb(nData, nData->xfered, nData->idlearg);
974 nData->xfered1 = 0; 974 nData->xfered1 = 0;
975 } 975 }
976 } 976 }
977 return i; 977 return i;
978} 978}
979 979
980/* 980/*
981 * FtpClose - close a data connection 981 * FtpClose - close a data connection
982 */ 982 */
983GLOBALDEF int FtpClose(netbuf *nData) 983GLOBALDEF int FtpClose(netbuf *nData)
984{ 984{
985 netbuf *ctrl; 985 netbuf *ctrl;
986 switch (nData->dir) 986 switch (nData->dir)
987 { 987 {
988 case FTPLIB_WRITE: 988 case FTPLIB_WRITE:
989 /* potential problem - if buffer flush fails, how to notify user? */ 989 /* potential problem - if buffer flush fails, how to notify user? */
990 if (nData->buf != NULL) 990 if (nData->buf != NULL)
991 writeline(NULL, 0, nData); 991 writeline(NULL, 0, nData);
992 case FTPLIB_READ: 992 case FTPLIB_READ:
993 if (nData->buf) 993 if (nData->buf)
994 free(nData->buf); 994 free(nData->buf);
995 shutdown(nData->handle,2); 995 shutdown(nData->handle,2);
996 net_close(nData->handle); 996 net_close(nData->handle);
997 ctrl = nData->ctrl; 997 ctrl = nData->ctrl;
998 free(nData); 998 free(nData);
999 if (ctrl) 999 if (ctrl)
1000 { 1000 {
1001 ctrl->data = NULL; 1001 ctrl->data = NULL;
1002 return(readresp('2', ctrl)); 1002 return(readresp('2', ctrl));
1003 } 1003 }
1004 return 1; 1004 return 1;
1005 case FTPLIB_CONTROL: 1005 case FTPLIB_CONTROL:
1006 if (nData->data) 1006 if (nData->data)
1007 { 1007 {
1008 nData->ctrl = NULL; 1008 nData->ctrl = NULL;
1009 FtpClose(nData); 1009 FtpClose(nData);
1010 } 1010 }
1011 net_close(nData->handle); 1011 net_close(nData->handle);
1012 free(nData); 1012 free(nData);
1013 return 0; 1013 return 0;
1014 } 1014 }
1015 return 1; 1015 return 1;
1016} 1016}
1017 1017
1018/* 1018/*
1019 * FtpSite - send a SITE command 1019 * FtpSite - send a SITE command
1020 * 1020 *
1021 * return 1 if command successful, 0 otherwise 1021 * return 1 if command successful, 0 otherwise
1022 */ 1022 */
1023GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl) 1023GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl)
1024{ 1024{
1025 char buf[256]; 1025 char buf[256];
1026 1026
1027 if ((strlen(cmd) + 7) > sizeof(buf)) 1027 if ((strlen(cmd) + 7) > sizeof(buf))
1028 return 0; 1028 return 0;
1029 sprintf(buf,"SITE %s",cmd); 1029 sprintf(buf,"SITE %s",cmd);
1030 if (!FtpSendCmd(buf,'2',nControl)) 1030 if (!FtpSendCmd(buf,'2',nControl))
1031 return 0; 1031 return 0;
1032 return 1; 1032 return 1;
1033} 1033}
1034 1034
1035/* 1035/*
1036 * FtpSysType - send a SYST command 1036 * FtpSysType - send a SYST command
1037 * 1037 *
1038 * Fills in the user buffer with the remote system type. If more 1038 * Fills in the user buffer with the remote system type. If more
1039 * information from the response is required, the user can parse 1039 * information from the response is required, the user can parse
1040 * it out of the response buffer returned by FtpLastResponse(). 1040 * it out of the response buffer returned by FtpLastResponse().
1041 * 1041 *
1042 * return 1 if command successful, 0 otherwise 1042 * return 1 if command successful, 0 otherwise
1043 */ 1043 */
1044GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl) 1044GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl)
1045{ 1045{
1046 int l = max; 1046 int l = max;
1047 char *b = buf; 1047 char *b = buf;
1048 char *s; 1048 char *s;
1049 if (!FtpSendCmd("SYST",'2',nControl)) 1049 if (!FtpSendCmd("SYST",'2',nControl))
1050 return 0; 1050 return 0;
1051 s = &nControl->response[4]; 1051 s = &nControl->response[4];
1052 while ((--l) && (*s != ' ')) 1052 while ((--l) && (*s != ' '))
1053 *b++ = *s++; 1053 *b++ = *s++;
1054 *b++ = '\0'; 1054 *b++ = '\0';
1055 return 1; 1055 return 1;
1056} 1056}
1057 1057
1058/* 1058/*
1059 * FtpMkdir - create a directory at server 1059 * FtpMkdir - create a directory at server
1060 * 1060 *
1061 * return 1 if successful, 0 otherwise 1061 * return 1 if successful, 0 otherwise
1062 */ 1062 */
1063GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl) 1063GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl)
1064{ 1064{
1065 char buf[256]; 1065 char buf[256];
1066 1066
1067 if ((strlen(path) + 6) > sizeof(buf)) 1067 if ((strlen(path) + 6) > sizeof(buf))
1068 return 0; 1068 return 0;
1069 sprintf(buf,"MKD %s",path); 1069 sprintf(buf,"MKD %s",path);
1070 if (!FtpSendCmd(buf,'2', nControl)) 1070 if (!FtpSendCmd(buf,'2', nControl))
1071 return 0; 1071 return 0;
1072 return 1; 1072 return 1;
1073} 1073}
1074 1074
1075/* 1075/*
1076 * FtpChdir - change path at remote 1076 * FtpChdir - change path at remote
1077 * 1077 *
1078 * return 1 if successful, 0 otherwise 1078 * return 1 if successful, 0 otherwise
1079 */ 1079 */
1080GLOBALDEF int FtpChdir(const char *path, netbuf *nControl) 1080GLOBALDEF int FtpChdir(const char *path, netbuf *nControl)
1081{ 1081{
1082 char buf[256]; 1082 char buf[256];
1083 1083
1084 if ((strlen(path) + 6) > sizeof(buf)) 1084 if ((strlen(path) + 6) > sizeof(buf))
1085 return 0; 1085 return 0;
1086 sprintf(buf,"CWD %s",path); 1086 sprintf(buf,"CWD %s",path);
1087 if (!FtpSendCmd(buf,'2',nControl)) 1087 if (!FtpSendCmd(buf,'2',nControl))
1088 return 0; 1088 return 0;
1089 return 1; 1089 return 1;
1090} 1090}
1091 1091
1092/* 1092/*
1093 * FtpCDUp - move to parent directory at remote 1093 * FtpCDUp - move to parent directory at remote
1094 * 1094 *
1095 * return 1 if successful, 0 otherwise 1095 * return 1 if successful, 0 otherwise
1096 */ 1096 */
1097GLOBALDEF int FtpCDUp(netbuf *nControl) 1097GLOBALDEF int FtpCDUp(netbuf *nControl)
1098{ 1098{
1099 if (!FtpSendCmd("CDUP",'2',nControl)) 1099 if (!FtpSendCmd("CDUP",'2',nControl))
1100 return 0; 1100 return 0;
1101 return 1; 1101 return 1;
1102} 1102}
1103 1103
1104/* 1104/*
1105 * FtpRmdir - remove directory at remote 1105 * FtpRmdir - remove directory at remote
1106 * 1106 *
1107 * return 1 if successful, 0 otherwise 1107 * return 1 if successful, 0 otherwise
1108 */ 1108 */
1109GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl) 1109GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl)
1110{ 1110{
1111 char buf[256]; 1111 char buf[256];
1112 1112
1113 if ((strlen(path) + 6) > sizeof(buf)) 1113 if ((strlen(path) + 6) > sizeof(buf))
1114 return 0; 1114 return 0;
1115 sprintf(buf,"RMD %s",path); 1115 sprintf(buf,"RMD %s",path);
1116 if (!FtpSendCmd(buf,'2',nControl)) 1116 if (!FtpSendCmd(buf,'2',nControl))
1117 return 0; 1117 return 0;
1118 return 1; 1118 return 1;
1119} 1119}
1120 1120
1121/* 1121/*
1122 * FtpPwd - get working directory at remote 1122 * FtpPwd - get working directory at remote
1123 * 1123 *
1124 * return 1 if successful, 0 otherwise 1124 * return 1 if successful, 0 otherwise
1125 */ 1125 */
1126GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl) 1126GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl)
1127{ 1127{
1128 int l = max; 1128 int l = max;
1129 char *b = path; 1129 char *b = path;
1130 char *s; 1130 char *s;
1131 if (!FtpSendCmd("PWD",'2',nControl)) 1131 if (!FtpSendCmd("PWD",'2',nControl))
1132 return 0; 1132 return 0;
1133 s = strchr(nControl->response, '"'); 1133 s = strchr(nControl->response, '"');
1134 if (s == NULL) 1134 if (s == NULL)
1135 return 0; 1135 return 0;
1136 s++; 1136 s++;
1137 while ((--l) && (*s) && (*s != '"')) 1137 while ((--l) && (*s) && (*s != '"'))
1138 *b++ = *s++; 1138 *b++ = *s++;
1139 *b++ = '\0'; 1139 *b++ = '\0';
1140 return 1; 1140 return 1;
1141} 1141}
1142 1142
1143/* 1143/*
1144 * FtpXfer - issue a command and transfer data 1144 * FtpXfer - issue a command and transfer data
1145 * 1145 *
1146 * return 1 if successful, 0 otherwise 1146 * return 1 if successful, 0 otherwise
1147 */ 1147 */
1148static int FtpXfer(const char *localfile, const char *path, 1148static int FtpXfer(const char *localfile, const char *path,
1149 netbuf *nControl, int typ, int mode) 1149 netbuf *nControl, int typ, int mode)
1150{ 1150{
1151 int l,c; 1151 int l,c;
1152 char *dbuf; 1152 char *dbuf;
1153 FILE *local = NULL; 1153 FILE *local = NULL;
1154 netbuf *nData; 1154 netbuf *nData;
1155 int rv=1; 1155 int rv=1;
1156 1156
1157 if (localfile != NULL) 1157 if (localfile != NULL)
1158 { 1158 {
1159 char ac[4] = "w"; 1159 char ac[4] = "w";
1160 if (typ == FTPLIB_FILE_WRITE) 1160 if (typ == FTPLIB_FILE_WRITE)
1161 ac[0] = 'r'; 1161 ac[0] = 'r';
1162 if (mode == FTPLIB_IMAGE) 1162 if (mode == FTPLIB_IMAGE)
1163 ac[1] = 'b'; 1163 ac[1] = 'b';
1164 local = fopen(localfile, ac); 1164 local = fopen(localfile, ac);
1165 if (local == NULL) 1165 if (local == NULL)
1166 { 1166 {
1167 strncpy(nControl->response, strerror(errno), 1167 strncpy(nControl->response, strerror(errno),
1168 sizeof(nControl->response)); 1168 sizeof(nControl->response));
1169 return 0; 1169 return 0;
1170 } 1170 }
1171 } 1171 }
1172 if (local == NULL) 1172 if (local == NULL)
1173 local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout; 1173 local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout;
1174 if (!FtpAccess(path, typ, mode, nControl, &nData)) 1174 if (!FtpAccess(path, typ, mode, nControl, &nData))
1175 { 1175 {
1176 if (localfile != NULL) 1176 if (localfile != NULL)
1177 fclose(local); 1177 fclose(local);
1178 return 0; 1178 return 0;
1179 } 1179 }
1180 dbuf = malloc(FTPLIB_BUFSIZ); 1180 dbuf = malloc(FTPLIB_BUFSIZ);
1181 if (typ == FTPLIB_FILE_WRITE) 1181 if (typ == FTPLIB_FILE_WRITE)
1182 { 1182 {
1183 while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0) 1183 while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0)
1184 if ((c = FtpWrite(dbuf, l, nData)) < l) 1184 if ((c = FtpWrite(dbuf, l, nData)) < l)
1185 { 1185 {
1186 printf("short write: passed %d, wrote %d\n", l, c); 1186 printf("short write: passed %d, wrote %d\n", l, c);
1187 rv = 0; 1187 rv = 0;
1188 break; 1188 break;
1189 } 1189 }
1190 } 1190 }
1191 else 1191 else
1192 { 1192 {
1193 while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) 1193 while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0)
1194 if (fwrite(dbuf, 1, l, local) <= 0) 1194 if (fwrite(dbuf, 1, l, local) <= 0)
1195 { 1195 {
1196 perror("localfile write"); 1196 perror("localfile write");
1197 rv = 0; 1197 rv = 0;
1198 break; 1198 break;
1199 } 1199 }
1200 } 1200 }
1201 free(dbuf); 1201 free(dbuf);
1202 fflush(local); 1202 fflush(local);
1203 if (localfile != NULL) 1203 if (localfile != NULL)
1204 fclose(local); 1204 fclose(local);
1205 FtpClose(nData); 1205 FtpClose(nData);
1206 return rv; 1206 return rv;
1207} 1207}
1208 1208
1209/* 1209/*
1210 * FtpNlst - issue an NLST command and write response to output 1210 * FtpNlst - issue an NLST command and write response to output
1211 * 1211 *
1212 * return 1 if successful, 0 otherwise 1212 * return 1 if successful, 0 otherwise
1213 */ 1213 */
1214GLOBALDEF int FtpNlst(const char *outputfile, const char *path, 1214GLOBALDEF int FtpNlst(const char *outputfile, const char *path,
1215 netbuf *nControl) 1215 netbuf *nControl)
1216{ 1216{
1217 return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII); 1217 return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII);
1218} 1218}
1219 1219
1220/* 1220/*
1221 * FtpDir - issue a LIST command and write response to output 1221 * FtpDir - issue a LIST command and write response to output
1222 * 1222 *
1223 * return 1 if successful, 0 otherwise 1223 * return 1 if successful, 0 otherwise
1224 */ 1224 */
1225GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl) 1225GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl)
1226{ 1226{
1227 return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII); 1227 return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII);
1228} 1228}
1229 1229
1230/* 1230/*
1231 * FtpSize - determine the size of a remote file 1231 * FtpSize - determine the size of a remote file
1232 * 1232 *
1233 * return 1 if successful, 0 otherwise 1233 * return 1 if successful, 0 otherwise
1234 */ 1234 */
1235GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl) 1235GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl)
1236{ 1236{
1237 char cmd[256]; 1237 char cmd[256];
1238 int resp,sz,rv=1; 1238 int resp,sz,rv=1;
1239 1239
1240 if ((strlen(path) + 7) > sizeof(cmd)) 1240 if ((strlen(path) + 7) > sizeof(cmd))
1241 return 0; 1241 return 0;
1242 sprintf(cmd, "TYPE %c", mode); 1242 sprintf(cmd, "TYPE %c", mode);
1243 if (!FtpSendCmd(cmd, '2', nControl)) 1243 if (!FtpSendCmd(cmd, '2', nControl))
1244 return 0; 1244 return 0;
1245 sprintf(cmd,"SIZE %s",path); 1245 sprintf(cmd,"SIZE %s",path);
1246 if (!FtpSendCmd(cmd,'2',nControl)) 1246 if (!FtpSendCmd(cmd,'2',nControl))
1247 rv = 0; 1247 rv = 0;
1248 else 1248 else
1249 { 1249 {
1250 if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2) 1250 if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2)
1251 *size = sz; 1251 *size = sz;
1252 else 1252 else
1253 rv = 0; 1253 rv = 0;
1254 } 1254 }
1255 return rv; 1255 return rv;
1256} 1256}
1257 1257
1258/* 1258/*
1259 * FtpModDate - determine the modification date of a remote file 1259 * FtpModDate - determine the modification date of a remote file
1260 * 1260 *
1261 * return 1 if successful, 0 otherwise 1261 * return 1 if successful, 0 otherwise
1262 */ 1262 */
1263GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl) 1263GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl)
1264{ 1264{
1265 char buf[256]; 1265 char buf[256];
1266 int rv = 1; 1266 int rv = 1;
1267 1267
1268 if ((strlen(path) + 7) > sizeof(buf)) 1268 if ((strlen(path) + 7) > sizeof(buf))
1269 return 0; 1269 return 0;
1270 sprintf(buf,"MDTM %s",path); 1270 sprintf(buf,"MDTM %s",path);
1271 if (!FtpSendCmd(buf,'2',nControl)) 1271 if (!FtpSendCmd(buf,'2',nControl))
1272 rv = 0; 1272 rv = 0;
1273 else 1273 else
1274 strncpy(dt, &nControl->response[4], max); 1274 strncpy(dt, &nControl->response[4], max);
1275 return rv; 1275 return rv;
1276} 1276}
1277 1277
1278/* 1278/*
1279 * FtpGet - issue a GET command and write received data to output 1279 * FtpGet - issue a GET command and write received data to output
1280 * 1280 *
1281 * return 1 if successful, 0 otherwise 1281 * return 1 if successful, 0 otherwise
1282 */ 1282 */
1283GLOBALDEF int FtpGet(const char *outputfile, const char *path, 1283GLOBALDEF int FtpGet(const char *outputfile, const char *path,
1284 char mode, netbuf *nControl) 1284 char mode, netbuf *nControl)
1285{ 1285{
1286 return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode); 1286 return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode);
1287} 1287}
1288 1288
1289/* 1289/*
1290 * FtpPut - issue a PUT command and send data from input 1290 * FtpPut - issue a PUT command and send data from input
1291 * 1291 *
1292 * return 1 if successful, 0 otherwise 1292 * return 1 if successful, 0 otherwise
1293 */ 1293 */
1294GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode, 1294GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode,
1295 netbuf *nControl) 1295 netbuf *nControl)
1296{ 1296{
1297 return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode); 1297 return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode);
1298} 1298}
1299 1299
1300/* 1300/*
1301 * FtpRename - rename a file at remote 1301 * FtpRename - rename a file at remote
1302 * 1302 *
1303 * return 1 if successful, 0 otherwise 1303 * return 1 if successful, 0 otherwise
1304 */ 1304 */
1305GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl) 1305GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl)
1306{ 1306{
1307 char cmd[256]; 1307 char cmd[256];
1308 1308
1309 if (((strlen(src) + 7) > sizeof(cmd)) || 1309 if (((strlen(src) + 7) > sizeof(cmd)) ||
1310 ((strlen(dst) + 7) > sizeof(cmd))) 1310 ((strlen(dst) + 7) > sizeof(cmd)))
1311 return 0; 1311 return 0;
1312 sprintf(cmd,"RNFR %s",src); 1312 sprintf(cmd,"RNFR %s",src);
1313 if (!FtpSendCmd(cmd,'3',nControl)) 1313 if (!FtpSendCmd(cmd,'3',nControl))
1314 return 0; 1314 return 0;
1315 sprintf(cmd,"RNTO %s",dst); 1315 sprintf(cmd,"RNTO %s",dst);
1316 if (!FtpSendCmd(cmd,'2',nControl)) 1316 if (!FtpSendCmd(cmd,'2',nControl))
1317 return 0; 1317 return 0;
1318 return 1; 1318 return 1;
1319} 1319}
1320 1320
1321/* 1321/*
1322 * FtpDelete - delete a file at remote 1322 * FtpDelete - delete a file at remote
1323 * 1323 *
1324 * return 1 if successful, 0 otherwise 1324 * return 1 if successful, 0 otherwise
1325 */ 1325 */
1326GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl) 1326GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl)
1327{ 1327{
1328 char cmd[256]; 1328 char cmd[256];
1329 1329
1330 if ((strlen(fnm) + 7) > sizeof(cmd)) 1330 if ((strlen(fnm) + 7) > sizeof(cmd))
1331 return 0; 1331 return 0;
1332 sprintf(cmd,"DELE %s",fnm); 1332 sprintf(cmd,"DELE %s",fnm);
1333 if (!FtpSendCmd(cmd,'2', nControl)) 1333 if (!FtpSendCmd(cmd,'2', nControl))
1334 return 0; 1334 return 0;
1335 return 1; 1335 return 1;
1336} 1336}
1337 1337
1338/* 1338/*
1339 * FtpQuit - disconnect from remote 1339 * FtpQuit - disconnect from remote
1340 * 1340 *
1341 * return 1 if successful, 0 otherwise 1341 * return 1 if successful, 0 otherwise
1342 */ 1342 */
1343GLOBALDEF void FtpQuit(netbuf *nControl) 1343GLOBALDEF void FtpQuit(netbuf *nControl)
1344{ 1344{
1345 if (nControl->dir != FTPLIB_CONTROL) 1345 if (nControl->dir != FTPLIB_CONTROL)
1346 return; 1346 return;
1347 if (FtpSendCmd("QUIT",'2',nControl) == 1) { 1347 if (FtpSendCmd("QUIT",'2',nControl) == 1) {
1348 if (ftplib_debug > 2) 1348 if (ftplib_debug > 2)
1349 fprintf(stderr, "FtpQuit: FtpSendCmd(QUIT) failed\n"); 1349 fprintf(stderr, "FtpQuit: FtpSendCmd(QUIT) failed\n");
1350 } 1350 }
1351 net_close(nControl->handle); 1351 net_close(nControl->handle);
1352 free(nControl->buf); 1352 free(nControl->buf);
1353 free(nControl); 1353 free(nControl);
1354} 1354}
diff --git a/noncore/settings/sysinfo/contrib/dhry.c b/noncore/settings/sysinfo/contrib/dhry.c
index 07fd1c0..5426157 100644
--- a/noncore/settings/sysinfo/contrib/dhry.c
+++ b/noncore/settings/sysinfo/contrib/dhry.c
@@ -1,1010 +1,1010 @@
1/*****************************************************/ 1/*****************************************************/
2/* Various timer routines. */ 2/* Various timer routines. */
3/* Al Aburto, aburto@nosc.mil, 18 Feb 1997 */ 3/* Al Aburto, aburto@nosc.mil, 18 Feb 1997 */
4/* */ 4/* */
5/* t = dtime() outputs the current time in seconds. */ 5/* t = dtime() outputs the current time in seconds. */
6/* Use CAUTION as some of these routines will mess */ 6/* Use CAUTION as some of these routines will mess */
7/* up when timing across the hour mark!!! */ 7/* up when timing across the hour mark!!! */
8/* */ 8/* */
9/* For timing I use the 'user' time whenever */ 9/* For timing I use the 'user' time whenever */
10/* possible. Using 'user+sys' time is a separate */ 10/* possible. Using 'user+sys' time is a separate */
11/* issue. */ 11/* issue. */
12/* */ 12/* */
13/* Example Usage: */ 13/* Example Usage: */
14/* [timer options added here] */ 14/* [timer options added here] */
15/* main() */ 15/* main() */
16/* { */ 16/* { */
17/* double starttime,benchtime,dtime(); */ 17/* double starttime,benchtime,dtime(); */
18/* */ 18/* */
19/* starttime = dtime(); */ 19/* starttime = dtime(); */
20/* [routine to time] */ 20/* [routine to time] */
21/* benchtime = dtime() - starttime; */ 21/* benchtime = dtime() - starttime; */
22/* } */ 22/* } */
23/* */ 23/* */
24/* [timer code below added here] */ 24/* [timer code below added here] */
25/*****************************************************/ 25/*****************************************************/
26 26
27/***************************************************************/ 27/***************************************************************/
28/* Timer options. You MUST uncomment one of the options below */ 28/* Timer options. You MUST uncomment one of the options below */
29/* or compile, for example, with the '-DUNIX' option. */ 29/* or compile, for example, with the '-DUNIX' option. */
30/***************************************************************/ 30/***************************************************************/
31/* #define Amiga */ 31/* #define Amiga */
32/* #define UNIX */ 32/* #define UNIX */
33/* #define UNIX_Old */ 33/* #define UNIX_Old */
34/* #define VMS */ 34/* #define VMS */
35/* #define BORLAND_C */ 35/* #define BORLAND_C */
36/* #define MSC */ 36/* #define MSC */
37/* #define MAC */ 37/* #define MAC */
38/* #define IPSC */ 38/* #define IPSC */
39/* #define FORTRAN_SEC */ 39/* #define FORTRAN_SEC */
40/* #define GTODay */ 40/* #define GTODay */
41/* #define CTimer */ 41/* #define CTimer */
42/* #define UXPM */ 42/* #define UXPM */
43/* #define MAC_TMgr */ 43/* #define MAC_TMgr */
44/* #define PARIX */ 44/* #define PARIX */
45/* #define POSIX */ 45/* #define POSIX */
46/* #define WIN32 */ 46/* #define WIN32 */
47/* #define POSIX1 */ 47/* #define POSIX1 */
48/***********************/ 48/***********************/
49 49
50/*********************************/ 50/*********************************/
51/* Timer code. */ 51/* Timer code. */
52/*********************************/ 52/*********************************/
53/*******************/ 53/*******************/
54/* Amiga dtime() */ 54/* Amiga dtime() */
55/*******************/ 55/*******************/
56#ifdef Amiga 56#ifdef Amiga
57#include <ctype.h> 57#include <ctype.h>
58#define HZ 50 58#define HZ 50
59 59
60double dtime() 60double dtime()
61{ 61{
62 double q; 62 double q;
63 63
64 struct tt 64 struct tt
65 { 65 {
66 long days; 66 long days;
67 long minutes; 67 long minutes;
68 long ticks; 68 long ticks;
69 } tt; 69 } tt;
70 70
71 DateStamp(&tt); 71 DateStamp(&tt);
72 72
73 q = ((double)(tt.ticks + (tt.minutes * 60L * 50L))) / (double)HZ; 73 q = ((double)(tt.ticks + (tt.minutes * 60L * 50L))) / (double)HZ;
74 74
75 return q; 75 return q;
76} 76}
77#endif 77#endif
78 78
79/*****************************************************/ 79/*****************************************************/
80/* UNIX dtime(). This is the preferred UNIX timer. */ 80/* UNIX dtime(). This is the preferred UNIX timer. */
81/* Provided by: Markku Kolkka, mk59200@cc.tut.fi */ 81/* Provided by: Markku Kolkka, mk59200@cc.tut.fi */
82/* HP-UX Addition by: Bo Thide', bt@irfu.se */ 82/* HP-UX Addition by: Bo Thide', bt@irfu.se */
83/*****************************************************/ 83/*****************************************************/
84#ifdef UNIX 84#ifdef UNIX
85#include <sys/time.h> 85#include <sys/time.h>
86#include <sys/resource.h> 86#include <sys/resource.h>
87 87
88#ifdef hpux 88#ifdef hpux
89#include <sys/syscall.h> 89#include <sys/syscall.h>
90#define getrusage(a,b) syscall(SYS_getrusage,a,b) 90#define getrusage(a,b) syscall(SYS_getrusage,a,b)
91#endif 91#endif
92 92
93struct rusage rusage; 93struct rusage rusage;
94 94
95double dtime() 95double dtime()
96{ 96{
97 double q; 97 double q;
98 98
99 getrusage(RUSAGE_SELF,&rusage); 99 getrusage(RUSAGE_SELF,&rusage);
100 100
101 q = (double)(rusage.ru_utime.tv_sec); 101 q = (double)(rusage.ru_utime.tv_sec);
102 q = q + (double)(rusage.ru_utime.tv_usec) * 1.0e-06; 102 q = q + (double)(rusage.ru_utime.tv_usec) * 1.0e-06;
103 103
104 return q; 104 return q;
105} 105}
106#endif 106#endif
107 107
108/***************************************************/ 108/***************************************************/
109/* UNIX_Old dtime(). This is the old UNIX timer. */ 109/* UNIX_Old dtime(). This is the old UNIX timer. */
110/* Make sure HZ is properly defined in param.h !! */ 110/* Make sure HZ is properly defined in param.h !! */
111/***************************************************/ 111/***************************************************/
112#ifdef UNIX_Old 112#ifdef UNIX_Old
113#include <sys/types.h> 113#include <sys/types.h>
114#include <sys/times.h> 114#include <sys/times.h>
115#include <sys/param.h> 115#include <sys/param.h>
116 116
117#ifndef HZ 117#ifndef HZ
118#define HZ 60 118#define HZ 60
119#endif 119#endif
120 120
121struct tms tms; 121struct tms tms;
122 122
123double dtime() 123double dtime()
124{ 124{
125 double q; 125 double q;
126 126
127 times(&tms); 127 times(&tms);
128 128
129 q = (double)(tms.tms_utime) / (double)HZ; 129 q = (double)(tms.tms_utime) / (double)HZ;
130 130
131 return q; 131 return q;
132} 132}
133#endif 133#endif
134 134
135/*********************************************************/ 135/*********************************************************/
136/* VMS dtime() for VMS systems. */ 136/* VMS dtime() for VMS systems. */
137/* Provided by: RAMO@uvphys.phys.UVic.CA */ 137/* Provided by: RAMO@uvphys.phys.UVic.CA */
138/* Some people have run into problems with this timer. */ 138/* Some people have run into problems with this timer. */
139/*********************************************************/ 139/*********************************************************/
140#ifdef VMS 140#ifdef VMS
141#include time 141#include time
142 142
143#ifndef HZ 143#ifndef HZ
144#define HZ 100 144#define HZ 100
145#endif 145#endif
146 146
147struct tbuffer_t 147struct tbuffer_t
148 { 148 {
149 int proc_user_time; 149 int proc_user_time;
150 int proc_system_time; 150 int proc_system_time;
151 int child_user_time; 151 int child_user_time;
152 int child_system_time; 152 int child_system_time;
153 }; 153 };
154 154
155struct tbuffer_t tms; 155struct tbuffer_t tms;
156 156
157double dtime() 157double dtime()
158{ 158{
159 double q; 159 double q;
160 160
161 times(&tms); 161 times(&tms);
162 162
163 q = (double)(tms.proc_user_time) / (double)HZ; 163 q = (double)(tms.proc_user_time) / (double)HZ;
164 164
165 return q; 165 return q;
166} 166}
167#endif 167#endif
168 168
169/******************************/ 169/******************************/
170/* BORLAND C dtime() for DOS */ 170/* BORLAND C dtime() for DOS */
171/******************************/ 171/******************************/
172#ifdef BORLAND_C 172#ifdef BORLAND_C
173#include <ctype.h> 173#include <ctype.h>
174#include <dos.h> 174#include <dos.h>
175#include <time.h> 175#include <time.h>
176 176
177#define HZ 100 177#define HZ 100
178struct time tnow; 178struct time tnow;
179 179
180double dtime() 180double dtime()
181{ 181{
182 double q; 182 double q;
183 183
184 gettime(&tnow); 184 gettime(&tnow);
185 185
186 q = 60.0 * (double)(tnow.ti_min); 186 q = 60.0 * (double)(tnow.ti_min);
187 q = q + (double)(tnow.ti_sec); 187 q = q + (double)(tnow.ti_sec);
188 q = q + (double)(tnow.ti_hund)/(double)HZ; 188 q = q + (double)(tnow.ti_hund)/(double)HZ;
189 189
190 return q; 190 return q;
191} 191}
192#endif 192#endif
193 193
194/**************************************/ 194/**************************************/
195/* Microsoft C (MSC) dtime() for DOS */ 195/* Microsoft C (MSC) dtime() for DOS */
196/**************************************/ 196/**************************************/
197#ifdef MSC 197#ifdef MSC
198#include <time.h> 198#include <time.h>
199#include <ctype.h> 199#include <ctype.h>
200 200
201#define HZ CLOCKS_PER_SEC 201#define HZ CLOCKS_PER_SEC
202clock_t tnow; 202clock_t tnow;
203 203
204double dtime() 204double dtime()
205{ 205{
206 double q; 206 double q;
207 207
208 tnow = clock(); 208 tnow = clock();
209 209
210 q = (double)tnow / (double)HZ; 210 q = (double)tnow / (double)HZ;
211 211
212 return q; 212 return q;
213} 213}
214#endif 214#endif
215 215
216/*************************************/ 216/*************************************/
217/* Macintosh (MAC) Think C dtime() */ 217/* Macintosh (MAC) Think C dtime() */
218/*************************************/ 218/*************************************/
219#ifdef MAC 219#ifdef MAC
220#include <time.h> 220#include <time.h>
221 221
222#define HZ 60 222#define HZ 60
223 223
224double dtime() 224double dtime()
225{ 225{
226 double q; 226 double q;
227 227
228 q = (double)clock() / (double)HZ; 228 q = (double)clock() / (double)HZ;
229 229
230 return q; 230 return q;
231} 231}
232#endif 232#endif
233 233
234/************************************************************/ 234/************************************************************/
235/* iPSC/860 (IPSC) dtime() for i860. */ 235/* iPSC/860 (IPSC) dtime() for i860. */
236/* Provided by: Dan Yergeau, yergeau@gloworm.Stanford.EDU */ 236/* Provided by: Dan Yergeau, yergeau@gloworm.Stanford.EDU */
237/************************************************************/ 237/************************************************************/
238#ifdef IPSC 238#ifdef IPSC
239extern double dclock(); 239extern double dclock();
240 240
241double dtime() 241double dtime()
242{ 242{
243 double q; 243 double q;
244 244
245 q = dclock(); 245 q = dclock();
246 246
247 return q; 247 return q;
248} 248}
249#endif 249#endif
250 250
251/**************************************************/ 251/**************************************************/
252/* FORTRAN dtime() for Cray type systems. */ 252/* FORTRAN dtime() for Cray type systems. */
253/* This is the preferred timer for Cray systems. */ 253/* This is the preferred timer for Cray systems. */
254/**************************************************/ 254/**************************************************/
255#ifdef FORTRAN_SEC 255#ifdef FORTRAN_SEC
256 256
257fortran double second(); 257fortran double second();
258 258
259double dtime() 259double dtime()
260{ 260{
261 double q; 261 double q;
262 262
263 second(&q); 263 second(&q);
264 264
265 return q; 265 return q;
266} 266}
267#endif 267#endif
268 268
269/***********************************************************/ 269/***********************************************************/
270/* UNICOS C dtime() for Cray UNICOS systems. Don't use */ 270/* UNICOS C dtime() for Cray UNICOS systems. Don't use */
271/* unless absolutely necessary as returned time includes */ 271/* unless absolutely necessary as returned time includes */
272/* 'user+system' time. Provided by: R. Mike Dority, */ 272/* 'user+system' time. Provided by: R. Mike Dority, */
273/* dority@craysea.cray.com */ 273/* dority@craysea.cray.com */
274/***********************************************************/ 274/***********************************************************/
275#ifdef CTimer 275#ifdef CTimer
276#include <time.h> 276#include <time.h>
277 277
278double dtime() 278double dtime()
279{ 279{
280 double q; 280 double q;
281 clock_t clock(void); 281 clock_t clock(void);
282 282
283 q = (double)clock() / (double)CLOCKS_PER_SEC; 283 q = (double)clock() / (double)CLOCKS_PER_SEC;
284 284
285 return q; 285 return q;
286} 286}
287#endif 287#endif
288 288
289/********************************************/ 289/********************************************/
290/* Another UNIX timer using gettimeofday(). */ 290/* Another UNIX timer using gettimeofday(). */
291/* However, getrusage() is preferred. */ 291/* However, getrusage() is preferred. */
292/********************************************/ 292/********************************************/
293#ifdef GTODay 293#ifdef GTODay
294#include <sys/time.h> 294#include <sys/time.h>
295 295
296struct timeval tnow; 296struct timeval tnow;
297 297
298double dtime() 298double dtime()
299{ 299{
300 double q; 300 double q;
301 301
302 gettimeofday(&tnow,NULL); 302 gettimeofday(&tnow,NULL);
303 q = (double)tnow.tv_sec + (double)tnow.tv_usec * 1.0e-6; 303 q = (double)tnow.tv_sec + (double)tnow.tv_usec * 1.0e-6;
304 304
305 return q; 305 return q;
306} 306}
307#endif 307#endif
308 308
309/*****************************************************/ 309/*****************************************************/
310/* Fujitsu UXP/M timer. */ 310/* Fujitsu UXP/M timer. */
311/* Provided by: Mathew Lim, ANUSF, M.Lim@anu.edu.au */ 311/* Provided by: Mathew Lim, ANUSF, M.Lim@anu.edu.au */
312/*****************************************************/ 312/*****************************************************/
313#ifdef UXPM 313#ifdef UXPM
314#include <sys/types.h> 314#include <sys/types.h>
315#include <sys/timesu.h> 315#include <sys/timesu.h>
316struct tmsu rusage; 316struct tmsu rusage;
317 317
318double dtime() 318double dtime()
319{ 319{
320 double q; 320 double q;
321 321
322 timesu(&rusage); 322 timesu(&rusage);
323 323
324 q = (double)(rusage.tms_utime) * 1.0e-06; 324 q = (double)(rusage.tms_utime) * 1.0e-06;
325 325
326 return q; 326 return q;
327} 327}
328#endif 328#endif
329 329
330/**********************************************/ 330/**********************************************/
331/* Macintosh (MAC_TMgr) Think C dtime() */ 331/* Macintosh (MAC_TMgr) Think C dtime() */
332/* requires Think C Language Extensions or */ 332/* requires Think C Language Extensions or */
333/* #include <MacHeaders> in the prefix */ 333/* #include <MacHeaders> in the prefix */
334/* provided by Francis H Schiffer 3rd (fhs) */ 334/* provided by Francis H Schiffer 3rd (fhs) */
335/* skipschiffer@genie.geis.com */ 335/* skipschiffer@genie.geis.com */
336/**********************************************/ 336/**********************************************/
337#ifdef MAC_TMgr 337#ifdef MAC_TMgr
338#include <Timer.h> 338#include <Timer.h>
339#include <stdlib.h> 339#include <stdlib.h>
340 340
341static TMTask mgrTimer; 341static TMTask mgrTimer;
342static Boolean mgrInited = false; 342static Boolean mgrInited = false;
343static double mgrClock; 343static double mgrClock;
344 344
345#define RMV_TIMER RmvTime( (QElemPtr)&mgrTimer ) 345#define RMV_TIMER RmvTime( (QElemPtr)&mgrTimer )
346#define MAX_TIME 1800000000L 346#define MAX_TIME 1800000000L
347/* MAX_TIME limits time between calls to */ 347/* MAX_TIME limits time between calls to */
348/* dtime( ) to no more than 30 minutes */ 348/* dtime( ) to no more than 30 minutes */
349/* this limitation could be removed by */ 349/* this limitation could be removed by */
350/* creating a completion routine to sum */ 350/* creating a completion routine to sum */
351/* 30 minute segments (fhs 1994 feb 9) */ 351/* 30 minute segments (fhs 1994 feb 9) */
352 352
353static void Remove_timer( ) 353static void Remove_timer( )
354{ 354{
355 RMV_TIMER; 355 RMV_TIMER;
356 mgrInited = false; 356 mgrInited = false;
357} 357}
358 358
359double dtime( ) 359double dtime( )
360{ 360{
361 if( mgrInited ) { 361 if( mgrInited ) {
362 RMV_TIMER; 362 RMV_TIMER;
363 mgrClock += (MAX_TIME + mgrTimer.tmCount)*1.0e-6; 363 mgrClock += (MAX_TIME + mgrTimer.tmCount)*1.0e-6;
364 } else { 364 } else {
365 if( _atexit( &Remove_timer ) == 0 ) mgrInited = true; 365 if( _atexit( &Remove_timer ) == 0 ) mgrInited = true;
366 mgrClock = 0.0; 366 mgrClock = 0.0;
367 } 367 }
368 368
369 if ( mgrInited ) 369 if ( mgrInited )
370 { 370 {
371 mgrTimer.tmAddr = NULL; 371 mgrTimer.tmAddr = NULL;
372 mgrTimer.tmCount = 0; 372 mgrTimer.tmCount = 0;
373 mgrTimer.tmWakeUp = 0; 373 mgrTimer.tmWakeUp = 0;
374 mgrTimer.tmReserved = 0; 374 mgrTimer.tmReserved = 0;
375 InsTime( (QElemPtr)&mgrTimer ); 375 InsTime( (QElemPtr)&mgrTimer );
376 PrimeTime( (QElemPtr)&mgrTimer, -MAX_TIME ); 376 PrimeTime( (QElemPtr)&mgrTimer, -MAX_TIME );
377 } 377 }
378 return( mgrClock ); 378 return( mgrClock );
379} 379}
380#endif 380#endif
381 381
382/***********************************************************/ 382/***********************************************************/
383/* Parsytec GCel timer. */ 383/* Parsytec GCel timer. */
384/* Provided by: Georg Wambach, gw@informatik.uni-koeln.de */ 384/* Provided by: Georg Wambach, gw@informatik.uni-koeln.de */
385/***********************************************************/ 385/***********************************************************/
386#ifdef PARIX 386#ifdef PARIX
387#include <sys/time.h> 387#include <sys/time.h>
388 388
389double dtime() 389double dtime()
390{ 390{
391 double q; 391 double q;
392 392
393 q = (double) (TimeNowHigh()) / (double) CLK_TCK_HIGH; 393 q = (double) (TimeNowHigh()) / (double) CLK_TCK_HIGH;
394 394
395 return q; 395 return q;
396} 396}
397#endif 397#endif
398 398
399/************************************************/ 399/************************************************/
400/* Sun Solaris POSIX dtime() routine */ 400/* Sun Solaris POSIX dtime() routine */
401/* Provided by: Case Larsen, CTLarsen.lbl.gov */ 401/* Provided by: Case Larsen, CTLarsen.lbl.gov */
402/************************************************/ 402/************************************************/
403#ifdef POSIX 403#ifdef POSIX
404#include <sys/time.h> 404#include <sys/time.h>
405#include <sys/resource.h> 405#include <sys/resource.h>
406#include <sys/rusage.h> 406#include <sys/rusage.h>
407 407
408#ifdef __hpux 408#ifdef __hpux
409#include <sys/syscall.h> 409#include <sys/syscall.h>
410#endif 410#endif
411 411
412struct rusage rusage; 412struct rusage rusage;
413 413
414double dtime() 414double dtime()
415{ 415{
416 double q; 416 double q;
417 417
418 getrusage(RUSAGE_SELF,&rusage); 418 getrusage(RUSAGE_SELF,&rusage);
419 419
420 q = (double)(rusage.ru_utime.tv_sec); 420 q = (double)(rusage.ru_utime.tv_sec);
421 q = q + (double)(rusage.ru_utime.tv_nsec) * 1.0e-09; 421 q = q + (double)(rusage.ru_utime.tv_nsec) * 1.0e-09;
422 422
423 return q; 423 return q;
424} 424}
425#endif 425#endif
426 426
427 427
428/****************************************************/ 428/****************************************************/
429/* Windows NT (32 bit) dtime() routine */ 429/* Windows NT (32 bit) dtime() routine */
430/* Provided by: Piers Haken, piersh@microsoft.com */ 430/* Provided by: Piers Haken, piersh@microsoft.com */
431/****************************************************/ 431/****************************************************/
432#ifdef WIN32 432#ifdef WIN32
433#include <windows.h> 433#include <windows.h>
434 434
435double dtime(void) 435double dtime(void)
436{ 436{
437 double q; 437 double q;
438 438
439 q = (double)GetTickCount() * 1.0e-03; 439 q = (double)GetTickCount() * 1.0e-03;
440 440
441 return q; 441 return q;
442} 442}
443#endif 443#endif
444 444
445/*****************************************************/ 445/*****************************************************/
446/* Time according to POSIX.1 - <J.Pelan@qub.ac.uk> */ 446/* Time according to POSIX.1 - <J.Pelan@qub.ac.uk> */
447/* Ref: "POSIX Programmer's Guide" O'Reilly & Assoc.*/ 447/* Ref: "POSIX Programmer's Guide" O'Reilly & Assoc.*/
448/*****************************************************/ 448/*****************************************************/
449#ifdef POSIX1 449#ifdef POSIX1
450#define _POSIX_SOURCE 1 450#define _POSIX_SOURCE 1
451#include <unistd.h> 451#include <unistd.h>
452#include <limits.h> 452#include <limits.h>
453#include <sys/times.h> 453#include <sys/times.h>
454 454
455struct tms tms; 455struct tms tms;
456 456
457double dtime() 457double dtime()
458{ 458{
459 double q; 459 double q;
460 times(&tms); 460 times(&tms);
461 q = (double)tms.tms_utime / (double)CLK_TCK; 461 q = (double)tms.tms_utime / (double)CLK_TCK;
462 return q; 462 return q;
463} 463}
464#endif 464#endif
465/* 465/*
466 ************************************************************************* 466 *************************************************************************
467 * 467 *
468 * "DHRYSTONE" Benchmark Program 468 * "DHRYSTONE" Benchmark Program
469 * ----------------------------- 469 * -----------------------------
470 * 470 *
471 * Version: C, Version 2.1 471 * Version: C, Version 2.1
472 * 472 *
473 * File: dhry_1.c (part 2 of 3) 473 * File: dhry_1.c (part 2 of 3)
474 * 474 *
475 * Date: May 25, 1988 475 * Date: May 25, 1988
476 * 476 *
477 * Author: Reinhold P. Weicker 477 * Author: Reinhold P. Weicker
478 * 478 *
479 ************************************************************************* 479 *************************************************************************
480 */ 480 */
481 481
482#include <stdio.h> 482#include <stdio.h>
483#include <stdlib.h> 483#include <stdlib.h>
484#include <string.h> 484#include <string.h>
485#include "dhry.h" 485#include "dhry.h"
486 486
487/* Global Variables: */ 487/* Global Variables: */
488 488
489Rec_Pointer Ptr_Glob, 489Rec_Pointer Ptr_Glob,
490 Next_Ptr_Glob; 490 Next_Ptr_Glob;
491int Int_Glob; 491int Int_Glob;
492Boolean Bool_Glob; 492Boolean Bool_Glob;
493char Ch_1_Glob, 493char Ch_1_Glob,
494 Ch_2_Glob; 494 Ch_2_Glob;
495int Arr_1_Glob [50]; 495int Arr_1_Glob [50];
496int Arr_2_Glob [50] [50]; 496int Arr_2_Glob [50] [50];
497 497
498char Reg_Define[32] = "Register option selected."; 498char Reg_Define[32] = "Register option selected.";
499 499
500//extern char *malloc (); 500//extern char *malloc ();
501Enumeration Func_1 (); 501Enumeration Func_1 ();
502 /* 502 /*
503 forward declaration necessary since Enumeration may not simply be int 503 forward declaration necessary since Enumeration may not simply be int
504 */ 504 */
505 505
506#ifndef ROPT 506#ifndef ROPT
507#define REG 507#define REG
508 /* REG becomes defined as empty */ 508 /* REG becomes defined as empty */
509 /* i.e. no register variables */ 509 /* i.e. no register variables */
510#else 510#else
511#define REG register 511#define REG register
512#endif 512#endif
513 513
514 514
515/* variables for time measurement: */ 515/* variables for time measurement: */
516 516
517#define Too_Small_Time 2 517#define Too_Small_Time 2
518 /* Measurements should last at least 2 seconds */ 518 /* Measurements should last at least 2 seconds */
519 519
520double Begin_Time, 520double Begin_Time,
521 End_Time, 521 End_Time,
522 User_Time; 522 User_Time;
523 523
524double Microseconds, 524double Microseconds,
525 Dhrystones_Per_Second, 525 Dhrystones_Per_Second,
526 Vax_Mips; 526 Vax_Mips;
527 527
528/* end of variables for time measurement */ 528/* end of variables for time measurement */
529 529
530/**********************************************************************************************/ 530/**********************************************************************************************/
531 531
532 532
533Proc_1 (Ptr_Val_Par) 533Proc_1 (Ptr_Val_Par)
534/******************/ 534/******************/
535 535
536REG Rec_Pointer Ptr_Val_Par; 536REG Rec_Pointer Ptr_Val_Par;
537 /* executed once */ 537 /* executed once */
538{ 538{
539 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; 539 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
540 /* == Ptr_Glob_Next */ 540 /* == Ptr_Glob_Next */
541 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */ 541 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
542 /* corresponds to "rename" in Ada, "with" in Pascal */ 542 /* corresponds to "rename" in Ada, "with" in Pascal */
543 543
544 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); 544 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
545 Ptr_Val_Par->variant.var_1.Int_Comp = 5; 545 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
546 Next_Record->variant.var_1.Int_Comp 546 Next_Record->variant.var_1.Int_Comp
547 = Ptr_Val_Par->variant.var_1.Int_Comp; 547 = Ptr_Val_Par->variant.var_1.Int_Comp;
548 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp; 548 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
549 Proc_3 (&Next_Record->Ptr_Comp); 549 Proc_3 (&Next_Record->Ptr_Comp);
550 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp 550 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
551 == Ptr_Glob->Ptr_Comp */ 551 == Ptr_Glob->Ptr_Comp */
552 if (Next_Record->Discr == Ident_1) 552 if (Next_Record->Discr == Ident_1)
553 /* then, executed */ 553 /* then, executed */
554 { 554 {
555 Next_Record->variant.var_1.Int_Comp = 6; 555 Next_Record->variant.var_1.Int_Comp = 6;
556 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, 556 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
557 &Next_Record->variant.var_1.Enum_Comp); 557 &Next_Record->variant.var_1.Enum_Comp);
558 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp; 558 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
559 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, 559 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
560 &Next_Record->variant.var_1.Int_Comp); 560 &Next_Record->variant.var_1.Int_Comp);
561 } 561 }
562 else /* not executed */ 562 else /* not executed */
563 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp); 563 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
564} /* Proc_1 */ 564} /* Proc_1 */
565 565
566 566
567Proc_2 (Int_Par_Ref) 567Proc_2 (Int_Par_Ref)
568/******************/ 568/******************/
569 /* executed once */ 569 /* executed once */
570 /* *Int_Par_Ref == 1, becomes 4 */ 570 /* *Int_Par_Ref == 1, becomes 4 */
571 571
572One_Fifty *Int_Par_Ref; 572One_Fifty *Int_Par_Ref;
573{ 573{
574 One_Fifty Int_Loc; 574 One_Fifty Int_Loc;
575 Enumeration Enum_Loc; 575 Enumeration Enum_Loc = Ident_2;
576 576
577 Int_Loc = *Int_Par_Ref + 10; 577 Int_Loc = *Int_Par_Ref + 10;
578 do /* executed once */ 578 do /* executed once */
579 if (Ch_1_Glob == 'A') 579 if (Ch_1_Glob == 'A')
580 /* then, executed */ 580 /* then, executed */
581 { 581 {
582 Int_Loc -= 1; 582 Int_Loc -= 1;
583 *Int_Par_Ref = Int_Loc - Int_Glob; 583 *Int_Par_Ref = Int_Loc - Int_Glob;
584 Enum_Loc = Ident_1; 584 Enum_Loc = Ident_1;
585 } /* if */ 585 } /* if */
586 while (Enum_Loc != Ident_1); /* true */ 586 while (Enum_Loc != Ident_1); /* true */
587} /* Proc_2 */ 587} /* Proc_2 */
588 588
589 589
590Proc_3 (Ptr_Ref_Par) 590Proc_3 (Ptr_Ref_Par)
591/******************/ 591/******************/
592 /* executed once */ 592 /* executed once */
593 /* Ptr_Ref_Par becomes Ptr_Glob */ 593 /* Ptr_Ref_Par becomes Ptr_Glob */
594 594
595Rec_Pointer *Ptr_Ref_Par; 595Rec_Pointer *Ptr_Ref_Par;
596 596
597{ 597{
598 if (Ptr_Glob != Null) 598 if (Ptr_Glob != Null)
599 /* then, executed */ 599 /* then, executed */
600 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp; 600 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
601 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp); 601 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
602} /* Proc_3 */ 602} /* Proc_3 */
603 603
604 604
605Proc_4 () /* without parameters */ 605Proc_4 () /* without parameters */
606/*******/ 606/*******/
607 /* executed once */ 607 /* executed once */
608{ 608{
609 Boolean Bool_Loc; 609 Boolean Bool_Loc;
610 610
611 Bool_Loc = Ch_1_Glob == 'A'; 611 Bool_Loc = Ch_1_Glob == 'A';
612 Bool_Glob = Bool_Loc | Bool_Glob; 612 Bool_Glob = Bool_Loc | Bool_Glob;
613 Ch_2_Glob = 'B'; 613 Ch_2_Glob = 'B';
614} /* Proc_4 */ 614} /* Proc_4 */
615 615
616 616
617Proc_5 () /* without parameters */ 617Proc_5 () /* without parameters */
618/*******/ 618/*******/
619 /* executed once */ 619 /* executed once */
620{ 620{
621 Ch_1_Glob = 'A'; 621 Ch_1_Glob = 'A';
622 Bool_Glob = false; 622 Bool_Glob = false;
623} /* Proc_5 */ 623} /* Proc_5 */
624 624
625 625
626 /* Procedure for the assignment of structures, */ 626 /* Procedure for the assignment of structures, */
627 /* if the C compiler doesn't support this feature */ 627 /* if the C compiler doesn't support this feature */
628#ifdef NOSTRUCTASSIGN 628#ifdef NOSTRUCTASSIGN
629memcpy (d, s, l) 629memcpy (d, s, l)
630register char *d; 630register char *d;
631register char *s; 631register char *s;
632register int l; 632register int l;
633{ 633{
634 while (l--) *d++ = *s++; 634 while (l--) *d++ = *s++;
635} 635}
636#endif 636#endif
637 637
638 638
639Proc_6 (Enum_Val_Par, Enum_Ref_Par) 639Proc_6 (Enum_Val_Par, Enum_Ref_Par)
640/*********************************/ 640/*********************************/
641 /* executed once */ 641 /* executed once */
642 /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */ 642 /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
643 643
644Enumeration Enum_Val_Par; 644Enumeration Enum_Val_Par;
645Enumeration *Enum_Ref_Par; 645Enumeration *Enum_Ref_Par;
646{ 646{
647 *Enum_Ref_Par = Enum_Val_Par; 647 *Enum_Ref_Par = Enum_Val_Par;
648 if (! Func_3 (Enum_Val_Par)) 648 if (! Func_3 (Enum_Val_Par))
649 /* then, not executed */ 649 /* then, not executed */
650 *Enum_Ref_Par = Ident_4; 650 *Enum_Ref_Par = Ident_4;
651 switch (Enum_Val_Par) 651 switch (Enum_Val_Par)
652 { 652 {
653 case Ident_1: 653 case Ident_1:
654 *Enum_Ref_Par = Ident_1; 654 *Enum_Ref_Par = Ident_1;
655 break; 655 break;
656 case Ident_2: 656 case Ident_2:
657 if (Int_Glob > 100) 657 if (Int_Glob > 100)
658 /* then */ 658 /* then */
659 *Enum_Ref_Par = Ident_1; 659 *Enum_Ref_Par = Ident_1;
660 else *Enum_Ref_Par = Ident_4; 660 else *Enum_Ref_Par = Ident_4;
661 break; 661 break;
662 case Ident_3: /* executed */ 662 case Ident_3: /* executed */
663 *Enum_Ref_Par = Ident_2; 663 *Enum_Ref_Par = Ident_2;
664 break; 664 break;
665 case Ident_4: break; 665 case Ident_4: break;
666 case Ident_5: 666 case Ident_5:
667 *Enum_Ref_Par = Ident_3; 667 *Enum_Ref_Par = Ident_3;
668 break; 668 break;
669 } /* switch */ 669 } /* switch */
670} /* Proc_6 */ 670} /* Proc_6 */
671 671
672 672
673Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref) 673Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref)
674/**********************************************/ 674/**********************************************/
675 /* executed three times */ 675 /* executed three times */
676 /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */ 676 /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
677 /* Int_Par_Ref becomes 7 */ 677 /* Int_Par_Ref becomes 7 */
678 /* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */ 678 /* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
679 /* Int_Par_Ref becomes 17 */ 679 /* Int_Par_Ref becomes 17 */
680 /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */ 680 /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
681 /* Int_Par_Ref becomes 18 */ 681 /* Int_Par_Ref becomes 18 */
682One_Fifty Int_1_Par_Val; 682One_Fifty Int_1_Par_Val;
683One_Fifty Int_2_Par_Val; 683One_Fifty Int_2_Par_Val;
684One_Fifty *Int_Par_Ref; 684One_Fifty *Int_Par_Ref;
685{ 685{
686 One_Fifty Int_Loc; 686 One_Fifty Int_Loc;
687 687
688 Int_Loc = Int_1_Par_Val + 2; 688 Int_Loc = Int_1_Par_Val + 2;
689 *Int_Par_Ref = Int_2_Par_Val + Int_Loc; 689 *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
690} /* Proc_7 */ 690} /* Proc_7 */
691 691
692 692
693Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val) 693Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val)
694/*********************************************************************/ 694/*********************************************************************/
695 /* executed once */ 695 /* executed once */
696 /* Int_Par_Val_1 == 3 */ 696 /* Int_Par_Val_1 == 3 */
697 /* Int_Par_Val_2 == 7 */ 697 /* Int_Par_Val_2 == 7 */
698Arr_1_Dim Arr_1_Par_Ref; 698Arr_1_Dim Arr_1_Par_Ref;
699Arr_2_Dim Arr_2_Par_Ref; 699Arr_2_Dim Arr_2_Par_Ref;
700int Int_1_Par_Val; 700int Int_1_Par_Val;
701int Int_2_Par_Val; 701int Int_2_Par_Val;
702{ 702{
703 REG One_Fifty Int_Index; 703 REG One_Fifty Int_Index;
704 REG One_Fifty Int_Loc; 704 REG One_Fifty Int_Loc;
705 705
706 Int_Loc = Int_1_Par_Val + 5; 706 Int_Loc = Int_1_Par_Val + 5;
707 Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val; 707 Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
708 Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc]; 708 Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
709 Arr_1_Par_Ref [Int_Loc+30] = Int_Loc; 709 Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
710 for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index) 710 for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
711 Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc; 711 Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
712 Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1; 712 Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
713 Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc]; 713 Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
714 Int_Glob = 5; 714 Int_Glob = 5;
715} /* Proc_8 */ 715} /* Proc_8 */
716 716
717 717
718Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val) 718Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val)
719/*************************************************/ 719/*************************************************/
720 /* executed three times */ 720 /* executed three times */
721 /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */ 721 /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */
722 /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */ 722 /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */
723 /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */ 723 /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */
724 724
725Capital_Letter Ch_1_Par_Val; 725Capital_Letter Ch_1_Par_Val;
726Capital_Letter Ch_2_Par_Val; 726Capital_Letter Ch_2_Par_Val;
727{ 727{
728 Capital_Letter Ch_1_Loc; 728 Capital_Letter Ch_1_Loc;
729 Capital_Letter Ch_2_Loc; 729 Capital_Letter Ch_2_Loc;
730 730
731 Ch_1_Loc = Ch_1_Par_Val; 731 Ch_1_Loc = Ch_1_Par_Val;
732 Ch_2_Loc = Ch_1_Loc; 732 Ch_2_Loc = Ch_1_Loc;
733 if (Ch_2_Loc != Ch_2_Par_Val) 733 if (Ch_2_Loc != Ch_2_Par_Val)
734 /* then, executed */ 734 /* then, executed */
735 return (Ident_1); 735 return (Ident_1);
736 else /* not executed */ 736 else /* not executed */
737 { 737 {
738 Ch_1_Glob = Ch_1_Loc; 738 Ch_1_Glob = Ch_1_Loc;
739 return (Ident_2); 739 return (Ident_2);
740 } 740 }
741} /* Func_1 */ 741} /* Func_1 */
742 742
743 743
744Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref) 744Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref)
745/*************************************************/ 745/*************************************************/
746 /* executed once */ 746 /* executed once */
747 /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */ 747 /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
748 /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */ 748 /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
749 749
750Str_30 Str_1_Par_Ref; 750Str_30 Str_1_Par_Ref;
751Str_30 Str_2_Par_Ref; 751Str_30 Str_2_Par_Ref;
752{ 752{
753 REG One_Thirty Int_Loc; 753 REG One_Thirty Int_Loc;
754 Capital_Letter Ch_Loc; 754 Capital_Letter Ch_Loc;
755 755
756 Int_Loc = 2; 756 Int_Loc = 2;
757 while (Int_Loc <= 2) /* loop body executed once */ 757 while (Int_Loc <= 2) /* loop body executed once */
758 if (Func_1 (Str_1_Par_Ref[Int_Loc], 758 if (Func_1 (Str_1_Par_Ref[Int_Loc],
759 Str_2_Par_Ref[Int_Loc+1]) == Ident_1) 759 Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
760 /* then, executed */ 760 /* then, executed */
761 { 761 {
762 Ch_Loc = 'A'; 762 Ch_Loc = 'A';
763 Int_Loc += 1; 763 Int_Loc += 1;
764 } /* if, while */ 764 } /* if, while */
765 if (Ch_Loc >= 'W' && Ch_Loc < 'Z') 765 if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
766 /* then, not executed */ 766 /* then, not executed */
767 Int_Loc = 7; 767 Int_Loc = 7;
768 if (Ch_Loc == 'R') 768 if (Ch_Loc == 'R')
769 /* then, not executed */ 769 /* then, not executed */
770 return (true); 770 return (true);
771 else /* executed */ 771 else /* executed */
772 { 772 {
773 if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0) 773 if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
774 /* then, not executed */ 774 /* then, not executed */
775 { 775 {
776 Int_Loc += 7; 776 Int_Loc += 7;
777 Int_Glob = Int_Loc; 777 Int_Glob = Int_Loc;
778 return (true); 778 return (true);
779 } 779 }
780 else /* executed */ 780 else /* executed */
781 return (false); 781 return (false);
782 } /* if Ch_Loc */ 782 } /* if Ch_Loc */
783} /* Func_2 */ 783} /* Func_2 */
784 784
785 785
786Boolean Func_3 (Enum_Par_Val) 786Boolean Func_3 (Enum_Par_Val)
787/***************************/ 787/***************************/
788 /* executed once */ 788 /* executed once */
789 /* Enum_Par_Val == Ident_3 */ 789 /* Enum_Par_Val == Ident_3 */
790Enumeration Enum_Par_Val; 790Enumeration Enum_Par_Val;
791{ 791{
792 Enumeration Enum_Loc; 792 Enumeration Enum_Loc;
793 793
794 Enum_Loc = Enum_Par_Val; 794 Enum_Loc = Enum_Par_Val;
795 if (Enum_Loc == Ident_3) 795 if (Enum_Loc == Ident_3)
796 /* then, executed */ 796 /* then, executed */
797 return (true); 797 return (true);
798 else /* not executed */ 798 else /* not executed */
799 return (false); 799 return (false);
800} /* Func_3 */ 800} /* Func_3 */
801 801
802/*********************************************************************************/ 802/*********************************************************************************/
803 803
804double dhry_main( int n ) 804double dhry_main( int n )
805/*****/ 805/*****/
806 806
807 /* main program, corresponds to procedures */ 807 /* main program, corresponds to procedures */
808 /* Main and Proc_0 in the Ada version */ 808 /* Main and Proc_0 in the Ada version */
809{ 809{
810 One_Fifty Int_1_Loc; 810 One_Fifty Int_1_Loc;
811 REG One_Fifty Int_2_Loc; 811 REG One_Fifty Int_2_Loc;
812 One_Fifty Int_3_Loc; 812 One_Fifty Int_3_Loc;
813 REG char Ch_Index; 813 REG char Ch_Index;
814 Enumeration Enum_Loc; 814 Enumeration Enum_Loc;
815 Str_30 Str_1_Loc; 815 Str_30 Str_1_Loc;
816 Str_30 Str_2_Loc; 816 Str_30 Str_2_Loc;
817 REG int Run_Index; 817 REG int Run_Index;
818 REG int Number_Of_Runs; 818 REG int Number_Of_Runs;
819 819
820 FILE *Ap; 820 FILE *Ap;
821 821
822 /* Initializations */ 822 /* Initializations */
823 823
824/* if ((Ap = fopen("dhry.res","a+")) == NULL) 824/* if ((Ap = fopen("dhry.res","a+")) == NULL)
825 { 825 {
826 printf("Can not open dhry.res\n\n"); 826 printf("Can not open dhry.res\n\n");
827 exit(1); 827 exit(1);
828 } 828 }
829*/ 829*/
830 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type)); 830 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
831 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type)); 831 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
832 832
833 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob; 833 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
834 Ptr_Glob->Discr = Ident_1; 834 Ptr_Glob->Discr = Ident_1;
835 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3; 835 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
836 Ptr_Glob->variant.var_1.Int_Comp = 40; 836 Ptr_Glob->variant.var_1.Int_Comp = 40;
837 strcpy (Ptr_Glob->variant.var_1.Str_Comp, 837 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
838 "DHRYSTONE PROGRAM, SOME STRING"); 838 "DHRYSTONE PROGRAM, SOME STRING");
839 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); 839 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
840 840
841 Arr_2_Glob [8][7] = 10; 841 Arr_2_Glob [8][7] = 10;
842 /* Was missing in published program. Without this statement, */ 842 /* Was missing in published program. Without this statement, */
843 /* Arr_2_Glob [8][7] would have an undefined value. */ 843 /* Arr_2_Glob [8][7] would have an undefined value. */
844 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ 844 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
845 /* overflow may occur for this array element. */ 845 /* overflow may occur for this array element. */
846 846
847/* 847/*
848 if (Reg) 848 if (Reg)
849 { 849 {
850 printf ("Program compiled with 'register' attribute\n"); 850 printf ("Program compiled with 'register' attribute\n");
851 printf ("\n"); 851 printf ("\n");
852 } 852 }
853 else 853 else
854 { 854 {
855 printf ("Program compiled without 'register' attribute\n"); 855 printf ("Program compiled without 'register' attribute\n");
856 printf ("\n"); 856 printf ("\n");
857 } 857 }
858*/ 858*/
859 Number_Of_Runs = n; 859 Number_Of_Runs = n;
860 860
861 /***************/ 861 /***************/
862 /* Start timer */ 862 /* Start timer */
863 /***************/ 863 /***************/
864 864
865 Begin_Time = dtime(); 865 Begin_Time = dtime();
866 866
867 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) 867 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
868 { 868 {
869 869
870 Proc_5(); 870 Proc_5();
871 Proc_4(); 871 Proc_4();
872 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */ 872 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
873 Int_1_Loc = 2; 873 Int_1_Loc = 2;
874 Int_2_Loc = 3; 874 Int_2_Loc = 3;
875 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING"); 875 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
876 Enum_Loc = Ident_2; 876 Enum_Loc = Ident_2;
877 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc); 877 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
878 /* Bool_Glob == 1 */ 878 /* Bool_Glob == 1 */
879 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */ 879 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
880 { 880 {
881 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc; 881 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
882 /* Int_3_Loc == 7 */ 882 /* Int_3_Loc == 7 */
883 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc); 883 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
884 /* Int_3_Loc == 7 */ 884 /* Int_3_Loc == 7 */
885 Int_1_Loc += 1; 885 Int_1_Loc += 1;
886 } /* while */ 886 } /* while */
887 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ 887 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
888 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc); 888 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
889 /* Int_Glob == 5 */ 889 /* Int_Glob == 5 */
890 Proc_1 (Ptr_Glob); 890 Proc_1 (Ptr_Glob);
891 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) 891 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
892 /* loop body executed twice */ 892 /* loop body executed twice */
893 { 893 {
894 if (Enum_Loc == Func_1 (Ch_Index, 'C')) 894 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
895 /* then, not executed */ 895 /* then, not executed */
896 { 896 {
897 Proc_6 (Ident_1, &Enum_Loc); 897 Proc_6 (Ident_1, &Enum_Loc);
898 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING"); 898 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
899 Int_2_Loc = Run_Index; 899 Int_2_Loc = Run_Index;
900 Int_Glob = Run_Index; 900 Int_Glob = Run_Index;
901 } 901 }
902 } 902 }
903 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ 903 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
904 Int_2_Loc = Int_2_Loc * Int_1_Loc; 904 Int_2_Loc = Int_2_Loc * Int_1_Loc;
905 Int_1_Loc = Int_2_Loc / Int_3_Loc; 905 Int_1_Loc = Int_2_Loc / Int_3_Loc;
906 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc; 906 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
907 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */ 907 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
908 Proc_2 (&Int_1_Loc); 908 Proc_2 (&Int_1_Loc);
909 /* Int_1_Loc == 5 */ 909 /* Int_1_Loc == 5 */
910 910
911 } /* loop "for Run_Index" */ 911 } /* loop "for Run_Index" */
912 912
913 /**************/ 913 /**************/
914 /* Stop timer */ 914 /* Stop timer */
915 /**************/ 915 /**************/
916 916
917 End_Time = dtime(); 917 End_Time = dtime();
918 918
919/* 919/*
920 printf ("Execution ends\n"); 920 printf ("Execution ends\n");
921 printf ("\n"); 921 printf ("\n");
922 printf ("Final values of the variables used in the benchmark:\n"); 922 printf ("Final values of the variables used in the benchmark:\n");
923 printf ("\n"); 923 printf ("\n");
924 printf ("Int_Glob: %d\n", Int_Glob); 924 printf ("Int_Glob: %d\n", Int_Glob);
925 printf (" should be: %d\n", 5); 925 printf (" should be: %d\n", 5);
926 printf ("Bool_Glob: %d\n", Bool_Glob); 926 printf ("Bool_Glob: %d\n", Bool_Glob);
927 printf (" should be: %d\n", 1); 927 printf (" should be: %d\n", 1);
928 printf ("Ch_1_Glob: %c\n", Ch_1_Glob); 928 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
929 printf (" should be: %c\n", 'A'); 929 printf (" should be: %c\n", 'A');
930 printf ("Ch_2_Glob: %c\n", Ch_2_Glob); 930 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
931 printf (" should be: %c\n", 'B'); 931 printf (" should be: %c\n", 'B');
932 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]); 932 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
933 printf (" should be: %d\n", 7); 933 printf (" should be: %d\n", 7);
934 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]); 934 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
935 printf (" should be: Number_Of_Runs + 10\n"); 935 printf (" should be: Number_Of_Runs + 10\n");
936 printf ("Ptr_Glob->\n"); 936 printf ("Ptr_Glob->\n");
937 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp); 937 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
938 printf (" should be: (implementation-dependent)\n"); 938 printf (" should be: (implementation-dependent)\n");
939 printf (" Discr: %d\n", Ptr_Glob->Discr); 939 printf (" Discr: %d\n", Ptr_Glob->Discr);
940 printf (" should be: %d\n", 0); 940 printf (" should be: %d\n", 0);
941 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp); 941 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
942 printf (" should be: %d\n", 2); 942 printf (" should be: %d\n", 2);
943 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp); 943 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
944 printf (" should be: %d\n", 17); 944 printf (" should be: %d\n", 17);
945 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp); 945 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
946 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n"); 946 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
947 printf ("Next_Ptr_Glob->\n"); 947 printf ("Next_Ptr_Glob->\n");
948 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp); 948 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
949 printf (" should be: (implementation-dependent), same as above\n"); 949 printf (" should be: (implementation-dependent), same as above\n");
950 printf (" Discr: %d\n", Next_Ptr_Glob->Discr); 950 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
951 printf (" should be: %d\n", 0); 951 printf (" should be: %d\n", 0);
952 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp); 952 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
953 printf (" should be: %d\n", 1); 953 printf (" should be: %d\n", 1);
954 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp); 954 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
955 printf (" should be: %d\n", 18); 955 printf (" should be: %d\n", 18);
956 printf (" Str_Comp: %s\n", Next_Ptr_Glob->variant.var_1.Str_Comp); 956 printf (" Str_Comp: %s\n", Next_Ptr_Glob->variant.var_1.Str_Comp);
957 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n"); 957 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
958 printf ("Int_1_Loc: %d\n", Int_1_Loc); 958 printf ("Int_1_Loc: %d\n", Int_1_Loc);
959 printf (" should be: %d\n", 5); 959 printf (" should be: %d\n", 5);
960 printf ("Int_2_Loc: %d\n", Int_2_Loc); 960 printf ("Int_2_Loc: %d\n", Int_2_Loc);
961 printf (" should be: %d\n", 13); 961 printf (" should be: %d\n", 13);
962 printf ("Int_3_Loc: %d\n", Int_3_Loc); 962 printf ("Int_3_Loc: %d\n", Int_3_Loc);
963 printf (" should be: %d\n", 7); 963 printf (" should be: %d\n", 7);
964 printf ("Enum_Loc: %d\n", Enum_Loc); 964 printf ("Enum_Loc: %d\n", Enum_Loc);
965 printf (" should be: %d\n", 1); 965 printf (" should be: %d\n", 1);
966 printf ("Str_1_Loc: %s\n", Str_1_Loc); 966 printf ("Str_1_Loc: %s\n", Str_1_Loc);
967 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n"); 967 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
968 printf ("Str_2_Loc: %s\n", Str_2_Loc); 968 printf ("Str_2_Loc: %s\n", Str_2_Loc);
969 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n"); 969 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
970 printf ("\n"); 970 printf ("\n");
971*/ 971*/
972 User_Time = End_Time - Begin_Time; 972 User_Time = End_Time - Begin_Time;
973 973
974 if (User_Time < Too_Small_Time) return -1; 974 if (User_Time < Too_Small_Time) return -1;
975 else 975 else
976 { 976 {
977 Microseconds = User_Time * Mic_secs_Per_Second 977 Microseconds = User_Time * Mic_secs_Per_Second
978 / (double) Number_Of_Runs; 978 / (double) Number_Of_Runs;
979 Dhrystones_Per_Second = (double) Number_Of_Runs / User_Time; 979 Dhrystones_Per_Second = (double) Number_Of_Runs / User_Time;
980 Vax_Mips = Dhrystones_Per_Second / 1757.0; 980 Vax_Mips = Dhrystones_Per_Second / 1757.0;
981 981
982#ifdef ROPT 982#ifdef ROPT
983 //printf ("Register option selected? YES\n"); 983 //printf ("Register option selected? YES\n");
984#else 984#else
985 //printf ("Register option selected? NO\n"); 985 //printf ("Register option selected? NO\n");
986 strncpy(Reg_Define, "Register option not selected.", 30); 986 strncpy(Reg_Define, "Register option not selected.", 30);
987#endif 987#endif
988 printf ("Microseconds for one run through Dhrystone: "); 988 printf ("Microseconds for one run through Dhrystone: ");
989 printf ("%7.1lf \n", Microseconds); 989 printf ("%7.1lf \n", Microseconds);
990 printf ("Dhrystones per Second: "); 990 printf ("Dhrystones per Second: ");
991 printf ("%10.1lf \n", Dhrystones_Per_Second); 991 printf ("%10.1lf \n", Dhrystones_Per_Second);
992 printf ("VAX MIPS rating = %10.3lf \n",Vax_Mips); 992 printf ("VAX MIPS rating = %10.3lf \n",Vax_Mips);
993 printf ("\n"); 993 printf ("\n");
994 994
995 return Dhrystones_Per_Second; 995 return Dhrystones_Per_Second;
996 996
997/* 997/*
998 998
999 fprintf(Ap,"\n"); 999 fprintf(Ap,"\n");
1000 fprintf(Ap,"Dhrystone Benchmark, Version 2.1 (Language: C)\n"); 1000 fprintf(Ap,"Dhrystone Benchmark, Version 2.1 (Language: C)\n");
1001 fprintf(Ap,"%s\n",Reg_Define); 1001 fprintf(Ap,"%s\n",Reg_Define);
1002 fprintf(Ap,"Microseconds for one loop: %7.1lf\n",Microseconds); 1002 fprintf(Ap,"Microseconds for one loop: %7.1lf\n",Microseconds);
1003 fprintf(Ap,"Dhrystones per second: %10.1lf\n",Dhrystones_Per_Second); 1003 fprintf(Ap,"Dhrystones per second: %10.1lf\n",Dhrystones_Per_Second);
1004 fprintf(Ap,"VAX MIPS rating: %10.3lf\n",Vax_Mips); 1004 fprintf(Ap,"VAX MIPS rating: %10.3lf\n",Vax_Mips);
1005 fclose(Ap); 1005 fclose(Ap);
1006*/ 1006*/
1007 1007
1008 } 1008 }
1009 1009
1010} 1010}