xkbdraw.c revision 4cd6a3ae
1/************************************************************ 2 Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc. 3 4 Permission to use, copy, modify, and distribute this 5 software and its documentation for any purpose and without 6 fee is hereby granted, provided that the above copyright 7 notice appear in all copies and that both that copyright 8 notice and this permission notice appear in supporting 9 documentation, and that the name of Silicon Graphics not be 10 used in advertising or publicity pertaining to distribution 11 of the software without specific prior written permission. 12 Silicon Graphics makes no representation about the suitability 13 of this software for any purpose. It is provided "as is" 14 without any express or implied warranty. 15 16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 23 THE USE OR PERFORMANCE OF THIS SOFTWARE. 24 25 ********************************************************/ 26 27#ifdef HAVE_CONFIG_H 28#include <config.h> 29#endif 30#include <stdio.h> 31#include <ctype.h> 32#include <stdlib.h> 33 34#include <X11/Xos.h> 35#include <X11/Xfuncs.h> 36#include <X11/Xlib.h> 37#include <X11/keysym.h> 38#include <X11/XKBlib.h> 39#include <X11/extensions/XKBgeom.h> 40#include "XKMformat.h" 41#include "XKBfileInt.h" 42 43static void 44_XkbAddDrawable(XkbDrawablePtr *pfirst,XkbDrawablePtr *plast,XkbDrawablePtr tmp) 45{ 46XkbDrawablePtr old; 47 48 if (*pfirst==NULL) { 49 *pfirst= *plast= tmp; 50 } 51 else if (tmp->priority>=(*plast)->priority) { 52 (*plast)->next= tmp; 53 *plast= tmp; 54 } 55 else if (tmp->priority<(*pfirst)->priority) { 56 tmp->next= (*pfirst); 57 (*pfirst)= tmp; 58 } 59 else { 60 old= *pfirst; 61 while ((old->next)&&(old->next->priority<=tmp->priority)) { 62 old= old->next; 63 } 64 tmp->next= old->next; 65 old->next= tmp; 66 } 67 return; 68} 69 70XkbDrawablePtr 71XkbGetOrderedDrawables(XkbGeometryPtr geom,XkbSectionPtr section) 72{ 73XkbDrawablePtr first,last,tmp; 74int i; 75 76 first= last= NULL; 77 if (geom!=NULL) { 78 XkbSectionPtr section; 79 XkbDoodadPtr doodad; 80 for (i=0,section=geom->sections;i<geom->num_sections;i++,section++) { 81 tmp= _XkbTypedCalloc(1,XkbDrawableRec); 82 if (!tmp) { 83 XkbFreeOrderedDrawables(first); 84 return NULL; 85 } 86 tmp->type= XkbDW_Section; 87 tmp->priority= section->priority; 88 tmp->u.section= section; 89 tmp->next= NULL; 90 _XkbAddDrawable(&first,&last,tmp); 91 } 92 for (i=0,doodad=geom->doodads;i<geom->num_doodads;i++,doodad++) { 93 tmp= _XkbTypedCalloc(1,XkbDrawableRec); 94 if (!tmp) { 95 XkbFreeOrderedDrawables(first); 96 return NULL; 97 } 98 tmp->type= XkbDW_Doodad; 99 tmp->priority= doodad->any.priority; 100 tmp->u.doodad= doodad; 101 tmp->next= NULL; 102 _XkbAddDrawable(&first,&last,tmp); 103 } 104 } 105 if (section!=NULL) { 106 XkbDoodadPtr doodad; 107 for (i=0,doodad=section->doodads;i<section->num_doodads;i++,doodad++) { 108 tmp= _XkbTypedCalloc(1,XkbDrawableRec); 109 if (!tmp) { 110 XkbFreeOrderedDrawables(first); 111 return NULL; 112 } 113 tmp->type= XkbDW_Doodad; 114 tmp->priority= doodad->any.priority; 115 tmp->u.doodad= doodad; 116 tmp->next= NULL; 117 _XkbAddDrawable(&first,&last,tmp); 118 } 119 } 120 return first; 121} 122 123void 124XkbFreeOrderedDrawables(XkbDrawablePtr draw) 125{ 126XkbDrawablePtr tmp; 127 128 for (;draw!=NULL;draw=tmp) { 129 tmp= draw->next; 130 _XkbFree(draw); 131 } 132 return; 133} 134