2002-09-25 10:03:41 +00:00
|
|
|
/**
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
* \file filetools.cpp
|
2002-09-25 10:03:41 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* parts Copyright 1985, 1990, 1993 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* \author Ivan Schreter
|
|
|
|
* \author Dirk Niggemann
|
|
|
|
* \author Asger Alstrup
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2002-09-25 10:03:41 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
2003-06-18 09:56:10 +00:00
|
|
|
* \author Angus Leeming
|
|
|
|
* \author John Levon
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Herbert Voß
|
2002-09-25 10:03:41 +00:00
|
|
|
*
|
2003-09-08 09:51:40 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 10:03:41 +00:00
|
|
|
*
|
|
|
|
* General path-mangling functions
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
|
|
|
|
#include "support/debug.h"
|
2005-02-15 13:45:41 +00:00
|
|
|
#include "support/environment.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/gettext.h"
|
2005-02-15 13:45:41 +00:00
|
|
|
#include "support/lstrings.h"
|
2004-11-07 13:22:51 +00:00
|
|
|
#include "support/os.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
#include "support/Package.h"
|
|
|
|
#include "support/Path.h"
|
|
|
|
#include "support/Systemcall.h"
|
2007-12-02 09:59:26 +00:00
|
|
|
#include "support/qstring_helpers.h"
|
|
|
|
|
|
|
|
#include <QDir>
|
2001-07-29 15:34:18 +00:00
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2003-09-25 23:01:43 +00:00
|
|
|
#include <boost/regex.hpp>
|
2003-09-09 17:25:35 +00:00
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
2005-04-21 14:03:30 +00:00
|
|
|
#include <cerrno>
|
2002-06-10 07:57:39 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <fstream>
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2002-06-10 07:57:39 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2009-05-11 22:03:52 +00:00
|
|
|
#define USE_QPROCESS
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace support {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-04-08 09:09:57 +00:00
|
|
|
bool isLyXFilename(string const & filename)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-07-16 21:17:10 +00:00
|
|
|
return suffixIs(ascii_lowercase(filename), ".lyx");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-08 09:09:57 +00:00
|
|
|
bool isSGMLFilename(string const & filename)
|
2000-11-13 15:43:36 +00:00
|
|
|
{
|
2002-07-16 21:17:10 +00:00
|
|
|
return suffixIs(ascii_lowercase(filename), ".sgml");
|
2000-11-13 15:43:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-26 16:55:42 +00:00
|
|
|
bool isValidLaTeXFilename(string const & filename)
|
|
|
|
{
|
|
|
|
string const invalid_chars("#$%{}()[]\"^");
|
2007-10-18 23:03:51 +00:00
|
|
|
return filename.find_first_of(invalid_chars) == string::npos;
|
2007-06-26 16:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-10 09:31:27 +00:00
|
|
|
string const latex_path(string const & original_path,
|
|
|
|
latex_path_extension extension,
|
|
|
|
latex_path_dots dots)
|
2005-04-18 17:43:11 +00:00
|
|
|
{
|
2006-03-24 12:48:37 +00:00
|
|
|
// On cygwin, we may need windows or posix style paths.
|
2006-04-05 19:26:08 +00:00
|
|
|
string path = os::latex_path(original_path);
|
2005-04-18 17:43:11 +00:00
|
|
|
path = subst(path, "~", "\\string~");
|
2005-07-14 22:09:22 +00:00
|
|
|
if (path.find(' ') != string::npos) {
|
2005-06-21 09:01:41 +00:00
|
|
|
// We can't use '"' because " is sometimes active (e.g. if
|
|
|
|
// babel is loaded with the "german" option)
|
2005-07-10 09:31:27 +00:00
|
|
|
if (extension == EXCLUDE_EXTENSION) {
|
2006-04-05 19:26:08 +00:00
|
|
|
// ChangeExtension calls os::internal_path internally
|
|
|
|
// so don't use it to remove the extension.
|
2006-04-08 22:31:11 +00:00
|
|
|
string const ext = getExtension(path);
|
2006-04-05 19:26:08 +00:00
|
|
|
string const base = ext.empty() ?
|
|
|
|
path :
|
|
|
|
path.substr(0, path.length() - ext.length() - 1);
|
2005-07-08 15:43:46 +00:00
|
|
|
// ChangeExtension calls os::internal_path internally
|
|
|
|
// so don't use it to re-add the extension.
|
|
|
|
path = "\\string\"" + base + "\\string\"." + ext;
|
2005-07-14 22:09:22 +00:00
|
|
|
} else {
|
2005-07-08 15:43:46 +00:00
|
|
|
path = "\\string\"" + path + "\\string\"";
|
2005-07-14 22:09:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dots == ESCAPE_DOTS ? subst(path, ".", "\\lyxdot ") : path;
|
2005-04-18 17:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Substitutes spaces with underscores in filename (and path)
|
2007-11-28 18:07:09 +00:00
|
|
|
FileName const makeLatexName(FileName const & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-11-28 18:07:09 +00:00
|
|
|
string name = file.onlyFileName();
|
|
|
|
string const path = file.onlyPath().absFilename() + "/";
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-11-02 21:19:58 +00:00
|
|
|
// ok so we scan through the string twice, but who cares.
|
2007-11-28 18:07:09 +00:00
|
|
|
// FIXME: in Unicode time this will break for sure! There is
|
|
|
|
// a non-latin world out there...
|
2005-07-14 22:09:22 +00:00
|
|
|
string const keep = "abcdefghijklmnopqrstuvwxyz"
|
1999-11-03 12:24:23 +00:00
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
2007-02-25 09:00:28 +00:00
|
|
|
"@!'()*+,-./0123456789:;<=>?[]`|";
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-11-02 21:19:58 +00:00
|
|
|
string::size_type pos = 0;
|
2005-07-14 22:09:22 +00:00
|
|
|
while ((pos = name.find_first_not_of(keep, pos)) != string::npos)
|
1999-11-03 12:45:11 +00:00
|
|
|
name[pos++] = '_';
|
2005-07-14 22:09:22 +00:00
|
|
|
|
2007-11-28 18:07:09 +00:00
|
|
|
FileName latex_name(path + name);
|
|
|
|
latex_name.changeExtension(".tex");
|
|
|
|
return latex_name;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
|
2006-09-11 16:07:49 +00:00
|
|
|
string const quoteName(string const & name, quote_style style)
|
1999-12-03 13:51:01 +00:00
|
|
|
{
|
2006-09-11 16:07:49 +00:00
|
|
|
switch(style) {
|
|
|
|
case quote_shell:
|
2009-12-19 19:29:53 +00:00
|
|
|
// This does not work on native Windows for filenames
|
|
|
|
// containing the following characters < > : " / \ | ? *
|
|
|
|
// Moreover, it can't be made to work, as, according to
|
|
|
|
// http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
|
|
|
|
// those are reserved characters, and thus are forbidden.
|
|
|
|
// Please, also note that the command-line parser in
|
|
|
|
// ForkedCall::generateChild cannot deal with filenames
|
|
|
|
// containing " or ', therefore we don't pass user filenames
|
|
|
|
// to child processes if possible. We store them in a python
|
|
|
|
// script instead, where we don't have these limitations.
|
2009-05-11 22:03:52 +00:00
|
|
|
#ifndef USE_QPROCESS
|
2006-09-11 16:07:49 +00:00
|
|
|
return (os::shell() == os::UNIX) ?
|
2009-12-19 19:29:53 +00:00
|
|
|
'\'' + subst(name, "'", "\'\\\'\'") + '\'' :
|
2006-09-11 16:07:49 +00:00
|
|
|
'"' + name + '"';
|
2009-05-11 22:03:52 +00:00
|
|
|
#else
|
2009-12-18 22:15:46 +00:00
|
|
|
// According to the QProcess parser, a single double
|
|
|
|
// quote is represented by three consecutive ones.
|
2009-12-19 17:26:09 +00:00
|
|
|
// Here we simply escape the double quote and let our
|
|
|
|
// simple parser in Systemcall.cpp do the substitution.
|
|
|
|
return '"' + subst(name, "\"", "\\\"") + '"';
|
2009-05-11 22:03:52 +00:00
|
|
|
#endif
|
2006-09-11 16:07:49 +00:00
|
|
|
case quote_python:
|
|
|
|
return "\"" + subst(subst(name, "\\", "\\\\"), "\"", "\\\"")
|
|
|
|
+ "\"";
|
|
|
|
}
|
|
|
|
// shut up stupid compiler
|
|
|
|
return string();
|
1999-12-03 13:51:01 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-12-21 12:04:01 +00:00
|
|
|
#if 0
|
1999-09-27 18:44:28 +00:00
|
|
|
// Uses a string of paths separated by ";"s to find a file to open.
|
|
|
|
// Can't cope with pathnames with a ';' in them. Returns full path to file.
|
|
|
|
// If path entry begins with $$LyX/, use system_lyxdir
|
|
|
|
// If path entry begins with $$User/, use user_lyxdir
|
|
|
|
// Example: "$$User/doc;$$LyX/doc"
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const fileOpenSearch(string const & path, string const & name,
|
2000-08-05 05:17:18 +00:00
|
|
|
string const & ext)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName real_file;
|
2002-06-26 19:07:34 +00:00
|
|
|
string path_element;
|
1999-09-27 18:44:28 +00:00
|
|
|
bool notfound = true;
|
1999-11-02 06:42:25 +00:00
|
|
|
string tmppath = split(path, path_element, ';');
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
while (notfound && !path_element.empty()) {
|
2004-12-20 16:59:33 +00:00
|
|
|
path_element = os::internal_path(path_element);
|
1999-10-02 16:21:10 +00:00
|
|
|
if (!suffixIs(path_element, '/'))
|
2005-07-14 22:09:22 +00:00
|
|
|
path_element += '/';
|
2005-01-10 19:17:43 +00:00
|
|
|
path_element = subst(path_element, "$$LyX",
|
2007-04-06 13:09:54 +00:00
|
|
|
package().system_support().absFilename());
|
2005-01-10 19:17:43 +00:00
|
|
|
path_element = subst(path_element, "$$User",
|
2007-04-06 13:09:54 +00:00
|
|
|
package().user_support().absFilename());
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
real_file = fileSearch(path_element, name, ext);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
if (real_file.empty()) {
|
2000-01-20 01:41:55 +00:00
|
|
|
do {
|
|
|
|
tmppath = split(tmppath, path_element, ';');
|
2001-12-05 08:04:20 +00:00
|
|
|
} while (!tmppath.empty() && path_element.empty());
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
2000-01-20 01:41:55 +00:00
|
|
|
notfound = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return real_file;
|
|
|
|
}
|
2006-12-21 12:04:01 +00:00
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Returns the real name of file name in directory path, with optional
|
2002-03-21 17:09:55 +00:00
|
|
|
// extension ext.
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const fileSearch(string const & path, string const & name,
|
2007-05-28 22:27:45 +00:00
|
|
|
string const & ext, search_mode mode)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// if `name' is an absolute path, we ignore the setting of `path'
|
|
|
|
// Expand Environmentvariables in 'name'
|
2006-04-08 22:31:11 +00:00
|
|
|
string const tmpname = replaceEnvironmentPath(name);
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName fullname(makeAbsPath(tmpname, path));
|
1999-09-27 18:44:28 +00:00
|
|
|
// search first without extension, then with it.
|
2007-11-25 11:18:16 +00:00
|
|
|
if (fullname.isReadableFile())
|
1999-09-27 18:44:28 +00:00
|
|
|
return fullname;
|
2007-01-29 18:37:13 +00:00
|
|
|
if (ext.empty())
|
2006-12-21 12:04:01 +00:00
|
|
|
// We are done.
|
2008-01-26 20:25:25 +00:00
|
|
|
return mode == may_not_exist ? fullname : FileName();
|
2007-01-29 18:37:13 +00:00
|
|
|
// Only add the extension if it is not already the extension of
|
|
|
|
// fullname.
|
|
|
|
if (getExtension(fullname.absFilename()) != ext)
|
|
|
|
fullname = FileName(addExtension(fullname.absFilename(), ext));
|
2008-01-26 20:25:25 +00:00
|
|
|
if (fullname.isReadableFile() || mode == may_not_exist)
|
2007-01-29 18:37:13 +00:00
|
|
|
return fullname;
|
|
|
|
return FileName();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Search the file name.ext in the subdirectory dir of
|
|
|
|
// 1) user_lyxdir
|
|
|
|
// 2) build_lyxdir (if not empty)
|
|
|
|
// 3) system_lyxdir
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const libFileSearch(string const & dir, string const & name,
|
2000-08-05 05:17:18 +00:00
|
|
|
string const & ext)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName fullname = fileSearch(addPath(package().user_support().absFilename(), dir),
|
2005-01-10 19:17:43 +00:00
|
|
|
name, ext);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!fullname.empty())
|
|
|
|
return fullname;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
if (!package().build_support().empty())
|
2007-04-06 13:09:54 +00:00
|
|
|
fullname = fileSearch(addPath(package().build_support().absFilename(), dir),
|
2005-01-10 19:17:43 +00:00
|
|
|
name, ext);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!fullname.empty())
|
|
|
|
return fullname;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
return fileSearch(addPath(package().system_support().absFilename(), dir), name, ext);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const i18nLibFileSearch(string const & dir, string const & name,
|
2000-08-05 05:17:18 +00:00
|
|
|
string const & ext)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-10-12 16:23:26 +00:00
|
|
|
/* The highest priority value is the `LANGUAGE' environment
|
2001-10-24 13:21:20 +00:00
|
|
|
variable. But we don't use the value if the currently
|
2007-08-07 20:39:55 +00:00
|
|
|
selected locale is the C locale. This is a GNU extension.
|
2004-03-24 12:05:57 +00:00
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
Otherwise, w use a trick to guess what support/gettext.has done:
|
2007-08-07 20:39:55 +00:00
|
|
|
each po file is able to tell us its name. (JMarc)
|
|
|
|
*/
|
|
|
|
|
|
|
|
string lang = to_ascii(_("[[Replace with the code of your language]]"));
|
2005-02-15 13:45:41 +00:00
|
|
|
string const language = getEnv("LANGUAGE");
|
2007-08-07 20:39:55 +00:00
|
|
|
if (!lang.empty() && !language.empty())
|
2004-03-24 12:05:57 +00:00
|
|
|
lang = language;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2004-06-29 12:55:09 +00:00
|
|
|
string l;
|
|
|
|
lang = split(lang, l, ':');
|
2007-08-07 20:39:55 +00:00
|
|
|
while (!l.empty()) {
|
|
|
|
FileName tmp;
|
|
|
|
// First try with the full name
|
|
|
|
tmp = libFileSearch(addPath(dir, l), name, ext);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!tmp.empty())
|
|
|
|
return tmp;
|
2007-08-07 20:39:55 +00:00
|
|
|
|
|
|
|
// Then the name without country code
|
|
|
|
string const shortl = token(l, '_', 0);
|
|
|
|
if (shortl != l) {
|
|
|
|
tmp = libFileSearch(addPath(dir, shortl), name, ext);
|
|
|
|
if (!tmp.empty())
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2007-02-25 18:12:03 +00:00
|
|
|
#if 1
|
2007-08-07 20:39:55 +00:00
|
|
|
// For compatibility, to be removed later (JMarc)
|
|
|
|
tmp = libFileSearch(dir, token(l, '_', 0) + '_' + name,
|
|
|
|
ext);
|
|
|
|
if (!tmp.empty()) {
|
|
|
|
lyxerr << "i18nLibFileSearch: File `" << tmp
|
2007-02-25 18:12:03 +00:00
|
|
|
<< "' has been found by the old method" <<endl;
|
2007-08-07 20:39:55 +00:00
|
|
|
return tmp;
|
2007-02-25 18:12:03 +00:00
|
|
|
}
|
|
|
|
#endif
|
2004-06-29 12:55:09 +00:00
|
|
|
lang = split(lang, l, ':');
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2004-06-29 12:55:09 +00:00
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
return libFileSearch(dir, name, ext);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-11 16:07:49 +00:00
|
|
|
string const libScriptSearch(string const & command_in, quote_style style)
|
2002-03-27 00:05:28 +00:00
|
|
|
{
|
2005-07-14 22:09:22 +00:00
|
|
|
static string const token_scriptpath = "$$s/";
|
2003-05-31 09:24:46 +00:00
|
|
|
|
|
|
|
string command = command_in;
|
|
|
|
// Find the starting position of "$$s/"
|
|
|
|
string::size_type const pos1 = command.find(token_scriptpath);
|
|
|
|
if (pos1 == string::npos)
|
2002-03-27 00:05:28 +00:00
|
|
|
return command;
|
2005-02-01 16:41:24 +00:00
|
|
|
// Find the end of the "$$s/some_subdir/some_script" word within
|
|
|
|
// command. Assumes that the script name does not contain spaces.
|
2003-05-31 09:24:46 +00:00
|
|
|
string::size_type const start_script = pos1 + 4;
|
|
|
|
string::size_type const pos2 = command.find(' ', start_script);
|
|
|
|
string::size_type const size_script = pos2 == string::npos?
|
|
|
|
(command.size() - start_script) : pos2 - start_script;
|
|
|
|
|
|
|
|
// Does this script file exist?
|
2007-05-28 22:27:45 +00:00
|
|
|
string const script =
|
2006-11-26 21:30:39 +00:00
|
|
|
libFileSearch(".", command.substr(start_script, size_script)).absFilename();
|
2003-05-31 09:24:46 +00:00
|
|
|
|
|
|
|
if (script.empty()) {
|
|
|
|
// Replace "$$s/" with ""
|
|
|
|
command.erase(pos1, 4);
|
|
|
|
} else {
|
2005-01-20 15:02:16 +00:00
|
|
|
// Replace "$$s/foo/some_script" with "<path to>/some_script".
|
2003-05-31 09:24:46 +00:00
|
|
|
string::size_type const size_replace = size_script + 4;
|
2006-09-11 16:07:49 +00:00
|
|
|
command.replace(pos1, size_replace, quoteName(script, style));
|
2003-05-31 09:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return command;
|
2002-03-27 00:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-20 10:03:45 +00:00
|
|
|
static FileName createTmpDir(FileName const & tempdir, string const & mask)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::FILES, "createTmpDir: tempdir=`" << tempdir << "'\n"
|
|
|
|
<< "createTmpDir: mask=`" << mask << '\'');
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2008-07-23 09:27:33 +00:00
|
|
|
FileName const tmpfl = FileName::tempName(tempdir, mask);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2007-12-14 22:33:15 +00:00
|
|
|
if (tmpfl.empty() || !tmpfl.createDirectory(0700)) {
|
2008-07-23 09:27:33 +00:00
|
|
|
LYXERR0("LyX could not create temporary directory in " << tempdir
|
2008-06-09 09:57:10 +00:00
|
|
|
<< "'");
|
2006-11-26 21:30:39 +00:00
|
|
|
return FileName();
|
2004-02-25 12:00:53 +00:00
|
|
|
}
|
2003-03-29 09:02:08 +00:00
|
|
|
|
2006-12-27 10:56:11 +00:00
|
|
|
return tmpfl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const createLyXTmpDir(FileName const & deflt)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2008-06-09 14:33:31 +00:00
|
|
|
if (deflt.empty() || deflt == package().system_temp_dir())
|
|
|
|
return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
|
2007-11-07 19:52:11 +00:00
|
|
|
|
2007-12-14 22:33:15 +00:00
|
|
|
if (deflt.createDirectory(0777))
|
2007-11-07 19:52:11 +00:00
|
|
|
return deflt;
|
|
|
|
|
|
|
|
if (deflt.isDirWritable()) {
|
|
|
|
// deflt could not be created because it
|
|
|
|
// did exist already, so let's create our own
|
|
|
|
// dir inside deflt.
|
|
|
|
return createTmpDir(deflt, "lyx_tmpdir");
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
2007-11-07 19:52:11 +00:00
|
|
|
// some other error occured.
|
2008-06-09 14:33:31 +00:00
|
|
|
return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Strip filename from path name
|
2006-04-08 22:31:11 +00:00
|
|
|
string const onlyPath(string const & filename)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// If empty filename, return empty
|
2005-07-14 22:09:22 +00:00
|
|
|
if (filename.empty())
|
|
|
|
return filename;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Find last / or start of filename
|
2007-11-07 19:52:11 +00:00
|
|
|
size_t j = filename.rfind('/');
|
2005-07-14 22:09:22 +00:00
|
|
|
return j == string::npos ? "./" : filename.substr(0, j + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
2008-01-26 20:25:25 +00:00
|
|
|
// 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.
|
2006-12-27 10:56:11 +00:00
|
|
|
FileName const makeAbsPath(string const & relPath, string const & basePath)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// checks for already absolute path
|
2009-05-02 17:12:31 +00:00
|
|
|
if (FileName::isAbsolute(relPath))
|
|
|
|
return FileName(relPath);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Copies given paths
|
2006-04-08 22:31:11 +00:00
|
|
|
string tempRel = os::internal_path(relPath);
|
2001-05-17 15:11:01 +00:00
|
|
|
// Since TempRel is NOT absolute, we can safely replace "//" with "/"
|
2006-04-08 22:31:11 +00:00
|
|
|
tempRel = subst(tempRel, "//", "/");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
string tempBase;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2009-05-02 17:12:31 +00:00
|
|
|
if (FileName::isAbsolute(basePath))
|
2006-04-08 22:31:11 +00:00
|
|
|
tempBase = basePath;
|
2001-05-17 15:11:01 +00:00
|
|
|
else
|
2007-12-16 10:18:00 +00:00
|
|
|
tempBase = addPath(FileName::getcwd().absFilename(), basePath);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Handle /./ at the end of the path
|
2006-04-08 22:31:11 +00:00
|
|
|
while (suffixIs(tempBase, "/./"))
|
|
|
|
tempBase.erase(tempBase.length() - 2);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// processes relative path
|
2006-04-08 22:31:11 +00:00
|
|
|
string rTemp = tempRel;
|
|
|
|
string temp;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2008-01-26 20:41:19 +00:00
|
|
|
// Check for a leading "~"
|
|
|
|
// Split by first /
|
|
|
|
rTemp = split(rTemp, temp, '/');
|
|
|
|
if (temp == "~") {
|
|
|
|
tempBase = package().home_dir().absFilename();
|
|
|
|
tempRel = rTemp;
|
|
|
|
}
|
|
|
|
|
|
|
|
rTemp = tempRel;
|
2006-04-08 22:31:11 +00:00
|
|
|
while (!rTemp.empty()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// Split by next /
|
2006-04-08 22:31:11 +00:00
|
|
|
rTemp = split(rTemp, temp, '/');
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
if (temp == ".") continue;
|
|
|
|
if (temp == "..") {
|
1999-09-27 18:44:28 +00:00
|
|
|
// Remove one level of TempBase
|
2008-01-26 20:41:19 +00:00
|
|
|
if (tempBase.length() <= 1) {
|
|
|
|
//this is supposed to be an absolute path, so...
|
|
|
|
tempBase = "/";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//erase a trailing slash if there is one
|
|
|
|
if (suffixIs(tempBase, "/"))
|
|
|
|
tempBase.erase(tempBase.length() - 1, string::npos);
|
|
|
|
|
|
|
|
string::size_type i = tempBase.length() - 1;
|
2006-04-08 22:31:11 +00:00
|
|
|
while (i > 0 && tempBase[i] != '/')
|
2005-07-14 22:09:22 +00:00
|
|
|
--i;
|
1999-11-01 04:22:28 +00:00
|
|
|
if (i > 0)
|
2006-04-08 22:31:11 +00:00
|
|
|
tempBase.erase(i, string::npos);
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
2008-01-26 20:41:19 +00:00
|
|
|
tempBase = '/';
|
2006-04-08 22:31:11 +00:00
|
|
|
} else if (temp.empty() && !rTemp.empty()) {
|
|
|
|
tempBase = os::current_root() + rTemp;
|
|
|
|
rTemp.erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
|
|
|
// Add this piece to TempBase
|
2006-04-08 22:31:11 +00:00
|
|
|
if (!suffixIs(tempBase, '/'))
|
|
|
|
tempBase += '/';
|
|
|
|
tempBase += temp;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns absolute path
|
2007-11-28 15:25:07 +00:00
|
|
|
return FileName(tempBase);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Correctly append filename to the pathname.
|
|
|
|
// If pathname is '.', then don't use pathname.
|
|
|
|
// Chops any path of filename.
|
2006-04-08 22:31:11 +00:00
|
|
|
string const addName(string const & path, string const & fname)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2006-04-08 22:31:11 +00:00
|
|
|
string const basename = onlyFilename(fname);
|
1999-10-02 16:21:10 +00:00
|
|
|
string buf;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
if (path != "." && path != "./" && !path.empty()) {
|
2004-12-20 16:59:33 +00:00
|
|
|
buf = os::internal_path(path);
|
1999-10-02 16:21:10 +00:00
|
|
|
if (!suffixIs(path, '/'))
|
1999-09-27 18:44:28 +00:00
|
|
|
buf += '/';
|
|
|
|
}
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
return buf + basename;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Strips path from filename
|
2006-04-08 22:31:11 +00:00
|
|
|
string const onlyFilename(string const & fname)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-20 14:35:05 +00:00
|
|
|
if (fname.empty())
|
|
|
|
return fname;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string::size_type j = fname.rfind('/');
|
|
|
|
if (j == string::npos) // no '/' in fname
|
|
|
|
return fname;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Strip to basename
|
1999-10-02 16:21:10 +00:00
|
|
|
return fname.substr(j + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create absolute path. If impossible, don't do anything
|
|
|
|
// Supports ./ and ~/. Later we can add support for ~logname/. (Asger)
|
2006-04-08 22:31:11 +00:00
|
|
|
string const expandPath(string const & path)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// checks for already absolute path
|
2006-04-08 22:31:11 +00:00
|
|
|
string rTemp = replaceEnvironmentPath(path);
|
2009-05-02 17:12:31 +00:00
|
|
|
if (FileName::isAbsolute(rTemp))
|
2006-04-08 22:31:11 +00:00
|
|
|
return rTemp;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
string temp;
|
|
|
|
string const copy = rTemp;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Split by next /
|
2006-04-08 22:31:11 +00:00
|
|
|
rTemp = split(rTemp, temp, '/');
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
if (temp == ".")
|
2007-12-16 10:18:00 +00:00
|
|
|
return FileName::getcwd().absFilename() + '/' + rTemp;
|
2005-07-14 22:09:22 +00:00
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
if (temp == "~")
|
2007-04-06 13:09:54 +00:00
|
|
|
return package().home_dir().absFilename() + '/' + rTemp;
|
2005-07-14 22:09:22 +00:00
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
if (temp == "..")
|
2006-12-27 10:56:11 +00:00
|
|
|
return makeAbsPath(copy).absFilename();
|
2005-07-14 22:09:22 +00:00
|
|
|
|
2001-10-24 13:21:20 +00:00
|
|
|
// Don't know how to handle this
|
|
|
|
return copy;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-29 21:44:34 +00:00
|
|
|
// Search the string for ${VAR} and $VAR and replace VAR using getenv.
|
2006-04-08 22:31:11 +00:00
|
|
|
string const replaceEnvironmentPath(string const & path)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-09-29 21:44:34 +00:00
|
|
|
// ${VAR} is defined as
|
2003-09-25 23:01:43 +00:00
|
|
|
// $\{[A-Za-z_][A-Za-z_0-9]*\}
|
2003-10-16 16:41:32 +00:00
|
|
|
static string const envvar_br = "[$]\\{([A-Za-z_][A-Za-z_0-9]*)\\}";
|
2003-09-25 23:01:43 +00:00
|
|
|
|
2003-09-29 21:44:34 +00:00
|
|
|
// $VAR is defined as:
|
|
|
|
// $\{[A-Za-z_][A-Za-z_0-9]*\}
|
2003-10-16 16:41:32 +00:00
|
|
|
static string const envvar = "[$]([A-Za-z_][A-Za-z_0-9]*)";
|
2003-09-29 21:44:34 +00:00
|
|
|
|
2003-10-16 16:41:32 +00:00
|
|
|
static boost::regex envvar_br_re("(.*)" + envvar_br + "(.*)");
|
|
|
|
static boost::regex envvar_re("(.*)" + envvar + "(.*)");
|
2003-09-25 23:01:43 +00:00
|
|
|
boost::smatch what;
|
2009-05-09 17:06:54 +00:00
|
|
|
string result;
|
|
|
|
string remaining = path;
|
2003-09-25 23:01:43 +00:00
|
|
|
while (1) {
|
2009-05-09 17:06:54 +00:00
|
|
|
regex_match(remaining, what, envvar_br_re);
|
2003-09-29 21:44:34 +00:00
|
|
|
if (!what[0].matched) {
|
2009-05-09 17:06:54 +00:00
|
|
|
regex_match(remaining, what, envvar_re);
|
|
|
|
if (!what[0].matched) {
|
|
|
|
result += remaining;
|
2003-09-29 21:44:34 +00:00
|
|
|
break;
|
2009-05-09 17:06:54 +00:00
|
|
|
}
|
2003-09-29 21:44:34 +00:00
|
|
|
}
|
2009-05-09 17:06:54 +00:00
|
|
|
string env_var = getEnv(what.str(2));
|
|
|
|
if (!env_var.empty())
|
|
|
|
result += what.str(1) + env_var;
|
|
|
|
else
|
|
|
|
result += what.str(1) + "$" + what.str(2);
|
|
|
|
remaining = what.str(3);
|
2002-03-21 17:09:55 +00:00
|
|
|
}
|
2003-09-25 23:01:43 +00:00
|
|
|
return result;
|
2002-11-06 11:15:24 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Make relative path out of two absolute paths
|
2007-03-27 07:24:16 +00:00
|
|
|
docstring const makeRelPath(docstring const & abspath, docstring const & basepath)
|
1999-09-27 18:44:28 +00:00
|
|
|
// Makes relative path out of absolute path. If it is deeper than basepath,
|
|
|
|
// it's easy. If basepath and abspath share something (they are all deeper
|
|
|
|
// than some directory), it'll be rendered using ..'s. If they are completely
|
|
|
|
// different, then the absolute path will be used as relative path.
|
|
|
|
{
|
2007-03-27 07:24:16 +00:00
|
|
|
docstring::size_type const abslen = abspath.length();
|
|
|
|
docstring::size_type const baselen = basepath.length();
|
2001-05-17 15:11:01 +00:00
|
|
|
|
2007-03-27 07:24:16 +00:00
|
|
|
docstring::size_type i = os::common_path(abspath, basepath);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
// actually no match - cannot make it relative
|
|
|
|
return abspath;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count how many dirs there are in basepath above match
|
|
|
|
// and append as many '..''s into relpath
|
2007-03-27 07:24:16 +00:00
|
|
|
docstring buf;
|
|
|
|
docstring::size_type j = i;
|
1999-09-27 18:44:28 +00:00
|
|
|
while (j < baselen) {
|
|
|
|
if (basepath[j] == '/') {
|
2001-10-24 13:21:20 +00:00
|
|
|
if (j + 1 == baselen)
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
buf += "../";
|
|
|
|
}
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append relative stuff from common directory to abspath
|
2001-10-24 13:21:20 +00:00
|
|
|
if (abspath[i] == '/')
|
|
|
|
++i;
|
1999-12-07 00:44:53 +00:00
|
|
|
for (; i < abslen; ++i)
|
1999-09-27 18:44:28 +00:00
|
|
|
buf += abspath[i];
|
|
|
|
// Remove trailing /
|
1999-10-02 16:21:10 +00:00
|
|
|
if (suffixIs(buf, '/'))
|
|
|
|
buf.erase(buf.length() - 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
// Substitute empty with .
|
|
|
|
if (buf.empty())
|
|
|
|
buf = '.';
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Append sub-directory(ies) to a path in an intelligent way
|
2006-04-08 22:31:11 +00:00
|
|
|
string const addPath(string const & path, string const & path_2)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string buf;
|
2004-12-20 16:59:33 +00:00
|
|
|
string const path2 = os::internal_path(path_2);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!path.empty() && path != "." && path != "./") {
|
2004-12-20 16:59:33 +00:00
|
|
|
buf = os::internal_path(path);
|
1999-10-02 16:21:10 +00:00
|
|
|
if (path[path.length() - 1] != '/')
|
1999-09-27 18:44:28 +00:00
|
|
|
buf += '/';
|
|
|
|
}
|
|
|
|
|
2001-05-17 15:11:01 +00:00
|
|
|
if (!path2.empty()) {
|
2002-03-21 17:09:55 +00:00
|
|
|
string::size_type const p2start = path2.find_first_not_of('/');
|
2001-05-17 15:11:01 +00:00
|
|
|
string::size_type const p2end = path2.find_last_not_of('/');
|
|
|
|
string const tmp = path2.substr(p2start, p2end - p2start + 1);
|
|
|
|
buf += tmp + '/';
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
string const changeExtension(string const & oldname, string const & extension)
|
1999-10-02 16:21:10 +00:00
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
string::size_type const last_slash = oldname.rfind('/');
|
2000-02-07 20:17:03 +00:00
|
|
|
string::size_type last_dot = oldname.rfind('.');
|
|
|
|
if (last_dot < last_slash && last_slash != string::npos)
|
|
|
|
last_dot = string::npos;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string ext;
|
|
|
|
// Make sure the extension starts with a dot
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!extension.empty() && extension[0] != '.')
|
2002-11-27 10:30:28 +00:00
|
|
|
ext= '.' + extension;
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
|
|
|
ext = extension;
|
2000-05-11 16:12:46 +00:00
|
|
|
|
2004-12-20 16:59:33 +00:00
|
|
|
return os::internal_path(oldname.substr(0, last_dot) + ext);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2006-04-01 10:49:58 +00:00
|
|
|
string const removeExtension(string const & name)
|
|
|
|
{
|
2006-04-08 22:31:11 +00:00
|
|
|
return changeExtension(name, string());
|
2006-04-01 10:49:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-21 12:04:01 +00:00
|
|
|
string const addExtension(string const & name, string const & extension)
|
|
|
|
{
|
|
|
|
if (!extension.empty() && extension[0] != '.')
|
|
|
|
return name + '.' + extension;
|
|
|
|
return name + extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-30 03:40:51 +00:00
|
|
|
/// Return the extension of the file (not including the .)
|
2006-04-08 22:31:11 +00:00
|
|
|
string const getExtension(string const & name)
|
2000-08-30 03:40:51 +00:00
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
string::size_type const last_slash = name.rfind('/');
|
|
|
|
string::size_type const last_dot = name.rfind('.');
|
2000-08-30 03:40:51 +00:00
|
|
|
if (last_dot != string::npos &&
|
|
|
|
(last_slash == string::npos || last_dot > last_slash))
|
|
|
|
return name.substr(last_dot + 1,
|
|
|
|
name.length() - (last_dot + 1));
|
|
|
|
else
|
|
|
|
return string();
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2004-10-29 15:47:55 +00:00
|
|
|
|
2003-09-03 17:23:38 +00:00
|
|
|
string const unzippedFileName(string const & zipped_file)
|
|
|
|
{
|
2006-04-08 22:31:11 +00:00
|
|
|
string const ext = getExtension(zipped_file);
|
2003-09-03 17:23:38 +00:00
|
|
|
if (ext == "gz" || ext == "z" || ext == "Z")
|
2006-04-08 22:31:11 +00:00
|
|
|
return changeExtension(zipped_file, string());
|
2008-04-08 09:28:15 +00:00
|
|
|
return onlyPath(zipped_file) + "unzipped_" + onlyFilename(zipped_file);
|
2003-09-03 17:23:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const unzipFile(FileName const & zipped_file, string const & unzipped_file)
|
2002-02-07 19:37:34 +00:00
|
|
|
{
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const tempfile = FileName(unzipped_file.empty() ?
|
|
|
|
unzippedFileName(zipped_file.toFilesystemEncoding()) :
|
|
|
|
unzipped_file);
|
2002-02-16 18:34:30 +00:00
|
|
|
// Run gunzip
|
2006-11-26 21:30:39 +00:00
|
|
|
string const command = "gunzip -c " +
|
|
|
|
zipped_file.toFilesystemEncoding() + " > " +
|
|
|
|
tempfile.toFilesystemEncoding();
|
2002-02-18 19:13:48 +00:00
|
|
|
Systemcall one;
|
|
|
|
one.startscript(Systemcall::Wait, command);
|
2002-02-16 18:34:30 +00:00
|
|
|
// test that command was executed successfully (anon)
|
|
|
|
// yes, please do. (Lgb)
|
|
|
|
return tempfile;
|
2002-02-07 19:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-11 08:54:10 +00:00
|
|
|
docstring const makeDisplayPath(string const & path, unsigned int threshold)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2003-04-08 00:06:52 +00:00
|
|
|
string str = path;
|
2007-02-28 21:48:04 +00:00
|
|
|
|
|
|
|
// If file is from LyXDir, display it as if it were relative.
|
2007-04-06 13:09:54 +00:00
|
|
|
string const system = package().system_support().absFilename();
|
2007-03-14 00:36:25 +00:00
|
|
|
if (prefixIs(str, system) && str != system)
|
2007-05-28 22:27:45 +00:00
|
|
|
return from_utf8("[" + str.erase(0, system.length()) + "]");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-04-08 00:06:52 +00:00
|
|
|
// replace /home/blah with ~/
|
2007-04-06 13:09:54 +00:00
|
|
|
string const home = package().home_dir().absFilename();
|
2005-09-07 09:44:58 +00:00
|
|
|
if (!home.empty() && prefixIs(str, home))
|
2003-04-08 00:06:52 +00:00
|
|
|
str = subst(str, home, "~");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-04-08 00:06:52 +00:00
|
|
|
if (str.length() <= threshold)
|
2007-01-18 20:47:27 +00:00
|
|
|
return from_utf8(os::external_path(str));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-04-08 00:06:52 +00:00
|
|
|
string const prefix = ".../";
|
|
|
|
string temp;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-04-08 00:06:52 +00:00
|
|
|
while (str.length() > threshold)
|
|
|
|
str = split(str, temp, '/');
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2003-04-08 00:06:52 +00:00
|
|
|
// Did we shorten everything away?
|
|
|
|
if (str.empty()) {
|
|
|
|
// Yes, filename itself is too long.
|
|
|
|
// Pick the start and the end of the filename.
|
2006-04-08 22:31:11 +00:00
|
|
|
str = onlyFilename(path);
|
2003-04-08 00:06:52 +00:00
|
|
|
string const head = str.substr(0, threshold / 2 - 3);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-04-08 00:06:52 +00:00
|
|
|
string::size_type len = str.length();
|
|
|
|
string const tail =
|
|
|
|
str.substr(len - threshold / 2 - 2, len - 1);
|
|
|
|
str = head + "..." + tail;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2003-04-08 00:06:52 +00:00
|
|
|
|
2007-01-18 20:47:27 +00:00
|
|
|
return from_utf8(os::external_path(prefix + str));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 06:42:25 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
bool readLink(FileName const & file, FileName & link)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2005-01-04 13:24:56 +00:00
|
|
|
#ifdef HAVE_READLINK
|
2002-07-17 21:43:06 +00:00
|
|
|
char linkbuffer[512];
|
1999-12-07 00:44:53 +00:00
|
|
|
// Should be PATH_MAX but that needs autconf support
|
2007-04-06 13:09:54 +00:00
|
|
|
string const encoded = file.toFilesystemEncoding();
|
|
|
|
int const nRead = ::readlink(encoded.c_str(),
|
2002-07-17 21:43:06 +00:00
|
|
|
linkbuffer, sizeof(linkbuffer) - 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (nRead <= 0)
|
|
|
|
return false;
|
2002-07-17 21:43:06 +00:00
|
|
|
linkbuffer[nRead] = '\0'; // terminator
|
2007-04-06 13:09:54 +00:00
|
|
|
link = makeAbsPath(linkbuffer, onlyPath(file.absFilename()));
|
1999-09-27 18:44:28 +00:00
|
|
|
return true;
|
2005-01-04 13:24:56 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-24 22:14:46 +00:00
|
|
|
|
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
cmd_ret const runCommand(string const & cmd)
|
1999-11-24 22:14:46 +00:00
|
|
|
{
|
2004-04-05 08:52:45 +00:00
|
|
|
// FIXME: replace all calls to RunCommand with ForkedCall
|
2007-04-26 04:41:58 +00:00
|
|
|
// (if the output is not needed) or the code in ISpell.cpp
|
2004-04-05 06:46:22 +00:00
|
|
|
// (if the output is needed).
|
2004-04-20 08:51:15 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
// One question is if we should use popen or
|
|
|
|
// create our own popen based on fork, exec, pipe
|
|
|
|
// of course the best would be to have a
|
|
|
|
// pstream (process stream), with the
|
2000-01-06 02:44:26 +00:00
|
|
|
// variants ipstream, opstream
|
2002-02-08 11:23:58 +00:00
|
|
|
|
2005-05-03 20:32:55 +00:00
|
|
|
#if defined (HAVE_POPEN)
|
2002-09-23 16:03:11 +00:00
|
|
|
FILE * inf = ::popen(cmd.c_str(), os::popen_read_mode());
|
2005-05-03 20:32:55 +00:00
|
|
|
#elif defined (HAVE__POPEN)
|
|
|
|
FILE * inf = ::_popen(cmd.c_str(), os::popen_read_mode());
|
|
|
|
#else
|
|
|
|
#error No popen() function.
|
|
|
|
#endif
|
2002-02-08 11:23:58 +00:00
|
|
|
|
|
|
|
// (Claus Hentschel) Check if popen was succesful ;-)
|
2004-04-05 06:46:22 +00:00
|
|
|
if (!inf) {
|
|
|
|
lyxerr << "RunCommand:: could not start child process" << endl;
|
2005-07-14 22:09:22 +00:00
|
|
|
return make_pair(-1, string());
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
string ret;
|
|
|
|
int c = fgetc(inf);
|
|
|
|
while (c != EOF) {
|
|
|
|
ret += static_cast<char>(c);
|
|
|
|
c = fgetc(inf);
|
|
|
|
}
|
2005-05-03 20:32:55 +00:00
|
|
|
|
|
|
|
#if defined (HAVE_PCLOSE)
|
2000-11-14 02:01:57 +00:00
|
|
|
int const pret = pclose(inf);
|
2005-05-03 20:32:55 +00:00
|
|
|
#elif defined (HAVE__PCLOSE)
|
|
|
|
int const pret = _pclose(inf);
|
|
|
|
#else
|
|
|
|
#error No pclose() function.
|
|
|
|
#endif
|
|
|
|
|
2004-04-05 06:46:22 +00:00
|
|
|
if (pret == -1)
|
|
|
|
perror("RunCommand:: could not terminate child process");
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
return make_pair(pret, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-01 20:09:08 +00:00
|
|
|
FileName const findtexfile(string const & fil, string const & /*format*/)
|
1999-11-24 22:14:46 +00:00
|
|
|
{
|
|
|
|
/* There is no problem to extend this function too use other
|
|
|
|
methods to look for files. It could be setup to look
|
|
|
|
in environment paths and also if wanted as a last resort
|
|
|
|
to a recursive find. One of the easier extensions would
|
|
|
|
perhaps be to use the LyX file lookup methods. But! I am
|
|
|
|
going to implement this until I see some demand for it.
|
|
|
|
Lgb
|
|
|
|
*/
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-03-01 18:15:39 +00:00
|
|
|
// If the file can be found directly, we just return a
|
2002-03-21 17:09:55 +00:00
|
|
|
// absolute path version of it.
|
2006-12-01 20:09:08 +00:00
|
|
|
FileName const absfile(makeAbsPath(fil));
|
2007-10-20 10:03:45 +00:00
|
|
|
if (absfile.exists())
|
2006-12-01 20:09:08 +00:00
|
|
|
return absfile;
|
2000-03-01 18:15:39 +00:00
|
|
|
|
2008-06-05 05:39:19 +00:00
|
|
|
// Now we try to find it using kpsewhich.
|
2000-03-02 02:19:43 +00:00
|
|
|
// It seems from the kpsewhich manual page that it is safe to use
|
|
|
|
// kpsewhich without --format: "When the --format option is not
|
|
|
|
// given, the search path used when looking for a file is inferred
|
|
|
|
// from the name given, by looking for a known extension. If no
|
|
|
|
// known extension is found, the search path for TeX source files
|
|
|
|
// is used."
|
|
|
|
// However, we want to take advantage of the format sine almost all
|
|
|
|
// the different formats has environment variables that can be used
|
|
|
|
// to controll which paths to search. f.ex. bib looks in
|
|
|
|
// BIBINPUTS and TEXBIB. Small list follows:
|
|
|
|
// bib - BIBINPUTS, TEXBIB
|
|
|
|
// bst - BSTINPUTS
|
|
|
|
// graphic/figure - TEXPICTS, TEXINPUTS
|
|
|
|
// ist - TEXINDEXSTYLE, INDEXSTYLE
|
|
|
|
// pk - PROGRAMFONTS, PKFONTS, TEXPKS, GLYPHFONTS, TEXFONTS
|
|
|
|
// tex - TEXINPUTS
|
|
|
|
// tfm - TFMFONTS, TEXFONTS
|
|
|
|
// This means that to use kpsewhich in the best possible way we
|
|
|
|
// should help it by setting additional path in the approp. envir.var.
|
2001-10-24 13:21:20 +00:00
|
|
|
string const kpsecmd = "kpsewhich " + fil;
|
2000-01-12 11:16:01 +00:00
|
|
|
|
2006-04-08 22:31:11 +00:00
|
|
|
cmd_ret const c = runCommand(kpsecmd);
|
2001-10-24 13:21:20 +00:00
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::LATEX, "kpse status = " << c.first << '\n'
|
|
|
|
<< "kpse result = `" << rtrim(c.second, "\n\r") << '\'');
|
2002-03-21 17:09:55 +00:00
|
|
|
if (c.first != -1)
|
2007-11-28 15:25:07 +00:00
|
|
|
return FileName(rtrim(to_utf8(from_filesystem8bit(c.second)), "\n\r"));
|
2001-06-21 10:55:48 +00:00
|
|
|
else
|
2006-12-01 20:09:08 +00:00
|
|
|
return FileName();
|
1999-11-24 22:14:46 +00:00
|
|
|
}
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
void readBB_lyxerrMessage(FileName const & file, bool & zipped,
|
2002-07-28 18:13:51 +00:00
|
|
|
string const & message)
|
2002-06-18 20:47:49 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GRAPHICS, "[readBB_from_PSFile] " << message);
|
2007-08-10 11:47:12 +00:00
|
|
|
// FIXME: Why is this func deleting a file? (Lgb)
|
2002-06-18 20:47:49 +00:00
|
|
|
if (zipped)
|
2007-11-28 09:01:49 +00:00
|
|
|
file.removeFile();
|
2002-06-18 20:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
string const readBB_from_PSFile(FileName const & file)
|
2002-04-08 14:55:52 +00:00
|
|
|
{
|
|
|
|
// in a (e)ps-file it's an entry like %%BoundingBox:23 45 321 345
|
|
|
|
// It seems that every command in the header has an own line,
|
|
|
|
// getline() should work for all files.
|
|
|
|
// On the other hand some plot programs write the bb at the
|
|
|
|
// end of the file. Than we have in the header:
|
|
|
|
// %%BoundingBox: (atend)
|
|
|
|
// In this case we must check the end.
|
2007-10-20 19:48:53 +00:00
|
|
|
bool zipped = file.isZippedFile();
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const file_ = zipped ? unzipFile(file) : file;
|
2007-10-20 19:48:53 +00:00
|
|
|
string const format = file_.guessFormatFromContents();
|
2002-06-18 20:47:49 +00:00
|
|
|
|
|
|
|
if (format != "eps" && format != "ps") {
|
2002-07-28 18:13:51 +00:00
|
|
|
readBB_lyxerrMessage(file_, zipped,"no(e)ps-format");
|
2002-04-08 14:55:52 +00:00
|
|
|
return string();
|
2002-06-18 20:47:49 +00:00
|
|
|
}
|
2002-04-08 14:55:52 +00:00
|
|
|
|
2006-04-05 08:19:48 +00:00
|
|
|
static boost::regex bbox_re(
|
|
|
|
"^%%BoundingBox:\\s*([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)");
|
2007-12-12 19:28:07 +00:00
|
|
|
ifstream is(file_.toFilesystemEncoding().c_str());
|
2002-04-08 14:55:52 +00:00
|
|
|
while (is) {
|
|
|
|
string s;
|
2002-05-02 10:46:51 +00:00
|
|
|
getline(is,s);
|
2006-04-05 08:19:48 +00:00
|
|
|
boost::smatch what;
|
|
|
|
if (regex_match(s, what, bbox_re)) {
|
|
|
|
// Our callers expect the tokens in the string
|
|
|
|
// separated by single spaces.
|
|
|
|
// FIXME: change return type from string to something
|
|
|
|
// sensible
|
|
|
|
ostringstream os;
|
|
|
|
os << what.str(1) << ' ' << what.str(2) << ' '
|
|
|
|
<< what.str(3) << ' ' << what.str(4);
|
|
|
|
string const bb = os.str();
|
2002-06-18 20:47:49 +00:00
|
|
|
readBB_lyxerrMessage(file_, zipped, bb);
|
|
|
|
return bb;
|
|
|
|
}
|
2002-04-08 14:55:52 +00:00
|
|
|
}
|
2002-06-18 20:47:49 +00:00
|
|
|
readBB_lyxerrMessage(file_, zipped, "no bb found");
|
2002-04-08 14:55:52 +00:00
|
|
|
return string();
|
|
|
|
}
|
2003-06-03 10:14:52 +00:00
|
|
|
|
|
|
|
|
2007-10-18 21:10:35 +00:00
|
|
|
int compare_timestamps(FileName const & file1, FileName const & file2)
|
2003-06-03 10:14:52 +00:00
|
|
|
{
|
|
|
|
// If the original is newer than the copy, then copy the original
|
|
|
|
// to the new directory.
|
2003-09-03 17:23:38 +00:00
|
|
|
|
|
|
|
int cmp = 0;
|
2007-10-18 21:10:35 +00:00
|
|
|
if (file1.exists() && file2.exists()) {
|
|
|
|
double const tmp = difftime(file1.lastModified(), file2.lastModified());
|
2003-09-03 17:23:38 +00:00
|
|
|
if (tmp != 0)
|
|
|
|
cmp = tmp > 0 ? 1 : -1;
|
|
|
|
|
2007-10-18 21:10:35 +00:00
|
|
|
} else if (file1.exists()) {
|
2003-09-03 17:23:38 +00:00
|
|
|
cmp = 1;
|
2007-10-18 21:10:35 +00:00
|
|
|
} else if (file2.exists()) {
|
2003-09-03 17:23:38 +00:00
|
|
|
cmp = -1;
|
2003-06-03 10:14:52 +00:00
|
|
|
}
|
|
|
|
|
2003-09-03 17:23:38 +00:00
|
|
|
return cmp;
|
2003-06-03 10:14:52 +00:00
|
|
|
}
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2007-12-02 09:19:43 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
} //namespace support
|
|
|
|
} // namespace lyx
|