]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Provide a way to also output the file name we are reading when reporting an error.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 25 Aug 2013 05:23:15 +0000 (05:23 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Sun, 25 Aug 2013 05:23:15 +0000 (05:23 +0000)
git-svn-id: https://svn.dealii.org/trunk@30476 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/parameter_handler.h
deal.II/source/base/parameter_handler.cc

index 80814702202b91bdcc340ae784ce9140a4a459cf..e14cc51e98f83986d8ef8fd3be1721986a8e2d6d 100644 (file)
@@ -1575,12 +1575,15 @@ public:
   virtual ~ParameterHandler ();
 
   /**
-   * Read input from a stream until stream returns <tt>eof</tt> condition
-   * or error.
+   * Read input from a stream until the stream returns the <tt>eof</tt> 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. <tt>lineno</tt> is the number of the line
+   * Scan one line of input. <tt>input_filename</tt> and <tt>lineno</tt>
+   * are the name of the input file and the current number of the line
    * presently scanned (for the logs if there are messages). Return
    * <tt>false</tt> if line contained stuff that could not be understood,
    * the uppermost subsection was to be left by an <tt>END</tt> 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;
index 21a47df92dff2569e8dc6f5fba4c494b78aeee9c..e91986060eb41416043df5e4a60996db3cbe02ef 100644 (file)
@@ -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<subsection_path.size(); ++i)
             std::cerr << std::setw(i*2+4) << " "
@@ -2313,8 +2316,9 @@ ParameterHandler::scan_line (std::string        line,
     {
       if (subsection_path.size() == 0)
         {
-          std::cerr << "Line " << lineno
-                    << ": There is no subsection to leave here!" << std::endl;
+          std::cerr << "Line <" << lineno
+                    << "> 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<unsigned int> (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
                     << "    <Present subsection:" << std::endl;
           for (unsigned int i=0; i<subsection_path.size(); ++i)
@@ -2387,8 +2394,9 @@ ParameterHandler::scan_line (std::string        line,
     }
 
   // this line matched nothing known
-  std::cerr << "Line " << lineno
-            << ": This line matched nothing known ('set' or 'subsection' missing!?):" << std::endl
+  std::cerr << "Line <" << lineno
+            << "> of file <" << input_filename
+            << ">: This line matched nothing known ('set' or 'subsection' missing!?):" << std::endl
             << "    " << line << std::endl;
   return false;
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.