File indexing completed on 2024-05-05 17:15:16

0001 /**********************************************************************************
0002  *   Copyright (C) 2003 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net)          *
0003  *                 2011-2022 by Michel Ludwig (michel.ludwig@kdemail.net)         *
0004  **********************************************************************************/
0005 
0006 /***************************************************************************
0007  *                                                                         *
0008  *   This program is free software; you can redistribute it and/or modify  *
0009  *   it under the terms of the GNU General Public License as published by  *
0010  *   the Free Software Foundation; either version 2 of the License, or     *
0011  *   (at your option) any later version.                                   *
0012  *                                                                         *
0013  ***************************************************************************/
0014 
0015 #ifndef LATEXOUTPUTPARSER_H
0016 #define LATEXOUTPUTPARSER_H
0017 
0018 #include <QStack>
0019 
0020 #include "kileconstants.h"
0021 #include "kileextensions.h"
0022 #include "outputinfo.h"
0023 #include "parser.h"
0024 
0025 namespace KileParser {
0026 
0027 class LaTeXOutputParserInput : public ParserInput
0028 {
0029 public:
0030     LaTeXOutputParserInput(const QUrl &url, KileDocument::Extensions *extensions,
0031                            const QString& sourceFile,
0032                            // for QuickPreview
0033                            const QString &texfilename = "", int selrow = -1, int docrow = -1);
0034 
0035     KileDocument::Extensions *extensions;
0036     QString sourceFile;
0037     QString texfilename;
0038     int selrow;
0039     int docrow;
0040 };
0041 
0042 class LaTeXOutputParserOutput : public ParserOutput {
0043 public:
0044     LaTeXOutputParserOutput();
0045     virtual ~LaTeXOutputParserOutput();
0046 
0047     QString problem;
0048     QString logFile;
0049     LatexOutputInfoArray infoList;
0050     int nWarnings;
0051     int nErrors;
0052     int nBadBoxes;
0053 };
0054 
0055 class LOFStackItem
0056 {
0057 public:
0058     explicit LOFStackItem(const QString& file = QString(), bool sure = false) : m_file(file), m_reliable(sure) {}
0059 
0060     const QString& file() const {
0061         return m_file;
0062     }
0063     void setFile(const QString & file) {
0064         m_file = file;
0065     }
0066 
0067     bool reliable() const {
0068         return m_reliable;
0069     }
0070     void setReliable(bool sure) {
0071         m_reliable = sure;
0072     }
0073 
0074 private:
0075     QString m_file;
0076     bool m_reliable;
0077 };
0078 
0079 class LaTeXOutputParser : public Parser
0080 {
0081     Q_OBJECT
0082 
0083 public:
0084     LaTeXOutputParser(ParserThread *parserThread, LaTeXOutputParserInput *input, QObject *parent = Q_NULLPTR);
0085     virtual ~LaTeXOutputParser();
0086 
0087     ParserOutput* parse() override;
0088 
0089     void updateInfoLists(const QString &texfilename, int selrow, int docrow);
0090 
0091     enum {Start = 0, FileName, FileNameHeuristic, Error, Warning, BadBox, LineNumber};
0092 
0093     const QString& log() const {
0094         return m_log;
0095     }
0096 
0097     const QString& source() const  {
0098         return m_source;
0099     }
0100     const QString& path() const {
0101         return m_srcPath;
0102     }
0103 
0104 protected:
0105     /**
0106     Parses the given line for the start of new files or the end of
0107     old files.
0108     */
0109     void updateFileStack(const QString &strLine, short & dwCookie);
0110     void updateFileStackHeuristic(const QString &strLine, short & dwCookie);
0111 
0112     /**
0113     Forwards the currently parsed item to the item list.
0114     */
0115     void flushCurrentItem();
0116 
0117 public:
0118     /** Return number of errors etc. found in log-file. */
0119     void getErrorCount(int *errors, int *warnings, int *badboxes);
0120     void clearErrorCount() {
0121         m_nErrors=m_nWarnings=m_nBadBoxes=0 ;
0122     }
0123 
0124 protected:
0125     virtual short parseLine(const QString & strLine, short dwCookie);
0126 
0127     bool detectError(const QString & strLine, short &dwCookie);
0128     bool detectWarning(const QString & strLine, short &dwCookie);
0129     bool detectBadBox(const QString & strLine, short &dwCookie);
0130     bool detectLaTeXLineNumber(QString & warning, short & dwCookie, int len);
0131     bool detectBadBoxLineNumber(QString & strLine, short & dwCookie, int len);
0132 
0133     bool fileExists(const QString & name);
0134 
0135 protected:
0136     /**
0137     These constants are describing, which item types is currently
0138     parsed.
0139     */
0140     enum tagCookies
0141     {
0142         itmNone = 0,
0143         itmError,
0144         itmWarning,
0145         itmBadBox
0146     };
0147 
0148 
0149 private:
0150     KileDocument::Extensions *m_extensions;
0151     /** number or errors detected */
0152     int m_nErrors;
0153 
0154     /** number of warning detected */
0155     int m_nWarnings;
0156 
0157     /** number of bad boxes detected */
0158     int m_nBadBoxes;
0159 
0160     int m_nParens;
0161 
0162     int m_nOutputLines;
0163     QString m_log, m_source, m_srcPath;
0164 
0165     /** Pointer to list of Latex output information */
0166     LatexOutputInfoArray *m_infoList;
0167 
0168     QString m_logFile;
0169 
0170     // for QuickPreview
0171     QString texfilename;
0172     int selrow;
0173     int docrow;
0174 
0175     /**
0176     Stack containing the files parsed by the compiler. The top-most
0177     element is the currently parsed file.
0178     */
0179     QStack<LOFStackItem> m_stackFile;
0180 
0181     /** The item currently parsed. */
0182     LatexOutputInfo m_currentItem;
0183 
0184     /**
0185     Returns the zero based index of the currently parsed line in the
0186     output file.
0187     */
0188     int GetCurrentOutputLine() const;
0189 
0190     void setSource(const QString &src);
0191 
0192 };
0193 
0194 }
0195 
0196 #endif