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 / phase1.tcl < prev    next >
Text File  |  1998-09-19  |  10KB  |  379 lines

  1. # $XConsortium: phase1.tcl /main/3 1996/10/28 05:42:26 kaleb $
  2. #
  3. #
  4. #
  5. #
  6. # $XFree86: xc/programs/Xserver/hw/xfree86/XF86Setup/phase1.tcl,v 3.13.2.4 1998/02/26 13:58:59 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. # Phase I - Initial text mode interaction w/user and starting of VGA16 server
  16. #
  17.  
  18. set clicks1 [clock clicks]
  19.  
  20. # load the autoload stuff
  21. source $tcl_library/init.tcl
  22. # load language specific library
  23. source $XF86Setup_library/texts/local_text.tcl
  24. # load in our library
  25. source $XF86Setup_library/setuplib.tcl
  26. source $XF86Setup_library/filelist.tcl
  27. source $XF86Setup_library/carddata.tcl
  28. source $XF86Setup_library/mondata.tcl
  29.  
  30. proc find_dialog {} {
  31.     global env
  32.  
  33.     foreach dir [split $env(PATH) :] {
  34.         if { [file executable $dir/dialog] } {
  35.             # aha! found one, now let's test to make sure
  36.             set retval [catch {
  37.                 exec strings $dir/dialog \
  38.                 | grep infobox >& /dev/null }]
  39.             if {$retval == 0} {
  40.                 return $dir/dialog
  41.             }
  42.         }
  43.     }
  44.     return ""
  45. }
  46.  
  47. proc check_for_files { xwinhome } {
  48.     global FilePermsDescriptions FilePermsReadMe
  49.  
  50.     foreach var [array names FilePermsDescriptions] {
  51.         global FilePerms$var
  52.         foreach tmp [array names FilePerms$var] {
  53.         set pattern [lindex $tmp 0]
  54.         set perms   [lindex $tmp 1] ;# ignored (for now at least)
  55.         if ![llength [glob -nocomplain -- $xwinhome/$pattern]] {
  56.             set msg [format "Not all of the %s %s %s %s" \
  57.                 $FilePermsDescriptions($var) \
  58.                 "are installed. The file" \
  59.                 $xwinhome/$pattern "is missing"]
  60.             mesg [parafmt 65 $msg] okay
  61.             exit 1
  62.         }
  63.         }
  64.     }
  65.     foreach readme [array names FilePermsReadMe] {
  66.         set pattern [lindex $readme 0]
  67.         set perms   [lindex $readme 1] ;# ignored (for now at least)
  68.         if ![llength [glob -nocomplain -- $xwinhome/$pattern]] {
  69.         mesg [parafmt 65 "Warning! Not all of the READMEs are\
  70.             installed. You may not be able to view some of\
  71.             the instructions regarding setting up your card,\
  72.             but otherwise, everything should work correctly"] \
  73.             okay
  74.         break
  75.         }
  76.     }
  77. }
  78.  
  79. proc set_xf86config_defaults {} {
  80.     global Xwinhome ConfigFile
  81.     global Files Server Keyboard Pointer MonitorIDs DeviceIDs
  82.  
  83.     if {![catch {xf86config_readfile $Xwinhome files server \
  84.         keyboard mouse monitor device screen} tmp]} {
  85.     array set Files        [array get files]
  86.     array set Server    [array get Server]
  87.     array set Keyboard    [array get keyboard]
  88.     array set Pointer    [array get mouse]
  89.     foreach drvr { Mono VGA2 VGA16 SVGA Accel } {
  90.         global Scrn_$drvr
  91.         if [info exists screen_$drvr] {
  92.         array set Scrn_$drvr    [array get screen_$drvr]
  93.         } else {
  94.         set Scrn_${drvr}(Driver) ""
  95.         }
  96.     }
  97.     set MonitorIDs [set DeviceIDs ""]
  98.     set primon 0
  99.     set priname "Primary Monitor"
  100.     global Monitor_$priname
  101.     foreach mon [info vars monitor_*] {
  102.         set id [string range $mon 8 end]
  103.         global Monitor_$id
  104.         if { "$id" == "$priname" } {
  105.             set primon 1
  106.         } else {
  107.             array set Monitor_$id [array get Monitor_$priname]
  108.         }
  109.         lappend MonitorIDs $id
  110.         array set Monitor_$id    [array get monitor_$id]
  111.     }
  112.     if !$primon { global Monitor_$priname; unset Monitor_$priname }
  113.     set pridev 0
  114.     set priname "Primary Card"
  115.     global Device_$priname
  116.     foreach dev [info vars device_*] {
  117.         set id [string range $dev 7 end]
  118.         global Device_$id
  119.         if { "$id" == "$priname" } {
  120.             set pridev 1
  121.         } else {
  122.             array set Device_$id [array get Device_$priname]
  123.         }
  124.         lappend DeviceIDs $id
  125.         array set Device_$id    [array get device_$id]
  126.         set Device_${id}(Options) [set Device_${id}(Option)]
  127.         set Device_${id}(Server) NoMatch
  128.     }
  129.     if !$pridev { global Device_$priname; unset Device_$priname }
  130.     set fd [open $ConfigFile r]
  131.     set ws      "\[ \t\]"
  132.     set nqt     {[^"]}
  133.     set alnum   {[A-Z0-9]}
  134.     set idpat   "^$ws+\[Ii]\[Dd]$nqt+\"($nqt*)\""
  135.     set servpat "\"$nqt*\"$ws+##.*SERVER:$ws*($alnum+)"
  136.     while { [gets $fd line] >= 0 } {
  137.         set tmp [string toupper [zap_white $line] ]
  138.         if { [string compare $tmp {SECTION"DEVICE"}] == 0 } {
  139.         while { [gets $fd nextline] >= 0 } {
  140.             set upper [string toupper $nextline]
  141.             if { [regexp $idpat $nextline dummy id] } {
  142.             set found [regexp $servpat $upper dummy serv]
  143.             if $found {
  144.                 if { [string match XF86_* $serv] } {
  145.                     set serv [string range $serv 5 end]
  146.                 }
  147.                 set Device_${id}(Server) $serv
  148.             }
  149.             break
  150.             }
  151.             if ![string compare [string trim $upper] "ENDSECTION"] {
  152.             break
  153.             }
  154.         }
  155.         }
  156.     }
  157.     close $fd
  158.     global ServerList
  159.     foreach devid $DeviceIDs {
  160.         set varname Device_${devid}(Server)
  161.         if { ![info exists $varname] ||
  162.             [lsearch -exact $ServerList [set $varname]] < 0} {
  163.         set filename $Xwinhome/bin/X
  164.         for {set nlinks 0} \
  165.             {[file exists $filename] && \
  166.              [file type $filename]=="link" && $nlinks<20} \
  167.             {incr nlinks} {
  168.             set filename [readlink $filename]
  169.         }
  170.         set $varname [string range [file tail $filename] 5 end]
  171.         if { [lsearch -exact $ServerList [set $varname]] < 0
  172.             || $nlinks == 20} {
  173.             set $varname SVGA
  174.         }
  175.         }
  176.     }
  177.     } else {
  178.     mesg "Error encountered reading existing\
  179.         configuration file" okay
  180.     puts $tmp
  181.     exit 0
  182.     }
  183. }
  184.  
  185. if $NoDialog {
  186.     set Dialog ""
  187. } else {
  188.     set Dialog [find_dialog]
  189. }
  190.  
  191. check_for_files $Xwinhome
  192.  
  193. set ConfigFile [xf86config_findfile]
  194. set StartServer 1
  195. set ReConfig 0
  196. set UseConfigFile 0
  197. if { [string length $ConfigFile] > 0 } {
  198.     if [info exists env(DISPLAY)] {
  199.         set msg [format "%s\n \n%s\n \n%s" \
  200.                 [parafmt 65 "It appears that you are currently \
  201.                 running under X11. If this is correct \
  202.                 and you are interested in making some \
  203.                 adjustments to your current setup, \
  204.                 answer yes to the following question."] \
  205.                 [parafmt 65 "If this is incorrect or you \
  206.                 would like to go through the full \
  207.                 configuration process, then answer no."] \
  208.                 "Is this a reconfiguration?" ]
  209.         set ReConfig [mesg $msg yesno]
  210.     }
  211.     if { $ReConfig } {
  212.         set UseConfigFile 1
  213.         set StartServer 0
  214.         if { [getuid] != 0 } {
  215.             set proceed [mesg "You are not running as\
  216.             root.\n\nSuperuser privileges are usually\
  217.             required to save any changes\nyou make\
  218.             in a directory that is searched by the\
  219.             server and\nare required to change the\
  220.             mouse device.\n\nWould you like\
  221.             to continue anyway?" yesno]
  222.             if !$proceed {
  223.                 exit 1
  224.             }
  225.         }
  226.     } else {
  227.         if { [getuid] != 0 } {
  228.             mesg "You need to be root to set the initial\
  229.             configuration with this program" okay
  230.             exit 1
  231.         }
  232. #        set UseConfigFile [mesg "Would you like to use the\
  233. #            existing XF86Config file for defaults?" yesno]
  234.     }
  235.     # initialize the configuration variables
  236.     initconfig $Xwinhome
  237.  
  238.     if { $UseConfigFile } {
  239.         set_xf86config_defaults
  240.     }
  241. } else {
  242.     set ConfigFile /etc/XF86Config
  243.     if { [getuid] != 0 } {
  244.         mesg "You need to be root to run this program" okay
  245.         exit 1
  246.     }
  247.     if $pc98 {
  248.         if { !$ReConfig && ![file exists $Xwinhome/bin/XF98_EGC]
  249.                         && ![file exists $Xwinhome/bin/XF98_NEC480] } {
  250.             mesg "Either the EGC server or the NEC480 server is required\n\
  251.             to run this program" okay
  252.             exit 1
  253.         }
  254.     }
  255.     # initialize the configuration variables
  256.     initconfig $Xwinhome
  257. }
  258.  
  259. set clicks2 [clock clicks]
  260.  
  261. if { ![getuid] } {
  262.     if { !$UseConfigFile } {
  263.     # Check for the SysV Xqueue mouse driver
  264.     if { [file exists /etc/conf/pack.d/xque]
  265.         && [file exists /usr/lib/mousemgr] } {
  266.         set xque [mesg "Would you like to use the Xqueue driver\n\
  267.             for mouse and keyboard input?" yesno]
  268.         if $xque {
  269.         set Keyboard(Protocol)    Xqueue
  270.         set Pointer(Protocol)    Xqueue
  271.         set Pointer(Device)    ""
  272.         }
  273.     }
  274.  
  275.     # Check for the SCO OsMouse
  276.     if { [file exists /etc/conf/pack.d/cn/class.h]
  277.         && [file exists /etc/conf/pack.d/ev] } {
  278.         set osmse [mesg "Would you like to use the system event\
  279.             queue for mouse input?" yesno]
  280.         if $osmse {
  281.         set Pointer(Protocol)    OsMouse
  282.         set Pointer(Device)    ""
  283.         }
  284.     }
  285.     }
  286. }
  287.  
  288. set PID [pid]
  289. if { [info exists env(TMPDIR)] } {
  290.     set XF86SetupDir $env(TMPDIR)/.XF86Setup$PID
  291. } else {
  292.     set XF86SetupDir /tmp/.XF86Setup$PID
  293. }
  294.  
  295.  
  296. if ![mkdir $XF86SetupDir 0700] {
  297.     mesg "Unable to make directory $XF86SetupDir\n\
  298.          for storing temporary files" okay
  299.     exit 1
  300. }
  301.  
  302. set rand1 [random 1073741823]
  303. random seed [expr $clicks2-$clicks1]
  304. set rand2 [random 1073741823]
  305.  
  306. set TmpDir /tmp/[format "%x-%x" $rand1 $rand2]
  307. if ![mkdir $TmpDir 0700] {
  308.     mesg "Unable to make directory $TmpDir\n\
  309.          for storing temporary files" okay
  310.     exit 1
  311. }
  312. check_tmpdirs
  313.  
  314. if { ![getuid] } {
  315.     if [string length $Pointer(Device)] {
  316.         if {[file exists $Pointer(Device)]
  317.             && [file type $Pointer(Device)] == "link" } {
  318.             set Pointer(RealDev) [readlink $Pointer(Device)]
  319.             set Pointer(OldLink) $Pointer(Device)
  320.             if ![string compare $Pointer(RealDev) "/dev/psaux"] {
  321.             set Pointer(Protocol) "PS/2"
  322.         }
  323.         } else {
  324.         set Pointer(RealDev) $Pointer(Device)
  325.         }
  326.         set Pointer(Device) $TmpDir/mouse
  327.     }
  328.     if [info exists Pointer(RealDev)] {
  329.         link $Pointer(RealDev) $Pointer(Device)
  330.     }
  331. }
  332.  
  333. set Confname $TmpDir/Config
  334.  
  335. if $StartServer {
  336.     # write out a temp XF86Config file
  337.     if !$pc98 {
  338.         writeXF86Config $Confname-1 -vgamode -generic
  339.     } else {
  340.         writeXF86Config $Confname-1 -vgamode
  341.     }
  342.  
  343.     set vbeConfig [vbe_getconfiginfo]
  344.     mesg "SciTech Nucleus driver version [vbe_getversion] detected.\n\
  345.               Manufacturer: [lindex $vbeConfig 0]\n\
  346.               Chipset: [lindex $vbeConfig 1]\n\
  347.               DAC: [lindex $vbeConfig 2]\n\
  348.               Driver version: [lindex $vbeConfig 4]\n\n\
  349.               Press \[Enter\] to switch to graphics mode.\n\
  350.               \nThis may take a while..." okay
  351.  
  352.     if !$pc98 {
  353.         set ServerPID [start_server SDD $Confname-1 ServerOut-1]
  354.     } else {
  355.         if !$pc98_EGC {
  356.         set ServerPID [start_server NEC480 $Confname-1 ServerOut-1]
  357. #        if {$ServerPID == 0 || $ServerPID == -1} {
  358. #            puts "Unable to start NEC480 server!\n\
  359. #                try to start EGC server.\n";
  360. #            set pc98_EGC 1;
  361. #        }
  362.             } else {
  363.         set ServerPID [start_server EGC $Confname-1 ServerOut-1]
  364.         }
  365.     }
  366.  
  367.     if { $ServerPID == 0 } {
  368.         mesg "Unable to start X server!" info
  369.         exit 1
  370.     }
  371.     if { $ServerPID == -1 } {
  372.         mesg "Unable to communicate with X server!" info
  373.         exit 1
  374.     }
  375. } else {
  376.     mesg "Please wait\n\nThis may take a while..." info
  377. }
  378.  
  379.