This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goclient. commit 864a0938551d993397adc1d0f27c4a8ca421a771 Author: Mihai Moldovan <ionic@ionic.de> Date: Sat Apr 9 08:36:40 2016 +0200 src/x2goutils.{cpp,h}: add new function add_to_path () to add multiple entries to a PATH-like string if they do not exist in there yet. --- debian/changelog | 2 ++ src/x2goutils.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/x2goutils.h | 12 ++++++++ 3 files changed, 102 insertions(+) diff --git a/debian/changelog b/debian/changelog index c058a99..6b16560 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,8 @@ x2goclient (4.0.5.2-0x2go1) UNRELEASED; urgency=medium /opt/X11/bin to x2goclient's environment and child environments before starting xmodmap. Fixes: #1019. Requires a re-release of X2Go Client for OS X. + - src/x2goutils.{cpp,h}: add new function add_to_path () to add multiple + entries to a PATH-like string if they do not exist in there yet. [ Mike DePaulo ] * New upstream release (4.0.5.2): diff --git a/src/x2goutils.cpp b/src/x2goutils.cpp index 4a45102..31ac3ac 100644 --- a/src/x2goutils.cpp +++ b/src/x2goutils.cpp @@ -194,4 +194,92 @@ void show_XQuartz_generic_error (const QString &main_error, const QString &addit "or\n" "<center><b>/Applications/Utilities/XQuartz.app</b></center>")); } + +QString add_to_path (const QString &orig_path, const QStringList &add, const bool back) { + QString ret = orig_path; + std::vector<bool> found; + + QStringList orig_path_list = orig_path.split (":"); + + /* + * Clean up add list. We want to make sure no entry ends in a slash + * and skip empty entries. + */ + QStringList tmp_clean_add; + for (int i = 0; i < add.size (); ++i) { + if (!(add[i].isEmpty ())) { + if (add[i].right (1) == "/") { + QString tmp_elem = add[i].right (1); + + if (!(tmp_elem.isEmpty ())) { + tmp_clean_add.append (tmp_elem); + } + } + else { + tmp_clean_add.append (add[i]); + } + } + } + + /* Nothing to add, really... */ + if (tmp_clean_add.isEmpty ()) { + return (ret); + } + + /* Create unique array. */ + QStringList clean_add; + { + QStringList::const_iterator begin = tmp_clean_add.constBegin (), + end = tmp_clean_add.constEnd (); + for (QStringList::const_iterator cit = begin; cit != end; ++cit) { + bool tmp_found = false; + + for (QStringList::const_iterator cit2 = cit + 1; cit2 != end; ++cit2) { + if (*cit == *cit) { + tmp_found = true; + break; + } + } + + if (!tmp_found) { + clean_add.append (*cit); + } + } + } + + /* Nothing to add. */ + if (clean_add.isEmpty ()) { + return (ret); + } + + found.resize (clean_add.size (), false); + + for (int i = 0; i < orig_path_list.length (); ++i) { + for (int y = 0; y < clean_add.size (); ++y) { + if (!found[y]) { + if ((orig_path_list[i] == QString (clean_add[y])) || (orig_path_list[i] == QString (clean_add[y] + '/'))) { + found[y] = true; + break; + } + } + } + } + + if (back) { + for (int i = 0; i < clean_add.size (); ++i) { + if (!found[i]) { + ret.append (QString (":" + clean_add[i])); + } + } + } + else { + for (int i = (clean_add.size () - 1); i > 0; --i) { + if (!found[i]) { + ret.prepend (QString (clean_add[i] + ":")); + } + } + } + + return (ret); +} #endif /* defined (Q_OS_DARWIN) */ diff --git a/src/x2goutils.h b/src/x2goutils.h index af65663..e36203e 100644 --- a/src/x2goutils.h +++ b/src/x2goutils.h @@ -45,6 +45,18 @@ bool font_is_monospaced (const QFont &font); void show_XQuartz_not_found_error (); void show_XQuartz_start_error (); void show_XQuartz_generic_error (const QString &main_error, const QString &additional_info); + +/* + * Add a list of strings to a PATH value. + * + * If back is true (the default), each entry is (potentially) appended to the original + * PATH value, if not already existing within the original PATH value. + * Ex.: <orig_path>:<add_entry1>:<add_entry2>:... + * + * Otherwise, each entry is prepended to the original PATH value, if not already existing. + * Ex.: <add_entry1>:<add_entry2>:...:<orig_path> + */ +QString add_to_path (const QString &orig_path, const QStringList &add, const bool back = true); #endif /* defined (Q_OS_DARWIN) */ #endif /* !defined (X2GOUTILS_H) */ -- Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git