-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtclbib.tcl
533 lines (445 loc) · 12.3 KB
/
tclbib.tcl
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"
lappend auto_path [file dirname [info script]]/tcllib
package require Control 1.0
package require Gui 1.0
package require Db 1.0
package require Ilf 1.0
package require Basic 1.0
package require Nlm 1.0
package require Memo 1.0
package require Html 1.0
package require BibTeX 1.0
package require Csv 1.0
package require TeX 1.0
package require Rtf 1.0
Basic::Basic
namespace import Basic::*
#namespace import Basic::busy Basic::openFile Basic::saveFile
font create ansi -family Helvetica -size 10 -weight bold
font create ansifixed -family Courier -size 10 -weight normal
# Control::
set wrapMode 0
set sortMode AUTHOR
set outputTeXId 0
set outputSelected 1
# Achtung: dieses Datum wird im Makefile auf das aktuelle Datum gesetzt
set version "2001-01-26"
if { $tcl_platform(platform) == "unix" } {
set defpath [pwd]
set rcfile ~/.tclbibrc
set tmpFile /tmp/ilf.tmp
} else {
set defpath .
set rcfile "E:/tclbib.ini"
set tmpFile "C:/ilf.tmp"
font configure ansi -family Helvetica -size 9 -weight normal
font configure ansifixed -family Courier -size 9 -weight normal
}
set showAll 1
set dbWidget 0
set dbHasChanged 0
set lineNumber -1
# lokales resource file deaktiviert
#if [ file exists $rcfile ] {
# source $rcfile
#}
proc reallyContinue { a } {
global dbHasChanged
if { ! $dbHasChanged } {
return 1
}
set r [tk_messageBox \
-message [format "You will loose your %d changes !\nReally %s?" \
$dbHasChanged $a ] \
-type yesno -icon warning]
if { $r } {
return 1
}
return 0
}
# Convenience Routinen
proc arr2list { arrVar } {
upvar $arrVar arr
set l [list]
set searchId [array startsearch arr]
while { [array anymore arr $searchId] } {
set e [array nextelement arr $searchId]
if { $arr($e) == 1 } {
lappend l $e
}
}
array donesearch arr $searchId
return $l
}
proc searchAll { s1 } {
global showAll
set idlist [list]
set s1 [format "*%s*" [ string tolower $s1 ]]
global sArr
set searchFieldList [arr2list sArr]
foreach entry $Db::dbList {
if { $showAll || [Entry::isSelected $entry] } {
foreach field $searchFieldList {
set s2 [ string tolower [Entry::getField $entry $field] ]
if { [string match $s1 $s2] } {
lappend idlist [Entry::getId $entry]
break
}
}
}
}
Db::selectEntry [Db::getSelected 1] 0
Db::selectEntry $idlist
set showAll 0
updateDisplay
}
proc exportOptionsDialog { } {
set w .exportDialog
set searchWord ""
if { ![Basic::initTransientDialog $w "Export Options"] } {
return
}
frame $w.whatframe -relief groove -bd 2
set f $w.whatframe
checkbutton $f.wrapMode -text "Wrap Lines In Output" -variable wrapMode
checkbutton $f.texId -text "Include TexID" -variable outputTeXId
checkbutton $f.sel -text "Selected only" -variable outputSelected
pack $f.wrapMode $f.texId $f.sel -side top -anchor w
pack $f -fill x -side top
set f $w.buttonframe
frame $f -bd 10
button $f.help -text Help -command {
tk_messageBox -message \
"Wrap Lines In Output: sinnvoll, wenn man die Ausgabe direkt ausdrucken möchte.\n\
Include TexID: sinnvoll, wenn man mit bibtex arbeitet.\n\
Selected only: Gesamtliste oder nur die * Auswahl ausgeben?"
}
button $f.ok -default active -text Ok -command " destroy $w "
bind $w <Return> "$f.ok invoke"
pack $f.help $f.ok -side left -expand 1
pack $f -fill x -side top
}
proc searchDialog { } {
set w .searchDialog
set searchWord ""
if { ! [Basic::initTransientDialog $w "Search"] } {
return
}
set f $w.whatframe
frame $f -relief groove -bd 2
set n 0
global sArr
foreach fieldName [Entry::getSearchFields] {
set fn [string tolower $fieldName]
checkbutton $f.$fn -text $fieldName \
-variable sArr($fieldName)
grid configure $f.$fn -in $f -sticky w \
-row [expr $n / 3] -column [expr $n % 3]
incr n
}
grid columnconfigure $f [list 0 1 2] -minsize 40
pack $f
set f $w.search
frame $f -relief groove -bd 2
label $f.text -text "Enter:"
entry $f.entry -textvariable searchWord
pack $f.text $f.entry -side left
pack $f -fill x -side top
focus $f.entry
set f $w.buttonframe
frame $f -bd 10
button $f.close -text Close -command " destroy $w "
button $f.help -text Help -command {
tk_messageBox -message \
"Bei 'Show selected' wird nur innerhalb der selektierten Eintraege gesucht .\
'?' bzw. '\*' stehen fuer 1 bzw. 0-n beliebige Zeichen"
}
button $f.ok -default active -text {Search } -command { busy; searchAll $searchWord }
#bind $w <Return> { searchAll $searchWord ; destroy .searchDialog }
bind $w <Return> "$f.ok invoke"
bind $w <Escape> "$f.close invoke"
pack $f.close $f.help $f.ok -side left -expand 1
pack $f -fill x -side top
}
proc compRecords { i1 i2 } {
global fieldNameIndex
set t1 [lindex [lindex $dbList $i1] $fieldNameIndex(Title) ]
set t2 [lindex [lindex $dbList $i2] $fieldNameIndex(Title) ]
set t1 [string tolower $t1]
set t2 [string tolower $t2]
regsub -all { [^a-z0-9] } $t1 "" t1
regsub -all { [^a-z0-9] } $t2 "" t2
if { [string compare $t1 $t2] != 0} {
return 1
}
return 0
}
proc getListSelection { } {
global dbWidget
set idlist [list]
foreach i [ $dbWidget curselection] {
lappend idlist [string range [$dbWidget get $i] 1 3 ]
}
return $idlist
}
proc selectDuplicate { } {
global sortMode
set saveSortMode $sortMode
Db::sort TEXID
set prevtexid ""
set previd ""
foreach entry $Db::dbList {
set texid [ Entry::getField $entry TEXID ]
set id [ Entry::getId $entry ]
if { $texid == $prevtexid } {
Db::selectEntry $id
Db::selectEntry $previd
}
set previd $id
set prevtexid $texid
}
set sortMode $saveSortMode
updateDisplay
}
proc selectRecord { cmd } {
busy
switch -- $cmd {
"none" { Db::selectAllEntries 0}
"all" { Db::selectAllEntries 1}
"select" { Db::selectEntry [getListSelection] 1}
"deselect" { Db::selectEntry [getListSelection] 0}
"invertall" { Db::invertAllEntries }
}
updateDisplay nosort
}
proc delRecord { } {
set idList [Db::getSelected 1]
foreach id $idList {
destroy .text$id
}
Db::deleteEntry $idList
updateDisplay nosort
}
proc newRecord { type } {
global dbWidget
set entry [Entry::getNew]
Entry::setField entry AUTHOR ""
Entry::setField entry TITLE ""
Entry::setField entry PDATE ""
Entry::setField entry DOMAIN "M"
switch -- $type {
"article" {
Entry::setField entry JOURNAL ""
Entry::setField entry NUMBER ""
Entry::setField entry PAGES ""
Entry::setField entry VOLUME ""
}
"book" {
Entry::setField entry EDITOR ""
Entry::setField entry PUBLISHER ""
Entry::setField entry PADDRESS ""
Entry::setField entry ISBN ""
}
"inbook" {
Entry::setField entry PUBLISHER ""
Entry::setField entry PADDRESS ""
Entry::setField entry EDITOR ""
Entry::setField entry PAGES ""
Entry::setField entry ISBN ""
}
"incollection" {
Entry::setField entry BOOKTITLE ""
Entry::setField entry PUBLISHER ""
Entry::setField entry PADDRESS ""
Entry::setField entry EDITOR ""
Entry::setField entry PAGES ""
Entry::setField entry ISBN ""
}
"inproceedings" {
Entry::setField entry BOOKTITLE ""
Entry::setField entry EDITOR ""
Entry::setField entry ORGANIZATION ""
Entry::setField entry SERIES ""
Entry::setField entry PAGES ""
Entry::setField entry PUBLISHER ""
Entry::setField entry PADDRESS ""
}
}
Entry::setField entry PLACE ""
Entry::setField entry CONTENT ""
Entry::setField entry DOI ""
Entry::setField entry PTYPE $type
Db::addEntry entry
# Hinscrollen
$dbWidget yview moveto 1
updateDisplay nosort
# Fenster öffnen
Gui::entryDialog [ Entry::getId $entry]
}
proc entryDialogSave { w cls} {
global dbHasChanged
# ID aus dem Fenstertitel holen
set id [wm title $w]
set s [$w.text get 1.0 end]
# Eintrag mit **** beenden
append s "\n****"
set entry [list]
# Eintrag aktualisieren
incr dbHasChanged
Db::replaceEntry [Ilf::scanEntry $s $id]
updateDisplay
# Fenster schliesen
if { $cls } {
destroy $w
}
}
# wird momentan nicht genutzt FAM 210300
proc authorList { } {
global dbWidget
global dbList
global mainWindowBgColor
global mainWindowFgColor
set w .aList
if { ! [Basic::initDialog $w "Authors"] } return
frame $w.frame
pack $w.frame -side top -fill both -expand yes
scrollbar $w.frame.vscroll -orient vertical \
-command "$w.frame.list yview"
listbox $w.frame.list -font ansifixed -width 104 -height 200\
-yscroll "$w.frame.vscroll set" \
-selectmode extended -bg $mainWindowBgColor -fg $mainWindowFgColor
set aWidget $w.frame.list
$aWidget delete 0 end
}
proc updateDisplay { { sort yes } } {
global dbWidget
global sortMode
global showAll
global status
set yl [$dbWidget yview]
if {$sort == "yes"} {
Db::sort $sortMode
}
$dbWidget delete 0 end
foreach entry $Db::dbList {
if { $showAll || [Entry::isSelected $entry] } {
$dbWidget insert end [Entry::getString $entry]
}
}
set s [$dbWidget size]
if { $s == 1 } {
set e entry
} else {
set e entries
}
if { $showAll == 0 } {
if { $s == 0 } {
set status "no entries selected - use \"Show all\""
} else {
set status [format "%d %s selected" $s $e]
}
} else {
set status [format "%d %s" $s $e]
}
Gui::updateSelection
$dbWidget yview moveto [lindex $yl 0]
busy 0
}
proc warnSaver { } {
global dbHasChanged
if { $dbHasChanged > 0 } {
if { $dbHasChanged == 1 } {
set msg "You have made one change.\nBetter save some time."
} else {
set msg [format "You have made %d changes.\nBetter save some time..." \
$dbHasChanged]
}
Basic::Warning $msg
}
after 600000 warnSaver
}
proc askExport { } {
global outputSelected
set n [llength [Db::getSelected 1]]
if { $n == 0 && $outputSelected } {
# set outputSelected 0
tk_messageBox \
-message [format "Export options is \"selected only\".\
But nothing is selected. \
So please select some entries first!" ] \
-type ok -icon warning
return cancel
}
return ok
}
proc newIlf { } {
global dbHasChanged
if { ! [reallyContinue New] } {
return
}
set dbHasChanged 0
# Alle noch offenen Entry Fenster schliessen
# Frage waeren hier zwecklos..
foreach w [winfo children .] {
if { [string match ".text*" $w] } {
destroy $w
}
}
Db::new
updateDisplay nosort
Control::setFilename UNTITLED
}
###########################################################################
# HIER STARTET DAS PROGRAMM
###########################################################################
foreach field [list AUTHOR TITLE ] {
set sArr($field) 1
}
Gui::create
set dbWidget .frame.list
newIlf
# Geht nicht unter Win ?
#doEntryConfigure
.menu.edit entryconfigure "Delete" -state disabled
focus .frame.vscroll
if { $argc == 1 } {
Control::openIlf [lindex $argv 0]
}
if { $argc == 3 } {
Control::openIlf [lindex $argv 0]
selectRecord all
Control::export [lindex $argv 1 ] [ lindex $argv 2 ]
exit
}
after 600000 warnSaver
###########################################################################
# AB HIER TESTUMGEBUNG
###########################################################################
set test 0
if { $test != 0 } {
puts [ time [Control::openIlf /home/frank/Literatur/frank.ilf ]]
#puts [ time [openIlf /usr/local/share/Literatur/imi_arch.ilf ]]
Control::importNlm "testdata/out.nlm"
set outputSelected 0
set outputTeXId 1
#newIlf
#puts [time [mergeNLM conny.nlm]]
#newIlf
#puts [time [mergeNLM conny.nlm]]
Control::saveAsIlf conny.ilf
Control::saveIlf
newIlf
Control::openIlf conny.ilf
#newIlf
#openIlf conny.ilf
##exportBib conny.bib
Control::export Csv conny.csv
Control::export Memo conny.txt
Control::export Html conny.htm
Control::export Rtf conny.rtf
Control::export TeX conny.tex
Control::export BibTeX conny.bib
exit
}