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