#! /usr/bin/perl

use strict;
use warnings;

# gener
sub xlink($)
{
  my ($fun) = @_;

  # not documented, or do not exist (!)
  return "<function>$fun</function>"
  if $fun eq 'PQregisterThreadLock' or
     $fun eq 'PQerrorField' or
     $fun eq 'PQsetResultInstanceData';

  my $lfun = lc $fun;
  return "<xref linkend=\"libpq-$lfun\"/>";
}

# process input

$/ = undef;
my $text = <>;
$text =~ s,<function>(PQ[_a-zA-Z0-9]*)</function>(?!\s*\.?<indexterm>),xlink($1),seg;
print $text;
