#! /opt/SUNWssp/release/Ultra-Enterprise-10000/2/5/1/bin/ssptk -f
#
# ident	"@(#)hvChildHead.tcl	1.5	96/10/14 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#	General Main to service commands as a separate process
#	This file is exec-ed from hostview with flags.
#	The flags determine which proc will be run by this new process.
#
#	exec ${gHV_HOME}/execTextPopup $cmdArg $domainName &
#	called by: genTextExec { cmdArg }
#	menuBar:	    -command "genTextExec sspLog" -underline 0
#
# notes:
#
# domain info is on the hostview side 
# this is a separate process

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)blklistGraphic.tcl	1.12	97/02/20 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   This file supports the blacklist GUI canvas.  Place everything on the canvas
#   to establish path names and geometry.  Most objects will be invisible.
#   Subsequent routines can make objects visible by changing colors.
#
# Main Routine:
#   proc blklistGraphic {bg1 fg1}
# 
# System Board Decoration:
#   proc BLdecorateSys {parent bg1 fg1 bg2 fg2}
#
# proc BLsytleProcPath { procpath }
# proc blProcPath { cell }
# proc blvisibleSys {target bg1 fg1}
#
# Create Front of Cabinet:
#   proc BLfrontTemplate {parent bg1 fg1 bg2 fg2}
#
# Create Back of Cabinet:
#   proc BLbackTemplate {parent bg1 fg1 bg2 fg2}
#
# Create Center Plane:
#   proc BLbussTemplate {parent bg1 fg1}
#
# proc blklistGraphic {viewFlag bg1 fg1}
#
# proc blklistDetails { }
#
proc BLsytleProcPath { procpath } {

    set base blklistGraphic

    # proc path is for the main canvas
    # alter it for the blacklist canvas
    set newtemp [lreplace [split dummy$procpath .] 1 1 $base]
    set newtemp2 ""
    foreach elem $newtemp {
	if { [string compare $elem "dummy"] != 0 } {
	    set newtemp2 [join "${newtemp2}. $elem" ""]
	}
    }
    set procpath $newtemp2
    return $procpath
}
#
# Processor rectangles need icons and labels.  
# These need to be present, visible or not so packer knows what to do.
#
# bg1 = default background color
# fg1 = text color
# bg2 = diag backround color
# fg2 = diag foreground color
#
proc BLdecorateSys {parent bg1 fg1 bg2 fg2} {
    debug 1 "decorateSys:$parent"

    #set parent [string trim $parent bl_]
    set cells [procList $parent]

    set base blklistGraphic
    #set base blklistGraphic.box
    #set base [lindex 0 [split $parent .]]

    foreach cell $cells {
	#set temp1 [procPath $cell]

	# proc path is for the main canvas
	# alter it for the blacklist canvas
	
	set temp1 [ BLsytleProcPath [procPath $cell] ]

	if { 0 } {
	    set newtemp [lreplace [split dummy$temp1 .] 1 1 $base]
	    set newtemp2 ""
	    foreach elem $newtemp {
		if { [string compare $elem "dummy"] != 0 } {
		    set newtemp2 [join "${newtemp2}. $elem" ""]
		}
	    }
	    set temp1 $newtemp2
	}

	frame $temp1 -bg $bg1

	#
	# Make invisible, but I need the text for spacing
	#



	# this is for the board view
	if { 0 } {
	    label $temp1.id -text $cell -bg white -foreground white
	    label $temp1.icon -image dummy -bg white -highlightbackground white

	    #label $temp1.id -text $cell -bg $bg1 -foreground $bg1
	    #label $temp1.icon -image dummy -bg $bg1 -highlightbackground $bg1
	    ####label $temp1.id -text $cell -bg $bg1 -foreground $fg2
	    ####label $temp1.icon -image dummy -bg $fg2 -highlightbackground $bg1
	}

	##junk

	if { 0 } {
	#label $temp1.id -text $cell -bg white -foreground white
	    #label $temp1.icon -image dummy -bg white -highlightbackground white

	    label $temp1.id -text $cell -bg $bg1 -foreground $fg1
	    label $temp1.icon -image dummy -bg white -highlightbackground $bg1
	    ####label $temp1.id -text $cell -bg $bg1 -foreground $fg2
	    ####label $temp1.icon -image dummy -bg $fg2 -highlightbackground $bg1

	pack $temp1 -side top
	pack $temp1.id $temp1.icon -side left
	}



	# good!!! for proc view
	label $temp1.id -text $cell -bg $bg2 -foreground $fg2 -pady 5
	#label $temp1.id -text $cell -bg $bg1 -foreground $fg1 -pady 5
        frame $temp1.icon -bg $bg2 -bd 4
        #frame $temp1.icon -bg $bg1 -bd 4
            label $temp1.icon.icon -image dummy -bg white -highlightbackground $bg1
            #label $temp1.icon -image dummy -bg white -highlightbackground $bg1


            ####label $temp1.id -text $cell -bg $bg1 -foreground $fg2
            ####label $temp1.icon -image dummy -bg $fg2 -highlightbackground $bg1

        pack $temp1 -side top
        pack $temp1.id $temp1.icon $temp1.icon.icon -side left
        #pack $temp1.id $temp1.icon -side left
	#debug 1 "packing $temp1.id $temp1.icon $temp1.icon.icon "
    }
}

proc blProcPath { cell } {

    set base blklistGraphic
    #set base blklistGraphic.box
    set temp1 [procPath $cell]

    # proc path is for the main canvas
    # alter it for the blacklist canvas
    set newtemp [lreplace [split dummy$temp1 .] 1 1 $base]
    set newtemp2 ""
    foreach elem $newtemp {
	if { [string compare $elem "dummy"] != 0 } {
	    set newtemp2 [join "${newtemp2}. $elem" ""]
	}
    }

    return $newtemp2
}
#
# Make a system board visible.  Establish bindings.
# target = b0..b15
#
proc blvisibleSys {target viewFlag bg1 fg1} {
    debug 1 "blvisibleSys:$target"
    
    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    $winboard configure -bg $bg1 -relief flat
    $winboard.board configure -bg cyan4 -relief ridge
    #$winboard.board configure -bg purple -relief raised

    #
    # If this board has a domain affiliation, color it in.
    #

    set target [string trim $target bl_]
    

    set cells [procList $target]

    foreach cell $cells {

	set temp1 [blProcPath $cell]
	if { 0 } {
	    set temp1 [procPath $cell]
	    $temp1.id configure -fg $fg1
	    $temp1.id configure -fg $fg1

	    set cell_temp [whatProcState $cell]
	    set cell_state [lindex $cell_temp 0]
	    set symbol [getImage $cell_state]
	    set cell_color [iconRunColor [lindex $cell_temp 1]]
	
	    $temp1.icon configure -image $symbol -bg $cell_color

	    pack $temp1.id 	$temp1.icon -side left
	}

	# use the same bindings as the main window,
	# this will work because blacklist is a child.

	#bind $temp1      <Button-2> {boardSelect %W}
	#bind $temp1
	#Error: no event type or button # or keysym
	#bind $temp1      <Shift><Button-1> {boardSelect %W}

	if { [string compare $viewFlag "boardView"] == 0 } {
	    bind $temp1      <Button-1> {blboardSelect %W}
	    bind $temp1.id   <Button-1> {blboardSelect %W}
	    bind $temp1.icon <Button-1> {blboardSelect %W}
	    bind $temp1.icon.icon <Button-1> {blboardSelect %W}

	    bind $temp1	<Button-2> {blboardSelectTog %W}
	    bind $temp1.id	<Button-2> {blboardSelectTog %W}
	    bind $temp1.icon	<Button-2> {blboardSelectTog %W}
	    bind $temp1.icon.icon	<Button-2> {blboardSelectTog %W}
	} else {
	    bind $temp1.icon.icon <Button-1> {blprocSelect %W}
	    bind $temp1.icon.icon	<Button-2> {blprocSelectTog %W}
	}
	
	#bind $temp1      <Button-3> {detailPopup %W}
	#bind $temp1.id   <Button-3> {detailPopup %W}
	#bind $temp1.icon <Button-3> {detailPopup %W}
    }
}



#
# bg1 = default background color
# fg1 = text color
# bg2 = diag backround color
# fg2 = diag foreground color
#
proc BLfrontTemplate {parent bg1 fg1 bg2 fg2} {
    global gFrontBoards

    debug 1 "BLfrontTemplate:$parent"

    foreach slot $gFrontBoards {
	frame $parent.$slot -bg $bg1
	if {[string first csb $slot] >= 0} {
	    continue
	    if { 0 } {
		set csb [ string trimleft $slot csb]
		label $parent.$slot.id -text "CSB $csb" -bg $bg1
	    }
	} elseif {[string first cb $slot] >= 0} {
	    continue
	    set cb [ string trimleft $slot cb]
	    label $parent.$slot.id -text "CB $cb" -bg $bg1
	} else {
	    label $parent.$slot.id -text "SB $slot" -bg $bg1
	}


	pack $parent.$slot -side left -fill both -expand yes
	pack $parent.$slot.id -side bottom

	frame $parent.$slot.select -relief flat -borderwidth 4 -bg $bg1
	pack  $parent.$slot.select -padx 1m -side top

	frame $parent.$slot.select.domain -relief flat -borderwidth 4 -bg $bg2
	pack  $parent.$slot.select.domain -side bottom

	set winboard $parent.$slot.select.domain.board

	frame $winboard -relief flat -borderwidth 4 -bg $bg1
	pack  $winboard

	switch $slot {
	    Xcsb0 {decorateSB $winboard $slot $bg1 $fg1 $bg2 $fg2 }
	    cb0 {decorateCB $winboard $slot $bg1 $fg1 $bg2 $fg2 }
	    0  {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    1  {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    2  {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    3  {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    4  {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    5  {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    6  {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    7  {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	}
    }
}

#
# bg1 = default background color
# fg1 = text color
# bg2 = diag backround color
# fg2 = diag foreground color
#
proc BLbackTemplate {parent bg1 fg1 bg2 fg2} {
    global gBackBoards

    debug 1 "BLbackTemplate:$parent"

    foreach slot $gBackBoards {
	
	frame $parent.$slot -bg $bg1
	
	if {[string first csb $slot] >= 0} {
	    continue
	    if { 0 } {
		set csb [ string trimleft $slot csb]
		label $parent.$slot.id -text "CSB $csb" -bg $bg1
	    }
	} elseif {[string first cb $slot] >= 0} {
	    continue
	    set cb [ string trimleft $slot cb]
	    label $parent.$slot.id -text "CB $cb" -bg $bg1
	} else {
	    label $parent.$slot.id -text "SB $slot" -bg $bg1
	}

	pack $parent.$slot -side left -fill both -expand yes
	pack $parent.$slot.id -side top

	frame $parent.$slot.select -relief flat -borderwidth 4 -bg $bg1
	pack  $parent.$slot.select -padx 1m -side bottom

	frame $parent.$slot.select.domain -relief flat -borderwidth 4 -bg $bg2
	pack  $parent.$slot.select.domain -side bottom

	set winboard $parent.$slot.select.domain.board

	frame $winboard -relief flat -borderwidth 4 -bg $bg1
	pack  $winboard

	switch $slot {
	    csb1 {decorateSB $winboard $slot $bg1 $fg1 $bg2 $fg2 }
	    cb1 {decorateCB $winboard $slot $bg1 $fg1 $bg2 $fg2 }
	    8  {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    9  {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    10 {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    11 {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    12 {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    13 {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    14 {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    15 {BLdecorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	}
    }
}

proc BLbussTemplate {parent bg1 fg1} {
    debug 1 "bussTemplate:$parent"

    set labeltext "ABUS2 ABUS3 DBUS1 DBUS0 ABUS1 ABUS0"
    set cnt 0

    foreach buss {abus2 abus3 dbus1 dbus0 abus1 abus0} {
	frame $parent.$buss -relief groove -bd 0 -bg cyan4
	#frame $parent.$buss -relief groove -bd 1 -bg cyan4
	#frame $parent.$buss -relief groove -bd 1 -bg green
	#frame $parent.$buss -relief groove -bd 1 -bg $bg1
	#frame $parent.$buss -borderwidth 1 -relief groove  -bg $bg1
	pack $parent.$buss -side top -expand yes -fill x
	
	label $parent.$buss.id -text [lindex $labeltext $cnt] \
		-bg white -foreground $fg1 -pady -4
		#-bg white -foreground $fg1
		#-bg yellow -foreground yellow
		#-bg $bg1 -foreground $fg1
	pack $parent.$buss.id -expand yes -fill x
	incr cnt
	bind $parent.$buss  <Button-1> {blbusSelect %W}
	bind $parent.$buss.id  <Button-1> {blbusSelect %W}
	bind $parent.$buss  <Button-2> {blbusSelectTog %W}
	bind $parent.$buss.id  <Button-2> {blbusSelectTog %W}
    }
}

#
# bg1 = overall background color
# fg1 = letters
#
proc blklistGraphic {viewFlag bg1 fg1} {
    global gViewFlag

    debug 4 "blklistGraphic"

    set w .blklistGraphic
    set gViewFlag $viewFlag

    # this could be a toggle between the board view and the proc view
    if [winfo exists $w] {
	#pack forget $w
	destroy $w
	canvas .blklistGraphic -relief groove -borderwidth 4 -bg $bg1
	pack .blklistGraphic -fill both -expand yes
    }

    frame $w.header -bg $bg1
    pack  $w.header -fill both -expand yes -padx 2m -pady 2m

    if {[string compare $viewFlag "boardView"] == 0 } {
	set labtext "Board View"
    } else {
	set labtext "Processor View"
    }
    label $w.header.lab -text $labtext -bd 5 -bg $bg1 -fg $fg1
    pack  $w.header.lab -side top 

    #frame $w.box -relief groove -borderwidth 4 -bg $bg1
    #pack $w.box -fill both -expand yes

    #set w $w.box

    #
    # back is for cards in the rear of the machine
    #
    frame $w.back -bg $bg1
    pack  $w.back -fill both -expand yes -padx 2m -pady 2m

    frame $w.back.cards -bg $bg1 
    pack  $w.back.cards -side bottom -fill both -expand yes

    #    backTemplate $w.back.cards $bg1 $fg1 blue red
    if {[string compare $viewFlag "boardView"] == 0 } {
	BLbackTemplate $w.back.cards $bg1 $fg1 white white
	#BLbackTemplate $w.back.cards white white green $bg1
	#BLbackTemplate $w.back.cards $bg1 $fg1 green $bg1
    } else {
	BLbackTemplate $w.back.cards $bg1 $fg1 $bg1 $fg1
	#BLbackTemplate $w.back.cards $bg1 $fg1 green $bg1
    }
    #BLbackTemplate $w.back.cards $bg1 $fg1 $bg1 $bg1

    #
    # center is for the system buss diagram
    #
    frame $w.buss -bg $bg1 -relief groove -borderwidth 4
    pack  $w.buss -fill x -expand yes -padx 2m

    #    bussTemplate $w.buss $bg1 $fg1
    BLbussTemplate $w.buss white black 
    #bussTemplate $w.buss gray black 

    #
    # front is for cards in the front of the machine
    #
    frame $w.front -bg $bg1
    pack  $w.front -fill both -expand yes -padx 2m -pady 2m


    frame $w.front.cards -bg $bg1
    pack  $w.front.cards -side bottom -fill both -expand yes

    #    frontTemplate $w.front.cards $bg1 $fg1 blue red
    # only the first color matters

    if {[string compare $viewFlag "boardView"] == 0 } {
	BLfrontTemplate $w.front.cards $bg1 $fg1 white white
    } else {
	BLfrontTemplate $w.front.cards $bg1 $fg1 $bg1 $fg1
    }


    #BLfrontTemplate $w.front.cards $bg1 $fg1 green $bg1
    #BLfrontTemplate $w.front.cards $bg1 $fg1 $bg1 $bg1

    # 
    blklistDetails $viewFlag
    update idletasks
    # show current blacklist config
    displayBlacklist $viewFlag

}
proc blklistDetails { viewFlag } {
    global gSystemBoards
    global gcbBoards
    global gcsbBoards
    global gBg1
    global gFg1

    debug 1 "blklistDetails"

    foreach board $gSystemBoards {
	set state [whatBoardState $board]
	debug 1 "$board: $state"

###
	if { [lsearch $state slot_loaded] > -10} {
	    ###grayedSys bl_$board white white
	    blvisibleSys bl_$board $viewFlag $gBg1 $gFg1
	}
    }
    foreach cb $gcbBoards {
	if { 0 } {
	    set state [whatBoardState $cb]
	    if { [lsearch $state slot_loaded] > -10} {
		grayedCB bl_$cb $gBg1 $gFg1
		visibleCB bl_$cb $gBg1 $gFg1
	    }
	}
    }
    foreach board $gcsbBoards {
	if { 0 } {
	    set state [whatBoardState $board]
	    if { [lsearch $state slot_loaded] > -10} {
		grayedSB bl_$board $gBg1 $gFg1
		visibleSB bl_$board $gBg1 $gFg1
	    }
	}
    }


}

proc blacklistStart { platform } {
    global gBg1
    global gFg1
    global gBlacklistfile
    global env
    


    frame .blMenuBar -relief groove -borderwidth 4 -bg $gBg1
    pack .blMenuBar -side top -fill x

    BlMenuBar $gBg1

    canvas .blklistGraphic -relief groove -borderwidth 4 -bg $gBg1
    pack .blklistGraphic -fill both -expand yes

    if { ![llength $gBlacklistfile] } {
	set gBlacklistfile $env(SSPVAR)/etc/${platform}/blacklist
	debug 1 "gBlacklistfile: $gBlacklistfile"
    }

    blklistGraphic boardView $gBg1 $gFg1

    wm title . "Hostview-$platform Blacklist Edit"

}

#

# see hvTail


# ==>Main Menu Bar
#
#frame .menuBar -relief groove -borderwidth 4 -bg $gBg1
#pack .menuBar -side top -fill x
#menuBar $gBg1

#
# ==>Blklist Graphic Display
#
set w .blklistGraphic
#canvas $w -relief groove -borderwidth 4 -bg $gBg1
#pack $w -fill both -expand yes

#blklistGraphic $gBg1 $gFg1

#wm title . "Hostview - Blacklist"

#tkwait visibility $w

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***p
#
# ident	"@(#)blsysGraphUtils.tcl	1.10	97/01/29 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Supporting routines for the blsystemGraphic display.
#
# proc blBoardColor { board color }
# proc blProcColor { board color }
# proc blBusColor { bus bgcolor fgcolor }
#
#
# Select a board on the blacklist GUI (Button 1 event).
#   proc blboardSelect {arg}
#   proc blboardSelectToggle {arg}
#
# Select a board on the blacklist GUI (Button 1 event).
#   proc blbusSelect {arg}
#   proc blbusSelectToggle {arg}
#
# proc busPath {arg} {
# proc displayBlacklist {}

#



proc blBoardColor { board color } {

    debug 1 "blBoardColor: $board $color"
    #
    # Build a path to the select frame and color it.
    #
    set temp2 [boardPath bl_$board]
    set temp3 "$temp2.select"

    set gSelected(sysbd) $board

    #$temp3 configure -bg black
    set cells [procList $board]
     foreach cell $cells {

	# proc path is for the main canvas
	# alter it for the blacklist canvas
	
	set board [ BLsytleProcPath [procPath $cell] ]
	$board.id config -bg $color -foreground $color
	$board.icon config -bg $color -highlightbackground $color
	$board.icon.icon config -bg $color -highlightbackground $color
    }
}
#proc color
proc blProcColor { proc color } {

    debug 1 "blProcColor: $proc $color"
    #
    # Build a path to the select frame and color it.
    #
    #set temp2 [procPath $proc]
    #set temp3 "$temp2.select"

    #set gSelected(proc) $proc

    set board [ BLsytleProcPath [procPath $proc] ]
    $board.icon.icon config -bg $color -highlightbackground $color

    if { 0 } {
	#$temp3 configure -bg black
	set cells [procList $proc]
	foreach cell $cells {

	    # proc path is for the main canvas
	    # alter it for the blacklist canvas
	
	    #set proc [ BLsytleProcPath [procPath $cell] ]
	    #$proc.id config -bg $color -foreground $color
	    $proc.icon config -bg $color -highlightbackground $color
	}
    }
}
#
# Operator has pressed button 1 on a board
# This event is enabled via binding.
#
proc blboardSelect {arg} {
    global gBg1
    global gBackBoards
    global gFrontBoards

    global gSelected
    global gSelectedList

    global gBLchanged

    debug 1 "boardSelect from:$arg"

    set gBLchanged 1
    .blMenuBar.file.m entryconfigure 2 -state normal
    .blMenuBar.file.m entryconfigure 4 -state normal

    foreach board $gSelectedList(sysbd) {
	#set result [boardPath bl_$board]
	#$result.select configure -bg $gBg1
	blBoardColor $board white
    }
    set gSelectedList(sysbd) ""

    #
    # Reset the selection frame
    #
    if { [ info exists gSelected(sysbd)] } {
	if {[string length $gSelected(sysbd)] > 0} {
	    blBoardColor $gSelected(sysbd) white
	}
    }

    #
    # Build a path to the select frame and color it.
    #
    set temp1 [whatBoard $arg]

    blBoardColor $temp1 black
    set gSelected(sysbd) $temp1

    if { 0 } {
	set temp2 [boardPath bl_$temp1]
	set temp3 "$temp2.select"

	set gSelected(sysbd) $temp1

	#$temp3 configure -bg black
	set cells [procList $temp1]
	foreach cell $cells {
	    #set temp1 [procPath $cell]

	    # proc path is for the main canvas
	    # alter it for the blacklist canvas
	
	    set temp1 [ BLsytleProcPath [procPath $cell] ]
	    $temp1.id config -bg black -foreground black
	    $temp1.icon config -bg black -highlightbackground black -foreground black
	    $temp1.icon.icon config -bg black -highlightbackground black -foreground black
	}
    }

    debug 1 "1: gSelectedList(sysbd): $gSelectedList(sysbd) theSelectedB: $temp1 gSelected(sysbd): $gSelected(sysbd)"
    

}


#
# Operator has pressed button 2 on a board
# toggle selection of this board.
# This event is enabled via binding.
#
proc blboardSelectTog {arg} {
    global gBg1
    global gBackBoards
    global gFrontBoards

    global gSelected
    global gSelectedList

    global gBLchanged

    debug 1 "blboardSelectTog from:$arg"
    set gBLchanged 1
    .blMenuBar.file.m entryconfigure 2 -state normal
    .blMenuBar.file.m entryconfigure 4 -state normal

    # if it is gSelected(sysbd), turn it off and promote one of the others
    # if there are any.

    #
    # Build a path to the select frame and color it.
    #

    if { [ string length $arg ] < 5 } {
	# a board number
	# a board number
    } else {
	#full path
	set temp1 [whatBoard $arg]
    }
    set temp2 [boardPath bl_$temp1]
    set temp3 "$temp2.select"

    set theSelectedB $temp1
    debug 1 "1: gSelectedList(sysbd): $gSelectedList(sysbd) theSelectedB: $theSelectedB"

    #
    # Reset the selection frame
    #
    set ndx [lsearch $gSelectedList(sysbd) $theSelectedB ]
    if { $ndx > -1 } {

	#toggle this board from selected to deselected.

	#set gSelectedList(sysbd) [lreplace $gSelectedList(sysbd) $ndx $ndx ""]

	set temp1 ""
	set cnt 0
	foreach board $gSelectedList(sysbd) {
	    if { $cnt != $ndx } {
		set temp1 "$temp1 [lindex $gSelectedList(sysbd) $cnt]"
	    }
	    incr cnt
	}
	set gSelectedList(sysbd) $temp1

	blBoardColor $theSelectedB white
	#set result [boardPath bl_$theSelectedB]
	#$result.select configure -bg $gBg1
    } elseif { [ info exists gSelected(sysbd)] && 
	       [string compare $theSelectedB $gSelected(sysbd)] == 0 } {

	# it was selected by button-1 before
	
	if { [llength $gSelectedList(sysbd)] > 0 } {
	    # promote one or set to null
	    set gSelected(sysbd) [lindex $gSelectedList(sysbd) 0]

	    set len [llength $gSelectedList(sysbd)]
	    set temp1 ""
	    for { set i 1 } { $i < $len } { incr i} {
		debug 1 "temp1: $temp1"
		set temp1 "$temp1 [lindex $gSelectedList(sysbd) $i]"
	    }
	    set gSelectedList(sysbd) $temp1
	} else {
	    # promote one or set to null
	    unset gSelected(sysbd)
	    #set gSelected(sysbd) ""
	}

	blBoardColor $theSelectedB white
	#set result [boardPath bl_$theSelectedB]
	#$result.select configure -bg $gBg1
    } else {
	#toggle this board to selected.

	if { ![info exists gSelected(sysbd)] } {
	    set gSelected(sysbd) $theSelectedB
	} else {
	    set gSelectedList(sysbd) "$gSelectedList(sysbd) $theSelectedB"
	}

	#$temp3 configure -bg black
	blBoardColor $temp1 black
    }
    if { [info exists gSelected(sysbd)] } {
	debug 1 "2: gSelectedList(sysbd): $gSelectedList(sysbd) theSelectedB: $theSelectedB gSelected(sysbd): $gSelected(sysbd)"
    }
}



#
# Operator has pressed button 1 on a bus
# This event is enabled via binding.
#
proc blbusSelect {arg} {
    global gBg1
    global gBackBuss
    global gFrontBuss

    global gSelected
    global gSelectedList

    global gBLchanged
    global gBusChanged

    debug 1 "busSelect from:$arg"
    set gBLchanged 1
    set gBusChanged 1
    .blMenuBar.file.m entryconfigure 2 -state normal
    .blMenuBar.file.m entryconfigure 4 -state normal

    if { ![info exists gSelected(bus)] } {
	set gSelected(bus) ""
    }
    if { ![info exists gSelectedList(bus)] } {
	set gSelectedList(bus) ""
    }

    foreach bus $gSelectedList(bus) {
	blBusColor $bus white black
	#set result [busPath bl_$bus]
	#$result.select configure -bg $gBg1
    }
    set gSelectedList(bus) ""

    #
    # Reset the selection frame
    #
    if {[string length $gSelected(bus)] > 0} {
	blBusColor $gSelected(bus) white black
	
	#set result [busPath bl_$gSelected(bus)]
	#$result.select configure -bg $gBg1
    }

    #
    # Build a path to the select frame and color it.
    #
    set temp1 [whatBus $arg]

    blBusColor $temp1 black white
    set gSelected(bus) $temp1

    if { 0 } {
	set temp2 [busPath bl_$temp1]
	set temp3 "$temp2.select"

	set gSelected(bus) $temp1

	#$temp3 configure -bg black
	set cells [procList $temp1]
	foreach cell $cells {
	    #set temp1 [procPath $cell]

	    # proc path is for the main canvas
	    # alter it for the blacklist canvas
	
	    set temp1 [ BLsytleProcPath [procPath $cell] ]
	    $temp1.id config -bg black -foreground black
	    $temp1.icon config -bg black -highlightbackground black
	    $temp1.icon.icon config -bg black -highlightbackground black
	}
    }

    debug 1 "1: gSelectedList(bus): $gSelectedList(bus) theSelectedB: $temp1 gSelected(bus): $gSelected(bus)"
    

}


#
# Operator has pressed button 2 on a bus
# toggle selection of this bus.
# This event is enabled via binding.
#
proc blbusSelectTog {arg} {
    global gBg1
    global gBackBuss
    global gFrontBuss

    global gSelected
    global gSelectedList

    global gBLchanged
    global gBusChanged

    debug 1 "blbusSelect from:$arg"
    set gBLchanged 1
    set gBusChanged 1
    .blMenuBar.file.m entryconfigure 2 -state normal
    .blMenuBar.file.m entryconfigure 4 -state normal

    if { ![info exists gSelected(bus)] } {
	set gSelected(bus) ""
    }
    if { ![info exists gSelectedList(bus)] } {
	set gSelectedList(bus) ""
    }

    # if it is gSelected(bus), turn it off and promote one of the others
    # if there are any.

    #
    # Build a path to the select frame and color it.
    #

    if { [ string length $arg ] < 5 } {
	# a bus number
	# a bus number
    } else {
	#full path
	set temp1 [whatBus $arg]
    }
    set temp2 [busPath bl_$temp1]
    set temp3 "$temp2.select"

    set theSelectedB $temp1
    debug 1 "1: gSelectedList(bus): $gSelectedList(bus) theSelectedB: $theSelectedB"

    #
    # Reset the selection frame
    #
    set ndx [lsearch $gSelectedList(bus) $theSelectedB ]
    if { $ndx > -1 } {

	#toggle this bus from selected to deselected.

	#set gSelectedList(bus) [lreplace $gSelectedList(bus) $ndx $ndx ""]

	set temp1 ""
	set cnt 0
	foreach bus $gSelectedList(bus) {
	    if { $cnt != $ndx } {
		set temp1 "$temp1 [lindex $gSelectedList(bus) $cnt]"
	    }
	    incr cnt
	}
	set gSelectedList(bus) $temp1

	blBusColor $theSelectedB white black
	#set result [busPath bl_$theSelectedB]
	#$result.select configure -bg $gBg1
    } elseif { [string compare $theSelectedB $gSelected(bus)] == 0 } {

	# it was selected by button-1 before
	
	if { [llength $gSelectedList(bus)] > 0 } {
	    # promote one or set to null
	    set gSelected(bus) [lindex $gSelectedList(bus) 0]

	    set len [llength $gSelectedList(bus)]
	    set temp1 ""
	    for { set i 1 } { $i < $len } { incr i} {
		debug 1 "temp1: $temp1"
		set temp1 "$temp1 [lindex $gSelectedList(bus) $i]"
	    }
	    set gSelectedList(bus) $temp1
	} else {
	    # promote one or set to null
	    unset gSelected(bus)
	    #set gSelected(bus) ""
	}

	blBusColor $theSelectedB white black
	#set result [busPath bl_$theSelectedB]
	#$result.select configure -bg $gBg1

    } else {
	#toggle this bus to selected.

	if { [string compare $gSelected(bus) ""] == 0 } {
	    set gSelected(bus) $theSelectedB
	} else {
	    set gSelectedList(bus) "$gSelectedList(bus) $theSelectedB"
	}

	#$temp3 configure -bg black
	blBusColor $temp1 black white
    }
    if { [info exists gSelected(bus)] } {
	debug 1 "2: gSelectedList(bus): $gSelectedList(bus) theSelectedB: $theSelectedB gSelected(bus): $gSelected(bus)"
    }
}

#
# Operator has pressed button 1 on a proc
# This event is enabled via binding.
#
proc blprocSelect {arg} {
    global gBg1
    global gBackProcs
    global gFrontProcs

    global gSelected
    global gSelectedList

    global gBLchanged

    debug 1 "procSelect from:$arg"
    set gBLchanged 1
    .blMenuBar.file.m entryconfigure 2 -state normal
    .blMenuBar.file.m entryconfigure 4 -state normal

    if { ![info exists gSelected(proc)] } {
	set gSelected(proc) ""
    }
    if { ![info exists gSelectedList(proc)] } {
	set gSelectedList(proc) ""
    }

    foreach proc $gSelectedList(proc) {
	blProcColor $proc white
    }
    set gSelectedList(proc) ""

    #
    # Reset the selection frame
    #
    if {[string length $gSelected(proc)] > 0} {
	blProcColor $gSelected(proc) white
    }

    #
    # Build a path to the select frame and color it.
    #
    set temp1 [procMap $arg]

    blProcColor $temp1 black
    set gSelected(proc) $temp1

    debug 1 "1: gSelectedList(proc): $gSelectedList(proc) theSelectedB: $temp1 gSelected(proc): $gSelected(proc)"
    

}
#
# Operator has pressed button 2 on a proc
# toggle selection of this proc.
# This event is enabled via binding.
#
proc blprocSelectTog {arg} {
    global gBg1

    global gSelected
    global gSelectedList

    global gBLchanged

    debug 1 "blprocSelectTog from:$arg"
    set gBLchanged 1
    .blMenuBar.file.m entryconfigure 2 -state normal
    .blMenuBar.file.m entryconfigure 4 -state normal

    if { ![info exists gSelected(proc)] } {
	set gSelected(proc) ""
    }
    if { ![info exists gSelectedList(proc)] } {
	set gSelectedList(proc) ""
    }

    # if it is gSelected(proc), turn it off and promote one of the others
    # if there are any.

    #
    # Build a path to the select frame and color it.
    #

    if { [ string length $arg ] < 5 } {
	# a proc number
	# a proc number
    } else {
	#full path
	set temp1 [procMap $arg]
    }

    set theSelectedP $temp1
    debug 1 "1: gSelectedList(proc): $gSelectedList(proc) theSelectedP: $theSelectedP"

    #
    # Reset the selection frame
    #
    set ndx [lsearch $gSelectedList(proc) $theSelectedP ]
    if { $ndx > -1 } {

	#toggle this proc from selected to deselected.

	#set gSelectedList(proc) [lreplace $gSelectedList(proc) $ndx $ndx ""]

	set temp1 ""
	set cnt 0
	foreach proc $gSelectedList(proc) {
	    if { $cnt != $ndx } {
		set temp1 "$temp1 [lindex $gSelectedList(proc) $cnt]"
	    }
	    incr cnt
	}
	set gSelectedList(proc) $temp1

	blProcColor $theSelectedP white
    } elseif { [string compare $theSelectedP $gSelected(proc)] == 0 } {

	# it was selected by button-1 before
	
	if { [llength $gSelectedList(proc)] > 0 } {
	    # promote one or set to null
	    set gSelected(proc) [lindex $gSelectedList(proc) 0]

	    set len [llength $gSelectedList(proc)]
	    set temp1 ""
	    for { set i 1 } { $i < $len } { incr i} {
		debug 1 "temp1: $temp1"
		set temp1 "$temp1 [lindex $gSelectedList(proc) $i]"
	    }
	    set gSelectedList(proc) $temp1
	} else {
	    # promote one or set to null
	    set gSelected(proc) ""
	}

	blProcColor $theSelectedP white

    } else {
	#toggle this proc to selected.

	if { [string compare $gSelected(proc) ""] == 0 } {
	    set gSelected(proc) $theSelectedP
	} else {
	    set gSelectedList(proc) "$gSelectedList(proc) $theSelectedP"
	}

	#$temp3 configure -bg black
	blProcColor $temp1 black
    }
    if { [info exists gSelectedList(proc)] } {
	debug 1 "2: gSelectedList(proc): $gSelectedList(proc) theSelectedP: $theSelectedP gSelected(proc): $gSelected(proc)"
    }
}


proc procMap {arg} {

    set temp1 [split $arg .]
    set ndx [lsearch $temp1 "board"]
    set proc [lindex $temp1 [incr ndx]]

    # Leading zero is a problem...
    set temp2 [string trimleft $proc 0]
    if {[string length $temp2] < 1} {
	set temp2 0
    }
    if {$temp2 < 10 } {
	set temp2 0$temp2
    }

    set proc $temp2


    return $proc
}





#
# Given a processor string, return the bus id
# args is complete path to bus, returns bus in form b0, b1.
# args is complete path to bus, returns bus in form 0, 1.
#
proc whatBus {arg} {
    debug 1 "whatBus:$arg"

    set temp2 [split $arg .]

    set ndx1 [lsearch $temp2 buss]

    if {$ndx1 >= 0} {
	incr ndx1
	return [lindex $temp2 $ndx1]
    } else {
	return ""
    }
}

proc blBusColor { bus bgcolor fgcolor } {

    debug 1 "blBusColor: $bus $bgcolor $fgcolor"
    #
    # Build a path to the select frame and color it.
    #
    set temp2 [busPath bl_$bus]

    $temp2 config -bg $bgcolor -fg $fgcolor

    if { 0 } {
    #set temp3 "$temp2.select"

    set gSelected(bus) $bus

    #$temp3 configure -bg black
    set cells [procList $bus]
     foreach cell $cells {

	# proc path is for the main canvas
	# alter it for the blacklist canvas
	
	set bus [ BLsytleProcPath [procPath $cell] ]
	$bus.id config -bg $color -foreground $color
	$bus.icon config -bg $color -highlightbackground $color
    }
}
}

#
# Given a bus name, return the associated path.
# arg has the form b0..b15
# arg has the form 0..15
#
proc busPath {arg} {
    debug 1 "busPath:$arg"

    set blw .blklistGraphic.buss
    #set blw .blklistGraphic.box

    switch $arg {
	bl_abus0  {return $blw.abus0.id}
	bl_abus1  {return $blw.abus1.id}
	bl_abus2  {return $blw.abus2.id}
	bl_abus3  {return $blw.abus3.id}
	bl_dbus0  {return $blw.dbus0.id}
	bl_dbus1  {return $blw.dbus1.id}

	default {debug 5 "==>SWITCH DEFAULT in busPath:$arg"}
    }
}

# write out the current black list config
#
#
#
proc displayBlacklist { viewFlag } {
    global gBg1
    global gBackBoards
    global gFrontBoards

    global gSelected
    global gSelectedList
    global gSelected
    global gSelectedList
    global gSelected
    global gSelectedList

    global gBlacklistfile
    global gBLread
    global gBLchanged


    # read blacklist if not already read
    if {[info exists gBLread] } {
	set ret -1
    } else {
	set ret [initBLstate $gBlacklistfile]
	set gBLread 1
	set gBLchanged 0
	.blMenuBar.file.m entryconfigure 2 -state disabled
	.blMenuBar.file.m entryconfigure 4 -state disabled
	set gSelectedList(sysbd) ""
	set gSelectedList(bus) ""
	set gSelectedList(proc) ""
    }

    # put it in hostview terms, fill in gSelected and gSelectedList
    if { $ret != -1 } {
	decodeBlklist
    }


    if { [string compare $viewFlag "boardView"] == 0 } {
	# the gui comes up with all the boards white.
	# color in the ones that were in the blacklist

	if { [info exists gSelected(sysbd)] } {
	    foreach board $gSelected(sysbd) {
	    blBoardColor $board black
	}
	    foreach board $gSelectedList(sysbd) {
		#set result [boardPath bl_$board]
		#$result.select configure -bg $gBg1
		blBoardColor $board black
	    }
	    debug 1 "2: gSelectedList(sysbd): $gSelectedList(sysbd) gSelected(sysbd): $gSelected(sysbd)"
	}
    } else {
	if { [info exists gSelected(proc)] } {
	    foreach proc $gSelected(proc) {
		blProcColor $proc black
	    }
	    foreach proc $gSelectedList(proc) {
		blProcColor $proc black
	    }
	    debug 1 "2: gSelectedList(proc): $gSelectedList(proc) gSelected(proc): $gSelected(proc)" 
	}
    }
    if { [info exists gSelected(bus)] } {
	foreach bus $gSelectedList(bus) {
	    blBusColor $bus black white
	}
	foreach bus $gSelected(bus) {
	    blBusColor $bus black white
	}
	debug 1 "2: gSelectedList(bus): $gSelectedList(bus) gSelected(bus): $gSelected(bus)"
    }


}
proc closeBLgui {} {
    global gBLchanged

    if { $gBLchanged == 1 } {
	set result [tk_dialog .bldia "Hostview - Unsaved Changes" \
                        "Unsaved Changes.\nSave before closing?" \
                        questhead 0 Yes No Cancel]
	if { $result == 2 } {
            return
        } elseif { $result == 0 } {
	    appendblacklist
	}
    }

    destroy .
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)creBitmaps.tcl	1.4	96/10/14 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Create hostview bitmaps
#

set gBm_dir $env(SSPOPT)/bitmaps

image create photo power       -file $gBm_dir/bolt.ppm
image create photo powerRed       -file $gBm_dir/boltRed.ppm


image create bitmap sysfault    -file $gBm_dir/sysfaults.xbm
image create bitmap procs       -file $gBm_dir/procs.xbm
image create bitmap sbrds       -file $gBm_dir/sbrds.xbm

image create photo fan         -file $gBm_dir/fan.ppm
image create photo fanRed         -file $gBm_dir/fanRed.ppm

image create photo event       -file $gBm_dir/event.ppm
image create photo eventRed       -file $gBm_dir/eventRed.ppm

image create photo temperature -file $gBm_dir/temperature.ppm
image create photo temperatureRed -file $gBm_dir/temperatureRed.ppm

image create bitmap os       -file $gBm_dir/os.xbm
image create bitmap obp      -file $gBm_dir/obp.xbm
image create bitmap post     -file $gBm_dir/post.xbm
image create bitmap dhlp     -file $gBm_dir/dhlp.xbm
image create bitmap dummy    -file $gBm_dir/dummy.xbm
image create bitmap ques     -file $gBm_dir/ques.xbm
image create bitmap circle    -file $gBm_dir/circle.xbm
image create bitmap bigcircle -file $gBm_dir/bigcircle.xbm

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)globals.tcl	1.23	97/02/14 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Define global variables used within hostview.  
#   All global variables are prefixed w/a small g and a capital to flag
#   their devious purpose. 
#

# gDebugThreshold defines debug traffic.  0 = everything.
#=> 5  switch defaults, mib member non errors
#=>10 mibmembers error printout
########set gDebugThreshold 0
#set gDebugThreshold 4
set gDebugThreshold 5
#set staleStateTest 0

####set gHV_HOME $env(HOSTVIEW_HOME)
set gHV_HOME .

# bg1 is the background color of the main window.
set gBg1 gray81
# powered on boards
set gBg3 blue

# bg2 is the "active background" color for buttons
set gBg2 GhostWhite

# fg1 is default text color for main window.
set gFg1 black

# Healthy color
set gHealthy green3

# Problem color
set gProblem red

# bGrey is the color of components which are present but not powered.
set gGrey grey

# Board selection (main GUI)
set gSelectedBoard ""
set gSelectedBoardList ""
set gPlatformType ""
set gOs "2.5.1"
set gMY_PLATFORM ""

#
# Default font
#
set gFont1 -*-helvetica-bold-r-*-*-*-120-75-75-*-*-iso8859-1
#set gFont1 -Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-* 
#set gFont2 -Adobe-Helvetica-Bold-R-Normal--*-140-*-*-*-*-*-* 
set gFont2 -*-helvetica-bold-r-*-*-*-140-75-75-*-*-iso8859-1

#
# Lists
#
set gBuss {abus2 abus3 dbus1 dbus0 abus1 abus0}
	
set gFrontPower {bp0 bp1 bp2 bp3}
set gBackPower  {bp4 bp5 bp6 bp7}
set gBulkPower  {bp0 bp1 bp2 bp3 bp4 bp5 bp6 bp7}

set gCenterBoards {ctr}
set gFrontBoards {csb0 cb0 0 1 2 3 4 5 6 7} 
#set gFrontBoards {sb0 cb0 b0 b1 b2 b3 b4 b5 b6 b7} 
set gBackBoards  {csb1 cb1 15 14 13 12 11 10 9 8} 
#set gBackBoards  {sb1 cb1 b15 b14 b13 b12 b11 b10 b9 b8} 

set gFrontSysBoards {0 1 2 3 4 5 6 7} 
#set gFrontSysBoards {b0 b1 b2 b3 b4 b5 b6 b7} 
set gBackSysBoards {8 9 10 11 12 13 14 15}
#set gBackSysBoards {b8 b9 b10 b11 b12 b13 b14 b15}
set gSystemBoards {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}
#set gSystemBoards {b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15}
set gcbBoards {cb0 cb1}
set gcsbBoards {csb0 csb1}

set gFanDrawers {ft0 ft1 ft2 ft3 ft4 ft5 ft6 ft7 ft8 ft9 ft10 ft11 ft12 ft13 ft14 ft15}

#
# Boards with temperature sensors
#
set gThermalSource "ctr $gFrontBoards $gBackBoards"

#
# Board List, looks like {b0 domain power loaded}
# Board List, looks like {0 domain power loaded}
#
set gBoards ""

#
# Processor List, looks like {b0 {os running}}
#   where os could be {dummy|os|obp|post|dhlp} and running
#   could be {running|exit|prerun|unknown|blacklist|redlist|not configured}
#
set gProcessors ""

#
# Legal domain colors
#
set gDomainColors {white orange yellow pink brown red green violet grey }
#set gDomainColors {red orange yellow green blue violet grey white}
#
# domain color mapping, initially all colors available, set to -1
# later assign the color to a domain, 0 1 2.  if a color is freed, 0 -1 1
#
set gNumDomCols [ llength $gDomainColors ]
set gDomainColorMap ""
foreach color $gDomainColors {
    set gDomainColorMap "$gDomainColorMap -1"
}
#
# Defined domains and members, looks like {orange {b0 b1 b2}}
#
set gDomains ""
#
# domain name map.  index 0 is the first domain, colormap will have 0.
# 
set gDomainNameMap ""

#
# gPowered contains the board ID of enabled boards. 
# This is simply to communicate between systemDetail and systemGraphic
# which boards could be selected.
#
set gPowered "ctr"
#set gPowered "ctr $gBulkPower"

#
# gPopupBoard contains the board ID os a button 3 popup from the main GUI.
# There can only be one of these active at any given instant.
#
set gPopupBoard 0

#
# List of fans and status, looks like {off|nominal|high {ft0b} {ft0 ft1}}
# "high { ft0b} {ft0 ft1}"
# speed for all { failed list } {powered list} { present "conf" list }
#
set gFanList "nominal {} {} {}"


# bulk power status
# for bulk power, if it's present, it's either on/fail (not off).
#  { present list } { failed list } {powered list}
set gBulkPowerList "{} {} {}"

#
# Thermal Values
#
# gTd values define the drawing coordinates used by the thermalDetail form.
# Each temperature is represented by a fat vertical line.
#
# These are treated as constants.  No application should modify these values.
# gTdX1 is initial X value of temperature bar.
# gTdY1, gTdY2 are Y values of temperature bar.
# gTdInc is increment value between bars (x coordinate, left to right).
# gTdWidth is bar width.
#
set gTdX1 36
#set gTdX1 15
set gTdY1 1
set gTdY2 150
#set gTdWidth 20
set gTdWidth 60
#set gTdInc 22
set gTdInc [expr $gTdWidth + 2]
#
# Define the max and min thermal bargraph values (Celsius).
#
set gThermalMaxTemp 80
set gThermalMinTemp 20
#
# Define where thermal trouble starts (Celsius)
#
#set gThermalProblem 60
#
# gThermalList contains the most recent values for all thermal sensors.
# List members are organized in the form {board flag {values}} where 
# flag of 1 indicates problem condition.
#
set gThermalList ""

#
# Power Values
#
# gPd values define the drawing coordinates used by the powerDetail form.
# Each voltage/current is represented by a fat vertical line.
#
# These are treated as constants.  No application should modify these values.
# gPdX1 is initial X value of voltage/current bar.
# gPdY1, gPdY2 are Y values of voltage/current bar.
# gPdInc is increment value between bars (x coordinate, left to right).
# gPdWidth is bar width.
#
set gPdX1 36
#set gPdX1 15
set gPdY1 1
set gPdY2 150
set gPdWidth 60
###set gPdWidth 30
set gPdInc [expr $gPdWidth + 2]

#set gPdInc 22
#set gPdWidth 20
#set gPdX1 15
#
# gPowerList contains the most recent values for all power sensors.
#
set gPowerList ""
# powered buses
set gBusUp ""

# flag to popup "working" window when true
set gNewWin 0

# Define various attributes supporting the edit/properties window.
# 
# gPropVar defines currently selected category
# gPropCategories defines the legal category options for this window.
#
# gProPower is the default power script filename.
#  
set gPropVar dr
set gPropCategories {general blacklist power dr}

#
# Support for properties/dr option
#
set gPropUpdateFlag no
set gPropUpdateFlag2 no

set gPropUpdateValue 10
set gPropUpdateValue2 10

#
# Support for properties/power option
#
set gPwrExecFlag no
set gPwrExecFlag2 no

set gPwrExecCmd "/opt/SUNWssp/bin/power"

#
# Support for properties/edit blacklist
#
set gEdtBlkSave yes
set gEdtBlkSave2 yes
set gEdtBlkPrint lpr
set gEdtBlkDir /optSUNWssp/etc/eng1
set gEdtBlkFile blacklist
set gEdtBlkExt .bak 
set gEdtBlkBackup yes
set gEdtBlkBackup2 yes

#
# Directory which contains the DR routines.
#
#set gDRdirectory "/home/hostview/dr2"

#
#
#
set gDRboard {cpu memory device obp unsafe all}

#
# dr memory config
#
set gMemCurSys 512
set gMemAttCap 512
set gMemMax 1024
set gMemDet 1(enabled)

set gMemConfig 256
set gInterFact 1

set gMemReduction "276 (256+20)"
set gMemRemaining 0
set gMemPercent "50% (0KB Remaining)"
set gMemTimeStart "Tue Jan 17 10:05:34 1995"
set gMemTimeNow   "Tue Jan 17 10:35:17 1995"

# directory containing bitmaps, ascii help files
set gBm_dir $env(SSPOPT)/bitmaps
set gAsciiHelp_dir $env(SSPOPT)/hv_help
set ghelpFile "*.help"

set ghelpBringupFile bringup.help	
set ghelpDrFile dr.help	
set ghelpEditmenuFile editmenu.help	
set ghelpMenuFile menu.help	
set ghelpBlacklistFile prop.help	
set ghelpPropFile prop.help	
set ghelpDomainsFile domains.help	
set ghelpEditFile edit.help	
set ghelpHotswapFile hotswap.help	
set ghelpPowerFile power.help	

#Mib poll frequency, seconds
set pollfrequency 120
set gMibTouched 0
set testfail 0

# set the freq to use when filtering failure events
#set gTrapFreq 240
set gTrapFreq 60
#set gTrapFreq 10
# set the freq to use when refreshing
#set gMibRefreshFreq 60
set gMibRefreshFreq 300
#set gMibRefreshFreq 600

#milliseconds
set gBoardPowerWait 5000

#failure mode history
set gHvFailLogDir $env(SSPVAR)/adm
#set gHvFailLogDir .

# this should be in app defaults
#set gHvMaxFails2Log 16
#set gHvMaxFails2Log 128
set gHvMaxFails2Log 64
#set gSystemFail {{arbstop mari}}
set gSystemFail ""
# each failure event writes a fixed size of info to the log file
# 2 ** 14
#set gFailTextSize 4096
#set gFailTextSize 16384
set gFailTextSize [expr $gHvMaxFails2Log * 80 + 4000]
#set gFailTextSize [expr $gHvMaxFails2Log * 80 * 3 / 4 + 4000]

# can explicity set blacklist file or set to "" for the default
# the default is: $env(SSPVAR)/etc/${platform}/blacklist
#set gBlacklistfile /export/home/ssp/mari/blacklist
set gBlacklistfile ""


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)utilities.tcl	1.4	96/09/16 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   GP support routines.
#

#
# Somewhere, a dismiss button has been pressed.
# Find that sucker and nuke it.
#
proc dismissMe { } {
    global gPidMibFresh

    set geox [winfo pointerx .]
    set geoy [winfo pointery .]
    set target1 [winfo containing $geox $geoy]

    debug 1 "I think this is:$target1"

    set target2 [split $target1 .]

    set target3 [lindex $target2 1]

    set count [countWin]

    if { $count < 2 } {
	if [info exists gPidMibFresh] {
	    debug 1 "killing gPidMibFresh: $gPidMibFresh"
	    if [catch {exec kill $gPidMibFresh} result] {
		debug 10 $result
	    }
	    unset gPidMibFresh
	}
    }

    destroy .$target3

    return $target1
}

#
# Write debug traffic to stdout.
#
proc debug {flag arg} {
    global gDebugThreshold

    if {$flag > $gDebugThreshold} {
	puts "$flag $arg"
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)hostview_init.tcl	1.3	96/08/26 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   hostview initialization file
#

# user configurable
if { [ file readable ${gHV_HOME}/.hostview ] > 0 } {
	source ${gHV_HOME}/.hostview 
}

#
# Check SSP environment variables:
#
set cray_env "SUNW_HOSTNAME SSPLOGGER"
#set cray_env "SUNW_HOSTNAME SSPETC SSPVAR SSPLOGGER"

foreach var $cray_env {
	if { ![info exists env($var)] } {
	puts "error hostview: Environment variable '$var' must be set."
	#error "hostview: Environment variable '$var' must be set."
	}
}
# for testing:	
if {[ info exists env(SSPLOGGER)] < 1} {
	set env(SSPLOGGER) /workspace/sw/xfire/mari/sspxf/hostview/adm
}

if {[ info exists env(SUNW_HOSTNAME)] < 1} {
	set env(SUNW_HOSTNAME) marvin
}


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)eventText.tcl	1.9	97/02/14 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   General proc to service event commands as a separate process using a text
#   widget.
#
#
# called from hostview_child (hvGenExec)
#

proc eventTextPopDet { cmdArg filename filebase} {
    global gFont2
    global gEventFlg

    debug 2 "eventTextPopDet:$cmdArg $filename $filebase"

    # this proc is invoked as a separate process.
    # the window has no parent

    wm title . "Hostview - Event"

    frame .f
    pack .f -fill x
    # pack .f   moves topic to the middle

    frame .f.left
    pack  .f.left -side left

    #Topic
    label .f.left.topic -text Event:

    pack  .f.left.topic -ipady 10 -ipadx 10

    #pack  .t1 -ipady 10 -ipadx 10
    #text  .t1.text -relief groove -width 60 -height 10 -yscrollcommand ".t1.yscroll set"
    #pack  .t1.text -side top

    frame .t1
    pack  .t1
    # this text frame is not allowed to resize
    #pack  .t1 -expand true -fill both
    scrollbar .t1.yscroll -command ".t1.text yview"
    pack .t1.yscroll -side right -fill y


	# user input - scrolled multi line - text editor
    text  .t1.text -relief groove -yscrollcommand ".t1.yscroll set" \
	    -width 110 -height 8
    pack  .t1.text -side left -fill both

    frame .f2
    pack .f2 -fill x

    frame .f2.left2
    pack  .f2.left2 -side left
    label .f2.left2.desc -text "Detailed Description:"

    pack  .f2.left2.desc -ipady 10 -ipadx 10

    frame .t2
    pack  .t2 -expand y -fill both

    scrollbar .t2.xscroll -command ".t2.text xview" -orient horiz
    pack .t2.xscroll -side bottom -fill x 

    scrollbar .t2.yscroll -command ".t2.text yview"
    pack .t2.yscroll -side right -fill y


	# user input - scrolled multi line - text editor
    text  .t2.text -relief groove -yscrollcommand ".t2.yscroll set" \
	    -xscrollcommand ".t2.xscroll set" -width 75 -height 14 \
	    -setgrid true
    pack  .t2.text -side left -expand y -fill both


    # display and count choices for this topic
    set nchoices [ eventChoices $cmdArg $filename $filebase]


    frame .buttonbox
    pack  .buttonbox -fill x 



    button .buttonbox.dismiss -text dismiss -command abortExec

    pack .buttonbox.dismiss


}

proc text2button2 { t start end command } {
    global textbutton

    set gFontEvent1 *-helvetica-bold-r-*-17-*

    if ![info exists textbutton(uid)] {
	set textbutton(uid) 0
    } else {
	incr textbutton(uid)
    }
    set tag button$textbutton(uid)


    $t tag configure $tag -relief ridge -borderwidth 2 -font $gFontEvent1 \
	    -offset -6

    # save the background and foreground
    set back [$t cget -bg]
    set front [$t cget -fg]

    #bind the command to the tag
    $t tag bind $tag <Button-1> $command
    $t tag add $tag $start $end

    $t tag bind $tag <Enter> "revVid2 $t $tag"
    $t tag bind $tag <Leave> "retVid2 $t $tag $front $back"

    # use another tag to remember the cursor

}
# reverse video
proc revVid2 { t tag } {
    $t tag configure $tag -background [$t cget -fg]
    $t tag configure $tag -foreground [$t cget -bg]
}
# putback video
proc retVid2 { t tag front back} {
    $t tag configure $tag -background $back
    $t tag configure $tag -foreground $front
}
# putback cursor - regexp not matching...
proc text2buttonFixCursor { t cursor } {
    #regexp {cursor=([^ ]*)} {%W tag names} x cursor
    $t config -cursor $cursor
}


# 
# write verbage to text widget.
# 
#
proc p2TextWtop {dest verbage} {
    global gThetop

    $dest insert end $verbage
    $dest see [expr $gThetop + 10]
    #$dest see end
}
proc ins2TextW2 {dest verbage} {
    global gThetop

    $dest insert insert $verbage output
    $dest see $gThetop
    #$dest see end
}

#
# return label for window 
#
proc eventChoices { errevent filename filebase} {
    global gHV_HOME
    global geventPowerFile
    global gPower
    global gThetop
    set limit ""

    debug 2 "eventChoices: $errevent $filename $filebase"
    set gThetop [.t1.text index end]

    # show all the errors on the errevent list
    # 
    set numerrs [llength $errevent]

    for { set i 0 } { $i < $numerrs } { incr i } {
	set latesterr($i) [lindex $errevent $i]
	set domain($i) [lindex $latesterr($i) 1]
	if { [ scan $domain($i) "%d"  num ] == 1 } { set domain($i) "" }
	set syserr($i) [lindex $latesterr($i) 0]
	set when($i) [lindex $latesterr($i) 2]
	if { [string first panic $syserr($i)] > -1 } {
	    set syserr($i) panic
	}
    }

    
    set limit $numerrs
    for { set i 0 } { $i < $numerrs } { incr i } {
	p2TextWtop .t1.text "Error: $syserr($i) $domain($i)  $when($i)\n"
	set s1 [expr $i + 1]
	set s2 [expr $i + 2]
	.t1.text tag add event$i ${s1}.0 ${s2}.0
	.t1.text tag configure event$i -font *-times-bold-r-*-14-* -offset -6
	text2button2 .t1.text ${s1}.0 ${s2}.0 "getEvent $i $filename $filebase"
    }

    return $limit
}


proc getEvent { flag filename filebase} {
    global gOldCursor
    global gThetop
    global gFailTextSize
    
    set tailsize 50
    set t .t1.text

    debug 1 "getEvent:  $flag $filename $filebase"
    set gOldCursor [$t cget -cursor]
    $t see end
    set gThetop [.t2.text index end]

    $t config -cursor watch

    # this is not needed for the man page method
    # tag the output widget to wrap on word bound.
    # inserts will pick up this tag, but only if some text has it.
    # no text may be there yet, so still need insert tag, not p2TextWtop
    .t2.text tag add output 1.0 end
    .t2.text tag configure output -wrap word

    if { [file readable $filename] } {

	if { [catch { open $filename "r" } fd] } {
	    debug 10 "error opening file: $filename"
	    return {}
	}
	# seek $filebase + $gFailTextSize * $flag
	
	set position [expr $gFailTextSize * $flag + $filebase]

	debug 1 "position: $position"
	seek $fd $position start

	# read gFailTextSize
	set data [ read $fd $gFailTextSize]

	set pattern "=+=+=+=+=" 

	debug 1 "data: $data"

	if { $data != "" } {

	    set lastchar [string last $pattern $data]

	    set lastchar [expr $lastchar + [ string length $pattern ]]
	    debug 1 "last char: $lastchar"
	    set cleandata [ string range $data 0 $lastchar]
	    ins2TextW2 .t2.text $cleandata
	    ins2TextW2 .t2.text "\n\n"

	    # fire off the snapshot: hvSnapShot $cleandata
	    if { 0 } {
		if {[catch {exec hostview_child -E "$cleandata" &} result] } {
		    debug 10 $result
		}
	    }

	    # put out to text widget
	    # creating a snapshot of hostview when the $error occurred.


	    set cleandata ""
	    set data ""

	}
	$t config -cursor $gOldCursor
	#puts $fd $params
	close $fd
    }

}
#


proc execeCmdFcn {execCmd} {
    global gPid
    global gFp
    global env
    global gEventFlg

    set outputDest .t2.text

    # read back the command box, allows user to edit the command
    set cmd $execCmd

    # redirect stderr and stdout
    if [catch {open "|$cmd |& cat"} fp1] {
	p2TextWtop $outputDest "Error: $fp1\n"
	puts stderr "Error: $fp1 \ncommand: $cmd\n"
	return "-1"
    }
    # non-blocking read
    fileevent $fp1 readable [list eventReader $fp1]

    set gPid [pid $fp1]
    set gFp $fp1

    return ""
}

proc eventReader { pipe } {
    global gOldCursor

    set outputDest .t2.text
    set selectW .t1.text

    if [eof $pipe] {
	#close $pipe
	catch {close $pipe}
	$selectW config -cursor $gOldCursor
	return
    }
    gets $pipe buff1
    p2TextWtop $outputDest $buff1
    p2TextWtop $outputDest \n

}


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)execTextPopup.tcl	1.20	97/02/21 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# now called from hostview_child ( hvGenExec )
#
# Description:
#   General proc to service commands as a separate process using a text
#   widget to exec a command.  
#
#	exec ${gHV_HOME}/execTextPopup $cmdArg $domainName &
#	called by: genTextExec { cmdArg }
#	menuBar:	    -command "genTextExec sspLog" -underline 0
#
# notes:
#  if user picks domain after execute button, restart window
#  ( domain info is on the hostview side )


proc genTextPopDet { cmdArg domainName  } {
    global gFont2
    global gHelpFlg
    global gDirflag
    global gMY_PLATFORM

    debug 2 "genTextExec:$cmdArg $domainName"

    # this proc is invoked as a separate process.
    # the window has no parent

	# title based on input arg
    wm title . [ wtitleCre $cmdArg ]
    # setting minsize or maxsize enables window resizing
    wm minsize . 30 5

	# Only want text portion of window to grow on resize, so
	# don't use -expand option when packing this frame.


    frame .f -bd 2
    pack .f
    #pack .f -expand y -fill both

    frame .f.left
    pack  .f.left -side left

    label .f.left.hostname -text "Domain Name:" -bd 2
    #label .f.left.hostname -text "SUNW_HOSTNAME:"
    label .f.left.command -text "Command:" -bd 2
	# pack these 2 widgets, anchor east
    pack  .f.left.hostname .f.left.command -anchor e

    frame .f.right
    pack  .f.right -expand y -fill both

	# user input - one line
    entry .f.right.hostname -relief sunken -width 15 -font $gFont2
    entry .f.right.command  -relief sunken -width 60 -font $gFont2 
    	
    pack  .f.right.hostname .f.right.command -anchor w

    if {  [string compare $cmdArg "domainRemove"] == 0 } {
	set gMY_PLATFORM [lindex $domainName 1]
	set domainName [lindex $domainName 0]
    }

    # fill in execCmd, helpCmd
    cmdFcn $cmdArg $domainName execCmd

    frame .t
    pack  .t -expand true -fill both
    #pack  .t

    # user input - scrolled multi line - text editor
    # setgrid true makes window resizable
    text  .t.text -relief groove -setgrid true -width 80 -height 25 \
	    -bd 6 \
	    -yscrollcommand ".t.yscroll set" \
	    -xscrollcommand ".t.xscroll set"
    scrollbar .t.xscroll -command ".t.text xview" -orient horiz
    pack .t.xscroll -side bottom -fill x 
    pack  .t.text -side left -expand y -fill both

    scrollbar .t.yscroll -command ".t.text yview"
    pack .t.yscroll -side right -fill y


    if { [string compare $domainName "no_domain"] != 0 && 
    [string compare $cmdArg "domainCreate"] != 0 } {
	.f.right.hostname insert 0 $domainName
    }
    .f.right.command insert 0 $execCmd


    frame .buttonbox -bd 2
    pack  .buttonbox -fill x
    #pack  .buttonbox -expand y -fill x 

    # help commands allow further execs.  other commands do not.
    set gHelpFlg 0
    
    bind .f.right.command <Return> "execCmdFcn \"$execCmd\""
    bind .f.right.command <Control-c> abortExec
    focus .f.right.command

    button .buttonbox.execute -text execute -command "execCmdFcn \"$execCmd\""
    button .buttonbox.dismiss -text dismiss -command "destroy ."
    #button .buttonbox.dismiss -text dismiss -command abortExec
    button .buttonbox.abort   -text abort   -command abortExec

    button .buttonbox.help    -text help    -command "helpFcn $cmdArg"

    pack .buttonbox.execute .buttonbox.dismiss \
	 .buttonbox.abort   .buttonbox.help \
	 -side left -expand y -fill x
    #-side left -expand y -fill x

    # some commands have special bindings
    specialBindings $cmdArg $execCmd $domainName
}

proc specialBindings { cmdArg execCmd domainName } {

    if { $cmdArg == "domainCreate" } {
	.f.right.command delete 0 end
	.f.right.command insert 0 domain_create
	focus .f.right.hostname

	.buttonbox.execute config -command {
	    set execCmd [specDomCreBuild]
	    if { [string compare $execCmd "FAIL"] != 0 } {
		execCmdFcn \"$execCmd\"
		.f.right.command delete 0 end
		.f.right.command insert 0 domain_create
	    }
	}
    } elseif { $cmdArg == "sspLog" } {
	.buttonbox.dismiss config -command abortExec
	execCmdFcn \"$execCmd\"

    } elseif { $cmdArg == "domainStatus" || $cmdArg == "domainHistory" } {
	execCmdFcn \"$execCmd\"

    } elseif { $cmdArg == "domainRemove" } {
	# keep the -q option a secret and do not allow another domainRemove
	.buttonbox.execute config -command "specDomrem $domainName"
	bind .f.right.command <Return> "specDomrem $domainName"
    } elseif { $cmdArg == "domainRename" } {
	.buttonbox.execute config -command specDomRename
	bind .f.right.command <Return> "specDomRename"
    } elseif { $cmdArg == "fan" } {
	.buttonbox.execute config -command "specFan"
	bind .f.right.command <Return> "specFan"
    } elseif { $cmdArg == "power" } {
	.buttonbox.execute config -command "specPower"
	bind .f.right.command <Return> "specPower"
    } elseif { $cmdArg == "bringup" } {
	.buttonbox.execute config -command "specBringup"
	bind .f.right.command <Return> "specBringup"
    }

}
# 
# write verbage to text widget.
# 
#
proc put2TextW {dest verbage} {

    $dest insert end $verbage
    $dest see end
}

#
# return label for window 
#
proc wtitleCre {cmdArg} {

    set title1 ""

    switch $cmdArg {
	sspLog { set title1 "SSP Logs" }
	domainCreate { set title1 "Create Domain" }
	domainRemove { set title1 "Remove Domain" }
	domainRename { set title1 "Rename Domain" }
	domainStatus { set title1 "Domain Status" }
	domainHistory { set title1 "Domain History" }
	power { set title1 "Power Control and Status" }
	bringup { set title1 "Bringup Command" }
	fan { set title1 "Fan Control and Status" }
    }
    return $title1
}

#
# Ssp Logs specifics: domain name and command to exec
#
proc cmdFcn {cmdArg domainName execCmd} {
    global gPwrExecCmd
    global gDirflag

    global env

    upvar $execCmd cmd;		#pass by reference

    set cmd ""
	
#for use with properties:
# didn't work: power { set cmd $gPwrExecCmd }
#domainCreate { set cmd "domain_create -d" }
#domainCreate { set cmd [ specDomCre $domainName] }

    switch $cmdArg {
	sspLog { set cmd [ specSspLog $domainName ] }
	domainCreate { set cmd [ specDomCre $domainName] }
	domainRemove { set cmd "domain_remove -d $domainName" }
	domainRename { set cmd "domain_rename -d ${domainName} -n \
		new_domain_name" }
	domainStatus { set cmd domain_status }
	domainHistory { set cmd domain_history }
	power { set cmd power }
	bringup { set cmd [ bldBringup $domainName]}
	fan { set cmd fan }
    }
    return $cmd
}

proc specDomRename {} {
    set cmd [ .f.right.command get ]
    set new_domain_name [lindex $cmd 4]
    set h_list [lindex [get_domain_history_entry $new_domain_name] 0]

    set result 0
    if {[llength $h_list]} {
	set msg "History entry for $new_domain_name exists.  Domain rename will overwrite this history.\n\nDo you want to continue?"

	set result [tk_dialog .dlg_domc "Hostview Question" \
		$msg \
		questhead 1 Continue Cancel ]
    }
    if { $result < 1 } {
	.f.right.command delete 0 end
	.f.right.command insert 0 "$cmd -q"
	execCmdFcn x
	.f.right.command delete 0 end
	.f.right.command insert 0 $cmd
	
    }
}

proc specFan {} {


    set cmd [ .f.right.command get ]

    #put2TextW .t.text "specFan cmd: $cmd"

    set result 0
    if { [lsearch $cmd off] != -1 } {

	set msg "Warning: turning off fan trays can cause system boards to overheat.\n\nDo you want to continue?"

	set result [tk_dialog .dlg_domc "Hostview Question" \
			$msg \
			questhead 1 Continue Cancel ]
    }
    if { $result < 1 } {
	.f.right.command delete 0 end
	.f.right.command insert 0 "$cmd -q"
	execCmdFcn x
	.f.right.command delete 0 end
	.f.right.command insert 0 $cmd
	#put2TextW .t.text "cmd: $cmd"
	
    }


}

proc specDomrem { domainName } {
    global env
    global gMY_PLATFORM

    set cmd [ .f.right.command get ]

    #put2TextW .t.text "specDomrem cmd: $cmd"


    set oldSUNW_HOSTNAME $env(SUNW_HOSTNAME)
    set env(SUNW_HOSTNAME) $domainName
    set domState [check_host -q]
    set env(SUNW_HOSTNAME) $oldSUNW_HOSTNAME

    if { $domState == 0 } {

	set msg "Domain $domainName is up.\n\nContinue removing this domain ?"
	    
	set result [tk_dialog .dlg_domr "Hostview Question" \
			$msg \
			questhead 1 Yes Cancel ]

	if { $result == 1 } {
	    return
	}
    }


    #domain_remove -q -d xf1 -y  <=== This will remove directories
    #domain_remove -q -d xf1 -n  <=== This will NOT remove directories

    set msg2 "The following subdirectories contain domain specific information such as messages files, configuration files, and hpost dump files. You may choose to keep these directories if you still need this information. This domain may be recreated with or without this information being saved.\n$env(SSPVAR)/adm/${domainName}\n$env(SSPVAR)/etc/${gMY_PLATFORM}/${domainName}\nKeep directories ?"

    set result [tk_dialog .dlg_domr "Hostview Question" \
			$msg2 \
		    questhead 0 Yes No Cancel ]
    
    if { $result == 2 } {
	return
    } elseif { $result == 0 } {
	set dirflag "-n"
    } else {
	set dirflag "-y"
    }

    .f.right.command delete 0 end
    .f.right.command insert 0 "$cmd -q $dirflag"
    execCmdFcn x
    .f.right.command delete 0 end
    .f.right.command insert 0 $cmd
    #put2TextW .t.text "cmd: $cmd"
	
}

proc specPower {} {

    # note: power command has user prompts that we avoid by parsing $cmd.

    set cmd [ .f.right.command get ]

#   put2TextW .t.text "specPower cmd: $cmd\n"
	if { $cmd == "" } {
		set cmd "power"
		.f.right.command delete 0 end
		.f.right.command insert 0 "$cmd"
	} elseif { [lindex $cmd 0] != "power" } {
		set cmd "power $cmd"
		.f.right.command delete 0 end
		.f.right.command insert 0 "$cmd"
	}

    foreach i $cmd {
        if { $i == "-cb" || $i == "-B" || $i == "-ps" } {
            set msg2 "You cannot use the $i argument from hostview. You may need to use the power command from a shell prompt."
            tk_dialog .dlg_domc "Hostview - Power" $msg2 {} -1 OK
            return
        }
    }

#   put2TextW .t.text "cmd: $cmd\n"
    execCmdFcn x

}

proc specBringup {} {

    set cmd [ .f.right.command get ]

    #put2TextW .t.text "specBringup cmd: $cmd"

    .f.right.command delete 0 end
    .f.right.command insert 0 "$cmd -F"
    execCmdFcn x
    .f.right.command delete 0 end
    .f.right.command insert 0 $cmd
    #put2TextW .t.text "cmd: $cmd"
	
}

proc specDomCre { domainName } {
    global env
    global gMY_PLATFORM
    global gOs
    global gPlatformType
    global gFont2
    global gSelectedBoard
    global gSelectedBoardList
    global gPlatformType
    global gFontlab
    global gPresentBoards

    #set gFontlab 10x20
    set gFontlab  -*-helvetica-bold-r-*-*-*-140-75-75-*-*-iso8859-1

    #create entry widgets.  fill with sysbrds. wait for os.

    frame .f2
    pack .f2

    frame .f2.left2
    pack  .f2.left2 -side left

    label .f2.left2.sysbrds -text "System Boards:" -bd 6
    #label .f2.left2.sysbrds -text "System Boards:" -font $gFontlab -bd 3
    label .f2.left2.os -text "OS Version:" -bd 6
    label .f2.left2.plat -text "Platform Type:" -bd 6
    #label .f2.left2.apply -text "Build Command:" -bd 6
	# pack these 3 widgets, anchor east
    pack  .f2.left2.sysbrds .f2.left2.os .f2.left2.plat -anchor e

    frame .f2.right2
    pack  .f2.right2 -expand y -fill both

	# user input - one line
    #entry .f2.right2.command  -relief sunken -width 60 -font $gFont2 
    entry .f2.right2.sysbrds -relief sunken -width 30 -font $gFont2
    entry .f2.right2.os  -relief sunken -width 30 -font $gFont2 
    entry .f2.right2.plat  -relief sunken -width 30 -font $gFont2 
    #button .f2.right2.apply -text apply -command specDomCreBuild
    	
    pack  .f2.right2.sysbrds .f2.right2.os .f2.right2.plat -anchor w

    if { 0 } {
	# Ultra Enterprise platform type
	if { [ catch  { set gPlatformType  [lindex [lindex [get_cb_config] 0] 1]} errMsg ] } {
	    # Log errMsg message to messages file
	    logMessage $errMsg "hostview"
	    return
	}
    }

    set gMY_PLATFORM [lindex $domainName 0]
    set sysbrds [lindex $domainName 1]
    set plattype [lindex $domainName 2]
    set gPresentBoards [lindex $domainName 3]


    .f2.right2.sysbrds insert 0 $sysbrds
    #.f2.right2.sysbrds insert 0 "hello"
    .f2.right2.plat insert 0 $plattype
    .f2.right2.os insert 0 $gOs

    set cmd "domain_create"
    #set cmd "domain_create -d ${domainName}"

    #.f.right.command delete 0 end
    #.f.right.command insert 0 $cmd

    return $cmd
}
proc specDomCreBuild {} {
    global gMY_PLATFORM
    global gPresentBoards

    #set gMY_PLATFORM [eval hv_hostinfo -n]
    
    set os [ .f2.right2.os get ]
    set sysbrds [ .f2.right2.sysbrds get ]
    set plattype [ .f2.right2.plat get ]
    set domainName [ .f.right.hostname get ]

    foreach brd $sysbrds {
	    if { [lsearch $gPresentBoards $brd] < 0} {

		set msg "Board $brd is not present on this platform.\n\nDo you want to continue?"

		set result [tk_dialog .dlg_domc "Hostview Question" \
			$msg \
			questhead 1 Continue Cancel ]

		if { $result > 0 } {
		    return FAIL
		}
	    }
	}

    set cmd "domain_create -d ${domainName} -b $sysbrds -t $plattype -p $gMY_PLATFORM -o $os -q"

    if { 1 } {
	.f.right.command delete 0 end
	.f.right.command insert 0 $cmd
    }
    return $cmd
}
proc specSspLog { domainName } {
    global env

    if { $domainName == "no_domain" } {
	set domainName ""
    }
    set cmd "tail -f $env(SSPLOGGER)/${domainName}/messages"
    return $cmd
}
proc bldBringup { domainName } {
    global env

    #didn't work
    #bringup { set cmd "{cd; bringup -F}" }

    if { $domainName == "no_domain" } {
	set domainName ""
    }
    set env(SUNW_HOSTNAME) $domainName
    #cd
    set cmd "bringup"
    return $cmd
}
#
proc helpFcn {cmdArg} {
    global gHelpFlg
    set outputDest .t.text
    
    set helpCmd "man"

    switch $cmdArg {
	XsspLog { .buttonbox.help config -state disabled
		return }
	sspLog { set helpCmd menu }
	domainCreate { set helpCmd domains }
	domainRemove { set helpCmd domains }
	domainRename { set helpCmd domains }
	domainStatus { set helpCmd domains }
	domainHistory { set helpCmd domains }
	bringup { set helpCmd bringup }
	fan { set helpCmd fan }
	power { set helpCmd power }
    }


    helpTextExec $helpCmd

    #.f.right.command delete 0 end
    #.f.right.command insert 0 $helpCmd

    set gHelpFlg 1

    return ""

}

# 
# this used here and by helpText
proc abortExec {} {
    global gPid
    global gFp
    
    # if the pipe is open (tail -f) close will hang.
    #catch {close $gFp}

    if [catch {exec kill -9 [lindex $gPid 0]} ret] {
	#puts stderr "Error: $ret\nfunction: abortExec\n"
    }

    destroy .
    exit(0)
	
}

#
# generic actions
#
# exec a command
#
#
#todo: doesn't allow complex commands ie, env | grep HOST
#	tried "$comd" and ${cmd}


proc execCmdFcn {execCmd} {
    global gPid
    global gFp
    global env
    global gHelpFlg
    global gOldCursor
    global gProcName
    global gParent
    global gCat
    global recurse_depth
    global gDebugThreshold

    set recurse_depth 0
    set outputDest .t.text

    set gOldCursor [. cget -cursor]
    #set gOldCursor [.buttonbox.execute cget -cursor]

    #. config -cursor watch
    .buttonbox.execute config -cursor watch

    # read back the command box, allows user to edit the command
    set cmd [ .f.right.command get ]
    set SUNW_HOSTNAME [ .f.right.hostname get ]
    if { [string compare $SUNW_HOSTNAME "no_domain"] && [string compare $SUNW_HOSTNAME ""] } {
	set env(SUNW_HOSTNAME) $SUNW_HOSTNAME
    }
    
    # note: this has to be changed in globals to be seen here (not cmd line)
    if { $gDebugThreshold < 4 } {
	put2TextW .t.text "exec cmd: $cmd"
    }

    # redirect stderr and stdout
    if [catch {open "|$cmd |& cat"} fp1] {
	put2TextW $outputDest "Error: $fp1\n"
	debug 10 "Error: $fp1 \ncommand: $cmd\n"
	return "-1"
    }

    # non-blocking read
    fileevent $fp1 readable [list Reader $fp1]

    #put2TextW $outputDest "cmd: $cmd"



    set gPid [pid $fp1]
    set gFp $fp1
    set gParent [lindex $gPid 0]
    set gCat [lindex $gPid 1]
    set gProcName [lindex $cmd 0]

    #debug 1 "gPid: $gPid"
    #put2TextW $outputDest "gPid: $gPid"

    # disallow subsequent executions
    .buttonbox.execute configure -state disabled
    
    return ""
}

proc Reader { pipe } {
    global gOldCursor
    global gProcName

    set outputDest .t.text

    if [eof $pipe] {
	catch {close $pipe}
	. config -cursor $gOldCursor
	#.buttonbox.execute config -cursor $gOldCursor
	.buttonbox.execute configure -state normal
	.buttonbox.execute config -cursor arrow
	return
    }
    gets $pipe buff1
    put2TextW $outputDest $buff1
    put2TextW $outputDest \n

    if { 0 } {
	set fd [open /tmp/foo a]
	puts $fd "in Reader"
	close $fd
    }
 
    # bringup fires off netcon_server in the background.
    # my pipe never gets eof, leaves the cat process defunct
    # and the user cannot tell bringup is complete
    # so,
    # if bringup is gone, kill the cat.

    if { $gProcName == "bringup"} {
	#grep netcon_server
	if { [lsearch $buff1 netcon_server ] > -1 } {
	    if { 0 } {
		set fd [open /tmp/foo a]
		puts $fd "found netcon_server: [exec date]"
		close $fd
	    }

	    #20 seconds
	    after 20000 doLater
	}
    }
}
proc doLater { } {
    global gOldCursor
    global gCat
    global recurse_depth

    # is bringup complete?
    set flag [ doneyet ]
	    
    if { 0 } {
	set fd [open /tmp/foo a]
	puts $fd "the flag: $flag"
	close $fd
    }
 
    if { $flag == 0 } {
	if { 0 } {
	    set fd [open /tmp/foo a]
	    puts $fd "the flag again: $flag"
	    puts $fd "killing cat: $gCat"
	    close $fd
	}

	catch {exec kill -9 $gCat}

	. config -cursor $gOldCursor
	return
    } else {
	if { 0 } {
	    set fd [open /tmp/foo a]
	    puts $fd "$flag != 0 will incr recurse_depth: $recurse_depth"
	    close $fd
	}

	#recursion
	incr recurse_depth

	if { $recurse_depth < 5 } {
	    after 20000 doLater
	}
    }
}

proc doneyet { } {
 
    global gParent
    global gProcName

    if { 0 } {
	set fd [open /tmp/foo a]
	puts $fd "doneyet ps: [exec date]"
	close $fd
    }
 

    set temp "exec ps -ef | grep $gParent | grep $gProcName | grep -v grep"
    if { [catch {exec ps -ef | grep $gParent | grep $gProcName | grep -v grep} ps]} {
	if { 0 } {
	    set fd [open /tmp/foo a]
	    puts $fd "catch of ps $gParent $gProcName failed: ps is $ps"
	    close $fd
	}
        return 0
    }
 
    if { 0 } {
	set fd [open /tmp/foo a]
	puts $fd "temp: $temp"
	puts $fd "ps: $ps"
	close $fd
    }
 
    if { ![info exists ps] } {
	if { 0 } {
	    set fd [open /tmp/foo a]
	    puts $fd "Not info exists ps"
	    close $fd
	}
	return 0
    }
    return 1
}



#update idletasks

#
# Main
#

#if {$argc != 2} {
 #   puts stderr "Usage:execTextPopup commandArg domainName"
  #  #puts stderr "Usage:execTextPopup sspLog domainName"
   # exit
#}

#set cmdArg [lindex $argv 0]
#set domainName [lindex $argv 1]

#source ./globals
#source ./utilities
#source ./hostview_init

#genTextPopDet $cmdArg $domainName


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)genTextExec.tcl	1.16	97/02/14 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   General proc to service commands from the menu bar that use a text
#   widget to exec a command.  
#
#	menuBar:	    -command "genTextExec sspLog" -underline 0
#	menuBar:	    -command {exec $gDRdirectory/dr_board.tcl detach &}
#
# notes:
#  if user picks domain after execute button, restart window

proc genTextExec {cmdArg } {

    global gMY_PLATFORM
    global gSelectedBoard
    global gSelectedBoardList
    global gPlatformType
    global gMY_PLATFORM
    global gHV_HOME
    global env
    global gSystemBoards

    set domainName "null_domain"

    set domainName [ getSelDom ]
    debug 1 "genTextExec: cmdArg: $cmdArg domainName: $domainName"

    set flag ok
    set domNeeded 0
    set dialog .domdlg

    debug 1 "llength gSelectedBoardList:[ llength $gSelectedBoardList ]"

    if { [ llength $gSelectedBoardList ] } {
	set domNeeded 1
    }

    if { $domainName == "no_domain" || $domNeeded == 1} {
	switch $cmdArg {
	    bringup { set flag bail }
	    domainRename { 
		set flag bail 
		set cmdArg rename
	    }
	    domainRemove { 
		set flag bail
		set cmdArg removal
	    }
	}
	if { $flag == "bail" } {
	    set result [hv_tk_dialog $dialog "Hostview Warning" \
			    "One domain must be selected\n          for ${cmdArg}." \
			    warning 0 OK]
	    return
	}
	set domainName no_domain
    }

    if { [string compare $cmdArg "sspLog"] == 0 } {

	if { $domainName == "no_domain"} {
	    set dom ""
	    set msg "log file does not exist."
	} else {
	    set dom $domainName
	    set msg "log file does not exist for $domainName."
	}
	set msgfile "$env(SSPLOGGER)/${dom}/messages"

	if { [file exists $msgfile] != 1 } {
	    set result [tk_dialog .dlg_domr "Hostview Information" \
		    $msg \
		    info 0 Cancel ]

	    if { $result == 0 } {
		return
	    }
	}

    } elseif { [string compare $cmdArg "domainRemove"] == 0 } {
	set domainName [format "{{%s} {%s}}" \
			    $domainName $gMY_PLATFORM]

    } elseif { [string compare $cmdArg "domainCreate"] == 0 } {

	set gPresentBoards ""
	foreach brd $gSystemBoards {
	    set state [whatBoardState $brd]
	    if { [lsearch $state slot_loaded] > -1} {
		set gPresentBoards "$gPresentBoards $brd"
	    }
	}

	if { 0 } {
	    foreach brd "$gSelectedBoard $gSelectedBoardList" {
		set state [whatBoardState $brd]
		if { [lsearch $state slot_loaded] < 0} {


		    set msg "Board $brd is not present on this platform.\n\nDo you want to continue?"

		    set result [tk_dialog .dlg_domr "Hostview Question" \
					$msg \
				    questhead 1 Continue Cancel ]
		    
		    if { $result > 0 } {
			return
		    }
		}
	    }
	}

	set domainName [format "{{%s} {%s %s} {%s} {%s}}" \
		$gMY_PLATFORM $gSelectedBoard $gSelectedBoardList \
		$gPlatformType $gPresentBoards]
    } elseif { [string compare $cmdArg "bringup"] == 0 } {

	set msg "Hostview uses the Force option on bringup.\n\nDo you want to continue?"

		    set result [tk_dialog .dlg_domr "Hostview Information" \
			    $msg \
			    questhead 1 Continue Cancel ]

		    if { $result > 0 } {
			return
		    }
    }

    # domainName has evolved to actually contain an arg list 

    debug 1 "genTextExec: cmdArg domainName: $cmdArg $domainName"
    if [catch {exec hostview_child -t "$cmdArg $domainName" &} result] {
	debug 10 $result
    }
    #exec ${gHV_HOME}/execTextPopup $cmdArg $domainName &
}

proc helpTextExec {cmdArg } {
    global gHV_HOME

    debug 2 "helpTextExec:$cmdArg"

    switch $cmdArg {
	icon {
	    if [catch {exec hostview_child -i $cmdArg &} result] {
    		debug 10 $result
	    }
   
	    #exec ${gHV_HOME}/iconHelp $cmdArg
	    return
	}
    }
    #all other help widgets
    if [catch {exec hostview_child -m $cmdArg &} result] {
	debug 10 $result
    }
    return
}

proc eventTextExec {} {
    global gSystemFail
    global gSysFailLog
    global gHvFailLogDir
    global gFilebase

    if { ![info exists gFilebase] } {
	set result [hv_tk_dialog .dlg_fail "Hostview Information" \
                    "No Failures have been recorded." \
		    info 0 OK ]

	return
    }
    debug 2 "eventTextExec:gSystemFail: $gSystemFail $gFilebase"

    if [catch {exec hostview_child -e $gSystemFail $gHvFailLogDir/$gSysFailLog $gFilebase &} result] {
	debug 10 $result
    }
    return
}

proc netconExec {} {
    global env
    global gSelectedBoardList

    set dialog .domdlg


    set domainName [ getSelDom ]
    #set domainName [ domainOrCrayhostname ]

    if { $domainName == "no_domain" || [ llength $gSelectedBoardList ] } {
	set result [hv_tk_dialog $dialog "Hostview Warning" \
		"One domain must be selected for netcontool." \
		warning 0 OK ]
	return
    }

    set oldSunw_hostname $env(SUNW_HOSTNAME)

    if { $domainName != $oldSunw_hostname } {
	set env(SUNW_HOSTNAME) $domainName
    }

    if [catch {exec netcontool &} result] {
	debug 10 $result
    }
    set env(SUNW_HOSTNAME) $oldSunw_hostname
}

proc blEditExec { } {
    global gMY_PLATFORM
    
    debug 1 "blEditExec:gMY_PLATFORM $gMY_PLATFORM"

    if [catch {exec hostview_child -B $gMY_PLATFORM &} result] {
	debug 10 $result
    }

    return
}

#
# below only use if window is same process as hostview:
#
#proc execTextPopup {cmd_arg } {
proc xxx {cmd_arg } {
    global gFont1
    global gFont2

    debug 2 "getTextExec:$cmd_arg"

    set w .$cmd_arg

	# top level popup, but still a child of the main window
    toplevel $w
	# command to exec is the title
    wm title $w [ wtitle$cmd_arg ]

	# frame: group widgets inside frame to pos in relation
    frame $w.f
    pack $w.f -expand y -fill both

    frame $w.f.left
    pack  $w.f.left -side left

    label $w.f.left.hostname -text "Domain Name:"
    #label $w.f.left.hostname -text "SUNW_HOSTNAME:"
    label $w.f.left.command -text "Command:"
	# pack these 2 widgets, anchor east
    pack  $w.f.left.hostname $w.f.left.command -anchor e

    frame $w.f.right
    pack  $w.f.right -expand y -fill both

	# user input - one line
    entry $w.f.right.hostname -relief sunken -width 15 -font $gFont2
    entry $w.f.right.command  -relief sunken -width 60 -font $gFont2 
    	
    pack  $w.f.right.hostname $w.f.right.command -anchor w

    frame $w.t
    pack  $w.t
	# user input - scrolled multi line - text editor
    text  $w.t.text -relief groove -yscrollcommand "$w.t.yscroll set" \
	    -xscrollcommand "$w.t.xscroll set"
    scrollbar $w.t.xscroll -command "$w.t.text xview" -orient horiz
    pack $w.t.xscroll -side bottom -fill x 
    pack  $w.t.text -side left

    scrollbar $w.t.yscroll -command "$w.t.text yview"
    pack $w.t.yscroll -side right -fill y


    # get hostname and full command with cmd$cmd_arg
    $w.f.right.hostname insert 0 [ cmd$cmd_arg $w.t.text execCmd]
    $w.f.right.command insert 0 $execCmd


    frame $w.buttonbox
    pack  $w.buttonbox -expand y -fill x 

    button $w.buttonbox.execute -text execute -command "exec$cmd_arg $w"
    button $w.buttonbox.dismiss -text dismiss -command #dismissMe $w"
    button $w.buttonbox.abort   -text abort   -command abortExec
    button $w.buttonbox.help    -text help

    pack $w.buttonbox.execute $w.buttonbox.dismiss \
	 $w.buttonbox.abort   $w.buttonbox.help \
	 -side left -expand y -fill x
}

# 
# write verbage to text widget.
# 
#
proc Xput2TextW {dest verbage} {

    $dest insert end $verbage
    $dest see end
}

# return label for window in specific case (Ssp Logs)
proc XwtitlesspLog {} {
    return {Ssp Logs}
}
#
# Ssp Logs specifics: domain name and command to exec
#

proc XcmdsspLog {outputDest execCmd} {
    global gSelectedBoard
    global gSUNW_SSPLOGS

    set domain_name "null_domain"
    upvar $execCmd cmd

    if {[string length $gSelectedBoard] > 0} {
	set domain_name [ whatIsMyDomain $gSelectedBoard ]
    } else {
	#error popup would be better, window not up to write to yet.
	#put2TextW $outputDest "cmdsspLog: must select a board in domain \
		of interest"
	puts "\n\ncmdsspLog: must select a board in domain of interest\n"
    }

    set cmd "tail -f ${gSUNW_SSPLOGS}/adm/${domain_name}/messages"
    return "$domain_name"
}
# 
proc XabortExec {wname} {
    #    puts "accept:[${wname}.f.right.hostname get]"

    destroy $wname
    #destroy .cd
}

#
# non-generic actions
#
# exec "tail -f" on the ssp log for this domain.
#
#

proc XexecsspLog {wname} {
    global gSelectedBoard

    set outputDest ${wname}.t.text

    # read back the command box, allows user to edit the command
    set cmd [ ${wname}.f.right.command get ]

    #set f1 [open "| ${cmd}" r ]

    if [catch {open "|$cmd |& cat"} fp1] {
#error handling?
	puts stderr "cannot open pipe: $fp1"
	continue
    }
    fileevent $fp1 readable [list Reader $fp1]
}

proc XReader { pipe } {
    if [eof $pipe] {
	close $pipe
#	catch {close $pipe}
#	destroy .
	return
    }
    gets $pipe buff1
    put2TextW $outputDest $str1

}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***


#
# ident	"@(#)helpText.tcl	1.11	97/02/27 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   General proc to service help commands as a separate process using a text
#   widget.
#
#	exec ${gHV_HOME}/helpTextPopup $cmdArg &
#	called by: helpTextExec { cmdArg }
#	menuBar:	    -command "helpTextExec icon" -underline 0
#
# notes:
# now called from hostview_child (hvGenExec)

proc helpTextPopDet { cmdArg  } {
    global gFont2
    global gHelpFlg

    debug 2 "helpTextExec:$cmdArg"

    # this proc is invoked as a separate process.
    # the window has no parent

    wm title . "Hostview - Help"

    frame .f
    pack .f -fill x
    # pack .f   moves topic to the middle

    frame .f.left
    pack  .f.left -side left

    #Topic
    label .f.left.topic -text Topic:

    pack  .f.left.topic -ipady 10 -ipadx 10

    #pack  .t1 -ipady 10 -ipadx 10
    #text  .t1.text -relief groove -width 60 -height 10 -yscrollcommand ".t1.yscroll set"
    #pack  .t1.text -side top

    frame .t1
    pack  .t1
    # this text frame is not allowed to resize
    #pack  .t1 -expand true -fill both
    scrollbar .t1.yscroll -command ".t1.text yview"
    pack .t1.yscroll -side right -fill y


	# user input - scrolled multi line - text editor
    text  .t1.text -relief groove -yscrollcommand ".t1.yscroll set" \
	    -width 75 -height 8
    pack  .t1.text -side left -fill both

    frame .f2
    pack .f2 -fill x

    frame .f2.left2
    pack  .f2.left2 -side left
    label .f2.left2.desc -text Description:

    pack  .f2.left2.desc -ipady 10 -ipadx 10

    frame .t2
    pack  .t2 -expand y -fill both

    scrollbar .t2.xscroll -command ".t2.text xview" -orient horiz
    pack .t2.xscroll -side bottom -fill x 

    scrollbar .t2.yscroll -command ".t2.text yview"
    pack .t2.yscroll -side right -fill y


	# user input - scrolled multi line - text editor
    # height 15 matches with old hostview, 40 better for man pages
    text  .t2.text -relief groove -yscrollcommand ".t2.yscroll set" \
	    -xscrollcommand ".t2.xscroll set" -width 75 -height 30 \
	    -setgrid true
    pack  .t2.text -side left -expand y -fill both


    # display and count choices for this topic
    set nchoices [ helpChoices $cmdArg ]


    frame .buttonbox
    pack  .buttonbox -fill x 



    button .buttonbox.dismiss -text dismiss -command abortExec

    pack .buttonbox.dismiss


}

proc text2button { t start end command } {
    global textbutton

    set gFontHelp1 *-helvetica-bold-r-*-17-*

    if ![info exists textbutton(uid)] {
	set textbutton(uid) 0
    } else {
	incr textbutton(uid)
    }
    set tag button$textbutton(uid)


    $t tag configure $tag -relief ridge -borderwidth 2 -font $gFontHelp1 \
	    -offset -6

    # save the background and foreground
    set back [$t cget -bg]
    set front [$t cget -fg]

#    $t tag configure $tag -relief raised -borderwidth 2
#    if {[tk colormodel $t] == "color"} {
#	$t tag configure $tag -background thistle
#    } else {
	#$t tag configure $tag -background [$t cget -fg]
	#$t tag configure $tag -foreground [$t cget -bg]
#    }

    #bind the command to the tag
    $t tag bind $tag <Button-1> $command
    $t tag add $tag $start $end

$t tag bind $tag <Enter> "revVid $t $tag"
$t tag bind $tag <Leave> "retVid $t $tag $front $back"

    # use another tag to remember the cursor

#this didn't work, come back later

    $t tag add cursor=[$t cget -cursor] $start $end
    #$t tag bind $tag <Enter> {%W config -cursor tcross}
    #$t tag bind $tag <Leave> {text2buttonFixCursor %W  $cursor}
    #$t tag bind $tag <Leave> {text2buttonFixCursor %W}
	

}
# reverse video
proc revVid { t tag } {
    $t tag configure $tag -background [$t cget -fg]
    $t tag configure $tag -foreground [$t cget -bg]
}
# putback video
proc retVid { t tag front back} {
    $t tag configure $tag -background $back
    $t tag configure $tag -foreground $front
}
# putback cursor - regexp not matching...
proc text2buttonFixCursor { t cursor } {
    #regexp {cursor=([^ ]*)} {%W tag names} x cursor
    $t config -cursor $cursor
}


# 
# write verbage to text widget.
# 
#
proc put2TextWtop {dest verbage} {
    global gThetop

    $dest insert end $verbage
    $dest see [expr $gThetop + 10]
    #$dest see end
}
proc ins2TextW {dest verbage} {
    global gThetop

    $dest insert insert $verbage output
    $dest see $gThetop
    #$dest see end
}

#
# return label for window 
#
proc helpChoices { topic } {
    global gHV_HOME
    global env
    global gAsciiHelp_dir
    global ghelpFile
    global gPower
    global gThetop
    global gPowerHelp
    global gBringupHelp
    global gDomainHelp
    global gDrHelp
    global gBlacklistHelp
    global gMenuHelp
    global geditMenuHelp
    global gPropHelp
    global gFanHelp

    global ghelpPowerFilet
    global gPowert
    global gThetopt
    global gPowerHelpt
    global gBringupHelpt
    global gDomainHelpt
    global gDrHelpt
    global gBlacklistHelpt
    global geditMenuHelpt
    global gMenuHelpt
    global gPropHelpt
    global gFanHelpt

    set limit ""

    set t .t1.text
    set gThetop [.t1.text index end]
    
    switch $topic {
	power { 
	    set flag gPowerHelp
	}
	menu { set flag gMenuHelp }
	prop {set flag gPropHelp }
	dr { set flag gDrHelp }
	domains { set flag gDomainHelp }
	bringup { set flag gBringupHelp }
	fan { set flag gFanHelp }
	blacklist { set flag gBlacklistHelp }
	editmenu { set flag geditMenuHelp }
    }

    # later: now get alltopics (just headers), later get specifics
    # if we use the ascii text format like the prev hostview (not man command)
    set filelist [glob ${gAsciiHelp_dir}/$ghelpFile]
    foreach file $filelist {
	source $file
    }


    set limit [array size $flag]

    #need extra level of eval for array with variable name:
    #[set ${flag}($ndx)]

    for {set ndx 1 } {$ndx <= $limit} {incr ndx} {
	put2TextWtop .t1.text [set ${flag}($ndx)]
	put2TextWtop .t1.text "\n"
    }

    for {set ndx 1 } {$ndx <= $limit} {incr ndx} {
	set end [expr $ndx +1]
	
	.t1.text tag add help2 ${ndx}.0 ${end}.0
    }


    .t1.text tag configure help2 -offset -6 \
	    -font *-helvetica-bold-r-*-17-* -relief sunken -borderwidth 2

    #source ${gAsciiHelp_dir}/$ghelpFile
    #source ${gAsciiHelp_dir}/$g${topic}helpt

    for {set ndx 1 } {$ndx <= $limit} {incr ndx} {
	set end [expr $ndx +1]

	text2button .t1.text ${ndx}.0 ${end}.0 "getHelp ${topic}$ndx"
    }


    #automatically run the man page
    #getHelp power1

	if { 0 } {
    #need to send over an extra flag to know which domain man page to 
    #start up automatically
    switch $topic {
	power { 
	    getHelp power5
	}
	menu { }
	domains { }
	bringup { getHelp bringup3 }
	fan { getHelp fan1 }
    }

	}

    $t see 1.0
    #$t see $gThetop
    return $limit
}

#
# return label for window 
#
proc XhelpChoices { topic } {
    global gHV_HOME
    global ghelpPowerFile
    global gPower
    global gThetop
    set limit ""

    set gThetop [.t1.text index end]

    switch $topic {
	power { 
	    set limit 5
	    #set limit [array size gPowerHelp]
	    #put2TextWtop .t1.text "Power Man Page\n"
	    put2TextWtop .t1.text "Powering the Host\n"
	    put2TextWtop .t1.text "Setting Up Hostview's Power Command\n"
	    put2TextWtop .t1.text "Powering On or Off from Hostview\n"
	    put2TextWtop .t1.text "Margin and Trip Settings\n"


	    for {set ndx 1 } {$ndx <= $limit} {incr ndx} {
		set end [expr $ndx +1]

		.t1.text tag add help1 ${ndx}.0 ${end}.0
	    }
	    #eventually will use same tag for all
	    #.t1.text tag add help1 1.0 2.0
	    #.t1.text tag add help2 2.0 3.0
	    #.t1.text tag add help2 3.0 4.0
	    #.t1.text tag add help4 4.0 5.0

# pick one of these we like
#.t1.text tag configure help1 -underline 1
.t1.text tag configure help1 -font *-times-bold-r-*-14-* -offset -6 
.t1.text tag configure help2 -offset -6 \
-font *-helvetica-bold-r-*-17-* -relief sunken -borderwidth 2
#.t1.text tag configure help2 -relief sunken -borderwidth 20
.t1.text tag configure help3 -foreground blue -offset -6 
.t1.text tag configure help4 -relief ridge -borderwidth 2 -font *-helvetica-bold-r-*-17-* -offset -6 

# if we use the ascii text format like the prev hostview (not man command)
#source ${gHV_HOME}/$ghelpPowerFile

for {set ndx 1 } {$ndx <= $limit} {incr ndx} {
    set end [expr $ndx +1]

    text2button .t1.text ${ndx}.0 ${end}.0 "getHelp power$ndx"
}

#automatically run the man page
getHelp power1
	}
	icon { }
	menu { }
	properties { }
	dr { }
	domains { }
	bringup { }
	fan { }
    }
    return $limit
}
proc getHelp { flag } {
    #global gHV_HOME
    global gPower
    global gOldCursor
    global gThetop
    global ghelpPowerFilet
    global gPowert
    global gThetopt
    global gPowerHelpt
    global gBringupHelpt
    global gDomainHelpt
    global gDrHelpt
    global gBlacklistHelpt
    global gMenuHelpt
    global geditMenuHelpt
    global gPropHelpt
    global gFanHelpt

    global gPowerHelp
    global gBringupHelp
    global gDomainHelp
    global gDrHelp
    global gBlacklistHelp
    global gMenuHelp
    global geditMenuHelp
    global gPropHelp
    global gFanHelp

    set t .t1.text

    set gOldCursor [$t cget -cursor]
    #$t see end
    set gThetop [.t2.text index end]
#puts $gThetop
#puts $gOldCursor
    $t config -cursor watch

if { 0 } {
    #will need this, for now all are in image
    #source $env(SSPOPT)/hvHelp/${topic}.help
}

	# this is not needed for the man page method
    # tag the output widget to wrap on word bound.
    # inserts will pick up this tag, but only if some text has it.
    # no text may be there yet, so still need insert tag, not put2TextWtop
    .t2.text tag add output 1.0 end
    .t2.text tag configure output -wrap word


    switch $flag {
	power5 { 
	    #$t config -cursor watch
	    exechCmdFcn "man power"
	}
	power1 { 
	    put2TextWtop .t2.text $gPowerHelp(1)
	    underlineMe [string length $gPowerHelp(1)]
	    put2TextWtop .t2.text $gPowerHelpt(1)
	}
	power2 { 
	    put2TextWtop .t2.text $gPowerHelp(2)
	    underlineMe [string length $gPowerHelp(2)]
	    put2TextWtop .t2.text $gPowerHelpt(2)
	}
	power3 { 
	    put2TextWtop .t2.text $gPowerHelp(3)
	    underlineMe [string length $gPowerHelp(3)]
	    put2TextWtop .t2.text $gPowerHelpt(3)
	}
	power4 { 
	    put2TextWtop .t2.text $gPowerHelp(4)
	    underlineMe [string length $gPowerHelp(4)]
	    put2TextWtop .t2.text $gPowerHelpt(4)
	}
	fan1 { 
	    #$t config -cursor watch
	    exechCmdFcn "man fan"
	}
	bringup1 { 
	    put2TextWtop .t2.text $gBringupHelp(1)
	    underlineMe [string length $gBringupHelp(1)]
	    put2TextWtop .t2.text $gBringupHelpt(1)
	}
	bringup2 { 
	    put2TextWtop .t2.text $gBringupHelp(2)
	    underlineMe [string length $gBringupHelp(2)]
	    put2TextWtop .t2.text $gBringupHelpt(2)
	}
	bringup3 { 
	    exechCmdFcn "man bringup"
	}
	domains1 { 
	    put2TextWtop .t2.text $gDomainHelp(1)
	    underlineMe [string length $gDomainHelp(1)]
	    put2TextWtop .t2.text $gDomainHelpt(1)
	}
	domains2 { 
	    put2TextWtop .t2.text $gDomainHelp(2)
	    underlineMe [string length $gDomainHelp(2)]
	    put2TextWtop .t2.text $gDomainHelpt(2)
	}
	domains3 { 
	    put2TextWtop .t2.text $gDomainHelp(3)
	    underlineMe [string length $gDomainHelp(3)]
	    put2TextWtop .t2.text $gDomainHelpt(3)
	}
	domains4 { 
	    put2TextWtop .t2.text $gDomainHelp(4)
	    underlineMe [string length $gDomainHelp(4)]
	    put2TextWtop .t2.text $gDomainHelpt(4)
	}
	domains5 { 
	    put2TextWtop .t2.text $gDomainHelp(5)
	    underlineMe [string length $gDomainHelp(5)]
	    put2TextWtop .t2.text $gDomainHelpt(5)
	}
	domains6 { 
	    exechCmdFcn "man domain_create"
	}
	domains7 { 
	    exechCmdFcn "man domain_remove"
	}
	domains8 { 
	    exechCmdFcn "man domain_rename"
	}
	dr1 { 
	    put2TextWtop .t2.text $gDrHelp(1)
	    underlineMe [string length $gDrHelp(1)]
	    put2TextWtop .t2.text $gDrHelpt(1)
	}
	dr2 { 
	    put2TextWtop .t2.text $gDrHelp(2)
	    underlineMe [string length $gDrHelp(2)]
	    put2TextWtop .t2.text $gDrHelpt(2)
	}
	dr3 { 
	    put2TextWtop .t2.text $gDrHelp(3)
	    underlineMe [string length $gDrHelp(3)]
	    put2TextWtop .t2.text $gDrHelpt(3)
	}
	dr4 { 
	    put2TextWtop .t2.text $gDrHelp(4)
	    underlineMe [string length $gDrHelp(4)]
	    put2TextWtop .t2.text $gDrHelpt(4)
	}
	dr5 { 
	    put2TextWtop .t2.text $gDrHelp(5)
	    underlineMe [string length $gDrHelp(5)]
	    put2TextWtop .t2.text $gDrHelpt(5)
	}
	dr6 { 
	    put2TextWtop .t2.text $gDrHelp(6)
	    underlineMe [string length $gDrHelp(6)]
	    put2TextWtop .t2.text $gDrHelpt(6)
	}
	dr7 { 
	    put2TextWtop .t2.text $gDrHelp(7)
	    underlineMe [string length $gDrHelp(7)]
	    put2TextWtop .t2.text $gDrHelpt(7)
	}
	dr8 { 
	    put2TextWtop .t2.text $gDrHelp(8)
	    underlineMe [string length $gDrHelp(8)]
	    put2TextWtop .t2.text $gDrHelpt(8)
	}
	dr9 { 
	    put2TextWtop .t2.text $gDrHelp(9)
	    underlineMe [string length $gDrHelp(9)]
	    put2TextWtop .t2.text $gDrHelpt(9)
	}
	dr10 { 
	    put2TextWtop .t2.text $gDrHelp(10)
	    underlineMe [string length $gDrHelp(10)]
	    put2TextWtop .t2.text $gDrHelpt(10)
	}
	dr11 { 
	    put2TextWtop .t2.text $gDrHelp(11)
	    underlineMe [string length $gDrHelp(11)]
	    put2TextWtop .t2.text $gDrHelpt(11)
	}
	menu1 { 
	    put2TextWtop .t2.text $gMenuHelp(1)
	    underlineMe [string length $gMenuHelp(1)]
	    put2TextWtop .t2.text $gMenuHelpt(1)
	}
	menu2 { 
	    put2TextWtop .t2.text $gMenuHelp(2)
	    underlineMe [string length $gMenuHelp(2)]
	    put2TextWtop .t2.text $gMenuHelpt(2)
	}
	menu3 { 
	    put2TextWtop .t2.text $gMenuHelp(3)
	    underlineMe [string length $gMenuHelp(3)]
	    put2TextWtop .t2.text $gMenuHelpt(3)
	}
	menu4 { 
	    put2TextWtop .t2.text $gMenuHelp(4)
	    underlineMe [string length $gMenuHelp(4)]
	    put2TextWtop .t2.text $gMenuHelpt(4)
	}
	menu5 { 
	    put2TextWtop .t2.text $gMenuHelp(5)
	    underlineMe [string length $gMenuHelp(5)]
	    put2TextWtop .t2.text $gMenuHelpt(5)
	}
	menu6 { 
	    put2TextWtop .t2.text $gMenuHelp(6)
	    underlineMe [string length $gMenuHelp(6)]
	    put2TextWtop .t2.text $gMenuHelpt(6)
	}
	menu7 { 
	    put2TextWtop .t2.text $gMenuHelp(7)
	    underlineMe [string length $gMenuHelp(7)]
	    put2TextWtop .t2.text $gMenuHelpt(7)
	}
	menu8 { 
	    put2TextWtop .t2.text $gMenuHelp(8)
	    underlineMe [string length $gMenuHelp(8)]
	    put2TextWtop .t2.text $gMenuHelpt(8)
	}
	menu9 { 
	    put2TextWtop .t2.text $gMenuHelp(9)
	    underlineMe [string length $gMenuHelp(9)]
	    put2TextWtop .t2.text $gMenuHelpt(9)
	}
	menu10 { 
	    put2TextWtop .t2.text $gMenuHelp(10)
	    underlineMe [string length $gMenuHelp(10)]
	    put2TextWtop .t2.text $gMenuHelpt(10)
	}
	menu11 { 
	    put2TextWtop .t2.text $gMenuHelp(11)
	    underlineMe [string length $gMenuHelp(11)]
	    put2TextWtop .t2.text $gMenuHelpt(11)
	}
	menu12 { 
	    put2TextWtop .t2.text $gMenuHelp(12)
	    underlineMe [string length $gMenuHelp(12)]
	    put2TextWtop .t2.text $gMenuHelpt(12)
	}
	menu13 { 
	    put2TextWtop .t2.text $gMenuHelp(13)
	    underlineMe [string length $gMenuHelp(13)]
	    put2TextWtop .t2.text $gMenuHelpt(13)
	}
	menu14 { 
	    put2TextWtop .t2.text $gMenuHelp(14)
	    underlineMe [string length $gMenuHelp(14)]
	    put2TextWtop .t2.text $gMenuHelpt(14)
	}
	menu15 { 
	    put2TextWtop .t2.text $gMenuHelp(15)
	    underlineMe [string length $gMenuHelp(15)]
	    put2TextWtop .t2.text $gMenuHelpt(15)
	}
	menu16 { 
	    put2TextWtop .t2.text $gMenuHelp(16)
	    underlineMe [string length $gMenuHelp(16)]
	    put2TextWtop .t2.text $gMenuHelpt(16)
	}
	menu17 { 
	    put2TextWtop .t2.text $gMenuHelp(17)
	    underlineMe [string length $gMenuHelp(17)]
	    put2TextWtop .t2.text $gMenuHelpt(17)
	}
	menu18 { 
	    put2TextWtop .t2.text $gMenuHelp(18)
	    underlineMe [string length $gMenuHelp(18)]
	    put2TextWtop .t2.text $gMenuHelpt(18)
	}
	menu19 { 
	    put2TextWtop .t2.text $gMenuHelp(19)
	    underlineMe [string length $gMenuHelp(19)]
	    put2TextWtop .t2.text $gMenuHelpt(19)
	}
	menu20 { 
	    put2TextWtop .t2.text $gMenuHelp(20)
	    underlineMe [string length $gMenuHelp(20)]
	    put2TextWtop .t2.text $gMenuHelpt(20)
	}
	menu21 { 
	    put2TextWtop .t2.text $gMenuHelp(21)
	    underlineMe [string length $gMenuHelp(21)]
	    put2TextWtop .t2.text $gMenuHelpt(21)
	}
	menu22 { 
	    put2TextWtop .t2.text $gMenuHelp(22)
	    underlineMe [string length $gMenuHelp(22)]
	    put2TextWtop .t2.text $gMenuHelpt(22)
	}
	menu23 { 
	    put2TextWtop .t2.text $gMenuHelp(23)
	    underlineMe [string length $gMenuHelp(23)]
	    put2TextWtop .t2.text $gMenuHelpt(23)
	}
	menu24 { 
	    put2TextWtop .t2.text $gMenuHelp(24)
	    underlineMe [string length $gMenuHelp(24)]
	    put2TextWtop .t2.text $gMenuHelpt(24)
	}
	menu25 { 
	    put2TextWtop .t2.text $gMenuHelp(25)
	    underlineMe [string length $gMenuHelp(25)]
	    put2TextWtop .t2.text $gMenuHelpt(25)
	}
	menu26 { 
	    put2TextWtop .t2.text $gMenuHelp(26)
	    underlineMe [string length $gMenuHelp(26)]
	    put2TextWtop .t2.text $gMenuHelpt(26)
	}
	menu27 { 
	    put2TextWtop .t2.text $gMenuHelp(27)
	    underlineMe [string length $gMenuHelp(27)]
	    put2TextWtop .t2.text $gMenuHelpt(27)
	}
	prop1 { 
	    put2TextWtop .t2.text $gPropHelp(1)
	    underlineMe [string length $gPropHelp(1)]
	    put2TextWtop .t2.text $gPropHelpt(1)
	}
	blacklist1 {
	    put2TextWtop .t2.text $gBlacklistHelp(1)
	    underlineMe [string length $gBlacklistHelp(1)]
            put2TextWtop .t2.text $gBlacklistHelpt(1)
        }
        blacklist2 {
	    put2TextWtop .t2.text $gBlacklistHelp(2)
	    underlineMe [string length $gBlacklistHelp(2)]
            put2TextWtop .t2.text $gBlacklistHelpt(2)
        }
	editmenu1 {
	    put2TextWtop .t2.text $geditMenuHelp(1)
	    underlineMe [string length $geditMenuHelp(1)]
            put2TextWtop .t2.text $geditMenuHelpt(1)
        }
        editmenu2 {
	    put2TextWtop .t2.text $geditMenuHelp(2)
	    underlineMe [string length $geditMenuHelp(2)]
            put2TextWtop .t2.text $geditMenuHelpt(2)
        }
        editmenu3 {
	    put2TextWtop .t2.text $geditMenuHelp(3)
	    underlineMe [string length $geditMenuHelp(3)]
            put2TextWtop .t2.text $geditMenuHelpt(3)
        }
        editmenu4 {
	    put2TextWtop .t2.text $geditMenuHelp(4)
	    underlineMe [string length $geditMenuHelp(4)]
            put2TextWtop .t2.text $geditMenuHelpt(4)
        }
        editmenu5 {
	    put2TextWtop .t2.text $geditMenuHelp(5)
	    underlineMe [string length $geditMenuHelp(5)]
            put2TextWtop .t2.text $geditMenuHelpt(5)
        }
        editmenu6 {
	    put2TextWtop .t2.text $geditMenuHelp(6)
	    underlineMe [string length $geditMenuHelp(6)]
            put2TextWtop .t2.text $geditMenuHelpt(6)
        }
        editmenu7 {
	    put2TextWtop .t2.text $geditMenuHelp(7)
	    underlineMe [string length $geditMenuHelp(7)]
            put2TextWtop .t2.text $geditMenuHelpt(7)
        }

	
    }

    .t2.text tag add output 1.0 end
    .t2.text tag configure output -wrap word

    ins2TextW .t2.text "\n\n"
    $t config -cursor $gOldCursor

}

proc underlineMe { len } {

        set uline "========================================================================================================"

            put2TextWtop .t2.text "\n"
            set uline2 [ string range $uline 0 $len ]
            put2TextWtop .t2.text $uline2
            put2TextWtop .t2.text "\n"
            put2TextWtop .t2.text "\n"
}

#
#same proc exists in execTextPopup
#
#proc abortExec {} {
#   global gPid
#  global gFp

   # # if the pipe is open (tail -f) close will hang.
    ##catch {close $gFp}

#    if [catch {exec kill [lindex $gPid 0]} ret] {
#       #puts stderr "Error: $ret\nfunction: abortExec\n"
#  }

#    destroy .
#   exit(0)

#}

#
# generic actions
#
# exec a command
#
#
#todo: doesn't allow complex commands ie, env | grep HOST
#	tried "$comd" and ${cmd}


proc exechCmdFcn {execCmd} {
    global gPid
    global gFp
    global env
    global gHelpFlg

    set outputDest .t2.text

    # read back the command box, allows user to edit the command
    set cmd $execCmd
    #set cmd [ .f.right.command get ]
    #set CRAY_HOSTNAME [ .f.right.hostname get ]
    #set env(CRAY_HOSTNAME) $CRAY_HOSTNAME

    # redirect stderr and stdout
    if [catch {open "|$cmd |& cat"} fp1] {
	put2TextWtop $outputDest "Error: $fp1\n"
	puts stderr "Error: $fp1 \ncommand: $cmd\n"
	return "-1"
    }
    # non-blocking read
    fileevent $fp1 readable [list helpReader $fp1]

    set gPid [pid $fp1]
    set gFp $fp1

    # disallow subsequent executions (unless a help command)
    #if { $gHelpFlg != 1 } {
	#.buttonbox.execute configure -state disabled
    #} else {
	#set gHelpFlg 0
	#.f.right.command delete 0 end
	#.f.right.command insert 0 $execCmd
    #}
    return ""
}

proc helpReader { pipe } {
    global gOldCursor

    set outputDest .t2.text
    set selectW .t1.text

    if [eof $pipe] {
	#close $pipe
	catch {close $pipe}
	$selectW config -cursor $gOldCursor
	return
    }
    gets $pipe buff1

    # strip man page control sequence _\b which prints in the text widget.
    # a more general method would be better.  didn't get sed
    # working with tcl
    if { [string first "\b" $buff1] > -1 } {
	#put2TextWtop $outputDest "found b"
	set buff2 ""
	set max [string length $buff1]
	for { set i 0 } { $i < $max } { incr i } {
	    set char1 [ string index $buff1 $i ]
	    if { $char1 == "_" } {
		incr i
		set char1 [ string index $buff1 $i ]
		if { $char1 != "\b" } {
		    set buff2 ${buff2}_
		    set i [expr $i - 1]
		}
	    } else {
		set buff2 "$buff2${char1}"
	    }
	}
	put2TextWtop $outputDest $buff2

    } else {
	put2TextWtop $outputDest $buff1
    }
    put2TextWtop $outputDest \n

}


#update idletasks

#
# Main
#

#if {$argc != 1} {
#    puts stderr "Usage:helpText commandArg"
 #   exit
#}

#set cmdArg [lindex $argv 0]

#source ./globals
#source ./utilities
#source ./hostview_init

#helpTextPopDet $cmdArg


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)iconHelp.tcl	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Display icons and procossor signiture and state colors
#   in a widget.
#
#	exec ${gHV_HOME}/iconHelp $cmdArg &
#	called by: helpTextExec { cmdArg }
#	menuBar:	    -command "helpTextExec icon" -underline 0
#
#

proc helpIconPopDet { cmdArg  } {
    global gFont2
    global gBg1

    debug 2 "helpTextExec:$cmdArg"

    # this proc is invoked as a separate process.
    # the window has no parent

    wm title . "Hostview - Icon Help"

    frame .f
    #moves topic to the middle
    pack .f

    frame .f.left
    pack  .f.left -side left

    label .f.left.topic -text "Detailed Status"

    pack  .f.left.topic -ipady 10 -ipadx 10

    frame .iconBl

    iconBlock $gBg1
    pack .iconBl -side top

    frame .l1
    #moves topic to the middle
    pack .l1

    frame .l1.l1
    pack  .l1.l1 -side left

    label .l1.l1.left -text "Power Supplies"
    label .l1.l1.right -text "Temperature"

    pack  .l1.l1.left .l1.l1.right -side left -ipady 10 -ipadx 10

    frame .iconBl2

    iconBlock2 $gBg1
    pack .iconBl2 -side top


    frame .l2
    #moves topic to the middle
    pack .l2
    #pack .l2 -expand y -fill both

    frame .l2.l2
    pack  .l2.l2 -side left

    label .l2.l2.left -text "Fan"
    label .l2.l2.right -text "Events"

    pack  .l2.l2.left .l2.l2.right -side left -ipady 10 -ipadx 25


    frame .prf -borderwidth 2 -relief groove
    pack .prf

    frame .prf.f2
    #moves topic to the middle
    pack .prf.f2
    #pack .prf.f2 -expand y -fill both

    frame .prf.f2.left
    pack  .prf.f2.left -side left

    label .prf.f2.left.ind -text "Index"
    label .prf.f2.left.com -text "Combination of:"

    pack  .prf.f2.left.ind .prf.f2.left.com -side top

    for {set ndx 1} {$ndx < 8 } {incr ndx} {
	frame .prf.fp$ndx
	#pack .prf.fp$ndx
	frame .prf.fp$ndx.procStat
    }
    procBlock $gBg1
    
    for {set ndx 1} {$ndx < 8 } {incr ndx} {
	pack .prf.fp$ndx.procStat -side top -anchor w -fill x
	pack .prf.fp$ndx -side top -fill x
	#pack .prf.fp$ndx
    }    

    frame .buttonbox
    pack  .buttonbox -expand y -fill x 

    button .buttonbox.dismiss -text dismiss -command ihAbortExec
    pack .buttonbox.dismiss


}
# see iconBar
proc iconBlock { bg1 } {

    frame  .iconBl.power -relief flat -borderwidth 4 -bg $bg1
    button .iconBl.power.button -image power -bg white

    frame  .iconBl.thermal -relief flat -borderwidth 4 -bg $bg1
    button .iconBl.thermal.button -image temperature -bg white 

    #pack .iconBl.power -side left
    #pack .iconBl.thermal -side right
    pack .iconBl.power .iconBl.thermal -side left -padx 10
    pack .iconBl.power.button .iconBl.thermal.button -side top
}
proc iconBlock2 { bg1 } {

    frame  .iconBl2.fan -relief flat -borderwidth 4 -bg $bg1
    button .iconBl2.fan.button -image fan -bg white

    frame .iconBl2.event -relief flat -borderwidth 4 -bg $bg1
    button .iconBl2.event.button -image event -bg white

    pack .iconBl2.fan .iconBl2.event -side left -padx 10
    pack .iconBl2.fan.button .iconBl2.event.button
}

proc procBlock { bg1 } {
    global gHealthy

    frame  .prf.fp1.procStat.os -relief flat -width 145 -borderwidth 4
    frame  .prf.fp1.procStat.os.l
    frame  .prf.fp1.procStat.os.r
    button .prf.fp1.procStat.os.l.button -image os -bg white
    label .prf.fp1.procStat.os.l.os -text "O/S"
    label .prf.fp1.procStat.os.r.run -text "Running"
    button .prf.fp1.procStat.os.r.button2 -bg $gHealthy
    pack .prf.fp1.procStat.os.l.os .prf.fp1.procStat.os.l.button \
	    -side right -anchor w
    pack .prf.fp1.procStat.os.r.run \
	    .prf.fp1.procStat.os.r.button2 -side left -anchor w
    pack .prf.fp1.procStat.os.l -side left -padx 10
    pack .prf.fp1.procStat.os.r -side right -padx 10
    pack .prf.fp1.procStat.os -side top -fill x

    frame  .prf.fp2.procStat.post -relief flat -borderwidth 4
    frame  .prf.fp2.procStat.post.l
    frame  .prf.fp2.procStat.post.r
    button .prf.fp2.procStat.post.l.button -image post -bg white
    label .prf.fp2.procStat.post.l.post -text "POST"
    label .prf.fp2.procStat.post.r.exit -text "Exit"
    button .prf.fp2.procStat.post.r.button2 -bg maroon
    pack .prf.fp2.procStat.post.l.post .prf.fp2.procStat.post.l.button \
	    -side right
    pack .prf.fp2.procStat.post.r.exit .prf.fp2.procStat.post.r.button2 \
	    -side left -fill x -anchor e
    pack .prf.fp2.procStat.post.l -side left -padx 10
    pack .prf.fp2.procStat.post.r -side right -padx 10
    pack .prf.fp2.procStat.post -side top -fill x

    frame  .prf.fp3.procStat.dhlp -relief flat -borderwidth 4
    frame  .prf.fp3.procStat.dhlp.l
    frame  .prf.fp3.procStat.dhlp.r
    button .prf.fp3.procStat.dhlp.l.button -image dhlp -bg white
    label .prf.fp3.procStat.dhlp.l.dhlp -text "DHLP"
    label .prf.fp3.procStat.dhlp.r.prerun -text "Prerun"
    button .prf.fp3.procStat.dhlp.r.button2 -bg yellow
    pack .prf.fp3.procStat.dhlp.l.dhlp .prf.fp3.procStat.dhlp.l.button \
	    -side right
    pack .prf.fp3.procStat.dhlp.r.prerun \
	    .prf.fp3.procStat.dhlp.r.button2 -side left -anchor e -fill x
    pack .prf.fp3.procStat.dhlp.l -side left -padx 10
    pack .prf.fp3.procStat.dhlp.r -side right -padx 10
    pack .prf.fp3.procStat.dhlp -side top -fill x

    frame .prf.fp4.procStat.obp -relief flat -borderwidth 4
    frame  .prf.fp4.procStat.obp.l
    frame  .prf.fp4.procStat.obp.r
    button .prf.fp4.procStat.obp.l.button -image obp -bg white
    label .prf.fp4.procStat.obp.l.obp -text "OBP"
    label .prf.fp4.procStat.obp.r.unknown -text "Unknown"
    button .prf.fp4.procStat.obp.r.button2 -bg blue
    pack .prf.fp4.procStat.obp.l.obp .prf.fp4.procStat.obp.l.button \
	    -side right -anchor e
    pack .prf.fp4.procStat.obp.r.unknown \
	    .prf.fp4.procStat.obp.r.button2 -side left
    pack .prf.fp4.procStat.obp.l -side left -padx 10
    pack .prf.fp4.procStat.obp.r -side right -padx 10
    pack .prf.fp4.procStat.obp -fill x

    frame .prf.fp5.procStat.unk -relief flat -borderwidth 4
    frame  .prf.fp5.procStat.unk.l
    frame  .prf.fp5.procStat.unk.r
    button .prf.fp5.procStat.unk.l.button -image ques -bg white
    label .prf.fp5.procStat.unk.l.unk -text "Unknown"
    label .prf.fp5.procStat.unk.r.blk -text "Blacklisted"
    button .prf.fp5.procStat.unk.r.button2 -bg black
    pack .prf.fp5.procStat.unk.l.unk .prf.fp5.procStat.unk.l.button -side right
    pack .prf.fp5.procStat.unk.r.blk \
	    .prf.fp5.procStat.unk.r.button2 -side left
    pack .prf.fp5.procStat.unk.l -side left -padx 10
    pack .prf.fp5.procStat.unk.r -side right -padx 10
    pack .prf.fp5.procStat.unk -fill x


    frame .prf.fp6.procStat.redl -relief flat -borderwidth 4
    pack .prf.fp6.procStat.redl -side right -padx 10
    button .prf.fp6.procStat.redl.button -bg red
    label .prf.fp6.procStat.redl.redl -text "Redlisted"
    pack .prf.fp6.procStat.redl.redl .prf.fp6.procStat.redl.button \
	    -side left -anchor w 

    frame .prf.fp7.procStat.nconf -relief flat -borderwidth 4
    pack .prf.fp7.procStat.nconf -side right -padx 10
    button .prf.fp7.procStat.nconf.button -bg white
    label .prf.fp7.procStat.nconf.nconf -text "Present but not configured"
    pack .prf.fp7.procStat.nconf.nconf .prf.fp7.procStat.nconf.button \
	    -side left -anchor w


}

#
#
proc ihAbortExec {} {
    destroy .
    exit(0)

}

#
#
# Main
#

#if {$argc != 1} {
#    puts stderr "Usage:helpText commandArg"
#    exit
#}

#set cmdArg [lindex $argv 0]

#source ./globals
#source ./utilities
#source ./hostview_init
#source ./creBitmaps

#helpIconPopDet $cmdArg


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)dummy_dr_setup.tcl	1.3	96/08/26 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

proc dummy_dr_setup {cmdArg } {
    global env

    set act [lindex $cmdArg 0]
    #set act [lindex $argv 0]
    set brd [lindex $cmdArg 1]
    #set brd [lindex $argv 1]
    set domainName [lindex $cmdArg 2]
    #set domainName [lindex $argv 2]
    #set domainName2 [lindex $argv 3]
    
    # this sets domainName2 to a value if there is one (or null)
    set domainName2 [lindex $cmdArg 3]

    #cd /workspace/sw2/xfire/jcf/sspxf/src/cmd/dr/drview
    
    set env(LD_LIBRARY_PATH) /net/marvin/workspace/sw2/xfire/jcf/sspxf/proto/opt/SUNWssp/lib:/gate/sspxf/proto/opt/SUNWssp/lib:$env(LD_LIBRARY_PATH)
    #source testit
    
    exec dummy_dr $act $brd $domainName &
    # use for real dr
    #exec dummy_dr $act $brd $domainName $domainName2 &
    
    #drview attach 2 newdomain
    
    destroy .
}



#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)listUtils.tcl	1.15	97/02/14 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Primitives for list management.
#
# gFanList:
#   Set system fan speed.
#     proc updateFanSpeed {speed}
#   Set system fan failure.
#     proc updateFanFailure {fan flag} 
#   Get system fan speed.
#     proc whatFanSpeed {}
#   Get system fan failure.
#     proc whatFanFailure {}
# gBulkPowerList:
#   Set system BP conf list.
#     proc updateBPconf {BP flag}
#   Set system BP failure.
#     proc updateBPFailure {BP flag} 
#   Get system BP conf.
#     proc whatBPconf {}
#   Get system BP failure.
#     proc whatBPFailure {}
# gPowerList:
#   Given a board, flag and power values, update the list.
#     proc updatePower {board, flag, {power_vals}}
#   Given a board, index and 1 power value, update the list.
#     proc update1Power {board, index, power_val}
#   Given a board, return the list item.
#     proc whatPower {board}
# gThermalList:
#   Given a board, flag and temperatures, update the list.
#     proc updateThermal {board, flag, {temperatures}}
#   Given a board, index and 1 temperature, update the list.
#     proc update1Thermal {board, index, temperatures}
#   Given a board, return the list item.
#     proc whatTemperature {board}
# gDomains:
#   Given a domain, return a list of members.
#     proc whatDomain {color}
#   Given a domain and board, update the domain list.
#     proc updateDomain {domainName, board, add|delete}
#   Given a board, return it's domain.
#     proc whatIsMyDomain {board}
#   determine what domain is selected (if any)
#	whatDomainSelected {} {
#   return the domain or SUNW_HOSTNAME if no domain selected
#	domainOrCrayhostname
#   return the domain or no_domain if no domain selected
#	getSelDom
# gBoards:
#   Given a board id, update the state.
#     proc updateBoardList {board state}
#   Given a board id, return the state
#     proc whatBoardState {board}
#   Initialization for gBoards
#     proc setupBoardList {} 
# gProcessors:
#   Given a processor id (00..63) update the signature (empty|os|obp|post|dhlp) and state
#     proc updateProcList {procId state} 
#   Given a processor id (00..63) return the sig (empty|os|obp|post|dhlp). and state.
#     proc whatProcState {procId} 
#   Initialization for gProcessors
#     proc setupProcList {} 
# gPowered
#   add a board to the list of powered boards
#	greenPower {board}
#

#
# Set system fan speed.  Speed is off|nominal|high
#
proc updateFanSpeed {speed} {
    global gFanList

    debug 2 "updateFanSpeed:$speed"

    set gFanList [lreplace $gFanList 0 0 $speed]
}

#
# Set system fan failure. flag = fail|repair, fan = ft0a
#
proc updateFanFailure {fan flag} {
    global gFanList

    debug 2 "updateFanFailure:$fan $flag"

    set failures [lindex $gFanList 1]
    
    if {[string compare $flag fail] == 0} {
	if { [lsearch $failures $fan] == -1 } {
	    set failures "$failures $fan"
	    set gFanList [lreplace $gFanList 1 1 $failures]
	}
    } else {
	set temp1 ""
	foreach ndx $failures {
	    if {[string compare $ndx $fan] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
	set gFanList [lreplace $gFanList 1 1 $temp1]
    }
}
#
# Set system fan failure. flag = on|off, fan = ft0
# update list of fans that are powered.
#
proc updateFansPowered {fan flag} {
    global gFanList

    debug 2 "updateFansPowered:$fan $flag"

    set fanspowered [lindex $gFanList 2]
    
    if {[string compare $flag powerOn] == 0} {
	if { [lsearch $fanspowered $fan] == -1 } {
	    set fanspowered "$fanspowered $fan"
	    set gFanList [lreplace $gFanList 2 2 $fanspowered]
	}
    } else {
	set temp1 ""
	foreach ndx $fanspowered {
	    if {[string compare $ndx $fan] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
	set gFanList [lreplace $gFanList 2 2 $temp1]
    }
}
#
# Get system fan speed.
#
proc whatFanSpeed {} {
    global gFanList

    debug 2 "whatFanSpeed"

    return [lindex $gFanList 0]
}
#
# Get system fans powered list.
#
proc whatFansPowered {} {
    global gFanList

    debug 2 "whatFansPowered"

    return [lindex $gFanList 2]
}
#
#   Get system fan failure.
#
proc whatFanFailure {} {
    global gFanList
    
    debug 2 "whatFanFailure: [lindex $gFanList 1]"

    return [lindex $gFanList 1]
}
#
# Set FAN conf list
#
proc updateFanconf {FAN flag} {
    global gFanList

    debug 2 "updateFanconf:$FAN $flag"
    set fanconf [lindex $gFanList 3]

    set temp1 ""
    if { [ string compare remove $flag] == 0 } {
	foreach ndx $fanconf {
	    if {[string compare $ndx $FAN] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
    } else {
	if { [ lsearch $gFanList $FAN ] == -1 } {
	    set temp1 "$fanconf $FAN"
	}
    }
    set gFanList [lreplace $gFanList 3 3 $temp1]
}
#
# Set BP conf list
#
proc updateBPconf {BP flag} {
    global gBulkPowerList

    debug 2 "updateBpconf:$BP $flag"
    set bpconf [lindex $gBulkPowerList 0]

    set temp1 ""
    if { [ string compare remove $flag] == 0 } {
	foreach ndx $bpconf {
	    if {[string compare $ndx $BP] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
    } else {
	if { [ lsearch $gBulkPowerList $BP ] == -1 } {
	    set temp1 "$bpconf $BP"
	}
    }
    set gBulkPowerList [lreplace $gBulkPowerList 0 0 $temp1]
}

#
# Set system BP failure. flag = fail|repair
#
proc updateBPFailure {BP flag} {
    global gBulkPowerList

    debug 2 "updateBPFailure:$BP $flag"

    set failures [lindex $gBulkPowerList 1]
    
    if {[string compare $flag fail] == 0} {
	if { [lsearch $failures $BP] == -1 } {
	    set failures "$failures $BP"
	    set gBulkPowerList [lreplace $gBulkPowerList 1 1 $failures]
	}
    } else {
	set temp1 ""
	foreach ndx $failures {
	    if {[string compare $ndx $bp] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
	set gBulkPowerList [lreplace $gBulkPowerList 1 1 $temp1]
    }
}
#
# 
# update list of bps that are powered.
#
proc updateBpsPowered {bp flag} {
    global gBulkPowerList

    debug 2 "updateBpsPowered:$bp $flag"

    set bpspowered [lindex $gBulkPowerList 2]
    
    if {[string compare $flag powerOn] == 0} {
	if { [lsearch $bpspowered $bp] == -1 } {
	    set bpspowered "$bpspowered $bp"
	    set gBulkPowerList [lreplace $gBulkPowerList 2 2 $bpspowered]
	}
    } else {
	set temp1 ""
	foreach ndx $bpspowered {
	    if {[string compare $ndx $bp] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
	set gBulkPowerList [lreplace $gBulkPowerList 2 2 $temp1]
    }
}

proc updateBpsPres {bp flag} {
    global gBulkPowerList

    debug 2 "updateBpsPres:$bp $flag"

    set bpspres [lindex $gBulkPowerList 0]
    
    if {[string compare $flag slot_loaded] == 0} {
	if { [lsearch $bpspres $bp] == -1 } {
	    set bpspres "$bpspres $bp"
	    set gBulkPowerList [lreplace $gBulkPowerList 0 0 $bpspres]
	}
    } else {
	set temp1 ""
	foreach ndx $bpspres {
	    if {[string compare $ndx $bp] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
	set gBulkPowerList [lreplace $gBulkPowerList 0 0 $temp1]
    }
}

proc updateBpsFail { bp flag } {
    global gBulkPowerList

    debug 2 "updateBpsFail:$bp flag"

    set bpsfail [lindex $gBulkPowerList 1]
    
    if { [string compare $flag fail] == 0 } {
	if { [lsearch $bpsfail $bp] == -1 } {
	    set bpsfail "$bpsfail $bp"
	    set gBulkPowerList [lreplace $gBulkPowerList 1 1 $bpsfail]
	}
    } else {
	if { [lsearch $bpsfail $bp] > -1 } {
	    set temp1 ""
	    foreach ndx $bpsfail {
		if {[string compare $ndx $bp] != 0} {
		    set temp1 "$temp1 $ndx"
		}
	    }
	    set gBulkPowerList [lreplace $gBulkPowerList 1 1 $temp1]
	}
    }
}

#
# Get system bp conf
#
proc whatBPconf {} {
    global gBulkPowerList

    debug 2 "whatBpconf"

    return [lindex $gBulkPowerList 0]
}
#
# Get system bps powered list.
#
proc whatBpsPowered {} {
    global gBulkPowerList

    debug 2 "whatBpsPowered"

    return [lindex $gBulkPowerList 2]
}
#
#   Get system bp failure.
#
proc whatBpFailure {} {
    global gBulkPowerList
    
    debug 2 "whatBpFailure"

    return [lindex $gBulkPowerList 1]
}

proc updateBusList { bus flag } {
    global gBusUp

    debug 2 "updateBusList:$bus flag"

    if { [string compare $flag up] == 0 } {
	if { [lsearch $gBusUp $bus] == -1 } {
	    set gBusUp "$gBusUp $bus"
	}
    } else {
	if { [lsearch $gBusUp $bus] > -1 } {
	    set temp1 ""
	    foreach ndx $gBusUp {
		if {[string compare $ndx $bus] != 0} {
		    set temp1 "$temp1 $ndx"
		}
	    }
	    set gBusUp $temp1
	}
    }
}



#
# Update an entry in gPowerList
#
proc updatePower {board flag pwr_vals} {
    global gPowerList

    debug 2 "updatePower:$board $flag $pwr_vals"

    set new_stuff "$board $flag {$pwr_vals}"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gPowerList $board*]

    if {$ndx < 0} {
	set gPowerList "$gPowerList {$new_stuff}"
    } else {
	set gPowerList [lreplace $gPowerList $ndx $ndx $new_stuff]
    }
}
#
# Return a entry in gPowerList
#
proc whatPower {board} {
    global gPowerList
    debug 2 "whatPower:$board"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gPowerList $board*]

    if {$ndx < 0} {
	return ""
    } else {
	return [lindex $gPowerList $ndx]
    }
}
#
# remove entry in power list
#
proc delPower {board} {
    global gPowerList
    debug 2 "delPower:$board"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gPowerList $board*]

    if {$ndx < 0} {
	return ""
    } else {
	set gPowerList [ lreplace $gPowerList $ndx $ndx ]
    }
}

#
# Update an entry in gPowerList
#
proc update1Power {board ndx pwr_val} {
    global gPowerList
    global gDebugThreshold

    debug 2 "update1Power:$board $ndx $pwr_val"

    set pwrList [whatPower $board]
    if { ![llength $pwrList ]} {
	#read the mib
	hv_hostinfo -p
	return
    }
    set flag [lindex $pwrList 1]
    set pwrs [lindex $pwrList 2]
    #1 0 {{4.0 4.1 4.2 4.3 4.4} {}}
    #cb0 0 {{4.0 4.1 4.2 4.3 4.4} {}}
    #csb0 0 {{4.0 4.1 3.0} {}}
    # no longer used: ctr 0 {{10 20 30} {}}

    set s0 [llength [lindex $pwrs 0 ]]
    set s1 [llength [lindex $pwrs 1 ]]
    set s2 [llength [lindex $pwrs 2 ]]
    if { $ndx < $s0 } {
	set pwr [lindex $pwrs 0 ]
	#set pwr [lindex [lindex $pwrList 2] 0 ]

	set temp [lindex $pwr $ndx]
	if { [ string compare $temp ""] == 0 } {
	    set message "board: $board pwrList: $pwrList gPowerList: $gPowerList"
	    logMessage $message "Hostview: error: "
	    exec echo $message > /var/tmp/junk.mari.mari
	    if { 0 } {
	    exec mail mari@mar.west.sun.com < /var/tmp/junk.mari.mari
	    }
	    if { $gDebugThreshold < 4 } {
		set result [hv_tk_dialog .fileerr "Hostview Error" \
				"$message" \
				warning 0 OK]
	    }

	    return
	}

	set newpwr [lreplace $pwr $ndx $ndx $pwr_val]
	set pwrs [lreplace $pwrs 0 0 $newpwr]
    } elseif { $ndx < [expr $s0 + $s1] } {
	set pwr [lindex [lindex $pwrList 2] 1 ]
	set ndx [expr $ndx - $s0]
	set newpwr [lreplace $pwr $ndx $ndx $pwr_val]
	set pwrs [lreplace $pwrs 1 1 $newpwr]
    } else {
	set pwr [lindex [lindex $pwrList 2] 2 ]
	set ndx [expr $ndx - $s0 - $s1]
	set newpwr [lreplace $pwr $ndx $ndx $pwr_val]
	set pwrs [lreplace $pwrs 2 2 $newpwr]
    }
    updatePower $board $flag $pwrs

}
#
#
# add a board to the list of powered boards
# this may only be used by ctr and bulk power
proc greenPower {board} {
    global gPowered

    debug 2 "greenPower:$board"
	if { [string compare $board bp1] == 0 } {
		set match "bp1 "
	} else {
		set match $board
	}

    set ndx [lsearch -glob $gPowered $match*]

    if {$ndx < 0} {
	set gPowered "$gPowered $board"
    }
}
proc brownPower {board} {
    global gPowered

    debug 2 "greenPower:$board"
    if { [string compare $board bp1] == 0 } {
	set match "bp1 "
    } else {
	set match $board
    }

    set ndx [lsearch -glob $gPowered $match*]
    
    if {$ndx >= 0} {
	set temp1 ""
	foreach ndx $gPowered {
	    if {[string compare $ndx $board] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}

	set gPowered $temp1
    }
}

#
# Update an entry in gThermalList
#
proc updateThermal {board flag temperatures} {
    global gThermalList

    debug 2 "updateThermal:$board $flag $temperatures"

    set new_stuff "$board $flag {$temperatures}"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gThermalList $board*]

    if {$ndx < 0} {
	set gThermalList "$gThermalList {$new_stuff}"
    } else {
	set gThermalList [lreplace $gThermalList $ndx $ndx $new_stuff]
    }
}

#
# Update an entry in gThermalList
#
proc update1Thermal {board ndx temperature} {
    global gThermalList

    debug 2 "update1Thermal:$board $ndx $temperature"

    set tempList [whatTemperature $board]
    if { ![llength $tempList ]} {
	#read the mib
	hv_hostinfo -t
	return
    }
    set flag [lindex $tempList 1]
    set temps [lindex $tempList 2]
    #1 0 {{21 21 21 21 21} {43 50 34} {52 57 53 53}}
    #cb0 0 {{0. 0. 0.} {0. 0. 0.}}
    #csb0 0 {32 32}
    #ctr 0 {{24 24 24 24 24 24 24 24 24 24 } {24 24 24 24 24 24 24 24 24 24 }}

    set s0 [llength [lindex $temps 0 ]]
    set s1 [llength [lindex $temps 1 ]]
    set s2 [llength [lindex $temps 2 ]]
    if { $ndx < $s0 } {
	set temp [lindex [lindex $tempList 2] 0 ]
	set newtemp [lreplace $temp $ndx $ndx $temperature]
	set temps [lreplace $temps 0 0 $newtemp]
    } elseif { $ndx < [expr $s0 + $s1] } {
	set temp [lindex [lindex $tempList 2] 1 ]
	set ndx [expr $ndx - $s0]
	set newtemp [lreplace $temp $ndx $ndx $temperature]
	set temps [lreplace $temps 1 1 $newtemp]
    } else {
	set temp [lindex [lindex $tempList 2] 2 ]
	set ndx [expr $ndx - $s0 - $s1]
	set newtemp [lreplace $temp $ndx $ndx $temperature]
	set temps [lreplace $temps 2 2 $newtemp]
    }
    updateThermal $board $flag $temps

}
#
# Return a entry in gThermalList
#
proc whatTemperature {board} {
    global gThermalList
    debug 2 "whatTemperature:$board"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gThermalList $board*]

    if {$ndx < 0} {
	return ""
    } else {
	return [lindex $gThermalList $ndx]
    }
}

#
# Remove an entry in gThermalList
#
proc delTemperature {board} {
    global gThermalList
    debug 2 "delTemperature:$board"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gThermalList $board*]

    if {$ndx < 0} {
	return ""
    } else {
	set gThermalList [ lreplace $gThermalList $ndx $ndx ]
    }
}


#
# Given a domain, return a list of members.
#
proc whatDomain {domainName} {
    global gDomains

    debug 2 "whatDomain:$domainName"

    set ndx [domainIndex $domainName ]
    if { $ndx < 0 } {
	return ""
    } else {
	set temp1 [lindex $gDomains $ndx]
	set temp2 [lindex $temp1 1]
	return $temp2
    }
}
#
# check domain exists, return the index
# 
#
proc domainIndex { domainName } {
    global gDomains

    set ndx [lsearch -glob $gDomains $domainName*]

    if { $ndx >= 0 } {
	set limit [ llength $gDomains ]
	while { $ndx < $limit } {
	    # make sure it's an exact match
	    if { [lsearch  [lindex $gDomains $ndx ] $domainName] >= 0 } {
		break
	    }
	    set ndx [expr $ndx + 1]
	}
	if { $ndx == $limit } {
	    set ndx -1
	}
    }
    return $ndx

}
# use to match into a 1 level nested list
proc exactMatch { theList item  } {

    set ndx [lsearch -glob $theList $item*]

    if { $ndx >= 0 } {
	set limit [ llength $theList ]
	while { $ndx < $limit } {
	    # make sure it's an exact match
	    if { [lsearch  [lindex $theList $ndx ] $item] >= 0 } {
		break
	    }
	    set ndx [expr $ndx + 1]
	}
	if { $ndx == $limit } {
	    set ndx -1
	}
    }
    return $ndx

}

#
# Given a domain, return it's color
#
proc whatColorDomain {domainName} {
    global gDomains
    global gDomainColorMap
    global gDomainColors

    debug 2 "whatColorDomain:$domainName"

    set ndx [domainIndex $domainName ]
    if { $ndx < 0 } {
	return ""
    }

    set cindx 0
    foreach color $gDomainColorMap {
	if { $color == $ndx } {
	    break
	}
	set cindx [expr $cindx + 1]
    }
    set color [lindex $gDomainColors $cindx]

    return $color
}

#
# Given a domain and board, update the domain list.
#
proc updateDomain {domainName board option} {
    global gDomains

    debug 2 "updateDomain:$domainName $board $option"

    set ndx [domainIndex $domainName ]
    #set ndx [lsearch -glob $gDomains $domainName*]

    if {[string compare $option add] == 0} {
	if {$ndx < 0} {
	    set gDomains "$gDomains {$domainName {$board}}"
	} else {
	    set temp1 [lindex $gDomains $ndx]
	    set temp2 [lindex $temp1 1]
	    set temp3 "$temp2 $board"
	    set gDomains [lreplace $gDomains $ndx $ndx "$domainName {$temp3}"]
	}
    } else {
	if {$ndx >= 0} {
	    set temp1 [lindex $gDomains $ndx]
	    set temp2 [lindex $temp1 1]
	    set temp3 ""

	    foreach ndx2 $temp2 {
		if {[lsearch $board $ndx2] < 0} {
		    set temp3 "$temp3 $ndx2"
		} 
	    }
	    set gDomains [lreplace $gDomains $ndx $ndx "$domainName {$temp3}"]
	}
    }
}

#
# Given a board, return it's domain.
#
proc whatIsMyDomain {board} {
    global gBoards

    debug 2 "whatIsMyDomain:$board"

	# gBoard List, looks like {b0 domain power loaded}

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gBoards $board*]

    if {$ndx < 0} {
	return ""
    } else {
	set temp1 [lindex $gBoards $ndx]
	set temp2 [lindex $temp1 1]
	return $temp2
    }
}

#
# determine what, if any, domain is selected
#
proc whatDomainSelected {} {
    global gBoards
    global gSelectedBoard

    debug 2 "whatDomainSelected:$gSelectedBoard"

	# gBoard List, looks like {0 domain power_on slot_loaded}

	if { [string compare $gSelectedBoard 1] == 0 } {
		set board "1 "
	} else {
		set board $gSelectedBoard
	}
	if {[string length $gSelectedBoard] < 1} {
		set ndx -1
	} else {
    		set ndx [lsearch -glob $gBoards $board*]
	}

    if {$ndx < 0} {
	return ""
    } else {
	set temp1 [lindex $gBoards $ndx]
	set temp2 [lindex $temp1 1]
	return $temp2
    }
}
#
# determine what, if any, domain is selected
# return domain, if exists, or SUNW_HOSTNAME
# 
#
proc domainOrCrayhostname {} {
	global env
	global gSelectedBoard
	set domain ""

    debug 2 "domainOrCrayhostname:$gSelectedBoard"

	set domain [ whatDomainSelected ]
	debug 1 "domain: $domain"
	if {[string length $domain] > 0} {
		return $domain
	} else {
		return $env(SUNW_HOSTNAME)
	}
}
#
# determine what, if any, domain is selected
# return domain, if exists, or no_domain
# 
#
proc getSelDom {} {
	global env
	global gSelectedBoard
	set domain ""

    debug 2 "getSelDom:$gSelectedBoard"

	set domain [ whatDomainSelected ]
	debug 1 "domain: $domain"
	if {[string length $domain] > 0} {
		return $domain
	} else {
		return "no_domain"
	}
}

#
# Given a board id, update the state.
#
proc updateBoardList {board state} {
    global gBoards

    debug 2 "updateBoardList:$board $state"

	if { [string compare $board 1] == 0 } {
		set match "1 "
	} else {
		set match $board
	}
    set ndx [lsearch -glob $gBoards $match*]
    
    if {$ndx < 0} {
	debug 5 "updateBoardList search failure for:$board"
    } else {
	set gBoards [lreplace $gBoards $ndx $ndx "$board $state"]
    }
}

#
# Given a board id, return the state.
#
proc whatBoardState {board} {
    global gBoards

    debug 2 "whatBoardState:$board"

	if { [string compare $board 1] == 0 } {
		set match "1 "
	} else {
		set match $board
	}
    set ndx [lsearch -glob $gBoards $match*]

    if {$ndx < 0} {
	debug 5 "whatBoardState search failure:$board"
	return empty
    }

    set result [lindex $gBoards $ndx]
    return $result
}

#
# Initialization for gBoards
#
proc setupBoardList {} {
    global gBoards

    global gCenterBoards
    global gFrontBoards
    global gBackBoards

    debug 1 "setupBoardList"

    foreach board $gCenterBoards {
	set gBoards "$gBoards {$board no_domain power_off slot_loaded}"
    }

    set config "no_domain power_off slot_empty jtag_off clock_off"
    foreach board $gFrontBoards {
	set gBoards "$gBoards {$board $config}"
    }

    foreach board $gBackBoards {
	set gBoards "$gBoards {$board $config}"
    }
}

#
# Given a processor id (00..63) update the signature (empty|os|obp|post|dhlp)
#   and state (color).
#
proc updateProcList {procId signature color} {
    global gProcessors

    debug 2 "updateProcList:$procId $signature $color"

    set ndx [lsearch -glob $gProcessors $procId*]
    
    if {$ndx < 0} {
	debug 5 "updateProcList search failure for:$procId"
    } else {
	set gProcessors [lreplace $gProcessors $ndx $ndx "$procId {$signature $color}"]
    }
}

#
# Given a processor id (00..63) return the signature (empty|os|obp|post|dhlp)
#   and color.
# actually it's the signiture and state.
#
proc whatProcState {procId} {
    global gProcessors

    debug 2 "whatProcState:$procId"

    set ndx [lsearch -glob $gProcessors $procId*]

    if {$ndx < 0} {
	debug 5 "whatProcState search failure:$procId"
	return empty
    }

    set result [lindex $gProcessors $ndx]
    return [lindex $result 1]
}

#
# Initialization for gProcessors
#
proc setupProcList {} {
    global gProcessors

    debug 1 "setupProcList"

    for {set ndx 0} {$ndx < 64} {incr ndx} {
	if {$ndx < 10} {
	    set gProcessors "$gProcessors {0$ndx {empty empty}}"
	} else {
	    set gProcessors "$gProcessors {$ndx {empty empty}}"
	}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)menuBar.tcl	1.13	97/02/27 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Create and populate the menu bar on the main window of HostView.
#
# Entry:
#   bg1 = background color.
#
# Exit:
#   Nothing.
#

proc menuBar {bg1} {
    global gDebugThreshold
    global env

    #
    # File Command and Options
    #
    menubutton .menuBar.file -text File -menu .menuBar.file.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.file.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.file.m add command -label "SSP Logs" \
	    -command "genTextExec sspLog"
    .menuBar.file.m add command -label "Quit" \
	    -command topKill

    #
    # Edit Command and Options
    #
    menubutton .menuBar.edit -text Edit -menu .menuBar.edit.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.edit.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.edit.m add command -label "Properties" \
	    -command properties -state disabled
    .menuBar.edit.m add command -label "Blacklist File" \
	    -command blEditExec

    #
    # Control Command and Options
    #
    menubutton .menuBar.control -text Control -menu .menuBar.control.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.control.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.control.m add command -label "Power" \
	    -command "genTextExec power"
    .menuBar.control.m add command -label "Bringup" \
	    -command "genTextExec bringup"
    .menuBar.control.m add command -label "Fan" \
	    -command "genTextExec fan"

    #
    # Configuration Command and Options
    #
    menubutton .menuBar.configuration -text Configuration \
	    -menu .menuBar.configuration.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.configuration.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.configuration.m add cascade -label "Board" \
	    -menu .menuBar.configuration.m.board

    menu .menuBar.configuration.m.board -tearoff 0
    .menuBar.configuration.m.board add command -label "Attach" \
	    -command {drSelectionsPopDet attach }
    .menuBar.configuration.m.board add command -label "Detach" \
	    -command {drSelectionsPopDet detach }

    .menuBar.configuration.m add cascade -label "Domain" \
	    -menu .menuBar.configuration.m.domain

    menu .menuBar.configuration.m.domain -tearoff 0
    .menuBar.configuration.m.domain add command -label "Create" \
	    -command "genTextExec domainCreate"
    .menuBar.configuration.m.domain add command -label "Remove" \
	    -command "genTextExec domainRemove"
    .menuBar.configuration.m.domain add command -label "Rename" \
	    -command "genTextExec domainRename"
    .menuBar.configuration.m.domain add command -label "Status" \
	    -command "genTextExec domainStatus"
    .menuBar.configuration.m.domain add command -label "History" \
	    -command "genTextExec domainHistory"
    #
    # Terminal Command and Options
    #
    menubutton .menuBar.terminal -text Terminal -menu .menuBar.terminal.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.terminal.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.terminal.m add command -label "netcontool" \
	    -command netconExec
    .menuBar.terminal.m add cascade -label "SSP" \
	    -menu .menuBar.terminal.m.ssp

	menu .menuBar.terminal.m.ssp -tearoff 0

# uname -n gives current host, but hostview could be client, so
# will need to find out ssp host: .sspprivate/ssp_to_domain and get the host
# or MIB: cbStarfireHostName?
#xlsfonts | grep fixed
    .menuBar.terminal.m.ssp add command -label "xterm" \
	    -command "exec xterm -e rlogin [exec uname -n] &"
	    #-command "exec xterm -e rlogin [exec uname -n] &" -underline 0
	    #-command "exec xterm -fn \'-misc-fixed-bold-r-normal--14-130-75-75-c-70-iso8859-1\' -e rlogin [exec uname -n] &" -underline 0

.menuBar.terminal.m.ssp add command -label "cmdtool" \
	    -command "exec cmdtool rlogin [exec uname -n] &"
.menuBar.terminal.m.ssp add command -label "shelltool" \
	    -command "exec shelltool rlogin [exec uname -n] &"

    .menuBar.terminal.m add cascade -label "rlogin" \
	    -menu .menuBar.terminal.m.rlogin
menu .menuBar.terminal.m.rlogin -tearoff 0

    .menuBar.terminal.m.rlogin add command -label "xterm" \
	    -command "rloginExec xterm"
    .menuBar.terminal.m.rlogin add command -label "cmdtool" \
	    -command "rloginExec cmdtool"
    .menuBar.terminal.m.rlogin add command -label "shelltool" \
	    -command "rloginExec shelltool"


if { $gDebugThreshold  < 4 } {
    .menuBar.terminal.m add cascade -label "test" \
	    -menu .menuBar.terminal.m.test
menu .menuBar.terminal.m.test -tearoff 0

    .menuBar.terminal.m.test add command -label "probe" \
	    -command script0 -underline 0
    .menuBar.terminal.m.test add command -label "power up" \
	    -command script1 -underline 0
    .menuBar.terminal.m.test add command -label "SysBoards" \
	    -command script1a -underline 0
    .menuBar.terminal.m.test add command -label "p,power,Sysbds" \
	    -command "script0; script1; script1a" -underline 0
    .menuBar.terminal.m.test add command -label "HiTemps" \
	    -command script2 -underline 0
    .menuBar.terminal.m.test add command -label "NormTemps" \
	    -command script3 -underline 0
    .menuBar.terminal.m.test add command -label "NukeBoards" \
	    -command script4 -underline 0
    .menuBar.terminal.m.test add command -label "RestBoards" \
	    -command script5 -underline 0
    .menuBar.terminal.m.test add command -label "HiFans" \
	    -command script8 -underline 0
    .menuBar.terminal.m.test add command -label "lists" \
	    -command diag_script -underline 0
    .menuBar.terminal.m.test add command -label "inactivate domains" \
	    -command inactivate_domains -underline 0
    .menuBar.terminal.m.test add command -label "hvDrviewUp 0" \
	    -command "hvDrviewUp 0 drviewup" -underline 0
.menuBar.terminal.m.test add command -label "rmDomain" \
	    -command "dom_test" -underline 0
if { 1 } {
    .menuBar.terminal.m.test add command -label "rm_b0" \
	    -command "rmBfromDomain b0 orange" -underline 0
} else {
    .menuBar.terminal.m.test add command -label "rm_b5" \
            -command "rmBfromDomain b5 sspproto5" -underline 0
}

}
    #
    # View Command and Options
    #
    menubutton .menuBar.view -text View -menu .menuBar.view.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.view.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.view.m add command -label "All Domains" \
	    -command "setDomainView all"
    .menuBar.view.m add command -label "Shared Memory" \
	    -command "buttonStub" -state disabled

    #
    # Failure Event Command and Options
    #
    menubutton .menuBar.failure -text Failure -menu .menuBar.failure.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

	#don't use this anymore, use failure icon
    menu .menuBar.failure.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.failure.m add command -label "power supply" \
	    -command buttonStub -underline 0
    .menuBar.failure.m add command -label "system board" \
	    -command buttonStub -underline 0
    .menuBar.failure.m add command -label "processor" \
	    -command buttonStub -underline 0
    .menuBar.failure.m add command -label "system fault" \
	    -command buttonStub -underline 0

    #
    # Help Command and Options
    #
    menubutton .menuBar.help -text Help -menu .menuBar.help.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.help.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.help.m add command -label "On Icon" \
	    -command "helpTextExec icon"
    .menuBar.help.m add command -label "On Menu" \
	    -command "helpTextExec menu"
    .menuBar.help.m add command -label "On Properties" \
	    -command "helpTextExec prop"
    .menuBar.help.m add command -label "On Power" \
	    -command "helpTextExec power"
    .menuBar.help.m add command -label "On DR" \
	    -command "helpTextExec dr"
    .menuBar.help.m add command -label "On Domains" \
	    -command "helpTextExec domains"
    .menuBar.help.m add command -label "On Bringup" \
	    -command "helpTextExec bringup"
    .menuBar.help.m add command -label "On Fan" \
	    -command "helpTextExec fan"
    .menuBar.help.m add command -label "On blacklist" \
	    -command "helpTextExec blacklist"
    .menuBar.help.m add command -label "On edit" \
	    -command "helpTextExec editmenu"

    #
    # Realize menuBar
    #
    pack .menuBar.file .menuBar.edit .menuBar.control .menuBar.configuration\
	    .menuBar.terminal .menuBar.view -side left 

	# pack .menuBar.file .menuBar.edit .menuBar.control \
		.menuBar.configuration\
	    .menuBar.terminal .menuBar.view .menuBar.failure  -side left 

    pack .menuBar.help -side right
}



proc BlMenuBar {bg1} {
    global env
    global gBg1
    global gFg1

    #
    # File Command and Options
    #
    menubutton .blMenuBar.file -text File -menu .blMenuBar.file.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .blMenuBar.file.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .blMenuBar.file.m add command -label "New" \
	-command newBlacklist

    .blMenuBar.file.m add command -label "Open ..." \
	-command "" -state disabled
    .blMenuBar.file.m add command -label "Save" \
	-command "appendblacklist" -state disabled
    .blMenuBar.file.m add command -label "SaveAs ..." \
	-command "" -state disabled
    .blMenuBar.file.m add command -label "Print" \
	-command "printBlacklist"  -state disabled
    .blMenuBar.file.m add command -label "Close" \
	    -command "closeBLgui"

    #
    # View Command and Options
    #
    menubutton .blMenuBar.view -text View -menu .blMenuBar.view.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .blMenuBar.view.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .blMenuBar.view.m add command -label "Boards" \
	    -command "blklistGraphic boardView $gBg1 $gFg1"
    .blMenuBar.view.m add command -label "Processors" \
	    -command "blklistGraphic procView $gBg1 $gFg1"
    .blMenuBar.view.m add cascade -label "Detail Board" \
	-menu .blMenuBar.view.m.detailBoard

    menu .blMenuBar.view.m.detailBoard -tearoff 0

    .blMenuBar.view.m.detailBoard add command -label "0" \
	    -command ""  -state disabled
    .blMenuBar.view.m.detailBoard add command -label "1" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "2" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "3" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "4" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "5" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "6" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "7" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "8" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "9" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "10" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "11" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "12" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "13" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "14" \
	    -command "" -state disabled
    .blMenuBar.view.m.detailBoard add command -label "15" \
	    -command "" -state disabled

    
    #
    # Help Command and Options
    #
    menubutton .blMenuBar.help -text Help -menu .blMenuBar.help.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .blMenuBar.help.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .blMenuBar.help.m add command -label "On Menu" \
	    -command "helpTextExec editmenu"
    .blMenuBar.help.m add command -label "On Blacklist" \
	    -command "helpTextExec blacklist"

    #
    # Realize blMenuBar
    #
    pack .blMenuBar.file .blMenuBar.view -side left 

    pack .blMenuBar.help -side right

}


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)mibRefresh.tcl	1.3	97/01/10 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#	Periodically read the Mib and refresh popup windows
#	which are present
#
# 
#


proc KillMelater {mypid } {
    global gPidMibFresh

    if ![info exists gPidMibFresh] {
	set gPidMibFresh $mypid
    }
    debug 1 "gPidMibFresh: $gPidMibFresh"
}
proc MIBfresh {} {
global gNewWin

    debug 1 "MIBfresh"

    set t 0
    set p 0
    set f 0
    set children [winfo children .]

    foreach child $children {
	if {[lsearch $child *hermal* ] > -1 } {
	    set t 1
	} elseif {[lsearch $child *ower* ] > -1 } {
	    set p 1
	} elseif {[lsearch $child *fanDetail* ] > -1 } {
	    set f 1
	} elseif {[lsearch $child *wFan* ] > -1 } {
	    set f 1
	}
    }
    if { $t } {
	set gNewWin 0
	hv_hostinfo -t
    }
    if { $p } {
	set gNewWin 0
	hv_hostinfo -p
    }
    if { $f} {
	set gNewWin 0
	hv_hostinfo -f
    }
    return
}

# refreshmib is exec-ed (via hostview_child)
# it loops forever, and invokes mibFresh periodically.
#
proc refreshMib { hostviewName pollfreq} {
    global gHvName
    debug 1 "refreshMib: $pollfreq  $hostviewName"

    if { [string first # $hostviewName] > -1 } {
	set gHvName [split $hostviewName #]
	set gHvName [lreplace $gHvName 1 1 #[lindex $gHvName 1]]
	debug 1 "gHvName $gHvName"
    } else {
	set gHvName $hostviewName
    }
    set mypid [pid]
    if { [ catch {send $gHvName KillMelater $mypid} errmsg ] } {
	debug 4 "Error: $errmsg"
    }

    while { 1 } {
	sleep $pollfreq
	sendMsg1
    }

}
proc sendMsg1 {} {
    global gHvName

    debug 1 "sendMsg1: $gHvName"
    #set retstatus [send $dest]

    if { [ catch {send $gHvName MIBfresh} errmsg ] } {
	debug 4 "Error: $errmsg"
    }
}

proc countDetails { flag } {

    debug 1 "countDetails $flag"

    set t 0
    set p 0
    set f 0
    set children [winfo children .]

    foreach child $children {
	if {[lsearch $child *hermal* ] > -1 } {
	    incr t
	} elseif {[lsearch $child *ower* ] > -1 } {
	    incr p
	} elseif {[lsearch $child *fanDetail* ] > -1 } {
	    incr f
	} elseif {[lsearch $child *wFan* ] > -1 } {
	    incr f
	}
    }
    switch $flag {
	"power" { return $p }
	"thermal" { return $t }
	"fan" { return $f }
    }
}

proc countWin {} {

    set count 0

    set children [winfo children .]

    foreach child $children {
	if {[lsearch $child *hermal* ] > -1 } {
	    incr count
	} elseif {[lsearch $child *ower* ] > -1 } {
	    incr count
	} elseif {[lsearch $child *fanDetail* ] > -1 } {
	    incr count
	} elseif {[lsearch $child *wFan* ] > -1 } {
	    incr count
	}
    }
    debug 1 "count win: $count"
    return $count
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)nameUtils.tcl	1.7	97/02/18 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   This file contains routines which assist in building widget strings.
#
# Boards:
#   proc whatBoard {arg} returns board ID from path
#   proc boardPath {arg} given board ID returns path
#
# Processors:
#   proc whatProc {arg} returns system board ID from processor ID.
#   proc procPath {arg} returns widget path to arg.
#   proc procList {board} returns list of processors on a system board.
#
# System Detail:
#   proc path2sd {arg} returns item name from path.
#   proc sd2path {arg} returns widget path to arg 
#

#
# Given a processor string, return the board id
# args is complete path to board, returns board in form b0, b1.
# args is complete path to board, returns board in form 0, 1.
#
proc whatBoard {arg} {
    debug 1 "whatBoard:$arg"

    set temp2 [split $arg .]

    set ndx1 [lsearch $temp2 power]

    if {$ndx1 >= 0} {
	incr ndx1
    } else {
	set ndx1 1
	while (1) {
	    if {[string compare cards [lindex $temp2 $ndx1]]} {
		incr ndx1
	    } else {
		incr ndx1
		if {[string compare special [lindex $temp2 $ndx1]]} {
		} else {
		    incr ndx1
		}
		break;
	    }
	}
    }
    return [lindex $temp2 $ndx1]
}

#
# Given a board name, return the associated path.
# arg has the form b0..b15
# arg has the form 0..15
#
proc boardPath {arg} {
    debug 1 "boardPath:$arg"

    set blw .blklistGraphic
    #set blw .blklistGraphic.box

    switch $arg {
	csb0 {return .systemGraphic.front.cards.csb0}
	csb1 {return .systemGraphic.back.cards.csb1}

	cb0 {return .systemGraphic.front.cards.cb0}
	cb1 {return .systemGraphic.back.cards.cb1}

	0  {return .systemGraphic.front.cards.0}
	1  {return .systemGraphic.front.cards.1}
	2  {return .systemGraphic.front.cards.2}
	3  {return .systemGraphic.front.cards.3}
	4  {return .systemGraphic.front.cards.4}
	5  {return .systemGraphic.front.cards.5}
	6  {return .systemGraphic.front.cards.6}
	7  {return .systemGraphic.front.cards.7}

	8  {return .systemGraphic.back.cards.8}
	9  {return .systemGraphic.back.cards.9}
	10 {return .systemGraphic.back.cards.10}
	11 {return .systemGraphic.back.cards.11}
	12 {return .systemGraphic.back.cards.12}
	13 {return .systemGraphic.back.cards.13}
	14 {return .systemGraphic.back.cards.14}
	15 {return .systemGraphic.back.cards.15}

	bl_csb0 {return $blw.front.cards.csb0}
	bl_csb1 {return $blw.back.cards.csb1}

	bl_cb0 {return $blw.front.cards.cb0}
	bl_cb1 {return $blw.back.cards.cb1}

	bl_0  {return $blw.front.cards.0}
	bl_1  {return $blw.front.cards.1}
	bl_2  {return $blw.front.cards.2}
	bl_3  {return $blw.front.cards.3}
	bl_4  {return $blw.front.cards.4}
	bl_5  {return $blw.front.cards.5}
	bl_6  {return $blw.front.cards.6}
	bl_7  {return $blw.front.cards.7}

	bl_8  {return $blw.back.cards.8}
	bl_9  {return $blw.back.cards.9}
	bl_10 {return $blw.back.cards.10}
	bl_11 {return $blw.back.cards.11}
	bl_12 {return $blw.back.cards.12}
	bl_13 {return $blw.back.cards.13}
	bl_14 {return $blw.back.cards.14}
	bl_15 {return $blw.back.cards.15}

	default {debug 5 "==>SWITCH DEFAULT in boardPath:$arg"}
    }
}

#
# Given a processor id, return the associated system board.
# arg has the form 0..63, returns b0..b15
# arg has the form 0..63, returns 0..15
#
proc whatProc {arg} {
    debug 1 "whatProc:$arg"

    # Leading zero is a problem...
    set temp2 [string trimleft $arg 0]
    if {[string length $temp2] < 1} {
	set temp2 0
    } 

    set temp1 [expr $temp2/4]
    return "$temp1"
    #return "b$temp1"
}

#
# Given a processor id, return the associated path.
# arg has the form 0..63
#
proc procPath {arg} {
    debug 1 "procPath:$arg"

    set board [whatProc $arg]
    set temp1 [boardPath $board]

    if {$arg < 10} {
	set cell "0$arg"
    } else {
	set cell $arg
    }

    return "$temp1.select.domain.board.$cell"
}

#
# Given a board, return a list of processor cells.
# List is arranged as "top down" respective to the GUI.
# board = board ID in the form b0..b15
# board = board ID in the form 0..15
#
proc procList {board} {
    global gFrontSysBoards

    debug 1 "procList:$board"

    set temp1 [string trim $board bl_]
    set temp1 [string trim $temp1 b]

#    debug 1 "I know this is card:$temp1"

    set retarg {}

    if {[lsearch $gFrontSysBoards $board] < 0} {
	set cell_limit [expr (1+$temp1)*4]

	for {set cell [expr $temp1*4]} {$cell < $cell_limit} {incr cell} {
	    set retarg [concat $retarg $cell]
	}
    } else {
	set cell_limit [expr $temp1*4]
	incr temp1

	for {set cell [expr $temp1*4-1]} {$cell >=$cell_limit} {incr cell -1} {
	    if {$cell < 10} {
		set retarg [concat $retarg 0$cell]
	    } else {
		set retarg [concat $retarg $cell]
	    }
	}
    }
    debug 1 "retarg:$retarg"
    return $retarg
}

#
# Return the object identifier from a systemDetail path.
#
proc path2sd {arg} {
    global gBackBoards
    global gFrontBoards

    global gBulkPower
    global gFanDrawers

    debug 1 "path2sd:$arg"

    set temp1 [split $arg .]

    foreach ndx1 $temp1 {
	if {[string compare ctr $ndx1] == 0} {
	    return ctr
	} else {
	    set ndx2 [lsearch $gFrontBoards $ndx1]
	    if {$ndx2 >= 0} {
		return $ndx1
	    }
	    set ndx2 [lsearch $gBackBoards $ndx1]
	    if {$ndx2 >= 0} {
		return $ndx1
	    }
	    set ndx2 [lsearch $gFanDrawers $ndx1]
	    if {$ndx2 >= 0} {
		return $ndx1
	    }
	    set ndx2 [lsearch $gBulkPower $ndx1]
	    if {$ndx2 >= 0} {
		return $ndx1
	    }
	}
    }
    debug 5 "path2sd unknown item:$arg"
}

#
# Given a object name return a path usefile for the systemDetail template.
#
proc sd2path {arg} {
    debug 1 "sd2path:$arg"

    switch $arg {
	ctr {return .canvas.sub2.center.bottom.cards.ctr}

	bp0 {return .canvas.sub2.front.top.power.bp0}
	bp1 {return .canvas.sub2.front.top.power.bp1}
	bp2 {return .canvas.sub2.front.top.power.bp2}
	bp3 {return .canvas.sub2.front.top.power.bp3}
	bp4 {return .canvas.sub2.back.top.power.bp4}
	bp5 {return .canvas.sub2.back.top.power.bp5}
	bp6 {return .canvas.sub2.back.top.power.bp6}
	bp7 {return .canvas.sub2.back.top.power.bp7}

	csb0 {return .canvas.sub2.front.bottom.cards.special.csb0}
	cb0 {return .canvas.sub2.front.bottom.cards.special.cb0}

	csb1 {return .canvas.sub2.back.bottom.cards.special.csb1}
	cb1 {return .canvas.sub2.back.bottom.cards.special.cb1}

	0  {return .canvas.sub2.front.bottom.cards.0}
	1  {return .canvas.sub2.front.bottom.cards.1}
	2  {return .canvas.sub2.front.bottom.cards.2}
	3  {return .canvas.sub2.front.bottom.cards.3}
	4  {return .canvas.sub2.front.bottom.cards.4}
	5  {return .canvas.sub2.front.bottom.cards.5}
	6  {return .canvas.sub2.front.bottom.cards.6}
	7  {return .canvas.sub2.front.bottom.cards.7}

	8  {return .canvas.sub2.back.bottom.cards.8}
	9  {return .canvas.sub2.back.bottom.cards.9}
	10 {return .canvas.sub2.back.bottom.cards.10}
	11 {return .canvas.sub2.back.bottom.cards.11}
	12 {return .canvas.sub2.back.bottom.cards.12}
	13 {return .canvas.sub2.back.bottom.cards.13}
	14 {return .canvas.sub2.back.bottom.cards.14}
	15 {return .canvas.sub2.back.bottom.cards.15}

	ft0  {return .canvas.sub2.front.bottom.topfan.ft0}
	ft1  {return .canvas.sub2.front.bottom.topfan.ft1}
	ft2  {return .canvas.sub2.front.bottom.topfan.ft2}
	ft3  {return .canvas.sub2.front.bottom.topfan.ft3}
	ft4  {return .canvas.sub2.front.bottom.botfan.ft4}
	ft5  {return .canvas.sub2.front.bottom.botfan.ft5}
	ft6  {return .canvas.sub2.front.bottom.botfan.ft6}
	ft7  {return .canvas.sub2.front.bottom.botfan.ft7}

	ft8  {return .canvas.sub2.back.bottom.topfan.ft8}
	ft9  {return .canvas.sub2.back.bottom.topfan.ft9}
	ft10 {return .canvas.sub2.back.bottom.topfan.ft10}
	ft11 {return .canvas.sub2.back.bottom.topfan.ft11}
	ft12 {return .canvas.sub2.back.bottom.botfan.ft12}
	ft13 {return .canvas.sub2.back.bottom.botfan.ft13}
	ft14 {return .canvas.sub2.back.bottom.botfan.ft14}
	ft15 {return .canvas.sub2.back.bottom.botfan.ft15}

	default {debug 5 "==>SWITCH DEFAULT in sd2path:$arg"}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)stale.tcl	1.8	97/01/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#	Periodically read the Mib and popup window
#	if MIB does not respond.
#
# notes:
# if snmp answers, destroy popup if it exists.
# if snmp doesn't answer, leave popup or create popup.
# snmp gets $retries tries to answer.
#


proc staleState {} {
    global gMibTouched
    global testfail
    global gDebugThreshold
    global staleStateTest

    debug 1 "staleState"

    set dialog .dlg

    set platform [eval hv_hostinfo -n]

    #after does not work as desired here, and sleep would hang hostview
    if { 0 } {
	set retries 3
	set retrytime 1000; #milliseconds
	for { set i 0} { $i < $retries } {incr i} {
	    if { [string compare $platform ""] == 0 } {
		after $retrytime "set platform [eval hv_hostinfo -n]"
	    } else {
		break
	    }
	}
    }

    #for testing
    if { [info exists staleStateTest] } {
	incr testfail
	if { [expr $testfail % 5] == 0} {
	    set platform ""
	}
    }
  
    #
    #may want to change warning bitmap to error bitmap

    if { [string compare $platform ""] != 0 } {
	if [winfo exists $dialog] {
	    destroy $dialog
	}
    } else {
	if ![winfo exists $dialog] {
	    set result [hv_tk_dialog $dialog "Hostview Warning" \
		    "Stale state.  No response from SNMP manager." \
		    warning 0 OK Cancel]
	}
    }
    set gMibTouched 0
    return
}
proc MIBmonitor {} {

    debug 1 "MIBmonitor"
    set act [eval wasMIBtouched]
    if { $act } {
	staleState
    } else {
	if [winfo exists .dlg] {
	    destroy .dlg
	}
    }
    return
}
proc wasMIBtouched {} {
    global gMibTouched
    
    if { $gMibTouched } {
	set gMibTouched 0
	return 0
    } 
    return 1
}

# staleDriver is exec-ed (via hostview_child)
# it loops forever, and invokes staleState periodically.
#
proc staleDriver { hostviewName pollfreq } {
    global gHvName

    debug 1 "staleDriver: $pollfreq  $hostviewName"

    if { [string first # $hostviewName] > -1 } {
	set gHvName [split $hostviewName #]
	set gHvName [lreplace $gHvName 1 1 #[lindex $gHvName 1]]
	debug 1 "gHvName $gHvName"
    } else {
	set gHvName $hostviewName
    }
    #destroy .

    while { 1 } {
	sleep $pollfreq
	sendMsg
    }

}
proc sendMsg {} {
    global gHvName

    debug 1 "sendMsg:$gHvName"
    #set retstatus [send $dest]
	debug 4 "mib poll event"
    if { [ catch {send $gHvName MIBmonitor} errmsg ] } {
	debug 4 "Error: $errmsg"
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)sysGraphUtils.tcl	1.21	97/02/18 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Supporting routines for the systemGraphic display.
#
# Update a processor icon:
#   proc updateProcIcon {procid symbol}
#   proc getImage { signiture }
#
# Make a support board visible:
#   proc visibleSB {target bg1 fg1}
#
# Make a "grayed out" support board.
#   proc grayedSB {target bg1 fg1}
#
# Make a control board visible:
#   proc visibleCB {target bg1 fg1}
#
# Make a "grayed out" control board.
#   proc grayedCB {target bg1 fg1}
#
# Make a system board visible:
#   proc visibleSys {target bg1 fg1}
#
# Make a "grayed out" system board:
#   proc grayedSys {target bg1 fg1}
#
# Make a system board invisible:
#   proc invisibleSys {target bg1 fg1 procStateFlag}
#
# Set a Control Board to provide JTAG
#   proc visibleJtag {target bg1 fg1}
#
# Set a Control Board to provide clock
#   proc visibleClock {target bg1 fg1}
#
# Select a board on the main GUI (Button 1 event).
#   proc boardSelect {arg}
#
# Set a buss state (color)
#   proc bussState {buss bg1 fg1}
#
# Set a domain color
#   proc setBoardDomainColor {board color}
#

# Update a processor icon.
# procid = processor id in the range 0..63
#
proc updateProcIcon {procid} {
    debug 2 "updateProcIcon:$procid"

    set target [procPath $procid]
    set target "$target.icon"

    set temp1 [whatProcState $procid]
    
    set symbol [getImage [lindex $temp1 0]]
    set color  [iconRunColor [lindex $temp1 1]]

    $target configure -image $symbol -bg $color
}
proc getImage { signiture } {

    switch $signiture {
	"download-helper" { set signiture dhlp }
	"open-boot-prom"  { set signiture obp }
	"power-on-selftest" { set signiture post }
	"operating-system" { set signiture os }
	"dummy"		{ set signiture dummy }
	"empty"		{ set signiture dummy }
	"none"		{ set signiture dummy }
	"unknown"	{ set signiture ques }
    }
    switch $signiture {
	dhlp {}
	obp {}
	post {}
	os {}
	ques {}
	dummy {}
	default {
	    debug 5 "==>SWITCH DEFAULT in getImage:$signiture"
	    set signiture ques
	}
    }
    return $signiture
}
#
# Make a support board (sb0, sb1) visible.  Establish bindings.
# Make a support board (csb0, csb1) visible.  Establish bindings.
# target = csb0, csb1
#
proc visibleSB {target bg1 fg1} {
    debug 1 "visibleSB:$target $bg1 $fg1"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -bg $bg1 -relief groove
    #$winboard configure -bg blue -relief groove
    $winboard.board configure -bg $bg1 -relief raised
    #$winboard.board configure -bg blue -relief raised

    #bind $winboard.board.cell <Button-1> {boardSelect %W}
    bind $winboard.board.cell <Button-3> {detailPopup %W}

    #bind $winboard.board.cell.id <Button-1> {boardSelect %W}
    bind $winboard.board.cell.id <Button-3> {detailPopup %W}

    #bind $winboard.board.cell <Button-2> {boardSelectTog %W}
    #bind $winboard.board.cell.id <Button-2> {boardSelectTog %W}
}

proc invisibleSB {target bg1 fg1} {
    debug 1 "invisibleSB:$target"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    bind $winboard.board.cell <Button-1> ""
    bind $winboard.board.cell <Button-2> ""
    bind $winboard.board.cell <Button-3> ""

    bind $winboard.board.cell.id <Button-1> ""
    bind $winboard.board.cell.id <Button-2> ""
    bind $winboard.board.cell.id <Button-3> ""
}

#
# Draw a present, but powered down support board
#
proc grayedSB {target bg1 fg1} {
    debug 1 "grayedSB:$target"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    bind $winboard.board.cell <Button-1> {boardSelect %W}
    bind $winboard.board.cell.id <Button-1> {boardSelect %W}
    bind $winboard.board.cell <Button-2> {boardSelectTog %W}
    bind $winboard.board.cell.id <Button-2> {boardSelectTog %W}
}

#
# Make a control board (cb0, cb1) visible.  Establish bindings.
# target = cb0, cb1
#
proc visibleCB {target bg1 fg1} {
    debug 1 "visibleCB:$target $bg1 $fg1"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -bg $bg1 -relief groove
    $winboard.board configure -bg $bg1 -relief raised
    #$winboard configure -bg blue -relief groove
    #$winboard.board configure -bg blue -relief raised

    bind $winboard.board.cell <Button-3> {detailPopup %W}
    bind $winboard.board.cell.jtag <Button-3> {detailPopup %W}
    bind $winboard.board.cell.clock <Button-3> {detailPopup %W}
}
proc invisibleCB {target bg1 fg1} {
    debug 1 "invisibleCB:$target"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    bind $winboard.board.cell <Button-1> ""
    bind $winboard.board.cell <Button-3> ""

    bind $winboard.board.cell.jtag <Button-1> ""
    bind $winboard.board.cell.jtag <Button-3> ""

    bind $winboard.board.cell.clock <Button-1> ""
    bind $winboard.board.cell.clock <Button-3> ""

    setClock $target off
    setJtag $target off
}
#
# Draw a present, but powered down control board
#
proc grayedCB {target bg1 fg1} {
    debug 1 "grayedCB:$target"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    #bind $winboard.board.cell <Button-1> {boardSelect %W}
    #bind $winboard.board.cell.jtag <Button-1> {boardSelect %W}
    #bind $winboard.board.cell.clock <Button-1> {boardSelect %W}

}

#
# Make a system board visible.  Establish bindings.
# target = b0..b15
#
proc visibleSys {target bg1 fg1} {
    debug 1 "visibleSys:$target bg: $bg1 fg: $fg1"
    global gBg1

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -bg grey -relief flat
    #$winboard configure -bg $bg1 -relief flat
    $winboard.board configure -bg $bg1 -relief raised
    #$winboard.board configure -bg blue -relief raised

    #
    # If this board has a domain affiliation, color it in.
    #

	set target [string trim $target bl_]

    set temp1 [whatBoardState $target]
    set domain [lindex $temp1 1]
    if {[string compare "no_domain" $domain] != 0} {
	set color [whatColorDomain  $domain ]
	setBoardDomainColor $target $color
    }

    set cells [procList $target]

    foreach cell $cells {
	set temp1 [procPath $cell]
	$temp1.id configure -fg $fg1

	set cell_temp [whatProcState $cell]
	set cell_state [lindex $cell_temp 0]
	set symbol [getImage $cell_state]
	set cell_color [iconRunColor [lindex $cell_temp 1]]
	
	$temp1.icon configure -image $symbol -bg $cell_color

	pack $temp1.id 	$temp1.icon -side left

	#bind $temp1      <Button-2> {boardSelect %W}
	#bind $temp1
	#Error: no event type or button # or keysym
	#bind $temp1      <Shift><Button-1> {boardSelect %W}

	if { 0 } {
	    bind $temp1      <Button-1> {boardSelect %W}
	    bind $temp1.id   <Button-1> {boardSelect %W}
	    bind $temp1.icon <Button-1> {boardSelect %W}

	    bind $temp1	<Button-2> {boardSelectTog %W}
	    bind $temp1.id	<Button-2> {boardSelectTog %W}
	    bind $temp1.icon	<Button-2> {boardSelectTog %W}
	}

	bind $temp1      <Button-3> {detailPopup %W}
	bind $temp1.id   <Button-3> {detailPopup %W}
	bind $temp1.icon <Button-3> {detailPopup %W}
    }
}

#
# Create a present, but not powered board.
#
proc grayedSys {target bg1 fg1} {
    debug 1 "grayedSys:$target $bg1 $fg1"

#result is null
    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    set cells [procList $target]

    foreach cell $cells {
	set temp1 [procPath $cell]

	bind $temp1      <Button-1> {boardSelect %W}
	bind $temp1.id   <Button-1> {boardSelect %W}
	bind $temp1.icon <Button-1> {boardSelect %W}

	bind $temp1	<Button-2> {boardSelectTog %W}
	bind $temp1.id	<Button-2> {boardSelectTog %W}
	bind $temp1.icon	<Button-2> {boardSelectTog %W}
    }

}

#
# Make a system board invisible.
# target = b0..b15, bg1 = background color, fg1 = text color
#
proc invisibleSys {target bg1 fg1 procStateFlag } {
    debug 3 "invisibleSys:$target  procStateFlag  $procStateFlag"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    set cells [procList $target]

    foreach cell $cells {
	set temp1 [procPath $cell]

	bind $temp1 <Button-1> ""
	bind $temp1 <Button-2> ""
	bind $temp1 <Button-3> ""

	bind $temp1.id <Button-1> ""
	bind $temp1.id <Button-2> ""
	bind $temp1.id <Button-3> ""

	bind $temp1.icon <Button-1> ""
	bind $temp1.icon <Button-2> ""
	bind $temp1.icon <Button-3> ""

	$temp1.id configure -fg $bg1
	$temp1.icon configure -image dummy -bg $bg1 -highlightbackground $bg1
	if { [string compare $procStateFlag "update"] == 0 } {
	    updateProcList $cell empty empty
	}
    }
}

#
# This CB supplies JTAG.
# target = cb0, cb1
#
proc visibleJtag {target bg1 fg1} {
    debug 1 "visibleJtag:$target"

    set winboard [boardPath $target]
    set winboard $winboard.select.domain.board.cell.jtag
    $winboard configure -foreground $fg1 
}
#
# This CB supplies JTAG.
# target = cb0, cb1
#
proc invisibleJtag {target bg1 fg1} {
    debug 1 "invisibleJtag:$target"

    set winboard [boardPath $target]
    set winboard $winboard.select.domain.board.cell.jtag
    $winboard configure -relief flat -bg $bg1 -fg $fg1
}

#
# This CB supplies clock
# target = cb0, cb1
#
proc visibleClock {target bg1 fg1} {
    debug 1 "visibleClock:$target"

    set winboard [boardPath $target]
    set winboard $winboard.select.domain.board.cell.clock
    $winboard configure -foreground $fg1 
}
#
# This CB supplies clock
# target = cb0, cb1
#
proc invisibleClock {target bg1 fg1} {
    debug 1 "invisibleClock:$target"

    set winboard [boardPath $target]
    set winboard $winboard.select.domain.board.cell.clock
    $winboard configure -relief flat -bg $bg1 -fg $fg1
}

#
# Operator has pressed button 1 on a board
# This event is enabled via binding.
#
proc boardSelect {arg} {
    global gBg1
    global gBackBoards
    global gFrontBoards

    global gSelectedBoard
    global gSelectedBoardList

    debug 1 "boardSelect from:$arg"


    foreach board $gSelectedBoardList {
	    set result [boardPath $board]
	    $result.select configure -bg $gBg1
    }
    set gSelectedBoardList ""

    #
    # Reset the selection frame
    #
    if {[string length $gSelectedBoard] > 0} {
	set result [boardPath $gSelectedBoard]
	$result.select configure -bg $gBg1
    }

    #
    # Build a path to the select frame and color it.
    #
    set temp1 [whatBoard $arg]
    set temp2 [boardPath $temp1]
    set temp3 "$temp2.select"

    set gSelectedBoard $temp1

    $temp3 configure -bg black

    debug 1 "1: gSelectedBoardList: $gSelectedBoardList theSelectedB: $temp1 gSelectedBoard: $gSelectedBoard"


}


#
# Operator has pressed button 2 on a board
# toggle selection of this board.
# This event is enabled via binding.
# arg can be full path to board, or just the board # 
#
proc boardSelectTog {arg} {
    global gBg1
    global gBackBoards
    global gFrontBoards

    global gSelectedBoard
    global gSelectedBoardList

    debug 1 "boardSelectTog from:$arg"


    # if it is gselectedboard, turn it off and promote one of the others
    # if there are any.

    #
    # Build a path to the select frame and color it.
    #
    if { [ string length $arg ] < 5 } {
	# a board number
	set temp1 $arg
    } else {
	#full path
	set temp1 [whatBoard $arg]
    }
    set temp2 [boardPath $temp1]
    set temp3 "$temp2.select"

    set theSelectedB $temp1
    debug 1 "1: gSelectedBoardList: $gSelectedBoardList theSelectedB: $theSelectedB"

    #
    # Reset the selection frame
    #
    set ndx [lsearch $gSelectedBoardList $theSelectedB ]
    if { $ndx > -1 } {

	#toggle this board from selected to deselected.

	#set gSelectedBoardList [lreplace $gSelectedBoardList $ndx $ndx ""]

	set temp1 ""
	set cnt 0
	foreach board $gSelectedBoardList {
	    if { $cnt != $ndx } {
		set temp1 "$temp1 [lindex $gSelectedBoardList $cnt]"
	    }
	    incr cnt
	}
	set gSelectedBoardList $temp1

	set result [boardPath $theSelectedB]
	$result.select configure -bg $gBg1
    } elseif { [string compare $theSelectedB $gSelectedBoard] == 0 } {

	# it was selected by button-1 before
	
	if { [llength $gSelectedBoardList] > 0 } {
	    # promote one or set to null
	    set gSelectedBoard [lindex $gSelectedBoardList 0]

	    set len [llength $gSelectedBoardList]
	    set temp1 ""
	    for { set i 1 } { $i < $len } { incr i} {
		debug 1 "temp1: $temp1"
		set temp1 "$temp1 [lindex $gSelectedBoardList $i]"
	    }
	    set gSelectedBoardList $temp1
	} else {
	    # promote one or set to null
	    set gSelectedBoard ""
	}

	set result [boardPath $theSelectedB]
	$result.select configure -bg $gBg1

    } else {
	#toggle this board to selected.

	if { [string compare $gSelectedBoard ""] == 0 } {
	    set gSelectedBoard $theSelectedB
	} else {
	    set gSelectedBoardList "$gSelectedBoardList $theSelectedB"
	}

	$temp3 configure -bg black
    }
    debug 1 "2: gSelectedBoardList: $gSelectedBoardList theSelectedB: $theSelectedB gSelectedBoard: $gSelectedBoard"
}



#
# Return a background color for a processor icon.
#
proc iconRunColor {arg} {
    global gBg1

    debug 2 "iconRunColor:$arg"

    switch $arg {
	blacklist {return Black}
	exit      {return Maroon}
	prerun    {return Yellow2}
	present   {return White}
	redlist   {return Red}
	running   {return green3}
	run	  {return green3}
	unknown   {return Blue2}
	dummy	{return $gBg1}
	empty	{return $gBg1}

	default {
	    debug 5 "==>SWITCH DEFAULT in iconRunColor:$arg"
	    return Blue2
	}
    }
}

#
# Set a running buss.
#
proc greenBus {buss} {
    global gHealthy

    debug 1 "greenBbuss:$buss"

    set candidate ".systemGraphic.buss.$buss.id"
    $candidate configure -bg $gHealthy

    updateBusList $buss up
}
#
# turn off a  buss.
#
proc grayBus {buss} {
    global gGrey

    debug 1 "grayBuss:$buss"

    set candidate ".systemGraphic.buss.$buss.id"
    $candidate configure -bg $gGrey

    updateBusList $buss down
}
#
# Color the domain frame
# board in the form b0, b1, etc.
#
proc setBoardDomainColor {board color} {
    debug 1 "setBoardDomainColor:$board $color"

    set temp1 [boardPath $board]
    set temp2 "$temp1.select.domain"

    $temp2 configure -bg $color
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)writeBlacklist.tcl	1.8	97/02/20 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   blacklist file handling
#
#
proc initBLstate { blacklistfile } {

    global gBLdata
    global gBLinitdata

    global gBusInput
    global gBusChanged
    global gCplaneInput

    set gBusInput 0
    set gBusChanged 0
    set gCplaneInput 0

    debug 1 "initBLstate:  $blacklistfile"
    

    if { ![file readable $blacklistfile] } {
	set gBLdata ""
	set gBLinitdata ""
	debug 1 "initBLstate:  not readable: $blacklistfile"
	return 0
    }

    if { [ catch {set ret [open_blacklist $blacklistfile]} errmsg ] } {
            debug 10 "Error opening blacklist: $errmsg"
            return -1
    }

    if { [ catch {set gBLdata [ parse_blacklist ]} errmsg ] } {
            debug 10 "Error parsing blacklist: $errmsg"
            return -1
    }
    if { [ catch {set ret [close_blacklist $blacklistfile]} errmsg ] } {
            debug 10 "Error closing blacklist: $errmsg"
            return -1
    }

    set gBLinitdata $gBLdata

    return 1

}
proc appendblacklist { } {
    global gBLdata
    global gBLinitdata
    global gSelected
    global gSelectedList
    global gBlacklistfile
    global gBLchanged


    set bltok "sysbd proc abus dbus ioc scard mem mgroup mlimit cplane pc xdb cic ldpath"
    

    if { 0 } {
	# gBLdata $gBLinitdata may not exist
	# if nothing was changed, leave the file alone
	if { [string compare $gBLdata $gBLinitdata] } {
	    return 0
	}
    }

    # comment out the existing file
    set ret [commentBlacklist]
    
    if { [file writable $gBlacklistfile] } {
        if { [ catch {set fileId [ open $gBlacklistfile r+ 0600]} errmsg ] } {
            debug 10 "Error opening blacklist file: $errmsg"
            return
        }
	if { ![info exists gFilebase] } {
            set gFilebase [file size $gBlacklistfile]
        }

    } else {
        if { ![info exists gFilebase] } {
            set gFilebase 0
        }
        if { [ catch {set fileId [ open $gBlacklistfile w 0600]} errmsg ] } {
            debug 10 "Error opening blacklist file: $errmsg"
            return
        }
    }

    # hostview syntax is different from blacklist
    # hostview procs are 12, 13 and blacklist is 3.0, 3.1
    # also buses.
    # and cplane map to buses
    hv2blDecode


    seek $fileId 0 end
    set junk [tell $fileId]
    debug 1 "tell: $junk"

    set tday [exec date]

    puts $fileId "\n\#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+"
    puts $fileId "\#Blacklist file edited by Hostview - $tday"
    puts $fileId "\#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+"

    foreach tok $bltok {
	if { [info exists gSelected($tok)] } {
	    debug 1 "tok: $tok"
	    if { [llength $gSelected($tok)] } {
		set temp "$tok $gSelected($tok)"
		debug 1 "tok: $tok"
	    }
	}
	if { [info exists gSelectedList($tok)] } {
	    if { [llength $gSelectedList($tok)] } {
		foreach elem $gSelectedList($tok) {
		    set temp "$temp $elem"
		}
		debug 1 "tok: $tok"
	    }
	}
	if { [info exists temp] } {
	    puts $fileId "$temp"
	    unset temp
	}
    }

    puts $fileId "\n\#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="
    puts $fileId "\#End Hostview Edit - $tday"
    puts $fileId "\#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="

    close $fileId

    # put the procs back in hostview terms in case user wants to edit further.
    hv2blPutBack

    # reset flag
    set gBLchanged 0
    .blMenuBar.file.m entryconfigure 2 -state disabled
    .blMenuBar.file.m entryconfigure 4 -state disabled

}

#### come back to cplane

proc decodeBlklist { } {
    global gBLdata

    global gSelected
    global gSelectedList

    global gOrigTokOrder
    global gBusInput
    global gBusChanged
    global gCplaneInput

    #set gBusInput 0
    #set gBusChanged 0
    #set gCplaneInput 0

    set gOrigTokOrder ""

    debug 1 "decodeBlklist: gBLdata: $gBLdata"

    foreach elem $gBLdata {
	set tok [lindex $elem 0]
	switch $tok {
	    sysbd {
		genericDecode $elem
	    }
	    proc {
		set ndx 0
		set last [expr [llength $elem] -1]
		foreach x $elem {
		    if { $ndx == $last} {
			continue
		    }
		    if { $ndx != 0 } {
			set temp1 [split $x .]
			set proc [expr [expr [lindex $temp1 0] * 4] + [lindex $temp1 1]]
			if {$proc < 10} {
			    set proc "0$proc"
			}
			if { ![info exists gSelected(proc)] } {
			    set gSelected(proc) $proc
			} else {
			    if { [lsearch $gSelectedList(proc) $proc] == -1 && [lsearch $gSelected(proc) $proc] == -1 } {
				set gSelectedList(proc) "$gSelectedList(proc) $proc"
			    }
			}
		    }
		    incr ndx
		}
		set gOrigTokOrder "$gOrigTokOrder $tok"
		debug 1 "gSelected(proc): $gSelected(proc) gSelectedList(proc): $gSelectedList(proc)"
	    }
	    abus {
		set gBusInput 1
		set ndx 0
		set last [expr [llength $elem] -1]
		foreach x $elem {
		    # ignore comment for now
		    if { $ndx == $last} {
			continue
		    }
		    if { $ndx != 0 } {
			if { ![info exists gSelected(bus)] } {
			    set gSelected(bus) abus$x
			} else {
			    if { [lsearch $gSelectedList(bus) abus$x] == -1 && [lsearch $gSelected(bus) abus$x] == -1 } {
				set gSelectedList(bus) "$gSelectedList(bus) abus$x"
			    }
			}
		    }
		    incr ndx
		}
		set gOrigTokOrder "$gOrigTokOrder $tok"
	    }
	    dbus {
		set gBusInput 1
		set ndx 0
		set last [expr [llength $elem] -1]
		foreach x $elem {
		    # ignore comment for now
		    if { $ndx == $last} {
			continue
		    }
		    if { $ndx != 0 } {
			if { ![info exists gSelected(bus)] } {
			    set gSelected(bus) dbus$x
			} else {
			    if { [lsearch $gSelectedList(bus) dbus$x] == -1 && [lsearch $gSelected(bus) dbus$x] == -1  } {
				set gSelectedList(bus) "$gSelectedList(bus) dbus$x"
			    }
			}
		    }
		    incr ndx
		}
		set gOrigTokOrder "$gOrigTokOrder $tok"
		debug 1 "gSelected(bus): $gSelected(bus) gSelectedList(bus): $gSelectedList(bus)"
	    }
	    cplane {
		set gCplaneInput 1
		genericDecode $elem

		#cplane 0 maps to buses: abus0 abus1 dbus
		set ndx 0
		set last [expr [llength $elem] -1]
		foreach x $elem {
		    # ignore comment for now
		    if { $ndx == $last} {
			continue
		    }
		    if { $ndx != 0 } {
			switch $x {
			    0 { 
				genericDecode {bus abus0 abus1 dbus0 { "" }}
			    }
			    1 {
				genericDecode {bus abus2 abus3 dbus1 { "" }}
			    }
			}
		    }
		    incr ndx
		}
	    }
	    ioc {
		genericDecode $elem
	    }
	    scard {
		genericDecode $elem
	    }
	    mem {
		genericDecode $elem
	    }
	    memgroup {
		genericDecode $elem
	    }
	    mlimit {
		genericDecode $elem
	    }
	    pc {
		genericDecode $elem
	    }
	    xdb {
		genericDecode $elem
	    }
	    cic {
		genericDecode $elem
	    }
	    ldpath {
		genericDecode $elem
	    }
	}
    }
}

# hostview syntax is different from blacklist
# hostview procs are 12, 13 and blacklist is 3.0, 3.1
# also buses.

proc hv2blDecode {} {

    global gSelected
    global gSelectedList
    global gSelectedproc
    global gSelectedListproc
    global gSelectedbus
    global gSelectedListbus

    global gCplaneInput
    global gBusInput
    global gBusChanged


        
    if { [info exists gSelected(proc)] } {
	set tmp1 [expr $gSelected(proc) / 4]
	set tmp2 [expr $gSelected(proc) % 4]
	set proc1 "${tmp1}.$tmp2"

	set procList ""
	foreach proc $gSelectedList(proc) {
	    set tmp1 [expr $proc / 4]
	    set tmp2 [expr $proc % 4]
	    set procList "$procList ${tmp1}.$tmp2"
	}
	#save the old ones
	set gSelectedproc $gSelected(proc)
	set gSelectedListproc $gSelectedList(proc)

	set gSelected(proc) $proc1
	set gSelectedList(proc) $procList
    }
	    
    if { 0 } {
	global gCplaneInput
	global gBusInput
    }

    # if abus or dbus was an input token from the black list
    # or if any changes were made to the buses use bus not cplane
    # else
    # cplane was input and no changes were made, put the cplane back.

    if { $gBusChanged || $gBusInput} {

	set gSelectedList(abus) ""
	set gSelectedList(dbus) ""
	if { [info exists gSelected(abus)] } {
	    unset gSelected(abus)
	}
	if { [info exists gSelected(dbus)] } {
	    unset gSelected(dbus)
	}

	# separate gSelectedList(bus) into gSelectedList(abus) and gSelectedList(dbus)

	if { [info exists gSelected(bus)] } {
	    if { [string length $gSelected(bus)] } {
		if { [string first a $gSelected(bus)] >= 0} {
		    set gSelected(abus) [string trimleft $gSelected(bus) abus]
		} else {
		    set gSelected(dbus) [string trimleft $gSelected(bus) dbus]
		}
	    }
	    debug 1 "gSelected(bus): $gSelected(bus)"
	    if { [info exists gSelected(abus)] } {
		debug 1 "gSelected(abus): $gSelected(abus)"
	    } elseif { [info exists gSelected(dbus)] }  {
		debug 1 "gSelected(dbus): $gSelected(dbus)"
	    }
	    
	}
	if { [info exists gSelectedList(bus)] } {
	    foreach bus $gSelectedList(bus) {
		if { [string first a $bus] >= 0} {
		    if { ![info exists gSelected(abus)] } {
			set gSelected(abus) [string trimleft $bus abus]
		    } else {
			if { ![info exists gSelectedList(abus)] } {
			    set gSelectedList(abus) ""
			}
			set gSelectedList(abus) "$gSelectedList(abus) [string trimleft $bus abus]"
		    }
		} else {
		    if { ![info exists gSelected(dbus)] } {
			set gSelected(dbus) [string trimleft $bus dbus]
		    } else {
			if { ![info exists gSelectedList(dbus)] } {
			    set gSelectedList(dbus) ""
			}
			set gSelectedList(dbus) "$gSelectedList(dbus) [string trimleft $bus dbus]"
		    }
		}
	    }
	    debug 1 "gSelectedList(dbus): $gSelectedList(dbus) gSelectedList(dbus): $gSelectedList(dbus)"
	}
	# use bus, not cplane
	if { [info exists gSelected(cplane)] } {
	     unset gSelected(cplane)
	     set $gSelectedList(cplane) ""
	 }
    } elseif { $gCplaneInput } {
	# cplane was input and not abus or dbus, and no changes were made
	# save bus config
	if { [info exists gSelected(bus)] } {
	     set gSelectedbus $gSelected(bus)
	     unset gSelected(bus)
	     set gSelectedListbus $gSelectedList(bus)
	     set gSelectedList(bus) ""
	 }
    }

}
 # put the procs back in hostview terms in case user wants to edit further.
proc hv2blPutBack {} {

    global gSelected
    global gSelectedList
    global gSelectedproc
    global gSelectedListproc
    global gSelectedbus
    global gSelectedListbus

    if { [info exists gSelected(proc)] } {
	set gSelected(proc) $gSelectedproc
	set gSelectedList(proc) $gSelectedListproc
    }
     if { [info exists gSelectedbus] } {
	set gSelected(bus) $gSelectedbus
	set gSelectedList(bus) $gSelectedListbus
    }


}

proc commentBlacklist {} {
    global gBlacklistfile

    if { [file writable $gBlacklistfile] } {
        if { [ catch {set fileId [ open $gBlacklistfile r+ 0600]} errmsg ] } {
            debug 10 "Error opening blacklist file: $errmsg"
            return -1
        }
    } else {
	return -1
    }

    if { [ catch {set fileIdout [ open ${gBlacklistfile}.tmp.hostview w+ 0600]} errmsg ] } {
	debug 10 "Error opening blacklist temp file: $errmsg"
	return -1
    }

    seek $fileId 0

    while { [ gets $fileId line] >= 0} {
	if {[string first \# $line] == 0} {
	    puts $fileIdout $line
	} else {
	    puts $fileIdout \#$line
	}
    }
    close $fileIdout
    close $fileId

     if { [ catch {exec mv ${gBlacklistfile}.tmp.hostview $gBlacklistfile} errmsg ] } {
	debug 10 "Error replacing blacklist file: $errmsg"
	return -1
    }
}

	
proc genericDecode { blLine } {

    global gSelected
    global gSelectedList
    global gOrigTokOrder

    debug 1 "genericDecode: blLine: $blLine"


    set ndx 0
    set token [ lindex $blLine 0 ]
    set last [expr [llength $blLine] -1]
    foreach elem $blLine {
	# ignore comment for now
	if { $ndx == $last} {
	    continue
	}
	if { $ndx != 0 } {
	    if { ![info exists gSelected($token)] } {
		set gSelected($token) $elem
		set gSelectedList($token) ""
	    } else {
		if { [lsearch $gSelectedList($token) $elem] == -1 && [lsearch $gSelected($token) $elem] == -1  } {
		    set gSelectedList($token) "$gSelectedList($token) $elem"
		}
	    }
	}
	incr ndx
    }
    set gOrigTokOrder "$gOrigTokOrder $token"
    debug 1 "gSelected($token): $gSelected($token) gSelectedList($token): $gSelectedList($token)"
}

proc newBlacklist {} {
    global gBlacklistfile

    global gSelected
    global gSelectedList
    global gSelected
    global gSelectedList
    global gSelected
    global gSelectedList

    global gBLread
    global gBLchanged
    global gBusChanged
    global gViewFlag

    global gBg1
    global gFg1

    set result [tk_dialog .bldia "Hostview - Initialize Blacklist" \
		    "This will copy the blacklist file to a\nbackup and start from scratch.\nDo you wish to continue?"\
		    questhead 1 Yes Cancel]
    if { $result == 1 } {
	return
    }

    if { $gBLchanged == 1 } {
	set result [tk_dialog .bldia "Hostview - Unsaved Changes" \
                        "Unsaved Changes.\nSave before opening new blacklist file?" \
                        questhead 0 Yes No Cancel]
	if { $result == 2 } {
            return
        } elseif { $result == 0 } {
	    appendblacklist
	}
    }

    set tday [exec date]
    set filetail "[lindex $tday 1].[lindex $tday 2].[lindex $tday 3]"

    if { [file writable $gBlacklistfile] } {
	if { [ catch {exec mv $gBlacklistfile ${gBlacklistfile}.${filetail}} errmsg ] } {
            debug 10 "Error copying blacklist file to backup: $errmsg"
            return -1
        }
    } else {
	return -1
    }


    set gBLread 1
    set gBLchanged 0
    set gBusChanged 0

    set allbltok "sysbd proc abus dbus bus ioc scard mem mgroup mlimit cplane pc xdb cic ldpath"

    foreach tok $allbltok {
	if { [info exists gSelected($tok)] } {
	    unset gSelected($tok)
	}
	if { [info exists gSelectedList($tok)] } {
	    set gSelectedList($tok) ""
	}
    }
    
    # clear the display
    blklistGraphic $gViewFlag $gBg1 $gFg1
}



#
proc printBlacklist { } {
    global gBLdata
    global gBLinitdata
    global gSelected
    global gSelectedList
    global gBlacklistfile
    global gBLchanged


    set bltok "sysbd proc abus dbus ioc scard mem mgroup mlimit cplane pc xdb cic ldpath"
    

    set tday [exec date]
    set filetail "[lindex $tday 1].[lindex $tday 2].[lindex $tday 3]"
    set tmpfile $gBlacklistfile.lp.${filetail}

    if { [ catch {set fileId [ open $tmpfile w 0600]} errmsg ] } {
	debug 10 "Error opening blacklist file: $errmsg"
	return
    }

    # hostview syntax is different from blacklist
    # hostview procs are 12, 13 and blacklist is 3.0, 3.1
    # also buses.
    # and cplane map to buses
    hv2blDecode


    seek $fileId 0 end
    set junk [tell $fileId]
    debug 1 "tell: $junk"

    set tday [exec date]

    puts $fileId "\n\#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="
    puts $fileId "\#Blacklist file - would be created by Hostview - $tday"
    puts $fileId "\#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="

    foreach tok $bltok {
	if { [info exists gSelected($tok)] } {
	    debug 1 "tok: $tok"
	    if { [llength $gSelected($tok)] } {
		set temp "$tok $gSelected($tok)"
		debug 1 "tok: $tok"
	    }
	}
	if { [info exists gSelectedList($tok)] } {
	    if { [llength $gSelectedList($tok)] } {
		foreach elem $gSelectedList($tok) {
		    set temp "$temp $elem"
		}
		debug 1 "tok: $tok"
	    }
	}
	if { [info exists temp] } {
	    puts $fileId "$temp"
	    unset temp
	}
    }

    puts $fileId "\n\#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="
    puts $fileId "\#End Hostview Edit - $tday"
    puts $fileId "\#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="

    close $fileId

    # put the procs back in hostview terms in case user wants to edit further.
    hv2blPutBack

    if { [ catch {exec lp $tmpfile} errmsg ] } {
	debug 10 "Error printing potential blacklist file: $errmsg"
    }
     if { [ catch {exec rm $tmpfile} errmsg ] } {
	debug 10 "Error removing temporary potential blacklist file: $errmsg"
	return -1
    }

}
#
# ident	"@(#)writeLog.tcl	1.2	96/09/04 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

proc writeLog {fileId} {
    global gBoards
    global gDomains
    global gFanList
    global gProcessors
    global gThermalList
    global gPowerList
    global gDomainColors
    global gDomainColorMap
    global gPowered
    global gSystemFail
    global gBulkPowerList

	debug 1 "writeLog: $fileId"

    puts $fileId "#Hostview internal state snapshot"
    puts $fileId "\n#board states:{board domain power loaded|empty} "
    puts $fileId $gBoards
    puts $fileId "\n#Domains: {domain_name {sys board list}}"
    puts $fileId $gDomains
    puts $fileId "\n#Processors: { proc number {signature state}}"
    puts $fileId $gProcessors
    puts $fileId "\n#Thermal List: { board flag {values}} flag 1 indicates problem condition."
    puts $fileId $gThermalList
    puts $fileId "\n#Power List: { board flag {values}} flag 1 indicates problem condition."
    puts $fileId $gPowerList
    puts $fileId "\n#Fan List: speed_for_all { failed list } {powered list}"
    puts $fileId $gFanList"
    puts $fileId "\n#Bulk Power List: { present list } { failed list } {powered list}"
    puts $fileId $gBulkPowerList

    puts $fileId "\n#Powered center plane and bulk power {bp2 is PS2}"
    puts $fileId $gPowered
    puts $fileId "\n#System Fail List: {failure domain_name {date}}"
    puts $fileId $gSystemFail
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)hvGenExec.tcl	1.8	97/02/14 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#	General Main to service commands as a separate process
#	This file is exec-ed from hostview with flags.
#	The flags determine which proc will be run by this new process.
#	This process runs under the name hostview_child
#
#	Usage:hostview_child -{tmireEMBp} { commandArgs }
#
#	called by: genTextExec { cmdArg }
#	menuBar:	    -command "genTextExec sspLog" -underline 0
#
# notes:
# domain info is on the hostview side 
# this is a separate process

# Main
#

if {$argc < 2} {
    debug 10 "Usage:hostview_child -{tmireMBp} { commandArgs }"
    exit
}

set valid_args "-tmireMpB"
set usage "usage: hostview_child \[-tmireBMp\]\n \
	\t\[-t\] - popup text widget.\n \
	\t\[-m\] - popup help text widget.\n \
	\t\[-i\] - popup icon help widget.\n \
	\t\[-r\] - popup dr environment widget.\n \
	\t\[-e\] - popup event text widget.\n \
	\t\[-B\] - popup blacklist editor.\n \
	\t\[-E\] - popup hostview error snapshot.\n \
	\t\[-M\] - process to init refresh details displaying the MIB.\n \
	\t\[-p\] - process to init polling of the MIB (stale state).\n"

set flags [lindex $argv 0]
set cmdArgs [lindex $argv 1]
#
# Check command line arguments
#
if { [ catch {CLA_Parse Args $flags $valid_args} errmsg ] } {
    debug 10 "Error: $errmsg"
    debug 10 $usage
    return
}
    debug 1 "hvGenExec: argv: $argv"
    debug 1 "hvGenExec: $flags $cmdArgs"
#
if { [info exists Args(t)] } {
    debug 1 "calling genTextPopDet: with $cmdArgs"
    debug 1 "call genTextPopDet: with [lindex $cmdArgs 0] [lindex $cmdArgs 1]"
    #all domain operations
    genTextPopDet [lindex $cmdArgs 0] [lindex $cmdArgs 1]
    #genTextPopDet $cmdArgs
}

if { [info exists Args(m)] } {
    debug 1 "helpTextPopDet: $cmdArgs"
    helpTextPopDet $cmdArgs
    ##helpTextPopDet [lindex $cmdArgs 0]
    #helpTextPopDet $cmdArgs
}

if { [info exists Args(i)] } {
    debug 1 "helpIconPopDet: $cmdArgs"
    helpIconPopDet $cmdArgs
}

if { [info exists Args(r)] } {
    debug 1 "dummy_dr_setup: $cmdArgs"
    # 3 args, parsed later
    dummy_dr_setup $cmdArgs
}
if { [info exists Args(e)] } {
    debug 1 "info exists Args(e) argv: $argv"
	set filename [lindex $argv 2]
	set filebase [lindex $argv 3]
    debug 1 "eventTextPopDet: $cmdArgs $filename $filebase"
    eventTextPopDet $cmdArgs $filename $filebase
}
if { [info exists Args(B)] } {
    debug 1 "blacklistStart: $cmdArgs"
    blacklistStart $cmdArgs
}
if { [info exists Args(p)] } {
    debug 1 "hostview_child: $cmdArgs"
    staleDriver  [lindex $cmdArgs 0] [lindex $cmdArgs 1]
}

if { [info exists Args(M)] } {
    debug 1 "hostview_child: $cmdArgs"
    refreshMib  [lindex $cmdArgs 0] [lindex $cmdArgs 1]
}
if { [info exists Args(E)] } {
    debug 1 "hvSnapshot: $cmdArgs"
    hvSnapshot $cmdArgs
}


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
