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