示例#1
0
// Common function to call all command handlers
void builtInCmdExecutor(Cmd c)
{
	if(!strcmp(c->args[0],"cd"))
	{
		executeCD(c);
	}
	else if(!strcmp(c->args[0],"echo"))
	{
		executeEcho(c);
	}
	else if(!strcmp(c->args[0],"logout"))
	{
		executeLogout(c);
	}
	
	else if(!strcmp(c->args[0],"nice"))
	{	
		executeNice(c);
	}
	else if(!strcmp(c->args[0],"pwd"))
	{
		executePwd(c);
	}
	else if(!strcmp(c->args[0],"setenv"))	
	{
		executeSetenv(c);
	}	
	else if(!strcmp(c->args[0],"unsetenv"))
	{
		executeUnsetenv(c);
	}
	else if(!strcmp(c->args[0],"where"))
	{
		executeWhere(c);	 
	}
}
void commandDecider (CMD_t *inputCommand)
{
	char *commandName = inputCommand -> argv[0];

	if (ifRedirection (inputCommand))
	{
		// Send to Redirection
		executeRedirection (inputCommand);
		return;
	}

	if (ifPiping (inputCommand))
	{
		// Send to Piping
		executePiping (inputCommand);
		return;
	}

	if (ifReturn (inputCommand))
	{
		// Don't do anything
		return;
	}

	if (!strcmp (commandName, "help"))
	{
		// Send to help
		executeHelp (inputCommand);
		return;
	}

	if (!strcmp (commandName, "clear"))
	{
		// Send to clear
		executeClear (inputCommand);
		return;
	}

	if (!strcmp (commandName, "pwd"))
	{
		// Send to pwd
		showPWD ();
		return;
	}

	if (!strcmp (commandName, "ls"))
	{
		// Send to ls
		executeLS (inputCommand);
		return;
	}

	if (!strcmp (commandName, "whoami"))
	{
		// Send to whoami
		showWhoami ();
		return;
	}

	if (!strcmp (commandName, "cd"))
	{
		// Send to cd
		executeCD (inputCommand);
		return;
	}

	if (!strcmp (commandName, "pid"))
	{
		// Send to pid
		executePID (inputCommand);
		return;
	}

	if (!strcmp (commandName, "history"))
	{
		// Send to history
		executeHistory (inputCommand);
		return;
	}

	if (!strcmp (commandName, "kill"))
	{
		// Send to kill
		executeKill (inputCommand);
		return;
	}

	if (!strcmp (commandName, "exit"))
	{
		clearHistory ();
		exit (0);
	}

	printf ("ERROR: INVALID_COMMAND :: \"%s\" is not a recognised command.. Type \"help\" for more information\n", commandName);
	return;
}