96a6640000ac72715e01ef01f2edbce73ffb5457
[framework/uifw/xorg/server/xorg-server.git] / hw / xfree86 / common / xf86Config.c
1 /*
2  * Loosely based on code bearing the following copyright:
3  *
4  *   Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
5  */
6
7 /*
8  * Copyright 1992-2003 by The XFree86 Project, Inc.
9  * Copyright 1997 by Metro Link, Inc.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  *
29  * Except as contained in this notice, the name of the copyright holder(s)
30  * and author(s) shall not be used in advertising or otherwise to promote
31  * the sale, use or other dealings in this Software without prior written
32  * authorization from the copyright holder(s) and author(s).
33  */
34
35 /*
36  *
37  * Authors:
38  *      Dirk Hohndel <hohndel@XFree86.Org>
39  *      David Dawes <dawes@XFree86.Org>
40  *      Marc La France <tsi@XFree86.Org>
41  *      Egbert Eich <eich@XFree86.Org>
42  *      ... and others
43  */
44
45 #ifdef HAVE_XORG_CONFIG_H
46 #include <xorg-config.h>
47 #endif
48
49 #ifdef XF86DRI
50 #include <sys/types.h>
51 #include <grp.h>
52 #endif
53
54 #include "xf86.h"
55 #include "xf86Modes.h"
56 #include "xf86Parser.h"
57 #include "xf86tokens.h"
58 #include "xf86Config.h"
59 #include "xf86Priv.h"
60 #include "xf86_OSlib.h"
61 #include "configProcs.h"
62 #include "globals.h"
63 #include "extension.h"
64 #include "xf86pciBus.h"
65
66 #include "xf86Xinput.h"
67
68 #include "xkbsrv.h"
69
70 #include "picture.h"
71
72 /*
73  * These paths define the way the config file search is done.  The escape
74  * sequences are documented in parser/scan.c.
75  */
76 #ifndef ALL_CONFIGPATH
77 #define ALL_CONFIGPATH  "%A," "%R," \
78                         "/etc/X11/%R," "%P/etc/X11/%R," \
79                         "%E," "%F," \
80                         "/etc/X11/%F," "%P/etc/X11/%F," \
81                         "/etc/X11/%X," "/etc/%X," \
82                         "%P/etc/X11/%X.%H," \
83                         "%P/etc/X11/%X," \
84                         "%P/lib/X11/%X.%H," \
85                         "%P/lib/X11/%X"
86 #endif
87 #ifndef RESTRICTED_CONFIGPATH
88 #define RESTRICTED_CONFIGPATH   "/etc/X11/%S," "%P/etc/X11/%S," \
89                         "/etc/X11/%G," "%P/etc/X11/%G," \
90                         "/etc/X11/%X," "/etc/%X," \
91                         "%P/etc/X11/%X.%H," \
92                         "%P/etc/X11/%X," \
93                         "%P/lib/X11/%X.%H," \
94                         "%P/lib/X11/%X"
95 #endif
96 #ifndef ALL_CONFIGDIRPATH
97 #define ALL_CONFIGDIRPATH       "%A," "%R," \
98                                 "/etc/X11/%R," "%C/X11/%R," \
99                                 "/etc/X11/%X," "%C/X11/%X"
100 #endif
101 #ifndef RESTRICTED_CONFIGDIRPATH
102 #define RESTRICTED_CONFIGDIRPATH        "/etc/X11/%R," "%C/X11/%R," \
103                                         "/etc/X11/%X," "%C/X11/%X"
104 #endif
105 #ifndef SYS_CONFIGDIRPATH
106 #define SYS_CONFIGDIRPATH       "%D/X11/%X"
107 #endif
108 #ifndef PROJECTROOT
109 #define PROJECTROOT     "/usr/X11R6"
110 #endif
111
112 static ModuleDefault ModuleDefaults[] = {
113 #ifdef GLXEXT
114     {.name = "glx",.toLoad = TRUE,.load_opt = NULL},
115 #endif
116 #ifdef __CYGWIN__
117     /* load DIX modules used by drivers first */
118     {.name = "fb",.toLoad = TRUE,.load_opt = NULL},
119     {.name = "shadow",.toLoad = TRUE,.load_opt = NULL},
120 #endif
121     {.name = NULL,.toLoad = FALSE,.load_opt = NULL}
122 };
123
124 /* Forward declarations */
125 static Bool configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen,
126                          int scrnum, MessageType from);
127 static Bool configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor);
128 static Bool configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device,
129                          Bool active);
130 static Bool configInput(InputInfoPtr pInfo, XF86ConfInputPtr conf_input,
131                         MessageType from);
132 static Bool configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display);
133 static Bool addDefaultModes(MonPtr monitorp);
134
135 #ifdef XF86DRI
136 static void configDRI(XF86ConfDRIPtr drip);
137 #endif
138 static void configExtensions(XF86ConfExtensionsPtr conf_ext);
139
140 /*
141  * xf86GetPathElem --
142  *      Extract a single element from the font path string starting at
143  *      pnt.  The font path element will be returned, and pnt will be
144  *      updated to point to the start of the next element, or set to
145  *      NULL if there are no more.
146  */
147 static char *
148 xf86GetPathElem(char **pnt)
149 {
150     char *p1;
151
152     p1 = *pnt;
153     *pnt = index(*pnt, ',');
154     if (*pnt != NULL) {
155         **pnt = '\0';
156         *pnt += 1;
157     }
158     return p1;
159 }
160
161 /*
162  * xf86ValidateFontPath --
163  *      Validates the user-specified font path.  Each element that
164  *      begins with a '/' is checked to make sure the directory exists.
165  *      If the directory exists, the existence of a file named 'fonts.dir'
166  *      is checked.  If either check fails, an error is printed and the
167  *      element is removed from the font path.
168  */
169
170 #define DIR_FILE "/fonts.dir"
171 static char *
172 xf86ValidateFontPath(char *path)
173 {
174     char *next, *tmp_path, *out_pnt, *path_elem, *p1, *dir_elem;
175     struct stat stat_buf;
176     int flag;
177     int dirlen;
178
179     tmp_path = calloc(1, strlen(path) + 1);
180     out_pnt = tmp_path;
181     path_elem = NULL;
182     next = path;
183     while (next != NULL) {
184         path_elem = xf86GetPathElem(&next);
185         if (*path_elem == '/') {
186             dir_elem = xnfcalloc(1, strlen(path_elem) + 1);
187             if ((p1 = strchr(path_elem, ':')) != 0)
188                 dirlen = p1 - path_elem;
189             else
190                 dirlen = strlen(path_elem);
191             strlcpy(dir_elem, path_elem, dirlen + 1);
192             flag = stat(dir_elem, &stat_buf);
193             if (flag == 0)
194                 if (!S_ISDIR(stat_buf.st_mode))
195                     flag = -1;
196             if (flag != 0) {
197                 xf86Msg(X_WARNING, "The directory \"%s\" does not exist.\n",
198                         dir_elem);
199                 xf86ErrorF("\tEntry deleted from font path.\n");
200                 free(dir_elem);
201                 continue;
202             }
203             else {
204                 XNFasprintf(&p1, "%s%s", dir_elem, DIR_FILE);
205                 flag = stat(p1, &stat_buf);
206                 if (flag == 0)
207                     if (!S_ISREG(stat_buf.st_mode))
208                         flag = -1;
209                 free(p1);
210                 if (flag != 0) {
211                     xf86Msg(X_WARNING,
212                             "`fonts.dir' not found (or not valid) in \"%s\".\n",
213                             dir_elem);
214                     xf86ErrorF("\tEntry deleted from font path.\n");
215                     xf86ErrorF("\t(Run 'mkfontdir' on \"%s\").\n", dir_elem);
216                     free(dir_elem);
217                     continue;
218                 }
219             }
220             free(dir_elem);
221         }
222
223         /*
224          * Either an OK directory, or a font server name.  So add it to
225          * the path.
226          */
227         if (out_pnt != tmp_path)
228             *out_pnt++ = ',';
229         strcat(out_pnt, path_elem);
230         out_pnt += strlen(path_elem);
231     }
232     return tmp_path;
233 }
234
235 #define FIND_SUITABLE(pointertype, listhead, ptr)                                            \
236     do {                                                                                     \
237         pointertype _l, _p;                                                                  \
238                                                                                              \
239         for (_l = (listhead), _p = NULL; !_p && _l; _l = (pointertype)_l->list.next) {       \
240             if (!_l->match_seat || (SeatId && xf86nameCompare(_l->match_seat, SeatId) == 0)) \
241                 _p = _l;                                                                     \
242         }                                                                                    \
243                                                                                              \
244         (ptr) = _p;                                                                          \
245     } while(0)
246
247 /*
248  * use the datastructure that the parser provides and pick out the parts
249  * that we need at this point
250  */
251 const char **
252 xf86ModulelistFromConfig(void ***optlist)
253 {
254     int count = 0, i = 0;
255     const char **modulearray;
256
257     const char *ignore[] = { "GLcore", "speedo", "bitmap", "drm",
258         "freetype", "type1",
259         NULL
260     };
261     void **optarray;
262     XF86LoadPtr modp;
263     Bool found;
264
265     /*
266      * make sure the config file has been parsed and that we have a
267      * ModulePath set; if no ModulePath was given, use the default
268      * ModulePath
269      */
270     if (xf86configptr == NULL) {
271         xf86Msg(X_ERROR, "Cannot access global config data structure\n");
272         return NULL;
273     }
274
275     if (xf86configptr->conf_modules) {
276         /* Walk the disable list and let people know what we've parsed to
277          * not be loaded 
278          */
279         modp = xf86configptr->conf_modules->mod_disable_lst;
280         while (modp) {
281             xf86Msg(X_WARNING,
282                     "\"%s\" will not be loaded unless you've specified it to be loaded elsewhere.\n",
283                     modp->load_name);
284             modp = (XF86LoadPtr) modp->list.next;
285         }
286         /*
287          * Walk the default settings table. For each module listed to be
288          * loaded, make sure it's in the mod_load_lst. If it's not, make
289          * sure it's not in the mod_no_load_lst. If it's not disabled,
290          * append it to mod_load_lst
291          */
292         for (i = 0; ModuleDefaults[i].name != NULL; i++) {
293             if (ModuleDefaults[i].toLoad == FALSE) {
294                 xf86Msg(X_WARNING,
295                         "\"%s\" is not to be loaded by default. Skipping.\n",
296                         ModuleDefaults[i].name);
297                 continue;
298             }
299             found = FALSE;
300             modp = xf86configptr->conf_modules->mod_load_lst;
301             while (modp) {
302                 if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) {
303                     xf86Msg(X_INFO,
304                             "\"%s\" will be loaded. This was enabled by default and also specified in the config file.\n",
305                             ModuleDefaults[i].name);
306                     found = TRUE;
307                     break;
308                 }
309                 modp = (XF86LoadPtr) modp->list.next;
310             }
311             if (found == FALSE) {
312                 modp = xf86configptr->conf_modules->mod_disable_lst;
313                 while (modp) {
314                     if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) {
315                         xf86Msg(X_INFO,
316                                 "\"%s\" will be loaded even though the default is to disable it.\n",
317                                 ModuleDefaults[i].name);
318                         found = TRUE;
319                         break;
320                     }
321                     modp = (XF86LoadPtr) modp->list.next;
322                 }
323             }
324             if (found == FALSE) {
325                 XF86LoadPtr ptr = (XF86LoadPtr) xf86configptr->conf_modules;
326
327                 xf86addNewLoadDirective(ptr, ModuleDefaults[i].name,
328                                         XF86_LOAD_MODULE,
329                                         ModuleDefaults[i].load_opt);
330                 xf86Msg(X_INFO, "\"%s\" will be loaded by default.\n",
331                         ModuleDefaults[i].name);
332             }
333         }
334     }
335     else {
336         xf86configptr->conf_modules = xnfcalloc(1, sizeof(XF86ConfModuleRec));
337         for (i = 0; ModuleDefaults[i].name != NULL; i++) {
338             if (ModuleDefaults[i].toLoad == TRUE) {
339                 XF86LoadPtr ptr = (XF86LoadPtr) xf86configptr->conf_modules;
340
341                 xf86addNewLoadDirective(ptr, ModuleDefaults[i].name,
342                                         XF86_LOAD_MODULE,
343                                         ModuleDefaults[i].load_opt);
344             }
345         }
346     }
347
348     /*
349      * Walk the list of modules in the "Module" section to determine how
350      * many we have.
351      */
352     modp = xf86configptr->conf_modules->mod_load_lst;
353     while (modp) {
354         for (i = 0; ignore[i]; i++) {
355             if (strcmp(modp->load_name, ignore[i]) == 0)
356                 modp->ignore = 1;
357         }
358         if (!modp->ignore)
359             count++;
360         modp = (XF86LoadPtr) modp->list.next;
361     }
362
363     /*
364      * allocate the memory and walk the list again to fill in the pointers
365      */
366     modulearray = xnfalloc((count + 1) * sizeof(char *));
367     optarray = xnfalloc((count + 1) * sizeof(void *));
368     count = 0;
369     if (xf86configptr->conf_modules) {
370         modp = xf86configptr->conf_modules->mod_load_lst;
371         while (modp) {
372             if (!modp->ignore) {
373                 modulearray[count] = modp->load_name;
374                 optarray[count] = modp->load_opt;
375                 count++;
376             }
377             modp = (XF86LoadPtr) modp->list.next;
378         }
379     }
380     modulearray[count] = NULL;
381     optarray[count] = NULL;
382     if (optlist)
383         *optlist = optarray;
384     else
385         free(optarray);
386     return modulearray;
387 }
388
389 const char **
390 xf86DriverlistFromConfig(void)
391 {
392     int count = 0;
393     int j;
394     const char **modulearray;
395     screenLayoutPtr slp;
396
397     /*
398      * make sure the config file has been parsed and that we have a
399      * ModulePath set; if no ModulePath was given, use the default
400      * ModulePath
401      */
402     if (xf86configptr == NULL) {
403         xf86Msg(X_ERROR, "Cannot access global config data structure\n");
404         return NULL;
405     }
406
407     /*
408      * Walk the list of driver lines in active "Device" sections to
409      * determine now many implicitly loaded modules there are.
410      *
411      */
412     if (xf86ConfigLayout.screens) {
413         slp = xf86ConfigLayout.screens;
414         while ((slp++)->screen) {
415             count++;
416         }
417     }
418
419     /*
420      * Handle the set of inactive "Device" sections.
421      */
422     j = 0;
423     while (xf86ConfigLayout.inactives[j++].identifier)
424         count++;
425
426     if (count == 0)
427         return NULL;
428
429     /*
430      * allocate the memory and walk the list again to fill in the pointers
431      */
432     modulearray = xnfalloc((count + 1) * sizeof(char *));
433     count = 0;
434     slp = xf86ConfigLayout.screens;
435     while (slp->screen) {
436         modulearray[count] = slp->screen->device->driver;
437         count++;
438         slp++;
439     }
440
441     j = 0;
442
443     while (xf86ConfigLayout.inactives[j].identifier)
444         modulearray[count++] = xf86ConfigLayout.inactives[j++].driver;
445
446     modulearray[count] = NULL;
447
448     /* Remove duplicates */
449     for (count = 0; modulearray[count] != NULL; count++) {
450         int i;
451
452         for (i = 0; i < count; i++)
453             if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) {
454                 modulearray[count] = "";
455                 break;
456             }
457     }
458     return modulearray;
459 }
460
461 const char **
462 xf86InputDriverlistFromConfig(void)
463 {
464     int count = 0;
465     const char **modulearray;
466     InputInfoPtr *idp;
467
468     /*
469      * make sure the config file has been parsed and that we have a
470      * ModulePath set; if no ModulePath was given, use the default
471      * ModulePath
472      */
473     if (xf86configptr == NULL) {
474         xf86Msg(X_ERROR, "Cannot access global config data structure\n");
475         return NULL;
476     }
477
478     /*
479      * Walk the list of driver lines in active "InputDevice" sections to
480      * determine now many implicitly loaded modules there are.
481      */
482     if (xf86ConfigLayout.inputs) {
483         idp = xf86ConfigLayout.inputs;
484         while (*idp) {
485             count++;
486             idp++;
487         }
488     }
489
490     if (count == 0)
491         return NULL;
492
493     /*
494      * allocate the memory and walk the list again to fill in the pointers
495      */
496     modulearray = xnfalloc((count + 1) * sizeof(char *));
497     count = 0;
498     idp = xf86ConfigLayout.inputs;
499     while (idp && *idp) {
500         modulearray[count] = (*idp)->driver;
501         count++;
502         idp++;
503     }
504     modulearray[count] = NULL;
505
506     /* Remove duplicates */
507     for (count = 0; modulearray[count] != NULL; count++) {
508         int i;
509
510         for (i = 0; i < count; i++)
511             if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) {
512                 modulearray[count] = "";
513                 break;
514             }
515     }
516     return modulearray;
517 }
518
519 static void
520 fixup_video_driver_list(const char **drivers)
521 {
522     static const char *fallback[5] = { "modesetting", "fbdev", "vesa", "wsfb", NULL };
523     const char **end, **drv;
524     const char *x;
525     int i;
526
527     /* walk to the end of the list */
528     for (end = drivers; *end && **end; end++);
529     end--;
530
531     /*
532      * for each of the fallback drivers, if we find it in the list,
533      * swap it with the last available non-fallback driver.
534      */
535     for (i = 0; fallback[i]; i++) {
536         for (drv = drivers; drv != end; drv++) {
537             if (strstr(*drv, fallback[i])) {
538                 x = *drv;
539                 *drv = *end;
540                 *end = x;
541                 end--;
542                 break;
543             }
544         }
545     }
546 }
547
548 static const char **
549 GenerateDriverlist(const char *dirname)
550 {
551     const char **ret;
552     const char *subdirs[] = { dirname, NULL };
553     static const char *patlist[] = { "(.*)_drv\\.so", NULL };
554     ret = LoaderListDirs(subdirs, patlist);
555
556     /* fix up the probe order for video drivers */
557     if (strstr(dirname, "drivers") && ret != NULL)
558         fixup_video_driver_list(ret);
559
560     return ret;
561 }
562
563 const char **
564 xf86DriverlistFromCompile(void)
565 {
566     static const char **driverlist = NULL;
567
568     if (!driverlist)
569         driverlist = GenerateDriverlist("drivers");
570
571     return driverlist;
572 }
573
574 /*
575  * xf86ConfigError --
576  *      Print a READABLE ErrorMessage!!!  All information that is 
577  *      available is printed.
578  */
579 static void
580 _X_ATTRIBUTE_PRINTF(1, 2)
581 xf86ConfigError(const char *msg, ...)
582 {
583     va_list ap;
584
585     ErrorF("\nConfig Error:\n");
586     va_start(ap, msg);
587     VErrorF(msg, ap);
588     va_end(ap);
589     ErrorF("\n");
590     return;
591 }
592
593 static void
594 configFiles(XF86ConfFilesPtr fileconf)
595 {
596     MessageType pathFrom;
597     Bool must_copy;
598     int size, countDirs;
599     char *temp_path, *log_buf, *start, *end;
600
601     /* FontPath */
602     must_copy = TRUE;
603
604     temp_path = defaultFontPath ? (char *) defaultFontPath : (char *) "";
605     if (xf86fpFlag)
606         pathFrom = X_CMDLINE;
607     else if (fileconf && fileconf->file_fontpath) {
608         pathFrom = X_CONFIG;
609         if (xf86Info.useDefaultFontPath) {
610             char *new_font_path;
611             if (asprintf(&new_font_path, "%s%s%s", fileconf->file_fontpath,
612                          *temp_path ? "," : "", temp_path) == -1)
613                 new_font_path = NULL;
614             else
615                 must_copy = FALSE;
616             defaultFontPath = new_font_path;
617         }
618         else
619             defaultFontPath = fileconf->file_fontpath;
620     }
621     else
622         pathFrom = X_DEFAULT;
623     temp_path = defaultFontPath ? (char *) defaultFontPath : (char *) "";
624
625     /* xf86ValidateFontPath modifies its argument, but returns a copy of it. */
626     temp_path = must_copy ? xnfstrdup(defaultFontPath) : (char *) defaultFontPath;
627     defaultFontPath = xf86ValidateFontPath(temp_path);
628     free(temp_path);
629
630     /* make fontpath more readable in the logfiles */
631     countDirs = 1;
632     temp_path = (char *) defaultFontPath;
633     while ((temp_path = index(temp_path, ',')) != NULL) {
634         countDirs++;
635         temp_path++;
636     }
637
638     log_buf = xnfalloc(strlen(defaultFontPath) + (2 * countDirs) + 1);
639     temp_path = log_buf;
640     start = (char *) defaultFontPath;
641     while ((end = index(start, ',')) != NULL) {
642         size = (end - start) + 1;
643         *(temp_path++) = '\t';
644         strncpy(temp_path, start, size);
645         temp_path += size;
646         *(temp_path++) = '\n';
647         start += size;
648     }
649     /* copy last entry */
650     *(temp_path++) = '\t';
651     strcpy(temp_path, start);
652     xf86Msg(pathFrom, "FontPath set to:\n%s\n", log_buf);
653     free(log_buf);
654
655     /* ModulePath */
656
657     if (fileconf) {
658         if (xf86ModPathFrom != X_CMDLINE && fileconf->file_modulepath) {
659             xf86ModulePath = fileconf->file_modulepath;
660             xf86ModPathFrom = X_CONFIG;
661         }
662     }
663
664     xf86Msg(xf86ModPathFrom, "ModulePath set to \"%s\"\n", xf86ModulePath);
665
666     if (!xf86xkbdirFlag && fileconf && fileconf->file_xkbdir) {
667         XkbBaseDirectory = fileconf->file_xkbdir;
668         xf86Msg(X_CONFIG, "XKB base directory set to \"%s\"\n",
669                 XkbBaseDirectory);
670     }
671 #if 0
672     /* LogFile */
673     /*
674      * XXX The problem with this is that the log file is already open.
675      * One option might be to copy the exiting contents to the new location.
676      * and re-open it.  The down side is that the default location would
677      * already have been overwritten.  Another option would be to start with
678      * unique temporary location, then copy it once the correct name is known.
679      * A problem with this is what happens if the server exits before that
680      * happens.
681      */
682     if (xf86LogFileFrom == X_DEFAULT && fileconf->file_logfile) {
683         xf86LogFile = fileconf->file_logfile;
684         xf86LogFileFrom = X_CONFIG;
685     }
686 #endif
687
688     return;
689 }
690
691 typedef enum {
692     FLAG_NOTRAPSIGNALS,
693     FLAG_DONTVTSWITCH,
694     FLAG_DONTZAP,
695     FLAG_DONTZOOM,
696     FLAG_DISABLEVIDMODE,
697     FLAG_ALLOWNONLOCAL,
698     FLAG_ALLOWMOUSEOPENFAIL,
699     FLAG_SAVER_BLANKTIME,
700     FLAG_DPMS_STANDBYTIME,
701     FLAG_DPMS_SUSPENDTIME,
702     FLAG_DPMS_OFFTIME,
703     FLAG_PIXMAP,
704     FLAG_NOPM,
705     FLAG_XINERAMA,
706     FLAG_LOG,
707     FLAG_RENDER_COLORMAP_MODE,
708     FLAG_RANDR,
709     FLAG_AIGLX,
710     FLAG_IGNORE_ABI,
711     FLAG_ALLOW_EMPTY_INPUT,
712     FLAG_USE_DEFAULT_FONT_PATH,
713     FLAG_AUTO_ADD_DEVICES,
714     FLAG_AUTO_ENABLE_DEVICES,
715     FLAG_GLX_VISUALS,
716     FLAG_DRI2,
717     FLAG_USE_SIGIO,
718     FLAG_AUTO_ADD_GPU,
719 } FlagValues;
720
721 /**
722  * NOTE: the last value for each entry is NOT the default. It is set to TRUE
723  * if the parser found the option in the config file.
724  */
725 static OptionInfoRec FlagOptions[] = {
726     {FLAG_NOTRAPSIGNALS, "NoTrapSignals", OPTV_BOOLEAN,
727      {0}, FALSE},
728     {FLAG_DONTVTSWITCH, "DontVTSwitch", OPTV_BOOLEAN,
729      {0}, FALSE},
730     {FLAG_DONTZAP, "DontZap", OPTV_BOOLEAN,
731      {0}, FALSE},
732     {FLAG_DONTZOOM, "DontZoom", OPTV_BOOLEAN,
733      {0}, FALSE},
734     {FLAG_DISABLEVIDMODE, "DisableVidModeExtension", OPTV_BOOLEAN,
735      {0}, FALSE},
736     {FLAG_ALLOWNONLOCAL, "AllowNonLocalXvidtune", OPTV_BOOLEAN,
737      {0}, FALSE},
738     {FLAG_ALLOWMOUSEOPENFAIL, "AllowMouseOpenFail", OPTV_BOOLEAN,
739      {0}, FALSE},
740     {FLAG_SAVER_BLANKTIME, "BlankTime", OPTV_INTEGER,
741      {0}, FALSE},
742     {FLAG_DPMS_STANDBYTIME, "StandbyTime", OPTV_INTEGER,
743      {0}, FALSE},
744     {FLAG_DPMS_SUSPENDTIME, "SuspendTime", OPTV_INTEGER,
745      {0}, FALSE},
746     {FLAG_DPMS_OFFTIME, "OffTime", OPTV_INTEGER,
747      {0}, FALSE},
748     {FLAG_PIXMAP, "Pixmap", OPTV_INTEGER,
749      {0}, FALSE},
750     {FLAG_NOPM, "NoPM", OPTV_BOOLEAN,
751      {0}, FALSE},
752     {FLAG_XINERAMA, "Xinerama", OPTV_BOOLEAN,
753      {0}, FALSE},
754     {FLAG_LOG, "Log", OPTV_STRING,
755      {0}, FALSE},
756     {FLAG_RENDER_COLORMAP_MODE, "RenderColormapMode", OPTV_STRING,
757      {0}, FALSE},
758     {FLAG_RANDR, "RandR", OPTV_BOOLEAN,
759      {0}, FALSE},
760     {FLAG_AIGLX, "AIGLX", OPTV_BOOLEAN,
761      {0}, FALSE},
762     {FLAG_IGNORE_ABI, "IgnoreABI", OPTV_BOOLEAN,
763      {0}, FALSE},
764     {FLAG_USE_DEFAULT_FONT_PATH, "UseDefaultFontPath", OPTV_BOOLEAN,
765      {0}, FALSE},
766     {FLAG_AUTO_ADD_DEVICES, "AutoAddDevices", OPTV_BOOLEAN,
767      {0}, FALSE},
768     {FLAG_AUTO_ENABLE_DEVICES, "AutoEnableDevices", OPTV_BOOLEAN,
769      {0}, FALSE},
770     {FLAG_GLX_VISUALS, "GlxVisuals", OPTV_STRING,
771      {0}, FALSE},
772     {FLAG_DRI2, "DRI2", OPTV_BOOLEAN,
773      {0}, FALSE},
774     {FLAG_USE_SIGIO, "UseSIGIO", OPTV_BOOLEAN,
775      {0}, FALSE},
776     {FLAG_AUTO_ADD_GPU, "AutoAddGPU", OPTV_BOOLEAN,
777      {0}, FALSE},
778     {-1, NULL, OPTV_NONE,
779      {0}, FALSE},
780 };
781
782 static Bool
783 configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
784 {
785     XF86OptionPtr optp, tmp;
786     int i;
787     Pix24Flags pix24 = Pix24DontCare;
788     Bool value;
789     MessageType from;
790     const char *s;
791     XkbRMLVOSet set;
792     const char *rules;
793
794     /* Default options. */
795 #ifndef _F_SET_XKB_DEFAULT_OPTIONS_FROM_CONFIGURE_
796     set.rules = "base";
797     set.model = "pc105";
798     set.layout = "us";
799     set.variant = NULL;
800     set.options = NULL;
801 #else//_F_SET_XKB_DEFAULT_OPTIONS_FROM_CONFIGURE_
802     set.rules = XKB_DFLT_RULES?XKB_DFLT_RULES:"base";
803     set.model = XKB_DFLT_MODEL?XKB_DFLT_MODEL:"pc105";
804     set.layout = XKB_DFLT_LAYOUT?XKB_DFLT_LAYOUT:"us";
805     set.variant = XKB_DFLT_VARIANT?XKB_DFLT_VARIANT:NULL;
806     set.options = XKB_DFLT_OPTIONS?XKB_DFLT_OPTIONS:NULL;
807 #endif//_F_SET_XKB_DEFAULT_OPTIONS_FROM_CONFIGURE_
808
809     /*
810      * Merge the ServerLayout and ServerFlags options.  The former have
811      * precedence over the latter.
812      */
813     optp = NULL;
814     if (flagsconf && flagsconf->flg_option_lst)
815         optp = xf86optionListDup(flagsconf->flg_option_lst);
816     if (layoutopts) {
817         tmp = xf86optionListDup(layoutopts);
818         if (optp)
819             optp = xf86optionListMerge(optp, tmp);
820         else
821             optp = tmp;
822     }
823
824     xf86ProcessOptions(-1, optp, FlagOptions);
825
826     xf86GetOptValBool(FlagOptions, FLAG_NOTRAPSIGNALS, &xf86Info.notrapSignals);
827     xf86GetOptValBool(FlagOptions, FLAG_DONTVTSWITCH, &xf86Info.dontVTSwitch);
828     xf86GetOptValBool(FlagOptions, FLAG_DONTZAP, &xf86Info.dontZap);
829     xf86GetOptValBool(FlagOptions, FLAG_DONTZOOM, &xf86Info.dontZoom);
830
831     xf86GetOptValBool(FlagOptions, FLAG_IGNORE_ABI, &xf86Info.ignoreABI);
832     if (xf86Info.ignoreABI) {
833         xf86Msg(X_CONFIG, "Ignoring ABI Version\n");
834     }
835
836     if (xf86SIGIOSupported()) {
837         xf86Info.useSIGIO =
838             xf86ReturnOptValBool(FlagOptions, FLAG_USE_SIGIO,
839                                  USE_SIGIO_BY_DEFAULT);
840         if (xf86IsOptionSet(FlagOptions, FLAG_USE_SIGIO)) {
841             from = X_CONFIG;
842         }
843         else {
844             from = X_DEFAULT;
845         }
846         if (!xf86Info.useSIGIO) {
847             xf86Msg(from, "Disabling SIGIO handlers for input devices\n");
848         }
849         else if (from == X_CONFIG) {
850             xf86Msg(from, "Enabling SIGIO handlers for input devices\n");
851         }
852     }
853     else {
854         xf86Info.useSIGIO = FALSE;
855     }
856
857     if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ADD_DEVICES)) {
858         xf86GetOptValBool(FlagOptions, FLAG_AUTO_ADD_DEVICES,
859                           &xf86Info.autoAddDevices);
860         from = X_CONFIG;
861     }
862     else {
863         from = X_DEFAULT;
864     }
865     xf86Msg(from, "%sutomatically adding devices\n",
866             xf86Info.autoAddDevices ? "A" : "Not a");
867
868     if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ENABLE_DEVICES)) {
869         xf86GetOptValBool(FlagOptions, FLAG_AUTO_ENABLE_DEVICES,
870                           &xf86Info.autoEnableDevices);
871         from = X_CONFIG;
872     }
873     else {
874         from = X_DEFAULT;
875     }
876     xf86Msg(from, "%sutomatically enabling devices\n",
877             xf86Info.autoEnableDevices ? "A" : "Not a");
878
879     if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ADD_GPU)) {
880         xf86GetOptValBool(FlagOptions, FLAG_AUTO_ADD_GPU,
881                           &xf86Info.autoAddGPU);
882         from = X_CONFIG;
883     }
884     else {
885         from = X_DEFAULT;
886     }
887     xf86Msg(from, "%sutomatically adding GPU devices\n",
888             xf86Info.autoAddGPU ? "A" : "Not a");
889     /*
890      * Set things up based on the config file information.  Some of these
891      * settings may be overridden later when the command line options are
892      * checked.
893      */
894 #ifdef XF86VIDMODE
895     if (xf86GetOptValBool(FlagOptions, FLAG_DISABLEVIDMODE, &value))
896         xf86Info.vidModeEnabled = !value;
897     if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWNONLOCAL, &value))
898         xf86Info.vidModeAllowNonLocal = value;
899 #endif
900
901     if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWMOUSEOPENFAIL, &value))
902         xf86Info.allowMouseOpenFail = value;
903
904     xf86Info.pmFlag = TRUE;
905     if (xf86GetOptValBool(FlagOptions, FLAG_NOPM, &value))
906         xf86Info.pmFlag = !value;
907     {
908         if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) {
909             if (!xf86NameCmp(s, "flush")) {
910                 xf86Msg(X_CONFIG, "Flushing logfile enabled\n");
911                 xf86Info.log = LogFlush;
912                 LogSetParameter(XLOG_FLUSH, TRUE);
913             }
914             else if (!xf86NameCmp(s, "sync")) {
915                 xf86Msg(X_CONFIG, "Syncing logfile enabled\n");
916                 xf86Info.log = LogSync;
917                 LogSetParameter(XLOG_FLUSH, TRUE);
918                 LogSetParameter(XLOG_SYNC, TRUE);
919             }
920             else {
921                 xf86Msg(X_WARNING, "Unknown Log option\n");
922             }
923         }
924     }
925
926     {
927         if ((s = xf86GetOptValString(FlagOptions, FLAG_RENDER_COLORMAP_MODE))) {
928             int policy = PictureParseCmapPolicy(s);
929
930             if (policy == PictureCmapPolicyInvalid)
931                 xf86Msg(X_WARNING, "Unknown colormap policy \"%s\"\n", s);
932             else {
933                 xf86Msg(X_CONFIG, "Render colormap policy set to %s\n", s);
934                 PictureCmapPolicy = policy;
935             }
936         }
937     }
938
939 #ifdef RANDR
940     xf86Info.disableRandR = FALSE;
941     xf86Info.randRFrom = X_DEFAULT;
942     if (xf86GetOptValBool(FlagOptions, FLAG_RANDR, &value)) {
943         xf86Info.disableRandR = !value;
944         xf86Info.randRFrom = X_CONFIG;
945     }
946 #endif
947
948     xf86Info.aiglx = TRUE;
949     xf86Info.aiglxFrom = X_DEFAULT;
950     if (xf86GetOptValBool(FlagOptions, FLAG_AIGLX, &value)) {
951         xf86Info.aiglx = value;
952         xf86Info.aiglxFrom = X_CONFIG;
953     }
954
955 #ifdef GLXEXT
956     xf86Info.glxVisuals = XF86_GlxVisualsTypical;
957     xf86Info.glxVisualsFrom = X_DEFAULT;
958     if ((s = xf86GetOptValString(FlagOptions, FLAG_GLX_VISUALS))) {
959         if (!xf86NameCmp(s, "minimal")) {
960             xf86Info.glxVisuals = XF86_GlxVisualsMinimal;
961         }
962         else if (!xf86NameCmp(s, "typical")) {
963             xf86Info.glxVisuals = XF86_GlxVisualsTypical;
964         }
965         else if (!xf86NameCmp(s, "all")) {
966             xf86Info.glxVisuals = XF86_GlxVisualsAll;
967         }
968         else {
969             xf86Msg(X_WARNING, "Unknown GlxVisuals option\n");
970         }
971     }
972
973     if (xf86GetOptValBool(FlagOptions, FLAG_AIGLX, &value)) {
974         xf86Info.aiglx = value;
975         xf86Info.aiglxFrom = X_CONFIG;
976     }
977 #endif
978
979     /* if we're not hotplugging, force some input devices to exist */
980     xf86Info.forceInputDevices = !(xf86Info.autoAddDevices &&
981                                    xf86Info.autoEnableDevices);
982
983     /* when forcing input devices, we use kbd. otherwise evdev, so use the
984      * evdev rules set. */
985 #if defined(linux)
986     if (!xf86Info.forceInputDevices)
987         rules = "evdev";
988     else
989 #endif
990         rules = "base";
991
992     /* Xkb default options. */
993     XkbInitRules(&set, rules, "pc105", "us", NULL, NULL);
994     XkbSetRulesDflts(&set);
995     XkbFreeRMLVOSet(&set, FALSE);
996
997     xf86Info.useDefaultFontPath = TRUE;
998     xf86Info.useDefaultFontPathFrom = X_DEFAULT;
999     if (xf86GetOptValBool(FlagOptions, FLAG_USE_DEFAULT_FONT_PATH, &value)) {
1000         xf86Info.useDefaultFontPath = value;
1001         xf86Info.useDefaultFontPathFrom = X_CONFIG;
1002     }
1003
1004 /* Make sure that timers don't overflow CARD32's after multiplying */
1005 #define MAX_TIME_IN_MIN (0x7fffffff / MILLI_PER_MIN)
1006
1007     i = -1;
1008     xf86GetOptValInteger(FlagOptions, FLAG_SAVER_BLANKTIME, &i);
1009     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
1010         ScreenSaverTime = defaultScreenSaverTime = i * MILLI_PER_MIN;
1011     else if (i != -1)
1012         xf86ConfigError
1013             ("BlankTime value %d outside legal range of 0 - %d minutes", i,
1014              MAX_TIME_IN_MIN);
1015
1016 #ifdef DPMSExtension
1017     i = -1;
1018     xf86GetOptValInteger(FlagOptions, FLAG_DPMS_STANDBYTIME, &i);
1019     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
1020         DPMSStandbyTime = i * MILLI_PER_MIN;
1021     else if (i != -1)
1022         xf86ConfigError
1023             ("StandbyTime value %d outside legal range of 0 - %d minutes", i,
1024              MAX_TIME_IN_MIN);
1025     i = -1;
1026     xf86GetOptValInteger(FlagOptions, FLAG_DPMS_SUSPENDTIME, &i);
1027     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
1028         DPMSSuspendTime = i * MILLI_PER_MIN;
1029     else if (i != -1)
1030         xf86ConfigError
1031             ("SuspendTime value %d outside legal range of 0 - %d minutes", i,
1032              MAX_TIME_IN_MIN);
1033     i = -1;
1034     xf86GetOptValInteger(FlagOptions, FLAG_DPMS_OFFTIME, &i);
1035     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
1036         DPMSOffTime = i * MILLI_PER_MIN;
1037     else if (i != -1)
1038         xf86ConfigError
1039             ("OffTime value %d outside legal range of 0 - %d minutes", i,
1040              MAX_TIME_IN_MIN);
1041 #endif
1042
1043     i = -1;
1044     xf86GetOptValInteger(FlagOptions, FLAG_PIXMAP, &i);
1045     switch (i) {
1046     case 24:
1047         pix24 = Pix24Use24;
1048         break;
1049     case 32:
1050         pix24 = Pix24Use32;
1051         break;
1052     case -1:
1053         break;
1054     default:
1055         xf86ConfigError("Pixmap option's value (%d) must be 24 or 32\n", i);
1056         return FALSE;
1057     }
1058     if (xf86Pix24 != Pix24DontCare) {
1059         xf86Info.pixmap24 = xf86Pix24;
1060         xf86Info.pix24From = X_CMDLINE;
1061     }
1062     else if (pix24 != Pix24DontCare) {
1063         xf86Info.pixmap24 = pix24;
1064         xf86Info.pix24From = X_CONFIG;
1065     }
1066     else {
1067         xf86Info.pixmap24 = Pix24DontCare;
1068         xf86Info.pix24From = X_DEFAULT;
1069     }
1070
1071 #ifdef PANORAMIX
1072     from = X_DEFAULT;
1073     if (!noPanoramiXExtension)
1074         from = X_CMDLINE;
1075     else if (xf86GetOptValBool(FlagOptions, FLAG_XINERAMA, &value)) {
1076         noPanoramiXExtension = !value;
1077         from = X_CONFIG;
1078     }
1079     if (!noPanoramiXExtension)
1080         xf86Msg(from, "Xinerama: enabled\n");
1081 #endif
1082
1083 #ifdef DRI2
1084     xf86Info.dri2 = FALSE;
1085     xf86Info.dri2From = X_DEFAULT;
1086     if (xf86GetOptValBool(FlagOptions, FLAG_DRI2, &value)) {
1087         xf86Info.dri2 = value;
1088         xf86Info.dri2From = X_CONFIG;
1089     }
1090 #endif
1091
1092     return TRUE;
1093 }
1094
1095 Bool
1096 xf86DRI2Enabled(void)
1097 {
1098     return xf86Info.dri2;
1099 }
1100
1101 /**
1102  * Search for the pInfo in the null-terminated list given and remove (and
1103  * free) it if present. All other devices are moved forward.
1104  */
1105 static void
1106 freeDevice(InputInfoPtr * list, InputInfoPtr pInfo)
1107 {
1108     InputInfoPtr *devs;
1109
1110     for (devs = list; devs && *devs; devs++) {
1111         if (*devs == pInfo) {
1112             free(*devs);
1113             for (; devs && *devs; devs++)
1114                 devs[0] = devs[1];
1115             break;
1116         }
1117     }
1118 }
1119
1120 /**
1121  * Append pInfo to the null-terminated list, allocating space as necessary.
1122  * pInfo is used as the last element.
1123  */
1124 static InputInfoPtr *
1125 addDevice(InputInfoPtr * list, InputInfoPtr pInfo)
1126 {
1127     InputInfoPtr *devs;
1128     int count = 1;
1129
1130     for (devs = list; devs && *devs; devs++)
1131         count++;
1132
1133     list = xnfrealloc(list, (count + 1) * sizeof(InputInfoPtr));
1134     list[count] = NULL;
1135
1136     list[count - 1] = pInfo;
1137     return list;
1138 }
1139
1140 /*
1141  * Locate the core input devices.  These can be specified/located in
1142  * the following ways, in order of priority:
1143  *
1144  *  1. The InputDevices named by the -pointer and -keyboard command line
1145  *     options.
1146  *  2. The "CorePointer" and "CoreKeyboard" InputDevices referred to by
1147  *     the active ServerLayout.
1148  *  3. The first InputDevices marked as "CorePointer" and "CoreKeyboard".
1149  *  4. The first InputDevices that use 'keyboard' or 'kbd' and a valid mouse
1150  *     driver (mouse, synaptics, evdev, vmmouse, void)
1151  *  5. Default devices with an empty (default) configuration.  These defaults
1152  *     will reference the 'mouse' and 'keyboard' drivers.
1153  */
1154
1155 static Bool
1156 checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
1157 {
1158     InputInfoPtr corePointer = NULL, coreKeyboard = NULL;
1159     Bool foundPointer = FALSE, foundKeyboard = FALSE;
1160     const char *pointerMsg = NULL, *keyboardMsg = NULL;
1161     InputInfoPtr *devs,         /* iterator */
1162      indp;
1163     InputInfoPtr Pointer, Keyboard;
1164     XF86ConfInputPtr confInput;
1165     XF86ConfInputRec defPtr, defKbd;
1166     MessageType from = X_DEFAULT;
1167
1168     const char *mousedrivers[] = { "mouse", "synaptics", "evdev", "vmmouse",
1169         "void", NULL
1170     };
1171
1172     /*
1173      * First check if a core pointer or core keyboard have been specified
1174      * in the active ServerLayout.  If more than one is specified for either,
1175      * remove the core attribute from the later ones.
1176      */
1177     for (devs = servlayoutp->inputs; devs && *devs; devs++) {
1178         indp = *devs;
1179         if (indp->options &&
1180             xf86CheckBoolOption(indp->options, "CorePointer", FALSE)) {
1181             if (!corePointer) {
1182                 corePointer = indp;
1183             }
1184         }
1185         if (indp->options &&
1186             xf86CheckBoolOption(indp->options, "CoreKeyboard", FALSE)) {
1187             if (!coreKeyboard) {
1188                 coreKeyboard = indp;
1189             }
1190         }
1191     }
1192
1193     confInput = NULL;
1194
1195     /* 1. Check for the -pointer command line option. */
1196     if (xf86PointerName) {
1197         confInput = xf86findInput(xf86PointerName,
1198                                   xf86configptr->conf_input_lst);
1199         if (!confInput) {
1200             xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n",
1201                     xf86PointerName);
1202             return FALSE;
1203         }
1204         from = X_CMDLINE;
1205         /*
1206          * If one was already specified in the ServerLayout, it needs to be
1207          * removed.
1208          */
1209         if (corePointer) {
1210             freeDevice(servlayoutp->inputs, corePointer);
1211             corePointer = NULL;
1212         }
1213         foundPointer = TRUE;
1214     }
1215
1216     /* 2. ServerLayout-specified core pointer. */
1217     if (corePointer) {
1218         foundPointer = TRUE;
1219         from = X_CONFIG;
1220     }
1221
1222     /* 3. First core pointer device. */
1223     if (!foundPointer && (xf86Info.forceInputDevices || implicitLayout)) {
1224         XF86ConfInputPtr p;
1225
1226         for (p = xf86configptr->conf_input_lst; p; p = p->list.next) {
1227             if (p->inp_option_lst &&
1228                 xf86CheckBoolOption(p->inp_option_lst, "CorePointer", FALSE)) {
1229                 confInput = p;
1230                 foundPointer = TRUE;
1231                 from = X_DEFAULT;
1232                 pointerMsg = "first core pointer device";
1233                 break;
1234             }
1235         }
1236     }
1237
1238     /* 4. First pointer with an allowed mouse driver. */
1239     if (!foundPointer && xf86Info.forceInputDevices) {
1240         const char **driver = mousedrivers;
1241
1242         confInput = xf86findInput(CONF_IMPLICIT_POINTER,
1243                                   xf86configptr->conf_input_lst);
1244         while (*driver && !confInput) {
1245             confInput = xf86findInputByDriver(*driver,
1246                                               xf86configptr->conf_input_lst);
1247             driver++;
1248         }
1249         if (confInput) {
1250             foundPointer = TRUE;
1251             from = X_DEFAULT;
1252             pointerMsg = "first mouse device";
1253         }
1254     }
1255
1256     /* 5. Built-in default. */
1257     if (!foundPointer && xf86Info.forceInputDevices) {
1258         memset(&defPtr, 0, sizeof(defPtr));
1259         defPtr.inp_identifier = strdup("<default pointer>");
1260         defPtr.inp_driver = strdup("mouse");
1261         confInput = &defPtr;
1262         foundPointer = TRUE;
1263         from = X_DEFAULT;
1264         pointerMsg = "default mouse configuration";
1265     }
1266
1267     /* Add the core pointer device to the layout, and set it to Core. */
1268     if (foundPointer && confInput) {
1269         Pointer = xf86AllocateInput();
1270         if (Pointer)
1271             foundPointer = configInput(Pointer, confInput, from);
1272         if (foundPointer) {
1273             Pointer->options = xf86AddNewOption(Pointer->options,
1274                                                 "CorePointer", "on");
1275             Pointer->options = xf86AddNewOption(Pointer->options,
1276                                                 "driver",
1277                                                 confInput->inp_driver);
1278             Pointer->options =
1279                 xf86AddNewOption(Pointer->options, "identifier",
1280                                  confInput->inp_identifier);
1281             servlayoutp->inputs = addDevice(servlayoutp->inputs, Pointer);
1282         }
1283     }
1284
1285     if (!foundPointer && xf86Info.forceInputDevices) {
1286         /* This shouldn't happen. */
1287         xf86Msg(X_ERROR, "Cannot locate a core pointer device.\n");
1288         xf86DeleteInput(Pointer, 0);
1289         return FALSE;
1290     }
1291
1292     confInput = NULL;
1293
1294     /* 1. Check for the -keyboard command line option. */
1295     if (xf86KeyboardName) {
1296         confInput = xf86findInput(xf86KeyboardName,
1297                                   xf86configptr->conf_input_lst);
1298         if (!confInput) {
1299             xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n",
1300                     xf86KeyboardName);
1301             return FALSE;
1302         }
1303         from = X_CMDLINE;
1304         /*
1305          * If one was already specified in the ServerLayout, it needs to be
1306          * removed.
1307          */
1308         if (coreKeyboard) {
1309             freeDevice(servlayoutp->inputs, coreKeyboard);
1310             coreKeyboard = NULL;
1311         }
1312         foundKeyboard = TRUE;
1313     }
1314
1315     /* 2. ServerLayout-specified core keyboard. */
1316     if (coreKeyboard) {
1317         foundKeyboard = TRUE;
1318         from = X_CONFIG;
1319     }
1320
1321     /* 3. First core keyboard device. */
1322     if (!foundKeyboard && (xf86Info.forceInputDevices || implicitLayout)) {
1323         XF86ConfInputPtr p;
1324
1325         for (p = xf86configptr->conf_input_lst; p; p = p->list.next) {
1326             if (p->inp_option_lst &&
1327                 xf86CheckBoolOption(p->inp_option_lst, "CoreKeyboard", FALSE)) {
1328                 confInput = p;
1329                 foundKeyboard = TRUE;
1330                 from = X_DEFAULT;
1331                 keyboardMsg = "first core keyboard device";
1332                 break;
1333             }
1334         }
1335     }
1336
1337     /* 4. First keyboard with 'keyboard' or 'kbd' as the driver. */
1338     if (!foundKeyboard && xf86Info.forceInputDevices) {
1339         confInput = xf86findInput(CONF_IMPLICIT_KEYBOARD,
1340                                   xf86configptr->conf_input_lst);
1341         if (!confInput) {
1342             confInput = xf86findInputByDriver("kbd",
1343                                               xf86configptr->conf_input_lst);
1344         }
1345         if (confInput) {
1346             foundKeyboard = TRUE;
1347             from = X_DEFAULT;
1348             keyboardMsg = "first keyboard device";
1349         }
1350     }
1351
1352     /* 5. Built-in default. */
1353     if (!foundKeyboard && xf86Info.forceInputDevices) {
1354         memset(&defKbd, 0, sizeof(defKbd));
1355         defKbd.inp_identifier = strdup("<default keyboard>");
1356         defKbd.inp_driver = strdup("kbd");
1357         confInput = &defKbd;
1358         foundKeyboard = TRUE;
1359         keyboardMsg = "default keyboard configuration";
1360         from = X_DEFAULT;
1361     }
1362
1363     /* Add the core keyboard device to the layout, and set it to Core. */
1364     if (foundKeyboard && confInput) {
1365         Keyboard = xf86AllocateInput();
1366         if (Keyboard)
1367             foundKeyboard = configInput(Keyboard, confInput, from);
1368         if (foundKeyboard) {
1369             Keyboard->options = xf86AddNewOption(Keyboard->options,
1370                                                  "CoreKeyboard", "on");
1371             Keyboard->options = xf86AddNewOption(Keyboard->options,
1372                                                  "driver",
1373                                                  confInput->inp_driver);
1374             Keyboard->options =
1375                 xf86AddNewOption(Keyboard->options, "identifier",
1376                                  confInput->inp_identifier);
1377             servlayoutp->inputs = addDevice(servlayoutp->inputs, Keyboard);
1378         }
1379     }
1380
1381     if (!foundKeyboard && xf86Info.forceInputDevices) {
1382         /* This shouldn't happen. */
1383         xf86Msg(X_ERROR, "Cannot locate a core keyboard device.\n");
1384         xf86DeleteInput(Keyboard, 0);
1385         return FALSE;
1386     }
1387
1388     if (pointerMsg) {
1389         if (implicitLayout)
1390             xf86Msg(X_DEFAULT, "No Layout section. Using the %s.\n",
1391                     pointerMsg);
1392         else
1393             xf86Msg(X_DEFAULT, "The core pointer device wasn't specified "
1394                     "explicitly in the layout.\n"
1395                     "\tUsing the %s.\n", pointerMsg);
1396     }
1397
1398     if (keyboardMsg) {
1399         if (implicitLayout)
1400             xf86Msg(X_DEFAULT, "No Layout section. Using the %s.\n",
1401                     keyboardMsg);
1402         else
1403             xf86Msg(X_DEFAULT, "The core keyboard device wasn't specified "
1404                     "explicitly in the layout.\n"
1405                     "\tUsing the %s.\n", keyboardMsg);
1406     }
1407
1408     if (!xf86Info.forceInputDevices && !(foundPointer && foundKeyboard)) {
1409 #if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS)
1410         const char *config_backend;
1411
1412 #if defined(CONFIG_HAL)
1413         config_backend = "HAL";
1414 #elif defined(CONFIG_UDEV)
1415         config_backend = "udev";
1416 #else
1417         config_backend = "wscons";
1418 #endif
1419         xf86Msg(X_INFO, "The server relies on %s to provide the list of "
1420                 "input devices.\n\tIf no devices become available, "
1421                 "reconfigure %s or disable AutoAddDevices.\n",
1422                 config_backend, config_backend);
1423 #else
1424         xf86Msg(X_WARNING, "Hotplugging requested but the server was "
1425                 "compiled without a config backend. "
1426                 "No input devices were configured, the server "
1427                 "will start without any input devices.\n");
1428 #endif
1429     }
1430
1431     return TRUE;
1432 }
1433
1434 typedef enum {
1435     LAYOUT_ISOLATEDEVICE,
1436     LAYOUT_SINGLECARD
1437 } LayoutValues;
1438
1439 static OptionInfoRec LayoutOptions[] = {
1440     {LAYOUT_ISOLATEDEVICE, "IsolateDevice", OPTV_STRING,
1441      {0}, FALSE},
1442     {LAYOUT_SINGLECARD, "SingleCard", OPTV_BOOLEAN,
1443      {0}, FALSE},
1444     {-1, NULL, OPTV_NONE,
1445      {0}, FALSE},
1446 };
1447
1448 static Bool
1449 configInputDevices(XF86ConfLayoutPtr layout, serverLayoutPtr servlayoutp)
1450 {
1451     XF86ConfInputrefPtr irp;
1452     InputInfoPtr *indp;
1453     int count = 0;
1454
1455     /*
1456      * Count the number of input devices.
1457      */
1458     irp = layout->lay_input_lst;
1459     while (irp) {
1460         count++;
1461         irp = (XF86ConfInputrefPtr) irp->list.next;
1462     }
1463     DebugF("Found %d input devices in the layout section %s\n",
1464            count, layout->lay_identifier);
1465     indp = xnfcalloc((count + 1), sizeof(InputInfoPtr));
1466     indp[count] = NULL;
1467     irp = layout->lay_input_lst;
1468     count = 0;
1469     while (irp) {
1470         indp[count] = xf86AllocateInput();
1471         if (!configInput(indp[count], irp->iref_inputdev, X_CONFIG)) {
1472             do {
1473                 free(indp[count]);
1474             } while (count--);
1475             free(indp);
1476             return FALSE;
1477         }
1478         indp[count]->options = xf86OptionListMerge(indp[count]->options,
1479                                                    irp->iref_option_lst);
1480         count++;
1481         irp = (XF86ConfInputrefPtr) irp->list.next;
1482     }
1483     servlayoutp->inputs = indp;
1484
1485     return TRUE;
1486 }
1487
1488 /*
1489  * figure out which layout is active, which screens are used in that layout,
1490  * which drivers and monitors are used in these screens
1491  */
1492 static Bool
1493 configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
1494              char *default_layout)
1495 {
1496     XF86ConfAdjacencyPtr adjp;
1497     XF86ConfInactivePtr idp;
1498     int saved_count, count = 0;
1499     int scrnum;
1500     XF86ConfLayoutPtr l;
1501     MessageType from;
1502     screenLayoutPtr slp;
1503     GDevPtr gdp;
1504     int i = 0, j;
1505
1506     if (!servlayoutp)
1507         return FALSE;
1508
1509     /*
1510      * which layout section is the active one?
1511      *
1512      * If there is a -layout command line option, use that one, otherwise
1513      * pick the first one.
1514      */
1515     from = X_DEFAULT;
1516     if (xf86LayoutName != NULL)
1517         from = X_CMDLINE;
1518     else if (default_layout) {
1519         xf86LayoutName = default_layout;
1520         from = X_CONFIG;
1521     }
1522     if (xf86LayoutName != NULL) {
1523         if ((l = xf86findLayout(xf86LayoutName, conf_layout)) == NULL) {
1524             xf86Msg(X_ERROR, "No ServerLayout section called \"%s\"\n",
1525                     xf86LayoutName);
1526             return FALSE;
1527         }
1528         conf_layout = l;
1529     }
1530     xf86Msg(from, "ServerLayout \"%s\"\n", conf_layout->lay_identifier);
1531     adjp = conf_layout->lay_adjacency_lst;
1532
1533     /*
1534      * we know that each screen is referenced exactly once on the left side
1535      * of a layout statement in the Layout section. So to allocate the right
1536      * size for the array we do a quick walk of the list to figure out how
1537      * many sections we have
1538      */
1539     while (adjp) {
1540         count++;
1541         adjp = (XF86ConfAdjacencyPtr) adjp->list.next;
1542     }
1543
1544     DebugF("Found %d screens in the layout section %s",
1545            count, conf_layout->lay_identifier);
1546     if (!count)                 /* alloc enough storage even if no screen is specified */
1547         count = 1;
1548
1549     slp = xnfcalloc(1, (count + 1) * sizeof(screenLayoutRec));
1550     slp[count].screen = NULL;
1551     /*
1552      * now that we have storage, loop over the list again and fill in our
1553      * data structure; at this point we do not fill in the adjacency
1554      * information as it is not clear if we need it at all
1555      */
1556     adjp = conf_layout->lay_adjacency_lst;
1557     count = 0;
1558     while (adjp) {
1559         slp[count].screen = xnfcalloc(1, sizeof(confScreenRec));
1560         if (adjp->adj_scrnum < 0)
1561             scrnum = count;
1562         else
1563             scrnum = adjp->adj_scrnum;
1564         if (!configScreen(slp[count].screen, adjp->adj_screen, scrnum,
1565                           X_CONFIG)) {
1566             do {
1567                 free(slp[count].screen);
1568             } while (count--);
1569             free(slp);
1570             return FALSE;
1571         }
1572         slp[count].x = adjp->adj_x;
1573         slp[count].y = adjp->adj_y;
1574         slp[count].refname = adjp->adj_refscreen;
1575         switch (adjp->adj_where) {
1576         case CONF_ADJ_OBSOLETE:
1577             slp[count].where = PosObsolete;
1578             slp[count].topname = adjp->adj_top_str;
1579             slp[count].bottomname = adjp->adj_bottom_str;
1580             slp[count].leftname = adjp->adj_left_str;
1581             slp[count].rightname = adjp->adj_right_str;
1582             break;
1583         case CONF_ADJ_ABSOLUTE:
1584             slp[count].where = PosAbsolute;
1585             break;
1586         case CONF_ADJ_RIGHTOF:
1587             slp[count].where = PosRightOf;
1588             break;
1589         case CONF_ADJ_LEFTOF:
1590             slp[count].where = PosLeftOf;
1591             break;
1592         case CONF_ADJ_ABOVE:
1593             slp[count].where = PosAbove;
1594             break;
1595         case CONF_ADJ_BELOW:
1596             slp[count].where = PosBelow;
1597             break;
1598         case CONF_ADJ_RELATIVE:
1599             slp[count].where = PosRelative;
1600             break;
1601         }
1602         count++;
1603         adjp = (XF86ConfAdjacencyPtr) adjp->list.next;
1604     }
1605
1606     /* No screen was specified in the layout. take the first one from the
1607      * config file, or - if it is NULL - configScreen autogenerates one for
1608      * us */
1609     if (!count) {
1610         XF86ConfScreenPtr screen;
1611
1612         FIND_SUITABLE (XF86ConfScreenPtr, xf86configptr->conf_screen_lst, screen);
1613         slp[0].screen = xnfcalloc(1, sizeof(confScreenRec));
1614         if (!configScreen(slp[0].screen, screen,
1615                           0, X_CONFIG)) {
1616             free(slp[0].screen);
1617             free(slp);
1618             return FALSE;
1619         }
1620     }
1621
1622     /* XXX Need to tie down the upper left screen. */
1623
1624     /* Fill in the refscreen and top/bottom/left/right values */
1625     for (i = 0; i < count; i++) {
1626         for (j = 0; j < count; j++) {
1627             if (slp[i].refname &&
1628                 strcmp(slp[i].refname, slp[j].screen->id) == 0) {
1629                 slp[i].refscreen = slp[j].screen;
1630             }
1631             if (slp[i].topname &&
1632                 strcmp(slp[i].topname, slp[j].screen->id) == 0) {
1633                 slp[i].top = slp[j].screen;
1634             }
1635             if (slp[i].bottomname &&
1636                 strcmp(slp[i].bottomname, slp[j].screen->id) == 0) {
1637                 slp[i].bottom = slp[j].screen;
1638             }
1639             if (slp[i].leftname &&
1640                 strcmp(slp[i].leftname, slp[j].screen->id) == 0) {
1641                 slp[i].left = slp[j].screen;
1642             }
1643             if (slp[i].rightname &&
1644                 strcmp(slp[i].rightname, slp[j].screen->id) == 0) {
1645                 slp[i].right = slp[j].screen;
1646             }
1647         }
1648         if (slp[i].where != PosObsolete
1649             && slp[i].where != PosAbsolute && !slp[i].refscreen) {
1650             xf86Msg(X_ERROR, "Screen %s doesn't exist: deleting placement\n",
1651                     slp[i].refname);
1652             slp[i].where = PosAbsolute;
1653             slp[i].x = 0;
1654             slp[i].y = 0;
1655         }
1656     }
1657
1658     if (!count)
1659         saved_count = 1;
1660     else
1661         saved_count = count;
1662     /*
1663      * Count the number of inactive devices.
1664      */
1665     count = 0;
1666     idp = conf_layout->lay_inactive_lst;
1667     while (idp) {
1668         count++;
1669         idp = (XF86ConfInactivePtr) idp->list.next;
1670     }
1671     DebugF("Found %d inactive devices in the layout section %s\n",
1672            count, conf_layout->lay_identifier);
1673     gdp = xnfalloc((count + 1) * sizeof(GDevRec));
1674     gdp[count].identifier = NULL;
1675     idp = conf_layout->lay_inactive_lst;
1676     count = 0;
1677     while (idp) {
1678         if (!configDevice(&gdp[count], idp->inactive_device, FALSE))
1679             goto bail;
1680         count++;
1681         idp = (XF86ConfInactivePtr) idp->list.next;
1682     }
1683
1684     if (!configInputDevices(conf_layout, servlayoutp))
1685         goto bail;
1686
1687     servlayoutp->id = conf_layout->lay_identifier;
1688     servlayoutp->screens = slp;
1689     servlayoutp->inactives = gdp;
1690     servlayoutp->options = conf_layout->lay_option_lst;
1691     from = X_DEFAULT;
1692
1693     return TRUE;
1694
1695  bail:
1696     do {
1697         free(slp[saved_count].screen);
1698     } while (saved_count--);
1699     free(slp);
1700     free(gdp);
1701     return FALSE;
1702 }
1703
1704 /*
1705  * No layout section, so find the first Screen section and set that up as
1706  * the only active screen.
1707  */
1708 static Bool
1709 configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen,
1710                     XF86ConfigPtr conf_ptr)
1711 {
1712     MessageType from;
1713     XF86ConfScreenPtr s;
1714     screenLayoutPtr slp;
1715     InputInfoPtr *indp;
1716     XF86ConfLayoutRec layout;
1717
1718     if (!servlayoutp)
1719         return FALSE;
1720
1721     /*
1722      * which screen section is the active one?
1723      *
1724      * If there is a -screen option, use that one, otherwise use the first
1725      * one.
1726      */
1727
1728     from = X_CONFIG;
1729     if (xf86ScreenName != NULL) {
1730         if ((s = xf86findScreen(xf86ScreenName, conf_screen)) == NULL) {
1731             xf86Msg(X_ERROR, "No Screen section called \"%s\"\n",
1732                     xf86ScreenName);
1733             return FALSE;
1734         }
1735         conf_screen = s;
1736         from = X_CMDLINE;
1737     }
1738
1739     /* We have exactly one screen */
1740
1741     slp = xnfcalloc(1, 2 * sizeof(screenLayoutRec));
1742     slp[0].screen = xnfcalloc(1, sizeof(confScreenRec));
1743     slp[1].screen = NULL;
1744     if (!configScreen(slp[0].screen, conf_screen, 0, from)) {
1745         free(slp);
1746         return FALSE;
1747     }
1748     servlayoutp->id = "(implicit)";
1749     servlayoutp->screens = slp;
1750     servlayoutp->inactives = xnfcalloc(1, sizeof(GDevRec));
1751     servlayoutp->options = NULL;
1752
1753     memset(&layout, 0, sizeof(layout));
1754     layout.lay_identifier = servlayoutp->id;
1755     if (xf86layoutAddInputDevices(conf_ptr, &layout) > 0) {
1756         if (!configInputDevices(&layout, servlayoutp))
1757             return FALSE;
1758         from = X_DEFAULT;
1759     }
1760     else {
1761         /* Set up an empty input device list, then look for some core devices. */
1762         indp = xnfalloc(sizeof(InputInfoPtr));
1763         *indp = NULL;
1764         servlayoutp->inputs = indp;
1765     }
1766
1767     return TRUE;
1768 }
1769
1770 static Bool
1771 configXvAdaptor(confXvAdaptorPtr adaptor, XF86ConfVideoAdaptorPtr conf_adaptor)
1772 {
1773     int count = 0;
1774     XF86ConfVideoPortPtr conf_port;
1775
1776     xf86Msg(X_CONFIG, "|   |-->VideoAdaptor \"%s\"\n",
1777             conf_adaptor->va_identifier);
1778     adaptor->identifier = conf_adaptor->va_identifier;
1779     adaptor->options = conf_adaptor->va_option_lst;
1780     if (conf_adaptor->va_busid || conf_adaptor->va_driver) {
1781         xf86Msg(X_CONFIG, "|   | Unsupported device type, skipping entry\n");
1782         return FALSE;
1783     }
1784
1785     /*
1786      * figure out how many videoport subsections there are and fill them in
1787      */
1788     conf_port = conf_adaptor->va_port_lst;
1789     while (conf_port) {
1790         count++;
1791         conf_port = (XF86ConfVideoPortPtr) conf_port->list.next;
1792     }
1793     adaptor->ports = xnfalloc((count) * sizeof(confXvPortRec));
1794     adaptor->numports = count;
1795     count = 0;
1796     conf_port = conf_adaptor->va_port_lst;
1797     while (conf_port) {
1798         adaptor->ports[count].identifier = conf_port->vp_identifier;
1799         adaptor->ports[count].options = conf_port->vp_option_lst;
1800         count++;
1801         conf_port = (XF86ConfVideoPortPtr) conf_port->list.next;
1802     }
1803
1804     return TRUE;
1805 }
1806
1807 static Bool
1808 configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
1809              MessageType from)
1810 {
1811     int count = 0;
1812     XF86ConfDisplayPtr dispptr;
1813     XF86ConfAdaptorLinkPtr conf_adaptor;
1814     Bool defaultMonitor = FALSE;
1815     XF86ConfScreenRec local_conf_screen;
1816
1817     if (!conf_screen) {
1818         memset(&local_conf_screen, 0, sizeof(local_conf_screen));
1819         conf_screen = &local_conf_screen;
1820         conf_screen->scrn_identifier = "Default Screen Section";
1821         xf86Msg(X_DEFAULT, "No screen section available. Using defaults.\n");
1822     }
1823
1824     xf86Msg(from, "|-->Screen \"%s\" (%d)\n", conf_screen->scrn_identifier,
1825             scrnum);
1826     /*
1827      * now we fill in the elements of the screen
1828      */
1829     screenp->id = conf_screen->scrn_identifier;
1830     screenp->screennum = scrnum;
1831     screenp->defaultdepth = conf_screen->scrn_defaultdepth;
1832     screenp->defaultbpp = conf_screen->scrn_defaultbpp;
1833     screenp->defaultfbbpp = conf_screen->scrn_defaultfbbpp;
1834     screenp->monitor = xnfcalloc(1, sizeof(MonRec));
1835     /* If no monitor is specified, create a default one. */
1836     if (!conf_screen->scrn_monitor) {
1837         XF86ConfMonitorRec defMon;
1838
1839         memset(&defMon, 0, sizeof(defMon));
1840         defMon.mon_identifier = "<default monitor>";
1841         if (!configMonitor(screenp->monitor, &defMon))
1842             return FALSE;
1843         defaultMonitor = TRUE;
1844     }
1845     else {
1846         if (!configMonitor(screenp->monitor, conf_screen->scrn_monitor))
1847             return FALSE;
1848     }
1849     /* Configure the device. If there isn't one configured, attach to the
1850      * first inactive one that we can configure. If there's none that work,
1851      * set it to NULL so that the section can be autoconfigured later */
1852     screenp->device = xnfcalloc(1, sizeof(GDevRec));
1853     if ((!conf_screen->scrn_device) && (xf86configptr->conf_device_lst)) {
1854         FIND_SUITABLE (XF86ConfDevicePtr, xf86configptr->conf_device_lst, conf_screen->scrn_device);
1855         xf86Msg(X_DEFAULT, "No device specified for screen \"%s\".\n"
1856                 "\tUsing the first device section listed.\n", screenp->id);
1857     }
1858     if (configDevice(screenp->device, conf_screen->scrn_device, TRUE)) {
1859         screenp->device->myScreenSection = screenp;
1860     }
1861     else {
1862         screenp->device = NULL;
1863     }
1864     screenp->options = conf_screen->scrn_option_lst;
1865
1866     /*
1867      * figure out how many display subsections there are and fill them in
1868      */
1869     dispptr = conf_screen->scrn_display_lst;
1870     while (dispptr) {
1871         count++;
1872         dispptr = (XF86ConfDisplayPtr) dispptr->list.next;
1873     }
1874     screenp->displays = xnfalloc((count) * sizeof(DispRec));
1875     screenp->numdisplays = count;
1876
1877     /* Fill in the default Virtual size, if any */
1878     if (conf_screen->scrn_virtualX && conf_screen->scrn_virtualY) {
1879         for (count = 0, dispptr = conf_screen->scrn_display_lst;
1880              dispptr;
1881              dispptr = (XF86ConfDisplayPtr) dispptr->list.next, count++) {
1882             screenp->displays[count].virtualX = conf_screen->scrn_virtualX;
1883             screenp->displays[count].virtualY = conf_screen->scrn_virtualY;
1884         }
1885     }
1886
1887     /* Now do the per-Display Virtual sizes */
1888     count = 0;
1889     dispptr = conf_screen->scrn_display_lst;
1890     while (dispptr) {
1891         configDisplay(&(screenp->displays[count]), dispptr);
1892         count++;
1893         dispptr = (XF86ConfDisplayPtr) dispptr->list.next;
1894     }
1895
1896     /*
1897      * figure out how many videoadaptor references there are and fill them in
1898      */
1899     conf_adaptor = conf_screen->scrn_adaptor_lst;
1900     while (conf_adaptor) {
1901         count++;
1902         conf_adaptor = (XF86ConfAdaptorLinkPtr) conf_adaptor->list.next;
1903     }
1904     screenp->xvadaptors = xnfalloc((count) * sizeof(confXvAdaptorRec));
1905     screenp->numxvadaptors = 0;
1906     conf_adaptor = conf_screen->scrn_adaptor_lst;
1907     while (conf_adaptor) {
1908         if (configXvAdaptor(&(screenp->xvadaptors[screenp->numxvadaptors]),
1909                             conf_adaptor->al_adaptor))
1910             screenp->numxvadaptors++;
1911         conf_adaptor = (XF86ConfAdaptorLinkPtr) conf_adaptor->list.next;
1912     }
1913
1914     if (defaultMonitor) {
1915         xf86Msg(X_DEFAULT, "No monitor specified for screen \"%s\".\n"
1916                 "\tUsing a default monitor configuration.\n", screenp->id);
1917     }
1918     return TRUE;
1919 }
1920
1921 typedef enum {
1922     MON_REDUCEDBLANKING,
1923     MON_MAX_PIX_CLOCK,
1924 } MonitorValues;
1925
1926 static OptionInfoRec MonitorOptions[] = {
1927     {MON_REDUCEDBLANKING, "ReducedBlanking", OPTV_BOOLEAN,
1928      {0}, FALSE},
1929     {MON_MAX_PIX_CLOCK, "MaxPixClock", OPTV_FREQ,
1930      {0}, FALSE},
1931     {-1, NULL, OPTV_NONE,
1932      {0}, FALSE},
1933 };
1934
1935 static Bool
1936 configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor)
1937 {
1938     int count;
1939     DisplayModePtr mode, last = NULL;
1940     XF86ConfModeLinePtr cmodep;
1941     XF86ConfModesPtr modes;
1942     XF86ConfModesLinkPtr modeslnk = conf_monitor->mon_modes_sect_lst;
1943     Gamma zeros = { 0.0, 0.0, 0.0 };
1944     float badgamma = 0.0;
1945     double maxPixClock;
1946
1947     xf86Msg(X_CONFIG, "|   |-->Monitor \"%s\"\n", conf_monitor->mon_identifier);
1948     monitorp->id = conf_monitor->mon_identifier;
1949     monitorp->vendor = conf_monitor->mon_vendor;
1950     monitorp->model = conf_monitor->mon_modelname;
1951     monitorp->Modes = NULL;
1952     monitorp->Last = NULL;
1953     monitorp->gamma = zeros;
1954     monitorp->widthmm = conf_monitor->mon_width;
1955     monitorp->heightmm = conf_monitor->mon_height;
1956     monitorp->reducedblanking = FALSE;
1957     monitorp->maxPixClock = 0;
1958     monitorp->options = conf_monitor->mon_option_lst;
1959
1960     /*
1961      * fill in the monitor structure
1962      */
1963     for (count = 0;
1964          count < conf_monitor->mon_n_hsync && count < MAX_HSYNC; count++) {
1965         monitorp->hsync[count].hi = conf_monitor->mon_hsync[count].hi;
1966         monitorp->hsync[count].lo = conf_monitor->mon_hsync[count].lo;
1967     }
1968     monitorp->nHsync = count;
1969     for (count = 0;
1970          count < conf_monitor->mon_n_vrefresh && count < MAX_VREFRESH;
1971          count++) {
1972         monitorp->vrefresh[count].hi = conf_monitor->mon_vrefresh[count].hi;
1973         monitorp->vrefresh[count].lo = conf_monitor->mon_vrefresh[count].lo;
1974     }
1975     monitorp->nVrefresh = count;
1976
1977     /*
1978      * first we collect the mode lines from the UseModes directive
1979      */
1980     while (modeslnk) {
1981         modes = xf86findModes(modeslnk->ml_modes_str,
1982                               xf86configptr->conf_modes_lst);
1983         modeslnk->ml_modes = modes;
1984
1985         /* now add the modes found in the modes
1986            section to the list of modes for this
1987            monitor unless it has been added before
1988            because we are reusing the same section 
1989            for another screen */
1990         if (xf86itemNotSublist((GenericListPtr) conf_monitor->mon_modeline_lst,
1991                                (GenericListPtr) modes->mon_modeline_lst)) {
1992             conf_monitor->mon_modeline_lst = (XF86ConfModeLinePtr)
1993                 xf86addListItem((GenericListPtr) conf_monitor->mon_modeline_lst,
1994                                 (GenericListPtr) modes->mon_modeline_lst);
1995         }
1996         modeslnk = modeslnk->list.next;
1997     }
1998
1999     /*
2000      * we need to hook in the mode lines now
2001      * here both data structures use lists, only our internal one
2002      * is double linked
2003      */
2004     cmodep = conf_monitor->mon_modeline_lst;
2005     while (cmodep) {
2006         mode = xnfcalloc(1, sizeof(DisplayModeRec));
2007         mode->type = 0;
2008         mode->Clock = cmodep->ml_clock;
2009         mode->HDisplay = cmodep->ml_hdisplay;
2010         mode->HSyncStart = cmodep->ml_hsyncstart;
2011         mode->HSyncEnd = cmodep->ml_hsyncend;
2012         mode->HTotal = cmodep->ml_htotal;
2013         mode->VDisplay = cmodep->ml_vdisplay;
2014         mode->VSyncStart = cmodep->ml_vsyncstart;
2015         mode->VSyncEnd = cmodep->ml_vsyncend;
2016         mode->VTotal = cmodep->ml_vtotal;
2017         mode->Flags = cmodep->ml_flags;
2018         mode->HSkew = cmodep->ml_hskew;
2019         mode->VScan = cmodep->ml_vscan;
2020         mode->name = xnfstrdup(cmodep->ml_identifier);
2021         if (last) {
2022             mode->prev = last;
2023             last->next = mode;
2024         }
2025         else {
2026             /*
2027              * this is the first mode
2028              */
2029             monitorp->Modes = mode;
2030             mode->prev = NULL;
2031         }
2032         last = mode;
2033         cmodep = (XF86ConfModeLinePtr) cmodep->list.next;
2034     }
2035     if (last) {
2036         last->next = NULL;
2037     }
2038     monitorp->Last = last;
2039
2040     /* add the (VESA) default modes */
2041     if (!addDefaultModes(monitorp))
2042         return FALSE;
2043
2044     if (conf_monitor->mon_gamma_red > GAMMA_ZERO)
2045         monitorp->gamma.red = conf_monitor->mon_gamma_red;
2046     if (conf_monitor->mon_gamma_green > GAMMA_ZERO)
2047         monitorp->gamma.green = conf_monitor->mon_gamma_green;
2048     if (conf_monitor->mon_gamma_blue > GAMMA_ZERO)
2049         monitorp->gamma.blue = conf_monitor->mon_gamma_blue;
2050
2051     /* Check that the gamma values are within range */
2052     if (monitorp->gamma.red > GAMMA_ZERO &&
2053         (monitorp->gamma.red < GAMMA_MIN || monitorp->gamma.red > GAMMA_MAX)) {
2054         badgamma = monitorp->gamma.red;
2055     }
2056     else if (monitorp->gamma.green > GAMMA_ZERO &&
2057              (monitorp->gamma.green < GAMMA_MIN ||
2058               monitorp->gamma.green > GAMMA_MAX)) {
2059         badgamma = monitorp->gamma.green;
2060     }
2061     else if (monitorp->gamma.blue > GAMMA_ZERO &&
2062              (monitorp->gamma.blue < GAMMA_MIN ||
2063               monitorp->gamma.blue > GAMMA_MAX)) {
2064         badgamma = monitorp->gamma.blue;
2065     }
2066     if (badgamma > GAMMA_ZERO) {
2067         xf86ConfigError("Gamma value %.f is out of range (%.2f - %.1f)\n",
2068                         badgamma, GAMMA_MIN, GAMMA_MAX);
2069         return FALSE;
2070     }
2071
2072     xf86ProcessOptions(-1, monitorp->options, MonitorOptions);
2073     xf86GetOptValBool(MonitorOptions, MON_REDUCEDBLANKING,
2074                       &monitorp->reducedblanking);
2075     if (xf86GetOptValFreq(MonitorOptions, MON_MAX_PIX_CLOCK, OPTUNITS_KHZ,
2076                           &maxPixClock) == TRUE) {
2077         monitorp->maxPixClock = (int) maxPixClock;
2078     }
2079
2080     return TRUE;
2081 }
2082
2083 static int
2084 lookupVisual(const char *visname)
2085 {
2086     int i;
2087
2088     if (!visname || !*visname)
2089         return -1;
2090
2091     for (i = 0; i <= DirectColor; i++) {
2092         if (!xf86nameCompare(visname, xf86VisualNames[i]))
2093             break;
2094     }
2095
2096     if (i <= DirectColor)
2097         return i;
2098
2099     return -1;
2100 }
2101
2102 static Bool
2103 configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display)
2104 {
2105     int count = 0;
2106     XF86ModePtr modep;
2107
2108     displayp->frameX0 = conf_display->disp_frameX0;
2109     displayp->frameY0 = conf_display->disp_frameY0;
2110     displayp->virtualX = conf_display->disp_virtualX;
2111     displayp->virtualY = conf_display->disp_virtualY;
2112     displayp->depth = conf_display->disp_depth;
2113     displayp->fbbpp = conf_display->disp_bpp;
2114     displayp->weight.red = conf_display->disp_weight.red;
2115     displayp->weight.green = conf_display->disp_weight.green;
2116     displayp->weight.blue = conf_display->disp_weight.blue;
2117     displayp->blackColour.red = conf_display->disp_black.red;
2118     displayp->blackColour.green = conf_display->disp_black.green;
2119     displayp->blackColour.blue = conf_display->disp_black.blue;
2120     displayp->whiteColour.red = conf_display->disp_white.red;
2121     displayp->whiteColour.green = conf_display->disp_white.green;
2122     displayp->whiteColour.blue = conf_display->disp_white.blue;
2123     displayp->options = conf_display->disp_option_lst;
2124     if (conf_display->disp_visual) {
2125         displayp->defaultVisual = lookupVisual(conf_display->disp_visual);
2126         if (displayp->defaultVisual == -1) {
2127             xf86ConfigError("Invalid visual name: \"%s\"",
2128                             conf_display->disp_visual);
2129             return FALSE;
2130         }
2131     }
2132     else {
2133         displayp->defaultVisual = -1;
2134     }
2135
2136     /*
2137      * now hook in the modes
2138      */
2139     modep = conf_display->disp_mode_lst;
2140     while (modep) {
2141         count++;
2142         modep = (XF86ModePtr) modep->list.next;
2143     }
2144     displayp->modes = xnfalloc((count + 1) * sizeof(char *));
2145     modep = conf_display->disp_mode_lst;
2146     count = 0;
2147     while (modep) {
2148         displayp->modes[count] = modep->mode_name;
2149         count++;
2150         modep = (XF86ModePtr) modep->list.next;
2151     }
2152     displayp->modes[count] = NULL;
2153
2154     return TRUE;
2155 }
2156
2157 static Bool
2158 configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, Bool active)
2159 {
2160     int i;
2161
2162     if (!conf_device) {
2163         return FALSE;
2164     }
2165
2166     if (active)
2167         xf86Msg(X_CONFIG, "|   |-->Device \"%s\"\n",
2168                 conf_device->dev_identifier);
2169     else
2170         xf86Msg(X_CONFIG, "|-->Inactive Device \"%s\"\n",
2171                 conf_device->dev_identifier);
2172
2173     devicep->identifier = conf_device->dev_identifier;
2174     devicep->vendor = conf_device->dev_vendor;
2175     devicep->board = conf_device->dev_board;
2176     devicep->chipset = conf_device->dev_chipset;
2177     devicep->ramdac = conf_device->dev_ramdac;
2178     devicep->driver = conf_device->dev_driver;
2179     devicep->active = active;
2180     devicep->videoRam = conf_device->dev_videoram;
2181     devicep->BiosBase = conf_device->dev_bios_base;
2182     devicep->MemBase = conf_device->dev_mem_base;
2183     devicep->IOBase = conf_device->dev_io_base;
2184     devicep->clockchip = conf_device->dev_clockchip;
2185     devicep->busID = conf_device->dev_busid;
2186     devicep->textClockFreq = conf_device->dev_textclockfreq;
2187     devicep->chipID = conf_device->dev_chipid;
2188     devicep->chipRev = conf_device->dev_chiprev;
2189     devicep->options = conf_device->dev_option_lst;
2190     devicep->irq = conf_device->dev_irq;
2191     devicep->screen = conf_device->dev_screen;
2192
2193     for (i = 0; i < MAXDACSPEEDS; i++) {
2194         if (i < CONF_MAXDACSPEEDS)
2195             devicep->dacSpeeds[i] = conf_device->dev_dacSpeeds[i];
2196         else
2197             devicep->dacSpeeds[i] = 0;
2198     }
2199     devicep->numclocks = conf_device->dev_clocks;
2200     if (devicep->numclocks > MAXCLOCKS)
2201         devicep->numclocks = MAXCLOCKS;
2202     for (i = 0; i < devicep->numclocks; i++) {
2203         devicep->clock[i] = conf_device->dev_clock[i];
2204     }
2205     devicep->claimed = FALSE;
2206
2207     return TRUE;
2208 }
2209
2210 #ifdef XF86DRI
2211 static void
2212 configDRI(XF86ConfDRIPtr drip)
2213 {
2214     struct group *grp;
2215
2216     xf86ConfigDRI.group = -1;
2217     xf86ConfigDRI.mode = 0;
2218
2219     if (drip) {
2220         if (drip->dri_group_name) {
2221             if ((grp = getgrnam(drip->dri_group_name)))
2222                 xf86ConfigDRI.group = grp->gr_gid;
2223         }
2224         else {
2225             if (drip->dri_group >= 0)
2226                 xf86ConfigDRI.group = drip->dri_group;
2227         }
2228         xf86ConfigDRI.mode = drip->dri_mode;
2229     }
2230 }
2231 #endif
2232
2233 static void
2234 configExtensions(XF86ConfExtensionsPtr conf_ext)
2235 {
2236     XF86OptionPtr o;
2237
2238     if (conf_ext && conf_ext->ext_option_lst) {
2239         for (o = conf_ext->ext_option_lst; o; o = xf86NextOption(o)) {
2240             char *name = xf86OptionName(o);
2241             char *val = xf86OptionValue(o);
2242             char *n;
2243             Bool enable = TRUE;
2244
2245             /* Handle "No<ExtensionName>" */
2246             n = xf86NormalizeName(name);
2247             if (strncmp(n, "no", 2) == 0) {
2248                 name += 2;
2249                 enable = FALSE;
2250             }
2251
2252             if (!val ||
2253                 xf86NameCmp(val, "enable") == 0 ||
2254                 xf86NameCmp(val, "enabled") == 0 ||
2255                 xf86NameCmp(val, "on") == 0 ||
2256                 xf86NameCmp(val, "1") == 0 ||
2257                 xf86NameCmp(val, "yes") == 0 || xf86NameCmp(val, "true") == 0) {
2258                 /* NOTHING NEEDED -- enabling is handled below */
2259             }
2260             else if (xf86NameCmp(val, "disable") == 0 ||
2261                      xf86NameCmp(val, "disabled") == 0 ||
2262                      xf86NameCmp(val, "off") == 0 ||
2263                      xf86NameCmp(val, "0") == 0 ||
2264                      xf86NameCmp(val, "no") == 0 ||
2265                      xf86NameCmp(val, "false") == 0) {
2266                 enable = !enable;
2267             }
2268             else {
2269                 xf86Msg(X_WARNING, "Ignoring unrecognized value \"%s\"\n", val);
2270                 free(n);
2271                 continue;
2272             }
2273
2274             if (EnableDisableExtension(name, enable)) {
2275                 xf86Msg(X_CONFIG, "Extension \"%s\" is %s\n",
2276                         name, enable ? "enabled" : "disabled");
2277             }
2278             else {
2279                 xf86Msg(X_WARNING, "Ignoring unrecognized extension \"%s\"\n",
2280                         name);
2281             }
2282             free(n);
2283         }
2284     }
2285 }
2286
2287 static Bool
2288 configInput(InputInfoPtr inputp, XF86ConfInputPtr conf_input, MessageType from)
2289 {
2290     xf86Msg(from, "|-->Input Device \"%s\"\n", conf_input->inp_identifier);
2291     inputp->name = conf_input->inp_identifier;
2292     inputp->driver = conf_input->inp_driver;
2293     inputp->options = conf_input->inp_option_lst;
2294     inputp->attrs = NULL;
2295
2296     return TRUE;
2297 }
2298
2299 static Bool
2300 modeIsPresent(DisplayModePtr mode, MonPtr monitorp)
2301 {
2302     DisplayModePtr knownmodes = monitorp->Modes;
2303
2304     /* all I can think of is a linear search... */
2305     while (knownmodes != NULL) {
2306         if (!strcmp(mode->name, knownmodes->name) &&
2307             !(knownmodes->type & M_T_DEFAULT))
2308             return TRUE;
2309         knownmodes = knownmodes->next;
2310     }
2311     return FALSE;
2312 }
2313
2314 static Bool
2315 addDefaultModes(MonPtr monitorp)
2316 {
2317     DisplayModePtr mode;
2318     DisplayModePtr last = monitorp->Last;
2319     int i = 0;
2320
2321     for (i = 0; i < xf86NumDefaultModes; i++) {
2322         mode = xf86DuplicateMode(&xf86DefaultModes[i]);
2323         if (!modeIsPresent(mode, monitorp)) {
2324             monitorp->Modes = xf86ModesAdd(monitorp->Modes, mode);
2325             last = mode;
2326         }
2327         else {
2328             free(mode);
2329         }
2330     }
2331     monitorp->Last = last;
2332
2333     return TRUE;
2334 }
2335
2336 static void
2337 checkInput(serverLayoutPtr layout, Bool implicit_layout)
2338 {
2339     checkCoreInputDevices(layout, implicit_layout);
2340
2341     /* Unless we're forcing input devices, disable mouse/kbd devices in the
2342      * config. Otherwise the same physical device is added multiple times,
2343      * leading to duplicate events.
2344      */
2345     if (!xf86Info.forceInputDevices && layout->inputs) {
2346         InputInfoPtr *dev = layout->inputs;
2347         BOOL warned = FALSE;
2348
2349         while (*dev) {
2350             if (strcmp((*dev)->driver, "kbd") == 0 ||
2351                 strcmp((*dev)->driver, "mouse") == 0 ||
2352                 strcmp((*dev)->driver, "vmmouse") == 0) {
2353                 InputInfoPtr *current;
2354
2355                 if (!warned) {
2356                     xf86Msg(X_WARNING, "Hotplugging is on, devices using "
2357                             "drivers 'kbd', 'mouse' or 'vmmouse' will be disabled.\n");
2358                     warned = TRUE;
2359                 }
2360
2361                 xf86Msg(X_WARNING, "Disabling %s\n", (*dev)->name);
2362
2363                 current = dev;
2364                 free(*dev);
2365                 *dev = NULL;
2366
2367                 do {
2368                     *current = *(current + 1);
2369                     current++;
2370                 } while (*current);
2371             }
2372             else
2373                 dev++;
2374         }
2375     }
2376 }
2377
2378 /*
2379  * load the config file and fill the global data structure
2380  */
2381 ConfigStatus
2382 xf86HandleConfigFile(Bool autoconfig)
2383 {
2384     const char *scanptr;
2385     Bool singlecard = 0;
2386     Bool implicit_layout = FALSE;
2387     XF86ConfLayoutPtr layout;
2388
2389     if (!autoconfig) {
2390         char *filename, *dirname, *sysdirname;
2391         const char *filesearch, *dirsearch;
2392         MessageType filefrom = X_DEFAULT;
2393         MessageType dirfrom = X_DEFAULT;
2394
2395         if (!xf86PrivsElevated()) {
2396             filesearch = ALL_CONFIGPATH;
2397             dirsearch = ALL_CONFIGDIRPATH;
2398         }
2399         else {
2400             filesearch = RESTRICTED_CONFIGPATH;
2401             dirsearch = RESTRICTED_CONFIGDIRPATH;
2402         }
2403
2404         if (xf86ConfigFile)
2405             filefrom = X_CMDLINE;
2406         if (xf86ConfigDir)
2407             dirfrom = X_CMDLINE;
2408
2409         xf86initConfigFiles();
2410         sysdirname = xf86openConfigDirFiles(SYS_CONFIGDIRPATH, NULL,
2411                                             PROJECTROOT);
2412         dirname = xf86openConfigDirFiles(dirsearch, xf86ConfigDir, PROJECTROOT);
2413         filename = xf86openConfigFile(filesearch, xf86ConfigFile, PROJECTROOT);
2414         if (filename) {
2415             xf86MsgVerb(filefrom, 0, "Using config file: \"%s\"\n", filename);
2416             xf86ConfigFile = xnfstrdup(filename);
2417         }
2418         else {
2419             if (xf86ConfigFile)
2420                 xf86Msg(X_ERROR, "Unable to locate/open config file: \"%s\"\n",
2421                         xf86ConfigFile);
2422         }
2423         if (dirname) {
2424             xf86MsgVerb(dirfrom, 0, "Using config directory: \"%s\"\n",
2425                         dirname);
2426             xf86ConfigDir = xnfstrdup(dirname);
2427         }
2428         else {
2429             if (xf86ConfigDir)
2430                 xf86Msg(X_ERROR,
2431                         "Unable to locate/open config directory: \"%s\"\n",
2432                         xf86ConfigDir);
2433         }
2434         if (sysdirname)
2435             xf86MsgVerb(X_DEFAULT, 0, "Using system config directory \"%s\"\n",
2436                         sysdirname);
2437         if (!filename && !dirname && !sysdirname)
2438             return CONFIG_NOFILE;
2439
2440         free(filename);
2441         free(dirname);
2442         free(sysdirname);
2443     }
2444
2445     if ((xf86configptr = xf86readConfigFile()) == NULL) {
2446         xf86Msg(X_ERROR, "Problem parsing the config file\n");
2447         return CONFIG_PARSE_ERROR;
2448     }
2449     xf86closeConfigFile();
2450
2451     /* Initialise a few things. */
2452
2453     /*
2454      * now we convert part of the information contained in the parser
2455      * structures into our own structures.
2456      * The important part here is to figure out which Screen Sections
2457      * in the XF86Config file are active so that we can piece together
2458      * the modes that we need later down the road.
2459      * And while we are at it, we'll decode the rest of the stuff as well
2460      */
2461
2462     /* First check if a layout section is present, and if it is valid. */
2463     FIND_SUITABLE(XF86ConfLayoutPtr, xf86configptr->conf_layout_lst, layout);
2464     if (layout == NULL || xf86ScreenName != NULL) {
2465         XF86ConfScreenPtr screen;
2466
2467         if (xf86ScreenName == NULL) {
2468             xf86Msg(X_DEFAULT,
2469                     "No Layout section.  Using the first Screen section.\n");
2470         }
2471         FIND_SUITABLE (XF86ConfScreenPtr, xf86configptr->conf_screen_lst, screen);
2472         if (!configImpliedLayout(&xf86ConfigLayout,
2473                                  screen,
2474                                  xf86configptr)) {
2475             xf86Msg(X_ERROR, "Unable to determine the screen layout\n");
2476             return CONFIG_PARSE_ERROR;
2477         }
2478         implicit_layout = TRUE;
2479     }
2480     else {
2481         if (xf86configptr->conf_flags != NULL) {
2482             char *dfltlayout = NULL;
2483             void *optlist = xf86configptr->conf_flags->flg_option_lst;
2484
2485             if (optlist && xf86FindOption(optlist, "defaultserverlayout"))
2486                 dfltlayout =
2487                     xf86SetStrOption(optlist, "defaultserverlayout", NULL);
2488             if (!configLayout(&xf86ConfigLayout, layout, dfltlayout)) {
2489                 xf86Msg(X_ERROR, "Unable to determine the screen layout\n");
2490                 return CONFIG_PARSE_ERROR;
2491             }
2492         }
2493         else {
2494             if (!configLayout(&xf86ConfigLayout, layout, NULL)) {
2495                 xf86Msg(X_ERROR, "Unable to determine the screen layout\n");
2496                 return CONFIG_PARSE_ERROR;
2497             }
2498         }
2499     }
2500
2501     xf86ProcessOptions(-1, xf86ConfigLayout.options, LayoutOptions);
2502 #ifdef XSERVER_LIBPCIACCESS
2503     if ((scanptr = xf86GetOptValString(LayoutOptions, LAYOUT_ISOLATEDEVICE))) {
2504         ;                       /* IsolateDevice specified; overrides SingleCard */
2505     }
2506     else {
2507         xf86GetOptValBool(LayoutOptions, LAYOUT_SINGLECARD, &singlecard);
2508         if (singlecard)
2509             scanptr = xf86ConfigLayout.screens->screen->device->busID;
2510     }
2511     if (scanptr) {
2512         if (strncmp(scanptr, "PCI:", 4) != 0) {
2513             xf86Msg(X_WARNING, "Bus types other than PCI not yet isolable.\n"
2514                     "\tIgnoring IsolateDevice option.\n");
2515         }
2516         else
2517             xf86PciIsolateDevice(scanptr);
2518     }
2519 #endif
2520     /* Now process everything else */
2521     if (!configServerFlags(xf86configptr->conf_flags, xf86ConfigLayout.options)) {
2522         ErrorF("Problem when converting the config data structures\n");
2523         return CONFIG_PARSE_ERROR;
2524     }
2525
2526     configFiles(xf86configptr->conf_files);
2527     configExtensions(xf86configptr->conf_extensions);
2528 #ifdef XF86DRI
2529     configDRI(xf86configptr->conf_dri);
2530 #endif
2531
2532     checkInput(&xf86ConfigLayout, implicit_layout);
2533
2534     /*
2535      * Handle some command line options that can override some of the
2536      * ServerFlags settings.
2537      */
2538 #ifdef XF86VIDMODE
2539     if (xf86VidModeDisabled)
2540         xf86Info.vidModeEnabled = FALSE;
2541     if (xf86VidModeAllowNonLocal)
2542         xf86Info.vidModeAllowNonLocal = TRUE;
2543 #endif
2544
2545     if (xf86AllowMouseOpenFail)
2546         xf86Info.allowMouseOpenFail = TRUE;
2547
2548     return CONFIG_OK;
2549 }
2550
2551 Bool
2552 xf86PathIsSafe(const char *path)
2553 {
2554     return (xf86pathIsSafe(path) != 0);
2555 }