2
0

test1139.pl 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. # for tests and debug only, can remain hidden
  167. '--test-event' => 6,
  168. '--wdebug' => 6,
  169. );
  170. #########################################################################
  171. # parse the curl code that parses the command line arguments!
  172. open($r, "<", "$root/src/tool_getparam.c") ||
  173. die "no input file";
  174. my $list;
  175. my @getparam; # store all parsed parameters
  176. my $prevlong = "";
  177. my $no = 0;
  178. while(<$r>) {
  179. $no++;
  180. chomp;
  181. if(/struct LongShort aliases/) {
  182. $list=1;
  183. }
  184. elsif($list) {
  185. if( /^ \{(\"[^,]*\").*\'(.)\', (.*)\}/) {
  186. my ($l, $s, $rd)=($1, $2, $3);
  187. my $sh;
  188. my $lo;
  189. my $title;
  190. if(($l cmp $prevlong) < 0) {
  191. print STDERR "tool_getparam.c:$no: '$l' is NOT placed in alpha-order\n";
  192. }
  193. if($l =~ /\"(.*)\"/) {
  194. # long option
  195. $lo = $1;
  196. $title="--$lo";
  197. }
  198. if($s ne " ") {
  199. # a short option
  200. $sh = $s;
  201. $title="-$sh, $title";
  202. }
  203. push @getparam, $title;
  204. $opts{$title} |= 1;
  205. $prevlong = $l;
  206. }
  207. }
  208. }
  209. close($r);
  210. #########################################################################
  211. # parse the curl.1 manpage, extract all documented command line options
  212. # The manpage may or may not be rebuilt, so check both possible locations
  213. open($r, "<", "$buildroot/docs/cmdline-opts/curl.1") || open($r, "<", "$root/docs/cmdline-opts/curl.1") ||
  214. die "failed getting curl.1";
  215. my @manpage; # store all parsed parameters
  216. while(<$r>) {
  217. chomp;
  218. my $l= $_;
  219. $l =~ s/\\-/-/g;
  220. if($l =~ /^\.IP \"(-[^\"]*)\"/) {
  221. my $str = $1;
  222. my $combo;
  223. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  224. # figure out the -short, --long combo
  225. $combo = "-$1, --$2";
  226. }
  227. elsif($str =~ /^--([a-z0-9.-]*)/) {
  228. # figure out the --long name
  229. $combo = "--$1";
  230. }
  231. if($combo) {
  232. push @manpage, $combo;
  233. $opts{$combo} |= 2;
  234. }
  235. }
  236. }
  237. close($r);
  238. #########################################################################
  239. # parse the curl code that outputs the curl -h list
  240. open($r, "<", "$root/src/tool_listhelp.c") ||
  241. die "no input file";
  242. my @toolhelp; # store all parsed parameters
  243. while(<$r>) {
  244. chomp;
  245. my $l= $_;
  246. if(/^ \{\" *(.*)/) {
  247. my $str=$1;
  248. my $combo;
  249. if($str =~ /^-(.), --([a-z0-9.-]*)/) {
  250. # figure out the -short, --long combo
  251. $combo = "-$1, --$2";
  252. }
  253. elsif($str =~ /^--([a-z0-9.-]*)/) {
  254. # figure out the --long name
  255. $combo = "--$1";
  256. }
  257. if($combo) {
  258. push @toolhelp, $combo;
  259. $opts{$combo} |= 4;
  260. }
  261. }
  262. }
  263. close($r);
  264. #
  265. # Now we have three arrays with options to cross-reference.
  266. foreach my $o (keys %opts) {
  267. my $where = $opts{$o};
  268. if($where != 7) {
  269. # this is not in all three places
  270. $errors++;
  271. my $exists;
  272. my $missing;
  273. if($where & 1) {
  274. $exists=" tool_getparam.c";
  275. }
  276. else {
  277. $missing=" tool_getparam.c";
  278. }
  279. if($where & 2) {
  280. $exists.= " curl.1";
  281. }
  282. else {
  283. $missing.= " curl.1";
  284. }
  285. if($where & 4) {
  286. $exists .= " tool_listhelp.c";
  287. }
  288. else {
  289. $missing .= " tool_listhelp.c";
  290. }
  291. print STDERR "$o is not in$missing (but in$exists)\n";
  292. }
  293. }
  294. print STDERR "$errors\n";