find-doc-nits 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. #! /usr/bin/env perl
  2. # Copyright 2002-2021 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', 'DESCRIPTION', 'COPYRIGHT' ],
  75. 1 => [ 'SYNOPSIS', 'OPTIONS' ],
  76. 3 => [ 'SYNOPSIS', 'RETURN VALUES' ],
  77. 5 => [ ],
  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. my $id = "${filename}:1:";
  622. check_head_style($id, $contents);
  623. # Check ordering of some sections in man3
  624. if ( $filename =~ m|man3/| ) {
  625. check_section_location($id, $contents, "RETURN VALUES", "EXAMPLES");
  626. check_section_location($id, $contents, "SEE ALSO", "HISTORY");
  627. check_section_location($id, $contents, "EXAMPLES", "SEE ALSO");
  628. }
  629. # Make sure every link has a section.
  630. while ( $contents =~ /$markup_re/msg ) {
  631. my $target = $1;
  632. next unless $target =~ /^L<(.*)>$/; # Skip if not L<...>
  633. $target = $1; # Peal away L< and >
  634. $target =~ s/\/[^\/]*$//; # Peal away possible anchor
  635. $target =~ s/.*\|//g; # Peal away possible link text
  636. next if $target eq ''; # Skip if links within page, or
  637. next if $target =~ /::/; # links to a Perl module, or
  638. next if $target =~ /^https?:/; # is a URL link, or
  639. next if $target =~ /\([1357]\)$/; # it has a section
  640. err($id, "Section missing in $target")
  641. }
  642. # Check for proper links to commands.
  643. while ( $contents =~ /L<([^>]*)\(1\)(?:\/.*)?>/g ) {
  644. my $target = $1;
  645. next if $target =~ /openssl-?/;
  646. next if ( grep { basename($_) eq "$target.pod" }
  647. files(TAGS => [ 'manual', 'man1' ]) );
  648. next if $target =~ /ps|apropos|sha1sum|procmail|perl/;
  649. err($id, "Bad command link L<$target(1)>") if grep /man1/, @sections;
  650. }
  651. # Check for proper in-man-3 API links.
  652. while ( $contents =~ /L<([^>]*)\(3\)(?:\/.*)?>/g ) {
  653. my $target = $1;
  654. err($id, "Bad L<$target>")
  655. unless $target =~ /^[_[:alpha:]][_[:alnum:]]*$/
  656. }
  657. unless ( $contents =~ /^=for openssl generic/ms ) {
  658. if ( $filename =~ m|man3/| ) {
  659. name_synopsis($id, $filename, $contents);
  660. functionname_check($id, $filename, $contents);
  661. } elsif ( $filename =~ m|man1/| ) {
  662. option_check($id, $filename, $contents)
  663. }
  664. }
  665. wording($id, $contents);
  666. err($id, "Doesn't start with =pod")
  667. if $contents !~ /^=pod/;
  668. err($id, "Doesn't end with =cut")
  669. if $contents !~ /=cut\n$/;
  670. err($id, "More than one cut line.")
  671. if $contents =~ /=cut.*=cut/ms;
  672. err($id, "EXAMPLE not EXAMPLES section.")
  673. if $contents =~ /=head1 EXAMPLE[^S]/;
  674. err($id, "WARNING not WARNINGS section.")
  675. if $contents =~ /=head1 WARNING[^S]/;
  676. err($id, "Missing copyright")
  677. if $contents !~ /Copyright .* The OpenSSL Project Authors/;
  678. err($id, "Copyright not last")
  679. if $contents =~ /head1 COPYRIGHT.*=head/ms;
  680. err($id, "head2 in All uppercase")
  681. if $contents =~ /head2\s+[A-Z ]+\n/;
  682. err($id, "Extra space after head")
  683. if $contents =~ /=head\d\s\s+/;
  684. err($id, "Period in NAME section")
  685. if $contents =~ /=head1 NAME.*\.\n.*=head1 SYNOPSIS/ms;
  686. err($id, "Duplicate $1 in L<>")
  687. if $contents =~ /L<([^>]*)\|([^>]*)>/ && $1 eq $2;
  688. err($id, "Bad =over $1")
  689. if $contents =~ /=over([^ ][^24])/;
  690. err($id, "Possible version style issue")
  691. if $contents =~ /OpenSSL version [019]/;
  692. if ( $contents !~ /=for openssl multiple includes/ ) {
  693. # Look for multiple consecutive openssl #include lines
  694. # (non-consecutive lines are okay; see man3/MD5.pod).
  695. if ( $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms ) {
  696. my $count = 0;
  697. foreach my $line ( split /\n+/, $1 ) {
  698. if ( $line =~ m@include <openssl/@ ) {
  699. err($id, "Has multiple includes")
  700. if ++$count == 2;
  701. } else {
  702. $count = 0;
  703. }
  704. }
  705. }
  706. }
  707. open my $OUT, '>', $temp
  708. or die "Can't open $temp, $!";
  709. err($id, "POD errors")
  710. if podchecker($filename, $OUT) != 0;
  711. close $OUT;
  712. open $OUT, '<', $temp
  713. or die "Can't read $temp, $!";
  714. while ( <$OUT> ) {
  715. next if /\(section\) in.*deprecated/;
  716. print;
  717. }
  718. close $OUT;
  719. unlink $temp || warn "Can't remove $temp, $!";
  720. # Find what section this page is in; assume 3.
  721. my $section = 3;
  722. $section = $1 if $dirname =~ /man([1-9])/;
  723. foreach ( (@{$mandatory_sections{'*'}}, @{$mandatory_sections{$section}}) ) {
  724. err($id, "Missing $_ head1 section")
  725. if $contents !~ /^=head1\s+${_}\s*$/m;
  726. }
  727. }
  728. # Information database ###############################################
  729. # Map of links in each POD file; filename => [ "foo(1)", "bar(3)", ... ]
  730. my %link_map = ();
  731. # Map of names in each POD file or from "missing" files; possible values are:
  732. # If found in a POD files, "name(s)" => filename
  733. # If found in a "missing" file or external, "name(s)" => ''
  734. my %name_map = ();
  735. # State of man-page names.
  736. # %state is affected by loading util/*.num and util/*.syms
  737. # Values may be one of:
  738. # 'crypto' : belongs in libcrypto (loaded from libcrypto.num)
  739. # 'ssl' : belongs in libssl (loaded from libssl.num)
  740. # 'other' : belongs in libcrypto or libssl (loaded from other.syms)
  741. # 'internal' : Internal
  742. # 'public' : Public (generic name or external documentation)
  743. # Any of these values except 'public' may be prefixed with 'missing_'
  744. # to indicate that they are known to be missing.
  745. my %state;
  746. # %missing is affected by loading util/missing*.txt. Values may be one of:
  747. # 'crypto' : belongs in libcrypto (loaded from libcrypto.num)
  748. # 'ssl' : belongs in libssl (loaded from libssl.num)
  749. # 'other' : belongs in libcrypto or libssl (loaded from other.syms)
  750. # 'internal' : Internal
  751. my %missing;
  752. # Parse libcrypto.num, etc., and return sorted list of what's there.
  753. sub loadnum ($;$) {
  754. my $file = shift;
  755. my $type = shift;
  756. my @symbols;
  757. open my $IN, '<', catfile($config{sourcedir}, $file)
  758. or die "Can't open $file, $!, stopped";
  759. while ( <$IN> ) {
  760. next if /^#/;
  761. next if /\bNOEXIST\b/;
  762. my @fields = split();
  763. die "Malformed line $. in $file: $_"
  764. if scalar @fields != 2 && scalar @fields != 4;
  765. $state{$fields[0].'(3)'} = $type // 'internal';
  766. }
  767. close $IN;
  768. }
  769. # Load file of symbol names that we know aren't documented.
  770. sub loadmissing($;$)
  771. {
  772. my $missingfile = shift;
  773. my $type = shift;
  774. open FH, catfile($config{sourcedir}, $missingfile)
  775. or die "Can't open $missingfile";
  776. while ( <FH> ) {
  777. chomp;
  778. next if /^#/;
  779. $missing{$_} = $type // 'internal';
  780. }
  781. close FH;
  782. }
  783. # Check that we have consistent public / internal documentation and declaration
  784. sub checkstate () {
  785. # Collect all known names, no matter where they come from
  786. my %names = map { $_ => 1 } (keys %name_map, keys %state, keys %missing);
  787. # Check section 3, i.e. functions and macros
  788. foreach ( grep { $_ =~ /\(3\)$/ } sort keys %names ) {
  789. next if ( $name_map{$_} // '') eq '' || $_ =~ /$ignored/;
  790. # If a man-page isn't recorded public or if it's recorded missing
  791. # and internal, it's declared to be internal.
  792. my $declared_internal =
  793. ($state{$_} // 'internal') eq 'internal'
  794. || ($missing{$_} // '') eq 'internal';
  795. # If a man-page isn't recorded internal or if it's recorded missing
  796. # and not internal, it's declared to be public
  797. my $declared_public =
  798. ($state{$_} // 'internal') ne 'internal'
  799. || ($missing{$_} // 'internal') ne 'internal';
  800. err("$_ is supposedly public but is documented as internal")
  801. if ( $declared_public && $name_map{$_} =~ /\/internal\// );
  802. err("$_ is supposedly internal (maybe missing from other.syms) but is documented as public")
  803. if ( $declared_internal && $name_map{$_} !~ /\/internal\// );
  804. }
  805. }
  806. # Check for undocumented macros; ignore those in the "missing" file
  807. # and do simple check for #define in our header files.
  808. sub checkmacros {
  809. my $count = 0;
  810. my %seen;
  811. foreach my $f ( files(TAGS => 'public_header') ) {
  812. # Skip some internals we don't want to document yet.
  813. my $b = basename($f);
  814. next if $b eq 'asn1.h';
  815. next if $b eq 'asn1t.h';
  816. next if $b eq 'err.h';
  817. open(IN, $f)
  818. or die "Can't open $f, $!";
  819. while ( <IN> ) {
  820. next unless /^#\s*define\s*(\S+)\(/;
  821. my $macro = "$1(3)"; # We know they're all in section 3
  822. next if defined $name_map{$macro}
  823. || defined $missing{$macro}
  824. || defined $seen{$macro}
  825. || $macro =~ /$ignored/;
  826. err("$f:", "macro $macro undocumented")
  827. if $opt_d || $opt_e;
  828. $count++;
  829. $seen{$macro} = 1;
  830. }
  831. close(IN);
  832. }
  833. err("# $count macros undocumented (count is approximate)")
  834. if $count > 0;
  835. }
  836. # Find out what is undocumented (filtering out the known missing ones)
  837. # and display them.
  838. sub printem ($) {
  839. my $type = shift;
  840. my $count = 0;
  841. foreach my $func ( grep { $state{$_} eq $type } sort keys %state ) {
  842. next if defined $name_map{$func}
  843. || defined $missing{$func};
  844. err("$type:", "function $func undocumented")
  845. if $opt_d || $opt_e;
  846. $count++;
  847. }
  848. err("# $count lib$type names are not documented")
  849. if $count > 0;
  850. }
  851. # Collect all the names in a manpage.
  852. sub collectnames {
  853. my %podinfo = @_;
  854. my $filename = $podinfo{filename};
  855. $filename =~ m|man(\d)/|;
  856. my $section = $1;
  857. my $simplename = basename($filename, ".pod");
  858. my $id = "${filename}:1:";
  859. my $is_generic = $podinfo{contents} =~ /^=for openssl generic/ms;
  860. unless ( grep { $simplename eq $_ } @{$podinfo{names}} ) {
  861. err($id, "$simplename not in NAME section");
  862. push @{$podinfo{names}}, $simplename;
  863. }
  864. foreach my $name ( @{$podinfo{names}} ) {
  865. next if $name eq "";
  866. err($id, "'$name' contains whitespace")
  867. if $name =~ /\s/;
  868. my $name_sec = "$name($section)";
  869. if ( !defined $name_map{$name_sec} ) {
  870. $name_map{$name_sec} = $filename;
  871. $state{$name_sec} //=
  872. ( $filename =~ /\/internal\// ? 'internal' : 'public' )
  873. if $is_generic;
  874. } elsif ( $filename eq $name_map{$name_sec} ) {
  875. err($id, "$name_sec duplicated in NAME section of",
  876. $name_map{$name_sec});
  877. } elsif ( $name_map{$name_sec} ne '' ) {
  878. err($id, "$name_sec also in NAME section of",
  879. $name_map{$name_sec});
  880. }
  881. }
  882. if ( $podinfo{contents} =~ /=for openssl foreign manual (.*)\n/ ) {
  883. foreach my $f ( split / /, $1 ) {
  884. $name_map{$f} = ''; # It still exists!
  885. $state{$f} = 'public'; # We assume!
  886. }
  887. }
  888. my @links = ();
  889. # Don't use this regexp directly on $podinfo{contents}, as it causes
  890. # a regexp recursion, which fails on really big PODs. Instead, use
  891. # $markup_re to pick up general markup, and use this regexp to check
  892. # that the markup that was found is indeed a link.
  893. my $linkre = qr/L<
  894. # if the link is of the form L<something|name(s)>,
  895. # then remove 'something'. Note that 'something'
  896. # may contain POD codes as well...
  897. (?:(?:[^\|]|<[^>]*>)*\|)?
  898. # we're only interested in references that have
  899. # a one digit section number
  900. ([^\/>\(]+\(\d\))
  901. /x;
  902. while ( $podinfo{contents} =~ /$markup_re/msg ) {
  903. my $x = $1;
  904. if ($x =~ $linkre) {
  905. push @links, $1;
  906. }
  907. }
  908. $link_map{$filename} = [ @links ];
  909. }
  910. # Look for L<> ("link") references that point to files that do not exist.
  911. sub checklinks {
  912. foreach my $filename ( sort keys %link_map ) {
  913. foreach my $link ( @{$link_map{$filename}} ) {
  914. err("${filename}:1:", "reference to non-existing $link")
  915. unless defined $name_map{$link} || defined $missing{$link};
  916. err("${filename}:1:", "reference of internal $link in public documentation $filename")
  917. if ( ( ($state{$link} // '') eq 'internal'
  918. || ($missing{$link} // '') eq 'internal' )
  919. && $filename !~ /\/internal\// );
  920. }
  921. }
  922. }
  923. # Cipher/digests to skip if they show up as "not implemented"
  924. # because they are, via the "-*" construct.
  925. my %skips = (
  926. 'aes128' => 1,
  927. 'aes192' => 1,
  928. 'aes256' => 1,
  929. 'aria128' => 1,
  930. 'aria192' => 1,
  931. 'aria256' => 1,
  932. 'camellia128' => 1,
  933. 'camellia192' => 1,
  934. 'camellia256' => 1,
  935. 'des' => 1,
  936. 'des3' => 1,
  937. 'idea' => 1,
  938. 'cipher' => 1,
  939. 'digest' => 1,
  940. );
  941. my %genopts; # generic options parsed from apps/include/opt.h
  942. # Check the flags of a command and see if everything is in the manpage
  943. sub checkflags {
  944. my $cmd = shift;
  945. my $doc = shift;
  946. my @cmdopts;
  947. my %docopts;
  948. # Get the list of options in the command source file.
  949. my $active = 0;
  950. my $expect_helpstr = "";
  951. open CFH, "apps/$cmd.c"
  952. or die "Can't open apps/$cmd.c to list options for $cmd, $!";
  953. while ( <CFH> ) {
  954. chop;
  955. if ($active) {
  956. last if m/^\s*};/;
  957. if ($expect_helpstr ne "") {
  958. next if m/^\s*#\s*if/;
  959. err("$cmd does not implement help for -$expect_helpstr") unless m/^\s*"/;
  960. $expect_helpstr = "";
  961. }
  962. if (m/\{\s*"([^"]+)"\s*,\s*OPT_[A-Z0-9_]+\s*,\s*('[-\/:<>cEfFlMnNpsuU]'|0)(.*)$/
  963. && !($cmd eq "s_client" && $1 eq "wdebug")) {
  964. push @cmdopts, $1;
  965. $expect_helpstr = $1;
  966. $expect_helpstr = "" if $3 =~ m/^\s*,\s*"/;
  967. } elsif (m/[\s,](OPT_[A-Z]+_OPTIONS?)\s*(,|$)/) {
  968. push @cmdopts, @{ $genopts{$1} };
  969. }
  970. } elsif (m/^const\s+OPTIONS\s*/) {
  971. $active = 1;
  972. }
  973. }
  974. close CFH;
  975. # Get the list of flags from the synopsis
  976. open CFH, "<$doc"
  977. or die "Can't open $doc, $!";
  978. while ( <CFH> ) {
  979. chop;
  980. last if /DESCRIPTION/;
  981. my $opt;
  982. if ( /\[B<-([^ >]+)/ ) {
  983. $opt = $1;
  984. } elsif ( /^B<-([^ >]+)/ ) {
  985. $opt = $1;
  986. } else {
  987. next;
  988. }
  989. $opt = $1 if $opt =~ /I<(.*)/;
  990. $docopts{$1} = 1;
  991. }
  992. close CFH;
  993. # See what's in the command not the manpage.
  994. my @undocced = sort grep { !defined $docopts{$_} } @cmdopts;
  995. foreach ( @undocced ) {
  996. err("$doc: undocumented $cmd option -$_");
  997. }
  998. # See what's in the command not the manpage.
  999. my @unimpl = sort grep { my $e = $_; !(grep /^\Q$e\E$/, @cmdopts) } keys %docopts;
  1000. foreach ( @unimpl ) {
  1001. next if $_ eq "-"; # Skip the -- end-of-flags marker
  1002. next if defined $skips{$_};
  1003. err("$doc: $cmd does not implement -$_");
  1004. }
  1005. }
  1006. ##
  1007. ## MAIN()
  1008. ## Do the work requested by the various getopt flags.
  1009. ## The flags are parsed in alphabetical order, just because we have
  1010. ## to have *some way* of listing them.
  1011. ##
  1012. if ( $opt_c ) {
  1013. my @commands = ();
  1014. # Get the lists of generic options.
  1015. my $active = "";
  1016. open OFH, catdir($config{sourcedir}, "apps/include/opt.h")
  1017. or die "Can't open apps/include/opt.h to list generic options, $!";
  1018. while ( <OFH> ) {
  1019. chop;
  1020. push @{ $genopts{$active} }, $1 if $active ne "" && m/^\s+\{\s*"([^"]+)"\s*,\s*OPT_/;
  1021. $active = $1 if m/^\s*#\s*define\s+(OPT_[A-Z]+_OPTIONS?)\s*\\\s*$/;
  1022. $active = "" if m/^\s*$/;
  1023. }
  1024. close OFH;
  1025. # Get list of commands.
  1026. opendir(DIR, "apps");
  1027. @commands = grep(/\.c$/, readdir(DIR));
  1028. closedir(DIR);
  1029. # See if each has a manpage.
  1030. foreach my $cmd ( @commands ) {
  1031. $cmd =~ s/\.c$//;
  1032. next if $cmd eq 'progs' || $cmd eq 'vms_decc_init';
  1033. my @doc = ( grep { basename($_) eq "openssl-$cmd.pod"
  1034. # For "tsget" and "CA.pl" pod pages
  1035. || basename($_) eq "$cmd.pod" }
  1036. files(TAGS => [ 'manual', 'man1' ]) );
  1037. my $num = scalar @doc;
  1038. if ($num > 1) {
  1039. err("$num manuals for 'openssl $cmd': ".join(", ", @doc));
  1040. } elsif ($num < 1) {
  1041. err("no manual for 'openssl $cmd'");
  1042. } else {
  1043. checkflags($cmd, @doc);
  1044. }
  1045. }
  1046. }
  1047. # Populate %state
  1048. loadnum('util/libcrypto.num', 'crypto');
  1049. loadnum('util/libssl.num', 'ssl');
  1050. loadnum('util/other.syms', 'other');
  1051. loadnum('util/other-internal.syms');
  1052. if ( $opt_o ) {
  1053. loadmissing('util/missingmacro111.txt', 'crypto');
  1054. loadmissing('util/missingcrypto111.txt', 'crypto');
  1055. loadmissing('util/missingssl111.txt', 'ssl');
  1056. } elsif ( !$opt_u ) {
  1057. loadmissing('util/missingmacro.txt', 'crypto');
  1058. loadmissing('util/missingcrypto.txt', 'crypto');
  1059. loadmissing('util/missingssl.txt', 'ssl');
  1060. loadmissing('util/missingcrypto-internal.txt');
  1061. loadmissing('util/missingssl-internal.txt');
  1062. }
  1063. if ( $opt_n || $opt_l || $opt_u || $opt_v ) {
  1064. my @files_to_read = ( $opt_n && @ARGV ) ? @ARGV : files(TAGS => 'manual');
  1065. foreach (@files_to_read) {
  1066. my %podinfo = extract_pod_info($_, { debug => $debug });
  1067. collectnames(%podinfo)
  1068. if ( $opt_l || $opt_u || $opt_v );
  1069. check(%podinfo)
  1070. if ( $opt_n );
  1071. }
  1072. }
  1073. if ( $opt_l ) {
  1074. checklinks();
  1075. }
  1076. if ( $opt_n ) {
  1077. # If not given args, check that all man1 commands are named properly.
  1078. if ( scalar @ARGV == 0 && grep /man1/, @sections ) {
  1079. foreach ( files(TAGS => [ 'public_manual', 'man1' ]) ) {
  1080. next if /openssl\.pod/
  1081. || /CA\.pl/ || /tsget\.pod/; # these commands are special cases
  1082. err("$_ doesn't start with openssl-") unless /openssl-/;
  1083. }
  1084. }
  1085. }
  1086. checkstate();
  1087. if ( $opt_u || $opt_v) {
  1088. printem('crypto');
  1089. printem('ssl');
  1090. checkmacros();
  1091. }
  1092. exit $status;