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