int main( void ) { List *list = CreateList( ); node *n; int x = 17; int y = 18; int z = 19; InsertFront( list, &x, sizeof( int ) ); InsertFront( list, &y, sizeof( int ) ); InsertFront( list, &z, sizeof( int ) ); // Loop through list. It's important to use ListBegin and ListEnd for proper looping. // Make note of what pointers Begin and End return. for(n = ListBegin( list ); n != ListEnd( list ); n = n->next) printf( "%d\n", NODE_DATA( n, int ) ); // Proper way to delete nodes from list is like so: // note -- we are not doing n = n->next within the for loop, instead // we use the return value of delete for(n = ListBegin( list ); n != ListEnd( list );) n = DeleteNode( list, n ); getchar( ); return 0; }
/*------------------------------------------------------------------------ ------------------------- Execute the photoflo --------------------------- ------------------------------------------------------------------------*/ static Bool execute(floDefPtr flo, peTexPtr importer) { bandMsk ready; peTexPtr pet; peDefPtr ped; pedLstPtr lst = ListEmpty(&flo->optDAG) ? &flo->defDAG : &flo->optDAG; CARD32 sched_count = SCHED_BAIL_OUT; CARD32 strip_count = flo->floTex->putCnt; if(importer) { /* Put the ImportClient element at the head of the ready-list */ InsertMember(importer,&flo->floTex->schedHead); importer->scheduled = importer->receptor[IMPORT].ready; } do { /* execute elements from the head of the ready-list until it's empty * (calls to schedule from the data manager may prepend * additional elements to the ready-list) */ while(!ListEmpty(&flo->floTex->schedHead)) { pet = flo->floTex->schedHead.flink; if(Activate(flo,pet->peDef,pet) && (ready = runnable(flo,pet))) { pet->scheduled = ready; /* remember which bands keep us alive */ } else { /* element is no longer runnable, remove it and check for errors */ RemoveMember(pet,pet); pet->scheduled = 0; if(ferrCode(flo)) return(flo->flags.active = FALSE); } if(strip_count != flo->floTex->putCnt) { sched_count = SCHED_BAIL_OUT; strip_count = flo->floTex->putCnt; } else if( !--sched_count) ImplementationError(flo,pet->peDef, return(FALSE)); } /* Load all the elements onto the ready-list that can keep producing * output without requiring any additional input (e.g. ImportResource * elements). */ for(ped = lst->flink; !ListEnd(ped,lst); ped = ped->flink) if(ped->peTex->emitting && !ped->peTex->admissionCnt) InsertMember(ped->peTex,&flo->floTex->schedHead); /* * keep on trucking if there's nothing expected from the client */ } while(!flo->floTex->imports && !ListEmpty(&flo->floTex->schedHead)); /* if we still have stuff to do, count another round, otherwise shut it down */ if(flo->floTex->imports || flo->floTex->exports) ++flo->floTex->exitCnt; else ddShutdown(flo); return(flo->flags.active); } /* end execute */
void EmptyList( List *list ) { Node *n; for(n = ListBegin( list ); n != ListEnd( list ); ) { n = DeleteNode( list, n ); } }