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