2
0

manpage-scan.pl 8.1 KB

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