manpage-scan.pl 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2016 - 2020, 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. ###########################################################################
  23. #
  24. # Scan symbols-in-version (which is verified to be correct by test 1119), then
  25. # verify that each option mention in there that should have its own man page
  26. # actually does.
  27. #
  28. # In addition, make sure that every current option to curl_easy_setopt,
  29. # curl_easy_getinfo and curl_multi_setopt are also mentioned in their
  30. # corresponding main (index) man page.
  31. #
  32. # src/tool_getparam.c lists all options curl can parse
  33. # docs/curl.1 documents all command line options
  34. # src/tool_help.c outputs all options with curl -h
  35. # - make sure they're all in sync
  36. #
  37. # Output all deviances to stderr.
  38. use strict;
  39. use warnings;
  40. # we may get the dir roots pointed out
  41. my $root=$ARGV[0] || ".";
  42. my $buildroot=$ARGV[1] || ".";
  43. my $syms = "$root/docs/libcurl/symbols-in-versions";
  44. my $curlh = "$root/include/curl/curl.h";
  45. my $errors=0;
  46. # the prepopulated alias list is the CURLINFO_* defines that are used for the
  47. # debug function callback and the fact that they use the same prefix as the
  48. # curl_easy_getinfo options was a mistake.
  49. my %alias = (
  50. 'CURLINFO_DATA_IN' => 'none',
  51. 'CURLINFO_DATA_OUT' => 'none',
  52. 'CURLINFO_END' => 'none',
  53. 'CURLINFO_HEADER_IN' => 'none',
  54. 'CURLINFO_HEADER_OUT' => 'none',
  55. 'CURLINFO_LASTONE' => 'none',
  56. 'CURLINFO_NONE' => 'none',
  57. 'CURLINFO_SSL_DATA_IN' => 'none',
  58. 'CURLINFO_SSL_DATA_OUT' => 'none',
  59. 'CURLINFO_TEXT' => 'none'
  60. );
  61. sub scanmanpage {
  62. my ($file, @words) = @_;
  63. open(M, "<$file");
  64. my @m = <M>;
  65. close(M);
  66. foreach my $m (@words) {
  67. my @g = grep(/^\.IP $m/, @m);
  68. if(!$g[0]) {
  69. print STDERR "Missing mention of $m in $file\n";
  70. $errors++;
  71. }
  72. }
  73. }
  74. # check for define alises
  75. open(R, "<$curlh") ||
  76. die "no curl.h";
  77. while(<R>) {
  78. if(/^\#define (CURL(OPT|INFO|MOPT)_\w+) (.*)/) {
  79. $alias{$1}=$3;
  80. }
  81. }
  82. close(R);
  83. my @curlopt;
  84. my @curlinfo;
  85. my @curlmopt;
  86. open(R, "<$syms") ||
  87. die "no input file";
  88. while(<R>) {
  89. chomp;
  90. my $l= $_;
  91. if($l =~ /(CURL(OPT|INFO|MOPT)_\w+) *([0-9.]*) *([0-9.-]*) *([0-9.]*)/) {
  92. my ($opt, $type, $add, $dep, $rem) = ($1, $2, $3, $4, $5);
  93. if($alias{$opt}) {
  94. #print "$opt => $alias{$opt}\n";
  95. }
  96. elsif($rem) {
  97. # $opt was removed in $rem
  98. # so don't check for that
  99. }
  100. else {
  101. if($type eq "OPT") {
  102. push @curlopt, $opt,
  103. }
  104. elsif($type eq "INFO") {
  105. push @curlinfo, $opt,
  106. }
  107. elsif($type eq "MOPT") {
  108. push @curlmopt, $opt,
  109. }
  110. if(! -f "$root/docs/libcurl/opts/$opt.3") {
  111. print STDERR "Missing $opt.3\n";
  112. $errors++;
  113. }
  114. }
  115. }
  116. }
  117. close(R);
  118. scanmanpage("$root/docs/libcurl/curl_easy_setopt.3", @curlopt);
  119. scanmanpage("$root/docs/libcurl/curl_easy_getinfo.3", @curlinfo);
  120. scanmanpage("$root/docs/libcurl/curl_multi_setopt.3", @curlmopt);
  121. # using this hash array, we can skip specific options
  122. my %opts = (
  123. # pretend these --no options exists in tool_getparam.c
  124. '--no-alpn' => 1,
  125. '--no-npn' => 1,
  126. '-N, --no-buffer' => 1,
  127. '--no-sessionid' => 1,
  128. '--no-keepalive' => 1,
  129. '--no-progress-meter' => 1,
  130. # pretend these options without -no exist in curl.1 and tool_help.c
  131. '--alpn' => 6,
  132. '--npn' => 6,
  133. '--eprt' => 6,
  134. '--epsv' => 6,
  135. '--keepalive' => 6,
  136. '-N, --buffer' => 6,
  137. '--sessionid' => 6,
  138. '--progress-meter' => 6,
  139. # deprecated options do not need to be in tool_help.c nor curl.1
  140. '--krb4' => 6,
  141. '--ftp-ssl' => 6,
  142. '--ftp-ssl-reqd' => 6,
  143. # for tests and debug only, can remain hidden
  144. '--test-event' => 6,
  145. '--wdebug' => 6,
  146. );
  147. #########################################################################
  148. # parse the curl code that parses the command line arguments!
  149. open(R, "<$root/src/tool_getparam.c") ||
  150. die "no input file";
  151. my $list;
  152. my @getparam; # store all parsed parameters
  153. while(<R>) {
  154. chomp;
  155. my $l= $_;
  156. if(/struct LongShort aliases/) {
  157. $list=1;
  158. }
  159. elsif($list) {
  160. if( /^ \{([^,]*), *([^ ]*)/) {
  161. my ($s, $l)=($1, $2);
  162. my $sh;
  163. my $lo;
  164. my $title;
  165. if($l =~ /\"(.*)\"/) {
  166. # long option
  167. $lo = $1;
  168. $title="--$lo";
  169. }
  170. if($s =~ /\"(.)\"/) {
  171. # a short option
  172. $sh = $1;
  173. $title="-$sh, $title";
  174. }
  175. push @getparam, $title;
  176. $opts{$title} |= 1;
  177. }
  178. }
  179. }
  180. close(R);
  181. #########################################################################
  182. # parse the curl.1 man page, extract all documented command line options
  183. # The man page may or may not be rebuilt, so check both possible locations
  184. open(R, "<$buildroot/docs/curl.1") || open(R, "<$root/docs/curl.1") ||
  185. die "no input file";
  186. my @manpage; # store all parsed parameters
  187. while(<R>) {
  188. chomp;
  189. my $l= $_;
  190. if(/^\.IP \"(-[^\"]*)\"/) {
  191. my $str = $1;
  192. my $combo;
  193. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  194. # figure out the -short, --long combo
  195. $combo = "-$1, --$2";
  196. }
  197. elsif($str =~ /^--([a-z0-9.-]*)/) {
  198. # figure out the --long name
  199. $combo = "--$1";
  200. }
  201. if($combo) {
  202. push @manpage, $combo;
  203. $opts{$combo} |= 2;
  204. }
  205. }
  206. }
  207. close(R);
  208. #########################################################################
  209. # parse the curl code that outputs the curl -h list
  210. open(R, "<$root/src/tool_help.c") ||
  211. die "no input file";
  212. my @toolhelp; # store all parsed parameters
  213. while(<R>) {
  214. chomp;
  215. my $l= $_;
  216. if(/^ \{\" *(.*)/) {
  217. my $str=$1;
  218. my $combo;
  219. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  220. # figure out the -short, --long combo
  221. $combo = "-$1, --$2";
  222. }
  223. elsif($str =~ /^--([a-z0-9.-]*)/) {
  224. # figure out the --long name
  225. $combo = "--$1";
  226. }
  227. if($combo) {
  228. push @toolhelp, $combo;
  229. $opts{$combo} |= 4;
  230. }
  231. }
  232. }
  233. close(R);
  234. #
  235. # Now we have three arrays with options to cross-reference.
  236. foreach my $o (keys %opts) {
  237. my $where = $opts{$o};
  238. if($where != 7) {
  239. # this is not in all three places
  240. $errors++;
  241. my $exists;
  242. my $missing;
  243. if($where & 1) {
  244. $exists=" tool_getparam.c";
  245. }
  246. else {
  247. $missing=" tool_getparam.c";
  248. }
  249. if($where & 2) {
  250. $exists.= " curl.1";
  251. }
  252. else {
  253. $missing.= " curl.1";
  254. }
  255. if($where & 4) {
  256. $exists .= " tool_help.c";
  257. }
  258. else {
  259. $missing .= " tool_help.c";
  260. }
  261. print STDERR "$o is not in$missing (but in$exists)\n";
  262. }
  263. }
  264. print STDERR "$errors\n";