summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-08 16:06:12 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-08 16:06:12 -0700
commit52d5172a700c6f0a0236eb43c36c636335f70e90 (patch)
tree4da317afa3a864ae01835df2fdc348143469004c /scripts
parent1fd00a3f6d84efbf5cd4b52a01ec05e1f74d05e6 (diff)
downloadsubsurface-52d5172a700c6f0a0236eb43c36c636335f70e90.tar.gz
Automate picking supported DCs on iOS and Android
We use a little script to create the code snippet. This script in return relies on comments that were added to the latest libdivecomputer source (in the Subsurface-branch). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dcTransport.pl85
1 files changed, 85 insertions, 0 deletions
diff --git a/scripts/dcTransport.pl b/scripts/dcTransport.pl
new file mode 100755
index 000000000..1d2e0dba4
--- /dev/null
+++ b/scripts/dcTransport.pl
@@ -0,0 +1,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;