2
0

manpage-scan.pl 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. ###########################################################################
  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_listhelp.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. '--no-clobber' => 1,
  139. # pretend these options without -no exist in curl.1 and tool_listhelp.c
  140. '--alpn' => 6,
  141. '--npn' => 6,
  142. '--eprt' => 6,
  143. '--epsv' => 6,
  144. '--keepalive' => 6,
  145. '-N, --buffer' => 6,
  146. '--sessionid' => 6,
  147. '--progress-meter' => 6,
  148. '--clobber' => 6,
  149. # deprecated options do not need to be in tool_help.c nor curl.1
  150. '--krb4' => 6,
  151. '--ftp-ssl' => 6,
  152. '--ftp-ssl-reqd' => 6,
  153. # for tests and debug only, can remain hidden
  154. '--test-event' => 6,
  155. '--wdebug' => 6,
  156. );
  157. #########################################################################
  158. # parse the curl code that parses the command line arguments!
  159. open(R, "<$root/src/tool_getparam.c") ||
  160. die "no input file";
  161. my $list;
  162. my @getparam; # store all parsed parameters
  163. while(<R>) {
  164. chomp;
  165. my $l= $_;
  166. if(/struct LongShort aliases/) {
  167. $list=1;
  168. }
  169. elsif($list) {
  170. if( /^ \{([^,]*), *([^ ]*)/) {
  171. my ($s, $l)=($1, $2);
  172. my $sh;
  173. my $lo;
  174. my $title;
  175. if($l =~ /\"(.*)\"/) {
  176. # long option
  177. $lo = $1;
  178. $title="--$lo";
  179. }
  180. if($s =~ /\"(.)\"/) {
  181. # a short option
  182. $sh = $1;
  183. $title="-$sh, $title";
  184. }
  185. push @getparam, $title;
  186. $opts{$title} |= 1;
  187. }
  188. }
  189. }
  190. close(R);
  191. #########################################################################
  192. # parse the curl.1 man page, extract all documented command line options
  193. # The man page may or may not be rebuilt, so check both possible locations
  194. open(R, "<$buildroot/docs/curl.1") || open(R, "<$root/docs/curl.1") ||
  195. die "no input file";
  196. my @manpage; # store all parsed parameters
  197. while(<R>) {
  198. chomp;
  199. my $l= $_;
  200. $l =~ s/\\-/-/g;
  201. if($l =~ /^\.IP \"(-[^\"]*)\"/) {
  202. my $str = $1;
  203. my $combo;
  204. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  205. # figure out the -short, --long combo
  206. $combo = "-$1, --$2";
  207. }
  208. elsif($str =~ /^--([a-z0-9.-]*)/) {
  209. # figure out the --long name
  210. $combo = "--$1";
  211. }
  212. if($combo) {
  213. push @manpage, $combo;
  214. $opts{$combo} |= 2;
  215. }
  216. }
  217. }
  218. close(R);
  219. #########################################################################
  220. # parse the curl code that outputs the curl -h list
  221. open(R, "<$root/src/tool_listhelp.c") ||
  222. die "no input file";
  223. my @toolhelp; # store all parsed parameters
  224. while(<R>) {
  225. chomp;
  226. my $l= $_;
  227. if(/^ \{\" *(.*)/) {
  228. my $str=$1;
  229. my $combo;
  230. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  231. # figure out the -short, --long combo
  232. $combo = "-$1, --$2";
  233. }
  234. elsif($str =~ /^--([a-z0-9.-]*)/) {
  235. # figure out the --long name
  236. $combo = "--$1";
  237. }
  238. if($combo) {
  239. push @toolhelp, $combo;
  240. $opts{$combo} |= 4;
  241. }
  242. }
  243. }
  244. close(R);
  245. #
  246. # Now we have three arrays with options to cross-reference.
  247. foreach my $o (keys %opts) {
  248. my $where = $opts{$o};
  249. if($where != 7) {
  250. # this is not in all three places
  251. $errors++;
  252. my $exists;
  253. my $missing;
  254. if($where & 1) {
  255. $exists=" tool_getparam.c";
  256. }
  257. else {
  258. $missing=" tool_getparam.c";
  259. }
  260. if($where & 2) {
  261. $exists.= " curl.1";
  262. }
  263. else {
  264. $missing.= " curl.1";
  265. }
  266. if($where & 4) {
  267. $exists .= " tool_listhelp.c";
  268. }
  269. else {
  270. $missing .= " tool_listhelp.c";
  271. }
  272. print STDERR "$o is not in$missing (but in$exists)\n";
  273. }
  274. }
  275. print STDERR "$errors\n";