2015-06-30 17:59:00 +00:00
|
|
|
#include "tidyplatform.h"
|
2011-11-17 02:44:16 +00:00
|
|
|
#include "tidy-int.h"
|
|
|
|
|
|
|
|
#include "TidyNodeIter.h"
|
|
|
|
|
|
|
|
TidyNodeIter *newTidyNodeIter( Node *pStart )
|
|
|
|
{
|
|
|
|
TidyNodeIter *pThis = NULL;
|
|
|
|
if (NULL != (pThis = MemAlloc( sizeof( TidyNodeIter ))))
|
|
|
|
{
|
|
|
|
ClearMemory( pThis, sizeof( TidyNodeIter ));
|
|
|
|
pThis->pTop = pStart;
|
|
|
|
}
|
|
|
|
return pThis;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *nextTidyNode( TidyNodeIter *pThis )
|
|
|
|
{
|
|
|
|
if (NULL == pThis->pCurrent)
|
|
|
|
{
|
2016-10-25 14:41:03 +00:00
|
|
|
/* just starting out, initialize */
|
2011-11-17 02:44:16 +00:00
|
|
|
pThis->pCurrent = pThis->pTop->content;
|
|
|
|
}
|
|
|
|
else if (NULL != pThis->pCurrent->content)
|
|
|
|
{
|
2016-10-25 14:41:03 +00:00
|
|
|
/* the next element, if any, is my first-born child */
|
2011-11-17 02:44:16 +00:00
|
|
|
pThis->pCurrent = pThis->pCurrent->content;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-25 14:41:03 +00:00
|
|
|
/* no children, I guess my next younger brother inherits the throne. */
|
2011-11-17 02:44:16 +00:00
|
|
|
while ( NULL == pThis->pCurrent->next
|
|
|
|
&& pThis->pTop != pThis->pCurrent->parent )
|
|
|
|
{
|
2016-10-25 14:41:03 +00:00
|
|
|
/* no siblings, do any of my ancestors have younger sibs? */
|
2011-11-17 02:44:16 +00:00
|
|
|
pThis->pCurrent = pThis->pCurrent->parent;
|
|
|
|
}
|
|
|
|
pThis->pCurrent = pThis->pCurrent->next;
|
|
|
|
}
|
|
|
|
return pThis->pCurrent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCurrentNode( TidyNodeIter *pThis, Node *newCurr )
|
|
|
|
{
|
|
|
|
if (NULL != newCurr)
|
|
|
|
pThis->pCurrent = newCurr;
|
|
|
|
}
|