Skip to content

Commit

Permalink
Step 5: MyShell
Browse files Browse the repository at this point in the history
  • Loading branch information
cnphil committed Apr 5, 2013
1 parent 01622c5 commit 0ee7386
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Binary file added MyShell
Binary file not shown.
28 changes: 28 additions & 0 deletions MyShell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "cse356header.h"
#include "readline.c"
#define MAX_ARGS 50

main()
{
while (true) {
int argc;
char *argv[MAX_ARGS];

write(1, "$ ", 2);
char buffer[256];
readline(0, buffer, 255);
buffer[strlen(buffer) - 1] = '\0'; // get rid of cr
if(strcmp("exit", buffer) == 0) exit(0);
pid_t forkpid;
forkpid = fork();

if(forkpid == 0) { // child process
argv[0] = buffer; argv[1] = NULL;
execvp(argv[0], argv);
exit(0);
}
wait(NULL);

}
exit(0);
}
6 changes: 5 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: MyCopy ForkCopy PipeCopy timer
all: MyCopy ForkCopy PipeCopy timer MyShell
clear:
rm *.o
MyCopy: MyCopy.o
Expand All @@ -17,3 +17,7 @@ timer: timer.o
g++ timer.o -o timer
timer.o:
g++ -c timer.c
MyShell: MyShell.o
g++ MyShell.o -o MyShell
MyShell.o:
g++ -c MyShell.c
5 changes: 2 additions & 3 deletions readline.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "unp.h"

ssize_t
readline(int fd, void *vptr, size_t maxlen)
readline(int fd, char *vptr, size_t maxlen)
{
ssize_t n, rc;
char c, *ptr;
Expand All @@ -23,4 +22,4 @@ readline(int fd, void *vptr, size_t maxlen)

*ptr = 0;
return(n);
}
}

0 comments on commit 0ee7386

Please sign in to comment.