Skip to content

Commit 378a24d

Browse files
committed
add useful script
1 parent cc16cd2 commit 378a24d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

misc/length-subroutines.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Use gawk if available, otherwise fall back to awk
4+
if command -v gawk > /dev/null; then
5+
AWK_CMD="gawk"
6+
IGNORECASE_BLOCK='BEGIN { IGNORECASE = 1 }'
7+
else
8+
AWK_CMD="awk"
9+
IGNORECASE_BLOCK=''
10+
echo "Warning: gawk not found. Case-insensitive matching may not work as expected." >&2
11+
fi
12+
13+
find . -type f \( -name "*.f90" -o -name "*.fpp" \) | while read file; do
14+
"$AWK_CMD" "
15+
$IGNORECASE_BLOCK
16+
/^[ \t]*((pure|elemental|impure)[ \t]+)*subroutine[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\(/ {
17+
in_sub = 1
18+
match(\$0, /subroutine[ \t]+([a-zA-Z_][a-zA-Z0-9_]*)/, arr)
19+
sub_name = arr[1]
20+
start_line = NR
21+
next
22+
}
23+
/^[ \t]*end[ \t]+subroutine[ \t]*([a-zA-Z_][a-zA-Z0-9_]*)?[ \t]*\$/ && in_sub {
24+
end_line = NR
25+
print (end_line - start_line + 1) \"\t\" FILENAME \": \" sub_name
26+
in_sub = 0
27+
}
28+
" "$file"
29+
done | sort -nr | awk -F'\t' '{print $2 " : " $1 " lines"}' | head -20

0 commit comments

Comments
 (0)