<td class="content">
<?php

// $Date: 2004/01/06 09:23:12 $
// $Revision: 1.18 $
// $Author: jcrocholl $

function params() {
    global
$params;
    
$result = '';
    if (
$params) {
        
$result .= "<table class=\"params\">\n";
        
$result .= "<tr>" .
            
"<th>Param&nbsp;</th>" .
            
"<th style=\"text-align: right\">Type&nbsp;</th>" .
            
"<th>Description</th>" .
            
"</tr>\n";
        
$result .= $params;
        
$result .= "</table>\n";
    }
    
$params = '';
    return
$result;
}

function
clear() {
    global
$package, $type, $exception, $function, $procedure, $params, $text;
    
$package = '';
    
$type = '';
    
$exception = '';
    
$function = '';
    
$procedure = '';
    
$params = '';
    
$text = '';
}

function
param($name, $direction, $type, $comment) {
    global
$params;
    
$direction = preg_replace('/\s+/', '&nbsp;', $direction);
    if (
$direction == 'return') {
        
$params .= '<tr>' .
            
'<td colspan="2"><table class="param"><tr>'.
            
"<td class=\"param_name\">" .
            
"<span class=\"keyword\">$direction&nbsp;</td>" .
            
"<td class=\"param_type\">" .
            
"<span class=\"type\">$type</span>&nbsp;</td>" .
            
'</tr></table></td>'.
            
"<td class=\"comment param_comment\">$comment</td>" .
            
"</tr>\n";
    } else {
        
$params .= '<tr>' .
            
'<td colspan="2"><table class="param"><tr>'.
            
"<td class=\"param_name\">" .
            
"<span class=\"keyword\">$direction</span>&nbsp;" .
            
"$name&nbsp;</td>" .
            
"<td class=\"type param_type\">$type</span>&nbsp;</td>" .
            
'</tr></table></td>'.
            
"<td class=\"comment param_comment\">$comment</td>" .
            
"</tr>\n";
    }
}

function
quick_anchor() {
    global
$quick_link;
    
$quick_link++;
    return
"<a name=\"$quick_link\"></a>\n";
}

function
quick_link($where) {
    global
$quick_link;
    return
"<a href=\"#$quick_link\">$where</a>";
}

function
output() {
    global
$package, $type, $exception, $function, $procedure, $params, $text;
    global
$quick_methods, $quick_types, $quick_exceptions, $quick_packages;
    if (
$function) {
        
$result .= quick_anchor();
        
$result .= frame_head('orange', icon('method'), "function $function");
        if (
$text) frame_row_single($rows, $text);
        
frame_row_single($rows, params());
        
$result .= frame_tail($rows);
        
frame_row($quick_methods, icon('method'), quick_link($function));
    } elseif (
$procedure) {
        
$result .= quick_anchor();
        
$result .= frame_head('orange', icon('method'), "procedure $procedure");
        if (
$text) frame_row_single($rows, $text);
        
frame_row_single($rows, params());
        
$result .= frame_tail($rows);
        
frame_row($quick_methods, icon('method'), quick_link($procedure));
    } elseif (
$type) {
        
$result .= quick_anchor();
        
$result .= frame_head('blue', icon('type'), "type $type");
        if (
$text) frame_row_single($rows, $text);
        
$result .= frame_tail($rows);
        
frame_row($quick_types, icon('type'), quick_link($type));
    } elseif (
$exception) {
        
$result .= quick_anchor();
        
$result .= frame_head('red', icon('exception'), "exception $exception");
        if (
$text) frame_row_single($rows, $text);
        
$result .= frame_tail($rows);
        
frame_row($quick_exceptions, icon('exception'), quick_link($exception));
    } elseif (
$package) {
        
$result .= quick_anchor();
        
$result .= frame_head('black', icon('package'), "package $package");
        if (
$text) frame_row_single($rows, $text);
        
$result .= frame_tail($rows);
        
frame_row($quick_packages, icon('package'), quick_link($package));
    }
    return
$result;
}

clear();
foreach (
file($filename) as $line) {
    
$line = rtrim($line);
    if (
preg_match('/^\s*function\s+([^\(\s]+)$/', $line, $matches)) {
        
$function = $matches[1];
    } elseif (
preg_match('/^\s*procedure\s+([^\(\s]+)$/', $line, $matches)) {
        
$procedure = $matches[1];
    } elseif (
preg_match('/^\s*(sub)*type\s+([^\(\s]+)/', $line, $matches)) {
        
$type = $matches[2];
    } elseif (
preg_match('/^\s*package\s+(\S+)/', $line, $matches)) {
        if (!
$h1) {
            
$h1 = $matches[1];
            print
"<h1>$h1</h1>\n";
            if (
$text) print "<p>$text</p>\n";
        } else {
            
$package = $matches[1];
        }
    } elseif (
preg_match('/^\s*(.+)\s*:\s*exception\s*;*/i', $line, $matches)) {
        
$exception = $matches[1];
    } elseif (
preg_match('/^\s*\(*(.+?)\s*:\s*' .
                         
'(in)*\s*(out|access)*\s*(\S+?)\)*' .
                         
';*\s*(--(.+?))*$/', $line, $matches)) {
        
$direction = $matches[2];
        if (
$matches[2] and $matches[3]) $direction .= ' ';
        
$direction .= $matches[3];
        
param(str_replace(' ', '&nbsp;', $matches[1]),
              
$direction, $matches[4], $matches[6]);
    } elseif (
preg_match('/^\s*(return)\s*(\S+?)\s*' .
                         
';*\s*(--(.+?))*$/', $line, $matches)) {
        
param('', $matches[1], $matches[2], $matches[4]);
    } elseif (
preg_match('/^\s*--$/', $line, $matches)) {
        if (
$text) $text .= "<br/>";
    } elseif (
preg_match('/^\s*--(\s-|)\s+(.+?)$/', $line, $matches)) {
        if (
$text) {
            if (
$matches[1]) $text .= "<br/>\n&bull;&nbsp;";
            else
$text .= "\n";
        }
        
$text .= $matches[2];
    } elseif (
preg_match('/^\s*private$/', $line)) {
        break;
    } elseif (
preg_match('/----/', $line)) {
        if (
$text) print "<h2>$text</h2>\n";
        
clear();
    } elseif (
preg_match('/^$/', $line)) {
        
$output .= output();
        if (
$h1) {
            print
$output;
            
$output = '';
        }
        
clear();
    }
}

output();

?>
</td>
<td class="nav" style="padding-left: 8px;">
<?php

function quick($icon, $caption, $color, $content) {
    if (
$content) {
        print
frame_head($color, $icon, $caption);
        print
frame_tail($content);
    }

}

quick(icon('package'), 'packages', 'black', $quick_packages);
quick(icon('type'), 'types', 'blue', $quick_types);
quick(icon('exception'), 'exceptions', 'red', $quick_exceptions);
quick(icon('method'), 'methods', 'orange', $quick_methods);

?>
</td>