File: make_protos

package info (click to toggle)
kbtin 2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,856 kB
  • sloc: ansic: 18,627; perl: 179; sh: 88; makefile: 17
file content (37 lines) | stat: -rwxr-xr-x 794 bytes parent folder | download | duplicates (2)
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