line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
# NAME : BibTeX/Entry.pm |
3
|
|
|
|
|
|
|
# CLASSES : Text::BibTeX::Entry |
4
|
|
|
|
|
|
|
# RELATIONS : base class for Text::BibTeX::StructuredEntry, and |
5
|
|
|
|
|
|
|
# ultimately for all user-supplied structured entry classes |
6
|
|
|
|
|
|
|
# DESCRIPTION: Provides an object-oriented interface to BibTeX entries. |
7
|
|
|
|
|
|
|
# CREATED : March 1997, Greg Ward |
8
|
|
|
|
|
|
|
# MODIFIED : |
9
|
|
|
|
|
|
|
# VERSION : $Id$ |
10
|
|
|
|
|
|
|
# COPYRIGHT : Copyright (c) 1997-2000 by Gregory P. Ward. All rights |
11
|
|
|
|
|
|
|
# reserved. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# This file is part of the Text::BibTeX library. This |
14
|
|
|
|
|
|
|
# library is free software; you may redistribute it and/or |
15
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
16
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
package Text::BibTeX::Entry; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
require 5.004; # for isa, and delete on a slice |
20
|
|
|
|
|
|
|
|
21
|
13
|
|
|
13
|
|
87
|
use strict; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
411
|
|
22
|
13
|
|
|
13
|
|
69
|
use vars qw'$VERSION'; |
|
13
|
|
|
|
|
24
|
|
|
13
|
|
|
|
|
525
|
|
23
|
13
|
|
|
13
|
|
62
|
use Carp; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
834
|
|
24
|
13
|
|
|
13
|
|
158
|
use Text::BibTeX qw(:metatypes :nodetypes); |
|
13
|
|
|
|
|
30
|
|
|
13
|
|
|
|
|
40125
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$VERSION = 0.88; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Text::BibTeX::Entry - read and parse BibTeX files |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use Text::BibTeX::Entry; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# ...assuming that $bibfile and $newbib are both objects of class |
37
|
|
|
|
|
|
|
# Text::BibTeX::File, opened for reading and writing (respectively): |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Entry creation/parsing methods: |
40
|
|
|
|
|
|
|
$entry = Text::BibTeX::Entry->new(); |
41
|
|
|
|
|
|
|
$entry->read ($bibfile); |
42
|
|
|
|
|
|
|
$entry->parse ($filename, $filehandle); |
43
|
|
|
|
|
|
|
$entry->parse_s ($entry_text); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# or: |
46
|
|
|
|
|
|
|
$entry = Text::BibTeX::Entry->new( $bibfile ); |
47
|
|
|
|
|
|
|
$entry = Text::BibTeX::Entry->new( $filename, $filehandle ); |
48
|
|
|
|
|
|
|
$entry = Text::BibTeX::Entry->new( $entry_text ); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Entry query methods |
51
|
|
|
|
|
|
|
warn "error in input" unless $entry->parse_ok; |
52
|
|
|
|
|
|
|
$metatype = $entry->metatype; |
53
|
|
|
|
|
|
|
$type = $entry->type; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# if metatype is BTE_REGULAR or BTE_MACRODEF: |
56
|
|
|
|
|
|
|
$key = $entry->key; # only for BTE_REGULAR metatype |
57
|
|
|
|
|
|
|
$num_fields = $entry->num_fields; |
58
|
|
|
|
|
|
|
@fieldlist = $entry->fieldlist; |
59
|
|
|
|
|
|
|
$has_title = $entry->exists ('title'); |
60
|
|
|
|
|
|
|
$title = $entry->get ('title'); |
61
|
|
|
|
|
|
|
# or: |
62
|
|
|
|
|
|
|
($val1,$val2,...$valn) = $entry->get ($field1, $field2, ..., $fieldn); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# if metatype is BTE_COMMENT or BTE_PREAMBLE: |
65
|
|
|
|
|
|
|
$value = $entry->value; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Author name methods |
68
|
|
|
|
|
|
|
@authors = $entry->split ('author'); |
69
|
|
|
|
|
|
|
($first_author) = $entry->names ('author'); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Entry modification methods |
72
|
|
|
|
|
|
|
$entry->set_type ($new_type); |
73
|
|
|
|
|
|
|
$entry->set_key ($new_key); |
74
|
|
|
|
|
|
|
$entry->set ('title', $new_title); |
75
|
|
|
|
|
|
|
# or: |
76
|
|
|
|
|
|
|
$entry->set ($field1, $val1, $field2, $val2, ..., $fieldn, $valn); |
77
|
|
|
|
|
|
|
$entry->delete (@fields); |
78
|
|
|
|
|
|
|
$entry->set_fieldlist (\@fieldlist); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Entry output methods |
81
|
|
|
|
|
|
|
$entry->write ($newbib); |
82
|
|
|
|
|
|
|
$entry->print ($filehandle); |
83
|
|
|
|
|
|
|
$entry_text = $entry->print_s; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Reset internal parser state: |
86
|
|
|
|
|
|
|
$entry = Text::BibTeX::Entry->new(); |
87
|
|
|
|
|
|
|
$entry->parse ($filename, undef); |
88
|
|
|
|
|
|
|
$entry->parse_s (undef); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# or: |
91
|
|
|
|
|
|
|
$entry = Text::BibTeX::Entry->new( $filename, undef ); |
92
|
|
|
|
|
|
|
$entry = Text::BibTeX::Entry->new( undef ); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Miscellaneous methods |
95
|
|
|
|
|
|
|
$entry->warn ($entry_warning); |
96
|
|
|
|
|
|
|
# or: |
97
|
|
|
|
|
|
|
$entry->warn ($field_warning, $field); |
98
|
|
|
|
|
|
|
$entry->clone; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 DESCRIPTION |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
C does all the real work of reading and parsing |
103
|
|
|
|
|
|
|
BibTeX files. (Well, actually it just provides an object-oriented Perl |
104
|
|
|
|
|
|
|
front-end to a C library that does all that. But that's not important |
105
|
|
|
|
|
|
|
right now.) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
BibTeX entries can be read either from C objects (using |
108
|
|
|
|
|
|
|
the C method), or directly from a filehandle (using the C |
109
|
|
|
|
|
|
|
method), or from a string (using C). The first is preferable, |
110
|
|
|
|
|
|
|
since you don't have to worry about supplying the filename, and because of |
111
|
|
|
|
|
|
|
the extra functionality provided by the C class. |
112
|
|
|
|
|
|
|
Currently, this means that you may specify the I to |
113
|
|
|
|
|
|
|
which entries are expected to conform via the C class. This lets you |
114
|
|
|
|
|
|
|
ensure that entries follow the rules for required fields and mutually |
115
|
|
|
|
|
|
|
constrained fields for a particular type of database, and also gives you |
116
|
|
|
|
|
|
|
access to all the methods of the I for this |
117
|
|
|
|
|
|
|
database structure. See L for details on database |
118
|
|
|
|
|
|
|
structures. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Once you have the entry, you can query it or change it in a variety of |
121
|
|
|
|
|
|
|
ways. The query methods are C, C, C, C, |
122
|
|
|
|
|
|
|
C, C, and C. Methods for changing the entry are |
123
|
|
|
|
|
|
|
C, C, C, C, and C. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Finally, you can output BibTeX entries, again either to an open |
126
|
|
|
|
|
|
|
C object, a filehandle or a string. (A filehandle or |
127
|
|
|
|
|
|
|
C object must, of course, have been opened in write mode.) Output to |
128
|
|
|
|
|
|
|
a C object is done with the C method, to a filehandle via |
129
|
|
|
|
|
|
|
C, and to a string with C. Using the C class is |
130
|
|
|
|
|
|
|
recommended for future extensibility, although it currently doesn't offer |
131
|
|
|
|
|
|
|
anything extra. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 METHODS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 Entry creation/parsing methods |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over 4 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item new ([OPTS ,] [SOURCE]) |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Creates a new C object. If the SOURCE parameter is |
142
|
|
|
|
|
|
|
supplied, it must be one of the following: a C (or |
143
|
|
|
|
|
|
|
descendant class) object, a filename/filehandle pair, or a string. Calls |
144
|
|
|
|
|
|
|
C to read from a C object, C to read from |
145
|
|
|
|
|
|
|
a filehandle, and C to read from a string. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
A filehandle can be specified as a GLOB reference, or as an |
148
|
|
|
|
|
|
|
C (or descendants) object, or as a C (or |
149
|
|
|
|
|
|
|
descendants) object. (But there's really no point in using |
150
|
|
|
|
|
|
|
C objects, since C requires Perl 5.004, which |
151
|
|
|
|
|
|
|
always includes the C modules.) You can I pass in the name of |
152
|
|
|
|
|
|
|
a filehandle as a string, though, because C |
153
|
|
|
|
|
|
|
conforms to the C |
154
|
|
|
|
|
|
|
references). |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
The corresponding filename should be supplied in order to allow for |
157
|
|
|
|
|
|
|
accurate error messages; if you simply don't have the filename, you can |
158
|
|
|
|
|
|
|
pass C and you'll get error messages without a filename. (It's |
159
|
|
|
|
|
|
|
probably better to rearrange your code so that the filename is |
160
|
|
|
|
|
|
|
available, though.) |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Thus, the following are equivalent to read from a file named by |
163
|
|
|
|
|
|
|
C<$filename> (error handling ignored): |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# good ol' fashioned filehandle and GLOB ref |
166
|
|
|
|
|
|
|
open (BIBFILE, $filename); |
167
|
|
|
|
|
|
|
$entry = Text::BibTeX::Entry->new($filename, \*BIBFILE); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# newfangled IO::File thingy |
170
|
|
|
|
|
|
|
$file = IO::File->new($filename); |
171
|
|
|
|
|
|
|
$entry = Text::BibTeX::Entry->new($filename, $file); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
But using a C object is simpler and preferred: |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
$file = Text::BibTeX::File->new($filename); |
176
|
|
|
|
|
|
|
$entry = Text::BibTeX::Entry->new($file); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Returns the new object, unless SOURCE is supplied and reading/parsing |
179
|
|
|
|
|
|
|
the entry fails (e.g., due to end of file) -- then it returns false. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
You may supply a reference to an option hash as first argument. |
182
|
|
|
|
|
|
|
Supported options are: |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=over 4 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item BINMODE |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Set the way Text::BibTeX deals with strings. By default it manages |
189
|
|
|
|
|
|
|
strings as bytes. You can set BINMODE to 'utf-8' to get NFC normalized |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Text::BibTeX::Entry->new( |
192
|
|
|
|
|
|
|
{ binmode => 'utf-8', normalization => 'NFD' }, |
193
|
|
|
|
|
|
|
$file }); |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item NORMALIZATION |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
UTF-8 strings and you can customise the normalization with the NORMALIZATION option. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=back |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub new |
206
|
|
|
|
|
|
|
{ |
207
|
111
|
|
|
111
|
1
|
27818
|
my ($class, @source) = @_; |
208
|
|
|
|
|
|
|
|
209
|
111
|
|
33
|
|
|
339
|
$class = ref ($class) || $class; |
210
|
|
|
|
|
|
|
|
211
|
111
|
|
|
|
|
499
|
my $self = {'file' => undef, |
212
|
|
|
|
|
|
|
'type' => undef, |
213
|
|
|
|
|
|
|
'key' => undef, |
214
|
|
|
|
|
|
|
'status' => undef, |
215
|
|
|
|
|
|
|
'metatype' => undef, |
216
|
|
|
|
|
|
|
'fields' => [], |
217
|
|
|
|
|
|
|
'values' => {}}; |
218
|
111
|
|
|
|
|
194
|
bless $self, $class; |
219
|
|
|
|
|
|
|
|
220
|
111
|
|
|
|
|
153
|
my $opts = {}; |
221
|
111
|
50
|
66
|
|
|
377
|
$opts = shift @source if scalar(@source) and ref $source[0] eq "HASH"; |
222
|
111
|
|
|
|
|
265
|
$opts->{ lc $_ } = $opts->{$_} for ( keys %$opts ); |
223
|
|
|
|
|
|
|
$self->{binmode} = 'utf-8' |
224
|
111
|
50
|
33
|
|
|
268
|
if exists $opts->{binmode} && $opts->{binmode} =~ /utf-?8/i; |
225
|
111
|
50
|
|
|
|
192
|
$self->{normalization} = $opts->{normalization} if exists $opts->{normalization}; |
226
|
|
|
|
|
|
|
|
227
|
111
|
100
|
|
|
|
196
|
if (@source) |
228
|
|
|
|
|
|
|
{ |
229
|
105
|
|
|
|
|
163
|
my $status; |
230
|
|
|
|
|
|
|
|
231
|
105
|
100
|
100
|
|
|
656
|
if (@source == 1 && ref($source[0]) && $source[0]->isa ('Text::BibTeX::File')) |
|
|
100
|
66
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
232
|
|
|
|
|
|
|
{ |
233
|
84
|
|
|
|
|
103
|
my $file = $source[0]; |
234
|
84
|
|
|
|
|
132
|
$status = $self->read ($file); |
235
|
84
|
100
|
|
|
|
285
|
if (my $structure = $file->structure) |
236
|
|
|
|
|
|
|
{ |
237
|
2
|
|
|
|
|
4
|
$self->{structure} = $structure; |
238
|
2
|
|
|
|
|
8
|
bless $self, $structure->entry_class; |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
elsif (@source == 2 && (defined ($source[0]) && ! ref ($source[0])) && (!defined ($source[1]) || fileno ($source[1]) >= 0)) |
242
|
15
|
|
|
|
|
66
|
{ $status = $self->parse ($source[0], $source[1]) } |
243
|
|
|
|
|
|
|
elsif (@source == 1 && ! ref ($source[0])) |
244
|
6
|
|
|
|
|
41
|
{ $status = $self->parse_s ($source[0]) } |
245
|
|
|
|
|
|
|
else |
246
|
0
|
|
|
|
|
0
|
{ croak "new: source argument must be either a Text::BibTeX::File " . |
247
|
|
|
|
|
|
|
"(or descendant) object, filename/filehandle pair, or " . |
248
|
|
|
|
|
|
|
"a string"; } |
249
|
|
|
|
|
|
|
|
250
|
105
|
100
|
|
|
|
290
|
return $status unless $status; # parse failed -- tell our caller |
251
|
|
|
|
|
|
|
} |
252
|
94
|
|
|
|
|
268
|
$self; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item clone |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Clone a Text::BibTeX::Entry object, returning the clone. This re-uses the reference to any |
258
|
|
|
|
|
|
|
Text::BibTeX::Structure or Text::BibTeX::File but copies everything else, |
259
|
|
|
|
|
|
|
so that the clone can be modified apart from the original. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=cut |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub clone |
264
|
|
|
|
|
|
|
{ |
265
|
1
|
|
|
1
|
1
|
1860
|
my $self = shift; |
266
|
1
|
|
|
|
|
3
|
my $clone = {}; |
267
|
|
|
|
|
|
|
# Use the same structure object - won't be changed |
268
|
1
|
50
|
|
|
|
6
|
if ($self->{structure}) { |
269
|
0
|
|
|
|
|
0
|
$clone->{structure} = $self->{structure}; |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
# Use the same file object - won't be changed |
272
|
1
|
50
|
|
|
|
4
|
if ($self->{file}) { |
273
|
|
|
|
|
|
|
$clone->{file} = $self->{file} |
274
|
0
|
|
|
|
|
0
|
} |
275
|
|
|
|
|
|
|
# These might be changed so make copies |
276
|
1
|
|
|
|
|
3
|
$clone->{binmode} = $self->{binmode}; |
277
|
1
|
|
|
|
|
3
|
$clone->{normalization} = $self->{normalization}; |
278
|
1
|
|
|
|
|
2
|
$clone->{type} = $self->{type}; |
279
|
1
|
|
|
|
|
3
|
$clone->{key} = $self->{key}; |
280
|
1
|
|
|
|
|
2
|
$clone->{status} = $self->{status}; |
281
|
1
|
|
|
|
|
2
|
$clone->{metatype} = $self->{metatype}; |
282
|
1
|
|
|
|
|
2
|
$clone->{fields} = [ map {$_} @{$self->{fields}} ]; |
|
4
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
4
|
|
283
|
1
|
|
|
|
|
2
|
while (my ($k, $v) = each %{$self->{values}}) { |
|
5
|
|
|
|
|
15
|
|
284
|
4
|
|
|
|
|
11
|
$clone->{values}{$k} = $v; |
285
|
|
|
|
|
|
|
} |
286
|
1
|
|
|
|
|
3
|
while (my ($k, $v) = each %{$self->{lines}}) { |
|
7
|
|
|
|
|
19
|
|
287
|
6
|
|
|
|
|
10
|
$clone->{lines}{$k} = $v; |
288
|
|
|
|
|
|
|
} |
289
|
1
|
|
|
|
|
3
|
bless $clone, ref($self); |
290
|
1
|
|
|
|
|
3
|
return $clone; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item read (BIBFILE) |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
Reads and parses an entry from BIBFILE, which must be a |
296
|
|
|
|
|
|
|
C object (or descendant). The next entry will be read |
297
|
|
|
|
|
|
|
from the file associated with that object. |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
Returns the same as C (or C): false if no entry found |
300
|
|
|
|
|
|
|
(e.g., at end-of-file), true otherwise. To see if the parse itself failed |
301
|
|
|
|
|
|
|
(due to errors in the input), call the C method. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=cut |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
sub read |
306
|
|
|
|
|
|
|
{ |
307
|
88
|
|
|
88
|
1
|
137
|
my ($self, $source, $preserve) = @_; |
308
|
88
|
50
|
|
|
|
180
|
croak "`source' argument must be ref to open Text::BibTeX::File " . |
309
|
|
|
|
|
|
|
"(or descendant) object" |
310
|
|
|
|
|
|
|
unless ($source->isa('Text::BibTeX::File')); |
311
|
|
|
|
|
|
|
|
312
|
88
|
|
|
|
|
120
|
my $fn = $source->{'filename'}; |
313
|
88
|
|
|
|
|
100
|
my $fh = $source->{'handle'}; |
314
|
88
|
|
|
|
|
116
|
$self->{'file'} = $source; # store File object for later use |
315
|
|
|
|
|
|
|
## Propagate flags |
316
|
88
|
|
|
|
|
119
|
for my $f (qw.binmode normalization.) { |
317
|
176
|
100
|
|
|
|
463
|
$self->{$f} = $source->{$f} unless exists $self->{$f}; |
318
|
|
|
|
|
|
|
} |
319
|
88
|
|
|
|
|
142
|
return $self->parse ($fn, $fh, $preserve); |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=item parse (FILENAME, FILEHANDLE) |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
Reads and parses the next entry from FILEHANDLE. (That is, it scans the |
326
|
|
|
|
|
|
|
input until an '@' sign is seen, and then slurps up to the next '@' |
327
|
|
|
|
|
|
|
sign. Everything between the two '@' signs [including the first one, |
328
|
|
|
|
|
|
|
but not the second one -- it's pushed back onto the input stream for the |
329
|
|
|
|
|
|
|
next entry] is parsed as a BibTeX entry, with the simultaneous |
330
|
|
|
|
|
|
|
construction of an abstract syntax tree [AST]. The AST is traversed to |
331
|
|
|
|
|
|
|
ferret out the most interesting information, and this is stuffed into a |
332
|
|
|
|
|
|
|
Perl hash, which coincidentally is the C object |
333
|
|
|
|
|
|
|
you've been tossing around. But you don't need to know any of that -- I |
334
|
|
|
|
|
|
|
just figured if you've read this far, you might want to know something |
335
|
|
|
|
|
|
|
about the inner workings of this module.) |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
The success of the parse is stored internally so that you can later |
338
|
|
|
|
|
|
|
query it with the C method. Even in the presence of syntax |
339
|
|
|
|
|
|
|
errors, you'll usually get something resembling your input, but it's |
340
|
|
|
|
|
|
|
usually not wise to try to do anything with it. Just call C, |
341
|
|
|
|
|
|
|
and if it returns false then silently skip to the next entry. (The |
342
|
|
|
|
|
|
|
error messages printed out by the parser should be quite adequate for |
343
|
|
|
|
|
|
|
the user to figure out what's wrong. And no, there's currently no way |
344
|
|
|
|
|
|
|
for you to capture or redirect those error messages -- they're always |
345
|
|
|
|
|
|
|
printed to C by the underlying C code. That should change in |
346
|
|
|
|
|
|
|
future releases.) |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
If no '@' signs are seen on the input before reaching end-of-file, then |
349
|
|
|
|
|
|
|
we've exhausted all the entries in the file, and C returns a |
350
|
|
|
|
|
|
|
false value. Otherwise, it returns a true value -- even if there were |
351
|
|
|
|
|
|
|
syntax errors. Hence, it's important to check C. |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
The FILENAME parameter is only used for generating error messages, but |
354
|
|
|
|
|
|
|
anybody using your program will certainly appreciate your setting it |
355
|
|
|
|
|
|
|
correctly! |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
Passing C to FILEHANDLE will reset the state of the underlying |
358
|
|
|
|
|
|
|
C parser, which is required in order to parse multiple files. |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=item parse_s (TEXT) |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
Parses a BibTeX entry (using the above rules) from the string TEXT. The |
363
|
|
|
|
|
|
|
string is not modified; repeatedly calling C with the same string |
364
|
|
|
|
|
|
|
will give you the same results each time. Thus, there's no point in |
365
|
|
|
|
|
|
|
putting multiple entries in one string. |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
Passing C to TEXT will reset the state of the underlying |
368
|
|
|
|
|
|
|
C parser, which may be required in order to parse multiple strings. |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
=back |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
=cut |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
sub _preserve |
375
|
|
|
|
|
|
|
{ |
376
|
126
|
|
|
126
|
|
174
|
my ($self, $preserve) = @_; |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
$preserve = $self->{'file'}->preserve_values |
379
|
|
|
|
|
|
|
if ! defined $preserve && |
380
|
|
|
|
|
|
|
defined $self->{'file'} && |
381
|
126
|
100
|
66
|
|
|
677
|
$self->{'file'}->isa ('Text::BibTeX::File'); |
|
|
|
66
|
|
|
|
|
382
|
126
|
50
|
|
|
|
246
|
require Text::BibTeX::Value if $preserve; |
383
|
126
|
|
|
|
|
174
|
$preserve; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
sub parse |
387
|
|
|
|
|
|
|
{ |
388
|
106
|
|
|
106
|
1
|
2628
|
my ($self, $filename, $filehandle, $preserve) = @_; |
389
|
|
|
|
|
|
|
|
390
|
106
|
|
|
|
|
189
|
$preserve = $self->_preserve ($preserve); |
391
|
106
|
100
|
|
|
|
186
|
if (defined $filehandle) { |
392
|
96
|
|
|
|
|
5128
|
_parse ($self, $filename, $filehandle, $preserve); |
393
|
|
|
|
|
|
|
} else { |
394
|
10
|
|
|
|
|
66
|
_reset_parse (); |
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
sub parse_s |
400
|
|
|
|
|
|
|
{ |
401
|
20
|
|
|
20
|
1
|
32138
|
my ($self, $text, $preserve) = @_; |
402
|
|
|
|
|
|
|
|
403
|
20
|
|
|
|
|
62
|
$preserve = $self->_preserve ($preserve); |
404
|
20
|
100
|
|
|
|
59
|
if (defined $text) { |
405
|
18
|
|
|
|
|
1156
|
_parse_s ($self, $text, $preserve); |
406
|
|
|
|
|
|
|
} else { |
407
|
2
|
|
|
|
|
12
|
_reset_parse_s (); |
408
|
|
|
|
|
|
|
} |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
=head2 Entry query methods |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
=over 4 |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
=item parse_ok () |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
Returns false if there were any serious errors encountered while parsing |
419
|
|
|
|
|
|
|
the entry. (A "serious" error is a lexical or syntax error; currently, |
420
|
|
|
|
|
|
|
warnings such as "undefined macro" result in an error message being |
421
|
|
|
|
|
|
|
printed to C for the user's edification, but no notice is |
422
|
|
|
|
|
|
|
available to the calling code.) |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
=item type () |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
Returns the type of the entry. (The `type' is the word that follows the |
427
|
|
|
|
|
|
|
'@' sign; e.g. `article', `book', `inproceedings', etc. for the standard |
428
|
|
|
|
|
|
|
BibTeX styles.) |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
=item metatype () |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
Returns the metatype of the entry. (The `metatype' is a numeric value used |
433
|
|
|
|
|
|
|
to classify entry types into four groups: comment, preamble, macro |
434
|
|
|
|
|
|
|
definition (C<@string> entries), and regular (all other entry types). |
435
|
|
|
|
|
|
|
C exports four constants for these metatypes: C, |
436
|
|
|
|
|
|
|
C, C, and C.) |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
=item key () |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
Returns the key of the entry. (The key is the token immediately |
441
|
|
|
|
|
|
|
following the opening `{' or `(' in "regular" entries. Returns C |
442
|
|
|
|
|
|
|
for entries that don't have a key, such as macro definition (C<@string>) |
443
|
|
|
|
|
|
|
entries.) |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
=item num_fields () |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
Returns the number of fields in the entry. (Note that, currently, this is |
448
|
|
|
|
|
|
|
I equivalent to putting C in front of a call to C. |
449
|
|
|
|
|
|
|
See below for the consequences of calling C in a scalar |
450
|
|
|
|
|
|
|
context.) |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
=item fieldlist () |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
Returns the list of fields in the entry. |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
B In scalar context, it no longer returns a |
457
|
|
|
|
|
|
|
reference to the object's own list of fields. |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
=cut |
460
|
|
|
|
|
|
|
|
461
|
19
|
|
|
19
|
1
|
11306
|
sub parse_ok { shift->{'status'}; } |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
sub metatype { |
464
|
2
|
|
|
2
|
1
|
9
|
my $self = shift; |
465
|
2
|
|
|
|
|
6
|
Text::BibTeX->_process_result( $self->{'metatype'}, $self->{binmode}, $self->{normalization} ); |
466
|
|
|
|
|
|
|
} |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
sub type { |
469
|
33
|
|
|
33
|
1
|
69
|
my $self = shift; |
470
|
33
|
|
|
|
|
182
|
Text::BibTeX->_process_result( $self->{'type'}, $self->{binmode}, $self->{normalization} ); |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
sub key { |
474
|
28
|
|
|
28
|
1
|
54
|
my $self = shift; |
475
|
|
|
|
|
|
|
exists $self->{key} |
476
|
|
|
|
|
|
|
? Text::BibTeX->_process_result($self->{key}, $self->{binmode}, $self->{normalization}) |
477
|
28
|
100
|
|
|
|
144
|
: undef; |
478
|
|
|
|
|
|
|
} |
479
|
|
|
|
|
|
|
|
480
|
0
|
|
|
0
|
1
|
0
|
sub num_fields { scalar @{shift->{'fields'}}; } |
|
0
|
|
|
|
|
0
|
|
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
sub fieldlist { |
483
|
21
|
|
|
21
|
1
|
10776
|
my $self = shift; |
484
|
21
|
|
|
|
|
39
|
return map { Text::BibTeX->_process_result($_, $self->{binmode}, $self->{normalization})} @{$self->{'fields'}}; |
|
64
|
|
|
|
|
218
|
|
|
21
|
|
|
|
|
62
|
|
485
|
|
|
|
|
|
|
} |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
=item exists (FIELD) |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
Returns true if a field named FIELD is present in the entry, false |
490
|
|
|
|
|
|
|
otherwise. |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
=item get (FIELD, ...) |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
Returns the value of one or more FIELDs, as a list of values. For example: |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
$author = $entry->get ('author'); |
497
|
|
|
|
|
|
|
($author, $editor) = $entry->get ('author', 'editor'); |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
If a FIELD is not present in the entry, C will be returned at its |
500
|
|
|
|
|
|
|
place in the return list. However, you can't completely trust this as a |
501
|
|
|
|
|
|
|
test for presence or absence of a field; it is possible for a field to be |
502
|
|
|
|
|
|
|
present but undefined. Currently this can only happen due to certain |
503
|
|
|
|
|
|
|
syntax errors in the input, or if you pass an undefined value to C, or |
504
|
|
|
|
|
|
|
if you create a new field with C (the new field's value is |
505
|
|
|
|
|
|
|
implicitly set to C). |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
Normally, the field value is what the input looks like after "maximal |
508
|
|
|
|
|
|
|
processing"--quote characters are removed, whitespace is collapsed (the |
509
|
|
|
|
|
|
|
same way that BibTeX itself does it), macros are expanded, and multiple |
510
|
|
|
|
|
|
|
tokens are pasted together. (See L for details on the |
511
|
|
|
|
|
|
|
post-processing performed by B.) |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
For example, if your input file has the following: |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
@string{of = "of"} |
516
|
|
|
|
|
|
|
@string{foobars = "Foobars"} |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
@article{foobar, |
519
|
|
|
|
|
|
|
title = { The Mating Habits } # of # " Adult " # foobars |
520
|
|
|
|
|
|
|
} |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
then using C to query the value of the C field from the |
523
|
|
|
|
|
|
|
C entry would give the string "The Mating Habits of Adult Foobars". |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
However, in certain circumstances you may wish to preserve the values as |
526
|
|
|
|
|
|
|
they appear in the input. This is done by setting a C |
527
|
|
|
|
|
|
|
flag at some point; then, C will return not strings but |
528
|
|
|
|
|
|
|
C objects. Each C object is a list of |
529
|
|
|
|
|
|
|
C objects, which in turn consists of a simple |
530
|
|
|
|
|
|
|
value type (string, macro, or number) and the text of the simple value. |
531
|
|
|
|
|
|
|
Various ways to set the C flag and the interface to |
532
|
|
|
|
|
|
|
both C and C objects are described in |
533
|
|
|
|
|
|
|
L. |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
=item value () |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
Returns the single string associated with C<@comment> and C<@preamble> |
538
|
|
|
|
|
|
|
entries. For instance, the entry |
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
@preamble{" This is a preamble" # |
541
|
|
|
|
|
|
|
{---the concatenation of several strings}} |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
would return a value of "This is a preamble---the concatenation of |
544
|
|
|
|
|
|
|
several strings". |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
If this entry was parsed in "value preservation" mode, then C |
547
|
|
|
|
|
|
|
acts like C, and returns a C object rather than a simple |
548
|
|
|
|
|
|
|
string. |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
=back |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
=cut |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
sub exists |
555
|
|
|
|
|
|
|
{ |
556
|
91
|
|
|
91
|
1
|
628
|
my ($self, $field) = @_; |
557
|
|
|
|
|
|
|
|
558
|
91
|
|
|
|
|
277
|
exists $self->{values}{Text::BibTeX->_process_argument($field, $self->{binmode}, $self->{normalization})}; |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
sub get |
562
|
|
|
|
|
|
|
{ |
563
|
123
|
|
|
123
|
1
|
32137
|
my ($self, @fields) = @_; |
564
|
|
|
|
|
|
|
|
565
|
123
|
|
|
|
|
264
|
my @x = @{$self->{'values'}}{map {Text::BibTeX->_process_argument($_, $self->{binmode}, $self->{normalization})} @fields}; |
|
123
|
|
|
|
|
348
|
|
|
179
|
|
|
|
|
608
|
|
566
|
|
|
|
|
|
|
|
567
|
123
|
100
|
|
|
|
217
|
@x = map {defined($_) ? Text::BibTeX->_process_result($_, $self->{binmode}, $self->{normalization}): undef} @x; |
|
179
|
|
|
|
|
525
|
|
568
|
|
|
|
|
|
|
|
569
|
123
|
100
|
|
|
|
768
|
return (@x > 1) ? @x : $x[0]; |
570
|
|
|
|
|
|
|
} |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
sub value { |
573
|
2
|
|
|
2
|
1
|
10
|
my $self = shift; |
574
|
2
|
|
|
|
|
7
|
Text::BibTeX->_process_result($self->{value}, $self->{binmode}, $self->{normalization}); |
575
|
|
|
|
|
|
|
} |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
=head2 Author name methods |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
This is the only part of the module that makes any assumption about the |
581
|
|
|
|
|
|
|
nature of the data, namely that certain fields are lists delimited by a |
582
|
|
|
|
|
|
|
simple word such as "and", and that the delimited sub-strings are human |
583
|
|
|
|
|
|
|
names of the "First von Last" or "von Last, Jr., First" style used by |
584
|
|
|
|
|
|
|
BibTeX. If you are using this module for anything other than |
585
|
|
|
|
|
|
|
bibliographic data, you can most likely forget about these two methods. |
586
|
|
|
|
|
|
|
However, if you are in fact hacking on BibTeX-style bibliographic data, |
587
|
|
|
|
|
|
|
these could come in very handy -- the name-parsing done by BibTeX is not |
588
|
|
|
|
|
|
|
trivial, and the list-splitting would also be a pain to implement in |
589
|
|
|
|
|
|
|
Perl because you have to pay attention to brace-depth. (Not that it |
590
|
|
|
|
|
|
|
wasn't a pain to implement in C -- it's just a lot more efficient than a |
591
|
|
|
|
|
|
|
Perl implementation would be.) |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
Incidentally, both of these methods assume that the strings being split |
594
|
|
|
|
|
|
|
have already been "collapsed" in the BibTeX way, i.e. all leading and |
595
|
|
|
|
|
|
|
trailing whitespace removed and internal whitespace reduced to single |
596
|
|
|
|
|
|
|
spaces. This should always be the case when using these two methods on |
597
|
|
|
|
|
|
|
a C object, but these are actually just front ends |
598
|
|
|
|
|
|
|
to more general functions in C. (More general in that you |
599
|
|
|
|
|
|
|
supply the string to be parsed, rather than supplying the name of an |
600
|
|
|
|
|
|
|
entry field.) Should you ever use those more general functions |
601
|
|
|
|
|
|
|
directly, you might have to worry about collapsing whitespace; see |
602
|
|
|
|
|
|
|
L (the C and C functions in |
603
|
|
|
|
|
|
|
particular) for more information. |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
Please note that the interface to author name parsing is experimental, |
606
|
|
|
|
|
|
|
subject to change, and open to discussion. Please let me know if you |
607
|
|
|
|
|
|
|
have problems with it, think it's just perfect, or whatever. |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
=over 4 |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
=item split (FIELD [, DELIM [, DESC]]) |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
Splits the value of FIELD on DELIM (default: `and'). Don't assume that |
614
|
|
|
|
|
|
|
this works the same as Perl's builtin C just because the names are |
615
|
|
|
|
|
|
|
the same: in particular, DELIM must be a simple string (no regexps), and |
616
|
|
|
|
|
|
|
delimiters that are at the beginning or end of the string, or at non-zero |
617
|
|
|
|
|
|
|
brace depth, or not surrounded by whitespace, are ignored. Some examples |
618
|
|
|
|
|
|
|
might illuminate matters: |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
if field F is... then split (F) returns... |
621
|
|
|
|
|
|
|
'Name1 and Name2' ('Name1', 'Name2') |
622
|
|
|
|
|
|
|
'Name1 and and Name2' ('Name1', undef, 'Name2') |
623
|
|
|
|
|
|
|
'Name1 and' ('Name1 and') |
624
|
|
|
|
|
|
|
'and Name2' ('and Name2') |
625
|
|
|
|
|
|
|
'Name1 {and} Name2 and Name3' ('Name1 {and} Name2', 'Name3') |
626
|
|
|
|
|
|
|
'{Name1 and Name2} and Name3' ('{Name1 and Name2}', 'Name3') |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
Note that a warning will be issued for empty names (as in the second |
629
|
|
|
|
|
|
|
example above). A warning ought to be issued for delimiters at the |
630
|
|
|
|
|
|
|
beginning or end of a string, but currently this isn't done. (Hmmm.) |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
DESC is a one-word description of the substrings; it defaults to 'name'. |
633
|
|
|
|
|
|
|
It is only used for generating warning messages. |
634
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
=item names (FIELD) |
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
Splits FIELD as described above, and further splits each name into four |
638
|
|
|
|
|
|
|
components: first, von, last, and jr. |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
Returns a list of C objects, each of which represents |
641
|
|
|
|
|
|
|
one name. Use the C method to query these objects; see |
642
|
|
|
|
|
|
|
L for details on the interface to name objects (and on |
643
|
|
|
|
|
|
|
name-parsing as well). |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
For example if this entry: |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
@article{foo, |
648
|
|
|
|
|
|
|
author = {John Smith and |
649
|
|
|
|
|
|
|
Hacker, J. Random and |
650
|
|
|
|
|
|
|
Ludwig van Beethoven and |
651
|
|
|
|
|
|
|
{Foo, Bar and Company}}} |
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
has been parsed into a C object C<$entry>, then |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
@names = $entry->names ('author'); |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
will put a list of C objects in C<@names>. These can |
658
|
|
|
|
|
|
|
be queried individually as described in L; for instance, |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
@last = $names[0]->part ('last'); |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
would put the list of tokens comprising the last name of the first author |
663
|
|
|
|
|
|
|
into the C<@last> array: C<('Smith')>. |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
=cut |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
sub split |
668
|
|
|
|
|
|
|
{ |
669
|
20
|
|
|
20
|
1
|
1150
|
my ($self, $field, $delim, $desc) = @_; |
670
|
|
|
|
|
|
|
|
671
|
20
|
50
|
|
|
|
44
|
return unless $self->exists($field); |
672
|
20
|
|
50
|
|
|
82
|
$delim ||= 'and'; |
673
|
20
|
|
50
|
|
|
62
|
$desc ||= 'name'; |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
# local $^W = 0 # suppress spurious warning from |
676
|
|
|
|
|
|
|
# unless defined $filename; # undefined $filename |
677
|
|
|
|
|
|
|
Text::BibTeX::split_list($self->{values}{$field}, |
678
|
|
|
|
|
|
|
$delim, |
679
|
|
|
|
|
|
|
($self->{file} && $self->{file}{filename}), |
680
|
|
|
|
|
|
|
$self->{lines}{$field}, |
681
|
|
|
|
|
|
|
$desc, |
682
|
|
|
|
|
|
|
{binmode => $self->{binmode}, |
683
|
20
|
|
66
|
|
|
135
|
normalization => $self->{normalization}}); |
684
|
|
|
|
|
|
|
} |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
sub names |
687
|
|
|
|
|
|
|
{ |
688
|
14
|
|
|
14
|
1
|
641
|
require Text::BibTeX::Name; |
689
|
|
|
|
|
|
|
|
690
|
14
|
|
|
|
|
42
|
my ($self, $field) = @_; |
691
|
14
|
|
|
|
|
29
|
my (@names, $i); |
692
|
|
|
|
|
|
|
|
693
|
14
|
|
66
|
|
|
54
|
my $filename = ($self->{'file'} && $self->{'file'}{'filename'}); |
694
|
14
|
|
|
|
|
23
|
my $line = $self->{'lines'}{$field}; |
695
|
|
|
|
|
|
|
|
696
|
14
|
|
|
|
|
46
|
@names = $self->split ($field); |
697
|
|
|
|
|
|
|
# local $^W = 0 # suppress spurious warning from |
698
|
|
|
|
|
|
|
# unless defined $filename; # undefined $filename |
699
|
14
|
|
|
|
|
92
|
for $i (0 .. $#names) |
700
|
|
|
|
|
|
|
{ |
701
|
|
|
|
|
|
|
$names[$i] = Text::BibTeX::Name->new( |
702
|
27
|
|
|
|
|
117
|
{binmode => $self->{binmode}, normalization => $self->{normalization}},$names[$i], $filename, $line, $i); |
703
|
|
|
|
|
|
|
} |
704
|
14
|
|
|
|
|
47
|
@names; |
705
|
|
|
|
|
|
|
} |
706
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
=back |
708
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
=head2 Entry modification methods |
710
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
=over 4 |
712
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
=item set_type (TYPE) |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
Sets the entry's type. |
716
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
=item set_metatype (METATYPE) |
718
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
Sets the entry's metatype (must be one of the four constants |
720
|
|
|
|
|
|
|
C, C, C, and C, which |
721
|
|
|
|
|
|
|
are all optionally exported from C). |
722
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
=item set_key (KEY) |
724
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
Sets the entry's key. |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
=item set (FIELD, VALUE, ...) |
728
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
Sets the value of field FIELD. (VALUE might be C or unsupplied, |
730
|
|
|
|
|
|
|
in which case FIELD will simply be set to C -- this is where the |
731
|
|
|
|
|
|
|
difference between the C method and testing the definedness of |
732
|
|
|
|
|
|
|
field values becomes clear.) |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
Multiple (FIELD, VALUE) pairs may be supplied; they will be processed in |
735
|
|
|
|
|
|
|
order (i.e. the input is treated like a list, not a hash). For example: |
736
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
$entry->set ('author', $author); |
738
|
|
|
|
|
|
|
$entry->set ('author', $author, 'editor', $editor); |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
VALUE can be either a simple string or a C object; |
741
|
|
|
|
|
|
|
it doesn't matter if the entry was parsed in "full post-processing" or |
742
|
|
|
|
|
|
|
"preserve input values" mode. |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
=item delete (FIELD) |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
Deletes field FIELD from an entry. |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
=item set_fieldlist (FIELDLIST) |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
Sets the entry's list of fields to FIELDLIST, which must be a list |
751
|
|
|
|
|
|
|
reference. If any of the field names supplied in FIELDLIST are not |
752
|
|
|
|
|
|
|
currently present in the entry, they are created with the value C |
753
|
|
|
|
|
|
|
and a warning is printed. Conversely, if any of the fields currently |
754
|
|
|
|
|
|
|
present in the entry are not named in the list of fields supplied to |
755
|
|
|
|
|
|
|
C, they are deleted from the entry and another warning is |
756
|
|
|
|
|
|
|
printed. |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
=back |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
=cut |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
sub set_type |
763
|
|
|
|
|
|
|
{ |
764
|
1
|
|
|
1
|
1
|
3
|
my ($self, $type) = @_; |
765
|
|
|
|
|
|
|
|
766
|
1
|
|
|
|
|
2
|
$self->{'type'} = $type; |
767
|
|
|
|
|
|
|
} |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
sub set_metatype |
770
|
|
|
|
|
|
|
{ |
771
|
0
|
|
|
0
|
1
|
0
|
my ($self, $metatype) = @_; |
772
|
|
|
|
|
|
|
|
773
|
0
|
|
|
|
|
0
|
$self->{'metatype'} = $metatype; |
774
|
|
|
|
|
|
|
} |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
sub set_key |
777
|
|
|
|
|
|
|
{ |
778
|
1
|
|
|
1
|
1
|
3
|
my ($self, $key) = @_; |
779
|
|
|
|
|
|
|
|
780
|
1
|
|
|
|
|
4
|
$self->{'key'} = Text::BibTeX->_process_argument($key, $self->{binmode}, $self->{normalization}); |
781
|
|
|
|
|
|
|
} |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
sub set |
784
|
|
|
|
|
|
|
{ |
785
|
3
|
|
|
3
|
1
|
905
|
my $self = shift; |
786
|
3
|
50
|
|
|
|
12
|
croak "set: must supply an even number of arguments" |
787
|
|
|
|
|
|
|
unless (@_ % 2 == 0); |
788
|
3
|
|
|
|
|
6
|
my ($field, $value); |
789
|
|
|
|
|
|
|
|
790
|
3
|
|
|
|
|
8
|
while (@_) |
791
|
|
|
|
|
|
|
{ |
792
|
4
|
|
|
|
|
19
|
($field,$value) = (shift,Text::BibTeX->_process_argument(shift, $self->{binmode}, $self->{normalization})); |
793
|
0
|
|
|
|
|
0
|
push (@{$self->{'fields'}}, $field) |
794
|
4
|
50
|
|
|
|
13
|
unless exists $self->{'values'}{$field}; |
795
|
4
|
|
|
|
|
12
|
$self->{'values'}{$field} = $value; |
796
|
|
|
|
|
|
|
} |
797
|
|
|
|
|
|
|
} |
798
|
|
|
|
|
|
|
|
799
|
|
|
|
|
|
|
sub delete |
800
|
|
|
|
|
|
|
{ |
801
|
2
|
|
|
2
|
1
|
6
|
my ($self, @fields) = @_; |
802
|
2
|
|
|
|
|
4
|
my (%gone); |
803
|
|
|
|
|
|
|
|
804
|
2
|
|
|
|
|
5
|
%gone = map {$_, 1} @fields; |
|
4
|
|
|
|
|
9
|
|
805
|
2
|
|
|
|
|
4
|
@{$self->{'fields'}} = grep (! $gone{$_}, @{$self->{'fields'}}); |
|
2
|
|
|
|
|
35
|
|
|
2
|
|
|
|
|
6
|
|
806
|
2
|
|
|
|
|
5
|
delete @{$self->{'values'}}{@fields}; |
|
2
|
|
|
|
|
9
|
|
807
|
|
|
|
|
|
|
} |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
sub set_fieldlist |
810
|
|
|
|
|
|
|
{ |
811
|
1
|
|
|
1
|
1
|
867
|
my ($self, $fields) = @_; |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
# Warn if any of the caller's fields aren't already present in the entry |
814
|
|
|
|
|
|
|
|
815
|
1
|
|
|
|
|
3
|
my ($field, %in_list); |
816
|
1
|
|
|
|
|
3
|
foreach $field (@$fields) |
817
|
|
|
|
|
|
|
{ |
818
|
4
|
|
|
|
|
8
|
$in_list{$field} = 1; |
819
|
4
|
100
|
|
|
|
10
|
unless (exists $self->{'values'}{$field}) |
820
|
|
|
|
|
|
|
{ |
821
|
1
|
|
|
|
|
151
|
carp "Implicitly adding undefined field \"$field\""; |
822
|
1
|
|
|
|
|
120
|
$self->{'values'}{$field} = undef; |
823
|
|
|
|
|
|
|
} |
824
|
|
|
|
|
|
|
} |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
# And see if there are any fields in the entry that aren't in the user's |
827
|
|
|
|
|
|
|
# list; delete them from the entry if so |
828
|
|
|
|
|
|
|
|
829
|
1
|
|
|
|
|
2
|
foreach $field (keys %{$self->{'values'}}) |
|
1
|
|
|
|
|
5
|
|
830
|
|
|
|
|
|
|
{ |
831
|
4
|
50
|
|
|
|
9
|
unless ($in_list{$field}) |
832
|
|
|
|
|
|
|
{ |
833
|
0
|
|
|
|
|
0
|
carp "Implicitly deleting field \"$field\""; |
834
|
0
|
|
|
|
|
0
|
delete $self->{'values'}{$field}; |
835
|
|
|
|
|
|
|
} |
836
|
|
|
|
|
|
|
} |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
# Now we can install (a copy of) the caller's desired field list; |
839
|
|
|
|
|
|
|
|
840
|
1
|
|
|
|
|
6
|
$self->{'fields'} = [@$fields]; |
841
|
|
|
|
|
|
|
} |
842
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
=head2 Entry output methods |
845
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
=over 4 |
847
|
|
|
|
|
|
|
|
848
|
|
|
|
|
|
|
=item write (BIBFILE) |
849
|
|
|
|
|
|
|
|
850
|
|
|
|
|
|
|
Prints a BibTeX entry on the filehandle associated with BIBFILE (which |
851
|
|
|
|
|
|
|
should be a C object, opened for output). Currently |
852
|
|
|
|
|
|
|
the printout is not particularly human-friendly; a highly configurable |
853
|
|
|
|
|
|
|
pretty-printer will be developed eventually. |
854
|
|
|
|
|
|
|
|
855
|
|
|
|
|
|
|
=item print (FILEHANDLE) |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
Prints a BibTeX entry on FILEHANDLE. |
858
|
|
|
|
|
|
|
|
859
|
|
|
|
|
|
|
=item print_s () |
860
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
Prints a BibTeX entry to a string, which is the return value. |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
=cut |
864
|
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
sub write |
866
|
|
|
|
|
|
|
{ |
867
|
1
|
|
|
1
|
1
|
10
|
my ($self, $bibfile) = @_; |
868
|
|
|
|
|
|
|
|
869
|
1
|
|
|
|
|
2
|
my $fh = $bibfile->{'handle'}; |
870
|
1
|
|
|
|
|
3
|
$self->print ($fh); |
871
|
|
|
|
|
|
|
} |
872
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
sub print |
874
|
|
|
|
|
|
|
{ |
875
|
3
|
|
|
3
|
1
|
695
|
my ($self, $handle) = @_; |
876
|
|
|
|
|
|
|
|
877
|
3
|
|
50
|
|
|
9
|
$handle ||= \*STDOUT; |
878
|
3
|
|
|
|
|
9
|
print $handle $self->print_s; |
879
|
|
|
|
|
|
|
} |
880
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
sub print_s |
882
|
|
|
|
|
|
|
{ |
883
|
4
|
|
|
4
|
1
|
7
|
my $self = shift; |
884
|
4
|
|
|
|
|
9
|
my ($field, $output); |
885
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
sub value_to_string |
887
|
|
|
|
|
|
|
{ |
888
|
16
|
|
|
16
|
0
|
19
|
my $value = shift; |
889
|
|
|
|
|
|
|
|
890
|
16
|
50
|
|
|
|
30
|
if (! ref $value) # just a string |
891
|
|
|
|
|
|
|
{ |
892
|
16
|
|
|
|
|
37
|
return "{$value}"; |
893
|
|
|
|
|
|
|
} |
894
|
|
|
|
|
|
|
else # a Text::BibTeX::Value object |
895
|
|
|
|
|
|
|
{ |
896
|
0
|
0
|
|
|
|
0
|
confess "value is a reference, but not to Text::BibTeX::Value object" |
897
|
|
|
|
|
|
|
unless $value->isa ('Text::BibTeX::Value'); |
898
|
0
|
|
|
|
|
0
|
my @values = $value->values; |
899
|
0
|
|
|
|
|
0
|
foreach (@values) |
900
|
|
|
|
|
|
|
{ |
901
|
0
|
0
|
|
|
|
0
|
$_ = $_->type == &BTAST_STRING ? '{' . $_->text . '}' : $_->text; |
902
|
|
|
|
|
|
|
} |
903
|
0
|
|
|
|
|
0
|
return join (' # ', @values); |
904
|
|
|
|
|
|
|
} |
905
|
|
|
|
|
|
|
} |
906
|
|
|
|
|
|
|
|
907
|
4
|
50
|
|
|
|
12
|
carp "entry type undefined" unless defined $self->{'type'}; |
908
|
4
|
50
|
|
|
|
10
|
carp "entry metatype undefined" unless defined $self->{'metatype'}; |
909
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
# Regular and macro-def entries have to be treated differently when |
911
|
|
|
|
|
|
|
# printing the first line, because the former have keys and the latter |
912
|
|
|
|
|
|
|
# do not. |
913
|
4
|
50
|
|
|
|
104
|
if ($self->{'metatype'} == &BTE_REGULAR) |
|
|
0
|
|
|
|
|
|
914
|
|
|
|
|
|
|
{ |
915
|
4
|
50
|
|
|
|
12
|
carp "entry key undefined" unless defined $self->{'key'}; |
916
|
|
|
|
|
|
|
$output = sprintf ("@%s{%s,\n", |
917
|
|
|
|
|
|
|
$self->{'type'} || '', |
918
|
4
|
|
50
|
|
|
32
|
$self->{'key'} || ''); |
|
|
|
50
|
|
|
|
|
919
|
|
|
|
|
|
|
} |
920
|
|
|
|
|
|
|
elsif ($self->{'metatype'} == &BTE_MACRODEF) |
921
|
|
|
|
|
|
|
{ |
922
|
|
|
|
|
|
|
$output = sprintf ("@%s{\n", |
923
|
0
|
|
0
|
|
|
0
|
$self->{'type'} || ''); |
924
|
|
|
|
|
|
|
} |
925
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
# Comment and preamble entries are treated the same -- we print out |
927
|
|
|
|
|
|
|
# the entire entry, on one line, right here. |
928
|
|
|
|
|
|
|
else # comment or preamble |
929
|
|
|
|
|
|
|
{ |
930
|
|
|
|
|
|
|
return sprintf ("@%s{%s}\n\n", |
931
|
|
|
|
|
|
|
$self->{'type'}, |
932
|
0
|
|
|
|
|
0
|
value_to_string ($self->{'value'})); |
933
|
|
|
|
|
|
|
} |
934
|
|
|
|
|
|
|
|
935
|
|
|
|
|
|
|
# Here we print out all the fields/values of a regular or macro-def entry |
936
|
4
|
|
|
|
|
9
|
my @fields = @{$self->{'fields'}}; |
|
4
|
|
|
|
|
15
|
|
937
|
4
|
|
|
|
|
12
|
while ($field = shift @fields) |
938
|
|
|
|
|
|
|
{ |
939
|
16
|
|
|
|
|
31
|
my $value = $self->{'values'}{$field}; |
940
|
16
|
50
|
|
|
|
31
|
if (! defined $value) |
941
|
|
|
|
|
|
|
{ |
942
|
0
|
|
|
|
|
0
|
carp "field \"$field\" has undefined value\n"; |
943
|
0
|
|
|
|
|
0
|
$value = ''; |
944
|
|
|
|
|
|
|
} |
945
|
|
|
|
|
|
|
|
946
|
16
|
|
|
|
|
32
|
$output .= " $field = "; |
947
|
16
|
|
|
|
|
29
|
$output .= value_to_string ($value); |
948
|
|
|
|
|
|
|
|
949
|
16
|
|
|
|
|
36
|
$output .= ",\n"; |
950
|
|
|
|
|
|
|
} |
951
|
|
|
|
|
|
|
|
952
|
|
|
|
|
|
|
# Tack on the last line, and we're done! |
953
|
4
|
|
|
|
|
8
|
$output .= "}\n\n"; |
954
|
|
|
|
|
|
|
|
955
|
4
|
|
|
|
|
25
|
Text::BibTeX->_process_result($output, $self->{binmode}, $self->{normalization}); |
956
|
|
|
|
|
|
|
} |
957
|
|
|
|
|
|
|
|
958
|
|
|
|
|
|
|
=back |
959
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
=head2 Miscellaneous methods |
961
|
|
|
|
|
|
|
|
962
|
|
|
|
|
|
|
=over 4 |
963
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
=item warn (WARNING [, FIELD]) |
965
|
|
|
|
|
|
|
|
966
|
|
|
|
|
|
|
Prepends a bit of location information (filename and line number(s)) to |
967
|
|
|
|
|
|
|
WARNING, appends a newline, and passes it to Perl's C. If FIELD is |
968
|
|
|
|
|
|
|
supplied, the line number given is just that of the field; otherwise, the |
969
|
|
|
|
|
|
|
range of lines for the whole entry is given. (Well, almost -- currently, |
970
|
|
|
|
|
|
|
the line number of the last field is used as the last line of the whole |
971
|
|
|
|
|
|
|
entry. This is a bug.) |
972
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
For example, if lines 10-15 of file F look like this: |
974
|
|
|
|
|
|
|
|
975
|
|
|
|
|
|
|
@article{homer97, |
976
|
|
|
|
|
|
|
author = {Homer Simpson and Ned Flanders}, |
977
|
|
|
|
|
|
|
title = {Territorial Imperatives in Modern Suburbia}, |
978
|
|
|
|
|
|
|
journal = {Journal of Suburban Studies}, |
979
|
|
|
|
|
|
|
year = 1997 |
980
|
|
|
|
|
|
|
} |
981
|
|
|
|
|
|
|
|
982
|
|
|
|
|
|
|
then, after parsing this entry to C<$entry>, the calls |
983
|
|
|
|
|
|
|
|
984
|
|
|
|
|
|
|
$entry->warn ('what a silly entry'); |
985
|
|
|
|
|
|
|
$entry->warn ('what a silly journal', 'journal'); |
986
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
would result in the following warnings being issued: |
988
|
|
|
|
|
|
|
|
989
|
|
|
|
|
|
|
foo.bib, lines 10-14: what a silly entry |
990
|
|
|
|
|
|
|
foo.bib, line 13: what a silly journal |
991
|
|
|
|
|
|
|
|
992
|
|
|
|
|
|
|
=cut |
993
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
sub warn |
995
|
|
|
|
|
|
|
{ |
996
|
0
|
|
|
0
|
1
|
0
|
my ($self, $warning, $field) = @_; |
997
|
|
|
|
|
|
|
|
998
|
0
|
|
|
|
|
0
|
my $location = ''; |
999
|
0
|
0
|
|
|
|
0
|
if ($self->{'file'}) |
1000
|
|
|
|
|
|
|
{ |
1001
|
0
|
|
|
|
|
0
|
$location = $self->{'file'}{'filename'} . ", "; |
1002
|
|
|
|
|
|
|
} |
1003
|
|
|
|
|
|
|
|
1004
|
0
|
|
|
|
|
0
|
my $lines = $self->{'lines'}; |
1005
|
0
|
0
|
|
|
|
0
|
my $entry_range = ($lines->{'START'} == $lines->{'STOP'}) |
1006
|
|
|
|
|
|
|
? "line $lines->{'START'}" |
1007
|
|
|
|
|
|
|
: "lines $lines->{'START'}-$lines->{'STOP'}"; |
1008
|
|
|
|
|
|
|
|
1009
|
0
|
0
|
|
|
|
0
|
if (defined $field) |
1010
|
|
|
|
|
|
|
{ |
1011
|
0
|
0
|
|
|
|
0
|
$location .= (exists $lines->{$field}) |
1012
|
|
|
|
|
|
|
? "line $lines->{$field}: " |
1013
|
|
|
|
|
|
|
: "$entry_range (unknown field \"$field\"): "; |
1014
|
|
|
|
|
|
|
} |
1015
|
|
|
|
|
|
|
else |
1016
|
|
|
|
|
|
|
{ |
1017
|
0
|
|
|
|
|
0
|
$location .= "$entry_range: "; |
1018
|
|
|
|
|
|
|
} |
1019
|
|
|
|
|
|
|
|
1020
|
0
|
|
|
|
|
0
|
warn "$location$warning\n"; |
1021
|
|
|
|
|
|
|
} |
1022
|
|
|
|
|
|
|
|
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
=item line ([FIELD]) |
1025
|
|
|
|
|
|
|
|
1026
|
|
|
|
|
|
|
Returns the line number of FIELD. If the entry was parsed from a string, |
1027
|
|
|
|
|
|
|
this still works--it's just the line number relative to the start of the |
1028
|
|
|
|
|
|
|
string. If the entry was parsed from a file, this works just as you'd |
1029
|
|
|
|
|
|
|
expect it to: it returns the absolute line number with respect to the |
1030
|
|
|
|
|
|
|
whole file. Line numbers are one-based. |
1031
|
|
|
|
|
|
|
|
1032
|
|
|
|
|
|
|
If FIELD is not supplied, returns a two-element list containing the line |
1033
|
|
|
|
|
|
|
numbers of the beginning and end of the whole entry. (Actually, the |
1034
|
|
|
|
|
|
|
"end" line number is currently inaccurate: it's really the the line |
1035
|
|
|
|
|
|
|
number of the last field in the entry. But it's better than nothing.) |
1036
|
|
|
|
|
|
|
|
1037
|
|
|
|
|
|
|
=cut |
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
sub line |
1040
|
|
|
|
|
|
|
{ |
1041
|
6
|
|
|
6
|
1
|
8
|
my ($self, $field) = @_; |
1042
|
|
|
|
|
|
|
|
1043
|
6
|
50
|
|
|
|
11
|
if (defined $field) |
1044
|
|
|
|
|
|
|
{ |
1045
|
6
|
|
|
|
|
20
|
return $self->{'lines'}{$field}; |
1046
|
|
|
|
|
|
|
} |
1047
|
|
|
|
|
|
|
else |
1048
|
|
|
|
|
|
|
{ |
1049
|
0
|
|
|
|
|
0
|
return @{$self->{'lines'}}{'START','STOP'}; |
|
0
|
|
|
|
|
0
|
|
1050
|
|
|
|
|
|
|
} |
1051
|
|
|
|
|
|
|
} |
1052
|
|
|
|
|
|
|
|
1053
|
|
|
|
|
|
|
=item filename () |
1054
|
|
|
|
|
|
|
|
1055
|
|
|
|
|
|
|
Returns the name of the file from which the entry was parsed. Only |
1056
|
|
|
|
|
|
|
works if the file is represented by a C object---if |
1057
|
|
|
|
|
|
|
you just passed a filename/filehandle pair to C, you can't get |
1058
|
|
|
|
|
|
|
the filename back. (Sorry.) |
1059
|
|
|
|
|
|
|
|
1060
|
|
|
|
|
|
|
=cut |
1061
|
|
|
|
|
|
|
|
1062
|
|
|
|
|
|
|
sub filename |
1063
|
|
|
|
|
|
|
{ |
1064
|
6
|
|
|
6
|
1
|
10
|
my $self = shift; |
1065
|
|
|
|
|
|
|
|
1066
|
6
|
|
|
|
|
20
|
$self->{'file'}{'filename'}; # ooh yuck -- poking into File object |
1067
|
|
|
|
|
|
|
} |
1068
|
|
|
|
|
|
|
|
1069
|
|
|
|
|
|
|
1; |
1070
|
|
|
|
|
|
|
|
1071
|
|
|
|
|
|
|
=back |
1072
|
|
|
|
|
|
|
|
1073
|
|
|
|
|
|
|
=head1 SEE ALSO |
1074
|
|
|
|
|
|
|
|
1075
|
|
|
|
|
|
|
L, L, L |
1076
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
=head1 AUTHOR |
1078
|
|
|
|
|
|
|
|
1079
|
|
|
|
|
|
|
Greg Ward |
1080
|
|
|
|
|
|
|
|
1081
|
|
|
|
|
|
|
=head1 COPYRIGHT |
1082
|
|
|
|
|
|
|
|
1083
|
|
|
|
|
|
|
Copyright (c) 1997-2000 by Gregory P. Ward. All rights reserved. This file |
1084
|
|
|
|
|
|
|
is part of the Text::BibTeX library. This library is free software; you |
1085
|
|
|
|
|
|
|
may redistribute it and/or modify it under the same terms as Perl itself. |
1086
|
|
|
|
|
|
|
|
1087
|
|
|
|
|
|
|
=cut |