From 6b2a0264b4b84858b7ab083ea759554c684bb3f8 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Thu, 17 Nov 2016 16:53:32 -0500 Subject: [PATCH] whitespace --- bish.cc | 22 ++++++++-------------- util_fns.cc | 4 +++- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/bish.cc b/bish.cc index e22632d..d63a9de 100644 --- a/bish.cc +++ b/bish.cc @@ -53,10 +53,10 @@ int main(int argc, char **argv){ if (line && *line) add_history (line); // handle multiple commands w/ semicolon - vector wfwe = split(line, ';'); - for (auto it: wfwe) { + vector semicolon_split = split(line, ';'); + for (auto semicolon_iter: semicolon_split) { - command *cmd = parse(split(it.c_str())); + command *cmd = parse(split(semicolon_iter.c_str())); int num_cmds = cmd->cmds.size(); // debug info // print_cmd(cmd); @@ -78,16 +78,15 @@ int main(int argc, char **argv){ } if (num_cmds > 1) { - - int in = 0, fd[2]; + int in = 0, pipefd[2]; for (int i = 0; i < num_cmds-1; i++) { - if (pipe(fd)) perror("pipe"); + if (pipe(pipefd)) perror("pipe"); cmd->cmds[i].ispipe = true; cmd->cmds[i].infd = in; - cmd->cmds[i].outfd = fd[1]; + cmd->cmds[i].outfd = pipefd[1]; expand_and_execute(&cmd->cmds[i]); - close(fd[1]); - in = fd[0]; + close(pipefd[1]); + in = pipefd[0]; } if (in != 0) { cmd->cmds[num_cmds-1].ispipe = true; @@ -101,8 +100,6 @@ int main(int argc, char **argv){ expand_and_execute(&cmd->cmds[0]); } - - // 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); // if (dotsrcfile < 0) { @@ -112,8 +109,6 @@ int main(int argc, char **argv){ // // do the thing to read the files // } - - // reset args array for the next prompt delete cmd; @@ -121,6 +116,5 @@ int main(int argc, char **argv){ } // end main while loop cout << endl; if (write_history(histpath.c_str())) perror("write_history"); - return 0; } diff --git a/util_fns.cc b/util_fns.cc index dd46b65..0f0a5d7 100644 --- a/util_fns.cc +++ b/util_fns.cc @@ -49,6 +49,7 @@ char** v_to_cpp(vector vargs) { void check_cmd_io(simple_command *cmd) { + // do all the io redirs n stuff if (cmd->ispipe) { if (!remap_pipe_stdin_stdout(cmd->infd, cmd->outfd)) { // perror("dup2-remap_pipe_stdin_stdout"); @@ -87,6 +88,7 @@ void check_cmd_io(simple_command *cmd) { +// this method adapted from // http://www.gnu.org/software/libc/manual/html_node/Wordexp-Example.html int expand_and_execute (simple_command *cmd) { const char *program = cmd->vargs[0].c_str(); @@ -134,7 +136,7 @@ int expand_and_execute (simple_command *cmd) { if (pid == 0) { /* This is the child process. Execute the command. */ check_cmd_io(cmd); - execvp (result.we_wordv[0], result.we_wordv); + execvp(result.we_wordv[0], result.we_wordv); cout << "that's not a command, bish" << endl; exit (EXIT_FAILURE); }