New client with better Explain support and nice icons.
[ir-tcl-moved-to-github.git] / client2 / formats / raw.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: raw.tcl,v $
7 # Revision 1.1  1998-09-30 10:53:54  perhans
8 # New client with better Explain support and nice icons.
9 #
10 # Revision 1.13  1997/11/19 11:22:10  adam
11 # Object identifiers can be accessed in GRS-1 records.
12 #
13 # Revision 1.12  1996/04/12 13:45:50  adam
14 # Minor changes.
15 #
16 # Revision 1.11  1996/03/29  16:05:37  adam
17 # Bug fix: GRS records wasn't recognized.
18 #
19 # Revision 1.10  1996/01/23  15:24:24  adam
20 # Wrore more comments.
21 #
22 # Revision 1.9  1995/10/17  14:18:10  adam
23 # Minor changes in presentation formats.
24 #
25 # Revision 1.8  1995/10/17  10:58:09  adam
26 # More work on presentation formats.
27 #
28 # Revision 1.7  1995/10/12  14:46:58  adam
29 # The record position in the raw format is much more visible.
30 #
31 # Revision 1.6  1995/09/20  11:37:07  adam
32 # Work on GRS.
33 #
34 # Revision 1.5  1995/08/28  12:22:09  adam
35 # Use 'line' instead of 'list' in MARC extraction.
36 #
37 # Revision 1.4  1995/06/22  13:16:29  adam
38 # Feature: SUTRS. Setting getSutrs implemented.
39 # Work on display formats.
40 #
41 # Revision 1.3  1995/06/14  12:16:42  adam
42 # Minor presentation format changes.
43 #
44 # Revision 1.2  1995/06/12  15:18:10  adam
45 # Work on presentation formats. These are used in the main window as well
46 # as popup windows.
47 #
48 #
49 proc display-grs-raw {w r i} {
50     foreach e $r {
51         for {set j 0} {$j < $i} {incr j} {
52             insertWithTags $w "  " {}
53         }
54         insertWithTags $w "([lindex $e 0],[lindex $e 2])" marc-tag
55         if {[lindex $e 3] == "string"} {
56             insertWithTags $w [lindex $e 4] {}
57             insertWithTags $w "\n" {}
58         } elseif {[lindex $e 3] == "subtree"} {
59             insertWithTags $w "\n" {}
60             display-grs-raw $w [lindex $e 4] [expr $i+1]
61         } else {
62             insertWithTags $w [lindex $e 4] {}
63             insertWithTags $w "\n" {}
64         }
65     }
66 }
67
68 # Procedure display-raw {sno no w flag}
69 #  sno    result set number (integer)
70 #  no     record position (integer)
71 #  w      text widget in which the record should be displayed.
72 #  hflag  header flag. If true a header showing the record position
73 #         should be displayed.
74 # This procedure attempts to display records in a raw format.
75 proc display-raw {sno no w hflag} {
76     if {$hflag} {
77         insertWithTags $w " $no " marc-head
78         insertWithTags $w "\n"
79     } else {
80         $w delete 0.0 end
81     }
82     set type [z39.$sno type $no]
83     if {$type == "SD"} {
84         set err [lindex [z39.$sno diag $no] 1]
85         set add [lindex [z39.$sno diag $no] 2]
86         if {$add != {}} {
87             set add " :${add}"
88         }
89         insertWithTags $w "Error ${err}${add}\n" marc-id
90         return
91     }
92     if {$type != "DB"} {
93         return
94     }
95     set rtype [z39.$sno recordType $no]
96     if {$rtype == "SUTRS"} {
97         insertWithTags $w [join [z39.$sno getSutrs $no]] {}
98         $w insert end "\n"
99         return
100     } 
101     if {$rtype == "GRS-1"} {
102         display-grs-raw $w [z39.$sno getGrs $no] 0
103         return
104     }
105     if {[catch {set r [z39.$sno getMarc $no line * * *]}]} {
106         insertWithTags $w "Unknown record type: $rtype\n" marc-id
107         return
108     }
109     foreach line $r {
110         set tag [lindex $line 0]
111         set indicator [lindex $line 1]
112         set fields [lindex $line 2]
113         
114         if {$indicator != ""} {
115             insertWithTags $w "$tag $indicator" marc-tag
116         } else {
117             insertWithTags $w "$tag    " marc-tag
118         }
119         foreach field $fields {
120             set id [lindex $field 0]
121             set data [lindex $field 1]
122             if {$id != ""} {
123                 insertWithTags $w " $id " marc-id
124             }
125             insertWithTags $w $data {}
126         }
127         $w insert end "\n"
128     }
129 }
130