#!/bin/bash12# This file is part of t8code.3# t8code is a C library to manage a collection (a forest) of multiple4# connected adaptive space-trees of general element classes in parallel.5#6# Copyright (C) 2025 the developers7#8# t8code is free software; you can redistribute it and/or modify9# it under the terms of the GNU General Public License as published by10# the Free Software Foundation; either version 2 of the License, or11# (at your option) any later version.12#13# t8code is distributed in the hope that it will be useful,14# but WITHOUT ANY WARRANTY; without even the implied warranty of15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16# GNU General Public License for more details.17#18# You should have received a copy of the GNU General Public License19# along with t8code; if not, write to the Free Software Foundation, Inc.,20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.2122if [ "$#" -ne 1 ]; then23echo "Usage: $0 <file_path>"24exit 125fi2627file_path=$12829echo "$file_path"3031if [[ "$file_path" -ef "src/t8_with_macro_error.h" ]]32then33echo The file \"src/t8_with_macro_error.h\" will be ignored by the check_macros.sh script.34exit 035fi3637#38# This script searches for lines containing a macro definition in the style of '#ifdef T8_ENABLE_'39# in the specified file and processes each matching line.40# It uses 'grep' to find all occurrences of '#ifdef T8_ENABLE_' in the file located41# at the path stored in the variable 'file_path'. The '-n' option with 'grep'42# ensures that the line numbers of the matching lines are included in the output.43# The output of 'grep' is then piped into a 'while' loop, which reads each line44# and splits it into the line number and the line content using ':' as the delimiter.45# Variables:46# - file_path: The path to the file to be searched.47# - line_number: The line number where the macro definition is found.48# - line: The content of the line where the macro definition is found.49#5051found_macros=FALSE5253# Check for #ifdef T8_ENABLE54while IFS=: read -r line_number line; do55macro_name=$(echo "$line" | grep -o 'T8_ENABLE_[^ ]*')56echo "Incorrect macro found in $file_path on line $line_number: $macro_name. Please use '#if T8_ENABLE_' instead."57found_macros=TRUE58done < <(grep -n '#ifdef T8_ENABLE_' "$file_path")5960# Check for #ifdef T8_WITH or #if T8_WITH61while IFS=: read -r line_number line; do62macro_name=$(echo "$line" | grep -o 'T8_WITH_[^ ]*')63echo "Incorrect macro found in $file_path on line $line_number: $macro_name. Please use '#if T8_ENABLE_' instead."64found_macros=TRUE65done < <(grep -E -n '#if T8_WITH_|#ifdef T8_WITH' "$file_path")6667if [ "$found_macros" = "TRUE" ]; then68exit 169else70exit 071fi727374