#!/usr/bin/perl ## ## Copyright (c) 1999 Internet Images Srl ## Massimiliano Masserelli ## ## Synopsys: ## classdoctpl.pl < classdeclaration.inc ## ## Output: ## A file for every class defined in classdeclaration.inc, named after ## each class with ".sgml" extension containing a workable template ## to start with. ## A line to stdout for every class method and instance, just to tell ## you what's going on. ## ## Bugs/Features: ## Instances which are initialized in declaration with defaults, are ## reported as such in output template[s]. This DOES NOT follow ## phplib documentation style, but may be an useful reminder when ## editing the template. ## ## WARNING!! ## This script is a VERY QUICK HACK(tm). If you follow phplib codestyle ## should work. It works for me(tm), YMMV. ## ## $Id: classdoctpl.pl,v 1.1 1999/07/29 11:23:48 negro Exp $ ## $pcount = 0; $cclass = ""; while (<>) { chop; while (?\}?) { $pcount --; } reset; if ($pcount == 0) { if (/class\s+(\w+)\s+{/) { # Beginning of a class $cclass = $1; push(@classes, $cclass); @{$variables{$cclass}} = (); @{$methods{$cclass}} = (); } } elsif ($pcount == 1) { # if (/function\s+(\w+)\s*\(([a-zA-Z ,\$=_]*)\)\s*\{/) { if (/function\s+(\w+)\s*\((.*)\)\s*\{/) { push(@{$methods{$cclass}}, sprintf("%s(%s)", $1, $2)); print $cclass . "->" . $1 . "(" . $2 . ")\n"; } if (/var\s+(\$\w+)\s*=\s*(\S.*)\s*;/) { push(@{$variables{$cclass}}, sprintf("%s = %s", $1, $2)); print $cclass . "->" . $1 . "=" . $2 . "\n"; } if (/var\s+(\$\w+)\s*;/) { push(@{$variables{$cclass}}, sprintf("%s", $1)); print $cclass . "->" . $1 . "\n"; } } while (?\{?) { $pcount++; } reset; } for $cl (@classes) { open(OUT, "> $cl.sgml") || print "Cannot open $cl.sgml\n", next; print OUT '' . "\n"; print OUT sprintf("%s\n

\n\n", tosgml($cl)); print OUT "\n"; print OUT "Instance variables\n"; print OUT "

\n"; print OUT "\n"; print OUT "\n"; print OUT "\n"; for $vr (@{$variables{$cl}}) { print OUT sprintf("%sDescription\n", tosgml($vr)); } print OUT "\n"; print OUT "\n"; print OUT "
Accessible instance variables.
\n"; print OUT "\n"; print OUT "\n"; print OUT "\n"; print OUT "\n"; print OUT "\n"; print OUT "
Internal instance variables.
\n"; print OUT "\n"; print OUT "Instance methods\n"; print OUT "

\n"; print OUT "\n"; print OUT "Accessible instance methods\n"; print OUT "

\n"; print OUT "\n"; print OUT "\n"; for $mt (@{$methods{$cl}}) { print OUT sprintf("%s\n", tosgml($mt)); print OUT "

\n"; print OUT "\n"; } print OUT "\n"; print OUT "\n"; print OUT "Internal instance methods\n"; print OUT "

\n"; print OUT "\n"; print OUT "\n"; print OUT "\n"; print OUT "Example\n"; print OUT "

\n"; print OUT "\n"; print OUT "Use\n"; print OUT "\n"; print OUT "\n"; print OUT "\n"; print OUT "\n"; close(OUT); } sub tosgml($) { my $string = shift; $string =~ s/_/_/g; $string =~ s/>/>/g; $string =~ s/