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$
|
2016-01-12 08:26:07 +00:00
|
|
|
|
|
|
|
my $noWarnings = grep $_ eq '-noWarnings', @ARGV;
|
2016-01-16 17:00:15 +00:00
|
|
|
my ($verify) = grep $_ =~ /\.pm$/ , @ARGV;
|
|
|
|
|
2016-02-03 16:27:29 +00:00
|
|
|
use constant TAGS => qw{ul li code b i u table tr td div};
|
2016-01-12 08:26:07 +00:00
|
|
|
|
2016-01-16 17:00:15 +00:00
|
|
|
sub generateModuleCommandref($$;$);
|
|
|
|
|
2012-11-04 13:29:55 +00:00
|
|
|
my %mods;
|
2016-01-16 19:27:21 +00:00
|
|
|
my %modIdx;
|
2012-11-26 15:10:37 +00:00
|
|
|
my @modDir = ("FHEM");
|
2016-01-16 17:00:15 +00:00
|
|
|
my @lang = ("EN", "DE");
|
|
|
|
|
|
|
|
if(!$verify) {
|
|
|
|
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";
|
2016-01-16 19:27:21 +00:00
|
|
|
$modIdx{$l} = "device";
|
|
|
|
open(MOD, "$modDir/$of") || die("Cant open $modDir/$l");
|
|
|
|
while(my $cl = <MOD>) {
|
2016-01-17 06:35:00 +00:00
|
|
|
if($cl =~ m/^=item\s+(helper|command|device)/) {
|
|
|
|
$modIdx{$l} = $1;
|
|
|
|
last;
|
|
|
|
}
|
2016-01-16 19:27:21 +00:00
|
|
|
}
|
|
|
|
close(MOD);
|
2016-01-16 17:00:15 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-17 11:47:01 +00:00
|
|
|
|
|
|
|
if(-f "configDB.pm") {
|
|
|
|
$mods{configDB} = "configDB.pm";
|
|
|
|
$modIdx{configDB} = "helper";
|
|
|
|
}
|
|
|
|
|
2016-01-16 17:00:15 +00:00
|
|
|
} else { # check for syntax only
|
|
|
|
my $modname = $verify;
|
|
|
|
$modname =~ s/^.*[\/\\](?:\d\d_)?(.+).pm$/$1/;
|
|
|
|
$mods{$modname} = $verify;
|
|
|
|
foreach my $lang (@lang) {
|
|
|
|
generateModuleCommandref($modname, $lang);
|
2012-11-04 13:29:55 +00:00
|
|
|
}
|
2016-01-16 17:00:15 +00:00
|
|
|
exit;
|
2012-11-04 13:29:55 +00:00
|
|
|
}
|
|
|
|
|
2016-01-16 19:27:21 +00:00
|
|
|
sub
|
|
|
|
printList($)
|
|
|
|
{
|
|
|
|
for my $i (sort { "\L$a" cmp "\L$b" } keys %modIdx) {
|
|
|
|
print OUT " <a href=\"#$i\">$i</a> \n"
|
|
|
|
if($modIdx{$i} eq $_[0]);
|
|
|
|
}
|
|
|
|
while(my $l = <IN>) {
|
|
|
|
next if($l =~ m/href=/);
|
|
|
|
print OUT $l;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
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";
|
|
|
|
|
2016-01-16 19:27:21 +00:00
|
|
|
if(!$suffix) { # First run: remember commands/helper module
|
|
|
|
my $modType;
|
|
|
|
while(my $l = <IN>) {
|
|
|
|
$modType = "command" if($l =~ m/>Fhem commands</);
|
|
|
|
$modType = "device" if($l =~ m/>Devices</);
|
|
|
|
$modType = "helper" if($l =~ m/>Helper modules</);
|
2016-03-12 12:23:59 +00:00
|
|
|
$modIdx{$1} = $modType
|
|
|
|
if($modType && $l =~ m/href="#(.*?)">/ && $1 ne "global");
|
2016-01-16 19:27:21 +00:00
|
|
|
last if($l =~ m/<!-- header end -->/);
|
|
|
|
}
|
|
|
|
seek(IN,0,0);
|
2012-11-26 15:10:37 +00:00
|
|
|
}
|
2012-11-04 13:29:55 +00:00
|
|
|
|
2012-11-26 15:10:37 +00:00
|
|
|
# Second run: create the file
|
2016-01-16 19:27:21 +00:00
|
|
|
while(my $l = <IN>) { # Header
|
2012-11-26 15:10:37 +00:00
|
|
|
last if($l =~ m/name="perl"/);
|
|
|
|
print OUT $l;
|
2016-01-16 19:27:21 +00:00
|
|
|
printList($1) if($l =~ m/<!-- header:(.*) -->/);
|
2012-11-26 15:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Copy the doc part from the module
|
|
|
|
foreach my $mod (sort keys %mods) {
|
2016-01-16 17:00:15 +00:00
|
|
|
generateModuleCommandref($mod,$lang, \*OUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy the tail
|
|
|
|
print OUT '<a name="perl"></a>',"\n";
|
|
|
|
while(my $l = <IN>) {
|
|
|
|
print OUT $l;
|
|
|
|
}
|
|
|
|
close(OUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
#############################
|
|
|
|
# read a module file and check/print the commandref
|
|
|
|
sub generateModuleCommandref($$;$)
|
|
|
|
{
|
|
|
|
my ($mod, $lang, $fh) = @_;
|
2012-11-26 15:10:37 +00:00
|
|
|
my $tag;
|
2016-01-16 17:00:15 +00:00
|
|
|
my $suffix = ($lang eq "EN" ? "" : "_$lang");
|
2012-11-26 15:10:37 +00:00
|
|
|
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;
|
2013-07-23 06:03:11 +00:00
|
|
|
my $dosMode = 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-07-23 06:03:11 +00:00
|
|
|
$dosMode = 1 if($l =~ m/^=begin html$suffix.*\r/);
|
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
|
2016-01-17 06:35:00 +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) {
|
2016-01-16 17:00:15 +00:00
|
|
|
print $fh $l if($fh);
|
2013-01-12 21:11:54 +00:00
|
|
|
$docCount++;
|
2014-02-28 14:07:37 +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
|
|
|
$tagcount{$tag} +=()= ($l =~ /<$tag>/gi);
|
|
|
|
$tagcount{$tag} -=()= ($l =~ /<\/$tag>/gi);
|
2014-11-02 15:30:49 +00:00
|
|
|
$llwct{$tag} = $line if(!$tagcount{$tag});
|
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-07-23 06:03:11 +00:00
|
|
|
print "*** $lang $mods{$mod}: ignoring text due to DOS encoding\n"
|
|
|
|
if($dosMode);
|
|
|
|
print "*** $lang $mods{$mod}: No document text found\n"
|
2015-03-29 10:06:15 +00:00
|
|
|
if(!$suffix && !$docCount && !$dosMode && $mods{$mod} !~ m,/99_,);
|
2014-02-04 13:12:02 +00:00
|
|
|
if($suffix && !$docCount && !$dosMode) {
|
2016-01-16 17:00:15 +00:00
|
|
|
if($lang eq "DE" && $fh) {
|
|
|
|
print $fh <<EOF;
|
2014-02-04 13:12:02 +00:00
|
|
|
<a name="$mod"></a>
|
|
|
|
<h3>$mod</h3>
|
|
|
|
<ul>
|
2014-02-28 07:48:55 +00:00
|
|
|
Leider keine deutsche Dokumentation vorhanden. Die englische Version gibt es
|
|
|
|
hier: <a href='commandref.html#$mod'>$mod</a><br/>
|
2014-02-04 13:12:02 +00:00
|
|
|
</ul>
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
}
|
2016-01-17 06:35:00 +00:00
|
|
|
print "*** $lang $mods{$mod}: No a-tag with name=\"$mod\" \n"
|
2016-01-12 08:26:07 +00:00
|
|
|
if(!$suffix && $docCount && !$hasLink && !$noWarnings);
|
2013-01-14 07:28:05 +00:00
|
|
|
|
2012-11-26 15:10:37 +00:00
|
|
|
foreach $tag (TAGS) {
|
2016-01-17 06:35:00 +00:00
|
|
|
print("*** $lang $mods{$mod}: Unbalanced $tag ".
|
2013-01-03 13:08:39 +00:00
|
|
|
"($tagcount{$tag}, last line ok: $llwct{$tag})\n")
|
2016-01-12 08:26:07 +00:00
|
|
|
if($tagcount{$tag} && !$noWarnings);
|
2012-11-26 15:10:37 +00:00
|
|
|
}
|
2012-11-04 13:29:55 +00:00
|
|
|
}
|