2
0

mkpod2html.pl 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #! /usr/bin/env perl
  2. # Copyright 2020 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. use strict;
  9. use warnings;
  10. use lib ".";
  11. use Getopt::Std;
  12. use Pod::Html;
  13. use File::Spec::Functions qw(:DEFAULT rel2abs);
  14. # Options.
  15. our($opt_i); # -i INFILE
  16. our($opt_o); # -o OUTFILE
  17. our($opt_t); # -t TITLE
  18. our($opt_r); # -r PODROOT
  19. getopts('i:o:t:r:');
  20. die "-i flag missing" unless $opt_i;
  21. die "-o flag missing" unless $opt_o;
  22. die "-t flag missing" unless $opt_t;
  23. die "-r flag missing" unless $opt_r;
  24. # We originally used realpath() here, but the Windows implementation appears
  25. # to require that the directory or file exist to be able to process the input,
  26. # so we use rel2abs() instead, which only processes the string without
  27. # looking further.
  28. $opt_i = rel2abs($opt_i) or die "Can't convert to real path: $!";
  29. $opt_o = rel2abs($opt_o) or die "Can't convert to real path: $!";
  30. $opt_r = rel2abs($opt_r) or die "Can't convert to real path: $!";
  31. pod2html
  32. "--infile=$opt_i",
  33. "--outfile=$opt_o",
  34. "--title=$opt_t",
  35. "--podroot=$opt_r",
  36. "--podpath=man1:man3:man5:man7",
  37. "--htmldir=..";
  38. # Read in contents.
  39. open F, "<$opt_o"
  40. or die "Can't read $opt_o, $!";
  41. my $contents = '';
  42. {
  43. local $/ = undef;
  44. $contents = <F>;
  45. }
  46. close F;
  47. unlink $opt_o;
  48. $contents =~
  49. s|href="http://man\.he\.net/(man\d/[^"]+)(?:\.html)?"|href="../$1.html"|g;
  50. open F, ">$opt_o"
  51. or die "Can't write $opt_o, $!";
  52. print F $contents;
  53. close F;