| 1 |
#!/usr/local/bin/tclsh |
| 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-1997 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 Tcl(/Tk). |
| 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 Tcl to parse the result. |
| 33 |
# |
| 34 |
|
| 35 |
# take the first argument as file name |
| 36 |
set file [lindex $argv 0] |
| 37 |
|
| 38 |
set FD [open "|bibtool -q -- pass.comments=off -- print.line.length=999999 -- print.indent=0 -- print.align=0 $file" r] |
| 39 |
set bibtool_is_in_record 0 |
| 40 |
|
| 41 |
while { [gets $FD line] >= 0 } { |
| 42 |
if {[regexp {^\@STRING} $line]} { |
| 43 |
} elseif {[regexp {^\@PREAMBLE} $line]} { |
| 44 |
} elseif {[regexp {^\@COMMENT} $line]} { |
| 45 |
} elseif { !$bibtool_is_in_record && |
| 46 |
[regexp -nocase {^\@([a-z]*)\{[ ]*(.*),} $line all type key]} { |
| 47 |
puts "type: $type\nkey: $key" |
| 48 |
set bibtool_is_in_record 1 |
| 49 |
} elseif {$bibtool_is_in_record && |
| 50 |
[regexp -nocase {([a-z]*)=(.*)} $line all item value]} { |
| 51 |
regsub {,$} $value {} value |
| 52 |
puts "entry: $item\nvalue: $value" |
| 53 |
} elseif {$bibtool_is_in_record && $line=="\}"} { |
| 54 |
puts END_OF_RECORD |
| 55 |
set bibtool_is_in_record 0 |
| 56 |
} |
| 57 |
} |
| 58 |
close $FD |
| 59 |
|