using support::bformat;
using support::changeExtension;
using support::contains;
+using support::FileName;
using support::findtexfile;
using support::getcwd;
+using support::makeAbsPath;
using support::onlyFilename;
using support::prefixIs;
using support::quoteName;
+using support::removeExtension;
using support::rtrim;
using support::split;
using support::subst;
*/
LaTeX::LaTeX(string const & latex, OutputParams const & rp,
- string const & f, string const & p)
- : cmd(latex), file(f), path(p), runparams(rp)
+ FileName const & f)
+ : cmd(latex), file(f), runparams(rp)
{
num_errors = 0;
- depfile = file + ".dep";
if (prefixIs(cmd, "pdf")) { // Do we use pdflatex ?
- depfile += "-pdf";
- output_file = changeExtension(file,".pdf");
+ depfile = FileName(file.absFilename() + ".dep-pdf");
+ output_file = FileName(changeExtension(file.absFilename(), ".pdf"));
} else {
- output_file = changeExtension(file,".dvi");
+ depfile = FileName(file.absFilename() + ".dep");
+ output_file = FileName(changeExtension(file.absFilename(), ".dvi"));
}
}
// but the reason for the error might be in a generated file...
- string const ofname = onlyFilename(file);
-
// bibtex file
- string const bbl = changeExtension(ofname, ".bbl");
+ FileName const bbl(changeExtension(file.absFilename(), ".bbl"));
unlink(bbl);
// makeindex file
- string const ind = changeExtension(ofname, ".ind");
+ FileName const ind(changeExtension(file.absFilename(), ".ind"));
unlink(ind);
// nomencl file
- string const nls = changeExtension(ofname, ".nls");
+ FileName const nls(changeExtension(file.absFilename(), ".nls"));
unlink(nls);
// Also remove the aux file
- string const aux = changeExtension(ofname, ".aux");
+ FileName const aux(changeExtension(file.absFilename(), ".aux"));
unlink(aux);
}
bool rerun = false; // rerun requested
// The class LaTeX does not know the temp path.
- theBufferList().updateIncludedTeXfiles(getcwd(), runparams);
+ theBufferList().updateIncludedTeXfiles(getcwd().absFilename(), runparams);
// Never write the depfile if an error was encountered.
// remake the dependency file.
//
- bool had_depfile = fs::exists(depfile);
+ bool had_depfile = fs::exists(depfile.toFilesystemEncoding());
bool run_bibtex = false;
- string aux_file = onlyFilename(changeExtension(file, "aux"));
+ FileName const aux_file(changeExtension(file.absFilename(), "aux"));
if (had_depfile) {
lyxerr[Debug::DEPEND] << "Dependency file exists" << endl;
// Can't just check if anything has changed because it might have aborted
// on error last time... in which cas we need to re-run latex
// and collect the error messages (even if they are the same).
- if (!fs::exists(output_file)) {
+ if (!fs::exists(output_file.toFilesystemEncoding())) {
lyxerr[Debug::DEPEND]
<< "re-running LaTeX because output file doesn't exist." << endl;
} else if (!head.sumchange()) {
// memoir (at least) writes an empty *idx file in the first place.
// A second latex run is needed.
- rerun = fs::exists(changeExtension(file, ".idx"))
- && fs::is_empty(changeExtension(file, ".idx"));
+ FileName const idxfile(changeExtension(file.absFilename(), ".idx"));
+ rerun = fs::exists(idxfile.toFilesystemEncoding()) &&
+ fs::is_empty(idxfile.toFilesystemEncoding());
// run makeindex
- if (head.haschanged(onlyFilename(changeExtension(file, ".idx")))) {
+ if (head.haschanged(idxfile)) {
// no checks for now
lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
message(_("Running MakeIndex."));
- rerun |= runMakeIndex(onlyFilename(changeExtension(file, ".idx")), runparams);
+ // onlyFilename() is needed for cygwin
+ rerun |= runMakeIndex(onlyFilename(idxfile.absFilename()), runparams);
}
- if (head.haschanged(onlyFilename(changeExtension(file, ".nlo")))) {
+ if (head.haschanged(FileName(changeExtension(file.absFilename(), ".nlo")))) {
lyxerr[Debug::LATEX] << "Running MakeIndex for nomencl." << endl;
message(_("Running MakeIndex for nomencl."));
- string const nomenclstr = " -s nomencl.ist -o " + changeExtension(file, ".nls");
- rerun |= runMakeIndex(onlyFilename(changeExtension(file, ".nlo")), runparams, nomenclstr);
+ // onlyFilename() is needed for cygwin
+ string const nomenclstr = " -s nomencl.ist -o " + onlyFilename(changeExtension(file.toFilesystemEncoding(), ".nls"));
+ rerun |= runMakeIndex(onlyFilename(changeExtension(file.absFilename(), ".nlo")), runparams, nomenclstr);
}
// run bibtex
// more after this.
// run makeindex if the <file>.idx has changed or was generated.
- if (head.haschanged(onlyFilename(changeExtension(file, ".idx")))) {
+ if (head.haschanged(FileName(changeExtension(file.absFilename(), ".idx")))) {
// no checks for now
lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
message(_("Running MakeIndex."));
- rerun = runMakeIndex(onlyFilename(changeExtension(file, ".idx")), runparams);
+ // onlyFilename() is needed for cygwin
+ rerun = runMakeIndex(onlyFilename(changeExtension(file.absFilename(), ".idx")), runparams);
}
// I am not pretty sure if need this twice.
- if (head.haschanged(onlyFilename(changeExtension(file, ".nlo")))) {
+ if (head.haschanged(FileName(changeExtension(file.absFilename(), ".nlo")))) {
lyxerr[Debug::LATEX] << "Running MakeIndex for nomencl." << endl;
message(_("Running MakeIndex for nomencl."));
- string nomenclstr = " -s nomencl.ist -o " + changeExtension(file, ".nls");
- rerun |= runMakeIndex(onlyFilename(changeExtension(file, ".nlo")), runparams, nomenclstr);
+ // onlyFilename() is needed for cygwin
+ string nomenclstr = " -s nomencl.ist -o " + onlyFilename(changeExtension(file.toFilesystemEncoding(), ".nls"));
+ rerun |= runMakeIndex(onlyFilename(changeExtension(file.absFilename(), ".nlo")), runparams, nomenclstr);
}
// 2
int LaTeX::startscript()
{
- string tmp = cmd + ' ' + quoteName(file) + " > " + os::nulldev();
+ // onlyFilename() is needed for cygwin
+ string tmp = cmd + ' ' + quoteName(onlyFilename(file.toFilesystemEncoding())) + " > " + os::nulldev();
Systemcall one;
return one.startscript(Systemcall::Wait, tmp);
}
vector<Aux_Info> const
-LaTeX::scanAuxFiles(string const & file)
+LaTeX::scanAuxFiles(FileName const & file)
{
vector<Aux_Info> result;
result.push_back(scanAuxFile(file));
+ string const basename = removeExtension(file.absFilename());
for (int i = 1; i < 1000; ++i) {
- string const file2 = changeExtension(file, "")
+ FileName const file2(basename
+ '.' + convert<string>(i)
- + ".aux";
- if (!fs::exists(file2))
+ + ".aux");
+ if (!fs::exists(file2.toFilesystemEncoding()))
break;
result.push_back(scanAuxFile(file2));
}
}
-Aux_Info const LaTeX::scanAuxFile(string const & file)
+Aux_Info const LaTeX::scanAuxFile(FileName const & file)
{
Aux_Info result;
result.aux_file = file;
}
-void LaTeX::scanAuxFile(string const & file, Aux_Info & aux_info)
+void LaTeX::scanAuxFile(FileName const & file, Aux_Info & aux_info)
{
lyxerr[Debug::LATEX] << "Scanning aux file: " << file << endl;
- ifstream ifs(file.c_str());
+ ifstream ifs(file.toFilesystemEncoding().c_str());
string token;
static regex const reg1("\\\\citation\\{([^}]+)\\}");
static regex const reg2("\\\\bibdata\\{([^}]+)\\}");
aux_info.styles.insert(style);
} else if (regex_match(token, sub, reg4)) {
string const file2 = sub.str(1);
- scanAuxFile(file2, aux_info);
+ scanAuxFile(makeAbsPath(file2), aux_info);
}
}
}
it != bibtex_info.end(); ++it) {
for (set<string>::const_iterator it2 = it->databases.begin();
it2 != it->databases.end(); ++it2) {
- string file = findtexfile(*it2, "bib");
+ FileName const file = findtexfile(*it2, "bib");
if (!file.empty())
dep.insert(file, true);
}
for (set<string>::const_iterator it2 = it->styles.begin();
it2 != it->styles.end(); ++it2) {
- string file = findtexfile(*it2, "bst");
+ FileName const file = findtexfile(*it2, "bst");
if (!file.empty())
dep.insert(file, true);
}
result = true;
string tmp = lyxrc.bibtex_command + " ";
- tmp += quoteName(onlyFilename(changeExtension(it->aux_file, string())));
+ // onlyFilename() is needed for cygwin
+ tmp += quoteName(onlyFilename(removeExtension(it->aux_file.absFilename())));
Systemcall one;
one.startscript(Systemcall::Wait, tmp);
}
int last_line = -1;
int line_count = 1;
int retval = NO_ERRORS;
- string tmp = onlyFilename(changeExtension(file, ".log"));
+ string tmp = onlyFilename(changeExtension(file.absFilename(), ".log"));
lyxerr[Debug::LATEX] << "Log file: " << tmp << endl;
- ifstream ifs(tmp.c_str());
+ FileName const fn = FileName(makeAbsPath(tmp));
+ ifstream ifs(fn.toFilesystemEncoding().c_str());
string token;
while (getline(ifs, token)) {
// On initial insert we want to do the update at once
// since this file cannot be a file generated by
// the latex run.
- if (fs::exists(foundfile) && !fs::is_directory(foundfile))
- head.insert(foundfile, true);
+ FileName const absname(foundfile);
+ if (fs::exists(absname.toFilesystemEncoding()) &&
+ !fs::is_directory(absname.toFilesystemEncoding()))
+ head.insert(absname, true);
return;
}
string const onlyfile = onlyFilename(foundfile);
+ FileName const absname(makeAbsPath(onlyfile));
// (2) foundfile is in the tmpdir
// insert it into head
- if (fs::exists(onlyfile)) {
+ if (fs::exists(absname.toFilesystemEncoding())) {
static regex unwanted("^.*\\.(aux|log|dvi|bbl|ind|glo)$");
if (regex_match(onlyfile, unwanted)) {
lyxerr[Debug::DEPEND]
<< "Tmpdir TeX file: "
<< onlyfile
<< endl;
- head.insert(onlyfile, true);
+ head.insert(absname, true);
} else {
lyxerr[Debug::DEPEND]
<< "In tmpdir file:"
<< onlyfile
<< endl;
- head.insert(onlyfile);
+ head.insert(absname);
}
} else
lyxerr[Debug::DEPEND]
// files used by the LaTeX run. The files are then entered into the
// dependency file.
- string const logfile = onlyFilename(changeExtension(file, ".log"));
+ string const logfile = onlyFilename(changeExtension(file.absFilename(), ".log"));
static regex reg1(".*\\([^)]+.*");
static regex reg2("File: ([^ ]+).*");
// This line is not present if no toc should be created.
static regex miktexTocReg("\\\\tf@toc=\\\\write.*");
- ifstream ifs(logfile.c_str());
+ FileName const fn(makeAbsPath(logfile));
+ ifstream ifs(fn.toFilesystemEncoding().c_str());
while (ifs) {
// Ok, the scanning of files here is not sufficient.
// Sometimes files are named by "File: xxx" only
else if (regex_match(token, sub, regnomencl))
handleFoundFile(sub.str(1), head);
else if (regex_match(token, sub, miktexTocReg))
- handleFoundFile(changeExtension(file, ".toc"), head);
+ handleFoundFile(onlyFilename(changeExtension(file.absFilename(), ".toc")), head);
}
// Make sure that the main .tex file is in the dependancy file.
- head.insert(onlyFilename(file), true);
+ head.insert(file, true);
}