mkproto.pl 974 B

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