manpage-scan.pl 8.1 KB

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