Explain now also finds Gils attributes.
[ir-tcl-moved-to-github.git] / client2 / formats / medium.tcl
1 #Procedure display-grs-medium {w r i}
2 #  w            text widget in which the record should be displayed
3 #  r            record
4 #  i            indent
5 #This procedure displaies the GRS-1 records in a medium sized format and 
6 #puts tags around the text in order to format the output.
7 proc display-grs-medium {w r i} {
8     global tagSet
9     
10         $w tag configure indent$i -lmargin1 [expr $i * 16] \
11                 -lmargin2 [expr $i * 16 + 8]
12     foreach e $r {
13         set start [$w index insert]
14         set ttype [lindex $e 0]
15         set tval [lindex $e 2]
16         if {$ttype == 3} {
17             insertWithTags $w "$tval per" marc-pref
18         } elseif {[info exists tagSet($ttype,$tval)]} {
19             insertWithTags $w "$tagSet($ttype,$tval) " marc-pref
20         } else {
21             insertWithTags $w "($ttype,$tval) " marc-tag
22         }
23         if {[lindex $e 3] == "string"} {
24             insertWithTags $w [lindex $e 4] marc-text
25             insertWithTags $w "\n"
26         } elseif {[lindex $e 3] == "subtree"} {
27             insertWithTags $w "\n"
28         } else {
29             insertWithTags $w [lindex $e 4] {}
30             insertWithTags $w " \n" {}
31         }
32                 $w tag add indent$i $start insert
33         if {[lindex $e 3] == "subtree"} {
34             display-grs-medium $w [lindex $e 4] [expr $i+1]
35         }
36     }
37 }
38
39 # Procedure display-medium {sno no w hflag}
40 #  sno    result set number (integer)
41 #  no     record position (integer)
42 #  w      text widget in which the record should be displayed
43 #  hflag  header flag. If true a header showing the record position
44 #         should be displayed.
45 # This procedure attempts to display records in a medium-sized format.
46 proc display-medium {sno no w hflag} {
47     if {$hflag} {
48         insertWithTags $w " $no " marc-head
49         insertWithTags $w "\n"
50     } else {
51         $w delete 0.0 end
52     }
53     set type [z39.$sno type $no]
54     if {$type == "SD"} {
55         set err [lindex [z39.$sno diag $no] 1]
56         set add [lindex [z39.$sno diag $no] 2]
57         if {$add != {}} {
58             set add " :${add}"
59         }
60         insertWithTags $w "Error ${err}${add}\n" marc-id
61         return
62     }
63     if {$type != "DB"} {
64         return
65     }
66     set rtype [z39.$sno recordType $no]
67     if {$rtype == "SUTRS"} {
68         insertWithTags $w [join [z39.$sno getSutrs $no]] {}
69         $w insert end "\n"
70         return
71     } 
72     if {$rtype == "GRS-1"} {
73         display-grs-medium $w [z39.$sno getGrs $no] 0
74         return
75     }
76     if {[catch {set i [z39.$sno getMarc $no field 245 * a]}]} {
77         insertWithTags $w "Unknown record type: $rtype\n" marc-id
78         return
79     }
80     if {[llength $i]} {
81         insertWithTags $w "Title " marc-pref
82         insertWithTags $w [string trimright [lindex $i 0] /] marc-text
83         set i [concat [z39.$sno getMarc $no field 245 * b] [z39.$sno getMarc $no field 251 * a]]
84         if {"x$i" != "x"} {
85             insertWithTags $w [string trimright [lindex $i 0] /] marc-text
86         }
87         $w insert end "\n"
88     }
89     set i [concat [z39.$sno getMarc $no field 700 * a] [z39.$sno getMarc $no field 700 * h]]
90     if {![llength $i]} {
91         set i [concat [z39.$sno getMarc $no field 100 * a] [z39.$sno getMarc $no field 100 * h]]
92     }
93     if {[llength $i]} {
94         if {[llength $i] > 1} {
95             insertWithTags $w "Authors " marc-pref
96         } else {
97             insertWithTags $w "Author " marc-pref
98         }
99         foreach x $i {
100             insertWithTags $w $x marc-it
101         }
102         $w insert end "\n"
103     }
104     set i [z39.$sno getMarc $no field 110 * *]
105     if {[llength $i]} {
106         insertWithTags $w "Co-Author " marc-pref
107         foreach x $i {
108             insertWithTags $w $x marc-text
109         }
110         $w insert end "\n"
111     }
112
113     set i [z39.$sno getMarc $no field 650 * *]
114     if {[llength $i]} {
115         set n 0
116         insertWithTags $w "Keywords " marc-pref
117         foreach x $i {
118             if {$n > 0} {
119 #                $w insert end ", "
120             }
121             insertWithTags $w $x marc-it
122             incr n
123         }
124         $w insert end "\n"
125     }
126     set i [concat [z39.$sno getMarc $no field 260 * b] [z39.$sno getMarc $no field 260 * a]]
127     if {[llength $i]} {
128         insertWithTags $w "Publisher " marc-pref
129         foreach x $i {
130             insertWithTags $w $x marc-text
131         }
132         $w insert end "\n"
133     }
134     set i [z39.$sno getMarc $no field 260 * c]
135     if {[llength $i]} {
136         insertWithTags $w "Year " marc-pref
137         foreach x $i {
138             insertWithTags $w $x marc-text
139         }
140         $w insert end "\n"
141     }
142     set i [concat [z39.$sno getMarc $no field 300 * a] [z39.$sno getMarc $no field 300 * b] \
143         [z39.$sno getMarc $no field 300 * c] [z39.$sno getMarc $no field 300 * e]]
144     if {[llength $i]} {
145         insertWithTags $w "Phys. Desc. " marc-pref
146         foreach x $i {
147             insertWithTags $w $x marc-text
148         }
149         $w insert end "\n"
150     }
151     set i [z39.$sno getMarc $no field 020 * a]
152     if {[llength $i]} {
153         insertWithTags $w "ISBN " marc-pref
154         foreach x $i {
155             insertWithTags $w $x marc-text
156         }
157         $w insert end "\n"
158     }
159     set i [z39.$sno getMarc $no field 021 * a]
160     if {[llength $i]} {
161         insertWithTags $w "ISBN " marc-pref
162         foreach x $i {
163             insertWithTags $w $x marc-text
164         }
165         $w insert end "\n"
166     }
167     set i [z39.$sno getMarc $no field 022 * a]
168     if {[llength $i]} {
169         insertWithTags $w "ISSN " marc-pref
170         foreach x $i {
171             insertWithTags $w $x marc-text
172         }
173         $w insert end "\n"
174     }
175     set i [z39.$sno getMarc $no field 030 * a]
176     if {[llength $i]} {
177         insertWithTags $w "CODEN " 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 015 * a]
184     if {[llength $i]} {
185         insertWithTags $w "Ctl number " 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 010 * a]
192     if {[llength $i]} {
193         insertWithTags $w "LC number " 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 710 * a]
200     if {[llength $i]} {
201         insertWithTags $w "Corporate name " marc-pref
202         foreach x $i {
203             insertWithTags $w $x marc-text
204         }
205         $w insert end "\n"
206     }
207 }