2 # This file is boilerplate TCL/TK function definitions for 'make xconfig'.
7 # 8 January 1999, Michael Elizabeth Chastain, <mec@shout.net>
8 # - Remove unused do_cmd function (part of the 2.0 sound support).
9 # - Arrange buttons in three columns for better screen fitting.
10 # - Add CONSTANT_Y, CONSTANT_M, CONSTANT_N for commands like:
11 # dep_tristate 'foo' CONFIG_FOO m
13 # 23 January 1999, Michael Elizabeth Chastain, <mec@shout.net>
14 # - Shut vfix the hell up.
16 # 24 January 1999, Michael Elizabeth Chastain, <mec@shout.net>
17 # - Improve the exit message (Jeff Ronne).
20 # This is a handy replacement for ".widget cget" that requires neither tk4
21 # nor additional source code uglification.
23 proc cget { w option } {
24 return "[lindex [$w configure $option] 4]"
28 # Function to compensate for broken config.in scripts like the sound driver,
29 # which make dependencies on variables that are never even conditionally
34 if [ catch {eval concat $$var} ] {
40 # Constant values used by certain dep_tristate commands.
48 # Create a "reference" object to steal colors from.
53 # On monochrome displays, -disabledforeground is blank by default; that's
54 # bad. Fill it with -foreground instead.
56 if { [cget .ref -disabledforeground] == "" } {
57 .ref configure -disabledforeground [cget .ref -foreground]
62 # Define some macros we will need to parse the config.in file.
65 proc mainmenu_name { text } {
69 proc menu_option { w menu_num text } {
70 global menus_per_column
71 global processed_top_level
72 set processed_top_level [expr $processed_top_level + 1]
73 if { $processed_top_level <= $menus_per_column } then {
75 } elseif { $processed_top_level <= [expr 2 * $menus_per_column] } then {
80 button .f0.x$menu_num -anchor w -text "$text" \
81 -command "$w .$w \"$text\""
82 pack .f0.x$menu_num -pady 0 -side top -fill x -in .f0.$myframe
85 proc load_configfile { w title func } {
87 toplevel $w -class Dialog
90 label $w.bm -bitmap questhead
91 pack $w.bm -pady 10 -side top -padx 10
92 label $w.x.l -text "Enter filename:" -relief raised
93 entry $w.x.x -width 35 -relief sunken -borderwidth 2 \
94 -textvariable loadfile
95 pack $w.x.l $w.x.x -anchor w -side left
96 pack $w.x -side top -pady 10
101 button $w.f.back -text "OK" -width 20 \
102 -command "destroy $w; focus $oldFocus;$func .fileio"
103 button $w.f.canc -text "Cancel" \
104 -width 20 -command "destroy $w; focus $oldFocus"
105 pack $w.f.back $w.f.canc -side left -pady 10 -padx 45
106 pack $w.f -pady 10 -side bottom -padx 10 -anchor w
108 global winx; global winy
109 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
110 wm geometry $w +$winx+$winy
113 bind all <Alt-q> {maybe_exit .maybe}
115 proc maybe_exit { w } {
117 toplevel $w -class Dialog
118 label $w.bm -bitmap questhead
119 pack $w.bm -pady 10 -side top -padx 10
120 message $w.m -width 400 -aspect 300 \
121 -text "Changes will be lost. Are you sure?" -relief flat
122 pack $w.m -pady 10 -side top -padx 10
123 wm title $w "Are you sure?"
127 button $w.f.back -text "OK" -width 20 \
129 button $w.f.canc -text "Cancel" \
130 -width 20 -command "destroy $w; focus $oldFocus"
131 pack $w.f.back $w.f.canc -side left -pady 10 -padx 45
132 pack $w.f -pady 10 -side bottom -padx 10 -anchor w
133 bind $w <Return> "exit"
134 bind $w <Escape> "destroy $w; focus $oldFocus"
136 global winx; global winy
137 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
138 wm geometry $w +$winx+$winy
141 proc read_config_file { w } {
143 if { [string length $loadfile] != 0 && [file readable $loadfile] == 1 } then {
144 read_config $loadfile
147 toplevel $w -class Dialog
148 message $w.m -width 400 -aspect 300 -text \
149 "Unable to read file $loadfile" \
151 label $w.bm -bitmap error
152 pack $w.bm $w.m -pady 10 -side top -padx 10
153 wm title $w "Xconfig Internal Error"
157 button $w.f.back -text "Bummer" \
158 -width 10 -command "destroy $w; focus $oldFocus"
159 pack $w.f.back -side bottom -pady 10 -anchor s
160 pack $w.f -pady 10 -side top -padx 10 -anchor s
162 global winx; global winy
163 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
164 wm geometry $w +$winx+$winy
168 proc write_config_file { w } {
170 if { [string length $loadfile] != 0
171 && ([file writable $loadfile] == 1 || ([file exists $loadfile] == 0 && [file writable [file dirname $loadfile]] == 1)) } then {
172 writeconfig $loadfile /dev/null
175 toplevel $w -class Dialog
176 message $w.m -width 400 -aspect 300 -text \
177 "Unable to write file $loadfile" \
179 label $w.bm -bitmap error
180 pack $w.bm $w.m -pady 10 -side top -padx 10
181 wm title $w "Xconfig Internal Error"
185 button $w.f.back -text "OK" \
186 -width 10 -command "destroy $w; focus $oldFocus"
187 pack $w.f.back -side bottom -pady 10 -anchor s
188 pack $w.f -pady 10 -side top -padx 10 -anchor s
190 global winx; global winy
191 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
192 wm geometry $w +$winx+$winy
196 proc read_config { filename } {
197 set file1 [open $filename r]
199 while { [gets $file1 line] >= 0} {
200 if [regexp {([0-9A-Za-z_]+)=([ynm])} $line foo var value] {
201 if { $value == "y" } then { set cmd "global $var; set $var 1" }
202 if { $value == "n" } then { set cmd "global $var; set $var 0" }
203 if { $value == "m" } then { set cmd "global $var; set $var 2" }
206 if [regexp {# ([0-9A-Za-z_]+) is not set} $line foo var] {
207 set cmd "global $var; set $var 0"
210 if [regexp {([0-9A-Za-z_]+)=([0-9A-Fa-f]+)} $line foo var value] {
211 set cmd "global $var; set $var $value"
214 if [regexp {([0-9A-Za-z_]+)="([^"]*)"} $line foo var value] {
215 set cmd "global $var; set $var \"$value\""
223 proc write_comment { file1 file2 text } {
226 puts $file1 "# $text"
229 puts $file2 " * $text"
233 proc effective_dep { deplist } {
234 global CONFIG_MODULES
237 if {$i == 0} then {set depend 0}
238 if {$i == 2 && $depend == 1} then {set depend 2}
240 if {$depend == 2 && $CONFIG_MODULES == 0} then {set depend 0}
244 proc sync_tristate { var dep } {
245 global CONFIG_MODULES
246 if {$dep == 0 && ($var == 1 || $var == 2)} then {
248 } elseif {$dep == 2 && $var == 1} then {
250 } elseif {$var == 2 && $CONFIG_MODULES == 0} then {
251 if {$dep == 1} then {set var 1} else {set var 0}
256 proc sync_bool { var dep modset } {
257 set var [sync_tristate $var $dep]
258 if {$dep == 2 && $var == 2} then {
264 proc write_tristate { file1 file2 varname variable deplist modset } {
265 set variable [sync_tristate $variable [effective_dep $deplist]]
266 if { $variable == 2 } \
267 then { set variable $modset }
268 if { $variable == 1 } \
269 then { puts $file1 "$varname=y"; \
270 puts $file2 "#define $varname 1" } \
271 elseif { $variable == 2 } \
272 then { puts $file1 "$varname=m"; \
273 puts $file2 "#undef $varname"; \
274 puts $file2 "#define ${varname}_MODULE 1" } \
275 elseif { $variable == 0 } \
276 then { puts $file1 "# $varname is not set"; \
277 puts $file2 "#undef $varname"} \
279 puts stdout "ERROR - Attempting to write value for unconfigured variable ($varname)." \
283 proc write_int { file1 file2 varname variable dep } {
285 then { puts $file1 "# $varname is not set"; \
286 puts $file2 "#undef $varname"} \
288 puts $file1 "$varname=$variable"; \
289 puts $file2 "#define $varname ($variable)"; \
293 proc write_hex { file1 file2 varname variable dep } {
295 then { puts $file1 "# $varname is not set"; \
296 puts $file2 "#undef $varname"} \
298 puts $file1 "$varname=$variable"; \
299 puts -nonewline $file2 "#define $varname 0x"; \
300 puts $file2 [exec echo $variable | sed s/^0\[xX\]//]; \
304 proc write_string { file1 file2 varname variable dep } {
306 then { puts $file1 "# $varname is not set"; \
307 puts $file2 "#undef $varname"} \
309 puts $file1 "$varname=\"$variable\""; \
310 puts $file2 "#define $varname \"$variable\""; \
314 proc option_name {w mnum line text helpidx} {
315 button $w.x$line.l -text "$text" -relief groove -anchor w
316 $w.x$line.l configure -activefore [cget $w.x$line.l -fg] \
317 -activeback [cget $w.x$line.l -bg]
318 button $w.x$line.help -text "Help" -relief raised \
319 -command "dohelp .dohelp $helpidx .menu$mnum"
320 pack $w.x$line.help -side right -fill y
321 pack $w.x$line.l -side right -fill both -expand on
324 proc toggle_switch2 {w mnum line text variable} {
325 frame $w.x$line -relief sunken
326 radiobutton $w.x$line.y -text "y" -variable $variable -value 1 \
327 -relief groove -width 2 -command "update_active"
328 radiobutton $w.x$line.m -text "-" -variable $variable -value 2 \
329 -relief groove -width 2 -command "update_active"
330 radiobutton $w.x$line.n -text "n" -variable $variable -value 0 \
331 -relief groove -width 2 -command "update_active"
333 option_name $w $mnum $line $text $variable
335 pack $w.x$line.n $w.x$line.m $w.x$line.y -side right -fill y
338 proc toggle_switch3 {w mnum line text variable} {
339 frame $w.x$line -relief sunken
340 radiobutton $w.x$line.y -text "y" -variable $variable -value 1 \
341 -relief groove -width 2 -command "update_active"
342 radiobutton $w.x$line.m -text "m" -variable $variable -value 2 \
343 -relief groove -width 2 -command "update_active"
344 radiobutton $w.x$line.n -text "n" -variable $variable -value 0 \
345 -relief groove -width 2 -command "update_active"
347 option_name $w $mnum $line $text $variable
349 global CONFIG_MODULES
350 if {($CONFIG_MODULES == 0)} then {
351 $w.x$line.m configure -state disabled
353 pack $w.x$line.n $w.x$line.m $w.x$line.y -side right -fill y
356 proc bool {w mnum line text variable} {
357 toggle_switch2 $w $mnum $line $text $variable
358 $w.x$line.m configure -state disabled
359 pack $w.x$line -anchor w -fill both -expand on
362 proc tristate {w mnum line text variable } {
363 toggle_switch3 $w $mnum $line $text $variable
364 pack $w.x$line -anchor w -fill both -expand on
367 proc dep_tristate {w mnum line text variable } {
368 tristate $w $mnum $line $text $variable
371 proc dep_bool {w mnum line text variable } {
372 bool $w $mnum $line $text $variable
375 proc int { w mnum line text variable } {
377 entry $w.x$line.x -width 18 -relief sunken -borderwidth 2 \
378 -textvariable $variable
379 option_name $w $mnum $line $text $variable
380 pack $w.x$line.x -anchor w -side right -fill y
381 pack $w.x$line -anchor w -fill both -expand on
384 proc hex { w mnum line text variable } {
385 int $w $mnum $line $text $variable
388 proc istring { w mnum line text variable } {
390 entry $w.x$line.x -width 18 -relief sunken -borderwidth 2 \
391 -textvariable $variable
392 option_name $w $mnum $line $text $variable
393 pack $w.x$line.x -anchor w -side right -fill y
394 pack $w.x$line -anchor w -fill both -expand on
397 proc minimenu { w mnum line text variable helpidx } {
399 menubutton $w.x$line.x -textvariable $variable -menu \
400 $w.x$line.x.menu -relief raised \
402 option_name $w $mnum $line $text $helpidx
403 pack $w.x$line.x -anchor w -side right -fill y
404 pack $w.x$line -anchor w -fill both -expand on
407 proc menusplit {w m n} {
410 set menuoptsize [expr [$m yposition 2] - [$m yposition 1]]
411 set maxsize [winfo screenheight $w]
412 set splitpoint [expr $maxsize * 4 / 5 / $menuoptsize - 1]
413 for {set i [expr $splitpoint + 1]} {$i <= $n} {incr i $splitpoint} {
414 $m entryconfigure $i -columnbreak 1
419 proc menutitle {text menu w} {
423 proc submenu { w mnum line text subnum } {
425 button $w.x$line.l -text "" -width 15 -relief groove
426 $w.x$line.l configure -activefore [cget $w.x$line.l -fg] \
427 -activeback [cget $w.x$line.l -bg] -state disabled
428 button $w.x$line.m -text "$text" -relief raised -anchor w \
429 -command "catch {destroy .menu$subnum}; menu$subnum .menu$subnum \"$text\""
430 pack $w.x$line.l -side left -fill both
431 pack $w.x$line.m -anchor w -side right -fill both -expand on
432 pack $w.x$line -anchor w -fill both -expand on
435 proc comment {w mnum line text } {
437 button $w.x$line.l -text "" -width 15 -relief groove
438 $w.x$line.l configure -activefore [cget $w.x$line.l -fg] \
439 -activeback [cget $w.x$line.l -bg] -state disabled
440 button $w.x$line.m -text "$text" -relief groove -anchor w
441 $w.x$line.m configure -activefore [cget $w.x$line.m -fg] \
442 -activeback [cget $w.x$line.m -bg]
443 pack $w.x$line.l -side left -fill both
444 pack $w.x$line.m -anchor w -side right -fill both -expand on
445 pack $w.x$line -anchor w -fill both -expand on
448 proc dohelp {w var parent} {
450 toplevel $w -class Dialog
456 if { [file readable Documentation/Configure.help] == 1} then {
458 # First escape sed regexp special characters in var:
459 set var [exec echo "$var" | sed s/\[\]\[\/.^$*\]/\\\\&/g]
460 # Now pick out right help text:
461 set message [exec sed -n "
471 " Documentation/Configure.help]
472 set found [expr [string length "$message"] > 0]
476 pack $w.f1 -fill both -expand on
482 button $w.f2.ok -text "OK" \
483 -width 10 -command "destroy $w; catch {focus $oldFocus}"
484 pack $w.f2.ok -side bottom -pady 6 -anchor n
485 pack $w.f2 -side bottom -padx 10 -anchor s
487 scrollbar $w.f1.vscroll -command "$w.f1.canvas yview"
488 pack $w.f1.vscroll -side right -fill y
490 canvas $w.f1.canvas -relief flat -borderwidth 0 \
491 -yscrollcommand "$w.f1.vscroll set"
493 pack $w.f1.canvas -side right -fill y -expand on
495 if { $found == 0 } then {
496 if { $filefound == 0 } then {
497 message $w.f1.f.m -width 750 -aspect 300 -relief flat -text \
498 "No help available - unable to open file Documentation/Configure.help. This file should have come with your kernel."
500 message $w.f1.f.m -width 400 -aspect 300 -relief flat -text \
501 "No help available for $var"
503 label $w.f1.bm -bitmap error
506 text $w.f1.f.m -width 73 -relief flat -wrap word
507 $w.f1.f.m insert 0.0 $message
508 $w.f1.f.m conf -state disabled -height [$w.f1.f.m index end]
510 label $w.f1.bm -bitmap info
511 wm title $w "Configuration help"
513 pack $w.f1.f.m -side left
514 pack $w.f1.bm $w.f1.f -side left -padx 10
517 set winx [expr [winfo x $parent]+20]
518 set winy [expr [winfo y $parent]+20]
519 wm geometry $w +$winx+$winy
520 set sizok [expr [winfo reqheight $w.f2.ok] + 12]
521 set maxy [expr [winfo screenheight .] * 3 / 4]
522 set canvtotal [winfo reqheight $w.f1.f.m]
523 if [expr $sizok + $canvtotal < $maxy] {
526 set sizy [expr $maxy - $sizok]
528 $w.f1.canvas configure -height $sizy -width [winfo reqwidth $w.f1.f.m] \
529 -scrollregion "0 0 [winfo reqwidth $w.f1.f.m] \
530 [winfo reqheight $w.f1.f.m]"
531 $w.f1.canvas create window 0 0 -anchor nw -window $w.f1.f
534 set maxy [winfo screenheight .]
535 if [expr $sizok + $canvtotal < $maxy] {
536 set sizy [expr $sizok + $canvtotal]
540 wm maxsize $w [winfo width $w] $sizy
543 bind all <Alt-s> { catch {exec cp -f .config .config.old}; \
544 writeconfig .config include/linux/autoconf.h; wrapup .wrap }
548 toplevel $w -class Dialog
550 global CONFIG_MODVERSIONS; vfix CONFIG_MODVERSIONS
551 if { ([file exists .hdepend] != 1) || ($CONFIG_MODVERSIONS == 1) } then {
552 message $w.m -width 400 -aspect 300 -relief raised -text \
553 "End of Linux kernel configuration. Check the top-level Makefile for additional configuration. Next, you must run 'make dep'."
555 message $w.m -width 400 -aspect 300 -relief raised -text \
556 "End of Linux kernel configuration. Check the top-level Makefile for additional configuration. Next, you may 'make bzImage', 'make bzdisk', or 'make bzlilo.'"
558 label $w.bm -bitmap info
559 pack $w.bm $w.m -pady 10 -side top -padx 10
560 wm title $w "Kernel build instructions"
564 button $w.f.back -text "OK" \
565 -width 10 -command "exit"
566 pack $w.f.back -side bottom -pady 10 -anchor s
567 pack $w.f -pady 10 -side top -padx 10 -anchor s
569 bind $w <Return> "exit"
570 global winx; global winy
571 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
572 wm geometry $w +$winx+$winy
576 proc unregister_active {num} {
578 set index [lsearch -exact $active_menus $num]
579 if {$index != -1} then {set active_menus [lreplace $active_menus $index $index]}
582 proc update_active {} {
583 global active_menus total_menus
585 if {[llength $active_menus] > 0} then {
586 set max [lindex $active_menus end]
587 update_define [toplevel_menu [lindex $active_menus 0]] $max 0
589 foreach i $active_menus {
590 if {[winfo exists .menu$i] == 0} then {
596 update_define [expr $max + 1] $total_menus 1
600 proc configure_entry {w option items} {
602 $w.$i configure -state $option
606 proc validate_int {name val default} {
607 if {([exec echo $val | sed s/^-//g | tr -d \[:digit:\] ] != "")} then {
608 global $name; set $name $default
612 proc validate_hex {name val default} {
613 if {([exec echo $val | tr -d \[:xdigit:\] ] != "")} then {
614 global $name; set $name $default
618 proc update_define {first last allow_update} {
619 for {set i $first} {$i <= $last} {incr i} {
621 if {$allow_update == 1} then update
626 # Next set up the particulars for the top level menu, and define a few
627 # buttons which we will stick down at the bottom.
635 set active_menus [list]
636 set processed_top_level 0