Пример #1
0
/*---------------------------------------------------------------------------*/
csr_list_result csr_list_remove(csr_list* list, csr_list_node* node)
{
    require(TR_CSR_LIST, list != NULL);
    require(TR_CSR_LIST, node != NULL);
    require(TR_CSR_LIST, isInList(list, node) != NULL); /*lint !e666 */

    if (list->head == node)
    {
        list->head = node->next;
        if (list->head == NULL)
        {
            list->tail = NULL;
        }
        DELETE_NODE(node);
    }
    else
    {
        csr_list_node* prevnode = findPrevNode(list, node);
        if (prevnode == NULL)
        {
            return csr_list_not_found;
        }
        prevnode->next = node->next;
        if (prevnode->next == NULL)
        {
            list->tail = prevnode;
        }
        DELETE_NODE(node);
    }
    list->count--;
    return csr_list_success;
}
Пример #2
0
/*---------------------------------------------------------------------------*/
void csr_list_remove_tail(csr_list* list)
{
    csr_list_node* curr = list->head;
    csr_list_node* prev = NULL;

    require(TR_CSR_LIST, list != NULL);

    if (list->head != NULL)
    {
        while (curr->next != NULL)
        {
            prev = curr;
            curr = curr->next;
        }

        /* delete the node */
        DELETE_NODE(curr);

        /* and update the previous node to be tail */
        if (prev)
        {
            prev->next = NULL;
        }

        /* update the list tail */
        list->tail = prev;
        list->count--;
    }
}
Пример #3
0
/* test for unused nodes - adds supports for these nodes */
void md_idiotproof_nodes(void)
{
  int used = 0 ;
  int i,j ;
  
  for (i=0; i<n_len; i++)
  {
    used = 0 ;

    for (j=0; j<e_len; j++)
    {
      if ((GET_ELEM_N1(j) == i) || (GET_ELEM_N2(j) == i))
      {
        used = 1 ; 
        break ;
      }
    }

    if (used == 0)
    {
      DELETE_NODE(i) ;
      i-- ;
    }
  }
}
Пример #4
0
	void XMLNode::DeleteChildren()
	{
		while( _firstChild ) {
			XMLNode* node = _firstChild;
			Unlink( node );

			DELETE_NODE( node );
		}
		_firstChild = _lastChild = 0;
	}
Пример #5
0
/*---------------------------------------------------------------------------*/
void csr_list_clear(csr_list* list)
{
    require(TR_CSR_LIST, list != NULL);

    while(list->head != NULL)
    {
        csr_list_node* node = list->head;
        list->head = list->head->next;
        DELETE_NODE(node);
    }

    csr_list_init(list);
}
Пример #6
0
	char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
	{
		// This is a recursive method, but thinking about it "at the current level"
		// it is a pretty simple flat list:
		//		<foo/>
		//		<!-- comment -->
		//
		// With a special case:
		//		<foo>
		//		</foo>
		//		<!-- comment -->
		//
		// Where the closing element (/foo) *must* be the next thing after the opening
		// element, and the names must match. BUT the tricky bit is that the closing
		// element will be read by the child.
		//
		// 'endTag' is the end tag for this node, it is returned by a call to a child.
		// 'parentEnd' is the end tag for the parent, which is filled in and returned.

		while( p && *p ) {
			XMLNode* node = 0;

			p = _document->Identify( p, &node );
			if ( p == 0 || node == 0 ) {
				break;
			}

			StrPair endTag;
			p = node->ParseDeep( p, &endTag );
			if ( !p ) {
				DELETE_NODE( node );
				node = 0;
				if ( !_document->Error() ) {
					_document->SetError( XML_ERROR_PARSING, 0, 0 );
				}
				break;
			}

			// We read the end tag. Return it to the parent.
			if ( node->ToElement() && node->ToElement()->ClosingType() == XMLElement::CLOSING ) {
				if ( parentEnd ) {
					*parentEnd = static_cast<XMLElement*>(node)->_value;
				}
				node->_memPool->SetTracked();	// created and then immediately deleted.
				DELETE_NODE( node );
				return p;
			}

			// Handle an end tag returned to this level.
			// And handle a bunch of annoying errors.
			XMLElement* ele = node->ToElement();
			if ( ele ) {
				if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) {
					_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );
					p = 0;
				}
				else if ( !endTag.Empty() && ele->ClosingType() != XMLElement::OPEN ) {
					_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );
					p = 0;
				}
				else if ( !endTag.Empty() ) {
					if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() )) {
						_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );
						p = 0;
					}
				}
			}
			if ( p == 0 ) {
				DELETE_NODE( node );
				node = 0;
			}
			if ( node ) {
				this->InsertEndChild( node );
			}
		}
		return 0;
	}
Пример #7
0
	void XMLNode::DeleteChild( XMLNode* node )
	{
		TIXMLASSERT( node->_parent == this );
		DELETE_NODE( node );
	}
Пример #8
0
Файл: tree.c Проект: rforge/rcwb
/**
 * Deletes an evaluation tree with the depth-first method.
 *
 * @param etptr  The evaluation tree to delete.
 */
void
free_evaltree(Evaltree *etptr)
{
  if ((*etptr) != NULL) {
    /* is the current node an operator node? */
    
    switch ((*etptr)->node.type) {

    case node:
      switch((*etptr)->node.op_id) {
        
        /* delete the binary operator nodes: two children. */
      case re_od_concat:
      case re_oi_concat:
      case re_disj:
        assert((*etptr)->node.left != NULL);   /* the left child must exist  */
        free_evaltree(&((*etptr)->node.left)); /* delete the left child      */
        assert((*etptr)->node.right != NULL);  /* the right child must exit  */
        free_evaltree(&((*etptr)->node.right));/* delete the right child     */
        DELETE_NODE((*etptr));                 /* delete the current op node */
        break;
        
        /* delete the unary operator nodes: one children. */
      case re_repeat:
        free_evaltree(&((*etptr)->node.left)); /* delete the left child      */
        DELETE_NODE((*etptr));                 /* delete the current op node */
        break;
      }
      break;

    case meet_union:
  
      assert((*etptr)->cooc.left != NULL);
      free_evaltree(&((*etptr)->cooc.left));
      assert((*etptr)->cooc.right != NULL);
      free_evaltree(&((*etptr)->cooc.right));
      DELETE_NODE((*etptr));
      break;

    case leaf:

      /* the current node must be a leaf */
      assert((*etptr)->leaf.type == leaf);
      DELETE_NODE((*etptr));                  /* free the current leaf     */

      break;

    case tabular:

      /* delete the next node */
      free_evaltree(&((*etptr)->tab_el.next));

      /* free myself */
      DELETE_NODE((*etptr));

      break;

    default:
      assert(0 && "Can't be");
      break;
    }
  }
}