4da563
=head1 NAME
4da563
4da563
docbook2man-spec.pl - convert DocBook RefEntries to Unix manpages
4da563
4da563
=head1 SYNOPSIS
4da563
4da563
The sgmlspl script from the SGMLSpm Perl module must be used to run
4da563
this script.  Use it like this:
4da563
4da563
nsgmls some-docbook-document.sgml | sgmlspl docbook2man-spec.pl
4da563
4da563
See man page or included DocBook documentation for details.
4da563
4da563
=head1 DESCRIPTION
4da563
4da563
This is a sgmlspl spec file that produces Unix-style
4da563
man pages from DocBook RefEntry markup.
4da563
4da563
=head1 COPYRIGHT
4da563
4da563
Copyright (C) 1998-2001 Steve Cheng <stevecheng@users.sourceforge.net>
4da563
4da563
Copyright (C) 1999 Thomas Lockhart <lockhart@alumni.caltech.edu>
4da563
4da563
This program is free software; you can redistribute it and/or modify it
4da563
under the terms of the GNU General Public License as published by the Free
4da563
Software Foundation; either version 2, or (at your option) any later
4da563
version.
4da563
4da563
You should have received a copy of the GNU General Public License along with
4da563
this program; see the file COPYING.  If not, please write to the Free
4da563
Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
4da563
4da563
=cut
4da563
4da563
# $Id: docbook2man-spec.pl,v 1.11 2010/10/04 10:23:31 ovasik Exp $
4da563
4da563
use SGMLS;			# Use the SGMLS package.
4da563
use SGMLS::Output;		# Use stack-based output.
4da563
use SGMLS::Refs;
4da563
4da563
4da563
########################################################################
4da563
# SGMLSPL script produced automatically by the script sgmlspl.pl
4da563
#
4da563
# Document Type: any, but processes only RefEntries
4da563
# Edited by: me :)
4da563
########################################################################
4da563
4da563
4da563
$write_manpages = 0;
4da563
$blank_xrefs = 0;
4da563
4da563
$default_sect = "1";
4da563
$default_date = `date "+%d %B %Y"`;
4da563
$cite_numeral_only = 1;
4da563
4da563
while (@ARGV) {
4da563
	my $arg = shift @ARGV;
4da563
	if ($arg eq "--section") {
4da563
		$default_sect = shift @ARGV || die "$arg requires an argument\n";
4da563
	} elsif ($arg eq "--date") {
4da563
		$default_date = shift @ARGV || die "$arg requires an argument\n";
4da563
	} elsif ($arg eq "--lowercase") {
4da563
		$lowercase_names = 1;
4da563
	} elsif ($arg eq "--preserve-case") {
4da563
		$lowercase_names = 0;
4da563
	} elsif ($arg eq "--cite-numeral-only") {
4da563
		$cite_numeral_only = 1;
4da563
	} elsif ($arg eq "--nocite-numeral-only") {
4da563
		$cite_numeral_only = 0;
4da563
	} elsif ($arg eq "--help") {
4da563
		print "Usage: $0",
4da563
			" [ --section <label> ]",
4da563
			" [ --date <string> ]",
4da563
			" [ --lowercase | --preserve-case ]",
4da563
			" [ --cite-numeral-only | --nocite-numeral-only ]",
4da563
			"\n";
4da563
		exit;
4da563
	} else {
4da563
		die "unrecognized switch $arg; try $0 --help\n";
4da563
	}
4da563
}
4da563
4da563
sgml('start', sub { 
4da563
	push_output('nul');
4da563
	$raw_cdata = 1;			# Makes it a bit faster.
4da563
	
4da563
	# Links file
4da563
	open(LINKSFILE, ">manpage.links");
4da563
4da563
	$Refs = new SGMLS::Refs("manpage.refs", "manpage.log");
4da563
});
4da563
sgml('end', sub {
4da563
	close(LINKSFILE);
4da563
4da563
	# Explicitly invoke destructor,
4da563
	# otherwise cache file may not get written!
4da563
	# Thomas Lockhart, 1999-08-03, perl-5.004, RedHat5.2
4da563
	undef $Refs;
4da563
4da563
	if($blank_xrefs) {
4da563
		warn "Warning: output contains unresolved XRefs\n";
4da563
	}
4da563
});
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Output helpers 
4da563
#
4da563
########################################################################
4da563
4da563
# Remove leading and trailing blanks.
4da563
4da563
sub StripString
4da563
{
4da563
	my $str = shift;
4da563
4da563
	$str = $1 if ($str =~ m#^\s*(\S.*)#);
4da563
	$str = $1 if ($str =~ m#^(.*\S)\s*$#);
4da563
4da563
	return $str;
4da563
}
4da563
4da563
# Generate a good file name, for given manpage title and manvolnum
4da563
# (cdata content).
4da563
# Cleanup whitespace and convert to lower case if required.
4da563
4da563
sub FileInfo
4da563
{
4da563
	my $title = StripString(shift);
4da563
	my $volnum = StripString(shift);
4da563
4da563
	$title = lc $title if $lowercase_names;
4da563
4da563
	$title =~ tr/ /_/;
4da563
	$volnum =~ tr/ /_/;
4da563
4da563
	my $sectcite = $volnum;
4da563
	# The 'package name' part of the section should
4da563
	# not be used when citing it.
4da563
	if ($cite_numeral_only) {
4da563
		$sectcite = $1 if ($volnum =~ /^([0-9]+)/);
4da563
	}
4da563
	
4da563
	return ("$title.$volnum", "$title($sectcite)");
4da563
}
4da563
4da563
# Our own version of sgml() and output() to allow simple string output
4da563
# to play well with roff's stupid whitespace rules. 
4da563
4da563
sub man_sgml
4da563
{
4da563
	if(ref($_[1]) eq 'CODE') {
4da563
		return &sgml;
4da563
	}
4da563
	
4da563
	my $s = $_[1];
4da563
	$s =~ s/\\/\\\\/g;
4da563
	$s =~ s/'/\\'/g;
4da563
4da563
	sgml($_[0], eval("sub { man_output '$s' }"));
4da563
}
4da563
4da563
sub man_output
4da563
{
4da563
	if($separator eq 'full') {
4da563
		output "\n" unless $newline_last++;
4da563
		output ".PP\n";
4da563
		$separator = '';
4da563
	}
4da563
	
4da563
	$_ = shift;
4da563
	if(s/^\n//) {
4da563
		output "\n" unless $newline_last++;
4da563
	}
4da563
	return if $_ eq '';
4da563
	
4da563
	output $_;
4da563
4da563
	if(@_) {
4da563
		output @_;
4da563
		$newline_last = (pop(@_) =~ /\n$/);
4da563
	} else {
4da563
		$newline_last = ($_ =~ /\n$/)
4da563
	}
4da563
}
4da563
4da563
# Fold lines into one, quote some characters
4da563
sub fold_string
4da563
{
4da563
	$_ = shift;
4da563
	
4da563
	s/\\/\\\\/g;
4da563
	s/"/""/g;
4da563
4da563
	# Change tabs and newlines to spaces
4da563
	# The newlines will be swallowed later while trimming
4da563
	tr/[\t\n]/  /;
4da563
4da563
	# Trim whitespace from beginning and end.
4da563
	s/^ +//;
4da563
	s/ +$//;
4da563
4da563
	return $_;
4da563
}
4da563
	
4da563
sub save_cdata()
4da563
{
4da563
	$raw_cdata++;
4da563
	push_output('string');
4da563
}
4da563
4da563
sub bold_on()
4da563
{
4da563
	# If the last font is also bold, don't change anything.
4da563
	# Basically this is to just get more readable man output.
4da563
	if($fontstack[$#fontstack] ne 'bold') {
4da563
		if(!$raw_cdata) {
4da563
			output '\fB';
4da563
			#$newline_last = 0;
4da563
		}
4da563
	}
4da563
	push(@fontstack, 'bold');
4da563
}
4da563
4da563
sub italic_on()
4da563
{
4da563
	# If the last font is also italic, don't change anything.
4da563
	if($fontstack[$#fontstack] ne 'italic') {
4da563
		if(!$raw_cdata) {
4da563
			output '\fI';
4da563
			#$newline_last = 0;
4da563
		}
4da563
	}
4da563
	push(@fontstack, 'italic');
4da563
}
4da563
4da563
sub font_off()
4da563
{
4da563
	my $thisfont = pop(@fontstack);
4da563
	my $lastfont = $fontstack[$#fontstack];
4da563
	
4da563
	# Only output font change if it is different
4da563
	if($thisfont ne $lastfont) {
4da563
		if($raw_cdata)			{ return; }
4da563
		elsif($lastfont eq 'bold') 	{ output '\fB'; }
4da563
		elsif($lastfont eq 'italic')	{ output '\fI'; }
4da563
		else				{ output '\fR'; }
4da563
	
4da563
		#$newline_last = 0;
4da563
	}
4da563
}
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Manpage management
4da563
#
4da563
########################################################################
4da563
4da563
sgml('<REFENTRY>', sub { 
4da563
	# This will be overwritten at end of REFMETA, when we know the name of the page.
4da563
	pop_output();
4da563
	
4da563
	$write_manpages = 1;		# Currently writing manpage.
4da563
	
4da563
	$nocollapse_whitespace = 0;	# Current whitespace collapse counter.
4da563
	$newline_last = 1;		# At beginning of line?
4da563
		# Just a bit of warning, you will see this variable manipulated
4da563
		# manually a lot.  It makes the code harder to follow but it
4da563
		# saves you from having to worry about collapsing at the end of
4da563
		# parse, stopping at verbatims, etc.
4da563
	$raw_cdata = 0;                 # Instructs certain output functions to
4da563
					# leave CDATA alone, so we can assign
4da563
					# it to a string and process it, etc.
4da563
	@fontstack = ();		# Fonts being activated.
4da563
	
4da563
	$list_nestlevel = 0;		# Indent certain nested content.
4da563
4da563
	# Separator to use between 'elements' in the content of a
4da563
	# paragraph (usually).  This makes sure that PCDATA after a list
4da563
	# in a PARA gets a break in between and not become part of the
4da563
	# last listitem.  Note that we can't do it after the list ends,
4da563
	# because often the list ends the paragraph and we'll get an
4da563
	# extra break.  Anything that changes the separator status from
4da563
	# the default should also save its last state in the parent
4da563
	# element's ext, but I'm not going to explain further.  It's a
4da563
	# gross hack and almost guaranteed to fail in unforseen cases.
4da563
	# The only way to avoid all this is to use a tree/grove model, which
4da563
	# we're _not_ doing.
4da563
	$separator = '';
4da563
	
4da563
	$manpage_title = '';		# Needed for indexing.
4da563
	$manpage_sect = '';
4da563
	@manpage_names = ();
4da563
	
4da563
	$manpage_misc = '';
4da563
4da563
	# check refentry's language
4da563
	if(defined($_[0]->attribute('LANG')->value)) {
4da563
	  $manpage_lang = $_[0]->attribute('LANG')->value;
4da563
	}
4da563
	else {
4da563
	  $manpage_lang = '';
4da563
	}
4da563
});
4da563
sgml('</REFENTRY>', sub {
4da563
	if(!$newline_last) {
4da563
		output "\n";
4da563
	}
4da563
	
4da563
	$raw_cdata = 1;
4da563
	push_output('nul');
4da563
4da563
	$write_manpages = 0;
4da563
});
4da563
4da563
sgml('</REFMETA>', sub {
4da563
	my ($filename, $citation) = 
4da563
		FileInfo($manpage_title, $manpage_sect || $default_sect);
4da563
4da563
	push_output('file', $filename);
4da563
4da563
	output <<'_END_BANNER';
4da563
.\" auto-generated by docbook2man-spec from docbook-utils package
4da563
_END_BANNER
4da563
4da563
	my $manpage_date = $_[0]->parent->ext->{'date'} || $default_date;
4da563
4da563
	output '.TH "';
4da563
4da563
	# If the title is not mixed-case, convention says to
4da563
	# uppercase the whole title.  (The canonical title is
4da563
	# lowercase.)
4da563
	if($manpage_title =~ /[A-Z]/) {
4da563
		output fold_string($manpage_title);
4da563
	} else {
4da563
		output uc(fold_string($manpage_title));
4da563
	}
4da563
	
4da563
	output  '" "', fold_string($manpage_sect), 
4da563
		'" "', fold_string($manpage_date),
4da563
		'" "', $manpage_misc, 
4da563
		'" "', $manpage_manual, 
4da563
		"\"\n";
4da563
4da563
	$newline_last = 1;
4da563
4da563
	# References to this RefEntry.
4da563
	if(defined($_[0]->parent->attribute('ID')->value)) {
4da563
		my $id = $_[0]->parent->attribute('ID')->value;
4da563
4da563
		# Append XREFLABEL content to citations.
4da563
		if(defined($_[0]->parent->attribute('XREFLABEL')->value)) {
4da563
			$citation = $_[0]->parent->attribute('XREFLABEL')->value .
4da563
					' [' . $citation . ']';
4da563
		}
4da563
4da563
		$Refs->put("refentry:$id", $citation);
4da563
	}
4da563
});
4da563
4da563
sgml('<REFENTRYTITLE>', sub { 
4da563
	if($_[0]->in('REFMETA')) { 
4da563
		save_cdata();
4da563
	} else { 
4da563
		# Manpage citations are in bold.
4da563
		bold_on();
4da563
	}
4da563
});
4da563
sgml('</REFENTRYTITLE>', sub { 
4da563
	if($_[0]->in('REFMETA')) {
4da563
		$raw_cdata--;
4da563
		$manpage_title = pop_output();
4da563
	}
4da563
	else { font_off(); }
4da563
4da563
	if (defined($_[0]->attribute('ID')->value)) {
4da563
		my $id = $_[0]->attribute('ID')->value;
4da563
		$Refs->put("refentrytitle:$id", $manpage_title);
4da563
	}
4da563
});
4da563
4da563
sgml('<MANVOLNUM>', sub { 
4da563
	if($_[0]->in('REFMETA')) { 
4da563
		save_cdata();	
4da563
	} else {
4da563
		# Manpage citations use ().
4da563
		output '(';
4da563
	}
4da563
});
4da563
sgml('</MANVOLNUM>', sub { 
4da563
	if($_[0]->in('REFMETA')) {
4da563
		$raw_cdata--;
4da563
		$manpage_sect = pop_output();
4da563
	}
4da563
	else { output ')' }
4da563
});
4da563
4da563
sgml('<REFMISCINFO>', \&save_cdata);
4da563
sgml('</REFMISCINFO>', sub { 
4da563
	$raw_cdata--;
4da563
	$manpage_misc = fold_string(pop_output());
4da563
});
4da563
4da563
4da563
# NAME section
4da563
#man_sgml('<REFNAMEDIV>', "\n.SH NAME\n");
4da563
man_sgml('<REFNAMEDIV>', sub {
4da563
	my %text = { fr=>'NOM', es=>'NOMBRE', pl=>'NAZWA' };
4da563
	
4da563
	if(defined $text{lc($manpage_lang)})
4da563
	{
4da563
		man_output "\n.SH " . $text{lc($manpage_lang)} . "\n";
4da563
	} elsif(defined $_[0]->attribute('LANG') and
4da563
		defined $text{lc($_[0]->attribute('LANG')->value)})
4da563
	{
4da563
		man_output "\n.SH " . $text{lc($_[0]->attribute('LANG'))} . "\n";
4da563
	} else {
4da563
		man_output "\n.SH NAME\n";
4da563
	}
4da563
});
4da563
4da563
sgml('<REFNAME>', \&save_cdata);
4da563
sgml('</REFNAME>', sub { 
4da563
	$raw_cdata--;
4da563
	push(@manpage_names, pop_output());
4da563
});
4da563
4da563
sgml('<REFPURPOSE>', \&save_cdata);
4da563
sgml('</REFPURPOSE>', sub { 
4da563
	$raw_cdata--;
4da563
	my $manpage_purpose = fold_string(pop_output());
4da563
	
4da563
	for(my $i = 0; $i < $#manpage_names; $i++) {
4da563
		output fold_string($manpage_names[$i]), ', ';
4da563
	}
4da563
4da563
	output fold_string($manpage_names[$#manpage_names]);
4da563
	output " \\- $manpage_purpose\n";
4da563
4da563
	$newline_last = 1;
4da563
4da563
	foreach(@manpage_names) {
4da563
		# Don't link to itself
4da563
		if($_ ne $manpage_title) {
4da563
			print LINKSFILE "$manpage_title.$manpage_sect	$_.$manpage_sect\n";
4da563
		}
4da563
	}
4da563
});
4da563
	
4da563
man_sgml('<REFCLASS>', "\n.sp\n");
4da563
4da563
#RefDescriptor
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# SYNOPSIS section and synopses
4da563
#
4da563
########################################################################
4da563
4da563
#man_sgml('<REFSYNOPSISDIV>', "\n.SH SYNOPSIS\n");
4da563
man_sgml('<REFSYNOPSISDIV>', sub {
4da563
	   if ($manpage_lang eq "pl") { man_output "\n.SH SK£ADNIA\n"; }
4da563
	   # waits for another languages
4da563
	   #elsif ($manpage_lang eq "xx") { man_output "\n.SH xxxxxxx\n"; } 
4da563
	   else { man_output "\n.SH SYNOPSIS\n"; }
4da563
});   
4da563
4da563
man_sgml('</REFSYNOPSISDIV>', "\n");
4da563
4da563
## FIXME! Must be made into block elements!!
4da563
#sgml('<FUNCSYNOPSIS>', \&bold_on);
4da563
#sgml('</FUNCSYNOPSIS>', \&font_off);
4da563
#sgml('<CMDSYNOPSIS>', \&bold_on);
4da563
#sgml('</CMDSYNOPSIS>', \&font_off);
4da563
4da563
man_sgml('<FUNCSYNOPSIS>', sub {
4da563
	man_output("\n.nf\n");
4da563
	bold_on();
4da563
});
4da563
man_sgml('</FUNCSYNOPSIS>', sub {
4da563
	man_output("\n.fi");
4da563
	font_off();
4da563
});
4da563
4da563
man_sgml('<CMDSYNOPSIS>', "\n.sp\n");
4da563
man_sgml('</CMDSYNOPSIS>', "\n");
4da563
4da563
man_sgml('<FUNCPROTOTYPE>', "\n.sp\n");
4da563
4da563
# Arguments to functions.  This is C convention.
4da563
#man_sgml('<PARAMDEF>', '(');
4da563
#man_sgml('</PARAMDEF>', ");\n");
4da563
#man_sgml('<VOID>', "(void);\n");
4da563
sub paramdef
4da563
{
4da563
	if($_[0]->parent->ext->{'inparams'}) {
4da563
		output ', ';
4da563
	} else {
4da563
		output ' (';
4da563
		$_[0]->parent->ext->{'inparams'} = 1;
4da563
	}
4da563
}
4da563
man_sgml('<PARAMDEF>', \&paramdef);
4da563
man_sgml('</FUNCPROTOTYPE>', ");\n");
4da563
man_sgml('<VOID>', "(void");
4da563
man_sgml('<VARARGS>', "(...");
4da563
4da563
4da563
sub arg_start
4da563
{
4da563
	# my $choice = $_[0]->attribute('CHOICE')->value;
4da563
4da563
	# The content model for CmdSynopsis doesn't include #PCDATA,
4da563
	# so we won't see any of the whitespace in the source file,
4da563
	# so we have to add it after each component.
4da563
	man_output ' ';
4da563
4da563
	if($_[0]->attribute('CHOICE')->value =~ /opt/i) {
4da563
		man_output '[ ';
4da563
	}
4da563
	bold_on();
4da563
}
4da563
sub arg_end
4da563
{
4da563
	font_off();
4da563
	if($_[0]->attribute('REP')->value =~ /^Repeat/i) {
4da563
		italic_on();
4da563
		man_output '...';
4da563
		font_off();
4da563
	}
4da563
	if($_[0]->attribute('CHOICE')->value =~ /opt/i) {
4da563
		man_output ' ] ';
4da563
	}
4da563
}
4da563
4da563
sgml('<ARG>', \&arg_start);
4da563
sgml('</ARG>', \&arg_end);
4da563
sgml('<GROUP>', \&arg_start);
4da563
sgml('</GROUP>', \&arg_end);
4da563
4da563
sgml('<OPTION>', \&bold_on);
4da563
sgml('</OPTION>', \&font_off);
4da563
4da563
# FIXME: This is one _blank_ line.
4da563
man_sgml('<SBR>', "\n\n");
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# General sections
4da563
#
4da563
########################################################################
4da563
4da563
# The name of the section is handled by TITLE.  This just sets
4da563
# up the roff markup.
4da563
man_sgml('<REFSECT1>', sub { $separator = ''; man_output "\n.SH "});
4da563
man_sgml('<REFSECT2>', sub { $separator = ''; man_output "\n.SS "});
4da563
man_sgml('<REFSECT3>', sub { $separator = ''; man_output "\n.SS "});
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Titles, metadata.
4da563
#
4da563
########################################################################
4da563
4da563
sgml('<TITLE>', sub {
4da563
	if($_[0]->in('REFERENCE') or $_[0]->in('BOOK')) {
4da563
		$write_manpages = 1;
4da563
	}
4da563
	save_cdata();
4da563
});
4da563
sgml('</TITLE>', sub {
4da563
	my ($element, $event) = @_;
4da563
	my $title = fold_string(pop_output());
4da563
	$raw_cdata--;
4da563
	
4da563
	if($element->in('REFERENCE') or $element->in('BOOK')) {
4da563
		# We use TITLE of enclosing Reference or Book as manual name
4da563
		$manpage_manual = $title;
4da563
		$write_manpages = 0;
4da563
	}
4da563
	elsif(exists $element->parent->ext->{'title'}) {
4da563
		# By far the easiest case.  Just fold the string as
4da563
		# above, and then set the parent element's variable.
4da563
		$_[0]->parent->ext->{'title'} = $title;
4da563
	}
4da563
	else {
4da563
		# If the parent element's handlers are lazy, 
4da563
		# output the folded string for them :)
4da563
		# We assume they want uppercase and a newline.
4da563
		man_output '"', uc($title), "\"\n";
4da563
	}
4da563
4da563
	if (defined($element->attribute('ID')->value)) {
4da563
		my $id = $_[0]->attribute('ID')->value;
4da563
		$Refs->put("title:$id", $title);
4da563
	}
4da563
4da563
	my ($filename, $citation) =
4da563
		FileInfo($manpage_title, $manpage_sect || $default_sect);
4da563
	my $parentid = $element->parent->attribute('ID')->value;
4da563
	if ($parentid and ($element->in('REFSECT1') or $element->in('REFSECT2') or $element->in('REFSECT3'))) {
4da563
		$Refs->put("refsect:$parentid", "$citation");
4da563
	}
4da563
});
4da563
4da563
sgml('<ATTRIBUTION>', sub { 
4da563
	if($_[0]->in('BLOCKQUOTE')) {
4da563
		push_output('string');
4da563
	}
4da563
});
4da563
sgml('</ATTRIBUTION>', sub { 
4da563
	if($_[0]->in('BLOCKQUOTE')) {
4da563
		$_[0]->parent->ext->{'attribution'} = pop_output(); 
4da563
	} else {
4da563
		# For an Epigraph.
4da563
		man_output "\n\n";
4da563
	}
4da563
});
4da563
4da563
sgml('<DATE>', sub {
4da563
      save_cdata();
4da563
});
4da563
sgml('</DATE>', sub {
4da563
      $_[0]->parent->parent->ext->{'date'} = fold_string(pop_output());
4da563
      $raw_cdata--;
4da563
});
4da563
4da563
sub ignore_content { push_output 'nul'; }
4da563
sub restore_content { pop_output(); }
4da563
4da563
sgml('<DOCINFO>', \&ignore_content);
4da563
sgml('</DOCINFO>', \&restore_content);
4da563
sgml('<REFSYNOPSISDIVINFO>', \&ignore_content);
4da563
sgml('</REFSYNOPSISDIVINFO>', \&restore_content);
4da563
sgml('<REFSECT1INFO>', \&ignore_content);
4da563
sgml('</REFSECT1INFO>', \&restore_content);
4da563
sgml('<REFSECT2INFO>', \&ignore_content);
4da563
sgml('</REFSECT2INFO>', \&restore_content);
4da563
sgml('<REFSECT3INFO>', \&ignore_content);
4da563
sgml('</REFSECT3INFO>', \&restore_content);
4da563
4da563
sgml('<INDEXTERM>', \&ignore_content);
4da563
sgml('</INDEXTERM>', \&restore_content);
4da563
4da563
sgml('<AUTHORBLURB>', \&ignore_content);
4da563
sgml('</AUTHORBLURB>', \&restore_content);
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Set bold on enclosed content 
4da563
#
4da563
########################################################################
4da563
4da563
sgml('<APPLICATION>', \&bold_on);
4da563
sgml('</APPLICATION>', \&font_off);
4da563
4da563
sgml('<CLASSNAME>', \&bold_on);		sgml('</CLASSNAME>', \&font_off);
4da563
sgml('<STRUCTNAME>', \&bold_on);	sgml('</STRUCTNAME>', \&font_off);
4da563
sgml('<STRUCTFIELD>', \&bold_on);	sgml('</STRUCTFIELD>', \&font_off);
4da563
sgml('<SYMBOL>', \&bold_on);		sgml('</SYMBOL>', \&font_off);
4da563
sgml('<TYPE>', \&bold_on);		sgml('</TYPE>', \&font_off);
4da563
4da563
sgml('<ENVAR>', \&bold_on);	sgml('</ENVAR>', \&font_off);
4da563
4da563
sgml('<FUNCTION>', \&bold_on);	sgml('</FUNCTION>', \&font_off);
4da563
4da563
sgml('<EMPHASIS>', \&bold_on);	sgml('</EMPHASIS>', \&font_off);
4da563
4da563
sgml('<ERRORNAME>', \&bold_on);	sgml('</ERRORNAME>', \&font_off);
4da563
# ERRORTYPE
4da563
4da563
sgml('<COMMAND>', \&bold_on);	sgml('</COMMAND>', \&font_off);
4da563
4da563
sgml('<GUIBUTTON>', \&bold_on);	sgml('</GUIBUTTON>', \&font_off);
4da563
sgml('<GUIICON>', \&bold_on);	sgml('</GUIICON>', \&font_off);
4da563
# GUILABEL
4da563
# GUIMENU
4da563
# GUIMENUITEM
4da563
# GUISUBMENU
4da563
# MENUCHOICE
4da563
4da563
sgml('<ACCEL>', \&bold_on);	sgml('</ACCEL>', \&font_off);
4da563
# KEYCODE
4da563
# SHORTCUT
4da563
4da563
4da563
sgml('<KEYCOMBO>', sub {
4da563
	$separator = 'none';
4da563
	$_[0]->ext->{'separator'} = 'none';
4da563
});
4da563
sgml('</KEYCOMBO>', sub { $separator = $_[0]->parent->ext->{'separator'}; });
4da563
4da563
sub _keycombo {
4da563
	if($_[0]->in('KEYCOMBO')) {
4da563
		if($separator eq 'none') { $separator = '' }
4da563
		else { man_output "+"; }
4da563
	}
4da563
	bold_on();
4da563
}
4da563
sgml('<KEYCAP>', \&_keycombo);	sgml('</KEYCAP>', \&font_off);
4da563
sgml('<KEYSYM>', \&_keycombo);	sgml('</KEYSYM>', \&font_off);
4da563
sgml('<MOUSEBUTTON>', \&_keycombo);	sgml('</MOUSEBUTTON>', \&font_off);
4da563
4da563
4da563
sgml('<USERINPUT>', \&bold_on);	sgml('</USERINPUT>', \&font_off);
4da563
4da563
sgml('<INTERFACEDEFINITION>', \&bold_on);
4da563
sgml('</INTERFACEDEFINITION>', \&font_off);
4da563
4da563
# May need to look at the CLASS
4da563
sgml('<SYSTEMITEM>', \&bold_on);
4da563
sgml('</SYSTEMITEM>', \&font_off);
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Set italic on enclosed content 
4da563
#
4da563
########################################################################
4da563
4da563
sgml('<FIRSTTERM>', \&italic_on);	sgml('</FIRSTTERM>', \&font_off);
4da563
4da563
sgml('<FILENAME>', \&italic_on);	sgml('</FILENAME>', \&font_off);
4da563
sgml('<PARAMETER>', \&italic_on);	sgml('</PARAMETER>', \&font_off);
4da563
sgml('<PROPERTY>', \&italic_on);	sgml('</PROPERTY>', \&font_off);
4da563
4da563
sgml('<REPLACEABLE>', sub {
4da563
	italic_on();
4da563
	if($_[0]->in('TOKEN')) {
4da563
		# When tokenizing, follow more 'intuitive' convention
4da563
		output "<";
4da563
	}
4da563
});
4da563
sgml('</REPLACEABLE>', sub {
4da563
	if($_[0]->in('TOKEN')) {
4da563
		output ">";
4da563
	}
4da563
	font_off();
4da563
});
4da563
4da563
sgml('<CITETITLE>', \&italic_on);	sgml('</CITETITLE>', \&font_off);
4da563
sgml('<FOREIGNPHRASE>', \&italic_on);	sgml('</FOREIGNPHRASE>', \&font_off);
4da563
4da563
sgml('<LINEANNOTATION>', \&italic_on);	sgml('</LINEANNOTATION>', \&font_off);
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Other 'inline' elements 
4da563
#
4da563
########################################################################
4da563
4da563
man_sgml('<EMAIL>', '<');
4da563
man_sgml('</EMAIL>', '>');
4da563
man_sgml('<OPTIONAL>', '[');
4da563
man_sgml('</OPTIONAL>', ']');
4da563
4da563
man_sgml('</TRADEMARK>', "\\u\\s-2TM\\s+2\\d");
4da563
4da563
man_sgml('<COMMENT>', "[Comment: ");
4da563
man_sgml('</COMMENT>', "]");
4da563
4da563
man_sgml('<QUOTE>', "``");
4da563
man_sgml('</QUOTE>', "''");
4da563
4da563
#man_sgml('<LITERAL>', '"');
4da563
#man_sgml('</LITERAL>', '"');
4da563
# There doesn't seem to be a good way to represent LITERAL in -man
4da563
# ComputerOutput, SGMLTag, Markup are the same thing.
4da563
4da563
# These create spaces between content in special elements
4da563
# without PCDATA content.
4da563
man_sgml('</HONORIFIC>', " ");
4da563
man_sgml('</FIRSTNAME>', " ");
4da563
man_sgml('</SURNAME>', " ");
4da563
man_sgml('</LINEAGE>', " ");
4da563
man_sgml('</OTHERNAME>', " ");
4da563
4da563
man_sgml('<AFFILIATION>', "(");
4da563
man_sgml('</AFFILIATION>', ") ");
4da563
man_sgml('<CONTRIB>', "(");
4da563
man_sgml('</CONTRIB>', ") ");
4da563
4da563
man_sgml('</STREET>', " ");
4da563
man_sgml('</POB>', " ");
4da563
man_sgml('</POSTCODE>', " ");
4da563
man_sgml('</CITY>', " ");
4da563
man_sgml('</STATE>', " ");
4da563
man_sgml('</COUNTRY>', " ");
4da563
man_sgml('</PHONE>', " ");
4da563
man_sgml('</FAX>', " ");
4da563
man_sgml('</OTHERADDRESS>', " ");
4da563
4da563
man_sgml('</ALT>', ": ");
4da563
man_sgml('<GRAPHIC>', " [GRAPHIC] ");
4da563
4da563
# No special presentation:
4da563
4da563
# AUTHORINITIALS
4da563
4da563
# ABBREV
4da563
# ACTION
4da563
# ACRONYM
4da563
# CITATION
4da563
# PHRASE
4da563
# QUOTE
4da563
# WORDASWORD
4da563
4da563
# PROMPT
4da563
# RETURNVALUE
4da563
# TOKEN
4da563
4da563
# DATABASE
4da563
# HARDWARE
4da563
# INTERFACE
4da563
# MEDIALABEL
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Paragraph and paragraph-like elements 
4da563
#
4da563
########################################################################
4da563
4da563
sub para_start {
4da563
	if($separator eq '' or $separator eq 'full') {
4da563
		$separator = '';
4da563
		man_output "\n.PP\n";
4da563
	} elsif($separator eq 'blank') { 
4da563
		man_output "\n\n";
4da563
	} elsif($separator eq 'none' ) {
4da563
		$_[0]->parent->ext->{'separator'} = 'blank';
4da563
		$separator = 'blank';
4da563
	}
4da563
}
4da563
# Actually applies to a few other block elements as well
4da563
sub para_end {
4da563
	$separator = $_[0]->parent->ext->{'separator'};
4da563
	man_output "\n";
4da563
}
4da563
4da563
sgml('<PARA>', \&para_start);
4da563
sgml('</PARA>', \&para_end);
4da563
sgml('<SIMPARA>', \&para_start);
4da563
sgml('</SIMPARA>', \&para_end);
4da563
4da563
# Nothing special, except maybe FIXME set nobreak.
4da563
sgml('<INFORMALEXAMPLE>', \&para_start);
4da563
sgml('</INFORMALEXAMPLE>', \&para_end);
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Blocks using SS sections
4da563
#
4da563
########################################################################
4da563
4da563
# FIXME: We need to consider the effects of SS
4da563
# in a hanging tag :(
4da563
4da563
# Complete with the optional-title dilemma (again).
4da563
sgml('<ABSTRACT>', sub {
4da563
	$_[0]->ext->{'title'} = 'ABSTRACT';
4da563
	output "\n" unless $newline_last++;
4da563
	push_output('string');
4da563
});
4da563
sgml('</ABSTRACT>', sub {
4da563
	my $content = pop_output();
4da563
	
4da563
	# As ABSTRACT is never on the same level as RefSect1,
4da563
	# this leaves us with only .SS in terms of -man macros.
4da563
	output ".SS \"", uc($_[0]->ext->{'title'}), "\"\n";
4da563
4da563
	output $content;
4da563
	output "\n" unless $newline_last++;
4da563
});
4da563
4da563
4da563
4da563
# Ah, I needed a break.  Example always has a title.
4da563
sgml('<EXAMPLE>', sub { $separator = ''; man_output "\n.SS "});
4da563
sgml('</EXAMPLE>', \&para_end);
4da563
4da563
# Same with sidebar.
4da563
sgml('<SIDEBAR>', sub { $separator = ''; man_output "\n.SS "});
4da563
sgml('</SIDEBAR>', \&para_end);
4da563
4da563
sgml('<FORMALPARA>', sub { $separator = ''; man_output "\n.SS "});
4da563
sgml('</FORMALPARA>', \&para_end);
4da563
4da563
sgml('<FIGURE>', sub { $separator = ''; man_output "\n.SS "});
4da563
sgml('</FIGURE>', \&para_end);
4da563
4da563
4da563
4da563
# NO title.
4da563
sgml('<HIGHLIGHTS>', sub { $separator = ''; man_output "\n.SS HIGHLIGHTS\n"});
4da563
sgml('</HIGHLIGHTS>', \&para_end);
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Indented 'Block' elements 
4da563
#
4da563
########################################################################
4da563
4da563
sub indent_block_start
4da563
{
4da563
	$separator = '';
4da563
	man_output "\n.sp\n.RS\n";
4da563
}
4da563
sub indent_block_end
4da563
{
4da563
	$separator = $_[0]->parent->ext->{'separator'};
4da563
	man_output "\n.RE\n.sp\n";
4da563
}
4da563
4da563
sgml('<ADDRESS>', sub {
4da563
	&indent_block_start;
4da563
	if($_[0]->attribute('FORMAT')->type eq 'NOTATION'
4da563
	   and $_[0]->attribute('FORMAT')->value->name eq 'LINESPECIFIC') {
4da563
		&verbatim_start;
4da563
	}
4da563
});
4da563
sgml('</ADDRESS>', sub {
4da563
	if($_[0]->attribute('FORMAT')->type eq 'NOTATION'
4da563
	   and $_[0]->attribute('FORMAT')->value->name eq 'LINESPECIFIC') {
4da563
		&verbatim_end;
4da563
	}
4da563
	&indent_block_end;
4da563
});
4da563
	
4da563
# This element is almost like an admonition (below),
4da563
# only the default title is blank :)
4da563
4da563
sgml('
', sub {
4da563
	$_[0]->ext->{'title'} = ''; 
4da563
	&indent_block_start;
4da563
	push_output('string');
4da563
});
4da563
sgml('', sub {
4da563
	my $content = pop_output();
4da563
4da563
	if($_[0]->ext->{'title'}) {
4da563
		output ".B \"", $_[0]->ext->{'title'}, ":\"\n";
4da563
	}
4da563
	
4da563
	output $content;
4da563
4da563
	if($_[0]->ext->{'attribution'}) {
4da563
		man_output "\n\n                -- ",
4da563
				$_[0]->ext->{'attribution'}, "\n";
4da563
	}
4da563
	
4da563
	&indent_block_end;
4da563
});
4da563
4da563
# Set off admonitions from the rest of the text by indenting.
4da563
# FIXME: Need to check if this works inside paragraphs, not enclosing them.
4da563
sub admonition_end {
4da563
	my $content = pop_output();
4da563
4da563
	# When the admonition is only one paragraph,
4da563
	# it looks nicer if the title was inline.
4da563
	my $num_para;
4da563
	while ($content =~ /^\.PP/gm) { $num_para++ }
4da563
	if($num_para==1) {
4da563
		$content =~ s/^\.PP\n//;
4da563
	}
4da563
	
4da563
	output ".B \"" . $_[0]->ext->{'title'} . ":\"\n";
4da563
	output $content;
4da563
	
4da563
	&indent_block_end;
4da563
}
4da563
4da563
sgml('<NOTE>', sub {
4da563
	# We can't see right now whether or not there is a TITLE
4da563
	# element, so we have to save the output now and add it back
4da563
	# at the end of this admonition.
4da563
	$_[0]->ext->{'title'} = 'Note';
4da563
	
4da563
	&indent_block_start;
4da563
	
4da563
	push_output('string');
4da563
});
4da563
sgml('</NOTE>', \&admonition_end);
4da563
4da563
# Same as above.
4da563
sgml('<WARNING>', sub { 
4da563
	$_[0]->ext->{'title'} = 'Warning'; 
4da563
	&indent_block_start;
4da563
	push_output('string');
4da563
});
4da563
sgml('</WARNING>', \&admonition_end);
4da563
4da563
sgml('<TIP>', sub {
4da563
	$_[0]->ext->{'title'} = 'Tip';
4da563
	&indent_block_start;
4da563
	push_output('string');
4da563
});
4da563
sgml('</TIP>', \&admonition_end);
4da563
sgml('<CAUTION>', sub {
4da563
	$_[0]->ext->{'title'} = 'Caution';
4da563
	&indent_block_start;
4da563
	push_output('string');
4da563
});
4da563
sgml('</CAUTION>', \&admonition_end);
4da563
4da563
sgml('<IMPORTANT>', sub {
4da563
	$_[0]->ext->{'title'} = 'Important';
4da563
	&indent_block_start;
4da563
	push_output('string');
4da563
});
4da563
sgml('</IMPORTANT>', \&admonition_end);
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Verbatim displays. 
4da563
#
4da563
########################################################################
4da563
4da563
sub verbatim_start {
4da563
	$separator = '';
4da563
	man_output "\n.sp\n";
4da563
	man_output "\n.nf\n" unless $nocollapse_whitespace++;
4da563
}
4da563
4da563
sub verbatim_end {
4da563
	man_output "\n.sp\n";
4da563
	man_output "\n.fi\n" unless --$nocollapse_whitespace;
4da563
	$separator = $_[0]->parent->ext->{'separator'};
4da563
}
4da563
4da563
sgml('<PROGRAMLISTING>', \&verbatim_start); 
4da563
sgml('</PROGRAMLISTING>', \&verbatim_end);
4da563
4da563
sgml('<SCREEN>', \&verbatim_start); 
4da563
sgml('</SCREEN>', \&verbatim_end);
4da563
4da563
sgml('<LITERALLAYOUT>', \&verbatim_start); 
4da563
sgml('</LITERALLAYOUT>', \&verbatim_end);
4da563
4da563
sgml('<SYNOPSIS>', sub {
4da563
	my $format = $_[0]->attribute('FORMAT');
4da563
4da563
	if($format->type eq 'NOTATION'
4da563
	   and $format->value->name eq 'LINESPECIFIC')
4da563
	{
4da563
		&verbatim_start;
4da563
	} else {
4da563
		$separator = '';
4da563
		man_output "\n.sp\n";
4da563
	}
4da563
});
4da563
4da563
sgml('</SYNOPSIS>', sub {
4da563
	my $format = $_[0]->attribute('FORMAT');
4da563
	
4da563
	if($format->type eq 'NOTATION'
4da563
	   and $format->value->name eq 'LINESPECIFIC')
4da563
	{
4da563
		&verbatim_end;
4da563
	} else {
4da563
		man_output "\n";
4da563
		$_[0]->parent->ext->{'separator'} = 'full';
4da563
		$separator = 'full';
4da563
	}
4da563
});
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Lists
4da563
#
4da563
########################################################################
4da563
4da563
# Indent nested lists.
4da563
sub list_start {
4da563
	man_output "\n.RS\n" if $list_nestlevel++;
4da563
}
4da563
sub list_end {
4da563
	man_output "\n.RE\n" if --$list_nestlevel;
4da563
	$_[0]->parent->ext->{'separator'} = 'full';
4da563
	$separator = 'full';
4da563
}
4da563
4da563
sgml('<VARIABLELIST>', \&list_start);
4da563
sgml('</VARIABLELIST>', \&list_end);
4da563
sgml('<ITEMIZEDLIST>', \&list_start);
4da563
sgml('</ITEMIZEDLIST>', \&list_end);
4da563
sgml('<ORDEREDLIST>', sub { 
4da563
	&list_start;
4da563
	$_[0]->ext->{'count'} = 1;
4da563
});
4da563
sgml('</ORDEREDLIST>', \&list_end);
4da563
		
4da563
# Output content on one line, bolded.
4da563
sgml('<TERM>', sub { 
4da563
	man_output "\n.TP\n";
4da563
	bold_on();
4da563
	push_output('string');
4da563
});
4da563
sgml('</TERM>', sub { 
4da563
	my $term = StripString(pop_output());
4da563
	$term =~ tr/\n/ /;
4da563
	output $term;
4da563
	font_off();
4da563
	output "\n";
4da563
	$newline_last = 1;
4da563
});
4da563
	
4da563
sgml('<LISTITEM>', sub {
4da563
	# A bulleted list.
4da563
	if($_[0]->in('ITEMIZEDLIST')) {
4da563
		man_output "\n.TP 0.2i\n\\(bu\n";
4da563
	}
4da563
4da563
	# Need numbers.
4da563
	# Assume Arabic numeration for now.
4da563
	elsif($_[0]->in('ORDEREDLIST')) {
4da563
		man_output "\n.IP ", $_[0]->parent->ext->{'count'}++, ". \n";
4da563
	}
4da563
	
4da563
	$_[0]->ext->{'separator'} = 'none';
4da563
	$separator = 'none';
4da563
});
4da563
4da563
sgml('<SIMPLELIST>', sub {
4da563
	$_[0]->ext->{'first_member'} = 1;
4da563
});
4da563
sgml('<MEMBER>', sub {
4da563
	my $parent = $_[0]->parent;
4da563
	
4da563
	if($parent->attribute('TYPE')->value =~ /Inline/i) {
4da563
		if($parent->ext->{'first_member'}) {
4da563
			# If this is the first member don't put any commas
4da563
			$parent->ext->{'first_member'} = 0;
4da563
		} else {
4da563
			man_output ", ";
4da563
		}
4da563
4da563
	# We don't really have Horiz rendering, so it's the same
4da563
	# as Vert.
4da563
	} else {
4da563
		man_output "\n\n";
4da563
	}
4da563
});
4da563
4da563
# We implement Procedures as indent and lists
4da563
4da563
sgml('<PROCEDURE>', sub {
4da563
	$_[0]->ext->{'count'} = 1;
4da563
	&indent_block_start;
4da563
});
4da563
sgml('</PROCEDURE>', sub {
4da563
	&indent_block_end;
4da563
	$_[0]->parent->ext->{'separator'} = 'full';
4da563
	$separator = 'full';
4da563
});
4da563
4da563
sgml('<STEP>', sub {
4da563
	man_output "\n.IP ", $_[0]->parent->ext->{'count'}++, ". \n";
4da563
	$_[0]->ext->{'separator'} = 'none';
4da563
	$separator = 'none';
4da563
});
4da563
4da563
4da563
########################################################################
4da563
#
4da563
# Linkage, cross references
4da563
#
4da563
########################################################################
4da563
4da563
# Print the URL
4da563
sgml('</ULINK>', sub {
4da563
	man_output ' <URL:', $_[0]->attribute('URL')->value, '>';
4da563
});
4da563
4da563
# If cross reference target is a RefEntry, 
4da563
# output CiteRefEntry-style references.
4da563
sgml('<XREF>', sub {
4da563
	my $id = $_[0]->attribute('LINKEND')->value;
4da563
4da563
	my $manref = $Refs->get("refentry:$id") || $Refs->get("refsect:$id");
4da563
	if(!defined $manref) {
4da563
		$blank_xrefs++ if $write_manpages;
4da563
		man_output "[XRef to $id]";
4da563
		return;
4da563
	}
4da563
4da563
	# Limited ENDTERM support.
4da563
	if(defined $_[0]->attribute('ENDTERM')->value) {
4da563
		my $endterm = $_[0]->attribute('ENDTERM')->value;
4da563
		my $content = $Refs->get("title:$endterm") ||
4da563
				$Refs->get("refentrytitle:$endterm");
4da563
		man_output $content, ' [';
4da563
	}
4da563
4da563
	# This also displays the XREFLABEL (as bold)...
4da563
	# It's not worth the bother to fix it though, there
4da563
	# are better tools for this.
4da563
	my ($title, $sect) = ($manref =~ /(.*)(\(.*\))/);
4da563
	bold_on();
4da563
	man_output $title;
4da563
	font_off();
4da563
	man_output $sect;
4da563
4da563
	if(defined $_[0]->attribute('ENDTERM')->value) {
4da563
		man_output ']';
4da563
	}
4da563
});
4da563
4da563
# Anchor
4da563
4da563
########################################################################
4da563
#
4da563
# SDATA 
4da563
#
4da563
########################################################################
4da563
4da563
man_sgml('|[lt    ]|', '<');
4da563
man_sgml('|[equals]|', '=');
4da563
man_sgml('|[gt    ]|', '>');
4da563
man_sgml('|[plus  ]|', '\(pl');
4da563
man_sgml('|[dollar]|', '$');
4da563
man_sgml('|[num   ]|', '#');
4da563
man_sgml('|[percnt]|', '%');
4da563
man_sgml('|[amp   ]|', '&';;
4da563
man_sgml('|[commat]|', '@');
4da563
man_sgml('|[lsqb  ]|', '[');
4da563
man_sgml('|[bsol  ]|', '\e');
4da563
man_sgml('|[rsqb  ]|', ']');
4da563
man_sgml('|[lcub  ]|', '{');
4da563
man_sgml('|[verbar]|', '\(or');
4da563
man_sgml('|[rcub  ]|', '}');
4da563
man_sgml('|[excl  ]|', '!');
4da563
man_sgml('|[quot  ]|', '"');
4da563
man_sgml('|[apos  ]|', '\\&\'');
4da563
man_sgml('|[lpar  ]|', '(');
4da563
man_sgml('|[rpar  ]|', ')');
4da563
man_sgml('|[comma ]|', ',');
4da563
man_sgml('|[lowbar]|', '_');
4da563
man_sgml('|[period]|', '.');
4da563
man_sgml('|[sol   ]|', '/');
4da563
man_sgml('|[colon ]|', ':');
4da563
man_sgml('|[semi  ]|', ';');
4da563
man_sgml('|[quest ]|', '?');
4da563
man_sgml('|[grave ]|', '`');
4da563
man_sgml('|[tilde ]|', '~');
4da563
man_sgml('|[half  ]|', '\(12');
4da563
man_sgml('|[frac12]|', '\(12');
4da563
man_sgml('|[frac14]|', '\(14');
4da563
man_sgml('|[frac34]|', '\(34');
4da563
man_sgml('|[frac18]|', '1/8');
4da563
man_sgml('|[frac38]|', '3/8');
4da563
man_sgml('|[frac58]|', '5/8');
4da563
man_sgml('|[frac78]|', '7/8');
4da563
man_sgml('|[sup1  ]|', '\u1\l');
4da563
man_sgml('|[sup2  ]|', '\u2\l');
4da563
man_sgml('|[sup3  ]|', '\u3\l');
4da563
man_sgml('|[plusmn]|', '\(+-');
4da563
man_sgml('|[divide]|', '\(di');
4da563
man_sgml('|[times ]|', '\(ti');
4da563
man_sgml('|[pound ]|', '#');
4da563
man_sgml('|[cent  ]|', '\(ct');
4da563
man_sgml('|[yen   ]|', 'yen');
4da563
man_sgml('|[ast   ]|', '*');
4da563
man_sgml('|[horbar]|', '_');
4da563
man_sgml('|[micro ]|', '\(*m');
4da563
man_sgml('|[ohm   ]|', '\(*W');
4da563
man_sgml('|[deg   ]|', '\(de');
4da563
man_sgml('|[sect  ]|', '\(sc');
4da563
man_sgml('|[larr  ]|', '\(<-');
4da563
man_sgml('|[rarr  ]|', '\(->');
4da563
man_sgml('|[uarr  ]|', '\(ua');
4da563
man_sgml('|[darr  ]|', '\(da');
4da563
man_sgml('|[copy  ]|', '\(co');
4da563
man_sgml('|[reg   ]|', '\(rg');
4da563
man_sgml('|[trade ]|', '\(tm');
4da563
man_sgml('|[brvbar]|', '|');
4da563
man_sgml('|[not   ]|', '\(no');
4da563
man_sgml('|[hyphen]|', '\-');
4da563
man_sgml('|[laquo ]|', '<<');
4da563
man_sgml('|[raquo ]|', '>>');
4da563
man_sgml('|[lsquo ]|', '`');
4da563
man_sgml('|[rsquo ]|', '\&\'');
4da563
man_sgml('|[ldquo ]|', '"');
4da563
man_sgml('|[rdquo ]|', '"');
4da563
man_sgml('|[nbsp  ]|', '\ ');
4da563
man_sgml('|[shy   ]|', '\%');
4da563
man_sgml('|[emsp  ]|', '\ \ ');
4da563
man_sgml('|[ensp  ]|', '\ ');
4da563
man_sgml('|[emsp3 ]|', '\ ');
4da563
man_sgml('|[emsp4 ]|', '\ ');
4da563
man_sgml('|[numsp ]|', '\0');
4da563
man_sgml('|[puncsp]|', '\|');
4da563
man_sgml('|[thinsp]|', '\!');
4da563
man_sgml('|[hairsp]|', '\\^');
4da563
man_sgml('|[mdash ]|', '\(em');
4da563
man_sgml('|[ndash ]|', '-');
4da563
man_sgml('|[dash  ]|', '-');
4da563
man_sgml('|[blank ]|', '\ ');
4da563
man_sgml('|[hellip]|', '\&...');
4da563
man_sgml('|[nldr  ]|', '\&..');
4da563
man_sgml('|[frac13]|', '1/3');
4da563
man_sgml('|[frac23]|', '2/3');
4da563
man_sgml('|[frac15]|', '1/5');
4da563
man_sgml('|[frac25]|', '2/5');
4da563
man_sgml('|[frac35]|', '3/5');
4da563
man_sgml('|[frac45]|', '4/5');
4da563
man_sgml('|[frac16]|', '1/6');
4da563
man_sgml('|[frac56]|', '5/6');
4da563
man_sgml('|[cir   ]|', '\(ci');
4da563
man_sgml('|[squ   ]|', '\(sq');
4da563
man_sgml('|[star  ]|', '\(**');
4da563
man_sgml('|[bull  ]|', '\(bu');
4da563
man_sgml('|[dagger]|', '\(dg');
4da563
man_sgml('|[Dagger]|', '\(dd');
4da563
man_sgml('|[caret ]|', '\^');
4da563
man_sgml('|[lsquor]|', '`');
4da563
man_sgml('|[ldquor]|', '``');
4da563
man_sgml('|[fflig ]|', '\(ff');
4da563
man_sgml('|[filig ]|', '\(fi');
4da563
man_sgml('|[ffilig]|', '\(Fi');
4da563
man_sgml('|[ffllig]|', '\(Fl');
4da563
man_sgml('|[fllig ]|', '\(fl');
4da563
man_sgml('|[rdquor]|', '\&\'\'');
4da563
man_sgml('|[rsquor]|', '\&\'');
4da563
man_sgml('|[vellip]|', '\&...');
4da563
man_sgml('|[aacute]|', '\(a\'');
4da563
man_sgml('|[Aacute]|', '\(A\'');
4da563
man_sgml('|[acirc ]|', '\(a^');
4da563
man_sgml('|[Acirc ]|', '\(A^');
4da563
man_sgml('|[agrave]|', '\(a`');
4da563
man_sgml('|[Agrave]|', '\(A`');
4da563
man_sgml('|[auml  ]|', '\(a:');
4da563
man_sgml('|[aelig ]|', '\(ae');
4da563
man_sgml('|[AElig ]|', '\(AE');
4da563
man_sgml('|[eacute]|', '\(e\'');
4da563
man_sgml('|[Eacute]|', '\(E\'');
4da563
man_sgml('|[egrave]|', '\(e`');
4da563
man_sgml('|[Egrave]|', '\(E`');
4da563
man_sgml('|[iacute]|', '\(i\'');
4da563
man_sgml('|[Iacute]|', '\(I\'');
4da563
man_sgml('|[igrave]|', '\(i`');
4da563
man_sgml('|[Igrave]|', '\(I`');
4da563
man_sgml('|[ntilde]|', '\(n~');
4da563
man_sgml('|[Ntilde]|', '\(N~');
4da563
man_sgml('|[oacute]|', '\(o\'');
4da563
man_sgml('|[Oacute]|', '\(O\'');
4da563
man_sgml('|[ograve]|', '\(o`');
4da563
man_sgml('|[Ograve]|', '\(O`');
4da563
man_sgml('|[oslash]|', '\(o/');
4da563
man_sgml('|[Oslash]|', '\(O/');
4da563
man_sgml('|[szlig ]|', '\(ss');
4da563
man_sgml('|[thorn ]|', '\(th');
4da563
man_sgml('|[uacute]|', '\(u\'');
4da563
man_sgml('|[Uacute]|', '\(U\'');
4da563
man_sgml('|[ugrave]|', '\(u`');
4da563
man_sgml('|[Ugrave]|', '\(U`');
4da563
man_sgml('|[aogon ]|', '\(ao');
4da563
man_sgml('|[agr   ]|', '\(*a');
4da563
man_sgml('|[Agr   ]|', '\(*A');
4da563
man_sgml('|[bgr   ]|', '\(*b');
4da563
man_sgml('|[Bgr   ]|', '\(*B');
4da563
man_sgml('|[ggr   ]|', '\(*g');
4da563
man_sgml('|[Ggr   ]|', '\(*G');
4da563
man_sgml('|[dgr   ]|', '\(*d');
4da563
man_sgml('|[Dgr   ]|', '\(*D');
4da563
man_sgml('|[egr   ]|', '\(*e');
4da563
man_sgml('|[Egr   ]|', '\(*E');
4da563
man_sgml('|[zgr   ]|', '\(*z');
4da563
man_sgml('|[Zgr   ]|', '\(*Z');
4da563
man_sgml('|[eegr  ]|', '\(*y');
4da563
man_sgml('|[EEgr  ]|', '\(*Y');
4da563
man_sgml('|[thgr  ]|', '\(*h');
4da563
man_sgml('|[THgr  ]|', '\(*H');
4da563
man_sgml('|[igr   ]|', '\(*i');
4da563
man_sgml('|[Igr   ]|', '\(*I');
4da563
man_sgml('|[kgr   ]|', '\(*k');
4da563
man_sgml('|[Kgr   ]|', '\(*K');
4da563
man_sgml('|[lgr   ]|', '\(*l');
4da563
man_sgml('|[Lgr   ]|', '\(*L');
4da563
man_sgml('|[mgr   ]|', '\(*m');
4da563
man_sgml('|[Mgr   ]|', '\(*M');
4da563
man_sgml('|[ngr   ]|', '\(*n');
4da563
man_sgml('|[Ngr   ]|', '\(*N');
4da563
man_sgml('|[xgr   ]|', '\(*c');
4da563
man_sgml('|[Xgr   ]|', '\(*C');
4da563
man_sgml('|[ogr   ]|', '\(*o');
4da563
man_sgml('|[Ogr   ]|', '\(*O');
4da563
man_sgml('|[pgr   ]|', '\(*p');
4da563
man_sgml('|[Pgr   ]|', '\(*P');
4da563
man_sgml('|[rgr   ]|', '\(*r');
4da563
man_sgml('|[Rgr   ]|', '\(*R');
4da563
man_sgml('|[sgr   ]|', '\(*s');
4da563
man_sgml('|[Sgr   ]|', '\(*S');
4da563
man_sgml('|[sfgr  ]|', '\(ts');
4da563
man_sgml('|[tgr   ]|', '\(*t');
4da563
man_sgml('|[Tgr   ]|', '\(*T');
4da563
man_sgml('|[ugr   ]|', '\(*u');
4da563
man_sgml('|[Ugr   ]|', '\(*U');
4da563
man_sgml('|[phgr  ]|', '\(*f');
4da563
man_sgml('|[PHgr  ]|', '\(*F');
4da563
man_sgml('|[khgr  ]|', '\(*x');
4da563
man_sgml('|[KHgr  ]|', '\(*X');
4da563
man_sgml('|[psgr  ]|', '\(*q');
4da563
man_sgml('|[PSgr  ]|', '\(*Q');
4da563
man_sgml('|[ohgr  ]|', '\(*w');
4da563
man_sgml('|[OHgr  ]|', '\(*W');
4da563
man_sgml('|[alpha ]|', '\(*a');
4da563
man_sgml('|[beta  ]|', '\(*b');
4da563
man_sgml('|[gamma ]|', '\(*g');
4da563
man_sgml('|[Gamma ]|', '\(*G');
4da563
man_sgml('|[delta ]|', '\(*d');
4da563
man_sgml('|[Delta ]|', '\(*D');
4da563
man_sgml('|[epsi  ]|', '\(*e');
4da563
man_sgml('|[epsis ]|', '\(*e');
4da563
man_sgml('|[zeta  ]|', '\(*z');
4da563
man_sgml('|[eta   ]|', '\(*y');
4da563
man_sgml('|[thetas]|', '\(*h');
4da563
man_sgml('|[Theta ]|', '\(*H');
4da563
man_sgml('|[iota  ]|', '\(*i');
4da563
man_sgml('|[kappa ]|', '\(*k');
4da563
man_sgml('|[lambda]|', '\(*l');
4da563
man_sgml('|[Lambda]|', '\(*L');
4da563
man_sgml('|[mu    ]|', '\(*m');
4da563
man_sgml('|[nu    ]|', '\(*n');
4da563
man_sgml('|[xi    ]|', '\(*c');
4da563
man_sgml('|[Xi    ]|', '\(*C');
4da563
man_sgml('|[pi    ]|', '\(*p');
4da563
man_sgml('|[Pi    ]|', '\(*P');
4da563
man_sgml('|[rho   ]|', '\(*r');
4da563
man_sgml('|[sigma ]|', '\(*s');
4da563
man_sgml('|[Sigma ]|', '\(*S');
4da563
man_sgml('|[tau   ]|', '\(*t');
4da563
man_sgml('|[upsi  ]|', '\(*u');
4da563
man_sgml('|[Upsi  ]|', '\(*U');
4da563
man_sgml('|[phis  ]|', '\(*f');
4da563
man_sgml('|[Phi   ]|', '\(*F');
4da563
man_sgml('|[chi   ]|', '\(*x');
4da563
man_sgml('|[psi   ]|', '\(*q');
4da563
man_sgml('|[Psi   ]|', '\(*X');
4da563
man_sgml('|[omega ]|', '\(*w');
4da563
man_sgml('|[Omega ]|', '\(*W');
4da563
man_sgml('|[ap    ]|', '\(ap');
4da563
man_sgml('|[equiv ]|', '\(==');
4da563
man_sgml('|[ge    ]|', '\(>=');
4da563
man_sgml('|[infin ]|', '\(if');
4da563
man_sgml('|[isin  ]|', '\(sb');
4da563
man_sgml('|[le    ]|', '\(<=');
4da563
man_sgml('|[minus ]|', '\(mi');
4da563
man_sgml('|[ne    ]|', '\(!=');
4da563
man_sgml('|[prop  ]|', '\(pt');
4da563
man_sgml('|[square]|', '\(sq');
4da563
man_sgml('|[sub   ]|', '\(sb');
4da563
man_sgml('|[sube  ]|', '\(ib');
4da563
man_sgml('|[sup   ]|', '\(sp');
4da563
man_sgml('|[supe  ]|', '\(ip');
4da563
man_sgml('|[acute ]|', '\&\'');
4da563
man_sgml('|[breve ]|', '\(be');
4da563
man_sgml('|[caron ]|', '\(hc');
4da563
man_sgml('|[cedil ]|', '\(cd');
4da563
man_sgml('|[dot   ]|', '\(dt');
4da563
man_sgml('|[macr  ]|', '\(ma');
4da563
man_sgml('|[ogon  ]|', '\(og');
4da563
man_sgml('|[ring  ]|', '\(ri');
4da563
man_sgml('|[uml   ]|', '\(..');
4da563
4da563
sgml('sdata',sub {
4da563
	my ($element, $event) = @_;
4da563
	my ($file, $line) = ($event->file, $event->line);
4da563
	man_output "|[", $_[0], "]|";
4da563
	warn "Warning: unrecognized SDATA '$_[0]'"
4da563
	     . ($file && $line ? " in $file on line $line" : "")
4da563
	     . ": please add definition to docbook2man-spec.pl\n";
4da563
});
4da563
4da563
#
4da563
# Default handlers (uncomment these if needed).  Right now, these are set
4da563
# up to gag on any unrecognised elements, sdata, processing-instructions,
4da563
# or entities.
4da563
#
4da563
# sgml('start_element',sub { die "Unknown element: " . $_[0]->name; });
4da563
# sgml('end_element','');
4da563
4da563
# This is for weeding out and escaping certain characters.
4da563
# This looks like it's inefficient since it's done on every line, but
4da563
# in reality, SGMLSpm and sgmlspl parsing ESIS takes _much_ longer.
4da563
4da563
sgml('cdata', sub
4da563
{ 
4da563
	if(!$write_manpages) { return; }
4da563
	elsif($raw_cdata) { output $_[0]; return; }
4da563
4da563
	if($separator eq 'full') {
4da563
		output "\n" unless $newline_last++;
4da563
		output ".PP\n";
4da563
		$separator = '';
4da563
	}
4da563
	
4da563
	# Escape backslashes
4da563
	$_[0] =~ s/\\/\\\\/g;
4da563
4da563
  # Escape dots and single quotes in column 1
4da563
	$_[0] =~ s/^[ \t]*\./\\\&\./;
4da563
	$_[0] =~ s/^[ \t]*\'/\\\&\'/;
4da563
4da563
4da563
	# In non-'pre'-type elements:
4da563
	if(!$nocollapse_whitespace) {
4da563
		# Change tabs to spaces
4da563
		$_[0] =~ tr/\t / /s;
4da563
4da563
		# Do not allow indents at beginning of line
4da563
		# groff chokes on that.
4da563
		if($newline_last) { 
4da563
			$_[0] =~ s/^ //;
4da563
4da563
			# If the line is all blank, don't do anything.
4da563
			if($_[0] eq '') { return; }
4da563
			
4da563
			$_[0] =~ s/^\./\\\&\./;
4da563
	
4da563
			# Argh... roff doesn't like ' for some unknown reason 
4da563
			$_[0] =~ s/^\'/\\\&\'/;
4da563
		}
4da563
	}
4da563
4da563
	$newline_last = 0;
4da563
4da563
	output $_[0];
4da563
});
4da563
4da563
4da563
# When in whitespace-collapsing mode, we disallow consecutive newlines.
4da563
4da563
sgml('re', sub
4da563
{
4da563
	if($nocollapse_whitespace || !$newline_last) {
4da563
		output "\n";
4da563
	}
4da563
4da563
	$newline_last = 1;
4da563
});
4da563
4da563
sgml('pi', sub {});
4da563
sgml('entity',sub { die "Unknown external entity: " . $_[0]->name; });
4da563
sgml('start_subdoc',sub { die "Unknown subdoc entity: " . $_[0]->name; });
4da563
sgml('end_subdoc',sub{});
4da563
sgml('conforming',sub{});
4da563
4da563
1;
4da563