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