summaryrefslogtreecommitdiff
authorar <ar>2004-05-27 22:04:46 (UTC)
committer ar <ar>2004-05-27 22:04:46 (UTC)
commit4f7c3c4d0d634706d13950b3827714b168e279e3 (patch) (side-by-side diff)
tree2df448e7a4dcd538c26365873e194be2b55e83b7
parent46f81a089ba8febdb79e0d150b69f74bb1ea7d18 (diff)
downloadopie-4f7c3c4d0d634706d13950b3827714b168e279e3.zip
opie-4f7c3c4d0d634706d13950b3827714b168e279e3.tar.gz
opie-4f7c3c4d0d634706d13950b3827714b168e279e3.tar.bz2
- convert qDebug to odebug
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/keyz-cfg/zkb.cpp26
-rw-r--r--noncore/apps/opie-gutenbrowser/gutenbrowser.cpp15
-rw-r--r--noncore/apps/opie-reader/BuffDoc.h2
-rw-r--r--noncore/apps/opie-reader/CEncoding.h4
-rw-r--r--noncore/apps/opie-reader/CExpander.h0
-rw-r--r--noncore/apps/opie-reader/Filedata.h4
-rw-r--r--noncore/apps/opie-reader/FontControl.h4
-rw-r--r--noncore/apps/opie-reader/Palm2QImage.cpp55
-rw-r--r--noncore/apps/opie-reader/QTReader.h12
-rw-r--r--noncore/apps/opie-reader/QTReaderApp.h4
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.h2
-rw-r--r--noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp80
12 files changed, 114 insertions, 94 deletions
diff --git a/noncore/apps/keyz-cfg/zkb.cpp b/noncore/apps/keyz-cfg/zkb.cpp
index 58bde2a..c9e1dc5 100644
--- a/noncore/apps/keyz-cfg/zkb.cpp
+++ b/noncore/apps/keyz-cfg/zkb.cpp
@@ -1,589 +1,589 @@
#include "zkb.h"
+
+/* OPIE */
+#include <opie2/odebug.h>
+
#include <stdio.h>
// Implementation of Action class
Action::Action():state(0), keycode(0), unicode(0), flags(0) {
}
Action::Action(State* s, ushort kc, ushort uni, int f):
state(s), keycode(kc), unicode(uni), flags(f) {
}
Action::~Action() {
}
State* Action::getState() const {
return state;
}
void Action::setState(State* s) {
state = s;
setDefined(true);
}
bool Action::hasEvent() const {
return flags & Event;
}
void Action::setEvent(bool e) {
flags = (flags & ~Event) | ((e) ? Event : 0);
if (e) {
setDefined(true);
} else {
if (state == 0) {
setDefined(false);
}
}
}
bool Action::isDefined() const {
return flags & Defined;
}
void Action::setDefined(bool d) {
flags = (flags & ~Defined) | ((d) ? Defined : 0);
}
int Action::getKeycode() const {
return keycode;
}
void Action::setKeycode(int c) {
keycode = (ushort) c;
setEvent(true);
}
int Action::getUnicode() const {
return unicode;
}
void Action::setUnicode(int u) {
unicode = (ushort) u;
setEvent(true);
}
int Action::getModifiers() const {
int ret = 0;
if (flags & Shift_Mod) {
ret |= Qt::ShiftButton;
}
if (flags & Ctrl_Mod) {
ret |= Qt::ControlButton;
}
if (flags & Alt_Mod) {
ret |= Qt::AltButton;
}
if (flags & Keypad_Mod) {
ret |= Qt::Keypad;
}
return ret;
}
void Action::setModifiers(int m) {
int n = 0;
if (m & Qt::ShiftButton) {
n |= Shift_Mod;
}
if (m & Qt::ControlButton) {
n |= Ctrl_Mod;
}
if (m & Qt::AltButton) {
n |= Alt_Mod;
}
if (m & Qt::Keypad) {
n |= Keypad_Mod;
}
flags = flags & ~Mod_Bits | n;
setEvent(true);
}
bool Action::isPressed() const {
return (flags & Press) != 0;
}
void Action::setPressed(bool p) {
flags = (flags & ~Press) | ((p) ? Press : 0);
setEvent(true);
}
bool Action::isAutorepeat() const {
return (flags & Autorepeat) != 0;
}
void Action::setAutorepeat(bool p) {
flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0);
setEvent(true);
}
// Implementation of State class
const short State::x1[] = { /* from 0x20 to 0x5f */
31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */
11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */
15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */
8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */
18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */
7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */
15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */
23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */
31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */
-1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */
};
const short State::x2[] = { /* from 0x1000 to 0x1057*/
42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */
-1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */
33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */
-1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */
37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */
-1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */
-1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */
43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */
};
State::State(State* p):parent(p), keys(0) {
keys = new Action[Key_Max * 2 + 1];
}
State::State(const State& s) {
parent = s.parent;
keys = new Action[Key_Max * 2 + 1];
memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1));
}
State::~State() {
if (keys!=0) {
delete [] keys;
}
}
Action* State::get(int keycode, bool pressed, bool follow) const {
Action* ret = 0;
int n = translateKeycode(keycode);
if (n != -1 && keys != 0) {
if (pressed) {
n += Key_Max;
}
ret = &keys[n];
}
if (ret==0 || !ret->isDefined()) {
if (follow && parent!=0) {
ret = parent->get(keycode, pressed, follow);
}
}
return ret;
}
bool State::set(int keycode, bool pressed, Action& action) {
int n = translateKeycode(keycode);
if (n==-1 || keys==0) {
return false;
}
if (pressed) {
n += Key_Max + 1;
}
keys[n] = action;
return true;
}
State* State::getParent() const {
return parent;
}
void State::setParent(State* s) {
parent = s;
}
int State::translateKeycode(int keycode) const {
if (keycode < 0x20) {
return -1;
}
if (keycode < 0x80) {
return x1[keycode - 0x20];
}
if (keycode < 0x1000) {
return -1;
}
if (keycode < 0x1057) {
return x2[keycode - 0x1000];
}
return -1;
}
// Implementation of Keymap class
Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) {
repeatDelay=400;
repeatPeriod=80;
connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat()));
}
Keymap::~Keymap() {
QMap<QString, State*>::Iterator it;
for(it = states.begin(); it != states.end(); ++it) {
delete it.data();
}
states.clear();
}
bool Keymap::filter(int unicode, int keycode, int modifiers,
bool isPress, bool autoRepeat) {
- qDebug("filter: >>> unicode=%x, keycode=%x, modifiers=%x, "
- "ispressed=%x\n", unicode, keycode, modifiers, isPress);
+ odebug << "filter: >>> unicode=" << unicode << ", keycode=" << keycode
+ << ", modifiers=" << modifiers << ", ispressed=" << isPress << oendl;
if (!enabled) {
return false;
}
// the second check is workaround to make suspend work if
// the user pressed it right after he did resume. for some
// reason the event sent by qt has autoRepeat true in this
// case
if (autoRepeat && keycode != 4177) {
return true;
}
(void) unicode; (void) modifiers;
Action* action = currentState->get(keycode, isPress, true);
if (action==0 || !action->isDefined()) {
return true;
}
if (action->hasEvent()) {
- qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, "
- "ispressed=%x\n", action->getUnicode(),
- action->getKeycode(), action->getModifiers(),
- action->isPressed());
+ odebug << "filter:<<< unicode=" << action->getUnicode() << ", keycode=" << action->getKeycode()
+ << ", modifiers=" << action->getModifiers() << ", ispressed=" << action->isPressed() << oendl;
QWSServer::sendKeyEvent(action->getUnicode(),
action->getKeycode(), action->getModifiers(),
action->isPressed(), false);
}
if (action->isAutorepeat()) {
autoRepeatAction = action;
repeater.start(repeatDelay, TRUE);
} else {
autoRepeatAction = 0;
}
State* nstate = action->getState();
if (nstate != 0) {
setCurrentState(nstate);
QString lbl = getCurrentLabel();
if (!lbl.isEmpty()) {
emit stateChanged(lbl);
}
}
return true;
}
void Keymap::enable() {
enabled = true;
}
void Keymap::disable() {
enabled = false;
}
QStringList Keymap::listStates() {
QStringList ret;
QMap<QString, State*>::Iterator it;
for(it = states.begin(); it != states.end(); ++it) {
ret.append(it.key());
}
return ret;
}
State* Keymap::getStateByName(const QString& name) {
QMap<QString, State*>::Iterator it = states.find(name);
if (it == states.end()) {
return 0;
}
return it.data();
}
QStringList Keymap::listLabels() {
QStringList ret;
for(uint i = 0; i < labelList.count(); i++) {
ret.append(*labelList.at(i));
}
return ret;
}
State* Keymap::getStateByLabel(const QString& label) {
QMap<QString, QString>::Iterator lit = labels.find(label);
State* state = 0;
if (lit == labels.end()) {
return 0;
}
QString name = lit.data();
int n = name.find(":*");
if (n>=0 && n==(int)(name.length()-2)) {
name=name.left(name.length() - 1);
n = currentStateName.findRev(":");
if (n >= 0) {
name += currentStateName.mid(n+1);
}
}
// odebug << "look for: " << name.utf8() << "\n" << oendl;
QMap<QString, State*>::Iterator sit = states.find(name);
if (sit != states.end()) {
state = sit.data();
}
return state;
}
bool Keymap::addState(const QString& name, State* state) {
if (states.find(name) != states.end()) {
return false;
}
states.insert(name, state);
lsmapInSync = false;
if (currentState == 0) {
setCurrentState(state);
}
return true;
}
State* Keymap::getCurrentState() const {
return currentState;
}
QString Keymap::getCurrentLabel() {
return currentLabel;
}
bool Keymap::setCurrentState(State* state) {
QMap<QString, State*>::Iterator it;
for(it = states.begin(); it != states.end(); ++it) {
State* s = it.data();
if (s == state) {
currentState = s;
currentStateName = it.key();
- qDebug("state changed: %s\n", (const char*)
- currentStateName.utf8());
+ odebug << "state changed: " << (const char*)currentStateName.utf8() << oendl;
if (!lsmapInSync) {
generateLabelStateMaps();
}
QMap<State*, QString>::Iterator tit;
tit = stateLabelMap.find(state);
if (tit != stateLabelMap.end()) {
currentLabel = tit.data();
} else {
// odebug << "no label for: " + currentStateName + "\n" << oendl;
currentLabel = "";
}
return true;
}
}
return false;
}
bool Keymap::removeState(const QString& name, bool force) {
QMap<QString, State*>::Iterator it = states.find(name);
if (it == states.end()) {
return false;
}
State* state = it.data();
QList<Action> acts = findStateUsage(state);
if (!acts.isEmpty()) {
if (!force) {
return false;
} else {
for(Action* a = acts.first(); a != 0; a = acts.next()) {
a->setState(0);
}
}
}
if (state == currentState) {
if (states.begin() != states.end()) {
setCurrentState(states.begin().data());
}
}
states.remove(it);
delete state;
lsmapInSync = false;
return true;
}
void Keymap::autoRepeat() {
if (autoRepeatAction != 0) {
- qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, "
- "ispressed=%x\n", autoRepeatAction->getUnicode(),
- autoRepeatAction->getKeycode(),
- autoRepeatAction->getModifiers(),
- autoRepeatAction->isPressed());
+ odebug << "filter:<<< unicode=" << autoRepeatAction->getUnicode()
+ << ", keycode=" << autoRepeatAction->getKeycode()
+ << ", modifiers=" << autoRepeatAction->getModifiers()
+ << "ispressed=" << autoRepeatAction->isPressed() << oendl;
QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(),
autoRepeatAction->getKeycode(),
autoRepeatAction->getModifiers(),
autoRepeatAction->isPressed(), true);
}
repeater.start(repeatPeriod, TRUE);
}
bool Keymap::addLabel(const QString& label, const QString& state, int index) {
if (labels.find(label) != labels.end()) {
return false;
}
labels.insert(label, state);
const QString& l = labels.find(label).key();
if (index == -1) {
labelList.append(l);
} else {
labelList.insert(labelList.at(index), l);
}
lsmapInSync = false;
return true;
}
bool Keymap::removeLabel(const QString& label) {
if (labels.find(label) == labels.end()) {
return false;
}
labels.remove(label);
labelList.remove(label);
lsmapInSync = false;
if (label == currentLabel) {
currentLabel = "";
}
return true;
}
int Keymap::getAutorepeatDelay() const {
return repeatDelay;
}
void Keymap::setAutorepeatDelay(int n) {
repeatDelay = n;
}
int Keymap::getAutorepeatPeriod() const {
return repeatPeriod;
}
void Keymap::setAutorepeatPeriod(int n) {
repeatPeriod = n;
}
QList<Action> Keymap::findStateUsage(State* s) {
QList<Action> ret;
QMap<QString, State*>::Iterator it;
for(it = states.begin(); it != states.end(); ++it) {
State* state = it.data();
for(int i = 0; i < 0x1100; i++) {
Action* action = state->get(i, false);
if (action!=0 && action->getState()==s) {
ret.append(action);
}
action = state->get(i, true);
if (action!=0 && action->getState()==s) {
ret.append(action);
}
}
}
return ret;
}
void Keymap::generateLabelStateMaps() {
stateLabelMap.clear();
QMap<QString, QString>::Iterator lit;
for(lit = labels.begin(); lit != labels.end(); ++lit) {
QString label = lit.key();
QString name = lit.data();
bool wc = false;
int n = name.find("*");
if (n>=0 && n==(int)(name.length()-1)) {
name=name.left(name.length() - 1);
wc = true;
}
QMap<QString, State*>::Iterator sit;
for(sit = states.begin(); sit != states.end(); ++sit) {
QString sname = sit.key();
State* state = sit.data();
if (sname.length() < name.length()) {
continue;
}
if (sname.left(name.length()) == name) {
if (wc || sname.length()==name.length()) {
stateLabelMap.insert(state, label);
}
}
}
}
lsmapInSync = true;
}
diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
index be2b897..f14080f 100644
--- a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
+++ b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
@@ -232,764 +232,767 @@ void Gutenbrowser::goGetit( const QString &url, bool showMsg) {
// system(cmd);
while ( fgets( line, sizeof line, fp)) {
outDlg->OutputEdit->append(line);
outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
}
pclose(fp);
outDlg->close();
if(outDlg)
delete outDlg;
} else {
if( brow == "Konq") {
cmd = "konqueror "+url+" &";
}
if( brow == "Opera") { //for desktop testing
cmd = "opera "+url+" &";
}
// if( brow == "Opera") { // on Zaurus
// cmd = "operagui "+url+" &";
// }
if( brow == "Mozilla") {
cmd = "mozilla "+url+" &";
}
if( brow == "Netscape") {
cmd = "netscape "+url+" &";
}
if(brow == "wget") {
// cmd="wget -q "+url+" &";
QString tempHtml=local_library+"webster.html";
cmd="wget -O "+tempHtml+" -q "+url;
}
chdir(local_library);
odebug << "Issuing the sys command: " << cmd << "" << oendl;
system(cmd);
}
}
void Gutenbrowser::toggleButtonIcons( bool useEm) {
QString pixDir;
if(useEm)
useEm=TRUE;
pixDir=QPEApplication::qpeDir()+"pics/gutenbrowser";
odebug << "Docdir is "+QPEApplication::documentDir() << oendl;
if( useIcons && QDir( pixDir).exists() ) {
LibraryButton->setPixmap( Resource::loadPixmap("home") ); //in inline
OpenButton->setPixmap( Resource::loadPixmap("gutenbrowser/openbook"));
ForwardButton->setPixmap( Resource::loadPixmap("forward"));//in inline
BackButton->setPixmap( Resource::loadPixmap("back") );//in inline
SearchButton->setPixmap( Resource::loadPixmap("gutenbrowser/search") );//in inline
lastBmkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark_folder"));
setBookmarkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark") );
dictionaryButton->setPixmap( Resource::loadPixmap("gutenbrowser/spellcheck") );
InfoBar->setPixmap( Resource::loadPixmap("gutenbrowser/google"));
}
}
bool Gutenbrowser::queryExit()
{
int exit=QMessageBox::information(this, "Quit...", "Do your really want to quit?",
QMessageBox::Ok, QMessageBox::Cancel);
if (exit==1) {
writeConfig();
qApp->quit();
} else {
};
return (exit==1);
}
// SLOT IMPLEMENTATION
void Gutenbrowser::slotFilePrint() {
}
void Gutenbrowser::ByeBye() {
if (b_queryExit)
queryExit();
else {
// writeConfig();
qApp->quit();
}
}
void Gutenbrowser::HelpBtn() {
HelpMe* HelpDlg;
HelpDlg = new HelpMe( this, "Help Dialog");
HelpDlg->showMaximized();
}
void Gutenbrowser::DownloadIndex() {
#ifndef Q_WS_QWS
{
switch( QMessageBox::information( 0, (tr("Download Library Index, or FTP sites?")),
(tr("Do you want to download the newest\n"
"Project Gutenberg Library Index?\n"
"or select an ftp site?\n")),
(tr("&Library Index")), (tr("&Ftp Site")), (tr("&Cancel")), 2, 2 ) )
{
case 0: // index clicked,
downloadLibIndex();
break;
case 1: // ftp selected
downloadFtpList();
break;
case 2: // Cancel
break;
};
}
#endif
} // end DownloadIndex
void Gutenbrowser::downloadFtpList() {
// QString cmd="wget http://www.promo.net/pg/list.html");
//system(cmd);
qApp->processEvents();
optionsDialog* optDlg;
optDlg = new optionsDialog( this,"Options_Dlg", true);
optDlg->getSite();
if(optDlg)
delete optDlg;
}
void Gutenbrowser::downloadLibIndex() {
// QString dwmloader = local_library + "pgwhole.zip";
// QString cmd = "lynx -source http://www.gutenberg.net/pgwhole.zip | cat >> " + dwmloader;
// system(cmd);
// QString outputFile= local_library+ "GUTINDEX.ALL";
// config.setGroup( "FTPsite" ); // ftp server config
// ftp_host=config.readEntry("SiteName", "");
// ftp_base_dir= config.readEntry("base", "");
// QString networkUrl= "ftp://"+ftp_host+ftp_base_dir+"/GUTINDEX.ALL";
QDir dir( local_library);
dir.cd("", TRUE);
goGetit( "http://sailor.gutenberg.org/GUTINDEX.ALL", false); // until ghttp works on binaries -qt3
// goGetit( "http://www.gutenberg.net/pgwhole.zip", true); // until ghttp works on binaries -qt3
// NetworkDialog *NetworkDlg;
// NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, outputFile );
// if( NetworkDlg->exec() != 0 )
// { // use new, improved, *INSTANT* network-dialog-file-getterer
//// QMessageBox::message("Note","");
// }
// if(NetworkDlg)
// delete NetworkDlg;
}
void Gutenbrowser::PrintBtn() {
}
void Gutenbrowser::SearchBtn() {
if( loadCheck) {
odebug << "loadCheck: we have a loaded doc" << oendl;
Search();
}
// else
// QMessageBox::message("Note","Sorry, can't search. No etext is loaded");
}
void Gutenbrowser::ForwardBtn() {
if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) {
QString s;
QString insertString;
int pageSize= Lview->PageSize();
Lview->clear();
for(int fd=0; fd < pageSize - 1;fd++) {
f.readLine(s, 256);
if(useWrap)
s.replace(QRegExp("\n"),"");
insertString+=s;
Lview->insertLine( s, -1);
// odebug << s << oendl;
currentLine++;
}
// Lview->insertAt( insertString,0,0, FALSE);
currentFilePos = f.at();
// if( i_pageNum != pages) {
// Lview->MultiLine_Ex::pageDown( FALSE);
i_pageNum++;
pageStopArray.resize(i_pageNum + 1);
// int length = Lview->length();
pageStopArray[i_pageNum ] = currentFilePos;
- // qDebug("%d current page is number %d, pagesize %d, length %d, current %d",
- // currentFilePos, i_pageNum, pageSize, Lview->length(), pageStopArray[i_pageNum] );
+ // odebug << currentFilePos << " current page is number " << i_pageNum
+ // << ", pagesize " << pageSize << ", length " << Lview->length()
+ // << ", current " << pageStopArray[i_pageNum] << oendl;
setStatus();
Lview->setCursorPosition( 0, 0, FALSE);
// }
} else {
// odebug << "bal" << oendl;
// if( i_pageNum != pages) {
// // int newTop = Lview->Top();
// // if(Lview->lastRow() > i)
// Lview->ScrollUp(1);
// // i_pageNum++;
// setStatus();
// Lview->setCursorPosition( Lview->Top(), 0, FALSE);
// }
}
Lview->setFocus();
// odebug << "page number " << i_pageNum << " line number " << currentLine << "" << oendl;
}
void Gutenbrowser::BackBtn() {
if( i_pageNum > 0) {
int pageSize= Lview->PageSize();
// int length=Lview->length();
i_pageNum--;
currentFilePos = f.at();
- // qDebug("%d move back to %d, current page number %d, %d, length %d",
- // currentFilePos, pageStopArray[i_pageNum - 1 ], i_pageNum, pageSize, Lview->length() );
+ // odebug << currentFilePos << " move back to " << pageStopArray[i_pageNum - 1 ]
+ // << ", current page number " << i_pageNum
+ // << ", " << pageSize << ", length " << Lview->length() << oendl;
if( i_pageNum < 2) {
f.at( 0);
} else {
if(!f.at( pageStopArray[i_pageNum - 1] ))
odebug << "File positioned backward did not work" << oendl;
}
QString s;
// int sizeLine=0;
Lview->clear();
// QString insertString;
for(int fd = 0; fd < pageSize ;fd++) {
// Lview->removeLine( Lview->PageSize() );
f.readLine(s, 256);
if(useWrap)
s.replace(QRegExp("\n"),"");
currentLine++;
// insertString+=s;
Lview->insertLine( s, -1);
}
// Lview->insertAt( insertString,0,0, FALSE);
if( !BackButton->autoRepeat() && !BackButton->isDown()) {
QString topR;
QString lastR;
QString pageR;
// int sizer = Lview->lastRow() - Lview->topRow();
// int i_topRow = Lview->topRow();
if( i_pageNum < 1)
i_pageNum = 1;
setCaption(QString::number(i_pageNum));
} else {
// int newTop = Lview->Top();
// if(Lview->lastRow() > i)
Lview->MultiLine_Ex::pageUp( FALSE);
// Lview->ScrollDown(1);
// i_pageNum--;
if( i_pageNum < 1)
i_pageNum = 1;
setStatus();
Lview->setCursorPosition( Lview->Top(), 0, FALSE);
}
}
Lview->setFocus();
}
void Gutenbrowser::doBeginBtn() {
if(loadCheck) {
qApp->processEvents();
BeginBtn();
}
}
// moves text to the very top = 0
void Gutenbrowser::TopBtn() {
if(loadCheck) {
if( i_pageNum != 0) {
odebug << "top" << oendl;
qApp->processEvents();
currentLine = 0;
i_pageNum = 1;
int pageSize = Lview->PageSize() ;
Lview->clear();
QString s;
f.at(0);
for(int fd=0; fd < pageSize ;fd++) {
f.readLine(s, 256);
if(useWrap)
s.replace(QRegExp("\n"),"");
Lview->insertLine(s ,-1);
currentLine++;
}
Lview->setCursorPosition( 0,0, FALSE);
i_pageNum=1;
setStatus();
}
Lview->setFocus();
}
}
//moves text to the start of the EText
void Gutenbrowser::BeginBtn() {
i_pageNum = 1;
currentLine = 0;
QString s_pattern="*END*THE SMALL PRINT";
QString sPattern2 = "*END THE SMALL PRINT";
int pageSize = Lview->PageSize();
Lview->clear();
// int lines = Lview->numLines();
int pos = 0;//, i = 0;
int i_topRow = Lview->topRow();
QString LeftText;// = Lview->text();
int linesPerPage = Lview->lastRow() - Lview->topRow();
// int pages = (( linesPerPage / Lview->editSize() ) ) +1;
// int pageN = 0;
i_pageNum = 1;
int lastPage=1;
int lineNo=0;
QString s;
f.at( 0);
while ( !f.atEnd() ) {
f.readLine(s, 256);
lineNo++;
LeftText = s;
currentFilePos = f.at();
i_pageNum = lineNo/pageSize;
if(lastPage < i_pageNum) {
pageStopArray.resize(i_pageNum + 1);
pageStopArray[i_pageNum ] = currentFilePos;
// odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl;
}
// lastPage = i_pageNum;
if( LeftText.find( s_pattern, 0 , TRUE) != -1 || LeftText.find( sPattern2, 0 , TRUE) != -1 ) {
odebug << "<<<<<< FOUND IT!! new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl;
break;
}
}
if(f.atEnd()) //in case we didnt find anything, we need to show something
f.at(0);
Lview->clear();
for(int fd=0; fd < pageSize - 1;fd++) {
f.readLine(s, 256);
if(useWrap)
s.replace(QRegExp("\n"),"");
Lview->insertLine( s, -1);
currentLine++;
}
i_pageNum = lineNo/pageSize;
pageStopArray.resize(i_pageNum + 1);
// int length = Lview->length();
qApp->processEvents();
if( pos > i_topRow ) {
Lview->setCursorPosition( pos+linesPerPage+2/* - i_topRow+3 */,0, FALSE);
} else {
Lview->setCursorPosition( pos+2 , 0, FALSE );
}
Lview->deselect();
// AdjustStatus();
Lview->setFocus();
}
/*
sets the current page and place as a bookmark*/
void Gutenbrowser::setBookmark() {
int eexit=QMessageBox::information(this, "Note",
"Do you really want to \nset this bookmark?."
,QMessageBox::Yes, QMessageBox::No);
if (eexit== 3) {
currentFilePos = f.at();
Config cfg("Gutenbrowser");
cfg.setGroup("General");
file_name=cfg.readEntry("Current","");
qApp->processEvents();
odebug << "Settingbook mark "+file_name << oendl;
cfg.setGroup("Titles");
title=cfg.readEntry(file_name,"");
odebug << "title is "+ title << oendl;
cfg.setGroup( "Bookmarks" );
cfg.writeEntry("File Name",file_name);
cfg.writeEntry("Page Number",QString::number(i_pageNum) );
cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1]));
cfg.writeEntry("Title", title);
int row = Lview->topRow();// Lview->Top();
cfg.writeEntry("LineNumber",QString::number(row) );
cfg.setGroup(title);
cfg.writeEntry("File Name",file_name);
cfg.writeEntry( "LineNumber", QString::number( row));
cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1]));
cfg.writeEntry( "Page Number", QString::number( i_pageNum) );
bookmarksMenu->insertItem( title);
}
} //end setBookmark
/* goes to last set bookmark*/
void Gutenbrowser::Bookmark( int itemId) {
// qApp->processEvents();
Config config("Gutenbrowser");
config.setGroup( "Bookmarks" );
// odebug << "<<<<<< " << Lview->PageSize() << ", " << Lview->lastRow() - Lview->topRow() << "" << oendl;
QString itemString;
odebug << "menu item " << itemId << "" << oendl;
QString tempTitle;
QString s_Bmrkrow;
QString s_pageNum;
int Bmrkrow=0;
int bookmarkPosition = 0;
// qApp->processEvents();
config.setGroup( "Bookmarks" );
title = config.readEntry("Title", "");
file_name = config.readEntry("File Name", "");
i_pageNum = config.readNumEntry("Page Number", 0);
bookmarkPosition = config.readNumEntry( "PagePosition",0);
Bmrkrow = config.readNumEntry("LineNumber",0);
if( !file_name.contains("/")) {
file_name = local_library + file_name;
}
// getTitle(file_name);
// qApp->processEvents();
// Lview->setFocus();
this->setFocus();
Lview->clear();
load(file_name);
int pageSize= Lview->PageSize();
f.at(0);
// Lview->clear();
QString s;
int lineNo=0;
int lastPage=1;
while ( !f.atEnd() ) {
f.readLine(s, 256);
lineNo++;
currentFilePos = f.at();
i_pageNum = lineNo/pageSize;
if(lastPage < i_pageNum) {
pageStopArray.resize(i_pageNum + 1);
pageStopArray[i_pageNum ] = currentFilePos;
// odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl;
}
if(currentFilePos == bookmarkPosition)
break;
}
if(f.atEnd())
f.at(0);
else
f.at( bookmarkPosition);
for(int fd=0; fd < pageSize - 1;fd++) {
f.readLine(s, 256);
lineNo++;
if(useWrap)
s.replace(QRegExp("\n"),"");
Lview->insertLine( s, -1);
currentLine++;
}
i_pageNum = lineNo/pageSize;
pageStopArray.resize(i_pageNum + 1);
if(showMainList) {
showMainList=FALSE;
mainList->hide();
Lview->show();
// qApp->processEvents();
}
odebug << "bookmark loaded" << oendl;
setCaption(title);
}
bool Gutenbrowser::load( const char *fileName) {
// QCopEnvelope ( "QPE/System", "busy()" );
// odebug << "Title is already set as "+title << oendl;
odebug << "sizeHint " << sizeHint().height() << " pageSize " << Lview->PageSize() << "" << oendl;
if( Lview->PageSize() < 4) {
Lview->setMaximumHeight( sizeHint().height() );
Lview->setMinimumHeight( sizeHint().height() );
pointSize = Lview->fontInfo().pointSize();
odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl;
if(pointSize < 10)
Lview->setFixedVisibleLines(19);
else
Lview->setFixedVisibleLines( ( (sizeHint().height() / pointSize ) * 2) -2);
}
Config cfg("Gutenbrowser");
cfg.setGroup("General");
cfg.writeEntry("Current",fileName);
currentLine=0;
file_name=fileName;
QString o_file = fileName;
// if (i_pageNum < 1) {
i_pageNum = 1;
// }
odebug << "ready to open "+o_file << oendl;
if(f.isOpen()) f.close();
f.setName( o_file);
if ( !f.open( IO_ReadOnly)) {
QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n" +o_file)) );
return false;
}
currentFilePos = 0;
pageStopArray.resize(3);
pageStopArray[0] = currentFilePos;
fileHandle = f.handle();
QString insertString;
QTextStream t(&f);
QString s;
for(int fd=0; fd < Lview->PageSize() ;fd++) {
s=t.readLine();
// insertString+=s;
if(useWrap)
s.replace(QRegExp("\n"),"");
// s.replace(QRegExp("\r"),"");
Lview->insertLine( s,-1);
currentLine++;
}
// int length = Lview->length();
currentFilePos = f.at();
pageStopArray[1] = currentFilePos;
- qDebug("<<<<<<<<<<<%d current page is number %d, length %d, current %d, pageSize %d",
- currentFilePos, i_pageNum, Lview->length(), pageStopArray[i_pageNum], Lview->PageSize() );
+ odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum
+ << ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum]
+ << ", pageSize " << Lview->PageSize() << oendl;
Lview->setMaxLines(Lview->PageSize()*2);
odebug << "Gulped " << currentLine << "" << oendl;
setCaption(title);
Lview->setAutoUpdate( TRUE);
Lview->setCursorPosition(0,0,FALSE);
// pages = (int)(( Lview->numLines() / Lview->editSize() ) / 2 ) +1;
//odebug << "number of pages " << pages << "" << oendl;
loadCheck = true;
enableButtons(true);
if( donateMenu->count() == 3) {
donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() ));
}
Lview->setFocus();
// QCopEnvelope("QPE/System", "notBusy()" );
return true;
} // end load
void Gutenbrowser::Search() {
// if( searchDlg->isHidden())
{
odebug << "Starting search dialog" << oendl;
searchDlg = new SearchDialog( this, "Etext Search", true);
searchDlg->setCaption( tr( "Etext Search" ));
// searchDlg->setLabel( "- searches etext");
connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot()));
connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot()));
QString resultString;
QString string = searchDlg->searchString;
Lview->deselect();
searchDlg->show();
searchDlg->result();
}
}
void Gutenbrowser::search_slot( ) {
int line, col;
if (!searchDlg /*&& !loadCheck */)
return;
Lview->getCursorPosition(&line,&col);
QString to_find_string=searchDlg->get_text();
// searchDlg->get_direction();// is true if searching backward
if ( last_search != 0 && searchDlg->get_direction() ){
col = col - pattern.length() - 1 ;
}
again:
int result = doSearch( to_find_string , /* searchDlg->case_sensitive()*/ TRUE, searchDlg->forward_search(), line, col);
if(result == 0){
if(!searchDlg->get_direction()){ // forward search
int query = QMessageBox::information( searchDlg, "Find",
"End of document reached.\nContinue from the beginning?",
"Yes", "No", "", 0,1);
if (query == 0){
line = 0;
col = 0;
goto again;
}
} else { //backward search
int query = QMessageBox::information( searchDlg, "Find",
"End of document reached.\nContinue from the beginning?",
"Yes", "No", "", 0,1);
if (query == 0){
QString string = Lview->textLine( Lview->numLines() - 1 );
line = Lview->numLines() - 1;
lineCheck = line;
col = string.length();
last_search = -1; //BACKWARD;
goto again;
}
}
} else {
//// emit CursorPositionChanged(); textLine
}
}
int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) {
int i, length;
int pos = -1;
if(forward) {
QString string;
for(i = line; i < Lview->numLines(); i++) {
string = Lview->textLine(i);
pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);
if( pos != -1) {
int top = Lview->Top();
length = s_pattern.length();
if( i > Lview->lastRow() ) {
Lview->setCursorPosition(i,pos,FALSE);
for(int l = 0 ; l < length; l++) {
Lview->cursorRight(TRUE);
}
Lview->setCursorPosition( i , pos + length, TRUE );
int newTop = Lview->Top();
if(Lview->lastRow() > i)
Lview->ScrollUp( newTop - top);
// AdjustStatus();
} else {
Lview->setCursorPosition(i,pos,FALSE);
for(int l = 0 ; l < length; l++) {
Lview->cursorRight(TRUE);
}
Lview->setCursorPosition( i , pos + length, TRUE );
// AdjustStatus();
}
pattern = s_pattern;
last_search = 1; //FORWARD;
return 1;
}
}
} else { //////////////// searching backwards
QString string;
for( i = line; i >= 0; i--) {
string = Lview->textLine(i);
int line_length = string.length();
pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
if (pos != -1) {
// int top = Lview->Top();
length = s_pattern.length();
if( i < Lview->Top() ) {
Lview->ScrollDown( Lview->PageSize() );
Lview->MultiLine_Ex::pageUp( FALSE );
if( ! (line == i && pos > col ) ) {
Lview->setCursorPosition( i ,pos ,FALSE );
for(int l = 0 ; l < length; l++) {
Lview->cursorRight(TRUE);
}
Lview->setCursorPosition(i ,pos + length ,TRUE );
// int newTop = Lview->Top();
/* if(useSplitter) Rview->ScrollUp( newTop - top);
*/ }
} else {
if( ! (line == i && pos > col ) ) {
Lview->setCursorPosition( i, pos, FALSE );
for( int l = 0 ; l < length; l++) {
Lview->cursorRight( TRUE);
}
Lview->setCursorPosition( i, pos + length, TRUE );
}
pattern = s_pattern;
last_search = -1;
return 1;
}
}
}
}
return 0;
}
void Gutenbrowser::LibraryBtn() {
QString newestLibraryFile ="pgwhole.zip";
QString zipFile;
// odebug << "Local Library is " << local_library << " " << oendl;
zipFile="/usr/bin/unzip";
// odebug << "newestLibraryFile is " << newestLibraryFile << " " << oendl;
if( QFile::exists( local_library+newestLibraryFile)) {
if( QFile::exists(zipFile) ) {
UnZipIt(newestLibraryFile);
}
else
QMessageBox::message( "Note",( tr("Please install unzip")) );
}
// LibraryDlg = new LibraryDialog( this, "Library Index");
LibraryDlg->setCaption( tr( "Gutenberg Library"));
Config config("Gutenbrowser");
config.setGroup("General");
QString tmp=config.readEntry("RunBefore","FALSE");
if(tmp=="FALSE") {
QMessageBox::message( "Note",
"<P>Your first time running gutenbrowser. You'll need to click the \"load library\" button to load the gutenberg index.</P>");
config.writeEntry("RunBefore","TRUE");
}
if(useSplitter)
LibraryDlg->useSmallInterface=FALSE;
LibraryDlg->showMaximized();
if( LibraryDlg->exec() != 0 ) {
listItemNumber = LibraryDlg->DlglistItemNumber;
listItemFile = LibraryDlg->DlglistItemFile;
listItemYear = LibraryDlg->DlglistItemYear;
listItemTitle = LibraryDlg->DlglistItemTitle;
diff --git a/noncore/apps/opie-reader/BuffDoc.h b/noncore/apps/opie-reader/BuffDoc.h
index 29d0329..61531c0 100644
--- a/noncore/apps/opie-reader/BuffDoc.h
+++ b/noncore/apps/opie-reader/BuffDoc.h
@@ -1,122 +1,122 @@
#ifndef __BuffDoc_h
#define __BuffDoc_h
#include "useqpe.h"
#include "ZText.h"
#include "Aportis.h"
#include "ztxt.h"
#include "ppm_expander.h"
#include "CDrawBuffer.h"
#include "CFilter.h"
#include <qfontmetrics.h>
#include <qmessagebox.h>
class BuffDoc
{
CDrawBuffer lastword;
CSizeBuffer lastsizes, allsizes;
size_t laststartline;
bool lastispara;
CExpander* exp;
CFilterChain* filt;
public:
void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
{
if (exp == NULL)
{
data = NULL;
len = 0;
}
else
{
exp->setSaveData(data, len, src, srclen);
}
}
void putSaveData(unsigned char*& src, unsigned short& srclen)
{
if (exp != NULL)
{
exp->putSaveData(src, srclen);
}
}
#ifdef USEQPE
void suspend() { if (exp != NULL) exp->suspend(); }
void unsuspend() { if (exp != NULL) exp->unsuspend(); }
#else
void suspend() {}
void unsuspend() {}
#endif
~BuffDoc()
{
delete filt;
delete exp;
}
BuffDoc()
{
exp = NULL;
filt = NULL;
lastword.empty();
-// // qDebug("Buffdoc created");
+ // odebug << "Buffdoc created" << oendl;
}
bool empty() { return (exp == NULL); }
void setfilter(CFilterChain* _f)
{
if (filt != NULL) delete filt;
filt = _f;
filt->setsource(exp);
}
CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); }
bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); }
bool iseol() { return (lastword[0] == '\0'); }
int openfile(QWidget* _parent, const char *src);
tchar getch()
{
tchar ch = UEOF;
CStyle sty;
if (exp != NULL)
{
filt->getch(ch, sty);
}
return ch;
}
void getch(tchar& ch, CStyle& sty)
{
if (exp != NULL)
{
filt->getch(ch, sty);
}
else
ch = UEOF;
}
void setwidth(int w) { if (exp != NULL) exp->setwidth(w); }
QImage* getPicture(unsigned long tgt) { return (exp == NULL) ? NULL : exp->getPicture(tgt); }
unsigned int startSection() { return (exp == NULL) ? 0 : exp->startSection(); }
unsigned int endSection() { return (exp == NULL) ? 0 : exp->endSection(); }
unsigned int locate() { return (exp == NULL) ? 0 : laststartline; }
unsigned int explocate() { return (exp == NULL) ? 0 : exp->locate(); }
void setContinuous(bool _b) { if (exp != NULL) exp->setContinuous(_b); }
MarkupType PreferredMarkup() { return (exp == NULL) ? cTEXT : exp->PreferredMarkup(); }
linkType hyperlink(unsigned int n, QString& wrd);
size_t getHome() { return ((exp != NULL) ? exp->getHome() : 0); }
void locate(unsigned int n);
bool getline(CDrawBuffer* buff, int w, unsigned char _border);
bool getline(CDrawBuffer* buff, int w, int cw, unsigned char _border);
void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); }
int getpara(CBuffer& buff)
{
tchar ch;
int i = 0;
while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch;
buff[i] = '\0';
if (i == 0 && ch == UEOF) i = -1;
laststartline = exp->locate();
return i;
}
void saveposn(size_t posn) { exp->saveposn(posn); }
void writeposn(size_t posn) { exp->writeposn(posn); }
bool forward(size_t& loc) { return exp->forward(loc); }
bool back(size_t& loc) { return exp->back(loc); }
bool hasnavigation() { return exp->hasnavigation(); }
};
#endif
diff --git a/noncore/apps/opie-reader/CEncoding.h b/noncore/apps/opie-reader/CEncoding.h
index 463fba9..df0104a 100644
--- a/noncore/apps/opie-reader/CEncoding.h
+++ b/noncore/apps/opie-reader/CEncoding.h
@@ -1,74 +1,74 @@
#ifndef __CENCODING_H
#define __CENCODING_H
#include "CExpander.h"
#define MAX_ENCODING 6
class CEncoding : public CCharacterSource
{
friend class CFilterChain;
protected:
CExpander* parent;
linkType hyperlink(unsigned int n, QString& t) { return parent->hyperlink(n,t); }
public:
CEncoding() : parent(NULL) {}
void setparent(CExpander* p) { parent = p; }
virtual ~CEncoding() {};
};
class CUtf8 : public CEncoding
{
public:
void getch(tchar& ch, CStyle& sty);
};
class CUcs16be : public CEncoding
{
public:
void getch(tchar& ch, CStyle& sty);
};
class CUcs16le : public CEncoding
{
public:
void getch(tchar& ch, CStyle& sty);
};
class Ccp1252 : public CEncoding
{
public:
void getch(tchar& ch, CStyle& sty);
};
class CPalm : public Ccp1252
{
public:
void getch(tchar& ch, CStyle& sty);
};
class CAscii : public CEncoding
{
public:
void getch(tchar& ch, CStyle& sty);
};
#include "CEncoding_tables.h"
class CGeneral8Bit : public CEncoding
{
int m_index;
public:
CGeneral8Bit(int _i) : m_index(_i)
{
-// qDebug("8Bit:%d", _i);
-// qDebug("%s", unicodetable::iterator(_i)->mime);
+// odebug << "8Bit: " << _i << oendl;
+// odebug << unicodetable::iterator(_i)->mime << oendl;
}
void getch(tchar& ch, CStyle& sty)
{
parent->getch(ch, sty);
ch = unicodetable::unicodevalue(m_index, ch);
}
};
#endif
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h
index 7b21d3e..9fae245 100644
--- a/noncore/apps/opie-reader/CExpander.h
+++ b/noncore/apps/opie-reader/CExpander.h
diff --git a/noncore/apps/opie-reader/Filedata.h b/noncore/apps/opie-reader/Filedata.h
index 096dd31..1b85b71 100644
--- a/noncore/apps/opie-reader/Filedata.h
+++ b/noncore/apps/opie-reader/Filedata.h
@@ -1,51 +1,51 @@
#ifndef __FILEDATA_H
#define __FILEDATA_H
#include <time.h>
class CFiledata
{
unsigned char* data;
bool m_own;
public:
CFiledata(tchar* d)
{
data = (unsigned char*)d;
m_own = false;
}
CFiledata(time_t dt, tchar* nm)
{
int nlen = ustrlen(nm)+1;
data = new unsigned char[sizeof(time_t)+sizeof(tchar)*nlen];
*((time_t *)data) = dt;
memcpy(data+sizeof(time_t), nm, sizeof(tchar)*nlen);
m_own = true;
}
~CFiledata()
{
if (m_own && data != NULL)
{
delete [] data;
-// qDebug("~Filedata: deleting");
+// odebug << "~Filedata: deleting" << oendl;
}
else
{
-// qDebug("~Filedata: not deleting");
+// odebug << "~Filedata: not deleting" << oendl;
}
}
tchar* name() const { return (tchar*)(data+sizeof(time_t)); }
time_t date() { return *((time_t *)data); }
void setdate(time_t _t) { *((time_t *)data) = _t; }
unsigned char* content() { return data; }
size_t length() const { return sizeof(time_t)+sizeof(tchar)*(ustrlen(name())+1); }
bool operator==(const CFiledata& rhs)
{
return ((length() == rhs.length()) && (memcmp(data, rhs.data, length()) == 0));
}
bool samename(const CFiledata& rhs)
{
return (ustrcmp((tchar *)(data+sizeof(time_t)),(tchar *)(rhs.data+sizeof(time_t))) == 0);
}
};
#endif
diff --git a/noncore/apps/opie-reader/FontControl.h b/noncore/apps/opie-reader/FontControl.h
index 5681496..e56b619 100644
--- a/noncore/apps/opie-reader/FontControl.h
+++ b/noncore/apps/opie-reader/FontControl.h
@@ -1,153 +1,153 @@
#ifndef __FONTCONTROL_H
#define __FONTCONTROL_H
#include <qfontdatabase.h>
#include <qfontmetrics.h>
#include "StyleConsts.h"
class FontControl
{
int * m_fontsizes;
int m_size, g_size;
QString m_fontname;
QString m_fixedfontname;
int m_maxsize;
bool m_hasCourier;
int m_leading, m_extraspace;
unsigned char m_basesize;
public:
void setBaseSize(unsigned char _s) { m_basesize = _s; }
unsigned char getBaseSize() { return m_basesize; }
int gzoom();
FontControl(QString n = "helvetica", int size = 10)
:
m_fontsizes(NULL), m_hasCourier(false), m_leading(0), m_extraspace(0)
{
ChangeFont(n, size);
}
~FontControl()
{
if (m_fontsizes != NULL) delete [] m_fontsizes;
}
void hasCourier(bool _b, const QString& _nm)
{
m_hasCourier = _b;
m_fixedfontname = _nm;
}
QString& fixedfontname() { return m_fixedfontname; }
bool hasCourier() { return m_hasCourier; }
QString name() { return m_fontname; }
int currentsize() { return m_fontsizes[m_size]; }
int getsize(const CStyle& size)
{
int tgt = m_size+size.getFontSize();
if (tgt < 0)
{
tgt = 0;
}
if (tgt >= m_maxsize)
{
tgt = m_maxsize - 1;
}
return m_fontsizes[tgt];
}
int ascent()
{
QFont f(name(), currentsize());
QFontMetrics fm(f);
return fm.ascent();
}
int ascent(const CStyle& ch)
{
QFont f(name(), getsize(ch));
QFontMetrics fm(f);
return fm.ascent();
}
int descent()
{
QFont f(name(), currentsize());
QFontMetrics fm(f);
return fm.descent();
}
int descent(const CStyle& ch)
{
QFont f(name(), getsize(ch));
QFontMetrics fm(f);
return fm.descent();
}
int lineSpacing()
{
QFont f(name(), currentsize());
QFontMetrics fm(f);
return fm.lineSpacing();
}
int lineSpacing(const CStyle& ch)
{
QFont f(name(), getsize(ch));
QFontMetrics fm(f);
return fm.lineSpacing();
}
bool decreasesize()
{
/*
if (--m_size < 0)
{
m_size = 0;
return false;
}
else return true;
*/
if (g_size-- == m_size)
{
if (--m_size < 0)
{
m_size = 0;
}
}
-// qDebug("Font:%d Graphics:%d", m_size, g_size);
+// odebug << "Font:" << m_size << " Graphics:" << g_size << oendl;
return true;
}
bool increasesize()
{
/*
if (++m_size >= m_maxsize)
{
m_size = m_maxsize - 1;
return false;
}
else return true;
*/
if (g_size++ == m_size)
{
if (++m_size >= m_maxsize)
{
m_size = m_maxsize - 1;
}
}
-// qDebug("Font:%d Graphics:%d", m_size, g_size);
+// odebug << "Font:" << m_size << " Graphics:" << g_size << oendl;
return true;
}
bool ChangeFont(QString& n)
{
return ChangeFont(n, currentsize());
}
bool ChangeFont(QString& n, int tgt);
void setlead(int _lead)
{
m_leading = _lead;
}
int getlead()
{
return m_leading;
}
void setextraspace(int _lead)
{
m_extraspace = _lead;
}
int getextraspace()
{
return m_extraspace;
}
};
#endif
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp
index 9339595..b0d4e00 100644
--- a/noncore/apps/opie-reader/Palm2QImage.cpp
+++ b/noncore/apps/opie-reader/Palm2QImage.cpp
@@ -1,308 +1,319 @@
/* -*- mode: c; indent-tabs-mode: nil; -*- */
+
+/* OPIE */
+#include <opie2/odebug.h>
+
+/* QT */
+#include <qimage.h>
+
+/* STD */
#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,
*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);
+// odebug << "Palm image is " << width << "x" << height
+// << ", " << bits_per_pixel << " bpp, version " << version
+// << ", flags 0x" << flags << ", compression " << compression_type << oendl;
#endif
if (compression_type == PALM_COMPRESSION_PACKBITS) {
-// qDebug ("Image uses packbits compression; not yet supported");
+// odebug << "Image uses packbits compression; not yet supported" << oendl;
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);
+// odebug << "Image uses unknown compression, code 0x" << compression_type << oendl;
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");
+// odebug << "Palm images with custom colormaps are not currently supported." << oendl;
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);
+// odebug << "Bits:" << palm_red_bits << ", " << palm_green_bits << ", " << palm_blue_bits << oendl;
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);
+// odebug << "Can't handle this format DirectColor image -- too wide in some color ("
+// << palm_red_bits << ":" << palm_green_bits << ":" << palm_blue_bits << oendl;
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);
+// odebug << "Can't handle this format DirectColor image -- too many bits per pixel ("
+// << bits_per_pixel << ")" << oendl;
return NULL;
}
imagedatastart = palmimage + 24;
} else {
-// qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel);
+// odebug << "Unknown bits-per-pixel of " << bits_per_pixel << " encountered" << oendl;
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) {
-// qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row);
+// odebug << "inval:" << inval << " palm_ptr:" << palm_ptr << " x_ptr:" << x_ptr
+// << " bpr:" << bytes_per_row << oendl;
/* 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");
+ odebug << "Case 4" << oendl;
+ odebug << "Is compressed:" << (((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true") << oendl;
+ odebug << "Has colourmap:" << (((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true") << oendl;
+ odebug << "Has transparency:" << (((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true") << oendl;
+ odebug << "Direct colour:" << (((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true") << oendl;
+ odebug << "four byte field:" << (((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true") << oendl;
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));
+ odebug << "pixel is " << 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)) << ")" << oendl;
*/
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;
}
QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b)
{
-//// qDebug("hrule [%d, %d]", w, h);
+// odebug << "hrule [" << w << ", " << h << "]" << oendl;
QPixmap* qimage = new QPixmap(w, h);
qimage->fill(QColor(r,g,b));
QImage* ret = new QImage(qimage->convertToImage());
delete qimage;
return ret;
}
diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h
index dfbdfb9..f89de63 100644
--- a/noncore/apps/opie-reader/QTReader.h
+++ b/noncore/apps/opie-reader/QTReader.h
@@ -1,272 +1,272 @@
#ifndef __QTREADER_H
#define __QTREADER_H
//#define _SCROLLPIPE
#include <qwidget.h>
//#include <qpainter.h>
#include "my_list.h"
#include "BuffDoc.h"
#include "FontControl.h"
//#include <qtimer.h>
class CDrawBuffer;
//class CBuffer;
class QPainter;
class QTimer;
class QPixmap;
class QTReader : public QWidget
{
Q_OBJECT
static tchar pluckernextpart[];
static tchar jplucknextpart[];
friend class QTReaderApp;
void suspend();
void increaseScroll();
void reduceScroll();
void drawText(QPainter& p, int x, int y, tchar* text);
int m_delay;
unsigned int m_overlap;
bool m_autoScroll, m_swapmouse;
void autoscroll();
QTimer* timer;
int m_scrolldy1, m_scrolldy2, m_encd, m_scrollpart;
void focusInEvent(QFocusEvent*);
void focusOutEvent(QFocusEvent*);
void processmousepositionevent( QMouseEvent* _e );
void processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno);
bool ChangeFont(int);
bool getline(CDrawBuffer*);
int m_charWidth;
int m_charpc;
unsigned char m_border;
FontControl m_fontControl;
void setBaseSize(unsigned char _s) { m_fontControl.setBaseSize(_s); }
unsigned char getBaseSize() { return m_fontControl.getBaseSize(); }
#ifdef _SCROLLPIPE
FILE* m_pipeout;
QString m_pipetarget;
bool m_isPaused;
bool m_pauseAfterEachPara;
#endif
public:
QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0);
// QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0);
~QTReader();
void zoomin();
void zoomout();
void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
{
buffdoc.setSaveData(data, len, src, srclen);
}
void putSaveData(unsigned char*& src, unsigned short& srclen)
{
buffdoc.putSaveData(src, srclen);
}
bool empty();
void setContinuous(bool _b);
void toggle_autoscroll();
void setautoscroll(bool);
void disableAutoscroll() { m_autoScroll = false; }
void copy()
{
/*
size_t nd = locate();
jumpto(m_mark);
QString text;
while (m_mark < nd)
{
text += buffdoc.getch();
m_mark++;
}
QApplication::clipboard()->setText(text);
jumpto(nd);
*/
};
void clear() {};
void setText(const QString& n, const QString& s) { m_string = n; load_file((const char*)s); };
/*
void setText(bool oldfile)
{
if (oldfile)
{
m_string = m_lastfile;
load_file((const tchar*)m_string);
}
else
{
m_string = QString::null;
}
};
*/
void setlead(int _lead)
{
m_fontControl.setlead(_lead);
}
int getlead()
{
return m_fontControl.getlead();
}
void setextraspace(int _lead)
{
m_fontControl.setextraspace(_lead);
}
int getextraspace()
{
return m_fontControl.getextraspace();
}
void setpagemode(bool _b)
{
m_bpagemode = _b;
}
void setmono(bool _b)
{
m_bMonoSpaced = _b;
ChangeFont(m_fontControl.currentsize());
locate(pagelocate());
}
void setencoding(int _f)
{
m_encd = _f;
setfilter(getfilter());
}
MarkupType PreferredMarkup();
CEncoding* getencoding()
{
-// qDebug("m_encd:%d", m_encd);
+// odebug << "m_encd:" << m_encd << oendl;
switch (m_encd)
{
case 4:
-// qDebug("palm");
+// odebug << "palm" << oendl;
return new CPalm;
case 1:
-// qDebug("utf8");
+// odebug << "utf8" << oendl;
return new CUtf8;
case 2:
-// qDebug("ucs16be");
+// odebug << "ucs16be" << oendl;
return new CUcs16be;
case 3:
-// qDebug("ucs16le");
+// odebug << "ucs16le" << oendl;
return new CUcs16le;
case 0:
-// qDebug("ascii");
+// odebug << "ascii" << oendl;
return new CAscii;
default:
return new CGeneral8Bit(m_encd-MAX_ENCODING+1);
}
}
CFilterChain* getfilter()
{
CFilterChain * filt = new CFilterChain(getencoding());
if (bstripcr) filt->addfilter(new stripcr);
if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt);
if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter);
if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml);
if (bdehyphen) filt->addfilter(new dehyphen);
if (bunindent) filt->addfilter(new unindent);
if (brepara) filt->addfilter(new repara);
if (bonespace) filt->addfilter(new OnePara);
if (bindenter) filt->addfilter(new indenter(bindenter));
if (bdblspce) filt->addfilter(new dblspce);
#ifdef REPALM
if (brepalm) filt->addfilter(new repalm);
#endif
if (bremap) filt->addfilter(new remap);
if (bdepluck) filt->addfilter(new DePluck(pluckernextpart));
if (bdejpluck) filt->addfilter(new DePluck(jplucknextpart));
if (bmakebold) filt->addfilter(new embolden);
if (bfulljust) filt->addfilter(new FullJust);
return filt;
}
private slots:
void goHome();
void goBack();
void goForward();
void doscroll();
void drawIt( QPainter * );
void paintEvent( QPaintEvent * );
// void resizeEvent( QResizeEvent * p ) { update(); }
void keyPressEvent(QKeyEvent*);
void drawFonts(QPainter*);
private:
void setTwoTouch(bool _b);
void init();
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
// void mouseDoubleClickEvent( QMouseEvent* );
QString m_string, m_fontname;
void setfont();
//myoutput stuff
private:
bool mouseUpOn;
linkType getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt);
bool m_twotouch, m_touchone;
size_t m_startpos, m_startoffset;
void dopageup(unsigned int);
void dopageup();
void lineDown();
void lineUp();
void dopagedn();
long real_delay();
int m_textsize;
int m_lastwidth, m_lastheight;
CBufferFace<CDrawBuffer*> textarray;
CBufferFace<size_t> locnarray;
unsigned int numlines;
// bool m_showlast;
bool bstripcr, btextfmt, bstriphtml, bdehyphen, bdepluck, bdejpluck, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt, bonespace, bfulljust;
#ifdef REPALM
bool brepalm;
#endif
bool m_bpagemode, m_bMonoSpaced, m_continuousDocument;
unsigned char bindenter;
QString m_lastfile;
size_t m_lastposn;
public:
bool bDoUpdates;
void NavUp();
void NavDown();
tchar getch() { return buffdoc.getch(); }
bool synch(size_t, size_t);
bool tight;
bool load_file(const char *newfile, unsigned int lcn=0);
BuffDoc buffdoc;
CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); }
bool locate(unsigned long n);
void jumpto(unsigned long n) { buffdoc.unsuspend(); buffdoc.locate(n); }
unsigned long locate() { buffdoc.unsuspend(); return buffdoc.locate(); }
unsigned long explocate() { buffdoc.unsuspend(); return buffdoc.explocate(); }
unsigned long pagelocate() { return locnarray[0]; }
unsigned long mylastpos;
void setfilter(CFilterChain *f) { buffdoc.unsuspend(); buffdoc.setfilter(f); locate(pagelocate()); }
void restore() { jumpto(mylastpos); }
void goUp();
void refresh() { locate(pagelocate()); }
void goDown();
// bool bold;
int textsize() { return m_textsize; }
void textsize(int ts) { m_textsize = ts; }
bool fillbuffer(int ru = 0, int ht = 0, int newht = -1);
unsigned int screenlines();
void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.unsuspend(); buffdoc.sizes(fs,ts); }
static const char *fonts[];
// unsigned int *fontsizes;
int m_ascent, m_descent, m_linespacing;
QFontMetrics* m_fm;
QString firstword();
signals:
void OnRedraw();
void OnWordSelected(const QString&, size_t, const QString&);
void OnShowPicture(QImage&);
void OnURLSelected(const QString&);
};
#endif
diff --git a/noncore/apps/opie-reader/QTReaderApp.h b/noncore/apps/opie-reader/QTReaderApp.h
index ab6f60e..fe3eebf 100644
--- a/noncore/apps/opie-reader/QTReaderApp.h
+++ b/noncore/apps/opie-reader/QTReaderApp.h
@@ -210,233 +210,233 @@ private slots:
{
m_doAnnotation = _b;
}
void OnDictionary(bool _b)
{
m_doDictionary = _b;
}
void OnClipboard(bool _b)
{
m_doClipboard = _b;
}
void OnWordSelected(const QString&, size_t, const QString&);
void OnURLSelected(const QString& href);
void showgraphic(QImage&);
void addAnno(const QString&, const QString&, size_t);
void addAnno(const QString&, const QString&);
void addanno();
void showAnnotation();
void do_setencoding(int i);
void do_setfont(const QString&);
void buttonActionSelected(QAction*);
// void msgHandler(const QCString&, const QByteArray&);
void monospace(bool);
void jump();
void settarget();
#ifdef _SCROLLPIPE
// void setpipetarget();
// void setpause(bool);
#endif
// void setspacing();
void setfont();
void clearBkmkList();
void listBkmkFiles();
void editMark();
void autoScroll(bool);
void addbkmk();
void savebkmks();
// void importFiles();
void showprefs();
void showtoolbarprefs();
void infoClose();
// void oldFile();
void showinfo();
// void indentplus();
// void indentminus();
void fileOpen();
void fileClose();
void editCopy();
void editFind();
void gotoStart();
void gotoEnd();
void pageup();
void pagedn();
void findNext();
void findClose();
void regClose();
#ifdef __ISEARCH
// void search( const QString& );
#else
void search();
#endif
void showEditTools();
// void stripcr(bool);
// void setfulljust(bool);
// void onespace(bool);
#ifdef REPALM
// void repalm(bool);
#endif
// void peanut(bool _b);
// void remap(bool);
// void embolden(bool);
// void autofmt(bool);
// void textfmt(bool);
// void striphtml(bool);
// void dehyphen(bool);
// void depluck(bool);
// void dejpluck(bool);
// void unindent(bool);
// void repara(bool);
// void dblspce(bool);
void pagemode(bool);
// void gotobkmk(const QString& bm);
void gotobkmk(int);
void cancelbkmk();
void do_gotomark();
void do_delmark();
void do_autogen();
void do_regaction();
void OnRedraw();
private:
void writeUrl(const QString& file, const QString& href);
QAction *m_preferences_action, *m_open_action, *m_close_action;
QAction *m_info_action, *m_touch_action, *m_find_action, *m_start_action;
QAction *m_end_action, *m_jump_action, *m_pageline_action;
QAction *m_pageup_action, *m_pagedn_action, *m_back_action;
QAction *m_home_action, *m_forward_action, *m_zoomin_action;
QAction *m_zoomout_action, *m_setfont_action, *m_mark_action;
QAction *m_annotate_action, *m_goto_action, *m_delete_action;
QAction *m_autogen_action, *m_clear_action, *m_save_action;
QAction *m_tidy_action, *m_startBlock_action, *m_endBlock_action;
QAction *m_setenc_action, *m_setmono_action, *m_saveconfig_action;
QAction *m_loadconfig_action, *m_toolbarprefs_action, *m_tidyconfig_action;
QAction *m_exportlinks_action;
void addtoolbars(Config* config);
ToolbarPolicy m_tbpol, m_tbpolsave;
ToolBarDock m_tbposition;
bool m_tbmove, m_tbmovesave;
QToolBar* filebar();
QToolBar* viewbar();
QToolBar* navbar();
QToolBar* markbar();
void hidetoolbars();
void addfilebar(Config* _config, const QString& key, QAction* a);
void addviewbar(Config* _config, const QString& key, QAction* a);
void addnavbar(Config* _config, const QString& key, QAction* a);
void addmarkbar(Config* _config, const QString& key, QAction* a);
bool checkbar(Config* _config, const QString& key);
#ifdef _SCRIPT
void SaveScript(const char* sname);
#endif
/*
void setstate(unsigned char* _sd, unsigned short _sdlen);
void getstate(unsigned char*& data, unsigned short& len);
*/
void fileOpen2();
void readfilelist();
void savefilelist();
void updatefileinfo();
bool openfrombkmk(Bkmk*);
QString m_targetapp, m_targetmsg;
bool listbkmk(CList<Bkmk>*, const QString& _lab = QString::null);
QString usefilebrowser();
void do_regedit();
void colorChanged( const QColor &c );
void clear();
void updateCaption();
void do_autogen(const QString&);
void do_addbkmk(const QString&);
bool findNextBookmark(size_t start);
private:
QAction* m_scrollButton;
QAction* m_buttonAction[MAX_ACTIONS];
CBkmkSelector* bkmkselector;
ActionTypes m_spaceTarget, m_escapeTarget, m_returnTarget, m_leftTarget, m_rightTarget,
m_upTarget, m_downTarget;
bool m_leftScroll, m_rightScroll, m_upScroll, m_downScroll;
bool m_bcloseDisabled, m_disableesckey;
size_t searchStart;
#ifdef __ISEARCH
QStack<searchrecord>* searchStack;
bool dosearch(size_t start, CDrawBuffer& test, const QString& arg);
#else
bool dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg);
#endif
QWidgetStack *editorStack;
QTReader* reader;
QComboBox* m_fontSelector;
// QToolBar /* *menu,*/ *fileBar;
QToolBar *menubar, *fileBar, *navBar, *viewBar, *markBar;
#ifdef USEQPE
QMenuBar *mb;
#else
QMenuBar *mb;
#endif
QFloatBar *searchBar, *regBar/*, *m_fontBar*/;
QToolBar /* *searchBar, *regBar,*/ *m_fontBar;
QLineEdit *searchEdit, *regEdit;
bool searchVisible;
bool regVisible;
bool m_fontVisible, m_twoTouch;
bool bFromDocView;
static unsigned long m_uid;
long unsigned get_unique_id() { return m_uid++; }
/*
void resizeEvent( QResizeEvent * r)
{
-// qDebug("resize:(%u,%u)", r->oldSize().width(), r->oldSize().height());
-// qDebug("resize:(%u,%u)", r->size().width(), r->size().height());
+// odebug << "resize:(" << r->oldSize().width() << "," << r->oldSize().height() << ")" << oendl;
+// odebug << "resize:(" << r->size().width() << "," << r->size().height() << ")" << oendl;
// bgroup->move( width()-bgroup->width(), 0 );
}
*/
CList<Bkmk>* pBkmklist;
CList<Bkmk>* pOpenlist;
infowin* m_infoWin;
GraphicWin* m_graphicwin;
QProgressBar* pbar;
bool m_fBkmksChanged;
// int m_nRegAction;
regedit_type m_nRegAction;
bkmk_action m_nBkmkAction;
QString m_autogenstr;
bool m_dontSave;
};
//const int cAutoGen = 0;
//const int cAddBkmk = 1;
//const int cDelBkmk = 2;
//const int cGotoBkmk = 3;
//const int cRmBkmkFile = 4;
//const int cJump = 5;
//const int cMonoSpace = 6;
//const int cOverlap = 7;
//const int cSetTarget = 8;
//const int cOpenFile = 9;
//const int cSetPipeTarget = 10;
//const int cSetConfigName = 11;
//const int cMargin = 12;
//const int cExtraSpace = 14;
//const int cExtraLead = 15;
//const int cGfxSize = 16;
//const int cChooseFont = 2;
//const int cChooseEncoding = 1;
#endif
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.h b/noncore/apps/tinykate/libkate/document/katedocument.h
index 9d8ec6a..969be87 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.h
+++ b/noncore/apps/tinykate/libkate/document/katedocument.h
@@ -1,271 +1,271 @@
/***************************************************************************
katedocument.h - description
-------------------
begin : Mon Jan 15 2001
copyright : (C) 2001 by Christoph "Crossfire" Cullmann
(C) 2002 by Joseph Wenninger
email : crossfire@babylon2k.de
jowenn@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
/*
Copyright (C) 1998, 1999 Jochen Wilhelmy
digisnap@cs.tu-berlin.de
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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.
*/
#ifndef kate_document_h
#define kate_document_h
#include <qobject.h>
#include <qlist.h>
#include <qcolor.h>
#include <qfont.h>
#include <qfontmetrics.h>
#include <qdatetime.h>
#include <qfileinfo.h>
#include "../view/kateview.h"
#include "katehighlight.h"
#include "katebuffer.h"
#include "katetextline.h"
#include <qptrdict.h>
class KateCmd;
class CachedFontMetrics : public QFontMetrics {
private:
short *warray[256];
public:
CachedFontMetrics(const QFont& f) : QFontMetrics(f) {
for (int i=0; i<256; i++) warray[i]=0;
}
~CachedFontMetrics() {
for (int i=0; i<256; i++)
if (warray[i]) delete[] warray[i];
}
int width(QChar c) {
uchar cell=c.cell();
uchar row=c.row();
short *wa=warray[row];
if (!wa) {
- // qDebug("create row: %d",row);
+ // odebug << "create row: " << row << oendl;
wa=warray[row]=new short[256];
for (int i=0; i<256; i++) wa[i]=-1;
}
if (wa[cell]<0) wa[cell]=(short) QFontMetrics::width(c);
return (int)wa[cell];
}
int width(QString s) { return QFontMetrics::width(s); }
};
class Attribute {
public:
Attribute() { ; };
QColor col;
QColor selCol;
bool bold;
bool italic;
};
class KateAction {
public:
enum Action {replace, wordWrap, wordUnWrap, newLine, delLine,
insLine, killLine};//, doubleLine, removeLine};
KateAction(Action, PointStruc &cursor, int len = 0,
const QString &text = QString::null);
Action action;
PointStruc cursor;
int len;
QString text;
KateAction *next;
};
class KateActionGroup {
public:
// the undo group types
enum { ugNone, //
ugPaste, // paste
ugDelBlock, // delete/replace selected text
ugIndent, // indent
ugUnindent, // unindent
ugComment, // comment
ugUncomment, // uncomment
ugReplace, // text search/replace
ugSpell, // spell check
ugInsChar, // char type/deleting
ugDelChar, // '' ''
ugInsLine, // line insert/delete
ugDelLine // '' ''
};
KateActionGroup(PointStruc &aStart, int type = ugNone);
~KateActionGroup();
void insertAction(KateAction *);
static const char * typeName(int type);
PointStruc start;
PointStruc end;
KateAction *action;
int undoType;
};
/**
The text document. It contains the textlines, controls the
document changing operations and does undo/redo. WARNING: do not change
the text contents directly in methods where this is not explicitly
permitted. All changes have to be made with some basic operations,
which are recorded by the undo/redo system.
@see TextLine
@author Jochen Wilhelmy
*/
class KateDocument: public Kate::Document
{
Q_OBJECT
friend class KateViewInternal;
friend class KateView;
friend class KateIconBorder;
public:
KateDocument(bool bSingleViewMode=false, bool bBrowserView=false, QWidget *parentWidget = 0, const char *widgetName = 0, QObject * = 0, const char * = 0);
~KateDocument();
protected:
QFont myFont, myFontBold, myFontItalic, myFontBI;
CachedFontMetrics myFontMetrics, myFontMetricsBold, myFontMetricsItalic, myFontMetricsBI;
public:
void setFont (QFont font);
QFont getFont () { return myFont; };
CachedFontMetrics getFontMetrics () { return myFontMetrics; };
virtual bool saveFile();
virtual KTextEditor::View *createView( QWidget *parent, const char *name );
virtual QString textLine( int line ) const;
virtual void insertLine( const QString &s, int line = -1 );
void insert_Line(const QString& s,int line=-1, bool update=true);
void remove_Line(int line,bool update=true);
void replaceLine(const QString& s,int line=-1);
virtual void insertAt( const QString &s, int line, int col, bool mark = FALSE );
virtual void removeLine( int line );
virtual int length() const;
virtual void setSelection( int row_from, int col_from, int row_to, int col_t );
virtual bool hasSelection() const;
virtual QString selection() const;
// only to make part work, don't change it !
bool m_bSingleViewMode;
// public interface
/**
* gets the number of lines
*/
virtual int numLines() const;
/**
* gets the last line number (numLines() -1)
*/
int lastLine() const {return numLines()-1;}
/**
gets the given line
@return the TextLine object at the given line
@see TextLine
*/
TextLine::Ptr getTextLine(int line) const;
/**
get the length in pixels of the given line
*/
int textLength(int line);
void setTabWidth(int);
int tabWidth() {return tabChars;}
void setReadOnly(bool);
bool isReadOnly() const;
void setNewDoc( bool );
bool isNewDoc() const;
virtual void setReadWrite( bool ){};
virtual bool isReadWrite() const {return true;}
virtual void setModified(bool);
virtual bool isModified() const;
void setSingleSelection(bool ss) {m_singleSelection = ss;}
bool singleSelection() {return m_singleSelection;}
void readConfig();
void writeConfig();
void readSessionConfig(KateConfig *);
void writeSessionConfig(KateConfig *);
bool hasBrowserExtension() const { return m_bBrowserView; }
protected:
bool m_bBrowserView;
signals:
void selectionChanged();
void highlightChanged();
void modifiedChanged ();
void preHighlightChanged(long);
// search stuff
protected:
static QStringList searchForList;
static QStringList replaceWithList;
static uint uniqueID;
// highlight stuff
public:
Highlight *highlight() {return m_highlight;}
int highlightNum() {return hlManager->findHl(m_highlight);}
int numAttribs() {return m_numAttribs;}
Attribute *attribs() {return m_attribs;}
void setDontChangeHlOnSave();
protected:
void setHighlight(int n);
void makeAttribs();
void updateFontData();
protected slots:
void hlChanged();
// view interaction
public:
virtual void addView(KTextEditor::View *);
virtual void removeView(KTextEditor::View *);
diff --git a/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp b/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
index a2c680f..78635b2 100644
--- a/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
+++ b/noncore/apps/tinykate/libkate/qt3back/qregexp3.cpp
@@ -1,246 +1,252 @@
/****************************************************************************
** $Id$
**
** Implementation of QRegExp class
**
** Created : 950126
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#if QT_VERSION >=300
#error QRegExp3 is now in QT 3 use QRegExp instead
#endif
-#include "qarray.h"
-#include "qbitarray.h"
-#include "qcache.h"
-#include "qintdict.h"
-#include "qmap.h"
#if QT_VERSION < 300
#include "./qregexp3.h"
#else
#include "qregexp.h"
#endif
-#include "qstring.h"
-#include "qtl.h"
-#include "qvector.h"
+/* OPIE */
+#include <opie2/odebug.h>
+
+/* QT */
+#include <qarray.h>
+#include <qbitarray.h>
+#include <qcache.h>
+#include <qintdict.h>
+#include <qmap.h>
+#include <qstring.h>
+#include <qtl.h>
+#include <qvector.h>
+
+/* STD */
#include <limits.h>
/*
WARNING! Be sure to read qregexp.tex before modifying this file.
*/
/*!
\class QRegExp3 qregexp.h
\brief The QRegExp class provides pattern matching using regular expressions.
\ingroup tools
\ingroup misc
\ingroup shared
Regular expressions, "regexps", provide a way to find patterns
within text. This is useful in many contexts, for example:
<ol>
<li>\e Validation. A regexp can be used to check whether a piece of
text meets some criteria, e.g. is an integer or contains no
whitespace.
<li>\e Searching. Regexps provide a much more powerful means of
searching text than simple string matching does. For example we can
create a regexp which says "find one of the words 'mail', 'letter'
or 'correspondence' but not any of the words 'email', 'mailman'
'mailer', 'letterbox' etc."
<li><em>Search and Replace.</em> A regexp can be used to replace a
pattern with a piece of text, for example replace all occurrences of
'&' with '\&amp;' except where the '&' is already followed by
'amp;'.
<li><em>String Splitting.</em> A regexp can be used to identify
where a string should be split into its component fields, e.g.
splitting tab delimited strings.
</ol>
We present a very brief introduction to regexps, a description of
Qt's regexp language, some code examples, and finally the function
documentation. QRegExp is modelled on Perl's regexp engine and fully
supports Unicode. QRegExp may also be used in the weaker 'wildcard'
(globbing) mode which works in a similar way to command shells. A
good text on regexps is <i>Mastering Regular Expressions: Powerful
Techniques for Perl and Other Tools</i> by Jeffrey E. Friedl, ISBN
1565922573.
Experienced regexp users may prefer to skip the introduction and
go directly to the relevant information:
<ul>
<li><a href="#characters-and-abbreviations-for-sets-of-characters">
Characters and Abbreviations for Sets of Characters</a>
<li><a href="#sets-of-characters">Sets of Characters</a>
<li><a href="#quantifiers">Quantifiers</a>
<li><a href="#capturing-text">Capturing Text</a>
<li><a href="#assertions">Assertions</a>
<li><a href="#wildcard-matching">Wildcard Matching (globbing)</a>
<li><a href="#perl-users">Notes for Perl Users</a>
<li><a href="#code-examples">Code Examples</a>
<li><a href="#member-function-documentation">Member Function Documentation</a>
</ul>
<b>Introduction</b>
Regexps are built up from expressions, quantifiers and assertions.
The simplest form of expression is simply a character, e.g. <b>x</b>
or <b>5</b>. An expression can also be a set of characters. For
example, <b>[ABCD]</b>, will match an <b>A</b> or a <b>B</b> or a
<b>C</b> or a <b>D</b>. As a shorthand we could write this as
<b>[A-D]</b>. If we want to match any of the captital letters in the
English alphabet we can write <b>[A-Z]</b>. A quantifier tells the
regexp engine how many occurrences of the expression we want, e.g.
<b>x{1,1}</b> means match an <b>x</b> which occurs at least once and
at most once. We'll look at assertions and more complex expressions
later. Note that regexps cannot be used to check for balanced
brackets or tags (unless you know the maximum level of nesting).
We'll start by writing a regexp to match integers in the range 0 to
99. We will require at least one digit so we will start with
<b>[0-9]{1,1}</b> which means match a digit exactly once. This
regexp alone will match integers in the range 0 to 9. To match one
or two digits we can increase the maximum number of occurrences so
the regexp becomes <b>[0-9]{1,2}</b> meaning match a digit at least
once and at most twice. However, this regexp as it stands will not
match correctly. This regexp will match one or two digits \e within
a string. To ensure that we match against the whole string we must
use the anchor assertions. We need <b>^</b> (caret) which when it is
the first character in the regexp means that the regexp must match
from the beginning of the string. And we also need <b>$</b> (dollar)
which when it is the last character in the regexp means that the
regexp must match until the end of the string. So now our regexp is
<b>^[0-9]{1,2}$</b>. Note that assertions do not match any
characters.
If you've seen regexps elsewhere they may have looked different from
the one above. This is because some sets of characters and some
quantifiers are so common that they have special symbols to
represent them. <b>[0-9]</b> can be replaced with the symbol
<b>\d</b>. The quantifier to match exactly one occurrence,
<b>{1,1}</b>, can be replaced with the expression itself. This means
that <b>x{1,1}</b> is exactly the same as <b>x</b> alone. So our 0
to 99 matcher could be written: <b>^\d{1,2}$</b>, although most
people would write it <b>^\d\d?$</b>. The <b>?</b> is the same as
the quantifier <b>{0,1}</b>, i.e. a minimum of no occurrences a
maximum of one occurrence. This is used to make an expression
optional. The regexp <b>^\d\d?$</b> means "from the beginning of the
string match one digit followed by zero or one digits and then the
end of the string".
Our second example is matching the words 'mail', 'letter' or
'correspondence' but without matching 'email', 'mailman', 'mailer',
'letterbox' etc. We'll start by just matching 'mail'. In full the
regexp is, <b>m{1,1}a{1,1}i{1,1}l{1,1}</b>, but since an expression
itself is automatically quantified by <b>{1,1}</b> we can simply
write this as <b>mail</b>; an 'm' followed by an 'a' followed by an
'i' followed by an 'l'. The symbol '|' (bar) is used for \e
alternation, so our regexp now becomes
<b>mail|letter|correspondence</b> which means match 'mail' \e or
'letter' \e or 'correspondence'. Whilst this regexp will find the
words we want it will also find words we don't want such as 'email'.
We will start by putting our regexp in parenthesis
<b>(mail|letter|correspondence)</b>. Parenthesis have two effects,
firstly they group expressions together and secondly they identify
parts of the regexp that we wish to <a href="#capturing-text">capture</a>.
Our regexp still matches any of the three words but now they are
grouped together as a unit. This is useful for building up more
complex regexps. It is also useful because it allows us to examine
which of the words actually matched. We need to use another
assertion, this time <b>\b</b> "word boundary":
<b>\b(mail|letter|correspondence)\b</b>. This regexp means "match a
word boundary followed by the expression in parenthesis followed by
another word boundary". The <b>\b</b> assertion matches at a \e
position in the regexp not a \e character in the regexp. A word
boundary is any non-word character such as a space a newline or the
beginning or end of the string.
For our third example we want to replace ampersands with the HTML
entity '\&amp;'. The regexp to match is simple: <b>\&</b>, i.e.
match one ampersand. Unfortunately this will mess up our text if
some of the ampersands have already been turned into HTML entities.
So what we really want to say is replace an ampersand providing it
is not followed by 'amp;'. For this we need the negative lookahead
assertion and our regexp becomes: <b>\&(?!amp;)</b>. The negative
lookahead assertion is introduced with '(?!' and finishes at the
')'. It means that the text it contains, 'amp;' in our example, must
\e not follow the expression that preceeds it.
Regexps provide a rich language that can be used in a variety of
ways. For example suppose we want to count all the occurrences of
'Eric' and 'Eirik' in a string. Two valid regexps to match these are
<b>\\</b><b>b(Eric|Eirik)</b><b>\\</b><b>b</b> and
<b>\\</b><b>bEi?ri[ck]</b><b>\\</b><b>b</b>. We need the word boundary
'\b' so we don't get 'Ericsson' etc. The second regexp actually
matches more than we want, 'Eric', 'Erik', 'Eiric' and 'Eirik'.
We will implement some the examples above in the
<a href="#code-examples">code examples</a> section.
<a name="characters-and-abbreviations-for-sets-of-characters">
<b>Characters and Abbreviations for Sets of Characters</b></a>
<ul>
<li><b>c</b> Any character represents itself unless it has a special regexp
meaning. Thus <b>c</b> matches the character \e c.
<li><b>\\</b><b>c</b> A character that follows a backslash matches the
character itself except where mentioned below. For example if you
wished to match a literal caret at the beginning of a string you
would write <b>\^</b>.
<li><b>\\</b><b>a</b> This matches the ASCII bell character (BEL, 0x07).
<li><b>\\</b><b>f</b> This matches the ASCII form feed character (FF, 0x0C).
<li><b>\\</b><b>n</b> This matches the ASCII line feed character (LF, 0x0A), (Unix newline).
<li><b>\\</b><b>r</b> This matches the ASCII carriage return character (CR, 0x0D).
<li><b>\\</b><b>t</b> This matches the ASCII horizontal tab character (HT, 0x09).
<li><b>\\</b><b>v</b> This matches the ASCII vertical tab character (VT, 0x0B).
<li><b>\\</b><b>xhhhh</b> This matches the Unicode character corresponding
to the hexadecimal number hhhh (between 0x0000 and 0xFFFF). \0ooo
(i.e., \zero ooo) matches the ASCII/Latin-1 character corresponding
to the octal number ooo (between 0 and 0377).
<li><b>. (dot)</b> This matches any character (including newline).
<li><b>\\</b><b>d</b> This matches a digit (see QChar::isDigit()).
<li><b>\\</b><b>D</b> This matches a non-digit.
<li><b>\\</b><b>s</b> This matches a whitespace (see QChar::isSpace()).
<li><b>\\</b><b>S</b> This matches a non-whitespace.
<li><b>\\</b><b>w</b> This matches a word character (see QChar::isLetterOrNumber()).
<li><b>\\</b><b>W</b> This matches a non-word character.
<li><b>\\</b><b>n</b> The n<sup>th</sup>
<a href="#capturing-text">backreference</a>, e.g. \1, \2, etc.
</ul>
@@ -1242,428 +1248,428 @@ QArray<int> QRegExpEngine::match( const QString& str, int pos, bool minimal,
} else {
return mmCapturedNoMatch;
}
}
/*
The three following functions add one state to the automaton and return the
number of the state.
*/
int QRegExpEngine::createState( QChar ch )
{
return setupState( ch.unicode() );
}
int QRegExpEngine::createState( const CharClass& cc )
{
#ifndef QT_NO_REGEXP_CCLASS
int n = cl.size();
cl.resize( n + 1 );
cl.insert( n, new CharClass(cc) );
return setupState( CharClassBit | n );
#else
Q_UNUSED( cc );
return setupState( CharClassBit );
#endif
}
#ifndef QT_NO_REGEXP_BACKREF
int QRegExpEngine::createState( int bref )
{
if ( bref > nbrefs ) {
nbrefs = bref;
if ( nbrefs > MaxBackRefs ) {
yyError = TRUE;
return 0;
}
}
return setupState( BackRefBit | bref );
}
#endif
/*
The two following functions add a transition between all pairs of states
(i, j) where i is fond in from, and j is found in to.
Cat-transitions are distinguished from plus-transitions for capturing.
*/
void QRegExpEngine::addCatTransitions( const QArray<int>& from,
const QArray<int>& to )
{
for ( int i = 0; i < (int) from.size(); i++ ) {
State *st = s[from[i]];
mergeInto( &st->outs, to );
}
}
#ifndef QT_NO_REGEXP_CAPTURE
void QRegExpEngine::addPlusTransitions( const QArray<int>& from,
const QArray<int>& to, int atom )
{
for ( int i = 0; i < (int) from.size(); i++ ) {
State *st = s[from[i]];
QArray<int> oldOuts = st->outs.copy();
mergeInto( &st->outs, to );
if ( f[atom].capture >= 0 ) {
if ( st->reenter == 0 )
st->reenter = new QMap<int, int>;
for ( int j = 0; j < (int) to.size(); j++ ) {
if ( !st->reenter->contains(to[j]) &&
oldOuts.bsearch(to[j]) < 0 )
st->reenter->insert( to[j], atom );
}
}
}
}
#endif
#ifndef QT_NO_REGEXP_ANCHOR_ALT
/*
Returns an anchor that means a OR b.
*/
int QRegExpEngine::anchorAlternation( int a, int b )
{
if ( ((a & b) == a || (a & b) == b) && ((a | b) & Anchor_Alternation) == 0 )
return a & b;
int n = aa.size();
aa.resize( n + 1 );
aa[n].a = a;
aa[n].b = b;
return Anchor_Alternation | n;
}
/*
Returns an anchor that means a AND b.
*/
int QRegExpEngine::anchorConcatenation( int a, int b )
{
if ( ((a | b) & Anchor_Alternation) == 0 )
return a | b;
if ( (b & Anchor_Alternation) != 0 )
qSwap( a, b );
int aprime = anchorConcatenation( aa[a ^ Anchor_Alternation].a, b );
int bprime = anchorConcatenation( aa[a ^ Anchor_Alternation].b, b );
return anchorAlternation( aprime, bprime );
}
#endif
/*
Adds anchor a on a transition caracterised by its from state and its to state.
*/
void QRegExpEngine::addAnchors( int from, int to, int a )
{
State *st = s[from];
if ( st->anchors == 0 )
st->anchors = new QMap<int, int>;
if ( st->anchors->contains(to) )
a = anchorAlternation( (*st->anchors)[to], a );
st->anchors->insert( to, a );
}
#ifndef QT_NO_REGEXP_OPTIM
/*
The two following functions provide the engine with the information needed by
its matching heuristics.
*/
void QRegExpEngine::setupGoodStringHeuristic( int earlyStart, int lateStart,
const QString& str )
{
goodEarlyStart = earlyStart;
goodLateStart = lateStart;
goodStr = cs ? str : str.lower();
}
void QRegExpEngine::setupBadCharHeuristic( int minLen,
const QArray<int>& firstOcc )
{
minl = minLen;
occ1 = cs ? firstOcc : *firstOccurrenceAtZero;
}
/*
This function chooses between the good-string and the bad-character
heuristics. It computes two scores and chooses the heuristic with the highest
score.
Here are some common-sense constraints on the scores that should be respected
if the formulas are ever modified: (1) If goodStr is empty, the good-string
heuristic scores 0. (2) If the search is case insensitive, the good-string
heuristic should be used, unless it scores 0. (Case insensitivity
turns all entries of occ1 to 0.) (3) If (goodLateStart - goodEarlyStart) is
big, the good-string heuristic should score less.
*/
void QRegExpEngine::heuristicallyChooseHeuristic()
{
int i;
if ( minl == 0 )
return;
/*
Magic formula: The good string has to constitute a good proportion of the
minimum-length string, and appear at a more-or-less known index.
*/
int goodStringScore = ( 64 * goodStr.length() / minl ) -
( goodLateStart - goodEarlyStart );
/*
Less magic formula: We pick a couple of characters at random, and check
whether they are good or bad.
*/
int badCharScore = 0;
int step = QMAX( 1, NumBadChars / 32 );
for ( i = 1; i < NumBadChars; i += step ) {
if ( occ1[i] == NoOccurrence )
badCharScore += minl;
else
badCharScore += occ1[i];
}
badCharScore /= minl;
useGoodStringHeuristic = ( goodStringScore > badCharScore );
}
#endif
#if defined(QT_DEBUG)
void QRegExpEngine::dump() const
{
int i, j;
- qDebug( "Case %ssensitive engine", cs ? "" : "in" );
- qDebug( " States" );
+ odebug << "Case " << (cs ? "" : "in") << "sensitive engine" << oendl;
+ odebug << " States" << oendl;
for ( i = 0; i < ns; i++ ) {
- qDebug( " %d%s", i,
- i == InitialState ? " (initial)" :
- i == FinalState ? " (final)" : "" );
+ odebug << " " << i
+ << (i == InitialState ? " (initial)" : i == FinalState ? " (final)" : "") << oendl;
+
#ifndef QT_NO_REGEXP_CAPTURE
- qDebug( " in atom %d", s[i]->atom );
+ odebug << " in atom " << s[i]->atom << oendl;
#endif
int m = s[i]->match;
if ( (m & CharClassBit) != 0 ) {
- qDebug( " match character class %d", m ^ CharClassBit );
+ odebug << " match character class " << (m ^ CharClassBit) << oendl;
#ifndef QT_NO_REGEXP_CCLASS
cl[m ^ CharClassBit]->dump();
#else
- qDebug( " negative character class" );
+ odebug << " negative character class" << oendl;
#endif
} else if ( (m & BackRefBit) != 0 ) {
- qDebug( " match back-reference %d", m ^ BackRefBit );
+ odebug << " match back-reference " << (m ^ BackRefBit) << oendl;
} else if ( m >= 0x20 && m <= 0x7e ) {
- qDebug( " match 0x%.4x (%c)", m, m );
+ odebug << " match " << QString().sprintf( "0x%.4x", m) << " (" << m << ")" << oendl;
+
} else {
- qDebug( " match 0x%.4x", m );
+ odebug << " match " << QString().sprintf( "0x%.4x", m) << oendl;
}
for ( j = 0; j < (int) s[i]->outs.size(); j++ ) {
int next = s[i]->outs[j];
- qDebug( " -> %d", next );
+ odebug << " -> " << next << oendl;
if ( s[i]->reenter != 0 && s[i]->reenter->contains(next) )
- qDebug( " [reenter %d]", (*s[i]->reenter)[next] );
+ odebug << " [reenter " << (*s[i]->reenter)[next] << "]" << oendl;
if ( s[i]->anchors != 0 && at(*s[i]->anchors, next) != 0 )
- qDebug( " [anchors 0x%.8x]", (*s[i]->anchors)[next] );
+ odebug << " [anchors " << QString().sprintf( "0x%.8x]", (*s[i]->anchors)[next] ) << oendl;
}
}
#ifndef QT_NO_REGEXP_CAPTURE
if ( nf > 0 ) {
- qDebug( " Atom Parent Capture" );
+ odebug << " Atom Parent Capture" << oendl;
for ( i = 0; i < nf; i++ )
- qDebug( " %6d %6d %6d", i, f[i].parent, f[i].capture );
+ odebug << QString().sprintf(" %6d %6d %6d", i, f[i].parent, f[i].capture ) << oendl;
}
#endif
#ifndef QT_NO_REGEXP_ANCHOR_ALT
for ( i = 0; i < (int) aa.size(); i++ )
- qDebug( " Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i, aa[i].a,
- aa[i].b );
+ odebug << QString().sprintf(" Anchor alternation 0x%.8x: 0x%.8x 0x%.9x", i, aa[i].a, aa[i].b ) << oendl;
#endif
}
#endif
void QRegExpEngine::setup( bool caseSensitive )
{
#ifndef QT_NO_REGEXP_OPTIM
if ( engCount++ == 0 ) {
noOccurrences = new QArray<int>( NumBadChars );
firstOccurrenceAtZero = new QArray<int>( NumBadChars );
noOccurrences->fill( NoOccurrence );
firstOccurrenceAtZero->fill( 0 );
}
#endif
s.setAutoDelete( TRUE );
s.resize( 32 );
ns = 0;
#ifndef QT_NO_REGEXP_CAPTURE
f.resize( 32 );
nf = 0;
cf = -1;
#endif
realncap = 0;
ncap = 0;
#ifndef QT_NO_REGEXP_CCLASS
cl.setAutoDelete( TRUE );
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
ahead.setAutoDelete( TRUE );
#endif
#ifndef QT_NO_REGEXP_OPTIM
caretAnchored = TRUE;
#endif
valid = FALSE;
cs = caseSensitive;
#ifndef QT_NO_REGEXP_BACKREF
nbrefs = 0;
#endif
#ifndef QT_NO_REGEXP_OPTIM
useGoodStringHeuristic = FALSE;
minl = 0;
occ1 = *firstOccurrenceAtZero;
#endif
mmCapturedNoMatch.fill( -1, 2 );
}
int QRegExpEngine::setupState( int match )
{
if ( (ns & (ns + 1)) == 0 && ns + 1 >= (int) s.size() )
s.resize( (ns + 1) << 1 );
#ifndef QT_NO_REGEXP_CAPTURE
s.insert( ns, new State(cf, match) );
#else
s.insert( ns, new State(match) );
#endif
return ns++;
}
#ifndef QT_NO_REGEXP_CAPTURE
/*
Functions startAtom() and finishAtom() should be called to delimit atoms.
When a state is created, it is assigned to the current atom. The information
is later used for capturing.
*/
int QRegExpEngine::startAtom( bool capture )
{
if ( (nf & (nf + 1)) == 0 && nf + 1 >= (int) f.size() )
f.resize( (nf + 1) << 1 );
f[nf].parent = cf;
cf = nf++;
f[cf].capture = capture ? ncap++ : -1;
return cf;
}
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
/*
Creates a lookahead anchor.
*/
int QRegExpEngine::addLookahead( QRegExpEngine *eng, bool negative )
{
int n = ahead.size();
if ( n == MaxLookaheads ) {
yyError = TRUE;
return 0;
}
ahead.resize( n + 1 );
ahead.insert( n, new Lookahead(eng, negative) );
return Anchor_FirstLookahead << n;
}
#endif
#ifndef QT_NO_REGEXP_CAPTURE
/*
We want the longest leftmost captures.
*/
bool QRegExpEngine::isBetterCapture( const int *begin1, const int *end1,
const int *begin2, const int *end2 )
{
for ( int i = 0; i < ncap; i++ ) {
int delta = begin2[i] - begin1[i]; // it has to start early...
if ( delta == 0 )
delta = end1[i] - end2[i]; // ...and end late (like a party)
if ( delta != 0 )
return delta > 0;
}
return FALSE;
}
#endif
/*
Returns TRUE if anchor a matches at position mmPos + i in the input string,
otherwise FALSE.
*/
bool QRegExpEngine::testAnchor( int i, int a, const int *capBegin )
{
int j;
#ifndef QT_NO_REGEXP_ANCHOR_ALT
if ( (a & Anchor_Alternation) != 0 ) {
return testAnchor( i, aa[a ^ Anchor_Alternation].a, capBegin ) ||
testAnchor( i, aa[a ^ Anchor_Alternation].b, capBegin );
}
#endif
if ( (a & Anchor_Caret) != 0 ) {
if ( mmPos + i != 0 )
return FALSE;
}
if ( (a & Anchor_Dollar) != 0 ) {
if ( mmPos + i != mmLen )
return FALSE;
}
#ifndef QT_NO_REGEXP_ESCAPE
if ( (a & (Anchor_Word | Anchor_NonWord)) != 0 ) {
bool before = FALSE, after = FALSE;
if ( mmPos + i != 0 )
before = mmIn[mmPos + i - 1].isLetterOrNumber();
if ( mmPos + i != mmLen )
after = mmIn[mmPos + i].isLetterOrNumber();
if ( (a & Anchor_Word) != 0 && (before == after) )
return FALSE;
if ( (a & Anchor_NonWord) != 0 && (before != after) )
return FALSE;
}
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
bool catchx = TRUE;
if ( (a & Anchor_LookaheadMask) != 0 ) {
QConstString cstr = QConstString( (QChar *) mmIn + mmPos + i,
mmLen - mmPos - i );
for ( j = 0; j < (int) ahead.size(); j++ ) {
if ( (a & (Anchor_FirstLookahead << j)) != 0 ) {
catchx = ( ahead[j]->eng->match(cstr.string(), 0, TRUE,
TRUE)[0] == 0 );
if ( catchx == ahead[j]->neg )
return FALSE;
}
}
}
#endif
#ifndef QT_NO_REGEXP_CAPTURE
#ifndef QT_NO_REGEXP_BACKREF
for ( j = 0; j < nbrefs; j++ ) {
if ( (a & (Anchor_BackRef1Empty << j)) != 0 ) {
if ( capBegin[j] != EmptyCapture )
return FALSE;
}
}
#endif
#endif
return TRUE;
}
#ifndef QT_NO_REGEXP_OPTIM
/*
The three following functions are what Jeffrey Friedl would call transmissions
(or bump-alongs). Using one or the other should make no difference, except
in performance.
*/
bool QRegExpEngine::goodStringMatch()
{
int k = mmPos + goodEarlyStart;
while ( (k = mmStr->find(goodStr, k, cs)) != -1 ) {
int from = k - goodLateStart;
int to = k - goodEarlyStart;
if ( from > mmPos )
mmPos = from;
@@ -2007,650 +2013,650 @@ bool QRegExpEngine::matchHere()
mmNextCapBegin + m * ncap,
mmNextCapEnd + m * ncap) ) {
memcpy( mmNextCapBegin + m * ncap, capBegin,
ncap * sizeof(int) );
memcpy( mmNextCapEnd + m * ncap, capEnd,
ncap * sizeof(int) );
}
}
#ifndef QT_NO_REGEXP_BACKREF
/*
We are done with updating the capture zones. It's now
time to put the next state to sleep, if it needs to, and
to remove it from mmNextStack.
*/
if ( needSomeSleep > 0 ) {
zzZ = new int[1 + 2 * ncap];
zzZ[0] = next;
if ( ncap > 0 ) {
memcpy( zzZ + 1, capBegin, ncap * sizeof(int) );
memcpy( zzZ + 1 + ncap, capEnd,
ncap * sizeof(int) );
}
mmInNextStack[mmNextStack[--nnext]] = -1;
mmSleeping.insert( i + needSomeSleep, zzZ );
}
#endif
#endif
}
}
}
#ifndef QT_NO_REGEXP_CAPTURE
/*
If we reached the final state, hurray! Copy the captured zone.
*/
if ( ncap > 0 && (m = mmInNextStack[FinalState]) != -1 ) {
memcpy( mmCapBegin, mmNextCapBegin + m * ncap, ncap * sizeof(int) );
memcpy( mmCapEnd, mmNextCapEnd + m * ncap, ncap * sizeof(int) );
}
#ifndef QT_NO_REGEXP_BACKREF
/*
It's time to wake up the sleepers.
*/
if ( mmSleeping.count() > 0 ) {
while ( (zzZ = mmSleeping.take(i)) != 0 ) {
int next = zzZ[0];
int *capBegin = zzZ + 1;
int *capEnd = zzZ + 1 + ncap;
bool copyOver = TRUE;
if ( (m = mmInNextStack[zzZ[0]]) == -1 ) {
m = nnext++;
mmNextStack[m] = next;
mmInNextStack[next] = m;
} else {
copyOver = isBetterCapture( mmNextCapBegin + m * ncap,
mmNextCapEnd + m * ncap,
capBegin, capEnd );
}
if ( copyOver ) {
memcpy( mmNextCapBegin + m * ncap, capBegin,
ncap * sizeof(int) );
memcpy( mmNextCapEnd + m * ncap, capEnd,
ncap * sizeof(int) );
}
delete[] zzZ;
}
}
#endif
#endif
for ( j = 0; j < nnext; j++ )
mmInNextStack[mmNextStack[j]] = -1;
qSwap( mmCurStack, mmNextStack );
#ifndef QT_NO_REGEXP_CAPTURE
qSwap( mmCurCapBegin, mmNextCapBegin );
qSwap( mmCurCapEnd, mmNextCapEnd );
#endif
ncur = nnext;
nnext = 0;
i++;
}
#ifndef QT_NO_REGEXP_BACKREF
/*
If minimal matching is enabled, we might have some sleepers left.
*/
while ( !mmSleeping.isEmpty() ) {
zzZ = mmSleeping.take( *QIntDictIterator<int>(mmSleeping) );
delete[] zzZ;
}
#endif
match = ( mmMatchedLen >= 0 );
if ( !match )
mmMatchedLen = i - 1;
return match;
}
#ifndef QT_NO_REGEXP_CCLASS
QRegExpEngine::CharClass::CharClass()
: c( 0 ), n( FALSE )
#ifndef QT_NO_REGEXP_OPTIM
, occ1( *noOccurrences )
#endif
{
}
QRegExpEngine::CharClass& QRegExpEngine::CharClass::operator=(
const CharClass& cc )
{
c = cc.c;
r = cc.r.copy();
n = cc.n;
#ifndef QT_NO_REGEXP_OPTIM
occ1 = cc.occ1;
#endif
return *this;
}
void QRegExpEngine::CharClass::clear()
{
c = 0;
r.resize( 0 );
n = FALSE;
}
void QRegExpEngine::CharClass::setNegative( bool negative )
{
n = negative;
#ifndef QT_NO_REGEXP_OPTIM
occ1 = *firstOccurrenceAtZero;
#endif
}
void QRegExpEngine::CharClass::addCategories( int cats )
{
c |= cats;
#ifndef QT_NO_REGEXP_OPTIM
occ1 = *firstOccurrenceAtZero;
#endif
}
void QRegExpEngine::CharClass::addRange( ushort from, ushort to )
{
if ( from > to )
qSwap( from, to );
int n = r.size();
r.resize( n + 1 );
r[n].from = from;
r[n].to = to;
#ifndef QT_NO_REGEXP_OPTIM
int i;
if ( to - from < NumBadChars ) {
occ1.detach();
if ( from % NumBadChars <= to % NumBadChars ) {
for ( i = from % NumBadChars; i <= to % NumBadChars; i++ )
occ1[i] = 0;
} else {
for ( i = 0; i <= to % NumBadChars; i++ )
occ1[i] = 0;
for ( i = from % NumBadChars; i < NumBadChars; i++ )
occ1[i] = 0;
}
} else {
occ1 = *firstOccurrenceAtZero;
}
#endif
}
bool QRegExpEngine::CharClass::in( QChar ch ) const
{
#ifndef QT_NO_REGEXP_OPTIM
if ( occ1[BadChar(ch)] == NoOccurrence )
return n;
#endif
if ( c != 0 && (c & (1 << (int) ch.category())) != 0 )
return !n;
for ( int i = 0; i < (int) r.size(); i++ ) {
if ( ch.unicode() >= r[i].from && ch.unicode() <= r[i].to )
return !n;
}
return n;
}
#if defined(QT_DEBUG)
void QRegExpEngine::CharClass::dump() const
{
int i;
- qDebug( " %stive character class", n ? "nega" : "posi" );
+ odebug << " " << (n ? "nega" : "posi") << "tive character class" << oendl;
#ifndef QT_NO_REGEXP_CCLASS
if ( c != 0 )
- qDebug( " categories 0x%.8x", c );
+ odebug << QString().sprintf(" categories 0x%.8x", c ) << oendl;
#endif
for ( i = 0; i < (int) r.size(); i++ )
- qDebug( " 0x%.4x through 0x%.4x", r[i].from, r[i].to );
+ odebug << QString().sprintf(" 0x%.4x through 0x%.4x", r[i].from, r[i].to ) << oendl;
}
#endif
#endif
QRegExpEngine::Box::Box( QRegExpEngine *engine )
: eng( engine ), skipanchors( 0 )
#ifndef QT_NO_REGEXP_OPTIM
, earlyStart( 0 ), lateStart( 0 ), maxl( 0 ), occ1( *noOccurrences )
#endif
{
minl = 0;
}
QRegExpEngine::Box& QRegExpEngine::Box::operator=( const Box& b )
{
eng = b.eng;
ls = b.ls;
rs = b.rs;
lanchors = b.lanchors;
ranchors = b.ranchors;
skipanchors = b.skipanchors;
#ifndef QT_NO_REGEXP_OPTIM
earlyStart = b.earlyStart;
lateStart = b.lateStart;
str = b.str;
leftStr = b.leftStr;
rightStr = b.rightStr;
maxl = b.maxl;
occ1 = b.occ1;
#endif
minl = b.minl;
return *this;
}
void QRegExpEngine::Box::set( QChar ch )
{
ls.resize( 1 );
ls[0] = eng->createState( ch );
rs = ls;
rs.detach();
#ifndef QT_NO_REGEXP_OPTIM
str = ch;
leftStr = ch;
rightStr = ch;
maxl = 1;
occ1.detach();
occ1[BadChar(ch)] = 0;
#endif
minl = 1;
}
void QRegExpEngine::Box::set( const CharClass& cc )
{
ls.resize( 1 );
ls[0] = eng->createState( cc );
rs = ls;
rs.detach();
#ifndef QT_NO_REGEXP_OPTIM
maxl = 1;
occ1 = cc.firstOccurrence();
#endif
minl = 1;
}
#ifndef QT_NO_REGEXP_BACKREF
void QRegExpEngine::Box::set( int bref )
{
ls.resize( 1 );
ls[0] = eng->createState( bref );
rs = ls;
rs.detach();
if ( bref >= 1 && bref <= MaxBackRefs )
skipanchors = Anchor_BackRef0Empty << bref;
#ifndef QT_NO_REGEXP_OPTIM
maxl = InftyLen;
#endif
minl = 0;
}
#endif
void QRegExpEngine::Box::cat( const Box& b )
{
eng->addCatTransitions( rs, b.ls );
addAnchorsToEngine( b );
if ( minl == 0 ) {
mergeInto( &lanchors, b.lanchors );
if ( skipanchors != 0 ) {
for ( int i = 0; i < (int) b.ls.size(); i++ ) {
int a = eng->anchorConcatenation( at(lanchors, b.ls[i]),
skipanchors );
lanchors.insert( b.ls[i], a );
}
}
mergeInto( &ls, b.ls );
}
if ( b.minl == 0 ) {
mergeInto( &ranchors, b.ranchors );
if ( b.skipanchors != 0 ) {
for ( int i = 0; i < (int) rs.size(); i++ ) {
int a = eng->anchorConcatenation( at(ranchors, rs[i]),
b.skipanchors );
ranchors.insert( rs[i], a );
}
}
mergeInto( &rs, b.rs );
} else {
ranchors = b.ranchors;
rs = b.rs;
}
#ifndef QT_NO_REGEXP_OPTIM
if ( maxl != InftyLen ) {
if ( rightStr.length() + b.leftStr.length() >
QMAX(str.length(), b.str.length()) ) {
earlyStart = minl - rightStr.length();
lateStart = maxl - rightStr.length();
str = rightStr + b.leftStr;
} else if ( b.str.length() > str.length() ) {
earlyStart = minl + b.earlyStart;
lateStart = maxl + b.lateStart;
str = b.str;
}
}
if ( (int) leftStr.length() == maxl )
leftStr += b.leftStr;
if ( (int) b.rightStr.length() == b.maxl )
rightStr += b.rightStr;
else
rightStr = b.rightStr;
if ( maxl == InftyLen || b.maxl == InftyLen )
maxl = InftyLen;
else
maxl += b.maxl;
occ1.detach();
for ( int i = 0; i < NumBadChars; i++ ) {
if ( b.occ1[i] != NoOccurrence && minl + b.occ1[i] < occ1[i] )
occ1[i] = minl + b.occ1[i];
}
#endif
minl += b.minl;
if ( minl == 0 )
skipanchors = eng->anchorConcatenation( skipanchors, b.skipanchors );
else
skipanchors = 0;
}
void QRegExpEngine::Box::orx( const Box& b )
{
mergeInto( &ls, b.ls );
mergeInto( &lanchors, b.lanchors );
mergeInto( &rs, b.rs );
mergeInto( &ranchors, b.ranchors );
skipanchors = eng->anchorAlternation( skipanchors, b.skipanchors );
#ifndef QT_NO_REGEXP_OPTIM
occ1.detach();
for ( int i = 0; i < NumBadChars; i++ ) {
if ( occ1[i] > b.occ1[i] )
occ1[i] = b.occ1[i];
}
earlyStart = 0;
lateStart = 0;
str = QString::null;
leftStr = QString::null;
rightStr = QString::null;
if ( b.maxl > maxl )
maxl = b.maxl;
#endif
if ( b.minl < minl )
minl = b.minl;
}
void QRegExpEngine::Box::plus( int atom )
{
#ifndef QT_NO_REGEXP_CAPTURE
eng->addPlusTransitions( rs, ls, atom );
#else
Q_UNUSED( atom );
eng->addCatTransitions( rs, ls );
#endif
addAnchorsToEngine( *this );
#ifndef QT_NO_REGEXP_OPTIM
maxl = InftyLen;
#endif
}
void QRegExpEngine::Box::opt()
{
#ifndef QT_NO_REGEXP_OPTIM
earlyStart = 0;
lateStart = 0;
str = QString::null;
leftStr = QString::null;
rightStr = QString::null;
#endif
skipanchors = 0;
minl = 0;
}
void QRegExpEngine::Box::catAnchor( int a )
{
if ( a != 0 ) {
for ( int i = 0; i < (int) rs.size(); i++ ) {
a = eng->anchorConcatenation( at(ranchors, rs[i]), a );
ranchors.insert( rs[i], a );
}
if ( minl == 0 )
skipanchors = eng->anchorConcatenation( skipanchors, a );
}
}
#ifndef QT_NO_REGEXP_OPTIM
void QRegExpEngine::Box::setupHeuristics()
{
eng->setupGoodStringHeuristic( earlyStart, lateStart, str );
/*
A regular expression such as 112|1 has occ1['2'] = 2 and minl = 1 at this
point. An entry of occ1 has to be at most minl or infinity for the rest
of the algorithm to go well.
We waited until here before normalizing these cases (instead of doing it
in Box::orx()) because sometimes things improve by themselves; consider
(112|1)34.
*/
for ( int i = 0; i < NumBadChars; i++ ) {
if ( occ1[i] != NoOccurrence && occ1[i] >= minl )
occ1[i] = minl;
}
eng->setupBadCharHeuristic( minl, occ1 );
eng->heuristicallyChooseHeuristic();
}
#endif
#if defined(QT_DEBUG)
void QRegExpEngine::Box::dump() const
{
int i;
- qDebug( "Box of at least %d character%s", minl, minl == 1 ? "" : "s" );
- qDebug( " Left states:" );
+ odebug << "Box of at least " << minl << " character" << (minl == 1 ? "" : "s") << oendl;
+ odebug << " Left states:" << oendl;
for ( i = 0; i < (int) ls.size(); i++ ) {
if ( at(lanchors, ls[i]) == 0 )
- qDebug( " %d", ls[i] );
+ odebug << " " << ls[i] << oendl;
else
- qDebug( " %d [anchors 0x%.8x]", ls[i], lanchors[ls[i]] );
+ odebug << " " << ls[i] << QString().sprintf(" [anchors 0x%.8x]", lanchors[ls[i]]) << oendl;
}
- qDebug( " Right states:" );
+ odebug << " Right states:" << oendl;
for ( i = 0; i < (int) rs.size(); i++ ) {
if ( at(ranchors, ls[i]) == 0 )
- qDebug( " %d", rs[i] );
+ odebug << " " << rs[i] << oendl;
else
- qDebug( " %d [anchors 0x%.8x]", rs[i], ranchors[rs[i]] );
+ odebug << " " << rs[i] << QString().sprintf(" [anchors 0x%.8x]", ranchors[rs[i]]) << oendl;
}
- qDebug( " Skip anchors: 0x%.8x", skipanchors );
+ odebug << QString().sprintf(" Skip anchors: 0x%.8x", skipanchors) << oendl;
}
#endif
void QRegExpEngine::Box::addAnchorsToEngine( const Box& to ) const
{
for ( int i = 0; i < (int) to.ls.size(); i++ ) {
for ( int j = 0; j < (int) rs.size(); j++ ) {
int a = eng->anchorConcatenation( at(ranchors, rs[j]),
at(to.lanchors, to.ls[i]) );
eng->addAnchors( rs[j], to.ls[i], a );
}
}
}
int QRegExpEngine::getChar()
{
return ( yyPos == yyLen ) ? EOS : yyIn[yyPos++].unicode();
}
int QRegExpEngine::getEscape()
{
#ifndef QT_NO_REGEXP_ESCAPE
const char tab[] = "afnrtv"; // no b, as \b means word boundary
const char backTab[] = "\a\f\n\r\t\v";
ushort low;
int i;
#endif
ushort val;
int prevCh = yyCh;
if ( prevCh == EOS ) {
yyError = TRUE;
return Tok_Char | '\\';
}
yyCh = getChar();
#ifndef QT_NO_REGEXP_ESCAPE
if ( (prevCh & ~0xff) == 0 ) {
const char *p = strchr( tab, prevCh );
if ( p != 0 )
return Tok_Char | backTab[p - tab];
}
#endif
switch ( prevCh ) {
#ifndef QT_NO_REGEXP_ESCAPE
case '0':
val = 0;
for ( i = 0; i < 3; i++ ) {
if ( yyCh >= '0' && yyCh <= '7' )
val = ( val << 3 ) | ( yyCh - '0' );
else
break;
yyCh = getChar();
}
if ( (val & ~0377) != 0 )
yyError = TRUE;
return Tok_Char | val;
#endif
#ifndef QT_NO_REGEXP_ESCAPE
case 'B':
return Tok_NonWord;
#endif
#ifndef QT_NO_REGEXP_CCLASS
case 'D':
// see QChar::isDigit()
yyCharClass->addCategories( 0x7fffffef );
return Tok_CharClass;
case 'S':
// see QChar::isSpace()
yyCharClass->addCategories( 0x7ffff87f );
yyCharClass->addRange( 0x0000, 0x0008 );
yyCharClass->addRange( 0x000e, 0x001f );
yyCharClass->addRange( 0x007f, 0x009f );
return Tok_CharClass;
case 'W':
// see QChar::isLetterOrNumber()
yyCharClass->addCategories( 0x7ff07f8f );
return Tok_CharClass;
#endif
#ifndef QT_NO_REGEXP_ESCAPE
case 'b':
return Tok_Word;
#endif
#ifndef QT_NO_REGEXP_CCLASS
case 'd':
// see QChar::isDigit()
yyCharClass->addCategories( 0x00000010 );
return Tok_CharClass;
case 's':
// see QChar::isSpace()
yyCharClass->addCategories( 0x00000380 );
yyCharClass->addRange( 0x0009, 0x000d );
return Tok_CharClass;
case 'w':
// see QChar::isLetterOrNumber()
yyCharClass->addCategories( 0x000f8070 );
return Tok_CharClass;
#endif
#ifndef QT_NO_REGEXP_ESCAPE
case 'x':
val = 0;
for ( i = 0; i < 4; i++ ) {
low = QChar( yyCh ).lower();
if ( low >= '0' && low <= '9' )
val = ( val << 4 ) | ( low - '0' );
else if ( low >= 'a' && low <= 'f' )
val = ( val << 4 ) | ( low - 'a' + 10 );
else
break;
yyCh = getChar();
}
return Tok_Char | val;
#endif
default:
if ( prevCh >= '1' && prevCh <= '9' ) {
#ifndef QT_NO_REGEXP_BACKREF
val = prevCh - '0';
while ( yyCh >= '0' && yyCh <= '9' ) {
val = ( val *= 10 ) | ( yyCh - '0' );
yyCh = getChar();
}
return Tok_BackRef | val;
#else
yyError = TRUE;
#endif
}
return Tok_Char | prevCh;
}
}
#ifndef QT_NO_REGEXP_INTERVAL
int QRegExpEngine::getRep( int def )
{
if ( yyCh >= '0' && yyCh <= '9' ) {
int rep = 0;
do {
rep = 10 * rep + yyCh - '0';
if ( rep >= InftyRep ) {
yyError = TRUE;
rep = def;
}
yyCh = getChar();
} while ( yyCh >= '0' && yyCh <= '9' );
return rep;
} else {
return def;
}
}
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
void QRegExpEngine::skipChars( int n )
{
if ( n > 0 ) {
yyPos += n - 1;
yyCh = getChar();
}
}
#endif
void QRegExpEngine::startTokenizer( const QChar *rx, int len )
{
yyIn = rx;
yyPos0 = 0;
yyPos = 0;
yyLen = len;
yyCh = getChar();
yyCharClass = new CharClass;
yyMinRep = 0;
yyMaxRep = 0;
yyError = FALSE;
}
int QRegExpEngine::getToken()
{
#ifndef QT_NO_REGEXP_CCLASS
ushort pendingCh = 0;
bool charPending;
bool rangePending;
int tok;
#endif
int prevCh = yyCh;
yyPos0 = yyPos - 1;
#ifndef QT_NO_REGEXP_CCLASS
yyCharClass->clear();
#endif
yyMinRep = 0;
yyMaxRep = 0;
yyCh = getChar();
switch ( prevCh ) {
case EOS: