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
|
#!/usr/bin/perl
#############################################################################
## Kwave - update-command-xref.pl
## -------------------
## begin : Sun Jan 04 2015
## copyright : (C) 2015 by Thomas Eschenbacher
## email : Thomas.Eschenbacher@gmx.de
#############################################################################
#
#############################################################################
## #
## This program is free software; you can redistribute it and/or modify #
## it under the terms of the GNU General Public License as published by #
## the Free Software Foundation; either version 2 of the License, or #
## (at your option) any later version. #
## #
#############################################################################
# split argument string
my $src_dir = $ARGV[0];
my $in = $ARGV[1];
my $out = $ARGV[2];
open(IN, "<" . $in ) or die "cannot open input file " . $in;
open(OUT, ">" . $out) or die "cannot open output file " . $out;
my @scanned_cmds;
sub scan_file
{
my $file = shift;
open(IN2, $file);
while (<IN2>) {
my $line = $_;
chomp $line;
$line =~ s/\s+$//;
$line =~ s/^\s+|\s+$//g;
if ($line =~ /^CASE_COMMAND\s*\(\"(.+)\"\s*\)/) {
my $cmd = $1;
push(@scanned_cmds, $cmd) if (! grep {$_ eq $cmd} @scanned_cmds);
}
}
close(IN2);
}
sub process_dir
{
my $path = shift;
opendir(DIR, $path) or die "opendir $path: $!";
my @files = grep { !/(^\.)/ } readdir(DIR);
closedir(DIR);
@files = map { $path . '/' . $_ } @files;
for (@files) {
if (-d $_) {
process_dir($_);
} else {
my $file = $_;
if ( $file =~ /\.(inl|cxx|cpp)$/ ) {
scan_file($file);
}
}
}
}
sub make_stub
{
local $cmd = shift;
local $lbl = $cmd;
print OUT "\t\<\!-- \@COMMAND\@ " . $cmd . "(TODO) --\>\n";
$lbl =~ s/[^\w]/_/g;
print OUT "\t<sect2 id=\"cmd_sect_" . $lbl . "\">" .
"<title id=\"cmd_title_" . $lbl . "\">" .
"&no-i18n-cmd_" . $lbl . ";</title>\n";
print OUT "\t<para>\n";
print OUT "\t TBD\n";
print OUT "\t</para>\n";
print OUT "\t</sect2>\n";
print OUT "\n";
}
#
# recursively scan all files and subdirs for command names
#
process_dir($src_dir);
@scanned_cmds = sort { $a cmp $b } @scanned_cmds;
my @remaining_cmds = @scanned_cmds;
my $linenr = 0;
my $mode = "normal";
my $last_cmd = "";
LINE: while (<IN>) {
my $line = $_;
$linenr += 1;
if ($mode eq "normal") {
if ($line =~ /\<\!\-\-\ \@COMMAND_INDEX_START\@\ \-\-\>/) {
print OUT $line;
$mode = "index";
next LINE;
}
if ($line =~ /\<\!\-\-\ \@COMMAND_ENTITIES_START\@\ \-\-\>/) {
print OUT $line;
$mode = "entities";
next LINE;
}
if ($line =~ /\<\!\-\-\ \@COMMAND\@\ ([\w\:]+)\(([\w\,\:\[\]\.]*)\)\ \-\-\>/) {
my $cmd = $1;
my $params = $2;
# print "### found command '" . $cmd . "' params: '" . $params . "'\n";
if (not grep {$_ eq $cmd} @scanned_cmds) {
print STDERR "WARNING: command '" . $cmd . "' is not supported / does not exist\n";
} else {
while (@remaining_cmds) {
my $next_cmd = shift @remaining_cmds;
# if command is next in list of remaining -> remove from list
# print "next_cmd=".$next_cmd.", cmd=".$cmd."\n";
if ($cmd eq $next_cmd) {
# print "(FOUND)\n";
# show a warning if there documentation is not finished
# for this command
if ($params eq "TODO") {
print STDERR "WARNING: command '" . $cmd . "': documentation is not finished (TODO)\n";
}
print OUT $line;
next LINE;
}
if ($cmd gt $next_cmd) {
print STDERR "WARNING: command '" . $next_cmd . "' is undocumented, adding stub\n";
make_stub $next_cmd;
} else {
last;
}
}
}
print OUT $line;
next LINE;
}
if ($line =~ /\<\!\-\-\ \@COMMAND_END_OF_LIST\@\ \-\-\>/) {
# print "WARNING: some commands left\n";
while (@remaining_cmds) {
local $cmd = shift @remaining_cmds;
print STDERR "WARNING: command '" . $cmd . "' is undocumented, adding stub\n";
make_stub $cmd;
}
}
print OUT $line;
}
if ($line =~ /\<\!\-\-\ \@COMMAND_ENTITIES_END\@\ \-\-\>/) {
foreach (@scanned_cmds) {
local $cmd = $_;
local $lbl = $cmd;
$lbl =~ s/[^\w]/_/g;
print OUT " \<\!ENTITY no-i18n-cmd_" . $lbl . " \"" . $cmd . "\"\>\n";
}
print OUT $line;
$mode = "normal";
next LINE;
}
if ($mode eq "index") {
if ($line =~ /\<\!\-\-\ \@COMMAND_INDEX_END\@\ \-\-\>/) {
# create a new command index
my $first_char = "*";
foreach (@scanned_cmds) {
my $cmd = $_;
my $first = substr($cmd, 0, 1);
if (not ($first eq $first_char)) {
print OUT "\t </indexdiv>\n" if (not ($first_char eq "*"));
print OUT "\t <indexdiv><title>" . $first . "</title>\n";
$first_char = $first;
}
$cmd =~ s/[^\w]/_/g;
print OUT "\t\t<indexentry><primaryie>" .
"<link linkend=\"cmd_sect_" . $cmd . "\" " .
"endterm=\"cmd_title_" . $cmd . "\"/>" .
"</primaryie></indexentry>\n";
}
print OUT "\t </indexdiv>\n";
# switch back to normal mode
$mode = "normal";
print OUT $line;
next LINE;
}
}
}
close(IN);
close(OUT);
#############################################################################
#############################################################################
|