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