Inserting and removing entities in lists
Several functions are provided for inserting and removing entities in lists. You cannot have an entity in more than one list at a time. You can insert and remove entities into lists using the functions in the table below.
| Function | Description | 
|---|---|
| csptls | Insert the entity into the list at the proper position for the ordering defined on the list. | 
| cspols | Put the entity on the list using a one-time ordering, as when putting an entity at the head of the list regardless of the list ordering. | 
| csppls | Insert the entity prior to a certain entity already in the list. | 
| cspfls | Insert the entity following a certain entity already in the list. | 
| csgtls | Remove by an entity’s position in the list. | 
| csgpls | Remove by a pointer to the entity. | 
The following example illustrates the way entities are inserted and removed from a list. This function builds a list of materials which have a quantity on hand below some threshold. It then passes the list to a function named “process” to do some processing of the information in the list. Finally, the function empties and deletes the list.
typedef struct 
{
   MATL *mp;   /* Pointer to a material. */
}UCMATL;
#define UCTHOLD 100.0
void lowqoh()
{
   MATL    *mp;
   CSLIST   *lp;
   UCMATL   *ucp, *nucp;
   lp = CSMXLS("", CSFIFO, NULL);
   for ( mp = (MATL *)csfsls(SSGVAR.sgmatl);
      mp != NULL;
      mp = (MATL *)csnxls(CSENTITY *mp)) 
   {
    if ( mp->mtqoh <= UCTHOLD ) 
    {
        ucp = CSNEW(UCMATL);
        ucp->mp = mp;
        csptls(lp, CSENTITY *ucp);
    }
   }
   process(lp);
   for ( ucp = (UCMATL *)csfsls(lp);
      ucp != NULL;
      ucp = nucp) 
   {
      nucp = (UCMATL *)csnxls(CSENTITY *ucp);
      csgpls(lp,ucp);
      csterm(ucp);
   }
   csdlls(lp);
}