aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-08 22:21:35 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-08 22:21:35 +0100
commit4c18d1cdef297325314de41108fe41385c07867d (patch)
tree46487eb3f98e193425b193be14a6506820a55f3d
parenta0b37c33588030ed96e58365c063958d370491bc (diff)
downloadpaludis-4c18d1cdef297325314de41108fe41385c07867d.tar.gz
paludis-4c18d1cdef297325314de41108fe41385c07867d.tar.xz
escape
-rw-r--r--paludis/args/Makefile.am2
-rw-r--r--paludis/args/args_option.cc11
-rw-r--r--paludis/args/escape.cc45
-rw-r--r--paludis/args/escape.hh34
-rw-r--r--paludis/resolver/sanitised_dependencies.cc76
-rw-r--r--src/clients/cave/cmd_resolve.cc5
6 files changed, 163 insertions, 10 deletions
diff --git a/paludis/args/Makefile.am b/paludis/args/Makefile.am
index 501696a..149d6b0 100644
--- a/paludis/args/Makefile.am
+++ b/paludis/args/Makefile.am
@@ -21,6 +21,7 @@ paludis_args_include_HEADERS = \
bad_argument.hh \
args_visitor.hh \
args_dumper.hh \
+ escape.hh \
man.hh \
deps_option_arg.hh \
log_level_arg.hh \
@@ -39,6 +40,7 @@ libpaludisargs_@PALUDIS_PC_SLOT@_la_SOURCES = \
args_visitor.cc \
args_dumper.cc \
deps_option_arg.cc \
+ escape.cc \
log_level_arg.cc \
dep_list_args_group.cc \
install_args_group.cc
diff --git a/paludis/args/args_option.cc b/paludis/args/args_option.cc
index 979d670..ce3648e 100644
--- a/paludis/args/args_option.cc
+++ b/paludis/args/args_option.cc
@@ -19,6 +19,7 @@
#include "args.hh"
#include "args_error.hh"
+#include "escape.hh"
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/make_named_values.hh>
@@ -135,7 +136,7 @@ const std::string
StringArg::forwardable_string() const
{
if (specified())
- return "--" + long_name() + " " + argument();
+ return "--" + long_name() + " " + escape(argument());
else
return "";
}
@@ -210,7 +211,8 @@ const std::string
StringSetArg::forwardable_string() const
{
if (specified())
- return "--" + long_name() + " " + join(begin_args(), end_args(), " --" + long_name() + " ");
+ return "--" + long_name() + " " + join(begin_args(), end_args(), " --" + long_name() + " ",
+ &escape);
else
return "";
}
@@ -258,7 +260,8 @@ const std::string
StringSequenceArg::forwardable_string() const
{
if (specified())
- return "--" + long_name() + " " + join(begin_args(), end_args(), " --" + long_name() + " ");
+ return "--" + long_name() + " " + join(begin_args(), end_args(), " --" + long_name() + " ",
+ &escape);
else
return "";
}
@@ -430,7 +433,7 @@ const std::string
EnumArg::forwardable_string() const
{
if (specified())
- return "--" + long_name() + " " + argument();
+ return "--" + long_name() + " " + escape(argument());
else
return "";
}
diff --git a/paludis/args/escape.cc b/paludis/args/escape.cc
new file mode 100644
index 0000000..47b41b6
--- /dev/null
+++ b/paludis/args/escape.cc
@@ -0,0 +1,45 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * 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 <paludis/args/escape.hh>
+#include <sstream>
+
+using namespace paludis;
+using namespace paludis::args;
+
+const std::string
+paludis::args::escape(const std::string & s)
+{
+ std::stringstream result;
+ for (std::string::const_iterator c(s.begin()), c_end(s.end()) ;
+ c != c_end ; ++c)
+ {
+ if ((*c >= 'a' && *c <= 'z') ||
+ (*c >= 'A' && *c <= 'Z') ||
+ (*c >= '0' && *c <= '9') ||
+ *c == '-' ||
+ *c == '_')
+ result << *c;
+ else
+ result << '\\' << *c;
+ }
+
+ return result.str();
+}
+
diff --git a/paludis/args/escape.hh b/paludis/args/escape.hh
new file mode 100644
index 0000000..75d3e7b
--- /dev/null
+++ b/paludis/args/escape.hh
@@ -0,0 +1,34 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * 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_PALUDIS_ARGS_ESCAPE_HH
+#define PALUDIS_GUARD_PALUDIS_ARGS_ESCAPE_HH 1
+
+#include <paludis/util/attributes.hh>
+#include <string>
+
+namespace paludis
+{
+ namespace args
+ {
+ const std::string escape(const std::string &) PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
+ }
+}
+
+#endif
diff --git a/paludis/resolver/sanitised_dependencies.cc b/paludis/resolver/sanitised_dependencies.cc
index 04a494b..5f75d92 100644
--- a/paludis/resolver/sanitised_dependencies.cc
+++ b/paludis/resolver/sanitised_dependencies.cc
@@ -46,6 +46,63 @@ namespace
l->push_back(t);
}
+ struct AnyOfAlternativesVisitor
+ {
+ const std::tr1::shared_ptr<Sequence<std::string> > result;
+
+ AnyOfAlternativesVisitor() :
+ result(new Sequence<std::string>)
+ {
+ }
+
+ void visit(const DependencySpecTree::NodeType<NamedSetDepSpec>::Type & s)
+ {
+ result->push_back(stringify(*s.spec()));
+ }
+
+ void visit(const DependencySpecTree::NodeType<DependencyLabelsDepSpec>::Type & s)
+ {
+ result->push_back(stringify(*s.spec()));
+ }
+
+ void visit(const DependencySpecTree::NodeType<PackageDepSpec>::Type & s)
+ {
+ result->push_back(stringify(*s.spec()));
+ }
+
+ void visit(const DependencySpecTree::NodeType<BlockDepSpec>::Type & s)
+ {
+ result->push_back(stringify(*s.spec()));
+ }
+
+ void visit(const DependencySpecTree::NodeType<ConditionalDepSpec>::Type & node)
+ {
+ if (node.spec()->condition_met())
+ {
+ AnyOfAlternativesVisitor v;
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(v));
+ result->push_back(stringify(*node.spec()) + " ( " + join(v.result->begin(),
+ v.result->end(), " ") + " )");
+ }
+ }
+
+ void visit(const DependencySpecTree::NodeType<AnyDepSpec>::Type & node)
+ {
+ AnyOfAlternativesVisitor v;
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(v));
+ result->push_back("|| ( " + join(v.result->begin(),
+ v.result->end(), " ") + " )");
+ }
+
+ void visit(const DependencySpecTree::NodeType<AllDepSpec>::Type & node)
+ {
+ AnyOfAlternativesVisitor v;
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(v));
+ result->push_back("( " + join(v.result->begin(),
+ v.result->end(), " ") + " )");
+ }
+ };
+
struct AnyDepSpecChildHandler
{
const Resolver & resolver;
@@ -234,6 +291,7 @@ namespace
SanitisedDependencies & sanitised_dependencies;
const std::string raw_name;
const std::string human_name;
+ std::tr1::shared_ptr<Sequence<std::string> > any_of_alternatives;
std::list<std::tr1::shared_ptr<ActiveDependencyLabels> > labels_stack;
Finder(
@@ -242,12 +300,14 @@ namespace
SanitisedDependencies & s,
const std::tr1::shared_ptr<const DependencyLabelSequence> & l,
const std::string & rn,
- const std::string & hn) :
+ const std::string & hn,
+ const std::tr1::shared_ptr<Sequence<std::string> > & a) :
resolver(r),
our_qpn_s(q),
sanitised_dependencies(s),
raw_name(rn),
- human_name(hn)
+ human_name(hn),
+ any_of_alternatives(a)
{
labels_stack.push_front(make_shared_ptr(new ActiveDependencyLabels(*l)));
}
@@ -284,7 +344,7 @@ namespace
return make_named_values<SanitisedDependency>(
value_for<n::active_dependency_labels>(*labels_stack.begin()),
value_for<n::active_dependency_labels_as_string>(adl.str()),
- value_for<n::any_of_alternatives>(make_null_shared_ptr()),
+ value_for<n::any_of_alternatives>(any_of_alternatives),
value_for<n::metadata_key_human_name>(human_name),
value_for<n::metadata_key_raw_name>(raw_name),
value_for<n::spec>(spec)
@@ -320,6 +380,14 @@ namespace
void visit(const DependencySpecTree::NodeType<AnyDepSpec>::Type & node)
{
+ Save<std::tr1::shared_ptr<Sequence<std::string> > > save_any_of_alternatives(&any_of_alternatives);
+
+ {
+ AnyOfAlternativesVisitor v;
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(v));
+ any_of_alternatives = v.result;
+ }
+
AnyDepSpecChildHandler h(resolver, our_qpn_s, std::tr1::bind(&Finder::make_sanitised, this, std::tr1::placeholders::_1));
std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(h));
h.commit(
@@ -368,7 +436,7 @@ SanitisedDependencies::_populate_one(
Context context("When finding dependencies for '" + stringify(*id) + "' from key '" + ((*id).*pmf)()->raw_name() + "':");
Finder f(resolver, QPN_S(id), *this, ((*id).*pmf)()->initial_labels(), ((*id).*pmf)()->raw_name(),
- ((*id).*pmf)()->human_name());
+ ((*id).*pmf)()->human_name(), make_null_shared_ptr());
((*id).*pmf)()->value()->root()->accept(f);
}
diff --git a/src/clients/cave/cmd_resolve.cc b/src/clients/cave/cmd_resolve.cc
index 8a7d22b..0feff2d 100644
--- a/src/clients/cave/cmd_resolve.cc
+++ b/src/clients/cave/cmd_resolve.cc
@@ -30,6 +30,7 @@
#include <paludis/util/make_named_values.hh>
#include <paludis/util/system.hh>
#include <paludis/args/do_help.hh>
+#include <paludis/args/escape.hh>
#include <paludis/resolver/resolver.hh>
#include <paludis/resolver/resolution.hh>
#include <paludis/resolver/decision.hh>
@@ -505,7 +506,7 @@ namespace
for (ResolveCommandLine::ParametersConstIterator p(cmdline.begin_parameters()), p_end(cmdline.end_parameters()) ;
p != p_end ; ++p)
- command = command + " " + *p;
+ command = command + " " + args::escape(*p);
paludis::Command cmd(command);
cmd
@@ -559,7 +560,7 @@ namespace
for (ResolveCommandLine::ParametersConstIterator p(cmdline.begin_parameters()), p_end(cmdline.end_parameters()) ;
p != p_end ; ++p)
- command = command + " " + *p;
+ command = command + " " + args::escape(*p);
paludis::Command cmd(command);
cmd