Bug fix: GRS records wasn't recognized.
[ir-tcl-moved-to-github.git] / formats / line.tcl
1 # IR toolkit for tcl/tk
2 # (c) Index Data 1995
3 # See the file LICENSE for details.
4 # Sebastian Hammer, Adam Dickmeiss
5 #
6 # $Log: line.tcl,v $
7 # Revision 1.12  1996-03-29 16:05:36  adam
8 # Bug fix: GRS records wasn't recognized.
9 #
10 # Revision 1.11  1996/01/23  15:24:21  adam
11 # Wrore more comments.
12 #
13 # Revision 1.10  1995/10/17  17:39:46  adam
14 # Minor bug fix in call to display-grs-line.
15 #
16 # Revision 1.9  1995/10/17  14:18:09  adam
17 # Minor changes in presentation formats.
18 #
19 # Revision 1.8  1995/10/17  10:58:08  adam
20 # More work on presentation formats.
21 #
22 # Revision 1.7  1995/09/20  11:37:06  adam
23 # Work on GRS.
24 #
25 # Revision 1.6  1995/06/29  12:34:20  adam
26 # IrTcl now works with both tk4.0b4/tcl7.4b4 and tk3.6/tcl7.3
27 #
28 # Revision 1.5  1995/06/22  13:16:28  adam
29 # Feature: SUTRS. Setting getSutrs implemented.
30 # Work on display formats.
31 #
32 # Revision 1.4  1995/06/19  08:10:21  adam
33 # Inverse highligt colours in monochrome mode.
34 #
35 # Revision 1.3  1995/06/16  12:29:00  adam
36 # Use insertWithTags on diagnostic errors.
37 #
38 # Revision 1.2  1995/06/13  14:39:06  adam
39 # Fix: if {$var != ""} doesn't work if var is a large numerical!
40 # Highlight when line format is used.
41 #
42 # Revision 1.1  1995/06/12  15:18:10  adam
43 # Work on presentation formats. These are used in the main window as well
44 # as popup windows.
45 #
46 #
47
48 proc display-grs-line {w r i} {
49     foreach e $r {
50         for {set j 0} {$j < $i} {incr j} {
51             insertWithTags $w "  " {}
52         }
53         insertWithTags $w "([lindex $e 0]:[lindex $e 2])" marc-tag
54         if {[lindex $e 3] == "string"} {
55             insertWithTags $w [lindex $e 4] {}
56             insertWithTags $w "\n" {}
57         } elseif {[lindex $e 3] == "subtree"} {
58             insertWithTags $w "\n" {}
59             display-grs-line $w [lindex $e 4] [expr $i+1]
60         } else {
61             insertWithTags $w [lindex $e 4] {}
62             insertWithTags $w " ?\n" {}
63         }
64     }
65 }
66
67 # Procedure display-line {sno no w hflag}
68 #  sno    result set number (integer)
69 #  no     record position (integer)
70 #  w      text widget in which the record should be displayed.
71 #  hflag  header flag. If true a header showing the record position
72 #         should be displayed.
73 # This procedure attempts to display records in a line-per-line format.
74 proc display-line {sno no w hflag} {
75     global monoFlag
76     set type [z39.$sno type $no] 
77     if {$hflag} {
78         if {! $monoFlag} {
79             $w tag bind r$no <Any-Enter> \
80                 [list $w tag configure r$no -background gray80]
81             $w tag bind r$no <Any-Leave> \
82                 [list $w tag configure r$no -background {}]
83         } else {
84             $w tag bind r$no <Any-Enter> \
85                 [list $w tag configure r$no -background black -foreground white]
86             $w tag bind r$no <Any-Leave> \
87                 [list $w tag configure r$no -background {} -foreground {}]
88         }
89     } else {
90         $w delete 0.0 end
91     }
92     if {$hflag} {
93         set nostr [format "%5d " $no]
94         insertWithTags $w $nostr marc-small-head
95     }
96     if {$type == "DB"} {
97         set rtype [z39.$sno recordType $no]
98         if {$rtype == "SUTRS"} {
99             insertWithTags $w [join [z39.$sno getSutrs $no]]
100         } elseif {$rtype == "GRS-1"} {
101             display-grs-line $w [z39.$sno getGrs $no] 0
102         } else {
103             if {[catch {
104                 set title [lindex [z39.$sno getMarc $no field 245 * a] 0]
105                 set year  [lindex [z39.$sno getMarc $no field 260 * c] 0]
106                 insertWithTags $w "$title - " marc-text
107                 insertWithTags $w "$year\n" marc-it
108             }]} {
109                 insertWithTags $w "Unknown record type: $rtype\n" marc-id
110             }
111         }
112     } elseif {$type == "SD"} {
113         set err [lindex [z39.$sno diag $no] 1]
114         set add [lindex [z39.$sno diag $no] 2]
115         if {$add != {}} {
116             set add " :${add}"
117         }
118         insertWithTags $w "Error ${err}${add}\n" marc-id
119     } 
120 }