#!/usr/bin/perl
use strict;
## Copyright (C) Michael Still (mikal@stillhq.com)
## Released under the terms of the GNU GPL
##
## A script to make or install the manpages extracted by split-man
##
## Arguements: $1 -- the word "convert" or "install"
## $2 -- the directory containing the SGML files for the manpages
## $3 -- the filename which contained the sgmldoc output
## (I need this so I know which manpages to convert)
my($LISTING, $GENERATED, $INPUT, $OUTPUT, $front, $mode, $filename);
if($ARGV[0] eq ""){
die "Usage: makeman [convert | install]
\n";
}
if( ! -d "$ARGV[1]" ){
die "Output directory \"$ARGV[1]\" does not exist\n";
}
if($ARGV[0] eq "convert"){
open LISTING, "grep \"\" $ARGV[2] |";
while(){
s/<\/.*$//;
s/^.*>//;
s/\.sgml//;
s/struct //;
s/typedef //;
chomp;
$filename = $_;
print "Processing $filename\n";
# Open the input file to extract the front matter, generate the man page,
# and open it, and the rearrange everything until it is happy
open INPUT, "< $ARGV[1]/$filename.sgml";
$front = "";
$mode = 0;
while(){
if(/.*ENDFRONTTAG.*/){
$mode = 0;
}
if($mode > 0){
s///;
s///;
s/<\/bookinfo>//;
s///;
s<\/docinfo>//;
s/^[ \t]*//;
}
if($mode == 2){
if(//){
}
elsif(/<\/para>/){
$front = "$front.\\\" \n";
}
elsif(/<\/legalnotice>/){
$mode = 1;
}
elsif(/^[ \t]*$/){
}
else{
$front = "$front.\\\" $_";
}
}
if($mode == 1){
if(/(.*)<\/title>/){
$front = "$front.\\\" This documentation was generated from the book titled \"$1\", which is part of the Linux kernel source.\n.\\\" \n";
}
elsif(//){
$front = "$front.\\\" This documentation comes with the following legal notice:\n.\\\" \n";
$mode = 2;
}
elsif(//){
$front = "$front.\\\" Documentation by: ";
}
elsif(/(.*)<\/firstname>/){
$front = "$front$1 ";
}
elsif(/(.*)<\/surname>/){
$front = "$front$1 ";
}
elsif(/(.*)<\/email>/){
$front = "$front($1)";
}
elsif(/\/author>/){
$front = "$front\n";
}
elsif(//){
$front = "$front.\\\" Documentation copyright: ";
}
elsif(/(.*)<\/holder>/){
$front = "$front$1 ";
}
elsif(/(.*)<\/year>/){
$front = "$front$1 ";
}
elsif(/\/copyright>/){
$front = "$front\n";
}
elsif(/^[ \t]*$/
|| //
|| /<\/affiliation>/
|| //
|| /<\/address>/
|| //
|| /<\/authorgroup>/
|| /<\/legalnotice>/
|| //
|| /<\/date>/
|| //
|| /<\/edition>/){
}
else{
print "Unknown tag in manpage conversion: $_";
}
}
if(/.*BEGINFRONTTAG.*/){
$mode = 1;
}
}
close INPUT;
system("cd $ARGV[1]; docbook2man $filename.sgml; mv $filename.9 /tmp/$$.9\n");
open GENERATED, "< /tmp/$$.9";
open OUTPUT, "> $ARGV[1]/$filename.9";
print OUTPUT "$front";
print OUTPUT ".\\\" For comments on the formatting of this manpage, please contact Michael Still \n\n";
while(){
print OUTPUT "$_";
}
close OUTPUT;
close GENERATED;
system("gzip -f $ARGV[1]/$filename.9\n");
unlink("/tmp/$filename.9");
}
}
elsif($ARGV[0] eq "install"){
system("mkdir -p /usr/local/man/man9/; install $ARGV[1]/*.9.gz /usr/local/man/man9/");
}
else{
die "Usage: makeman [convert | install] \n";
}
print "Done\n";