3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
33 * Implements gmx::HelpWriterContext.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36 * \ingroup module_onlinehelp
38 #include "helpwritercontext.h"
44 #include "gromacs/legacyheaders/smalloc.h"
45 #include "gromacs/legacyheaders/wman.h"
47 #include "gromacs/onlinehelp/helpformat.h"
48 #include "gromacs/utility/exceptions.h"
49 #include "gromacs/utility/file.h"
50 #include "gromacs/utility/gmxassert.h"
51 #include "gromacs/utility/programinfo.h"
52 #include "gromacs/utility/stringutil.h"
58 * Make the string uppercase.
60 * \param[in] text Input text.
61 * \returns \p text with all characters transformed to uppercase.
62 * \throws std::bad_alloc if out of memory.
64 std::string toUpperCase(const std::string &text)
66 std::string result(text);
67 transform(result.begin(), result.end(), result.begin(), toupper);
76 /********************************************************************
77 * HelpWriterContext::Impl
81 * Private implementation class for HelpWriterContext.
83 * \ingroup module_onlinehelp
85 class HelpWriterContext::Impl
88 //! Initializes the context with the given output file and format.
89 explicit Impl(File *file, HelpOutputFormat format)
90 : file_(*file), format_(format)
94 //! Output file to which the help is written.
96 //! Output format for the help output.
97 HelpOutputFormat format_;
100 /********************************************************************
104 HelpWriterContext::HelpWriterContext(File *file, HelpOutputFormat format)
105 : impl_(new Impl(file, format))
107 if (format != eHelpOutputFormat_Console)
109 // TODO: Implement once the situation with Redmine issue #969 is more
111 GMX_THROW(NotImplementedError(
112 "This output format is not implemented"));
116 HelpWriterContext::~HelpWriterContext()
120 HelpOutputFormat HelpWriterContext::outputFormat() const
122 return impl_->format_;
125 File &HelpWriterContext::outputFile() const
130 std::string HelpWriterContext::substituteMarkup(const std::string &text) const
132 char *resultStr = check_tty(text.c_str());
133 scoped_ptr_sfree resultGuard(resultStr);
134 return std::string(resultStr);
137 void HelpWriterContext::writeTitle(const std::string &title) const
139 File &file = outputFile();
140 file.writeLine(toUpperCase(title));
144 void HelpWriterContext::writeTextBlock(const std::string &text) const
146 TextLineWrapper wrapper;
147 wrapper.settings().setLineLength(78);
148 const char *program = ProgramInfo::getInstance().programName().c_str();
149 std::string newText = replaceAll(text, "[PROGRAM]", program);
150 outputFile().writeLine(wrapper.wrapToString(substituteMarkup(newText)));