xkbdraw.c revision 70728a38
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
4470728a38Smrg_XkbAddDrawable(XkbDrawablePtr *pfirst, XkbDrawablePtr *plast,
4570728a38Smrg                XkbDrawablePtr tmp)
468c9fbc29Smrg{
4770728a38Smrg    XkbDrawablePtr old;
488c9fbc29Smrg
4970728a38Smrg    if (*pfirst == NULL) {
5070728a38Smrg        *pfirst = *plast = tmp;
518c9fbc29Smrg    }
5270728a38Smrg    else if (tmp->priority >= (*plast)->priority) {
5370728a38Smrg        (*plast)->next = tmp;
5470728a38Smrg        *plast = tmp;
558c9fbc29Smrg    }
5670728a38Smrg    else if (tmp->priority < (*pfirst)->priority) {
5770728a38Smrg        tmp->next = (*pfirst);
5870728a38Smrg        (*pfirst) = tmp;
598c9fbc29Smrg    }
608c9fbc29Smrg    else {
6170728a38Smrg        old = *pfirst;
6270728a38Smrg        while ((old->next) && (old->next->priority <= tmp->priority)) {
6370728a38Smrg            old = old->next;
6470728a38Smrg        }
6570728a38Smrg        tmp->next = old->next;
6670728a38Smrg        old->next = tmp;
678c9fbc29Smrg    }
688c9fbc29Smrg    return;
698c9fbc29Smrg}
708c9fbc29Smrg
718c9fbc29SmrgXkbDrawablePtr
7270728a38SmrgXkbGetOrderedDrawables(XkbGeometryPtr geom, XkbSectionPtr section)
738c9fbc29Smrg{
7470728a38Smrg    XkbDrawablePtr first, last, tmp;
7570728a38Smrg    int i;
768c9fbc29Smrg
7770728a38Smrg    first = last = NULL;
7870728a38Smrg    if (geom != NULL) {
7970728a38Smrg        XkbSectionPtr section;
8070728a38Smrg        XkbDoodadPtr doodad;
8170728a38Smrg
8270728a38Smrg        for (i = 0, section = geom->sections; i < geom->num_sections;
8370728a38Smrg             i++, section++) {
8470728a38Smrg            tmp = _XkbTypedCalloc(1, XkbDrawableRec);
8570728a38Smrg            if (!tmp) {
8670728a38Smrg                XkbFreeOrderedDrawables(first);
8770728a38Smrg                return NULL;
8870728a38Smrg            }
8970728a38Smrg            tmp->type = XkbDW_Section;
9070728a38Smrg            tmp->priority = section->priority;
9170728a38Smrg            tmp->u.section = section;
9270728a38Smrg            tmp->next = NULL;
9370728a38Smrg            _XkbAddDrawable(&first, &last, tmp);
9470728a38Smrg        }
9570728a38Smrg        for (i = 0, doodad = geom->doodads; i < geom->num_doodads;
9670728a38Smrg             i++, doodad++) {
9770728a38Smrg            tmp = _XkbTypedCalloc(1, XkbDrawableRec);
9870728a38Smrg            if (!tmp) {
9970728a38Smrg                XkbFreeOrderedDrawables(first);
10070728a38Smrg                return NULL;
10170728a38Smrg            }
10270728a38Smrg            tmp->type = XkbDW_Doodad;
10370728a38Smrg            tmp->priority = doodad->any.priority;
10470728a38Smrg            tmp->u.doodad = doodad;
10570728a38Smrg            tmp->next = NULL;
10670728a38Smrg            _XkbAddDrawable(&first, &last, tmp);
10770728a38Smrg        }
1088c9fbc29Smrg    }
10970728a38Smrg    if (section != NULL) {
11070728a38Smrg        XkbDoodadPtr doodad;
11170728a38Smrg
11270728a38Smrg        for (i = 0, doodad = section->doodads; i < section->num_doodads;
11370728a38Smrg             i++, doodad++) {
11470728a38Smrg            tmp = _XkbTypedCalloc(1, XkbDrawableRec);
11570728a38Smrg            if (!tmp) {
11670728a38Smrg                XkbFreeOrderedDrawables(first);
11770728a38Smrg                return NULL;
11870728a38Smrg            }
11970728a38Smrg            tmp->type = XkbDW_Doodad;
12070728a38Smrg            tmp->priority = doodad->any.priority;
12170728a38Smrg            tmp->u.doodad = doodad;
12270728a38Smrg            tmp->next = NULL;
12370728a38Smrg            _XkbAddDrawable(&first, &last, tmp);
12470728a38Smrg        }
1258c9fbc29Smrg    }
1268c9fbc29Smrg    return first;
1278c9fbc29Smrg}
1288c9fbc29Smrg
1298c9fbc29Smrgvoid
1308c9fbc29SmrgXkbFreeOrderedDrawables(XkbDrawablePtr draw)
1318c9fbc29Smrg{
13270728a38Smrg    XkbDrawablePtr tmp;
1338c9fbc29Smrg
13470728a38Smrg    for (; draw != NULL; draw = tmp) {
13570728a38Smrg        tmp = draw->next;
13670728a38Smrg        _XkbFree(draw);
13770728a38Smrg    }
13870728a38Smrg    return;
1398c9fbc29Smrg}
140