home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d911 / psm.lha / PSM / Source / source.lha / lists.c < prev    next >
C/C++ Source or Header  |  1993-07-28  |  1KB  |  61 lines

  1.  
  2. #include <exec/lists.h>
  3. #include <exec/nodes.h>
  4.  
  5. void *num_to_node(struct List *lst,ULONG num)
  6. {
  7.     struct Node *nd;
  8.  
  9.     for(nd = lst->lh_Head;
  10.         nd != NULL && nd->ln_Succ != NULL && num > 0;
  11.         nd = nd->ln_Succ, num--) ;
  12.  
  13.     if(nd == NULL || nd->ln_Succ == NULL) return NULL;
  14.     else return nd;
  15. }
  16.  
  17. ULONG node_to_num(struct List *lst,void *nd)
  18. {
  19.     struct Node *pos;
  20.     ULONG num = 0;
  21.  
  22.     for(pos = lst->lh_Head;
  23.         pos != NULL && pos->ln_Succ != NULL && pos != (struct Node *)nd;
  24.         pos = pos->ln_Succ, num++) ;
  25.  
  26.     if(pos == NULL || pos->ln_Succ == NULL) return ~0;
  27.     else return num;
  28. }
  29.  
  30. void *head_node(struct List *lst)
  31. {
  32.     if(lst == NULL || lst->lh_Head == NULL || lst->lh_Head->ln_Succ == NULL)
  33.         return NULL;
  34.  
  35.     return lst->lh_Head;
  36. }
  37.  
  38. void *tail_node(struct List *lst)
  39. {
  40.     if(lst == NULL || lst->lh_TailPred == NULL || lst->lh_TailPred->ln_Pred == NULL)
  41.         return NULL;
  42.  
  43.     return lst->lh_TailPred;
  44. }
  45.  
  46. void *next_node(void *nd)
  47. {
  48.     if( nd == NULL || ((struct Node *)nd)->ln_Succ == NULL
  49.         || ((struct Node *)nd)->ln_Succ->ln_Succ == NULL ) return NULL;
  50.  
  51.     return ((struct Node *)nd)->ln_Succ;
  52. }
  53.  
  54. void *prev_node(void *nd)
  55. {
  56.     if( nd == NULL || ((struct Node *)nd)->ln_Pred == NULL
  57.         || ((struct Node *)nd)->ln_Pred->ln_Pred == NULL ) return NULL;
  58.  
  59.     return ((struct Node *)nd)->ln_Pred;
  60. }
  61.