TCL/javascript/php stuff

tcl code, javascript code, php code, documentation tools,

Tuesday, October 04, 2005

PHP DOC 0.0.0.0.0.0.0.0.0.0.1

so, this is the code for the documenter, and some examples of its usage at the bottom, im hoping to improve its lousy colors, and shitty layout soon enough,
if anyone has any ideas on how to improve this , please...


<?php
# vim: :set wrap!
# and
# a whole lot of other stuff

function make($path="./",$mask="*.php",$mode="doc",$key="function",$ch="#"){
#path must have a trailing slash , there is no recursion.
$pat1="/^\s*${key}\s+([^(]*)\s*\(([^\)]*)\)\s*[^{]*{/";
$pat3="/^\s*$ch(.*)/";
//$pat1="/^\s*${key}[^{]{/";
$list=array(); //data list
$fn=0;//file number
foreach (glob("$path$mask") as $filename){
$fun=0;//function number
///echo("<hr>");
if($mode=="doc"){ //documentation
$all=file($filename);
$list[$fn]=array();
$list[$fn]["filename"]=$filename;
$list[$fn]["comments"]="";
for($i1=1;$i1<count($all);$i1++){ //starts at 1: so that it ignores the <?php tag
$list[$fn]["comments"].="\n<br>";
if(preg_match($pat3,$all[$i1],$mt)){
$list[$fn]["comments"].="\n<br>".trim($mt[1]);
}else{
break;
}
}
$list[$fn]["functions"]=array();

$all2=0;
for($i=0;$i<count($all);$i++){
$mt2=array();
if(preg_match($pat1,$all[$i],$mt2)){
//echo("<br><font color=red>funk $all[$i]</font>");
$list[$fn]["functions"][$fun]=array();
$list[$fn]["functions"][$fun]["name"]=trim($mt2[1]);
$list[$fn]["functions"][$fun]["parameters"]=explode(",",trim($mt2[2]));
$list[$fn]["functions"][$fun]["comments"]="";
for($k=$i+1;$k<count($all);$k++){
$mt=array();
if(preg_match($pat3,$all[$k],$mt)){
$list[$fn]["functions"][$fun]["comments"].="\n<br>".trim($mt[1]);
//echo("<br><font color=blue>comment $all[$k]</font>");
}else{
break;
}
}
$i=$k;
$fun++; //yeah, right
}else{
//echo("<br>$i:$all[$i] :::".preg_match($pat1,$all[$i]));
}

}

}
if($mode=="make"){ //callerID

}
//echo "$filename size " . filesize($filename) . "<br>";
$fn++;
}
//echo("<pre>");print_r($list);echo("</pre>");
return($list);

}

function show_html_list($list){
#this function recieves a structured representation
#of a program and displays it in html.
$all3="";
for($i=0;$i<count($list);$i++){
$fn=$list[$i]["filename"];//filename
$fc=$list[$i]["comments"];//file comments
echo("<table width=100% border=1 cellspacing=0 cellpadding=0><tr><td valign=top colspan=2 style='background-color:blue;color:white'><h3>$fn</h3></td></tr>");
echo("<tr><td style='background-color:rgb(100,100,255);color:white'>comments</td><td>$fc</td></tr>");
if(count($list[$i]["functions"])>0){
echo("<tr><td width=10% valign=top style='background-color:rgb(150,150,200);color:white'>Functions</td><td valign=top>");
echo("<table border=1 cellspacing=0 cellpadding=0 width=100% height=100%>");
echo("<tr><th style='background-color:darkblue;color:white' width=10%>name</th><th style='background-color:darkblue;color:white'>parameters</th><th style='background-color:darkblue;color:white'>comments</th></tr>");
for($i1=0;$i1<count($list[$i]["functions"]);$i1++){
$funname=$list[$i]["functions"][$i1]["name"];
echo("<tr><td valign=top><b>");
echo("$funname</b></td><td valign=top>");
$all3.="\ncall[\"$funname\"]=\"$fn\"";

$i2=0;
echo("<ul>");
for($i2=0;$i2<count($list[$i]["functions"][$i1]["parameters"]);$i2++){
echo("<li>".$list[$i]["functions"][$i1]["parameters"][$i2]);
//echo("<br>");
}
echo("</ul>");
echo("</td><td valign=top><pre>");
echo($list[$i]["functions"][$i1]["comments"]);
echo("</pre></td></tr>");
//echo("<pre>"); print_r($list[$i]["functions"]);

//echo($list[$i]["functions"][$i1]["name"]);
}
echo("</table>");
}
echo("</td></tr></table><br>");
}
echo("<hr>");
echo("<pre>$all3</pre>");

}
//$l=make("./","f1.php");
$l2=make("../","*.php","doc","function","#");
show_html_list($l2);
$l2=make("../include/","*.php","doc","function","#");
show_html_list($l2);
$l2=make("../modules/","*.php","doc","function","#");
show_html_list($l2);
$l2=make("../media/","*.js","doc","function","//");
show_html_list($l2);

?>