author | erik <erik> | 2007-01-29 21:53:48 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-29 21:53:48 (UTC) |
commit | 02ef45be75a3024df11365956e1cce6392d9103c (patch) (side-by-side diff) | |
tree | 42fd5c909d67a473f57a607e01d32e01b3dd2511 | |
parent | b2c306a99b8dc82c981390f02db859149fac8cf0 (diff) | |
download | opie-02ef45be75a3024df11365956e1cce6392d9103c.zip opie-02ef45be75a3024df11365956e1cce6392d9103c.tar.gz opie-02ef45be75a3024df11365956e1cce6392d9103c.tar.bz2 |
Each file in this commit has an issue where the initial value of a variable
is assumed to be something but no initial value is given.
This commit changes that by either assigning an initial value or removing
the assumption on an initial value (usually the former).
-rw-r--r-- | libopie2/opiecore/device/odevice_htc.cpp | 3 | ||||
-rw-r--r-- | libopie2/opiepim/private/opimeventsortvector.cpp | 9 | ||||
-rw-r--r-- | noncore/apps/confedit/listviewitemconffile.cpp | 19 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_irda.cpp | 1 | ||||
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 8 | ||||
-rw-r--r-- | noncore/apps/opie-reader/CFilter.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-reader/CRegExp.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-reader/Palm2QImage.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-reader/QTReader.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-reader/plucker_base.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-reader/striphtml.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katehighlight.cpp | 6 | ||||
-rw-r--r-- | noncore/net/ftplib/ftplib.c | 2 | ||||
-rw-r--r-- | noncore/settings/sysinfo/contrib/dhry.c | 2 |
14 files changed, 33 insertions, 33 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 @@ -167,438 +167,437 @@ void HTC::init(const QString& cpu_info) if ( model == "HTC Blueangel" ) { d->m_model = Model_HTC_Blueangel; d->m_modelstr = "HTC Blueangel"; } if ( model == "HTC Himalaya" ) { d->m_model = Model_HTC_Himalaya; d->m_modelstr = "HTC Himalaya"; } if ( model == "HTC Magician" ) { d->m_model = Model_HTC_Magician; d->m_modelstr = "HTC Magician"; } // set path to backlight device switch ( d->m_model ) { case Model_HTC_Universal: case Model_HTC_Magician: case Model_HTC_Alpine: case Model_HTC_Beetles: case Model_HTC_Apache: m_backlightdev = "/sys/class/backlight/pxa2xx-fb/"; break; case Model_HTC_Blueangel: case Model_HTC_Himalaya: m_backlightdev = "/sys/class/backlight/w100fb/"; break; default: m_backlightdev = "/sys/class/backlight/pxafb/"; } // set initial rotation switch( d->m_model ) { case Model_HTC_Universal: initHingeSensor(); d->m_rotation = rotation(); d->m_direction = direction(); break; default: d->m_rotation = Rot270; } // set default qte driver switch( d->m_model ) { default: d->m_qteDriver = "Transformed"; } m_leds[0] = Led_Off; qDebug( "HTC::init() - Using the 2.6 Xanadux on a %s", (const char*) d->m_modelstr ); } void HTC::initButtons() { qDebug( "HTC::initButtons()" ); if ( d->m_buttons ) return; d->m_buttons = new QValueList <ODeviceButton>; struct htc_button * phtc_buttons; int buttoncount; switch ( d->m_model ) { case Model_HTC_Universal: if ( isQWS( ) ) { addPreHandler(this); } phtc_buttons = htc_buttons_universal; buttoncount = ARRAY_SIZE(htc_buttons_universal); break; default: phtc_buttons = htc_buttons; buttoncount = ARRAY_SIZE(htc_buttons); break; } for ( int i = 0; i < buttoncount; i++ ) { struct htc_button *zb = phtc_buttons + i; ODeviceButton b; b.setKeycode( zb->code ); b.setUserText( QObject::tr( "Button", zb->utext )); b.setPixmap( OResource::loadPixmap( zb->pix )); b.setFactoryPresetPressedAction( OQCopMessage( makeChannel ( zb->fpressedservice ), zb->fpressedaction )); b.setFactoryPresetHeldAction( OQCopMessage( makeChannel ( zb->fheldservice ), zb->fheldaction )); d->m_buttons->append( b ); } reloadButtonMapping(); } typedef struct sharp_led_status { int which; /* select which LED status is wanted. */ int status; /* set new led status if you call SHARP_LED_SETSTATUS */ } sharp_led_status; void HTC::buzzer( int sound ) { #ifndef QT_NO_SOUND Sound *snd = 0; // All devices except SL5500 have a DSP device if ( d->m_model == Model_HTC_Universal ) { switch ( sound ){ case SHARP_BUZ_TOUCHSOUND: { static Sound touch_sound("touchsound"); snd = &touch_sound; } break; case SHARP_BUZ_KEYSOUND: { static Sound key_sound( "keysound" ); snd = &key_sound; } break; case SHARP_BUZ_SCHEDULE_ALARM: default: { static Sound alarm_sound("alarm"); snd = &alarm_sound; } break; } } // If a soundname is defined, we expect that this device has // sound capabilities.. Otherwise we expect to have the buzzer // device.. if ( snd && snd->isFinished() ){ changeMixerForAlarm( 0, "/dev/sound/mixer", snd ); snd->play(); } else if( !snd ) { int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); if ( fd >= 0 ) { ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); ::close ( fd ); } } #endif } void HTC::playAlarmSound() { buzzer( SHARP_BUZ_SCHEDULE_ALARM ); } void HTC::playTouchSound() { buzzer( SHARP_BUZ_TOUCHSOUND ); } void HTC::playKeySound() { buzzer( SHARP_BUZ_KEYSOUND ); } QValueList <OLed> HTC::ledList() const { QValueList <OLed> vl; vl << Led_Mail; return vl; } QValueList <OLedState> HTC::ledStateList( OLed l ) const { QValueList <OLedState> vl; if ( l == Led_Mail ) vl << Led_Off << Led_On << Led_BlinkSlow; return vl; } OLedState HTC::ledState( OLed which ) const { if ( which == Led_Mail ) return m_leds [0]; else return Led_Off; } bool HTC::setLedState( OLed which, OLedState st ) { qDebug( "HTC::setLedState: ODevice handling not yet implemented" ); return false; } int HTC::displayBrightnessResolution() const { int res = 1; int fd = ::open( m_backlightdev + "max_brightness", O_RDONLY|O_NONBLOCK ); if ( fd ) { char buf[100]; if ( ::read( fd, &buf[0], sizeof buf ) ) ::sscanf( &buf[0], "%d", &res ); ::close( fd ); } return res; } bool HTC::setDisplayBrightness( int bright ) { //qDebug( "HTC::setDisplayBrightness( %d )", bright ); bool res = false; if ( bright > 255 ) bright = 255; if ( bright < 0 ) bright = 0; int numberOfSteps = displayBrightnessResolution(); int val = ( bright == 1 ) ? 1 : ( bright * numberOfSteps ) / 255; int fd = ::open( m_backlightdev + "brightness", O_WRONLY|O_NONBLOCK ); if ( fd ) { char buf[100]; int len = ::snprintf( &buf[0], sizeof buf, "%d", val ); res = ( ::write( fd, &buf[0], len ) == 0 ); ::close( fd ); } return res; } bool HTC::setDisplayStatus( bool on ) { bool res = false; int fd = ::open( m_backlightdev + "power", O_WRONLY|O_NONBLOCK ); if ( fd ) { char buf[10]; buf[0] = on ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; buf[1] = '\0'; res = ( ::write( fd, &buf[0], 2 ) == 0 ); ::close( fd ); } return res; } Transformation HTC::rotation() const { qDebug( "HTC::rotation()" ); - Transformation rot; + Transformation rot = Rot270; switch ( d->m_model ) { case Model_HTC_Universal: { OHingeStatus hs = readHingeSensor(); qDebug( "HTC::rotation() - hinge sensor = %d", (int) hs ); if ( hs == CASE_PORTRAIT ) rot = Rot0; else if ( hs == CASE_UNKNOWN ) rot = Rot270; - else rot = Rot270; } break; } qDebug( "HTC::rotation() - returning '%d'", rot ); return rot; } ODirection HTC::direction() const { ODirection dir; switch ( d->m_model ) { case Model_HTC_Universal: { OHingeStatus hs = readHingeSensor(); if ( hs == CASE_PORTRAIT ) dir = CCW; else if ( hs == CASE_UNKNOWN ) dir = CCW; else dir = CW; } break; default: dir = d->m_direction; break; } return dir; } bool HTC::hasHingeSensor() const { return d->m_model == Model_HTC_Universal; } OHingeStatus HTC::readHingeSensor() const { /* * The HTC Universal keyboard is event source 1 in kernel 2.6. * Hinge status is reported via Input System Switchs 0 and 1 like that: * * ------------------------- * | SW0 | SW1 | CASE | * |-----|-----|-----------| * | 0 0 Unknown | * | 1 0 Portrait | * | 0 1 Closed | * | 1 1 Landscape | * ------------------------- */ OInputDevice* keyboard = OInputSystem::instance()->device( "event1" ); bool switch0 = true; bool switch1 = false; if ( keyboard ) { switch0 = keyboard->isHeld( OInputDevice::Switch0 ); switch1 = keyboard->isHeld( OInputDevice::Switch1 ); } if ( switch0 ) { return switch1 ? CASE_LANDSCAPE : CASE_PORTRAIT; } else { return switch1 ? CASE_CLOSED : CASE_UNKNOWN; } } void HTC::initHingeSensor() { if ( m_embedix ) return; m_hinge.setName( "/dev/input/event1" ); if ( !m_hinge.open( IO_ReadOnly ) ) { qWarning( "HTC::init() - Couldn't open /dev/input/event1 for read (%s)", strerror( errno ) ); return; } QSocketNotifier* sn = new QSocketNotifier( m_hinge.handle(), QSocketNotifier::Read, this ); QObject::connect( sn, SIGNAL(activated(int)), this, SLOT(hingeSensorTriggered()) ); qDebug( "HTC::init() - Hinge Sensor Initialization successfully completed" ); } void HTC::hingeSensorTriggered() { qDebug( "HTC::hingeSensorTriggered() - got event" ); struct input_event e; if ( ::read( m_hinge.handle(), &e, sizeof e ) > 0 ) { qDebug( "HTC::hingeSensorTriggered() - event has type %d, code %d, value %d", e.type, e.code, e.value ); if ( e.type != EV_SW ) return; if ( readHingeSensor() != CASE_UNKNOWN ) { qDebug( "HTC::hingeSensorTriggered() - got valid switch event, calling rotateDefault()" ); QCopChannel::send( "QPE/Rotation", "rotateDefault()" ); } } } void HTC::systemMessage( const QCString &msg, const QByteArray & ) { if ( msg == "deviceButtonMappingChanged()" ) { reloadButtonMapping(); } } /* * Take code from iPAQ device. * That way we switch the cursor directions depending on status of hinge sensor, eg. hardware direction. * I hope that is ok - Alwin */ bool HTC::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) { int newkeycode = keycode; if ( !hasHingeSensor() ) return false; /* map cursor keys depending on the hinge status */ switch ( keycode ) { // Rotate cursor keys case Key_Left : case Key_Right: case Key_Up : case Key_Down : { if (rotation()==Rot90) { newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; } } break; } if (newkeycode!=keycode) { if ( newkeycode != Key_unknown ) { QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); } return true; } return false; } bool HTC::suspend() { /* MV */ return false; if ( !isQWS( ) ) // only qwsserver is allowed to suspend return false; bool res = false; QCopChannel::send( "QPE/System", "aboutToSuspend()" ); struct timeval tvs, tvn; ::gettimeofday ( &tvs, 0 ); ::sync(); // flush fs caches res = ( ::system ( "apm --suspend" ) == 0 ); // This is needed because some apm implementations are asynchronous and we // can not be sure when exactly the device is really suspended // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. // on non embedix eg. 2.6 kernel line apm is synchronous so we don't need it here. if ( res && m_embedix) { do { // wait at most 1.5 sec: either suspend didn't work or the device resumed ::usleep ( 200 * 1000 ); ::gettimeofday ( &tvn, 0 ); } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < m_timeOut ); } QCopChannel::send( "QPE/System", "returnFromSuspend()" ); return res; } 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 @@ /* This file is part of the Opie Project Copyright (C) 2004 Stefan Eilers <stefan@eilers-online.net> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "opimeventsortvector.h" #include <opie2/ocontactaccess.h> #include <opie2/opimnotifymanager.h> #include <opie2/odatebookaccess.h> #include <qvaluelist.h> namespace Opie { namespace Internal { -namespace{ - -inline int testAlarmNotifiers( const OPimNotifyManager& leftnotifiers, const OPimNotifyManager& rightnotifiers ){ +int testAlarmNotifiers( const OPimNotifyManager& leftnotifiers, const OPimNotifyManager& rightnotifiers ){ OPimNotifyManager::Alarms left_alarms = leftnotifiers.alarms(); OPimNotifyManager::Alarms right_alarms = rightnotifiers.alarms(); // Well.. How could we compare two lists of alarms? I think we should find the most early datetimes // and compare them.. (se) // Find the first alarm of the left list OPimNotifyManager::Alarms::Iterator it; QDateTime left_earliest; // This datetime is initialized as invalid!! for ( it = left_alarms.begin(); it != left_alarms.end(); ++it ){ if ( !left_earliest.isValid() || left_earliest > (*it).dateTime() ){ left_earliest = (*it).dateTime(); } } QDateTime right_earliest; // This datetime is initialized as invalid!! for ( it = right_alarms.begin(); it != right_alarms.end(); ++it ){ if ( !right_earliest.isValid() || right_earliest > (*it).dateTime() ){ right_earliest = (*it).dateTime(); } } - int ret; + int ret = 0; // Now compare this found alarms if ( !left_earliest .isValid() ) ret++; if ( !right_earliest.isValid() ) ret--; if ( left_earliest.isValid() && right_earliest.isValid() ){ - ret += left_earliest < right_earliest ? -1 : 1; + left_earliest < right_earliest ? ret-- : ret++; } return ret; } -} OPimEventSortVector::OPimEventSortVector( uint size, bool asc, int sort ) : OPimSortVector<OPimEvent>( size, asc, sort ) {} int OPimEventSortVector::compareItems( const OPimEvent& left, const OPimEvent& right ) { if ( left.uid() == right.uid() ) return 0; int ret = 0; bool asc = sortAscending(); switch( sortOrder() ) { case ODateBookAccess::SortDescription: ret = testString( left.description(), right.description() ); break; case ODateBookAccess::SortLocation: ret = testString( left.location(), right.location() ); break; case ODateBookAccess::SortNote: ret = testString( left.note(),right.note() ); break; case ODateBookAccess::SortStartTime: ret = testTime( left.startDateTime().time(), right.startDateTime().time() ); break; case ODateBookAccess::SortEndTime: ret = testTime( left.endDateTime().time(), right.endDateTime().time() ); break; case ODateBookAccess::SortStartDate: ret = testDate( left.startDateTime().date(), right.startDateTime().date() ); break; case ODateBookAccess::SortEndDate: ret = testDate( left.endDateTime().date(), right.endDateTime().date() ); break; case ODateBookAccess::SortStartDateTime: ret = testDateTime( left.startDateTime(), right.startDateTime() ); break; case ODateBookAccess::SortEndDateTime: ret = testDateTime( left.endDateTime(), right.endDateTime() ); break; case ODateBookAccess::SortAlarmDateTime: ret = testAlarmNotifiers( left.notifiers(), right.notifiers() ); break; default: odebug << "OpimEventSortVector: Unknown sortOrder: " << sortOrder() << oendl; } /* twist to honor ascending/descending setting as QVector only sorts ascending */ if ( !asc ) ret *= -1; // Maybe differentiate as in OPimTodoSortVector ### FIXME // if( ret ) return ret; } } } 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 @@ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // (c) 2002 Patrick S. Vogt <tille@handhelds.org> #include "listviewitemconffile.h" #include "listviewitemconfigentry.h" /* OPIE */ #include <opie2/odebug.h> using namespace Opie::Core; /* QT */ #include <qmessagebox.h> #include <qtextstream.h> #define tr QObject::tr ListViewItemConfFile::ListViewItemConfFile(QFileInfo *file, QListView *parent) : ListViewItemConf(parent), _valid(false) { confFileInfo = file; // parseFile(); displayText(); } ListViewItemConfFile::~ListViewItemConfFile() { } void ListViewItemConfFile::displayText() { setText(0,(_changed?"*":"")+confFileInfo->fileName()); } QString ListViewItemConfFile::fileName() { return confFileInfo->fileName(); } void ListViewItemConfFile::parseFile() { //odebug << "ListViewItemConfFile::parseFile BEGIN" << oendl; QFile confFile(confFileInfo->absFilePath()); if(! confFile.open(IO_ReadOnly)) QMessageBox::critical(0,tr("Could not open"),tr("The file ")+confFileInfo->fileName()+tr(" could not be opened."),1,0); + QTextStream t( &confFile ); QString s; QString group; - ListViewItemConfigEntry *groupItem; + ListViewItemConfigEntry *groupItem = 0; ListViewItemConfigEntry *item; while ( !t.atEnd() ) { s = t.readLine().stripWhiteSpace(); //odebug << "line: >" << s.latin1() << "<\n" << oendl; if (s.contains("<?xml")) { _valid = false; break; - }else - if ( s[0] == '[' && s[s.length()-1] == ']' ) + } + else if ( s[0] == '[' && s[s.length()-1] == ']' ) { // odebug << "got group"+s << oendl; group = s.mid(1,s.length()-2); - if (!groupItem) groupItem = new ListViewItemConfigEntry(this, tr("no group") ); + if (!groupItem) + groupItem = new ListViewItemConfigEntry(this, tr("no group") ); + groupItem = new ListViewItemConfigEntry(this, group ); insertItem( groupItem ); - } else - if ( int pos = s.find('=') ) + } + else if ( int pos = s.find('=') ) { // odebug << "got key"+s << oendl; - if (!groupItem) odebug << "PANIK NO GROUP! >" << group.latin1() << "<" << oendl; + if (!groupItem) + odebug << "PANIC! no group >" << group.latin1() << "<" << oendl; + item = new ListViewItemConfigEntry(this, group, s ); groupItem->insertItem( item ); } } confFile.close(); setExpandable( _valid ); // odebug << "ListViewItemConfFile::parseFile END" << oendl; } void ListViewItemConfFile::remove() { QFile::remove(confFileInfo->absFilePath()); QFile::remove(backupFileName()); delete this; } void ListViewItemConfFile::revert() { if (!_changed) { // read the backup file QFile conf(confFileInfo->absFilePath()); QFile back(backupFileName()); if (!back.open(IO_ReadOnly)) return; if (!conf.open(IO_WriteOnly)) return; #define SIZE 124 char buf[SIZE]; while (int c = back.readBlock(buf, SIZE) ) conf.writeBlock(buf,c); conf.close(); back.close(); } parseFile(); expand(); } void ListViewItemConfFile::save() { if (!_changed) return; QFile conf(confFileInfo->absFilePath()); QFile back(backupFileName()); if (!conf.open(IO_ReadOnly)) return; if (!back.open(IO_WriteOnly)) return; char buf[SIZE]; while (int c = conf.readBlock(buf, SIZE) ) back.writeBlock(buf,c); conf.close(); back.close(); if (!conf.open(IO_WriteOnly)) return; QTextStream *t = new QTextStream( &conf ); for (QListViewItem *it = firstChild(); it!=0;it = it->nextSibling()) { ((ListViewItemConfigEntry*)it)->save(t); } conf.close(); unchanged(); } bool ListViewItemConfFile::revertable() { return _changed || QFile(backupFileName()).exists(); } QString ListViewItemConfFile::backupFileName() { return confFileInfo->absFilePath()+"~"; } void ListViewItemConfFile::expand() { QListViewItem *subItem = firstChild(); QListViewItem *toDel; while(subItem) { toDel = subItem; subItem = subItem->nextSibling(); delete toDel; } parseFile(); } 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 @@ #include "io_irda.h" IOIrda::IOIrda( const Profile &config ) : IOSerial( config ) { m_attach = 0; } IOIrda::~IOIrda() { if ( m_attach ) { delete m_attach; } } void IOIrda::close() { IOSerial::close(); // still need error handling delete m_attach; } bool IOIrda::open() { bool ret; // irdaattach here m_attach = new Opie::Core::OProcess(); *m_attach << "irattach /dev/ttyS2 -s"; connect( m_attach, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( slotExited(Opie::Core::OProcess*) ) ); if ( m_attach->start() ) { ret= IOSerial::open(); } else { // emit error!!! delete m_attach; m_attach = 0l; + ret = false; } return ret; } void IOIrda::reload( const Profile &config ) { m_device = config.readEntry("Device", IRDA_DEFAULT_DEVICE); m_baud = config.readNumEntry("Baud", IRDA_DEFAULT_BAUD); m_parity = config.readNumEntry("Parity", IRDA_DEFAULT_PARITY); m_dbits = config.readNumEntry("DataBits", IRDA_DEFAULT_DBITS); m_sbits = config.readNumEntry("StopBits", IRDA_DEFAULT_SBITS); m_flow = config.readNumEntry("Flow", IRDA_DEFAULT_FLOW); } QString IOIrda::identifier() const { return "irda"; } QString IOIrda::name() const { return "Irda IO Layer"; } void IOIrda::slotExited(Opie::Core::OProcess* proc ){ close(); delete proc; } 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 @@ -454,382 +454,378 @@ void MainWindow::slotTerminate() { } void MainWindow::slotQuickLaunch() { Profile prof = manager()->profile( "default" ); if ( prof.name() == "default" ) { create( prof ); } else { #ifndef EAST Profile newProf = Profile( "default", "console", "default" , 0, 3, 0 ); newProf.setAutoConnect( true ); create( newProf ); slotSaveSession(); #endif } } void MainWindow::slotConfigure() { ConfigDialog conf( manager()->all(), factory() ); int ret = QPEApplication::execDialog( &conf ); if ( QDialog::Accepted == ret ) { manager()->setProfiles( conf.list() ); manager()->save(); populateProfiles(); } } /* * we will remove * this window from the tabwidget * remove it from the list * delete it * and set the currentSession() */ void MainWindow::slotClose() { if (!currentSession() ) return; Session* ses = currentSession(); /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */ m_curSession = NULL; tabWidget()->remove( /*currentSession()*/ses ); /*it's autodelete */ m_sessions.remove( ses ); if (!currentSession() ) { m_connect->setEnabled( false ); m_disconnect->setEnabled( false ); m_terminate->setEnabled( false ); m_transfer->setEnabled( false ); m_recordScript->setEnabled( false ); m_saveScript->setEnabled( false ); m_scripts->setItemEnabled(m_runScript_id, false); m_fullscreen->setEnabled( false ); m_wrap->setEnabled( false ); m_closewindow->setEnabled( false ); } m_kb->loadDefaults(); } /* * We will get the name * Then the profile * and then we will make a profile */ void MainWindow::slotProfile( int id) { Profile prof = manager()->profile( m_sessionsPop->text( id) ); create( prof ); } void MainWindow::create( const Profile& prof ) { char *homeDir = getenv("HOME"); if ( homeDir ) ::chdir( homeDir ); if(m_curSession) if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide(); Session *ses = manager()->fromProfile( prof, tabWidget() ); if((!ses) || (!ses->layer()) || (!ses->widgetStack())) { QMessageBox::warning(this, QObject::tr("Session failed"), QObject::tr("<qt>Cannot open session: Not all components were found.</qt>")); //if(ses) delete ses; return; } m_sessions.append( ses ); tabWidget()->add( ses ); tabWidget()->repaint(); m_curSession = ses; // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it m_connect->setEnabled( true ); m_disconnect->setEnabled( false ); m_terminate->setEnabled( true ); m_fullscreen->setEnabled( true ); m_wrap->setEnabled( true ); m_closewindow->setEnabled( true ); m_transfer->setEnabled( false ); m_recordScript->setEnabled( false ); m_saveScript->setEnabled( false ); m_scripts->setItemEnabled(m_runScript_id, false); // is io_layer wants direct connection, then autoconnect //if ( ( m_curSession->layer() )->supports()[0] == 1 ) { if (prof.autoConnect()) { slotConnect(); } QWidget *w = currentSession()->widget(); if(w) w->setFocus(); if(currentSession()->profile().readNumEntry("Wrap", 80)){ m_isWrapped = true; } else { m_isWrapped = false; } m_kb->load(currentSession()->profile()); } void MainWindow::slotTransfer() { if ( currentSession() ) { Session *mysession = currentSession(); TransferDialog dlg(/*mysession->widgetStack()*/this, this); mysession->setTransferDialog(&dlg); //dlg.reparent(mysession->widgetStack(), QPoint(0, 0)); //dlg.showMaximized(); currentSession()->widgetStack()->addWidget(&dlg, -1); dlg.show(); //dlg.exec(); while(dlg.isRunning()) qApp->processEvents(); mysession->setTransferDialog(0l); } } void MainWindow::slotOpenKeb(bool state) { if (state) m_keyBar->show(); else m_keyBar->hide(); } void MainWindow::slotOpenButtons( bool state ) { if ( state ) { m_buttonBar->show(); } else { m_buttonBar->hide(); } } void MainWindow::slotSessionChanged( Session* ses ) { if(m_curSession) if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide(); if(ses) if(ses->transferDialog()) ses->transferDialog()->show(); if ( ses ) { m_curSession = ses; if ( m_curSession->layer()->isConnected() ) { m_connect->setEnabled( false ); m_disconnect->setEnabled( true ); m_recordScript->setEnabled(!m_curSession->emulationHandler()->isRecording()); m_saveScript->setEnabled(m_curSession->emulationHandler()->isRecording()); m_scripts->setItemEnabled(m_runScript_id, true); } else { m_connect->setEnabled( true ); m_disconnect->setEnabled( false ); m_recordScript->setEnabled( false ); m_saveScript->setEnabled( false ); m_scripts->setItemEnabled(m_runScript_id, false); } if ( ( currentSession()->emulationHandler()->isLogging() ) ) { m_recordLog->setText( tr("Stop log") ); } else { m_recordLog->setText( tr("Start log") ); } if ( ( m_curSession->layer() )->supports()[1] == 0 ) { m_transfer->setEnabled( false ); } else { m_transfer->setEnabled( true ); } QWidget *w = m_curSession->widget(); if(w) w->setFocus(); if(currentSession()->profile().readNumEntry("Wrap", 80)){ m_isWrapped = true; } else { m_isWrapped = false; } m_kb->load(currentSession()->profile()); } } void MainWindow::slotWrap() { if(m_curSession) { EmulationHandler *e = m_curSession->emulationHandler(); if(e) { e->setWrap( m_isWrapped ? 80:0 ); m_isWrapped = !m_isWrapped; } } } void MainWindow::slotFullscreen() { if ( m_isFullscreen ) { ( m_curSession->widgetStack() )->reparent( savedParentFullscreen, 0, QPoint(0,0), true ); ( m_curSession->widgetStack() )->resize( savedParentFullscreen->width(), savedParentFullscreen->height() ); ( m_curSession->emulationHandler() )->cornerButton()->hide(); disconnect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) ); } else { savedParentFullscreen = ( m_curSession->widgetStack() )->parentWidget(); ( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame ); ( m_curSession->widgetStack() )->reparent( 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop , QPoint(0,0), false ); ( m_curSession->widgetStack() )->resize( qApp->desktop()->width(), qApp->desktop()->height() ); ( m_curSession->widgetStack() )->setFocus(); ( m_curSession->widgetStack() )->show(); ( ( m_curSession->emulationHandler() )->cornerButton() )->show(); connect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) ); } m_isFullscreen = !m_isFullscreen; } void MainWindow::slotScrollbarSelected(int index) { - int loc; + int loc = 0; Config cfg( "Konsole" ); cfg.setGroup("ScrollBar"); - if(index == sm_none) - { - loc = 0; - } - else if(index == sm_left) + if(index == sm_left) { loc = 1; } else if(index == sm_right) { loc = 2; } cfg.writeEntry("Position", loc); if (currentSession()) { currentSession()->emulationHandler()->setScrollbarLocation(loc); } m_scrollbar->setItemChecked(sm_none, index == sm_none); m_scrollbar->setItemChecked(sm_left, index == sm_left); m_scrollbar->setItemChecked(sm_right, index == sm_right); } void MainWindow::slotKeyReceived(FKey k, ushort, ushort, bool pressed) { if ( m_curSession ) { QEvent::Type state; if (pressed) state = QEvent::KeyPress; else state = QEvent::KeyRelease; QKeyEvent ke(state, k.qcode, k.unicode, 0, QString(QChar(k.unicode))); // is this the best way to do this? cant figure out any other way to work QApplication::sendEvent((QObject *)m_curSession->widget(), &ke); ke.ignore(); } } void MainWindow::slotCopy() { if (!currentSession() ) return; currentSession()->emulationHandler()->copy(); } void MainWindow::slotPaste() { if (!currentSession() ) return; currentSession()->emulationHandler()->paste(); } /* * Save the session */ void MainWindow::slotSaveSession() { if (!currentSession() ) { QMessageBox::information(this, tr("Save Connection"), tr("<qt>There is no Connection.</qt>"), 1 ); return; } manager()->add( currentSession()->profile() ); manager()->save(); populateProfiles(); } void MainWindow::slotSaveLog() { if( currentSession()->emulationHandler()->isLogging() ) { DocLnk nf; QString m_logName = currentSession()->emulationHandler()->logFileName(); QFileInfo info(m_logName); nf.setType("text/plain"); nf.setFile(m_logName); nf.setName(info.fileName()); nf.writeLink(); m_recordLog->setText( tr("Start log") ); m_recordingLog = false; currentSession()->emulationHandler()->clearLog(); } else { QMap<QString, QStringList> map; QStringList text; text << "text/plain"; map.insert(tr("Log"), text ); Opie::Core::OConfig cfg("opie-console"); cfg.setGroup("defaults"); QString startDir = cfg.readEntry("defaultlogdir", QPEApplication::documentDir() ); QString m_logName = OFileDialog::getSaveFileName(2, startDir, QString::null, map, 0, startDir); if (m_logName.isEmpty() ) return; m_recordLog->setText( tr("Stop log") ); m_recordingLog = true; currentSession()->emulationHandler()->startLogging(m_logName); } } void MainWindow::slotSaveHistory() { QMap<QString, QStringList> map; QStringList text; text << "text/plain"; map.insert(tr("History"), text ); QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map); if (filename.isEmpty() ) return; QFileInfo info(filename); DocLnk nf; nf.setType("text/plain"); nf.setFile(filename); nf.setName(info.fileName()); QFile file(filename); if ( !file.open(IO_WriteOnly ) ) return; QTextStream str(&file ); if ( currentSession() ) currentSession()->emulationHandler()->emulation()->streamHistory(&str); file.close(); nf.writeLink(); } 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 @@ -248,513 +248,513 @@ void PeanutFormatter::getch(tchar& ch, CStyle& sty, unsigned long& pos) int code = 0; for (int i = 0; i < 3; i++) { parent->getch(ch, dummy, pos); code = 10*code + ch - '0'; } ch = code; } break; case 'v': { while (1) { parent->getch(ch, dummy, pos); if (ch == '\\') { parent->getch(ch, dummy, pos); if (ch == 'v') { parent->getch(ch, dummy, pos); break; } } } } break; case 's': case 'n': currentstyle.setFontSize(0); parent->getch(ch,dummy, pos); break; case 'p': currentstyle.unset(); // parent->getch(ch,dummy); ch = 10; break; case 'l': if (currentstyle.getFontSize() == 1) { currentstyle.setFontSize(0); } else { currentstyle.setFontSize(1); } parent->getch(ch, dummy, pos); break; case 'x': if (currentstyle.getFontSize() == 0) { // currentstyle.unset(); // currentstyle.setBold(); currentstyle.setFontSize(1); } else { currentstyle.unset(); } // parent->getch(ch, dummy); ch = 10; break; case 'i': if (currentstyle.isItalic()) { currentstyle.unsetItalic(); } else { currentstyle.setItalic(); } parent->getch(ch, dummy, pos); break; case 'b': case 'B': if (currentstyle.isBold()) { currentstyle.unsetBold(); } else { currentstyle.setBold(); } parent->getch(ch, dummy, pos); break; case 'c': if (currentstyle.getJustify() == m_AlignCentre) { currentstyle.setLeftJustify(); } else { currentstyle.setCentreJustify(); } parent->getch(ch, dummy, pos); break; case 'r': if (currentstyle.getJustify() == m_AlignRight) { currentstyle.setLeftJustify(); } else { currentstyle.setRightJustify(); } parent->getch(ch, dummy, pos); break; default: currentstyle.setColour(255,0,0); } } sty = currentstyle; } void OnePara::getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); if (m_lastchar == 10) { while (ch == 10) parent->getch(ch, sty, pos); } m_lastchar = ch; } void repalm::getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); switch (ch) { case 0x80: ch = 0x20ac; break; case 0x82: ch = 0x201a; break; case 0x83: ch = 0x0192; break; case 0x84: ch = 0x201e; break; case 0x85: ch = 0x2026; break; case 0x86: ch = 0x2020; break; case 0x87: ch = 0x2021; break; case 0x88: ch = 0x02c6; break; case 0x89: ch = 0x2030; break; case 0x8a: ch = 0x0160; break; case 0x8b: ch = 0x2039; break; case 0x8c: ch = 0x0152; break; /* case 0x8e: ch = 0x017d; break; */ case 0x91: ch = 0x2018; break; case 0x92: ch = 0x2019; break; case 0x93: ch = 0x201c; break; case 0x94: ch = 0x201d; break; case 0x95: ch = 0x2022; break; case 0x96: ch = 0x2013; break; case 0x97: ch = 0x2014; break; case 0x98: ch = 0x02dc; break; case 0x99: ch = 0x2122; break; case 0x9a: ch = 0x0161; break; case 0x9b: ch = 0x203a; break; case 0x9c: ch = 0x0153; break; case 0x9e: ch = 0x017e; break; case 0x9f: ch = 0x0178; break; case 0x18: ch = 0x2026; break; case 0x19: ch = 0x2007; break; case 0x8d: ch = 0x2662; break; case 0x8e: ch = 0x2663; break; case 0x8f: ch = 0x2661; break; case 0x90: ch = 0x2660; break; default: break; } } //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 }; //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 }; void DePluck::getch(tchar& ch, CStyle& sty, unsigned long& pos) { if (m_buffed > 0) { sty = m_laststyle; ch = nextpart[m_current++]; if (m_current == m_buffed) { m_current = m_buffed = 0; } } else { if (m_buffer != 0) { ch = m_buffer; m_buffer = 0; return; } - unsigned long lnk, lnkoff; + unsigned long lnk = 0, lnkoff = 0; do { if (nextpart[m_buffed] == 0) break; parent->getch(ch, sty, pos); m_laststyle = sty; if (sty.getLink()) { lnk = sty.getData(); lnkoff = sty.getOffset(); } } while (ch == nextpart[m_buffed] && sty.getLink() && ++m_buffed); m_current = 0; if (nextpart[m_buffed] == 0) { m_buffed = 0; QString dmy, dmy2; parent->hyperlink(lnk, lnkoff, dmy, dmy2); do { parent->getch(ch, sty, pos); } while (ch != 10); parent->getch(ch, sty, pos); } else if (m_buffed > 0) { m_buffer = ch; ch = nextpart[0]; if (m_buffed == 1) { m_buffed = 0; } else m_current = 1; } } return; } HighlightFilter::HighlightFilter(QTReader* _p) : pReader(_p), lastpos(0), nextpos(0), red(255), green(255), blue(255) { } #include "Bkmks.h" #include "QTReader.h" void HighlightFilter::refresh(unsigned long pos) { bkmks = pReader->Bkmklist(); red = green = blue = 255; if (bkmks == NULL) { lastpos = 0; nextpos = 0xffffffff; } else { lastpos = 0; nextpos = 0xffffffff; for (CList<Bkmk>::iterator i = bkmks->begin(); i != bkmks->end(); i++) { if ((*i).value() <= pos && pos < (*i).value2()) { red = i->red(); green = i->green(); blue = i->blue(); lastpos = (*i).value(); nextpos = (*i).value2(); break; } if ((*i).value() > pos) { nextpos = (*i).value(); break; } lastpos = (*i).value(); } } } void HighlightFilter::getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); if (bkmks != pReader->Bkmklist() || pos <= lastpos || pos >= nextpos) { // qDebug("Recalc <%lu, %lu, %lu>", lastpos, pos, nextpos); refresh(pos); // qDebug("Recalc(2) <%lu, %lu, %lu>", lastpos, pos, nextpos); } int r = sty.bRed(), g = sty.bGreen(), b = sty.bBlue(); if (r == 255 && g == 255 && b == 255) { sty.setBackground(red, green, blue); } } void kern::getch(tchar& ch, CStyle& sty, unsigned long& pos) { if (uselast) { ch = lastchar; sty = laststy; uselast = false; return; } else { parent->getch(ch, sty, pos); } switch (ch) { case 'f': { tchar savedchar = 'f'; parent->getch(ch, sty, pos); switch (ch) { case 'i': ch = (251 << 8) + 1; break; case 'l': ch = (251 << 8) + 2; break; default: lastchar = ch; uselast = true; laststy = sty; ch = savedchar; } } break; default: break; } } class ErrorFilter : public CFilter { QString error; int currentpos; public: ErrorFilter(const QString& _s) : error(_s), currentpos(0) {} ~ErrorFilter() {} void getch(tchar& ch, CStyle& sty, unsigned long& pos) { if (currentpos == error.length()) { ch = UEOF; currentpos = 0; } else { ch = error[currentpos++].unicode(); } } QString about() { return parent->about(); } }; #ifndef __STATIC ExternFilter::ExternFilter(const QString& nm, const QString& optional) : filt(NULL), handle(NULL) { #ifdef USEQPE #ifdef OPIE QString filterpath(getenv("OPIEDIR")); #else QString filterpath(getenv("QTDIR")); #endif filterpath += "/plugins/reader/filters/lib"; #else QString filterpath(getenv("READERDIR")); filterpath += "/filters/lib"; #endif filterpath += nm; filterpath += ".so"; if (QFile::exists(filterpath)) { qDebug("Filter:%s", (const char*)filterpath); handle = dlopen(filterpath, RTLD_LAZY); if (handle == 0) { qDebug("Can't find filter:%s", dlerror()); // status = -10; filt = new ErrorFilter(QString("Can't find plugin:")+nm); return; } CFilter* (*newfilter)(const QString&); newfilter = (CFilter* (*)(const QString&))dlsym(handle, "newfilter"); if (newfilter == NULL) { qDebug("Can't find newfilter"); filt = new ErrorFilter(QString("Can't find entry point in plugin:")+nm); return; } filt = (*newfilter)(optional); } else { qDebug("No filter path:%s", (const char*)filterpath); filt = new ErrorFilter(QString("No filter plugins installed:")+nm); } if (filt == NULL) { qDebug("Can't do newfilter"); filt = new ErrorFilter(QString("Filter creation failed:")+nm); return; } } #endif void makeInverse::getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); int r,g,b; r = 255 - sty.Red(), g = 255 - sty.Green(), b = 255 - sty.Blue(); sty.setColour(r,g,b); r = 255 - sty.bRed(), g = 255 - sty.bGreen(), b = 255 - sty.bBlue(); sty.setBackground(r,g,b); r = 255 - sty.pRed(), g = 255 - sty.pGreen(), b = 255 - sty.pBlue(); sty.setPaper(r,g,b); } /* void makeNegative::getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); QColor fg(sty.Red(), sty.Green(), sty.Blue()); int h,s,v; fg.hsv(&h,&s,&v); fg.setHsv(h,s,255-v); int r,g,b; fg.rgb(&r,&g,&b); sty.setColour(r,g,b); fg = QColor(sty.bRed(), sty.bGreen(), sty.bBlue()); fg.hsv(&h,&s,&v); fg.setHsv(h,s,255-v); fg.rgb(&r,&g,&b); sty.setBackground(r,g,b); } */ void setbg::getch(tchar& ch, CStyle& sty, unsigned long& pos) { parent->getch(ch, sty, pos); int r = sty.pRed(), g = sty.pGreen(), b = sty.pBlue(); if (r == 255 && g == 255 && b == 255) { sty.setPaper(m_r,m_g,m_b); } else { qDebug("We have background [%x%x%x]", r, g, b); } r = sty.bRed(), g = sty.bGreen(), b = sty.bBlue(); if (r == 255 && g == 255 && b == 255) { 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,546 +1,546 @@ #include "CRegExp.h" //#include <stdio.h> #include <stdlib.h> //#include <string.h> tchar CRegExpFilt::escapedchar(tchar c) { switch (c) { case '\\': return '\\'; break; case '"': return '\"'; break; case 'a': return '\a'; break; case 'b': return '\b'; break; case 'f': return '\f'; break; case 'n': return '\n'; break; case 'r': return '\r'; break; case 't': return '\t'; break; case 'v': return '\v'; break; default: return c; break; } } void CRegExpFilt::regchar(tchar c, bool insens) { if (insens) { tchar t = upper(c); CV[t] = 0; t = lower(c); CV[t] = 0; } else { CV[c] = 0; } } void CRegExpFilt::prepreprocessing(const QString& pat, bool insens) { for (unsigned int p = 0; p < pat.length(); p++) { #ifdef _WINDOWS switch (pat.at(p).unicode()) #else switch (pat[p].unicode()) #endif { case '{': { break; } case '}': { break; } case '^': { break; } case '.' : { break; } case '#': { p++; #ifdef _WINDOWS while ('0' <= pat.at(p).unicode() && pat.at(p).unicode() <= '9') #else while ('0' <= pat[p].unicode() && pat[p].unicode() <= '9') #endif { } p--; break; } case '\\' : { #ifdef _WINDOWS tchar c = escapedchar(pat.at(++p).unicode()); #else tchar c = escapedchar(pat[++p].unicode()); #endif regchar(c, insens); break; } case '[' : { - tchar clast; + tchar clast = 0; bool invert = false; tchar c; #ifdef _WINDOWS if (pat.at(p+1).unicode() == '^') #else if (pat[p+1].unicode() == '^') #endif { p++; invert = true; } #ifdef _WINDOWS while ((c = pat.at(++p).unicode()) != ']') #else while ((c = pat[++p].unicode()) != ']') #endif { if (c == '\\') { #ifdef _WINDOWS c = escapedchar(pat.at(++p).unicode()); #else c = escapedchar(pat[++p].unicode()); #endif if (c == ']') break; } if (c == '-') { #ifdef _WINDOWS c = pat.at(++p).unicode(); #else c = pat[++p].unicode(); #endif for (tchar j = clast; j <= c; j++) { regchar(j, insens); } } else { regchar(c, insens); } clast = c; } break; } default : { #ifdef _WINDOWS regchar(pat.at(p).unicode(), insens); #else regchar(pat[p].unicode(), insens); #endif break; } } } /* for (iter i = CV.begin(); i != CV.end(); ++i) { printf("Pre: [%u]\n", i.first()); } */ CV[0] = 0; } unsigned int CRegExpFilt::preprocessing(const QString& pat, bool insens) { prepreprocessing(pat, insens); qDebug("PrePreProcessing done"); unsigned int p, m; bool inkeep = false; keep = 0; replace = 0; for (unsigned int j = 0; j < WORD_SIZE; j++) { bit[j] = (1 << (WORD_SIZE -j -1)); lfcnt[j] = 0; } for (p = 0, m = 0; p < pat.length(); p++) { qDebug("m is %u", m); if (inkeep) keep |= bit[m]; #ifdef _WINDOWS switch (pat.at(p).unicode()) #else switch (pat[p].unicode()) #endif { case '{': { inkeep = true; break; } case '}': { keep ^= bit[m]; inkeep = false; break; } case '^': { replace |= bit[m]; lfcnt[m]++; break; } case '.' : { for (iter j = CV.begin(); j != CV.end(); ++j) CV[j.first()] |= bit[m]; m++; break; } case '#': { if (m > 0) { p++; int count = 0; #ifdef _WINDOWS while ('0' <= pat.at(p).unicode() && pat.at(p).unicode() <= '9') #else while ('0' <= pat[p].unicode() && pat[p].unicode() <= '9') #endif { #ifdef _WINDOWS count = 10*count + pat.at(p++).unicode() - '0'; #else count = 10*count + pat[p++].unicode() - '0'; #endif } p--; count = count-1; unsigned int mask = 0; for (unsigned int i = m; i < m+count; i++) { mask |= bit[i]; } for (iter it = CV.begin(); it != CV.end(); ++it) { if (CV[it.first()] & bit[m-1]) { CV[it.first()] |= mask; } } if (keep & bit[m-1]) keep |= mask; m += count; } else { p++; } break; } case '\\' : { #ifdef _WINDOWS tchar c = escapedchar(pat.at(++p).unicode()); #else tchar c = escapedchar(pat[++p].unicode()); #endif if (insens) { CV[upper(c)] |= bit[m]; CV[lower(c)] |= bit[m]; } else { CV[c] |= bit[m]; } m++; break; } case '[' : { - tchar c, clast; + tchar c, clast = 0; bool invert = false; #ifdef _WINDOWS if (pat.at(p+1).unicode() == '^') #else if (pat[p+1].unicode() == '^') #endif { p++; invert = true; } #ifdef _WINDOWS while ((c = pat.at(++p).unicode()) != ']') #else while ((c = pat[++p].unicode()) != ']') #endif { if (c == '\\') { #ifdef _WINDOWS c = escapedchar(pat.at(++p).unicode()); #else c = escapedchar(pat[++p].unicode()); #endif if (c == ']') break; } if (c == '-') { #ifdef _WINDOWS c = pat.at(++p).unicode(); #else c = pat[++p].unicode(); #endif for (tchar j = clast; j <= c; j++) { if (insens) { iter it; if ((it = CV.find(upper(j))) != CV.end()) CV[it] |= bit[m]; else CV[0] |= bit[m]; if ((it = CV.find(lower(j))) != CV.end()) CV[it] |= bit[m]; else CV[0] |= bit[m]; } else { iter it; if ((it = CV.find(j)) != CV.end()) CV[it] |= bit[m]; else { CV[0] |= bit[m]; } } } } else { if (insens) { iter it; if ((it = CV.find(upper(c))) != CV.end()) CV[it] |= bit[m]; else CV[0] |= bit[m]; if ((it = CV.find(lower(c))) != CV.end()) CV[it] |= bit[m]; else CV[0] |= bit[m]; } else { iter it; if ((it = CV.find(c)) != CV.end()) CV[it] |= bit[m]; else CV[0] |= bit[m]; } } clast = c; } if (invert) { for (iter i = CV.begin(); i != CV.end(); ++i) { CV[i.first()] ^= bit[m]; } } m++; break; } default : { #ifdef _WINDOWS tchar c = pat.at(p).unicode(); #else tchar c = pat[p].unicode(); #endif if (insens) { CV[upper(c)] |= bit[m]; CV[lower(c)] |= bit[m]; } else CV[c] |= bit[m]; m++; break; } } } qDebug("Returning:%u",m); return m; } bool CRegExpFilt::empty() { return m_outQueue.empty(); } tchar CRegExpFilt::pop() { return m_outQueue.pop(); } bool CRegExpFilt::addch(tchar ch) { word[cur] = ch; cur = (cur+1)%patlength; if (len < patlength) len++; unsigned int cv = 0; iter it; if ((it = CV.find(ch)) == CV.end()) { cv = CV[0]; } else { cv = CV[it]; } R = ((R >> 1) | bit_0) & cv; /* Exact matches */ if (R & endpos) { for (unsigned int i = 0; i < patlength; i++) { if (replace & bit[i]) { for (unsigned int j = 0; j < lfcnt[i]; j++) { m_outQueue.push(10); } } if (keep & bit[i]) { m_outQueue.push(word[(cur+i)%patlength]); // putchar('*'); // putchar(i + '0'); } len = 0; } return true; } else { if (len == patlength) { tchar ch = word[cur]; if (ch == 10) ch = ' '; m_outQueue.push(ch); } return false; } } void CRegExpFilt::restart() { R = 0; len = 0; } CRegExpFilt::CRegExpFilt(const QString& pat, bool insensflag) : CV(300) { cur = 0; patlength = preprocessing(pat, insensflag); qDebug("Preprocesing done:%u", patlength); endpos = bit[patlength-1]; bit_0 = bit[0]; restart(); qDebug("Pattern: %s:%u", (const char*)pat, patlength); } CRegExpFilt::~CRegExpFilt() { } #ifdef NOWAYISTHISDEFINED void reportmatch(tchar *line, /*tchar *text,*/ unsigned int mtype, unsigned int lino) { /* tchar *text = line + strlen(line); tchar *ptr = line; if (mtype == 0) printf("Exact match at line number %u.\n", lino); else printf("%u error match at line number %u.\n", mtype, lino); while (ptr < text) putchar(*ptr++); printf("%c[4m^%c[24m%s\n", 27, 27, ptr); */ } void usage(void) { printf("Usage: CRegExpFilt [-i] pattern/a file\n"); } int getline(tchar *s,int lim,FILE *f) { int c, i; for (i = 0; i < lim-1 && (c = getc(f)) != EOF && c != '\n'; ) { s[i++] = (tchar)c; } s[i] = '\0'; return ((c == EOF && i == 0) ? -1 : i); } #define BUF_SIZE 256 int main(int argc, char **argv) { unsigned int lino = 0; unsigned int blino = 0; bool insens = false; int len; tchar line[BUF_SIZE]; FILE *inf; /* Error checking of cmd ln args! */ if (argc < 3) {usage(); return 10; } /* Corresponds to requiring a minimum of 3 matches */ for (len = 1; len < argc-2; len++) { if (argv[len][0] != '-') {usage(); return 10; } else switch (argv[len][1]) { 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 @@ /* -*- mode: c; indent-tabs-mode: nil; -*- */ #include <stdio.h> #include <stdlib.h> #include <string.h> #ifndef _WINDOWS #include <unistd.h> /* for link */ #endif #include <sys/types.h> #include <sys/stat.h> #include <stdarg.h> #include <qimage.h> /***********************************************************************/ /***********************************************************************/ /***** *****/ /***** Code to decode the Palm image format to JPEG *****/ /***** *****/ /***********************************************************************/ /***********************************************************************/ #define READ_BIGENDIAN_SHORT(p) (((p)[0] << 8)|((p)[1])) #define READ_BIGENDIAN_LONG(p) (((p)[0] << 24)|((p)[1] << 16)|((p)[2] << 8)|((p)[3])) #define PALM_IS_COMPRESSED_FLAG 0x8000 #define PALM_HAS_COLORMAP_FLAG 0x4000 #define PALM_HAS_TRANSPARENCY_FLAG 0x2000 #define PALM_DIRECT_COLOR_FLAG 0x0400 #define PALM_4_BYTE_FIELD_FLAG 0x0200 #define PALM_COMPRESSION_SCANLINE 0x00 #define PALM_COMPRESSION_RLE 0x01 #define PALM_COMPRESSION_PACKBITS 0x02 #define PALM_COMPRESSION_NONE 0xFF #define PALM_COLORMAP_SIZE 232 typedef struct { unsigned char red; unsigned char green; unsigned char blue; } ColorMapEntry; static ColorMapEntry Palm8BitColormap[] = { { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 }, { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 }, { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 }, { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 }, { 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 }, { 204, 153, 255 }, { 204, 102, 255 }, { 204, 51, 255 }, { 204, 0, 255 }, { 204, 255, 204 }, { 204, 204, 204 }, { 204, 153, 204 }, { 204, 102, 204 }, { 204, 51, 204 }, { 204, 0, 204 }, { 204, 255, 153 }, { 204, 204, 153 }, { 204, 153, 153 }, { 204, 102, 153 }, { 204, 51, 153 }, { 204, 0, 153 }, { 153, 255, 255 }, { 153, 204, 255 }, { 153, 153, 255 }, { 153, 102, 255 }, { 153, 51, 255 }, { 153, 0, 255 }, { 153, 255, 204 }, { 153, 204, 204 }, { 153, 153, 204 }, { 153, 102, 204 }, { 153, 51, 204 }, { 153, 0, 204 }, { 153, 255, 153 }, { 153, 204, 153 }, { 153, 153, 153 }, { 153, 102, 153 }, { 153, 51, 153 }, { 153, 0, 153 }, { 102, 255, 255 }, { 102, 204, 255 }, { 102, 153, 255 }, { 102, 102, 255 }, { 102, 51, 255 }, { 102, 0, 255 }, { 102, 255, 204 }, { 102, 204, 204 }, { 102, 153, 204 }, { 102, 102, 204 }, { 102, 51, 204 }, { 102, 0, 204 }, { 102, 255, 153 }, { 102, 204, 153 }, { 102, 153, 153 }, { 102, 102, 153 }, { 102, 51, 153 }, { 102, 0, 153 }, { 51, 255, 255 }, { 51, 204, 255 }, { 51, 153, 255 }, { 51, 102, 255 }, { 51, 51, 255 }, { 51, 0, 255 }, { 51, 255, 204 }, { 51, 204, 204 }, { 51, 153, 204 }, { 51, 102, 204 }, { 51, 51, 204 }, { 51, 0, 204 }, { 51, 255, 153 }, { 51, 204, 153 }, { 51, 153, 153 }, { 51, 102, 153 }, { 51, 51, 153 }, { 51, 0, 153 }, { 0, 255, 255 }, { 0, 204, 255 }, { 0, 153, 255 }, { 0, 102, 255 }, { 0, 51, 255 }, { 0, 0, 255 }, { 0, 255, 204 }, { 0, 204, 204 }, { 0, 153, 204 }, { 0, 102, 204 }, { 0, 51, 204 }, { 0, 0, 204 }, { 0, 255, 153 }, { 0, 204, 153 }, { 0, 153, 153 }, { 0, 102, 153 }, { 0, 51, 153 }, { 0, 0, 153 }, { 255, 255, 102 }, { 255, 204, 102 }, { 255, 153, 102 }, { 255, 102, 102 }, { 255, 51, 102 }, { 255, 0, 102 }, { 255, 255, 51 }, { 255, 204, 51 }, { 255, 153, 51 }, { 255, 102, 51 }, { 255, 51, 51 }, { 255, 0, 51 }, { 255, 255, 0 }, { 255, 204, 0 }, { 255, 153, 0 }, { 255, 102, 0 }, { 255, 51, 0 }, { 255, 0, 0 }, { 204, 255, 102 }, { 204, 204, 102 }, { 204, 153, 102 }, { 204, 102, 102 }, { 204, 51, 102 }, { 204, 0, 102 }, { 204, 255, 51 }, { 204, 204, 51 }, { 204, 153, 51 }, { 204, 102, 51 }, { 204, 51, 51 }, { 204, 0, 51 }, { 204, 255, 0 }, { 204, 204, 0 }, { 204, 153, 0 }, { 204, 102, 0 }, { 204, 51, 0 }, { 204, 0, 0 }, { 153, 255, 102 }, { 153, 204, 102 }, { 153, 153, 102 }, { 153, 102, 102 }, { 153, 51, 102 }, { 153, 0, 102 }, { 153, 255, 51 }, { 153, 204, 51 }, { 153, 153, 51 }, { 153, 102, 51 }, { 153, 51, 51 }, { 153, 0, 51 }, { 153, 255, 0 }, { 153, 204, 0 }, { 153, 153, 0 }, { 153, 102, 0 }, { 153, 51, 0 }, { 153, 0, 0 }, { 102, 255, 102 }, { 102, 204, 102 }, { 102, 153, 102 }, { 102, 102, 102 }, { 102, 51, 102 }, { 102, 0, 102 }, { 102, 255, 51 }, { 102, 204, 51 }, { 102, 153, 51 }, { 102, 102, 51 }, { 102, 51, 51 }, { 102, 0, 51 }, { 102, 255, 0 }, { 102, 204, 0 }, { 102, 153, 0 }, { 102, 102, 0 }, { 102, 51, 0 }, { 102, 0, 0 }, { 51, 255, 102 }, { 51, 204, 102 }, { 51, 153, 102 }, { 51, 102, 102 }, { 51, 51, 102 }, { 51, 0, 102 }, { 51, 255, 51 }, { 51, 204, 51 }, { 51, 153, 51 }, { 51, 102, 51 }, { 51, 51, 51 }, { 51, 0, 51 }, { 51, 255, 0 }, { 51, 204, 0 }, { 51, 153, 0 }, { 51, 102, 0 }, { 51, 51, 0 }, { 51, 0, 0 }, { 0, 255, 102 }, { 0, 204, 102 }, { 0, 153, 102 }, { 0, 102, 102 }, { 0, 51, 102 }, { 0, 0, 102 }, { 0, 255, 51 }, { 0, 204, 51 }, { 0, 153, 51 }, { 0, 102, 51 }, { 0, 51, 51 }, { 0, 0, 51 }, { 0, 255, 0 }, { 0, 204, 0 }, { 0, 153, 0 }, { 0, 102, 0 }, { 0, 51, 0 }, { 17, 17, 17 }, { 34, 34, 34 }, { 68, 68, 68 }, { 85, 85, 85 }, { 119, 119, 119 }, { 136, 136, 136 }, { 170, 170, 170 }, { 187, 187, 187 }, { 221, 221, 221 }, { 238, 238, 238 }, { 192, 192, 192 }, { 128, 0, 0 }, { 128, 0, 128 }, { 0, 128, 0 }, { 0, 128, 128 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }}; static ColorMapEntry Palm1BitColormap[] = {{ 255, 255, 255 }, { 0, 0, 0 }}; static ColorMapEntry Palm2BitColormap[] = { { 255, 255, 255 }, { 192, 192, 192 }, { 128, 128, 128 }, { 0, 0, 0 }}; static ColorMapEntry Palm4BitColormap[] = { { 255, 255, 255 }, { 238, 238, 238 }, { 221, 221, 221 }, { 204, 204, 204 }, { 187, 187, 187 }, { 170, 170, 170 }, { 153, 153, 153 }, { 136, 136, 136 }, { 119, 119, 119 }, { 102, 102, 102 }, { 85, 85, 85 }, { 68, 68, 68 }, { 51, 51, 51 }, { 34, 34, 34 }, { 17, 17, 17 }, { 0, 0, 0 }}; QImage* Palm2QImage (unsigned char *image_bytes_in, int byte_count_in) { unsigned int width, height, bytes_per_row, flags, next_depth_offset; unsigned int bits_per_pixel, version, transparent_index, compression_type, i, j, inval, inbit, mask, incount; unsigned int palm_red_bits, palm_green_bits, palm_blue_bits; - unsigned char *palm_ptr, *x_ptr, *imagedata, *inbyte, *rowbuf, *lastrow, + unsigned char *palm_ptr, *x_ptr, *inbyte, *rowbuf, *lastrow, *imagedatastart, *palmimage; ColorMapEntry *colormap; palmimage = image_bytes_in; width = READ_BIGENDIAN_SHORT(palmimage + 0); height = READ_BIGENDIAN_SHORT(palmimage + 2); bytes_per_row = READ_BIGENDIAN_SHORT(palmimage + 4); flags = READ_BIGENDIAN_SHORT(palmimage + 6); bits_per_pixel = palmimage[8]; version = palmimage[9]; next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10); transparent_index = palmimage[12]; compression_type = palmimage[13]; /* bytes 14 and 15 are reserved by Palm and always 0 */ #if 0 // qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d", width, height, bits_per_pixel, version, flags, compression_type); #endif if (compression_type == PALM_COMPRESSION_PACKBITS) { // qDebug ("Image uses packbits compression; not yet supported"); return NULL; } else if ((compression_type != PALM_COMPRESSION_NONE) && (compression_type != PALM_COMPRESSION_RLE) && (compression_type != PALM_COMPRESSION_SCANLINE)) { // qDebug ("Image uses unknown compression, code 0x%x", compression_type); return NULL; } /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps: 1, 2, or 4 bit grayscale 8-bit StaticColor using the Palm standard colormap 8-bit PseudoColor using a user-specified colormap 16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue Each of these can be compressed with one of four compression schemes, "RLE", "Scanline", "PackBits", or none. We begin by constructing the colormap. */ if (flags & PALM_HAS_COLORMAP_FLAG) { // qDebug("Palm images with custom colormaps are not currently supported.\n"); return NULL; } else if (bits_per_pixel == 1) { colormap = Palm1BitColormap; imagedatastart = palmimage + 16; } else if (bits_per_pixel == 2) { colormap = Palm2BitColormap; imagedatastart = palmimage + 16; } else if (bits_per_pixel == 4) { colormap = Palm4BitColormap; imagedatastart = palmimage + 16; } else if (bits_per_pixel == 8) { colormap = Palm8BitColormap; imagedatastart = palmimage + 16; } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) { colormap = NULL; palm_red_bits = palmimage[16]; palm_green_bits = palmimage[17]; palm_blue_bits = palmimage[18]; // qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits); if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) { // 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); return NULL; } if (bits_per_pixel > (8 * sizeof(unsigned long))) { // qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel); return NULL; } imagedatastart = palmimage + 24; } else { // qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel); return NULL; } #ifndef USEQPE QImage* qimage = new QImage(width, height, 32); #else QImage* qimage = new QImage(width, height, 16); #endif /* row by row, uncompress the Palm image and copy it to the JPEG buffer */ rowbuf = new unsigned char[bytes_per_row * width]; lastrow = new unsigned char[bytes_per_row * width]; - for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) { + for (i=0, palm_ptr = imagedatastart , x_ptr = 0; i < height; ++i) { // qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row); /* first, uncompress the Palm image */ if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { for (j = 0; j < bytes_per_row; ) { incount = *palm_ptr++; inval = *palm_ptr++; memset(rowbuf + j, inval, incount); j += incount; } } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) { for (j = 0; j < bytes_per_row; j += 8) { incount = *palm_ptr++; inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8; for (inbit = 0; inbit < inval; inbit += 1) { if (incount & (1 << (7 - inbit))) rowbuf[j + inbit] = *palm_ptr++; else rowbuf[j + inbit] = lastrow[j + inbit]; } } memcpy (lastrow, rowbuf, bytes_per_row); } else if (((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_NONE)) || ((flags & PALM_IS_COMPRESSED_FLAG) == 0)) { memcpy (rowbuf, palm_ptr, bytes_per_row); palm_ptr += bytes_per_row; } else { qDebug("Case 4"); qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true"); qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true"); qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true"); qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true"); qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true"); memcpy (rowbuf, palm_ptr, bytes_per_row); palm_ptr += bytes_per_row; } /* next, write it to the GDK bitmap */ if (colormap) { mask = (1 << bits_per_pixel) - 1; for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) { inval = ((*inbyte) & (mask << inbit)) >> inbit; /* correct for oddity of the 8-bit color Palm pixmap... */ if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231; /* now lookup the correct color and set the pixel in the GTK bitmap */ QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue); qimage->setPixel(j, i, colour); if (!inbit) { ++inbyte; inbit = 8 - bits_per_pixel; } else { inbit -= bits_per_pixel; } } } else if (!colormap && bits_per_pixel == 16) { for (inbyte = rowbuf, j = 0; j < width; ++j) { inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1]; /* qDebug ("pixel is %d,%d (%d:%d:%d)", j, i, ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)); */ QRgb colour = qRgb( ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)); qimage->setPixel(j, i, colour); inbyte += 2; } } } delete [] rowbuf; delete [] lastrow; return qimage; } 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 @@ -291,513 +291,513 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) else { m_drageligible = true; } } qDebug("Drag eligible:%s", (m_drageligible) ? "true" : "false"); } else { if (m_scrollpos == 1) { if (x < m_left_border) { lineUp(); } if (y > ht - m_bottommargin) { lineDown(); } } else if (m_scrollpos != 0) { if (y < m_topmargin) { lineUp(); } if (y > ht - m_bottommargin) { lineDown(); } } } } } void QTReader::processmousepositionevent( QMouseEvent* _e ) { int x, y, ht, wh; if (m_rotated) { x = _e->y(); y = width()-_e->x(); ht = width(); wh = height(); } else { x = _e->x(); y = _e->y(); ht = height(); wh = width(); } if (buffdoc.hasnavigation()) { if (y > (2*ht)/3) { goDown(); } else if (y < ht/3) { goUp(); } else { if (x < wh/3) { goBack(); } else if (x > (2*wh)/3) { goForward(); } else { goHome(); } } } else { if (y > ht/2) { goDown(); } else { goUp(); } } } void QTReader::goHome() { if (buffdoc.hasnavigation()) { size_t current=pagelocate(); size_t home=buffdoc.getHome(); if (current!=home) { buffdoc.saveposn(m_lastfile, current); locate(home); } } else locate(0); } void QTReader::goBack() { if (buffdoc.hasnavigation()) { size_t target = pagelocate(); QString nxt = m_lastfile; buffdoc.writeposn(m_lastfile, target); linkType lt = buffdoc.back(nxt, target); if ((lt & eFile) != 0) { if (nxt != m_lastfile) { emit NewFileRequest(nxt); } locate(target); } else if ((lt & eLink) != 0) { locate(target); } } } void QTReader::goForward() { if (buffdoc.hasnavigation()) { size_t target = pagelocate(); QString nxt = m_lastfile; linkType lt = buffdoc.forward(nxt, target); if ((lt & eFile) != 0) { if (nxt != m_lastfile) { emit NewFileRequest(nxt); } locate(target); } else if ((lt & eLink) != 0) { locate(target); } } } linkType 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) { int ht; if (m_scrolldy == m_topmargin) { lineno = 0; ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin; } else { if (y >= m_scrolldy) { lineno = 0; ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy + m_topmargin; } else { lineno = 0; ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy+m_topmargin; while ((ht < h) && (lineno < numlines-1)) { ht += textarray[++lineno]->lineSpacing(); } ht = textarray[lineno]->lineSpacing(); } } while ((ht < y) && (lineno < numlines-1)) { ht += textarray[++lineno]->lineSpacing(); } if (ht < y && textarray[numlines]->showPartial()) lineno = numlines; start = locnarray[lineno]; int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; if (m_bMonoSpaced) { offset = (x - textarray[lineno]->offset(w, m_left_border, m_right_border, availht))/m_charWidth; } else { int i; CDrawBuffer* t = textarray[lineno]; x = x - t->offset(width(), m_left_border, m_right_border, availht); for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--); offset = i; } return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img, tabtgt); } void QTReader::suspend() { buffdoc.suspend(); /*#ifdef OPIE if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend(); #else if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend(); #endif */ } void QTReader::setDoubleBuffer(bool _b) { m_doubleBuffered = _b; if (_b || m_rotated) { if (dbuff == NULL) { dbuff = new QPixmap(); dbp = new QPainter(); } if (m_rotated) { dbuff->resize(height(), width()); } else { dbuff->resize(width(), height()); } m_outofdate = true; } else { if (dbuff != NULL) { delete dbuff; delete dbp; } dbuff = NULL; dbp = NULL; } } void QTReader::setTwoTouch(bool _b) { setBackgroundColor( m_bg ); m_twotouch = m_touchone = _b; } void QTReader::setContinuous(bool _b) { buffdoc.setContinuous(m_continuousDocument = _b); } void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno) { - unsigned long wrdstart, wrdend; + unsigned long wrdstart = 0, wrdend = 0; QString wrd; int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; if (m_twotouch) { if (m_touchone) { m_touchone = false; m_startpos = startpos; m_startoffset = startoffset; setBackgroundColor( lightGray ); } else { m_touchone = true; setBackgroundColor( m_bg ); size_t endpos, endoffset; endpos = startpos; endoffset = startoffset; size_t currentpos = locate(); if (endpos >= m_startpos) { jumpto(m_startpos); for (int i = 0; i < m_startoffset; i++) { getch(); } wrdstart = buffdoc.explocate(); if (m_startpos == endpos) { for (int i = m_startoffset; i <= endoffset; i++) { wrd += QChar(getch()); } } else { while (buffdoc.explocate() <= endpos) { wrd += QChar(getch()); } for (int i = 0; i < endoffset; i++) { wrd += QChar(getch()); } } wrdend = buffdoc.explocate(); jumpto(currentpos); } } } else if (m_bMonoSpaced) { int chno = (m_rotated) ? (_e->y()-textarray[lineno]->offset(height(), m_left_border, m_right_border, availht))/m_charWidth : (_e->x()-textarray[lineno]->offset(width(), m_left_border, m_right_border, availht))/m_charWidth; if (chno < ustrlen(textarray[lineno]->data())) { wrd[0] = textarray[lineno]->data()[chno]; } } else { CDrawBuffer* t = textarray[lineno]; int first = 0; int tgt = (m_rotated) ? _e->y() - t->offset(height(), m_left_border, m_right_border, availht) : _e->x() - t->offset(width(), m_left_border, m_right_border, availht); while (1) { int i = first+1; int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; if (t->width(availht, i, true, (m_rotated) ? height() : width(), m_left_border, m_right_border) > tgt) { wrd = toQString(t->data()+first, i - first); // qDebug("Got %s", (const char *)wrd); break; } while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; if ((*t)[i] == 0) break; first = i; } } if (!wrd.isEmpty()) { qDebug("Selected:%s", (const char*)wrd); if (m_twotouch) { emit OnWordSelected(wrd, wrdstart, wrdend, wrd); } else { QString line = toQString(textarray[lineno]->data()); emit OnWordSelected(wrd, locnarray[lineno], locnarray[lineno]+line.length(), line); } } } #ifdef USETIMER void QTReader::actionDrag() { if (m_drageligible) { int fivepages = 5*((2*width()+m_textsize/2)/m_textsize)*((height()+m_textsize/2)/m_textsize); if (m_dragtarget > fivepages && locnarray[numlines] < m_dragtarget - fivepages) { int tgt = m_dragtarget - fivepages/2; //qDebug("Jumping to %u (%u)", tgt, fivepages); if (tgt < buffdoc.startSection()) { tgt = buffdoc.startSection(); } locate(tgt); drawFonts(); } else if (locnarray[0] > m_dragtarget+fivepages) { int tgt = m_dragtarget + fivepages/2; //qDebug("Jumping to %u (%u)", tgt, fivepages); if (tgt > buffdoc.endSection()) { dopageup(); } else { locate(tgt); drawFonts(); } } else if (locnarray[numlines] <= m_dragtarget) { dopagedn(); } else if (locnarray[0] > m_dragtarget) { dopageup(); } } else { m_dragtimer->stop(); } } #endif void QTReader::mouseMoveEvent( QMouseEvent* _e ) { if (m_drageligible) { int ht; int mp; int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); //qDebug("Mouse moved to (%u, %u)", _e->x(), _e->y()); switch (m_scrollpos) { case 1: { if (m_rotated) { ht = height(); mp = _e->y(); } else { ht = width(); mp = _e->x(); } } break; case 2: case 3: { if (m_rotated) { ht = width(); mp = width()-_e->x(); } else { ht = height(); mp = _e->y(); } } break; case 0: default: ht = -1; break; } if (ht >= 0) { #ifdef USETIMER m_dragtarget = (sectionsize*mp+ht/2)/ht + buffdoc.startSection(); if (!m_dragtimer->isActive()) { m_dragtimer->start(0, false); } #else int dp = (sectionsize*mp+ht/2)/ht + buffdoc.startSection(); locate(dp); #endif } } } void QTReader::mouseReleaseEvent( QMouseEvent* _e ) { qDebug("Mouse released at (%u, %u)", _e->x(), _e->y()); if (m_drageligible) { m_drageligible = false; } else { int x, y, ht, wh; if (m_rotated) { x = _e->y(); y = width()-_e->x(); ht = width(); wh = height(); } else { x = _e->x(); y = _e->y(); ht = height(); wh = width(); } if (_e->button() == LeftButton) { if (mouseUpOn) { // qDebug("MouseRelease"); /* switch(m_scrollpos) { case 1: // Bottom if (y > ht - 5) { locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh); return; } break; case 2: // right if (x > wh - m_right_border) { locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht); return; } break; case 3: // left if (x < m_left_border) { locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht); 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 @@ -452,513 +452,513 @@ void CPlucker_base::UnZip(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuff inflateEnd(&zstream); } */ size_t CPlucker_base::UnDoc(UInt8* compressedbuffer, size_t reclen, UInt8* tgtbuffer, size_t bsize) { // UInt16 headerSize; UInt16 docSize; UInt16 i; UInt16 j; UInt16 k; UInt8 *inBuf = compressedbuffer; UInt8 *outBuf = tgtbuffer; // headerSize = sizeof( Header ) + record->paragraphs * sizeof( Paragraph ); docSize = reclen; j = 0; k = 0; while ( j < docSize ) { i = 0; while ( i < bsize && j < docSize ) { UInt16 c; c = (UInt16) inBuf[ j++ ]; if ( 0 < c && c < 9 ) { while ( 0 < c-- ) outBuf[ i++ ] = inBuf[ j++ ]; } else if ( c < 0x80 ) outBuf[ i++ ] = c; else if ( 0xc0 <= c ) { outBuf[ i++ ] = ' '; outBuf[ i++ ] = c ^ 0x80; } else { Int16 m; Int16 n; c <<= 8; c += inBuf[ j++ ]; m = ( c & 0x3fff ) >> COUNT_BITS; n = c & ( ( 1 << COUNT_BITS ) - 1 ); n += 2; do { outBuf[ i ] = outBuf[ i - m ]; i++; } while ( 0 < n-- ); } } k += bsize; } return i; } void CPlucker_base::home() { currentpos = 0; expand(1); } CList<Bkmk>* CPlucker_base::getbkmklist() { /* UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; for (int i = 1; i < ntohs(head.recordList.numRecords); i++) { gotorecordnumber(i); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type == 8) { UInt16 n; fread(&n, 1, sizeof(n), fin); n = ntohs(n); //qDebug("Found %u bookmarks", n); } //qDebug("Found:%d, %u", i , thishdr_type); } */ return NULL; } #include <qnamespace.h> QImage* CPlucker_base::expandimg(UInt16 tgt, bool border) { QImage* qimage = getimg(tgt); QImage* ret; if (qimage == NULL) return NULL; if (border) { QPixmap* image = new QPixmap(0,0); image->convertFromImage(*qimage); delete qimage; QPixmap* pret = new QPixmap(image->width()+4, image->height()+4); pret->fill(Qt::red); bitBlt(pret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP); delete image; ret = new QImage(pret->convertToImage()); } else { ret = qimage; } return ret; } #ifdef _BUFFERPICS #include <qmap.h> #endif QImage* CPlucker_base::getPicture(unsigned long tgt) { #ifdef _BUFFERPICS static QMap<unsigned long, QPixmap> pix; QMap<unsigned long, QPixmap>::Iterator t = pix.find(tgt); if (t == pix.end()) { pix[tgt] = *expandimg(tgt); return &pix[tgt]; } else return &(t.data()); #else return expandimg(tgt >> 16); #endif } #ifdef LOCALPICTURES #include <unistd.h> #include <qpe/global.h> void CPlucker_base::showimg(UInt16 tgt) { //qDebug("Crassssssh!"); QPixmap* qimage = expandimg(tgt); m_picture->setFixedSize(qimage->size()); m_picture->setBackgroundPixmap(*qimage); delete qimage; m_viewer->show(); /* char tmp[] = "uqtreader.XXXXXX"; QImage* qimage = getimg(tgt); QPixmap* image = new QPixmap(0,0); // //qDebug("New image"); image->convertFromImage(*qimage); delete qimage; char tmpfile[sizeof(tmp)+1]; strcpy(tmpfile,tmp); int f = mkstemp(tmpfile); close(f); //qDebug("TMPFILE:%s", tmpfile); if (image->save(tmpfile,"PNG")) { QCopEnvelope e("QPE/Application/showimg", "setDocument(QString)"); e << QString(tmpfile); } Global::statusMessage("Opening image"); sleep(5); delete image; unlink(tmpfile); */ } #endif unsigned short CPlucker_base::finduid(unsigned short urlid) { // //qDebug("Finding %u", urlid); unsigned short jmin = 1, jmax = ntohs(head.recordList.numRecords); unsigned short jmid = (jmin+jmax) >> 1; while (jmax - jmin > 1) { gotorecordnumber(jmid); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); unsigned short luid = thishdr_uid; // //qDebug("%u %u %u : %u", jmin, jmid, jmax, urlid); if (luid == urlid) { return jmid; } if (luid < urlid) { jmin = jmid; } else { jmax = jmid; } jmid = (jmin+jmax) >> 1; } gotorecordnumber(jmin); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); unsigned short luid = thishdr_uid; //qDebug("jmin at end:%u,%u", jmin, luid); if (luid == urlid) { return jmin; } gotorecordnumber(jmax); GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); luid = thishdr_uid; //qDebug("jmax at end:%u,%u", jmax, luid); if (luid == urlid) { return jmax; } //qDebug("Couldn't find %u", urlid); return 0; // Not found! } #include <qnamespace.h> void CPlucker_base::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen) { unsigned short sz = 0; for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) { sz++; } size_t newlen = srclen+sizeof(sz)+sz*sizeof(unsigned long); unsigned char* newdata = new unsigned char[newlen]; unsigned char* pdata = newdata; memcpy(newdata, src, srclen); newdata += srclen; memcpy(newdata, &sz, sizeof(sz)); newdata += sizeof(sz); #ifdef _WINDOWS for (it = visited.begin(); it != visited.end(); it++) #else for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++) #endif { unsigned long t = *it; // qDebug("[%u]", t); memcpy(newdata, &t, sizeof(t)); newdata += sizeof(t); } m_nav.setSaveData(data, len, pdata, newlen); delete [] pdata; } void CPlucker_base::putSaveData(unsigned char*& src, unsigned short& srclen) { - unsigned short sz; + unsigned short sz = 0; if (srclen >= sizeof(sz)) { memcpy(&sz, src, sizeof(sz)); src += sizeof(sz); srclen -= sizeof(sz); } for (int i = 0; i < sz; i++) { unsigned long t; if (srclen >= sizeof(t)) { memcpy(&t, src, sizeof(t)); // qDebug("[%u]", t); visited.push_front(t); src += sizeof(t); srclen -= sizeof(t); } else { QMessageBox::warning(NULL, PROGNAME, "File data mismatch\nMight fix itself"); break; } } m_nav.putSaveData(src, srclen); } int CPlucker_base::OpenFile(const char *src) { qDebug("plucker openfile:%s", src); m_lastBreak = 0; if (!Cpdb::openpdbfile(src)) { return -1; } if (!CorrectDecoder()) return -1; gotorecordnumber(0); fread(&hdr0, 1, 6, fin); qDebug("Compression type:%u", ntohs(hdr0.version)); switch (ntohs(hdr0.version)) { case 2: m_decompress = UnZip; break; case 1: m_decompress = UnDoc; break; #ifdef USENEF case 3: m_decompress = getdecompressor("PluckerDecompress3"); break; case 4: m_decompress = getdecompressor("PluckerDecompress4"); break; #endif default: m_decompress = NULL; } if (m_decompress == NULL) return -1; setbuffersize(); compressedtextbuffer = new UInt8[compressedbuffersize]; expandedtextbuffer = new UInt8[buffersize]; unsigned int nrecs = ntohs(hdr0.nRecords); qDebug("Version %u, no. reserved recs %u", ntohs(hdr0.version), nrecs); textlength = ntohl(head.sortInfoID); qDebug("Textlength at startup:%u", textlength); UInt16 homerecid = 1; for (unsigned int i = 0; i < nrecs; i++) { UInt16 id, name; fread(&name, 1, sizeof(name), fin); fread(&id, 1, sizeof(id), fin); //qDebug("N:%d, I:%d", ntohs(name), ntohs(id)); if (ntohs(name) == 0) homerecid = ntohs(id); } textlength = 0; for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++) { gotorecordnumber(recptr); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_uid == homerecid) { m_homepos = textlength; break; } if (thishdr_type < 2) textlength += thishdr_size; } qDebug("Found home"); textlength = 0; home(); qDebug("Gone home"); #ifdef LOCALPICTURES if (m_viewer == NULL) { m_viewer = new QScrollView(NULL); m_picture = new QWidget(m_viewer->viewport()); m_viewer->addChild(m_picture); } #endif return 0; } QImage* CPlucker_base::getimg(UInt16 tgt) { size_t reclen; UInt16 thisrec = finduid(tgt); qDebug("getimg:Found %u from uid:%u", thisrec, tgt); reclen = recordlength(thisrec); gotorecordnumber(thisrec); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (thishdr_type == 15) { char *buffer = new char[thishdr_size]; fread(buffer, thishdr_size, sizeof(char), fin); unsigned short tmp; memcpy(&tmp, buffer, sizeof(tmp)); unsigned short cols = ntohs(tmp); memcpy(&tmp, buffer+sizeof(tmp), sizeof(tmp)); unsigned short rows = ntohs(tmp); qDebug("Found a picture of type:%u [%u,%u]", thishdr_type, rows, cols); QImage*** images; images = new QImage**[rows]; #ifdef _WINDOWS int i; for (i = 0; i < rows; i++) #else for (int i = 0; i < rows; i++) #endif { images[i] = new QImage*[cols]; } int height = 0; int width = 0; #ifdef _WINDOWS for (i = 0; i < rows; i++) #else for (int i = 0; i < rows; i++) #endif { width = 0; for (int j = 0; j < cols; j++) { memcpy(&tmp, buffer+(i*cols+j+2)*sizeof(tmp), sizeof(tmp)); unsigned short uid = ntohs(tmp); images[i][j] = getimg(uid); width += images[i][j]->width(); } height += images[i][0]->height(); } delete [] buffer; QPixmap pm(width, height); int hoffset = 0; #ifdef _WINDOWS for (i = 0; i < rows; i++) #else for (int i = 0; i < rows; i++) #endif { int woffset = 0; int delht = images[i][0]->height(); for (int j = 0; j < cols; j++) { QPixmap pm2; pm2.convertFromImage(*(images[i][j])); delete images[i][j]; bitBlt(&pm, woffset, hoffset, &pm2, 0, 0, pm2.width(), pm2.height()); woffset += pm2.width(); } hoffset += delht; } #ifdef _WINDOWS for (i = 0; i < rows; i++) #else for (int i = 0; i < rows; i++) #endif { delete [] images[i]; } delete [] images; return new QImage(pm.convertToImage()); } else { qDebug("Found a picture of type:%u", thishdr_type); reclen -= HeaderSize(); UInt32 imgsize = thishdr_size; UInt8* imgbuffer = new UInt8[imgsize]; Expand(reclen, thishdr_type, imgbuffer, imgsize); return imagefromdata(imgbuffer, imgsize); } } linkType CPlucker_base::hyperlink(unsigned int n, unsigned int offset, QString& wrd, QString&) { visited.push_front(n); UInt16 tuid = (n >> 16); n &= 0xffff; char *turl = geturl(tuid); if (turl != NULL) { qDebug("URL in PB:%s", turl); wrd = turl; delete [] turl; } else { wrd.truncate(0); } qDebug("Hyper: UID:%u, Para:%u, Offset:%u", tuid, n, offset); UInt16 thisrec = 1; currentpos = 0; gotorecordnumber(thisrec); UInt16 thishdr_uid, thishdr_nParagraphs; UInt32 thishdr_size; UInt8 thishdr_type, thishdr_reserved; while (1) { GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved); if (tuid == thishdr_uid) break; if (thishdr_type < 2) currentpos += thishdr_size; // //qDebug("hyper-cp:%u", currentpos); thisrec++; if (thisrec >= ntohs(head.recordList.numRecords)) { if (wrd.isEmpty()) { QMessageBox::information(NULL, QString(PROGNAME), QString("Couldn't find link") ); } else { #ifdef USEQPE if (wrd.length() > 10) { Global::statusMessage(wrd.left(8) + ".."); } else { 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 @@ -220,513 +220,513 @@ QString striphtml::dehtml(const QString& _info) if ('0' <= ch1 && ch1 <= '9') { ch += ch1 - '0'; } else if ('a' <= ch1 && ch1 <= 'f') { ch += ch1 - 'a' + 10; } else if ('A' <= ch1 && ch1 <= 'F') { ch += ch1 - 'A' + 10; } } } info += ch; } return info; } bool striphtml::findanchor(const QString& _info) { // QProgressDialog dlg("Finding link...", QString::null, 0, NULL, "progress", true); // QProgressBar dlg(0); if (parent->findanchor(_info)) { reset(); return true; } qDebug("Using html find"); parent->locate(parent->startSection()); #if defined(USEQPE) || defined(_WINDOWS) QString info; for (int i = 0; i < _info.length(); i++) { tchar ch = _info[i]; if (QString(".^$[]*+?").find(ch) != -1) { info += '\\'; } info += ch; } #else QString info = QRegExp::escape(_info); #endif qDebug("Adjusted searchstring:%s", (const char*)info); QString sname("<[Aa][^>]*[ \t]+[Nn][Aa][Mm][Ee][ \t]*=[ \t]*\"?"); sname += info + "\"?[ \t>]"; QString sid("<[A-Za-z][^>]*[ \t]+[Ii][Dd][ \t]*=[ \t]*\"?"); sid += info+"\"?[ \t>]"; #ifdef USEQPE QRegExp name(sname); QRegExp id(sid); #else QRegExp name(sname+"|"+sid); #endif bool ret = true; locate(0); unsigned long pos = 0; unsigned long startpos = 0; int offset; CBuffer test; qDebug("striphtml::findanchor"); // dlg.show(); if (getpara(test, pos) >= 0) { while (1) { // qApp->processEvents(); if ((offset = name.match(toQString(test.data()))) != -1) break; #ifdef USEQPE if ((offset = id.match(toQString(test.data()))) != -1) break; #endif if (getpara(test, pos) < 0) { locate(startpos); qDebug("Not found"); return false; } } locate(pos); qDebug("Found"); ret = true; } else { locate(startpos); qDebug("Not found"); ret = false; } return ret; } striphtml::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) { href2filepos = new QMap<QString, unsigned long>; id2href = new QMap<unsigned long, QString>; } striphtml::~striphtml() { if (entmap != NULL) delete entmap; delete href2filepos; delete id2href; } void striphtml::initentmap() { entmap = new QMap<QString, tchar>; #ifdef USEQPE #ifdef OPIE QString fname(getenv("OPIEDIR")); #else QString fname(getenv("QTDIR")); #endif fname += "/plugins/reader/data"; #else QString fname(getenv("READERDIR")); fname += "/data"; #endif QFileInfo fi; fi.setFile(fname, "HTMLentities"); if (fi.exists()) { fname = fi.absFilePath(); QFile fl(fname); if (fl.open(IO_ReadOnly)) { QTextStream t(&fl); QString key, value; while (!t.eof()) { QString data = t.readLine(); int colon = data.find(':'); if (colon > 0) { QString key = data.left(colon); QString value = data.right(data.length()-colon-1); bool ok; int ret = value.toInt(&ok); if (ok) { (*entmap)[key] = ret; } } } fl.close(); } } } unsigned short striphtml::skip_ws() { tchar ch; CStyle sty; unsigned long dummy; do { mygetch(ch, sty, dummy); } while (ch < 33 && ch != UEOF); return ch; } unsigned short striphtml::skip_ws_end() { unsigned long dummy; return skip_ws_end(dummy); } unsigned short striphtml::skip_ws_end(unsigned long& pos) { tchar ch; CStyle sty; do { mygetch(ch, sty, pos); } while (ch != '>' && ch != UEOF); return ch; } QString striphtml::getname(tchar& ch, const QString& nd) { QString nm = ""; // nm += ch; CStyle sty; unsigned long dummy; while (1) { // if ( QChar(ch).isLetterOrNumber() ) if (ch != UEOF && nd.find(ch, 0, false) == -1 && nm.length() < 2048) { nm += ch; } else { break; } mygetch(ch, sty, dummy); } return nm; } QString striphtml::getattr(tchar& ch) { QString ref; CStyle sty; unsigned long pos; if (ch == ' ') ch = skip_ws(); if (ch == '=') { ch = skip_ws(); if (ch == '"') { mygetch(ch, sty, pos); ref = getname(ch, "\""); ch = skip_ws(); } else if (ch == '\'') { mygetch(ch, sty, pos); ref = getname(ch, "\'"); ch = skip_ws(); } else { ref = getname(ch, " >"); if (ch == ' ') ch = skip_ws(); } } return ref; } linkType striphtml::hyperlink(unsigned int n, unsigned int, QString& w, QString& nm) { #if defined(USEQPE) || defined(_WINDOWS) QMap<unsigned long, QString>::Iterator hrefit = id2href->find(n); #else QMap<unsigned long, QString>::iterator hrefit = id2href->find(n); #endif if (hrefit == id2href->end()) { return eNone; } QString href = *hrefit; #if defined(USEQPE) || defined(_WINDOWS) QMap<QString, unsigned long>::Iterator fpit = href2filepos->find(href); #else QMap<QString, unsigned long>::iterator fpit = href2filepos->find(href); #endif if (fpit == href2filepos->end()) { if (href == "history.back()") { QString fc = currentfile; - unsigned long loc; + unsigned long loc = 0; htmlmark m(fc, loc); linkType ret = (m_nav.back(m)) ? eFile : eNone; if (fc == m.filename()) { if ((ret & eFile) != 0) { locate(m.posn()); return eLink; } } return eNone; } qDebug("Searching for %s", (const char*)href); QString file, name; int colon = href.find('#'); if (colon >= 0) { file = dehtml(href.left(colon)); name = dehtml(href.right(href.length()-colon-1)); } else { file = dehtml(href); } qDebug("File:%s", (const char*)file); qDebug("Name:%s", (const char*)name); if (file.isEmpty()) { if (parent->findanchor(name)) { reset(); return eLink; } fpit = href2filepos->find(name); if (fpit != href2filepos->end()) { locate(*fpit); return eLink; } else { // nm = QString("<a[^>]*name[ \t]*=[ \t]*\"") + name + "\""; qDebug("Do a search for:%s", (const char*)name); findanchor(name); return eLink; } } else // if (href.find('#') == -1) { if (m_bchm) { w = file; nm = name; return eFile; } else { QFileInfo f(currentfile); QFileInfo f1(f.dir(true), file); if (f1.exists()) { w = f1.absFilePath(); nm = name; } else { w = file; } return (f1.exists() ? eFile : eNone); } } return eNone; } locate(*fpit); // parent->locate((*href2filepos)[(*id2href)[n]]); return eLink; } /* unsigned short striphtml::parse_m() { tchar ch; CStyle sty; unsigned long dummy; mygetch(ch, sty, dummy); if (ch == 'm' || ch == 'M') { ch = skip_ws_end(); if (ch == '>') { return 0; } } return ch; } */ void striphtml::mygetch(tchar& ch, CStyle& sty, unsigned long& pos) { if (!text_q.isEmpty() && !m_inblock) { ch = text_q[0].unicode(); text_q = text_q.right(text_q.length()-1); } else { parent->getch(ch, sty, pos); if (ch == '<') { m_inblock = true; } if (ch == '>') { m_inblock = false; } } if (ch == 10 && !isPre) { #ifdef REMOVE_LF_BEFORE_ENDTAG parent->getch(ch, sty, pos); if (ch == '<') { parent->getch(ch, sty, pos); if (ch == '/') { ch = '<'; text_q += '/'; } else { text_q += '<'; text_q += ch; ch = ' '; } } else { text_q += ch; ch = ' '; } #else ch = ' '; #endif } } void striphtml::parse_paragraph(CStyle& currentstyle, tchar& ch, unsigned long pos) { /* int count = 0; for (CList<CStyle>::iterator iter = stylestack.begin(); iter != stylestack.end(); ++iter) { count++; } qDebug("Currently have %u styles", count); */ if (stylestack.isEmpty()) { currentstyle.unset(); } else { currentstyle = stylestack.first(); } if (forcecentre) { currentstyle.setCentreJustify(); } if (ch == ' ') ch = skip_ws(); while (ch != '>' && ch != UEOF) { QString ent = getname(ch, " =>").lower(); QString attr = getattr(ch).lower(); //qDebug("(Paragraph)Entity:%s Attr:%s", (const char*)ent, (const char*)attr); if (ent == "align") { if (attr == "center") { currentstyle.setCentreJustify(); } if (attr == "right") { currentstyle.setRightJustify(); } if (attr == "justify") { currentstyle.setFullJustify(); } } if (ent == "id") { (*href2filepos)[attr] = pos; } if (ent == "bgcolor") { qDebug("Got paper colour:%s", (const char*)attr); unsigned char r,g,b; parse_color(attr, r, g, b); currentstyle.setPaper(r, g, b); } if (ent == "color") { qDebug("Got foreground colour:%s", (const char*)attr); unsigned char r,g,b; parse_color(attr, r, g, b); currentstyle.setColour(r, g, b); } if (ch == ' ') ch = skip_ws(); } ch = 10; } void striphtml::getch(tchar& ch, CStyle& sty, unsigned long& pos) { currentstyle.clearPicture(); if (!q.isEmpty()) { ch = q[0].unicode(); if (ch == '-') { tchar w = q[1].unicode(); tchar h = q[2].unicode(); unsigned char r = q[3].unicode(); unsigned char g = q[4].unicode(); unsigned char b = q[5].unicode(); ch = '#'; //qDebug("html:hrule<%u, %u>", w, h); currentstyle.setPicture(false, hRule(w,h,r,g,b)); q = q.right(q.length()-6); } else { q = q.right(q.length()-1); } sty = currentstyle; lastch = ch; return; } do { unsigned long npos; CStyle dummy; mygetch(ch, dummy, pos); while (ch == '<' && ch != UEOF) { ch = skip_ws(); QString ent = getname(ch, " >").lower(); // qDebug("Entity:%s", (const char*)ent); 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 @@ -1063,406 +1063,408 @@ bool Highlight::isInWord(QChar c) /******************************************************************************************* Highlight - readCommentConfig This function is a helper for makeContextList. It parses the xml file for information, how single or multi line comments are marked * input: none ************* * output: none ************* * return value: none *******************************************************************************************/ void Highlight::readCommentConfig() { cslStart = ""; HlManager::self()->syntax->setIdentifier(identifier); syntaxContextData *data=HlManager::self()->syntax->getGroupInfo("general","comment"); if (data) { // kdDebug(13010)<<"COMMENT DATA FOUND"<<endl; while (HlManager::self()->syntax->nextGroup(data)) { if (HlManager::self()->syntax->groupData(data,"name")=="singleLine") cslStart=HlManager::self()->syntax->groupData(data,"start"); if (HlManager::self()->syntax->groupData(data,"name")=="multiLine") { cmlStart=HlManager::self()->syntax->groupData(data,"start"); cmlEnd=HlManager::self()->syntax->groupData(data,"end"); } } HlManager::self()->syntax->freeGroupInfo(data); } } /******************************************************************************************* Highlight - readGlobalKeyWordConfig This function is a helper for makeContextList. It parses the xml file for information, if keywords should be treated case(in)sensitive and creates the keyword delimiter list. Which is the default list, without any given weak deliminiators * input: none ************* * output: none ************* * return value: none *******************************************************************************************/ void Highlight::readGlobalKeywordConfig() { // Tell the syntax document class which file we want to parse HlManager::self()->syntax->setIdentifier(identifier); // Get the keywords config entry syntaxContextData * data=HlManager::self()->syntax->getConfig("general","keywords"); if (data) { kdDebug(13010)<<"Found global keyword config"<<endl; if (HlManager::self()->syntax->groupItemData(data,QString("casesensitive"))!="0") casesensitive=true; else {casesensitive=false; kdDebug(13010)<<"Turning on case insensitiveness"<<endl;} //get the weak deliminators weakDeliminator=(!HlManager::self()->syntax->groupItemData(data,QString("weakDeliminator"))); // remove any weakDelimitars (if any) from the default list and store this list. int f; for (int s=0; s < weakDeliminator.length(); s++) { f = 0; f = deliminator.find (weakDeliminator[s]); if (f > -1) deliminator.remove (f, 1); } deliminatorChars = deliminator.unicode(); deliminatorLen = deliminator.length(); HlManager::self()->syntax->freeGroupInfo(data); } else { //Default values casesensitive=true; weakDeliminator=QString(""); } } /******************************************************************************************* Highlight - makeContextList That's the most important initialization function for each highlighting. It's called each time a document gets a highlighting style assigned. parses the xml file and creates a corresponding internal structure * input: none ************* * output: none ************* * return value: none *******************************************************************************************/ void Highlight::makeContextList() { if (noHl) return; HlKeyword *keyword=0, *dataType=0; syntaxContextData *data, *datasub; HlItem *c; readCommentConfig(); readGlobalKeywordConfig(); // Let the syntax document class know, which file we'd like to parse HlManager::self()->syntax->setIdentifier(identifier); // This list is needed for the translation of the attribute parameter, if the itemData name is given instead of the index ItemDataList iDl; createItemData(iDl); //start the real work data=HlManager::self()->syntax->getGroupInfo("highlighting","context"); int i=0; if (data) { while (HlManager::self()->syntax->nextGroup(data)) { // BEGIN - Translation of the attribute parameter QString tmpAttr=HlManager::self()->syntax->groupData(data,QString("attribute")).simplifyWhiteSpace(); int attr; if (QString("%1").arg(tmpAttr.toInt())==tmpAttr) attr=tmpAttr.toInt(); else attr=lookupAttrName(tmpAttr,iDl); // END - Translation of the attribute parameter contextList[i]=new HlContext( attr, (HlManager::self()->syntax->groupData(data,QString("lineEndContext"))).toInt(), (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).isEmpty()?-1: (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).toInt()); //Let's create all items for the context while (HlManager::self()->syntax->nextItem(data)) { // kdDebug(13010)<< "In make Contextlist: Item:"<<endl; c=createHlItem(data,iDl); if (c) { contextList[i]->items.append(c); // Not supported completely atm and only one level. Subitems.(all have to be matched to at once) datasub=HlManager::self()->syntax->getSubItems(data); bool tmpbool; if (tmpbool=HlManager::self()->syntax->nextItem(datasub)) { c->subItems=new QList<HlItem>; for (;tmpbool;tmpbool=HlManager::self()->syntax->nextItem(datasub)) c->subItems->append(createHlItem(datasub,iDl)); } HlManager::self()->syntax->freeGroupInfo(datasub); // end of sublevel } // kdDebug(13010)<<"Last line in loop"<<endl; } i++; } } HlManager::self()->syntax->freeGroupInfo(data); } HlManager::HlManager() : QObject(0L) { syntax = new SyntaxDocument(); SyntaxModeList modeList = syntax->modeList(); hlList.setAutoDelete(true); hlList.append(new Highlight(0)); uint i=0; while (i < modeList.count()) { hlList.append(new Highlight(modeList.at(i))); i++; } } HlManager::~HlManager() { if(syntax) delete syntax; } HlManager *HlManager::self() { if ( !s_pSelf ) s_pSelf = new HlManager; return s_pSelf; } Highlight *HlManager::getHl(int n) { if (n < 0 || n >= (int) hlList.count()) n = 0; return hlList.at(n); } int HlManager::defaultHl() { KateConfig *config; config = KGlobal::config(); config->setGroup("General Options"); #warning fixme return nameFind(config->readEntry("Highlight")); } int HlManager::nameFind(const QString &name) { int z; for (z = hlList.count() - 1; z > 0; z--) { if (hlList.at(z)->iName == name) break; } return z; } int HlManager::wildcardFind(const QString &fileName) { Highlight *highlight; int p1, p2; QString w; for (highlight = hlList.first(); highlight != 0L; highlight = hlList.next()) { p1 = 0; w = highlight->getWildcards(); while (p1 < (int) w.length()) { p2 = w.find(';',p1); if (p2 == -1) p2 = w.length(); if (p1 < p2) { QRegExp regExp(w.mid(p1,p2 - p1),true,true); if (regExp.match(fileName) == 0) return hlList.at(); } p1 = p2 + 1; } } return -1; } int HlManager::makeAttribs(Highlight *highlight, Attribute *a, int maxAttribs) { ItemStyleList defaultStyleList; - ItemStyle *defaultStyle; + ItemStyle *defaultStyle = 0; ItemDataList itemDataList; ItemData *itemData; int nAttribs, z; odebug << "HlManager::makeAttribs" << oendl; defaultStyleList.setAutoDelete(true); getDefaults(defaultStyleList); // itemDataList.setAutoDelete(true); highlight->getItemDataList(itemDataList); nAttribs = itemDataList.count(); for (z = 0; z < nAttribs; z++) { - odebug << "HlManager::makeAttribs: createing one attribute definition" << oendl; + odebug << "HlManager::makeAttribs: creating an attribute definition" << oendl; itemData = itemDataList.at(z); if (itemData->defStyle) { // default style defaultStyle = defaultStyleList.at(itemData->defStyleNum); a[z].col = defaultStyle->col; a[z].selCol = defaultStyle->selCol; a[z].bold = defaultStyle->bold; a[z].italic = defaultStyle->italic; } else { // custom style a[z].col = itemData->col; a[z].selCol = itemData->selCol; a[z].bold = itemData->bold; a[z].italic = itemData->italic; } } for (; z < maxAttribs; z++) { a[z].col = black; a[z].selCol = black; + if (defaultStyle) { a[z].bold = defaultStyle->bold; a[z].italic = defaultStyle->italic; } + } return nAttribs; } int HlManager::defaultStyles() { return 10; } QString HlManager::defaultStyleName(int n) { static QStringList names; if (names.isEmpty()) { names << i18n("Normal"); names << i18n("Keyword"); names << i18n("Data Type"); names << i18n("Decimal/Value"); names << i18n("Base-N Integer"); names << i18n("Floating Point"); names << i18n("Character"); names << i18n("String"); names << i18n("Comment"); names << i18n("Others"); } return names[n]; } void HlManager::getDefaults(ItemStyleList &list) { KateConfig *config; int z; ItemStyle *i; QString s; QRgb col, selCol; list.setAutoDelete(true); //ItemStyle(color, selected color, bold, italic) list.append(new ItemStyle(black,white,false,false)); //normal list.append(new ItemStyle(black,white,true,false)); //keyword list.append(new ItemStyle(darkRed,white,false,false)); //datatype list.append(new ItemStyle(blue,cyan,false,false)); //decimal/value list.append(new ItemStyle(darkCyan,cyan,false,false)); //base n list.append(new ItemStyle(darkMagenta,cyan,false,false));//float list.append(new ItemStyle(magenta,magenta,false,false)); //char list.append(new ItemStyle(red,red,false,false)); //string list.append(new ItemStyle(darkGray,gray,false,true)); //comment list.append(new ItemStyle(darkGreen,green,false,false)); //others #warning fixme /* config = KateFactory::instance()->config(); config->setGroup("Default Item Styles"); for (z = 0; z < defaultStyles(); z++) { i = list.at(z); s = config->readEntry(defaultStyleName(z)); if (!s.isEmpty()) { sscanf(s.latin1(),"%X,%X,%d,%d",&col,&selCol,&i->bold,&i->italic); i->col.setRgb(col); i->selCol.setRgb(selCol); } } */ } void HlManager::setDefaults(ItemStyleList &list) { KateConfig *config; int z; ItemStyle *i; char s[64]; #warning fixme /* config = KateFactory::instance()->config(); config->setGroup("Default Item Styles"); for (z = 0; z < defaultStyles(); z++) { i = list.at(z); sprintf(s,"%X,%X,%d,%d",i->col.rgb(),i->selCol.rgb(),i->bold, i->italic); config->writeEntry(defaultStyleName(z),s); } */ emit changed(); } int HlManager::highlights() { return (int) hlList.count(); } QString HlManager::hlName(int n) { return hlList.at(n)->iName; } QString HlManager::hlSection(int n) { return hlList.at(n)->iSection; } void HlManager::getHlDataList(HlDataList &list) { int z; for (z = 0; z < (int) hlList.count(); z++) { list.append(hlList.at(z)->getData()); } } void HlManager::setHlDataList(HlDataList &list) { int z; for (z = 0; z < (int) hlList.count(); z++) { hlList.at(z)->setData(list.at(z)); } //notify documents about changes in highlight configuration emit changed(); } 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 @@ -528,513 +528,513 @@ GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) { net_close(sControl); free(ctrl->buf); free(ctrl); return 0; } *nControl = ctrl; return 1; } /* * FtpOptions - change connection options * * returns 1 if successful, 0 on error */ GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl) { int v,rv=0; switch (opt) { case FTPLIB_CONNMODE: v = (int) val; if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT)) { nControl->cmode = v; rv = 1; } break; case FTPLIB_CALLBACK: nControl->idlecb = (FtpCallback) val; rv = 1; break; case FTPLIB_IDLETIME: v = (int) val; rv = 1; nControl->idletime.tv_sec = v / 1000; nControl->idletime.tv_usec = (v % 1000) * 1000; break; case FTPLIB_CALLBACKARG: rv = 1; nControl->idlearg = (void *) val; break; case FTPLIB_CALLBACKBYTES: rv = 1; nControl->cbbytes = (int) val; break; } return rv; } /* * FtpSendCmd - send a command and wait for expected response * * return 1 if proper response received, 0 otherwise */ static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl) { char buf[256]; if (nControl->dir != FTPLIB_CONTROL) return 0; if (ftplib_debug > 2) fprintf(stderr,"%s\n",cmd); if ((strlen(cmd) + 3) > sizeof(buf)) return 0; sprintf(buf,"%s\r\n",cmd); if (net_write(nControl->handle,buf,strlen(buf)) <= 0) { perror("write"); return 0; } return readresp(expresp, nControl); } /* * FtpLogin - log in to remote server * * return 1 if logged in, 0 otherwise */ GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl) { char tempbuf[64]; if (((strlen(user) + 7) > sizeof(tempbuf)) || ((strlen(pass) + 7) > sizeof(tempbuf))) return 0; sprintf(tempbuf,"USER %s",user); if (!FtpSendCmd(tempbuf,'3',nControl)) { if (nControl->response[0] == '2') return 1; return 0; } sprintf(tempbuf,"PASS %s",pass); return FtpSendCmd(tempbuf,'2',nControl); } /* * FtpOpenPort - set up data connection * * return 1 if successful, 0 otherwise */ static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir) { int sData; union { struct sockaddr sa; struct sockaddr_in in; } sin; struct linger lng = { 0, 0 }; unsigned int l; int on=1; netbuf *ctrl; char *cp; unsigned int v[6]; char buf[256]; if (nControl->dir != FTPLIB_CONTROL) return -1; if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE)) { sprintf(nControl->response, "Invalid direction %d\n", dir); return -1; } if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE)) { sprintf(nControl->response, "Invalid mode %c\n", mode); return -1; } l = sizeof(sin); if (nControl->cmode == FTPLIB_PASSIVE) { memset(&sin, 0, l); sin.in.sin_family = AF_INET; if (!FtpSendCmd("PASV",'2',nControl)) return -1; cp = strchr(nControl->response,'('); if (cp == NULL) return -1; cp++; sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]); sin.sa.sa_data[2] = v[2]; sin.sa.sa_data[3] = v[3]; sin.sa.sa_data[4] = v[4]; sin.sa.sa_data[5] = v[5]; sin.sa.sa_data[0] = v[0]; sin.sa.sa_data[1] = v[1]; } else { if (getsockname(nControl->handle, &sin.sa, &l) < 0) { perror("getsockname"); return 0; } } sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); if (sData == -1) { perror("socket"); return -1; } if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR, SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1) { perror("setsockopt"); net_close(sData); return -1; } if (setsockopt(sData,SOL_SOCKET,SO_LINGER, SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1) { perror("setsockopt"); net_close(sData); return -1; } if (nControl->cmode == FTPLIB_PASSIVE) { if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1) { perror("connect"); net_close(sData); return -1; } } else { sin.in.sin_port = 0; if (bind(sData, &sin.sa, sizeof(sin)) == -1) { perror("bind"); net_close(sData); return 0; } if (listen(sData, 1) < 0) { perror("listen"); net_close(sData); return 0; } if (getsockname(sData, &sin.sa, &l) < 0) return 0; sprintf(buf, "PORT %d,%d,%d,%d,%d,%d", (unsigned char) sin.sa.sa_data[2], (unsigned char) sin.sa.sa_data[3], (unsigned char) sin.sa.sa_data[4], (unsigned char) sin.sa.sa_data[5], (unsigned char) sin.sa.sa_data[0], (unsigned char) sin.sa.sa_data[1]); if (!FtpSendCmd(buf,'2',nControl)) { net_close(sData); return 0; } } ctrl = calloc(1,sizeof(netbuf)); if (ctrl == NULL) { perror("calloc"); net_close(sData); return -1; } if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL)) { perror("calloc"); net_close(sData); free(ctrl); return -1; } ctrl->handle = sData; ctrl->dir = dir; ctrl->idletime = nControl->idletime; ctrl->idlearg = nControl->idlearg; ctrl->xfered = 0; ctrl->xfered1 = 0; ctrl->cbbytes = nControl->cbbytes; if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes) ctrl->idlecb = nControl->idlecb; else ctrl->idlecb = NULL; *nData = ctrl; return 1; } /* * FtpAcceptConnection - accept connection from server * * return 1 if successful, 0 otherwise */ static int FtpAcceptConnection(netbuf *nData, netbuf *nControl) { int sData; struct sockaddr addr; unsigned int l; int i; struct timeval tv; fd_set mask; - int rv; + int rv = 1; FD_ZERO(&mask); FD_SET(nControl->handle, &mask); FD_SET(nData->handle, &mask); tv.tv_usec = 0; tv.tv_sec = ACCEPT_TIMEOUT; printf("<<<<<<<<<<<<<<<<%d\n",ACCEPT_TIMEOUT); i = nControl->handle; if (i < nData->handle) i = nData->handle; i = select(i+1, &mask, NULL, NULL, &tv); if (i == -1) { strncpy(nControl->response, strerror(errno), sizeof(nControl->response)); net_close(nData->handle); nData->handle = 0; rv = 0; } else if (i == 0) { strcpy(nControl->response, "timed out waiting for connection"); net_close(nData->handle); nData->handle = 0; rv = 0; } else { if (FD_ISSET(nData->handle, &mask)) { l = sizeof(addr); sData = accept(nData->handle, &addr, &l); i = errno; net_close(nData->handle); if (sData > 0) { rv = 1; nData->handle = sData; } else { strncpy(nControl->response, strerror(i), sizeof(nControl->response)); nData->handle = 0; rv = 0; } } else if (FD_ISSET(nControl->handle, &mask)) { net_close(nData->handle); nData->handle = 0; readresp('2', nControl); rv = 0; } } return rv; } /* * FtpAccess - return a handle for a data stream * * return 1 if successful, 0 otherwise */ GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl, netbuf **nData) { char buf[256]; int dir; if ((path == NULL) && ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ))) { sprintf(nControl->response, "Missing path argument for file transfer\n"); return 0; } sprintf(buf, "TYPE %c", mode); if (!FtpSendCmd(buf, '2', nControl)) return 0; switch (typ) { case FTPLIB_DIR: strcpy(buf,"NLST"); dir = FTPLIB_READ; break; case FTPLIB_DIR_VERBOSE: strcpy(buf,"LIST"); dir = FTPLIB_READ; break; case FTPLIB_FILE_READ: strcpy(buf,"RETR"); dir = FTPLIB_READ; break; case FTPLIB_FILE_WRITE: strcpy(buf,"STOR"); dir = FTPLIB_WRITE; break; default: sprintf(nControl->response, "Invalid open type %d\n", typ); return 0; } if (path != NULL) { int i = strlen(buf); buf[i++] = ' '; if ((strlen(path) + i) >= sizeof(buf)) return 0; strcpy(&buf[i],path); } if (FtpOpenPort(nControl, nData, mode, dir) == -1) return 0; if (!FtpSendCmd(buf, '1', nControl)) { FtpClose(*nData); *nData = NULL; return 0; } (*nData)->ctrl = nControl; nControl->data = *nData; if (nControl->cmode == FTPLIB_PORT) { if (!FtpAcceptConnection(*nData,nControl)) { FtpClose(*nData); *nData = NULL; nControl->data = NULL; return 0; } } return 1; } /* * FtpRead - read from a data connection */ GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData) { int i; if (nData->dir != FTPLIB_READ) return 0; if (nData->buf) i = readline(buf, max, nData); else { i = socket_wait(nData); if (i != 1) return 0; i = net_read(nData->handle, buf, max); } if (i == -1) return 0; nData->xfered += i; if (nData->idlecb && nData->cbbytes) { nData->xfered1 += i; if (nData->xfered1 > nData->cbbytes) { if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0) return 0; nData->xfered1 = 0; } } return i; } /* * FtpWrite - write to a data connection */ GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData) { int i; if (nData->dir != FTPLIB_WRITE) return 0; if (nData->buf) i = writeline(buf, len, nData); else { if (socket_wait(nData) < 0) fprintf(stderr, "FtpWrite: socket_wait failed with %s\n", nData->ctrl->response); i = net_write(nData->handle, buf, len); } if (i == -1) return 0; nData->xfered += i; if (nData->idlecb && nData->cbbytes) { nData->xfered1 += i; if (nData->xfered1 > nData->cbbytes) { nData->idlecb(nData, nData->xfered, nData->idlearg); nData->xfered1 = 0; } } return i; } /* * FtpClose - close a data connection */ GLOBALDEF int FtpClose(netbuf *nData) { netbuf *ctrl; switch (nData->dir) { case FTPLIB_WRITE: /* potential problem - if buffer flush fails, how to notify user? */ if (nData->buf != NULL) writeline(NULL, 0, nData); case FTPLIB_READ: if (nData->buf) free(nData->buf); shutdown(nData->handle,2); net_close(nData->handle); ctrl = nData->ctrl; free(nData); if (ctrl) { ctrl->data = NULL; return(readresp('2', ctrl)); } return 1; case FTPLIB_CONTROL: if (nData->data) { nData->ctrl = NULL; FtpClose(nData); } net_close(nData->handle); free(nData); return 0; } return 1; } /* * FtpSite - send a SITE command * * return 1 if command successful, 0 otherwise */ GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl) { char buf[256]; if ((strlen(cmd) + 7) > sizeof(buf)) return 0; sprintf(buf,"SITE %s",cmd); if (!FtpSendCmd(buf,'2',nControl)) return 0; return 1; } /* * FtpSysType - send a SYST command * * Fills in the user buffer with the remote system type. If more * information from the response is required, the user can parse * it out of the response buffer returned by FtpLastResponse(). 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 @@ -319,513 +319,513 @@ double dtime() { double q; timesu(&rusage); q = (double)(rusage.tms_utime) * 1.0e-06; return q; } #endif /**********************************************/ /* Macintosh (MAC_TMgr) Think C dtime() */ /* requires Think C Language Extensions or */ /* #include <MacHeaders> in the prefix */ /* provided by Francis H Schiffer 3rd (fhs) */ /* skipschiffer@genie.geis.com */ /**********************************************/ #ifdef MAC_TMgr #include <Timer.h> #include <stdlib.h> static TMTask mgrTimer; static Boolean mgrInited = false; static double mgrClock; #define RMV_TIMER RmvTime( (QElemPtr)&mgrTimer ) #define MAX_TIME 1800000000L /* MAX_TIME limits time between calls to */ /* dtime( ) to no more than 30 minutes */ /* this limitation could be removed by */ /* creating a completion routine to sum */ /* 30 minute segments (fhs 1994 feb 9) */ static void Remove_timer( ) { RMV_TIMER; mgrInited = false; } double dtime( ) { if( mgrInited ) { RMV_TIMER; mgrClock += (MAX_TIME + mgrTimer.tmCount)*1.0e-6; } else { if( _atexit( &Remove_timer ) == 0 ) mgrInited = true; mgrClock = 0.0; } if ( mgrInited ) { mgrTimer.tmAddr = NULL; mgrTimer.tmCount = 0; mgrTimer.tmWakeUp = 0; mgrTimer.tmReserved = 0; InsTime( (QElemPtr)&mgrTimer ); PrimeTime( (QElemPtr)&mgrTimer, -MAX_TIME ); } return( mgrClock ); } #endif /***********************************************************/ /* Parsytec GCel timer. */ /* Provided by: Georg Wambach, gw@informatik.uni-koeln.de */ /***********************************************************/ #ifdef PARIX #include <sys/time.h> double dtime() { double q; q = (double) (TimeNowHigh()) / (double) CLK_TCK_HIGH; return q; } #endif /************************************************/ /* Sun Solaris POSIX dtime() routine */ /* Provided by: Case Larsen, CTLarsen.lbl.gov */ /************************************************/ #ifdef POSIX #include <sys/time.h> #include <sys/resource.h> #include <sys/rusage.h> #ifdef __hpux #include <sys/syscall.h> #endif struct rusage rusage; double dtime() { double q; getrusage(RUSAGE_SELF,&rusage); q = (double)(rusage.ru_utime.tv_sec); q = q + (double)(rusage.ru_utime.tv_nsec) * 1.0e-09; return q; } #endif /****************************************************/ /* Windows NT (32 bit) dtime() routine */ /* Provided by: Piers Haken, piersh@microsoft.com */ /****************************************************/ #ifdef WIN32 #include <windows.h> double dtime(void) { double q; q = (double)GetTickCount() * 1.0e-03; return q; } #endif /*****************************************************/ /* Time according to POSIX.1 - <J.Pelan@qub.ac.uk> */ /* Ref: "POSIX Programmer's Guide" O'Reilly & Assoc.*/ /*****************************************************/ #ifdef POSIX1 #define _POSIX_SOURCE 1 #include <unistd.h> #include <limits.h> #include <sys/times.h> struct tms tms; double dtime() { double q; times(&tms); q = (double)tms.tms_utime / (double)CLK_TCK; return q; } #endif /* ************************************************************************* * * "DHRYSTONE" Benchmark Program * ----------------------------- * * Version: C, Version 2.1 * * File: dhry_1.c (part 2 of 3) * * Date: May 25, 1988 * * Author: Reinhold P. Weicker * ************************************************************************* */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "dhry.h" /* Global Variables: */ Rec_Pointer Ptr_Glob, Next_Ptr_Glob; int Int_Glob; Boolean Bool_Glob; char Ch_1_Glob, Ch_2_Glob; int Arr_1_Glob [50]; int Arr_2_Glob [50] [50]; char Reg_Define[32] = "Register option selected."; //extern char *malloc (); Enumeration Func_1 (); /* forward declaration necessary since Enumeration may not simply be int */ #ifndef ROPT #define REG /* REG becomes defined as empty */ /* i.e. no register variables */ #else #define REG register #endif /* variables for time measurement: */ #define Too_Small_Time 2 /* Measurements should last at least 2 seconds */ double Begin_Time, End_Time, User_Time; double Microseconds, Dhrystones_Per_Second, Vax_Mips; /* end of variables for time measurement */ /**********************************************************************************************/ Proc_1 (Ptr_Val_Par) /******************/ REG Rec_Pointer Ptr_Val_Par; /* executed once */ { REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; /* == Ptr_Glob_Next */ /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */ /* corresponds to "rename" in Ada, "with" in Pascal */ structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); Ptr_Val_Par->variant.var_1.Int_Comp = 5; Next_Record->variant.var_1.Int_Comp = Ptr_Val_Par->variant.var_1.Int_Comp; Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp; Proc_3 (&Next_Record->Ptr_Comp); /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp == Ptr_Glob->Ptr_Comp */ if (Next_Record->Discr == Ident_1) /* then, executed */ { Next_Record->variant.var_1.Int_Comp = 6; Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, &Next_Record->variant.var_1.Enum_Comp); Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp; Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, &Next_Record->variant.var_1.Int_Comp); } else /* not executed */ structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp); } /* Proc_1 */ Proc_2 (Int_Par_Ref) /******************/ /* executed once */ /* *Int_Par_Ref == 1, becomes 4 */ One_Fifty *Int_Par_Ref; { One_Fifty Int_Loc; - Enumeration Enum_Loc; + Enumeration Enum_Loc = Ident_2; Int_Loc = *Int_Par_Ref + 10; do /* executed once */ if (Ch_1_Glob == 'A') /* then, executed */ { Int_Loc -= 1; *Int_Par_Ref = Int_Loc - Int_Glob; Enum_Loc = Ident_1; } /* if */ while (Enum_Loc != Ident_1); /* true */ } /* Proc_2 */ Proc_3 (Ptr_Ref_Par) /******************/ /* executed once */ /* Ptr_Ref_Par becomes Ptr_Glob */ Rec_Pointer *Ptr_Ref_Par; { if (Ptr_Glob != Null) /* then, executed */ *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp; Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp); } /* Proc_3 */ Proc_4 () /* without parameters */ /*******/ /* executed once */ { Boolean Bool_Loc; Bool_Loc = Ch_1_Glob == 'A'; Bool_Glob = Bool_Loc | Bool_Glob; Ch_2_Glob = 'B'; } /* Proc_4 */ Proc_5 () /* without parameters */ /*******/ /* executed once */ { Ch_1_Glob = 'A'; Bool_Glob = false; } /* Proc_5 */ /* Procedure for the assignment of structures, */ /* if the C compiler doesn't support this feature */ #ifdef NOSTRUCTASSIGN memcpy (d, s, l) register char *d; register char *s; register int l; { while (l--) *d++ = *s++; } #endif Proc_6 (Enum_Val_Par, Enum_Ref_Par) /*********************************/ /* executed once */ /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */ Enumeration Enum_Val_Par; Enumeration *Enum_Ref_Par; { *Enum_Ref_Par = Enum_Val_Par; if (! Func_3 (Enum_Val_Par)) /* then, not executed */ *Enum_Ref_Par = Ident_4; switch (Enum_Val_Par) { case Ident_1: *Enum_Ref_Par = Ident_1; break; case Ident_2: if (Int_Glob > 100) /* then */ *Enum_Ref_Par = Ident_1; else *Enum_Ref_Par = Ident_4; break; case Ident_3: /* executed */ *Enum_Ref_Par = Ident_2; break; case Ident_4: break; case Ident_5: *Enum_Ref_Par = Ident_3; break; } /* switch */ } /* Proc_6 */ Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref) /**********************************************/ /* executed three times */ /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */ /* Int_Par_Ref becomes 7 */ /* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */ /* Int_Par_Ref becomes 17 */ /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */ /* Int_Par_Ref becomes 18 */ One_Fifty Int_1_Par_Val; One_Fifty Int_2_Par_Val; One_Fifty *Int_Par_Ref; { One_Fifty Int_Loc; Int_Loc = Int_1_Par_Val + 2; *Int_Par_Ref = Int_2_Par_Val + Int_Loc; } /* Proc_7 */ Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val) /*********************************************************************/ /* executed once */ /* Int_Par_Val_1 == 3 */ /* Int_Par_Val_2 == 7 */ Arr_1_Dim Arr_1_Par_Ref; Arr_2_Dim Arr_2_Par_Ref; int Int_1_Par_Val; int Int_2_Par_Val; { REG One_Fifty Int_Index; REG One_Fifty Int_Loc; Int_Loc = Int_1_Par_Val + 5; Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val; Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc]; Arr_1_Par_Ref [Int_Loc+30] = Int_Loc; for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index) Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc; Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1; Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc]; Int_Glob = 5; } /* Proc_8 */ Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val) /*************************************************/ /* executed three times */ /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */ /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */ /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */ Capital_Letter Ch_1_Par_Val; Capital_Letter Ch_2_Par_Val; { Capital_Letter Ch_1_Loc; Capital_Letter Ch_2_Loc; Ch_1_Loc = Ch_1_Par_Val; Ch_2_Loc = Ch_1_Loc; if (Ch_2_Loc != Ch_2_Par_Val) /* then, executed */ return (Ident_1); else /* not executed */ { Ch_1_Glob = Ch_1_Loc; return (Ident_2); } } /* Func_1 */ Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref) /*************************************************/ /* executed once */ /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */ /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */ Str_30 Str_1_Par_Ref; Str_30 Str_2_Par_Ref; { REG One_Thirty Int_Loc; Capital_Letter Ch_Loc; Int_Loc = 2; while (Int_Loc <= 2) /* loop body executed once */ if (Func_1 (Str_1_Par_Ref[Int_Loc], Str_2_Par_Ref[Int_Loc+1]) == Ident_1) /* then, executed */ { Ch_Loc = 'A'; Int_Loc += 1; } /* if, while */ if (Ch_Loc >= 'W' && Ch_Loc < 'Z') /* then, not executed */ Int_Loc = 7; if (Ch_Loc == 'R') /* then, not executed */ return (true); else /* executed */ { if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0) /* then, not executed */ { Int_Loc += 7; Int_Glob = Int_Loc; return (true); } else /* executed */ return (false); } /* if Ch_Loc */ } /* Func_2 */ Boolean Func_3 (Enum_Par_Val) /***************************/ /* executed once */ /* Enum_Par_Val == Ident_3 */ Enumeration Enum_Par_Val; { Enumeration Enum_Loc; Enum_Loc = Enum_Par_Val; if (Enum_Loc == Ident_3) /* then, executed */ return (true); else /* not executed */ return (false); } /* Func_3 */ /*********************************************************************************/ double dhry_main( int n ) /*****/ /* main program, corresponds to procedures */ /* Main and Proc_0 in the Ada version */ { One_Fifty Int_1_Loc; REG One_Fifty Int_2_Loc; One_Fifty Int_3_Loc; REG char Ch_Index; Enumeration Enum_Loc; Str_30 Str_1_Loc; Str_30 Str_2_Loc; REG int Run_Index; REG int Number_Of_Runs; FILE *Ap; /* Initializations */ /* if ((Ap = fopen("dhry.res","a+")) == NULL) { printf("Can not open dhry.res\n\n"); exit(1); } */ Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type)); Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type)); |