Removed lines and list as synonyms of list in MARC extractron.
[ir-tcl-moved-to-github.git] / shell.tcl
1 # $Id: shell.tcl,v 1.2 1995-08-28 12:21:22 adam Exp $
2 #
3 source display.tcl
4
5 ir z
6
7 proc help {} {
8     puts "Commands:"
9     puts " target <host> <database>"
10     puts " find <query>"
11     puts " show <offset> <number>"
12     puts ""
13 }
14
15 proc target {name database} {
16     z disconnect
17     z failback {puts "Connection failed"}
18     z callback {connect-response}
19     z databaseNames $database
20     z connect $name
21     return {}
22 }
23
24 proc connect-response {} {
25     z callback {init-response}
26     z init
27 }
28
29 proc init-response {} {
30     puts "Connect and initialized."
31 }
32
33 proc find-response {z} {
34     set sstatus [$z searchStatus]
35     if {$sstatus} {
36         set h [$z resultCount]
37         puts "Search ok. $h hits"
38     } else {
39         puts "Search failed"
40     }
41     common-response $z 1
42 }
43
44 proc common-response {z from} {
45     set status [lindex [$z responseStatus] 0]
46     switch $status {
47     NSD { 
48             puts -nonewline "NSD"
49             puts -nonewline [lindex [$z responseStatus] 1]
50             puts -nonewline " "
51             puts -nonewline [lindex [$z responseStatus] 2]
52             puts -nonewline ": "
53             puts -nonewline [lindex [$z responseStatus] 3]
54             puts ""
55         }
56     DBOSD {
57             puts "DBOSD"
58             for {set i $from} {$i < [$z nextResultSetPosition]} {incr i} {
59                 if {[$z type $i] == ""} {
60                     break
61                 }
62                 puts "\# $i"
63                 display $z $i
64             }
65         }
66     }
67 }
68
69 proc show {from number} {
70     z callback "common-response z.1 $from"
71     z.1 present $from $number
72 }
73     
74 proc find {query} {
75     ir-set z.1 z
76     z failback {puts "Connection closed"}
77     z callback {find-response z.1}
78     z.1 search $query
79 }
80