whitespace
This commit is contained in:
parent
8dc82a66a8
commit
6b2a0264b4
22
bish.cc
22
bish.cc
|
@ -53,10 +53,10 @@ int main(int argc, char **argv){
|
|||
if (line && *line) add_history (line);
|
||||
|
||||
// handle multiple commands w/ semicolon
|
||||
vector<string> wfwe = split(line, ';');
|
||||
for (auto it: wfwe) {
|
||||
vector<string> 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;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ char** v_to_cpp(vector<string> 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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue