Diffstat (limited to 'noncore/apps/tinykate/libkate/document/katehighlight.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katehighlight.cpp | 126 |
1 files changed, 65 insertions, 61 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.cpp b/noncore/apps/tinykate/libkate/document/katehighlight.cpp index 0d2c283..539d356 100644 --- a/noncore/apps/tinykate/libkate/document/katehighlight.cpp +++ b/noncore/apps/tinykate/libkate/document/katehighlight.cpp @@ -1,65 +1,69 @@ /* Copyright (C) 1998, 1999 Jochen Wilhelmy digisnap@cs.tu-berlin.de - (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> - (C) 2002 Joseph Wenninger <jowenn@kde.org> + (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> + (C) 2002 Joseph Wenninger <jowenn@kde.org> 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. */ -#include <string.h> - -#include <qtextstream.h> -#include <qpe/config.h> -#include <kglobal.h> -//#include <kinstance.h> -//#include <kmimemagic.h> -#include <klocale.h> -//#include <kregexp.h> -#include <kglobalsettings.h> -#include <kdebug.h> -#include <kstddirs.h> - #include "katehighlight.h" - - #include "katetextline.h" #include "katedocument.h" #include "katesyntaxdocument.h" +#include "kglobal.h" +//#include "kinstance.h" +//#include "kmimemagic.h" +#include "klocale.h" +//#include "kregexp.h" +#include "kglobalsettings.h" +#include "kdebug.h" +#include "kstddirs.h" + +/* OPIE */ +#include <opie2/odebug.h> +#include <qpe/config.h> + +/* QT */ +#include <qtextstream.h> + +/* STD */ +#include <string.h> + HlManager *HlManager::s_pSelf = 0; enum Item_styles { dsNormal,dsKeyword,dsDataType,dsDecVal,dsBaseN,dsFloat,dsChar,dsString,dsComment,dsOthers}; static bool trueBool = true; static QString stdDeliminator = QString ("!%&()*+,-./:;<=>?[]^{|}~ \t\\"); int getDefStyleNum(QString name) { if (name=="dsNormal") return dsNormal; if (name=="dsKeyword") return dsKeyword; if (name=="dsDataType") return dsDataType; if (name=="dsDecVal") return dsDecVal; if (name=="dsBaseN") return dsBaseN; if (name=="dsFloat") return dsFloat; if (name=="dsChar") return dsChar; if (name=="dsString") return dsString; if (name=="dsComment") return dsComment; if (name=="dsOthers") return dsOthers; return dsNormal; } @@ -99,50 +103,50 @@ const QChar *HlCharDetect::checkHgl(const QChar *str, int len, bool) { } Hl2CharDetect::Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2) : HlItem(attribute,context) { sChar1 = ch1; sChar2 = ch2; } const QChar *Hl2CharDetect::checkHgl(const QChar *str, int len, bool) { if (str[0] == sChar1 && str[1] == sChar2) return str + 2; return 0L; } HlStringDetect::HlStringDetect(int attribute, int context, const QString &s, bool inSensitive) : HlItem(attribute, context), str(inSensitive ? s.upper():s), _inSensitive(inSensitive) { } HlStringDetect::~HlStringDetect() { } const QChar *HlStringDetect::checkHgl(const QChar *s, int len, bool) { if (!_inSensitive) {if (memcmp(s, str.unicode(), str.length()*sizeof(QChar)) == 0) return s + str.length();} else { - QString tmp=QString(s,str.length()).upper(); - if (tmp==str) return s+str.length(); + QString tmp=QString(s,str.length()).upper(); + if (tmp==str) return s+str.length(); } return 0L; } HlRangeDetect::HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2) : HlItem(attribute,context) { sChar1 = ch1; sChar2 = ch2; } const QChar *HlRangeDetect::checkHgl(const QChar *s, int len, bool) { if (*s == sChar1) { do { s++; len--; if (len == 0) return 0L; } while (*s != sChar2); return s + 1; } @@ -192,91 +196,91 @@ const QChar *HlKeyword::checkHgl(const QChar *s, int len, bool b) len--; } if (s2 == s) return 0L; QString lookup = QString(s,s2-s); if ( dict.find(lookup) ) return s2; return 0L; } HlInt::HlInt(int attribute, int context) : HlItem(attribute,context) { } const QChar *HlInt::checkHgl(const QChar *str, int len, bool) { const QChar *s,*s1; s = str; while (s->isDigit()) s++; if (s > str) { if (subItems) { - for (HlItem *it=subItems->first();it;it=subItems->next()) + for (HlItem *it=subItems->first();it;it=subItems->next()) { s1=it->checkHgl(s, len, false); - if (s1) return s1; + if (s1) return s1; } } return s; } return 0L; } HlFloat::HlFloat(int attribute, int context) : HlItem(attribute,context) { } const QChar *HlFloat::checkHgl(const QChar *s, int len, bool) { bool b, p; const QChar *s1; b = false; while (s->isDigit()){ s++; b = true; } if (p = (*s == '.')) { s++; while (s->isDigit()) { s++; b = true; } } if (!b) return 0L; if ((*s&0xdf) == 'E') s++; else if (!p) return 0L; - else - { + else + { if (subItems) { - for (HlItem *it=subItems->first();it;it=subItems->next()) + for (HlItem *it=subItems->first();it;it=subItems->next()) { s1=it->checkHgl(s, len, false); - if (s1) return s1; + if (s1) return s1; } } return s; } if ((*s == '-')||(*s =='+')) s++; b = false; while (s->isDigit()) { s++; b = true; } if (b) { if (subItems) { for (HlItem *it=subItems->first();it;it=subItems->next()) { s1=it->checkHgl(s, len, false); if (s1) return s1; } } return s; } else return 0L; } @@ -324,49 +328,49 @@ const QChar *HlCOct::checkHgl(const QChar *str, int len, bool) { s = str; while (*s >= '0' && *s <= '7') s++; if (s > str) { if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; return s; } } return 0L; } HlCHex::HlCHex(int attribute, int context) : HlItem(attribute,context) { } const QChar *HlCHex::checkHgl(const QChar *str, int len, bool) { const QChar *s=str; #if 0 int i; for (i=0;(*s)!='\0';s++,i++); QString line(str,i); QRegExp3 rx("0[xX][a-fA-F\\d]+[UuLl]?"); // this matches but is also matching parenthesis int pos=rx.search(line,0); if(pos > -1) return str+rx.matchedLength(); else - return 0L; + return 0L; #else if (str[0] == '0' && ((str[1]&0xdf) == 'X' )) { str += 2; s = str; while (s->isDigit() || ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') /*|| (*s >= 'a' && *s <= 'f')*/) s++; if (s > str) { if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; return s; } } return 0L; #endif } HlCFloat::HlCFloat(int attribute, int context) : HlFloat(attribute,context) { } const QChar *HlCFloat::checkHgl(const QChar *s, int len, bool lineStart) { s = HlFloat::checkHgl(s, len, lineStart); if (s && ((*s&0xdf) == 'F' )) s++; return s; @@ -379,62 +383,62 @@ HlAnyChar::HlAnyChar(int attribute, int context, const QChar* charList, uint len } const QChar *HlAnyChar::checkHgl(const QChar *s, int len, bool) { if (ustrchr(_charList, _charListLen, *s)) return s +1; return 0L; } HlRegExpr::HlRegExpr(int attribute, int context,QString regexp) : HlItem(attribute, context) { handlesLinestart=regexp.startsWith("^"); if(!handlesLinestart) regexp.prepend("^"); Expr=new QRegExp3(regexp); } const QChar *HlRegExpr::checkHgl(const QChar *s, int len, bool lineStart) { if ((!lineStart) && handlesLinestart) return 0; QString line(s,len); int pos = Expr->search( line, 0 ); if (pos==-1) return 0L; else - return (s+Expr->matchedLength()); + return (s+Expr->matchedLength()); }; HlLineContinue::HlLineContinue(int attribute, int context) : HlItem(attribute,context) { } const QChar *HlLineContinue::checkHgl(const QChar *s, int len, bool) { if ((s[0].latin1() == '\\') && (len == 1)) - { + { return s + 1; - } + } return 0L; } HlCStringChar::HlCStringChar(int attribute, int context) : HlItem(attribute,context) { } //checks for hex and oct (for example \x1b or \033) const QChar *checkCharHexOct(const QChar *str) { const QChar *s; s=str; int n; if (*s == 'x') { n = 0; do { s++; n *= 16; if (s->isDigit()) n += *s - '0'; else if ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') n += (*s&0xdf) - 'A' + 10; // else if (*s >= 'a' && *s <= 'f') n += *s - 'a' + 10; else break; if (n >= 256) return 0L; } while (true); @@ -600,49 +604,49 @@ int Highlight::doHighlight(int ctxNum, TextLine *textLine) QChar lastChar = ' '; // first char const QChar *str = textLine->getText(); // non space char - index of that char const QChar *s1 = textLine->firstNonSpace(); uint z = textLine->firstChar(); // length of textline uint len = textLine->length(); bool found = false; while (z < len) { found = false; for (item = context->items.first(); item != 0L; item = context->items.next()) { if (item->startEnable(lastChar)) { s2 = item->checkHgl(s1, len-z, z==0); if (s2 > s1) { - qDebug("An item has been detected"); + odebug << "An item has been detected" << oendl; textLine->setAttribs(item->attr,s1 - str,s2 - str); ctxNum = item->ctx; context = contextList[ctxNum]; z = z + s2 - s1 - 1; s1 = s2 - 1; found = true; break; } } } // nothing found: set attribute of one char if (!found) textLine->setAttribs(context->attr,s1 - str,s1 - str + 1); lastChar = *s1; s1++; z++; } //set "end of line"-properties textLine->setAttr(context->attr); //return new context @@ -832,78 +836,78 @@ void Highlight::done() { if (noHl) return; for (int z = 0; z < nContexts; z++) delete contextList[z]; } /******************************************************************************************* Highlight - createItemData This function reads the itemData entries from the config file, which specifies the default attribute styles for matched items/contexts. * input: none ************* * output: ItemDataList &list :A reference to the internal list containing the parsed default config ************* * return value: none *******************************************************************************************/ void Highlight::createItemData(ItemDataList &list) { - qDebug("Highlight::createItemData"); + odebug << "Highlight::createItemData" << oendl; // If no highlighting is selected we need only one default. if (noHl) { list.append(new ItemData(I18N_NOOP("Normal Text"), dsNormal)); return; } QString color; QString selColor; QString bold; QString italic; // If the internal list isn't already available read the config file if (internalIDList.count()==0) { //if all references to the list are destried the contents will also be deleted internalIDList.setAutoDelete(true); syntaxContextData *data; - qDebug("Trying to read itemData section"); + odebug << "Trying to read itemData section" << oendl; //Tell the syntax document class which file we want to parse and which data group HlManager::self()->syntax->setIdentifier(identifier); data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData"); //begin with the real parsing while (HlManager::self()->syntax->nextGroup(data)) { - qDebug("Setting up one itemData element"); + odebug << "Setting up one itemData element" << oendl; // read all attributes color=HlManager::self()->syntax->groupData(data,QString("color")); selColor=HlManager::self()->syntax->groupData(data,QString("selColor")); bold=HlManager::self()->syntax->groupData(data,QString("bold")); italic=HlManager::self()->syntax->groupData(data,QString("italic")); //check if the user overrides something if ( (!color.isEmpty()) && (!selColor.isEmpty()) && (!bold.isEmpty()) && (!italic.isEmpty())) { //create a user defined style internalIDList.append(new ItemData( HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))), QColor(color),QColor(selColor),(bold=="true") || (bold=="1"), (italic=="true") || (italic=="1") )); } else { //assign a default style internalIDList.append(new ItemData( HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))))); } } @@ -912,54 +916,54 @@ void Highlight::createItemData(ItemDataList &list) } //set the ouput reference list=internalIDList; } /******************************************************************************************* Highlight - lookupAttrName This function is a helper for makeContextList and createHlItem. It looks the given attribute name in the itemData list up and returns it's index * input: QString &name :the attribute name to lookup * ItemDataList &iDl :the list containing all * available attributes ************* * output: none ************* * return value: int :The index of the attribute * or 0 *******************************************************************************************/ int Highlight::lookupAttrName(const QString& name, ItemDataList &iDl) { - for (int i=0;i<iDl.count();i++) - { - if (iDl.at(i)->name==name) return i; - } - kdDebug(13010)<<"Couldn't resolve itemDataName"<<endl; - return 0; + for (int i=0;i<iDl.count();i++) + { + if (iDl.at(i)->name==name) return i; + } + kdDebug(13010)<<"Couldn't resolve itemDataName"<<endl; + return 0; } /******************************************************************************************* Highlight - createHlItem This function is a helper for makeContextList. It parses the xml file for information, how single or multi line comments are marked * input: syntaxContextData *data : Data about the item read from * the xml file * ItemDataList &iDl : List of all available itemData * entries. Needed for attribute * name->index translation ************* * output: none ************* * return value: HlItem * : Pointer to the newly created item * object *******************************************************************************************/ HlItem *Highlight::createHlItem(syntaxContextData *data, ItemDataList &iDl) { // No highlighting -> exit if (noHl) @@ -1056,105 +1060,105 @@ bool Highlight::isInWord(QChar c) This function is a helper for makeContextList. It parses the xml file for information, how single or multi line comments are marked * input: none ************* * output: none ************* * return value: none *******************************************************************************************/ void Highlight::readCommentConfig() { cslStart = ""; HlManager::self()->syntax->setIdentifier(identifier); syntaxContextData *data=HlManager::self()->syntax->getGroupInfo("general","comment"); if (data) { // kdDebug(13010)<<"COMMENT DATA FOUND"<<endl; while (HlManager::self()->syntax->nextGroup(data)) { if (HlManager::self()->syntax->groupData(data,"name")=="singleLine") - cslStart=HlManager::self()->syntax->groupData(data,"start"); - if (HlManager::self()->syntax->groupData(data,"name")=="multiLine") + cslStart=HlManager::self()->syntax->groupData(data,"start"); + if (HlManager::self()->syntax->groupData(data,"name")=="multiLine") { - cmlStart=HlManager::self()->syntax->groupData(data,"start"); - cmlEnd=HlManager::self()->syntax->groupData(data,"end"); + cmlStart=HlManager::self()->syntax->groupData(data,"start"); + cmlEnd=HlManager::self()->syntax->groupData(data,"end"); } } HlManager::self()->syntax->freeGroupInfo(data); } } /******************************************************************************************* Highlight - readGlobalKeyWordConfig This function is a helper for makeContextList. It parses the xml file for information, if keywords should be treated case(in)sensitive and creates the keyword delimiter list. Which is the default list, without any given weak deliminiators * input: none ************* * output: none ************* * return value: none *******************************************************************************************/ void Highlight::readGlobalKeywordConfig() { // Tell the syntax document class which file we want to parse HlManager::self()->syntax->setIdentifier(identifier); // Get the keywords config entry syntaxContextData * data=HlManager::self()->syntax->getConfig("general","keywords"); if (data) { - kdDebug(13010)<<"Found global keyword config"<<endl; + kdDebug(13010)<<"Found global keyword config"<<endl; if (HlManager::self()->syntax->groupItemData(data,QString("casesensitive"))!="0") - casesensitive=true; else {casesensitive=false; kdDebug(13010)<<"Turning on case insensitiveness"<<endl;} + casesensitive=true; else {casesensitive=false; kdDebug(13010)<<"Turning on case insensitiveness"<<endl;} //get the weak deliminators weakDeliminator=(!HlManager::self()->syntax->groupItemData(data,QString("weakDeliminator"))); // remove any weakDelimitars (if any) from the default list and store this list. int f; for (int s=0; s < weakDeliminator.length(); s++) { f = 0; f = deliminator.find (weakDeliminator[s]); if (f > -1) deliminator.remove (f, 1); } deliminatorChars = deliminator.unicode(); deliminatorLen = deliminator.length(); - HlManager::self()->syntax->freeGroupInfo(data); + HlManager::self()->syntax->freeGroupInfo(data); } else { //Default values casesensitive=true; weakDeliminator=QString(""); } } /******************************************************************************************* Highlight - makeContextList That's the most important initialization function for each highlighting. It's called each time a document gets a highlighting style assigned. parses the xml file and creates a corresponding internal structure * input: none ************* * output: none ************* * return value: none *******************************************************************************************/ @@ -1183,67 +1187,67 @@ void Highlight::makeContextList() if (data) { while (HlManager::self()->syntax->nextGroup(data)) { // BEGIN - Translation of the attribute parameter QString tmpAttr=HlManager::self()->syntax->groupData(data,QString("attribute")).simplifyWhiteSpace(); int attr; if (QString("%1").arg(tmpAttr.toInt())==tmpAttr) attr=tmpAttr.toInt(); else attr=lookupAttrName(tmpAttr,iDl); // END - Translation of the attribute parameter contextList[i]=new HlContext( attr, (HlManager::self()->syntax->groupData(data,QString("lineEndContext"))).toInt(), (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).isEmpty()?-1: (HlManager::self()->syntax->groupData(data,QString("lineBeginContext"))).toInt()); //Let's create all items for the context while (HlManager::self()->syntax->nextItem(data)) { -// kdDebug(13010)<< "In make Contextlist: Item:"<<endl; - c=createHlItem(data,iDl); - if (c) - { +// kdDebug(13010)<< "In make Contextlist: Item:"<<endl; + c=createHlItem(data,iDl); + if (c) + { contextList[i]->items.append(c); // Not supported completely atm and only one level. Subitems.(all have to be matched to at once) - datasub=HlManager::self()->syntax->getSubItems(data); - bool tmpbool; - if (tmpbool=HlManager::self()->syntax->nextItem(datasub)) - { + datasub=HlManager::self()->syntax->getSubItems(data); + bool tmpbool; + if (tmpbool=HlManager::self()->syntax->nextItem(datasub)) + { c->subItems=new QList<HlItem>; - for (;tmpbool;tmpbool=HlManager::self()->syntax->nextItem(datasub)) + for (;tmpbool;tmpbool=HlManager::self()->syntax->nextItem(datasub)) c->subItems->append(createHlItem(datasub,iDl)); } - HlManager::self()->syntax->freeGroupInfo(datasub); + HlManager::self()->syntax->freeGroupInfo(datasub); // end of sublevel - } -// kdDebug(13010)<<"Last line in loop"<<endl; + } +// kdDebug(13010)<<"Last line in loop"<<endl; } i++; } } HlManager::self()->syntax->freeGroupInfo(data); } HlManager::HlManager() : QObject(0L) { syntax = new SyntaxDocument(); SyntaxModeList modeList = syntax->modeList(); hlList.setAutoDelete(true); hlList.append(new Highlight(0)); uint i=0; while (i < modeList.count()) { hlList.append(new Highlight(modeList.at(i))); i++; } @@ -1291,58 +1295,58 @@ int HlManager::wildcardFind(const QString &fileName) { for (highlight = hlList.first(); highlight != 0L; highlight = hlList.next()) { p1 = 0; w = highlight->getWildcards(); while (p1 < (int) w.length()) { p2 = w.find(';',p1); if (p2 == -1) p2 = w.length(); if (p1 < p2) { QRegExp regExp(w.mid(p1,p2 - p1),true,true); if (regExp.match(fileName) == 0) return hlList.at(); } p1 = p2 + 1; } } return -1; } int HlManager::makeAttribs(Highlight *highlight, Attribute *a, int maxAttribs) { ItemStyleList defaultStyleList; ItemStyle *defaultStyle; ItemDataList itemDataList; ItemData *itemData; int nAttribs, z; - qDebug("HlManager::makeAttribs"); + odebug << "HlManager::makeAttribs" << oendl; defaultStyleList.setAutoDelete(true); getDefaults(defaultStyleList); // itemDataList.setAutoDelete(true); highlight->getItemDataList(itemDataList); nAttribs = itemDataList.count(); for (z = 0; z < nAttribs; z++) { - qDebug("HlManager::makeAttribs: createing one attribute definition"); + odebug << "HlManager::makeAttribs: createing one attribute definition" << oendl; itemData = itemDataList.at(z); if (itemData->defStyle) { // default style defaultStyle = defaultStyleList.at(itemData->defStyleNum); a[z].col = defaultStyle->col; a[z].selCol = defaultStyle->selCol; a[z].bold = defaultStyle->bold; a[z].italic = defaultStyle->italic; } else { // custom style a[z].col = itemData->col; a[z].selCol = itemData->selCol; a[z].bold = itemData->bold; a[z].italic = itemData->italic; } } for (; z < maxAttribs; z++) { a[z].col = black; a[z].selCol = black; a[z].bold = defaultStyle->bold; a[z].italic = defaultStyle->italic; } return nAttribs; @@ -1394,49 +1398,49 @@ void HlManager::getDefaults(ItemStyleList &list) { list.append(new ItemStyle(darkGreen,green,false,false)); //others #warning fixme /* config = KateFactory::instance()->config(); config->setGroup("Default Item Styles"); for (z = 0; z < defaultStyles(); z++) { i = list.at(z); s = config->readEntry(defaultStyleName(z)); if (!s.isEmpty()) { sscanf(s.latin1(),"%X,%X,%d,%d",&col,&selCol,&i->bold,&i->italic); i->col.setRgb(col); i->selCol.setRgb(selCol); } } */ } void HlManager::setDefaults(ItemStyleList &list) { KateConfig *config; int z; ItemStyle *i; char s[64]; #warning fixme -/* +/* config = KateFactory::instance()->config(); config->setGroup("Default Item Styles"); for (z = 0; z < defaultStyles(); z++) { i = list.at(z); sprintf(s,"%X,%X,%d,%d",i->col.rgb(),i->selCol.rgb(),i->bold, i->italic); config->writeEntry(defaultStyleName(z),s); } */ emit changed(); } int HlManager::highlights() { return (int) hlList.count(); } QString HlManager::hlName(int n) { return hlList.at(n)->iName; } QString HlManager::hlSection(int n) { return hlList.at(n)->iSection; } |