xref: /openssl/util/mkpod2html.pl (revision dc18f036)
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
9use strict;
10use warnings;
11
12use lib ".";
13use Getopt::Std;
14use Pod::Html;
15use File::Spec::Functions qw(:DEFAULT rel2abs);
16
17# Options.
18our($opt_i);    # -i INFILE
19our($opt_o);    # -o OUTFILE
20our($opt_t);    # -t TITLE
21our($opt_r);    # -r PODROOT
22
23getopts('i:o:t:r:');
24die "-i flag missing" unless $opt_i;
25die "-o flag missing" unless $opt_o;
26die "-t flag missing" unless $opt_t;
27die "-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
37pod2html
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.
46open F, "<$opt_o"
47    or die "Can't read $opt_o, $!";
48my $contents = '';
49{
50    local $/ = undef;
51    $contents = <F>;
52}
53close F;
54unlink $opt_o;
55
56$contents =~
57    s|href="http://man\.he\.net/(man\d/[^"]+)(?:\.html)?"|href="../$1.html"|g;
58open F, ">$opt_o"
59    or die "Can't write $opt_o, $!";
60print F $contents;
61close F;
62