line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# --*-Perl-*-- |
2
|
|
|
|
|
|
|
# $Id: File.pm 18 2004-12-12 07:41:44Z tandler $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Biblio::File; |
6
|
2
|
|
|
2
|
|
58
|
use 5.006; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
69
|
|
7
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
66
|
|
8
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
64
|
|
9
|
|
|
|
|
|
|
#use English; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# for debug: |
12
|
2
|
|
|
2
|
|
10
|
use Data::Dumper; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
158
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN { |
15
|
2
|
|
|
2
|
|
10
|
use vars qw($Revision $VERSION); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
257
|
|
16
|
2
|
50
|
|
2
|
|
36
|
my $major = 1; q$Revision: 18 $ =~ /: (\d+)/; my ($minor) = ($1); $VERSION = "$major." . ($minor<10 ? '0' : '') . $minor;
|
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
63
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# This class is a subclass of DBI::db, exported by the DBI module. |
21
|
2
|
|
|
2
|
|
536
|
use Biblio::BP; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
17
|
|
22
|
|
|
|
|
|
|
# select destination format etc. |
23
|
|
|
|
|
|
|
Biblio::BP::format("auto", "canon:8859-1"); |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
13
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2310
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
30
|
2
|
|
33
|
|
|
11
|
my $class = ref($self) || $self; |
31
|
2
|
|
|
|
|
8
|
my %args = @_; |
32
|
2
|
|
|
|
|
9
|
$self = { %args }; |
33
|
2
|
|
|
|
|
14
|
return bless $self, $class; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub DESTROY ($) { |
39
|
2
|
|
|
2
|
|
1013
|
my $self = shift; |
40
|
2
|
|
|
|
|
13
|
$self->disconnect(); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
2
|
0
|
601
|
sub disconnect { |
44
|
|
|
|
|
|
|
# as long as we don't have to save anything, ignore this! |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
# methods |
50
|
|
|
|
|
|
|
# |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub getCiteKeys { |
54
|
|
|
|
|
|
|
# return all paper IDs |
55
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
56
|
0
|
|
|
|
|
0
|
return keys %{$self->refs()}; |
|
0
|
|
|
|
|
0
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub queryPapers { |
62
|
|
|
|
|
|
|
# query papers, look in $queryFields for $pattern |
63
|
2
|
|
|
2
|
0
|
1350
|
my $self = shift; |
64
|
2
|
|
|
|
|
9
|
my ($pattern, $queryFields, $resultFields, $ignoreCase) = @_; |
65
|
2
|
50
|
|
|
|
9
|
$ignoreCase = 1 if not defined($ignoreCase); |
66
|
2
|
50
|
|
|
|
179
|
$pattern = lc($pattern) if($ignoreCase); |
67
|
|
|
|
|
|
|
# no query yet ... |
68
|
2
|
|
|
|
|
9
|
return $self->refs(); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub queryPaperWithId ($$) { |
72
|
2
|
|
|
2
|
0
|
746
|
my ($self, $id) = @_; |
73
|
2
|
|
|
|
|
7
|
return $self->refs()->{$id}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# |
77
|
|
|
|
|
|
|
# |
78
|
|
|
|
|
|
|
# add & update papers |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
# |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub storePaper { |
84
|
1
|
|
|
1
|
0
|
916
|
my ($self, $ref, $update) = @_; |
85
|
1
|
|
|
|
|
4
|
my $id = $ref->{'CiteKey'}; |
86
|
1
|
|
|
|
|
4
|
my $old_ref = $self->queryPaperWithId($id); |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
101
|
print STDERR "storePaper not yet supported ...\n"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
# |
95
|
|
|
|
|
|
|
# shortcuts |
96
|
|
|
|
|
|
|
# |
97
|
|
|
|
|
|
|
# |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub replaceShortcuts { |
100
|
|
|
|
|
|
|
# look in $text and replace all shortcuts |
101
|
0
|
|
|
0
|
0
|
0
|
my ($self, $text) = @_; |
102
|
0
|
0
|
|
|
|
0
|
return undef unless defined($text); |
103
|
|
|
|
|
|
|
# check, if there is any {} field at all -> this is *much* faster! |
104
|
0
|
0
|
|
|
|
0
|
return $text unless $text =~ /\{/; |
105
|
0
|
|
|
|
|
0
|
my $shortcuts = $self->shortcuts(); |
106
|
0
|
0
|
|
|
|
0
|
my $pattern = join("|", map( /:$/ ? "$_.*" : $_, (keys(%{$shortcuts})))); |
|
0
|
|
|
|
|
0
|
|
107
|
|
|
|
|
|
|
#print $pattern; |
108
|
0
|
|
|
|
|
0
|
$text =~ s/\{($pattern)\}/ $self->expandShortcut($shortcuts, $1) /ge; |
|
0
|
|
|
|
|
0
|
|
109
|
0
|
|
|
|
|
0
|
return $text; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
sub expandShortcut { |
112
|
0
|
|
|
0
|
0
|
0
|
my ($self, $shortcuts, $text) = @_; |
113
|
0
|
|
|
|
|
0
|
my @pars = split(/:/, $text); |
114
|
0
|
0
|
|
|
|
0
|
my $k = shift @pars; if( @pars ) { $k = "$k:"; } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
115
|
0
|
|
|
|
|
0
|
my $v = $shortcuts->{$k}; |
116
|
0
|
|
|
|
|
0
|
$v =~ s/%(\d)/ $pars[$1-1] /ge; |
|
0
|
|
|
|
|
0
|
|
117
|
|
|
|
|
|
|
#print "\n\n$k ---- $v\n\n"; |
118
|
0
|
|
|
|
|
0
|
return $v; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub shortcuts { |
122
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
123
|
0
|
0
|
|
|
|
0
|
return $self->{'shortcuts'} if defined($self->{'shortcuts'}); |
124
|
0
|
|
|
|
|
0
|
return {}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub updateShortcuts { |
128
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
129
|
|
|
|
|
|
|
# delete $self->{'shortcuts'}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# |
134
|
|
|
|
|
|
|
# |
135
|
|
|
|
|
|
|
# private file access |
136
|
|
|
|
|
|
|
# |
137
|
|
|
|
|
|
|
# |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub refs { |
140
|
|
|
|
|
|
|
# return all papers as defined in DB |
141
|
4
|
|
|
4
|
0
|
9
|
my $self = shift; |
142
|
4
|
|
|
|
|
15
|
my $refs = $self->{'refs'}; |
143
|
4
|
100
|
|
|
|
12
|
if( not defined($refs) ) { |
144
|
|
|
|
|
|
|
# maybe handle multiple files if file() points to an array |
145
|
2
|
|
|
|
|
7
|
$refs = $self->readFile($self->file()); |
146
|
2
|
|
|
|
|
9
|
$self->{'refs'} = $refs; |
147
|
|
|
|
|
|
|
} |
148
|
4
|
|
|
|
|
20
|
return $refs; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
2
|
|
50
|
2
|
0
|
12
|
sub file { return shift->{'file'} || 'biblio.bib'; } |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub readFile { |
154
|
2
|
|
|
2
|
0
|
5
|
my ($self, $file) = @_; |
155
|
2
|
50
|
|
|
|
6
|
print STDERR "Read $file ...\n" unless $self->{quiet}; |
156
|
2
|
|
|
|
|
12
|
my $fmt = Biblio::BP::open($file); |
157
|
2
|
50
|
|
|
|
9
|
return undef unless defined $fmt; |
158
|
2
|
|
|
|
|
3
|
my ($ref, $key); |
159
|
2
|
|
|
|
|
4
|
my $refs = {}; |
160
|
2
|
|
|
|
|
7
|
my $rn = 0; |
161
|
2
|
|
|
|
|
12
|
while ( defined($ref = Biblio::BP::readpbib()) ) { |
162
|
132
|
|
|
|
|
193
|
$rn++; |
163
|
132
|
|
|
|
|
199
|
$key = $ref->{'CiteKey'}; |
164
|
132
|
|
|
|
|
573
|
$refs->{$key} = $ref; |
165
|
|
|
|
|
|
|
} |
166
|
2
|
50
|
|
|
|
13
|
print STDERR "$rn records read from $file" unless $self->{quiet}; |
167
|
2
|
50
|
|
|
|
10
|
Biblio::BP::print_error_totals() unless $self->{quiet}; |
168
|
2
|
50
|
|
|
|
8
|
print STDERR ".\n" unless $self->{quiet}; |
169
|
2
|
|
|
|
|
13
|
Biblio::BP::close(); |
170
|
2
|
|
|
|
|
7
|
return $refs; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# |
176
|
|
|
|
|
|
|
# $Log: File.pm,v $ |
177
|
|
|
|
|
|
|
# Revision 1.2 2003/04/14 09:43:55 ptandler |
178
|
|
|
|
|
|
|
# fixed prototype |
179
|
|
|
|
|
|
|
# |
180
|
|
|
|
|
|
|
# Revision 1.1 2003/01/21 10:25:08 ptandler |
181
|
|
|
|
|
|
|
# support for Biblio::File |
182
|
|
|
|
|
|
|
# |