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