|
Packit Service |
c5cf8c |
#! /bin/bash
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if hash gindent 2>/dev/null; then
|
|
Packit Service |
c5cf8c |
indent=gindent
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
indent=indent
|
|
Packit Service |
c5cf8c |
fi
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
indent_version=$($indent --version)
|
|
Packit Service |
c5cf8c |
if echo "$indent_version" | grep -q "GNU indent"; then
|
|
Packit Service |
c5cf8c |
:
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
echo "This script requires GNU indent."
|
|
Packit Service |
c5cf8c |
exit
|
|
Packit Service |
c5cf8c |
fi
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
indent_code()
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
file=$1
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
$indent \
|
|
Packit Service |
c5cf8c |
`# Expansion of Kernighan & Ritchie style` \
|
|
Packit Service |
c5cf8c |
--no-blank-lines-after-declarations \
|
|
Packit Service |
c5cf8c |
`# --no-blank-lines-after-procedures` `# Overwritten below` \
|
|
Packit Service |
c5cf8c |
`# --break-before-boolean-operator` `# Overwritten below` \
|
|
Packit Service |
c5cf8c |
--no-blank-lines-after-commas \
|
|
Packit Service |
c5cf8c |
--braces-on-if-line \
|
|
Packit Service |
c5cf8c |
--braces-on-struct-decl-line \
|
|
Packit Service |
c5cf8c |
`# --comment-indentation33` `# Overwritten below` \
|
|
Packit Service |
c5cf8c |
--declaration-comment-column33 \
|
|
Packit Service |
c5cf8c |
--no-comment-delimiters-on-blank-lines \
|
|
Packit Service |
c5cf8c |
--cuddle-else \
|
|
Packit Service |
c5cf8c |
--continuation-indentation4 \
|
|
Packit Service |
c5cf8c |
`# --case-indentation0` `# Overwritten below` \
|
|
Packit Service |
c5cf8c |
`# --else-endif-column33` `# Overwritten below` \
|
|
Packit Service |
c5cf8c |
--space-after-cast \
|
|
Packit Service |
c5cf8c |
--line-comments-indentation0 \
|
|
Packit Service |
c5cf8c |
--declaration-indentation1 \
|
|
Packit Service |
c5cf8c |
--dont-format-first-column-comments \
|
|
Packit Service |
c5cf8c |
--dont-format-comments \
|
|
Packit Service |
c5cf8c |
--honour-newlines \
|
|
Packit Service |
c5cf8c |
--indent-level4 \
|
|
Packit Service |
c5cf8c |
--parameter-indentation0 \
|
|
Packit Service |
c5cf8c |
`# --line-length75` `# Overwritten below` \
|
|
Packit Service |
c5cf8c |
--continue-at-parentheses \
|
|
Packit Service |
c5cf8c |
--no-space-after-function-call-names \
|
|
Packit Service |
c5cf8c |
--no-space-after-parentheses \
|
|
Packit Service |
c5cf8c |
--dont-break-procedure-type \
|
|
Packit Service |
c5cf8c |
--space-after-for \
|
|
Packit Service |
c5cf8c |
--space-after-if \
|
|
Packit Service |
c5cf8c |
--space-after-while \
|
|
Packit Service |
c5cf8c |
`# --dont-star-comments` `# Overwritten below` \
|
|
Packit Service |
c5cf8c |
--leave-optional-blank-lines \
|
|
Packit Service |
c5cf8c |
--dont-space-special-semicolon \
|
|
Packit Service |
c5cf8c |
`# End of K&R expansion` \
|
|
Packit Service |
c5cf8c |
--line-length100 \
|
|
Packit Service |
c5cf8c |
--else-endif-column1 \
|
|
Packit Service |
c5cf8c |
--start-left-side-of-comments \
|
|
Packit Service |
c5cf8c |
--break-after-boolean-operator \
|
|
Packit Service |
c5cf8c |
--comment-indentation1 \
|
|
Packit Service |
c5cf8c |
--no-tabs \
|
|
Packit Service |
c5cf8c |
--blank-lines-after-procedures \
|
|
Packit Service |
c5cf8c |
--leave-optional-blank-lines \
|
|
Packit Service |
c5cf8c |
--braces-after-func-def-line \
|
|
Packit Service |
c5cf8c |
--brace-indent0 \
|
|
Packit Service |
c5cf8c |
--cuddle-do-while \
|
|
Packit Service |
c5cf8c |
--no-space-after-function-call-names \
|
|
Packit Service |
c5cf8c |
--case-indentation4 \
|
|
Packit Service |
c5cf8c |
${file}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
rm -f ${file}~
|
|
Packit Service |
c5cf8c |
cp ${file} /tmp/${USER}.__tmp__ && \
|
|
Packit Service |
c5cf8c |
cat ${file} | sed -e 's/ *$//g' -e 's/( */(/g' -e 's/ *)/)/g' \
|
|
Packit Service |
c5cf8c |
-e 's/if(/if (/g' -e 's/while(/while (/g' -e 's/do{/do {/g' -e 's/}while/} while/g' > \
|
|
Packit Service |
c5cf8c |
/tmp/${USER}.__tmp__ && mv /tmp/${USER}.__tmp__ ${file}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
usage()
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
echo "Usage: $1 [filename | --all] {--recursive} {--debug}"
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Check usage
|
|
Packit Service |
c5cf8c |
if [ -z "$1" ]; then
|
|
Packit Service |
c5cf8c |
usage $0
|
|
Packit Service |
c5cf8c |
exit
|
|
Packit Service |
c5cf8c |
fi
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Make sure the parameters make sense
|
|
Packit Service |
c5cf8c |
all=0
|
|
Packit Service |
c5cf8c |
recursive=0
|
|
Packit Service |
c5cf8c |
got_file=0
|
|
Packit Service |
c5cf8c |
debug=
|
|
Packit Service |
c5cf8c |
ignore=0
|
|
Packit Service |
c5cf8c |
ignore_list="src/mpid/ch3|doc/"
|
|
Packit Service |
c5cf8c |
ignore_list="$ignore_list|src/mpi/romio/include/mpiof.h.in|test/mpi/errors/f77/io/addsize.h.in|test/mpi/errors/f77/io/iooffset.h.in"
|
|
Packit Service |
c5cf8c |
ignore_list="$ignore_list|test/mpi/f77/attr/attraints.h.in|test/mpi/f77/datatype/typeaints.h.in|test/mpi/f77/ext/add1size.h.in"
|
|
Packit Service |
c5cf8c |
ignore_list="$ignore_list|test/mpi/f77/io/ioaint.h.in|test/mpi/f77/io/iodisp.h.in|test/mpi/f77/io/iooffset.h.in"
|
|
Packit Service |
c5cf8c |
ignore_list="$ignore_list|test/mpi/f77/pt2pt/attr1aints.h.in|test/mpi/f77/rma/addsize.h.in|test/mpi/f77/spawn/type1aint.h.in"
|
|
Packit Service |
c5cf8c |
ignore_list="$ignore_list|src/include/mpi.h.in|src/mpi/romio/include/mpio.h.in"
|
|
Packit Service |
c5cf8c |
ignore_list="$ignore_list|src/mpi/romio/adio/include/adioi_errmsg.h"
|
|
Packit Service |
c5cf8c |
for arg in $@; do
|
|
Packit Service |
c5cf8c |
if [ "$ignore" = "1" ] ; then
|
|
Packit Service |
c5cf8c |
ignore_list="$ignore_list|$arg"
|
|
Packit Service |
c5cf8c |
ignore=0
|
|
Packit Service |
c5cf8c |
continue;
|
|
Packit Service |
c5cf8c |
fi
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if [ "$arg" = "--all" ]; then
|
|
Packit Service |
c5cf8c |
all=1
|
|
Packit Service |
c5cf8c |
elif [ "$arg" = "--recursive" ]; then
|
|
Packit Service |
c5cf8c |
recursive=1
|
|
Packit Service |
c5cf8c |
elif [ "$arg" = "--debug" ]; then
|
|
Packit Service |
c5cf8c |
debug="echo"
|
|
Packit Service |
c5cf8c |
elif [ "$arg" = "--ignore" ] ; then
|
|
Packit Service |
c5cf8c |
ignore=1
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
got_file=1
|
|
Packit Service |
c5cf8c |
fi
|
|
Packit Service |
c5cf8c |
done
|
|
Packit Service |
c5cf8c |
if [ "$recursive" = "1" -a "$all" = "0" ]; then
|
|
Packit Service |
c5cf8c |
echo "--recursive cannot be used without --all"
|
|
Packit Service |
c5cf8c |
usage $0
|
|
Packit Service |
c5cf8c |
exit
|
|
Packit Service |
c5cf8c |
fi
|
|
Packit Service |
c5cf8c |
if [ "$got_file" = "1" -a "$all" = "1" ]; then
|
|
Packit Service |
c5cf8c |
echo "--all cannot be used in conjunction with a specific file"
|
|
Packit Service |
c5cf8c |
usage $0
|
|
Packit Service |
c5cf8c |
exit
|
|
Packit Service |
c5cf8c |
fi
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if [ "$recursive" = "1" ]; then
|
|
Packit Service |
c5cf8c |
for i in `git ls-files | egrep '(\.c$|\.h$|\.c\.in$|\.h\.in$|\.cpp$|\.cpp.in$)' | \
|
|
Packit Service |
c5cf8c |
egrep -v "($ignore_list)"` ; do
|
|
Packit Service |
c5cf8c |
${debug} indent_code $i
|
|
Packit Service |
c5cf8c |
${debug} indent_code $i
|
|
Packit Service |
c5cf8c |
done
|
|
Packit Service |
c5cf8c |
elif [ "$all" = "1" ]; then
|
|
Packit Service |
c5cf8c |
for i in `git ls-files | cut -d/ -f1 | uniq | egrep '(\.c$|\.h$|\.c\.in$|\.h\.in$|\.cpp$|\.cpp.in$)' | \
|
|
Packit Service |
c5cf8c |
egrep -v "($ignore_list)"` ; do
|
|
Packit Service |
c5cf8c |
${debug} indent_code $i
|
|
Packit Service |
c5cf8c |
${debug} indent_code $i
|
|
Packit Service |
c5cf8c |
done
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
${debug} indent_code $@
|
|
Packit Service |
c5cf8c |
${debug} indent_code $@
|
|
Packit Service |
c5cf8c |
fi
|