cvs: phpdoc /scripts zendapi_protos.php

From: Date: Sun, 28 Aug 2005 09:55:52 +0000
Subject: cvs: phpdoc /scripts zendapi_protos.php
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969369732@lists.php.net to get a copy of this message
hholzgra Sun Aug 28 05:55:52 2005 EDT Added files: /phpdoc/scripts zendapi_protos.php Log: a simple script that generates docbook template files for zend API functions by parsing header files piped in on standard input (i finally decided to take action as "The Creators of PHP" are not likely to *ever* do this homework of theirs ... :( http://cvs.php.net/co.php/phpdoc/scripts/zendapi_protos.php?r=1.1&p=1 Index: phpdoc/scripts/zendapi_protos.php +++ phpdoc/scripts/zendapi_protos.php <?php // just read from standard input right now $in = fopen("php://stdin", "r"); // loop over all lines in the file while (!feof($in)) { // TODO a prototype may span more than one line? $line = trim(fgets($in)); // we look for prototypes marked with ZEND_API // TODO prototypes may be indented by whitespace? if (!strncmp("ZEND_API", $line, 8)) { // parse prototypes, step #1 if (preg_match('|^ZEND_API\s+(\S+)\s+(\S+)\((.*)\);$|', $line, $matches)) { $return_type = $matches[1]; $function = $matches[2]; // the pointer '*' is usually next to the function name, not the type // TODO what if there is whitespace on both sides of the '*'? if ($function{0} == '*') { $return_type.= "*"; $function = substr($function, 1); } // the parameters are spearated by commas // TODO find a better way to handle TSRMLS_D and TSRMLS_DC // TODO handle ... $params = array(); foreach (explode(",", trim($matches[3])) as $param) { $tokens = preg_split("/\s+/", trim($param)); $type = array_shift($tokens); $name = implode(" ", $tokens); if (empty($name)) { $params[] = $type; } else { $params[$type] = $name; } } // now write the template file to phpdoc/en/internals/zendapi/functions ob_start(); echo '<?xml version="1.0" encoding="iso-8859-1"?>'."\n"; ?> <!-- $Revision: 1.1 $ --> <refentry id="zend-api.<?php echo str_replace("_","-",$function); ?>"> <refnamediv> <refname><?php echo $function; ?></refname> <refpurpose>...</refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <methodsynopsis> <type><?php echo $return_type; ?></type><methodname><?php echo $function; ?></methodname> <?php foreach($params as $type => $name) { if (is_numeric($type)) $type = ""; echo " <methodparam><type>$type</type><parameter>$name</parameter></methodparam>\n"; } ?> </methodsynopsis> <para> ... </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <?php foreach($params as $type => $name) { if (is_numeric($type)) $type = ""; ?> <varlistentry> <term><parameter><?php $name; ?></parameter></term> <listitem> <para> ... </para> </listitem> </varlistentry> <?php } ?> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> ... </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> <?php file_put_contents("../en/internals/zendapi/functions/".$function.".xml", ob_get_clean()); } } } ?>

« previous php.doc (#969369732) next »