eyBuildLib API Reference : eyBuildLib

eblist

NAME

eblist - link list operate lib

ROUTINES

lstInit( ) - initialize a list descriptor
lstInsert( ) - insert a node in a list after a specified node
lstAdd( ) - add a node to the end of a list
lstConcat( ) - concatenate two lists
lstDelete( ) - delete a specified node from a list
lstExtract( ) - extract a sublist from a list
lstCount( ) - report the number of nodes in a list
lstFirst( ) - find first node in list
lstLast( ) - find the last node in a list
lstPrevious( ) - find the previous node in a list
lstNext( ) - find the next node in a list
lstNth( ) - find the Nth node in a list
lstNStep( ) - find a list node nStep steps away from a specified node
lstFind( ) - find a node in a list
lstFree( ) - free up a list
lstForEach( ) - done user hook for each list node

DESCRIPTION

This subroutine library supports the creation and maintenance of a doubly linked list. The user supplies a list descriptor (type LIST) that will contain pointers to the first and last nodes in the list, and a count of the number of nodes in the list. The nodes in the list can be any user-defined structure, but they must reserve space for two pointers as their first elements. Both the forward and backward chains are terminated with a NULL pointer.

NON-EMPTY LIST

   ---------             --------          --------
   | head--------------->| next----------->| next---------
   |       |             |      |          |      |      |
   |       |       ------- prev |<---------- prev |      |
   |       |       |     |      |          |      |      |
   | tail------    |     | ...  |    ----->| ...  |      |
   |       |  |    v                 |                   v
   |count=2|  |  -----               |                 -----
   ---------  |   ---                |                  ---
              |    -                 |                   -
              |                      |
              ------------------------

EMPTY LIST

        -----------
        |  head------------------
        |         |             |
        |  tail----------       |
        |         |     |       v
        | count=0 |   -----   -----
        -----------    ---     ---
                        -       -

NOTE

this libarary realized a "VxWorks lstLib" like operation APIs, but not a copy of "VxWorks lstLib". you can traverse the list with lstForEach( ) to process each node.

INCLUDE FILES

eblist.h


eyBuildLib : Routines

lstInit( )

NAME

lstInit( ) - initialize a list descriptor

SYNOPSIS

void lstInit
    (
    LIST * plst
    )

DESCRIPTION

This routine initializes a specified list to an empty list.

RETURNS

N/A

SEE ALSO

eblist


eyBuildLib : Routines

lstInsert( )

NAME

lstInsert( ) - insert a node in a list after a specified node

SYNOPSIS

void lstInsert
    (
    LIST * plst,              /* pointer to list descriptor */
    NODE * pPrev,             /* pointer to node after which to insert */
    NODE * pnode              /* pointer to node to be inserted */
    )

DESCRIPTION

This routine inserts a specified node in a specified list. The new node is placed following the list node pPrev. If pPrev is NULL, the node is inserted at the head of the list.

RETURNS

N/A

SEE ALSO

eblist


eyBuildLib : Routines

lstAdd( )

NAME

lstAdd( ) - add a node to the end of a list

SYNOPSIS

void lstAdd
    (
    LIST * plst,              /* pointer to list descriptor */
    NODE * pnode              /* new node to add */
    )

DESCRIPTION

This routine adds a specified node to the end of a specified list.

RETURNS

N/A

SEE ALSO

eblist


eyBuildLib : Routines

lstConcat( )

NAME

lstConcat( ) - concatenate two lists

SYNOPSIS

void lstConcat
    (
    LIST * pdst,              /* destination list */
    LIST * psrc               /* list to be added to dstList */
    )

DESCRIPTION

This routine concatenates the second list to the end of the first list. The second list is left empty. Either list (or both) can be empty at the beginning of the operation.

RETURNS

N/A

SEE ALSO

eblist


eyBuildLib : Routines

lstDelete( )

NAME

lstDelete( ) - delete a specified node from a list

SYNOPSIS

void lstDelete
    (
    LIST * plst,              /* pointer to list descriptor */
    NODE * pnode              /* pointer to node to be deleted */
    )

DESCRIPTION

This routine deletes a specified node from a specified list. It will not free the node memory space.

RETURNS

N/A

SEE ALSO

eblist


eyBuildLib : Routines

lstExtract( )

NAME

lstExtract( ) - extract a sublist from a list

SYNOPSIS

void lstExtract
    (
    LIST * psrc,              /* pointer to source list */
    NODE * pstart,            /* first node in sublist to be extracted */
    NODE * pend,              /* last node in sublist to be extracted */
    LIST * pdst               /* ptr to list where to put extracted list */
    )

DESCRIPTION

This routine extracts the sublist that starts with pStartNode and ends with pEndNode from a source list. It places the extracted list in pDstList.

RETURNS

N/A

SEE ALSO

eblist


eyBuildLib : Routines

lstCount( )

NAME

lstCount( ) - report the number of nodes in a list

SYNOPSIS

int lstCount
    (
    LIST * plst               /* pointer to list descriptor */
    )

DESCRIPTION

This routine returns the number of nodes in a specified list.

RETURNS

The number of nodes in the list.

SEE ALSO

eblist


eyBuildLib : Routines

lstFirst( )

NAME

lstFirst( ) - find first node in list

SYNOPSIS

NODE * lstFirst
    (
    LIST * plst               /* pointer to list descriptor */
    )

DESCRIPTION

This routine finds the first node in a linked list.

RETURNS

A pointer to the first node in a list, or NULL if the list is empty.

SEE ALSO

eblist


eyBuildLib : Routines

lstLast( )

NAME

lstLast( ) - find the last node in a list

SYNOPSIS

NODE * lstLast
    (
    LIST * plst               /* pointer to list descriptor */
    )

DESCRIPTION

This routine finds the last node in a list.

RETURNS

A pointer to the last node in the list, or NULL if the list is empty.

SEE ALSO

eblist


eyBuildLib : Routines

lstPrevious( )

NAME

lstPrevious( ) - find the previous node in a list

SYNOPSIS

NODE * lstPrevious
    (
    NODE * pnode              /* ptr to node whose predecessor is to be found */
    )

DESCRIPTION

This routine locates the node immediately preceding the node pointed to by pNode.

RETURNS

A pointer to the previous node in the list, or NULL if there is no previous node.

SEE ALSO

eblist


eyBuildLib : Routines

lstNext( )

NAME

lstNext( ) - find the next node in a list

SYNOPSIS

NODE * lstNext
    (
    NODE * pnode              /* ptr to node whose successor is to be found */
    )

DESCRIPTION

This routine locates the node immediately following a specified node.

RETURNS

A pointer to the next node in the list, or NULL if there is no next node.

SEE ALSO

eblist


eyBuildLib : Routines

lstNth( )

NAME

lstNth( ) - find the Nth node in a list

SYNOPSIS

NODE * lstNth
    (
    LIST * plst,              /* pointer to list descriptor */
    int    nodenum            /* number of node to be found */
    )

DESCRIPTION

This routine returns a pointer to the node specified by a number nodenum where the first node in the list is numbered 1. Note that the search is optimized by searching forward from the beginning; if the node is closer to the head, and searching back from the end; if it is closer to the tail.

RETURNS

A pointer to the Nth node, or NULL if there is no Nth node.

SEE ALSO

eblist


eyBuildLib : Routines

lstNStep( )

NAME

lstNStep( ) - find a list node nStep steps away from a specified node

SYNOPSIS

NODE * lstNStep
    (
    NODE * pnode,             /* the known node */
    int    nstep              /* number of steps away to find */
    )

DESCRIPTION

This routine locates the node nStep steps away in either direction from a specified node. If nStep is positive, it steps toward the tail. If nStep is negative, it steps toward the head. If the number of steps is out of range, NULL is returned.

RETURNS

A pointer to the node nStep steps away, or NULL if the node is out of range.

SEE ALSO

eblist


eyBuildLib : Routines

lstFind( )

NAME

lstFind( ) - find a node in a list

SYNOPSIS

int lstFind
    (
    LIST * plst,              /* list in which to search */
    NODE * pnode              /* pointer to node to search for */
    )

DESCRIPTION

This routine returns the node number of a specified node (the first node is 1).

RETURNS

The node number, or ERROR if the node is not found.

SEE ALSO

eblist


eyBuildLib : Routines

lstFree( )

NAME

lstFree( ) - free up a list

SYNOPSIS

void lstFree
    (
    LIST * plst               /* list for which to free all nodes */
    )

DESCRIPTION

This routine turns any list into an empty list. It also frees up memory used for nodes.

RETURNS

N/A

SEE ALSO

eblist, free( )


eyBuildLib : Routines

lstForEach( )

NAME

lstForEach( ) - done user hook for each list node

SYNOPSIS

void lstForEach
    (
    LIST *       plst,        /* pointer to list descriptor */
    int          order,       /* 0: from head to tail, !0 reverse */
    FUN_FOR_EACH done,        /* for each hook */
    void *       cookie,      /* hook parameter */
                 ...
    )

DESCRIPTION

This routine is to done user hook for each list node

NOTE

usually, you can at most transfer 4 parameter to done hook.

RETURN

N/A

SEE ALSO

eblist