Last active
November 25, 2016 13:43
-
-
Save howardjones/378a9c848fa9cfc401d0c738a1609cb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Cheezy perl script to produce the typeset Unix manual, as ken intended. | |
# | |
# Gets a list of every manpage from man(1), and compile them into per-section PDF files in the final/ subdir | |
# Pulls the intro page to the front of each section, if there is one. | |
# Also leaves the individual PDF pages in the various man* subdirs | |
# | |
# Assumptions: you have groff and ghostscript installed. I think you will need to run makewhatis, too. | |
# | |
# You probably want to make sure the man-pages package is installed to get section 2 & 3 fleshed out | |
# | |
# Takes about an hour to run on my average CentOS 6 system, producing 18145 pages (45MB) of PDF output! | |
# | |
# Twitter: @anotherhowie November 2016 | |
mkdir("final"); | |
# man will tell us all the manpages it knows about | |
open(PAGES, "man -aw \\* |"); | |
while(<PAGES>) { | |
chomp; chomp; | |
@parts = split(/\//); | |
$section = $parts[-2]; | |
$new_path = join("/", @parts[-2,-1]); | |
$new_path =~ s/\.gz/.pdf/; | |
if (! exists($sections{$section})) { | |
$sections{$section} = {}; | |
mkdir $section; | |
} | |
$sections{$section}{$_} = $new_path; | |
} | |
close(PAGES); | |
foreach $section (sort keys %sections) { | |
print "## Section $section\n"; | |
@pages = sort keys %{$sections{$section}}; | |
foreach $page (@pages) { | |
$new_path = $sections{$section}{$page}; | |
# print "# $page => $new_path\n"; | |
$command = "cat $page | groff -Tps -mandoc - | ps2pdf - $new_path"; | |
if ($page =~ /\.gz$/) { | |
$command = "z".$command; | |
} | |
if (! -f $new_path) { | |
print "$command\n"; | |
system($command); | |
} | |
} | |
# end of section collating | |
@outputs = map {$sections{$section}{$_}} @pages; | |
# move the intro to the front of the section, if there is one | |
($intro) = grep { m/\/intro\./} @outputs; | |
@page_order = grep { ! m/\/intro\./} @outputs; | |
if ($intro) { | |
unshift(@page_order, $intro); | |
} | |
system("gs", "-dBATCH", "-dNOPAUSE", "-sDEVICE=pdfwrite", "-sOutputFile=final/${section}.pdf", @page_order); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment