home *** CD-ROM | disk | FTP | other *** search
-
- #include <proto/exec.h>
- #include "lists.h"
-
- void *num_to_node(struct List *lst,ULONG num)
- {
- struct Node *nd;
-
- for(nd = lst->lh_Head;
- nd != NULL && nd->ln_Succ != NULL && num > 0;
- nd = nd->ln_Succ, num--) ;
-
- if(nd == NULL || nd->ln_Succ == NULL) return NULL;
- else return nd;
- }
-
- ULONG node_to_num(struct List *lst,void *nd)
- {
- struct Node *pos;
- ULONG num = 0;
-
- if(!nd) return 0;
-
- for(pos = lst->lh_Head;
- pos != NULL && pos->ln_Succ != NULL && pos != (struct Node *)nd;
- pos = pos->ln_Succ, num++) ;
-
- if(pos == NULL || pos->ln_Succ == NULL) return ~0;
- else return num;
- }
-
- void *head_node(struct List *lst)
- {
- if(lst == NULL || lst->lh_Head == NULL || lst->lh_Head->ln_Succ == NULL)
- return NULL;
-
- return lst->lh_Head;
- }
-
- void *tail_node(struct List *lst)
- {
- if(lst == NULL || lst->lh_TailPred == NULL || lst->lh_TailPred->ln_Pred == NULL)
- return NULL;
-
- return lst->lh_TailPred;
- }
-
- void *next_node(void *nd)
- {
- if( nd == NULL || ((struct Node *)nd)->ln_Succ == NULL
- || ((struct Node *)nd)->ln_Succ->ln_Succ == NULL ) return NULL;
-
- return ((struct Node *)nd)->ln_Succ;
- }
-
- void *prev_node(void *nd)
- {
- if( nd == NULL || ((struct Node *)nd)->ln_Pred == NULL
- || ((struct Node *)nd)->ln_Pred->ln_Pred == NULL ) return NULL;
-
- return ((struct Node *)nd)->ln_Pred;
- }
-