-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.sh
executable file
·42 lines (36 loc) · 994 Bytes
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# Set output directory
output_dir="scripts/output"
mkdir -p "$output_dir"
# Determine the directory to search
if [ $# == 1 ]; then
dir="$1"
else
dir="."
fi
# Function to extract and format functions
extract_functions() {
local dir="$1"
local prevdir=""
find "$dir" -type f -name "*.c" | while read -r file; do
if [ -f "$file" ]; then
dirname=$(dirname "$file")
dirname=$(basename "$dirname")
filename=$(basename "$file")
functions=$(grep -oE '[a-z].* .*[a-z].*\([^)]*\)' "$file" | grep -v "static" | tr "\n" ";" | sed 's/;/;\n/g')
if [ -n "$functions" ]; then
if [ "$dirname" != "$prevdir" ]; then
printf "%.30s\n" "// $dirname ------------------------------------"
prevdir="$dirname"
echo
fi
echo "/* $filename */"
echo "$functions"
echo
fi
fi
done
}
# Extract functions and save to output file
extract_functions "$dir" >"$output_dir/fncts"
echo "Function extraction complete. Output saved to $output_dir/fncts"