check-manpages 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #! /usr/bin/perl
  2. # $OpenBSD: check-manpages,v 1.7 2010/06/30 11:11:19 espie Exp $
  3. #
  4. # Copyright (c) 2004 Marc Espie <espie@openbsd.org>
  5. #
  6. # Permission to use, copy, modify, and distribute this software for any
  7. # purpose with or without fee is hereby granted, provided that the above
  8. # copyright notice and this permission notice appear in all copies.
  9. #
  10. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. #
  18. # check all manpages in existing packages
  19. use OpenBSD::AddCreateDelete;
  20. use OpenBSD::PackageInfo;
  21. use OpenBSD::PackingList;
  22. use OpenBSD::Ustar;
  23. use File::Temp;
  24. my $state = OpenBSD::AddCreateDelete::State->new('check-manpages');
  25. $state->handle_options('[-mnx]');
  26. $state->progress->set_header("Scanning packages");
  27. if (@ARGV==0) {
  28. @ARGV=(<*.tgz>);
  29. }
  30. my $extract_dir = File::Temp::tempdir("manpages.XXXXXXXXXXXX", DIR => '.');
  31. $state->say("Extracting all documentation into #1", $extract_dir);
  32. my %mandirs=();
  33. $state->progress->for_list("Scanning packages", \@ARGV,
  34. sub {
  35. my $pkgname = shift;
  36. my $true_package = $state->repo->find($pkgname);
  37. return unless $true_package;
  38. my $dir = $true_package->info;
  39. my $plist = OpenBSD::PackingList->fromfile($dir.CONTENTS);
  40. for my $item (@{$plist->{items}}) {
  41. next unless $item->IsFile;
  42. my $n = $item->fullname;
  43. if ($n =~ m,/man/(?:man.*?|cat.*?)/,) {
  44. my $file;
  45. do {
  46. $file = $true_package->next;
  47. } while ($file->{name} ne $item->{name});
  48. $file->{name} = $n;
  49. $n =~ m,^(.*/man)/(?:man.*?|cat.?)/,;
  50. $mandirs{"$extract_dir$1"} = 1;
  51. $file->{cwd} = $item->cwd;
  52. $file->{destdir} = $extract_dir;
  53. eval { $file->create; };
  54. }
  55. }
  56. $true_package->close;
  57. $true_package->wipe_info;
  58. $plist->forget;
  59. });
  60. $state->errsay("Running makewhatis in #1", join(' ', keys(%mandirs)));
  61. $state->system("/usr/libexec/makewhatis -p ".join(' ', keys(%mandirs)));