summaryrefslogtreecommitdiff
path: root/noncore/apps/tinykate/libkate/document/katehighlight.cpp
Unidiff
Diffstat (limited to 'noncore/apps/tinykate/libkate/document/katehighlight.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/document/katehighlight.cpp46
1 files changed, 25 insertions, 21 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
@@ -10,44 +10,48 @@
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <string.h>
23
24#include <qtextstream.h>
25#include <qpe/config.h>
26#include <kglobal.h>
27//#include <kinstance.h>
28//#include <kmimemagic.h>
29#include <klocale.h>
30//#include <kregexp.h>
31#include <kglobalsettings.h>
32#include <kdebug.h>
33#include <kstddirs.h>
34
35#include "katehighlight.h" 22#include "katehighlight.h"
36
37
38#include "katetextline.h" 23#include "katetextline.h"
39#include "katedocument.h" 24#include "katedocument.h"
40#include "katesyntaxdocument.h" 25#include "katesyntaxdocument.h"
41 26
27#include "kglobal.h"
28//#include "kinstance.h"
29//#include "kmimemagic.h"
30#include "klocale.h"
31//#include "kregexp.h"
32#include "kglobalsettings.h"
33#include "kdebug.h"
34#include "kstddirs.h"
35
36/* OPIE */
37#include <opie2/odebug.h>
38#include <qpe/config.h>
39
40/* QT */
41#include <qtextstream.h>
42
43/* STD */
44#include <string.h>
45
42 46
43HlManager *HlManager::s_pSelf = 0; 47HlManager *HlManager::s_pSelf = 0;
44 48
45enum Item_styles { dsNormal,dsKeyword,dsDataType,dsDecVal,dsBaseN,dsFloat,dsChar,dsString,dsComment,dsOthers}; 49enum Item_styles { dsNormal,dsKeyword,dsDataType,dsDecVal,dsBaseN,dsFloat,dsChar,dsString,dsComment,dsOthers};
46 50
47static bool trueBool = true; 51static bool trueBool = true;
48static QString stdDeliminator = QString ("!%&()*+,-./:;<=>?[]^{|}~ \t\\"); 52static QString stdDeliminator = QString ("!%&()*+,-./:;<=>?[]^{|}~ \t\\");
49 53
50int getDefStyleNum(QString name) 54int getDefStyleNum(QString name)
51{ 55{
52 if (name=="dsNormal") return dsNormal; 56 if (name=="dsNormal") return dsNormal;
53 if (name=="dsKeyword") return dsKeyword; 57 if (name=="dsKeyword") return dsKeyword;
@@ -612,25 +616,25 @@ int Highlight::doHighlight(int ctxNum, TextLine *textLine)
612 bool found = false; 616 bool found = false;
613 while (z < len) 617 while (z < len)
614 { 618 {
615 found = false; 619 found = false;
616 620
617 for (item = context->items.first(); item != 0L; item = context->items.next()) 621 for (item = context->items.first(); item != 0L; item = context->items.next())
618 { 622 {
619 if (item->startEnable(lastChar)) 623 if (item->startEnable(lastChar))
620 { 624 {
621 s2 = item->checkHgl(s1, len-z, z==0); 625 s2 = item->checkHgl(s1, len-z, z==0);
622 if (s2 > s1) 626 if (s2 > s1)
623 { 627 {
624 qDebug("An item has been detected"); 628 odebug << "An item has been detected" << oendl;
625 textLine->setAttribs(item->attr,s1 - str,s2 - str); 629 textLine->setAttribs(item->attr,s1 - str,s2 - str);
626 ctxNum = item->ctx; 630 ctxNum = item->ctx;
627 context = contextList[ctxNum]; 631 context = contextList[ctxNum];
628 z = z + s2 - s1 - 1; 632 z = z + s2 - s1 - 1;
629 s1 = s2 - 1; 633 s1 = s2 - 1;
630 found = true; 634 found = true;
631 break; 635 break;
632 } 636 }
633 } 637 }
634 } 638 }
635 639
636 // nothing found: set attribute of one char 640 // nothing found: set attribute of one char
@@ -844,54 +848,54 @@ void Highlight::done()
844 848
845 * input: none 849 * input: none
846 ************* 850 *************
847 * output: ItemDataList &list :A reference to the internal 851 * output: ItemDataList &list :A reference to the internal
848 list containing the parsed 852 list containing the parsed
849 default config 853 default config
850 ************* 854 *************
851 * return value: none 855 * return value: none
852*******************************************************************************************/ 856*******************************************************************************************/
853 857
854void Highlight::createItemData(ItemDataList &list) 858void Highlight::createItemData(ItemDataList &list)
855{ 859{
856 qDebug("Highlight::createItemData"); 860 odebug << "Highlight::createItemData" << oendl;
857 861
858 // If no highlighting is selected we need only one default. 862 // If no highlighting is selected we need only one default.
859 if (noHl) 863 if (noHl)
860 { 864 {
861 list.append(new ItemData(I18N_NOOP("Normal Text"), dsNormal)); 865 list.append(new ItemData(I18N_NOOP("Normal Text"), dsNormal));
862 return; 866 return;
863 } 867 }
864 868
865 QString color; 869 QString color;
866 QString selColor; 870 QString selColor;
867 QString bold; 871 QString bold;
868 QString italic; 872 QString italic;
869 873
870 // If the internal list isn't already available read the config file 874 // If the internal list isn't already available read the config file
871 if (internalIDList.count()==0) 875 if (internalIDList.count()==0)
872 { 876 {
873 //if all references to the list are destried the contents will also be deleted 877 //if all references to the list are destried the contents will also be deleted
874 internalIDList.setAutoDelete(true); 878 internalIDList.setAutoDelete(true);
875 syntaxContextData *data; 879 syntaxContextData *data;
876 880
877 qDebug("Trying to read itemData section"); 881 odebug << "Trying to read itemData section" << oendl;
878 882
879 //Tell the syntax document class which file we want to parse and which data group 883 //Tell the syntax document class which file we want to parse and which data group
880 HlManager::self()->syntax->setIdentifier(identifier); 884 HlManager::self()->syntax->setIdentifier(identifier);
881 data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData"); 885 data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData");
882 //begin with the real parsing 886 //begin with the real parsing
883 while (HlManager::self()->syntax->nextGroup(data)) 887 while (HlManager::self()->syntax->nextGroup(data))
884 { 888 {
885 qDebug("Setting up one itemData element"); 889 odebug << "Setting up one itemData element" << oendl;
886 // read all attributes 890 // read all attributes
887 color=HlManager::self()->syntax->groupData(data,QString("color")); 891 color=HlManager::self()->syntax->groupData(data,QString("color"));
888 selColor=HlManager::self()->syntax->groupData(data,QString("selColor")); 892 selColor=HlManager::self()->syntax->groupData(data,QString("selColor"));
889 bold=HlManager::self()->syntax->groupData(data,QString("bold")); 893 bold=HlManager::self()->syntax->groupData(data,QString("bold"));
890 italic=HlManager::self()->syntax->groupData(data,QString("italic")); 894 italic=HlManager::self()->syntax->groupData(data,QString("italic"));
891 //check if the user overrides something 895 //check if the user overrides something
892 if ( (!color.isEmpty()) && (!selColor.isEmpty()) && (!bold.isEmpty()) && (!italic.isEmpty())) 896 if ( (!color.isEmpty()) && (!selColor.isEmpty()) && (!bold.isEmpty()) && (!italic.isEmpty()))
893 { 897 {
894 //create a user defined style 898 //create a user defined style
895 internalIDList.append(new ItemData( 899 internalIDList.append(new ItemData(
896 HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(), 900 HlManager::self()->syntax->groupData(data,QString("name")).simplifyWhiteSpace(),
897 getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))), 901 getDefStyleNum(HlManager::self()->syntax->groupData(data,QString("defStyleNum"))),
@@ -1303,34 +1307,34 @@ int HlManager::wildcardFind(const QString &fileName) {
1303 } 1307 }
1304 return -1; 1308 return -1;
1305} 1309}
1306 1310
1307 1311
1308int HlManager::makeAttribs(Highlight *highlight, Attribute *a, int maxAttribs) { 1312int HlManager::makeAttribs(Highlight *highlight, Attribute *a, int maxAttribs) {
1309 ItemStyleList defaultStyleList; 1313 ItemStyleList defaultStyleList;
1310 ItemStyle *defaultStyle; 1314 ItemStyle *defaultStyle;
1311 ItemDataList itemDataList; 1315 ItemDataList itemDataList;
1312 ItemData *itemData; 1316 ItemData *itemData;
1313 int nAttribs, z; 1317 int nAttribs, z;
1314 1318
1315 qDebug("HlManager::makeAttribs"); 1319 odebug << "HlManager::makeAttribs" << oendl;
1316 1320
1317 defaultStyleList.setAutoDelete(true); 1321 defaultStyleList.setAutoDelete(true);
1318 getDefaults(defaultStyleList); 1322 getDefaults(defaultStyleList);
1319 1323
1320// itemDataList.setAutoDelete(true); 1324// itemDataList.setAutoDelete(true);
1321 highlight->getItemDataList(itemDataList); 1325 highlight->getItemDataList(itemDataList);
1322 nAttribs = itemDataList.count(); 1326 nAttribs = itemDataList.count();
1323 for (z = 0; z < nAttribs; z++) { 1327 for (z = 0; z < nAttribs; z++) {
1324 qDebug("HlManager::makeAttribs: createing one attribute definition"); 1328 odebug << "HlManager::makeAttribs: createing one attribute definition" << oendl;
1325 itemData = itemDataList.at(z); 1329 itemData = itemDataList.at(z);
1326 if (itemData->defStyle) { 1330 if (itemData->defStyle) {
1327 // default style 1331 // default style
1328 defaultStyle = defaultStyleList.at(itemData->defStyleNum); 1332 defaultStyle = defaultStyleList.at(itemData->defStyleNum);
1329 a[z].col = defaultStyle->col; 1333 a[z].col = defaultStyle->col;
1330 a[z].selCol = defaultStyle->selCol; 1334 a[z].selCol = defaultStyle->selCol;
1331 a[z].bold = defaultStyle->bold; 1335 a[z].bold = defaultStyle->bold;
1332 a[z].italic = defaultStyle->italic; 1336 a[z].italic = defaultStyle->italic;
1333 } else { 1337 } else {
1334 // custom style 1338 // custom style
1335 a[z].col = itemData->col; 1339 a[z].col = itemData->col;
1336 a[z].selCol = itemData->selCol; 1340 a[z].selCol = itemData->selCol;