New client with better Explain support and nice icons.
[ir-tcl-moved-to-github.git] / client2 / formats / medium.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: medium.tcl,v $
7 # Revision 1.1  1998-09-30 10:53:54  perhans
8 # New client with better Explain support and nice icons.
9 #
10 # Revision 1.15  1997/11/19 11:22:10  adam
11 # Object identifiers can be accessed in GRS-1 records.
12 #
13 # Revision 1.14  1996/04/12 13:45:49  adam
14 # Minor changes.
15 #
16 # Revision 1.13  1996/04/12  12:25:27  adam
17 # Modified display of GRS-1 records to include headings for standard
18 # tag sets.
19 #
20 # Revision 1.12  1996/03/29  16:05:36  adam
21 # Bug fix: GRS records wasn't recognized.
22 #
23 # Revision 1.11  1996/01/23  15:24:23  adam
24 # Wrore more comments.
25 #
26 # Revision 1.10  1996/01/11  09:31:05  quinn
27 # Small.
28 #
29 # Revision 1.9  1995/10/17  14:18:10  adam
30 # Minor changes in presentation formats.
31 #
32 # Revision 1.8  1995/10/17  10:58:09  adam
33 # More work on presentation formats.
34 #
35 # Revision 1.7  1995/10/16  17:01:03  adam
36 # Medium presentation format looks better.
37 #
38 # Revision 1.6  1995/09/20  11:37:06  adam
39 # Work on GRS.
40 #
41 # Revision 1.5  1995/06/22  13:16:29  adam
42 # Feature: SUTRS. Setting getSutrs implemented.
43 # Work on display formats.
44 #
45 # Revision 1.4  1995/06/14  12:16:42  adam
46 # Minor presentation format changes.
47 #
48 # Revision 1.3  1995/06/13  14:39:06  adam
49 # Fix: if {$var != ""} doesn't work if var is a large numerical!
50 # Highlight when line format is used.
51 #
52 # Revision 1.2  1995/06/12  15:18:10  adam
53 # Work on presentation formats. These are used in the main window as well
54 # as popup windows.
55 #
56 #
57 proc display-grs-medium {w r i} {
58     global tagSet
59     
60     foreach e $r {
61         if {[tk4]} {
62             set start [$w index insert]
63         } else {
64             for {set j 0} {$j < $i} {incr j} {
65                 insertWithTags $w "  " marc-tag
66             }
67         }
68         set ttype [lindex $e 0]
69         set tval [lindex $e 2]
70         if {$ttype == 3} {
71             insertWithTags $w "$tval " marc-pref
72         } elseif {[info exists tagSet($ttype,$tval)]} {
73             insertWithTags $w "$tagSet($ttype,$tval) " marc-pref
74         } else {
75             insertWithTags $w "($ttype,$tval) " marc-tag
76         }
77         if {[lindex $e 3] == "string"} {
78             insertWithTags $w [lindex $e 4] marc-text
79             insertWithTags $w "\n"
80         } elseif {[lindex $e 3] == "subtree"} {
81             insertWithTags $w "\n"
82         } else {
83             insertWithTags $w [lindex $e 4] {}
84             insertWithTags $w " \n" {}
85         }
86         if {[tk4]} {
87             $w tag configure indent$i \
88                     -lmargin1 [expr $i * 16] \
89                     -lmargin2 [expr $i * 16 + 8]
90             $w tag add indent$i $start insert
91         }
92         if {[lindex $e 3] == "subtree"} {
93             display-grs-medium $w [lindex $e 4] [expr $i+1]
94         }
95     }
96 }
97
98 # Procedure display-medium {sno no w hflag}
99 #  sno    result set number (integer)
100 #  no     record position (integer)
101 #  w      text widget in which the record should be displayed
102 #  hflag  header flag. If true a header showing the record position
103 #         should be displayed.
104 # This procedure attempts to display records in a medium-sized format.
105 proc display-medium {sno no w hflag} {
106     if {$hflag} {
107         insertWithTags $w " $no " marc-head
108         insertWithTags $w "\n"
109     } else {
110         $w delete 0.0 end
111     }
112     set type [z39.$sno type $no]
113     if {$type == "SD"} {
114         set err [lindex [z39.$sno diag $no] 1]
115         set add [lindex [z39.$sno diag $no] 2]
116         if {$add != {}} {
117             set add " :${add}"
118         }
119         insertWithTags $w "Error ${err}${add}\n" marc-id
120         return
121     }
122     if {$type != "DB"} {
123         return
124     }
125     set rtype [z39.$sno recordType $no]
126     if {$rtype == "SUTRS"} {
127         insertWithTags $w [join [z39.$sno getSutrs $no]] {}
128         $w insert end "\n"
129         return
130     } 
131     if {$rtype == "GRS-1"} {
132         display-grs-medium $w [z39.$sno getGrs $no] 0
133         return
134     }
135     if {[catch {set i [z39.$sno getMarc $no field 245 * a]}]} {
136         insertWithTags $w "Unknown record type: $rtype\n" marc-id
137         return
138     }
139     if {[llength $i]} {
140         insertWithTags $w "Title " marc-pref
141         insertWithTags $w [string trimright [lindex $i 0] /] marc-text
142         set i [z39.$sno getMarc $no field 245 * b]
143         if {"x$i" != "x"} {
144             insertWithTags $w [string trimright [lindex $i 0] /] marc-text
145         }
146         $w insert end "\n"
147     }
148     set i [z39.$sno getMarc $no field 700 * a]
149     if {![llength $i]} {
150         set i [z39.$sno getMarc $no field 100 * a]
151     }
152     if {[llength $i]} {
153         if {[llength $i] > 1} {
154             insertWithTags $w "Authors " marc-pref
155         } else {
156             insertWithTags $w "Author " marc-pref
157         }
158         foreach x $i {
159             insertWithTags $w $x marc-it
160         }
161         $w insert end "\n"
162     }
163     set i [z39.$sno getMarc $no field 110 * *]
164     if {[llength $i]} {
165         insertWithTags $w "Co-Author " marc-pref
166         foreach x $i {
167             insertWithTags $w $x marc-text
168         }
169         $w insert end "\n"
170     }
171
172     set i [z39.$sno getMarc $no field 650 * *]
173     if {[llength $i]} {
174         set n 0
175         insertWithTags $w "Keywords " marc-pref
176         foreach x $i {
177             if {$n > 0} {
178                 $w insert end ", "
179             }
180             insertWithTags $w $x marc-it
181             incr n
182         }
183         $w insert end "\n"
184     }
185     set i [concat [z39.$sno getMarc $no field 260 * a] \
186             [z39.$sno getMarc $no field 260 * b]]
187     if {[llength $i]} {
188         insertWithTags $w "Publisher " marc-pref
189         foreach x $i {
190             insertWithTags $w $x marc-text
191         }
192         $w insert end "\n"
193     }
194     set i [z39.$sno getMarc $no field 020 * a]
195     if {[llength $i]} {
196         insertWithTags $w "ISBN " marc-pref
197         foreach x $i {
198             insertWithTags $w $x marc-text
199         }
200         $w insert end "\n"
201     }
202     set i [z39.$sno getMarc $no field 022 * a]
203     if {[llength $i]} {
204         insertWithTags $w "ISSN " marc-pref
205         foreach x $i {
206             insertWithTags $w $x marc-text
207         }
208         $w insert end "\n"
209     }
210     set i [z39.$sno getMarc $no field 030 * a]
211     if {[llength $i]} {
212         insertWithTags $w "CODEN " marc-pref
213         foreach x $i {
214             insertWithTags $w $x marc-text
215         }
216         $w insert end "\n"
217     }
218     set i [z39.$sno getMarc $no field 015 * a]
219     if {[llength $i]} {
220         insertWithTags $w "Ctl number " marc-pref
221         foreach x $i {
222             insertWithTags $w $x marc-text
223         }
224         $w insert end "\n"
225     }
226     set i [z39.$sno getMarc $no field 010 * a]
227     if {[llength $i]} {
228         insertWithTags $w "LC number " marc-pref
229         foreach x $i {
230             insertWithTags $w $x marc-text
231         }
232         $w insert end "\n"
233     }
234     set i [z39.$sno getMarc $no field 710 * a]
235     if {[llength $i]} {
236         insertWithTags $w "Corporate name " marc-pref
237         foreach x $i {
238             insertWithTags $w $x marc-text
239         }
240         $w insert end "\n"
241     }
242 }