1 1.1 christos #! /usr/bin/env perl 2 1.1 christos # Copyright 2020 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos # 4 1.1 christos # Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos # this file except in compliance with the License. You can obtain a copy 6 1.1 christos # in the file LICENSE in the source distribution or at 7 1.1 christos # https://www.openssl.org/source/license.html 8 1.1 christos 9 1.1 christos use strict; 10 1.1 christos use warnings; 11 1.1 christos 12 1.1 christos use lib "."; 13 1.1 christos use Getopt::Std; 14 1.1 christos use Pod::Html; 15 1.1 christos use File::Spec::Functions qw(:DEFAULT rel2abs); 16 1.1 christos 17 1.1 christos # Options. 18 1.1 christos our($opt_i); # -i INFILE 19 1.1 christos our($opt_o); # -o OUTFILE 20 1.1 christos our($opt_t); # -t TITLE 21 1.1 christos our($opt_r); # -r PODROOT 22 1.1 christos 23 1.1 christos getopts('i:o:t:r:'); 24 1.1 christos die "-i flag missing" unless $opt_i; 25 1.1 christos die "-o flag missing" unless $opt_o; 26 1.1 christos die "-t flag missing" unless $opt_t; 27 1.1 christos die "-r flag missing" unless $opt_r; 28 1.1 christos 29 1.1 christos # We originally used realpath() here, but the Windows implementation appears 30 1.1 christos # to require that the directory or file exist to be able to process the input, 31 1.1 christos # so we use rel2abs() instead, which only processes the string without 32 1.1 christos # looking further. 33 1.1 christos $opt_i = rel2abs($opt_i) or die "Can't convert to real path: $!"; 34 1.1 christos $opt_o = rel2abs($opt_o) or die "Can't convert to real path: $!"; 35 1.1 christos $opt_r = rel2abs($opt_r) or die "Can't convert to real path: $!"; 36 1.1 christos 37 1.1 christos pod2html 38 1.1 christos "--infile=$opt_i", 39 1.1 christos "--outfile=$opt_o", 40 1.1 christos "--title=$opt_t", 41 1.1 christos "--podroot=$opt_r", 42 1.1 christos "--podpath=man1:man3:man5:man7", 43 1.1 christos "--htmldir=.."; 44 1.1 christos 45 1.1 christos # Read in contents. 46 1.1 christos open F, "<$opt_o" 47 1.1 christos or die "Can't read $opt_o, $!"; 48 1.1 christos my $contents = ''; 49 1.1 christos { 50 1.1 christos local $/ = undef; 51 1.1 christos $contents = <F>; 52 1.1 christos } 53 1.1 christos close F; 54 1.1 christos unlink $opt_o; 55 1.1 christos 56 1.1 christos $contents =~ 57 1.1 christos s|href="http://man\.he\.net/(man\d/[^"]+)(?:\.html)?"|href="../$1.html"|g; 58 1.1 christos open F, ">$opt_o" 59 1.1 christos or die "Can't write $opt_o, $!"; 60 1.1 christos print F $contents; 61 1.1 christos close F; 62