aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/parse-descriptor.pl
blob: 19d4085e80f630969a4474b0cebac38877dd8780 (plain) (blame)
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
#!/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
use Carp;

#set command line arguments
my ($infi, $outfi) = @ARGV;
my ($type) = $outfi =~ /\.([^.]+)$/;

if ($infi !~ /.*descriptor.c/) {
	croak "run as $ARGV[0] <path to descriptor.c> <outputfile>\n";
}

open(my $fh, "<", $infi) || croak "can't open $infi: $!";
open(STDOUT, ">", $outfi) || croak "can't open $outfi: $!";

my $lastVend = "";
my @descriptors = ();
while (<$fh>) {
	if (/^\s*{\s*"([^\,]*)"\s*,\s*"([^\,]*)"\s*,\s*([^\,]*).*}/) {
		push(@descriptors, "$1,$2");
	}
}
my @sortedDescriptors = sort @descriptors;
foreach (@sortedDescriptors) {
	($vend, $mod) = split(',', $_);
	if ($type eq "html") {
		if ($vend eq $lastVend) {
			printf(", %s", $mod);
		} else {
			if ($lastVend lt "Uemis" && $vend gt "Uemis") {
				printf("</li>\n\t</ul>\n    </dd>\n    <dt>Uemis</dt><dd>\n\t<ul>\n\t    <li>Zürich SDA");
			}
			if ($lastVend eq "") {
				printf("<dl><dt>%s</dt><dd>\n\t<ul>\n\t    <li>%s", $vend, $mod);
			} else {
				printf("</li>\n\t</ul>\n    </dd>\n    <dt>%s</dt><dd>\n\t<ul>\n\t    <li>%s", $vend, $mod);
			}
		}
	} else {
		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);
			}
		}
	}
	$lastVend = $vend;
}
if ($type eq "html") {
    print("</li>\n\t</ul>\n    </dd>\n</dl>");
}
close $fh;