aboutsummaryrefslogtreecommitdiff
path: root/0.4.0/paludis/args
diff options
context:
space:
mode:
Diffstat (limited to '0.4.0/paludis/args')
-rw-r--r--0.4.0/paludis/args/Makefile.am46
-rw-r--r--0.4.0/paludis/args/args.cc27
-rw-r--r--0.4.0/paludis/args/args.hh35
-rw-r--r--0.4.0/paludis/args/args_TEST.cc161
-rw-r--r--0.4.0/paludis/args/args_dumper.cc81
-rw-r--r--0.4.0/paludis/args/args_dumper.hh79
-rw-r--r--0.4.0/paludis/args/args_error.cc35
-rw-r--r--0.4.0/paludis/args/args_error.hh53
-rw-r--r--0.4.0/paludis/args/args_group.cc47
-rw-r--r--0.4.0/paludis/args/args_group.hh98
-rw-r--r--0.4.0/paludis/args/args_handler.cc129
-rw-r--r--0.4.0/paludis/args/args_handler.hh129
-rw-r--r--0.4.0/paludis/args/args_option.cc134
-rw-r--r--0.4.0/paludis/args/args_option.hh359
-rw-r--r--0.4.0/paludis/args/args_visitor.cc97
-rw-r--r--0.4.0/paludis/args/args_visitor.hh96
-rw-r--r--0.4.0/paludis/args/bad_argument.cc35
-rw-r--r--0.4.0/paludis/args/bad_argument.hh53
-rw-r--r--0.4.0/paludis/args/bad_value.cc32
-rw-r--r--0.4.0/paludis/args/bad_value.hh53
-rw-r--r--0.4.0/paludis/args/missing_value.cc36
-rw-r--r--0.4.0/paludis/args/missing_value.hh55
22 files changed, 1870 insertions, 0 deletions
diff --git a/0.4.0/paludis/args/Makefile.am b/0.4.0/paludis/args/Makefile.am
new file mode 100644
index 000000000..ddfdac14f
--- /dev/null
+++ b/0.4.0/paludis/args/Makefile.am
@@ -0,0 +1,46 @@
+CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda
+MAINTAINERCLEANFILES = Makefile.in
+AM_CXXFLAGS = -I$(top_srcdir)
+
+TESTS = \
+ args_TEST
+
+paludis_args_includedir = $(includedir)/paludis/args/
+
+paludis_args_include_HEADERS = \
+ args.hh \
+ args_error.hh \
+ args_group.hh \
+ args_handler.hh \
+ args_option.hh \
+ bad_argument.hh \
+ args_visitor.hh \
+ bad_value.hh \
+ missing_value.hh \
+ args_dumper.hh
+
+libpaludisargs_a_SOURCES = $(paludis_args_include_HEADERS) \
+ args.cc \
+ args_error.cc \
+ args_group.cc \
+ args_handler.cc \
+ args_option.cc \
+ bad_argument.cc \
+ args_visitor.cc \
+ bad_value.cc \
+ missing_value.cc \
+ args_dumper.cc
+
+TESTS_ENVIRONMENT = env -u PALUDIS_OPTIONS TEST_SCRIPT_DIR="$(srcdir)/" bash $(top_srcdir)/test/run_test.sh
+lib_LIBRARIES = libpaludisargs.a
+check_PROGRAMS = $(TESTS)
+
+test_ldadd = \
+ $(top_builddir)/test/libtest.a \
+ libpaludisargs.a \
+ $(top_builddir)/paludis/libpaludis.a \
+ $(top_builddir)/paludis/util/libpaludisutil.a
+
+args_TEST_SOURCES = args_TEST.cc
+args_TEST_LDADD = $(test_ldadd)
+
diff --git a/0.4.0/paludis/args/args.cc b/0.4.0/paludis/args/args.cc
new file mode 100644
index 000000000..fac59ce90
--- /dev/null
+++ b/0.4.0/paludis/args/args.cc
@@ -0,0 +1,27 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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 "args.hh"
+
+/** \file
+ * Implementation for args.hh .
+ *
+ * \ingroup grplibpaludisargs
+ */
+
diff --git a/0.4.0/paludis/args/args.hh b/0.4.0/paludis/args/args.hh
new file mode 100644
index 000000000..ce54edae0
--- /dev/null
+++ b/0.4.0/paludis/args/args.hh
@@ -0,0 +1,35 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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_ARGS_ARGS_HH
+#define PALUDIS_GUARD_ARGS_ARGS_HH 1
+
+/** \file
+ * Master include file for command line argument handling.
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+#include <paludis/args/args_error.hh>
+#include <paludis/args/args_group.hh>
+#include <paludis/args/args_handler.hh>
+#include <paludis/args/args_option.hh>
+#include <paludis/args/bad_argument.hh>
+
+#endif
diff --git a/0.4.0/paludis/args/args_TEST.cc b/0.4.0/paludis/args/args_TEST.cc
new file mode 100644
index 000000000..d94c7dd13
--- /dev/null
+++ b/0.4.0/paludis/args/args_TEST.cc
@@ -0,0 +1,161 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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 <paludis/args/args.hh>
+#include <paludis/args/missing_value.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace paludis;
+using namespace paludis::args;
+using namespace test;
+
+/** \file
+ * Test cases for paludis::args things.
+ *
+ * \ingroup grptestcases
+ */
+
+#ifndef DOXYGEN
+
+struct CommandLine : public ArgsHandler
+{
+ ArgsGroup group_one;
+ SwitchArg arg_foo;
+ SwitchArg arg_bar;
+ SwitchArg arg_dummy;
+
+ ArgsGroup group_two;
+ SwitchArg arg_baz;
+ AliasArg arg_other_baz;
+ StringArg arg_something;
+ IntegerArg arg_somenum;
+ EnumArg arg_enum;
+
+ ArgsGroup group_three;
+ EnumArg arg_other_enum;
+ StringSetArg arg_stringset;
+
+ CommandLine();
+ ~CommandLine();
+};
+
+CommandLine::CommandLine() :
+ group_one(this, "Group one"),
+ arg_foo(&group_one, "foo", 'f', "Enable foo"),
+ arg_bar(&group_one, "bar", 'b', "Enable bar"),
+ arg_dummy(&group_one, "dummy", 'd', "Enable something else"),
+
+ group_two(this, "Group two"),
+ arg_baz(&group_two, "baz", 'z', "Enable baz"),
+ arg_other_baz(&arg_baz, "other-baz"),
+ arg_something(&group_two, "something", 's', "Value of something"),
+ arg_somenum(&group_two, "num", 'n', "Some number"),
+ arg_enum(&group_two, "enum", 'e', "One of three", EnumArg::EnumArgOptions("one", "Option one")("two", "option two")("three", "option three"), "two"),
+
+ group_three(this, "Group three"),
+ arg_other_enum(&group_three, "something", '\0', "Blah.", EnumArg::EnumArgOptions("a", "A")("b", "B")("c", "C"), "b"),
+ arg_stringset(&group_three, "stringset", 't', "A StringSet.")
+{
+}
+
+CommandLine::~CommandLine()
+{
+}
+
+#endif
+
+namespace test_cases
+{
+ /**
+ * \test Simple args tests.
+ *
+ * \ingroup grptestcases
+ */
+ struct ArgsTestSimple : TestCase
+ {
+ ArgsTestSimple() : TestCase("simple") { }
+
+ void run()
+ {
+ char * args[] = { "program-name", "--other-baz", "-fsne", "blah", "7", "three", "--", "--dummy",
+ "one", "two" };
+ CommandLine c1;
+ c1.run(10, args);
+ TEST_CHECK(c1.arg_foo.specified());
+ TEST_CHECK(! c1.arg_bar.specified());
+ TEST_CHECK(c1.arg_baz.specified());
+ TEST_CHECK(c1.arg_other_baz.specified());
+ TEST_CHECK(c1.arg_something.specified());
+ TEST_CHECK(c1.arg_something.argument() == "blah");
+ TEST_CHECK(c1.arg_somenum.specified());
+ TEST_CHECK(c1.arg_somenum.argument() == 7);
+ TEST_CHECK(c1.arg_enum.specified());
+ TEST_CHECK(c1.arg_enum.argument() == "three");
+ TEST_CHECK(! c1.arg_dummy.specified());
+ TEST_CHECK(! c1.arg_other_enum.specified());
+ TEST_CHECK(c1.arg_other_enum.argument() == "b");
+
+ TEST_CHECK_EQUAL(std::distance(c1.begin_parameters(), c1.end_parameters()), 3);
+ TEST_CHECK_EQUAL(*c1.begin_parameters(), "--dummy");
+ TEST_CHECK_EQUAL(*++c1.begin_parameters(), "one");
+ TEST_CHECK_EQUAL(*++(++(c1.begin_parameters())), "two");
+ }
+ } test_args_simple;
+
+ /**
+ * \test Missing parameters tests.
+ *
+ * \ingroup grptestcases
+ */
+ struct ArgsTestNoParam : TestCase
+ {
+ ArgsTestNoParam() : TestCase("Missing parameters") { }
+
+ void run()
+ {
+ char *args[] = { "program-name", "-e" };
+ CommandLine c1;
+ TEST_CHECK_THROWS(c1.run(2, args), MissingValue);
+ }
+ } test_args_no_param;
+
+ /**
+ * \test String tests.
+ *
+ * \ingroup grptestcases
+ */
+ struct ArgsTestStringSet : TestCase
+ {
+ ArgsTestStringSet() : TestCase("StringSet") { }
+
+ void run()
+ {
+ char *args[] = { "program-name", "--stringset", "one", "-t", "two", "-t", "three", "fnord" };
+ CommandLine c1;
+ c1.run(8, args);
+ TEST_CHECK(c1.arg_stringset.specified());
+ TEST_CHECK(std::find(c1.arg_stringset.args_begin(), c1.arg_stringset.args_end(), "one") != c1.arg_stringset.args_end());
+ TEST_CHECK(std::find(c1.arg_stringset.args_begin(), c1.arg_stringset.args_end(), "two") != c1.arg_stringset.args_end());
+ TEST_CHECK(std::find(c1.arg_stringset.args_begin(), c1.arg_stringset.args_end(), "three") != c1.arg_stringset.args_end());
+ TEST_CHECK(std::find(c1.arg_stringset.args_begin(), c1.arg_stringset.args_end(), "fnord") == c1.arg_stringset.args_end());
+ }
+ } test_args_string_set;
+}
+
diff --git a/0.4.0/paludis/args/args_dumper.cc b/0.4.0/paludis/args/args_dumper.cc
new file mode 100644
index 000000000..afdc747c0
--- /dev/null
+++ b/0.4.0/paludis/args/args_dumper.cc
@@ -0,0 +1,81 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Stephen Bennett <spb@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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/args_dumper.hh>
+#include <paludis/args/args_option.hh>
+
+#include <sstream>
+
+/** \file
+ * Implementation of ArgsDumper.
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+using namespace paludis;
+using namespace paludis::args;
+
+ArgsDumper::ArgsDumper(std::ostream & os) :
+ _os(os)
+{
+}
+
+void ArgsDumper::visit(const ArgsOption * const a)
+{
+ std::stringstream p;
+ p << " --" << a->long_name();
+ if (a->short_name())
+ p << ", -" << a->short_name();
+ if (p.str().length() < 24)
+ p << std::string(24 - p.str().length(), ' ');
+ else
+ p << std::endl << std::string(24, ' ');
+ _os << p.str();
+ _os << " " << a->description() << std::endl;
+}
+
+#ifndef DOXYGEN
+#define VISIT(type) void ArgsDumper::visit(const type * const a) \
+ { visit(static_cast<const ArgsOption *>(a)); }
+
+VISIT(SwitchArg)
+VISIT(StringArg)
+VISIT(IntegerArg)
+VISIT(AliasArg)
+VISIT(StringSetArg)
+#endif
+
+void ArgsDumper::visit(const EnumArg * const a)
+{
+ visit(static_cast<const ArgsOption *>(a));
+ for (EnumArg::AllowedArgIterator it = a->begin_allowed_args(), it_end = a->end_allowed_args();
+ it != it_end; ++it)
+ {
+ std::stringstream p;
+ p << " " << (*it).first;
+ if (p.str().length() < 26)
+ p << std::string(26 - p.str().length(), ' ');
+ _os << p.str();
+ _os << " " << (*it).second;
+ if ((*it).first == a->default_arg())
+ _os << " (default)";
+ _os << std::endl;
+ }
+}
diff --git a/0.4.0/paludis/args/args_dumper.hh b/0.4.0/paludis/args/args_dumper.hh
new file mode 100644
index 000000000..34ba0a1b3
--- /dev/null
+++ b/0.4.0/paludis/args/args_dumper.hh
@@ -0,0 +1,79 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Stephen Bennett <spb@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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_ARGS_DUMPER_HH
+#define PALUDIS_GUARD_PALUDIS_ARGS_ARGS_DUMPER_HH 1
+
+#include <ostream>
+#include <paludis/args/args_visitor.hh>
+#include <paludis/util/visitor.hh>
+
+namespace paludis
+{
+ namespace args
+ {
+ class ArgsOption;
+ class SwitchArg;
+ class StringArg;
+ class IntegerArg;
+ class AliasArg;
+ class EnumArg;
+
+ /**
+ * Visitor class. Prints help text appropriate to each command line option.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class ArgsDumper : public ArgsVisitorTypes::ConstVisitor
+ {
+ private:
+ std::ostream & _os;
+
+ public:
+ /**
+ * Constructor.
+ */
+ ArgsDumper(std::ostream & os);
+
+ /// Visit an ArgsOption.
+ void visit(const ArgsOption * const);
+
+ /// Visit a SwitchArg.
+ void visit(const SwitchArg * const);
+
+ /// Visit a StringArg.
+ void visit(const StringArg * const);
+
+ /// Visit an IntegerArg.
+ void visit(const IntegerArg * const);
+
+ /// Visit an AliasArg.
+ void visit(const AliasArg * const);
+
+ /// Visit an EnumArg.
+ void visit(const EnumArg * const);
+
+ /// Visit a StringSetArg.
+ void visit(const StringSetArg * const);
+ };
+ }
+}
+
+#endif
diff --git a/0.4.0/paludis/args/args_error.cc b/0.4.0/paludis/args/args_error.cc
new file mode 100644
index 000000000..46aaa0d27
--- /dev/null
+++ b/0.4.0/paludis/args/args_error.cc
@@ -0,0 +1,35 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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 "args_error.hh"
+
+/** \file
+ * Implementation for ArgsError.
+ *
+ * \ingroup grplibpaludisargs
+ * \ingroup grpexceptions
+ */
+
+using namespace paludis::args;
+
+ArgsError::ArgsError(const std::string & message) throw () :
+ paludis::Exception("Error handling command line: " + message)
+{
+}
+
diff --git a/0.4.0/paludis/args/args_error.hh b/0.4.0/paludis/args/args_error.hh
new file mode 100644
index 000000000..8d8355bfa
--- /dev/null
+++ b/0.4.0/paludis/args/args_error.hh
@@ -0,0 +1,53 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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_ARGS_ARGS_ERROR_HH
+#define PALUDIS_GUARD_ARGS_ARGS_ERROR_HH 1
+
+#include <paludis/util/exception.hh>
+#include <string>
+
+/** \file
+ * Declaration for ArgsError.
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+namespace paludis
+{
+ namespace args
+ {
+ /**
+ * Thrown if an invalid command line argument is provided.
+ *
+ * \ingroup grplibpaludisargs
+ * \ingroup grpexceptions
+ */
+ class ArgsError : public paludis::Exception
+ {
+ protected:
+ /**
+ * Constructor.
+ */
+ ArgsError(const std::string & message) throw ();
+ };
+ }
+}
+
+#endif
diff --git a/0.4.0/paludis/args/args_group.cc b/0.4.0/paludis/args/args_group.cc
new file mode 100644
index 000000000..593e3e7e8
--- /dev/null
+++ b/0.4.0/paludis/args/args_group.cc
@@ -0,0 +1,47 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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 "args.hh"
+
+/** \file
+ * Implementation for ArgsGroup.
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+using namespace paludis::args;
+
+ArgsGroup::ArgsGroup(ArgsHandler * h, const std::string & name) :
+ _name(name),
+ _handler(h)
+{
+ h->add(this);
+}
+
+void
+ArgsGroup::add(ArgsOption * const value)
+{
+ /// \bug Should check for uniqueness of short and long names.
+ _args_options.push_back(value);
+}
+
+ArgsGroup::~ArgsGroup()
+{
+}
+
diff --git a/0.4.0/paludis/args/args_group.hh b/0.4.0/paludis/args/args_group.hh
new file mode 100644
index 000000000..c4d4aa53f
--- /dev/null
+++ b/0.4.0/paludis/args/args_group.hh
@@ -0,0 +1,98 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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_ARGS_ARGS_GROUP_HH
+#define PALUDIS_GUARD_ARGS_ARGS_GROUP_HH 1
+
+#include <list>
+#include <paludis/args/args_option.hh>
+#include <string>
+
+/** \file
+ * Declaration for ArgsGroup.
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+namespace paludis
+{
+
+ namespace args
+ {
+ class ArgsHandler;
+
+ /**
+ * Contains a related group of command line arguments.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class ArgsGroup
+ {
+ friend class ArgsHandler;
+ friend class ArgsOption;
+
+ private:
+ ArgsGroup(const ArgsGroup &);
+
+ void operator= (const ArgsGroup &);
+
+ const std::string _name;
+
+ std::list<ArgsOption *> _args_options;
+
+ ArgsHandler * _handler;
+
+ protected:
+ /**
+ * Add an ArgsOption instance (called by the ArgsOption
+ * constructor).
+ */
+ void add(ArgsOption * const value);
+
+ public:
+ /**
+ * Constructor.
+ */
+ ArgsGroup(ArgsHandler * h, const std::string & name);
+
+ /**
+ * Destructor.
+ */
+ ~ArgsGroup();
+
+ /**
+ * Fetch our name.
+ */
+ const std::string & name() const
+ {
+ return _name;
+ }
+
+ /**
+ * Fetch our handler.
+ */
+ ArgsHandler * handler() const
+ {
+ return _handler;
+ }
+ };
+ }
+}
+
+#endif
diff --git a/0.4.0/paludis/args/args_handler.cc b/0.4.0/paludis/args/args_handler.cc
new file mode 100644
index 000000000..a68165554
--- /dev/null
+++ b/0.4.0/paludis/args/args_handler.cc
@@ -0,0 +1,129 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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 "args.hh"
+#include "args_dumper.hh"
+#include <algorithm>
+#include <paludis/util/system.hh>
+
+/** \file
+ * Implementation for ArgsHandler.
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+using namespace paludis::args;
+
+ArgsHandler::ArgsHandler()
+{
+}
+
+void
+ArgsHandler::add(ArgsGroup * const g)
+{
+ /// \bug Should check for name uniqueness.
+ _groups.push_back(g);
+}
+
+void
+ArgsHandler::run(const int argc, const char * const * const argv)
+{
+ std::list<std::string> args;
+
+ std::string env_options = paludis::getenv_with_default("PALUDIS_OPTIONS", "");
+
+ std::istringstream iss(env_options);
+ std::string option;
+ while(iss.good())
+ {
+ iss >> option;
+ if(!option.empty())
+ args.push_back(option);
+ }
+
+ args.insert(args.end(), &argv[1], &argv[argc]);
+
+ std::list<std::string>::iterator argit = args.begin(), arge = args.end();
+
+ ArgsVisitor visitor(&argit, arge);
+
+ for ( ; argit != arge; ++argit )
+ {
+ std::string arg = *argit;
+
+ if (arg == "--")
+ {
+ ++argit;
+ break;
+ }
+ else if (0 == arg.compare(0, 2, "--"))
+ {
+ arg.erase(0, 2);
+ std::map<std::string, ArgsOption*>::iterator it = _longopts.find(arg);
+ if (it == _longopts.end())
+ throw BadArgument("--" + arg);
+ (*it).second->accept(&visitor);
+ }
+ else if (arg[0] == '-')
+ {
+ arg.erase(0, 1);
+ for (std::string::iterator c = arg.begin(); c != arg.end(); ++c)
+ {
+ std::map<char, ArgsOption*>::iterator it = _shortopts.find(*c);
+ if (it == _shortopts.end())
+ {
+ throw BadArgument(std::string("-") + *c);
+ }
+ (*it).second->accept(&visitor);
+ }
+ }
+ else
+ {
+ _parameters.push_back(arg);
+ }
+ }
+
+ _parameters.insert(_parameters.end(), argit, args.end());
+}
+
+void
+ArgsHandler::dump_to_stream(std::ostream & s) const
+{
+ ArgsDumper dump(s);
+ std::list<ArgsGroup *>::const_iterator g(_groups.begin()), g_end(_groups.end());
+ for ( ; g != g_end ; ++g)
+ {
+ s << (*g)->name() << ":" << std::endl;
+
+ std::for_each((*g)->_args_options.begin(), (*g)->_args_options.end(),
+ accept_visitor(&dump));
+
+ s << std::endl;
+ }
+}
+
+#ifndef DOXYGEN
+std::ostream &
+paludis::args::operator<< (std::ostream & s, const ArgsHandler & h)
+{
+ h.dump_to_stream(s);
+ return s;
+}
+#endif
+
diff --git a/0.4.0/paludis/args/args_handler.hh b/0.4.0/paludis/args/args_handler.hh
new file mode 100644
index 000000000..42a517920
--- /dev/null
+++ b/0.4.0/paludis/args/args_handler.hh
@@ -0,0 +1,129 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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_ARGS_ARGS_HANDLER_HH
+#define PALUDIS_GUARD_ARGS_ARGS_HANDLER_HH 1
+
+#include <map>
+#include <ostream>
+#include <paludis/args/args_group.hh>
+#include <paludis/util/instantiation_policy.hh>
+#include <string>
+
+/** \file
+ * Declaration for ArgsHandler.
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+namespace paludis
+{
+ namespace args
+ {
+ /**
+ * Handles command line arguments.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class ArgsHandler : private InstantiationPolicy<ArgsHandler, instantiation_method::NonCopyableTag>
+ {
+ friend class ArgsGroup;
+ friend std::ostream & operator<< (std::ostream &, const ArgsHandler &);
+
+ private:
+ std::list<ArgsGroup *> _groups;
+ std::list<std::string> _parameters;
+
+ std::map<std::string, ArgsOption *> _longopts;
+ std::map<char, ArgsOption *> _shortopts;
+
+ protected:
+ /**
+ * Add an new ArgsGroup (called by the ArgsGroup constructor).
+ */
+ void add(ArgsGroup * const);
+
+ /**
+ * Dump, for --help output (called by operator<<).
+ */
+ void dump_to_stream(std::ostream & s) const;
+
+ public:
+ /**
+ * Constructor.
+ */
+ ArgsHandler();
+
+ /**
+ * Parse command line arguments.
+ */
+ void run(const int, const char * const * const);
+
+ /**
+ * Iterate over our parameters (non - and -- switches and their
+ * values).
+ */
+ typedef std::list<std::string>::const_iterator ParametersIterator;
+
+ /**
+ * Pointer to the start of our parameters.
+ */
+ ParametersIterator begin_parameters() const
+ {
+ return _parameters.begin();
+ }
+
+ /**
+ * Pointer to past the end of our parameters.
+ */
+ ParametersIterator end_parameters() const
+ {
+ return _parameters.end();
+ }
+
+ /**
+ * Do we have no parameters?
+ */
+ bool empty() const
+ {
+ return _parameters.empty();
+ }
+
+ /**
+ * Add an ArgsOption instance.
+ */
+ void add_option(ArgsOption *opt, const std::string long_name, const char short_name = '\0')
+ {
+ _longopts[long_name] = opt;
+ if (short_name != '\0')
+ _shortopts[short_name] = opt;
+ }
+
+ };
+
+ /**
+ * Output an ArgsHandler to an ostream, for --help output.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ std::ostream & operator<< (std::ostream &, const ArgsHandler &);
+ }
+}
+
+#endif
diff --git a/0.4.0/paludis/args/args_option.cc b/0.4.0/paludis/args/args_option.cc
new file mode 100644
index 000000000..b7f4287bc
--- /dev/null
+++ b/0.4.0/paludis/args/args_option.cc
@@ -0,0 +1,134 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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 "args.hh"
+#include "bad_value.hh"
+
+/** \file
+ * Implementation for ArgsOption.
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+using namespace paludis::args;
+
+ArgsOption::ArgsOption(ArgsGroup * const g, const std::string & long_name,
+ const char short_name, const std::string & description) :
+ _group(g),
+ _long_name(long_name),
+ _short_name(short_name),
+ _description(description),
+ _specified(false)
+{
+ g->add(this);
+ g->_handler->add_option(this, long_name, short_name);
+}
+
+ArgsOption::~ArgsOption()
+{
+}
+
+SwitchArg::SwitchArg(ArgsGroup * const group, std::string long_name, char short_name,
+ std::string description) :
+ ArgsOption(group, long_name, short_name, description)
+{
+}
+
+SwitchArg::~SwitchArg()
+{
+}
+
+AliasArg::AliasArg(ArgsOption * const other, const std::string & long_name) :
+ ArgsOption(other->group(), long_name, '\0', "Alias for --" + other->long_name()),
+ _other(other)
+{
+ other->group()->handler()->add_option(other, long_name);
+}
+
+StringArg::StringArg(ArgsGroup * const g, const std::string & long_name,
+ const char short_name, const std::string & description) :
+ ArgsOption(g, long_name, short_name, description)
+{
+}
+
+StringSetArg::StringSetArg(ArgsGroup * const g, const std::string & long_name,
+ const char short_name, const std::string & description) :
+ ArgsOption(g, long_name, short_name, description)
+{
+}
+
+IntegerArg::IntegerArg(ArgsGroup * const group, const std::string& long_name,
+ char short_name, const std::string& description) :
+ ArgsOption(group, long_name, short_name, description)
+{
+}
+
+namespace
+{
+ /**
+ * Is an arg a particular value?
+ *
+ * \ingroup grplibpaludisargs
+ */
+ struct ArgIs
+ {
+ /// The argument.
+ const std::string arg;
+
+ /// Constructor.
+ ArgIs(const std::string & a) :
+ arg(a)
+ {
+ }
+
+ /// Comparator.
+ bool operator() (const std::pair<std::string, std::string> & p) const
+ {
+ return p.first == arg;
+ }
+ };
+}
+
+void EnumArg::set_argument(const std::string & arg)
+{
+ if (_allowed_args.end() == std::find_if(_allowed_args.begin(),
+ _allowed_args.end(), ArgIs(arg)))
+ throw (BadValue("--" + long_name(), arg));
+
+ _argument = arg;
+}
+
+EnumArg::~EnumArg()
+{
+}
+
+EnumArg::EnumArgOptions::EnumArgOptions(std::string opt, std::string desc)
+{
+ _options.push_back(std::make_pair(opt, desc));
+}
+
+EnumArg::EnumArgOptions & EnumArg::EnumArgOptions::operator() (std::string opt, std::string desc)
+{
+ _options.push_back(std::make_pair(opt, desc));
+ return *this;
+}
+
+EnumArg::EnumArgOptions::~EnumArgOptions()
+{
+}
diff --git a/0.4.0/paludis/args/args_option.hh b/0.4.0/paludis/args/args_option.hh
new file mode 100644
index 000000000..bce3c863b
--- /dev/null
+++ b/0.4.0/paludis/args/args_option.hh
@@ -0,0 +1,359 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ * Copyright (c) 2006 Stephen Bennett <spb@gentoo.org>
+ *
+ * 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_ARGS_ARGS_OPTION_HH
+#define PALUDIS_GUARD_ARGS_ARGS_OPTION_HH 1
+
+#include <paludis/args/args_visitor.hh>
+#include <set>
+#include <string>
+#include <vector>
+
+/** \file
+ * Declaration for ArgsOption.
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+namespace paludis
+{
+ namespace args
+ {
+ class ArgsGroup;
+
+ /**
+ * Base class for a command line option.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class ArgsOption : public virtual VisitableInterface<ArgsVisitorTypes>
+ {
+ friend class ArgsHandler;
+
+ private:
+ ArgsGroup * const _group;
+
+ const std::string _long_name;
+ const char _short_name;
+ const std::string _description;
+
+ bool _specified;
+
+ ArgsOption(const ArgsOption &);
+
+ void operator= (const ArgsOption &);
+
+ protected:
+ /**
+ * Constructor.
+ */
+ ArgsOption(ArgsGroup * const, const std::string & long_name,
+ const char short_name, const std::string & description);
+
+ /**
+ * Destructor.
+ */
+ ~ArgsOption();
+
+ public:
+ /**
+ * Fetch our long name.
+ */
+ const std::string & long_name() const
+ {
+ return _long_name;
+ }
+
+ /**
+ * Fetch our short name (may be 0).
+ */
+ char short_name() const
+ {
+ return _short_name;
+ }
+
+ /**
+ * Fetch our description.
+ */
+ const std::string & description() const
+ {
+ return _description;
+ }
+
+ /**
+ * Fetch whether or not we were specified on the
+ * command line.
+ */
+ virtual bool specified() const
+ {
+ return _specified;
+ }
+
+ /**
+ * Set the value returned by specified().
+ */
+ virtual void set_specified(const bool value)
+ {
+ _specified = value;
+ }
+
+ /**
+ * Fetch our group.
+ */
+ ArgsGroup * group()
+ {
+ return _group;
+ }
+ };
+
+ /**
+ * A SwitchArg is an option that can either be specified or not
+ * specified, and that takes no value (for example, --help).
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class SwitchArg : public ArgsOption, public Visitable<SwitchArg, ArgsVisitorTypes>
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ SwitchArg(ArgsGroup * const group, std::string long_name, char short_name,
+ std::string description);
+
+ ~SwitchArg();
+ };
+
+ /**
+ * An option that takes a string argument.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class StringArg : public ArgsOption, public Visitable<StringArg, ArgsVisitorTypes>
+ {
+ private:
+ std::string _argument;
+
+ public:
+
+ /**
+ * Constructor
+ */
+ StringArg(ArgsGroup * const, const std::string & long_name,
+ const char short_name, const std::string & description);
+
+ /**
+ * Fetch the argument that was given to this option.
+ */
+ const std::string& argument() const { return _argument; }
+
+ /**
+ * Set the argument returned by argument().
+ */
+ void set_argument(const std::string& arg) { _argument = arg; }
+ };
+
+ /**
+ * An option that takes a set of strings.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class StringSetArg : public ArgsOption, public Visitable<StringSetArg, ArgsVisitorTypes>
+ {
+ private:
+ std::set<std::string> _args;
+
+ public:
+
+ /**
+ * Type used to iterate over specified args.
+ */
+ typedef std::set<std::string>::const_iterator Iterator;
+
+ /**
+ * Constructor
+ */
+ StringSetArg(ArgsGroup * const, const std::string & long_name,
+ const char short_name, const std::string & description);
+
+ /**
+ * Retrieve an iterator to the first arg
+ */
+ Iterator args_begin() const { return _args.begin(); }
+
+ /**
+ * Retrieve an iterator one past the last arg
+ */
+ Iterator args_end() const { return _args.end(); }
+
+ /**
+ * Add an argument to the set returned by [ args_begin(), args_end() )
+ */
+ void add_argument(const std::string & arg) { _args.insert(arg); }
+ };
+
+
+ /**
+ * An AliasArg is an alias for another argument.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class AliasArg : public ArgsOption, public Visitable<AliasArg, ArgsVisitorTypes>
+ {
+ private:
+ ArgsOption * const _other;
+
+ public:
+ /**
+ * Constructor.
+ */
+ AliasArg(ArgsOption * const other, const std::string & new_long_name);
+
+ virtual bool specified() const
+ {
+ return _other->specified();
+ }
+
+ virtual void set_specified(const bool value)
+ {
+ _other->set_specified(value);
+ }
+ };
+
+ /**
+ * An option that takes an integer argument.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class IntegerArg : public ArgsOption, public Visitable<IntegerArg, ArgsVisitorTypes>
+ {
+ private:
+ int _argument;
+
+ public:
+ /**
+ * Constructor
+ */
+ IntegerArg(ArgsGroup * const, const std::string & long_name,
+ const char short_name, const std::string & description);
+ /**
+ * Fetch the argument that was given to this option.
+ */
+ int argument() const { return _argument; }
+
+ /**
+ * Set the argument returned by argument().
+ */
+ void set_argument(const int arg) { _argument = arg; }
+ };
+
+ /**
+ * An option that takes one of a predefined set of string arguments.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class EnumArg : public ArgsOption, public Visitable<EnumArg, ArgsVisitorTypes>
+ {
+ private:
+ const std::vector<std::pair<std::string, std::string> > _allowed_args;
+ std::string _argument;
+ const std::string _default_arg;
+
+ public:
+
+ /**
+ * Helper class for passing available options and associated descriptions
+ * to the EnumArg constructor.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class EnumArgOptions
+ {
+ private:
+ friend class EnumArg;
+ std::vector<std::pair<std::string, std::string> > _options;
+
+ public:
+ /**
+ * Constructor
+ */
+ EnumArgOptions(const std::string, const std::string);
+
+ /**
+ * Destructor.
+ */
+ ~EnumArgOptions();
+
+ /**
+ * Adds another (option, description) pair.
+ */
+ EnumArgOptions& operator() (const std::string, const std::string);
+ };
+
+ /**
+ * Constructor.
+ */
+ EnumArg(ArgsGroup * const group, const std::string & long_name,
+ const char short_name, const std::string & description,
+ const EnumArgOptions & opts, const std::string & default_arg) :
+ ArgsOption(group, long_name, short_name, description),
+ _allowed_args(opts._options), _argument(default_arg),
+ _default_arg(default_arg)
+ {
+ }
+
+ ~EnumArg();
+
+ /**
+ * Fetch the argument that was given to this option.
+ */
+ const std::string & argument() const { return _argument; }
+
+ /**
+ * Set the argument returned by argument(), having verified that
+ * it is one of the arguments allowed for this option.
+ */
+ void set_argument(const std::string & arg);
+
+ /**
+ * Fetch the default option, as specified to the constructor.
+ */
+ const std::string & default_arg() const { return _default_arg; }
+
+ /**
+ * Type used to iterate over valid arguments to this option
+ */
+ typedef std::vector<std::pair<std::string, std::string> >::const_iterator AllowedArgIterator;
+
+ /**
+ * Returns an iterator pointing to a pair containing the first valid argument,
+ * and its description.
+ */
+ AllowedArgIterator begin_allowed_args() const { return _allowed_args.begin(); }
+
+ /**
+ * Returns an iterator pointing just beyond the last valid argument.
+ */
+ AllowedArgIterator end_allowed_args() const { return _allowed_args.end(); }
+ };
+ }
+}
+
+#endif
diff --git a/0.4.0/paludis/args/args_visitor.cc b/0.4.0/paludis/args/args_visitor.cc
new file mode 100644
index 000000000..979debd67
--- /dev/null
+++ b/0.4.0/paludis/args/args_visitor.cc
@@ -0,0 +1,97 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+/*
+ * Copyright (c) 2005, 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 "args_option.hh"
+#include "bad_value.hh"
+#include "missing_value.hh"
+#include <paludis/util/visitor.hh>
+
+#include <paludis/util/destringify.hh>
+
+#include <sstream>
+
+/** \file
+ * Implementation for ArgsVisitor.
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+using namespace paludis;
+using namespace args;
+
+ArgsVisitor::ArgsVisitor(std::list<std::string>::iterator *ai,
+ std::list<std::string>::iterator ae) : _args_index(ai), _args_end(ae)
+{
+}
+
+const std::string& ArgsVisitor::get_param(const ArgsOption * const arg)
+{
+ if (++(*_args_index) == _args_end)
+ {
+ throw MissingValue("--" + arg->long_name());
+ }
+ return **_args_index;
+}
+
+void ArgsVisitor::visit(ArgsOption * const arg)
+{
+ arg->set_specified(true);
+}
+
+void ArgsVisitor::visit(StringArg * const arg)
+{
+ visit(static_cast<ArgsOption *>(arg));
+ arg->set_argument(get_param(arg));
+}
+
+void ArgsVisitor::visit(AliasArg * const arg)
+{
+ visit(static_cast<ArgsOption *>(arg));
+}
+
+void ArgsVisitor::visit(SwitchArg * const arg)
+{
+ visit(static_cast<ArgsOption *>(arg));
+}
+
+void ArgsVisitor::visit(IntegerArg * const arg)
+{
+ visit(static_cast<ArgsOption*>(arg));
+ std::string param = get_param(arg);
+ try
+ {
+ arg->set_argument(destringify<int>(param));
+ }
+ catch(DestringifyError &e)
+ {
+ throw BadValue("--" + arg->long_name(), param);
+ }
+}
+
+void ArgsVisitor::visit(EnumArg * const arg)
+{
+ visit(static_cast<ArgsOption*>(arg));
+ arg->set_argument(get_param(arg));
+}
+
+void ArgsVisitor::visit(StringSetArg * const arg)
+{
+ visit(static_cast<ArgsOption *>(arg));
+ std::string param = get_param(arg);
+ arg->add_argument(param);
+}
diff --git a/0.4.0/paludis/args/args_visitor.hh b/0.4.0/paludis/args/args_visitor.hh
new file mode 100644
index 000000000..17a9eacba
--- /dev/null
+++ b/0.4.0/paludis/args/args_visitor.hh
@@ -0,0 +1,96 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ * Copyright (c) 2006 Stephen Bennett <spb@gentoo.org>
+ *
+ * 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_ARGS_ARGS_VISITOR_HH
+#define PALUDIS_GUARD_ARGS_ARGS_VISITOR_HH 1
+
+#include <list>
+#include <paludis/util/visitor.hh>
+#include <string>
+
+/** \file
+ * Declaration for ArgsVisitor
+ *
+ * \ingroup grplibpaludisargs
+ */
+
+namespace paludis
+{
+ namespace args
+ {
+ class ArgsOption;
+ class StringArg;
+ class AliasArg;
+ class SwitchArg;
+ class IntegerArg;
+ class EnumArg;
+ class StringSetArg;
+
+ /**
+ * Visitor types for visitors that can visit Args.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ typedef VisitorTypes<ArgsOption *, StringArg *, AliasArg *, SwitchArg *,
+ IntegerArg *, EnumArg *, StringSetArg *> ArgsVisitorTypes;
+
+ /**
+ * Visitor class. Processes command-line options as they are found.
+ *
+ * \ingroup grplibpaludisargs
+ */
+ class ArgsVisitor : public ArgsVisitorTypes::Visitor
+ {
+ private:
+ std::list<std::string>::iterator *_args_index, _args_end;
+
+ const std::string& get_param(const ArgsOption * const);
+
+ public:
+ /**
+ * Constructor
+ */
+ ArgsVisitor(std::list<std::string>::iterator *, std::list<std::string>::iterator);
+
+ /// Visit an ArgsOption.
+ void visit(ArgsOption * const);
+
+ /// Visit a StringArg.
+ void visit(StringArg * const);
+
+ /// Visit an AliasArg.
+ void visit(AliasArg * const);
+
+ /// Visit a SwitchArg.
+ void visit(SwitchArg * const);
+
+ /// Visit an IntegerArg.
+ void visit(IntegerArg * const);
+
+ /// Visit an EnumArg.
+ void visit(EnumArg * const);
+
+ /// Visit a StringSetArg.
+ void visit(StringSetArg * const);
+ };
+ }
+}
+
+#endif
diff --git a/0.4.0/paludis/args/bad_argument.cc b/0.4.0/paludis/args/bad_argument.cc
new file mode 100644
index 000000000..af5554c20
--- /dev/null
+++ b/0.4.0/paludis/args/bad_argument.cc
@@ -0,0 +1,35 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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 "bad_argument.hh"
+
+/** \file
+ * Implementation for BadArgument.
+ *
+ * \ingroup Args
+ * \ingroup Exception
+ */
+
+using namespace paludis::args;
+
+BadArgument::BadArgument(const std::string & option) throw () :
+ ArgsError("Bad argument '" + option + "'")
+{
+}
+
diff --git a/0.4.0/paludis/args/bad_argument.hh b/0.4.0/paludis/args/bad_argument.hh
new file mode 100644
index 000000000..3b0e925d4
--- /dev/null
+++ b/0.4.0/paludis/args/bad_argument.hh
@@ -0,0 +1,53 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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_ARGS_BAD_ARGUMENT_HH
+#define PALUDIS_GUARD_ARGS_BAD_ARGUMENT_HH 1
+
+#include <paludis/args/args_error.hh>
+
+/** \file
+ * Declaration for BadArgument.
+ *
+ * \ingroup grplibpaludisargs
+ * \ingroup grpexceptions
+ */
+
+namespace paludis
+{
+ namespace args
+ {
+ /**
+ * Thrown if an unrecognised command line argument is specified.
+ *
+ * \ingroup grplibpaludisargs
+ * \ingroup grpexceptions
+ */
+ class BadArgument : public ArgsError
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ BadArgument(const std::string & option) throw ();
+ };
+ }
+}
+
+#endif
diff --git a/0.4.0/paludis/args/bad_value.cc b/0.4.0/paludis/args/bad_value.cc
new file mode 100644
index 000000000..5899bea4d
--- /dev/null
+++ b/0.4.0/paludis/args/bad_value.cc
@@ -0,0 +1,32 @@
+#include "bad_value.hh"
+
+/*
+ * Copyright (c) 2005, 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
+ */
+
+/** \file
+ * Implementation for BadValue
+ *
+ * \ingroup Args
+ * \ingroup Exception
+ */
+
+using namespace paludis::args;
+
+BadValue::BadValue(const std::string& option, const std::string& value) throw () :
+ ArgsError("Invalid parameter '" + value + "' for argument '" + option + "'")
+{
+}
diff --git a/0.4.0/paludis/args/bad_value.hh b/0.4.0/paludis/args/bad_value.hh
new file mode 100644
index 000000000..0392bbc9d
--- /dev/null
+++ b/0.4.0/paludis/args/bad_value.hh
@@ -0,0 +1,53 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 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_ARGS_BAD_VALUE_HH
+#define PALUDIS_GUARD_ARGS_BAD_VALUE_HH 1
+
+#include <paludis/args/args_error.hh>
+
+/** \file
+ * Declaration for BadValue.
+ *
+ * \ingroup grplibpaludisargs
+ * \ingroup grpexceptions
+ */
+
+namespace paludis
+{
+ namespace args
+ {
+ /**
+ * Thrown if an invalid parameter is passed to a valid command line argument.
+ *
+ * \ingroup grplibpaludisargs
+ * \ingroup grpexceptions
+ */
+ class BadValue : public ArgsError
+ {
+ public:
+ /**
+ * Constructor
+ */
+ BadValue(const std::string& option, const std::string& value) throw();
+ };
+ }
+}
+
+#endif
diff --git a/0.4.0/paludis/args/missing_value.cc b/0.4.0/paludis/args/missing_value.cc
new file mode 100644
index 000000000..2474ea5fa
--- /dev/null
+++ b/0.4.0/paludis/args/missing_value.cc
@@ -0,0 +1,36 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Stephen Bennett <spb@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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 "missing_value.hh"
+
+/**
+ * \file
+ * Implementation of MissingValue
+ *
+ * \ingroup Args
+ * \ingroup Exception
+ */
+
+using namespace paludis::args;
+
+MissingValue::MissingValue(const std::string & arg) throw() :
+ ArgsError("No parameter given for '" + arg + "'")
+{
+}
diff --git a/0.4.0/paludis/args/missing_value.hh b/0.4.0/paludis/args/missing_value.hh
new file mode 100644
index 000000000..9873ff092
--- /dev/null
+++ b/0.4.0/paludis/args/missing_value.hh
@@ -0,0 +1,55 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Stephen Bennett <spb@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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_MISSING_VALUE_HH
+#define PALUDIS_GUARD_PALUDIS_ARGS_MISSING_VALUE_HH 1
+
+#include <paludis/args/args_error.hh>
+
+/** \file
+ * Declaration for MissingValue
+ *
+ * \ingroup grplibpaludisargs
+ * \ingroup grpexceptions
+ */
+
+namespace paludis
+{
+ namespace args
+ {
+ /**
+ * Thrown if an argument is specified that needs a parameter,
+ * but no parameter is given.
+ *
+ * \ingroup grplibpaludisargs
+ * \ingroup grpexceptions
+ */
+ class MissingValue : public ArgsError
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ MissingValue(const std::string & arg) throw ();
+ };
+ }
+}
+
+#endif