#!/usr/bin/perl # # (c) Copyright 2000-2002 convergence integrated media GmbH. # (c) Copyright 2002 convergence GmbH. # # All rights reserved. # # Written by Denis Oliver Kropp , # Andreas Hundt and # Sven Neumann . # # 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 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. # ################################################################ # # # Documentation generator (early stage of implementation) # # # # - Reads header from stdin # # - Writes HTML to several files # # # ################################################################ html_create( INDEX, "index.html", "DirectFB Interfaces" ); html_create( TYPES, "types.html", "DirectFB Types" ); print INDEX "

\n", "

\n"; while (<>) { chomp; if ( /^\s*\/\*\s*$/ ) { $comment = "

\n"; while (<>) { chomp; last if ( /^\s*\*\/\s*$/ ); if (/^\s*\*\s*(.*)$/) { if ($1 eq "") { $comment .= "

\n"; } else { $comment .= " $1\n"; } } } $comment .= "

\n"; } elsif ( /^\s*DECLARE_INTERFACE\s*\(\s*(\w+)\s\)\s*$/ ) { $interface_abstracts{$1} = $comment; print INDEX " \n"; } elsif ( /^\s*DEFINE_INTERFACE\s*\(\s*(\w+),\s*$/ ) { parse_interface( $1 ); } elsif ( /^\s*typedef\s+enum\s*\{?\s*$/ ) { parse_enum(); } elsif ( /^\s*typedef\s+(struct|union)\s*\{?\s*$/ ) { parse_struct(); } else { $comment = ""; } } print INDEX "
\n", " $1\n", " \n", " $comment\n", "
\n", "

\n"; html_close( INDEX ); html_close( TYPES ); # # Reads stdin until the end of the interface is reached. # Writes formatted HTML to stdout. # Parameter is the interface name. # sub parse_interface (NAME) { my $interface = shift(@_); $headline = ""; $detailed = ""; $section = ""; html_create( INTERFACE, "$interface.html", "" . "DirectFB Interfaces" . "", $interface ); # print INTERFACE "

\n", # " $interface_abstracts{$interface}\n", # "

"; $comment =~ s/\/\

/g; print INTERFACE "$comment"; print INTERFACE "

\n", "

\n"; print INTERFACE " \n"; print INTERFACE " \n"; print INTERFACE " \n"; print INTERFACE " \n"; while (<>) { chomp; last if /^\s*\)\s*$/; if ( /^\s*\/\*\*\s*(.+)\s*\*\*\/\s*$/ ) { $section = $1; } elsif ( /^\s*DFBResult\s*\(\s*\*\s*(\w+)\s*\)\s*\(?\s*$/ ) { print INTERFACE " \n"; html_create( FUNCTION, "${interface}_$1.html", "" . "$interface" . "", $1 ); print FUNCTION "

$headline

\n", "

Methods of $interface
\n", " $section\n", " \n", " ", "$1\n", " \n", " $headline\n", "
\n", " \n"; while (<>) { chomp; last if /^\s*\)\;\s*$/; if ( /^\s*([\w\ ]+)\s+(\**\w+)\s*,?\s*$/ ) { $type = $1; $name = $2; $type =~ s/\ *$//; if ($types{$type}) { $type = "$type"; } elsif ($interface_abstracts{$type}) { $type = "$type"; } print FUNCTION " \n"; } } print FUNCTION " \n", "
$1 (
 \n", " $type\n", " \n", " $name\n", "
);
\n", "

\n"; print FUNCTION "

$detailed

\n"; $headline = ""; $detailed = ""; $section = ""; html_close( FUNCTION ); } elsif ( /^\s*\/\*\s*$/ ) { $headline = ""; $detailed = ""; $headline_mode = 1; while (<>) { chomp; last if /^\s*\*\/\s*$/; if ($headline_mode == 1) { if (/^\s*\*?\s*$/) { $headline_mode = 0; } elsif (/^\s*\*?\s*(.+)$/) { $headline .= " $1"; } } else { if (/^\s*\*?\s*$/) { $detailed .= "

"; } elsif (/^\s*\*?\s*(.+)$/) { $detailed .= " $1"; } } } } } print INTERFACE " \n"; print INTERFACE "

\n", "

\n"; html_close( INTERFACE ); } # # Reads stdin until the end of the enum is reached. # Writes formatted HTML to stdout. # sub parse_enum { %entries = (); @list = (); while (<>) { chomp; $entry = ""; # complete one line entry with assignment if ( /^\s*(\w+)\s*=\s*([\w\d]+)\s*,?\s*\/\*\s*(.+)\*\/\s*$/ ) { $entry = $1; $entries{ $entry } = $3; } # with comment opening elsif ( /^\s*(\w+)\s*=\s*([\w\d]+)\s*,?\s*\/\*\s*(.+)\s*$/ ) { $entry = $1; $entries{ $entry } = $3; while (<>) { chomp; if ( /^\s*(.+)\*\/\s*$/ ) { $entries{ $entry } .= " $1"; last; } elsif ( /^\s*(.+)\s*$/ ) { $entries{ $entry } .= " $1"; } } } # complete one line entry elsif ( /^\s*(\w+)\s*,?\s*\/\*\s*(.+)\*\/\s*$/ ) { $entry = $1; $entries{ $entry } = $2; } # with comment opening elsif ( /^\s*(\w+)\s*,?\s*\/\*\s*(.+)\s*$/ ) { $entry = $1; $entries{ $entry } = $2; while (<>) { chomp; if ( /^\s*(.+)\*\/\s*$/ ) { $entries{ $entry } .= " $1"; last; } elsif ( /^\s*(.+)\s*$/ ) { $entries{ $entry } .= " $1"; } } } elsif ( /^\s*\}\s*(\w+)\s*\;\s*$/ ) { $enum = $1; $types{$enum} = 1; last; } if ($entry ne "") { push (@list, $entry); } } if (scalar @list > 0) { print TYPES "

", "", "$enum\n"; print TYPES "$comment"; foreach $key (@list) { print TYPES "

", " $key
", " $entries{$key}", "

\n"; } } } # # Reads stdin until the end of the enum is reached. # Writes formatted HTML to stdout. # sub parse_struct { @entries = (); %entries_params = (); %entries_types = (); while (<>) { chomp; # without comment if ( /^\s*([\w\ ]+)\s+(\**[\w\d\+\[\]]+;)\s*$/ ) { $type = $1; $entry = $2; $type =~ s/\ *$//; if ($types{$type}) { $entries_types{$entry} = "
$type"; } elsif ($interface_abstracts{$type}) { $entries_types{$entry} = "$type"; } else { $entries_types{$entry} = "$type"; } push (@entries, $entry); $entries_params{ $entry } = ""; } # complete one line entry elsif ( /^\s*([\w\ ]+)\s+(\**[\w\d\+\[\]]+;)\s*\/\*\s*(.+)\*\/\s*$/ ) { $type = $1; $entry = $2; $text = $3; $type =~ s/\ *$//; if ($types{$type}) { $entries_types{$entry} = "$type"; } elsif ($interface_abstracts{$type}) { $entries_types{$entry} = "$type"; } else { $entries_types{$entry} = "$type"; } push (@entries, $entry); $entries_params{ $entry } = $text; } # with comment opening elsif ( /^\s*([\w\ ]+)\s+(\**[\w\d\+\[\]]+;)\s*\/\*\s*(.+)\s*$/ ) { $type = $1; $entry = $2; $text = $3; $type =~ s/\ *$//; if ($types{$type}) { $entries_types{$entry} = "$type"; } elsif ($interface_abstracts{$type}) { $entries_types{$entry} = "$type"; } else { $entries_types{$entry} = "$type"; } push (@entries, $entry); $entries_params{ $entry } = $text; while (<>) { chomp; if ( /^\s*(.+)\*\/\s*$/ ) { $entries_params{ $entry } .= " $1"; last; } elsif ( /^\s*(.+)\s*$/ ) { $entries_params{ $entry } .= " $1"; } } } elsif ( /^\s*\}\s*(\w+)\s*\;\s*$/ ) { $struct = $1; $types{$struct} = 1; last; } } if (scalar @entries > 0) { print TYPES "

", "", "$struct\n"; print TYPES "

\n", " \n"; foreach $key (@entries) { print TYPES " \n"; } print TYPES "
 \n", " $entries_types{$key}\n", " \n", " $key\n", " \n", " $entries_params{$key}\n", "
\n", "

\n"; print TYPES "$comment"; } } sub html_create (FILEHANDLE, FILENAME, TITLE, SUBTITLE) { my $FILE = shift(@_); my $filename = shift(@_); my $title = shift(@_); my $subtitle = shift(@_); open( $FILE, ">$filename" ) or die ("*** Can not open '$filename' for writing:\n*** $!"); print $FILE "\n", "\n", "\n", " DirectFB Reference Manual\n", "\n", "\n", "\n", "\n", " \n", " \n", "
\n", " \n", " \n", "   ", " DirectFB Reference Manual\n", "
\n"; if ($subtitle) { print $FILE " \n", " \n", "
\n", " $title \n", " \n", "  $subtitle\n", "
\n"; } else { print $FILE " $title\n"; } print $FILE "
\n", "\n"; } sub html_close (FILEHANDLE) { my $FILE = shift(@_); print $FILE "\n", "\n", " \n", "
\n", "   (C) Copyright by convergence GmbH\n", " \n", " \n", " \n", " \n", "
\n", "\n", "\n", "\n"; close( $FILE ); }