1 /********************************************************************************** 2 * Copyright (C) 2003 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net) * 3 * 2011-2019 by Michel Ludwig (michel.ludwig@kdemail.net) * 4 ***********************************************************************************/ 5 6 /*************************************************************************** 7 * * 8 * This program is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU General Public License as published by * 10 * the Free Software Foundation; either version 2 of the License, or * 11 * (at your option) any later version. * 12 * * 13 ***************************************************************************/ 14 15 #ifndef LATEXOUTPUTPARSER_H 16 #define LATEXOUTPUTPARSER_H 17 18 #include <QLinkedList> 19 #include <QStack> 20 21 #include "kileconstants.h" 22 #include "kileextensions.h" 23 #include "outputinfo.h" 24 #include "parser.h" 25 26 namespace KileParser { 27 28 class LaTeXOutputParserInput : public ParserInput 29 { 30 public: 31 LaTeXOutputParserInput(const QUrl &url, KileDocument::Extensions *extensions, 32 const QString& sourceFile, 33 // for QuickPreview 34 const QString &texfilename = "", int selrow = -1, int docrow = -1); 35 36 KileDocument::Extensions *extensions; 37 QString sourceFile; 38 QString texfilename; 39 int selrow; 40 int docrow; 41 }; 42 43 class LaTeXOutputParserOutput : public ParserOutput { 44 public: 45 LaTeXOutputParserOutput(); 46 virtual ~LaTeXOutputParserOutput(); 47 48 QString problem; 49 QString logFile; 50 LatexOutputInfoArray infoList; 51 int nWarnings; 52 int nErrors; 53 int nBadBoxes; 54 }; 55 56 class LOFStackItem 57 { 58 public: m_file(file)59 explicit LOFStackItem(const QString& file = QString(), bool sure = false) : m_file(file), m_reliable(sure) {} 60 file()61 const QString& file() const { 62 return m_file; 63 } setFile(const QString & file)64 void setFile(const QString & file) { 65 m_file = file; 66 } 67 reliable()68 bool reliable() const { 69 return m_reliable; 70 } setReliable(bool sure)71 void setReliable(bool sure) { 72 m_reliable = sure; 73 } 74 75 private: 76 QString m_file; 77 bool m_reliable; 78 }; 79 80 class LaTeXOutputParser : public Parser 81 { 82 Q_OBJECT 83 84 public: 85 LaTeXOutputParser(ParserThread *parserThread, LaTeXOutputParserInput *input, QObject *parent = Q_NULLPTR); 86 virtual ~LaTeXOutputParser(); 87 88 ParserOutput* parse() override; 89 90 void updateInfoLists(const QString &texfilename, int selrow, int docrow); 91 92 enum {Start = 0, FileName, FileNameHeuristic, Error, Warning, BadBox, LineNumber}; 93 log()94 const QString& log() const { 95 return m_log; 96 } 97 source()98 const QString& source() const { 99 return m_source; 100 } path()101 const QString& path() const { 102 return m_srcPath; 103 } 104 105 protected: 106 /** 107 Parses the given line for the start of new files or the end of 108 old files. 109 */ 110 void updateFileStack(const QString &strLine, short & dwCookie); 111 void updateFileStackHeuristic(const QString &strLine, short & dwCookie); 112 113 /** 114 Forwards the currently parsed item to the item list. 115 */ 116 void flushCurrentItem(); 117 118 public: 119 /** Return number of errors etc. found in log-file. */ 120 void getErrorCount(int *errors, int *warnings, int *badboxes); clearErrorCount()121 void clearErrorCount() { 122 m_nErrors=m_nWarnings=m_nBadBoxes=0 ; 123 } 124 125 protected: 126 virtual short parseLine(const QString & strLine, short dwCookie); 127 128 bool detectError(const QString & strLine, short &dwCookie); 129 bool detectWarning(const QString & strLine, short &dwCookie); 130 bool detectBadBox(const QString & strLine, short &dwCookie); 131 bool detectLaTeXLineNumber(QString & warning, short & dwCookie, int len); 132 bool detectBadBoxLineNumber(QString & strLine, short & dwCookie, int len); 133 134 bool fileExists(const QString & name); 135 136 protected: 137 /** 138 These constants are describing, which item types is currently 139 parsed. 140 */ 141 enum tagCookies 142 { 143 itmNone = 0, 144 itmError, 145 itmWarning, 146 itmBadBox 147 }; 148 149 150 private: 151 KileDocument::Extensions *m_extensions; 152 /** number or errors detected */ 153 int m_nErrors; 154 155 /** number of warning detected */ 156 int m_nWarnings; 157 158 /** number of bad boxes detected */ 159 int m_nBadBoxes; 160 161 int m_nParens; 162 163 int m_nOutputLines; 164 QString m_log, m_source, m_srcPath; 165 166 /** Pointer to list of Latex output information */ 167 LatexOutputInfoArray *m_infoList; 168 169 QString m_logFile; 170 171 // for QuickPreview 172 QString texfilename; 173 int selrow; 174 int docrow; 175 176 /** 177 Stack containing the files parsed by the compiler. The top-most 178 element is the currently parsed file. 179 */ 180 QStack<LOFStackItem> m_stackFile; 181 182 /** The item currently parsed. */ 183 LatexOutputInfo m_currentItem; 184 185 /** 186 Returns the zero based index of the currently parsed line in the 187 output file. 188 */ 189 int GetCurrentOutputLine() const; 190 191 void setSource(const QString &src); 192 193 }; 194 195 } 196 197 #endif 198