kinfo.c revision 4642e01f
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 = xcalloc (1, sizeof (KdCardInfo)); 38 if (!ci) 39 return 0; 40 for (prev = &kdCardInfo; *prev; prev = &(*prev)->next); 41 *prev = ci; 42 ci->cfuncs = funcs; 43 ci->attr = *attr; 44 ci->closure = closure; 45 ci->screenList = 0; 46 ci->selected = 0; 47 ci->next = 0; 48 return ci; 49} 50 51KdCardInfo * 52KdCardInfoLast (void) 53{ 54 KdCardInfo *ci; 55 56 if (!kdCardInfo) 57 return 0; 58 for (ci = kdCardInfo; ci->next; ci = ci->next); 59 return ci; 60} 61 62void 63KdCardInfoDispose (KdCardInfo *ci) 64{ 65 KdCardInfo **prev; 66 67 for (prev = &kdCardInfo; *prev; prev = &(*prev)->next) 68 if (*prev == ci) 69 { 70 *prev = ci->next; 71 xfree (ci); 72 break; 73 } 74} 75 76KdScreenInfo * 77KdScreenInfoAdd (KdCardInfo *ci) 78{ 79 KdScreenInfo *si, **prev; 80 int n; 81 82 si = xcalloc (1, sizeof (KdScreenInfo)); 83 if (!si) 84 return 0; 85 for (prev = &ci->screenList, n = 0; *prev; prev = &(*prev)->next, n++); 86 *prev = si; 87 si->next = 0; 88 si->card = ci; 89 si->mynum = n; 90 return si; 91} 92 93void 94KdScreenInfoDispose (KdScreenInfo *si) 95{ 96 KdCardInfo *ci = si->card; 97 KdScreenInfo **prev; 98 99 for (prev = &ci->screenList; *prev; prev = &(*prev)->next) { 100 if (*prev == si) 101 { 102 *prev = si->next; 103 xfree (si); 104 if (!ci->screenList) 105 KdCardInfoDispose (ci); 106 break; 107 } 108 } 109} 110 111KdPointerInfo * 112KdNewPointer (void) 113{ 114 KdPointerInfo *pi; 115 int i; 116 117 pi = (KdPointerInfo *)xcalloc(1, sizeof(KdPointerInfo)); 118 if (!pi) 119 return NULL; 120 121 pi->name = KdSaveString("Generic Pointer"); 122 pi->path = NULL; 123 pi->inputClass = KD_MOUSE; 124 pi->driver = NULL; 125 pi->driverPrivate = NULL; 126 pi->next = NULL; 127 pi->options = NULL; 128 pi->nAxes = 3; 129 pi->nButtons = KD_MAX_BUTTON; 130 for (i = 1; i < KD_MAX_BUTTON; i++) 131 pi->map[i] = i; 132 133 return pi; 134} 135 136void 137KdFreePointer(KdPointerInfo *pi) 138{ 139 InputOption *option, *prev = NULL; 140 141 if (pi->name) 142 xfree(pi->name); 143 if (pi->path) 144 xfree(pi->path); 145 146 for (option = pi->options; option; option = option->next) { 147 if (prev) 148 xfree(prev); 149 if (option->key) 150 xfree(option->key); 151 if (option->value) 152 xfree(option->value); 153 prev = option; 154 } 155 156 if (prev) 157 xfree(prev); 158 159 xfree(pi); 160} 161 162void 163KdFreeKeyboard(KdKeyboardInfo *ki) 164{ 165 if (ki->name) 166 xfree(ki->name); 167 if (ki->path) 168 xfree(ki->path); 169 ki->next = NULL; 170 xfree(ki); 171} 172