Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

Commit

Permalink
using perror at appropriate places
Browse files Browse the repository at this point in the history
  • Loading branch information
nautatva committed Feb 10, 2019
1 parent 27ac1cf commit daaa3e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions assignment 1/my_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,35 @@ int main(int argc, char *argv[])
// i is the token number at which the echo trails off
if (i == -1)
{
printf("Did not find \" \n");

printf("Shell: Incorrect command \n");
// perror("Did not find \" \n");
/*What to replace here?????*/
break;
}
}

if (strcmp(tokens[i], "sleep") == 0)
else if (strcmp(tokens[i], "sleep") == 0)
{
int sleepNo = stoi(tokens[i + 1]);
if (sleepNo > MAX_NUM_TOKENS)
{
printf("Sleeping cannot be done for such long period \n");
printf("Shell: Incorrect command \n");
// perror("Sleeping cannot be done for such long period \n");
/*What to replace here?????*/
break;
}
sleep(sleepNo);
}

if (strcmp(tokens[i], "cd") == 0)
else if (strcmp(tokens[i], "cd") == 0)
{
i++;
if (chdir(tokens[i]) == -1)
/*We just have to change directory in our custom shell right!??? */
{
printf("no such directory \n");
printf("Shell: Incorrect command \n");
// perror("no such directory \n");
/*What to replace here????? */
}
else
Expand All @@ -108,11 +112,15 @@ int main(int argc, char *argv[])
};
}

if (strcmp(tokens[i], "ls") == 0)
else if (strcmp(tokens[i], "ls") == 0)
{
ls();
/*Work on this ????*/
}
else
{
printf("Shell: Incorrect command \n");
}
}

// Freeing the allocated memory
Expand Down Expand Up @@ -241,7 +249,9 @@ void ls()

if (dr == NULL) // opendir returns NULL if couldn't open directory
{
printf("Could not open current directory");

printf("Shell: Incorrect command \n");
// printf("Could not open current directory");
return;
}

Expand Down
Binary file modified assignment 1/shell.pdf
Binary file not shown.

0 comments on commit daaa3e1

Please sign in to comment.