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
24 #include "support/filetools.h"
26 #include "support/debug.h"
27 #include "support/environment.h"
28 #include "support/gettext.h"
29 #include "support/lstrings.h"
30 #include "support/os.h"
31 #include "support/Package.h"
32 #include "support/Path.h"
33 #include "support/Systemcall.h"
34 #include "support/qstring_helpers.h"
38 #include "support/lassert.h"
39 #include "support/regex.h"
63 bool isLyXFileName(string const & filename)
65 return suffixIs(ascii_lowercase(filename), ".lyx");
69 bool isSGMLFileName(string const & filename)
71 return suffixIs(ascii_lowercase(filename), ".sgml");
75 bool isValidLaTeXFileName(string const & filename)
77 string const invalid_chars("#%\"");
78 return filename.find_first_of(invalid_chars) == string::npos;
82 bool isValidDVIFileName(string const & filename)
84 string const invalid_chars("${}()[]^");
85 return filename.find_first_of(invalid_chars) == string::npos;
89 string const latex_path(string const & original_path,
90 latex_path_extension extension,
93 // On cygwin, we may need windows or posix style paths.
94 string path = os::latex_path(original_path);
95 path = subst(path, "~", "\\string~");
96 if (path.find(' ') != string::npos) {
97 // We can't use '"' because " is sometimes active (e.g. if
98 // babel is loaded with the "german" option)
99 if (extension == EXCLUDE_EXTENSION) {
100 // ChangeExtension calls os::internal_path internally
101 // so don't use it to remove the extension.
102 string const ext = getExtension(path);
103 string const base = ext.empty() ?
105 path.substr(0, path.length() - ext.length() - 1);
106 // ChangeExtension calls os::internal_path internally
107 // so don't use it to re-add the extension.
108 path = "\\string\"" + base + "\\string\"." + ext;
110 path = "\\string\"" + path + "\\string\"";
114 return dots == ESCAPE_DOTS ? subst(path, ".", "\\lyxdot ") : path;
118 // Substitutes spaces with underscores in filename (and path)
119 FileName const makeLatexName(FileName const & file)
121 string name = file.onlyFileName();
122 string const path = file.onlyPath().absFileName() + "/";
124 // ok so we scan through the string twice, but who cares.
125 // FIXME: in Unicode time this will break for sure! There is
126 // a non-latin world out there...
127 string const keep = "abcdefghijklmnopqrstuvwxyz"
128 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
129 "@!'()*+,-./0123456789:;<=>?[]`|";
131 string::size_type pos = 0;
132 while ((pos = name.find_first_not_of(keep, pos)) != string::npos)
135 FileName latex_name(path + name);
136 latex_name.changeExtension(".tex");
141 string const quoteName(string const & name, quote_style style)
145 // This does not work on native Windows for filenames
146 // containing the following characters < > : " / \ | ? *
147 // Moreover, it can't be made to work, as, according to
148 // http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
149 // those are reserved characters, and thus are forbidden.
150 // Please, also note that the command-line parser in
151 // ForkedCall::generateChild cannot deal with filenames
152 // containing " or ', therefore we don't pass user filenames
153 // to child processes if possible. We store them in a python
154 // script instead, where we don't have these limitations.
156 return (os::shell() == os::UNIX) ?
157 '\'' + subst(name, "'", "\'\\\'\'") + '\'' :
160 // According to the QProcess parser, a single double
161 // quote is represented by three consecutive ones.
162 // Here we simply escape the double quote and let our
163 // simple parser in Systemcall.cpp do the substitution.
164 return '"' + subst(name, "\"", "\\\"") + '"';
167 return "\"" + subst(subst(name, "\\", "\\\\"), "\"", "\\\"")
170 // shut up stupid compiler
176 // Uses a string of paths separated by ";"s to find a file to open.
177 // Can't cope with pathnames with a ';' in them. Returns full path to file.
178 // If path entry begins with $$LyX/, use system_lyxdir
179 // If path entry begins with $$User/, use user_lyxdir
180 // Example: "$$User/doc;$$LyX/doc"
181 FileName const fileOpenSearch(string const & path, string const & name,
186 bool notfound = true;
187 string tmppath = split(path, path_element, ';');
189 while (notfound && !path_element.empty()) {
190 path_element = os::internal_path(path_element);
191 if (!suffixIs(path_element, '/'))
193 path_element = subst(path_element, "$$LyX",
194 package().system_support().absFileName());
195 path_element = subst(path_element, "$$User",
196 package().user_support().absFileName());
198 real_file = fileSearch(path_element, name, ext);
200 if (real_file.empty()) {
202 tmppath = split(tmppath, path_element, ';');
203 } while (!tmppath.empty() && path_element.empty());
213 // Returns the real name of file name in directory path, with optional
215 FileName const fileSearch(string const & path, string const & name,
216 string const & ext, search_mode mode)
218 // if `name' is an absolute path, we ignore the setting of `path'
219 // Expand Environmentvariables in 'name'
220 string const tmpname = replaceEnvironmentPath(name);
221 FileName fullname(makeAbsPath(tmpname, path));
222 // search first without extension, then with it.
223 if (fullname.isReadableFile())
227 return mode == may_not_exist ? fullname : FileName();
228 // Only add the extension if it is not already the extension of
230 if (getExtension(fullname.absFileName()) != ext)
231 fullname = FileName(addExtension(fullname.absFileName(), ext));
232 if (fullname.isReadableFile() || mode == may_not_exist)
238 // Search the file name.ext in the subdirectory dir of
240 // 2) build_lyxdir (if not empty)
242 FileName const libFileSearch(string const & dir, string const & name,
245 FileName fullname = fileSearch(addPath(package().user_support().absFileName(), dir),
247 if (!fullname.empty())
250 if (!package().build_support().empty())
251 fullname = fileSearch(addPath(package().build_support().absFileName(), dir),
253 if (!fullname.empty())
256 return fileSearch(addPath(package().system_support().absFileName(), dir), name, ext);
260 FileName const i18nLibFileSearch(string const & dir, string const & name,
263 /* The highest priority value is the `LANGUAGE' environment
264 variable. But we don't use the value if the currently
265 selected locale is the C locale. This is a GNU extension.
267 Otherwise, w use a trick to guess what support/gettext.has done:
268 each po file is able to tell us its name. (JMarc)
271 string lang = to_ascii(_(languageTestString()));
272 string const language = getEnv("LANGUAGE");
273 if (!lang.empty() && !language.empty())
277 lang = split(lang, l, ':');
280 // First try with the full name
281 tmp = libFileSearch(addPath(dir, l), name, ext);
285 // Then the name without country code
286 string const shortl = token(l, '_', 0);
288 tmp = libFileSearch(addPath(dir, shortl), name, ext);
294 // For compatibility, to be removed later (JMarc)
295 tmp = libFileSearch(dir, token(l, '_', 0) + '_' + name,
298 lyxerr << "i18nLibFileSearch: File `" << tmp
299 << "' has been found by the old method" <<endl;
303 lang = split(lang, l, ':');
306 return libFileSearch(dir, name, ext);
310 string const libScriptSearch(string const & command_in, quote_style style)
312 static string const token_scriptpath = "$$s/";
314 string command = command_in;
315 // Find the starting position of "$$s/"
316 string::size_type const pos1 = command.find(token_scriptpath);
317 if (pos1 == string::npos)
319 // Find the end of the "$$s/some_subdir/some_script" word within
320 // command. Assumes that the script name does not contain spaces.
321 string::size_type const start_script = pos1 + 4;
322 string::size_type const pos2 = command.find(' ', start_script);
323 string::size_type const size_script = pos2 == string::npos?
324 (command.size() - start_script) : pos2 - start_script;
326 // Does this script file exist?
327 string const script =
328 libFileSearch(".", command.substr(start_script, size_script)).absFileName();
330 if (script.empty()) {
331 // Replace "$$s/" with ""
332 command.erase(pos1, 4);
334 // Replace "$$s/foo/some_script" with "<path to>/some_script".
335 string::size_type const size_replace = size_script + 4;
336 command.replace(pos1, size_replace, quoteName(script, style));
343 static FileName createTmpDir(FileName const & tempdir, string const & mask)
345 LYXERR(Debug::FILES, "createTmpDir: tempdir=`" << tempdir << "'\n"
346 << "createTmpDir: mask=`" << mask << '\'');
348 FileName const tmpfl = FileName::tempName(tempdir, mask);
350 if (tmpfl.empty() || !tmpfl.createDirectory(0700)) {
351 LYXERR0("LyX could not create temporary directory in " << tempdir
360 FileName const createLyXTmpDir(FileName const & deflt)
362 if (deflt.empty() || deflt == package().system_temp_dir())
363 return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
365 if (deflt.createDirectory(0777))
368 if (deflt.isDirWritable()) {
369 // deflt could not be created because it
370 // did exist already, so let's create our own
372 return createTmpDir(deflt, "lyx_tmpdir");
374 // some other error occured.
375 return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
380 // Strip filename from path name
381 string const onlyPath(string const & filename)
383 // If empty filename, return empty
384 if (filename.empty())
387 // Find last / or start of filename
388 size_t j = filename.rfind('/');
389 return j == string::npos ? "./" : filename.substr(0, j + 1);
393 // Convert relative path into absolute path based on a basepath.
394 // If relpath is absolute, just use that.
395 // If basepath is empty, use CWD as base.
396 // Note that basePath can be a relative path, in the sense that it may
397 // not begin with "/" (e.g.), but it should NOT contain such constructs
399 // FIXME It might be nice if the code didn't simply assume that.
400 FileName const makeAbsPath(string const & relPath, string const & basePath)
402 // checks for already absolute path
403 if (FileName::isAbsolute(relPath))
404 return FileName(relPath);
406 // Copies given paths
407 string tempRel = os::internal_path(relPath);
408 // Since TempRel is NOT absolute, we can safely replace "//" with "/"
409 tempRel = subst(tempRel, "//", "/");
413 if (FileName::isAbsolute(basePath))
416 tempBase = addPath(FileName::getcwd().absFileName(), basePath);
418 // Handle /./ at the end of the path
419 while (suffixIs(tempBase, "/./"))
420 tempBase.erase(tempBase.length() - 2);
422 // processes relative path
423 string rTemp = tempRel;
426 // Check for a leading "~"
428 rTemp = split(rTemp, temp, '/');
430 tempBase = package().home_dir().absFileName();
435 while (!rTemp.empty()) {
437 rTemp = split(rTemp, temp, '/');
439 if (temp == ".") continue;
441 // Remove one level of TempBase
442 if (tempBase.length() <= 1) {
443 //this is supposed to be an absolute path, so...
447 //erase a trailing slash if there is one
448 if (suffixIs(tempBase, "/"))
449 tempBase.erase(tempBase.length() - 1, string::npos);
451 string::size_type i = tempBase.length() - 1;
452 while (i > 0 && tempBase[i] != '/')
455 tempBase.erase(i, string::npos);
458 } else if (temp.empty() && !rTemp.empty()) {
459 tempBase = os::current_root() + rTemp;
462 // Add this piece to TempBase
463 if (!suffixIs(tempBase, '/'))
469 // returns absolute path
470 return FileName(tempBase);
474 // Correctly append filename to the pathname.
475 // If pathname is '.', then don't use pathname.
476 // Chops any path of filename.
477 string const addName(string const & path, string const & fname)
479 string const basename = onlyFileName(fname);
482 if (path != "." && path != "./" && !path.empty()) {
483 buf = os::internal_path(path);
484 if (!suffixIs(path, '/'))
488 return buf + basename;
492 // Strips path from filename
493 string const onlyFileName(string const & fname)
498 string::size_type j = fname.rfind('/');
499 if (j == string::npos) // no '/' in fname
503 return fname.substr(j + 1);
507 // Create absolute path. If impossible, don't do anything
508 // Supports ./ and ~/. Later we can add support for ~logname/. (Asger)
509 string const expandPath(string const & path)
511 // checks for already absolute path
512 string rTemp = replaceEnvironmentPath(path);
513 if (FileName::isAbsolute(rTemp))
517 string const copy = rTemp;
520 rTemp = split(rTemp, temp, '/');
523 return FileName::getcwd().absFileName() + '/' + rTemp;
526 return package().home_dir().absFileName() + '/' + rTemp;
529 return makeAbsPath(copy).absFileName();
531 // Don't know how to handle this
536 // Search the string for ${VAR} and $VAR and replace VAR using getenv.
537 string const replaceEnvironmentPath(string const & path)
539 // ${VAR} is defined as
540 // $\{[A-Za-z_][A-Za-z_0-9]*\}
541 static string const envvar_br = "[$]\\{([A-Za-z_][A-Za-z_0-9]*)\\}";
543 // $VAR is defined as:
544 // $[A-Za-z_][A-Za-z_0-9]*
545 static string const envvar = "[$]([A-Za-z_][A-Za-z_0-9]*)";
547 static regex envvar_br_re("(.*)" + envvar_br + "(.*)");
548 static regex envvar_re("(.*)" + envvar + "(.*)");
551 string remaining = path;
553 regex_match(remaining, what, envvar_br_re);
554 if (!what[0].matched) {
555 regex_match(remaining, what, envvar_re);
556 if (!what[0].matched) {
561 string env_var = getEnv(what.str(2));
562 if (!env_var.empty())
563 result += what.str(1) + env_var;
565 result += what.str(1) + "$" + what.str(2);
566 remaining = what.str(3);
572 // Make relative path out of two absolute paths
573 docstring const makeRelPath(docstring const & abspath, docstring const & basepath)
574 // Makes relative path out of absolute path. If it is deeper than basepath,
575 // it's easy. If basepath and abspath share something (they are all deeper
576 // than some directory), it'll be rendered using ..'s. If they are completely
577 // different, then the absolute path will be used as relative path.
579 docstring::size_type const abslen = abspath.length();
580 docstring::size_type const baselen = basepath.length();
582 docstring::size_type i = os::common_path(abspath, basepath);
585 // actually no match - cannot make it relative
589 // Count how many dirs there are in basepath above match
590 // and append as many '..''s into relpath
592 docstring::size_type j = i;
593 while (j < baselen) {
594 if (basepath[j] == '/') {
595 if (j + 1 == baselen)
602 // Append relative stuff from common directory to abspath
603 if (abspath[i] == '/')
605 for (; i < abslen; ++i)
608 if (suffixIs(buf, '/'))
609 buf.erase(buf.length() - 1);
610 // Substitute empty with .
617 // Append sub-directory(ies) to a path in an intelligent way
618 string const addPath(string const & path, string const & path_2)
621 string const path2 = os::internal_path(path_2);
623 if (!path.empty() && path != "." && path != "./") {
624 buf = os::internal_path(path);
625 if (path[path.length() - 1] != '/')
629 if (!path2.empty()) {
630 string::size_type const p2start = path2.find_first_not_of('/');
631 string::size_type const p2end = path2.find_last_not_of('/');
632 string const tmp = path2.substr(p2start, p2end - p2start + 1);
639 string const changeExtension(string const & oldname, string const & extension)
641 string::size_type const last_slash = oldname.rfind('/');
642 string::size_type last_dot = oldname.rfind('.');
643 if (last_dot < last_slash && last_slash != string::npos)
644 last_dot = string::npos;
647 // Make sure the extension starts with a dot
648 if (!extension.empty() && extension[0] != '.')
649 ext= '.' + extension;
653 return os::internal_path(oldname.substr(0, last_dot) + ext);
657 string const removeExtension(string const & name)
659 return changeExtension(name, string());
663 string const addExtension(string const & name, string const & extension)
665 if (!extension.empty() && extension[0] != '.')
666 return name + '.' + extension;
667 return name + extension;
671 /// Return the extension of the file (not including the .)
672 string const getExtension(string const & name)
674 string::size_type const last_slash = name.rfind('/');
675 string::size_type const last_dot = name.rfind('.');
676 if (last_dot != string::npos &&
677 (last_slash == string::npos || last_dot > last_slash))
678 return name.substr(last_dot + 1,
679 name.length() - (last_dot + 1));
685 string const unzippedFileName(string const & zipped_file)
687 string const ext = getExtension(zipped_file);
688 if (ext == "gz" || ext == "z" || ext == "Z")
689 return changeExtension(zipped_file, string());
690 return onlyPath(zipped_file) + "unzipped_" + onlyFileName(zipped_file);
694 FileName const unzipFile(FileName const & zipped_file, string const & unzipped_file)
696 FileName const tempfile = FileName(unzipped_file.empty() ?
697 unzippedFileName(zipped_file.toFilesystemEncoding()) :
700 string const command = "gunzip -c " +
701 zipped_file.toFilesystemEncoding() + " > " +
702 tempfile.toFilesystemEncoding();
704 one.startscript(Systemcall::Wait, command);
705 // test that command was executed successfully (anon)
706 // yes, please do. (Lgb)
711 docstring const makeDisplayPath(string const & path, unsigned int threshold)
715 // If file is from LyXDir, display it as if it were relative.
716 string const system = package().system_support().absFileName();
717 if (prefixIs(str, system) && str != system)
718 return from_utf8("[" + str.erase(0, system.length()) + "]");
720 // replace /home/blah with ~/
721 string const home = package().home_dir().absFileName();
722 if (!home.empty() && prefixIs(str, home))
723 str = subst(str, home, "~");
725 if (str.length() <= threshold)
726 return from_utf8(os::external_path(str));
728 string const prefix = ".../";
731 while (str.length() > threshold)
732 str = split(str, temp, '/');
734 // Did we shorten everything away?
736 // Yes, filename itself is too long.
737 // Pick the start and the end of the filename.
738 str = onlyFileName(path);
739 string const head = str.substr(0, threshold / 2 - 3);
741 string::size_type len = str.length();
743 str.substr(len - threshold / 2 - 2, len - 1);
744 str = head + "..." + tail;
747 return from_utf8(os::external_path(prefix + str));
752 bool readLink(FileName const & file, FileName & link)
754 char linkbuffer[PATH_MAX + 1];
755 string const encoded = file.toFilesystemEncoding();
756 int const nRead = ::readlink(encoded.c_str(),
757 linkbuffer, sizeof(linkbuffer) - 1);
760 linkbuffer[nRead] = '\0'; // terminator
761 link = makeAbsPath(linkbuffer, onlyPath(file.absFileName()));
765 bool readLink(FileName const &, FileName &)
772 cmd_ret const runCommand(string const & cmd)
774 // FIXME: replace all calls to RunCommand with ForkedCall
775 // (if the output is not needed) or the code in ISpell.cpp
776 // (if the output is needed).
778 // One question is if we should use popen or
779 // create our own popen based on fork, exec, pipe
780 // of course the best would be to have a
781 // pstream (process stream), with the
782 // variants ipstream, opstream
787 PROCESS_INFORMATION process;
788 SECURITY_ATTRIBUTES security;
792 security.nLength = sizeof(SECURITY_ATTRIBUTES);
793 security.bInheritHandle = TRUE;
794 security.lpSecurityDescriptor = NULL;
796 if (CreatePipe(&in, &out, &security, 0)) {
797 memset(&startup, 0, sizeof(STARTUPINFO));
798 memset(&process, 0, sizeof(PROCESS_INFORMATION));
800 startup.cb = sizeof(STARTUPINFO);
801 startup.dwFlags = STARTF_USESTDHANDLES;
803 startup.hStdError = GetStdHandle(STD_ERROR_HANDLE);
804 startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
805 startup.hStdOutput = out;
807 if (CreateProcess(0, (LPTSTR)cmd.c_str(), &security, &security,
808 TRUE, CREATE_NO_WINDOW, 0, 0, &startup, &process)) {
810 CloseHandle(process.hThread);
811 fno = _open_osfhandle((long)in, _O_RDONLY);
813 inf = _fdopen(fno, "r");
816 #elif defined (HAVE_POPEN)
817 FILE * inf = ::popen(cmd.c_str(), os::popen_read_mode());
818 #elif defined (HAVE__POPEN)
819 FILE * inf = ::_popen(cmd.c_str(), os::popen_read_mode());
821 #error No popen() function.
824 // (Claus Hentschel) Check if popen was successful ;-)
826 lyxerr << "RunCommand:: could not start child process" << endl;
827 return make_pair(-1, string());
833 ret += static_cast<char>(c);
838 WaitForSingleObject(process.hProcess, INFINITE);
839 CloseHandle(process.hProcess);
840 int const pret = fclose(inf);
841 #elif defined (HAVE_PCLOSE)
842 int const pret = pclose(inf);
843 #elif defined (HAVE__PCLOSE)
844 int const pret = _pclose(inf);
846 #error No pclose() function.
850 perror("RunCommand:: could not terminate child process");
852 return make_pair(pret, ret);
856 FileName const findtexfile(string const & fil, string const & /*format*/)
858 /* There is no problem to extend this function too use other
859 methods to look for files. It could be setup to look
860 in environment paths and also if wanted as a last resort
861 to a recursive find. One of the easier extensions would
862 perhaps be to use the LyX file lookup methods. But! I am
863 going to implement this until I see some demand for it.
867 // If the file can be found directly, we just return a
868 // absolute path version of it.
869 FileName const absfile(makeAbsPath(fil));
870 if (absfile.exists())
873 // Now we try to find it using kpsewhich.
874 // It seems from the kpsewhich manual page that it is safe to use
875 // kpsewhich without --format: "When the --format option is not
876 // given, the search path used when looking for a file is inferred
877 // from the name given, by looking for a known extension. If no
878 // known extension is found, the search path for TeX source files
880 // However, we want to take advantage of the format sine almost all
881 // the different formats has environment variables that can be used
882 // to controll which paths to search. f.ex. bib looks in
883 // BIBINPUTS and TEXBIB. Small list follows:
884 // bib - BIBINPUTS, TEXBIB
886 // graphic/figure - TEXPICTS, TEXINPUTS
887 // ist - TEXINDEXSTYLE, INDEXSTYLE
888 // pk - PROGRAMFONTS, PKFONTS, TEXPKS, GLYPHFONTS, TEXFONTS
890 // tfm - TFMFONTS, TEXFONTS
891 // This means that to use kpsewhich in the best possible way we
892 // should help it by setting additional path in the approp. envir.var.
893 string const kpsecmd = "kpsewhich " + fil;
895 cmd_ret const c = runCommand(kpsecmd);
897 LYXERR(Debug::LATEX, "kpse status = " << c.first << '\n'
898 << "kpse result = `" << rtrim(c.second, "\n\r") << '\'');
900 return FileName(rtrim(to_utf8(from_filesystem8bit(c.second)), "\n\r"));
906 void readBB_lyxerrMessage(FileName const & file, bool & zipped,
907 string const & message)
909 LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] " << message);
910 // FIXME: Why is this func deleting a file? (Lgb)
916 string const readBB_from_PSFile(FileName const & file)
918 // in a (e)ps-file it's an entry like %%BoundingBox:23 45 321 345
919 // It seems that every command in the header has an own line,
920 // getline() should work for all files.
921 // On the other hand some plot programs write the bb at the
922 // end of the file. Than we have in the header:
923 // %%BoundingBox: (atend)
924 // In this case we must check the end.
925 bool zipped = file.isZippedFile();
926 FileName const file_ = zipped ? unzipFile(file) : file;
927 string const format = file_.guessFormatFromContents();
929 if (format != "eps" && format != "ps") {
930 readBB_lyxerrMessage(file_, zipped,"no(e)ps-format");
934 static lyx::regex bbox_re(
935 "^%%BoundingBox:\\s*([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)");
936 ifstream is(file_.toFilesystemEncoding().c_str());
941 if (regex_match(s, what, bbox_re)) {
942 // Our callers expect the tokens in the string
943 // separated by single spaces.
944 // FIXME: change return type from string to something
947 os << what.str(1) << ' ' << what.str(2) << ' '
948 << what.str(3) << ' ' << what.str(4);
949 string const bb = os.str();
950 readBB_lyxerrMessage(file_, zipped, bb);
954 readBB_lyxerrMessage(file_, zipped, "no bb found");
959 int compare_timestamps(FileName const & file1, FileName const & file2)
961 // If the original is newer than the copy, then copy the original
962 // to the new directory.
965 if (file1.exists() && file2.exists()) {
966 double const tmp = difftime(file1.lastModified(), file2.lastModified());
968 cmp = tmp > 0 ? 1 : -1;
970 } else if (file1.exists()) {
972 } else if (file2.exists()) {
980 bool prefs2prefs(FileName const & filename, FileName const & tempfile, bool lfuns)
982 FileName const script = libFileSearch("scripts", "prefs2prefs.py");
983 if (script.empty()) {
984 LYXERR0("Could not find bind file conversion "
985 "script prefs2prefs.py.");
989 ostringstream command;
990 command << os::python() << ' ' << quoteName(script.toFilesystemEncoding())
991 << ' ' << (lfuns ? "-l" : "-p") << ' '
992 << quoteName(filename.toFilesystemEncoding())
993 << ' ' << quoteName(tempfile.toFilesystemEncoding());
994 string const command_str = command.str();
996 LYXERR(Debug::FILES, "Running `" << command_str << '\'');
998 cmd_ret const ret = runCommand(command_str);
999 if (ret.first != 0) {
1000 LYXERR0("Could not run file conversion script prefs2prefs.py.");
1007 } //namespace support