xkbdraw.c revision 8c9fbc29
18c9fbc29Smrg/* $Xorg: xkbdraw.c,v 1.3 2000/08/17 19:46:43 cpqbld Exp $ */ 28c9fbc29Smrg/************************************************************ 38c9fbc29Smrg Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc. 48c9fbc29Smrg 58c9fbc29Smrg Permission to use, copy, modify, and distribute this 68c9fbc29Smrg software and its documentation for any purpose and without 78c9fbc29Smrg fee is hereby granted, provided that the above copyright 88c9fbc29Smrg notice appear in all copies and that both that copyright 98c9fbc29Smrg notice and this permission notice appear in supporting 108c9fbc29Smrg documentation, and that the name of Silicon Graphics not be 118c9fbc29Smrg used in advertising or publicity pertaining to distribution 128c9fbc29Smrg of the software without specific prior written permission. 138c9fbc29Smrg Silicon Graphics makes no representation about the suitability 148c9fbc29Smrg of this software for any purpose. It is provided "as is" 158c9fbc29Smrg without any express or implied warranty. 168c9fbc29Smrg 178c9fbc29Smrg SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 188c9fbc29Smrg SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 198c9fbc29Smrg AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 208c9fbc29Smrg GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 218c9fbc29Smrg DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 228c9fbc29Smrg DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 238c9fbc29Smrg OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 248c9fbc29Smrg THE USE OR PERFORMANCE OF THIS SOFTWARE. 258c9fbc29Smrg 268c9fbc29Smrg ********************************************************/ 278c9fbc29Smrg/* $XFree86: xc/lib/xkbfile/xkbdraw.c,v 1.3 2001/07/29 05:01:13 tsi Exp $ */ 288c9fbc29Smrg 298c9fbc29Smrg#ifdef HAVE_CONFIG_H 308c9fbc29Smrg#include <config.h> 318c9fbc29Smrg#endif 328c9fbc29Smrg#include <stdio.h> 338c9fbc29Smrg#include <ctype.h> 348c9fbc29Smrg#include <stdlib.h> 358c9fbc29Smrg 368c9fbc29Smrg#include <X11/Xos.h> 378c9fbc29Smrg#include <X11/Xfuncs.h> 388c9fbc29Smrg#include <X11/Xlib.h> 398c9fbc29Smrg#include <X11/keysym.h> 408c9fbc29Smrg#include <X11/XKBlib.h> 418c9fbc29Smrg#include <X11/extensions/XKBgeom.h> 428c9fbc29Smrg#include "XKMformat.h" 438c9fbc29Smrg#include "XKBfileInt.h" 448c9fbc29Smrg 458c9fbc29Smrgstatic void 468c9fbc29Smrg_XkbAddDrawable(XkbDrawablePtr *pfirst,XkbDrawablePtr *plast,XkbDrawablePtr tmp) 478c9fbc29Smrg{ 488c9fbc29SmrgXkbDrawablePtr old; 498c9fbc29Smrg 508c9fbc29Smrg if (*pfirst==NULL) { 518c9fbc29Smrg *pfirst= *plast= tmp; 528c9fbc29Smrg } 538c9fbc29Smrg else if (tmp->priority>=(*plast)->priority) { 548c9fbc29Smrg (*plast)->next= tmp; 558c9fbc29Smrg *plast= tmp; 568c9fbc29Smrg } 578c9fbc29Smrg else if (tmp->priority<(*pfirst)->priority) { 588c9fbc29Smrg tmp->next= (*pfirst); 598c9fbc29Smrg (*pfirst)= tmp; 608c9fbc29Smrg } 618c9fbc29Smrg else { 628c9fbc29Smrg old= *pfirst; 638c9fbc29Smrg while ((old->next)&&(old->next->priority<=tmp->priority)) { 648c9fbc29Smrg old= old->next; 658c9fbc29Smrg } 668c9fbc29Smrg tmp->next= old->next; 678c9fbc29Smrg old->next= tmp; 688c9fbc29Smrg } 698c9fbc29Smrg return; 708c9fbc29Smrg} 718c9fbc29Smrg 728c9fbc29SmrgXkbDrawablePtr 738c9fbc29SmrgXkbGetOrderedDrawables(XkbGeometryPtr geom,XkbSectionPtr section) 748c9fbc29Smrg{ 758c9fbc29SmrgXkbDrawablePtr first,last,tmp; 768c9fbc29Smrgint i; 778c9fbc29Smrg 788c9fbc29Smrg first= last= NULL; 798c9fbc29Smrg if (geom!=NULL) { 808c9fbc29Smrg XkbSectionPtr section; 818c9fbc29Smrg XkbDoodadPtr doodad; 828c9fbc29Smrg for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) { 838c9fbc29Smrg tmp= _XkbTypedCalloc(1,XkbDrawableRec); 848c9fbc29Smrg if (!tmp) { 858c9fbc29Smrg XkbFreeOrderedDrawables(first); 868c9fbc29Smrg return NULL; 878c9fbc29Smrg } 888c9fbc29Smrg tmp->type= XkbDW_Section; 898c9fbc29Smrg tmp->priority= section->priority; 908c9fbc29Smrg tmp->u.section= section; 918c9fbc29Smrg tmp->next= NULL; 928c9fbc29Smrg _XkbAddDrawable(&first,&last,tmp); 938c9fbc29Smrg } 948c9fbc29Smrg for (i=0,doodad=geom->doodads;i<geom->num_doodads;i++,doodad++) { 958c9fbc29Smrg tmp= _XkbTypedCalloc(1,XkbDrawableRec); 968c9fbc29Smrg if (!tmp) { 978c9fbc29Smrg XkbFreeOrderedDrawables(first); 988c9fbc29Smrg return NULL; 998c9fbc29Smrg } 1008c9fbc29Smrg tmp->type= XkbDW_Doodad; 1018c9fbc29Smrg tmp->priority= doodad->any.priority; 1028c9fbc29Smrg tmp->u.doodad= doodad; 1038c9fbc29Smrg tmp->next= NULL; 1048c9fbc29Smrg _XkbAddDrawable(&first,&last,tmp); 1058c9fbc29Smrg } 1068c9fbc29Smrg } 1078c9fbc29Smrg if (section!=NULL) { 1088c9fbc29Smrg XkbDoodadPtr doodad; 1098c9fbc29Smrg for (i=0,doodad=section->doodads;i<section->num_doodads;i++,doodad++) { 1108c9fbc29Smrg tmp= _XkbTypedCalloc(1,XkbDrawableRec); 1118c9fbc29Smrg if (!tmp) { 1128c9fbc29Smrg XkbFreeOrderedDrawables(first); 1138c9fbc29Smrg return NULL; 1148c9fbc29Smrg } 1158c9fbc29Smrg tmp->type= XkbDW_Doodad; 1168c9fbc29Smrg tmp->priority= doodad->any.priority; 1178c9fbc29Smrg tmp->u.doodad= doodad; 1188c9fbc29Smrg tmp->next= NULL; 1198c9fbc29Smrg _XkbAddDrawable(&first,&last,tmp); 1208c9fbc29Smrg } 1218c9fbc29Smrg } 1228c9fbc29Smrg return first; 1238c9fbc29Smrg} 1248c9fbc29Smrg 1258c9fbc29Smrgvoid 1268c9fbc29SmrgXkbFreeOrderedDrawables(XkbDrawablePtr draw) 1278c9fbc29Smrg{ 1288c9fbc29SmrgXkbDrawablePtr tmp; 1298c9fbc29Smrg 1308c9fbc29Smrg for (;draw!=NULL;draw=tmp) { 1318c9fbc29Smrg tmp= draw->next; 1328c9fbc29Smrg _XkbFree(draw); 1338c9fbc29Smrg } 1348c9fbc29Smrg return; 1358c9fbc29Smrg} 136