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