[13] | 1 | /* |
---|
| 2 | * $Id: list.h,v 1.8 2005/04/18 05:14:28 fabio Exp $ |
---|
| 3 | * |
---|
| 4 | */ |
---|
| 5 | /* |
---|
| 6 | * List Management Package Header File |
---|
| 7 | * |
---|
| 8 | * David Harrison |
---|
| 9 | * University of California, 1985 |
---|
| 10 | * |
---|
| 11 | * This file contains public type definitions for the List Managment |
---|
| 12 | * package implemented in list.c. This is stand alone package. |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #ifndef LS_DEFINED |
---|
| 16 | #define LS_DEFINED |
---|
| 17 | |
---|
| 18 | typedef void ls_dummy; |
---|
| 19 | |
---|
| 20 | typedef ls_dummy *lsList; /* List handle */ |
---|
| 21 | typedef ls_dummy *lsGen; /* List generator handle */ |
---|
| 22 | typedef ls_dummy *lsHandle; /* Handle to an item */ |
---|
| 23 | typedef int lsStatus; /* Return codes */ |
---|
| 24 | typedef void *lsGeneric; /* Generic pointer */ |
---|
| 25 | |
---|
| 26 | #define LS_NIL 0 /* Nil for lsList */ |
---|
| 27 | |
---|
| 28 | #define LS_BADSTATE -3 /* Bad generator state */ |
---|
| 29 | #define LS_BADPARAM -2 /* Bad parameter value */ |
---|
| 30 | #define LS_NOMORE -1 /* No more items */ |
---|
| 31 | |
---|
| 32 | #define LS_OK 0 |
---|
| 33 | |
---|
| 34 | #define LS_BEFORE 1 /* Set spot before object */ |
---|
| 35 | #define LS_AFTER 2 /* Set spot after object */ |
---|
| 36 | #define LS_STOP 3 /* Stop generating items */ |
---|
| 37 | #define LS_DELETE 4 /* Delete generated item */ |
---|
| 38 | |
---|
| 39 | /* |
---|
| 40 | * For all those routines that take a handle, this macro can be |
---|
| 41 | * used when no handle is required. |
---|
| 42 | */ |
---|
| 43 | |
---|
| 44 | #define LS_NH (lsHandle *) 0 |
---|
| 45 | |
---|
| 46 | typedef lsGeneric (*LS_PFLSG)(lsGeneric); |
---|
| 47 | |
---|
| 48 | EXTERN lsList lsCreate ARGS((void)); |
---|
| 49 | /* Create a new list */ |
---|
| 50 | EXTERN lsStatus lsDestroy ARGS((lsList, void (*)(lsGeneric))); |
---|
| 51 | /* Delete a previously created list */ |
---|
| 52 | EXTERN lsList lsCopy ARGS((lsList, LS_PFLSG)); |
---|
| 53 | /* Copies the contents of a list */ |
---|
| 54 | |
---|
| 55 | EXTERN lsStatus lsFirstItem ARGS((lsList, lsGeneric, lsHandle *)); |
---|
| 56 | /* Gets the first item of a list */ |
---|
| 57 | EXTERN lsStatus lsLastItem ARGS((lsList, lsGeneric, lsHandle *)); |
---|
| 58 | /* Gets the last item of a list */ |
---|
| 59 | |
---|
| 60 | EXTERN lsStatus lsNewBegin ARGS((lsList, lsGeneric, lsHandle *)); |
---|
| 61 | /* Add item to start of list */ |
---|
| 62 | EXTERN lsStatus lsNewEnd ARGS((lsList, lsGeneric, lsHandle *)); |
---|
| 63 | /* Add item to end of list */ |
---|
| 64 | |
---|
| 65 | EXTERN lsStatus lsDelBegin ARGS((lsList, lsGeneric)); |
---|
| 66 | /* Delete first item of a list */ |
---|
| 67 | EXTERN lsStatus lsDelEnd ARGS((lsList, lsGeneric)); |
---|
| 68 | /* Delete last item of a list */ |
---|
| 69 | |
---|
| 70 | EXTERN int lsLength ARGS((lsList)); |
---|
| 71 | /* Returns the length of the list */ |
---|
| 72 | |
---|
| 73 | EXTERN lsGen lsStart ARGS((lsList)); |
---|
| 74 | /* Begin generation of items in a list */ |
---|
| 75 | EXTERN lsGen lsEnd ARGS((lsList)); |
---|
| 76 | /* Begin generation at end of list */ |
---|
| 77 | EXTERN lsGen lsGenHandle ARGS((lsHandle, lsGeneric, int)); |
---|
| 78 | /* Produces a generator given a handle */ |
---|
| 79 | EXTERN lsStatus lsNext ARGS((lsGen, lsGeneric, lsHandle *)); |
---|
| 80 | /* Generate next item in sequence */ |
---|
| 81 | EXTERN lsStatus lsPrev ARGS((lsGen, lsGeneric, lsHandle *)); |
---|
| 82 | /* Generate previous item in sequence */ |
---|
| 83 | EXTERN lsStatus lsInBefore ARGS((lsGen, lsGeneric, lsHandle *)); |
---|
| 84 | /* Insert an item before the most recently generated by lsNext */ |
---|
| 85 | EXTERN lsStatus lsInAfter ARGS((lsGen, lsGeneric, lsHandle *)); |
---|
| 86 | /* Insert an item after the most recently generated by lsNext */ |
---|
| 87 | EXTERN lsStatus lsDelBefore ARGS((lsGen, lsGeneric)); |
---|
| 88 | /* Delete the item before the current spot */ |
---|
| 89 | EXTERN lsStatus lsDelAfter ARGS((lsGen, lsGeneric)); |
---|
| 90 | /* Delete the item after the current spot */ |
---|
| 91 | EXTERN lsStatus lsFinish ARGS((lsGen)); |
---|
| 92 | /* End generation of items in a list */ |
---|
| 93 | EXTERN lsStatus lsForeach ARGS((lsList list, lsStatus (*userFunc)(lsGeneric, lsGeneric), lsGeneric arg)); |
---|
| 94 | /* Generation of all items of a list from the first */ |
---|
| 95 | EXTERN lsStatus lsBackeach ARGS((lsList list, lsStatus (*userFunc)(lsGeneric, lsGeneric), lsGeneric arg)); |
---|
| 96 | /* Generation of all items of a list from the last */ |
---|
| 97 | |
---|
| 98 | EXTERN lsList lsQueryHandle ARGS((lsHandle)); |
---|
| 99 | /* Returns the list of a handle */ |
---|
| 100 | EXTERN lsGeneric lsFetchHandle ARGS((lsHandle)); |
---|
| 101 | /* Returns data associated with handle */ |
---|
| 102 | EXTERN lsStatus lsRemoveItem ARGS((lsHandle, lsGeneric)); |
---|
| 103 | /* Removes item associated with handle from list */ |
---|
| 104 | |
---|
| 105 | EXTERN lsStatus lsSort ARGS((lsList, int (*)(lsGeneric, lsGeneric))); |
---|
| 106 | |
---|
| 107 | /* Sorts a list */ |
---|
| 108 | EXTERN lsStatus lsUniq ARGS((lsList, int (*)(lsGeneric, lsGeneric), void (*)(lsGeneric) )); |
---|
| 109 | /* Removes duplicates from a sorted list */ |
---|
| 110 | /* |
---|
| 111 | * Macro to iterate the items of a list.Note the following: |
---|
| 112 | * 1) in a for loop, the test is evaluate before the first time through the body |
---|
| 113 | * 2) the logical OR operator guarantees left to right evaluation, and the second |
---|
| 114 | * operand is not evaluated if first operand evaluates to non-zero |
---|
| 115 | * 3) the comma operator returns the value of its second argument. |
---|
| 116 | */ |
---|
| 117 | #define lsForEachItem( \ |
---|
| 118 | list, /* lsList, list to iterate */ \ |
---|
| 119 | gen, /* lsGen, local variable for iterator */ \ |
---|
| 120 | data /* lsGeneric, variable to return data */ \ |
---|
| 121 | ) \ |
---|
| 122 | for(gen = lsStart(list); \ |
---|
| 123 | (lsNext(gen, &data, LS_NH) == LS_OK) \ |
---|
| 124 | || ((void) lsFinish(gen), 0); \ |
---|
| 125 | ) |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | #endif |
---|