hholzgra                Thu Oct 23 03:15:07 2003 EDT

  Added files:                 
    /functable  checkdoc.php protos.php 
  Log:
  additional scripts ....
  

Index: functable/checkdoc.php
+++ functable/checkdoc.php
#!/usr/local/bin/php
<?php

require_once "PEAR.php";
require_once "File/Find.php";
require_once "XML/Parser.php";

require_once "config.php";
require_once "lib/dbconnect.php";

/**
 * Scan file for <refname> tags and store their positions
 *
 * @author Hartmut Holzgraefe <[EMAIL PROTECTED]>
 */
class func_finder extends XML_Parser {
    /**
         * Name of file being scanned
         *
         * @type string
         */
        var $filename = "";

        /**
         * Remember last chunk of plain data here
         *
         * @type string
         */
        var $last_data = "";
        
        /**
         * Data handler just stores last data seen 
         *
         * @access private
         * @param  resource XML parser 
         * @param  string   cdata
         */
        function cdataHandler($xp, $cdata) {
                $this->last_data = $cdata;
        }
        
        /**
         * <refname> end tag handler stores tag position in database
         *
         * We assume that <refname>...</refname> is on a single line
         * and that the cdata within is just a single chunk
         *
         * @access private
         * @param  resource XML parser
         * @param  string   tag name
         */
        function xmltag_refname_($xp, $elem) {
                $query = sprintf("INSERT INTO docfile (function, docfile, lineno) 
                                       VALUES ('%s',     '%s',    %d);\n",
                                                 $this->last_data,
                                                 ereg_replace("^sources/", "", 
$this->filename),
                                                 xml_get_current_line_number($xp)
                                                 );
                mysql_query($query);
        }

        /**
         * Constructor
         *
         * @access public
         * @param  string  file to scan
         */
        function func_finder($filename) {
                parent::XML_Parser(null, "func");
                $this->filename = $filename;
                $this->setInputFile($filename);
                $this->parse();
        }
}

   
/*       _       _           _                 _      
 *  __ _| | ___ | |__   __ _| |   ___ ___   __| | ___ 
 * / _` | |/ _ \| '_ \ / _` | |  / __/ _ \ / _` |/ _ \
 *| (_| | | (_) | |_) | (_| | | | (_| (_) | (_| |  __/
 * \__, |_|\___/|_.__/ \__,_|_|  \___\___/ \__,_|\___|
 * |___/                                              
 */

// purge database 
mysql_query("TRUNCATE TABLE docfile");

// get a file finder helper object
$find = new File_Find;

// now let it search for all relevant XML files
foreach ($find->search('.*\.xml', 'sources/phpdoc/en/reference') as $file) {
        // and scan them
        $ff = new func_finder($file); unset($ff);
}


?>
Index: functable/protos.php
+++ functable/protos.php
#!/usr/local/bin/php
<?php

require_once "PEAR.php";
require_once "File/Find.php";

require_once "config.php";
require_once "lib/dbconnect.php";

function proto_scan ($version, $filename) {

        $fp = fopen($filename, "r");

        if ($fp) {
                $lineno = 0;
                while (!feof($fp)) {
                        $line = fgets($fp);
                        $lineno++;

                        // check for proto lines
                        if (preg_match('|/\*\s*\{\{\{\s+proto\s(.*)|', $line, 
$matches)) {
                                $proto = $matches[1];
                                $proto_line = $lineno;

                                // ignore protos for object methods
                                if (strstr($proto, "::") || strstr($proto, "->")) {
                                        continue;
                                }

                                // ingore anything that does not look like a function 
                                if (!preg_match('|(\w+)\s*\(|', $proto, $matches)) {
                                        continue;
                                }
                                $function = $matches[1];

                                // the rest of the comment is the description
                                $comment = "";
                                while (!feof($fp)) {
                                        $comment .= trim(fgets($fp))." ";
                                        $lineno++;

                                        // check for comment end and cut where 
appropriate
                                        $pos = strpos($comment, "*/");
                                        if ($pos !== false) {
                                                $comment = substr($comment, 0, $pos);
                                                break;
                                        }
                                }

                                // store into the database
                                store_proto($version, $filename, $proto_line, 
$function, $proto, $comment);
                        }
                }
                fclose($fp);
        }
}


function store_proto($version, $filename, $proto_line, $function, $proto, $comment) {
        echo "
INSERT INTO proto$version 
        SET function   = '".mysql_escape_string($function)."'
          , proto      = '".mysql_escape_string($proto)."'
          , proto_desc = '".mysql_escape_string($comment)."';
         ";
}


/*       _       _           _                 _      
 *  __ _| | ___ | |__   __ _| |   ___ ___   __| | ___ 
 * / _` | |/ _ \| '_ \ / _` | |  / __/ _ \ / _` |/ _ \
 *| (_| | | (_) | |_) | (_| | | | (_| (_) | (_| |  __/
 * \__, |_|\___/|_.__/ \__,_|_|  \___\___/ \__,_|\___|
 * |___/                                              
 */

// purge database 
mysql_query("TRUNCATE TABLE docfile");

// get a file finder helper object
$find = new File_Find;

// now let it search for all relevant source files
foreach ($find->search('.*\.e?[chy]', 'sources/php_5_cvs') as $file) {
        proto_scan("5", $file);
}


?>

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to