From 20fb47ec778abe215ca69692434ff753596319e6 Mon Sep 17 00:00:00 2001 From: Maurus Cuelenaere Date: Mon, 6 Oct 2008 22:19:54 +0000 Subject: Commit FS#9462: an semi-automatic plugin API documentation generator git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18722 a1c6a512-1295-4272-9138-f99709370657 --- utils/rockbox_api/functions.php | 337 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100755 utils/rockbox_api/functions.php (limited to 'utils/rockbox_api/functions.php') diff --git a/utils/rockbox_api/functions.php b/utils/rockbox_api/functions.php new file mode 100755 index 0000000..0f34fc6 --- /dev/null +++ b/utils/rockbox_api/functions.php @@ -0,0 +1,337 @@ + $line) + { + if(trim($line) == "struct plugin_api {") + { + $text = explode("\n", $text); + $text = array_slice($text, $line_nr+1); + break; + } + } + + foreach($text as $line_nr => $line) + { + if(trim($line) == "};") + { + $text = array_slice($text, 0, $line_nr-1); + break; + } + } + /* Locating done */ + + /* Clean up stuff a bit .. */ + for($i=0; $i $tmp, "cond" => "(".implode(") && (", $conditions).")", "group" => $group); + } + } + + uksort($ret, "func_sort"); + + return $ret; +} + +function parse_documentation($data) +{ + $data = explode("\n", $data); + + $ret = array(); + $cur_func = ""; + foreach($data as $line) + { + if(substr($line, 0, 1) == "#") + continue; + else if(substr($line, 0, 4) == " ") + { + $tmp = trim($line); + if(strpos($tmp, " ") !== false) + $tmp = array(substr($tmp, 1, strpos($tmp, " ")-1), substr($tmp, strpos($tmp, " ")) ); + else + $tmp = array(substr($tmp, 1), ""); + + $ret[$cur_func][$tmp[0]][] = $tmp[1]; + } + else if(strlen($line) == 0) + continue; + else + $cur_func = substr($line, 0); + } + + $_ret = array(); + foreach($ret as $func => $el) + { + if(isset($el["group"])) + $group = trim($el["group"][0]); + else + $group = "misc"; + + $_ret[$group][$func] = $el; + } + + return $_ret; +} + +function get_func($func) +{ + $func = preg_replace('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', '', $func); + if(strpos($func, "PREFIX") !== false) + $func = substr($func, 0, strrpos($func, "(")); + else if(strpos($func, "(") !== false) + $func = substr($func, 0, strpos($func, "(")); + + return $func; +} + +function get_args($func) +{ + /* Check if this _is_ a function */ + if(strpos($func, "(") === false) + return array(); + + /* Get rid of return value */ + $func = preg_replace('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', '', $func); + + /* Get rid of function name */ + if(strpos($func, "(") !== false) + $func = substr($func, strpos($func, "(")); + + /* Get rid of ATTRIBUTE_PRINTF */ + if(strpos($func, "ATTRIBUTE_PRINTF") !== false) + $func = substr($func, 0, strpos($func, "ATTRIBUTE_PRINTF")); + + $level = 0; + $args = array(); + $buffer = ""; + for($i=0; $i 1) + $buffer .= "("; + break; + case ")": + $level--; + if($level > 0) + { + $buffer .= ")"; + break; + } + case ",": + if($level <= 1) + { + if(strpos($buffer, "(,") !== false) + { + $tmp = array(); + preg_match_all('/[^ ]*, [^)]*\)/', $buffer, $tmp); + $tmp = $tmp[0]; + foreach($tmp as $el) + { + if(strlen($el) > 0) + $args[] = trim($el); + } + $tmp = preg_replace('/[^ ]*, [^)]*\)/', '', $buffer); + $args[] = trim($tmp); + } + else + $args[] = trim($buffer); + $buffer = ""; + } + else + $buffer .= ","; + break; + default: + $buffer .= $func{$i}; + break; + } + } + + /* Filter out void */ + for($i=0; $i\1', $data); + $data = ereg_replace('\[W\[([^#\[]*)([^\[]*)\]\]', '\1', $data); + $data = ereg_replace('\[S\[([^\[]*)\]\]', '\1', $data); + $data = ereg_replace('\[F\[([^\[]*)\]\]', '\1', $data); + $data = ereg_replace('\[\[([^#\[]*)([^\[]*)\]\]', '\1', $data); + $data = str_replace("%BR%", "
", $data); + $data = nl2br($data); + + return $data; +} +?> -- cgit v1.1