<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#! /usr/bin/perl -w
#
# Generate API documentation. See documentation/documentation.sgml for details.
#
# Copyright (C) 2000 Mike McCormack
# Copyright (C) 2003 Jon Griffiths
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# TODO
#  SGML gurus - feel free to smarten up the SGML.
#  Add any other relevant information for the dll - imports etc
#  Should we have a special output mode for WineHQ?

use strict;
use bytes;

# Function flags. most of these come from the spec flags
my $FLAG_DOCUMENTED = 1;
my $FLAG_NONAME     = 2;
my $FLAG_I386       = 4;
my $FLAG_REGISTER   = 8;
my $FLAG_APAIR      = 16; # The A version of a matching W function
my $FLAG_WPAIR      = 32; # The W version of a matching A function
my $FLAG_64PAIR     = 64; # The 64 bit version of a matching 32 bit function


# Options
my $opt_output_directory = "man3w"; # All default options are for nroff (man pages)
my $opt_manual_section = "3w";
my $opt_wine_root_dir = "";
my $opt_output_format = "";         # '' = nroff, 'h' = html, 's' = sgml
my $opt_output_empty = 0;           # Non-zero = Create 'empty' comments (for every implemented function)
my $opt_fussy = 1;                  # Non-zero = Create only if we have a RETURNS section
my $opt_verbose = 0;                # &gt;0 = verbosity. Can be given multiple times (for debugging)
my @opt_header_file_list = ();
my @opt_spec_file_list = ();
my @opt_source_file_list = ();

# All the collected details about all the .spec files being processed
my %spec_files;
# All the collected details about all the source files being processed
my %source_files;
# All documented functions that are to be placed in the index
my @index_entries_list = ();

# useful globals
my $pwd = `pwd`."/";
$pwd =~ s/\n//;
my @datetime = localtime;
my @months = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun",
               "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
my $year = $datetime[5] + 1900;
my $date = "$months[$datetime[4]] $year";

sub usage
{
  print "\nCreate API Documentation from Wine source code.\n\n",
        "Usage: c2man.pl [options] {-w &lt;spec&gt;} {-I &lt;include&gt;} {&lt;source&gt;}\n",
        "Where: &lt;spec&gt; is a .spec file giving a DLL's exports.\n",
        "       &lt;include&gt; is an include directory used by the DLL.\n",
        "       &lt;source&gt; is a source file of the DLL.\n",
        "       The above can be given multiple times on the command line, as appropriate.\n",
        "Options:\n",
        " -Th      : Output HTML instead of a man page\n",
        " -Ts      : Output SGML (Docbook source) instead of a man page\n",
        " -o &lt;dir&gt; : Create output in &lt;dir&gt;, default is \"",$opt_output_directory,"\"\n",
        " -s &lt;sect&gt;: Set manual section to &lt;sect&gt;, default is ",$opt_manual_section,"\n",
        " -e       : Output \"FIXME\" documentation from empty comments.\n",
        " -v       : Verbosity. Can be given more than once for more detail.\n";
}

# Print usage if we're called with no args
if( @ARGV == 0)
{
  usage();
}

# Process command line options
while(defined($_ = shift @ARGV))
{
  if( s/^-// )
  {
    # An option.
    for ($_)
    {
      /^o$/  &amp;&amp; do { $opt_output_directory = shift @ARGV; last; };
      s/^S// &amp;&amp; do { $opt_manual_section   = $_;          last; };
      /^Th$/ &amp;&amp; do { $opt_output_format  = "h";           last; };
      /^Ts$/ &amp;&amp; do { $opt_output_format  = "s";           last; };
      /^v$/  &amp;&amp; do { $opt_verbose++;                      last; };
      /^e$/  &amp;&amp; do { $opt_output_empty = 1;               last; };
      /^L$/  &amp;&amp; do { last; };
      /^w$/  &amp;&amp; do { @opt_spec_file_list = (@opt_spec_file_list, shift @ARGV); last; };
      s/^I// &amp;&amp; do { if ($_ ne ".") {
                       my $include = $_."/*.h";
                       $include =~ s/\/\//\//g;
                       my $have_headers = `ls $include &gt;/dev/null 2&gt;&amp;1`;
                       if ($? &gt;&gt; 8 == 0) { @opt_header_file_list = (@opt_header_file_list, $include); }
                     }
                     last;
                   };
      s/^R// &amp;&amp; do { if ($_ =~ /^\//) { $opt_wine_root_dir = $_; }
                     else { $opt_wine_root_dir = `cd $pwd/$_ &amp;&amp; pwd`; }
                     $opt_wine_root_dir =~ s/\n//;
                     $opt_wine_root_dir =~ s/\/\//\//g;
                     if (! $opt_wine_root_dir =~ /\/$/ ) { $opt_wine_root_dir = $opt_wine_root_dir."/"; };
                     last;
             };
      die "Unrecognised option $_\n";
    }
  }
  else
  {
    # A source file.
    push (@opt_source_file_list, $_);
  }
}

# Remove duplicate include directories
my %htmp;
@opt_header_file_list = grep(!$htmp{$_}++, @opt_header_file_list);

if ($opt_verbose &gt; 3)
{
  print "Output dir:'".$opt_output_directory."'\n";
  print "Section   :'".$opt_manual_section."'\n";
  print "Format  :'".$opt_output_format."'\n";
  print "Root    :'".$opt_wine_root_dir."'\n";
  print "Spec files:'@opt_spec_file_list'\n";
  print "Includes  :'@opt_header_file_list'\n";
  print "Sources   :'@opt_source_file_list'\n";
}

if (@opt_spec_file_list == 0)
{
  exit 0; # Don't bother processing non-dll files
}

# Read in each .spec files exports and other details
while(my $spec_file = shift @opt_spec_file_list)
{
  process_spec_file($spec_file);
}

if ($opt_verbose &gt; 3)
{
    foreach my $spec_file ( keys %spec_files )
    {
        print "in '$spec_file':\n";
        my $spec_details = $spec_files{$spec_file}[0];
        my $exports = $spec_details-&gt;{EXPORTS};
        for (@$exports)
        {
           print @$_[0].",".@$_[1].",".@$_[2].",".@$_[3]."\n";
        }
    }
}

# Extract and output the comments from each source file
while(defined($_ = shift @opt_source_file_list))
{
  process_source_file($_);
}

# Write the index files for each spec
process_index_files();

# Write the master index file
output_master_index_files();

exit 0;


# Generate the list of exported entries for the dll
sub process_spec_file
{
  my $spec_name = shift(@_);
  my $dll_name  = $spec_name;
  $dll_name =~ s/\..*//;       # Strip the file extension
  my $uc_dll_name  = uc $dll_name;

  my $spec_details =
  {
    NAME =&gt; $spec_name,
    DLL_NAME =&gt; $dll_name,
    NUM_EXPORTS =&gt; 0,
    NUM_STUBS =&gt; 0,
    NUM_FUNCS =&gt; 0,
    NUM_FORWARDS =&gt; 0,
    NUM_VARS =&gt; 0,
    NUM_DOCS =&gt; 0,
    CONTRIBUTORS =&gt; [ ],
    SOURCES =&gt; [ ],
    DESCRIPTION =&gt; [ ],
    EXPORTS =&gt; [ ],
    EXPORTED_NAMES =&gt; { },
    IMPLEMENTATION_NAMES =&gt; { },
    EXTRA_COMMENTS =&gt; [ ],
    CURRENT_EXTRA =&gt; [ ] ,
  };

  if ($opt_verbose &gt; 0)
  {
    print "Processing ".$spec_name."\n";
  }

  # We allow opening to fail just to cater for the peculiarities of
  # the Wine build system. This doesn't hurt, in any case
  open(SPEC_FILE, "&lt;$spec_name") || return;

  while(&lt;SPEC_FILE&gt;)
  {
    s/^\s+//;            # Strip leading space
    s/\s+\n$/\n/;        # Strip trailing space
    s/\s+/ /g;           # Strip multiple tabs &amp; spaces to a single space
    s/\s*#.*//;          # Strip comments
    s/\(.*\)/ /;         # Strip arguments
    s/\s+/ /g;           # Strip multiple tabs &amp; spaces to a single space (again)
    s/\n$//;             # Strip newline

    my $flags = 0;
    if( /\-noname/ )
    {
      $flags |= $FLAG_NONAME;
    }
    if( /\-i386/ )
    {
      $flags |= $FLAG_I386;
    }
    if( /\-register/ )
    {
      $flags |= $FLAG_REGISTER;
    }
    s/ \-[a-z0-9]+//g;   # Strip flags

    if( /^(([0-9]+)|@) / )
    {
      # This line contains an exported symbol
      my ($ordinal, $call_convention, $exported_name, $implementation_name) = split(' ');

      for ($call_convention)
      {
        /^(cdecl|stdcall|varargs|pascal)$/
                 &amp;&amp; do { $spec_details-&gt;{NUM_FUNCS}++;    last; };
        /^(variable|equate)$/
                 &amp;&amp; do { $spec_details-&gt;{NUM_VARS}++;     last; };
        /^(extern)$/
                 &amp;&amp; do { $spec_details-&gt;{NUM_FORWARDS}++; last; };
        /^stub$/ &amp;&amp; do { $spec_details-&gt;{NUM_STUBS}++;    last; };
        if ($opt_verbose &gt; 0)
        {
          print "Warning: didn't recognise convention \'",$call_convention,"'\n";
        }
        last;
      }

      # Convert ordinal only names so we can find them later
      if ($exported_name eq "@")
      {
        $exported_name = $uc_dll_name.'_'.$ordinal;
      }
      if (!defined($implementation_name))
      {
        $implementation_name = $exported_name;
      }
      if ($implementation_name eq "")
      {
        $implementation_name = $exported_name;
      }

      if ($implementation_name =~ /(.*?)\./)
      {
        $call_convention = "forward"; # Referencing a function from another dll
        $spec_details-&gt;{NUM_FUNCS}--;
        $spec_details-&gt;{NUM_FORWARDS}++;
      }

      # Add indices for the exported and implementation names
      $spec_details-&gt;{EXPORTED_NAMES}{$exported_name} = $spec_details-&gt;{NUM_EXPORTS};
      if ($implementation_name ne $exported_name)
      {
        $spec_details-&gt;{IMPLEMENTATION_NAMES}{$exported_name} = $spec_details-&gt;{NUM_EXPORTS};
      }

      # Add the exported entry
      $spec_details-&gt;{NUM_EXPORTS}++;
      my @export = ($ordinal, $call_convention, $exported_name, $implementation_name, $flags);
      push (@{$spec_details-&gt;{EXPORTS}},[@export]);
    }
  }
  close(SPEC_FILE);

  # Add this .spec files details to the list of .spec files
  $spec_files{$uc_dll_name} = [$spec_details];
}

# Read each source file, extract comments, and generate API documentation if appropriate
sub process_source_file
{
  my $source_file = shift(@_);
  my $source_details =
  {
    CONTRIBUTORS =&gt; [ ],
    DEBUG_CHANNEL =&gt; "",
  };
  my $comment =
  {
    FILE =&gt; $source_file,
    COMMENT_NAME =&gt; "",
    ALT_NAME =&gt; "",
    DLL_NAME =&gt; "",
    ORDINAL =&gt; "",
    RETURNS =&gt; "",
    PROTOTYPE =&gt; [],
    TEXT =&gt; [],
  };
  my $parse_state = 0;
  my $ignore_blank_lines = 1;
  my $extra_comment = 0; # 1 if this is an extra comment, i.e its not a .spec export

  if ($opt_verbose &gt; 0)
  {
    print "Processing ".$source_file."\n";
  }
  open(SOURCE_FILE,"&lt;$source_file") || die "couldn't open ".$source_file."\n";

  # Add this source file to the list of source files
  $source_files{$source_file} = [$source_details];

  while(&lt;SOURCE_FILE&gt;)
  {
    s/\n$//;   # Strip newline
    s/^\s+//;  # Strip leading space
    s/\s+$//;  # Strip trailing space
    if (! /^\*\|/ )
    {
      # Strip multiple tabs &amp; spaces to a single space
      s/\s+/ /g;
    }

    if ( / +Copyright *(\([Cc]\))*[0-9 \-\,\/]*([[:alpha:][:^ascii:] \.\-]+)/ )
    {
      # Extract a contributor to this file
      my $contributor = $2;
      $contributor =~ s/ *$//;
      $contributor =~ s/^by //;
      $contributor =~ s/\.$//;
      $contributor =~ s/ (for .*)/ \($1\)/;
      if ($contributor ne "")
      {
        if ($opt_verbose &gt; 3)
        {
          print "Info: Found contributor:'".$contributor."'\n";
        }
        push (@{$source_details-&gt;{CONTRIBUTORS}},$contributor);
      }
    }
    elsif ( /WINE_DEFAULT_DEBUG_CHANNEL\(([A-Za-z]*)\)/ )
    {
      # Extract the debug channel to use
      if ($opt_verbose &gt; 3)
      {
        print "Info: Found debug channel:'".$1."'\n";
      }
      $source_details-&gt;{DEBUG_CHANNEL} = $1;
    }

    if ($parse_state == 0) # Searching for a comment
    {
      if ( /^\/\**$/ )
      {
        # Found a comment start
        $comment-&gt;{COMMENT_NAME} = "";
        $comment-&gt;{ALT_NAME} = "";
        $comment-&gt;{DLL_NAME} = "";
        $comment-&gt;{ORDINAL} = "";
        $comment-&gt;{RETURNS} = "";
        $comment-&gt;{PROTOTYPE} = [];
        $comment-&gt;{TEXT} = [];
        $ignore_blank_lines = 1;
        $extra_comment = 0;
        $parse_state = 3;
      }
    }
    elsif ($parse_state == 1) # Reading in a comment
    {
      if ( /^\**\// )
      {
        # Found the end of the comment
        $parse_state = 2;
      }
      elsif ( s/^\*\|/\|/ )
      {
        # A line of comment not meant to be pre-processed
        push (@{$comment-&gt;{TEXT}},$_); # Add the comment text
      }
      elsif ( s/^ *\** *// )
      {
        # A line of comment, starting with an asterisk
        if ( /^[A-Z]+$/ || $_ eq "")
        {
          # This is a section start, so skip blank lines before and after it.
          my $last_line = pop(@{$comment-&gt;{TEXT}});
          if (defined($last_line) &amp;&amp; $last_line ne "")
          {
            # Put it back
            push (@{$comment-&gt;{TEXT}},$last_line);
          }
          if ( /^[A-Z]+$/ )
          {
            $ignore_blank_lines = 1;
          }
          else
          {
            $ignore_blank_lines = 0;
          }
        }

        if ($ignore_blank_lines == 0 || $_ ne "")
        {
          push (@{$comment-&gt;{TEXT}},$_); # Add the comment text
        }
      }
      else
      {
        # This isn't a well formatted comment: look for the next one
        $parse_state = 0;
      }
    }
    elsif ($parse_state == 2) # Finished reading in a comment
    {
      if ( /(WINAPIV|WINAPI|__cdecl|PASCAL|CALLBACK|FARPROC16)/ ||
           /.*?\(.*?\)/ )
      {
        # Comment is followed by a function definition
        $parse_state = 4; # Fall through to read prototype
      }
      else
      {
        # Allow cpp directives and blank lines between the comment and prototype
        if ($extra_comment == 1)
        {
          # An extra comment not followed by a function definition
          $parse_state = 5; # Fall through to process comment
        }
        elsif (!/^\#/ &amp;&amp; !/^ *$/ &amp;&amp; !/^__ASM_GLOBAL_FUNC/)
        {
          # This isn't a well formatted comment: look for the next one
          if ($opt_verbose &gt; 1)
          {
            print "Info: Function '",$comment-&gt;{COMMENT_NAME},"' not followed by prototype.\n";
          }
          $parse_state = 0;
        }
      }
    }
    elsif ($parse_state == 3) # Reading in the first line of a comment
    {
      s/^ *\** *//;
      if ( /^([\@A-Za-z0-9_]+) +(\(|\[)([A-Za-z0-9_]+)\.(([0-9]+)|@)(\)|\])$/ )
      {
        # Found a correctly formed "ApiName (DLLNAME.Ordinal)" line.
        $comment-&gt;{COMMENT_NAME} = $1;
        $comment-&gt;{DLL_NAME} = uc $3;
        $comment-&gt;{ORDINAL} = $4;
        $comment-&gt;{DLL_NAME} =~ s/^KERNEL$/KRNL386/; # Too many of these to ignore, _old_ code
        $parse_state = 1;
      }
      elsif ( /^([A-Za-z0-9_]+) +\{([A-Za-z0-9_]+)\}$/ )
      {
        # Found a correctly formed "CommentTitle {DLLNAME}" line (extra documentation)
        $comment-&gt;{COMMENT_NAME} = $1;
        $comment-&gt;{DLL_NAME} = uc $2;
        $comment-&gt;{ORDINAL} = "";
        $extra_comment = 1;
        $parse_state = 1;
      }
      else
      {
        # This isn't a well formatted comment: look for the next one
        $parse_state = 0;
      }
    }

    if ($parse_state == 4) # Reading in the function definition
    {
      push (@{$comment-&gt;{PROTOTYPE}},$_);
      # Strip comments from the line before checking for ')'
      my $stripped_line = $_;
      $stripped_line =~ s/ *(\/\* *)(.*?)( *\*\/ *)//;
      if ( $stripped_line =~ /\)/ )
      {
        # Strip a blank last line
        my $last_line = pop(@{$comment-&gt;{TEXT}});
        if (defined($last_line) &amp;&amp; $last_line ne "")
        {
          # Put it back
          push (@{$comment-&gt;{TEXT}},$last_line);
        }

        if ($opt_output_empty != 0 &amp;&amp; @{$comment-&gt;{TEXT}} == 0)
        {
          # Create a 'not implemented' comment
          @{$comment-&gt;{TEXT}} = ("fixme: This function has not yet been documented.");
        }
        $parse_state = 5;
      }
    }

    if ($parse_state == 5) # Processing the comment
    {
      # Process it, if it has any text
      if (@{$comment-&gt;{TEXT}} &gt; 0)
      {
        if ($extra_comment == 1)
        {
          process_extra_comment($comment);
        }
        else
        {
          @{$comment-&gt;{TEXT}} = ("DESCRIPTION", @{$comment-&gt;{TEXT}});
          process_comment($comment);
        }
      }
      elsif ($opt_verbose &gt; 1 &amp;&amp; $opt_output_empty == 0)
      {
        print "Info: Function '",$comment-&gt;{COMMENT_NAME},"' has no documentation.\n";
      }
      $parse_state = 0;
    }
  }
  close(SOURCE_FILE);
}

# Standardise a comments text for consistency
sub process_comment_text
{
  my $comment = shift(@_);
  my $i = 0;

  for (@{$comment-&gt;{TEXT}})
  {
    if (! /^\|/ )
    {
      # Map I/O values. These come in too many formats to standardise now....
      s/\[I\]|\[i\]|\[in\]|\[IN\]/\[In\] /g;
      s/\[O\]|\[o\]|\[out\]|\[OUT\]/\[Out\]/g;
      s/\[I\/O\]|\[I\,O\]|\[i\/o\]|\[in\/out\]|\[IN\/OUT\]/\[In\/Out\]/g;
      # TRUE/FALSE/NULL are defines, capitilise them
      s/True|true/TRUE/g;
      s/False|false/FALSE/g;
      s/Null|null/NULL/g;
      # Preferred capitalisations
      s/ wine| WINE/ Wine/g;
      s/ API | api / Api /g;
      s/DLL|Dll/dll /g;
      s/ URL | url / Url /g;
      s/WIN16|win16/Win16/g;
      s/WIN32|win32/Win32/g;
      s/WIN64|win64/Win64/g;
      s/ ID | id / Id /g;
      # Grammar
      s/([a-z])\.([A-Z])/$1\. $2/g; # Space after full stop
      s/ \:/\:/g;                   # Colons to the left
      s/ \;/\;/g;                   # Semi-colons too
      # Common idioms
      s/^See ([A-Za-z0-9_]+)\.$/See $1\(\)\./;                # Referring to A version from W
      s/^Unicode version of ([A-Za-z0-9_]+)\.$/See $1\(\)\./; # Ditto
      s/^64\-bit version of ([A-Za-z0-9_]+)\.$/See $1\(\)\./; # Referring to 32 bit version from 64
      s/^PARAMETERS$/PARAMS/;  # Name of parameter section should be 'PARAMS'
      # Trademarks
      s/( |\.)(MS|Microsoft|microsoft)( |\.)/$1Microsoft\(tm\)$3/g;
      s/( |\.)(Windows|windows|windoze|winblows)( |\.)/$1Windows\(tm\)$3/g;
      s/( |\.)(DOS|dos|msdos)( |\.)/$1MS-DOS\(tm\)$3/g;
      s/( |\.)(UNIX|Unix|unix)( |\.)/$1Unix\(tm\)$3/g;
      # Abbreviations
      s/( char )/ character /g;
      s/( chars )/ characters /g;
      s/( info )/ information /g;
      s/( app )/ application /g;
      s/( apps )/ applications /g;
      s/( exe )/ executable /g;
      s/( ptr )/ pointer /g;
      s/( obj )/ object /g;
      s/( err )/ error /g;
      s/( bool )/ boolean /g;
      # Punctuation
      if ( /\[I|\[O/ &amp;&amp; ! /\.$/ )
      {
        $_ = $_."."; # Always have a full stop at the end of parameter desc.
      }
      elsif ($i &gt; 0 &amp;&amp; /^[A-Z]*$/  &amp;&amp;
               !(@{$comment-&gt;{TEXT}}[$i-1] =~ /\.$/) &amp;&amp;
               !(@{$comment-&gt;{TEXT}}[$i-1] =~ /\:$/))
      {

        if (!(@{$comment-&gt;{TEXT}}[$i-1] =~ /^[A-Z]*$/))
        {
          # Paragraphs always end with a full stop
          @{$comment-&gt;{TEXT}}[$i-1] = @{$comment-&gt;{TEXT}}[$i-1].".";
        }
      }
    }
    $i++;
  }
}

# Standardise our comment and output it if it is suitable.
sub process_comment
{
  my $comment = shift(@_);

  # Don't process this comment if the function isn't exported
  my $spec_details = $spec_files{$comment-&gt;{DLL_NAME}}[0];

  if (!defined($spec_details))
  {
    if ($opt_verbose &gt; 2)
    {
      print "Warning: Function '".$comment-&gt;{COMMENT_NAME}."' belongs to '".
            $comment-&gt;{DLL_NAME}."' (not passed with -w): not processing it.\n";
    }
    return;
  }

  if ($comment-&gt;{COMMENT_NAME} eq "@")
  {
    my $found = 0;

    # Find the name from the .spec file
    for (@{$spec_details-&gt;{EXPORTS}})
    {
      if (@$_[0] eq $comment-&gt;{ORDINAL})
      {
        $comment-&gt;{COMMENT_NAME} = @$_[2];
        $found = 1;
      }
    }

    if ($found == 0)
    {
      # Create an implementation name
      $comment-&gt;{COMMENT_NAME} = $comment-&gt;{DLL_NAME}."_".$comment-&gt;{ORDINAL};
    }
  }

  my $exported_names = $spec_details-&gt;{EXPORTED_NAMES};
  my $export_index = $exported_names-&gt;{$comment-&gt;{COMMENT_NAME}};
  my $implementation_names = $spec_details-&gt;{IMPLEMENTATION_NAMES};

  if (!defined($export_index))
  {
    # Perhaps the comment uses the implementation name?
    $export_index = $implementation_names-&gt;{$comment-&gt;{COMMENT_NAME}};
  }
  if (!defined($export_index))
  {
    # This function doesn't appear to be exported. hmm.
    if ($opt_verbose &gt; 2)
    {
      print "Warning: Function '".$comment-&gt;{COMMENT_NAME}."' claims to belong to '".
            $comment-&gt;{DLL_NAME}."' but is not exported by it: not processing it.\n";
    }
    return;
  }

  # When the function is exported twice we have the second name below the first
  # (you see this a lot in ntdll, but also in some other places).
  my $first_line = ${@{$comment-&gt;{TEXT}}}[1];

  if ( $first_line =~ /^(@|[A-Za-z0-9_]+) +(\(|\[)([A-Za-z0-9_]+)\.(([0-9]+)|@)(\)|\])$/ )
  {
    # Found a second name - mark it as documented
    my $alt_index = $exported_names-&gt;{$1};
    if (defined($alt_index))
    {
      if ($opt_verbose &gt; 2)
      {
        print "Info: Found alternate name '",$1,"\n";
      }
      my $alt_export = @{$spec_details-&gt;{EXPORTS}}[$alt_index];
      @$alt_export[4] |= $FLAG_DOCUMENTED;
      $spec_details-&gt;{NUM_DOCS}++;
      ${@{$comment-&gt;{TEXT}}}[1] = "";
    }
  }

  if (@{$spec_details-&gt;{CURRENT_EXTRA}})
  {
    # We have an extra comment that might be related to this one
    my $current_comment = ${@{$spec_details-&gt;{CURRENT_EXTRA}}}[0];
    my $current_name = $current_comment-&gt;{COMMENT_NAME};
    if ($comment-&gt;{COMMENT_NAME} =~ /^$current_name/ &amp;&amp; $comment-&gt;{COMMENT_NAME} ne $current_name)
    {
      if ($opt_verbose &gt; 2)
      {
        print "Linking ",$comment-&gt;{COMMENT_NAME}," to $current_name\n";
      }
      # Add a reference to this comment to our extra comment
      push (@{$current_comment-&gt;{TEXT}}, $comment-&gt;{COMMENT_NAME}."()","");
    }
  }

  # We want our docs generated using the implementation name, so they are unique
  my $export = @{$spec_details-&gt;{EXPORTS}}[$export_index];
  $comment-&gt;{COMMENT_NAME} = @$export[3];
  $comment-&gt;{ALT_NAME} = @$export[2];

  # Mark the function as documented
  $spec_details-&gt;{NUM_DOCS}++;
  @$export[4] |= $FLAG_DOCUMENTED;

  # This file is used by the DLL - Make sure we get our contributors right
  push (@{$spec_details-&gt;{SOURCES}},$comment-&gt;{FILE});

  # If we have parameter comments in the prototype, extract them
  my @parameter_comments;
  for (@{$comment-&gt;{PROTOTYPE}})
  {
    s/ *\, */\,/g; # Strip spaces from around commas

    if ( s/ *(\/\* *)(.*?)( *\*\/ *)// ) # Strip out comment
    {
      my $parameter_comment = $2;
      if (!$parameter_comment =~ /^\[/ )
      {
        # Add [IO] markers so we format the comment correctly
        $parameter_comment = "[fixme] ".$parameter_comment;
      }
      if ( /( |\*)([A-Za-z_]{1}[A-Za-z_0-9]*)(\,|\))/ )
      {
        # Add the parameter name
        $parameter_comment = $2." ".$parameter_comment;
      }
      push (@parameter_comments, $parameter_comment);
    }
  }

  # If we extracted any prototype comments, add them to the comment text.
  if (@parameter_comments)
  {
    @parameter_comments = ("PARAMS", @parameter_comments);
    my @new_comment = ();
    my $inserted_params = 0;

    for (@{$comment-&gt;{TEXT}})
    {
      if ( $inserted_params == 0 &amp;&amp; /^[A-Z]+$/ )
      {
        # Found a section header, so this is where we insert
        push (@new_comment, @parameter_comments);
        $inserted_params = 1;
      }
      push (@new_comment, $_);
    }
    if ($inserted_params == 0)
    {
      # Add them to the end
      push (@new_comment, @parameter_comments);
    }
    $comment-&gt;{TEXT} = [@new_comment];
  }

  if ($opt_fussy == 1 &amp;&amp; $opt_output_empty == 0)
  {
    # Reject any comment that doesn't have a description or a RETURNS section.
    # This is the default for now, 'coz many comments aren't suitable.
    my $found_returns = 0;
    my $found_description_text = 0;
    my $in_description = 0;
    for (@{$comment-&gt;{TEXT}})
    {
      if ( /^RETURNS$/ )
      {
        $found_returns = 1;
        $in_description = 0;
      }
      elsif ( /^DESCRIPTION$/ )
      {
        $in_description = 1;
      }
      elsif ($in_description == 1)
      {
        if ( !/^[A-Z]+$/ )
        {
          # Don't reject comments that refer to another doc (e.g. A/W)
          if ( /^See ([A-Za-z0-9_]+)\.$/ )
          {
            if ($comment-&gt;{COMMENT_NAME} =~ /W$/ )
            {
              # This is probably a Unicode version of an Ascii function.
              # Create the Ascii name and see if its been documented
              my $ascii_name = $comment-&gt;{COMMENT_NAME};
              $ascii_name =~ s/W$/A/;

              my $ascii_export_index = $exported_names-&gt;{$ascii_name};

              if (!defined($ascii_export_index))
              {
                $ascii_export_index = $implementation_names-&gt;{$ascii_name};
              }
              if (!defined($ascii_export_index))
              {
                if ($opt_verbose &gt; 2)
                {
                  print "Warning: Function '".$comment-&gt;{COMMENT_NAME}."' is not an A/W pair.\n";
                }
              }
              else
              {
                my $ascii_export = @{$spec_details-&gt;{EXPORTS}}[$ascii_export_index];
                if (@$ascii_export[4] &amp; $FLAG_DOCUMENTED)
                {
                  # Flag these functions as an A/W pair
                  @$ascii_export[4] |= $FLAG_APAIR;
                  @$export[4] |= $FLAG_WPAIR;
                }
              }
            }
            $found_returns = 1;
          }
          elsif ( /^Unicode version of ([A-Za-z0-9_]+)\.$/ )
          {
            @$export[4] |= $FLAG_WPAIR; # Explicitly marked as W version
            $found_returns = 1;
          }
          elsif ( /^64\-bit version of ([A-Za-z0-9_]+)\.$/ )
          {
            @$export[4] |= $FLAG_64PAIR; # Explicitly marked as 64 bit version
            $found_returns = 1;
          }
          $found_description_text = 1;
        }
        else
        {
          $in_description = 0;
        }
      }
    }
    if ($found_returns == 0 || $found_description_text == 0)
    {
      if ($opt_verbose &gt; 2)
      {
        print "Info: Function '",$comment-&gt;{COMMENT_NAME},"' has no ",
              "description and/or RETURNS section, skipping\n";
      }
      $spec_details-&gt;{NUM_DOCS}--;
      @$export[4] &amp;= ~$FLAG_DOCUMENTED;
      return;
    }
  }

  process_comment_text($comment);

  # Strip the prototypes return value, call convention, name and brackets
  # (This leaves it as a list of types and names, or empty for void functions)
  my $prototype = join(" ", @{$comment-&gt;{PROTOTYPE}});
  $prototype =~ s/  / /g;

  if ( $prototype =~ /(WINAPIV|WINAPI|__cdecl|PASCAL|CALLBACK|FARPROC16)/ )
  {
    $prototype =~ s/^(.*?) (WINAPIV|WINAPI|__cdecl|PASCAL|CALLBACK|FARPROC16) (.*?)\( *(.*)/$4/;
    $comment-&gt;{RETURNS} = $1;
  }
  else
  {
    $prototype =~ s/^(.*?)([A-Za-z0-9_]+)\( *(.*)/$3/;
    $comment-&gt;{RETURNS} = $1;
  }

  $prototype =~ s/ *\).*//;        # Strip end bracket
  $prototype =~ s/ *\* */\*/g;     # Strip space around pointers
  $prototype =~ s/ *\, */\,/g;     # Strip space around commas
  $prototype =~ s/^(void|VOID)$//; # If void, leave blank
  $prototype =~ s/\*([A-Za-z_])/\* $1/g; # Separate pointers from parameter name
  @{$comment-&gt;{PROTOTYPE}} = split ( /,/ ,$prototype);

  # FIXME: If we have no parameters, make sure we have a PARAMS: None. section

  # Find header file
  my $h_file = "";
  if (@$export[4] &amp; $FLAG_NONAME)
  {
    $h_file = "Exported by ordinal only. Use GetProcAddress() to obtain a pointer to the function.";
  }
  else
  {
    if ($comment-&gt;{COMMENT_NAME} ne "")
    {
      my $tmp = "grep -s -l $comment-&gt;{COMMENT_NAME} @opt_header_file_list 2&gt;/dev/null";
      $tmp = `$tmp`;
      my $exit_value  = $? &gt;&gt; 8;
      if ($exit_value == 0)
      {
        $tmp =~ s/\n.*//g;
        if ($tmp ne "")
        {
          $h_file = `basename $tmp`;
        }
      }
    }
    elsif ($comment-&gt;{ALT_NAME} ne "")
    {
      my $tmp = "grep -s -l $comment-&gt;{ALT_NAME} @opt_header_file_list"." 2&gt;/dev/null";
      $tmp = `$tmp`;
      my $exit_value  = $? &gt;&gt; 8;
      if ($exit_value == 0)
      {
        $tmp =~ s/\n.*//g;
        if ($tmp ne "")
        {
          $h_file = `basename $tmp`;
        }
      }
    }
    $h_file =~ s/^ *//;
    $h_file =~ s/\n//;
    if ($h_file eq "")
    {
      $h_file = "Not defined in a Wine header. The function is either undocumented, or missing from Wine."
    }
    else
    {
      $h_file = "Defined in \"".$h_file."\".";
    }
  }

  # Find source file
  my $c_file = $comment-&gt;{FILE};
  if ($opt_wine_root_dir ne "")
  {
    my $cfile = $pwd."/".$c_file;     # Current dir + file
    $cfile =~ s/(.+)(\/.*$)/$1/;      # Strip the filename
    $cfile = `cd $cfile &amp;&amp; pwd`;      # Strip any relative parts (e.g. "../../")
    $cfile =~ s/\n//;                 # Strip newline
    my $newfile = $c_file;
    $newfile =~ s/(.+)(\/.*$)/$2/;    # Strip all but the filename
    $cfile = $cfile."/".$newfile;     # Append filename to base path
    $cfile =~ s/$opt_wine_root_dir//; # Get rid of the root directory
    $cfile =~ s/\/\//\//g;            # Remove any double slashes
    $cfile =~ s/^\/+//;               # Strip initial directory slash
    $c_file = $cfile;
  }
  $c_file = "Implemented in \"".$c_file."\".";

  # Add the implementation details
  push (@{$comment-&gt;{TEXT}}, "IMPLEMENTATION","",$h_file,"",$c_file);

  if (@$export[4] &amp; $FLAG_I386)
  {
    push (@{$comment-&gt;{TEXT}}, "", "Available on x86 platforms only.");
  }
  if (@$export[4] &amp; $FLAG_REGISTER)
  {
    push (@{$comment-&gt;{TEXT}}, "", "This function passes one or more arguments in registers. ",
          "For more details, please read the source code.");
  }
  my $source_details = $source_files{$comment-&gt;{FILE}}[0];
  if ($source_details-&gt;{DEBUG_CHANNEL} ne "")
  {
    push (@{$comment-&gt;{TEXT}}, "", "Debug channel \"".$source_details-&gt;{DEBUG_CHANNEL}."\".");
  }

  # Write out the documentation for the API
  output_comment($comment)
}

# process our extra comment and output it if it is suitable.
sub process_extra_comment
{
  my $comment = shift(@_);

  my $spec_details = $spec_files{$comment-&gt;{DLL_NAME}}[0];

  if (!defined($spec_details))
  {
    if ($opt_verbose &gt; 2)
    {
      print "Warning: Extra comment '".$comment-&gt;{COMMENT_NAME}."' belongs to '".
            $comment-&gt;{DLL_NAME}."' (not passed with -w): not processing it.\n";
    }
    return;
  }

  # Check first to see if this is documentation for the DLL.
  if ($comment-&gt;{COMMENT_NAME} eq $comment-&gt;{DLL_NAME})
  {
    if ($opt_verbose &gt; 2)
    {
      print "Info: Found DLL documentation\n";
    }
    for (@{$comment-&gt;{TEXT}})
    {
      push (@{$spec_details-&gt;{DESCRIPTION}}, $_);
    }
    return;
  }

  # Add the comment to the DLL page as a link
  push (@{$spec_details-&gt;{EXTRA_COMMENTS}},$comment-&gt;{COMMENT_NAME});

  # If we have a prototype, process as a regular comment
  if (@{$comment-&gt;{PROTOTYPE}})
  {
    $comment-&gt;{ORDINAL} = "@";

    # Add an index for the comment name
    $spec_details-&gt;{EXPORTED_NAMES}{$comment-&gt;{COMMENT_NAME}} = $spec_details-&gt;{NUM_EXPORTS};

    # Add a fake exported entry
    $spec_details-&gt;{NUM_EXPORTS}++;
    my ($ordinal, $call_convention, $exported_name, $implementation_name, $documented) =
     ("@", "fake", $comment-&gt;{COMMENT_NAME}, $comment-&gt;{COMMENT_NAME}, 0);
    my @export = ($ordinal, $call_convention, $exported_name, $implementation_name, $documented);
    push (@{$spec_details-&gt;{EXPORTS}},[@export]);
    @{$comment-&gt;{TEXT}} = ("DESCRIPTION", @{$comment-&gt;{TEXT}});
    process_comment($comment);
    return;
  }

  if ($opt_verbose &gt; 0)
  {
    print "Processing ",$comment-&gt;{COMMENT_NAME},"\n";
  }

  if (@{$spec_details-&gt;{CURRENT_EXTRA}})
  {
    my $current_comment = ${@{$spec_details-&gt;{CURRENT_EXTRA}}}[0];

    if ($opt_verbose &gt; 0)
    {
      print "Processing old current: ",$current_comment-&gt;{COMMENT_NAME},"\n";
    }
    # Output the current comment
    process_comment_text($current_comment);
    output_open_api_file($current_comment-&gt;{COMMENT_NAME});
    output_api_header($current_comment);
    output_api_name($current_comment);
    output_api_comment($current_comment);
    output_api_footer($current_comment);
    output_close_api_file();
  }

  if ($opt_verbose &gt; 2)
  {
    print "Setting current to ",$comment-&gt;{COMMENT_NAME},"\n";
  }

  my $comment_copy =
  {
    FILE =&gt; $comment-&gt;{FILE},
    COMMENT_NAME =&gt; $comment-&gt;{COMMENT_NAME},
    ALT_NAME =&gt; $comment-&gt;{ALT_NAME},
    DLL_NAME =&gt; $comment-&gt;{DLL_NAME},
    ORDINAL =&gt; $comment-&gt;{ORDINAL},
    RETURNS =&gt; $comment-&gt;{RETURNS},
    PROTOTYPE =&gt; [],
    TEXT =&gt; [],
  };

  for (@{$comment-&gt;{TEXT}})
  {
    push (@{$comment_copy-&gt;{TEXT}}, $_);
  }
  # Set this comment to be the current extra comment
  @{$spec_details-&gt;{CURRENT_EXTRA}} = ($comment_copy);
}

# Write a standardised comment out in the appropriate format
sub output_comment
{
  my $comment = shift(@_);

  if ($opt_verbose &gt; 0)
  {
    print "Processing ",$comment-&gt;{COMMENT_NAME},"\n";
  }

  if ($opt_verbose &gt; 4)
  {
    print "--PROTO--\n";
    for (@{$comment-&gt;{PROTOTYPE}})
    {
      print "'".$_."'\n";
    }

    print "--COMMENT--\n";
    for (@{$comment-&gt;{TEXT} })
    {
      print $_."\n";
    }
  }

  output_open_api_file($comment-&gt;{COMMENT_NAME});
  output_api_header($comment);
  output_api_name($comment);
  output_api_synopsis($comment);
  output_api_comment($comment);
  output_api_footer($comment);
  output_close_api_file();
}

# Write out an index file for each .spec processed
sub process_index_files
{
  foreach my $spec_file (keys %spec_files)
  {
    my $spec_details = $spec_files{$spec_file}[0];
    if (defined ($spec_details-&gt;{DLL_NAME}))
    {
      if (@{$spec_details-&gt;{CURRENT_EXTRA}})
      {
        # We have an unwritten extra comment, write it
        my $current_comment = ${@{$spec_details-&gt;{CURRENT_EXTRA}}}[0];
        process_extra_comment($current_comment);
        @{$spec_details-&gt;{CURRENT_EXTRA}} = ();
       }
       output_spec($spec_details);
    }
  }
}

# Write a spec files documentation out in the appropriate format
sub output_spec
{
  my $spec_details = shift(@_);

  if ($opt_verbose &gt; 2)
  {
    print "Writing:",$spec_details-&gt;{DLL_NAME},"\n";
  }

  # Use the comment output functions for consistency
  my $comment =
  {
    FILE =&gt; $spec_details-&gt;{DLL_NAME},
    COMMENT_NAME =&gt; $spec_details-&gt;{DLL_NAME}.".dll",
    ALT_NAME =&gt; $spec_details-&gt;{DLL_NAME},
    DLL_NAME =&gt; "",
    ORDINAL =&gt; "",
    RETURNS =&gt; "",
    PROTOTYPE =&gt; [],
    TEXT =&gt; [],
  };
  my $total_implemented = $spec_details-&gt;{NUM_FORWARDS} + $spec_details-&gt;{NUM_VARS} +
     $spec_details-&gt;{NUM_FUNCS};
  my $percent_implemented = 0;
  if ($total_implemented)
  {
    $percent_implemented = $total_implemented /
     ($total_implemented + $spec_details-&gt;{NUM_STUBS}) * 100;
  }
  $percent_implemented = int($percent_implemented);
  my $percent_documented = 0;
  if ($spec_details-&gt;{NUM_DOCS})
  {
    # Treat forwards and data as documented funcs for statistics
    $percent_documented = $spec_details-&gt;{NUM_DOCS} / $spec_details-&gt;{NUM_FUNCS} * 100;
    $percent_documented = int($percent_documented);
  }

  # Make a list of the contributors to this DLL. Do this only for the source
  # files that make up the DLL, because some directories specify multiple dlls.
  my @contributors;

  for (@{$spec_details-&gt;{SOURCES}})
  {
    my $source_details = $source_files{$_}[0];
    for (@{$source_details-&gt;{CONTRIBUTORS}})
    {
      push (@contributors, $_);
    }
  }

  my %saw;
  @contributors = grep(!$saw{$_}++, @contributors); # remove dups, from perlfaq4 manpage
  @contributors = sort @contributors;

  # Remove duplicates and blanks
  for(my $i=0; $i&lt;@contributors; $i++)
  {
    if ($i &gt; 0 &amp;&amp; ($contributors[$i] =~ /$contributors[$i-1]/ || $contributors[$i-1] eq ""))
    {
      $contributors[$i-1] = $contributors[$i];
    }
  }
  undef %saw;
  @contributors = grep(!$saw{$_}++, @contributors);

  if ($opt_verbose &gt; 3)
  {
    print "Contributors:\n";
    for (@contributors)
    {
      print "'".$_."'\n";
    }
  }
  my $contribstring = join (", ", @contributors);

  # Create the initial comment text
  @{$comment-&gt;{TEXT}} = (
    "NAME",
    $comment-&gt;{COMMENT_NAME}
  );

  # Add the description, if we have one
  if (@{$spec_details-&gt;{DESCRIPTION}})
  {
    push (@{$comment-&gt;{TEXT}}, "DESCRIPTION");
    for (@{$spec_details-&gt;{DESCRIPTION}})
    {
      push (@{$comment-&gt;{TEXT}}, $_);
    }
  }

  # Add the statistics and contributors
  push (@{$comment-&gt;{TEXT}},
    "STATISTICS",
    "Forwards: ".$spec_details-&gt;{NUM_FORWARDS},
    "Variables: ".$spec_details-&gt;{NUM_VARS},
    "Stubs: ".$spec_details-&gt;{NUM_STUBS},
    "Functions: ".$spec_details-&gt;{NUM_FUNCS},
    "Exports-Total: ".$spec_details-&gt;{NUM_EXPORTS},
    "Implemented-Total: ".$total_implemented." (".$percent_implemented."%)",
    "Documented-Total: ".$spec_details-&gt;{NUM_DOCS}." (".$percent_documented."%)",
    "CONTRIBUTORS",
    "The following people hold copyrights on the source files comprising this dll:",
    "",
    $contribstring,
    "Note: This list may not be complete.",
    "For a complete listing, see the Files \"AUTHORS\" and \"Changelog\" in the Wine source tree.",
    "",
  );

  if ($opt_output_format eq "h")
  {
    # Add the exports to the comment text
    push (@{$comment-&gt;{TEXT}},"EXPORTS");
    my $exports = $spec_details-&gt;{EXPORTS};
    for (@$exports)
    {
      my $line = "";

      # @$_ =&gt; ordinal, call convention, exported name, implementation name, flags;
      if (@$_[1] eq "forward")
      {
        my $forward_dll = @$_[3];
        $forward_dll =~ s/\.(.*)//;
        $line = @$_[2]." (forward to ".$1."() in ".$forward_dll."())";
      }
      elsif (@$_[1] eq "extern")
      {
        $line = @$_[2]." (extern)";
      }
      elsif (@$_[1] eq "stub")
      {
        $line = @$_[2]." (stub)";
      }
      elsif (@$_[1] eq "fake")
      {
        # Don't add this function here, it gets listed with the extra documentation
        if (!(@$_[4] &amp; $FLAG_WPAIR))
        {
          # This function should be indexed
          push (@index_entries_list, @$_[3].",".@$_[3]);
        }
      }
      elsif (@$_[1] eq "equate" || @$_[1] eq "variable")
      {
        $line = @$_[2]." (data)";
      }
      else
      {
        # A function
        if (@$_[4] &amp; $FLAG_DOCUMENTED)
        {
          # Documented
          $line = @$_[2]." (implemented as ".@$_[3]."())";
          if (@$_[2] ne @$_[3])
          {
            $line = @$_[2]." (implemented as ".@$_[3]."())";
          }
          else
          {
            $line = @$_[2]."()";
          }
          if (!(@$_[4] &amp; $FLAG_WPAIR))
          {
            # This function should be indexed
            push (@index_entries_list, @$_[2].",".@$_[3]);
          }
        }
        else
        {
          $line = @$_[2]." (not documented)";
        }
      }
      if ($line ne "")
      {
        push (@{$comment-&gt;{TEXT}}, $line, "");
      }
    }

    # Add links to the extra documentation
    if (@{$spec_details-&gt;{EXTRA_COMMENTS}})
    {
      push (@{$comment-&gt;{TEXT}}, "SEE ALSO");
      my %htmp;
      @{$spec_details-&gt;{EXTRA_COMMENTS}} = grep(!$htmp{$_}++, @{$spec_details-&gt;{EXTRA_COMMENTS}});
      for (@{$spec_details-&gt;{EXTRA_COMMENTS}})
      {
        push (@{$comment-&gt;{TEXT}}, $_."()", "");
      }
    }
  }
  # The dll entry should also be indexed
  push (@index_entries_list, $spec_details-&gt;{DLL_NAME}.",".$spec_details-&gt;{DLL_NAME});

  # Write out the document
  output_open_api_file($spec_details-&gt;{DLL_NAME});
  output_api_header($comment);
  output_api_comment($comment);
  output_api_footer($comment);
  output_close_api_file();

  # Add this dll to the database of dll names
  my $output_file = $opt_output_directory."/dlls.db";

  # Append the dllname to the output db of names
  open(DLLDB,"&gt;&gt;$output_file") || die "Couldn't create $output_file\n";
  print DLLDB $spec_details-&gt;{DLL_NAME},"\n";
  close(DLLDB);

  if ($opt_output_format eq "s")
  {
    output_sgml_dll_file($spec_details);
    return;
  }
}

#
# OUTPUT FUNCTIONS
# ----------------
# Only these functions know anything about formatting for a specific
# output type. The functions above work only with plain text.
# This is to allow new types of output to be added easily.

# Open the api file
sub output_open_api_file
{
  my $output_name = shift(@_);
  $output_name = $opt_output_directory."/".$output_name;

  if ($opt_output_format eq "h")
  {
    $output_name = $output_name.".html";
  }
  elsif ($opt_output_format eq "s")
  {
    $output_name = $output_name.".sgml";
  }
  else
  {
    $output_name = $output_name.".".$opt_manual_section;
  }
  open(OUTPUT,"&gt;$output_name") || die "Couldn't create file '$output_name'\n";
}

# Close the api file
sub output_close_api_file
{
  close (OUTPUT);
}

# Output the api file header
sub output_api_header
{
  my $comment = shift(@_);

  if ($opt_output_format eq "h")
  {
      print OUTPUT "&lt;!-- Generated file - DO NOT EDIT! --&gt;\n";
      print OUTPUT "&lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\"&gt;\n";
      print OUTPUT "&lt;HTML&gt;\n&lt;HEAD&gt;\n";
      print OUTPUT "&lt;LINK REL=\"StyleSheet\" href=\"apidoc.css\" type=\"text/css\"&gt;\n";
      print OUTPUT "&lt;META NAME=\"GENERATOR\" CONTENT=\"tools/c2man.pl\"&gt;\n";
      print OUTPUT "&lt;META NAME=\"keywords\" CONTENT=\"Win32,Wine,API,$comment-&gt;{COMMENT_NAME}\"&gt;\n";
      print OUTPUT "&lt;TITLE&gt;Wine API: $comment-&gt;{COMMENT_NAME}&lt;/TITLE&gt;\n&lt;/HEAD&gt;\n&lt;BODY&gt;\n";
  }
  elsif ($opt_output_format eq "s")
  {
      print OUTPUT "&lt;!-- Generated file - DO NOT EDIT! --&gt;\n",
                   "&lt;sect1&gt;\n",
                   "&lt;title&gt;$comment-&gt;{COMMENT_NAME}&lt;/title&gt;\n";
  }
  else
  {
      print OUTPUT ".\\\" -*- nroff -*-\n.\\\" Generated file - DO NOT EDIT!\n".
                   ".TH ",$comment-&gt;{COMMENT_NAME}," ",$opt_manual_section," \"",$date,"\" \"".
                   "Wine API\" \"Wine API\"\n";
  }
}

sub output_api_footer
{
  if ($opt_output_format eq "h")
  {
      print OUTPUT "&lt;hr&gt;&lt;p&gt;&lt;i class=\"copy\"&gt;Copyright &amp;copy ".$year." The Wine Project.".
                   " All trademarks are the property of their respective owners.".
                   " Visit &lt;a HREF=http://www.winehq.org&gt;WineHQ&lt;/a&gt; for license details.".
                   " Generated $date.&lt;/i&gt;&lt;/p&gt;\n&lt;/body&gt;\n&lt;/html&gt;\n";
  }
  elsif ($opt_output_format eq "s")
  {
      print OUTPUT "&lt;/sect1&gt;\n";
      return;
  }
  else
  {
  }
}

sub output_api_section_start
{
  my $comment = shift(@_);
  my $section_name = shift(@_);

  if ($opt_output_format eq "h")
  {
    print OUTPUT "\n&lt;p&gt;&lt;h2 class=\"section\"&gt;",$section_name,"&lt;/h2&gt;&lt;/p&gt;\n";
  }
  elsif ($opt_output_format eq "s")
  {
    print OUTPUT "&lt;bridgehead&gt;",$section_name,"&lt;/bridgehead&gt;\n";
  }
  else
  {
    print OUTPUT "\n\.SH ",$section_name,"\n";
  }
}

sub output_api_section_end
{
  # Not currently required by any output formats
}

sub output_api_name
{
  my $comment = shift(@_);

  output_api_section_start($comment,"NAME");

  my $dll_ordinal = "";
  if ($comment-&gt;{ORDINAL} ne "")
  {
    $dll_ordinal = "(".$comment-&gt;{DLL_NAME}.".".$comment-&gt;{ORDINAL}.")";
  }
  if ($opt_output_format eq "h")
  {
    print OUTPUT "&lt;p&gt;&lt;b class=\"func_name\"&gt;",$comment-&gt;{COMMENT_NAME},
                 "&lt;/b&gt;&amp;nbsp;&amp;nbsp;&lt;i class=\"dll_ord\"&gt;",
                 ,$dll_ordinal,"&lt;/i&gt;&lt;/p&gt;\n";
  }
  elsif ($opt_output_format eq "s")
  {
    print OUTPUT "&lt;para&gt;\n  &lt;command&gt;",$comment-&gt;{COMMENT_NAME},"&lt;/command&gt;  &lt;emphasis&gt;",
                 $dll_ordinal,"&lt;/emphasis&gt;\n&lt;/para&gt;\n";
  }
  else
  {
    print OUTPUT "\\fB",$comment-&gt;{COMMENT_NAME},"\\fR ",$dll_ordinal;
  }

  output_api_section_end();
}

sub output_api_synopsis
{
  my $comment = shift(@_);
  my @fmt;

  output_api_section_start($comment,"SYNOPSIS");

  if ($opt_output_format eq "h")
  {
    print OUTPUT "&lt;p&gt;&lt;pre class=\"proto\"&gt;\n ", $comment-&gt;{RETURNS}," ",$comment-&gt;{COMMENT_NAME},"\n (\n";
    @fmt = ("", "\n", "&lt;tt class=\"param\"&gt;", "&lt;/tt&gt;");
  }
  elsif ($opt_output_format eq "s")
  {
    print OUTPUT "&lt;screen&gt;\n ",$comment-&gt;{RETURNS}," ",$comment-&gt;{COMMENT_NAME},"\n (\n";
    @fmt = ("", "\n", "&lt;emphasis&gt;", "&lt;/emphasis&gt;");
  }
  else
  {
    print OUTPUT $comment-&gt;{RETURNS}," ",$comment-&gt;{COMMENT_NAME},"\n (\n";
    @fmt = ("", "\n", "\\fI", "\\fR");
  }

  # Since our prototype is output in a pre-formatted block, line up the
  # parameters and parameter comments in the same column.

  # First caluculate where the columns should start
  my $biggest_length = 0;
  for(my $i=0; $i &lt; @{$comment-&gt;{PROTOTYPE}}; $i++)
  {
    my $line = ${@{$comment-&gt;{PROTOTYPE}}}[$i];
    if ($line =~ /(.+?)([A-Za-z_][A-Za-z_0-9]*)$/)
    {
      my $length = length $1;
      if ($length &gt; $biggest_length)
      {
        $biggest_length = $length;
      }
    }
  }

  # Now pad the string with blanks
  for(my $i=0; $i &lt; @{$comment-&gt;{PROTOTYPE}}; $i++)
  {
    my $line = ${@{$comment-&gt;{PROTOTYPE}}}[$i];
    if ($line =~ /(.+?)([A-Za-z_][A-Za-z_0-9]*)$/)
    {
      my $pad_len = $biggest_length - length $1;
      my $padding = " " x ($pad_len);
      ${@{$comment-&gt;{PROTOTYPE}}}[$i] = $1.$padding.$2;
    }
  }

  for(my $i=0; $i &lt; @{$comment-&gt;{PROTOTYPE}}; $i++)
  {
    # Format the parameter name
    my $line = ${@{$comment-&gt;{PROTOTYPE}}}[$i];
    my $comma = ($i == @{$comment-&gt;{PROTOTYPE}}-1) ? "" : ",";
    $line =~ s/(.+?)([A-Za-z_][A-Za-z_0-9]*)$/  $fmt[0]$1$fmt[2]$2$fmt[3]$comma$fmt[1]/;
    print OUTPUT $line;
  }

  if ($opt_output_format eq "h")
  {
    print OUTPUT " )\n\n&lt;/pre&gt;&lt;/p&gt;\n";
  }
  elsif ($opt_output_format eq "s")
  {
    print OUTPUT " )\n&lt;/screen&gt;\n";
  }
  else
  {
    print OUTPUT " )\n";
  }

  output_api_section_end();
}

sub output_api_comment
{
  my $comment = shift(@_);
  my $open_paragraph = 0;
  my $open_raw = 0;
  my $param_docs = 0;
  my @fmt;

  if ($opt_output_format eq "h")
  {
    @fmt = ("&lt;p&gt;", "&lt;/p&gt;\n", "&lt;tt class=\"const\"&gt;", "&lt;/tt&gt;", "&lt;b class=\"emp\"&gt;", "&lt;/b&gt;",
            "&lt;tt class=\"coderef\"&gt;", "&lt;/tt&gt;", "&lt;tt class=\"param\"&gt;", "&lt;/tt&gt;",
            "&lt;i class=\"in_out\"&gt;", "&lt;/i&gt;", "&lt;pre class=\"raw\"&gt;\n", "&lt;/pre&gt;\n",
            "&lt;table class=\"tab\"&gt;&lt;colgroup&gt;&lt;col&gt;&lt;col&gt;&lt;col&gt;&lt;/colgroup&gt;&lt;tbody&gt;\n",
            "&lt;/tbody&gt;&lt;/table&gt;\n","&lt;tr&gt;&lt;td&gt;","&lt;/td&gt;&lt;/tr&gt;\n","&lt;/td&gt;","&lt;/td&gt;&lt;td&gt;");
  }
  elsif ($opt_output_format eq "s")
  {
    @fmt = ("&lt;para&gt;\n","\n&lt;/para&gt;\n","&lt;constant&gt;","&lt;/constant&gt;","&lt;emphasis&gt;","&lt;/emphasis&gt;",
            "&lt;command&gt;","&lt;/command&gt;","&lt;constant&gt;","&lt;/constant&gt;","&lt;emphasis&gt;","&lt;/emphasis&gt;",
            "&lt;screen&gt;\n","&lt;/screen&gt;\n",
            "&lt;informaltable frame=\"none\"&gt;\n&lt;tgroup cols=\"3\"&gt;\n&lt;tbody&gt;\n",
            "&lt;/tbody&gt;\n&lt;/tgroup&gt;\n&lt;/informaltable&gt;\n","&lt;row&gt;&lt;entry&gt;","&lt;/entry&gt;&lt;/row&gt;\n",
            "&lt;/entry&gt;","&lt;/entry&gt;&lt;entry&gt;");
  }
  else
  {
    @fmt = ("\.PP\n", "\n", "\\fB", "\\fR", "\\fB", "\\fR", "\\fB", "\\fR", "\\fI", "\\fR",
            "\\fB", "\\fR ", "", "", "", "","","\n.PP\n","","");
  }

  # Extract the parameter names
  my @parameter_names;
  for (@{$comment-&gt;{PROTOTYPE}})
  {
    if ( /(.+?)([A-Za-z_][A-Za-z_0-9]*)$/ )
    {
      push (@parameter_names, $2);
    }
  }

  for (@{$comment-&gt;{TEXT}})
  {
    if ($opt_output_format eq "h" || $opt_output_format eq "s")
    {
      # Map special characters
      s/\&amp;/\&amp;amp;/g;
      s/\&lt;/\&amp;lt;/g;
      s/\&gt;/\&amp;gt;/g;
      s/\([Cc]\)/\&amp;copy;/g;
      s/\(tm\)/&amp;#174;/;
    }

    if ( s/^\|// )
    {
      # Raw output
      if ($open_raw == 0)
      {
        if ($open_paragraph == 1)
        {
          # Close the open paragraph
          print OUTPUT $fmt[1];
          $open_paragraph = 0;
        }
        # Start raw output
        print OUTPUT $fmt[12];
        $open_raw = 1;
      }
      if ($opt_output_format eq "")
      {
        print OUTPUT ".br\n"; # Prevent 'man' running these lines together
      }
      print OUTPUT $_,"\n";
    }
    else
    {
      if ($opt_output_format eq "h")
      {
        # Link to the file in WineHQ cvs
        s/^(Implemented in \")(.+?)(\"\.)/$1$2$3 http:\/\/source.winehq.org\/source\/$2/g;
      }
      # Highlight strings
      s/(\".+?\")/$fmt[2]$1$fmt[3]/g;
      # Highlight literal chars
      s/(\'.\')/$fmt[2]$1$fmt[3]/g;
      s/(\'.{2}\')/$fmt[2]$1$fmt[3]/g;
      # Highlight numeric constants
      s/( |\-|\+|\.|\()([0-9\-\.]+)( |\-|$|\.|\,|\*|\?|\))/$1$fmt[2]$2$fmt[3]$3/g;

      # Leading cases ("xxxx:","-") start new paragraphs &amp; are emphasised
      # FIXME: Using bullet points for leading '-' would look nicer.
      if ($open_paragraph == 1)
      {
        s/^(\-)/$fmt[1]$fmt[0]$fmt[4]$1$fmt[5]/;
        s/^([[A-Za-z\-]+\:)/$fmt[1]$fmt[0]$fmt[4]$1$fmt[5]/;
      }
      else
      {
        s/^(\-)/$fmt[4]$1$fmt[5]/;
        s/^([[A-Za-z\-]+\:)/$fmt[4]$1$fmt[5]/;
      }

      if ($opt_output_format eq "h")
      {
        # Html uses links for API calls
        s/([A-Za-z_]+[A-Za-z_0-9]+)(\(\))/&lt;a href\=\"$1\.html\"&gt;$1&lt;\/a&gt;/g;
        # Index references
        s/\{\{(.*?)\}\}\{\{(.*?)\}\}/&lt;a href\=\"$2\.html\"&gt;$1&lt;\/a&gt;/g;
        s/ ([A-Z_])(\(\))/&lt;a href\=\"$1\.html\"&gt;$1&lt;\/a&gt;/g;
        # And references to COM objects (hey, they'll get documented one day)
        s/ (I[A-Z]{1}[A-Za-z0-9_]+) (Object|object|Interface|interface)/ &lt;a href\=\"$1\.html\"&gt;$1&lt;\/a&gt; $2/g;
        # Convert any web addresses to real links
        s/(http\:\/\/)(.+?)($| )/&lt;a href\=\"$1$2\"&gt;$2&lt;\/a&gt;$3/g;
      }
      else
      {
        if ($opt_output_format eq "")
        {
          # Give the man section for API calls
          s/ ([A-Za-z_]+[A-Za-z_0-9]+)\(\)/ $fmt[6]$1\($opt_manual_section\)$fmt[7]/g;
        }
        else
        {
          # Highlight API calls
          s/ ([A-Za-z_]+[A-Za-z_0-9]+\(\))/ $fmt[6]$1$fmt[7]/g;
        }

        # And references to COM objects
        s/ (I[A-Z]{1}[A-Za-z0-9_]+) (Object|object|Interface|interface)/ $fmt[6]$1$fmt[7] $2/g;
      }

      if ($open_raw == 1)
      {
        # Finish the raw output
        print OUTPUT $fmt[13];
        $open_raw = 0;
      }

      if ( /^[A-Z]+$/ || /^SEE ALSO$/ )
      {
        # Start of a new section
        if ($open_paragraph == 1)
        {
          if ($param_docs == 1)
          {
            print OUTPUT $fmt[17],$fmt[15];
          }
          else
          {
            print OUTPUT $fmt[1];
          }
          $open_paragraph = 0;
        }
        output_api_section_start($comment,$_);
        if ( /^PARAMS$/ )
        {
          print OUTPUT $fmt[14];
          $param_docs = 1;
        }
        else
        {
          #print OUTPUT $fmt[15];
          $param_docs = 0;
        }
      }
      elsif ( /^$/ )
      {
        # Empty line, indicating a new paragraph
        if ($open_paragraph == 1)
        {
          if ($param_docs == 0)
          {
            print OUTPUT $fmt[1];
            $open_paragraph = 0;
          }
        }
      }
      else
      {
        if ($param_docs == 1)
        {
          if ($open_paragraph == 1)
          {
            # For parameter docs, put each parameter into a new paragraph/table row
            print OUTPUT $fmt[17];
            $open_paragraph = 0;
          }
          s/(\[.+\])( *)/$fmt[19]$fmt[10]$1$fmt[11]$fmt[19] /; # Format In/Out
        }
        else
        {
          # Within paragraph lines, prevent lines running together
          $_ = $_." ";
        }

        # Format parameter names where they appear in the comment
        for my $parameter_name (@parameter_names)
        {
          s/(^|[ \.\,\(\-\*])($parameter_name)($|[ \.\)\,\-\=\/])/$1$fmt[8]$2$fmt[9]$3/g;
        }
        # Structure dereferences include the dereferenced member
        s/(\-\&gt;[A-Za-z_]+)/$fmt[8]$1$fmt[9]/g;
        s/(\-\&amp;gt\;[A-Za-z_]+)/$fmt[8]$1$fmt[9]/g;

        if ($open_paragraph == 0)
        {
          if ($param_docs == 1)
          {
            print OUTPUT $fmt[16];
          }
          else
          {
            print OUTPUT $fmt[0];
          }
          $open_paragraph = 1;
        }
        # Anything in all uppercase on its own gets emphasised
        s/(^|[ \.\,\(\[\|\=])([A-Z]+?[A-Z0-9_]+)($|[ \.\,\*\?\|\)\=\'])/$1$fmt[6]$2$fmt[7]$3/g;

        print OUTPUT $_;
      }
    }
  }
  if ($open_raw == 1)
  {
    print OUTPUT $fmt[13];
  }
  if ($open_paragraph == 1)
  {
    print OUTPUT $fmt[1];
  }
}

# Create the master index file
sub output_master_index_files
{
  if ($opt_output_format eq "")
  {
    return; # No master index for man pages
  }

  if ($opt_output_format eq "h")
  {
    # Append the index entries to the output db of index entries
    my $output_file = $opt_output_directory."/index.db";
    open(INDEXDB,"&gt;&gt;$output_file") || die "Couldn't create $output_file\n";
    for (@index_entries_list)
    {
      $_ =~ s/A\,/\,/;
      print INDEXDB $_."\n";
    }
    close(INDEXDB);
  }

  # Use the comment output functions for consistency
  my $comment =
  {
    FILE =&gt; "",
    COMMENT_NAME =&gt; "The Wine Api Guide",
    ALT_NAME =&gt; "The Wine Api Guide",
    DLL_NAME =&gt; "",
    ORDINAL =&gt; "",
    RETURNS =&gt; "",
    PROTOTYPE =&gt; [],
    TEXT =&gt; [],
  };

  if ($opt_output_format eq "s")
  {
    $comment-&gt;{COMMENT_NAME} = "Introduction";
    $comment-&gt;{ALT_NAME} = "Introduction",
  }
  elsif ($opt_output_format eq "h")
  {
    @{$comment-&gt;{TEXT}} = (
      "NAME",
       $comment-&gt;{COMMENT_NAME},
       "INTRODUCTION",
    );
  }

  # Create the initial comment text
  push (@{$comment-&gt;{TEXT}},
    "This document describes the Api calls made available",
    "by Wine. They are grouped by the dll that exports them.",
    "",
    "Please do not edit this document, since it is generated automatically",
    "from the Wine source code tree. Details on updating this documentation",
    "are given in the \"Wine Developers Guide\".",
    "CONTRIBUTORS",
    "Api documentation is generally written by the person who ",
    "implements a given Api call. Authors of each dll are listed in the overview ",
    "section for that dll. Additional contributors who have updated source files ",
    "but have not entered their names in a copyright statement are noted by an ",
    "entry in the file \"Changelog\" from the Wine source code distribution.",
      ""
  );

  # Read in all dlls from the database of dll names
  my $input_file = $opt_output_directory."/dlls.db";
  my @dlls = `cat $input_file|sort|uniq`;

  if ($opt_output_format eq "h")
  {
    # HTML gets a list of all the dlls and an index. For docbook the index creates this for us
    push (@{$comment-&gt;{TEXT}},
      "INDEX",
      "For an alphabetical listing of the functions available, please click the ",
      "first letter of the functions name below:","",
      "[ _(), A(), B(), C(), D(), E(), F(), G(), H(), ".
      "I(), J(), K(), L(), M(), N(), O(), P(), Q(), ".
      "R(), S(), T(), U(), V(), W(), X(), Y(), Z() ]", "",
      "DLLS",
      "Each dll provided by Wine is documented individually. The following dlls are provided :",
      ""
    );
    # Add the dlls to the comment
    for (@dlls)
    {
      $_ =~ s/(\..*)?\n/\(\)/;
      push (@{$comment-&gt;{TEXT}}, $_, "");
    }
    output_open_api_file("index");
  }
  elsif ($opt_output_format eq "s")
  {
    # Just write this as the initial blurb, with a chapter heading
    output_open_api_file("blurb");
    print OUTPUT "&lt;chapter id =\"blurb\"&gt;\n&lt;title&gt;Introduction to The Wine Api Guide&lt;/title&gt;\n"
  }

  # Write out the document
  output_api_header($comment);
  output_api_comment($comment);
  output_api_footer($comment);
  if ($opt_output_format eq "s")
  {
    print OUTPUT "&lt;/chapter&gt;\n" # finish the chapter
  }
  output_close_api_file();

  if ($opt_output_format eq "s")
  {
    output_sgml_master_file(\@dlls);
    return;
  }
  if ($opt_output_format eq "h")
  {
    output_html_index_files();
    output_html_stylesheet();
    return;
  }
}

# Write the master wine-api.sgml, linking it to each dll.
sub output_sgml_master_file
{
  my $dlls = shift(@_);

  output_open_api_file("wine-api");
  print OUTPUT "&lt;!-- Generated file - DO NOT EDIT! --&gt;\n";
  print OUTPUT "&lt;!doctype book PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\" [\n\n";
  print OUTPUT "&lt;!entity blurb SYSTEM \"blurb.sgml\"&gt;\n";

  # List the entities
  for (@$dlls)
  {
    $_ =~ s/(\..*)?\n//;
    print OUTPUT "&lt;!entity ",$_," SYSTEM \"",$_,".sgml\"&gt;\n"
  }

  print OUTPUT "]&gt;\n\n&lt;book id=\"index\"&gt;\n&lt;bookinfo&gt;&lt;title&gt;The Wine Api Guide&lt;/title&gt;&lt;/bookinfo&gt;\n\n";
  print OUTPUT "  &amp;blurb;\n";

  for (@$dlls)
  {
    print OUTPUT "  &amp;",$_,";\n"
  }
  print OUTPUT "\n\n&lt;/book&gt;\n";

  output_close_api_file();
}

# Produce the sgml for the dll chapter from the generated files
sub output_sgml_dll_file
{
  my $spec_details = shift(@_);

  # Make a list of all the documentation files to include
  my $exports = $spec_details-&gt;{EXPORTS};
  my @source_files = ();
  for (@$exports)
  {
    # @$_ =&gt; ordinal, call convention, exported name, implementation name, documented;
    if (@$_[1] ne "forward" &amp;&amp; @$_[1] ne "extern" &amp;&amp; @$_[1] ne "stub" &amp;&amp; @$_[1] ne "equate" &amp;&amp;
        @$_[1] ne "variable" &amp;&amp; @$_[1] ne "fake" &amp;&amp; @$_[4] &amp; 1)
    {
      # A documented function
      push (@source_files,@$_[3]);
    }
  }

  push (@source_files,@{$spec_details-&gt;{EXTRA_COMMENTS}});

  @source_files = sort @source_files;

  # create a new chapter for this dll
  my $tmp_name = $opt_output_directory."/".$spec_details-&gt;{DLL_NAME}.".tmp";
  open(OUTPUT,"&gt;$tmp_name") || die "Couldn't create $tmp_name\n";
  print OUTPUT "&lt;chapter&gt;\n&lt;title&gt;$spec_details-&gt;{DLL_NAME}&lt;/title&gt;\n";
  output_close_api_file();

  # Add the sorted documentation, cleaning up as we go
  `cat $opt_output_directory/$spec_details-&gt;{DLL_NAME}.sgml &gt;&gt;$tmp_name`;
  for (@source_files)
  {
    `cat $opt_output_directory/$_.sgml &gt;&gt;$tmp_name`;
    `rm -f $opt_output_directory/$_.sgml`;
  }

  # close the chapter, and overwite the dll source
  open(OUTPUT,"&gt;&gt;$tmp_name") || die "Couldn't create $tmp_name\n";
  print OUTPUT "&lt;/chapter&gt;\n";
  close OUTPUT;
  `mv $tmp_name $opt_output_directory/$spec_details-&gt;{DLL_NAME}.sgml`;
}

# Write the html index files containing the function names
sub output_html_index_files
{
  if ($opt_output_format ne "h")
  {
    return;
  }

  my @letters = ('_', 'A' .. 'Z');

  # Read in all functions
  my $input_file = $opt_output_directory."/index.db";
  my @funcs = `cat $input_file|sort|uniq`;

  for (@letters)
  {
    my $letter = $_;
    my $comment =
    {
      FILE =&gt; "",
      COMMENT_NAME =&gt; "",
      ALT_NAME =&gt; "",
      DLL_NAME =&gt; "",
      ORDINAL =&gt; "",
      RETURNS =&gt; "",
      PROTOTYPE =&gt; [],
      TEXT =&gt; [],
    };

    $comment-&gt;{COMMENT_NAME} = $letter." Functions";
    $comment-&gt;{ALT_NAME} = $letter." Functions";

    push (@{$comment-&gt;{TEXT}},
      "NAME",
      $comment-&gt;{COMMENT_NAME},
      "FUNCTIONS"
    );

    # Add the functions to the comment
    for (@funcs)
    {
      my $first_char = substr ($_, 0, 1);
      $first_char = uc $first_char;

      if ($first_char eq $letter)
      {
        my $name = $_;
        my $file;
        $name =~ s/(^.*?)\,(.*?)\n/$1/;
        $file = $2;
        push (@{$comment-&gt;{TEXT}}, "{{".$name."}}{{".$file."}}","");
      }
    }

    # Write out the document
    output_open_api_file($letter);
    output_api_header($comment);
    output_api_comment($comment);
    output_api_footer($comment);
    output_close_api_file();
  }
}

# Output the stylesheet for HTML output
sub output_html_stylesheet
{
  if ($opt_output_format ne "h")
  {
    return;
  }

  my $css;
  ($css = &lt;&lt;HERE_TARGET) =~ s/^\s+//gm;
/*
 * Default styles for Wine HTML Documentation.
 *
 * This style sheet should be altered to suit your needs/taste.
 */
BODY { /* Page body */
background-color: white;
color: black;
font-family: Tahoma,sans-serif;
font-style: normal;
font-size: 10pt;
}
a:link { color: #4444ff; } /* Links */
a:visited { color: #333377 }
a:active { color: #0000dd }
H2.section { /* Section Headers */
font-family: sans-serif;
color: #777777;
background-color: #F0F0FE;
margin-left: 0.2in;
margin-right: 1.0in;
}
b.func_name { /* Function Name */
font-size: 10pt;
font-style: bold;
}
i.dll_ord { /* Italicised DLL+ordinal */
color: #888888;
font-family: sans-serif;
font-size: 8pt;
}
p { /* Paragraphs */
margin-left: 0.5in;
margin-right: 0.5in;
}
table { /* tables */
margin-left: 0.5in;
margin-right: 0.5in;
}
pre.proto /* API Function prototype */
{
border-style: solid;
border-width: 1px;
border-color: #777777;
background-color: #F0F0BB;
color: black;
font-size: 10pt;
vertical-align: top;
margin-left: 0.5in;
margin-right: 1.0in;
}
pre.raw { /* Raw text output */
margin-left: 0.6in;
margin-right: 1.1in;
background-color: #8080DC;
}
tt.param { /* Parameter name */
font-style: italic;
color: blue;
}
tt.const { /* Constant */
color: red;
}
i.in_out { /* In/Out */
font-size: 8pt;
color: grey;
}
tt.coderef { /* Code in description text */
color: darkgreen;
}
b.emp /* Emphasis */ {
font-style: bold;
color: darkblue;
}
i.footer { /* Footer */
font-family: sans-serif;
font-size: 6pt;
color: darkgrey;
}
HERE_TARGET

  my $output_file = "$opt_output_directory/apidoc.css";
  open(CSS,"&gt;$output_file") || die "Couldn't create the file $output_file\n";
  print CSS $css;
  close(CSS);
}
</pre></body></html>