Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ttlogmerge: convert to make output filename optional (default: STDOUT)

  • Loading branch information...
commit c534a481f039d22b2836c1e9542d87d549c9333c 1 parent d5ec08f
@pmyteh authored
Showing with 14 additions and 9 deletions.
  1. +14 −9 script/ttlogmerge.pl
View
23 script/ttlogmerge.pl
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-# Syntax: ttlogmerge.pl logfile1 logfile2 outputlogfile
+# Syntax: ttlogmerge.pl logfile1 logfile2 [outputlogfile]
#
# A helper script for the Unison file synchroniser. One option for Unison is to
# use an external program to merge two files which have been change in both
@@ -48,7 +48,7 @@ sub parse
# It appears TT shortens the human-readable date string to stay
# under 80 characters per line.
for my $i (1..3) { pop(@tokens) } # Discard date string
-# print "parse: ", $_[0], @tokens;
+# print STDERR "parse: ", $_[0], @tokens;
return @tokens;
}
@@ -57,14 +57,19 @@ sub parse_timestamp
{
my $s = $_[0];
my @tokens = split(/\s+/, $s);
- print "parse_timestamp: ", $tokens[0];
+ print STDERR "parse_timestamp: ", $tokens[0];
return $tokens[0];
}
-open(my $f1, "<", $ARGV[0]) or die;
-open(my $f2, "<", $ARGV[1]) or die;
-# TODO: make third argument optional, defaulting to stdout.
-open(my $fo, ">", $ARGV[2]) or die;
+open(my $f1, "<", shift) or die;
+open(my $f2, "<", shift) or die;
+my $outn = shift;
+my $fo;
+if $(outn) {
+ open($fo, ">", $outn) or die;
+} else {
+ open($fo, '>&', \*STDOUT) or die;
+}
# Read initial lines from files
my $l1 = <$f1>;
@@ -122,12 +127,12 @@ sub parse_timestamp
# Any non-undefined files have unprocessed data in $lx
if (defined $l1) {
do {
-# print "Extra line in f1. Writing.\n", $l1;
+# print STDERR "Extra line in f1. Writing.\n", $l1;
print $fo $l1
} while ($l1 = <$f1>);
} elsif (defined $l2) {
do {
-# print "Extra line in f2. Writing.\n", $l2;
+# print STDERR "Extra line in f2. Writing.\n", $l2;
print $fo $l2
} while ($l2 = <$f2>);
}
Please sign in to comment.
Something went wrong with that request. Please try again.