home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
177.lha
/
DRes_v1.3
/
docs
/
lists.doc
< prev
next >
Wrap
Text File
|
1988-04-28
|
6KB
|
165 lines
LISTS.DOC
These are general list handling routines that should have been provided
in EXEC. In addition to basic additions, I provide support for structures
whos Nodes are not at the base of the structure. These are the infamous
'sptr's below. Such routines take a pointer to the structure, add an
offset to it to get to the Node, do the specified operation, then subtract
the offset to return to the 'sptr's actual base. In otherwords, it allows
you to deal with such structures without having to do these hacks in your
source.
GetHead GetHead
GetSucc GetSucc
node = GetHead(list)
node = GetSucc(node) (physically the same routine as GetHead()).
This routine returns the successor of a node in the list. If a list is
specified, the first node in the list is returned. NULL is returned if
the list is empty or one has reached the end of the list.
GetTail GetTail
node = GetTail(list)
This routine returns the last node in the list, or NULL if the list
is empty.
GetPred GetPred
node = GetPred(node)
This routine returns the previous node from the given node, or NULL
if we are at the head of the list.
GetHeadOff GetHeadOff
sptr = GetHeadOff(list, offset)
This routine retrieves the first node in the list and subtracts the
specified offset to get to the base of the structure (where 'offset'
is the offset into the structure where the Node has been placed rather
than placing it as the first object in the structure).
NULL is returned is the list is empty. NOTE! Unlike GetHead(), only
a valid list pointer may be specified here.
GetTailOff GetTailOff
sptr = GetTailOff(list, offset)
This routine works the same as GetHeadOff() but works on the last
node in the list.
GetSuccOff GetSuccOff
sptr = GetSuccOff(sptr, offset)
Given a structure pointer where the Node is offset from the structure
base, add the offset to the pointer, determine the successor if any,
then subtract the offset from the successor to get back to the
structure base for the successor.
NULL is returned if there is no successor.
GetPredOff GetPredOff
sptr = GetPredOff(sptr, offset)
This routine works the same as GetSuccOff() but works on the previous
node rather than the next. NULL is returned if we are at the head
of the list;
EnqueueLong EnqueueLong
(void) EnqueueLong(list, startnode, node, valoff)
This routine queues a node into a list beginning its search at the
startnode (first element if startnode == NULL). The list is assumed
to be sorted by the longword valoff from the node structure. I.E.
If you had a graphic structure with a Node at its base and where
coordinates were stored in longwords, you insert nodes sorted by
one of the coordinates into a list.
valoff is the offset from the node base where the longword value
the list is sorted by exists.
EnqueueOffLong EnqueueOffLong
(void) EnqueueOffLong(list, startnode, sptr, off, valoff)
This works just like EnqueueLong() but an extra parameter, 'off', is
provided to inform the routine where in the structure the Node is.
Does that make sense?
SearchFwdNode SearchFwdNode
retval = SearchFwdNode(node, function, arg)
MINNODE *node;
long (*function)();
long arg;
This routine searches a list in the forward direction beginning at
the specified node, calling the function vector for every node. The
function is called C-fashion (A4 and A5 are intact to support the
small code model and D2/D3 may be destroyed in addition to standard
scratch variables to support Aztec C). The function is given two
arguments: the node, and the arg passed to SearchFwdNode():
(*function)(current_srch_node, arg)
The search is terminated if the function vector returns a non-zero
value. If the search reaches the end of the list, NULL is returned.
NOTE: you may pass a NULL as the node to SearchFwdNode() which results
in a NULL being immediately returned.
SearchRvsNode SearchRvsNode
retval = SearchFwdNode(node, function, arg)
This function works exactly the same as SearchFwdNode() but works
in reverse begining at the specified node.
SearchFwdList SearchFwdList
retval = SearchFwdList(list, function, arg)
This function works exactly the same as SearchFwdNode() but you give
it a pointer to a list rather than to a node.
A valid list pointer must be specified, but the list may be empty.
SearchRvsList SearchRvsList
retval = SearchRvsList(list, function, arg)
This function works exactly the same as SearchRvsNode() but you give
it a pointer to a list rather than to a node.
A valid list pointer must be specified, but the list may be empty.
SearchFwdNodeOff SearchFwdNodeOff
SearchRvsNodeOff SearchRvsNodeOff
SearchFwdListOff SearchFwdListOff
SearchRvsListOff SearchRvsListOff
rval = SearchFwdNodeOff(sptr, function, off, arg)
rval = SearchRvsNodeOff(sptr, function, off, arg)
rval = SearchFwdListOff(list, function, off, arg)
rval = SearchRvsListOff(list, function, off, arg)
These routines work like those shown above, but an additional
argument, an offset, is supplied. This is the offset into the
structure pointer where the Node structure is embedded. In otherwords,
the other routines were simply special cases of this one with off == 0.
Note that for *NodeOff() routines a pointer to a structure containing
the Node structure in it somewhere is supplied, whereas in the
*ListOff() routines a pointer to the list base is given (this hasn't
changed).