list.c revision 3e747e6d
13e747e6dSmrg/*****************************************************************************/ 23e747e6dSmrg/* 33e747e6dSmrg 43e747e6dSmrgCopyright 1989, 1998 The Open Group 53e747e6dSmrg 63e747e6dSmrgPermission to use, copy, modify, distribute, and sell this software and its 73e747e6dSmrgdocumentation for any purpose is hereby granted without fee, provided that 83e747e6dSmrgthe above copyright notice appear in all copies and that both that 93e747e6dSmrgcopyright notice and this permission notice appear in supporting 103e747e6dSmrgdocumentation. 113e747e6dSmrg 123e747e6dSmrgThe above copyright notice and this permission notice shall be included in 133e747e6dSmrgall copies or substantial portions of the Software. 143e747e6dSmrg 153e747e6dSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 163e747e6dSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 173e747e6dSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 183e747e6dSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 193e747e6dSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 203e747e6dSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 213e747e6dSmrg 223e747e6dSmrgExcept as contained in this notice, the name of The Open Group shall not be 233e747e6dSmrgused in advertising or otherwise to promote the sale, use or other dealings 243e747e6dSmrgin this Software without prior written authorization from The Open Group. 253e747e6dSmrg 263e747e6dSmrg*/ 273e747e6dSmrg/** Copyright 1988 by Evans & Sutherland Computer Corporation, **/ 283e747e6dSmrg/** Salt Lake City, Utah **/ 293e747e6dSmrg/** Cambridge, Massachusetts **/ 303e747e6dSmrg/** **/ 313e747e6dSmrg/** All Rights Reserved **/ 323e747e6dSmrg/** **/ 333e747e6dSmrg/** Permission to use, copy, modify, and distribute this software and **/ 343e747e6dSmrg/** its documentation for any purpose and without fee is hereby **/ 353e747e6dSmrg/** granted, provided that the above copyright notice appear in all **/ 363e747e6dSmrg/** copies and that both that copyright notice and this permis- **/ 373e747e6dSmrg/** sion notice appear in supporting documentation, and that the **/ 383e747e6dSmrg/** name of Evans & Sutherland not be used in advertising **/ 393e747e6dSmrg/** in publicity pertaining to distribution of the software without **/ 403e747e6dSmrg/** specific, written prior permission. **/ 413e747e6dSmrg/** **/ 423e747e6dSmrg/** EVANS & SUTHERLAND DISCLAIMs ALL WARRANTIES WITH REGARD **/ 433e747e6dSmrg/** TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- **/ 443e747e6dSmrg/** ABILITY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND **/ 453e747e6dSmrg/** BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAM- **/ 463e747e6dSmrg/** AGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/ 473e747e6dSmrg/** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/ 483e747e6dSmrg/** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/ 493e747e6dSmrg/** OR PERFORMANCE OF THIS SOFTWARE. **/ 503e747e6dSmrg/*****************************************************************************/ 513e747e6dSmrg/* $XFree86: xc/programs/twm/list.c,v 1.8 2002/09/24 21:00:27 tsi Exp $ */ 523e747e6dSmrg 533e747e6dSmrg 543e747e6dSmrg/********************************************************************** 553e747e6dSmrg * 563e747e6dSmrg * $Xorg: list.c,v 1.4 2001/02/09 02:05:36 xorgcvs Exp $ 573e747e6dSmrg * 583e747e6dSmrg * TWM code to deal with the name lists for the NoTitle list and 593e747e6dSmrg * the AutoRaise list 603e747e6dSmrg * 613e747e6dSmrg * 11-Apr-88 Tom LaStrange Initial Version. 623e747e6dSmrg * 633e747e6dSmrg **********************************************************************/ 643e747e6dSmrg 653e747e6dSmrg#include <stdio.h> 663e747e6dSmrg#include "twm.h" 673e747e6dSmrg#include "screen.h" 683e747e6dSmrg#include "gram.h" 693e747e6dSmrg#include "util.h" 703e747e6dSmrg 713e747e6dSmrgstruct name_list_struct 723e747e6dSmrg{ 733e747e6dSmrg name_list *next; /**< pointer to the next name */ 743e747e6dSmrg char *name; /**< the name of the window */ 753e747e6dSmrg char *ptr; /**< list dependent data */ 763e747e6dSmrg}; 773e747e6dSmrg 783e747e6dSmrg/** 793e747e6dSmrg * add a window name to the appropriate list. 803e747e6dSmrg * 813e747e6dSmrg * If the list does not use the ptr value, a non-null value 823e747e6dSmrg * should be placed in it. LookInList returns this ptr value 833e747e6dSmrg * and procedures calling LookInList will check for a non-null 843e747e6dSmrg * return value as an indication of success. 853e747e6dSmrg * 863e747e6dSmrg * \param list the address of the pointer to the head of a list 873e747e6dSmrg * \param name a pointer to the name of the window 883e747e6dSmrg * \param ptr pointer to list dependent data 893e747e6dSmrg */ 903e747e6dSmrgvoid 913e747e6dSmrgAddToList(name_list **list_head, char *name, char *ptr) 923e747e6dSmrg{ 933e747e6dSmrg name_list *nptr; 943e747e6dSmrg 953e747e6dSmrg if (!list_head) return; /* ignore empty inserts */ 963e747e6dSmrg 973e747e6dSmrg nptr = (name_list *)malloc(sizeof(name_list)); 983e747e6dSmrg if (nptr == NULL) 993e747e6dSmrg { 1003e747e6dSmrg twmrc_error_prefix(); 1013e747e6dSmrg fprintf (stderr, "unable to allocate %ld bytes for name_list\n", 1023e747e6dSmrg (unsigned long)sizeof(name_list)); 1033e747e6dSmrg Done(NULL, NULL); 1043e747e6dSmrg } 1053e747e6dSmrg 1063e747e6dSmrg nptr->next = *list_head; 1073e747e6dSmrg nptr->name = name; 1083e747e6dSmrg nptr->ptr = (ptr == NULL) ? (char *)TRUE : ptr; 1093e747e6dSmrg *list_head = nptr; 1103e747e6dSmrg} 1113e747e6dSmrg 1123e747e6dSmrg/** 1133e747e6dSmrg * look through a list for a window name, or class 1143e747e6dSmrg * 1153e747e6dSmrg * \return the ptr field of the list structure or NULL if the name 1163e747e6dSmrg * or class was not found in the list 1173e747e6dSmrg * 1183e747e6dSmrg * \param list a pointer to the head of a list 1193e747e6dSmrg * \param name a pointer to the name to look for 1203e747e6dSmrg * \param class a pointer to the class to look for 1213e747e6dSmrg */ 1223e747e6dSmrgchar * 1233e747e6dSmrgLookInList(name_list *list_head, char *name, XClassHint *class) 1243e747e6dSmrg{ 1253e747e6dSmrg name_list *nptr; 1263e747e6dSmrg 1273e747e6dSmrg /* look for the name first */ 1283e747e6dSmrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 1293e747e6dSmrg if (strcmp(name, nptr->name) == 0) 1303e747e6dSmrg return (nptr->ptr); 1313e747e6dSmrg 1323e747e6dSmrg if (class) 1333e747e6dSmrg { 1343e747e6dSmrg /* look for the res_name next */ 1353e747e6dSmrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 1363e747e6dSmrg if (strcmp(class->res_name, nptr->name) == 0) 1373e747e6dSmrg return (nptr->ptr); 1383e747e6dSmrg 1393e747e6dSmrg /* finally look for the res_class */ 1403e747e6dSmrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 1413e747e6dSmrg if (strcmp(class->res_class, nptr->name) == 0) 1423e747e6dSmrg return (nptr->ptr); 1433e747e6dSmrg } 1443e747e6dSmrg return (NULL); 1453e747e6dSmrg} 1463e747e6dSmrg 1473e747e6dSmrgchar * 1483e747e6dSmrgLookInNameList(name_list *list_head, char *name) 1493e747e6dSmrg{ 1503e747e6dSmrg return (LookInList(list_head, name, NULL)); 1513e747e6dSmrg} 1523e747e6dSmrg 1533e747e6dSmrg/** 1543e747e6dSmrg * look through a list for a window name, or class 1553e747e6dSmrg * 1563e747e6dSmrg * \return TRUE if the name was found 1573e747e6dSmrg * \return FALSE if the name was not found 1583e747e6dSmrg * 1593e747e6dSmrg * \param list a pointer to the head of a list 1603e747e6dSmrg * \param name a pointer to the name to look for 1613e747e6dSmrg * \param class a pointer to the class to look for 1623e747e6dSmrg * \param[out] ptr fill in the list value if the name was found 1633e747e6dSmrg */ 1643e747e6dSmrgint GetColorFromList(name_list *list_head, char *name, XClassHint *class, 1653e747e6dSmrg Pixel *ptr) 1663e747e6dSmrg{ 1673e747e6dSmrg int save; 1683e747e6dSmrg name_list *nptr; 1693e747e6dSmrg 1703e747e6dSmrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 1713e747e6dSmrg if (strcmp(name, nptr->name) == 0) 1723e747e6dSmrg { 1733e747e6dSmrg save = Scr->FirstTime; 1743e747e6dSmrg Scr->FirstTime = TRUE; 1753e747e6dSmrg GetColor(Scr->Monochrome, ptr, nptr->ptr); 1763e747e6dSmrg Scr->FirstTime = save; 1773e747e6dSmrg return (TRUE); 1783e747e6dSmrg } 1793e747e6dSmrg 1803e747e6dSmrg if (class) 1813e747e6dSmrg { 1823e747e6dSmrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 1833e747e6dSmrg if (strcmp(class->res_name, nptr->name) == 0) 1843e747e6dSmrg { 1853e747e6dSmrg save = Scr->FirstTime; 1863e747e6dSmrg Scr->FirstTime = TRUE; 1873e747e6dSmrg GetColor(Scr->Monochrome, ptr, nptr->ptr); 1883e747e6dSmrg Scr->FirstTime = save; 1893e747e6dSmrg return (TRUE); 1903e747e6dSmrg } 1913e747e6dSmrg 1923e747e6dSmrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 1933e747e6dSmrg if (strcmp(class->res_class, nptr->name) == 0) 1943e747e6dSmrg { 1953e747e6dSmrg save = Scr->FirstTime; 1963e747e6dSmrg Scr->FirstTime = TRUE; 1973e747e6dSmrg GetColor(Scr->Monochrome, ptr, nptr->ptr); 1983e747e6dSmrg Scr->FirstTime = save; 1993e747e6dSmrg return (TRUE); 2003e747e6dSmrg } 2013e747e6dSmrg } 2023e747e6dSmrg return (FALSE); 2033e747e6dSmrg} 2043e747e6dSmrg 2053e747e6dSmrg/** 2063e747e6dSmrg * free up a list 2073e747e6dSmrg */ 2083e747e6dSmrgvoid FreeList(name_list **list) 2093e747e6dSmrg{ 2103e747e6dSmrg name_list *nptr; 2113e747e6dSmrg name_list *tmp; 2123e747e6dSmrg 2133e747e6dSmrg for (nptr = *list; nptr != NULL; ) 2143e747e6dSmrg { 2153e747e6dSmrg tmp = nptr->next; 2163e747e6dSmrg free((char *) nptr); 2173e747e6dSmrg nptr = tmp; 2183e747e6dSmrg } 2193e747e6dSmrg *list = NULL; 2203e747e6dSmrg} 221