Beispiel #1
0
void completeCommand()
{
	while (operatorStack != NULL)
	{
		int tempOper = peekOperator();
		pop(true);
		command_t secondCommand = peekCommand();
		pop(false);
		command_t firstCommand = peekCommand();
		pop(false);
		command_t newCommand = combine(firstCommand, secondCommand, tempOper);
		push(-1, newCommand);
	}
	if (stream == NULL)
	{
		stream = (command_stream_t)checked_malloc(sizeof(struct command_stream));
		stream->command = commandStack->command;
		stream->next = NULL;
		headStream = (command_stream_t)checked_malloc(sizeof(struct command_stream));
		headStream = stream;
	}
	else
		if (stream != NULL)
		{
			tempStream = (command_stream_t)checked_malloc(sizeof(struct command_stream));
			tempStream->command = commandStack->command;
			stream->next = tempStream;
			stream = tempStream;
		}
	initStacks();
}
Beispiel #2
0
void processOperator(int operator)
{
	if (operatorStack == NULL)
	{
		push(operator, NULL);
	}
	else
	{
		if (precedence(operator) > precedence(peekOperator()))
		{
			push(operator, NULL);
		}
		else
		{
			while (precedence(peekOperator()) != 0 && precedence(operator) <= precedence(peekOperator()))
			{
				int topOper = peekOperator();
				if(topOper == 1) 
				{
					command_t topCommand = peekCommand();
					pop(false);
					command_t newCommand = makeSubshell(topCommand);
				}
				if(topOper != 1)
				{
					int tempOper = peekOperator();
					pop(true);
					command_t secondCommand = peekCommand();
					pop(false);
					command_t firstCommand = peekCommand();
					pop(false);
					command_t newCommand = combine(firstCommand, secondCommand, tempOper);
					push(-1, newCommand);
				}
				if (operatorStack == NULL)
					break;
			}
			push(operator, NULL);
		}
	}
}
bool CCEThread::processCommands(int wait)
{
	CCEThreadCommand* cmd;
	while((cmd = peekCommand())!=NULL) {
		bool r = processCommand(cmd);
		delete cmd;
		if(!r) {			
			return false;
		}
	}

	if(wait<0) {
		m_event.waitSign();
	} else if(wait>0) {
		m_event.waitSign(wait);
	}
	return m_valid;
}