Add safety check for local --remove-source-files.
[rsync.git] / mkproto.awk
1 #!/usr/bin/awk -f
2
3 BEGIN {
4     while ((getline i < "proto.h") > 0) old_protos = old_protos ? old_protos "\n" i : i
5     close("proto.h")
6     protos = "/* This file is automatically generated with \"make proto\". DO NOT EDIT */\n"
7 }
8
9 inheader {
10     protos = protos "\n" ((inheader = /\)[ \t]*$/ ? 0 : 1) ? $0 : $0 ";")
11     next
12 }
13
14 /^FN_(LOCAL|GLOBAL)_[^(]+\([^,()]+/ {
15     local = /^FN_LOCAL/
16     gsub(/^FN_(LOC|GLOB)AL_|,.*$/, "")
17     sub(/^BOOL\(/, "BOOL ")
18     sub(/^CHAR\(/, "char ")
19     sub(/^INTEGER\(/, "int ")
20     sub(/^STRING\(/, "char *")
21     protos = protos "\n" $0 (local ? "(int module_id);" : "(void);")
22     next
23 }
24
25 /^static|^extern|;/||!/^[A-Za-z][A-Za-z0-9_]* / { next }
26
27 /\(.*\)[ \t]*$/ {
28     protos = protos "\n" $0 ";"
29     next
30 }
31
32 /\(/ {
33     inheader = 1
34     protos = protos "\n" $0
35 }
36
37 END {
38     if (old_protos != protos) print protos > "proto.h"
39     system("touch proto.h-tstamp")
40 }