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