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