From 0c270e48afc4efa03ebb27a514bca9ef869cc910 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Fri, 9 Nov 2007 17:40:56 +0000 Subject: [PATCH] Let's try using perl for building proto.h. --- mkproto.pl | 51 ++++++++++++++++++++++++++++++++++++++++++++++ prepare-source.mak | 7 +------ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 mkproto.pl diff --git a/mkproto.pl b/mkproto.pl new file mode 100644 index 00000000..f453501b --- /dev/null +++ b/mkproto.pl @@ -0,0 +1,51 @@ +# generate prototypes for rsync +use strict; + +my $old_protos = ''; +if (open(IN, '<', 'proto.h')) { + $old_protos = join('', ); + close IN; +} + +my %FN_MAP = ( + BOOL => 'BOOL ', + CHAR => 'char ', + INTEGER => 'int ', + STRING => 'char *', +); + +my $inheader = 0; +my $protos = qq|/* This file is automatically generated with "make proto". DO NOT EDIT */\n\n|; + +while (<>) { + if ($inheader) { + if (/[)][ \t]*$/) { + $inheader = 0; + s/$/;/; + } + $protos .= $_; + } + + if (/^FN_(LOCAL|GLOBAL)_([^(]+)\(([^,()]+)/) { + my $ret = $FN_MAP{$2}; + my $func = $3; + my $arg = $1 eq 'LOCAL' ? 'int ' : 'void'; + $protos .= "$ret$func($arg);\n"; + } elsif (/^static|^extern/ || /[;]/) { + ; + } elsif (!/^[A-Za-z][A-Za-z0-9_]* /) { + ; + } elsif (/[(].*[)][ \t]*$/) { + s/$/;/; + $protos .= $_; + } elsif (/[(]/) { + $inheader = 1; + $protos .= $_; + } +} + +if ($old_protos ne $protos) { + open(OUT, '>', 'proto.h') or die $!; + print OUT $protos; + close OUT; +} diff --git a/prepare-source.mak b/prepare-source.mak index ef27e1ed..e7ff9958 100644 --- a/prepare-source.mak +++ b/prepare-source.mak @@ -9,12 +9,7 @@ config.h.in: configure.in aclocal.m4 autoheader && touch config.h.in proto.h: *.c lib/compat.c - cat *.c lib/compat.c | awk -f mkproto.awk >proto.h.new - if diff proto.h proto.h.new >/dev/null 2>&1; then \ - rm proto.h.new; \ - else \ - mv proto.h.new proto.h; \ - fi + perl mkproto.pl *.c lib/compat.c man: rsync.1 rsyncd.conf.5 -- 2.34.1