2
0

find-doc-nits 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. #! /usr/bin/env perl
  2. # Copyright 2002-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. require 5.10.0;
  9. use warnings;
  10. use strict;
  11. use Carp qw(:DEFAULT cluck);
  12. use Pod::Checker;
  13. use File::Find;
  14. use File::Basename;
  15. use File::Spec::Functions;
  16. use Getopt::Std;
  17. use FindBin;
  18. use lib "$FindBin::Bin/perl";
  19. use OpenSSL::Util::Pod;
  20. use lib '.';
  21. use configdata;
  22. # Set to 1 for debug output
  23. my $debug = 0;
  24. # Options.
  25. our($opt_d);
  26. our($opt_e);
  27. our($opt_s);
  28. our($opt_o);
  29. our($opt_h);
  30. our($opt_l);
  31. our($opt_m);
  32. our($opt_n);
  33. our($opt_p);
  34. our($opt_u);
  35. our($opt_v);
  36. our($opt_c);
  37. # Print usage message and exit.
  38. sub help {
  39. print <<EOF;
  40. Find small errors (nits) in documentation. Options:
  41. -c List undocumented commands, undocumented options and unimplemented options.
  42. -d Detailed list of undocumented (implies -u)
  43. -e Detailed list of new undocumented (implies -v)
  44. -h Print this help message
  45. -l Print bogus links
  46. -m Name(s) of manuals to focus on. Default: man1,man3,man5,man7
  47. -n Print nits in POD pages
  48. -o Causes -e/-v to count symbols added since 1.1.1 as new (implies -v)
  49. -u Count undocumented functions
  50. -v Count new undocumented functions
  51. EOF
  52. exit;
  53. }
  54. getopts('cdehlm:nouv');
  55. help() if $opt_h;
  56. $opt_u = 1 if $opt_d;
  57. $opt_v = 1 if $opt_o || $opt_e;
  58. die "Cannot use both -u and -v"
  59. if $opt_u && $opt_v;
  60. die "Cannot use both -d and -e"
  61. if $opt_d && $opt_e;
  62. # We only need to check c, l, n, u and v.
  63. # Options d, e, o imply one of the above.
  64. die "Need one of -[cdehlnouv] flags.\n"
  65. unless $opt_c or $opt_l or $opt_n or $opt_u or $opt_v;
  66. my $temp = '/tmp/docnits.txt';
  67. my $OUT;
  68. my $status = 0;
  69. $opt_m = "man1,man3,man5,man7" unless $opt_m;
  70. die "Argument of -m option may contain only man1, man3, man5, and/or man7"
  71. unless $opt_m =~ /^(man[1357][, ]?)*$/;
  72. my @sections = ( split /[, ]/, $opt_m );
  73. my %mandatory_sections = (
  74. '*' => [ 'NAME', 'COPYRIGHT' ],
  75. 1 => [ 'DESCRIPTION', 'SYNOPSIS', 'OPTIONS' ],
  76. 3 => [ 'DESCRIPTION', 'SYNOPSIS', 'RETURN VALUES' ],
  77. 5 => [ 'DESCRIPTION' ],
  78. 7 => [ ]
  79. );
  80. # Symbols that we ignored.
  81. # They are reserved macros that we currently don't document
  82. my $ignored = qr/(?| ^i2d_
  83. | ^d2i_
  84. | ^DEPRECATEDIN
  85. | ^OSSL_DEPRECATED
  86. | \Q_fnsig(3)\E$
  87. | ^IMPLEMENT_
  88. | ^_?DECLARE_
  89. | ^sk_
  90. | ^SKM_DEFINE_STACK_OF_INTERNAL
  91. | ^lh_
  92. | ^DEFINE_LHASH_OF_(INTERNAL|DEPRECATED)
  93. )/x;
  94. # A common regexp for C symbol names
  95. my $C_symbol = qr/\b[[:alpha:]][_[:alnum:]]*\b/;
  96. # Collect all POD files, both internal and public, and regardless of location
  97. # We collect them in a hash table with each file being a key, so we can attach
  98. # tags to them. For example, internal docs will have the word "internal"
  99. # attached to them.
  100. my %files = ();
  101. # We collect files names on the fly, on known tag basis
  102. my %collected_tags = ();
  103. # We cache results based on tags
  104. my %collected_results = ();
  105. # files OPTIONS
  106. #
  107. # Example:
  108. #
  109. # files(TAGS => 'manual');
  110. # files(TAGS => [ 'manual', 'man1' ]);
  111. #
  112. # This function returns an array of files corresponding to a set of tags
  113. # given with the options "TAGS". The value of this option can be a single
  114. # word, or an array of several words, which work as inclusive or exclusive
  115. # selectors. Inclusive selectors are used to add one more set of files to
  116. # the returned array, while exclusive selectors limit the set of files added
  117. # to the array. The recognised tag values are:
  118. #
  119. # 'public_manual' - inclusive selector, adds public manuals to the
  120. # returned array of files.
  121. # 'internal_manual' - inclusive selector, adds internal manuals to the
  122. # returned array of files.
  123. # 'manual' - inclusive selector, adds any manual to the returned
  124. # array of files. This is really a shorthand for
  125. # 'public_manual' and 'internal_manual' combined.
  126. # 'public_header' - inclusive selector, adds public headers to the
  127. # returned array of files.
  128. # 'header' - inclusive selector, adds any header file to the
  129. # returned array of files. Since we currently only
  130. # care about public headers, this is exactly
  131. # equivalent to 'public_header', but is present for
  132. # consistency.
  133. #
  134. # 'man1', 'man3', 'man5', 'man7'
  135. # - exclusive selectors, only applicable together with
  136. # any of the manual selectors. If any of these are
  137. # present, only the manuals from the given sections
  138. # will be included. If none of these are present,
  139. # the manuals from all sections will be returned.
  140. #
  141. # All returned manual files come from configdata.pm.
  142. # All returned header files come from looking inside
  143. # "$config{sourcedir}/include/openssl"
  144. #
  145. sub files {
  146. my %opts = ( @_ ); # Make a copy of the arguments
  147. $opts{TAGS} = [ $opts{TAGS} ] if ref($opts{TAGS}) eq '';
  148. croak "No tags given, or not an array"
  149. unless exists $opts{TAGS} && ref($opts{TAGS}) eq 'ARRAY';
  150. my %tags = map { $_ => 1 } @{$opts{TAGS}};
  151. $tags{public_manual} = 1
  152. if $tags{manual} && ($tags{public} // !$tags{internal});
  153. $tags{internal_manual} = 1
  154. if $tags{manual} && ($tags{internal} // !$tags{public});
  155. $tags{public_header} = 1
  156. if $tags{header} && ($tags{public} // !$tags{internal});
  157. delete $tags{manual};
  158. delete $tags{header};
  159. delete $tags{public};
  160. delete $tags{internal};
  161. my $tags_as_key = join(':', sort keys %tags);
  162. cluck "DEBUG[files]: This is how we got here!" if $debug;
  163. print STDERR "DEBUG[files]: tags: $tags_as_key\n" if $debug;
  164. my %tags_to_collect = ( map { $_ => 1 }
  165. grep { !exists $collected_tags{$_} }
  166. keys %tags );
  167. if ($tags_to_collect{public_manual}) {
  168. print STDERR "DEBUG[files]: collecting public manuals\n"
  169. if $debug;
  170. # The structure in configdata.pm is that $unified_info{mandocs}
  171. # contains lists of man files, and in turn, $unified_info{depends}
  172. # contains hash tables showing which POD file each of those man
  173. # files depend on. We use that information to find the POD files,
  174. # and to attach the man section they belong to as tags
  175. foreach my $mansect ( @sections ) {
  176. foreach ( map { @{$unified_info{depends}->{$_}} }
  177. @{$unified_info{mandocs}->{$mansect}} ) {
  178. $files{$_} = { $mansect => 1, public_manual => 1 };
  179. }
  180. }
  181. $collected_tags{public_manual} = 1;
  182. }
  183. if ($tags_to_collect{internal_manual}) {
  184. print STDERR "DEBUG[files]: collecting internal manuals\n"
  185. if $debug;
  186. # We don't have the internal docs in configdata.pm. However, they
  187. # are all in the source tree, so they're easy to find.
  188. foreach my $mansect ( @sections ) {
  189. foreach ( glob(catfile($config{sourcedir},
  190. 'doc', 'internal', $mansect, '*.pod')) ) {
  191. $files{$_} = { $mansect => 1, internal_manual => 1 };
  192. }
  193. }
  194. $collected_tags{internal_manual} = 1;
  195. }
  196. if ($tags_to_collect{public_header}) {
  197. print STDERR "DEBUG[files]: collecting public headers\n"
  198. if $debug;
  199. foreach ( glob(catfile($config{sourcedir},
  200. 'include', 'openssl', '*.h')) ) {
  201. $files{$_} = { public_header => 1 };
  202. }
  203. }
  204. my @result = @{$collected_results{$tags_as_key} // []};
  205. if (!@result) {
  206. # Produce a result based on caller tags
  207. foreach my $type ( ( 'public_manual', 'internal_manual' ) ) {
  208. next unless $tags{$type};
  209. # If caller asked for specific sections, we care about sections.
  210. # Otherwise, we give back all of them.
  211. my @selected_sections =
  212. grep { $tags{$_} } @sections;
  213. @selected_sections = @sections unless @selected_sections;
  214. foreach my $section ( ( @selected_sections ) ) {
  215. push @result,
  216. ( sort { basename($a) cmp basename($b) }
  217. grep { $files{$_}->{$type} && $files{$_}->{$section} }
  218. keys %files );
  219. }
  220. }
  221. if ($tags{public_header}) {
  222. push @result,
  223. ( sort { basename($a) cmp basename($b) }
  224. grep { $files{$_}->{public_header} }
  225. keys %files );
  226. }
  227. if ($debug) {
  228. print STDERR "DEBUG[files]: result:\n";
  229. print STDERR "DEBUG[files]: $_\n" foreach @result;
  230. }
  231. $collected_results{$tags_as_key} = [ @result ];
  232. }
  233. return @result;
  234. }
  235. # Print error message, set $status.
  236. sub err {
  237. print join(" ", @_), "\n";
  238. $status = 1
  239. }
  240. # Cross-check functions in the NAME and SYNOPSIS section.
  241. sub name_synopsis {
  242. my $id = shift;
  243. my $filename = shift;
  244. my $contents = shift;
  245. # Get NAME section and all words in it.
  246. return unless $contents =~ /=head1 NAME(.*)=head1 SYNOPSIS/ms;
  247. my $tmp = $1;
  248. $tmp =~ tr/\n/ /;
  249. err($id, "Trailing comma before - in NAME")
  250. if $tmp =~ /, *-/;
  251. $tmp =~ s/ -.*//g;
  252. err($id, "POD markup among the names in NAME")
  253. if $tmp =~ /[<>]/;
  254. $tmp =~ s/ */ /g;
  255. err($id, "Missing comma in NAME")
  256. if $tmp =~ /[^,] /;
  257. my $dirname = dirname($filename);
  258. my $section = basename($dirname);
  259. my $simplename = basename($filename, ".pod");
  260. my $foundfilename = 0;
  261. my %foundfilenames = ();
  262. my %names;
  263. foreach my $n ( split ',', $tmp ) {
  264. $n =~ s/^\s+//;
  265. $n =~ s/\s+$//;
  266. err($id, "The name '$n' contains white-space")
  267. if $n =~ /\s/;
  268. $names{$n} = 1;
  269. $foundfilename++ if $n eq $simplename;
  270. $foundfilenames{$n} = 1
  271. if ( ( grep { basename($_) eq "$n.pod" }
  272. files(TAGS => [ 'manual', $section ]) )
  273. && $n ne $simplename );
  274. }
  275. err($id, "The following exist as other .pod files:",
  276. sort keys %foundfilenames)
  277. if %foundfilenames;
  278. err($id, "$simplename (filename) missing from NAME section")
  279. unless $foundfilename;
  280. # Find all functions in SYNOPSIS
  281. return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms;
  282. my $syn = $1;
  283. my $ignore_until = undef; # If defined, this is a regexp
  284. # Remove all non-code lines
  285. $syn =~ s/^(?:\s*?|\S.*?)$//msg;
  286. # Remove all comments
  287. $syn =~ s/\/\*.*?\*\///msg;
  288. while ( $syn ) {
  289. # "env" lines end at a newline.
  290. # Preprocessor lines start with a # and end at a newline.
  291. # Other lines end with a semicolon, and may cover more than
  292. # one physical line.
  293. if ( $syn !~ /^ \s*(env .*?|#.*?|.*?;)\s*$/ms ) {
  294. err($id, "Can't parse rest of synopsis:\n$syn\n(declarations not ending with a semicolon (;)?)");
  295. last;
  296. }
  297. my $line = $1;
  298. $syn = $';
  299. print STDERR "DEBUG[name_synopsis] \$line = '$line'\n" if $debug;
  300. # Special code to skip over documented structures
  301. if ( defined $ignore_until) {
  302. next if $line !~ /$ignore_until/;
  303. $ignore_until = undef;
  304. next;
  305. }
  306. if ( $line =~ /^\s*(?:typedef\s+)?struct(?:\s+\S+)\s*\{/ ) {
  307. $ignore_until = qr/\}.*?;/;
  308. next;
  309. }
  310. my $sym;
  311. my $is_prototype = 1;
  312. $line =~ s/LHASH_OF\([^)]+\)/int/g;
  313. $line =~ s/STACK_OF\([^)]+\)/int/g;
  314. $line =~ s/SPARSE_ARRAY_OF\([^)]+\)/int/g;
  315. $line =~ s/__declspec\([^)]+\)//;
  316. ## We don't prohibit that space, to allow typedefs looking like
  317. ## this:
  318. ##
  319. ## typedef int (fantastically_long_name_breaks_80char_limit)
  320. ## (fantastically_long_name_breaks_80char_limit *something);
  321. ##
  322. #if ( $line =~ /typedef.*\(\*?\S+\)\s+\(/ ) {
  323. # # a callback function with whitespace before the argument list:
  324. # # typedef ... (*NAME) (...
  325. # # typedef ... (NAME) (...
  326. # err($id, "Function typedef has space before arg list: $line");
  327. #}
  328. if ( $line =~ /env (\S*)=/ ) {
  329. # environment variable env NAME=...
  330. $sym = $1;
  331. } elsif ( $line =~ /typedef.*\(\*?($C_symbol)\)\s*\(/ ) {
  332. # a callback function pointer: typedef ... (*NAME)(...
  333. # a callback function signature: typedef ... (NAME)(...
  334. $sym = $1;
  335. } elsif ( $line =~ /typedef.*($C_symbol)\s*\(/ ) {
  336. # a callback function signature: typedef ... NAME(...
  337. $sym = $1;
  338. } elsif ( $line =~ /typedef.*($C_symbol);/ ) {
  339. # a simple typedef: typedef ... NAME;
  340. $is_prototype = 0;
  341. $sym = $1;
  342. } elsif ( $line =~ /enum ($C_symbol) \{/ ) {
  343. # an enumeration: enum ... {
  344. $sym = $1;
  345. } elsif ( $line =~ /#\s*(?:define|undef) ($C_symbol)/ ) {
  346. $is_prototype = 0;
  347. $sym = $1;
  348. } elsif ( $line =~ /^[^\(]*?\(\*($C_symbol)\s*\(/ ) {
  349. # a function returning a function pointer: TYPE (*NAME(args))(args)
  350. $sym = $1;
  351. } elsif ( $line =~ /^[^\(]*?($C_symbol)\s*\(/ ) {
  352. # a simple function declaration
  353. $sym = $1;
  354. }
  355. else {
  356. next;
  357. }
  358. print STDERR "DEBUG[name_synopsis] \$sym = '$sym'\n" if $debug;
  359. err($id, "$sym missing from NAME section")
  360. unless defined $names{$sym};
  361. $names{$sym} = 2;
  362. # Do some sanity checks on the prototype.
  363. err($id, "Prototype missing spaces around commas: $line")
  364. if $is_prototype && $line =~ /[a-z0-9],[^\s]/;
  365. }
  366. foreach my $n ( keys %names ) {
  367. next if $names{$n} == 2;
  368. err($id, "$n missing from SYNOPSIS")
  369. }
  370. }
  371. # Check if SECTION ($3) is located before BEFORE ($4)
  372. sub check_section_location {
  373. my $id = shift;
  374. my $contents = shift;
  375. my $section = shift;
  376. my $before = shift;
  377. return unless $contents =~ /=head1 $section/
  378. and $contents =~ /=head1 $before/;
  379. err($id, "$section should appear before $before section")
  380. if $contents =~ /=head1 $before.*=head1 $section/ms;
  381. }
  382. # Check if a =head1 is duplicated, or a =headX is duplicated within a
  383. # =head1. Treats =head2 =head3 as equivalent -- it doesn't reset the head3
  384. # sets if it finds a =head2 -- but that is good enough for now. Also check
  385. # for proper capitalization, trailing periods, etc.
  386. sub check_head_style {
  387. my $id = shift;
  388. my $contents = shift;
  389. my %head1;
  390. my %subheads;
  391. foreach my $line ( split /\n+/, $contents ) {
  392. next unless $line =~ /^=head/;
  393. if ( $line =~ /head1/ ) {
  394. err($id, "Duplicate section $line")
  395. if defined $head1{$line};
  396. $head1{$line} = 1;
  397. %subheads = ();
  398. } else {
  399. err($id, "Duplicate subsection $line")
  400. if defined $subheads{$line};
  401. $subheads{$line} = 1;
  402. }
  403. err($id, "Period in =head")
  404. if $line =~ /\.[^\w]/ or $line =~ /\.$/;
  405. err($id, "not all uppercase in =head1")
  406. if $line =~ /head1.*[a-z]/;
  407. err($id, "All uppercase in subhead")
  408. if $line =~ /head[234][ A-Z0-9]+$/;
  409. }
  410. }
  411. # Because we have options and symbols with extra markup, we need
  412. # to take that into account, so we need a regexp that extracts
  413. # markup chunks, including recursive markup.
  414. # please read up on /(?R)/ in perlre(1)
  415. # (note: order is important, (?R) needs to come before .)
  416. # (note: non-greedy is important, or something like 'B<foo> and B<bar>'
  417. # will be captured as one item)
  418. my $markup_re =
  419. qr/( # Capture group
  420. [BIL]< # The start of what we recurse on
  421. (?:(?-1)|.)*? # recurse the whole regexp (referring to
  422. # the last opened capture group, i.e. the
  423. # start of this regexp), or pick next
  424. # character. Do NOT be greedy!
  425. > # The end of what we recurse on
  426. )/x; # (the x allows this sort of split up regexp)
  427. # Options must start with a dash, followed by a letter, possibly
  428. # followed by letters, digits, dashes and underscores, and the last
  429. # character must be a letter or a digit.
  430. # We do also accept the single -? or -n, where n is a digit
  431. my $option_re =
  432. qr/(?:
  433. \? # Single question mark
  434. |
  435. \d # Single digit
  436. |
  437. - # Single dash (--)
  438. |
  439. [[:alpha:]](?:[-_[:alnum:]]*?[[:alnum:]])?
  440. )/x;
  441. # Helper function to check if a given $thing is properly marked up
  442. # option. It returns one of these values:
  443. # undef if it's not an option
  444. # "" if it's a malformed option
  445. # $unwrapped the option with the outermost B<> wrapping removed.
  446. sub normalise_option {
  447. my $id = shift;
  448. my $filename = shift;
  449. my $thing = shift;
  450. my $unwrapped = $thing;
  451. my $unmarked = $thing;
  452. # $unwrapped is the option with the outer B<> markup removed
  453. $unwrapped =~ s/^B<//;
  454. $unwrapped =~ s/>$//;
  455. # $unmarked is the option with *all* markup removed
  456. $unmarked =~ s/[BIL]<|>//msg;
  457. # If we found an option, check it, collect it
  458. if ( $unwrapped =~ /^\s*-/ ) {
  459. return $unwrapped # return option with outer B<> removed
  460. if $unmarked =~ /^-${option_re}$/;
  461. return ""; # Malformed option
  462. }
  463. return undef; # Something else
  464. }
  465. # Checks of command option (man1) formatting. The man1 checks are
  466. # restricted to the SYNOPSIS and OPTIONS sections, the rest is too
  467. # free form, we simply cannot be too strict there.
  468. sub option_check {
  469. my $id = shift;
  470. my $filename = shift;
  471. my $contents = shift;
  472. my $synopsis = ($contents =~ /=head1\s+SYNOPSIS(.*?)=head1/s, $1);
  473. # Some pages have more than one OPTIONS section, let's make sure
  474. # to get them all
  475. my $options = '';
  476. while ( $contents =~ /=head1\s+[A-Z ]*?OPTIONS$(.*?)(?==head1)/msg ) {
  477. $options .= $1;
  478. }
  479. # Look for options with no or incorrect markup
  480. while ( $synopsis =~
  481. /(?<![-<[:alnum:]])-(?:$markup_re|.)*(?![->[:alnum:]])/msg ) {
  482. err($id, "Malformed option [1] in SYNOPSIS: $&");
  483. }
  484. my @synopsis;
  485. while ( $synopsis =~ /$markup_re/msg ) {
  486. my $found = $&;
  487. push @synopsis, $found if $found =~ /^B<-/;
  488. print STDERR "$id:DEBUG[option_check] SYNOPSIS: found $found\n"
  489. if $debug;
  490. my $option_uw = normalise_option($id, $filename, $found);
  491. err($id, "Malformed option [2] in SYNOPSIS: $found")
  492. if defined $option_uw && $option_uw eq '';
  493. }
  494. # In OPTIONS, we look for =item paragraphs.
  495. # (?=^\s*$) detects an empty line.
  496. my @options;
  497. while ( $options =~ /=item\s+(.*?)(?=^\s*$)/msg ) {
  498. my $item = $&;
  499. while ( $item =~ /(\[\s*)?($markup_re)/msg ) {
  500. my $found = $2;
  501. print STDERR "$id:DEBUG[option_check] OPTIONS: found $&\n"
  502. if $debug;
  503. err($id, "Unexpected bracket in OPTIONS =item: $item")
  504. if ($1 // '') ne '' && $found =~ /^B<\s*-/;
  505. my $option_uw = normalise_option($id, $filename, $found);
  506. err($id, "Malformed option in OPTIONS: $found")
  507. if defined $option_uw && $option_uw eq '';
  508. if ($found =~ /^B<-/) {
  509. push @options, $found;
  510. err($id, "OPTIONS entry $found missing from SYNOPSIS")
  511. unless (grep /^\Q$found\E$/, @synopsis)
  512. || $id =~ /(openssl|-options)\.pod:1:$/;
  513. }
  514. }
  515. }
  516. foreach (@synopsis) {
  517. my $option = $_;
  518. err($id, "SYNOPSIS entry $option missing from OPTIONS")
  519. unless (grep /^\Q$option\E$/, @options);
  520. }
  521. }
  522. # Normal symbol form
  523. my $symbol_re = qr/[[:alpha:]_][_[:alnum:]]*?/;
  524. # Checks of function name (man3) formatting. The man3 checks are
  525. # easier than the man1 checks, we only check the names followed by (),
  526. # and only the names that have POD markup.
  527. sub functionname_check {
  528. my $id = shift;
  529. my $filename = shift;
  530. my $contents = shift;
  531. while ( $contents =~ /($markup_re)\(\)/msg ) {
  532. print STDERR "$id:DEBUG[functionname_check] SYNOPSIS: found $&\n"
  533. if $debug;
  534. my $symbol = $1;
  535. my $unmarked = $symbol;
  536. $unmarked =~ s/[BIL]<|>//msg;
  537. err($id, "Malformed symbol: $symbol")
  538. unless $symbol =~ /^B<.*?>$/ && $unmarked =~ /^${symbol_re}$/
  539. }
  540. # We can't do the kind of collecting coolness that option_check()
  541. # does, because there are too many things that can't be found in
  542. # name repositories like the NAME sections, such as symbol names
  543. # with a variable part (typically marked up as B<foo_I<TYPE>_bar>
  544. }
  545. # This is from http://man7.org/linux/man-pages/man7/man-pages.7.html
  546. my %preferred_words = (
  547. '16bit' => '16-bit',
  548. 'a.k.a.' => 'aka',
  549. 'bitmask' => 'bit mask',
  550. 'builtin' => 'built-in',
  551. #'epoch' => 'Epoch', # handled specially, below
  552. 'fall-back' => 'fallback',
  553. 'file name' => 'filename',
  554. 'file system' => 'filesystem',
  555. 'host name' => 'hostname',
  556. 'i-node' => 'inode',
  557. 'lower case' => 'lowercase',
  558. 'lower-case' => 'lowercase',
  559. 'manpage' => 'man page',
  560. 'non-blocking' => 'nonblocking',
  561. 'non-default' => 'nondefault',
  562. 'non-empty' => 'nonempty',
  563. 'non-negative' => 'nonnegative',
  564. 'non-zero' => 'nonzero',
  565. 'path name' => 'pathname',
  566. 'pre-allocated' => 'preallocated',
  567. 'pseudo-terminal' => 'pseudoterminal',
  568. 'real time' => 'real-time',
  569. 'realtime' => 'real-time',
  570. 'reserved port' => 'privileged port',
  571. 'runtime' => 'run time',
  572. 'saved group ID'=> 'saved set-group-ID',
  573. 'saved set-GID' => 'saved set-group-ID',
  574. 'saved set-UID' => 'saved set-user-ID',
  575. 'saved user ID' => 'saved set-user-ID',
  576. 'set-GID' => 'set-group-ID',
  577. 'set-UID' => 'set-user-ID',
  578. 'setgid' => 'set-group-ID',
  579. 'setuid' => 'set-user-ID',
  580. 'sub-system' => 'subsystem',
  581. 'super block' => 'superblock',
  582. 'super-block' => 'superblock',
  583. 'super user' => 'superuser',
  584. 'super-user' => 'superuser',
  585. 'system port' => 'privileged port',
  586. 'time stamp' => 'timestamp',
  587. 'time zone' => 'timezone',
  588. 'upper case' => 'uppercase',
  589. 'upper-case' => 'uppercase',
  590. 'useable' => 'usable',
  591. 'user name' => 'username',
  592. 'userspace' => 'user space',
  593. 'zeroes' => 'zeros'
  594. );
  595. # Search manpage for words that have a different preferred use.
  596. sub wording {
  597. my $id = shift;
  598. my $contents = shift;
  599. foreach my $k ( keys %preferred_words ) {
  600. # Sigh, trademark
  601. next if $k eq 'file system'
  602. and $contents =~ /Microsoft Encrypted File System/;
  603. err($id, "Found '$k' should use '$preferred_words{$k}'")
  604. if $contents =~ /\b\Q$k\E\b/i;
  605. }
  606. err($id, "Found 'epoch' should use 'Epoch'")
  607. if $contents =~ /\bepoch\b/;
  608. if ( $id =~ m@man1/@ ) {
  609. err($id, "found 'tool' in NAME, should use 'command'")
  610. if $contents =~ /=head1 NAME.*\btool\b.*=head1 SYNOPSIS/s;
  611. err($id, "found 'utility' in NAME, should use 'command'")
  612. if $contents =~ /NAME.*\butility\b.*=head1 SYNOPSIS/s;
  613. }
  614. }
  615. # Perform all sorts of nit/error checks on a manpage
  616. sub check {
  617. my %podinfo = @_;
  618. my $filename = $podinfo{filename};
  619. my $dirname = basename(dirname($filename));
  620. my $contents = $podinfo{contents};
  621. # Find what section this page is in; presume 3.
  622. my $mansect = 3;
  623. $mansect = $1 if $filename =~ /man([1-9])/;
  624. my $id = "${filename}:1:";
  625. check_head_style($id, $contents);
  626. # Check ordering of some sections in man3
  627. if ( $mansect == 3 ) {
  628. check_section_location($id, $contents, "RETURN VALUES", "EXAMPLES");
  629. check_section_location($id, $contents, "SEE ALSO", "HISTORY");
  630. check_section_location($id, $contents, "EXAMPLES", "SEE ALSO");
  631. }
  632. # Make sure every link has a man section number.
  633. while ( $contents =~ /$markup_re/msg ) {
  634. my $target = $1;
  635. next unless $target =~ /^L<(.*)>$/; # Skip if not L<...>
  636. $target = $1; # Peal away L< and >
  637. $target =~ s/\/[^\/]*$//; # Peal away possible anchor
  638. $target =~ s/.*\|//g; # Peal away possible link text
  639. next if $target eq ''; # Skip if links within page, or
  640. next if $target =~ /::/; # links to a Perl module, or
  641. next if $target =~ /^https?:/; # is a URL link, or
  642. next if $target =~ /\([1357]\)$/; # it has a section
  643. err($id, "Missing man section number (likely, $mansect) in L<$target>")
  644. }
  645. # Check for proper links to commands.
  646. while ( $contents =~ /L<([^>]*)\(1\)(?:\/.*)?>/g ) {
  647. my $target = $1;
  648. next if $target =~ /openssl-?/;
  649. next if ( grep { basename($_) eq "$target.pod" }
  650. files(TAGS => [ 'manual', 'man1' ]) );
  651. next if $target =~ /ps|apropos|sha1sum|procmail|perl/;
  652. err($id, "Bad command link L<$target(1)>") if grep /man1/, @sections;
  653. }
  654. # Check for proper in-man-3 API links.
  655. while ( $contents =~ /L<([^>]*)\(3\)(?:\/.*)?>/g ) {
  656. my $target = $1;
  657. err($id, "Bad L<$target>")
  658. unless $target =~ /^[_[:alpha:]][_[:alnum:]]*$/
  659. }
  660. unless ( $contents =~ /^=for openssl generic/ms ) {
  661. if ( $mansect == 3 ) {
  662. name_synopsis($id, $filename, $contents);
  663. functionname_check($id, $filename, $contents);
  664. } elsif ( $mansect == 1 ) {
  665. option_check($id, $filename, $contents)
  666. }
  667. }
  668. wording($id, $contents);
  669. err($id, "Doesn't start with =pod")
  670. if $contents !~ /^=pod/;
  671. err($id, "Doesn't end with =cut")
  672. if $contents !~ /=cut\n$/;
  673. err($id, "More than one cut line.")
  674. if $contents =~ /=cut.*=cut/ms;
  675. err($id, "EXAMPLE not EXAMPLES section.")
  676. if $contents =~ /=head1 EXAMPLE[^S]/;
  677. err($id, "WARNING not WARNINGS section.")
  678. if $contents =~ /=head1 WARNING[^S]/;
  679. err($id, "Missing copyright")
  680. if $contents !~ /Copyright .* The OpenSSL Project Authors/;
  681. err($id, "Copyright not last")
  682. if $contents =~ /head1 COPYRIGHT.*=head/ms;
  683. err($id, "head2 in All uppercase")
  684. if $contents =~ /head2\s+[A-Z ]+\n/;
  685. err($id, "Extra space after head")
  686. if $contents =~ /=head\d\s\s+/;
  687. err($id, "Period in NAME section")
  688. if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
  689. err($id, "Duplicate $1 in L<>")
  690. if $contents =~ /L<([^>]*)\|([^>]*)>/ && $1 eq $2;
  691. err($id, "Bad =over $1")
  692. if $contents =~ /=over([^ ][^24])/;
  693. err($id, "Possible version style issue")
  694. if $contents =~ /OpenSSL version [019]/;
  695. if ( $contents !~ /=for openssl multiple includes/ ) {
  696. # Look for multiple consecutive openssl #include lines
  697. # (non-consecutive lines are okay; see man3/MD5.pod).
  698. if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
  699. my $count = 0;
  700. foreach my $line ( split /\n+/, $1 ) {
  701. if ( $line =~ m@include <openssl/@ ) {
  702. err($id, "Has multiple includes")
  703. if ++$count == 2;
  704. } else {
  705. $count = 0;
  706. }
  707. }
  708. }
  709. }
  710. open my $OUT, '>', $temp
  711. or die "Can't open $temp, $!";
  712. err($id, "POD errors")
  713. if podchecker($filename, $OUT) != 0;
  714. close $OUT;
  715. open $OUT, '<', $temp
  716. or die "Can't read $temp, $!";
  717. while ( <$OUT> ) {
  718. next if /\(section\) in.*deprecated/;
  719. print;
  720. }
  721. close $OUT;
  722. unlink $temp || warn "Can't remove $temp, $!";
  723. # Find what section this page is in; presume 3.
  724. my $section = 3;
  725. $section = $1 if $dirname =~ /man([1-9])/;
  726. foreach ( (@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}}) ) {
  727. err($id, "Missing $_ head1 section")
  728. if $contents !~ /^=head1\s+${_}\s*$/m;
  729. }
  730. }
  731. # Information database ###############################################
  732. # Map of links in each POD file; filename => [ "foo(1)", "bar(3)", ... ]
  733. my %link_map = ();
  734. # Map of names in each POD file or from "missing" files; possible values are:
  735. # If found in a POD files, "name(s)" => filename
  736. # If found in a "missing" file or external, "name(s)" => ''
  737. my %name_map = ();
  738. # State of man-page names.
  739. # %state is affected by loading util/*.num and util/*.syms
  740. # Values may be one of:
  741. # 'crypto' : belongs in libcrypto (loaded from libcrypto.num)
  742. # 'ssl' : belongs in libssl (loaded from libssl.num)
  743. # 'other' : belongs in libcrypto or libssl (loaded from other.syms)
  744. # 'internal' : Internal
  745. # 'public' : Public (generic name or external documentation)
  746. # Any of these values except 'public' may be prefixed with 'missing_'
  747. # to indicate that they are known to be missing.
  748. my %state;
  749. # %missing is affected by loading util/missing*.txt. Values may be one of:
  750. # 'crypto' : belongs in libcrypto (loaded from libcrypto.num)
  751. # 'ssl' : belongs in libssl (loaded from libssl.num)
  752. # 'other' : belongs in libcrypto or libssl (loaded from other.syms)
  753. # 'internal' : Internal
  754. my %missing;
  755. # Parse libcrypto.num, etc., and return sorted list of what's there.
  756. sub loadnum ($;$) {
  757. my $file = shift;
  758. my $type = shift;
  759. my @symbols;
  760. open my $IN, '<', catfile($config{sourcedir}, $file)
  761. or die "Can't open $file, $!, stopped";
  762. while ( <$IN> ) {
  763. next if /^#/;
  764. next if /\bNOEXIST\b/;
  765. my @fields = split();
  766. die "Malformed line $. in $file: $_"
  767. if scalar @fields != 2 && scalar @fields != 4;
  768. $state{$fields[0].'(3)'} = $type // 'internal';
  769. }
  770. close $IN;
  771. }
  772. # Load file of symbol names that we know aren't documented.
  773. sub loadmissing($;$)
  774. {
  775. my $missingfile = shift;
  776. my $type = shift;
  777. open FH, catfile($config{sourcedir}, $missingfile)
  778. or die "Can't open $missingfile";
  779. while ( <FH> ) {
  780. chomp;
  781. next if /^#/;
  782. $missing{$_} = $type // 'internal';
  783. }
  784. close FH;
  785. }
  786. # Check that we have consistent public / internal documentation and declaration
  787. sub checkstate () {
  788. # Collect all known names, no matter where they come from
  789. my %names = map { $_ => 1 } (keys %name_map, keys %state, keys %missing);
  790. # Check section 3, i.e. functions and macros
  791. foreach ( grep { $_ =~ /\(3\)$/ } sort keys %names ) {
  792. next if ( $name_map{$_} // '') eq '' || $_ =~ /$ignored/;
  793. # If a man-page isn't recorded public or if it's recorded missing
  794. # and internal, it's declared to be internal.
  795. my $declared_internal =
  796. ($state{$_} // 'internal') eq 'internal'
  797. || ($missing{$_} // '') eq 'internal';
  798. # If a man-page isn't recorded internal or if it's recorded missing
  799. # and not internal, it's declared to be public
  800. my $declared_public =
  801. ($state{$_} // 'internal') ne 'internal'
  802. || ($missing{$_} // 'internal') ne 'internal';
  803. err("$_ is supposedly public but is documented as internal")
  804. if ( $declared_public && $name_map{$_} =~ /\/internal\// );
  805. err("$_ is supposedly internal (maybe missing from other.syms) but is documented as public")
  806. if ( $declared_internal && $name_map{$_} !~ /\/internal\// );
  807. }
  808. }
  809. # Check for undocumented macros; ignore those in the "missing" file
  810. # and do simple check for #define in our header files.
  811. sub checkmacros {
  812. my $count = 0;
  813. my %seen;
  814. foreach my $f ( files(TAGS => 'public_header') ) {
  815. # Skip some internals we don't want to document yet.
  816. my $b = basename($f);
  817. next if $b eq 'asn1.h';
  818. next if $b eq 'asn1t.h';
  819. next if $b eq 'err.h';
  820. open(IN, $f)
  821. or die "Can't open $f, $!";
  822. while ( <IN> ) {
  823. next unless /^#\s*define\s*(\S+)\(/;
  824. my $macro = "$1(3)"; # We know they're all in section 3
  825. next if defined $name_map{$macro}
  826. || defined $missing{$macro}
  827. || defined $seen{$macro}
  828. || $macro =~ /$ignored/;
  829. err("$f:", "macro $macro undocumented")
  830. if $opt_d || $opt_e;
  831. $count++;
  832. $seen{$macro} = 1;
  833. }
  834. close(IN);
  835. }
  836. err("# $count macros undocumented (count is approximate)")
  837. if $count > 0;
  838. }
  839. # Find out what is undocumented (filtering out the known missing ones)
  840. # and display them.
  841. sub printem ($) {
  842. my $type = shift;
  843. my $count = 0;
  844. foreach my $func ( grep { $state{$_} eq $type } sort keys %state ) {
  845. next if defined $name_map{$func}
  846. || defined $missing{$func};
  847. err("$type:", "function $func undocumented")
  848. if $opt_d || $opt_e;
  849. $count++;
  850. }
  851. err("# $count lib$type names are not documented")
  852. if $count > 0;
  853. }
  854. # Collect all the names in a manpage.
  855. sub collectnames {
  856. my %podinfo = @_;
  857. my $filename = $podinfo{filename};
  858. $filename =~ m|man(\d)/|;
  859. my $section = $1;
  860. my $simplename = basename($filename, ".pod");
  861. my $id = "${filename}:1:";
  862. my $is_generic = $podinfo{contents} =~ /^=for openssl generic/ms;
  863. unless ( grep { $simplename eq $_ } @{$podinfo{names}} ) {
  864. err($id, "$simplename not in NAME section");
  865. push @{$podinfo{names}}, $simplename;
  866. }
  867. foreach my $name ( @{$podinfo{names}} ) {
  868. next if $name eq "";
  869. err($id, "'$name' contains whitespace")
  870. if $name =~ /\s/;
  871. my $name_sec = "$name($section)";
  872. if ( !defined $name_map{$name_sec} ) {
  873. $name_map{$name_sec} = $filename;
  874. $state{$name_sec} //=
  875. ( $filename =~ /\/internal\// ? 'internal' : 'public' )
  876. if $is_generic;
  877. } elsif ( $filename eq $name_map{$name_sec} ) {
  878. err($id, "$name_sec duplicated in NAME section of",
  879. $name_map{$name_sec});
  880. } elsif ( $name_map{$name_sec} ne '' ) {
  881. err($id, "$name_sec also in NAME section of",
  882. $name_map{$name_sec});
  883. }
  884. }
  885. if ( $podinfo{contents} =~ /=for openssl foreign manual (.*)\n/ ) {
  886. foreach my $f ( split / /, $1 ) {
  887. $name_map{$f} = ''; # It still exists!
  888. $state{$f} = 'public'; # We assume!
  889. }
  890. }
  891. my @links = ();
  892. # Don't use this regexp directly on $podinfo{contents}, as it causes
  893. # a regexp recursion, which fails on really big PODs. Instead, use
  894. # $markup_re to pick up general markup, and use this regexp to check
  895. # that the markup that was found is indeed a link.
  896. my $linkre = qr/L<
  897. # if the link is of the form L<something|name(s)>,
  898. # then remove 'something'. Note that 'something'
  899. # may contain POD codes as well...
  900. (?:(?:[^\|]|<[^>]*>)*\|)?
  901. # we're only interested in references that have
  902. # a one digit section number
  903. ([^\/>\(]+\(\d\))
  904. /x;
  905. while ( $podinfo{contents} =~ /$markup_re/msg ) {
  906. my $x = $1;
  907. if ($x =~ $linkre) {
  908. push @links, $1;
  909. }
  910. }
  911. $link_map{$filename} = [ @links ];
  912. }
  913. # Look for L<> ("link") references that point to files that do not exist.
  914. sub checklinks {
  915. foreach my $filename ( sort keys %link_map ) {
  916. foreach my $link ( @{$link_map{$filename}} ) {
  917. err("${filename}:1:", "reference to non-existing $link")
  918. unless defined $name_map{$link} || defined $missing{$link};
  919. err("${filename}:1:", "reference of internal $link in public documentation $filename")
  920. if ( ( ($state{$link} // '') eq 'internal'
  921. || ($missing{$link} // '') eq 'internal' )
  922. && $filename !~ /\/internal\// );
  923. }
  924. }
  925. }
  926. # Cipher/digests to skip if they show up as "not implemented"
  927. # because they are, via the "-*" construct.
  928. my %skips = (
  929. 'aes128' => 1,
  930. 'aes192' => 1,
  931. 'aes256' => 1,
  932. 'aria128' => 1,
  933. 'aria192' => 1,
  934. 'aria256' => 1,
  935. 'camellia128' => 1,
  936. 'camellia192' => 1,
  937. 'camellia256' => 1,
  938. 'des' => 1,
  939. 'des3' => 1,
  940. 'idea' => 1,
  941. 'cipher' => 1,
  942. 'digest' => 1,
  943. );
  944. my %genopts; # generic options parsed from apps/include/opt.h
  945. # Check the flags of a command and see if everything is in the manpage
  946. sub checkflags {
  947. my $cmd = shift;
  948. my $doc = shift;
  949. my @cmdopts;
  950. my %docopts;
  951. # Get the list of options in the command source file.
  952. my $active = 0;
  953. my $expect_helpstr = "";
  954. open CFH, "apps/$cmd.c"
  955. or die "Can't open apps/$cmd.c to list options for $cmd, $!";
  956. while ( <CFH> ) {
  957. chop;
  958. if ($active) {
  959. last if m/^\s*};/;
  960. if ($expect_helpstr ne "") {
  961. next if m/^\s*#\s*if/;
  962. err("$cmd does not implement help for -$expect_helpstr") unless m/^\s*"/;
  963. $expect_helpstr = "";
  964. }
  965. if (m/\{\s*"([^"]+)"\s*,\s*OPT_[A-Z0-9_]+\s*,\s*('[-\/:<>cAEfFlMnNpsuU]'|0)(.*)$/
  966. && !($cmd eq "s_client" && $1 eq "wdebug")) {
  967. push @cmdopts, $1;
  968. $expect_helpstr = $1;
  969. $expect_helpstr = "" if $3 =~ m/^\s*,\s*"/;
  970. } elsif (m/[\s,](OPT_[A-Z]+_OPTIONS?)\s*(,|$)/) {
  971. push @cmdopts, @{ $genopts{$1} };
  972. }
  973. } elsif (m/^const\s+OPTIONS\s*/) {
  974. $active = 1;
  975. }
  976. }
  977. close CFH;
  978. # Get the list of flags from the synopsis
  979. open CFH, "<$doc"
  980. or die "Can't open $doc, $!";
  981. while ( <CFH> ) {
  982. chop;
  983. last if /DESCRIPTION/;
  984. my $opt;
  985. if ( /\[B<-([^ >]+)/ ) {
  986. $opt = $1;
  987. } elsif ( /^B<-([^ >]+)/ ) {
  988. $opt = $1;
  989. } else {
  990. next;
  991. }
  992. $opt = $1 if $opt =~ /I<(.*)/;
  993. $docopts{$1} = 1;
  994. }
  995. close CFH;
  996. # See what's in the command not the manpage.
  997. my @undocced = sort grep { !defined $docopts{$_} } @cmdopts;
  998. foreach ( @undocced ) {
  999. err("$doc: undocumented $cmd option -$_");
  1000. }
  1001. # See what's in the manpage not the command.
  1002. my @unimpl = sort grep { my $e = $_; !(grep /^\Q$e\E$/, @cmdopts) } keys %docopts;
  1003. foreach ( @unimpl ) {
  1004. next if $_ eq "-"; # Skip the -- end-of-flags marker
  1005. next if defined $skips{$_};
  1006. err("$doc: $cmd does not implement -$_");
  1007. }
  1008. }
  1009. ##
  1010. ## MAIN()
  1011. ## Do the work requested by the various getopt flags.
  1012. ## The flags are parsed in alphabetical order, just because we have
  1013. ## to have *some way* of listing them.
  1014. ##
  1015. if ( $opt_c ) {
  1016. my @commands = ();
  1017. # Get the lists of generic options.
  1018. my $active = "";
  1019. open OFH, catdir($config{sourcedir}, "apps/include/opt.h")
  1020. or die "Can't open apps/include/opt.h to list generic options, $!";
  1021. while ( <OFH> ) {
  1022. chop;
  1023. push @{ $genopts{$active} }, $1 if $active ne "" && m/^\s+\{\s*"([^"]+)"\s*,\s*OPT_/;
  1024. $active = $1 if m/^\s*#\s*define\s+(OPT_[A-Z]+_OPTIONS?)\s*\\\s*$/;
  1025. $active = "" if m/^\s*$/;
  1026. }
  1027. close OFH;
  1028. # Get list of commands.
  1029. opendir(DIR, "apps");
  1030. @commands = grep(/\.c$/, readdir(DIR));
  1031. closedir(DIR);
  1032. # See if each has a manpage.
  1033. foreach my $cmd ( @commands ) {
  1034. $cmd =~ s/\.c$//;
  1035. next if $cmd eq 'progs' || $cmd eq 'vms_decc_init';
  1036. my @doc = ( grep { basename($_) eq "openssl-$cmd.pod"
  1037. # For "tsget" and "CA.pl" pod pages
  1038. || basename($_) eq "$cmd.pod" }
  1039. files(TAGS => [ 'manual', 'man1' ]) );
  1040. my $num = scalar @doc;
  1041. if ($num > 1) {
  1042. err("$num manuals for 'openssl $cmd': ".join(", ", @doc));
  1043. } elsif ($num < 1) {
  1044. err("no manual for 'openssl $cmd'");
  1045. } else {
  1046. checkflags($cmd, @doc);
  1047. }
  1048. }
  1049. }
  1050. # Populate %state
  1051. loadnum('util/libcrypto.num', 'crypto');
  1052. loadnum('util/libssl.num', 'ssl');
  1053. loadnum('util/other.syms', 'other');
  1054. loadnum('util/other-internal.syms');
  1055. if ( $opt_o ) {
  1056. loadmissing('util/missingmacro111.txt', 'crypto');
  1057. loadmissing('util/missingcrypto111.txt', 'crypto');
  1058. loadmissing('util/missingssl111.txt', 'ssl');
  1059. } elsif ( !$opt_u ) {
  1060. loadmissing('util/missingmacro.txt', 'crypto');
  1061. loadmissing('util/missingcrypto.txt', 'crypto');
  1062. loadmissing('util/missingssl.txt', 'ssl');
  1063. loadmissing('util/missingcrypto-internal.txt');
  1064. loadmissing('util/missingssl-internal.txt');
  1065. }
  1066. if ( $opt_n || $opt_l || $opt_u || $opt_v ) {
  1067. my @files_to_read = ( $opt_n && @ARGV ) ? @ARGV : files(TAGS => 'manual');
  1068. foreach (@files_to_read) {
  1069. my %podinfo = extract_pod_info($_, { debug => $debug });
  1070. collectnames(%podinfo)
  1071. if ( $opt_l || $opt_u || $opt_v );
  1072. check(%podinfo)
  1073. if ( $opt_n );
  1074. }
  1075. }
  1076. if ( $opt_l ) {
  1077. checklinks();
  1078. }
  1079. if ( $opt_n ) {
  1080. # If not given args, check that all man1 commands are named properly.
  1081. if ( scalar @ARGV == 0 && grep /man1/, @sections ) {
  1082. foreach ( files(TAGS => [ 'public_manual', 'man1' ]) ) {
  1083. next if /openssl\.pod/
  1084. || /CA\.pl/ || /tsget\.pod/; # these commands are special cases
  1085. err("$_ doesn't start with openssl-") unless /openssl-/;
  1086. }
  1087. }
  1088. }
  1089. checkstate();
  1090. if ( $opt_u || $opt_v) {
  1091. printem('crypto');
  1092. printem('ssl');
  1093. checkmacros();
  1094. }
  1095. exit $status;