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