blob: 7cd91b4000bc843f6af87d0e39e947ce20eda1b4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#!/usr/bin/env tclsh
## -*- tcl -*-
#####
#
# "BibTeX parser" -- Example Application.
# http://wiki.tcl.tk/13719
#
# Tcl code harvested on: 7 Mar 2005, 23:55 GMT
# Wiki page last updated: ???
#
#####
# bibtex.tcl --
#
# A basic parser for BibTeX bibliography databases.
#
# Copyright (c) 2005 Neil Madden.
# License: Tcl/BSD style.
package require Tcl 8.4
package require bibtex
proc readfile file {
set fd [open $file]
set cn [read $fd]
close $fd
return $cn
}
proc progress {token percent} {
set str [format "Processing: \[%3d%%\]" $percent]
puts -nonewline "\r$str"
flush stdout
return
}
proc count {token type key data} {
#puts "== $token $type $key"
global count total
if {[info exists count($type)]} {
incr count($type)
} else {
set count($type) 1
}
incr total
return
}
# ### ### ### ######### ######### #########
puts -nonewline "Processing: \[ 0%\]"; flush stdout
array set count { }
set total 0
bibtex::parse \
-recordcommand count \
-progresscommand progress \
[readfile [lindex $argv 0]]
puts ""
puts "Summary ======"
puts "Total: $total"
parray count
# ### ### ### ######### ######### #########
# EOF
exit
|