/* intlist.h - Linked list of integers. */ /* * * Although this file was originally written to be used in Modoc, * it is written to have a general interface so that it could be used * in other applications. * * Author & Maintainer: Fumiaki Okushi (okushi@cs.csubak.edu) * SIMPLIFIED --AVG */ #ifndef INTLIST_H #define INTLIST_H #if 0 #ifndef lint static char vcid_h[] = "$Id: $"; #endif /* !lint */ #endif typedef struct IL_node *intlist; struct IL_node { int data; intlist next; }; #define IL_EMPTYLIST ((intlist)NULL) #define IL_FIRST(list) ((list)->data) #define IL_REST(list) ((list)->next) /* Following functions are for the traditional unreclaimable nodes.*/ intlist IL_cons(int data, const intlist list); /* The CONS function, as defined in Lisp. * The new cons cell is an unreclaimable node. * Similarly, FIRST, REST, EMPTYLIST are CAR, CDR, NIL in MacLisp. */ intlist IL_emptylist(void); int IL_first(intlist L); intlist IL_rest(intlist L); void IL_free(intlist L); /* Move nodes in the list to the free-list for unreclaimable nodes. * The operation is DESTRUCTIVE. Caller is responsible for setting * L = IL_EMPTYLIST afterwards. */ /**********************************************************************/ /* Following functions provide some utilities. */ #define IL_ISEMPTY(list) ((list)==IL_EMPTYLIST) int IL_member(int number, const intlist list); /* Return 1 if the number is in the list; otherwise, 0. */ int IL_max(const intlist list); /* Return the maximum value in the list; INT_MIN (as defined in limits.h) is returned * if the list is empty. */ void IL_print(const intlist list); /* Print the integers in the list to stdout. */ int IL_length(const intlist list); /* Return the number of integers in the list. */ intlist IL_nthcdr(int n, const intlist list); int IL_test_range(const intlist L, int lb, int ub, int *error); /* Return 1 if all integers are within the bounds of [lb,ub] (inclusive). * If not, return 0. * If error is not NULL, the first out-of-bounds integer will be stored in *error. */ #endif /* !INTLIST_H */ /* eof */