3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * parts Copyright 1985, 1990, 1993 Free Software Foundation, Inc.
8 * \author Ivan Schreter
9 * \author Dirk Niggemann
10 * \author Asger Alstrup
11 * \author Lars Gullik Bjønnes
12 * \author Jean-Marc Lasgouttes
13 * \author Angus Leeming
17 * Full author contact details are available in file CREDITS.
19 * General path-mangling functions
26 #include "support/filetools.h"
28 #include "support/debug.h"
29 #include "support/environment.h"
30 #include "support/gettext.h"
31 #include "support/lstrings.h"
32 #include "support/os.h"
33 #include "support/Package.h"
34 #include "support/Path.h"
35 #include "support/Systemcall.h"
36 #include "support/qstring_helpers.h"
40 #include "support/lassert.h"
41 #include "support/regex.h"
65 bool isLyXFileName(string const & filename)
67 return suffixIs(ascii_lowercase(filename), ".lyx");
71 bool isSGMLFileName(string const & filename)
73 return suffixIs(ascii_lowercase(filename), ".sgml");
77 bool isValidLaTeXFileName(string const & filename)
79 string const invalid_chars("#%\"");
80 return filename.find_first_of(invalid_chars) == string::npos;
84 bool isValidDVIFileName(string const & filename)
86 string const invalid_chars("${}()[]^");
87 return filename.find_first_of(invalid_chars) == string::npos;
91 string const latex_path(string const & original_path,
92 latex_path_extension extension,
95 // On cygwin, we may need windows or posix style paths.
96 string path = os::latex_path(original_path);
97 path = subst(path, "~", "\\string~");
98 if (path.find(' ') != string::npos) {
99 // We can't use '"' because " is sometimes active (e.g. if
100 // babel is loaded with the "german" option)
101 if (extension == EXCLUDE_EXTENSION) {
102 // ChangeExtension calls os::internal_path internally
103 // so don't use it to remove the extension.
104 string const ext = getExtension(path);
105 string const base = ext.empty() ?
107 path.substr(0, path.length() - ext.length() - 1);
108 // ChangeExtension calls os::internal_path internally
109 // so don't use it to re-add the extension.
110 path = "\\string\"" + base + "\\string\"." + ext;
112 path = "\\string\"" + path + "\\string\"";
116 return dots == ESCAPE_DOTS ? subst(path, ".", "\\lyxdot ") : path;
120 // Substitutes spaces with underscores in filename (and path)
121 FileName const makeLatexName(FileName const & file)
123 string name = file.onlyFileName();
124 string const path = file.onlyPath().absFileName() + "/";
126 // ok so we scan through the string twice, but who cares.
127 // FIXME: in Unicode time this will break for sure! There is
128 // a non-latin world out there...
129 string const keep = "abcdefghijklmnopqrstuvwxyz"
130 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
131 "@!'()*+,-./0123456789:;<=>?[]`|";
133 string::size_type pos = 0;
134 while ((pos = name.find_first_not_of(keep, pos)) != string::npos)
137 FileName latex_name(path + name);
138 latex_name.changeExtension(".tex");
143 string const quoteName(string const & name, quote_style style)
147 // This does not work on native Windows for filenames
148 // containing the following characters < > : " / \ | ? *
149 // Moreover, it can't be made to work, as, according to
150 // http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
151 // those are reserved characters, and thus are forbidden.
152 // Please, also note that the command-line parser in
153 // ForkedCall::generateChild cannot deal with filenames
154 // containing " or ', therefore we don't pass user filenames
155 // to child processes if possible. We store them in a python
156 // script instead, where we don't have these limitations.
158 return (os::shell() == os::UNIX) ?
159 '\'' + subst(name, "'", "\'\\\'\'") + '\'' :
162 // According to the QProcess parser, a single double
163 // quote is represented by three consecutive ones.
164 // Here we simply escape the double quote and let our
165 // simple parser in Systemcall.cpp do the substitution.
166 return '"' + subst(name, "\"", "\\\"") + '"';
169 return "\"" + subst(subst(name, "\\", "\\\\"), "\"", "\\\"")
172 // shut up stupid compiler
178 // Uses a string of paths separated by ";"s to find a file to open.
179 // Can't cope with pathnames with a ';' in them. Returns full path to file.
180 // If path entry begins with $$LyX/, use system_lyxdir
181 // If path entry begins with $$User/, use user_lyxdir
182 // Example: "$$User/doc;$$LyX/doc"
183 FileName const fileOpenSearch(string const & path, string const & name,
188 bool notfound = true;
189 string tmppath = split(path, path_element, ';');
191 while (notfound && !path_element.empty()) {
192 path_element = os::internal_path(path_element);
193 if (!suffixIs(path_element, '/'))
195 path_element = subst(path_element, "$$LyX",
196 package().system_support().absFileName());
197 path_element = subst(path_element, "$$User",
198 package().user_support().absFileName());
200 real_file = fileSearch(path_element, name, ext);
202 if (real_file.empty()) {
204 tmppath = split(tmppath, path_element, ';');
205 } while (!tmppath.empty() && path_element.empty());
215 // Returns the real name of file name in directory path, with optional
217 FileName const fileSearch(string const & path, string const & name,
218 string const & ext, search_mode mode)
220 // if `name' is an absolute path, we ignore the setting of `path'
221 // Expand Environmentvariables in 'name'
222 string const tmpname = replaceEnvironmentPath(name);
223 FileName fullname(makeAbsPath(tmpname, path));
224 // search first without extension, then with it.
225 if (fullname.isReadableFile())
229 return mode == may_not_exist ? fullname : FileName();
230 // Only add the extension if it is not already the extension of
232 if (getExtension(fullname.absFileName()) != ext)
233 fullname = FileName(addExtension(fullname.absFileName(), ext));
234 if (fullname.isReadableFile() || mode == may_not_exist)
240 // Search the file name.ext in the subdirectory dir of
242 // 2) build_lyxdir (if not empty)
244 FileName const libFileSearch(string const & dir, string const & name,
247 FileName fullname = fileSearch(addPath(package().user_support().absFileName(), dir),
249 if (!fullname.empty())
252 if (!package().build_support().empty())
253 fullname = fileSearch(addPath(package().build_support().absFileName(), dir),
255 if (!fullname.empty())
258 return fileSearch(addPath(package().system_support().absFileName(), dir), name, ext);
262 FileName const i18nLibFileSearch(string const & dir, string const & name,
265 /* The highest priority value is the `LANGUAGE' environment
266 variable. But we don't use the value if the currently
267 selected locale is the C locale. This is a GNU extension.
269 Otherwise, w use a trick to guess what support/gettext.has done:
270 each po file is able to tell us its name. (JMarc)
273 string lang = to_ascii(_(languageTestString()));
274 string const language = getEnv("LANGUAGE");
275 if (!lang.empty() && !language.empty())
279 lang = split(lang, l, ':');
282 // First try with the full name
283 tmp = libFileSearch(addPath(dir, l), name, ext);
287 // Then the name without country code
288 string const shortl = token(l, '_', 0);
290 tmp = libFileSearch(addPath(dir, shortl), name, ext);
296 // For compatibility, to be removed later (JMarc)
297 tmp = libFileSearch(dir, token(l, '_', 0) + '_' + name,
300 lyxerr << "i18nLibFileSearch: File `" << tmp
301 << "' has been found by the old method" <<endl;
305 lang = split(lang, l, ':');
308 return libFileSearch(dir, name, ext);
312 FileName const imageLibFileSearch(string & dir, string const & name,
315 if (!lyx::lyxrc.icon_set.empty()) {
316 string const imagedir = addPath(dir, lyx::lyxrc.icon_set);
317 FileName const fn = libFileSearch(imagedir, name, ext);
323 return libFileSearch(dir, name, ext);
327 string const libScriptSearch(string const & command_in, quote_style style)
329 static string const token_scriptpath = "$$s/";
331 string command = command_in;
332 // Find the starting position of "$$s/"
333 string::size_type const pos1 = command.find(token_scriptpath);
334 if (pos1 == string::npos)
336 // Find the end of the "$$s/some_subdir/some_script" word within
337 // command. Assumes that the script name does not contain spaces.
338 string::size_type const start_script = pos1 + 4;
339 string::size_type const pos2 = command.find(' ', start_script);
340 string::size_type const size_script = pos2 == string::npos?
341 (command.size() - start_script) : pos2 - start_script;
343 // Does this script file exist?
344 string const script =
345 libFileSearch(".", command.substr(start_script, size_script)).absFileName();
347 if (script.empty()) {
348 // Replace "$$s/" with ""
349 command.erase(pos1, 4);
351 // Replace "$$s/foo/some_script" with "<path to>/some_script".
352 string::size_type const size_replace = size_script + 4;
353 command.replace(pos1, size_replace, quoteName(script, style));
360 static FileName createTmpDir(FileName const & tempdir, string const & mask)
362 LYXERR(Debug::FILES, "createTmpDir: tempdir=`" << tempdir << "'\n"
363 << "createTmpDir: mask=`" << mask << '\'');
365 FileName const tmpfl = FileName::tempName(tempdir, mask);
367 if (tmpfl.empty() || !tmpfl.createDirectory(0700)) {
368 LYXERR0("LyX could not create temporary directory in " << tempdir
377 FileName const createLyXTmpDir(FileName const & deflt)
379 if (deflt.empty() || deflt == package().system_temp_dir())
380 return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
382 if (deflt.createDirectory(0777))
385 if (deflt.isDirWritable()) {
386 // deflt could not be created because it
387 // did exist already, so let's create our own
389 return createTmpDir(deflt, "lyx_tmpdir");
391 // some other error occured.
392 return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
397 // Strip filename from path name
398 string const onlyPath(string const & filename)
400 // If empty filename, return empty
401 if (filename.empty())
404 // Find last / or start of filename
405 size_t j = filename.rfind('/');
406 return j == string::npos ? "./" : filename.substr(0, j + 1);
410 // Convert relative path into absolute path based on a basepath.
411 // If relpath is absolute, just use that.
412 // If basepath is empty, use CWD as base.
413 // Note that basePath can be a relative path, in the sense that it may
414 // not begin with "/" (e.g.), but it should NOT contain such constructs
416 // FIXME It might be nice if the code didn't simply assume that.
417 FileName const makeAbsPath(string const & relPath, string const & basePath)
419 // checks for already absolute path
420 if (FileName::isAbsolute(relPath))
421 return FileName(relPath);
423 // Copies given paths
424 string tempRel = os::internal_path(relPath);
425 // Since TempRel is NOT absolute, we can safely replace "//" with "/"
426 tempRel = subst(tempRel, "//", "/");
430 if (FileName::isAbsolute(basePath))
433 tempBase = addPath(FileName::getcwd().absFileName(), basePath);
435 // Handle /./ at the end of the path
436 while (suffixIs(tempBase, "/./"))
437 tempBase.erase(tempBase.length() - 2);
439 // processes relative path
440 string rTemp = tempRel;
443 // Check for a leading "~"
445 rTemp = split(rTemp, temp, '/');
447 tempBase = package().home_dir().absFileName();
452 while (!rTemp.empty()) {
454 rTemp = split(rTemp, temp, '/');
456 if (temp == ".") continue;
458 // Remove one level of TempBase
459 if (tempBase.length() <= 1) {
460 //this is supposed to be an absolute path, so...
464 //erase a trailing slash if there is one
465 if (suffixIs(tempBase, "/"))
466 tempBase.erase(tempBase.length() - 1, string::npos);
468 string::size_type i = tempBase.length() - 1;
469 while (i > 0 && tempBase[i] != '/')
472 tempBase.erase(i, string::npos);
475 } else if (temp.empty() && !rTemp.empty()) {
476 tempBase = os::current_root() + rTemp;
479 // Add this piece to TempBase
480 if (!suffixIs(tempBase, '/'))
486 // returns absolute path
487 return FileName(tempBase);
491 // Correctly append filename to the pathname.
492 // If pathname is '.', then don't use pathname.
493 // Chops any path of filename.
494 string const addName(string const & path, string const & fname)
496 string const basename = onlyFileName(fname);
499 if (path != "." && path != "./" && !path.empty()) {
500 buf = os::internal_path(path);
501 if (!suffixIs(path, '/'))
505 return buf + basename;
509 // Strips path from filename
510 string const onlyFileName(string const & fname)
515 string::size_type j = fname.rfind('/');
516 if (j == string::npos) // no '/' in fname
520 return fname.substr(j + 1);
524 // Create absolute path. If impossible, don't do anything
525 // Supports ./ and ~/. Later we can add support for ~logname/. (Asger)
526 string const expandPath(string const & path)
528 // checks for already absolute path
529 string rTemp = replaceEnvironmentPath(path);
530 if (FileName::isAbsolute(rTemp))
534 string const copy = rTemp;
537 rTemp = split(rTemp, temp, '/');
540 return FileName::getcwd().absFileName() + '/' + rTemp;
543 return package().home_dir().absFileName() + '/' + rTemp;
546 return makeAbsPath(copy).absFileName();
548 // Don't know how to handle this
553 // Search the string for ${VAR} and $VAR and replace VAR using getenv.
554 string const replaceEnvironmentPath(string const & path)
556 // ${VAR} is defined as
557 // $\{[A-Za-z_][A-Za-z_0-9]*\}
558 static string const envvar_br = "[$]\\{([A-Za-z_][A-Za-z_0-9]*)\\}";
560 // $VAR is defined as:
561 // $[A-Za-z_][A-Za-z_0-9]*
562 static string const envvar = "[$]([A-Za-z_][A-Za-z_0-9]*)";
564 static regex envvar_br_re("(.*)" + envvar_br + "(.*)");
565 static regex envvar_re("(.*)" + envvar + "(.*)");
566 string result = path;
569 if (!regex_match(result, what, envvar_br_re)) {
570 if (!regex_match(result, what, envvar_re))
573 string env_var = getEnv(what.str(2));
574 result = what.str(1) + env_var + what.str(3);
580 // Make relative path out of two absolute paths
581 docstring const makeRelPath(docstring const & abspath, docstring const & basepath)
582 // Makes relative path out of absolute path. If it is deeper than basepath,
583 // it's easy. If basepath and abspath share something (they are all deeper
584 // than some directory), it'll be rendered using ..'s. If they are completely
585 // different, then the absolute path will be used as relative path.
587 docstring::size_type const abslen = abspath.length();
588 docstring::size_type const baselen = basepath.length();
590 docstring::size_type i = os::common_path(abspath, basepath);
593 // actually no match - cannot make it relative
597 // Count how many dirs there are in basepath above match
598 // and append as many '..''s into relpath
600 docstring::size_type j = i;
601 while (j < baselen) {
602 if (basepath[j] == '/') {
603 if (j + 1 == baselen)
610 // Append relative stuff from common directory to abspath
611 if (abspath[i] == '/')
613 for (; i < abslen; ++i)
616 if (suffixIs(buf, '/'))
617 buf.erase(buf.length() - 1);
618 // Substitute empty with .
625 // Append sub-directory(ies) to a path in an intelligent way
626 string const addPath(string const & path, string const & path_2)
629 string const path2 = os::internal_path(path_2);
631 if (!path.empty() && path != "." && path != "./") {
632 buf = os::internal_path(path);
633 if (path[path.length() - 1] != '/')
637 if (!path2.empty()) {
638 string::size_type const p2start = path2.find_first_not_of('/');
639 string::size_type const p2end = path2.find_last_not_of('/');
640 string const tmp = path2.substr(p2start, p2end - p2start + 1);
647 string const changeExtension(string const & oldname, string const & extension)
649 string::size_type const last_slash = oldname.rfind('/');
650 string::size_type last_dot = oldname.rfind('.');
651 if (last_dot < last_slash && last_slash != string::npos)
652 last_dot = string::npos;
655 // Make sure the extension starts with a dot
656 if (!extension.empty() && extension[0] != '.')
657 ext= '.' + extension;
661 return os::internal_path(oldname.substr(0, last_dot) + ext);
665 string const removeExtension(string const & name)
667 return changeExtension(name, string());
671 string const addExtension(string const & name, string const & extension)
673 if (!extension.empty() && extension[0] != '.')
674 return name + '.' + extension;
675 return name + extension;
679 /// Return the extension of the file (not including the .)
680 string const getExtension(string const & name)
682 string::size_type const last_slash = name.rfind('/');
683 string::size_type const last_dot = name.rfind('.');
684 if (last_dot != string::npos &&
685 (last_slash == string::npos || last_dot > last_slash))
686 return name.substr(last_dot + 1,
687 name.length() - (last_dot + 1));
693 string const unzippedFileName(string const & zipped_file)
695 string const ext = getExtension(zipped_file);
696 if (ext == "gz" || ext == "z" || ext == "Z")
697 return changeExtension(zipped_file, string());
698 return onlyPath(zipped_file) + "unzipped_" + onlyFileName(zipped_file);
702 FileName const unzipFile(FileName const & zipped_file, string const & unzipped_file)
704 FileName const tempfile = FileName(unzipped_file.empty() ?
705 unzippedFileName(zipped_file.toFilesystemEncoding()) :
708 string const command = "gunzip -c " +
709 zipped_file.toFilesystemEncoding() + " > " +
710 tempfile.toFilesystemEncoding();
712 one.startscript(Systemcall::Wait, command);
713 // test that command was executed successfully (anon)
714 // yes, please do. (Lgb)
719 docstring const makeDisplayPath(string const & path, unsigned int threshold)
723 // If file is from LyXDir, display it as if it were relative.
724 string const system = package().system_support().absFileName();
725 if (prefixIs(str, system) && str != system)
726 return from_utf8("[" + str.erase(0, system.length()) + "]");
728 // replace /home/blah with ~/
729 string const home = package().home_dir().absFileName();
730 if (!home.empty() && prefixIs(str, home))
731 str = subst(str, home, "~");
733 if (str.length() <= threshold)
734 return from_utf8(os::external_path(str));
736 string const prefix = ".../";
739 while (str.length() > threshold)
740 str = split(str, temp, '/');
742 // Did we shorten everything away?
744 // Yes, filename itself is too long.
745 // Pick the start and the end of the filename.
746 str = onlyFileName(path);
747 string const head = str.substr(0, threshold / 2 - 3);
749 string::size_type len = str.length();
751 str.substr(len - threshold / 2 - 2, len - 1);
752 str = head + "..." + tail;
755 return from_utf8(os::external_path(prefix + str));
760 bool readLink(FileName const & file, FileName & link)
762 char linkbuffer[PATH_MAX + 1];
763 string const encoded = file.toFilesystemEncoding();
764 int const nRead = ::readlink(encoded.c_str(),
765 linkbuffer, sizeof(linkbuffer) - 1);
768 linkbuffer[nRead] = '\0'; // terminator
769 link = makeAbsPath(linkbuffer, onlyPath(file.absFileName()));
773 bool readLink(FileName const &, FileName &)
780 cmd_ret const runCommand(string const & cmd)
782 // FIXME: replace all calls to RunCommand with ForkedCall
783 // (if the output is not needed) or the code in ISpell.cpp
784 // (if the output is needed).
786 // One question is if we should use popen or
787 // create our own popen based on fork, exec, pipe
788 // of course the best would be to have a
789 // pstream (process stream), with the
790 // variants ipstream, opstream
795 PROCESS_INFORMATION process;
796 SECURITY_ATTRIBUTES security;
800 security.nLength = sizeof(SECURITY_ATTRIBUTES);
801 security.bInheritHandle = TRUE;
802 security.lpSecurityDescriptor = NULL;
804 if (CreatePipe(&in, &out, &security, 0)) {
805 memset(&startup, 0, sizeof(STARTUPINFO));
806 memset(&process, 0, sizeof(PROCESS_INFORMATION));
808 startup.cb = sizeof(STARTUPINFO);
809 startup.dwFlags = STARTF_USESTDHANDLES;
811 startup.hStdError = GetStdHandle(STD_ERROR_HANDLE);
812 startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
813 startup.hStdOutput = out;
815 if (CreateProcess(0, (LPTSTR)cmd.c_str(), &security, &security,
816 TRUE, CREATE_NO_WINDOW, 0, 0, &startup, &process)) {
818 CloseHandle(process.hThread);
819 fno = _open_osfhandle((long)in, _O_RDONLY);
821 inf = _fdopen(fno, "r");
824 #elif defined (HAVE_POPEN)
825 FILE * inf = ::popen(cmd.c_str(), os::popen_read_mode());
826 #elif defined (HAVE__POPEN)
827 FILE * inf = ::_popen(cmd.c_str(), os::popen_read_mode());
829 #error No popen() function.
832 // (Claus Hentschel) Check if popen was successful ;-)
834 lyxerr << "RunCommand:: could not start child process" << endl;
835 return make_pair(-1, string());
841 ret += static_cast<char>(c);
846 WaitForSingleObject(process.hProcess, INFINITE);
847 CloseHandle(process.hProcess);
848 int const pret = fclose(inf);
849 #elif defined (HAVE_PCLOSE)
850 int const pret = pclose(inf);
851 #elif defined (HAVE__PCLOSE)
852 int const pret = _pclose(inf);
854 #error No pclose() function.
858 perror("RunCommand:: could not terminate child process");
860 return make_pair(pret, ret);
864 FileName const findtexfile(string const & fil, string const & /*format*/)
866 /* There is no problem to extend this function too use other
867 methods to look for files. It could be setup to look
868 in environment paths and also if wanted as a last resort
869 to a recursive find. One of the easier extensions would
870 perhaps be to use the LyX file lookup methods. But! I am
871 going to implement this until I see some demand for it.
875 // If the file can be found directly, we just return a
876 // absolute path version of it.
877 FileName const absfile(makeAbsPath(fil));
878 if (absfile.exists())
881 // Now we try to find it using kpsewhich.
882 // It seems from the kpsewhich manual page that it is safe to use
883 // kpsewhich without --format: "When the --format option is not
884 // given, the search path used when looking for a file is inferred
885 // from the name given, by looking for a known extension. If no
886 // known extension is found, the search path for TeX source files
888 // However, we want to take advantage of the format sine almost all
889 // the different formats has environment variables that can be used
890 // to controll which paths to search. f.ex. bib looks in
891 // BIBINPUTS and TEXBIB. Small list follows:
892 // bib - BIBINPUTS, TEXBIB
894 // graphic/figure - TEXPICTS, TEXINPUTS
895 // ist - TEXINDEXSTYLE, INDEXSTYLE
896 // pk - PROGRAMFONTS, PKFONTS, TEXPKS, GLYPHFONTS, TEXFONTS
898 // tfm - TFMFONTS, TEXFONTS
899 // This means that to use kpsewhich in the best possible way we
900 // should help it by setting additional path in the approp. envir.var.
901 string const kpsecmd = "kpsewhich " + fil;
903 cmd_ret const c = runCommand(kpsecmd);
905 LYXERR(Debug::LATEX, "kpse status = " << c.first << '\n'
906 << "kpse result = `" << rtrim(c.second, "\n\r") << '\'');
908 return FileName(rtrim(to_utf8(from_filesystem8bit(c.second)), "\n\r"));
914 void readBB_lyxerrMessage(FileName const & file, bool & zipped,
915 string const & message)
917 LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] " << message);
918 // FIXME: Why is this func deleting a file? (Lgb)
924 string const readBB_from_PSFile(FileName const & file)
926 // in a (e)ps-file it's an entry like %%BoundingBox:23 45 321 345
927 // It seems that every command in the header has an own line,
928 // getline() should work for all files.
929 // On the other hand some plot programs write the bb at the
930 // end of the file. Than we have in the header:
931 // %%BoundingBox: (atend)
932 // In this case we must check the end.
933 bool zipped = file.isZippedFile();
934 FileName const file_ = zipped ? unzipFile(file) : file;
935 string const format = file_.guessFormatFromContents();
937 if (format != "eps" && format != "ps") {
938 readBB_lyxerrMessage(file_, zipped,"no(e)ps-format");
942 static lyx::regex bbox_re(
943 "^%%BoundingBox:\\s*([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)");
944 ifstream is(file_.toFilesystemEncoding().c_str());
949 if (regex_match(s, what, bbox_re)) {
950 // Our callers expect the tokens in the string
951 // separated by single spaces.
952 // FIXME: change return type from string to something
955 os << what.str(1) << ' ' << what.str(2) << ' '
956 << what.str(3) << ' ' << what.str(4);
957 string const bb = os.str();
958 readBB_lyxerrMessage(file_, zipped, bb);
962 readBB_lyxerrMessage(file_, zipped, "no bb found");
967 int compare_timestamps(FileName const & file1, FileName const & file2)
969 // If the original is newer than the copy, then copy the original
970 // to the new directory.
973 if (file1.exists() && file2.exists()) {
974 double const tmp = difftime(file1.lastModified(), file2.lastModified());
976 cmp = tmp > 0 ? 1 : -1;
978 } else if (file1.exists()) {
980 } else if (file2.exists()) {
988 bool prefs2prefs(FileName const & filename, FileName const & tempfile, bool lfuns)
990 FileName const script = libFileSearch("scripts", "prefs2prefs.py");
991 if (script.empty()) {
992 LYXERR0("Could not find bind file conversion "
993 "script prefs2prefs.py.");
997 ostringstream command;
998 command << os::python() << ' ' << quoteName(script.toFilesystemEncoding())
999 << ' ' << (lfuns ? "-l" : "-p") << ' '
1000 << quoteName(filename.toFilesystemEncoding())
1001 << ' ' << quoteName(tempfile.toFilesystemEncoding());
1002 string const command_str = command.str();
1004 LYXERR(Debug::FILES, "Running `" << command_str << '\'');
1006 cmd_ret const ret = runCommand(command_str);
1007 if (ret.first != 0) {
1008 LYXERR0("Could not run file conversion script prefs2prefs.py.");
1015 } //namespace support