2014-08-07 20:51:02 +00:00
|
|
|
#!/bin/perl
|
|
|
|
#
|
|
|
|
# Extract supported divecomputers from libdivecomputer source
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# parse-descriptor.pl <path to libdivecomputer/src/descriptor.c> <outfile>
|
|
|
|
#
|
|
|
|
# depending on suffix of the outfile it creates the right content for
|
|
|
|
# either a text file or and html file
|
2013-12-14 00:28:54 +00:00
|
|
|
use Carp;
|
|
|
|
|
|
|
|
#set command line arguments
|
|
|
|
my ($infi, $outfi) = @ARGV;
|
|
|
|
my ($type) = $outfi =~ /\.([^.]+)$/;
|
|
|
|
|
2014-08-07 20:51:02 +00:00
|
|
|
if ($infi !~ /.*descriptor.c/) {
|
|
|
|
croak "run as $ARGV[0] <path to descriptor.c> <outputfile>\n";
|
|
|
|
}
|
|
|
|
|
2013-12-14 00:28:54 +00:00
|
|
|
open(my $fh, "<", $infi) || croak "can't open $infi: $!";
|
|
|
|
open(STDOUT, ">", $outfi) || croak "can't open $outfi: $!";
|
|
|
|
|
|
|
|
my $lastVend = "";
|
2017-01-15 03:22:21 +00:00
|
|
|
my $lastMod = "";
|
2014-08-07 20:51:02 +00:00
|
|
|
my @descriptors = ();
|
2013-12-14 00:28:54 +00:00
|
|
|
while (<$fh>) {
|
2014-08-07 20:51:02 +00:00
|
|
|
if (/^\s*{\s*"([^\,]*)"\s*,\s*"([^\,]*)"\s*,\s*([^\,]*).*}/) {
|
|
|
|
push(@descriptors, "$1,$2");
|
2013-12-14 00:28:54 +00:00
|
|
|
}
|
2014-08-07 20:51:02 +00:00
|
|
|
}
|
|
|
|
my @sortedDescriptors = sort @descriptors;
|
|
|
|
foreach (@sortedDescriptors) {
|
|
|
|
($vend, $mod) = split(',', $_);
|
2017-01-15 03:22:21 +00:00
|
|
|
next if ($vend eq $lastVend && $mod eq $lastMod);
|
2014-08-07 20:51:02 +00:00
|
|
|
if ($type eq "html") {
|
|
|
|
if ($vend eq $lastVend) {
|
|
|
|
printf(", %s", $mod);
|
|
|
|
} else {
|
|
|
|
if ($lastVend lt "Uemis" && $vend gt "Uemis") {
|
2014-08-09 19:04:48 +00:00
|
|
|
printf("</li></ul>\n </dd>\n <dt>Uemis</dt><dd><ul>\n\t <li>Zürich SDA");
|
2014-08-07 20:51:02 +00:00
|
|
|
}
|
|
|
|
if ($lastVend eq "") {
|
2014-08-09 19:04:48 +00:00
|
|
|
printf("<dl><dt>%s</dt><dd><ul>\n\t <li>%s", $vend, $mod);
|
2014-08-07 20:51:02 +00:00
|
|
|
} else {
|
2014-08-09 19:04:48 +00:00
|
|
|
printf("</li></ul>\n </dd>\n <dt>%s</dt><dd><ul>\n\t <li>%s", $vend, $mod);
|
2014-08-07 20:51:02 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-14 00:28:54 +00:00
|
|
|
} else {
|
2014-08-07 20:51:02 +00:00
|
|
|
if ($vend eq $lastVend) {
|
|
|
|
printf(", %s", $mod);
|
|
|
|
} else {
|
|
|
|
if ($lastVend lt "Uemis" && $vend gt "Uemis") {
|
|
|
|
printf("\nUemis: Zürich SDA");
|
|
|
|
}
|
|
|
|
if ($lastVend eq "") {
|
|
|
|
printf("%s: %s", $vend, $mod);
|
|
|
|
} else {
|
|
|
|
printf("\n%s: %s", $vend, $mod);
|
|
|
|
}
|
|
|
|
}
|
2013-12-14 00:28:54 +00:00
|
|
|
}
|
2014-08-07 20:51:02 +00:00
|
|
|
$lastVend = $vend;
|
2017-01-15 03:22:21 +00:00
|
|
|
$lastMod = $mod;
|
2013-12-14 00:28:54 +00:00
|
|
|
}
|
|
|
|
if ($type eq "html") {
|
2013-12-15 16:16:06 +00:00
|
|
|
print("</li>\n\t</ul>\n </dd>\n</dl>");
|
2013-12-14 00:28:54 +00:00
|
|
|
}
|
|
|
|
close $fh;
|