Debian Codegraph @

Perl/bibtool.pl

raw ◀ ▶
1 Debian patch touch this file
•1 #!/usr/bin/perl
2 ##*****************************************************************************
3 ##
4 ## This file is part of BibTool.
5 ## It is distributed under the GNU General Public License.
6 ## See the file COPYING for details.
7 ##
8 ## (c) 1996-2020 Gerd Neugebauer
9 ##
10 ## Net: [email protected]
11 ##
12 ## This program is free software; you can redistribute it and/or modify
13 ## it under the terms of the GNU General Public License as published by
14 ## the Free Software Foundation; either version 2, or (at your option)
15 ## any later version.
16 ##
17 ## This program is distributed in the hope that it will be useful,
18 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ## GNU General Public License for more details.
21 ##
22 ## You should have received a copy of the GNU General Public License
23 ## along with this program; if not, write to the Free Software
24 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 ##
26 ##*****************************************************************************
27 #
28 # This sample file shows how bibtool can be interfaced with Perl.
29 # BibTool is assumed to be on the search path for executables.
30 # BibTool is called with the appropriate parameters. In this examples
31 # it is used only for normalization of the BibTeX database.
32 # Afterwards it is rather simple for Perl to parse the result.
33 #
34
35 $file=$ARGV[0]; # take the first argument as file name
36
37 open(FD,"bibtool -q -- expand.macros=on -- pass.comments=off -- print.line.length=999999 -- print.indent=0 -- print.align=0 $file |");
38 $bibtool_is_in_record = 0;
39 while(<FD>) {
40 if (/^\@STRING/o) {
41 }
42 elsif (/^\@PREAMBLE/o) {
43 }
44 elsif (/^\@COMMENT/o) {
45 }
46 elsif ($bibtool_is_in_record == 0 && /^@([a-zA-Z]*){[ \t]*(.*),/o) {
47 $type = $1;
48 $key = $2;
49 printf("type: %s\nkey: %s\n",$type,$key);
50 $bibtool_is_in_record = 1;
51 }
52 elsif ($bibtool_is_in_record == 1 && /([a-zA-Z]*)=(.*)$/o) {
53 $item = $1;
54 $value = $2;
55 printf("entry: %s\nvalue: %s\n",$item,$value);
56 }
57 elsif ($bibtool_is_in_record == 1 && /^}/o) {
58 printf("END_OF_RECORD\n");
59 $bibtool_is_in_record = 0;
60 }
61 }
62 close(FD);
63