1# FILE: header.tk 2# This file is boilerplate TCL/TK function definitions for 'make xconfig'. 3# 4# CHANGES 5# ======= 6# 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 12# 13# 23 January 1999, Michael Elizabeth Chastain, <mec@shout.net> 14# - Shut vfix the hell up. 15# 16# 24 January 1999, Michael Elizabeth Chastain, <mec@shout.net> 17# - Improve the exit message (Jeff Ronne). 18 19# 20# This is a handy replacement for ".widget cget" that requires neither tk4 21# nor additional source code uglification. 22# 23proc cget { w option } { 24 return "[lindex [$w configure $option] 4]" 25} 26 27# 28# Function to compensate for broken config.in scripts like the sound driver, 29# which make dependencies on variables that are never even conditionally 30# defined. 31# 32proc vfix { var } { 33 global $var 34 if [ catch {eval concat $$var} ] { 35 set $var 4 36 } 37} 38 39# 40# Constant values used by certain dep_tristate commands. 41# 42set CONSTANT_Y 1 43set CONSTANT_M 2 44set CONSTANT_N 0 45set CONSTANT_E 4 46 47# 48# Create a "reference" object to steal colors from. 49# 50button .ref 51 52# 53# On monochrome displays, -disabledforeground is blank by default; that's 54# bad. Fill it with -foreground instead. 55# 56if { [cget .ref -disabledforeground] == "" } { 57 .ref configure -disabledforeground [cget .ref -foreground] 58} 59 60 61# 62# Define some macros we will need to parse the config.in file. 63# 64 65proc mainmenu_name { text } { 66 wm title . "$text" 67} 68 69proc 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 { 74 set myframe left 75 } elseif { $processed_top_level <= [expr 2 * $menus_per_column] } then { 76 set myframe middle 77 } else { 78 set myframe right 79 } 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 83} 84 85proc load_configfile { w title func } { 86 catch {destroy $w} 87 toplevel $w -class Dialog 88 global loadfile 89 frame $w.x 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 97 wm title $w "$title" 98 99 set oldFocus [focus] 100 frame $w.f 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 107 focus $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 111} 112 113proc maybe_exit { w } { 114 catch {destroy $w} 115 toplevel $w -class Dialog 116 label $w.bm -bitmap questhead 117 pack $w.bm -pady 10 -side top -padx 10 118 message $w.m -width 400 -aspect 300 \ 119 -text "Changes will be lost. Are you sure?" -relief flat 120 pack $w.m -pady 10 -side top -padx 10 121 wm title $w "Are you sure?" 122 123 set oldFocus [focus] 124 frame $w.f 125 button $w.f.back -text "OK" -width 20 \ 126 -command "exit" 127 button $w.f.canc -text "Cancel" \ 128 -width 20 -command "destroy $w; focus $oldFocus" 129 pack $w.f.back $w.f.canc -side left -pady 10 -padx 45 130 pack $w.f -pady 10 -side bottom -padx 10 -anchor w 131 focus $w 132 global winx; global winy 133 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30] 134 wm geometry $w +$winx+$winy 135} 136 137proc read_config_file { w } { 138 global loadfile 139 if { [string length $loadfile] != 0 && [file readable $loadfile] == 1 } then { 140 read_config $loadfile 141 } else { 142 catch {destroy $w} 143 toplevel $w -class Dialog 144 message $w.m -width 400 -aspect 300 -text \ 145 "Unable to read file $loadfile" \ 146 -relief raised 147 label $w.bm -bitmap error 148 pack $w.bm $w.m -pady 10 -side top -padx 10 149 wm title $w "Xconfig Internal Error" 150 151 set oldFocus [focus] 152 frame $w.f 153 button $w.f.back -text "Bummer" \ 154 -width 10 -command "destroy $w; focus $oldFocus" 155 pack $w.f.back -side bottom -pady 10 -anchor s 156 pack $w.f -pady 10 -side top -padx 10 -anchor s 157 focus $w 158 global winx; global winy 159 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30] 160 wm geometry $w +$winx+$winy 161 } 162} 163 164proc write_config_file { w } { 165 global loadfile 166 if { [string length $loadfile] != 0 167 && ([file writable $loadfile] == 1 || ([file exists $loadfile] == 0 && [file writable [file dirname $loadfile]] == 1)) } then { 168 writeconfig $loadfile /dev/null 169 } else { 170 catch {destroy $w} 171 toplevel $w -class Dialog 172 message $w.m -width 400 -aspect 300 -text \ 173 "Unable to write file $loadfile" \ 174 -relief raised 175 label $w.bm -bitmap error 176 pack $w.bm $w.m -pady 10 -side top -padx 10 177 wm title $w "Xconfig Internal Error" 178 179 set oldFocus [focus] 180 frame $w.f 181 button $w.f.back -text "OK" \ 182 -width 10 -command "destroy $w; focus $oldFocus" 183 pack $w.f.back -side bottom -pady 10 -anchor s 184 pack $w.f -pady 10 -side top -padx 10 -anchor s 185 focus $w 186 global winx; global winy 187 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30] 188 wm geometry $w +$winx+$winy 189 } 190} 191 192proc read_config { filename } { 193 set file1 [open $filename r] 194 clear_choices 195 while { [gets $file1 line] >= 0} { 196 if [regexp {([0-9A-Za-z_]+)=([ynm])} $line foo var value] { 197 if { $value == "y" } then { set cmd "global $var; set $var 1" } 198 if { $value == "n" } then { set cmd "global $var; set $var 0" } 199 if { $value == "m" } then { set cmd "global $var; set $var 2" } 200 eval $cmd 201 } 202 if [regexp {# ([0-9A-Za-z_]+) is not set} $line foo var] { 203 set cmd "global $var; set $var 0" 204 eval $cmd 205 } 206 if [regexp {([0-9A-Za-z_]+)=([0-9A-Fa-f]+)} $line foo var value] { 207 set cmd "global $var; set $var $value" 208 eval $cmd 209 } 210 if [regexp {([0-9A-Za-z_]+)="([^"]*)"} $line foo var value] { 211 set cmd "global $var; set $var \"$value\"" 212 eval $cmd 213 } 214 } 215 close $file1 216 update_choices 217 update_mainmenu 218} 219proc write_comment { file1 file2 text } { 220 puts $file1 "" 221 puts $file1 "#" 222 puts $file1 "# $text" 223 puts $file1 "#" 224 puts $file2 "/*" 225 puts $file2 " * $text" 226 puts $file2 " */" 227} 228 229proc effective_dep { deplist } { 230 global CONFIG_MODULES 231 set depend 1 232 foreach i $deplist { 233 if {$i == 0} then {set depend 0} 234 if {$i == 2 && $depend == 1} then {set depend 2} 235 } 236 if {$depend == 2 && $CONFIG_MODULES == 0} then {set depend 0} 237 return $depend 238} 239 240proc sync_tristate { var dep } { 241 global CONFIG_MODULES 242 if {$dep == 0 && ($var == 1 || $var == 2)} then { 243 set var 0 244 } elseif {$dep == 2 && $var == 1} then { 245 set var 2 246 } elseif {$var == 2 && $CONFIG_MODULES == 0} then { 247 if {$dep == 1} then {set var 1} else {set var 0} 248 } 249 return $var 250} 251 252proc sync_bool { var dep modset } { 253 set var [sync_tristate $var $dep] 254 if {$dep == 2 && $var == 2} then { 255 set var $modset 256 } 257 return $var 258} 259 260proc write_tristate { file1 file2 varname variable deplist modset } { 261 set variable [sync_tristate $variable [effective_dep $deplist]] 262 if { $variable == 2 } \ 263 then { set variable $modset } 264 if { $variable == 1 } \ 265 then { puts $file1 "$varname=y"; \ 266 puts $file2 "#define $varname 1" } \ 267 elseif { $variable == 2 } \ 268 then { puts $file1 "$varname=m"; \ 269 puts $file2 "#undef $varname"; \ 270 puts $file2 "#define ${varname}_MODULE 1" } \ 271 elseif { $variable == 0 } \ 272 then { puts $file1 "# $varname is not set"; \ 273 puts $file2 "#undef $varname"} \ 274 else { \ 275 puts stdout "ERROR - Attempting to write value for unconfigured variable ($varname)." \ 276 } 277} 278 279proc write_int { file1 file2 varname variable dep } { 280 if { $dep == 0 } \ 281 then { puts $file1 "# $varname is not set"; \ 282 puts $file2 "#undef $varname"} \ 283 else { 284 puts $file1 "$varname=$variable"; \ 285 puts $file2 "#define $varname ($variable)"; \ 286 } 287} 288 289proc write_hex { file1 file2 varname variable dep } { 290 if { $dep == 0 } \ 291 then { puts $file1 "# $varname is not set"; \ 292 puts $file2 "#undef $varname"} \ 293 else { 294 puts $file1 "$varname=$variable"; \ 295 puts -nonewline $file2 "#define $varname 0x"; \ 296 puts $file2 [exec echo $variable | sed s/^0\[xX\]//]; \ 297 } 298} 299 300proc write_string { file1 file2 varname variable dep } { 301 if { $dep == 0 } \ 302 then { puts $file1 "# $varname is not set"; \ 303 puts $file2 "#undef $varname"} \ 304 else { 305 puts $file1 "$varname=\"$variable\""; \ 306 puts $file2 "#define $varname \"$variable\""; \ 307 } 308} 309 310proc option_name {w mnum line text helpidx} { 311 button $w.x$line.l -text "$text" -relief groove -anchor w 312 $w.x$line.l configure -activefore [cget $w.x$line.l -fg] \ 313 -activeback [cget $w.x$line.l -bg] 314 button $w.x$line.help -text "Help" -relief raised \ 315 -command "dohelp .dohelp $helpidx .menu$mnum" 316 pack $w.x$line.help -side right -fill y 317 pack $w.x$line.l -side right -fill both -expand on 318} 319 320proc toggle_switch2 {w mnum line text variable} { 321 frame $w.x$line -relief sunken 322 radiobutton $w.x$line.y -text "y" -variable $variable -value 1 \ 323 -relief groove -width 2 -command "update_active" 324 radiobutton $w.x$line.m -text "-" -variable $variable -value 2 \ 325 -relief groove -width 2 -command "update_active" 326 radiobutton $w.x$line.n -text "n" -variable $variable -value 0 \ 327 -relief groove -width 2 -command "update_active" 328 329 option_name $w $mnum $line $text $variable 330 331 pack $w.x$line.n $w.x$line.m $w.x$line.y -side right -fill y 332} 333 334proc toggle_switch3 {w mnum line text variable} { 335 frame $w.x$line -relief sunken 336 radiobutton $w.x$line.y -text "y" -variable $variable -value 1 \ 337 -relief groove -width 2 -command "update_active" 338 radiobutton $w.x$line.m -text "m" -variable $variable -value 2 \ 339 -relief groove -width 2 -command "update_active" 340 radiobutton $w.x$line.n -text "n" -variable $variable -value 0 \ 341 -relief groove -width 2 -command "update_active" 342 343 option_name $w $mnum $line $text $variable 344 345 global CONFIG_MODULES 346 if {($CONFIG_MODULES == 0)} then { 347 $w.x$line.m configure -state disabled 348 } 349 pack $w.x$line.n $w.x$line.m $w.x$line.y -side right -fill y 350} 351 352proc bool {w mnum line text variable} { 353 toggle_switch2 $w $mnum $line $text $variable 354 $w.x$line.m configure -state disabled 355 pack $w.x$line -anchor w -fill both -expand on 356} 357 358proc tristate {w mnum line text variable } { 359 toggle_switch3 $w $mnum $line $text $variable 360 pack $w.x$line -anchor w -fill both -expand on 361} 362 363proc dep_tristate {w mnum line text variable } { 364 tristate $w $mnum $line $text $variable 365} 366 367proc dep_bool {w mnum line text variable } { 368 bool $w $mnum $line $text $variable 369} 370 371proc int { w mnum line text variable } { 372 frame $w.x$line 373 entry $w.x$line.x -width 18 -relief sunken -borderwidth 2 \ 374 -textvariable $variable 375 option_name $w $mnum $line $text $variable 376 pack $w.x$line.x -anchor w -side right -fill y 377 pack $w.x$line -anchor w -fill both -expand on 378} 379 380proc hex { w mnum line text variable } { 381 int $w $mnum $line $text $variable 382} 383 384proc istring { w mnum line text variable } { 385 frame $w.x$line 386 entry $w.x$line.x -width 18 -relief sunken -borderwidth 2 \ 387 -textvariable $variable 388 option_name $w $mnum $line $text $variable 389 pack $w.x$line.x -anchor w -side right -fill y 390 pack $w.x$line -anchor w -fill both -expand on 391} 392 393proc minimenu { w mnum line text variable helpidx } { 394 frame $w.x$line 395 menubutton $w.x$line.x -textvariable $variable -menu \ 396 $w.x$line.x.menu -relief raised \ 397 -anchor w 398 option_name $w $mnum $line $text $helpidx 399 pack $w.x$line.x -anchor w -side right -fill y 400 pack $w.x$line -anchor w -fill both -expand on 401} 402 403proc menusplit {w m n} { 404 if { $n > 2 } then { 405 update idletasks 406 set menuoptsize [expr [$m yposition 2] - [$m yposition 1]] 407 set maxsize [winfo screenheight $w] 408 set splitpoint [expr $maxsize * 4 / 5 / $menuoptsize - 1] 409 for {set i [expr $splitpoint + 1]} {$i <= $n} {incr i $splitpoint} { 410 $m entryconfigure $i -columnbreak 1 411 } 412 } 413} 414 415proc menutitle {text menu w} { 416 wm title $w "$text" 417} 418 419proc submenu { w mnum line text subnum } { 420 frame $w.x$line 421 button $w.x$line.l -text "" -width 15 -relief groove 422 $w.x$line.l configure -activefore [cget $w.x$line.l -fg] \ 423 -activeback [cget $w.x$line.l -bg] -state disabled 424 button $w.x$line.m -text "$text" -relief raised -anchor w \ 425 -command "catch {destroy .menu$subnum}; menu$subnum .menu$subnum \"$text\"" 426 pack $w.x$line.l -side left -fill both 427 pack $w.x$line.m -anchor w -side right -fill both -expand on 428 pack $w.x$line -anchor w -fill both -expand on 429} 430 431proc comment {w mnum line text } { 432 frame $w.x$line 433 button $w.x$line.l -text "" -width 15 -relief groove 434 $w.x$line.l configure -activefore [cget $w.x$line.l -fg] \ 435 -activeback [cget $w.x$line.l -bg] -state disabled 436 button $w.x$line.m -text "$text" -relief groove -anchor w 437 $w.x$line.m configure -activefore [cget $w.x$line.m -fg] \ 438 -activeback [cget $w.x$line.m -bg] 439 pack $w.x$line.l -side left -fill both 440 pack $w.x$line.m -anchor w -side right -fill both -expand on 441 pack $w.x$line -anchor w -fill both -expand on 442} 443 444proc dohelp {w var parent} { 445 catch {destroy $w} 446 toplevel $w -class Dialog 447 448 set filefound 0 449 set found 0 450 set lineno 0 451 452 if { [file readable Documentation/Configure.help] == 1} then { 453 set filefound 1 454 # First escape sed regexp special characters in var: 455 set var [exec echo "$var" | sed s/\[\]\[\/.^$*\]/\\\\&/g] 456 # Now pick out right help text: 457 set message [exec sed -n " 458 /^$var\[ \]*\$/,\${ 459 /^$var\[ \]*\$/c\\ 460${var}:\\ 461 462 /^#/b 463 /^\[^ \]/q 464 s/^ // 465 p 466 } 467 " Documentation/Configure.help] 468 set found [expr [string length "$message"] > 0] 469 } 470 471 frame $w.f1 472 pack $w.f1 -fill both -expand on 473 474 # Do the OK button 475 # 476 set oldFocus [focus] 477 frame $w.f2 478 button $w.f2.ok -text "OK" \ 479 -width 10 -command "destroy $w; catch {focus $oldFocus}" 480 pack $w.f2.ok -side bottom -pady 6 -anchor n 481 pack $w.f2 -side bottom -padx 10 -anchor s 482 483 scrollbar $w.f1.vscroll -command "$w.f1.canvas yview" 484 pack $w.f1.vscroll -side right -fill y 485 486 canvas $w.f1.canvas -relief flat -borderwidth 0 \ 487 -yscrollcommand "$w.f1.vscroll set" 488 frame $w.f1.f 489 pack $w.f1.canvas -side right -fill y -expand on 490 491 if { $found == 0 } then { 492 if { $filefound == 0 } then { 493 message $w.f1.f.m -width 750 -aspect 300 -relief flat -text \ 494 "No help available - unable to open file Documentation/Configure.help. This file should have come with your kernel." 495 } else { 496 message $w.f1.f.m -width 400 -aspect 300 -relief flat -text \ 497 "No help available for $var" 498 } 499 label $w.f1.bm -bitmap error 500 wm title $w "RTFM" 501 } else { 502 text $w.f1.f.m -width 73 -relief flat -wrap word 503 $w.f1.f.m insert 0.0 $message 504 $w.f1.f.m conf -state disabled -height [$w.f1.f.m index end] 505 506 label $w.f1.bm -bitmap info 507 wm title $w "Configuration help" 508 } 509 pack $w.f1.f.m -side left 510 pack $w.f1.bm $w.f1.f -side left -padx 10 511 512 focus $w 513 set winx [expr [winfo x $parent]+20] 514 set winy [expr [winfo y $parent]+20] 515 wm geometry $w +$winx+$winy 516 set sizok [expr [winfo reqheight $w.f2.ok] + 12] 517 set maxy [expr [winfo screenheight .] * 3 / 4] 518 set canvtotal [winfo reqheight $w.f1.f.m] 519 if [expr $sizok + $canvtotal < $maxy] { 520 set sizy $canvtotal 521 } else { 522 set sizy [expr $maxy - $sizok] 523 } 524 $w.f1.canvas configure -height $sizy -width [winfo reqwidth $w.f1.f.m] \ 525 -scrollregion "0 0 [winfo reqwidth $w.f1.f.m] \ 526 [winfo reqheight $w.f1.f.m]" 527 $w.f1.canvas create window 0 0 -anchor nw -window $w.f1.f 528 update idletasks 529 530 set maxy [winfo screenheight .] 531 if [expr $sizok + $canvtotal < $maxy] { 532 set sizy [expr $sizok + $canvtotal] 533 } else { 534 set sizy $maxy 535 } 536 wm maxsize $w [winfo width $w] $sizy 537} 538 539proc wrapup {w } { 540 catch {destroy $w} 541 toplevel $w -class Dialog 542 543 global CONFIG_MODVERSIONS; vfix CONFIG_MODVERSIONS 544 if { ([file exists .hdepend] != 1) || ($CONFIG_MODVERSIONS == 1) } then { 545 message $w.m -width 400 -aspect 300 -relief raised -text \ 546 "End of Linux kernel configuration. Check the top-level Makefile for additional configuration. Next, you must run 'make dep'." 547 } else { 548 message $w.m -width 400 -aspect 300 -relief raised -text \ 549 "End of Linux kernel configuration. Check the top-level Makefile for additional configuration. Next, you may 'make bzImage', 'make bzdisk', or 'make bzlilo.'" 550 } 551 label $w.bm -bitmap info 552 pack $w.bm $w.m -pady 10 -side top -padx 10 553 wm title $w "Kernel build instructions" 554 555 set oldFocus [focus] 556 frame $w.f 557 button $w.f.back -text "OK" \ 558 -width 10 -command "exit" 559 pack $w.f.back -side bottom -pady 10 -anchor s 560 pack $w.f -pady 10 -side top -padx 10 -anchor s 561 focus $w 562 global winx; global winy 563 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30] 564 wm geometry $w +$winx+$winy 565 566} 567 568proc unregister_active {num} { 569 global active_menus 570 set index [lsearch -exact $active_menus $num] 571 if {$index != -1} then {set active_menus [lreplace $active_menus $index $index]} 572} 573 574proc update_active {} { 575 global active_menus total_menus 576 set max 0 577 if {[llength $active_menus] > 0} then { 578 set max [lindex $active_menus end] 579 update_define [toplevel_menu [lindex $active_menus 0]] $max 0 580 } 581 foreach i $active_menus { 582 if {[winfo exists .menu$i] == 0} then { 583 unregister_active $i 584 } else { 585 update_menu$i 586 } 587 } 588 update_define [expr $max + 1] $total_menus 1 589 update_mainmenu 590} 591 592proc configure_entry {w option items} { 593 foreach i $items { 594 $w.$i configure -state $option 595 } 596} 597 598proc validate_int {name val default} { 599 if {([exec echo $val | sed s/^-//g | tr -d \[:digit:\] ] != "")} then { 600 global $name; set $name $default 601 } 602} 603 604proc validate_hex {name val default} { 605 if {([exec echo $val | tr -d \[:xdigit:\] ] != "")} then { 606 global $name; set $name $default 607 } 608} 609 610proc update_define {first last allow_update} { 611 for {set i $first} {$i <= $last} {incr i} { 612 update_define_menu$i 613 if {$allow_update == 1} then update 614 } 615} 616 617# 618# Next set up the particulars for the top level menu, and define a few 619# buttons which we will stick down at the bottom. 620# 621 622frame .f0 623frame .f0.left 624frame .f0.middle 625frame .f0.right 626 627set active_menus [list] 628set processed_top_level 0 629

