The package reworking.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9463 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2005-01-10 19:17:43 +00:00
parent e20b77bb20
commit b5589bf6cf
48 changed files with 1261 additions and 829 deletions

View File

@ -1,3 +1,7 @@
2005-01-06 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* lyxinclude.m4 (LYX_USE_PACKAGING): new macro.
2005-01-05 Lars Gullik Bjonnes <larsbj@gullik.net>
* lyxinclude.m4 (enable_stdlib_debug): new switch

View File

@ -550,6 +550,37 @@ AC_SUBST(FRONTENDS_PROGS)
])
## Check what kind of packaging should be used at install time.
## The default is autodetected.
AC_DEFUN([LYX_USE_PACKAGING],
[AC_MSG_CHECKING([what packaging should be used])
AC_ARG_WITH(packaging,
[ --with-packaging=THIS Use THIS packaging for installation:
Possible values: posix, windows, macosx],
[lyx_use_packaging="$withval"], [
case $host in
*-apple-darwin*) lyx_use_packaging=macosx ;;
*-pc-mingw32*) lyx_use_packaging=windows;;
*) lyx_use_packaging=posix;;
esac])
AC_MSG_RESULT($lyx_use_packaging)
case $lyx_use_packaging in
macosx) AC_DEFINE(USE_MACOSX_PACKAGING, 1, [Define to 1 if LyX should use a MacOS X application bundle file layout])
default_prefix="/Applications/LyX.app"
bindir='${prefix}/Contents/MacOS'
datadir='${prefix}/Contents/Resources'
mandir='${prefix}/Contents/Resources/man' ;;
windows) AC_DEFINE(USE_WINDOWS_PACKAGING, 1, [Define to 1 if LyX should use a Windows-style file layout])
default_prefix="'C:Program Files/LyX'"
bindir='${prefix}/bin'
datadir='${prefix}/Resources'
mandir='${prefix}/Resources/man' ;;
posix) AC_DEFINE(USE_POSIX_PACKAGING, 1, [Define to 1 if LyX should use a POSIX-style file layout])
default_prefix=$ac_default_prefix ;;
*) LYX_ERROR([Unknown packaging type $lyx_use_packaging]) ;;
esac
])
## ------------------------------------------------------------------------
## Find a file (or one of more files in a list of dirs)

View File

@ -227,6 +227,12 @@ dnl qt build will fail without moc or uic
esac
done
### Check how the files should be packaged
LYX_USE_PACKAGING
# fix the value of the prefixes.
test "x$prefix" = xNONE && prefix=$default_prefix
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
### Setup GNU gettext
dnl GNU gettext is written in C
AC_LANG_PUSH(C)
@ -310,6 +316,7 @@ VERSION_INFO="Configuration\n\
C++ Compiler flags: ${CPPFLAGS} ${CXXFLAGS}\n\
Linker flags: ${LDFLAGS}\n\
${FRONTEND_INFO}\
Packaging: ${lyx_use_packaging}\n\
LyX binary dir: ${real_bindir}\n\
LyX files dir: ${real_datadir}\n"

View File

@ -205,7 +205,6 @@ src/output_plaintext.C
src/paragraph.C
src/rowpainter.C
src/support/filefilterlist.C
src/support/path_defines.C.in
src/text.C
src/text2.C
src/text3.C

View File

@ -65,11 +65,11 @@
#include "graphics/Previews.h"
#include "support/convert.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
#include "support/forkedcontr.h"
#include "support/path_defines.h"
#include "support/convert.h"
#include "support/package.h"
#include "support/types.h"
#include <boost/bind.hpp>
@ -86,8 +86,8 @@ using lyx::support::ForkedcallsController;
using lyx::support::IsDirWriteable;
using lyx::support::MakeDisplayPath;
using lyx::support::MakeAbsPath;
using lyx::support::package;
using lyx::support::strToUnsignedInt;
using lyx::support::system_lyxdir;
using std::endl;
using std::istringstream;
@ -779,7 +779,7 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm)
make_pair(string(_("Documents|#o#O")),
string(lyxrc.document_path)),
make_pair(string(_("Examples|#E#e")),
string(AddPath(system_lyxdir(), "examples"))));
string(AddPath(package().system_support(), "examples"))));
FileDialog::Result result =
fileDlg.open(initpath,

View File

@ -1,3 +1,16 @@
2005-01-10 Angus Leeming <leeming@lyx.org>
* Makefile.am: remove the lyx_main.C special casing.
* BufferView_pimpl.C:
* bufferlist.C:
* exporter.C:
* lyx_cb.C:
* lyx_main.C:
* lyxfunc.C:
* messages.C: use support/package.h to provide the paths to the
various directories used by LyX.
2005-01-09 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* CutAndPaste.C (pasteSelectionHelper): fix bug 1332 (preserve the

View File

@ -27,7 +27,7 @@
#include "frontends/Alert.h"
#include "support/filetools.h"
#include "support/os.h"
#include "support/package.h"
#include <boost/bind.hpp>
@ -40,6 +40,7 @@ using lyx::support::MakeAbsPath;
using lyx::support::MakeDisplayPath;
using lyx::support::OnlyFilename;
using lyx::support::removeAutosaveFile;
using lyx::support::package;
using lyx::support::prefixIs;
using boost::bind;
@ -55,7 +56,6 @@ using std::vector;
using std::back_inserter;
using std::transform;
namespace os = lyx::support::os;
BufferList::BufferList()
{}
@ -319,7 +319,7 @@ void BufferList::emergencyWrite(Buffer * buf)
}
// 2) In HOME directory.
string s = AddName(os::homepath(), buf->fileName());
string s = AddName(package().home_dir(), buf->fileName());
s += ".emergency";
lyxerr << ' ' << s << endl;
if (buf->writeFile(s)) {

View File

@ -1,3 +1,8 @@
2005-01-10 Angus Leeming <leeming@lyx.org>
* messages.C: use support/package.h to provide the paths to the
various directories used by LyX.
2004-12-16 Angus Leeming <leeming@lyx.org>
* messages.C: remove redundant "using lyx::support::GetEnvPath;"

View File

@ -11,10 +11,9 @@
#include "messages.h"
#include "support/filetools.h"
#include "support/path_defines.h"
using lyx::support::lyx_localedir;
#include "support/package.h"
using lyx::support::package;
using std::string;
@ -39,7 +38,8 @@ public:
//lyxerr << "Messages: language(" << l
// << ") in dir(" << dir << ")" << std::endl;
cat_gl = mssg_gl.open(PACKAGE, loc_gl, lyx_localedir().c_str());
cat_gl = mssg_gl.open(PACKAGE, loc_gl,
package().locale_dir().c_str());
}
@ -94,7 +94,7 @@ public:
char * old = strdup(setlocale(LC_ALL, 0));
char * n = setlocale(LC_ALL, lang_.c_str());
bindtextdomain(PACKAGE, lyx_localedir().c_str());
bindtextdomain(PACKAGE, package().locale_dir().c_str());
textdomain(PACKAGE);
const char* msg = gettext(m.c_str());
setlocale(LC_ALL, old);

View File

@ -33,7 +33,7 @@
#include "support/FileInfo.h"
#include "support/filetools.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/package.h"
using lyx::support::AddName;
using lyx::support::bformat;
@ -43,6 +43,7 @@ using lyx::support::MakeAbsPath;
using lyx::support::MakeDisplayPath;
using lyx::support::OnlyFilename;
using lyx::support::OnlyPath;
using lyx::support::package;
using lyx::support::prefixIs;
using std::find;
@ -103,7 +104,7 @@ CopyStatus copyFile(string const & format,
// overwrite themselves. This check could be changed to
// boost::filesystem::equivalent(sourceFile, destFile) if export to
// other directories than the document directory is desired.
if (!prefixIs(OnlyPath(sourceFile), lyx::support::os::getTmpDir()))
if (!prefixIs(OnlyPath(sourceFile), package().temp_dir()))
return ret;
if (!force) {

View File

@ -1,3 +1,11 @@
2005-01-10 Angus Leeming <leeming@lyx.org>
* ControlAboutlyx.C:
* ControlGraphics.C:
* helper_funcs.C:
* tex_helpers.C: use support/package.h to provide the paths to the
various directories used by LyX.
2005-01-06 Lars Gullik Bjonnes <larsbj@gullik.net>
* ControlTabularCreate.C (dispatchParams):

View File

@ -16,7 +16,7 @@
#include "version.h"
#include "support/filetools.h" // FileSearch
#include "support/path_defines.h"
#include "support/package.h"
#include <fstream>
#include <sstream>
@ -30,8 +30,7 @@ namespace lyx {
using support::FileSearch;
using support::MakeDisplayPath;
using support::system_lyxdir;
using support::user_lyxdir;
using support::package;
namespace frontend {
@ -43,7 +42,7 @@ ControlAboutlyx::ControlAboutlyx(Dialog & parent)
void ControlAboutlyx::getCredits(ostream & ss) const
{
string const name = FileSearch(system_lyxdir(), "CREDITS");
string const name = FileSearch(package().system_support(), "CREDITS");
bool found(!name.empty());
@ -90,10 +89,10 @@ string const ControlAboutlyx::getVersion() const
<< lyx_release_date
<< "\n"
<< _("Library directory: ")
<< MakeDisplayPath(system_lyxdir())
<< MakeDisplayPath(package().system_support())
<< "\n"
<< _("User directory: ")
<< MakeDisplayPath(user_lyxdir());
<< MakeDisplayPath(package().user_support());
return ss.str();
}

View File

@ -25,11 +25,11 @@
#include "insets/insetgraphics.h"
#include "support/convert.h"
#include "support/FileInfo.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
#include "support/path_defines.h"
#include "support/convert.h"
#include "support/package.h"
#include "support/types.h"
using std::make_pair;
@ -44,9 +44,8 @@ using support::FileFilterList;
using support::FileInfo;
using support::IsFileReadable;
using support::MakeAbsPath;
using support::package;
using support::readBB_from_PSFile;
using support::system_lyxdir;
using support::user_lyxdir;
namespace frontend {
@ -85,11 +84,11 @@ string const ControlGraphics::browse(string const & in_name) const
string const title = _("Select graphics file");
// Does user clipart directory exist?
string clipdir = AddName (user_lyxdir(), "clipart");
string clipdir = AddName (package().user_support(), "clipart");
FileInfo fileInfo(clipdir);
if (!(fileInfo.isOK() && fileInfo.isDir()))
// No - bail out to system clipart directory
clipdir = AddName (system_lyxdir(), "clipart");
clipdir = AddName (package().system_support(), "clipart");
pair<string, string> dir1(_("Clipart|#C#c"), clipdir);
pair<string, string> dir2(_("Documents|#o#O"), string(lyxrc.document_path));
// Show the file browser dialog

View File

@ -20,7 +20,7 @@
#include "frontends/FileDialog.h"
#include "support/filetools.h"
#include "support/path_defines.h"
#include "support/package.h"
using std::pair;
using std::vector;
@ -40,9 +40,8 @@ using support::MakeAbsPath;
using support::MakeRelPath;
using support::OnlyFilename;
using support::OnlyPath;
using support::package;
using support::prefixIs;
using support::system_lyxdir;
using support::user_lyxdir;
namespace frontend {
@ -116,10 +115,10 @@ string const browseLibFile(string const & dir,
FileFilterList const & filters)
{
pair<string,string> const dir1(_("System files|#S#s"),
AddName(system_lyxdir(), dir));
AddName(package().system_support(), dir));
pair<string,string> const dir2(_("User files|#U#u"),
AddName(user_lyxdir(), dir));
AddName(package().user_support(), dir));
string const result = browseFile(LibFileSearch(dir, name, ext), title,
filters, false, dir1, dir2);

View File

@ -16,10 +16,10 @@
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/systemcall.h"
#include "support/path.h"
#include "support/lyxalgo.h"
#include "support/path_defines.h"
#include "support/package.h"
#include "support/path.h"
#include "support/systemcall.h"
#include <boost/cregex.hpp>
#include <fstream>
@ -34,12 +34,11 @@ using support::GetFileContents;
using support::getVectorFromString;
using support::LibFileSearch;
using support::OnlyFilename;
using support::Path;
using support::package;
using support::Path;
using support::split;
using support::Systemcall;
using support::token;
using support::user_lyxdir;
namespace frontend {
@ -48,7 +47,7 @@ namespace frontend {
void rescanTexStyles()
{
// Run rescan in user lyx directory
Path p(user_lyxdir());
Path p(package().user_support());
Systemcall one;
one.startscript(Systemcall::Wait,
LibFileSearch("scripts", "TeXFiles.sh"));
@ -58,7 +57,7 @@ void rescanTexStyles()
void texhash()
{
// Run texhash in user lyx directory
Path p(user_lyxdir());
Path p(package().user_support());
//path to texhash through system
Systemcall one;

View File

@ -1,3 +1,8 @@
2005-01-10 Angus Leeming <leeming@lyx.org>
* lyx_gui.C: use support/package.h to provide the paths to the
various directories used by LyX.
2005-01-04 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* lyx_gui.C: change getDVI() to int.

View File

@ -16,7 +16,7 @@
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/filetools.h"
#include "support/path_defines.h"
#include "support/package.h"
#include "debug.h"
#include "gettext.h"
@ -160,7 +160,6 @@ void lyx_gui::parse_init(int & argc, char * argv[])
if (!display) {
lyxerr << "LyX: unable to access X display, exiting" << endl;
os::warn("Unable to access X display, exiting");
::exit(1);
}

View File

@ -1,3 +1,9 @@
2005-01-10 Angus Leeming <leeming@lyx.org>
* ghelpers.C:
* lyx_gui.C: use support/package.h to provide the paths to the
various directories used by LyX.
2005-01-06 Lars Gullik Bjonnes <larsbj@gullik.net>
* GParagraph.C: drop unused include tostr.h

View File

@ -23,7 +23,7 @@
#include "debug.h"
#include "support/filetools.h"
#include "support/path_defines.h"
#include "support/package.h"
using std::string;
using std::vector;
@ -144,7 +144,7 @@ string const findGladeFile(string const & name)
// Second, search in the src tree.
string const dir =
lyx::support::AddPath(lyx::support::top_srcdir(),
lyx::support::AddPath(lyx::support::package().top_srcdir(),
"src/frontends/gtk/glade");
filename = lyx::support::ChangeExtension(name, ".glade");

View File

@ -54,7 +54,7 @@
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/filetools.h"
#include "support/path_defines.h"
#include "support/package.h"
#include <gtkmm.h>
@ -72,6 +72,8 @@ namespace os = lyx::support::os;
using std::ostringstream;
using std::string;
using lyx::support::package;
using lyx::frontend::colorCache;
using lyx::frontend::GView;
using lyx::frontend::XformsColor;
@ -181,7 +183,6 @@ void parse_init_xforms(int & argc, char * argv[])
if (!display) {
lyxerr << "LyX: unable to access X display, exiting"
<< std::endl;
lyx::support::os::warn("Unable to access X display, exiting");
::exit(1);
}
@ -212,8 +213,8 @@ void lyx_gui::parse_init(int & argc, char * argv[])
void parse_lyxrc_xforms()
{
XformsColor::read(lyx::support::AddName(
lyx::support::user_lyxdir(), "preferences.xform"));
XformsColor::read(lyx::support::AddName(package().user_support(),
"preferences.xform"));
if (lyxrc.popup_font_encoding.empty())
lyxrc.popup_font_encoding = lyxrc.font_norm;
@ -345,7 +346,7 @@ void lyx_gui::start(string const & batch, std::vector<string> const & files)
lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
os::internal_path(os::getTmpDir() + "/lyxsocket"));
os::internal_path(package().temp_dir() + "/lyxsocket"));
for_each(files.begin(), files.end(),
bind(&BufferView::loadLyXFile, view.view(), _1, true));

View File

@ -1,3 +1,8 @@
2005-01-10 Angus Leeming <leeming@lyx.org>
* lyx_gui.C: use support/package.h to provide the paths to the
various directories used by LyX.
2005-01-07 Ruurd Reitsma <rareitsma@yahoo.com>
* qfont_metrics.C (ascent, descent): correct the metrics returned

View File

@ -29,6 +29,7 @@
#include "support/lstrings.h"
#include "support/os.h"
#include "support/package.h"
#include "debug.h"
// Dear Lord, deliver us from Evil, aka the Qt headers
@ -55,6 +56,7 @@
#include <qtextcodec.h>
using lyx::support::ltrim;
using lyx::support::package;
using lyx::frontend::QtView;
@ -229,7 +231,7 @@ void start(string const & batch, vector<string> const & files)
lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes);
lyxsocket = new LyXServerSocket(&view.getLyXFunc(),
os::internal_path(os::getTmpDir() + "/lyxsocket"));
os::internal_path(package().temp_dir() + "/lyxsocket"));
for_each(files.begin(), files.end(),
bind(&BufferView::loadLyXFile, view.view(), _1, true));

View File

@ -1,3 +1,10 @@
2005-01-10 Angus Leeming <leeming@lyx.org>
* FormFiledialog.C:
* FormPreferences.C:
* lyx_gui.C: use support/package.h to provide the paths to the
various directories used by LyX.
2005-01-06 Lars Gullik Bjonnes <larsbj@gullik.net>
* xforms_helpers.C:

View File

@ -19,14 +19,14 @@
#include "frontends/Dialogs.h"
#include "support/convert.h"
#include "support/FileInfo.h"
#include "support/filefilterlist.h"
#include "support/filetools.h"
#include "support/globbing.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/convert.h"
#include "support/package.h"
#include "lyx_forms.h"
@ -69,6 +69,7 @@ using lyx::support::getcwd;
using lyx::support::LyXReadLink;
using lyx::support::MakeAbsPath;
using lyx::support::OnlyFilename;
using lyx::support::package;
using lyx::support::split;
using lyx::support::subst;
using lyx::support::suffixIs;
@ -82,7 +83,7 @@ using std::map;
using std::vector;
using namespace lyx::frontend;
namespace os = lyx::support::os;
namespace {
@ -617,7 +618,7 @@ void FileDialog::Private::FileDlgCB(FL_OBJECT *, long arg)
break;
case 11: // home
current_dlg_->SetDirectory(os::homepath());
current_dlg_->SetDirectory(package().home_dir());
current_dlg_->SetFilters(fl_get_input(file_dlg_form_->PatBox));
current_dlg_->Reread();
break;

View File

@ -29,7 +29,7 @@
#include "lyxfont.h"
#include "support/lstrings.h"
#include "support/path_defines.h"
#include "support/package.h"
#include "support/filetools.h"
#include "lyx_forms.h"
@ -50,10 +50,10 @@ namespace lyx {
using support::AddName;
using support::ChangeExtension;
using support::package;
using support::rtrim;
using support::strToDbl;
using support::trim;
using support::user_lyxdir;
namespace frontend {
@ -305,7 +305,7 @@ void FormPreferences::apply()
// The "Save" button has been pressed.
if (dialog().isClosing() && colors_.modifiedXformsPrefs) {
string const filename =
AddName(user_lyxdir(), "preferences.xform");
AddName(package().user_support(), "preferences.xform");
colors_.modifiedXformsPrefs = !XformsColor::write(filename);
}
}

View File

@ -36,7 +36,7 @@
#include "support/filetools.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/path_defines.h"
#include "support/package.h"
#include "lyx_forms.h"
@ -48,7 +48,7 @@
#include <iomanip>
using lyx::support::AddName;
using lyx::support::user_lyxdir;
using lyx::support::package;
using lyx::frontend::fontloader;
using lyx::frontend::getRGBColor;
@ -179,7 +179,6 @@ void parse_init(int & argc, char * argv[])
if (!display) {
lyxerr << "LyX: unable to access X display, exiting" << endl;
os::warn("Unable to access X display, exiting");
::exit(1);
}
@ -204,7 +203,8 @@ void parse_init(int & argc, char * argv[])
void parse_lyxrc()
{
XformsColor::read(AddName(user_lyxdir(), "preferences.xform"));
XformsColor::read(AddName(package().user_support(),
"preferences.xform"));
if (lyxrc.popup_font_encoding.empty())
lyxrc.popup_font_encoding = lyxrc.font_norm;
@ -302,7 +302,7 @@ void start(string const & batch, vector<string> const & files)
lyxserver = new LyXServer(&view->getLyXFunc(), lyxrc.lyxpipes);
lyxsocket = new LyXServerSocket(&view->getLyXFunc(),
os::internal_path(os::getTmpDir() + "/lyxsocket"));
os::internal_path(package().temp_dir() + "/lyxsocket"));
for_each(files.begin(), files.end(),
bind(&BufferView::loadLyXFile, view->view(), _1, true));

View File

@ -1,3 +1,8 @@
2005-01-10 Angus Leeming <leeming@lyx.org>
* ExternalTemplate.C: use support/package.h to provide the paths to the
various directories used by LyX.
2005-01-06 Lars Gullik Bjonnes <larsbj@gullik.net>
* insetwrap.C:

View File

@ -28,8 +28,8 @@
#include "support/lstrings.h"
#include "support/lyxalgo.h"
#include "support/lyxlib.h"
#include "support/package.h"
#include "support/path.h"
#include "support/path_defines.h"
#include "support/std_ostream.h"
@ -109,7 +109,8 @@ string const doSubstitution(InsetExternalParams const & params,
relToParentPath);
}
result = support::subst(result, "$$Tempname", params.tempname());
result = support::subst(result, "$$Sysdir", support::system_lyxdir());
result = support::subst(result, "$$Sysdir",
support::package().system_support());
// Handle the $$Contents(filename) syntax
if (support::contains(result, "$$Contents(\"")) {

View File

@ -18,8 +18,8 @@
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/package.h"
#include "support/path.h"
#include "support/path_defines.h"
namespace support = lyx::support;
@ -54,7 +54,7 @@ Template::Format::Format()
TemplateManager::TemplateManager()
{
readTemplates(support::user_lyxdir());
readTemplates(support::package().user_support());
if (lyxerr.debugging(Debug::EXTERNAL)) {
dumpPreambleDefs(lyxerr);
lyxerr << '\n';

View File

@ -39,9 +39,8 @@
#include "support/filetools.h"
#include "support/forkedcall.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/package.h"
#include "support/path.h"
#include "support/path_defines.h"
#include "support/systemcall.h"
#include <boost/shared_ptr.hpp>
@ -62,17 +61,14 @@ using lyx::support::MakeDisplayPath;
using lyx::support::OnlyFilename;
using lyx::support::OnlyPath;
using lyx::support::Path;
using lyx::support::package;
using lyx::support::QuoteName;
using lyx::support::removeAutosaveFile;
using lyx::support::rename;
using lyx::support::split;
using lyx::support::system_lyxdir;
using lyx::support::Systemcall;
using lyx::support::tempName;
using lyx::support::unlink;
using lyx::support::user_lyxdir;
namespace os = lyx::support::os;
using boost::shared_ptr;
@ -205,11 +201,11 @@ void QuitLyX()
bufferlist.closeAll();
// do any other cleanup procedures now
lyxerr[Debug::INFO] << "Deleting tmp dir " << os::getTmpDir() << endl;
lyxerr[Debug::INFO] << "Deleting tmp dir " << package().temp_dir() << endl;
if (destroyDir(os::getTmpDir()) != 0) {
if (destroyDir(package().temp_dir()) != 0) {
string msg = bformat(_("Could not remove the temporary directory %1$s"),
os::getTmpDir());
package().temp_dir());
Alert::warning(_("Could not remove temporary directory"), msg);
}
@ -444,8 +440,9 @@ void Reconfigure(BufferView * bv)
bv->owner()->message(_("Running configure..."));
// Run configure in user lyx directory
Path p(user_lyxdir());
string const configure_script = AddName(system_lyxdir(), "configure");
Path p(package().user_support());
string const configure_script =
AddName(package().system_support(), "configure");
string const configure_command = "sh " + QuoteName(configure_script);
Systemcall one;
one.startscript(Systemcall::Wait, configure_command);

View File

@ -49,8 +49,8 @@
#include "support/filetools.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/package.h"
#include "support/path.h"
#include "support/path_defines.h"
#include <boost/bind.hpp>
@ -67,15 +67,10 @@ using lyx::support::FileSearch;
using lyx::support::GetEnv;
using lyx::support::i18nLibFileSearch;
using lyx::support::LibFileSearch;
using lyx::support::package;
using lyx::support::Path;
using lyx::support::QuoteName;
using lyx::support::rtrim;
using lyx::support::setLyxPaths;
using lyx::support::system_lyxdir;
using lyx::support::user_lyxdir;
using lyx::support::os::getTmpDir;
using lyx::support::os::setTmpDir;
namespace os = lyx::support::os;
@ -102,6 +97,12 @@ boost::scoped_ptr<kb_keymap> toplevel_keymap;
namespace {
// Filled with the command line arguments "foo" of "-sysdir foo" or
// "-userdir foo".
string cl_system_support;
string cl_user_support;
void showFileError(string const & error)
{
Alert::warning(_("Could not read configuration file"),
@ -189,6 +190,8 @@ void LyX::priv_exec(int & argc, char * argv[])
// we need to parse for "-dbg" and "-help"
bool const want_gui = easyParse(argc, argv);
lyx::support::init_package(argv[0], cl_system_support, cl_user_support);
if (want_gui)
lyx_gui::parse_init(argc, argv);
@ -340,12 +343,36 @@ void LyX::init(bool gui)
signal(SIGTERM, error_handler);
// SIGPIPE can be safely ignored.
bool const explicit_userdir = setLyxPaths();
#if defined (USE_MACOSX_PACKAGING)
// Set PATH for LyX/Mac
//
// LyX/Mac is a relocatable application bundle; here we add to
// the PATH so it can find binaries like reLyX inside its own
// application bundle, and also append PATH elements that it
// needs to run latex, previewers, etc.
string oldpath = GetEnv("PATH");
string newpath = "PATH=" + oldpath + ":" + package().binary_dir() + ":";
newpath += "/sw/bin:/usr/local/bin:"
"/usr/local/teTeX/bin/powerpc-apple-darwin-current";
PutEnv(newpath);
lyxerr[Debug::INIT] << "Running from LyX/Mac bundle. "
"Setting PATH to: " << GetEnv("PATH") << endl;
#endif
// Set the locale_dir.
string const & locale_dir = package().locale_dir();
FileInfo fi(locale_dir);
if (fi.isOK() && fi.isDir()) {
lyxerr[Debug::INIT]
<< "Setting locale directory to "
<< locale_dir << endl;
//gettext_init(locale_dir);
}
// Check that user LyX directory is ok. We don't do that if
// running in batch mode.
if (gui) {
queryUserLyXDir(explicit_userdir);
queryUserLyXDir(package().explicit_user_support());
} else {
first_start = false;
}
@ -353,12 +380,16 @@ void LyX::init(bool gui)
// Disable gui when easyparse says so
lyx_gui::use_gui = gui;
lyxrc.tempdir_path = package().temp_dir();
lyxrc.document_path = package().document_dir();
if (lyxrc.template_path.empty()) {
lyxrc.template_path = AddPath(system_lyxdir(), "templates");
lyxrc.template_path = AddPath(package().system_support(),
"templates");
}
if (lyxrc.lastfiles.empty()) {
lyxrc.lastfiles = AddName(user_lyxdir(), "lastfiles");
lyxrc.lastfiles = AddName(package().user_support(), "lastfiles");
}
if (lyxrc.roman_font_name.empty())
@ -406,8 +437,10 @@ void LyX::init(bool gui)
if (lyxerr.debugging(Debug::LYXRC))
lyxrc.print();
setTmpDir(createLyXTmpDir(lyxrc.tempdir_path));
if (getTmpDir().empty()) {
package().document_dir() = lyxrc.document_path;
package().temp_dir() = createLyXTmpDir(lyxrc.tempdir_path);
if (package().temp_dir().empty()) {
Alert::error(_("Could not create temporary directory"),
bformat(_("Could not create a temporary directory in\n"
"%1$s. Make sure that this\n"
@ -422,7 +455,7 @@ void LyX::init(bool gui)
}
if (lyxerr.debugging(Debug::INIT)) {
lyxerr << "LyX tmp dir: `" << getTmpDir() << '\'' << endl;
lyxerr << "LyX tmp dir: `" << package().temp_dir() << '\'' << endl;
}
lyxerr[Debug::INIT] << "Reading lastfiles `"
@ -528,20 +561,20 @@ void LyX::deadKeyBindings(kb_keymap * kbmap)
void LyX::queryUserLyXDir(bool explicit_userdir)
{
string const configure_script = AddName(system_lyxdir(), "configure");
string const configure_script = AddName(package().system_support(), "configure");
string const configure_command = "sh " + QuoteName(configure_script);
// Does user directory exist?
FileInfo fileInfo(user_lyxdir());
FileInfo fileInfo(package().user_support());
if (fileInfo.isOK() && fileInfo.isDir()) {
first_start = false;
FileInfo script(configure_script);
FileInfo defaults(AddName(user_lyxdir(), "lyxrc.defaults"));
FileInfo defaults(AddName(package().user_support(), "lyxrc.defaults"));
if (defaults.isOK() && script.isOK()
&& defaults.getModificationTime() < script.getModificationTime()) {
lyxerr << _("LyX: reconfiguring user directory")
<< endl;
Path p(user_lyxdir());
Path p(package().user_support());
::system(configure_command.c_str());
lyxerr << "LyX: " << _("Done!") << endl;
}
@ -550,19 +583,34 @@ void LyX::queryUserLyXDir(bool explicit_userdir)
first_start = !explicit_userdir;
lyxerr << bformat(_("LyX: Creating directory %1$s"
" and running configure..."), user_lyxdir()) << endl;
// If the user specified explicitly a directory, ask whether
// to create it. If the user says "no", then exit.
if (explicit_userdir &&
!Alert::prompt(
_("Missing LyX support directory"),
bformat(_("You have specified a non-existent user "
"LyX directory, %1$s.\n"
"It is needed to keep your own configuration."),
package().user_support()),
1, 0,
_("&Create directory."),
_("&Exit LyX."))) {
lyxerr << _("No user LyX directory. Exiting.") << endl;
exit(1);
}
if (!createDirectory(user_lyxdir(), 0755)) {
// Failed, let's use $HOME instead.
user_lyxdir(os::homepath());
lyxerr << bformat(_("Failed. Will use %1$s instead."),
user_lyxdir()) << endl;
return;
lyxerr << bformat(_("LyX: Creating directory %1$s"
" and running configure..."), package().user_support()) << endl;
if (!createDirectory(package().user_support(), 0755)) {
// Failed, so let's exit.
lyxerr << _("Failed to create directory. Exiting.")
<< endl;
exit(1);
}
// Run configure in user lyx directory
Path p(user_lyxdir());
Path p(package().user_support());
::system(configure_command.c_str());
lyxerr << "LyX: " << _("Done!") << endl;
}
@ -763,7 +811,7 @@ int parse_sysdir(string const & arg, string const &)
lyxerr << _("Missing directory for -sysdir switch") << endl;
exit(1);
}
system_lyxdir(arg);
cl_system_support = arg;
return 1;
}
@ -773,7 +821,7 @@ int parse_userdir(string const & arg, string const &)
lyxerr << _("Missing directory for -userdir switch") << endl;
exit(1);
}
user_lyxdir(arg);
cl_user_support = arg;
return 1;
}

View File

@ -84,7 +84,7 @@
#include "support/forkedcontr.h"
#include "support/lstrings.h"
#include "support/path.h"
#include "support/path_defines.h"
#include "support/package.h"
#include "support/systemcall.h"
#include "support/convert.h"
#include "support/os.h"
@ -108,6 +108,7 @@ using lyx::support::IsFileReadable;
using lyx::support::isStrInt;
using lyx::support::MakeAbsPath;
using lyx::support::MakeDisplayPath;
using lyx::support::package;
using lyx::support::Path;
using lyx::support::QuoteName;
using lyx::support::rtrim;
@ -115,13 +116,10 @@ using lyx::support::split;
using lyx::support::strToInt;
using lyx::support::strToUnsignedInt;
using lyx::support::subst;
using lyx::support::system_lyxdir;
using lyx::support::Systemcall;
using lyx::support::token;
using lyx::support::trim;
using lyx::support::user_lyxdir;
using lyx::support::prefixIs;
using lyx::support::os::getTmpDir;
using std::endl;
using std::make_pair;
@ -1069,7 +1067,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
int row;
istringstream is(argument);
is >> file_name >> row;
if (prefixIs(file_name, getTmpDir())) {
if (prefixIs(file_name, package().temp_dir())) {
// Needed by inverse dvi search. If it is a file
// in tmpdir, call the apropriated function
view()->setBuffer(bufferlist.getBufferFromTmp(file_name));
@ -1294,7 +1292,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
}
case LFUN_SAVEPREFERENCES: {
Path p(user_lyxdir());
Path p(package().user_support());
lyxrc.write("preferences", false);
break;
}
@ -1398,7 +1396,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case LFUN_SAVE_AS_DEFAULT: {
string const fname =
AddName(AddPath(user_lyxdir(), "templates/"),
AddName(AddPath(package().user_support(), "templates/"),
"defaults.lyx");
Buffer defaults(fname);
@ -1661,7 +1659,7 @@ void LyXFunc::open(string const & fname)
make_pair(string(_("Documents|#o#O")),
string(lyxrc.document_path)),
make_pair(string(_("Examples|#E#e")),
string(AddPath(system_lyxdir(), "examples"))));
string(AddPath(package().system_support(), "examples"))));
FileDialog::Result result =
fileDlg.open(initpath,
@ -1737,7 +1735,7 @@ void LyXFunc::doImport(string const & argument)
make_pair(string(_("Documents|#o#O")),
string(lyxrc.document_path)),
make_pair(string(_("Examples|#E#e")),
string(AddPath(system_lyxdir(), "examples"))));
string(AddPath(package().system_support(), "examples"))));
string const filter = formats.prettyName(format)
+ " (*." + formats.extension(format) + ')';

View File

@ -11,11 +11,11 @@
#include "messages.h"
#include "support/filetools.h"
#include "support/path_defines.h"
#include "support/package.h"
#include <boost/regex.hpp>
using lyx::support::lyx_localedir;
using lyx::support::package;
using std::string;
@ -41,7 +41,7 @@ public:
//lyxerr << "Messages: language(" << l
// << ") in dir(" << dir << ")" << std::endl;
cat_gl = mssg_gl.open(PACKAGE, loc_gl, lyx_localedir().c_str());
cat_gl = mssg_gl.open(PACKAGE, loc_gl, package().locale_dir().c_str());
}
@ -96,7 +96,7 @@ public:
char * old = strdup(setlocale(LC_ALL, 0));
char * n = setlocale(LC_ALL, lang_.c_str());
bindtextdomain(PACKAGE, lyx_localedir().c_str());
bindtextdomain(PACKAGE, package().locale_dir().c_str());
textdomain(PACKAGE);
const char* msg = gettext(m.c_str());
// Some english words have different translations, depending

View File

@ -1,3 +1,26 @@
2005-01-10 Angus Leeming <leeming@lyx.org>
* os.h:
* os_os2.C:
* os_unix.C:
* os_win32.C (binpath, binname, homepath, setTmpDir, getTmpDir, warn):
removed. Remove also all code to set the associated data variables.
* package.{C.in,h}: new files to ascertain the paths to the
various directories used by LyX. Does nothing with these paths,
just determines the strings themselves.
* path_defines.{C.in,h}: removed.
* Makefile.am: remove path_defines.{C.in,h}. Add package.{C.in,h}.
* filetools.C[Ch] (GetEnvPath): remove.
(getEnvPath): replacement. Returns a vector<string> of paths.
* filetools.C:
* tempname.C: use support/package.h to provide the paths to the
various directories used by LyX.
2005-01-07 Angus Leeming <leeming@lyx.org>
* convert.C (string>): add specialization for long.

View File

@ -4,13 +4,13 @@ noinst_LTLIBRARIES = libsupport.la
CLEANFILES += path_defines.C
EXTRA_DIST = path_defines.C.in os_unix.C os_win32.C os_os2.C
EXTRA_DIST = package.C.in os_unix.C os_win32.C os_os2.C
if USE_COMPRESSION
COMPRESSION = gzstream.C gzstream.h
endif
BUILT_SOURCES = path_defines.C
BUILT_SOURCES = package.C
AM_CPPFLAGS = $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES)
@ -60,8 +60,8 @@ libsupport_la_SOURCES = \
os2_errortable.h \
path.C \
path.h \
path_defines.C \
path_defines.h \
package.C \
package.h \
putenv.C \
rename.C \
rmdir.C \
@ -80,20 +80,19 @@ libsupport_la_SOURCES = \
unlink.C
path_defines.C: build_path_defines
package.C: build_package
build_path_defines: path_defines.C.in
@rm -f tmp_path_defines ;\
build_package: package.C.in
@rm -f tmp_package ;\
ABS_SRCDIR=`cd $(top_srcdir) && pwd` ;\
ABS_BUILDDIR=`cd ../.. && pwd` ;\
sed "s,%LYX_DIR%,$(pkgdatadir), ;\
s,%LOCALEDIR%,$(datadir)/locale, ;\
s,%BUILDDIR%,$${ABS_BUILDDIR}, ;\
s,%TOP_SRCDIR%,$${ABS_SRCDIR}," \
$(srcdir)/path_defines.C.in > tmp_path_defines ;\
if cmp -s tmp_path_defines path_defines.C ; then \
rm -f tmp_path_defines ;\
$(srcdir)/package.C.in > tmp_package ;\
if cmp -s tmp_package package.C ; then \
rm -f tmp_package ;\
else \
rm -f path_defines.C ;\
mv tmp_path_defines path_defines.C ;\
rm -f package.C ;\
mv tmp_package package.C ;\
fi

View File

@ -27,8 +27,8 @@
#include "support/lstrings.h"
#include "support/FileInfo.h"
#include "support/forkedcontr.h"
#include "support/package.h"
#include "support/path.h"
#include "support/path_defines.h"
#include "support/lyxlib.h"
#include "support/os.h"
@ -38,6 +38,7 @@
#include <boost/assert.hpp>
#include <boost/regex.hpp>
#include <boost/tokenizer.hpp>
#include <fcntl.h>
@ -188,8 +189,10 @@ string const FileOpenSearch(string const & path, string const & name,
path_element = os::internal_path(path_element);
if (!suffixIs(path_element, '/'))
path_element+= '/';
path_element = subst(path_element, "$$LyX", system_lyxdir());
path_element = subst(path_element, "$$User", user_lyxdir());
path_element = subst(path_element, "$$LyX",
package().system_support());
path_element = subst(path_element, "$$User",
package().user_support());
real_file = FileSearch(path_element, name, ext);
@ -294,16 +297,18 @@ string const FileSearch(string const & path, string const & name,
string const LibFileSearch(string const & dir, string const & name,
string const & ext)
{
string fullname = FileSearch(AddPath(user_lyxdir(), dir), name, ext);
string fullname = FileSearch(AddPath(package().user_support(), dir),
name, ext);
if (!fullname.empty())
return fullname;
if (!build_lyxdir().empty())
fullname = FileSearch(AddPath(build_lyxdir(), dir), name, ext);
if (!package().build_support().empty())
fullname = FileSearch(AddPath(package().build_support(), dir),
name, ext);
if (!fullname.empty())
return fullname;
return FileSearch(AddPath(system_lyxdir(), dir), name, ext);
return FileSearch(AddPath(package().system_support(), dir), name, ext);
}
@ -389,6 +394,30 @@ string const GetEnv(string const & envname)
}
vector<string> const getEnvPath(string const & name)
{
typedef boost::char_separator<char> Separator;
typedef boost::tokenizer<Separator> Tokenizer;
#if defined (__EMX__) || defined (_WIN32)
Separator const separator(";");
#else
Separator const separator(":");
#endif
string const env_var = GetEnv(name);
Tokenizer const tokens(env_var, separator);
Tokenizer::const_iterator it = tokens.begin();
Tokenizer::const_iterator const end = tokens.end();
std::vector<string> vars;
for (; it != end; ++it)
vars.push_back(os::internal_path(*it));
return vars;
}
string const GetEnvPath(string const & name)
{
#ifndef __EMX__
@ -495,9 +524,12 @@ string const createBufferTmpDir()
{
static int count;
// We are in our own directory. Why bother to mangle name?
// In fact I wrote this code to circumvent a problematic behaviour (bug?)
// of EMX mkstemp().
string const tmpfl = os::getTmpDir() + "/lyx_tmpbuf" + convert<string>(count++);
// In fact I wrote this code to circumvent a problematic behaviour
// (bug?) of EMX mkstemp().
string const tmpfl =
package().temp_dir() + "/lyx_tmpbuf" +
convert<string>(count++);
if (mkdir(tmpfl, 0777)) {
lyxerr << "LyX could not create the temporary directory '"
<< tmpfl << "'" << endl;
@ -690,7 +722,7 @@ string const ExpandPath(string const & path)
return getcwd() + '/' + RTemp;
}
if (Temp == "~") {
return os::homepath() + '/' + RTemp;
return package().home_dir() + '/' + RTemp;
}
if (Temp == "..") {
return MakeAbsPath(copy);
@ -1111,7 +1143,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold)
{
string str = path;
string const home(os::homepath());
string const home(package().home_dir());
// replace /home/blah with ~/
if (prefixIs(str, home))

View File

@ -115,8 +115,13 @@ std::string const LibScriptSearch(std::string const & command);
///
std::string const GetEnv(std::string const & envname);
/// A helper function.
std::string const GetEnvPath(std::string const & name);
/** Return the contents of the environment variable \c name,
* split using the OS-dependent token separating elements.
* Each element is then passed through os::internal_path to
* guarantee that it is in the form of a unix-stype path.
* If the environment variable is not set, then returns an empty vector.
 */
std::vector<std::string> const getEnvPath(std::string const & name);
/// Substitutes active latex characters with underscores in filename
std::string const MakeLatexName(std::string const & file);

View File

@ -29,16 +29,7 @@ enum shell_type {
// do some work just once
void init(int argc, char * argv[]);
// returns path of LyX binary
std::string const & binpath();
// returns name of LyX binary
std::string const & binname();
//
void setTmpDir(std::string const & p);
//
std::string const & getTmpDir();
// Returns the user's home directory ($HOME in the unix world).
std::string const & homepath();
// Returns the name of the NULL device (/dev/null, null).
std::string const & nulldev();
//
@ -56,8 +47,6 @@ bool is_absolute_path(std::string const & p);
// returns a string suitable to be passed to popen when
// same for popen().
char const * popen_read_mode();
//
void warn(std::string const & mesg);
} // namespace os
} // namespace support

View File

@ -21,27 +21,19 @@
#define INCL_DOSERRORS
#include <os2.h>
#include <boost/scoped_array.hpp>
using boost::scoped_array;
namespace lyx {
namespace support {
namespace os {
namespace {
string binpath_;
string binname_;
string tmpdir_;
string homepath_;
string nulldev_;
os::shell_type shell_ = os::UNIX;
shell_type shell_ = UNIX;
unsigned long cp_ = 0;
}
namespace os {
void init(int argc, char * argv[])
{
_wildcard(&argc, &argv);
@ -50,16 +42,6 @@ void init(int argc, char * argv[])
APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
if (rc != NO_ERROR)
exit(rc);
scoped_array<char> tmp(new char[256]);
// This is the only reliable way to retrieve the executable name.
rc = DosQueryModuleName(ppib->pib_hmte, 256L, tmp);
if (rc != NO_ERROR)
exit(rc);
string p = tmp.get();
p = internal_path(p);
binname_ = OnlyFilename(p);
binname_.erase(binname_.length()-4, string::npos);
binpath_ = OnlyPath(p);
// OS/2 cmd.exe has another use for '&'
string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
@ -89,16 +71,6 @@ void init(int argc, char * argv[])
// CPList[1] == system default codepage, the rest are auxilary.
// Once cp_ is correctly set, you can call other routines.
cp_ = CPList[1];
tmpdir_ = "/tmp";
homepath_ = GetEnvPath("HOME");
nulldev_ = "null";
}
void warn(string const & /*mesg*/)
{
return;
}
@ -218,38 +190,9 @@ char const * popen_read_mode()
}
string const & binpath()
{
return binpath_;
}
string const & binname()
{
return binname_;
}
void setTmpDir(string const & p)
{
tmpdir_ = p;
}
string const & getTmpDir()
{
return tmpdir_;
}
string const & homepath()
{
return homepath_;
}
string const & nulldev()
{
static string const nulldev_ = "null";
return nulldev_;
}
@ -259,4 +202,6 @@ shell_type shell()
return shell_;
}
} // end namespace os
} // namespace os
} // namespace support
} // namespace lyx

View File

@ -13,61 +13,16 @@
#include <config.h>
#include "support/os.h"
#include "support/filetools.h"
#include "support/lstrings.h"
using std::string;
namespace {
string binpath_;
string binname_;
string tmpdir_;
string homepath_;
string nulldev_;
}
namespace lyx {
namespace support {
namespace os {
void init(int /*argc*/, char * argv[])
{
static bool initialized = false;
if (initialized)
return;
initialized = true;
string tmp = argv[0];
binname_ = OnlyFilename(tmp);
tmp = ExpandPath(tmp); // This expands ./ and ~/
if (!is_absolute_path(tmp)) {
string binsearchpath = GetEnvPath("PATH");
// This will make "src/lyx" work always :-)
binsearchpath += ";.";
tmp = FileOpenSearch(binsearchpath, tmp);
}
tmp = MakeAbsPath(OnlyPath(tmp));
// In case we are running in place and compiled with shared libraries
if (suffixIs(tmp, "/.libs/"))
tmp.erase(tmp.length() - 6, string::npos);
binpath_ = tmp;
tmpdir_ = "/tmp";
homepath_ = GetEnvPath("HOME");
nulldev_ = "/dev/null";
}
void warn(string const & /*mesg*/)
{
return;
}
void init(int, char *[])
{}
string current_root()
@ -120,38 +75,9 @@ char const * popen_read_mode()
}
string const & binpath()
{
return binpath_;
}
string const & binname()
{
return binname_;
}
void setTmpDir(string const & p)
{
tmpdir_ = p;
}
string const & getTmpDir()
{
return tmpdir_;
}
string const & homepath()
{
return homepath_;
}
string const & nulldev()
{
static string const nulldev_ = "/dev/null";
return nulldev_;
}

View File

@ -13,8 +13,6 @@
#include <config.h>
#include "support/os.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "debug.h"
@ -28,69 +26,16 @@
# include <direct.h> // _getdrive
#endif
using namespace lyx::support;
using std::endl;
using std::string;
namespace {
string binpath_;
string binname_;
string tmpdir_;
string homepath_;
string nulldev_;
}
namespace lyx {
namespace support {
namespace os {
void init(int /* argc */, char * argv[])
{
static bool initialized = false;
if (initialized)
return;
initialized = true;
string tmp = internal_path(argv[0]);
binname_ = OnlyFilename(tmp);
tmp = ExpandPath(tmp); // This expands ./ and ~/
if (!is_absolute_path(tmp)) {
string binsearchpath = GetEnvPath("PATH");
// This will make "src/lyx" work always :-)
binsearchpath += ";.";
tmp = internal_path(argv[0]);
tmp = FileOpenSearch(binsearchpath, tmp);
}
tmp = MakeAbsPath(OnlyPath(tmp));
// In case we are running in place and compiled with shared libraries
if (suffixIs(tmp, "/.libs/"))
tmp.erase(tmp.length()-6, string::npos);
binpath_ = tmp;
#if defined(__CYGWIN__) || defined(__CYGWIN32__)
tmpdir_ = "/tmp";
homepath_ = GetEnvPath("HOME");
nulldev_ = "/dev/null";
#else
tmpdir_ = string();
homepath_ = GetEnvPath("HOMEDRIVE") + GetEnvPath("HOMEPATH");
nulldev_ = "nul";
#endif
}
void warn(string const & mesg)
{
MessageBox(0, mesg.c_str(), "LyX error",
MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
}
void init(int, char *[])
{}
string current_root()
@ -129,6 +74,7 @@ string::size_type common_path(string const & p1, string const & p2)
string external_path(string const & p)
{
string dos_path;
#if defined(__CYGWIN__) || defined(__CYGWIN32__)
// Translate from cygwin path syntax to dos path syntax
if (is_absolute_path(p)) {
@ -196,38 +142,13 @@ char const * popen_read_mode()
}
string const & binpath()
{
return binpath_;
}
string const & binname()
{
return binname_;
}
void setTmpDir(string const & p)
{
tmpdir_ = p;
}
string const & getTmpDir()
{
return tmpdir_;
}
string const & homepath()
{
return homepath_;
}
string const & nulldev()
{
#if defined(__CYGWIN__) || defined(__CYGWIN32__)
static string const nulldev_ = "/dev/null";
#else
static string const nulldev_ = "nul";
#endif
return nulldev_;
}

696
src/support/package.C.in Normal file
View File

@ -0,0 +1,696 @@
// -*- C++ -*-
/**
* \file package.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*
* Warning! This file is autogenerated from package.C.in.
* All changes to this file will be lost.
*/
#include <config.h>
#include "support/package.h"
#include "debug.h"
#include "gettext.h"
#include "support/FileInfo.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/os.h"
#include <boost/assert.hpp>
#include <boost/tuple/tuple.hpp>
#include <list>
#include <utility>
#if !defined (USE_WINDOWS_PACKAGING) && \
!defined (USE_MACOSX_PACKAGING) && \
!defined (USE_POSIX_PACKAGING)
#error USE_FOO_PACKAGING must be defined for FOO = WINDOWS, MACOSX or POSIX.
#endif
#if defined (USE_WINDOWS_PACKAGING)
# include <windows.h>
# include <shlobj.h> // SHGetFolderPath
// Needed for MinGW:
# ifndef SHGFP_TYPE_CURRENT
# define SHGFP_TYPE_CURRENT 0
# endif
#elif defined (USE_MACOSX_PACKAGING)
# include <CoreServices/CoreServices.h> // FSFindFolder, FSRefMakePath
#endif
using std::string;
namespace lyx {
namespace support {
namespace {
Package package_;
bool initialised_ = false;
} // namespace anon
void init_package(string const & command_line_arg0,
string const & command_line_system_support_dir,
string const & command_line_user_support_dir)
{
// Can do so only once.
if (initialised_)
return;
package_ = Package(command_line_arg0,
command_line_system_support_dir,
command_line_user_support_dir);
initialised_ = true;
}
Package const & package()
{
BOOST_ASSERT(initialised_);
return package_;
}
namespace {
string const abs_path_from_binary_name(string const & exe);
std::pair<string, string> const get_build_dirs(string const & abs_binary);
string const get_document_dir(string const & home_dir);
string const get_home_dir();
string const get_locale_dir(string const & system_support_dir);
string const get_system_support_dir(string const & abs_binary,
string const & command_line_system_support_dir);
string const get_temp_dir();
string const get_default_user_support_dir(string const & home_dir);
std::pair<string, bool> const
get_user_support_dir(string const & default_user_support_dir,
string const & command_line_user_support_dir);
} // namespace anon
Package::Package(string const & command_line_arg0,
string const & command_line_system_support_dir,
string const & command_line_user_support_dir)
: explicit_user_support_dir_(false)
{
home_dir_ = get_home_dir();
temp_dir_ = get_temp_dir();
document_dir_ = get_document_dir(home_dir_);
string const abs_binary = abs_path_from_binary_name(command_line_arg0);
binary_dir_ = OnlyPath(abs_binary);
// Is LyX being run in-place from the build tree?
boost::tie(build_support_dir_, system_support_dir_) =
get_build_dirs(abs_binary);
if (build_support_dir_.empty())
system_support_dir_ =
get_system_support_dir(abs_binary,
command_line_system_support_dir);
locale_dir_ = get_locale_dir(system_support_dir_);
string const default_user_support_dir =
get_default_user_support_dir(home_dir_);
boost::tie(user_support_dir_, explicit_user_support_dir_) =
get_user_support_dir(default_user_support_dir,
command_line_user_support_dir);
lyxerr[Debug::INIT]
<< "<package>\n"
<< "\tbinary_dir " << binary_dir() << '\n'
<< "\tsystem_support " << system_support() << '\n'
<< "\tbuild_support " << build_support() << '\n'
<< "\tuser_support " << user_support() << '\n'
<< "\tlocale_dir " << locale_dir() << '\n'
<< "\tdocument_dir " << document_dir() << '\n'
<< "\ttemp_dir " << temp_dir() << '\n'
<< "\thome_dir " << home_dir() << '\n'
<< "<\\package>\n" << std::endl;
}
namespace {
// These next three functions contain the stuff that is substituted at
// configuration-time.
string const top_srcdir()
{
static string const dir("%TOP_SRCDIR%");
return dir;
}
string const hardcoded_localedir()
{
return string("%LOCALEDIR%");
}
string const hardcoded_system_support_dir()
{
return string("%LYX_DIR%");
}
} // namespace anon
string const & Package::top_srcdir() const
{
static string const dir("%TOP_SRCDIR%");
return dir;
}
namespace {
bool check_command_line_dir(string const & dir,
string const & file,
string const & command_line_switch);
string const extract_env_var_dir(string const & env_var);
bool check_env_var_dir(string const & dir,
string const & env_var);
bool check_env_var_dir(string const & dir,
string const & file,
string const & env_var);
string const relative_locale_dir();
string const relative_system_support_dir();
#if defined (USE_WINDOWS_PACKAGING)
// Given a folder ID, returns the folder name (in unix-style format).
// Eg CSIDL_PERSONAL -> "C:/Documents and Settings/USERNAME/My Documents"
string const win32_folder_path(int folder_id)
{
char folder_path[PATH_MAX + 1];
if (SUCCEEDED(SHGetFolderPath(0, folder_id, 0,
SHGFP_TYPE_CURRENT, folder_path)))
return os::internal_path(folder_path);
return string();
}
#endif
std::pair<string, string> const get_build_dirs(string const & abs_binary)
{
string const check_text = "Checking whether LyX is run in place...";
// We're looking for "lyxrc.defaults" in a directory
// binary_dir/../lib
// We're also looking for "chkconfig.ltx" in a directory
// binary_dir/top_srcdir()/lib
// If both are found, then we're running LyX in-place.
// Note that the name of the lyx binary may be a symbolic link.
// If that is the case, then we follow the links too.
string binary = abs_binary;
while (true) {
// Try and find "lyxrc.defaults".
string const binary_dir = OnlyPath(binary);
string const build_support_dir =
NormalizePath(AddPath(binary_dir, "../lib"));
if (!FileSearch(build_support_dir, "lyxrc.defaults").empty()) {
// Try and find "chkconfig.ltx".
string const system_support_dir =
MakeAbsPath(AddPath(top_srcdir(), "lib"),
AddPath(binary_dir, "support"));
if (!FileSearch(system_support_dir, "chkconfig.ltx").empty()) {
lyxerr[Debug::INIT] << check_text << " yes"
<< std::endl;
return std::make_pair(build_support_dir, system_support_dir);
}
}
// Check whether binary is a symbolic link.
// If so, resolve it and repeat the exercise.
FileInfo const file(binary, true);
if (!file.isOK() || !file.isLink())
break;
string link;
if (LyXReadLink(binary, link, true)) {
binary = link;
} else {
// Unable to resolve the link.
break;
}
}
lyxerr[Debug::INIT] << check_text << " no" << std::endl;
return std::make_pair(string(), string());
}
// Specification of document_dir_ may be reset by LyXRC,
// but the default is fixed for a given OS.
string const get_document_dir(string const & home_dir)
{
#if defined (USE_WINDOWS_PACKAGING)
(void)home_dir; // Silence warning about unused variable.
return win32_folder_path(CSIDL_PERSONAL);
#else // Posix-like.
return home_dir;
#endif
}
// The specification of home_dir_ is fixed for a given OS.
// A typical example on Windows: "C:/Documents and Settings/USERNAME"
// and on a Posix-like machine: "/home/USERNAME".
string const get_home_dir()
{
#if defined (USE_WINDOWS_PACKAGING)
string const home_dir = GetEnv("USERPROFILE");
#else // Posix-like.
string const home_dir = GetEnv("HOME");
#endif
return os::internal_path(home_dir);
}
// Several sources are probed to ascertain the locale directory.
// The only requirement is that the result is indeed a directory.
string const get_locale_dir(string const & system_support_dir)
{
// 1. Use the "LYX_LOCALEDIR" environment variable.
string path = extract_env_var_dir("LYX_LOCALEDIR");
if (!path.empty() && check_env_var_dir(path, "LYX_LOCALEDIR"))
return path;
// 2. Search for system_support_dir / <relative locale dir>
// The <relative locale dir> is OS-dependent. (On Unix, it will
// be "../locale/".)
path = NormalizePath(AddPath(system_support_dir, relative_locale_dir()));
FileInfo fi(path);
if (fi.isOK() && fi.isDir())
return path;
// 3. Fall back to the hard-coded LOCALEDIR.
path = hardcoded_localedir();
FileInfo fi2(path);
if (fi2.isOK() && fi2.isDir())
return path;
return string();
}
// Specification of temp_dir_ may be reset by LyXRC,
// but the default is fixed for a given OS.
string const get_temp_dir()
{
#if defined (USE_WINDOWS_PACKAGING)
// Typical example: C:/TEMP/.
char path[PATH_MAX + 1];
GetTempPath(PATH_MAX, path);
return os::internal_path(path);
#else // Posix-like.
return "/tmp";
#endif
}
// If we use a 'lazy' lyxerr in the hope of setting the locale before
// printing any messages, then we should ensure that it is flushed first.
void bail_out()
{
#ifndef CXX_GLOBAL_CSTD
using std::exit;
#endif
exit(1);
}
// Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
string const abs_path_from_command_line(string const & command_line)
{
if (command_line.empty())
return string();
string const path = os::internal_path(command_line);
return os::is_absolute_path(path) ? path : MakeAbsPath(path);
}
// Does the grunt work for abs_path_from_binary_name()
string const get_binary_path(string const & exe)
{
string const exe_path = os::internal_path(exe);
if (os::is_absolute_path(exe_path))
return exe_path;
// Two possibilities present themselves.
// 1. The binary is relative to the CWD.
string const abs_exe_path = MakeAbsPath(exe_path);
if (FileInfo(abs_exe_path, true).isOK())
return abs_exe_path;
// 2. exe must be the name of the binary only and it
// can be found on the PATH.
string const exe_name = OnlyFilename(exe_path);
if (exe_name != exe_path)
return string();
std::vector<string> const path = getEnvPath("PATH");
std::vector<string>::const_iterator it = path.begin();
std::vector<string>::const_iterator const end = path.end();
for (; it != end; ++it) {
if (!os::is_absolute_path(*it))
// Someone is playing silly buggers.
continue;
string const exe_path = AddName(*it, exe_name);
if (FileInfo(exe_path, true).isOK())
return exe_path;
}
// Didn't find anything.
return string();
}
// Extracts the absolute path to the binary name received as argv[0].
string const abs_path_from_binary_name(string const & exe)
{
string const abs_binary = get_binary_path(exe);
if (abs_binary.empty()) {
lyxerr << bformat(_("Unable to determine the path to the "
"LyX binary from the command line %1%"),
exe)
<< std::endl;
bail_out();
}
return abs_binary;
}
// A plethora of directories is searched to ascertain the system
// lyxdir which is defined as the first directory to contain
// "chkconfig.ltx".
string const
get_system_support_dir(string const & abs_binary,
string const & command_line_system_support_dir)
{
string const chkconfig_ltx = "chkconfig.ltx";
// searched_dirs is used for diagnostic purposes only in the case
// that "chkconfig.ltx" is not found.
std::list<string> searched_dirs;
// 1. Use the -sysdir command line parameter.
string path = abs_path_from_command_line(command_line_system_support_dir);
if (!path.empty()) {
searched_dirs.push_back(path);
if (check_command_line_dir(path, chkconfig_ltx, "-sysdir"))
return path;
}
// 2. Use the "LYX_DIR_13x" environment variable.
path = extract_env_var_dir("LYX_DIR_13x");
if (!path.empty()) {
searched_dirs.push_back(path);
if (check_env_var_dir(path, chkconfig_ltx, "LYX_DIR_13x"))
return path;
}
// 3. Search relative to the lyx binary.
// We're looking for "chkconfig.ltx" in a directory
// OnlyPath(abs_binary) / <relative dir> / PACKAGE /
// PACKAGE is hardcoded in config.h. Eg "lyx" or "lyx-1.3.6cvs".
// <relative dir> is OS-dependent; on Unix, it will be "../share/".
string const relative_lyxdir = relative_system_support_dir();
// One subtlety to be aware of. The name of the lyx binary may be
// a symbolic link. If that is the case, then we follow the links too.
string binary = abs_binary;
while (true) {
// Try and find "chkconfig.ltx".
string const binary_dir = OnlyPath(binary);
string const lyxdir =
NormalizePath(AddPath(binary_dir, relative_lyxdir));
searched_dirs.push_back(lyxdir);
if (!FileSearch(lyxdir, chkconfig_ltx).empty()) {
// Success! "chkconfig.ltx" has been found.
return lyxdir;
}
// Check whether binary is a symbolic link.
// If so, resolve it and repeat the exercise.
FileInfo const file(binary, true);
if (!file.isOK() || !file.isLink())
break;
string link;
if (LyXReadLink(binary, link, true)) {
binary = link;
} else {
// Unable to resolve the link.
break;
}
}
// 4. Repeat the exercise on the directory itself.
string binary_dir = OnlyPath(abs_binary);
while (true) {
// This time test whether the directory is a symbolic link
// *before* looking for "chkconfig.ltx".
// (We've looked relative to the original already.)
FileInfo const file(binary_dir, true);
if (!file.isOK() || !file.isLink())
break;
string link;
if (LyXReadLink(binary_dir, link, true)) {
binary_dir = link;
} else {
// Unable to resolve the link.
break;
}
// Try and find "chkconfig.ltx".
string const lyxdir =
NormalizePath(AddPath(binary_dir, relative_lyxdir));
searched_dirs.push_back(lyxdir);
if (!FileSearch(lyxdir, chkconfig_ltx).empty()) {
// Success! "chkconfig.ltx" has been found.
return lyxdir;
}
}
// 5. In desparation, try the hard-coded system support dir.
path = hardcoded_system_support_dir();
if (!FileSearch(path, chkconfig_ltx).empty())
return path;
// Everything has failed :-(
// So inform the user and exit.
string searched_dirs_str;
typedef std::list<string>::const_iterator iterator;
iterator const begin = searched_dirs.begin();
iterator const end = searched_dirs.end();
for (iterator it = begin; it != end; ++it) {
if (it != begin)
searched_dirs_str += "\n\t";
searched_dirs_str += *it;
}
lyxerr << bformat(_("Unable to determine the system directory "
"having searched\n"
"\t%1%\n"
"Try the '-sysdir' command line parameter or "
"set the environment variable LYX_DIR_13x to "
"the LyX system directory containing the file "
"`chkconfig.ltx'."),
searched_dirs_str)
<< std::endl;
bail_out();
// Keep the compiler happy.
return string();
}
// Returns the absolute path to the user lyxdir, together with a flag
// indicating whether this directory was specified explicitly (as -userdir
// or through an environment variable) or whether it was deduced.
std::pair<string, bool> const
get_user_support_dir(string const & default_user_support_dir,
string const & command_line_user_support_dir)
{
bool explicit_userdir = true;
// 1. Use the -userdir command line parameter.
string path =
abs_path_from_command_line(command_line_user_support_dir);
if (!path.empty())
return std::make_pair(path, explicit_userdir);
// 2. Use the LYX_USERDIR_13x environment variable.
path = extract_env_var_dir("LYX_USERDIR_13x");
if (!path.empty())
return std::make_pair(path, explicit_userdir);
// 3. Use the OS-dependent default_user_support_dir
explicit_userdir = false;
return std::make_pair(default_user_support_dir, explicit_userdir);
}
// $HOME/.lyx on all platforms but Win32 where it will be something like
// "C:/Documents and Settings/USERNAME/Application Data/lyx"
string const get_default_user_support_dir(string const & home_dir)
{
#if defined (USE_WINDOWS_PACKAGING)
(void)home_dir; // Silence warning about unused variable.
return AddPath(win32_folder_path(CSIDL_APPDATA), PACKAGE);
#elif defined (USE_MACOSX_PACKAGING)
(void)home_dir; // Silence warning about unused variable.
FSRef fsref;
OSErr const error_code =
FSFindFolder(kUserDomain, kApplicationSupportFolderType,
kDontCreateFolder, &fsref);
if (error_code != 0)
return string();
char store[PATH_MAX + 1];
OSStatus const status_code =
FSRefMakePath(&fsref,
reinterpret_cast<UInt8*>(store), PATH_MAX);
if (status_code != 0)
return string();
return AddPath(reinterpret_cast<char const *>(store), PACKAGE);
#else // USE_POSIX_PACKAGING
return AddPath(home_dir, string(".") + PACKAGE);
#endif
}
// Check that directory @c dir contains @c file.
// Else emit a warning about an invalid @c command_line_switch.
bool check_command_line_dir(string const & dir,
string const & file,
string const & command_line_switch)
{
string const abs_path = FileSearch(dir, file);
if (abs_path.empty()) {
lyxerr << bformat(_("Invalid %1% switch.\n"
"Directory %2% does not contain %3%."),
command_line_switch, dir, file)
<< std::endl;
}
return !abs_path.empty();
}
// The environment variable @c env_var expands to a (single) file path.
string const extract_env_var_dir(string const & env_var)
{
string const dir = os::internal_path(GetEnv(env_var));
return dir.empty() ? dir : MakeAbsPath(dir);
}
// Check that directory @c dir contains @c file.
// Else emit a warning about an invalid @c env_var.
bool check_env_var_dir(string const & dir,
string const & file,
string const & env_var)
{
string const abs_path = FileSearch(dir, file);
if (abs_path.empty()) {
lyxerr << bformat(_("Invalid %1% environment variable.\n"
"Directory %2% does not contain %3%."),
env_var, dir, file)
<< std::endl;
}
return !abs_path.empty();
}
// Check that directory @c dir is indeed a directory.
// Else emit a warning about an invalid @c env_var.
bool check_env_var_dir(string const & dir,
string const & env_var)
{
FileInfo fi(dir);
bool const success = (fi.isOK() && fi.isDir());
if (!success) {
lyxerr << bformat(_("Invalid %1% environment variable.\n"
"%2% is not a directory."),
env_var, dir)
<< std::endl;
}
return success;
}
// The locale directory relative to the LyX system directory.
string const relative_locale_dir()
{
return "../locale/";
}
// The system lyxdir is relative to the directory containing the LyX binary.
string const relative_system_support_dir()
{
string result;
#if defined (USE_WINDOWS_PACKAGING) || defined (USE_MACOSX_PACKAGING)
result = AddPath("../Resources/", PACKAGE);
#else // Posix-like.
result = AddPath("../share/", PACKAGE);
#endif
return result;
}
} // namespace anon
} // namespace support
} // namespace lyx

183
src/support/package.h Normal file
View File

@ -0,0 +1,183 @@
// -*- C++ -*-
/**
* \file package.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*
* A store of the paths to the various different directoies used
* by LyX. These paths differ markedly from one OS to another,
* following the local Windows, MacOS X or Posix conventions.
*/
#ifndef LYX_PACHAGE_H
#define LYX_PACHAGE_H
#include <string>
namespace lyx {
namespace support {
class Package;
/** Initialise package() with the command line data.
* This data is exactly as it was passed in the argv[] array.
*
* @param command_line_arg0 argv[0], the name of the LyX executable
* as passed on the command line.
*
* @param command_line_system_support_dir, the LyX system dir,
* as specified on the command line with "-sysdir <path to dir>".
*
* @param command_line_user_support_dir, the LyX user dir,
* as specified on the command line with "-userdir <path to dir>".
*/
void init_package(std::string const & command_line_arg0,
std::string const & command_line_system_support_dir,
std::string const & command_line_user_support_dir);
/** Accessor to the global data.
* Asserts that init_package() has been called first.
*/
Package const & package();
class Package {
public:
/// Default constructor does not lead to the paths being set.
Package();
/** Called by init_package, above.
* All paths will be initialized.
*/
Package(std::string const & command_line_arg0,
std::string const & command_line_system_support_dir,
std::string const & command_line_user_support_dir);
/** The directory containing the LyX executable.
*/
std::string const & binary_dir() const;
/** The top of the LyX source code tree.
* Used by the GTK frontend when searching for .glade files.
*/
std::string const & top_srcdir() const;
/** The path to the system-level support files
* we're actually going to use.
*/
std::string const & system_support() const;
/** The path to the autogenerated support files
* when running in-place.
*/
std::string const & build_support() const;
/** The path to the user-level support files.
*/
std::string const & user_support() const;
/** The user_support directory was set explicitly using either
* the -userdir command line switch or
* the LYX_USERDIR_13x environment variable.
*/
bool explicit_user_support() const;
/** The path to the locale directory.
*/
std::string const & locale_dir() const;
/** The default document directory.
* Can be reset by LyXRC.
*/
std::string & document_dir() const;
/** The path to the temporary directory.
* (Eg /tmp on *nix.)
* Can be reset by LyXRC.
*/
std::string & temp_dir() const;
/** Used when setting the user_support directory.
* Used also when expanding "~/" or contracting to "~/". (filetools.C)
* Used by the XForms file dialog.
* Used in emergencyWrite (bufferlist.C) as one possible location
* for the dump.
*/
std::string const & home_dir() const;
private:
std::string binary_dir_;
std::string system_support_dir_;
std::string build_support_dir_;
std::string user_support_dir_;
std::string locale_dir_;
mutable std::string document_dir_;
mutable std::string temp_dir_;
std::string home_dir_;
bool explicit_user_support_dir_;
};
inline
Package::Package() {}
inline
std::string const & Package::binary_dir() const
{
return binary_dir_;
}
inline
std::string const & Package::system_support() const
{
return system_support_dir_;
}
inline
std::string const & Package::build_support() const
{
return build_support_dir_;
}
inline
std::string const & Package::user_support() const
{
return user_support_dir_;
}
inline
bool Package::explicit_user_support() const
{
return explicit_user_support_dir_;
}
inline
std::string const & Package::locale_dir() const
{
return locale_dir_;
}
inline
std::string & Package::document_dir() const
{
return document_dir_;
}
inline
std::string & Package::temp_dir() const
{
return temp_dir_;
}
inline
std::string const & Package::home_dir() const
{
return home_dir_;
}
} // namespace support
} // namespace lyx
#endif // LYX_PACHAGE_H

View File

@ -1,383 +0,0 @@
// -*- C++ -*-
/**
* \file path_defines.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*
* Warning! This file is autogenerated from path_defines.C.in.
* All changes to this file will be lost.
*/
#include <config.h>
#include "path_defines.h"
#include "debug.h"
#include "gettext.h"
#include "FileInfo.h"
#include "filetools.h"
#include "lstrings.h"
#include "os.h"
#include "lyxlib.h"
using std::string;
using std::endl;
namespace {
// Store for the path to the lyx support files we're actually going to use.
string system_lyxdir_;
// Store for the path to the autogenerated files when running in place
string build_lyxdir_;
// Store for the path to the user-level support files.
string user_lyxdir_;
// Store for the path to the locale directory.
string localedir_;
/* The absolute path to the system-level lyx support files.
* (Make-time value.)
*/
string const & lyx_dir()
{
static string const ld = "%LYX_DIR%";
return ld;
}
} // namespace anon
namespace lyx {
namespace support {
/* The absolute path to the top of the lyx build tree.
* (Make-time value.)
*/
string const & top_srcdir()
{
static string const lts = "%TOP_SRCDIR%";
return lts;
}
/* The absolute path to the system-level lyx locale directory.
* (Make-time value.)
*/
string const & lyx_localedir()
{
static string const ll = "%LOCALEDIR%";
if (localedir_.empty())
return ll;
else
return localedir_;
}
string const & build_dir()
{
static string const bl = "%BUILDDIR%";
return bl;
}
string const & build_lyxdir()
{
return build_lyxdir_;
}
void build_lyxdir(string const & sld)
{
build_lyxdir_ = sld;
}
string const & system_lyxdir()
{
return system_lyxdir_;
}
void system_lyxdir(string const & sld)
{
system_lyxdir_ = sld;
}
string const & user_lyxdir()
{
return user_lyxdir_;
}
void user_lyxdir(string const & uld)
{
user_lyxdir_ = uld;
}
bool setLyxPaths()
{
//
// Determine path of binary
//
string binpath = os::binpath();
string binname = os::binname();
string fullbinname = MakeAbsPath(binname, binpath);
if (binpath.empty()) {
lyxerr << _("Warning: could not determine path of binary.")
<< "\n"
<< _("If you have problems, try starting LyX with an absolute path.")
<< endl;
}
lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
string searchpath;
//
// Determine whether we are running in place and set
// build_lyxdir accordingly
//
string const buildlyxdir = MakeAbsPath("../lib", binpath);
if (!FileSearch(buildlyxdir, "lyxrc.defaults").empty()) {
searchpath += AddPath(top_srcdir(), "lib") + ';';
build_lyxdir(buildlyxdir);
lyxerr[Debug::INIT] << "Checking whether LyX is run in "
"place... yes" << endl;
} else {
lyxerr[Debug::INIT]
<< "Checking whether LyX is run in place... no"
<< endl;
}
//
// Determine system directory.
//
// Directories are searched in this order:
// 1) -sysdir command line parameter
// 2) LYX_DIR_14x environment variable
// 3) Maybe <path of binary>/TOP_SRCDIR/lib
// 4) <path of binary>/../Resources/<name of binary>/ [for LyX/Mac]
// 5) <path of binary>/../share/<name of binary>/
// 5a) repeat 4 after following the Symlink if <path of
// binary> is a symbolic link.
// 6) hardcoded lyx_dir
// The directory is checked for the presence of the file
// "chkconfig.ltx", and if that is present, the directory
// is accepted as the system directory.
// If no chkconfig.ltx file is found, a warning is given,
// and the hardcoded lyx_dir is used.
// If we had a command line switch, system_lyxdir_ is already set
if (!system_lyxdir_.empty())
searchpath = MakeAbsPath(system_lyxdir_) + ';';
string const lyxdir = GetEnvPath("LYX_DIR_14x");
if (!lyxdir.empty()) {
lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
searchpath += lyxdir + ';';
}
// Path of binary/../Resources/
searchpath += NormalizePath(AddPath(binpath, "../Resources/") +
OnlyFilename(binname)) + ';';
string fullbinpath = binpath;
FileInfo file(fullbinname, true);
if (file.isLink()) {
lyxerr[Debug::INIT] << "binary is a link" << endl;
string link;
if (LyXReadLink(fullbinname, link, true)) {
// Path of binary/../share/name of binary/
searchpath += NormalizePath(AddPath(binpath,
"../share/")
+ OnlyFilename(binname));
searchpath += ';';
fullbinpath = link;
binpath = MakeAbsPath(OnlyPath(fullbinpath));
}
}
bool followlink;
do {
// Path of binary/../share/name of binary/
string const exe_name = OnlyFilename(binname);
#ifdef _WIN32
string const lyx_system_dir_name =
suffixIs(exe_name, ".exe") ?
ChangeExtension(exe_name, "") :
exe_name;
#else
string const lyx_system_dir_name = exe_name;
#endif
string const shared_dir_name =
NormalizePath(AddPath(binpath, "../share/"));
searchpath += shared_dir_name + lyx_system_dir_name + ';';
// Follow Symlinks
FileInfo file(fullbinpath, true);
followlink = file.isLink();
if (followlink) {
lyxerr[Debug::INIT] << " directory " << fullbinpath
<< " is a link" << endl;
string link;
if (LyXReadLink(fullbinpath, link, true)) {
fullbinpath = link;
binpath = MakeAbsPath(OnlyPath(fullbinpath));
}
else {
followlink = false;
}
}
} while (followlink);
// <absolute top srcdir>/lib
searchpath += AddPath(top_srcdir(), "lib") + ';';
// Hardcoded dir
searchpath += lyx_dir();
lyxerr[Debug::INIT] << "System directory search path: "
<< searchpath << endl;
string const filename = "chkconfig.ltx";
string const temp = FileOpenSearch(searchpath, filename, string());
system_lyxdir_ = OnlyPath(temp);
// Reduce "path/../path" stuff out of system directory
system_lyxdir_ = NormalizePath(system_lyxdir_);
bool path_shown = false;
// Warn if environment variable is set, but unusable
if (!lyxdir.empty()) {
if (system_lyxdir_ != NormalizePath(lyxdir)) {
lyxerr <<_("LYX_DIR_14x environment variable no good.")
<< '\n'
<< _("System directory set to: ")
<< system_lyxdir_ << endl;
path_shown = true;
}
}
// Warn the user if we couldn't find "chkconfig.ltx"
if (system_lyxdir_ == "./") {
lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
<<_("Try the '-sysdir' command line parameter or ")
<<_("set the environment variable LYX_DIR_14x to the "
"LyX system directory ")
<< _("containing the file `chkconfig.ltx'.") << endl;
if (!path_shown) {
FileInfo fi(lyx_dir());
if (!fi.exist()) {
lyxerr << "Couldn't even find the default LYX_DIR." << endl
<< "Giving up." << endl;
exit(1);
}
lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
lyx_dir()) << endl;
} else {
lyxerr << _("Expect problems.") << endl;
}
system_lyxdir_ = lyx_dir();
path_shown = true;
}
if (!path_shown)
lyxerr[Debug::INIT] << "System directory: '"
<< system_lyxdir_ << '\'' << endl;
// This is true when we are running from a Mac OS X bundle
// (for LyX/Mac)
bool const inOSXBundle =
system_lyxdir_ == NormalizePath(AddPath(binpath, "../Resources/")
+ OnlyFilename(binname));
if (inOSXBundle)
lyxerr[Debug::INIT] << "Running from LyX/Mac bundle."
<< endl;
//
// Set PATH for LyX/Mac
// LyX/Mac is a relocatable application bundle; here we add to
// the PATH so it can find binaries like reLyX inside its own
// application bundle, and also append PATH elements that it
// needs to run latex, previewers, etc.
//
if (inOSXBundle) {
const string newpath = GetEnv("PATH") + ":" + binpath
+ ":/sw/bin:/usr/local/bin"
+ ":/usr/local/teTeX/bin/powerpc-apple-darwin-current";
lyx::support::putenv("PATH", newpath);
lyxerr[Debug::INIT] << "LyX/Mac: setting PATH to: "
<< GetEnv("PATH") << endl;
}
//
// Determine locale directory
//
if (!GetEnv("LYX_LOCALEDIR").empty()) {
localedir_ = GetEnv("LYX_LOCALEDIR");
lyxerr[Debug::INIT] << "LYX_LOCALEDIR=" << localedir_ << endl;
} else if (inOSXBundle) {
string const maybe_localedir =
NormalizePath(AddPath(system_lyxdir_, "../locale"));
FileInfo fi(maybe_localedir);
if (fi.isOK() && fi.isDir()) {
lyxerr[Debug::INIT]
<< "LyX/Mac: setting locale directory to "
<< maybe_localedir << endl;
localedir_ = maybe_localedir;
}
}
//
// Determine user lyx-dir
//
// Directories are searched in this order:
// 1) -userdir command line parameter
// 2) LYX_USERDIR_14x environment variable
// 3) $HOME/.<name of binary>
// If we had a command line switch, user_lyxdir_ is already set
bool explicit_userdir = true;
if (user_lyxdir_.empty()) {
// LYX_USERDIR_14x environment variable
user_lyxdir_ = GetEnvPath("LYX_USERDIR_14x");
// default behaviour
if (user_lyxdir_.empty())
if (inOSXBundle)
user_lyxdir_ = AddPath(os::homepath(),
"Library/Preferences/LyX");
else
user_lyxdir_ = AddPath(os::homepath(),
string(".") + PACKAGE);
explicit_userdir = false;
}
lyxerr[Debug::INIT] << "User LyX directory: '"
<< user_lyxdir_ << '\'' << endl;
return explicit_userdir;
}
} // namespace support
} // namespace lyx

View File

@ -1,51 +0,0 @@
// -*- C++ -*-
/**
* \file path_defines.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#ifndef PATH_DEFINES_H
#define PATH_DEFINES_H
#include <string>
namespace lyx {
namespace support {
std::string const & lyx_localedir();
/* The absolute path to the top of the lyx build tree.
* (Make-time value.)
*/
std::string const & top_srcdir();
/// The absolute path to the lyx support files we're actually going to use.
std::string const & system_lyxdir();
/// Set the absolute path to the lyx support files (from the command line).
void system_lyxdir(std::string const &);
/// The absolute path to the lyx support files in the build directory
std::string const & build_lyxdir();
/// The absolute path to the user-level lyx support files.
std::string const & user_lyxdir();
/// Set the absolute path to the user-level lyx support files.
void user_lyxdir(std::string const &);
/** \returns true if the user lyx dir existed already and did not need
* to be created afresh.
*/
bool setLyxPaths();
} // namespace support
} // namespace lyx
#endif // NOT PATH_DEFINES_H

View File

@ -11,9 +11,10 @@
#include <config.h>
#include "support/lyxlib.h"
#include "support/filetools.h"
#include "support/convert.h"
#include "support/os.h"
#include "support/filetools.h"
#include "support/package.h"
#include "debug.h"
@ -53,7 +54,7 @@ int make_tempfile(char * templ)
string const lyx::support::tempName(string const & dir, string const & mask)
{
string const tmpdir(dir.empty() ? os::getTmpDir() : dir);
string const tmpdir(dir.empty() ? package().temp_dir() : dir);
string tmpfl(AddName(tmpdir, mask));
tmpfl += convert<string>(getpid());
tmpfl += "XXXXXX";

View File

@ -1,3 +1,8 @@
2005-01-10 Angus Leeming <leeming@lyx.org>
* tex2lyx.C: use support/package.h to provide the paths to the
various directories used by LyX.
2005-01-06 Lars Gullik Bjonnes <larsbj@gullik.net>
* text.C: tostr -> convert
@ -11,8 +16,6 @@
* preamble.C (parse_preamble): handle second optional arg of
\newcommand etc. and add the command to the known commands (fixes
bug 1750)
* texparser.[Ch] (getFullArg): new, like getArg but distinguish
between empty arguments and no argument found
* texparser.[Ch] (getFullOpt): new, like getOpt but distinguish
between empty arguments and no argument found
* tex2lyx.[Ch]: (add_known_command): new

View File

@ -17,11 +17,11 @@
#include "debug.h"
#include "lyxtextclass.h"
#include "support/path_defines.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/package.h"
#include <boost/function.hpp>
@ -51,8 +51,6 @@ using lyx::support::isStrUnsignedInt;
using lyx::support::ltrim;
using lyx::support::rtrim;
using lyx::support::strToUnsignedInt;
using lyx::support::system_lyxdir;
using lyx::support::user_lyxdir;
using lyx::support::IsFileReadable;
using lyx::support::IsFileWriteable;
@ -249,13 +247,19 @@ int parse_syntaxfile(string const & arg, string const &)
}
// Filled with the command line arguments "foo" of "-sysdir foo" or
// "-userdir foo".
string cl_system_support;
string cl_user_support;
int parse_sysdir(string const & arg, string const &)
{
if (arg.empty()) {
cerr << "Missing directory for -sysdir switch" << endl;
exit(1);
}
system_lyxdir(arg);
cl_system_support = arg;
return 1;
}
@ -266,7 +270,7 @@ int parse_userdir(string const & arg, string const &)
cerr << "Missing directory for -userdir switch" << endl;
exit(1);
}
user_lyxdir(arg);
cl_user_support = arg;
return 1;
}
@ -381,7 +385,7 @@ int main(int argc, char * argv[])
}
lyx::support::os::init(argc, argv);
lyx::support::setLyxPaths();
lyx::support::init_package(argv[0], cl_system_support, cl_user_support);
string const system_syntaxfile = lyx::support::LibFileSearch("reLyX", "syntax.default");
if (system_syntaxfile.empty()) {