summaryrefslogtreecommitdiff
path: root/vest/line_mediator.pl
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-16 20:40:43 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-16 20:40:43 +0000
commitcb1839bbb4153955eef1be290a28b47d20de08ca (patch)
tree534938bec72d15b4b37ac3ed3d270c6a8913b817 /vest/line_mediator.pl
parent8099ca52236e1512e7f201b5c5defd1e51bb1c29 (diff)
SNAKE mode for (c1 | c2 | c1) where the two c1 are actually the same process, and test cat.pl with no buffering
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@292 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'vest/line_mediator.pl')
-rwxr-xr-xvest/line_mediator.pl42
1 files changed, 31 insertions, 11 deletions
diff --git a/vest/line_mediator.pl b/vest/line_mediator.pl
index 0a9af82e..87a73590 100755
--- a/vest/line_mediator.pl
+++ b/vest/line_mediator.pl
@@ -23,24 +23,44 @@ if (scalar @ARGV) {
}
pop @c1;
my @c2=@ARGV;
-(scalar @c1 && scalar @c2) || die "usage: $0 cmd1 args -- cmd2 args; hooks up two processes, 2nd of which has one line of output per line of input, expected by the first, which starts off the communication. crosses stdin/stderr of cmd1 and cmd2 line by line (both must flush on newline and output. cmd1 initiates the conversation (sends the first line). QUIET=1 env var suppresses debugging output. default: attempts to cross stdin/stdout of c1 and c2 directly (via two unidirectional posix pipes created before fork). env SERIAL=1: (no parallelism possible) but lines exchanged are logged unless QUIET.";
+@ARGV=();
+(scalar @c1 && scalar @c2) || die "usage: $0 cmd1 args -- cmd2 args; hooks up two processes, 2nd of which has one line of output per line of input, expected by the first, which starts off the communication. crosses stdin/stderr of cmd1 and cmd2 line by line (both must flush on newline and output. cmd1 initiates the conversation (sends the first line). QUIET=1 env var suppresses debugging output. default: attempts to cross stdin/stdout of c1 and c2 directly (via two unidirectional posix pipes created before fork). env SERIAL=1: (no parallelism possible) but lines exchanged are logged unless QUIET. if SNAKE then stdin -> c1 -> c2 -> c1 -> stdout";
info("1 cmd:",@c1,"\n");
info("2 cmd:",@c2,"\n");
-if ($ENV{SERIAL}) {
+sub lineto {
+ select $_[0];
+ $|=1;
+ shift;
+ print @_;
+}
+my $snake=$ENV{SNAKE};
+my $serial=$ENV{SERIAL};
+if ($serial || $snake) {
my ($R1,$W1,$R2,$W2);
my $c1p=open2($R1,$W1,@c1); # Open2 R W backward from Open3.
my $c2p=open2($R2,$W2,@c2);
- select $W2;
- $|=1;
- while(<$R1>) {
- info("1:",$_);
- print $_;
- $_=<$R2>;
- last unless defined $_;
- info("2:",$_);
- print $W1 $_;
+ if ($snake) {
+ while(<STDIN>) {
+ lineto($W1,$_);
+ last unless defined ($_=<$R1>);
+ lineto($W2,$_);
+ last unless defined ($_=<$R2>);
+ lineto($W1,$_);
+ last unless defined ($_=<$R1>);
+ lineto(*STDOUT,$_);
+ }
+ } else {
+ while(<$R1>) {
+ info("1:",$_);
+ select $W2;
+ $|=1;
+ print $_;
+ last unless defined ($_=<$R2>);
+ info("2:",$_);
+ print $W1 $_;
+ }
}
} else {
my @rw1=POSIX::pipe();