home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / tcopuls_.sit / listlink.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-17  |  1.8 KB  |  91 lines  |  [TEXT/MPS ]

  1. /* -*- Emacs Mode: C++ -*- */
  2.  
  3. /*    listlink.c - ListLink Class implementation
  4.  
  5.     Copyright (C) 1989, Integrity Software
  6.     Author: Isaac J. Salzman (salzman@rand.org)
  7.  
  8.     This software may be freely used/modified/distributed
  9.     as desired so long as this copyright notice remains
  10.     in tact.
  11. */
  12.  
  13. #ifndef lint
  14. static char *RcsId = "$Header: /tmp_mnt/amnt/lh/salzman/src/class/RCS/listlink.c,v 1.1 89/09/17 15:01:32 salzman Exp Locker: salzman $";
  15. #endif
  16.  
  17. /*
  18.  * $Log:    listlink.c,v $
  19.  * Revision 1.1  89/09/17  15:01:32  salzman
  20.  * Initial revision
  21.  * 
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26.  
  27. #include "listlink.h"
  28.  
  29. DEF_INIT(ListLink)(char *str, Link *lp) SUPER_INIT_ARGS((str))
  30. {
  31.     list = lp;
  32.  
  33.     INIT_SUPER(StrLink,(str));
  34.     
  35.     RETURN_THIS;
  36. }
  37.  
  38. DEF_DEST(ListLink)(void)
  39. {
  40.     /* we *could* destroy all our member lists, but that's not
  41.        necessarily a good idea since they should be able to go
  42.        on living when this object dies -- and should be destroyed
  43.        explicitly.
  44.     */
  45.        
  46.     DESTROY_SUPER;
  47. }
  48.  
  49. void ListLink::showval(void)
  50. {
  51.     printf("list name = %s\n", string);
  52.     if (list)
  53.         list->showlist();
  54. }
  55.  
  56. /* this method looks for a string in one of our sublists, or looks to
  57.    see if it's the name of one of our sub lists, in which case it will
  58.    display the contents of the entire sub list.
  59. */
  60.  
  61. void ListLink::lookup(char *item)
  62. {
  63.     register Link *lpp;
  64.     register ListLink *lp;
  65.     
  66.     if (lp = (ListLink *) find(item))
  67.       {
  68.           printf("found list called \"%s\"\n", item);
  69.           lp->showval();
  70.           return ;
  71.       }
  72.     else
  73.       {
  74.           for (lp=(ListLink *) next();lp;lp = (ListLink *) lp->next())
  75.           {
  76.               if (lpp = lp->list->find(item))
  77.               {
  78.                   printf("found item \"%s\" in list \"%s\"\n", item, 
  79.                       lp->string);
  80.                   lpp->showval();
  81.                   return ;
  82.               }
  83.           }
  84.     }
  85.     
  86.     /* this is never reached if something's found */
  87.     printf("item \"%s\" not found\n", item);
  88.     
  89. }
  90.  
  91.