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
+1 -1
View File
@@ -1,7 +1,7 @@
OBJS = shell.o OBJS = shell.o
SOURCE = shell.c SOURCE = shell.c
HEADER = HEADER =
OUT = ss OUT = sh
CC = gcc CC = gcc
FLAGS = -g -c FLAGS = -g -c
LFLAGS = -lreadline LFLAGS = -lreadline
+4 -22
View File
@@ -40,7 +40,7 @@ void execArgs(char** parsed)
return; return;
} else if (pid == 0) { } else if (pid == 0) {
if (execvp(parsed[0], parsed) < 0) { if (execvp(parsed[0], parsed) < 0) {
printf("\nCould not execute command.."); printf("\nsh: command not found: \%s", parsed[0]);
} }
exit(0); exit(0);
} else { } else {
@@ -75,7 +75,7 @@ void execArgsPiped(char** parsed, char** parsedpipe)
close(pipefd[1]); close(pipefd[1]);
if (execvp(parsed[0], parsed) < 0) { if (execvp(parsed[0], parsed) < 0) {
printf("\nCould not execute command 1.."); printf("\nsh: command not found: \%s", parsed[0], parsedpipe[0]);
exit(0); exit(0);
} }
} else { } else {
@@ -94,7 +94,7 @@ void execArgsPiped(char** parsed, char** parsedpipe)
dup2(pipefd[0], STDIN_FILENO); dup2(pipefd[0], STDIN_FILENO);
close(pipefd[0]); close(pipefd[0]);
if (execvp(parsedpipe[0], parsedpipe) < 0) { if (execvp(parsedpipe[0], parsedpipe) < 0) {
printf("\nCould not execute command 2.."); printf("\nsh: command not found: \%s", parsedpipe[0]);
exit(0); exit(0);
} }
} else { } 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 // Function to execute builtin commands
int ownCmdHandler(char** parsed) int ownCmdHandler(char** parsed)
{ {
int NoOfOwnCmds = 4, i, switchOwnArg = 0; int NoOfOwnCmds = 2, i, switchOwnArg = 0;
char* ListOfOwnCmds[NoOfOwnCmds]; char* ListOfOwnCmds[NoOfOwnCmds];
char* username; char* username;
ListOfOwnCmds[0] = "exit"; ListOfOwnCmds[0] = "exit";
ListOfOwnCmds[1] = "cd"; ListOfOwnCmds[1] = "cd";
ListOfOwnCmds[2] = "help";
for (i = 0; i < NoOfOwnCmds; i++) { for (i = 0; i < NoOfOwnCmds; i++) {
if (strcmp(parsed[0], ListOfOwnCmds[i]) == 0) { if (strcmp(parsed[0], ListOfOwnCmds[i]) == 0) {
@@ -143,9 +128,6 @@ int ownCmdHandler(char** parsed)
case 2: case 2:
chdir(parsed[1]); chdir(parsed[1]);
return 1; return 1;
case 3:
openHelp();
return 1;
default: default:
break; break;
} }