#!/usr/bin/env perl
######################################################################
#
# Copyright 2002-2020 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
#
######################################################################
# DESCRIPTION: Edits pod2latex output

use warnings;

my $Opt_DistTitle = $ARGV[0] or die "%Error: No disttitle specified,";
my $Opt_DistDate = $ARGV[1] or die "%Error: No distdate specified,";

my $header =
    ("\\usepackage[left=1.0in,right=1.0in,top=1.0in,bottom=1.0in]{geometry}\n"
     ."\\usepackage[pdftex,bookmarks=true,bookmarksnumbered=true,hypertexnames=false,breaklinks=true,colorlinks=true,linkcolor=blue]{hyperref}\n"
     ."\\usepackage{fancyhdr} \\pagestyle{fancy}\n"
     ."\\usepackage{graphicx}\n"
     ."\n"
     ."\\setlength{\\parindent}{0pt} \\setlength{\\parskip}{\\baselineskip}\n"
     ."\n"
     ."\\title{\\includegraphics[width=6cm]{docs/verilator_logo.png}\\\\ ${Opt_DistTitle}}\n"
     ."\\date{${Opt_DistDate}}\n"
     ."\\author{https:\/\/verilator.org}\n"
     ."\\lhead[${Opt_DistTitle}]{${Opt_DistTitle}}\n"
    );

foreach my $line (<STDIN>) {
    $line =~ s/(\\begin\{document\})/${header}$1/;
    $line =~ s/(\\tableofcontents)/\\begin\{titlepage\} \\maketitle \\end\{titlepage\}\n$1/;
    print "$line";
}
