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
|
#!/bin/sh
set -e
DIR="$1"
shift
DIR="${*:+${DIR:-.}/}"
mkdir -p "protos"
for f in ${*:--}
do
h="${f%.c}.h"
(cd "$DIR";
# functions
grep -Eh '^[a-zA-Z_]+.*[a-zA-Z_][a-zA-Z0-9_]*\(.*\)$' "$f"|
grep -v '^static'|
grep -Ev '^void [a-z_]+_command\('|
grep -Ev '^struct session \*[a-z_]+_command\('|
sed 's/.*/extern &;/'
# variables
grep -Eh '^[a-zA-Z_][][a-zA-Z0-9_*, ]*[=;]' "$f"|
grep -v '^static'|
grep -v '^extern'|
grep -v '^typedef'|
sed 's/ *[=;].*//'|
sed 's/.*/extern &;/'
# function pointers
grep -Eh '^[a-zA-Z_]+ \(\*[a-zA-Z_]+\)\([][a-zA-Z0-9_*,. ]*\) *[=;]' "$f"|
grep -v '^static'|
grep -v '^extern'|
grep -v '^typedef'|
sed 's/ *[=;].*//'|
sed 's/.*/extern &;/'
) >"protos/$h"
done
|