From: Wolfgang Bangerth Date: Sun, 25 Aug 2013 05:23:15 +0000 (+0000) Subject: Provide a way to also output the file name we are reading when reporting an error. X-Git-Tag: v8.1.0~964 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e3eec6a4fe4e0383b520f8220540b789dcffac5;p=dealii.git Provide a way to also output the file name we are reading when reporting an error. git-svn-id: https://svn.dealii.org/trunk@30476 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/base/parameter_handler.h b/deal.II/include/deal.II/base/parameter_handler.h index 8081470220..e14cc51e98 100644 --- a/deal.II/include/deal.II/base/parameter_handler.h +++ b/deal.II/include/deal.II/base/parameter_handler.h @@ -1575,12 +1575,15 @@ public: virtual ~ParameterHandler (); /** - * Read input from a stream until stream returns eof condition - * or error. + * Read input from a stream until the stream returns the eof condition + * or error. The second argument can be used to denote the name of the file + * (if that's what the input stream represents) we are reading from; this + * is only used when creating output for error messages. * * Return whether the read was successful. */ - virtual bool read_input (std::istream &input); + virtual bool read_input (std::istream &input, + const std::string &filename = "input file"); /** * Read input from a file the name of which is given. The PathSearch @@ -1945,7 +1948,8 @@ private: std::string get_current_full_path (const std::string &name) const; /** - * Scan one line of input. lineno is the number of the line + * Scan one line of input. input_filename and lineno + * are the name of the input file and the current number of the line * presently scanned (for the logs if there are messages). Return * false if line contained stuff that could not be understood, * the uppermost subsection was to be left by an END or @@ -1957,6 +1961,7 @@ private: * caller's variable is not changed. */ bool scan_line (std::string line, + const std::string &input_filename, const unsigned int lineno); friend class MultipleParameterLoop; diff --git a/deal.II/source/base/parameter_handler.cc b/deal.II/source/base/parameter_handler.cc index 21a47df92d..e91986060e 100644 --- a/deal.II/source/base/parameter_handler.cc +++ b/deal.II/source/base/parameter_handler.cc @@ -1313,7 +1313,8 @@ ParameterHandler::get_current_full_path (const std::string &name) const -bool ParameterHandler::read_input (std::istream &input) +bool ParameterHandler::read_input (std::istream &input, + const std::string &filename) { AssertThrow (input, ExcIO()); @@ -1325,7 +1326,7 @@ bool ParameterHandler::read_input (std::istream &input) { ++lineno; getline (input, line); - status &= scan_line (line, lineno); + status &= scan_line (line, filename, lineno); } return status; @@ -1345,7 +1346,7 @@ bool ParameterHandler::read_input (const std::string &filename, std::ifstream input (openname.c_str()); AssertThrow(input, ExcIO()); - return read_input (input); + return read_input (input, filename); } catch (const PathSearch::ExcFileNotFound &) { @@ -1370,7 +1371,7 @@ bool ParameterHandler::read_input_from_string (const char *s) // create an istringstream representation and pass it off // to the other functions doing this work std::istringstream in (s); - return read_input (in); + return read_input (in, "input string"); } @@ -2254,8 +2255,9 @@ ParameterHandler::log_parameters_section (LogStream &out) bool -ParameterHandler::scan_line (std::string line, - const unsigned int lineno) +ParameterHandler::scan_line (std::string line, + const std::string &input_filename, + const unsigned int lineno) { // if there is a comment, delete it if (line.find('#') != std::string::npos) @@ -2291,8 +2293,9 @@ ParameterHandler::scan_line (std::string line, // check whether subsection exists if (!entries->get_child_optional (get_current_full_path(subsection))) { - std::cerr << "Line " << lineno - << ": There is no such subsection to be entered: " + std::cerr << "Line <" << lineno + << "> of file <" << input_filename + << ">: There is no such subsection to be entered: " << demangle(get_current_full_path(subsection)) << std::endl; for (unsigned int i=0; i of file <" << input_filename + << ">: There is no subsection to leave here!" << std::endl; return false; } else @@ -2355,7 +2359,9 @@ ParameterHandler::scan_line (std::string line, = entries->get (get_current_full_path(entry_name) + path_separator + "pattern"); if (!patterns[pattern_index]->match(entry_value)) { - std::cerr << "Line " << lineno << ":" << std::endl + std::cerr << "Line <" << lineno + << "> of file <" << input_filename + << ">:" << std::endl << " The entry value" << std::endl << " " << entry_value << std::endl << " for the entry named" << std::endl @@ -2373,8 +2379,9 @@ ParameterHandler::scan_line (std::string line, } else { - std::cerr << "Line " << lineno - << ": No such entry was declared:" << std::endl + std::cerr << "Line <" << lineno + << "> of file <" << input_filename + << ">: No such entry was declared:" << std::endl << " " << entry_name << std::endl << " of file <" << input_filename + << ">: This line matched nothing known ('set' or 'subsection' missing!?):" << std::endl << " " << line << std::endl; return false; }