xf86Config.c 73.6 KB
Newer Older
1
/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86Config.c,v 1.4 2004/08/09 02:08:35 kem Exp $ */
Egbert Eich's avatar
Egbert Eich committed
2
/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Config.c,v 3.276 2003/10/08 14:58:26 dawes Exp $ */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
3
4


5
/*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
6
 * Loosely based on code bearing the following copyright:
7
 *
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
8
 *   Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
9
10
11
12
13
14
15
16
17
18
19
20
 */

/*
 * 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:
21
 *
22
23
 * 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
24
 *
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 * 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
47
48
 */

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

54
55
56
57
#ifdef __UNIXOS2__
#define I_NEED_OS2_H
#endif

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
58
59
60
61
62
#include "xf86.h"
#include "xf86Parser.h"
#include "xf86tokens.h"
#include "xf86Config.h"
#include "xf86Priv.h"
63
64
#include "xf86_OSlib.h"

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
65
#include "globals.h"
66
67
68

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

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
72
73
74
#ifdef XKB
#define XKB_IN_SERVER
#include "XKBsrv.h"
75
76
#endif

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

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
81
82
83
84
#if (defined(i386) || defined(__i386__)) && \
    (defined(__FreeBSD__) || defined(__NetBSD__) || defined(linux) || \
     (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
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * 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;

/* 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
static Bool configDRI(XF86ConfDRIPtr drip);
130
#endif
131
static Bool configExtensions(XF86ConfExtensionsPtr conf_ext);
132
133
134
135
136
137
138
139

/*
 * 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
140
141
static char *
xf86GetPathElem(char **pnt)
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
{
  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
162
163

#define DIR_FILE "/fonts.dir"
164
static char *
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
165
xf86ValidateFontPath(char *path)
166
167
168
169
170
171
{
  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
172
  tmp_path = xcalloc(1,strlen(path)+1);
173
174
175
176
177
178
  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
179
180
#ifndef __UNIXOS2__
      dir_elem = xnfcalloc(1, strlen(path_elem) + 1);
181
182
183
184
      if ((p1 = strchr(path_elem, ':')) != 0)
#else
    /* OS/2 must prepend X11ROOT */
      path_elem = (char*)__XOS2RedirRoot(path_elem);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
185
      dir_elem = xnfcalloc(1, strlen(path_elem) + 1);
186
187
188
189
190
191
192
193
194
      if (p1 = strchr(path_elem+2, ':'))
#endif
	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
195
	if (!S_ISDIR(stat_buf.st_mode))
196
197
	  flag = -1;
      if (flag != 0) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
198
199
200
        xf86Msg(X_WARNING, "The directory \"%s\" does not exist.\n", dir_elem);
	xf86ErrorF("\tEntry deleted from font path.\n");
	xfree(dir_elem);
201
202
203
	continue;
      }
      else {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
204
	p1 = xnfalloc(strlen(dir_elem)+strlen(DIR_FILE)+1);
205
206
207
208
	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
209
	  if (!S_ISREG(stat_buf.st_mode))
210
	    flag = -1;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
211
#ifndef __UNIXOS2__
212
213
214
	xfree(p1);
#endif
	if (flag != 0) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
215
216
217
218
219
220
	  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);
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
	  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
239

240
/*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
241
242
 * use the datastructure that the parser provides and pick out the parts
 * that we need at this point
243
 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
244
245
char **
xf86ModulelistFromConfig(pointer **optlist)
246
{
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
    int count = 0;
    char **modulearray;
    pointer *optarray;
    XF86LoadPtr modp;
    
    /*
     * 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) {
	/*
	 * Walk the list of modules in the "Module" section to determine how
	 * many we have.
	 */
	modp = xf86configptr->conf_modules->mod_load_lst;
	while (modp) {
	    count++;
	    modp = (XF86LoadPtr) modp->list.next;
271
	}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
272
273
274
    }
    if (count == 0)
	return NULL;
275

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
276
277
278
279
280
281
282
283
284
285
286
287
288
    /*
     * 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) {
	modp = xf86configptr->conf_modules->mod_load_lst;
	while (modp) {
	    modulearray[count] = modp->load_name;
	    optarray[count] = modp->load_opt;
	    count++;
	    modp = (XF86LoadPtr) modp->list.next;
289
290
	}
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    modulearray[count] = NULL;
    optarray[count] = NULL;
    if (optlist)
	*optlist = optarray;
    else
	xfree(optarray);
    return modulearray;
}


char **
xf86DriverlistFromConfig()
{
    int count = 0;
    int j;
    char **modulearray;
    screenLayoutPtr slp;
308
    
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
309
310
311
312
313
314
315
316
    /*
     * 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;
317
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
318
319
320
321
322
323
324
325
326
327
328
    
    /*
     * 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++;
        }
329
330
    }

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
331
332
333
334
335
336
    /*
     * Handle the set of inactive "Device" sections.
     */
    j = 0;
    while (xf86ConfigLayout.inactives[j++].identifier)
	count++;
337

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
338
339
    if (count == 0)
	return NULL;
340

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
341
342
343
344
345
346
347
348
349
350
351
    /*
     * 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++;
    }
352

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
353
    j = 0;
354

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
355
356
    while (xf86ConfigLayout.inactives[j].identifier) 
	modulearray[count++] = xf86ConfigLayout.inactives[j++].driver;
357

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
358
    modulearray[count] = NULL;
359

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
360
361
362
    /* Remove duplicates */
    for (count = 0; modulearray[count] != NULL; count++) {
	int i;
363

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
364
365
366
367
368
369
370
	for (i = 0; i < count; i++)
	    if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) {
		modulearray[count] = "";
		break;
	    }
    }
    return modulearray;
371
372
373
}


Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
374
375
Bool
xf86BuiltinInputDriver(const char *name)
376
{
377
#ifdef USE_DEPRECATED_KEYBOARD_DRIVER
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
378
379
380
    if (xf86NameCmp(name, "keyboard") == 0)
	return TRUE;
    else
381
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
382
	return FALSE;
383
384
}

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
385
386
387
388
389
390
char **
xf86InputDriverlistFromConfig()
{
    int count = 0;
    char **modulearray;
    IDevPtr idp;
391
392
    
    /*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
393
394
395
     * make sure the config file has been parsed and that we have a
     * ModulePath set; if no ModulePath was given, use the default
     * ModulePath
396
     */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
397
398
399
    if (xf86configptr == NULL) {
        xf86Msg(X_ERROR, "Cannot access global config data structure\n");
        return NULL;
400
401
402
    }
    
    /*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
403
404
     * Walk the list of driver lines in active "InputDevice" sections to
     * determine now many implicitly loaded modules there are.
405
     */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
406
407
408
409
410
411
412
413
    if (xf86ConfigLayout.inputs) {
        idp = xf86ConfigLayout.inputs;
        while (idp->identifier) {
	    if (!xf86BuiltinInputDriver(idp->driver))
	        count++;
	    idp++;
        }
    }
414

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
415
416
    if (count == 0)
	return NULL;
417
418

    /*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
419
     * allocate the memory and walk the list again to fill in the pointers
420
     */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
421
422
423
424
425
426
427
428
429
430
431
    modulearray = xnfalloc((count + 1) * sizeof(char*));
    count = 0;
    idp = xf86ConfigLayout.inputs;
    while (idp->identifier) {
	if (!xf86BuiltinInputDriver(idp->driver)) {
	    modulearray[count] = idp->driver;
	    count++;
	}
	idp++;
    }
    modulearray[count] = NULL;
432

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
433
434
435
436
437
438
439
440
441
442
443
    /* 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;
444
445
446
447
}


/*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
448
449
450
 * 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.
451
 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
452
453
static char **
GenerateDriverlist(char * dirname, char * drivernames)
454
{
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
    char *cp, **driverlist;
    int count;

    /* Count the number needed */
    count = 0;
    cp = drivernames;
    while (*cp) {
	while (*cp && isspace(*cp)) cp++;
	if (!*cp) break;
	count++;
	while (*cp && !isspace(*cp)) cp++;
    }

    if (!count)
	return NULL;

    /* Now allocate the array of pointers to 0-terminated driver names */
    driverlist = (char **)xnfalloc((count + 1) * sizeof(char *));
    count = 0;
    cp = drivernames;
    while (*cp) {
	while (*cp && isspace(*cp)) cp++;
	if (!*cp) break;
	driverlist[count++] = cp;
	while (*cp && !isspace(*cp)) cp++;
	if (!*cp) break;
	*cp++ = 0;
    }
    driverlist[count] = NULL;

#ifdef XFree86LOADER
486
    {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
487
488
489
490
491
492
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
528
529
530
531
532
533
534
535
536
537
        const char *subdirs[] = {NULL, NULL};
        static const char *patlist[] = {"(.*)_drv\\.so", "(.*)_drv\\.o", NULL};
        char **dlist, **clist, **dcp, **ccp;
	int size;

        subdirs[0] = dirname;

        /* Get module list */
        dlist = LoaderListDirs(subdirs, patlist);
        if (!dlist) {
            xfree(driverlist);
            return NULL;        /* No modules, no list */
        }

        clist = driverlist;

        /* The resulting list cannot be longer than the module list */
        for (dcp = dlist, count = 0;  *dcp++;  count++);
        driverlist = (char **)xnfalloc((size = count + 1) * sizeof(char *));

        /* First, add modules not in compiled-in list */
        for (count = 0, dcp = dlist;  *dcp;  dcp++) {
            for (ccp = clist;  ;  ccp++) {
                if (!*ccp) {
                    driverlist[count++] = *dcp;
		    if (count >= size)
			driverlist = (char**)
			    xnfrealloc(driverlist, ++size * sizeof(char*));
                    break;
                }
                if (!strcmp(*ccp, *dcp))
                    break;
            }
        }

        /* Next, add compiled-in names that are also modules */
        for (ccp = clist;  *ccp;  ccp++) {
            for (dcp = dlist;  *dcp;  dcp++) {
                if (!strcmp(*ccp, *dcp)) {
                    driverlist[count++] = *ccp;
		    if (count >= size)
			driverlist = (char**)
			    xnfrealloc(driverlist, ++size * sizeof(char*));
                    break;
                }
            }
        }

        driverlist[count] = NULL;
        xfree(clist);
        xfree(dlist);
538
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
539
540
541
#endif /* XFree86LOADER */

    return driverlist;
542
543
}

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
544
545
546

char **
xf86DriverlistFromCompile(void)
547
{
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
548
549
    static char **driverlist = NULL;
    static Bool generated = FALSE;
550

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
551
552
    /* This string is modified in-place */
    static char drivernames[] = DRIVERS;
553

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
554
555
556
    if (!generated) {
        generated = TRUE;
        driverlist = GenerateDriverlist("drivers", drivernames);
557
558
    }

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
    return driverlist;
}


char **
xf86InputDriverlistFromCompile(void)
{
    static char **driverlist = NULL;
    static Bool generated = FALSE;

    /* This string is modified in-place */
    static char drivernames[] = IDRIVERS;

    if (!generated) {
        generated = TRUE;
	driverlist = GenerateDriverlist("input", drivernames);
575
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605

    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;
}

static Bool
configFiles(XF86ConfFilesPtr fileconf)
{
  MessageType pathFrom = X_DEFAULT;

  /* FontPath */

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

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

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

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
661
662
663
664
665
666
667
668
669
670
671
672
  xf86Msg(pathFrom, "FontPath set to \"%s\"\n", defaultFontPath);

  /* RgbPath */

  pathFrom = X_DEFAULT;

  if (xf86coFlag)
    pathFrom = X_CMDLINE;
  else if (fileconf) {
    if (fileconf->file_rgbpath) {
      rgbPath = fileconf->file_rgbpath;
      pathFrom = X_CONFIG;
673
674
    }
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691

  xf86Msg(pathFrom, "RgbPath set to \"%s\"\n", rgbPath);

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

  if (fileconf) {
    if (xf86ModPathFrom != X_CMDLINE && fileconf->file_modulepath) {
      xf86ModulePath = fileconf->file_modulepath;
      xf86ModPathFrom = X_CONFIG;
692
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
693
694
695
696
  }

  xf86Msg(xf86ModPathFrom, "ModulePath set to \"%s\"\n", xf86ModulePath);
#endif
697

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
698
699
#if 0
  /* LogFile */
700
  /*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
701
702
703
704
705
706
707
   * 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.
708
   */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
709
710
711
712
713
  if (xf86LogFileFrom == X_DEFAULT && fileconf->file_logfile) {
    xf86LogFile = fileconf->file_logfile;
    xf86LogFileFrom = X_CONFIG;
  }
#endif
714

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
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
773
774
775
776
777
778
779
780
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
  return TRUE;
}

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,
    FLAG_RANDR
} 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 },
  { -1,				NULL,				OPTV_NONE,
	{0}, FALSE },
};

#if defined(i386) || defined(__i386__)
static Bool
detectPC98(void)
{
#ifdef SUPPORT_PC98
    unsigned char buf[2];
831

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
832
833
834
835
836
837
838
839
    if (xf86ReadBIOS(0xf8000, 0xe80, buf, 2) != 2)
	return FALSE;
    if ((buf[0] == 0x98) && (buf[1] == 0x21))
	return TRUE;
    else
	return FALSE;
#else
    return FALSE;
840
841
#endif
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
842
#endif /* __i386__ */
843

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
844
845
static Bool
configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
846
{
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
    XF86OptionPtr optp, tmp;
    int i;
    Pix24Flags pix24 = Pix24DontCare;
    Bool value;
    MessageType from;

    /*
     * 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));

    /*
     * 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");
906
#else
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
907
908
	if (value)
	    xf86Msg(X_WARNING, "VTSysReq is not supported on this OS\n");
909
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
    }

    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;
    {
	const char *s;
	if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) {
	    if (!xf86NameCmp(s,"flush")) {
		xf86Msg(X_CONFIG, "Flushing logfile enabled\n");
		xf86Info.log = LogFlush;
946
		LogSetParameter(XLOG_FLUSH, TRUE);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
947
948
949
	    } else if (!xf86NameCmp(s,"sync")) {
		xf86Msg(X_CONFIG, "Syncing logfile enabled\n");
		xf86Info.log = LogSync;
950
		LogSetParameter(XLOG_SYNC, TRUE);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
951
952
953
954
955
	    } else {
		xf86Msg(X_WARNING,"Unknown Log option\n");
	    }
        }
    }
956
    
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
957
958
959
960
961
962
963
964
965
#ifdef RENDER
    {
	const char *s;

	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
966
	    {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
967
968
		xf86Msg(X_CONFIG, "Render colormap policy set to %s\n", s);
		PictureCmapPolicy = policy;
969
970
	    }
	}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
    }
#endif
    {
	const char *s;
	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");
987
	    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
        }
    }
#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;
	
    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_SAVER_BLANKTIME, &i);
    if (i >= 0)
	ScreenSaverTime = defaultScreenSaverTime = i * MILLI_PER_MIN;
1009

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
#ifdef DPMSExtension
    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_DPMS_STANDBYTIME, &i);
    if (i >= 0)
	DPMSStandbyTime = defaultDPMSStandbyTime = i * MILLI_PER_MIN;
    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_DPMS_SUSPENDTIME, &i);
    if (i >= 0)
	DPMSSuspendTime = defaultDPMSSuspendTime = i * MILLI_PER_MIN;
    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_DPMS_OFFTIME, &i);
    if (i >= 0)
	DPMSOffTime = defaultDPMSOffTime = i * MILLI_PER_MIN;
#endif

    i = -1;
    xf86GetOptValInteger(FlagOptions, FLAG_PIXMAP, &i);
    switch (i) {
    case 24:
	pix24 = Pix24Use24;
	break;
    case 32:
	pix24 = Pix24Use32;
	break;
    case -1:
	break;
1036
    default:
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1037
1038
	xf86ConfigError("Pixmap option's value (%d) must be 24 or 32\n", i);
	return FALSE;
1039
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
    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;
    }
#if defined(i386) || defined(__i386__)
    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");
	}
1061
1062
#endif

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1063
1064
1065
1066
1067
1068
1069
#ifdef PANORAMIX
    from = X_DEFAULT;
    if (!noPanoramiXExtension)
      from = X_CMDLINE;
    else if (xf86GetOptValBool(FlagOptions, FLAG_XINERAMA, &value)) {
      noPanoramiXExtension = !value;
      from = X_CONFIG;
1070
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1071
1072
    if (!noPanoramiXExtension)
      xf86Msg(from, "Xinerama: enabled\n");
1073
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1074
1075

    return TRUE;
1076
1077
}

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1078
1079
1080
1081
1082
1083
/*
 * XXX This function is temporary, and will be removed when the keyboard
 * driver is converted into a regular input driver.
 */
static Bool
configInputKbd(IDevPtr inputp)
1084
{
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1085
1086
1087
1088
1089
  char *s;
  MessageType from = X_DEFAULT;
  Bool customKeycodesDefault = FALSE;
  int verb = 0;

1090
1091
1092
1093
  /* Initialize defaults */
  xf86Info.xleds         = 0L;
  xf86Info.kbdDelay      = 500;
  xf86Info.kbdRate       = 30;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1094
1095
  
  xf86Info.kbdProc       = NULL;
1096
1097
  xf86Info.vtinit        = NULL;
  xf86Info.vtSysreq      = VT_SYSREQ_DEFAULT;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1098
#if defined(SVR4) && defined(i386)
1099
1100
  xf86Info.panix106      = FALSE;
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1101
1102
1103
  xf86Info.kbdCustomKeycodes = FALSE;
#ifdef WSCONS_SUPPORT
  xf86Info.kbdFd 	   = -1;
1104
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1105
1106
#ifdef XKB
  if (!xf86IsPc98()) {
Egbert Eich's avatar
Egbert Eich committed
1107
    xf86Info.xkbrules      = __XKBDEFRULES__;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
    xf86Info.xkbmodel      = "pc105";
    xf86Info.xkblayout     = "us";
    xf86Info.xkbvariant    = NULL;
    xf86Info.xkboptions    = NULL;
  } else {
    xf86Info.xkbrules      = "xfree98";
    xf86Info.xkbmodel      = "pc98";
    xf86Info.xkblayout     = "nec/jp";
    xf86Info.xkbvariant    = NULL;
    xf86Info.xkboptions    = NULL;
  }
  xf86Info.xkbcomponents_specified = FALSE;
  /* Should discourage the use of these. */
  xf86Info.xkbkeymap     = NULL;
  xf86Info.xkbtypes      = NULL;
  xf86Info.xkbcompat     = NULL;
  xf86Info.xkbkeycodes   = NULL;
  xf86Info.xkbsymbols    = NULL;
  xf86Info.xkbgeometry   = NULL;
#endif

  s = xf86SetStrOption(inputp->commonOptions, "Protocol", "standard");
  if (xf86NameCmp(s, "standard") == 0) {
     xf86Info.kbdProc    = xf86KbdProc;
     xf86Info.kbdEvents  = xf86KbdEvents;
     xfree(s);
  } else if (xf86NameCmp(s, "xqueue") == 0) {
1135
#ifdef XQUEUE
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
    xf86Info.kbdProc = xf86XqueKbdProc;
    xf86Info.kbdEvents = xf86XqueEvents;
    xf86Msg(X_CONFIG, "Xqueue selected for keyboard input\n");
#endif
    xfree(s);
#ifdef WSCONS_SUPPORT
  } else if (xf86NameCmp(s, "wskbd") == 0) {
     xf86Info.kbdProc    = xf86KbdProc;
     xf86Info.kbdEvents  = xf86WSKbdEvents;
     xfree(s);
     s = xf86SetStrOption(inputp->commonOptions, "Device", NULL);
     xf86Msg(X_CONFIG, "Keyboard: Protocol: wskbd\n");
     if (s == NULL) {
	 xf86ConfigError("A \"device\" option is required with"
			 " the \"wskbd\" keyboard protocol");
	 return FALSE;
     }
     xf86Info.kbdFd = open(s, O_RDWR | O_NONBLOCK | O_EXCL);
     if (xf86Info.kbdFd == -1) {
       xf86ConfigError("cannot open \"%s\"", s);
       xfree(s);
       return FALSE;
     }
     xfree(s);
     /* Find out keyboard type */
     if (ioctl(xf86Info.kbdFd, WSKBDIO_GTYPE, &xf86Info.wsKbdType) == -1) {
	     xf86ConfigError("cannot get keyboard type");
	     close(xf86Info.kbdFd);
	     return FALSE;
     }
     switch (xf86Info.wsKbdType) {
     case WSKBD_TYPE_PC_XT:
	     xf86Msg(X_PROBED, "Keyboard type: XT\n");
	     break;
     case WSKBD_TYPE_PC_AT:
	     xf86Msg(X_PROBED, "Keyboard type: AT\n");
	     break;
     case WSKBD_TYPE_USB:
	     xf86Msg(X_PROBED, "Keyboard type: USB\n");
	     break;
#ifdef WSKBD_TYPE_ADB
     case WSKBD_TYPE_ADB:
	     xf86Msg(X_PROBED, "Keyboard type: ADB\n");
	     break;
1180
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1181
1182
1183
1184
#ifdef WSKBD_TYPE_SUN
     case WSKBD_TYPE_SUN:
	     xf86Msg(X_PROBED, "Keyboard type: Sun\n");
	     break;
1185
1186
1187
1188
1189
#endif
#ifdef WSKBD_TYPE_SUN5
     case WSKBD_TYPE_SUN5:
	     xf86Msg(X_PROBED, "Keyboard type: Sun5\n");
	     break;
1190
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1191
1192
1193
1194
1195
1196
     default:
	     xf86ConfigError("Unsupported wskbd type \"%d\"", 
			     xf86Info.wsKbdType);
	     close(xf86Info.kbdFd);
	     return FALSE;
     }
1197
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1198
1199
1200
1201
1202
  } else {
    xf86ConfigError("\"%s\" is not a valid keyboard protocol name", s);
    xfree(s);
    return FALSE;
  }
1203

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1204
1205
1206
1207
1208
1209
1210
1211
1212
  s = xf86SetStrOption(inputp->commonOptions, "AutoRepeat", NULL);
  if (s) {
    if (sscanf(s, "%d %d", &xf86Info.kbdDelay, &xf86Info.kbdRate) != 2) {
      xf86ConfigError("\"%s\" is not a valid AutoRepeat value", s);
      xfree(s);
      return FALSE;
    }
  xfree(s);
  }
1213

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
  s = xf86SetStrOption(inputp->commonOptions, "XLeds", NULL);
  if (s) {
    char *l, *end;
    unsigned int i;
    l = strtok(s, " \t\n");
    while (l) {
      i = strtoul(l, &end, 0);
      if (*end == '\0')
	xf86Info.xleds |= 1L << (i - 1);
      else {
	xf86ConfigError("\"%s\" is not a valid XLeds value", l);
	xfree(s);
	return FALSE;
      }
      l = strtok(NULL, " \t\n");
1229
    }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1230
    xfree(s);
1231
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243

#ifdef XKB
  from = X_DEFAULT;
  if (noXkbExtension)
    from = X_CMDLINE;
  else if (xf86FindOption(inputp->commonOptions, "XkbDisable")) {
    xf86Msg(X_WARNING, "KEYBOARD: XKB should be disabled in the "
	    "ServerFlags section instead\n"
	    "\tof in the \"keyboard\" InputDevice section.\n");
    noXkbExtension =
	xf86SetBoolOption(inputp->commonOptions, "XkbDisable", FALSE);
    from = X_CONFIG;
1244
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
  if (noXkbExtension)
    xf86Msg(from, "XKB: disabled\n");

#define NULL_IF_EMPTY(s) (s[0] ? s : (xfree(s), (char *)NULL))

  if (!noXkbExtension && !XkbInitialMap) {
    if ((s = xf86SetStrOption(inputp->commonOptions, "XkbKeymap", NULL))) {
      xf86Info.xkbkeymap = NULL_IF_EMPTY(s);
      xf86Msg(X_CONFIG, "XKB: keymap: \"%s\" "
		"(overrides other XKB settings)\n", xf86Info.xkbkeymap);
    } else {
      if ((s = xf86SetStrOption(inputp->commonOptions, "XkbCompat", NULL))) {
	xf86Info.xkbcompat = NULL_IF_EMPTY(s);
	xf86Info.xkbcomponents_specified = TRUE;
	xf86Msg(X_CONFIG, "XKB: compat: \"%s\"\n", s);
1260
      }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1261
1262
1263
1264
1265

      if ((s = xf86SetStrOption(inputp->commonOptions, "XkbTypes", NULL))) {
	xf86Info.xkbtypes = NULL_IF_EMPTY(s);
	xf86Info.xkbcomponents_specified = TRUE;
	xf86Msg(X_CONFIG, "XKB: types: \"%s\"\n", s);
1266
1267
      }

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1268
1269
1270
1271
      if ((s = xf86SetStrOption(inputp->commonOptions, "XkbKeycodes", NULL))) {
	xf86Info.xkbkeycodes = NULL_IF_EMPTY(s);
	xf86Info.xkbcomponents_specified = TRUE;
	xf86Msg(X_CONFIG, "XKB: keycodes: \"%s\"\n", s);
1272
1273
      }

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1274
1275
1276
1277
1278
      if ((s = xf86SetStrOption(inputp->commonOptions, "XkbGeometry", NULL))) {
	xf86Info.xkbgeometry = NULL_IF_EMPTY(s);
	xf86Info.xkbcomponents_specified = TRUE;
	xf86Msg(X_CONFIG, "XKB: geometry: \"%s\"\n", s);
      }
1279

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1280
1281
1282
1283
      if ((s = xf86SetStrOption(inputp->commonOptions, "XkbSymbols", NULL))) {
	xf86Info.xkbsymbols = NULL_IF_EMPTY(s);
	xf86Info.xkbcomponents_specified = TRUE;
	xf86Msg(X_CONFIG, "XKB: symbols: \"%s\"\n", s);
1284
1285
      }

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1286
1287
1288
1289
1290
      if ((s = xf86SetStrOption(inputp->commonOptions, "XkbRules", NULL))) {
	xf86Info.xkbrules = NULL_IF_EMPTY(s);
	xf86Info.xkbcomponents_specified = TRUE;
	xf86Msg(X_CONFIG, "XKB: rules: \"%s\"\n", s);
      }
1291

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1292
1293
1294
1295
1296
      if ((s = xf86SetStrOption(inputp->commonOptions, "XkbModel", NULL))) {
	xf86Info.xkbmodel = NULL_IF_EMPTY(s);
	xf86Info.xkbcomponents_specified = TRUE;
	xf86Msg(X_CONFIG, "XKB: model: \"%s\"\n", s);
      }
1297

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1298
1299
1300
1301
1302
      if ((s = xf86SetStrOption(inputp->commonOptions, "XkbLayout", NULL))) {
	xf86Info.xkblayout = NULL_IF_EMPTY(s);
	xf86Info.xkbcomponents_specified = TRUE;
	xf86Msg(X_CONFIG, "XKB: layout: \"%s\"\n", s);
      }
1303

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1304
1305
1306
1307
      if ((s = xf86SetStrOption(inputp->commonOptions, "XkbVariant", NULL))) {
	xf86Info.xkbvariant = NULL_IF_EMPTY(s);
	xf86Info.xkbcomponents_specified = TRUE;
	xf86Msg(X_CONFIG, "XKB: variant: \"%s\"\n", s);
1308
1309
      }

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1310
1311
1312
1313
1314
1315
      if ((s = xf86SetStrOption(inputp->commonOptions, "XkbOptions", NULL))) {
	xf86Info.xkboptions = NULL_IF_EMPTY(s);
	xf86Info.xkbcomponents_specified = TRUE;
	xf86Msg(X_CONFIG, "XKB: options: \"%s\"\n", s);
      }
    }
1316
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1317
1318
1319
1320
1321
1322
#undef NULL_IF_EMPTY
#endif
#if defined(SVR4) && defined(i386)
  if ((xf86Info.panix106 =
	xf86SetBoolOption(inputp->commonOptions, "Panix106", FALSE))) {
    xf86Msg(X_CONFIG, "PANIX106: enabled\n");
1323
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1324
1325
#endif

1326
  /*
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1327
1328
1329
1330
   * This was once a compile time option (ASSUME_CUSTOM_KEYCODES)
   * defaulting to 1 on Linux/PPC. It is no longer necessary, but for
   * backwards compatibility we provide 'Option "CustomKeycodes"'
   * and try to autoprobe on Linux/PPC.
1331
   */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1332
1333
1334
  from = X_DEFAULT;
  verb = 2;
#if defined(__linux__) && defined(__powerpc__)
1335
  {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
    FILE *f;

    f = fopen("/proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes","r");
    if (f) {
      if (fgetc(f) == '0') {
	customKeycodesDefault = TRUE;
	from = X_PROBED;
	verb = 1;
      }
      fclose(f);
1346
1347
1348
    }
  }
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
  if (xf86FindOption(inputp->commonOptions, "CustomKeycodes")) {
    from = X_CONFIG;
    verb = 1;
  }
  xf86Info.kbdCustomKeycodes =
	xf86SetBoolOption(inputp->commonOptions, "CustomKeycodes",
			  customKeycodesDefault);
  xf86MsgVerb(from, verb, "Keyboard: CustomKeycode %s\n",
		xf86Info.kbdCustomKeycodes ? "enabled" : "disabled");

  return TRUE;
1360
1361
}

1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
/*
 * 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
1377
1378
1379
static Bool
checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
{
1380
    IDevPtr corePointer = NULL, coreKeyboard = NULL;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1381
    Bool foundPointer = FALSE, foundKeyboard = FALSE;
1382
    const char *pointerMsg = NULL, *keyboardMsg = NULL;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1383
1384
1385
    IDevPtr indp;
    IDevRec Pointer, Keyboard;
    XF86ConfInputPtr confInput;
1386
    XF86ConfInputRec defPtr, defKbd;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1387
1388
1389
    int count = 0;
    MessageType from = X_DEFAULT;

1390
1391
1392
1393
1394
    /*
     * 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.
     */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1395
    for (indp = servlayoutp->inputs; indp->identifier; indp++) {
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
	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;
1422
	}
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
	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
1439
1440
1441
	}
	count++;
    }
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488

    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) {
	    for (indp = servlayoutp->inputs; indp->identifier; indp++)
		if (indp == corePointer)
		    break;
	    for (; indp->identifier; indp++)
		indp[0] = indp[1];
	    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
1489
	    }
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
	}
    }

    /* 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
1503
	    from = X_DEFAULT;
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
	    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++;
	    indp = xnfrealloc(servlayoutp->inputs,
			      (count + 1) * sizeof(IDevRec));
	    indp[count - 1] = Pointer;
	    indp[count - 1].extraOptions =
				xf86addNewOption(NULL, "CorePointer", NULL);
	    indp[count].identifier = NULL;
	    servlayoutp->inputs = indp;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1531
	}
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
    }

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

    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) {
	    for (indp = servlayoutp->inputs; indp->identifier; indp++)
		if (indp == coreKeyboard)
		    break;
	    for (; indp->identifier; indp++)
		indp[0] = indp[1];
	    count--;
	}
	coreKeyboard = NULL;
	foundKeyboard = TRUE;
    }

    /* 2. ServerLayout-specified core keyboard. */
    if (coreKeyboard) {
	foundKeyboard = TRUE;
	from = X_CONFIG;
    }

    /* 3. First core keyboard device. */
    if (!foundKeyboard) {
	XF86ConfInputPtr p;

	for (p = xf86configptr->conf_input_lst; p; p = p->list.next) {
	    if (p->inp_option_lst &&
		xf86CheckBoolOption(p->inp_option_lst, "CoreKeyboard", FALSE)) {
		confInput = p;
		foundKeyboard = TRUE;
		from = X_DEFAULT;
		keyboardMsg = "first core keyboard device";
		break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1586
	    }
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
	}
    }

    /* 4. First keyboard with 'keyboard' or 'kbd' as the driver. */
    if (!foundKeyboard) {
	confInput = xf86findInput(CONF_IMPLICIT_KEYBOARD,
				  xf86configptr->conf_input_lst);
	if (!confInput) {
	    confInput = xf86findInputByDriver("keyboard",
					      xf86configptr->conf_input_lst);
	}
	if (!confInput) {
	    confInput = xf86findInputByDriver("kbd",
					      xf86configptr->conf_input_lst);
	}
	if (confInput) {
	    foundKeyboard = TRUE;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1604
	    from = X_DEFAULT;
1605
	    pointerMsg = "first keyboard device";
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1606
1607
	}
    }
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617

    /* 5. Built-in default. */
    if (!foundKeyboard) {
	bzero(&defKbd, sizeof(defKbd));
	defKbd.inp_identifier = "<default keyboard>";
	defKbd.inp_driver = "keyboard";
	confInput = &defKbd;
	foundKeyboard = TRUE;
	keyboardMsg = "default keyboard configuration";
	from = X_DEFAULT;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1618
    }
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637

    /* Add the core keyboard device to the layout, and set it to Core. */
    if (foundKeyboard && confInput) {
	foundKeyboard = configInput(&Keyboard, confInput, from);
        if (foundKeyboard) {
	    count++;
	    indp = xnfrealloc(servlayoutp->inputs,
			      (count + 1) * sizeof(IDevRec));
	    indp[count - 1] = Keyboard;
	    indp[count - 1].extraOptions =
				xf86addNewOption(NULL, "CoreKeyboard", NULL);
	    indp[count].identifier = NULL;
	    servlayoutp->inputs = indp;
	}
    }

    if (!foundKeyboard) {
	/* This shouldn't happen. */
	xf86Msg(X_ERROR, "Cannot locate a core keyboard device.\n");
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1638
	return FALSE;