home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / twm / part01 / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-12  |  4.2 KB  |  144 lines

  1. /*****************************************************************************/
  2. /**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  3. /**                          Salt Lake City, Utah                           **/
  4. /**                                                                         **/
  5. /**                           All Rights Reserved                           **/
  6. /**                                                                         **/
  7. /**    Permission to use, copy, modify, and distribute this software and    **/
  8. /**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  9. /**    granted, provided that the above copyright notice appear  in  all    **/
  10. /**    copies and that both  that  copyright  notice  and  this  permis-    **/
  11. /**    sion  notice appear in supporting  documentation,  and  that  the    **/
  12. /**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  13. /**    city pertaining to distribution  of the software without  specif-    **/
  14. /**    ic, written prior permission.                                        **/
  15. /**                                                                         **/
  16. /**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  17. /**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  18. /**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  19. /**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  20. /**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  21. /**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  22. /**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  23. /**    FORMANCE OF THIS SOFTWARE.                                           **/
  24. /*****************************************************************************/
  25.  
  26. /**********************************************************************
  27.  *
  28.  * $Header: list.c,v 1.2 88/04/15 07:09:53 tlastran Exp $
  29.  *
  30.  * TWM code to deal with the name lists for the NoTitle list and
  31.  * the AutoRaise list
  32.  *
  33.  * 11-Apr-88 Tom LaStrange        Initial Version.
  34.  *
  35.  **********************************************************************/
  36.  
  37. #ifndef lint
  38. static char RCSinfo[]=
  39. "$Header: list.c,v 1.2 88/04/15 07:09:53 tlastran Exp $";
  40. #endif lint
  41.  
  42. #include <stdio.h>
  43. #include "twm.h"
  44. #include "gram.h"
  45.  
  46. typedef struct name_list name_list;
  47.  
  48. struct name_list
  49. {
  50.     name_list *next;        /* pointer to the next name */
  51.     char *name;            /* the name of the window */
  52. };
  53.  
  54. name_list *NoTitle = NULL;    /* list of window names with no title bar */
  55. name_list *AutoRaise = NULL;    /* list of window names to auto-raise */
  56.  
  57. /***********************************************************************
  58.  *
  59.  *  Procedure:
  60.  *    AddToList - add a window name to the appropriate list
  61.  *
  62.  *  Inputs:
  63.  *    list    - a #define to identify the list
  64.  *    name    - a pointer to the name of the window 
  65.  *
  66.  ***********************************************************************
  67.  */
  68.  
  69. void
  70. AddToList(list, name)
  71. int list;
  72. char *name;
  73. {
  74.     name_list *ptr;
  75.  
  76.     ptr = (name_list *)malloc(sizeof(name_list));
  77.     if (ptr == NULL)
  78.     {
  79.     fprintf(stderr, "twm: out of memory\n");
  80.     exit(1);
  81.     }
  82.  
  83.     ptr->name = name;
  84.  
  85.     switch (list)
  86.     {
  87.     case AUTO_RAISE:
  88.     ptr->next = AutoRaise;
  89.     AutoRaise = ptr;
  90.     break;
  91.  
  92.     case NO_TITLE:
  93.     ptr->next = NoTitle;
  94.     NoTitle = ptr;
  95.     break;
  96.     }
  97. }
  98.  
  99. /***********************************************************************
  100.  *
  101.  *  Procedure:
  102.  *    LookInList - look through a list for a window name
  103.  *
  104.  *  Returned Value:
  105.  *    TRUE    - the window was found in the list
  106.  *    FALSE    - the window was not found in the list
  107.  *
  108.  *  Inputs:
  109.  *    list    - a #define to identify the list
  110.  *    name    - a pointer to the name to look for
  111.  *
  112.  ***********************************************************************
  113.  */
  114.  
  115. int
  116. LookInList(list, name)
  117. int list;
  118. char *name;
  119. {
  120.     name_list *l;
  121.     name_list *ptr;
  122.  
  123.     switch (list)
  124.     {
  125.     case AUTO_RAISE:
  126.     l = AutoRaise;
  127.     break;
  128.  
  129.     case NO_TITLE:
  130.     l = NoTitle;
  131.     break;
  132.     }
  133.  
  134.     for (ptr = l; ptr != NULL; ptr = ptr->next)
  135.     {
  136.     int len;
  137.  
  138.     len = strlen(ptr->name);
  139.     if (strncmp(name, ptr->name, len) == 0)
  140.         return (TRUE);
  141.     }
  142.     return (FALSE);
  143. }
  144.