summaryrefslogtreecommitdiffstats
path: root/tcllib/examples/bibtex
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 19:39:39 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 19:39:39 (GMT)
commitea28451286d3ea4a772fa174483f9a7a66bb1ab3 (patch)
tree6ee9d8a7848333a7ceeee3b13d492e40225f8b86 /tcllib/examples/bibtex
parentb5ca09bae0d6a1edce939eea03594dd56383f2c8 (diff)
parent7c621da28f07e449ad90c387344f07a453927569 (diff)
downloadblt-ea28451286d3ea4a772fa174483f9a7a66bb1ab3.zip
blt-ea28451286d3ea4a772fa174483f9a7a66bb1ab3.tar.gz
blt-ea28451286d3ea4a772fa174483f9a7a66bb1ab3.tar.bz2
Merge commit '7c621da28f07e449ad90c387344f07a453927569' as 'tcllib'
Diffstat (limited to 'tcllib/examples/bibtex')
-rw-r--r--tcllib/examples/bibtex/bibtex.tcl70
1 files changed, 70 insertions, 0 deletions
diff --git a/tcllib/examples/bibtex/bibtex.tcl b/tcllib/examples/bibtex/bibtex.tcl
new file mode 100644
index 0000000..7cd91b4
--- /dev/null
+++ b/tcllib/examples/bibtex/bibtex.tcl
@@ -0,0 +1,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