Allow YAZ 2 series only
[ir-tcl-moved-to-github.git] / formats / line.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: line.tcl,v $
7 # Revision 1.15  1997-11-24 11:34:38  adam
8 # Using odr_nullval() instead of ODR_NULLVAL when appropriate.
9 #
10 # Revision 1.14  1997/11/19 11:22:10  adam
11 # Object identifiers can be accessed in GRS-1 records.
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:21  adam
21 # Wrore more comments.
22 #
23 # Revision 1.10  1995/10/17  17:39:46  adam
24 # Minor bug fix in call to display-grs-line.
25 #
26 # Revision 1.9  1995/10/17  14:18:09  adam
27 # Minor changes in presentation formats.
28 #
29 # Revision 1.8  1995/10/17  10:58:08  adam
30 # More work on presentation formats.
31 #
32 # Revision 1.7  1995/09/20  11:37:06  adam
33 # Work on GRS.
34 #
35 # Revision 1.6  1995/06/29  12:34:20  adam
36 # IrTcl now works with both tk4.0b4/tcl7.4b4 and tk3.6/tcl7.3
37 #
38 # Revision 1.5  1995/06/22  13:16:28  adam
39 # Feature: SUTRS. Setting getSutrs implemented.
40 # Work on display formats.
41 #
42 # Revision 1.4  1995/06/19  08:10:21  adam
43 # Inverse highligt colours in monochrome mode.
44 #
45 # Revision 1.3  1995/06/16  12:29:00  adam
46 # Use insertWithTags on diagnostic errors.
47 #
48 # Revision 1.2  1995/06/13  14:39:06  adam
49 # Fix: if {$var != ""} doesn't work if var is a large numerical!
50 # Highlight when line format is used.
51 #
52 # Revision 1.1  1995/06/12  15:18:10  adam
53 # Work on presentation formats. These are used in the main window as well
54 # as popup windows.
55 #
56 #
57 proc display-grs-line {w r i} {
58     global tagSet
59     
60     if {[tk4]} {
61         set start [$w index insert]
62     }
63     set head Untitled
64     foreach e $r {
65         if {![tk4]} {
66             for {set j 0} {$j < $i} {incr j} {
67                 insertWithTags $w "  " marc-tag
68             }
69         }
70         set ttype [lindex $e 0]
71         set tval [lindex $e 2]
72         if {$ttype == 2 && $tval == 1} {
73             if {[lindex $e 3] == "subtree"} {
74                 set f [lindex $e 4]
75                 foreach e $f {
76                     if {[lindex $e 0] == 1 && [lindex $e 2] == 19} {
77                         break
78                     }
79                 }
80             }
81             if {[lindex $e 3] == "string"} {
82                 set head [lindex $e 4]
83             }
84             break
85         }
86     }
87     insertWithTags $w $head marc-text
88     insertWithTags $w "\n"
89     if {[tk4]} {
90         $w tag configure indent$i \
91                 -lmargin1 [expr $i * 10] \
92                 -lmargin2 [expr $i * 10 + 5]
93         $w tag add indent$i $start insert
94     }
95 }
96
97 # Procedure display-line {sno no w hflag}
98 #  sno    result set number (integer)
99 #  no     record position (integer)
100 #  w      text widget in which the record should be displayed.
101 #  hflag  header flag. If true a header showing the record position
102 #         should be displayed.
103 # This procedure attempts to display records in a line-per-line format.
104 proc display-line {sno no w hflag} {
105     global monoFlag
106     set type [z39.$sno type $no] 
107     if {$hflag} {
108         if {! $monoFlag} {
109             $w tag bind r$no <Any-Enter> \
110                 [list $w tag configure r$no -background gray80]
111             $w tag bind r$no <Any-Leave> \
112                 [list $w tag configure r$no -background {}]
113         } else {
114             $w tag bind r$no <Any-Enter> \
115                 [list $w tag configure r$no -background black -foreground white]
116             $w tag bind r$no <Any-Leave> \
117                 [list $w tag configure r$no -background {} -foreground {}]
118         }
119     } else {
120         $w delete 0.0 end
121     }
122     if {$hflag} {
123         set nostr [format "%5d " $no]
124         insertWithTags $w $nostr marc-small-head
125     }
126     if {$type == "DB"} {
127         set rtype [z39.$sno recordType $no]
128         if {$rtype == "SUTRS"} {
129             insertWithTags $w [join [z39.$sno getSutrs $no]]
130         } elseif {$rtype == "GRS-1"} {
131             display-grs-line $w [z39.$sno getGrs $no] 0
132         } else {
133             if {[catch {
134                 set title [lindex [z39.$sno getMarc $no field 245 * a] 0]
135                 set year  [lindex [z39.$sno getMarc $no field 260 * c] 0]
136                 insertWithTags $w "$title - " marc-text
137                 insertWithTags $w "$year\n" marc-it
138             }]} {
139                 insertWithTags $w "Unknown record type: $rtype\n" marc-id
140             }
141         }
142     } elseif {$type == "SD"} {
143         set err [lindex [z39.$sno diag $no] 1]
144         set add [lindex [z39.$sno diag $no] 2]
145         if {$add != {}} {
146             set add " :${add}"
147         }
148         insertWithTags $w "Error ${err}${add}\n" marc-id
149     } 
150 }