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
|
/* $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
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/XKBGAlloc.c,v 3.4 2001/01/17 19:41:48 dawes Exp $ */
#define NEED_EVENTS
#define NEED_REPLIES
#ifndef XKB_IN_SERVER
#include <stdio.h>
#include "Xlibint.h"
#include "XKBlibint.h"
#include <X11/extensions/XKBgeom.h>
#include <X11/extensions/XKBproto.h>
#else
#include <stdio.h>
#include "X.h"
#include "Xproto.h"
#include "misc.h"
#include "inputstr.h"
#include "XKBsrv.h"
#include "XKBgeom.h"
#endif /* XKB_IN_SERVER */
#ifdef X_NOT_POSIX
#define Size_t unsigned int
#else
#define Size_t size_t
#endif
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_XkbFreeGeomLeafElems( Bool freeAll,
int first,
int count,
unsigned short * num_inout,
unsigned short * sz_inout,
char ** elems,
unsigned int elem_sz)
#else
_XkbFreeGeomLeafElems(freeAll,first,count,num_inout,sz_inout,elems,elem_sz)
Bool freeAll;
int first;
int count;
unsigned short * num_inout;
unsigned short * sz_inout;
char ** elems;
unsigned int elem_sz;
#endif
{
if ((freeAll)||(*elems==NULL)) {
*num_inout= *sz_inout= 0;
if (*elems!=NULL) {
_XkbFree(*elems);
*elems= NULL;
}
return;
}
if ((first>=(*num_inout))||(first<0)||(count<1))
return;
if (first+count>=(*num_inout)) {
/* truncating the array is easy */
(*num_inout)= first;
}
else {
char * ptr;
int extra;
ptr= *elems;
extra= ((*num_inout)-(first+count))*elem_sz;
if (extra>0)
memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],extra);
(*num_inout)-= count;
}
return;
}
typedef void (*ContentsClearFunc)(
#if NeedFunctionPrototypes
char * /* priv */
#endif
);
static void
#if NeedFunctionPrototypes
_XkbFreeGeomNonLeafElems( Bool freeAll,
int first,
int count,
unsigned short * num_inout,
unsigned short * sz_inout,
char ** elems,
unsigned int elem_sz,
ContentsClearFunc freeFunc)
#else
_XkbFreeGeomNonLeafElems(freeAll,first,count,num_inout,sz_inout,elems,elem_sz,
freeFunc)
Bool freeAll;
int first;
int count;
unsigned short * num_inout;
unsigned short * sz_inout;
char ** elems;
unsigned int elem_sz;
ContentsClearFunc freeFunc;
#endif
{
register int i;
register char *ptr;
if (freeAll) {
first= 0;
count= (*num_inout);
}
else if ((first>=(*num_inout))||(first<0)||(count<1))
return;
else if (first+count>(*num_inout))
count= (*num_inout)-first;
if (*elems==NULL)
return;
if (freeFunc) {
ptr= *elems;
ptr+= first*elem_sz;
for (i=0;i<count;i++) {
(*freeFunc)(ptr);
ptr+= elem_sz;
}
}
if (freeAll) {
(*num_inout)= (*sz_inout)= 0;
if (*elems) {
_XkbFree(*elems);
*elems= NULL;
}
}
else if (first+count>=(*num_inout))
*num_inout= first;
else {
i= ((*num_inout)-(first+count))*elem_sz;
ptr= *elems;
memmove(&ptr[first*elem_sz],&ptr[(first+count)*elem_sz],i);
(*num_inout)-= count;
}
return;
}
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_XkbClearProperty(char *prop_in)
#else
_XkbClearProperty(prop_in)
char * prop_in;
#endif
{
XkbPropertyPtr prop= (XkbPropertyPtr)prop_in;
if (prop->name) {
_XkbFree(prop->name);
prop->name= NULL;
}
if (prop->value) {
_XkbFree(prop->value);
prop->value= NULL;
}
return;
}
void
#if NeedFunctionPrototypes
XkbFreeGeomProperties( XkbGeometryPtr geom,
int first,
int count,
Bool freeAll)
#else
XkbFreeGeomProperties(geom,first,count,freeAll)
XkbGeometryPtr geom;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomNonLeafElems(freeAll,first,count,
&geom->num_properties,&geom->sz_properties,
(char **)&geom->properties,
sizeof(XkbPropertyRec),_XkbClearProperty);
return;
}
/***====================================================================***/
void
#if NeedFunctionPrototypes
XkbFreeGeomKeyAliases( XkbGeometryPtr geom,
int first,
int count,
Bool freeAll)
#else
XkbFreeGeomKeyAliases(geom,first,count,freeAll)
XkbGeometryPtr geom;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomLeafElems(freeAll,first,count,
&geom->num_key_aliases,&geom->sz_key_aliases,
(char **)&geom->key_aliases,
sizeof(XkbKeyAliasRec));
return;
}
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_XkbClearColor(char *color_in)
#else
_XkbClearColor(color_in)
char * color_in;
#endif
{
XkbColorPtr color= (XkbColorPtr)color_in;
if (color->spec)
_XkbFree(color->spec);
return;
}
void
#if NeedFunctionPrototypes
XkbFreeGeomColors(XkbGeometryPtr geom,int first,int count,Bool freeAll)
#else
XkbFreeGeomColors(geom,first,count,freeAll)
XkbGeometryPtr geom;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomNonLeafElems(freeAll,first,count,
&geom->num_colors,&geom->sz_colors,
(char **)&geom->colors,
sizeof(XkbColorRec),_XkbClearColor);
return;
}
/***====================================================================***/
void
#if NeedFunctionPrototypes
XkbFreeGeomPoints(XkbOutlinePtr outline,int first,int count,Bool freeAll)
#else
XkbFreeGeomPoints(outline,first,count,freeAll)
XkbOutlinePtr outline;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomLeafElems(freeAll,first,count,
&outline->num_points,&outline->sz_points,
(char **)&outline->points,
sizeof(XkbPointRec));
return;
}
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_XkbClearOutline(char *outline_in)
#else
_XkbClearOutline(outline_in)
char * outline_in;
#endif
{
XkbOutlinePtr outline= (XkbOutlinePtr)outline_in;
if (outline->points!=NULL)
XkbFreeGeomPoints(outline,0,outline->num_points,True);
return;
}
void
#if NeedFunctionPrototypes
XkbFreeGeomOutlines(XkbShapePtr shape,int first,int count,Bool freeAll)
#else
XkbFreeGeomOutlines(shape,first,count,freeAll)
XkbShapePtr shape;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomNonLeafElems(freeAll,first,count,
&shape->num_outlines,&shape->sz_outlines,
(char **)&shape->outlines,
sizeof(XkbOutlineRec),_XkbClearOutline);
return;
}
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_XkbClearShape(char *shape_in)
#else
_XkbClearShape(shape_in)
char * shape_in;
#endif
{
XkbShapePtr shape= (XkbShapePtr)shape_in;
if (shape->outlines)
XkbFreeGeomOutlines(shape,0,shape->num_outlines,True);
return;
}
void
#if NeedFunctionPrototypes
XkbFreeGeomShapes(XkbGeometryPtr geom,int first,int count,Bool freeAll)
#else
XkbFreeGeomShapes(geom,first,count,freeAll)
XkbGeometryPtr geom;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomNonLeafElems(freeAll,first,count,
&geom->num_shapes,&geom->sz_shapes,
(char **)&geom->shapes,
sizeof(XkbShapeRec),_XkbClearShape);
return;
}
/***====================================================================***/
void
#if NeedFunctionPrototypes
XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row,int first,int count,Bool freeAll)
#else
XkbFreeGeomOverlayKeys(row,first,count,freeAll)
XkbOverlayRowPtr row;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomLeafElems(freeAll,first,count,
&row->num_keys,&row->sz_keys,
(char **)&row->keys,
sizeof(XkbOverlayKeyRec));
return;
}
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_XkbClearOverlayRow(char *row_in)
#else
_XkbClearOverlayRow(row_in)
char * row_in;
#endif
{
XkbOverlayRowPtr row= (XkbOverlayRowPtr)row_in;
if (row->keys!=NULL)
XkbFreeGeomOverlayKeys(row,0,row->num_keys,True);
return;
}
void
#if NeedFunctionPrototypes
XkbFreeGeomOverlayRows(XkbOverlayPtr overlay,int first,int count,Bool freeAll)
#else
XkbFreeGeomOverlayRows(overlay,first,count,freeAll)
XkbOverlayPtr overlay;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomNonLeafElems(freeAll,first,count,
&overlay->num_rows,&overlay->sz_rows,
(char **)&overlay->rows,
sizeof(XkbOverlayRowRec),_XkbClearOverlayRow);
return;
}
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_XkbClearOverlay(char *overlay_in)
#else
_XkbClearOverlay(overlay_in)
char * overlay_in;
#endif
{
XkbOverlayPtr overlay= (XkbOverlayPtr)overlay_in;
if (overlay->rows!=NULL)
XkbFreeGeomOverlayRows(overlay,0,overlay->num_rows,True);
return;
}
void
#if NeedFunctionPrototypes
XkbFreeGeomOverlays(XkbSectionPtr section,int first,int count,Bool freeAll)
#else
XkbFreeGeomOverlays(section,first,count,freeAll)
XkbSectionPtr section;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomNonLeafElems(freeAll,first,count,
§ion->num_overlays,§ion->sz_overlays,
(char **)§ion->overlays,
sizeof(XkbOverlayRec),_XkbClearOverlay);
return;
}
/***====================================================================***/
void
#if NeedFunctionPrototypes
XkbFreeGeomKeys(XkbRowPtr row,int first,int count,Bool freeAll)
#else
XkbFreeGeomKeys(row,first,count,freeAll)
XkbRowPtr row;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomLeafElems(freeAll,first,count,
&row->num_keys,&row->sz_keys,
(char **)&row->keys,
sizeof(XkbKeyRec));
return;
}
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_XkbClearRow(char *row_in)
#else
_XkbClearRow(row_in)
char * row_in;
#endif
{
XkbRowPtr row= (XkbRowPtr)row_in;
if (row->keys!=NULL)
XkbFreeGeomKeys(row,0,row->num_keys,True);
return;
}
void
#if NeedFunctionPrototypes
XkbFreeGeomRows(XkbSectionPtr section,int first,int count,Bool freeAll)
#else
XkbFreeGeomRows(section,first,count,freeAll)
XkbSectionPtr section;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomNonLeafElems(freeAll,first,count,
§ion->num_rows,§ion->sz_rows,
(char **)§ion->rows,
sizeof(XkbRowRec),_XkbClearRow);
}
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_XkbClearSection(char *section_in)
#else
_XkbClearSection(section_in)
char * section_in;
#endif
{
XkbSectionPtr section= (XkbSectionPtr)section_in;
if (section->rows!=NULL)
XkbFreeGeomRows(section,0,section->num_rows,True);
if (section->doodads!=NULL) {
XkbFreeGeomDoodads(section->doodads,section->num_doodads,True);
section->doodads= NULL;
}
return;
}
void
#if NeedFunctionPrototypes
XkbFreeGeomSections(XkbGeometryPtr geom,int first,int count,Bool freeAll)
#else
XkbFreeGeomSections(geom,first,count,freeAll)
XkbGeometryPtr geom;
int first;
int count;
Bool freeAll;
#endif
{
_XkbFreeGeomNonLeafElems(freeAll,first,count,
&geom->num_sections,&geom->sz_sections,
(char **)&geom->sections,
sizeof(XkbSectionRec),_XkbClearSection);
return;
}
/***====================================================================***/
static void
#if NeedFunctionPrototypes
_XkbClearDoodad(char *doodad_in)
#else
_XkbClearDoodad(doodad_in)
char * doodad_in;
#endif
{
XkbDoodadPtr doodad= (XkbDoodadPtr)doodad_in;
switch (doodad->any.type) {
case XkbTextDoodad:
{
if (doodad->text.text!=NULL) {
_XkbFree(doodad->text.text);
doodad->text.text= NULL;
}
if (doodad->text.font!=NULL) {
_XkbFree(doodad->text.font);
doodad->text.font= NULL;
}
}
break;
case XkbLogoDoodad:
{
if (doodad->logo.logo_name!=NULL) {
_XkbFree(doodad->logo.logo_name);
doodad->logo.logo_name= NULL;
}
}
break;
}
return;
}
void
#if NeedFunctionPrototypes
XkbFreeGeomDoodads(XkbDoodadPtr doodads,int nDoodads,Bool freeAll)
#else
XkbFreeGeomDoodads(doodads,nDoodads,freeAll)
XkbDoodadPtr doodads;
int nDoodads;
Bool freeAll;
#endif
{
register int i;
register XkbDoodadPtr doodad;
if (doodads) {
for (i=0,doodad= doodads;i<nDoodads;i++,doodad++) {
_XkbClearDoodad((char *)doodad);
}
if (freeAll)
_XkbFree(doodads);
}
return;
}
void
#if NeedFunctionPrototypes
XkbFreeGeometry(XkbGeometryPtr geom,unsigned which,Bool freeMap)
#else
XkbFreeGeometry(geom,which,freeMap)
XkbGeometryPtr geom;
unsigned which;
Bool freeMap;
#endif
{
if (geom==NULL)
return;
if (freeMap)
which= XkbGeomAllMask;
if ((which&XkbGeomPropertiesMask)&&(geom->properties!=NULL))
XkbFreeGeomProperties(geom,0,geom->num_properties,True);
if ((which&XkbGeomColorsMask)&&(geom->colors!=NULL))
XkbFreeGeomColors(geom,0,geom->num_colors,True);
if ((which&XkbGeomShapesMask)&&(geom->shapes!=NULL))
XkbFreeGeomShapes(geom,0,geom->num_shapes,True);
if ((which&XkbGeomSectionsMask)&&(geom->sections!=NULL))
XkbFreeGeomSections(geom,0,geom->num_sections,True);
if ((which&XkbGeomDoodadsMask)&&(geom->doodads!= NULL)) {
XkbFreeGeomDoodads(geom->doodads,geom->num_doodads,True);
geom->doodads= NULL;
geom->num_doodads= geom->sz_doodads= 0;
}
if ((which&XkbGeomKeyAliasesMask)&&(geom->key_aliases!=NULL))
XkbFreeGeomKeyAliases(geom,0,geom->num_key_aliases,True);
if (freeMap) {
if (geom->label_font!=NULL) {
_XkbFree(geom->label_font);
geom->label_font= NULL;
}
_XkbFree(geom);
}
return;
}
/***====================================================================***/
static Status
#if NeedFunctionPrototypes
_XkbGeomAlloc( XPointer * old,
unsigned short * num,
unsigned short * total,
int num_new,
Size_t sz_elem)
#else
_XkbGeomAlloc(old,num,total,num_new,sz_elem)
XPointer * old;
unsigned short * num;
unsigned short * total;
int num_new;
Size_t sz_elem;
#endif
{
if (num_new<1)
return Success;
if ((*old)==NULL)
*num= *total= 0;
if ((*num)+num_new<=(*total))
return Success;
*total= (*num)+num_new;
if ((*old)!=NULL)
(*old)= (XPointer)_XkbRealloc((*old),(*total)*sz_elem);
else (*old)= (XPointer)_XkbCalloc((*total),sz_elem);
if ((*old)==NULL) {
*total= *num= 0;
return BadAlloc;
}
if (*num>0) {
char *tmp= (char *)(*old);
bzero(&tmp[sz_elem*(*num)],(num_new*sz_elem));
}
return Success;
}
#define _XkbAllocProps(g,n) _XkbGeomAlloc((XPointer *)&(g)->properties,\
&(g)->num_properties,&(g)->sz_properties,\
(n),sizeof(XkbPropertyRec))
#define _XkbAllocColors(g,n) _XkbGeomAlloc((XPointer *)&(g)->colors,\
&(g)->num_colors,&(g)->sz_colors,\
(n),sizeof(XkbColorRec))
#define _XkbAllocShapes(g,n) _XkbGeomAlloc((XPointer *)&(g)->shapes,\
&(g)->num_shapes,&(g)->sz_shapes,\
(n),sizeof(XkbShapeRec))
#define _XkbAllocSections(g,n) _XkbGeomAlloc((XPointer *)&(g)->sections,\
&(g)->num_sections,&(g)->sz_sections,\
(n),sizeof(XkbSectionRec))
#define _XkbAllocDoodads(g,n) _XkbGeomAlloc((XPointer *)&(g)->doodads,\
&(g)->num_doodads,&(g)->sz_doodads,\
(n),sizeof(XkbDoodadRec))
#define _XkbAllocKeyAliases(g,n) _XkbGeomAlloc((XPointer *)&(g)->key_aliases,\
&(g)->num_key_aliases,&(g)->sz_key_aliases,\
(n),sizeof(XkbKeyAliasRec))
#define _XkbAllocOutlines(s,n) _XkbGeomAlloc((XPointer *)&(s)->outlines,\
&(s)->num_outlines,&(s)->sz_outlines,\
(n),sizeof(XkbOutlineRec))
#define _XkbAllocRows(s,n) _XkbGeomAlloc((XPointer *)&(s)->rows,\
&(s)->num_rows,&(s)->sz_rows,\
(n),sizeof(XkbRowRec))
#define _XkbAllocPoints(o,n) _XkbGeomAlloc((XPointer *)&(o)->points,\
&(o)->num_points,&(o)->sz_points,\
(n),sizeof(XkbPointRec))
#define _XkbAllocKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\
&(r)->num_keys,&(r)->sz_keys,\
(n),sizeof(XkbKeyRec))
#define _XkbAllocOverlays(s,n) _XkbGeomAlloc((XPointer *)&(s)->overlays,\
&(s)->num_overlays,&(s)->sz_overlays,\
(n),sizeof(XkbOverlayRec))
#define _XkbAllocOverlayRows(o,n) _XkbGeomAlloc((XPointer *)&(o)->rows,\
&(o)->num_rows,&(o)->sz_rows,\
(n),sizeof(XkbOverlayRowRec))
#define _XkbAllocOverlayKeys(r,n) _XkbGeomAlloc((XPointer *)&(r)->keys,\
&(r)->num_keys,&(r)->sz_keys,\
(n),sizeof(XkbOverlayKeyRec))
Status
#if NeedFunctionPrototypes
XkbAllocGeomProps(XkbGeometryPtr geom,int nProps)
#else
XkbAllocGeomProps(geom,nProps)
XkbGeometryPtr geom;
int nProps;
#endif
{
return _XkbAllocProps(geom,nProps);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomColors(XkbGeometryPtr geom,int nColors)
#else
XkbAllocGeomColors(geom,nColors)
XkbGeometryPtr geom;
int nColors;
#endif
{
return _XkbAllocColors(geom,nColors);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomKeyAliases(XkbGeometryPtr geom,int nKeyAliases)
#else
XkbAllocGeomKeyAliases(geom,nKeyAliases)
XkbGeometryPtr geom;
int nKeyAliases;
#endif
{
return _XkbAllocKeyAliases(geom,nKeyAliases);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomShapes(XkbGeometryPtr geom,int nShapes)
#else
XkbAllocGeomShapes(geom,nShapes)
XkbGeometryPtr geom;
int nShapes;
#endif
{
return _XkbAllocShapes(geom,nShapes);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomSections(XkbGeometryPtr geom,int nSections)
#else
XkbAllocGeomSections(geom,nSections)
XkbGeometryPtr geom;
int nSections;
#endif
{
return _XkbAllocSections(geom,nSections);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomOverlays(XkbSectionPtr section,int nOverlays)
#else
XkbAllocGeomOverlays(section,nOverlays)
XkbSectionPtr section;
int nOverlays;
#endif
{
return _XkbAllocOverlays(section,nOverlays);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomOverlayRows(XkbOverlayPtr overlay,int nRows)
#else
XkbAllocGeomOverlayRows(overlay,nRows)
XkbOverlayPtr overlay;
int nRows;
#endif
{
return _XkbAllocOverlayRows(overlay,nRows);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row,int nKeys)
#else
XkbAllocGeomOverlayKeys(row,nKeys)
XkbOverlayRowPtr row;
int nKeys;
#endif
{
return _XkbAllocOverlayKeys(row,nKeys);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomDoodads(XkbGeometryPtr geom,int nDoodads)
#else
XkbAllocGeomDoodads(geom,nDoodads)
XkbGeometryPtr geom;
int nDoodads;
#endif
{
return _XkbAllocDoodads(geom,nDoodads);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomSectionDoodads(XkbSectionPtr section,int nDoodads)
#else
XkbAllocGeomSectionDoodads(section,nDoodads)
XkbSectionPtr section;
int nDoodads;
#endif
{
return _XkbAllocDoodads(section,nDoodads);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomOutlines(XkbShapePtr shape,int nOL)
#else
XkbAllocGeomOutlines(shape,nOL)
XkbShapePtr shape;
int nOL;
#endif
{
return _XkbAllocOutlines(shape,nOL);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomRows(XkbSectionPtr section,int nRows)
#else
XkbAllocGeomRows(section,nRows)
XkbSectionPtr section;
int nRows;
#endif
{
return _XkbAllocRows(section,nRows);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomPoints(XkbOutlinePtr ol,int nPts)
#else
XkbAllocGeomPoints(ol,nPts)
XkbOutlinePtr ol;
int nPts;
#endif
{
return _XkbAllocPoints(ol,nPts);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeomKeys(XkbRowPtr row,int nKeys)
#else
XkbAllocGeomKeys(row,nKeys)
XkbRowPtr row;
int nKeys;
#endif
{
return _XkbAllocKeys(row,nKeys);
}
Status
#if NeedFunctionPrototypes
XkbAllocGeometry(XkbDescPtr xkb,XkbGeometrySizesPtr sizes)
#else
XkbAllocGeometry(xkb,sizes)
XkbDescPtr xkb;
XkbGeometrySizesPtr sizes;
#endif
{
XkbGeometryPtr geom;
Status rtrn;
if (xkb->geom==NULL) {
xkb->geom= _XkbTypedCalloc(1,XkbGeometryRec);
if (!xkb->geom)
return BadAlloc;
}
geom= xkb->geom;
if ((sizes->which&XkbGeomPropertiesMask)&&
((rtrn=_XkbAllocProps(geom,sizes->num_properties))!=Success)) {
goto BAIL;
}
if ((sizes->which&XkbGeomColorsMask)&&
((rtrn=_XkbAllocColors(geom,sizes->num_colors))!=Success)) {
goto BAIL;
}
if ((sizes->which&XkbGeomShapesMask)&&
((rtrn=_XkbAllocShapes(geom,sizes->num_shapes))!=Success)) {
goto BAIL;
}
if ((sizes->which&XkbGeomSectionsMask)&&
((rtrn=_XkbAllocSections(geom,sizes->num_sections))!=Success)) {
goto BAIL;
}
if ((sizes->which&XkbGeomDoodadsMask)&&
((rtrn=_XkbAllocDoodads(geom,sizes->num_doodads))!=Success)) {
goto BAIL;
}
if ((sizes->which&XkbGeomKeyAliasesMask)&&
((rtrn=_XkbAllocKeyAliases(geom,sizes->num_key_aliases))!=Success)) {
goto BAIL;
}
return Success;
BAIL:
XkbFreeGeometry(geom,XkbGeomAllMask,True);
xkb->geom= NULL;
return rtrn;
}
/***====================================================================***/
XkbPropertyPtr
#if NeedFunctionPrototypes
XkbAddGeomProperty(XkbGeometryPtr geom,char *name,char *value)
#else
XkbAddGeomProperty(geom,name,value)
XkbGeometryPtr geom;
char * name;
char * value;
#endif
{
register int i;
register XkbPropertyPtr prop;
if ((!geom)||(!name)||(!value))
return NULL;
for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
if ((prop->name)&&(strcmp(name,prop->name)==0)) {
if (prop->value)
_XkbFree(prop->value);
prop->value= (char *)_XkbAlloc(strlen(value)+1);
if (prop->value)
strcpy(prop->value,value);
return prop;
}
}
if ((geom->num_properties>=geom->sz_properties)&&
(_XkbAllocProps(geom,1)!=Success)) {
return NULL;
}
prop= &geom->properties[geom->num_properties];
prop->name= (char *)_XkbAlloc(strlen(name)+1);
if (!name)
return NULL;
strcpy(prop->name,name);
prop->value= (char *)_XkbAlloc(strlen(value)+1);
if (!value) {
_XkbFree(prop->name);
prop->name= NULL;
return NULL;
}
strcpy(prop->value,value);
geom->num_properties++;
return prop;
}
XkbKeyAliasPtr
#if NeedFunctionPrototypes
XkbAddGeomKeyAlias(XkbGeometryPtr geom,char *aliasStr,char *realStr)
#else
XkbAddGeomKeyAlias(geom,aliasStr,realStr)
XkbGeometryPtr geom;
char * aliasStr;
char * realStr;
#endif
{
register int i;
register XkbKeyAliasPtr alias;
if ((!geom)||(!aliasStr)||(!realStr)||(!aliasStr[0])||(!realStr[0]))
return NULL;
for (i=0,alias=geom->key_aliases;i<geom->num_key_aliases;i++,alias++) {
if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) {
bzero(alias->real,XkbKeyNameLength);
strncpy(alias->real,realStr,XkbKeyNameLength);
return alias;
}
}
if ((geom->num_key_aliases>=geom->sz_key_aliases)&&
(_XkbAllocKeyAliases(geom,1)!=Success)) {
return NULL;
}
alias= &geom->key_aliases[geom->num_key_aliases];
bzero(alias,sizeof(XkbKeyAliasRec));
strncpy(alias->alias,aliasStr,XkbKeyNameLength);
strncpy(alias->real,realStr,XkbKeyNameLength);
geom->num_key_aliases++;
return alias;
}
XkbColorPtr
#if NeedFunctionPrototypes
XkbAddGeomColor(XkbGeometryPtr geom,char *spec,unsigned int pixel)
#else
XkbAddGeomColor(geom,spec,pixel)
XkbGeometryPtr geom;
char * spec;
unsigned int pixel;
#endif
{
register int i;
register XkbColorPtr color;
if ((!geom)||(!spec))
return NULL;
for (i=0,color=geom->colors;i<geom->num_colors;i++,color++) {
if ((color->spec)&&(strcmp(color->spec,spec)==0)) {
color->pixel= pixel;
return color;
}
}
if ((geom->num_colors>=geom->sz_colors)&&
(_XkbAllocColors(geom,1)!=Success)) {
return NULL;
}
color= &geom->colors[geom->num_colors];
color->pixel= pixel;
color->spec= (char *)_XkbAlloc(strlen(spec)+1);
if (!color->spec)
return NULL;
strcpy(color->spec,spec);
geom->num_colors++;
return color;
}
XkbOutlinePtr
#if NeedFunctionPrototypes
XkbAddGeomOutline(XkbShapePtr shape,int sz_points)
#else
XkbAddGeomOutline(shape,sz_points)
XkbShapePtr shape;
int sz_points;
#endif
{
XkbOutlinePtr outline;
if ((!shape)||(sz_points<0))
return NULL;
if ((shape->num_outlines>=shape->sz_outlines)&&
(_XkbAllocOutlines(shape,1)!=Success)) {
return NULL;
}
outline= &shape->outlines[shape->num_outlines];
bzero(outline,sizeof(XkbOutlineRec));
if ((sz_points>0)&&(_XkbAllocPoints(outline,sz_points)!=Success))
return NULL;
shape->num_outlines++;
return outline;
}
XkbShapePtr
#if NeedFunctionPrototypes
XkbAddGeomShape(XkbGeometryPtr geom,Atom name,int sz_outlines)
#else
XkbAddGeomShape(geom,name,sz_outlines)
XkbGeometryPtr geom;
Atom name;
int sz_outlines;
#endif
{
XkbShapePtr shape;
register int i;
if ((!geom)||(!name)||(sz_outlines<0))
return NULL;
if (geom->num_shapes>0) {
for (shape=geom->shapes,i=0;i<geom->num_shapes;i++,shape++) {
if (name==shape->name)
return shape;
}
}
if ((geom->num_shapes>=geom->sz_shapes)&&
(_XkbAllocShapes(geom,1)!=Success))
return NULL;
shape= &geom->shapes[geom->num_shapes];
bzero(shape,sizeof(XkbShapeRec));
if ((sz_outlines>0)&&(_XkbAllocOutlines(shape,sz_outlines)!=Success))
return NULL;
shape->name= name;
shape->primary= shape->approx= NULL;
geom->num_shapes++;
return shape;
}
XkbKeyPtr
#if NeedFunctionPrototypes
XkbAddGeomKey(XkbRowPtr row)
#else
XkbAddGeomKey(row)
XkbRowPtr row;
#endif
{
XkbKeyPtr key;
if (!row)
return NULL;
if ((row->num_keys>=row->sz_keys)&&(_XkbAllocKeys(row,1)!=Success))
return NULL;
key= &row->keys[row->num_keys++];
bzero(key,sizeof(XkbKeyRec));
return key;
}
XkbRowPtr
#if NeedFunctionPrototypes
XkbAddGeomRow(XkbSectionPtr section,int sz_keys)
#else
XkbAddGeomRow(section,sz_keys)
XkbSectionPtr section;
int sz_keys;
#endif
{
XkbRowPtr row;
if ((!section)||(sz_keys<0))
return NULL;
if ((section->num_rows>=section->sz_rows)&&
(_XkbAllocRows(section,1)!=Success))
return NULL;
row= §ion->rows[section->num_rows];
bzero(row,sizeof(XkbRowRec));
if ((sz_keys>0)&&(_XkbAllocKeys(row,sz_keys)!=Success))
return NULL;
section->num_rows++;
return row;
}
XkbSectionPtr
#if NeedFunctionPrototypes
XkbAddGeomSection( XkbGeometryPtr geom,
Atom name,
int sz_rows,
int sz_doodads,
int sz_over)
#else
XkbAddGeomSection(geom,name,sz_rows,sz_doodads,sz_over)
XkbGeometryPtr geom;
Atom name;
int sz_rows;
int sz_doodads;
int sz_over;
#endif
{
register int i;
XkbSectionPtr section;
if ((!geom)||(name==None)||(sz_rows<0))
return NULL;
for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) {
if (section->name!=name)
continue;
if (((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))||
((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success))||
((sz_over>0)&&(_XkbAllocOverlays(section,sz_over)!=Success)))
return NULL;
return section;
}
if ((geom->num_sections>=geom->sz_sections)&&
(_XkbAllocSections(geom,1)!=Success))
return NULL;
section= &geom->sections[geom->num_sections];
if ((sz_rows>0)&&(_XkbAllocRows(section,sz_rows)!=Success))
return NULL;
if ((sz_doodads>0)&&(_XkbAllocDoodads(section,sz_doodads)!=Success)) {
if (section->rows) {
_XkbFree(section->rows);
section->rows= NULL;
section->sz_rows= section->num_rows= 0;
}
return NULL;
}
section->name= name;
geom->num_sections++;
return section;
}
XkbDoodadPtr
#if NeedFunctionPrototypes
XkbAddGeomDoodad(XkbGeometryPtr geom,XkbSectionPtr section,Atom name)
#else
XkbAddGeomDoodad(geom,section,name)
XkbGeometryPtr geom;
XkbSectionPtr section;
Atom name;
#endif
{
XkbDoodadPtr old,doodad;
register int i,nDoodads;
if ((!geom)||(name==None))
return NULL;
if ((section!=NULL)&&(section->num_doodads>0)) {
old= section->doodads;
nDoodads= section->num_doodads;
}
else {
old= geom->doodads;
nDoodads= geom->num_doodads;
}
for (i=0,doodad=old;i<nDoodads;i++,doodad++) {
if (doodad->any.name==name)
return doodad;
}
if (section) {
if ((section->num_doodads>=geom->sz_doodads)&&
(_XkbAllocDoodads(section,1)!=Success)) {
return NULL;
}
doodad= §ion->doodads[section->num_doodads++];
}
else {
if ((geom->num_doodads>=geom->sz_doodads)&&
(_XkbAllocDoodads(geom,1)!=Success))
return NULL;
doodad= &geom->doodads[geom->num_doodads++];
}
bzero(doodad,sizeof(XkbDoodadRec));
doodad->any.name= name;
return doodad;
}
XkbOverlayKeyPtr
#if NeedFunctionPrototypes
XkbAddGeomOverlayKey( XkbOverlayPtr overlay,
XkbOverlayRowPtr row,
char * over,
char * under)
#else
XkbAddGeomOverlayKey(overlay,row,over,under)
XkbOverlayPtr overlay;
XkbOverlayRowPtr row;
char * over;
char * under;
#endif
{
register int i;
XkbOverlayKeyPtr key;
XkbSectionPtr section;
XkbRowPtr row_under;
Bool found;
if ((!overlay)||(!row)||(!over)||(!under))
return NULL;
section= overlay->section_under;
if (row->row_under>=section->num_rows)
return NULL;
row_under= §ion->rows[row->row_under];
for (i=0,found=False;i<row_under->num_keys;i++) {
if (strncmp(under,row_under->keys[i].name.name,XkbKeyNameLength)==0) {
found= True;
break;
}
}
if (!found)
return NULL;
if ((row->num_keys>=row->sz_keys)&&(_XkbAllocOverlayKeys(row,1)!=Success))
return NULL;
key= &row->keys[row->num_keys];
strncpy(key->under.name,under,XkbKeyNameLength);
strncpy(key->over.name,over,XkbKeyNameLength);
row->num_keys++;
return key;
}
XkbOverlayRowPtr
#if NeedFunctionPrototypes
XkbAddGeomOverlayRow(XkbOverlayPtr overlay,int row_under,int sz_keys)
#else
XkbAddGeomOverlayRow(overlay,row_under,sz_keys)
XkbOverlayPtr overlay;
int row_under;
int sz_keys;
#endif
{
register int i;
XkbOverlayRowPtr row;
if ((!overlay)||(sz_keys<0))
return NULL;
if (row_under>=overlay->section_under->num_rows)
return NULL;
for (i=0;i<overlay->num_rows;i++) {
if (overlay->rows[i].row_under==row_under) {
row= &overlay->rows[i];
if ((row->sz_keys<sz_keys)&&
(_XkbAllocOverlayKeys(row,sz_keys)!=Success)) {
return NULL;
}
return &overlay->rows[i];
}
}
if ((overlay->num_rows>=overlay->sz_rows)&&
(_XkbAllocOverlayRows(overlay,1)!=Success))
return NULL;
row= &overlay->rows[overlay->num_rows];
bzero(row,sizeof(XkbOverlayRowRec));
if ((sz_keys>0)&&(_XkbAllocOverlayKeys(row,sz_keys)!=Success))
return NULL;
row->row_under= row_under;
overlay->num_rows++;
return row;
}
XkbOverlayPtr
#if NeedFunctionPrototypes
XkbAddGeomOverlay(XkbSectionPtr section,Atom name,int sz_rows)
#else
XkbAddGeomOverlay(section,name,sz_rows)
XkbSectionPtr section;
Atom name;
int sz_rows;
#endif
{
register int i;
XkbOverlayPtr overlay;
if ((!section)||(name==None)||(sz_rows==0))
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= §ion->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;
}
|