First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / src / kinfo.c
blob2621f10dddef9b1ebe75ce26eb58878cf750c91c
1 /*
2 * Copyright © 1999 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
23 #ifdef HAVE_CONFIG_H
24 #include <kdrive-config.h>
25 #endif
26 #include "kdrive.h"
28 KdCardInfo *kdCardInfo;
30 KdCardInfo *
31 KdCardInfoAdd (KdCardFuncs *funcs,
32 KdCardAttr *attr,
33 void *closure)
35 KdCardInfo *ci, **prev;
37 ci = (KdCardInfo *) xalloc (sizeof (KdCardInfo));
38 if (!ci)
39 return 0;
40 bzero (ci, sizeof (KdCardInfo));
41 for (prev = &kdCardInfo; *prev; prev = &(*prev)->next);
42 *prev = ci;
43 ci->cfuncs = funcs;
44 ci->attr = *attr;
45 ci->closure = closure;
46 ci->screenList = 0;
47 ci->selected = 0;
48 ci->next = 0;
49 return ci;
52 KdCardInfo *
53 KdCardInfoLast (void)
55 KdCardInfo *ci;
57 if (!kdCardInfo)
58 return 0;
59 for (ci = kdCardInfo; ci->next; ci = ci->next);
60 return ci;
63 void
64 KdCardInfoDispose (KdCardInfo *ci)
66 KdCardInfo **prev;
68 for (prev = &kdCardInfo; *prev; prev = &(*prev)->next)
69 if (*prev == ci)
71 *prev = ci->next;
72 xfree (ci);
73 break;
77 KdScreenInfo *
78 KdScreenInfoAdd (KdCardInfo *ci)
80 KdScreenInfo *si, **prev;
81 int n;
83 si = (KdScreenInfo *) xalloc (sizeof (KdScreenInfo));
84 if (!si)
85 return 0;
86 bzero (si, sizeof (KdScreenInfo));
87 for (prev = &ci->screenList, n = 0; *prev; prev = &(*prev)->next, n++);
88 *prev = si;
89 si->next = 0;
90 si->card = ci;
91 si->mynum = n;
92 return si;
95 void
96 KdScreenInfoDispose (KdScreenInfo *si)
98 KdCardInfo *ci = si->card;
99 KdScreenInfo **prev;
101 for (prev = &ci->screenList; *prev; prev = &(*prev)->next) {
102 if (*prev == si)
104 *prev = si->next;
105 xfree (si);
106 if (!ci->screenList)
107 KdCardInfoDispose (ci);
108 break;
113 KdPointerInfo *
114 KdNewPointer (void)
116 KdPointerInfo *pi;
117 int i;
119 pi = (KdPointerInfo *)xcalloc(1, sizeof(KdPointerInfo));
120 if (!pi)
121 return NULL;
123 pi->name = KdSaveString("Generic Pointer");
124 pi->path = NULL;
125 pi->inputClass = KD_MOUSE;
126 pi->driver = NULL;
127 pi->driverPrivate = NULL;
128 pi->next = NULL;
129 pi->options = NULL;
130 pi->nAxes = 3;
131 pi->nButtons = KD_MAX_BUTTON;
132 for (i = 1; i < KD_MAX_BUTTON; i++)
133 pi->map[i] = i;
135 return pi;
138 void
139 KdFreePointer(KdPointerInfo *pi)
141 InputOption *option, *prev = NULL;
143 if (pi->name)
144 xfree(pi->name);
145 if (pi->path)
146 xfree(pi->path);
148 for (option = pi->options; option; option = option->next) {
149 if (prev)
150 xfree(prev);
151 if (option->key)
152 xfree(option->key);
153 if (option->value)
154 xfree(option->value);
155 prev = option;
158 if (prev)
159 xfree(prev);
161 xfree(pi);
164 void
165 KdFreeKeyboard(KdKeyboardInfo *ki)
167 if (ki->name)
168 xfree(ki->name);
169 if (ki->path)
170 xfree(ki->path);
171 ki->next = NULL;
172 xfree(ki);