Frobby  0.9.1
HelpAction.cpp
Go to the documentation of this file.
1 /* Frobby: Software for monomial ideal computations.
2  Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see http://www.gnu.org/licenses/.
16 */
17 #include "stdinc.h"
18 #include "HelpAction.h"
19 
20 #include "Parameter.h"
21 #include "IOHandler.h"
22 #include "DataType.h"
23 #include "error.h"
24 #include "display.h"
25 #include "FrobbyStringStream.h"
26 #include "ColumnPrinter.h"
27 
28 #include <algorithm>
29 
31  Action
32 (staticGetName(),
33  "Display this help screen.",
34  "Typing `frobby help' displays a list of the available actions.\n"
35  "Typing `frobby help ACTION' displays a detailed description of that "
36  "action.\n\n"
37  "As an example, typing `frobby help irrdecom' will yield detailed "
38  "information\n"
39  "about the irrdecom action.",
40  true) {
41 }
42 
43 void HelpAction::obtainParameters(vector<Parameter*>& parameters) {
44 }
45 
46 void HelpAction::processNonParameter(const char* str) {
47  _topic = str;
48 }
49 
50 namespace {
51  // Helper function for displayActionHelp().
52  bool paramCmp(Parameter* a, Parameter* b) {
53  ASSERT(a != 0);
54  ASSERT(b != 0);
55  return string(a->getName()) < b->getName();
56  }
57 }
58 
61  out << "Displaying information on action: " << action.getName() << "\n\n";
62  out << action.getDescription() << "\n";
63 
64  vector<Parameter*> parameters;
65  action.obtainParameters(parameters);
66  sort(parameters.begin(), parameters.end(), paramCmp);
67 
68  display(out);
69 
70  if (!parameters.empty()) {
71  fprintf(stderr, "\nThe parameters accepted by %s are as follows.\n",
72  action.getName());
73 
74  typedef vector<Parameter*>::const_iterator cit;
75  for (cit it = parameters.begin(); it != parameters.end(); ++it) {
76  string defaultValue = (*it)->getValueAsString();
77  fprintf(stderr, "\n -%s %s (default is %s)\n",
78  (*it)->getName().c_str(),
79  (*it)->getArgumentType().c_str(),
80  (*it)->getValueAsString().c_str());
81  display((*it)->getDescription(), " ");
82  }
83  }
84 }
85 
87  display
88  ("Displaying information on topic: io\n"
89  "\n"
90  "Frobby understands several file formats. These are not documented, "
91  "but they are simple enough that seeing an example should be enough "
92  "to figure them out. Getting an example is as simple as making "
93  "Frobby produce output in that format. "
94  "\n\n"
95  "It is true of all the formats that white-space is insignificant, "
96  "but other than that Frobby is quite fuzzy about how the input "
97  "must look. E.g. a Macaulay 2 file containing a monomial ideal "
98  "must start with \"R = \", so writing \"r = \" with a lower-case r "
99  "is an error. To help with this, Frobby tries to say what is wrong "
100  "if there is an error."
101  "\n\n"
102  "If no input format is specified, Frobby will guess at the format, "
103  "and it will guess correctly if there are no errors in the input. "
104  "If no output format is specified, Frobby will use the same format "
105  "for output as for input. If you want to force Frobby to use a "
106  "specific format, use the -iformat and -oformat options. Using "
107  "these with the transform action allows translation between formats. "
108  "\n\n"
109  "The formats available in Frobby and the types of data they "
110  "support are as follows. "
111  "\n");
112 
113  vector<string> names;
114  getIOHandlerNames(names);
115  for (vector<string>::const_iterator name = names.begin();
116  name != names.end(); ++name) {
117  auto_ptr<IOHandler> handler = createIOHandler(*name);
118  ASSERT(handler.get() != 0);
119 
120  fprintf(stderr, "\n* The format %s: %s\n",
121  handler->getName(),
122  handler->getDescription());
123 
124 
125  vector<const DataType*> types = DataType::getTypes();
126  for (vector<const DataType*>::const_iterator typeIt = types.begin();
127  typeIt != types.end(); ++typeIt) {
128  const DataType& type = **typeIt;
129 
130  bool input = handler->supportsInput(type);
131  bool output = handler->supportsOutput(type);
132 
133  const char* formatStr = "";
134  if (input && output)
135  formatStr = " - supports input and output of %s.\n";
136  else if (input)
137  formatStr = " - supports input of %s.\n";
138  else if (output)
139  formatStr = " - supports output of %s.\n";
140 
141  fprintf(stderr, formatStr, type.getName());
142  }
143  }
144 }
145 
147  if (_topic != "") {
148  if (_topic == "io")
149  displayIOHelp();
150  else
152 
153  return;
154  }
155 
156  FrobbyStringStream out;
157 
158  out << "Frobby version " << constants::version
159  << " Copyright (C) 2007 Bjarke Hammersholt Roune\n";
160  out <<
161  "Frobby performs a number of computations related to monomial "
162  "ideals.\nYou run it by typing `frobby ACTION', where ACTION is "
163  "one of the following. "
164  "\n\n";
165 
166  ColumnPrinter printer;
167  printer.addColumn(false, " ");
168  printer.addColumn(true, " - ");
169 
170  vector<string> names;
171  Action::getActionNames(names);
172  for (vector<string>::const_iterator it = names.begin();
173  it != names.end(); ++it) {
174  auto_ptr<Action> action(Action::createActionWithPrefix(*it));
175  if (action->displayAction()) {
176  printer[0] << action->getName() << '\n';
177  printer[1] << action->getShortDescription() << '\n';
178  }
179  }
180  printer.print(out);
181 
182  out <<
183  "\nType 'frobby help ACTION' to get more details on a specific action.\n"
184  "Note that all input and output is done via the standard streams.\n"
185  "Type 'frobby help io' for more information on input and output formats.\n"
186  "See www.broune.com for further information and new versions of Frobby.\n"
187  "\n"
188  "Frobby is free software and you are welcome to redistribute it under certain "
189  "conditions. Frobby comes with ABSOLUTELY NO WARRANTY. See the GNU General "
190  "Public License version 2.0 in the file COPYING for details.\n";
191  display(out);
192 }
193 
195  return "help";
196 }
197 
199  return false;
200 }
display
void display(const string &msg, const string &prepend)
Display msg to standard error with automatic line breaking.
Definition: display.cpp:131
DataType.h
HelpAction::displayAction
virtual bool displayAction() const
Returns whether this action should be shown to the user by the help action.
Definition: HelpAction.cpp:198
Action::getName
const char * getName() const
Definition: Action.cpp:113
stdinc.h
IOHandler.h
HelpAction::staticGetName
static const char * staticGetName()
Definition: HelpAction.cpp:194
Action::getActionNames
static void getActionNames(vector< string > &names)
Definition: Action.cpp:105
HelpAction.h
Action::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
Parameter
Definition: Parameter.h:24
Action
Definition: Action.h:25
ColumnPrinter::addColumn
void addColumn(bool flushLeft=true, const string &prefix=" ", const string &suffix="")
Definition: ColumnPrinter.cpp:51
ColumnPrinter
Definition: ColumnPrinter.h:27
FrobbyStringStream.h
HelpAction::displayIOHelp
void displayIOHelp()
Definition: HelpAction.cpp:86
Parameter::getName
const string & getName() const
Definition: Parameter.h:29
DataType::getTypes
static vector< const DataType * > getTypes()
Returns a vector of all types except null.
Definition: DataType.cpp:64
HelpAction::HelpAction
HelpAction()
Definition: HelpAction.cpp:30
HelpAction::perform
virtual void perform()
Definition: HelpAction.cpp:146
HelpAction::_topic
string _topic
Definition: HelpAction.h:40
error.h
HelpAction::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: HelpAction.cpp:43
getIOHandlerNames
void getIOHandlerNames(vector< string > &names)
Add the name of each fomat to names.
Definition: IOHandler.cpp:156
Action::getDescription
const char * getDescription() const
Definition: Action.cpp:121
ColumnPrinter.h
Parameter.h
ColumnPrinter::print
void print(ostream &out) const
Definition: ColumnPrinter.cpp:70
createIOHandler
auto_ptr< IOHandler > createIOHandler(const string &prefix)
Returns an IOHandler for the format whose name has the given prefix.
Definition: IOHandler.cpp:145
display.h
HelpAction::displayActionHelp
void displayActionHelp(Action &action)
Definition: HelpAction.cpp:59
DataType::getName
const char * getName() const
Returns the name of the structure.
Definition: DataType.cpp:24
Action::createActionWithPrefix
static auto_ptr< Action > createActionWithPrefix(const string &prefix)
Definition: Action.cpp:109
FrobbyStringStream
A replacement for stringstream.
Definition: FrobbyStringStream.h:26
constants::version
const char *const version
Definition: stdinc.cpp:20
ASSERT
#define ASSERT(X)
Definition: stdinc.h:86
DataType
The intention of this class is to describe the different kinds of mathematical structures that Frobby...
Definition: DataType.h:29
HelpAction::processNonParameter
virtual void processNonParameter(const char *str)
Definition: HelpAction.cpp:46