X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLaTeX.C;h=d7f56bb5303c25646a3bd7886b4af4e821c98757;hb=e5b8f6956160631022fede155f55bad7951eecb8;hp=8cbb27f2fee7a88607af3c539bf742aa4043338f;hpb=e35725d5c0bfef496ebdb18b23539f7f78a336ff;p=lyx.git diff --git a/src/LaTeX.C b/src/LaTeX.C index 8cbb27f2fe..d7f56bb530 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -40,11 +40,14 @@ using support::absolutePath; 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; @@ -95,8 +98,8 @@ docstring runMessage(unsigned int count) * CLASS TEXERRORS */ -void TeXErrors::insertError(int line, string const & error_desc, - string const & error_text) +void TeXErrors::insertError(int line, docstring const & error_desc, + docstring const & error_text) { Error newerr(line, error_desc, error_text); errors.push_back(newerr); @@ -123,16 +126,16 @@ bool operator!=(Aux_Info const & a, Aux_Info const & o) */ 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")); } } @@ -148,22 +151,20 @@ void LaTeX::deleteFilesOnError() const // 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); } @@ -203,9 +204,9 @@ int LaTeX::run(TeXErrors & terr) // 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; @@ -219,7 +220,7 @@ int LaTeX::run(TeXErrors & terr) // 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()) { @@ -277,21 +278,24 @@ int LaTeX::run(TeXErrors & terr) // 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); + message(_("Running MakeIndex for nomencl.")); + // 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 @@ -355,19 +359,21 @@ int LaTeX::run(TeXErrors & terr) // more after this. // run makeindex if the .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); + message(_("Running MakeIndex for nomencl.")); + // 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 @@ -408,7 +414,8 @@ int LaTeX::run(TeXErrors & terr) 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); } @@ -432,17 +439,18 @@ bool LaTeX::runMakeIndex(string const & f, OutputParams const & runparams, vector const -LaTeX::scanAuxFiles(string const & file) +LaTeX::scanAuxFiles(FileName const & file) { vector 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(i) - + ".aux"; - if (!fs::exists(file2)) + + ".aux"); + if (!fs::exists(file2.toFilesystemEncoding())) break; result.push_back(scanAuxFile(file2)); } @@ -450,7 +458,7 @@ LaTeX::scanAuxFiles(string const & file) } -Aux_Info const LaTeX::scanAuxFile(string const & file) +Aux_Info const LaTeX::scanAuxFile(FileName const & file) { Aux_Info result; result.aux_file = file; @@ -459,11 +467,11 @@ Aux_Info const LaTeX::scanAuxFile(string const & 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\\{([^}]+)\\}"); @@ -504,7 +512,7 @@ void LaTeX::scanAuxFile(string const & file, Aux_Info & aux_info) aux_info.styles.insert(style); } else if (regex_match(token, sub, reg4)) { string const file2 = sub.str(1); - scanAuxFile(file2, aux_info); + scanAuxFile(FileName(makeAbsPath(file2)), aux_info); } } } @@ -523,14 +531,14 @@ void LaTeX::updateBibtexDependencies(DepTable & dep, it != bibtex_info.end(); ++it) { for (set::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::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); } @@ -548,7 +556,8 @@ bool LaTeX::runBibTeX(vector const & bibtex_info) 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); } @@ -562,9 +571,10 @@ int LaTeX::scanLogFile(TeXErrors & terr) 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)) { @@ -671,7 +681,11 @@ int LaTeX::scanLogFile(TeXErrors & terr) last_line = line; } if (line_count <= 5) { - terr.insertError(line, desc, errstr); + // FIXME UNICODE + // We have no idea what the encoding of the log file is + // (probably pure ascii, but maybe some localized + // latex compilers or packages exist) + terr.insertError(line, from_utf8(desc), from_utf8(errstr)); ++num_errors; } } @@ -721,19 +735,22 @@ void handleFoundFile(string const & ff, DepTable & head) lyxerr[Debug::DEPEND] << "AbsolutePath file: " << foundfile << endl; // On initial insert we want to do the update at once - // since this file can not be a file generated by + // 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] @@ -749,13 +766,13 @@ void handleFoundFile(string const & ff, DepTable & head) << "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] @@ -772,7 +789,7 @@ void LaTeX::deplog(DepTable & head) // 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: ([^ ]+).*"); @@ -792,7 +809,8 @@ void LaTeX::deplog(DepTable & head) // 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 = FileName(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 @@ -835,11 +853,11 @@ void LaTeX::deplog(DepTable & head) 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); }