summaryrefslogtreecommitdiffstats
path: root/scripts/dcTransport.pl
blob: 1d2e0dba4bc92a64c0db1dfae776a772f6411005 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/perl
#
# Extract supported divecomputers on Android and iOS from libdivecomputer source
#
# Usage:
#
# dcTransport.pl <path to libdivecomputer/src/descriptor.c> <outfile>
#
use Carp;

#set command line arguments
my ($infi, $outfi) = @ARGV;

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 $ftdi = "\/\/ FTDI";
my $bt =   "\/\/ BT";
my $ble =  "\/\/ BLE";
printf("// This segment of the source is automatically generated\n");
printf("// please edit scripts/dcTransport.pl , regenerated the code and copy it here\n\n");

my @android = ();
my @ios = ();
while (<$fh>) {
	if (/^\s*{\s*"([^\,]*)"\s*,\s*"([^\,]*)"\s*,\s*([^\,]*).*}/) {
		my $v = $1;
		my $p = $2;
		if (/$ftdi/) {
			push(@android, "$v,$p");
		}
		if (/$bt/) {
			push(@android, "$v,$p");
		}
		if (/$ble/) {
			push(@android, "$v,$p");
			push(@ios, "$v,$p");
		}
	}
}

my $lastMod;
my $lastVend;
my @sortedandroid = sort @android;
my @sortedios = sort @ios;
print("#if defined(Q_OS_ANDROID)\n\t/* BT, BLE and FTDI devices */\n");

my $endV;
foreach (@sortedandroid) {
	($vend, $mod) = split(',', $_);
	next if ($vend eq $lastVend && $mod eq $lastMod);
	if ($vend eq $lastVend) {
		printf(", {\"%s\"}", $mod);
	} else {
		printf($endV);
		printf("\tmobileProductList[\"%s\"] =\n\t\tQStringList({{\"%s\"}", $vend, $mod);
		$endV = "});\n";
	}
	$lastVend = $vend;
	$lastMod = $mod;
}
printf($endV);
$endV="";
printf("\n#endif\n#if defined(Q_OS_IOS)\n\t/* BLE only, Qt does not support classic BT on iOS */\n");
foreach (@sortedios) {
	($vend, $mod) = split(',', $_);
	next if ($vend eq $lastVend && $mod eq $lastMod);
	if ($vend eq $lastVend) {
		printf(", {\"%s\"}", $mod);
	} else {
		printf($endV);
		printf("\tmobileProductList[\"%s\"] =\n\t\tQStringList({{\"%s\"}", $vend, $mod);
		$endV = "});\n";
	}
	$lastVend = $vend;
	$lastMod = $mod;
}
printf($endV);
printf("\n#endif\n");
printf("// end of the automatically generated code\n");
close $fh;