]> git.lyx.org Git - lyx.git/commitdiff
The package reworking.
authorAngus Leeming <leeming@lyx.org>
Mon, 10 Jan 2005 19:17:43 +0000 (19:17 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 10 Jan 2005 19:17:43 +0000 (19:17 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9463 a592a061-630c-0410-9148-cb99ea01b6c8

48 files changed:
config/ChangeLog
config/lyxinclude.m4
configure.ac
po/POTFILES.in
src/BufferView_pimpl.C
src/ChangeLog
src/bufferlist.C
src/client/ChangeLog
src/client/messages.C
src/exporter.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlAboutlyx.C
src/frontends/controllers/ControlGraphics.C
src/frontends/controllers/helper_funcs.C
src/frontends/controllers/tex_helpers.C
src/frontends/gnome/ChangeLog
src/frontends/gnome/lyx_gui.C
src/frontends/gtk/ChangeLog
src/frontends/gtk/ghelpers.C
src/frontends/gtk/lyx_gui.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/lyx_gui.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormFiledialog.C
src/frontends/xforms/FormPreferences.C
src/frontends/xforms/lyx_gui.C
src/insets/ChangeLog
src/insets/ExternalSupport.C
src/insets/ExternalTemplate.C
src/lyx_cb.C
src/lyx_main.C
src/lyxfunc.C
src/messages.C
src/support/ChangeLog
src/support/Makefile.am
src/support/filetools.C
src/support/filetools.h
src/support/os.h
src/support/os_os2.C
src/support/os_unix.C
src/support/os_win32.C
src/support/package.C.in [new file with mode: 0644]
src/support/package.h [new file with mode: 0644]
src/support/path_defines.C.in [deleted file]
src/support/path_defines.h [deleted file]
src/support/tempname.C
src/tex2lyx/ChangeLog
src/tex2lyx/tex2lyx.C

index 3de6b3923aac20bc14981f8be94970a9cfa39f8c..a13821f4499b6c91e202620ad264edaf52fb58e2 100644 (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
index d1b3b8488fd72f99258bd01512c71cd3ca523e28..eb2aa64ecccaeaded2df34f38162d29813f5566f 100644 (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)
index be36a8c8ef7770042a6239d62c23ef8cb9842f06..a8a2ffafde8c2fcaaa4790fa94c29e44f5c10104 100644 (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"
 
index 566e18cd4f1d5ee9d615d1047fd9585eeccd4e3d..295efd9f1529fb02afdafc101c47f4d18a224700 100644 (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
index 9bf0dadfc6a1b19ca934b421a730e224da81d5d8..bc8b3ee1484c07e63f93b4dddb5eb02ec9886fbc 100644 (file)
 
 #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,
index 51460ea0bcef2c04105069cfee753179b33aea70..fe2acaeca1af4e0fa53ff84645cf892ae6dc1431 100644 (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
index d5a5e0252f6fd25c4c77fa4e144bb2cd630b2f09..2ae3df66871419a7450d8f7a8e690c61e7c547fc 100644 (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)) {
index c8fecd592b3b5046c31ac23632e2505e2a44258e..8417fe70cf837aae94982af7512827da0ce12aaf 100644 (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;"
index a118c733b327baba3954fc9dcd2a8b6c8be6c56a..c1b0f8bae3f36db0b8f13d09693edb110cc06756 100644 (file)
 
 #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);
index ba090ea8af942df6bf915f4985e564bea679da86..7576096d6b70969d41b2f94c8e6bd404c51fc2e5 100644 (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) {
index d9c4f73e2099fc488f88d4ad0ac3e1be18641bf7..f0eec8a4da0887ce484a2a98c9fcc18ae088eed8 100644 (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):
index 6591b6f7488061f231dedea8bb4c63760c649dd1..b0b7ef1d34726c01ed26b65f1cb848301790c461 100644 (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();
 }
index 8335e35713ade4feb487a656ce92329274b4cce7..611afc09105db1fa17f301d3e2a28084454147d3 100644 (file)
 
 #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
index 7d9fdb1614a1f85dfdd159852d1e2b4845bde52c..aafd5f35377a67be33e5f9acee9cd5903f83f706 100644 (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);
index 383464b96be295b4c956f901cee0c55eb76c7f2e..66583a32b15c23ca6960ce8cf44e93317b1eb821 100644 (file)
 
 #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;
index 2bb1ab2900b485578f503d96b0b12c1923b59bdd..64220996422bea0d9de872264b3063d105057b04 100644 (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.
index eac418cb20aff9a595cf31addf2c24d03291dac4..4c9e3460ab80db3ef5dc291c99b9c36e5a2b469d 100644 (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);
        }
 
index 4123144369dc49920c4e1ac790307cc49fbeffe9..047230d8183ee5a23180db4146c2cac02c2d6263 100644 (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
index 2491e1721d67b334a6c07672cd77030a80bce02c..7d0d85c43e8125d8ff4bf3cee7ca57a3a34937ab 100644 (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");
index 0d940337e0916415d5ecd59f6c613c3d391e7bae..64f4affea9b7153825cf602ef079fe816d755d84 100644 (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));
index d2f582536640a409dedc4bacbfc7cede7b2ba67a..3e13694d477866ee370f6891368f0c8886554680 100644 (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
index ad5a739347c5d3d782acff97911a5d4893b39072..f5230da5570d72ea3dd4dde4ceee1490b6e2e2b7 100644 (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));
index ea6cc1f3d9dab8c5b173f3c0e22f1a2051076e29..a8861acd8649a2891b6c233e86cc670494419e27 100644 (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:
index 7cea65f8f4fd59654c8d1ad8f6830bcc17e0abb0..4f901282199e30162ad3e4423d898fe4e0de7782 100644 (file)
 
 #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;
index 4593bddf5f8c8c378cb475daa7f99dee1f1556bd..c79c6432532ab44afcaf02af20d87dd4d50c4ef7 100644 (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);
        }
 }
index fcf67db9232ff5ab5b969b8fba42192bb258a6fe..9b19a07309b04baa1eb9ec596c150ecb2140f90c 100644 (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));
index a73f5cdf1869bde817c64cba9409ccfd29e46a37..5a20dfe6cbf081e18a749db66721394e6ccad9a6 100644 (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:
index 510b02c4397b60f700abd1d43d4c50a111d9d529..081520a24d9d5fed0a210d86d606b066c087a822 100644 (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(\"")) {
index 482a0663dbf7e567bd6c341c3649d9bae607e2a1..197667759426db5dd075d07a37e8ec985710ae39 100644 (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';
index 211bae8df72e0c107c5d5c57ef7df373e54a5a89..24dbdb8afc88189c3f25bd7f8bb3381c858a21bf 100644 (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);
index 15cbee94a5e2b4799ce1a87cbb7eb4447d39444d..4e09a294745f8ceaa5b7867aae857fde5845599d 100644 (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;
 
+       // 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);
+       }
+
        lyxerr << bformat(_("LyX: Creating directory %1$s"
-                                 " and running configure..."), user_lyxdir()) << endl;
+                           " and running configure..."), package().user_support()) << endl;
 
-       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;
+       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;
 }
 
index 7188aa577471bc271e3668e83b6801bc0b2c9aa0..9753450d6fa30216901ac304acc287e468f535ec 100644 (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) + ')';
index f3ddd12eab872e520e14d4550e071020804fa714..d523af76262f059b4da67a05c4cb241d8e0dc51d 100644 (file)
 
 #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
index 59d37379e563c31c458e9e6f019ced341d1afbae..d54b7ba2f938125f40f0ffd51eec7d8e823981d4 100644 (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.
index ad8291ee347c36d5c74d0948437ff7d0e7f189ff..de6adecb9c6387474a856a33739525f7eb056729 100644 (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
index 2f220470e22950bedcf4a367e68820e56f256312..5a354a6096141c770ca6f9150ba1f777acd24d06 100644 (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))
index 6b4c4b1edfaa136151dfe7edf621f46f87d78a0b..29069f88b89285fac3299e19d6cf69d23afc5c47 100644 (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);
index bb4a0231391a7b11a0709704ab1de049a2405448..2aae334d340846e19ce60e39e0e516ff29fb81d8 100644 (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
index ac4b33e98f9d59e3d723d0490ddd957bcaf91b24..9a42ebeecb5fac64b080d5f93ee84ff60505243c 100644 (file)
 #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
index 53594714e35622b369963910b150cf1b78d6f448..b5d67f34e3f220b7f344ecac71a8f2881ed554f4 100644 (file)
 #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_;
 }
 
index b7c48ae1a46679605c95d3fd410959047452536d..386246949ef1ebc162a13e79669da97bc98cb238 100644 (file)
@@ -13,8 +13,6 @@
 #include <config.h>
 
 #include "support/os.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
 
 #include "debug.h"
 
 # 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_;
 }
 
diff --git a/src/support/package.C.in b/src/support/package.C.in
new file mode 100644 (file)
index 0000000..9ad6bfe
--- /dev/null
@@ -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
diff --git a/src/support/package.h b/src/support/package.h
new file mode 100644 (file)
index 0000000..cfe1828
--- /dev/null
@@ -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
diff --git a/src/support/path_defines.C.in b/src/support/path_defines.C.in
deleted file mode 100644 (file)
index dfe7062..0000000
+++ /dev/null
@@ -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
diff --git a/src/support/path_defines.h b/src/support/path_defines.h
deleted file mode 100644 (file)
index 97dfc3a..0000000
+++ /dev/null
@@ -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
index 18826367c2a70d5cfa532bfe93c9a86441eed249..9e78525b82f43961bac7f848273412d92e45ae3d 100644 (file)
 #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";
index 45dbfea54f6b23a986c7ee09e5a3d1684bbfe981..8437f28f4f45126e8de7c4aed30e84f4450dc030 100644 (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
index 62c99b4922f3f737b040a1383d66f8121bf396ce..0c26d02d03f3d69b83f15e6e95114aca0a680c5a 100644 (file)
 
 #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()) {