]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Ensure exactly one newline at the end of each file. 11675/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 3 Feb 2021 20:54:27 +0000 (13:54 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 3 Feb 2021 20:54:27 +0000 (13:54 -0700)
contrib/utilities/indent

index 039619b442746f175c414a3f10bb63bc93d71dc0..0da2355d68e21120b4c88ae784f00de98ef53940 100755 (executable)
@@ -75,3 +75,35 @@ process_changed "tests include source examples cmake/scripts contrib/python-bind
 
 process_changed "tests include source examples cmake/scripts contrib/python-bindings doc" \
   ".*\.(cc|h|cu|cuh|html|dox|txt)" remove_trailing_whitespace
+
+
+#
+# Ensure only a single newline at end of files
+#
+ensure_single_trailing_newline()
+{
+  f=$1
+
+  # Remove newlines at end of file
+  # Check that the current line only contains newlines
+  # If it doesn't match, print it
+  # If it does match and we're not at the end of the file,
+  # append the next line to the current line and repeat the check
+  # If it does match and we're at the end of the file,
+  # remove the line.
+  sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba' $f >$f.tmpi
+
+  # Then add a newline to the end of the file
+  # '$' denotes the end of file
+  # 'a\' appends the following text (which in this case is nothing)
+  # on a new line
+  sed -e '$a\' $f.tmpi >$f.tmp
+
+  diff -q $f $f.tmp >/dev/null || mv $f.tmp $f
+  rm -f $f.tmp $f.tmpi
+}
+export -f ensure_single_trailing_newline
+
+process_changed "tests include source examples cmake/scripts contrib/python-bindings doc" \
+  ".*\.(cc|h|cu|cuh|html|dox|txt)" ensure_single_trailing_newline
+

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.