Use typedefs for the types of the functions that are passed as arguments
to the list functions for better readability. Submitted by: Max Okumoto <okumoto@ucsd.edu>
This commit is contained in:
parent
ac06cb0ad3
commit
1734fd27b4
@ -293,6 +293,6 @@ For_Run(int lineno)
|
||||
Lst_ForEach(arg.lst, ForExec, (void *) &arg);
|
||||
|
||||
free(arg.var);
|
||||
Lst_Destroy(arg.lst, (void (*)(void *)) free);
|
||||
Lst_Destroy(arg.lst, free);
|
||||
Buf_Destroy(arg.buf, TRUE);
|
||||
}
|
||||
|
@ -93,13 +93,18 @@ struct Lst {
|
||||
};
|
||||
typedef struct Lst *Lst;
|
||||
|
||||
typedef int CompareProc(void *, void *);
|
||||
typedef int DoProc(void *, void *);
|
||||
typedef void *DuplicateProc(void *);
|
||||
typedef void FreeProc(void *);
|
||||
|
||||
/*
|
||||
* NOFREE can be used as the freeProc to Lst_Destroy when the elements are
|
||||
* not to be freed.
|
||||
* NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
|
||||
*/
|
||||
#define NOFREE ((void (*)(void *)) 0)
|
||||
#define NOCOPY ((void * (*)(void *)) 0)
|
||||
#define NOFREE ((FreeProc *)NULL)
|
||||
#define NOCOPY ((DuplicateProc *)NULL)
|
||||
|
||||
#define LST_CONCNEW 0 /* create new LstNode's when using Lst_Concat */
|
||||
#define LST_CONCLINK 1 /* relink LstNode's when using Lst_Concat */
|
||||
@ -110,9 +115,9 @@ typedef struct Lst *Lst;
|
||||
/* Create a new list */
|
||||
Lst Lst_Init(Boolean);
|
||||
/* Duplicate an existing list */
|
||||
Lst Lst_Duplicate(Lst, void * (*)(void *));
|
||||
Lst Lst_Duplicate(Lst, DuplicateProc *);
|
||||
/* Destroy an old one */
|
||||
void Lst_Destroy(Lst, void (*)(void *));
|
||||
void Lst_Destroy(Lst, FreeProc *);
|
||||
|
||||
/*
|
||||
* Functions to modify a list
|
||||
@ -148,22 +153,22 @@ void * Lst_Datum(LstNode);
|
||||
* Functions for entire lists
|
||||
*/
|
||||
/* Find an element in a list */
|
||||
LstNode Lst_Find(Lst, void *, int (*)(void *, void *));
|
||||
LstNode Lst_Find(Lst, void *, CompareProc *);
|
||||
/* Find an element starting from somewhere */
|
||||
LstNode Lst_FindFrom(Lst, LstNode, void *, int (*cProc)(void *, void *));
|
||||
LstNode Lst_FindFrom(Lst, LstNode, void *, CompareProc *);
|
||||
/*
|
||||
* See if the given datum is on the list. Returns the LstNode containing
|
||||
* the datum
|
||||
*/
|
||||
LstNode Lst_Member(Lst, void *);
|
||||
/* Apply a function to all elements of a lst */
|
||||
void Lst_ForEach(Lst, int (*)(void *, void *), void *);
|
||||
void Lst_ForEach(Lst, DoProc *, void *);
|
||||
/*
|
||||
* Apply a function to all elements of a lst starting from a certain point.
|
||||
* If the list is circular, the application will wrap around to the
|
||||
* beginning of the list again.
|
||||
*/
|
||||
void Lst_ForEachFrom(Lst, LstNode, int (*)(void *, void *), void *);
|
||||
void Lst_ForEachFrom(Lst, LstNode, DoProc *, void *);
|
||||
/*
|
||||
* these functions are for dealing with a list as a table, of sorts.
|
||||
* An idea of the "current element" is kept and used by all the functions
|
||||
|
@ -65,7 +65,7 @@ __FBSDID("$FreeBSD$");
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Lst_Destroy(Lst list, void (*freeProc)(void *))
|
||||
Lst_Destroy(Lst list, FreeProc *freeProc)
|
||||
{
|
||||
LstNode ln;
|
||||
LstNode tln = NULL;
|
||||
|
@ -68,7 +68,7 @@ __FBSDID("$FreeBSD$");
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
Lst
|
||||
Lst_Duplicate(Lst list, void *(*copyProc)(void *))
|
||||
Lst_Duplicate(Lst list, DuplicateProc *copyProc)
|
||||
{
|
||||
Lst nl;
|
||||
LstNode ln;
|
||||
|
@ -64,7 +64,7 @@ __FBSDID("$FreeBSD$");
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
LstNode
|
||||
Lst_Find(Lst l, void *d, int (*cProc)(void *, void *))
|
||||
Lst_Find(Lst l, void *d, CompareProc *cProc)
|
||||
{
|
||||
|
||||
return (Lst_FindFrom (l, Lst_First(l), d, cProc));
|
||||
|
@ -65,7 +65,7 @@ __FBSDID("$FreeBSD$");
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
LstNode
|
||||
Lst_FindFrom(Lst l, LstNode ln, void *d, int (*cProc)(void *, void *))
|
||||
Lst_FindFrom(Lst l, LstNode ln, void *d, CompareProc *cProc)
|
||||
{
|
||||
LstNode tln;
|
||||
Boolean found = FALSE;
|
||||
|
@ -65,7 +65,7 @@ __FBSDID("$FreeBSD$");
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Lst_ForEach(Lst l, int (*proc)(void *, void *), void *d)
|
||||
Lst_ForEach(Lst l, DoProc *proc, void *d)
|
||||
{
|
||||
|
||||
Lst_ForEachFrom(l, Lst_First(l), proc, d);
|
||||
|
@ -66,7 +66,7 @@ __FBSDID("$FreeBSD$");
|
||||
*-----------------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
Lst_ForEachFrom(Lst list, LstNode ln, int (*proc)(void *, void *), void *d)
|
||||
Lst_ForEachFrom(Lst list, LstNode ln, DoProc *proc, void *d)
|
||||
{
|
||||
LstNode next;
|
||||
Boolean done;
|
||||
|
@ -874,7 +874,7 @@ main(int argc, char **argv)
|
||||
|
||||
Lst_Destroy(variables, NOFREE);
|
||||
Lst_Destroy(makefiles, NOFREE);
|
||||
Lst_Destroy(create, (void (*)(void *)) free);
|
||||
Lst_Destroy(create, free);
|
||||
|
||||
/* print the graph now it's been processed if the user requested it */
|
||||
if (DEBUG(GRAPH2))
|
||||
|
@ -2536,7 +2536,7 @@ Parse_Init (void)
|
||||
void
|
||||
Parse_End (void)
|
||||
{
|
||||
Lst_Destroy(targCmds, (void (*)(void *)) free);
|
||||
Lst_Destroy(targCmds, free);
|
||||
if (targets)
|
||||
Lst_Destroy(targets, NOFREE);
|
||||
Lst_Destroy(sysIncPath, Dir_Destroy);
|
||||
|
Loading…
Reference in New Issue
Block a user