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