#!/usr/bin/perl
#*******************************************************************************#
# #
# texi2man.perl: #
# #
#*******************************************************************************#
#***************************************************************************************************
# *
# Copyright (C) 2003, 2004 Joerg Kunze *
# *
# I have got this file from Usenet. It was Written by Adrian Mariano, *
# additional features by Eric Backus *
# *
# This file is part of siliconBrain. *
# *
# siliconBrain is free software; you can redistribute it and/or modify *
# it under the terms of the GNU General Public License as published by *
# the Free Software Foundation; either version 2 of the License, or *
# (at your option) any later version. *
# *
# siliconBrain is distributed in the hope that it will be useful, *
# but WITHOUT ANY WARRANTY; without even the implied warranty of *
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# GNU General Public License for more details. *
# *
# You should have received a copy of the GNU General Public License *
# along with this program; if not, write to the Free Software *
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
# *
#***************************************************************************************************
$release = '$siliconBrainRelease: 0.2.3 $';
$rcsIdentifier = '$Id: texi2man.perl,v 1.12 2004/12/14 23:31:26 joerg Exp $';
$saveStamp = '$siliconBrainSaveStamp: 2004/12/14 22:27:22, Joerg Kunze$';
use POSIX;
$isRecord = 0;
$packageName = $ENV{"siliconBrainPackageName"};
$upperLeft = $packageName;
$lowerLeft = $packageName;
$lowerMiddle = POSIX::strftime( "%Y %B %d", gmtime( time ) );
print
".\\\" Converted to man's nroff format by
.\\\" $release
.\\\" $rcsIdentifier
.\\\" $saveStamp
";
sub manilize {
$texinfoInput = $_[ 0 ];
while( <$texinfoInput> ) {
next if( /^$/ || /\@node / );
s/\@c( |$)/.\\\"$1/;
if( /\@section (.*)/ ) {
$commandName = $1;
if( $commandName =~ /.*\.record$/ ) {
$isRecord = 1;
}
print ".TH $commandName 1 \"$lowerMiddle\" \"$lowerLeft\" \"$upperLeft\"\n";
$shortDescription = <>;
print ".SH NAME\n";
print "$commandName \\- $shortDescription\n";
next;
}
if( /\@subsection (.*)/ ) {
print ".SH \U$1\n";
next;
}
s/\@cite\{([^}]*)}/\\\`$1\'/g;
s/\@code\{([^}]*)}/\\\`$1\'/g;
s/\@email\{([^}]*)}/\\\`$1\'/g;
s/\@file\{([^}]*)}/\\\`$1\'/g;
s/\@kbd\{([^}]*)}/\\\`$1\'/g;
s/\@samp\{([^}]*)}/\\\`$1\'/g;
s/\@url\{([^}]*)}/\\\`$1\'/g;
s/\@dfn\{([^}]*)}/\"$1\"/g;
s/\@key\{([^}]*)}/<$1>/g;
s/\@emph\{([^}]*)}/\\fI$1\\fR/g;
s/\@strong\{([^}]*)}/\\fB$1\\fR/g;
s/\@var\{([^}]*)}/\U$1\E/g;
s/\@sc\{([^}]*)}/\U$1\E/g;
s/\@w\{([^}]*)}/$1/g;
s/\@pxref\{([^}]*)}/See \\fI$1\\fR/g; # <file://\\fI$1\\fR/g> ;
s/\@footnote\{([^}]*)}/[$1]/g;
s/\@minus\{}/-/g;
s/\@copyright\{}/(C)/g;
s/\@noindent//;
s/\@\{/{/g;
s/\@}/}/g;
s/\@\@/@/g;
s/\'\'/\"/;
s/\`\`/\"/;
s/---/--/;
next if( /\@table/ );
next if( /\@end table/ );
next if( /\@itemize/ );
next if( /\@end itemize/ );
s/\@itemx (.*)/.TP\n.BI $1/ ;
s/\@item (\S+)(.*)/.TP\n\\fB$1\\fR$2/ ;
s/\@item.*/.TP\n/;
print;
}
}
print "";
manilize( \*STDIN );
#---------------------------------------------------------#
# inject standard options, in case it is a record command #
#---------------------------------------------------------#
if( $isRecord ) {
open recordOptions, "record.specification | generate --texinfo |";
while( <recordOptions> ) {
last if ( /^\@subsection Options$/ );
next;
}
print ".SH OPTIONS\n";
print(
"\`$commandName\' is a record command. And so it has, like all" .
"record commands, the following standard options:\n"
);
manilize( \*recordOptions );
close recordOptions;
}
print ".SH AUTHOR\n";
open authorSnippet, "documentation/authors.snippet.texinfo";
manilize( \*authorSnippet );
close authorSnippet;
print <<"endOfMan";
.SH REPORTING BUGS
At the moment there is no other information than the authors. This is because this man
page is generated. So please contact one of the authors.
.SH COPYING
This file is part of $packageName. $packageName is free software.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts.
The sources of $commandName are published under the GNU general public licence.
.SH SEE ALSO
endOfMan
if( isRecord ) {
print "\\fBrecord\\fR(1) for a detailed description of the generic and common\n" .
"part of all record commands.\n" .
".PP\n";
}
print <<"endOfMan";
The full documentation for $packageName is maintained as a Texinfo manual. If the info and
$packageName programs are properly installed at your site, the command
.IP
info $packageName
.PP
should give you access to the complete manual.
endOfMan
exit 0;
#***************************************************************************************************
# *
# rest of the original code, not yet incorporated. *
# *
#***************************************************************************************************
s/\@value\{([^\s]+)}/$value{$1}/eg;
if (/\@set\s+([^\s]+)\s+(.*)$/) { $value{$1} = $2; next; }
if (/\@clear\s+([^\s]+)\s+(.*)$/) { delete $value{$1}; next; }
if (/\@itemx (.*)/) { printf(", $1"); $diditem=1; next; }
elsif ($diditem) { printf("\n"); $diditem=0; }
if (/\@item (.*)/)
{
printf("%s.TP\n%s.B $1", $manprefix, $manprefix);
$diditem=1;
next;
}
if (s/\@chapter (.*)/.SH \U$1\E/)
{
printf("%s%s", $manprefix, $_);
$justdidlp=1;
next;
}
if (s/\@section (.*)/$1/)
{
printf("%s.B %s", $manprefix, $_);
next;
}
if (/\@example/) { printf("%s.nf\n", $manprefix); $example=1; next; }
if (/\@end example/) { printf("%s.fi\n", $manprefix); $example=0; next;
}
if (/\@display/) { printf("%s.nf\n", $manprefix); $example=1; next; }
if (/\@end display/) { printf("%s.fi\n", $manprefix); $example=0; next;
}
if (/\@format/) { printf("%s.nf\n", $manprefix); $example=1; next; }
if (/\@end format/) { printf("%s.fi\n", $manprefix); $example=0; next; }
if (/\@smallexample/) { printf("%s.nf\n", $manprefix); $example=1; next;
}
if (/\@end smallexample/) { printf("%s.fi\n", $manprefix); $example=0;
next; }
if (!$example && /^\s*$/ && !$doman)
{
if ($justdidlp) { next; }
printf(".PP\n");
$justdidlp=1;
next;
}
if (/^\@/) { next; }
printf("%s%s", $manprefix, $_);
if (!$doman) { $justdidlp=0; }
# $Log: texi2man.perl,v $
# Revision 1.12 2004/12/14 23:31:26 joerg
# published for new release 0.2.3
#
# Revision 1.11 2004/12/14 23:17:05 joerg
# published for new release 0.2.2
#
# Revision 1.10 2004/12/14 22:42:23 joerg
# allFiles: all sources have a Log CVS keyword at the end now.
#