From abe57f09c0550b178cfa20b62ba52fe5e19d3955 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Thu, 5 Apr 2018 11:10:48 +0200 Subject: [PATCH] Make using astyle for indenting a bit easier --- contrib/utilities/indent | 47 +++++++++++++++++-------------- contrib/utilities/setup_astyle.sh | 20 +++++++++++++ 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/contrib/utilities/indent b/contrib/utilities/indent index 64d2f0c98a..30151d0b54 100755 --- a/contrib/utilities/indent +++ b/contrib/utilities/indent @@ -30,6 +30,11 @@ # from a build directory. # +# Add the location 'setup_astyle.sh' installs astyle to to the local PATH. +THIS_PATH="$(dirname $0)" # relative +THIS_PATH="$( cd $THIS_PATH && pwd )" # absolutized and normalized +export PATH=$THIS_PATH/programs/astyle/build/gcc/bin/:$PATH + if test ! -d source -o ! -d include -o ! -d examples ; then echo "*** This script must be run from the top-level directory of deal.II." exit 1 @@ -40,16 +45,17 @@ if test ! -f contrib/styles/astyle.rc ; then exit 1 fi -if test -z "`which astyle`" ; then +if test -z "$(command -v astyle)" ; then echo "*** No astyle program found." echo "***" echo "*** You can download astyle from http://astyle.sourceforge.net/" echo "*** Note that you will need exactly version 2.04 (no newer or" echo "*** older version will yield the correct indentation)." + echo "*** You can run the 'setup_astyle.sh' script for that." exit 1 fi -if test "`astyle --version 2>&1`" != "Artistic Style Version 2.04" ; then +if test "$(astyle --version 2>&1)" != "Artistic Style Version 2.04" ; then echo "*** Found a version of astyle different than the required version 2.04." exit 1 fi @@ -58,41 +64,40 @@ fi # collect all header and source files and process them in batches of 50 files # with up to 10 in parallel -find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print | xargs -n 50 -P 10 astyle --options=contrib/styles/astyle.rc +find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 50 -P 10 astyle --options=contrib/styles/astyle.rc # use the same process to set file permissions for all source files -find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print | xargs -n 50 -P 10 chmod 644 +find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 50 -P 10 chmod 644 -# convert dos formatted files to unix file format by stripping out +# convert dos formatted files to unix file format by stripping out # carriage returns (15=0x0D): dos_to_unix() { f=$1 - tr -d '\015' <$f >$f.tmp - diff -q $f $f.tmp >/dev/null || mv $f.tmp $f - rm -f $f.tmp + tr -d '\015' <"$f" >"$f.tmp" + diff -q "$f" "$f.tmp" >/dev/null || mv "$f.tmp" "$f" + rm -f "$f.tmp" } export -f dos_to_unix -find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print | xargs -n 1 -P 10 -I {} bash -c 'dos_to_unix "$@"' _ {} +find tests include source examples \( -name '*.cc' -o -name '*.h' -o -name '*.cu' -o -name '*.cuh' \) -print0 | xargs -0 -n 1 -P 10 -I {} bash -c 'dos_to_unix "$@"' _ {} # format .inst.in files. We need to replace \{ and \} because it confuses # astyle. format_inst() { f=$1 - cp $f $f.tmp - sed -i.orig 's#\\{#{ //#g' $f.tmp - sed -i.orig 's#\\}#} //#g' $f.tmp - astyle --options=none --quiet $f.tmp - sed -i.orig 's#{ //#\\{#g' $f.tmp - sed -i.orig 's#} //#\\}#g' $f.tmp - if ! diff -q $f $f.tmp >/dev/null + cp "$f" "$f.tmp" + sed -i.orig 's#\\{#{ //#g' "$f.tmp" + sed -i.orig 's#\\}#} //#g' "$f.tmp" + astyle --options=none --quiet "$f.tmp" + sed -i.orig 's#{ //#\\{#g' "$f.tmp" + sed -i.orig 's#} //#\\}#g' "$f.tmp" + if ! diff -q "$f" "$f.tmp" >/dev/null then - cp $f.tmp $f + cp "$f.tmp" "$f" fi - rm $f.tmp $f.tmp.orig + rm "$f.tmp" "$f.tmp.orig" } +export -f format_inst -for i in `find source -name '*.inst.in'` ; do - format_inst $i -done +find source -name '*.inst.in' -exec bash -c 'format_inst "$@"' bash {} + diff --git a/contrib/utilities/setup_astyle.sh b/contrib/utilities/setup_astyle.sh index fdb23e6628..1a5dda842f 100755 --- a/contrib/utilities/setup_astyle.sh +++ b/contrib/utilities/setup_astyle.sh @@ -1,4 +1,24 @@ #!/bin/sh +## --------------------------------------------------------------------- +## +## Copyright (C) 2018 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. +## +## --------------------------------------------------------------------- + +# +# This script downloads and installs astyle-2.04 in programs/astyle/build/gcc. +# The installed binary is used in the 'indent' script in case astyle is +# installed by this script. +# PRG=$PWD/programs -- 2.39.5