Skip to content

Commit 7448609

Browse files
author
mohdsaid497566
committed
comments removal
1 parent 393d69b commit 7448609

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

.github/workflows/pmd.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,50 @@ jobs:
2929
- name: Running PMD
3030
run: |
3131
alias pmd="$HOME/pmd/bin/pmd"
32-
pmd cpd -l fortran pr/src/* > ../pmd-fort.txt
32+
33+
SOURCE_DIR="${1:-pr/src}"
34+
total_files=$(find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) | wc -l)
35+
processed=0
36+
37+
find "$SOURCE_DIR" -type f \( -name "*.f" -o -name "*.f90" -o -name "*.for" -o -name "*.fpp" -o -name "*.F" -o -name "*.F90" \) -print0 |
38+
while IFS= read -r -d $'\0' file; do
39+
processed=$((processed + 1))
40+
echo -e "[$processed/$total_files] Processing ${file}..."
41+
42+
# Create a temporary file with same permissions as original
43+
TMP_FILE=$(mktemp)
44+
if [ $? -ne 0 ]; then
45+
echo -e "Failed to create temporary file for $file, skipping"
46+
continue
47+
fi
48+
49+
# Copy permissions from original file
50+
chmod --reference="$file" "$TMP_FILE"
51+
52+
# More comprehensive sed command to handle different Fortran comment styles:
53+
# 1. Replace lines that are entirely comments with an empty line:
54+
# - Lines starting with '!' (free form comments)
55+
# - Lines starting with 'c', 'C', '*', 'd', 'D' in column 1 (fixed form comments)
56+
# 2. Remove end-of-line comments (anything after '!' that isn't in a string)
57+
# 3. Preserve strings containing '!' characters
58+
sed -E \
59+
-e '/^\s*!/s/.*//' \
60+
-e '/^[cC*dD]/s/.*//' \
61+
-e '/^[ \t]*[cC*dD]/s/.*//' \
62+
-e 's/([^"'\'']*("[^"]*"[^"'\'']*|'\''[^'\'']*'\''[^"'\'']*)*[^"'\'']*)[!].*$/\1/' \
63+
"$file" > "$TMP_FILE"
64+
65+
# Check if file was actually modified before replacing
66+
if cmp -s "$file" "$TMP_FILE"; then
67+
echo -e "No changes needed for $file"
68+
rm "$TMP_FILE"
69+
else
70+
# Overwrite the original file with the processed content
71+
mv "$TMP_FILE" "$file"
72+
echo -e "Successfully processed $file"
73+
fi
74+
done
75+
pmd cpd -l fortran /* > ../pmd-fort.txt
3376
pmd cpd -l python pr/toolchain/* > ../pmd-py.txt
3477
3578
- name: Display PMD Reports

0 commit comments

Comments
 (0)