1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
3 // C++ Implementation: dvisourcesplitter
5 // Author: Jeroen Wijnhout <Jeroen.Wijnhout@kdemail.net>, (C) 2004
7 // Copyright: See COPYING file that comes with this distribution
12 #include "dvisourcesplitter.h"
13 #include "kvs_debug.h"
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
;
32 //remove src: if necessary
33 if ( filepart
.left(4) == "src:" ) filepart
= srclink
.mid(4);
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;
45 filepart
= filepart
.trimmed();
46 linepart
= linepart
.trimmed();
48 #ifdef DEBUG_SOURCESPLITTER
49 kDebug(kvs::dvi
) << "DVI_SourceSplitter: filepart " << filepart
<< " linepart " << linepart
;
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();
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();
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();
80 if ( tempInfo
.exists() ) { found
= true; break;}
85 m_fileInfo
= tempInfo
;
86 linepart
= linepart
.left(maxindex
- index
);
91 m_line
= linepart
.toInt(&ok
);
94 #ifdef DEBUG_SOURCESPLITTER
95 kDebug(kvs::dvi
) << "DVI_SourceSplitter: result: file " << m_fileInfo
.absoluteFilePath() << " line " << m_line
;