blob: 5fb46c9d581515bf1984f15e208e9b47fa34777e [file] [log] [blame]
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +00001#!/usr/bin/php
2<?
3require_once("functions.php");
4
5$input = file_get_contents($argv[1]);
6
7$input = parse_documentation($input);
8
Maurus Cuelenaeree7ea23b2008-10-09 11:48:26 +00009/* Format input */
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000010foreach($input as $rootname => $rootel)
11{
12 foreach($rootel as $name => $el)
13 $input[$name] = $el;
14 unset($input[$rootname]);
15}
16
17$new = get_newest();
18
Maurus Cuelenaeree7ea23b2008-10-09 11:48:26 +000019/* Format new */
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000020foreach($new as $name => $el)
21{
22 unset($new[$name]);
23 $name = clean_func($el["func"]);
24
25 $new[$name] = array(
26 "group" => array($el["group"]),
27 "description" => array("")
28 );
29
30 if(strlen($el["cond"]) > 2)
31 $new[$name]["conditions"][0] = $el["cond"];
32
33 $args = get_args($el["func"]);
34 if(count($args) > 0)
35 {
36 foreach($args as $n => $arg)
37 {
38 $tmp = split_var($arg);
39 $args[$n] = $tmp[1];
40 }
41 $new[$name]["param"] = $args;
42 }
43
44 if(get_return($el["func"]) !== false)
45 $new[$name]["return"][0] = "";
46}
47
Maurus Cuelenaeree7ea23b2008-10-09 11:48:26 +000048/* Compare and merge both */
49$merged = array();
50foreach($new as $name => $el)
51{
52 if(isset($input[$name]))
53 {
54 $merged[$name] = $input[$name];
55 $merged[$name]["conditions"] = $new[$name]["conditions"];
56
57 if(strlen($el["group"][0]) > 0)
58 $merged[$name]["group"] = $el["group"];
59
60 if(isset($el["param"]))
61 {
62 foreach($el["param"] as $nr => $parel)
63 {
64 if($parel != $input[$name]["param"][$nr])
65 {
66 $param = trim($parel);
67 $p1 = substr($param, 0, strpos($param, " "));
68
69 $param = trim($input[$name]["param"][$nr]);
70 $p2 = substr($param, strpos($param, " "));
71 $merged[$name]["params"][] = $p1." ".$p2." [AUTO-ADDED]";
72 }
73 else
74 $merged[$name]["params"][] = $parel;
75 }
76 }
77
78 if(!isset($el["return"]) && isset($merged[$name]["return"]))
79 unset($merged[$name]["return"]);
80
81 unset($input[$name]);
82 }
83 else
84 $merged[$name] = $el;
85}
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000086
Maurus Cuelenaeree7ea23b2008-10-09 11:48:26 +000087/* Now to the rest of input */
88foreach($input as $name => $el)
89 $merged[$name." [DEPRECATED]"] = $el;
Maurus Cuelenaere20fb47e2008-10-06 22:19:54 +000090
91uksort($merged, "func_sort");
92
93echo '# Auto generated documentation by Rockbox plugin API generator v2'."\n";
94echo '# Made by Maurus Cuelenaere'."\n";
95echo <<<MOO
96# __________ __ ___.
97# Open \______ \ ____ ____ | | _\_ |__ _______ ___
98# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
99# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
100# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
101# \/ \/ \/ \/ \/
102# \$Id$
103#
104# Generated from $svn\x61pps/plugin.h
105#
106# Format:
107# \\group memory and strings
108# \\conditions defined(HAVE_BACKLIGHT)
109# \\param fmt
110# \\return
111# \\description
112# \\see func1 func2 [S[apps/plugin.c]]
113#
114# Markup:
115# [W[wiki url]]
116# [S[svn url]]
117# [F[function]]
118# [[url]]
119# %BR%
120# =code=
121
122MOO;
123
124foreach($merged as $func => $line)
125{
126 echo "\n".clean_func($func)."\n";
127
128 if(strlen($line["group"]) > 0)
129 echo " \\group ".trim($line["group"][0])."\n";
130
131 if(strlen($line["conditions"]) > 2)
132 echo " \\conditions ".trim(_simplify($line["conditions"][0]))."\n";
133
134 if(isset($line["param"]))
135 {
136 foreach($line["param"] as $param)
137 {
138 if($param != "...")
139 echo " \\param ".trim($param)."\n";
140 }
141 }
142
143 if(isset($line["return"]))
144 {
145 if(trim($line["return"]) == "")
146 echo " \\return\n";
147 else
148 echo " \\return ".trim($line["return"][0])."\n";
149 }
150
151 if(trim($line["description"]) == "")
152 echo " \\description\n";
153 else
154 echo " \\description ".trim($line["description"][0])."\n";
155
156 if(isset($line["see"]))
157 echo " \\see ".trim($line["see"][0])."\n";
158}
159
160echo "\n# END\n";
161?>