cvs: pear /Structures_DataGrid/tools/manual-gen mkmanual.sh parse-options.php
| From: | Mark Wiesemann | Date: | Sat, 19 Aug 2006 17:39:20 +0000 |
| Subject: | cvs: pear /Structures_DataGrid/tools/manual-gen mkmanual.sh parse-options.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-41735@lists.php.net to get a copy of this message | ||
wiesemann Sat Aug 19 17:39:20 2006 UTC
Modified files:
/pear/Structures_DataGrid/tools/manual-gen mkmanual.sh
parse-options.php
Log:
- options parser now reads also descriptions and notes
- parser is now called by mkmanual.sh
- only open TODO item: parse (and add) examples
http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh?r1=1.9&r2=1.10&diff_format=u Index: pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh diff -u pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh:1.9 pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh:1.10 --- pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh:1.9 Sun Jul 30 14:55:17 2006 +++ pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh Sat Aug 19 17:39:20 2006 @@ -28,7 +28,7 @@ TARGET_DIR=$1 fi -VERSION=0.2 +VERSION=0.3 echo "Structures_DataGrid Manual Generator $VERSION" @@ -61,6 +61,10 @@ echo +echo "Parsing/Generating DataSource and Renderer files" +php tools/manual-gen/parse-options.php $TARGET_DIR_PHPDOC +echo "Done." + # Cleaning "Warnings" and fixing require_once() # The sed command that removes examples line numbers might be dangerous echo "Removing Warnings and examples line numbers, fixing require_once() into:" @@ -81,13 +85,13 @@ # Patching new/modified files cd $BUILD_DIR/structures/structures-datagrid echo "Patching new/modified file: " -for f in structures-datagrid/*.xml structures-datagrid-column/*.xml; do +for f in structures-datagrid/*.xml structures-datagrid-column/*.xml structures-datagrid-datasource/*.xml structures-datagrid-renderer/*.xml; do if ! diff -Nu -I '\$Revision.*\$' $TARGET_DIR/en/package/structures/structures-datagrid/$f \ $f > $BUILD_DIR/diff then patch $TARGET_DIR/en/package/structures/structures-datagrid/$f < $BUILD_DIR/diff fi -done +done echo echo Done. You can now regenerate the html manual. http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/tools/manual-gen/parse-options.php?r1=1.5&r2=1.6&diff_format=u Index: pear/Structures_DataGrid/tools/manual-gen/parse-options.php diff -u pear/Structures_DataGrid/tools/manual-gen/parse-options.php:1.5 pear/Structures_DataGrid/tools/manual-gen/parse-options.php:1.6 --- pear/Structures_DataGrid/tools/manual-gen/parse-options.php:1.5 Fri Aug 18 22:32:54 2006 +++ pear/Structures_DataGrid/tools/manual-gen/parse-options.php Sat Aug 19 17:39:20 2006 @@ -1,34 +1,36 @@ <?php -// run me from the command line (while being in pear/Structures_DataGrid), using: -// php tools/manual-gen/parse-options.php +// this script is intended to be run by mkmanual.sh error_reporting(E_ALL); -require_once 'File/Util.php'; - -// TODO: this script should be called by mkmanual.sh -// TODO: pass the peardoc path as a parameter to this script -// TODO: we need different peardoc path definitions for Cygwin and PHP -// TODO: remove this constant -define('PEARDOC_PATH', 'c:/data/repository/peardoc'); +if ($argc != 2) { + die('Missing parameter: temporary target dir'); +} define('PATH', '../'); -define('TMP_PATH', File_Util::tmpDir() . '/sdgdoc/'); +define('TMP_PATH', $argv[1] . '/structures/structures-datagrid/'); + if (!is_dir(TMP_PATH)) { mkdir(TMP_PATH, 0770, true); +} +if (!is_dir(TMP_PATH . 'structures-datagrid-datasource/')) { mkdir(TMP_PATH . 'structures-datagrid-datasource/', 0770, true); +} +if (!is_dir(TMP_PATH . 'structures-datagrid-renderer/')) { mkdir(TMP_PATH . 'structures-datagrid-renderer/', 0770, true); } +$descriptions = array(); $options = array(); +$notes = array(); $inheritance = array(); // parse all directories whose names begin with 'Structures_DataGrid' $directories = scandir(PATH); foreach ($directories as $directory) { if (substr($directory, 0, 19) == 'Structures_DataGrid') { - parseDirectory($options, $inheritance, $directory); + parseDirectory($descriptions, $options, $notes, $inheritance, $directory); } } @@ -57,7 +59,7 @@ // sort the options alphabetically ksort($driver_options); // save the options as an XML file - $id = writeXMLFile($orig_class, $driver_options); + $id = writeXMLFile($orig_class, $descriptions[$orig_class], $driver_options, $notes[$orig_class]); $ids[] = $id; } @@ -68,7 +70,7 @@ } file_put_contents(TMP_PATH . 'ids.txt', $id_file); -function parseDirectory(&$options, &$inheritance, $dir) +function parseDirectory(&$descriptions, &$options, &$notes, &$inheritance, $dir) { $entries = scandir(PATH . $dir); foreach ($entries as $entry) { @@ -77,17 +79,17 @@ if (!in_array($entry, array('.', '..', 'CVS', 'docs', 'tools'))) { // step recursive into subdirectories if (is_dir(PATH . $dir . '/' . $entry)) { - parseDirectory($options, $inheritance, $dir . '/' . $entry); + parseDirectory($descriptions, $options, $notes, $inheritance, $dir . '/' . $entry); } // parse the file if the extension is .php if (substr($entry, -4) == '.php') { - parseFile($options, $inheritance, $dir . '/' . $entry); + parseFile($descriptions, $options, $notes, $inheritance, $dir . '/' . $entry); } } } } -function parseFile(&$options, &$inheritance, $filename) +function parseFile(&$descriptions, &$options, &$notes, &$inheritance, $filename) { echo 'Parsing ' . $filename . ' ... '; @@ -103,47 +105,132 @@ // save the inheritance relation $inheritance[$class] = $extends; - // search for the row after that the options are documented - $startRow = getStartRow($file); - - // the driver has no options - if ($startRow === false) { - echo "NO OPTIONS FOUND\n"; - $options[$class] = array(); - return; - } + // get the descriptions + $descriptions[$class] = getDescriptions($file, $descriptionsEndRow); - // search for the row that indicates the end of the options block - $endRow = getEndRow($file, $startRow); + // get the options + $options[$class] = getOptions($file, $descriptionsEndRow, $optionsEndRow); - // the driver has no options - // (this should not happen => die) - if ($endRow === false) { - die('END OF OPTION BLOCK NOT FOUND'); - } + // get the 'GENERAL NOTES' + $notes[$class] = getNotes($file, $optionsEndRow); - // collect the options - $options[$class] = getOptions($file, $startRow, $endRow); - // we're done with this file echo "DONE\n"; } -function getStartRow($file) +function getDescriptionsStartRow($file) { $startRow = false; + $i = 0; foreach ($file as $rowNumber => $row) { - // we've found the row where the options documentation begins - if (strpos($row, ' * SUPPORTED OPTIONS:') !== false) { + // we've found the row where the descriptions begin + if ($i > 2 && strpos($row, '/**') !== false) { $startRow = $rowNumber; break; } + $i++; } return $startRow; } -function getEndRow($file, $startRow) +function getDescriptionsEndRow($file, $startRow) +{ + if ($startRow === false) { + return false; + } + + $endRowTemp1 = 0; + for ($i = $startRow + 2; $i < count($file); $i++) { + // we've found one possible end of the descriptions + if (strpos($file[$i], 'SUPPORTED OPTIONS:') !== false) { + $endRowTemp1 = $i - 1; + break; + } + } + // maybe there are no options available + // ==> we also search for 'SUPPORTED OPERATION MODES' + $endRowTemp2 = 0; + for ($i = $startRow + 2; $i < count($file); $i++) { + // we've found another possible end of the descriptions + if (strpos($file[$i], 'SUPPORTED OPERATION MODES:') !== false) { + $endRowTemp2 = $i - 1; + break; + } + } + // maybe there are no also no operation modes available (that's the case in + // DataSource drivers) + // ==> we also search for '@version' + $endRowTemp3 = 0; + for ($i = $startRow + 2; $i < count($file); $i++) { + // we've found another possible end of the descriptions + if (strpos($file[$i], '@version') !== false) { + $endRowTemp3 = $i - 1; + break; + } + } + + // TODO: maybe the following checks can be formulated shorter? + if ($endRowTemp1 > 0 && $endRowTemp2 > 0 && $endRowTemp3 > 0) { + return min($endRowTemp1, $endRowTemp2, $endRowTemp3); + } elseif ($endRowTemp1 > 0 && $endRowTemp2 > 0) { + return min($endRowTemp1, $endRowTemp2); + } elseif ($endRowTemp1 > 0 && $endRowTemp3 > 0) { + return min($endRowTemp1, $endRowTemp3); + } elseif ($endRowTemp2 > 0 && $endRowTemp3 > 0) { + return min($endRowTemp2, $endRowTemp3); + } elseif ($endRowTemp1 > 0) { + return $endRowTemp1; + } elseif ($endRowTemp2 > 0) { + return $endRowTemp2; + } elseif ($endRowTemp3 > 0) { + return $endRowTemp3; + } + return false; +} + +function getDescriptions($file, &$descriptionsEndRow) +{ + // search for the limits of the descriptions + $startRow = getDescriptionsStartRow($file); + $endRow = getDescriptionsEndRow($file, $startRow); + + $descriptionsEndRow = $endRow; + + // the driver has no options + if ($startRow === false || $endRow === false) { + echo "NO DESCRIPTION FOUND\n"; + return array('short' => '', 'long' => ''); + } + + // read the descriptions + $short = ''; + $long = ''; + for ($i = $startRow + 1; $i < $endRow; $i++) { + $row = rtrim(substr($file[$i], 3)); + // do we have found the end of the short description? + if ($row == '') { + break; + } + $short .= ' ' . $row . "\n"; + } + for ($j = $i + 1; $j < $endRow; $j++) { + $long .= ' ' . rtrim(substr($file[$j], 3)) . "\n"; + } + + return array('short' => trim($short), 'long' => trim($long)); +} + +function getOptionsStartRow($file, $descriptionsEndRow) +{ + if (strpos($file[$descriptionsEndRow + 1], ' * SUPPORTED OPTIONS:') !== false) { + return $descriptionsEndRow + 1; + } + return false; + +} + +function getOptionsEndRow($file, $startRow) { $endRow = false; for ($i = $startRow + 2; $i < count($file); $i++) { @@ -157,7 +244,33 @@ return $endRow; } -function getOptions($file, $startRow, $endRow) +function getOptions($file, $descriptionsEndRow, &$optionsEndRow) +{ + // search for the row after that the options are documented + $startRow = getOptionsStartRow($file, $descriptionsEndRow); + + // the driver has no options + if ($startRow === false) { + echo "NO OPTIONS FOUND\n"; + return array(); + } + + // search for the row that indicates the end of the options block + $endRow = getOptionsEndRow($file, $startRow); + + // the driver has no options + // (this should not happen => die) + if ($endRow === false) { + die('END OF OPTION BLOCK NOT FOUND'); + } + + $optionsEndRow = $endRow; + + // collect the options + return _getOptions($file, $startRow, $endRow); +} + +function _getOptions($file, $startRow, $endRow) { $currOption = ''; $options = array(); @@ -194,6 +307,72 @@ return $options; } +function getNotesStartRow($file, $optionsEndRow) +{ + // for DataSource drivers this is the expected place + if (strpos($file[$optionsEndRow + 1], ' * GENERAL NOTES:') !== false) { + return $optionsEndRow + 1; + } + // for Renderer drivers this is the expected place + if (strpos($file[$optionsEndRow + 7], ' * GENERAL NOTES:') !== false) { + return $optionsEndRow + 7; + } + return false; +} + +function getNotesEndRow($file, $startRow) +{ + $endRow = false; + if ($startRow === false) { + return $endRow; + } + for ($i = $startRow + 2; $i < count($file); $i++) { + // we've found the row where the 'GENERAL NOTES' documentation ends + if (strpos($file[$i], '@version') !== false) { + $endRow = $i - 1; + break; + } + } + + return $endRow; +} + +function getNotes($file, $optionsEndRow) +{ + // search for the limits of the 'GENERAL NOTES' section + $startRow = getNotesStartRow($file, $optionsEndRow); + $endRow = getNotesEndRow($file, $startRow); + + // the driver has no options + if ($startRow === false || $endRow === false) { + echo "NO NOTES FOUND\n"; + return ''; + } + + // read the 'GENERAL NOTES' + $notes = ''; + for ($i = $startRow + 2; $i < $endRow; $i++) { + $row = rtrim(substr($file[$i], 3)); + if (strpos($row, '<code>') !== false) { + $codeTagOpen = true; + } + if (strpos($row, '</code>') !== false) { + $codeTagOpen = false; + } + if (!$codeTagOpen && $row == '') { + $notes .= " </para>\n <para>"; + } + $notes .= ' ' . $row . "\n"; + } + + $notes = htmlentities(trim($notes)); + $notes = str_replace(array('<code>', '</code>', '<para>', '</para>'), + array('<programlisting>', '</programlisting>', '<para>', '</para>'), + $notes + ); + return $notes; +} + function getClassName($file) { $file = join("\n", $file); @@ -217,7 +396,7 @@ return $prefix . trim(str_replace("\n", "\n$prefix$indentStr", $content)); } -function writeXMLFile($driver, $options) +function writeXMLFile($driver, $descriptions, $options, $notes) { // prepare some variables for the XML contents $type = 'structures-datagrid-' . ((strpos($driver, 'DataSource') !== false) ? 'datasource' : 'renderer'); @@ -226,15 +405,21 @@ // prepare the XML file $xml = '<?xml version="1.0" encoding="iso-8859-1" ?>' . "\n"; - $xml .= '<!-- $Revision: 1.5 $ -->' . "\n"; + $xml .= '<!-- $' . 'Revision$ -->' . "\n"; // avoid replacement by CVS here $xml .= '<refentry id="' . $id . '">' . "\n"; $xml .= ' <refnamediv>' . "\n"; $xml .= ' <refname>' . $driver . '</refname>' . "\n"; - // TODO: extract a short description from the source code - $xml .= ' <refpurpose>[TODO]</refpurpose>' . "\n"; + $xml .= ' <refpurpose>' . $descriptions['short'] . '</refpurpose>' . "\n"; $xml .= ' </refnamediv>' . "\n"; - // TODO: extract the 'GENERAL NOTES' section from the source code // TODO: extract example code link from the source code + if ($descriptions['long'] != '') { + $xml .= ' <refsect1 id="' . $id . '.desc">' . "\n"; + $xml .= ' <title>Description</title>' . "\n"; + $xml .= ' <para>' . "\n"; + $xml .= ' ' . $descriptions['long'] . "\n"; + $xml .= ' </para>' . "\n"; + $xml .= ' </refsect1>' . "\n"; + } $xml .= ' <refsect1 id="' . $id . '.options">' . "\n"; $xml .= ' <title>Options</title>' . "\n"; $xml .= ' <para>' . "\n"; @@ -264,6 +449,14 @@ $xml .= ' </tgroup>' . "\n"; $xml .= ' </table>' . "\n"; $xml .= ' </refsect1>' . "\n"; + if ($notes != '') { + $xml .= ' <refsect1 id="' . $id . '.notes">' . "\n"; + $xml .= ' <title>General notes</title>' . "\n"; + $xml .= ' <para>' . "\n"; + $xml .= ' ' . $notes . "\n"; + $xml .= ' </para>' . "\n"; + $xml .= ' </refsect1>' . "\n"; + } $xml .= '</refentry>' . "\n"; $xml .= '<!-- Keep this comment at the end of the file' . "\n"; $xml .= 'Local variables:' . "\n"; @@ -287,14 +480,6 @@ // write the XML file file_put_contents(TMP_PATH . $type . '/' . $name . '.xml', $xml); - - // move the XML file into peardoc directory - // TODO: this resets the CVS $Revision: 1.5 $ tag: every run of this script would - // indicate a change of *all* generated XML files - // solution: use 'patch' as in mkmanual.sh - unlink(PEARDOC_PATH . '/en/package/structures/structures-datagrid/' . $type . '/' . $name . '.xml'); - rename(TMP_PATH . $type . '/' . $name . '.xml', - PEARDOC_PATH . '/en/package/structures/structures-datagrid/' . $type . '/' . $name . '.xml'); // return the generated id return $id;
http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh?r1=1.9&r2=1.10&diff_format=u Index: pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh diff -u pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh:1.9 pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh:1.10 --- pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh:1.9 Sun Jul 30 14:55:17 2006 +++ pear/Structures_DataGrid/tools/manual-gen/mkmanual.sh Sat Aug 19 17:39:20 2006 @@ -28,7 +28,7 @@ TARGET_DIR=$1 fi -VERSION=0.2 +VERSION=0.3 echo "Structures_DataGrid Manual Generator $VERSION" @@ -61,6 +61,10 @@ echo +echo "Parsing/Generating DataSource and Renderer files" +php tools/manual-gen/parse-options.php $TARGET_DIR_PHPDOC +echo "Done." + # Cleaning "Warnings" and fixing require_once() # The sed command that removes examples line numbers might be dangerous echo "Removing Warnings and examples line numbers, fixing require_once() into:" @@ -81,13 +85,13 @@ # Patching new/modified files cd $BUILD_DIR/structures/structures-datagrid echo "Patching new/modified file: " -for f in structures-datagrid/*.xml structures-datagrid-column/*.xml; do +for f in structures-datagrid/*.xml structures-datagrid-column/*.xml structures-datagrid-datasource/*.xml structures-datagrid-renderer/*.xml; do if ! diff -Nu -I '\$Revision.*\$' $TARGET_DIR/en/package/structures/structures-datagrid/$f \ $f > $BUILD_DIR/diff then patch $TARGET_DIR/en/package/structures/structures-datagrid/$f < $BUILD_DIR/diff fi -done +done echo echo Done. You can now regenerate the html manual. http://cvs.php.net/viewvc.cgi/pear/Structures_DataGrid/tools/manual-gen/parse-options.php?r1=1.5&r2=1.6&diff_format=u Index: pear/Structures_DataGrid/tools/manual-gen/parse-options.php diff -u pear/Structures_DataGrid/tools/manual-gen/parse-options.php:1.5 pear/Structures_DataGrid/tools/manual-gen/parse-options.php:1.6 --- pear/Structures_DataGrid/tools/manual-gen/parse-options.php:1.5 Fri Aug 18 22:32:54 2006 +++ pear/Structures_DataGrid/tools/manual-gen/parse-options.php Sat Aug 19 17:39:20 2006 @@ -1,34 +1,36 @@ <?php -// run me from the command line (while being in pear/Structures_DataGrid), using: -// php tools/manual-gen/parse-options.php +// this script is intended to be run by mkmanual.sh error_reporting(E_ALL); -require_once 'File/Util.php'; - -// TODO: this script should be called by mkmanual.sh -// TODO: pass the peardoc path as a parameter to this script -// TODO: we need different peardoc path definitions for Cygwin and PHP -// TODO: remove this constant -define('PEARDOC_PATH', 'c:/data/repository/peardoc'); +if ($argc != 2) { + die('Missing parameter: temporary target dir'); +} define('PATH', '../'); -define('TMP_PATH', File_Util::tmpDir() . '/sdgdoc/'); +define('TMP_PATH', $argv[1] . '/structures/structures-datagrid/'); + if (!is_dir(TMP_PATH)) { mkdir(TMP_PATH, 0770, true); +} +if (!is_dir(TMP_PATH . 'structures-datagrid-datasource/')) { mkdir(TMP_PATH . 'structures-datagrid-datasource/', 0770, true); +} +if (!is_dir(TMP_PATH . 'structures-datagrid-renderer/')) { mkdir(TMP_PATH . 'structures-datagrid-renderer/', 0770, true); } +$descriptions = array(); $options = array(); +$notes = array(); $inheritance = array(); // parse all directories whose names begin with 'Structures_DataGrid' $directories = scandir(PATH); foreach ($directories as $directory) { if (substr($directory, 0, 19) == 'Structures_DataGrid') { - parseDirectory($options, $inheritance, $directory); + parseDirectory($descriptions, $options, $notes, $inheritance, $directory); } } @@ -57,7 +59,7 @@ // sort the options alphabetically ksort($driver_options); // save the options as an XML file - $id = writeXMLFile($orig_class, $driver_options); + $id = writeXMLFile($orig_class, $descriptions[$orig_class], $driver_options, $notes[$orig_class]); $ids[] = $id; } @@ -68,7 +70,7 @@ } file_put_contents(TMP_PATH . 'ids.txt', $id_file); -function parseDirectory(&$options, &$inheritance, $dir) +function parseDirectory(&$descriptions, &$options, &$notes, &$inheritance, $dir) { $entries = scandir(PATH . $dir); foreach ($entries as $entry) { @@ -77,17 +79,17 @@ if (!in_array($entry, array('.', '..', 'CVS', 'docs', 'tools'))) { // step recursive into subdirectories if (is_dir(PATH . $dir . '/' . $entry)) { - parseDirectory($options, $inheritance, $dir . '/' . $entry); + parseDirectory($descriptions, $options, $notes, $inheritance, $dir . '/' . $entry); } // parse the file if the extension is .php if (substr($entry, -4) == '.php') { - parseFile($options, $inheritance, $dir . '/' . $entry); + parseFile($descriptions, $options, $notes, $inheritance, $dir . '/' . $entry); } } } } -function parseFile(&$options, &$inheritance, $filename) +function parseFile(&$descriptions, &$options, &$notes, &$inheritance, $filename) { echo 'Parsing ' . $filename . ' ... '; @@ -103,47 +105,132 @@ // save the inheritance relation $inheritance[$class] = $extends; - // search for the row after that the options are documented - $startRow = getStartRow($file); - - // the driver has no options - if ($startRow === false) { - echo "NO OPTIONS FOUND\n"; - $options[$class] = array(); - return; - } + // get the descriptions + $descriptions[$class] = getDescriptions($file, $descriptionsEndRow); - // search for the row that indicates the end of the options block - $endRow = getEndRow($file, $startRow); + // get the options + $options[$class] = getOptions($file, $descriptionsEndRow, $optionsEndRow); - // the driver has no options - // (this should not happen => die) - if ($endRow === false) { - die('END OF OPTION BLOCK NOT FOUND'); - } + // get the 'GENERAL NOTES' + $notes[$class] = getNotes($file, $optionsEndRow); - // collect the options - $options[$class] = getOptions($file, $startRow, $endRow); - // we're done with this file echo "DONE\n"; } -function getStartRow($file) +function getDescriptionsStartRow($file) { $startRow = false; + $i = 0; foreach ($file as $rowNumber => $row) { - // we've found the row where the options documentation begins - if (strpos($row, ' * SUPPORTED OPTIONS:') !== false) { + // we've found the row where the descriptions begin + if ($i > 2 && strpos($row, '/**') !== false) { $startRow = $rowNumber; break; } + $i++; } return $startRow; } -function getEndRow($file, $startRow) +function getDescriptionsEndRow($file, $startRow) +{ + if ($startRow === false) { + return false; + } + + $endRowTemp1 = 0; + for ($i = $startRow + 2; $i < count($file); $i++) { + // we've found one possible end of the descriptions + if (strpos($file[$i], 'SUPPORTED OPTIONS:') !== false) { + $endRowTemp1 = $i - 1; + break; + } + } + // maybe there are no options available + // ==> we also search for 'SUPPORTED OPERATION MODES' + $endRowTemp2 = 0; + for ($i = $startRow + 2; $i < count($file); $i++) { + // we've found another possible end of the descriptions + if (strpos($file[$i], 'SUPPORTED OPERATION MODES:') !== false) { + $endRowTemp2 = $i - 1; + break; + } + } + // maybe there are no also no operation modes available (that's the case in + // DataSource drivers) + // ==> we also search for '@version' + $endRowTemp3 = 0; + for ($i = $startRow + 2; $i < count($file); $i++) { + // we've found another possible end of the descriptions + if (strpos($file[$i], '@version') !== false) { + $endRowTemp3 = $i - 1; + break; + } + } + + // TODO: maybe the following checks can be formulated shorter? + if ($endRowTemp1 > 0 && $endRowTemp2 > 0 && $endRowTemp3 > 0) { + return min($endRowTemp1, $endRowTemp2, $endRowTemp3); + } elseif ($endRowTemp1 > 0 && $endRowTemp2 > 0) { + return min($endRowTemp1, $endRowTemp2); + } elseif ($endRowTemp1 > 0 && $endRowTemp3 > 0) { + return min($endRowTemp1, $endRowTemp3); + } elseif ($endRowTemp2 > 0 && $endRowTemp3 > 0) { + return min($endRowTemp2, $endRowTemp3); + } elseif ($endRowTemp1 > 0) { + return $endRowTemp1; + } elseif ($endRowTemp2 > 0) { + return $endRowTemp2; + } elseif ($endRowTemp3 > 0) { + return $endRowTemp3; + } + return false; +} + +function getDescriptions($file, &$descriptionsEndRow) +{ + // search for the limits of the descriptions + $startRow = getDescriptionsStartRow($file); + $endRow = getDescriptionsEndRow($file, $startRow); + + $descriptionsEndRow = $endRow; + + // the driver has no options + if ($startRow === false || $endRow === false) { + echo "NO DESCRIPTION FOUND\n"; + return array('short' => '', 'long' => ''); + } + + // read the descriptions + $short = ''; + $long = ''; + for ($i = $startRow + 1; $i < $endRow; $i++) { + $row = rtrim(substr($file[$i], 3)); + // do we have found the end of the short description? + if ($row == '') { + break; + } + $short .= ' ' . $row . "\n"; + } + for ($j = $i + 1; $j < $endRow; $j++) { + $long .= ' ' . rtrim(substr($file[$j], 3)) . "\n"; + } + + return array('short' => trim($short), 'long' => trim($long)); +} + +function getOptionsStartRow($file, $descriptionsEndRow) +{ + if (strpos($file[$descriptionsEndRow + 1], ' * SUPPORTED OPTIONS:') !== false) { + return $descriptionsEndRow + 1; + } + return false; + +} + +function getOptionsEndRow($file, $startRow) { $endRow = false; for ($i = $startRow + 2; $i < count($file); $i++) { @@ -157,7 +244,33 @@ return $endRow; } -function getOptions($file, $startRow, $endRow) +function getOptions($file, $descriptionsEndRow, &$optionsEndRow) +{ + // search for the row after that the options are documented + $startRow = getOptionsStartRow($file, $descriptionsEndRow); + + // the driver has no options + if ($startRow === false) { + echo "NO OPTIONS FOUND\n"; + return array(); + } + + // search for the row that indicates the end of the options block + $endRow = getOptionsEndRow($file, $startRow); + + // the driver has no options + // (this should not happen => die) + if ($endRow === false) { + die('END OF OPTION BLOCK NOT FOUND'); + } + + $optionsEndRow = $endRow; + + // collect the options + return _getOptions($file, $startRow, $endRow); +} + +function _getOptions($file, $startRow, $endRow) { $currOption = ''; $options = array(); @@ -194,6 +307,72 @@ return $options; } +function getNotesStartRow($file, $optionsEndRow) +{ + // for DataSource drivers this is the expected place + if (strpos($file[$optionsEndRow + 1], ' * GENERAL NOTES:') !== false) { + return $optionsEndRow + 1; + } + // for Renderer drivers this is the expected place + if (strpos($file[$optionsEndRow + 7], ' * GENERAL NOTES:') !== false) { + return $optionsEndRow + 7; + } + return false; +} + +function getNotesEndRow($file, $startRow) +{ + $endRow = false; + if ($startRow === false) { + return $endRow; + } + for ($i = $startRow + 2; $i < count($file); $i++) { + // we've found the row where the 'GENERAL NOTES' documentation ends + if (strpos($file[$i], '@version') !== false) { + $endRow = $i - 1; + break; + } + } + + return $endRow; +} + +function getNotes($file, $optionsEndRow) +{ + // search for the limits of the 'GENERAL NOTES' section + $startRow = getNotesStartRow($file, $optionsEndRow); + $endRow = getNotesEndRow($file, $startRow); + + // the driver has no options + if ($startRow === false || $endRow === false) { + echo "NO NOTES FOUND\n"; + return ''; + } + + // read the 'GENERAL NOTES' + $notes = ''; + for ($i = $startRow + 2; $i < $endRow; $i++) { + $row = rtrim(substr($file[$i], 3)); + if (strpos($row, '<code>') !== false) { + $codeTagOpen = true; + } + if (strpos($row, '</code>') !== false) { + $codeTagOpen = false; + } + if (!$codeTagOpen && $row == '') { + $notes .= " </para>\n <para>"; + } + $notes .= ' ' . $row . "\n"; + } + + $notes = htmlentities(trim($notes)); + $notes = str_replace(array('<code>', '</code>', '<para>', '</para>'), + array('<programlisting>', '</programlisting>', '<para>', '</para>'), + $notes + ); + return $notes; +} + function getClassName($file) { $file = join("\n", $file); @@ -217,7 +396,7 @@ return $prefix . trim(str_replace("\n", "\n$prefix$indentStr", $content)); } -function writeXMLFile($driver, $options) +function writeXMLFile($driver, $descriptions, $options, $notes) { // prepare some variables for the XML contents $type = 'structures-datagrid-' . ((strpos($driver, 'DataSource') !== false) ? 'datasource' : 'renderer'); @@ -226,15 +405,21 @@ // prepare the XML file $xml = '<?xml version="1.0" encoding="iso-8859-1" ?>' . "\n"; - $xml .= '<!-- $Revision: 1.5 $ -->' . "\n"; + $xml .= '<!-- $' . 'Revision$ -->' . "\n"; // avoid replacement by CVS here $xml .= '<refentry id="' . $id . '">' . "\n"; $xml .= ' <refnamediv>' . "\n"; $xml .= ' <refname>' . $driver . '</refname>' . "\n"; - // TODO: extract a short description from the source code - $xml .= ' <refpurpose>[TODO]</refpurpose>' . "\n"; + $xml .= ' <refpurpose>' . $descriptions['short'] . '</refpurpose>' . "\n"; $xml .= ' </refnamediv>' . "\n"; - // TODO: extract the 'GENERAL NOTES' section from the source code // TODO: extract example code link from the source code + if ($descriptions['long'] != '') { + $xml .= ' <refsect1 id="' . $id . '.desc">' . "\n"; + $xml .= ' <title>Description</title>' . "\n"; + $xml .= ' <para>' . "\n"; + $xml .= ' ' . $descriptions['long'] . "\n"; + $xml .= ' </para>' . "\n"; + $xml .= ' </refsect1>' . "\n"; + } $xml .= ' <refsect1 id="' . $id . '.options">' . "\n"; $xml .= ' <title>Options</title>' . "\n"; $xml .= ' <para>' . "\n"; @@ -264,6 +449,14 @@ $xml .= ' </tgroup>' . "\n"; $xml .= ' </table>' . "\n"; $xml .= ' </refsect1>' . "\n"; + if ($notes != '') { + $xml .= ' <refsect1 id="' . $id . '.notes">' . "\n"; + $xml .= ' <title>General notes</title>' . "\n"; + $xml .= ' <para>' . "\n"; + $xml .= ' ' . $notes . "\n"; + $xml .= ' </para>' . "\n"; + $xml .= ' </refsect1>' . "\n"; + } $xml .= '</refentry>' . "\n"; $xml .= '<!-- Keep this comment at the end of the file' . "\n"; $xml .= 'Local variables:' . "\n"; @@ -287,14 +480,6 @@ // write the XML file file_put_contents(TMP_PATH . $type . '/' . $name . '.xml', $xml); - - // move the XML file into peardoc directory - // TODO: this resets the CVS $Revision: 1.5 $ tag: every run of this script would - // indicate a change of *all* generated XML files - // solution: use 'patch' as in mkmanual.sh - unlink(PEARDOC_PATH . '/en/package/structures/structures-datagrid/' . $type . '/' . $name . '.xml'); - rename(TMP_PATH . $type . '/' . $name . '.xml', - PEARDOC_PATH . '/en/package/structures/structures-datagrid/' . $type . '/' . $name . '.xml'); // return the generated id return $id;