Use FileName instead of strings in support::Package.

This fixes some encoding problems, and hopefully also bug 3410.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17746 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2007-04-06 13:09:54 +00:00
parent 675b84c1b0
commit d4e8fdd703
28 changed files with 261 additions and 234 deletions

View File

@ -1555,7 +1555,7 @@ void BufferView::menuInsertLyXFile(string const & filenm)
FileDialog fileDlg(_("Select LyX document to insert"), FileDialog fileDlg(_("Select LyX document to insert"),
LFUN_FILE_INSERT, LFUN_FILE_INSERT,
make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)), make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
make_pair(_("Examples|#E#e"), from_utf8(addPath(package().system_support(), "examples")))); make_pair(_("Examples|#E#e"), from_utf8(addPath(package().system_support().absFilename(), "examples"))));
FileDialog::Result result = FileDialog::Result result =
fileDlg.open(from_utf8(initpath), fileDlg.open(from_utf8(initpath),

View File

@ -189,7 +189,7 @@ void ConverterCache::init()
return; return;
// We do this here and not in the constructor because package() gets // We do this here and not in the constructor because package() gets
// initialized after all static variables. // initialized after all static variables.
cache_dir = FileName(addName(support::package().user_support(), "cache")); cache_dir = FileName(addName(support::package().user_support().absFilename(), "cache"));
if (!fs::exists(cache_dir.toFilesystemEncoding())) if (!fs::exists(cache_dir.toFilesystemEncoding()))
if (support::mkdir(cache_dir, 0700) != 0) { if (support::mkdir(cache_dir, 0700) != 0) {
lyxerr << "Could not create cache directory `" lyxerr << "Could not create cache directory `"

View File

@ -1142,7 +1142,7 @@ int Buffer::runChktex()
string const name = addName(path, getLatexName()); string const name = addName(path, getLatexName());
string const org_path = filePath(); string const org_path = filePath();
support::Path p(path); // path to LaTeX file support::Path p(FileName(path)); // path to LaTeX file
message(_("Running chktex...")); message(_("Running chktex..."));
// Generate the LaTeX file if neccessary // Generate the LaTeX file if neccessary

View File

@ -364,7 +364,7 @@ void BufferList::emergencyWrite(Buffer * buf)
} }
// 2) In HOME directory. // 2) In HOME directory.
string s = addName(package().home_dir(), buf->fileName()); string s = addName(package().home_dir().absFilename(), buf->fileName());
s += ".emergency"; s += ".emergency";
lyxerr << ' ' << s << endl; lyxerr << ' ' << s << endl;
if (buf->writeFile(FileName(s))) { if (buf->writeFile(FileName(s))) {
@ -378,7 +378,7 @@ void BufferList::emergencyWrite(Buffer * buf)
// 3) In "/tmp" directory. // 3) In "/tmp" directory.
// MakeAbsPath to prepend the current // MakeAbsPath to prepend the current
// drive letter on OS/2 // drive letter on OS/2
s = addName(package().temp_dir(), buf->fileName()); s = addName(package().temp_dir().absFilename(), buf->fileName());
s += ".emergency"; s += ".emergency";
lyxerr << ' ' << s << endl; lyxerr << ' ' << s << endl;
if (buf->writeFile(FileName(s))) { if (buf->writeFile(FileName(s))) {

View File

@ -48,8 +48,8 @@ public:
//lyxerr << "Messages: language(" << l //lyxerr << "Messages: language(" << l
// << ") in dir(" << dir << ")" << std::endl; // << ") in dir(" << dir << ")" << std::endl;
cat_gl = mssg_gl.open(PACKAGE, loc_gl, string const locale_dir = package().locale_dir().toFilesystemEncoding();
package().locale_dir().c_str()); cat_gl = mssg_gl.open(PACKAGE, loc_gl, locale_dir.c_str());
} }
@ -112,14 +112,15 @@ public:
// return what we got in. // return what we got in.
return from_ascii(m); return from_ascii(m);
errno = 0; errno = 0;
char const * c = bindtextdomain(PACKAGE, package().locale_dir().c_str()); string const locale_dir = package().locale_dir().toFilesystemEncoding();
char const * c = bindtextdomain(PACKAGE, locale_dir.c_str());
int e = errno; int e = errno;
if (e) { if (e) {
LYXERR(Debug::DEBUG) LYXERR(Debug::DEBUG)
<< BOOST_CURRENT_FUNCTION << '\n' << BOOST_CURRENT_FUNCTION << '\n'
<< "Error code: " << errno << '\n' << "Error code: " << errno << '\n'
<< "Lang, mess: " << lang_ << " " << m << '\n' << "Lang, mess: " << lang_ << " " << m << '\n'
<< "Directory : " << package().locale_dir() << '\n' << "Directory : " << package().locale_dir().absFilename() << '\n'
<< "Rtn value : " << c << endl; << "Rtn value : " << c << endl;
} }

View File

@ -349,7 +349,7 @@ bool Converters::convert(Buffer const * buffer,
// generated by the converter are deleted when LyX closes and do not // generated by the converter are deleted when LyX closes and do not
// clutter the real working directory. // clutter the real working directory.
string path = onlyPath(from_file.absFilename()); string path = onlyPath(from_file.absFilename());
Path p(path); Path p(FileName(path));
// empty the error list before any new conversion takes place. // empty the error list before any new conversion takes place.
errorList.clear(); errorList.clear();
@ -431,7 +431,7 @@ bool Converters::convert(Buffer const * buffer,
Systemcall one; Systemcall one;
int res; int res;
if (conv.original_dir) { if (conv.original_dir) {
Path p(buffer->filePath()); Path p(FileName(buffer->filePath()));
res = one.startscript(type, res = one.startscript(type,
to_filesystem8bit(from_utf8(command))); to_filesystem8bit(from_utf8(command)));
} else } else

View File

@ -116,7 +116,7 @@ CopyStatus copyFile(string const & format,
// overwrite themselves. This check could be changed to // overwrite themselves. This check could be changed to
// boost::filesystem::equivalent(sourceFile, destFile) if export to // boost::filesystem::equivalent(sourceFile, destFile) if export to
// other directories than the document directory is desired. // other directories than the document directory is desired.
if (!prefixIs(onlyPath(sourceFile.absFilename()), package().temp_dir())) if (!prefixIs(onlyPath(sourceFile.absFilename()), package().temp_dir().absFilename()))
return ret; return ret;
if (!force) { if (!force) {

View File

@ -43,7 +43,7 @@ ControlAboutlyx::ControlAboutlyx(Dialog & parent)
void ControlAboutlyx::getCredits(ostream & ss) const void ControlAboutlyx::getCredits(ostream & ss) const
{ {
FileName const name = fileSearch(package().system_support(), "CREDITS"); FileName const name = fileSearch(package().system_support().absFilename(), "CREDITS");
bool found(!name.empty()); bool found(!name.empty());
@ -90,10 +90,10 @@ string const ControlAboutlyx::getVersion() const
<< lyx_release_date << lyx_release_date
<< ")\n" << ")\n"
<< to_utf8(_("Library directory: ")) << to_utf8(_("Library directory: "))
<< to_utf8(makeDisplayPath(package().system_support())) << to_utf8(makeDisplayPath(package().system_support().absFilename()))
<< "\n" << "\n"
<< to_utf8(_("User directory: ")) << to_utf8(_("User directory: "))
<< to_utf8(makeDisplayPath(package().user_support())); << to_utf8(makeDisplayPath(package().user_support().absFilename()));
return ss.str(); return ss.str();
} }

View File

@ -87,11 +87,11 @@ docstring const ControlGraphics::browse(docstring const & in_name) const
docstring const title = _("Select graphics file"); docstring const title = _("Select graphics file");
// Does user clipart directory exist? // Does user clipart directory exist?
string clipdir = addName(package().user_support(), "clipart"); string clipdir = addName(package().user_support().absFilename(), "clipart");
string const encoded_clipdir = FileName(clipdir).toFilesystemEncoding(); string const encoded_clipdir = FileName(clipdir).toFilesystemEncoding();
if (!(fs::exists(encoded_clipdir) && fs::is_directory(encoded_clipdir))) if (!(fs::exists(encoded_clipdir) && fs::is_directory(encoded_clipdir)))
// No - bail out to system clipart directory // No - bail out to system clipart directory
clipdir = addName(package().system_support(), "clipart"); clipdir = addName(package().system_support().absFilename(), "clipart");
pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir)); pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path)); pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
// Show the file browser dialog // Show the file browser dialog

View File

@ -100,10 +100,10 @@ docstring const browseLibFile(docstring const & dir,
{ {
// FIXME UNICODE // FIXME UNICODE
pair<docstring, docstring> const dir1(_("System files|#S#s"), pair<docstring, docstring> const dir1(_("System files|#S#s"),
from_utf8(addName(package().system_support(), to_utf8(dir)))); from_utf8(addName(package().system_support().absFilename(), to_utf8(dir))));
pair<docstring, docstring> const dir2(_("User files|#U#u"), pair<docstring, docstring> const dir2(_("User files|#U#u"),
from_utf8(addName(package().user_support(), to_utf8(dir)))); from_utf8(addName(package().user_support().absFilename(), to_utf8(dir))));
docstring const result = browseFile(from_utf8( docstring const result = browseFile(from_utf8(
libFileSearch(to_utf8(dir), to_utf8(name), to_utf8(ext)).absFilename()), libFileSearch(to_utf8(dir), to_utf8(name), to_utf8(ext)).absFilename()),

View File

@ -167,7 +167,7 @@ string const doSubstitution(InsetExternalParams const & params,
'.' + support::getExtension(filename), use_latex_path); '.' + support::getExtension(filename), use_latex_path);
result = subst_path(result, "$$Tempname", params.tempname().absFilename(), use_latex_path); result = subst_path(result, "$$Tempname", params.tempname().absFilename(), use_latex_path);
result = subst_path(result, "$$Sysdir", result = subst_path(result, "$$Sysdir",
support::package().system_support(), use_latex_path); support::package().system_support().absFilename(), use_latex_path);
// Handle the $$Contents(filename) syntax // Handle the $$Contents(filename) syntax
if (support::contains(result, "$$Contents(\"")) { if (support::contains(result, "$$Contents(\"")) {

View File

@ -233,7 +233,7 @@ TemplateManager::getPreambleDefByName(string const & name) const
} }
void TemplateManager::readTemplates(string const & path) void TemplateManager::readTemplates(support::FileName const & path)
{ {
support::Path p(path); support::Path p(path);

View File

@ -19,6 +19,8 @@
namespace lyx { namespace lyx {
namespace support { class FileName; }
class LyXLex; class LyXLex;
namespace external { namespace external {
@ -117,7 +119,7 @@ public:
std::string const getPreambleDefByName(std::string const & name) const; std::string const getPreambleDefByName(std::string const & name) const;
private: private:
TemplateManager(); TemplateManager();
void readTemplates(std::string const & path); void readTemplates(support::FileName const & path);
void dumpTemplates(std::ostream &) const; void dumpTemplates(std::ostream &) const;
void dumpPreambleDefs(std::ostream &) const; void dumpPreambleDefs(std::ostream &) const;

View File

@ -309,7 +309,7 @@ int InsetBibtex::latex(Buffer const & buffer, odocstream & os,
vector<FileName> const InsetBibtex::getFiles(Buffer const & buffer) const vector<FileName> const InsetBibtex::getFiles(Buffer const & buffer) const
{ {
Path p(buffer.filePath()); Path p(FileName(buffer.filePath()));
vector<FileName> vec; vector<FileName> vec;

View File

@ -456,7 +456,7 @@ int LyX::exec(int & argc, char * argv[])
// such that package().temp_dir() is properly initialized. // such that package().temp_dir() is properly initialized.
pimpl_->lyx_server_.reset(new LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes)); pimpl_->lyx_server_.reset(new LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
pimpl_->lyx_socket_.reset(new LyXServerSocket(&pimpl_->lyxfunc_, pimpl_->lyx_socket_.reset(new LyXServerSocket(&pimpl_->lyxfunc_,
os::internal_path(package().temp_dir() + "/lyxsocket"))); package().temp_dir().absFilename() + "/lyxsocket"));
// Start the real execution loop. // Start the real execution loop.
exit_status = pimpl_->application_->exec(); exit_status = pimpl_->application_->exec();
@ -482,12 +482,12 @@ void LyX::prepareExit()
// do any other cleanup procedures now // do any other cleanup procedures now
if (package().temp_dir() != package().system_temp_dir()) { if (package().temp_dir() != package().system_temp_dir()) {
LYXERR(Debug::INFO) << "Deleting tmp dir " LYXERR(Debug::INFO) << "Deleting tmp dir "
<< package().temp_dir() << endl; << package().temp_dir().absFilename() << endl;
if (!destroyDir(FileName(package().temp_dir()))) { if (!destroyDir(package().temp_dir())) {
docstring const msg = docstring const msg =
bformat(_("Unable to remove the temporary directory %1$s"), bformat(_("Unable to remove the temporary directory %1$s"),
from_utf8(package().temp_dir())); from_utf8(package().temp_dir().absFilename()));
Alert::warning(_("Unable to remove temporary directory"), msg); Alert::warning(_("Unable to remove temporary directory"), msg);
} }
} }
@ -812,11 +812,11 @@ bool LyX::init()
signal(SIGTERM, error_handler); signal(SIGTERM, error_handler);
// SIGPIPE can be safely ignored. // SIGPIPE can be safely ignored.
lyxrc.tempdir_path = package().temp_dir(); lyxrc.tempdir_path = package().temp_dir().absFilename();
lyxrc.document_path = package().document_dir(); lyxrc.document_path = package().document_dir().absFilename();
if (lyxrc.template_path.empty()) { if (lyxrc.template_path.empty()) {
lyxrc.template_path = addPath(package().system_support(), lyxrc.template_path = addPath(package().system_support().absFilename(),
"templates"); "templates");
} }
@ -836,7 +836,7 @@ bool LyX::init()
// Add the directory containing the LyX executable to the path // Add the directory containing the LyX executable to the path
// so that LyX can find things like tex2lyx. // so that LyX can find things like tex2lyx.
if (package().build_support().empty()) if (package().build_support().empty())
prependEnvPath("PATH", package().binary_dir()); prependEnvPath("PATH", package().binary_dir().absFilename());
#endif #endif
if (!lyxrc.path_prefix.empty()) if (!lyxrc.path_prefix.empty())
prependEnvPath("PATH", lyxrc.path_prefix); prependEnvPath("PATH", lyxrc.path_prefix);
@ -906,9 +906,9 @@ bool LyX::init()
FileName const document_path(lyxrc.document_path); FileName const document_path(lyxrc.document_path);
if (fs::exists(document_path.toFilesystemEncoding()) && if (fs::exists(document_path.toFilesystemEncoding()) &&
fs::is_directory(document_path.toFilesystemEncoding())) fs::is_directory(document_path.toFilesystemEncoding()))
package().document_dir() = lyxrc.document_path; package().document_dir() = document_path;
package().temp_dir() = createLyXTmpDir(FileName(lyxrc.tempdir_path)).absFilename(); package().temp_dir() = createLyXTmpDir(FileName(lyxrc.tempdir_path));
if (package().temp_dir().empty()) { if (package().temp_dir().empty()) {
Alert::error(_("Could not create temporary directory"), Alert::error(_("Could not create temporary directory"),
bformat(_("Could not create a temporary directory in\n" bformat(_("Could not create a temporary directory in\n"
@ -923,7 +923,9 @@ bool LyX::init()
return false; return false;
} }
LYXERR(Debug::INIT) << "LyX tmp dir: `" << package().temp_dir() << '\'' << endl; LYXERR(Debug::INIT) << "LyX tmp dir: `"
<< package().temp_dir().absFilename()
<< '\'' << endl;
LYXERR(Debug::INIT) << "Reading session information '.lyx/session'..." << endl; LYXERR(Debug::INIT) << "Reading session information '.lyx/session'..." << endl;
pimpl_->session_.reset(new Session(lyxrc.num_lastfiles)); pimpl_->session_.reset(new Session(lyxrc.num_lastfiles));
@ -1042,13 +1044,13 @@ bool needsUpdate(string const & file)
static bool firstrun = true; static bool firstrun = true;
if (firstrun) { if (firstrun) {
configure_script = FileName(addName( configure_script = FileName(addName(
package().system_support(), package().system_support().absFilename(),
"configure.py")).toFilesystemEncoding(); "configure.py")).toFilesystemEncoding();
firstrun = false; firstrun = false;
} }
string const absfile = FileName(addName( string const absfile = FileName(addName(
package().user_support(), file)).toFilesystemEncoding(); package().user_support().absFilename(), file)).toFilesystemEncoding();
return (! fs::exists(absfile)) return (! fs::exists(absfile))
|| (fs::last_write_time(configure_script) || (fs::last_write_time(configure_script)
> fs::last_write_time(absfile)); > fs::last_write_time(absfile));
@ -1061,7 +1063,7 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
{ {
// Does user directory exist? // Does user directory exist?
string const user_support = string const user_support =
FileName(package().user_support()).toFilesystemEncoding(); package().user_support().toFilesystemEncoding();
if (fs::exists(user_support) && fs::is_directory(user_support)) { if (fs::exists(user_support) && fs::is_directory(user_support)) {
first_start = false; first_start = false;
@ -1080,7 +1082,7 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
bformat(_("You have specified a non-existent user " bformat(_("You have specified a non-existent user "
"LyX directory, %1$s.\n" "LyX directory, %1$s.\n"
"It is needed to keep your own configuration."), "It is needed to keep your own configuration."),
from_utf8(package().user_support())), from_utf8(package().user_support().absFilename())),
1, 0, 1, 0,
_("&Create directory"), _("&Create directory"),
_("&Exit LyX"))) { _("&Exit LyX"))) {
@ -1089,7 +1091,7 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
} }
lyxerr << to_utf8(bformat(_("LyX: Creating directory %1$s"), lyxerr << to_utf8(bformat(_("LyX: Creating directory %1$s"),
from_utf8(package().user_support()))) from_utf8(package().user_support().absFilename())))
<< endl; << endl;
if (!createDirectory(package().user_support(), 0755)) { if (!createDirectory(package().user_support(), 0755)) {

View File

@ -1005,7 +1005,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
// Push directory path. // Push directory path.
string const path = buffer->temppath(); string const path = buffer->temppath();
support::Path p(path); support::Path p(FileName(path));
// there are three cases here: // there are three cases here:
// 1. we print to a file // 1. we print to a file
@ -1227,7 +1227,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
int row; int row;
istringstream is(argument); istringstream is(argument);
is >> file_name >> row; is >> file_name >> row;
if (prefixIs(file_name, package().temp_dir())) { if (prefixIs(file_name, package().temp_dir().absFilename())) {
// Needed by inverse dvi search. If it is a file // Needed by inverse dvi search. If it is a file
// in tmpdir, call the apropriated function // in tmpdir, call the apropriated function
lyx_view_->setBuffer(theBufferList().getBufferFromTmp(file_name)); lyx_view_->setBuffer(theBufferList().getBufferFromTmp(file_name));
@ -1462,7 +1462,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_PREFERENCES_SAVE: { case LFUN_PREFERENCES_SAVE: {
lyxrc.write(makeAbsPath("preferences", lyxrc.write(makeAbsPath("preferences",
package().user_support()), package().user_support().absFilename()),
false); false);
break; break;
} }
@ -1588,7 +1588,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_BUFFER_SAVE_AS_DEFAULT: { case LFUN_BUFFER_SAVE_AS_DEFAULT: {
string const fname = string const fname =
addName(addPath(package().user_support(), "templates/"), addName(addPath(package().user_support().absFilename(), "templates/"),
"defaults.lyx"); "defaults.lyx");
Buffer defaults(fname); Buffer defaults(fname);
@ -1900,7 +1900,7 @@ void LyXFunc::open(string const & fname)
FileDialog fileDlg(_("Select document to open"), FileDialog fileDlg(_("Select document to open"),
LFUN_FILE_OPEN, LFUN_FILE_OPEN,
make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)), make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
make_pair(_("Examples|#E#e"), from_utf8(addPath(package().system_support(), "examples")))); make_pair(_("Examples|#E#e"), from_utf8(addPath(package().system_support().absFilename(), "examples"))));
FileDialog::Result result = FileDialog::Result result =
fileDlg.open(from_utf8(initpath), fileDlg.open(from_utf8(initpath),
@ -1974,7 +1974,7 @@ void LyXFunc::doImport(string const & argument)
LFUN_BUFFER_IMPORT, LFUN_BUFFER_IMPORT,
make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)), make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)),
make_pair(_("Examples|#E#e"), make_pair(_("Examples|#E#e"),
from_utf8(addPath(package().system_support(), "examples")))); from_utf8(addPath(package().system_support().absFilename(), "examples"))));
docstring filter = formats.prettyName(format); docstring filter = formats.prettyName(format);
filter += " (*."; filter += " (*.";
@ -2155,7 +2155,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
string const encoded = FileName( string const encoded = FileName(
lyxrc_new.document_path).toFilesystemEncoding(); lyxrc_new.document_path).toFilesystemEncoding();
if (fs::exists(encoded) && fs::is_directory(encoded)) if (fs::exists(encoded) && fs::is_directory(encoded))
support::package().document_dir() = lyxrc.document_path; support::package().document_dir() = FileName(lyxrc.document_path);
} }
case LyXRC::RC_ESC_CHARS: case LyXRC::RC_ESC_CHARS:
case LyXRC::RC_FONT_ENCODING: case LyXRC::RC_FONT_ENCODING:

View File

@ -112,14 +112,15 @@ docstring const Messages::get(string const & m) const
setlocale(LC_CTYPE, lang_.c_str()); setlocale(LC_CTYPE, lang_.c_str());
errno = 0; errno = 0;
char const * c = bindtextdomain(PACKAGE, package().locale_dir().c_str()); string const locale_dir = package().locale_dir().toFilesystemEncoding();
char const * c = bindtextdomain(PACKAGE, locale_dir.c_str());
int e = errno; int e = errno;
if (e) { if (e) {
LYXERR(Debug::DEBUG) LYXERR(Debug::DEBUG)
<< BOOST_CURRENT_FUNCTION << '\n' << BOOST_CURRENT_FUNCTION << '\n'
<< "Error code: " << errno << '\n' << "Error code: " << errno << '\n'
<< "Lang, mess: " << lang_ << " " << m << '\n' << "Lang, mess: " << lang_ << " " << m << '\n'
<< "Directory : " << package().locale_dir() << '\n' << "Directory : " << package().locale_dir().absFilename() << '\n'
<< "Rtn value : " << c << endl; << "Rtn value : " << c << endl;
} }
@ -222,7 +223,8 @@ public:
//lyxerr << "Messages: language(" << l //lyxerr << "Messages: language(" << l
// << ") in dir(" << dir << ")" << endl; // << ") in dir(" << dir << ")" << endl;
cat_gl = mssg_gl.open(PACKAGE, loc_gl, package().locale_dir().c_str()); string const locale_dir = package().locale_dir().toFilesystemEncoding();
cat_gl = mssg_gl.open(PACKAGE, loc_gl, locale_dir.c_str());
} }

View File

@ -464,7 +464,7 @@ Session::Session(unsigned int num) :
{ {
// locate the session file // locate the session file
// note that the session file name 'session' is hard-coded // note that the session file name 'session' is hard-coded
session_file = FileName(addName(package().user_support(), "session")); session_file = FileName(addName(package().user_support().absFilename(), "session"));
// //
readFile(); readFile();
} }

View File

@ -192,9 +192,9 @@ FileName const fileOpenSearch(string const & path, string const & name,
if (!suffixIs(path_element, '/')) if (!suffixIs(path_element, '/'))
path_element += '/'; path_element += '/';
path_element = subst(path_element, "$$LyX", path_element = subst(path_element, "$$LyX",
package().system_support()); package().system_support().absFilename());
path_element = subst(path_element, "$$User", path_element = subst(path_element, "$$User",
package().user_support()); package().user_support().absFilename());
real_file = fileSearch(path_element, name, ext); real_file = fileSearch(path_element, name, ext);
@ -274,18 +274,18 @@ FileName const fileSearch(string const & path, string const & name,
FileName const libFileSearch(string const & dir, string const & name, FileName const libFileSearch(string const & dir, string const & name,
string const & ext) string const & ext)
{ {
FileName fullname = fileSearch(addPath(package().user_support(), dir), FileName fullname = fileSearch(addPath(package().user_support().absFilename(), dir),
name, ext); name, ext);
if (!fullname.empty()) if (!fullname.empty())
return fullname; return fullname;
if (!package().build_support().empty()) if (!package().build_support().empty())
fullname = fileSearch(addPath(package().build_support(), dir), fullname = fileSearch(addPath(package().build_support().absFilename(), dir),
name, ext); name, ext);
if (!fullname.empty()) if (!fullname.empty())
return fullname; return fullname;
return fileSearch(addPath(package().system_support(), dir), name, ext); return fileSearch(addPath(package().system_support().absFilename(), dir), name, ext);
} }
@ -417,7 +417,7 @@ string const createBufferTmpDir()
// In fact I wrote this code to circumvent a problematic behaviour // In fact I wrote this code to circumvent a problematic behaviour
// (bug?) of EMX mkstemp(). // (bug?) of EMX mkstemp().
string const tmpfl = string const tmpfl =
package().temp_dir() + "/lyx_tmpbuf" + package().temp_dir().absFilename() + "/lyx_tmpbuf" +
convert<string>(count++); convert<string>(count++);
if (mkdir(FileName(tmpfl), 0777)) { if (mkdir(FileName(tmpfl), 0777)) {
@ -450,11 +450,10 @@ FileName const createLyXTmpDir(FileName const & deflt)
} }
bool createDirectory(string const & path, int permission) bool createDirectory(FileName const & path, int permission)
{ {
string temp = rtrim(os::internal_path(path), "/"); BOOST_ASSERT(!path.empty());
BOOST_ASSERT(!temp.empty()); return mkdir(path, permission) == 0;
return mkdir(FileName(temp), permission) == 0;
} }
@ -591,7 +590,7 @@ string const expandPath(string const & path)
return getcwd().absFilename() + '/' + rTemp; return getcwd().absFilename() + '/' + rTemp;
if (temp == "~") if (temp == "~")
return package().home_dir() + '/' + rTemp; return package().home_dir().absFilename() + '/' + rTemp;
if (temp == "..") if (temp == "..")
return makeAbsPath(copy).absFilename(); return makeAbsPath(copy).absFilename();
@ -998,12 +997,12 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold)
string str = path; string str = path;
// If file is from LyXDir, display it as if it were relative. // If file is from LyXDir, display it as if it were relative.
string const system = package().system_support(); string const system = package().system_support().absFilename();
if (prefixIs(str, system) && str != system) if (prefixIs(str, system) && str != system)
return from_utf8("[" + str.erase(0, system.length()) + "]"); return from_utf8("[" + str.erase(0, system.length()) + "]");
// replace /home/blah with ~/ // replace /home/blah with ~/
string const home = package().home_dir(); string const home = package().home_dir().absFilename();
if (!home.empty() && prefixIs(str, home)) if (!home.empty() && prefixIs(str, home))
str = subst(str, home, "~"); str = subst(str, home, "~");
@ -1033,20 +1032,18 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold)
} }
bool readLink(string const & file, string & link, bool resolve) bool readLink(FileName const & file, FileName & link)
{ {
#ifdef HAVE_READLINK #ifdef HAVE_READLINK
char linkbuffer[512]; char linkbuffer[512];
// Should be PATH_MAX but that needs autconf support // Should be PATH_MAX but that needs autconf support
int const nRead = ::readlink(file.c_str(), string const encoded = file.toFilesystemEncoding();
int const nRead = ::readlink(encoded.c_str(),
linkbuffer, sizeof(linkbuffer) - 1); linkbuffer, sizeof(linkbuffer) - 1);
if (nRead <= 0) if (nRead <= 0)
return false; return false;
linkbuffer[nRead] = '\0'; // terminator linkbuffer[nRead] = '\0'; // terminator
if (resolve) link = makeAbsPath(linkbuffer, onlyPath(file.absFilename()));
link = makeAbsPath(linkbuffer, onlyPath(file)).absFilename();
else
link = linkbuffer;
return true; return true;
#else #else
return false; return false;

View File

@ -29,7 +29,7 @@ bool destroyDir(FileName const & tmpdir);
std::string const createBufferTmpDir(); std::string const createBufferTmpDir();
/// Creates directory. Returns true on success /// Creates directory. Returns true on success
bool createDirectory(std::string const & name, int permissions); bool createDirectory(FileName const & name, int permissions);
/** Creates the global LyX temp dir. /** Creates the global LyX temp dir.
\p deflt can be an existing directory name. In this case a new directory \p deflt can be an existing directory name. In this case a new directory
@ -276,12 +276,10 @@ std::string const getFileContents(FileName const & fname);
*/ */
std::string const replaceEnvironmentPath(std::string const & path); std::string const replaceEnvironmentPath(std::string const & path);
/* Set \c link to the path \c file points to as a symbolic link. /** Set \c link to the path \c file points to as a symbolic link.
If \c resolve is true, then \c link is an absolute path \return true if successful.
Returns true if successful */ */
bool readLink(std::string const & file, bool readLink(FileName const & file, FileName & link);
std::string & link,
bool resolve = false);
/** /**
* Search a TeX file in all locations the latex compiler would search it, * Search a TeX file in all locations the latex compiler would search it,

View File

@ -328,7 +328,7 @@ void addFontResources()
{ {
#ifdef X_DISPLAY_MISSING #ifdef X_DISPLAY_MISSING
// Windows only: Add BaKoMa TrueType font resources // Windows only: Add BaKoMa TrueType font resources
string const fonts_dir = addPath(package().system_support(), "fonts"); string const fonts_dir = addPath(package().system_support().absFilename(), "fonts");
for (int i = 0 ; i < num_fonts_truetype ; ++i) { for (int i = 0 ; i < num_fonts_truetype ; ++i) {
string const font_current = to_local8bit(from_utf8(convert_path( string const font_current = to_local8bit(from_utf8(convert_path(
@ -344,7 +344,7 @@ void restoreFontResources()
{ {
#ifdef X_DISPLAY_MISSING #ifdef X_DISPLAY_MISSING
// Windows only: Remove BaKoMa TrueType font resources // Windows only: Remove BaKoMa TrueType font resources
string const fonts_dir = addPath(package().system_support(), "fonts"); string const fonts_dir = addPath(package().system_support().absFilename(), "fonts");
for(int i = 0 ; i < num_fonts_truetype ; ++i) { for(int i = 0 ; i < num_fonts_truetype ; ++i) {
string const font_current = to_local8bit(from_utf8(convert_path( string const font_current = to_local8bit(from_utf8(convert_path(

View File

@ -406,7 +406,7 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode)
void addFontResources() void addFontResources()
{ {
// Windows only: Add BaKoMa TrueType font resources // Windows only: Add BaKoMa TrueType font resources
string const fonts_dir = addPath(package().system_support(), "fonts"); string const fonts_dir = addPath(package().system_support().absFilename(), "fonts");
for (int i = 0 ; i < num_fonts_truetype ; ++i) { for (int i = 0 ; i < num_fonts_truetype ; ++i) {
string const font_current = string const font_current =
@ -419,7 +419,7 @@ void addFontResources()
void restoreFontResources() void restoreFontResources()
{ {
// Windows only: Remove BaKoMa TrueType font resources // Windows only: Remove BaKoMa TrueType font resources
string const fonts_dir = addPath(package().system_support(), "fonts"); string const fonts_dir = addPath(package().system_support().absFilename(), "fonts");
for(int i = 0 ; i < num_fonts_truetype ; ++i) { for(int i = 0 ; i < num_fonts_truetype ; ++i) {
string const font_current = string const font_current =

View File

@ -89,27 +89,27 @@ Package const & package()
namespace { namespace {
string const abs_path_from_binary_name(string const & exe); FileName const abs_path_from_binary_name(string const & exe);
std::pair<string, string> const std::pair<FileName, FileName> const
get_build_dirs(string const & abs_binary, get_build_dirs(FileName const & abs_binary,
exe_build_dir_to_top_build_dir top_build_dir_location); exe_build_dir_to_top_build_dir top_build_dir_location);
string const get_document_dir(string const & home_dir); FileName const get_document_dir(FileName const & home_dir);
string const get_home_dir(); FileName const get_home_dir();
string const get_locale_dir(string const & system_support_dir); FileName const get_locale_dir(FileName const & system_support_dir);
string const get_system_support_dir(string const & abs_binary, FileName const get_system_support_dir(FileName const & abs_binary,
string const & command_line_system_support_dir); string const & command_line_system_support_dir);
string const get_temp_dir(); FileName const get_temp_dir();
string const get_default_user_support_dir(string const & home_dir); FileName const get_default_user_support_dir(FileName const & home_dir);
std::pair<string, bool> const std::pair<FileName, bool> const
get_user_support_dir(string const & default_user_support_dir, get_user_support_dir(FileName const & default_user_support_dir,
string const & command_line_user_support_dir); string const & command_line_user_support_dir);
@ -129,8 +129,8 @@ Package::Package(string const & command_line_arg0,
temp_dir_ = system_temp_dir_; temp_dir_ = system_temp_dir_;
document_dir_ = get_document_dir(home_dir_); document_dir_ = get_document_dir(home_dir_);
string const abs_binary = abs_path_from_binary_name(command_line_arg0); FileName const abs_binary = abs_path_from_binary_name(command_line_arg0);
binary_dir_ = onlyPath(abs_binary); binary_dir_ = FileName(onlyPath(abs_binary.absFilename()));
// Is LyX being run in-place from the build tree? // Is LyX being run in-place from the build tree?
boost::tie(build_support_dir_, system_support_dir_) = boost::tie(build_support_dir_, system_support_dir_) =
@ -143,26 +143,27 @@ Package::Package(string const & command_line_arg0,
locale_dir_ = get_locale_dir(system_support_dir_); locale_dir_ = get_locale_dir(system_support_dir_);
string const default_user_support_dir = FileName const default_user_support_dir =
get_default_user_support_dir(home_dir_); get_default_user_support_dir(home_dir_);
boost::tie(user_support_dir_, explicit_user_support_dir_) = boost::tie(user_support_dir_, explicit_user_support_dir_) =
get_user_support_dir(default_user_support_dir, get_user_support_dir(default_user_support_dir,
command_line_user_support_dir); command_line_user_support_dir);
string const configure_script = addName(system_support(), "configure.py"); FileName const configure_script(addName(system_support().absFilename(), "configure.py"));
configure_command_ = os::python() + ' ' + quoteName(configure_script) configure_command_ = os::python() + ' ' +
+ with_version_suffix(); quoteName(configure_script.toFilesystemEncoding()) +
with_version_suffix();
lyxerr[Debug::INIT] lyxerr[Debug::INIT]
<< "<package>\n" << "<package>\n"
<< "\tbinary_dir " << binary_dir() << '\n' << "\tbinary_dir " << binary_dir().absFilename() << '\n'
<< "\tsystem_support " << system_support() << '\n' << "\tsystem_support " << system_support().absFilename() << '\n'
<< "\tbuild_support " << build_support() << '\n' << "\tbuild_support " << build_support().absFilename() << '\n'
<< "\tuser_support " << user_support() << '\n' << "\tuser_support " << user_support().absFilename() << '\n'
<< "\tlocale_dir " << locale_dir() << '\n' << "\tlocale_dir " << locale_dir().absFilename() << '\n'
<< "\tdocument_dir " << document_dir() << '\n' << "\tdocument_dir " << document_dir().absFilename() << '\n'
<< "\ttemp_dir " << temp_dir() << '\n' << "\ttemp_dir " << temp_dir().absFilename() << '\n'
<< "\thome_dir " << home_dir() << '\n' << "\thome_dir " << home_dir().absFilename() << '\n'
<< "</package>\n" << std::endl; << "</package>\n" << std::endl;
} }
@ -171,15 +172,19 @@ namespace {
// These next functions contain the stuff that is substituted at // These next functions contain the stuff that is substituted at
// configuration-time. // configuration-time.
string const hardcoded_localedir() FileName const hardcoded_localedir()
{ {
return string("@LOCALEDIR@"); // FIXME UNICODE
// The build system needs to make sure that this is in utf8 encoding.
return FileName("@LOCALEDIR@");
} }
string const hardcoded_system_support_dir() FileName const hardcoded_system_support_dir()
{ {
return string("@LYX_DIR@"); // FIXME UNICODE
// The build system needs to make sure that this is in utf8 encoding.
return FileName("@LYX_DIR@");
} }
@ -194,9 +199,11 @@ string const & with_version_suffix()
} // namespace anon } // namespace anon
string const & Package::top_srcdir() FileName const & Package::top_srcdir()
{ {
static string const dir("@TOP_SRCDIR@"); // FIXME UNICODE
// The build system needs to make sure that this is in utf8 encoding.
static FileName const dir("@TOP_SRCDIR@");
return dir; return dir;
} }
@ -207,12 +214,12 @@ bool check_command_line_dir(string const & dir,
string const & file, string const & file,
string const & command_line_switch); string const & command_line_switch);
string const extract_env_var_dir(string const & env_var); FileName const extract_env_var_dir(string const & env_var);
bool check_env_var_dir(string const & dir, bool check_env_var_dir(FileName const & dir,
string const & env_var); string const & env_var);
bool check_env_var_dir(string const & dir, bool check_env_var_dir(FileName const & dir,
string const & file, string const & file,
string const & env_var); string const & env_var);
@ -221,8 +228,19 @@ string const relative_locale_dir();
string const relative_system_support_dir(); string const relative_system_support_dir();
std::string const /**
get_build_support_dir(std::string const & binary_dir, * Convert \p name to internal path and strip a trailing slash, since it
* comes from user input (commandline or environment).
* \p name is encoded in utf8.
*/
string const fix_dir_name(string const & name)
{
return rtrim(os::internal_path(name), "/");
}
FileName const
get_build_support_dir(string const & binary_dir,
exe_build_dir_to_top_build_dir top_build_dir_location) exe_build_dir_to_top_build_dir top_build_dir_location)
{ {
string indirection; string indirection;
@ -235,12 +253,12 @@ get_build_support_dir(std::string const & binary_dir,
break; break;
} }
return normalizePath(addPath(binary_dir, indirection)); return FileName(normalizePath(addPath(binary_dir, indirection)));
} }
std::pair<string, string> const std::pair<FileName, FileName> const
get_build_dirs(string const & abs_binary, get_build_dirs(FileName const & abs_binary,
exe_build_dir_to_top_build_dir top_build_dir_location) exe_build_dir_to_top_build_dir top_build_dir_location)
{ {
string const check_text = "Checking whether LyX is run in place..."; string const check_text = "Checking whether LyX is run in place...";
@ -253,17 +271,17 @@ get_build_dirs(string const & abs_binary,
// Note that the name of the lyx binary may be a symbolic link. // Note that the name of the lyx binary may be a symbolic link.
// If that is the case, then we follow the links too. // If that is the case, then we follow the links too.
string binary = abs_binary; FileName binary = abs_binary;
while (true) { while (true) {
// Try and find "lyxrc.defaults". // Try and find "lyxrc.defaults".
string const binary_dir = onlyPath(binary); string const binary_dir = onlyPath(binary.absFilename());
string const build_support_dir = FileName const build_support_dir =
get_build_support_dir(binary_dir, top_build_dir_location); get_build_support_dir(binary_dir, top_build_dir_location);
if (!fileSearch(build_support_dir, "Makefile").empty()) { if (!fileSearch(build_support_dir.absFilename(), "Makefile").empty()) {
// Try and find "chkconfig.ltx". // Try and find "chkconfig.ltx".
string const system_support_dir = string const system_support_dir =
addPath(Package::top_srcdir(), "lib"); addPath(Package::top_srcdir().absFilename(), "lib");
if (!fileSearch(system_support_dir, "chkconfig.ltx").empty()) { if (!fileSearch(system_support_dir, "chkconfig.ltx").empty()) {
lyxerr[Debug::INIT] << check_text << " yes" lyxerr[Debug::INIT] << check_text << " yes"
@ -274,11 +292,11 @@ get_build_dirs(string const & abs_binary,
// Check whether binary is a symbolic link. // Check whether binary is a symbolic link.
// If so, resolve it and repeat the exercise. // If so, resolve it and repeat the exercise.
if (!fs::symbolic_link_exists(FileName(binary).toFilesystemEncoding())) if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
break; break;
string link; FileName link;
if (readLink(binary, link, true)) { if (readLink(binary, link)) {
binary = link; binary = link;
} else { } else {
// Unable to resolve the link. // Unable to resolve the link.
@ -287,18 +305,18 @@ get_build_dirs(string const & abs_binary,
} }
lyxerr[Debug::INIT] << check_text << " no" << std::endl; lyxerr[Debug::INIT] << check_text << " no" << std::endl;
return std::make_pair(string(), string()); return std::make_pair(FileName(), FileName());
} }
// Specification of document_dir_ may be reset by LyXRC, // Specification of document_dir_ may be reset by LyXRC,
// but the default is fixed for a given OS. // but the default is fixed for a given OS.
string const get_document_dir(string const & home_dir) FileName const get_document_dir(FileName const & home_dir)
{ {
#if defined (USE_WINDOWS_PACKAGING) #if defined (USE_WINDOWS_PACKAGING)
(void)home_dir; // Silence warning about unused variable. (void)home_dir; // Silence warning about unused variable.
os::GetFolderPath win32_folder_path; os::GetFolderPath win32_folder_path;
return win32_folder_path(os::GetFolderPath::PERSONAL); return FileName(win32_folder_path(os::GetFolderPath::PERSONAL));
#else // Posix-like. #else // Posix-like.
return home_dir; return home_dir;
#endif #endif
@ -308,7 +326,7 @@ string const get_document_dir(string const & home_dir)
// The specification of home_dir_ is fixed for a given OS. // The specification of home_dir_ is fixed for a given OS.
// A typical example on Windows: "C:/Documents and Settings/USERNAME" // A typical example on Windows: "C:/Documents and Settings/USERNAME"
// and on a Posix-like machine: "/home/USERNAME". // and on a Posix-like machine: "/home/USERNAME".
string const get_home_dir() FileName const get_home_dir()
{ {
#if defined (USE_WINDOWS_PACKAGING) #if defined (USE_WINDOWS_PACKAGING)
string const home_dir = getEnv("USERPROFILE"); string const home_dir = getEnv("USERPROFILE");
@ -316,66 +334,67 @@ string const get_home_dir()
string const home_dir = getEnv("HOME"); string const home_dir = getEnv("HOME");
#endif #endif
return os::internal_path(home_dir); return FileName(fix_dir_name(home_dir));
} }
// Several sources are probed to ascertain the locale directory. // Several sources are probed to ascertain the locale directory.
// The only requirement is that the result is indeed a directory. // The only requirement is that the result is indeed a directory.
string const get_locale_dir(string const & system_support_dir) FileName const get_locale_dir(FileName const & system_support_dir)
{ {
// 1. Use the "LYX_LOCALEDIR" environment variable. // 1. Use the "LYX_LOCALEDIR" environment variable.
string const path_env = extract_env_var_dir("LYX_LOCALEDIR"); FileName const path_env = extract_env_var_dir("LYX_LOCALEDIR");
if (!path_env.empty() && check_env_var_dir(path_env, "LYX_LOCALEDIR")) if (!path_env.empty() && check_env_var_dir(path_env, "LYX_LOCALEDIR"))
return path_env; return path_env;
// 2. Search for system_support_dir / <relative locale dir> // 2. Search for system_support_dir / <relative locale dir>
// The <relative locale dir> is OS-dependent. (On Unix, it will // The <relative locale dir> is OS-dependent. (On Unix, it will
// be "../locale/".) // be "../locale/".)
FileName path(normalizePath(addPath(system_support_dir, relative_locale_dir()))); FileName path(normalizePath(addPath(system_support_dir.absFilename(),
relative_locale_dir())));
if (fs::exists(path.toFilesystemEncoding()) && if (fs::exists(path.toFilesystemEncoding()) &&
fs::is_directory(path.toFilesystemEncoding())) fs::is_directory(path.toFilesystemEncoding()))
return path.absFilename(); return path;
// 3. Fall back to the hard-coded LOCALEDIR. // 3. Fall back to the hard-coded LOCALEDIR.
path = FileName(hardcoded_localedir()); path = hardcoded_localedir();
if (fs::exists(path.toFilesystemEncoding()) && if (fs::exists(path.toFilesystemEncoding()) &&
fs::is_directory(path.toFilesystemEncoding())) fs::is_directory(path.toFilesystemEncoding()))
return path.absFilename(); return path;
return string(); return FileName();
} }
// Specification of temp_dir_ may be reset by LyXRC, // Specification of temp_dir_ may be reset by LyXRC,
// but the default is fixed for a given OS. // but the default is fixed for a given OS.
string const get_temp_dir() FileName const get_temp_dir()
{ {
#if defined (USE_WINDOWS_PACKAGING) #if defined (USE_WINDOWS_PACKAGING)
// Typical example: C:/TEMP/. // Typical example: C:/TEMP/.
char path[MAX_PATH]; char path[MAX_PATH];
GetTempPath(MAX_PATH, path); GetTempPath(MAX_PATH, path);
return os::internal_path(path); return FileName(os::internal_path(to_utf8(from_local8bit(path))));
#else // Posix-like. #else // Posix-like.
return "/tmp"; return FileName("/tmp");
#endif #endif
} }
// Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo" // Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
string const abs_path_from_command_line(string const & command_line) FileName const abs_path_from_command_line(string const & command_line)
{ {
if (command_line.empty()) if (command_line.empty())
return string(); return FileName();
string const path = os::internal_path(command_line); string const path = fix_dir_name(command_line);
return os::is_absolute_path(path) ? path : makeAbsPath(path).absFilename(); return os::is_absolute_path(path) ? FileName(path) : makeAbsPath(path);
} }
// Does the grunt work for abs_path_from_binary_name() // Does the grunt work for abs_path_from_binary_name()
string const get_binary_path(string const & exe) FileName const get_binary_path(string const & exe)
{ {
#if defined (USE_WINDOWS_PACKAGING) #if defined (USE_WINDOWS_PACKAGING)
// The executable may have been invoked either with or // The executable may have been invoked either with or
@ -388,19 +407,19 @@ string const get_binary_path(string const & exe)
string const exe_path = os::internal_path(exe); string const exe_path = os::internal_path(exe);
#endif #endif
if (os::is_absolute_path(exe_path)) if (os::is_absolute_path(exe_path))
return exe_path; return FileName(exe_path);
// Two possibilities present themselves. // Two possibilities present themselves.
// 1. The binary is relative to the CWD. // 1. The binary is relative to the CWD.
string const abs_exe_path = makeAbsPath(exe_path).absFilename(); FileName const abs_exe_path = makeAbsPath(exe_path);
if (fs::exists(FileName(abs_exe_path).toFilesystemEncoding())) if (fs::exists(abs_exe_path.toFilesystemEncoding()))
return abs_exe_path; return abs_exe_path;
// 2. exe must be the name of the binary only and it // 2. exe must be the name of the binary only and it
// can be found on the PATH. // can be found on the PATH.
string const exe_name = onlyFilename(exe_path); string const exe_name = onlyFilename(exe_path);
if (exe_name != exe_path) if (exe_name != exe_path)
return string(); return FileName();
std::vector<string> const path = getEnvPath("PATH"); std::vector<string> const path = getEnvPath("PATH");
std::vector<string>::const_iterator it = path.begin(); std::vector<string>::const_iterator it = path.begin();
@ -409,20 +428,20 @@ string const get_binary_path(string const & exe)
// This will do nothing if *it is already absolute. // This will do nothing if *it is already absolute.
string const exe_dir = makeAbsPath(*it).absFilename(); string const exe_dir = makeAbsPath(*it).absFilename();
string const exe_path = addName(exe_dir, exe_name); FileName const exe_path(addName(exe_dir, exe_name));
if (fs::exists(FileName(exe_path).toFilesystemEncoding())) if (fs::exists(exe_path.toFilesystemEncoding()))
return exe_path; return exe_path;
} }
// Didn't find anything. // Didn't find anything.
return string(); return FileName();
} }
// Extracts the absolute path to the binary name received as argv[0]. // Extracts the absolute path to the binary name received as argv[0].
string const abs_path_from_binary_name(string const & exe) FileName const abs_path_from_binary_name(string const & exe)
{ {
string const abs_binary = get_binary_path(exe); FileName const abs_binary = get_binary_path(exe);
if (abs_binary.empty()) { if (abs_binary.empty()) {
// FIXME UNICODE // FIXME UNICODE
throw ExceptionMessage(ErrorException, throw ExceptionMessage(ErrorException,
@ -437,21 +456,21 @@ string const abs_path_from_binary_name(string const & exe)
// A plethora of directories is searched to ascertain the system // A plethora of directories is searched to ascertain the system
// lyxdir which is defined as the first directory to contain // lyxdir which is defined as the first directory to contain
// "chkconfig.ltx". // "chkconfig.ltx".
string const FileName const
get_system_support_dir(string const & abs_binary, get_system_support_dir(FileName const & abs_binary,
string const & command_line_system_support_dir) string const & command_line_system_support_dir)
{ {
string const chkconfig_ltx = "chkconfig.ltx"; string const chkconfig_ltx = "chkconfig.ltx";
// searched_dirs is used for diagnostic purposes only in the case // searched_dirs is used for diagnostic purposes only in the case
// that "chkconfig.ltx" is not found. // that "chkconfig.ltx" is not found.
std::list<string> searched_dirs; std::list<FileName> searched_dirs;
// 1. Use the -sysdir command line parameter. // 1. Use the -sysdir command line parameter.
string path = abs_path_from_command_line(command_line_system_support_dir); FileName path = abs_path_from_command_line(command_line_system_support_dir);
if (!path.empty()) { if (!path.empty()) {
searched_dirs.push_back(path); searched_dirs.push_back(path);
if (check_command_line_dir(path, chkconfig_ltx, "-sysdir")) if (check_command_line_dir(path.absFilename(), chkconfig_ltx, "-sysdir"))
return path; return path;
} }
@ -472,27 +491,27 @@ get_system_support_dir(string const & abs_binary,
// One subtlety to be aware of. The name of the lyx binary may be // One subtlety to be aware of. The name of the lyx binary may be
// a symbolic link. If that is the case, then we follow the links too. // a symbolic link. If that is the case, then we follow the links too.
string binary = abs_binary; FileName binary = abs_binary;
while (true) { while (true) {
// Try and find "chkconfig.ltx". // Try and find "chkconfig.ltx".
string const binary_dir = onlyPath(binary); string const binary_dir = onlyPath(binary.absFilename());
string const lyxdir = FileName const lyxdir(
normalizePath(addPath(binary_dir, relative_lyxdir)); normalizePath(addPath(binary_dir, relative_lyxdir)));
searched_dirs.push_back(lyxdir); searched_dirs.push_back(lyxdir);
if (!fileSearch(lyxdir, chkconfig_ltx).empty()) { if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) {
// Success! "chkconfig.ltx" has been found. // Success! "chkconfig.ltx" has been found.
return lyxdir; return lyxdir;
} }
// Check whether binary is a symbolic link. // Check whether binary is a symbolic link.
// If so, resolve it and repeat the exercise. // If so, resolve it and repeat the exercise.
if (!fs::symbolic_link_exists(FileName(binary).toFilesystemEncoding())) if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
break; break;
string link; FileName link;
if (readLink(binary, link, true)) { if (readLink(binary, link)) {
binary = link; binary = link;
} else { } else {
// Unable to resolve the link. // Unable to resolve the link.
@ -501,16 +520,16 @@ get_system_support_dir(string const & abs_binary,
} }
// 4. Repeat the exercise on the directory itself. // 4. Repeat the exercise on the directory itself.
string binary_dir = onlyPath(abs_binary); FileName binary_dir(onlyPath(abs_binary.absFilename()));
while (true) { while (true) {
// This time test whether the directory is a symbolic link // This time test whether the directory is a symbolic link
// *before* looking for "chkconfig.ltx". // *before* looking for "chkconfig.ltx".
// (We've looked relative to the original already.) // (We've looked relative to the original already.)
if (!fs::symbolic_link_exists(FileName(binary).toFilesystemEncoding())) if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
break; break;
string link; FileName link;
if (readLink(binary_dir, link, true)) { if (readLink(binary_dir, link)) {
binary_dir = link; binary_dir = link;
} else { } else {
// Unable to resolve the link. // Unable to resolve the link.
@ -518,11 +537,11 @@ get_system_support_dir(string const & abs_binary,
} }
// Try and find "chkconfig.ltx". // Try and find "chkconfig.ltx".
string const lyxdir = FileName const lyxdir(
normalizePath(addPath(binary_dir, relative_lyxdir)); normalizePath(addPath(binary_dir.absFilename(), relative_lyxdir)));
searched_dirs.push_back(lyxdir); searched_dirs.push_back(lyxdir);
if (!fileSearch(lyxdir, chkconfig_ltx).empty()) { if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) {
// Success! "chkconfig.ltx" has been found. // Success! "chkconfig.ltx" has been found.
return lyxdir; return lyxdir;
} }
@ -530,19 +549,19 @@ get_system_support_dir(string const & abs_binary,
// 5. In desparation, try the hard-coded system support dir. // 5. In desparation, try the hard-coded system support dir.
path = hardcoded_system_support_dir(); path = hardcoded_system_support_dir();
if (!fileSearch(path, chkconfig_ltx).empty()) if (!fileSearch(path.absFilename(), chkconfig_ltx).empty())
return path; return path;
// Everything has failed :-( // Everything has failed :-(
// So inform the user and exit. // So inform the user and exit.
string searched_dirs_str; string searched_dirs_str;
typedef std::list<string>::const_iterator iterator; typedef std::list<FileName>::const_iterator iterator;
iterator const begin = searched_dirs.begin(); iterator const begin = searched_dirs.begin();
iterator const end = searched_dirs.end(); iterator const end = searched_dirs.end();
for (iterator it = begin; it != end; ++it) { for (iterator it = begin; it != end; ++it) {
if (it != begin) if (it != begin)
searched_dirs_str += "\n\t"; searched_dirs_str += "\n\t";
searched_dirs_str += *it; searched_dirs_str += it->absFilename();
} }
// FIXME UNICODE // FIXME UNICODE
@ -557,21 +576,21 @@ get_system_support_dir(string const & abs_binary,
from_utf8(searched_dirs_str))); from_utf8(searched_dirs_str)));
// Keep the compiler happy. // Keep the compiler happy.
return string(); return FileName();
} }
// Returns the absolute path to the user lyxdir, together with a flag // Returns the absolute path to the user lyxdir, together with a flag
// indicating whether this directory was specified explicitly (as -userdir // indicating whether this directory was specified explicitly (as -userdir
// or through an environment variable) or whether it was deduced. // or through an environment variable) or whether it was deduced.
std::pair<string, bool> const std::pair<FileName, bool> const
get_user_support_dir(string const & default_user_support_dir, get_user_support_dir(FileName const & default_user_support_dir,
string const & command_line_user_support_dir) string const & command_line_user_support_dir)
{ {
bool explicit_userdir = true; bool explicit_userdir = true;
// 1. Use the -userdir command line parameter. // 1. Use the -userdir command line parameter.
string path = FileName path =
abs_path_from_command_line(command_line_user_support_dir); abs_path_from_command_line(command_line_user_support_dir);
if (!path.empty()) if (!path.empty())
return std::make_pair(path, explicit_userdir); return std::make_pair(path, explicit_userdir);
@ -589,13 +608,13 @@ get_user_support_dir(string const & default_user_support_dir,
// $HOME/.lyx on POSIX but on Win32 it will be something like // $HOME/.lyx on POSIX but on Win32 it will be something like
// "C:/Documents and Settings/USERNAME/Application Data/LyX" // "C:/Documents and Settings/USERNAME/Application Data/LyX"
string const get_default_user_support_dir(string const & home_dir) FileName const get_default_user_support_dir(FileName const & home_dir)
{ {
#if defined (USE_WINDOWS_PACKAGING) #if defined (USE_WINDOWS_PACKAGING)
(void)home_dir; // Silence warning about unused variable. (void)home_dir; // Silence warning about unused variable.
os::GetFolderPath win32_folder_path; os::GetFolderPath win32_folder_path;
return addPath(win32_folder_path(os::GetFolderPath::APPDATA), PACKAGE); return FileName(addPath(win32_folder_path(os::GetFolderPath::APPDATA), PACKAGE));
#elif defined (USE_MACOSX_PACKAGING) #elif defined (USE_MACOSX_PACKAGING)
(void)home_dir; // Silence warning about unused variable. (void)home_dir; // Silence warning about unused variable.
@ -605,19 +624,20 @@ string const get_default_user_support_dir(string const & home_dir)
FSFindFolder(kUserDomain, kApplicationSupportFolderType, FSFindFolder(kUserDomain, kApplicationSupportFolderType,
kDontCreateFolder, &fsref); kDontCreateFolder, &fsref);
if (error_code != 0) if (error_code != 0)
return string(); return FileName();
// FSRefMakePath returns the result in utf8
char store[PATH_MAX + 1]; char store[PATH_MAX + 1];
OSStatus const status_code = OSStatus const status_code =
FSRefMakePath(&fsref, FSRefMakePath(&fsref,
reinterpret_cast<UInt8*>(store), PATH_MAX); reinterpret_cast<UInt8*>(store), PATH_MAX);
if (status_code != 0) if (status_code != 0)
return string(); return FileName();
return addPath(reinterpret_cast<char const *>(store), PACKAGE); return FileName(addPath(reinterpret_cast<char const *>(store), PACKAGE));
#else // USE_POSIX_PACKAGING #else // USE_POSIX_PACKAGING
return addPath(home_dir, string(".") + PACKAGE); return FileName(addPath(home_dir.absFilename(), string(".") + PACKAGE));
#endif #endif
} }
@ -642,26 +662,26 @@ bool check_command_line_dir(string const & dir,
// The environment variable @c env_var expands to a (single) file path. // The environment variable @c env_var expands to a (single) file path.
string const extract_env_var_dir(string const & env_var) FileName const extract_env_var_dir(string const & env_var)
{ {
string const dir = os::internal_path(getEnv(env_var)); string const dir = fix_dir_name(getEnv(env_var));
return dir.empty() ? dir : makeAbsPath(dir).absFilename(); return dir.empty() ? FileName() : makeAbsPath(dir);
} }
// Check that directory @c dir contains @c file. // Check that directory @c dir contains @c file.
// Else emit a warning about an invalid @c env_var. // Else emit a warning about an invalid @c env_var.
bool check_env_var_dir(string const & dir, bool check_env_var_dir(FileName const & dir,
string const & file, string const & file,
string const & env_var) string const & env_var)
{ {
FileName const abs_path = fileSearch(dir, file); FileName const abs_path = fileSearch(dir.absFilename(), file);
if (abs_path.empty()) { if (abs_path.empty()) {
// FIXME UNICODE // FIXME UNICODE
throw ExceptionMessage(WarningException, _("File not found"), bformat( throw ExceptionMessage(WarningException, _("File not found"), bformat(
_("Invalid %1$s environment variable.\n" _("Invalid %1$s environment variable.\n"
"Directory %2$s does not contain %3$s."), "Directory %2$s does not contain %3$s."),
from_utf8(env_var), from_utf8(dir), from_utf8(env_var), from_utf8(dir.absFilename()),
from_utf8(file))); from_utf8(file)));
} }
@ -671,10 +691,10 @@ bool check_env_var_dir(string const & dir,
// Check that directory @c dir is indeed a directory. // Check that directory @c dir is indeed a directory.
// Else emit a warning about an invalid @c env_var. // Else emit a warning about an invalid @c env_var.
bool check_env_var_dir(string const & dir, bool check_env_var_dir(FileName const & dir,
string const & env_var) string const & env_var)
{ {
string const encoded(FileName(dir).toFilesystemEncoding()); string const encoded(dir.toFilesystemEncoding());
bool const success = (fs::exists(encoded) && fs::is_directory(encoded)); bool const success = (fs::exists(encoded) && fs::is_directory(encoded));
if (!success) { if (!success) {
@ -687,7 +707,7 @@ bool check_env_var_dir(string const & dir,
_("Invalid %1$s environment variable.\n%2$s is not a directory."); _("Invalid %1$s environment variable.\n%2$s is not a directory.");
throw ExceptionMessage(WarningException, _("Directory not found"), bformat( throw ExceptionMessage(WarningException, _("Directory not found"), bformat(
fmt, from_utf8(env_var), from_utf8(dir))); fmt, from_utf8(env_var), from_utf8(dir.absFilename())));
} }
return success; return success;

View File

@ -15,6 +15,8 @@
#ifndef LYX_PACHAGE_H #ifndef LYX_PACHAGE_H
#define LYX_PACHAGE_H #define LYX_PACHAGE_H
#include "support/filename.h"
#include <string> #include <string>
namespace lyx { namespace lyx {
@ -69,25 +71,25 @@ public:
/** The directory containing the LyX executable. /** The directory containing the LyX executable.
*/ */
std::string const & binary_dir() const; FileName const & binary_dir() const;
/** The top of the LyX source code tree. /** The top of the LyX source code tree.
*/ */
static std::string const & top_srcdir(); static FileName const & top_srcdir();
/** The path to the system-level support files /** The path to the system-level support files
* we're actually going to use. * we're actually going to use.
*/ */
std::string const & system_support() const; FileName const & system_support() const;
/** The path to the autogenerated support files /** The path to the autogenerated support files
* when running in-place. * when running in-place.
*/ */
std::string const & build_support() const; FileName const & build_support() const;
/** The path to the user-level support files. /** The path to the user-level support files.
*/ */
std::string const & user_support() const; FileName const & user_support() const;
/** The user_support directory was set explicitly using either /** The user_support directory was set explicitly using either
* the -userdir command line switch or * the -userdir command line switch or
@ -97,23 +99,23 @@ public:
/** The path to the locale directory. /** The path to the locale directory.
*/ */
std::string const & locale_dir() const; FileName const & locale_dir() const;
/** The default document directory. /** The default document directory.
* Can be reset by LyXRC. * Can be reset by LyXRC.
*/ */
std::string & document_dir() const; FileName & document_dir() const;
/** The path to the system temporary directory. /** The path to the system temporary directory.
* (Eg /tmp on *nix.) * (Eg /tmp on *nix.)
*/ */
std::string const & system_temp_dir() const; FileName const & system_temp_dir() const;
/** The path to the temporary directory used by LyX. /** The path to the temporary directory used by LyX.
* (Eg /tmp/lyx_tmpdir800nBI1z9 on *nix.) * (Eg /tmp/lyx_tmpdir800nBI1z9 on *nix.)
* Can be reset by LyXRC. * Can be reset by LyXRC.
*/ */
std::string & temp_dir() const; FileName & temp_dir() const;
/** Used when setting the user_support directory. /** Used when setting the user_support directory.
* Used also when expanding "~/" or contracting to "~/". (filetools.C) * Used also when expanding "~/" or contracting to "~/". (filetools.C)
@ -121,21 +123,24 @@ public:
* for the dump. * for the dump.
* This may be empty (e. g. when run under a CGI environment) * This may be empty (e. g. when run under a CGI environment)
*/ */
std::string const & home_dir() const; FileName const & home_dir() const;
/// Command to run the configure script /** Command to run the configure script.
* Caution: This is "ready-to-run", i.e. in the locale encoding, not
* utf8.
*/
std::string const & configure_command() const; std::string const & configure_command() const;
private: private:
std::string binary_dir_; FileName binary_dir_;
std::string system_support_dir_; FileName system_support_dir_;
std::string build_support_dir_; FileName build_support_dir_;
std::string user_support_dir_; FileName user_support_dir_;
std::string locale_dir_; FileName locale_dir_;
mutable std::string document_dir_; mutable FileName document_dir_;
mutable std::string temp_dir_; mutable FileName temp_dir_;
std::string system_temp_dir_; FileName system_temp_dir_;
std::string home_dir_; FileName home_dir_;
std::string configure_command_; std::string configure_command_;
bool explicit_user_support_dir_; bool explicit_user_support_dir_;
}; };
@ -145,25 +150,25 @@ inline
Package::Package() {} Package::Package() {}
inline inline
std::string const & Package::binary_dir() const FileName const & Package::binary_dir() const
{ {
return binary_dir_; return binary_dir_;
} }
inline inline
std::string const & Package::system_support() const FileName const & Package::system_support() const
{ {
return system_support_dir_; return system_support_dir_;
} }
inline inline
std::string const & Package::build_support() const FileName const & Package::build_support() const
{ {
return build_support_dir_; return build_support_dir_;
} }
inline inline
std::string const & Package::user_support() const FileName const & Package::user_support() const
{ {
return user_support_dir_; return user_support_dir_;
} }
@ -175,31 +180,31 @@ bool Package::explicit_user_support() const
} }
inline inline
std::string const & Package::locale_dir() const FileName const & Package::locale_dir() const
{ {
return locale_dir_; return locale_dir_;
} }
inline inline
std::string & Package::document_dir() const FileName & Package::document_dir() const
{ {
return document_dir_; return document_dir_;
} }
inline inline
std::string & Package::temp_dir() const FileName & Package::temp_dir() const
{ {
return temp_dir_; return temp_dir_;
} }
inline inline
std::string const & Package::system_temp_dir() const FileName const & Package::system_temp_dir() const
{ {
return system_temp_dir_; return system_temp_dir_;
} }
inline inline
std::string const & Package::home_dir() const FileName const & Package::home_dir() const
{ {
return home_dir_; return home_dir_;
} }

View File

@ -14,7 +14,6 @@
#define PATH_C #define PATH_C
#include "support/path.h" #include "support/path.h"
#include "support/filename.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"
@ -24,13 +23,13 @@ using std::string;
namespace lyx { namespace lyx {
namespace support { namespace support {
Path::Path(string const & path) Path::Path(FileName const & path)
: popped_(false) : popped_(false)
{ {
if (!path.empty()) { if (!path.empty()) {
pushedDir_ = getcwd(); pushedDir_ = getcwd();
if (pushedDir_.empty() || chdir(FileName(path))) { if (pushedDir_.empty() || chdir(path)) {
/* FIXME: throw */ /* FIXME: throw */
} }
} else { } else {

View File

@ -37,7 +37,7 @@ namespace support {
class Path : boost::noncopyable { class Path : boost::noncopyable {
public: public:
/// change to the given directory /// change to the given directory
explicit Path(std::string const & path); explicit Path(FileName const & path);
/// set cwd to the previous value if needed /// set cwd to the previous value if needed
~Path(); ~Path();

View File

@ -80,8 +80,9 @@ int make_tempfile(char * templ)
FileName const tempName(FileName const & dir, string const & mask) FileName const tempName(FileName const & dir, string const & mask)
{ {
// FIXME UNICODE encoding of package().temp_dir() is probably wrong string const tmpdir(dir.empty() ?
string const tmpdir(dir.empty() ? package().temp_dir() : dir.toFilesystemEncoding()); package().temp_dir().toFilesystemEncoding() :
dir.toFilesystemEncoding());
string tmpfl(addName(tmpdir, mask)); string tmpfl(addName(tmpdir, mask));
#if defined (HAVE_GETPID) #if defined (HAVE_GETPID)
tmpfl += convert<string>(getpid()); tmpfl += convert<string>(getpid());

View File

@ -60,7 +60,7 @@ int VCS::doVCCommand(string const & cmd, string const & path)
{ {
LYXERR(Debug::LYXVC) << "doVCCommand: " << cmd << endl; LYXERR(Debug::LYXVC) << "doVCCommand: " << cmd << endl;
Systemcall one; Systemcall one;
support::Path p(path); support::Path p(FileName(path));
int const ret = one.startscript(Systemcall::Wait, cmd); int const ret = one.startscript(Systemcall::Wait, cmd);
return ret; return ret;
} }