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