1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
#!/usr/bin/perl
use IO::File;
# Open up the output files
$fh = new IO::File "> api.html";
# Lists for the index
@IText = ();
@ISettings = ();
@IDrawing = ();
@IDevices = ();
@IInteractive = ();
@Device = ();
@Test = ();
@Settings = ();
@Drawing = ();
@Interactive = ();
# Subroutine for parsing individual comments
sub processComment
{
my $fh;
my @prototype;
my $type = '';
my $name = '';
my $desciption = '';
my @seeAlso;
my @lists;
$desciption = '';
undef @lists;
undef @seeAlso;
undef @prototype;
# Get all the info
do
{
# Get the name and type
if ($_[0] =~ m/.* (Interactive|Text|Drawing|Device|Settings):\s*(.*)$/)
{
($type, $name) = ($1, $2);
}
# Get the desciption
elsif ($_[0] =~ m/^.*Synopsis:\s*(.*)$/)
{
$description = $1;
while ($_[1] =~ m/\s\*\s*(\S.*)$/)
{
$description = $description . ' ' . $1;
shift;
}
}
# Get the see also list
elsif ($_[0] =~ m/.* See Also: (.*)$/)
{
@seeAlso = split (/,\s*/, $1);
}
# Get any lists
elsif ($_[0] =~ m/\s*\*\s*(\S.*):/)
{
# the title
my @tmp = ();
push @tmp, $1;
# the items
while ($_[1] =~ m/\s*\*\s*\-(.*)\s*:\-\s*(\S.*)$/)
{
push @tmp, $1;
push @tmp, $2;
shift;
# Items over more than one line.
while ($_[1] !~ m/^\s*\*\s*\-.*\s*:\-\s*\S.*$/ && $_[1] !~ m/^\s*\*\s*$/ && $_[1] =~ m/^\s*\*/)
{
$_[1] =~ m/^\s*\*\s*(\S.*)$/;
push (@tmp, pop (@tmp) . ' ' . $1);
shift;
}
}
push @lists, \@tmp;
}
# Fuction prototype
elsif ($_[0] !~ m/^ \*/)
{
# Type
chomp ($_[0]);
push @prototype, $_[0];
shift;
chomp ($_[0]);
# Name
push @prototype, substr ($_[0], 0, index ($_[0], ' '));
# Arguments
push @prototype, substr ($_[0], index ($_[0], ' '));
while (shift)
{
$_[0] =~ m/^\s*(.*)$/;
push @prototype, pop (@prototype) . " $1";
}
}
} while (shift);
# Add to the index and description lists
if ($type eq "Text")
{
$IFile = \@IText;
$File = \@Text;
}
elsif ($type eq "Drawing")
{
$IFile = \@IDrawing;
$File = \@Drawing;
}
elsif ($type eq "Device")
{
$IFile = \@IDevice;
$File = \@Device;
}
elsif ($type eq "Settings")
{
$IFile = \@ISettings;
$File = \@Settings;
}
elsif ($type eq "Interactive")
{
$IFile = \@IInteractive;
$File = \@Interactive;
}
else
{
return;
}
push @$IFile, $name;
# Name
push @$File, "<h3><a name=\"$name\">$name</a><hr></h3>\n";
# Prototype
push @$File, "<table class=\"proto\">\n<tr><td width=10%>" . shift (@prototype) . "</td><td width=20%>" . shift (@prototype) . "</td><td>" . shift (@prototype) . ";</tr></table>";
# Description
push @$File, "<p>$description</p>\n";
# Lists
foreach $item (@lists)
{
# Name
push @$File, "<h4>" . shift (@$item) . ":</h4>\n";
# Table preamble
push @$File, "<table class=\"api\">";
# Table contents
while (@$item)
{
push @$File, "<tr>\n<td>" . shift (@$item) . ":</td>";
push @$File, "<td>" . shift (@$item) . "</td>\n</tr>";
}
# Table postamble
push @$File, "</table>";
}
# See Also
if (@seeAlso)
{
push @$File, "<h4>See Also:</h4><p>";
foreach (@seeAlso)
{
push @$File, "<a href=\"#$_\">$_</a> ";
}
push @$File, "</p>";
}
}
# prossess each comment
my @currentComment = ();
my $inComment = 0;
while (<>)
{
# Begin a comment
if ($_ =~ m/\/\*\*/ && $inComment == 0)
{
$inComment = 1;
}
# End comment
elsif ($_ =~ m/\*\// && $inComment == 1)
{
# Get the prototype as well
my $nextL = <>;
while ($nextL && $nextL !~ m/{/)
{
push @currentComment, $nextL;
$nextL = <>;
}
&processComment (@currentComment);
@currentComment = ();
$inComment = 0;
}
# Add to comment
elsif ($inComment == 1)
{
push (@currentComment, $_);
}
}
# Write the output file
# First the formating junk
$fh->print (
"<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html\"; charset=utf-8\" \>
<title>giza - API Reference Manual</title>
<link rel=\"stylesheet\" href=\"../style.css\" type=\"text/css\" \>
</head>
<div class=\"header\">
<a href=\"/giza\"><img alt=\"giza\" src=\"../title.png\"\></a>
</div>
<div id=\"menucontainer\">
<ul id=\"menulist\">
<li><a href=\"../news/\">news</a></li>
<li><a href=\"../download/\">download</a></li>
<li><a href=\"../documentation/\">documentation</a></li>
<li><a href=\"../contact/\">contact</a></li>
<li><a href=\"../samples/\">samples</a></li>
</ul>
</div>
<div id=\"content\">
<h1>API Reference Manual</h1>
<p>Here we provided a function by function reference for the low-level C API to giza.
<br/>The giza API is <strong>stable</strong>.
From version 1.0 we aim to keep backwards compatibility, although new functionality may be added</p>
<h1>Index</h1>
<dl class=\"toc\">");
# Then the index
$fh->print ("<dt><a href=\"#Device_management\">Device Management</a></dt>\n");
foreach (@IDevice)
{
$fh->print ("<dd><a href=\"#$_\">$_</a></dd>\n");
}
$fh->print ("<dt><a href=\"#Drawing\">Drawing</a></dt>\n");
foreach (@IDrawing)
{
$fh->print ("<dd><a href=\"#$_\">$_</a></dd>\n");
}
$fh->print ("<dt><a href=\"#Text\">Text</a></dt>\n");
foreach (@IText)
{
$fh->print ("<dd><a href=\"#$_\">$_</a></dd>\n");
}
$fh->print ("<dt><a href=\"#Settings\">Settings</a></dt>\n");
foreach (@ISettings)
{
$fh->print ("<dd><a href=\"#$_\">$_</a></dd>\n");
}
$fh->print ("<dt><a href=\"#Interactive\">Interactive</a></dt>\n");
foreach (@IInteractive)
{
$fh->print ("<dd><a href=\"#$_\">$_</a></dd>\n");
}
$fh->print ("</dl>");
# Write descriptions for Device Management
$fh->print ("<a name=\"Device_managment\"></a><h1>Device Managment</h1>\n");
foreach (@Device)
{
$fh->print ("$_");
}
# Write descriptions for Drawing
$fh->print ("<a name=\"Drawing\"></a><h1>Drawing</h1>\n");
foreach (@Drawing)
{
$fh->print ("$_");
}
# Write descriptions for Text
$fh->print ("<a name=\"Text\"></a><h1>Text</h1>\n");
foreach (@Text)
{
$fh->print ("$_");
}
# Write descriptions for Settings
$fh->print ("<a name=\"Settings\"></a><h1>Settings</h1>\n");
foreach (@Settings)
{
$fh->print ("$_");
}
# Write descriptions for Interactive
$fh->print ("<a name=\"Interactive\"></a><h1>Interactive</h1>\n");
foreach (@Interactive)
{
$fh->print ("$_");
}
# Close the files
$fh->flush ();
$fh->close ();
|