Commit 3abe8bb0 authored by Lindsay Knupp's avatar Lindsay Knupp
Browse files

Lab 9.4 completed

parent 1dd6e827
......@@ -12,8 +12,6 @@
#include <sys/wait.h>
#include <signal.h>
#include "ishell.h"
#define MAXCNT 10
#define MAXLEN 20
......@@ -34,10 +32,15 @@ int main (int argc, char *argv[]){
char* tokens2[MAXCNT];
char* line = NULL;
size_t length;
int entertwice;
char * enter = NULL;
size_t enter_length;
// Ask user for input
while(1){
entertwice = -1;
printf("ishell> ");
strcpy(path,"/usr/bin/");
......@@ -47,10 +50,17 @@ int main (int argc, char *argv[]){
//get user input from terminal
getline(&line,&length,stdin);
length = strlen(line);
line[length-1] = 0;
char* arr[] = {"ls",NULL};
if (line[0] == '\n'){
getline(&enter,&enter_length,stdin);
//char* arr[] = {"ls",NULL};
entertwice = 0;
}
else{
length = strlen(line);
line[length-1] = 0;
}
// initialize arrays for clean strings
for (int i = 0; i<MAXCNT; i++){
semitokens[i] = (char*)malloc(MAXLEN);
......@@ -59,7 +69,6 @@ int main (int argc, char *argv[]){
tokens[i] = (char*)malloc(MAXLEN);
}
// split command(s) by semicolon
int semi_token_count = 0;
for (str = line; ; str = NULL){
......@@ -120,7 +129,13 @@ int main (int argc, char *argv[]){
// child branch
if (pid == 0){
execv(path,tokens);
// enter was hit twice
if (entertwice == 0){
execv("/usr/bin/ls",arr);
}
else{
execv(path,tokens);
}
}
// parent branch
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment