Index: modules/bibtex/bibtex.man ================================================================== --- modules/bibtex/bibtex.man +++ modules/bibtex/bibtex.man @@ -1,17 +1,18 @@ [comment {-*- tcl -*- doctools manpage}] -[manpage_begin bibtex n 0.5] +[vset VERSION 0.6] +[manpage_begin bibtex n [vset VERSION]] [keywords bibliography] [keywords bibtex] [keywords parsing] [keywords {text processing}] [copyright {2005 for documentation, Andreas Kupries }] [moddesc {bibtex}] [titledesc {Parse bibtex files}] [category {Text processing}] [require Tcl 8.4] -[require bibtex [opt 0.5]] +[require bibtex [opt [vset VERSION]]] [description] [para] This package provides commands for the parsing of bibliographies in BibTeX format. @@ -74,10 +75,11 @@ [opt "[option -recordcommand] [arg recordcmd]"] \ [opt "[option -preamblecommand] [arg preamblecmd]"] \ [opt "[option -stringcommand] [arg stringcmd]"] \ [opt "[option -commentcommand] [arg commentcmd]"] \ [opt "[option -progresscommand] [arg progresscmd]"] \ + [opt "[option -casesensitivestrings] [arg bool]"] \ "([arg text] | [option -channel] [arg chan])"] This is the most low-level form for the parser. The returned result will be a handle for the parser. During processing it will invoke the invoke the specified callback commands for each type of data found in @@ -97,10 +99,16 @@ arguments depends on the callback and is explained below. The first argument will however always be the handle of the parser invoking the callback. [list_begin definitions] + +[def "[option -casesensitivestrings]"] + +This option takes a boolean value. When set string macro processing +becomes case-sensitive. The default is case-insensitive string macro +processing. [def "[cmd recordcmd] [arg token] [arg type] [arg key] [arg recorddict]"] This callback is invoked whenever the parser detects a bibliography record in the input. Its arguments are the record type, the Index: modules/bibtex/bibtex.pcx ================================================================== --- modules/bibtex/bibtex.pcx +++ modules/bibtex/bibtex.pcx @@ -8,10 +8,11 @@ # package require pcx pcx::register bibtex pcx::tcldep 0.5 needs tcl 8.5 +pcx::tcldep 0.6 needs tcl 8.5 namespace eval ::bibtex {} pcx::message parseSaxCmdErr {Options -*command and -command exclude each other} err @@ -50,9 +51,35 @@ }} pcx::check 0.5 std ::bibtex::wait \ {checkSimpleArgs 1 1 { checkWord }} + +pcx::check 0.6 std ::bibtex::parse \ + {checkSimpleArgs 1 -1 { + {checkConstrained { + checkSwitches exact { + {-casesensitivestrings checkBoolean} + {-recordcommand {checkSetConstraint sax {checkProcCall 4}}} + {-preamblecommand {checkSetConstraint sax {checkProcCall 2}}} + {-stringcommand {checkSetConstraint sax {checkProcCall 2}}} + {-commentcommand {checkSetConstraint sax {checkProcCall 2}}} + {-progresscommand {checkSetConstraint sax {checkProcCall 2}}} + {-command {checkSetConstraint cmd {checkProcCall 2}}} + {-channel {checkSetConstraint chan checkChannelID}} + } {checkConstraint { + {{chan sax cmd} {warn bibtex::parseSaxCmdErr {} checkAtEnd}} + {{sax cmd} {warn bibtex::parseSaxCmdErr {} { + checkSimpleArgs 1 1 { + checkWord + } + }}} + {chan checkAtEnd} + } {checkSimpleArgs 1 1 { + checkWord + }}} + }} + }} # Initialization via pcx::init. # Use a ::bibtex::init procedure for non-standard initialization. pcx::complete Index: modules/bibtex/bibtex.tcl ================================================================== --- modules/bibtex/bibtex.tcl +++ modules/bibtex/bibtex.tcl @@ -161,17 +161,18 @@ # Basic processing of the argument list # and the options found therein. set opts [lrange [::cmdline::GetOptionDefaults { - {command.arg {}} - {channel.arg {}} - {recordcommand.arg {}} - {preamblecommand.arg {}} - {stringcommand.arg {}} - {commentcommand.arg {}} - {progresscommand.arg {}} + {command.arg {}} + {channel.arg {}} + {recordcommand.arg {}} + {preamblecommand.arg {}} + {stringcommand.arg {}} + {commentcommand.arg {}} + {progresscommand.arg {}} + {casesensitivestrings.arg {}} } result] 2 end] ;# Remove ? and help. set argc [llength $argv] while {[set err [::cmdline::getopt argv $opts opt arg]]} { if {$err < 0} { @@ -248,10 +249,17 @@ if {![info exists state(-stringcommand)]} { set state(-stringcommand) [list ::bibtex::addStrings] } if {![info exists state(-recordcommand)] && (!$sax)} { set state(-recordcommand) [list ::bibtex::AddRecord] + } + if {[info exists state(-casesensitivestrings)] && + $state(-casesensitivestrings) + } { + set state(casesensitivestrings) 1 + } else { + set state(casesensitivestrings) 0 } return } proc ::bibtex::Callback {token type args} { @@ -361,31 +369,44 @@ -> cmnt rest]} { # Are @comments blocks, or just 1 line? # Does anyone care? Callback $token comment $cmnt - } elseif {[regexp -nocase {\s*string[^\{]*\{(.*)\}[^\}]*} \ + } elseif {[regexp -nocase {^\s*string[^\{]*\{(.*)\}[^\}]*} \ $block -> rest]} { # string macro defs - Callback $token string [ParseBlock $rest] - + if {$data($token,casesensitivestrings)} { + Callback $token string [ParseString $rest] + } else { + Callback $token string [ParseBlock $rest] + } } elseif {[regexp -nocase {\s*preamble[^\{]*\{(.*)\}[^\}]*} \ $block -> rest]} { Callback $token preamble $rest } elseif {[regexp {([^\{]+)\{([^,]*),(.*)\}[^\}]*} \ $block -> type key rest]} { - # Do any @string mappings (these are case insensitive) - set rest [string map -nocase $data($token,strings) $rest] + # Do any @string mappings + if {$data($token,casesensitivestrings)} { + # puts $data($token,strings) + set rest [string map $data($token,strings) $rest] + } else { + set rest [string map -nocase $data($token,strings) $rest] + } Callback $token record [Tidy $type] [string trim $key] \ [ParseBlock $rest] } else { ## FUTURE: Use a logger. puts stderr "Skipping: $block" } } } + +proc ::bibtex::ParseString {block} { + regexp {(\S+)[^=]*=(.*)} $block -> key rest + return [list $key $rest] +} proc ::bibtex::ParseBlock {block} { set ret [list] set index 0 while { @@ -475,7 +496,7 @@ ## } # ### ### ### ######### ######### ######### ## Ready to go -package provide bibtex 0.5 +package provide bibtex 0.6 # EOF Index: modules/bibtex/pkgIndex.tcl ================================================================== --- modules/bibtex/pkgIndex.tcl +++ modules/bibtex/pkgIndex.tcl @@ -1,2 +1,2 @@ if {![package vsatisfies [package provide Tcl] 8.4]} {return} -package ifneeded bibtex 0.5 [list source [file join $dir bibtex.tcl]] +package ifneeded bibtex 0.6 [list source [file join $dir bibtex.tcl]]