void SC_TerminalClient::onInputRead(const boost::system::error_code &error, std::size_t bytes_transferred)
{
	if (error == boost::asio::error::operation_aborted) {
		postfl("SCLang Input: Quit requested\n");
		return;
	}

	if (error == boost::asio::error::eof) {
		postfl("SCLang Input: EOF. Will quit.\n");
		onQuit(0);
		return;
	}

	if (error) {
		postfl("SCLang Input: %s.\n", error.message().c_str());
		onQuit(1);
		return;
	}

	if (!error) {
#if HAVE_READLINE
		if (mUseReadline) {
			rl_callback_read_char();
			startInputRead();
			return;
		}
#endif
		pushCmdLine( inputBuffer.data(), bytes_transferred );
	}
}
struct Stack* parseCmdLine(const char* const clStr)
{
	struct CmdLine* cmdLine;
	struct Queue* tokens;
	char *token, *nextToken, *command;
	char **operators, **files;
	bool background, pushed, pipedIn, pipeOut;
	struct Stack* commandStack;
	int i;
	struct LinkedList* parameters;

	tokens=tokenize(clStr);
	commandStack=stackCreate();

	pipedIn=false;
	pipeOut=false;

	while (!queueIsEmpty(tokens))
	{
		//Get Command
		pushed=false;
		command=(char *)queueGetFront(tokens);

		//Parse Parameters
		parameters=listCreate();
		if (!queueIsEmpty(tokens))
		{
			while (!queueIsEmpty(tokens))
			{
				token=(char *)queuePeek(tokens);
				if (!isDelimiter(token))
				{
					listAppend(parameters, token);
					queueGetFront(tokens);
				}
				else
				{
					break;
				}
			}
		}

		//Check for Redirects
		operators=(char **)malloc(sizeof(char*)*REDIRECTS);
		files=(char **)malloc(sizeof(char*)*REDIRECTS);
		for (i=0; i<REDIRECTS; i++)
		{
			operators[i]=NULL;
			files[i]=NULL;
		}
		if (!queueIsEmpty(tokens))
		{
			for (i=0; i<REDIRECTS && !queueIsEmpty(tokens); i++)
			{
				token=(char *)queuePeek(tokens);

				if (strcmp(token, CL_TOKEN_GREATER_THAN)==0
                                    || strcmp(token, CL_TOKEN_LESS_THAN)==0)
				{
					operators[i]=token;
					queueGetFront(tokens);
					token=(char *)queueGetFront(tokens);
					files[i]=token;
				}
				else
				{
					break;
				}
			}
		}

		//Check for background process or pipe
		background=false;
		pipeOut=false;
		if (!queueIsEmpty(tokens))
		{
			token=(char *)queuePeek(tokens);
			if (strcmp(token, CL_TOKEN_AMP)==0)
			{
				queueGetFront(tokens);
				background=true;
			}
			else if (strcmp(token, CL_TOKEN_PIPE)==0)
                        {
				queueGetFront(tokens);
                                pipeOut=true;
                        }
		}
		
		//Add Command to Stack of Commands
		pushCmdLine(commandStack, command, parameters, operators, files, pipedIn, pipeOut, background);
		pushed=true;
		pipedIn=pipeOut;

		if (background || !pipeOut)
		{
			break; //Terminated because in background or syntax error
		}
	}

	if (!pushed)
	{
		free(operators);
		free(files);
	}
	
        queueDestroy(tokens, false);

	return commandStack;
}