From 5bef46157c4d7ee9813edcd56df6219fa7028bd2 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Sat, 26 Jan 2008 20:25:25 +0000 Subject: [PATCH] Add some comments, and change enum terminology to reflect actual purpose. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22685 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyX.cpp | 2 +- src/LyXFunc.cpp | 4 ++-- src/support/filetools.cpp | 8 ++++++-- src/support/filetools.h | 8 ++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/LyX.cpp b/src/LyX.cpp index b7a0376455..e12d859f40 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -530,7 +530,7 @@ int LyX::init(int & argc, char * argv[]) // the filename if necessary pimpl_->files_to_load_.push_back(fileSearch(string(), os::internal_path(to_utf8(from_local8bit(argv[argi]))), - "lyx", allow_unreadable)); + "lyx", may_not_exist)); } if (first_start) diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 966ad3a2d1..289c3f8923 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1930,9 +1930,9 @@ void LyXFunc::open(string const & fname) filename = fname; // get absolute path of file and add ".lyx" to the filename if - // necessary. we allow_unreadable because the file may not exist. + // necessary. FileName const fullname = - fileSearch(string(), filename, "lyx", support::allow_unreadable); + fileSearch(string(), filename, "lyx", support::may_not_exist); if (!fullname.empty()) filename = fullname.absFilename(); diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index aa9e8429b9..f84891c349 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -200,12 +200,12 @@ FileName const fileSearch(string const & path, string const & name, return fullname; if (ext.empty()) // We are done. - return mode == allow_unreadable ? fullname : FileName(); + return mode == may_not_exist ? fullname : FileName(); // Only add the extension if it is not already the extension of // fullname. if (getExtension(fullname.absFilename()) != ext) fullname = FileName(addExtension(fullname.absFilename(), ext)); - if (fullname.isReadableFile() || mode == allow_unreadable) + if (fullname.isReadableFile() || mode == may_not_exist) return fullname; return FileName(); } @@ -375,6 +375,10 @@ string const onlyPath(string const & filename) // Convert relative path into absolute path based on a basepath. // If relpath is absolute, just use that. // If basepath is empty, use CWD as base. +// Note that basePath can be a relative path, in the sense that it may +// not begin with "/" (e.g.), but it should NOT contain such constructs +// as "/../". +// FIXME It might be nice if the code didn't simply assume that. FileName const makeAbsPath(string const & relPath, string const & basePath) { FileName relative_path(relPath); diff --git a/src/support/filetools.h b/src/support/filetools.h index 936b7113cb..dadde24c5d 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -46,11 +46,11 @@ FileName const fileOpenSearch(std::string const & path, /// How to search files enum search_mode { - // The file must exist (return an empty file name otherwise) - standard_mode, + /// The file must exist (return an empty file name otherwise) + must_exist, /// Only do file name expansion, return the complete name even if /// the file does not exist - allow_unreadable + may_not_exist }; /** Returns the real name of file name in directory path, with optional @@ -61,7 +61,7 @@ enum search_mode { FileName const fileSearch(std::string const & path, std::string const & name, std::string const & ext = std::string(), - search_mode mode = standard_mode); + search_mode mode = must_exist); /// bool isLyXFilename(std::string const & filename); -- 2.39.2