aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-26 14:17:34 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-26 14:17:34 +0000
commit60ffbda8a002c7221ab7c20ce60380d34435dad6 (patch)
treefd26fd15be441b565d24aad9535f91e10127aa80
parentf4ae26ad23992b74c86d6c6a5054d1e0a8d4ae6b (diff)
downloadpaludis-60ffbda8a002c7221ab7c20ce60380d34435dad6.tar.gz
paludis-60ffbda8a002c7221ab7c20ce60380d34435dad6.tar.xz
Use the fancy licence displayer for --query as well as --install
-rw-r--r--src/Makefile.am1
-rw-r--r--src/install.cc66
-rw-r--r--src/licence.cc66
-rw-r--r--src/licence.hh64
-rw-r--r--src/query.cc10
5 files changed, 141 insertions, 66 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 9f2fdad..164d2d4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,6 +16,7 @@ paludis_SOURCES = \
list.hh list.cc \
query.hh query.cc \
sync.hh sync.cc \
+ licence.hh licence.cc \
paludis.cc
paludis_LDADD = \
diff --git a/src/install.cc b/src/install.cc
index 7577f65..29d98e8 100644
--- a/src/install.cc
+++ b/src/install.cc
@@ -19,6 +19,7 @@
#include "src/colour.hh"
#include "src/install.hh"
+#include "src/licence.hh"
#include <iostream>
#include <paludis/paludis.hh>
#include <paludis/util/iterator.hh>
@@ -35,69 +36,6 @@ using std::endl;
namespace
{
- /**
- * Display licences.
- */
- struct LicenceDisplayer :
- p::DepAtomVisitorTypes::ConstVisitor
- {
- /// Our environment.
- const p::Environment * const env;
-
- /// Our db entry.
- const p::PackageDatabaseEntry * const db_entry;
-
- /// Constructor.
- LicenceDisplayer(const p::Environment * const e, const p::PackageDatabaseEntry * const d) :
- env(e),
- db_entry(d)
- {
- }
-
- ///\name Visit methods
- ///{
- void visit(const p::AllDepAtom * atom)
- {
- cerr << "( ";
- std::for_each(atom->begin(), atom->end(), p::accept_visitor(this));
- cerr << ") ";
- }
-
- void visit(const p::AnyDepAtom * atom)
- {
- cerr << "|| ( ";
- std::for_each(atom->begin(), atom->end(), p::accept_visitor(this));
- cerr << ") ";
- }
-
- void visit(const p::UseDepAtom * atom)
- {
- cerr << atom->flag() << "? ( ";
- std::for_each(atom->begin(), atom->end(), p::accept_visitor(this));
- cerr << ") ";
- }
-
- void visit(const p::PlainTextDepAtom * atom)
- {
- if (env->accept_license(atom->text(), db_entry))
- cerr << colour(cl_green, atom->text());
- else
- cerr << colour(cl_red, atom->text());
- cerr << " ";
- }
-
- void visit(const p::PackageDepAtom *) PALUDIS_ATTRIBUTE((noreturn))
- {
- throw p::InternalError(PALUDIS_HERE, "todo: encountered PackageDepAtom in licence?"); /// \bug todo
- }
-
- void visit(const p::BlockDepAtom *) PALUDIS_ATTRIBUTE((noreturn))
- {
- throw p::InternalError(PALUDIS_HERE, "todo: encountered BlockDepAtom in licence?"); /// \bug todo
- }
- ///}
- };
-
struct TagDisplayer :
p::DepTagVisitorTypes::ConstVisitor
{
@@ -503,7 +441,7 @@ do_install()
pp->get<p::pde_name>(), pp->get<p::pde_version>())->get(
p::vmk_license));
- LicenceDisplayer ld(env, &*pp);
+ LicenceDisplayer ld(cerr, env, &*pp);
p::DepParser::parse(license_str, p::DepParserPolicy<p::PlainTextDepAtom,
true>::get_instance())->accept(&ld);
}
diff --git a/src/licence.cc b/src/licence.cc
new file mode 100644
index 0000000..bb1ebfd
--- /dev/null
+++ b/src/licence.cc
@@ -0,0 +1,66 @@
+/* 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 "licence.hh"
+#include "colour.hh"
+#include <ostream>
+
+void
+LicenceDisplayer::visit(const paludis::AllDepAtom * atom)
+{
+ stream << "( ";
+ std::for_each(atom->begin(), atom->end(), paludis::accept_visitor(this));
+ stream << ") ";
+}
+
+void
+LicenceDisplayer::visit(const paludis::AnyDepAtom * atom)
+{
+ stream << "|| ( ";
+ std::for_each(atom->begin(), atom->end(), paludis::accept_visitor(this));
+ stream << ") ";
+}
+
+void
+LicenceDisplayer::visit(const paludis::UseDepAtom * atom)
+{
+ stream << atom->flag() << "? ( ";
+ std::for_each(atom->begin(), atom->end(), paludis::accept_visitor(this));
+ stream << ") ";
+}
+
+void
+LicenceDisplayer::visit(const paludis::PlainTextDepAtom * atom)
+{
+ if (env->accept_license(atom->text(), db_entry))
+ stream << colour(cl_green, atom->text());
+ else
+ stream << colour(cl_red, "(" + atom->text() + ")!");
+ stream << " ";
+}
+
+LicenceDisplayer::LicenceDisplayer(
+ std::ostream & s,
+ const paludis::Environment * const e,
+ const paludis::PackageDatabaseEntry * const d) :
+ stream(s),
+ env(e),
+ db_entry(d)
+{
+}
diff --git a/src/licence.hh b/src/licence.hh
new file mode 100644
index 0000000..366aa57
--- /dev/null
+++ b/src/licence.hh
@@ -0,0 +1,64 @@
+/* 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_LICENCE_HH
+#define PALUDIS_GUARD_SRC_LICENCE_HH 1
+
+#include <paludis/paludis.hh>
+#include <iosfwd>
+
+struct LicenceDisplayer :
+ paludis::DepAtomVisitorTypes::ConstVisitor
+{
+ /// Our stream.
+ std::ostream & stream;
+
+ /// Our environment.
+ const paludis::Environment * const env;
+
+ /// Our db entry.
+ const paludis::PackageDatabaseEntry * const db_entry;
+
+ /// Constructor.
+ LicenceDisplayer(
+ std::ostream & stream,
+ const paludis::Environment * const e,
+ const paludis::PackageDatabaseEntry * const d);
+
+ ///\name Visit methods
+ ///{
+ void visit(const paludis::AllDepAtom * atom);
+
+ void visit(const paludis::AnyDepAtom * atom);
+
+ void visit(const paludis::UseDepAtom * atom);
+
+ void visit(const paludis::PlainTextDepAtom * atom);
+
+ void visit(const paludis::PackageDepAtom *)
+ {
+ }
+
+ void visit(const paludis::BlockDepAtom *)
+ {
+ }
+ ///}
+};
+
+#endif
diff --git a/src/query.cc b/src/query.cc
index a80b22d..979aa0e 100644
--- a/src/query.cc
+++ b/src/query.cc
@@ -19,6 +19,7 @@
#include "src/colour.hh"
#include "src/query.hh"
+#include "src/licence.hh"
#include <functional>
#include <iomanip>
#include <iostream>
@@ -170,8 +171,13 @@ void do_one_query(
" " << metadata->get(p::vmk_description) << endl;
if (! metadata->get(p::vmk_license).empty())
- cout << " " << std::setw(22) << std::left << "License:" << std::setw(0) <<
- " " << metadata->get(p::vmk_license) << endl;
+ {
+ cout << " " << std::setw(22) << std::left << "License:" << std::setw(0) << " ";
+ LicenceDisplayer d(cout, env, &display_entry);
+ p::DepParser::parse(metadata->get(p::vmk_license),
+ p::DepParserPolicy<p::PlainTextDepAtom, true>::get_instance())->accept(&d);
+ cout << endl;
+ }
if (CommandLine::get_instance()->a_show_deps.specified())
{