SVN_SILENT made messages (.desktop file)
[kdegraphics.git] / okular / generators / dvi / dvisourcesplitter.cpp
blob37d5a1b13703e5d6f62289de71c3cded288347fd
1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
2 //
3 // C++ Implementation: dvisourcesplitter
4 //
5 // Author: Jeroen Wijnhout <Jeroen.Wijnhout@kdemail.net>, (C) 2004
6 //
7 // Copyright: See COPYING file that comes with this distribution
8 //
10 #include <config.h>
12 #include "dvisourcesplitter.h"
13 #include "kvs_debug.h"
15 #include <QDir>
17 //#define DEBUG_SOURCESPLITTER
20 DVI_SourceFileSplitter::DVI_SourceFileSplitter(const QString &srclink, const QString &dviFile)
22 QString filepart = srclink, linepart;
23 // if sourcefilename starts with a number
24 // then there could be a mix up, i.e. src:123file.tex
25 // line 123 and file.tex or line 12 and 3file.tex?
26 bool possibleNumberMixUp = false;
28 #ifdef DEBUG_SOURCESPLITTER
29 kDebug(kvs::dvi) << "DVI_SourceSplitter: srclink " << srclink;
30 #endif
32 //remove src: if necessary
33 if ( filepart.left(4) == "src:" ) filepart = srclink.mid(4);
35 //split first
36 quint32 max = filepart.length(), i = 0;
37 for(i=0; i<max; ++i) if ( !filepart[i].isDigit()) break;
38 linepart = filepart.left(i);
39 filepart = filepart.mid(i);
41 //check for number mix up
42 if ( filepart[0] != ' ' && (linepart.length() != 1) ) possibleNumberMixUp = true;
44 //remove a spaces
45 filepart = filepart.trimmed();
46 linepart = linepart.trimmed();
48 #ifdef DEBUG_SOURCESPLITTER
49 kDebug(kvs::dvi) << "DVI_SourceSplitter: filepart " << filepart << " linepart " << linepart;
50 #endif
52 //test if the file exists
53 m_fileInfo.setFile(QFileInfo(dviFile).absoluteDir(), filepart);
54 bool fiExists = m_fileInfo.exists();
56 //if it doesn't exist, but adding ".tex"
57 if ( !fiExists && QFileInfo(m_fileInfo.absoluteFilePath() + ".tex").exists() )
58 m_fileInfo.setFile(m_fileInfo.absoluteFilePath() + ".tex");
60 //if that doesn't help either, perhaps the file started with a
61 //number: move the numbers from the sourceline to the filename
62 //one by one (also try to add .tex repeatedly)
63 if ( possibleNumberMixUp && !fiExists )
65 QFileInfo tempInfo(m_fileInfo);
66 QString tempFileName = tempInfo.fileName();
67 quint32 index, maxindex = linepart.length();
68 bool found = false;
69 for ( index = 1; index < maxindex; ++index)
71 tempInfo.setFile(linepart.right(index) + tempFileName);
72 #ifdef DEBUG_SOURCESPLITTER
73 kDebug(kvs::dvi) << "DVI_SourceSplitter: trying " << tempInfo.fileName();
74 #endif
75 if ( tempInfo.exists() ) { found = true; break;}
76 tempInfo.setFile(linepart.right(index) + tempFileName + ".tex");
77 #ifdef DEBUG_SOURCESPLITTER
78 kDebug(kvs::dvi) << "DVI_SourceSplitter: trying " << tempInfo.fileName();
79 #endif
80 if ( tempInfo.exists() ) { found = true; break;}
83 if (found)
85 m_fileInfo = tempInfo;
86 linepart = linepart.left(maxindex - index);
90 bool ok;
91 m_line = linepart.toInt(&ok);
92 if (!ok) m_line = 0;
94 #ifdef DEBUG_SOURCESPLITTER
95 kDebug(kvs::dvi) << "DVI_SourceSplitter: result: file " << m_fileInfo.absoluteFilePath() << " line " << m_line;
96 #endif