#include <config.h>
+#include "support/filetools.h"
+
#include "support/convert.h"
+#include "support/debug.h"
#include "support/environment.h"
-#include "support/filetools.h"
+#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/Package.h"
#include "support/Path.h"
#include "support/Systemcall.h"
+#include "support/qstring_helpers.h"
-// FIXME Interface violation
-#include "gettext.h"
-#include "debug.h"
+#include <QDir>
#include <boost/assert.hpp>
-#include <boost/filesystem/operations.hpp>
#include <boost/regex.hpp>
#include <fcntl.h>
#include <fstream>
#include <sstream>
-using std::endl;
-using std::getline;
-using std::make_pair;
-using std::string;
-using std::ifstream;
-using std::ostringstream;
-using std::vector;
-using std::pair;
-
-namespace fs = boost::filesystem;
+using namespace std;
namespace lyx {
namespace support {
// Substitutes spaces with underscores in filename (and path)
-string const makeLatexName(string const & file)
+FileName const makeLatexName(FileName const & file)
{
- string name = onlyFilename(file);
- string const path = onlyPath(file);
+ string name = file.onlyFileName();
+ string const path = file.onlyPath().absFilename() + "/";
// ok so we scan through the string twice, but who cares.
+ // FIXME: in Unicode time this will break for sure! There is
+ // a non-latin world out there...
string const keep = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"@!'()*+,-./0123456789:;<=>?[]`|";
while ((pos = name.find_first_not_of(keep, pos)) != string::npos)
name[pos++] = '_';
- return addName(path, name);
+ FileName latex_name(path + name);
+ latex_name.changeExtension(".tex");
+ return latex_name;
}
#endif
-/// Returns a vector of all files in directory dir having extension ext.
-vector<FileName> const dirList(FileName const & dir, string const & ext)
-{
- // EXCEPTIONS FIXME. Rewrite needed when we turn on exceptions. (Lgb)
- vector<FileName> dirlist;
-
- if (!(dir.exists() && dir.isDirectory())) {
- LYXERR(Debug::FILES, "Directory \"" << dir
- << "\" does not exist to DirList.");
- return dirlist;
- }
-
- string extension;
- if (!ext.empty() && ext[0] != '.')
- extension += '.';
- extension += ext;
-
- string const encoded_dir = dir.toFilesystemEncoding();
- fs::directory_iterator dit(encoded_dir);
- fs::directory_iterator end;
- for (; dit != end; ++dit) {
- string const & fil = dit->leaf();
- if (suffixIs(fil, extension))
- dirlist.push_back(FileName::fromFilesystemEncoding(
- encoded_dir + '/' + fil));
- }
- return dirlist;
-}
-
-
// Returns the real name of file name in directory path, with optional
// extension ext.
FileName const fileSearch(string const & path, string const & name,
string const tmpname = replaceEnvironmentPath(name);
FileName fullname(makeAbsPath(tmpname, path));
// search first without extension, then with it.
- if (fullname.isReadable())
+ if (fullname.isReadableFile())
return fullname;
if (ext.empty())
// We are done.
// fullname.
if (getExtension(fullname.absFilename()) != ext)
fullname = FileName(addExtension(fullname.absFilename(), ext));
- if (fullname.isReadable() || mode == allow_unreadable)
+ if (fullname.isReadableFile() || mode == allow_unreadable)
return fullname;
return FileName();
}
variable. But we don't use the value if the currently
selected locale is the C locale. This is a GNU extension.
- Otherwise, w use a trick to guess what gettext has done:
+ Otherwise, w use a trick to guess what support/gettext.has done:
each po file is able to tell us its name. (JMarc)
*/
// 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);
+ tmpfl.removeFile();
if (tmpfl.empty() || mkdir(tmpfl, 0700)) {
lyxerr << "LyX could not create the temporary directory '"
}
// returns absolute path
- return FileName(os::internal_path(tempBase));
+ return FileName(tempBase);
}
}
-// Normalize a path. Constracts path/../path
-// Can't handle "../../" or "/../" (Asger)
-// Also converts paths like /foo//bar ==> /foo/bar
-string const normalizePath(string const & path)
-{
- // Normalize paths like /foo//bar ==> /foo/bar
- static boost::regex regex("/{2,}");
- string const tmppath = boost::regex_merge(path, regex, "/");
-
- fs::path const npath = fs::path(tmppath, fs::no_check).normalize();
-
- if (!npath.is_complete())
- return "./" + npath.string() + '/';
-
- return npath.string() + '/';
-}
-
-
// Search the string for ${VAR} and $VAR and replace VAR using getenv.
string const replaceEnvironmentPath(string const & path)
{
LYXERR(Debug::LATEX, "kpse status = " << c.first << '\n'
<< "kpse result = `" << rtrim(c.second, "\n\r") << '\'');
if (c.first != -1)
- return FileName(os::internal_path(rtrim(to_utf8(from_filesystem8bit(c.second)),
- "\n\r")));
+ return FileName(rtrim(to_utf8(from_filesystem8bit(c.second)), "\n\r"));
else
return FileName();
}
a += '#';
FileName const autosave(a);
if (autosave.exists())
- unlink(autosave);
+ autosave.removeFile();
}
LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] " << message);
// FIXME: Why is this func deleting a file? (Lgb)
if (zipped)
- unlink(file);
+ file.removeFile();
}
static boost::regex bbox_re(
"^%%BoundingBox:\\s*([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)");
- std::ifstream is(file_.toFilesystemEncoding().c_str());
+ ifstream is(file_.toFilesystemEncoding().c_str());
while (is) {
string s;
getline(is,s);
return cmp;
}
+
} //namespace support
} // namespace lyx