aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-18 20:49:43 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-18 20:49:43 +0000
commita516fa71043aca793cc6c64cca0e98f0c60daee8 (patch)
treecb6be67cf75486dba8e748ef4347b5cc9a648b5e
parentbeb90ceb6828994c1a7145f956ed553f1fbf29e3 (diff)
downloadpaludis-a516fa71043aca793cc6c64cca0e98f0c60daee8.tar.gz
paludis-a516fa71043aca793cc6c64cca0e98f0c60daee8.tar.xz
Display USE flags for --query.
-rw-r--r--src/paludis/Makefile.am1
-rw-r--r--src/paludis/install.cc70
-rw-r--r--src/paludis/query.cc16
-rw-r--r--src/paludis/use.cc104
-rw-r--r--src/paludis/use.hh35
5 files changed, 154 insertions, 72 deletions
diff --git a/src/paludis/Makefile.am b/src/paludis/Makefile.am
index e3ce259..eea67bb 100644
--- a/src/paludis/Makefile.am
+++ b/src/paludis/Makefile.am
@@ -35,6 +35,7 @@ paludis_SOURCES = \
query.hh query.cc \
sync.hh sync.cc \
licence.hh licence.cc \
+ use.hh use.cc \
contents.hh contents.cc \
owner.hh owner.cc \
news.hh news.cc \
diff --git a/src/paludis/install.cc b/src/paludis/install.cc
index 8bd812f..cec9860 100644
--- a/src/paludis/install.cc
+++ b/src/paludis/install.cc
@@ -20,6 +20,7 @@
#include "colour.hh"
#include "install.hh"
#include "licence.hh"
+#include "use.hh"
#include <iostream>
#include <set>
@@ -485,74 +486,7 @@ namespace
d.version, d.repository));
/* display USE flags */
- if (d.metadata->get_ebuild_interface())
- {
- const RepositoryUseInterface * const use_interface(
- DefaultEnvironment::get_instance()->package_database()->
- fetch_repository(d.repository)->use_interface);
- std::set<UseFlagName> iuse;
- WhitespaceTokeniser::get_instance()->tokenise(
- d.metadata->get_ebuild_interface()->iuse,
- create_inserter<UseFlagName>(std::inserter(iuse, iuse.end())));
-
-
- /* display normal use flags first */
- for (std::set<UseFlagName>::const_iterator i(iuse.begin()), i_end(iuse.end()) ;
- i != i_end ; ++i)
- {
- if (use_interface->is_expand_flag(*i))
- continue;
-
- if (DefaultEnvironment::get_instance()->query_use(*i, &p))
- {
- if (use_interface && use_interface->query_use_force(*i, &p))
- cout << " " << colour(cl_flag_on, "(" + stringify(*i) + ")");
- else
- cout << " " << colour(cl_flag_on, *i);
- }
- else
- {
- if (use_interface && use_interface->query_use_mask(*i, &p))
- cout << " " << colour(cl_flag_off, "(-" + stringify(*i) + ")");
- else
- cout << " " << colour(cl_flag_off, "-" + stringify(*i));
- }
- }
-
- /* now display expand flags */
- UseFlagName old_expand_name("OFTEN_NOT_BEEN_ON_BOATS");
- for (std::set<UseFlagName>::const_iterator i(iuse.begin()), i_end(iuse.end()) ;
- i != i_end ; ++i)
- {
- if ((! use_interface->is_expand_flag(*i)) ||
- (use_interface->is_expand_hidden_flag(*i)))
- continue;
-
- UseFlagName expand_name(use_interface->expand_flag_name(*i)),
- expand_value(use_interface->expand_flag_value(*i));
-
- if (expand_name != old_expand_name)
- {
- cout << " " << expand_name << ":";
- old_expand_name = expand_name;
- }
-
- if (DefaultEnvironment::get_instance()->query_use(*i, &p))
- {
- if (use_interface && use_interface->query_use_force(*i, &p))
- cout << " " << colour(cl_flag_on, "(" + stringify(expand_value) + ")");
- else
- cout << " " << colour(cl_flag_on, expand_value);
- }
- else
- {
- if (use_interface && use_interface->query_use_mask(*i, &p))
- cout << " " << colour(cl_flag_off, "(-" + stringify(expand_value) + ")");
- else
- cout << " " << colour(cl_flag_off, "-" + stringify(expand_value));
- }
- }
- }
+ std::cout << make_pretty_use_flags_string(DefaultEnvironment::get_instance(), p, d.metadata);
/* display tag, add tag to our post display list */
if (! d.tag->empty())
diff --git a/src/paludis/query.cc b/src/paludis/query.cc
index 3f62b7a..a4299bd 100644
--- a/src/paludis/query.cc
+++ b/src/paludis/query.cc
@@ -20,6 +20,7 @@
#include "colour.hh"
#include "query.hh"
#include "licence.hh"
+#include "use.hh"
#include <functional>
#include <iomanip>
#include <iostream>
@@ -277,10 +278,17 @@ void do_one_query(
}
}
- if (metadata->get_ebuild_interface() && ! metadata->get_ebuild_interface()->
- provide_string.empty())
- cout << " " << std::setw(22) << std::left << "Provides:" << std::setw(0) <<
- " " << metadata->get_ebuild_interface()->provide_string << endl;
+ if (metadata->get_ebuild_interface())
+ {
+ if (! metadata->get_ebuild_interface()->provide_string.empty())
+ cout << " " << std::setw(22) << std::left << "Provides:" << std::setw(0) <<
+ " " << metadata->get_ebuild_interface()->provide_string << endl;
+
+ if (! metadata->get_ebuild_interface()->iuse.empty())
+ cout << " " << std::setw(22) << std::left << "Use flags:" << std::setw(0) <<
+ " " << make_pretty_use_flags_string(p::DefaultEnvironment::get_instance(),
+ display_entry, metadata) << endl;
+ }
if (metadata->get_virtual_interface())
cout << " " << std::setw(22) << std::left << "Virtual for:" << std::setw(0) <<
diff --git a/src/paludis/use.cc b/src/paludis/use.cc
new file mode 100644
index 0000000..b1c4863
--- /dev/null
+++ b/src/paludis/use.cc
@@ -0,0 +1,104 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "use.hh"
+#include "colour.hh"
+#include <paludis/util/tokeniser.hh>
+#include <sstream>
+#include <set>
+
+using namespace paludis;
+
+std::string
+make_pretty_use_flags_string(const Environment * const env, const PackageDatabaseEntry & p,
+ VersionMetadata::ConstPointer metadata)
+{
+ std::ostringstream c;
+
+ if (metadata->get_ebuild_interface())
+ {
+ const RepositoryUseInterface * const use_interface(
+ env->package_database()->
+ fetch_repository(p.repository)->use_interface);
+ std::set<UseFlagName> iuse;
+ WhitespaceTokeniser::get_instance()->tokenise(
+ metadata->get_ebuild_interface()->iuse,
+ create_inserter<UseFlagName>(std::inserter(iuse, iuse.end())));
+
+ /* display normal use flags first */
+ for (std::set<UseFlagName>::const_iterator i(iuse.begin()), i_end(iuse.end()) ;
+ i != i_end ; ++i)
+ {
+ if (use_interface->is_expand_flag(*i))
+ continue;
+
+ if (env->query_use(*i, &p))
+ {
+ if (use_interface && use_interface->query_use_force(*i, &p))
+ c << " " << colour(cl_flag_on, "(" + stringify(*i) + ")");
+ else
+ c << " " << colour(cl_flag_on, *i);
+ }
+ else
+ {
+ if (use_interface && use_interface->query_use_mask(*i, &p))
+ c << " " << colour(cl_flag_off, "(-" + stringify(*i) + ")");
+ else
+ c << " " << colour(cl_flag_off, "-" + stringify(*i));
+ }
+ }
+
+ /* now display expand flags */
+ UseFlagName old_expand_name("OFTEN_NOT_BEEN_ON_BOATS");
+ for (std::set<UseFlagName>::const_iterator i(iuse.begin()), i_end(iuse.end()) ;
+ i != i_end ; ++i)
+ {
+ if ((! use_interface->is_expand_flag(*i)) ||
+ (use_interface->is_expand_hidden_flag(*i)))
+ continue;
+
+ UseFlagName expand_name(use_interface->expand_flag_name(*i)),
+ expand_value(use_interface->expand_flag_value(*i));
+
+ if (expand_name != old_expand_name)
+ {
+ c << " " << expand_name << ":";
+ old_expand_name = expand_name;
+ }
+
+ if (env->query_use(*i, &p))
+ {
+ if (use_interface && use_interface->query_use_force(*i, &p))
+ c << " " << colour(cl_flag_on, "(" + stringify(expand_value) + ")");
+ else
+ c << " " << colour(cl_flag_on, expand_value);
+ }
+ else
+ {
+ if (use_interface && use_interface->query_use_mask(*i, &p))
+ c << " " << colour(cl_flag_off, "(-" + stringify(expand_value) + ")");
+ else
+ c << " " << colour(cl_flag_off, "-" + stringify(expand_value));
+ }
+ }
+ }
+
+ return c.str();
+}
+
diff --git a/src/paludis/use.hh b/src/paludis/use.hh
new file mode 100644
index 0000000..295bcc3
--- /dev/null
+++ b/src/paludis/use.hh
@@ -0,0 +1,35 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_SRC_PALUDIS_USE_HH
+#define PALUDIS_GUARD_SRC_PALUDIS_USE_HH 1
+
+#include <paludis/name.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database_entry.hh>
+#include <paludis/version_metadata.hh>
+
+/**
+ * Make a nice string for outputting USE flags.
+ */
+std::string
+make_pretty_use_flags_string(const paludis::Environment * const env, const paludis::PackageDatabaseEntry & p,
+ paludis::VersionMetadata::ConstPointer metadata) PALUDIS_ATTRIBUTE((nonnull(1)));
+
+#endif