home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / x / xf86conf.c < prev    next >
C/C++ Source or Header  |  1995-10-10  |  46KB  |  1,552 lines

  1.  
  2. /*
  3.  * This is a dumb configuration program that will create a base
  4.  * XF86Config file based on menu choices. Its main feature is that
  5.  * clueless users may be less inclined to select crazy sync rates
  6.  * way over monitor spec, by presenting a menu with standard monitor
  7.  * types. Also some people don't read docs unless an executable that
  8.  * they can run tells them to.
  9.  *
  10.  * It assumes a 24-line or bigger text console.
  11.  *
  12.  * Revision history:
  13.  * 25Sep94 Initial version.
  14.  * 27Sep94 Fix hsync range of monitor types to match with best possible mode.
  15.  *         Remove 'const'.
  16.  *         Tweak descriptions.
  17.  * 28Sep94 Fixes from J"org Wunsch:
  18.  *           Don't use gets().
  19.  *           Add mouse device prompt.
  20.  *           Fix lines overrun for 24-line console.
  21.  *         Increase buffer size for probeonly output.
  22.  * 29Sep94 Fix bad bug with old XF86Config preserving during probeonly run.
  23.  *         Add note about vertical refresh in interlaced modes.
  24.  *         Name gets() replacement getstring().
  25.  *         Add warning about binary paths.
  26.  *         Fixes from David Dawes:
  27.  *           Don't use 'ln -sf'.
  28.  *           Omit man path reference in comment.
  29.  *           Generate only a generic 320x200 SVGA section for accel cards.
  30.  *         Only allow writing to /usr/X11R6/lib/X11 if root, and use
  31.  *           -xf86config for the -probeonly phase (root only).
  32.  *         Fix bug that forces screen type to accel in some cases.
  33.  * 30Sep94 Continue after clocks probe fails.
  34.  *         Note about programmable clocks.
  35.  *         Rename to 'xf86config'. Not to be confused with XF86Config
  36.  *           or the -xf86config option.
  37.  * 07Oct94 Correct hsync in standard mode timings comments, and include
  38.  *           the proper +/-h/vsync flags.
  39.  *
  40.  * Possible enhancements:
  41.  * - Add more standard mode timings (also applies to README.Config). Missing
  42.  *   are 1024x768 @ 72 Hz, 1152x900 modes, and 1280x1024 @ ~70 Hz.
  43.  *   I suspect there is a VESA standard for 1024x768 @ 72 Hz with 77 MHz dot
  44.  *   clock, and 1024x768 @ 75 Hz with 78.7 MHz dot clock.
  45.  *
  46.  */
  47.  
  48.  
  49. #include <stdlib.h>
  50. #include <stdio.h>
  51. #include <ctype.h>
  52. #include <string.h>
  53. #include <unistd.h>
  54.  
  55.  
  56.  
  57. /*
  58.  * Configuration variables.
  59.  */
  60.  
  61. #define MAX_CLOCKS_LINES 16
  62.  
  63. int config_mousetype;        /* Mouse. */
  64. int config_emulate3buttons;
  65. int config_chordmiddle;
  66. char *config_pointerdevice;
  67. int config_monitortype;        /* Monitor. */
  68. char *config_hsyncrange;
  69. char *config_vsyncrange;
  70. char *config_monitoridentifier;
  71. char *config_monitorvendorname;
  72. char *config_monitormodelname;
  73. int config_videomemory;
  74. int config_screentype;        /* mono, vga16, svga, accel */
  75. char *config_deviceidentifier;
  76. char *config_devicevendorname;
  77. char *config_deviceboardname;
  78. int config_numberofclockslines;
  79. char *config_clocksline[MAX_CLOCKS_LINES];
  80. char *config_modesline8bpp;
  81. char *config_modesline16bpp;
  82. char *config_modesline32bpp;
  83. int config_virtualx8bpp, config_virtualy8bpp;
  84. int config_virtualx16bpp, config_virtualy16bpp;
  85. int config_virtualx32bpp, config_virtualy32bpp;
  86.  
  87.  
  88. void write_XF86Config();
  89.  
  90.  
  91. /*
  92.  * This is the initial intro text that appears when the program is started.
  93.  */
  94.  
  95. static char *intro_text =
  96. "\n"
  97. "This program will create a basic XF86Config file, based on menu selections you\n"
  98. "make.\n"
  99. "\n"
  100. "The XF86Config file usually resides in /usr/X11R6/lib/X11. A sample XF86Config\n"
  101. "file is supplied with XFree86; this program does not use it. The program\n"
  102. "will ask for a pathname when it is ready to write the file.\n"
  103. "\n"
  104. "You can either take the sample XF86Config as a base and edit it for your\n"
  105. "configuration, or let this program produce a base XF86Config file for your\n"
  106. "configuration and fine-tune it. Refer to /usr/X11R6/lib/X11/doc/README.Config\n"
  107. "for a detailed overview of the configuration process.\n"
  108. "\n"
  109. "For accelerated servers (including accelerated drivers in the SVGA server),\n"
  110. "there are many chipset and card-specific options and settings. This program\n"
  111. "does not know about these. On some configurations some of these settings must\n"
  112. "be specified. Refer to the server man pages and chipset-specific READMEs.\n"
  113. "\n"
  114. "Before continuing with this program, make sure you know the chipset and\n"
  115. "amount of video memory on your video card. SuperProbe can help with this.\n"
  116. "It is also helpful if you know what server you want to run.\n"
  117. "\n"
  118. ;
  119.  
  120. static char *finalcomment_text =
  121. "File has been written. Take a look at it before running 'startx'. Note that\n"
  122. "the XF86Config file must be in one of the directories searched by the server\n"
  123. "(e.g. /usr/X11R6/lib/X11) in order to be used. Within the server press\n"
  124. "ctrl, alt and '+' simultaneously to cycle video resolutions.\n"
  125. "\n"
  126. "For further configuration, refer to /usr/X11R6/lib/X11/doc/README.Config.\n"
  127. "\n";
  128.  
  129.  
  130. void keypress() {
  131.     printf("Press enter to continue, or ctrl-c to abort.");
  132.     getchar();
  133.     printf("\n");
  134. }
  135.  
  136. void emptylines() {
  137.     int i;
  138.     for (i = 0; i < 50; i++)
  139.         printf("\n");
  140. }
  141.  
  142. int answerisyes(s)
  143.     char *s;
  144. {
  145.     if (s[0] == '\'')    /* For fools that type the ' literally. */
  146.         return tolower(s[1]) == 'y';
  147.     return tolower(s[0]) == 'y';
  148. }
  149.  
  150. /*
  151.  * This is a replacement for gets(). Limit is 80 chars.
  152.  * The 386BSD descendants scream about using gets(), for good reason.
  153.  */
  154.  
  155. void getstring(s)
  156.     char *s;
  157. {
  158.     char *cp;
  159.     fgets(s, 80, stdin);
  160.     cp = strchr(s, '\n');
  161.     if (cp)
  162.         *cp=0;
  163. }
  164.  
  165.  
  166. /*
  167.  * Mouse configuration.
  168.  */
  169.  
  170. static char *mouseintro_text =
  171. "First specify a mouse protocol type. Choose one from the following list:\n"
  172. "\n";
  173.  
  174. static char *mousetype_name[8] = {
  175.     "Microsoft compatible (2-button protocol)",
  176.     "Mouse Systems (3-button protocol)",
  177.     "Bus Mouse",
  178.     "PS/2 Mouse",
  179.     "Logitech Mouse (old type, Logitech protocol)",
  180.     "Logitech MouseMan (Microsoft compatible)",
  181.     "MM Series",    /* XXXX These descriptions should be improved. */
  182.     "MM HitTablet"
  183. };
  184.  
  185. static char *mousetype_identifier[8] = {
  186.     "Microsoft",
  187.     "MouseSystems",
  188.     "Busmouse",
  189.     "PS/2",
  190.     "Logitech",
  191.     "MouseMan",
  192.     "MMSeries",
  193.     "MMHitTab"
  194. };
  195.  
  196. static char *mousedev_text =
  197. "Now give the full device name that the mouse is connected to, for example\n"
  198. "/dev/tty00. Just pressing enter will use the default, /dev/mouse.\n"
  199. "\n";
  200.  
  201. static char *mousecomment_text =
  202. "If you have a two-button mouse, it is most likely of type 1, and if you have\n"
  203. "a three-button mouse, it can probably support both protocol 1 and 2. There are\n"
  204. "two main varieties of the latter type: mice with a switch to select the\n"
  205. "protocol, and mice that default to 1 and require a button to be held at\n"
  206. "boot-time to select protocol 2. Some mice can be convinced to do 2 by sending\n"
  207. "a special sequence to the serial port.\n"
  208. "\n";
  209.  
  210. static char *twobuttonmousecomment_text =
  211. "You have selected a two-button mouse protocol. It is recommended that you\n"
  212. "enable Emulate3Buttons.\n";
  213.  
  214. static char *threebuttonmousecomment_text =
  215. "You have selected a three-button mouse protocol. It is recommended that you\n"
  216. "do not enable Emulate3Buttons, unless the third button doesn't work.\n";
  217.  
  218. static char *unknownbuttonsmousecomment_text =
  219. "If your mouse has only two buttons, it is recommended that you enable\n"
  220. "Emulate3Buttons.\n";
  221.  
  222. static char *microsoftmousecomment_text =
  223. "You have selected a Microsoft protocol mouse. If your mouse was made by\n"
  224. "Logitech, you might want to enable ChordMiddle which could cause the\n"
  225. "third button to work.\n";
  226.  
  227. static char *logitechmousecomment_text =
  228. "You have selected a Logitech protocol mouse. This is only valid for old\n"
  229. "Logitech mice.\n";
  230.  
  231. static char *mousemancomment_text =
  232. "You have selected a Logitech MouseMan type mouse. You might want to enable\n"
  233. "ChordMiddle which could cause the third button to work.\n";
  234.  
  235. void mouse_configuration() {
  236.     int i;
  237.     char s[80];
  238.     printf("%s", mouseintro_text);
  239.     
  240.     for (i = 0; i < 8; i++)
  241.         printf("%2d.  %s\n", i + 1, mousetype_name[i]);
  242.  
  243.     printf("\n");
  244.  
  245.     printf("%s", mousecomment_text);
  246.     
  247.     printf("Enter a protocol number: ");
  248.     getstring(s);
  249.     config_mousetype = atoi(s) - 1;
  250.  
  251.     printf("\n");
  252.  
  253.     if (config_mousetype == 4) {
  254.         /* Logitech. */
  255.         printf("%s", logitechmousecomment_text);
  256.         printf("\n");
  257.         printf("Please answer the following question with either 'y' or 'n'.\n");
  258.         printf("Are you sure it's really not a Microsoft compatible one? ");
  259.         getstring(s);
  260.         if (!answerisyes(s))
  261.             config_mousetype = 0;
  262.         printf("\n");
  263.     }
  264.  
  265.     config_chordmiddle = 0;
  266.     if (config_mousetype == 0 || config_mousetype == 5) {
  267.         /* Microsoft or MouseMan. */
  268.         if (config_mousetype == 0)
  269.             printf("%s", microsoftmousecomment_text);
  270.         else
  271.             printf("%s", mousemancomment_text);
  272.         printf("\n");
  273.         printf("Please answer the following question with either 'y' or 'n'.\n");
  274.         printf("Do you want to enable ChordMiddle? ");
  275.         getstring(s);
  276.         if (answerisyes(s))
  277.             config_chordmiddle = 1;
  278.         printf("\n");
  279.     }
  280.  
  281.     switch (config_mousetype) {
  282.     case 0 : /* Microsoft compatible */
  283.         if (config_chordmiddle)
  284.             printf("%s", threebuttonmousecomment_text);
  285.         else
  286.             printf("%s", twobuttonmousecomment_text);
  287.         break;
  288.     case 1 : /* Mouse Systems. */
  289.         printf("%s", threebuttonmousecomment_text);
  290.         break;
  291.     default :
  292.         printf("%s", unknownbuttonsmousecomment_text);
  293.         break;
  294.     }
  295.  
  296.     printf("\n");
  297.  
  298.     printf("Please answer the following question with either 'y' or 'n'.\n");
  299.     printf("Do you want to enable Emulate3Buttons? ");
  300.     getstring(s);
  301.     if (answerisyes(s))
  302.         config_emulate3buttons = 1;
  303.     else
  304.         config_emulate3buttons = 0;
  305.     printf("\n");
  306.  
  307.     printf("%s", mousedev_text);
  308.     printf("Mouse device: ");
  309.     getstring(s);
  310.     if (strlen(s) == 0)
  311.         config_pointerdevice = "/dev/mouse";
  312.     else {
  313.         config_pointerdevice = malloc(strlen(s) + 1);
  314.         strcpy(config_pointerdevice, s);
  315.        }
  316.        printf("\n");
  317. }
  318.  
  319.  
  320. /*
  321.  * Monitor configuration.
  322.  */
  323.  
  324. static char *monitorintro_text =
  325. "Now we want to set the specifications of the monitor. The two critical\n"
  326. "parameters are the vertical refresh rate, which is the rate at which the\n"
  327. "the whole screen is refreshed, and most importantly the horizontal sync rate,\n"
  328. "which is the rate at which scanlines are displayed.\n"
  329. "\n"
  330. "The valid range for horizontal sync and vertical sync should be documented\n"
  331. "in the manual of your monitor. If in doubt, check the monitor database\n"
  332. "/usr/X11R6/lib/X11/doc/Monitors to see if your monitor is there.\n"
  333. "\n";
  334.  
  335. static char *hsyncintro_text =
  336. "You must indicate the horizontal sync range of your monitor. You can either\n"
  337. "select one of the predefined ranges below that correspond to industry-\n"
  338. "standard monitor types, or give a specific range.\n"
  339. "\n";
  340.  
  341. static char *customhsync_text =
  342. "Please enter the horizontal sync range of your monitor, in the format used\n"
  343. "in the table of monitor types above. You can either specify one or more\n"
  344. "continuous ranges (e.g. 15-25, 30-50), or one or more fixed sync frequencies.\n"
  345. "\n";
  346.  
  347. static char *vsyncintro_text =
  348. "You must indicate the vertical sync range of your monitor. You can either\n"
  349. "select one of the predefined ranges below that correspond to industry-\n"
  350. "standard monitor types, or give a specific range. For interlaced modes,\n"
  351. "the number that counts is the high one (e.g. 87 Hz rather than 43 Hz).\n"
  352. "\n"
  353. " 1  50-70\n"
  354. " 2  50-90\n"
  355. " 3  50-100\n"
  356. " 4  40-150\n"
  357. " 5  Enter your own vertical sync range\n";
  358.  
  359. static char *monitordescintro_text =
  360. "You must now enter a few identification/description strings, namely an\n"
  361. "identifier, a vendor name, and a model name. Just pressing enter will fill\n"
  362. "in default names.\n"
  363. "\n";
  364.  
  365. #define NU_MONITORTYPES 9
  366.  
  367. static char *monitortype_range[NU_MONITORTYPES] = {
  368.     "31.5",
  369.     "31.5 - 35.1",
  370.     "31.5, 35.5",
  371.     "31.5, 35.15, 35.5",
  372.     "31.5 - 37.9",
  373.     "31.5 - 48.5",
  374.     "31.5 - 57.0",
  375.     "31.5 - 64.3",
  376.     "31.5 - 79.0"
  377. };
  378.  
  379. static char *monitortype_name[NU_MONITORTYPES] = {
  380.     "Standard VGA, 640x480 @ 60 Hz",
  381.     "Super VGA, 800x600 @ 56 Hz",
  382.     "8514 Compatible, 1024x768 @ 87 Hz interlaced (no 800x600)",
  383.     "Super VGA, 1024x768 @ 87 Hz interlaced, 800x600 @ 56 Hz",
  384.     "Extended Super VGA, 800x600 @ 60 Hz, 640x480 @ 72 Hz",
  385.     "Non-Interlaced SVGA, 1024x768 @ 60 Hz, 800x600 @ 72 Hz",
  386.     "High Frequency SVGA, 1024x768 @ 70 Hz",
  387.     "Monitor that can do 1280x1024 @ 60 Hz",
  388.     "Monitor that can do 1280x1024 @ 74 Hz"
  389. };
  390.  
  391. void monitor_configuration() {
  392.     int i;
  393.     char s[80];
  394.     printf("%s", monitorintro_text);
  395.  
  396.     keypress();
  397.     emptylines();
  398.  
  399.     printf("%s", hsyncintro_text);
  400.  
  401.     printf("    hsync in kHz; monitor type with characteristic modes\n");
  402.     for (i = 0; i < NU_MONITORTYPES; i++)
  403.         printf("%2d  %s; %s\n", i + 1, monitortype_range[i],
  404.             monitortype_name[i]);
  405.  
  406.     printf("%2d  Enter your own horizontal sync range\n",
  407.         NU_MONITORTYPES + 1);
  408.     printf("\n");
  409.  
  410.     printf("Enter your choice (1-%d): ", NU_MONITORTYPES + 1);
  411.     getstring(s);
  412.     config_monitortype = atoi(s) - 1;
  413.  
  414.     printf("\n");
  415.  
  416.     if (config_monitortype < NU_MONITORTYPES)
  417.         config_hsyncrange = monitortype_range[config_monitortype];
  418.     else {
  419.         /* Custom hsync range option selected. */
  420.         printf("%s", customhsync_text);
  421.         printf("Horizontal sync range: ");
  422.         getstring(s);
  423.         config_hsyncrange = malloc(strlen(s) + 1);
  424.         strcpy(config_hsyncrange, s);
  425.         printf("\n");
  426.     }
  427.  
  428.     printf("%s", vsyncintro_text);
  429.     printf("\n");
  430.  
  431.     printf("Enter your choice: ");
  432.     getstring(s);
  433.     printf("\n");
  434.     switch (atoi(s)) {
  435.     case 1 :
  436.         config_vsyncrange = "50-70";
  437.         break;
  438.     case 2 :
  439.         config_vsyncrange = "50-90";
  440.         break;
  441.     case 3 :
  442.         config_vsyncrange = "50-100";
  443.         break;
  444.     case 4 :
  445.         config_vsyncrange = "40-150";
  446.         break;
  447.     case 5 :
  448.         /* Custom vsync range option selected. */
  449.         printf("Vertical sync range: ");
  450.         getstring(s);
  451.         config_vsyncrange = malloc(strlen(s) + 1);
  452.         strcpy(config_vsyncrange, s);
  453.         printf("\n");
  454.         break;
  455.     }
  456.     printf("%s", monitordescintro_text);
  457.     printf("The strings are free-form, spaces are allowed.\n");
  458.     printf("Enter an identifier for your monitor definition: ");
  459.     getstring(s);
  460.     if (strlen(s) == 0)
  461.         config_monitoridentifier = "My Monitor";
  462.     else {
  463.         config_monitoridentifier = malloc(strlen(s) + 1);
  464.         strcpy(config_monitoridentifier, s);
  465.     }
  466.     printf("Enter the vendor name of your monitor: ");
  467.     getstring(s);
  468.     if (strlen(s) == 0)
  469.         config_monitorvendorname = "Unknown";
  470.     else {
  471.         config_monitorvendorname = malloc(strlen(s) + 1);
  472.         strcpy(config_monitorvendorname, s);
  473.     }
  474.     printf("Enter the model name of your monitor: ");
  475.     getstring(s);
  476.     if (strlen(s) == 0)
  477.         config_monitormodelname = "Unknown";
  478.     else {
  479.         config_monitormodelname = malloc(strlen(s) + 1);
  480.         strcpy(config_monitormodelname, s);
  481.     }
  482. }
  483.  
  484.  
  485. /*
  486.  * Screen/video card configuration.
  487.  */
  488.  
  489. static char *screenintro_text =
  490. "Now we must configure video card specific settings. The first thing is\n"
  491. "which server to run. Refer to the manpages and other documentation. The\n"
  492. "following servers are available (they may not all be installed on your system):\n"
  493. "\n"
  494. " 1  The XF86_Mono server. This a monochrome server that should work on any\n"
  495. "    VGA-compatible card, in 640x480 (more on some SVGA chipsets).\n"
  496. " 2  The XF86_VGA16 server. This is a 16-color VGA server that should work on\n"
  497. "    any VGA-compatible card.\n"
  498. " 3  The XF86_SVGA server. This is a 256 color SVGA server that supports a\n"
  499. "    a number of SVGA chipsets. It is accelerated on some Cirrus and WD\n"
  500. "    chipsets; it supports 16/32-bit color on certain Cirrus configurations.\n"
  501. " 4  The accelerated servers. These include XF86_S3, XF86_Mach32, XF86_Mach8,\n"
  502. "    XF86_8514, XF86_P9000, XF86_AGX, and XF86_W32.\n"
  503. "\n"
  504. "These four server types correspond to the four different \"Screen\" sections in\n"
  505. "XF86Config (vga2, vga16, svga, accel).\n"
  506. "\n";
  507.  
  508. static char *screenlink_text =
  509. "The server to run is selected by changing the symbolic link 'X'. For example,\n"
  510. "'rm /usr/X11R6/bin/X; ln -s /usr/X11R6/bin/XF86_SVGA /usr/X11R6/bin/X' selects\n"
  511. "the SVGA server.\n"
  512. "\n";
  513.  
  514. static char *deviceintro_text =
  515. "Now you must give information about your video card. This will be used for\n"
  516. "the \"Device\" section of your video card in XF86Config.\n"
  517. "\n";
  518.  
  519. static char *videomemoryintro_text =
  520. "You must indicate how much video memory you have. It is probably a good\n"
  521. "idea to use the same approximate amount as that detected by the server you\n"
  522. "intend to use.\n"
  523. "\n"
  524. "How much video memory do you have on your video card:\n"
  525. "\n";
  526.  
  527. static char *screenaccelservers_text =
  528. "Select an accel server:\n"
  529. "\n";
  530.  
  531. static char *carddescintro_text =
  532. "You must now enter a few identification/description strings, namely an\n"
  533. "identifier, a vendor name, and a model name. Just pressing enter will fill\n"
  534. "in default names.\n"
  535. "\n";
  536.  
  537. static char *devicevendornamecomment_text =
  538. "You can simply press enter here if you have a generic card, or want to\n"
  539. "describe your card with one string.\n";
  540.  
  541. static char *devicecomment_text =
  542. "More options and settings can be specified in the Device section. For most\n"
  543. "configurations, a Clocks line is useful since it prevents the slow and nasty\n"
  544. "sounding clock probing at server start-up. Probed clocks are displayed at\n"
  545. "server startup, along with other server and hardware configuration info.\n"
  546. "You can save this information in a file by running\n"
  547. "'X -probeonly 2>output_file'. Be warned that clock probing is inherently\n"
  548. "imprecise; some clocks may be slightly too high (varies per run).\n"
  549. "\n"
  550. "Especially for accelerated servers, Ramdac and Dacspeed settings or special\n"
  551. "options may be required in the Device section.\n"
  552. "\n";
  553.  
  554. static char *deviceclocksquestion_text =
  555. "At this point I can run X -probeonly, and try to extract the clock information\n"
  556. "from the output. It is recommended that you do this yourself and add a clocks\n"
  557. "line (note that the list of clocks may be split over multiple Clocks lines) to\n"
  558. "your Device section afterwards. Be aware that a clocks line is not\n"
  559. "appropriate for drivers that have a fixed set of clocks and don't probe by\n"
  560. "default (e.g. Cirrus). Also, for the P9000 server you must simply specify\n"
  561. "clocks line that matches the modes you want to use.  For the S3 server with\n"
  562. "a programmable clock chip you need a 'ClockChip' line and no Clocks line.\n"
  563. "\n"
  564. "You must be root to be able to run X -probeonly now.\n"
  565. "\n";
  566.  
  567. static char *modesorderintro_text =
  568. "For each depth, a list of modes (resolutions) is defined. The default\n"
  569. "resolution that the server will start-up with will be the first listed\n"
  570. "mode that can be supported by the monitor and card.\n"
  571. "Currently it is set to:\n"
  572. "\n";
  573.  
  574. static char *modesorder_text2 =
  575. "Note that 16bpp and 32bpp are only supported on a few configurations.\n"
  576. "Modes that cannot be supported due to monitor or clock constraints will\n"
  577. "be automatically skipped by the server.\n"
  578. "\n"
  579. " 1  Change the modes for 8pp (256 colors)\n"
  580. " 2  Change the modes for 16bpp (32K/64K colors)\n"
  581. " 3  Change the modes for 32bpp (24-bit color)\n"
  582. " 4  The modes are OK, continue.\n"
  583. "\n";
  584.  
  585. static char *modeslist_text =
  586. "Please type the digits corresponding to the modes that you want to select.\n"
  587. "For example, 432 selects \"1024x768\" \"800x600\" \"640x480\", with a\n"
  588. "default mode of 1024x768.\n"
  589. "\n";
  590.  
  591. static char *accelserver_name[7] = {
  592.     "XF86_S3", "XF86_Mach32", "XF86_Mach8", "XF86_8514", "XF86_P9000",
  593.     "XF86_AGX", "XF86_W32"
  594. };
  595.  
  596. static int videomemory[5] = {
  597.     256, 512, 1024, 2048, 4096
  598. };
  599.  
  600. #define NU_MODESTRINGS 5
  601.  
  602. static char *modestring[NU_MODESTRINGS] = {
  603.     "\"640x400\"",
  604.     "\"640x480\"",
  605.     "\"800x600\"",
  606.     "\"1024x768\"",
  607.     "\"1280x1024\""
  608. };
  609.  
  610. void screen_configuration() {
  611.     int i, c;
  612.     char s[80];
  613.     printf("%s", screenintro_text);
  614.  
  615.     printf("Which one of these four screen types do you intend to run by default (1-4)? ");
  616.     getstring(s);
  617.     config_screentype = atoi(s);
  618.     printf("\n");
  619.  
  620.     printf("%s", screenlink_text);
  621.     printf("Please answer the following question with either 'y' or 'n'.\n");
  622.     printf("Do you want me to set the symbolic link? ");
  623.     getstring(s);
  624.     printf("\n");
  625.     if (answerisyes(s)) {
  626.         char *servername;
  627.         if (config_screentype == 4) {
  628.             /* Accel server. */
  629.             printf("%s", screenaccelservers_text);
  630.             for (i = 0; i < 7; i++)
  631.                 printf("%2d  %s\n", i + 1,
  632.                     accelserver_name[i]);
  633.             printf("\n");
  634.             printf("Which accel server: ");
  635.             getstring(s);
  636.             servername = accelserver_name[atoi(s) - 1];
  637.             printf("\n");
  638.         }
  639.         else
  640.             switch (config_screentype) {
  641.             case 1 : servername = "XF86_Mono"; break;
  642.             case 2 : servername = "XF86_VGA16"; break;
  643.             case 3 : servername = "XF86_SVGA"; break;
  644.             }
  645.         system("rm -f /usr/X11R6/bin/X");
  646.         sprintf(s, "ln -s /usr/X11R6/bin/%s /usr/X11R6/bin/X",
  647.             servername);
  648.         system(s);
  649.     }
  650.  
  651.     emptylines();
  652.  
  653.     /*
  654.      * Configure the "Device" section for the video card.
  655.      */
  656.  
  657.     printf("%s", deviceintro_text);
  658.  
  659.     printf("%s", videomemoryintro_text);
  660.  
  661.     for (i = 0; i < 5; i++)
  662.         printf("%2d  %dK\n", i + 1, videomemory[i]);
  663.     printf(" 6  Other\n\n");
  664.  
  665.     printf("Enter your choice: ");
  666.     getstring(s);
  667.     printf("\n");
  668.     
  669.     c = atoi(s) - 1;
  670.     if (c < 5)
  671.         config_videomemory = videomemory[c];
  672.     else {
  673.         printf("Amount of video memory in Kbytes: ");
  674.         getstring(s);
  675.         config_videomemory = atoi(s);
  676.         printf("\n");
  677.     }
  678.  
  679.     printf("%s", carddescintro_text);
  680.     printf("The strings are free-form, spaces are allowed.\n");
  681.     printf("Enter an identifier for your video card definition: ");
  682.     getstring(s);
  683.     if (strlen(s) == 0)
  684.         config_deviceidentifier = "My Video Card";
  685.     else {
  686.         config_deviceidentifier = malloc(strlen(s) + 1);
  687.         strcpy(config_deviceidentifier, s);
  688.     }
  689.     printf("%s", devicevendornamecomment_text);
  690.     
  691.     printf("Enter the vendor name of your video card: ");
  692.     getstring(s);
  693.     if (strlen(s) == 0)
  694.         config_devicevendorname = "Unknown";
  695.     else {
  696.         config_devicevendorname = malloc(strlen(s) + 1);
  697.         strcpy(config_devicevendorname, s);
  698.     }
  699.     printf("Enter the model (board) name of your video card: ");
  700.     getstring(s);
  701.     if (strlen(s) == 0)
  702.         config_deviceboardname = "Unknown";
  703.     else {
  704.         config_deviceboardname = malloc(strlen(s) + 1);
  705.                 strcpy(config_deviceboardname, s);
  706.     }
  707.     printf("\n");
  708.  
  709.     emptylines();
  710.  
  711.     printf("%s", devicecomment_text);
  712.  
  713.     /*
  714.      * Initialize screen mode variables for svga and accel
  715.      * to default values.
  716.      * XXXX Doesn't leave room for off-screen caching in 16/32bpp modes
  717.      *      for the accelerated servers.
  718.      */
  719.     config_modesline8bpp =
  720.     config_modesline16bpp =
  721.     config_modesline32bpp = "\"640x480\"";
  722.     config_virtualx8bpp = config_virtualx16bpp = config_virtualx32bpp =
  723.     config_virtualy8bpp = config_virtualy16bpp = config_virtualy32bpp = 0;
  724.     if (config_videomemory >= 2048) {
  725.         if (config_screentype == 4) {
  726.             /*
  727.              * Allow room for font/pixmap cache for accel
  728.              * servers.
  729.              * Also the mach32 is has a limited width.
  730.              */
  731.             config_virtualx8bpp = 1280;
  732.             config_virtualy8bpp = 1024;
  733.         }
  734.         else {
  735.             config_virtualx8bpp = 1600;
  736.             config_virtualy8bpp = 1200;
  737.         }
  738.         if (config_screentype == 4) {
  739.             config_virtualx16bpp = 1024;
  740.             config_virtualy16bpp = 768;
  741.         }
  742.         else {
  743.             config_virtualx16bpp = 1152;
  744.             config_virtualy16bpp = 900;
  745.         }
  746.         config_virtualx32bpp = 800;
  747.         config_virtualy32bpp = 600;
  748.         config_modesline8bpp = "\"640x480\" \"800x600\" \"1024x768\" \"1280x1024\"";
  749.         config_modesline16bpp = "\"640x480\" \"800x600\" \"1024x768\"";
  750.         config_modesline32bpp = "\"640x480\" \"800x600\"";
  751.     }
  752.     else
  753.     if (config_videomemory >= 1024) {
  754.         if (config_screentype == 4) {
  755.             /*
  756.              * Allow room for font/pixmap cache for accel
  757.              * servers.
  758.              */
  759.             config_virtualx8bpp = 1024;
  760.             config_virtualy8bpp = 768;
  761.         }
  762.         else {
  763.             config_virtualx8bpp = 1152;
  764.             config_virtualy8bpp = 900;
  765.         }
  766.         config_virtualx16bpp = 800; /* Forget about cache space;  */
  767.         config_virtualy16bpp = 600; /* it's small enough as it is. */
  768.         config_virtualx32bpp = 640;
  769.         config_virtualy32bpp = 400;
  770.         config_modesline8bpp = "\"640x480\" \"800x600\" \"1024x768\"";
  771.         config_modesline16bpp = "\"640x480\" \"800x600\"";
  772.         config_modesline32bpp = "\"640x400\"";
  773.     }
  774.     else
  775.     if (config_videomemory >= 512) {
  776.         config_virtualx8bpp = 800;
  777.         config_virtualy8bpp = 600;
  778.         config_modesline8bpp = "\"640x480\" \"800x600\"";
  779.         config_modesline16bpp = "\"640x400\"";
  780.     }
  781.     else
  782.     if (config_videomemory >= 256) {
  783.         config_modesline8bpp = "640x400";
  784.         config_virtualx8bpp = 640;
  785.         config_virtualy8bpp = 400;
  786.     }
  787.     else {
  788.         printf("Fatal error: Invalid amount of video memory.\n");
  789.         exit(-1);
  790.     }
  791.  
  792.     /*
  793.      * Optionally run X -probeonly to figure out the clocks.
  794.      */
  795.  
  796.     config_numberofclockslines = 0;
  797.  
  798.     printf("%s", deviceclocksquestion_text);
  799.     printf("Do you want me to run 'X -probeonly' now? ");
  800.     getstring(s);
  801.     printf("\n");
  802.     if (answerisyes(s)) {
  803.         /*
  804.          * Write temporary XF86Config and run X -probeonly.
  805.          * Only allow when root.
  806.          */
  807.         FILE *f;
  808.         char *buf;
  809.         if (getuid() != 0) {
  810.             printf("Sorry, you must be root to do this.\n\n");
  811.             goto endofprobeonly;
  812.         }
  813.         printf("Running X -probeonly -pn -xf86config /usr/X11R6/lib/X11/XF86Config.tmp.\n");
  814.         write_XF86Config("/usr/X11R6/lib/X11/XF86Config.tmp");
  815.         if (system("X -probeonly -pn -xf86config /usr/X11R6/lib/X11/XF86Config.tmp 2>/tmp/dumbconfig.2")) {
  816.             printf("X -probeonly call failed.\n");
  817.             printf("No Clocks line inserted.\n");
  818.             goto clocksprobefailed;
  819.         }
  820.         /* Look for 'clocks:' (case sensitive). */        
  821.         if (system("grep clocks\\: /tmp/dumbconfig.2 >/tmp/dumbconfig.3")) {
  822.             printf("grep failed.\n");
  823.             printf("Cannot find clocks in server output.\n");
  824.             goto clocksprobefailed;
  825.         }
  826.         f = fopen("/tmp/dumbconfig.3", "r");
  827.         buf = malloc(8192);
  828.         while (fgets(buf, 8192, f) != NULL) {
  829.             char *clks;
  830.             clks = strstr(buf, "clocks: ") + 8;
  831.             clks[strlen(clks) - 1]  = '\0';    /* Remove '\n'. */
  832.             config_clocksline[config_numberofclockslines] =
  833.                 malloc(strlen(clks) + 1);
  834.             strcpy(config_clocksline[config_numberofclockslines],
  835.                 clks);
  836.             printf("Clocks %s\n", clks);
  837.             config_numberofclockslines++;
  838.         }
  839.         fclose(f);
  840. clocksprobefailed:
  841.         unlink("/tmp/dumbconfig.3");
  842.         unlink("/tmp/dumbconfig.2");
  843.         unlink("/usr/X11R6/lib/X11/XF86Config.tmp");
  844.         printf("\n");
  845.  
  846. endofprobeonly:
  847.         keypress();
  848.     }
  849.  
  850.     /*
  851.      * For the mono and vga16 server, no further configuration is
  852.      * required.
  853.      */
  854.     if (config_screentype == 1 || config_screentype == 2)
  855.         return;
  856.  
  857.     /*
  858.      * Configure the modes order.
  859.      */
  860.      for (;;) {
  861.          char modes[128];
  862.  
  863.         emptylines();
  864.  
  865.         printf("%s", modesorderintro_text);
  866.         printf("%s for 8bpp\n", config_modesline8bpp);
  867.         printf("%s for 16bpp\n", config_modesline16bpp);
  868.         printf("%s for 32bpp\n", config_modesline32bpp);
  869.         printf("\n");
  870.         printf("%s", modesorder_text2);
  871.  
  872.         printf("Enter your choice: ");
  873.         getstring(s);
  874.         printf("\n");
  875.  
  876.         c = atoi(s) - 1;
  877.         if (c < 0 || c >= 3)
  878.             break;
  879.  
  880.         printf("Select modes from the following list:\n\n");
  881.  
  882.         for (i = 0; i < NU_MODESTRINGS; i++)
  883.             printf("%2d  %s\n", i + 1, modestring[i]);
  884.         printf("\n");
  885.  
  886.         printf("%s", modeslist_text);
  887.  
  888.         printf("Which modes? ");
  889.         getstring(s);
  890.         printf("\n");
  891.  
  892.         modes[0] = '\0';
  893.         for (i = 0; i < strlen(s); i++) {
  894.             if (s[i] < '1' || s[i] > '5') {
  895.                 printf("Invalid mode skipped.\n");
  896.                 continue;
  897.             }
  898.             if (i > 0)
  899.                 strcat(modes, " ");
  900.             strcat(modes, modestring[s[i] - '1']);
  901.         }
  902.         switch (c) {
  903.         case 0 :
  904.             config_modesline8bpp = malloc(strlen(modes) + 1);
  905.             strcpy(config_modesline8bpp, modes);
  906.             break;
  907.         case 1 :
  908.             config_modesline16bpp = malloc(strlen(modes) + 1);
  909.             strcpy(config_modesline16bpp, modes);
  910.             break;
  911.         case 2 :
  912.             config_modesline32bpp = malloc(strlen(modes) + 1);
  913.             strcpy(config_modesline32bpp, modes);
  914.             break;
  915.         }
  916.     }
  917. }
  918.  
  919.  
  920. /*
  921.  * Create the XF86Config file.
  922.  */
  923.  
  924. static char *XF86Config_firstchunk_text =
  925. "# File generated by xf86config.\n"
  926. "\n"
  927. "#\n"
  928. "# Copyright (c) 1994 by The XFree86 Project, Inc.\n"
  929. "#\n"
  930. "# Permission is hereby granted, free of charge, to any person obtaining a\n"
  931. "# copy of this software and associated documentation files (the \"Software\"),\n"
  932. "# to deal in the Software without restriction, including without limitation\n"
  933. "# the rights to use, copy, modify, merge, publish, distribute, sublicense,\n"
  934. "# and/or sell copies of the Software, and to permit persons to whom the\n"
  935. "# Software is furnished to do so, subject to the following conditions:\n"
  936. "# \n"
  937. "# The above copyright notice and this permission notice shall be included in\n"
  938. "# all copies or substantial portions of the Software.\n"
  939. "# \n"
  940. "# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
  941. "# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
  942. "# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\n"
  943. "# THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n"
  944. "# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF\n"
  945. "# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n"
  946. "# SOFTWARE.\n"
  947. "# \n"
  948. "# Except as contained in this notice, the name of the XFree86 Project shall\n"
  949. "# not be used in advertising or otherwise to promote the sale, use or other\n"
  950. "# dealings in this Software without prior written authorization from the\n"
  951. "# XFree86 Project.\n"
  952. "#\n"
  953. "\n"
  954. "# **********************************************************************\n"
  955. "# Refer to the XF86Config(4/5) man page for details about the format of \n"
  956. "# this file.\n"
  957. "# **********************************************************************\n"
  958. "\n"
  959. "# **********************************************************************\n"
  960. "# Files section.  This allows default font and rgb paths to be set\n"
  961. "# **********************************************************************\n"
  962. "\n"
  963. "Section \"Files\"\n"
  964. "\n"
  965. "    RgbPath    \"/usr/X11R6/lib/X11/rgb\"\n"
  966. "\n"
  967. "# Multiple FontPath entries are allowed (which are concatenated together),\n"
  968. "# as well as specifying multiple comma-separated entries in one FontPath\n"
  969. "# command (or a combination of both methods)\n"
  970. "\n"
  971. "    FontPath    \"/usr/X11R6/lib/X11/fonts/misc/\"\n"
  972. "        FontPath    \"/usr/X11R6/lib/X11/fonts/Type1/\"\n"
  973. "        FontPath    \"/usr/X11R6/lib/X11/fonts/Speedo/\"\n"
  974. "        FontPath    \"/usr/X11R6/lib/X11/fonts/75dpi/\"\n"
  975. "    FontPath    \"/usr/X11R6/lib/X11/fonts/100dpi/\"\n"
  976. "\n"
  977. "EndSection\n"
  978. "\n"
  979. "# **********************************************************************\n"
  980. "# Server flags section.\n"
  981. "# **********************************************************************\n"
  982. "\n"
  983. "Section \"ServerFlags\"\n"
  984. "\n"
  985. "# Uncomment this to cause a core dump at the spot where a signal is \n"
  986. "# received.  This may leave the console in an unusable state, but may\n"
  987. "# provide a better stack trace in the core dump to aid in debugging\n"
  988. "\n"
  989. "#    NoTrapSignals\n"
  990. "\n"
  991. "# Uncomment this to disable the <Crtl><Alt><BS> server abort sequence\n"
  992. "\n"
  993. "#    DontZap\n"
  994. "\n"
  995. "EndSection\n"
  996. "\n"
  997. "# **********************************************************************\n"
  998. "# Input devices\n"
  999. "# **********************************************************************\n"
  1000. "\n"
  1001. "# **********************************************************************\n"
  1002. "# Keyboard section\n"
  1003. "# **********************************************************************\n"
  1004. "\n"
  1005. "Section \"Keyboard\"\n"
  1006. "\n"
  1007. "    Protocol    \"Standard\"\n"
  1008. "\n"
  1009. "# when using XQUEUE, comment out the above line, and uncomment the\n"
  1010. "# following line\n"
  1011. "\n"
  1012. "#    Protocol    \"Xqueue\"\n"
  1013. "\n"
  1014. "    AutoRepeat    500 5\n"
  1015. "    ServerNumLock\n"
  1016. "\n"
  1017. "# Specifiy which keyboard LEDs can be user-controlled (eg, with xset(1))\n"
  1018. "#    Xleds      1 2 3\n"
  1019. "\n"
  1020. "# To set the LeftAlt to Meta, RightAlt key to ModeShift, \n"
  1021. "# RightCtl key to Compose, and ScrollLock key to ModeLock:\n"
  1022. "\n"
  1023. "#    LeftAlt     Meta\n"
  1024. "#    RightAlt    ModeShift\n"
  1025. "#    RightCtl    Compose\n"
  1026. "#    ScrollLock  ModeLock\n"
  1027. "\n"
  1028. "EndSection\n"
  1029. "\n"
  1030. "\n";
  1031.  
  1032. static char *pointersection_text1 = 
  1033. "# **********************************************************************\n"
  1034. "# Pointer section\n"
  1035. "# **********************************************************************\n"
  1036. "\n"
  1037. "Section \"Pointer\"\n";
  1038.  
  1039. static char *pointersection_text2 =
  1040. "\n"
  1041. "# When using XQUEUE, comment out the above two lines, and uncomment\n"
  1042. "# the following line.\n"
  1043. "\n"
  1044. "#    Protocol    \"Xqueue\"\n"
  1045. "\n"
  1046. "# Baudrate and SampleRate are only for some Logitech mice\n"
  1047. "\n"
  1048. "#    BaudRate    9600\n"
  1049. "#    SampleRate    150\n"
  1050. "\n"
  1051. "# Emulate3Buttons is an option for 2-button Microsoft mice\n"
  1052. "\n";
  1053.  
  1054. static char *monitorsection_text1 =
  1055. "# **********************************************************************\n"
  1056. "# Monitor section\n"
  1057. "# **********************************************************************\n"
  1058. "\n"
  1059. "# Any number of monitor sections may be present\n"
  1060. "\n"
  1061. "Section \"Monitor\"\n"
  1062. "\n";
  1063.  
  1064. static char *monitorsection_text2 =
  1065. "# Bandwidth is in MHz unless units are specified\n"
  1066. "\n"
  1067. "#    Bandwidth    25.2\n"
  1068. "\n"
  1069. "# HorizSync is in kHz unless units are specified.\n"
  1070. "# HorizSync may be a comma separated list of discrete values, or a\n"
  1071. "# comma separated list of ranges of values.\n"
  1072. "# NOTE: THE VALUES HERE ARE EXAMPLES ONLY.  REFER TO YOUR MONITOR\'S\n"
  1073. "# USER MANUAL FOR THE CORRECT NUMBERS.\n"
  1074. "\n";
  1075.  
  1076. static char *monitorsection_text3 =
  1077. "#    HorizSync    30-64         # multisync\n"
  1078. "#    HorizSync    31.5, 35.2    # multiple fixed sync frequencies\n"
  1079. "#    HorizSync    15-25, 30-50  # multiple ranges of sync frequencies\n"
  1080. "\n"
  1081. "# VertRefresh is in Hz unless units are specified.\n"
  1082. "# VertRefresh may be a comma separated list of discrete values, or a\n"
  1083. "# comma separated list of ranges of values.\n"
  1084. "# NOTE: THE VALUES HERE ARE EXAMPLES ONLY.  REFER TO YOUR MONITOR\'S\n"
  1085. "# USER MANUAL FOR THE CORRECT NUMBERS.\n"
  1086. "\n";
  1087.  
  1088. static char *monitorsection_text4 =
  1089. "# Modes can be specified in two formats.  A compact one-line format, or\n"
  1090. "# a multi-line format.\n"
  1091. "\n"
  1092. "# These two are equivalent\n"
  1093. "\n"
  1094. "#    ModeLine \"1024x768i\" 45 1024 1048 1208 1264 768 776 784 817 Interlace\n"
  1095. "\n"
  1096. "#    Mode \"1024x768i\"\n"
  1097. "#        DotClock    45\n"
  1098. "#        HTimings    1024 1048 1208 1264\n"
  1099. "#        VTimings    768 776 784 817\n"
  1100. "#        Flags        \"Interlace\"\n"
  1101. "#    EndMode\n"
  1102. "\n";
  1103.  
  1104. static char *modelines_text =
  1105. "# 640x400 @ 70 Hz, 31.5 kHz hsync\n"
  1106. "Modeline \"640x400\"     25.175 640  664  760  800   400  409  411  450\n"
  1107. "# 640x480 @ 60 Hz, 31.5 kHz hsync\n"
  1108. "Modeline \"640x480\"     25.175 640  664  760  800   480  491  493  525\n"
  1109. "# 800x600 @ 56 Hz, 35.15 kHz hsync\n"
  1110. "ModeLine \"800x600\"     36     800  824  896 1024   600  601  603  625\n"
  1111. "# 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync\n"
  1112. "Modeline \"1024x768\"    44.9  1024 1048 1208 1264   768  776  784  817 Interlace\n"
  1113. "\n"
  1114. "# 640x480 @ 72 Hz, 36.5 kHz hsync\n"
  1115. "Modeline \"640x480\"     31.5   640  680  720  864   480  488  491  521\n"
  1116. "# 800x600 @ 60 Hz, 37.8 kHz hsync\n"
  1117. "Modeline \"800x600\"     40     800  840  968 1056   600  601  605  628 +hsync +vsync\n"
  1118. "\n"
  1119. "# 800x600 @ 72 Hz, 48.0 kHz hsync\n"
  1120. "Modeline \"800x600\"     50     800  856  976 1040   600  637  643  666 +hsync +vsync\n"
  1121. "# 1024x768 @ 60 Hz, 48.4 kHz hsync\n"
  1122. "Modeline \"1024x768\"    65    1024 1032 1176 1344   768  771  777  806 -hsync -vsync\n"
  1123. "\n"
  1124. "# 1024x768 @ 70 Hz, 56.5 kHz hsync\n"
  1125. "Modeline \"1024x768\"    75    1024 1048 1184 1328   768  771  777  806 -hsync -vsync\n"
  1126. "# 1280x1024 @ 87 Hz interlaced, 51 kHz hsync\n"
  1127. "Modeline \"1280x1024\"   80    1280 1296 1512 1568  1024 1025 1037 1165 Interlace\n"
  1128. "\n"
  1129. "# 1024x768 @ 76 Hz, 62.5 kHz hsync\n"
  1130. "Modeline \"1024x768\"    85    1024 1032 1152 1360   768  784  787  823\n"
  1131. "# 1280x1024 @ 61 Hz, 64.2 kHz hsync\n"
  1132. "Modeline \"1280x1024\"  110    1280 1328 1512 1712  1024 1025 1028 1054\n"
  1133. "\n"
  1134. "# 1280x1024 @ 74 Hz, 78.85 kHz hsync\n"
  1135. "Modeline \"1280x1024\"  135    1280 1312 1456 1712  1024 1027 1030 1064\n"
  1136. "\n";
  1137.  
  1138. static char *devicesection_text =
  1139. "# **********************************************************************\n"
  1140. "# Graphics device section\n"
  1141. "# **********************************************************************\n"
  1142. "\n"
  1143. "# Any number of graphics device sections may be present\n"
  1144. "\n"
  1145. "# Standard VGA Device:\n"
  1146. "\n"
  1147. "Section \"Device\"\n"
  1148. "    Identifier    \"Generic VGA\"\n"
  1149. "    VendorName    \"Unknown\"\n"
  1150. "    BoardName    \"Unknown\"\n"
  1151. "    Chipset    \"generic\"\n"
  1152. "\n"
  1153. "#    VideoRam    256\n"
  1154. "\n"
  1155. "#    Clocks    25.2 28.3\n"
  1156. "\n"
  1157. "EndSection\n"
  1158. "\n"
  1159. "# Sample Device for accelerated server:\n"
  1160. "\n"
  1161. "# Section \"Device\"\n"
  1162. "#    Identifier    \"Actix GE32+ 2MB\"\n"
  1163. "#    VendorName    \"Actix\"\n"
  1164. "#    BoardName    \"GE32+\"\n"
  1165. "#    Ramdac    \"ATT20C490\"\n"
  1166. "#    Dacspeed    110\n"
  1167. "#    Option    \"dac_8_bit\"\n"
  1168. "#    Clocks     25.0  28.0  40.0   0.0  50.0  77.0  36.0  45.0\n"
  1169. "#    Clocks    130.0 120.0  80.0  31.0 110.0  65.0  75.0  94.0\n"
  1170. "# EndSection\n"
  1171. "\n"
  1172. "# Device configured by xf86config:\n"
  1173. "\n";
  1174.  
  1175. static char *screensection_text1 =
  1176. "# **********************************************************************\n"
  1177. "# Screen sections\n"
  1178. "# **********************************************************************\n"
  1179. "\n";
  1180.  
  1181.  
  1182. void write_XF86Config(filename)
  1183.     char *filename;
  1184. {
  1185.     FILE *f;
  1186.  
  1187.     /*
  1188.      * Write the file.
  1189.      */
  1190.  
  1191.     f = fopen(filename, "w");
  1192.     if (f == NULL) {
  1193.         printf("Failed to open filename for writing.\n");
  1194.         if (getuid() != 0)
  1195.             printf("Maybe you need to be root to write to the specified directory?\n");
  1196.         exit(-1);
  1197.     }
  1198.  
  1199.     fprintf(f, "%s", XF86Config_firstchunk_text);
  1200.  
  1201.     /*
  1202.      * Write pointer section.
  1203.      */
  1204.     fprintf(f, "%s", pointersection_text1);
  1205.     fprintf(f, "    Protocol    \"%s\"\n",
  1206.         mousetype_identifier[config_mousetype]);
  1207.     fprintf(f, "    Device      \"%s\"\n", config_pointerdevice);
  1208.     fprintf(f, "%s", pointersection_text2);
  1209.     if (!config_emulate3buttons)
  1210.         fprintf(f, "#");
  1211.     fprintf(f, "    Emulate3Buttons\n\n");
  1212.     fprintf(f, "# ChordMiddle is an option for some 3-button Logitech mice\n\n");
  1213.     if (!config_chordmiddle)
  1214.         fprintf(f, "#");
  1215.     fprintf(f, "    ChordMiddle\n\n");
  1216.     fprintf(f, "EndSection\n\n\n");
  1217.  
  1218.     /*
  1219.      * Write monitor section.
  1220.      */
  1221.     fprintf(f, "%s", monitorsection_text1);
  1222.     fprintf(f, "    Identifier  \"%s\"\n", config_monitoridentifier);
  1223.     fprintf(f, "    VendorName  \"%s\"\n", config_monitorvendorname);
  1224.     fprintf(f, "    ModelName   \"%s\"\n", config_monitormodelname);
  1225.     fprintf(f, "\n");
  1226.     fprintf(f, "%s", monitorsection_text2);
  1227.     fprintf(f, "    HorizSync   %s\n", config_hsyncrange);
  1228.     fprintf(f, "\n");
  1229.     fprintf(f, "%s", monitorsection_text3);
  1230.     fprintf(f, "    VertRefresh %s\n", config_vsyncrange);
  1231.     fprintf(f, "\n");
  1232.     fprintf(f, "%s", monitorsection_text4);
  1233.     fprintf(f, "%s", modelines_text);
  1234.     fprintf(f, "EndSection\n\n\n");
  1235.  
  1236.     /*
  1237.      * Write Device section.
  1238.      */
  1239.  
  1240.     fprintf(f, "%s", devicesection_text);
  1241.     fprintf(f, "Section \"Device\"\n");
  1242.     fprintf(f, "    Identifier  \"%s\"\n", config_deviceidentifier);
  1243.     fprintf(f, "    VendorName  \"%s\"\n", config_devicevendorname);
  1244.     fprintf(f, "    BoardName   \"%s\"\n", config_deviceboardname);
  1245.     fprintf(f, "    VideoRam    %d\n", config_videomemory);
  1246.     if (config_numberofclockslines == 0)
  1247.         fprintf(f, "    # Insert Clocks lines here\n");
  1248.     else {
  1249.         int i;
  1250.         for (i = 0; i < config_numberofclockslines; i++)
  1251.             fprintf(f, "    Clocks %s\n", config_clocksline[i]);
  1252.     }
  1253.     fprintf(f, "EndSection\n\n\n");    
  1254.  
  1255.     /*
  1256.      * Write Screen sections.
  1257.      */
  1258.  
  1259.     fprintf(f, "%s", screensection_text1);
  1260.  
  1261.     /*
  1262.      * SVGA screen section.
  1263.      */
  1264.     if (config_screentype == 3)
  1265.         fprintf(f, 
  1266.             "# The Colour SVGA server\n"
  1267.             "\n"
  1268.             "Section \"Screen\"\n"
  1269.             "    Driver      \"svga\"\n"
  1270.             "    # Use Device \"Generic VGA\" for Standard VGA 320x200x256\n"
  1271.             "    #Device      \"Generic VGA\"\n"
  1272.             "    Device      \"%s\"\n"
  1273.             "    Monitor     \"%s\"\n"
  1274.             "    Subsection \"Display\"\n"
  1275.             "        Depth       8\n"
  1276.             "        # Omit the Modes line for the \"Generic VGA\" device\n"
  1277.             "        Modes       %s\n"
  1278.             "        ViewPort    0 0\n"
  1279.             "        # Use Virtual 320 200 for Generic VGA\n"
  1280.             "        Virtual     %d %d\n"
  1281.             "    EndSubsection\n"
  1282.             "    Subsection \"Display\"\n"
  1283.             "        Depth       16\n"
  1284.             "        Modes       %s\n"
  1285.             "        ViewPort    0 0\n"
  1286.             "        Virtual     %d %d\n"
  1287.             "    EndSubsection\n"
  1288.             "    Subsection \"Display\"\n"
  1289.             "        Depth       32\n"
  1290.             "        Modes       %s\n"
  1291.             "        ViewPort    0 0\n"
  1292.             "        Virtual     %d %d\n"
  1293.             "    EndSubsection\n"
  1294.             "EndSection\n"
  1295.             "\n",
  1296.             config_deviceidentifier,
  1297.             config_monitoridentifier,
  1298.             config_modesline8bpp,
  1299.             config_virtualx8bpp, config_virtualy8bpp,
  1300.             config_modesline16bpp,
  1301.             config_virtualx16bpp, config_virtualy16bpp,
  1302.             config_modesline32bpp,
  1303.              config_virtualx32bpp, config_virtualy32bpp
  1304.         );
  1305.     else
  1306.         /*
  1307.          * If the default server is not the SVGA server, generate
  1308.          * an SVGA server screen for just generic 320x200.
  1309.          */
  1310.         fprintf(f, 
  1311.             "# The Colour SVGA server\n"
  1312.             "\n"
  1313.             "Section \"Screen\"\n"
  1314.             "    Driver      \"svga\"\n"
  1315.             "    Device      \"Generic VGA\"\n"
  1316.             "    #Device      \"%s\"\n"
  1317.             "    Monitor     \"%s\"\n"
  1318.             "    Subsection \"Display\"\n"
  1319.             "        Depth       8\n"
  1320.             "        #Modes       %s\n"
  1321.             "        ViewPort    0 0\n"
  1322.             "        Virtual     320 200\n"
  1323.             "        #Virtual     %d %d\n"
  1324.             "    EndSubsection\n"
  1325.             "EndSection\n"
  1326.             "\n",
  1327.             config_deviceidentifier,
  1328.             config_monitoridentifier,
  1329.             config_modesline8bpp,
  1330.             config_virtualx8bpp, config_virtualy8bpp
  1331.         );
  1332.  
  1333.     /*
  1334.      * VGA16 screen section.
  1335.      */
  1336.     fprintf(f, 
  1337.         "# The 16-color VGA server\n"
  1338.         "\n"
  1339.         "Section \"Screen\"\n"
  1340.         "    Driver      \"vga16\"\n"
  1341.         "    Device      \"%s\"\n"
  1342.         "    Monitor     \"%s\"\n"
  1343.         "    Subsection \"Display\"\n"
  1344.         /*
  1345.          * Depend on 800x600 to be deleted if not available due to
  1346.          * dot clock or monitor constraints.
  1347.          */
  1348.         "        Modes       \"640x480\" \"800x600\"\n"
  1349.         "        ViewPort    0 0\n"
  1350.         "        Virtual     800 600\n"
  1351.         "    EndSubsection\n"
  1352.         "EndSection\n"
  1353.         "\n",
  1354.         /*
  1355.          * If mono or vga16 is configured as the default server,
  1356.          * use the configured video card device instead of the
  1357.          * generic VGA device.
  1358.          */
  1359.         (config_screentype == 1 || config_screentype == 2) ?
  1360.             config_deviceidentifier :
  1361.             "Generic VGA",
  1362.         config_monitoridentifier
  1363.     );
  1364.  
  1365.     /*
  1366.      * VGA2 screen section.
  1367.      * This is almost identical to the VGA16 section.
  1368.      */
  1369.     fprintf(f, 
  1370.         "# The Mono server\n"
  1371.         "\n"
  1372.         "Section \"Screen\"\n"
  1373.         "    Driver      \"vga2\"\n"
  1374.         "    Device      \"%s\"\n"
  1375.         "    Monitor     \"%s\"\n"
  1376.         "    Subsection \"Display\"\n"
  1377.         /*
  1378.          * Depend on 800x600 to be deleted if not available due to
  1379.          * dot clock or monitor constraints.
  1380.          */
  1381.         "        Modes       \"640x480\" \"800x600\"\n"
  1382.         "        ViewPort    0 0\n"
  1383.         "        Virtual     800 600\n"
  1384.         "    EndSubsection\n"
  1385.         "EndSection\n"
  1386.         "\n",
  1387.         /*
  1388.          * If mono or vga16 is configured as the default server,
  1389.          * use the configured video card device instead of the
  1390.          * generic VGA device.
  1391.          */
  1392.         (config_screentype == 1 || config_screentype == 2) ?
  1393.             config_deviceidentifier :
  1394.             "Generic VGA",
  1395.         config_monitoridentifier
  1396.     );
  1397.  
  1398.     /*
  1399.      * The Accel section.
  1400.      */
  1401.     fprintf(f, 
  1402.         "# The accelerated servers (S3, Mach32, Mach8, 8514, P9000, AGX, W32)\n"
  1403.         "\n"
  1404.         "Section \"Screen\"\n"
  1405.         "    Driver      \"accel\"\n"
  1406.         "    Device      \"%s\"\n"
  1407.         "    Monitor     \"%s\"\n"
  1408.         "    Subsection \"Display\"\n"
  1409.         "        Depth       8\n"
  1410.         "        Modes       %s\n"
  1411.         "        ViewPort    0 0\n"
  1412.         "        Virtual     %d %d\n"
  1413.         "    EndSubsection\n"
  1414.         "    Subsection \"Display\"\n"
  1415.         "        Depth       16\n"
  1416.         "        Modes       %s\n"
  1417.         "        ViewPort    0 0\n"
  1418.         "        Virtual     %d %d\n"
  1419.         "    EndSubsection\n"
  1420.         "    Subsection \"Display\"\n"
  1421.         "        Depth       32\n"
  1422.         "        Modes       %s\n"
  1423.         "        ViewPort    0 0\n"
  1424.         "        Virtual     %d %d\n"
  1425.         "    EndSubsection\n"
  1426.         "EndSection\n"
  1427.         "\n",
  1428.         config_deviceidentifier,
  1429.         config_monitoridentifier,
  1430.         config_modesline8bpp,
  1431.         config_virtualx8bpp, config_virtualy8bpp,
  1432.         config_modesline16bpp,
  1433.         config_virtualx16bpp, config_virtualy16bpp,
  1434.         config_modesline32bpp,
  1435.         config_virtualx32bpp, config_virtualy32bpp
  1436.     );
  1437.  
  1438.     fclose(f);
  1439. }
  1440.  
  1441.  
  1442. /*
  1443.  * Ask where to write XF86Config to. Returns filename.
  1444.  */
  1445.  
  1446. char *ask_XF86Config_location() {
  1447.     char s[80];
  1448.     char *filename;
  1449.  
  1450.     printf(
  1451. "I am going to write the XF86Config file now. Make sure you don't accidently\n"
  1452. "overwrite a previously configured one.\n\n");
  1453.  
  1454.     if (getuid() == 0) {
  1455.         printf("Please answer the following question with either 'y' or 'n'.\n");
  1456.         printf("Shall I write it to the default location, /usr/X11R6/lib/X11/XF86Config? ");
  1457.         getstring(s);
  1458.         printf("\n");
  1459.         if (answerisyes(s))
  1460.             return "/usr/X11R6/lib/X11/XF86Config";
  1461.     }
  1462.  
  1463.     printf("Do you want it written to the current directory as 'XF86Config'? ");
  1464.     getstring(s);
  1465.     printf("\n");
  1466.     if (answerisyes(s))
  1467.         return "XF86Config";
  1468.  
  1469.     printf("Please give a path+filename to write to: ");
  1470.     getstring(s);
  1471.     printf("\n");
  1472.     filename = malloc(strlen(s) + 1);
  1473.     strcpy(filename, s);
  1474.     return filename;
  1475. }
  1476.  
  1477.  
  1478. /*
  1479.  * Check if an earlier version of XFree86 is installed; warn about proper
  1480.  * search path order in that case.
  1481.  */
  1482.  
  1483. static char *oldxfree86_text =
  1484. "The directory '/usr/X386/bin' exists. You probably have an old version of\n"
  1485. "XFree86 installed (XFree86 3.1 installs in '/usr/X11R6' instead of\n"
  1486. "'/usr/X386').\n"
  1487. "\n"
  1488. "It is imperative that the directory '/usr/X11R6/bin' is present in your\n"
  1489. "search path, *before* any occurrence of '/usr/X386/bin'. If you have installed\n"
  1490. "X program binaries that are not in the base XFree86 distribution in\n"
  1491. "'/usr/X386/bin', you can keep the directory in your path as long as it is\n"
  1492. "after '/usr/X11R6/bin'.\n"
  1493. "\n";
  1494.  
  1495. static char *pathnote_text =    
  1496. "Note that the X binary directory in your path may be a symbolic link.\n"
  1497. "In that case you could modify the symbolic link to point to the new binaries.\n"
  1498. "Example: 'rm -f /usr/bin/X11; ln -s /usr/X11R6/bin /usr/bin/X11', if the\n"
  1499. "link is '/usr/bin/X11'.\n"
  1500. "\n"
  1501. "Make sure the path is OK before continuing.\n";
  1502.  
  1503. void path_check() {
  1504.     FILE *f;
  1505.     f = fopen("/usr/X386/bin", "r");
  1506.     if (f == NULL)
  1507.         return;
  1508.  
  1509.     fclose(f);
  1510.     printf("%s", oldxfree86_text);
  1511.     printf("Your PATH is currently set as follows:\n%s\n\n",
  1512.         getenv("PATH"));
  1513.     printf("%s", pathnote_text);
  1514.     keypress();
  1515. }
  1516.  
  1517.  
  1518. /*
  1519.  * Program entry point.
  1520.  */
  1521.  
  1522. void main() {
  1523.     emptylines();
  1524.  
  1525.     printf("%s", intro_text);
  1526.  
  1527.     keypress();
  1528.     emptylines();
  1529.  
  1530.     path_check();
  1531.  
  1532.     emptylines();
  1533.  
  1534.     mouse_configuration();
  1535.  
  1536.     emptylines();
  1537.  
  1538.     monitor_configuration();
  1539.  
  1540.     emptylines();
  1541.  
  1542.      screen_configuration();
  1543.  
  1544.     emptylines();
  1545.  
  1546.     write_XF86Config(ask_XF86Config_location());
  1547.  
  1548.     printf("%s", finalcomment_text);
  1549.  
  1550.     exit(0);
  1551. }
  1552.