linux-old/scripts/header.tk
<<
>>
Prefs
   1#
   2# This is a handy replacement for ".widget cget" that requires neither tk4
   3# nor additional source code uglification.
   4#
   5proc cget { w option } {
   6        return "[lindex [$w configure $option] 4]"
   7}
   8
   9#
  10# Function to compensate for broken config.in scripts like the sound driver,
  11# which make dependencies on variables that are never even conditionally
  12# defined.
  13#
  14proc vfix { var } {
  15        global $var
  16        if [ catch {eval concat $$var} ] {
  17                puts stdout "WARNING - broken Config.in!  $var was not declared!"
  18                set $var 0
  19        }
  20}
  21
  22#
  23# Create a "reference" object to steal colors from.
  24#
  25button .ref
  26#
  27# On monochrome displays, -disabledforeground is blank by default; that's
  28# bad.  Fill it with -foreground instead.
  29#
  30if { [cget .ref -disabledforeground] == "" } {
  31        .ref configure -disabledforeground [cget .ref -foreground]
  32}
  33
  34
  35#
  36# Define some macros we will need to parse the config.in file.
  37#
  38proc mainmenu_name { text } {
  39        message .header.message -width 400 -relief raised -text "$text"
  40        pack .header.label .header.message -side left -padx 15
  41        wm title . "$text"
  42}
  43
  44proc menu_option { w menu_num text } {
  45        button .f0.x$menu_num -text "$text" -width 50 -command "$w .$w \"$text\""
  46        pack .f0.x$menu_num -pady 1 -expand on
  47}
  48
  49#
  50# Not used at the moment, but this runs a command in a subprocess and
  51# displays the result in a window with a scrollbar.
  52#
  53# For now, we just do external "make" commands to stdout with do_make, so
  54# this function is never called.
  55#
  56proc do_cmd { w command } {
  57        catch {destroy $w}
  58        toplevel $w -class Dialog
  59        frame $w.tb
  60        text $w.tb.text -relief raised -bd 2 -yscrollcommand "$w.tb.scroll set"
  61        scrollbar $w.tb.scroll -command "$w.tb.text yview"
  62        pack $w.tb.scroll -side right -fill y
  63        pack $w.tb.text -side left
  64
  65        set oldFocus [focus]
  66        frame $w.back
  67        button $w.back.ok -text "OK" -width 20 \
  68                -command "destroy $w; focus $oldFocus" -state disabled
  69        button $w.back.ccl -text "Cancel" -width 20 \
  70                -command "destroy $w; focus $oldFocus"
  71        pack $w.tb -side top
  72        pack $w.back.ok $w.back.ccl -side left
  73        pack $w.back -side bottom -pady 10
  74
  75        focus $w
  76        wm geometry $w +30+35
  77
  78        $w.tb.text delete 1.0 end
  79        set f [open |$command]
  80        while {![eof $f]} {
  81                $w.tb.text insert end [read $f 256]
  82        }
  83        close $f
  84        $w.back.ok configure -state normal
  85}
  86
  87proc load_configfile { w title func } {
  88        catch {destroy $w}
  89        toplevel $w -class Dialog
  90        global loadfile
  91        frame $w.x
  92        label $w.bm -bitmap questhead
  93        pack  $w.bm -pady 10 -side top -padx 10
  94        label $w.x.l -text "Enter filename:" -relief raised
  95        entry $w.x.x -width 35 -relief sunken -borderwidth 2 \
  96                -textvariable loadfile
  97        pack $w.x.l $w.x.x -anchor w -side left
  98        pack $w.x -side top -pady 10
  99        wm title $w "$title" 
 100
 101        set oldFocus [focus]
 102        frame $w.f
 103        button $w.f.back -text "OK" -width 20 \
 104                -command "destroy $w; focus $oldFocus;$func .fileio"
 105        button $w.f.canc -text "Cancel" \
 106                -width 20 -command "destroy $w; focus $oldFocus"
 107        pack $w.f.back $w.f.canc -side left -pady 10 -padx 45
 108        pack $w.f -pady 10 -side bottom -padx 10 -anchor w
 109        focus $w
 110        global winx; global winy
 111        set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
 112        wm geometry $w +$winx+$winy
 113}
 114
 115proc 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?" 
 124
 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        focus $w
 134        global winx; global winy
 135        set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
 136        wm geometry $w +$winx+$winy
 137}
 138
 139proc read_config_file { w } {
 140        global loadfile
 141        if { [string length $loadfile] != 0 && [file readable $loadfile] == 1 } then {
 142                read_config $loadfile
 143        } else {
 144                catch {destroy $w}
 145                toplevel $w -class Dialog
 146                message $w.m -width 400 -aspect 300 -text \
 147                        "Unable to read file $loadfile" \
 148                         -relief raised 
 149                label $w.bm -bitmap error
 150                pack $w.bm $w.m -pady 10 -side top -padx 10
 151                wm title $w "Oops" 
 152
 153                set oldFocus [focus]
 154                frame $w.f
 155                button $w.f.back -text "Bummer" \
 156                        -width 10 -command "destroy $w; focus $oldFocus"
 157                pack $w.f.back -side bottom -pady 10 -anchor s
 158                pack $w.f -pady 10 -side top -padx 10 -anchor s
 159                focus $w
 160                global winx; global winy
 161                set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
 162                wm geometry $w +$winx+$winy
 163        }
 164}
 165
 166proc write_config_file  { w } {
 167        global loadfile
 168        if { [string length $loadfile] != 0 
 169                && ([file writable $loadfile] == 1 || ([file exists $loadfile] == 0 && [file writable [file dirname $loadfile]] == 1)) } then {
 170                writeconfig $loadfile /dev/null
 171        } else {
 172                catch {destroy $w}
 173                toplevel $w -class Dialog
 174                message $w.m -width 400 -aspect 300 -text \
 175                        "Unable to write file $loadfile" \
 176                         -relief raised 
 177                label $w.bm -bitmap error
 178                pack $w.bm $w.m -pady 10 -side top -padx 10
 179                wm title $w "Oops" 
 180
 181                set oldFocus [focus]
 182                frame $w.f
 183                button $w.f.back -text "OK" \
 184                        -width 10 -command "destroy $w; focus $oldFocus"
 185                pack $w.f.back -side bottom -pady 10 -anchor s
 186                pack $w.f -pady 10 -side top -padx 10 -anchor s
 187                focus $w
 188                global winx; global winy
 189                set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
 190                wm geometry $w +$winx+$winy
 191        }
 192}
 193
 194proc read_config { filename } {
 195        set file1 [open $filename r]
 196        clear_choices
 197        while { [gets $file1 line] >= 0} {
 198                if [regexp {([0-9A-Za-z_]+)=([ynm])} $line foo var value] {
 199                        if { $value == "y" } then { set cmd "global $var; set $var 1" }
 200                        if { $value == "n" } then { set cmd "global $var; set $var 0" }
 201                        if { $value == "m" } then { set cmd "global $var; set $var 2" }
 202                        eval $cmd
 203                }
 204                if [regexp {# ([0-9A-Za-z_]+) is not set} $line foo var] {
 205                        set cmd "global $var; set $var 0"
 206                        eval $cmd
 207                }
 208                if [regexp {([0-9A-Za-z_]+)=([0-9A-Fa-f]+)} $line foo var value] {
 209                        set cmd "global $var; set $var $value"
 210                        eval $cmd
 211                }
 212                if [regexp {([0-9A-Za-z_]+)="([0-9A-Za-z]+)"} $line foo var value] {
 213                        set cmd "global $var; set $var $value"
 214                        eval $cmd
 215                }
 216        }
 217        close $file1
 218        update_choices
 219        update_mainmenu .rdupd
 220}
 221proc write_comment { file1 file2 text } {
 222        puts $file1 ""
 223        puts $file1 "#"
 224        puts $file1 "# $text"
 225        puts $file1 "#"
 226        puts $file2 "/*"
 227        puts $file2 " * $text"
 228        puts $file2 " */"
 229}
 230
 231proc write_tristate { file1 file2 varname variable dep } {
 232        if { $variable == 0 } \
 233                then { puts $file1 "# $varname is not set"; \
 234                       puts $file2 "#undef $varname"} \
 235        elseif { $variable == 2 || ($dep == 2 && $variable == 1) } \
 236                then { puts $file1 "$varname=m"; \
 237                       puts $file2 "#undef $varname"; \
 238                       puts $file2 "#define ${varname}_MODULE 1" } \
 239        elseif { $variable == 1 && $dep != 2 } \
 240                then { puts $file1 "$varname=y"; \
 241                       puts $file2 "#define $varname 1" } \
 242        else { \
 243            error "Attempting to write value for variable that is not configured ($varname)." \
 244        }
 245}
 246
 247proc write_int { file1 file2 varname variable dep } {
 248        if { $dep == 0 } \
 249                then { puts $file1 "# $varname is not set"; \
 250                       puts $file2 "#undef $varname"} \
 251        else {
 252                puts $file1 "$varname=$variable"; \
 253                puts $file2 "#define $varname $variable"; \
 254        }
 255}
 256
 257proc write_hex { file1 file2 varname variable dep } {
 258        if { $dep == 0 } \
 259                then { puts $file1 "# $varname is not set"; \
 260                       puts $file2 "#undef $varname"} \
 261        else {
 262                puts $file1 "$varname=$variable"; \
 263                puts $file2 "#define $varname 0x$variable"; \
 264        }
 265}
 266
 267proc write_string { file1 file2 varname variable dep } {
 268        if { $dep == 0 } \
 269                then { puts $file1 "# $varname is not set"; \
 270                       puts $file2 "#undef $varname"} \
 271        else {
 272                puts $file1 "$varname=\"$variable\""; \
 273                puts $file2 "#define $varname \"$variable\""; \
 274        }
 275}
 276
 277proc option_name {w mnum line text helpidx} {
 278        button $w.x$line.l -text "$text" -relief groove -anchor w
 279        $w.x$line.l configure -activefore [cget $w.x$line.l -fg] \
 280                                -activeback [cget $w.x$line.l -bg]
 281        button $w.x$line.help -text "Help" -relief raised \
 282                -command "dohelp .dohelp $helpidx"
 283        pack $w.x$line.help -side right -fill y
 284        pack $w.x$line.l -side right -fill both -expand on
 285}
 286
 287proc toggle_switch {w mnum line text variable} {
 288        frame $w.x$line -relief sunken
 289        radiobutton $w.x$line.y -text "y" -variable $variable -value 1 \
 290                -relief groove -width 2 -command "update_menu$mnum .menu$mnum"
 291        radiobutton $w.x$line.m -text "m"  -variable $variable -value 2 \
 292                -relief groove -width 2 -command "update_menu$mnum .menu$mnum"
 293        radiobutton $w.x$line.n -text "n"  -variable $variable -value 0 \
 294                -relief groove -width 2 -command "update_menu$mnum .menu$mnum"
 295                
 296        option_name $w $mnum $line $text $variable
 297                
 298        pack $w.x$line.n $w.x$line.m $w.x$line.y -side right -fill y
 299}
 300
 301proc bool {w mnum line text variable} {
 302        toggle_switch $w $mnum $line $text $variable
 303        $w.x$line.m configure -state disabled
 304        pack $w.x$line -anchor w -fill both -expand on
 305}
 306
 307proc tristate {w mnum line text variable } {
 308        toggle_switch $w $mnum $line $text $variable
 309        pack $w.x$line -anchor w -fill both -expand on
 310}
 311
 312proc dep_tristate {w mnum line text variable depend } {
 313        tristate $w $mnum $line $text $variable
 314}
 315
 316proc int { w mnum line text variable } {
 317        frame $w.x$line
 318        entry $w.x$line.x -width 18 -relief sunken -borderwidth 2 \
 319                -textvariable $variable
 320        option_name $w $mnum $line $text $variable
 321        pack $w.x$line.x -anchor w -side right -fill y
 322        pack $w.x$line -anchor w -fill both -expand on
 323}
 324
 325proc hex { w mnum line text variable } {
 326        int $w $mnum $line $text $variable
 327}
 328
 329proc istring { w mnum line text variable } {
 330        frame $w.x$line
 331        entry $w.x$line.x -width 18 -relief sunken -borderwidth 2 \
 332                -textvariable $variable
 333        option_name $w $mnum $line $text $variable
 334        pack $w.x$line.x -anchor w -side right -fill y
 335        pack $w.x$line -anchor w -fill both -expand on
 336}
 337
 338proc minimenu { w mnum line text variable helpidx } {
 339        frame $w.x$line
 340        menubutton $w.x$line.x -textvariable $variable -menu \
 341                $w.x$line.x.menu -relief raised \
 342                -width 15 -anchor w
 343        option_name $w $mnum $line $text $helpidx
 344        pack $w.x$line.x -anchor w -side right -fill y
 345        pack $w.x$line -anchor w -fill both -expand on
 346}
 347
 348proc comment {w line text } {
 349#nothing done for comments now.
 350}
 351
 352proc do_make { command } {
 353        exec sh -c $command <@stdin >@stdout 2>@stderr
 354#       do_cmd .make_window "sh -c $command"
 355}
 356
 357proc dohelp {w var }  {
 358        catch {destroy $w}
 359        toplevel $w -class Dialog
 360
 361        set filefound 0
 362        set found 0
 363        set lineno 0
 364
 365        if { [file readable Documentation/Configure.help] == 1} then {
 366                set filefound 1
 367                set message [exec sed -n "
 368                        /^$var\[        \]*\$/,\${
 369                                /^$var\[        \]*\$/c\\
 370${var}:\\
 371
 372                                /^#.*/d
 373                                /^\[    \]*\$/bL
 374                                H
 375                        }
 376                        d
 377                        :L x
 378                        s/\\n  //
 379                        s/\\n  / /g
 380                        p
 381                        q
 382                        " Documentation/Configure.help]
 383                set found [expr [string length "$message"] > 0]
 384        }
 385        
 386        frame $w.f1
 387
 388        if { $found == 0 } then {
 389                if { $filefound == 0 } then {
 390                message $w.f1.m -width 750 -aspect 300 -relief flat -text \
 391                        "No help available - unable to open file Documentation/Configure.help.  This file should have come with your kernel."
 392                } else {
 393                message $w.f1.m -width 400 -aspect 300 -relief flat -text \
 394                        "No help available for $var"
 395                }
 396                label $w.f1.bm -bitmap error
 397                wm title $w "RTFM"
 398        } else {
 399                message $w.f1.m -width 400 -aspect 300 -text $message \
 400                         -relief flat
 401                label $w.f1.bm -bitmap info
 402                wm title $w "Configuration help" 
 403        }
 404        pack $w.f1.bm $w.f1.m -side left -padx 10
 405        pack $w.f1 -side top
 406        set oldFocus [focus]
 407        
 408        # Do the OK button
 409        #
 410        frame $w.f2
 411        button $w.f2.ok -text "OK" \
 412                -width 10 -command "destroy $w; focus $oldFocus"
 413        pack $w.f2.ok -side bottom -pady 10 -anchor s
 414        pack $w.f2 -side bottom -padx 10 -anchor s
 415
 416        # Finish off the window
 417        #
 418        focus $w
 419        global winx; global winy
 420        set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
 421        wm geometry $w +$winx+$winy
 422}
 423
 424proc wrapup {w }  {
 425        catch {destroy $w}
 426        toplevel $w -class Dialog
 427        message $w.m -width 400 -aspect 300 -text \
 428                "The linux kernel is now hopefully configured for your setup. Check the top-level Makefile for additional configuration, and do a 'make dep ; make clean' if you want to be sure all the files are correctly re-made."  -relief raised 
 429        label $w.bm -bitmap info
 430        pack $w.bm $w.m -pady 10 -side top -padx 10
 431        wm title $w "Kernel build instructions" 
 432
 433        set oldFocus [focus]
 434        frame $w.f
 435        button $w.f.back -text "OK" \
 436                -width 10 -command "exit"
 437        pack $w.f.back -side bottom -pady 10 -anchor s
 438        pack $w.f -pady 10 -side top -padx 10 -anchor s
 439        focus $w
 440        global winx; global winy
 441        set winx [expr [winfo x .]+30]; set winy [expr [winfo y .]+30]
 442        wm geometry $w +$winx+$winy
 443
 444}
 445
 446proc check_sound_config { num } {
 447#nothing for now.
 448}
 449
 450proc do_sound {w mnum line} {
 451        message $w.x$line -width 400 -aspect 300 -text "Note: The sound drivers cannot as of yet be configured via the X-based interface" -relief raised
 452        pack $w.x$line -side top -pady 10
 453}
 454
 455#
 456# Next set up the particulars for the top level menu, and define a few
 457# buttons which we will stick down at the bottom.
 458#
 459frame .header
 460label .header.label 
 461
 462frame .f0 
 463
 464
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.