2
0

test1139.pl 8.7 KB

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