/*
 * MandelVroom 2.0
 *
 * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
 *
 * All rights reserved.
 *
 * Permission is hereby granted to distribute this program's source
 * executable, and documentation for non-comercial purposes, so long as the
 * copyright notices are not removed from the sources, executable or
 * documentation.  This program may not be distributed for a profit without
 * the express written consent of the author Kevin L. Clague.
 *
 * This program is not in the public domain.
 *
 * Fred Fish is expressly granted permission to distribute this program's
 * source and executable as part of the "Fred Fish freely redistributable
 * Amiga software library."
 *
 * Permission is expressly granted for this program and it's source to be
 * distributed as part of the Amicus Amiga software disks, and the
 * First Amiga User Group's Hot Mix disks.
 *
 * contents: this file contains some routines to check for adding nodes to
 * lists twice, or removing nodes that are not in a list.
 */
#include <exec/lists.h>
#include <exec/nodes.h>

#undef AddHead
#undef Remove

extern BYTE FromWB;

safeAddHead( ListPtr, NodePtr, File, Line, Function )
  register struct List *ListPtr;
  register struct Node *NodePtr;
  char *File, *Function;
  int  Line;
{
  register struct Node *CurNode;

  CurNode = ListPtr->lh_Head;

  while ( CurNode->ln_Succ ) {

    if ( CurNode == NodePtr ) {
      if (! FromWB)
        printf("Error adding node to list twice\n in file %s, line %d, function %s\n",
                File, Line, Function);
      return;
    }

    CurNode = CurNode->ln_Succ;
  }
  AddHead( ListPtr, NodePtr );
}

safeRemove( NodePtr, File, Line, Function )
  register struct Node *NodePtr;
  char *File, *Function;
  int  Line;
{
  if (NodePtr->ln_Pred == NULL && !FromWB) {
      printf("Error Removing node when it'd not it list\n");
      printf("In File %s Line %d Function %s\n",File,Line,Function);
  } else {

    if (NodePtr->ln_Succ == NULL && !FromWB) {
      printf("Error Removing node when it'd not it list\n");
      printf("In File %s Line %d Function %s\n",File,Line,Function);
    }
  }

  Remove( NodePtr );

  NodePtr->ln_Pred = NULL;
  NodePtr->ln_Succ = NULL;
}



