+
+sub create_toc {
+ my ($apis_listed) = @_;
+ my $type_size = 0;
+ my $name_size = 0;
+ my $ret, $xname, $args, $line;
+ $apis_toc = "";
+
+
+ # Try to align things, so compute type size, method size, and arguments
+ foreach $line (split /\n/, $apis_listed){
+ $p = $prototype{$line};
+ ($ret, $xname, $args) = $p =~ /(.*)\n(\w+)[ \t](.*)/;
+ $tl = length ($ret);
+ $pl = length ($xname);
+
+ $type_size = $tl if ($tl > $type_size);
+ $name_size = $pl if ($pl > $name_size);
+ }
+
+ $type_size++;
+ $name_size++;
+
+ foreach $line (split /\n/, $apis_listed){
+ chop;
+ $p = $prototype{$line};
+ ($ret, $xname, $args) = $p =~ /(.*)\n(\w+)[ \t](.*)/;
+
+ $rspace = " " x ($type_size - length ($ret));
+ $nspace = " " x ($name_size - length ($xname));
+ $args = &format ($args, length ($ret . $rspace . $xname . $nspace), 60);
+ $apis_toc .= "$ret$rspace<a href=\"\#api:$line\">$xname</a>$nspace$args\n";
+ }
+ return $apis_toc;
+}
+
+#
+# Formats the rest of the arguments in a way that will fit in N columns
+#
+sub format {
+ my ($args, $size, $limit) = @_;
+ my $sret = "";
+
+# return $args if ((length (args) + size) < $limit);
+
+ $remain = $limit - $size;
+ @sa = split /,/, $args;
+ $linelen = $size;
+ foreach $arg (@sa){
+ if ($sret eq ""){
+ $sret = $arg . ", ";
+ $linelen += length ($sret);
+ } else {
+ if ($linelen + length ($arg) < $limit){
+ $sret .= "FITS" . $arg . ", ";
+ } else {
+ $newline = " " x ($size) . $arg . ", ";
+ $linelen = length ($newline);
+ $sret .= "\n" . $newline;
+ }
+ }
+ }
+ $sret =~ s/, $/;/;
+ return $sret;
+}
+
+sub opt_print {
+ my ($caption, $opttext, $quote) = @_;
+
+ if ($opttext ne "" && (!($opttext =~ /^[ \t]+$/))){
+ print OUT "<b>$caption</b>\n";
+ if ($quote == 1){
+ print OUT "<blockquote>$opttext</blockquote>\n";
+ } else {
+ print OUT "<p>$opttext\n";
+ }
+ }
+}