First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xwin / winconfig.c
blob2c1877172b28e934d1fae8c50cc967872b04e050
1 /*
2 *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *Except as contained in this notice, the name of the XFree86 Project
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from the XFree86 Project.
28 * Authors: Alexander Gottwald
31 #ifdef HAVE_XWIN_CONFIG_H
32 #include <xwin-config.h>
33 #endif
34 #include "win.h"
35 #include "winconfig.h"
36 #include "winmsg.h"
37 #include "globals.h"
39 #ifdef XKB
40 #ifndef XKB_IN_SERVER
41 #define XKB_IN_SERVER
42 #endif
43 #include <xkbsrv.h>
44 #endif
46 #ifdef XWIN_XF86CONFIG
47 #ifndef CONFIGPATH
48 #define CONFIGPATH "%A," "%R," \
49 "/etc/X11/%R," "%P/etc/X11/%R," \
50 "%E," "%F," \
51 "/etc/X11/%F," "%P/etc/X11/%F," \
52 "%D/%X," \
53 "/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
54 "%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
55 "%P/etc/X11/%X," \
56 "%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
57 "%P/lib/X11/%X"
58 #endif
60 XF86ConfigPtr g_xf86configptr = NULL;
61 #endif
63 WinCmdlineRec g_cmdline = {
64 #ifdef XWIN_XF86CONFIG
65 NULL, /* configFile */
66 #endif
67 NULL, /* fontPath */
68 NULL, /* rgbPath */
69 #ifdef XWIN_XF86CONFIG
70 NULL, /* keyboard */
71 #endif
72 #ifdef XKB
73 FALSE, /* noXkbExtension */
74 NULL, /* xkbMap */
75 NULL, /* xkbRules */
76 NULL, /* xkbModel */
77 NULL, /* xkbLayout */
78 NULL, /* xkbVariant */
79 NULL, /* xkbOptions */
80 #endif
81 NULL, /* screenname */
82 NULL, /* mousename */
83 FALSE, /* emulate3Buttons */
84 0 /* emulate3Timeout */
87 winInfoRec g_winInfo = {
88 { /* keyboard */
89 0, /* leds */
90 500, /* delay */
91 30 /* rate */
92 #ifdef XKB
95 { /* xkb */
96 FALSE, /* disable */
97 NULL, /* rules */
98 NULL, /* model */
99 NULL, /* layout */
100 NULL, /* variant */
101 NULL, /* options */
102 NULL, /* initialMap */
103 NULL, /* keymap */
104 NULL, /* types */
105 NULL, /* compat */
106 NULL, /* keycodes */
107 NULL, /* symbols */
108 NULL /* geometry */
109 #endif
113 FALSE,
117 #define NULL_IF_EMPTY(x) (winNameCompare(x,"")?x:NULL)
119 #ifdef XWIN_XF86CONFIG
120 serverLayoutRec g_winConfigLayout;
122 static Bool ParseOptionValue (int scrnIndex, pointer options,
123 OptionInfoPtr p);
124 static Bool configLayout (serverLayoutPtr, XF86ConfLayoutPtr, char *);
125 static Bool configImpliedLayout (serverLayoutPtr, XF86ConfScreenPtr);
126 static Bool GetBoolValue (OptionInfoPtr p, const char *s);
129 Bool
130 winReadConfigfile ()
132 Bool retval = TRUE;
133 const char *filename;
134 MessageType from = X_DEFAULT;
135 char *xf86ConfigFile = NULL;
137 if (g_cmdline.configFile)
139 from = X_CMDLINE;
140 xf86ConfigFile = g_cmdline.configFile;
143 /* Parse config file into data structure */
145 filename = xf86openConfigFile (CONFIGPATH, xf86ConfigFile, PROJECTROOT);
147 /* Hack for backward compatibility */
148 if (!filename && from == X_DEFAULT)
149 filename = xf86openConfigFile (CONFIGPATH, "XF86Config", PROJECTROOT);
151 if (filename)
153 winMsg (from, "Using config file: \"%s\"\n", filename);
155 else
157 winMsg (X_ERROR, "Unable to locate/open config file");
158 if (xf86ConfigFile)
159 ErrorF (": \"%s\"", xf86ConfigFile);
160 ErrorF ("\n");
161 return FALSE;
163 if ((g_xf86configptr = xf86readConfigFile ()) == NULL)
165 winMsg (X_ERROR, "Problem parsing the config file\n");
166 return FALSE;
168 xf86closeConfigFile ();
170 LogPrintMarkers();
172 /* set options from data structure */
174 if (g_xf86configptr->conf_layout_lst == NULL || g_cmdline.screenname != NULL)
176 if (g_cmdline.screenname == NULL)
178 winMsg (X_WARNING,
179 "No Layout section. Using the first Screen section.\n");
181 if (!configImpliedLayout (&g_winConfigLayout,
182 g_xf86configptr->conf_screen_lst))
184 winMsg (X_ERROR, "Unable to determine the screen layout\n");
185 return FALSE;
188 else
190 /* Check if layout is given in the config file */
191 if (g_xf86configptr->conf_flags != NULL)
193 char *dfltlayout = NULL;
194 pointer optlist = g_xf86configptr->conf_flags->flg_option_lst;
196 if (optlist && winFindOption (optlist, "defaultserverlayout"))
197 dfltlayout =
198 winSetStrOption (optlist, "defaultserverlayout", NULL);
200 if (!configLayout (&g_winConfigLayout,
201 g_xf86configptr->conf_layout_lst,
202 dfltlayout))
204 winMsg (X_ERROR, "Unable to determine the screen layout\n");
205 return FALSE;
208 else
210 if (!configLayout (&g_winConfigLayout,
211 g_xf86configptr->conf_layout_lst,
212 NULL))
214 winMsg (X_ERROR, "Unable to determine the screen layout\n");
215 return FALSE;
220 /* setup special config files */
221 winConfigFiles ();
222 return retval;
224 #endif
226 /* load layout definitions */
227 #include "winlayouts.h"
229 /* Set the keyboard configuration */
230 Bool
231 winConfigKeyboard (DeviceIntPtr pDevice)
233 #ifdef XKB
234 char layoutName[KL_NAMELENGTH];
235 static unsigned int layoutNum = 0;
236 int keyboardType;
237 #endif
238 #ifdef XWIN_XF86CONFIG
239 XF86ConfInputPtr kbd = NULL;
240 XF86ConfInputPtr input_list = NULL;
241 MessageType kbdfrom = X_CONFIG;
242 #endif
243 MessageType from = X_DEFAULT;
244 char *s = NULL;
246 /* Setup defaults */
247 #ifdef XKB
248 g_winInfo.xkb.disable = FALSE;
249 # ifdef PC98 /* japanese */ /* not implemented */
250 g_winInfo.xkb.rules = "xfree98";
251 g_winInfo.xkb.model = "pc98";
252 g_winInfo.xkb.layout = "nex/jp";
253 g_winInfo.xkb.variant = NULL;
254 g_winInfo.xkb.options = NULL;
255 # else
256 g_winInfo.xkb.rules = "xorg";
257 g_winInfo.xkb.model = "pc101";
258 g_winInfo.xkb.layout = "us";
259 g_winInfo.xkb.variant = NULL;
260 g_winInfo.xkb.options = NULL;
261 # endif /* PC98 */
264 * Query the windows autorepeat settings and change the xserver defaults.
265 * If XKB is disabled then windows handles the autorepeat and the special
266 * treatment is not needed
269 int kbd_delay;
270 DWORD kbd_speed;
271 if (SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &kbd_delay, 0) &&
272 SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &kbd_speed, 0))
274 switch (kbd_delay)
276 case 0: g_winInfo.keyboard.delay = 250; break;
277 case 1: g_winInfo.keyboard.delay = 500; break;
278 case 2: g_winInfo.keyboard.delay = 750; break;
279 default:
280 case 3: g_winInfo.keyboard.delay = 1000; break;
282 g_winInfo.keyboard.rate = (kbd_speed>0)?kbd_speed:1;
283 winMsgVerb(X_PROBED, 1, "Setting autorepeat to delay=%d, rate=%d\n",
284 g_winInfo.keyboard.delay, g_winInfo.keyboard.rate);
289 keyboardType = GetKeyboardType (0);
290 if (keyboardType > 0 && GetKeyboardLayoutName (layoutName))
292 WinKBLayoutPtr pLayout;
293 Bool bfound = FALSE;
295 if (! layoutNum)
296 layoutNum = strtoul (layoutName, (char **)NULL, 16);
297 if ((layoutNum & 0xffff) == 0x411) {
298 /* The japanese layouts know a lot of different IMEs which all have
299 different layout numbers set. Map them to a single entry.
300 Same might apply for chinese, korean and other symbol languages
301 too */
302 layoutNum = (layoutNum & 0xffff);
303 if (keyboardType == 7)
305 /* Japanese layouts have problems with key event messages
306 such as the lack of WM_KEYUP for Caps Lock key.
307 Loading US layout fixes this problem. */
308 if (LoadKeyboardLayout("00000409", KLF_ACTIVATE) != NULL)
309 winMsg (X_INFO, "Loading US keyboard layout.\n");
310 else
311 winMsg (X_ERROR, "LoadKeyboardLaout failed.\n");
314 winMsg (X_PROBED, "winConfigKeyboard - Layout: \"%s\" (%08x) \n",
315 layoutName, layoutNum);
317 for (pLayout = winKBLayouts; pLayout->winlayout != -1; pLayout++)
319 if (pLayout->winlayout != layoutNum)
320 continue;
321 if (pLayout->winkbtype > 0 && pLayout->winkbtype != keyboardType)
322 continue;
324 bfound = TRUE;
325 winMsg (X_PROBED,
326 "Using preset keyboard for \"%s\" (%x), type \"%d\"\n",
327 pLayout->layoutname, pLayout->winlayout, keyboardType);
329 g_winInfo.xkb.model = pLayout->xkbmodel;
330 g_winInfo.xkb.layout = pLayout->xkblayout;
331 g_winInfo.xkb.variant = pLayout->xkbvariant;
332 g_winInfo.xkb.options = pLayout->xkboptions;
333 break;
336 if (!bfound)
338 HKEY regkey = NULL;
339 const char regtempl[] =
340 "SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\";
341 char *regpath;
342 char lname[256];
343 DWORD namesize = sizeof(lname);
345 regpath = malloc(sizeof(regtempl) + KL_NAMELENGTH + 1);
346 strcpy(regpath, regtempl);
347 strcat(regpath, layoutName);
349 if (!RegOpenKey(HKEY_LOCAL_MACHINE, regpath, &regkey) &&
350 !RegQueryValueEx(regkey, "Layout Text", 0, NULL, lname, &namesize))
352 winMsg (X_ERROR,
353 "Keyboardlayout \"%s\" (%s) is unknown\n", lname, layoutName);
356 /* Close registry key */
357 if (regkey)
358 RegCloseKey (regkey);
359 free(regpath);
363 g_winInfo.xkb.initialMap = NULL;
364 g_winInfo.xkb.keymap = NULL;
365 g_winInfo.xkb.types = NULL;
366 g_winInfo.xkb.compat = NULL;
367 g_winInfo.xkb.keycodes = NULL;
368 g_winInfo.xkb.symbols = NULL;
369 g_winInfo.xkb.geometry = NULL;
370 #endif /* XKB */
372 /* parse the configuration */
373 #ifdef XWIN_XF86CONFIG
374 if (g_cmdline.keyboard)
375 kbdfrom = X_CMDLINE;
378 * Until the layout code is finished, I search for the keyboard
379 * device and configure the server with it.
382 if (g_xf86configptr != NULL)
383 input_list = g_xf86configptr->conf_input_lst;
385 while (input_list != NULL)
387 if (winNameCompare (input_list->inp_driver, "keyboard") == 0)
389 /* Check if device name matches requested name */
390 if (g_cmdline.keyboard && winNameCompare (input_list->inp_identifier,
391 g_cmdline.keyboard))
392 continue;
393 kbd = input_list;
395 input_list = input_list->list.next;
398 if (kbd != NULL)
401 if (kbd->inp_identifier)
402 winMsg (kbdfrom, "Using keyboard \"%s\" as primary keyboard\n",
403 kbd->inp_identifier);
405 if ((s = winSetStrOption(kbd->inp_option_lst, "AutoRepeat", NULL)))
407 if ((sscanf(s, "%ld %ld", &g_winInfo.keyboard.delay,
408 &g_winInfo.keyboard.rate) != 2) ||
409 (g_winInfo.keyboard.delay < 1) ||
410 (g_winInfo.keyboard.rate == 0) ||
411 (1000 / g_winInfo.keyboard.rate) < 1)
413 winErrorFVerb (2, "\"%s\" is not a valid AutoRepeat value", s);
414 xfree(s);
415 return FALSE;
417 xfree(s);
418 winMsg (X_CONFIG, "AutoRepeat: %ld %ld\n",
419 g_winInfo.keyboard.delay, g_winInfo.keyboard.rate);
421 #endif
423 #ifdef XKB
424 from = X_DEFAULT;
425 if (g_cmdline.noXkbExtension)
427 from = X_CMDLINE;
428 g_winInfo.xkb.disable = TRUE;
430 #ifdef XWIN_XF86CONFIG
431 else if (kbd->inp_option_lst)
433 int b = winSetBoolOption (kbd->inp_option_lst, "XkbDisable", FALSE);
434 if (b)
436 from = X_CONFIG;
437 g_winInfo.xkb.disable = TRUE;
440 #endif
441 if (g_winInfo.xkb.disable)
443 winMsg (from, "XkbExtension disabled\n");
445 else
447 s = NULL;
448 if (g_cmdline.xkbRules)
450 s = g_cmdline.xkbRules;
451 from = X_CMDLINE;
453 #ifdef XWIN_XF86CONFIG
454 else
456 s = winSetStrOption (kbd->inp_option_lst, "XkbRules", NULL);
457 from = X_CONFIG;
459 #endif
460 if (s)
462 g_winInfo.xkb.rules = NULL_IF_EMPTY (s);
463 winMsg (from, "XKB: rules: \"%s\"\n", s);
466 s = NULL;
467 if (g_cmdline.xkbModel)
469 s = g_cmdline.xkbModel;
470 from = X_CMDLINE;
472 #ifdef XWIN_XF86CONFIG
473 else
475 s = winSetStrOption (kbd->inp_option_lst, "XkbModel", NULL);
476 from = X_CONFIG;
478 #endif
479 if (s)
481 g_winInfo.xkb.model = NULL_IF_EMPTY (s);
482 winMsg (from, "XKB: model: \"%s\"\n", s);
485 s = NULL;
486 if (g_cmdline.xkbLayout)
488 s = g_cmdline.xkbLayout;
489 from = X_CMDLINE;
491 #ifdef XWIN_XF86CONFIG
492 else
494 s = winSetStrOption (kbd->inp_option_lst, "XkbLayout", NULL);
495 from = X_CONFIG;
497 #endif
498 if (s)
500 g_winInfo.xkb.layout = NULL_IF_EMPTY (s);
501 winMsg (from, "XKB: layout: \"%s\"\n", s);
504 s = NULL;
505 if (g_cmdline.xkbVariant)
507 s = g_cmdline.xkbVariant;
508 from = X_CMDLINE;
510 #ifdef XWIN_XF86CONFIG
511 else
513 s = winSetStrOption (kbd->inp_option_lst, "XkbVariant", NULL);
514 from = X_CONFIG;
516 #endif
517 if (s)
519 g_winInfo.xkb.variant = NULL_IF_EMPTY (s);
520 winMsg (from, "XKB: variant: \"%s\"\n", s);
523 s = NULL;
524 if (g_cmdline.xkbOptions)
526 s = g_cmdline.xkbOptions;
527 from = X_CMDLINE;
529 #ifdef XWIN_XF86CONFIG
530 else
532 s = winSetStrOption (kbd->inp_option_lst, "XkbOptions", NULL);
533 from = X_CONFIG;
535 #endif
536 if (s)
538 g_winInfo.xkb.options = NULL_IF_EMPTY (s);
539 winMsg (from, "XKB: options: \"%s\"\n", s);
542 #ifdef XWIN_XF86CONFIG
543 from = X_CMDLINE;
545 if ((s = winSetStrOption (kbd->inp_option_lst, "XkbKeymap", NULL)))
547 g_winInfo.xkb.keymap = NULL_IF_EMPTY (s);
548 winMsg (X_CONFIG, "XKB: keymap: \"%s\" "
549 " (overrides other XKB settings)\n", s);
552 if ((s = winSetStrOption (kbd->inp_option_lst, "XkbCompat", NULL)))
554 g_winInfo.xkb.compat = NULL_IF_EMPTY (s);
555 winMsg (X_CONFIG, "XKB: compat: \"%s\"\n", s);
558 if ((s = winSetStrOption (kbd->inp_option_lst, "XkbTypes", NULL)))
560 g_winInfo.xkb.types = NULL_IF_EMPTY (s);
561 winMsg (X_CONFIG, "XKB: types: \"%s\"\n", s);
564 if ((s =
565 winSetStrOption (kbd->inp_option_lst, "XkbKeycodes", NULL)))
567 g_winInfo.xkb.keycodes = NULL_IF_EMPTY (s);
568 winMsg (X_CONFIG, "XKB: keycodes: \"%s\"\n", s);
571 if ((s =
572 winSetStrOption (kbd->inp_option_lst, "XkbGeometry", NULL)))
574 g_winInfo.xkb.geometry = NULL_IF_EMPTY (s);
575 winMsg (X_CONFIG, "XKB: geometry: \"%s\"\n", s);
578 if ((s = winSetStrOption (kbd->inp_option_lst, "XkbSymbols", NULL)))
580 g_winInfo.xkb.symbols = NULL_IF_EMPTY (s);
581 winMsg (X_CONFIG, "XKB: symbols: \"%s\"\n", s);
583 #endif
584 #endif
586 #ifdef XWIN_XF86CONFIG
588 #endif
590 return TRUE;
594 #ifdef XWIN_XF86CONFIG
595 Bool
596 winConfigMouse (DeviceIntPtr pDevice)
598 MessageType mousefrom = X_CONFIG;
600 XF86ConfInputPtr mouse = NULL;
601 XF86ConfInputPtr input_list = NULL;
603 if (g_cmdline.mouse)
604 mousefrom = X_CMDLINE;
606 if (g_xf86configptr != NULL)
607 input_list = g_xf86configptr->conf_input_lst;
609 while (input_list != NULL)
611 if (winNameCompare (input_list->inp_driver, "mouse") == 0)
613 /* Check if device name matches requested name */
614 if (g_cmdline.mouse && winNameCompare (input_list->inp_identifier,
615 g_cmdline.mouse))
616 continue;
617 mouse = input_list;
619 input_list = input_list->list.next;
622 if (mouse != NULL)
624 if (mouse->inp_identifier)
625 winMsg (mousefrom, "Using pointer \"%s\" as primary pointer\n",
626 mouse->inp_identifier);
628 g_winInfo.pointer.emulate3Buttons =
629 winSetBoolOption (mouse->inp_option_lst, "Emulate3Buttons", FALSE);
630 if (g_cmdline.emulate3buttons)
631 g_winInfo.pointer.emulate3Buttons = g_cmdline.emulate3buttons;
633 g_winInfo.pointer.emulate3Timeout =
634 winSetIntOption (mouse->inp_option_lst, "Emulate3Timeout", 50);
635 if (g_cmdline.emulate3timeout)
636 g_winInfo.pointer.emulate3Timeout = g_cmdline.emulate3timeout;
638 else
640 winMsg (X_ERROR, "No primary pointer configured\n");
641 winMsg (X_DEFAULT, "Using compiletime defaults for pointer\n");
644 return TRUE;
648 Bool
649 winConfigFiles ()
651 MessageType from;
652 XF86ConfFilesPtr filesptr = NULL;
654 /* set some shortcuts */
655 if (g_xf86configptr != NULL)
657 filesptr = g_xf86configptr->conf_files;
661 /* Fontpath */
662 from = X_DEFAULT;
664 if (g_cmdline.fontPath)
666 from = X_CMDLINE;
667 defaultFontPath = g_cmdline.fontPath;
669 else if (filesptr != NULL && filesptr->file_fontpath)
671 from = X_CONFIG;
672 defaultFontPath = xstrdup (filesptr->file_fontpath);
674 winMsg (from, "FontPath set to \"%s\"\n", defaultFontPath);
676 /* RGBPath */
677 from = X_DEFAULT;
678 if (g_cmdline.rgbPath)
680 from = X_CMDLINE;
681 rgbPath = g_cmdline.rgbPath;
683 else if (filesptr != NULL && filesptr->file_rgbpath)
685 from = X_CONFIG;
686 rgbPath = xstrdup (filesptr->file_rgbpath);
688 winMsg (from, "RgbPath set to \"%s\"\n", rgbPath);
690 return TRUE;
692 #else
693 Bool
694 winConfigFiles ()
696 MessageType from;
698 /* Fontpath */
699 if (g_cmdline.fontPath)
701 defaultFontPath = g_cmdline.fontPath;
702 winMsg (X_CMDLINE, "FontPath set to \"%s\"\n", defaultFontPath);
705 /* RGBPath */
706 if (g_cmdline.rgbPath)
708 from = X_CMDLINE;
709 rgbPath = g_cmdline.rgbPath;
710 winMsg (X_CMDLINE, "RgbPath set to \"%s\"\n", rgbPath);
713 return TRUE;
715 #endif
718 Bool
719 winConfigOptions ()
721 return TRUE;
725 Bool
726 winConfigScreens ()
728 return TRUE;
732 #ifdef XWIN_XF86CONFIG
733 char *
734 winSetStrOption (pointer optlist, const char *name, char *deflt)
736 OptionInfoRec o;
738 o.name = name;
739 o.type = OPTV_STRING;
740 if (ParseOptionValue (-1, optlist, &o))
741 deflt = o.value.str;
742 if (deflt)
743 return xstrdup (deflt);
744 else
745 return NULL;
750 winSetBoolOption (pointer optlist, const char *name, int deflt)
752 OptionInfoRec o;
754 o.name = name;
755 o.type = OPTV_BOOLEAN;
756 if (ParseOptionValue (-1, optlist, &o))
757 deflt = o.value.bool;
758 return deflt;
763 winSetIntOption (pointer optlist, const char *name, int deflt)
765 OptionInfoRec o;
767 o.name = name;
768 o.type = OPTV_INTEGER;
769 if (ParseOptionValue (-1, optlist, &o))
770 deflt = o.value.num;
771 return deflt;
775 double
776 winSetRealOption (pointer optlist, const char *name, double deflt)
778 OptionInfoRec o;
780 o.name = name;
781 o.type = OPTV_REAL;
782 if (ParseOptionValue (-1, optlist, &o))
783 deflt = o.value.realnum;
784 return deflt;
786 #endif
790 * Compare two strings for equality. This is caseinsensitive and
791 * The characters '_', ' ' (space) and '\t' (tab) are treated as
792 * not existing.
796 winNameCompare (const char *s1, const char *s2)
798 char c1, c2;
800 if (!s1 || *s1 == 0)
802 if (!s2 || *s2 == 0)
803 return 0;
804 else
805 return 1;
808 while (*s1 == '_' || *s1 == ' ' || *s1 == '\t')
809 s1++;
810 while (*s2 == '_' || *s2 == ' ' || *s2 == '\t')
811 s2++;
813 c1 = (isupper (*s1) ? tolower (*s1) : *s1);
814 c2 = (isupper (*s2) ? tolower (*s2) : *s2);
816 while (c1 == c2)
818 if (c1 == 0)
819 return 0;
820 s1++;
821 s2++;
823 while (*s1 == '_' || *s1 == ' ' || *s1 == '\t')
824 s1++;
825 while (*s2 == '_' || *s2 == ' ' || *s2 == '\t')
826 s2++;
828 c1 = (isupper (*s1) ? tolower (*s1) : *s1);
829 c2 = (isupper (*s2) ? tolower (*s2) : *s2);
831 return (c1 - c2);
835 #ifdef XWIN_XF86CONFIG
837 * Find the named option in the list.
838 * @return the pointer to the option record, or NULL if not found.
841 XF86OptionPtr
842 winFindOption (XF86OptionPtr list, const char *name)
844 while (list)
846 if (winNameCompare (list->opt_name, name) == 0)
847 return list;
848 list = list->list.next;
850 return NULL;
855 * Find the Value of an named option.
856 * @return The option value or NULL if not found.
859 char *
860 winFindOptionValue (XF86OptionPtr list, const char *name)
862 list = winFindOption (list, name);
863 if (list)
865 if (list->opt_val)
866 return (list->opt_val);
867 else
868 return "";
870 return (NULL);
875 * Parse the option.
878 static Bool
879 ParseOptionValue (int scrnIndex, pointer options, OptionInfoPtr p)
881 char *s, *end;
883 if ((s = winFindOptionValue (options, p->name)) != NULL)
885 switch (p->type)
887 case OPTV_INTEGER:
888 if (*s == '\0')
890 winDrvMsg (scrnIndex, X_WARNING,
891 "Option \"%s\" requires an integer value\n",
892 p->name);
893 p->found = FALSE;
895 else
897 p->value.num = strtoul (s, &end, 0);
898 if (*end == '\0')
900 p->found = TRUE;
902 else
904 winDrvMsg (scrnIndex, X_WARNING,
905 "Option \"%s\" requires an integer value\n",
906 p->name);
907 p->found = FALSE;
910 break;
911 case OPTV_STRING:
912 if (*s == '\0')
914 winDrvMsg (scrnIndex, X_WARNING,
915 "Option \"%s\" requires an string value\n", p->name);
916 p->found = FALSE;
918 else
920 p->value.str = s;
921 p->found = TRUE;
923 break;
924 case OPTV_ANYSTR:
925 p->value.str = s;
926 p->found = TRUE;
927 break;
928 case OPTV_REAL:
929 if (*s == '\0')
931 winDrvMsg (scrnIndex, X_WARNING,
932 "Option \"%s\" requires a floating point value\n",
933 p->name);
934 p->found = FALSE;
936 else
938 p->value.realnum = strtod (s, &end);
939 if (*end == '\0')
941 p->found = TRUE;
943 else
945 winDrvMsg (scrnIndex, X_WARNING,
946 "Option \"%s\" requires a floating point value\n",
947 p->name);
948 p->found = FALSE;
951 break;
952 case OPTV_BOOLEAN:
953 if (GetBoolValue (p, s))
955 p->found = TRUE;
957 else
959 winDrvMsg (scrnIndex, X_WARNING,
960 "Option \"%s\" requires a boolean value\n", p->name);
961 p->found = FALSE;
963 break;
964 case OPTV_FREQ:
965 if (*s == '\0')
967 winDrvMsg (scrnIndex, X_WARNING,
968 "Option \"%s\" requires a frequency value\n",
969 p->name);
970 p->found = FALSE;
972 else
974 double freq = strtod (s, &end);
975 int units = 0;
977 if (end != s)
979 p->found = TRUE;
980 if (!winNameCompare (end, "Hz"))
981 units = 1;
982 else if (!winNameCompare (end, "kHz") ||
983 !winNameCompare (end, "k"))
984 units = 1000;
985 else if (!winNameCompare (end, "MHz") ||
986 !winNameCompare (end, "M"))
987 units = 1000000;
988 else
990 winDrvMsg (scrnIndex, X_WARNING,
991 "Option \"%s\" requires a frequency value\n",
992 p->name);
993 p->found = FALSE;
995 if (p->found)
996 freq *= (double) units;
998 else
1000 winDrvMsg (scrnIndex, X_WARNING,
1001 "Option \"%s\" requires a frequency value\n",
1002 p->name);
1003 p->found = FALSE;
1005 if (p->found)
1007 p->value.freq.freq = freq;
1008 p->value.freq.units = units;
1011 break;
1012 case OPTV_NONE:
1013 /* Should never get here */
1014 p->found = FALSE;
1015 break;
1017 if (p->found)
1019 winDrvMsgVerb (scrnIndex, X_CONFIG, 2, "Option \"%s\"", p->name);
1020 if (!(p->type == OPTV_BOOLEAN && *s == 0))
1022 winErrorFVerb (2, " \"%s\"", s);
1024 winErrorFVerb (2, "\n");
1027 else if (p->type == OPTV_BOOLEAN)
1029 /* Look for matches with options with or without a "No" prefix. */
1030 char *n, *newn;
1031 OptionInfoRec opt;
1033 n = winNormalizeName (p->name);
1034 if (!n)
1036 p->found = FALSE;
1037 return FALSE;
1039 if (strncmp (n, "no", 2) == 0)
1041 newn = n + 2;
1043 else
1045 free (n);
1046 n = malloc (strlen (p->name) + 2 + 1);
1047 if (!n)
1049 p->found = FALSE;
1050 return FALSE;
1052 strcpy (n, "No");
1053 strcat (n, p->name);
1054 newn = n;
1056 if ((s = winFindOptionValue (options, newn)) != NULL)
1058 if (GetBoolValue (&opt, s))
1060 p->value.bool = !opt.value.bool;
1061 p->found = TRUE;
1063 else
1065 winDrvMsg (scrnIndex, X_WARNING,
1066 "Option \"%s\" requires a boolean value\n", newn);
1067 p->found = FALSE;
1070 else
1072 p->found = FALSE;
1074 if (p->found)
1076 winDrvMsgVerb (scrnIndex, X_CONFIG, 2, "Option \"%s\"", newn);
1077 if (*s != 0)
1079 winErrorFVerb (2, " \"%s\"", s);
1081 winErrorFVerb (2, "\n");
1083 free (n);
1085 else
1087 p->found = FALSE;
1089 return p->found;
1093 static Bool
1094 configLayout (serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
1095 char *default_layout)
1097 #if 0
1098 #pragma warn UNIMPLEMENTED
1099 #endif
1100 return TRUE;
1104 static Bool
1105 configImpliedLayout (serverLayoutPtr servlayoutp,
1106 XF86ConfScreenPtr conf_screen)
1108 #if 0
1109 #pragma warn UNIMPLEMENTED
1110 #endif
1111 return TRUE;
1115 static Bool
1116 GetBoolValue (OptionInfoPtr p, const char *s)
1118 if (*s == 0)
1120 p->value.bool = TRUE;
1122 else
1124 if (winNameCompare (s, "1") == 0)
1125 p->value.bool = TRUE;
1126 else if (winNameCompare (s, "on") == 0)
1127 p->value.bool = TRUE;
1128 else if (winNameCompare (s, "true") == 0)
1129 p->value.bool = TRUE;
1130 else if (winNameCompare (s, "yes") == 0)
1131 p->value.bool = TRUE;
1132 else if (winNameCompare (s, "0") == 0)
1133 p->value.bool = FALSE;
1134 else if (winNameCompare (s, "off") == 0)
1135 p->value.bool = FALSE;
1136 else if (winNameCompare (s, "false") == 0)
1137 p->value.bool = FALSE;
1138 else if (winNameCompare (s, "no") == 0)
1139 p->value.bool = FALSE;
1141 return TRUE;
1143 #endif
1146 char *
1147 winNormalizeName (const char *s)
1149 char *ret, *q;
1150 const char *p;
1152 if (s == NULL)
1153 return NULL;
1155 ret = malloc (strlen (s) + 1);
1156 for (p = s, q = ret; *p != 0; p++)
1158 switch (*p)
1160 case '_':
1161 case ' ':
1162 case '\t':
1163 continue;
1164 default:
1165 if (isupper (*p))
1166 *q++ = tolower (*p);
1167 else
1168 *q++ = *p;
1171 *q = '\0';
1172 return ret;