Debian Codegraph @

scripts/clang-format-all

raw
1 #!/bin/sh
2
3 #
4 # KIM-API: An API for interatomic models
5 # Copyright (c) 2013--2022, Regents of the University of Minnesota.
6 # All rights reserved.
7 #
8 # Contributors:
9 # Ryan S. Elliott
10 #
11 # SPDX-License-Identifier: LGPL-2.1-or-later
12 #
13 # This library is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU Lesser General Public
15 # License as published by the Free Software Foundation; either
16 # version 2.1 of the License, or (at your option) any later version.
17 #
18 # This library is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # Lesser General Public License for more details.
22 #
23 # You should have received a copy of the GNU Lesser General Public License
24 # along with this library; if not, write to the Free Software Foundation,
25 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #
27
28 #
29 # Release: This file is part of the kim-api.git repository.
30 #
31
32
33 # filter file list # NOTE: keep in sync with verion in git-hooks/pre-commit
34 filter_file_list () {
35 local file_list="$1"
36 local ignore_file="`git rev-parse --show-toplevel`/.format-ignore"
37 files_to_check_format=""
38
39 for file in ${file_list}; do
40 local keep=`printf ${file} | sed -e 's/^.*\.hpp$//' \
41 -e 's/^.*\.hpp\.in$//' \
42 -e 's/^.*\.cpp$//' \
43 -e 's/^.*\.cpp\.in$//' \
44 -e 's/^.*\.inc$//' \
45 -e 's/^.*\.inc\.in$//' \
46 -e 's/^.*\.h$//' \
47 -e 's/^.*\.h\.in$//' \
48 -e 's/^.*\.c$//' \
49 -e 's/^.*\.c\.in$//'`
50 if test -f "${ignore_file}"; then
51 if test `grep -c "^${file}$" "${ignore_file}"` -gt 0; then
52 # ignore
53 printf "File '${file}' is in format-ignore file: ignoring.\n"
54 keep=no
55 fi
56 fi
57
58 if test x"${keep}" = x""; then
59 files_to_check_format="${files_to_check_format} ${file}"
60 fi
61 done
62 }
63
64 # goto the top level repo directory
65 if THE_GIT_DIR="`git rev-parse --show-toplevel 2> /dev/null`"; then
66 cd "${THE_GIT_DIR}"
67 else
68 printf "Not in the git repo. Exiting...\n"
69 exit 1
70 fi
71
72 files=`find . -name "*.hpp" \
73 -o -name "*.hpp.in" \
74 -o -name "*.cpp" \
75 -o -name "*.cpp.in" \
76 -o -name "*.inc" \
77 -o -name "*.inc.in" \
78 -o -name "*.h" \
79 -o -name "*.h.in" \
80 -o -name "*.c" \
81 -o -name "*.c.in" | \
82 sed -e 's|^\./||'`
83
84 printf "Executing clang-format on all c/c++ files in directory ${PWD}.\n"
85
86 files_to_check_format=""
87 filter_file_list "${files}"
88
89 clang-format -style=file -i ${files_to_check_format}