2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
2011-02-25 09:50:54 -08:00
|
|
|
Copyright (C) 2005-2011 Warzone 2100 Project
|
2007-01-15 12:09:25 -08:00
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2006-09-25 09:46:28 -07:00
|
|
|
/*! \file listmacs.h
|
|
|
|
* \brief Macros for some simple list operations
|
2007-06-28 10:47:08 -07:00
|
|
|
*
|
|
|
|
* The parameters for the macros are :
|
|
|
|
*
|
|
|
|
* psHead the pointer to the start of the list
|
|
|
|
* psEntry the pointer to the list entry
|
|
|
|
* TYPE the type of the list structure (not a pointer to it)
|
|
|
|
*
|
|
|
|
*/
|
2008-11-09 14:58:04 -08:00
|
|
|
#ifndef __INCLUDED_LIB_FRAMEWORK_LISTMACS_H__
|
|
|
|
#define __INCLUDED_LIB_FRAMEWORK_LISTMACS_H__
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2008-11-09 14:58:04 -08:00
|
|
|
/**
|
|
|
|
* Append an entry to the end of a linked list
|
|
|
|
*/
|
|
|
|
#define LIST_APPEND(psHead, psEntry, TYPE) \
|
2007-06-28 10:47:08 -07:00
|
|
|
{ \
|
|
|
|
TYPE *psPrev, *psCurr; \
|
|
|
|
\
|
2008-11-09 14:58:04 -08:00
|
|
|
/* Find the end of the list */ \
|
2007-06-28 10:47:08 -07:00
|
|
|
psPrev = NULL; \
|
|
|
|
for(psCurr = (psHead); psCurr; psCurr = psCurr->psNext) \
|
|
|
|
{ \
|
|
|
|
psPrev = psCurr; \
|
|
|
|
} \
|
2008-11-09 14:58:04 -08:00
|
|
|
\
|
|
|
|
(psEntry)->psNext = NULL; \
|
|
|
|
\
|
2007-06-28 10:47:08 -07:00
|
|
|
if (psPrev) \
|
|
|
|
{ \
|
2008-11-09 14:58:04 -08:00
|
|
|
/* Append to the end */ \
|
2007-06-28 10:47:08 -07:00
|
|
|
psPrev->psNext = (psEntry); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
2008-11-09 14:58:04 -08:00
|
|
|
/* If a NULL list got passed, make this item the list */ \
|
2007-06-28 10:47:08 -07:00
|
|
|
(psHead) = (psEntry); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2008-11-09 14:58:04 -08:00
|
|
|
/**
|
|
|
|
* Remove an entry from a linked list
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
#define LIST_REMOVE(psHead, psEntry, TYPE) \
|
|
|
|
{ \
|
|
|
|
TYPE *psPrev, *psCurr; \
|
|
|
|
\
|
|
|
|
psPrev = NULL; \
|
|
|
|
for(psCurr = (psHead); psCurr; psCurr = psCurr->psNext) \
|
|
|
|
{ \
|
|
|
|
if (psCurr == (psEntry)) \
|
|
|
|
{ \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
psPrev = psCurr; \
|
|
|
|
} \
|
2008-11-09 14:58:04 -08:00
|
|
|
ASSERT(psCurr != NULL, "LIST_REMOVE: entry not found"); \
|
2007-06-28 10:47:08 -07:00
|
|
|
if (psPrev == NULL) \
|
|
|
|
{ \
|
|
|
|
(psHead) = (psHead)->psNext; \
|
|
|
|
} \
|
|
|
|
else if (psCurr != NULL) \
|
|
|
|
{ \
|
|
|
|
psPrev->psNext = psCurr->psNext; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2008-11-09 14:58:04 -08:00
|
|
|
#endif // __INCLUDED_LIB_FRAMEWORK_LISTMACS_H__
|