aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-10 09:20:28 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-10 10:13:44 +0100
commit8a4defb4131d3baf2ea9cd2223f0f5e2fd0dda5a (patch)
tree272b3009954138d26ade2c0b2dcad9b3a4227be9
parentb0c920c73203b9a03fb91e16455975515ebdb6c8 (diff)
downloadpaludis-8a4defb4131d3baf2ea9cd2223f0f5e2fd0dda5a.tar.gz
paludis-8a4defb4131d3baf2ea9cd2223f0f5e2fd0dda5a.tar.xz
Support 'see also' in man pages
-rw-r--r--paludis/args/args_handler.cc28
-rw-r--r--paludis/args/args_handler.hh21
-rw-r--r--paludis/args/man.cc52
-rw-r--r--paludis/args/man.hh14
4 files changed, 112 insertions, 3 deletions
diff --git a/paludis/args/args_handler.cc b/paludis/args/args_handler.cc
index 1092f24..ab985b4 100644
--- a/paludis/args/args_handler.cc
+++ b/paludis/args/args_handler.cc
@@ -58,6 +58,7 @@ namespace paludis
std::list<std::pair<std::string, std::string> > example_lines;
std::list<std::string> notes;
std::list<std::string> descriptions;
+ std::list<std::pair<std::string, int> > see_alsos;
std::tr1::shared_ptr<Sequence<std::string> > separate_after_dashes_args;
std::map<std::string, ArgsOption *> longopts;
@@ -118,6 +119,12 @@ namespace paludis
{
typedef std::list<std::string>::iterator UnderlyingIterator;
};
+
+ template <>
+ struct WrappedForwardIteratorTraits<ArgsHandler::SeeAlsoConstIteratorTag>
+ {
+ typedef std::list<std::pair<std::string, int> >::const_iterator UnderlyingIterator;
+ };
}
ArgsHandler::ArgsHandler() :
@@ -154,6 +161,12 @@ ArgsHandler::add_note(const std::string & e)
}
void
+ArgsHandler::add_see_also(const std::string & e, const int s)
+{
+ _imp->see_alsos.push_back(std::make_pair(e, s));
+}
+
+void
ArgsHandler::add(ArgsSection * const s)
{
_imp->sections.push_back(s);
@@ -402,6 +415,18 @@ ArgsHandler::end_notes() const
return NotesIterator(_imp->notes.end());
}
+ArgsHandler::SeeAlsoConstIterator
+ArgsHandler::begin_see_alsos() const
+{
+ return SeeAlsoConstIterator(_imp->see_alsos.begin());
+}
+
+ArgsHandler::SeeAlsoConstIterator
+ArgsHandler::end_see_alsos() const
+{
+ return SeeAlsoConstIterator(_imp->see_alsos.end());
+}
+
ArgsHandler::ArgsSectionsConstIterator
ArgsHandler::begin_args_sections() const
{
@@ -455,5 +480,6 @@ template class WrappedForwardIterator<ArgsHandler::ExamplesConstIteratorTag,
template class WrappedForwardIterator<ArgsHandler::ArgsSectionsConstIteratorTag, const ArgsSection>;
template class WrappedForwardIterator<ArgsHandler::NotesIteratorTag, const std::string>;
template class WrappedForwardIterator<ArgsHandler::DescriptionLineConstIteratorTag, const std::string>;
-template class WrappedForwardIterator<args::ArgsHandler::ArgsIteratorTag, std::string>;
+template class WrappedForwardIterator<ArgsHandler::ArgsIteratorTag, std::string>;
+template class WrappedForwardIterator<ArgsHandler::SeeAlsoConstIteratorTag, const std::pair<std::string, int> >;
diff --git a/paludis/args/args_handler.hh b/paludis/args/args_handler.hh
index 046e0b1..f906670 100644
--- a/paludis/args/args_handler.hh
+++ b/paludis/args/args_handler.hh
@@ -90,6 +90,13 @@ namespace paludis
void add_description_line(const std::string & l);
/**
+ * Add a 'see also' item.
+ *
+ * \since 0.48.2
+ */
+ void add_see_also(const std::string &, int section);
+
+ /**
* Add an new ArgsSection (called by the ArgsSection constructor).
*/
void add(ArgsSection * const);
@@ -255,6 +262,19 @@ namespace paludis
///\}
+ ///\name Iterate over our 'see also' lines
+ ///\since 0.48.2
+ ///\{
+
+ struct SeeAlsoConstIteratorTag;
+ typedef WrappedForwardIterator<SeeAlsoConstIteratorTag, const std::pair<std::string, int> > SeeAlsoConstIterator;
+
+ SeeAlsoConstIterator begin_see_alsos() const;
+
+ SeeAlsoConstIterator end_see_alsos() const;
+
+ ///\}
+
///\name For use by ArgsVisitor
///\{
@@ -311,6 +331,7 @@ namespace paludis
extern template class WrappedForwardIterator<args::ArgsHandler::DescriptionLineConstIteratorTag, const std::string>;
extern template class WrappedForwardIterator<args::ArgsHandler::NotesIteratorTag, const std::string>;
extern template class WrappedForwardIterator<args::ArgsHandler::ArgsIteratorTag, std::string>;
+ extern template class WrappedForwardIterator<args::ArgsHandler::SeeAlsoConstIteratorTag, const std::pair<std::string, int> >;
}
#endif
diff --git a/paludis/args/man.cc b/paludis/args/man.cc
index eb79370..cc421e9 100644
--- a/paludis/args/man.cc
+++ b/paludis/args/man.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006, 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2006, 2007, 2008, 2009, 2010 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
@@ -171,6 +171,17 @@ paludis::args::generate_doc(DocWriter & dw, const ArgsHandler * const h)
dw.end_examples();
}
+
+ if (h->begin_see_alsos() != h->end_see_alsos())
+ {
+ dw.start_see_alsos();
+
+ for (ArgsHandler::SeeAlsoConstIterator u(h->begin_see_alsos()),
+ u_end(h->end_see_alsos()) ; u != u_end ; ++u)
+ dw.see_also(u->first, u->second, u == h->begin_see_alsos());
+
+ dw.end_see_alsos();
+ }
}
DocWriter::~DocWriter()
@@ -354,6 +365,25 @@ HtmlWriter::end_examples()
}
void
+HtmlWriter::start_see_alsos()
+{
+ _os << "<h2>See Also</h2>" << endl;
+ _os << "<ul>" << endl;
+}
+
+void
+HtmlWriter::see_also(const std::string & page, const int s, const bool)
+{
+ _os << "<li><strong>" << page << "</strong> (" << s << ")</li>" << endl;
+}
+
+void
+HtmlWriter::end_see_alsos()
+{
+ _os << "</ul>" << endl;
+}
+
+void
HtmlWriter::section(const std::string & title)
{
_os << "<h2>" << title << "</h2>" << endl;
@@ -561,6 +591,26 @@ ManWriter::end_examples()
}
void
+ManWriter::start_see_alsos()
+{
+ _os << ".SH SEE ALSO" << endl;
+ _os << ".sp" << endl;
+}
+
+void
+ManWriter::see_also(const std::string & m, const int s, const bool first)
+{
+ if (! first)
+ _os << ", ";
+ _os << "\\fB" << m << "\\fR(" << s << ")";
+}
+
+void
+ManWriter::end_see_alsos()
+{
+}
+
+void
ManWriter::start_notes()
{
_os << ".SH NOTES" << endl;
diff --git a/paludis/args/man.hh b/paludis/args/man.hh
index fb79d07..0305390 100644
--- a/paludis/args/man.hh
+++ b/paludis/args/man.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006, 2007, 2009 Ciaran McCreesh
+ * Copyright (c) 2006, 2007, 2009, 2010 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
@@ -91,6 +91,10 @@ namespace paludis
virtual void subsection(const std::string & title) = 0;
virtual void paragraph(const std::string & text) = 0;
+ virtual void start_see_alsos() = 0;
+ virtual void see_also(const std::string &, const int, const bool first) = 0;
+ virtual void end_see_alsos() = 0;
+
///\}
};
@@ -150,6 +154,10 @@ namespace paludis
void section(const std::string & title);
void subsection(const std::string & title);
void paragraph(const std::string & text);
+
+ void start_see_alsos();
+ void see_also(const std::string &, const int, const bool first);
+ void end_see_alsos();
};
/**
@@ -208,6 +216,10 @@ namespace paludis
void section(const std::string & title);
void subsection(const std::string & title);
void paragraph(const std::string & text);
+
+ void start_see_alsos();
+ void see_also(const std::string &, const int, const bool first);
+ void end_see_alsos();
};
}