示例#1
0
char * makeDirectory(const char *fn, const char *p){
	//struct needed to check if a file exists easily	
	struct stat st = {0};
	
	char *path;
	char *final;
	char *cutter;
	if(fn == NULL){
		return "Error! formart for mkdir is: mkdir File_Name Path\n";
	}
	if (p == NULL){
		path = showPWD();
	}
	else {
		asprintf(&path, "%s", p);
	}
	
	asprintf(&final, "%s/%s", path, fn);
	//remove the final character
	final[strlen(final) - 1] = 0;
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;
}