verify-examples.pl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. my $check = "./scripts/checksrc.pl";
  28. my $error;
  29. if($files[0] eq "-h") {
  30. print "Usage: verify-synopsis [man pages]\n";
  31. exit;
  32. }
  33. sub testcompile {
  34. my $rc = system("gcc -c test.c -DCURL_DISABLE_TYPECHECK -DCURL_ALLOW_OLD_MULTI_SOCKET -DCURL_DISABLE_DEPRECATION -Wunused -Werror -Wno-unused-but-set-variable -I include") >> 8;
  35. return $rc;
  36. }
  37. sub checksrc {
  38. my $rc = system("$check test.c") >> 8;
  39. return $rc;
  40. }
  41. sub extract {
  42. my($f) = @_;
  43. my $syn = 0;
  44. my $l = 0;
  45. my $iline = 0;
  46. my $fail = 0;
  47. open(F, "<$f") or die "failed opening input file $f : $!";
  48. open(O, ">$cfile") or die "failed opening output file $cfile : $!";
  49. print O "#include <curl/curl.h>\n";
  50. while(<F>) {
  51. $iline++;
  52. if(/^.SH EXAMPLE/) {
  53. $syn = 1
  54. }
  55. elsif($syn == 1) {
  56. if(/^.nf/) {
  57. $syn++;
  58. print O "/* !checksrc! disable UNUSEDIGNORE all */\n";
  59. print O "/* !checksrc! disable COPYRIGHT all */\n";
  60. print O "/* !checksrc! disable FOPENMODE all */\n";
  61. printf O "#line %d \"$f\"\n", $iline+1;
  62. }
  63. }
  64. elsif($syn == 2) {
  65. if(/^.fi/) {
  66. last;
  67. }
  68. if(/(?<!\\)(?:\\{2})*\\(?!\\)/) {
  69. print STDERR
  70. "Error while processing file $f line $iline:\n$_" .
  71. "Error: Single backslashes \\ are not properly shown in " .
  72. "manpage EXAMPLE output unless they are escaped \\\\.\n";
  73. $fail = 1;
  74. $error = 1;
  75. last;
  76. }
  77. # two backslashes become one
  78. $_ =~ s/\\\\/\\/g;
  79. print O $_;
  80. $l++;
  81. }
  82. }
  83. close(F);
  84. close(O);
  85. return ($fail ? 0 : $l);
  86. }
  87. my $count;
  88. for my $m (@files) {
  89. #print "Verify $m\n";
  90. my $out = extract($m);
  91. if($out) {
  92. $error |= testcompile($m);
  93. $error |= checksrc($m);
  94. }
  95. $count++;
  96. }
  97. if(!$error) {
  98. print "Verified $count man pages ok\n";
  99. }
  100. else {
  101. print "Detected problems\n";
  102. }
  103. exit $error;