Define LCD dpi for n900, n8xx and the pandora
[maemo-rb.git] / utils / rockbox_api / functions.php
blobd66caa1b29797322e66141c9159fd00cec29ba52
1 <?
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);
12 function get_newest()
14 global $svn;
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);
30 break;
34 foreach($text as $line_nr => $line)
36 if(trim($line) == "};")
38 $text = array_slice($text, 0, $line_nr-1);
39 break;
42 /* Locating done */
44 /* Clean up stuff a bit .. */
45 for($i=0; $i<count($text); $i++)
46 $text[$i] = trim($text[$i]);
49 /* Fake preprocesser */
50 $ret = array();
51 $_groups = array();
52 $conditions = array();
53 $strip_next = 0;
54 $group = "";
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).")";
68 else
70 while(substr($tmp, strlen($tmp)-1, 1) == "\\")
72 $i++;
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) == "\\")
83 $i++;
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)
94 $group = "";
95 else if(substr($tmp, 0, 2) == "/*")
97 while(strpos($tmp, "*/") === false)
99 $i++;
100 $tmp .= " ".trim($text[$i]);
102 $group = explode("/*", trim($tmp));
103 $group = explode("*/", $group[1]);
104 $group = trim($group[0]);
106 else
108 while(strpos($tmp, ";") === false)
110 $i++;
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");
123 return $ret;
126 function parse_documentation($data)
128 $data = explode("\n", $data);
130 $ret = array();
131 $cur_func = "";
132 foreach($data as $line)
134 if(substr($line, 0, 1) == "#")
135 continue;
136 else if(substr($line, 0, 4) == " ")
138 $tmp = trim($line);
139 if(strpos($tmp, " ") !== false)
140 $tmp = array(substr($tmp, 1, strpos($tmp, " ")-1), substr($tmp, strpos($tmp, " ")) );
141 else
142 $tmp = array(substr($tmp, 1), "");
144 $ret[$cur_func][$tmp[0]][] = $tmp[1];
146 else if(strlen($line) == 0)
147 continue;
148 else
149 $cur_func = substr($line, 0);
152 $_ret = array();
153 foreach($ret as $func => $el)
155 if(isset($el["group"]))
156 $group = trim($el["group"][0]);
157 else
158 $group = "misc";
160 $_ret[$group][$func] = $el;
163 return $_ret;
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, "("));
174 return $func;
177 function get_args($func)
179 /* Check if this _is_ a function */
180 if(strpos($func, "(") === false)
181 return array();
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"));
194 $level = 0;
195 $args = array();
196 $buffer = "";
197 for($i=0; $i<strlen($func); $i++)
199 switch($func{$i})
201 case "(":
202 $level++;
203 if($level > 1)
204 $buffer .= "(";
205 break;
206 case ")":
207 $level--;
208 if($level > 0)
210 $buffer .= ")";
211 break;
213 case ",":
214 if($level <= 1)
216 if(strpos($buffer, "(,") !== false)
218 $tmp = array();
219 preg_match_all('/[^ ]*, [^)]*\)/', $buffer, $tmp);
220 $tmp = $tmp[0];
221 foreach($tmp as $el)
223 if(strlen($el) > 0)
224 $args[] = trim($el);
226 $tmp = preg_replace('/[^ ]*, [^)]*\)/', '', $buffer);
227 $args[] = trim($tmp);
229 else
230 $args[] = trim($buffer);
231 $buffer = "";
233 else
234 $buffer .= ",";
235 break;
236 default:
237 $buffer .= $func{$i};
238 break;
242 /* Filter out void */
243 for($i=0; $i<count($args); $i++)
245 if($args[$i] == "void")
246 unset($args[$i]);
249 return $args;
252 function get_return($func)
254 $ret = array();
255 preg_match('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', $func, $ret);
257 if(trim($ret[0]) == "void")
258 return false;
259 else
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)
273 $p2 = array();
274 preg_match('/\(\*\w*\)/', $var, $p2);
275 $p2 = $p2[0];
277 $p1 = substr($var, strpos($var, $p2));
278 $p2 = substr($p2, 2, strlen($p2)-3);
280 else
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++)
289 $p1 .= "*";
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);
300 return $text;
303 function clean_func($func)
305 $func = str_replace(array(" ", " "), " ", $func);
306 $func = str_replace(" ", " ", $func);
307 return $func;
310 function do_see_markup($data)
312 $ret = array();
313 foreach($data as $el)
315 $el = trim($el);
317 if(substr($el, 0, 1) != "[")
318 $ret[] = do_markup("[F[".$el."]]");
319 else
320 $ret[] = do_markup($el);
323 return implode(" &amp; ", $ret);
326 function do_markup($data)
328 global $svn, $wiki;
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);
338 return $data;
341 function get_tpl_part($search, $haystack)
343 $tpl = array();
344 ereg($search[0].".*".$search[1], $haystack, $tpl);
345 return str_replace(array($search[0], $search[1]), "", $tpl[0]);