lab 2 cleanup
This commit is contained in:
Binary file not shown.
@@ -61,7 +61,7 @@ int parse_commands(char input[INPUT_MAX], char cmd_strs[CMD_MAX][INPUT_MAX])
|
||||
{
|
||||
if (cmd_count >= CMD_MAX)
|
||||
{
|
||||
fprintf(stderr, "Too many commands\n");
|
||||
fprintf(stderr, "\nToo many commands\n");
|
||||
return -1;
|
||||
}
|
||||
strncpy(cmd_strs[cmd_count], cmd_ptr, INPUT_MAX);
|
||||
@@ -79,8 +79,7 @@ int main()
|
||||
|
||||
int quit_flag = 0;
|
||||
|
||||
// TODO need to be able to get input from
|
||||
// the user in a loop
|
||||
// Get user input in a loop
|
||||
while(quit_flag == 0) {
|
||||
|
||||
// Print the input prompt
|
||||
@@ -92,7 +91,7 @@ int main()
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO: Figure out how to handle the 'quit' command
|
||||
// Set quit flag
|
||||
if (strcmp(user_input, "quit") == 0){
|
||||
printf("Quitting...\n");
|
||||
quit_flag = 1;
|
||||
@@ -107,8 +106,8 @@ int main()
|
||||
}
|
||||
|
||||
// Chop the commands into arguments and execute one at a time
|
||||
if(!quit_flag) {
|
||||
for (int i = 0; i < cmd_count; i++) {
|
||||
|
||||
char **args = malloc(ARG_MAX*sizeof(char *));
|
||||
char* str = malloc(10*sizeof(char));
|
||||
strncpy(str, strtok(cmd_strs[i], " "), 10);
|
||||
@@ -120,7 +119,6 @@ int main()
|
||||
j++;
|
||||
}
|
||||
pid_t pid = fork();
|
||||
|
||||
if(pid == 0) {
|
||||
execvp(args[0], args);
|
||||
printf("Command not found: %s\n", args[0]);
|
||||
@@ -134,5 +132,6 @@ int main()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user