/* Aplica una funcion a todos los elementos del árbol */
void map_tree(void (*func)(void *), TREE *t)
{
    TREE *c;

    if(t->childs != NULL)
    {
        c = (TREE *)first_l(t->childs);
        while(c != NULL)
        {
            map_tree(func, c);
            c = (TREE *)next_l(t->childs);
        }
    }
    (*func)(t->value);
}
/* Libera todo el árbol */
void free_tree(TREE *t)
{
    TREE *c;

    if(t->childs != NULL)
    {
        c = (TREE *)first_l(t->childs);
        while(c != NULL)
        {
            free_tree(c);
            c = (TREE *)next_l(t->childs);
        }
        free_l(t->childs);
    }
    free(t);
}
Beispiel #3
0
/*
 * refill the msequencecontainer object with the next set of sequences and descriptions	
 */
unsigned long msequenceServer::next(const bool _f)
{
/*
 * exit on completion	
 */
	if(done())
		return 0;
/*
 * start the reading process, if it hasn't been started	
 */
	if(!started())	{
		if(!start())	{
			m_bDone = true;
			m_bError = true;
			m_strStatus += "Server would not start.\r\n";
			return 0;
		}
	}
	if(m_lFileType == XBANG)
		return next_pro(_f);
	if(!_f)
		return next_l();
/*
 * initialized the time	
 */
	double dStart = clock();
	unsigned long iLength = 0;
	msequence seqTemp;
	char cValue = '\0';
	char *pValue = NULL;
	char *pEol = NULL;
	m_pCol->clear();
	while(!feof(m_pInput) && iLength < m_pCol->m_tMax)	{
/*
 * store the description in a temporary msequence object, obtained in the previous read	
 */
		m_pCol->m_vASequences[iLength].m_strDes = m_strFirst;
/*
 * strip whitespace characters from the sequence line
 */
		pValue = m_pLine;
		fgets(pValue,m_lSize,m_pInput);
/*
 * clear the sequence in a temporary msequence object	
 */
		while(pValue[0] != '>' && !feof(m_pInput))	{
/*
 * store initial sequence line, and repeat until the next description line is encountered	
 */
			pValue += strlen(pValue);
			pValue--;
			if(pValue > m_pLine)	{
				while(pValue > m_pLine && isspace(*pValue))	{
					pValue--;
				}
				if(!isspace(*pValue) && *pValue != '\0')	{
					pValue++;
					*pValue = '\0';
				}
			}
			fgets(pValue,m_lSize,m_pInput);
		}
		cValue = *pValue;
		*pValue = '\0';
		bz(m_pLine);
		m_pCol->m_vASequences[iLength].m_strSeq = m_pLine;
		m_pCol->m_vASequences[iLength].m_siPath = (short int)(m_vstrPaths.size() - 1);
		*pValue = cValue;
/*
 *	store the next description line
 */
		if(pValue[0] == '>')	{
			if(strchr(pValue,0x01))	{
				pEol = strchr(pValue,0x01);
				*pEol = '\0';
			}
			else	{
				pEol = pValue + strlen(pValue) - 1;
				while(pEol > pValue && isspace(*pEol))	{
					*pEol = '\0';
					pEol--;
				}
			}
			pEol = strchr(pValue,'\r');
			if(pEol)	{
				*pEol = '\0';
			}
			pEol = strchr(pValue,'\n');
			if(pEol)	{
				*pEol = '\0';
			}
			m_strFirst = pValue + 1;
		}
		m_pCol->m_tLength++;
		iLength++;
	}
/*
 * if the current sequence list file is finished, close it and get the next one, otherwise finish	
 */
	if(feof(m_pInput))	{
		if(m_dstrFasta.empty())	{
			finish();
		}
		else	{
			fclose(m_pInput);
			start();
		}
	}
/*
 * store the time required to load the msequencecontainer	
 */
	m_dTime += (double)(clock() - dStart);
	return iLength;
}