All day for not very much...

Well, Ok, tex2lyx now has reasonable values for the build_lyxdir,
system_lyxdir, user_lyxdir variables.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7394 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-07-27 19:26:36 +00:00
parent c625f0a370
commit 8700a256d3
9 changed files with 328 additions and 200 deletions

View File

@ -1,11 +1,17 @@
2003-07-27 Angus Leeming <leeming@lyx.org>
* Makefile.am: remove special casing for configure-time setting of
LYX_DIR, TOP_SRCDIR and LOCALEDIR.
* lyx_main.C (init): remove all Jean-Marc's magic setting of
system_lyxdir, build_lyxdir and user_lyxdir into the support lib.
2003-07-26 André Pönitz <poenitz@gmx.net>
* lyxtext.h:
* lyxtext.h:
* text.C:
* text2.C: get rid of LyXText::need_break_row
2003-07-27 Lars Gullik Bjønnes <larsbj@gullik.net>
* toc.[Ch]: put namespace toc inside namespace lyx

View File

@ -39,8 +39,6 @@ lyx_DEPENDENCIES = $(LYX_CONV_LIBS) $(BOOST_LIBS) $(INTLLIBS)
INCLUDES = $(BOOST_INCLUDES)
localedir = $(datadir)/locale
BUILT_SOURCES = version.C
lyx_SOURCES = \
@ -251,15 +249,5 @@ lyx_SOURCES = \
vspace.C \
vspace.h
lyx_main.o: lyx_main.C lyx_main.h config.h version.h \
lyxrc.h support/path.h support/filetools.h \
bufferlist.h debug.h support/FileInfo.h lastfiles.h intl.h \
lyxserver.h layout.h gettext.h kbmap.h lfuns.h language.h
$(CXXCOMPILE) -DLYX_DIR=\"$(pkgdatadir)\" \
-DTOP_SRCDIR=\"$(top_srcdir)\" -c $(top_srcdir)/src/lyx_main.C
messages.o: messages.C messages.h config.h LString.h support/filetools.h
$(CXXCOMPILE) -DLOCALEDIR=\"$(localedir)\" -c $(top_srcdir)/src/messages.C
dist-hook:
cd $(distdir) ; rm -rf `find cheaders -name \*CVS\*`

View File

@ -13,9 +13,9 @@
#include "support/filetools.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/FileInfo.h"
#include "support/path.h"
#include "support/path_defines.h"
#include "debug.h"
#include "gettext.h"
#include "lyxlex.h"
@ -64,9 +64,9 @@ extern void QuitLyX();
extern LyXServer * lyxserver;
string system_lyxdir;
string build_lyxdir;
string user_lyxdir;
extern string system_lyxdir;
extern string build_lyxdir;
extern string user_lyxdir;
DebugStream lyxerr;
@ -237,184 +237,7 @@ void LyX::init(bool gui)
signal(SIGINT, error_handler);
signal(SIGTERM, error_handler);
//
// 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;
//
// 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>/../share/<name of binary>/
// 4a) repeat 4 after following the Symlink if <path of
// binary> is a symbolic link.
// 5) 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
string searchpath;
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 + ';';
}
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/
searchpath += NormalizePath(AddPath(binpath, "../share/") +
OnlyFilename(binname)) + ';';
// 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);
// <path of binary>/TOP_SRCDIR/lib
build_lyxdir = MakeAbsPath("../lib", binpath);
if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
binpath) + ';';
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;
build_lyxdir.erase();
}
// 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;
//
// 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())
user_lyxdir = AddPath(GetEnvPath("HOME"),
string(".") + PACKAGE);
explicit_userdir = false;
}
lyxerr[Debug::INIT] << "User LyX directory: '"
<< user_lyxdir << '\'' << endl;
bool const explicit_userdir = setLyxPaths();
// Check that user LyX directory is ok. We don't do that if
// running in batch mode.

View File

@ -4,3 +4,4 @@ Makefile
*.lo
libsupport.la
.libs
path_defines.C

View File

@ -1,3 +1,16 @@
2003-07-27 Angus Leeming <leeming@lyx.org>
* path_defines.{h,C.in}, : new files. Store/set the various lyx
paths, lyx_dir, top_srcdir, localedir, system_lyxdir, build_lyxdir
user_lyxdir.
* Makefile.am: add some magic to enable the user to set the path to
the system-level lyx support files, the top of the lyx build tree
and the system-level lyx locale directory at _make_ time rather
than configure time.
* .cvsignore: add path_defines.C.
2003-07-26 Angus Leeming <leeming@lyx.org>
* os.h: remove irrelevant discussion of system_tempdir.

View File

@ -1,16 +1,21 @@
include $(top_srcdir)/config/common.am
nodist_include_HEADERS = path_defines.C
noinst_LTLIBRARIES = libsupport.la
CLEANFILES = path_defines.C
INCLUDES = -I$(srcdir)/../ $(BOOST_INCLUDES)
EXTRA_DIST = lyxstring.C lyxstring.h \
EXTRA_DIST = path_defines.C.in lyxstring.C lyxstring.h \
os_unix.C os_win32.C os_os2.C
if USE_LYXSTRING
LYXSTRING = lyxstring.C lyxstring.h
endif
BUILT_SOURCES = path_defines.C
libsupport_la_SOURCES = \
BoostFormat.h \
DebugStream.C \
@ -58,6 +63,7 @@ libsupport_la_SOURCES = \
os2_errortable.h \
path.C \
path.h \
path_defines.C \
putenv.C \
rename.C \
rmdir.C \
@ -75,3 +81,20 @@ libsupport_la_SOURCES = \
userinfo.C \
userinfo.h \
unlink.C
path_defines.C: build_path_defines
build_path_defines: path_defines.C.in
@rm -f tmp_path_defines ;\
ABS_SRCDIR=`cd $(top_srcdir) && pwd` ;\
sed "s,%LYX_DIR%,$(pkgdatadir), ;\
s,%LOCALEDIR%,$(datadir)/locale, ;\
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 ;\
else \
rm -f path_defines.C ;\
mv tmp_path_defines path_defines.C ;\
fi

View File

@ -0,0 +1,244 @@
// -*- 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"
using std::endl;
string build_lyxdir;
string system_lyxdir;
string user_lyxdir;
namespace {
/* The absolute path to the system-level lyx support files.
* (Compile-time value.)
*/
string const & lyx_dir()
{
static string const ld = "%LYX_DIR%";
return ld;
}
/* The absolute path to the top of the lyx build tree.
* (Compile-time value.)
*/
string const & lyx_top_srcdir()
{
static string const lts = "%TOP_SRCDIR%";
return lts;
}
/* The absolute path to the system-level lyx locale directory.
* (Compile-time value.)
*/
string const & lyx_localedir()
{
static string const ll = "%LOCALEDIR%";
return ll;
}
} // namespace anon
namespace lyx {
namespace support {
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;
//
// 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>/../share/<name of binary>/
// 4a) repeat 4 after following the Symlink if <path of
// binary> is a symbolic link.
// 5) 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
string searchpath;
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 + ';';
}
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/
searchpath += NormalizePath(AddPath(binpath, "../share/") +
OnlyFilename(binname)) + ';';
// 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(lyx_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;
//
// 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())
user_lyxdir = AddPath(GetEnvPath("HOME"),
string(".") + PACKAGE);
explicit_userdir = false;
}
lyxerr[Debug::INIT] << "User LyX directory: '"
<< user_lyxdir << '\'' << endl;
return explicit_userdir;
}
} // namespace support
} // namespace lyx

View File

@ -0,0 +1,28 @@
// -*- 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 "LString.h"
namespace lyx {
namespace support {
/** \returns true if the user lyx dir existed already and did not need
* to be created afresh.
*/
bool setLyxPaths();
} // namespace support
} // namespace lyx
#endif // NOT PATH_DEFINES_H

View File

@ -9,6 +9,8 @@
#include "debug.h"
#include "lyx_main.h"
#include "lyxtextclass.h"
#include "support/path_defines.h"
#include "support/os.h"
#include <cctype>
#include <fstream>
@ -31,9 +33,6 @@ using std::string;
using std::vector;
// Hacks to allow the thing to link in the lyxlayout stuff
string system_lyxdir = "../../../lib";
string build_lyxdir = "../../lib";
string user_lyxdir = ".";
Debug::type const Debug::ANY = Debug::type(0);
DebugStream lyxerr;
@ -150,6 +149,9 @@ int main(int argc, char * argv[])
return 2;
}
lyx::support::os::init(&argc, &argv);
lyx::support::setLyxPaths();
ifstream is(argv[1]);
Parser p(is);
//p.dump();