
/* OpenWebSpider
 *
 *  Author:     Stefano Alimonti aka Shen139
 *  Mail:       shen139 [at] openwebspider (dot) org
 *
 *
 * This file is part of OpenWebSpider
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef __LIST
#define __LIST

int lstInited = 0;

int lstFreeAll(NODE* first)
{
NODE* cur = first;
NODE* tmp;
lstInited = 0;

	lstInited=0;
	
	if(first==NULL)
		return 1;

	if(cur->field == NULL && cur->next == NULL)
	{
		return 1;
	}

	while(cur != NULL)
	{
		tmp=cur->next;

		if(cur->field!=NULL)
			free(cur->field);
		
		if(cur!=NULL)
			free(cur);

		//FREE(cur->field);
		//FREE(cur);
		cur=tmp;
	}

return 1;
}

NODE* lstGetNodeX(NODE* first, int x)
{
NODE* cur = first;

	thrdBlock(BLOCKTHRDHST);
	while(cur != NULL && x>0)	//to correct in do while
	{
		x--;
		cur=cur->next;
	}
	thrdUnBlock(BLOCKTHRDHST);

return (x==0) ? cur : NULL;
}

NODE* lstGetLastNode(NODE* first, int* NumOfNodes)
{
NODE* cur = first;

	if(lstInited == 0)
		return NULL;

	if(NumOfNodes!=NULL)
		*NumOfNodes=0;

	while(cur->next != NULL)
	{
		if(NumOfNodes!=NULL)
			(*NumOfNodes)++;

		cur=cur->next;
	}
	
return cur;
}

#endif

/*EOF*/
