- Notifications
You must be signed in to change notification settings - Fork7
/
Copy pathGPS.pm
123 lines (101 loc) · 2.37 KB
/
GPS.pm
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- perl -*-
#
# Author: Slaven Rezic
#
# Copyright (C) 2001,2004,2012 Slaven Rezic. All rights reserved.
# This package is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# Mail: slaven@rezic.de
# WWW: http://bbbike.de
#
# XXX rename to BBBikeGPS, to avoid conflicts with GPS:: namespace
# XXX no --- BBBikeGPS is already taken...
packageGPS;
use strict;
use varsqw(@gps $_UTF8_BOM);
# KML is checked before GPX, because the KML magic is more strict
@gps =qw(GpsmanData MyNMEA G7toWin_2 G7toWin_ASCII Ovl WaypointPlus MPS Gardown KML GPX Gpsbabel);
$_UTF8_BOM ="\xef\xbb\xbf";
subnew {bless {},shift }
suball {@gps }
subpreload {
my$self =shift;
my$mod =shift;
my$fullmod ='GPS::' .$mod;
eval"require$fullmod";
die$@if$@;
$fullmod;
}
subtransfer_to_file { 1}
subdefault_extension {".txt" }
subtransfer {
my($self,%args) =@_;
my$file =$args{-file}ordie"-file argument is missing";
my$res =$args{-res}ordie"-res argument is missing";
openmy$F,">$file"ordie"Can't write to$file:$!";
binmode$F;
print$F$res;
close$F;
}
submagics {
my$self =shift;
die"No magics for$self defined";
}
# check for magic
subcheck {
my$self =shift;
my$file =shift;
my(%args) =@_;
my($fh,$lines_ref) =$self->overread_trash($file,%args);
defined$fh;
}
# Return ($fh, \@lines)
# $fh is a filehandle or undef
# @lines is an array reference of the magic lines
suboverread_trash {
my$self =shift;
my$file =shift;
my(%args) =@_;
my(@magics) =$self->magics;
my@last_lines;
my$found = 0;
openmy$fh,$file
ordie"Die Datei$file kann nicht geöffnet werden:$!";
binmode$fh;
FILETRY: {
while(<$fh>) {
if (@magics == 1) {
if (/$magics[0]/) {
push@last_lines,$_;
$found = 1;
last FILETRY;
}
last FILETRYif (!$args{-fuzzy});
}else {
if (@last_lines ==@magics) {
shift@last_lines;
}
push@last_lines,$_;
if (@last_lines ==@magics) {
TRY: {
for(my$i = 0;$i<=$#last_lines;$i++) {
last TRYif ($last_lines[$i] !~/$magics[$i]/);
}
$found = 1;
last FILETRY;
}
last FILETRYif (!$args{-fuzzy});
}
}
}
}
if ($found) {
($fh, \@last_lines);
}else {
close$fh;
(undef, []);
}
}
1;
__END__