1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
<?php
/*
+----------------------------------------------------------------------+
| PHP Version 4 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2010 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: anatoly techtonik <techtonik@php.net> |
+----------------------------------------------------------------------+
$Id: genfuncsummary.php 293138 2010-01-05 10:21:11Z rquadling $
*/
// Extract function summaries from sources of PHP and it's extensions
//
// Example of block looked in .c, .cpp, .h and .ec files
//
// /* {{{ proto string zend_version(void)
// Get the version of the Zend Engine */
//
if ($argc != 2 ||
in_array($argv[1], array('--help', '-help', '-h', '-?')) ||
!is_dir($argv[1])) {
echo "Extract function summaries from sources of PHP\n\n";
echo "Usage: $argv[0] <php source dir>\n";
echo " --help, -help, -h, -? - to get this help\n";
die;
}
// find all source files recursively - returns array with filenames
function get_parsefiles($srcpath) {
$parsefiles = array();
$srcdir = dir($srcpath);
while (false !== ($file = $srcdir->read())) {
$filepath = $srcpath."/".$file;
if (is_dir($filepath) && $file !== "." && $file !== "..") {
$parsefiles = array_merge($parsefiles, get_parsefiles($filepath));
continue;
}
if (preg_match('/\.(c|cpp|h|ec)$/i', $file)) {
$parsefiles[] = $filepath;
}
}
$srcdir->close();
return $parsefiles;
}
$parsefiles = get_parsefiles($argv[1]);
sort($parsefiles);
// check for PHP3 sources
if (is_file($argv[1]."/language-scanner.lex")) { // only in PHP3 sources
$parsefiles[] = $argv[1]."/language-scanner.lex";
}
// make unified directory separator - /
if (DIRECTORY_SEPARATOR == '\\') {
$parsefiles = array_map( create_function('$a', 'return str_replace("\\\\", "/", $a);'), $parsefiles );
}
// proto regex
$proto_regex = "`^\s*/\*\s+\{{3}\s+proto\s+(\S+)\s+?(.+)(?:(?:\r\n|\r|\n)(.*)\*/|\*/)`mU";
// matches[1] - return value from function prototype
// matches[2] - rest of prototype starting with function name to sort by
// matches[3] - description with newlines to be stripped and identation to be added
// prototype blocks
foreach ($parsefiles as $key => $file) {
$file_contents = file_get_contents($file);
$m = preg_match_all($proto_regex, $file_contents, $matches);
if ($m) {
// output source file name
echo preg_replace("|^[./]+|", "# ", $file)."\n";
$preturn = array();
$prest = array();
$pdesc = array();
foreach($matches[1] as $mk => $mv) {
$preturn[] = $matches[1][$mk];
$prest[] = $matches[2][$mk];
$pdesc[] = " " . preg_replace("`\s+`msU", " ", trim($matches[3][$mk]));
}
array_multisort($prest, $preturn, $pdesc);
foreach($preturn as $k => $v) {
echo $preturn[$k] . " " . $prest[$k] . " \n" . $pdesc[$k] . " \n";
}
} else {
unset($parsefiles[$key]);
}
}
/****[ Original algorithm of genfunclist.sh ] *****/
# | Authors: Gabor Hoitsy <goba@php.net> |
/*
for i in `find $1 -name "*.[ch]" -print -o -name "*.ec" -print | xargs egrep -li "\{\{\{ proto" | sort` ; do
echo $i | sed -e "s|$1|# php-src|"
$awkprog -f $awkscript < $i | sort +1 | $awkprog -F "---" '{ print $1; print $2; }' | sed -e's/^[[:space:]]+//' -e's/[[:space:]]+/ /'
done
if test -f $1/language-scanner.lex # only in PHP3
then
$awkprog -f funcsummary.awk < $1/language-scanner.lex | sort +1 | $awkprog -F "---" '{ print $1; print $2; }'
fi
*/
/****[ Original funcsummary.awk ] *****/
//
///^[[:space:]]*\/\*[[:space:]]*\{\{\{[[:space:]]*proto/ {
// split($0,proto,"proto[[:space:]]+|\\*/[[:space:]]*$");
// parse=1;
// same=1;
// lc=0;
//}
///\*\// {
// if(parse) {
// lines="";
// for(i=0;i<lc;i++) {
// lines = sprintf("%s %s ",lines,line[i]);
// }
// if(!same) {
// split($0,temp,"\\*/[[:space:]]*$");
// lines = sprintf("%s %s ",lines,temp[1]);
// }
// printf("%s --- %s\n",proto[2],lines);
// parse=0;
// }
// next;
//}
//{
// if(parse && !same) {
// split($0,temp,"\\*/[[:space:]]*$");
// line[lc++]=temp[1];
//
// }
// same=0;
//}
?>
|