xf86Config.c 76 KB
Newer Older
1
/*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
2
 * Loosely based on code bearing the following copyright:
3
 *
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
4
 *   Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
5
6
7
8
9
10
11
12
13
14
15
16
 */

/*
 * Copyright 1992-2003 by The XFree86 Project, Inc.
 * Copyright 1997 by Metro Link, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
17
 *
18
19
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
20
 *
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of the copyright holder(s)
 * and author(s) shall not be used in advertising or otherwise to promote
 * the sale, use or other dealings in this Software without prior written
 * authorization from the copyright holder(s) and author(s).
 */

/*
 *
 * Authors:
 *	Dirk Hohndel <hohndel@XFree86.Org>
 *	David Dawes <dawes@XFree86.Org>
 *      Marc La France <tsi@XFree86.Org>
 *      Egbert Eich <eich@XFree86.Org>
 *      ... and others
43
44
 */

45
46
47
48
#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
49
50
51
#ifdef XF86DRI
#include <sys/types.h>
#include <grp.h>
52
53
#endif

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
54
55
56
57
58
#include "xf86.h"
#include "xf86Parser.h"
#include "xf86tokens.h"
#include "xf86Config.h"
#include "xf86Priv.h"
59
#include "xf86_OSlib.h"
60
#include "configProcs.h"
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
61
#include "globals.h"
62
#include "extension.h"
63
#include "Pci.h"
64
65
66

#ifdef XINPUT
#include "xf86Xinput.h"
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
67
extern DeviceAssocRec mouse_assoc;
68
69
#endif

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
70
#ifdef XKB
71
#undef XKB_IN_SERVER
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
72
#define XKB_IN_SERVER
73
#include <xkbsrv.h>
74
75
#endif

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
76
77
#ifdef RENDER
#include "picture.h"
78
79
#endif

80
#if (defined(__i386__)) && \
81
82
    (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
     defined(__NetBSD__) || defined(linux) || \
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
83
84
     (defined(SVR4) && !defined(sun)) || defined(__GNU__))
#define SUPPORT_PC98
85
86
#endif

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * These paths define the way the config file search is done.  The escape
 * sequences are documented in parser/scan.c.
 */
#ifndef ROOT_CONFIGPATH
#define ROOT_CONFIGPATH	"%A," "%R," \
			"/etc/X11/%R," "%P/etc/X11/%R," \
			"%E," "%F," \
			"/etc/X11/%F," "%P/etc/X11/%F," \
			"%D/%X," \
			"/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
			"%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
			"%P/etc/X11/%X," \
			"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
			"%P/lib/X11/%X"
#endif
#ifndef USER_CONFIGPATH
#define USER_CONFIGPATH	"/etc/X11/%S," "%P/etc/X11/%S," \
			"/etc/X11/%G," "%P/etc/X11/%G," \
			"/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
			"%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
			"%P/etc/X11/%X," \
			"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
			"%P/lib/X11/%X"
#endif
#ifndef PROJECTROOT
#define PROJECTROOT	"/usr/X11R6"
#endif

static char *fontPath = NULL;

118
119
120
121
122
123
124
125
126
127
128
static ModuleDefault ModuleDefaults[] = {
    {.name = "extmod",   .toLoad = TRUE,    .load_opt=NULL},
    {.name = "dbe",      .toLoad = TRUE,    .load_opt=NULL},
    {.name = "glx",      .toLoad = TRUE,    .load_opt=NULL},
    {.name = "freetype", .toLoad = TRUE,    .load_opt=NULL},
    {.name = "record",   .toLoad = TRUE,    .load_opt=NULL},
    {.name = "dri",      .toLoad = TRUE,    .load_opt=NULL},
    {.name = NULL,       .toLoad = FALSE,   .load_opt=NULL}
};


Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
129
130
131
132
133
134
135
136
137
138
139
/* Forward declarations */
static Bool configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen,
			 int scrnum, MessageType from);
static Bool configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor);
static Bool configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device,
			 Bool active);
static Bool configInput(IDevPtr inputp, XF86ConfInputPtr conf_input,
			MessageType from);
static Bool configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display);
static Bool addDefaultModes(MonPtr monitorp);
#ifdef XF86DRI
140
static void configDRI(XF86ConfDRIPtr drip);
141
#endif
142
static void configExtensions(XF86ConfExtensionsPtr conf_ext);
143
144
145
146
147
148
149
150

/*
 * xf86GetPathElem --
 *	Extract a single element from the font path string starting at
 *	pnt.  The font path element will be returned, and pnt will be
 *	updated to point to the start of the next element, or set to
 *	NULL if there are no more.
 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
151
152
static char *
xf86GetPathElem(char **pnt)
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{
  char *p1;

  p1 = *pnt;
  *pnt = index(*pnt, ',');
  if (*pnt != NULL) {
    **pnt = '\0';
    *pnt += 1;
  }
  return(p1);
}

/*
 * xf86ValidateFontPath --
 *	Validates the user-specified font path.  Each element that
 *	begins with a '/' is checked to make sure the directory exists.
 *	If the directory exists, the existence of a file named 'fonts.dir'
 *	is checked.  If either check fails, an error is printed and the
 *	element is removed from the font path.
 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
173
174

#define DIR_FILE "/fonts.dir"
175
static char *
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
176
xf86ValidateFontPath(char *path)
177
178
179
180
181
182
{
  char *tmp_path, *out_pnt, *path_elem, *next, *p1, *dir_elem;
  struct stat stat_buf;
  int flag;
  int dirlen;

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
183
  tmp_path = xcalloc(1,strlen(path)+1);
184
185
186
187
188
189
  out_pnt = tmp_path;
  path_elem = NULL;
  next = path;
  while (next != NULL) {
    path_elem = xf86GetPathElem(&next);
    if (*path_elem == '/') {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
190
      dir_elem = xnfcalloc(1, strlen(path_elem) + 1);
191
192
193
194
195
196
197
198
      if ((p1 = strchr(path_elem, ':')) != 0)
	dirlen = p1 - path_elem;
      else
	dirlen = strlen(path_elem);
      strncpy(dir_elem, path_elem, dirlen);
      dir_elem[dirlen] = '\0';
      flag = stat(dir_elem, &stat_buf);
      if (flag == 0)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
199
	if (!S_ISDIR(stat_buf.st_mode))
200
201
	  flag = -1;
      if (flag != 0) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
202
203
204
        xf86Msg(X_WARNING, "The directory \"%s\" does not exist.\n", dir_elem);
	xf86ErrorF("\tEntry deleted from font path.\n");
	xfree(dir_elem);
205
206
207
	continue;
      }
      else {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
208
	p1 = xnfalloc(strlen(dir_elem)+strlen(DIR_FILE)+1);
209
210
211
212
	strcpy(p1, dir_elem);
	strcat(p1, DIR_FILE);
	flag = stat(p1, &stat_buf);
	if (flag == 0)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
213
	  if (!S_ISREG(stat_buf.st_mode))
214
215
216
	    flag = -1;
	xfree(p1);
	if (flag != 0) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
217
218
219
220
221
222
	  xf86Msg(X_WARNING,
		  "`fonts.dir' not found (or not valid) in \"%s\".\n", 
		  dir_elem);
	  xf86ErrorF("\tEntry deleted from font path.\n");
	  xf86ErrorF("\t(Run 'mkfontdir' on \"%s\").\n", dir_elem);
	  xfree(dir_elem);
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
	  continue;
	}
      }
      xfree(dir_elem);
    }

    /*
     * Either an OK directory, or a font server name.  So add it to
     * the path.
     */
    if (out_pnt != tmp_path)
      *out_pnt++ = ',';
    strcat(out_pnt, path_elem);
    out_pnt += strlen(path_elem);
  }
  return(tmp_path);
}

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
241

242
/*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
243
244
 * use the datastructure that the parser provides and pick out the parts
 * that we need at this point
245
 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
246
247
char **
xf86ModulelistFromConfig(pointer **optlist)
248
{
249
    int count = 0, i = 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
250
    char **modulearray;
251
    char *ignore[] = { "GLcore", "speedo", "bitmap", "drm", NULL };
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
252
253
    pointer *optarray;
    XF86LoadPtr modp;
254
    Bool found;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
255
256
257
258
259
260
261
262
263
264
265
266
    
    /*
     * make sure the config file has been parsed and that we have a
     * ModulePath set; if no ModulePath was given, use the default
     * ModulePath
     */
    if (xf86configptr == NULL) {
        xf86Msg(X_ERROR, "Cannot access global config data structure\n");
        return NULL;
    }
    
    if (xf86configptr->conf_modules) {
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
        /* Walk the disable list and let people know what we've parsed to
         * not be loaded 
         */
        modp = xf86configptr->conf_modules->mod_disable_lst;
        while (modp) {
            xf86Msg(X_WARNING, "\"%s\" will not be loaded unless you've specified it to be loaded elsewhere.\n", modp->load_name);
	        modp = (XF86LoadPtr) modp->list.next;
        }
        /*
         * Walk the default settings table. For each module listed to be
         * loaded, make sure it's in the mod_load_lst. If it's not, make
         * sure it's not in the mod_no_load_lst. If it's not disabled,
         * append it to mod_load_lst
         */
         for (i=0 ; ModuleDefaults[i].name != NULL ; i++) {
            if (ModuleDefaults[i].toLoad == FALSE) {
                xf86Msg(X_WARNING, "\"%s\" is not to be loaded by default. Skipping.\n", ModuleDefaults[i].name);
                continue;
285
            }
286
287
288
289
            found = FALSE;
            modp = xf86configptr->conf_modules->mod_load_lst;
            while (modp) {
                if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) {
290
                    xf86Msg(X_INFO, "\"%s\" will be loaded. This was enabled by default and also specified in the config file.\n", ModuleDefaults[i].name);
291
292
293
294
295
296
297
298
299
                    found = TRUE;
                    break;
                }
	        modp = (XF86LoadPtr) modp->list.next;
            }
            if (found == FALSE) {
                modp = xf86configptr->conf_modules->mod_disable_lst;
                while (modp) {
                    if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) {
300
                        xf86Msg(X_INFO, "\"%s\" will be loaded even though the default is to disable it.\n", ModuleDefaults[i].name);
301
302
303
304
305
306
307
308
309
                        found = TRUE;
                        break;
                    }
	                modp = (XF86LoadPtr) modp->list.next;
                }
            }
            if (found == FALSE) {
	            XF86ConfModulePtr ptr = xf86configptr->conf_modules;
	            ptr = xf86addNewLoadDirective(ptr, ModuleDefaults[i].name, XF86_LOAD_MODULE, ModuleDefaults[i].load_opt);
310
                xf86Msg(X_INFO, "\"%s\" will be loaded by default.\n", ModuleDefaults[i].name);
311
312
            }
         }
313
314
    } else {
	xf86configptr->conf_modules = xnfcalloc(1, sizeof(XF86ConfModuleRec));
315
316
317
318
319
320
	for (i=0 ; ModuleDefaults[i].name != NULL ; i++) {
	    if (ModuleDefaults[i].toLoad == TRUE) {
		XF86ConfModulePtr ptr = xf86configptr->conf_modules;
		ptr = xf86addNewLoadDirective(ptr, ModuleDefaults[i].name, XF86_LOAD_MODULE, ModuleDefaults[i].load_opt);
	    }
	}
321
322
    }

323
324
325
326
327
328
329
330
331
332
333
334
335
336
	    /*
	     * Walk the list of modules in the "Module" section to determine how
	     * many we have.
	    */
	    modp = xf86configptr->conf_modules->mod_load_lst;
	    while (modp) {
                for (i = 0; ignore[i]; i++) {
                    if (strcmp(modp->load_name, ignore[i]) == 0)
                        modp->ignore = 1;
                }
                if (!modp->ignore)
	            count++;
	        modp = (XF86LoadPtr) modp->list.next;
	    }
337

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
338
339
340
341
342
343
344
    /*
     * allocate the memory and walk the list again to fill in the pointers
     */
    modulearray = xnfalloc((count + 1) * sizeof(char*));
    optarray = xnfalloc((count + 1) * sizeof(pointer));
    count = 0;
    if (xf86configptr->conf_modules) {
345
346
	    modp = xf86configptr->conf_modules->mod_load_lst;
	    while (modp) {
347
            if (!modp->ignore) {
348
349
350
	            modulearray[count] = modp->load_name;
	            optarray[count] = modp->load_opt;
	            count++;
351
            }
352
353
	        modp = (XF86LoadPtr) modp->list.next;
	    }
354
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
355
356
357
    modulearray[count] = NULL;
    optarray[count] = NULL;
    if (optlist)
358
	    *optlist = optarray;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
359
    else
360
	    xfree(optarray);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
361
362
363
364
365
366
367
368
369
370
371
    return modulearray;
}


char **
xf86DriverlistFromConfig()
{
    int count = 0;
    int j;
    char **modulearray;
    screenLayoutPtr slp;
372
    
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
373
374
375
376
377
378
379
380
    /*
     * make sure the config file has been parsed and that we have a
     * ModulePath set; if no ModulePath was given, use the default
     * ModulePath
     */
    if (xf86configptr == NULL) {
        xf86Msg(X_ERROR, "Cannot access global config data structure\n");
        return NULL;
381
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
382
383
384
385
386
387
388
389
390
391
392
    
    /*
     * Walk the list of driver lines in active "Device" sections to
     * determine now many implicitly loaded modules there are.
     *
     */
    if (xf86ConfigLayout.screens) {
        slp = xf86ConfigLayout.screens;
        while ((slp++)->screen) {
	    count++;
        }
393
394
    }

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
395
396
397
398
399
400
    /*
     * Handle the set of inactive "Device" sections.
     */
    j = 0;
    while (xf86ConfigLayout.inactives[j++].identifier)
	count++;
401

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
402
403
    if (count == 0)
	return NULL;
404

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
405
406
407
408
409
410
411
412
413
414
415
    /*
     * allocate the memory and walk the list again to fill in the pointers
     */
    modulearray = xnfalloc((count + 1) * sizeof(char*));
    count = 0;
    slp = xf86ConfigLayout.screens;
    while (slp->screen) {
	modulearray[count] = slp->screen->device->driver;
	count++;
	slp++;
    }
416

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
417
    j = 0;
418

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
419
420
    while (xf86ConfigLayout.inactives[j].identifier) 
	modulearray[count++] = xf86ConfigLayout.inactives[j++].driver;
421

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
422
    modulearray[count] = NULL;
423

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
424
425
426
    /* Remove duplicates */
    for (count = 0; modulearray[count] != NULL; count++) {
	int i;
427

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
428
429
430
431
432
433
434
	for (i = 0; i < count; i++)
	    if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) {
		modulearray[count] = "";
		break;
	    }
    }
    return modulearray;
435
436
}

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
437
438
439
440
441
char **
xf86InputDriverlistFromConfig()
{
    int count = 0;
    char **modulearray;
442
    IDevPtr* idp;
443
444
    
    /*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
445
446
447
     * make sure the config file has been parsed and that we have a
     * ModulePath set; if no ModulePath was given, use the default
     * ModulePath
448
     */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
449
450
451
    if (xf86configptr == NULL) {
        xf86Msg(X_ERROR, "Cannot access global config data structure\n");
        return NULL;
452
453
454
    }
    
    /*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
455
456
     * Walk the list of driver lines in active "InputDevice" sections to
     * determine now many implicitly loaded modules there are.
457
     */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
458
459
    if (xf86ConfigLayout.inputs) {
        idp = xf86ConfigLayout.inputs;
460
        while (*idp) {
461
	    count++;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
462
463
464
	    idp++;
        }
    }
465

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
466
467
    if (count == 0)
	return NULL;
468
469

    /*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
470
     * allocate the memory and walk the list again to fill in the pointers
471
     */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
472
473
474
    modulearray = xnfalloc((count + 1) * sizeof(char*));
    count = 0;
    idp = xf86ConfigLayout.inputs;
475
476
    while (idp && *idp) {
        modulearray[count] = (*idp)->driver;
477
	count++;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
478
479
480
	idp++;
    }
    modulearray[count] = NULL;
481

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
482
483
484
485
486
487
488
489
490
491
492
    /* Remove duplicates */
    for (count = 0; modulearray[count] != NULL; count++) {
	int i;

	for (i = 0; i < count; i++)
	    if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) {
		modulearray[count] = "";
		break;
	    }
    }
    return modulearray;
493
494
}

495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
static void
fixup_video_driver_list(char **drivers)
{
    static const char *fallback[5] = { "vga", "vesa", "fbdev", "wsfb", NULL };
    char **end, **drv;
    char *x;
    char **ati, **atimisc;
    int i;

    /* walk to the end of the list */
    for (end = drivers; *end && **end; end++) ;
    end--;

    /*
     * for each of the fallback drivers, if we find it in the list,
     * swap it with the last available non-fallback driver.
     */
    for (i = 0; fallback[i]; i++) {
        for (drv = drivers; drv != end; drv++) {
            if (strstr(*drv, fallback[i])) {
                x = *drv; *drv = *end; *end = x;
                end--;
                break;
            }
        }
    }
    /*
     * since the ati wrapper driver is gross and awful, sort ati before
     * atimisc, which makes sure all the ati symbols are visible in xorgcfg.
     */
    for (drv = drivers; drv != end; drv++) {
        if (!strcmp(*drv, "atimisc")) {
            atimisc = drv;
528
            for (drv = atimisc; drv != end; drv++) {
529
530
531
532
533
534
                if (!strcmp(*drv, "ati")) {
                    ati = drv;
                    x = *ati; *ati = *atimisc; *atimisc = x;
                    return;
                }
            }
535
            /* if we get here, ati was already ahead of atimisc */
536
            return;
537
538
539
540
        }
    }
}

541
542

/*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
543
544
545
 * Generate a compiled-in list of driver names.  This is used to produce a
 * consistent probe order.  For the loader server, we also look for vendor-
 * provided modules, pre-pending them to our own list.
546
 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
547
548
static char **
GenerateDriverlist(char * dirname, char * drivernames)
549
{
550
    char **ret;
551
    const char *subdirs[] = { dirname, NULL };
552
    static const char *patlist[] = {"(.*)_drv\\.so", "(.*)_drv\\.o", NULL};
553
554
555
    ret = LoaderListDirs(subdirs, patlist);
    
    /* fix up the probe order for video drivers */
556
    if (strstr(dirname, "drivers") && ret != NULL)
557
        fixup_video_driver_list(ret);
558
559

    return ret;
560
561
}

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
562
563
564

char **
xf86DriverlistFromCompile(void)
565
{
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
566
567
    static char **driverlist = NULL;
    static Bool generated = FALSE;
568

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
569
570
    /* This string is modified in-place */
    static char drivernames[] = DRIVERS;
571

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
572
573
574
    if (!generated) {
        generated = TRUE;
        driverlist = GenerateDriverlist("drivers", drivernames);
575
576
    }

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
    return driverlist;
}

/*
 * xf86ConfigError --
 *      Print a READABLE ErrorMessage!!!  All information that is 
 *      available is printed.
 */
static void
xf86ConfigError(char *msg, ...)
{
    va_list ap;

    ErrorF("\nConfig Error:\n");
    va_start(ap, msg);
    VErrorF(msg, ap);
    va_end(ap);
    ErrorF("\n");
    return;
}

598
static void
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
599
600
601
configFiles(XF86ConfFilesPtr fileconf)
{
  MessageType pathFrom = X_DEFAULT;
602
603
604
  int countDirs;
  char *temp_path;
  char *log_buf;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
605
606

  /* FontPath */
607
  /* Try XF86Config FontPath first */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
608
609
610
611
612
  if (!xf86fpFlag) {
   if (fileconf) {
    if (fileconf->file_fontpath) {
      char *f = xf86ValidateFontPath(fileconf->file_fontpath);
      pathFrom = X_CONFIG;
613
614
      if (*f) {
        if (xf86Info.useDefaultFontPath) {
615
          xf86Msg(X_DEFAULT, "Including the default font path %s.\n", defaultFontPath);
616
617
618
619
620
621
622
623
624
          char *g = xnfalloc(strlen(defaultFontPath) + strlen(f) + 3);
          strcpy(g, f);
          strcat(g, ",");
          defaultFontPath = strcat(g, defaultFontPath);
          xfree(f);
        } else {
          defaultFontPath = f;
        }
      } else {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
625
626
627
628
629
630
631
	xf86Msg(X_WARNING,
	    "FontPath is completely invalid.  Using compiled-in default.\n");
        fontPath = NULL;
        pathFrom = X_DEFAULT;
      }
    } 
   } else {
632
      xf86Msg(X_DEFAULT,
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
633
634
635
636
637
	    "No FontPath specified.  Using compiled-in default.\n");
      pathFrom = X_DEFAULT;
   }
  } else {
    /* Use fontpath specified with '-fp' */
638
639
    if (fontPath)
    {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
640
      fontPath = NULL;
641
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
642
    pathFrom = X_CMDLINE;
643
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
644
645
  if (!fileconf) {
      /* xf86ValidateFontPath will write into it's arg, but defaultFontPath
646
       could be static, so we make a copy. */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
647
    char *f = xnfalloc(strlen(defaultFontPath) + 1);
648
649
650
651
    f[0] = '\0';
    strcpy (f, defaultFontPath);
    defaultFontPath = xf86ValidateFontPath(f);
    xfree(f);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
652
653
654
655
656
657
658
659
660
661
662
663
  } else {
   if (fileconf) {
    if (!fileconf->file_fontpath) {
      /* xf86ValidateFontPath will write into it's arg, but defaultFontPath
       could be static, so we make a copy. */
     char *f = xnfalloc(strlen(defaultFontPath) + 1);
     f[0] = '\0';
     strcpy (f, defaultFontPath);
     defaultFontPath = xf86ValidateFontPath(f);
     xfree(f);
    }
   }
664
665
666
667
668
  }

  /* If defaultFontPath is still empty, exit here */

  if (! *defaultFontPath)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
669
    FatalError("No valid FontPath could be found.");
670

671
  /* make fontpath more readable in the logfiles */
672
673
  countDirs = 1;
  temp_path = defaultFontPath;
674
675
676
677
  while((temp_path = index(temp_path, ',')) != NULL) {
    countDirs++;
    temp_path++;
  }
678
  log_buf = xnfalloc(strlen(defaultFontPath) + (2 * countDirs) + 1);
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
  if(!log_buf) /* fallback to old method */
    xf86Msg(pathFrom, "FontPath set to \"%s\"\n", defaultFontPath);
  else {
    char *start, *end;
    int size;
    temp_path = log_buf;
    start = defaultFontPath;
    while((end = index(start, ',')) != NULL) {
      size = (end - start) + 1;
      *(temp_path++) = '\t';
      strncpy(temp_path, start, size);
      temp_path += size;
      *(temp_path++) = '\n';
      start += size;
    }
    /* copy last entry */
    *(temp_path++) = '\t';
    strcpy(temp_path, start);
    xf86Msg(pathFrom, "FontPath set to:\n%s\n", log_buf);
    xfree(log_buf);
  }

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
701
702
703
704
705
706
707
708
709
710
711
712
713
714

  if (fileconf && fileconf->file_inputdevs) {
      xf86InputDeviceList = fileconf->file_inputdevs;
      xf86Msg(X_CONFIG, "Input device list set to \"%s\"\n",
	  xf86InputDeviceList);
  }
  
  
  /* ModulePath */

  if (fileconf) {
    if (xf86ModPathFrom != X_CMDLINE && fileconf->file_modulepath) {
      xf86ModulePath = fileconf->file_modulepath;
      xf86ModPathFrom = X_CONFIG;
715
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
716
717
718
  }

  xf86Msg(xf86ModPathFrom, "ModulePath set to \"%s\"\n", xf86ModulePath);
719

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
720
721
#if 0
  /* LogFile */
722
  /*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
723
724
725
726
727
728
729
   * XXX The problem with this is that the log file is already open.
   * One option might be to copy the exiting contents to the new location.
   * and re-open it.  The down side is that the default location would
   * already have been overwritten.  Another option would be to start with
   * unique temporary location, then copy it once the correct name is known.
   * A problem with this is what happens if the server exits before that
   * happens.
730
   */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
731
732
733
734
735
  if (xf86LogFileFrom == X_DEFAULT && fileconf->file_logfile) {
    xf86LogFile = fileconf->file_logfile;
    xf86LogFileFrom = X_CONFIG;
  }
#endif
736

737
  return;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
}

typedef enum {
    FLAG_NOTRAPSIGNALS,
    FLAG_DONTVTSWITCH,
    FLAG_DONTZAP,
    FLAG_DONTZOOM,
    FLAG_DISABLEVIDMODE,
    FLAG_ALLOWNONLOCAL,
    FLAG_DISABLEMODINDEV,
    FLAG_MODINDEVALLOWNONLOCAL,
    FLAG_ALLOWMOUSEOPENFAIL,
    FLAG_VTINIT,
    FLAG_VTSYSREQ,
    FLAG_XKBDISABLE,
    FLAG_PCIPROBE1,
    FLAG_PCIPROBE2,
    FLAG_PCIFORCECONFIG1,
    FLAG_PCIFORCECONFIG2,
    FLAG_PCIFORCENONE,
    FLAG_PCIOSCONFIG,
    FLAG_SAVER_BLANKTIME,
    FLAG_DPMS_STANDBYTIME,
    FLAG_DPMS_SUSPENDTIME,
    FLAG_DPMS_OFFTIME,
    FLAG_PIXMAP,
    FLAG_PC98,
    FLAG_ESTIMATE_SIZES_AGGRESSIVELY,
    FLAG_NOPM,
    FLAG_XINERAMA,
    FLAG_ALLOW_DEACTIVATE_GRABS,
    FLAG_ALLOW_CLOSEDOWN_GRABS,
    FLAG_LOG,
    FLAG_RENDER_COLORMAP_MODE,
    FLAG_HANDLE_SPECIAL_KEYS,
773
    FLAG_RANDR,
774
    FLAG_AIGLX,
775
776
    FLAG_IGNORE_ABI,
    FLAG_ALLOW_EMPTY_INPUT,
Daniel Stone's avatar
Daniel Stone committed
777
778
779
    FLAG_USE_DEFAULT_FONT_PATH,
    FLAG_AUTO_ADD_DEVICES,
    FLAG_AUTO_ENABLE_DEVICES,
780
    FLAG_GLX_VISUALS,
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
} FlagValues;
   
static OptionInfoRec FlagOptions[] = {
  { FLAG_NOTRAPSIGNALS,		"NoTrapSignals",		OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_DONTVTSWITCH,		"DontVTSwitch",			OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_DONTZAP,		"DontZap",			OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_DONTZOOM,		"DontZoom",			OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_DISABLEVIDMODE,	"DisableVidModeExtension",	OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_ALLOWNONLOCAL,		"AllowNonLocalXvidtune",	OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_DISABLEMODINDEV,	"DisableModInDev",		OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_MODINDEVALLOWNONLOCAL,	"AllowNonLocalModInDev",	OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_ALLOWMOUSEOPENFAIL,	"AllowMouseOpenFail",		OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_VTINIT,		"VTInit",			OPTV_STRING,
	{0}, FALSE },
  { FLAG_VTSYSREQ,		"VTSysReq",			OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_XKBDISABLE,		"XkbDisable",			OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_PCIPROBE1,		"PciProbe1"		,	OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_PCIPROBE2,		"PciProbe2",			OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_PCIFORCECONFIG1,	"PciForceConfig1",		OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_PCIFORCECONFIG2,	"PciForceConfig2",		OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_PCIFORCENONE,		"PciForceNone",			OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_PCIOSCONFIG,	        "PciOsConfig",   		OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_SAVER_BLANKTIME,	"BlankTime"		,	OPTV_INTEGER,
	{0}, FALSE },
  { FLAG_DPMS_STANDBYTIME,	"StandbyTime",			OPTV_INTEGER,
	{0}, FALSE },
  { FLAG_DPMS_SUSPENDTIME,	"SuspendTime",			OPTV_INTEGER,
	{0}, FALSE },
  { FLAG_DPMS_OFFTIME,		"OffTime",			OPTV_INTEGER,
	{0}, FALSE },
  { FLAG_PIXMAP,		"Pixmap",			OPTV_INTEGER,
	{0}, FALSE },
  { FLAG_PC98,			"PC98",				OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_ESTIMATE_SIZES_AGGRESSIVELY,"EstimateSizesAggressively",OPTV_INTEGER,
	{0}, FALSE },
  { FLAG_NOPM,			"NoPM",				OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_XINERAMA,		"Xinerama",			OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_ALLOW_DEACTIVATE_GRABS,"AllowDeactivateGrabs",		OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_ALLOW_CLOSEDOWN_GRABS, "AllowClosedownGrabs",		OPTV_BOOLEAN,
	{0}, FALSE },
  { FLAG_LOG,			"Log",				OPTV_STRING,
	{0}, FALSE },
  { FLAG_RENDER_COLORMAP_MODE,	"RenderColormapMode",		OPTV_STRING,
        {0}, FALSE },
  { FLAG_HANDLE_SPECIAL_KEYS,	"HandleSpecialKeys",		OPTV_STRING,
        {0}, FALSE },
  { FLAG_RANDR,			"RandR",			OPTV_BOOLEAN,
	{0}, FALSE },
850
851
  { FLAG_AIGLX,			"AIGLX",			OPTV_BOOLEAN,
	{0}, FALSE },
852
853
  { FLAG_ALLOW_EMPTY_INPUT,     "AllowEmptyInput",              OPTV_BOOLEAN,
        {0}, FALSE },
854
855
  { FLAG_IGNORE_ABI,			"IgnoreABI",			OPTV_BOOLEAN,
	{0}, FALSE },
856
857
  { FLAG_USE_DEFAULT_FONT_PATH,  "UseDefaultFontPath",			OPTV_BOOLEAN,
	{0}, FALSE },
Daniel Stone's avatar
Daniel Stone committed
858
859
860
861
  { FLAG_AUTO_ADD_DEVICES,       "AutoAddDevices",                      OPTV_BOOLEAN,
        {0}, TRUE },
  { FLAG_AUTO_ENABLE_DEVICES,    "AutoEnableDevices",                   OPTV_BOOLEAN,
        {0}, TRUE },
862
863
  { FLAG_GLX_VISUALS,		"GlxVisuals",			OPTV_STRING,
        {0}, FALSE },
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
864
865
866
867
  { -1,				NULL,				OPTV_NONE,
	{0}, FALSE },
};

868
#ifdef __i386__
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
869
870
871
872
873
static Bool
detectPC98(void)
{
#ifdef SUPPORT_PC98
    unsigned char buf[2];
874

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
875
876
877
878
879
880
881
882
    if (xf86ReadBIOS(0xf8000, 0xe80, buf, 2) != 2)
	return FALSE;
    if ((buf[0] == 0x98) && (buf[1] == 0x21))
	return TRUE;
    else
	return FALSE;
#else
    return FALSE;
883
884
#endif
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
885
#endif /* __i386__ */
886

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
887
888
static Bool
configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
889
{
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
890
891
892
893
894
    XF86OptionPtr optp, tmp;
    int i;
    Pix24Flags pix24 = Pix24DontCare;
    Bool value;
    MessageType from;
895
    const char *s;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922

    /*
     * Merge the ServerLayout and ServerFlags options.  The former have
     * precedence over the latter.
     */
    optp = NULL;
    if (flagsconf && flagsconf->flg_option_lst)
	optp = xf86optionListDup(flagsconf->flg_option_lst);
    if (layoutopts) {
	tmp = xf86optionListDup(layoutopts);
	if (optp)
	    optp = xf86optionListMerge(optp, tmp);
	else
	    optp = tmp;
    }

    xf86ProcessOptions(-1, optp, FlagOptions);

    xf86GetOptValBool(FlagOptions, FLAG_NOTRAPSIGNALS, &xf86Info.notrapSignals);
    xf86GetOptValBool(FlagOptions, FLAG_DONTVTSWITCH, &xf86Info.dontVTSwitch);
    xf86GetOptValBool(FlagOptions, FLAG_DONTZAP, &xf86Info.dontZap);
    xf86GetOptValBool(FlagOptions, FLAG_DONTZOOM, &xf86Info.dontZoom);

    xf86GetOptValBool(FlagOptions, FLAG_ALLOW_DEACTIVATE_GRABS,
		      &(xf86Info.grabInfo.allowDeactivate));
    xf86GetOptValBool(FlagOptions, FLAG_ALLOW_CLOSEDOWN_GRABS,
		      &(xf86Info.grabInfo.allowClosedown));
923
    xf86GetOptValBool(FlagOptions, FLAG_IGNORE_ABI, &xf86Info.ignoreABI);
924
    if (xf86Info.ignoreABI) {
925
926
	    xf86Msg(X_CONFIG, "Ignoring ABI Version\n");
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
927

Daniel Stone's avatar
Daniel Stone committed
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
    if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ADD_DEVICES)) {
        xf86GetOptValBool(FlagOptions, FLAG_AUTO_ADD_DEVICES,
                          &xf86Info.autoAddDevices);
        from = X_CONFIG;
    }
    else {
        xf86Info.autoAddDevices = TRUE;
        from = X_DEFAULT;
    }
    xf86Msg(from, "%sutomatically adding devices\n",
            xf86Info.autoAddDevices ? "A" : "Not a");

    if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ENABLE_DEVICES)) {
        xf86GetOptValBool(FlagOptions, FLAG_AUTO_ENABLE_DEVICES,
                          &xf86Info.autoEnableDevices);
        from = X_CONFIG;
    }
    else {
        xf86Info.autoEnableDevices = TRUE;
        from = X_DEFAULT;
    }
    xf86Msg(from, "%sutomatically enabling devices\n",
            xf86Info.autoEnableDevices ? "A" : "Not a");

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
    /*
     * Set things up based on the config file information.  Some of these
     * settings may be overridden later when the command line options are
     * checked.
     */
#ifdef XF86VIDMODE
    if (xf86GetOptValBool(FlagOptions, FLAG_DISABLEVIDMODE, &value))
	xf86Info.vidModeEnabled = !value;
    if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWNONLOCAL, &value))
	xf86Info.vidModeAllowNonLocal = value;
#endif

#ifdef XF86MISC
    if (xf86GetOptValBool(FlagOptions, FLAG_DISABLEMODINDEV, &value))
	xf86Info.miscModInDevEnabled = !value;
    if (xf86GetOptValBool(FlagOptions, FLAG_MODINDEVALLOWNONLOCAL, &value))
	xf86Info.miscModInDevAllowNonLocal = value;
#endif

    if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWMOUSEOPENFAIL, &value))
	xf86Info.allowMouseOpenFail = value;

    if (xf86GetOptValBool(FlagOptions, FLAG_VTSYSREQ, &value)) {
#ifdef USE_VT_SYSREQ
	xf86Info.vtSysreq = value;
	xf86Msg(X_CONFIG, "VTSysReq %s\n", value ? "enabled" : "disabled");
978
#else
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
979
980
	if (value)
	    xf86Msg(X_WARNING, "VTSysReq is not supported on this OS\n");
981
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
    }

    if (xf86GetOptValBool(FlagOptions, FLAG_XKBDISABLE, &value)) {
#ifdef XKB
	noXkbExtension = value;
	xf86Msg(X_CONFIG, "Xkb %s\n", value ? "disabled" : "enabled");
#else
	if (!value)
	    xf86Msg(X_WARNING, "Xserver doesn't support XKB\n");
#endif
    }

    xf86Info.vtinit = xf86GetOptValString(FlagOptions, FLAG_VTINIT);

    if (xf86IsOptionSet(FlagOptions, FLAG_PCIPROBE1))
	xf86Info.pciFlags = PCIProbe1;
    if (xf86IsOptionSet(FlagOptions, FLAG_PCIPROBE2))
	xf86Info.pciFlags = PCIProbe2;
    if (xf86IsOptionSet(FlagOptions, FLAG_PCIFORCECONFIG1))
	xf86Info.pciFlags = PCIForceConfig1;
    if (xf86IsOptionSet(FlagOptions, FLAG_PCIFORCECONFIG2))
	xf86Info.pciFlags = PCIForceConfig2;
    if (xf86IsOptionSet(FlagOptions, FLAG_PCIOSCONFIG))
	xf86Info.pciFlags = PCIOsConfig;
    if (xf86IsOptionSet(FlagOptions, FLAG_PCIFORCENONE))
	xf86Info.pciFlags = PCIForceNone;

    xf86Info.pmFlag = TRUE;
    if (xf86GetOptValBool(FlagOptions, FLAG_NOPM, &value)) 
	xf86Info.pmFlag = !value;
    {
	if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) {
	    if (!xf86NameCmp(s,"flush")) {
		xf86Msg(X_CONFIG, "Flushing logfile enabled\n");
		xf86Info.log = LogFlush;
1017
		LogSetParameter(XLOG_FLUSH, TRUE);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1018
1019
1020
	    } else if (!xf86NameCmp(s,"sync")) {
		xf86Msg(X_CONFIG, "Syncing logfile enabled\n");
		xf86Info.log = LogSync;
1021
		LogSetParameter(XLOG_FLUSH, TRUE);
1022
		LogSetParameter(XLOG_SYNC, TRUE);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1023
1024
1025
1026
1027
	    } else {
		xf86Msg(X_WARNING,"Unknown Log option\n");
	    }
        }
    }
1028
    
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1029
1030
1031
1032
1033
1034
1035
#ifdef RENDER
    {
	if ((s = xf86GetOptValString(FlagOptions, FLAG_RENDER_COLORMAP_MODE))){
	    int policy = PictureParseCmapPolicy (s);
	    if (policy == PictureCmapPolicyInvalid)
		xf86Msg(X_WARNING, "Unknown colormap policy \"%s\"\n", s);
	    else
1036
	    {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1037
1038
		xf86Msg(X_CONFIG, "Render colormap policy set to %s\n", s);
		PictureCmapPolicy = policy;
1039
1040
	    }
	}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
    }
#endif
    {
	if ((s = xf86GetOptValString(FlagOptions, FLAG_HANDLE_SPECIAL_KEYS))) {
	    if (!xf86NameCmp(s,"always")) {
		xf86Msg(X_CONFIG, "Always handling special keys in DDX\n");
		xf86Info.ddxSpecialKeys = SKAlways;
	    } else if (!xf86NameCmp(s,"whenneeded")) {
		xf86Msg(X_CONFIG, "Special keys handled in DDX only if needed\n");
		xf86Info.ddxSpecialKeys = SKWhenNeeded;
	    } else if (!xf86NameCmp(s,"never")) {
		xf86Msg(X_CONFIG, "Never handling special keys in DDX\n");
		xf86Info.ddxSpecialKeys = SKNever;
	    } else {
		xf86Msg(X_WARNING,"Unknown HandleSpecialKeys option\n");
1056
	    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
        }
    }
#ifdef RANDR
    xf86Info.disableRandR = FALSE;
    xf86Info.randRFrom = X_DEFAULT;
    if (xf86GetOptValBool(FlagOptions, FLAG_RANDR, &value)) {
	xf86Info.disableRandR = !value;
	xf86Info.randRFrom = X_CONFIG;
    }
#endif
    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_ESTIMATE_SIZES_AGGRESSIVELY, &i);
    if (i >= 0)
	xf86Info.estimateSizesAggressively = i;
    else
	xf86Info.estimateSizesAggressively = 0;
1073

1074
1075
1076
1077
1078
1079
1080
    xf86Info.aiglx = TRUE;
    xf86Info.aiglxFrom = X_DEFAULT;
    if (xf86GetOptValBool(FlagOptions, FLAG_AIGLX, &value)) {
	xf86Info.aiglx = value;
	xf86Info.aiglxFrom = X_CONFIG;
    }

1081
#ifdef GLXEXT
1082
    xf86Info.glxVisuals = XF86_GlxVisualsTypical;
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
    xf86Info.glxVisualsFrom = X_DEFAULT;
    if ((s = xf86GetOptValString(FlagOptions, FLAG_GLX_VISUALS))) {
	if (!xf86NameCmp(s, "minimal")) {
	    xf86Info.glxVisuals = XF86_GlxVisualsMinimal;
	} else if (!xf86NameCmp(s, "typical")) {
	    xf86Info.glxVisuals = XF86_GlxVisualsTypical;
	} else if (!xf86NameCmp(s, "all")) {
	    xf86Info.glxVisuals = XF86_GlxVisualsAll;
	} else {
	    xf86Msg(X_WARNING,"Unknown HandleSpecialKeys option\n");
	}
    }

    if (xf86GetOptValBool(FlagOptions, FLAG_AIGLX, &value)) {
	xf86Info.aiglx = value;
	xf86Info.aiglxFrom = X_CONFIG;
    }
#endif

1102
1103
1104
1105
    xf86Info.allowEmptyInput = FALSE;
    if (xf86GetOptValBool(FlagOptions, FLAG_ALLOW_EMPTY_INPUT, &value))
        xf86Info.allowEmptyInput = TRUE;

1106
1107
1108
1109
1110
1111
1112
    xf86Info.useDefaultFontPath = TRUE;
    xf86Info.useDefaultFontPathFrom = X_DEFAULT;
    if (xf86GetOptValBool(FlagOptions, FLAG_USE_DEFAULT_FONT_PATH, &value)) {
	xf86Info.useDefaultFontPath = value;
	xf86Info.useDefaultFontPathFrom = X_CONFIG;
    }

1113
1114
1115
/* Make sure that timers don't overflow CARD32's after multiplying */
#define MAX_TIME_IN_MIN (0x7fffffff / MILLI_PER_MIN)

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1116
1117
    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_SAVER_BLANKTIME, &i);
1118
    if ((i >= 0) && (i < MAX_TIME_IN_MIN))
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1119
	ScreenSaverTime = defaultScreenSaverTime = i * MILLI_PER_MIN;
1120
1121
1122
    else if (i != -1)
	xf86ConfigError("BlankTime value %d outside legal range of 0 - %d minutes",
			i, MAX_TIME_IN_MIN);
1123

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1124
1125
1126
#ifdef DPMSExtension
    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_DPMS_STANDBYTIME, &i);
1127
    if ((i >= 0) && (i < MAX_TIME_IN_MIN))
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1128
	DPMSStandbyTime = defaultDPMSStandbyTime = i * MILLI_PER_MIN;
1129
1130
1131
    else if (i != -1)
	xf86ConfigError("StandbyTime value %d outside legal range of 0 - %d minutes",
			i, MAX_TIME_IN_MIN);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1132
1133
    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_DPMS_SUSPENDTIME, &i);
1134
    if ((i >= 0) && (i < MAX_TIME_IN_MIN))
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1135
	DPMSSuspendTime = defaultDPMSSuspendTime = i * MILLI_PER_MIN;
1136
1137
1138
    else if (i != -1)
	xf86ConfigError("SuspendTime value %d outside legal range of 0 - %d minutes",
			i, MAX_TIME_IN_MIN);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1139
1140
    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_DPMS_OFFTIME, &i);
1141
    if ((i >= 0) && (i < MAX_TIME_IN_MIN))
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1142
	DPMSOffTime = defaultDPMSOffTime = i * MILLI_PER_MIN;
1143
1144
1145
    else if (i != -1)
	xf86ConfigError("OffTime value %d outside legal range of 0 - %d minutes",
			i, MAX_TIME_IN_MIN);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
#endif

    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_PIXMAP, &i);
    switch (i) {
    case 24:
	pix24 = Pix24Use24;
	break;
    case 32:
	pix24 = Pix24Use32;
	break;
    case -1:
	break;
1159
    default:
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1160
1161
	xf86ConfigError("Pixmap option's value (%d) must be 24 or 32\n", i);
	return FALSE;
1162
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
    if (xf86Pix24 != Pix24DontCare) {
	xf86Info.pixmap24 = xf86Pix24;
	xf86Info.pix24From = X_CMDLINE;
    } else if (pix24 != Pix24DontCare) {
	xf86Info.pixmap24 = pix24;
	xf86Info.pix24From = X_CONFIG;
    } else {
	xf86Info.pixmap24 = Pix24DontCare;
	xf86Info.pix24From = X_DEFAULT;
    }
1173
#ifdef __i386__
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
    if (xf86GetOptValBool(FlagOptions, FLAG_PC98, &value)) {
	xf86Info.pc98 = value;
	if (value) {
	    xf86Msg(X_CONFIG, "Japanese PC98 architecture\n");
	}
    } else
	if (detectPC98()) {
	    xf86Info.pc98 = TRUE;
	    xf86Msg(X_PROBED, "Japanese PC98 architecture\n");
	}
1184
1185
#endif

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1186
1187
1188
1189
1190
1191
1192
#ifdef PANORAMIX
    from = X_DEFAULT;
    if (!noPanoramiXExtension)
      from = X_CMDLINE;
    else if (xf86GetOptValBool(FlagOptions, FLAG_XINERAMA, &value)) {
      noPanoramiXExtension = !value;
      from = X_CONFIG;
1193
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1194
1195
    if (!noPanoramiXExtension)
      xf86Msg(from, "Xinerama: enabled\n");
1196
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1197
1198

    return TRUE;
1199
1200
}

1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
/*
 * Locate the core input devices.  These can be specified/located in
 * the following ways, in order of priority:
 *
 *  1. The InputDevices named by the -pointer and -keyboard command line
 *     options.
 *  2. The "CorePointer" and "CoreKeyboard" InputDevices referred to by
 *     the active ServerLayout.
 *  3. The first InputDevices marked as "CorePointer" and "CoreKeyboard".
 *  4. The first InputDevices that use the 'mouse' and 'keyboard' or 'kbd'
 *     drivers.
 *  5. Default devices with an empty (default) configuration.  These defaults
 *     will reference the 'mouse' and 'keyboard' drivers.
 */

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1216
1217
1218
static Bool
checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
{
1219
    IDevPtr corePointer = NULL, coreKeyboard = NULL;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1220
    Bool foundPointer = FALSE, foundKeyboard = FALSE;
1221
    const char *pointerMsg = NULL, *keyboardMsg = NULL;
1222
1223
    IDevPtr *devs, /* iterator */
            indp;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1224
1225
    IDevRec Pointer, Keyboard;
    XF86ConfInputPtr confInput;
1226
    XF86ConfInputRec defPtr, defKbd;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1227
1228
    int count = 0;
    MessageType from = X_DEFAULT;
1229
    int found = 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1230

1231
1232
1233
1234
1235
    /*
     * First check if a core pointer or core keyboard have been specified
     * in the active ServerLayout.  If more than one is specified for either,
     * remove the core attribute from the later ones.
     */
1236
1237
    for (devs = servlayoutp->inputs; devs && *devs; devs++) {
        indp = *devs;
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
	pointer opt1 = NULL, opt2 = NULL;
	if (indp->commonOptions &&
	    xf86CheckBoolOption(indp->commonOptions, "CorePointer", FALSE)) {
	    opt1 = indp->commonOptions;
	}
	if (indp->extraOptions &&
	    xf86CheckBoolOption(indp->extraOptions, "CorePointer", FALSE)) {
	    opt2 = indp->extraOptions;
	}
	if (opt1 || opt2) {
	    if (!corePointer) {
		corePointer = indp;
	    } else {
		if (opt1)
		    xf86ReplaceBoolOption(opt1, "CorePointer", FALSE);
		if (opt2)
		    xf86ReplaceBoolOption(opt2, "CorePointer", FALSE);
		xf86Msg(X_WARNING, "Duplicate core pointer devices.  "
			"Removing core pointer attribute from \"%s\"\n",
			indp->identifier);
	    }
	}
	opt1 = opt2 = NULL;
	if (indp->commonOptions &&
	    xf86CheckBoolOption(indp->commonOptions, "CoreKeyboard", FALSE)) {
	    opt1 = indp->commonOptions;
1264
	}
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
	if (indp->extraOptions &&
	    xf86CheckBoolOption(indp->extraOptions, "CoreKeyboard", FALSE)) {
	    opt2 = indp->extraOptions;
	}
	if (opt1 || opt2) {
	    if (!coreKeyboard) {
		coreKeyboard = indp;
	    } else {
		if (opt1)
		    xf86ReplaceBoolOption(opt1, "CoreKeyboard", FALSE);
		if (opt2)
		    xf86ReplaceBoolOption(opt2, "CoreKeyboard", FALSE);
		xf86Msg(X_WARNING, "Duplicate core keyboard devices.  "
			"Removing core keyboard attribute from \"%s\"\n",
			indp->identifier);
	    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1281
1282
1283
	}
	count++;
    }
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301

    confInput = NULL;

    /* 1. Check for the -pointer command line option. */
    if (xf86PointerName) {
	confInput = xf86findInput(xf86PointerName,
				  xf86configptr->conf_input_lst);
	if (!confInput) {
	    xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n",
		    xf86PointerName);
	    return FALSE;
	}
	from = X_CMDLINE;
	/*
	 * If one was already specified in the ServerLayout, it needs to be
	 * removed.
	 */
	if (corePointer) {
1302
1303
1304
1305
1306
	    for (devs = servlayoutp->inputs; devs && *devs; devs++)
		if (*devs == corePointer)
                {
                    xfree(*devs);
                    *devs = (IDevPtr)0x1; /* ensure we dont skip next loop*/
1307
		    break;
1308
1309
1310
                }
	    for (; devs && *devs; devs++)
		devs[0] = devs[1];
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
	    count--;
	}
	corePointer = NULL;
	foundPointer = TRUE;
    }

    /* 2. ServerLayout-specified core pointer. */
    if (corePointer) {
	foundPointer = TRUE;
	from = X_CONFIG;
    }

    /* 3. First core pointer device. */
    if (!foundPointer) {
	XF86ConfInputPtr p;

	for (p = xf86configptr->conf_input_lst; p; p = p->list.next) {
	    if (p->inp_option_lst &&
		xf86CheckBoolOption(p->inp_option_lst, "CorePointer", FALSE)) {
		confInput = p;
		foundPointer = TRUE;
		from = X_DEFAULT;
		pointerMsg = "first core pointer device";
		break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1335
	    }
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
	}
    }

    /* 4. First pointer with 'mouse' as the driver. */
    if (!foundPointer) {
	confInput = xf86findInput(CONF_IMPLICIT_POINTER,
				  xf86configptr->conf_input_lst);
	if (!confInput) {
	    confInput = xf86findInputByDriver("mouse",
					      xf86configptr->conf_input_lst);
	}
	if (confInput) {
	    foundPointer = TRUE;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1349
	    from = X_DEFAULT;
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
	    pointerMsg = "first mouse device";
	}
    }

    /* 5. Built-in default. */
    if (!foundPointer) {
	bzero(&defPtr, sizeof(defPtr));
	defPtr.inp_identifier = "<default pointer>";
	defPtr.inp_driver = "mouse";
	confInput = &defPtr;
	foundPointer = TRUE;
	from = X_DEFAULT;
	pointerMsg = "default mouse configuration";
    }

    /* Add the core pointer device to the layout, and set it to Core. */
    if (foundPointer && confInput) {
	foundPointer = configInput(&Pointer, confInput, from);
        if (foundPointer) {
	    count++;
1370
1371
1372
1373
1374
	    devs = xnfrealloc(servlayoutp->inputs,
			      (count + 1) * sizeof(IDevPtr));
            devs[count - 1] = xnfalloc(sizeof(IDevRec));
	    *devs[count - 1] = Pointer;
	    devs[count - 1]->extraOptions =
1375
				xf86addNewOption(NULL, xnfstrdup("CorePointer"), NULL);
1376
	    devs[count] = NULL;
1377
	    servlayoutp->inputs = devs;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1378
	}
1379
1380
1381
1382
1383
1384
1385
1386
    }

    if (!foundPointer) {
	/* This shouldn't happen. */
	xf86Msg(X_ERROR, "Cannot locate a core pointer device.\n");
	return FALSE;
    }

1387
1388
1389
1390
    /*
     * always synthesize a 'mouse' section configured to send core
     * events, unless a 'void' section is found, in which case the user
     * probably wants to run footless.
1391
1392
1393
     *
     * If you're using an evdev keyboard and expect a default mouse
     * section ... deal.
1394
     */
1395
1396
1397
    for (devs = servlayoutp->inputs; devs && *devs; devs++) {
	if (!strcmp((*devs)->driver, "void") || !strcmp((*devs)->driver, "mouse") ||
            !strcmp((*devs)->driver, "vmmouse") || !strcmp((*devs)->driver, "evdev")) {
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
	    found = 1; break;
	}
    }
    if (!found) {
	xf86Msg(X_INFO, "No default mouse found, adding one\n");
	bzero(&defPtr, sizeof(defPtr));
	defPtr.inp_identifier = "<default pointer>";
	defPtr.inp_driver = "mouse";
	confInput = &defPtr;
	foundPointer = configInput(&Pointer, confInput, from);
        if (foundPointer) {
	    count++;
1410
1411
1412
1413
1414
	    devs = xnfrealloc(servlayoutp->inputs,
			      (count + 1) * sizeof(IDevPtr));
            devs[count - 1] = xnfalloc(sizeof(IDevRec));
	    *devs[count - 1] = Pointer;
	    devs[count - 1]->extraOptions =
1415
				xf86addNewOption(NULL, xnfstrdup("AlwaysCore"), NULL);
1416
	    devs[count] = NULL;
1417
	    servlayoutp->inputs = devs;
1418
1419
1420
	}
    }

1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
    confInput = NULL;

    /* 1. Check for the -keyboard command line option. */
    if (xf86KeyboardName) {
	confInput = xf86findInput(xf86KeyboardName,
				  xf86configptr->conf_input_lst);
	if (!confInput) {
	    xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n",
		    xf86KeyboardName);
	    return FALSE;
	}
	from = X_CMDLINE;
	/*
	 * If one was already specified in the ServerLayout, it needs to be
	 * removed.
	 */
	if (coreKeyboard) {
1438
1439
1440
1441
1442
	    for (devs = servlayoutp->inputs; devs && *devs; devs++)
		if (*devs == coreKeyboard)
                {
                    xfree(*devs);
                    *devs = (IDevPtr)0x1; /* ensure we dont skip next loop */
1443
		    break;
1444
1445
1446
                }
	    for (; devs && *devs; devs++)
		devs[0] = devs[1];