2012-11-04 13:29:55 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2013-03-24 17:47:28 +00:00
|
|
|
# MAXWI
|
|
|
|
# With pre: 1320, without 1020 (content only)
|
|
|
|
# pre { white-space: pre-wrap; } : 900
|
|
|
|
|
2012-11-04 13:29:55 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2012-11-04 19:06:13 +00:00
|
|
|
# $Id$
|
2012-11-04 19:03:27 +00:00
|
|
|
use constant TAGS => qw{ul li code};
|
2012-11-04 13:29:55 +00:00
|
|
|
my %mods;
|
2012-11-26 15:10:37 +00:00
|
|
|
my @modDir = ("FHEM");
|
2012-11-04 13:29:55 +00:00
|
|
|
foreach my $modDir (@modDir) {
|
|
|
|
opendir(DH, $modDir) || die "Cant open $modDir: $!\n";
|
|
|
|
while(my $l = readdir DH) {
|
|
|
|
next if($l !~ m/^\d\d_.*\.pm$/);
|
|
|
|
my $of = $l;
|
|
|
|
$l =~ s/.pm$//;
|
|
|
|
$l =~ s/^[0-9][0-9]_//;
|
|
|
|
$mods{$l} = "$modDir/$of";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-26 15:10:37 +00:00
|
|
|
my @lang = ("EN", "DE");
|
2012-11-04 13:29:55 +00:00
|
|
|
|
2012-11-26 15:10:37 +00:00
|
|
|
foreach my $lang (@lang) {
|
|
|
|
my $suffix = ($lang eq "EN" ? "" : "_$lang");
|
|
|
|
my $docIn = "docs/commandref_frame$suffix.html";
|
|
|
|
my $docOut = "docs/commandref$suffix.html";
|
2012-11-04 13:29:55 +00:00
|
|
|
|
2012-11-26 15:10:37 +00:00
|
|
|
open(IN, "$docIn") || die "Cant open $docIn: $!\n";
|
|
|
|
open(OUT, ">$docOut") || die "Cant open $docOut: $!\n";
|
|
|
|
|
|
|
|
# First run: check what is a command and what is a helper module
|
|
|
|
my $status;
|
|
|
|
my %noindex;
|
|
|
|
while(my $l = <IN>) {
|
|
|
|
last if($l =~ m/<h3>Introduction/);
|
|
|
|
$noindex{$1} = 1 if($l =~ m/href="#(.*)"/);
|
|
|
|
}
|
|
|
|
seek(IN,0,0);
|
2012-11-04 13:29:55 +00:00
|
|
|
|
2012-11-26 15:10:37 +00:00
|
|
|
# Second run: create the file
|
|
|
|
# Header
|
|
|
|
while(my $l = <IN>) {
|
|
|
|
print OUT $l;
|
|
|
|
last if($l =~ m/#global/);
|
|
|
|
}
|
|
|
|
|
|
|
|
# index for devices.
|
|
|
|
foreach my $mod (sort keys %mods) {
|
|
|
|
next if($noindex{$mod});
|
|
|
|
print OUT " <a href='#$mod'>$mod</a> \n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy the middle part
|
|
|
|
while(my $l = <IN>) {
|
|
|
|
last if($l =~ m/name="perl"/);
|
|
|
|
print OUT $l;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy the doc part from the module
|
|
|
|
foreach my $mod (sort keys %mods) {
|
|
|
|
my $tag;
|
|
|
|
my %tagcount= ();
|
2013-01-03 13:08:39 +00:00
|
|
|
my %llwct = (); # Last line with closed tag
|
2012-11-26 15:10:37 +00:00
|
|
|
open(MOD, $mods{$mod}) || die("Cant open $mods{$mod}:$!\n");
|
|
|
|
my $skip = 1;
|
2013-01-03 13:08:39 +00:00
|
|
|
my $line = 0;
|
2013-01-12 21:11:54 +00:00
|
|
|
my $docCount = 0;
|
2013-01-14 07:28:05 +00:00
|
|
|
my $hasLink = 0;
|
2012-11-26 15:10:37 +00:00
|
|
|
while(my $l = <MOD>) {
|
2013-01-03 13:08:39 +00:00
|
|
|
$line++;
|
2013-01-14 07:28:05 +00:00
|
|
|
|
2013-01-12 21:11:54 +00:00
|
|
|
if($l =~ m/^=begin html$suffix$/) {
|
2012-11-26 15:10:37 +00:00
|
|
|
$l = <MOD>; # skip one line, to be able to repeat join+split
|
2013-01-14 07:33:09 +00:00
|
|
|
print "$lang $mod: nonempty line after =begin html ignored\n"
|
2013-01-14 07:28:05 +00:00
|
|
|
if($l =~ m/^...*$/);
|
2013-01-03 13:08:39 +00:00
|
|
|
$skip = 0; $line++;
|
2013-01-14 07:28:05 +00:00
|
|
|
|
2013-01-12 21:11:54 +00:00
|
|
|
} elsif($l =~ m/^=end html$suffix$/) {
|
2012-11-26 15:10:37 +00:00
|
|
|
$skip = 1;
|
2013-01-14 07:28:05 +00:00
|
|
|
|
2012-11-26 15:10:37 +00:00
|
|
|
} elsif(!$skip) {
|
|
|
|
print OUT $l;
|
2013-01-12 21:11:54 +00:00
|
|
|
$docCount++;
|
2013-01-14 07:28:05 +00:00
|
|
|
$hasLink = ($l =~ m/<a name="$mod">/) if(!$hasLink);
|
2012-11-26 15:10:37 +00:00
|
|
|
foreach $tag (TAGS) {
|
2013-01-03 13:08:39 +00:00
|
|
|
my $ot = ($tagcount{$tag} ? $tagcount{$tag} : 0);
|
|
|
|
$tagcount{$tag} +=()= ($l =~ /<$tag>/gi);
|
|
|
|
$tagcount{$tag} -=()= ($l =~ /<\/$tag>/gi);
|
|
|
|
$llwct{$tag} = $line if(!$llwct{$tag} || ($ot && !$tagcount{$tag}));
|
|
|
|
#print "$mod $line $tag $tagcount{$tag}\n" if($tagcount{$tag} ne $ot);
|
2012-11-26 15:10:37 +00:00
|
|
|
}
|
2012-11-04 19:03:27 +00:00
|
|
|
}
|
2012-11-04 13:29:55 +00:00
|
|
|
}
|
2012-11-26 15:10:37 +00:00
|
|
|
close(MOD);
|
2013-01-14 07:33:09 +00:00
|
|
|
print "$lang $mod: No document text found\n" if(!$suffix && !$docCount);
|
|
|
|
print "$lang $mod: No <a name=\"$mod\"> link\n"
|
2013-01-14 07:28:05 +00:00
|
|
|
if(!$suffix && $docCount && !$hasLink);
|
|
|
|
|
2012-11-26 15:10:37 +00:00
|
|
|
foreach $tag (TAGS) {
|
2013-01-03 13:08:39 +00:00
|
|
|
print("$lang $mods{$mod}: Unbalanced $tag ".
|
|
|
|
"($tagcount{$tag}, last line ok: $llwct{$tag})\n")
|
|
|
|
if($tagcount{$tag});
|
2012-11-26 15:10:37 +00:00
|
|
|
}
|
2012-11-04 13:29:55 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 15:10:37 +00:00
|
|
|
# Copy the tail
|
|
|
|
print OUT '<a name="perl"></a>',"\n";
|
|
|
|
while(my $l = <IN>) {
|
|
|
|
print OUT $l;
|
|
|
|
}
|
|
|
|
close(OUT);
|
2012-11-04 13:29:55 +00:00
|
|
|
}
|