#! /usr/bin/php %s\n", highlight_string($m[1], true)); } function mf($f, &$m) { return preg_match_all( '/\/\* *\{\{\{ *proto (.*?)(\n|$)(.*?)PHP_(?:FUNCTION|METHOD)\((.*?)\)/s', file_get_contents($f), $m); } function ff($t) { $t = preg_replace('/^ \* /m', '', trim($t, "*/ \n")); $t = preg_replace_callback('/(\<\?php.*?\?\>)/s', 'hl', $t); $t = str_replace("
\n
\n", "

\n

", nl2br(preg_replace('/\n *\* */', "\n", $t))); $t = preg_replace('/(\
\n)+\(\
\n)+/', '

', $t);
    $t = preg_replace('/(\
\n)+\<\/pre\>(\
\n)+/', '

', $t); $t = str_replace("
\n", "", $t); return sprintf('

%s

', ltrim($t, ' *')); } function e($s) { $a = func_get_args(); array_unshift($a, STDERR); call_user_func_array('fprintf', $a); } $preface = <<<_PREFACE Function Summary of ext/%s _PREFACE; $footer = <<<_FOOTER

Generated at: %s

_FOOTER; if ($_SERVER['argc'] < 2) { die("Usage: {$_SERVER['argv'][0]} [ ...]\n"); } $TOC = array(); printf($preface, basename(getcwd())); $seen = array(); foreach (array_slice($_SERVER['argv'], 1) as $fp) { foreach (glob($fp) as $f) { if (isset($seen[$f])) { continue; } else { $seen[$f] = true; } if (mf($f, $m)) { $c = null; e("\nAnalyzing %s\n", basename($f)); printf("

%s

\n", basename($f), basename($f)); foreach ($m[1] as $i => $p) { e("Documenting $p\n"); if ($o = preg_match('/^(.*), (.*)$/', $m[4][$i], $n)) { if ($n[1] != $c) { $c = $n[1]; printf("

%s

\n", $n[1], $n[1]); } $TOC[basename($f)][$n[1]][$n[2]] = $n[1].'::'.$n[2].'()'; printf("%s\n", 3, $n[1].'_'.$n[2], $p, 3); } else { $TOC[basename($f)][$m[4][$i]] = $m[4][$i].'()'; printf("%s\n", 2, $m[4][$i], $p, 2); } print ff($m[3][$i]) ."\n"; } print "
\n"; } } } printf("
Table of Contents\n
    \n"); foreach ($TOC as $file => $f) { printf("
  • %s\n
      \n", $file, $file); foreach ($f as $cof => $met) { if (is_array($met)) { foreach ($met as $id => $m) { printf("
    • %s
    • \n", $cof, $id, $m); } } else { printf("
    • %s\n", $cof, $cof); } printf("
    • \n"); } printf("
    \n
  • \n"); } printf("
\n
\n"); printf($footer, date('r')); e("\nDone\n"); ?>