kinfo.c revision 05b261ec
1/* 2 * Copyright � 1999 Keith Packard 3 * 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. 13 * 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. 21 */ 22 23#ifdef HAVE_CONFIG_H 24#include <kdrive-config.h> 25#endif 26#include "kdrive.h" 27 28KdCardInfo *kdCardInfo; 29 30KdCardInfo * 31KdCardInfoAdd (KdCardFuncs *funcs, 32 KdCardAttr *attr, 33 void *closure) 34{ 35 KdCardInfo *ci, **prev; 36 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; 50} 51 52KdCardInfo * 53KdCardInfoLast (void) 54{ 55 KdCardInfo *ci; 56 57 if (!kdCardInfo) 58 return 0; 59 for (ci = kdCardInfo; ci->next; ci = ci->next); 60 return ci; 61} 62 63void 64KdCardInfoDispose (KdCardInfo *ci) 65{ 66 KdCardInfo **prev; 67 68 for (prev = &kdCardInfo; *prev; prev = &(*prev)->next) 69 if (*prev == ci) 70 { 71 *prev = ci->next; 72 xfree (ci); 73 break; 74 } 75} 76 77KdScreenInfo * 78KdScreenInfoAdd (KdCardInfo *ci) 79{ 80 KdScreenInfo *si, **prev; 81 int n; 82 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; 93} 94 95void 96KdScreenInfoDispose (KdScreenInfo *si) 97{ 98 KdCardInfo *ci = si->card; 99 KdScreenInfo **prev; 100 101 for (prev = &ci->screenList; *prev; prev = &(*prev)->next) { 102 if (*prev == si) 103 { 104 *prev = si->next; 105 xfree (si); 106 if (!ci->screenList) 107 KdCardInfoDispose (ci); 108 break; 109 } 110 } 111} 112 113KdPointerInfo * 114KdNewPointer (void) 115{ 116 KdPointerInfo *pi; 117 int i; 118 119 pi = (KdPointerInfo *)xcalloc(1, sizeof(KdPointerInfo)); 120 if (!pi) 121 return NULL; 122 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; 134 135 return pi; 136} 137 138void 139KdFreePointer(KdPointerInfo *pi) 140{ 141 InputOption *option, *prev = NULL; 142 143 if (pi->name) 144 xfree(pi->name); 145 if (pi->path) 146 xfree(pi->path); 147 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; 156 } 157 158 if (prev) 159 xfree(prev); 160 161 xfree(pi); 162} 163 164void 165KdFreeKeyboard(KdKeyboardInfo *ki) 166{ 167 if (ki->name) 168 xfree(ki->name); 169 if (ki->path) 170 xfree(ki->path); 171 ki->next = NULL; 172 xfree(ki); 173} 174