manpage-scan.pl 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2016 - 2021, 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;
  65. while(<M>) {
  66. if($_ =~ /^\.IP (.*)/) {
  67. my $w = $1;
  68. # "unquote" minuses
  69. $w =~ s/\\-/-/g;
  70. push @m, $w;
  71. }
  72. }
  73. close(M);
  74. foreach my $m (@words) {
  75. my @g = grep(/$m/, @m);
  76. if(!$g[0]) {
  77. print STDERR "Missing mention of $m in $file\n";
  78. $errors++;
  79. }
  80. }
  81. }
  82. # check for define alises
  83. open(R, "<$curlh") ||
  84. die "no curl.h";
  85. while(<R>) {
  86. if(/^\#define (CURL(OPT|INFO|MOPT)_\w+) (.*)/) {
  87. $alias{$1}=$3;
  88. }
  89. }
  90. close(R);
  91. my @curlopt;
  92. my @curlinfo;
  93. my @curlmopt;
  94. open(R, "<$syms") ||
  95. die "no input file";
  96. while(<R>) {
  97. chomp;
  98. my $l= $_;
  99. if($l =~ /(CURL(OPT|INFO|MOPT)_\w+) *([0-9.]*) *([0-9.-]*) *([0-9.]*)/) {
  100. my ($opt, $type, $add, $dep, $rem) = ($1, $2, $3, $4, $5);
  101. if($alias{$opt}) {
  102. #print "$opt => $alias{$opt}\n";
  103. }
  104. elsif($rem) {
  105. # $opt was removed in $rem
  106. # so don't check for that
  107. }
  108. else {
  109. if($type eq "OPT") {
  110. push @curlopt, $opt,
  111. }
  112. elsif($type eq "INFO") {
  113. push @curlinfo, $opt,
  114. }
  115. elsif($type eq "MOPT") {
  116. push @curlmopt, $opt,
  117. }
  118. if(! -f "$root/docs/libcurl/opts/$opt.3") {
  119. print STDERR "Missing $opt.3\n";
  120. $errors++;
  121. }
  122. }
  123. }
  124. }
  125. close(R);
  126. scanmanpage("$root/docs/libcurl/curl_easy_setopt.3", @curlopt);
  127. scanmanpage("$root/docs/libcurl/curl_easy_getinfo.3", @curlinfo);
  128. scanmanpage("$root/docs/libcurl/curl_multi_setopt.3", @curlmopt);
  129. # using this hash array, we can skip specific options
  130. my %opts = (
  131. # pretend these --no options exists in tool_getparam.c
  132. '--no-alpn' => 1,
  133. '--no-npn' => 1,
  134. '-N, --no-buffer' => 1,
  135. '--no-sessionid' => 1,
  136. '--no-keepalive' => 1,
  137. '--no-progress-meter' => 1,
  138. # pretend these options without -no exist in curl.1 and tool_help.c
  139. '--alpn' => 6,
  140. '--npn' => 6,
  141. '--eprt' => 6,
  142. '--epsv' => 6,
  143. '--keepalive' => 6,
  144. '-N, --buffer' => 6,
  145. '--sessionid' => 6,
  146. '--progress-meter' => 6,
  147. # deprecated options do not need to be in tool_help.c nor curl.1
  148. '--krb4' => 6,
  149. '--ftp-ssl' => 6,
  150. '--ftp-ssl-reqd' => 6,
  151. # for tests and debug only, can remain hidden
  152. '--test-event' => 6,
  153. '--wdebug' => 6,
  154. );
  155. #########################################################################
  156. # parse the curl code that parses the command line arguments!
  157. open(R, "<$root/src/tool_getparam.c") ||
  158. die "no input file";
  159. my $list;
  160. my @getparam; # store all parsed parameters
  161. while(<R>) {
  162. chomp;
  163. my $l= $_;
  164. if(/struct LongShort aliases/) {
  165. $list=1;
  166. }
  167. elsif($list) {
  168. if( /^ \{([^,]*), *([^ ]*)/) {
  169. my ($s, $l)=($1, $2);
  170. my $sh;
  171. my $lo;
  172. my $title;
  173. if($l =~ /\"(.*)\"/) {
  174. # long option
  175. $lo = $1;
  176. $title="--$lo";
  177. }
  178. if($s =~ /\"(.)\"/) {
  179. # a short option
  180. $sh = $1;
  181. $title="-$sh, $title";
  182. }
  183. push @getparam, $title;
  184. $opts{$title} |= 1;
  185. }
  186. }
  187. }
  188. close(R);
  189. #########################################################################
  190. # parse the curl.1 man page, extract all documented command line options
  191. # The man page may or may not be rebuilt, so check both possible locations
  192. open(R, "<$buildroot/docs/curl.1") || open(R, "<$root/docs/curl.1") ||
  193. die "no input file";
  194. my @manpage; # store all parsed parameters
  195. while(<R>) {
  196. chomp;
  197. my $l= $_;
  198. $l =~ s/\\-/-/g;
  199. if($l =~ /^\.IP \"(-[^\"]*)\"/) {
  200. my $str = $1;
  201. my $combo;
  202. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  203. # figure out the -short, --long combo
  204. $combo = "-$1, --$2";
  205. }
  206. elsif($str =~ /^--([a-z0-9.-]*)/) {
  207. # figure out the --long name
  208. $combo = "--$1";
  209. }
  210. if($combo) {
  211. push @manpage, $combo;
  212. $opts{$combo} |= 2;
  213. }
  214. }
  215. }
  216. close(R);
  217. #########################################################################
  218. # parse the curl code that outputs the curl -h list
  219. open(R, "<$root/src/tool_help.c") ||
  220. die "no input file";
  221. my @toolhelp; # store all parsed parameters
  222. while(<R>) {
  223. chomp;
  224. my $l= $_;
  225. if(/^ \{\" *(.*)/) {
  226. my $str=$1;
  227. my $combo;
  228. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  229. # figure out the -short, --long combo
  230. $combo = "-$1, --$2";
  231. }
  232. elsif($str =~ /^--([a-z0-9.-]*)/) {
  233. # figure out the --long name
  234. $combo = "--$1";
  235. }
  236. if($combo) {
  237. push @toolhelp, $combo;
  238. $opts{$combo} |= 4;
  239. }
  240. }
  241. }
  242. close(R);
  243. #
  244. # Now we have three arrays with options to cross-reference.
  245. foreach my $o (keys %opts) {
  246. my $where = $opts{$o};
  247. if($where != 7) {
  248. # this is not in all three places
  249. $errors++;
  250. my $exists;
  251. my $missing;
  252. if($where & 1) {
  253. $exists=" tool_getparam.c";
  254. }
  255. else {
  256. $missing=" tool_getparam.c";
  257. }
  258. if($where & 2) {
  259. $exists.= " curl.1";
  260. }
  261. else {
  262. $missing.= " curl.1";
  263. }
  264. if($where & 4) {
  265. $exists .= " tool_help.c";
  266. }
  267. else {
  268. $missing .= " tool_help.c";
  269. }
  270. print STDERR "$o is not in$missing (but in$exists)\n";
  271. }
  272. }
  273. print STDERR "$errors\n";