verify-synopsis.pl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. my @files = @ARGV;
  26. my $cfile = "test.c";
  27. if($files[0] eq "-h") {
  28. print "Usage: verify-synopsis [man pages]\n";
  29. exit;
  30. }
  31. sub testcompile {
  32. my $rc = system("gcc -c test.c -DCURL_DISABLE_TYPECHECK -DCURL_ALLOW_OLD_MULTI_SOCKET -I include") >> 8;
  33. return $rc;
  34. }
  35. sub extract {
  36. my($f) = @_;
  37. my $syn = 0;
  38. my $l = 0;
  39. my $iline = 0;
  40. open(F, "<$f");
  41. open(O, ">$cfile");
  42. while(<F>) {
  43. $iline++;
  44. if(/^# SYNOPSIS/) {
  45. $syn = 1
  46. }
  47. elsif($syn == 1) {
  48. if(/^\~\~\~/) {
  49. $syn++;
  50. print O "#line $iline \"$f\"\n";
  51. }
  52. }
  53. elsif($syn == 2) {
  54. if(/^\~\~\~/) {
  55. last;
  56. }
  57. # turn the vararg argument into vararg
  58. $_ =~ s/, parameter\)\;/, ...);/;
  59. print O $_;
  60. $l++;
  61. }
  62. }
  63. close(F);
  64. close(O);
  65. if($syn < 2) {
  66. print STDERR "Found no synopsis in $f\n";
  67. return 1;
  68. }
  69. return 0;
  70. }
  71. my $error;
  72. for my $m (@files) {
  73. $error |= extract($m);
  74. $error |= testcompile($m);
  75. }
  76. exit $error;