Preparing for release of 3.0.1
[rsync/rsync.git] / mkproto.pl
1 # generate prototypes for rsync
2
3 $old_protos = '';
4 if (open(IN, 'proto.h')) {
5     $old_protos = join('', <IN>);
6     close IN;
7 }
8
9 %FN_MAP = (
10     BOOL => 'BOOL ',
11     CHAR => 'char ',
12     INTEGER => 'int ',
13     STRING => 'char *',
14 );
15
16 $inheader = 0;
17 $protos = qq|/* This file is automatically generated with "make proto". DO NOT EDIT */\n\n|;
18
19 while (<>) {
20     if ($inheader) {
21         if (/[)][ \t]*$/) {
22             $inheader = 0;
23             s/$/;/;
24         }
25         $protos .= $_;
26     } elsif (/^FN_(LOCAL|GLOBAL)_([^(]+)\(([^,()]+)/) {
27         $ret = $FN_MAP{$2};
28         $func = $3;
29         $arg = $1 eq 'LOCAL' ? 'int module_id' : 'void';
30         $protos .= "$ret$func($arg);\n";
31     } elsif (/^static|^extern/ || /[;]/ || !/^[A-Za-z][A-Za-z0-9_]* /) {
32         ;
33     } elsif (/[(].*[)][ \t]*$/) {
34         s/$/;/;
35         $protos .= $_;
36     } elsif (/[(]/) {
37         $inheader = 1;
38         $protos .= $_;
39     }
40 }
41
42 if ($old_protos ne $protos) {
43     open(OUT, '>proto.h') or die $!;
44     print OUT $protos;
45     close OUT;
46 }
47
48 open(OUT, '>proto.h-tstamp') and close OUT;