Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/scripts/check_macros.sh
900 views
1
#!/bin/bash
2
3
# This file is part of t8code.
4
# t8code is a C library to manage a collection (a forest) of multiple
5
# connected adaptive space-trees of general element classes in parallel.
6
#
7
# Copyright (C) 2025 the developers
8
#
9
# t8code is free software; you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 2 of the License, or
12
# (at your option) any later version.
13
#
14
# t8code is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
18
#
19
# You should have received a copy of the GNU General Public License
20
# along with t8code; if not, write to the Free Software Foundation, Inc.,
21
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23
if [ "$#" -ne 1 ]; then
24
echo "Usage: $0 <file_path>"
25
exit 1
26
fi
27
28
file_path=$1
29
30
echo "$file_path"
31
32
if [[ "$file_path" -ef "src/t8_with_macro_error.h" ]]
33
then
34
echo The file \"src/t8_with_macro_error.h\" will be ignored by the check_macros.sh script.
35
exit 0
36
fi
37
38
#
39
# This script searches for lines containing a macro definition in the style of '#ifdef T8_ENABLE_'
40
# in the specified file and processes each matching line.
41
# It uses 'grep' to find all occurrences of '#ifdef T8_ENABLE_' in the file located
42
# at the path stored in the variable 'file_path'. The '-n' option with 'grep'
43
# ensures that the line numbers of the matching lines are included in the output.
44
# The output of 'grep' is then piped into a 'while' loop, which reads each line
45
# and splits it into the line number and the line content using ':' as the delimiter.
46
# Variables:
47
# - file_path: The path to the file to be searched.
48
# - line_number: The line number where the macro definition is found.
49
# - line: The content of the line where the macro definition is found.
50
#
51
52
found_macros=FALSE
53
54
# Check for #ifdef T8_ENABLE
55
while IFS=: read -r line_number line; do
56
macro_name=$(echo "$line" | grep -o 'T8_ENABLE_[^ ]*')
57
echo "Incorrect macro found in $file_path on line $line_number: $macro_name. Please use '#if T8_ENABLE_' instead."
58
found_macros=TRUE
59
done < <(grep -n '#ifdef T8_ENABLE_' "$file_path")
60
61
# Check for #ifdef T8_WITH or #if T8_WITH
62
while IFS=: read -r line_number line; do
63
macro_name=$(echo "$line" | grep -o 'T8_WITH_[^ ]*')
64
echo "Incorrect macro found in $file_path on line $line_number: $macro_name. Please use '#if T8_ENABLE_' instead."
65
found_macros=TRUE
66
done < <(grep -E -n '#if T8_WITH_|#ifdef T8_WITH' "$file_path")
67
68
if [ "$found_macros" = "TRUE" ]; then
69
exit 1
70
else
71
exit 0
72
fi
73
74