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