line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: ListDB.pm Mon Aug 5 19:57:50 2002 $ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION Sub class of Palm::PDB |
6
|
|
|
|
|
|
|
# specialized for listDB by Andrew Low |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# COPYRIGHT (c) 2002 by Rudiger Peusquens |
9
|
|
|
|
|
|
|
# All rights reserved. |
10
|
|
|
|
|
|
|
# This program is free software; you can redistribute it |
11
|
|
|
|
|
|
|
# and/or modify it under the same terms as Perl itself. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# AUTHOR Rudiger Peusquens |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# HISTORY |
16
|
|
|
|
|
|
|
# $Log$ |
17
|
|
|
|
|
|
|
# |
18
|
1
|
|
|
1
|
|
577
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Palm::ListDB; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
2633
|
use Palm::StdAppInfo(); |
|
1
|
|
|
|
|
12376
|
|
|
1
|
|
|
|
|
22
|
|
23
|
1
|
|
|
1
|
|
11
|
use Palm::Raw(); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
20
|
|
24
|
1
|
|
|
1
|
|
5
|
use Carp qw(carp); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
95
|
|
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
5
|
use vars qw( $VERSION @ISA ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1366
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
@ISA = qw( Palm::StdAppInfo Palm::Raw ); |
29
|
|
|
|
|
|
|
$VERSION = '0.25'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub import { |
32
|
1
|
|
|
1
|
|
12
|
&Palm::PDB::RegisterPDBHandlers( __PACKAGE__, |
33
|
|
|
|
|
|
|
[ "LSdb", "DATA" ], |
34
|
|
|
|
|
|
|
[ "LSdb", "" ] ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub new { |
38
|
0
|
|
|
0
|
1
|
|
my $classname = shift; |
39
|
0
|
|
|
|
|
|
my $self = $classname->SUPER::new(@_); |
40
|
|
|
|
|
|
|
# Create a generic PDB. No need to rebless it, |
41
|
|
|
|
|
|
|
# though. |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->{name} = 'ListDB'; # give it a default name |
44
|
0
|
|
|
|
|
|
$self->{creator} = 'LSdb'; |
45
|
0
|
|
|
|
|
|
$self->{type} = 'DATA'; |
46
|
0
|
|
|
|
|
|
$self->{attributes}{resource} = 0; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Initialize the AppInfo block |
49
|
0
|
|
|
|
|
|
$self->{appinfo} = { |
50
|
|
|
|
|
|
|
writeProtect => 0, # *ListDb's* write protection |
51
|
|
|
|
|
|
|
lastCategory => 0xff, # default: All |
52
|
|
|
|
|
|
|
field1 => '', |
53
|
|
|
|
|
|
|
field2 => '', |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Add the standard AppInfo block stuff |
57
|
0
|
|
|
|
|
|
&Palm::StdAppInfo::seed_StdAppInfo($self->{appinfo}); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Give the PDB a blank sort block |
60
|
0
|
|
|
|
|
|
$self->{sort} = undef; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Give the PDB an empty list of records |
63
|
0
|
|
|
|
|
|
$self->{records} = []; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return $self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub ParseAppInfoBlock { |
69
|
0
|
|
|
0
|
1
|
|
my ($self, $data) = @_; |
70
|
0
|
|
|
|
|
|
my $appinfo = {}; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
&Palm::StdAppInfo::parse_StdAppInfo( $appinfo, $data ); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# don't know what first 2 bytes are for |
75
|
0
|
|
|
|
|
|
my ($C1, $C2, $field1, $field2) = unpack 'C2a16a16', $appinfo->{other}; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$appinfo->{ writeProtect } = $C1; |
78
|
0
|
|
|
|
|
|
$appinfo->{ lastCategory } = $C2; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# trim after first NUL (renaming might have left "Foo\0bar") |
81
|
0
|
|
|
|
|
|
$field1 =~ s/\0.*$//; |
82
|
0
|
|
|
|
|
|
$field2 =~ s/\0.*$//; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$appinfo->{field1} = $field1; |
85
|
0
|
|
|
|
|
|
$appinfo->{field2} = $field2; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $appinfo; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub PackAppInfoBlock { |
91
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my %data = ( writeProtect => 0, |
94
|
|
|
|
|
|
|
lastCategory => 0xff ); # default 0xff : "All" |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
foreach my $attr (qw(field1 field2)) { |
97
|
0
|
0
|
|
|
|
|
if ( defined $self->{appinfo}{$attr} ) { |
98
|
0
|
|
|
|
|
|
$data{$attr} = $self->{appinfo}{$attr}; |
99
|
|
|
|
|
|
|
} else { |
100
|
0
|
|
|
|
|
|
$data{$attr} = ''; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
0
|
0
|
|
|
|
|
if ( $self->{appinfo}{writeProtect} ) { |
104
|
0
|
|
|
|
|
|
$data{writeProtect} = 1; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
0
|
|
|
|
|
if ( defined $self->{appinfo}{lastCategory} ) { |
107
|
0
|
|
|
|
|
|
$data{lastCategory} = $self->{appinfo}{lastCategory}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Pack the non-category part of the AppInfo block |
111
|
|
|
|
|
|
|
# We need to pad the last 202 bytes. |
112
|
0
|
|
|
|
|
|
$self->{appinfo}{other} = pack 'C2a16a16x202', |
113
|
|
|
|
|
|
|
@data{qw(writeProtect lastCategory |
114
|
|
|
|
|
|
|
field1 field2)}; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Pack the AppInfo block |
117
|
0
|
|
|
|
|
|
return &Palm::StdAppInfo::pack_StdAppInfo($self->{appinfo}); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub ParseRecord { |
122
|
0
|
|
|
0
|
1
|
|
my ($self, %record) = @_; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
delete $record{offset}; # This is useless |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# split into fields |
127
|
|
|
|
|
|
|
# ignore first 3 chars; they are offsets |
128
|
0
|
|
|
|
|
|
my ($field1, $field2, $note) = split /\0/, substr( $record{ data }, 3 ); |
129
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
$record{ field1 } = $field1 unless $field1 eq ''; |
131
|
0
|
0
|
|
|
|
|
$record{ field2 } = $field2 unless $field2 eq ''; |
132
|
0
|
0
|
|
|
|
|
unless ( $note eq '' ) { |
133
|
|
|
|
|
|
|
# make sure we have our local newlines |
134
|
0
|
|
|
|
|
|
( $record{ note } = $note ) =~ s/\012/\n/g; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
delete $record{ data }; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
return \%record; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub PackRecord { |
143
|
0
|
|
|
0
|
1
|
|
my ($self, $record) = @_; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
my %data = (); |
146
|
0
|
|
|
|
|
|
foreach my $attr (qw(field1 field2 note)) { |
147
|
0
|
0
|
|
|
|
|
if ( defined $record->{$attr} ) { |
148
|
0
|
|
|
|
|
|
$data{$attr} = $record->{$attr}; |
149
|
|
|
|
|
|
|
} else { |
150
|
0
|
|
|
|
|
|
$data{$attr} = ''; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# fix note if it's a array ref |
155
|
0
|
0
|
|
|
|
|
$data{note} = join "\012", @{ $data{note} } |
|
0
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
if ref $data{note} eq 'ARRAY'; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
$data{note} =~ s/\r?\n\r?/\012/g; # fix PalmOS newlines |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
my $data = pack('CCC', |
161
|
|
|
|
|
|
|
3, |
162
|
|
|
|
|
|
|
4 + length( $data{field1} ), |
163
|
|
|
|
|
|
|
5 + length( $data{field1} ) |
164
|
|
|
|
|
|
|
+ length( $data{field2} ) ); |
165
|
0
|
|
|
|
|
|
$data .= $data{field1} . "\0"; |
166
|
0
|
|
|
|
|
|
$data .= $data{field2} . "\0"; |
167
|
0
|
|
|
|
|
|
$data .= $data{note} . "\0"; |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
return $data ; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub new_Record { |
173
|
0
|
|
|
0
|
1
|
|
my ($self, %args) = @_; |
174
|
0
|
|
|
|
|
|
my $record = $self->SUPER::new_Record(); |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# maybe set category |
177
|
0
|
0
|
|
|
|
|
if ( defined( my $category = $args{category} ) ) { |
178
|
0
|
|
|
|
|
|
my @categories = @{ $self->{appinfo}{categories} }; |
|
0
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
my $catIndex = undef; |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
0
|
|
|
|
if ( $category eq '' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# empty string silently mapped to Unfiled |
183
|
0
|
|
|
|
|
|
$catIndex = 0; |
184
|
|
|
|
|
|
|
} elsif ( $category =~ /\D/ ) { |
185
|
|
|
|
|
|
|
# category by name |
186
|
0
|
|
|
|
|
|
foreach my $i ( 0 .. $#categories ) { |
187
|
0
|
|
|
|
|
|
my $cat = $categories[$i]; |
188
|
0
|
0
|
0
|
|
|
|
if ( defined $cat->{name} and $cat->{name} eq $category ) { |
189
|
0
|
|
|
|
|
|
$catIndex = $i; |
190
|
0
|
|
|
|
|
|
last; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} elsif ( $category >= 0 and $category <= $#categories ) { |
194
|
|
|
|
|
|
|
# category by index |
195
|
0
|
|
|
|
|
|
$catIndex = $category; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# fall back to "Unfiled" |
199
|
0
|
0
|
|
|
|
|
unless ( defined $catIndex ) { |
200
|
0
|
|
|
|
|
|
carp "Bad category `$category'. Using `Unfiled' (0)"; |
201
|
0
|
|
|
|
|
|
$catIndex = 0; |
202
|
|
|
|
|
|
|
} |
203
|
0
|
|
|
|
|
|
$record->{category} = $catIndex; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# set field1, field2 and note |
207
|
0
|
|
|
|
|
|
foreach my $field (qw(field1 field2 note)) { |
208
|
0
|
0
|
|
|
|
|
if ( defined $args{$field} ) { |
209
|
0
|
|
|
|
|
|
$record->{$field} = $args{$field}; |
210
|
|
|
|
|
|
|
} else { |
211
|
0
|
|
|
|
|
|
$record->{$field} = undef; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
return $record; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
1; # module must return success |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
__END__ |