*** empty log message ***
[chuck-blob.git] / exile / ugen_doc_xhtml.pl
blob07ad1d1fa1683b06cd3ce89a5817e7b1927fee17
1 #! /usr/bin/perl
4 sub open_ugen;
5 sub close_ugen;
6 sub open_flist;
7 sub close_flist;
8 sub print_extends;
9 sub print_function;
11 sub cleanup;
13 $ugen_open = 0;
14 $flist_open = 0;
15 $ugen_name = "";
17 sub open_namespace;
18 sub close_namespace;
19 sub open_export;
20 sub close_export;
21 sub add_param;
23 $namespace_open = 0;
24 $namespace_name ="";
25 $export_open = 0;
26 $export_name ="";
27 @export_comments = ();
28 $export_param_num = 0;
29 $export_is_function = 0;
31 %library_notes = (
32 'stk' => '(STK Import)'
36 $lib_src = "";
37 $lib_note = "";
39 $doc_class_name = "";
40 $doc_info_open = 0;
41 %doc_brief;
42 %doc_data;
44 $example_open = 0;
45 $example_ready = 0;
46 @example_lines = ();
48 sub print_example;
49 sub print_section;
51 foreach ( @ARGV ) {
53 $file = $_;
56 open ( SOURCE , $file ) || printf " cannot open file \n";
57 while ( <SOURCE> ) {
59 if ( /\/\*\! \\class\s*(\w*)/ ) {
60 $doc_info_open = 1;
61 $doc_class_name = $1;
62 #print "dox for $1\n";
63 $doc_brief{$doc_class_name} = "";
64 $doc_data{$doc_class_name} = "";
66 elsif ( $doc_info_open ) {
67 if ( /(.*)\*\// ) {
68 $doc_data{$doc_class_name} .= $1;
69 $doc_info_open = 0;
70 $doc_class_name = "";
72 elsif ( /\\brief (.*)/ ) {
73 $doc_brief{$doc_class_name} = $1;
75 else {
76 $doc_data{$doc_class_name} .= $_;
81 close ( SOURCE );
83 $outfile = substr ( $file, rindex($file, "/" ) + 1 );
84 $outfile =~ s/(\.cpp|\.c)/.html/;
85 print "file: $file : generating documentation in $outfile\n";
86 open ( HTML , ">" , "$outfile" ) || die "outfile could not be opened";
87 print HTML "
88 <html>
89 <head>
90 <title>chuck documentation</title>
91 <link rel=\"stylesheet\" type=\"text/css\" href=\"ckdoc.css\">
92 </head>
93 <body>
94 <div class=\"library\">
95 <div class=\"exportlist\">
98 open ( SOURCE , $file ) || printf " cannot open file \n";
99 while ( <SOURCE> ) {
101 if ( /\/\*\! \\example\s*(\w*)/ ) {
102 $example_open = 1;
103 @example_lines = ();
105 elsif ( $example_open ) {
106 if ( /(.*)\*\// ) {
107 push ( @example_lines, $1 );
108 $example_open = 0;
109 $example_ready = 1;
110 if ( !$export_open && !$ugen_open ) {
111 print_example();
114 else {
115 push ( @example_lines, $_ );
120 # if ( /\/\/\!\s*\\(section\w*)\s+(.*)$/ ) { //in comment case
122 if ( /\/\/\!\s*(.*)$/ ) {
123 #comments
124 my $comm = $1;
125 if ( $comm =~ /\\(section\w*)\s+(.*)/ ) {
126 print_section ( $2, $1 );
128 else {
129 push @comments, $comm;
133 if ( /DLL_QUERY\s+(\w*)_query/ ) {
134 $lib_src = $1;
135 $lib_note = $library_notes{$1};
136 @comments = ();
138 if ( /QUERY->ugen_add\s*\(\s*(.*?)\)/ ) {
139 open_ugen ( split ( /[\s,\"]+/ , $1 ) , @comments);
140 @comments = ();
142 if ( /QUERY->ugen_extends\s*\(\s*(.*?)\)/ ) {
143 print_extends ( split ( /[\s,\"]+/ , $1 ) , @comments);
144 @comments = ();
146 if ( /QUERY->ugen_ctrl\s*\(\s*(.*?)\)/ ) {
147 print_function ( split ( /[\s,\"]+/ , $1 ) , @comments);
148 @comments = ();
151 if ( /QUERY->set_name\s*\(\s*(.*?)\)/ ) {
152 open_namespace ( split ( /[\s,\"]+/ , $1 ) , @comments);
153 @comments = ();
157 if ( /^\s*QUERY->add_export\s*\(\s*(.*?)\)/ ) {
158 open_export ( split ( /[\s,\"]+/ , $1 ) , @comments);
159 @comments = ();
162 if ( /^\s*QUERY->add_param\s*\(\s*(.*?)\)/ ) {
163 add_param ( split ( /[\s,\"]+/ , $1 ) , @comments);
164 @comments = ();
167 #stupid lazy shortcuts in ckx libs
168 if ( /^\s*(\w+)_CKADDEXPORT\s*\(\s*(.*?)\)/ ) {
169 my ( $type, $name ) = split ( /[\s,\"]+/ , $2 );
170 @stdargs = ( "QUERY", $type, $name, lc($1).$name."_impl", "TRUE");
171 open_export ( @stdargs , @comments);
172 @comments = ();
175 #more laziness biting me in the ass
176 if ( /^\s*(\w+)_CKADDPARAM\s*\(\s*(.*?)\)/ ) {
177 @expargs = split ( /[\s,\"]+/ , $2 );
178 @stdargs = ( "QUERY", @expargs );
179 add_param ( @stdargs , @comments);
180 @comments = ();
185 cleanup();
186 close ( SOURCE );
187 print HTML "\n</div></div></body></html>";
188 close ( HTML );
194 sub open_ugen {
195 my ( $query, $name, $arg2, @comments ) = @_;
196 cleanup();
197 $ugen_name = $name;
199 $brief = $doc_brief{$ugen_name};
200 $data = $doc_data{$ugen_name};
201 if ( $brief ne "" ) { @comments = ( $brief, @comments ); }
204 print HTML "
205 <div class=\"ugen\">
206 <h3><a class=\"heading\" name=\"$ugen_name\">[ugen]</a>: <span class=\"name\">$ugen_name</span> $lib_note</h3>
207 <div class=\"comments\"><ul>
209 foreach ( @comments ) { print HTML "<li> $_</li>\n"; }
210 print HTML "</ul></div>\n";
211 if ( $data ne "" ) { print HTML "<pre class=\"data\">$data</pre>"; }
212 $ugen_open = 1;
215 sub close_ugen {
217 if ( $flist_open ) { close_flist(); }
218 if ( $example_ready ) { print_example(); }
220 print HTML "</div>\n";
222 $ugen_name = "";
223 $ugen_open = 0;
226 sub print_extends {
227 my ( $query, $parent ) = @_;
228 print HTML "<h4>extends <b><a href=\"#$parent\">$parent</a></b></h4>";
232 sub cleanup {
233 if ( $ugen_open == 1) { close_ugen(); }
234 if ( $export_open == 1) { close_export(); }
237 sub open_flist {
239 print HTML "
240 <div class=\"members\">
241 [ctrl param]:
242 <ul>";
243 $flist_open = 1;
246 sub close_flist {
247 print HTML "</ul></div>\n";
248 $flist_open = 0;
251 sub print_function {
252 my ($query, $ctor, $cget, $type, $name, @comments) = @_;
253 if ( !$flist_open ) { open_flist(); }
255 $comm = join ( "<br />", @comments);
256 $access = "";
258 if ( $ctor ne "NULL" && $cget ne "NULL" ) { $access = "READ/WRITE"; }
259 elsif ( $ctor ne "NULL" ) { $access = "WRITE only" }
260 elsif ( $cget ne "NULL" ) { $access = "READ only" }
261 print HTML "<li><b>.$name</b> - ( $type , $access ) - <span class=\"comment\">$comm</span></li>\n";
262 # print HTML "---member $type $name $ctor $cget -- $comm\n";
267 sub print_example {
268 print HTML "
269 <div class=\"example\">[example]<br />
270 <div class=\"code\">";
271 foreach ( @example_lines ) { print HTML substr($_,5);}
272 print HTML "</div></div>";
273 @example_lines = ();
274 $example_ready = 0;
277 sub print_section {
278 cleanup(); #sections end current class...
279 my ( $name, $type ) = @_;
280 print HTML "<div class=\"$type\">$name</div>";
283 sub open_namespace {
284 my ( $query, $name ) = @_;
285 $namespace_open = 1;
288 sub close_namespace {
289 $namespace_open = 0;
292 sub open_export {
293 my ( $query, $type, $name, $func, $flag, @comments ) = @_;
294 cleanup();
295 @export_comments=@comments;
297 if ( $flag eq "TRUE" ) {
298 print HTML "<div class=\"export\"><h3>
299 <a class=\"heading\" name=\"$name\">[function]</a>:
300 $type <b class=\"name\">$name</b> ( ";
301 $export_is_function = 1;
304 else {
305 print HTML "<div class=\"export\"><h3>
306 <a class=\"heading\" name=\"$name\">[constant]</a>:
307 $type <b class=\"name\">$name</b></h3>\n";
308 $export_is_function = 0;
310 $export_param_num = 0;
311 $export_open = 1;
314 sub close_export {
316 if ( $export_is_function == 1 ) { print HTML " );</h3>\n"; }
317 if ( scalar( @export_comments ) > 0 ) {
318 print HTML "<div class=\"comments\"><ul>\n";
319 foreach ( @export_comments ) { print HTML "<li>$_</li>\n"; }
320 print HTML "</ul></div>\n";
322 if ( $example_ready ) { print_example(); }
323 print HTML "</div>\n";
324 $export_open = 0;
329 sub add_param {
330 my ($query, $type, $name, @comments ) = @_;
331 push ( @export_comments, @comments );
332 $sep = "";
333 if ( $export_param_num ) { $sep = ", "; }
334 print HTML "$sep$type <b class=\"arg\">$name</b>";
335 $export_param_num ++;