home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / alib / newlist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  1.7 KB  |  90 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: newlist.c,v 1.1 1996/11/28 10:40:29 aros Exp $
  4.  
  5.     Desc: Initialize a list
  6.     Lang: english
  7. */
  8. #define AROS_ALMOST_COMPATIBLE
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13. #include <exec/lists.h>
  14.  
  15.     void NewList (
  16.  
  17. /*  SYNOPSIS */
  18.     struct List * list)
  19.  
  20. /*  FUNCTION
  21.     Initialize a list. After that, you can use functions like
  22.     AddHead(), AddTail() and Insert() on the list.
  23.  
  24.     INPUTS
  25.     list - the list to be initialized
  26.  
  27.     RESULT
  28.     None.
  29.  
  30.     NOTES
  31.     You can also pass a struct MinList to this function.
  32.  
  33.     EXAMPLE
  34.     See below.
  35.  
  36.     BUGS
  37.  
  38.     SEE ALSO
  39.     NEWLIST() macro, AddHead(), AddTail(), Insert(), Enqueue(),
  40.     Remove(), RemHead(), RemTail()
  41.  
  42.     INTERNALS
  43.  
  44.     HISTORY
  45.     28.11.96 digulla written
  46.  
  47. ******************************************************************************/
  48. {
  49.     NEWLIST(list);
  50. } /* NewList */
  51.  
  52. #ifdef TEST
  53. #include <stdio.h>
  54.  
  55. int main (int argc, char ** argv)
  56. {
  57.     struct List list;
  58.     struct Node node;
  59.     struct Usage
  60.     {
  61.     struct Node node;
  62.     int        data;
  63.     } usage;
  64.  
  65.     /* Initializing the list */
  66.     NewList (&list);
  67.  
  68.     /* Adding a node to the list */
  69.     AddHead (&list, &node);
  70.  
  71.     /*
  72.     But most of the time, you will do something like this: The struct
  73.     Usage contains a node as it's first field. Now you can collect any
  74.     number of struct Usage structures in a list.
  75.     */
  76.     AddTail (&list, (struct Node *)&usage);
  77.  
  78.     /*
  79.     If you want to avoid the cast, you can of course do this:
  80.  
  81.         AddTail (&list, &usage.node);
  82.  
  83.     but sometimes you won't, because then you can write general
  84.     functions to handle lists with all kinds of nodes in them.
  85.     */
  86.  
  87.     return 0;
  88. } /* main */
  89. #endif /* TEST */
  90.