mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
The setEnvPath stuff.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9473 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
88311570e4
commit
211c2f3136
@ -1,3 +1,13 @@
|
||||
2005-01-12 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* lyx_main.C (init): set the PATH variable to include the
|
||||
directory containing the LyX binary when running on Mac or Windows.
|
||||
|
||||
2005-01-12 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* lyx_main.C (init): remove cruft that purports to set the locale
|
||||
dir. It doesn't and is not needed anyway.
|
||||
|
||||
2005-01-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* Makefile.am: remove the lyx_main.C special casing.
|
||||
|
@ -343,32 +343,25 @@ void LyX::init(bool gui)
|
||||
signal(SIGTERM, error_handler);
|
||||
// SIGPIPE can be safely ignored.
|
||||
|
||||
#if !defined (USE_POSIX_PACKAGING)
|
||||
// Add the directory containing the LyX executable to the path
|
||||
// so that LyX can find things like reLyX.
|
||||
if (package.build_support().empty()) {
|
||||
vector<string> path = getEnvPath("PATH");
|
||||
path.insert(path.begin(), package.binary_dir());
|
||||
setEnvPath("PATH", path);
|
||||
}
|
||||
#endif
|
||||
#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. "
|
||||
// This hard-coded nastiness should be moved into a LyXRC variable.
|
||||
vector<string> path = getEnvPath("PATH");
|
||||
path.insert(path.begin(), "/usr/local/teTeX/bin/powerpc-apple-darwin-current");
|
||||
path.insert(path.begin(), "/usr/local/bin");
|
||||
path.insert(path.begin(), "/sw/bin");
|
||||
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) {
|
||||
|
@ -1,15 +1,22 @@
|
||||
2005-01-12 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* filetools.[Ch] (setEnvPath): new function to create a PATH-style
|
||||
string from a vector of paths and to use it to set an environment
|
||||
variable.
|
||||
(putEnv): resurrect this from the grave.
|
||||
|
||||
* os.h, os_os2.C, os_unix.C, os_win32.C (path_separator): new
|
||||
function returning the character used to separate paths returned
|
||||
by the PATH environment variable.
|
||||
|
||||
* os_win32.C: add #include "lstring.h" back in.
|
||||
|
||||
* package.C.in (package): comment out the ASSERT for now.
|
||||
(check_env_var_dir): write one of the strings to be translated
|
||||
(any one, doesn't matter) on a single line so that the
|
||||
gettext search mechanism in po/Makefile.in.in will register
|
||||
package.C.in as a file containing strings that need translation.
|
||||
|
||||
2005-01-12 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* os_win32.C: add #include "lstring.h" back in.
|
||||
|
||||
2005-01-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* os.h:
|
||||
|
@ -399,13 +399,8 @@ 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);
|
||||
Separator const separator(string(1, os::path_separator()).c_str());
|
||||
Tokenizer const tokens(env_var, separator);
|
||||
Tokenizer::const_iterator it = tokens.begin();
|
||||
Tokenizer::const_iterator const end = tokens.end();
|
||||
@ -418,14 +413,57 @@ vector<string> const getEnvPath(string const & name)
|
||||
}
|
||||
|
||||
|
||||
string const GetEnvPath(string const & name)
|
||||
void setEnvPath(string const & name, vector<string> const & env)
|
||||
{
|
||||
#ifndef __EMX__
|
||||
string const pathlist = subst(GetEnv(name), ':', ';');
|
||||
char const separator(os::path_separator());
|
||||
std::ostringstream ss;
|
||||
vector<string>::const_iterator it = env.begin();
|
||||
vector<string>::const_iterator const end = env.end();
|
||||
for (; it != end; ++it) {
|
||||
if (ss.tellp() > 0)
|
||||
ss << separator;
|
||||
ss << os::external_path(*it);
|
||||
}
|
||||
putEnv(name + "=" + ss.str());
|
||||
}
|
||||
|
||||
|
||||
bool putEnv(string const & envstr)
|
||||
{
|
||||
// CHECK Look at and fix this.
|
||||
// f.ex. what about error checking?
|
||||
|
||||
#if defined (HAVE_SETENV)
|
||||
string name;
|
||||
string const value = split(envstr, name, '=');
|
||||
int const retval = ::setenv(name.c_str(), value.c_str(), true);
|
||||
#elif defined (HAVE_PUTENV)
|
||||
// this leaks, but what can we do about it?
|
||||
// Is doing a getenv() and a free() of the older value
|
||||
// a good idea? (JMarc)
|
||||
// Actually we don't have to leak...calling putenv like this
|
||||
// should be enough: ... and this is obviously not enough if putenv
|
||||
// does not make a copy of the string. It is also not very wise to
|
||||
// put a string on the free store. If we have to leak we should do it
|
||||
// like this:
|
||||
char * leaker = new char[envstr.length() + 1];
|
||||
envstr.copy(leaker, envstr.length());
|
||||
leaker[envstr.length()] = '\0';
|
||||
int const retval = ::putenv(leaker);
|
||||
|
||||
// If putenv does not make a copy of the char const * this
|
||||
// is very dangerous. OTOH if it does take a copy this is the
|
||||
// best solution.
|
||||
// The only implementation of putenv that I have seen does not
|
||||
// allocate memory. _And_ after testing the putenv in glibc it
|
||||
// seems that we need to make a copy of the string contents.
|
||||
// I will enable the above.
|
||||
//int retval = lyx::putenv(envstr.c_str());
|
||||
#else
|
||||
string const pathlist = os::internal_path(GetEnv(name));
|
||||
// No environment setting function. Can this happen?
|
||||
int const retval = 1; //return an error condition.
|
||||
#endif
|
||||
return rtrim(pathlist, ";");
|
||||
return retval == 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -123,6 +123,15 @@ std::string const GetEnv(std::string const & envname);
|
||||
*/
|
||||
std::vector<std::string> const getEnvPath(std::string const & name);
|
||||
|
||||
/** Set the contents of the environment variable \c name
|
||||
* using the paths stored in the \c env vector.
|
||||
* Each element is passed through os::external_path.
|
||||
*/
|
||||
void setEnvPath(std::string const & name, std::vector<std::string> const & env);
|
||||
|
||||
/// Set an environment variable using a string of the form "name=FOO".
|
||||
bool putEnv(std::string const & envstr);
|
||||
|
||||
/// Substitutes active latex characters with underscores in filename
|
||||
std::string const MakeLatexName(std::string const & file);
|
||||
|
||||
|
@ -21,32 +21,44 @@ namespace lyx {
|
||||
namespace support {
|
||||
namespace os {
|
||||
|
||||
//
|
||||
enum shell_type {
|
||||
UNIX, // Do we have to distinguish sh and csh?
|
||||
CMD_EXE
|
||||
};
|
||||
|
||||
// do some work just once
|
||||
/// Do some work just once.
|
||||
void init(int argc, char * argv[]);
|
||||
|
||||
// Returns the name of the NULL device (/dev/null, null).
|
||||
/// Returns the name of the NULL device (/dev/null, null).
|
||||
std::string const & nulldev();
|
||||
//
|
||||
|
||||
/// Returns "/" on *nix, "C:/", etc on Windows.
|
||||
std::string current_root();
|
||||
//
|
||||
|
||||
///
|
||||
shell_type shell();
|
||||
// DBCS aware!
|
||||
|
||||
/// Extract the path common to both @c p1 and @c p2. DBCS aware!
|
||||
std::string::size_type common_path(std::string const & p1, std::string const & p2);
|
||||
// Converts a unix style path to host OS style.
|
||||
|
||||
/// Converts a unix style path to host OS style.
|
||||
std::string external_path(std::string const & p);
|
||||
// Converts a host OS style path to unix style.
|
||||
|
||||
/// Converts a host OS style path to unix style.
|
||||
std::string internal_path(std::string const & p);
|
||||
// is path absolute?
|
||||
|
||||
/// Is the path absolute?
|
||||
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();
|
||||
|
||||
/** Returns a string suitable to be passed to popen when
|
||||
* reading a file.
|
||||
*/
|
||||
char const * popen_read_mode();
|
||||
|
||||
/** The character used to separate paths returned by the
|
||||
* PATH environment variable.
|
||||
*/
|
||||
char path_separator();
|
||||
|
||||
} // namespace os
|
||||
} // namespace support
|
||||
|
@ -202,6 +202,12 @@ shell_type shell()
|
||||
return shell_;
|
||||
}
|
||||
|
||||
|
||||
char path_separator()
|
||||
{
|
||||
return ';';
|
||||
}
|
||||
|
||||
} // namespace os
|
||||
} // namespace support
|
||||
} // namespace lyx
|
||||
|
@ -87,6 +87,11 @@ shell_type shell()
|
||||
return UNIX;
|
||||
}
|
||||
|
||||
char path_separator()
|
||||
{
|
||||
return ':';
|
||||
}
|
||||
|
||||
} // namespace os
|
||||
} // namespace support
|
||||
} // namespace lyx
|
||||
|
@ -163,6 +163,15 @@ shell_type shell()
|
||||
#endif
|
||||
}
|
||||
|
||||
char path_separator()
|
||||
{
|
||||
#if defined (_WIN32)
|
||||
return ';';
|
||||
#else // Cygwin
|
||||
return ':';
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace os
|
||||
} // namespace support
|
||||
} // namespace lyx
|
||||
|
Loading…
Reference in New Issue
Block a user