summaryrefslogtreecommitdiff
path: root/src/xkbconfig.c
blob: c94b06feb93b62987cb8ed72c4cced8f61035d95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
/* $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
 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/xkbconfig.c,v 3.7 2001/11/30 12:11:51 eich Exp $ */

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

#include <X11/Xfuncs.h>

#include <X11/Xfuncs.h>

#ifndef XKB_IN_SERVER

#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include "XKBfileInt.h"

#else

#include "X.h"
#define	NEED_EVENTS
#include <X11/keysym.h>
#include "Xproto.h"
#include "misc.h"
#include "inputstr.h"
#include "dix.h"
#define	XKBSRV_NEED_FILE_FUNCS
#include "XKBsrv.h"
#endif

#include <X11/extensions/XKBconfig.h>

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

#define	XKBCF_MAX_STR_LEN	100
static char _XkbCF_rtrn[XKBCF_MAX_STR_LEN+1];

static int
#if NeedFunctionPrototypes
ScanIdent(FILE *file,int ch,XkbCFScanResultPtr val_rtrn)
#else
ScanIdent(file,ch,val_rtrn)
    FILE *		file;
    int			ch;
    XkbCFScanResultPtr	val_rtrn;
#endif
{
register int	i;
char *		str;

    val_rtrn->str= str= _XkbCF_rtrn;
    for (i=0;(isalpha(ch)||isdigit(ch)||(ch=='_'));ch=getc(file)) {
	if (i<XKBCF_MAX_STR_LEN)
	    str[i++]= ch;
    }
    if ((ch!=EOF)&&(ch!=' ')&&(ch!='\t'))
	ungetc(ch,file);
    str[i]= '\0';
    return XkbCF_Ident;
}

static int
#if NeedFunctionPrototypes
ScanString(FILE *file,int quote,XkbCFScanResultPtr val_rtrn)
#else
ScanString(file,quote,val_rtrn)
    FILE *		file;
    int			quote;
    XkbCFScanResultPtr	val_rtrn;
#endif
{
int	ch,nInBuf;

    nInBuf = 0;
    while ( ((ch=getc(file))!=EOF) && (ch!='\n') && (ch!=quote) ) {
	if ( ch == '\\' ) {
	    if ((ch = getc(file))!=EOF) {
		if ( ch=='n' )		ch = '\n';
		else if ( ch == 't' )	ch = '\t';
		else if ( ch == 'v' )	ch = '\v';
		else if ( ch == 'b' )	ch = '\b';
		else if ( ch == 'r' )	ch = '\r';
		else if ( ch == 'f' )	ch = '\f';
		else if ( ch == 'e' )	ch = '\033';
		else if ( ch == '0' ) {
		    int tmp,stop;
		    ch = stop = 0;
		    if (((tmp=getc(file))!=EOF) && (isdigit(tmp)) && 
						(tmp!='8') && (tmp!='9')) {
			ch= (ch*8)+(tmp-'0');
		    }
		    else {
			stop= 1;
			ungetc(tmp,file);
		    }
		    if ((!stop) && ((tmp=getc(file))!=EOF) && (isdigit(tmp)) && 
						(tmp!='8') && (tmp!='9')) {
			ch= (ch*8)+(tmp-'0');
		    }
		    else {
			stop= 1;
			ungetc(tmp,file);
		    }
		    if ((!stop) && ((tmp=getc(file))!=EOF) && (isdigit(tmp)) && 
						(tmp!='8') && (tmp!='9')) {
			ch= (ch*8)+(tmp-'0');
		    }
		    else {
			stop= 1;
			ungetc(tmp,file);
		    }
		}
	    }
	    else return XkbCF_EOF;
	}

	if ( nInBuf < XKBCF_MAX_STR_LEN-1 ) 
	    _XkbCF_rtrn[nInBuf++] = ch;
    }
    if ( ch == quote ) {
	_XkbCF_rtrn[nInBuf++] = '\0';
	val_rtrn->str= _XkbCF_rtrn;
	return XkbCF_String;
    }
    return XkbCF_UnterminatedString;
}

static int
#if NeedFunctionPrototypes
ScanInteger(FILE *file,int ch,XkbCFScanResultPtr val_rtrn)
#else
ScanInteger(file,ch,val_rtrn)
    FILE *		file;
    int			ch;
    XkbCFScanResultPtr	val_rtrn;
#endif
{
int	i;

    if (isdigit(ch))
	ungetc(ch,file);
    if (fscanf(file,"%i",&i)==1) {
	val_rtrn->ival= i;
	return XkbCF_Integer;
    }
    return XkbCF_Unknown;
}

int 
#if NeedFunctionPrototypes
XkbCFScan(FILE *file,XkbCFScanResultPtr val_rtrn,XkbConfigRtrnPtr rtrn)
#else
XkbCFScan(file,val_rtrn,rtrn)
    FILE *		file;
    XkbCFScanResultPtr	val_rtrn;
    XkbConfigRtrnPtr	rtrn;
#endif
{
int	ch;

    do {
	ch= getc(file);
    } while ((ch=='\t')||(ch==' '));
    if (isalpha(ch))
	 return ScanIdent(file,ch,val_rtrn);
    else if (isdigit(ch))
	 return ScanInteger(file,ch,val_rtrn);
    else if (ch=='"')
	 return ScanString(file,ch,val_rtrn);
    else if (ch=='\n') {
	rtrn->line++;
	return XkbCF_EOL;
    }
    else if (ch==';')
	return XkbCF_Semi;
    else if (ch=='=')
	return XkbCF_Equals;
    else if (ch=='+') {
	ch= getc(file);
	if (ch=='=')
	    return XkbCF_PlusEquals;
	if ((ch!=EOF)&&(ch!=' ')&&(ch!='\t'))
	    ungetc(ch,file);
	return XkbCF_Plus;
    }
    else if (ch=='-') {
	ch= getc(file);
	if (ch=='=')
	    return XkbCF_MinusEquals;
	if ((ch!=EOF)&&(ch!=' ')&&(ch!='\t'))
	    ungetc(ch,file);
	return XkbCF_Minus;
    }
    else if (ch==EOF)
	return XkbCF_EOF;
    else if ((ch=='#')||((ch=='/')&&(getc(file)=='/'))) {
	while ((ch!='\n')&&(ch!=EOF))
	    ch= getc(file);
	rtrn->line++;
	return XkbCF_EOL;
    }
    return XkbCF_Unknown;
}

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

#define	_XkbCF_Illegal			0
#define	_XkbCF_Keymap		 	1
#define	_XkbCF_Keycodes		 	2
#define	_XkbCF_Geometry		 	3
#define	_XkbCF_PhysSymbols	 	4
#define _XkbCF_Symbols		 	5
#define	_XkbCF_Types		 	6
#define	_XkbCF_CompatMap	 	7

#define	_XkbCF_RulesFile		8
#define	_XkbCF_Model			9
#define	_XkbCF_Layout			10
#define	_XkbCF_Variant			11
#define	_XkbCF_Options			12
	
#define	_XkbCF_InitialMods	 	13
#define	_XkbCF_InitialCtrls	 	14

#define	_XkbCF_ClickVolume	 	15
#define	_XkbCF_BellVolume	 	16
#define	_XkbCF_BellPitch	 	17
#define	_XkbCF_BellDuration	 	18
#define	_XkbCF_RepeatDelay	 	19
#define	_XkbCF_RepeatInterval	 	20
#define	_XkbCF_SlowKeysDelay	 	21
#define	_XkbCF_DebounceDelay		22
#define	_XkbCF_MouseKeysDelay		23
#define	_XkbCF_MouseKeysInterval	24
#define	_XkbCF_MouseKeysTimeToMax	25
#define	_XkbCF_MouseKeysMaxSpeed	26
#define	_XkbCF_MouseKeysCurve		27
#define	_XkbCF_AccessXTimeout		28
#define	_XkbCF_AccessXTimeoutCtrlsOn	29
#define	_XkbCF_AccessXTimeoutCtrlsOff	30
#define	_XkbCF_AccessXTimeoutOptsOn	31
#define	_XkbCF_AccessXTimeoutOptsOff	32

#define	_XkbCF_IgnoreLockMods		33
#define	_XkbCF_IgnoreGroupLock		34
#define	_XkbCF_InternalMods		35

#define	_XkbCF_GroupsWrap		36
#define	_XkbCF_InitialFeedback		37

static Bool
#if NeedFunctionPrototypes
AddCtrlByName(XkbConfigRtrnPtr rtrn,char *name,unsigned long *ctrls_rtrn)
#else
AddCtrlByName(rtrn,name,ctrls_rtrn)
    XkbConfigRtrnPtr	rtrn;
    char *		name;
    unsigned long *	ctrls_rtrn;
#endif
{
    if ((_XkbStrCaseCmp(name,"repeat")==0)||
	(_XkbStrCaseCmp(name,"repeatkeys")==0))
	*ctrls_rtrn= XkbRepeatKeysMask;
    else if (_XkbStrCaseCmp(name,"slowkeys")==0)
	*ctrls_rtrn= XkbSlowKeysMask;
    else if (_XkbStrCaseCmp(name,"bouncekeys")==0)
	*ctrls_rtrn= XkbBounceKeysMask;
    else if (_XkbStrCaseCmp(name,"stickykeys")==0)
	*ctrls_rtrn= XkbStickyKeysMask;
    else if (_XkbStrCaseCmp(name,"mousekeys")==0)
	*ctrls_rtrn= XkbMouseKeysMask;
    else if (_XkbStrCaseCmp(name,"mousekeysaccel")==0)
	*ctrls_rtrn= XkbMouseKeysAccelMask;
    else if (_XkbStrCaseCmp(name,"accessxkeys")==0)
	*ctrls_rtrn= XkbAccessXKeysMask;
    else if (_XkbStrCaseCmp(name,"accessxtimeout")==0)
	*ctrls_rtrn= XkbAccessXTimeoutMask;
    else if (_XkbStrCaseCmp(name,"accessxfeedback")==0)
	*ctrls_rtrn= XkbAccessXFeedbackMask;
    else if (_XkbStrCaseCmp(name,"audiblebell")==0)
	*ctrls_rtrn= XkbAudibleBellMask;
    else if (_XkbStrCaseCmp(name,"overlay1")==0)
	*ctrls_rtrn= XkbOverlay1Mask;
    else if (_XkbStrCaseCmp(name,"overlay2")==0)
	*ctrls_rtrn= XkbOverlay2Mask;
    else if (_XkbStrCaseCmp(name,"ignoregrouplock")==0)
	*ctrls_rtrn= XkbIgnoreGroupLockMask;
    else {
	rtrn->error= XkbCF_ExpectedControl;
	return False;
    }
    return True;
}

static Bool
#if NeedFunctionPrototypes
AddAXTimeoutOptByName(	XkbConfigRtrnPtr	rtrn,
			char *			name,
			unsigned short *	opts_rtrn)
#else
AddAXTimeoutOptByName(rtrn,name,opts_rtrn)
    XkbConfigRtrnPtr	rtrn;
    char *		name;
    unsigned short *	opts_rtrn;
#endif
{
    if (_XkbStrCaseCmp(name,"slowkeyspress")==0)
	*opts_rtrn= XkbAX_SKPressFBMask;
    else if (_XkbStrCaseCmp(name,"slowkeysaccept")==0)
	*opts_rtrn= XkbAX_SKAcceptFBMask;
    else if (_XkbStrCaseCmp(name,"feature")==0)
	*opts_rtrn= XkbAX_FeatureFBMask;
    else if (_XkbStrCaseCmp(name,"slowwarn")==0)
	*opts_rtrn= XkbAX_SlowWarnFBMask;
    else if (_XkbStrCaseCmp(name,"indicator")==0)
	*opts_rtrn= XkbAX_IndicatorFBMask;
    else if (_XkbStrCaseCmp(name,"stickykeys")==0)
	*opts_rtrn= XkbAX_StickyKeysFBMask;
    else if (_XkbStrCaseCmp(name,"twokeys")==0)
	*opts_rtrn= XkbAX_TwoKeysMask;
    else if (_XkbStrCaseCmp(name,"latchtolock")==0)
	*opts_rtrn= XkbAX_LatchToLockMask;
    else if (_XkbStrCaseCmp(name,"slowkeysrelease")==0)
	*opts_rtrn= XkbAX_SKReleaseFBMask;
    else if (_XkbStrCaseCmp(name,"slowkeysreject")==0)
	*opts_rtrn= XkbAX_SKRejectFBMask;
    else if (_XkbStrCaseCmp(name,"bouncekeysreject")==0)
	*opts_rtrn= XkbAX_BKRejectFBMask;
    else if (_XkbStrCaseCmp(name,"dumbbell")==0)
	*opts_rtrn= XkbAX_DumbBellFBMask;
    else {
	rtrn->error= XkbCF_ExpectedControl;
	return False;
    }
    return True;
}

XkbConfigUnboundModPtr
#if NeedFunctionPrototypes
XkbCFAddModByName(	XkbConfigRtrnPtr	rtrn,
			int			what,
			char *			name,
			Bool			merge,
			XkbConfigUnboundModPtr	last)
#else
XkbCFAddModByName(rtrn,what,name,merge,last)
    XkbConfigRtrnPtr		rtrn;
    int				what;
    char *			name;
    Bool			merge;
    XkbConfigUnboundModPtr	last;
#endif
{
    if (rtrn->num_unbound_mods>=rtrn->sz_unbound_mods) {
	rtrn->sz_unbound_mods+= 5;
	rtrn->unbound_mods= _XkbTypedRealloc(rtrn->unbound_mods,
						  rtrn->sz_unbound_mods,
						  XkbConfigUnboundModRec);
	if (rtrn->unbound_mods==NULL) {
	    rtrn->error= XkbCF_BadAlloc;
	    return False;
	}
    }
    if (last==NULL) {
	last= &rtrn->unbound_mods[rtrn->num_unbound_mods++];
	last->what= what;
	last->mods= 0;
	last->vmods= 0;
	last->merge= merge;
	last->name= NULL;
    }
    if (_XkbStrCaseCmp(name,"shift")==0)
	last->mods|= ShiftMask;
    else if (_XkbStrCaseCmp(name,"lock")==0)
	last->mods|= LockMask;
    else if ((_XkbStrCaseCmp(name,"control")==0)||
		(_XkbStrCaseCmp(name,"ctrl")==0))
	last->mods|= ControlMask;
    else if (_XkbStrCaseCmp(name,"mod1")==0)
	last->mods|= Mod1Mask;
    else if (_XkbStrCaseCmp(name,"mod2")==0)
	last->mods|= Mod2Mask;
    else if (_XkbStrCaseCmp(name,"mod3")==0)
	last->mods|= Mod3Mask;
    else if (_XkbStrCaseCmp(name,"mod4")==0)
	last->mods|= Mod4Mask;
    else if (_XkbStrCaseCmp(name,"mod5")==0)
	last->mods|= Mod5Mask;
    else {
	if (last->name!=NULL) {
	    last= &rtrn->unbound_mods[rtrn->num_unbound_mods++];
	    last->what= what;
	    last->mods= 0;
	    last->vmods= 0;
	    last->merge= merge;
	    last->name= NULL;
	}
	last->name= _XkbDupString(name);
    }
    return last;
}

int
#if NeedFunctionPrototypes
XkbCFBindMods(XkbConfigRtrnPtr rtrn,XkbDescPtr xkb)
#else
XkbCFBindMods(rtrn,xkb)
    XkbConfigRtrnPtr	rtrn;
    XkbDescPtr		xkb;
#endif
{
register int 		n,v;
Atom			name;
XkbConfigUnboundModPtr	mod;
int			missing;

    if (rtrn->num_unbound_mods<1)
	return 0;
    if ((xkb==NULL) || (xkb->names==NULL))
	return -1;

    missing= 0;
    for (n=0,mod=rtrn->unbound_mods;n<rtrn->num_unbound_mods;n++,mod++) {
	if (mod->name!=NULL) {
	    name= XkbInternAtom(xkb->dpy,mod->name,True);
	    if (name==None)
		continue;
	    for (v=0;v<XkbNumVirtualMods;v++) {
		if (xkb->names->vmods[v]==name) {
		    mod->vmods= (1<<v);
		    _XkbFree(mod->name);
		    mod->name= NULL;
		    break;
		}
	    }
	    if (mod->name!=NULL)
		missing++;
	}
    }
    return missing;
}

Bool
#if NeedFunctionPrototypes
XkbCFApplyMods(XkbConfigRtrnPtr rtrn,int what,XkbConfigModInfoPtr info)
#else
XkbCFApplyMods(rtrn,what,info)
    XkbConfigRtrnPtr	rtrn;
    int			what;
    XkbConfigModInfoPtr	info;
#endif
{
register int 		n;
XkbConfigUnboundModPtr	mod;

    if (rtrn->num_unbound_mods<1)
	return True;

    for (n=0,mod=rtrn->unbound_mods;n<rtrn->num_unbound_mods;n++,mod++) {
	if (mod->what!=what)
	    continue;
 	if (mod->merge==XkbCF_MergeRemove) {
	    info->mods_clear|= mod->mods;
	    info->vmods_clear|= mod->vmods;
	}
	else {
	    if (mod->merge==XkbCF_MergeSet)
		info->replace= True;
	    info->mods|= mod->mods;
	    info->vmods|= mod->vmods;
	}
	if (mod->name==NULL) {
	    mod->what= _XkbCF_Illegal;
	}
	else {
	    mod->mods= 0;
	    mod->vmods= 0;
	}
    }
    return True;
}

/*ARGSUSED*/
static Bool
#if NeedFunctionPrototypes
DefaultParser(	FILE *			file,
		XkbConfigFieldsPtr	fields,
		XkbConfigFieldPtr	field,
		XkbDescPtr		xkb,
		XkbConfigRtrnPtr	rtrn)
#else
DefaultParser(file,fields,field,xkb,rtrn)
    FILE *		file;
    XkbConfigFieldsPtr	fields;
    XkbConfigFieldPtr	field;
    XkbDescPtr		xkb;
    XkbConfigRtrnPtr	rtrn;
#endif
{
int			tok;
XkbCFScanResultRec	val;
char **			str;
int			merge;
unsigned long *		ctrls, ctrls_mask;
unsigned short *	opts, opts_mask;
int *			pival, sign;
int			onoff;
XkbConfigUnboundModPtr	last;
unsigned		what;

    tok= XkbCFScan(file,&val,rtrn);
    str= NULL;
    onoff= 0;
    pival= NULL;
    switch (field->field_id) {
	case _XkbCF_RulesFile:	if (!str)	str= &rtrn->rules_file;
	case _XkbCF_Model:	if (!str)	str= &rtrn->model;
	case _XkbCF_Layout:	if (!str)	str= &rtrn->layout;
	case _XkbCF_Variant:	if (!str)	str= &rtrn->variant;
	case _XkbCF_Options:	if (!str)	str= &rtrn->options;
	case _XkbCF_Keymap: 	if (!str)	str= &rtrn->keymap;
	case _XkbCF_Keycodes: 	if (!str)	str= &rtrn->keycodes;
	case _XkbCF_Geometry: 	if (!str)	str= &rtrn->geometry;
	case _XkbCF_PhysSymbols:if (!str)	str= &rtrn->phys_symbols;
	case _XkbCF_Symbols: 	if (!str)	str= &rtrn->symbols;
	case _XkbCF_Types: 	if (!str)	str= &rtrn->types;
	case _XkbCF_CompatMap:	if (!str)	str= &rtrn->compat;
	    if (tok!=XkbCF_Equals) {
		rtrn->error= XkbCF_MissingEquals;
		goto BAILOUT;
	    }
	    tok= XkbCFScan(file,&val,rtrn);
	    if ((tok!=XkbCF_String)&&(tok!=XkbCF_Ident)) {
		rtrn->error= XkbCF_ExpectedString;
		return False;
	    }
	    tok= XkbCFScan(file,&val,rtrn);
	    if ((tok!=XkbCF_EOL)&&(tok!=XkbCF_Semi)&&(tok!=XkbCF_EOF)) {
		rtrn->error= XkbCF_ExpectedEOS;
		return False;
	    }
	    if (*str!=NULL)
		_XkbFree(*str);
	    *str= _XkbDupString(val.str);
	    break;
	case _XkbCF_InitialMods:
	case _XkbCF_IgnoreLockMods:
	case _XkbCF_InternalMods:
	    what= XkbCF_InitialMods;
	    if (field->field_id==_XkbCF_InitialMods)
		rtrn->defined|= (what=XkbCF_InitialMods);
	    else if (field->field_id==_XkbCF_InternalMods)
		rtrn->defined|= (what=XkbCF_InternalMods);
	    else if (field->field_id==_XkbCF_IgnoreLockMods)
		rtrn->defined|= (what=XkbCF_IgnoreLockMods);
	    if (tok==XkbCF_Equals)		merge= XkbCF_MergeSet;
	    else if (tok==XkbCF_MinusEquals)	merge= XkbCF_MergeRemove;
	    else if (tok==XkbCF_PlusEquals)	merge= XkbCF_MergeAdd;
	    else {
		rtrn->error= XkbCF_MissingEquals;
		goto BAILOUT;
	    }
	    tok= XkbCFScan(file,&val,rtrn);
	    if ((tok==XkbCF_EOL)||(tok==XkbCF_Semi)||(tok==XkbCF_EOF)) {
		rtrn->error= XkbCF_ExpectedModifier;
		return False;
	    }
	    last= NULL;
	    while ((tok!=XkbCF_EOL)&&(tok!=XkbCF_Semi)&&(tok!=XkbCF_EOF)) {
		if ((tok!=XkbCF_Ident)&&(tok!=XkbCF_String)) {
		    rtrn->error= XkbCF_ExpectedModifier;
		    return False;
		}
		last=XkbCFAddModByName(rtrn,what,val.str,merge,last);
		if (last==NULL)
		    return False;
		if (merge==XkbCF_MergeSet)
		    merge= XkbCF_MergeAdd;
		tok= XkbCFScan(file,&val,rtrn);
		if ((tok!=XkbCF_EOL)&&(tok!=XkbCF_EOF)&&(tok!=XkbCF_Semi)) {
		    if (tok!=XkbCF_Plus) {
			rtrn->error= XkbCF_ExpectedOperator;
			return False;
		    }
		    tok= XkbCFScan(file,&val,rtrn);
		}
	    }
	    break;
	case _XkbCF_InitialCtrls:
	    rtrn->defined|= XkbCF_InitialCtrls;
	    ctrls= NULL;
	    if (tok==XkbCF_PlusEquals)
		ctrls= &rtrn->initial_ctrls;
	    else if (tok==XkbCF_MinusEquals)
		ctrls= &rtrn->initial_ctrls_clear;
	    else if (tok==XkbCF_Equals) {
		ctrls= &rtrn->initial_ctrls;
		rtrn->replace_initial_ctrls= True;
		*ctrls= 0;
	    }
	    else {
		rtrn->error= XkbCF_MissingEquals;
		goto BAILOUT;
	    }
	    tok= XkbCFScan(file,&val,rtrn);
	    if ((tok==XkbCF_EOL)||(tok==XkbCF_Semi)||(tok==XkbCF_EOF)) {
		rtrn->error= XkbCF_ExpectedControl;
		return False;
	    }
	    while ((tok!=XkbCF_EOL)&&(tok!=XkbCF_Semi)&&(tok!=XkbCF_EOF)) {
		if ((tok!=XkbCF_Ident)&&(tok!=XkbCF_String)) {
		    rtrn->error= XkbCF_ExpectedControl;
		    return False;
		}
		if (!AddCtrlByName(rtrn,val.str,&ctrls_mask)) {
		    return False;
		}
		*ctrls |= ctrls_mask;
		tok= XkbCFScan(file,&val,rtrn);
		if ((tok!=XkbCF_EOL)&&(tok!=XkbCF_EOF)&&(tok!=XkbCF_Semi)) {
		    if (tok!=XkbCF_Plus) {
			rtrn->error= XkbCF_ExpectedOperator;
			return False;
		    }
		    tok= XkbCFScan(file,&val,rtrn);
		}
	    }
	    break;
	case _XkbCF_AccessXTimeoutCtrlsOn:
	case _XkbCF_AccessXTimeoutCtrlsOff:
	    opts= NULL;
	    if (tok==XkbCF_MinusEquals) {
		ctrls= &rtrn->axt_ctrls_ignore;
		opts= &rtrn->axt_opts_ignore;
	    }
	    else if ((tok==XkbCF_PlusEquals)||(tok==XkbCF_Equals)) {
		if (field->field_id==_XkbCF_AccessXTimeoutCtrlsOff) {
		    ctrls= &rtrn->axt_ctrls_off;
		    opts= &rtrn->axt_opts_off;
		    if (tok==XkbCF_Equals)
			rtrn->replace_axt_ctrls_off= True;
		}
		else {
		    ctrls= &rtrn->axt_ctrls_on;
		    opts= &rtrn->axt_opts_on;
		    if (tok==XkbCF_Equals)
			rtrn->replace_axt_ctrls_on= True;
		}
		*ctrls= 0;
	    }
	    else {
		rtrn->error= XkbCF_MissingEquals;
		goto BAILOUT;
	    }
	    tok= XkbCFScan(file,&val,rtrn);
	    if ((tok==XkbCF_EOL)||(tok==XkbCF_Semi)||(tok==XkbCF_EOF)) {
		rtrn->error= XkbCF_ExpectedControl;
		return False;
	    }
	    while ((tok!=XkbCF_EOL)&&(tok!=XkbCF_Semi)&&(tok!=XkbCF_EOF)) {
		if ((tok!=XkbCF_Ident)&&(tok!=XkbCF_String)) {
		    rtrn->error= XkbCF_ExpectedControl;
		    return False;
		}
		if (!AddCtrlByName(rtrn,val.str,&ctrls_mask)) {
		    if (!AddAXTimeoutOptByName(rtrn,val.str,&opts_mask))
			return False;
		    *opts |= opts_mask;
		    if (field->field_id==_XkbCF_AccessXTimeoutCtrlsOff) {
			rtrn->defined|= XkbCF_AccessXTimeoutOptsOff;
			if (rtrn->replace_axt_ctrls_off)
			    rtrn->replace_axt_opts_off= True;
		    }
		    else {
			rtrn->defined|= XkbCF_AccessXTimeoutOptsOn;
			if (rtrn->replace_axt_ctrls_on)
			    rtrn->replace_axt_opts_on= True;
		    }
		}
		else
		    *ctrls |= ctrls_mask;
		tok= XkbCFScan(file,&val,rtrn);
		if ((tok!=XkbCF_EOL)&&(tok!=XkbCF_EOF)&&(tok!=XkbCF_Semi)) {
		    if (tok!=XkbCF_Plus) {
			rtrn->error= XkbCF_ExpectedOperator;
			return False;
		    }
		    tok= XkbCFScan(file,&val,rtrn);
		}
	    }
	    break;
	case _XkbCF_InitialFeedback:
	    rtrn->defined|= XkbCF_InitialOpts;
	    opts= NULL;
	    if (tok==XkbCF_PlusEquals)
		opts= &rtrn->initial_opts;
	    else if (tok==XkbCF_MinusEquals)
		opts= &rtrn->initial_opts_clear;
	    else if (tok==XkbCF_Equals) {
		opts= &rtrn->initial_opts;
		rtrn->replace_initial_opts= True;
		*opts= 0;
	    }
	    else {
		rtrn->error= XkbCF_MissingEquals;
		goto BAILOUT;
	    }
	    tok= XkbCFScan(file,&val,rtrn);
	    if ((tok==XkbCF_EOL)||(tok==XkbCF_Semi)||(tok==XkbCF_EOF)) {
		rtrn->error= XkbCF_ExpectedAXOption;
		return False;
	    }
	    while ((tok!=XkbCF_EOL)&&(tok!=XkbCF_Semi)&&(tok!=XkbCF_EOF)) {
		if ((tok!=XkbCF_Ident)&&(tok!=XkbCF_String)) {
		    rtrn->error= XkbCF_ExpectedAXOption;
		    return False;
		}
		if (!AddAXTimeoutOptByName(rtrn,val.str,&opts_mask)) {
		    return False;
		}
		*opts |= opts_mask;
		tok= XkbCFScan(file,&val,rtrn);
		if ((tok!=XkbCF_EOL)&&(tok!=XkbCF_EOF)&&(tok!=XkbCF_Semi)) {
		    if (tok!=XkbCF_Plus) {
			rtrn->error= XkbCF_ExpectedOperator;
			return False;
		    }
		    tok= XkbCFScan(file,&val,rtrn);
		}
	    }
	    break;
	case _XkbCF_AccessXTimeoutOptsOff:
	case _XkbCF_AccessXTimeoutOptsOn:
	    opts= NULL;
	    if (tok==XkbCF_MinusEquals)
		opts= &rtrn->axt_opts_ignore;
	    else if ((tok==XkbCF_PlusEquals)||(tok==XkbCF_Equals)) {
		if (field->field_id==_XkbCF_AccessXTimeoutOptsOff) {
		    opts= &rtrn->axt_opts_off;
		    if (tok==XkbCF_Equals)
			rtrn->replace_axt_opts_off= True;
		}
		else {
		    opts= &rtrn->axt_opts_on;
		    if (tok==XkbCF_Equals)
			rtrn->replace_axt_opts_on= True;
		}
		*opts = 0;
	    }
	    else {
		rtrn->error= XkbCF_MissingEquals;
		goto BAILOUT;
	    }
	    tok= XkbCFScan(file,&val,rtrn);
	    if ((tok==XkbCF_EOL)||(tok==XkbCF_Semi)||(tok==XkbCF_EOF)) {
		rtrn->error= XkbCF_ExpectedControl;
		return False;
	    }
	    while ((tok!=XkbCF_EOL)&&(tok!=XkbCF_Semi)&&(tok!=XkbCF_EOF)) {
		if ((tok!=XkbCF_Ident)&&(tok!=XkbCF_String)) {
		    rtrn->error= XkbCF_ExpectedControl;
		    return False;
		}
		if (!AddAXTimeoutOptByName(rtrn,val.str,&opts_mask))
		    return False;
		*opts |= opts_mask;

		tok= XkbCFScan(file,&val,rtrn);
		if ((tok!=XkbCF_EOL)&&(tok!=XkbCF_EOF)&&(tok!=XkbCF_Semi)) {
		    if (tok!=XkbCF_Plus) {
			rtrn->error= XkbCF_ExpectedOperator;
			return False;
		    }
		    tok= XkbCFScan(file,&val,rtrn);
		}
	    }
	    break;
	case _XkbCF_ClickVolume:	
	    if (!pival) {
		pival= &rtrn->click_volume;
		onoff= 100;
	    }
	case _XkbCF_BellVolume:
	    if (!pival) {
		pival= &rtrn->bell_volume;
		onoff= 100;
	    }
	case _XkbCF_BellPitch:
	    if (!pival)
		pival= &rtrn->bell_pitch;
	case _XkbCF_BellDuration:
	    if (!pival)
		pival= &rtrn->bell_duration;
	case _XkbCF_RepeatDelay:
	    if (!pival)
		pival= &rtrn->repeat_delay;
	case _XkbCF_RepeatInterval:
	    if (!pival) 
		pival= &rtrn->repeat_interval;
	case _XkbCF_SlowKeysDelay:
	    if (!pival) 
		pival= &rtrn->slow_keys_delay;
	case _XkbCF_DebounceDelay:
	    if (!pival) 
		pival= &rtrn->debounce_delay;
	case _XkbCF_MouseKeysDelay:
	    if (!pival) 
		pival= &rtrn->mk_delay;
	case _XkbCF_MouseKeysInterval:
	    if (!pival) 
		pival= &rtrn->mk_interval;
	case _XkbCF_MouseKeysTimeToMax:
	    if (!pival) 
		pival= &rtrn->mk_time_to_max;
	case _XkbCF_MouseKeysMaxSpeed:
	    if (!pival) 
		pival= &rtrn->mk_max_speed;
	case _XkbCF_MouseKeysCurve:
	    if (!pival) 
		pival= &rtrn->mk_curve;
	case _XkbCF_AccessXTimeout:
	    if (!pival) 
		pival= &rtrn->ax_timeout;
	    if (tok!=XkbCF_Equals) {
		rtrn->error= XkbCF_MissingEquals;
		goto BAILOUT;
	    }
	    tok= XkbCFScan(file,&val,rtrn);
	    if (tok == XkbCF_Minus && field->field_id == _XkbCF_MouseKeysCurve) {
		/* This can be a negative value */
		tok = XkbCFScan(file,&val,rtrn);
		sign = -1;
	    }
	    else
		sign = 1;
	    if (tok!=XkbCF_Integer) {
		Bool ok= False;
		if ((onoff)&&(tok==XkbCF_Ident)&&(val.str!=NULL)) {
		    if (_XkbStrCaseCmp(val.str,"on")) {
			val.ival= onoff;
			ok= True;
		    }
		    else if (_XkbStrCaseCmp(val.str,"off")) {
			val.ival= 0;
			ok= True;
		    }
		}
		if (!ok) {
		    rtrn->error= XkbCF_ExpectedInteger;
		    goto BAILOUT;
		}
	    }
	    *pival= val.ival * sign;
	    if (field->field_id == _XkbCF_AccessXTimeout)
	        rtrn->defined|=XkbCF_AccessXTimeout;
	    tok= XkbCFScan(file,&val,rtrn);
	    if ((tok!=XkbCF_EOL)&&(tok!=XkbCF_Semi)&&(tok!=XkbCF_EOF)) {
		rtrn->error= XkbCF_ExpectedEOS;
		return False;
	    }
	    break;
	case _XkbCF_GroupsWrap:
	    if (tok!=XkbCF_Equals) {
		rtrn->error= XkbCF_MissingEquals;
		goto BAILOUT;
	    }
	    tok= XkbCFScan(file,&val,rtrn);
	    if (tok==XkbCF_Ident) {
		if (_XkbStrCaseCmp(val.str,"wrap")==0) {
		    rtrn->groups_wrap= XkbSetGroupInfo(0,XkbWrapIntoRange,0);
		}
		else if (_XkbStrCaseCmp(val.str,"clamp")==0) {
		    rtrn->groups_wrap= XkbSetGroupInfo(0,XkbClampIntoRange,0);
		}
		else {
		    rtrn->error= XkbCF_ExpectedOORGroupBehavior;
		    return False;
		}
	    }
	    else if ((tok==XkbCF_Integer)&&(XkbIsLegalGroup(val.ival-1))) {
		rtrn->groups_wrap= XkbSetGroupInfo(0,XkbRedirectIntoRange,
								val.ival-1);
	    }
	    else {
		rtrn->error= XkbCF_ExpectedOORGroupBehavior;
		return False;
	    }
	    rtrn->defined|= XkbCF_GroupsWrap;
	    tok= XkbCFScan(file,&val,rtrn);
	    if ((tok!=XkbCF_EOL)&&(tok!=XkbCF_Semi)&&(tok!=XkbCF_EOF)) {
		rtrn->error= XkbCF_ExpectedEOS;
		return False;
	    }
	    break;
	default:
	    rtrn->error= XkbCF_ExpectedInteger;
	    goto BAILOUT;
	    
    }
    return True;
BAILOUT:
    return False;
}

static Bool
#if NeedFunctionPrototypes
DefaultCleanUp(XkbConfigRtrnPtr rtrn)
#else
DefaultCleanUp(rtrn)
    XkbConfigRtrnPtr	rtrn;
#endif
{
    if (rtrn->keymap)	_XkbFree(rtrn->keymap);
    if (rtrn->keycodes)	_XkbFree(rtrn->keycodes);
    if (rtrn->geometry)	_XkbFree(rtrn->geometry);
    if (rtrn->phys_symbols)	_XkbFree(rtrn->phys_symbols);
    if (rtrn->symbols)	_XkbFree(rtrn->symbols);
    if (rtrn->types)	_XkbFree(rtrn->types);
    if (rtrn->compat)	_XkbFree(rtrn->compat);
    rtrn->keycodes= rtrn->geometry= NULL;
    rtrn->symbols= rtrn->phys_symbols= NULL;
    rtrn->types= rtrn->compat= NULL;
    if ((rtrn->unbound_mods!=NULL)&&(rtrn->num_unbound_mods>0)) {
	register int i;
	for (i=0;i<rtrn->num_unbound_mods;i++) {
	    if (rtrn->unbound_mods[i].name!=NULL) {
		_XkbFree(rtrn->unbound_mods[i].name);
		rtrn->unbound_mods[i].name= NULL;
	    }
	}
	_XkbFree(rtrn->unbound_mods);
	rtrn->sz_unbound_mods= 0;
	rtrn->num_unbound_mods= 0;
	rtrn->unbound_mods= NULL;
    }
    return True;
}

static Bool
#if NeedFunctionPrototypes
DefaultApplyNames(XkbConfigRtrnPtr rtrn,XkbDescPtr xkb)
#else
DefaultApplyNames(rtrn,xkb)
    XkbConfigRtrnPtr	rtrn;
    XkbDescPtr		xkb;
#endif
{
char *str;

    if (XkbAllocNames(xkb,XkbComponentNamesMask,0,0)!=Success)
	return False;
    if ((str=rtrn->keycodes)!=NULL) {
	xkb->names->keycodes= XkbInternAtom(xkb->dpy,str,False);
	_XkbFree(str);
	rtrn->keycodes= NULL;
    }
    if ((str=rtrn->geometry)!=NULL) {
	xkb->names->geometry= XkbInternAtom(xkb->dpy,str,False);
	_XkbFree(str);
	rtrn->geometry= NULL;
    }
    if ((str=rtrn->symbols)!=NULL) {
	xkb->names->symbols= XkbInternAtom(xkb->dpy,str,False);
	_XkbFree(str);
	rtrn->symbols= NULL;
    }
    if ((str=rtrn->phys_symbols)!=NULL) {
	xkb->names->phys_symbols= XkbInternAtom(xkb->dpy,str,False);
	_XkbFree(str);
	rtrn->phys_symbols= NULL;
    }
    if ((str=rtrn->types)!=NULL) {
	xkb->names->types= XkbInternAtom(xkb->dpy,str,False);
	_XkbFree(str);
	rtrn->types= NULL;
    }
    if ((str=rtrn->compat)!=NULL) {
	xkb->names->compat= XkbInternAtom(xkb->dpy,str,False);
	_XkbFree(str);
	rtrn->compat= NULL;
    }
    return True;
}

static Bool
#if NeedFunctionPrototypes
DefaultApplyControls(XkbConfigRtrnPtr rtrn,XkbDescPtr xkb)
#else
DefaultApplyControls(rtrn,xkb)
    XkbConfigRtrnPtr	rtrn;
    XkbDescPtr		xkb;
#endif
{
unsigned	on,off;
XkbControlsPtr	ctrls;
unsigned int	mask;

    if (XkbAllocControls(xkb,XkbAllControlsMask)!=Success)
	return False;
    ctrls= xkb->ctrls;
    if (rtrn->replace_initial_ctrls)
	 ctrls->enabled_ctrls=  rtrn->initial_ctrls;
    else ctrls->enabled_ctrls|= rtrn->initial_ctrls;
    ctrls->enabled_ctrls&= ~rtrn->initial_ctrls_clear;
    if (rtrn->internal_mods.replace) {
	ctrls->internal.real_mods= rtrn->internal_mods.mods;
	ctrls->internal.vmods= rtrn->internal_mods.vmods;
    }
    else {
	ctrls->internal.real_mods&= ~rtrn->internal_mods.mods_clear;
	ctrls->internal.vmods&= ~rtrn->internal_mods.vmods_clear;
	ctrls->internal.real_mods|= rtrn->internal_mods.mods;
	ctrls->internal.vmods|= rtrn->internal_mods.vmods;
    }
    mask= 0;
    (void)XkbVirtualModsToReal(xkb,ctrls->internal.vmods,&mask);
    ctrls->internal.mask= (ctrls->internal.real_mods|mask);

    if (rtrn->ignore_lock_mods.replace) {
	ctrls->ignore_lock.real_mods= rtrn->ignore_lock_mods.mods;
	ctrls->ignore_lock.vmods= rtrn->ignore_lock_mods.vmods;
    }
    else {
	ctrls->ignore_lock.real_mods&= ~rtrn->ignore_lock_mods.mods_clear;
	ctrls->ignore_lock.vmods&= ~rtrn->ignore_lock_mods.vmods_clear;
	ctrls->ignore_lock.real_mods|= rtrn->ignore_lock_mods.mods;
	ctrls->ignore_lock.vmods|= rtrn->ignore_lock_mods.vmods;
    }
    mask= 0;
    (void)XkbVirtualModsToReal(xkb,ctrls->ignore_lock.vmods,&mask);
    ctrls->ignore_lock.mask= (ctrls->ignore_lock.real_mods|mask);

    if (rtrn->repeat_delay>0)
	ctrls->repeat_delay= rtrn->repeat_delay;
    if (rtrn->repeat_interval>0)
	ctrls->repeat_interval= rtrn->repeat_interval;
    if (rtrn->slow_keys_delay>0)
	ctrls->slow_keys_delay= rtrn->slow_keys_delay;
    if (rtrn->debounce_delay>0)
	ctrls->debounce_delay= rtrn->debounce_delay;
    if (rtrn->mk_delay>0)
	ctrls->mk_delay= rtrn->mk_delay;
    if (rtrn->mk_interval>0)
	ctrls->mk_interval= rtrn->mk_interval;
    if (rtrn->mk_time_to_max>0)
	ctrls->mk_time_to_max= rtrn->mk_time_to_max;
    if (rtrn->mk_max_speed>0)
	ctrls->mk_max_speed= rtrn->mk_max_speed;
    if (rtrn->mk_curve>0)
	ctrls->mk_curve= rtrn->mk_curve;
    if (rtrn->defined&XkbCF_AccessXTimeout && rtrn->ax_timeout > 0)
	ctrls->ax_timeout= rtrn->ax_timeout;

    /* any value set to both off and on is reset to ignore */
    if ((off=(rtrn->axt_ctrls_on&rtrn->axt_ctrls_off))!=0)
	rtrn->axt_ctrls_ignore|= off;

    /* ignore takes priority over on and off */
    rtrn->axt_ctrls_on&= ~rtrn->axt_ctrls_ignore;
    rtrn->axt_ctrls_off&= ~rtrn->axt_ctrls_ignore;

    if (!rtrn->replace_axt_ctrls_off) {
	 off= (ctrls->axt_ctrls_mask&(~ctrls->axt_ctrls_values));
	 off&= ~rtrn->axt_ctrls_on;
	 off|= rtrn->axt_ctrls_off;
    }
    else off= rtrn->axt_ctrls_off;
    if (!rtrn->replace_axt_ctrls_on) {
	 on= (ctrls->axt_ctrls_mask&ctrls->axt_ctrls_values);
	 on&= ~rtrn->axt_ctrls_off;
	 on|= rtrn->axt_ctrls_on;
    }
    else on= rtrn->axt_ctrls_on;
    ctrls->axt_ctrls_mask= (on|off)&~rtrn->axt_ctrls_ignore;
    ctrls->axt_ctrls_values= on&~rtrn->axt_ctrls_ignore;

    /* any value set to both off and on is reset to ignore */
    if ((off=(rtrn->axt_opts_on&rtrn->axt_opts_off))!=0)
	rtrn->axt_opts_ignore|= off;

    /* ignore takes priority over on and off */
    rtrn->axt_opts_on&= ~rtrn->axt_opts_ignore;
    rtrn->axt_opts_off&= ~rtrn->axt_opts_ignore;

    if (rtrn->replace_axt_opts_off) {
	 off= (ctrls->axt_opts_mask&(~ctrls->axt_opts_values));
	 off&= ~rtrn->axt_opts_on;
	 off|= rtrn->axt_opts_off;
    }
    else off= rtrn->axt_opts_off;
    if (!rtrn->replace_axt_opts_on) {
	 on= (ctrls->axt_opts_mask&ctrls->axt_opts_values);
	 on&= ~rtrn->axt_opts_off;
	 on|= rtrn->axt_opts_on;
    }
    else on= rtrn->axt_opts_on;
    ctrls->axt_opts_mask= (unsigned short)((on|off)&~rtrn->axt_ctrls_ignore);
    ctrls->axt_opts_values= (unsigned short)(on&~rtrn->axt_ctrls_ignore);

    if (rtrn->defined&XkbCF_GroupsWrap) {
	int n;
	n= XkbNumGroups(ctrls->groups_wrap);
	rtrn->groups_wrap= XkbSetNumGroups(rtrn->groups_wrap,n);
	ctrls->groups_wrap= rtrn->groups_wrap;
    }
    return True;
}

/*ARGSUSED*/
static Bool
#if NeedFunctionPrototypes
DefaultFinish(	XkbConfigFieldsPtr	fields,
		XkbDescPtr		xkb,
		XkbConfigRtrnPtr	rtrn,
		int			what)
#else
DefaultFinish(fields,xkb,rtrn,what)
    XkbConfigFieldsPtr	fields;
    XkbDescPtr		xkb;
    XkbConfigRtrnPtr	rtrn;
    int			what;
#endif
{
    if ((what==XkbCF_Destroy)||(what==XkbCF_CleanUp))
	return DefaultCleanUp(rtrn);
    if (what==XkbCF_Check) {
	if ((rtrn->symbols==NULL)&&(rtrn->phys_symbols!=NULL))
	    rtrn->symbols= _XkbDupString(rtrn->phys_symbols);
    }
    if ((what==XkbCF_Apply)||(what==XkbCF_Check)) {
	if (xkb && xkb->names && (rtrn->num_unbound_mods>0))
	    XkbCFBindMods(rtrn,xkb);
	XkbCFApplyMods(rtrn,XkbCF_InitialMods,&rtrn->initial_mods);
	XkbCFApplyMods(rtrn,XkbCF_InternalMods,&rtrn->internal_mods);
	XkbCFApplyMods(rtrn,XkbCF_IgnoreLockMods,&rtrn->ignore_lock_mods);
    }
    if (what==XkbCF_Apply) {
	if (xkb!=NULL) {
	    DefaultApplyNames(rtrn,xkb);
	    DefaultApplyControls(rtrn,xkb);
	    XkbCFBindMods(rtrn,xkb);
	}
    }
    return True;
}

static XkbConfigFieldRec _XkbCFDfltFields[] = {
	{ "rules",	_XkbCF_RulesFile },
	{ "model",	_XkbCF_Model },
	{ "layout",	_XkbCF_Layout },
	{ "variant",	_XkbCF_Variant },
	{ "options",	_XkbCF_Options },
	{ "keymap",	_XkbCF_Keymap },
	{ "keycodes",	_XkbCF_Keycodes },
	{ "geometry",	_XkbCF_Geometry },
	{ "realsymbols",_XkbCF_PhysSymbols },
	{ "actualsymbols",_XkbCF_PhysSymbols },
	{ "symbols",	_XkbCF_Symbols },
	{ "symbolstouse",_XkbCF_Symbols },
	{ "types",	_XkbCF_Types },
	{ "compat",	_XkbCF_CompatMap },
	{ "modifiers",	_XkbCF_InitialMods },
	{ "controls",	_XkbCF_InitialCtrls },
	{ "click",	_XkbCF_ClickVolume },
	{ "clickvolume",_XkbCF_ClickVolume },
	{ "bell",	_XkbCF_BellVolume },
	{ "bellvolume",	_XkbCF_BellVolume },
	{ "bellpitch",	_XkbCF_BellPitch },
	{ "bellduration",_XkbCF_BellDuration },
	{ "repeatdelay",_XkbCF_RepeatDelay },
	{ "repeatinterval",_XkbCF_RepeatInterval },
	{ "slowkeysdelay",_XkbCF_SlowKeysDelay	},
	{ "debouncedelay",_XkbCF_DebounceDelay },
	{ "mousekeysdelay",_XkbCF_MouseKeysDelay },
	{ "mousekeysinterval",_XkbCF_MouseKeysInterval },
	{ "mousekeystimetomax",_XkbCF_MouseKeysTimeToMax },
	{ "mousekeysmaxspeed",_XkbCF_MouseKeysMaxSpeed },
	{ "mousekeyscurve",_XkbCF_MouseKeysCurve },
	{ "accessxtimeout",_XkbCF_AccessXTimeout },
	{ "axtimeout",_XkbCF_AccessXTimeout },
	{ "accessxtimeoutctrlson",_XkbCF_AccessXTimeoutCtrlsOn },
	{ "axtctrlson",	_XkbCF_AccessXTimeoutCtrlsOn },
	{ "accessxtimeoutctrlsoff",_XkbCF_AccessXTimeoutCtrlsOff },
	{ "axtctrlsoff",_XkbCF_AccessXTimeoutCtrlsOff },
	{ "accessxtimeoutfeedbackon", _XkbCF_AccessXTimeoutOptsOn },
	{ "axtfeedbackon", _XkbCF_AccessXTimeoutOptsOn },
	{ "accessxtimeoutfeedbackoff", _XkbCF_AccessXTimeoutOptsOff },
	{ "axtfeedbackoff", _XkbCF_AccessXTimeoutOptsOff },
	{ "ignorelockmods",_XkbCF_IgnoreLockMods },
	{ "ignorelockmodifiers",_XkbCF_IgnoreLockMods },
	{ "ignoregrouplock",_XkbCF_IgnoreGroupLock },
	{ "internalmods",_XkbCF_InternalMods },
	{ "internalmodifiers",_XkbCF_InternalMods },
	{ "outofrangegroups",_XkbCF_GroupsWrap },
	{ "groups", _XkbCF_GroupsWrap },
	{ "feedback", _XkbCF_InitialFeedback },
};
#define	_XkbCFNumDfltFields (sizeof(_XkbCFDfltFields)/sizeof(XkbConfigFieldRec))

static XkbConfigFieldsRec _XkbCFDflts = {
	0,			/* cfg_id */
	_XkbCFNumDfltFields,	/* num_fields */
	_XkbCFDfltFields,	/* fields */
	DefaultParser,	/* parser */
	DefaultFinish,	/* finish */
	NULL,			/* priv */
	NULL			/* next */
};

XkbConfigFieldsPtr	XkbCFDflts= &_XkbCFDflts;

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

XkbConfigFieldsPtr
#if NeedFunctionPrototypes
XkbCFDup(XkbConfigFieldsPtr fields)
#else
XkbCFDup(fields)
    XkbConfigFieldsPtr	fields;
#endif
{
XkbConfigFieldsPtr	pNew;

    pNew= _XkbTypedAlloc(XkbConfigFieldsRec);
    if (pNew!=NULL) {
	memcpy(pNew,fields,sizeof(XkbConfigFieldsRec));
	if ((pNew->fields!=NULL)&&(pNew->num_fields>0)) {
	    pNew->fields= _XkbTypedCalloc(pNew->num_fields,XkbConfigFieldRec);
	    if (pNew->fields) {
		memcpy(fields->fields,pNew->fields,
				(pNew->num_fields*sizeof(XkbConfigFieldRec)));
	    }
	    else {
		_XkbFree(pNew);
		return NULL;
	    }
	}
	else {
	    pNew->num_fields= 0;
	    pNew->fields= NULL;
	}
	pNew->next= NULL;
    }
    return pNew;
}

XkbConfigFieldsPtr 
#if NeedFunctionPrototypes
XkbCFFree(XkbConfigFieldsPtr fields,Bool all)
#else
XkbCFFree(fields,all)
    XkbConfigFieldsPtr	fields;
    Bool		all;
#endif
{
XkbConfigFieldsPtr	next;

    next= NULL;
    while (fields!=NULL) {
	next= fields->next;
	if (fields!=XkbCFDflts) {
	    if (fields->fields) {
		_XkbFree(fields->fields);
		fields->fields= NULL;
		fields->num_fields= 0;
	    }
	    _XkbFree(fields);
	}
	fields= (all?next:NULL);
    }
    return next;
}

Bool
#if NeedFunctionPrototypes
XkbCFApplyRtrnValues(	XkbConfigRtrnPtr	rtrn,
			XkbConfigFieldsPtr	fields,
			XkbDescPtr		xkb)
#else
XkbCFApplyRtrnValues(rtrn,fields,xkb)
    XkbConfigRtrnPtr	rtrn;
    XkbConfigFieldsPtr	fields;
    XkbDescPtr		xkb;
#endif
{
Bool			ok;

    if ((fields==NULL)||(rtrn==NULL)||(xkb==NULL))
	return False;
    for (ok=True;fields!=NULL;fields=fields->next) {
	if (fields->finish!=NULL)
	    ok= (*fields->finish)(fields,xkb,rtrn,XkbCF_Apply)&&ok;
    }
    return ok;
}

XkbConfigRtrnPrivPtr
#if NeedFunctionPrototypes
XkbCFAddPrivate(	XkbConfigRtrnPtr	rtrn,
			XkbConfigFieldsPtr	fields,
			XPointer		ptr)
#else
XkbCFAddPrivate(rtrn,fields,ptr)
    XkbConfigRtrnPtr	rtrn;
    XkbConfigFieldsPtr	fields;
    XPointer		ptr;
#endif
{
XkbConfigRtrnPrivPtr	priv;

    if ((rtrn==NULL)||(fields==NULL))
	return NULL;
    priv= _XkbTypedAlloc(XkbConfigRtrnPrivRec);
    if (priv!=NULL) {
	priv->cfg_id= 	fields->cfg_id;
	priv->priv=	ptr;
	priv->next= 	rtrn->priv;
	rtrn->priv=	priv;
    }
    return priv;
}

void
#if NeedFunctionPrototypes
XkbCFFreeRtrn(	XkbConfigRtrnPtr	rtrn,
		XkbConfigFieldsPtr	fields,
		XkbDescPtr		xkb)
#else
XkbCFFreeRtrn(rtrn,fields,xkb)
    XkbConfigRtrnPtr	rtrn;
    XkbConfigFieldsPtr	fields;
    XkbDescPtr		xkb;
#endif
{
XkbConfigRtrnPrivPtr	tmp,next;

    if ((fields==NULL)||(rtrn==NULL))
	return;
    while (fields!=NULL) {
	if (fields->finish!=NULL)
	    (*fields->finish)(fields,xkb,rtrn,XkbCF_Destroy);
	fields= fields->next;
    }
    for (tmp=rtrn->priv;tmp!=NULL;tmp=next) {
	next= tmp->next;
	bzero((char *)tmp,sizeof(XkbConfigRtrnPrivRec));
	_XkbFree(tmp);
    }
    bzero((char *)rtrn,sizeof(XkbConfigRtrnRec));
    return;
}

Bool
#if NeedFunctionPrototypes
XkbCFParse(	FILE *			file,
		XkbConfigFieldsPtr	fields,
		XkbDescPtr		xkb,
		XkbConfigRtrnPtr	rtrn)
#else
XkbCFParse(file,fields,xkb,rtrn)
    FILE *		file;
    XkbConfigFieldsPtr	fields;
    XkbDescPtr		xkb;
    XkbConfigRtrnPtr	rtrn;
#endif
{
int			tok;
XkbCFScanResultRec	val;
XkbConfigFieldsPtr	tmp;

    if ((file==NULL)||(fields==NULL)||(rtrn==NULL))
	return False;
    for (tok=0,tmp=fields;tmp!=NULL;tmp=tmp->next,tok++) {
	fields->cfg_id= tok;
    }
    bzero((char *)rtrn,sizeof(XkbConfigRtrnRec));
    rtrn->line= 1;
    rtrn->click_volume= -1;
    rtrn->bell_volume= -1;
    while ((tok=XkbCFScan(file,&val,rtrn))!=XkbCF_EOF) {
	if (tok==XkbCF_Ident) {
	    Bool		done;
	    for (tmp=fields,done=False;(tmp!=NULL)&&(!done);tmp=tmp->next) {
		register int 		i;
		XkbConfigFieldPtr	f;

		for (i=0,f=tmp->fields;(i<tmp->num_fields)&&(!done);i++,f++) {
		    if (_XkbStrCaseCmp(val.str,f->field)!=0)
			continue;
		    if ((*tmp->parser)(file,tmp,f,xkb,rtrn))
			 done= True;
		    else goto BAILOUT;
		}
	    }
	}
	else if ((tok!=XkbCF_EOL)&&(tok!=XkbCF_Semi)) {
	    rtrn->error= XkbCF_MissingIdent;
	    goto BAILOUT;
	}
    }
    for (tmp=fields;tmp!=NULL;tmp=tmp->next) {
	if ((tmp->finish)&&(!(*tmp->finish)(tmp,xkb,rtrn,XkbCF_Check)))
	    goto BAILOUT;
    }
    return True;
BAILOUT:
    for (tmp=fields;tmp!=NULL;tmp=tmp->next) {
	if (tmp->finish)
	    (*tmp->finish)(tmp,xkb,rtrn,XkbCF_CleanUp);
    }
    return False;
}

/*ARGSUSED*/
void
#if NeedFunctionPrototypes
XkbCFReportError(FILE *file,char *name,int error,int line)
#else
XkbCFReportError(file,name,error,line)
    FILE *	file;
    char *	name;
    int		error;
    int		line;
#endif
{
char *	msg;

    switch(error) {
	case XkbCF_BadAlloc:
	    msg= "allocation failed\n"; break;
	case XkbCF_UnterminatedString:
	    msg= "unterminated string on line %d"; break;
	case XkbCF_MissingIdent:
	    msg= "expected identifier on line %d"; break;
	case XkbCF_MissingEquals:
	    msg= "expected '=' on line %d"; break;
	case XkbCF_ExpectedEOS:
	    msg= "expected ';' or newline on line %d"; break;
	case XkbCF_ExpectedBoolean:
	    msg= "expected a boolean value on line %d"; break;
	case XkbCF_ExpectedInteger:
	    msg= "expected a numeric value on line %d"; break;
	case XkbCF_ExpectedString:
	    msg= "expected a string on line %d"; break;
	case XkbCF_ExpectedModifier:
	    msg= "expected a modifier name on line %d"; break;
	case XkbCF_ExpectedControl:
	    msg= "expected a control name on line %d"; break;
	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;
}