]> git.street.me.uk Git - andy/viking.git/blob - viking-remote
Document previous patches
[andy/viking.git] / viking-remote
1 #!/usr/bin/perl
2
3 #
4 # geo://wpname:cmnt@34.15,-118.15/topo=/somedir,aerial=/someotherdir
5 #
6
7 die "Usage: viking-remote uri\n" if ( $#ARGV < 0 );
8
9 if ( $ARGV[0] eq "debug" ) {
10   $DEBUG = 1;
11   shift @ARGV;
12 } else {
13   $DEBUG = 0;
14 }
15
16 ($ARGV[0] =~ m<(geo:)?/*([^/]*)(/(.*))?>) or die "Bad URI";
17 $loc = $2;
18 $extras = $4;
19
20 if ( $loc =~ /^(GC[0-9A-Z]+)$/ ) {
21  $gc = $loc;
22  $loc=`gcfetchtxt http://www.geocaching.com/seek/cache_details.aspx?wp=$loc|head -2|tail +2`;
23 }
24
25 # have a lot of fun...
26 ($loc =~ /^(([^:@]*)(:([^:@]*))?@)?N?(S?)\s*((([0-9'"`°o\-\.])|(° ))*)[, ]\s*E?(W?)\s*(([0-9'"`o\-\.]|(° ))*)(:([0-9\-\.]*))?$/)
27     or die "Bad URI";
28
29 $wp = $2 ? $2 : ( $gc ? $gc : "waypoint" );
30 $cmt = $4; $lat = $6; $lon = $11; $alt = $15;
31
32 $latfact = ($5 eq "S") ? -1 : 1;
33 $lonfact = ($10 eq "W") ? -1 : 1;
34
35 if ( $lat =~ /^(-?)(\d*)[°'"`o] *([\d.]*)$/ ) {
36   $lat = ($2 + ($3/60)) * ($1 ? -1 : 1);
37 }
38 if ( $lon =~ /^(-?)(\d*)[°'"`o] *([\d.]*)$/ ) {
39   $lon = ($2 + ($3/60)) * ($1 ? -1 : 1);
40  }
41
42 $lat *= $latfact;
43 $lon *= $lonfact;
44
45 if ( $extras =~ /^(auto)?street/ ) {
46   $mode = "latlon";
47   $zoom = 4.205;
48 } else {
49   $mode = "utm";
50   $zoom = 4.0;
51 }
52
53 if ( $DEBUG ) {
54   open(PIPE, "|cat");
55 } else {
56   open(PIPE, "|viking -- -");
57 }
58
59 print PIPE <<ENDDATA;
60 #VIKING GPS Data file http://gpsmaps.org/viking/
61 xmpp=$zoom;
62 ympp=$zoom;
63 lat=$lat
64 lon=$lon
65 mode=$mode
66 ENDDATA
67
68 @maps = split(',', $extras);
69 foreach $map (@maps) {
70   $maptype = -1;
71   $mapname = $map;
72   $mapdir = "";
73   $auto = "f";
74   if ( $map =~ /^auto/ ) {
75     $auto = "t";
76     $map = substr($map, 4, 999);
77   }
78   if ( $map =~ /^street/i ) {
79     $maptype = 9;
80   } elsif ( $map =~ /^expedia/i ) {
81     $maptype = 5;
82   } elsif ( $map =~ /^urban/ || $map =~ /^color/ ) {
83     $maptype = 4;
84   } elsif ( $map =~ /^topo/ || $map =~ /^terraserver/ ) {
85     $maptype = 2;
86   } elsif ( $map =~ /^ortho/ || $map =~ /^aerial/ ) {
87     $maptype = 1;
88   }
89   if ( $maptype != -1 ) {
90     @mapanddir = split('=', $map);
91     if ( $#mapanddir > 0 ) {
92       $mapname = $mapanddir[0];
93       $mapdir = $mapanddir[1];
94     }
95     print PIPE <<ENDDATA;
96
97 ~Layer Map
98 name=$mapname
99 mode=$maptype
100 directory=$mapdir
101 autodownload=$auto
102 ~EndLayer
103 ENDDATA
104   }
105 }
106
107 print PIPE <<ENDDATA;
108
109 ~Layer TrackWaypoint
110 name=$wp
111 tracks_visible=t
112 waypoints_visible=t
113 ~LayerData
114 type="waypoint" latitude="$lat" longitude="$lon" name="$wp" comment="$cmt" altitude="$alt"
115 ~EndLayerData
116 ~EndLayer
117 ENDDATA
118
119
120 close(PIPE);