Fix reported Samba bug.
[linux-2.6/linux-mips.git] / scripts / header.tk
blob94963425a9a59760547417e3e753db0d96066c4c
1 # FILE: header.tk
2 # This file is boilerplate TCL/TK function definitions for 'make xconfig'.
4 # CHANGES
5 # =======
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
30 # defined.
32 proc vfix { var } {
33         global $var
34         if [ catch {eval concat $$var} ] {
35                 set $var 4
36         }
40 # Constant values used by certain dep_tristate commands.
42 set CONSTANT_Y 1
43 set CONSTANT_M 2
44 set CONSTANT_N 0
45 set CONSTANT_E 4
48 # Create a "reference" object to steal colors from.
50 button .ref
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 } {
66         wm title . "$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 {
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
85 proc 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" 
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
113 bind all <Alt-q> {maybe_exit .maybe}
115 proc maybe_exit { w } {
116         catch {destroy $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?" 
125         set oldFocus [focus]
126         frame $w.f
127         button $w.f.back -text "OK" -width 20 \
128                 -command "exit"
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"
135         focus $w
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 } {
142         global loadfile
143         if { [string length $loadfile] != 0 && [file readable $loadfile] == 1 } then {
144                 read_config $loadfile
145         } else {
146                 catch {destroy $w}
147                 toplevel $w -class Dialog
148                 message $w.m -width 400 -aspect 300 -text \
149                         "Unable to read file $loadfile" \
150                          -relief raised 
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" 
155                 set oldFocus [focus]
156                 frame $w.f
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
161                 focus $w
162                 global winx; global winy
163                 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
164                 wm geometry $w +$winx+$winy
165         }
168 proc write_config_file  { w } {
169         global loadfile
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
173         } else {
174                 catch {destroy $w}
175                 toplevel $w -class Dialog
176                 message $w.m -width 400 -aspect 300 -text \
177                         "Unable to write file $loadfile" \
178                          -relief raised 
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" 
183                 set oldFocus [focus]
184                 frame $w.f
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
189                 focus $w
190                 global winx; global winy
191                 set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
192                 wm geometry $w +$winx+$winy
193         }
196 proc read_config { filename } {
197         set file1 [open $filename r]
198         clear_choices
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" }
204                         eval $cmd
205                 }
206                 if [regexp {# ([0-9A-Za-z_]+) is not set} $line foo var] {
207                         set cmd "global $var; set $var 0"
208                         eval $cmd
209                 }
210                 if [regexp {([0-9A-Za-z_]+)=([0-9A-Fa-f]+)} $line foo var value] {
211                         set cmd "global $var; set $var $value"
212                         eval $cmd
213                 }
214                 if [regexp {([0-9A-Za-z_]+)="([^"]*)"} $line foo var value] {
215                         set cmd "global $var; set $var \"$value\""
216                         eval $cmd
217                 }
218         }
219         close $file1
220         update_choices
221         update_mainmenu
223 proc write_comment { file1 file2 text } {
224         puts $file1 ""
225         puts $file1 "#"
226         puts $file1 "# $text"
227         puts $file1 "#"
228         puts $file2 "/*"
229         puts $file2 " * $text"
230         puts $file2 " */"
233 proc effective_dep { deplist } {
234         global CONFIG_MODULES
235         set depend 1
236         foreach i $deplist {
237                 if {$i == 0} then {set depend 0}
238                 if {$i == 2 && $depend == 1} then {set depend 2}
239         }
240         if {$depend == 2 && $CONFIG_MODULES == 0} then {set depend 0}
241         return $depend
244 proc sync_tristate { var dep } {
245         global CONFIG_MODULES
246         if {$dep == 0 && ($var == 1 || $var == 2)} then {
247                 set var 0
248         } elseif {$dep == 2 && $var == 1} then {
249                 set var 2
250         } elseif {$var == 2 && $CONFIG_MODULES == 0} then {
251                 if {$dep == 1} then {set var 1} else {set var 0}
252         }
253         return $var
256 proc sync_bool { var dep modset } {
257         set var [sync_tristate $var $dep]
258         if {$dep == 2 && $var == 2} then {
259                 set var $modset
260         }
261         return $var
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"} \
278         else { \
279             puts stdout "ERROR - Attempting to write value for unconfigured variable ($varname)." \
280         }
283 proc write_int { file1 file2 varname variable dep } {
284         if { $dep == 0 } \
285                 then { puts $file1 "# $varname is not set"; \
286                        puts $file2 "#undef  $varname"} \
287         else {
288                 puts $file1 "$varname=$variable"; \
289                 puts $file2 "#define $varname ($variable)"; \
290         }
293 proc write_hex { file1 file2 varname variable dep } {
294         if { $dep == 0 } \
295                 then { puts $file1 "# $varname is not set"; \
296                        puts $file2 "#undef  $varname"} \
297         else {
298                 puts $file1 "$varname=$variable"; \
299                 puts -nonewline $file2 "#define $varname 0x"; \
300                 puts $file2 [exec echo $variable | sed s/^0\[xX\]//]; \
301         }
304 proc write_string { file1 file2 varname variable dep } {
305         if { $dep == 0 } \
306                 then { puts $file1 "# $varname is not set"; \
307                        puts $file2 "#undef  $varname"} \
308         else {
309                 puts $file1 "$varname=\"$variable\""; \
310                 puts $file2 "#define $varname \"$variable\""; \
311         }
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
352         }
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 } {
376         frame $w.x$line
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 } {
389         frame $w.x$line
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 } {
398         frame $w.x$line
399         menubutton $w.x$line.x -textvariable $variable -menu \
400                 $w.x$line.x.menu -relief raised \
401                 -anchor w
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} {
408         if { $n > 2 } then {
409                 update idletasks
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
415                 }
416         }
419 proc menutitle {text menu w} {
420         wm title $w "$text"
423 proc submenu { w mnum line text subnum } {
424         frame $w.x$line
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 } {
436         frame $w.x$line
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}  {
449         catch {destroy $w}
450         toplevel $w -class Dialog
452         set filefound 0
453         set found 0
454         set lineno 0
456         if { [file readable Documentation/Configure.help] == 1} then {
457                 set filefound 1
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 "
462                         /^$var\[        \]*\$/,\${
463                                 /^$var\[        \]*\$/c\\
464 ${var}:\\
466                                 /^#/b
467                                 /^\[^   \]/q
468                                 s/^  //
469                                 p
470                         }
471                         " Documentation/Configure.help]
472                 set found [expr [string length "$message"] > 0]
473         }
475         frame $w.f1
476         pack $w.f1 -fill both -expand on
478         # Do the OK button
479         #
480         set oldFocus [focus]
481         frame $w.f2
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"
492         frame $w.f1.f
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."
499                 } else {
500                 message $w.f1.f.m -width 400 -aspect 300 -relief flat -text \
501                         "No help available for $var"
502                 }
503                 label $w.f1.bm -bitmap error
504                 wm title $w "RTFM"
505         } else {
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" 
512         }
513         pack $w.f1.f.m -side left
514         pack $w.f1.bm $w.f1.f -side left -padx 10
516         focus $w
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] {
524                 set sizy $canvtotal
525         } else {
526                 set sizy [expr $maxy - $sizok]
527         }
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
532         update idletasks
534         set maxy [winfo screenheight .]
535         if [expr $sizok + $canvtotal < $maxy] {
536                 set sizy [expr $sizok + $canvtotal]
537         } else {
538                 set sizy $maxy
539         }
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 }
546 proc wrapup {w }  {
547         catch {destroy $w}
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'."
554         } else {
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.'"
557         }
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" 
562         set oldFocus [focus]
563         frame $w.f
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
568         focus $w
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} {
577         global active_menus
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
584         set max 0
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
588         }
589         foreach i $active_menus {
590                 if {[winfo exists .menu$i] == 0} then {
591                         unregister_active $i
592                 } else {
593                         update_menu$i
594                 }
595         }
596         update_define [expr $max + 1] $total_menus 1
597         update_mainmenu
600 proc configure_entry {w option items} {
601         foreach i $items {
602                 $w.$i configure -state $option
603         }
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
609         }
612 proc validate_hex {name val default} {
613         if {([exec echo $val | tr -d \[:xdigit:\] ] != "")} then {
614                 global $name; set $name $default
615         }
618 proc update_define {first last allow_update} {
619         for {set i $first} {$i <= $last} {incr i} {
620                 update_define_menu$i
621                 if {$allow_update == 1} then update
622         }
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.
630 frame .f0 
631 frame .f0.left
632 frame .f0.middle
633 frame .f0.right
635 set active_menus [list]
636 set processed_top_level 0