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