done done done done done pipes n shit
This commit is contained in:
parent
f05259439a
commit
616db593cb
11
Makefile
11
Makefile
|
@ -1,11 +1,16 @@
|
|||
COMPILER_FLAGS = -O3 -Wall -std=c++11 -ggdb
|
||||
LINKER_FLAGS = -lreadline
|
||||
|
||||
OBJS = \
|
||||
bish.o \
|
||||
parse.o \
|
||||
util_fns.o
|
||||
|
||||
all:
|
||||
make bish
|
||||
|
||||
bish: bish.o parse.o util_fns.o Makefile
|
||||
g++ *.o -o bish $(LINKER_FLAGS)
|
||||
bish: $(OBJS) Makefile
|
||||
g++ $(OBJS) -o bish $(LINKER_FLAGS)
|
||||
|
||||
bish.o: bish.cc Makefile
|
||||
g++ bish.cc -c -o bish.o $(COMPILER_FLAGS)
|
||||
|
@ -13,7 +18,7 @@ bish.o: bish.cc Makefile
|
|||
parse.o: parse.cc Makefile
|
||||
g++ parse.cc -c -o parse.o $(COMPILER_FLAGS)
|
||||
|
||||
util_fns.cc: util_fns.cc Makefile
|
||||
util_fns.o: util_fns.cc Makefile
|
||||
g++ util_fns.cc -c -o util_fns.o $(COMPILER_FLAGS)
|
||||
|
||||
clean:
|
||||
|
|
|
@ -25,9 +25,9 @@ The Shell Assignment (total 42 points)
|
|||
+ `ls | wc`
|
||||
+ 1 ~~Can do lots of pipes~~
|
||||
+ `ls | grep fred | wc`
|
||||
+ 1 Can do at least one combination of these things
|
||||
+ 1 ~~Can do at least one combination of these things~~
|
||||
+ `ls | wc > fred`
|
||||
+ 4 Can do any combination of three of <, >, and |
|
||||
+ 4 ~~Can do any combination of three of <, >, and |~~
|
||||
+ `cat < filename | sort > sortedFile.txt`
|
||||
+ 2 Can set enviornment variables
|
||||
+ `PATH=:/bin:/sbin:/usr/sbin:/usr/bin`
|
||||
|
@ -69,7 +69,7 @@ The Shell Assignment (total 42 points)
|
|||
+ 2 Only runs execuatables from an approved list
|
||||
+ -2 Commands cannot have arguments (i.e. ls -l does not work).
|
||||
|
||||
20 pts
|
||||
25 pts
|
||||
/20
|
||||
|
||||
Some cases to consider
|
||||
|
|
13
bish.cc
13
bish.cc
|
@ -70,6 +70,13 @@ int main(int argc, char **argv){
|
|||
break;
|
||||
}
|
||||
|
||||
// COMMANDS that do something with the line before fork/exec
|
||||
if (cmd->cmds[0].vargs[0] == "!") {
|
||||
line = history_get(where_history())->line;
|
||||
cout << line << endl;
|
||||
cmd = parse(split(line));
|
||||
}
|
||||
|
||||
if (num_cmds > 1) {
|
||||
|
||||
int in = 0, fd[2];
|
||||
|
@ -95,12 +102,6 @@ int main(int argc, char **argv){
|
|||
}
|
||||
|
||||
|
||||
// COMMANDS that do something with the line before fork/exec
|
||||
// if (strcmp(cmd->cmds[0]->args[0], "!") == 0) {
|
||||
// line = history_get(where_history())->line;
|
||||
// cout << line << endl;
|
||||
// cmd = parse(split(line));
|
||||
// }
|
||||
|
||||
// else if (strcmp(cmd->cmds[0]->args[0], ".") == 0 || strcmp(cmd->cmds[0]->args[0], "source") == 0) {
|
||||
// int dotsrcfile = open(cmd->cmds[0]->args[1], O_RDONLY);
|
||||
|
|
|
@ -53,7 +53,7 @@ void check_cmd_io(simple_command *cmd) {
|
|||
if (!remap_pipe_stdin_stdout(cmd->infd, cmd->outfd)) {
|
||||
// perror("dup2-remap_pipe_stdin_stdout");
|
||||
}
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
// else {
|
||||
if (cmd->infile != "") {
|
||||
|
@ -133,10 +133,9 @@ int expand_and_execute (simple_command *cmd) {
|
|||
pid = fork();
|
||||
if (pid == 0) {
|
||||
/* This is the child process. Execute the command. */
|
||||
// int in = 0, out = 1;
|
||||
check_cmd_io(cmd);
|
||||
|
||||
execvp (result.we_wordv[0], result.we_wordv);
|
||||
cout << "that's not a command, bish" << endl;
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
else if (pid < 0)
|
||||
|
|
Loading…
Reference in New Issue