Next step of true unicode filenames: Use support::FileName instead of

std::string at many places (not all yet).


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16069 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2006-11-26 21:30:39 +00:00
parent 0dae88fca6
commit 8e6e970d7b
105 changed files with 834 additions and 666 deletions

View File

@ -209,7 +209,7 @@ bool BufferView::loadLyXFile(string const & filename, bool tolastfiles)
{
// Get absolute path of file and add ".lyx"
// to the filename if necessary
string s = fileSearch(string(), filename, "lyx");
string s = fileSearch(string(), filename, "lyx").absFilename();
bool const found = !s.empty();
@ -1387,7 +1387,7 @@ void BufferView::menuInsertLyXFile(string const & filenm)
// Get absolute path of file and add ".lyx"
// to the filename if necessary
filename = fileSearch(string(), filename, "lyx");
filename = fileSearch(string(), filename, "lyx").absFilename();
docstring const disp_fn = makeDisplayPath(filename);
// emit message signal.

View File

@ -32,7 +32,6 @@
#include <map>
#include <sstream>
using lyx::support::absolutePath;
using lyx::support::addName;
using std::string;
@ -41,6 +40,8 @@ namespace fs = boost::filesystem;
namespace lyx {
using support::FileName;
namespace {
unsigned long do_crc(string const & s)
@ -51,28 +52,27 @@ unsigned long do_crc(string const & s)
}
static string cache_dir;
static FileName cache_dir;
class CacheItem {
public:
CacheItem() {}
CacheItem(string const & orig_from, string const & to_format,
CacheItem(FileName const & orig_from, string const & to_format,
time_t t, unsigned long c)
: timestamp(t), checksum(c)
{
BOOST_ASSERT(absolutePath(orig_from));
std::ostringstream os;
os << std::setw(10) << std::setfill('0') << do_crc(orig_from)
os << std::setw(10) << std::setfill('0') << do_crc(orig_from.absFilename())
<< '-' << to_format;
cache_name = addName(cache_dir, os.str());
cache_name = FileName(addName(cache_dir.absFilename(), os.str()));
lyxerr[Debug::FILES] << "Add file cache item " << orig_from
<< ' ' << to_format << ' ' << cache_name
<< ' ' << timestamp << ' ' << checksum
<< '.' << std::endl;
}
~CacheItem() {}
string cache_name;
FileName cache_name;
time_t timestamp;
unsigned long checksum;
};
@ -84,7 +84,7 @@ public:
* nested map to find the cache item quickly by filename and format.
*/
typedef std::map<string, CacheItem> FormatCacheType;
typedef std::map<string, FormatCacheType> CacheType;
typedef std::map<FileName, FormatCacheType> CacheType;
class ConverterCache::Impl {
@ -94,7 +94,7 @@ public:
///
void writeIndex();
///
CacheItem * find(string const & from, string const & format);
CacheItem * find(FileName const & from, string const & format);
CacheType cache;
};
@ -102,8 +102,8 @@ public:
void ConverterCache::Impl::readIndex()
{
time_t const now = current_time();
string const index = addName(cache_dir, "index");
std::ifstream is(index.c_str());
FileName const index(addName(cache_dir.absFilename(), "index"));
std::ifstream is(index.toFilesystemEncoding().c_str());
while (is.good()) {
string orig_from;
string to_format;
@ -111,7 +111,8 @@ void ConverterCache::Impl::readIndex()
unsigned long checksum;
if (!(is >> orig_from >> to_format >> timestamp >> checksum))
return;
CacheItem item(orig_from, to_format, timestamp, checksum);
FileName const orig_from_name(orig_from);
CacheItem item(orig_from_name, to_format, timestamp, checksum);
// Don't cache files that do not exist anymore
if (!fs::exists(orig_from)) {
@ -123,7 +124,7 @@ void ConverterCache::Impl::readIndex()
}
// Delete the cached file if it is too old
if (difftime(now, fs::last_write_time(item.cache_name)) >
if (difftime(now, fs::last_write_time(item.cache_name.toFilesystemEncoding())) >
lyxrc.converter_cache_maxage) {
lyxerr[Debug::FILES] << "Not caching file `"
<< orig_from << "' (too old)." << std::endl;
@ -131,7 +132,7 @@ void ConverterCache::Impl::readIndex()
continue;
}
cache[orig_from][to_format] = item;
cache[orig_from_name][to_format] = item;
}
is.close();
}
@ -139,12 +140,12 @@ void ConverterCache::Impl::readIndex()
void ConverterCache::Impl::writeIndex()
{
string const index = addName(cache_dir, "index");
std::ofstream os(index.c_str());
FileName const index(addName(cache_dir.absFilename(), "index"));
std::ofstream os(index.toFilesystemEncoding().c_str());
os.close();
if (!lyx::support::chmod(index.c_str(), 0600))
if (!lyx::support::chmod(index, 0600))
return;
os.open(index.c_str());
os.open(index.toFilesystemEncoding().c_str());
CacheType::iterator it1 = cache.begin();
CacheType::iterator const end1 = cache.end();
for (; it1 != end1; ++it1) {
@ -159,7 +160,7 @@ void ConverterCache::Impl::writeIndex()
}
CacheItem * ConverterCache::Impl::find(string const & from,
CacheItem * ConverterCache::Impl::find(FileName const & from,
string const & format)
{
if (!lyxrc.use_converter_cache)
@ -188,8 +189,8 @@ void ConverterCache::init()
return;
// We do this here and not in the constructor because package() gets
// initialized after all static variables.
cache_dir = addName(support::package().user_support(), "cache");
if (!fs::exists(cache_dir))
cache_dir = FileName(addName(support::package().user_support(), "cache"));
if (!fs::exists(cache_dir.toFilesystemEncoding()))
if (support::mkdir(cache_dir, 0700) != 0) {
lyxerr << "Could not create cache directory `"
<< cache_dir << "'." << std::endl;
@ -212,21 +213,19 @@ ConverterCache::~ConverterCache()
}
void ConverterCache::add(string const & orig_from, string const & to_format,
string const & converted_file) const
void ConverterCache::add(FileName const & orig_from, string const & to_format,
FileName const & converted_file) const
{
if (!lyxrc.use_converter_cache)
return;
lyxerr[Debug::FILES] << BOOST_CURRENT_FUNCTION << ' ' << orig_from
<< ' ' << to_format << ' ' << converted_file
<< std::endl;
BOOST_ASSERT(absolutePath(orig_from));
BOOST_ASSERT(absolutePath(converted_file));
// Is the file in the cache already?
CacheItem * item = pimpl_->find(orig_from, to_format);
time_t const timestamp = fs::last_write_time(orig_from);
time_t const timestamp = fs::last_write_time(orig_from.toFilesystemEncoding());
Mover const & mover = movers(to_format);
if (item) {
lyxerr[Debug::FILES] << "ConverterCache::add(" << orig_from << "):\n"
@ -267,14 +266,13 @@ void ConverterCache::add(string const & orig_from, string const & to_format,
}
void ConverterCache::remove(string const & orig_from,
void ConverterCache::remove(FileName const & orig_from,
string const & to_format) const
{
if (!lyxrc.use_converter_cache)
return;
lyxerr[Debug::FILES] << BOOST_CURRENT_FUNCTION << ' ' << orig_from
<< ' ' << to_format << std::endl;
BOOST_ASSERT(absolutePath(orig_from));
CacheType::iterator const it1 = pimpl_->cache.find(orig_from);
if (it1 == pimpl_->cache.end())
@ -289,21 +287,20 @@ void ConverterCache::remove(string const & orig_from,
}
bool ConverterCache::inCache(string const & orig_from,
bool ConverterCache::inCache(FileName const & orig_from,
string const & to_format) const
{
if (!lyxrc.use_converter_cache)
return false;
lyxerr[Debug::FILES] << BOOST_CURRENT_FUNCTION << ' ' << orig_from
<< ' ' << to_format << std::endl;
BOOST_ASSERT(absolutePath(orig_from));
CacheItem * const item = pimpl_->find(orig_from, to_format);
if (!item) {
lyxerr[Debug::FILES] << "not in cache." << std::endl;
return false;
}
time_t const timestamp = fs::last_write_time(orig_from);
time_t const timestamp = fs::last_write_time(orig_from.toFilesystemEncoding());
if (item->timestamp == timestamp) {
lyxerr[Debug::FILES] << "identical timestamp." << std::endl;
return true;
@ -318,12 +315,11 @@ bool ConverterCache::inCache(string const & orig_from,
}
string const ConverterCache::cacheName(string const & orig_from,
FileName const & ConverterCache::cacheName(FileName const & orig_from,
string const & to_format) const
{
lyxerr[Debug::FILES] << BOOST_CURRENT_FUNCTION << ' ' << orig_from
<< ' ' << to_format << std::endl;
BOOST_ASSERT(absolutePath(orig_from));
CacheItem * const item = pimpl_->find(orig_from, to_format);
BOOST_ASSERT(item);
@ -331,15 +327,13 @@ string const ConverterCache::cacheName(string const & orig_from,
}
bool ConverterCache::copy(string const & orig_from, string const & to_format,
string const & dest) const
bool ConverterCache::copy(FileName const & orig_from, string const & to_format,
FileName const & dest) const
{
if (!lyxrc.use_converter_cache)
return false;
lyxerr[Debug::FILES] << BOOST_CURRENT_FUNCTION << ' ' << orig_from
<< ' ' << to_format << ' ' << dest << std::endl;
BOOST_ASSERT(absolutePath(orig_from));
BOOST_ASSERT(absolutePath(dest));
CacheItem * const item = pimpl_->find(orig_from, to_format);
BOOST_ASSERT(item);

View File

@ -29,6 +29,8 @@
namespace lyx {
namespace support { class FileName; }
/**
* Cache for converted files. The cache works as follows:
*
@ -60,27 +62,27 @@ public:
* Add \c converted_file (\c orig_from converted to \c to_format) to
* the cache if it is not already in or not up to date.
*/
void add(std::string const & orig_from, std::string const & to_format,
std::string const & converted_file) const;
void add(support::FileName const & orig_from, std::string const & to_format,
support::FileName const & converted_file) const;
/// Remove a file from the cache.
void remove(std::string const & orig_from,
void remove(support::FileName const & orig_from,
std::string const & to_format) const;
/**
* Returns \c true if \c orig_from converted to \c to_format is in
* the cache and up to date.
*/
bool inCache(std::string const & orig_from,
bool inCache(support::FileName const & orig_from,
std::string const & to_format) const;
/// Get the name of the cached file
std::string const cacheName(std::string const & orig_from,
std::string const & to_format) const;
support::FileName const & cacheName(support::FileName const & orig_from,
std::string const & to_format) const;
/// Copy the file from the cache to \p dest
bool copy(std::string const & orig_from, std::string const & to_format,
std::string const & dest) const;
bool copy(support::FileName const & orig_from, std::string const & to_format,
support::FileName const & dest) const;
private:
/** Make the c-tor, d-tor private so we can control how many objects

View File

@ -32,6 +32,7 @@ namespace lyx {
using std::time;
#endif
using support::FileName;
using support::ltrim;
using support::makeAbsPath;
using support::onlyFilename;
@ -52,10 +53,8 @@ bool DepTable::dep_info::changed() const
}
void DepTable::insert(string const & fi, bool upd)
void DepTable::insert(FileName const & f, bool upd)
{
// not quite sure if this is the correct place for MakeAbsPath
string const f = makeAbsPath(fi);
if (deplist.find(f) == deplist.end()) {
dep_info di;
di.crc_prev = 0;
@ -64,7 +63,7 @@ void DepTable::insert(string const & fi, bool upd)
di.crc_cur = sum(f);
lyxerr[Debug::DEPEND] << "done." << endl;
struct stat f_info;
stat(fi.c_str(), &f_info);
stat(f.toFilesystemEncoding().c_str(), &f_info);
di.mtime_cur = f_info.st_mtime;
} else {
di.crc_cur = 0;
@ -87,7 +86,7 @@ void DepTable::update()
dep_info &di = itr->second;
struct stat f_info;
if (stat(itr->first.c_str(), &f_info) == 0) {
if (stat(itr->first.toFilesystemEncoding().c_str(), &f_info) == 0) {
if (di.mtime_cur == f_info.st_mtime) {
di.crc_prev = di.crc_cur;
lyxerr[Debug::DEPEND] << itr->first << " same mtime" << endl;
@ -132,10 +131,8 @@ bool DepTable::sumchange() const
}
bool DepTable::haschanged(string const & f) const
bool DepTable::haschanged(FileName const & fil) const
{
// not quite sure if this is the correct place for MakeAbsPath
string const fil = makeAbsPath(f);
DepList::const_iterator cit = deplist.find(fil);
if (cit != deplist.end()) {
if (cit->second.changed())
@ -150,7 +147,7 @@ bool DepTable::extchanged(string const & ext) const
DepList::const_iterator cit = deplist.begin();
DepList::const_iterator end = deplist.end();
for (; cit != end; ++cit) {
if (suffixIs(cit->first, ext)) {
if (suffixIs(cit->first.absFilename(), ext)) {
if (cit->second.changed())
return true;
}
@ -164,7 +161,7 @@ bool DepTable::ext_exist(string const & ext) const
DepList::const_iterator cit = deplist.begin();
DepList::const_iterator end = deplist.end();
for (; cit != end; ++cit) {
if (suffixIs(cit->first, ext)) {
if (suffixIs(cit->first.absFilename(), ext)) {
return true;
}
}
@ -172,7 +169,7 @@ bool DepTable::ext_exist(string const & ext) const
}
bool DepTable::exist(string const & fil) const
bool DepTable::exist(FileName const & fil) const
{
return deplist.find(fil) != deplist.end();
}
@ -183,7 +180,7 @@ void DepTable::remove_files_with_extension(string const & suf)
DepList::iterator cit = deplist.begin();
DepList::iterator end = deplist.end();
while (cit != end) {
if (suffixIs(cit->first, suf)) {
if (suffixIs(cit->first.absFilename(), suf)) {
// Can't erase the current iterator, but we
// can increment and then erase.
// Deplist is a map so only the erased
@ -197,12 +194,12 @@ void DepTable::remove_files_with_extension(string const & suf)
}
void DepTable::remove_file(string const & filename)
void DepTable::remove_file(FileName const & filename)
{
DepList::iterator cit = deplist.begin();
DepList::iterator end = deplist.end();
while (cit != end) {
if (onlyFilename(cit->first) == filename) {
if (cit->first == filename) {
// Can't erase the current iterator, but we
// can increment and then erase.
// deplist is a map so only the erased
@ -216,9 +213,9 @@ void DepTable::remove_file(string const & filename)
}
void DepTable::write(string const & f) const
void DepTable::write(FileName const & f) const
{
ofstream ofs(f.c_str());
ofstream ofs(f.toFilesystemEncoding().c_str());
DepList::const_iterator cit = deplist.begin();
DepList::const_iterator end = deplist.end();
for (; cit != end; ++cit) {
@ -238,9 +235,9 @@ void DepTable::write(string const & f) const
}
bool DepTable::read(string const & f)
bool DepTable::read(FileName const & f)
{
ifstream ifs(f.c_str());
ifstream ifs(f.toFilesystemEncoding().c_str());
string nome;
dep_info di;
// This doesn't change through the loop.
@ -254,7 +251,7 @@ bool DepTable::read(string const & f)
<< di.mtime_cur << ' '
<< nome << endl;
}
deplist[nome] = di;
deplist[FileName(nome)] = di;
}
return deplist.size();
}

View File

@ -13,6 +13,8 @@
#ifndef DEP_TABLE_H
#define DEP_TABLE_H
#include "support/filename.h"
#include <map>
#include <string>
@ -25,28 +27,28 @@ public:
/** This one is a little bit harder since we need the absolute
filename. Should we insert files with .sty .cls etc as
extension? */
void insert(std::string const & f, bool upd = false);
void insert(support::FileName const & f, bool upd = false);
///
void update();
///
void write(std::string const & f) const;
void write(support::FileName const & f) const;
/// returns true if dep file was read successfully
bool read(std::string const & f);
bool read(support::FileName const & f);
/// returns true if any of the files has changed
bool sumchange() const;
/// return true if fil has changed.
bool haschanged(std::string const & fil) const;
bool haschanged(support::FileName const & fil) const;
/// return true if a file with extension ext has changed.
bool extchanged(std::string const & ext) const;
///
bool exist(std::string const & fil) const;
bool exist(support::FileName const & fil) const;
/// returns true if any files with ext exist
bool ext_exist(std::string const & ext) const;
///
void remove_files_with_extension(std::string const &);
///
void remove_file(std::string const &);
void remove_file(support::FileName const &);
private:
///
class dep_info {
@ -61,7 +63,7 @@ private:
bool changed() const;
};
///
typedef std::map<std::string, dep_info> DepList;
typedef std::map<support::FileName, dep_info> DepList;
///
DepList deplist;
};

View File

@ -40,8 +40,10 @@ 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;
@ -127,11 +129,11 @@ LaTeX::LaTeX(string const & latex, OutputParams const & rp,
: cmd(latex), file(f), path(p), runparams(rp)
{
num_errors = 0;
depfile = file + ".dep";
if (prefixIs(cmd, "pdf")) { // Do we use pdflatex ?
depfile += "-pdf";
depfile = FileName(makeAbsPath(file + ".dep-pdf"));
output_file = changeExtension(file,".pdf");
} else {
depfile = FileName(makeAbsPath(file + ".dep"));
output_file = changeExtension(file,".dvi");
}
}
@ -148,22 +150,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(makeAbsPath(changeExtension(file, ".bbl")));
unlink(bbl);
// makeindex file
string const ind = changeExtension(ofname, ".ind");
FileName const ind(makeAbsPath(changeExtension(file, ".ind")));
unlink(ind);
// nomencl file
string const nls = changeExtension(ofname, ".nls");
FileName const nls(makeAbsPath(changeExtension(file, ".nls")));
unlink(nls);
// Also remove the aux file
string const aux = changeExtension(ofname, ".aux");
FileName const aux(makeAbsPath(changeExtension(file, ".aux")));
unlink(aux);
}
@ -203,7 +203,7 @@ 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"));
@ -281,13 +281,13 @@ int LaTeX::run(TeXErrors & terr)
&& fs::is_empty(changeExtension(file, ".idx"));
// run makeindex
if (head.haschanged(onlyFilename(changeExtension(file, ".idx")))) {
if (head.haschanged(FileName(makeAbsPath(onlyFilename(changeExtension(file, ".idx")))))) {
// no checks for now
lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
message(_("Running MakeIndex."));
rerun |= runMakeIndex(onlyFilename(changeExtension(file, ".idx")), runparams);
}
if (head.haschanged(onlyFilename(changeExtension(file, ".nlo")))) {
if (head.haschanged(FileName(makeAbsPath(onlyFilename(changeExtension(file, ".nlo")))))) {
lyxerr[Debug::LATEX] << "Running MakeIndex for nomencl." << endl;
message(_("Running MakeIndex for nomencl."));
string const nomenclstr = " -s nomencl.ist -o " + changeExtension(file, ".nls");
@ -355,7 +355,7 @@ int LaTeX::run(TeXErrors & terr)
// 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(makeAbsPath(onlyFilename(changeExtension(file, ".idx")))))) {
// no checks for now
lyxerr[Debug::LATEX] << "Running MakeIndex." << endl;
message(_("Running MakeIndex."));
@ -363,7 +363,7 @@ int LaTeX::run(TeXErrors & terr)
}
// I am not pretty sure if need this twice.
if (head.haschanged(onlyFilename(changeExtension(file, ".nlo")))) {
if (head.haschanged(FileName(makeAbsPath(onlyFilename(changeExtension(file, ".nlo")))))) {
lyxerr[Debug::LATEX] << "Running MakeIndex for nomencl." << endl;
message(_("Running MakeIndex for nomencl."));
string nomenclstr = " -s nomencl.ist -o " + changeExtension(file, ".nls");
@ -525,14 +525,14 @@ void LaTeX::updateBibtexDependencies(DepTable & dep,
it2 != it->databases.end(); ++it2) {
string file = findtexfile(*it2, "bib");
if (!file.empty())
dep.insert(file, true);
dep.insert(FileName(makeAbsPath(file)), true);
}
for (set<string>::const_iterator it2 = it->styles.begin();
it2 != it->styles.end(); ++it2) {
string file = findtexfile(*it2, "bst");
if (!file.empty())
dep.insert(file, true);
dep.insert(FileName(makeAbsPath(file)), true);
}
}
}
@ -728,7 +728,7 @@ void handleFoundFile(string const & ff, DepTable & head)
// since this file cannot be a file generated by
// the latex run.
if (fs::exists(foundfile) && !fs::is_directory(foundfile))
head.insert(foundfile, true);
head.insert(FileName(makeAbsPath(foundfile)), true);
return;
}
@ -753,13 +753,13 @@ void handleFoundFile(string const & ff, DepTable & head)
<< "Tmpdir TeX file: "
<< onlyfile
<< endl;
head.insert(onlyfile, true);
head.insert(FileName(makeAbsPath(onlyfile)), true);
} else {
lyxerr[Debug::DEPEND]
<< "In tmpdir file:"
<< onlyfile
<< endl;
head.insert(onlyfile);
head.insert(FileName(makeAbsPath(onlyfile)));
}
} else
lyxerr[Debug::DEPEND]
@ -843,7 +843,7 @@ void LaTeX::deplog(DepTable & head)
}
// Make sure that the main .tex file is in the dependancy file.
head.insert(onlyFilename(file), true);
head.insert(FileName(makeAbsPath(onlyFilename(file))), true);
}

View File

@ -17,6 +17,7 @@
#include "outputparams.h"
#include "support/docstring.h"
#include "support/filename.h"
#include <boost/utility.hpp>
#include <boost/signal.hpp>
@ -155,7 +156,7 @@ private:
int startscript();
/// The dependency file.
std::string depfile;
support::FileName depfile;
///
void deplog(DepTable & head);

View File

@ -30,7 +30,6 @@
#include "support/docstream.h"
#include "support/filetools.h"
#include <sstream>
namespace lyx {
@ -77,7 +76,7 @@ void LaTeXFeatures::require(string const & name)
void LaTeXFeatures::getAvailable()
{
LyXLex lex(0, 0);
string real_file = libFileSearch("", "packages.lst");
support::FileName const real_file = libFileSearch("", "packages.lst");
if (real_file.empty())
return;

View File

@ -238,11 +238,11 @@ string const ToolbarBackend::getIcon(FuncRequest const & f)
if (!f.argument().empty())
xpm_name = subst(name + ' ' + to_utf8(f.argument()), ' ', '_');
fullname = libFileSearch("images", xpm_name, "xpm");
fullname = libFileSearch("images", xpm_name, "xpm").absFilename();
if (fullname.empty()) {
// try without the argument
fullname = libFileSearch("images", name, "xpm");
fullname = libFileSearch("images", name, "xpm").absFilename();
}
}
@ -255,7 +255,7 @@ string const ToolbarBackend::getIcon(FuncRequest const & f)
lyxerr[Debug::GUI] << "Cannot find icon for command \""
<< lyxaction.getActionName(f.action)
<< '(' << to_utf8(f.argument()) << ")\"" << endl;
return libFileSearch("images", "unknown", "xpm");
return libFileSearch("images", "unknown", "xpm").absFilename();
}

View File

@ -101,6 +101,7 @@ using support::changeExtension;
using support::cmd_ret;
using support::createBufferTmpDir;
using support::destroyDir;
using support::FileName;
using support::getFormatFromContents;
using support::isDirWriteable;
using support::libFileSearch;
@ -571,7 +572,8 @@ void Buffer::insertStringAsLines(ParagraphList & pars,
bool Buffer::readFile(string const & filename)
{
// Check if the file is compressed.
string const format = getFormatFromContents(filename);
FileName const name(makeAbsPath(filename));
string const format = getFormatFromContents(name);
if (format == "gzip" || format == "zip" || format == "compress") {
params().compressed = true;
}
@ -579,7 +581,7 @@ bool Buffer::readFile(string const & filename)
// remove dummy empty par
paragraphs().clear();
LyXLex lex(0, 0);
lex.setFile(filename);
lex.setFile(name);
if (!readFile(lex, filename))
return false;
@ -655,7 +657,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
from_utf8(filename)));
return false;
}
string const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
FileName const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
if (lyx2lyx.empty()) {
Alert::error(_("Conversion script not found"),
bformat(_("%1$s is from an earlier"
@ -666,7 +668,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename)
return false;
}
ostringstream command;
command << os::python() << ' ' << quoteName(lyx2lyx)
command << os::python() << ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
<< " -t " << convert<string>(LYX_FORMAT)
<< " -o " << quoteName(tmpfile) << ' '
<< quoteName(filename);
@ -745,7 +747,7 @@ bool Buffer::save() const
} else {
// Saving failed, so backup is not backup
if (lyxrc.make_backup)
rename(s, fileName());
rename(FileName(s), FileName(fileName()));
return false;
}
return true;

View File

@ -53,7 +53,9 @@ namespace lyx {
using namespace std;
using support::bformat;
using support::FileName;
using support::libFileSearch;
using support::makeAbsPath;
using support::makeDisplayPath;
using support::onlyFilename;
using support::onlyPath;
@ -127,7 +129,7 @@ bool readFile(Buffer * const b, string const & s)
return b->readFile(a);
case 1:
// Here we delete the autosave
unlink(a);
unlink(FileName(makeAbsPath(a)));
break;
default:
return false;
@ -185,7 +187,7 @@ Buffer * newFile(string const & filename, string const & templatename,
string tname;
// use defaults.lyx as a default template if it exists.
if (templatename.empty())
tname = libFileSearch("templates", "defaults.lyx");
tname = libFileSearch("templates", "defaults.lyx").absFilename();
else
tname = templatename;

View File

@ -51,8 +51,8 @@ bool CharacterSet::loadFile(string const & fname)
// open definition file
lyxerr[Debug::KBMAP]
<< "Reading character set file " << fname << ".cdef" << endl;
string const filename = libFileSearch("kbd", fname, "cdef");
ifstream ifs(filename.c_str());
support::FileName const filename = libFileSearch("kbd", fname, "cdef");
ifstream ifs(filename.toFilesystemEncoding().c_str());
if (!ifs) {
lyxerr << "Unable to open character set file" << endl;
return true; // no definition, use 7-bit ascii

View File

@ -34,13 +34,13 @@
namespace lyx {
using support::absolutePath;
using support::addName;
using support::bformat;
using support::changeExtension;
using support::compare_ascii_no_case;
using support::contains;
using support::dirList;
using support::FileName;
using support::getExtension;
using support::isFileReadable;
using support::libFileSearch;
@ -287,15 +287,11 @@ OutputParams::FLAVOR Converters::getFlavor(Graph::EdgePath const & path)
bool Converters::convert(Buffer const * buffer,
string const & from_file, string const & to_file,
string const & orig_from,
FileName const & from_file, FileName const & to_file,
FileName const & orig_from,
string const & from_format, string const & to_format,
ErrorList & errorList, int conversionflags)
{
BOOST_ASSERT(absolutePath(from_file));
BOOST_ASSERT(absolutePath(to_file));
BOOST_ASSERT(absolutePath(orig_from));
if (from_format == to_format)
return move(from_format, from_file, to_file, false);
@ -309,16 +305,16 @@ bool Converters::convert(Buffer const * buffer,
// if no special converter defined, then we take the
// default one from ImageMagic.
string const from_ext = from_format.empty() ?
getExtension(from_file) :
getExtension(from_file.absFilename()) :
formats.extension(from_format);
string const to_ext = formats.extension(to_format);
string const command =
support::os::python() + ' ' +
quoteName(libFileSearch("scripts", "convertDefault.py")) +
quoteName(libFileSearch("scripts", "convertDefault.py").toFilesystemEncoding()) +
' ' +
quoteName(from_ext + ':' + from_file) +
quoteName(from_ext + ':' + from_file.toFilesystemEncoding()) +
' ' +
quoteName(to_ext + ':' + to_file);
quoteName(to_ext + ':' + to_file.toFilesystemEncoding());
lyxerr[Debug::FILES]
<< "No converter defined! "
"I use convertDefault.py:\n\t"
@ -347,17 +343,17 @@ bool Converters::convert(Buffer const * buffer,
// This has the added benefit that all other files that may be
// generated by the converter are deleted when LyX closes and do not
// clutter the real working directory.
string path = onlyPath(from_file);
string path = onlyPath(from_file.absFilename());
Path p(path);
// empty the error list before any new conversion takes place.
errorList.clear();
bool run_latex = false;
string from_base = changeExtension(from_file, "");
string to_base = changeExtension(to_file, "");
string infile;
string outfile = from_file;
string from_base = changeExtension(from_file.absFilename(), "");
string to_base = changeExtension(to_file.absFilename(), "");
FileName infile;
FileName outfile = from_file;
for (Graph::EdgePath::const_iterator cit = edgepath.begin();
cit != edgepath.end(); ++cit) {
Converter const & conv = converterlist_[*cit];
@ -366,19 +362,19 @@ bool Converters::convert(Buffer const * buffer,
lyxerr[Debug::FILES] << "Converting from "
<< conv.from << " to " << conv.to << endl;
infile = outfile;
outfile = conv.result_dir.empty()
? changeExtension(from_file, conv.To->extension())
outfile = FileName(conv.result_dir.empty()
? changeExtension(from_file.absFilename(), conv.To->extension())
: addName(subst(conv.result_dir,
token_base, from_base),
subst(conv.result_file,
token_base, onlyFilename(from_base)));
token_base, onlyFilename(from_base))));
// if input and output files are equal, we use a
// temporary file as intermediary (JMarc)
string real_outfile;
FileName real_outfile;
if (outfile == infile) {
real_outfile = infile;
outfile = addName(buffer->temppath(), "tmpfile.out");
outfile = FileName(addName(buffer->temppath(), "tmpfile.out"));
}
if (conv.latex) {
@ -397,9 +393,9 @@ bool Converters::convert(Buffer const * buffer,
}
string const infile2 = (conv.original_dir)
? infile : makeRelPath(infile, path);
? infile.absFilename() : makeRelPath(infile.absFilename(), path);
string const outfile2 = (conv.original_dir)
? outfile : makeRelPath(outfile, path);
? outfile.absFilename() : makeRelPath(outfile.absFilename(), path);
string command = conv.command;
command = subst(command, token_from, quoteName(infile2));
@ -486,7 +482,7 @@ bool Converters::convert(Buffer const * buffer,
string const to = subst(conv.result_dir,
token_base, to_base);
Mover const & mover = movers(conv.from);
if (!mover.rename(from, to)) {
if (!mover.rename(FileName(from), FileName(to))) {
Alert::error(_("Cannot convert file"),
bformat(_("Could not move a temporary directory from %1$s to %2$s."),
from_ascii(from), from_ascii(to)));
@ -503,18 +499,18 @@ bool Converters::convert(Buffer const * buffer,
bool Converters::move(string const & fmt,
string const & from, string const & to, bool copy)
FileName const & from, FileName const & to, bool copy)
{
if (from == to)
return true;
bool no_errors = true;
string const path = onlyPath(from);
string const base = onlyFilename(changeExtension(from, ""));
string const to_base = changeExtension(to, "");
string const to_extension = getExtension(to);
string const path = onlyPath(from.absFilename());
string const base = onlyFilename(changeExtension(from.absFilename(), string()));
string const to_base = changeExtension(to.absFilename(), string());
string const to_extension = getExtension(to.absFilename());
vector<string> files = dirList(onlyPath(from), getExtension(from));
vector<string> files = dirList(onlyPath(from.absFilename()), getExtension(from.absFilename()));
for (vector<string>::const_iterator it = files.begin();
it != files.end(); ++it)
if (prefixIs(*it, base)) {
@ -526,8 +522,8 @@ bool Converters::move(string const & fmt,
Mover const & mover = movers(fmt);
bool const moved = copy
? mover.copy(from2, to2)
: mover.rename(from2, to2);
? mover.copy(FileName(from2), FileName(to2))
: mover.rename(FileName(from2), FileName(to2));
if (!moved && no_errors) {
Alert::error(_("Cannot convert file"),
bformat(copy ?

View File

@ -21,6 +21,7 @@
namespace lyx {
namespace support { class FileName; }
class Buffer;
class ErrorList;
@ -118,8 +119,8 @@ public:
};
///
bool convert(Buffer const * buffer,
std::string const & from_file, std::string const & to_file,
std::string const & orig_from,
support::FileName const & from_file, support::FileName const & to_file,
support::FileName const & orig_from,
std::string const & from_format, std::string const & to_format,
ErrorList & errorList, int conversionflags = none);
///
@ -154,7 +155,7 @@ private:
/// If \p from = /path/file.ext and \p to = /path2/file2.ext2 then
/// this method moves each /path/file*.ext file to /path2/file2*.ext2
bool move(std::string const & fmt,
std::string const & from, std::string const & to,
support::FileName const & from, support::FileName const & to,
bool copy);
///
Graph G_;

View File

@ -18,6 +18,8 @@
#include "lyxlex.h"
#include "lyxrc.h"
#include "support/filename.h"
namespace lyx {
@ -267,7 +269,7 @@ Encodings::Encodings()
{
}
void Encodings::read(string const & filename)
void Encodings::read(support::FileName const & filename)
{
enum Encodingtags {
et_encoding = 1,

View File

@ -20,6 +20,8 @@
namespace lyx {
namespace support { class FileName; }
///
class Encoding {
public:
@ -53,7 +55,7 @@ public:
///
Encodings();
///
void read(std::string const & filename);
void read(support::FileName const & filename);
/// Get encoding from LyX name \p name
Encoding const * getFromLyXName(std::string const & name) const;
/// Get encoding from LaTeX name \p name

View File

@ -43,6 +43,7 @@ using support::addName;
using support::bformat;
using support::changeExtension;
using support::contains;
using support::FileName;
using support::makeAbsPath;
using support::makeDisplayPath;
using support::onlyFilename;
@ -106,7 +107,7 @@ enum CopyStatus {
* - CANCEL if the export should be cancelled
*/
CopyStatus copyFile(string const & format,
string const & sourceFile, string const & destFile,
FileName const & sourceFile, FileName const & destFile,
string const & latexFile, bool force)
{
CopyStatus ret = force ? FORCE : SUCCESS;
@ -115,11 +116,11 @@ CopyStatus copyFile(string const & format,
// overwrite themselves. This check could be changed to
// boost::filesystem::equivalent(sourceFile, destFile) if export to
// other directories than the document directory is desired.
if (!prefixIs(onlyPath(sourceFile), package().temp_dir()))
if (!prefixIs(onlyPath(sourceFile.absFilename()), package().temp_dir()))
return ret;
if (!force) {
switch(checkOverwrite(destFile)) {
switch(checkOverwrite(destFile.absFilename())) {
case 0:
ret = SUCCESS;
break;
@ -135,8 +136,8 @@ CopyStatus copyFile(string const & format,
if (!mover.copy(sourceFile, destFile, latexFile))
Alert::error(_("Couldn't copy file"),
bformat(_("Copying %1$s to %2$s failed."),
makeDisplayPath(sourceFile),
makeDisplayPath(destFile)));
makeDisplayPath(sourceFile.absFilename()),
makeDisplayPath(destFile.absFilename())));
return ret;
}
@ -219,8 +220,8 @@ bool Exporter::Export(Buffer * buffer, string const & format,
string const error_type = (format == "program")? "Build" : bufferFormat(*buffer);
string const ext = formats.extension(format);
string const tmp_result_file = changeExtension(filename, ext);
bool const success = converters.convert(buffer, filename,
tmp_result_file, buffer->fileName(), backend_format, format,
bool const success = converters.convert(buffer, FileName(filename),
FileName(tmp_result_file), FileName(buffer->fileName()), backend_format, format,
buffer->errorList(error_type));
// Emit the signal to show the error list.
buffer->errors(error_type);
@ -242,15 +243,15 @@ bool Exporter::Export(Buffer * buffer, string const & format,
string const fmt =
formats.getFormatFromFile(it->sourceName);
status = copyFile(fmt, it->sourceName,
makeAbsPath(it->exportName, dest),
FileName(makeAbsPath(it->exportName, dest)),
it->exportName, status == FORCE);
}
if (status == CANCEL) {
buffer->message(_("Document export cancelled."));
} else if (fs::exists(tmp_result_file)) {
// Finally copy the main file
status = copyFile(format, tmp_result_file,
result_file, result_file,
status = copyFile(format, FileName(tmp_result_file),
FileName(result_file), result_file,
status == FORCE);
buffer->message(bformat(_("Document exported as %1$s "
"to file `%2$s'"),
@ -280,7 +281,7 @@ bool Exporter::preview(Buffer * buffer, string const & format)
string result_file;
if (!Export(buffer, format, true, result_file))
return false;
return formats.view(*buffer, result_file, format);
return formats.view(*buffer, FileName(result_file), format);
}
@ -311,7 +312,7 @@ Exporter::getExportableFormats(Buffer const & buffer, bool only_viewable)
}
ExportedFile::ExportedFile(string const & s, string const & e) :
ExportedFile::ExportedFile(FileName const & s, string const & e) :
sourceName(s), exportName(e) {}
@ -324,11 +325,9 @@ bool operator==(ExportedFile const & f1, ExportedFile const & f2)
void ExportData::addExternalFile(string const & format,
string const & sourceName,
FileName const & sourceName,
string const & exportName)
{
BOOST_ASSERT(support::absolutePath(sourceName));
// Make sure that we have every file only once, otherwise copyFile()
// would ask several times if it should overwrite a file.
vector<ExportedFile> & files = externalfiles[format];
@ -339,9 +338,9 @@ void ExportData::addExternalFile(string const & format,
void ExportData::addExternalFile(string const & format,
string const & sourceName)
FileName const & sourceName)
{
addExternalFile(format, sourceName, onlyFilename(sourceName));
addExternalFile(format, sourceName, onlyFilename(sourceName.absFilename()));
}

View File

@ -13,6 +13,8 @@
#ifndef EXPORTER_H
#define EXPORTER_H
#include "support/filename.h"
#include <map>
#include <string>
#include <vector>
@ -50,9 +52,9 @@ public:
class ExportedFile {
public:
ExportedFile(std::string const &, std::string const &);
ExportedFile(support::FileName const &, std::string const &);
/// absolute name of the source file
std::string sourceName;
support::FileName sourceName;
/// final name that the exported file should get (absolute name or
/// relative to the directory of the master document)
std::string exportName;
@ -76,7 +78,7 @@ public:
* or relative to the exported document.
*/
void addExternalFile(std::string const & format,
std::string const & sourceName,
support::FileName const & sourceName,
std::string const & exportName);
/** add a referenced file for one format.
* The final name is the source file name without path.
@ -84,7 +86,7 @@ public:
* \param sourceName source file name. Needs to be absolute
*/
void addExternalFile(std::string const & format,
std::string const & sourceName);
support::FileName const & sourceName);
/// get referenced files for \p format
std::vector<ExportedFile> const
externalFiles(std::string const & format) const;

View File

@ -35,6 +35,7 @@ using support::absolutePath;
using support::bformat;
using support::compare_ascii_no_case;
using support::contains;
using support::FileName;
using support::libScriptSearch;
using support::makeDisplayPath;
using support::onlyPath;
@ -136,7 +137,7 @@ Format const * Formats::getFormat(string const & name) const
}
string Formats::getFormatFromFile(string const & filename) const
string Formats::getFormatFromFile(FileName const & filename) const
{
if (filename.empty())
return string();
@ -146,7 +147,7 @@ string Formats::getFormatFromFile(string const & filename) const
return format;
// try to find a format from the file extension.
string const ext(support::getExtension(filename));
string const ext(support::getExtension(filename.absFilename()));
if (!ext.empty()) {
// this is ambigous if two formats have the same extension,
// but better than nothing
@ -261,14 +262,13 @@ void Formats::setViewer(string const & name, string const & command)
}
bool Formats::view(Buffer const & buffer, string const & filename,
bool Formats::view(Buffer const & buffer, FileName const & filename,
string const & format_name) const
{
BOOST_ASSERT(absolutePath(filename));
if (filename.empty() || !fs::exists(filename)) {
if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
Alert::error(_("Cannot view file"),
bformat(_("File does not exist: %1$s"),
from_utf8(filename)));
from_utf8(filename.absFilename())));
return false;
}
@ -286,12 +286,12 @@ bool Formats::view(Buffer const & buffer, string const & filename,
}
// viewer is 'auto'
if (format->viewer() == "auto") {
if (os::autoOpenFile(filename, os::VIEW))
if (os::autoOpenFile(filename.absFilename(), os::VIEW))
return true;
else {
Alert::error(_("Cannot view file"),
bformat(_("Auto-view file %1$s failed"),
from_utf8(filename)));
from_utf8(filename.absFilename())));
return false;
}
}
@ -312,10 +312,11 @@ bool Formats::view(Buffer const & buffer, string const & filename,
if (!contains(command, token_from))
command += ' ' + token_from;
command = subst(command, token_from, quoteName(filename));
command = subst(command, token_path, quoteName(onlyPath(filename)));
command = subst(command, token_from, quoteName(filename.toFilesystemEncoding()));
command = subst(command, token_path, quoteName(onlyPath(filename.toFilesystemEncoding())));
command = subst(command, token_socket, quoteName(theLyXServerSocket().address()));
lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
// FIXME UNICODE utf8 can be wrong for files
buffer.message(_("Executing command: ") + from_utf8(command));
Systemcall one;
@ -331,14 +332,13 @@ bool Formats::view(Buffer const & buffer, string const & filename,
}
bool Formats::edit(Buffer const & buffer, string const & filename,
bool Formats::edit(Buffer const & buffer, FileName const & filename,
string const & format_name) const
{
BOOST_ASSERT(absolutePath(filename));
if (filename.empty() || !fs::exists(filename)) {
if (filename.empty() || !fs::exists(filename.toFilesystemEncoding())) {
Alert::error(_("Cannot edit file"),
bformat(_("File does not exist: %1$s"),
from_utf8(filename)));
from_utf8(filename.absFilename())));
return false;
}
@ -356,12 +356,12 @@ bool Formats::edit(Buffer const & buffer, string const & filename,
}
// editor is 'auto'
if (format->editor() == "auto") {
if (os::autoOpenFile(filename, os::EDIT))
if (os::autoOpenFile(filename.absFilename(), os::EDIT))
return true;
else {
Alert::error(_("Cannot edit file"),
bformat(_("Auto-edit file %1$s failed"),
from_utf8(filename)));
from_utf8(filename.absFilename())));
return false;
}
}
@ -371,10 +371,11 @@ bool Formats::edit(Buffer const & buffer, string const & filename,
if (!contains(command, token_from))
command += ' ' + token_from;
command = subst(command, token_from, quoteName(filename));
command = subst(command, token_path, quoteName(onlyPath(filename)));
command = subst(command, token_from, quoteName(filename.toFilesystemEncoding()));
command = subst(command, token_path, quoteName(onlyPath(filename.toFilesystemEncoding())));
command = subst(command, token_socket, quoteName(theLyXServerSocket().address()));
lyxerr[Debug::FILES] << "Executing command: " << command << std::endl;
// FIXME UNICODE utf8 can be wrong for files
buffer.message(_("Executing command: ") + from_utf8(command));
Systemcall one;

View File

@ -15,11 +15,12 @@
#include "support/docstring.h"
#include <vector>
#include <string>
namespace lyx {
namespace support { class FileName; }
class Buffer;
class Format {
@ -131,7 +132,7 @@ public:
* \returns file format if it could be found, otherwise an empty
* string.
*/
std::string getFormatFromFile(std::string const & filename) const;
std::string getFormatFromFile(support::FileName const & filename) const;
/// Set editor and/or viewer to "auto" for formats that can be
/// opened by the OS.
void setAutoOpen();
@ -151,10 +152,10 @@ public:
///
void setViewer(std::string const & name, std::string const & command);
///
bool view(Buffer const & buffer, std::string const & filename,
bool view(Buffer const & buffer, support::FileName const & filename,
std::string const & format_name) const;
///
bool edit(Buffer const & buffer, std::string const & filename,
bool edit(Buffer const & buffer, support::FileName const & filename,
std::string const & format_name) const;
///
docstring const prettyName(std::string const & name) const;

View File

@ -28,6 +28,7 @@ using std::string;
namespace lyx {
using support::FileName;
using support::fileSearch;
using support::makeDisplayPath;
using support::package;
@ -42,12 +43,12 @@ ControlAboutlyx::ControlAboutlyx(Dialog & parent)
void ControlAboutlyx::getCredits(ostream & ss) const
{
string const name = fileSearch(package().system_support(), "CREDITS");
FileName const name = fileSearch(package().system_support(), "CREDITS");
bool found(!name.empty());
if (found) {
std::ifstream in(name.c_str());
std::ifstream in(name.toFilesystemEncoding().c_str());
ss << in.rdbuf();
found = ss.good();

View File

@ -38,6 +38,7 @@ using std::string;
namespace lyx {
using support::FileFilterList;
using support::FileName;
using support::makeAbsPath;
using support::readBB_from_PSFile;
@ -174,8 +175,7 @@ docstring const ControlExternal::browse(docstring const & input,
string const ControlExternal::readBB(string const & file)
{
string const abs_file =
makeAbsPath(file, kernel().bufferFilepath());
FileName const abs_file(makeAbsPath(file, kernel().bufferFilepath()));
// try to get it from the file, if possible. Zipped files are
// unzipped in the readBB_from_PSFile-Function

View File

@ -44,6 +44,7 @@ namespace lyx {
using support::addName;
using support::FileFilterList;
using support::FileName;
using support::isFileReadable;
using support::makeAbsPath;
using support::package;
@ -102,8 +103,7 @@ docstring const ControlGraphics::browse(docstring const & in_name) const
string const ControlGraphics::readBB(string const & file)
{
string const abs_file =
makeAbsPath(file, kernel().bufferFilepath());
FileName const abs_file(makeAbsPath(file, kernel().bufferFilepath()));
// try to get it from the file, if possible. Zipped files are
// unzipped in the readBB_from_PSFile-Function
@ -132,7 +132,7 @@ string const ControlGraphics::readBB(string const & file)
bool ControlGraphics::isFilenameValid(string const & fname) const
{
// It may be that the filename is relative.
string const name = makeAbsPath(fname, kernel().bufferFilepath());
FileName const name(makeAbsPath(fname, kernel().bufferFilepath()));
return isFileReadable(name);
}

View File

@ -35,6 +35,7 @@ using std::string;
namespace lyx {
using support::FileFilterList;
using support::FileName;
using support::isFileReadable;
using support::makeAbsPath;
using support::onlyPath;
@ -104,7 +105,7 @@ void ControlInclude::load(string const & file)
kernel().dispatch(FuncRequest(LFUN_BUFFER_CHILD_OPEN, file));
else
// tex file or other text file in verbatim mode
formats.edit(kernel().buffer(), file, "text");
formats.edit(kernel().buffer(), FileName(file), "text");
}
@ -114,7 +115,7 @@ bool ControlInclude::fileExists(string const & file)
= makeAbsPath(file,
onlyPath(kernel().buffer().fileName()));
if (isFileReadable(fileWithAbsPath))
if (isFileReadable(FileName(fileWithAbsPath)))
return true;
return false;

View File

@ -385,7 +385,7 @@ string const find_xpm(string const & name)
<< "Looking for math XPM called \""
<< xpm_name << '"' << std::endl;
return libFileSearch("images/math/", xpm_name, "xpm");
return libFileSearch("images/math/", xpm_name, "xpm").absFilename();
}
} // namespace frontend

View File

@ -11,12 +11,14 @@
#include <config.h>
#include "ControlShowFile.h"
#include "support/filetools.h"
using std::string;
namespace lyx {
using support::FileName;
using support::onlyFilename;
namespace frontend {
@ -29,7 +31,7 @@ ControlShowFile::ControlShowFile(Dialog & parent)
bool ControlShowFile::initialiseParams(string const & data)
{
filename_ = data;
filename_ = FileName(data);
return true;
}
@ -48,7 +50,7 @@ string ControlShowFile::getFileContents()
string ControlShowFile::getFileName()
{
return onlyFilename(filename_);
return onlyFilename(filename_.absFilename());
}
} // namespace frontend

View File

@ -14,6 +14,8 @@
#include "Dialog.h"
#include "support/filename.h"
namespace lyx {
namespace frontend {
@ -38,7 +40,7 @@ public:
private:
///
std::string filename_;
support::FileName filename_;
};
} // namespace frontend

View File

@ -109,7 +109,7 @@ docstring const browseLibFile(docstring const & dir,
lyx::from_utf8(addName(package().user_support(), lyx::to_utf8(dir))));
docstring const result = browseFile(lyx::from_utf8(
libFileSearch(lyx::to_utf8(dir), lyx::to_utf8(name), lyx::to_utf8(ext))),
libFileSearch(to_utf8(dir), to_utf8(name), to_utf8(ext)).absFilename()),
title, filters, false, dir1, dir2);
// remove the extension if it is the default one
@ -121,7 +121,7 @@ docstring const browseLibFile(docstring const & dir,
// remove the directory, if it is the default one
docstring const file = lyx::from_utf8(onlyFilename(lyx::to_utf8(noextresult)));
if (lyx::from_utf8(libFileSearch(lyx::to_utf8(dir), lyx::to_utf8(file), lyx::to_utf8(ext))) == result)
if (from_utf8(libFileSearch(to_utf8(dir), to_utf8(file), to_utf8(ext)).absFilename()) == result)
return file;
else
return noextresult;

View File

@ -35,6 +35,7 @@ namespace lyx {
using support::bformat;
using support::contains;
using support::FileName;
using support::getExtension;
using support::getFileContents;
using support::getVectorFromString;
@ -53,16 +54,16 @@ void rescanTexStyles()
{
// Run rescan in user lyx directory
Path p(package().user_support());
string const command = libFileSearch("scripts", "TeXFiles.py");
FileName const command = libFileSearch("scripts", "TeXFiles.py");
Systemcall one;
int const status = one.startscript(Systemcall::Wait,
lyx::support::os::python() + ' ' +
quoteName(command));
quoteName(command.toFilesystemEncoding()));
if (status == 0)
return;
// FIXME UNICODE
Alert::error(_("Could not update TeX information"),
bformat(_("The script `%s' failed."), lyx::from_utf8(command)));
bformat(_("The script `%s' failed."), lyx::from_utf8(command.absFilename())));
}
@ -80,7 +81,7 @@ void texhash()
void getTexFileList(string const & filename, std::vector<string> & list)
{
list.clear();
string const file = libFileSearch("", filename);
FileName const file = libFileSearch("", filename);
if (file.empty())
return;
@ -138,8 +139,12 @@ string const getTexFileFromList(string const & file,
lstfile = "bstFiles.lst";
else if (type == "bib")
lstfile = "bibFiles.lst";
string const allClasses = getFileContents(libFileSearch(string(),
lstfile));
FileName const abslstfile = libFileSearch(string(), lstfile);
if (abslstfile.empty()) {
lyxerr << "File `'" << lstfile << "' not found." << endl;
return string();
}
string const allClasses = getFileContents(abslstfile);
int entries = 0;
string classfile = token(allClasses, '\n', entries);
int count = 0;

View File

@ -69,7 +69,7 @@ void BulletsModule::setupPanel(QListWidget * lw, QString panelname, std::string
bulletpaneCO->addItem(panelname);
// get pixmap with bullets
QPixmap pixmap = QPixmap(toqstr(libFileSearch("images", fname, "xpm")));
QPixmap pixmap = QPixmap(toqstr(libFileSearch("images", fname, "xpm").absFilename()));
int const w = pixmap.width() / 6;
int const h = pixmap.height() / 6;

View File

@ -58,10 +58,10 @@ using std::endl;
using std::string;
using std::vector;
using lyx::support::onlyFilename;
namespace lyx {
using support::FileName;
using support::onlyFilename;
using support::subst;
using support::libFileSearch;
@ -118,9 +118,9 @@ GuiView::GuiView(int id)
#ifndef Q_WS_MACX
// assign an icon to main form. We do not do it under Qt/Mac,
// since the icon is provided in the application bundle.
string const iconname = libFileSearch("images", "lyx", "xpm");
FileName const iconname = libFileSearch("images", "lyx", "xpm");
if (!iconname.empty())
setWindowIcon(QPixmap(toqstr(iconname)));
setWindowIcon(QPixmap(toqstr(iconname.absFilename())));
#endif
}

View File

@ -61,6 +61,8 @@ namespace os = lyx::support::os;
namespace lyx {
using support::FileName;
/// return the LyX key state from Qt's
static key_modifier::state q_key_state(Qt::KeyboardModifiers state)
{
@ -470,11 +472,11 @@ void GuiWorkArea::doGreyOut(QLPainter & pain)
lyxerr[Debug::GUI] << "show banner: " << lyxrc.show_banner << endl;
/// The text to be written on top of the pixmap
QString const text = lyx_version ? QString(lyx_version) : qt_("unknown version");
string const file = support::libFileSearch("images", "banner", "ppm");
FileName const file = support::libFileSearch("images", "banner", "ppm");
if (file.empty())
return;
QPixmap pm(toqstr(file));
QPixmap pm(toqstr(file.absFilename()));
if (!pm) {
lyxerr << "could not load splash screen: '" << file << "'" << endl;
return;

View File

@ -78,8 +78,8 @@ QCommandBuffer::QCommandBuffer(GuiView * view, ControlCommandBuffer & control,
QWidget * parent)
: QWidget(parent), view_(view), controller_(control)
{
QPixmap qpup(toqstr(libFileSearch("images", "up", "xpm")));
QPixmap qpdown(toqstr(libFileSearch("images", "down", "xpm")));
QPixmap qpup(toqstr(libFileSearch("images", "up", "xpm").absFilename()));
QPixmap qpdown(toqstr(libFileSearch("images", "down", "xpm").absFilename()));
QVBoxLayout * top = new QVBoxLayout(this);
QHBoxLayout * layout = new QHBoxLayout(0);

View File

@ -19,6 +19,7 @@
#include "graphics/GraphicsParams.h"
#include "support/filename.h"
#include "support/lstrings.h" // lowercase
#include <QPainter>
@ -152,7 +153,7 @@ unsigned int QLImage::getHeight_impl() const
}
void QLImage::load_impl(string const & filename)
void QLImage::load_impl(support::FileName const & filename)
{
if (!original_.isNull()) {
lyxerr[Debug::GRAPHICS]
@ -161,7 +162,7 @@ void QLImage::load_impl(string const & filename)
return;
}
if (!original_.load(toqstr(filename))) {
if (!original_.load(toqstr(filename.absFilename()))) {
lyxerr[Debug::GRAPHICS]
<< "Unable to open image" << endl;
finishedLoading(false);

View File

@ -51,7 +51,7 @@ private:
* The process is asynchronous, so this method starts the loading.
* When finished, the Image::finishedLoading signal is emitted.
*/
virtual void load_impl(std::string const & filename);
virtual void load_impl(support::FileName const & filename);
/**
* Finishes the process of modifying transformed_, using
* \c params to decide on color, grayscale etc.

View File

@ -29,9 +29,11 @@
using std::string;
using lyx::support::libFileSearch;
namespace lyx {
using support::FileName;
using support::libFileSearch;
namespace frontend {
@ -70,26 +72,26 @@ QMathDialog::QMathDialog(QMath * form)
connect( equationPB, SIGNAL( clicked() ), this, SLOT( equationClicked() ) );
connect( symbolsCO, SIGNAL(activated(int)), this, SLOT(showingPanel(int)));
string icon_path = libFileSearch("images/math", "sqrt-square", "xpm");
sqrtPB->setIcon(QIcon(toqstr(icon_path)));
FileName icon_path = libFileSearch("images/math", "sqrt-square", "xpm");
sqrtPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
icon_path = libFileSearch("images/math", "space", "xpm");
spacePB->setIcon(QIcon(toqstr(icon_path)));
spacePB->setIcon(QIcon(toqstr(icon_path.absFilename())));
icon_path = libFileSearch("images/math", "style", "xpm");
stylePB->setIcon(QIcon(toqstr(icon_path)));
stylePB->setIcon(QIcon(toqstr(icon_path.absFilename())));
icon_path = libFileSearch("images/math", "font", "xpm");
fontPB->setIcon(QIcon(toqstr(icon_path)));
fontPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
icon_path = libFileSearch("images/math", "equation", "xpm");
equationPB->setIcon(QIcon(toqstr(icon_path)));
equationPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
icon_path = libFileSearch("images/math", "frac-square", "xpm");
fracPB->setIcon(QIcon(toqstr(icon_path)));
fracPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
icon_path = libFileSearch("images/math", "sub", "xpm");
subscriptPB->setIcon(QIcon(toqstr(icon_path)));
subscriptPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
icon_path = libFileSearch("images/math", "super", "xpm");
superscriptPB->setIcon(QIcon(toqstr(icon_path)));
superscriptPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
icon_path = libFileSearch("images/math", "matrix", "xpm");
matrixPB->setIcon(QIcon(toqstr(icon_path)));
matrixPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
icon_path = libFileSearch("images/math", "delim", "xpm");
delimitersPB->setIcon(QIcon(toqstr(icon_path)));
delimitersPB->setIcon(QIcon(toqstr(icon_path.absFilename())));
// function list
for (int i = 0; *function_names[i]; ++i) {

View File

@ -17,22 +17,24 @@
#include "debug.h"
#include "support/filename.h"
#include "support/filetools.h"
#include <map>
namespace support = lyx::support;
using std::string;
namespace lyx {
using support::FileName;
namespace graphics {
/** The cache contains one item per file, so use a map to find the
* cache item quickly by filename.
*/
typedef std::map<string, Cache::ItemPtr> CacheType;
typedef std::map<FileName, Cache::ItemPtr> CacheType;
class Cache::Impl {
public:
@ -64,15 +66,8 @@ std::vector<string> Cache::loadableFormats() const
}
void Cache::add(string const & file) const
void Cache::add(FileName const & file) const
{
if (!support::absolutePath(file)) {
lyxerr << "Cache::add(" << file << "):\n"
<< "The file must be have an absolute path."
<< std::endl;
return;
}
// Is the file in the cache already?
if (inCache(file)) {
lyxerr[Debug::GRAPHICS] << "Cache::add(" << file << "):\n"
@ -85,7 +80,7 @@ void Cache::add(string const & file) const
}
void Cache::remove(string const & file) const
void Cache::remove(FileName const & file) const
{
CacheType::iterator it = pimpl_->cache.find(file);
if (it == pimpl_->cache.end())
@ -101,13 +96,13 @@ void Cache::remove(string const & file) const
}
bool Cache::inCache(string const & file) const
bool Cache::inCache(FileName const & file) const
{
return pimpl_->cache.find(file) != pimpl_->cache.end();
}
Cache::ItemPtr const Cache::item(string const & file) const
Cache::ItemPtr const Cache::item(FileName const & file) const
{
CacheType::const_iterator it = pimpl_->cache.find(file);
if (it == pimpl_->cache.end())

View File

@ -29,6 +29,9 @@
namespace lyx {
namespace support { class FileName; }
namespace graphics {
class CacheItem;
@ -46,13 +49,13 @@ public:
std::vector<std::string> loadableFormats() const;
/// Add a graphics file to the cache.
void add(std::string const & file) const;
void add(support::FileName const & file) const;
/// Remove a file from the cache.
void remove(std::string const & file) const;
void remove(support::FileName const & file) const;
/// Returns \c true if the file is in the cache.
bool inCache(std::string const & file) const;
bool inCache(support::FileName const & file) const;
/** Get the cache item associated with file.
* Returns an empty container if there is no such item.
@ -66,7 +69,7 @@ public:
*/
typedef boost::shared_ptr<CacheItem> ItemPtr;
///
ItemPtr const item(std::string const & file) const;
ItemPtr const item(support::FileName const & file) const;
private:
/** Make the c-tor, d-tor private so we can control how many objects

View File

@ -20,6 +20,7 @@
#include "debug.h"
#include "format.h"
#include "support/filename.h"
#include "support/filetools.h"
#include "support/FileMonitor.h"
#include "support/lyxlib.h"
@ -30,6 +31,7 @@
namespace lyx {
using support::FileMonitor;
using support::FileName;
using support::isFileReadable;
using support::makeDisplayPath;
using support::onlyFilename;
@ -48,7 +50,7 @@ class CacheItem::Impl : public boost::signals::trackable {
public:
///
Impl(string const & file);
Impl(FileName const & file);
/** Start the image conversion process, checking first that it is
* necessary. If it is necessary, then a conversion task is started.
@ -100,18 +102,18 @@ public:
void reset();
/// The filename we refer too.
string const filename_;
FileName const filename_;
///
FileMonitor const monitor_;
/// Is the file compressed?
bool zipped_;
/// If so, store the uncompressed file in this temporary file.
string unzipped_filename_;
FileName unzipped_filename_;
/// The target format
string to_;
/// What file are we trying to load?
string file_to_load_;
FileName file_to_load_;
/** Should we delete the file after loading? True if the file is
* the result of a conversion process.
*/
@ -136,7 +138,7 @@ public:
};
CacheItem::CacheItem(string const & file)
CacheItem::CacheItem(FileName const & file)
: pimpl_(new Impl(file))
{}
@ -145,7 +147,7 @@ CacheItem::~CacheItem()
{}
string const & CacheItem::filename() const
FileName const & CacheItem::filename() const
{
return pimpl_->filename_;
}
@ -199,7 +201,7 @@ boost::signals::connection CacheItem::connect(slot_type const & slot) const
//------------------------------
CacheItem::Impl::Impl(string const & file)
CacheItem::Impl::Impl(FileName const & file)
: filename_(file),
monitor_(file, 2000),
zipped_(false),
@ -264,7 +266,7 @@ void CacheItem::Impl::imageConverted(bool success)
lyxerr[Debug::GRAPHICS] << "Image conversion " << text << '.' << endl;
file_to_load_ = converter_.get() ?
converter_->convertedFile() : string();
FileName(converter_->convertedFile()) : FileName();
converter_.reset();
cc_.disconnect();
@ -381,21 +383,21 @@ void CacheItem::Impl::convertToDisplayFormat()
}
// Make a local copy in case we unzip it
string filename;
FileName filename;
zipped_ = zippedFile(filename_);
if (zipped_) {
unzipped_filename_ = tempName(string(), filename_);
unzipped_filename_ = FileName(tempName(string(), filename_.toFilesystemEncoding()));
if (unzipped_filename_.empty()) {
setStatus(ErrorConverting);
lyxerr[Debug::GRAPHICS]
<< "\tCould not create temporary file." << endl;
return;
}
filename = unzipFile(filename_, unzipped_filename_);
filename = unzipFile(filename_, unzipped_filename_.toFilesystemEncoding());
} else
filename = filename_;
docstring const displayed_filename = makeDisplayPath(filename_);
docstring const displayed_filename = makeDisplayPath(filename_.absFilename());
lyxerr[Debug::GRAPHICS] << "[GrahicsCacheItem::convertToDisplayFormat]\n"
<< "\tAttempting to convert image file: " << filename
<< "\n\twith displayed filename: " << lyx::to_utf8(displayed_filename)
@ -436,7 +438,7 @@ void CacheItem::Impl::convertToDisplayFormat()
// Remove the temp file, we only want the name...
// FIXME: This is unsafe!
unlink(to_file_base);
unlink(FileName(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

View File

@ -36,6 +36,9 @@
namespace lyx {
namespace support { class FileName; }
namespace graphics {
class Image;
@ -45,13 +48,13 @@ class Converter;
class CacheItem : boost::noncopyable {
public:
///
CacheItem(std::string const & file);
CacheItem(support::FileName const & file);
/// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
~CacheItem();
///
std::string const & filename() const;
support::FileName const & filename() const;
/// It's in the cache. Now start the loading process.
void startLoading() const;

View File

@ -31,6 +31,7 @@
namespace support = lyx::support;
using support::changeExtension;
using support::FileName;
using support::Forkedcall;
using support::ForkedCallQueue;
using support::getExtension;
@ -56,7 +57,7 @@ namespace graphics {
class Converter::Impl : public boost::signals::trackable {
public:
///
Impl(string const &, string const &, string const &, string const &);
Impl(FileName const &, string const &, string const &, string const &);
///
void startConversion();
@ -78,9 +79,9 @@ public:
///
string script_command_;
///
string script_file_;
FileName script_file_;
///
string to_file_;
FileName to_file_;
///
bool valid_process_;
///
@ -95,7 +96,7 @@ bool Converter::isReachable(string const & from_format_name,
}
Converter::Converter(string const & from_file, string const & to_file_base,
Converter::Converter(FileName const & from_file, string const & to_file_base,
string const & from_format, string const & to_format)
: pimpl_(new Impl(from_file, to_file_base, from_format, to_format))
{}
@ -118,21 +119,21 @@ boost::signals::connection Converter::connect(slot_type const & slot) const
}
string const & Converter::convertedFile() const
FileName const & Converter::convertedFile() const
{
static string const empty;
static FileName const empty;
return pimpl_->finished_ ? pimpl_->to_file_ : empty;
}
/** Build the conversion script.
* The script is output to the stream \p script.
*/
static void build_script(string const & from_file, string const & to_file_base,
static void build_script(FileName const & from_file, string const & to_file_base,
string const & from_format, string const & to_format,
ostream & script);
Converter::Impl::Impl(string const & from_file, string const & to_file_base,
Converter::Impl::Impl(FileName const & from_file, string const & to_file_base,
string const & from_format, string const & to_format)
: valid_process_(false), finished_(false)
{
@ -145,7 +146,7 @@ Converter::Impl::Impl(string const & from_file, string const & to_file_base,
// The converted image is to be stored in this file (we do not
// use ChangeExtension because this is a basename which may
// nevertheless contain a '.')
to_file_ = to_file_base + '.' + formats.extension(to_format);
to_file_ = FileName(to_file_base + '.' + formats.extension(to_format));
// The conversion commands are stored in a stringstream
ostringstream script;
@ -157,10 +158,10 @@ Converter::Impl::Impl(string const & from_file, string const & to_file_base,
// Output the script to file.
static int counter = 0;
script_file_ = onlyPath(to_file_base) + "lyxconvert" +
convert<string>(counter++) + ".py";
script_file_ = FileName(onlyPath(to_file_base) + "lyxconvert" +
convert<string>(counter++) + ".py");
std::ofstream fs(script_file_.c_str());
std::ofstream fs(script_file_.toFilesystemEncoding().c_str());
if (!fs.good()) {
lyxerr << "Unable to write the conversion script to \""
<< script_file_ << '\n'
@ -177,8 +178,8 @@ Converter::Impl::Impl(string const & from_file, string const & to_file_base,
// list of forked processes.
// Note: 'python ' is absolutely essential, or execvp will fail.
script_command_ = support::os::python() + ' ' +
quoteName(script_file_) + ' ' +
quoteName(onlyFilename(from_file)) + ' ' +
quoteName(script_file_.toFilesystemEncoding()) + ' ' +
quoteName(onlyFilename(from_file.toFilesystemEncoding())) + ' ' +
quoteName(to_format);
// All is ready to go
valid_process_ = true;
@ -269,7 +270,7 @@ static void build_conversion_command(string const & command, ostream & script)
}
static void build_script(string const & from_file,
static void build_script(FileName const & from_file,
string const & to_file_base,
string const & from_format,
string const & to_format,
@ -302,14 +303,14 @@ static void build_script(string const & from_file,
static int counter = 0;
string const tmp = "gconvert" + convert<string>(counter++);
string const to_base = tempName(string(), tmp);
unlink(to_base);
unlink(FileName(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));
script << "infile = " << quoteName(from_file, quote_python) << "\n"
string outfile = changeExtension(to_base, getExtension(from_file.absFilename()));
script << "infile = " << quoteName(from_file.absFilename(), quote_python) << "\n"
"outfile = " << quoteName(outfile, quote_python) << "\n"
"shutil.copy(infile, outfile)\n";

View File

@ -22,6 +22,9 @@
#include <boost/utility.hpp>
namespace lyx {
namespace support { class FileName; }
namespace graphics {
class Converter : boost::noncopyable {
@ -33,7 +36,7 @@ public:
/** One Converter per conversion ensures that the (hidden) signal
* is always connected to the expected slot.
*/
Converter(std::string const & from_file, std::string const & to_file_base,
Converter(support::FileName const & from_file, std::string const & to_file_base,
std::string const & from_format, std::string const & to_format);
/// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
@ -56,7 +59,7 @@ public:
* If conversion fails or has not been completed, however, it
* returns an empty string.
*/
std::string const & convertedFile() const;
support::FileName const & convertedFile() const;
private:
/// Use the Pimpl idiom to hide the internals.

View File

@ -32,6 +32,9 @@
#include <utility>
namespace lyx {
namespace support { class FileName; }
namespace graphics {
class Params;
@ -76,7 +79,7 @@ public:
* The caller should expect this process to be asynchronous and
* so should connect to the "finished" signal above.
*/
void load(std::string const & filename);
void load(support::FileName const & filename);
/** Generate the pixmap.
* Uses the params to decide on color, grayscale etc.
@ -122,7 +125,7 @@ private:
* The caller should expect this process to be asynchronous and
* so should connect to the "finished" signal above.
*/
virtual void load_impl(std::string const & filename) = 0;
virtual void load_impl(support::FileName const & filename) = 0;
/** Generate the pixmap.
* Uses the params to decide on color, grayscale etc.
@ -170,7 +173,7 @@ bool Image::isDrawable() const
inline
void Image::load(std::string const & filename)
void Image::load(support::FileName const & filename)
{
return load_impl(filename);
}

View File

@ -17,6 +17,8 @@
#include "GraphicsParams.h"
#include "LoaderQueue.h"
#include "support/filename.h"
#include <boost/bind.hpp>
@ -24,6 +26,9 @@ using std::string;
namespace lyx {
using support::FileName;
namespace graphics {
class Loader::Impl : public boost::signals::trackable {
@ -33,7 +38,7 @@ public:
///
~Impl();
///
void resetFile(string const &);
void resetFile(FileName const &);
///
void resetParams(Params const &);
///
@ -70,14 +75,14 @@ Loader::Loader()
{}
Loader::Loader(string const & file, DisplayType type)
Loader::Loader(FileName const & file, DisplayType type)
: pimpl_(new Impl)
{
reset(file, type);
}
Loader::Loader(string const & file, Params const & params)
Loader::Loader(FileName const & file, Params const & params)
: pimpl_(new Impl)
{
reset(file, params);
@ -106,7 +111,7 @@ Loader & Loader::operator=(Loader const & other)
}
void Loader::reset(string const & file, DisplayType type) const
void Loader::reset(FileName const & file, DisplayType type) const
{
Params params;
params.display = type;
@ -117,7 +122,7 @@ void Loader::reset(string const & file, DisplayType type) const
}
void Loader::reset(string const & file, Params const & params) const
void Loader::reset(FileName const & file, Params const & params) const
{
pimpl_->resetParams(params);
pimpl_->resetFile(file);
@ -167,9 +172,9 @@ unsigned long Loader::checksum() const
}
string const & Loader::filename() const
FileName const & Loader::filename() const
{
static string const empty;
static FileName const empty;
return pimpl_->cached_item_.get() ?
pimpl_->cached_item_->filename() : empty;
}
@ -201,14 +206,14 @@ Loader::Impl::Impl()
Loader::Impl::~Impl()
{
resetFile(string());
resetFile(FileName());
}
void Loader::Impl::resetFile(string const & file)
void Loader::Impl::resetFile(FileName const & file)
{
string const old_file = cached_item_.get() ?
cached_item_->filename() : string();
FileName const old_file = cached_item_.get() ?
cached_item_->filename() : FileName();
if (file == old_file)
return;

View File

@ -30,6 +30,9 @@
#include <boost/signal.hpp>
namespace lyx {
namespace support { class FileName; }
namespace graphics {
class Image;
@ -40,9 +43,9 @@ public:
/// Must use the reset methods to make this instance usable.
Loader();
/// The image is not transformed, just displayed as-is.
Loader(std::string const & file_with_path, DisplayType = ColorDisplay);
Loader(support::FileName const & file_with_path, DisplayType = ColorDisplay);
/// The image is transformed before display.
Loader(std::string const & file_with_path, Params const &);
Loader(support::FileName const & file_with_path, Params const &);
///
Loader(Loader const &);
@ -52,17 +55,16 @@ public:
Loader & operator=(Loader const &);
/// The file can be changed, or the display params, or both.
void reset(std::string const & file_with_path,
void reset(support::FileName const & file_with_path,
DisplayType = ColorDisplay) const;
///
void reset(std::string const & file_with_path, Params const &) const;
void reset(support::FileName const & file_with_path, Params const &) const;
///
void reset(Params const &) const;
/// Returns the absolute path of the loaded (loading?) file.
std::string const & filename() const;
support::FileName const & filename() const;
///
bool empty() const { return filename().empty(); }
/** starting loading of the image is done by a urgency-based
* decision. Here we only call LoaderQueue::touch to request it.

View File

@ -16,6 +16,8 @@
#include "GraphicsTypes.h"
#include "support/filename.h"
#include <string>
#include <iosfwd>
@ -57,7 +59,7 @@ public:
unsigned int scale;
/// The image filename.
std::string filename;
support::FileName filename;
/** Note that the BoundingBox is always relative to the BoundingBox
* as stored in the EPS file.

View File

@ -15,23 +15,25 @@
#include "GraphicsLoader.h"
#include "PreviewLoader.h"
#include "support/filename.h"
#include "support/lyxlib.h"
#include <boost/bind.hpp>
namespace support = lyx::support;
using std::string;
namespace lyx {
using support::FileName;
namespace graphics {
class PreviewImage::Impl : public boost::signals::trackable {
public:
///
Impl(PreviewImage & p, PreviewLoader & l,
string const & s, string const & f, double af);
string const & s, FileName const & f, double af);
///
~Impl();
///
@ -54,7 +56,7 @@ public:
PreviewImage::PreviewImage(PreviewLoader & l,
string const & s,
string const & f,
FileName const & f,
double af)
: pimpl_(new Impl(*this, l, s, f, af))
{}
@ -106,7 +108,7 @@ Image const * PreviewImage::image() const
PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l,
string const & s,
string const & bf,
FileName const & bf,
double af)
: parent_(p), ploader_(l), iloader_(bf),
snippet_(s), ascent_frac_(af)

View File

@ -16,6 +16,9 @@
#include <string>
namespace lyx {
namespace support { class FileName; }
namespace graphics {
class PreviewLoader;
@ -28,7 +31,7 @@ public:
*/
PreviewImage(PreviewLoader & parent,
std::string const & latex_snippet,
std::string const & bitmap_file,
support::FileName const & bitmap_file,
double ascent_frac);
///
~PreviewImage();

View File

@ -41,6 +41,8 @@
#include <fstream>
#include <iomanip>
using lyx::support::FileName;
using std::endl;
using std::find;
using std::fill;
@ -60,13 +62,13 @@ using std::string;
namespace {
typedef pair<string, string> StrPair;
typedef pair<string, FileName> SnippetPair;
// A list of alll snippets to be converted to previews
typedef list<string> PendingSnippets;
// Each item in the vector is a pair<snippet, image file name>.
typedef vector<StrPair> BitmapFile;
typedef vector<SnippetPair> BitmapFile;
string const unique_filename(string const & bufferpath)
@ -110,7 +112,7 @@ lyx::Converter const * setConverter()
void setAscentFractions(vector<double> & ascent_fractions,
string const & metrics_file)
FileName const & metrics_file)
{
// If all else fails, then the images will have equal ascents and
// descents.
@ -118,7 +120,7 @@ void setAscentFractions(vector<double> & ascent_fractions,
vector<double>::iterator end = ascent_fractions.end();
fill(it, end, 0.5);
ifstream in(metrics_file.c_str());
ifstream in(metrics_file.toFilesystemEncoding().c_str());
if (!in.good()) {
lyx::lyxerr[lyx::Debug::GRAPHICS]
<< "setAscentFractions(" << metrics_file << ")\n"
@ -162,10 +164,10 @@ void setAscentFractions(vector<double> & ascent_fractions,
}
class FindFirst : public std::unary_function<StrPair, bool> {
class FindFirst : public std::unary_function<SnippetPair, bool> {
public:
FindFirst(string const & comp) : comp_(comp) {}
bool operator()(StrPair const & sp) const
bool operator()(SnippetPair const & sp) const
{
return sp.first == comp_;
}
@ -191,7 +193,7 @@ public:
///
string command;
///
string metrics_file;
FileName metrics_file;
///
BitmapFile snippets;
};
@ -349,13 +351,13 @@ public:
: to_format_(to_format), base_(filename_base), counter_(1)
{}
StrPair const operator()(string const & snippet)
SnippetPair const operator()(string const & snippet)
{
ostringstream os;
os << base_ << counter_++ << '.' << to_format_;
string const file = os.str();
return make_pair(snippet, file);
return make_pair(snippet, FileName(file));
}
private:
@ -369,7 +371,7 @@ InProgress::InProgress(string const & filename_base,
PendingSnippets const & pending,
string const & to_format)
: pid(0),
metrics_file(filename_base + ".metrics"),
metrics_file(FileName(filename_base + ".metrics")),
snippets(pending.size())
{
PendingSnippets::const_iterator pit = pending.begin();
@ -649,7 +651,7 @@ void PreviewLoader::Impl::finishedGenerating(pid_t pid, int retval)
int metrics_counter = 0;
for (; it != end; ++it, ++metrics_counter) {
string const & snip = it->first;
string const & file = it->second;
FileName const & file = it->second;
double af = ascent_fractions[metrics_counter];
PreviewImagePtr ptr(new PreviewImage(parent_, snip, file, af));

View File

@ -32,6 +32,7 @@ namespace lyx {
using support::bformat;
using support::changeExtension;
using support::FileName;
using support::makeDisplayPath;
using std::find;
@ -56,8 +57,8 @@ bool Importer::Import(LyXView * lv, string const & filename,
string const tofile =
changeExtension(filename,
formats.extension(*it));
if (!converters.convert(0, filename, tofile,
filename, format, *it, errorList))
if (!converters.convert(0, FileName(filename), FileName(tofile),
FileName(filename), format, *it, errorList))
return false;
loader_format = *it;
break;

View File

@ -30,7 +30,6 @@
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/package.h"
#include "support/path.h"
using std::endl;
using std::string;
@ -38,6 +37,9 @@ using std::vector;
namespace lyx {
using support::FileName;
namespace external {
Template const * getTemplatePtr(InsetExternalParams const & params)
@ -49,9 +51,8 @@ Template const * getTemplatePtr(InsetExternalParams const & params)
void editExternal(InsetExternalParams const & params, Buffer const & buffer)
{
string const file_with_path = params.filename.absFilename();
formats.edit(buffer, file_with_path,
formats.getFormatFromFile(file_with_path));
formats.edit(buffer, params.filename,
formats.getFormatFromFile(params.filename));
}
@ -154,7 +155,7 @@ string const doSubstitution(InsetExternalParams const & params,
support::PROTECT_EXTENSION, support::ESCAPE_DOTS);
result = subst_path(result, "$$Extension",
'.' + support::getExtension(filename), use_latex_path);
result = subst_path(result, "$$Tempname", params.tempname(), use_latex_path);
result = subst_path(result, "$$Tempname", params.tempname().absFilename(), use_latex_path);
result = subst_path(result, "$$Sysdir",
support::package().system_support(), use_latex_path);
@ -166,12 +167,10 @@ string const doSubstitution(InsetExternalParams const & params,
string const file = result.substr(pos + 12, end - (pos + 12));
string contents;
string const filepath = support::isFileReadable(file) ?
buffer.filePath() : m_buffer->temppath();
support::Path p(filepath);
if (support::isFileReadable(file))
contents = support::getFileContents(file);
FileName const absfile = FileName(
support::makeAbsPath(file, m_buffer->temppath()));
if (support::isFileReadable(absfile))
contents = support::getFileContents(absfile);
result = support::subst(result,
("$$Contents(\"" + file + "\")").c_str(),
@ -214,14 +213,12 @@ void updateExternal(InsetExternalParams const & params,
if (from_format.empty())
return; // NOT_NEEDED
string abs_from_file = params.filename.absFilename();
if (from_format == "*") {
if (abs_from_file.empty())
if (params.filename.empty())
return; // NOT_NEEDED
// Try and ascertain the file format from its contents.
from_format = formats.getFormatFromFile(abs_from_file);
from_format = formats.getFormatFromFile(params.filename);
if (from_format.empty())
return; // FAILURE
@ -245,20 +242,20 @@ void updateExternal(InsetExternalParams const & params,
// We copy the source file to the temp dir and do the conversion
// there if necessary
string const temp_file =
FileName const temp_file = FileName(
support::makeAbsPath(params.filename.mangledFilename(),
m_buffer->temppath());
if (!abs_from_file.empty()) {
unsigned long const from_checksum = support::sum(abs_from_file);
m_buffer->temppath()));
if (!params.filename.empty()) {
unsigned long const from_checksum = support::sum(params.filename);
unsigned long const temp_checksum = support::sum(temp_file);
if (from_checksum != temp_checksum) {
Mover const & mover = movers(from_format);
if (!mover.copy(abs_from_file, temp_file)) {
if (!mover.copy(params.filename, temp_file)) {
lyxerr[Debug::EXTERNAL]
<< "external::updateExternal. "
<< "Unable to copy "
<< abs_from_file << " to " << temp_file << endl;
<< params.filename << " to " << temp_file << endl;
return; // FAILURE
}
}
@ -268,8 +265,8 @@ void updateExternal(InsetExternalParams const & params,
string const to_file = doSubstitution(params, buffer,
outputFormat.updateResult,
false, true);
string const abs_to_file =
support::makeAbsPath(to_file, m_buffer->temppath());
FileName const abs_to_file = FileName(
support::makeAbsPath(to_file, m_buffer->temppath()));
// Record the referenced files for the exporter.
// The exporter will copy them to the export dir.
@ -280,10 +277,10 @@ void updateExternal(InsetExternalParams const & params,
vector<string>::const_iterator fit = rit->second.begin();
vector<string>::const_iterator fend = rit->second.end();
for (; fit != fend; ++fit) {
string const source = support::makeAbsPath(
FileName const source(support::makeAbsPath(
doSubstitution(params, buffer, *fit,
false, true),
m_buffer->temppath());
m_buffer->temppath()));
// The path of the referenced file is never the
// temp path, but the filename may be the mangled
// or the real name. Therefore we substitute the
@ -310,7 +307,7 @@ void updateExternal(InsetExternalParams const & params,
ErrorList el;
/* bool const success = */
converters.convert(&buffer, temp_file, abs_to_file,
abs_from_file, from_format, to_format, el,
params.filename, from_format, to_format, el,
Converters::try_default | Converters::try_cache);
// return success
}

View File

@ -253,7 +253,7 @@ void TemplateManager::readTemplates(string const & path)
LyXLex lex(templatetags, TM_TEMPLATE_END);
string filename = support::libFileSearch("", "external_templates");
support::FileName const filename = support::libFileSearch("", "external_templates");
if (filename.empty() || !lex.setFile(filename)) {
lex.printError("external::TemplateManager::readTemplates: "
"No template file");

View File

@ -24,7 +24,6 @@
#include "frontends/Alert.h"
#include "support/filename.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
@ -45,6 +44,7 @@ using support::changeExtension;
using support::contains;
using support::copy;
using support::DocFileName;
using support::FileName;
using support::findtexfile;
using support::isFileReadable;
using support::latex_path;
@ -117,7 +117,7 @@ string normalize_name(Buffer const & buffer, OutputParams const & runparams,
string const & name, string const & ext)
{
string const fname = makeAbsPath(name, buffer.filePath());
if (absolutePath(name) || !isFileReadable(fname + ext))
if (absolutePath(name) || !isFileReadable(FileName(fname + ext)))
return name;
else if (!runparams.nice)
return fname;
@ -169,15 +169,17 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
string utf8input(to_utf8(input));
string database =
normalize_name(buffer, runparams, utf8input, ".bib");
string const in_file = database + ".bib";
string const try_in_file = makeAbsPath(database + ".bib", buffer.filePath());
bool const not_from_texmf = isFileReadable(FileName(try_in_file));
if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
isFileReadable(in_file)) {
not_from_texmf) {
// mangledFilename() needs the extension
database = removeExtension(DocFileName(in_file).mangledFilename());
string const out_file = makeAbsPath(database + ".bib",
buffer.getMasterBuffer()->temppath());
DocFileName const in_file = DocFileName(try_in_file);
database = removeExtension(in_file.mangledFilename());
FileName const out_file = FileName(makeAbsPath(database + ".bib",
buffer.getMasterBuffer()->temppath()));
bool const success = copy(in_file, out_file);
if (!success) {
@ -222,18 +224,19 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
if (!style.empty()) {
string base =
normalize_name(buffer, runparams, style, ".bst");
string const in_file = base + ".bst";
string const try_in_file = makeAbsPath(base + ".bst", buffer.filePath());
bool const not_from_texmf = isFileReadable(FileName(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
// in the file name.
if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
isFileReadable(in_file)) {
not_from_texmf) {
// use new style name
base = removeExtension(
DocFileName(in_file).mangledFilename());
string const out_file = makeAbsPath(base + ".bst",
buffer.getMasterBuffer()->temppath());
DocFileName const in_file = DocFileName(try_in_file);
base = removeExtension(in_file.mangledFilename());
FileName const out_file = FileName(makeAbsPath(base + ".bst",
buffer.getMasterBuffer()->temppath()));
bool const success = copy(in_file, out_file);
if (!success) {
lyxerr << "Failed to copy '" << in_file

View File

@ -70,11 +70,11 @@ namespace external {
TempName::TempName()
{
tempname_ = support::tempName(string(), "lyxext");
string const tempname = support::tempName(string(), "lyxext");
// FIXME: This is unsafe
support::unlink(tempname_);
support::unlink(support::FileName(tempname));
// must have an extension for the converter code to work correctly.
tempname_ += ".tmp";
tempname_ = support::FileName(tempname + ".tmp");
}
@ -529,7 +529,7 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams)
{
graphics::Params gparams;
gparams.filename = eparams.filename.absFilename();
gparams.filename = eparams.filename;
gparams.scale = eparams.lyxscale;
if (eparams.clipdata.clip)
gparams.bb = eparams.clipdata.bbox;
@ -791,9 +791,8 @@ namespace {
bool preview_wanted(InsetExternalParams const & params)
{
string const included_file = params.filename.absFilename();
return params.display == external::PreviewDisplay &&
support::isFileReadable(included_file);
support::isFileReadable(params.filename);
}
@ -815,7 +814,7 @@ void add_preview_and_start_loading(RenderMonitoredPreview & renderer,
if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
preview_wanted(params)) {
renderer.setAbsFile(params.filename.absFilename());
renderer.setAbsFile(params.filename);
docstring const snippet = latex_string(inset, buffer);
renderer.addPreview(snippet, buffer);
renderer.startLoading(buffer);
@ -832,7 +831,7 @@ void InsetExternal::addPreview(graphics::PreviewLoader & ploader) const
return;
if (preview_wanted(params())) {
ptr->setAbsFile(params_.filename.absFilename());
ptr->setAbsFile(params_.filename);
docstring const snippet = latex_string(*this, ploader.buffer());
ptr->addPreview(snippet, ploader);
}

View File

@ -41,9 +41,9 @@ public:
TempName(TempName const &);
~TempName();
TempName & operator=(TempName const &);
std::string const & operator()() const { return tempname_; }
support::FileName const & operator()() const { return tempname_; }
private:
std::string tempname_;
support::FileName tempname_;
};
/// How is the image to be displayed on the LyX screen?
@ -72,7 +72,7 @@ public:
bool read(Buffer const &, LyXLex &);
/// The name of the tempfile used for manipulations.
std::string const & tempname() const { return tempname_(); }
support::FileName const & tempname() const { return tempname_(); }
/// The template currently in use.
void settemplate(std::string const &);

View File

@ -90,12 +90,12 @@ TODO
namespace lyx {
using support::absolutePath;
using support::bformat;
using support::changeExtension;
using support::compare_timestamps;
using support::contains;
using support::DocFileName;
using support::FileName;
using support::float_equal;
using support::getExtension;
using support::isFileReadable;
@ -453,12 +453,9 @@ enum CopyStatus {
};
std::pair<CopyStatus, string> const
copyFileIfNeeded(string const & file_in, string const & file_out)
std::pair<CopyStatus, FileName> const
copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
{
BOOST_ASSERT(absolutePath(file_in));
BOOST_ASSERT(absolutePath(file_out));
unsigned long const checksum_in = support::sum(file_in);
unsigned long const checksum_out = support::sum(file_out);
@ -473,7 +470,7 @@ copyFileIfNeeded(string const & file_in, string const & file_out)
lyxerr[Debug::GRAPHICS]
<< to_utf8(support::bformat(_("Could not copy the file\n%1$s\n"
"into the temporary directory."),
from_utf8(file_in)))
from_utf8(file_in.absFilename())))
<< std::endl;
}
@ -482,7 +479,7 @@ copyFileIfNeeded(string const & file_in, string const & file_out)
}
std::pair<CopyStatus, string> const
std::pair<CopyStatus, FileName> const
copyToDirIfNeeded(DocFileName const & file, string const & dir)
{
using support::rtrim;
@ -506,7 +503,7 @@ copyToDirIfNeeded(DocFileName const & file, string const & dir)
}
string const file_out = support::makeAbsPath(mangled, dir);
return copyFileIfNeeded(file_in, file_out);
return copyFileIfNeeded(file, FileName(file_out));
}
@ -563,7 +560,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
// temp_file will contain the file for LaTeX to act on if, for example,
// we move it to a temp dir or uncompress it.
string temp_file = orig_file;
FileName temp_file = params().filename;
// The master buffer. This is useful when there are multiple levels
// of include files
@ -573,7 +570,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
// not exist.
// We are not going to change the extension or using the name of the
// temporary file, the code is already complicated enough.
if (runparams.inComment || !isFileReadable(orig_file))
if (runparams.inComment || !isFileReadable(params().filename))
return params().filename.outputFilename(m_buffer->filePath());
// We place all temporary files in the master buffer's temp dir.
@ -594,8 +591,8 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
// run through the LaTeX compiler.
string output_file = support::os::external_path(runparams.nice ?
params().filename.outputFilename(m_buffer->filePath()) :
onlyFilename(temp_file));
string source_file = runparams.nice ? orig_file : temp_file;
onlyFilename(temp_file.absFilename()));
FileName source_file = runparams.nice ? FileName(params().filename) : temp_file;
string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
"latex" : "pdflatex";
@ -611,7 +608,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
lyxerr[Debug::GRAPHICS]
<< "\tpass zipped file to LaTeX.\n";
string const bb_orig_file = changeExtension(orig_file, "bb");
FileName const bb_orig_file = FileName(changeExtension(orig_file, "bb"));
if (runparams.nice) {
runparams.exportdata->addExternalFile(tex_format,
bb_orig_file,
@ -619,7 +616,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
} else {
// LaTeX needs the bounding box file in the
// tmp dir
string bb_file = changeExtension(temp_file, "bb");
FileName bb_file = FileName(changeExtension(temp_file.absFilename(), "bb"));
boost::tie(status, bb_file) =
copyFileIfNeeded(bb_orig_file, bb_file);
if (status == FAILURE)
@ -637,9 +634,10 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
support::EXCLUDE_EXTENSION);
}
string const unzipped_temp_file = unzippedFileName(temp_file);
FileName const unzipped_temp_file =
FileName(unzippedFileName(temp_file.absFilename()));
output_file = unzippedFileName(output_file);
source_file = unzippedFileName(source_file);
source_file = FileName(unzippedFileName(source_file.absFilename()));
if (compare_timestamps(unzipped_temp_file, temp_file) > 0) {
// temp_file has been unzipped already and
// orig_file has not changed in the meantime.
@ -673,15 +671,15 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
<< "\tthe orig file is: " << orig_file << endl;
if (from == to) {
if (!runparams.nice && getExtension(temp_file) != ext) {
if (!runparams.nice && getExtension(temp_file.absFilename()) != ext) {
// The LaTeX compiler will not be able to determine
// the file format from the extension, so we must
// change it.
string const new_file = changeExtension(temp_file, ext);
FileName const new_file = FileName(changeExtension(temp_file.absFilename(), ext));
if (support::rename(temp_file, new_file)) {
temp_file = new_file;
output_file = changeExtension(output_file, ext);
source_file = changeExtension(source_file, ext);
source_file = FileName(changeExtension(source_file.absFilename(), ext));
} else
lyxerr[Debug::GRAPHICS]
<< "Could not rename file `"
@ -696,7 +694,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
return stripExtensionIfPossible(output_file, to);
}
string const to_file = changeExtension(temp_file, ext);
FileName const to_file = FileName(changeExtension(temp_file.absFilename(), ext));
string const output_to_file = changeExtension(output_file, ext);
// Do we need to perform the conversion?
@ -722,7 +720,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
// FIXME (Abdel 12/08/06): Is there a need to show these errors?
ErrorList el;
if (converters.convert(&buf, temp_file, to_file, orig_file,
if (converters.convert(&buf, temp_file, to_file, params().filename,
from, to, el,
Converters::try_default | Converters::try_cache)) {
runparams.exportdata->addExternalFile(tex_format,
@ -747,8 +745,8 @@ int InsetGraphics::latex(Buffer const & buf, odocstream & os,
string const relative_file =
params().filename.relFilename(buf.filePath());
string const file_ = params().filename.absFilename();
bool const file_exists = !file_.empty() && isFileReadable(file_);
bool const file_exists = !params().filename.empty() &&
isFileReadable(params().filename);
string const message = file_exists ?
string() : string("bb = 0 0 200 100, draft, type=eps");
// if !message.empty() then there was no existing file
@ -866,10 +864,10 @@ int InsetGraphics::docbook(Buffer const &, odocstream & os,
// easier to use.
if (runparams.flavor == OutputParams::XML) {
runparams.exportdata->addExternalFile("docbook-xml",
params().filename.absFilename());
params().filename);
} else {
runparams.exportdata->addExternalFile("docbook",
params().filename.absFilename());
params().filename);
}
os << "<inlinemediaobject>";
@ -934,9 +932,8 @@ InsetGraphicsParams const & InsetGraphics::params() const
void InsetGraphics::editGraphics(InsetGraphicsParams const & p,
Buffer const & buffer) const
{
string const file_with_path = p.filename.absFilename();
formats.edit(buffer, file_with_path,
formats.getFormatFromFile(file_with_path));
formats.edit(buffer, p.filename,
formats.getFormatFromFile(p.filename));
}

View File

@ -266,7 +266,7 @@ bool InsetGraphicsParams::Read(LyXLex & lex, string const & token, string const
graphics::Params InsetGraphicsParams::as_grfxParams() const
{
graphics::Params pars;
pars.filename = filename.absFilename();
pars.filename = filename;
pars.scale = lyxscale;
pars.angle = convert<double>(rotateAngle);
@ -274,7 +274,7 @@ graphics::Params InsetGraphicsParams::as_grfxParams() const
pars.bb = bb;
// Get the original Bounding Box from the file
string const tmp = readBB_from_PSFile(filename.absFilename());
string const tmp = readBB_from_PSFile(filename);
lyxerr[Debug::GRAPHICS] << "BB_from_File: " << tmp << std::endl;
if (!tmp.empty()) {
#ifdef WITH_WARNINGS

View File

@ -40,7 +40,6 @@
#include "insets/render_preview.h"
#include "support/filename.h"
#include "support/filetools.h"
#include "support/lstrings.h" // contains
#include "support/lyxalgo.h"
@ -60,6 +59,7 @@ using support::changeExtension;
using support::contains;
using support::copy;
using support::DocFileName;
using support::FileName;
using support::getFileContents;
using support::isFileReadable;
using support::isLyXFilename;
@ -378,21 +378,21 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
if (incfile.empty())
return 0;
string const included_file = includedFilename(buffer, params_);
FileName const included_file(includedFilename(buffer, params_));
Buffer const * const m_buffer = buffer.getMasterBuffer();
// if incfile is relative, make it relative to the master
// buffer directory.
if (!absolutePath(incfile)) {
incfile = makeRelPath(included_file,
incfile = makeRelPath(included_file.absFilename(),
m_buffer->filePath());
}
// write it to a file (so far the complete file)
string const exportfile = changeExtension(incfile, ".tex");
string const mangled = DocFileName(changeExtension(included_file,
string const mangled = DocFileName(changeExtension(included_file.absFilename(),
".tex")).mangledFilename();
string const writefile = makeAbsPath(mangled, m_buffer->temppath());
FileName const writefile(makeAbsPath(mangled, m_buffer->temppath()));
if (!runparams.nice)
incfile = mangled;
@ -404,14 +404,14 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
// Don't try to load or copy the file
;
else if (loadIfNeeded(buffer, params_)) {
Buffer * tmp = theBufferList().getBuffer(included_file);
Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
if (tmp->params().textclass != m_buffer->params().textclass) {
// FIXME UNICODE
docstring text = bformat(_("Included file `%1$s'\n"
"has textclass `%2$s'\n"
"while parent file has textclass `%3$s'."),
makeDisplayPath(included_file),
makeDisplayPath(included_file.absFilename()),
from_utf8(tmp->params().getLyXTextClass().name()),
from_utf8(m_buffer->params().getLyXTextClass().name()));
Alert::warning(_("Different textclasses"), text);
@ -427,7 +427,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
// argument. Should we set it to string(), or should makeLaTeXFile
// make use of it somehow? (JMarc 20031002)
#endif
tmp->makeLaTeXFile(writefile,
tmp->makeLaTeXFile(writefile.absFilename(),
onlyPath(masterFilename(buffer)),
runparams, false);
} else {
@ -443,7 +443,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
lyxerr[Debug::LATEX]
<< to_utf8(bformat(_("Could not copy the file\n%1$s\n"
"into the temporary directory."),
from_utf8(included_file)))
from_utf8(included_file.absFilename())))
<< endl;
return 0;
}
@ -462,7 +462,7 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
exportfile);
// \input wants file with extension (default is .tex)
if (!isLyXFilename(included_file)) {
if (!isLyXFilename(included_file.absFilename())) {
incfile = latex_path(incfile);
// FIXME UNICODE
os << '\\' << from_ascii(params_.getCmdName())
@ -497,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(includedFilename(buffer, params_)));
getFileContents(FileName(includedFilename(buffer, params_))));
os << str;
// Return how many newlines we issued.
return int(lyx::count(str.begin(), str.end(), '\n'));
@ -519,12 +519,12 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
// write it to a file (so far the complete file)
string const exportfile = changeExtension(incfile, ".sgml");
string writefile = changeExtension(included_file, ".sgml");
DocFileName writefile(changeExtension(included_file, ".sgml"));
if (loadIfNeeded(buffer, params_)) {
Buffer * tmp = theBufferList().getBuffer(included_file);
string const mangled = DocFileName(writefile).mangledFilename();
string const mangled = writefile.mangledFilename();
writefile = makeAbsPath(mangled,
buffer.getMasterBuffer()->temppath());
if (!runparams.nice)
@ -534,7 +534,7 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
tmp->makeDocBookFile(writefile, runparams, true);
tmp->makeDocBookFile(writefile.absFilename(), runparams, true);
}
runparams.exportdata->addExternalFile("docbook", writefile,
@ -727,7 +727,7 @@ bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
string const included_file = includedFilename(buffer, params);
return type(params) == INPUT && params.preview() &&
isFileReadable(included_file);
isFileReadable(FileName(included_file));
}
@ -748,7 +748,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(includedFilename(buffer, params));
renderer.setAbsFile(FileName(includedFilename(buffer, params)));
docstring const snippet = latex_string(inset, buffer);
renderer.addPreview(snippet, buffer);
}
@ -761,7 +761,7 @@ void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const
{
Buffer const & buffer = ploader.buffer();
if (preview_wanted(params(), buffer)) {
preview_->setAbsFile(includedFilename(buffer, params()));
preview_->setAbsFile(FileName(includedFilename(buffer, params())));
docstring const snippet = latex_string(*this, buffer);
preview_->addPreview(snippet, ploader);
}

View File

@ -32,7 +32,6 @@
namespace lyx {
using support::absolutePath;
using support::onlyFilename;
using std::string;
@ -68,7 +67,6 @@ void RenderGraphic::update(graphics::Params const & params)
params_ = params;
if (!params_.filename.empty()) {
BOOST_ASSERT(absolutePath(params_.filename));
loader_.reset(params_.filename, params_);
}
}
@ -160,7 +158,7 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const
// FIXME UNICODE
docstring const justname =
from_utf8(onlyFilename(params_.filename));
from_utf8(onlyFilename(params_.filename.absFilename()));
if (!justname.empty()) {
msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
font_width = theFontMetrics(msgFont)
@ -210,7 +208,7 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
// Print the file name.
LyXFont msgFont = pi.base.font;
msgFont.setFamily(LyXFont::SANS_FAMILY);
string const justname = onlyFilename(params_.filename);
string const justname = onlyFilename(params_.filename.absFilename());
if (!justname.empty()) {
msgFont.setSize(LyXFont::SIZE_FOOTNOTE);

View File

@ -28,6 +28,7 @@
#include "graphics/PreviewLoader.h"
#include "graphics/Previews.h"
#include "support/filename.h"
#include "support/lstrings.h"
#include <boost/bind.hpp>
@ -35,6 +36,8 @@
namespace lyx {
using support::FileName;
using std::string;
using std::auto_ptr;
@ -238,11 +241,11 @@ void RenderPreview::imageReady(graphics::PreviewImage const & pimage)
RenderMonitoredPreview::RenderMonitoredPreview(InsetBase const * inset)
: RenderPreview(inset),
monitor_(std::string(), 2000)
monitor_(FileName(), 2000)
{}
void RenderMonitoredPreview::setAbsFile(string const & file)
void RenderMonitoredPreview::setAbsFile(FileName const & file)
{
monitor_.reset(file);
}

View File

@ -32,6 +32,8 @@ class LyXRC_PreviewStatus;
class MetricsInfo;
class PainterInfo;
namespace support { class FileName; }
namespace graphics {
class PreviewImage;
@ -108,7 +110,7 @@ public:
///
void draw(PainterInfo & pi, int x, int y) const;
///
void setAbsFile(std::string const & file);
void setAbsFile(support::FileName const & file);
///
bool monitoring() const { return monitor_.monitoring(); }
void startMonitoring() const { monitor_.start(); }

View File

@ -29,6 +29,7 @@
namespace lyx {
using support::FileName;
using support::i18nLibFileSearch;
using std::endl;
@ -106,7 +107,7 @@ bool kb_keymap::read(string const & bind_file)
if (lyxerr.debugging(Debug::PARSER))
lexrc.printTable(lyxerr);
string const tmp = i18nLibFileSearch("bind", bind_file, "bind");
FileName const tmp(i18nLibFileSearch("bind", bind_file, "bind"));
lexrc.setFile(tmp);
if (!lexrc.isOK()) {
lyxerr << "kb_keymap::read: cannot open bind file:"

View File

@ -19,6 +19,8 @@
#include "lyxlex.h"
#include "lyxrc.h"
#include "support/filename.h"
namespace lyx {
@ -35,7 +37,7 @@ Language latex_lang("latex", "latex", "Latex", false, "", 0, "latex", "");
Language const * latex_language = &latex_lang;
void Languages::read(string const & filename)
void Languages::read(support::FileName const & filename)
{
// We need to set the encoding of latex_lang
latex_lang = Language("latex", "latex", "Latex", false, "iso8859-1",

View File

@ -21,6 +21,7 @@
namespace lyx {
namespace support { class FileName; }
class Encoding;
@ -81,7 +82,7 @@ public:
///
typedef LanguageList::size_type size_type;
///
void read(std::string const & filename);
void read(support::FileName const & filename);
///
Language const * getLanguage(std::string const & language) const;
///

View File

@ -62,6 +62,7 @@ namespace lyx {
using support::addName;
using support::bformat;
using support::FileFilterList;
using support::FileName;
using support::ForkedProcess;
using support::isLyXFilename;
using support::libFileSearch;
@ -193,7 +194,7 @@ namespace {
class AutoSaveBuffer : public ForkedProcess {
public:
///
AutoSaveBuffer(BufferView & bv, string const & fname)
AutoSaveBuffer(BufferView & bv, FileName const & fname)
: bv_(bv), fname_(fname) {}
///
virtual shared_ptr<ForkedProcess> clone() const
@ -207,13 +208,13 @@ private:
virtual int generateChild();
///
BufferView & bv_;
string fname_;
FileName fname_;
};
int AutoSaveBuffer::start()
{
command_ = to_utf8(bformat(_("Auto-saving %1$s"), from_utf8(fname_)));
command_ = to_utf8(bformat(_("Auto-saving %1$s"), from_utf8(fname_.absFilename())));
return run(DontWait);
}
@ -231,9 +232,9 @@ int AutoSaveBuffer::generateChild()
// anyway.
bool failed = false;
string const tmp_ret = tempName(string(), "lyxauto");
FileName const tmp_ret(tempName(string(), "lyxauto"));
if (!tmp_ret.empty()) {
bv_.buffer()->writeFile(tmp_ret);
bv_.buffer()->writeFile(tmp_ret.absFilename());
// assume successful write of tmp_ret
if (!rename(tmp_ret, fname_)) {
failed = true;
@ -248,7 +249,7 @@ int AutoSaveBuffer::generateChild()
if (failed) {
// failed to write/rename tmp_ret so try writing direct
if (!bv_.buffer()->writeFile(fname_)) {
if (!bv_.buffer()->writeFile(fname_.absFilename())) {
// It is dangerous to do this in the child,
// but safe in the parent, so...
if (pid == -1)
@ -288,7 +289,7 @@ void autoSave(BufferView * bv)
fname += onlyFilename(bv->buffer()->fileName());
fname += '#';
AutoSaveBuffer autosave(*bv, fname);
AutoSaveBuffer autosave(*bv, FileName(fname));
autosave.start();
bv->buffer()->markBakClean();

View File

@ -74,6 +74,7 @@ using support::bformat;
using support::createDirectory;
using support::createLyXTmpDir;
using support::destroyDir;
using support::FileName;
using support::fileSearch;
using support::getEnv;
using support::i18nLibFileSearch;
@ -480,7 +481,7 @@ int LyX::loadFiles(int & argc, char * argv[],
}
if (first_start)
files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
files.push_back(i18nLibFileSearch("examples", "splash.lyx").absFilename());
Buffer * last_loaded = 0;
@ -490,7 +491,7 @@ int LyX::loadFiles(int & argc, char * argv[],
for (; it != end; ++it) {
// get absolute path of file and add ".lyx" to
// the filename if necessary
string s = fileSearch(string(), *it, "lyx");
string s = fileSearch(string(), *it, "lyx").absFilename();
if (s.empty()) {
Buffer * const b = newFile(*it, string(), true);
if (b)
@ -820,7 +821,7 @@ bool LyX::init()
fs::is_directory(lyxrc.document_path))
package().document_dir() = lyxrc.document_path;
package().temp_dir() = createLyXTmpDir(lyxrc.tempdir_path);
package().temp_dir() = createLyXTmpDir(FileName(lyxrc.tempdir_path)).absFilename();
if (package().temp_dir().empty()) {
Alert::error(_("Could not create temporary directory"),
bformat(_("Could not create a temporary directory in\n"
@ -1011,7 +1012,7 @@ bool LyX::readRcFile(string const & name)
{
lyxerr[Debug::INIT] << "About to read " << name << "... ";
string const lyxrc_path = libFileSearch(string(), name);
FileName const lyxrc_path = libFileSearch(string(), name);
if (!lyxrc_path.empty()) {
lyxerr[Debug::INIT] << "Found in " << lyxrc_path << endl;
@ -1060,7 +1061,7 @@ bool LyX::readUIFile(string const & name)
lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
string const ui_path = libFileSearch("ui", name, "ui");
FileName const ui_path = libFileSearch("ui", name, "ui");
if (ui_path.empty()) {
lyxerr[Debug::INIT] << "Could not find " << name << endl;
@ -1118,7 +1119,7 @@ bool LyX::readLanguagesFile(string const & name)
{
lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
string const lang_path = libFileSearch(string(), name);
FileName const lang_path = libFileSearch(string(), name);
if (lang_path.empty()) {
showFileError(name);
return false;
@ -1133,7 +1134,7 @@ bool LyX::readEncodingsFile(string const & name)
{
lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
string const enc_path = libFileSearch(string(), name);
FileName const enc_path = libFileSearch(string(), name);
if (enc_path.empty()) {
showFileError(name);
return false;

View File

@ -113,6 +113,7 @@ using support::bformat;
using support::changeExtension;
using support::contains;
using support::FileFilterList;
using support::FileName;
using support::fileSearch;
using support::ForkedcallsController;
using support::i18nLibFileSearch;
@ -540,7 +541,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
else if (name == "character" || name == "mathpanel")
enable = cur.inset().lyxCode() != InsetBase::ERT_CODE;
else if (name == "latexlog")
enable = isFileReadable(buf->getLogName().second);
enable = isFileReadable(FileName(buf->getLogName().second));
#if !defined (USE_ASPELL) && !defined (USE_ISPELL) && !defined (USE_PSPELL)
else if (name == "spellchecker")
enable = false;
@ -1075,7 +1076,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
setErrorMessage(_("Missing argument"));
break;
}
string const fname = i18nLibFileSearch("doc", arg, "lyx");
string const fname = i18nLibFileSearch("doc", arg, "lyx").absFilename();
if (fname.empty()) {
lyxerr << "LyX: unable to find documentation file `"
<< arg << "'. Bad installation?" << endl;
@ -1881,7 +1882,7 @@ void LyXFunc::open(string const & fname)
// get absolute path of file and add ".lyx" to the filename if
// necessary
string const fullpath = fileSearch(string(), filename, "lyx");
string const fullpath = fileSearch(string(), filename, "lyx").absFilename();
if (!fullpath.empty()) {
filename = fullpath;
}

View File

@ -99,7 +99,7 @@ void LyXLex::printError(string const & message) const
}
bool LyXLex::setFile(string const & filename)
bool LyXLex::setFile(support::FileName const & filename)
{
return pimpl_->setFile(filename);
}

View File

@ -26,6 +26,7 @@
namespace lyx {
namespace support { class FileName; }
///
struct keyword_item {
@ -66,7 +67,7 @@ public:
/// stream is not ok
bool operator!() const;
/// return true if able to open file, else false
bool setFile(std::string const & filename);
bool setFile(support::FileName const & filename);
///
void setStream(std::istream & is);
///

View File

@ -28,6 +28,7 @@
namespace lyx {
using support::compare_ascii_no_case;
using support::FileName;
using support::getFormatFromContents;
using support::makeDisplayPath;
using support::split;
@ -143,7 +144,7 @@ void LyXLex::Pimpl::popTable()
}
bool LyXLex::Pimpl::setFile(string const & filename)
bool LyXLex::Pimpl::setFile(FileName const & filename)
{
// Check the format of the file.
string const format = getFormatFromContents(filename);
@ -158,9 +159,9 @@ bool LyXLex::Pimpl::setFile(string const & filename)
lyxerr[Debug::LYXLEX] << "Error in LyXLex::setFile: "
"file or stream already set." << endl;
gz_.push(io::gzip_decompressor());
gz_.push(io::file_source(filename));
gz_.push(io::file_source(filename.toFilesystemEncoding()));
is.rdbuf(&gz_);
name = filename;
name = filename.absFilename();
lineno = 0;
return gz_.component<io::file_source>(1)->is_open() && is.good();
} else {
@ -172,9 +173,9 @@ bool LyXLex::Pimpl::setFile(string const & filename)
if (fb_.is_open() || istream::off_type(is.tellg()) > 0)
lyxerr[Debug::LYXLEX] << "Error in LyXLex::setFile: "
"file or stream already set." << endl;
fb_.open(filename.c_str(), ios::in);
fb_.open(filename.toFilesystemEncoding().c_str(), ios::in);
is.rdbuf(&fb_);
name = filename;
name = filename.absFilename();
lineno = 0;
return fb_.is_open() && is.good();
}

View File

@ -31,6 +31,8 @@ namespace io = boost::iostreams;
namespace lyx {
namespace support { class FileName; }
///
class LyXLex::Pimpl : boost::noncopyable {
public:
@ -49,7 +51,7 @@ public:
///
void popTable();
///
bool setFile(std::string const & filename);
bool setFile(support::FileName const & filename);
///
void setStream(std::istream & i);
///

View File

@ -48,6 +48,7 @@ namespace os = support::os;
using support::ascii_lowercase;
using support::bformat;
using support::expandPath;
using support::FileName;
using support::getEnv;
using support::libFileSearch;
using support::token;
@ -315,7 +316,7 @@ void oldFontFormat(string & family, string & foundry)
} // namespace anon
int LyXRC::read(string const & filename)
int LyXRC::read(FileName const & filename)
{
LyXLex lexrc(lyxrcTags, lyxrcCount);
if (lyxerr.debugging(Debug::PARSER))
@ -369,12 +370,12 @@ int LyXRC::read(LyXLex & lexrc)
switch (static_cast<LyXRCTags>(le)) {
case RC_INPUT: // Include file
if (lexrc.next()) {
string const tmp =
FileName const tmp =
libFileSearch(string(),
lexrc.getString());
if (read(tmp)) {
lexrc.printError("Error reading "
"included file: "+tmp);
"included file: " + tmp.absFilename());
}
}
break;

View File

@ -27,6 +27,8 @@
namespace lyx {
namespace support { class FileName; }
class LyXLex;
/// This contains the runtime configuration of LyX
@ -152,7 +154,7 @@ public:
///
void setDefaults();
///
int read(std::string const & filename);
int read(support::FileName const & filename);
///
int read(std::istream &);
private:

View File

@ -45,6 +45,8 @@
#include "LyXAction.h"
#include "lyxfunc.h"
#include "frontends/Application.h"
#include "support/filename.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
@ -60,6 +62,7 @@
namespace lyx {
using support::compare;
using support::FileName;
using support::rtrim;
using support::split;
using support::unlink;
@ -166,9 +169,10 @@ void LyXComm::closeConnection()
}
int LyXComm::startPipe(string const & filename, bool write)
int LyXComm::startPipe(string const & file, bool write)
{
if (::access(filename.c_str(), F_OK) == 0) {
FileName const filename(file);
if (::access(filename.toFilesystemEncoding().c_str(), F_OK) == 0) {
lyxerr << "LyXComm: Pipe " << filename << " already exists.\n"
<< "If no other LyX program is active, please delete"
" the pipe by hand and try again." << endl;
@ -176,12 +180,12 @@ int LyXComm::startPipe(string const & filename, bool write)
return -1;
}
if (::mkfifo(filename.c_str(), 0600) < 0) {
if (::mkfifo(filename.toFilesystemEncoding().c_str(), 0600) < 0) {
lyxerr << "LyXComm: Could not create pipe " << filename << '\n'
<< strerror(errno) << endl;
return -1;
};
int const fd = ::open(filename.c_str(),
int const fd = ::open(filename.toFilesystemEncoding().c_str(),
write ? (O_RDWR) : (O_RDONLY|O_NONBLOCK));
if (fd < 0) {
@ -214,7 +218,7 @@ void LyXComm::endPipe(int & fd, string const & filename, bool write)
<< '\n' << strerror(errno) << endl;
}
if (unlink(filename) < 0) {
if (unlink(FileName(filename)) < 0) {
lyxerr << "LyXComm: Could not remove pipe " << filename
<< '\n' << strerror(errno) << endl;
};

View File

@ -24,6 +24,7 @@
#include "frontends/Application.h"
#include "support/environment.h"
#include "support/filename.h"
#include "support/lyxlib.h"
#include "support/socktools.h"
@ -83,7 +84,7 @@ LyXServerSocket::~LyXServerSocket()
lyxerr << "lyx: Server socket " << fd_
<< " IO error on closing: " << strerror(errno);
}
support::unlink(address_);
support::unlink(support::FileName(address_));
lyxerr[Debug::LYXSERVER] << "lyx: Server socket quitting" << endl;
}

View File

@ -34,6 +34,7 @@ namespace fs = boost::filesystem;
namespace lyx {
using support::FileName;
using support::libFileSearch;
using support::makeDisplayPath;
using support::quoteName;
@ -67,9 +68,9 @@ private:
int const FORMAT = 2;
bool layout2layout(string const & filename, string const & tempfile)
bool layout2layout(FileName const & filename, FileName const & tempfile)
{
string const script = libFileSearch("scripts", "layout2layout.py");
FileName const script = libFileSearch("scripts", "layout2layout.py");
if (script.empty()) {
lyxerr << "Could not find layout conversion "
"script layout2layout.py." << endl;
@ -77,9 +78,9 @@ bool layout2layout(string const & filename, string const & tempfile)
}
std::ostringstream command;
command << support::os::python() << ' ' << quoteName(script)
<< ' ' << quoteName(filename)
<< ' ' << quoteName(tempfile);
command << support::os::python() << ' ' << quoteName(script.toFilesystemEncoding())
<< ' ' << quoteName(filename.toFilesystemEncoding())
<< ' ' << quoteName(tempfile.toFilesystemEncoding());
string const command_str = command.str();
lyxerr[Debug::TCLASS] << "Running `" << command_str << '\'' << endl;
@ -173,7 +174,7 @@ enum TextClassTags {
// Reads a textclass structure from file.
bool LyXTextClass::read(string const & filename, bool merge)
bool LyXTextClass::read(FileName const & filename, bool merge)
{
if (!support::isFileReadable(filename)) {
lyxerr << "Cannot read layout file `" << filename << "'."
@ -213,11 +214,11 @@ bool LyXTextClass::read(string const & filename, bool merge)
if (!merge)
lyxerr[Debug::TCLASS] << "Reading textclass "
<< to_utf8(makeDisplayPath(filename))
<< to_utf8(makeDisplayPath(filename.absFilename()))
<< endl;
else
lyxerr[Debug::TCLASS] << "Reading input file "
<< to_utf8(makeDisplayPath(filename))
<< to_utf8(makeDisplayPath(filename.absFilename()))
<< endl;
LyXLex lexrc(textClassTags,
@ -260,7 +261,7 @@ bool LyXTextClass::read(string const & filename, bool merge)
case TC_INPUT: // Include file
if (lexrc.next()) {
string const inc = lexrc.getString();
string tmp = libFileSearch("layouts", inc,
FileName tmp = libFileSearch("layouts", inc,
"layout");
if (tmp.empty()) {
@ -269,7 +270,7 @@ bool LyXTextClass::read(string const & filename, bool merge)
error = true;
} else if (read(tmp, true)) {
lexrc.printError("Error reading input"
"file: "+tmp);
"file: " + tmp.absFilename());
error = true;
}
}
@ -444,7 +445,7 @@ bool LyXTextClass::read(string const & filename, bool merge)
if (format != FORMAT) {
lyxerr[Debug::TCLASS] << "Converting layout file from format "
<< format << " to " << FORMAT << endl;
string const tempfile = support::tempName();
FileName const tempfile(support::tempName());
error = !layout2layout(filename, tempfile);
if (!error)
error = read(tempfile, merge);
@ -454,7 +455,7 @@ bool LyXTextClass::read(string const & filename, bool merge)
if (!merge) { // we are at top level here.
lyxerr[Debug::TCLASS] << "Finished reading textclass "
<< to_utf8(makeDisplayPath(filename))
<< to_utf8(makeDisplayPath(filename.absFilename()))
<< endl;
if (defaultlayout_.empty()) {
lyxerr << "Error: Textclass '" << name_
@ -484,7 +485,7 @@ bool LyXTextClass::read(string const & filename, bool merge)
} else
lyxerr[Debug::TCLASS] << "Finished reading input file "
<< to_utf8(makeDisplayPath(filename))
<< to_utf8(makeDisplayPath(filename.absFilename()))
<< endl;
return error;
@ -925,16 +926,16 @@ bool LyXTextClass::load(string const & path) const
return true;
// Read style-file, provided path is searched before the system ones
string layout_file;
FileName layout_file;
if (!path.empty())
layout_file = addName(path, name_ + ".layout");
if (layout_file.empty() || !fs::exists(layout_file))
layout_file = FileName(addName(path, name_ + ".layout"));
if (layout_file.empty() || !fs::exists(layout_file.toFilesystemEncoding()))
layout_file = libFileSearch("layouts", name_, "layout");
loaded_ = const_cast<LyXTextClass*>(this)->read(layout_file) == 0;
if (!loaded_) {
lyxerr << "Error reading `"
<< to_utf8(makeDisplayPath(layout_file))
<< to_utf8(makeDisplayPath(layout_file.absFilename()))
<< "'\n(Check `" << name_
<< "')\nCheck your installation and "
"try Options/Reconfigure..." << endl;

View File

@ -20,6 +20,8 @@
namespace lyx {
namespace support { class FileName; }
class LyXLex;
class Counters;
class FloatList;
@ -65,7 +67,7 @@ public:
const_iterator end() const { return layoutlist_.end(); }
/// Performs the read of the layout file.
bool read(std::string const & filename, bool merge = false);
bool read(support::FileName const & filename, bool merge = false);
///
void readOutputType(LyXLex &);
///

View File

@ -99,13 +99,14 @@ public:
bool LyXTextClassList::read()
{
LyXLex lex(0, 0);
string real_file = libFileSearch("", "textclass.lst");
support::FileName const real_file = libFileSearch("", "textclass.lst");
lyxerr[Debug::TCLASS] << "Reading textclasses from `"
<< real_file << '\'' << endl;
if (real_file.empty()) {
lyxerr << "LyXTextClassList::Read: unable to find "
"textclass file `" << to_utf8(makeDisplayPath(real_file, 1000))
"textclass file `"
<< to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
<< "'. Exiting." << endl;
return false;
// This causes LyX to end... Not a desirable behaviour. Lgb
@ -123,7 +124,8 @@ bool LyXTextClassList::read()
if (!lex.isOK()) {
lyxerr << "LyXTextClassList::Read: unable to open "
"textclass file `" << to_utf8(makeDisplayPath(real_file, 1000))
"textclass file `"
<< to_utf8(makeDisplayPath(real_file.absFilename(), 1000))
<< "'\nCheck your installation. LyX can't continue."
<< endl;
return false;

View File

@ -30,7 +30,9 @@
namespace lyx {
using support::bformat;
using support::FileName;
using support::isFileReadable;
using support::makeAbsPath;
using support::makeDisplayPath;
using support::tempName;
@ -94,7 +96,7 @@ void LyXVC::registrer()
string const filename = owner_->fileName();
// there must be a file to save
if (!isFileReadable(filename)) {
if (!isFileReadable(FileName(makeAbsPath(filename)))) {
Alert::error(_("Document not saved"),
_("You must save the document "
"before it can be registered."));
@ -105,7 +107,7 @@ void LyXVC::registrer()
if (!vcs) {
string const cvs_entries = "CVS/Entries";
if (isFileReadable(cvs_entries)) {
if (isFileReadable(FileName(makeAbsPath(cvs_entries)))) {
lyxerr[Debug::LYXVC]
<< "LyXVC: registering "
<< to_utf8(makeDisplayPath(filename))

View File

@ -146,14 +146,14 @@ Corrections theCorrections;
void initAutoCorrect()
{
lyxerr[Debug::MATHED] << "reading autocorrect file" << endl;
string const file = libFileSearch(string(), "autocorrect");
support::FileName const file = libFileSearch(string(), "autocorrect");
if (file.empty()) {
lyxerr << "Could not find autocorrect file" << endl;
return;
}
string line;
ifstream is(file.c_str());
ifstream is(file.toFilesystemEncoding().c_str());
while (getline(is, line)) {
if (line.size() == 0 || line[0] == '#') {
//lyxerr[Debug::MATHED] << "ignoring line '" << line << '\'' << endl;

View File

@ -1414,14 +1414,14 @@ MathArray pipeThroughExtern(string const & lang, docstring const & extra,
string data = to_utf8(os.str());
// search external script
string file = libFileSearch("mathed", "extern_" + lang);
support::FileName const file = libFileSearch("mathed", "extern_" + lang);
if (file.empty()) {
lyxerr << "converter to '" << lang << "' not found" << endl;
return MathArray();
}
// run external sript
string out = captureOutput(file, data);
string out = captureOutput(file.absFilename(), data);
MathArray res;
mathed_parse_cell(res, from_utf8(out));
return res;

View File

@ -111,14 +111,14 @@ bool math_font_available(docstring & name)
void initSymbols()
{
string const filename = libFileSearch(string(), "symbols");
support::FileName const filename = libFileSearch(string(), "symbols");
lyxerr[Debug::MATHED] << "read symbols from " << filename << endl;
if (filename.empty()) {
lyxerr << "Could not find symbols file" << endl;
return;
}
std::ifstream fs(filename.c_str());
std::ifstream fs(filename.toFilesystemEncoding().c_str());
string line;
bool skip = false;
while (getline(fs, line)) {

View File

@ -30,28 +30,42 @@ Movers movers;
Movers system_movers;
bool Mover::do_copy(string const & from, string const & to,
bool Mover::copy(support::FileName const & from, support::FileName const & to,
unsigned long int mode) const
{
return do_copy(from, to, to.absFilename(), mode);
}
bool Mover::do_copy(support::FileName const & from, support::FileName const & to,
string const &, unsigned long int mode) const
{
return support::copy(from, to, mode);
}
bool Mover::do_rename(string const & from, string const & to,
bool Mover::rename(support::FileName const & from,
support::FileName const & to) const
{
return do_rename(from, to, to.absFilename());
}
bool Mover::do_rename(support::FileName const & from, support::FileName const & to,
string const &) const
{
return support::rename(from, to);
}
bool SpecialisedMover::do_copy(string const & from, string const & to,
bool SpecialisedMover::do_copy(support::FileName const & from, support::FileName const & to,
string const & latex, unsigned long int mode) const
{
if (command_.empty())
return Mover::do_copy(from, to, latex, mode);
if (mode != (unsigned long int)-1) {
std::ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
std::ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
if (!ofs)
return false;
ofs.close();
@ -60,8 +74,8 @@ bool SpecialisedMover::do_copy(string const & from, string const & to,
}
string command = support::libScriptSearch(command_);
command = support::subst(command, "$$i", from);
command = support::subst(command, "$$o", to);
command = support::subst(command, "$$i", from.toFilesystemEncoding());
command = support::subst(command, "$$o", to.toFilesystemEncoding());
command = support::subst(command, "$$l", latex);
support::Systemcall one;
@ -69,7 +83,7 @@ bool SpecialisedMover::do_copy(string const & from, string const & to,
}
bool SpecialisedMover::do_rename(string const & from, string const & to,
bool SpecialisedMover::do_rename(support::FileName const & from, support::FileName const & to,
string const & latex) const
{
if (command_.empty())

View File

@ -18,6 +18,8 @@
namespace lyx {
namespace support { class FileName; }
/**
* Utility to copy a file of a specified format from one place to another.
* This base class simply invokes the command support::copy().
@ -34,11 +36,8 @@ public:
* \returns true if successful.
*/
bool
copy(std::string const & from, std::string const & to,
unsigned long int mode = (unsigned long int)-1) const
{
return do_copy(from, to, to, mode);
}
copy(support::FileName const & from, support::FileName const & to,
unsigned long int mode = (unsigned long int)-1) const;
/** Copy file @c from to @c to.
* \see SpecialisedMover::SpecialisedMover() for an explanation of
@ -49,7 +48,7 @@ public:
* \returns true if successful.
*/
bool
copy(std::string const & from, std::string const & to,
copy(support::FileName const & from, support::FileName const & to,
std::string const & latex,
unsigned long int mode = (unsigned long int)-1) const
{
@ -63,10 +62,7 @@ public:
* \returns true if successful.
*/
bool
rename(std::string const & from, std::string const & to) const
{
return do_rename(from, to, to);
}
rename(support::FileName const & from, support::FileName const & to) const;
/** Rename file @c from as @c to.
* \see SpecialisedMover::SpecialisedMover() for an explanation of
@ -77,7 +73,7 @@ public:
* \returns true if successful.
*/
bool
rename(std::string const & from, std::string const & to,
rename(support::FileName const & from, support::FileName const & to,
std::string const & latex) const
{
return do_rename(from, to, latex);
@ -85,11 +81,11 @@ public:
protected:
virtual bool
do_copy(std::string const & from, std::string const & to,
do_copy(support::FileName const & from, support::FileName const & to,
std::string const &, unsigned long int mode) const;
virtual bool
do_rename(std::string const & from, std::string const & to,
do_rename(support::FileName const & from, support::FileName const & to,
std::string const &) const;
};
@ -132,11 +128,11 @@ public:
private:
virtual bool
do_copy(std::string const & from, std::string const & to,
do_copy(support::FileName const & from, support::FileName const & to,
std::string const & latex, unsigned long int mode) const;
virtual bool
do_rename(std::string const & from, std::string const & to,
do_rename(support::FileName const & from, support::FileName const & to,
std::string const & latex) const;
std::string command_;

View File

@ -11,6 +11,7 @@
#include <config.h>
#include "support/FileMonitor.h"
#include "support/filename.h"
#include "support/lyxlib.h"
// FIXME Interface violation
@ -32,13 +33,13 @@ class FileMonitor::Impl : public boost::signals::trackable {
public:
///
Impl(string const & file_with_path, int interval);
Impl(FileName const & file_with_path, int interval);
///
void monitorFile();
///
string filename_;
FileName filename_;
///
Timeout timer_;
@ -55,7 +56,7 @@ public:
};
FileMonitor::FileMonitor(string const & file_with_path, int interval)
FileMonitor::FileMonitor(FileName const & file_with_path, int interval)
: pimpl_(new Impl(file_with_path, interval))
{}
@ -64,7 +65,7 @@ FileMonitor::~FileMonitor()
{}
void FileMonitor::reset(string const & file_with_path) const
void FileMonitor::reset(FileName const & file_with_path) const
{
if (pimpl_->filename_ == file_with_path)
return;
@ -80,7 +81,7 @@ void FileMonitor::reset(string const & file_with_path) const
}
string const & FileMonitor::filename() const
FileName const & FileMonitor::filename() const
{
return pimpl_->filename_;
}
@ -91,10 +92,10 @@ void FileMonitor::start() const
if (monitoring())
return;
if (!fs::exists(pimpl_->filename_))
if (!fs::exists(pimpl_->filename_.toFilesystemEncoding()))
return;
pimpl_->timestamp_ = fs::last_write_time(pimpl_->filename_);
pimpl_->timestamp_ = fs::last_write_time(pimpl_->filename_.toFilesystemEncoding());
pimpl_->checksum_ = sum(pimpl_->filename_);
if (pimpl_->timestamp_ && pimpl_->checksum_) {
@ -142,7 +143,7 @@ boost::signals::connection FileMonitor::connect(slot_type const & slot) const
//------------------------------
FileMonitor::Impl::Impl(string const & file_with_path, int interval)
FileMonitor::Impl::Impl(FileName const & file_with_path, int interval)
: filename_(file_with_path),
timer_(interval, Timeout::ONETIME),
timestamp_(0),
@ -156,13 +157,13 @@ void FileMonitor::Impl::monitorFile()
{
bool changed = false;
if (!fs::exists(filename_)) {
if (!fs::exists(filename_.toFilesystemEncoding())) {
changed = timestamp_ || checksum_;
timestamp_ = 0;
checksum_ = 0;
} else {
time_t const new_timestamp = fs::last_write_time(filename_);
time_t const new_timestamp = fs::last_write_time(filename_.toFilesystemEncoding());
if (new_timestamp != timestamp_) {
timestamp_ = new_timestamp;

View File

@ -22,21 +22,23 @@
namespace lyx {
namespace support {
class FileName;
class FileMonitor : boost::noncopyable {
public:
/** Once monitoring begins, the file will be monitored every
* interval ms.
*/
FileMonitor(std::string const & file_with_path, int interval);
FileMonitor(FileName const & file_with_path, int interval);
/// Define an empty d-tor out-of-line to keep boost::scoped_ptr happy.
~FileMonitor();
///
void reset(std::string const & file_with_path) const;
void reset(FileName const & file_with_path) const;
///
std::string const & filename() const;
FileName const & filename() const;
/// Begin monitoring the file
void start() const;

View File

@ -12,6 +12,8 @@
#include "support/lyxlib.h"
#include "support/filename.h"
namespace lyx {
@ -23,12 +25,12 @@ namespace lyx {
# include <windows.h>
#endif
int lyx::support::chdir(std::string const & name)
int support::chdir(FileName const & name)
{
#ifdef _WIN32
return SetCurrentDirectory(name.c_str()) != 0 ? 0 : -1;
return SetCurrentDirectory(name.toFilesystemEncoding().c_str()) != 0 ? 0 : -1;
#else
return ::chdir(name.c_str());
return ::chdir(name.toFilesystemEncoding().c_str());
#endif
}

View File

@ -12,6 +12,7 @@
#include <fstream>
#include "support/filename.h"
#include "support/lyxlib.h"
#ifdef HAVE_SYS_STAT_H
@ -31,10 +32,10 @@ using std::ios;
using std::string;
bool lyx::support::chmod(string const & file, unsigned long int mode)
bool lyx::support::chmod(FileName const & file, unsigned long int mode)
{
#if defined (HAVE_CHMOD) && defined (HAVE_MODE_T)
if (::chmod(file.c_str(), mode_t(mode)) != 0)
if (::chmod(file.toFilesystemEncoding().c_str(), mode_t(mode)) != 0)
return false;
#else
# ifdef WITH_WARNINGS
@ -45,14 +46,14 @@ bool lyx::support::chmod(string const & file, unsigned long int mode)
}
bool lyx::support::copy(string const & from, string const & to, unsigned long int mode)
bool lyx::support::copy(FileName const & from, FileName const & to, unsigned long int mode)
{
ifstream ifs(from.c_str(), ios::binary | ios::in);
ifstream ifs(from.toFilesystemEncoding().c_str(), ios::binary | ios::in);
if (!ifs)
return false;
if (mode != (unsigned long int)-1) {
ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
if (!ofs)
return false;
ofs.close();
@ -60,7 +61,7 @@ bool lyx::support::copy(string const & from, string const & to, unsigned long in
return false;
}
ofstream ofs(to.c_str(), ios::binary | ios::out | ios::trunc);
ofstream ofs(to.toFilesystemEncoding().c_str(), ios::binary | ios::out | ios::trunc);
if (!ofs)
return false;

View File

@ -34,6 +34,10 @@ FileName::FileName()
{}
FileName::~FileName()
{}
FileName::FileName(string const & abs_filename)
: name_(abs_filename)
{
@ -41,6 +45,26 @@ FileName::FileName(string const & abs_filename)
}
void FileName::set(string const & name)
{
name_ = name;
BOOST_ASSERT(absolutePath(name_));
}
void FileName::erase()
{
name_.erase();
}
string const FileName::toFilesystemEncoding() const
{
// FIXME UNICODE: correct encoding not implemented yet
return name_;
}
bool operator==(FileName const & lhs, FileName const & rhs)
{
return lhs.absFilename() == rhs.absFilename();
@ -53,6 +77,24 @@ bool operator!=(FileName const & lhs, FileName const & rhs)
}
bool operator<(FileName const & lhs, FileName const & rhs)
{
return lhs.absFilename() < rhs.absFilename();
}
bool operator>(FileName const & lhs, FileName const & rhs)
{
return lhs.absFilename() > rhs.absFilename();
}
std::ostream & operator<<(std::ostream & os, FileName const & filename)
{
return os << filename.absFilename();
}
DocFileName::DocFileName()
: save_abs_path_(true)
{}
@ -149,7 +191,7 @@ string const DocFileName::mangledFilename(std::string const & dir) const
bool DocFileName::isZipped() const
{
if (!zipped_valid_) {
zipped_ = zippedFile(name_);
zipped_ = zippedFile(*this);
zipped_valid_ = true;
}
return zipped_;

View File

@ -25,18 +25,27 @@ namespace support {
* The file may or may not exist.
*/
class FileName {
protected:
/// Constructor for empty filenames (only needed for DocFileName)
FileName();
public:
/// Constructor for empty filenames
FileName();
/** Constructor for nonempty filenames.
* 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.
*/
FileName(std::string const & abs_filename);
explicit FileName(std::string const & abs_filename);
virtual ~FileName();
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
std::string const absFilename() const { return name_; }
/**
* Get the file name in the encoding used by the file system.
* Only use this for accessing the file, e.g. with an fstream.
*/
std::string const toFilesystemEncoding() const;
protected:
/// The absolute file name.
/// The encoding is currently unspecified, anything else than ASCII
@ -47,6 +56,9 @@ protected:
bool operator==(FileName const &, FileName const &);
bool operator!=(FileName const &, FileName const &);
bool operator<(FileName const &, FileName const &);
bool operator>(FileName const &, FileName const &);
std::ostream & operator<<(std::ostream &, FileName const &);
/**

View File

@ -156,9 +156,9 @@ string const quoteName(string const & name, quote_style style)
}
// Is a file readable ?
bool isFileReadable(string const & path)
bool isFileReadable(FileName const & filename)
{
std::string const path = filename.toFilesystemEncoding();
return fs::exists(path) && !fs::is_directory(path) && fs::is_readable(path);
}
@ -174,7 +174,7 @@ bool isDirWriteable(string const & path)
if (tmpfl.empty())
return false;
unlink(tmpfl);
unlink(FileName(tmpfl));
return true;
}
@ -184,10 +184,10 @@ bool isDirWriteable(string const & path)
// If path entry begins with $$LyX/, use system_lyxdir
// If path entry begins with $$User/, use user_lyxdir
// Example: "$$User/doc;$$LyX/doc"
string const fileOpenSearch(string const & path, string const & name,
FileName const fileOpenSearch(string const & path, string const & name,
string const & ext)
{
string real_file;
FileName real_file;
string path_element;
bool notfound = true;
string tmppath = split(path, path_element, ';');
@ -247,22 +247,20 @@ vector<string> const dirList(string const & dir, string const & ext)
// Returns the real name of file name in directory path, with optional
// extension ext.
string const fileSearch(string const & path, string const & name,
FileName const fileSearch(string const & path, string const & name,
string const & ext)
{
// if `name' is an absolute path, we ignore the setting of `path'
// Expand Environmentvariables in 'name'
string const tmpname = replaceEnvironmentPath(name);
string fullname = makeAbsPath(tmpname, path);
FileName fullname(makeAbsPath(tmpname, path));
// search first without extension, then with it.
if (isFileReadable(fullname))
return fullname;
if (ext.empty())
return string();
// Is it not more reasonable to use ChangeExtension()? (SMiyata)
fullname += '.';
fullname += ext;
return isFileReadable(fullname) ? fullname : string();
return FileName();
fullname = FileName(changeExtension(fullname.absFilename(), ext));
return isFileReadable(fullname) ? fullname : FileName();
}
@ -270,10 +268,10 @@ string const fileSearch(string const & path, string const & name,
// 1) user_lyxdir
// 2) build_lyxdir (if not empty)
// 3) system_lyxdir
string const libFileSearch(string const & dir, string const & name,
FileName const libFileSearch(string const & dir, string const & name,
string const & ext)
{
string fullname = fileSearch(addPath(package().user_support(), dir),
FileName fullname = fileSearch(addPath(package().user_support(), dir),
name, ext);
if (!fullname.empty())
return fullname;
@ -288,7 +286,7 @@ string const libFileSearch(string const & dir, string const & name,
}
string const i18nLibFileSearch(string const & dir, string const & name,
FileName const i18nLibFileSearch(string const & dir, string const & name,
string const & ext)
{
// the following comments are from intl/dcigettext.c. We try
@ -316,7 +314,7 @@ string const i18nLibFileSearch(string const & dir, string const & name,
string l;
lang = split(lang, l, ':');
while (!l.empty() && l != "C" && l != "POSIX") {
string const tmp = libFileSearch(dir,
FileName const tmp = libFileSearch(dir,
token(l, '_', 0) + '_' + name,
ext);
if (!tmp.empty())
@ -345,8 +343,8 @@ string const libScriptSearch(string const & command_in, quote_style style)
(command.size() - start_script) : pos2 - start_script;
// Does this script file exist?
string const script =
libFileSearch(".", command.substr(start_script, size_script));
string const script =
libFileSearch(".", command.substr(start_script, size_script)).absFilename();
if (script.empty()) {
// Replace "$$s/" with ""
@ -363,26 +361,26 @@ string const libScriptSearch(string const & command_in, quote_style style)
namespace {
string const createTmpDir(string const & tempdir, string const & mask)
FileName const createTmpDir(FileName const & tempdir, string const & mask)
{
lyxerr[Debug::FILES]
<< "createTmpDir: tempdir=`" << tempdir << "'\n"
<< "createTmpDir: mask=`" << mask << '\'' << endl;
string const tmpfl = tempName(tempdir, mask);
string const tmpfl = tempName(tempdir.absFilename(), 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(tmpfl);
unlink(FileName(tmpfl));
if (tmpfl.empty() || mkdir(tmpfl, 0700)) {
if (tmpfl.empty() || mkdir(FileName(tmpfl), 0700)) {
lyxerr << "LyX could not create the temporary directory '"
<< tmpfl << "'" << endl;
return string();
return FileName();
}
return makeAbsPath(tmpfl);
return FileName(tmpfl);
}
} // namespace anon
@ -409,7 +407,7 @@ string const createBufferTmpDir()
package().temp_dir() + "/lyx_tmpbuf" +
convert<string>(count++);
if (mkdir(tmpfl, 0777)) {
if (mkdir(FileName(tmpfl), 0777)) {
lyxerr << "LyX could not create the temporary directory '"
<< tmpfl << "'" << endl;
return string();
@ -418,23 +416,23 @@ string const createBufferTmpDir()
}
string const createLyXTmpDir(string const & deflt)
FileName const createLyXTmpDir(FileName const & deflt)
{
if (!deflt.empty() && deflt != "/tmp") {
if (!deflt.empty() && deflt.absFilename() != "/tmp") {
if (mkdir(deflt, 0777)) {
if (isDirWriteable(deflt)) {
if (isDirWriteable(deflt.absFilename())) {
// deflt could not be created because it
// did exist already, so let's create our own
// dir inside deflt.
return createTmpDir(deflt, "lyx_tmpdir");
} else {
// some other error occured.
return createTmpDir("/tmp", "lyx_tmpdir");
return createTmpDir(FileName("/tmp"), "lyx_tmpdir");
}
} else
return deflt;
} else {
return createTmpDir("/tmp", "lyx_tmpdir");
return createTmpDir(FileName("/tmp"), "lyx_tmpdir");
}
}
@ -443,7 +441,7 @@ bool createDirectory(string const & path, int permission)
{
string temp = rtrim(os::internal_path(path), "/");
BOOST_ASSERT(!temp.empty());
return mkdir(temp, permission) == 0;
return mkdir(FileName(temp), permission) == 0;
}
@ -608,10 +606,11 @@ string const normalizePath(string const & path)
}
string const getFileContents(string const & fname)
string const getFileContents(FileName const & fname)
{
if (fs::exists(fname)) {
ifstream ifs(fname.c_str());
string const encodedname = fname.toFilesystemEncoding();
if (fs::exists(encodedname)) {
ifstream ifs(encodedname.c_str());
ostringstream ofs;
if (ifs && ofs) {
ofs << ifs.rdbuf();
@ -790,13 +789,13 @@ string const getExtension(string const & name)
// ZIP PK... http://www.halyava.ru/document/ind_arch.htm
// Z \037\235 UNIX compress
string const getFormatFromContents(string const & filename)
string const getFormatFromContents(FileName const & filename)
{
// paranoia check
if (filename.empty() || !isFileReadable(filename))
return string();
ifstream ifs(filename.c_str());
ifstream ifs(filename.toFilesystemEncoding().c_str());
if (!ifs)
// Couldn't open file...
return string();
@ -943,7 +942,7 @@ string const getFormatFromContents(string const & filename)
/// check for zipped file
bool zippedFile(string const & name)
bool zippedFile(FileName const & name)
{
string const type = getFormatFromContents(name);
if (contains("gzip zip compress", type) && !type.empty())
@ -961,12 +960,15 @@ string const unzippedFileName(string const & zipped_file)
}
string const unzipFile(string const & zipped_file, string const & unzipped_file)
FileName const unzipFile(FileName const & zipped_file, string const & unzipped_file)
{
string const tempfile = unzipped_file.empty() ?
unzippedFileName(zipped_file) : unzipped_file;
FileName const tempfile = FileName(unzipped_file.empty() ?
unzippedFileName(zipped_file.toFilesystemEncoding()) :
unzipped_file);
// Run gunzip
string const command = "gunzip -c " + zipped_file + " > " + tempfile;
string const command = "gunzip -c " +
zipped_file.toFilesystemEncoding() + " > " +
tempfile.toFilesystemEncoding();
Systemcall one;
one.startscript(Systemcall::Wait, command);
// test that command was executed successfully (anon)
@ -1135,12 +1137,13 @@ void removeAutosaveFile(string const & filename)
a += '#';
a += onlyFilename(filename);
a += '#';
if (fs::exists(a))
unlink(a);
FileName const autosave(a);
if (fs::exists(autosave.toFilesystemEncoding()))
unlink(autosave);
}
void readBB_lyxerrMessage(string const & file, bool & zipped,
void readBB_lyxerrMessage(FileName const & file, bool & zipped,
string const & message)
{
lyxerr[Debug::GRAPHICS] << "[readBB_from_PSFile] "
@ -1153,7 +1156,7 @@ void readBB_lyxerrMessage(string const & file, bool & zipped,
}
string const readBB_from_PSFile(string const & file)
string const readBB_from_PSFile(FileName const & file)
{
// in a (e)ps-file it's an entry like %%BoundingBox:23 45 321 345
// It seems that every command in the header has an own line,
@ -1163,7 +1166,7 @@ string const readBB_from_PSFile(string const & file)
// %%BoundingBox: (atend)
// In this case we must check the end.
bool zipped = zippedFile(file);
string const file_ = zipped ? unzipFile(file) : file;
FileName const file_ = zipped ? unzipFile(file) : file;
string const format = getFormatFromContents(file_);
if (format != "eps" && format != "ps") {
@ -1173,7 +1176,7 @@ string const readBB_from_PSFile(string const & file)
static boost::regex bbox_re(
"^%%BoundingBox:\\s*([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)");
std::ifstream is(file_.c_str());
std::ifstream is(file_.toFilesystemEncoding().c_str());
while (is) {
string s;
getline(is,s);
@ -1196,14 +1199,13 @@ string const readBB_from_PSFile(string const & file)
}
int compare_timestamps(string const & file1, string const & file2)
int compare_timestamps(FileName const & filename1, FileName const & filename2)
{
BOOST_ASSERT(absolutePath(file1));
BOOST_ASSERT(absolutePath(file2));
// If the original is newer than the copy, then copy the original
// to the new directory.
string const file1 = filename1.toFilesystemEncoding();
string const file2 = filename2.toFilesystemEncoding();
int cmp = 0;
if (fs::exists(file1) && fs::exists(file2)) {
double const tmp = difftime(fs::last_write_time(file1),

View File

@ -13,6 +13,7 @@
#define LYX_FILETOOL_H
#include "support/docstring.h"
#include "support/filename.h"
#include <vector>
#include <utility>
@ -36,7 +37,7 @@ bool createDirectory(std::string const & name, int permissions);
created and used as the temporary directory.
\return the tmp dir name or string() if something went wrong.
*/
std::string const createLyXTmpDir(std::string const & deflt);
FileName const createLyXTmpDir(FileName const & deflt);
/** Find file by searching several directories.
Uses a string of paths separated by ";"s to find a file to open.
@ -45,7 +46,7 @@ std::string const createLyXTmpDir(std::string const & deflt);
If path entry begins with $$User/, use user_lyxdir.
Example: "$$User/doc;$$LyX/doc".
*/
std::string const fileOpenSearch(std::string const & path,
FileName const fileOpenSearch(std::string const & path,
std::string const & name,
std::string const & ext = std::string());
@ -54,7 +55,7 @@ std::string const fileOpenSearch(std::string const & path,
The file is searched in the given path (unless it is an absolute
file name), first directly, and then with extension .ext (if given).
*/
std::string const fileSearch(std::string const & path,
FileName const fileSearch(std::string const & path,
std::string const & name,
std::string const & ext = std::string());
@ -72,7 +73,7 @@ bool isDirWriteable(std::string const & path);
/** Is a file readable ?
Returns true if the file `path' is readable.
*/
bool isFileReadable (std::string const & path);
bool isFileReadable(FileName const & path);
///
bool isLyXFilename(std::string const & filename);
@ -87,7 +88,7 @@ bool isSGMLFilename(std::string const & filename);
-# system_lyxdir
The third parameter `ext' is optional.
*/
std::string const libFileSearch(std::string const & dir,
FileName const libFileSearch(std::string const & dir,
std::string const & name,
std::string const & ext = std::string());
@ -95,7 +96,7 @@ std::string const libFileSearch(std::string const & dir,
internationalized version of the file by prepending $LANG_ to the
name
*/
std::string const
FileName const
i18nLibFileSearch(std::string const & dir,
std::string const & name,
std::string const & ext = std::string());
@ -186,10 +187,10 @@ std::string const getExtension(std::string const & name);
Normally you don't want to use this directly, but rather
Formats::getFormatFromFile().
*/
std::string const getFormatFromContents(std::string const & name);
std::string const getFormatFromContents(FileName const & name);
/// check for zipped file
bool zippedFile(std::string const & name);
bool zippedFile(FileName const & name);
/** \return the name that LyX will give to the unzipped file \p zipped_file
if the second argument of unzipFile() is empty.
@ -201,8 +202,8 @@ std::string const unzippedFileName(std::string const & zipped_file);
empty, and unzippedFileName(\p zipped_file) otherwise.
Will overwrite an already existing unzipped file without warning.
*/
std::string const unzipFile(std::string const & zipped_file,
std::string const & unzipped_file = std::string());
FileName const unzipFile(FileName const & zipped_file,
std::string const & unzipped_file = std::string());
/// Returns true is path is absolute
bool absolutePath(std::string const & path);
@ -245,7 +246,7 @@ std::string const normalizePath(std::string const & path);
std::string const onlyFilename(std::string const & fname);
/// Get the contents of a file as a huge std::string
std::string const getFileContents(std::string const & fname);
std::string const getFileContents(FileName const & fname);
/** Check and Replace Environmentvariables ${NAME} in Path.
Replaces all occurences of these, if they are found in the
@ -269,7 +270,7 @@ std::string const findtexfile(std::string const & fil,
void removeAutosaveFile(std::string const & filename);
/// read the BoundingBox entry from a ps/eps/pdf-file
std::string const readBB_from_PSFile(std::string const & file);
std::string const readBB_from_PSFile(FileName const & file);
/** \param file1, file2 the two files to be compared. Must have absolute paths.
* \returns 1 if \c file1 has a more recent timestamp than \c file2,
@ -278,7 +279,7 @@ std::string const readBB_from_PSFile(std::string const & file);
* If one of the files does not exist, the return value indicates the file
* which does exist. Eg, if \c file1 exists but \c file2 does not, return 1.
*/
int compare_timestamps(std::string const & file1, std::string const & file2);
int compare_timestamps(FileName const & file1, FileName const & file2);
typedef std::pair<int, std::string> cmd_ret;

View File

@ -21,30 +21,32 @@
namespace lyx {
namespace support {
class FileName;
/// get the current working directory
std::string const getcwd();
/// change to a directory, 0 is returned on success.
int chdir(std::string const & name);
int chdir(FileName const & name);
/// Change file permissions
bool chmod(std::string const & file, unsigned long int mode);
bool chmod(FileName const & file, unsigned long int mode);
/**
* rename a file, returns false if it fails.
* It can handle renames across partitions.
*/
bool rename(std::string const & from, std::string const & to);
bool rename(FileName const & from, FileName const & to);
/// copy a file, returns false it it fails
bool copy(std::string const & from, std::string const & to,
bool copy(FileName const & from, FileName const & to,
unsigned long int mode = (unsigned long int)-1);
/// generates a checksum of a file
unsigned long sum(std::string const & file);
unsigned long sum(FileName const & file);
/// FIXME: some point to this hmm ?
int kill(int pid, int sig);
/// FIXME: same here
void abort();
/// create the given directory with the given mode
int mkdir(std::string const & pathname, unsigned long int mode);
int mkdir(FileName const & pathname, unsigned long int mode);
/// unlink the given file
int unlink(std::string const & 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(),
std::string const & mask = std::string());

View File

@ -14,6 +14,8 @@
#include "debug.h"
#include "support/filename.h"
#include <boost/crc.hpp>
#include <algorithm>
@ -54,13 +56,14 @@ template struct boost::detail::crc_table_t<32, 0x04C11DB7, true>;
namespace lyx {
namespace support {
unsigned long support::sum(string const & file)
unsigned long sum(FileName const & file)
{
lyxerr[Debug::FILES] << "lyx::sum() using mmap (lightning fast)"
<< endl;
int fd = open(file.c_str(), O_RDONLY);
int fd = open(file.toFilesystemEncoding().c_str(), O_RDONLY);
if (!fd)
return 0;
@ -88,6 +91,7 @@ unsigned long support::sum(string const & file)
return result;
}
} // namespace support
} // namespace lyx
#else // No mmap
@ -111,17 +115,18 @@ unsigned long do_crc(InputIterator first, InputIterator last)
namespace lyx {
namespace support {
using std::ifstream;
#if HAVE_DECL_ISTREAMBUF_ITERATOR
using std::istreambuf_iterator;
unsigned long support::sum(string const & file)
unsigned long sum(FileName const & file)
{
lyxerr[Debug::FILES] << "lyx::sum() using istreambuf_iterator (fast)"
<< endl;
ifstream ifs(file.c_str());
ifstream ifs(file.toFilesystemEncoding().c_str());
if (!ifs) return 0;
istreambuf_iterator<char> beg(ifs);
@ -134,13 +139,13 @@ unsigned long support::sum(string const & file)
using std::istream_iterator;
using std::ios;
unsigned long support::sum(string const & file)
unsigned long sum(FileName const & file)
{
lyxerr[Debug::FILES]
<< "lyx::sum() using istream_iterator (slow as a snail)"
<< endl;
ifstream ifs(file.c_str());
ifstream ifs(file.toFilesystemEncoding().c_str());
if (!ifs) return 0;
ifs.unsetf(ios::skipws);
@ -151,6 +156,7 @@ unsigned long support::sum(string const & file)
}
#endif
} // namespace support
} // namespace lyx
#endif // mmap

View File

@ -11,6 +11,7 @@
#include <config.h>
#include "support/lyxlib.h"
#include "support/filename.h"
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
@ -30,30 +31,31 @@
#endif
namespace lyx {
namespace support {
int lyx::support::mkdir(std::string const & pathname, unsigned long int mode)
int mkdir(FileName const & pathname, unsigned long int mode)
{
// FIXME: why don't we have mode_t in lyx::mkdir prototype ??
#if HAVE_MKDIR
# if MKDIR_TAKES_ONE_ARG
// MinGW32
return ::mkdir(pathname.c_str());
return ::mkdir(pathname.toFilesystemEncoding().c_str());
# ifdef WITH_WARNINGS
# warning "Permissions of created directories are ignored on this system."
# endif
# else
// POSIX
return ::mkdir(pathname.c_str(), mode_t(mode));
return ::mkdir(pathname.toFilesystemEncoding().c_str(), mode_t(mode));
# endif
#elif defined(_WIN32)
// plain Windows 32
return CreateDirectory(pathname.c_str(), 0) != 0 ? 0 : -1;
return CreateDirectory(pathname.toFilesystemEncoding().c_str(), 0) != 0 ? 0 : -1;
# ifdef WITH_WARNINGS
# warning "Permissions of created directories are ignored on this system."
# endif
#elif HAVE__MKDIR
return ::_mkdir(pathname.c_str());
return ::_mkdir(pathname.toFilesystemEncoding().c_str());
# ifdef WITH_WARNINGS
# warning "Permissions of created directories are ignored on this system."
# endif
@ -63,4 +65,5 @@ int lyx::support::mkdir(std::string const & pathname, unsigned long int mode)
}
} // namespace support
} // namespace lyx

View File

@ -642,7 +642,7 @@ bool check_command_line_dir(string const & dir,
string const & file,
string const & command_line_switch)
{
string const abs_path = fileSearch(dir, file);
FileName const abs_path = fileSearch(dir, file);
if (abs_path.empty()) {
// FIXME UNICODE
lyxerr << lyx::to_utf8(bformat(_("Invalid %1$s switch.\n"
@ -670,7 +670,7 @@ bool check_env_var_dir(string const & dir,
string const & file,
string const & env_var)
{
string const abs_path = fileSearch(dir, file);
FileName const abs_path = fileSearch(dir, file);
if (abs_path.empty()) {
// FIXME UNICODE
lyxerr << lyx::to_utf8(bformat(_("Invalid %1$s environment variable.\n"

View File

@ -14,6 +14,7 @@
#define PATH_C
#include "support/path.h"
#include "support/filename.h"
#include "support/lyxlib.h"
@ -29,7 +30,7 @@ Path::Path(string const & path)
if (!path.empty()) {
pushedDir_ = getcwd();
if (pushedDir_.empty() || chdir(path)) {
if (pushedDir_.empty() || chdir(FileName(path))) {
/* FIXME: throw */
}
} else {
@ -52,7 +53,7 @@ int Path::pop()
return 0;
}
if (chdir(pushedDir_)) {
if (chdir(FileName(pushedDir_))) {
// should throw an exception
// throw DirChangeError();
}

View File

@ -11,19 +11,21 @@
#include <config.h>
#include "support/lyxlib.h"
#include "support/filename.h"
#include <cstdio>
namespace lyx {
namespace support {
using std::string;
bool lyx::support::rename(string const & from, string const & to)
bool rename(FileName const & from, FileName const & to)
{
if (::rename(from.c_str(), to.c_str()) == -1)
if (::rename(from.toFilesystemEncoding().c_str(), to.toFilesystemEncoding().c_str()) == -1)
if (copy(from, to)) {
unlink(from);
return true;
@ -33,4 +35,5 @@ bool lyx::support::rename(string const & from, string const & to)
}
} // namespace support
} // namespace lyx

View File

@ -11,6 +11,7 @@
#include <config.h>
#include "support/socktools.h"
#include "support/filename.h"
#if !defined (HAVE_FCNTL)
// We provide stubs because we don't (yet?) support the native OS API.
@ -114,7 +115,7 @@ int listen(string const & name, int queue)
lyxerr << "lyx: Could not bind address '" << name
<< "' to socket descriptor: " << strerror(errno) << endl;
::close(fd);
lyx::support::unlink(name);
unlink(FileName(name));
return -1;
}
@ -127,7 +128,7 @@ int listen(string const & name, int queue)
lyxerr << "lyx: Could not put socket in 'listen' state: "
<< strerror(errno) << endl;
::close(fd);
lyx::support::unlink(name);
unlink(FileName(name));
return -1;
}

View File

@ -11,18 +11,21 @@
#include <config.h>
#include "support/lyxlib.h"
#include "support/filename.h"
namespace lyx {
namespace support {
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
int lyx::support::unlink(std::string const & pathname)
int unlink(FileName const & pathname)
{
return ::unlink(pathname.c_str());
return ::unlink(pathname.toFilesystemEncoding().c_str());
}
} // namespace support
} // namespace lyx

Some files were not shown because too many files have changed in this diff Show More