list.c revision f66df612
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 523e747e6dSmrg/********************************************************************** 533e747e6dSmrg * 543e747e6dSmrg * TWM code to deal with the name lists for the NoTitle list and 553e747e6dSmrg * the AutoRaise list 563e747e6dSmrg * 573e747e6dSmrg * 11-Apr-88 Tom LaStrange Initial Version. 583e747e6dSmrg * 593e747e6dSmrg **********************************************************************/ 603e747e6dSmrg 613e747e6dSmrg#include <stdio.h> 623e747e6dSmrg#include "twm.h" 633e747e6dSmrg#include "screen.h" 643e747e6dSmrg#include "gram.h" 653e747e6dSmrg#include "util.h" 663e747e6dSmrg 67f66df612Smrgstruct name_list_struct { 683e747e6dSmrg name_list *next; /**< pointer to the next name */ 693e747e6dSmrg char *name; /**< the name of the window */ 703e747e6dSmrg char *ptr; /**< list dependent data */ 713e747e6dSmrg}; 723e747e6dSmrg 733e747e6dSmrg/** 743e747e6dSmrg * add a window name to the appropriate list. 753e747e6dSmrg * 76f66df612Smrg * If the list does not use the ptr value, a non-null value 77f66df612Smrg * should be placed in it. LookInList returns this ptr value 78f66df612Smrg * and procedures calling LookInList will check for a non-null 79f66df612Smrg * return value as an indication of success. 803e747e6dSmrg * 813e747e6dSmrg * \param list the address of the pointer to the head of a list 82ffd25bcaSmrg * \param name a pointer to the name of the window 833e747e6dSmrg * \param ptr pointer to list dependent data 843e747e6dSmrg */ 853e747e6dSmrgvoid 86f66df612SmrgAddToList(name_list ** list_head, char *name, char *ptr) 873e747e6dSmrg{ 883e747e6dSmrg name_list *nptr; 893e747e6dSmrg 90f66df612Smrg if (!list_head) 91f66df612Smrg return; /* ignore empty inserts */ 923e747e6dSmrg 93c2535118Smrg nptr = malloc(sizeof(name_list)); 94f66df612Smrg if (nptr == NULL) { 95f66df612Smrg parseWarning("unable to allocate %lu bytes for name_list", 96f66df612Smrg (unsigned long) sizeof(name_list)); 97f66df612Smrg Done(NULL, NULL); 983e747e6dSmrg } 993e747e6dSmrg 1003e747e6dSmrg nptr->next = *list_head; 1013e747e6dSmrg nptr->name = name; 102f66df612Smrg nptr->ptr = (ptr == NULL) ? (char *) TRUE : ptr; 1033e747e6dSmrg *list_head = nptr; 104ffd25bcaSmrg} 1053e747e6dSmrg 1063e747e6dSmrg/** 1073e747e6dSmrg * look through a list for a window name, or class 1083e747e6dSmrg * 109ffd25bcaSmrg * \return the ptr field of the list structure or NULL if the name 110f66df612Smrg * or class was not found in the list 1113e747e6dSmrg * 112f66df612Smrg * \param list a pointer to the head of a list 113f66df612Smrg * \param name a pointer to the name to look for 1143e747e6dSmrg * \param class a pointer to the class to look for 1153e747e6dSmrg */ 1163e747e6dSmrgchar * 117f66df612SmrgLookInList(name_list * list_head, const char *name, XClassHint *class) 1183e747e6dSmrg{ 1193e747e6dSmrg name_list *nptr; 1203e747e6dSmrg 1213e747e6dSmrg /* look for the name first */ 1223e747e6dSmrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 123f66df612Smrg if (strcmp(name, nptr->name) == 0) 124f66df612Smrg return (nptr->ptr); 125f66df612Smrg 126f66df612Smrg if (class) { 127f66df612Smrg /* look for the res_name next */ 128f66df612Smrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 129f66df612Smrg if (strcmp(class->res_name, nptr->name) == 0) 130f66df612Smrg return (nptr->ptr); 131f66df612Smrg 132f66df612Smrg /* finally look for the res_class */ 133f66df612Smrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 134f66df612Smrg if (strcmp(class->res_class, nptr->name) == 0) 135f66df612Smrg return (nptr->ptr); 1363e747e6dSmrg } 1373e747e6dSmrg return (NULL); 1383e747e6dSmrg} 1393e747e6dSmrg 1403e747e6dSmrgchar * 141f66df612SmrgLookInNameList(name_list * list_head, const char *name) 1423e747e6dSmrg{ 1433e747e6dSmrg return (LookInList(list_head, name, NULL)); 1443e747e6dSmrg} 1453e747e6dSmrg 1463e747e6dSmrg/** 1473e747e6dSmrg * look through a list for a window name, or class 1483e747e6dSmrg * 1493e747e6dSmrg * \return TRUE if the name was found 1503e747e6dSmrg * \return FALSE if the name was not found 1513e747e6dSmrg * 1523e747e6dSmrg * \param list a pointer to the head of a list 1533e747e6dSmrg * \param name a pointer to the name to look for 1543e747e6dSmrg * \param class a pointer to the class to look for 155f66df612Smrg * \param[out] ptr fill in the list value if the name was found 1563e747e6dSmrg */ 157f66df612Smrgint 158f66df612SmrgGetColorFromList(name_list * list_head, const char *name, XClassHint *class, 159f66df612Smrg Pixel *ptr) 1603e747e6dSmrg{ 1613e747e6dSmrg int save; 1623e747e6dSmrg name_list *nptr; 1633e747e6dSmrg 1643e747e6dSmrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 165f66df612Smrg if (strcmp(name, nptr->name) == 0) { 166f66df612Smrg save = Scr->FirstTime; 167f66df612Smrg Scr->FirstTime = TRUE; 168f66df612Smrg GetColor(Scr->Monochrome, ptr, nptr->ptr); 169f66df612Smrg Scr->FirstTime = (short) save; 170f66df612Smrg return (TRUE); 171f66df612Smrg } 172f66df612Smrg 173f66df612Smrg if (class) { 174f66df612Smrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 175f66df612Smrg if (strcmp(class->res_name, nptr->name) == 0) { 176f66df612Smrg save = Scr->FirstTime; 177f66df612Smrg Scr->FirstTime = TRUE; 178f66df612Smrg GetColor(Scr->Monochrome, ptr, nptr->ptr); 179f66df612Smrg Scr->FirstTime = (short) save; 180f66df612Smrg return (TRUE); 181f66df612Smrg } 182f66df612Smrg 183f66df612Smrg for (nptr = list_head; nptr != NULL; nptr = nptr->next) 184f66df612Smrg if (strcmp(class->res_class, nptr->name) == 0) { 185f66df612Smrg save = Scr->FirstTime; 186f66df612Smrg Scr->FirstTime = TRUE; 187f66df612Smrg GetColor(Scr->Monochrome, ptr, nptr->ptr); 188f66df612Smrg Scr->FirstTime = (short) save; 189f66df612Smrg return (TRUE); 190f66df612Smrg } 1913e747e6dSmrg } 1923e747e6dSmrg return (FALSE); 1933e747e6dSmrg} 1943e747e6dSmrg 1953e747e6dSmrg/** 1963e747e6dSmrg * free up a list 1973e747e6dSmrg */ 198f66df612Smrgvoid 199f66df612SmrgFreeList(name_list ** list) 2003e747e6dSmrg{ 2013e747e6dSmrg name_list *nptr; 2023e747e6dSmrg name_list *tmp; 2033e747e6dSmrg 204f66df612Smrg for (nptr = *list; nptr != NULL;) { 205f66df612Smrg tmp = nptr->next; 206f66df612Smrg free(nptr); 207f66df612Smrg nptr = tmp; 2083e747e6dSmrg } 2093e747e6dSmrg *list = NULL; 2103e747e6dSmrg} 211