Cleaned useless code and impoved some things

This commit is contained in:
hellisabove
2022-01-11 18:19:32 +02:00
parent 773b546f42
commit 002c629403
2 changed files with 5 additions and 23 deletions
+4 -22
View File
@@ -40,7 +40,7 @@ void execArgs(char** parsed)
return;
} else if (pid == 0) {
if (execvp(parsed[0], parsed) < 0) {
printf("\nCould not execute command..");
printf("\nsh: command not found: \%s", parsed[0]);
}
exit(0);
} else {
@@ -75,7 +75,7 @@ void execArgsPiped(char** parsed, char** parsedpipe)
close(pipefd[1]);
if (execvp(parsed[0], parsed) < 0) {
printf("\nCould not execute command 1..");
printf("\nsh: command not found: \%s", parsed[0], parsedpipe[0]);
exit(0);
}
} else {
@@ -94,7 +94,7 @@ void execArgsPiped(char** parsed, char** parsedpipe)
dup2(pipefd[0], STDIN_FILENO);
close(pipefd[0]);
if (execvp(parsedpipe[0], parsedpipe) < 0) {
printf("\nCould not execute command 2..");
printf("\nsh: command not found: \%s", parsedpipe[0]);
exit(0);
}
} else {
@@ -105,30 +105,15 @@ void execArgsPiped(char** parsed, char** parsedpipe)
}
}
// Help command builtin
void openHelp()
{
puts("\nList of Commands supported:"
"\n>cd"
"\n>ls"
"\n>exit"
"\n>all other general commands available in UNIX shell"
"\n>pipe handling"
"\n>improper space handling");
return;
}
// Function to execute builtin commands
int ownCmdHandler(char** parsed)
{
int NoOfOwnCmds = 4, i, switchOwnArg = 0;
int NoOfOwnCmds = 2, i, switchOwnArg = 0;
char* ListOfOwnCmds[NoOfOwnCmds];
char* username;
ListOfOwnCmds[0] = "exit";
ListOfOwnCmds[1] = "cd";
ListOfOwnCmds[2] = "help";
for (i = 0; i < NoOfOwnCmds; i++) {
if (strcmp(parsed[0], ListOfOwnCmds[i]) == 0) {
@@ -143,9 +128,6 @@ int ownCmdHandler(char** parsed)
case 2:
chdir(parsed[1]);
return 1;
case 3:
openHelp();
return 1;
default:
break;
}