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