-
Notifications
You must be signed in to change notification settings - Fork 7
/
BBBikePalm.pm
205 lines (185 loc) · 5.21 KB
/
BBBikePalm.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# -*- perl -*-
#
# $Id: BBBikePalm.pm,v 1.11 2008/01/19 23:02:40 eserte Exp $
# Author: Slaven Rezic
#
# Copyright (C) 2000,2008 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: [email protected]
# WWW: http://bbbike.de
#
# Palm-Routinen für BBBike
# in main muss definiert sein: is_in_path
# wenn in main folgendes definiert ist, wird es verwendet: status_message
use strict;
# main bbbike variables
use vars qw($os $tmpdir %tmpfiles $palm_doc_format $top);
my @prog_order = qw(txt2pdbdoc /usr/local/txt2pdbdoc/bin/txt2pdbdoc
pilot_makedoc
iSiloBSD iSiloLinux iSiloDOS
);
# module-private variables
use vars qw($win32_pdb_installer);
sub can_create_and_transfer_palm_docs {
((is_in_path("pilot_makedoc") ||
is_in_path("iSiloBSD") ||
is_in_path("iSiloLinux") ||
is_in_path("iSiloDOS") ||
is_in_path("txt2pdbdoc") ||
-x "/usr/local/txt2pdbdoc/bin/txt2pdbdoc")
&&
can_transfer_palm_docs());
}
sub can_transfer_palm_docs {
if ($os eq 'win') {
require Win32Util;
my $class = Win32Util::get_class_by_ext(".pdb") || "pdbfile";
$win32_pdb_installer = Win32Util::get_reg_cmd($class);
return (defined $win32_pdb_installer &&
$win32_pdb_installer ne "");
} else {
return 1 if (is_in_path("pilot-xfer"));
}
}
sub create_palm_button {
my $parent = shift;
my $get_endpoints_sub = shift;
$parent->Button
(-text => 'Palm',
-command => \&create_palm_doc,
);
}
sub create_palm_doc {
my $f = "$tmpdir/palmdoc-$$.";
my $doc = "$tmpdir/palmdoc-$$.pdb";
my $is_empty = sub {
if (!-r $f || -z $f) {
die "Datei $f existiert nicht bzw. ist leer";
}
};
if ($palm_doc_format eq 'isilo') {
BBBikePalm::to_top(\@prog_order,
qw(iSiloBSD iSiloLinux iSiloDOS));
}
foreach my $check_sys (@prog_order) {
my $full_path = is_in_path($check_sys);
if (defined $full_path) {
if ($check_sys =~ /isilo/i) {
if ($os eq 'win') {
# isilodos is a real DOS program ... only understanding 8.3
$f = "$tmpdir\\palmtmp.htm";
$doc = "$tmpdir\\palmtmp.pdb";
} else {
$f .= "html";
}
open(PALM, ">$f") or
die "$f kann nicht geschrieben werden: $!";
print PALM route_info_to_html();
close PALM;
$is_empty->();
my @cmd;
if ($os eq 'win') {
@cmd = "$full_path -y $f $doc";
} else {
@cmd = ($full_path, "-y", $f, $doc);
}
#warn "Executing @cmd\n";
system @cmd;
} else {
# XXX better move to bbbike?
my $route_name = "BBBike-Route";
if (defined $main::show_route_start and
defined $main::show_route_ziel) {
my($start, $ziel);
$start = Strasse::short(Strassen::strip_bezirk($main::show_route_start), 3); # Start besser abkürzen --- ist meist immer der Gleiche
$ziel = Strasse::short(Strassen::strip_bezirk($main::show_route_ziel), 2);
$route_name = "BBBike: $start-$ziel";
}
$f .= "txt";
open(PALM, ">$f") or
die "$f kann nicht geschrieben werden: $!";
print PALM BBBikePalm::strip_html_tags(route_info_to_html()); # or route_info_to_text???
close PALM;
$is_empty->();
if ($check_sys =~ /pilot_makedoc/) {
system($full_path, $f, $doc, $route_name);
} elsif ($check_sys =~ /txt2pdbdoc/) {
system($full_path, $route_name, $f, $doc);
}
}
last;
}
}
if (!-r $doc) {
die "Doc-Datei $doc konnte nicht erzeugt werden";
}
if (defined $win32_pdb_installer) {
Win32Util::start_cmd($win32_pdb_installer, $doc);
} else {
system("pilot-xfer -i $doc &");
BBBikePalm::hot_sync_message($top);
}
$tmpfiles{$doc}++;
}
sub BBBikePalm::strip_html_tags {
my $text = shift;
$text =~ s/<[^>]+>//gs;
$text;
}
sub BBBikePalm::to_top {
my($listref, @to_top) = @_;
my(%to_top) = map { ($_ => 1) } @to_top;
my @new_list = @to_top;
foreach (@$listref) {
push @new_list, $_ if !exists $to_top{$_};
}
@$listref = ();
foreach (@new_list) {
push @$listref, $_;
}
}
sub BBBikePalm::hot_sync_message {
my $msg = "Hotsync-Button drücken!";
if (defined &main::status_message) {
main::status_message($msg, "infodlg");
} else {
my $top = shift;
$top->messageBox(-title => "Hotsync",
-text => $msg);
}
}
######################################################################
# Routines for bbbike.cgi using Palm::PalmDoc
sub BBBikePalm::route2palm {
require Route::Descr;
require Palm::PalmDoc;
my(%args) = @_;
my $fh = delete $args{-fh};
my $file = delete $args{-file};
my $out = Route::Descr::convert(%args);
my $doc = Palm::PalmDoc->new;
if ($out->{Goal}) {
# Who is causing the bug behind this restriction?
my $title = substr("$out->{Start} - $out->{Goal}", 0, 31);
$doc->title($title);
} else {
$doc->title("BBBike-Route");
}
$doc->body(join("\n\n", map { join("\t", @$_) } @{$out->{Lines}}, $out->{Footer}));
#$doc->compression(1); # XXX no effect?
if ($fh) {
binmode $fh;
print $fh $doc->pdb_header,$doc->body;
} elsif ($file) {
open(F, ">$file") or die "Can't write to $file: $!";
binmode F;
print F $doc->pdb_header,$doc->body;
close F;
} else {
return $doc->pdb_header . $doc->body;
}
}
1;
__END__