1
|
1 |
#! /usr/bin/perl |
|
2 |
|
|
3 |
use strict; |
|
4 |
use warnings; |
|
5 |
|
|
6 |
my %docs; |
|
7 |
my @tags; |
|
8 |
my $inside; |
|
9 |
my $harvest; |
|
10 |
my @values; |
|
11 |
|
|
12 |
foreach my $file (@ARGV) { |
|
13 |
if ( not open SOURCE, '<', $file ) { |
|
14 |
print STDERR "Cannot open $file\n"; |
|
15 |
next; |
|
16 |
} |
|
17 |
|
|
18 |
my $chunk = 0; |
|
19 |
|
|
20 |
while (<SOURCE>) { |
|
21 |
if ( $inside ) { |
|
22 |
if ( not /^\/\/\// ) { |
|
23 |
$inside = 0; |
|
24 |
$chunk++; |
|
25 |
} elsif ( /^\/\/\/ G:/ ) { |
|
26 |
$inside = 0; |
|
27 |
$harvest = 'V: ' . substr ( $_, 6 ); |
|
28 |
} else { |
|
29 |
push @{$docs{$file}[$chunk]}, substr ( $_, 4 ); |
|
30 |
} |
|
31 |
} elsif ( $harvest ) { |
|
32 |
if ( /\{\s*NULL.*\}/ ) { |
|
33 |
push @{$docs{$file}[$chunk]}, $harvest . ' ' . join ( ', ', @values ); |
|
34 |
$harvest = undef; |
|
35 |
@values = (); |
|
36 |
$chunk++; |
|
37 |
} elsif ( /\{\s*"(.+)".*\}/ ) { |
|
38 |
push @values, $1; |
|
39 |
} |
|
40 |
} else { |
|
41 |
next if not /^\/\/\//; |
|
42 |
|
|
43 |
$inside = 1; |
|
44 |
my $tag = substr $_, 4; |
|
45 |
chomp $tag; |
|
46 |
push @{$docs{$file}[$chunk]}, $tag; |
|
47 |
# hack to allow twoword objects be written in text with spaces |
|
48 |
# now it matches "lm message" instead of "lm message node" -.- |
|
49 |
# and even if tag list will be reverse sorted by length, |
|
50 |
# it will produce nested links... |
|
51 |
# well, that all is now solved, but in not too impressive way.. |
|
52 |
$tag =~ s/_/./g; |
|
53 |
push @tags, $tag; |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
57 |
close SOURCE; |
|
58 |
} |
|
59 |
|
|
60 |
print <<HEADER |
|
61 |
<html> |
|
62 |
<head><title>lua-loudmouth docs</title></head> |
|
63 |
<body> |
|
64 |
HEADER |
|
65 |
; |
|
66 |
|
|
67 |
@tags = reverse sort { length $a <=> length $b } @tags; |
|
68 |
# TODO preserve original order |
|
69 |
foreach my $file ( sort keys %docs ) { |
|
70 |
print "<hr>"; |
|
71 |
foreach my $chunk ( @{$docs{$file}} ) { |
|
72 |
my $head = shift @$chunk; |
|
73 |
my $tag = $head; |
|
74 |
my $list = undef; |
|
75 |
$tag =~ s/_/./g; |
|
76 |
print "<a name='$tag'></a><h2>$head</h2><p>"; |
|
77 |
foreach ( @$chunk ) { |
|
78 |
s/^A: /<br\/>Arguments: /; |
|
79 |
s/^R: /<br\/>Return values: /; |
|
80 |
s/^V: /<br\/>Values: /; |
|
81 |
if ( $list ) { |
|
82 |
if ( /^\* / ) { |
|
83 |
s/^\* /<\/li><li>/; |
|
84 |
} else { |
|
85 |
s/^/<\/li><\/ul> /; |
|
86 |
$list = undef; |
|
87 |
} |
|
88 |
} elsif ( /^\* / ) { |
|
89 |
s/^\* /<ul><li>/; |
|
90 |
$list = 1; |
|
91 |
} |
|
92 |
foreach my $tag ( @tags ) { |
|
93 |
# TODO quotemeta required, but for now |
|
94 |
# this bug is rather desired... |
|
95 |
#s/\b$tag\b/<a href="#$tag">$&<\/a>/g; |
|
96 |
s/(.)\b($tag)\b/ if ( $1 eq '#' or $1 eq '>' ) { "$1$2" } else { "$1<a href='#$tag'>$2<\/a>" } /ge; |
|
97 |
} |
|
98 |
print $_; |
|
99 |
} |
|
100 |
print "</li></ul>" if $list; |
|
101 |
print "</p>" |
|
102 |
} |
|
103 |
print "<hr>"; |
|
104 |
} |
|
105 |
|
|
106 |
print "</body></html>" |
|
107 |
|
|
108 |
# The end |