diff --git a/eo/src/utils/make_help.cpp b/eo/src/utils/make_help.cpp new file mode 100644 index 00000000..ecddbd17 --- /dev/null +++ b/eo/src/utils/make_help.cpp @@ -0,0 +1,62 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// make_help.h +// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001 +/* + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact: todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mkeijzer@dhi.dk + */ +//----------------------------------------------------------------------------- +#include +#include + +/** Generation of the status file, and output of the help message if needed + * + * MUST be called after ALL parameters have been read in order to list them + * + * Warning: this is a plain .cpp file and shoudl NOT be included anywhere, + * but compiled separately and stored in a library. + * + * It is declared in all make_xxx.h files in representation-dependent dirs + * but it is NOT representation-dependent itself - that's why it's in utils + */ +void make_help(eoParser & _parser) +{ + // name of the "status" file where all actual parameter values will be saved + string str_status = _parser.ProgramName() + ".status"; // default value + eoValueParam& statusParam = _parser.createParam(str_status, "status","Status file",'\0', "Persistence" ); + + // dump status file BEFORE help, so the user gets a chance to use it: + // it's probably the case where she/he needs it most!!! + // Only help parameter will not be in status file - but who cares??? + if (statusParam.value() != "") + { + ofstream os(statusParam.value().c_str()); + os << _parser; // and you can use that file as parameter file + } + // do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED + // i.e. in case you need parameters somewhere else, postpone these + if (_parser.userNeedsHelp()) + { + _parser.printHelp(cout); + cout << "You can use an edited copy of file " << statusParam.value() + << " as parameter file" << endl; + exit(1); + } +}