exec expect
-- "$0" ${1+"$@"}
# share an xterm with other users
# See xkibitz(1) man page for complete info.
# Author: Don Libes, NIST
puts
"return return to program"
puts
"where <display> is an X display name such as nist.gov or nist.gov:0.0"
puts
"and <tag> is a tag from the = command."
puts
"+ and - require whitespace before argument."
puts
{return command must be spelled out
("r", "e", "t", ...
).
}
# disable history processing - there seems to be some incestuous relationship
# between history and unknown in Tcl 8.0
puts
"$args: invalid command"
set pid2tty
([pid
]) "/dev/tty"
if {[info exists env
(DISPLAY
)]} {
set pid2display
([pid
]) $env(DISPLAY
)
set pid2display
([pid
]) ""
# small int allowing user to more easily identify display
# maxtag always points at highest in use
global ids pid2display pid2tag tag2pid maxtag pid2sid
if {![string match
*:* $display]} {
if {![info exists env
(XKIBITZ_XTERM_ARGS
)]} {
set env
(XKIBITZ_XTERM_ARGS
) ""
set dummy1
[open
/dev
/null
]
set dummy2
[open
/dev
/null
]
stty raw
-echo < $spawn_out(slave
,name
)
# Linux needs additional stty, sounds like a bug in its stty to me.
# raw should imply this stuff, no?
stty
-icrnl -icanon < $spawn_out(slave
,name
)
regexp
".*(.)(.)" $spawn_out(slave
,name
) dummy c1 c2
if {[string compare
$c1 "/"] == 0} {
# On Pyramid and AIX, ttynames such as /dev/pts/1
# requre suffix to be padded with a 0
set pid
[eval exec xterm \
-geometry [stty columns
]x
[stty rows
] \
-S$c1$c2$spawn_out(slave
,fd
) \
$env(XKIBITZ_XTERM_ARGS
) &]
# xterm first sends back window id, discard
set pid2display
($pid) $display
set tag2pid
($maxtag) $pid
set pid2tag
($pid) $maxtag
set pid2sid
($pid) $spawn_id
set pid2tty
($pid) $spawn_out(slave
,name
)
global pid2display tag2pid pid2tty
foreach tag
[lsort
-integer [array names tag2pid
]] {
puts
[format
"%3d [stty columns < $tty]x[stty rows < $tty] $pid2display($pid)" $tag]
global tag2pid pid2tag pid2display maxtag ids pid2sid
if {![info exists tag2pid
($tag)]} {
# close and remove spawn_id from list
set spawn_id
$pid2sid($pid)
set index
[lsearch
$ids $spawn_id]
set ids
[lreplace
$ids $index $index]
# lower maxtag if possible
while {![info exists tag2pid
($maxtag)]} {
unset pid2display
([pid
]) ;# avoid killing self
foreach pid
[array names pid2display
] {
catch
{exec kill -9 $pid}
stty rows
$r columns
$c < $app_tty
foreach pid
[array names pid2tty
] {
if {$pid == [pid
]} continue
stty rows
$r columns
$c < $pid2tty($pid)
set escape
\035 ;# control-right-bracket
set escape_printable
"^\]"
while {[llength
$argv]>0} {
set flag
[lindex
$argv 0]
set escape
[lindex
$argv 1]
set escape_printable
$escape
set argv
[lrange
$argv 2 end
]
set argv
[lrange
$argv 2 end
]
spawn
-noecho $env(SHELL
)
set app_tty
$spawn_out(slave
,name
)
puts
"Escape sequence is $escape_printable"
-input $user_spawn_id -reset $escape {
puts
"\nfor help enter: ? or h or help"
-input $prog eof
exit -output $user_spawn_id -output ids