Exemplo n.º 1
0
/*
 * Context push and pop
 */
static void pushcontext(void)
{
	struct sContext **ppFileStack;

	ppFileStack = &pFileStack;
	while (*ppFileStack)
		ppFileStack = &((*ppFileStack)->pNext);

	*ppFileStack = malloc(sizeof(struct sContext));

	if (*ppFileStack == NULL)
		fatalerror("No memory for context");

	(*ppFileStack)->FlexHandle = CurrentFlexHandle;
	(*ppFileStack)->pNext = NULL;
	strcpy((char *)(*ppFileStack)->tzFileName, (char *)tzCurrentFileName);
	(*ppFileStack)->nLine = nLineNo;

	switch ((*ppFileStack)->nStatus = nCurrentStatus) {
	case STAT_isMacroArg:
	case STAT_isMacro:
		sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
		(*ppFileStack)->pMacro = pCurrentMacro;
		break;
	case STAT_isInclude:
		(*ppFileStack)->pFile = pCurrentFile;
		break;
	case STAT_isREPTBlock:
		sym_SaveCurrentMacroArgs((*ppFileStack)->tzMacroArgs);
		(*ppFileStack)->pREPTBlock = pCurrentREPTBlock;
		(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
		(*ppFileStack)->nREPTBlockCount = nCurrentREPTBlockCount;
		break;
	default:
		fatalerror("%s: Internal error.", __func__);
	}

	nLineNo = 0;
}
void    pushcontext (void)
{
    struct sContext **ppFileStack;

    ppFileStack = &pFileStack;
    while (*ppFileStack)
	ppFileStack = &((*ppFileStack)->pNext);

    if ((*ppFileStack=(struct sContext *)malloc(sizeof (struct sContext)))!=NULL)
    {
		(*ppFileStack)->FlexHandle = CurrentFlexHandle;
		(*ppFileStack)->pNext = NULL;
		strcpy ((char *)(*ppFileStack)->tzFileName, (char *)tzCurrentFileName);
		(*ppFileStack)->nLine = nLineNo;
		switch ((*ppFileStack)->nStatus = nCurrentStatus)
		{
		    case STAT_isMacroArg:
		    case STAT_isMacro:
				sym_SaveCurrentMacroArgs ((*ppFileStack)->tzMacroArgs);
				(*ppFileStack)->pMacro = pCurrentMacro;
				break;
		    case STAT_isInclude:
				(*ppFileStack)->pFile = pCurrentFile;
				break;
		    case STAT_isREPTBlock:
				sym_SaveCurrentMacroArgs ((*ppFileStack)->tzMacroArgs);
				(*ppFileStack)->pREPTBlock = pCurrentREPTBlock;
				(*ppFileStack)->nREPTBlockSize = nCurrentREPTBlockSize;
				(*ppFileStack)->nREPTBlockCount = nCurrentREPTBlockCount;
				break;
		}
		nLineNo = 0;
    }
    else
		ErrorFatal ("No memory for context");
}