File: generic

package info (click to toggle)
scsitools 0.15
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 384 kB
  • sloc: ansic: 3,154; tcl: 2,144; makefile: 48; sh: 41
file content (118 lines) | stat: -rw-r--r-- 3,397 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
frame .buttons
button .buttons.quit -text Quit \
	-activeforeground white -activebackground red -command exit
button .buttons.apply -text "Try Changes" -activebackground yellow -command {
	write_page $argv "-X"
# Reread values.. Thus see what the device actually did (and erase signs and leading 0's
# that Joe Blow user entered)
	read_page $argv "-X"
}

frame .buttons1
button .buttons1.default -text "Read Defaults" -activebackground green -command {
	read_page $argv "-M"
}
button .buttons1.saved -text "Read Saved" -activebackground green -command {
	read_page $argv "-S"
}
button .buttons1.current -text "Read Current" -activebackground green -command {
	read_page $argv "-X"
}
pack .buttons.apply  .buttons.quit  -side left -padx 10 -pady 3
pack .buttons1.default .buttons1.saved .buttons1.current -side left -padx 10 -pady 3
pack .buttons .buttons1

frame .space1
pack .space1 -pady 10

proc generate_textboxes { } {
    global text_list
    global text_descriptions
    global label_width
    global text_width
    set lineno 0

    foreach x $text_list { 
	frame .$x
	label .$x.label -text [lindex $text_descriptions $lineno] -width $label_width -anchor w
	text .$x.text -width $text_width -height 1 \
		 -relief sunken -borderwidth 2
	pack .$x.label .$x.text -side left
	set lineno [expr $lineno+1]
    }

}

proc read_page { device option } {
    global button_list
    global text_list
    global switch
    set line {}
    exec /sbin/scsiinfo -X $switch $option $device > /var/run/cachepage 2> /dev/null
    if {[catch {set file [open /var/run/cachepage r]}] == 1} return;
    gets $file line
    close $file
    exec rm /var/run/cachepage
    set first [lindex $line 0]
    set second [lindex $line 1]
    set lineno 0
    foreach x $button_list { 
	.$x deselect
        if { [ string compare [lindex $line $lineno] "0" ] != 0} then { .$x select }
	set lineno [expr $lineno+1]
    }
    foreach x $text_list { 
      .$x.text delete 1.0 end
      .$x.text insert end [lindex $line $lineno]
      set lineno [expr $lineno+1]
    }
}

proc read_modifiable { device } {
    global button_list
    global text_list
    global switch
    set line {}
    exec /sbin/scsiinfo -X -m $switch $device > /var/run/cachepage
    if {[catch {set file [open /var/run/cachepage r]}] == 1} return;
    gets $file line
    close $file
    exec rm /var/run/cachepage
    set lineno 0
    foreach x $button_list { 
        if { [ string compare [lindex $line $lineno] "0" ] == 0} then { .$x configure -state disabled }
	set lineno [expr $lineno+1]
    }

    foreach x $text_list { 
	if { [ string compare [lindex $line $lineno] "0" ] == 0} \
	  then { .$x.text configure -state disabled } \
	  else { .$x.text configure -background white }
      set lineno [expr $lineno+1]
    }
}

proc write_page { device option } {
    global button_list
    global text_list
    global switch
    set lineno 0
    set r3  [concat -X $switch -R $device]
    foreach x $button_list { 
	global $x
	set r1 [eval set $x]
        if { $r1 == 1 } then { set r3 [concat $r3 1] } \
          else { set r3 [concat $r3 0] }
	set lineno [expr $lineno+1]
    }
    foreach x $text_list { 
	set r3 [concat $r3 [.$x.text get 1.0 end]]
        set lineno [expr $lineno+1]
    }
    set file [open /var/run/wrscsi w]
    puts $file "/sbin/scsiinfo $r3"
    close $file
    exec sh < /var/run/wrscsi
    exec rm /var/run/wrscsi
}