; DEBUG multiplexer
;
; Changes to normal /debug behaviour:
;
; 1. Initiating a new /debug does not end the previous debug command.
; Messages will still be sent to the old window or file.
; 2. To stop a debug logger, type /debug off <window | filename>
; Use /debug -i off <window | filename> <identifier> to stop a prior /debug -i call.
; 3. You can use ON *:SIGNAL:DEBUG: { ... } to watch for a debugging message.
alias debug {
if ($1- == -i nul debug_multiplex) { .debug $1- | return }
var %opts = ""
if (-* iswm $1) { %opts = $1 | tokenize 32 $2- }
if ($1 == off) {
set %debug_outputs. $+ $cid $remtok(%debug_outputs. [ $+ [ $cid ] ],$iif($2,$2,debug.log),0,32)
if (i isin %opts) {
set %debug_identifiers. $+ $cid $remtok(%debug_identifiers. [ $+ [ $cid ] ],$3,0,32)
}
}
else {
var %output = $iif($1 == on,debug.log,$1)
if (@* iswm %output) window $iif(n isin %opts,-n,) %output
set %debug_outputs. $+ $cid $addtok(%debug_outputs. [ $+ [ $cid ] ],%output,32)
if (i isin %opts) {
set %debug_identifiers. $+ $cid $addtok(%debug_identifiers. [ $+ [ $cid ] ],$2,32)
}
}
}
alias debug_multiplex { .signal -n DEBUG $1- | return $1- }
ON *:CONNECT:.debug -i nul debug_multiplex
on *:EXIT:unset %debug_outputs.* | unset %debug_identifiers.*
on *:SIGNAL:DEBUG: {
var %i = 1
while ($gettok(%debug_outputs. [ $+ [ $cid ] ],%i,32)) {
var %output = $v1
if (%output != nul) $iif(@* iswm %output,echo,write) %output $1-
inc %i
}
var %i = 1
while ($gettok(%debug_identifiers. [ $+ [ $cid ] ],%i,32)) {
var %name = $v1
if ($isalias(%name)) %name
inc %i
}
}