]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Allow parameter files to end with a '\'.
authorDavid Wells <wellsd2@rpi.edu>
Thu, 28 Jan 2016 13:44:48 +0000 (08:44 -0500)
committerDavid Wells <wellsd2@rpi.edu>
Thu, 28 Jan 2016 13:44:48 +0000 (08:44 -0500)
source/base/parameter_handler.cc
tests/bits/parameter_handler_backslash_08.cc [new file with mode: 0644]
tests/bits/parameter_handler_backslash_08.output [new file with mode: 0644]
tests/bits/prm/parameter_handler_backslash_08.prm [new file with mode: 0644]

index f761081dd5c30ca06f3e43a58e5c0b03d4157278..28ecc77f9e480f8869332846a28130317ea34366 100644 (file)
@@ -1381,6 +1381,13 @@ bool ParameterHandler::read_input (std::istream &input,
         }
     }
 
+  // While it does not make much sense for anyone to actually do this, allow
+  // the last line to end in a backslash.
+  if (is_concatenated)
+    {
+      status &= scan_line (fully_concatenated_line, filename, current_line_n);
+    }
+
   if (status && (saved_path != subsection_path))
     {
       std::cerr << "Unbalanced 'subsection'/'end' in file <" << filename
diff --git a/tests/bits/parameter_handler_backslash_08.cc b/tests/bits/parameter_handler_backslash_08.cc
new file mode 100644 (file)
index 0000000..34dbeae
--- /dev/null
@@ -0,0 +1,62 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, 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.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+
+/*
+ * Test that the last line in a parameter file can end in a '\' with no ill
+ * effect.
+ */
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  for (unsigned int i = 0; i < 2; ++i)
+    {
+      ParameterHandler prm;
+      prm.enter_subsection ("Testing");
+      prm.declare_entry ("value", "value", Patterns::Anything());
+      prm.leave_subsection ();
+
+      // test both relevant read_input functions
+      if (i == 0)
+        {
+          prm.read_input(SOURCE_DIR "/prm/parameter_handler_backslash_08.prm");
+        }
+      else
+        {
+          std::ifstream input_stream
+          (SOURCE_DIR "/prm/parameter_handler_backslash_08.prm");
+          prm.read_input(input_stream);
+        }
+
+      std::string list;
+      prm.enter_subsection ("Testing");
+      list = prm.get ("value");
+      prm.leave_subsection ();
+
+      deallog << list << std::endl;
+    }
+
+  return 0;
+}
diff --git a/tests/bits/parameter_handler_backslash_08.output b/tests/bits/parameter_handler_backslash_08.output
new file mode 100644 (file)
index 0000000..d56fbce
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::value
+DEAL::value
diff --git a/tests/bits/prm/parameter_handler_backslash_08.prm b/tests/bits/prm/parameter_handler_backslash_08.prm
new file mode 100644 (file)
index 0000000..d9d7ec8
--- /dev/null
@@ -0,0 +1,5 @@
+# Allow the last line to end with a '\'.
+#---------------------------------------
+subsection Testing
+  set value = value
+end\

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.