line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# --*-Perl-*-- |
2
|
|
|
|
|
|
|
# $Id: BibliographyStyle.pm 11 2004-11-22 23:56:20Z tandler $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package PBib::BibliographyStyle; |
6
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
7
|
1
|
|
|
1
|
|
1260
|
use English; |
|
1
|
|
|
|
|
5881
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
2874
|
use charnames ':full'; # enable \N{unicode char name} in strings |
|
1
|
|
|
|
|
54019
|
|
|
1
|
|
|
|
|
9
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# for debug: |
11
|
1
|
|
|
1
|
|
247
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
93
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
BEGIN { |
14
|
1
|
|
|
1
|
|
6
|
use vars qw($Revision $VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
121
|
|
15
|
1
|
50
|
|
1
|
|
3
|
my $major = 1; q$Revision: 11 $ =~ /: (\d+)/; my ($minor) = ($1); $VERSION = "$major." . ($minor<10 ? '0' : '') . $minor;
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
28
|
|
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# superclass |
19
|
|
|
|
|
|
|
# use PBib::Style; |
20
|
1
|
|
|
1
|
|
7
|
use base qw(PBib::Style); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1436
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# used modules |
23
|
|
|
|
|
|
|
#use FileHandle; |
24
|
|
|
|
|
|
|
#use File::Basename; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# module variables |
28
|
|
|
|
|
|
|
#use vars qw(mmmm); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
# access methods |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
# |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
4
|
0
|
6
|
sub options { my $self = shift; return $self->converter()->bibOptions(); } |
|
4
|
|
|
|
|
17
|
|
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
4
|
0
|
21
|
sub includeAllRefs { return shift->fieldOption("all"); } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub text { |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
# generate bibliography |
45
|
|
|
|
|
|
|
# |
46
|
2
|
|
|
2
|
0
|
6
|
my ($self, $refField) = @_; |
47
|
2
|
|
|
|
|
7
|
$self->{'refID'} = $refField; |
48
|
2
|
|
|
|
|
23
|
$self->logMessage("bibliography item [", $self->refID(), "] found"); |
49
|
2
|
|
|
|
|
9
|
my $rc = $self->converter(); |
50
|
2
|
|
|
|
|
8
|
my $rf = $rc->refStyle(); |
51
|
2
|
|
|
|
|
11
|
my $ri = $rc->itemStyle(); |
52
|
2
|
|
|
|
|
4
|
my ($ref, $key); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# check for options ... |
55
|
2
|
50
|
|
|
|
10
|
if( $refField =~ s/^\s*:\s*([^\|\[\]]*)\s*\|\s*// ) { |
56
|
0
|
|
|
|
|
0
|
my $options = $self->parseFieldOptions($1); |
57
|
0
|
|
|
|
|
0
|
$self->{'fieldOptions'} = $options; |
58
|
|
|
|
|
|
|
#print Dumper $options; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
#print "$refField\n"; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
9
|
my $items = $self->items(); |
63
|
2
|
|
|
|
|
11
|
my $query = $self->convertQuery($refField); |
64
|
2
|
50
|
|
|
|
9
|
if( $query ) { |
65
|
0
|
|
|
|
|
0
|
$items = $self->selectItems($query, $items); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# sort items |
69
|
|
|
|
|
|
|
#print "sort ...\n"; |
70
|
2
|
|
|
|
|
3
|
my %item_keys; |
71
|
2
|
|
|
|
|
5
|
foreach $ref (@{$items}) { |
|
2
|
|
|
|
|
7
|
|
72
|
112
|
|
|
|
|
295
|
$key = $ri->sortkeyFor($ref); |
73
|
112
|
|
|
|
|
324
|
while( exists($item_keys{$key}) ) { |
74
|
0
|
|
|
|
|
0
|
$self->warn("duplicate sort key $key"); |
75
|
0
|
|
|
|
|
0
|
$key = $key . "#"; |
76
|
|
|
|
|
|
|
} |
77
|
112
|
|
|
|
|
386
|
$item_keys{$key} = $ref; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# format items |
81
|
|
|
|
|
|
|
#print "format ...\n"; |
82
|
2
|
|
|
|
|
6
|
my @bibitems; |
83
|
2
|
|
|
|
|
58
|
foreach $key (sort(keys(%item_keys))) { |
84
|
112
|
|
|
|
|
246
|
$ref = $item_keys{$key}; |
85
|
112
|
|
|
|
|
304
|
push @bibitems, $ri->formatWith($ref); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
22
|
my $outDoc = $rc->outDoc(); |
89
|
2
|
|
|
|
|
8
|
return $outDoc->bibitems_start() . |
90
|
|
|
|
|
|
|
join($outDoc->bibitems_separator(), @bibitems) . |
91
|
|
|
|
|
|
|
$outDoc->bibitems_end(); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# |
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
# helper methods |
97
|
|
|
|
|
|
|
# |
98
|
|
|
|
|
|
|
# |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub items { |
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
# return a list of items for bibliography |
103
|
|
|
|
|
|
|
# |
104
|
4
|
|
|
4
|
0
|
8
|
my ($self) = @_; |
105
|
4
|
50
|
|
|
|
14
|
if( $self->includeAllRefs() ) { |
106
|
0
|
|
|
|
|
0
|
my @items = keys %{$self->converter()->refs()}; |
|
0
|
|
|
|
|
0
|
|
107
|
|
|
|
|
|
|
#print "@items\n"; |
108
|
0
|
|
|
|
|
0
|
return \@items; |
109
|
|
|
|
|
|
|
} |
110
|
4
|
|
|
|
|
16
|
return $self->converter()->knownIDs(); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
0
|
0
|
0
|
sub selectItems { my ($self, $query, $items) = @_; |
114
|
0
|
|
|
|
|
0
|
my (@matches, $ref); |
115
|
0
|
|
|
|
|
0
|
foreach my $refID (@$items) { |
116
|
0
|
|
|
|
|
0
|
$ref = $self->converter()->entries($refID); |
117
|
|
|
|
|
|
|
# print "$query: "; |
118
|
|
|
|
|
|
|
# print $ref->{"Authors"}, " -> "; |
119
|
0
|
0
|
|
|
|
0
|
if( eval($query) ) { |
120
|
|
|
|
|
|
|
# print "!!!"; |
121
|
0
|
|
|
|
|
0
|
push @matches, $refID; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
# print "\n"; |
124
|
|
|
|
|
|
|
} |
125
|
0
|
|
|
|
|
0
|
return \@matches; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
2
|
|
|
2
|
0
|
5
|
sub convertQuery { my ($self, $refField) = @_; |
129
|
|
|
|
|
|
|
# |
130
|
|
|
|
|
|
|
# convert field to a perl expression |
131
|
|
|
|
|
|
|
# |
132
|
2
|
|
|
|
|
12
|
$refField =~ s/^\{|\}$//g; # strip braces |
133
|
2
|
|
|
|
|
6
|
$refField =~ s/\\[lr]quote ?/'/g; # convert quotes ##### hm ... |
134
|
2
|
|
|
|
|
6
|
$refField =~ s/\\[lr]dblquote ?/"/g; # convert quotes ##### hm ...
|
135
|
2
|
|
|
|
|
3
|
$refField =~ s/[\N{LEFT DOUBLE QUOTATION MARK}\N{RIGHT DOUBLE QUOTATION MARK}\N{DOUBLE LOW-9 QUOTATION MARK}\N{DOUBLE HIGH-REVERSED-9 QUOTATION MARK}]/"/g;
|
136
|
2
|
|
|
|
|
5
|
$refField =~ s/[\N{LEFT SINGLE QUOTATION MARK}\N{RIGHT SINGLE QUOTATION MARK}\N{SINGLE LOW-9 QUOTATION MARK}\N{LEFT SINGLE QUOTATION MARK}\N{SINGLE HIGH-REVERSED-9 QUOTATION MARK}]/'/g; |
137
|
2
|
|
|
|
|
4
|
$refField =~ s/%/(?:.*)/g; # convert wildcards |
138
|
2
|
|
|
|
|
5
|
$refField =~ s/\s*=\s*/ eq /gi; |
139
|
2
|
|
|
|
|
4
|
$refField =~ s/\s+LIKE\s+\'([^']*)\'/ =~ \/^$1\$\//gi; |
140
|
2
|
|
|
|
|
4
|
$refField =~ s/\s+OR\s+/ || /gi; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# convert Entries to perl code |
143
|
2
|
|
|
|
|
4
|
$refField =~ s/("[a-z]+\")/\$ref->\{$1\}/gi; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# some optimization: heading & trailing wildchars |
146
|
2
|
|
|
|
|
3
|
$refField =~ s/\/\^\(\?\:\.\*\)/\//g; |
147
|
2
|
|
|
|
|
4
|
$refField =~ s/\(\?\:\.\*\)\$\//\//g; |
148
|
|
|
|
|
|
|
|
149
|
2
|
|
|
|
|
20
|
$self->traceMessage("Converted query: {$refField}"); |
150
|
2
|
|
|
|
|
6
|
return $refField; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# |
156
|
|
|
|
|
|
|
# $Log: BibliographyStyle.pm,v $ |
157
|
|
|
|
|
|
|
# Revision 1.5 2003/04/14 09:46:49 ptandler |
158
|
|
|
|
|
|
|
# optimized query |
159
|
|
|
|
|
|
|
# |
160
|
|
|
|
|
|
|
# Revision 1.4 2002/08/08 08:23:28 Diss |
161
|
|
|
|
|
|
|
# - support field options |
162
|
|
|
|
|
|
|
# - field option "all" to include all refs in list (not only found refs) |
163
|
|
|
|
|
|
|
# |
164
|
|
|
|
|
|
|
# Revision 1.3 2002/05/27 10:24:23 Diss |
165
|
|
|
|
|
|
|
# support for [{...}] queries |
166
|
|
|
|
|
|
|
# |
167
|
|
|
|
|
|
|
# Revision 1.2 2002/03/27 10:00:50 Diss |
168
|
|
|
|
|
|
|
# new module structure, not yet included in LitRefs/LitUI (R2) |
169
|
|
|
|
|
|
|
# |
170
|
|
|
|
|
|
|
# Revision 1.1 2002/03/18 11:15:47 Diss |
171
|
|
|
|
|
|
|
# major additions: replace [] refs, generate bibliography using [{}], ... |
172
|
|
|
|
|
|
|
# |