* 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"
+DEFINE_MTYPE_STATIC(LIB, LINK_LIST, "Link List")
+DEFINE_MTYPE_STATIC(LIB, LINK_NODE, "Link Node")
+
/* Allocate new list. */
struct list *
list_new (void)
list->count++;
}
-void
+struct listnode *
listnode_add_after (struct list *list, struct listnode *pp, void *val)
{
struct listnode *nn;
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
listnode_free (node);
}
-/* ospf_spf.c */
-void
-list_add_node_prev (struct list *list, struct listnode *current, void *val)
-{
- struct listnode *node;
-
- assert (val != NULL);
-
- 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 (struct list *list, struct listnode *current, void *val)
-{
- struct listnode *node;
-
- assert (val != NULL);
-
- 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
list_add_list (struct list *l, struct list *m)