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