2 $svn = "http://svn.rockbox.org/viewvc.cgi/trunk/";
3 $wiki = "http://www.rockbox.org/wiki/";
5 function func_sort($a, $b)
7 $a = preg_replace('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', '', $a);
8 $b = preg_replace('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', '', $b);
9 return strnatcasecmp($a, $b);
16 $mypath = $_SERVER['SCRIPT_FILENAME'];
17 $mypath = substr($mypath, 0, strrpos($mypath, "/"))."/";
19 $text = file_get_contents($mypath."../../apps/plugin.h");
21 $text = str_replace(array("\r\n", "\r"), "\n", $text);
23 /* Located plugin_api struct */
24 foreach(explode("\n", $text) as $line_nr => $line)
26 if(trim($line) == "struct plugin_api {")
28 $text = explode("\n", $text);
29 $text = array_slice($text, $line_nr+
1);
34 foreach($text as $line_nr => $line)
36 if(trim($line) == "};")
38 $text = array_slice($text, 0, $line_nr-1);
44 /* Clean up stuff a bit .. */
45 for($i=0; $i<count($text); $i++
)
46 $text[$i] = trim($text[$i]);
49 /* Fake preprocesser */
52 $conditions = array();
55 for($i=0; $i<count($text); $i++
)
57 $tmp = trim($text[$i]);
59 if(substr($tmp, 0, 1) == '#')
61 $tmp = trim(substr($tmp, 1));
62 if(strtolower(substr($tmp, 0, 2)) == "if")
64 if(strtolower(substr($tmp, 2, 3)) == "def")
65 $conditions[] = "defined(".substr($tmp, 6).")";
66 else if(strtolower(substr($tmp, 2, 4)) == "ndef")
67 $conditions[] = "!defined(".substr($tmp, 7).")";
70 while(substr($tmp, strlen($tmp)-1, 1) == "\\")
73 $tmp = substr($tmp, 0, strlen($tmp)-1)." ".trim($text[$i]);
76 $conditions[] = substr($tmp, 3);
79 else if(strtolower(substr($tmp, 0, 4)) == "elif")
81 while(substr($tmp, strlen($tmp)-1, 1) == "\\")
84 $tmp = substr($tmp, 0, strlen($tmp)-1)." ".trim($text[$i]);
86 $conditions[count($conditions)-1] = substr($tmp, 5);
88 else if(strtolower(substr($tmp, 0, 4)) == "else")
89 $conditions[count($conditions)-1] = "!( ".$conditions[count($conditions)-1]." )";
90 else if(strtolower(substr($tmp, 0, 5)) == "endif")
91 array_pop($conditions);
93 else if(strlen($tmp) == 0)
95 else if(substr($tmp, 0, 2) == "/*")
97 while(strpos($tmp, "*/") === false)
100 $tmp .= " ".trim($text[$i]);
102 $group = explode("/*", trim($tmp));
103 $group = explode("*/", $group[1]);
104 $group = trim($group[0]);
108 while(strpos($tmp, ";") === false)
111 $tmp .= " ".trim($text[$i]);
114 /* Replace those (*func)(int args) with func(int args) */
115 $tmp = preg_replace('/\(\*([^\)]*)\)/i', '\1', $tmp, 1);
116 $tmp = substr($tmp, 0, strlen($tmp)-1);
117 $ret[$tmp] = array("func" => $tmp, "cond" => "(".implode(") && (", $conditions).")", "group" => $group);
121 uksort($ret, "func_sort");
126 function parse_documentation($data)
128 $data = explode("\n", $data);
132 foreach($data as $line)
134 if(substr($line, 0, 1) == "#")
136 else if(substr($line, 0, 4) == " ")
139 if(strpos($tmp, " ") !== false)
140 $tmp = array(substr($tmp, 1, strpos($tmp, " ")-1), substr($tmp, strpos($tmp, " ")) );
142 $tmp = array(substr($tmp, 1), "");
144 $ret[$cur_func][$tmp[0]][] = $tmp[1];
146 else if(strlen($line) == 0)
149 $cur_func = substr($line, 0);
153 foreach($ret as $func => $el)
155 if(isset($el["group"]))
156 $group = trim($el["group"][0]);
160 $_ret[$group][$func] = $el;
166 function get_func($func)
168 $func = preg_replace('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', '', $func);
169 if(strpos($func, "PREFIX") !== false)
170 $func = substr($func, 0, strrpos($func, "("));
171 else if(strpos($func, "(") !== false)
172 $func = substr($func, 0, strpos($func, "("));
177 function get_args($func)
179 /* Check if this _is_ a function */
180 if(strpos($func, "(") === false)
183 /* Get rid of return value */
184 $func = preg_replace('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', '', $func);
186 /* Get rid of function name */
187 if(strpos($func, "(") !== false)
188 $func = substr($func, strpos($func, "("));
190 /* Get rid of ATTRIBUTE_PRINTF */
191 if(strpos($func, "ATTRIBUTE_PRINTF") !== false)
192 $func = substr($func, 0, strpos($func, "ATTRIBUTE_PRINTF"));
197 for($i=0; $i<strlen($func); $i++
)
216 if(strpos($buffer, "(,") !== false)
219 preg_match_all('/[^ ]*, [^)]*\)/', $buffer, $tmp);
226 $tmp = preg_replace('/[^ ]*, [^)]*\)/', '', $buffer);
227 $args[] = trim($tmp);
230 $args[] = trim($buffer);
237 $buffer .= $func{$i};
242 /* Filter out void */
243 for($i=0; $i<count($args); $i++
)
245 if($args[$i] == "void")
252 function get_return($func)
255 preg_match('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', $func, $ret);
257 if(trim($ret[0]) == "void")
260 return trim($ret[0]);
263 function split_var($var)
265 if(strpos($var, "(,") !== false)
267 $p1 = substr($var, 0, strrpos($var, " "));
268 $p2 = substr($var, strrpos($var, " "));
269 $p2 = substr($p2, 0, strlen($p2)-1);
271 else if(strpos($var, "(*") !== false)
274 preg_match('/\(\*\w*\)/', $var, $p2);
277 $p1 = substr($var, strpos($var, $p2));
278 $p2 = substr($p2, 2, strlen($p2)-3);
282 $p1 = substr($var, 0, strrpos($var, " "));
283 $p2 = substr($var, strrpos($var, " "));
286 if(strpos($p2, "*") !== false)
288 for($i=0; $i<substr_count($p2, "*"); $i++
)
290 $p2 = str_replace("*", "", $p2);
293 return array(trim($p1), trim($p2));
296 function _simplify($text)
298 $text = ereg_replace('\(!\( (.*)[ ]?\)\)', '!\1', $text);
299 $text = ereg_replace('\(\(([^ ])\)\)', '\1', $text);
303 function clean_func($func)
305 $func = str_replace(array(" ", " "), " ", $func);
306 $func = str_replace(" ", " ", $func);
310 function do_see_markup($data)
313 foreach($data as $el)
317 if(substr($el, 0, 1) != "[")
318 $ret[] = do_markup("[F[".$el."]]");
320 $ret[] = do_markup($el);
323 return implode(" & ", $ret);
326 function do_markup($data)
330 $data = ereg_replace('=([^=]*)=', '<code>\1</code>', $data);
331 $data = ereg_replace('\[W\[([^#\[]*)([^\[]*)\]\]', '<a href="'.$wiki.'\1\2">\1</a>', $data);
332 $data = ereg_replace('\[S\[([^\[]*)\]\]', '<a href="'.$svn.'\1?content-type=text%2Fplain">\1</a>', $data);
333 $data = ereg_replace('\[F\[([^\[]*)\]\]', '<a href="#\1">\1</a>', $data);
334 $data = ereg_replace('\[\[([^#\[]*)([^\[]*)\]\]', '<a href="\1\2">\1</a>', $data);
335 $data = str_replace("%BR%", "<br />", $data);
336 $data = nl2br($data);
341 function get_tpl_part($search, $haystack)
344 ereg($search[0].".*".$search[1], $haystack, $tpl);
345 return str_replace(array($search[0], $search[1]), "", $tpl[0]);