xserver/xkb Imakefile, NONE, 1.1 Makefile, NONE, 1.1 Makefile.am, NONE, 1.1 Makefile.in, NONE, 1.1 XKBAlloc.c, NONE, 1.1 XKBGAlloc.c, NONE, 1.1 XKBMAlloc.c, NONE, 1.1 XKBMisc.c, NONE, 1.1 ddxBeep.c, NONE, 1.1 ddxConfig.c, NONE, 1.1 ddxCtrls.c, NONE, 1.1 ddxDevBtn.c, NONE, 1.1 ddxFakeBtn.c, NONE, 1.1 ddxFakeMtn.c, NONE, 1.1 ddxInit.c, NONE, 1.1 ddxKeyClick.c, NONE, 1.1 ddxKillSrv.c, NONE, 1.1 ddxLEDs.c, NONE, 1.1 ddxList.c, NONE, 1.1 ddxLoad.c, NONE, 1.1 ddxPrivate.c, NONE, 1.1 ddxVT.c, NONE, 1.1 maprules.c, NONE, 1.1 xf86KillSrv.c, NONE, 1.1 xf86Private.c, NONE, 1.1 xf86VT.c, NONE, 1.1 xkb.c, NONE, 1.1 xkb.h, NONE, 1.1 xkbAccessX.c, NONE, 1.1 xkbActions.c, NONE, 1.1 xkbDflts.h, NONE, 1.1 xkbEvents.c, NONE, 1.1 xkbInit.c, NONE, 1.1 xkbLEDs.c, NONE, 1.1 xkbPrKeyEv.c, NONE, 1.1 xkbPrOtherEv.c, NONE, 1.1 xkbSwap.c, NONE, 1.1 xkbUtils.c, NONE, 1.1 xkbconfig.c, NONE, 1.1 xkberrs.c, NONE, 1.1 xkbfmisc.c, NONE, 1.1 xkbout.c, NONE, 1.1 xkbtext.c, NONE, 1.1 xkmread.c, NONE, 1.1

Daniel Stone xserver-commit at pdx.freedesktop.org
Sun Apr 25 23:52:25 EST 2004


Committed by: daniel

Update of /cvs/xserver/xserver/xkb
In directory pdx:/tmp/cvs-serv17025/xkb

Added Files:
	Imakefile Makefile Makefile.am Makefile.in XKBAlloc.c 
	XKBGAlloc.c XKBMAlloc.c XKBMisc.c ddxBeep.c ddxConfig.c 
	ddxCtrls.c ddxDevBtn.c ddxFakeBtn.c ddxFakeMtn.c ddxInit.c 
	ddxKeyClick.c ddxKillSrv.c ddxLEDs.c ddxList.c ddxLoad.c 
	ddxPrivate.c ddxVT.c maprules.c xf86KillSrv.c xf86Private.c 
	xf86VT.c xkb.c xkb.h xkbAccessX.c xkbActions.c xkbDflts.h 
	xkbEvents.c xkbInit.c xkbLEDs.c xkbPrKeyEv.c xkbPrOtherEv.c 
	xkbSwap.c xkbUtils.c xkbconfig.c xkberrs.c xkbfmisc.c xkbout.c 
	xkbtext.c xkmread.c 
Log Message:
Xizzle is dead, long live Xorg.

Re-import the DDX from X11R6.7, complete with automakey goodness, and do the
requisite configure.ac, et al, updates; also import the XKB extension from the
6.7 DIX.

Currently it'll link and then hang solid in RADEONInitAccel(), or the next
function if you enable NoAccel.


--- NEW FILE: Imakefile ---
XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:53:45 cpqbld Exp $




XCOMM $XFree86: xc/programs/Xserver/xkb/Imakefile,v 3.21 2002/12/09 23:00:42 dawes Exp $

#define SGIHyperOpt
#include <Server.tmpl>

#ifdef SGIArchitecture
EXTRA_ALLOC_DEFINES = -DFORCE_ALLOCA
#endif

#if BuildXInputExt
XKBXI_SRCS = xkbPrOtherEv.c
XKBXI_OBJS = xkbPrOtherEv.o
#endif

#ifdef DfltDisableXKB
XKB_DISABLE = -DXKB_DFLT_DISABLED=1
#else
XKB_DISABLE = -DXKB_DFLT_DISABLED=0
#endif

XKB_DDXDEFS = XkbServerDefines

#if XF86Server || XorgServer
XF86INCLUDES = -I$(XF86COMSRC) -I$(XF86OSSRC)
   XF86_OBJS = xf86KillSrv.o xf86VT.o xf86Private.o
#endif

 DDX_SRCS = ddxBeep.c ddxCtrls.c ddxFakeBtn.c ddxFakeMtn.c ddxInit.c \
	    ddxKeyClick.c ddxKillSrv.c ddxLEDs.c ddxVT.c ddxLoad.c \
	    ddxList.c ddxConfig.c ddxDevBtn.c ddxPrivate.c xkbconfig.c
 DDX_OBJS = ddxBeep.o ddxCtrls.o ddxFakeBtn.o ddxFakeMtn.o ddxInit.o \
	    ddxKeyClick.o ddxKillSrv.o ddxLEDs.o ddxVT.o ddxLoad.o \
	    ddxList.o ddxConfig.o ddxDevBtn.o ddxPrivate.o xkbconfig.o
     SRCS = xkb.c xkbUtils.c xkbEvents.c xkbAccessX.c xkbSwap.c \
            xkbLEDs.c xkbInit.c xkbActions.c xkbPrKeyEv.c \
	    xkmread.c xkbtext.c xkbfmisc.c xkberrs.c xkbout.c maprules.c \
	    XKBMisc.c XKBMAlloc.c XKBAlloc.c XKBGAlloc.c \
	    $(XKBXI_SRCS) $(DDX_SRCS)
     OBJS = xkb.o xkbUtils.o xkbEvents.o xkbAccessX.o xkbSwap.o \
            xkbLEDs.o xkbInit.o xkbActions.o xkbPrKeyEv.o \
	    xkmread.o xkbtext.o xkbfmisc.o xkberrs.o xkbout.o maprules.o \
	    XKBMisc.o XKBMAlloc.o XKBAlloc.o XKBGAlloc.o \
	    $(XKBXI_OBJS) $(DDX_OBJS)
   INCLUDES = -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) -I$(SERVERSRC)/Xext \
	      -I$(SERVERSRC)/mi $(XF86INCLUDES)
   LINTLIBS = ../dix/llib-ldix.ln ../os/llib-los.ln

DEFINES = -DXKB_IN_SERVER $(EXTRA_ALLOC_DEFINES) $(XKB_DDXDEFS)
XKB_DEFINES = -DXKB_BASE_DIRECTORY=\"$(LIBDIR)/xkb\" $(XKB_DISABLE)

NormalLibraryObjectRule()
NormalLibraryTarget(xkb,$(OBJS))
LintLibraryTarget(xkb,$(SRCS))
NormalLintTarget($(SRCS))

#if XF86Server || XorgServer
ObjectFromSpecialSource(xf86KillSrv,ddxKillSrv,-DXF86DDXACTIONS)
ObjectFromSpecialSource(xf86VT,ddxVT,-DXF86DDXACTIONS)
ObjectFromSpecialSource(xf86Private,ddxPrivate,-DXF86DDXACTIONS)
AllTarget($(XF86_OBJS))
#endif

SpecialCObjectRule(xkbInit,$(ICONFIGFILES),$(XKB_DEFINES))

LinkSourceFile(maprules.c,$(XKBFILELIBSRC))
LinkSourceFile(xkmread.c,$(XKBFILELIBSRC))
LinkSourceFile(xkbtext.c,$(XKBFILELIBSRC))
XCOMM avoid clash between XKBMisc.c and xkbmisc.c on NT
LinkFile(xkbfmisc.c,$(XKBFILELIBSRC)/xkbmisc.c)
LinkSourceFile(xkberrs.c,$(XKBFILELIBSRC))
LinkSourceFile(xkbconfig.c,$(XKBFILELIBSRC))
LinkSourceFile(xkbout.c,$(XKBFILELIBSRC))
LinkSourceFile(XKBMisc.c,$(XLIBSRC))
LinkSourceFile(XKBMAlloc.c,$(XLIBSRC))
LinkSourceFile(XKBAlloc.c,$(XLIBSRC))
LinkSourceFile(XKBGAlloc.c,$(XLIBSRC))

LinkSourceFile(modinit.h,../Xext/extmod)

#if BuildLibraries
#if UseConfDirForXkb
LinkConfDirectory(xkb,.,xkb,.)
ODIR = $(CONFDIR)
#else
ODIR = $(LIBDIR)
#endif
#ifdef VarDbDirectory
NDIR = $(VARDBDIR)
#else
NDIR = $(CONFDIR)
#endif
#if !UseConfDirForXkb || defined(VarDbDirectory)
LinkConfDirectoryLong(xkb,xkb,compiled,compiled,$(ODIR),$(NDIR))
#endif
#endif

DependTarget()

--- NEW FILE: Makefile ---
# Makefile.in generated by automake 1.7.9 from Makefile.am.
# xkb/Makefile.  Generated from Makefile.in by configure.

# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.



srcdir = .
top_srcdir = ..

pkgdatadir = $(datadir)/Xserver
pkglibdir = $(libdir)/Xserver
pkgincludedir = $(includedir)/Xserver
top_builddir = ..

am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = /usr/bin/install -c
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
host_triplet = i686-pc-linux-gnu
ACLOCAL = aclocal-1.7
ALLOCA = 
AMDEP_FALSE = #
AMDEP_TRUE = 
AMTAR = ${SHELL} /home/daniel/x/xserver/missing --run tar
AR = ar
AS = as
AUTOCONF = ${SHELL} /home/daniel/x/xserver/missing --run autoconf
AUTOHEADER = ${SHELL} /home/daniel/x/xserver/missing --run autoheader
AUTOMAKE = automake-1.7
AWK = gawk
CC = gcc
CCAS = $(CC)
CCASFLAGS = $(CFLAGS)
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
COMPOSITE_FALSE = #
COMPOSITE_TRUE = 
CPP = gcc -E
CPPFLAGS = 
CXX = g++
CXXCPP = g++ -E
CXXDEPMODE = depmode=gcc3
CXXFLAGS = -g -O2
CYGPATH_W = echo
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
DLLTOOL = dlltool
DRI_FALSE = 
DRI_TRUE = #
ECHO = echo
ECHO_C = 
ECHO_N = -n
ECHO_T = 
EGREP = grep -E
EXEEXT = 
F77 = 
FFLAGS = 
GLX_FALSE = 
GLX_TRUE = #
H3600_TS_FALSE = 
H3600_TS_TRUE = #
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_STRIP_PROGRAM = ${SHELL} $(install_sh) -c -s
KDRIVEFBDEV_FALSE = #
KDRIVEFBDEV_TRUE = 
KDRIVESERVER_FALSE = 
KDRIVESERVER_TRUE = #
KDRIVEVESA_FALSE = #
KDRIVEVESA_TRUE = 
KDRIVE_INCS = 
KDRIVE_LIBS = 
KDRIVE_PURE_INCS = 
KDRIVE_PURE_LIBS = 
LDFLAGS = 
LEX = 
LEXLIB = 
LEX_OUTPUT_ROOT = 
LIBOBJS = 
LIBS = -lm 
LIBTOOL = $(SHELL) $(top_builddir)/libtool
LN_S = ln -s
LTLIBOBJS = 
MAINT = 
MAINTAINER_MODE_FALSE = #
MAINTAINER_MODE_TRUE = 
MAKEINFO = ${SHELL} /home/daniel/x/xserver/missing --run makeinfo
MESA_SOURCE = $(top_srcdir)/../Mesa
MITSHM_FALSE = #
MITSHM_TRUE = 
OBJDUMP = objdump
OBJEXT = o
PACKAGE = Xserver
PACKAGE_BUGREPORT = keithp at keithp.com
PACKAGE_NAME = Xserver
PACKAGE_STRING = Xserver 6.6.1
PACKAGE_TARNAME = Xserver
PACKAGE_VERSION = 6.6.1
PATH_SEPARATOR = :
PKG_CONFIG = /usr/bin/pkg-config
RANLIB = ranlib
RES_FALSE = #
RES_TRUE = 
SCREENSAVER_FALSE = #
SCREENSAVER_TRUE = 
SET_MAKE = 
SHAPE_FALSE = #
SHAPE_TRUE = 
SHELL = /bin/sh
STRIP = strip
TSLIB_FALSE = 
TSLIB_TRUE = #
USE_RGB_BUILTIN_FALSE = #
USE_RGB_BUILTIN_TRUE = 
VERSION = 6.6.1
XDMAUTH_FALSE = 
XDMAUTH_TRUE = #
XDMCP_CFLAGS = -I/home/daniel/install/x/include  
XDMCP_FALSE = #
XDMCP_LIBS = -L/home/daniel/install/x/lib -lXdmcp  
XDMCP_TRUE = 
XINERAMA_FALSE = 
XINERAMA_TRUE = #
XINPUT_FALSE = 
XINPUT_TRUE = #
XKB = 
XLOADABLE_FALSE = 
XLOADABLE_TRUE = #
XNESTSERVER_CFLAGS = 
XNESTSERVER_FALSE = 
XNESTSERVER_LIBS = 
XNESTSERVER_TRUE = #
XNEST_INCS = 
XNEST_LIBS = 
XORGSERVER_FALSE = #
XORGSERVER_TRUE = 
XORG_BUS_SBUS_FALSE = 
XORG_BUS_SBUS_TRUE = #
XORG_CFLAGS =  -D_XOPEN_SOURCE -D_POSIX_SOURCE=500 	             -D_BSD_SOURCE -Wall -DNEED_XF86_TYPES
XORG_CORE_LIBS = $(top_builddir)/dix/libdix.a $(top_builddir)/os/libos.a
XORG_INCS = -I$(top_srcdir)/hw/xorg/include \
	-I$(top_srcdir)/hw/xorg/common \
	-I$(top_srcdir)/hw/xorg/os-support \
	-I$(top_srcdir)/include \
	-I$(top_srcdir)/os \
	-I$(top_srcdir)/hw/xorg/os-support/bus -I$(top_srcdir)/Xext -I$(top_srcdir)/render -I$(top_srcdir)/randr -I$(top_srcdir)/xfixes -I$(top_srcdir)/damageext -I$(top_srcdir)/composite -I$(top_srcdir)/mi -I$(top_srcdir)/miext/damage 	           -I$(top_srcdir)/miext/shadow -I$(top_srcdir)/fb -DXTHREADS -DXUSE_MTSAFE_API -DDFLT_XKB_CONFIG_ROOT=/usr/X11R6/lib/X11/xkb -I/home/daniel/install/x/include -I/home/daniel/install/x/include/X11/fonts -I/home/daniel/install/x/include/X11/Xtrans   -I$(top_builddir)/Xi
XORG_LIBS = $(top_builddir)/fb/libfb.a $(top_builddir)/mi/libmi.a $(top_builddir)/Xi/libXi.a $(top_builddir)/xkb/libxkb.a $(top_builddir)/Xext/libXext.a $(top_builddir)/render/librender.a $(top_builddir)/randr/librandr.a $(top_builddir)/xfixes/libxfixes.a $(top_builddir)/damageext/libdamageext.a $(top_builddir)/composite/libcomposite.a 	           $(top_builddir)/miext/damage/libdamage.a $(top_builddir)/miext/shadow/libshadow.a $(top_builddir)/dix/libxpstubs.a
XORG_OS = linux
XORG_OS_SUBDIR = linux
XSDLSERVER_FALSE = 
XSDLSERVER_TRUE = #
XSDL_DIRS = 
XSDL_INCS = 
XSDL_LIBS = 
XSERVER_CFLAGS = -Wall -Wpointer-arith -Wstrict-prototypes 	-Wmissing-prototypes -Wmissing-declarations 	-Wnested-externs -fno-strict-aliasing -DXTHREADS -DXUSE_MTSAFE_API -DDFLT_XKB_CONFIG_ROOT=/usr/X11R6/lib/X11/xkb -I/home/daniel/install/x/include -I/home/daniel/install/x/include/X11/fonts -I/home/daniel/install/x/include/X11/Xtrans   -I${top_srcdir}/include -I${top_srcdir}/Xext
XSERVER_LIBS = -L/home/daniel/install/x/lib -lXfont -lm -lz -lxkbfile -lXau -lXext -lX11 -lXCB -lXdmcp  
XTRAP_FALSE = 
XTRAP_TRUE = #
XV_FALSE = #
XV_TRUE = 
XWINSERVER_CFLAGS = 
XWINSERVER_FALSE = 
XWINSERVER_LIBS = 
XWINSERVER_TRUE = #
XWIN_INCS = 
XWIN_LIBS = 
YACC = 
ac_ct_AR = ar
ac_ct_AS = 
ac_ct_CC = gcc
ac_ct_CXX = g++
ac_ct_DLLTOOL = 
ac_ct_F77 = 
ac_ct_OBJDUMP = 
ac_ct_RANLIB = ranlib
ac_ct_STRIP = strip
am__fastdepCC_FALSE = #
am__fastdepCC_TRUE = 
am__fastdepCXX_FALSE = #
am__fastdepCXX_TRUE = 
am__include = include
am__leading_dot = .
am__quote = 
bindir = ${exec_prefix}/bin
build = i686-pc-linux-gnu
build_alias = 
build_cpu = i686
build_os = linux-gnu
build_vendor = pc
datadir = ${prefix}/share
exec_prefix = ${prefix}
host = i686-pc-linux-gnu
host_alias = 
host_cpu = i686
host_os = linux-gnu
host_vendor = pc
includedir = ${prefix}/include
infodir = ${prefix}/info
install_sh = /home/daniel/x/xserver/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localstatedir = ${prefix}/var
mandir = ${prefix}/man
oldincludedir = /usr/include
prefix = /home/daniel/install/x
program_transform_name = s,x,x,
sbindir = ${exec_prefix}/sbin
sharedstatedir = ${prefix}/com
sysconfdir = ${prefix}/etc
target_alias = 
lib_LIBRARIES = libxkb.a
DDX_SRCS = \
        ddxBeep.c \
        ddxCtrls.c \
        ddxFakeBtn.c \
        ddxFakeMtn.c \
        ddxInit.c \
        ddxKeyClick.c \
        ddxKillSrv.c \
        ddxLEDs.c \
        ddxVT.c \
        ddxLoad.c \
        ddxList.c \
        ddxConfig.c \
        ddxDevBtn.c \
        ddxPrivate.c \
        xf86KillSrv.c \
        xf86VT.c \
        xf86Private.c

DIX_SRCS = \
        xkb.c \
        xkbUtils.c \
        xkbEvents.c \
        xkbAccessX.c \
        xkbSwap.c \
        xkbLEDs.c \
        xkbInit.c \
        xkbActions.c \
        xkbPrKeyEv.c

# this should be replaced by a common library or something, ideally -d
XKBFILE_SRCS = \
        maprules.c \
        xkmread.c \
        xkbtext.c \
        xkbfmisc.c \
        xkberrs.c \
        xkbconfig.c \
        xkbout.c

X11_SRCS = \
        XKBMisc.c \
        XKBAlloc.c \
        XKBGAlloc.c \
        XKBMAlloc.c

XI_SRCS = xkbPrOtherEv.c
libxkb_a_SOURCES = $(DDX_SRCS) $(DIX_SRCS) $(XI_SRCS) $(XKBFILE_SRCS) \
                   $(X11_SRCS)


AM_CFLAGS = -DXKB_DFLT_DISABLED=0 -DXKB_IN_SERVER \
            -DXKB_BASE_DIRECTORY=\"$(LIBDIR)/xkb\" -DXKB

INCLUDES = $(XORG_INCS) -I$(srcdir)/../mi -I$(srcdir)/../hw/xorg/common \
           -I$(srcdir)/../hw/xorg/include -I$(srcdir)/../hw/xorg/os-support/bus

subdir = xkb
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES =
LIBRARIES = $(lib_LIBRARIES)

libxkb_a_AR = $(AR) cru
libxkb_a_LIBADD =
am__objects_1 = ddxBeep.$(OBJEXT) ddxCtrls.$(OBJEXT) \
	ddxFakeBtn.$(OBJEXT) ddxFakeMtn.$(OBJEXT) ddxInit.$(OBJEXT) \
	ddxKeyClick.$(OBJEXT) ddxKillSrv.$(OBJEXT) ddxLEDs.$(OBJEXT) \
	ddxVT.$(OBJEXT) ddxLoad.$(OBJEXT) ddxList.$(OBJEXT) \
	ddxConfig.$(OBJEXT) ddxDevBtn.$(OBJEXT) ddxPrivate.$(OBJEXT) \
	xf86KillSrv.$(OBJEXT) xf86VT.$(OBJEXT) xf86Private.$(OBJEXT)
am__objects_2 = xkb.$(OBJEXT) xkbUtils.$(OBJEXT) xkbEvents.$(OBJEXT) \
	xkbAccessX.$(OBJEXT) xkbSwap.$(OBJEXT) xkbLEDs.$(OBJEXT) \
	xkbInit.$(OBJEXT) xkbActions.$(OBJEXT) xkbPrKeyEv.$(OBJEXT)
am__objects_3 = xkbPrOtherEv.$(OBJEXT)
am__objects_4 = maprules.$(OBJEXT) xkmread.$(OBJEXT) xkbtext.$(OBJEXT) \
	xkbfmisc.$(OBJEXT) xkberrs.$(OBJEXT) xkbconfig.$(OBJEXT) \
	xkbout.$(OBJEXT)
am__objects_5 = XKBMisc.$(OBJEXT) XKBAlloc.$(OBJEXT) XKBGAlloc.$(OBJEXT) \
	XKBMAlloc.$(OBJEXT)
am_libxkb_a_OBJECTS = $(am__objects_1) $(am__objects_2) $(am__objects_3) \
	$(am__objects_4) $(am__objects_5)
libxkb_a_OBJECTS = $(am_libxkb_a_OBJECTS)

DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)/include
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
DEP_FILES = ./$(DEPDIR)/XKBAlloc.Po ./$(DEPDIR)/XKBGAlloc.Po \
	./$(DEPDIR)/XKBMAlloc.Po ./$(DEPDIR)/XKBMisc.Po \
	./$(DEPDIR)/ddxBeep.Po ./$(DEPDIR)/ddxConfig.Po \
	./$(DEPDIR)/ddxCtrls.Po ./$(DEPDIR)/ddxDevBtn.Po \
	./$(DEPDIR)/ddxFakeBtn.Po ./$(DEPDIR)/ddxFakeMtn.Po \
	./$(DEPDIR)/ddxInit.Po ./$(DEPDIR)/ddxKeyClick.Po \
	./$(DEPDIR)/ddxKillSrv.Po ./$(DEPDIR)/ddxLEDs.Po \
	./$(DEPDIR)/ddxList.Po ./$(DEPDIR)/ddxLoad.Po \
	./$(DEPDIR)/ddxPrivate.Po ./$(DEPDIR)/ddxVT.Po \
	./$(DEPDIR)/maprules.Po ./$(DEPDIR)/xf86KillSrv.Po \
	./$(DEPDIR)/xf86Private.Po ./$(DEPDIR)/xf86VT.Po \
	./$(DEPDIR)/xkb.Po ./$(DEPDIR)/xkbAccessX.Po \
	./$(DEPDIR)/xkbActions.Po ./$(DEPDIR)/xkbEvents.Po \
	./$(DEPDIR)/xkbInit.Po ./$(DEPDIR)/xkbLEDs.Po \
	./$(DEPDIR)/xkbPrKeyEv.Po \
	./$(DEPDIR)/xkbPrOtherEv.Po ./$(DEPDIR)/xkbSwap.Po \
	./$(DEPDIR)/xkbUtils.Po ./$(DEPDIR)/xkbconfig.Po \
	./$(DEPDIR)/xkberrs.Po ./$(DEPDIR)/xkbfmisc.Po \
	./$(DEPDIR)/xkbout.Po ./$(DEPDIR)/xkbtext.Po \
	./$(DEPDIR)/xkmread.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
	$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
	$(AM_LDFLAGS) $(LDFLAGS) -o $@
DIST_SOURCES = $(libxkb_a_SOURCES)
DIST_COMMON = $(srcdir)/Makefile.in Makefile.am
SOURCES = $(libxkb_a_SOURCES)

all: all-am

.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in:  Makefile.am  $(top_srcdir)/configure.ac $(ACLOCAL_M4)
	cd $(top_srcdir) && \
	  $(AUTOMAKE) --gnu  xkb/Makefile
Makefile:  $(srcdir)/Makefile.in  $(top_builddir)/config.status
	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
libLIBRARIES_INSTALL = $(INSTALL_DATA)
install-libLIBRARIES: $(lib_LIBRARIES)
	@$(NORMAL_INSTALL)
	$(mkinstalldirs) $(DESTDIR)$(libdir)
	@list='$(lib_LIBRARIES)'; for p in $$list; do \
	  if test -f $$p; then \
	    f="`echo $$p | sed -e 's|^.*/||'`"; \
	    echo " $(libLIBRARIES_INSTALL) $$p $(DESTDIR)$(libdir)/$$f"; \
	    $(libLIBRARIES_INSTALL) $$p $(DESTDIR)$(libdir)/$$f; \
	  else :; fi; \
	done
	@$(POST_INSTALL)
	@list='$(lib_LIBRARIES)'; for p in $$list; do \
	  if test -f $$p; then \
	    p="`echo $$p | sed -e 's|^.*/||'`"; \
	    echo " $(RANLIB) $(DESTDIR)$(libdir)/$$p"; \
	    $(RANLIB) $(DESTDIR)$(libdir)/$$p; \
	  else :; fi; \
	done

uninstall-libLIBRARIES:
	@$(NORMAL_UNINSTALL)
	@list='$(lib_LIBRARIES)'; for p in $$list; do \
	  p="`echo $$p | sed -e 's|^.*/||'`"; \
	  echo " rm -f $(DESTDIR)$(libdir)/$$p"; \
	  rm -f $(DESTDIR)$(libdir)/$$p; \
	done

clean-libLIBRARIES:
	-test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES)
libxkb.a: $(libxkb_a_OBJECTS) $(libxkb_a_DEPENDENCIES) 
	-rm -f libxkb.a
	$(libxkb_a_AR) libxkb.a $(libxkb_a_OBJECTS) $(libxkb_a_LIBADD)
	$(RANLIB) libxkb.a

mostlyclean-compile:
	-rm -f *.$(OBJEXT) core *.core

distclean-compile:
	-rm -f *.tab.c

include ./$(DEPDIR)/XKBAlloc.Po
include ./$(DEPDIR)/XKBGAlloc.Po
include ./$(DEPDIR)/XKBMAlloc.Po
include ./$(DEPDIR)/XKBMisc.Po
include ./$(DEPDIR)/ddxBeep.Po
include ./$(DEPDIR)/ddxConfig.Po
include ./$(DEPDIR)/ddxCtrls.Po
include ./$(DEPDIR)/ddxDevBtn.Po
include ./$(DEPDIR)/ddxFakeBtn.Po
include ./$(DEPDIR)/ddxFakeMtn.Po
include ./$(DEPDIR)/ddxInit.Po
include ./$(DEPDIR)/ddxKeyClick.Po
include ./$(DEPDIR)/ddxKillSrv.Po
include ./$(DEPDIR)/ddxLEDs.Po
include ./$(DEPDIR)/ddxList.Po
include ./$(DEPDIR)/ddxLoad.Po
include ./$(DEPDIR)/ddxPrivate.Po
include ./$(DEPDIR)/ddxVT.Po
include ./$(DEPDIR)/maprules.Po
include ./$(DEPDIR)/xf86KillSrv.Po
include ./$(DEPDIR)/xf86Private.Po
include ./$(DEPDIR)/xf86VT.Po
include ./$(DEPDIR)/xkb.Po
include ./$(DEPDIR)/xkbAccessX.Po
include ./$(DEPDIR)/xkbActions.Po
include ./$(DEPDIR)/xkbEvents.Po
include ./$(DEPDIR)/xkbInit.Po
include ./$(DEPDIR)/xkbLEDs.Po
include ./$(DEPDIR)/xkbPrKeyEv.Po
include ./$(DEPDIR)/xkbPrOtherEv.Po
include ./$(DEPDIR)/xkbSwap.Po
include ./$(DEPDIR)/xkbUtils.Po
include ./$(DEPDIR)/xkbconfig.Po
include ./$(DEPDIR)/xkberrs.Po
include ./$(DEPDIR)/xkbfmisc.Po
include ./$(DEPDIR)/xkbout.Po
include ./$(DEPDIR)/xkbtext.Po
include ./$(DEPDIR)/xkmread.Po

.c.o:
	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
	  -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
	fi
#	source='$<' object='$@' libtool=no \
#	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' \
#	$(CCDEPMODE) $(depcomp) \
#	$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<

.c.obj:
	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
	  -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
	fi
#	source='$<' object='$@' libtool=no \
#	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' \
#	$(CCDEPMODE) $(depcomp) \
#	$(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`

.c.lo:
	if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
	  -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; \
	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
	fi
#	source='$<' object='$@' libtool=yes \
#	depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' \
#	$(CCDEPMODE) $(depcomp) \
#	$(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<

mostlyclean-libtool:
	-rm -f *.lo

clean-libtool:
	-rm -rf .libs _libs

distclean-libtool:
	-rm -f libtool
uninstall-info-am:

ETAGS = etags
ETAGSFLAGS =

CTAGS = ctags
CTAGSFLAGS =

tags: TAGS

ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	mkid -fID $$unique

TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
		$(TAGS_FILES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	test -z "$(ETAGS_ARGS)$$tags$$unique" \
	  || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
	     $$tags $$unique

ctags: CTAGS
CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
		$(TAGS_FILES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	test -z "$(CTAGS_ARGS)$$tags$$unique" \
	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
	     $$tags $$unique

GTAGS:
	here=`$(am__cd) $(top_builddir) && pwd` \
	  && cd $(top_srcdir) \
	  && gtags -i $(GTAGS_ARGS) $$here

distclean-tags:
	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)

top_distdir = ..
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)

distdir: $(DISTFILES)
	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
	list='$(DISTFILES)'; for file in $$list; do \
	  case $$file in \
	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
	  esac; \
	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
	    dir="/$$dir"; \
	    $(mkinstalldirs) "$(distdir)$$dir"; \
	  else \
	    dir=''; \
	  fi; \
	  if test -d $$d/$$file; then \
	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
	    fi; \
	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
	  else \
	    test -f $(distdir)/$$file \
	    || cp -p $$d/$$file $(distdir)/$$file \
	    || exit 1; \
	  fi; \
	done
check-am: all-am
check: check-am
all-am: Makefile $(LIBRARIES)

installdirs:
	$(mkinstalldirs) $(DESTDIR)$(libdir)
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am

install-am: all-am
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am

installcheck: installcheck-am
install-strip:
	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
	  `test -z '$(STRIP)' || \
	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:

clean-generic:

distclean-generic:
	-rm -f $(CONFIG_CLEAN_FILES)

maintainer-clean-generic:
	@echo "This command is intended for maintainers to use"
	@echo "it deletes files that may require special tools to rebuild."
clean: clean-am

clean-am: clean-generic clean-libLIBRARIES clean-libtool mostlyclean-am

distclean: distclean-am
	-rm -rf ./$(DEPDIR)
	-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
	distclean-libtool distclean-tags

dvi: dvi-am

dvi-am:

info: info-am

info-am:

install-data-am:

install-exec-am: install-libLIBRARIES

install-info: install-info-am

install-man:

installcheck-am:

maintainer-clean: maintainer-clean-am
	-rm -rf ./$(DEPDIR)
	-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic

mostlyclean: mostlyclean-am

mostlyclean-am: mostlyclean-compile mostlyclean-generic \
	mostlyclean-libtool

pdf: pdf-am

pdf-am:

ps: ps-am

ps-am:

uninstall-am: uninstall-info-am uninstall-libLIBRARIES

.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
	clean-libLIBRARIES clean-libtool ctags distclean \
	distclean-compile distclean-generic distclean-libtool \
	distclean-tags distdir dvi dvi-am info info-am install \
	install-am install-data install-data-am install-exec \
	install-exec-am install-info install-info-am \
	install-libLIBRARIES install-man install-strip installcheck \
	installcheck-am installdirs maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-compile \
	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
	tags uninstall uninstall-am uninstall-info-am \
	uninstall-libLIBRARIES


xf86%.c:
	echo "#define XF86DDXACTIONS" > $@
	echo "#include \"$(srcdir)/ddx$*.c\"" >> $@
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

--- NEW FILE: Makefile.am ---
lib_LIBRARIES = libxkb.a
DDX_SRCS = \
        ddxBeep.c \
        ddxCtrls.c \
        ddxFakeBtn.c \
        ddxFakeMtn.c \
        ddxInit.c \
        ddxKeyClick.c \
        ddxKillSrv.c \
        ddxLEDs.c \
        ddxVT.c \
        ddxLoad.c \
        ddxList.c \
        ddxConfig.c \
        ddxDevBtn.c \
        ddxPrivate.c \
        xf86KillSrv.c \
        xf86VT.c \
        xf86Private.c
DIX_SRCS = \
        xkb.c \
        xkbUtils.c \
        xkbEvents.c \
        xkbAccessX.c \
        xkbSwap.c \
        xkbLEDs.c \
        xkbInit.c \
        xkbActions.c \
        xkbPrKeyEv.c
# this should be replaced by a common library or something, ideally -d
XKBFILE_SRCS = \
        maprules.c \
        xkmread.c \
        xkbtext.c \
        xkbfmisc.c \
        xkberrs.c \
        xkbconfig.c \
        xkbout.c
X11_SRCS = \
        XKBMisc.c \
        XKBAlloc.c \
        XKBGAlloc.c \
        XKBMAlloc.c
XI_SRCS = xkbPrOtherEv.c
libxkb_a_SOURCES = $(DDX_SRCS) $(DIX_SRCS) $(XI_SRCS) $(XKBFILE_SRCS) \
                   $(X11_SRCS)

xf86%.c:
	echo "#define XF86DDXACTIONS" > $@
	echo "#include \"$(srcdir)/ddx$*.c\"" >> $@

AM_CFLAGS = -DXKB_DFLT_DISABLED=0 -DXKB_IN_SERVER \
            -DXKB_BASE_DIRECTORY=\"$(LIBDIR)/xkb\" -DXKB
INCLUDES = $(XORG_INCS) -I$(srcdir)/../mi -I$(srcdir)/../hw/xorg/common \
           -I$(srcdir)/../hw/xorg/include -I$(srcdir)/../hw/xorg/os-support/bus

--- NEW FILE: Makefile.in ---
# Makefile.in generated by automake 1.7.9 from Makefile.am.
# @configure_input@

# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.

@SET_MAKE@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..

am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
host_triplet = @host@
ACLOCAL = @ACLOCAL@
ALLOCA = @ALLOCA@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCAS = @CCAS@
CCASFLAGS = @CCASFLAGS@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
COMPOSITE_FALSE = @COMPOSITE_FALSE@
COMPOSITE_TRUE = @COMPOSITE_TRUE@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DRI_FALSE = @DRI_FALSE@
DRI_TRUE = @DRI_TRUE@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
GLX_FALSE = @GLX_FALSE@
GLX_TRUE = @GLX_TRUE@
H3600_TS_FALSE = @H3600_TS_FALSE@
H3600_TS_TRUE = @H3600_TS_TRUE@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
KDRIVEFBDEV_FALSE = @KDRIVEFBDEV_FALSE@
KDRIVEFBDEV_TRUE = @KDRIVEFBDEV_TRUE@
KDRIVESERVER_FALSE = @KDRIVESERVER_FALSE@
KDRIVESERVER_TRUE = @KDRIVESERVER_TRUE@
KDRIVEVESA_FALSE = @KDRIVEVESA_FALSE@
KDRIVEVESA_TRUE = @KDRIVEVESA_TRUE@
KDRIVE_INCS = @KDRIVE_INCS@
KDRIVE_LIBS = @KDRIVE_LIBS@
KDRIVE_PURE_INCS = @KDRIVE_PURE_INCS@
KDRIVE_PURE_LIBS = @KDRIVE_PURE_LIBS@
LDFLAGS = @LDFLAGS@
LEX = @LEX@
LEXLIB = @LEXLIB@
LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAINT = @MAINT@
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
MAKEINFO = @MAKEINFO@
MESA_SOURCE = @MESA_SOURCE@
MITSHM_FALSE = @MITSHM_FALSE@
MITSHM_TRUE = @MITSHM_TRUE@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
RANLIB = @RANLIB@
RES_FALSE = @RES_FALSE@
RES_TRUE = @RES_TRUE@
SCREENSAVER_FALSE = @SCREENSAVER_FALSE@
SCREENSAVER_TRUE = @SCREENSAVER_TRUE@
SET_MAKE = @SET_MAKE@
SHAPE_FALSE = @SHAPE_FALSE@
SHAPE_TRUE = @SHAPE_TRUE@
SHELL = @SHELL@
STRIP = @STRIP@
TSLIB_FALSE = @TSLIB_FALSE@
TSLIB_TRUE = @TSLIB_TRUE@
USE_RGB_BUILTIN_FALSE = @USE_RGB_BUILTIN_FALSE@
USE_RGB_BUILTIN_TRUE = @USE_RGB_BUILTIN_TRUE@
VERSION = @VERSION@
XDMAUTH_FALSE = @XDMAUTH_FALSE@
XDMAUTH_TRUE = @XDMAUTH_TRUE@
XDMCP_CFLAGS = @XDMCP_CFLAGS@
XDMCP_FALSE = @XDMCP_FALSE@
XDMCP_LIBS = @XDMCP_LIBS@
XDMCP_TRUE = @XDMCP_TRUE@
XINERAMA_FALSE = @XINERAMA_FALSE@
XINERAMA_TRUE = @XINERAMA_TRUE@
XINPUT_FALSE = @XINPUT_FALSE@
XINPUT_TRUE = @XINPUT_TRUE@
XKB = @XKB@
XLOADABLE_FALSE = @XLOADABLE_FALSE@
XLOADABLE_TRUE = @XLOADABLE_TRUE@
XNESTSERVER_CFLAGS = @XNESTSERVER_CFLAGS@
XNESTSERVER_FALSE = @XNESTSERVER_FALSE@
XNESTSERVER_LIBS = @XNESTSERVER_LIBS@
XNESTSERVER_TRUE = @XNESTSERVER_TRUE@
XNEST_INCS = @XNEST_INCS@
XNEST_LIBS = @XNEST_LIBS@
XORGSERVER_FALSE = @XORGSERVER_FALSE@
XORGSERVER_TRUE = @XORGSERVER_TRUE@
XORG_BUS_SBUS_FALSE = @XORG_BUS_SBUS_FALSE@
XORG_BUS_SBUS_TRUE = @XORG_BUS_SBUS_TRUE@
XORG_CFLAGS = @XORG_CFLAGS@
XORG_CORE_LIBS = @XORG_CORE_LIBS@
XORG_INCS = @XORG_INCS@
XORG_LIBS = @XORG_LIBS@
XORG_OS = @XORG_OS@
XORG_OS_SUBDIR = @XORG_OS_SUBDIR@
XSDLSERVER_FALSE = @XSDLSERVER_FALSE@
XSDLSERVER_TRUE = @XSDLSERVER_TRUE@
XSDL_DIRS = @XSDL_DIRS@
XSDL_INCS = @XSDL_INCS@
XSDL_LIBS = @XSDL_LIBS@
XSERVER_CFLAGS = @XSERVER_CFLAGS@
XSERVER_LIBS = @XSERVER_LIBS@
XTRAP_FALSE = @XTRAP_FALSE@
XTRAP_TRUE = @XTRAP_TRUE@
XV_FALSE = @XV_FALSE@
XV_TRUE = @XV_TRUE@
XWINSERVER_CFLAGS = @XWINSERVER_CFLAGS@
XWINSERVER_FALSE = @XWINSERVER_FALSE@
XWINSERVER_LIBS = @XWINSERVER_LIBS@
XWINSERVER_TRUE = @XWINSERVER_TRUE@
XWIN_INCS = @XWIN_INCS@
XWIN_LIBS = @XWIN_LIBS@
YACC = @YACC@
ac_ct_AR = @ac_ct_AR@
ac_ct_AS = @ac_ct_AS@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_DLLTOOL = @ac_ct_DLLTOOL@
ac_ct_F77 = @ac_ct_F77@
ac_ct_OBJDUMP = @ac_ct_OBJDUMP@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
lib_LIBRARIES = libxkb.a
DDX_SRCS = \
        ddxBeep.c \
        ddxCtrls.c \
        ddxFakeBtn.c \
        ddxFakeMtn.c \
        ddxInit.c \
        ddxKeyClick.c \
        ddxKillSrv.c \
        ddxLEDs.c \
        ddxVT.c \
        ddxLoad.c \
        ddxList.c \
        ddxConfig.c \
        ddxDevBtn.c \
        ddxPrivate.c \
        xf86KillSrv.c \
        xf86VT.c \
        xf86Private.c

DIX_SRCS = \
        xkb.c \
        xkbUtils.c \
        xkbEvents.c \
        xkbAccessX.c \
        xkbSwap.c \
        xkbLEDs.c \
        xkbInit.c \
        xkbActions.c \
        xkbPrKeyEv.c

# this should be replaced by a common library or something, ideally -d
XKBFILE_SRCS = \
        maprules.c \
        xkmread.c \
        xkbtext.c \
        xkbfmisc.c \
        xkberrs.c \
        xkbconfig.c \
        xkbout.c

X11_SRCS = \
        XKBMisc.c \
        XKBAlloc.c \
        XKBGAlloc.c \
        XKBMAlloc.c

XI_SRCS = xkbPrOtherEv.c
libxkb_a_SOURCES = $(DDX_SRCS) $(DIX_SRCS) $(XI_SRCS) $(XKBFILE_SRCS) \
                   $(X11_SRCS)


AM_CFLAGS = -DXKB_DFLT_DISABLED=0 -DXKB_IN_SERVER \
            -DXKB_BASE_DIRECTORY=\"$(LIBDIR)/xkb\" -DXKB

INCLUDES = $(XORG_INCS) -I$(srcdir)/../mi -I$(srcdir)/../hw/xorg/common \
           -I$(srcdir)/../hw/xorg/include -I$(srcdir)/../hw/xorg/os-support/bus

subdir = xkb
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/include/config.h
CONFIG_CLEAN_FILES =
LIBRARIES = $(lib_LIBRARIES)

libxkb_a_AR = $(AR) cru
libxkb_a_LIBADD =
am__objects_1 = ddxBeep.$(OBJEXT) ddxCtrls.$(OBJEXT) \
	ddxFakeBtn.$(OBJEXT) ddxFakeMtn.$(OBJEXT) ddxInit.$(OBJEXT) \
	ddxKeyClick.$(OBJEXT) ddxKillSrv.$(OBJEXT) ddxLEDs.$(OBJEXT) \
	ddxVT.$(OBJEXT) ddxLoad.$(OBJEXT) ddxList.$(OBJEXT) \
	ddxConfig.$(OBJEXT) ddxDevBtn.$(OBJEXT) ddxPrivate.$(OBJEXT) \
	xf86KillSrv.$(OBJEXT) xf86VT.$(OBJEXT) xf86Private.$(OBJEXT)
am__objects_2 = xkb.$(OBJEXT) xkbUtils.$(OBJEXT) xkbEvents.$(OBJEXT) \
	xkbAccessX.$(OBJEXT) xkbSwap.$(OBJEXT) xkbLEDs.$(OBJEXT) \
	xkbInit.$(OBJEXT) xkbActions.$(OBJEXT) xkbPrKeyEv.$(OBJEXT)
am__objects_3 = xkbPrOtherEv.$(OBJEXT)
am__objects_4 = maprules.$(OBJEXT) xkmread.$(OBJEXT) xkbtext.$(OBJEXT) \
	xkbfmisc.$(OBJEXT) xkberrs.$(OBJEXT) xkbconfig.$(OBJEXT) \
	xkbout.$(OBJEXT)
am__objects_5 = XKBMisc.$(OBJEXT) XKBAlloc.$(OBJEXT) XKBGAlloc.$(OBJEXT) \
	XKBMAlloc.$(OBJEXT)
am_libxkb_a_OBJECTS = $(am__objects_1) $(am__objects_2) $(am__objects_3) \
	$(am__objects_4) $(am__objects_5)
libxkb_a_OBJECTS = $(am_libxkb_a_OBJECTS)

DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)/include
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@AMDEP_TRUE at DEP_FILES = ./$(DEPDIR)/XKBAlloc.Po ./$(DEPDIR)/XKBGAlloc.Po \
@AMDEP_TRUE@	./$(DEPDIR)/XKBMAlloc.Po ./$(DEPDIR)/XKBMisc.Po \
@AMDEP_TRUE@	./$(DEPDIR)/ddxBeep.Po ./$(DEPDIR)/ddxConfig.Po \
@AMDEP_TRUE@	./$(DEPDIR)/ddxCtrls.Po ./$(DEPDIR)/ddxDevBtn.Po \
@AMDEP_TRUE@	./$(DEPDIR)/ddxFakeBtn.Po ./$(DEPDIR)/ddxFakeMtn.Po \
@AMDEP_TRUE@	./$(DEPDIR)/ddxInit.Po ./$(DEPDIR)/ddxKeyClick.Po \
@AMDEP_TRUE@	./$(DEPDIR)/ddxKillSrv.Po ./$(DEPDIR)/ddxLEDs.Po \
@AMDEP_TRUE@	./$(DEPDIR)/ddxList.Po ./$(DEPDIR)/ddxLoad.Po \
@AMDEP_TRUE@	./$(DEPDIR)/ddxPrivate.Po ./$(DEPDIR)/ddxVT.Po \
@AMDEP_TRUE@	./$(DEPDIR)/maprules.Po ./$(DEPDIR)/xf86KillSrv.Po \
@AMDEP_TRUE@	./$(DEPDIR)/xf86Private.Po ./$(DEPDIR)/xf86VT.Po \
@AMDEP_TRUE@	./$(DEPDIR)/xkb.Po ./$(DEPDIR)/xkbAccessX.Po \
@AMDEP_TRUE@	./$(DEPDIR)/xkbActions.Po ./$(DEPDIR)/xkbEvents.Po \
@AMDEP_TRUE@	./$(DEPDIR)/xkbInit.Po ./$(DEPDIR)/xkbLEDs.Po \
@AMDEP_TRUE@	./$(DEPDIR)/xkbPrKeyEv.Po \
@AMDEP_TRUE@	./$(DEPDIR)/xkbPrOtherEv.Po ./$(DEPDIR)/xkbSwap.Po \
@AMDEP_TRUE@	./$(DEPDIR)/xkbUtils.Po ./$(DEPDIR)/xkbconfig.Po \
@AMDEP_TRUE@	./$(DEPDIR)/xkberrs.Po ./$(DEPDIR)/xkbfmisc.Po \
@AMDEP_TRUE@	./$(DEPDIR)/xkbout.Po ./$(DEPDIR)/xkbtext.Po \
@AMDEP_TRUE@	./$(DEPDIR)/xkmread.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
	$(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
	$(AM_LDFLAGS) $(LDFLAGS) -o $@
DIST_SOURCES = $(libxkb_a_SOURCES)
DIST_COMMON = $(srcdir)/Makefile.in Makefile.am
SOURCES = $(libxkb_a_SOURCES)

all: all-am

.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am  $(top_srcdir)/configure.ac $(ACLOCAL_M4)
	cd $(top_srcdir) && \
	  $(AUTOMAKE) --gnu  xkb/Makefile
Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in  $(top_builddir)/config.status
	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
libLIBRARIES_INSTALL = $(INSTALL_DATA)
install-libLIBRARIES: $(lib_LIBRARIES)
	@$(NORMAL_INSTALL)
	$(mkinstalldirs) $(DESTDIR)$(libdir)
	@list='$(lib_LIBRARIES)'; for p in $$list; do \
	  if test -f $$p; then \
	    f="`echo $$p | sed -e 's|^.*/||'`"; \
	    echo " $(libLIBRARIES_INSTALL) $$p $(DESTDIR)$(libdir)/$$f"; \
	    $(libLIBRARIES_INSTALL) $$p $(DESTDIR)$(libdir)/$$f; \
	  else :; fi; \
	done
	@$(POST_INSTALL)
	@list='$(lib_LIBRARIES)'; for p in $$list; do \
	  if test -f $$p; then \
	    p="`echo $$p | sed -e 's|^.*/||'`"; \
	    echo " $(RANLIB) $(DESTDIR)$(libdir)/$$p"; \
	    $(RANLIB) $(DESTDIR)$(libdir)/$$p; \
	  else :; fi; \
	done

uninstall-libLIBRARIES:
	@$(NORMAL_UNINSTALL)
	@list='$(lib_LIBRARIES)'; for p in $$list; do \
	  p="`echo $$p | sed -e 's|^.*/||'`"; \
	  echo " rm -f $(DESTDIR)$(libdir)/$$p"; \
	  rm -f $(DESTDIR)$(libdir)/$$p; \
	done

clean-libLIBRARIES:
	-test -z "$(lib_LIBRARIES)" || rm -f $(lib_LIBRARIES)
libxkb.a: $(libxkb_a_OBJECTS) $(libxkb_a_DEPENDENCIES) 
	-rm -f libxkb.a
	$(libxkb_a_AR) libxkb.a $(libxkb_a_OBJECTS) $(libxkb_a_LIBADD)
	$(RANLIB) libxkb.a

mostlyclean-compile:
	-rm -f *.$(OBJEXT) core *.core

distclean-compile:
	-rm -f *.tab.c

@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/XKBAlloc.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/XKBGAlloc.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/XKBMAlloc.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/XKBMisc.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxBeep.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxConfig.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxCtrls.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxDevBtn.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxFakeBtn.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxFakeMtn.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxInit.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxKeyClick.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxKillSrv.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxLEDs.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxList.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxLoad.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxPrivate.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/ddxVT.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/maprules.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xf86KillSrv.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xf86Private.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xf86VT.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkb.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbAccessX.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbActions.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbEvents.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbInit.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbLEDs.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbPrKeyEv.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbPrOtherEv.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbSwap.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbUtils.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbconfig.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkberrs.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbfmisc.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbout.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkbtext.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/xkmread.Po at am__quote@

.c.o:
@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@	  -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@	fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@	$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<

.c.obj:
@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@	  -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@	fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@	$(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`

.c.lo:
@am__fastdepCC_TRUE@	if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@	  -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; \
@am__fastdepCC_TRUE@	else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@	fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<

mostlyclean-libtool:
	-rm -f *.lo

clean-libtool:
	-rm -rf .libs _libs

distclean-libtool:
	-rm -f libtool
uninstall-info-am:

ETAGS = etags
ETAGSFLAGS =

CTAGS = ctags
CTAGSFLAGS =

tags: TAGS

ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	mkid -fID $$unique

TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
		$(TAGS_FILES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	test -z "$(ETAGS_ARGS)$$tags$$unique" \
	  || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
	     $$tags $$unique

ctags: CTAGS
CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
		$(TAGS_FILES) $(LISP)
	tags=; \
	here=`pwd`; \
	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
	unique=`for i in $$list; do \
	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
	  done | \
	  $(AWK) '    { files[$$0] = 1; } \
	       END { for (i in files) print i; }'`; \
	test -z "$(CTAGS_ARGS)$$tags$$unique" \
	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
	     $$tags $$unique

GTAGS:
	here=`$(am__cd) $(top_builddir) && pwd` \
	  && cd $(top_srcdir) \
	  && gtags -i $(GTAGS_ARGS) $$here

distclean-tags:
	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)

top_distdir = ..
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)

distdir: $(DISTFILES)
	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
	list='$(DISTFILES)'; for file in $$list; do \
	  case $$file in \
	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
	  esac; \
	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
	    dir="/$$dir"; \
	    $(mkinstalldirs) "$(distdir)$$dir"; \
	  else \
	    dir=''; \
	  fi; \
	  if test -d $$d/$$file; then \
	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
	    fi; \
	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
	  else \
	    test -f $(distdir)/$$file \
	    || cp -p $$d/$$file $(distdir)/$$file \
	    || exit 1; \
	  fi; \
	done
check-am: all-am
check: check-am
all-am: Makefile $(LIBRARIES)

installdirs:
	$(mkinstalldirs) $(DESTDIR)$(libdir)
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am

install-am: all-am
	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am

installcheck: installcheck-am
install-strip:
	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
	  `test -z '$(STRIP)' || \
	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:

clean-generic:

distclean-generic:
	-rm -f $(CONFIG_CLEAN_FILES)

maintainer-clean-generic:
	@echo "This command is intended for maintainers to use"
	@echo "it deletes files that may require special tools to rebuild."
clean: clean-am

clean-am: clean-generic clean-libLIBRARIES clean-libtool mostlyclean-am

distclean: distclean-am
	-rm -rf ./$(DEPDIR)
	-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
	distclean-libtool distclean-tags

dvi: dvi-am

dvi-am:

info: info-am

info-am:

install-data-am:

install-exec-am: install-libLIBRARIES

install-info: install-info-am

install-man:

installcheck-am:

maintainer-clean: maintainer-clean-am
	-rm -rf ./$(DEPDIR)
	-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic

mostlyclean: mostlyclean-am

mostlyclean-am: mostlyclean-compile mostlyclean-generic \
	mostlyclean-libtool

pdf: pdf-am

pdf-am:

ps: ps-am

ps-am:

uninstall-am: uninstall-info-am uninstall-libLIBRARIES

.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
	clean-libLIBRARIES clean-libtool ctags distclean \
	distclean-compile distclean-generic distclean-libtool \
	distclean-tags distdir dvi dvi-am info info-am install \
	install-am install-data install-data-am install-exec \
	install-exec-am install-info install-info-am \
	install-libLIBRARIES install-man install-strip installcheck \
	installcheck-am installdirs maintainer-clean \
	maintainer-clean-generic mostlyclean mostlyclean-compile \
	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
	tags uninstall uninstall-am uninstall-info-am \
	uninstall-libLIBRARIES


xf86%.c:
	echo "#define XF86DDXACTIONS" > $@
	echo "#include \"$(srcdir)/ddx$*.c\"" >> $@
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

--- NEW FILE: XKBAlloc.c ---
/* $Xorg: XKBAlloc.c,v 1.4 2000/08/17 19:44:59 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/lib/X11/XKBAlloc.c,v 3.4 1998/08/20 08:55:49 dawes Exp $ */

#ifndef XKB_IN_SERVER

#include <stdio.h>
#define NEED_REPLIES
#define NEED_EVENTS
#include <X11/Xlibint.h>
#include <X11/extensions/XKBlibint.h>
#include <X11/extensions/XKBgeom.h>
#include <X11/extensions/XKBproto.h>

#else 

#include <stdio.h>
#include <X11/X.h>
#define	NEED_EVENTS
#define	NEED_REPLIES
#include <X11/Xproto.h>
#include "misc.h"
#include "inputstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XKBgeom.h>

#endif /* XKB_IN_SERVER */

/***===================================================================***/

/*ARGSUSED*/
Status
XkbAllocCompatMap(XkbDescPtr xkb,unsigned which,unsigned nSI)
{
XkbCompatMapPtr	compat;
XkbSymInterpretRec *prev_interpret;

    if (!xkb)
	return BadMatch;
    if (xkb->compat) {
	if (xkb->compat->size_si>=nSI)
	    return Success;
	compat= xkb->compat;
	compat->size_si= nSI;
	if (compat->sym_interpret==NULL)
	    compat->num_si= 0;
	prev_interpret = compat->sym_interpret;
	compat->sym_interpret= _XkbTypedRealloc(compat->sym_interpret,
						     nSI,XkbSymInterpretRec);
	if (compat->sym_interpret==NULL) {
	    _XkbFree(prev_interpret);
	    compat->size_si= compat->num_si= 0;
	    return BadAlloc;
	}
	if (compat->num_si!=0) {
	    _XkbClearElems(compat->sym_interpret,compat->num_si,
					compat->size_si-1,XkbSymInterpretRec);
	}
	return Success;
    }
    compat= _XkbTypedCalloc(1,XkbCompatMapRec);
    if (compat==NULL)
	return BadAlloc;
    if (nSI>0) {
	compat->sym_interpret= _XkbTypedCalloc(nSI,XkbSymInterpretRec);
	if (!compat->sym_interpret) {
	    _XkbFree(compat);
	    return BadAlloc;
	}
    }
    compat->size_si= nSI;
    compat->num_si= 0;
    bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec));
    xkb->compat= compat;
    return Success;
}


void
XkbFreeCompatMap(XkbDescPtr xkb,unsigned which,Bool freeMap)
{
register XkbCompatMapPtr compat;

    if ((xkb==NULL)||(xkb->compat==NULL))
	return;
    compat= xkb->compat;
    if (freeMap)
	which= XkbAllCompatMask;
    if (which&XkbGroupCompatMask)
	bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec));
    if (which&XkbSymInterpMask) {
	if ((compat->sym_interpret)&&(compat->size_si>0))
	    _XkbFree(compat->sym_interpret);
	compat->size_si= compat->num_si= 0;
	compat->sym_interpret= NULL;
    }
    if (freeMap) {
	_XkbFree(compat);
	xkb->compat= NULL;
    }
    return;
}

/***===================================================================***/

Status
XkbAllocNames(XkbDescPtr xkb,unsigned which,int nTotalRG,int nTotalAliases)
{
XkbNamesPtr	names;

    if (xkb==NULL)
	return BadMatch;
    if (xkb->names==NULL) {
	xkb->names = _XkbTypedCalloc(1,XkbNamesRec);
	if (xkb->names==NULL)
	    return BadAlloc;
    }
    names= xkb->names;
    if ((which&XkbKTLevelNamesMask)&&(xkb->map!=NULL)&&(xkb->map->types!=NULL)){
	register int	i;
	XkbKeyTypePtr	type;

	type= xkb->map->types;
	for (i=0;i<xkb->map->num_types;i++,type++) {
	    if (type->level_names==NULL) {
		type->level_names= _XkbTypedCalloc(type->num_levels,Atom);
		if (type->level_names==NULL)
		    return BadAlloc;
	    }
	}
    }
    if ((which&XkbKeyNamesMask)&&(names->keys==NULL)) {
	if ((!XkbIsLegalKeycode(xkb->min_key_code))||
	    (!XkbIsLegalKeycode(xkb->max_key_code))||
	    (xkb->max_key_code<xkb->min_key_code)) 
	    return BadValue;
	names->keys= _XkbTypedCalloc((xkb->max_key_code+1),XkbKeyNameRec);
	if (names->keys==NULL)
	    return BadAlloc;
    }
    if ((which&XkbKeyAliasesMask)&&(nTotalAliases>0)) {
	if (names->key_aliases==NULL) {
	    names->key_aliases= _XkbTypedCalloc(nTotalAliases,XkbKeyAliasRec);
	}
	else if (nTotalAliases>names->num_key_aliases) {
	    XkbKeyAliasRec *prev_aliases = names->key_aliases;

	    names->key_aliases= _XkbTypedRealloc(names->key_aliases,
						nTotalAliases,XkbKeyAliasRec);
	    if (names->key_aliases!=NULL) {
		_XkbClearElems(names->key_aliases,names->num_key_aliases,
						nTotalAliases-1,XkbKeyAliasRec);
	    } else {
		_XkbFree(prev_aliases);
	    }
	}
	if (names->key_aliases==NULL) {
	    names->num_key_aliases= 0;
	    return BadAlloc;
	}
	names->num_key_aliases= nTotalAliases;
    }
    if ((which&XkbRGNamesMask)&&(nTotalRG>0)) {
	if (names->radio_groups==NULL) {
	    names->radio_groups= _XkbTypedCalloc(nTotalRG,Atom);
	}
	else if (nTotalRG>names->num_rg) {
	    Atom *prev_radio_groups = names->radio_groups;

	    names->radio_groups= _XkbTypedRealloc(names->radio_groups,nTotalRG,
									Atom);
	    if (names->radio_groups!=NULL) {
		_XkbClearElems(names->radio_groups,names->num_rg,nTotalRG-1,
									Atom);
	    } else {
		_XkbFree(prev_radio_groups);
	    }
	}
	if (names->radio_groups==NULL)
	    return BadAlloc;
	names->num_rg= nTotalRG;
    }
    return Success;
}

void
XkbFreeNames(XkbDescPtr xkb,unsigned which,Bool freeMap)
{
XkbNamesPtr	names;

    if ((xkb==NULL)||(xkb->names==NULL))
	return;
    names= xkb->names;
    if (freeMap)
	which= XkbAllNamesMask; 
    if (which&XkbKTLevelNamesMask) {
	XkbClientMapPtr	map= xkb->map;
	if ((map!=NULL)&&(map->types!=NULL)) {
	    register int 		i;
	    register XkbKeyTypePtr	type;
	    type= map->types;
	    for (i=0;i<map->num_types;i++,type++) {
		if (type->level_names!=NULL) {
		    _XkbFree(type->level_names);
		    type->level_names= NULL;
		}
	    }
	}
    }
    if ((which&XkbKeyNamesMask)&&(names->keys!=NULL)) {
	_XkbFree(names->keys);
	names->keys= NULL;
	names->num_keys= 0;
    }
    if ((which&XkbKeyAliasesMask)&&(names->key_aliases)){
	_XkbFree(names->key_aliases);
	names->key_aliases=NULL;
	names->num_key_aliases=0;
    }
    if ((which&XkbRGNamesMask)&&(names->radio_groups)) {
	_XkbFree(names->radio_groups);
	names->radio_groups= NULL;
	names->num_rg= 0;
    }
    if (freeMap) {
	_XkbFree(names);
	xkb->names= NULL;
    }
    return;
}

/***===================================================================***/

Status
XkbAllocControls(XkbDescPtr xkb,unsigned which)
{
    if (xkb==NULL)
	return BadMatch;

    if (xkb->ctrls==NULL) {
	xkb->ctrls= _XkbTypedCalloc(1,XkbControlsRec);
	if (!xkb->ctrls)
	    return BadAlloc;
    }
    return Success;
}

void
XkbFreeControls(XkbDescPtr xkb,unsigned which,Bool freeMap)
{
    if (freeMap && (xkb!=NULL) && (xkb->ctrls!=NULL)) {
	_XkbFree(xkb->ctrls);
	xkb->ctrls= NULL;
    }
    return;
}

/***===================================================================***/

Status 
XkbAllocIndicatorMaps(XkbDescPtr xkb)
{
    if (xkb==NULL)
	return BadMatch;
    if (xkb->indicators==NULL) {
	xkb->indicators= _XkbTypedCalloc(1,XkbIndicatorRec);
	if (!xkb->indicators)
	    return BadAlloc;
    }
    return Success;
}

void
XkbFreeIndicatorMaps(XkbDescPtr xkb)
{
    if ((xkb!=NULL)&&(xkb->indicators!=NULL)) {
	_XkbFree(xkb->indicators);
	xkb->indicators= NULL;
    }
    return;
}

/***====================================================================***/

XkbDescRec	*
XkbAllocKeyboard(void)
{
XkbDescRec *xkb;

    xkb = _XkbTypedCalloc(1,XkbDescRec);
    if (xkb)
	xkb->device_spec= XkbUseCoreKbd;
    return xkb;
}

void
XkbFreeKeyboard(XkbDescPtr xkb,unsigned which,Bool freeAll)
{
    if (xkb==NULL)
	return;
    if (freeAll)
	which= XkbAllComponentsMask;
    if (which&XkbClientMapMask)
	XkbFreeClientMap(xkb,XkbAllClientInfoMask,True);
    if (which&XkbServerMapMask)
	XkbFreeServerMap(xkb,XkbAllServerInfoMask,True);
    if (which&XkbCompatMapMask)
	XkbFreeCompatMap(xkb,XkbAllCompatMask,True);
    if (which&XkbIndicatorMapMask)
	XkbFreeIndicatorMaps(xkb);
    if (which&XkbNamesMask)
	XkbFreeNames(xkb,XkbAllNamesMask,True);
    if ((which&XkbGeometryMask) && (xkb->geom!=NULL))
	XkbFreeGeometry(xkb->geom,XkbGeomAllMask,True);
    if (which&XkbControlsMask)
	XkbFreeControls(xkb,XkbAllControlsMask,True);
    if (freeAll)
	_XkbFree(xkb);
    return;
}

/***====================================================================***/

XkbDeviceLedInfoPtr
XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi,unsigned ledClass,unsigned ledId)
{
XkbDeviceLedInfoPtr	devli;
register int		i;

    if ((!devi)||(!XkbSingleXIClass(ledClass))||(!XkbSingleXIId(ledId)))
	return NULL;
    for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) {
	if ((devli->led_class==ledClass)&&(devli->led_id==ledId))
	    return devli;
    }
    if (devi->num_leds>=devi->sz_leds) {
	XkbDeviceLedInfoRec *prev_leds = devi->leds;
	
	if (devi->sz_leds>0)	devi->sz_leds*= 2;
	else			devi->sz_leds= 1;
	devi->leds= _XkbTypedRealloc(devi->leds,devi->sz_leds,
							XkbDeviceLedInfoRec);
	if (!devi->leds) {
	    _XkbFree(prev_leds);
	    devi->sz_leds= devi->num_leds= 0;
	    return NULL;
	}
	i= devi->num_leds;
	for (devli=&devi->leds[i];i<devi->sz_leds;i++,devli++) {
	    bzero(devli,sizeof(XkbDeviceLedInfoRec));
	    devli->led_class= XkbXINone;
	    devli->led_id= XkbXINone;
	}
    }
    devli= &devi->leds[devi->num_leds++];
    bzero(devli,sizeof(XkbDeviceLedInfoRec));
    devli->led_class= ledClass;
    devli->led_id= ledId;
    return devli;
}

Status
XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi,unsigned newTotal)
{
    XkbAction *prev_btn_acts;

    if ((!devi)||(newTotal>255))
	return BadValue;
    if ((devi->btn_acts!=NULL)&&(newTotal==devi->num_btns))
	return Success;
    if (newTotal==0) {
	if (devi->btn_acts!=NULL) {
	    _XkbFree(devi->btn_acts);
	    devi->btn_acts= NULL;
	}
	devi->num_btns= 0;
	return Success;
    }
    prev_btn_acts = devi->btn_acts;
    devi->btn_acts= _XkbTypedRealloc(devi->btn_acts,newTotal,XkbAction);
    if (devi->btn_acts==NULL) {
	_XkbFree(prev_btn_acts);
	devi->num_btns= 0;
	return BadAlloc;
    }
    if (newTotal>devi->num_btns) {
	XkbAction *act;
	act= &devi->btn_acts[devi->num_btns];
	bzero((char *)act,(newTotal-devi->num_btns)*sizeof(XkbAction));
    }
    devi->num_btns= newTotal;
    return Success;
}

XkbDeviceInfoPtr
XkbAllocDeviceInfo(unsigned deviceSpec,unsigned nButtons,unsigned szLeds)
{
XkbDeviceInfoPtr	devi;

    devi= _XkbTypedCalloc(1,XkbDeviceInfoRec);
    if (devi!=NULL) {
	devi->device_spec= deviceSpec;
	devi->has_own_state= False;
	devi->num_btns= 0;
	devi->btn_acts= NULL;
	if (nButtons>0) {
	    devi->num_btns= nButtons;
	    devi->btn_acts= _XkbTypedCalloc(nButtons,XkbAction);
	    if (!devi->btn_acts) {
		_XkbFree(devi);
		return NULL;
	    }
	}
	devi->dflt_kbd_fb= XkbXINone;
	devi->dflt_led_fb= XkbXINone;
	devi->num_leds= 0;
	devi->sz_leds= 0;
	devi->leds= NULL;
	if (szLeds>0) {
	    devi->sz_leds= szLeds;
	    devi->leds= _XkbTypedCalloc(szLeds,XkbDeviceLedInfoRec);
	    if (!devi->leds) {
		if (devi->btn_acts)
		    _XkbFree(devi->btn_acts);
		_XkbFree(devi);
		return NULL;
	    }
	}
    }
    return devi;
}


void 
XkbFreeDeviceInfo(XkbDeviceInfoPtr devi,unsigned which,Bool freeDevI)
{
    if (devi) {
	if (freeDevI) {
	    which= XkbXI_AllDeviceFeaturesMask;
	    if (devi->name) {
		_XkbFree(devi->name);
		devi->name= NULL;
	    }
	}
	if ((which&XkbXI_ButtonActionsMask)&&(devi->btn_acts)) {
	    _XkbFree(devi->btn_acts);
	    devi->num_btns= 0;
	    devi->btn_acts= NULL;
	}
	if ((which&XkbXI_IndicatorsMask)&&(devi->leds)) {
	    register int i;
	    if ((which&XkbXI_IndicatorsMask)==XkbXI_IndicatorsMask) {
		_XkbFree(devi->leds);
		devi->sz_leds= devi->num_leds= 0;
		devi->leds= NULL;
	    }
	    else {
		XkbDeviceLedInfoPtr	devli;
		for (i=0,devli=devi->leds;i<devi->num_leds;i++,devli++) {
		    if (which&XkbXI_IndicatorMapsMask)
			 bzero((char *)&devli->maps[0],sizeof(devli->maps));
		    else bzero((char *)&devli->names[0],sizeof(devli->names));
		}
	    }
	}
	if (freeDevI)
	    _XkbFree(devi);
    }
    return;
}

--- NEW FILE: XKBGAlloc.c ---
/* $Xorg: XKBGAlloc.c,v 1.3 2000/08/17 19:45:01 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...976 lines suppressed...]
	return NULL;

    for (i=0,overlay=section->overlays;i<section->num_overlays;i++,overlay++) {
	if (overlay->name==name) {
	    if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success))
		return NULL;
	    return overlay;
	}
    }
    if ((section->num_overlays>=section->sz_overlays)&&
				(_XkbAllocOverlays(section,1)!=Success))
	return NULL;
    overlay= &section->overlays[section->num_overlays];
    if ((sz_rows>0)&&(_XkbAllocOverlayRows(overlay,sz_rows)!=Success))
	return NULL;
    overlay->name= name;
    overlay->section_under= section;
    section->num_overlays++;
    return overlay;
}

--- NEW FILE: XKBMAlloc.c ---
/* $Xorg: XKBMAlloc.c,v 1.4 2000/08/17 19:45:02 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/lib/X11/XKBMAlloc.c,v 3.10 1998/10/03 08:41:27 dawes Exp $ */

#ifndef XKB_IN_SERVER

#include <stdio.h>
#define NEED_REPLIES
#define NEED_EVENTS
#include "Xlibint.h"
#include <X11/extensions/XKBproto.h>
#include <X11/keysym.h>
#include "XKBlibint.h"

#else 

#include <stdio.h>
#include <X11/X.h>
#define	NEED_EVENTS
#define	NEED_REPLIES
#include <X11/Xproto.h>
#include "misc.h"
#include "inputstr.h"
#include <X11/keysym.h>
#define	XKBSRV_NEED_FILE_FUNCS
#include <X11/extensions/XKBsrv.h>

#endif /* XKB_IN_SERVER */

/***====================================================================***/

Status
XkbAllocClientMap(XkbDescPtr xkb,unsigned which,unsigned nTotalTypes)
{
register int	i;
XkbClientMapPtr map;

    if ((xkb==NULL)||((nTotalTypes>0)&&(nTotalTypes<XkbNumRequiredTypes)))
	return BadValue;
    if ((which&XkbKeySymsMask)&&
	((!XkbIsLegalKeycode(xkb->min_key_code))||
	 (!XkbIsLegalKeycode(xkb->max_key_code))||
	 (xkb->max_key_code<xkb->min_key_code))) {
#ifdef DEBUG
fprintf(stderr,"bad keycode (%d,%d) in XkbAllocClientMap\n",
				xkb->min_key_code,xkb->max_key_code);
#endif
	return BadValue;
    }

    if (xkb->map==NULL) {
	map= _XkbTypedCalloc(1,XkbClientMapRec);
	if (map==NULL)
	    return BadAlloc;
	xkb->map= map;
    }
    else map= xkb->map;

    if ((which&XkbKeyTypesMask)&&(nTotalTypes>0)) {
	if (map->types==NULL) {
	    map->types= _XkbTypedCalloc(nTotalTypes,XkbKeyTypeRec);
	    if (map->types==NULL)
		return BadAlloc;
	    map->num_types= 0;
	    map->size_types= nTotalTypes;
	}
	else if (map->size_types<nTotalTypes) {
	    XkbKeyTypeRec *prev_types = map->types;

	    map->types= _XkbTypedRealloc(map->types,nTotalTypes,XkbKeyTypeRec);
	    if (map->types==NULL) {
		_XkbFree(prev_types);
		map->num_types= map->size_types= 0;
		return BadAlloc;
	    }
	    map->size_types= nTotalTypes;
	    bzero(&map->types[map->num_types], 
		  ((map->size_types-map->num_types)*sizeof(XkbKeyTypeRec)));
	}
    }
    if (which&XkbKeySymsMask) {
	int nKeys= XkbNumKeys(xkb);
	if (map->syms==NULL) {
	    map->size_syms= (nKeys*15)/10;
	    map->syms= _XkbTypedCalloc(map->size_syms,KeySym);
	    if (!map->syms) {
		map->size_syms= 0;
		return BadAlloc;
	    }
	    map->num_syms= 1;
	    map->syms[0]= NoSymbol;
	}
	if (map->key_sym_map==NULL) {
	    i= xkb->max_key_code+1;
	    map->key_sym_map= _XkbTypedCalloc(i,XkbSymMapRec);
	    if (map->key_sym_map==NULL)
		return BadAlloc;
	}
    }
    if (which&XkbModifierMapMask) {
	if ((!XkbIsLegalKeycode(xkb->min_key_code))||
	    (!XkbIsLegalKeycode(xkb->max_key_code))||
	    (xkb->max_key_code<xkb->min_key_code))
	    return BadMatch;
	if (map->modmap==NULL) {
	    i= xkb->max_key_code+1;
	    map->modmap= _XkbTypedCalloc(i,unsigned char);
	    if (map->modmap==NULL)
		return BadAlloc;
	}
    }
    return Success;
}

Status
XkbAllocServerMap(XkbDescPtr xkb,unsigned which,unsigned nNewActions)
{
register int	i;
XkbServerMapPtr map;

    if (xkb==NULL)
	return BadMatch;
    if (xkb->server==NULL) {
	map= _XkbTypedCalloc(1,XkbServerMapRec);
	if (map==NULL)
	    return BadAlloc;
	for (i=0;i<XkbNumVirtualMods;i++) {
	    map->vmods[i]= XkbNoModifierMask;
	}
	xkb->server= map;
    }
    else map= xkb->server;
    if (which&XkbExplicitComponentsMask) {
	if ((!XkbIsLegalKeycode(xkb->min_key_code))||
	    (!XkbIsLegalKeycode(xkb->max_key_code))||
	    (xkb->max_key_code<xkb->min_key_code))
	    return BadMatch;
	if (map->explicit==NULL) {
	    i= xkb->max_key_code+1;
	    map->explicit= _XkbTypedCalloc(i,unsigned char);
	    if (map->explicit==NULL)
		return BadAlloc;
	}
    }
    if (which&XkbKeyActionsMask) {
	if ((!XkbIsLegalKeycode(xkb->min_key_code))||
	    (!XkbIsLegalKeycode(xkb->max_key_code))||
	    (xkb->max_key_code<xkb->min_key_code))
	    return BadMatch;
        if (nNewActions<1)
	    nNewActions= 1;
	if (map->acts==NULL) {
	    map->acts= _XkbTypedCalloc((nNewActions+1),XkbAction);
	    if (map->acts==NULL)
		return BadAlloc;
	    map->num_acts= 1;
	    map->size_acts= nNewActions+1;
	}
	else if ((map->size_acts-map->num_acts)<nNewActions) {
	    unsigned need;
	    XkbAction *prev_acts = map->acts;
	    need= map->num_acts+nNewActions;
	    map->acts= _XkbTypedRealloc(map->acts,need,XkbAction);
	    if (map->acts==NULL) {
		_XkbFree(prev_acts);
	        map->num_acts= map->size_acts= 0;
	        return BadAlloc;
	    }
	    map->size_acts= need;
	    bzero(&map->acts[map->num_acts], 
		    ((map->size_acts-map->num_acts)*sizeof(XkbAction)));
	}
	if (map->key_acts==NULL) {
	    i= xkb->max_key_code+1;
	    map->key_acts= _XkbTypedCalloc(i,unsigned short);
	    if (map->key_acts==NULL)
		return BadAlloc;
	}
    }
    if (which&XkbKeyBehaviorsMask) {
	if ((!XkbIsLegalKeycode(xkb->min_key_code))||
	    (!XkbIsLegalKeycode(xkb->max_key_code))||
	    (xkb->max_key_code<xkb->min_key_code))
	    return BadMatch;
	if (map->behaviors==NULL) {
	    i= xkb->max_key_code+1;
	    map->behaviors= _XkbTypedCalloc(i,XkbBehavior);
	    if (map->behaviors==NULL)
		return BadAlloc;
	}
    }
    if (which&XkbVirtualModMapMask) {
	if ((!XkbIsLegalKeycode(xkb->min_key_code))||
	    (!XkbIsLegalKeycode(xkb->max_key_code))||
	    (xkb->max_key_code<xkb->min_key_code))
	    return BadMatch;
	if (map->vmodmap==NULL) {
	    i= xkb->max_key_code+1;
	    map->vmodmap= _XkbTypedCalloc(i,unsigned short);
	    if (map->vmodmap==NULL)
		return BadAlloc;
	}
    }
    return Success;
}

/***====================================================================***/

Status
XkbCopyKeyType(XkbKeyTypePtr from,XkbKeyTypePtr into)
{
    if ((!from)||(!into))
	return BadMatch;
    if (into->map) {
	_XkbFree(into->map);
	into->map= NULL;
    }
    if (into->preserve) {
	_XkbFree(into->preserve);
	into->preserve= NULL;
    }
    if (into->level_names) {
	_XkbFree(into->level_names);
	into->level_names= NULL;
    }
    *into= *from;
    if ((from->map)&&(into->map_count>0)) {
	into->map= _XkbTypedCalloc(into->map_count,XkbKTMapEntryRec);
	if (!into->map)
	    return BadAlloc;
	memcpy(into->map,from->map,into->map_count*sizeof(XkbKTMapEntryRec));
    }
    if ((from->preserve)&&(into->map_count>0)) {
	into->preserve= _XkbTypedCalloc(into->map_count,XkbModsRec);
	if (!into->preserve)
	    return BadAlloc;
	memcpy(into->preserve,from->preserve,
				into->map_count*sizeof(XkbModsRec));
    }
    if ((from->level_names)&&(into->num_levels>0)) {
	into->level_names= _XkbTypedCalloc(into->num_levels,Atom);
	if (!into->level_names)
	    return BadAlloc;
	memcpy(into->level_names,from->level_names,
				 into->num_levels*sizeof(Atom));
    }
    return Success;
}

Status
XkbCopyKeyTypes(XkbKeyTypePtr from,XkbKeyTypePtr into,int num_types)
{
register int i,rtrn;

    if ((!from)||(!into)||(num_types<0))
	return BadMatch;
    for (i=0;i<num_types;i++) {
	if ((rtrn= XkbCopyKeyType(from++,into++))!=Success)
	    return rtrn;
    }
    return Success;
}

XkbKeyTypePtr
XkbAddKeyType(	XkbDescPtr	xkb,
		Atom 		name,
		int 		map_count,
		Bool 		want_preserve,
		int		num_lvls)
{
register int 	i;
unsigned	tmp;
XkbKeyTypePtr	type;
XkbClientMapPtr	map;

    if ((!xkb)||(num_lvls<1))
	return NULL;
    map= xkb->map;
    if ((map)&&(map->types)) {
	for (i=0;i<map->num_types;i++) {
	    if (map->types[i].name==name) {
		Status status;
		status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls);
		return (status==Success?&map->types[i]:NULL);
	    }
	}
    }
    if ((!map)||(!map->types)||(!map->num_types<XkbNumRequiredTypes)) {
	tmp= XkbNumRequiredTypes+1;
	if (XkbAllocClientMap(xkb,XkbKeyTypesMask,tmp)!=Success)
	    return NULL;
	tmp= 0;
	if (map->num_types<=XkbKeypadIndex)
	    tmp|= XkbKeypadMask;
	if (map->num_types<=XkbAlphabeticIndex)
	    tmp|= XkbAlphabeticMask;
	if (map->num_types<=XkbTwoLevelIndex)
	    tmp|= XkbTwoLevelMask;
	if (map->num_types<=XkbOneLevelIndex)
	    tmp|= XkbOneLevelMask;
	if (XkbInitCanonicalKeyTypes(xkb,tmp,XkbNoModifier)==Success) {
	    for (i=0;i<map->num_types;i++) {
		Status status;
		if (map->types[i].name!=name)
		    continue;
		status=XkbResizeKeyType(xkb,i,map_count,want_preserve,num_lvls);
		return (status==Success?&map->types[i]:NULL);
	    }
	}
    }
    if ((map->num_types<=map->size_types)&&
	(XkbAllocClientMap(xkb,XkbKeyTypesMask,map->num_types+1)!=Success)) {
	return NULL;
    }
    type= &map->types[map->num_types];
    map->num_types++;
    bzero((char *)type,sizeof(XkbKeyTypeRec));
    type->num_levels=	num_lvls;
    type->map_count=	map_count;
    type->name=		name;
    if (map_count>0) {
	type->map=	_XkbTypedCalloc(map_count,XkbKTMapEntryRec);
	if (!type->map) {
	    map->num_types--;
	    return NULL;
	}
	if (want_preserve) {
	    type->preserve=	_XkbTypedCalloc(map_count,XkbModsRec);
	    if (!type->preserve) {
		_XkbFree(type->map);
		map->num_types--;
		return NULL;
	    }
	}
    }
    return type;
}

Status
XkbResizeKeyType(	XkbDescPtr	xkb,
			int		type_ndx,
			int		map_count,
			Bool		want_preserve,
			int		new_num_lvls)
{
XkbKeyTypePtr	type;
KeyCode		matchingKeys[XkbMaxKeyCount],nMatchingKeys;

    if ((type_ndx<0)||(type_ndx>=xkb->map->num_types)||(map_count<0)||
    							(new_num_lvls<1))
	return BadValue;
    switch (type_ndx) {
	case XkbOneLevelIndex:
	    if (new_num_lvls!=1)
		return BadMatch;
	    break;
	case XkbTwoLevelIndex:
	case XkbAlphabeticIndex:
	case XkbKeypadIndex:
	    if (new_num_lvls!=2)
		return BadMatch;
	    break;
    }
    type= &xkb->map->types[type_ndx];
    if (map_count==0) {
	if (type->map!=NULL)
	    _XkbFree(type->map);
	type->map= NULL;
	if (type->preserve!=NULL)
	    _XkbFree(type->preserve);
	type->preserve= NULL;
	type->map_count= 0;
    }
    else {
	XkbKTMapEntryRec *prev_map = type->map;

	if ((map_count>type->map_count)||(type->map==NULL))
	    type->map=_XkbTypedRealloc(type->map,map_count,XkbKTMapEntryRec);
	if (!type->map) {
	    if (prev_map) 
		_XkbFree(prev_map);
	    return BadAlloc;
	}
	if (want_preserve) {
	    XkbModsRec *prev_preserve = type->preserve;

	    if ((map_count>type->map_count)||(type->preserve==NULL)) {
		type->preserve= _XkbTypedRealloc(type->preserve,map_count,
	     						    XkbModsRec);
	    }
	    if (!type->preserve) {
		if (prev_preserve) 
		    _XkbFree(prev_preserve);
		return BadAlloc;
	    }
	}
	else if (type->preserve!=NULL) {
	    _XkbFree(type->preserve);
	    type->preserve= NULL;
	}
	type->map_count= map_count;
    }

    if ((new_num_lvls>type->num_levels)||(type->level_names==NULL)) {
	Atom * prev_level_names = type->level_names;

	type->level_names=_XkbTypedRealloc(type->level_names,new_num_lvls,Atom);
	if (!type->level_names) {
	    if (prev_level_names) 
		_XkbFree(prev_level_names);
	    return BadAlloc;
	}
    }
    /*
     * Here's the theory:
     *    If the width of the type changed, we might have to resize the symbol
     * maps for any keys that use the type for one or more groups.  This is
     * expensive, so we'll try to cull out any keys that are obviously okay:
     * In any case:
     *    - keys that have a group width <= the old width are okay (because
     *      they could not possibly have been associated with the old type)
     * If the key type increased in size:
     *    - keys that already have a group width >= to the new width are okay
     *    + keys that have a group width >= the old width but < the new width
     *      might have to be enlarged.
     * If the key type decreased in size:
     *    - keys that have a group width > the old width don't have to be
     *      resized (because they must have some other wider type associated 
     *      with some group).
     *    + keys that have a group width == the old width might have to be
     *      shrunk.
     * The possibilities marked with '+' require us to examine the key types
     * associated with each group for the key.
     */
    bzero(matchingKeys,XkbMaxKeyCount*sizeof(KeyCode));
    nMatchingKeys= 0;
    if (new_num_lvls>type->num_levels) {
	int	 		nTotal;
	KeySym	*		newSyms;
	int			width,match,nResize;
	register int		i,g,nSyms;

	nResize= 0;
	for (nTotal=1,i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
	    width= XkbKeyGroupsWidth(xkb,i);
	    if (width<type->num_levels)
		continue;
	    for (match=0,g=XkbKeyNumGroups(xkb,i)-1;(g>=0)&&(!match);g--) {
		if (XkbKeyKeyTypeIndex(xkb,i,g)==type_ndx) {
		    matchingKeys[nMatchingKeys++]= i;
		    match= 1;
		}
	    }
	    if ((!match)||(width>=new_num_lvls))
		nTotal+= XkbKeyNumSyms(xkb,i);
	    else {
		nTotal+= XkbKeyNumGroups(xkb,i)*new_num_lvls;
		nResize++;
	    }
	}
	if (nResize>0) {
	    int nextMatch;
	    xkb->map->size_syms= (nTotal*12)/10;
	    newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym);
	    if (newSyms==NULL)
		return BadAlloc;
	    nextMatch= 0;
	    nSyms= 1;
	    for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
		if (matchingKeys[nextMatch]==i) {
		    KeySym *pOld;
		    nextMatch++;
		    width= XkbKeyGroupsWidth(xkb,i);
		    pOld= XkbKeySymsPtr(xkb,i);
		    for (g=XkbKeyNumGroups(xkb,i)-1;g>=0;g--) {
			memcpy(&newSyms[nSyms+(new_num_lvls*g)],&pOld[width*g],
							width*sizeof(KeySym));
		    }
		    xkb->map->key_sym_map[i].offset= nSyms;
		    nSyms+= XkbKeyNumGroups(xkb,i)*new_num_lvls;
		}
		else {
		    memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i),
					XkbKeyNumSyms(xkb,i)*sizeof(KeySym));
		    xkb->map->key_sym_map[i].offset= nSyms;
		    nSyms+= XkbKeyNumSyms(xkb,i);
		}
	    }
	    type->num_levels= new_num_lvls;
	    _XkbFree(xkb->map->syms);
	    xkb->map->syms= newSyms;
	    xkb->map->num_syms= nSyms;
	    return Success;
	}
    }
    else if (new_num_lvls<type->num_levels) {
	int 		width,match;
	register int	g,i;
	for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
	    width= XkbKeyGroupsWidth(xkb,i);
	    if (width<type->num_levels)
		continue;
	    for (match=0,g=XkbKeyNumGroups(xkb,i)-1;(g>=0)&&(!match);g--) {
		if (XkbKeyKeyTypeIndex(xkb,i,g)==type_ndx) {
		    matchingKeys[nMatchingKeys++]= i;
		    match= 1;
		}
	    }
	}
    }
    if (nMatchingKeys>0) {
	int 		key,firstClear;
	register int	i,g;
	if (new_num_lvls>type->num_levels)
	     firstClear= type->num_levels;
	else firstClear= new_num_lvls;
	for (i=0;i<nMatchingKeys;i++) {
	    KeySym *	pSyms;
	    int		width,nClear;

	    key= matchingKeys[i];
	    width= XkbKeyGroupsWidth(xkb,key);
	    nClear= width-firstClear;
	    pSyms= XkbKeySymsPtr(xkb,key);
	    for (g=XkbKeyNumGroups(xkb,key)-1;g>=0;g--) {
		if (XkbKeyKeyTypeIndex(xkb,key,g)==type_ndx) {
		    if (nClear>0)
			bzero(&pSyms[g*width+firstClear],nClear*sizeof(KeySym));
		}
	    }
	}
    }
    type->num_levels= new_num_lvls;
    return Success;
}

KeySym *
XkbResizeKeySyms(XkbDescPtr xkb,int key,int needed)
{
register int i,nSyms,nKeySyms;
unsigned nOldSyms;
KeySym	*newSyms;

    if (needed==0) {
	xkb->map->key_sym_map[key].offset= 0;
	return xkb->map->syms;
    }
    nOldSyms= XkbKeyNumSyms(xkb,key);
    if (nOldSyms>=(unsigned)needed) {
	return XkbKeySymsPtr(xkb,key);
    }
    if (xkb->map->size_syms-xkb->map->num_syms>=(unsigned)needed) {
	if (nOldSyms>0) {
	    memcpy(&xkb->map->syms[xkb->map->num_syms],XkbKeySymsPtr(xkb,key),
						nOldSyms*sizeof(KeySym));
	}
	if ((needed-nOldSyms)>0) {
	    bzero(&xkb->map->syms[xkb->map->num_syms+XkbKeyNumSyms(xkb,key)],
					(needed-nOldSyms)*sizeof(KeySym));
	}
	xkb->map->key_sym_map[key].offset = xkb->map->num_syms;
	xkb->map->num_syms+= needed;
	return &xkb->map->syms[xkb->map->key_sym_map[key].offset];
    }
    xkb->map->size_syms+= (needed>32?needed:32);
    newSyms = _XkbTypedCalloc(xkb->map->size_syms,KeySym);
    if (newSyms==NULL)
	return NULL;
    newSyms[0]= NoSymbol;
    nSyms = 1;
    for (i=xkb->min_key_code;i<=(int)xkb->max_key_code;i++) {
	int nCopy;

	nCopy= nKeySyms= XkbKeyNumSyms(xkb,i);
	if ((nKeySyms==0)&&(i!=key))
	    continue;
	if (i==key)
	    nKeySyms= needed;
	if (nCopy!=0)
	   memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i),nCopy*sizeof(KeySym));
	if (nKeySyms>nCopy)
	    bzero(&newSyms[nSyms+nCopy],(nKeySyms-nCopy)*sizeof(KeySym));
	xkb->map->key_sym_map[i].offset = nSyms;
	nSyms+= nKeySyms;
    }
    _XkbFree(xkb->map->syms);
    xkb->map->syms = newSyms;
    xkb->map->num_syms = nSyms;
    return &xkb->map->syms[xkb->map->key_sym_map[key].offset];
}

static unsigned
_ExtendRange(	unsigned int 	old_flags,
		unsigned int	flag,
		KeyCode		newKC,
		KeyCode *	old_min,
		unsigned char *	old_num)
{
    if ((old_flags&flag)==0) {
	old_flags|= flag;
	*old_min= newKC;
	*old_num= 1;
    }
    else {
	int	last= (*old_min)+(*old_num)-1;
	if (newKC<*old_min) {
	    *old_min= newKC;
	    *old_num= (last-newKC)+1;
	}
	else if (newKC>last) {
	    *old_num= (newKC-(*old_min))+1;
	}
    }
    return old_flags;
}

Status
XkbChangeKeycodeRange(	XkbDescPtr	xkb,
			int 		minKC,
			int 		maxKC,
			XkbChangesPtr	changes)
{
int	tmp;

    if ((!xkb)||(minKC<XkbMinLegalKeyCode)||(maxKC>XkbMaxLegalKeyCode))
	return BadValue;
    if (minKC>maxKC)
	return BadMatch;
    if (minKC<xkb->min_key_code) {
	if (changes)
	    changes->map.min_key_code= minKC;
	tmp= xkb->min_key_code-minKC;
	if (xkb->map)  {
	    if (xkb->map->key_sym_map) {
		bzero((char *)&xkb->map->key_sym_map[minKC],
					tmp*sizeof(XkbSymMapRec));
		if (changes) {
		    changes->map.changed= _ExtendRange(changes->map.changed,
		    				XkbKeySymsMask,minKC,
	    					&changes->map.first_key_sym,
	    					&changes->map.num_key_syms);
		}
	    }
	    if (xkb->map->modmap) {
		bzero((char *)&xkb->map->modmap[minKC],tmp);
		if (changes) {
		    changes->map.changed= _ExtendRange(changes->map.changed,
		    				XkbModifierMapMask,minKC,
	    					&changes->map.first_modmap_key,
	    					&changes->map.num_modmap_keys);
		}
	    }
	}
	if (xkb->server) {
	    if (xkb->server->behaviors) {
		bzero((char *)&xkb->server->behaviors[minKC],
						tmp*sizeof(XkbBehavior));
		if (changes) {
		    changes->map.changed= _ExtendRange(changes->map.changed,
		    			XkbKeyBehaviorsMask,minKC,
    					&changes->map.first_key_behavior,
    					&changes->map.num_key_behaviors);
		}
	    }
	    if (xkb->server->key_acts) {
		bzero((char *)&xkb->server->key_acts[minKC],
						tmp*sizeof(unsigned short));
		if (changes) {
		    changes->map.changed= _ExtendRange(changes->map.changed,
		    			XkbKeyActionsMask,minKC,
    					&changes->map.first_key_act,
    					&changes->map.num_key_acts);
		}
	    }
	    if (xkb->server->vmodmap) {
		bzero((char *)&xkb->server->vmodmap[minKC],
						tmp*sizeof(unsigned short));
		if (changes) {
		    changes->map.changed= _ExtendRange(changes->map.changed,
		    			XkbVirtualModMapMask,minKC,
		    			&changes->map.first_modmap_key,
    					&changes->map.num_vmodmap_keys);
		}
	    }
	}
	if ((xkb->names)&&(xkb->names->keys)) {
	    bzero((char *)&xkb->names->keys[minKC],tmp*sizeof(XkbKeyNameRec));
	    if (changes) {
		changes->names.changed= _ExtendRange(changes->names.changed,
					XkbKeyNamesMask,minKC,
					&changes->names.first_key,
    					&changes->names.num_keys);
	    }
	}
	xkb->min_key_code= minKC;
    }
    if (maxKC>xkb->max_key_code) {
	if (changes)
	    changes->map.max_key_code= maxKC;
	tmp= maxKC-xkb->max_key_code;
	if (xkb->map)  {
	    if (xkb->map->key_sym_map) {
		XkbSymMapRec *prev_key_sym_map = xkb->map->key_sym_map;

		xkb->map->key_sym_map= _XkbTypedRealloc(xkb->map->key_sym_map,
						(maxKC+1),XkbSymMapRec);
		if (!xkb->map->key_sym_map) {
		    _XkbFree(prev_key_sym_map);
		    return BadAlloc;
		}
		bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code],
					tmp*sizeof(XkbSymMapRec));
		if (changes) {
		    changes->map.changed= _ExtendRange(changes->map.changed,
		    				XkbKeySymsMask,maxKC,
	    					&changes->map.first_key_sym,
	    					&changes->map.num_key_syms);
		}
	    }
	    if (xkb->map->modmap) {
		unsigned char *prev_modmap = xkb->map->modmap;

		xkb->map->modmap= _XkbTypedRealloc(xkb->map->modmap,
						(maxKC+1),unsigned char);
		if (!xkb->map->modmap) {
		    _XkbFree(prev_modmap);
		    return BadAlloc;
		}
		bzero((char *)&xkb->map->modmap[xkb->max_key_code],tmp);
		if (changes) {
		    changes->map.changed= _ExtendRange(changes->map.changed,
		    				XkbModifierMapMask,maxKC,
	    					&changes->map.first_modmap_key,
	    					&changes->map.num_modmap_keys);
		}
	    }
	}
	if (xkb->server) {
	    if (xkb->server->behaviors) {
		XkbBehavior *prev_behaviors = xkb->server->behaviors;

		xkb->server->behaviors=_XkbTypedRealloc(xkb->server->behaviors,
						(maxKC+1),XkbBehavior);
		if (!xkb->server->behaviors) {
		    _XkbFree(prev_behaviors);
		    return BadAlloc;
		}
		bzero((char *)&xkb->server->behaviors[xkb->max_key_code],
						tmp*sizeof(XkbBehavior));
		if (changes) {
		    changes->map.changed= _ExtendRange(changes->map.changed,
		    			XkbKeyBehaviorsMask,maxKC,
    					&changes->map.first_key_behavior,
    					&changes->map.num_key_behaviors);
		}
	    }
	    if (xkb->server->key_acts) {
		unsigned short *prev_key_acts = xkb->server->key_acts;

		xkb->server->key_acts= _XkbTypedRealloc(xkb->server->key_acts,
						(maxKC+1),unsigned short);
		if (!xkb->server->key_acts) {
		    _XkbFree(prev_key_acts);
		    return BadAlloc;
		}
		bzero((char *)&xkb->server->key_acts[xkb->max_key_code],
						tmp*sizeof(unsigned short));
		if (changes) {
		    changes->map.changed= _ExtendRange(changes->map.changed,
		    			XkbKeyActionsMask,maxKC,
    					&changes->map.first_key_act,
    					&changes->map.num_key_acts);
		}
	    }
	    if (xkb->server->vmodmap) {
		unsigned short *prev_vmodmap = xkb->server->vmodmap;

		xkb->server->vmodmap= _XkbTypedRealloc(xkb->server->vmodmap,
						(maxKC+1),unsigned short);
		if (!xkb->server->vmodmap) {
		    _XkbFree(prev_vmodmap);
		    return BadAlloc;
		}
		bzero((char *)&xkb->server->vmodmap[xkb->max_key_code],
						tmp*sizeof(unsigned short));
		if (changes) {
		    changes->map.changed= _ExtendRange(changes->map.changed,
		    			XkbVirtualModMapMask,maxKC,
		    			&changes->map.first_modmap_key,
    					&changes->map.num_vmodmap_keys);
		}
	    }
	}
	if ((xkb->names)&&(xkb->names->keys)) {
	    XkbKeyNameRec *prev_keys = xkb->names->keys;

	    xkb->names->keys= _XkbTypedRealloc(xkb->names->keys,
	    					(maxKC+1),XkbKeyNameRec);
	    if (!xkb->names->keys) {
		_XkbFree(prev_keys);
		return BadAlloc;
	    }
	    bzero((char *)&xkb->names->keys[xkb->max_key_code],
	    					tmp*sizeof(XkbKeyNameRec));
	    if (changes) {
		changes->names.changed= _ExtendRange(changes->names.changed,
					XkbKeyNamesMask,maxKC,
					&changes->names.first_key,
    					&changes->names.num_keys);
	    }
	}
	xkb->max_key_code= maxKC;
    }
    return Success;
}

XkbAction *
XkbResizeKeyActions(XkbDescPtr xkb,int key,int needed)
{
register int i,nActs;
XkbAction *newActs;

    if (needed==0) {
	xkb->server->key_acts[key]= 0;
	return NULL;
    }
    if (XkbKeyHasActions(xkb,key)&&(XkbKeyNumSyms(xkb,key)>=(unsigned)needed))
	return XkbKeyActionsPtr(xkb,key);
    if (xkb->server->size_acts-xkb->server->num_acts>=(unsigned)needed) {
	xkb->server->key_acts[key]= xkb->server->num_acts;
	xkb->server->num_acts+= needed;
	return &xkb->server->acts[xkb->server->key_acts[key]];
    }
    xkb->server->size_acts= xkb->server->num_acts+needed+8;
    newActs = _XkbTypedCalloc(xkb->server->size_acts,XkbAction);
    if (newActs==NULL)
	return NULL;
    newActs[0].type = XkbSA_NoAction;
    nActs = 1;
    for (i=xkb->min_key_code;i<=(int)xkb->max_key_code;i++) {
	int nKeyActs,nCopy;

	if ((xkb->server->key_acts[i]==0)&&(i!=key))
	    continue;

	nCopy= nKeyActs= XkbKeyNumActions(xkb,i);
	if (i==key) {
	    nKeyActs= needed;
	    if (needed<nCopy)
		nCopy= needed;
	}

	if (nCopy>0)
	    memcpy(&newActs[nActs],XkbKeyActionsPtr(xkb,i),
						nCopy*sizeof(XkbAction));
	if (nCopy<nKeyActs)
	    bzero(&newActs[nActs+nCopy],(nKeyActs-nCopy)*sizeof(XkbAction));
	xkb->server->key_acts[i]= nActs;
	nActs+= nKeyActs;
    }
    _XkbFree(xkb->server->acts);
    xkb->server->acts = newActs;
    xkb->server->num_acts= nActs;
    return &xkb->server->acts[xkb->server->key_acts[key]];
}

void
XkbFreeClientMap(XkbDescPtr xkb,unsigned what,Bool freeMap)
{
XkbClientMapPtr	map;

    if ((xkb==NULL)||(xkb->map==NULL))
	return;
    if (freeMap)
	what= XkbAllClientInfoMask;
    map= xkb->map;
    if (what&XkbKeyTypesMask) {
	if (map->types!=NULL) {
	    if (map->num_types>0) {
		register int 	i;
		XkbKeyTypePtr	type;
		for (i=0,type=map->types;i<map->num_types;i++,type++) {
		    if (type->map!=NULL) {
			_XkbFree(type->map);
			type->map= NULL;
		    }
		    if (type->preserve!=NULL) {
			_XkbFree(type->preserve);
			type->preserve= NULL;
		    }
		    type->map_count= 0;
		    if (type->level_names!=NULL) {
			_XkbFree(type->level_names);
			type->level_names= NULL;
		    }
		}
	    }
	    _XkbFree(map->types);
	    map->num_types= map->size_types= 0;
	    map->types= NULL;
	}
    }
    if (what&XkbKeySymsMask) {
	if (map->key_sym_map!=NULL) {
	    _XkbFree(map->key_sym_map);
	    map->key_sym_map= NULL;
	}
	if (map->syms!=NULL) {
	    _XkbFree(map->syms);
	    map->size_syms= map->num_syms= 0;
	    map->syms= NULL;
	}
    }
    if ((what&XkbModifierMapMask)&&(map->modmap!=NULL)) {
	_XkbFree(map->modmap);
	map->modmap= NULL;
    }
    if (freeMap) {
	_XkbFree(xkb->map);
	xkb->map= NULL;
    }
    return;
}

void
XkbFreeServerMap(XkbDescPtr xkb,unsigned what,Bool freeMap)
{
XkbServerMapPtr	map;

    if ((xkb==NULL)||(xkb->server==NULL))
	return;
    if (freeMap)
	what= XkbAllServerInfoMask;
    map= xkb->server;
    if ((what&XkbExplicitComponentsMask)&&(map->explicit!=NULL)) {
	_XkbFree(map->explicit);
	map->explicit= NULL;
    }
    if (what&XkbKeyActionsMask) {
	if (map->key_acts!=NULL) {
	    _XkbFree(map->key_acts);
	    map->key_acts= NULL;
	}
	if (map->acts!=NULL) {
	    _XkbFree(map->acts);
	    map->num_acts= map->size_acts= 0;
	    map->acts= NULL;
	}
    }
    if ((what&XkbKeyBehaviorsMask)&&(map->behaviors!=NULL)) {
	_XkbFree(map->behaviors);
	map->behaviors= NULL;
    }
    if ((what&XkbVirtualModMapMask)&&(map->vmodmap!=NULL)) {
	_XkbFree(map->vmodmap);
	map->vmodmap= NULL;
    }

    if (freeMap) {
	_XkbFree(xkb->server);
	xkb->server= NULL;
    }
    return;
}

--- NEW FILE: XKBMisc.c ---
/* $Xorg: XKBMisc.c,v 1.4 2000/08/17 19:45:02 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/lib/X11/XKBMisc.c,v 3.4 2001/08/01 00:44:38 tsi Exp $ */

#ifndef XKB_IN_SERVER

#include <stdio.h>
#define NEED_REPLIES
#define NEED_EVENTS
#include "Xlibint.h"
#include <X11/extensions/XKBproto.h>
#include <X11/keysym.h>
#include <X11/extensions/XKBlibint.h>

#else 

#include <stdio.h>
#include <X11/X.h>
#define	NEED_EVENTS
#define	NEED_REPLIES
#include <X11/Xproto.h>
#include "misc.h"
#include "inputstr.h"
#include <X11/keysym.h>
#define	XKBSRV_NEED_FILE_FUNCS
#include <X11/extensions/XKBsrv.h>

#endif /* XKB_IN_SERVER */

/***====================================================================***/

#define	mapSize(m)	(sizeof(m)/sizeof(XkbKTMapEntryRec))
static  XkbKTMapEntryRec map2Level[]= { 
  { True, ShiftMask, {1, ShiftMask, 0} }
};

static  XkbKTMapEntryRec mapAlpha[]= { 
  { True, ShiftMask, { 1, ShiftMask, 0 } },
  { True, LockMask,  { 0,  LockMask, 0 } }
};

static	XkbModsRec preAlpha[]= {
	{        0,        0, 0 },
	{ LockMask, LockMask, 0 }
};

#define	NL_VMOD_MASK	0
static  XkbKTMapEntryRec mapKeypad[]= { 
	{ True,	ShiftMask, { 1, ShiftMask,            0 } },
	{ False,        0, { 1,         0, NL_VMOD_MASK } }
};

static	XkbKeyTypeRec	canonicalTypes[XkbNumRequiredTypes] = {
	{ { 0, 0, 0 }, 
	  1,	/* num_levels */
	  0,	/* map_count */
	  NULL,		NULL,
	  None,		NULL
	},
	{ { ShiftMask, ShiftMask, 0 }, 
	  2,	/* num_levels */
	  mapSize(map2Level),	/* map_count */
	  map2Level,	NULL,
	  None,		NULL
	},
	{ { ShiftMask|LockMask, ShiftMask|LockMask, 0 }, 
	  2,				/* num_levels */
	  mapSize(mapAlpha),		/* map_count */
	  mapAlpha,	preAlpha,
	  None,		NULL
	},
	{ { ShiftMask, ShiftMask, NL_VMOD_MASK },
	  2,				/* num_levels */
	  mapSize(mapKeypad),		/* map_count */
	  mapKeypad,	NULL,
	  None,		NULL
	}
};

Status
XkbInitCanonicalKeyTypes(XkbDescPtr xkb,unsigned which,int keypadVMod)
{
XkbClientMapPtr	map;
XkbKeyTypePtr	from,to;
Status		rtrn;

    if (!xkb)
	return BadMatch;
    rtrn= XkbAllocClientMap(xkb,XkbKeyTypesMask,XkbNumRequiredTypes);
    if (rtrn!=Success)
	return rtrn;
    map= xkb->map;
    if ((which&XkbAllRequiredTypes)==0)
	return Success;
    rtrn= Success;
    from= canonicalTypes;
    to= map->types;
    if (which&XkbOneLevelMask)
	rtrn= XkbCopyKeyType(&from[XkbOneLevelIndex],&to[XkbOneLevelIndex]);
    if ((which&XkbTwoLevelMask)&&(rtrn==Success))
	rtrn= XkbCopyKeyType(&from[XkbTwoLevelIndex],&to[XkbTwoLevelIndex]);
    if ((which&XkbAlphabeticMask)&&(rtrn==Success))
	rtrn= XkbCopyKeyType(&from[XkbAlphabeticIndex],&to[XkbAlphabeticIndex]);
    if ((which&XkbKeypadMask)&&(rtrn==Success)) {
	XkbKeyTypePtr type;
	rtrn= XkbCopyKeyType(&from[XkbKeypadIndex],&to[XkbKeypadIndex]);
	type= &to[XkbKeypadIndex];
	if ((keypadVMod>=0)&&(keypadVMod<XkbNumVirtualMods)&&(rtrn==Success)) {
	    type->mods.vmods= (1<<keypadVMod);
	    type->map[0].active= True;
	    type->map[0].mods.mask= ShiftMask;
	    type->map[0].mods.real_mods= ShiftMask;
	    type->map[0].mods.vmods= 0;
	    type->map[0].level= 1;
	    type->map[1].active= False;
	    type->map[1].mods.mask= 0;
	    type->map[1].mods.real_mods= 0;
	    type->map[1].mods.vmods= (1<<keypadVMod);
	    type->map[1].level= 1;
	}
    }
    return Success;
}

/***====================================================================***/

#define	CORE_SYM(i)	(i<map_width?core_syms[i]:NoSymbol)
#define	XKB_OFFSET(g,l)	(((g)*groupsWidth)+(l))

int
XkbKeyTypesForCoreSymbols(	XkbDescPtr	xkb,
				int		map_width,
				KeySym *	core_syms,
				unsigned int 	protected,
    				int *		types_inout,
				KeySym *	xkb_syms_rtrn)
{
register int	i;
unsigned int	empty;
int		nSyms[XkbNumKbdGroups];
int		nGroups,tmp,groupsWidth;

    /* Section 12.2 of the protocol describes this process in more detail */
    /* Step 1:  find the # of symbols in the core mapping per group */
    groupsWidth= 2;
    for (i=0;i<XkbNumKbdGroups;i++) {
	if ((protected&(1<<i))&&(types_inout[i]<xkb->map->num_types)) {
	    nSyms[i]= xkb->map->types[types_inout[i]].num_levels;
	    if (nSyms[i]>groupsWidth)
		groupsWidth= nSyms[i];
	}
	else {
	    types_inout[i]= XkbTwoLevelIndex;	/* don't really know, yet */
	    nSyms[i]= 2;
	}
    }
    if (nSyms[XkbGroup1Index]<2)
	nSyms[XkbGroup1Index]= 2;
    if (nSyms[XkbGroup2Index]<2)
	nSyms[XkbGroup2Index]= 2;
    /* Step 2:	Copy the symbols from the core ordering to XKB ordering	*/
    /*		symbols in the core are in the order:			*/
    /*		G1L1 G1L2 G2L1 G2L2 [G1L[3-n]] [G2L[3-n]] [G3L*] [G3L*]	*/
    xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,0)]= CORE_SYM(0);
    xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,1)]= CORE_SYM(1);
    for (i=2;i<nSyms[XkbGroup1Index];i++) {
	xkb_syms_rtrn[XKB_OFFSET(XkbGroup1Index,i)]= CORE_SYM(2+i);
    }
    xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,0)]= CORE_SYM(2);
    xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,1)]= CORE_SYM(3);
    tmp= 2+(nSyms[XkbGroup1Index]-2); /* offset to extra group2 syms */
    for (i=2;i<nSyms[XkbGroup2Index];i++) {
	xkb_syms_rtrn[XKB_OFFSET(XkbGroup2Index,i)]= CORE_SYM(tmp+i);
    }
    tmp= nSyms[XkbGroup1Index]+nSyms[XkbGroup2Index];
    if ((tmp>=map_width)&&
	 ((protected&(XkbExplicitKeyType3Mask|XkbExplicitKeyType4Mask))==0)) {
	nSyms[XkbGroup3Index]= 0;
	nSyms[XkbGroup4Index]= 0;
	nGroups= 2;
    }
    else {
    	nGroups= 3;
	for (i=0;i<nSyms[XkbGroup3Index];i++,tmp++) {
	    xkb_syms_rtrn[XKB_OFFSET(XkbGroup3Index,i)]= CORE_SYM(tmp);
	}
	if ((tmp<map_width)||(protected&XkbExplicitKeyType4Mask)) {
	    nGroups= 4;
	    for (i=0;i<nSyms[XkbGroup4Index];i++,tmp++) {
		xkb_syms_rtrn[XKB_OFFSET(XkbGroup4Index,i)]= CORE_SYM(tmp);
	    }
	}
	else {
	    nSyms[XkbGroup4Index]= 0;
	}
    }
    /* steps 3&4: alphanumeric expansion,  assign canonical types */
    empty= 0;
    for (i=0;i<nGroups;i++) {
	KeySym *syms;
	syms= &xkb_syms_rtrn[XKB_OFFSET(i,0)];
	if ((nSyms[i]>1)&&(syms[1]==NoSymbol)&&(syms[0]!=NoSymbol)) {
	    KeySym upper,lower;
	    XConvertCase(syms[0],&lower,&upper);
	    if (upper!=lower) {
		xkb_syms_rtrn[XKB_OFFSET(i,0)]= lower;
		xkb_syms_rtrn[XKB_OFFSET(i,1)]= upper;
		if ((protected&(1<<i))==0)
		    types_inout[i]= XkbAlphabeticIndex;
	    }
	    else if ((protected&(1<<i))==0) {
		types_inout[i]= XkbOneLevelIndex;
	/*	nSyms[i]=	1;*/
	    }
	}
	if (((protected&(1<<i))==0)&&(types_inout[i]==XkbTwoLevelIndex)) {
	    if (IsKeypadKey(syms[0])||IsKeypadKey(syms[1]))
		types_inout[i]= XkbKeypadIndex;
	    else {
		KeySym upper,lower;
		XConvertCase(syms[0],&lower,&upper);
		if ((syms[0]==lower)&&(syms[1]==upper))
		    types_inout[i]= XkbAlphabeticIndex;
	    }
	}
	if (syms[0]==NoSymbol) {
	    register int n;
	    Bool	found;
	    for (n=1,found=False;(!found)&&(n<nSyms[i]);n++) {
		found= (syms[n]!=NoSymbol);
	    }
	    if (!found)
		empty|= (1<<i);
	}
    }
    /* step 5: squoosh out empty groups */
    if (empty) {
	for (i=nGroups-1;i>=0;i--) {
	    if (((empty&(1<<i))==0)||(protected&(1<<i)))
		break;
	    nGroups--;
	}
    }
    if (nGroups<1)
	return 0;

    /* step 6: replicate group 1 into group two, if necessary */
    if ((nGroups>1)&&((empty&(XkbGroup1Mask|XkbGroup2Mask))==XkbGroup2Mask)) {
	if ((protected&(XkbExplicitKeyType1Mask|XkbExplicitKeyType2Mask))==0) {
	    nSyms[XkbGroup2Index]= nSyms[XkbGroup1Index];
	    types_inout[XkbGroup2Index]= types_inout[XkbGroup1Index];
	    memcpy((char *)&xkb_syms_rtrn[2],(char *)xkb_syms_rtrn,
							2*sizeof(KeySym));
	}
	else if (types_inout[XkbGroup1Index]==types_inout[XkbGroup2Index]) {
	    memcpy((char *)&xkb_syms_rtrn[nSyms[XkbGroup1Index]],
	    				(char *)xkb_syms_rtrn,
					nSyms[XkbGroup1Index]*sizeof(KeySym));
	}
    }

    /* step 7: check for all groups identical or all width 1 */
    if (nGroups>1) {
	Bool sameType,allOneLevel;
	allOneLevel= (xkb->map->types[types_inout[0]].num_levels==1);
	for (i=1,sameType=True;(allOneLevel||sameType)&&(i<nGroups);i++) {
	    sameType=(sameType&&(types_inout[i]==types_inout[XkbGroup1Index]));
	    if (allOneLevel)
		allOneLevel= (xkb->map->types[types_inout[i]].num_levels==1);
	}
	if ((sameType)&&
	    (!(protected&(XkbExplicitKeyTypesMask&~XkbExplicitKeyType1Mask)))){
	    register int s;
	    Bool	identical;
	    for (i=1,identical=True;identical&&(i<nGroups);i++) {
		KeySym *syms;
		syms= &xkb_syms_rtrn[XKB_OFFSET(i,0)];
		for (s=0;identical&&(s<nSyms[i]);s++) {
		    if (syms[s]!=xkb_syms_rtrn[s])
			identical= False;
		}
	    }
	    if (identical)
		nGroups= 1;
	}
	if (allOneLevel && (nGroups>1)) {
	    KeySym *syms;
	    syms= &xkb_syms_rtrn[nSyms[XkbGroup1Index]];
	    nSyms[XkbGroup1Index]= 1;
	    for (i=1;i<nGroups;i++) {
		xkb_syms_rtrn[i]= syms[0];
		syms+= nSyms[i];
		nSyms[i]= 1;
	    }
	}
    }
    return nGroups;
}

static XkbSymInterpretPtr
_XkbFindMatchingInterp(	XkbDescPtr	xkb,
			KeySym 		sym,
			unsigned int	real_mods,
			unsigned int	level)
{
register unsigned	 i;
XkbSymInterpretPtr	 interp,rtrn;
CARD8			 mods;

    rtrn= NULL;
    interp= xkb->compat->sym_interpret;
    for (i=0;i<xkb->compat->num_si;i++,interp++) {
	if ((interp->sym==NoSymbol)||(sym==interp->sym)) {
	    int match;
	    if ((level==0)||((interp->match&XkbSI_LevelOneOnly)==0))
		 mods= real_mods;
	    else mods= 0;
	    switch (interp->match&XkbSI_OpMask) {
		case XkbSI_NoneOf:
		    match= ((interp->mods&mods)==0);
		    break;
		case XkbSI_AnyOfOrNone:
		    match= ((mods==0)||((interp->mods&mods)!=0));
		    break;
		case XkbSI_AnyOf:
		    match= ((interp->mods&mods)!=0);
		    break;
		case XkbSI_AllOf:
		    match= ((interp->mods&mods)==interp->mods);
		    break;
		case XkbSI_Exactly:
		    match= (interp->mods==mods);
		    break;
		default:
		    match= 0;
		    break;
	    }
	    if (match) {
		if (interp->sym!=NoSymbol) {
		    return interp;
		}
		else if (rtrn==NULL) {
		    rtrn= interp;
		}
	    }
	}
    }
    return rtrn;
}

static void
_XkbAddKeyChange(KeyCode *pFirst,unsigned char *pNum,KeyCode newKey)
{
KeyCode	last;

    last= (*pFirst)+(*pNum);
    if (newKey<*pFirst) {
	*pFirst= newKey;
	*pNum= (last-newKey)+1;
    }
    else if (newKey>last) {
	*pNum= (last-*pFirst)+1;
    }
    return;
}

static void
_XkbSetActionKeyMods(XkbDescPtr xkb,XkbAction *act,unsigned mods)
{
unsigned	tmp;

    switch (act->type) {
	case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods:
	    if (act->mods.flags&XkbSA_UseModMapMods)
		act->mods.real_mods= act->mods.mask= mods;
	    if ((tmp= XkbModActionVMods(&act->mods))!=0) {
		XkbVirtualModsToReal(xkb,tmp,&tmp);
		act->mods.mask|= tmp;
	    }
	    break;
	case XkbSA_ISOLock:
	    if (act->iso.flags&XkbSA_UseModMapMods)
		act->iso.real_mods= act->iso.mask= mods;
	    if ((tmp= XkbModActionVMods(&act->iso))!=0) {
		XkbVirtualModsToReal(xkb,tmp,&tmp);
		act->iso.mask|= tmp;
	    }
	    break;
    }
    return;
}

#define	IBUF_SIZE	8

Bool
XkbApplyCompatMapToKey(XkbDescPtr xkb,KeyCode key,XkbChangesPtr changes)
{
KeySym *		syms;
unsigned char 		explicit,mods;
XkbSymInterpretPtr	*interps,ibuf[IBUF_SIZE]; 
int			n,nSyms,found;
unsigned		changed,tmp;

    if ((!xkb)||(!xkb->map)||(!xkb->map->key_sym_map)||
    			(!xkb->compat)||(!xkb->compat->sym_interpret)||
			(key<xkb->min_key_code)||(key>xkb->max_key_code)) {
	return False;
    }
    if (((!xkb->server)||(!xkb->server->key_acts))&&
		(XkbAllocServerMap(xkb,XkbAllServerInfoMask,0)!=Success)) {
	return False;
    }
    changed= 0;	/* keeps track of what has changed in _this_ call */
    explicit= xkb->server->explicit[key];
    if (explicit&XkbExplicitInterpretMask) /* nothing to do */
	return True;
    mods= (xkb->map->modmap?xkb->map->modmap[key]:0);
    nSyms= XkbKeyNumSyms(xkb,key);
    syms= XkbKeySymsPtr(xkb,key);
    if (nSyms>IBUF_SIZE) {
	interps= _XkbTypedCalloc(nSyms,XkbSymInterpretPtr);
	if (interps==NULL) {
	    interps= ibuf;
	    nSyms= IBUF_SIZE;
	}
    }
    else {
	interps= ibuf;
    }
    found= 0;
    for (n=0;n<nSyms;n++) {
	unsigned level= (n%XkbKeyGroupsWidth(xkb,key));
	interps[n]= NULL;
	if (syms[n]!=NoSymbol) {
	    interps[n]= _XkbFindMatchingInterp(xkb,syms[n],mods,level);
	    if (interps[n]&&interps[n]->act.type!=XkbSA_NoAction)
		found++;
	    else interps[n]= NULL;
	}
    }
    /* 1/28/96 (ef) -- XXX! WORKING HERE */
    if (!found) {
	if (xkb->server->key_acts[key]!=0) {
	    xkb->server->key_acts[key]= 0;
	    changed|= XkbKeyActionsMask;
	}
    }
    else {
	XkbAction *pActs;
	unsigned int	new_vmodmask;
	changed|= XkbKeyActionsMask;
	pActs= XkbResizeKeyActions(xkb,key,nSyms);
	if (!pActs)
	    return False;
	new_vmodmask= 0;
	for (n=0;n<nSyms;n++) {
	    if (interps[n]) {
		unsigned effMods;

		pActs[n]= *((XkbAction *)&interps[n]->act);
		if ((n==0)||((interps[n]->match&XkbSI_LevelOneOnly)==0)) {
		     effMods= mods;
		     if (interps[n]->virtual_mod!=XkbNoModifier)
			new_vmodmask|= (1<<interps[n]->virtual_mod);
		}
		else effMods= 0;
		_XkbSetActionKeyMods(xkb,&pActs[n],effMods);
	    }
	    else pActs[n].type= XkbSA_NoAction;
	}
	if (((explicit&XkbExplicitVModMapMask)==0)&&
				(xkb->server->vmodmap[key]!=new_vmodmask)) {
	    changed|= XkbVirtualModMapMask;
	    xkb->server->vmodmap[key]= new_vmodmask;
	}
	if (interps[0]) {
	    if ((interps[0]->flags&XkbSI_LockingKey)&&
				((explicit&XkbExplicitBehaviorMask)==0)) {
		xkb->server->behaviors[key].type= XkbKB_Lock;
		changed|= XkbKeyBehaviorsMask;
	    }
	    if (((explicit&XkbExplicitAutoRepeatMask)==0)&&(xkb->ctrls)) {
		CARD8 old;
		old= xkb->ctrls->per_key_repeat[key/8];
		if (interps[0]->flags&XkbSI_AutoRepeat)
		     xkb->ctrls->per_key_repeat[key/8]|= (1<<(key%8));
		else xkb->ctrls->per_key_repeat[key/8]&= ~(1<<(key%8));
		if (changes && (old!=xkb->ctrls->per_key_repeat[key/8]))
		    changes->ctrls.changed_ctrls|= XkbPerKeyRepeatMask;
	    }
	}
    }
    if ((!found)||(interps[0]==NULL)) {
	if (((explicit&XkbExplicitAutoRepeatMask)==0)&&(xkb->ctrls)) {
	    CARD8 old;
	    old= xkb->ctrls->per_key_repeat[key/8];
#ifdef RETURN_SHOULD_REPEAT
	    if (*XkbKeySymsPtr(xkb,key) != XK_Return)
#endif
		xkb->ctrls->per_key_repeat[key/8]|= (1<<(key%8));
	    if (changes && (old!=xkb->ctrls->per_key_repeat[key/8]))
		changes->ctrls.changed_ctrls|= XkbPerKeyRepeatMask;
	}
	if (((explicit&XkbExplicitBehaviorMask)==0)&&
		(xkb->server->behaviors[key].type==XkbKB_Lock)) {
		xkb->server->behaviors[key].type= XkbKB_Default;
		changed|= XkbKeyBehaviorsMask;
	}
    }
    if (changes) {
	XkbMapChangesPtr	mc;
	mc= &changes->map;
	tmp= (changed&mc->changed);
	if (tmp&XkbKeyActionsMask)
	    _XkbAddKeyChange(&mc->first_key_act,&mc->num_key_acts,key);
	else if (changed&XkbKeyActionsMask) {
	    mc->changed|= XkbKeyActionsMask;
	    mc->first_key_act= key;
	    mc->num_key_acts= 1;
	}
	if (tmp&XkbKeyBehaviorsMask) {
	    _XkbAddKeyChange(&mc->first_key_behavior,&mc->num_key_behaviors,
	    								key);
	}
	else if (changed&XkbKeyBehaviorsMask) {
	    mc->changed|= XkbKeyBehaviorsMask;
	    mc->first_key_behavior= key;
	    mc->num_key_behaviors= 1;
	}
	if (tmp&XkbVirtualModMapMask)
	    _XkbAddKeyChange(&mc->first_vmodmap_key,&mc->num_vmodmap_keys,key);
	else if (changed&XkbVirtualModMapMask) {
	    mc->changed|= XkbVirtualModMapMask;
	    mc->first_vmodmap_key= key;
	    mc->num_vmodmap_keys= 1;
	}
	mc->changed|= changed;
    }
    if (interps!=ibuf)
	_XkbFree(interps);
    return True;
}

Bool
XkbUpdateMapFromCore(	XkbDescPtr	xkb,
			KeyCode		first_key,
			int		num_keys,
			int		map_width,
			KeySym *	core_keysyms,
			XkbChangesPtr	changes)
{
register int	key,last_key;
KeySym *	syms;

    syms= &core_keysyms[(first_key-xkb->min_key_code)*map_width];
    if (changes) {
	if (changes->map.changed&XkbKeySymsMask) {
	    _XkbAddKeyChange(&changes->map.first_key_sym,
	    			&changes->map.num_key_syms,first_key);
	    if (num_keys>1) {
		_XkbAddKeyChange(&changes->map.first_key_sym,
						&changes->map.num_key_syms,
						first_key+num_keys-1);
	    }
	}
	else {
	    changes->map.changed|= XkbKeySymsMask;
	    changes->map.first_key_sym= first_key;
	    changes->map.num_key_syms= num_keys;
	}
    }
    last_key= first_key+num_keys-1;
    for (key=first_key;key<=last_key;key++,syms+= map_width) {
	XkbMapChangesPtr	mc;
	unsigned		explicit;
	KeySym			tsyms[XkbMaxSymsPerKey];
	int	 		types[XkbNumKbdGroups];
	int			nG;

	explicit= xkb->server->explicit[key]&XkbExplicitKeyTypesMask;
	types[XkbGroup1Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index);
	types[XkbGroup2Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup2Index);
	types[XkbGroup3Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup3Index);
	types[XkbGroup4Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup4Index);
	nG= XkbKeyTypesForCoreSymbols(xkb,map_width,syms,explicit,types,tsyms);
	if (changes)
	     mc= &changes->map;
	else mc= NULL;
	XkbChangeTypesOfKey(xkb,key,nG,XkbAllGroupsMask,types,mc);
	memcpy((char *)XkbKeySymsPtr(xkb,key),(char *)tsyms,
					XkbKeyNumSyms(xkb,key)*sizeof(KeySym));
	XkbApplyCompatMapToKey(xkb,key,changes);
    }

    if ((xkb->server->vmods!=NULL)&&(xkb->map->modmap!=NULL)&&(changes)&&
	(changes->map.changed&(XkbVirtualModMapMask|XkbModifierMapMask))) {
	unsigned char		newVMods[XkbNumVirtualMods];
	register  unsigned 	bit,i;
	unsigned		present;

	bzero(newVMods,XkbNumVirtualMods);
	present= 0;
	for (key=xkb->min_key_code;key<=xkb->max_key_code;key++) {
	    if (xkb->server->vmodmap[key]==0)
		continue;
	    for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
		if (bit&xkb->server->vmodmap[key]) {
		    present|= bit;
		    newVMods[i]|= xkb->map->modmap[key];
		}
	    }
	}
	for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
	    if ((bit&present)&&(newVMods[i]!=xkb->server->vmods[i])) {
		changes->map.changed|= XkbVirtualModsMask;
		changes->map.vmods|= bit;
		xkb->server->vmods[i]= newVMods[i];
	    }
	}
    }
    if (changes && (changes->map.changed&XkbVirtualModsMask))
	XkbApplyVirtualModChanges(xkb,changes->map.vmods,changes);
    return True;
}

Status
XkbChangeTypesOfKey(	XkbDescPtr		 xkb,
			int		 	 key,
			int			 nGroups,
			unsigned	 	 groups,
			int	* 	 	 newTypesIn,
			XkbMapChangesPtr	 changes)
{
XkbKeyTypePtr	pOldType,pNewType;
register int	i;
int		width,nOldGroups,oldWidth,newTypes[XkbNumKbdGroups];

    if ((!xkb) || (!XkbKeycodeInRange(xkb,key)) || (!xkb->map) ||
	(!xkb->map->types)||(!newTypes)||((groups&XkbAllGroupsMask)==0)||
	(nGroups>XkbNumKbdGroups)) {
	return BadMatch;
    }
    if (nGroups==0) {
	for (i=0;i<XkbNumKbdGroups;i++) {
	    xkb->map->key_sym_map[key].kt_index[i]= XkbOneLevelIndex;
	}
	i= xkb->map->key_sym_map[key].group_info;
	i= XkbSetNumGroups(i,0);
	xkb->map->key_sym_map[key].group_info= i;
	XkbResizeKeySyms(xkb,key,0);
	return Success;
    }

    nOldGroups= XkbKeyNumGroups(xkb,key);
    oldWidth= XkbKeyGroupsWidth(xkb,key);
    for (width=i=0;i<nGroups;i++) {
	if (groups&(1<<i))
	     newTypes[i]=  newTypesIn[i];
	else if (i<nOldGroups)
	     newTypes[i]= XkbKeyKeyTypeIndex(xkb,key,i);
	else if (nOldGroups>0)
	     newTypes[i]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index);
	else newTypes[i]= XkbTwoLevelIndex;
	if (newTypes[i]>xkb->map->num_types)
	    return BadMatch;
	pNewType= &xkb->map->types[newTypes[i]];
	if (pNewType->num_levels>width)
	    width= pNewType->num_levels;
    }
    if ((xkb->ctrls)&&(nGroups>xkb->ctrls->num_groups))
	xkb->ctrls->num_groups= nGroups;
    if ((width!=oldWidth)||(nGroups!=nOldGroups)) {
	KeySym		oldSyms[XkbMaxSymsPerKey],*pSyms;
	int		nCopy;

	if (nOldGroups==0) {
	    pSyms= XkbResizeKeySyms(xkb,key,width*nGroups);
	    if (pSyms!=NULL) {
		i= xkb->map->key_sym_map[key].group_info;
		i= XkbSetNumGroups(i,nGroups);
		xkb->map->key_sym_map[key].group_info= i;
		xkb->map->key_sym_map[key].width= width;
		for (i=0;i<nGroups;i++) {
		    xkb->map->key_sym_map[key].kt_index[i]= newTypes[i];
		}
		return Success;
	    }
	    return BadAlloc;
	}
	pSyms= XkbKeySymsPtr(xkb,key);
	memcpy(oldSyms,pSyms,XkbKeyNumSyms(xkb,key)*sizeof(KeySym));
	pSyms= XkbResizeKeySyms(xkb,key,width*nGroups);
	if (pSyms==NULL)
	    return BadAlloc;
	bzero(pSyms,width*nGroups*sizeof(KeySym));
	for (i=0;(i<nGroups)&&(i<nOldGroups);i++) {
	    pOldType= XkbKeyKeyType(xkb,key,i);
	    pNewType= &xkb->map->types[newTypes[i]];
	    if (pNewType->num_levels>pOldType->num_levels)
		 nCopy= pOldType->num_levels;
	    else nCopy= pNewType->num_levels;
	    memcpy(&pSyms[i*width],&oldSyms[i*oldWidth],nCopy*sizeof(KeySym));
	}
	if (XkbKeyHasActions(xkb,key)) {
	    XkbAction	oldActs[XkbMaxSymsPerKey],*pActs;
	    pActs= XkbKeyActionsPtr(xkb,key);
	    memcpy(oldActs,pActs,XkbKeyNumSyms(xkb,key)*sizeof(XkbAction));
	    pActs= XkbResizeKeyActions(xkb,key,width*nGroups);
	    if (pActs==NULL)
		return BadAlloc;
	    bzero(pActs,width*nGroups*sizeof(XkbAction));
	    for (i=0;(i<nGroups)&&(i<nOldGroups);i++) {
		pOldType= XkbKeyKeyType(xkb,key,i);
		pNewType= &xkb->map->types[newTypes[i]];
		if (pNewType->num_levels>pOldType->num_levels)
		     nCopy= pOldType->num_levels;
		else nCopy= pNewType->num_levels;
		memcpy(&pActs[i*width],&oldActs[i*oldWidth],
						nCopy*sizeof(XkbAction));
	    }
	}
	i= xkb->map->key_sym_map[key].group_info;
	i= XkbSetNumGroups(i,nGroups);
	xkb->map->key_sym_map[key].group_info= i;
	xkb->map->key_sym_map[key].width= width;
    }
    width= 0;
    for (i=0;i<nGroups;i++) {
	xkb->map->key_sym_map[key].kt_index[i]= newTypes[i];
	if (xkb->map->types[newTypes[i]].num_levels>width)
	    width= xkb->map->types[newTypes[i]].num_levels;
    }
    xkb->map->key_sym_map[key].width= width;
    if (changes!=NULL) {
	if (changes->changed&XkbKeySymsMask) {
	    _XkbAddKeyChange(&changes->first_key_sym,&changes->num_key_syms,
	    								key);
	}
	else {
	    changes->changed|= XkbKeySymsMask;
	    changes->first_key_sym= key;
	    changes->num_key_syms= 1;
	}
    }
    return Success;
}

/***====================================================================***/

Bool
XkbVirtualModsToReal(XkbDescPtr xkb,unsigned virtual_mask,unsigned *mask_rtrn)
{
register int i,bit;
register unsigned mask;

    if (xkb==NULL)
	return False;
    if (virtual_mask==0) {
	*mask_rtrn= 0;
	return True;
    }
    if (xkb->server==NULL)
	return False;
    for (i=mask=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
	if (virtual_mask&bit)
	    mask|= xkb->server->vmods[i];
    }
    *mask_rtrn= mask;
    return True;
}

/***====================================================================***/

Bool
XkbUpdateActionVirtualMods(XkbDescPtr xkb,XkbAction *act,unsigned changed)
{
unsigned int	tmp;

    switch (act->type) {
	case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods:
	    if (((tmp= XkbModActionVMods(&act->mods))&changed)!=0) {
		XkbVirtualModsToReal(xkb,tmp,&tmp);
		act->mods.mask= act->mods.real_mods;
		act->mods.mask|= tmp;
		return True;
	    }
	    break;
	case XkbSA_ISOLock:
	    if ((((tmp= XkbModActionVMods(&act->iso))!=0)&changed)!=0) {
		XkbVirtualModsToReal(xkb,tmp,&tmp);
		act->iso.mask= act->iso.real_mods;
		act->iso.mask|= tmp;
		return True;
	    }
	    break;
    }
    return False;
}

void
XkbUpdateKeyTypeVirtualMods(	XkbDescPtr	xkb,
				XkbKeyTypePtr	type,
				unsigned int	changed,
				XkbChangesPtr 	changes)
{
register unsigned int	i;
unsigned int		mask;

    XkbVirtualModsToReal(xkb,type->mods.vmods,&mask);
    type->mods.mask= type->mods.real_mods|mask;
    if ((type->map_count>0)&&(type->mods.vmods!=0)) {
	XkbKTMapEntryPtr entry;
	for (i=0,entry=type->map;i<type->map_count;i++,entry++) {
	    if (entry->mods.vmods!=0) {
		XkbVirtualModsToReal(xkb,entry->mods.vmods,&mask);
		entry->mods.mask=entry->mods.real_mods|mask;
		/* entry is active if vmods are bound*/
	    	entry->active= (mask!=0);
	    }
	    else entry->active= 1;
	}
    }
    if (changes) {
	int	type_ndx;
	type_ndx= type-xkb->map->types;
	if ((type_ndx<0)||(type_ndx>xkb->map->num_types))
	    return;
	if (changes->map.changed&XkbKeyTypesMask) {
	    int last;
	    last= changes->map.first_type+changes->map.num_types-1;
	    if (type_ndx<changes->map.first_type) {
		changes->map.first_type= type_ndx;
		changes->map.num_types= (last-type_ndx)+1;
	    }
	    else if (type_ndx>last) {
		changes->map.num_types= (type_ndx-changes->map.first_type)+1;
	    }
	}
	else {
	    changes->map.changed|= XkbKeyTypesMask;
	    changes->map.first_type= type_ndx;
	    changes->map.num_types= 1;
	}
    }
    return;
}

Bool
XkbApplyVirtualModChanges(XkbDescPtr xkb,unsigned changed,XkbChangesPtr changes)
{
register int	i;
unsigned int	checkState = 0;

    if ((!xkb) || (!xkb->map) || (changed==0))
	return False;
    for (i=0;i<xkb->map->num_types;i++) {
	if (xkb->map->types[i].mods.vmods & changed)
	XkbUpdateKeyTypeVirtualMods(xkb,&xkb->map->types[i],changed,changes);
    }
    if (changed&xkb->ctrls->internal.vmods) {
	unsigned int	newMask;
	XkbVirtualModsToReal(xkb,xkb->ctrls->internal.vmods,&newMask);
	newMask|= xkb->ctrls->internal.real_mods;
	if (xkb->ctrls->internal.mask!=newMask) {
	    xkb->ctrls->internal.mask= newMask;
	    if (changes) {
		changes->ctrls.changed_ctrls|= XkbInternalModsMask;
		checkState= True;
	    }
	}
    }
    if (changed&xkb->ctrls->ignore_lock.vmods) {
	unsigned int	newMask;
	XkbVirtualModsToReal(xkb,xkb->ctrls->ignore_lock.vmods,&newMask);
	newMask|= xkb->ctrls->ignore_lock.real_mods;
	if (xkb->ctrls->ignore_lock.mask!=newMask) {
	    xkb->ctrls->ignore_lock.mask= newMask;
	    if (changes) {
		changes->ctrls.changed_ctrls|= XkbIgnoreLockModsMask;
		checkState= True;
	    }
	}
    }
    if (xkb->indicators!=NULL) {
	XkbIndicatorMapPtr map;
	map= &xkb->indicators->maps[0];
	for (i=0;i<XkbNumIndicators;i++,map++) {
	    if (map->mods.vmods&changed) {
		unsigned int newMask;
		XkbVirtualModsToReal(xkb,map->mods.vmods,&newMask);
		newMask|= map->mods.real_mods;
		if (newMask!=map->mods.mask) {
		    map->mods.mask= newMask;
		    if (changes) {
			changes->indicators.map_changes|= (1<<i);
			checkState= True;
		    }
		}
	    }
	}
    }
    if (xkb->compat!=NULL) {
	XkbCompatMapPtr	compat;
	compat= xkb->compat;
	for (i=0;i<XkbNumKbdGroups;i++) {
	    unsigned int newMask;
	    XkbVirtualModsToReal(xkb,compat->groups[i].vmods,&newMask);
	    newMask|= compat->groups[i].real_mods;
	    if (compat->groups[i].mask!=newMask) {
		compat->groups[i].mask= newMask;
		if (changes) {
		    changes->compat.changed_groups|= (1<<i);
		    checkState= True;
		}
	    }
	}
    }
    if (xkb->map && xkb->server) {
	int highChange = 0, lowChange = -1;
	for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
	    if (XkbKeyHasActions(xkb,i)) {
		register XkbAction *pAct;
		register int n;

		pAct= XkbKeyActionsPtr(xkb,i);
		for (n=XkbKeyNumActions(xkb,i);n>0;n--,pAct++) {
		    if ((pAct->type!=XkbSA_NoAction)&&
			XkbUpdateActionVirtualMods(xkb,pAct,changed)) {
			if (lowChange<0)
			    lowChange= i;
			highChange= i;
		    }
		}
	    }
	}
	if (changes && (lowChange>0)) { /* something changed */
	    if (changes->map.changed&XkbKeyActionsMask) {
		int last;
		if (changes->map.first_key_act<lowChange)
		    lowChange= changes->map.first_key_act;
		last= changes->map.first_key_act+changes->map.num_key_acts-1;
		if (last>highChange)
		    highChange= last;
	    }
	    changes->map.changed|= 	XkbKeyActionsMask;
	    changes->map.first_key_act=	lowChange;
	    changes->map.num_key_acts=	(highChange-lowChange)+1;
	}
    }
    return checkState;
}

--- NEW FILE: ddxBeep.c ---
/* $Xorg: ddxBeep.c,v 1.3 2000/08/17 19:53:45 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/ddxBeep.c,v 3.9 2002/12/05 21:59:00 paulo Exp $ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>

#if (defined(__osf__) && defined(__alpha))
#include <sys/sysinfo.h>
#include <alpha/hal_sysinfo.h>
#include <alpha/prom.h>
#endif

/*#define FALLING_TONE	1*/
/*#define RISING_TONE	1*/
#define FALLING_TONE	10
#define RISING_TONE	10
#define	SHORT_TONE	50
#define	SHORT_DELAY	60
#define	LONG_TONE	75
#define	VERY_LONG_TONE	100
#define	LONG_DELAY	85
#define CLICK_DURATION	1

#define	DEEP_PITCH	250
#define	LOW_PITCH	500
#define	MID_PITCH	1000
#define	HIGH_PITCH	2000
#define CLICK_PITCH	1500

static	unsigned long	atomGeneration= 0;
static	Atom	featureOn;
static	Atom	featureOff;
static	Atom	featureChange;
static	Atom	ledOn;
static	Atom	ledOff;
static	Atom	ledChange;
static	Atom	slowWarn;
static	Atom	slowPress;
static	Atom	slowReject;
static	Atom	slowAccept;
static	Atom	slowRelease;
static	Atom	stickyLatch;
static	Atom	stickyLock;
static	Atom	stickyUnlock;
static	Atom	bounceReject;
static  char 	doesPitch = 1;

#define	FEATURE_ON	"AX_FeatureOn"
#define	FEATURE_OFF	"AX_FeatureOff"
#define	FEATURE_CHANGE	"AX_FeatureChange"
#define	LED_ON		"AX_IndicatorOn"
#define	LED_OFF		"AX_IndicatorOff"
#define	LED_CHANGE	"AX_IndicatorChange"
#define	SLOW_WARN	"AX_SlowKeysWarning"
#define	SLOW_PRESS	"AX_SlowKeyPress"
#define	SLOW_REJECT	"AX_SlowKeyReject"
#define	SLOW_ACCEPT	"AX_SlowKeyAccept"
#define	SLOW_RELEASE	"AX_SlowKeyRelease"
#define	STICKY_LATCH	"AX_StickyLatch"
#define	STICKY_LOCK	"AX_StickyLock"
#define	STICKY_UNLOCK	"AX_StickyUnlock"
#define	BOUNCE_REJECT	"AX_BounceKeyReject"

#define	MAKE_ATOM(a)	MakeAtom(a,sizeof(a)-1,True)

static void
_XkbDDXBeepInitAtoms(void)
{
    featureOn= 		MAKE_ATOM(FEATURE_ON);
    featureOff= 	MAKE_ATOM(FEATURE_OFF);
    featureChange= 	MAKE_ATOM(FEATURE_CHANGE);
    ledOn= 		MAKE_ATOM(LED_ON);
    ledOff= 		MAKE_ATOM(LED_OFF);
    ledChange= 		MAKE_ATOM(LED_CHANGE);
    slowWarn= 		MAKE_ATOM(SLOW_WARN);
    slowPress= 		MAKE_ATOM(SLOW_PRESS);
    slowReject= 	MAKE_ATOM(SLOW_REJECT);
    slowAccept= 	MAKE_ATOM(SLOW_ACCEPT);
    slowRelease= 	MAKE_ATOM(SLOW_RELEASE);
    stickyLatch= 	MAKE_ATOM(STICKY_LATCH);
    stickyLock=		MAKE_ATOM(STICKY_LOCK);
    stickyUnlock= 	MAKE_ATOM(STICKY_UNLOCK);
    bounceReject= 	MAKE_ATOM(BOUNCE_REJECT);
#if (defined(__osf__) && defined(__alpha))
    /* [[[ WDW - Some bells do not allow for pitch changes.
     * Maybe this could become part of the keymap? ]]]
     */
    {
	char keyboard[8];

	/* Find the class of keyboard being used.
	 */
	keyboard[0] = '\0';
	if (-1 == getsysinfo(GSI_KEYBOARD, 
			     keyboard, sizeof(keyboard), 
			     0, NULL))
	    keyboard[0] = '\0';

	if ((strcmp(keyboard,"LK201") == 0) ||
	    (strcmp(keyboard,"LK401") == 0) ||
	    (strcmp(keyboard,"LK421") == 0) ||
	    (strcmp(keyboard,"LK443") == 0))
	    doesPitch = 0;
    }
#else
#if defined(sun)
    doesPitch = 0;
#endif
#endif
    return;
}

static CARD32
_XkbDDXBeepExpire(OsTimerPtr timer,CARD32 now,pointer arg)
{
DeviceIntPtr	dev= (DeviceIntPtr)arg;
KbdFeedbackPtr	feed;
KeybdCtrl *	ctrl;
XkbSrvInfoPtr	xkbInfo;
CARD32		next;
int		pitch,duration;
int		oldPitch,oldDuration;
Atom		name;

    if ((dev==NULL)||(dev->key==NULL)||(dev->key->xkbInfo==NULL)||
	(dev->kbdfeed==NULL))
	return 0;
    if (atomGeneration!=serverGeneration) {
	_XkbDDXBeepInitAtoms();
	atomGeneration= serverGeneration;
    }

    feed= dev->kbdfeed;
    ctrl= &feed->ctrl;
    xkbInfo= dev->key->xkbInfo;
    next= 0;
    pitch= oldPitch= ctrl->bell_pitch;
    duration= oldDuration= ctrl->bell_duration;
#ifdef DEBUG
    if (xkbDebugFlags>1)
	ErrorF("beep: %d (count= %d)\n",xkbInfo->beepType,xkbInfo->beepCount);
#endif
    name= None;
    switch (xkbInfo->beepType) {
	default:
	    ErrorF("Unknown beep type %d\n",xkbInfo->beepType);
	case _BEEP_NONE:
	    duration= 0;
	    break;

	/* When an LED is turned on, we want a high-pitched beep.
	 * When the LED it turned off, we want a low-pitched beep.
	 * If we cannot do pitch, we want a single beep for on and two
	 * beeps for off.
         */
	case _BEEP_LED_ON:
	    if (name==None)	name= ledOn;
	    duration= SHORT_TONE;
	    pitch= HIGH_PITCH;
	    break;
	case _BEEP_LED_OFF:
	    if (name==None)	name= ledOff;
	    duration= SHORT_TONE;
	    pitch= LOW_PITCH;
	    if (!doesPitch && xkbInfo->beepCount<1)
		next = SHORT_DELAY;	    
	    break;

	/* When a Feature is turned on, we want an up-siren.
	 * When a Feature is turned off, we want a down-siren.
	 * If we cannot do pitch, we want a single beep for on and two
	 * beeps for off.
         */
	case _BEEP_FEATURE_ON:
	    if (name==None)	name= featureOn;
	    if (xkbInfo->beepCount<1) {
		pitch= LOW_PITCH;
		duration= VERY_LONG_TONE;
		if (doesPitch)
		    next= SHORT_DELAY;
	    }
	    else {
		pitch= MID_PITCH;
		duration= SHORT_TONE;
	    }
	    break;

	case _BEEP_FEATURE_OFF:
	    if (name==None)	name= featureOff;
	    if (xkbInfo->beepCount<1) {
		pitch= MID_PITCH;
		if (doesPitch)
		     duration= VERY_LONG_TONE;
		else duration= SHORT_TONE;
		next= SHORT_DELAY;
	    }
	    else {
		pitch= LOW_PITCH;
		duration= SHORT_TONE;
	    }
	    break;

	/* Two high beeps indicate an LED or Feature changed
	 * state, but that another LED or Feature is also on.
	 * [[[WDW - This is not in AccessDOS ]]]
	 */
	case _BEEP_LED_CHANGE:
            if (name==None)	name= ledChange;
	case _BEEP_FEATURE_CHANGE:
	    if (name==None)	name= featureChange;
	    duration= SHORT_TONE;
	    pitch= HIGH_PITCH;
	    if (xkbInfo->beepCount<1) {
		next= SHORT_DELAY;
	    }
            break;

	/* Three high-pitched beeps are the warning that SlowKeys
	 * is going to be turned on or off.
	 */	  
	case _BEEP_SLOW_WARN:
	    if (name==None)	name= slowWarn;
	    duration= SHORT_TONE;
	    pitch= HIGH_PITCH;
	    if (xkbInfo->beepCount<2)
		next= SHORT_DELAY;
	    break;

	/* Click on SlowKeys press and accept.
	 * Deep pitch when a SlowKey or BounceKey is rejected.
	 * [[[WDW - Rejects are not in AccessDOS ]]]
	 * If we cannot do pitch, we want single beeps.
	 */	  
        case _BEEP_SLOW_PRESS:
	    if (name==None)	name= slowPress;
	case _BEEP_SLOW_ACCEPT:
	    if (name==None)	name= slowAccept;
	case _BEEP_SLOW_RELEASE:
	    if (name==None)	name= slowRelease;
	    duration= CLICK_DURATION;
	    pitch= CLICK_PITCH;
	    break;
	case _BEEP_BOUNCE_REJECT:
	    if (name==None)	name= bounceReject;
	case _BEEP_SLOW_REJECT:
	    if (name==None)	name= slowReject;
	    duration= SHORT_TONE;
	    pitch= DEEP_PITCH;
	    break;

	/* Low followed by high pitch when a StickyKey is latched.
	 * High pitch when a StickyKey is locked.
	 * Low pitch when unlocked.
         * If we cannot do pitch, two beeps for latch, nothing for
	 * lock, and two for unlock.
	 */	  
	case _BEEP_STICKY_LATCH:
	    if (name==None)	name= stickyLatch;
	    duration= SHORT_TONE;
	    if (xkbInfo->beepCount<1) {
		next= SHORT_DELAY;
		pitch= LOW_PITCH;
	    }
	    else pitch= HIGH_PITCH;
	    break;
	case _BEEP_STICKY_LOCK:
	    if (name==None)	name= stickyLock;
	    if (doesPitch) {
		duration= SHORT_TONE;
		pitch= HIGH_PITCH;
            }
	    break;
	case _BEEP_STICKY_UNLOCK:
	    if (name==None)	name= stickyUnlock;
	    duration= SHORT_TONE;
	    pitch= LOW_PITCH;
	    if (!doesPitch && xkbInfo->beepCount<1)
		next = SHORT_DELAY;	    
	    break;
    }
    if (timer == NULL && duration>0) {
	CARD32		starttime = GetTimeInMillis();
	CARD32		elapsedtime;

	ctrl->bell_duration= duration;
	ctrl->bell_pitch= pitch;
	if (xkbInfo->beepCount==0) {
	     XkbHandleBell(0,0,dev,ctrl->bell,(pointer)ctrl,KbdFeedbackClass,name,None,
									NULL);
	}
	else if (xkbInfo->desc->ctrls->enabled_ctrls&XkbAudibleBellMask) {
	    (*dev->kbdfeed->BellProc)(ctrl->bell,dev,(pointer)ctrl,KbdFeedbackClass);
	}
	ctrl->bell_duration= oldDuration;
	ctrl->bell_pitch= oldPitch;
	xkbInfo->beepCount++;

	/* Some DDX schedule the beep and return immediately, others don't
	   return until the beep is completed.  We measure the time and if
	   it's less than the beep duration, make sure not to schedule the
	   next beep until after the current one finishes. */

	elapsedtime = GetTimeInMillis();
	if (elapsedtime > starttime) { /* watch out for millisecond counter
					  overflow! */
	    elapsedtime -= starttime;
	} else {
	    elapsedtime = 0;
	}
	if (elapsedtime < duration) {
	    next += duration - elapsedtime;
	}

    }
    return next;
}

int
XkbDDXAccessXBeep(DeviceIntPtr dev,unsigned what,unsigned which)
{
XkbSrvInfoRec	*xkbInfo= dev->key->xkbInfo;
CARD32		 next;

    xkbInfo->beepType= what;
    xkbInfo->beepCount= 0;
    next= _XkbDDXBeepExpire(NULL,0,(pointer)dev);
    if (next>0) {
	xkbInfo->beepTimer= TimerSet(xkbInfo->beepTimer,
					0, next,
					_XkbDDXBeepExpire, (pointer)dev);
    }
    return 1;
}

--- NEW FILE: ddxConfig.c ---
/* $Xorg: ddxConfig.c,v 1.3 2000/08/17 19:53:45 cpqbld Exp $ */
/************************************************************
Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/ddxConfig.c,v 3.8 2002/12/20 20:18:35 paulo Exp $ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include "os.h"
#define	XKBSRV_NEED_FILE_FUNCS
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XKBconfig.h>

Bool
XkbDDXApplyConfig(XPointer cfg_in,XkbSrvInfoPtr info)
{
XkbConfigRtrnPtr 	rtrn;
XkbDescPtr		xkb;
Bool			ok;
XkbEventCauseRec	cause;

    xkb= info->desc;
    rtrn= (XkbConfigRtrnPtr)cfg_in;
    if (rtrn==NULL)
	return True;
    ok= XkbCFApplyRtrnValues(rtrn,XkbCFDflts,xkb);
    if (rtrn->initial_mods.replace) {
	info->state.locked_mods= rtrn->initial_mods.mods;
    }
    else {
	info->state.locked_mods|= rtrn->initial_mods.mods;
	if (rtrn->initial_mods.mods_clear)
	    info->state.locked_mods&= ~rtrn->initial_mods.mods_clear;
    }
    XkbComputeDerivedState(info);
    XkbSetCauseUnknown(&cause);
    XkbUpdateIndicators(info->device,XkbAllIndicatorsMask,False,NULL,&cause);
    if (info->device && info->device->kbdfeed) {
	DeviceIntPtr	dev;
	KeybdCtrl	newCtrl;
	dev= info->device;
	newCtrl= dev->kbdfeed->ctrl;
	if (rtrn->click_volume>=0)
	    newCtrl.click= rtrn->click_volume;
	if (rtrn->bell_volume>=0)
	    newCtrl.bell= rtrn->bell_volume;
	if (rtrn->bell_pitch>0)
	    newCtrl.bell_pitch= rtrn->bell_pitch;
	if (rtrn->bell_duration>0)
	    newCtrl.bell_duration= rtrn->bell_duration;
	if (dev->kbdfeed->CtrlProc)
	    (*dev->kbdfeed->CtrlProc)(dev,&newCtrl);
    }
    XkbCFFreeRtrn(rtrn,XkbCFDflts,xkb);
    return ok;
}

XPointer
XkbDDXPreloadConfig(	char **			rulesRtrn,
			XkbRF_VarDefsPtr 	defs,
			XkbComponentNamesPtr	names,
			DeviceIntPtr 		dev)
{
char			buf[PATH_MAX];
char *			dName;
FILE *			file;
XkbConfigRtrnPtr	rtrn;

#if defined(MetroLink)
    if (dev && dev->name)
	 dName= dev->name;
    else dName= "";
    /* It doesn't appear that XkbBaseDirectory could ever get set to NULL */
    sprintf(buf,"%s/X%s-config%s%s",XkbBaseDirectory,display,
 						(dName[0]?".":""),dName);
#else
    if (dev && dev->name)
	 dName= dev->name;
    else dName= "";
    if (XkbBaseDirectory!=NULL) {
	if (strlen(XkbBaseDirectory)+strlen(display)
		+strlen(dName)+10+(dName[0]?1:0) > PATH_MAX)
	{
#ifdef DEBUG
	    ErrorF("path exceeds max length\n");
#endif
	    return NULL;
	}
	sprintf(buf,"%s/X%s-config%s%s",XkbBaseDirectory,display,
						(dName[0]?".":""),dName);
    }
    else {
	if (strlen(display)+strlen(dName)+10+(dName[0]?1:0) > PATH_MAX)
	{
#ifdef DEBUG
	    ErrorF("path exceeds max length\n");
#endif
	    return NULL;
	}
        sprintf(buf,"X%s-config%s%s",display,(dName[0]?".":""),dName);
    }
#endif
#ifdef __UNIXOS2__
    strcpy(buf,(char*)__XOS2RedirRoot(buf));
#endif
#ifdef DEBUG
    ErrorF("Looking for keyboard configuration in %s...",buf);
#endif
    file= fopen(buf,"r");
    if (file==NULL) {
#ifdef DEBUG
	ErrorF("file not found\n");
#endif
	return NULL;
    }
    rtrn= _XkbTypedCalloc(1,XkbConfigRtrnRec);
    if (rtrn!=NULL) {
	if (!XkbCFParse(file,XkbCFDflts,NULL,rtrn)) {
#ifdef DEBUG
	    ErrorF("error\n");
#endif
	    ErrorF("Error parsing config file: ");
	    XkbCFReportError(stderr,buf,rtrn->error,rtrn->line);
	    _XkbFree(rtrn);
	    fclose(file);
	    return NULL;
	}
#ifdef DEBUG
	ErrorF("found it\n");
#endif
        if (rtrn->rules_file) {
	    *rulesRtrn= rtrn->rules_file;
	    rtrn->rules_file= NULL;
	}
	if (rtrn->model) {
	    defs->model= rtrn->model;
	    rtrn->model= NULL;
	}
	if (rtrn->layout) {
	    defs->layout= rtrn->layout;
	    rtrn->layout= NULL;
	}
	if (rtrn->variant) {
	    defs->variant= rtrn->variant;
	    rtrn->variant= NULL;
	}
	if (rtrn->options) {
	    defs->options= rtrn->options;
	    rtrn->options= NULL;
	}
	XkbSetRulesUsed(defs);

	if (rtrn->keycodes!=NULL) {
	    if (names->keycodes) _XkbFree(names->keycodes);
	    names->keycodes= rtrn->keycodes;
	    rtrn->keycodes= NULL;
	}
	if (rtrn->geometry!=NULL) {
	    if (names->geometry) _XkbFree(names->geometry);
	    names->geometry= rtrn->geometry;
	    rtrn->geometry= NULL;
	}
	if (rtrn->symbols!=NULL) {
	    if (rtrn->phys_symbols==NULL)
		rtrn->phys_symbols= _XkbDupString(names->symbols);
	    if (names->symbols) _XkbFree(names->symbols);
	    names->symbols= rtrn->symbols;
	    rtrn->symbols= NULL;
	}
	if (rtrn->types!=NULL) {
	    if (names->types) _XkbFree(names->types);
	    names->types= rtrn->types;
	    rtrn->types= NULL;
	}
	if (rtrn->compat!=NULL) {
	    if (names->compat) _XkbFree(names->compat);
	    names->compat= rtrn->compat;
	    rtrn->compat= NULL;
	}
    }
    fclose(file);
    return (XPointer)rtrn;
}

--- NEW FILE: ddxCtrls.c ---
/* $Xorg: ddxCtrls.c,v 1.3 2000/08/17 19:53:45 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/ddxCtrls.c,v 1.3 2001/01/17 22:37:14 dawes Exp $ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>

void
XkbDDXKeybdCtrlProc(DeviceIntPtr dev,KeybdCtrl *ctrl)
{
int realRepeat;

    realRepeat= ctrl->autoRepeat;
    if ((dev->kbdfeed)&&(XkbDDXUsesSoftRepeat(dev)))
	ctrl->autoRepeat= 0;
#ifdef DEBUG
if (xkbDebugFlags&0x4) {
    ErrorF("XkbDDXKeybdCtrlProc: setting repeat to %d (real repeat is %d)\n",
					ctrl->autoRepeat,realRepeat);
}
#endif
    if (dev->key && dev->key->xkbInfo && dev->key->xkbInfo->kbdProc)
	(*dev->key->xkbInfo->kbdProc)(dev,ctrl);
    ctrl->autoRepeat= realRepeat;
    return;
}


int
XkbDDXUsesSoftRepeat(DeviceIntPtr pXDev)
{
#ifndef XKB_ALWAYS_USES_SOFT_REPEAT
    if (pXDev && pXDev->kbdfeed ) {
	if (pXDev->kbdfeed->ctrl.autoRepeat) {
	    if (pXDev->key && pXDev->key->xkbInfo) {
		XkbDescPtr	xkb;
		xkb= pXDev->key->xkbInfo->desc;
		if ((xkb->ctrls->repeat_delay == 660) &&
		    (xkb->ctrls->repeat_interval == 40) &&
		    ((xkb->ctrls->enabled_ctrls&(XkbSlowKeysMask|
						 XkbBounceKeysMask|
						 XkbMouseKeysMask))==0)) {
			return 0;
		}
		return ((xkb->ctrls->enabled_ctrls&XkbRepeatKeysMask)!=0);
	    }
	}
    }
    return 0;
#else
    return 1;
#endif
}

void
XkbDDXChangeControls(DeviceIntPtr dev,XkbControlsPtr old,XkbControlsPtr new)
{
unsigned	changed, i;
unsigned 	char *rep_old, *rep_new, *rep_fb;

    changed= new->enabled_ctrls^old->enabled_ctrls;
#ifdef NOTDEF
    if (changed&XkbRepeatKeysMask) {
	if (dev->kbdfeed) {
	    int realRepeat;

	    if (new->enabled_ctrls&XkbRepeatKeysMask)
		 dev->kbdfeed->ctrl.autoRepeat= realRepeat= 1;
	    else dev->kbdfeed->ctrl.autoRepeat= realRepeat= 0;

	    if (XkbDDXUsesSoftRepeat(dev))
		dev->kbdfeed->ctrl.autoRepeat= FALSE;
	    if (dev->kbdfeed->CtrlProc)
		(*dev->kbdfeed->CtrlProc)(dev,&dev->kbdfeed->ctrl);
	    dev->kbdfeed->ctrl.autoRepeat= realRepeat;
	}
    }
#endif
    for (rep_old = old->per_key_repeat,
         rep_new = new->per_key_repeat,
	 rep_fb  = dev->kbdfeed->ctrl.autoRepeats,
         i = 0; i < XkbPerKeyBitArraySize; i++) {
        if (rep_old[i] != rep_new[i]) {
            rep_fb[i] = rep_new[i];
            changed &= XkbPerKeyRepeatMask;
        }
    }

    if (changed&XkbPerKeyRepeatMask) {
	if (dev->kbdfeed->CtrlProc)
	    (*dev->kbdfeed->CtrlProc)(dev,&dev->kbdfeed->ctrl);
    }
    return;
}


--- NEW FILE: ddxDevBtn.c ---
/* $Xorg: ddxDevBtn.c,v 1.3 2000/08/17 19:53:45 cpqbld Exp $ */
/************************************************************
Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/ddxDevBtn.c,v 3.3 2001/08/23 21:49:51 tsi Exp $ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>
#include <X11/extensions/XIproto.h>

extern	int	DeviceValuator;

void
XkbDDXFakeDeviceButton(DeviceIntPtr dev,Bool press,int button)
{
int *			devVal;
INT32 *			evVal;
xEvent			events[2];
deviceKeyButtonPointer *btn;
deviceValuator *	val;
int			x,y;
int			nAxes, i, count;

    if ((dev==(DeviceIntPtr)LookupPointerDevice())||(!dev->public.on))
	return;

    nAxes = (dev->valuator?dev->valuator->numAxes:0);
    if (nAxes > 6)
	nAxes = 6;

    GetSpritePosition(&x,&y);
    btn= (deviceKeyButtonPointer *) &events[0];
    val= (deviceValuator *) &events[1];
    if (press)		btn->type= DeviceButtonPress;
    else		btn->type= DeviceButtonRelease;
    btn->detail= 	button;
    btn->time= 		GetTimeInMillis();
    btn->root_x=	x;
    btn->root_y=	y;
    btn->deviceid= 	dev->id;
    count= 1;
    if (nAxes>0) {
	btn->deviceid|=	0x80;
	val->type = DeviceValuator;
	val->deviceid = dev->id;
	val->first_valuator = 0;

	evVal=	&val->valuator0;
	devVal= dev->valuator->axisVal;
	for (i=nAxes;i>0;i--) {
	    *evVal++ = *devVal++;
	    if (evVal > &val->valuator5) {
		int	tmp = val->first_valuator+6;
		val->num_valuators = 6;
		val++;
		evVal= &val->valuator0;
		val->first_valuator= tmp;
	    }
	}
	if ((nAxes % 6) != 0) {
	    val->num_valuators = (nAxes % 6);
	}
	count= 1+((nAxes+5)/6);
    }

    (*dev->public.processInputProc)((xEventPtr)btn, dev, count);
    return;
}

--- NEW FILE: ddxFakeBtn.c ---
/* $Xorg: ddxFakeBtn.c,v 1.3 2000/08/17 19:53:45 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86$ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>

void
XkbDDXFakePointerButton(int event,int button)
{
xEvent	ev;
int	x,y;
DevicePtr ptr;

    if ((ptr = LookupPointerDevice())==NULL)
	return;
    GetSpritePosition(&x,&y);
    ev.u.u.type = event;
    ev.u.u.detail = button;
    ev.u.keyButtonPointer.time = GetTimeInMillis();
    ev.u.keyButtonPointer.rootX = x;
    ev.u.keyButtonPointer.rootY = y;
    (*ptr->processInputProc)( &ev, (DeviceIntPtr)ptr, 1 );
    return;
}

--- NEW FILE: ddxFakeMtn.c ---
/* $XdotOrg: xc/programs/Xserver/xkb/ddxFakeMtn.c,v 1.1.4.5.2.2 2004/03/04 17:48:45 eich Exp $ */
/* $Xorg: ddxFakeMtn.c,v 1.3 2000/08/17 19:53:45 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/ddxFakeMtn.c,v 1.5 2003/09/13 16:39:01 dawes Exp $ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>

#ifdef PANORAMIX
#include "panoramiX.h"
#include "panoramiXsrv.h"
#endif

#include "mipointer.h"
#include "mipointrst.h"

void
XkbDDXFakePointerMotion(unsigned flags,int x,int y)
{
int 		   oldX,oldY;
ScreenPtr	   pScreen, oldScreen;

    GetSpritePosition(&oldX, &oldY);
    pScreen = oldScreen = GetSpriteWindow()->drawable.pScreen;

#ifdef PANORAMIX
    if (!noPanoramiXExtension) {
	BoxRec box;
	int i;

	if(!POINT_IN_REGION(pScreen, &XineramaScreenRegions[pScreen->myNum],
							    oldX, oldY, &box)) {
	    FOR_NSCREENS(i) {
		if(i == pScreen->myNum)
		    continue;
		if(POINT_IN_REGION(pScreen, &XineramaScreenRegions[i],
				   oldX, oldY, &box)) {
		    pScreen = screenInfo.screens[i];
		    break;
		}
	    }
	}
	oldScreen = pScreen;

	if (flags&XkbSA_MoveAbsoluteX)
	     oldX=  x;
	else oldX+= x;
	if (flags&XkbSA_MoveAbsoluteY)
	     oldY=  y;
	else oldY+= y;

	if(!POINT_IN_REGION(pScreen, &XineramaScreenRegions[pScreen->myNum],
							    oldX, oldY, &box)) {
	    FOR_NSCREENS(i) {
		if(i == pScreen->myNum)
		    continue;
		if(POINT_IN_REGION(pScreen, &XineramaScreenRegions[i],
				   oldX, oldY, &box)) {
		    pScreen = screenInfo.screens[i];
		    break;
		}
	    }
	}
	oldX -= panoramiXdataPtr[pScreen->myNum].x;
	oldY -= panoramiXdataPtr[pScreen->myNum].y;
    }
    else
#endif
    {
	if (flags&XkbSA_MoveAbsoluteX)
	     oldX=  x;
	else oldX+= x;
	if (flags&XkbSA_MoveAbsoluteY)
	     oldY=  y;
	else oldY+= y;

#define GetScreenPrivate(s) ((miPointerScreenPtr) ((s)->devPrivates[miPointerScreenIndex].ptr))	
	(*(GetScreenPrivate(oldScreen))->screenFuncs->CursorOffScreen)
	    (&pScreen, &oldX, &oldY);
    }

    if (pScreen != oldScreen)
	NewCurrentScreen(pScreen, oldX, oldY);
    if (pScreen->SetCursorPosition)
	(*pScreen->SetCursorPosition)(pScreen, oldX, oldY, TRUE);
}

--- NEW FILE: ddxInit.c ---
/* $Xorg: ddxInit.c,v 1.3 2000/08/17 19:53:45 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86$ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>

int
XkbDDXInitDevice(DeviceIntPtr dev)
{
    return 1;
}

--- NEW FILE: ddxKeyClick.c ---
/* $Xorg: ddxKeyClick.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86$ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>

void
XkbDDXKeyClick(DeviceIntPtr pXDev,int keycode,int synthetic)
{
#ifdef DEBUG
    if (xkbDebugFlags)
	ErrorF("Click.\n");
#endif
    return;
}

--- NEW FILE: ddxKillSrv.c ---
/* $Xorg: ddxKillSrv.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/ddxKillSrv.c,v 1.3 2002/11/23 19:27:50 tsi Exp $ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>

#ifdef XF86DDXACTIONS
#include "xf86.h"
#endif

int
XkbDDXTerminateServer(DeviceIntPtr dev,KeyCode key,XkbAction *act)
{
#ifdef XF86DDXACTIONS
    xf86ProcessActionEvent(ACTION_TERMINATE, NULL);
#else
    GiveUp(1);
#endif
    return 0;
}

--- NEW FILE: ddxLEDs.c ---
/* $Xorg: ddxLEDs.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86$ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>

void
XkbDDXUpdateIndicators(DeviceIntPtr dev,CARD32 new)
{
    dev->kbdfeed->ctrl.leds= new;
    (*dev->kbdfeed->CtrlProc)(dev,&dev->kbdfeed->ctrl);
    return;
}

void
XkbDDXUpdateDeviceIndicators(	DeviceIntPtr		dev,
				XkbSrvLedInfoPtr 	sli,
				CARD32 			new)
{
    if (sli->fb.kf==dev->kbdfeed)
	XkbDDXUpdateIndicators(dev,new);
    else if (sli->class==KbdFeedbackClass) {
	KbdFeedbackPtr	kf;
	kf= sli->fb.kf;
	if (kf && kf->CtrlProc) {
	    (*kf->CtrlProc)(dev,&kf->ctrl);
	}
    }
    else if (sli->class==LedFeedbackClass) {
	LedFeedbackPtr	lf;
	lf= sli->fb.lf;
	if (lf && lf->CtrlProc) {
	    (*lf->CtrlProc)(dev,&lf->ctrl);
	}
    }
    return;
}

--- NEW FILE: ddxList.c ---
/* $Xorg: ddxList.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */
/************************************************************
Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/ddxList.c,v 3.8 2003/07/16 01:39:05 dawes Exp $ */

#include <stdio.h>
#include <ctype.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xos.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include <X11/extensions/XKM.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#define	XKBSRV_NEED_FILE_FUNCS
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>

#ifndef PATH_MAX
#ifdef MAXPATHLEN
#define	PATH_MAX MAXPATHLEN
#else
#define	PATH_MAX 1024
#endif
#endif

/***====================================================================***/

static char *componentDirs[_XkbListNumComponents] = {
	"keymap", "keycodes", "types", "compat", "symbols", "geometry"
};

/***====================================================================***/

static Status
_AddListComponent(	XkbSrvListInfoPtr	list,
			int			what,
			unsigned		flags,
			char *			str,
			ClientPtr		client)
{
int		slen,wlen;
unsigned char *	wire8;
unsigned short *wire16;
char *		tmp;

    if (list->nTotal>=list->maxRtrn) {
	list->nTotal++;
	return Success;
    }
    tmp= strchr(str,')');
    if ((tmp==NULL)&&((tmp=strchr(str,'('))==NULL)) {
	slen= strlen(str);
	while ((slen>0) && isspace(str[slen-1])) {
	    slen--;
	}
    }
    else {
	slen= (tmp-str+1);
    }
    wlen= (((slen+1)/2)*2)+4;	/* four bytes for flags and length, pad to */
				/* 2-byte boundary */
    if ((list->szPool-list->nPool)<wlen) {
	if (wlen>1024)	list->szPool+= XkbPaddedSize(wlen*2);
	else		list->szPool+= 1024;
	list->pool= _XkbTypedRealloc(list->pool,list->szPool,char);
	if (!list->pool)
	    return BadAlloc;
    }
    wire16= (unsigned short *)&list->pool[list->nPool];
    wire8= (unsigned char *)&wire16[2];
    wire16[0]= flags;
    wire16[1]= slen;
    memcpy(wire8,str,slen);
    if (client->swapped) {
	register int n;
	swaps(&wire16[0],n);
	swaps(&wire16[1],n);
    }
    list->nPool+= wlen;
    list->nFound[what]++;
    list->nTotal++;
    return Success;
}

/***====================================================================***/
static Status
XkbDDXListComponent(	DeviceIntPtr 		dev,
			int			what,
			XkbSrvListInfoPtr	list,
			ClientPtr		client)
{
char 	*file,*map,*tmp,buf[PATH_MAX];
FILE 	*in;
Status	status;
int	rval;
Bool	haveDir;
#ifdef WIN32
char tmpname[32];
#endif    

    if ((list->pattern[what]==NULL)||(list->pattern[what][0]=='\0'))
	return Success;
    file= list->pattern[what];
    map= strrchr(file,'(');
    if (map!=NULL) {
	char *tmp;
	map++;
	tmp= strrchr(map,')');
	if ((tmp==NULL)||(tmp[1]!='\0')) {
	    /* illegal pattern.  No error, but no match */
	    return Success;
	}
    }

    in= NULL;
    haveDir= True;
#ifdef WIN32
    strcpy(tmpname, "\\temp\\xkb_XXXXXX");
    (void) mktemp(tmpname);
#endif
    if (XkbBaseDirectory!=NULL) {
	if (strlen(XkbBaseDirectory)+strlen(componentDirs[what])+6 > PATH_MAX)
	    return BadImplementation;
	if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
	    sprintf(buf,"%s/%s.dir",XkbBaseDirectory,componentDirs[what]);
	    in= fopen(buf,"r");
	}
	if (!in) {
	    haveDir= False;
	    if (strlen(XkbBaseDirectory)*2+strlen(componentDirs[what])
		    +(xkbDebugFlags>9?2:1)+strlen(file)+31 > PATH_MAX)
		return BadImplementation;
#ifndef WIN32
	    sprintf(buf,"%s/xkbcomp -R%s/%s -w %ld -l -vlfhpR '%s'",
		XkbBaseDirectory,XkbBaseDirectory,componentDirs[what],(long)
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
		file);
#else
	    sprintf(buf,"%s/xkbcomp -R%s/%s -w %ld -l -vlfhpR '%s' %s",
		XkbBaseDirectory,XkbBaseDirectory,componentDirs[what],(long)
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
		file, tmpname);
#endif
	}
    }
    else {
	if (strlen(XkbBaseDirectory)+strlen(componentDirs[what])+6 > PATH_MAX)
	    return BadImplementation;
	if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
	    sprintf(buf,"%s.dir",componentDirs[what]);
	    in= fopen(buf,"r");
	}
	if (!in) {
	    haveDir= False;
	    if (strlen(componentDirs[what])
		    +(xkbDebugFlags>9?2:1)+strlen(file)+29 > PATH_MAX)
		return BadImplementation;
#ifndef WIN32
	    sprintf(buf,"xkbcomp -R%s -w %ld -l -vlfhpR '%s'",
		componentDirs[what],(long)
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
		file);
#else
	    sprintf(buf,"xkbcomp -R%s -w %ld -l -vlfhpR '%s' %s",
		componentDirs[what],(long)
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
		file, tmpname);
#endif
	}
    }
    status= Success;
    if (!haveDir)
#ifndef WIN32
	in= Popen(buf,"r");
#else
    {
	if (System(buf) < 0)
	    ErrorF("Could not invoke keymap compiler\n");
	else
	    in= fopen(tmpname, "r");
    }
#endif
    if (!in)
	return BadImplementation;
    list->nFound[what]= 0;
    while ((status==Success)&&((tmp=fgets(buf,PATH_MAX,in))!=NULL)) {
	unsigned flags;
	register unsigned int i;
	if (*tmp=='#') /* comment, skip it */
	    continue;
	if (!strncmp(tmp, "Warning:", 8) || !strncmp(tmp, "        ", 8))
	    /* skip warnings too */
	    continue;
	flags= 0;
	/* each line in the listing is supposed to start with two */
	/* groups of eight characters, which specify the general  */
	/* flags and the flags that are specific to the component */
	/* if they're missing, fail with BadImplementation	  */
	for (i=0;(i<8)&&(status==Success);i++) { /* read the general flags */
	   if (isalpha(*tmp))	flags|= (1L<<i);
	   else if (*tmp!='-')	status= BadImplementation;
	   tmp++;
	}
	if (status != Success)  break;
	if (!isspace(*tmp)) {
	     status= BadImplementation;
	     break;
	}
	else tmp++;
	for (i=0;(i<8)&&(status==Success);i++) { /* read the component flags */
	   if (isalpha(*tmp))	flags|= (1L<<(i+8));
	   else if (*tmp!='-')	status= BadImplementation;
	   tmp++;
	}
	if (status != Success)  break;
	if (isspace(*tmp)) {
	    while (isspace(*tmp)) {
		tmp++;
	    }
	}
	else {
	    status= BadImplementation;
	    break;
	}
	status= _AddListComponent(list,what,flags,tmp,client);
    }
#ifndef WIN32
    if (haveDir)
	fclose(in);
    else if ((rval=pclose(in))!=0) {
	if (xkbDebugFlags)
	    ErrorF("xkbcomp returned exit code %d\n",rval);
    }
#else
    fclose(in);
#endif
    return status;
}

/***====================================================================***/

/* ARGSUSED */
Status
XkbDDXList(DeviceIntPtr	dev,XkbSrvListInfoPtr list,ClientPtr client)
{
Status	status;

    status= XkbDDXListComponent(dev,_XkbListKeymaps,list,client);
    if (status==Success)
	status= XkbDDXListComponent(dev,_XkbListKeycodes,list,client);
    if (status==Success)
	status= XkbDDXListComponent(dev,_XkbListTypes,list,client);
    if (status==Success)
	status= XkbDDXListComponent(dev,_XkbListCompat,list,client);
    if (status==Success)
	status= XkbDDXListComponent(dev,_XkbListSymbols,list,client);
    if (status==Success)
	status= XkbDDXListComponent(dev,_XkbListGeometry,list,client);
    return status;
}

--- NEW FILE: ddxLoad.c ---
/* $Xorg: ddxLoad.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/ddxLoad.c,v 3.35 2003/10/02 13:30:12 eich Exp $ */

#include <stdio.h>
#include <ctype.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xos.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include <X11/extensions/XKM.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#define	XKBSRV_NEED_FILE_FUNCS
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>
#include "xkb.h"

#if defined(CSRG_BASED) || defined(linux) || defined(__sgi) || defined(AIXV3) || defined(__osf__) || defined(__GNU__)
#include <paths.h>
#endif

#ifndef PATH_MAX
#ifdef MAXPATHLEN
#define	PATH_MAX MAXPATHLEN
#else
#define	PATH_MAX 1024
#endif
#endif

	/*
	 * If XKM_OUTPUT_DIR specifies a path without a leading slash, it is
	 * relative to the top-level XKB configuration directory.
	 * Making the server write to a subdirectory of that directory
	 * requires some work in the general case (install procedure
	 * has to create links to /var or somesuch on many machines),
	 * so we just compile into /usr/tmp for now.
	 */
#ifndef XKM_OUTPUT_DIR
#define	XKM_OUTPUT_DIR	"compiled/"
#endif

#define	PRE_ERROR_MSG "\"The XKEYBOARD keymap compiler (xkbcomp) reports:\""
#define	ERROR_PREFIX	"\"> \""
#define	POST_ERROR_MSG1 "\"Errors from xkbcomp are not fatal to the X server\""
#define	POST_ERROR_MSG2 "\"End of messages from xkbcomp\""

static void
OutputDirectory(
    char* outdir)
{
#ifndef WIN32
    if (getuid() == 0) {
	/* if server running as root it *may* be able to write */
	/* FIXME: check whether directory is writable at all */
	(void) strcpy (outdir, XKM_OUTPUT_DIR);
    } else
#endif
    {
#ifdef _PATH_VARTMP
	(void) strcpy (outdir, _PATH_VARTMP);
	if (outdir[strlen(outdir) - 1] != '/')	/* Hi IBM, Digital */
	    (void) strcat (outdir, "/");
#else
	(void) strcpy (outdir, "/tmp/");
#endif
    }
}

Bool
XkbDDXCompileNamedKeymap(	XkbDescPtr		xkb,
				XkbComponentNamesPtr	names,
				char *			nameRtrn,
				int			nameRtrnLen)
{
char 	cmd[PATH_MAX],file[PATH_MAX],xkm_output_dir[PATH_MAX],*map,*outFile;

    if (names->keymap==NULL)
	return False;
    strncpy(file,names->keymap,PATH_MAX); file[PATH_MAX-1]= '\0';
    if ((map= strrchr(file,'('))!=NULL) {
	char *tmp;
	if ((tmp= strrchr(map,')'))!=NULL) {
	    *map++= '\0';
	    *tmp= '\0';
	}
	else {
	    map= NULL;
	}
    }
    if ((outFile= strrchr(file,'/'))!=NULL)
	 outFile= _XkbDupString(&outFile[1]);
    else outFile= _XkbDupString(file);
    XkbEnsureSafeMapName(outFile);
    OutputDirectory(xkm_output_dir);

    if (XkbBaseDirectory!=NULL) {
#ifdef __UNIXOS2__
        char *tmpbase = (char*)__XOS2RedirRoot(XkbBaseDirectory);
        int i;
	if (strlen(tmpbase)*2+(xkbDebugFlags>9?2:1)
#else
	if (strlen(XkbBaseDirectory)*2+(xkbDebugFlags>9?2:1)
#endif
		+(map?strlen(map)+3:0)+strlen(PRE_ERROR_MSG)
		+strlen(ERROR_PREFIX)+strlen(POST_ERROR_MSG1)
		+strlen(file)+strlen(xkm_output_dir)
		+strlen(outFile)+53 > PATH_MAX)
	{
	    ErrorF("compiler command for keymap (%s) exceeds max length\n",
								names->keymap);
	    return False;
	}
#ifndef __UNIXOS2__
	sprintf(cmd,"%s/xkbcomp -w %d -R%s -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s %s%s.xkm",
		XkbBaseDirectory,
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
		XkbBaseDirectory,(map?"-m ":""),(map?map:""),
		PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,file,
		xkm_output_dir,outFile);
#else
	for (i=0; i<strlen(tmpbase); i++) if (tmpbase[i]=='/') tmpbase[i]='\\';
	sprintf(cmd,"%s\\xkbcomp -w %d -R%s -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s %s%s.xkm",
		tmpbase,
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
		tmpbase,(map?"-m ":""),(map?map:""),
		PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,file,
		xkm_output_dir,outFile);
	ErrorF("Command line for XKB is %s\n",cmd);
#endif
    }
    else {
	if ((xkbDebugFlags>9?2:1)+(map?strlen(map)+3:0)+strlen(PRE_ERROR_MSG)
		+strlen(ERROR_PREFIX)+strlen(POST_ERROR_MSG1)
		+strlen(file)+strlen(xkm_output_dir)
		+strlen(outFile)+49 > PATH_MAX)
	{
            ErrorF("compiler command for keymap (%s) exceeds max length\n",
							names->keymap);
	    return False;
	}
	sprintf(cmd,"xkbcomp -w %d -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s %s%s.xkm",
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
		(map?"-m ":""),(map?map:""),
		PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,file,
		xkm_output_dir,outFile);
    }
#ifdef DEBUG
    if (xkbDebugFlags) {
	ErrorF("XkbDDXCompileNamedKeymap compiling keymap using:\n");
	ErrorF("    \"cmd\"\n");
    }
#endif
    if (System(cmd)==0) {
	if (nameRtrn) {
	    strncpy(nameRtrn,outFile,nameRtrnLen);
	    nameRtrn[nameRtrnLen-1]= '\0';
	}
	if (outFile!=NULL)
	    _XkbFree(outFile);
	return True;
    } 
#ifdef DEBUG
    ErrorF("Error compiling keymap (%s)\n",names->keymap);
#endif
    if (outFile!=NULL)
	_XkbFree(outFile);
    return False;
}
        	
Bool    	
XkbDDXCompileKeymapByNames(	XkbDescPtr		xkb,
				XkbComponentNamesPtr	names,
				unsigned		want,
				unsigned		need,
				char *			nameRtrn,
				int			nameRtrnLen)
{
FILE *	out;
char	buf[PATH_MAX],keymap[PATH_MAX],xkm_output_dir[PATH_MAX];
#ifdef WIN32
char tmpname[32];
#endif    
#ifdef __UNIXOS2__
char *tmpbase;
int i;
#endif
    if ((names->keymap==NULL)||(names->keymap[0]=='\0')) {
	sprintf(keymap,"server-%s",display);
    }
    else {
	if (strlen(names->keymap) > PATH_MAX - 1) {
	    ErrorF("name of keymap (%s) exceeds max length\n", names->keymap);
	    return False;
	}
	strcpy(keymap,names->keymap);
    }

    XkbEnsureSafeMapName(keymap);
    OutputDirectory(xkm_output_dir);
#ifdef WIN32
    strcpy(tmpname, "\\temp\\xkb_XXXXXX");
    (void) mktemp(tmpname);
#endif
#ifdef __UNIXOS2__
    tmpbase = (char*)__XOS2RedirRoot(XkbBaseDirectory);
#endif
    if (XkbBaseDirectory!=NULL) {
	if (strlen(XkbBaseDirectory)*2+(xkbDebugFlags>9?2:1)
		+strlen(PRE_ERROR_MSG)+strlen(ERROR_PREFIX)
		+strlen(POST_ERROR_MSG1)+strlen(xkm_output_dir)
		+strlen(keymap)+48 > PATH_MAX)
	{
            ErrorF("compiler command for keymap (%s) exceeds max length\n",
							names->keymap);
	    return False;
	}
#ifndef WIN32
#ifndef __UNIXOS2__
	sprintf(buf,
	   "%s/xkbcomp -w %d -R%s -xkm - -em1 %s -emp %s -eml %s \"%s%s.xkm\"",
		XkbBaseDirectory,
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
		XkbBaseDirectory,
		PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,
		xkm_output_dir,keymap);
#else
	for (i=0; i<strlen(tmpbase); i++) if (tmpbase[i]=='/') tmpbase[i]='\\';
	sprintf(buf,
	  "%s\\xkbcomp -w %d -R%s -xkm - -em1 %s -emp %s -eml %s \"%s%s.xkm\"",
		tmpbase,
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
		tmpbase,
		PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,
		xkm_output_dir,keymap);
#endif
#else
	sprintf(buf,
      "%s/xkbcomp -w %d -R%s -xkm - -em1 %s -emp %s -eml %s \"%s%s.xkm\" < %s",
		XkbBaseDirectory,
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
		XkbBaseDirectory,
		PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,
		xkm_output_dir,keymap,tmpname);
#endif
    }
    else {
	if ((xkbDebugFlags>9?2:1)+strlen(PRE_ERROR_MSG)
		+strlen(ERROR_PREFIX)+strlen(POST_ERROR_MSG1)
		+strlen(xkm_output_dir)+strlen(keymap)+44 > PATH_MAX)
	{
            ErrorF("compiler command for keymap (%s) exceeds max length\n",
							names->keymap);
	    return False;
	}
#ifndef WIN32
	sprintf(buf,
		"xkbcomp -w %d -xkm - -em1 %s -emp %s -eml %s \"%s%s.xkm\"",
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
		PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,
		xkm_output_dir,keymap);
#else
	sprintf(buf,
	      "xkbcomp -w %d -xkm - -em1 %s -emp %s -eml %s \"%s%s.xkm\" < %s",
		((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
		PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,
		xkm_output_dir,keymap,tmpname);
#endif
    }
#ifndef WIN32
    out= Popen(buf,"w");
#else
    out= fopen(tmpname, "w");
#endif
    if (out!=NULL) {
#ifdef DEBUG
    if (xkbDebugFlags) {
       ErrorF("XkbDDXCompileKeymapByNames compiling keymap:\n");
       XkbWriteXKBKeymapForNames(stderr,names,NULL,xkb,want,need);
    }
#endif
	XkbWriteXKBKeymapForNames(out,names,NULL,xkb,want,need);
#ifndef WIN32
	if (Pclose(out)==0)
#else
	if (fclose(out)==0)
#endif
	{
#ifdef WIN32
	    if (System(buf) < 0)
		ErrorF("Could not invoke keymap compiler\n");
	    else {
#endif
	    if (nameRtrn) {
		strncpy(nameRtrn,keymap,nameRtrnLen);
		nameRtrn[nameRtrnLen-1]= '\0';
	    }
#if defined(Lynx) && defined(__i386__) && defined(NEED_POPEN_WORKAROUND)
	/* somehow popen/pclose is broken on LynxOS AT 2.3.0/2.4.0!
	 * the problem usually shows up with XF86Setup
	 * this hack waits at max 5 seconds after pclose() returns
	 * for the output of the xkbcomp output file.
	 * I didn't manage to get a patch in time for the 3.2 release
	 */
            {
		int i;
		char name[PATH_MAX];
                if (XkbBaseDirectory!=NULL)
		    sprintf(name,"%s/%s%s.xkm", XkbBaseDirectory
			,xkm_output_dir, keymap);
		else
                    sprintf(name,"%s%s.xkm", xkm_output_dir, keymap);
		for (i = 0; i < 10; i++) {
	            if (access(name, 0) == 0) break;
		    usleep(500000);
		}
#ifdef DEBUG
		if (i) ErrorF(">>>> Waited %d times for %s\n", i, name);
#endif
	    }
#endif
	    return True;
#ifdef WIN32
	    }
#endif
	}
#ifdef DEBUG
	else
	    ErrorF("Error compiling keymap (%s)\n",keymap);
#endif
    }
#ifdef DEBUG
    else {
#ifndef WIN32
	ErrorF("Could not invoke keymap compiler\n");
#else
	ErrorF("Could not open file %s\n", tmpname);
#endif
    }
#endif
    if (nameRtrn)
	nameRtrn[0]= '\0';
    return False;
}

FILE *
XkbDDXOpenConfigFile(char *mapName,char *fileNameRtrn,int fileNameRtrnLen)
{
char	buf[PATH_MAX],xkm_output_dir[PATH_MAX];
FILE *	file;

    buf[0]= '\0';
    if (mapName!=NULL) {
	OutputDirectory(xkm_output_dir);
	if ((XkbBaseDirectory!=NULL)&&(xkm_output_dir[0]!='/')) {
	    if (strlen(XkbBaseDirectory)+strlen(xkm_output_dir)
		     +strlen(mapName)+6 <= PATH_MAX)
	    {
	        sprintf(buf,"%s/%s%s.xkm",XkbBaseDirectory,
					xkm_output_dir,mapName);
	    }
	}
	else if (strlen(xkm_output_dir)+strlen(mapName)+5 <= PATH_MAX)
	    sprintf(buf,"%s%s.xkm",xkm_output_dir,mapName);
	if (buf[0] != '\0')
	    file= fopen(buf,"rb");
	else file= NULL;
    }
    else file= NULL;
    if ((fileNameRtrn!=NULL)&&(fileNameRtrnLen>0)) {
	strncpy(fileNameRtrn,buf,fileNameRtrnLen);
	buf[fileNameRtrnLen-1]= '\0';
    }
    return file;
}

unsigned
XkbDDXLoadKeymapByNames(	DeviceIntPtr		keybd,
				XkbComponentNamesPtr	names,
				unsigned		want,
				unsigned		need,
				XkbFileInfo *		finfoRtrn,
				char *			nameRtrn,
				int 			nameRtrnLen)
{
XkbDescPtr	xkb;
FILE	*	file;
char		fileName[PATH_MAX];
unsigned	missing;

    bzero(finfoRtrn,sizeof(XkbFileInfo));
    if ((keybd==NULL)||(keybd->key==NULL)||(keybd->key->xkbInfo==NULL))
	 xkb= NULL;
    else xkb= keybd->key->xkbInfo->desc;
    if ((names->keycodes==NULL)&&(names->types==NULL)&&
	(names->compat==NULL)&&(names->symbols==NULL)&&
	(names->geometry==NULL)) {
	if (names->keymap==NULL) {
	    bzero(finfoRtrn,sizeof(XkbFileInfo));
	    if (xkb && XkbDetermineFileType(finfoRtrn,XkbXKMFile,NULL) &&
	   				((finfoRtrn->defined&need)==need) ) {
		finfoRtrn->xkb= xkb;
		nameRtrn[0]= '\0';
		return finfoRtrn->defined;
	    }
	    return 0;
	}
	else if (!XkbDDXCompileNamedKeymap(xkb,names,nameRtrn,nameRtrnLen)) {
#ifdef NOISY
	    ErrorF("Couldn't compile keymap file\n");
#endif
	    return 0;
	}
    }
    else if (!XkbDDXCompileKeymapByNames(xkb,names,want,need,
						nameRtrn,nameRtrnLen)){
#ifdef NOISY
	ErrorF("Couldn't compile keymap file\n");
#endif
	return 0;
    }
    file= XkbDDXOpenConfigFile(nameRtrn,fileName,PATH_MAX);
    if (file==NULL) {
	LogMessage(X_ERROR, "Couldn't open compiled keymap file %s\n",fileName);
	return 0;
    }
    missing= XkmReadFile(file,need,want,finfoRtrn);
    if (finfoRtrn->xkb==NULL) {
	LogMessage(X_ERROR, "Error loading keymap %s\n",fileName);
	fclose(file);
	(void) unlink (fileName);
	return 0;
    }
#ifdef DEBUG
    else if (xkbDebugFlags) {
	ErrorF("Loaded %s, defined=0x%x\n",fileName,finfoRtrn->defined);
    }
#endif
    fclose(file);
    (void) unlink (fileName);
    return (need|want)&(~missing);
}

Bool
XkbDDXNamesFromRules(	DeviceIntPtr		keybd,
			char *			rules_name,
			XkbRF_VarDefsPtr	defs,
			XkbComponentNamesPtr	names)
{
char 		buf[PATH_MAX];
FILE *		file;
Bool		complete;
XkbRF_RulesPtr	rules;

    if (!rules_name)
	return False;
    if (XkbBaseDirectory==NULL) {
	if (strlen(rules_name)+7 > PATH_MAX)
	    return False;
	sprintf(buf,"rules/%s",rules_name);
    }
    else {
	if (strlen(XkbBaseDirectory)+strlen(rules_name)+8 > PATH_MAX)
	    return False;
        sprintf(buf,"%s/rules/%s",XkbBaseDirectory,rules_name);
    }
    if ((file= fopen(buf,"r"))==NULL)
	return False;
    if ((rules= XkbRF_Create(0,0))==NULL) {
	fclose(file);
	return False;
    }
    if (!XkbRF_LoadRules(file,rules)) {
	fclose(file);
	XkbRF_Free(rules,True);
	return False;
    }
    bzero((char *)names,sizeof(XkbComponentNamesRec));
    complete= XkbRF_GetComponents(rules,defs,names);
    fclose(file);
    XkbRF_Free(rules,True);
    return complete;
}



--- NEW FILE: ddxPrivate.c ---
/* $XFree86: xc/programs/Xserver/xkb/ddxPrivate.c,v 1.2 2003/04/03 16:20:22 dawes Exp $ */

#include <stdio.h>
#define NEED_EVENTS 1
#include <X11/X.h>
#include "windowstr.h"
#define XKBSRV_NEED_FILE_FUNCS
#include <X11/extensions/XKBsrv.h>

#ifdef XF86DDXACTIONS
#include "xf86.h"
#endif

int
XkbDDXPrivate(DeviceIntPtr dev,KeyCode key,XkbAction *act)
{
#ifdef XF86DDXACTIONS
    XkbAnyAction *xf86act = &(act->any);
    char msgbuf[XkbAnyActionDataSize+1];

    if (xf86act->type == XkbSA_XFree86Private) {
	memcpy(msgbuf, xf86act->data, XkbAnyActionDataSize);
	msgbuf[XkbAnyActionDataSize]= '\0';
	if (_XkbStrCaseCmp(msgbuf, "-vmode")==0)
	    xf86ProcessActionEvent(ACTION_PREV_MODE, NULL);
	else if (_XkbStrCaseCmp(msgbuf, "+vmode")==0)
	    xf86ProcessActionEvent(ACTION_NEXT_MODE, NULL);
	else if (_XkbStrCaseCmp(msgbuf, "ungrab")==0)
	    xf86ProcessActionEvent(ACTION_DISABLEGRAB, NULL);
	else if (_XkbStrCaseCmp(msgbuf, "clsgrb")==0)
	    xf86ProcessActionEvent(ACTION_CLOSECLIENT, NULL);
	else
	    xf86ProcessActionEvent(ACTION_MESSAGE, (void *) msgbuf);
    }
#endif
    return 0;
}


--- NEW FILE: ddxVT.c ---
/* $Xorg: ddxVT.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/ddxVT.c,v 1.3 2002/11/23 19:27:50 tsi Exp $ */

#include <stdio.h>
#define	NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XI.h>

#ifdef XF86DDXACTIONS
#include "xf86.h"
#endif

int
XkbDDXSwitchScreen(DeviceIntPtr dev,KeyCode key,XkbAction *act)
{
#ifdef XF86DDXACTIONS
    {
	int scrnnum = XkbSAScreen(&act->screen);

	if (act->screen.flags & XkbSA_SwitchApplication) {
	    if (act->screen.flags & XkbSA_SwitchAbsolute)
		xf86ProcessActionEvent(ACTION_SWITCHSCREEN,(void *) &scrnnum);
	    else {
		if (scrnnum < 0)
		    xf86ProcessActionEvent(ACTION_SWITCHSCREEN_PREV,NULL);
		else
		    xf86ProcessActionEvent(ACTION_SWITCHSCREEN_NEXT,NULL);
	    }
	}
    }
#endif
    return 1;
}

--- NEW FILE: maprules.c ---
/* $Xorg: maprules.c,v 1.4 2000/08/17 19:46:43 cpqbld Exp $ */
/************************************************************
 Copyright (c) 1996 by Silicon Graphics Computer Systems, Inc.

 Permission to use, copy, modify, and distribute this
 software and its documentation for any purpose and without
 fee is hereby granted, provided that the above copyright
 notice appear in all copies and that both that copyright
 notice and this permission notice appear in supporting
 documentation, and that the name of Silicon Graphics not be 
 used in advertising or publicity pertaining to distribution 
 of the software without specific prior written permission.
 Silicon Graphics makes no representation about the suitability 
 of this software for any purpose. It is provided "as is"
 without any express or implied warranty.
 
 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...1437 lines suppressed...]
    }
    pval[out++]= '\0';
    if (var_defs->options) {
        strcpy(&pval[out],var_defs->options);
        out+= strlen(var_defs->options);
    }
    pval[out++]= '\0';
    if (out!=len) {
	_XkbLibError(_XkbErrBadLength,"XkbRF_SetNamesProp",out);
	_XkbFree(pval);
	return False;
    }

    XChangeProperty(dpy,DefaultRootWindow(dpy),name,XA_STRING,8,PropModeReplace,
                                                (unsigned char *)pval,len);
    _XkbFree(pval);
    return True;
}

#endif

--- NEW FILE: xf86KillSrv.c ---
#define XF86DDXACTIONS
#include "./ddxKillSrv.c"

--- NEW FILE: xf86Private.c ---
#define XF86DDXACTIONS
#include "./ddxPrivate.c"

--- NEW FILE: xf86VT.c ---
#define XF86DDXACTIONS
#include "./ddxVT.c"

--- NEW FILE: xkb.c ---
/* $Xorg: xkb.c,v 1.3 2000/08/17 19:53:46 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...6190 lines suppressed...]
}

void
XkbExtensionInit(INITARGS)
{
    ExtensionEntry *extEntry;

    if ((extEntry = AddExtension(XkbName, XkbNumberEvents, XkbNumberErrors,
				 ProcXkbDispatch, SProcXkbDispatch,
				 XkbResetProc, StandardMinorOpcode))) {
	XkbReqCode = (unsigned char)extEntry->base;
	XkbEventBase = (unsigned char)extEntry->eventBase;
	XkbErrorBase = (unsigned char)extEntry->errorBase;
	XkbKeyboardErrorCode = XkbErrorBase+XkbKeyboard;
	RT_XKBCLIENT = CreateNewResourceType(XkbClientGone);
    }
    return;
}



--- NEW FILE: xkb.h ---
/* $XFree86$ */

/* #include "XKBfile.h" */

extern int ProcXkbUseExtension(ClientPtr client);
extern int ProcXkbSelectEvents(ClientPtr client);
extern int ProcXkbBell(ClientPtr client);
extern int ProcXkbGetState(ClientPtr client);
extern int ProcXkbLatchLockState(ClientPtr client);
extern int ProcXkbGetControls(ClientPtr client);
extern int ProcXkbSetControls(ClientPtr client);
extern int ProcXkbGetMap(ClientPtr client);
extern int ProcXkbSetMap(ClientPtr client);
extern int ProcXkbGetCompatMap(ClientPtr client);
extern int ProcXkbSetCompatMap(ClientPtr client);
extern int ProcXkbGetIndicatorState(ClientPtr client);
extern int ProcXkbGetIndicatorMap(ClientPtr client);
extern int ProcXkbSetIndicatorMap(ClientPtr client);
extern int ProcXkbGetNamedIndicator(ClientPtr client);
extern int ProcXkbSetNamedIndicator(ClientPtr client);
extern int ProcXkbGetNames(ClientPtr client);
extern int ProcXkbSetNames(ClientPtr client);
extern int ProcXkbGetGeometry(ClientPtr client);
extern int ProcXkbSetGeometry(ClientPtr client);
extern int ProcXkbPerClientFlags(ClientPtr client);
extern int ProcXkbListComponents(ClientPtr client);
extern int ProcXkbGetKbdByName(ClientPtr client);
extern int ProcXkbGetDeviceInfo(ClientPtr client);
extern int ProcXkbSetDeviceInfo(ClientPtr client);
extern int ProcXkbSetDebuggingFlags(ClientPtr client);

extern int XkbSetRepeatRate(DeviceIntPtr dev, int timeout, int interval, int major, int minor);
extern int XkbGetRepeatRate(DeviceIntPtr dev, int *timeout, int *interval);

extern Status XkbComputeGetIndicatorMapReplySize(
    XkbIndicatorPtr             indicators,
    xkbGetIndicatorMapReply     *rep);
extern int XkbSendIndicatorMap(
    ClientPtr                   client,
    XkbIndicatorPtr             indicators,
    xkbGetIndicatorMapReply     *rep);

extern void XkbComputeCompatState(XkbSrvInfoPtr xkbi);
extern void XkbSetPhysicalLockingKey(DeviceIntPtr dev, unsigned key);

extern Bool XkbFilterEvents(ClientPtr pClient, int nEvents, xEvent *xE);

extern Bool XkbApplyLEDChangeToKeyboard(
    XkbSrvInfoPtr           xkbi,
    XkbIndicatorMapPtr      map,
    Bool                    on,
    XkbChangesPtr           change);

extern Bool XkbWriteRulesProp(ClientPtr client, pointer closure);

extern XkbAction XkbGetButtonAction(DeviceIntPtr kbd, DeviceIntPtr dev, int button);

/* extern Status XkbMergeFile(XkbDescPtr xkb, XkbFileInfo finfo); */

extern Bool XkbDDXCompileNamedKeymap(
    XkbDescPtr              xkb,
    XkbComponentNamesPtr    names,
    char *                  nameRtrn,
    int                     nameRtrnLen);

extern Bool XkbDDXCompileKeymapByNames(
    XkbDescPtr              xkb,
    XkbComponentNamesPtr    names,
    unsigned                want,
    unsigned                need,
    char *                  nameRtrn,
    int                     nameRtrnLen);

--- NEW FILE: xkbAccessX.c ---
/* $Xorg: xkbAccessX.c,v 1.4 2001/02/05 18:50:20 coskrey Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/xkbAccessX.c,v 1.9 2001/08/23 14:33:25 alanh Exp $ */

#include <stdio.h>
#include <math.h>
#ifdef __QNX__
#include <limits.h>
#endif
#define NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "inputstr.h"
#include <X11/extensions/XKBsrv.h>
#if !defined(WIN32) && !defined(Lynx)
#include <sys/time.h>
#endif

int	XkbDfltRepeatDelay=	660;
int	XkbDfltRepeatInterval=	40;
pointer	XkbLastRepeatEvent=	NULL;

#define	DFLT_TIMEOUT_CTRLS (XkbAX_KRGMask|XkbStickyKeysMask|XkbMouseKeysMask)
#define	DFLT_TIMEOUT_OPTS  (XkbAX_IndicatorFBMask)

unsigned short	XkbDfltAccessXTimeout= 	120;
unsigned int	XkbDfltAccessXTimeoutMask= DFLT_TIMEOUT_CTRLS;
unsigned int	XkbDfltAccessXTimeoutValues= 0;
unsigned int	XkbDfltAccessXTimeoutOptionsMask= DFLT_TIMEOUT_OPTS;
unsigned int	XkbDfltAccessXTimeoutOptionsValues= 0;
unsigned int	XkbDfltAccessXFeedback= XkbAccessXFeedbackMask;
unsigned short	XkbDfltAccessXOptions=  XkbAX_AllOptionsMask & ~(XkbAX_IndicatorFBMask|XkbAX_SKReleaseFBMask|XkbAX_SKRejectFBMask);

void
AccessXComputeCurveFactor(XkbSrvInfoPtr xkbi,XkbControlsPtr ctrls)
{
    xkbi->mouseKeysCurve= 1.0+(((double)ctrls->mk_curve)*0.001);
    xkbi->mouseKeysCurveFactor= ( ((double)ctrls->mk_max_speed)/
	pow((double)ctrls->mk_time_to_max,xkbi->mouseKeysCurve));
    return;
}

void
AccessXInit(DeviceIntPtr keybd)
{
XkbSrvInfoPtr	xkbi = keybd->key->xkbInfo;
XkbControlsPtr	ctrls = xkbi->desc->ctrls;

    xkbi->shiftKeyCount= 0;
    xkbi->mouseKeysCounter= 0;
    xkbi->inactiveKey= 0;
    xkbi->slowKey= 0;
    xkbi->repeatKey= 0;
    xkbi->krgTimerActive= _OFF_TIMER;
    xkbi->beepType= _BEEP_NONE;
    xkbi->beepCount= 0;
    xkbi->mouseKeyTimer= NULL;
    xkbi->slowKeysTimer= NULL;
    xkbi->bounceKeysTimer= NULL;
    xkbi->repeatKeyTimer= NULL;
    xkbi->krgTimer= NULL;
    xkbi->beepTimer= NULL;
    ctrls->repeat_delay = XkbDfltRepeatDelay;
    ctrls->repeat_interval = XkbDfltRepeatInterval;
    ctrls->debounce_delay = 300;
    ctrls->slow_keys_delay = 300;
    ctrls->mk_delay = 160;
    ctrls->mk_interval = 40;
    ctrls->mk_time_to_max = 30;
    ctrls->mk_max_speed = 30;
    ctrls->mk_curve = 500;
    ctrls->mk_dflt_btn = 1;
    ctrls->ax_timeout = XkbDfltAccessXTimeout;
    ctrls->axt_ctrls_mask = XkbDfltAccessXTimeoutMask;
    ctrls->axt_ctrls_values = XkbDfltAccessXTimeoutValues;
    ctrls->axt_opts_mask = XkbDfltAccessXTimeoutOptionsMask;
    ctrls->axt_opts_values = XkbDfltAccessXTimeoutOptionsValues;
    if (XkbDfltAccessXTimeout)
	ctrls->enabled_ctrls |= XkbAccessXTimeoutMask;
    else
	ctrls->enabled_ctrls &= ~XkbAccessXTimeoutMask;
    ctrls->enabled_ctrls |= XkbDfltAccessXFeedback;
    ctrls->ax_options = XkbDfltAccessXOptions; 
    AccessXComputeCurveFactor(xkbi,ctrls);
    return;
}

/************************************************************************/
/*									*/
/* AccessXKeyboardEvent							*/
/*									*/
/*	Generate a synthetic keyboard event.				*/
/*									*/
/************************************************************************/
static void 
AccessXKeyboardEvent(DeviceIntPtr	keybd,
				 BYTE		type,
				 BYTE		keyCode,
				 Bool		isRepeat)
{
xEvent		xE;
    
    xE.u.u.type = type;
    xE.u.u.detail = keyCode;
    xE.u.keyButtonPointer.time = GetTimeInMillis();	    
#ifdef DEBUG
    if (xkbDebugFlags&0x8) {
	ErrorF("AXKE: Key %d %s\n",keyCode,(xE.u.u.type==KeyPress?"down":"up"));
    }
#endif

    if (_XkbIsPressEvent(type))
	XkbDDXKeyClick(keybd,keyCode,TRUE);
    else if (isRepeat)
	XkbLastRepeatEvent=	(pointer)&xE;
    XkbProcessKeyboardEvent(&xE,keybd,1L);
    XkbLastRepeatEvent= NULL;
    return;
    
} /* AccessXKeyboardEvent */

/************************************************************************/
/*									*/
/* AccessXKRGTurnOn							*/
/*									*/
/*	Turn the keyboard response group on.				*/
/*									*/
/************************************************************************/
static void
AccessXKRGTurnOn(DeviceIntPtr dev,CARD16 KRGControl,xkbControlsNotify	*pCN)
{
XkbSrvInfoPtr		xkbi = dev->key->xkbInfo;
XkbControlsPtr		ctrls = xkbi->desc->ctrls;
XkbControlsRec		old;
XkbEventCauseRec	cause;
XkbSrvLedInfoPtr	sli;

    old= *ctrls;
    ctrls->enabled_ctrls |= (KRGControl&XkbAX_KRGMask);
    if (XkbComputeControlsNotify(dev,&old,ctrls,pCN,False))
	XkbSendControlsNotify(dev,pCN);
    cause.kc=		pCN->keycode;
    cause.event=	pCN->eventType;
    cause.mjr=		pCN->requestMajor;
    cause.mnr=		pCN->requestMinor;
    sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
    XkbUpdateIndicators(dev,sli->usesControls,True,NULL,&cause);
    if (XkbAX_NeedFeedback(ctrls,XkbAX_FeatureFBMask))
	XkbDDXAccessXBeep(dev,_BEEP_FEATURE_ON,KRGControl);
    return;
    
} /* AccessXKRGTurnOn */

/************************************************************************/
/*									*/
/* AccessXKRGTurnOff							*/
/*									*/
/*	Turn the keyboard response group off.				*/
/*									*/
/************************************************************************/
static void 
AccessXKRGTurnOff(DeviceIntPtr dev,xkbControlsNotify *pCN)
{
XkbSrvInfoPtr		xkbi = dev->key->xkbInfo;
XkbControlsPtr		ctrls = xkbi->desc->ctrls;
XkbControlsRec		old;
XkbEventCauseRec	cause;
XkbSrvLedInfoPtr	sli;

    old = *ctrls;
    ctrls->enabled_ctrls &= ~XkbAX_KRGMask;
    if (XkbComputeControlsNotify(dev,&old,ctrls,pCN,False))
	XkbSendControlsNotify(dev,pCN);
    cause.kc=		pCN->keycode;
    cause.event=	pCN->eventType;
    cause.mjr=		pCN->requestMajor;
    cause.mnr=		pCN->requestMinor;
    sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
    XkbUpdateIndicators(dev,sli->usesControls,True,NULL,&cause);
    if (XkbAX_NeedFeedback(ctrls,XkbAX_FeatureFBMask)) {
	unsigned changes= old.enabled_ctrls^ctrls->enabled_ctrls;
	XkbDDXAccessXBeep(dev,_BEEP_FEATURE_OFF,changes);
    }
    return;
    
} /* AccessXKRGTurnOff */

/************************************************************************/
/*									*/
/* AccessXStickyKeysTurnOn						*/
/*									*/
/*	Turn StickyKeys on.						*/
/*									*/
/************************************************************************/
static void
AccessXStickyKeysTurnOn(DeviceIntPtr dev,xkbControlsNotify *pCN)
{
XkbSrvInfoPtr		xkbi = dev->key->xkbInfo;
XkbControlsPtr		ctrls = xkbi->desc->ctrls;
XkbControlsRec		old;
XkbEventCauseRec	cause;
XkbSrvLedInfoPtr	sli;

    old = *ctrls;
    ctrls->enabled_ctrls |= XkbStickyKeysMask;
    xkbi->shiftKeyCount = 0;
    if (XkbComputeControlsNotify(dev,&old,ctrls,pCN,False)) 
	XkbSendControlsNotify(dev,pCN);
    cause.kc=		pCN->keycode;
    cause.event=	pCN->eventType;
    cause.mjr=		pCN->requestMajor;
    cause.mnr=		pCN->requestMinor;
    sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
    XkbUpdateIndicators(dev,sli->usesControls,True,NULL,&cause);
    if (XkbAX_NeedFeedback(ctrls,XkbAX_FeatureFBMask)) {
	XkbDDXAccessXBeep(dev,_BEEP_FEATURE_ON,XkbStickyKeysMask);
    }
    return;
    
} /* AccessXStickyKeysTurnOn */

/************************************************************************/
/*									*/
/* AccessXStickyKeysTurnOff						*/
/*									*/
/*	Turn StickyKeys off.						*/
/*									*/
/************************************************************************/
static void
AccessXStickyKeysTurnOff(DeviceIntPtr dev,xkbControlsNotify *pCN)
{
XkbSrvInfoPtr		xkbi = dev->key->xkbInfo;
XkbControlsPtr		ctrls = xkbi->desc->ctrls;
XkbControlsRec		old;
XkbEventCauseRec	cause;
XkbSrvLedInfoPtr	sli;

    old = *ctrls;
    ctrls->enabled_ctrls &= ~XkbStickyKeysMask;
    xkbi->shiftKeyCount = 0;
    if (XkbComputeControlsNotify(dev,&old,ctrls,pCN,False))
	XkbSendControlsNotify(dev,pCN);

    cause.kc=		pCN->keycode;
    cause.event=	pCN->eventType;
    cause.mjr=		pCN->requestMajor;
    cause.mnr=		pCN->requestMinor;
    sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
    XkbUpdateIndicators(dev,sli->usesControls,True,NULL,&cause);
    if (XkbAX_NeedFeedback(ctrls,XkbAX_FeatureFBMask)) {
	XkbDDXAccessXBeep(dev,_BEEP_FEATURE_OFF,XkbStickyKeysMask);
    }
#ifndef NO_CLEAR_LATCHES_FOR_STICKY_KEYS_OFF
    XkbClearAllLatchesAndLocks(dev,xkbi,False,&cause);
#endif
    return;
} /* AccessXStickyKeysTurnOff */

static CARD32
AccessXKRGExpire(OsTimerPtr timer,CARD32 now,pointer arg)
{
XkbSrvInfoPtr		xkbi= ((DeviceIntPtr)arg)->key->xkbInfo;
xkbControlsNotify	cn;

    if (xkbi->krgTimerActive==_KRG_WARN_TIMER) {
	XkbDDXAccessXBeep((DeviceIntPtr)arg,_BEEP_SLOW_WARN,XkbStickyKeysMask);
	xkbi->krgTimerActive= _KRG_TIMER;
	return 4000;
    }
    xkbi->krgTimerActive= _OFF_TIMER;
    cn.keycode = 0;
    cn.eventType = 0;
    cn.requestMajor = 0;
    cn.requestMinor = 0;
    if (xkbi->desc->ctrls->enabled_ctrls&XkbSlowKeysMask)
	 AccessXKRGTurnOff((DeviceIntPtr)arg,&cn);
    else AccessXKRGTurnOn((DeviceIntPtr)arg,XkbSlowKeysMask,&cn);
    return 0;
}

static CARD32
AccessXRepeatKeyExpire(OsTimerPtr timer,CARD32 now,pointer arg)
{
XkbSrvInfoPtr	xkbi= ((DeviceIntPtr)arg)->key->xkbInfo;
KeyCode		key;

    if (xkbi->repeatKey==0)
	return 0;
    key= xkbi->repeatKey;
    AccessXKeyboardEvent((DeviceIntPtr)arg,KeyRelease,key,True);
    AccessXKeyboardEvent((DeviceIntPtr)arg,KeyPress,key,True);
    return xkbi->desc->ctrls->repeat_interval;
}

void
AccessXCancelRepeatKey(XkbSrvInfoPtr xkbi,KeyCode key)
{
    if (xkbi->repeatKey==key)
	xkbi->repeatKey= 0;
    return;
}

static CARD32
AccessXSlowKeyExpire(OsTimerPtr timer,CARD32 now,pointer arg)
{
DeviceIntPtr	keybd;
XkbSrvInfoPtr	xkbi;
XkbDescPtr	xkb;
XkbControlsPtr	ctrls;

    keybd= 	(DeviceIntPtr)arg;
    xkbi= 	keybd->key->xkbInfo;
    xkb= 	xkbi->desc;
    ctrls= 	xkb->ctrls;
    if (xkbi->slowKey!=0) {
	xkbAccessXNotify ev;
	KeySym *sym= XkbKeySymsPtr(xkb,xkbi->slowKey);
	ev.detail= XkbAXN_SKAccept;
	ev.keycode= xkbi->slowKey;
	ev.slowKeysDelay= ctrls->slow_keys_delay;
	ev.debounceDelay= ctrls->debounce_delay;
	XkbSendAccessXNotify(keybd,&ev);
	if (XkbAX_NeedFeedback(ctrls,XkbAX_SKAcceptFBMask))
	    XkbDDXAccessXBeep(keybd,_BEEP_SLOW_ACCEPT,XkbSlowKeysMask);
	AccessXKeyboardEvent(keybd,KeyPress,xkbi->slowKey,False);
	/* check for magic sequences */
	if ((ctrls->enabled_ctrls&XkbAccessXKeysMask) &&
	    ((sym[0]==XK_Shift_R)||(sym[0]==XK_Shift_L)))
	    xkbi->shiftKeyCount++;

	/* Start repeating if necessary.  Stop autorepeating if the user
	 * presses a non-modifier key that doesn't autorepeat.
	 */
	if (keybd->kbdfeed->ctrl.autoRepeat && 
	    ((xkbi->slowKey != xkbi->mouseKey) || (!xkbi->mouseKeysAccel)) &&
	     (ctrls->enabled_ctrls&XkbRepeatKeysMask)) {
#ifndef AIXV3
	    if (BitIsOn(keybd->kbdfeed->ctrl.autoRepeats,xkbi->slowKey))
#endif
	    {
		xkbi->repeatKey = xkbi->slowKey;
		xkbi->repeatKeyTimer= TimerSet(xkbi->repeatKeyTimer,
					0, ctrls->repeat_delay,
					AccessXRepeatKeyExpire, (pointer)keybd);
	    }
	}
    }
    return 0;
}

static CARD32
AccessXBounceKeyExpire(OsTimerPtr timer,CARD32 now,pointer arg)
{
XkbSrvInfoPtr	xkbi= ((DeviceIntPtr)arg)->key->xkbInfo;

    xkbi->inactiveKey= 0;
    return 0;
}

static CARD32
AccessXTimeoutExpire(OsTimerPtr timer,CARD32 now,pointer arg)
{
DeviceIntPtr		dev = (DeviceIntPtr)arg;
XkbSrvInfoPtr		xkbi= dev->key->xkbInfo;
XkbControlsPtr		ctrls= xkbi->desc->ctrls;
XkbControlsRec		old;
xkbControlsNotify	cn;
XkbEventCauseRec	cause;
XkbSrvLedInfoPtr	sli;

    if (xkbi->lastPtrEventTime) {
	unsigned timeToWait = (ctrls->ax_timeout*1000);
	unsigned timeElapsed = (now-xkbi->lastPtrEventTime);

	if (timeToWait > timeElapsed)
	    return (timeToWait - timeElapsed);
    }
    old= *ctrls;
    xkbi->shiftKeyCount= 0;
    ctrls->enabled_ctrls&= ~ctrls->axt_ctrls_mask;
    ctrls->enabled_ctrls|= 
	(ctrls->axt_ctrls_values&ctrls->axt_ctrls_mask);
    if (ctrls->axt_opts_mask) {
	ctrls->ax_options&= ~ctrls->axt_opts_mask;
	ctrls->ax_options|= (ctrls->axt_opts_values&ctrls->axt_opts_mask);
    }
    if (XkbComputeControlsNotify(dev,&old,ctrls,&cn,False)) {
	cn.keycode = 0;
	cn.eventType = 0;
	cn.requestMajor = 0;
	cn.requestMinor = 0;
	XkbSendControlsNotify(dev,&cn);
    }
    XkbSetCauseUnknown(&cause);
    sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
    XkbUpdateIndicators(dev,sli->usesControls,True,NULL,&cause);
    if (ctrls->ax_options!=old.ax_options) {
	unsigned set,cleared,bell;
	set= ctrls->ax_options&(~old.ax_options);
	cleared= (~ctrls->ax_options)&old.ax_options;
	if (set && cleared)	bell= _BEEP_FEATURE_CHANGE;
	else if (set)		bell= _BEEP_FEATURE_ON;
	else 			bell= _BEEP_FEATURE_OFF;
	XkbDDXAccessXBeep(dev,bell,XkbAccessXTimeoutMask);
    }
    xkbi->krgTimerActive= _OFF_TIMER;
    return 0;
}


/************************************************************************/
/*									*/
/* AccessXFilterPressEvent						*/
/*									*/
/* Filter events before they get any further if SlowKeys is turned on.	*/
/* In addition, this routine handles the ever so popular magic key	*/
/* acts for turning various accessibility features on/off.		*/
/*									*/
/* Returns TRUE if this routine has discarded the event.		*/
/* Returns FALSE if the event needs further processing.			*/
/*									*/
/************************************************************************/
Bool
AccessXFilterPressEvent(	register xEvent *	xE, 
				register DeviceIntPtr	keybd, 
				int			count)
{
XkbSrvInfoPtr	xkbi = keybd->key->xkbInfo;
XkbControlsPtr	ctrls = xkbi->desc->ctrls;
Bool		ignoreKeyEvent = FALSE;
KeyCode		key = xE->u.u.detail;
KeySym *	sym = XkbKeySymsPtr(xkbi->desc,key);

    if (ctrls->enabled_ctrls&XkbAccessXKeysMask) {
	/* check for magic sequences */
	if ((sym[0]==XK_Shift_R)||(sym[0]==XK_Shift_L)) {
	    if (XkbAX_NeedFeedback(ctrls,XkbAX_SlowWarnFBMask)) {
		xkbi->krgTimerActive = _KRG_WARN_TIMER;
		xkbi->krgTimer= TimerSet(xkbi->krgTimer, 0, 4000,
					AccessXKRGExpire, (pointer)keybd);
	    }
	    else {
		xkbi->krgTimerActive = _KRG_TIMER;
		xkbi->krgTimer= TimerSet(xkbi->krgTimer, 0, 8000,
					AccessXKRGExpire, (pointer)keybd);
	    }
	    if (!(ctrls->enabled_ctrls & XkbSlowKeysMask)) {
		CARD32 now= GetTimeInMillis();
		if ((now-xkbi->lastShiftEventTime)>15000)
		     xkbi->shiftKeyCount= 1;
		else xkbi->shiftKeyCount++;
		xkbi->lastShiftEventTime= now;
	    }
	}
	else {
	    if (xkbi->krgTimerActive) {
		xkbi->krgTimer= TimerSet(xkbi->krgTimer,0, 0, NULL, NULL);
		xkbi->krgTimerActive= _OFF_TIMER;
	    }
	}
    }
	
    /* Don't transmit the KeyPress if SlowKeys is turned on;
     * The wakeup handler will synthesize one for us if the user
     * has held the key long enough.
     */
    if (ctrls->enabled_ctrls & XkbSlowKeysMask) {
	xkbAccessXNotify	ev;
	/* If key was already pressed, ignore subsequent press events
	 * from the server's autorepeat
	 */
	if(xkbi->slowKey == key)
	    return TRUE;
	ev.detail= XkbAXN_SKPress;
	ev.keycode= key;
	ev.slowKeysDelay= ctrls->slow_keys_delay;
	ev.debounceDelay= ctrls->debounce_delay;
	XkbSendAccessXNotify(keybd,&ev);
	if (XkbAX_NeedFeedback(ctrls,XkbAX_SKPressFBMask))
	    XkbDDXAccessXBeep(keybd,_BEEP_SLOW_PRESS,XkbSlowKeysMask);
	xkbi->slowKey= key;
	xkbi->slowKeysTimer = TimerSet(xkbi->slowKeysTimer,
				 0, ctrls->slow_keys_delay,
				 AccessXSlowKeyExpire, (pointer)keybd);
	ignoreKeyEvent = TRUE;
    }

    /* Don't transmit the KeyPress if BounceKeys is turned on
     * and the user pressed the same key within a given time period
     * from the last release.
     */
    else if ((ctrls->enabled_ctrls & XkbBounceKeysMask) && 
					(key == xkbi->inactiveKey)) {
	if (XkbAX_NeedFeedback(ctrls,XkbAX_BKRejectFBMask))
	    XkbDDXAccessXBeep(keybd,_BEEP_BOUNCE_REJECT,XkbBounceKeysMask);
	ignoreKeyEvent = TRUE;
    }

    /* Start repeating if necessary.  Stop autorepeating if the user
     * presses a non-modifier key that doesn't autorepeat.
     */
    if (XkbDDXUsesSoftRepeat(keybd)) {
	if ((keybd->kbdfeed->ctrl.autoRepeat) &&
		((ctrls->enabled_ctrls&(XkbSlowKeysMask|XkbRepeatKeysMask))==
							XkbRepeatKeysMask)) {
#ifndef AIXV3
	    if (BitIsOn(keybd->kbdfeed->ctrl.autoRepeats,key))
#endif
	    {
#ifdef DEBUG
		if (xkbDebugFlags&0x10)
		    ErrorF("Starting software autorepeat...\n");
#endif	    
		xkbi->repeatKey = key;
		xkbi->repeatKeyTimer= TimerSet(xkbi->repeatKeyTimer,
					0, ctrls->repeat_delay,
					AccessXRepeatKeyExpire, (pointer)keybd);
	    }
	}
    }
    
    /* Check for two keys being pressed at the same time.  This section
     * essentially says the following:
     *
     *	If StickyKeys is on, and a modifier is currently being held down,
     *  and one of the following is true:  the current key is not a modifier
     *  or the currentKey is a modifier, but not the only modifier being
     *  held down, turn StickyKeys off if the TwoKeys off ctrl is set.
     */
    if ((ctrls->enabled_ctrls & XkbStickyKeysMask) && 
				(xkbi->state.base_mods!=0) &&
				(XkbAX_NeedOption(ctrls,XkbAX_TwoKeysMask))) {
	xkbControlsNotify cn;
	cn.keycode = key;
	cn.eventType = KeyPress;
	cn.requestMajor = 0;
	cn.requestMinor = 0;
	AccessXStickyKeysTurnOff(keybd,&cn);
    }
    
    if (!ignoreKeyEvent)
	XkbProcessKeyboardEvent(xE,keybd,count);
    return ignoreKeyEvent;
} /* AccessXFilterPressEvent */

/************************************************************************/
/*									*/
/* AccessXFilterReleaseEvent						*/
/*									*/
/* Filter events before they get any further if SlowKeys is turned on.	*/
/* In addition, this routine handles the ever so popular magic key	*/
/* acts for turning various accessibility features on/off.		*/
/*									*/
/* Returns TRUE if this routine has discarded the event.		*/
/* Returns FALSE if the event needs further processing.			*/
/*									*/
/************************************************************************/
Bool
AccessXFilterReleaseEvent(	register xEvent *	xE, 
				register DeviceIntPtr	keybd, 
				int			count)
{
XkbSrvInfoPtr	xkbi = keybd->key->xkbInfo;
XkbControlsPtr	ctrls = xkbi->desc->ctrls;
KeyCode		key = xE->u.u.detail;
Bool		ignoreKeyEvent = FALSE;
    
    /* Don't transmit the KeyRelease if BounceKeys is on and
     * this is the release of a key that was ignored due to 
     * BounceKeys.
     */
    if (ctrls->enabled_ctrls & XkbBounceKeysMask) {
	if ((key!=xkbi->mouseKey)&&(!BitIsOn(keybd->key->down,key)))
	    ignoreKeyEvent = TRUE;
	xkbi->inactiveKey= key;
	xkbi->bounceKeysTimer= TimerSet(xkbi->bounceKeysTimer, 0,
					ctrls->debounce_delay,
					AccessXBounceKeyExpire, (pointer)keybd);
    }

    /* Don't transmit the KeyRelease if SlowKeys is turned on and
     * the user didn't hold the key long enough.  We know we passed
     * the key if the down bit was set by CoreProcessKeyboadEvent.
     */
    if (ctrls->enabled_ctrls & XkbSlowKeysMask) {
	xkbAccessXNotify	ev;
	unsigned		beep_type;
	ev.keycode= key;
	ev.slowKeysDelay= ctrls->slow_keys_delay;
	ev.debounceDelay= ctrls->debounce_delay;
	if (BitIsOn(keybd->key->down,key) | (xkbi->mouseKey == key)) {
	    ev.detail= XkbAXN_SKRelease;
	    beep_type= _BEEP_SLOW_RELEASE;
	}
	else {
	    ev.detail= XkbAXN_SKReject;
	    beep_type= _BEEP_SLOW_REJECT;
	    ignoreKeyEvent = TRUE;
	}
	XkbSendAccessXNotify(keybd,&ev);
	if (XkbAX_NeedFeedback(ctrls,XkbAX_SKRejectFBMask)) {
	    XkbDDXAccessXBeep(keybd,beep_type,XkbSlowKeysMask);
	}
	if (xkbi->slowKey==key)
	    xkbi->slowKey= 0;
    }

    /* Stop Repeating if the user releases the key that is currently
     * repeating.
     */
    if (xkbi->repeatKey==key) {
	xkbi->repeatKey= 0;
    }

    if ((ctrls->enabled_ctrls&XkbAccessXTimeoutMask)&&(ctrls->ax_timeout>0)) {
	xkbi->lastPtrEventTime= 0;
	xkbi->krgTimer= TimerSet(xkbi->krgTimer, 0, 
					ctrls->ax_timeout*1000,
					AccessXTimeoutExpire, (pointer)keybd);
	xkbi->krgTimerActive= _ALL_TIMEOUT_TIMER;
    }
    else if (xkbi->krgTimerActive!=_OFF_TIMER) {
	xkbi->krgTimer= TimerSet(xkbi->krgTimer, 0, 0, NULL, NULL);
	xkbi->krgTimerActive= _OFF_TIMER;
    }
	
    /* Keep track of how many times the Shift key has been pressed.
     * If it has been pressed and released 5 times in a row, toggle
     * the state of StickyKeys.
     */
    if ((!ignoreKeyEvent)&&(xkbi->shiftKeyCount)) {
	KeySym *pSym= XkbKeySymsPtr(xkbi->desc,key);
	if ((pSym[0]!=XK_Shift_L)&&(pSym[0]!=XK_Shift_R)) {
	    xkbi->shiftKeyCount= 0;
	}
	else if (xkbi->shiftKeyCount>=5) {
	     xkbControlsNotify cn;
	     cn.keycode = key;
	     cn.eventType = KeyPress;
	     cn.requestMajor = 0;
	     cn.requestMinor = 0;
	     if (ctrls->enabled_ctrls & XkbStickyKeysMask)
		AccessXStickyKeysTurnOff(keybd,&cn);
	     else
		AccessXStickyKeysTurnOn(keybd,&cn);
	     xkbi->shiftKeyCount= 0;
	}
    }
    
    if (!ignoreKeyEvent)
	XkbProcessKeyboardEvent(xE,keybd,count);
    return ignoreKeyEvent;
    
} /* AccessXFilterReleaseEvent */

/************************************************************************/
/*									*/
/* ProcessPointerEvent							*/
/*									*/
/* This routine merely sets the shiftKeyCount and clears the keyboard   */
/* response group timer (if necessary) on a mouse event.  This is so	*/
/* multiple shifts with just the mouse and shift-drags with the mouse	*/
/* don't accidentally turn on StickyKeys or the Keyboard Response Group.*/
/*									*/
/************************************************************************/
void
ProcessPointerEvent(	register xEvent  *	xE, 
			register DeviceIntPtr	mouse, 
			int		        count)
{
DeviceIntPtr	dev = (DeviceIntPtr)LookupKeyboardDevice();
XkbSrvInfoPtr	xkbi = dev->key->xkbInfo;
unsigned 	changed = 0;

    xkbi->shiftKeyCount = 0;
    xkbi->lastPtrEventTime= xE->u.keyButtonPointer.time;

    if (xE->u.u.type==ButtonPress) {
	    changed |= XkbPointerButtonMask;
    }
    else if (xE->u.u.type==ButtonRelease) {
	xkbi->lockedPtrButtons&= ~(1<<(xE->u.u.detail&0x7));
	changed |= XkbPointerButtonMask;
    }
    CoreProcessPointerEvent(xE,mouse,count);

    xkbi->state.ptr_buttons = mouse->button->state;
    
    /* clear any latched modifiers */
    if ( xkbi->state.latched_mods && (xE->u.u.type==ButtonRelease) ) {
	unsigned 		changed_leds;
	XkbStateRec		oldState;
	XkbSrvLedInfoPtr	sli;

	sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
	oldState= xkbi->state;
	XkbLatchModifiers(dev,0xFF,0x00);

	XkbComputeDerivedState(xkbi);
	changed |= XkbStateChangedFlags(&oldState,&xkbi->state);
	if (changed&sli->usedComponents) {
	    changed_leds= XkbIndicatorsToUpdate(dev,changed,False);
	    if (changed_leds) {
		XkbEventCauseRec	cause;
		XkbSetCauseKey(&cause,(xE->u.u.detail&0x7),xE->u.u.type);
		XkbUpdateIndicators(dev,changed_leds,True,NULL,&cause);
	    }
	}
	dev->key->state= XkbStateFieldFromRec(&xkbi->state);
    }

    if (((xkbi->flags&_XkbStateNotifyInProgress)==0)&&(changed!=0)) {
	xkbStateNotify	sn;
	sn.keycode= xE->u.u.detail;
	sn.eventType= xE->u.u.type;
	sn.requestMajor = sn.requestMinor = 0;
	sn.changed= changed;
	XkbSendStateNotify(dev,&sn);
    }

} /* ProcessPointerEvent */





--- NEW FILE: xkbActions.c ---
/* $Xorg: xkbActions.c,v 1.3 2000/08/17 19:53:47 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...1334 lines suppressed...]
	sn.changed|= XkbGroupLockMask;
    }
    if ( genEv && sn.changed) {
	CARD32 	changed;

	XkbComputeDerivedState(xkbi);
	sn.keycode= 		cause->kc;
	sn.eventType=		cause->event;
	sn.requestMajor= 	cause->mjr;
	sn.requestMinor= 	cause->mnr;
	sn.changed= XkbStateChangedFlags(&os,&xkbi->state);
	XkbSendStateNotify(dev,&sn);
	changed= XkbIndicatorsToUpdate(dev,sn.changed,False);
	if (changed) {
	    XkbUpdateIndicators(dev,changed,True,NULL,cause);
	}
    }
    return;
}


--- NEW FILE: xkbDflts.h ---
/* $Xorg: xkbDflts.h,v 1.3 2000/08/17 19:53:47 cpqbld Exp $ */
/* $XFree86: xc/programs/Xserver/xkb/xkbDflts.h,v 1.2 2001/10/28 03:34:20 tsi Exp $ */
/* This file generated automatically by xkbcomp */
/* DO  NOT EDIT */
#ifndef DEFAULT_H
#define DEFAULT_H 1

#ifndef XKB_IN_SERVER
#define GET_ATOM(d,s)	XInternAtom(d,s,0)
#define DPYTYPE	Display *
#else
#define GET_ATOM(d,s)	MakeAtom(s,strlen(s),1)
#define DPYTYPE	char *
#endif
#define NUM_KEYS	1

#define	vmod_NumLock	0
#define	vmod_Alt	1
#define	vmod_LevelThree	2
#define	vmod_AltGr	3
#define	vmod_ScrollLock	4

#define	vmod_NumLockMask	(1<<0)
#define	vmod_AltMask	(1<<1)
#define	vmod_LevelThreeMask	(1<<2)
#define	vmod_AltGrMask	(1<<3)
#define	vmod_ScrollLockMask	(1<<4)

/* types name is "default" */
static Atom lnames_ONE_LEVEL[1];

static XkbKTMapEntryRec map_TWO_LEVEL[1]= {
    { 1,      1, {       ShiftMask,       ShiftMask,               0 } }
};
static Atom lnames_TWO_LEVEL[2];

static XkbKTMapEntryRec map_ALPHABETIC[2]= {
    { 1,      1, {       ShiftMask,       ShiftMask,               0 } },
    { 1,      0, {        LockMask,        LockMask,               0 } }
};
static XkbModsRec preserve_ALPHABETIC[2]= {
    {                 0,               0,               0 },
    {          LockMask,        LockMask,               0 }
};
static Atom lnames_ALPHABETIC[2];

static XkbKTMapEntryRec map_KEYPAD[2]= {
    { 1,      1, {       ShiftMask,       ShiftMask,               0 } },
    { 0,      1, {               0,               0, vmod_NumLockMask } }
};
static Atom lnames_KEYPAD[2];

static XkbKTMapEntryRec map_PC_BREAK[1]= {
    { 1,      1, {     ControlMask,     ControlMask,               0 } }
};
static Atom lnames_PC_BREAK[2];

static XkbKTMapEntryRec map_PC_SYSRQ[1]= {
    { 0,      1, {               0,               0,    vmod_AltMask } }
};
static Atom lnames_PC_SYSRQ[2];

static XkbKTMapEntryRec map_CTRL_ALT[1]= {
    { 0,      1, {     ControlMask,     ControlMask,    vmod_AltMask } }
};
static Atom lnames_CTRL_ALT[2];

static XkbKTMapEntryRec map_THREE_LEVEL[3]= {
    { 1,      1, {       ShiftMask,       ShiftMask,               0 } },
    { 0,      2, {               0,               0, vmod_LevelThreeMask } },
    { 0,      2, {       ShiftMask,       ShiftMask, vmod_LevelThreeMask } }
};
static Atom lnames_THREE_LEVEL[3];

static XkbKTMapEntryRec map_SHIFT_ALT[1]= {
    { 0,      1, {       ShiftMask,       ShiftMask,    vmod_AltMask } }
};
static Atom lnames_SHIFT_ALT[2];

static XkbKeyTypeRec dflt_types[]= {
    {
	{               0,               0,               0 },
	1,
	0,	NULL,	NULL,
	None,	lnames_ONE_LEVEL
    },
    {
	{       ShiftMask,       ShiftMask,               0 },
	2,
	1,	map_TWO_LEVEL,	NULL,
	None,	lnames_TWO_LEVEL
    },
    {
	{ ShiftMask|LockMask, ShiftMask|LockMask,               0 },
	2,
	2,	map_ALPHABETIC,	preserve_ALPHABETIC,
	None,	lnames_ALPHABETIC
    },
    {
	{       ShiftMask,       ShiftMask, vmod_NumLockMask },
	2,
	2,	map_KEYPAD,	NULL,
	None,	lnames_KEYPAD
    },
    {
	{     ControlMask,     ControlMask,               0 },
	2,
	1,	map_PC_BREAK,	NULL,
	None,	lnames_PC_BREAK
    },
    {
	{               0,               0,    vmod_AltMask },
	2,
	1,	map_PC_SYSRQ,	NULL,
	None,	lnames_PC_SYSRQ
    },
    {
	{     ControlMask,     ControlMask,    vmod_AltMask },
	2,
	1,	map_CTRL_ALT,	NULL,
	None,	lnames_CTRL_ALT
    },
    {
	{       ShiftMask,       ShiftMask, vmod_LevelThreeMask },
	3,
	3,	map_THREE_LEVEL,	NULL,
	None,	lnames_THREE_LEVEL
    },
    {
	{       ShiftMask,       ShiftMask,    vmod_AltMask },
	2,
	1,	map_SHIFT_ALT,	NULL,
	None,	lnames_SHIFT_ALT
    }
};
#define num_dflt_types (sizeof(dflt_types)/sizeof(XkbKeyTypeRec))


static void
initTypeNames(DPYTYPE dpy)
{
    dflt_types[0].name= GET_ATOM(dpy,"ONE_LEVEL");
    lnames_ONE_LEVEL[0]=	GET_ATOM(dpy,"Any");
    dflt_types[1].name= GET_ATOM(dpy,"TWO_LEVEL");
    lnames_TWO_LEVEL[0]=	GET_ATOM(dpy,"Base");
    lnames_TWO_LEVEL[1]=	GET_ATOM(dpy,"Shift");
    dflt_types[2].name= GET_ATOM(dpy,"ALPHABETIC");
    lnames_ALPHABETIC[0]=	GET_ATOM(dpy,"Base");
    lnames_ALPHABETIC[1]=	GET_ATOM(dpy,"Caps");
    dflt_types[3].name= GET_ATOM(dpy,"KEYPAD");
    lnames_KEYPAD[0]=	GET_ATOM(dpy,"Base");
    lnames_KEYPAD[1]=	GET_ATOM(dpy,"Number");
    dflt_types[4].name= GET_ATOM(dpy,"PC_BREAK");
    lnames_PC_BREAK[0]=	GET_ATOM(dpy,"Base");
    lnames_PC_BREAK[1]=	GET_ATOM(dpy,"Control");
    dflt_types[5].name= GET_ATOM(dpy,"PC_SYSRQ");
    lnames_PC_SYSRQ[0]=	GET_ATOM(dpy,"Base");
    lnames_PC_SYSRQ[1]=	GET_ATOM(dpy,"Alt");
    dflt_types[6].name= GET_ATOM(dpy,"CTRL+ALT");
    lnames_CTRL_ALT[0]=	GET_ATOM(dpy,"Base");
    lnames_CTRL_ALT[1]=	GET_ATOM(dpy,"Ctrl+Alt");
    dflt_types[7].name= GET_ATOM(dpy,"THREE_LEVEL");
    lnames_THREE_LEVEL[0]=	GET_ATOM(dpy,"Base");
    lnames_THREE_LEVEL[1]=	GET_ATOM(dpy,"Shift");
    lnames_THREE_LEVEL[2]=	GET_ATOM(dpy,"Level3");
    dflt_types[8].name= GET_ATOM(dpy,"SHIFT+ALT");
    lnames_SHIFT_ALT[0]=	GET_ATOM(dpy,"Base");
    lnames_SHIFT_ALT[1]=	GET_ATOM(dpy,"Shift+Alt");
}
/* compat name is "default" */
static XkbSymInterpretRec dfltSI[69]= {
    {    XK_ISO_Level2_Latch, 0x0000,
         XkbSI_LevelOneOnly|XkbSI_Exactly, ShiftMask,
         255,
       {      XkbSA_LatchMods, { 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Eisu_Shift, 0x0000,
         XkbSI_Exactly, LockMask,
         255,
       {       XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Eisu_toggle, 0x0000,
         XkbSI_Exactly, LockMask,
         255,
       {       XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Kana_Shift, 0x0000,
         XkbSI_Exactly, LockMask,
         255,
       {       XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Kana_Lock, 0x0000,
         XkbSI_Exactly, LockMask,
         255,
       {       XkbSA_NoAction, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Shift_Lock, 0x0000,
         XkbSI_AnyOf, ShiftMask|LockMask,
         255,
       {       XkbSA_LockMods, { 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Num_Lock, 0x0000,
         XkbSI_AnyOf, 0xff,
         0,
       {       XkbSA_LockMods, { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 } } },
    {    XK_Alt_L, 0x0000,
         XkbSI_AnyOf, 0xff,
         1,
       {        XkbSA_SetMods, { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Alt_R, 0x0000,
         XkbSI_AnyOf, 0xff,
         1,
       {        XkbSA_SetMods, { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Scroll_Lock, 0x0000,
         XkbSI_AnyOf, 0xff,
         4,
       {       XkbSA_LockMods, { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_ISO_Lock, 0x0000,
         XkbSI_AnyOf, 0xff,
         255,
       {        XkbSA_ISOLock, { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_ISO_Level3_Shift, 0x0000,
         XkbSI_LevelOneOnly|XkbSI_AnyOf, 0xff,
         2,
       {        XkbSA_SetMods, { 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00 } } },
    {    XK_ISO_Level3_Latch, 0x0000,
         XkbSI_LevelOneOnly|XkbSI_AnyOf, 0xff,
         2,
       {      XkbSA_LatchMods, { 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00 } } },
    {    XK_Mode_switch, 0x0000,
         XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff,
         3,
       {       XkbSA_SetGroup, { 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_1, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x01, 0x00, 0x00 } } },
    {    XK_KP_End, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x01, 0x00, 0x00 } } },
    {    XK_KP_2, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 } } },
    {    XK_KP_Down, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 } } },
    {    XK_KP_3, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00 } } },
    {    XK_KP_Next, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00 } } },
    {    XK_KP_4, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Left, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_6, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Right, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_7, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 } } },
    {    XK_KP_Home, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00 } } },
    {    XK_KP_8, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 } } },
    {    XK_KP_Up, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 } } },
    {    XK_KP_9, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 } } },
    {    XK_KP_Prior, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {        XkbSA_MovePtr, { 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00 } } },
    {    XK_KP_5, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Begin, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_F1, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_SetPtrDflt, { 0x04, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Divide, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_SetPtrDflt, { 0x04, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_F2, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_SetPtrDflt, { 0x04, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Multiply, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_SetPtrDflt, { 0x04, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_F3, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_SetPtrDflt, { 0x04, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Subtract, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_SetPtrDflt, { 0x04, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Separator, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Add, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_0, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_LockPtrBtn, { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Insert, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_LockPtrBtn, { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Decimal, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_LockPtrBtn, { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_KP_Delete, 0x0001,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_LockPtrBtn, { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_Button_Dflt, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_Button1, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_Button2, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_Button3, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_DblClick_Dflt, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_DblClick1, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_DblClick2, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_DblClick3, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {         XkbSA_PtrBtn, { 0x00, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_Drag_Dflt, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_LockPtrBtn, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_Drag1, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_LockPtrBtn, { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_Drag2, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_LockPtrBtn, { 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_Drag3, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_LockPtrBtn, { 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_EnableKeys, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {   XkbSA_LockControls, { 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00 } } },
    {    XK_Pointer_Accelerate, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {   XkbSA_LockControls, { 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00 } } },
    {    XK_Pointer_DfltBtnNext, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_SetPtrDflt, { 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_Pointer_DfltBtnPrev, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {     XkbSA_SetPtrDflt, { 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_AccessX_Enable, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {   XkbSA_LockControls, { 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00 } } },
    {    XK_Terminate_Server, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {      XkbSA_Terminate, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_ISO_Group_Latch, 0x0000,
         XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff,
         3,
       {     XkbSA_LatchGroup, { 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_ISO_Next_Group, 0x0000,
         XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff,
         3,
       {      XkbSA_LockGroup, { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_ISO_Prev_Group, 0x0000,
         XkbSI_LevelOneOnly|XkbSI_AnyOfOrNone, 0xff,
         3,
       {      XkbSA_LockGroup, { 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_ISO_First_Group, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {      XkbSA_LockGroup, { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    XK_ISO_Last_Group, 0x0000,
         XkbSI_AnyOfOrNone, 0xff,
         255,
       {      XkbSA_LockGroup, { 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } } },
    {    NoSymbol, 0x0000,
         XkbSI_Exactly, LockMask,
         255,
       {       XkbSA_LockMods, { 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00 } } },
    {    NoSymbol, 0x0000,
         XkbSI_AnyOf, 0xff,
         255,
       {        XkbSA_SetMods, { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } }
};
#define num_dfltSI (sizeof(dfltSI)/sizeof(XkbSymInterpretRec))

static XkbCompatMapRec compatMap= {
    dfltSI,
    {   /* group compatibility */
        {            0,            0,            0 },
        {            0,            0, vmod_AltGrMask },
        {            0,            0, vmod_AltGrMask },
        {            0,            0, vmod_AltGrMask }
    },
    num_dfltSI, num_dfltSI
};

static XkbIndicatorRec indicators= {
    0x0,
    {
        { 0x80, 0, 0x00, XkbIM_UseEffective, { LockMask,  LockMask, 0 }, 0 },
        { 0x80, 0, 0x00, XkbIM_UseEffective, { 0,  0, vmod_NumLockMask }, 0 },
        { 0x80, 0, 0x00, XkbIM_UseLocked, { ShiftMask,  ShiftMask, 0 }, 0 },
        { 0x80, 0, 0x00, 0, { 0,  0, 0 }, XkbMouseKeysMask },
        { 0x80, 0, 0x00, XkbIM_UseLocked, { 0,  0, vmod_ScrollLockMask }, 0 },
        { 0x80, XkbIM_UseEffective, 0xfe, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 },
        { 0x00, 0, 0x00, 0, { 0,  0, 0 }, 0 }
    }
};
static void
initIndicatorNames(DPYTYPE dpy,XkbDescPtr xkb)
{
    xkb->names->indicators[ 0]=	GET_ATOM(dpy,"Caps Lock");
    xkb->names->indicators[ 1]=	GET_ATOM(dpy,"Num Lock");
    xkb->names->indicators[ 2]=	GET_ATOM(dpy,"Shift Lock");
    xkb->names->indicators[ 3]=	GET_ATOM(dpy,"Mouse Keys");
    xkb->names->indicators[ 4]=	GET_ATOM(dpy,"Scroll Lock");
    xkb->names->indicators[ 5]=	GET_ATOM(dpy,"Group 2");
}
#endif /* DEFAULT_H */

--- NEW FILE: xkbEvents.c ---
/* $Xorg: xkbEvents.c,v 1.3 2000/08/17 19:53:47 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...1014 lines suppressed...]
		XkbInterestPtr	victim = interest->next;
		interest->next = victim->next;
		autoCtrls= victim->autoCtrls;
		autoValues= victim->autoCtrlValues;
		client= victim->client;
		_XkbFree(victim);
		found= True;
	    }
	    interest = interest->next;
	}
    }
    if (found && autoCtrls && dev->key && dev->key->xkbInfo ) {
	XkbEventCauseRec cause;

	xkbi= dev->key->xkbInfo;
	XkbSetCauseXkbReq(&cause,X_kbPerClientFlags,client);
	XkbEnableDisableControls(xkbi,autoCtrls,autoValues,NULL,&cause);
    }
    return found;
}

--- NEW FILE: xkbInit.c ---
/* $Xorg: xkbInit.c,v 1.3 2000/08/17 19:53:47 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...982 lines suppressed...]
	XkbDfltRepeatInterval = (long)atoi(argv[i]);
	return 2;
    }
    return 0;
}

void
XkbUseMsg(void)
{
    ErrorF("The X Keyboard Extension adds the following arguments:\n");
    ErrorF("-kb                    disable the X Keyboard Extension\n");
    ErrorF("+kb                    enable the X Keyboard Extension\n");
    ErrorF("[+-]accessx [ timeout [ timeout_mask [ feedback [ options_mask] ] ] ]\n");
    ErrorF("                       enable/disable accessx key sequences\n");
    ErrorF("-ar1                   set XKB autorepeat delay\n");
    ErrorF("-ar2                   set XKB autorepeat interval\n");
    ErrorF("-noloadxkb             don't load XKB keymap description\n");
    ErrorF("-xkbdb                 file that contains default XKB keymaps\n");
    ErrorF("-xkbmap                XKB keyboard description to load on startup\n");
}

--- NEW FILE: xkbLEDs.c ---
/* $Xorg: xkbLEDs.c,v 1.4 2001/05/10 19:54:01 steve Exp $ */
/************************************************************
Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...1024 lines suppressed...]
XkbApplyVModChangesToAllDevices(	DeviceIntPtr		dev,
					XkbDescPtr 		xkb,
					unsigned 		changed,
					XkbEventCausePtr	cause)
{
DeviceIntPtr			edev;
    if (dev!=(DeviceIntPtr)LookupKeyboardDevice())
	return;
    for (edev=inputInfo.devices;edev!=NULL;edev=edev->next) {
	if (edev->key)
	    continue;
	_UpdateDeviceVMods(edev,xkb,changed,cause);
    }
    for (edev=inputInfo.off_devices;edev!=NULL;edev=edev->next) {
	if (edev->key)
	    continue;
	_UpdateDeviceVMods(edev,xkb,changed,cause);
    }
    return;
}

--- NEW FILE: xkbPrKeyEv.c ---
/* $Xorg: xkbPrKeyEv.c,v 1.3 2000/08/17 19:53:48 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/xkbPrKeyEv.c,v 3.8 2001/01/17 22:37:15 dawes Exp $ */

#include <stdio.h>
#include <math.h>
#define NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "misc.h"
#include "inputstr.h"
#include <X11/extensions/XKBsrv.h>
#include <ctype.h>


/***====================================================================***/

void
XkbProcessKeyboardEvent(xEvent *xE,DeviceIntPtr keybd,int count)
{
KeyClassPtr	keyc = keybd->key;
XkbSrvInfoPtr	xkbi;
int		key;
XkbBehavior	behavior;
unsigned        ndx;

    xkbi= keyc->xkbInfo;
    key= xE->u.u.detail;
#ifdef DEBUG
    if (xkbDebugFlags&0x8) {
	ErrorF("XkbPKE: Key %d %s\n",key,(xE->u.u.type==KeyPress?"down":"up"));
    }
#endif

    if ( (xkbi->repeatKey==key) && (xE->u.u.type==KeyRelease) &&
	 ((xkbi->desc->ctrls->enabled_ctrls&XkbRepeatKeysMask)==0) ) {
	AccessXCancelRepeatKey(xkbi,key);
    }

    behavior= xkbi->desc->server->behaviors[key];
    /* The "permanent" flag indicates a hard-wired behavior that occurs */
    /* below XKB, such as a key that physically locks.   XKB does not   */
    /* do anything to implement the behavior, but it *does* report that */
    /* key is hardwired */
    if ((behavior.type&XkbKB_Permanent)==0) {
	switch (behavior.type) {
	    case XkbKB_Default:
		if (( xE->u.u.type == KeyPress ) && 
		    (keyc->down[key>>3] & (1<<(key&7)))) {
		    XkbLastRepeatEvent=	(pointer)xE;
		    xE->u.u.type = KeyRelease;
		    XkbHandleActions(keybd,keybd,xE,count);
		    xE->u.u.type = KeyPress;
		    XkbHandleActions(keybd,keybd,xE,count);
		    XkbLastRepeatEvent= NULL;
		    return;
		}
		else if ((xE->u.u.type==KeyRelease) &&
			(!(keyc->down[key>>3]&(1<<(key&7))))) {
		    XkbLastRepeatEvent=	(pointer)&xE;
		    xE->u.u.type = KeyPress;
		    XkbHandleActions(keybd,keybd,xE,count);
		    xE->u.u.type = KeyRelease;
		    XkbHandleActions(keybd,keybd,xE,count);
		    XkbLastRepeatEvent= NULL;
		    return;
		}
		break;
	    case XkbKB_Lock:
		if ( xE->u.u.type == KeyRelease )
		    return;
		else {
		    int	bit= 1<<(key&7);
		    if ( keyc->down[key>>3]&bit )
			xE->u.u.type= KeyRelease;
		}
		break;
	    case XkbKB_RadioGroup:
		ndx= (behavior.data&(~XkbKB_RGAllowNone));
		if ( ndx<xkbi->nRadioGroups ) {
		    XkbRadioGroupPtr	rg;

		    if ( xE->u.u.type == KeyRelease )
		        return;

		    rg = &xkbi->radioGroups[ndx];
		    if ( rg->currentDown == xE->u.u.detail ) {
		        if (behavior.data&XkbKB_RGAllowNone) {
		            xE->u.u.type = KeyRelease;
			    XkbHandleActions(keybd,keybd,xE,count);
			    rg->currentDown= 0;
		        }
		        return;
		    }
		    if ( rg->currentDown!=0 ) {
			int key = xE->u.u.detail;
			xE->u.u.type= KeyRelease;
			xE->u.u.detail= rg->currentDown;
		        XkbHandleActions(keybd,keybd,xE,count);
		        xE->u.u.type= KeyPress;
		        xE->u.u.detail= key;
		    }
		    rg->currentDown= key;
		}
		else ErrorF("InternalError! Illegal radio group %d\n",ndx);
		break;
	    case XkbKB_Overlay1: case XkbKB_Overlay2:
		{
		    unsigned	which;
		    if (behavior.type==XkbKB_Overlay1)	which= XkbOverlay1Mask;
		    else				which= XkbOverlay2Mask;
		    if ( (xkbi->desc->ctrls->enabled_ctrls&which)==0 )
			break;
		    if ((behavior.data>=xkbi->desc->min_key_code)&&
			(behavior.data<=xkbi->desc->max_key_code)) {
			xE->u.u.detail= behavior.data;
			/* 9/11/94 (ef) -- XXX! need to match release with */
			/*                 press even if the state of the  */
			/*                 corresponding overlay control   */
			/*                 changes while the key is down   */
		    }
		}
		break;
	    default:
		ErrorF("unknown key behavior 0x%04x\n",behavior.type);
#if defined(MetroLink)
		return;
#else
		break;
#endif
	}
    }
    XkbHandleActions(keybd,keybd,xE,count);
    return;
}

void
ProcessKeyboardEvent(xEvent *xE,DeviceIntPtr keybd,int count)
{
KeyClassPtr	keyc = keybd->key;
XkbSrvInfoPtr	xkbi;

    xkbi= keyc->xkbInfo;

#ifdef DEBUG
    if (xkbDebugFlags&0x8) {
	int key= xE->u.u.detail;
	ErrorF("PKE: Key %d %s\n",key,(xE->u.u.type==KeyPress?"down":"up"));
    }
#endif
    if ((xkbi->desc->ctrls->enabled_ctrls&XkbAllFilteredEventsMask)==0)
	XkbProcessKeyboardEvent(xE,keybd,count);
    else if (xE->u.u.type==KeyPress)
	AccessXFilterPressEvent(xE,keybd,count);
    else if (xE->u.u.type==KeyRelease)
	AccessXFilterReleaseEvent(xE,keybd,count);
    return;
}


--- NEW FILE: xkbPrOtherEv.c ---
/* $Xorg: xkbPrOtherEv.c,v 1.3 2000/08/17 19:53:48 cpqbld Exp $ */
/************************************************************
Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86$ */

#include <stdio.h>
#include <math.h>
#define NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include "misc.h"
#include "inputstr.h"
#include <X11/extensions/XKBsrv.h>

#include <X11/extensions/XI.h>
#include <X11/extensions/XIproto.h>

extern	void	ProcessOtherEvent(
    xEvent *		/* xE */,
    DeviceIntPtr 	/* dev */,
    int 		/* count */
);

/***====================================================================***/

void
XkbProcessOtherEvent(xEvent *xE,DeviceIntPtr dev,int count)
{
Bool	xkbCares,isBtn;

    xkbCares= True;
    isBtn= False;
    switch ( xE->u.u.type ) {
      case KeyPress:		xE->u.u.type= DeviceKeyPress; break;
      case KeyRelease:		xE->u.u.type= DeviceKeyRelease; break;
      case ButtonPress:		xE->u.u.type= DeviceButtonPress; 
				isBtn= True; 
				break;
      case ButtonRelease:	xE->u.u.type= DeviceButtonRelease;  
				isBtn= True; 
				break;
      default:			xkbCares= False; break;
    }
    if (xkbCares) {
	if ((!isBtn)||((dev->button)&&(dev->button->xkb_acts))) {
	   DeviceIntPtr	kbd;
	   if (dev->key)	kbd= dev;
	   else		kbd= (DeviceIntPtr)LookupKeyboardDevice();
	   XkbHandleActions(dev,kbd,xE,count);
	   return;
	}
    }
    ProcessOtherEvent(xE,dev,count);
    return;
}


--- NEW FILE: xkbSwap.c ---
/* $Xorg: xkbSwap.c,v 1.3 2000/08/17 19:53:48 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/xkbSwap.c,v 3.4 2003/09/13 16:39:01 dawes Exp $ */

#include "stdio.h"
#include <X11/X.h>
#define	NEED_EVENTS
#define	NEED_REPLIES
#include <X11/Xproto.h>
#include "misc.h"
#include "inputstr.h"
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XKBstr.h>
#include "extnsionst.h"
#include "xkb.h"

	/*
	 * REQUEST SWAPPING
	 */
static int
SProcXkbUseExtension(ClientPtr client)
{
register int n;

    REQUEST(xkbUseExtensionReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbUseExtensionReq);
    swaps(&stuff->wantedMajor,n);
    swaps(&stuff->wantedMinor,n);
    return ProcXkbUseExtension(client);
}

static int
SProcXkbSelectEvents(ClientPtr client)
{
register int n;

    REQUEST(xkbSelectEventsReq);

    swaps(&stuff->length,n);
    REQUEST_AT_LEAST_SIZE(xkbSelectEventsReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->affectWhich,n);
    swaps(&stuff->clear,n);
    swaps(&stuff->selectAll,n);
    swaps(&stuff->affectMap,n);
    swaps(&stuff->map,n);
    if ((stuff->affectWhich&(~XkbMapNotifyMask))!=0)  {
	union {
	    BOOL	*b;
	    CARD8	*c8;
	    CARD16	*c16;
	    CARD32	*c32;
	} from;
	register unsigned bit,ndx,maskLeft,dataLeft,size;

	from.c8= (CARD8 *)&stuff[1];
	dataLeft= (stuff->length*4)-SIZEOF(xkbSelectEventsReq);
	maskLeft= (stuff->affectWhich&(~XkbMapNotifyMask));
	for (ndx=0,bit=1; (maskLeft!=0); ndx++, bit<<=1) {
	    if (((bit&maskLeft)==0)||(ndx==XkbMapNotify))
		continue;
	    maskLeft&= ~bit;
	    if ((stuff->selectAll&bit)||(stuff->clear&bit))
		continue;
	    switch (ndx) {
		case XkbNewKeyboardNotify:
		case XkbStateNotify:
		case XkbNamesNotify:
		case XkbAccessXNotify:
		case XkbExtensionDeviceNotify:
		    size= 2;
		    break;
		case XkbControlsNotify:
		case XkbIndicatorStateNotify:
		case XkbIndicatorMapNotify:
		    size= 4;
		    break;
		case XkbBellNotify:
		case XkbActionMessage:
		case XkbCompatMapNotify:
		    size= 1;
		    break;
		default:
		    client->errorValue = _XkbErrCode2(0x1,bit);
		    return BadValue;
	    }
	    if (dataLeft<(size*2))
		return BadLength;
	    if (size==2) {
		swaps(&from.c16[0],n);
		swaps(&from.c16[1],n);
	    }
	    else if (size==4) {
		swapl(&from.c32[0],n);
		swapl(&from.c32[1],n);
	    }
	    else {
		size= 2;
	    }
	    from.c8+= (size*2);
	    dataLeft-= (size*2);
	}
	if (dataLeft>2) {
	    ErrorF("Extra data (%d bytes) after SelectEvents\n",dataLeft);
	    return BadLength;
	}
    }
    return ProcXkbSelectEvents(client);
}

static int
SProcXkbBell(ClientPtr client)
{
register int	n;

    REQUEST(xkbBellReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbBellReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->bellClass,n);
    swaps(&stuff->bellID,n);
    swapl(&stuff->name,n);
    swapl(&stuff->window,n);
    swaps(&stuff->pitch,n);
    swaps(&stuff->duration,n);
    return ProcXkbBell(client);
}

static int
SProcXkbGetState(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetStateReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbGetStateReq);
    swaps(&stuff->deviceSpec,n);
    return ProcXkbGetState(client);
}

static int
SProcXkbLatchLockState(ClientPtr client)
{
register int 	n;

    REQUEST(xkbLatchLockStateReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbLatchLockStateReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->groupLatch,n);
    return ProcXkbLatchLockState(client);
}

static int
SProcXkbGetControls(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetControlsReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbGetControlsReq);
    swaps(&stuff->deviceSpec,n);
    return ProcXkbGetControls(client);
}

static int
SProcXkbSetControls(ClientPtr client)
{
register int	n;

    REQUEST(xkbSetControlsReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbSetControlsReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->affectInternalVMods,n);
    swaps(&stuff->internalVMods,n);
    swaps(&stuff->affectIgnoreLockVMods,n);
    swaps(&stuff->ignoreLockVMods,n);
    swaps(&stuff->axOptions,n);
    swapl(&stuff->affectEnabledCtrls,n);
    swapl(&stuff->enabledCtrls,n);
    swapl(&stuff->changeCtrls,n);
    swaps(&stuff->repeatDelay,n);
    swaps(&stuff->repeatInterval,n);
    swaps(&stuff->slowKeysDelay,n);
    swaps(&stuff->debounceDelay,n);
    swaps(&stuff->mkDelay,n);
    swaps(&stuff->mkInterval,n);
    swaps(&stuff->mkTimeToMax,n);
    swaps(&stuff->mkMaxSpeed,n);
    swaps(&stuff->mkCurve,n);
    swaps(&stuff->axTimeout,n);
    swapl(&stuff->axtCtrlsMask,n);
    swapl(&stuff->axtCtrlsValues,n);
    swaps(&stuff->axtOptsMask,n);
    swaps(&stuff->axtOptsValues,n);
    return ProcXkbSetControls(client);
}

static int
SProcXkbGetMap(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetMapReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbGetMapReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->full,n);
    swaps(&stuff->partial,n);
    swaps(&stuff->virtualMods,n);
    return ProcXkbGetMap(client);
}

static int
SProcXkbSetMap(ClientPtr client)
{
register int	n;

    REQUEST(xkbSetMapReq);

    swaps(&stuff->length,n);
    REQUEST_AT_LEAST_SIZE(xkbSetMapReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->present,n);
    swaps(&stuff->flags,n);
    swaps(&stuff->totalSyms,n);
    swaps(&stuff->totalActs,n);
    swaps(&stuff->virtualMods,n);
    return ProcXkbSetMap(client);
}


static int
SProcXkbGetCompatMap(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetCompatMapReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbGetCompatMapReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->firstSI,n);
    swaps(&stuff->nSI,n);
    return ProcXkbGetCompatMap(client);
}

static int
SProcXkbSetCompatMap(ClientPtr client)
{
register int	n;

    REQUEST(xkbSetCompatMapReq);

    swaps(&stuff->length,n);
    REQUEST_AT_LEAST_SIZE(xkbSetCompatMapReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->firstSI,n);
    swaps(&stuff->nSI,n);
    return ProcXkbSetCompatMap(client);
}

static int
SProcXkbGetIndicatorState(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetIndicatorStateReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbGetIndicatorStateReq);
    swaps(&stuff->deviceSpec,n);
    return ProcXkbGetIndicatorState(client);
}

static int
SProcXkbGetIndicatorMap(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetIndicatorMapReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbGetIndicatorMapReq);
    swaps(&stuff->deviceSpec,n);
    swapl(&stuff->which,n);
    return ProcXkbGetIndicatorMap(client);
}

static int
SProcXkbSetIndicatorMap(ClientPtr client)
{
register int	n;

    REQUEST(xkbSetIndicatorMapReq);

    swaps(&stuff->length,n);
    REQUEST_AT_LEAST_SIZE(xkbSetIndicatorMapReq);
    swaps(&stuff->deviceSpec,n);
    swapl(&stuff->which,n);
    return ProcXkbSetIndicatorMap(client);
}

static int
SProcXkbGetNamedIndicator(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetNamedIndicatorReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbGetNamedIndicatorReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->ledClass,n);
    swaps(&stuff->ledID,n);
    swapl(&stuff->indicator,n);
    return ProcXkbGetNamedIndicator(client);
}

static int
SProcXkbSetNamedIndicator(ClientPtr client)
{
register int	n;

    REQUEST(xkbSetNamedIndicatorReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbSetNamedIndicatorReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->ledClass,n);
    swaps(&stuff->ledID,n);
    swapl(&stuff->indicator,n);
    swaps(&stuff->virtualMods,n);
    swapl(&stuff->ctrls,n);
    return ProcXkbSetNamedIndicator(client);
}


static int
SProcXkbGetNames(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetNamesReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbGetNamesReq);
    swaps(&stuff->deviceSpec,n);
    swapl(&stuff->which,n);
    return ProcXkbGetNames(client);
}

static int
SProcXkbSetNames(ClientPtr client)
{
register int	n;

    REQUEST(xkbSetNamesReq);

    swaps(&stuff->length,n);
    REQUEST_AT_LEAST_SIZE(xkbSetNamesReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->virtualMods,n);
    swapl(&stuff->which,n);
    swapl(&stuff->indicators,n);
    swaps(&stuff->totalKTLevelNames,n);
    return ProcXkbSetNames(client);
}

static int
SProcXkbGetGeometry(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetGeometryReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbGetGeometryReq);
    swaps(&stuff->deviceSpec,n);
    swapl(&stuff->name,n);
    return ProcXkbGetGeometry(client);
}

static int
SProcXkbSetGeometry(ClientPtr client)
{
register int	n;

    REQUEST(xkbSetGeometryReq);

    swaps(&stuff->length,n);
    REQUEST_AT_LEAST_SIZE(xkbSetGeometryReq);
    swaps(&stuff->deviceSpec,n);
    swapl(&stuff->name,n);
    swaps(&stuff->widthMM,n);
    swaps(&stuff->heightMM,n);
    swaps(&stuff->nProperties,n);
    swaps(&stuff->nColors,n);
    swaps(&stuff->nDoodads,n);
    swaps(&stuff->nKeyAliases,n);
    return ProcXkbSetGeometry(client);
}

static int
SProcXkbPerClientFlags(ClientPtr client)
{
register int	n;

    REQUEST(xkbPerClientFlagsReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbPerClientFlagsReq);
    swaps(&stuff->deviceSpec,n);
    swapl(&stuff->change,n);
    swapl(&stuff->value,n);
    swapl(&stuff->ctrlsToChange,n);
    swapl(&stuff->autoCtrls,n);
    swapl(&stuff->autoCtrlValues,n);
    return ProcXkbPerClientFlags(client);
}

static int
SProcXkbListComponents(ClientPtr client)
{
register int	n;

    REQUEST(xkbListComponentsReq);

    swaps(&stuff->length,n);
    REQUEST_AT_LEAST_SIZE(xkbListComponentsReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->maxNames,n);
    return ProcXkbListComponents(client);
}

static int
SProcXkbGetKbdByName(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetKbdByNameReq);

    swaps(&stuff->length,n);
    REQUEST_AT_LEAST_SIZE(xkbGetKbdByNameReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->want,n);
    swaps(&stuff->need,n);
    return ProcXkbGetKbdByName(client);
}

static int
SProcXkbGetDeviceInfo(ClientPtr client)
{
register int	n;

    REQUEST(xkbGetDeviceInfoReq);

    swaps(&stuff->length,n);
    REQUEST_SIZE_MATCH(xkbGetDeviceInfoReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->wanted,n);
    swaps(&stuff->ledClass,n);
    swaps(&stuff->ledID,n);
    return ProcXkbGetDeviceInfo(client);
}

static int
SProcXkbSetDeviceInfo(ClientPtr client)
{
register int	n;

    REQUEST(xkbSetDeviceInfoReq);

    swaps(&stuff->length,n);
    REQUEST_AT_LEAST_SIZE(xkbSetDeviceInfoReq);
    swaps(&stuff->deviceSpec,n);
    swaps(&stuff->change,n);
    swaps(&stuff->nDeviceLedFBs,n);
    return ProcXkbSetDeviceInfo(client);
}

static int
SProcXkbSetDebuggingFlags(ClientPtr client)
{
register int	n;

    REQUEST(xkbSetDebuggingFlagsReq);

    swaps(&stuff->length,n);
    REQUEST_AT_LEAST_SIZE(xkbSetDebuggingFlagsReq);
    swapl(&stuff->affectFlags,n);
    swapl(&stuff->flags,n);
    swapl(&stuff->affectCtrls,n);
    swapl(&stuff->ctrls,n);
    swaps(&stuff->msgLength,n);
    return ProcXkbSetDebuggingFlags(client);
}

int
SProcXkbDispatch (ClientPtr client)
{
    REQUEST(xReq);
    switch (stuff->data)
    {
    case X_kbUseExtension:
	return SProcXkbUseExtension(client);
    case X_kbSelectEvents:
	return SProcXkbSelectEvents(client);
    case X_kbBell:
	return SProcXkbBell(client);
    case X_kbGetState:
	return SProcXkbGetState(client);
    case X_kbLatchLockState:
	return SProcXkbLatchLockState(client);
    case X_kbGetControls:
	return SProcXkbGetControls(client);
    case X_kbSetControls:
	return SProcXkbSetControls(client);
    case X_kbGetMap:
	return SProcXkbGetMap(client);
    case X_kbSetMap:
	return SProcXkbSetMap(client);
    case X_kbGetCompatMap:
	return SProcXkbGetCompatMap(client);
    case X_kbSetCompatMap:
	return SProcXkbSetCompatMap(client);
    case X_kbGetIndicatorState:
	return SProcXkbGetIndicatorState(client);
    case X_kbGetIndicatorMap:
	return SProcXkbGetIndicatorMap(client);
    case X_kbSetIndicatorMap:
	return SProcXkbSetIndicatorMap(client);
    case X_kbGetNamedIndicator:
	return SProcXkbGetNamedIndicator(client);
    case X_kbSetNamedIndicator:
	return SProcXkbSetNamedIndicator(client);
    case X_kbGetNames:
	return SProcXkbGetNames(client);
    case X_kbSetNames:
	return SProcXkbSetNames(client);
    case X_kbGetGeometry:
	return SProcXkbGetGeometry(client);
    case X_kbSetGeometry:
	return SProcXkbSetGeometry(client);
    case X_kbPerClientFlags:
	return SProcXkbPerClientFlags(client);
    case X_kbListComponents:
	return SProcXkbListComponents(client);
    case X_kbGetKbdByName:
	return SProcXkbGetKbdByName(client);
    case X_kbGetDeviceInfo:
	return SProcXkbGetDeviceInfo(client);
    case X_kbSetDeviceInfo:
	return SProcXkbSetDeviceInfo(client);
    case X_kbSetDebuggingFlags:
	return SProcXkbSetDebuggingFlags(client);
    default:
	return BadRequest;
    }
}

--- NEW FILE: xkbUtils.c ---
/* $Xorg: xkbUtils.c,v 1.3 2000/08/17 19:53:48 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/programs/Xserver/xkb/xkbUtils.c,v 3.16 2003/11/03 05:12:02 tsi Exp $ */

#include <stdio.h>
#include <ctype.h>
#include <math.h>
#define NEED_EVENTS 1
#include <X11/X.h>
#include <X11/Xproto.h>
#define	XK_CYRILLIC
#include <X11/keysym.h>
#include "misc.h"
#include "inputstr.h"

#define	XKBSRV_NEED_FILE_FUNCS
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XKBgeom.h>
#include "xkb.h"

#ifdef MODE_SWITCH
extern Bool noKME; /* defined in os/utils.c */
#endif

int	XkbDisableLockActions = 0;

/***====================================================================***/

#ifndef RETURN_SHOULD_REPEAT
#if (defined(__osf__) && defined(__alpha))
#define RETURN_SHOULD_REPEAT 1
#else
#define	RETURN_SHOULD_REPEAT 0
#endif
#endif

/***====================================================================***/

DeviceIntPtr
_XkbLookupAnyDevice(int id,int *why_rtrn)
{
DeviceIntPtr dev = NULL;

    dev= (DeviceIntPtr)LookupKeyboardDevice();
    if ((id==XkbUseCoreKbd)||(dev->id==id))
	return dev;

    dev= (DeviceIntPtr)LookupPointerDevice();
    if ((id==XkbUseCorePtr)||(dev->id==id))
	return dev;

    if (id&(~0xff))
	 dev = NULL;

    dev= (DeviceIntPtr)LookupDevice(id);
    if (dev!=NULL) 
	return dev;
    if ((!dev)&&(why_rtrn))
	*why_rtrn= XkbErr_BadDevice;
    return dev;
}

DeviceIntPtr
_XkbLookupKeyboard(int id,int *why_rtrn)
{
DeviceIntPtr dev = NULL;

    if ((dev= _XkbLookupAnyDevice(id,why_rtrn))==NULL)
	return NULL;
    else if ((!dev->key)||(!dev->key->xkbInfo)) {
	if (why_rtrn)
	   *why_rtrn= XkbErr_BadClass;
	return NULL;
    }
    return dev;
}

DeviceIntPtr
_XkbLookupBellDevice(int id,int *why_rtrn)
{
DeviceIntPtr dev = NULL;

    if ((dev= _XkbLookupAnyDevice(id,why_rtrn))==NULL)
	return NULL;
    else if ((!dev->kbdfeed)&&(!dev->bell)) {
	if (why_rtrn)
	   *why_rtrn= XkbErr_BadClass;
	return NULL;
    }
    return dev;
}

DeviceIntPtr
_XkbLookupLedDevice(int id,int *why_rtrn)
{
DeviceIntPtr dev = NULL;

    if ((dev= _XkbLookupAnyDevice(id,why_rtrn))==NULL)
	return NULL;
    else if ((!dev->kbdfeed)&&(!dev->leds)) {
	if (why_rtrn)
	   *why_rtrn= XkbErr_BadClass;
	return NULL;
    }
    return dev;
}

DeviceIntPtr
_XkbLookupButtonDevice(int id,int *why_rtrn)
{
DeviceIntPtr dev = NULL;

    if ((dev= _XkbLookupAnyDevice(id,why_rtrn))==NULL)
	return NULL;
    else if (!dev->button) {
	if (why_rtrn)
	   *why_rtrn= XkbErr_BadClass;
	return NULL;
    }
    return dev;
}

void
XkbSetActionKeyMods(XkbDescPtr xkb,XkbAction *act,unsigned mods)
{
register unsigned	tmp;

    switch (act->type) {
	case XkbSA_SetMods: case XkbSA_LatchMods: case XkbSA_LockMods:
	    if (act->mods.flags&XkbSA_UseModMapMods)
		act->mods.real_mods= act->mods.mask= mods;
	    if ((tmp= XkbModActionVMods(&act->mods))!=0)
		act->mods.mask|= XkbMaskForVMask(xkb,tmp);
	    break;
	case XkbSA_ISOLock:
	    if (act->iso.flags&XkbSA_UseModMapMods)
		act->iso.real_mods= act->iso.mask= mods;
	    if ((tmp= XkbModActionVMods(&act->iso))!=0)
		act->iso.mask|= XkbMaskForVMask(xkb,tmp);
	    break;
    }
    return;
}

unsigned
XkbMaskForVMask(XkbDescPtr xkb,unsigned vmask)
{
register int i,bit;
register unsigned mask;
    
    for (mask=i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
	if (vmask&bit)
	    mask|= xkb->server->vmods[i];
    }
    return mask;
}


Bool
XkbApplyVModChanges(	XkbSrvInfoPtr		xkbi,
			unsigned		changed,
			XkbChangesPtr		changes,
			unsigned *		needChecksRtrn,
			XkbEventCausePtr	cause)
{
XkbDescPtr		xkb;
Bool			check;

    xkb= xkbi->desc;
#ifdef DEBUG
{
register unsigned i,bit;
    for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
	if ((changed&bit)==0)
	    continue;
	if (xkbDebugFlags)
	    ErrorF("Should be applying: change vmod %d to 0x%x\n",i,
					xkb->server->vmods[i]);
    }
}
#endif
    check= XkbApplyVirtualModChanges(xkb,changed,changes);
    XkbApplyVModChangesToAllDevices(xkbi->device,xkb,changed,cause);

    if (needChecksRtrn!=NULL)  {
	if (check)
	     *needChecksRtrn= XkbStateNotifyMask|XkbIndicatorStateNotifyMask;
	else *needChecksRtrn= 0;
    }
    else if (check) {
	/* 7/12/95 (ef) -- XXX check compatibility and/or indicator state */
    }
    return 1;
}

/***====================================================================***/

void
XkbUpdateKeyTypesFromCore(	DeviceIntPtr	pXDev,
				KeyCode	 	first,
				CARD8	 	num,
				XkbChangesPtr	changes)
{
XkbDescPtr		xkb;
unsigned		key,nG,explicit;
KeySymsPtr		pCore;
int			types[XkbNumKbdGroups];
KeySym			tsyms[XkbMaxSymsPerKey],*syms;
XkbMapChangesPtr	mc;

    xkb= pXDev->key->xkbInfo->desc;
#ifdef NOTYET
    if (first<xkb->min_key_code) {
	if (first>=XkbMinLegalKeyCode) {
	    xkb->min_key_code= first;
	    /* 1/12/95 (ef) -- XXX! should zero out the new maps */
	    changes->map.changed|= XkbKeycodesMask;
generate a NewKeyboard notify here?
	}
    }
#endif
    if (first+num-1>xkb->max_key_code) {
	/* 1/12/95 (ef) -- XXX! should allow XKB structures to grow */
	num= xkb->max_key_code-first+1;
    }

    mc= (changes?(&changes->map):NULL);

    pCore= &pXDev->key->curKeySyms;
    syms= &pCore->map[(first-xkb->min_key_code)*pCore->mapWidth];
    for (key=first; key<(first+num); key++,syms+= pCore->mapWidth) {
        explicit= xkb->server->explicit[key]&XkbExplicitKeyTypesMask;
        types[XkbGroup1Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup1Index);
        types[XkbGroup2Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup2Index);
        types[XkbGroup3Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup3Index);
        types[XkbGroup4Index]= XkbKeyKeyTypeIndex(xkb,key,XkbGroup4Index);
        nG= XkbKeyTypesForCoreSymbols(xkb,pCore->mapWidth,syms,explicit,types,
									tsyms);
	XkbChangeTypesOfKey(xkb,key,nG,XkbAllGroupsMask,types,mc);
	memcpy((char *)XkbKeySymsPtr(xkb,key),(char *)tsyms,
					XkbKeyNumSyms(xkb,key)*sizeof(KeySym));
    }
    if (changes->map.changed&XkbKeySymsMask) {
	CARD8 oldLast,newLast;
	oldLast = changes->map.first_key_sym+changes->map.num_key_syms-1;
	newLast = first+num-1;

	if (first<changes->map.first_key_sym)
	    changes->map.first_key_sym = first;
	if (oldLast>newLast)
	    newLast= oldLast;
	changes->map.num_key_syms = newLast-changes->map.first_key_sym+1;
    }
    else {
	changes->map.changed|= XkbKeySymsMask;
	changes->map.first_key_sym = first;
	changes->map.num_key_syms = num;
    }
    return;
}

void
XkbUpdateDescActions(	XkbDescPtr		xkb,
			KeyCode		 	first,
			CARD8		 	num,
			XkbChangesPtr	 	changes)
{
register unsigned	key;

    for (key=first;key<(first+num);key++) {
	XkbApplyCompatMapToKey(xkb,key,changes);
    }

    if (changes->map.changed&(XkbVirtualModMapMask|XkbModifierMapMask)) {
        unsigned char           newVMods[XkbNumVirtualMods];
        register  unsigned      bit,i;
        unsigned                present;

        bzero(newVMods,XkbNumVirtualMods);
        present= 0;
        for (key=xkb->min_key_code;key<=xkb->max_key_code;key++) {
            if (xkb->server->vmodmap[key]==0)
                continue;
            for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
                if (bit&xkb->server->vmodmap[key]) {
                    present|= bit;
                    newVMods[i]|= xkb->map->modmap[key];
                }
            }
        }
        for (i=0,bit=1;i<XkbNumVirtualMods;i++,bit<<=1) {
            if ((bit&present)&&(newVMods[i]!=xkb->server->vmods[i])) {
                changes->map.changed|= XkbVirtualModsMask;
                changes->map.vmods|= bit;
                xkb->server->vmods[i]= newVMods[i];
            }
        }
    }
    if (changes->map.changed&XkbVirtualModsMask)
        XkbApplyVirtualModChanges(xkb,changes->map.vmods,changes);

    if (changes->map.changed&XkbKeyActionsMask) {
	CARD8 oldLast,newLast;
	oldLast= changes->map.first_key_act+changes->map.num_key_acts-1;
	newLast = first+num-1;

	if (first<changes->map.first_key_act)
	    changes->map.first_key_act = first;
	if (newLast>oldLast)
	    newLast= oldLast;
	changes->map.num_key_acts= newLast-changes->map.first_key_act+1;
    }
    else {
	changes->map.changed|= XkbKeyActionsMask;
	changes->map.first_key_act = first;
	changes->map.num_key_acts = num;
    }
    return;
}

void
XkbUpdateActions(	DeviceIntPtr	 	pXDev,
			KeyCode		 	first,
			CARD8		 	num,
			XkbChangesPtr	 	changes,
			unsigned *	 	needChecksRtrn,
			XkbEventCausePtr	cause)
{
XkbSrvInfoPtr		xkbi;
XkbDescPtr		xkb;
CARD8 *			repeat;

    if (needChecksRtrn)
	*needChecksRtrn= 0;
    xkbi= pXDev->key->xkbInfo;
    xkb= xkbi->desc;
    repeat= xkb->ctrls->per_key_repeat;

    if (pXDev->kbdfeed)
	memcpy(repeat,pXDev->kbdfeed->ctrl.autoRepeats,32);

    XkbUpdateDescActions(xkb,first,num,changes);

    if ((pXDev->kbdfeed)&&
	(changes->ctrls.enabled_ctrls_changes&XkbPerKeyRepeatMask)) {
        memcpy(pXDev->kbdfeed->ctrl.autoRepeats,repeat, 32);
	(*pXDev->kbdfeed->CtrlProc)(pXDev, &pXDev->kbdfeed->ctrl);
    }
    return;
}

void
XkbUpdateCoreDescription(DeviceIntPtr keybd,Bool resize)
{
register int		key,tmp;
int			maxSymsPerKey,maxKeysPerMod;
int			first,last,firstCommon,lastCommon;
XkbDescPtr		xkb;
KeyClassPtr		keyc;
CARD8			keysPerMod[XkbNumModifiers];

    if (!keybd || !keybd->key || !keybd->key->xkbInfo)
	return;
    xkb= keybd->key->xkbInfo->desc;
    keyc= keybd->key;
    maxSymsPerKey= maxKeysPerMod= 0;
    bzero(keysPerMod,sizeof(keysPerMod));
    memcpy(keyc->modifierMap,xkb->map->modmap,xkb->max_key_code+1);
    if ((xkb->min_key_code==keyc->curKeySyms.minKeyCode)&&
	(xkb->max_key_code==keyc->curKeySyms.maxKeyCode)) {
	first= firstCommon= xkb->min_key_code;
	last= lastCommon= xkb->max_key_code;
    }
    else if (resize) {
	keyc->curKeySyms.minKeyCode= xkb->min_key_code;
	keyc->curKeySyms.maxKeyCode= xkb->max_key_code;
	tmp= keyc->curKeySyms.mapWidth*_XkbCoreNumKeys(keyc);
	keyc->curKeySyms.map= _XkbTypedRealloc(keyc->curKeySyms.map,tmp,KeySym);
	if (!keyc->curKeySyms.map)
	   FatalError("Couldn't allocate keysyms\n");
	first= firstCommon= xkb->min_key_code;
	last= lastCommon= xkb->max_key_code;
    }
    else {
	if (xkb->min_key_code<keyc->curKeySyms.minKeyCode) {
	    first= xkb->min_key_code;
	    firstCommon= keyc->curKeySyms.minKeyCode;
	}
	else {
	    firstCommon= xkb->min_key_code;
	    first= keyc->curKeySyms.minKeyCode;
	}
	if (xkb->max_key_code>keyc->curKeySyms.maxKeyCode) {
	    lastCommon= keyc->curKeySyms.maxKeyCode;
	    last= xkb->max_key_code;
	}
	else {
	    lastCommon= xkb->max_key_code;
	    last= keyc->curKeySyms.maxKeyCode;
	}
    }

    /* determine sizes */
    for (key=first;key<=last;key++) {
	if (XkbKeycodeInRange(xkb,key)) {
	    int	nGroups;
	    int	w;
	    nGroups= XkbKeyNumGroups(xkb,key);
	    tmp= 0;
	    if (nGroups>0) {
		if ((w=XkbKeyGroupWidth(xkb,key,XkbGroup1Index))<=2)
		     tmp+= 2;
		else tmp+= w + 2;
	    }
	    if (nGroups>1) {
                if (tmp <= 2) {
		     if ((w=XkbKeyGroupWidth(xkb,key,XkbGroup2Index))<2)
		          tmp+= 2;
		     else tmp+= w;
                } else {
                     if ((w=XkbKeyGroupWidth(xkb,key,XkbGroup2Index))>2)
                          tmp+= w - 2;
                }
	    }
	    if (nGroups>2)
		tmp+= XkbKeyGroupWidth(xkb,key,XkbGroup3Index);
	    if (nGroups>3)
		tmp+= XkbKeyGroupWidth(xkb,key,XkbGroup4Index);
	    if (tmp>maxSymsPerKey)
		maxSymsPerKey= tmp;
	}
	if (_XkbCoreKeycodeInRange(keyc,key)) {
	    if (keyc->modifierMap[key]!=0) {
		register unsigned bit,i,mask;
		mask= keyc->modifierMap[key];
		for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) {
		    if (mask&bit) {
			keysPerMod[i]++;
			if (keysPerMod[i]>maxKeysPerMod)
			    maxKeysPerMod= keysPerMod[i];
		    }
		}
	    }
	}
    }

    if (maxKeysPerMod>0) {
	tmp= maxKeysPerMod*XkbNumModifiers;
	if (keyc->modifierKeyMap==NULL)
	    keyc->modifierKeyMap= (KeyCode *)_XkbCalloc(1, tmp);
	else if (keyc->maxKeysPerModifier<maxKeysPerMod)
	    keyc->modifierKeyMap= (KeyCode *)_XkbRealloc(keyc->modifierKeyMap,tmp);
	if (keyc->modifierKeyMap==NULL)
	    FatalError("Couldn't allocate modifierKeyMap in UpdateCore\n");
	bzero(keyc->modifierKeyMap,tmp);
    }
    else if ((keyc->maxKeysPerModifier>0)&&(keyc->modifierKeyMap!=NULL)) {
	_XkbFree(keyc->modifierKeyMap);
	keyc->modifierKeyMap= NULL;
    }
    keyc->maxKeysPerModifier= maxKeysPerMod;

    if (maxSymsPerKey>0) {
	tmp= maxSymsPerKey*_XkbCoreNumKeys(keyc);
	keyc->curKeySyms.map= _XkbTypedRealloc(keyc->curKeySyms.map,tmp,KeySym);
	if (keyc->curKeySyms.map==NULL)
	    FatalError("Couldn't allocate symbols map in UpdateCore\n");
    }
    else if ((keyc->curKeySyms.mapWidth>0)&&(keyc->curKeySyms.map!=NULL)) {
	_XkbFree(keyc->curKeySyms.map);
	keyc->curKeySyms.map= NULL;
    }
    keyc->curKeySyms.mapWidth= maxSymsPerKey;

    bzero(keysPerMod,sizeof(keysPerMod));
    for (key=firstCommon;key<=lastCommon;key++) {
	if (keyc->curKeySyms.map!=NULL) {
	    KeySym *pCore,*pXKB;
	    unsigned nGroups,groupWidth,n,nOut;

	    nGroups= XkbKeyNumGroups(xkb,key);
	    n= (key-keyc->curKeySyms.minKeyCode)*maxSymsPerKey;
	    pCore= &keyc->curKeySyms.map[n];
	    bzero(pCore,maxSymsPerKey*sizeof(KeySym));
	    pXKB= XkbKeySymsPtr(xkb,key);
	    nOut= 2;
	    if (nGroups>0) {
		groupWidth= XkbKeyGroupWidth(xkb,key,XkbGroup1Index);
		if (groupWidth>0)	pCore[0]= pXKB[0];
		if (groupWidth>1)	pCore[1]= pXKB[1];
		for (n=2;n<groupWidth;n++) {
		    pCore[2+n]= pXKB[n];
		}
		if (groupWidth>2)
		    nOut= groupWidth;
	    }
	    pXKB+= XkbKeyGroupsWidth(xkb,key);
	    nOut+= 2;
	    if (nGroups>1) {
		groupWidth= XkbKeyGroupWidth(xkb,key,XkbGroup2Index);
		if (groupWidth>0)	pCore[2]= pXKB[0];
		if (groupWidth>1)	pCore[3]= pXKB[1];
		for (n=2;n<groupWidth;n++) {
		    pCore[nOut+(n-2)]= pXKB[n];
		}
		if (groupWidth>2)
		    nOut+= (groupWidth-2);
	    }
	    pXKB+= XkbKeyGroupsWidth(xkb,key);
	    for (n=XkbGroup3Index;n<nGroups;n++) {
		register int s;
		groupWidth= XkbKeyGroupWidth(xkb,key,n);
		for (s=0;s<groupWidth;s++) {
		    pCore[nOut++]= pXKB[s];
		}
		pXKB+= XkbKeyGroupsWidth(xkb,key);
	    }
	    if (!pCore[2] && !pCore[3] && maxSymsPerKey >= 6 &&
                (pCore[4] || pCore[5])) {
                pCore[2] = pCore[4];
                pCore[3] = pCore[5];
	    }
	}
	if (keyc->modifierMap[key]!=0) {
	    register unsigned bit,i,mask;
	    mask= keyc->modifierMap[key];
	    for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) {
		if (mask&bit) {
		    tmp= i*maxKeysPerMod+keysPerMod[i];
		    keyc->modifierKeyMap[tmp]= key;
		    keysPerMod[i]++;
		}
	    }
	}
    }
#ifdef MODE_SWITCH
    /* Fix up any of the KME stuff if we changed the core description.
     */
    if (!noKME)
	HandleKeyBinding(keyc, &keyc->curKeySyms);
#endif
    return;
}

void
XkbSetRepeatKeys(DeviceIntPtr pXDev,int key,int onoff)
{
    if (pXDev && pXDev->key && pXDev->key->xkbInfo) {
	xkbControlsNotify	cn;
	XkbControlsPtr		ctrls = pXDev->key->xkbInfo->desc->ctrls;
	XkbControlsRec 		old;
	old = *ctrls;

	if (key== -1) {	/* global autorepeat setting changed */
	    if (onoff)	ctrls->enabled_ctrls |= XkbRepeatKeysMask;
	    else	ctrls->enabled_ctrls &= ~XkbRepeatKeysMask;
	}
	else if (pXDev->kbdfeed) {
	    ctrls->per_key_repeat[key/8] = 
		pXDev->kbdfeed->ctrl.autoRepeats[key/8];
	}
	
	if (XkbComputeControlsNotify(pXDev,&old,ctrls,&cn,True))
	    XkbSendControlsNotify(pXDev,&cn);
    }
    return;
}

void
XkbApplyMappingChange(	DeviceIntPtr	kbd,
			CARD8		 request,
			KeyCode		 firstKey,
			CARD8		 num,
			ClientPtr	 client)
{
XkbEventCauseRec	cause;
XkbChangesRec	 	changes;
unsigned	 	check;

    if (kbd->key->xkbInfo==NULL)
	XkbInitDevice(kbd);
    bzero(&changes,sizeof(XkbChangesRec));
    check= 0;
    if (request==MappingKeyboard) {
	XkbSetCauseCoreReq(&cause,X_ChangeKeyboardMapping,client);
	XkbUpdateKeyTypesFromCore(kbd,firstKey,num,&changes);
	XkbUpdateActions(kbd,firstKey,num,&changes,&check,&cause);
	if (check)
	    XkbCheckSecondaryEffects(kbd->key->xkbInfo,check,&changes,&cause);
    }
    else if (request==MappingModifier) {
	XkbDescPtr	xkb= kbd->key->xkbInfo->desc;

	XkbSetCauseCoreReq(&cause,X_SetModifierMapping,client);

	num = xkb->max_key_code-xkb->min_key_code+1;
	memcpy(xkb->map->modmap,kbd->key->modifierMap,xkb->max_key_code+1);

	changes.map.changed|= XkbModifierMapMask;
	changes.map.first_modmap_key= xkb->min_key_code;
	changes.map.num_modmap_keys= num;
	XkbUpdateActions(kbd,xkb->min_key_code,num,&changes,&check,&cause);
	if (check)
	    XkbCheckSecondaryEffects(kbd->key->xkbInfo,check,&changes,&cause);
    }
    /* 3/26/94 (ef) -- XXX! Doesn't deal with input extension requests */
    XkbSendNotification(kbd,&changes,&cause);
    return;
}

void
XkbDisableComputedAutoRepeats(DeviceIntPtr dev,unsigned key)
{
XkbSrvInfoPtr	xkbi = dev->key->xkbInfo;
xkbMapNotify	mn;

    xkbi->desc->server->explicit[key]|= XkbExplicitAutoRepeatMask;
    bzero(&mn,sizeof(mn));
    mn.changed= XkbExplicitComponentsMask;
    mn.firstKeyExplicit= key;
    mn.nKeyExplicit= 1;
    XkbSendMapNotify(dev,&mn);
    return;
}

unsigned
XkbStateChangedFlags(XkbStatePtr old,XkbStatePtr new)
{
int		changed;

    changed=(old->group!=new->group?XkbGroupStateMask:0);
    changed|=(old->base_group!=new->base_group?XkbGroupBaseMask:0);
    changed|=(old->latched_group!=new->latched_group?XkbGroupLatchMask:0);
    changed|=(old->locked_group!=new->locked_group?XkbGroupLockMask:0);
    changed|=(old->mods!=new->mods?XkbModifierStateMask:0);
    changed|=(old->base_mods!=new->base_mods?XkbModifierBaseMask:0);
    changed|=(old->latched_mods!=new->latched_mods?XkbModifierLatchMask:0);
    changed|=(old->locked_mods!=new->locked_mods?XkbModifierLockMask:0);
    changed|=(old->compat_state!=new->compat_state?XkbCompatStateMask:0);
    changed|=(old->grab_mods!=new->grab_mods?XkbGrabModsMask:0);
    if (old->compat_grab_mods!=new->compat_grab_mods)
	changed|= XkbCompatGrabModsMask;
    changed|=(old->lookup_mods!=new->lookup_mods?XkbLookupModsMask:0);
    if (old->compat_lookup_mods!=new->compat_lookup_mods)
	changed|= XkbCompatLookupModsMask;
    changed|=(old->ptr_buttons!=new->ptr_buttons?XkbPointerButtonMask:0);
    return changed;
}

void
XkbComputeCompatState(XkbSrvInfoPtr xkbi)
{
CARD16 		grp_mask;
XkbStatePtr	state= &xkbi->state;
XkbCompatMapPtr	map;

    map= xkbi->desc->compat;
    grp_mask= map->groups[state->group].mask;
    state->compat_state = state->mods|grp_mask;
    state->compat_lookup_mods= state->lookup_mods|grp_mask;

    if (xkbi->desc->ctrls->enabled_ctrls&XkbIgnoreGroupLockMask)
	 grp_mask= map->groups[state->base_group].mask;
    state->compat_grab_mods= state->grab_mods|grp_mask;
    return;
}

unsigned
XkbAdjustGroup(int group,XkbControlsPtr ctrls)
{
unsigned	act;

    act= XkbOutOfRangeGroupAction(ctrls->groups_wrap);
    if (group<0) {
	while ( group < 0 )  {
	    if (act==XkbClampIntoRange) {
		group= XkbGroup1Index;
	    }
	    else if (act==XkbRedirectIntoRange) {
		int newGroup;
		newGroup= XkbOutOfRangeGroupNumber(ctrls->groups_wrap);
		if (newGroup>=ctrls->num_groups)
		     group= XkbGroup1Index;
		else group= newGroup;
	    }
	    else {
		group+= ctrls->num_groups;
	    }
	}
    }
    else if (group>=ctrls->num_groups) {
	if (act==XkbClampIntoRange) {
	    group= ctrls->num_groups-1;
	}
	else if (act==XkbRedirectIntoRange) {
	    int newGroup;
	    newGroup= XkbOutOfRangeGroupNumber(ctrls->groups_wrap);
	    if (newGroup>=ctrls->num_groups)
		 group= XkbGroup1Index;
	    else group= newGroup;
	}
	else {
	    group%= ctrls->num_groups;
	}
    }
    return group;
}

void
XkbComputeDerivedState(XkbSrvInfoPtr xkbi)
{
XkbStatePtr	state= &xkbi->state;
XkbControlsPtr	ctrls= xkbi->desc->ctrls;
unsigned char	grp;

    state->mods= (state->base_mods|state->latched_mods);
    state->mods|= state->locked_mods;
    state->lookup_mods= state->mods&(~ctrls->internal.mask);
    state->grab_mods= state->lookup_mods&(~ctrls->ignore_lock.mask);
    state->grab_mods|= 
	((state->base_mods|state->latched_mods)&ctrls->ignore_lock.mask);


    grp= state->locked_group;
    if (grp>=ctrls->num_groups)
	state->locked_group= XkbAdjustGroup(grp,ctrls);

    grp= state->locked_group+state->base_group+state->latched_group;
    if (grp>=ctrls->num_groups)
	 state->group= XkbAdjustGroup(grp,ctrls);
    else state->group= grp;
    XkbComputeCompatState(xkbi);
    return;
}

/***====================================================================***/

void
XkbCheckSecondaryEffects(	XkbSrvInfoPtr		xkbi,
				unsigned		which,
				XkbChangesPtr 		changes,
				XkbEventCausePtr	cause)
{
    if (which&XkbStateNotifyMask) {
	XkbStateRec old;
	old= xkbi->state;
	changes->state_changes|= XkbStateChangedFlags(&old,&xkbi->state);
	XkbComputeDerivedState(xkbi);
    }
    if (which&XkbIndicatorStateNotifyMask)
	XkbUpdateIndicators(xkbi->device,XkbAllIndicatorsMask,True,changes,
									cause);
    return;
}

/***====================================================================***/

void
XkbSetPhysicalLockingKey(DeviceIntPtr dev,unsigned key)
{
XkbDescPtr	xkb;

    xkb= dev->key->xkbInfo->desc;
    if ((key>=xkb->min_key_code) && (key<=xkb->max_key_code)) {
	xkb->server->behaviors[key].type= XkbKB_Lock|XkbKB_Permanent;
    }
    else ErrorF("Internal Error!  Bad XKB info in SetPhysicalLockingKey\n");
    return;
}

/***====================================================================***/

Bool
XkbEnableDisableControls(	XkbSrvInfoPtr		xkbi,
				unsigned long		change,
				unsigned long		newValues,
				XkbChangesPtr		changes,
				XkbEventCausePtr	cause)
{
XkbControlsPtr		ctrls;
unsigned 		old;
XkbSrvLedInfoPtr	sli;

    ctrls= xkbi->desc->ctrls;
    old= ctrls->enabled_ctrls;
    ctrls->enabled_ctrls&= ~change;
    ctrls->enabled_ctrls|= (change&newValues);
    if (old==ctrls->enabled_ctrls)
	return False;
    if (cause!=NULL) {
	xkbControlsNotify cn;
	cn.numGroups= ctrls->num_groups;
	cn.changedControls|= XkbControlsEnabledMask;
	cn.enabledControls= ctrls->enabled_ctrls;
	cn.enabledControlChanges= (ctrls->enabled_ctrls^old);
	cn.keycode= cause->kc;
	cn.eventType= cause->event;
	cn.requestMajor= cause->mjr;
	cn.requestMinor= cause->mnr;
	XkbSendControlsNotify(xkbi->device,&cn);
    }
    else {
	/* Yes, this really should be an XOR.  If ctrls->enabled_ctrls_changes*/
	/* is non-zero, the controls in question changed already in "this" */
	/* request and this change merely undoes the previous one.  By the */
	/* same token, we have to figure out whether or not ControlsEnabled */
	/* should be set or not in the changes structure */
	changes->ctrls.enabled_ctrls_changes^= (ctrls->enabled_ctrls^old);
	if (changes->ctrls.enabled_ctrls_changes)
	     changes->ctrls.changed_ctrls|= XkbControlsEnabledMask;
	else changes->ctrls.changed_ctrls&= ~XkbControlsEnabledMask;
    }
    sli= XkbFindSrvLedInfo(xkbi->device,XkbDfltXIClass,XkbDfltXIId,0);
    XkbUpdateIndicators(xkbi->device,sli->usesControls,True,changes,cause);
    return True;
}

/***====================================================================***/

#define	MAX_TOC	16

XkbGeometryPtr 
XkbLookupNamedGeometry(DeviceIntPtr dev,Atom name,Bool *shouldFree)
{
XkbSrvInfoPtr	xkbi=	dev->key->xkbInfo;
XkbDescPtr	xkb=	xkbi->desc;

    *shouldFree= 0;
    if (name==None) {
	if (xkb->geom!=NULL)
	    return xkb->geom;
	name= xkb->names->geometry;
    }
    if ((xkb->geom!=NULL)&&(xkb->geom->name==name))
	return xkb->geom;
    else if ((name==xkb->names->geometry)&&(xkb->geom==NULL)) {
	FILE *file= XkbDDXOpenConfigFile(XkbInitialMap,NULL,0);
	if (file!=NULL) {
	    XkbFileInfo		xkbFInfo;
	    xkmFileInfo		finfo;
	    xkmSectionInfo	toc[MAX_TOC],*entry;
	    bzero(&xkbFInfo,sizeof(xkbFInfo));
	    xkbFInfo.xkb= xkb;
	    if (XkmReadTOC(file,&finfo,MAX_TOC,toc)) {
		entry= XkmFindTOCEntry(&finfo,toc,XkmGeometryIndex);
		if (entry!=NULL)
		    XkmReadFileSection(file,entry,&xkbFInfo,NULL);
	    }
	    fclose(file);
	    if (xkb->geom) {
		*shouldFree= 0;
		return xkb->geom;
	    }
	}
    }
    *shouldFree= 1;
    return NULL;
}

void
XkbConvertCase(register KeySym sym, KeySym *lower, KeySym *upper)
{
    *lower = sym;
    *upper = sym;
    switch(sym >> 8) {
    case 0: /* Latin 1 */
	if ((sym >= XK_A) && (sym <= XK_Z))
	    *lower += (XK_a - XK_A);
	else if ((sym >= XK_a) && (sym <= XK_z))
	    *upper -= (XK_a - XK_A);
	else if ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis))
	    *lower += (XK_agrave - XK_Agrave);
	else if ((sym >= XK_agrave) && (sym <= XK_odiaeresis))
	    *upper -= (XK_agrave - XK_Agrave);
	else if ((sym >= XK_Ooblique) && (sym <= XK_Thorn))
	    *lower += (XK_oslash - XK_Ooblique);
	else if ((sym >= XK_oslash) && (sym <= XK_thorn))
	    *upper -= (XK_oslash - XK_Ooblique);
	break;
    case 1: /* Latin 2 */
	/* Assume the KeySym is a legal value (ignore discontinuities) */
	if (sym == XK_Aogonek)
	    *lower = XK_aogonek;
	else if (sym >= XK_Lstroke && sym <= XK_Sacute)
	    *lower += (XK_lstroke - XK_Lstroke);
	else if (sym >= XK_Scaron && sym <= XK_Zacute)
	    *lower += (XK_scaron - XK_Scaron);
	else if (sym >= XK_Zcaron && sym <= XK_Zabovedot)
	    *lower += (XK_zcaron - XK_Zcaron);
	else if (sym == XK_aogonek)
	    *upper = XK_Aogonek;
	else if (sym >= XK_lstroke && sym <= XK_sacute)
	    *upper -= (XK_lstroke - XK_Lstroke);
	else if (sym >= XK_scaron && sym <= XK_zacute)
	    *upper -= (XK_scaron - XK_Scaron);
	else if (sym >= XK_zcaron && sym <= XK_zabovedot)
	    *upper -= (XK_zcaron - XK_Zcaron);
	else if (sym >= XK_Racute && sym <= XK_Tcedilla)
	    *lower += (XK_racute - XK_Racute);
	else if (sym >= XK_racute && sym <= XK_tcedilla)
	    *upper -= (XK_racute - XK_Racute);
	break;
    case 2: /* Latin 3 */
	/* Assume the KeySym is a legal value (ignore discontinuities) */
	if (sym >= XK_Hstroke && sym <= XK_Hcircumflex)
	    *lower += (XK_hstroke - XK_Hstroke);
	else if (sym >= XK_Gbreve && sym <= XK_Jcircumflex)
	    *lower += (XK_gbreve - XK_Gbreve);
	else if (sym >= XK_hstroke && sym <= XK_hcircumflex)
	    *upper -= (XK_hstroke - XK_Hstroke);
	else if (sym >= XK_gbreve && sym <= XK_jcircumflex)
	    *upper -= (XK_gbreve - XK_Gbreve);
	else if (sym >= XK_Cabovedot && sym <= XK_Scircumflex)
	    *lower += (XK_cabovedot - XK_Cabovedot);
	else if (sym >= XK_cabovedot && sym <= XK_scircumflex)
	    *upper -= (XK_cabovedot - XK_Cabovedot);
	break;
    case 3: /* Latin 4 */
	/* Assume the KeySym is a legal value (ignore discontinuities) */
	if (sym >= XK_Rcedilla && sym <= XK_Tslash)
	    *lower += (XK_rcedilla - XK_Rcedilla);
	else if (sym >= XK_rcedilla && sym <= XK_tslash)
	    *upper -= (XK_rcedilla - XK_Rcedilla);
	else if (sym == XK_ENG)
	    *lower = XK_eng;
	else if (sym == XK_eng)
	    *upper = XK_ENG;
	else if (sym >= XK_Amacron && sym <= XK_Umacron)
	    *lower += (XK_amacron - XK_Amacron);
	else if (sym >= XK_amacron && sym <= XK_umacron)
	    *upper -= (XK_amacron - XK_Amacron);
	break;
    case 6: /* Cyrillic */
	/* Assume the KeySym is a legal value (ignore discontinuities) */
	if (sym >= XK_Serbian_DJE && sym <= XK_Serbian_DZE)
	    *lower -= (XK_Serbian_DJE - XK_Serbian_dje);
	else if (sym >= XK_Serbian_dje && sym <= XK_Serbian_dze)
	    *upper += (XK_Serbian_DJE - XK_Serbian_dje);
	else if (sym >= XK_Cyrillic_YU && sym <= XK_Cyrillic_HARDSIGN)
	    *lower -= (XK_Cyrillic_YU - XK_Cyrillic_yu);
	else if (sym >= XK_Cyrillic_yu && sym <= XK_Cyrillic_hardsign)
	    *upper += (XK_Cyrillic_YU - XK_Cyrillic_yu);
        break;
    case 7: /* Greek */
	/* Assume the KeySym is a legal value (ignore discontinuities) */
	if (sym >= XK_Greek_ALPHAaccent && sym <= XK_Greek_OMEGAaccent)
	    *lower += (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
	else if (sym >= XK_Greek_alphaaccent && sym <= XK_Greek_omegaaccent &&
		 sym != XK_Greek_iotaaccentdieresis &&
		 sym != XK_Greek_upsilonaccentdieresis)
	    *upper -= (XK_Greek_alphaaccent - XK_Greek_ALPHAaccent);
	else if (sym >= XK_Greek_ALPHA && sym <= XK_Greek_OMEGA)
	    *lower += (XK_Greek_alpha - XK_Greek_ALPHA);
	else if (sym >= XK_Greek_alpha && sym <= XK_Greek_omega &&
		 sym != XK_Greek_finalsmallsigma)
	    *upper -= (XK_Greek_alpha - XK_Greek_ALPHA);
        break;
    }
}

--- NEW FILE: xkbconfig.c ---
/* $Xorg: xkbconfig.c,v 1.4 2000/08/17 19:46:43 cpqbld Exp $ */
/************************************************************
 Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.

 Permission to use, copy, modify, and distribute this
 software and its documentation for any purpose and without
 fee is hereby granted, provided that the above copyright
 notice appear in all copies and that both that copyright
 notice and this permission notice appear in supporting
 documentation, and that the name of Silicon Graphics not be 
 used in advertising or publicity pertaining to distribution 
 of the software without specific prior written permission.
 Silicon Graphics makes no representation about the suitability 
 of this software for any purpose. It is provided "as is"
 without any express or implied warranty.
 
 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...1310 lines suppressed...]
	case XkbCF_ExpectedAXOption:
	    msg= "expected an AccessX option on line %d"; break;
	case XkbCF_ExpectedOperator:
	    msg= "expected '+' or '-' on line %d"; break;
	case XkbCF_ExpectedOORGroupBehavior:
	    msg= "expected wrap, clamp or group number on line %d"; break;
	default:
	    msg= "unknown error on line %d"; break;
    }
#ifndef XKB_IN_SERVER
    fprintf(file,msg,line);
    if (name)	fprintf(file," of %s\n",name);
    else	fprintf(file,"\n");
#else
    ErrorF(msg,line);
    if (name)	ErrorF(" of %s\n",name);
    else	ErrorF("\n");
#endif
    return;
}

--- NEW FILE: xkberrs.c ---
/* $Xorg: xkberrs.c,v 1.3 2000/08/17 19:46:44 cpqbld Exp $ */
/************************************************************
 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.

 Permission to use, copy, modify, and distribute this
 software and its documentation for any purpose and without
 fee is hereby granted, provided that the above copyright
 notice appear in all copies and that both that copyright
 notice and this permission notice appear in supporting
 documentation, and that the name of Silicon Graphics not be
 used in advertising or publicity pertaining to distribution
 of the software without specific prior written permission.
 Silicon Graphics makes no representation about the suitability
 of this software for any purpose. It is provided "as is"
 without any express or implied warranty.

 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
 THE USE OR PERFORMANCE OF THIS SOFTWARE.

 ********************************************************/
/* $XFree86: xc/lib/xkbfile/xkberrs.c,v 3.4 2001/07/29 05:01:13 tsi Exp $ */

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

char *		_XkbErrMessages[] = {
	"success",				/* _XkbSuccess		     */
	"key names not defined",		/* _XkbErrMissingNames	     */
	"key types not defined",		/* _XkbErrMissingTypes	     */
	"required key types not present",	/* _XkbErrMissingReqTypes    */
	"symbols not defined",			/* _XkbErrMissingSymbols     */
	"virtual modifier bindings not defined",/* _XkbErrMissingVMods	     */
	"indicators not defined",		/* _XkbErrMissingIndicators  */
	"compatibility map not defined",	/* _XkbErrMissingCompatMap   */
	"symbol interpretations not defined",	/* _XkbErrMissingSymInterps  */
	"geometry not defined",			/* _XkbErrMissingGeometry    */
	"illegal doodad type",			/* _XkbErrIllegalDoodad	     */
	"illegal TOC type",			/* _XkbErrIllegalTOCType     */
	"illegal contents",			/* _XkbErrIllegalContents    */
	"empty file",				/* _XkbErrEmptyFile	     */
	"file not found",			/* _XkbErrFileNotFound       */
	"cannot open",				/* _XkbErrFileCannotOpen     */
	"bad value",				/* _XkbErrBadValue           */
	"bad match",				/* _XkbErrBadMatch           */
	"illegal name for type",		/* _XkbErrBadTypeName        */
	"illegal width for type",		/* _XkbErrBadTypeWidth       */
	"bad file type",			/* _XkbErrBadFileType        */
	"bad file version",			/* _XkbErrBadFileVersion     */
	"error in Xkm file",			/* _XkbErrBadFileFormat      */
	"allocation failed",			/* _XkbErrBadAlloc           */
	"bad length",                           /* _XkbErrBadLength          */
	"X request failed",			/* _XkbErrXReqFailure        */
	"not implemented"                       /* _XkbErrBadImplementation  */
};

unsigned	_XkbErrCode;
char *		_XkbErrLocation= NULL;
unsigned	_XkbErrData;


--- NEW FILE: xkbfmisc.c ---
/* $Xorg: xkbmisc.c,v 1.4 2000/08/17 19:46:44 cpqbld Exp $ */
/************************************************************
 Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.

 Permission to use, copy, modify, and distribute this
 software and its documentation for any purpose and without
 fee is hereby granted, provided that the above copyright
 notice appear in all copies and that both that copyright
 notice and this permission notice appear in supporting
 documentation, and that the name of Silicon Graphics not be 
 used in advertising or publicity pertaining to distribution 
 of the software without specific prior written permission.
 Silicon Graphics makes no representation about the suitability 
 of this software for any purpose. It is provided "as is"
 without any express or implied warranty.
 
 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
 THE USE OR PERFORMANCE OF THIS SOFTWARE.

 ********************************************************/
/* $XFree86: xc/lib/xkbfile/xkbmisc.c,v 1.7 2003/07/16 02:31:10 dawes Exp $ */

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#include <X11/Xos.h>
#include <X11/Xfuncs.h>

#ifndef XKB_IN_SERVER

#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBgeom.h>
#include <X11/extensions/XKMformat.h>
#include <X11/extensions/XKBfileInt.h>

#else

#include <X11/X.h>
#define	NEED_EVENTS
#include <X11/keysym.h>
#include <X11/Xproto.h>
#include "misc.h"
#include "inputstr.h"
#include "dix.h"
#include <X11/extensions/XKBstr.h>
#define XKBSRV_NEED_FILE_FUNCS	1
#include <X11/extensions/XKBsrv.h>
#include <X11/extensions/XKBgeom.h>
#include "xkb.h"

#endif

unsigned
_XkbKSCheckCase(KeySym ks)
{
unsigned	set,rtrn;

    set= (ks & (~0xff)) >> 8;
    rtrn= 0;
    switch (set) {
	case 0:		/* latin 1 */
	    if (((ks>=XK_A)&&(ks<=XK_Z))||
		((ks>=XK_Agrave)&&(ks<=XK_THORN)&&(ks!=XK_multiply))) {
		rtrn|= _XkbKSUpper;
	    }
	    if (((ks>=XK_a)&&(ks<=XK_z))||
		((ks>=XK_agrave)&&(ks<=XK_ydiaeresis))) {
		rtrn|= _XkbKSLower;
	    }
	    break;
	case 1:		/* latin 2 */
	    if (((ks>=XK_Aogonek)&&(ks<=XK_Zabovedot)&&(ks!=XK_breve))||
		((ks>=XK_Racute)&&(ks<=XK_Tcedilla))) {
		rtrn|= _XkbKSUpper;
	    }
	    if (((ks>=XK_aogonek)&&(ks<=XK_zabovedot)&&(ks!=XK_caron))||
		((ks>=XK_racute)&&(ks<=XK_tcedilla))) {
		rtrn|= _XkbKSLower;
	    }
	    break;
	case 2:		/* latin 3 */
	    if (((ks>=XK_Hstroke)&&(ks<=XK_Jcircumflex))||
		((ks>=XK_Cabovedot)&&(ks<=XK_Scircumflex))) {
		rtrn|= _XkbKSUpper;
	    }
	    if (((ks>=XK_hstroke)&&(ks<=XK_jcircumflex))||
		((ks>=XK_cabovedot)&&(ks<=XK_scircumflex))) {
		rtrn|= _XkbKSLower;
	    }
	    break;
	case 3:		/* latin 4 */
	    if (((ks>=XK_Rcedilla)&&(ks<=XK_Tslash))||
	        (ks==XK_ENG)||
		((ks>=XK_Amacron)&&(ks<=XK_Umacron))) {
		rtrn|= _XkbKSUpper;
	    }
	    if (((ks>=XK_rcedilla)&&(ks<=XK_tslash))||
	        (ks==XK_eng)||
		((ks>=XK_amacron)&&(ks<=XK_umacron))) {
		rtrn|= _XkbKSLower;
	    }
	    break;
	case 18:		/* latin 8 */
	    if ((ks==XK_Babovedot)||
                ((ks>=XK_Dabovedot)&&(ks<=XK_Wacute))||
		((ks>=XK_Ygrave)&&(ks<=XK_Fabovedot))||
	        (ks==XK_Mabovedot)||
	        (ks==XK_Pabovedot)||
	        (ks==XK_Sabovedot)||
	        (ks==XK_Wdiaeresis)||
		((ks>=XK_Wcircumflex)&&(ks<=XK_Ycircumflex))) {
		rtrn|= _XkbKSUpper;
	    }
	    if ((ks==XK_babovedot)||
	        (ks==XK_dabovedot)||
	        (ks==XK_fabovedot)||
	        (ks==XK_mabovedot)||
                ((ks>=XK_wgrave)&&(ks<=XK_wacute))||
	        (ks==XK_ygrave)||
		((ks>=XK_wdiaeresis)&&(ks<=XK_ycircumflex))) {
		rtrn|= _XkbKSLower;
	    }
	    break;
	case 19:		/* latin 9 */
	    if ((ks==XK_OE)||(ks==XK_Ydiaeresis)) {
		rtrn|= _XkbKSUpper;
	    }
	    if (ks==XK_oe) {
		rtrn|= _XkbKSLower;
	    }
	    break;
    }
    return rtrn;
}

/***===================================================================***/

int
_XkbStrCaseCmp(char *str1,char *str2)
{
    char buf1[512],buf2[512];
    char c, *s;
    register int n;

    for (n=0, s = buf1; (c = *str1++); n++) {
        if (isupper(c))
            c = tolower(c);
        if (n>510)
            break;
        *s++ = c;
    }
    *s = '\0';
    for (n=0, s = buf2; (c = *str2++); n++) {
        if (isupper(c))
            c = tolower(c);
        if (n>510)
            break;
        *s++ = c;
    }
    *s = '\0';
    return (strcmp(buf1, buf2));
}

/***===================================================================***/

Bool
XkbLookupGroupAndLevel(	XkbDescPtr 	xkb,
			int 		key,
			int *		mods_inout,
			int *		grp_inout,
			int *		lvl_rtrn)
{
int		nG,eG;

    if ((!xkb)||(!XkbKeycodeInRange(xkb,key))||(!grp_inout))
	return False;

    nG= XkbKeyNumGroups(xkb,key);
    eG= *grp_inout;

    if ( nG==0 ) {
	*grp_inout= 0;
	if (lvl_rtrn!=NULL)
	    *lvl_rtrn= 0;
	return False;
    }
    else if ( nG==1 ) {
	eG= 0;
    }
    else if ( eG>=nG ) {
	unsigned gI= XkbKeyGroupInfo(xkb,key);
	switch (XkbOutOfRangeGroupAction(gI)) {
	    default:
		eG %= nG;
		break;
	    case XkbClampIntoRange:
		eG = nG-1;
		break;
	    case XkbRedirectIntoRange:
		eG = XkbOutOfRangeGroupNumber(gI);
		if (eG>=nG)
		    eG= 0;
		break;
	}
    }
    *grp_inout= eG;
    if (mods_inout!=NULL) {
	XkbKeyTypePtr	type;
	int		preserve;

	type = XkbKeyKeyType(xkb,key,eG);
	if (lvl_rtrn!=NULL)
	    *lvl_rtrn= 0;
	preserve= 0;
	if (type->map) { /* find the shift level */
	    register int i;
	    register XkbKTMapEntryPtr entry;
	    for (i=0,entry=type->map;i<type->map_count;i++,entry++) {
		if ((entry->active)&&
			(((*mods_inout)&type->mods.mask)==entry->mods.mask)){
		    if (lvl_rtrn!=NULL)
			*lvl_rtrn= entry->level;
		    if (type->preserve)
			preserve= type->preserve[i].mask;
		    break;
		}
	    }
	}
	(*mods_inout)&= ~(type->mods.mask&(~preserve));
    }
    return True;
}

/***===================================================================***/

static Bool
XkbWriteSectionFromName(FILE *file,char *sectionName,char *name)
{
    fprintf(file,"    xkb_%-20s { include \"%s\" };\n",sectionName,name);
    return True;
}

#define	NEED_DESC(n) ((!n)||((n)[0]=='+')||((n)[0]=='|')||(strchr((n),'%')))
#define	COMPLETE(n)  ((n)&&(!NEED_DESC(n)))

/* ARGSUSED */
static void
_AddIncl(	FILE *		file,
		XkbFileInfo *	result,
		Bool 		topLevel,
		Bool 		showImplicit,
		int 		index,
		void *		priv)
{
    if ((priv)&&(strcmp((char *)priv,"%")!=0))
	fprintf(file,"    include \"%s\"\n",(char *)priv);
    return;
}

Bool
XkbWriteXKBKeymapForNames(	FILE *			file,
				XkbComponentNamesPtr	names,
				Display *		dpy,
				XkbDescPtr		xkb,
				unsigned		want,
				unsigned		need)
{
char *		name,*tmp;
unsigned	complete;
XkbNamesPtr	old_names;
int		multi_section;
unsigned	wantNames,wantConfig,wantDflts;
XkbFileInfo	finfo;

    bzero(&finfo,sizeof(XkbFileInfo));

    complete= 0;
    if ((name=names->keymap)==NULL)	name= "default";
    if (COMPLETE(names->keycodes))	complete|= XkmKeyNamesMask;
    if (COMPLETE(names->types))		complete|= XkmTypesMask;
    if (COMPLETE(names->compat))	complete|= XkmCompatMapMask;
    if (COMPLETE(names->symbols))	complete|= XkmSymbolsMask;
    if (COMPLETE(names->geometry))	complete|= XkmGeometryMask;
    want|= (complete|need);
    if (want&XkmSymbolsMask)
	want|= XkmKeyNamesMask|XkmTypesMask;

    if (want==0)
	return False;

    if (xkb!=NULL) {
	 old_names= xkb->names;
	 finfo.type= 0;
	 finfo.defined= 0;
	 finfo.xkb= xkb;
	 if (!XkbDetermineFileType(&finfo,XkbXKBFile,NULL))
	    return False;
    }
    else old_names= NULL;

    wantConfig= want&(~complete);
    if (xkb!=NULL) {
	if (wantConfig&XkmTypesMask) {
	    if ((!xkb->map) || (xkb->map->num_types<XkbNumRequiredTypes))
		wantConfig&= ~XkmTypesMask;
	}
	if (wantConfig&XkmCompatMapMask) {
	    if ((!xkb->compat) || (xkb->compat->num_si<1))
		wantConfig&= ~XkmCompatMapMask;
	}
	if (wantConfig&XkmSymbolsMask) {
	    if ((!xkb->map) || (!xkb->map->key_sym_map))
		wantConfig&= ~XkmSymbolsMask;
	}
	if (wantConfig&XkmIndicatorsMask) {
	    if (!xkb->indicators)
		wantConfig&= ~XkmIndicatorsMask;
	}
	if (wantConfig&XkmKeyNamesMask) {
	    if ((!xkb->names)||(!xkb->names->keys))
		wantConfig&= ~XkmKeyNamesMask;
	}
	if ((wantConfig&XkmGeometryMask)&&(!xkb->geom))
	    wantConfig&= ~XkmGeometryMask;
    }
    else {
	wantConfig= 0;
    }
    complete|= wantConfig;

    wantDflts= 0;
    wantNames= want&(~complete);
    if ((xkb!=NULL) && (old_names!=NULL)) {
	if (wantNames&XkmTypesMask) {
	    if (old_names->types!=None) {
		tmp= XkbAtomGetString(dpy,old_names->types);
		names->types= _XkbDupString(tmp);
	    }
	    else {
		wantDflts|= XkmTypesMask;
	    }
	    complete|= XkmTypesMask; 
	}
	if (wantNames&XkmCompatMapMask) {
	    if (old_names->compat!=None) {
		tmp= XkbAtomGetString(dpy,old_names->compat);
		names->compat= _XkbDupString(tmp);
	    }
	    else wantDflts|= XkmCompatMapMask;
	    complete|= XkmCompatMapMask; 
	}
	if (wantNames&XkmSymbolsMask) {
	    if (old_names->symbols==None)
		return False;
	    tmp= XkbAtomGetString(dpy,old_names->symbols);
	    names->symbols= _XkbDupString(tmp);
	    complete|= XkmSymbolsMask; 
	}
	if (wantNames&XkmKeyNamesMask) {
	   if (old_names->keycodes!=None) {
		tmp= XkbAtomGetString(dpy,old_names->keycodes);
		names->keycodes= _XkbDupString(tmp);
	    }
	    else wantDflts|= XkmKeyNamesMask;
	    complete|= XkmKeyNamesMask;
	}
	if (wantNames&XkmGeometryMask) {
	    if (old_names->geometry==None)
		return False;
	    tmp= XkbAtomGetString(dpy,old_names->geometry);
	    names->geometry= _XkbDupString(tmp);
	    complete|= XkmGeometryMask; 
	    wantNames&= ~XkmGeometryMask;
	}
    }
    if (complete&XkmCompatMapMask)
	complete|= XkmIndicatorsMask|XkmVirtualModsMask;
    else if (complete&(XkmSymbolsMask|XkmTypesMask))
	complete|= XkmVirtualModsMask;
    if (need & (~complete))
	return False;
    if ((complete&XkmSymbolsMask)&&((XkmKeyNamesMask|XkmTypesMask)&(~complete)))
	return False;

    multi_section= 1;
    if (((complete&XkmKeymapRequired)==XkmKeymapRequired)&&
	((complete&(~XkmKeymapLegal))==0)) {
	fprintf(file,"xkb_keymap \"%s\" {\n",name);
    }
    else if (((complete&XkmSemanticsRequired)==XkmSemanticsRequired)&&
	((complete&(~XkmSemanticsLegal))==0)) {
	fprintf(file,"xkb_semantics \"%s\" {\n",name);
    }
    else if (((complete&XkmLayoutRequired)==XkmLayoutRequired)&&
	((complete&(~XkmLayoutLegal))==0)) {
	fprintf(file,"xkb_layout \"%s\" {\n",name);
    }
    else if (XkmSingleSection(complete&(~XkmVirtualModsMask))) {
	multi_section= 0;
    }
    else {
	return False;
    }

    wantNames= complete&(~(wantConfig|wantDflts));
    name= names->keycodes;
    if (wantConfig&XkmKeyNamesMask)
	XkbWriteXKBKeycodes(file,&finfo,False,False,_AddIncl,name);
    else if (wantDflts&XkmKeyNamesMask)
	fprintf(stderr,"Default symbols not implemented yet!\n");
    else if (wantNames&XkmKeyNamesMask)
	XkbWriteSectionFromName(file,"keycodes",name);

    name= names->types;
    if (wantConfig&XkmTypesMask)
	XkbWriteXKBKeyTypes(file,&finfo,False,False,_AddIncl,name);
    else if (wantDflts&XkmTypesMask)
	fprintf(stderr,"Default types not implemented yet!\n");
    else if (wantNames&XkmTypesMask)
	XkbWriteSectionFromName(file,"types",name);

    name= names->compat;
    if (wantConfig&XkmCompatMapMask)
	XkbWriteXKBCompatMap(file,&finfo,False,False,_AddIncl,name);
    else if (wantDflts&XkmCompatMapMask)
	fprintf(stderr,"Default interps not implemented yet!\n");
    else if (wantNames&XkmCompatMapMask)
	XkbWriteSectionFromName(file,"compatibility",name);

    name= names->symbols;
    if (wantConfig&XkmSymbolsMask)
	XkbWriteXKBSymbols(file,&finfo,False,False,_AddIncl,name);
    else if (wantNames&XkmSymbolsMask)
	XkbWriteSectionFromName(file,"symbols",name);

    name= names->geometry;
    if (wantConfig&XkmGeometryMask)
	XkbWriteXKBGeometry(file,&finfo,False,False,_AddIncl,name);
    else if (wantNames&XkmGeometryMask)
	XkbWriteSectionFromName(file,"geometry",name);

    if (multi_section)
	fprintf(file,"};\n");
    return True;
}

/***====================================================================***/

/*ARGSUSED*/
Status
XkbMergeFile(XkbDescPtr xkb,XkbFileInfo finfo)
{
    return BadImplementation;
}

/***====================================================================***/

int
XkbFindKeycodeByName(XkbDescPtr xkb,char *name,Bool use_aliases)
{
register int	i;

    if ((!xkb)||(!xkb->names)||(!xkb->names->keys))
	return 0;
    for (i=xkb->min_key_code;i<=xkb->max_key_code;i++) {
	if (strncmp(xkb->names->keys[i].name,name,XkbKeyNameLength)==0)
	    return i;
    }
    if (!use_aliases)
	return 0;
    if (xkb->geom && xkb->geom->key_aliases) {
	XkbKeyAliasPtr	a;
	a= xkb->geom->key_aliases;
	for (i=0;i<xkb->geom->num_key_aliases;i++,a++) {
	    if (strncmp(name,a->alias,XkbKeyNameLength)==0)
		return XkbFindKeycodeByName(xkb,a->real,False);
	}
    }
    if (xkb->names && xkb->names->key_aliases) {
	XkbKeyAliasPtr	a;
	a= xkb->names->key_aliases;
	for (i=0;i<xkb->names->num_key_aliases;i++,a++) {
	    if (strncmp(name,a->alias,XkbKeyNameLength)==0)
		return XkbFindKeycodeByName(xkb,a->real,False);
	}
    }
    return 0;
}


unsigned
XkbConvertGetByNameComponents(Bool toXkm,unsigned orig)
{
unsigned	rtrn;

    rtrn= 0;
    if (toXkm) {
	if (orig&XkbGBN_TypesMask)		rtrn|= XkmTypesMask;
	if (orig&XkbGBN_CompatMapMask)		rtrn|= XkmCompatMapMask;
	if (orig&XkbGBN_SymbolsMask)		rtrn|= XkmSymbolsMask;
	if (orig&XkbGBN_IndicatorMapMask)	rtrn|= XkmIndicatorsMask;
	if (orig&XkbGBN_KeyNamesMask)		rtrn|= XkmKeyNamesMask;
	if (orig&XkbGBN_GeometryMask)		rtrn|= XkmGeometryMask;
    }
    else {
	if (orig&XkmTypesMask)			rtrn|= XkbGBN_TypesMask;
	if (orig&XkmCompatMapMask)		rtrn|= XkbGBN_CompatMapMask;
	if (orig&XkmSymbolsMask)		rtrn|= XkbGBN_SymbolsMask;
	if (orig&XkmIndicatorsMask)		rtrn|= XkbGBN_IndicatorMapMask;
	if (orig&XkmKeyNamesMask)		rtrn|= XkbGBN_KeyNamesMask;
	if (orig&XkmGeometryMask)		rtrn|= XkbGBN_GeometryMask;
	if (orig!=0)				rtrn|= XkbGBN_OtherNamesMask;
    }
    return rtrn;
}

unsigned
XkbConvertXkbComponents(Bool toXkm,unsigned orig)
{
unsigned	rtrn;

    rtrn= 0;
    if (toXkm) {
	if (orig&XkbClientMapMask)	rtrn|= XkmTypesMask|XkmSymbolsMask;
	if (orig&XkbServerMapMask)	rtrn|= XkmTypesMask|XkmSymbolsMask;
	if (orig&XkbCompatMapMask)	rtrn|= XkmCompatMapMask;
	if (orig&XkbIndicatorMapMask)	rtrn|= XkmIndicatorsMask;
	if (orig&XkbNamesMask)		rtrn|= XkmKeyNamesMask;
	if (orig&XkbGeometryMask)	rtrn|= XkmGeometryMask;
    }
    else {
	if (orig!=0)			rtrn|= XkbNamesMask;
	if (orig&XkmTypesMask)		rtrn|= XkbClientMapMask;
	if (orig&XkmCompatMapMask)
		rtrn|= XkbCompatMapMask|XkbIndicatorMapMask;
	if (orig&XkmSymbolsMask)	rtrn|=XkbClientMapMask|XkbServerMapMask;
	if (orig&XkmIndicatorsMask)	rtrn|= XkbIndicatorMapMask;
	if (orig&XkmKeyNamesMask)	
		rtrn|= XkbNamesMask|XkbIndicatorMapMask;
	if (orig&XkmGeometryMask)	rtrn|= XkbGeometryMask;
    }
    return rtrn;
}

Bool
XkbDetermineFileType(XkbFileInfoPtr finfo,int format,int *opts_missing)
{
unsigned	present;
XkbDescPtr	xkb;

    if ((!finfo)||(!finfo->xkb))
	return False;
    if (opts_missing)
	*opts_missing= 0;
    xkb= finfo->xkb;
    present= 0;
    if ((xkb->names)&&(xkb->names->keys))	present|= XkmKeyNamesMask;
    if ((xkb->map)&&(xkb->map->types))		present|= XkmTypesMask;
    if (xkb->compat)				present|= XkmCompatMapMask;
    if ((xkb->map)&&(xkb->map->num_syms>1))	present|= XkmSymbolsMask;
    if (xkb->indicators)			present|= XkmIndicatorsMask;
    if (xkb->geom)				present|= XkmGeometryMask;
    if (!present)
	return False;
    else switch (present) {
	case XkmKeyNamesMask:	
	    finfo->type= 	XkmKeyNamesIndex;
	    finfo->defined= 	present;
	    return True;
	case XkmTypesMask:
	    finfo->type=	XkmTypesIndex;
	    finfo->defined= 	present;
	    return True;
	case XkmCompatMapMask:	
	    finfo->type=	XkmCompatMapIndex;
	    finfo->defined=	present;
	    return True;
	case XkmSymbolsMask:	
	    if (format!=XkbXKMFile) {
		finfo->type= 	XkmSymbolsIndex;
		finfo->defined=	present;
		return True;
	    }
	    break;
	case XkmGeometryMask:	
	    finfo->type=	XkmGeometryIndex;
	    finfo->defined=	present;
	    return True;
    }
    if ((present&(~XkmSemanticsLegal))==0) {
	if ((XkmSemanticsRequired&present)==XkmSemanticsRequired) {
	    if (opts_missing)
		*opts_missing= XkmSemanticsOptional&(~present);
	    finfo->type= 	XkmSemanticsFile;
	    finfo->defined=	present;
	    return True;
	}
    }
    else if ((present&(~XkmLayoutLegal))==0) {
	if ((XkmLayoutRequired&present)==XkmLayoutRequired) {
	    if (opts_missing)
		*opts_missing= XkmLayoutOptional&(~present);
	    finfo->type=	XkmLayoutFile;
	    finfo->defined=	present;
	    return True;
	}
    }
    else if ((present&(~XkmKeymapLegal))==0) {
	if ((XkmKeymapRequired&present)==XkmKeymapRequired) {
	    if (opts_missing)
		*opts_missing= XkmKeymapOptional&(~present);
	    finfo->type=	XkmKeymapFile;
	    finfo->defined=	present;
	    return True;
	}
    }
    return False;
}

/* all latin-1 alphanumerics, plus parens, slash, minus, underscore and */
/* wildcards */

static unsigned char componentSpecLegal[] = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0xff, 0x83,
	0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x07,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
};

void
XkbEnsureSafeMapName(char *name)
{
   if (name==NULL)
        return;
    while (*name!='\0') {
	if ((componentSpecLegal[(*name)/8]&(1<<((*name)%8)))==0)
	    *name= '_';
        name++;
    }
    return;
}

/***====================================================================***/

#define	UNMATCHABLE(c)	(((c)=='(')||((c)==')')||((c)=='/'))

Bool
XkbNameMatchesPattern(char *name,char *ptrn)
{
    while (ptrn[0]!='\0') {
	if (name[0]=='\0') {
	    if (ptrn[0]=='*') {
		ptrn++;
		continue;
	    }
	    return False;
	}
	if (ptrn[0]=='?') {
	    if (UNMATCHABLE(name[0]))
		return False;
	}
	else if (ptrn[0]=='*') {
	    if ((!UNMATCHABLE(name[0]))&&XkbNameMatchesPattern(name+1,ptrn))
		return True;
	    return XkbNameMatchesPattern(name,ptrn+1);
	}
	else if (ptrn[0]!=name[0])
	    return False;
	name++;
	ptrn++;
    }
    /* if we get here, the pattern is exhausted (-:just like me:-) */
    return (name[0]=='\0');
}

--- NEW FILE: xkbout.c ---
/* $Xorg: xkbout.c,v 1.3 2000/08/17 19:46:44 cpqbld Exp $ */
/************************************************************
 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.

 Permission to use, copy, modify, and distribute this
 software and its documentation for any purpose and without
 fee is hereby granted, provided that the above copyright
 notice appear in all copies and that both that copyright
 notice and this permission notice appear in supporting
 documentation, and that the name of Silicon Graphics not be 
 used in advertising or publicity pertaining to distribution 
 of the software without specific prior written permission.
 Silicon Graphics makes no representation about the suitability 
 of this software for any purpose. It is provided "as is"
 without any express or implied warranty.
 
 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...1021 lines suppressed...]
	    break;
	case XkmGeometryFile:
	case XkmGeometryIndex:
	    func= XkbWriteXKBGeometry;
	    break;
	case XkmVirtualModsIndex:
	case XkmIndicatorsIndex:
	    _XkbLibError(_XkbErrBadImplementation,
	    		XkbConfigText(result->type,XkbMessage),0);
	    return False;
    }
    if (out==NULL) {
	_XkbLibError(_XkbErrFileCannotOpen,"XkbWriteXkbFile",0);
	ok= False;
    }
    else if (func) {
	ok= (*func)(out,result,True,showImplicit,addOn,priv);
    }
    return ok;
}

--- NEW FILE: xkbtext.c ---
/* $Xorg: xkbtext.c,v 1.3 2000/08/17 19:46:44 cpqbld Exp $ */
/************************************************************
 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.

 Permission to use, copy, modify, and distribute this
 software and its documentation for any purpose and without
 fee is hereby granted, provided that the above copyright
 notice appear in all copies and that both that copyright
 notice and this permission notice appear in supporting
 documentation, and that the name of Silicon Graphics not be 
 used in advertising or publicity pertaining to distribution 
 of the software without specific prior written permission.
 Silicon Graphics makes no representation about the suitability 
 of this software for any purpose. It is provided "as is"
 without any express or implied warranty.
 
 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...1395 lines suppressed...]
	if ((tmp>0)&&(tmp<=100)) {
	    tmp= (PIXEL_MAX*tmp)/100;
	    color->red= 0;
	    color->green= color->blue= tmp;
	    return True;
	}
    }
    else if ((tmp=(_XkbStrCaseEqual(def,"yellow")*100))||
             (sscanf(def,"yellow%d",&tmp)==1)) {
	if ((tmp>0)&&(tmp<=100)) {
	    tmp= (PIXEL_MAX*tmp)/100;
	    color->blue= 0;
	    color->red= color->green= tmp;
	    return True;
	}
    }
    return False;
}

#endif

--- NEW FILE: xkmread.c ---
/* $Xorg: xkmread.c,v 1.3 2000/08/17 19:46:44 cpqbld Exp $ */
/************************************************************
 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.

 Permission to use, copy, modify, and distribute this
 software and its documentation for any purpose and without
 fee is hereby granted, provided that the above copyright
 notice appear in all copies and that both that copyright
 notice and this permission notice appear in supporting
 documentation, and that the name of Silicon Graphics not be 
 used in advertising or publicity pertaining to distribution 
 of the software without specific prior written permission.
 Silicon Graphics makes no representation about the suitability 
 of this software for any purpose. It is provided "as is"
 without any express or implied warranty.
 
 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
[...1270 lines suppressed...]
		tmp= ReadXkmGeometry(file,result);
		break;
	    default:
		_XkbLibError(_XkbErrBadImplementation,
				XkbConfigText(tmpTOC.type,XkbMessage),0);
		tmp= 0;
		break;
	}
	if (tmp>0) {
	    nRead+= tmp;
	    which&= ~(1<<toc[i].type);
	    result->defined|= (1<<toc[i].type);
	}
	if (nRead!=tmpTOC.size) {
	    _XkbLibError(_XkbErrBadLength,XkbConfigText(tmpTOC.type,XkbMessage),
	    						nRead-tmpTOC.size);
	}
    }
    return which;
}




More information about the xserver-commit mailing list