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