X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FLyX.cpp;h=706950fe9fa317b09a0d8fbbe503e6c92ff84a0f;hb=449c766e03d94ddf6c823cfcae845f76f83c0e1c;hp=b7848311b85a6a10450572285cab072a7bcf0f94;hpb=f8da042312cf9a563f46e4a767fc3c4ae6ecb764;p=lyx.git diff --git a/src/LyX.cpp b/src/LyX.cpp index b7848311b8..706950fe9f 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -77,6 +77,10 @@ using namespace std; using namespace lyx::support; +#if defined (USE_MACOSX_PACKAGING) +#include +#endif + namespace lyx { namespace Alert = frontend::Alert; @@ -357,7 +361,7 @@ int LyX::exec(int & argc, char * argv[]) // FIXME /* Create a CoreApplication class that will provide the main event loop - * and the socket callback registering. With Qt4, only QtCore + * and the socket callback registering. With Qt, only QtCore * library would be needed. * When this is done, a server_mode could be created and the following two * line would be moved out from here. @@ -667,7 +671,7 @@ static void error_handler(int err_sig) if (!msg.empty()) { lyxerr << "\nlyx: " << msg << endl; // try to make a GUI message - Alert::error(_("LyX crashed!"), msg); + Alert::error(_("LyX crashed!"), msg, true); } // Deinstall the signal handlers @@ -706,6 +710,55 @@ void LyX::printError(ErrorItem const & ei) cerr << to_utf8(tmp) << endl; } +#if defined (USE_MACOSX_PACKAGING) +namespace { + // Unexposed--extract an environment variable name from its NAME=VALUE + // representation + std::string varname(const char* line) + { + size_t nameLen = strcspn(line, "="); + if (nameLen == strlen(line)) { + return std::string(); + } else { + return std::string(line, nameLen); + } + } +} + +void cleanDuplicateEnvVars() +{ + std::set seen; + std::set dupes; + + // Create a list of the environment variables that appear more than once + for (char **read = *_NSGetEnviron(); *read; read++) { + std::string name = varname(*read); + if (name.size() == 0) { + continue; + } + if (seen.find(name) != seen.end()) { + dupes.insert(name); + } else { + seen.insert(name); + } + } + + // Loop over the list of duplicated variables + for (std::set::iterator dupe = dupes.begin(); dupe != dupes.end(); dupe++) { + const char *name = (*dupe).c_str(); + char *val = getenv(name); + if (val != NULL) { + LYXERR(Debug::INIT, "Duplicate environment variable: " << name); + // unsetenv removes *all* instances of the variable from the environment + unsetenv(name); + + // replace with the value from getenv (in practice appears to be the + // first value in the list) + setenv(name, val, 0); + } + } +} +#endif bool LyX::init() { @@ -718,6 +771,10 @@ bool LyX::init() signal(SIGTERM, error_handler); // SIGPIPE can be safely ignored. +#if defined (USE_MACOSX_PACKAGING) + cleanDuplicateEnvVars(); +#endif + lyxrc.tempdir_path = package().temp_dir().absFileName(); lyxrc.document_path = package().document_dir().absFileName(); @@ -1089,9 +1146,11 @@ int parse_version(string const &, string const &, string &) { cout << "LyX " << lyx_version << " (" << lyx_release_date << ")" << endl; + if (string(lyx_git_commit_hash) != "none") + cout << to_utf8(_(" Git commit hash ")) + << string(lyx_git_commit_hash).substr(0,8) << endl; cout << to_utf8(bformat(_("Built on %1$s[[date]], %2$s[[time]]"), - from_ascii(__DATE__), from_ascii(__TIME__))) << endl; - + from_ascii(lyx_build_date), from_ascii(lyx_build_time))) << endl; cout << lyx_version_info << endl; exit(0); return 0;