home *** CD-ROM | disk | FTP | other *** search
/ Freesoft 1999 February / Freesoft_1999-02_cd.bin / Recenz / Utility / DisplayDoctorLinux / scitech-display-doctor-1.0beta-3.i386.rpm / scitech-display-doctor-1.0beta.3.cpio.gz / scitech-display-doctor-1.0beta.3.cpio / usr / lib / nucleus / XF86Setup / setuplib.tcl < prev    next >
Text File  |  1998-09-19  |  22KB  |  730 lines

  1. # $XConsortium: setuplib.tcl /main/3 1996/10/25 10:21:33 kaleb $
  2. #
  3. #
  4. #
  5. #
  6. # $XFree86: xc/programs/Xserver/hw/xfree86/XF86Setup/setuplib.tcl,v 3.13.2.7 1998/02/28 08:54:10 dawes Exp $
  7. #
  8. # Copyright 1996 by Joseph V. Moss <joe@XFree86.Org>
  9. #
  10. # See the file "LICENSE" for information regarding redistribution terms,
  11. # and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13.  
  14. #
  15. # Library of routines used by XF86Setup
  16. #
  17.  
  18. # Initialize all the variables that hold configuration info
  19.  
  20. proc initconfig {xwinhome} {
  21.     global Files ServerFlags Keyboard Pointer
  22.     global "Monitor_Primary Monitor" "Device_Primary Card"
  23.     global DeviceIDs MonitorIDs OptionRefreshRate
  24.     global Scrn_Accel Scrn_Mono Scrn_VGA2 Scrn_VGA16 Scrn_SVGA Scrn_scitech
  25.     global pc98 pc98_EGC
  26.  
  27.     set fontdir  "$xwinhome/lib/X11/fonts"
  28.     set Files(FontPath)    [list $fontdir/misc:unscaled \
  29.           $fontdir/75dpi:unscaled $fontdir/100dpi:unscaled \
  30.           $fontdir/Type1 $fontdir/Speedo  \
  31.           $fontdir/misc $fontdir/75dpi $fontdir/100dpi ]
  32.     set Files(RGBPath)        $xwinhome/lib/X11/rgb
  33.     
  34.  
  35.     set ServerFlags(NoTrapSignals)            ""
  36.     set ServerFlags(DontZap)            ""
  37.     set ServerFlags(DontZoom)            ""
  38.     set ServerFlags(DisableVidModeExtension)    ""
  39.     set ServerFlags(AllowNonLocalXvidtune)        ""
  40.     set ServerFlags(DisableModInDev)        ""
  41.     set ServerFlags(AllowNonLocalModInDev)        ""
  42.  
  43.     set Keyboard(Protocol)        Standard
  44.     set Keyboard(ServerNumLock)    ""
  45.     foreach key { AutoRepeat LeftAlt RightAlt ScrollLock
  46.             RightCtl XLeds VTSysReq VTInit
  47.             XkbKeycodes XkbTypes XkbCompat
  48.             XkbSymbols XkbGeometry XkbKeymap } {
  49.         set Keyboard($key) ""
  50.     }
  51.     if !$pc98 {
  52.         set Keyboard(XkbDisable)    ""
  53.         set Keyboard(XkbRules)        xfree86
  54.         set Keyboard(XkbModel)        pc101
  55.         set Keyboard(XkbLayout)        us
  56.         set Keyboard(XkbVariant)    ""
  57.         set Keyboard(XkbOptions)    ""
  58.         set Pointer(Protocol)        Microsoft
  59.         set Pointer(Emulate3Buttons)    ""
  60.     } else {
  61.         set Keyboard(XkbDisable)    ""
  62.         set Keyboard(XkbRules)        xfree98
  63.         set Keyboard(XkbModel)        pc98
  64.         set Keyboard(XkbLayout)        nec/jp
  65.         set Keyboard(XkbVariant)    ""
  66.         set Keyboard(XkbOptions)    ""
  67.         set Pointer(Protocol)        BusMouse
  68.         set Pointer(Emulate3Buttons)    1
  69.     }
  70.  
  71.     set Pointer(Device)        /dev/mouse
  72.     set Pointer(BaudRate)        ""
  73.     set Pointer(Emulate3Timeout)    ""
  74.     set Pointer(ChordMiddle)    ""
  75.     set Pointer(SampleRate)        ""
  76.     set Pointer(Resolution)        ""
  77.     set Pointer(Buttons)        ""
  78.     set Pointer(ClearDTR)        ""
  79.     set Pointer(ClearRTS)        ""
  80.  
  81.     if !$pc98_EGC {
  82.         set id                "Primary Monitor"
  83.         set Monitor_${id}(VendorName)    Unknown
  84.         set Monitor_${id}(ModelName)    Unknown
  85.         set Monitor_${id}(HorizSync)    25-36
  86.         set Monitor_${id}(VertRefresh)    56-71
  87.         set Monitor_${id}(Gamma)    ""
  88.         set MonitorIDs [list $id]
  89.     } else {
  90.         set id                "Primary Monitor"
  91.         set Monitor_${id}(VendorName)    Unknown
  92.         set Monitor_${id}(ModelName)    Unknown
  93.         set Monitor_${id}(HorizSync)    24.8
  94.         set Monitor_${id}(VertRefresh)    56.4
  95.         set Monitor_${id}(Gamma)    ""
  96.         set MonitorIDs [list $id]
  97.     }
  98.     set id                "Primary Card"
  99.     set Device_${id}(VendorName)    Unknown
  100.     set Device_${id}(BoardName)    Unknown
  101.     if !$pc98 {
  102.         set Device_${id}(Server)    SDD
  103.         set Device_${id}(Options)    power_saver
  104.     } else {
  105.         if !$pc98_EGC {
  106.             set Device_${id}(Server)    NEC480
  107.         } else {
  108.             set Device_${id}(Server)    EGC
  109.         }
  110.         set uname [exec uname]
  111.         if {$uname == {FreeBSD}} {
  112.             set Pointer(Device)    /dev/mse0
  113.         } elseif {$uname == {NetBSD}} {
  114.             set Pointer(Device)    /dev/lms0
  115.         }
  116.     }
  117.     foreach key {Chipset Ramdac DacSpeed Clocks ClockChip
  118.             ClockProg Options VideoRam BIOSBase Membase
  119.             IOBase DACBase POSBase COPBase VGABase
  120.             Instance Speedup S3MNAdjust S3MClk S3RefClock
  121.             ExtraLines} {
  122.         set Device_${id}($key) ""
  123.     }
  124.     set DeviceIDs [list $id]
  125.  
  126.     set Scrn_Accel(Driver)        "Accel"
  127.     set Scrn_Accel(Device)        "Primary Card"
  128.     set Scrn_Accel(Monitor)        "Primary Monitor"
  129.     set Scrn_Accel(ScreenNo)    ""
  130.     set Scrn_Accel(BlankTime)    ""
  131.     set Scrn_Accel(SuspendTime)    ""
  132.     set Scrn_Accel(OffTime)        ""
  133.     set Scrn_Accel(DefaultColorDepth)    ""
  134.  
  135.     set Scrn_scitech(Driver)        "scitech"
  136.     set Scrn_scitech(Device)        "Primary Card"
  137.     set Scrn_scitech(Monitor)        "Primary Monitor"
  138.     set Scrn_scitech(ScreenNo)    ""
  139.     set Scrn_scitech(BlankTime)    ""
  140.     set Scrn_scitech(SuspendTime)    ""
  141.     set Scrn_scitech(OffTime)        ""
  142.     set Scrn_scitech(DefaultColorDepth)    "16"
  143.     set Scrn_scitech(DefaultRefreshRate)    "$OptionRefreshRate"
  144.  
  145.     if !$pc98 {
  146.         array set Scrn_Mono  [array get Scrn_Accel]
  147.         array set Scrn_VGA2  [array get Scrn_Accel]
  148.     }
  149.     array set Scrn_VGA16 [array get Scrn_Accel]
  150.     array set Scrn_SVGA  [array get Scrn_Accel]
  151.  
  152.     if !$pc98 {
  153.         set Scrn_Mono(Driver)        "Mono"
  154.         set Scrn_VGA2(Driver)        "VGA2"
  155.     }
  156.     set Scrn_SVGA(Driver)        "SVGA"
  157.     set Scrn_VGA16(Driver)        "VGA16"
  158.  
  159.     if !$pc98 {
  160.         set Scrn_Mono(Depth,1)        1
  161.         set Scrn_VGA2(Depth,1)        1
  162.     }
  163.     set Scrn_VGA16(Depth,4)        4
  164.  
  165.     foreach depth {8 15 16 24 32} {
  166.         set Scrn_SVGA(Depth,$depth)    $depth
  167.         set Scrn_Accel(Depth,$depth)    $depth
  168.         set Scrn_scitech(Depth,$depth)    $depth
  169.     }
  170. }
  171.  
  172.  
  173. proc compare_modes { m1 m2 } {
  174.     scan $m1 "%d%*c%d" m1x m1y
  175.     scan $m2 "%d%*c%d" m2x m2y
  176.     return [expr $m1x*$m1y - $m2x*$m2y ]
  177. }
  178.  
  179. # Write a XF86Config file to the given fd
  180.  
  181. proc writeXF86Config {filename args} {
  182.     global Files ServerFlags Keyboard Pointer
  183.     global MonitorIDs DeviceIDs MonitorStdModes SelectedMonitorModes
  184.     global Scrn_Accel Scrn_Mono Scrn_VGA2 Scrn_VGA16 Scrn_SVGA Scrn_scitech
  185.     global pc98 pc98_EGC haveSelectedModes DefaultColorDepth
  186.  
  187.     check_tmpdirs
  188.     set fd [open $filename w]
  189.     puts $fd "# XF86Config auto-generated by XF86Setup"
  190.     puts $fd "#"
  191.     puts $fd "# Copyright (c) 1996 by The XFree86 Project, Inc.\n"
  192.     puts $fd "#"
  193.     puts $fd "# Permission is hereby granted, free of charge, to any person obtaining a"
  194.     puts $fd {# copy of this software and associated documentation files (the "Software"),}
  195.     puts $fd "# to deal in the Software without restriction, including without limitation"
  196.     puts $fd "# the rights to use, copy, modify, merge, publish, distribute, sublicense,"
  197.     puts $fd "# and/or sell copies of the Software, and to permit persons to whom the"
  198.     puts $fd "# Software is furnished to do so, subject to the following conditions:"
  199.     puts $fd "#"
  200.     puts $fd "# The above copyright notice and this permission notice shall be included in"
  201.     puts $fd "# all copies or substantial portions of the Software."
  202.     puts $fd "#"
  203.     puts $fd {# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR}
  204.     puts $fd "# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,"
  205.     puts $fd "# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL"
  206.     puts $fd "# THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,"
  207.     puts $fd "# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF"
  208.     puts $fd "# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE"
  209.     puts $fd "# SOFTWARE."
  210.     puts $fd "#"
  211.     puts $fd "# Except as contained in this notice, the name of the XFree86 Project shall"
  212.     puts $fd "# not be used in advertising or otherwise to promote the sale, use or other"
  213.     puts $fd "# dealings in this Software without prior written authorization from the"
  214.     puts $fd "# XFree86 Project."
  215.     puts $fd "#"
  216.     puts $fd ""
  217.     puts $fd "# See 'man XF86Config' for info on the format of this file"
  218.  
  219.     puts $fd ""
  220.     puts $fd {Section "Files"}
  221.     puts $fd "   RgbPath    \"$Files(RGBPath)\""
  222.     foreach path $Files(FontPath) {
  223.         puts $fd "   FontPath   \"$path\""
  224.     }
  225.     puts $fd "EndSection"
  226.  
  227.     puts $fd ""
  228.     puts $fd {Section "ServerFlags"}
  229.     puts $fd "   # Uncomment this to cause a core dump at the spot where a signal is "
  230.     puts $fd "   # received.  This may leave the console in an unusable state, but may"
  231.     puts $fd "   # provide a better stack trace in the core dump to aid in debugging"
  232.     puts $fd "   #NoTrapSignals\n"
  233.         
  234.     puts $fd "   # Uncomment this to disable the <Crtl><Alt><BS> server abort sequence"
  235.     puts $fd "   # This allows clients to receive this key event."
  236.     puts $fd "   #DontZap\n"
  237.         
  238.     puts $fd "   # Uncomment this to disable the <Crtl><Alt><KP_+>/<KP_-> mode switching"
  239.     puts $fd "   # sequences.  This allows clients to receive these key events."
  240.     puts $fd "   #DontZoom"
  241.         
  242.  
  243.     foreach key {NoTrapSignals DontZap DontZoom} {
  244.         if { [string length $ServerFlags($key)] } {
  245.             puts "   $ServerFlags($key)"
  246.         }
  247.     }
  248.     puts $fd "EndSection"
  249.  
  250.     puts $fd ""
  251.     puts $fd {Section "Keyboard"}
  252.     puts $fd "   Protocol        \"$Keyboard(Protocol)\""
  253.     set xkbvars ""
  254.     foreach key [array names Keyboard {Xkb[ABCE-Z]*}] {
  255.         append xkbvars $Keyboard($key)
  256.     }
  257.     if { ![string length $xkbvars]
  258.             && [string length $Keyboard(ServerNumLock)] } {
  259.         puts $fd "   ServerNumLock"
  260.     }
  261.     foreach key { AutoRepeat LeftAlt RightAlt ScrollLock RightCtl XLeds } {
  262.         if { [string length $Keyboard($key)] } {
  263.             puts $fd [format "   %-15s %s" $key $Keyboard($key)]
  264.         }
  265.     }
  266.     foreach key { XkbKeycodes XkbTypes XkbCompat
  267.         XkbSymbols XkbGeometry XkbKeymap
  268.         XkbRules XkbModel XkbLayout XkbVariant XkbOptions} {
  269.         if { [string length $Keyboard($key)] } {
  270.             puts $fd [format "   %-15s \"%s\"" \
  271.                 $key $Keyboard($key)]
  272.         }
  273.     }
  274.     #if { [string length $Keyboard(XkbDisable)] } {
  275.     #    puts $fd "   XkbDisable"
  276.     #}
  277.     if { [string length $Keyboard(VTInit)] } {
  278.         puts $fd "   VTInit         \"$Keyboard(VTInit)\""
  279.     }
  280.     if { [string length $Keyboard(VTSysReq)] } {
  281.         puts $fd "   VTSysReq"
  282.     }
  283.     puts $fd "EndSection"
  284.  
  285.     puts $fd ""
  286.     puts $fd {Section "Pointer"}
  287.     puts $fd "   Protocol        \"$Pointer(Protocol)\""
  288.     if { [lsearch -exact $args -realdevice] >= 0 
  289.             && [info exists Pointer(RealDev)] } {
  290.         set realdev $Pointer(RealDev)
  291.     } else {
  292.         set realdev ""
  293.     }
  294.     if { [string length $realdev] } {
  295.         if {[info exists Pointer(OldLink)]
  296.             && ![string compare [readlink $Pointer(OldLink)] $realdev]} {
  297.             puts $fd "   Device          \"$Pointer(OldLink)\""
  298.         } else {
  299.             puts $fd "   Device          \"$realdev\""
  300.         }
  301.     } elseif { [string length $Pointer(Device)] } {
  302.         puts $fd "   Device          \"$Pointer(Device)\""
  303.     }
  304.     foreach key {BaudRate Emulate3Timeout SampleRate Resolution Buttons} {
  305.         if { [string length $Pointer($key)] && $Pointer($key) } {
  306.             puts $fd [format "   %-15s %s" $key $Pointer($key)]
  307.         }
  308.     }
  309.     foreach key {Emulate3Buttons ChordMiddle ClearDTR ClearRTS} {
  310.         if { [string length $Pointer($key)] } {
  311.             puts $fd "   $key"
  312.         }
  313.     }
  314.     puts $fd "EndSection"
  315.  
  316.     set modeNames ""
  317.     foreach id $MonitorIDs {
  318.         global Monitor_$id
  319.         puts $fd ""
  320.         puts $fd {Section "Monitor"}
  321.         puts $fd "   Identifier      \"$id\""
  322.         if { [string length [set Monitor_${id}(VendorName)]] } {
  323.         puts $fd "   VendorName      \"[set Monitor_${id}(VendorName)]\""
  324.         }
  325.         if { [string length [set Monitor_${id}(ModelName)]] } {
  326.         puts $fd "   ModelName       \"[set Monitor_${id}(ModelName)]\""
  327.         }
  328.         puts $fd "   HorizSync       [set Monitor_${id}(HorizSync)]"
  329.         puts $fd "   VertRefresh     [set Monitor_${id}(VertRefresh)]"
  330.         if { [string length [set Monitor_${id}(Gamma)]] } {
  331.         puts $fd "   Gamma           [set Monitor_${id}(Gamma)]"
  332.         }
  333.         set modepattern "None"
  334.         if { [lsearch -exact $args -vgamode] >= 0 } {
  335.         if !$pc98_EGC {
  336.             set modepattern " 640x480*"
  337.         } else {
  338.             set modepattern " 640x400*"
  339.         }
  340.         }
  341.         if { [lsearch -exact $args -defaultmodes] >= 0 } {
  342.         set modepattern "*"
  343.         }
  344.         if { [string compare None $modepattern] != 0} {
  345.         if { $haveSelectedModes <= 0 } {
  346. #            puts stderr "No selected modes"
  347.             foreach desc [lsort -decreasing \
  348.                       [array names MonitorStdModes $modepattern]] {
  349.             set modeline $MonitorStdModes($desc)
  350.             puts $fd "# $desc"
  351.             set id [format "%dx%d" \
  352.                     [lindex $modeline 1] [lindex $modeline 5]]
  353.             puts $fd [format "   Modeline  %-11s %s" \
  354.                       "\"$id\""  $modeline]
  355.             lappend modeNames $id
  356.             }
  357.         } else {
  358.             foreach desc [lsort -decreasing \
  359.                 [array names SelectedMonitorModes $modepattern]] {
  360.             set modeline $SelectedMonitorModes($desc)
  361.             if ![string match \#removed $modeline] {
  362.                 puts $fd "# $desc"
  363.                 set id [format "%dx%d" \
  364.                     [lindex $modeline 1] [lindex $modeline 5]]
  365.                 puts $fd [format "   Modeline  %-11s %s" \
  366.                       "\"$id\""  $modeline]
  367.                 lappend modeNames $id
  368.             }
  369.             }
  370.         }
  371.         } else {
  372.         set dispof [lsearch -exact $args -displayof]
  373.         if { $dispof >= 0 } {
  374.             set dispwin [lindex $args [expr $dispof+1]]
  375.             set modelist [xf86vid_getallmodelines \
  376.                 -displayof $dispwin]
  377.         } else {
  378.             set modelist [xf86vid_getallmodelines]
  379.         }
  380.         foreach modeline $modelist {
  381.             set id [format "%dx%d" \
  382.                 [lindex $modeline 1] [lindex $modeline 5]]
  383.             puts $fd [format "   Modeline  %-11s %s" \
  384.                 "\"$id\""  $modeline]
  385.             lappend modeNames $id
  386.         }
  387.         }
  388.         puts $fd "EndSection"
  389.     }
  390.  
  391.     set modesList [lrmdups -decreasing -command mode_compare $modeNames]
  392.  
  393.     foreach id $DeviceIDs {
  394.         global Device_$id
  395.         puts $fd ""
  396.         puts $fd {Section "Device"}
  397.         puts $fd "   Identifier      \"$id\""
  398.         foreach key {VendorName BoardName Ramdac Speedup} {
  399.         if { [string length [set Device_${id}($key)]] } {
  400.             puts $fd [format "   %-15s \"%s\"" \
  401.                 $key [set Device_${id}($key)] ]
  402.         }
  403.         }
  404.         if { [lsearch -exact $args -generic] < 0 } {
  405.         set chipset [set Device_${id}(Chipset)]
  406.         if { [string length $chipset] } {
  407.             puts $fd "   Chipset         \"$chipset\""
  408.         }
  409.         } else {
  410.         puts $fd "   Chipset         \"generic\""
  411.         }
  412.         puts $fd "   Option          \"power_saver\""
  413.         foreach opt [set Device_${id}(Options)] {
  414.         puts $fd "   Option          \"$opt\""
  415.         }
  416.         if { [lsearch -exact $args -noclocks] < 0 } {
  417.         set clockchip [set Device_${id}(ClockChip)]
  418.         if { [string length $clockchip] } {
  419.             puts $fd "   ClockChip       \"$clockchip\""
  420.         }
  421.         set clocks    [set Device_${id}(Clocks)]
  422.         if { [string length $clocks] } {
  423.             puts $fd "   Clocks          $clocks"
  424.         }
  425.         set clockprog [set Device_${id}(ClockProg)]
  426.         if { [string length $clockprog] } {
  427.             puts $fd "   ClockProg       $clockprog"
  428.         }
  429.         }
  430.         foreach key {DacSpeed VideoRam BIOSBase Membase IOBase
  431.             DACBase POSBase COPBase VGABase Instance
  432.             S3MNAdjust S3MClk S3RefClock} {
  433.         if { [string length [set Device_${id}($key)]] } {
  434.             puts $fd [format "   %-15s %s" \
  435.                 $key [set Device_${id}($key)] ]
  436.         }
  437.         }
  438.         if { [string length [set Device_${id}(ExtraLines)]] } {
  439.         puts $fd [set Device_${id}(ExtraLines)]
  440.         }
  441.         puts $fd "EndSection"
  442.     }
  443.  
  444.     foreach drvr {scitech Accel SVGA VGA16 VGA2 Mono} {
  445.  
  446.         if $pc98 {
  447.             if {![string compare $drvr "Mono"] || \
  448.                 ![string compare $drvr "VGA2"]} \
  449.                 continue
  450.         }
  451.         if { [string compare $drvr [set Scrn_${drvr}(Driver)]] } \
  452.             continue
  453.         puts $fd ""
  454.         puts $fd {Section "Screen"}
  455.         puts $fd "   Driver          \"$drvr\""
  456.         puts $fd "   Device          \"[set Scrn_${drvr}(Device)]\""
  457.         puts $fd "   Monitor         \"[set Scrn_${drvr}(Monitor)]\""
  458.         if { ![string compare $drvr "Accel"] ||
  459.              ![string compare $drvr "SVGA"] ||
  460.              ![string compare $drvr "scitech"]
  461.          } {
  462.             puts $fd "   DefaultColorDepth $DefaultColorDepth"
  463.         }
  464.         if { ![string compare $drvr "scitech" ] } {
  465.             puts $fd "   RefreshRate $Scrn_scitech(DefaultRefreshRate)"
  466.         }
  467.         
  468.         foreach key {ScreenNo BlankTime SuspendTime OffTime } {
  469.             if { [string length [set Scrn_${drvr}($key)]] } {
  470.             puts $fd [format "   %-15s %s" \
  471.                       $key [set Scrn_${drvr}($key)] ]
  472.             }
  473.         }
  474.         foreach depth {1 4 8 15 16 24 32} {
  475.             if [info exists Scrn_${drvr}(Depth,$depth)] {
  476.             puts $fd {   SubSection "Display"}
  477.             puts $fd "      Depth        $depth"
  478.             puts -nonewline $fd "      Modes       "
  479.             foreach mode [lsort -command compare_modes -decreasing $modesList] {
  480.                 puts -nonewline $fd " \"$mode\""
  481.             }
  482.             puts $fd ""
  483.                 if [info exists Scrn_${drvr}(Visual,$depth)] {
  484.                 puts $fd [format "      Visual       \"%s\"" \
  485.                 [set Scrn_${drvr}(Visual,$depth)] ]
  486.             }
  487.                 if { [lsearch -exact $args -vgamode] < 0 } {
  488.                     if [info exists Scrn_${drvr}(Virtual,$depth)] {
  489.                     puts $fd [format "      Virtual       %s" \
  490.                     [set Scrn_${drvr}(Virtual,$depth)] ]
  491.                 }
  492.                 }
  493.             foreach key {ViewPort White Black Weight
  494.                 InvertVCLK EarlySC BlankDelay} {
  495.                 if [info exists Scrn_${drvr}($key,$depth)] {
  496.                 puts $fd [format "      %-12s %s" \
  497.                     $key [set Scrn_${drvr}($key,$depth)] ]
  498.                 }
  499.             }
  500.             puts $fd "   EndSubSection"
  501.             }
  502.         }
  503.         puts $fd "EndSection"
  504.     }
  505.     close $fd
  506. }
  507.  
  508.  
  509. # compare two mode names of the form 0000x000
  510. #   horizontal width is compared first, then height
  511. proc mode_compare { itemA itemB } {
  512.     set Alist [split $itemA x]
  513.     set Blist [split $itemB x]
  514.     if { [lindex $Alist 0] == [lindex $Blist 0] } {
  515.         return [expr [lindex $Alist 1] - [lindex $Blist 1]]
  516.     }
  517.     return [expr [lindex $Alist 0] - [lindex $Blist 0]]
  518. }
  519.  
  520. proc set_resource_defaults {} {
  521.     # Colors chosen to work with the VGA16 server
  522.     option add *background            grey
  523.     option add *foreground            blue
  524.     option add *selectColor            cyan
  525.     option add *selectForeground        black
  526.     option add *disabledForeground        ""    ;# stippled
  527.     option add *highlightBackground        grey
  528.     option add *font            fixed
  529.     option add *Frame.highlightThickness    0
  530.     option add *Listbox.exportSelection    no
  531. }
  532.  
  533. proc create_main_window { w } {
  534.     global pc98_EGC
  535.  
  536.     toplevel $w
  537.     if !$pc98_EGC {
  538.         $w configure -height 480 -width 640 -highlightthickness 0
  539.     } else {
  540.         $w configure -height 400 -width 640 -highlightthickness 0
  541.     }
  542.     pack propagate $w no
  543.     wm geometry $w +0+0
  544.     if !$pc98_EGC {
  545.         #wm minsize $w 640 480
  546.     } else {
  547.         #wm minsize $w 640 400
  548.     }
  549. }
  550.  
  551. proc set_default_arrow_bindings { } {
  552.     foreach class {Button Checkbutton Radiobutton Entry} {
  553.         bind $class <Key-Down>    {focus [findfocuswindow %W y 15]}
  554.         bind $class <Key-Right>    {focus [findfocuswindow %W x 15]}
  555.         bind $class <Key-Up>    {focus [findfocuswindow %W y -15]}
  556.         bind $class <Key-Left>    {focus [findfocuswindow %W x -15]}
  557.     }
  558. }
  559.  
  560. proc start_server { server configfile outfile } {
  561.     global env TmpDir Xwinhome serverNumber pc98
  562.  
  563.     if { ![info exists serverNumber] } {
  564.         set serverNumber 7
  565.     } else {
  566.         incr serverNumber
  567.     }
  568.     set env(DISPLAY) [set disp :$serverNumber]
  569.  
  570.     if !$pc98 {
  571.         set pid [exec $Xwinhome/bin/XF86_$server $disp \
  572.             -allowMouseOpenFail -xf86config $configfile \
  573.             -bestRefresh >& $TmpDir/$outfile & ]
  574.     } else {
  575.         set pid [exec $Xwinhome/bin/XF98_$server $disp \
  576.             -allowMouseOpenFail -xf86config $configfile \
  577.             -bestRefresh >& $TmpDir/$outfile & ]
  578.     }
  579.  
  580.     sleep 9
  581.     set trycount 0
  582.     while { [incr trycount] < 10 } {
  583.         if ![process_running $pid] {
  584.             return 0
  585.         }
  586.         sleep 2
  587.         if [server_running $disp] {
  588.             return $pid
  589.         }
  590.     }
  591.     return -1
  592. }
  593.  
  594. proc clear_scrn {} {
  595.     global Dialog
  596.  
  597.     if { ![string length $Dialog] } {
  598.         set blank \n\n\n\n\n
  599.         puts $blank$blank$blank$blank$blank
  600.         flush stdout
  601.     } else {
  602.         catch {exec $Dialog --clear >&@stdout} ret
  603.     }
  604. }
  605.  
  606. proc mesg { text {buttontype okay} } {
  607.     global Dialog
  608.  
  609.     if { ![string length $Dialog] } {
  610.         puts $text
  611.         flush stdout
  612.         if { [string compare $buttontype yesno] == 0 } {
  613.             puts -nonewline "Okay (y/n)? "
  614.             flush stdout
  615.             gets stdin response
  616.             return [string match {[yY]} [string index $response 0]]
  617.         }
  618.         if { [string compare $buttontype okay] == 0 } {
  619.             puts -nonewline "Press \[Enter\] to continue..."
  620.             flush stdout
  621.             gets stdin response
  622.         }
  623.         return
  624.     }
  625.     # else
  626.     set textlist [split $text \n]
  627.     set height [expr [llength $textlist]+2]
  628.     if { [string compare $buttontype info] != 0 } {
  629.         incr height 2
  630.     }
  631.     set width 0
  632.     foreach line $textlist {
  633.         if { [string length $line] > $width } {
  634.             set width [string length $line]
  635.         }
  636.     }
  637.     incr width 6
  638.     set minwidth 12
  639.     if { [string compare $buttontype yesno] == 0 } {
  640.         set boxtype --yesno
  641.         incr width 2
  642.         set minwidth 25
  643.     } elseif { [string compare $buttontype okay] == 0 } {
  644.         set boxtype --msgbox
  645.     } else {
  646.         set boxtype --infobox
  647.     }
  648.     if { $width < $minwidth } {
  649.         set width $minwidth
  650.     }
  651.     set retval [catch {
  652.         exec $Dialog $boxtype $text $height $width >&@stdout
  653.     }]
  654.     return [expr $retval==0]
  655. }
  656.  
  657. proc save_state {} {
  658.     global env XF86SetupDir TmpDir StateFileName PID 
  659.     set StateFileName "$TmpDir/state"
  660.     check_tmpdirs
  661.     set fd [open $StateFileName w]
  662.  
  663.     global Dialog Confname ConfigFile UseConfigFile StartServer
  664.     global pc98
  665.  
  666.     puts $fd [list set Dialog $Dialog]
  667.     puts $fd [list set Confname $Confname]
  668.     puts $fd [list set ConfigFile $ConfigFile]
  669.     puts $fd [list set UseConfigFile $UseConfigFile]
  670.     puts $fd [list set StartServer $StartServer]
  671.     puts $fd [list set XF86SetupDir $XF86SetupDir]
  672.     puts $fd [list set TmpDir $TmpDir]
  673.     puts $fd [list set PID $PID]
  674.     global DeviceIDs MonitorIDs haveSelectedModes DefaultColorDepth
  675.     puts $fd [list set DeviceIDs $DeviceIDs]
  676.     puts $fd [list set MonitorIDs $MonitorIDs]
  677.     puts $fd [list set DefaultColorDepth $DefaultColorDepth]
  678.     puts $fd [list set haveSelectedModes $haveSelectedModes]
  679.     if !$pc98 {
  680.         set arrlist [list Files ServerFlags Keyboard Pointer \
  681.             SelectedMonitorModes MonitorStdModes \
  682.             Scrn_Accel Scrn_Mono Scrn_VGA2 Scrn_VGA16 Scrn_SVGA Scrn_scitech]
  683.     } else {
  684.         set arrlist [list Files ServerFlags Keyboard Pointer \
  685.             SelectedMonitorModes MonitorStdModes \
  686.             Scrn_Accel Scrn_VGA16 Scrn_SVGA]
  687.     }
  688.     foreach devid $DeviceIDs {
  689.         lappend arrlist Device_$devid
  690.     }
  691.     foreach monid $MonitorIDs {
  692.         lappend arrlist Monitor_$monid
  693.     }
  694.     foreach arrname $arrlist {
  695.         global $arrname
  696.         puts $fd [list array set $arrname [array get $arrname]]
  697.     }
  698.     close $fd
  699. }
  700.  
  701. proc shutdown {args} {
  702.     global env ExitStatus
  703.  
  704.     catch {destroy .}
  705.     catch {server_running -close $env(DISPLAY)}
  706.     if { [string length $args] } {
  707.         set ExitStatus $args
  708.     }
  709. }
  710.  
  711. proc check_tmpdirs {} {
  712.     global TmpDir XF86SetupDir
  713.  
  714.     file lstat $XF86SetupDir xfsdir
  715.     file lstat $TmpDir tmpdir
  716.     if {       [string compare $xfsdir(type) directory]
  717.         || [string compare $tmpdir(type) directory]
  718.         || $xfsdir(uid)  != [getuid]
  719.         || $tmpdir(uid)  != [getuid]
  720.         || $xfsdir(mode)&0077
  721.         || $tmpdir(mode)&0077 } \
  722.     {
  723.         mesg "The temporary files directory ($TmpDir)\n\
  724.             is no longer secure!"
  725.         shutdown 1
  726.         exit 1
  727.     }
  728. }
  729.  
  730.