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

  1. /* -*- Emacs Mode: C++ -*- */
  2.  
  3. /*    linktest.c - test program for Link class & subclasses
  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/linktest.c,v 1.1 89/09/17 15:01:26 salzman Exp Locker: salzman $";
  15. #endif
  16.  
  17. /*
  18.  * $Log:    linktest.c,v $
  19.  * Revision 1.1  89/09/17  15:01:26  salzman
  20.  * Initial revision
  21.  * 
  22.  */
  23.  
  24. #include <stdio.h>
  25. #ifdef THINK_C
  26. #include <stdlib.h>
  27. #else
  28. #ifdef __GNUG__
  29. #include <std.h>
  30. #endif
  31. #endif
  32.  
  33. #include "strlink.h"
  34. #include "intlink.h"
  35. #include "listlink.h"
  36.  
  37. main()
  38. {
  39.     Link *list1, *list2;
  40.     ListLink *listlist;
  41.     
  42.     char s[100], *gets(char *);
  43.     
  44.     /* create the lists */
  45.     list1 = MakeObject(Link)();
  46.     list2 = MakeObject(Link)();
  47.     
  48.     /* the params to MakeObject are essentially ignored for first link */
  49.     listlist = MakeObject(ListLink)("a list of lists", (Link *)NULL);
  50.     
  51.     /* put some stuff in first list -- mix strings & int's, start with
  52.        a prepend
  53.     */
  54.     
  55.     list1->prepend(MakeObject(StrLink)("item 0"));
  56.     list1->prepend(MakeObject(IntLink)(0));
  57.     list1->append(MakeObject(StrLink)("item 1"));
  58.     list1->append(MakeObject(IntLink)(1));
  59.     list1->prepend(MakeObject(StrLink)("item 2"));
  60.     list1->prepend(MakeObject(IntLink)(2));
  61.     list1->append(MakeObject(StrLink)("item 3"));
  62.     list1->append(MakeObject(IntLink)(3));
  63.  
  64.     /* put stuff in second list -- again mixing srings & int's, but
  65.        start with an append
  66.     */
  67.     
  68.     list2->append(MakeObject(StrLink)("item 4"));
  69.     list2->append(MakeObject(IntLink)(4));
  70.     list2->prepend(MakeObject(StrLink)("item 5"));
  71.     list2->prepend(MakeObject(IntLink)(5));
  72.     list2->append(MakeObject(StrLink)("item 6"));
  73.     list2->append(MakeObject(IntLink)(6));
  74.     list2->prepend(MakeObject(StrLink)("item 7"));
  75.     list2->prepend(MakeObject(IntLink)(7));
  76.  
  77.     /* now append the to lists to our list list */
  78.     
  79.     listlist->append(MakeObject(ListLink)("list 1", list1));
  80.     listlist->append(MakeObject(ListLink)("list 2", list2));
  81.  
  82.     /* and see if we can find anything! */
  83.     
  84.     for (;;)
  85.       {
  86.           printf("enter item to search for: ");
  87.           if (gets(s) == NULL)    /* until ^D */
  88.           break;
  89.           
  90.           listlist->lookup(s);
  91.       }
  92.     
  93.     printf("\n");
  94.     
  95.     listlist->showlist();        /* show entire list */
  96.     
  97.     DestroyObject(listlist);
  98.     DestroyObject(list1);
  99.     DestroyObject(list2);
  100.  
  101.     exit(0);
  102. }
  103.