1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
#! /usr/bin/perl
#
# This script modifies the HTML man pages generated by pod2html. It
# adds a header and footer, and creates links to other man pages.
## @OPENSOURCE_LICENSE_START@
## libfixbuf 2.0
##
## Copyright 2018-2020 Carnegie Mellon University. All Rights Reserved.
##
## NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE
## ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS"
## BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND,
## EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT
## LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY,
## EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE
## MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF
## ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR
## COPYRIGHT INFRINGEMENT.
##
## Released under a GNU-Lesser GPL 3.0-style license, please see
## LICENSE.txt or contact permission@sei.cmu.edu for full terms.
##
## [DISTRIBUTION STATEMENT A] This material has been approved for
## public release and unlimited distribution. Please see Copyright
## notice for non-US Government use and distribution.
##
## Carnegie Mellon(R) and CERT(R) are registered in the U.S. Patent
## and Trademark Office by Carnegie Mellon University.
##
## DM18-0325
## @OPENSOURCE_LICENSE_END@
use warnings;
use strict;
use File::Temp qw//;
use File::Copy;
my $NAME = $0;
$NAME =~ s,.*/,,;
our $old = $ARGV[0];
unless ($old) {
die "Usage: $NAME <filename>\n\tAdd header and footer to named file\n";
}
open(OLD, '<', $old)
or die "$NAME: Cannot open '$old' for reading: $!\n";
our ($fh, $new) = File::Temp::tempfile(UNLINK => 1)
or die "$NAME: Unable to create a temporary file: $!\n";
*NEW = $fh;
do_manpage();
close OLD;
close NEW
or die "$NAME: Cannot close '$new': $!\n";
move $new, $old
or die "$NAME: Cannot move '$old' to '$new': $!\n";
exit;
sub add_header
{
my ($title) = @_;
if ($title)
{
$title = "Documentation - $title";
}
else
{
$title = "Documentation";
}
return <<EOF;
<head>
<title>fixbuf - $title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="../site/style.css" />
</head>
<body>
<div id="p-body">
<div id="l-header">
<img src="../site/sei-logo.png" id="l-sei-logo"
alt="Software Engineering Institute | Carnegie Mellon©" />
<div id="l-netsa-logo"><a id="l-netsa-name" href="../index.html"><b>CERT NetSA Security Suite</b></a></div>
<div id="l-netsa-motto">Monitoring for Large-Scale Networks</div>
<h1 class="l-page-title">fixbuf</h1>
<span id="l-subtitle">Documentation</span>
</div><!-- l-header -->
<div id="l-content">
<div id="l-sidebar">
<div class="p-sidebar-section">
<h1><a href="index.html">fixbuf</a></h1>
<ul>
<li><a href="libfixbuf/index.html">Documentation</a></li>
<li><a href="../download.html">Downloads</a></li>
<li><a href="../../pyfixbuf/index.html">pyfixbuf</a></li>
</ul>
</div><!-- p-sidebar-section -->
</div><!-- l-sidebar -->
EOF
}
sub add_footer
{
return <<EOF;
</div><!-- l-content -->
<div id="l-footer">
© 2006-2020 Carnegie Mellon University
<span id="l-contact">
<a href="https://www.sei.cmu.edu/legal/index.cfm">Legal</a> |
<a href="https://www.sei.cmu.edu/legal/privacy-notice/index.cfm">Privacy Notice</a> |
<img alt="email address" src="/site/contact_email.png" />
</span>
</div>
</div><!-- p-body -->
</body>
EOF
}
sub do_manpage
{
# We'll overwrite this with name of man page
my $title = '';
# ignore everything until we get to the end of the index, but do
# cash the title
my $saw_index = 0;
# whether we saw the <head>
my $saw_head = 0;
$/ = ""; # read one paragraph at a time
while (<OLD>) {
# # Downgrade all <Hn> tags by one
# s{(</?h)(\d)\b([^>]*>)}{$1.($2 +1 ).$3}gieo;
# Get rid of any mailto: links
s{<link[^>]+mailto:[^>]+>}{}i;
# Remove all <hr>
s{<hr\b[^>]*>}{}iog;
# # Change <a name> to <a id>
# s{<a name="}{<a id="}iog;
# Make links to other man pages
#s{(<strong>$man_re\(\d\)</strong>)}{<a href="$2.html">$1</a>}og;
# Stash the title
if (m{<title>(.+)</title>}io) {
$title = $1;
}
# Don't print anything until we see the Perl-generated index
if ( !$saw_index) {
#old perldoc
if (m{(<!-- INDEX END -->)}) {
$saw_index = 1;
print NEW add_header($title);
next;
}
next unless m{(<h1 id="NAME">NAME</h1>)};
$saw_index = 1;
print NEW add_header($title);
print NEW "<h1><a name=\"name\">NAME</a></h1>";
next;
}
s{</body\b[^>]*>}{add_footer()}eio;
print NEW;
}
}
# do_manpage
|