From 979fdf74564c6cbbb832090b8f9c8f84532b8f54 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Wed, 27 Dec 2006 10:56:11 +0000 Subject: [PATCH] Fix strange bibtex problem by converting some more functions to use FileName instead of std::string * src/support/lyxlib.h * src/support/getcwd.C (getcwd): return a FileName, not a std::string in filesystem encoding * src/support/filetools.[Ch] (makeAbsPath): return a FileName, not a std::string in undefined encoding * src/support/lyxlib.h * src/support/tempName.C (makeAbsPath): return a FileName, not a std::string in undefined encoding * many other files: Adjust to the changes above git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16399 a592a061-630c-0410-9148-cb99ea01b6c8 --- Status.15x | 51 +++++++++++----------- src/BufferView.C | 3 +- src/Chktex.C | 2 +- src/LaTeX.C | 6 +-- src/buffer.C | 6 +-- src/buffer_funcs.C | 2 +- src/converter.C | 2 +- src/exporter.C | 2 +- src/frontends/controllers/ControlInclude.C | 7 ++- src/frontends/controllers/ControlRef.C | 2 +- src/frontends/controllers/helper_funcs.C | 4 +- src/frontends/qt4/FileDialog.C | 12 ++--- src/graphics/GraphicsCacheItem.C | 8 ++-- src/graphics/GraphicsConverter.C | 9 ++-- src/insets/ExternalSupport.C | 8 ++-- src/insets/insetbibtex.C | 14 +++--- src/insets/insetexternal.C | 6 +-- src/insets/insetgraphics.C | 4 +- src/insets/insetinclude.C | 37 ++++++++-------- src/lyx_cb.C | 6 +-- src/lyxfunc.C | 22 +++++----- src/lyxvc.C | 2 +- src/support/filename.C | 7 ++- src/support/filename.h | 8 +++- src/support/filetools.C | 34 +++++++-------- src/support/filetools.h | 4 +- src/support/getcwd.C | 12 ++--- src/support/lyxlib.h | 11 ++--- src/support/package.C.in | 8 ++-- src/support/path.C | 2 +- src/support/path.h | 4 +- src/support/tempname.C | 12 ++--- src/tex2lyx/tex2lyx.C | 17 ++++---- src/tex2lyx/text.C | 31 ++++++++----- 34 files changed, 195 insertions(+), 170 deletions(-) diff --git a/Status.15x b/Status.15x index f3e23147df..40bf45c6c6 100644 --- a/Status.15x +++ b/Status.15x @@ -52,30 +52,6 @@ FILE * agu-dtd is used as the default document class, which is not a good idea in 99% of all cases -* On Windows (using scons/MSVC): Create an empty bibtex file, called - 'lit.bib'. Create a new LyX document 'lit.lyx' in the same directory - that has a bibliography inset pointing to lit.bib. - Now, if lit.[lyx|bib] are stored in a path with ASCII characters only, - class FileName is used as follows: - FileName::FileName(string const &): C:/foo/lit.lyx.emergency - FileName::FileName(string const &): C:/foo/#lit.lyx# - FileName::FileName(string const &): C:/foo/ - FileName::FileName(string const &): C:/foo/lit.bib - FileName::FileName(string const &): C:/lyx-trunk/build-msvc/bin - FileName::FileName(string const &): C:/foo/lit.lyx,v - FileName::FileName(string const &): C:/foo/RCS/lit.lyx,v - FileName::FileName(string const &): C:/foo//CVS/Entries - FileName::FileName(string const &): C:/foo/lit.lyx - However, if the path contains a German Umlaut ("bäh"), LyX crashes: - FileName::FileName(string const &): C:/bäh/lit.lyx.emergency - FileName::FileName(string const &): C:/bäh/#lit.lyx# - FileName::FileName(string const &): C:/bäh/ - FileName::FileName(string const &): C:/bäh/lit.bib - FileName::FileName(string const &): lit.bib - Assertion triggered in __thiscall lyx::support::FileName::FileName(const class std::basic_string,class std::allocator > &) by failing check "empty() || absolutePath(name_)" in fil -e C:\cygwin\home\ms\lyx-trunk\src\support\filename.C:48 - Odd, isn't it? - SPELL CHECKING (Joost 4/11/06) @@ -662,4 +638,29 @@ CREDITS: FIXED (Abdel 2006-12-24): centralWidget() was not the WorkArea due to the new TabBar support. - \ No newline at end of file + +* On Windows (using scons/MSVC): Create an empty bibtex file, called + 'lit.bib'. Create a new LyX document 'lit.lyx' in the same directory + that has a bibliography inset pointing to lit.bib. + Now, if lit.[lyx|bib] are stored in a path with ASCII characters only, + class FileName is used as follows: + FileName::FileName(string const &): C:/foo/lit.lyx.emergency + FileName::FileName(string const &): C:/foo/#lit.lyx# + FileName::FileName(string const &): C:/foo/ + FileName::FileName(string const &): C:/foo/lit.bib + FileName::FileName(string const &): C:/lyx-trunk/build-msvc/bin + FileName::FileName(string const &): C:/foo/lit.lyx,v + FileName::FileName(string const &): C:/foo/RCS/lit.lyx,v + FileName::FileName(string const &): C:/foo//CVS/Entries + FileName::FileName(string const &): C:/foo/lit.lyx + However, if the path contains a German Umlaut ("bäh"), LyX crashes: + FileName::FileName(string const &): C:/bäh/lit.lyx.emergency + FileName::FileName(string const &): C:/bäh/#lit.lyx# + FileName::FileName(string const &): C:/bäh/ + FileName::FileName(string const &): C:/bäh/lit.bib + FileName::FileName(string const &): lit.bib + Assertion triggered in __thiscall lyx::support::FileName::FileName(const class std::basic_string,class std::allocator > &) by failing check "empty() || absolutePath(name_)" in fil +e C:\cygwin\home\ms\lyx-trunk\src\support\filename.C:48 + Odd, isn't it? + FIXED (Enrico (found problem) and Georg (fix) 2006-12-27) + diff --git a/src/BufferView.C b/src/BufferView.C index cd8e79892a..2ff1ec0a07 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -88,7 +88,6 @@ using support::fileSearch; using support::isDirWriteable; using support::isFileReadable; using support::makeDisplayPath; -using support::makeAbsPath; using support::package; using std::distance; @@ -1393,7 +1392,7 @@ void BufferView::menuInsertLyXFile(string const & filenm) if (buffer_) { string const trypath = buffer_->filePath(); // If directory is writeable, use this as default. - if (isDirWriteable(trypath)) + if (isDirWriteable(FileName(trypath))) initpath = trypath; } diff --git a/src/Chktex.C b/src/Chktex.C index abe36ebf28..981999f303 100644 --- a/src/Chktex.C +++ b/src/Chktex.C @@ -63,7 +63,7 @@ int Chktex::scanLogFile(TeXErrors & terr) { int retval = 0; - // FIXME: Find out whether we can onlyFilename() is really needed, + // FIXME: Find out whether onlyFilename() is really needed, // or whether makeAbsPath(onlyFilename()) is a noop here FileName const tmp(makeAbsPath(onlyFilename(changeExtension(file, ".log")))); diff --git a/src/LaTeX.C b/src/LaTeX.C index d7f56bb530..e840688324 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -184,7 +184,7 @@ int LaTeX::run(TeXErrors & terr) 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. @@ -512,7 +512,7 @@ void LaTeX::scanAuxFile(FileName 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(FileName(makeAbsPath(file2)), aux_info); + scanAuxFile(makeAbsPath(file2), aux_info); } } } @@ -809,7 +809,7 @@ void LaTeX::deplog(DepTable & head) // This line is not present if no toc should be created. static regex miktexTocReg("\\\\tf@toc=\\\\write.*"); - FileName const fn = FileName(makeAbsPath(logfile)); + FileName const fn(makeAbsPath(logfile)); ifstream ifs(fn.toFilesystemEncoding().c_str()); while (ifs) { // Ok, the scanning of files here is not sufficient. diff --git a/src/buffer.C b/src/buffer.C index 0e7944a176..cd83f5fd47 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -102,7 +102,6 @@ using support::createBufferTmpDir; using support::destroyDir; using support::FileName; using support::getFormatFromContents; -using support::isDirWriteable; using support::libFileSearch; using support::latex_path; using support::ltrim; @@ -389,9 +388,8 @@ void Buffer::setReadonly(bool const flag) void Buffer::setFileName(string const & newfile) { - string const filename = makeAbsPath(newfile); - pimpl_->filename = FileName(filename); - params().filepath = onlyPath(filename); + pimpl_->filename = makeAbsPath(newfile); + params().filepath = onlyPath(pimpl_->filename.absFilename()); setReadonly(fs::is_readonly(pimpl_->filename.toFilesystemEncoding())); updateTitles(); } diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index a756f0c253..8ed3e855a5 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -191,7 +191,7 @@ Buffer * newFile(string const & filename, string const & templatename, if (templatename.empty()) tname = libFileSearch("templates", "defaults.lyx"); else - tname = FileName(makeAbsPath(templatename)); + tname = makeAbsPath(templatename); if (!tname.empty()) { if (!b->readFile(tname)) { diff --git a/src/converter.C b/src/converter.C index 37edc5dde3..200e0a5a07 100644 --- a/src/converter.C +++ b/src/converter.C @@ -451,7 +451,7 @@ bool Converters::convert(Buffer const * buffer, " < " + quoteName(infile2 + ".out") + " > " + quoteName(logfile); one.startscript(Systemcall::Wait, command2); - if (!scanLog(*buffer, command, FileName(makeAbsPath(logfile, path)), errorList)) + if (!scanLog(*buffer, command, makeAbsPath(logfile, path), errorList)) return false; } diff --git a/src/exporter.C b/src/exporter.C index 853e8b7db1..3142ddf7aa 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -243,7 +243,7 @@ bool Exporter::Export(Buffer * buffer, string const & format, string const fmt = formats.getFormatFromFile(it->sourceName); status = copyFile(fmt, it->sourceName, - FileName(makeAbsPath(it->exportName, dest)), + makeAbsPath(it->exportName, dest), it->exportName, status == FORCE); } if (status == CANCEL) { diff --git a/src/frontends/controllers/ControlInclude.C b/src/frontends/controllers/ControlInclude.C index ad01b38bde..e45206b90e 100644 --- a/src/frontends/controllers/ControlInclude.C +++ b/src/frontends/controllers/ControlInclude.C @@ -111,11 +111,10 @@ void ControlInclude::load(string const & file) bool ControlInclude::fileExists(string const & file) { - string const fileWithAbsPath - = makeAbsPath(file, - onlyPath(kernel().buffer().fileName())); + FileName const fileWithAbsPath( + makeAbsPath(file, onlyPath(kernel().buffer().fileName()))); - if (isFileReadable(FileName(fileWithAbsPath))) + if (isFileReadable(fileWithAbsPath)) return true; return false; diff --git a/src/frontends/controllers/ControlRef.C b/src/frontends/controllers/ControlRef.C index 426cd7bf50..7b1b836546 100644 --- a/src/frontends/controllers/ControlRef.C +++ b/src/frontends/controllers/ControlRef.C @@ -38,7 +38,7 @@ ControlRef::ControlRef(Dialog & d) vector const ControlRef::getLabelList(string const & name) const { - Buffer const & buf = *theBufferList().getBuffer(makeAbsPath(name)); + Buffer const & buf = *theBufferList().getBuffer(makeAbsPath(name).absFilename()); vector list; buf.getLabelList(list); return list; diff --git a/src/frontends/controllers/helper_funcs.C b/src/frontends/controllers/helper_funcs.C index e77006f3e7..3743fd86b4 100644 --- a/src/frontends/controllers/helper_funcs.C +++ b/src/frontends/controllers/helper_funcs.C @@ -80,8 +80,8 @@ docstring const browseRelFile(docstring const & filename, pair const & dir1, pair const & dir2) { - docstring const fname = lyx::from_utf8( - makeAbsPath(lyx::to_utf8(filename), lyx::to_utf8(refpath))); + docstring const fname = from_utf8(makeAbsPath( + to_utf8(filename), to_utf8(refpath)).absFilename()); docstring const outname = browseFile(fname, title, filters, save, dir1, dir2); diff --git a/src/frontends/qt4/FileDialog.C b/src/frontends/qt4/FileDialog.C index 5552184218..106a517c10 100644 --- a/src/frontends/qt4/FileDialog.C +++ b/src/frontends/qt4/FileDialog.C @@ -82,8 +82,8 @@ FileDialog::Result const FileDialog::save(docstring const & path, result.first = FileDialog::Chosen; #ifdef USE_NATIVE_FILEDIALOG - docstring const startsWith - = lyx::from_utf8(makeAbsPath(lyx::to_utf8(suggested), lyx::to_utf8(path))); + docstring const startsWith = from_utf8( + makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename()); result.second = lyx::from_utf8(internal_path(fromqstr( QFileDialog::getSaveFileName(qApp->focusWidget(), toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) )))); @@ -118,8 +118,8 @@ FileDialog::Result const FileDialog::open(docstring const & path, result.first = FileDialog::Chosen; #ifdef USE_NATIVE_FILEDIALOG - docstring const startsWith = - lyx::from_utf8(makeAbsPath(lyx::to_utf8(suggested), lyx::to_utf8(path))); + docstring const startsWith = from_utf8( + makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename()); result.second = lyx::from_utf8(internal_path(fromqstr( QFileDialog::getOpenFileName(qApp->focusWidget(), toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) )))); @@ -150,8 +150,8 @@ FileDialog::Result const FileDialog::opendir(docstring const & path, result.first = FileDialog::Chosen; #ifdef USE_NATIVE_FILEDIALOG - docstring const startsWith - = lyx::from_utf8(makeAbsPath(lyx::to_utf8(suggested), lyx::to_utf8(path))); + docstring const startsWith = from_utf8( + makeAbsPath(to_utf8(suggested), to_utf8(path)).absFilename()); result.second = lyx::from_utf8(internal_path(fromqstr( QFileDialog::getExistingDirectory(qApp->focusWidget(), toqstr(title_),toqstr(startsWith))))); diff --git a/src/graphics/GraphicsCacheItem.C b/src/graphics/GraphicsCacheItem.C index db07b16eb2..ac99adb214 100644 --- a/src/graphics/GraphicsCacheItem.C +++ b/src/graphics/GraphicsCacheItem.C @@ -385,7 +385,7 @@ void CacheItem::Impl::convertToDisplayFormat() FileName filename; zipped_ = zippedFile(filename_); if (zipped_) { - unzipped_filename_ = FileName(tempName(string(), filename_.toFilesystemEncoding())); + unzipped_filename_ = tempName(FileName(), filename_.toFilesystemEncoding()); if (unzipped_filename_.empty()) { setStatus(ErrorConverting); lyxerr[Debug::GRAPHICS] @@ -432,17 +432,17 @@ void CacheItem::Impl::convertToDisplayFormat() // Add some stuff to create a uniquely named temporary file. // This file is deleted in loadImage after it is loaded into memory. - string const to_file_base = tempName(string(), "CacheItem"); + FileName const to_file_base(tempName(FileName(), "CacheItem")); remove_loaded_file_ = true; // Remove the temp file, we only want the name... // FIXME: This is unsafe! - unlink(FileName(to_file_base)); + unlink(to_file_base); // Connect a signal to this->imageConverted and pass this signal to // the graphics converter so that we can load the modified file // on completion of the conversion process. - converter_.reset(new Converter(filename, to_file_base, from, to_)); + converter_.reset(new Converter(filename, to_file_base.absFilename(), from, to_)); converter_->connect(boost::bind(&Impl::imageConverted, this, _1)); converter_->startConversion(); } diff --git a/src/graphics/GraphicsConverter.C b/src/graphics/GraphicsConverter.C index c9f6cdd10e..02eea8a48a 100644 --- a/src/graphics/GraphicsConverter.C +++ b/src/graphics/GraphicsConverter.C @@ -30,6 +30,7 @@ namespace support = lyx::support; +using support::addExtension; using support::changeExtension; using support::FileName; using support::Forkedcall; @@ -301,14 +302,14 @@ static void build_script(FileName const & from_file, // Remember to remove the temp file because we only want the name... static int counter = 0; string const tmp = "gconvert" + convert(counter++); - string const to_base = tempName(string(), tmp); - unlink(FileName(to_base)); + FileName const to_base(tempName(FileName(), tmp)); + unlink(to_base); // Create a copy of the file in case the original name contains // problematic characters like ' or ". We can work around that problem // in python, but the converters might be shell scripts and have more // troubles with it. - string outfile = changeExtension(to_base, getExtension(from_file.absFilename())); + string outfile = addExtension(to_base.absFilename(), getExtension(from_file.absFilename())); script << "infile = " << quoteName(from_file.absFilename(), quote_python) << "\n" "outfile = " << quoteName(outfile, quote_python) << "\n" "shutil.copy(infile, outfile)\n"; @@ -363,7 +364,7 @@ static void build_script(FileName const & from_file, // Build the conversion command string const infile = outfile; string const infile_base = changeExtension(infile, string()); - outfile = changeExtension(to_base, conv.To->extension()); + outfile = addExtension(to_base.absFilename(), conv.To->extension()); // Store these names in the python script script << "infile = " << quoteName(infile, quote_python) << "\n" diff --git a/src/insets/ExternalSupport.C b/src/insets/ExternalSupport.C index f4410fe1c9..f724b85168 100644 --- a/src/insets/ExternalSupport.C +++ b/src/insets/ExternalSupport.C @@ -91,7 +91,7 @@ string const doSubstitution(InsetExternalParams const & params, params.filename.outputFilename(parentpath); string const basename = support::changeExtension( support::onlyFilename(filename), string()); - string const absname = support::makeAbsPath(filename, parentpath); + string const absname = support::makeAbsPath(filename, parentpath).absFilename(); string result = s; if (what != ALL_BUT_PATHS) { @@ -167,7 +167,7 @@ string const doSubstitution(InsetExternalParams const & params, string const file = result.substr(pos + 12, end - (pos + 12)); string contents; - FileName const absfile = FileName( + FileName const absfile( support::makeAbsPath(file, m_buffer->temppath())); if (support::isFileReadable(absfile)) contents = support::getFileContents(absfile); @@ -242,7 +242,7 @@ void updateExternal(InsetExternalParams const & params, // We copy the source file to the temp dir and do the conversion // there if necessary - FileName const temp_file = FileName( + FileName const temp_file( support::makeAbsPath(params.filename.mangledFilename(), m_buffer->temppath())); if (!params.filename.empty()) { @@ -265,7 +265,7 @@ void updateExternal(InsetExternalParams const & params, string const to_file = doSubstitution(params, buffer, outputFormat.updateResult, false, true); - FileName const abs_to_file = FileName( + FileName const abs_to_file( support::makeAbsPath(to_file, m_buffer->temppath())); // Record the referenced files for the exporter. diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index f194c30e4e..8d3a3f6cd4 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -113,7 +113,7 @@ namespace { string normalize_name(Buffer const & buffer, OutputParams const & runparams, string const & name, string const & ext) { - string const fname = makeAbsPath(name, buffer.filePath()); + string const fname = makeAbsPath(name, buffer.filePath()).absFilename(); if (absolutePath(name) || !isFileReadable(FileName(fname + ext))) return name; else if (!runparams.nice) @@ -166,8 +166,8 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os, string utf8input(to_utf8(input)); string database = normalize_name(buffer, runparams, utf8input, ".bib"); - string const try_in_file = makeAbsPath(database + ".bib", buffer.filePath()); - bool const not_from_texmf = isFileReadable(FileName(try_in_file)); + FileName const try_in_file(makeAbsPath(database + ".bib", buffer.filePath())); + bool const not_from_texmf = isFileReadable(try_in_file); if (!runparams.inComment && !runparams.dryrun && !runparams.nice && not_from_texmf) { @@ -175,7 +175,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os, // mangledFilename() needs the extension DocFileName const in_file = DocFileName(try_in_file); database = removeExtension(in_file.mangledFilename()); - FileName const out_file = FileName(makeAbsPath(database + ".bib", + FileName const out_file(makeAbsPath(database + ".bib", buffer.getMasterBuffer()->temppath())); bool const success = copy(in_file, out_file); @@ -221,8 +221,8 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os, if (!style.empty()) { string base = normalize_name(buffer, runparams, style, ".bst"); - string const try_in_file = makeAbsPath(base + ".bst", buffer.filePath()); - bool const not_from_texmf = isFileReadable(FileName(try_in_file)); + FileName const try_in_file(makeAbsPath(base + ".bst", buffer.filePath())); + bool const not_from_texmf = isFileReadable(try_in_file); // If this style does not come from texmf and we are not // exporting to .tex copy it to the tmp directory. // This prevents problems with spaces and 8bit charcaters @@ -232,7 +232,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os, // use new style name DocFileName const in_file = DocFileName(try_in_file); base = removeExtension(in_file.mangledFilename()); - FileName const out_file = FileName(makeAbsPath(base + ".bst", + FileName const out_file(makeAbsPath(base + ".bst", buffer.getMasterBuffer()->temppath())); bool const success = copy(in_file, out_file); if (!success) { diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index d0b0f86fe2..a047a4fb94 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -70,11 +70,11 @@ namespace external { TempName::TempName() { - string const tempname = support::tempName(string(), "lyxext"); + support::FileName const tempname(support::tempName(support::FileName(), "lyxext")); // FIXME: This is unsafe - support::unlink(support::FileName(tempname)); + support::unlink(tempname); // must have an extension for the converter code to work correctly. - tempname_ = support::FileName(tempname + ".tmp"); + tempname_ = support::FileName(tempname.absFilename() + ".tmp"); } diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index ee7c29f340..a012012cf3 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -502,9 +502,9 @@ copyToDirIfNeeded(DocFileName const & file, string const & dir) string::size_type const ext_len = file_in.length() - base.length(); mangled[mangled.length() - ext_len] = '.'; } - string const file_out = support::makeAbsPath(mangled, dir); + FileName const file_out(support::makeAbsPath(mangled, dir)); - return copyFileIfNeeded(file, FileName(file_out)); + return copyFileIfNeeded(file, file_out); } diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 859aba0cb3..c53a8330a9 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -217,7 +217,7 @@ string const parentFilename(Buffer const & buffer) } -string const includedFilename(Buffer const & buffer, +FileName const includedFilename(Buffer const & buffer, InsetCommandParams const & params) { return makeAbsPath(to_utf8(params["filename"]), @@ -333,7 +333,7 @@ Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params if (isVerbatim(params)) return 0; - string const included_file = includedFilename(buffer, params); + string const included_file = includedFilename(buffer, params).absFilename(); if (!isLyXFilename(included_file)) return 0; @@ -347,18 +347,17 @@ bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params) if (isVerbatim(params)) return false; - string const included_file = includedFilename(buffer, params); - if (!isLyXFilename(included_file)) + FileName const included_file = includedFilename(buffer, params); + if (!isLyXFilename(included_file.absFilename())) return false; - Buffer * buf = theBufferList().getBuffer(included_file); + Buffer * buf = theBufferList().getBuffer(included_file.absFilename()); if (!buf) { // the readonly flag can/will be wrong, not anymore I think. - FileName const fullname(included_file); - if (!fs::exists(fullname.toFilesystemEncoding())) + if (!fs::exists(included_file.toFilesystemEncoding())) return false; - buf = theBufferList().newBuffer(included_file); - if (!loadLyXFile(buf, fullname)) + buf = theBufferList().newBuffer(included_file.absFilename()); + if (!loadLyXFile(buf, included_file)) return false; } if (buf) @@ -498,7 +497,7 @@ int InsetInclude::plaintext(Buffer const & buffer, odocstream & os, if (isVerbatim(params_)) { // FIXME: We don't know the encoding of the file docstring const str = from_utf8( - getFileContents(FileName(includedFilename(buffer, params_)))); + getFileContents(includedFilename(buffer, params_))); os << str; // Return how many newlines we issued. return int(lyx::count(str.begin(), str.end(), '\n')); @@ -516,7 +515,7 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os, if (incfile.empty()) return 0; - string const included_file = includedFilename(buffer, params_); + string const included_file = includedFilename(buffer, params_).absFilename(); // write it to a file (so far the complete file) string const exportfile = changeExtension(incfile, ".sgml"); @@ -561,7 +560,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const Buffer const & buffer = features.buffer(); - string const included_file = includedFilename(buffer, params_); + string const included_file = includedFilename(buffer, params_).absFilename(); if (isLyXFilename(included_file)) writefile = changeExtension(included_file, ".sgml"); @@ -571,7 +570,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const if (!features.runparams().nice && !isVerbatim(params_)) { incfile = DocFileName(writefile).mangledFilename(); writefile = makeAbsPath(incfile, - buffer.getMasterBuffer()->temppath()); + buffer.getMasterBuffer()->temppath()).absFilename(); } features.includeFile(include_label, writefile); @@ -601,7 +600,7 @@ void InsetInclude::getLabelList(Buffer const & buffer, std::vector & list) const { if (loadIfNeeded(buffer, params_)) { - string const included_file = includedFilename(buffer, params_); + string const included_file = includedFilename(buffer, params_).absFilename(); Buffer * tmp = theBufferList().getBuffer(included_file); tmp->setParentName(""); tmp->getLabelList(list); @@ -614,7 +613,7 @@ void InsetInclude::fillWithBibKeys(Buffer const & buffer, std::vector > & keys) const { if (loadIfNeeded(buffer, params_)) { - string const included_file = includedFilename(buffer, params_); + string const included_file = includedFilename(buffer, params_).absFilename(); Buffer * tmp = theBufferList().getBuffer(included_file); tmp->setParentName(""); tmp->fillWithBibKeys(keys); @@ -727,10 +726,10 @@ namespace { bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer) { - string const included_file = includedFilename(buffer, params); + FileName const included_file = includedFilename(buffer, params); return type(params) == INPUT && params.preview() && - isFileReadable(FileName(included_file)); + isFileReadable(included_file); } @@ -751,7 +750,7 @@ void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset, InsetCommandParams const & params = inset.params(); if (RenderPreview::status() != LyXRC::PREVIEW_OFF && preview_wanted(params, buffer)) { - renderer.setAbsFile(FileName(includedFilename(buffer, params))); + renderer.setAbsFile(includedFilename(buffer, params)); docstring const snippet = latex_string(inset, buffer); renderer.addPreview(snippet, buffer); } @@ -764,7 +763,7 @@ void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const { Buffer const & buffer = ploader.buffer(); if (preview_wanted(params(), buffer)) { - preview_->setAbsFile(FileName(includedFilename(buffer, params()))); + preview_->setAbsFile(includedFilename(buffer, params())); docstring const snippet = latex_string(*this, buffer); preview_->addPreview(snippet, ploader); } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 30f53dee5e..8b169149e4 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -155,7 +155,7 @@ bool writeAs(Buffer * buffer, string const & newname) return false; // Make sure the absolute filename ends with appropriate suffix - fname = makeAbsPath(fname); + fname = makeAbsPath(fname).absFilename(); if (!isLyXFilename(fname)) fname += ".lyx"; } else @@ -233,7 +233,7 @@ int AutoSaveBuffer::generateChild() // anyway. bool failed = false; - FileName const tmp_ret(tempName(string(), "lyxauto")); + FileName const tmp_ret(tempName(FileName(), "lyxauto")); if (!tmp_ret.empty()) { bv_.buffer()->writeFile(tmp_ret); // assume successful write of tmp_ret @@ -359,7 +359,7 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap if (result.first == FileDialog::Later) return string(); - fname = FileName(makeAbsPath(to_utf8(result.second))); + fname = makeAbsPath(to_utf8(result.second)); if (fname.empty()) return string(); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index bb47af70de..476d7793f7 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1017,7 +1017,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) // case 1: print to a file command += lyxrc.print_to_file + quoteName(makeAbsPath(target_name, - path)) + path).toFilesystemEncoding()) + ' ' + quoteName(dviname); res = one.startscript(Systemcall::DontWait, @@ -1342,17 +1342,17 @@ void LyXFunc::dispatch(FuncRequest const & cmd) case LFUN_BUFFER_CHILD_OPEN: { BOOST_ASSERT(lyx_view_); - string const filename = + FileName const filename = makeAbsPath(argument, lyx_view_->buffer()->filePath()); // FIXME Should use bformat setMessage(_("Opening child document ") + - makeDisplayPath(filename) + "..."); + makeDisplayPath(filename.absFilename()) + "..."); view()->saveBookmark(false); string const parentfilename = lyx_view_->buffer()->fileName(); - if (theBufferList().exists(filename)) - lyx_view_->setBuffer(theBufferList().getBuffer(filename)); + if (theBufferList().exists(filename.absFilename())) + lyx_view_->setBuffer(theBufferList().getBuffer(filename.absFilename())); else - lyx_view_->loadLyXFile(FileName(filename)); + lyx_view_->loadLyXFile(filename); // Set the parent name of the child document. // This makes insertion of citations and references in the child work, // when the target is in the parent or another child document. @@ -1412,8 +1412,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd) } case LFUN_PREFERENCES_SAVE: { - lyxrc.write(FileName(makeAbsPath("preferences", - package().user_support())), + lyxrc.write(makeAbsPath("preferences", + package().user_support()), false); break; } @@ -1796,7 +1796,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate) if (view()->buffer()) { string const trypath = lyx_view_->buffer()->filePath(); // If directory is writeable, use this as default. - if (isDirWriteable(trypath)) + if (isDirWriteable(FileName(trypath))) initpath = trypath; } @@ -1847,7 +1847,7 @@ void LyXFunc::open(string const & fname) if (view()->buffer()) { string const trypath = lyx_view_->buffer()->filePath(); // If directory is writeable, use this as default. - if (isDirWriteable(trypath)) + if (isDirWriteable(FileName(trypath))) initpath = trypath; } @@ -1920,7 +1920,7 @@ void LyXFunc::doImport(string const & argument) if (view()->buffer()) { string const trypath = lyx_view_->buffer()->filePath(); // If directory is writeable, use this as default. - if (isDirWriteable(trypath)) + if (isDirWriteable(FileName(trypath))) initpath = trypath; } diff --git a/src/lyxvc.C b/src/lyxvc.C index 9d7b96279e..835408913f 100644 --- a/src/lyxvc.C +++ b/src/lyxvc.C @@ -229,7 +229,7 @@ string const LyXVC::getLogFile() const if (!vcs) return string(); - FileName const tmpf(tempName(string(), "lyxvclog")); + FileName const tmpf(tempName(FileName(), "lyxvclog")); if (tmpf.empty()) { lyxerr[Debug::LYXVC] << "Could not generate logfile " << tmpf << endl; diff --git a/src/support/filename.C b/src/support/filename.C index 560aaf576e..280525be7a 100644 --- a/src/support/filename.C +++ b/src/support/filename.C @@ -117,10 +117,15 @@ DocFileName::DocFileName(string const & abs_filename, bool save_abs) {} +DocFileName::DocFileName(FileName const & abs_filename, bool save_abs) + : FileName(abs_filename), save_abs_path_(save_abs), zipped_valid_(false) +{} + + void DocFileName::set(string const & name, string const & buffer_path) { save_abs_path_ = absolutePath(name); - name_ = save_abs_path_ ? name : makeAbsPath(name, buffer_path); + name_ = save_abs_path_ ? name : makeAbsPath(name, buffer_path).absFilename(); zipped_valid_ = false; } diff --git a/src/support/filename.h b/src/support/filename.h index 71b422b375..2de36719e8 100644 --- a/src/support/filename.h +++ b/src/support/filename.h @@ -32,14 +32,19 @@ public: * explicit because we don't want implicit conversion of relative * paths in function arguments (e.g. of unlink). * \param abs_filename the file in question. Must have an absolute path. + * Encoding is always UTF-8. */ explicit FileName(std::string const & abs_filename); virtual ~FileName(); + /** Set a new filename. + * \param filename the file in question. Must have an absolute path. + * Encoding is always UTF-8. + */ virtual void set(std::string const & filename); virtual void erase(); /// Is this filename empty? bool empty() const { return name_.empty(); } - /// get the absolute file name + /// get the absolute file name in UTF-8 encoding std::string const absFilename() const { return name_; } /** * Get the file name in the encoding used by the file system. @@ -81,6 +86,7 @@ public: * \param save_abs_path how is the file to be output to file? */ DocFileName(std::string const & abs_filename, bool save_abs_path = true); + DocFileName(FileName const & abs_filename, bool save_abs_path = true); /** \param filename the file in question. May have either a relative * or an absolute path. diff --git a/src/support/filetools.C b/src/support/filetools.C index 105a45d560..264291d16e 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -165,16 +165,16 @@ bool isFileReadable(FileName const & filename) //returns true: dir writeable // false: not writeable -bool isDirWriteable(string const & path) +bool isDirWriteable(FileName const & path) { lyxerr[Debug::FILES] << "isDirWriteable: " << path << endl; - string const tmpfl = tempName(path, "lyxwritetest"); + FileName const tmpfl(tempName(path, "lyxwritetest")); if (tmpfl.empty()) return false; - unlink(FileName(tmpfl)); + unlink(tmpfl); return true; } @@ -242,7 +242,7 @@ vector const dirList(FileName const & dir, string const & ext) string const & fil = dit->leaf(); if (suffixIs(fil, extension)) dirlist.push_back(FileName::fromFilesystemEncoding( - makeAbsPath(fil, encoded_dir))); + encoded_dir + '/' + fil)); } return dirlist; } @@ -376,20 +376,20 @@ FileName const createTmpDir(FileName const & tempdir, string const & mask) << "createTmpDir: tempdir=`" << tempdir << "'\n" << "createTmpDir: mask=`" << mask << '\'' << endl; - string const tmpfl = tempName(tempdir.absFilename(), mask); + FileName const tmpfl(tempName(tempdir, mask)); // lyx::tempName actually creates a file to make sure that it // stays unique. So we have to delete it before we can create // a dir with the same name. Note also that we are not thread // safe because of the gap between unlink and mkdir. (Lgb) - unlink(FileName(tmpfl)); + unlink(tmpfl); - if (tmpfl.empty() || mkdir(FileName(tmpfl), 0700)) { + if (tmpfl.empty() || mkdir(tmpfl, 0700)) { lyxerr << "LyX could not create the temporary directory '" << tmpfl << "'" << endl; return FileName(); } - return FileName(tmpfl); + return tmpfl; } } // namespace anon @@ -429,7 +429,7 @@ FileName const createLyXTmpDir(FileName const & deflt) { if (!deflt.empty() && deflt.absFilename() != "/tmp") { if (mkdir(deflt, 0777)) { - if (isDirWriteable(deflt.absFilename())) { + if (isDirWriteable(deflt)) { // deflt could not be created because it // did exist already, so let's create our own // dir inside deflt. @@ -470,11 +470,11 @@ string const onlyPath(string const & filename) // Convert relative path into absolute path based on a basepath. // If relpath is absolute, just use that. // If basepath is empty, use CWD as base. -string const makeAbsPath(string const & relPath, string const & basePath) +FileName const makeAbsPath(string const & relPath, string const & basePath) { // checks for already absolute path if (os::is_absolute_path(relPath)) - return relPath; + return FileName(relPath); // Copies given paths string tempRel = os::internal_path(relPath); @@ -486,7 +486,7 @@ string const makeAbsPath(string const & relPath, string const & basePath) if (os::is_absolute_path(basePath)) tempBase = basePath; else - tempBase = addPath(getcwd(), basePath); + tempBase = addPath(getcwd().absFilename(), basePath); // Handle /./ at the end of the path while (suffixIs(tempBase, "/./")) @@ -524,7 +524,7 @@ string const makeAbsPath(string const & relPath, string const & basePath) } // returns absolute path - return os::internal_path(tempBase); + return FileName(os::internal_path(tempBase)); } @@ -584,13 +584,13 @@ string const expandPath(string const & path) rTemp = split(rTemp, temp, '/'); if (temp == ".") - return getcwd() + '/' + rTemp; + return getcwd().absFilename() + '/' + rTemp; if (temp == "~") return package().home_dir() + '/' + rTemp; if (temp == "..") - return makeAbsPath(copy); + return makeAbsPath(copy).absFilename(); // Don't know how to handle this return copy; @@ -1035,7 +1035,7 @@ bool readLink(string const & file, string & link, bool resolve) return false; linkbuffer[nRead] = '\0'; // terminator if (resolve) - link = makeAbsPath(linkbuffer, onlyPath(file)); + link = makeAbsPath(linkbuffer, onlyPath(file)).absFilename(); else link = linkbuffer; return true; @@ -1135,7 +1135,7 @@ FileName const findtexfile(string const & fil, string const & /*format*/) cmd_ret const c = runCommand(kpsecmd); lyxerr[Debug::LATEX] << "kpse status = " << c.first << '\n' - << "kpse result = `" << rtrim(c.second, "\n") + << "kpse result = `" << rtrim(c.second, "\n\r") << '\'' << endl; if (c.first != -1) return FileName(os::internal_path(rtrim(c.second, "\n\r"))); diff --git a/src/support/filetools.h b/src/support/filetools.h index 86abc47b4a..7de0b67a56 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -81,7 +81,7 @@ std::vector const dirList(FileName const & dir, true: dir writeable false: not writeable */ -bool isDirWriteable(std::string const & path); +bool isDirWriteable(FileName const & path); /** Is a file readable ? Returns true if the file `path' is readable. @@ -236,7 +236,7 @@ std::string const expandPath(std::string const & path); If relpath is absolute, just use that. If basepath doesn't exist use CWD. */ -std::string const makeAbsPath(std::string const & RelPath = std::string(), +FileName const makeAbsPath(std::string const & RelPath = std::string(), std::string const & BasePath = std::string()); /** Creates a nice compact path for displaying. The parameter diff --git a/src/support/getcwd.C b/src/support/getcwd.C index c1aaa6eac7..e7aea7277f 100644 --- a/src/support/getcwd.C +++ b/src/support/getcwd.C @@ -17,8 +17,6 @@ #include - -namespace lyx { #ifdef HAVE_UNISTD_H # include #endif @@ -28,11 +26,13 @@ namespace lyx { #endif using boost::scoped_array; -using support::os::internal_path; using std::string; +namespace lyx { +namespace support { + namespace { inline @@ -50,7 +50,7 @@ char * l_getcwd(char * buffer, size_t size) // Returns current working directory -string const lyx::support::getcwd() +FileName const getcwd() { int n = 256; // Assume path is less than 256 chars char * err; @@ -66,8 +66,8 @@ string const lyx::support::getcwd() string result; if (err) result = tbuf.get(); - return internal_path(result); + return FileName::fromFilesystemEncoding(os::internal_path(result)); } - +} // namespace support } // namespace lyx diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index ed3098af21..aacb7a6342 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -15,16 +15,16 @@ #ifndef LYX_LIB_H #define LYX_LIB_H +#include "support/filename.h" + #include namespace lyx { namespace support { -class FileName; - /// get the current working directory -std::string const getcwd(); +FileName const getcwd(); /// change to a directory, 0 is returned on success. int chdir(FileName const & name); /// Change file permissions @@ -47,8 +47,9 @@ void abort(); int mkdir(FileName const & pathname, unsigned long int mode); /// unlink the given file int unlink(FileName const & file); -/// (securely) create a temporary file in the given dir with the given prefix -std::string const tempName(std::string const & dir = std::string(), +/// (securely) create a temporary file in the given dir with the given mask +/// \p mask must be in filesystem encoding +FileName const tempName(FileName const & dir = FileName(), std::string const & mask = std::string()); diff --git a/src/support/package.C.in b/src/support/package.C.in index e41a1d9928..d34a3d4b9e 100644 --- a/src/support/package.C.in +++ b/src/support/package.C.in @@ -385,7 +385,7 @@ string const abs_path_from_command_line(string const & command_line) return string(); string const path = os::internal_path(command_line); - return os::is_absolute_path(path) ? path : makeAbsPath(path); + return os::is_absolute_path(path) ? path : makeAbsPath(path).absFilename(); } @@ -407,7 +407,7 @@ string const get_binary_path(string const & exe) // Two possibilities present themselves. // 1. The binary is relative to the CWD. - string const abs_exe_path = makeAbsPath(exe_path); + string const abs_exe_path = makeAbsPath(exe_path).absFilename(); if (fs::exists(FileName(abs_exe_path).toFilesystemEncoding())) return abs_exe_path; @@ -422,7 +422,7 @@ string const get_binary_path(string const & exe) std::vector::const_iterator const end = path.end(); for (; it != end; ++it) { // This will do nothing if *it is already absolute. - string const exe_dir = makeAbsPath(*it); + string const exe_dir = makeAbsPath(*it).absFilename(); string const exe_path = addName(exe_dir, exe_name); if (fs::exists(FileName(exe_path).toFilesystemEncoding())) @@ -663,7 +663,7 @@ bool check_command_line_dir(string const & dir, string const extract_env_var_dir(string const & env_var) { string const dir = os::internal_path(getEnv(env_var)); - return dir.empty() ? dir : makeAbsPath(dir); + return dir.empty() ? dir : makeAbsPath(dir).absFilename(); } diff --git a/src/support/path.C b/src/support/path.C index fd8f358f91..4989dd6a19 100644 --- a/src/support/path.C +++ b/src/support/path.C @@ -53,7 +53,7 @@ int Path::pop() return 0; } - if (chdir(FileName(pushedDir_))) { + if (chdir(pushedDir_)) { // should throw an exception // throw DirChangeError(); } diff --git a/src/support/path.h b/src/support/path.h index d1c4dfe18f..13296353aa 100644 --- a/src/support/path.h +++ b/src/support/path.h @@ -12,6 +12,8 @@ #ifndef PATH_H #define PATH_H +#include "support/filename.h" + #include #include @@ -46,7 +48,7 @@ private: /// whether we are in the new cwd or not bool popped_; /// the previous cwd - std::string pushedDir_; + FileName pushedDir_; }; // To avoid the wrong usage: diff --git a/src/support/tempname.C b/src/support/tempname.C index 3f3c6e222c..2e0783d2e2 100644 --- a/src/support/tempname.C +++ b/src/support/tempname.C @@ -45,6 +45,7 @@ using std::string; using std::endl; namespace lyx { +namespace support { namespace { @@ -77,9 +78,10 @@ int make_tempfile(char * templ) } // namespace anon -string const lyx::support::tempName(string const & dir, string const & mask) +FileName const tempName(FileName const & dir, string const & mask) { - string const tmpdir(dir.empty() ? package().temp_dir() : dir); + // FIXME UNICODE encoding of package().temp_dir() is probably wrong + string const tmpdir(dir.empty() ? package().temp_dir() : dir.toFilesystemEncoding()); string tmpfl(addName(tmpdir, mask)); #if defined (HAVE_GETPID) tmpfl += convert(getpid()); @@ -107,14 +109,14 @@ string const lyx::support::tempName(string const & dir, string const & mask) #endif lyxerr[Debug::FILES] << "Temporary file `" << t << "' created." << endl; - return t; + return FileName(t); } else { lyxerr[Debug::FILES] << "LyX Error: Unable to create temporary file." << endl; - return string(); + return FileName(); } } - +} // namespace support } // namespace lyx diff --git a/src/tex2lyx/tex2lyx.C b/src/tex2lyx/tex2lyx.C index 8f618672bf..ac24bc5aa5 100644 --- a/src/tex2lyx/tex2lyx.C +++ b/src/tex2lyx/tex2lyx.C @@ -381,8 +381,8 @@ void easyParse(int & argc, char * argv[]) if (it == cmdmap.end()) continue; - string arg((i + 1 < argc) ? argv[i + 1] : ""); - string arg2((i + 2 < argc) ? argv[i + 2] : ""); + string arg(to_utf8(from_local8bit((i + 1 < argc) ? argv[i + 1] : ""))); + string arg2(to_utf8(from_local8bit((i + 2 < argc) ? argv[i + 2] : ""))); int const remove = 1 + it->second(arg, arg2); @@ -518,17 +518,18 @@ int main(int argc, char * argv[]) } lyx::support::os::init(argc, argv); - lyx::support::init_package(argv[0], cl_system_support, cl_user_support, - lyx::support::top_build_dir_is_two_levels_up); + support::init_package(to_utf8(from_local8bit(argv[0])), + cl_system_support, cl_user_support, + support::top_build_dir_is_two_levels_up); // Now every known option is parsed. Look for input and output // file name (the latter is optional). - string const infilename = makeAbsPath(argv[1]); + string const infilename = makeAbsPath(to_utf8(from_local8bit(argv[1]))).absFilename(); string outfilename; if (argc > 2) { - outfilename = argv[2]; + outfilename = to_utf8(from_local8bit(argv[2])); if (outfilename != "-") - outfilename = makeAbsPath(argv[2]); + outfilename = makeAbsPath(to_utf8(from_local8bit(argv[2]))).absFilename(); } else outfilename = changeExtension(infilename, ".lyx"); @@ -539,7 +540,7 @@ int main(int argc, char * argv[]) } read_syntaxfile(system_syntaxfile); if (!syntaxfile.empty()) - read_syntaxfile(FileName(makeAbsPath(syntaxfile))); + read_syntaxfile(makeAbsPath(syntaxfile)); masterFilePath = onlyPath(infilename); parentFilePath = masterFilePath; diff --git a/src/tex2lyx/text.C b/src/tex2lyx/text.C index 108c627c60..8b169b2167 100644 --- a/src/tex2lyx/text.C +++ b/src/tex2lyx/text.C @@ -32,6 +32,7 @@ namespace lyx { +using support::addExtension; using support::changeExtension; using support::FileName; using support::makeAbsPath; @@ -354,11 +355,11 @@ void translate_box_len(string const & length, string & value, string & unit, str string find_file(string const & name, string const & path, char const * const * extensions) { + // FIXME UNICODE encoding of name and path may be wrong (makeAbsPath + // expects utf8) for (char const * const * what = extensions; *what; ++what) { - // We don't use ChangeExtension() because it does the wrong - // thing if name contains a dot. - string const trial = name + '.' + (*what); - if (fs::exists(FileName(makeAbsPath(trial, path)).toFilesystemEncoding())) + string const trial = addExtension(name, *what); + if (fs::exists(makeAbsPath(trial, path).toFilesystemEncoding())) return trial; } return string(); @@ -1021,7 +1022,9 @@ void fix_relative_filename(string & name) { if (lyx::support::absolutePath(name)) return; - name = makeRelPath(makeAbsPath(name, getMasterFilePath()), + // FIXME UNICODE encoding of name may be wrong (makeAbsPath expects + // utf8) + name = makeRelPath(makeAbsPath(name, getMasterFilePath()).absFilename(), getParentFilePath()); } @@ -1480,7 +1483,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, string const path = getMasterFilePath(); // We want to preserve relative / absolute filenames, // therefore path is only used for testing - if (!fs::exists(FileName(makeAbsPath(name, path)).toFilesystemEncoding())) { + // FIXME UNICODE encoding of name and path may be + // wrong (makeAbsPath expects utf8) + if (!fs::exists(makeAbsPath(name, path).toFilesystemEncoding())) { // The file extension is probably missing. // Now try to find it out. string const dvips_name = @@ -1510,7 +1515,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, name = pdftex_name; } - if (fs::exists(FileName(makeAbsPath(name, path)).toFilesystemEncoding())) + // FIXME UNICODE encoding of name and path may be + // wrong (makeAbsPath expects utf8) + if (fs::exists(makeAbsPath(name, path).toFilesystemEncoding())) fix_relative_filename(name); else cerr << "Warning: Could not find graphics file '" @@ -2132,8 +2139,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, string const path = getMasterFilePath(); // We want to preserve relative / absolute filenames, // therefore path is only used for testing + // FIXME UNICODE encoding of filename and path may be + // wrong (makeAbsPath expects utf8) if (t.cs() == "include" && - !fs::exists(FileName(makeAbsPath(filename, path)).toFilesystemEncoding())) { + !fs::exists(makeAbsPath(filename, path).toFilesystemEncoding())) { // The file extension is probably missing. // Now try to find it out. string const tex_name = @@ -2142,9 +2151,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, if (!tex_name.empty()) filename = tex_name; } - if (fs::exists(FileName(makeAbsPath(filename, path)).toFilesystemEncoding())) { + // FIXME UNICODE encoding of filename and path may be + // wrong (makeAbsPath expects utf8) + if (fs::exists(makeAbsPath(filename, path).toFilesystemEncoding())) { string const abstexname = - makeAbsPath(filename, path); + makeAbsPath(filename, path).absFilename(); string const abslyxname = changeExtension(abstexname, ".lyx"); fix_relative_filename(filename);