Menu

[r1]: / trunk / Source / Documentation / Scripts / generateHTML.pl  Maximize  Restore  History

Download this file

525 lines (428 with data), 24.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
#!/usr/bin/perl -w
use strict;
use DBI;
require DBD::SQLite;
use Data::Dumper;
#use POSIX;
#use IO::Handle;
#STDERR->autoflush(1);
#BEGIN { $diagnostics::PRETTY = 1 }
#use diagnostics;
my ($program_name, $script_name) = ($0, (defined($ENV{"SCRIPT_NAME"}) && defined($ENV{"SCRIPT_LINENO"})) ? "$ENV{'SCRIPT_NAME'}:$ENV{'SCRIPT_LINENO'}" : "");
$program_name =~ s/(.*?)\/?([^\/]+)$/$2/;
for my $env (qw(DOCUMENTATION_SQL_DATABASE_FILE GENERATED_HTML_DIR DOCUMENTATION_TEMPLATES_DIR)) {
if(!defined($ENV{$env})) { print("${script_name} error: $program_name: Environment variable $env not set.\n"); exit(1); }
}
my $dbh = DBI->connect("dbi:SQLite:dbname=$ENV{'DOCUMENTATION_SQL_DATABASE_FILE'}","","", { AutoCommit => 1, RaiseError => 1 });
$dbh->do("PRAGMA synchronous = OFF");
$dbh->do("ANALYZE");
$dbh->begin_work;
my %no_link;
for my $row (selectall_hash($dbh, "SELECT DISTINCT xref FROM xrefs WHERE href IS NULL")) { $no_link{$row->{'xref'}} = 1; }
print("Loading data...\n");
#$dbh->do("CREATE TEMP TABLE t_xtoc AS SELECT * FROM v_xtoc");
#print("Temp table built\n");
my %global_xtoc_cache = gen_xtoc_cache();
my (@rows, %toc, %tasks, %hdoc, %hdocFiles);
populate_tasks_html();
populate_const_html();
print("Creating toc.html\n");
create_toc_html();
for my $tocName (keys %{$global_xtoc_cache{'toc'}{'contentsForToc'}}) {
if(!exists($hdoc{$tocName}{'printedClassMethods'})) { $hdoc{$tocName}{'printedClassMethods'} = 0; }
if(!exists($hdoc{$tocName}{'printedInstanceMethods'})) { $hdoc{$tocName}{'printedInstanceMethods'} = 0; }
for my $tx (0 .. $#{$global_xtoc_cache{'toc'}{'contentsForToc'}{$tocName}}) {
my $at = $global_xtoc_cache{'toc'}{'contentsForToc'}{$tocName}[$tx];
if($at->{'table'} eq "objCMethods") {
if(!defined($hdoc{$tocName}{'methods'})) { $hdoc{$tocName}{'methods'} = ""; }
if($hdoc{$tocName}{'printedClassMethods'} == 0 && $at->{'linkText'} =~ /^\+/) {
$hdoc{$tocName}{'printedClassMethods'} = 1;
$hdoc{$tocName}{'methods'} .= "\n<h2>Class Methods</h2>\n\n";
} elsif($hdoc{$tocName}{'printedInstanceMethods'} == 0 && $at->{'linkText'} =~ /^\-/) {
$hdoc{$tocName}{'printedInstanceMethods'} = 1;
$hdoc{$tocName}{'methods'} .= "\n<h2>Instance Methods</h2>\n\n";
}
$hdoc{$tocName}{'methods'} .= meth_html($at->{'id'});
} elsif($at->{'table'} eq "prototypes") {
if(!exists($hdoc{$tocName}{'functions'})) { $hdoc{$tocName}{'functions'} = ""; }
$hdoc{$tocName}{'functions'} .= func_html($at->{'id'});
} elsif($at->{'table'} eq "typedefEnum") {
if(!exists($hdoc{$tocName}{'typedefs'})) { $hdoc{$tocName}{'typedefs'} = ""; }
$hdoc{$tocName}{'typedefs'} .= typedef_html($at->{'id'});
}
}
}
for my $atTocTemplate (keys %{$global_xtoc_cache{'toc'}{'contentsForToc'}}) {
my ($tocTmplFilename, $tocHtmlFilename, $HDOC_OUTPUT, $HDOC_TMPL, $hdoc_tmpl);
$tocTmplFilename = "$atTocTemplate.tmpl";
$tocHtmlFilename = "$atTocTemplate.html";
if (!(-e "$ENV{'DOCUMENTATION_TEMPLATES_DIR'}/$tocTmplFilename")) { printf("warning: The expected template '$tocTmplFilename' does not exist, skipping.\n"); next; }
print("Creating $tocHtmlFilename\n");
open($HDOC_TMPL, "<", "$ENV{'DOCUMENTATION_TEMPLATES_DIR'}/$tocTmplFilename"); read($HDOC_TMPL, $hdoc_tmpl, (stat($HDOC_TMPL))[7]); close($HDOC_TMPL);
if ($hdoc_tmpl !~ /\n$/s) { $hdoc_tmpl .= "\n"; }
$hdoc_tmpl =~ s/((?<!\\)[\%\$\@])/\\\\$1/g;
$hdoc_tmpl =~ s/(\\?)\\([\%\$\@])/$1$2/g;
my ($evald_hdoc, $in_eval_hdoc) = ("", '$evald_hdoc = <<END_OF_HDOC_TMPL;' . "\n" . $hdoc_tmpl . "END_OF_HDOC_TMPL\n");
eval($in_eval_hdoc);
$evald_hdoc = replaceLinks($evald_hdoc, $atTocTemplate);
open($HDOC_OUTPUT, ">", "$ENV{'GENERATED_HTML_DIR'}/$tocHtmlFilename"); print($HDOC_OUTPUT $evald_hdoc); close($HDOC_OUTPUT);
}
$dbh->commit;
$dbh->disconnect();
exit(0);
sub extractLinks {
my($text) = @_;
my %links;
while ($text =~ /\@link\s(.*?)\s(.*?)\s?\@\/link/sg) { my ($x, $y) = ($1, $1); $y =~ s?//apple_ref/\w+/\w+/(\w+)(\?:/.*)\??$1?; $links{$x} = $y; }
return(%links);
}
sub replaceLinks {
my($text, $className) = ($_[0], $_[1]);
my(%links) = extractLinks($text);
for my $atLink (sort keys %links) {
if ($no_link{$links{$atLink}} || $links{$atLink} eq $className) {
$text =~ s/\@link\s+$atLink\s+(.*?)\s?\@\/link/{
my $x=$1;
if($x !~ ?(\?i)<span class=\"code\">(.*\?)<\/span>?) { $x="<span class=\"code\">$x<\/span>"; }
$x
}/sge;
} else {
if (defined($global_xtoc_cache{'xref'}->{$links{$atLink}}{'href'})) {
$text =~ s/\@link\s+$atLink\s+(.*?)\s?\@\/link/{
my $x = $1;
my $linkClass = defined($global_xtoc_cache{'xref'}->{$links{$atLink}}{'class'}) ? $global_xtoc_cache{'xref'}->{$links{$atLink}}{'class'} : "";
my $classText = $linkClass ne "" ? " class=\"$linkClass\"" : "";
$x =~ s?<span class=\"$linkClass\">(.*\?)<\/span>?$1?sg;
$x = "<a href=\"$global_xtoc_cache{'xref'}->{$links{$atLink}}{'href'}\"$classText>$x<\/a>"
}/sge;
} else {
$text =~ s/\@link\s+$atLink\s+(.*?)\s?\@\/link/<span class="XXX code">$1<\/span>/sg;
}
}
}
return($text);
}
sub populate_const_html {
my ($const_html, $html, $declaredIn) = ("", "", "");
$html = "<h2>Constants</h2>\n\n";
$html .= "<div class=\"constants\">\n";
$html .= " <div class=\"declaration table\">\n";
for my $row (@{$global_xtoc_cache{'constantDefines'}}) {
if(!defined($row)) { next; }
my ($hdcid, $tags) = ($row->{'hdcid'}, $global_xtoc_cache{'tags'}[$row->{'hdcid'}]);
$html .= " <div class=\"row\"><div class=\"name cell\">" . add_xref($row->{'fullText'}) . "</div></div>\n";
$const_html .= " <div class=\"constant\">\n";
$const_html .= " <div class=\"identifier\"><a name=\"$global_xtoc_cache{'xref'}{$row->{'defineName'}}{'linkId'}\">$row->{'defineName'}</a></div>\n";
$const_html .= " <div class=\"text\">$tags->{'abstract'}</div>\n";
# $const_html .= " <div class=\"declared_in\"><div class=\"header\">Declared In</div>\n <div class=\"file\">$global_xtoc_cache{'headers'}[$row->{'hid'}]{'fileName'}</div>\n </div>\n";
# $const_html .= seealso_html($tags);
if (defined($tags->{'seealso'})) {
my(@seealso_html);
for my $s (@{$tags->{'seealso'}}) { push(@seealso_html, " <li>".$s."</li>"); }
$const_html .= " <div class=\"seealso\"><div class=\"header\">See Also</div>\n <ul>\n" . join("\n", @seealso_html) . "\n </ul>\n </div>\n";
}
$const_html .= " </div>\n";
$declaredIn = $global_xtoc_cache{'headers'}[$row->{'hid'}]{'fileName'};
}
$html .= " </div>\n";
$html .= " <div class=\"constants\"><div class=\"header\">Constants</div>\n" . $const_html . " </div>\n";
$html .= " <div class=\"declared_in\"><div class=\"header\">Declared In</div>\n <div class=\"file\">$declaredIn</div>\n </div>\n";
$html .= "</div>\n";
$hdoc{'Constants'}{'Constants'} = $html;
$hdoc{'Constants'}{'Preprocessor Macros'} = populate_cpp_html();
$const_html = "";
$html = "<h2>Exceptions</h2>\n\n";
$html .= "<div class=\"exceptions\">\n";
$html .= " <div class=\"declaration table\">\n";
for my $row (@{$global_xtoc_cache{'constants'}}) {
if(!defined($row)) { next; }
my ($hdcid, $tags) = ($row->{'hdcid'}, $global_xtoc_cache{'tags'}[$row->{'hdcid'}]);
$html .= " <div class=\"row\"><div class=\"name cell\">" . add_xref($row->{'fullText'}) . "</div></div>\n";
$const_html .= " <div class=\"constant\">\n";
$const_html .= " <div class=\"identifier\"><a name=\"$global_xtoc_cache{'xref'}{$row->{'name'}}{'linkId'}\">$row->{'name'}</a></div>\n";
$const_html .= " <div class=\"text\">$tags->{'abstract'}</div>\n";
if (defined($tags->{'seealso'})) {
my(@seealso_html);
for my $s (@{$tags->{'seealso'}}) { push(@seealso_html, " <li>".$s."</li>"); }
$const_html .= " <div class=\"seealso\"><div class=\"header\">See Also</div>\n <ul>\n" . join("\n", @seealso_html) . "\n </ul>\n </div>\n";
}
$const_html .= " </div>\n";
$declaredIn = $global_xtoc_cache{'headers'}[$row->{'hid'}]{'fileName'}
}
$html .= " </div>\n";
$html .= " <div class=\"constants\"><div class=\"header\">Constants</div>\n" . $const_html . " </div>\n";
$html .= " <div class=\"declared_in\"><div class=\"header\">Declared In</div>\n <div class=\"file\">$declaredIn</div>\n </div>\n";
$html .= "</div>\n";
$hdoc{'Constants'}{'Exceptions'} = $html;
}
sub populate_cpp_html {
my ($const_html, $html) = ("", "");
$html = "<h2>Preprocessor Macros</h2>\n\n";
for my $row (@{$global_xtoc_cache{'preprocessorDefines'}}) {
if(!defined($row)) { next; }
my ($hdcid, $tags) = ($row->{'hdcid'}, $global_xtoc_cache{'tags'}[$row->{'hdcid'}]);
my $signature_html = " <div class=\"signature\">$row->{'cppText'}</div>\n";
$html .= "<div class=\"macro\">\n <div class=\"name\"><a name=\"$global_xtoc_cache{'xref'}{$row->{'defineName'}}{'linkId'}\">$row->{'defineName'}</a></div>\n";
$html .= common_html($signature_html, $hdcid);
$html .= " <div class=\"declared_in\"><div class=\"header\">Declared In</div>\n <div class=\"file\">$global_xtoc_cache{'headers'}[$row->{'hid'}]{'fileName'}</div>\n </div>\n";
$html .= "</div>\n\n";
}
return($html);
}
sub add_xref {
my $xref = shift(@_);
# $xref =~ s/<span class="code">(\w+)<\/span>/defined($global_xtoc_cache{'xref'}{$1}{'href'}) ? "<a href=\"$global_xtoc_cache{'xref'}{$1}{'href'}\"" . $global_xtoc_cache{'xref'}{$1}{'class'} ne "" ? "class=\"$global_xtoc_cache{'xref'}{$1}{'class'}\"" :"" . ">$1<\/a>" : $1/sge;
$xref =~ s/<span class="code">(\w+)<\/span>/defined($global_xtoc_cache{'xref'}{$1}{'href'}) ? "<a href=\"$global_xtoc_cache{'xref'}{$1}{'href'}\" class=\"code\">$1<\/a>" : $1/sge;
$xref =~ s/(\w+)/defined($global_xtoc_cache{'xref'}{$1}{'href'}) ? "<a href=\"$global_xtoc_cache{'xref'}{$1}{'href'}\" class=\"code\">$1<\/a>" : $1/sge;
return($xref);
}
sub constant_html {
my $cid = shift(@_);
my $html;
my $const_html = "";
if(defined($global_xtoc_cache{'constants'}[$cid])) {
my $row = $global_xtoc_cache{'constants'}[$cid];
my ($hdcid, $tags) = ($row->{'hdcid'}, $global_xtoc_cache{'tags'}[$row->{'hdcid'}]);
$html = "<div class=\"constants\"><div class=\"header\">Constants</div>\n";
$html .= " <div class=\"constant\">\n";
$html .= " <div class=\"identifier\"><a name=\"$global_xtoc_cache{'xref'}{$row->{'name'}}{'linkId'}\">$row->{'name'}</a></div>\n";
$html .= " <div class=\"text\">$tags->{'abstract'}</div>\n";
$html .= " </div>\n";
$html .= "</div>\n";
}
return($html);
}
sub func_html {
my $pid = shift(@_);
my($html, $row, $signature_html) = ("");
if(defined($global_xtoc_cache{'functions'}[$pid])) {
my $row = $global_xtoc_cache{'functions'}[$pid];
my ($pretty, $hdcid, $tags) = ($row->{'prettyText'}, $row->{'hdcid'}, $global_xtoc_cache{'tags'}[$row->{'hdcid'}]);
$pretty =~ s/(\((.*?)\))/{my ($full, $mid) = ($1, $2); $mid =~ s?(\S+)?if(defined($global_xtoc_cache{'xref'}{$1}{'href'})) { "<a href=\"$global_xtoc_cache{'xref'}{$1}{'href'}\">$1<\/a>" } else { $1 }?sge; "($mid)"} /sge;
$signature_html = "<div class=\"signature\">$pretty</div>\n";
$html = "<div class=\"function\">\n<div class=\"name\"><a name=\"$global_xtoc_cache{'xref'}{$tags->{'function'}}{'linkId'}\">$tags->{'function'}</a></div>\n";
$html .= common_html($signature_html, $hdcid);
$html .= "</div>\n\n";
}
return($html);
}
sub meth_html {
my $ocmid = shift(@_);
my($html, $row, $signature_html) = ("");
if(defined($global_xtoc_cache{'methods'}[$ocmid])) {
my $row = $global_xtoc_cache{'methods'}[$ocmid];
my ($pretty, $hdcid, $tags, $mxref) = ($row->{'prettyText'}, $row->{'hdcid'}, $global_xtoc_cache{'tags'}[$row->{'hdcid'}], "$row->{'class'}/$row->{'type'}$row->{'selector'}");
$pretty =~ s/(\((.*?)\))/{my ($full, $mid) = ($1, $2); $mid =~ s?(\S+)?if(defined($global_xtoc_cache{'xref'}{$1}{'href'})) { "<a href=\"$global_xtoc_cache{'xref'}{$1}{'href'}\">$1<\/a>" } else { $1 }?sge; "($mid)"} /sge;
$signature_html = " <div class=\"signature\">$pretty</div>\n";
$html = "<div class=\"method\">\n <div class=\"name\"><a name=\"$global_xtoc_cache{'xref'}{$mxref}{'linkId'}\">$tags->{'method'}</a></div>\n";
$html .= common_html($signature_html, $hdcid);
$html .= "</div>\n\n";
}
return($html);
}
sub seealso_html {
my($tags, $html, $seealso_html, @seealso) = (shift(@_), "");
if (defined($tags->{'seealso'})) {
$seealso_html = join("\n", map(" <li>".$_."</li>", @{$tags->{'seealso'}}));
$html = <<END_HTML
<div class="seealso"><div class="header">See Also</div>
<ul>
$seealso_html
</ul>
</div>
END_HTML
}
}
sub common_html {
my $signature_html = shift(@_);
my $hdcid = shift(@_);
my($html, $tags, $row) = ("", $global_xtoc_cache{'tags'}[$hdcid]);
if (defined($tags->{'abstract'})) { $html .= " <div class=\"summary\">$tags->{'abstract'}</div>\n"; }
if (defined($signature_html)) { $html .= $signature_html; }
if (defined($tags->{'param'})) {
my @param_html;
for my $p (@{$tags->{'param'}}) {
my($arg, $text, $extra) = (@{$p}[0], @{$p}[1], "");
if ($text =~ /(.*?)\s*(<div.*)/s) { $extra = $2; $text = $1; if($extra !~ /\n\z/s) { $extra .= "\n"; } }
push(@param_html, " <li>\n <div class=\"name\">$arg</div>\n <div class=\"text\">$text</div>\n$extra\n </li>");
}
$html .= " <div class=\"parameters\"><div class=\"header\">Parameters</div>\n <ul>\n" . join("\n", @param_html) . "\n </ul>\n </div>\n";
}
if(defined($tags->{'discussion'})) { $html .= " <div class=\"discussion\"><div class=\"header\">Discussion</div>\n$tags->{'discussion'}\n </div>\n"; }
if(defined($tags->{'result'})) { $html .= " <div class=\"result\"><div class=\"header\">Return Value</div>\n$tags->{'result'}\n </div>\n"; }
if (defined($tags->{'seealso'})) {
my(@seealso_html);
for my $s (@{$tags->{'seealso'}}) { push(@seealso_html, " <li>".$s."</li>"); }
$html .= " <div class=\"seealso\"><div class=\"header\">See Also</div>\n <ul>\n" . join("\n", @seealso_html) . "\n </ul>\n </div>\n";
}
return($html);
}
sub typedef_html {
my $tdeid = shift(@_);
if(defined($global_xtoc_cache{'typedefs'}[$tdeid])) {
my $row = $global_xtoc_cache{'typedefs'}[$tdeid];
my ($html, $tags, $hdcid, $const_html) = ("", $global_xtoc_cache{'tags'}[$row->{'hdcid'}], $row->{'hdcid'}, "");
$html .= "<div class=\"typedef\">\n";
$html .= " <div class=\"name\"><a name=\"$global_xtoc_cache{'xref'}{$row->{'name'}}{'linkId'}\">$row->{'name'}</a></div>\n";
if(defined($tags->{'abstract'})) { $html .= " <div class=\"summary\">$tags->{'abstract'}</div>\n"; }
$html .= " <div class=\"declaration code table\">\n";
$html .= " <div class=\"top row\"><div class=\"cell\">typedef enum {</div></div>\n";
for my $tderow (@{$global_xtoc_cache{'enums'}[$row->{'tdeid'}]}) {
my $comma = ",";
if($tderow == $global_xtoc_cache{'enums'}[$row->{'tdeid'}][$#{$global_xtoc_cache{'enums'}[$row->{'tdeid'}]}]) { $comma = ""; }
$html .= " <div class=\"enum row\">\n";
$html .= " <div class=\"identifier cell\"><a href=\"$global_xtoc_cache{'xref'}{$tderow->{'identifier'}}{'href'}\">$tderow->{'identifier'}</a></div>\n";
$const_html .= " <div class=\"constant\">\n";
$const_html .= " <div class=\"identifier\"><a name=\"$global_xtoc_cache{'xref'}{$tderow->{'identifier'}}{'linkId'}\">$tderow->{'identifier'}</a></div>\n";
$const_html .= " <div class=\"text\">$tderow->{'tagText'}</div>\n";
$const_html .= " </div>\n";
$html .= " <div class=\"equals cell\">=</div>\n";
$html .= " <div class=\"constant cell\">$tderow->{'constant'}$comma</div>\n";
$html .= " </div>\n";
}
$html .= " <div class=\"bottom row\"><div class=\"cell\">} $row->{'name'};</div></div>\n";
$html .= " </div>\n\n";
$html .= " <div class=\"constants\"><div class=\"header\">Constants</div>\n" . $const_html . " </div>\n";
if(defined($row->{'discussion'})) { $html .= " <div class=\"discussion\"><div class=\"header\">Discussion</div>$row->{'discussion'}</div>\n"; }
$html .= " <div class=\"declared_in\"><div class=\"header\">Declared In</div>\n <div class=\"file\">$global_xtoc_cache{'headers'}[$row->{'hid'}]{'fileName'}</div>\n </div>\n";
$html .= "</div>\n\n";
return($html);
}
}
sub create_toc_html {
populate_toc_html();
my ($TOC_OUTPUT, $TOC_TMPL, $toc_tmpl);
open($TOC_TMPL, "<", "$ENV{'DOCUMENTATION_TEMPLATES_DIR'}/toc.tmpl"); read($TOC_TMPL, $toc_tmpl, (stat($TOC_TMPL))[7]); close($TOC_TMPL);
if ($toc_tmpl !~ /\n$/s) { $toc_tmpl .= "\n"; }
$toc_tmpl =~ s/((?<!\\)[\%\$\@])/\\\\$1/g;
$toc_tmpl =~ s/(\\?)\\([\%\$\@])/$1$2/g;
my ($et, $etoc) = ("", '$et = <<END_OF_TOC_TMPL;' . "\n" . $toc_tmpl . "END_OF_TOC_TMPL\n");
eval($etoc);
open($TOC_OUTPUT, ">", "$ENV{'GENERATED_HTML_DIR'}/toc.html"); print($TOC_OUTPUT $et); close($TOC_OUTPUT);
}
sub populate_toc_html {
for my $tocName (keys %{$global_xtoc_cache{'toc'}{'groupEntries'}}) {
my $html = "";
my (@tocArray) = (@{$global_xtoc_cache{'toc'}{'groupEntries'}{$tocName}});
my $file = $global_xtoc_cache{'toc'}{$tocName}{'file'};
my $sectionId = "tocID_$tocName";
$sectionId =~ s/[^a-zA-Z0-9_\.\-]//sg;
$html .= <<DIV_END;
<div class="section closed" id="$sectionId">
<div class="header">
<span class="indicator large">&nbsp;</span>
<span class="title"><a href="$file" target="doc">$tocName</a></span>
</div>
<div class="contents">
<div class="entries">
DIV_END
for my $tx (0 .. $#tocArray) {
my $groupName = $global_xtoc_cache{'toc'}{'tocGroups'}{$tocName}[$tx];
my $extraSpaces = "";
if(defined($groupName)) {
$extraSpaces = " ";
my $subSectionId = "tocID_${tocName}_${groupName}";
$subSectionId =~ s/[^a-zA-Z0-9_\.\-]//sg;
$html .= <<DIV_END;
<div class="section closed sub" id="$subSectionId">
<div class="header">
<span class="indicator small">&nbsp;</span>
<span class="title">$groupName</span>
</div>
<div class="contents">
<div class="entries">
DIV_END
}
for my $ex (0 .. $#{$global_xtoc_cache{'toc'}{'groupEntries'}{$tocName}[$tx]}) {
my $at = $global_xtoc_cache{'toc'}{'groupEntries'}{$tocName}[$tx][$ex];
$html .= "$extraSpaces <div class=\"entry\"><a href=\"$at->{'href'}\" title=\"$at->{'titleText'}\" class=\"code\" target=\"doc\">$at->{'linkText'}</a></div>\n";
}
if(defined($groupName)) {
$html .= <<DIV_END;
</div>
</div>
</div>
DIV_END
}
}
$html .= <<DIV_END;
<span class="rightEdge"><img alt="Overflow fade" src="Images/grad_18_1.png"></span>
</div>
</div>
</div>
DIV_END
$toc{$tocName} = $html;
}
}
sub populate_tasks_html {
for my $tocName (keys %{$global_xtoc_cache{'toc'}{'groupEntries'}}) {
my $html = "<h2>Tasks</h2>\n\n";
my (@tocArray) = (@{$global_xtoc_cache{'toc'}{'groupEntries'}{$tocName}});
for my $tx (0 .. $#tocArray) {
my $groupName = $global_xtoc_cache{'toc'}{'tocGroups'}{$tocName}[$tx];
$html .= "<div class=\"tasks\">\n";
if(defined($groupName)) { $html .= " <div class=\"header\">$groupName</div>\n"; }
$html .= " <ul>\n";
for my $ex (0 .. $#{$global_xtoc_cache{'toc'}{'groupEntries'}{$tocName}[$tx]}) {
my $at = $global_xtoc_cache{'toc'}{'groupEntries'}{$tocName}[$tx][$ex];
$html .= " <li><a href=\"$at->{'href'}\" title=\"$at->{'titleText'}\" class=\"code\">$at->{'linkText'}</a></li>\n";
}
$html .= " </ul>\n";
$html .= "</div>\n";
}
$hdoc{$tocName}{'tasks'} = $html;
}
}
sub stripExcess {
my($strip) = @_;
$strip =~ s/<div\s+[^>]*\bclass="[^\"]*\bbox\b[^\"]*"[^>]*>.*(?:<\/div>\s*){4}//sg;
$strip =~ s/\@link .*? (.*?)\s?\@\/link/$1/sg;
$strip =~ s/<[^>]+>(.*?)<\/[^>]+>/$1/sg;
$strip =~ s/\"/\\"/sg;
return($strip);
}
sub gen_xtoc_cache {
my (%cache);
for my $row (selectall_hash($dbh, "SELECT DISTINCT xref, linkId, href FROM t_xtoc WHERE xref IS NOT NULL AND linkId IS NOT NULL AND href IS NOT NULL")) {
$cache{'xref'}->{$row->{'xref'}}{'linkId'} = $row->{'linkId'};
$cache{'xref'}->{$row->{'xref'}}{'href'} = $row->{'href'};
$cache{'xref'}->{$row->{'xref'}}{'class'} = "code";
}
for my $row (selectall_hash($dbh, "SELECT DISTINCT xref, class, href FROM xrefs WHERE href IS NOT NULL")) {
$cache{'xref'}->{$row->{'xref'}}{'href'} = $row->{'href'};
$cache{'xref'}->{$row->{'xref'}}{'class'} = $row->{'class'};
}
for my $row (selectall_hash($dbh, "SELECT DISTINCT tbl, idCol, id, hdtype, tocName, groupName, pos, linkId, href, titleText, linkText, file FROM t_xtoc WHERE tocName IS NOT NULL AND pos IS NOT NULL AND id IS NOT NULL AND href IS NOT NULL AND linkText IS NOT NULL ORDER BY pos, linkText")) {
if(defined($row->{'groupName'})) { $cache{'toc'}{'tocGroups'}{$row->{'tocName'}}[$row->{'pos'} - 1] = $row->{'groupName'}; }
if(defined($row->{'file'})) { $cache{'toc'}{$row->{'tocName'}}{'file'} = $row->{'file'}; }
my $entry = {'table' => $row->{'tbl'}, 'idColumn' => $row->{'idCol'}, 'id' => $row->{'id'}, 'type' => $row->{'hdtype'}, 'href' => $row->{'href'}, 'linkId' => $row->{'linkId'}, 'linkText' => $row->{'linkText'}};
if(defined($row->{'titleText'})) { $entry->{'titleText'} = stripExcess($row->{'titleText'}); }
push(@{$cache{'toc'}{'groupEntries'}{$row->{'tocName'}}[$row->{'pos'} - 1]}, $entry);
}
for my $row (selectall_hash($dbh, "SELECT DISTINCT tbl, idCol, id, hdtype, tocName, linkId, href, linkText FROM t_xtoc WHERE tocName IS NOT NULL AND pos IS NOT NULL AND id IS NOT NULL AND href IS NOT NULL AND linkText IS NOT NULL ORDER BY linkText")) {
push(@{$cache{'toc'}{'contentsForToc'}{$row->{'tocName'}}}, {'table' => $row->{'tbl'}, 'idColumn' => $row->{'idCol'}, 'id' => $row->{'id'}, 'type' => $row->{'hdtype'}, 'href' => $row->{'href'}, 'linkId' => $row->{'linkId'},'linkText' => $row->{'linkText'}});
}
for my $row (selectall_hash($dbh, "SELECT * FROM v_hd_tags")) {
my $p = defined($row->{'arg1'}) ? [$row->{'arg0'}, $row->{'arg1'}] : $row->{'arg0'};
if($row->{'multiple'} == 0) { $cache{'tags'}[$row->{'hdcid'}]{$row->{'keyword'}} = $p; }
else { push(@{$cache{'tags'}[$row->{'hdcid'}]{$row->{'keyword'}}}, $p); }
}
for my $row (selectall_hash($dbh, "SELECT ocm.*, occ.class AS class FROM objCMethods AS ocm JOIN objCClass AS occ ON ocm.occlid = occ.occlid WHERE ocm.hdcid IS NOT NULL")) { $cache{'methods'}[$row->{'ocmid'}] = $row; }
for my $row (selectall_hash($dbh, "SELECT * FROM prototypes WHERE hdcid IS NOT NULL")) { $cache{'functions'}[$row->{'pid'}] = $row; }
for my $row (selectall_hash($dbh, "SELECT * FROM typedefEnum WHERE hdcid IS NOT NULL")) { $cache{'typedefs'}[$row->{'tdeid'}] = $row; }
for my $row (selectall_hash($dbh, "SELECT e.*, vhd.arg1 AS tagText FROM enumIdentifier AS e JOIN v_hd_tags AS vhd ON vhd.hdcid = e.hdcid AND vhd.keyword = 'constant' AND vhd.arg0 = e.identifier WHERE e.hdcid IS NOT NULL ORDER BY tdeid, position")) { $cache{'enums'}[$row->{'tdeid'}][$row->{'position'}] = $row; }
for my $row (selectall_hash($dbh, "SELECT * FROM constant WHERE hdcid IS NOT NULL ORDER BY name")) { push(@{$cache{'constants'}}, $row); }
for my $row (selectall_hash($dbh, "SELECT * FROM define WHERE hdcid IS NOT NULL ORDER BY defineName")) { push(@{$cache{'defines'}}, $row); }
for my $row (selectall_hash($dbh, "SELECT * FROM define WHERE hdcid IN (SELECT hdcid FROM t_xtoc WHERE tocName = 'Constants' AND groupName = 'Constants') ORDER BY defineName")) { push(@{$cache{'constantDefines'}}, $row); }
for my $row (selectall_hash($dbh, "SELECT * FROM define WHERE hdcid IN (SELECT hdcid FROM t_xtoc WHERE tocName = 'Constants' AND groupName = 'Preprocessor Macros') ORDER BY defineName")) { push(@{$cache{'preprocessorDefines'}}, $row); }
for my $row (selectall_hash($dbh, "SELECT * FROM headers")) { $cache{'headers'}[$row->{'hid'}] = $row; }
return(%cache);
}
sub selectall_hash {
my($dbh, $stmt, @args, @results) = (shift(@_), shift(@_), @_);
my $sth = (ref $stmt) ? $stmt : $dbh->prepare($stmt, undef) or return;
$sth->execute(@args) or return;
while (my $row = $sth->fetchrow_hashref) { push(@results, $row); }
$sth->finish;
return(@results);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.