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