simosh
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/local/bin/tcl
#
# Copyright (C) 1996-1998 by the Board of Trustees
# of Leland Stanford Junior University.
#
# This file is part of the SimOS distribution.
# See LICENSE file for terms of the license.
#
set simosfd 0
proc main {argc argv0 argv} {
global simosfd
set remoteMode 1
if {$argc == 3} {
if {[lindex $argv 0] == "-l"} {
set remoteMode 0
set machine [lindex $argv 1]
set port [lindex $argv 2]
} else {
puts "usage: $argv0 ?-l? machine port"
exit
}
} elseif {$argc == 2} {
set machine [lindex $argv 0]
set port [lindex $argv 1]
} else {
puts "usage: $argv0 ?-l? machine port"
exit
}
set simosfd [server_connect $machine $port]
if $remoteMode {
cmdloop "remote\# " "\# " sendcommand
} else {
cmdloop "simosh> " "> " eval
}
close $simosfd
}
proc remote {{command ""}} {
if {$command == ""} {
cmdloop "remote\# " "\# " sendcommand
} else {
sendcommand $command
}
}
proc sendcommand {command} {
global simosfd
server_send $simosfd [string length $command]
server_send -nonewline $simosfd $command
set len [gets $simosfd]
set result [read $simosfd $len]
return $result
}
proc cmdloop {prompt1 prompt2 evalcmd} {
set command ""
puts -nonewline $prompt1
while {[gets stdin line] != -1} {
if {$command != ""} {
set command "$command\n$line"
} else {
set command $line
}
if {[info complete $command]} {
if {$command == "exit"} {
return
}
catch {
$evalcmd $command
} result
if {$result != ""} {
puts $result
}
set command ""
puts -nonewline $prompt1
} else {
puts -nonewline $prompt2
}
}
}
main $argc $argv0 $argv