* 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 GNU Zebra; see the file COPYING. If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "linklist.h"
#include "memory.h"
-\f
+
+DEFINE_MTYPE_STATIC(LIB, LINK_LIST, "Link List")
+DEFINE_MTYPE_STATIC(LIB, LINK_NODE, "Link Node")
+
/* Allocate new list. */
struct list *
-list_new ()
+list_new (void)
{
- struct list *new;
-
- new = XMALLOC (MTYPE_LINK_LIST, sizeof (struct list));
- memset (new, 0, sizeof (struct list));
- return new;
+ return XCALLOC (MTYPE_LINK_LIST, sizeof (struct list));
}
/* Free list. */
/* Allocate new listnode. Internal use only. */
static struct listnode *
-listnode_new ()
+listnode_new (void)
{
- struct listnode *node;
-
- node = XMALLOC (MTYPE_LINK_NODE, sizeof (struct listnode));
- memset (node, 0, sizeof (struct listnode));
- return node;
+ return XCALLOC (MTYPE_LINK_NODE, sizeof (struct listnode));
}
/* Free listnode. */
{
XFREE (MTYPE_LINK_NODE, node);
}
-\f
+
/* Add new data to the list. */
void
listnode_add (struct list *list, void *val)
{
struct listnode *node;
-
+
+ assert (val != NULL);
+
node = listnode_new ();
node->prev = list->tail;
{
struct listnode *n;
struct listnode *new;
-
+
+ assert (val != NULL);
+
new = listnode_new ();
new->data = val;
list->count++;
}
-void
+struct listnode *
listnode_add_after (struct list *list, struct listnode *pp, void *val)
{
struct listnode *nn;
-
+
+ assert (val != NULL);
+
nn = listnode_new ();
nn->data = val;
pp->next = nn;
}
+ list->count++;
+ return nn;
}
+struct listnode *
+listnode_add_before (struct list *list, struct listnode *pp, void *val)
+{
+ struct listnode *nn;
+
+ assert (val != NULL);
+
+ nn = listnode_new ();
+ nn->data = val;
+
+ if (pp == NULL)
+ {
+ if (list->tail)
+ list->tail->next = nn;
+ else
+ list->head = nn;
+
+ nn->prev = list->tail;
+ nn->next = pp;
+
+ list->tail = nn;
+ }
+ else
+ {
+ if (pp->prev)
+ pp->prev->next = nn;
+ else
+ list->head = nn;
+
+ nn->prev = pp->prev;
+ nn->next = pp;
+
+ pp->prev = nn;
+ }
+ list->count++;
+ return nn;
+}
+
+/* Move given listnode to tail of the list */
+void
+listnode_move_to_tail (struct list *l, struct listnode *n)
+{
+ LISTNODE_DETACH(l,n);
+ LISTNODE_ATTACH(l,n);
+}
/* Delete specific date pointer from the list. */
void
void
list_delete (struct list *list)
{
- struct listnode *node;
- struct listnode *next;
-
assert(list);
- for (node = list->head; node; node = next)
- {
- next = node->next;
- if (list->del)
- (*list->del) (node->data);
- listnode_free (node);
- }
+ list_delete_all_node (list);
list_free (list);
}
struct listnode *
listnode_lookup (struct list *list, void *data)
{
- listnode node;
+ struct listnode *node;
assert(list);
- for (node = list->head; node; nextnode (node))
- if (data == getdata (node))
+ for (node = listhead(list); node; node = listnextnode (node))
+ if (data == listgetdata (node))
return node;
return NULL;
}
-\f
+
/* Delete the node from list. For ospfd and ospf6d. */
void
-list_delete_node (list list, listnode node)
+list_delete_node (struct list *list, struct listnode *node)
{
if (node->prev)
node->prev->next = node->next;
list->count--;
listnode_free (node);
}
-\f
-/* ospf_spf.c */
-void
-list_add_node_prev (list list, listnode current, void *val)
-{
- struct listnode *node;
-
- node = listnode_new ();
- node->next = current;
- node->data = val;
-
- if (current->prev == NULL)
- list->head = node;
- else
- current->prev->next = node;
-
- node->prev = current->prev;
- current->prev = node;
-
- list->count++;
-}
-
-/* ospf_spf.c */
-void
-list_add_node_next (list list, listnode current, void *val)
-{
- struct listnode *node;
-
- node = listnode_new ();
- node->prev = current;
- node->data = val;
-
- if (current->next == NULL)
- list->tail = node;
- else
- current->next->prev = node;
-
- node->next = current->next;
- current->next = node;
-
- list->count++;
-}
/* ospf_spf.c */
void
{
struct listnode *n;
- for (n = listhead (m); n; nextnode (n))
+ for (n = listhead (m); n; n = listnextnode (n))
listnode_add (l, n->data);
}