#!/bin/sh # Copyright for the Uniform Repository Service (c) 1995, 1996, 1997, # by Gerald Banon. All rights reserved. # Version 1.1 # um.tcl \ exec ../../../../../dpi.inpe.br/banon/1997/10.21.17.24/doc/tcl8.0/unix/tclsh "$0" ${1+"$@"} # Create a mirror.bib file solving redundancies set col ../../../../.. proc LookUpCitationKey {inputList} { global data set outputList "" foreach i $inputList { set outputList "$outputList $data($i,citationkey)" } return $outputList } set fileList [glob $col/*/*/*/*/doc/@reference.bib] set firstFile yes foreach file $fileList { regexp "$col/(.*/.*/.*/.*)/doc/.*$" $file m rep puts "processing $rep/doc/@reference.bib ..." if [catch {open $file r} fileId] { puts stderr "Cannot open $file: $fileId" } else { set i 1 if [info exists data2] {unset data2} set fileContent [read $fileId] close $fileId regsub -all {",} $fileContent {"} fileContent regsub -all {\\"} $fileContent {\\{"}} fileContent ;# \"{0} regsub -all {\\} $fileContent {\\\\} fileContent regsub -all {{"}} $fileContent {{\"}} fileContent regsub -all "(\[^\n\])@" $fileContent {\1#%#} fileContent foreach entry [lrange [split $fileContent @] 1 end] { regexp "^(\[^\{\]*)\{(\[^,\]*)," $entry \ m entryType citationKey set data2($i,entrytype) $entryType set data2($i,citationkey) $citationKey regsub {^[^,]*,} $entry "" entry regsub "\n\}.*$" $entry "" entry foreach {field equal value} $entry { if {[lsearch -exact \ {version size} $field] < 0} { set data2($i,[string tolower $field]) $value } } if {! [info exists data2($i,repository)]} { set data2($i,annote) "entry from $rep" } incr i } if {$firstFile == "yes"} { if [info exists data] {unset data} array set data [array get data2] regsub -all {,entrytype} \ [array names data *,entrytype] {} iList set numberOfEntries [llength $iList] set firstFile no } else { # <<< regsub -all {,entrytype} [array names data2 *,entrytype] {} i2List foreach i2 $i2List { set i [lsearch -exact \ [LookUpCitationKey $iList] $data2($i2,citationkey)] if {$i >= 0} { if {[string compare $data([lindex $iList $i],title) \ $data2($i2,title)] != 0 } { regsub -all "$i2," \ [array names data2 $i2,*] {} fieldList incr numberOfEntries foreach field $fieldList { set data($numberOfEntries,$field) $data2($i2,$field) } } else { # <<< foreach field {url annote} { if [info exists data2($i2,$field)] { if [info exists data([lindex $iList $i],$field)] { set data([lindex $iList $i],${field}1) \ $data([lindex $iList $i],$field) unset data([lindex $iList $i],$field) } set j [llength [array names data \ [lindex $iList $i],${field}*]] incr j set data([lindex $iList $i],$field$j) $data2($i2,$field) } } # >>> } } else { regsub -all "$i2," [array names data2 $i2,*] {} fieldList incr numberOfEntries foreach field $fieldList { set data($numberOfEntries,$field) $data2($i2,$field) } } } # >>> } } } proc FieldCompare {a b} { global entryType set arr(Article,author) a set arr(Article,title) b set arr(Article,journal) c set arr(Article,year) d set arr(Article,volume) e set arr(Article,number) f set arr(Article,pages) g set arr(Article,month) h set arr(Article,note) i set arr(Article,keywords) j set arr(Book,author) a set arr(Book,editor) b set arr(Book,title) c set arr(Book,publisher) d set arr(Book,year) e set arr(Book,volume) f set arr(Book,series) g set arr(Book,address) h set arr(Book,edition) i set arr(Book,month) j set arr(Book,note) k set arr(Book,keywords) l set arr(Booklet,title) a set arr(Booklet,author) b set arr(Booklet,howpublished) c set arr(Booklet,address) d set arr(Booklet,month) e set arr(Booklet,year) f set arr(Booklet,note) g set arr(Booklet,keywords) h set arr(InBook,author) a set arr(InBook,editor) b set arr(InBook,title) c set arr(InBook,chapter) d set arr(InBook,pages) e set arr(InBook,publisher) f set arr(InBook,year) g set arr(InBook,volume) h set arr(InBook,series) i set arr(InBook,address) j set arr(InBook,edition) k set arr(InBook,month) l set arr(InBook,note) m set arr(InBook,keywords) n set arr(InCollection,author) a set arr(InCollection,title) b set arr(InCollection,booktitle) c set arr(InCollection,publisher) d set arr(InCollection,year) e set arr(InCollection,editor) f set arr(InCollection,chapter) g set arr(InCollection,pages) h set arr(InCollection,address) i set arr(InCollection,month) j set arr(InCollection,note) k set arr(InCollection,keywords) l set arr(InProceedings,author) a set arr(InProceedings,title) b set arr(InProceedings,booktitle) c set arr(InProceedings,year) d set arr(InProceedings,editor) e set arr(InProceedings,pages) f set arr(InProceedings,organization) g set arr(InProceedings,publisher) h set arr(InProceedings,address) i set arr(InProceedings,month) j set arr(InProceedings,note) k set arr(InProceedings,keywords) l set arr(Manual,title) a set arr(Manual,author) b set arr(Manual,organization) c set arr(Manual,address) d set arr(Manual,edition) e set arr(Manual,month) f set arr(Manual,year) g set arr(Manual,note) h set arr(Manual,keywords) i set arr(MastersThesis,author) a set arr(MastersThesis,title) b set arr(MastersThesis,school) c set arr(MastersThesis,year) d set arr(MastersThesis,address) e set arr(MastersThesis,month) f set arr(MastersThesis,note) g set arr(MastersThesis,keywords) h set arr(Misc,author) a set arr(Misc,title) b set arr(Misc,howpublished) c set arr(Misc,month) d set arr(Misc,year) e set arr(Misc,note) f set arr(Misc,keywords) g set arr(PhdThesis,author) a set arr(PhdThesis,title) b set arr(PhdThesis,school) c set arr(PhdThesis,year) d set arr(PhdThesis,address) e set arr(PhdThesis,month) f set arr(PhdThesis,note) g set arr(PhdThesis,keywords) h set arr(Proceedings,title) a set arr(Proceedings,year) b set arr(Proceedings,editor) c set arr(Proceedings,publisher) d set arr(Proceedings,organization) e set arr(Proceedings,address) f set arr(Proceedings,month) g set arr(Proceedings,note) h set arr(Proceedings,keywords) i set arr(TechReport,author) a set arr(TechReport,title) b set arr(TechReport,institution) c set arr(TechReport,year) d set arr(TechReport,type) e set arr(TechReport,number) f set arr(TechReport,address) g set arr(TechReport,month) h set arr(TechReport,note) i set arr(TechReport,keywords) j set arr(Unpublished,author) a set arr(Unpublished,title) b set arr(Unpublished,note) c set arr(Unpublished,month) d set arr(Unpublished,year) e set arr(Unpublished,keywords) f if {[info exists arr($entryType,$a)] && \ [info exists arr($entryType,$b)]} { return [string compare \ [set arr($entryType,$a)] [set arr($entryType,$b)]] } if {[info exists arr($entryType,$a)] && \ ! [info exists arr($entryType,$b)]} { return -1 } if {! [info exists arr($entryType,$a)] && \ [info exists arr($entryType,$b)]} { return 1 } if {! [info exists arr($entryType,$a)] && \ ! [info exists arr($entryType,$b)]} { return [string compare $a $b] } } proc EntryCompare {a b} { global data set citationKeyA $data($a,citationkey) set citationKeyB $data($b,citationkey) return [string compare $citationKeyA $citationKeyB] } set output "" # set output [lappend output
] # set output [lappend output {] # set output [lappend output "Number of entries: $numberOfEntries\n"] regsub -all {,entrytype} [array names data *,entrytype] {} iList foreach i [lsort -command EntryCompare $iList] { set output [lappend output \ @$data($i,entrytype)\{$data($i,citationkey),] regsub -all "$i," [array names data $i,*] {} fieldList set entryType $data($i,entrytype) foreach field [lsort -command FieldCompare $fieldList] { set output [lappend output \ [format " %-18s" "${field} = "]\"$data($i,$field)\",] } set output [lappend output \}\n] } # set output [lappend output] if [catch {open ../not_sent/.setenv/mirror_path r} fileId] { puts stderr "Cannot open ../not_sent/.setenv/mirror_path: $fileId" } else { set mirrorPath [read $fileId] } close $fileId set fileId [open $col/[string trim $mirrorPath]/doc/mirror.bib a] regsub -all {\\{"}} [join $output \n] {\\"} fileContent ;# \"{o} regsub -all {#%#} $fileContent {@} fileContent regsub -all {url[0-9]*} $fileContent {URL} fileContent puts $fileId $fileContent close $fileId