Commit 6525cb92 authored by Lindsay Knupp's avatar Lindsay Knupp
Browse files

End of lab

parent 9896b97d
......@@ -8,4 +8,9 @@
#include <stdio.h>
#include <unistd.h>
#include "hexdump.h"
int main(int argc, char* argv[]){
}
......@@ -2,4 +2,9 @@ Lindsay Knupp
11/30/21
Lab 10 - prelab.txt
1 1 0 1 0 0 0 0 0
push first three bits to the right hand side, shift by 6 bits
so that it's the only thing in that number
1 1 0 & 1 0 0 or 0 1 0 or 0 0 1 to say which permission user has
CC = gcc -lreadline
CFLAGS = -std=gnu99 -Wall -g #-DDEBUG
EXECS = ishell
EXECS = ishell maybeishell
all: $(EXECS)
ishell: ishell.c
$(CC) $(CFLAGS) -o $@ $<
maybeishell: maybeishell.c
$(CC) $(CFLAGS) -o $@ $<
.PHONY: clean
clean:
/bin/rm -f *.o $(EXECS)
......@@ -34,60 +34,53 @@ int main (int argc, char *argv[]){
printf("ishell> ");
//parse user input and split into tokens
line = NULL;
//get user input from terminal
getline(&line,&length,stdin);
length = strlen(line);
line[length-1] = 0;
line[length-1] = 0;
for (int i=0;i<MAXCNT;i++){
tokens[i] = (char*) malloc(MAXLEN);
tokens1[i] = (char*) malloc(MAXLEN);
tokens2[i] = (char*) malloc(MAXLEN);
}
int token_count = 0;
for (str = line; ; str = NULL){
token = strtok_r(str," ", &saveptr);
if(token_count >= MAXCNT || token == NULL){
break;
}
strcpy(tokens[token_count],token);
tokens[token_count] = token;
token_count ++;
}
tokens[token_count] = NULL;
int command2 = 0;
for (int i = 0; i<MAXCNT; i++){
if(strcmp(tokens[i],";") == 0){
command2 = i;
break;
}
//int command2 = 0;
//for (int i = 0; i<MAXCNT; i++){
// if(strcmp(tokens[i],";") == 0){
// command2 = i;
// break;
// }
//}
}
//printf("command index %d\n",command2);
if (command2 != 0){
for (int i = 0; i < command2;i++){
strcpy(tokens1[i],tokens[i]);
}
tokens1[command2] = NULL;
//if (command2 != 0){
//for (int i = 0; i < command2;i++){
// strcpy(tokens1[i],tokens[i]);
//}
//tokens1[command2] = NULL;
for (int i = command2;i<token_count;i++){
strcpy(tokens2[i],tokens[i]);
}
tokens2[token_count] = NULL;
//for (int i = command2;i<token_count;i++){
// strcpy(tokens2[i],tokens[i]);
//}
//tokens2[token_count] = NULL;
strcpy(path2, "/usr/bin/");
strcpy(path, "/usr/bin/");
strcat(path, tokens1[0]);
strcat(path, tokens2[0]);
//strcpy(path2, "/usr/bin/");
//strcpy(path, "/usr/bin/");
}
tokens[token_count] = NULL;
//strcat(path, tokens1[0]);
//strcat(path, tokens2[0]);
//}
strcpy(path,"/usr/bin/");
strcat(path,tokens[0]);
free(line);
......@@ -99,17 +92,13 @@ int main (int argc, char *argv[]){
// child branch
if (pid == 0){
if(command2 != 0){
execv(path,tokens1);
execv(path2,tokens2);
}
execv(path,tokens);
}
// parent branch
else {
wait(&status);
fflush(stdout);
wait(&status);
int es = WEXITSTATUS(status);
if (es == 0){
printf("[ishell: program terminated successfully]\n");
......@@ -117,10 +106,6 @@ int main (int argc, char *argv[]){
else {
printf("[ishell: program terminated abnormally][%d]\n",es);
}
for (int i=0;i<token_count;i++){
free(tokens[i]);
}
}
}
return 0;
......
Supports Markdown
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