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